Skip to content

Commit

Permalink
Keep LOADED/READY state in Load/Init lower bit (backported from dd7cba0)
Browse files Browse the repository at this point in the history
  • Loading branch information
cahirwpz committed Dec 16, 2023
1 parent e679bcd commit 963eb7b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
8 changes: 0 additions & 8 deletions include/effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,10 @@ extern int lastFrameCount;
*/
extern bool exitLoop;

typedef enum {
EFFECT_LOADED = 1,
EFFECT_READY = 2,
EFFECT_RUNNING = 4,
} EffectStateT;

typedef void (*EffectFuncT)(void);

typedef struct Effect {
const char *name;
EffectStateT state;
/*
* Executed in background task when other effect is running.
* Precalculates data for the effect to be launched.
Expand Down Expand Up @@ -92,7 +85,6 @@ void EffectRun(EffectT *effect);
#define EFFECT(NAME, L, U, I, K, R, V) \
EffectT NAME##Effect = { \
.name = #NAME, \
.state = 0, \
.Load = (L), \
.UnLoad = (U), \
.Init = (I), \
Expand Down
18 changes: 10 additions & 8 deletions system/effect.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ static void SendEffectStatus(EffectT *effect) {
# define SendEffectStatus(x)
#endif

#define DONE 1

void EffectLoad(EffectT *effect) {
if (effect->state & EFFECT_LOADED)
if ((intptr_t)effect->Load & DONE)
return;

if (effect->Load) {
Expand All @@ -39,12 +41,12 @@ void EffectLoad(EffectT *effect) {
ShowMemStats();
}

effect->state |= EFFECT_LOADED;
(intptr_t)effect->Load |= DONE;
SendEffectStatus(effect);
}

void EffectInit(EffectT *effect) {
if (effect->state & EFFECT_READY)
if ((intptr_t)effect->Init & DONE)
return;

if (effect->Init) {
Expand All @@ -53,12 +55,12 @@ void EffectInit(EffectT *effect) {
ShowMemStats();
}

effect->state |= EFFECT_READY;
(intptr_t)effect->Init |= DONE;
SendEffectStatus(effect);
}

void EffectKill(EffectT *effect) {
if (!(effect->state & EFFECT_READY))
if (!((intptr_t)effect->Init & DONE))
return;

if (effect->Kill) {
Expand All @@ -67,12 +69,12 @@ void EffectKill(EffectT *effect) {
ShowMemStats();
}

effect->state &= ~EFFECT_READY;
(intptr_t)effect->Init ^= DONE;
SendEffectStatus(effect);
}

void EffectUnLoad(EffectT *effect) {
if (!(effect->state & EFFECT_LOADED))
if (!((intptr_t)effect->Load & DONE))
return;

if (effect->UnLoad) {
Expand All @@ -81,7 +83,7 @@ void EffectUnLoad(EffectT *effect) {
ShowMemStats();
}

effect->state &= ~EFFECT_LOADED;
(intptr_t)effect->Load ^= DONE;
SendEffectStatus(effect);
}

Expand Down

0 comments on commit 963eb7b

Please sign in to comment.