mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2024-12-05 00:38:00 +01:00
API consistency tweaks
This commit is contained in:
parent
df1790d242
commit
4da588cbb2
13 changed files with 125 additions and 130 deletions
2
Doxyfile
2
Doxyfile
|
@ -452,7 +452,7 @@ EXTRACT_STATIC = NO
|
|||
# for Java sources.
|
||||
# The default value is: YES.
|
||||
|
||||
EXTRACT_LOCAL_CLASSES = YES
|
||||
EXTRACT_LOCAL_CLASSES = NO
|
||||
|
||||
# This flag is only useful for Objective-C code. If set to YES, local methods,
|
||||
# which are defined in the implementation section but not in the interface are
|
||||
|
|
|
@ -49,7 +49,7 @@ SYMBOL_EXPORT void SelectSpritesheet(struct Game* game, struct Character* charac
|
|||
character->predecessor = NULL;
|
||||
}
|
||||
character->repeats = tmp->repeats;
|
||||
character->pos = reversed ? (tmp->frameCount - 1) : 0;
|
||||
character->pos = reversed ? (tmp->frame_count - 1) : 0;
|
||||
character->reversed = reversed;
|
||||
character->reversing = tmp->reversed ^ reversed;
|
||||
character->frame = &tmp->frames[character->pos];
|
||||
|
@ -65,7 +65,7 @@ SYMBOL_EXPORT void SelectSpritesheet(struct Game* game, struct Character* charac
|
|||
SYMBOL_EXPORT void SwitchSpritesheet(struct Game* game, struct Character* character, char* name) {
|
||||
int pos = character->pos;
|
||||
SelectSpritesheet(game, character, name);
|
||||
if (pos < character->spritesheets->frameCount) {
|
||||
if (pos < character->spritesheets->frame_count) {
|
||||
character->pos = pos;
|
||||
character->frame = &character->spritesheet->frames[character->pos];
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ SYMBOL_EXPORT void LoadSpritesheets(struct Game* game, struct Character* charact
|
|||
tmp->width = al_get_bitmap_width(tmp->bitmap) / tmp->cols;
|
||||
tmp->height = al_get_bitmap_height(tmp->bitmap) / tmp->rows;
|
||||
}
|
||||
for (int i = 0; i < tmp->frameCount; i++) {
|
||||
for (int i = 0; i < tmp->frame_count; i++) {
|
||||
if ((!tmp->frames[i].source) && (tmp->frames[i].file)) {
|
||||
if (game->config.debug.enabled) {
|
||||
PrintConsole(game, " - %s", tmp->frames[i].file);
|
||||
|
@ -148,7 +148,7 @@ SYMBOL_EXPORT void UnloadSpritesheets(struct Game* game, struct Character* chara
|
|||
PrintConsole(game, "Unloading spritesheets for character %s...", character->name);
|
||||
struct Spritesheet* tmp = character->spritesheets;
|
||||
while (tmp) {
|
||||
for (int i = 0; i < tmp->frameCount; i++) {
|
||||
for (int i = 0; i < tmp->frame_count; i++) {
|
||||
if (tmp->frames[i].filepath) {
|
||||
RemoveBitmap(game, tmp->frames[i].filepath);
|
||||
} else {
|
||||
|
@ -194,17 +194,17 @@ SYMBOL_EXPORT void RegisterSpritesheet(struct Game* game, struct Character* char
|
|||
s = malloc(sizeof(struct Spritesheet));
|
||||
s->name = strdup(name);
|
||||
s->bitmap = NULL;
|
||||
s->frameCount = strtolnull(al_get_config_value(config, "animation", "frames"), 0);
|
||||
s->frame_count = strtolnull(al_get_config_value(config, "animation", "frames"), 0);
|
||||
s->rows = strtolnull(al_get_config_value(config, "animation", "rows"), 0);
|
||||
s->cols = strtolnull(al_get_config_value(config, "animation", "cols"), 0);
|
||||
s->flipX = strtolnull(al_get_config_value(config, "animation", "flipX"), 0);
|
||||
s->flipY = strtolnull(al_get_config_value(config, "animation", "flipY"), 0);
|
||||
int blanks = strtolnull(al_get_config_value(config, "animation", "blanks"), 0);
|
||||
if (s->frameCount == 0) {
|
||||
s->frameCount = s->rows * s->cols - blanks;
|
||||
if (s->frame_count == 0) {
|
||||
s->frame_count = s->rows * s->cols - blanks;
|
||||
} else {
|
||||
s->rows = floor(sqrt(s->frameCount));
|
||||
s->cols = ceil(s->frameCount / (double)s->rows);
|
||||
s->rows = floor(sqrt(s->frame_count));
|
||||
s->cols = ceil(s->frame_count / (double)s->rows);
|
||||
}
|
||||
|
||||
s->bidir = strtolnull(al_get_config_value(config, "animation", "bidir"), 0);
|
||||
|
@ -251,9 +251,9 @@ SYMBOL_EXPORT void RegisterSpritesheet(struct Game* game, struct Character* char
|
|||
s->offsetX = strtolnull(al_get_config_value(config, "offset", "x"), 0);
|
||||
s->offsetY = strtolnull(al_get_config_value(config, "offset", "y"), 0);
|
||||
|
||||
s->frames = malloc(sizeof(struct SpritesheetFrame) * s->frameCount);
|
||||
s->frames = malloc(sizeof(struct SpritesheetFrame) * s->frame_count);
|
||||
|
||||
for (int i = 0; i < s->frameCount; i++) {
|
||||
for (int i = 0; i < s->frame_count; i++) {
|
||||
char framename[255];
|
||||
snprintf(framename, 255, "frame%d", i);
|
||||
s->frames[i].duration = strtodnull(al_get_config_value(config, framename, "duration"), s->duration);
|
||||
|
@ -338,7 +338,7 @@ SYMBOL_EXPORT struct Character* CreateCharacter(struct Game* game, char* name) {
|
|||
character->hidden = false;
|
||||
character->data = NULL;
|
||||
character->callback = NULL;
|
||||
character->callbackData = NULL;
|
||||
character->callback_data = NULL;
|
||||
character->destructor = NULL;
|
||||
|
||||
return character;
|
||||
|
@ -367,7 +367,7 @@ SYMBOL_EXPORT void DestroyCharacter(struct Game* game, struct Character* charact
|
|||
if (tmp->file) {
|
||||
free(tmp->file);
|
||||
}
|
||||
for (int i = 0; i < tmp->frameCount; i++) {
|
||||
for (int i = 0; i < tmp->frame_count; i++) {
|
||||
if (tmp->frames[i].filepath) {
|
||||
RemoveBitmap(game, tmp->frames[i].filepath);
|
||||
} else {
|
||||
|
@ -420,7 +420,7 @@ SYMBOL_EXPORT void AnimateCharacter(struct Game* game, struct Character* charact
|
|||
} else {
|
||||
character->pos++;
|
||||
}
|
||||
if (character->pos >= character->spritesheet->frameCount) {
|
||||
if (character->pos >= character->spritesheet->frame_count) {
|
||||
if (character->spritesheet->bidir) {
|
||||
character->pos -= 2;
|
||||
character->reversing = true;
|
||||
|
@ -440,7 +440,7 @@ SYMBOL_EXPORT void AnimateCharacter(struct Game* game, struct Character* charact
|
|||
reachedEnd = true;
|
||||
}
|
||||
} else {
|
||||
character->pos = character->spritesheet->frameCount - 1;
|
||||
character->pos = character->spritesheet->frame_count - 1;
|
||||
reachedEnd = true;
|
||||
}
|
||||
}
|
||||
|
@ -449,37 +449,37 @@ SYMBOL_EXPORT void AnimateCharacter(struct Game* game, struct Character* charact
|
|||
if (character->repeats > 0) {
|
||||
character->repeats--;
|
||||
if (character->callback) {
|
||||
character->callback(game, character, NULL, character->spritesheet, character->callbackData);
|
||||
character->callback(game, character, NULL, character->spritesheet, character->callback_data);
|
||||
}
|
||||
} else {
|
||||
if ((!character->reversed) && (character->successor)) {
|
||||
struct Spritesheet* old = character->spritesheet;
|
||||
SelectSpritesheet(game, character, character->successor);
|
||||
if (character->callback) {
|
||||
character->callback(game, character, character->spritesheet, old, character->callbackData);
|
||||
character->callback(game, character, character->spritesheet, old, character->callback_data);
|
||||
}
|
||||
} else if ((character->reversed) && (character->predecessor)) {
|
||||
struct Spritesheet* old = character->spritesheet;
|
||||
SelectSpritesheet(game, character, character->predecessor);
|
||||
if (character->callback) {
|
||||
character->callback(game, character, character->spritesheet, old, character->callbackData);
|
||||
character->callback(game, character, character->spritesheet, old, character->callback_data);
|
||||
}
|
||||
} else {
|
||||
if (character->repeats == 0) {
|
||||
if (character->reversed) {
|
||||
character->pos = 1;
|
||||
} else {
|
||||
character->pos = character->spritesheet->frameCount - 1;
|
||||
character->pos = character->spritesheet->frame_count - 1;
|
||||
}
|
||||
if (character->callback) {
|
||||
character->callback(game, character, NULL, character->spritesheet, character->callbackData);
|
||||
character->callback(game, character, NULL, character->spritesheet, character->callback_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (character->spritesheet->frameCount == 1) {
|
||||
if (character->spritesheet->frame_count == 1) {
|
||||
character->pos = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ struct SpritesheetFrame {
|
|||
struct Spritesheet {
|
||||
char* name; /*!< Name of the spritesheet (used in file paths). */
|
||||
ALLEGRO_BITMAP* bitmap; /*!< Spritesheet bitmap. */
|
||||
int frameCount;
|
||||
int frame_count;
|
||||
int rows; /*!< Number of rows in the spritesheet. */
|
||||
int cols; /*!< Number of columns in the spritesheet. */
|
||||
double duration;
|
||||
|
@ -108,7 +108,7 @@ struct Character {
|
|||
bool hidden;
|
||||
void* data; /*!< Additional, custom character data (HP etc.). */
|
||||
CharacterCallback* callback;
|
||||
void* callbackData;
|
||||
void* callback_data;
|
||||
CharacterDestructor* destructor;
|
||||
bool shared; /*!< Marks the list of spritesheets as shared, so it won't be freed together with the character. */
|
||||
};
|
||||
|
|
|
@ -15,8 +15,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/// \privatesection
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
#undef al_create_audio_stream
|
||||
|
|
|
@ -43,7 +43,7 @@ static struct Gamestate* FindGamestate(struct Game* game, const char* name) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
SYMBOL_EXPORT void RegisterGamestate(struct Game* game, const char* name, struct Gamestate_API* api) {
|
||||
SYMBOL_EXPORT void RegisterGamestate(struct Game* game, const char* name, struct GamestateAPI* api) {
|
||||
struct Gamestate* gs = FindGamestate(game, name);
|
||||
if (!gs) {
|
||||
gs = AddNewGamestate(game, name);
|
||||
|
@ -146,8 +146,8 @@ SYMBOL_EXPORT void PauseGamestate(struct Game* game, const char* name) {
|
|||
}
|
||||
gs->paused = true;
|
||||
game->_priv.current_gamestate = gs;
|
||||
if (gs->api->Gamestate_Pause) {
|
||||
(*gs->api->Gamestate_Pause)(game, gs->data);
|
||||
if (gs->api->pause) {
|
||||
(*gs->api->pause)(game, gs->data);
|
||||
}
|
||||
PrintConsole(game, "Gamestate \"%s\" paused.", name);
|
||||
} else {
|
||||
|
@ -168,8 +168,8 @@ SYMBOL_EXPORT void ResumeGamestate(struct Game* game, const char* name) {
|
|||
}
|
||||
gs->paused = false;
|
||||
game->_priv.current_gamestate = gs;
|
||||
if (gs->api->Gamestate_Resume) {
|
||||
(*gs->api->Gamestate_Resume)(game, gs->data);
|
||||
if (gs->api->resume) {
|
||||
(*gs->api->resume)(game, gs->data);
|
||||
}
|
||||
PrintConsole(game, "Gamestate \"%s\" resumed.", name);
|
||||
} else {
|
||||
|
|
|
@ -22,23 +22,23 @@
|
|||
|
||||
#include "libsuperderpy.h"
|
||||
|
||||
struct Gamestate_API {
|
||||
void (*Gamestate_Draw)(struct Game* game, void* data);
|
||||
void (*Gamestate_Logic)(struct Game* game, void* data, double delta);
|
||||
void (*Gamestate_Tick)(struct Game* game, void* data);
|
||||
struct GamestateAPI {
|
||||
void (*draw)(struct Game* game, void* data);
|
||||
void (*logic)(struct Game* game, void* data, double delta);
|
||||
void (*tick)(struct Game* game, void* data);
|
||||
|
||||
void* (*Gamestate_Load)(struct Game* game, void (*progress)(struct Game* game));
|
||||
void (*Gamestate_PostLoad)(struct Game* game, void* data);
|
||||
void (*Gamestate_Start)(struct Game* game, void* data);
|
||||
void (*Gamestate_Pause)(struct Game* game, void* data);
|
||||
void (*Gamestate_Resume)(struct Game* game, void* data);
|
||||
void (*Gamestate_Stop)(struct Game* game, void* data);
|
||||
void (*Gamestate_Unload)(struct Game* game, void* data);
|
||||
void* (*load)(struct Game* game, void (*progress)(struct Game* game));
|
||||
void (*post_load)(struct Game* game, void* data);
|
||||
void (*start)(struct Game* game, void* data);
|
||||
void (*pause)(struct Game* game, void* data);
|
||||
void (*resume)(struct Game* game, void* data);
|
||||
void (*stop)(struct Game* game, void* data);
|
||||
void (*unload)(struct Game* game, void* data);
|
||||
|
||||
void (*Gamestate_ProcessEvent)(struct Game* game, void* data, ALLEGRO_EVENT* ev);
|
||||
void (*Gamestate_Reload)(struct Game* game, void* data);
|
||||
void (*process_event)(struct Game* game, void* data, ALLEGRO_EVENT* ev);
|
||||
void (*reload)(struct Game* game, void* data);
|
||||
|
||||
int* Gamestate_ProgressCount;
|
||||
int* progress_count;
|
||||
};
|
||||
|
||||
struct Gamestate {
|
||||
|
@ -52,15 +52,15 @@ struct Gamestate {
|
|||
bool fromlib;
|
||||
bool open;
|
||||
struct Gamestate* next;
|
||||
struct Gamestate_API* api;
|
||||
struct GamestateAPI* api;
|
||||
ALLEGRO_BITMAP* fb;
|
||||
int progressCount;
|
||||
int progress_count;
|
||||
void* data;
|
||||
};
|
||||
|
||||
void LoadGamestate(struct Game* game, const char* name);
|
||||
void UnloadGamestate(struct Game* game, const char* name);
|
||||
void RegisterGamestate(struct Game* game, const char* name, struct Gamestate_API* api);
|
||||
void RegisterGamestate(struct Game* game, const char* name, struct GamestateAPI* api);
|
||||
void StartGamestate(struct Game* game, const char* name);
|
||||
void StopGamestate(struct Game* game, const char* name);
|
||||
void PauseGamestate(struct Game* game, const char* name);
|
||||
|
|
|
@ -26,8 +26,6 @@
|
|||
// 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves.
|
||||
// 2018-02-06: Inputs: Added mapping for ImGuiKey_Space.
|
||||
|
||||
/// \privatesection
|
||||
|
||||
#include "imgui/imgui_impl_allegro5.h"
|
||||
#include <float.h>
|
||||
#include <stdint.h> // uint64_t
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
*
|
||||
* Also, ponies.
|
||||
*/
|
||||
/// \privatesection
|
||||
|
||||
#include "internal.h"
|
||||
#include "3rdparty/valgrind.h"
|
||||
|
@ -52,7 +51,7 @@ SYMBOL_INTERNAL void DrawGamestates(struct Game* game) {
|
|||
al_reset_clipping_rectangle();
|
||||
al_clear_to_color(al_map_rgb(0, 0, 0)); // even if everything is going to be redrawn, it optimizes tiled rendering
|
||||
}
|
||||
tmp->api->Gamestate_Draw(game, tmp->data);
|
||||
tmp->api->draw(game, tmp->data);
|
||||
// TODO: save and restore more state for careless gamestating
|
||||
}
|
||||
tmp = tmp->next;
|
||||
|
@ -66,7 +65,7 @@ SYMBOL_INTERNAL void DrawGamestates(struct Game* game) {
|
|||
al_reset_clipping_rectangle();
|
||||
al_clear_to_color(al_map_rgb(0, 0, 0));
|
||||
}
|
||||
game->_priv.loading.gamestate->api->Gamestate_Draw(game, game->_priv.loading.gamestate->data);
|
||||
game->_priv.loading.gamestate->api->draw(game, game->_priv.loading.gamestate->data);
|
||||
}
|
||||
|
||||
al_set_target_backbuffer(game->display);
|
||||
|
@ -94,7 +93,7 @@ SYMBOL_INTERNAL void LogicGamestates(struct Game* game, double delta) {
|
|||
while (tmp) {
|
||||
if ((tmp->loaded) && (tmp->started) && (!tmp->paused)) {
|
||||
game->_priv.current_gamestate = tmp;
|
||||
tmp->api->Gamestate_Logic(game, tmp->data, delta);
|
||||
tmp->api->logic(game, tmp->data, delta);
|
||||
}
|
||||
tmp = tmp->next;
|
||||
}
|
||||
|
@ -108,8 +107,8 @@ SYMBOL_INTERNAL void TickGamestates(struct Game* game) {
|
|||
while (tmp) {
|
||||
if ((tmp->loaded) && (tmp->started) && (!tmp->paused)) {
|
||||
game->_priv.current_gamestate = tmp;
|
||||
if (tmp->api->Gamestate_Tick) {
|
||||
tmp->api->Gamestate_Tick(game, tmp->data);
|
||||
if (tmp->api->tick) {
|
||||
tmp->api->tick(game, tmp->data);
|
||||
}
|
||||
}
|
||||
tmp = tmp->next;
|
||||
|
@ -122,8 +121,8 @@ SYMBOL_INTERNAL void ReloadGamestates(struct Game* game) {
|
|||
while (tmp) {
|
||||
if (tmp->loaded) {
|
||||
game->_priv.current_gamestate = tmp;
|
||||
if (tmp->api->Gamestate_Reload) {
|
||||
tmp->api->Gamestate_Reload(game, tmp->data);
|
||||
if (tmp->api->reload) {
|
||||
tmp->api->reload(game, tmp->data);
|
||||
}
|
||||
}
|
||||
tmp = tmp->next;
|
||||
|
@ -135,7 +134,7 @@ SYMBOL_INTERNAL void EventGamestates(struct Game* game, ALLEGRO_EVENT* ev) {
|
|||
while (tmp) {
|
||||
if ((tmp->loaded) && (tmp->started) && (!tmp->paused)) {
|
||||
game->_priv.current_gamestate = tmp;
|
||||
tmp->api->Gamestate_ProcessEvent(game, tmp->data, ev);
|
||||
tmp->api->process_event(game, tmp->data, ev);
|
||||
}
|
||||
tmp = tmp->next;
|
||||
}
|
||||
|
@ -247,8 +246,8 @@ SYMBOL_INTERNAL void* GamestateLoadingThread(void* arg) {
|
|||
struct GamestateLoadingThreadData* data = arg;
|
||||
data->game->_priv.loading.in_progress = true;
|
||||
al_set_new_bitmap_flags(data->bitmap_flags);
|
||||
data->gamestate->data = data->gamestate->api->Gamestate_Load(data->game, &GamestateProgress);
|
||||
if (data->game->_priv.loading.progress != data->gamestate->progressCount) {
|
||||
data->gamestate->data = data->gamestate->api->load(data->game, &GamestateProgress);
|
||||
if (data->game->_priv.loading.progress != data->gamestate->progress_count) {
|
||||
PrintConsole(data->game, "[%s] WARNING: Gamestate_ProgressCount does not match the number of progress invokations (%d)!", data->gamestate->name, data->game->_priv.loading.progress);
|
||||
if (data->game->config.debug.enabled) {
|
||||
PrintConsole(data->game, "(sleeping for 3 seconds...)");
|
||||
|
@ -277,9 +276,9 @@ SYMBOL_INTERNAL void* ScreenshotThread(void* arg) {
|
|||
|
||||
SYMBOL_INTERNAL void CalculateProgress(struct Game* game) {
|
||||
struct Gamestate* tmp = game->_priv.loading.current;
|
||||
float progress = ((game->_priv.loading.progress / (float)(tmp->progressCount + 1)) / (float)game->_priv.loading.toLoad) + (game->_priv.loading.loaded / (float)game->_priv.loading.toLoad);
|
||||
float progress = ((game->_priv.loading.progress / (float)(tmp->progress_count + 1)) / (float)game->_priv.loading.to_load) + (game->_priv.loading.loaded / (float)game->_priv.loading.to_load);
|
||||
if (game->config.debug.enabled) {
|
||||
PrintConsole(game, "[%s] Progress: %d%% (%d/%d)", tmp->name, (int)(progress * 100), game->_priv.loading.progress, tmp->progressCount + 1);
|
||||
PrintConsole(game, "[%s] Progress: %d%% (%d/%d)", tmp->name, (int)(progress * 100), game->_priv.loading.progress, tmp->progress_count + 1);
|
||||
}
|
||||
game->loading.progress = progress;
|
||||
}
|
||||
|
@ -327,31 +326,31 @@ SYMBOL_INTERNAL bool OpenGamestate(struct Game* game, struct Gamestate* gamestat
|
|||
}
|
||||
|
||||
SYMBOL_INTERNAL bool LinkGamestate(struct Game* game, struct Gamestate* gamestate) {
|
||||
gamestate->api = calloc(1, sizeof(struct Gamestate_API));
|
||||
gamestate->api = calloc(1, sizeof(struct GamestateAPI));
|
||||
|
||||
#define GS_ERROR \
|
||||
FatalError(game, false, "Error on resolving gamestate's %s symbol: %s", gamestate->name, dlerror()); /* TODO: move out */ \
|
||||
free(gamestate->api); \
|
||||
return false;
|
||||
|
||||
if (!(gamestate->api->Gamestate_Draw = dlsym(gamestate->handle, "Gamestate_Draw"))) { GS_ERROR; }
|
||||
if (!(gamestate->api->Gamestate_Logic = dlsym(gamestate->handle, "Gamestate_Logic"))) { GS_ERROR; }
|
||||
if (!(gamestate->api->Gamestate_Load = dlsym(gamestate->handle, "Gamestate_Load"))) { GS_ERROR; }
|
||||
if (!(gamestate->api->Gamestate_Unload = dlsym(gamestate->handle, "Gamestate_Unload"))) { GS_ERROR; }
|
||||
if (!(gamestate->api->Gamestate_Start = dlsym(gamestate->handle, "Gamestate_Start"))) { GS_ERROR; }
|
||||
if (!(gamestate->api->Gamestate_Stop = dlsym(gamestate->handle, "Gamestate_Stop"))) { GS_ERROR; }
|
||||
if (!(gamestate->api->Gamestate_ProcessEvent = dlsym(gamestate->handle, "Gamestate_ProcessEvent"))) { GS_ERROR; }
|
||||
if (!(gamestate->api->draw = dlsym(gamestate->handle, "Gamestate_Draw"))) { GS_ERROR; }
|
||||
if (!(gamestate->api->logic = dlsym(gamestate->handle, "Gamestate_Logic"))) { GS_ERROR; }
|
||||
if (!(gamestate->api->load = dlsym(gamestate->handle, "Gamestate_Load"))) { GS_ERROR; }
|
||||
if (!(gamestate->api->unload = dlsym(gamestate->handle, "Gamestate_Unload"))) { GS_ERROR; }
|
||||
if (!(gamestate->api->start = dlsym(gamestate->handle, "Gamestate_Start"))) { GS_ERROR; }
|
||||
if (!(gamestate->api->stop = dlsym(gamestate->handle, "Gamestate_Stop"))) { GS_ERROR; }
|
||||
if (!(gamestate->api->process_event = dlsym(gamestate->handle, "Gamestate_ProcessEvent"))) { GS_ERROR; }
|
||||
|
||||
// optional
|
||||
gamestate->api->Gamestate_Tick = dlsym(gamestate->handle, "Gamestate_Tick");
|
||||
gamestate->api->Gamestate_PostLoad = dlsym(gamestate->handle, "Gamestate_PostLoad");
|
||||
gamestate->api->Gamestate_Pause = dlsym(gamestate->handle, "Gamestate_Pause");
|
||||
gamestate->api->Gamestate_Resume = dlsym(gamestate->handle, "Gamestate_Resume");
|
||||
gamestate->api->Gamestate_Reload = dlsym(gamestate->handle, "Gamestate_Reload");
|
||||
gamestate->api->Gamestate_ProgressCount = dlsym(gamestate->handle, "Gamestate_ProgressCount");
|
||||
gamestate->api->tick = dlsym(gamestate->handle, "Gamestate_Tick");
|
||||
gamestate->api->post_load = dlsym(gamestate->handle, "Gamestate_PostLoad");
|
||||
gamestate->api->pause = dlsym(gamestate->handle, "Gamestate_Pause");
|
||||
gamestate->api->resume = dlsym(gamestate->handle, "Gamestate_Resume");
|
||||
gamestate->api->reload = dlsym(gamestate->handle, "Gamestate_Reload");
|
||||
gamestate->api->progress_count = dlsym(gamestate->handle, "Gamestate_ProgressCount");
|
||||
|
||||
if (gamestate->api->Gamestate_ProgressCount) {
|
||||
gamestate->progressCount = *gamestate->api->Gamestate_ProgressCount;
|
||||
if (gamestate->api->progress_count) {
|
||||
gamestate->progress_count = *gamestate->api->progress_count;
|
||||
}
|
||||
|
||||
#undef GS_ERROR
|
||||
|
@ -374,7 +373,7 @@ SYMBOL_INTERNAL struct Gamestate* AllocateGamestate(struct Game* game, const cha
|
|||
tmp->next = NULL;
|
||||
tmp->api = NULL;
|
||||
tmp->fromlib = true;
|
||||
tmp->progressCount = 0;
|
||||
tmp->progress_count = 0;
|
||||
tmp->open = false;
|
||||
tmp->fb = NULL;
|
||||
tmp->showLoading = true;
|
||||
|
@ -590,9 +589,9 @@ SYMBOL_INTERNAL void ReloadCode(struct Game* game) {
|
|||
CloseGamestate(game, tmp);
|
||||
tmp->name = name;
|
||||
if (OpenGamestate(game, tmp) && LinkGamestate(game, tmp) && tmp->loaded) {
|
||||
if (tmp->api->Gamestate_Reload) {
|
||||
if (tmp->api->reload) {
|
||||
PrintConsole(game, "[%s] Reloading...", tmp->name);
|
||||
tmp->api->Gamestate_Reload(game, tmp->data);
|
||||
tmp->api->reload(game, tmp->data);
|
||||
}
|
||||
} else {
|
||||
// live-reload failed
|
||||
|
|
|
@ -362,7 +362,7 @@ SYMBOL_EXPORT int libsuperderpy_start(struct Game* game) {
|
|||
// TODO: support loading-less scenario
|
||||
return 2;
|
||||
}
|
||||
game->_priv.loading.gamestate->data = (*game->_priv.loading.gamestate->api->Gamestate_Load)(game, NULL);
|
||||
game->_priv.loading.gamestate->data = (*game->_priv.loading.gamestate->api->load)(game, NULL);
|
||||
PrintConsole(game, "Loading screen registered.");
|
||||
|
||||
ReloadShaders(game, false);
|
||||
|
@ -421,14 +421,14 @@ SYMBOL_EXPORT void libsuperderpy_destroy(struct Game* game) {
|
|||
if (tmp->started) {
|
||||
PrintConsole(game, "Stopping gamestate \"%s\"...", tmp->name);
|
||||
game->_priv.current_gamestate = tmp;
|
||||
(*tmp->api->Gamestate_Stop)(game, tmp->data);
|
||||
(*tmp->api->stop)(game, tmp->data);
|
||||
tmp->started = false;
|
||||
PrintConsole(game, "Gamestate \"%s\" stopped successfully.", tmp->name);
|
||||
}
|
||||
if (tmp->loaded) {
|
||||
PrintConsole(game, "Unloading gamestate \"%s\"...", tmp->name);
|
||||
game->_priv.current_gamestate = tmp;
|
||||
(*tmp->api->Gamestate_Unload)(game, tmp->data);
|
||||
(*tmp->api->unload)(game, tmp->data);
|
||||
tmp->loaded = false;
|
||||
PrintConsole(game, "Gamestate \"%s\" unloaded successfully.", tmp->name);
|
||||
}
|
||||
|
@ -438,7 +438,7 @@ SYMBOL_EXPORT void libsuperderpy_destroy(struct Game* game) {
|
|||
tmp = pom;
|
||||
}
|
||||
|
||||
(*game->_priv.loading.gamestate->api->Gamestate_Unload)(game, game->_priv.loading.gamestate->data);
|
||||
(*game->_priv.loading.gamestate->api->unload)(game, game->_priv.loading.gamestate->data);
|
||||
CloseGamestate(game, game->_priv.loading.gamestate);
|
||||
free(game->_priv.loading.gamestate);
|
||||
|
||||
|
|
|
@ -213,7 +213,7 @@ struct Game {
|
|||
struct Gamestate* gamestate;
|
||||
struct Gamestate* current;
|
||||
int progress;
|
||||
int loaded, toLoad;
|
||||
int loaded, to_load;
|
||||
volatile bool in_progress;
|
||||
double time;
|
||||
ALLEGRO_BITMAP* fb;
|
||||
|
|
|
@ -190,7 +190,7 @@ static inline bool MainloopTick(struct Game* game) {
|
|||
|
||||
struct Gamestate* tmp = game->_priv.gamestates;
|
||||
|
||||
game->_priv.loading.toLoad = 0;
|
||||
game->_priv.loading.to_load = 0;
|
||||
game->_priv.loading.loaded = 0;
|
||||
game->loading.progress = 0;
|
||||
|
||||
|
@ -199,13 +199,13 @@ static inline bool MainloopTick(struct Game* game) {
|
|||
if (tmp->pending_stop) {
|
||||
PrintConsole(game, "Stopping gamestate \"%s\"...", tmp->name);
|
||||
game->_priv.current_gamestate = tmp;
|
||||
(*tmp->api->Gamestate_Stop)(game, tmp->data);
|
||||
(*tmp->api->stop)(game, tmp->data);
|
||||
tmp->started = false;
|
||||
tmp->pending_stop = false;
|
||||
PrintConsole(game, "Gamestate \"%s\" stopped successfully.", tmp->name);
|
||||
}
|
||||
|
||||
if (tmp->pending_load) { game->_priv.loading.toLoad++; }
|
||||
if (tmp->pending_load) { game->_priv.loading.to_load++; }
|
||||
tmp = tmp->next;
|
||||
}
|
||||
|
||||
|
@ -218,14 +218,14 @@ static inline bool MainloopTick(struct Game* game) {
|
|||
tmp->loaded = false;
|
||||
tmp->pending_unload = false;
|
||||
game->_priv.current_gamestate = tmp;
|
||||
(*tmp->api->Gamestate_Unload)(game, tmp->data);
|
||||
(*tmp->api->unload)(game, tmp->data);
|
||||
al_resume_timer(game->_priv.timer);
|
||||
PrintConsole(game, "Gamestate \"%s\" unloaded successfully.", tmp->name);
|
||||
}
|
||||
if (tmp->pending_load) {
|
||||
al_stop_timer(game->_priv.timer);
|
||||
if (tmp->showLoading) {
|
||||
(*game->_priv.loading.gamestate->api->Gamestate_Start)(game, game->_priv.loading.gamestate->data);
|
||||
(*game->_priv.loading.gamestate->api->start)(game, game->_priv.loading.gamestate->data);
|
||||
}
|
||||
|
||||
if (!tmp->api) {
|
||||
|
@ -254,7 +254,7 @@ static inline bool MainloopTick(struct Game* game) {
|
|||
double delta = al_get_time() - game->_priv.loading.time;
|
||||
if (tmp->showLoading) {
|
||||
game->loading.shown = true;
|
||||
(*game->_priv.loading.gamestate->api->Gamestate_Logic)(game, game->_priv.loading.gamestate->data, delta);
|
||||
(*game->_priv.loading.gamestate->api->logic)(game, game->_priv.loading.gamestate->data, delta);
|
||||
DrawGamestates(game);
|
||||
}
|
||||
game->_priv.loading.time += delta;
|
||||
|
@ -289,9 +289,9 @@ static inline bool MainloopTick(struct Game* game) {
|
|||
|
||||
al_set_new_bitmap_flags(data.bitmap_flags);
|
||||
|
||||
if (tmp->api->Gamestate_PostLoad) {
|
||||
if (tmp->api->post_load) {
|
||||
PrintConsole(game, "[%s] Post-loading...", tmp->name);
|
||||
tmp->api->Gamestate_PostLoad(game, tmp->data);
|
||||
tmp->api->post_load(game, tmp->data);
|
||||
}
|
||||
|
||||
game->_priv.loading.progress++;
|
||||
|
@ -303,7 +303,7 @@ static inline bool MainloopTick(struct Game* game) {
|
|||
tmp->pending_load = false;
|
||||
}
|
||||
if (tmp->showLoading) {
|
||||
(*game->_priv.loading.gamestate->api->Gamestate_Stop)(game, game->_priv.loading.gamestate->data);
|
||||
(*game->_priv.loading.gamestate->api->stop)(game, game->_priv.loading.gamestate->data);
|
||||
game->loading.shown = false;
|
||||
}
|
||||
tmp->showLoading = true;
|
||||
|
@ -328,7 +328,7 @@ static inline bool MainloopTick(struct Game* game) {
|
|||
game->_priv.current_gamestate = tmp;
|
||||
tmp->started = true;
|
||||
tmp->pending_start = false;
|
||||
(*tmp->api->Gamestate_Start)(game, tmp->data);
|
||||
(*tmp->api->start)(game, tmp->data);
|
||||
al_resume_timer(game->_priv.timer);
|
||||
game->_priv.timestamp = al_get_time();
|
||||
PrintConsole(game, "Gamestate \"%s\" started successfully.", tmp->name);
|
||||
|
|
|
@ -19,7 +19,34 @@
|
|||
|
||||
// TODO: think about pre-allocating particle data
|
||||
|
||||
SYMBOL_EXPORT struct GravityParticleData* GravityParticleData(double dx, double dy, double gravity, double friction) {
|
||||
struct Particle {
|
||||
struct Character* character;
|
||||
bool active;
|
||||
ParticleFunc* func;
|
||||
struct ParticleState state;
|
||||
void* data;
|
||||
};
|
||||
|
||||
struct GravityParticleData {
|
||||
double dx, dy;
|
||||
double gravity;
|
||||
double friction;
|
||||
};
|
||||
|
||||
struct LinearParticleData {
|
||||
double dx, dy;
|
||||
};
|
||||
|
||||
struct FaderParticleData {
|
||||
ParticleFunc* func;
|
||||
void* data;
|
||||
double delay;
|
||||
double speed;
|
||||
double time;
|
||||
double fade;
|
||||
};
|
||||
|
||||
SYMBOL_EXPORT void* GravityParticleData(double dx, double dy, double gravity, double friction) {
|
||||
struct GravityParticleData* data = calloc(1, sizeof(struct GravityParticleData));
|
||||
data->dx = dx;
|
||||
data->dy = dy;
|
||||
|
@ -41,7 +68,7 @@ SYMBOL_EXPORT bool GravityParticle(struct Game* game, struct ParticleState* part
|
|||
return true;
|
||||
}
|
||||
|
||||
SYMBOL_EXPORT struct LinearParticleData* LinearParticleData(double dx, double dy) {
|
||||
SYMBOL_EXPORT void* LinearParticleData(double dx, double dy) {
|
||||
struct LinearParticleData* data = calloc(1, sizeof(struct LinearParticleData));
|
||||
data->dx = dx;
|
||||
data->dy = dy;
|
||||
|
@ -59,7 +86,7 @@ SYMBOL_EXPORT bool LinearParticle(struct Game* game, struct ParticleState* parti
|
|||
return true;
|
||||
}
|
||||
|
||||
SYMBOL_EXPORT struct FaderParticleData* FaderParticleData(double delay, double speed, ParticleFunc* func, void* d) {
|
||||
SYMBOL_EXPORT void* FaderParticleData(double delay, double speed, ParticleFunc* func, void* d) {
|
||||
struct FaderParticleData* data = calloc(1, sizeof(struct FaderParticleData));
|
||||
data->delay = delay;
|
||||
data->data = d;
|
||||
|
|
|
@ -34,14 +34,6 @@ struct ParticleState {
|
|||
|
||||
typedef bool ParticleFunc(struct Game* game, struct ParticleState* particle, double delta, void* data);
|
||||
|
||||
struct Particle {
|
||||
struct Character* character;
|
||||
bool active;
|
||||
ParticleFunc* func;
|
||||
struct ParticleState state;
|
||||
void* data;
|
||||
};
|
||||
|
||||
struct ParticleBucket {
|
||||
int size;
|
||||
int last;
|
||||
|
@ -50,32 +42,13 @@ struct ParticleBucket {
|
|||
struct Particle* particles;
|
||||
};
|
||||
|
||||
struct GravityParticleData {
|
||||
double dx, dy;
|
||||
double gravity;
|
||||
double friction;
|
||||
};
|
||||
|
||||
struct GravityParticleData* GravityParticleData(double dx, double dy, double gravity, double friction);
|
||||
void* GravityParticleData(double dx, double dy, double gravity, double friction);
|
||||
bool GravityParticle(struct Game* game, struct ParticleState* particle, double delta, void* d);
|
||||
|
||||
struct LinearParticleData {
|
||||
double dx, dy;
|
||||
};
|
||||
|
||||
struct LinearParticleData* LinearParticleData(double dx, double dy);
|
||||
void* LinearParticleData(double dx, double dy);
|
||||
bool LinearParticle(struct Game* game, struct ParticleState* particle, double delta, void* d);
|
||||
|
||||
struct FaderParticleData {
|
||||
ParticleFunc* func;
|
||||
void* data;
|
||||
double delay;
|
||||
double speed;
|
||||
double time;
|
||||
double fade;
|
||||
};
|
||||
|
||||
struct FaderParticleData* FaderParticleData(double delay, double speed, ParticleFunc* func, void* d);
|
||||
void* FaderParticleData(double delay, double speed, ParticleFunc* func, void* d);
|
||||
bool FaderParticle(struct Game* game, struct ParticleState* particle, double delta, void* d);
|
||||
|
||||
struct ParticleState SpawnParticleIn(float x, float y);
|
||||
|
|
Loading…
Reference in a new issue