Texture animations in editor

This commit is contained in:
2022-08-22 13:55:54 +00:00
parent dda8f1cc24
commit 0a76259a92
6 changed files with 99 additions and 44 deletions

View File

@@ -108,16 +108,12 @@ void tex_gpu_load(struct Texture *tex)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
}
unsigned int tex_incr_anim(unsigned int interval, struct TexAnimation *tex_anim)
void tex_incr_anim(struct TexAnimation *tex_anim)
{
anim_incr(tex_anim);
if (!tex_anim->tex->anim.loop
&& tex_anim->frame == tex_anim->tex->anim.frames)
if (!tex_anim->tex->anim.loop && tex_anim->frame == tex_anim->tex->anim.frames)
anim_pause(tex_anim);
return interval;
}
void anim_incr(struct TexAnimation *anim)
@@ -128,9 +124,7 @@ void anim_incr(struct TexAnimation *anim)
void anim_decr(struct TexAnimation *anim)
{
anim->frame =
(anim->frame + anim->tex->anim.frames -
1) % anim->tex->anim.frames;
anim->frame = (anim->frame + anim->tex->anim.frames - 1) % anim->tex->anim.frames;
tex_anim_calc_uv(anim);
}
@@ -138,9 +132,7 @@ void tex_anim_set(struct TexAnimation *anim)
{
if (anim->playing) {
timer_remove(anim->timer);
anim->timer =
timer_make(floor(1000.f / anim->tex->anim.ms), &tex_incr_anim,
anim);
anim->timer = timer_make(1.f / anim->tex->anim.ms, tex_incr_anim, anim);
}
@@ -186,10 +178,13 @@ void anim_play(struct TexAnimation *anim)
anim->frame = 0;
anim->playing = 1;
timer_remove(anim->timer);
anim->timer =
timer_make(floor(1000.f / anim->tex->anim.ms), &tex_incr_anim,
anim);
if (anim->timer == NULL)
anim->timer = timer_make(1.f / anim->tex->anim.ms, tex_incr_anim, anim);
else
timer_settime(anim->timer, 1.f/anim->tex->anim.ms);
timer_start(anim->timer);
}
void anim_stop(struct TexAnimation *anim)
@@ -200,7 +195,7 @@ void anim_stop(struct TexAnimation *anim)
anim->playing = 0;
anim->frame = 0;
anim->pausetime = 0;
timer_remove(anim->timer);
timer_stop(anim->timer);
tex_anim_calc_uv(anim);
}
@@ -210,7 +205,7 @@ void anim_pause(struct TexAnimation *anim)
return;
anim->playing = 0;
timer_remove(anim->timer);
timer_pause(anim->timer);
}
void anim_fwd(struct TexAnimation *anim)