mirror of
https://github.com/libretro/RetroArch
synced 2025-03-23 19:21:03 +00:00
Start reimplementing tween.c functions
This commit is contained in:
parent
3376c8dd4e
commit
821e37f480
@ -1,33 +1,30 @@
|
||||
#include "tween.h"
|
||||
#include <math.h>
|
||||
|
||||
tween_t* tweens = NULL;
|
||||
int numtweens = 0;
|
||||
static tween_t* tweens = NULL;
|
||||
static int numtweens = 0;
|
||||
|
||||
static void tween_free(tween_t *tw)
|
||||
{
|
||||
if (tw)
|
||||
free(tw);
|
||||
tw = NULL;
|
||||
}
|
||||
|
||||
void add_tween(float duration, float target_value, float* subject,
|
||||
easingFunc easing, tweenCallback callback)
|
||||
{
|
||||
tween_t *tween;
|
||||
tween_t *tweens_tmp;
|
||||
tween_t *tween = NULL;
|
||||
tweens = (tween_t*)
|
||||
realloc(tweens, (numtweens + 1) * sizeof(tween_t));
|
||||
|
||||
numtweens++;
|
||||
|
||||
tweens_tmp = (tween_t*)realloc(tweens, numtweens * sizeof(tween_t));
|
||||
if (tweens_tmp != NULL)
|
||||
if (!tweens) /* Realloc failed. */
|
||||
{
|
||||
tweens = tweens_tmp;
|
||||
}
|
||||
else // realloc failed
|
||||
{
|
||||
if (tweens != NULL)
|
||||
{
|
||||
free(tweens);
|
||||
tweens = NULL;
|
||||
}
|
||||
|
||||
tween_free(tweens);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
numtweens++;
|
||||
tween = (tween_t*)&tweens[numtweens-1];
|
||||
|
||||
if (!tween)
|
||||
@ -43,10 +40,8 @@ void add_tween(float duration, float target_value, float* subject,
|
||||
tween->callback = callback;
|
||||
}
|
||||
|
||||
void update_tween(void *data, float dt)
|
||||
void update_tween(tween_t *tween, float dt)
|
||||
{
|
||||
tween_t *tween = (tween_t*)data;
|
||||
|
||||
if (!tween)
|
||||
return;
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef float (*easingFunc)(float, float, float, float);
|
||||
|
||||
typedef void (*tweenCallback) (void);
|
||||
|
||||
typedef struct
|
||||
@ -35,8 +36,11 @@ typedef struct
|
||||
tweenCallback callback;
|
||||
} tween_t;
|
||||
|
||||
void add_tween(float duration, float target_value, float* subject, easingFunc easing, tweenCallback callback);
|
||||
void update_tween(void *data, float dt);
|
||||
void add_tween(float duration, float target_value,
|
||||
float* subject, easingFunc easing, tweenCallback callback);
|
||||
|
||||
void update_tween(tween_t *data, float dt);
|
||||
|
||||
void update_tweens(float dt);
|
||||
|
||||
// from https://github.com/kikito/tween.lua/blob/master/tween.lua
|
||||
|
Loading…
x
Reference in New Issue
Block a user