mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2024-12-05 00:38:00 +01:00
even more rumina hacks. now let's clean it up :)
This commit is contained in:
parent
e0f7e057ca
commit
5c2618f4ce
7 changed files with 95 additions and 23 deletions
|
@ -149,8 +149,10 @@ SYMBOL_EXPORT struct Character* CreateCharacter(struct Game* game, char* name) {
|
|||
character->pos_tmp = 0;
|
||||
character->x = -1;
|
||||
character->y = -1;
|
||||
character->pivotx = 0.5;
|
||||
character->pivoty = 0.5;
|
||||
character->pivotX = 0.5;
|
||||
character->pivotY = 0.5;
|
||||
character->confineX = -1;
|
||||
character->confineY = -1;
|
||||
character->spritesheets = NULL;
|
||||
character->spritesheet = NULL;
|
||||
character->successor = NULL;
|
||||
|
@ -212,7 +214,7 @@ SYMBOL_EXPORT void AnimateCharacter(struct Game* game, struct Character* charact
|
|||
}
|
||||
|
||||
SYMBOL_EXPORT void MoveCharacter(struct Game* game, struct Character* character, float x, float y, float angle) {
|
||||
MoveCharacterF(game, character, x / (float)game->viewport.width, y / (float)game->viewport.height, angle);
|
||||
MoveCharacterF(game, character, x / (float)GetCharacterConfineX(game, character), y / (float)GetCharacterConfineY(game, character), angle);
|
||||
}
|
||||
|
||||
SYMBOL_EXPORT void MoveCharacterF(struct Game* game, struct Character* character, float x, float y, float angle) {
|
||||
|
@ -230,19 +232,19 @@ SYMBOL_EXPORT void SetCharacterPositionF(struct Game* game, struct Character* ch
|
|||
}
|
||||
|
||||
SYMBOL_EXPORT void SetCharacterPosition(struct Game* game, struct Character* character, float x, float y, float angle) {
|
||||
SetCharacterPositionF(game, character, x / (float)game->viewport.width, y / (float)game->viewport.height, angle);
|
||||
SetCharacterPositionF(game, character, x / (float)GetCharacterConfineX(game, character), y / (float)GetCharacterConfineY(game, character), angle);
|
||||
}
|
||||
|
||||
SYMBOL_EXPORT void SetCharacterPivotPoint(struct Game* game, struct Character* character, float x, float y) {
|
||||
character->pivotx = x;
|
||||
character->pivoty = y;
|
||||
character->pivotX = x;
|
||||
character->pivotY = y;
|
||||
}
|
||||
|
||||
SYMBOL_EXPORT void DrawScaledCharacterF(struct Game* game, struct Character* character, ALLEGRO_COLOR tint, float scalex, float scaley, int flags) {
|
||||
if (character->dead) { return; }
|
||||
int spritesheetX = al_get_bitmap_width(character->bitmap) * (character->pos % character->spritesheet->cols);
|
||||
int spritesheetY = al_get_bitmap_height(character->bitmap) * (character->pos / character->spritesheet->cols);
|
||||
al_draw_tinted_scaled_rotated_bitmap_region(character->spritesheet->bitmap, spritesheetX, spritesheetY, al_get_bitmap_width(character->bitmap), al_get_bitmap_height(character->bitmap), tint, al_get_bitmap_width(character->bitmap) * character->pivotx, al_get_bitmap_height(character->bitmap) * character->pivoty, character->x * game->viewport.width + al_get_bitmap_width(character->bitmap) * scalex * character->pivotx, character->y * game->viewport.height + al_get_bitmap_height(character->bitmap) * scaley * character->pivoty, scalex, scaley, character->angle, flags);
|
||||
al_draw_tinted_scaled_rotated_bitmap_region(character->spritesheet->bitmap, spritesheetX, spritesheetY, al_get_bitmap_width(character->bitmap), al_get_bitmap_height(character->bitmap), tint, al_get_bitmap_width(character->bitmap) * character->pivotX, al_get_bitmap_height(character->bitmap) * character->pivotY, GetCharacterX(game, character) + al_get_bitmap_width(character->bitmap) * scalex * character->pivotX, GetCharacterY(game, character) + al_get_bitmap_height(character->bitmap) * scaley * character->pivotY, scalex, scaley, character->angle, flags);
|
||||
}
|
||||
|
||||
SYMBOL_EXPORT void DrawCharacterF(struct Game* game, struct Character* character, ALLEGRO_COLOR tint, int flags) {
|
||||
|
@ -253,7 +255,7 @@ SYMBOL_EXPORT void DrawScaledCharacter(struct Game* game, struct Character* char
|
|||
if (character->dead) { return; }
|
||||
int spritesheetX = al_get_bitmap_width(character->bitmap) * (character->pos % character->spritesheet->cols);
|
||||
int spritesheetY = al_get_bitmap_height(character->bitmap) * (character->pos / character->spritesheet->cols);
|
||||
al_draw_tinted_scaled_rotated_bitmap_region(character->spritesheet->bitmap, spritesheetX, spritesheetY, al_get_bitmap_width(character->bitmap), al_get_bitmap_height(character->bitmap), tint, al_get_bitmap_width(character->bitmap) * character->pivotx, al_get_bitmap_height(character->bitmap) * character->pivoty, (int)(character->x * game->viewport.width + al_get_bitmap_width(character->bitmap) * scalex * character->pivotx), (int)(character->y * game->viewport.height + al_get_bitmap_height(character->bitmap) * scaley * character->pivoty), scalex, scaley, character->angle, flags);
|
||||
al_draw_tinted_scaled_rotated_bitmap_region(character->spritesheet->bitmap, spritesheetX, spritesheetY, al_get_bitmap_width(character->bitmap), al_get_bitmap_height(character->bitmap), tint, al_get_bitmap_width(character->bitmap) * character->pivotX, al_get_bitmap_height(character->bitmap) * character->pivotY, (int)(GetCharacterX(game, character) + al_get_bitmap_width(character->bitmap) * scalex * character->pivotX), (int)(GetCharacterY(game, character) + al_get_bitmap_height(character->bitmap) * scaley * character->pivotY), scalex, scaley, character->angle, flags);
|
||||
}
|
||||
|
||||
SYMBOL_EXPORT void DrawCharacter(struct Game* game, struct Character* character, ALLEGRO_COLOR tint, int flags) {
|
||||
|
@ -263,12 +265,25 @@ SYMBOL_EXPORT void DrawCharacter(struct Game* game, struct Character* character,
|
|||
DrawScaledCharacter(game, character, tint, 1, 1, flags);
|
||||
}
|
||||
|
||||
SYMBOL_EXPORT void SetCharacterConfines(struct Game* game, struct Character* character, int x, int y) {
|
||||
character->confineX = x;
|
||||
character->confineY = y;
|
||||
}
|
||||
|
||||
SYMBOL_EXPORT int GetCharacterConfineX(struct Game* game, struct Character* character) {
|
||||
return (character->confineX >= 0) ? character->confineX : game->viewport.width;
|
||||
}
|
||||
|
||||
SYMBOL_EXPORT int GetCharacterConfineY(struct Game* game, struct Character* character) {
|
||||
return (character->confineY >= 0) ? character->confineY : game->viewport.height;
|
||||
}
|
||||
|
||||
SYMBOL_EXPORT int GetCharacterX(struct Game* game, struct Character* character) {
|
||||
return character->x * game->viewport.width;
|
||||
return character->x * GetCharacterConfineX(game, character);
|
||||
}
|
||||
|
||||
SYMBOL_EXPORT int GetCharacterY(struct Game* game, struct Character* character) {
|
||||
return character->y * game->viewport.height;
|
||||
return character->y * GetCharacterConfineY(game, character);
|
||||
}
|
||||
|
||||
SYMBOL_EXPORT float GetCharacterAngle(struct Game* game, struct Character* character) {
|
||||
|
|
|
@ -55,7 +55,8 @@ struct Character {
|
|||
float x; /*!< Horizontal position of character. */
|
||||
float y; /*!< Vertical position of character. */
|
||||
float angle; /*!< Characters display angle (radians). */
|
||||
float pivotx, pivoty; /*!< Pivot point, relative of character's size. */
|
||||
float pivotX, pivotY; /*!< Pivot point, relative of character's size. */
|
||||
int confineX, confineY;
|
||||
void* data; /*!< Additional, custom character data (HP etc.). */
|
||||
int repeat;
|
||||
bool shared;
|
||||
|
@ -83,10 +84,13 @@ void MoveCharacterF(struct Game* game, struct Character* character, float x, flo
|
|||
void SetCharacterPosition(struct Game* game, struct Character* character, float x, float y, float angle);
|
||||
void SetCharacterPositionF(struct Game* game, struct Character* character, float x, float y, float angle);
|
||||
void SetCharacterPivotPoint(struct Game* game, struct Character* character, float x, float y);
|
||||
void SetCharacterConfines(struct Game* game, struct Character* character, int x, int y);
|
||||
|
||||
int GetCharacterX(struct Game* game, struct Character* character);
|
||||
int GetCharacterY(struct Game* game, struct Character* character);
|
||||
float GetCharacterAngle(struct Game* game, struct Character* character);
|
||||
int GetCharacterConfineX(struct Game* game, struct Character* character);
|
||||
int GetCharacterConfineY(struct Game* game, struct Character* character);
|
||||
|
||||
bool IsOnCharacter(struct Game* game, struct Character* character, int x, int y);
|
||||
|
||||
|
|
|
@ -37,8 +37,13 @@ SYMBOL_INTERNAL void SimpleCompositor(struct Game* game, struct Gamestate* games
|
|||
}
|
||||
|
||||
SYMBOL_INTERNAL void DrawGamestates(struct Game* game) {
|
||||
ClearScreen(game);
|
||||
if (!game->handlers.compositor) {
|
||||
ClearScreen(game);
|
||||
}
|
||||
struct Gamestate* tmp = game->_priv.gamestates;
|
||||
if (game->handlers.predraw) {
|
||||
(*game->handlers.predraw)(game);
|
||||
}
|
||||
while (tmp) {
|
||||
if ((tmp->loaded) && (tmp->started)) {
|
||||
game->_priv.current_gamestate = tmp;
|
||||
|
@ -55,6 +60,7 @@ SYMBOL_INTERNAL void DrawGamestates(struct Game* game) {
|
|||
if (game->handlers.compositor) {
|
||||
ALLEGRO_TRANSFORM t;
|
||||
al_set_target_backbuffer(game->display);
|
||||
ClearScreen(game);
|
||||
al_identity_transform(&t);
|
||||
/* double factor = (sin(al_get_time()) / 2.0 + 1.0) * 2;
|
||||
al_translate_transform(&t, -game->_priv.clip_rect.w / factor, -game->_priv.clip_rect.h / factor);
|
||||
|
@ -64,10 +70,16 @@ SYMBOL_INTERNAL void DrawGamestates(struct Game* game) {
|
|||
al_use_transform(&t);
|
||||
game->handlers.compositor(game, game->_priv.gamestates);
|
||||
}
|
||||
if (game->handlers.postdraw) {
|
||||
(*game->handlers.postdraw)(game);
|
||||
}
|
||||
}
|
||||
|
||||
SYMBOL_INTERNAL void LogicGamestates(struct Game* game, double delta) {
|
||||
struct Gamestate* tmp = game->_priv.gamestates;
|
||||
if (game->handlers.prelogic) {
|
||||
(*game->handlers.prelogic)(game, delta);
|
||||
}
|
||||
while (tmp) {
|
||||
if ((tmp->loaded) && (tmp->started) && (!tmp->paused)) {
|
||||
game->_priv.current_gamestate = tmp;
|
||||
|
@ -75,6 +87,9 @@ SYMBOL_INTERNAL void LogicGamestates(struct Game* game, double delta) {
|
|||
}
|
||||
tmp = tmp->next;
|
||||
}
|
||||
if (game->handlers.postlogic) {
|
||||
(*game->handlers.postlogic)(game, delta);
|
||||
}
|
||||
}
|
||||
|
||||
SYMBOL_INTERNAL void ReloadGamestates(struct Game* game) {
|
||||
|
@ -142,6 +157,7 @@ SYMBOL_INTERNAL void DrawConsole(struct Game* game) {
|
|||
int clipX, clipY, clipWidth, clipHeight;
|
||||
al_get_clipping_rectangle(&clipX, &clipY, &clipWidth, &clipHeight);
|
||||
al_use_transform(&trans);
|
||||
al_hold_bitmap_drawing(true);
|
||||
|
||||
int width = (al_get_display_width(game->display) / game->viewport.width) * game->viewport.width;
|
||||
if (!game->viewport.integer_scaling) {
|
||||
|
@ -169,6 +185,7 @@ SYMBOL_INTERNAL void DrawConsole(struct Game* game) {
|
|||
|
||||
DrawTimelines(game);
|
||||
}
|
||||
al_hold_bitmap_drawing(false);
|
||||
|
||||
double game_time = al_get_time();
|
||||
if (game_time - game->_priv.fps_count.old_time >= 1.0) {
|
||||
|
@ -390,15 +407,10 @@ SYMBOL_INTERNAL void RemoveTimeline(struct Game* game, struct Timeline* timeline
|
|||
}
|
||||
|
||||
SYMBOL_INTERNAL void ClearScreen(struct Game* game) {
|
||||
ALLEGRO_TRANSFORM identity;
|
||||
al_set_target_backbuffer(game->display);
|
||||
al_set_clipping_rectangle(0, 0, al_get_display_width(game->display), al_get_display_height(game->display));
|
||||
al_identity_transform(&identity);
|
||||
al_use_transform(&identity);
|
||||
al_clear_to_color(al_map_rgb(0, 0, 0));
|
||||
al_use_transform(&game->projection);
|
||||
al_set_clipping_rectangle(game->_priv.clip_rect.x, game->_priv.clip_rect.y, game->_priv.clip_rect.w, game->_priv.clip_rect.h);
|
||||
// al_clear_to_color(al_map_rgb(0, 0, 0));
|
||||
}
|
||||
|
||||
static void DrawQueue(struct Game* game, struct TM_Action* queue, int clipX, int clipY) {
|
||||
|
|
|
@ -77,6 +77,10 @@ SYMBOL_EXPORT struct Game* libsuperderpy_init(int argc, char** argv, const char*
|
|||
game->handlers.event = NULL;
|
||||
game->handlers.destroy = NULL;
|
||||
game->handlers.compositor = NULL;
|
||||
game->handlers.prelogic = NULL;
|
||||
game->handlers.postlogic = NULL;
|
||||
game->handlers.predraw = NULL;
|
||||
game->handlers.postdraw = NULL;
|
||||
|
||||
game->config.fullscreen = strtol(GetConfigOptionDefault(game, "SuperDerpy", "fullscreen", "1"), NULL, 10);
|
||||
game->config.music = strtol(GetConfigOptionDefault(game, "SuperDerpy", "music", "10"), NULL, 10);
|
||||
|
@ -144,12 +148,11 @@ SYMBOL_EXPORT struct Game* libsuperderpy_init(int argc, char** argv, const char*
|
|||
|
||||
al_install_joystick();
|
||||
|
||||
al_set_new_display_flags((game->config.fullscreen ? (ALLEGRO_FULLSCREEN_WINDOW | ALLEGRO_FRAMELESS) : ALLEGRO_WINDOWED) | ALLEGRO_RESIZABLE | ALLEGRO_OPENGL | ALLEGRO_PROGRAMMABLE_PIPELINE);
|
||||
al_set_new_display_flags((game->config.fullscreen ? (ALLEGRO_FULLSCREEN_WINDOW | ALLEGRO_FRAMELESS) : ALLEGRO_WINDOWED) | ALLEGRO_RESIZABLE | ALLEGRO_OPENGL_3_0 | ALLEGRO_PROGRAMMABLE_PIPELINE);
|
||||
#ifdef __EMSCRIPTEN__
|
||||
al_set_new_display_flags((al_get_new_display_flags() | ALLEGRO_WINDOWED) ^ ALLEGRO_FULLSCREEN_WINDOW);
|
||||
#endif
|
||||
al_set_new_display_option(ALLEGRO_VSYNC, 2 - strtol(GetConfigOptionDefault(game, "SuperDerpy", "vsync", "1"), NULL, 10), ALLEGRO_SUGGEST);
|
||||
al_set_new_display_option(ALLEGRO_OPENGL, true, ALLEGRO_REQUIRE);
|
||||
|
||||
#ifdef LIBSUPERDERPY_ORIENTATION_LANDSCAPE
|
||||
al_set_new_display_option(ALLEGRO_SUPPORTED_ORIENTATIONS, ALLEGRO_DISPLAY_ORIENTATION_LANDSCAPE, ALLEGRO_SUGGEST);
|
||||
|
@ -157,6 +160,8 @@ SYMBOL_EXPORT struct Game* libsuperderpy_init(int argc, char** argv, const char*
|
|||
al_set_new_display_option(ALLEGRO_SUPPORTED_ORIENTATIONS, ALLEGRO_DISPLAY_ORIENTATION_PORTRAIT, ALLEGRO_SUGGEST);
|
||||
#endif
|
||||
|
||||
al_set_new_display_option(ALLEGRO_DEPTH_SIZE, 24, ALLEGRO_SUGGEST);
|
||||
|
||||
#ifdef ALLEGRO_WINDOWS
|
||||
al_set_new_window_position(20, 40); // workaround nasty Windows bug with window being created off-screen
|
||||
#endif
|
||||
|
@ -164,7 +169,7 @@ SYMBOL_EXPORT struct Game* libsuperderpy_init(int argc, char** argv, const char*
|
|||
al_set_new_window_title(game->name);
|
||||
game->display = al_create_display(game->config.width, game->config.height);
|
||||
if (!game->display) {
|
||||
fprintf(stderr, "failed to create display!\n");
|
||||
fprintf(stderr, "Failed to create display!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -176,6 +181,32 @@ SYMBOL_EXPORT struct Game* libsuperderpy_init(int argc, char** argv, const char*
|
|||
SetupViewport(game, viewport);
|
||||
|
||||
PrintConsole(game, "Viewport %dx%d", game->viewport.width, game->viewport.height);
|
||||
PrintConsole(game, "Max bitmap size: %d", al_get_display_option(game->display, ALLEGRO_MAX_BITMAP_SIZE));
|
||||
PrintConsole(game, "Color buffer bits: %d", al_get_display_option(game->display, ALLEGRO_COLOR_SIZE));
|
||||
PrintConsole(game, "Depth buffer bits: %d", al_get_display_option(game->display, ALLEGRO_DEPTH_SIZE));
|
||||
PrintConsole(game, "Stencil buffer bits: %d", al_get_display_option(game->display, ALLEGRO_STENCIL_SIZE));
|
||||
PrintConsole(game, "NPOT bitmaps: %d", al_get_display_option(game->display, ALLEGRO_SUPPORT_NPOT_BITMAP));
|
||||
PrintConsole(game, "Separate alpha: %d", al_get_display_option(game->display, ALLEGRO_SUPPORT_SEPARATE_ALPHA));
|
||||
|
||||
if (!al_get_display_option(game->display, ALLEGRO_COMPATIBLE_DISPLAY)) {
|
||||
al_destroy_display(game->display);
|
||||
fprintf(stderr, "Created display is Allegro incompatible!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!al_get_display_option(game->display, ALLEGRO_CAN_DRAW_INTO_BITMAP)) {
|
||||
FatalError(game, true, "The created display does not support drawing into bitmaps.");
|
||||
al_destroy_display(game->display);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!al_get_display_option(game->display, ALLEGRO_RENDER_METHOD)) {
|
||||
FatalError(game, true, "Failed to create hardware accelerated display.");
|
||||
al_destroy_display(game->display);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PrintConsole(game, "libsuperderpy display created :)");
|
||||
|
||||
ALLEGRO_BITMAP* icon = al_load_bitmap(GetDataFilePath(game, GetGameName(game, "icons/%s.png")));
|
||||
al_set_display_icon(game->display, icon);
|
||||
|
@ -369,6 +400,7 @@ SYMBOL_INTERNAL void libsuperderpy_mainloop(void* g) {
|
|||
al_run_detached_thread(GamestateLoadingThread, &data);
|
||||
while (game->_priv.loading.inProgress) {
|
||||
DrawGamestates(game);
|
||||
al_set_target_backbuffer(game->display);
|
||||
if (tmp->showLoading) {
|
||||
(*game->_priv.loading.gamestate->api->Gamestate_Draw)(game, game->_priv.loading.gamestate->data);
|
||||
}
|
||||
|
@ -435,6 +467,7 @@ SYMBOL_INTERNAL void libsuperderpy_mainloop(void* g) {
|
|||
|
||||
DrawGamestates(game);
|
||||
DrawConsole(game);
|
||||
//al_wait_for_vsync();
|
||||
al_flip_display();
|
||||
redraw = false;
|
||||
|
||||
|
|
|
@ -152,6 +152,10 @@ struct Game {
|
|||
bool (*event)(struct Game* game, ALLEGRO_EVENT* ev);
|
||||
void (*destroy)(struct Game* game);
|
||||
void (*compositor)(struct Game* game, struct Gamestate* gamestates);
|
||||
void (*prelogic)(struct Game* game, double delta);
|
||||
void (*postlogic)(struct Game* game, double delta);
|
||||
void (*predraw)(struct Game* game);
|
||||
void (*postdraw)(struct Game* game);
|
||||
} handlers;
|
||||
|
||||
LIBSUPERDERPY_DATA_TYPE* data;
|
||||
|
|
|
@ -46,6 +46,7 @@ SYMBOL_EXPORT void DrawHorizontalGradientRect(float x, float y, float w, float h
|
|||
}
|
||||
|
||||
SYMBOL_EXPORT void DrawTextWithShadow(ALLEGRO_FONT* font, ALLEGRO_COLOR color, float x, float y, int flags, char const* text) {
|
||||
// TODO: consider using a set of shaders
|
||||
al_draw_text(font, al_map_rgba(0, 0, 0, 128), x + 1, y + 1, flags, text);
|
||||
al_draw_text(font, color, x, y, flags, text);
|
||||
}
|
||||
|
@ -491,15 +492,17 @@ SYMBOL_EXPORT void SetFramebufferAsTarget(struct Game* game) {
|
|||
|
||||
SYMBOL_EXPORT ALLEGRO_BITMAP* CreateNotPreservedBitmap(int width, int height) {
|
||||
int flags = al_get_new_bitmap_flags();
|
||||
//al_set_new_bitmap_depth(24);
|
||||
al_add_new_bitmap_flag(ALLEGRO_NO_PRESERVE_TEXTURE);
|
||||
ALLEGRO_BITMAP* bitmap = al_create_bitmap(width, height);
|
||||
al_set_new_bitmap_flags(flags);
|
||||
//al_set_new_bitmap_depth(0);
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
SYMBOL_EXPORT void EnableCompositor(struct Game* game) {
|
||||
SYMBOL_EXPORT void EnableCompositor(struct Game* game, void compositor(struct Game* game, struct Gamestate* gamestates)) {
|
||||
PrintConsole(game, "Compositor enabled.");
|
||||
game->handlers.compositor = SimpleCompositor;
|
||||
game->handlers.compositor = compositor ? compositor : SimpleCompositor;
|
||||
ResizeGamestates(game);
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#endif
|
||||
|
||||
struct Viewport;
|
||||
struct Gamestate;
|
||||
|
||||
/*! \brief Draws rectangle filled with vertical gradient. */
|
||||
void DrawVerticalGradientRect(float x, float y, float w, float h, ALLEGRO_COLOR top, ALLEGRO_COLOR bottom);
|
||||
|
@ -82,7 +83,7 @@ void SetFramebufferAsTarget(struct Game* game);
|
|||
|
||||
ALLEGRO_BITMAP* CreateNotPreservedBitmap(int width, int height);
|
||||
|
||||
void EnableCompositor(struct Game* game);
|
||||
void EnableCompositor(struct Game* game, void compositor(struct Game* game, struct Gamestate* gamestates));
|
||||
void DisableCompositor(struct Game* game);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue