Rework sprite render system
Internal Changelog: - Add more fields - Elapsed is now in sprite component - Add rotation fields - Tweak early exit checks in render functionsscene_man
parent
754d380221
commit
42c4572066
|
@ -32,6 +32,7 @@ int main(void)
|
||||||
Font* fnt = get_font(&assets, "testfont");
|
Font* fnt = get_font(&assets, "testfont");
|
||||||
|
|
||||||
int current_frame = 0;
|
int current_frame = 0;
|
||||||
|
int elapsed = 0;
|
||||||
while(!WindowShouldClose())
|
while(!WindowShouldClose())
|
||||||
{
|
{
|
||||||
if (IsKeyReleased(KEY_C))
|
if (IsKeyReleased(KEY_C))
|
||||||
|
@ -49,12 +50,12 @@ int main(void)
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
|
||||||
// Update the animated Sprite
|
// Update the animated Sprite
|
||||||
spr2->elapsed++;
|
elapsed++;
|
||||||
if (spr2->elapsed == spr2->speed)
|
if (elapsed == spr2->speed)
|
||||||
{
|
{
|
||||||
current_frame++;
|
current_frame++;
|
||||||
current_frame %= spr2->frame_count;
|
current_frame %= spr2->frame_count;
|
||||||
spr2->elapsed = 0;
|
elapsed = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
term_assets(&assets);
|
term_assets(&assets);
|
||||||
|
|
|
@ -186,7 +186,6 @@ typedef struct Sprite {
|
||||||
Vector2 origin;
|
Vector2 origin;
|
||||||
Vector2 anchor;
|
Vector2 anchor;
|
||||||
int frame_count;
|
int frame_count;
|
||||||
int elapsed;
|
|
||||||
int speed;
|
int speed;
|
||||||
char* name;
|
char* name;
|
||||||
} Sprite_t;
|
} Sprite_t;
|
||||||
|
@ -207,6 +206,11 @@ typedef struct _CSprite_t {
|
||||||
bool pause;
|
bool pause;
|
||||||
int current_frame;
|
int current_frame;
|
||||||
float fractional;
|
float fractional;
|
||||||
|
float rotation; // Degree
|
||||||
|
float rotation_speed; // Degree / s
|
||||||
|
int elapsed;
|
||||||
|
Vector2 offset;
|
||||||
|
Color colour;
|
||||||
} CSprite_t;
|
} CSprite_t;
|
||||||
|
|
||||||
typedef struct _CMoveable_t {
|
typedef struct _CMoveable_t {
|
||||||
|
|
|
@ -63,7 +63,6 @@ int main(void)
|
||||||
.origin = (Vector2){0, 0},
|
.origin = (Vector2){0, 0},
|
||||||
.anchor = (Vector2){tex.width / 2, tex.height / 2},
|
.anchor = (Vector2){tex.width / 2, tex.height / 2},
|
||||||
.frame_count = 0,
|
.frame_count = 0,
|
||||||
.elapsed = 0,
|
|
||||||
.speed = 0,
|
.speed = 0,
|
||||||
.name = "test_spr"
|
.name = "test_spr"
|
||||||
};
|
};
|
||||||
|
|
2
run.sh
2
run.sh
|
@ -1,3 +1,3 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
LSAN_OPTIONS=suppressions=./lsan_supp.txt ./build/$1
|
./build.sh && LSAN_OPTIONS=suppressions=./lsan_supp.txt ./build/$1
|
||||||
|
|
|
@ -2002,7 +2002,6 @@ void sprite_animation_system(Scene_t* scene)
|
||||||
{
|
{
|
||||||
next_idx = p_cspr->transition_func(p_ent);
|
next_idx = p_cspr->transition_func(p_ent);
|
||||||
}
|
}
|
||||||
if (p_cspr->pause) return;
|
|
||||||
|
|
||||||
bool reset = p_cspr->current_idx != next_idx;
|
bool reset = p_cspr->current_idx != next_idx;
|
||||||
p_cspr->current_idx = next_idx;
|
p_cspr->current_idx = next_idx;
|
||||||
|
@ -2010,7 +2009,14 @@ void sprite_animation_system(Scene_t* scene)
|
||||||
SpriteRenderInfo_t spr = p_cspr->sprites[p_cspr->current_idx];
|
SpriteRenderInfo_t spr = p_cspr->sprites[p_cspr->current_idx];
|
||||||
if (spr.sprite == NULL) continue;
|
if (spr.sprite == NULL) continue;
|
||||||
|
|
||||||
if (reset) p_cspr->current_frame = 0;
|
if (reset)
|
||||||
|
{
|
||||||
|
p_cspr->fractional = 0;
|
||||||
|
p_cspr->elapsed = 0;
|
||||||
|
p_cspr->current_frame = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (spr.sprite->speed == 0) continue;
|
||||||
|
|
||||||
// Animate it (handle frame count)
|
// Animate it (handle frame count)
|
||||||
p_cspr->fractional += scene->delta_time;
|
p_cspr->fractional += scene->delta_time;
|
||||||
|
@ -2018,12 +2024,15 @@ void sprite_animation_system(Scene_t* scene)
|
||||||
if (p_cspr->fractional > ANIM_FRAME_RATE)
|
if (p_cspr->fractional > ANIM_FRAME_RATE)
|
||||||
{
|
{
|
||||||
p_cspr->fractional -= ANIM_FRAME_RATE;
|
p_cspr->fractional -= ANIM_FRAME_RATE;
|
||||||
spr.sprite->elapsed++;
|
p_cspr->elapsed++;
|
||||||
if (spr.sprite->elapsed == spr.sprite->speed)
|
if (p_cspr->elapsed == spr.sprite->speed)
|
||||||
{
|
{
|
||||||
p_cspr->current_frame++;
|
p_cspr->elapsed = 0;
|
||||||
p_cspr->current_frame %= spr.sprite->frame_count;
|
if (!p_cspr->pause)
|
||||||
spr.sprite->elapsed = 0;
|
{
|
||||||
|
p_cspr->current_frame++;
|
||||||
|
p_cspr->current_frame %= spr.sprite->frame_count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue