From 60bafccdd2868cd2800aee081075342472c3b543 Mon Sep 17 00:00:00 2001 From: Neil McGill Date: Sun, 26 May 2024 16:34:06 +0100 Subject: [PATCH] fix sdl message box not appearing --- src/gfx.cpp | 10 --- src/level.cpp | 9 ++- src/level_dungeon.cpp | 128 ++++++++++++++++++++++++++--------- src/log.cpp | 7 +- src/my_ascii.hpp | 4 +- src/my_game_defs.hpp | 6 +- src/my_thing.hpp | 2 +- src/sdl.cpp | 10 +-- src/util.cpp | 8 +-- src/wid_rightbar.cpp | 133 +++++++++++++++++++++++++++++++++++-- src/wid_rightbar_ascii.cpp | 133 ------------------------------------- 11 files changed, 252 insertions(+), 198 deletions(-) delete mode 100644 src/wid_rightbar_ascii.cpp diff --git a/src/gfx.cpp b/src/gfx.cpp index 7d545e0..f308f39 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -845,15 +845,6 @@ static void gfx_ui_init_15(void) } } -static void gfx_init_rightbar(void) -{ - const char *tiles[] = { - "ui_rightbar", - }; - - tile_load_arr_sprites("data/gfx/ui/ui_rightbar.tga", "rightbar", 104, 256, ARRAY_SIZE(tiles), tiles, GL_NEAREST); -} - static void gfx_init_ui(void) {} void gfx_init(void) @@ -863,7 +854,6 @@ void gfx_init(void) // begin sort marker1 { gfx_init_12x12(); gfx_init_24x24(); - gfx_init_rightbar(); gfx_init_ui(); gfx_ui_init_0(); gfx_ui_init_1(); diff --git a/src/level.cpp b/src/level.cpp index d863721..66e970d 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -22,7 +22,14 @@ Levelp level_new(void) // NOTE: if we use "new" here, the initialization is visibly slower. // DO NOT USE C++ classes or types // - Levelp l = (Levelp) myzalloc(SIZEOF(*l), "l"); + Levelp l; + LOG("Level memory: %u Mb", SIZEOF(Level) / (1024 * 1024)); + LOG("Thing AI: %u Mb", SIZEOF(l->thing_ai) / (1024 * 1024)); + LOG("Thing structs: %u Mb", SIZEOF(l->thing_body) / (1024 * 1024)); + LOG("Thing IDs: %u Mb", SIZEOF(l->thing_id) / (1024 * 1024)); + LOG("Thing size: %u b", SIZEOF(Thing)); + + l = (Levelp) myzalloc(SIZEOF(*l), "l"); if (! l) { return nullptr; } diff --git a/src/level_dungeon.cpp b/src/level_dungeon.cpp index 38e2b0b..5b14390 100644 --- a/src/level_dungeon.cpp +++ b/src/level_dungeon.cpp @@ -7,36 +7,100 @@ void level_dungeon_create_and_place(Levelp l, int z) { level_map_set(l, z, - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" - "x1..x...........x..............x" - "x...x=xx=x......x..xxxx==xxxx..x" - "x...x..x..x.....x..xxxx...xxx..x" - "x...x..xx..x....x..xxx.....=...x" - "x...=.xx....x...x...=......=...x" - "x...=..x.....x..x..xxx.....=...x" - "xxx.=.xxx.....x.x..xxxx...xxx..x" - "x...=...xxx.....x..xxxx==xxxx..x" - "x...=.xxx.......x..............x" - "x...=.......xxxxx...x.......x..x" - "x..xxxxx........x..x.x=====x...x" - "x......x........x...x.....x....x" - "xx...xxx........x........x.....x" - "x..............x........x......x" - "xxxx.xxx......x..x.....x.......x" - "x..x.x...........xx............x" - "x..x.x............x.x......x...x" - "x..x.x....xxx.......x..xxxxxxx.x" - "x.........x.x.....xxx....x.....x" - "x..xxx.x..xxx.....xx...........x" - "x...x..x...........x...x....x..x" - "x.........xxx...........x..x...x" - "x...x..xx.xxx......x...x.......x" - "x..xxx....xxx.xxxxxx....x...x..x" - "x...x...x..........x...x...x...x" - "x.......x..........x....x......x" - "x.......x..........x...........x" - "x.......x.........xxxxxxxxxxxxxx" - "x.......x......................x" - "x.......x.....................Ex" - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xx...............x............................................................................xx" + "xx...............x............................................................................xx" + "xx.....1.........x............................................................................xx" + "xx...............x............................................................................xx" + "xx.........xxxxxxx............................................................................xx" + "xxxxx......x.....=............................................................................xx" + "xx..x............=............................................................................xx" + "xx..x......x.....=............................................................................xx" + "xx..x......x.....=............................................................................xx" + "xx..xx====xx.xxxxx............................................................................xx" + "xx............................................................................................xx" + "xx.........x..................................................................................xx" + "xx..........x.................................................................................xx" + "xx...........x................................................................................xx" + "xx............x...............................................................................xx" + "xx.............x..............................................................................xx" + "xx..............x.............................................................................xx" + "xx...............x............................................................................xx" + "xx................x...........................................................................xx" + "xx.................x..........................................................................xx" + "xx..................x.........................................................................xx" + "xx...................x........................................................................xx" + "xx....................x.......................................................................xx" + "xx.....................x......................................................................xx" + "xx......................x.....................................................................xx" + "xx.......................x....................................................................xx" + "xx........................x...................................................................xx" + "xx.........................x..................................................................xx" + "xx..........................x.................................................................xx" + "xx...........................x................................................................xx" + "xx............................x...............................................................xx" + "xx.............................x..............................................................xx" + "xx..............................x.............................................................xx" + "xx...............................x............................................................xx" + "xx................................x...........................................................xx" + "xx.................................x..........................................................xx" + "xx..................................x.........................................................xx" + "xx...................................x........................................................xx" + "xx....................................x.......................................................xx" + "xx.....................................x......................................................xx" + "xx......................................x.....................................................xx" + "xx.......................................x....................................................xx" + "xx........................................x...................................................xx" + "xx.........................................x..................................................xx" + "xx..........................................x.................................................xx" + "xx...........................................x................................................xx" + "xx............................................x...............................................xx" + "xx.............................................x..............................................xx" + "xx..............................................x.............................................xx" + "xx...............................................x............................................xx" + "xx................................................x...........................................xx" + "xx.................................................x..........................................xx" + "xx..................................................x.........................................xx" + "xx...................................................x........................................xx" + "xx....................................................x.......................................xx" + "xx.....................................................x......................................xx" + "xx......................................................x.....................................xx" + "xx.......................................................x....................................xx" + "xx........................................................x...................................xx" + "xx.........................................................x..................................xx" + "xx..........................................................x.................................xx" + "xx...........................................................x................................xx" + "xx............................................................x...............................xx" + "xx.............................................................x..............................xx" + "xx..............................................................x.............................xx" + "xx...............................................................x............................xx" + "xx................................................................x...........................xx" + "xx.................................................................x..........................xx" + "xx..................................................................x.........................xx" + "xx...................................................................x........................xx" + "xx....................................................................x.......................xx" + "xx.....................................................................x......................xx" + "xx......................................................................x.....................xx" + "xx.......................................................................x....................xx" + "xx........................................................................x...................xx" + "xx.........................................................................x..................xx" + "xx..........................................................................x.................xx" + "xx...........................................................................x................xx" + "xx............................................................................x...............xx" + "xx.............................................................................x..............xx" + "xx..............................................................................x.............xx" + "xx...............................................................................x............xx" + "xx................................................................................x...........xx" + "xx.................................................................................x..........xx" + "xx..................................................................................x.........xx" + "xx...................................................................................x........xx" + "xx....................................................................................x.......xx" + "xx.....................................................................................x......xx" + "xx......................................................................................x.....xx" + "xx.......................................................................................x....xx" + "xx............................................................................................xx" + "xx...........................................................................................Exx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); } diff --git a/src/log.cpp b/src/log.cpp index 6618988..cc65418 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -7,6 +7,8 @@ #include "my_callstack.hpp" #include "my_console.hpp" #include "my_log.hpp" +#include "my_sdl_event.hpp" +#include "my_sdl_proto.hpp" #include "my_string.hpp" #include "my_wid_console.hpp" @@ -466,7 +468,10 @@ static void sdl_msgerr_(const char *fmt, va_list args) #if SDL_MAJOR_VERSION >= 2 CON("INF: Show SDL message box"); - SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "gorget", buf, nullptr); + // + // The window is needed else the box appears behind the main window. + // + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "gorget", buf, sdl.window); CON("INF: Finished SDL message box"); #endif } diff --git a/src/my_ascii.hpp b/src/my_ascii.hpp index 915bbb6..91fe511 100644 --- a/src/my_ascii.hpp +++ b/src/my_ascii.hpp @@ -11,8 +11,8 @@ #include "my_tile.hpp" #include "my_ui.hpp" -#define TERM_GFX_WIDTH_DEF 80 -#define TERM_GFX_HEIGHT_DEF 40 +#define TERM_GFX_WIDTH_DEF 120 +#define TERM_GFX_HEIGHT_DEF 80 #define TERM_WIDTH_MAX (TERM_GFX_WIDTH_DEF * 2) #define TERM_HEIGHT_MAX (TERM_GFX_HEIGHT_DEF * 2) diff --git a/src/my_game_defs.hpp b/src/my_game_defs.hpp index 8c92c97..ff93a17 100644 --- a/src/my_game_defs.hpp +++ b/src/my_game_defs.hpp @@ -6,9 +6,9 @@ #ifndef _MY_GAME_DEFS_HPP_ #define _MY_GAME_DEFS_HPP_ -#define MAP_WIDTH 32 -#define MAP_HEIGHT 32 -#define MAP_DEPTH 32 +#define MAP_WIDTH 96 +#define MAP_HEIGHT 96 +#define MAP_DEPTH 16 #define MAP_SLOTS 16 #define MAP_SCROLL_BORDER 0.4 #define MAP_SCROLL_SPEED 5 diff --git a/src/my_thing.hpp b/src/my_thing.hpp index 8d893cb..755727b 100644 --- a/src/my_thing.hpp +++ b/src/my_thing.hpp @@ -27,7 +27,7 @@ // Essentially equates to the max number of monsters // #define THING_AI_MAX 65535 /* sizeof ai_id */ -#define THING_MOVE_PATH_MAX (MAP_WIDTH * MAP_HEIGHT) +#define THING_MOVE_PATH_MAX MAP_WIDTH typedef struct ThingAi_ { // diff --git a/src/sdl.cpp b/src/sdl.cpp index 64d79c6..d2705b1 100644 --- a/src/sdl.cpp +++ b/src/sdl.cpp @@ -696,11 +696,7 @@ void config_game_gfx_update(void) game_pix_height_set(game, game_window_pix_height_get(game)); game_pix_width_set(game, game_window_pix_width_get(game)); - if (1) { - game_pix_height_set(game, TILE_WIDTH * 20); - } else { - game_pix_height_set(game, TILE_WIDTH * MAP_HEIGHT); - } + game_pix_height_set(game, TILE_WIDTH * MAP_HEIGHT / 4); float game_pix_width = (int) (((double) game_pix_height_get(game)) * game_aspect_ratio_get(game)); game_pix_width /= TILE_WIDTH; game_pix_width = ceil(game_pix_width); @@ -719,8 +715,8 @@ void config_game_gfx_update(void) // // Use the same resolution as the game // - game_ui_pix_width_set(game, game_pix_width_get(game)); - game_ui_pix_height_set(game, game_pix_height_get(game)); + game_ui_pix_width_set(game, game_pix_width_get(game) * 2); + game_ui_pix_height_set(game, game_pix_height_get(game) * 2); if (! TILE_WIDTH) { ERR("TILE_WIDTH zero"); diff --git a/src/util.cpp b/src/util.cpp index 4a89db2..e6566f4 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -14,7 +14,7 @@ void *myzalloc_(int size, const char *what, const char *file, const char *func, void *ptr = calloc(1, size); if (! ptr) { - DIE("No memory, %s:%s():%u", file, func, line); + DIE("No memory, %s:%s:%u, size %u", file, func, line, size); } IF_DEBUG2 { ptrcheck_alloc(MTYPE_MISC, ptr, what, size, file, func, line); } @@ -28,7 +28,7 @@ void *mymalloc_(int size, const char *what, const char *file, const char *func, void *ptr = malloc(size); if (! ptr) { - DIE("No memory, %s:%s():%u", file, func, line); + DIE("No memory, %s:%s:%u", file, func, line); } IF_DEBUG2 { ptrcheck_alloc(MTYPE_MISC, ptr, what, size, file, func, line); } @@ -43,7 +43,7 @@ void *myrealloc_(void *ptr, int size, const char *what, const char *file, const ptr = realloc(ptr, size); if (! ptr) { - DIE("No memory, %s:%s():%u", file, func, line); + DIE("No memory, %s:%s:%u", file, func, line); } IF_DEBUG2 { ptrcheck_alloc(MTYPE_MISC, ptr, what, size, file, func, line); } @@ -69,7 +69,7 @@ char *dupstr_(const char *in, const char *what, const char *file, const char *fu char *ptr = strdup(in); if (! ptr) { - DIE("No memory, %s:%s():%u", file, func, line); + DIE("No memory, %s:%s:%u", file, func, line); } int size = (__typeof__(size)) strlen(in); diff --git a/src/wid_rightbar.cpp b/src/wid_rightbar.cpp index a59cf17..91996d0 100644 --- a/src/wid_rightbar.cpp +++ b/src/wid_rightbar.cpp @@ -4,17 +4,142 @@ #include "my_ascii.hpp" #include "my_callstack.hpp" +#include "my_color_defs.hpp" #include "my_game.hpp" +#include "my_level.hpp" +#include "my_main.hpp" +#include "my_ptrcheck.hpp" #include "my_sdl_event.hpp" +#include "my_string.hpp" #include "my_wids.hpp" -static bool wid_rightbar_create(class Game *); - Widp wid_rightbar {}; Widp wid_map_mini {}; static WidPopup *wid_rightbar_popup; +static bool wid_rightbar_create_window(class Game *g) +{ + TRACE_AND_INDENT(); + DBG2("Remake rightbar"); + + auto level = game_level_get(g); + if (! level) { + return false; + } + + int width = UI_RIGHTBAR_WIDTH; + int y_at = 0; + + { + TRACE_AND_INDENT(); + point tl(TERM_WIDTH - width, 0); + point br(TERM_WIDTH - 1, TERM_HEIGHT - 1); + + wid_rightbar = wid_new_square_window("wid rightbar"); + wid_set_ignore_scroll_events(wid_rightbar, true); + wid_set_pos(wid_rightbar, tl, br); + wid_set_style(wid_rightbar, UI_WID_STYLE_NORMAL); + wid_lower(wid_rightbar); + } + + y_at = 4; + { + TRACE_AND_INDENT(); + auto w = wid_new_square_button(wid_rightbar, "level no"); + point tl(0, y_at); + point br(width - 1, y_at); + auto s = dynprintf("Level %u", level->num); + wid_set_pos(w, tl, br); + wid_set_text(w, s); + wid_set_style(w, UI_WID_STYLE_NORMAL); + wid_set_shape_none(w); + myfree(s); + } + + if (0) { + y_at++; + TRACE_AND_INDENT(); + auto w = wid_new_plain(wid_rightbar, "Seed"); + point tl(0, y_at); + point br(width - 1, y_at); + + auto s = dynprintf("Seed: %%fg=gray$%s", game_seed_name_get(game)); + wid_set_pos(w, tl, br); + wid_set_text(w, s); + wid_set_shape_none(w); + myfree(s); + } + +#if 0 + y_at = 8; + { + TRACE_AND_INDENT(); + auto w = wid_new_square_button(wid_rightbar, "player1"); + point tl(0, y_at); + point br(width - 1, y_at); + auto s = dynprintf("%04u %04u", 0, 100); + wid_set_pos(w, tl, br); + wid_set_text(w, s); + wid_set_style(w, UI_WID_STYLE_NORMAL); + wid_set_color(w, WID_COLOR_TEXT_FG, RED); + wid_set_shape_none(w); + myfree(s); + } + + y_at = 13; + { + TRACE_AND_INDENT(); + auto w = wid_new_square_button(wid_rightbar, "player2"); + point tl(0, y_at); + point br(width - 1, y_at); + auto s = dynprintf("%4u %4u", 0, 100); + wid_set_pos(w, tl, br); + wid_set_text(w, s); + wid_set_style(w, UI_WID_STYLE_NORMAL); + wid_set_color(w, WID_COLOR_TEXT_FG, DODGERBLUE); + wid_set_shape_none(w); + myfree(s); + } + + y_at = 18; + { + TRACE_AND_INDENT(); + auto w = wid_new_square_button(wid_rightbar, "player2"); + point tl(0, y_at); + point br(width - 1, y_at); + auto s = dynprintf("%4u %4u", 0, 100); + wid_set_pos(w, tl, br); + wid_set_text(w, s); + wid_set_style(w, UI_WID_STYLE_NORMAL); + wid_set_color(w, WID_COLOR_TEXT_FG, YELLOW); + wid_set_shape_none(w); + myfree(s); + } + + y_at = 23; + { + TRACE_AND_INDENT(); + auto w = wid_new_square_button(wid_rightbar, "player2"); + point tl(0, y_at); + point br(width - 1, y_at); + auto s = dynprintf("%4u %4u", 0, 100); + wid_set_pos(w, tl, br); + wid_set_text(w, s); + wid_set_style(w, UI_WID_STYLE_NORMAL); + wid_set_color(w, WID_COLOR_TEXT_FG, GREEN); + wid_set_shape_none(w); + myfree(s); + } +#endif + + wid_update(wid_rightbar); + + DBG2("Remade rightbar"); + + return true; +} + void wid_rightbar_fini(class Game *g) { TRACE_AND_INDENT(); @@ -28,7 +153,7 @@ void wid_rightbar_fini(class Game *g) bool wid_rightbar_init(class Game *g) { TRACE_AND_INDENT(); - return wid_rightbar_create(g); + return wid_rightbar_create_window(g); } bool wid_rightbar_create(class Game *g) @@ -40,7 +165,7 @@ bool wid_rightbar_create(class Game *g) return false; } - return wid_rightbar_ascii_create(g); + return wid_rightbar_create_window(g); } bool is_mouse_over_rightbar(void) diff --git a/src/wid_rightbar_ascii.cpp b/src/wid_rightbar_ascii.cpp deleted file mode 100644 index 798027b..0000000 --- a/src/wid_rightbar_ascii.cpp +++ /dev/null @@ -1,133 +0,0 @@ -// -// Copyright Neil McGill, goblinhack@gmail.com -// - -#include "my_ascii.hpp" -#include "my_callstack.hpp" -#include "my_color_defs.hpp" -#include "my_game.hpp" -#include "my_level.hpp" -#include "my_ptrcheck.hpp" -#include "my_string.hpp" -#include "my_wids.hpp" - -bool wid_rightbar_ascii_create(class Game *g) -{ - TRACE_AND_INDENT(); - DBG2("Remake rightbar"); - - auto level = game_level_get(g); - if (! level) { - return false; - } - - int width = UI_RIGHTBAR_WIDTH; - int y_at = 0; - - { - TRACE_AND_INDENT(); - point tl(TERM_WIDTH - width, 0); - point br(TERM_WIDTH - 1, TERM_HEIGHT - 1); - - wid_rightbar = wid_new_square_window("wid rightbar"); - wid_set_ignore_scroll_events(wid_rightbar, true); - wid_set_pos(wid_rightbar, tl, br); - wid_set_style(wid_rightbar, UI_WID_STYLE_NORMAL); - wid_set_tilename(TILE_LAYER_BG_0, wid_rightbar, "ui_rightbar"); - wid_lower(wid_rightbar); - } - - y_at = 4; - { - TRACE_AND_INDENT(); - auto w = wid_new_square_button(wid_rightbar, "level no"); - point tl(0, y_at); - point br(width - 1, y_at); - auto s = dynprintf("Level %u", level->num); - wid_set_pos(w, tl, br); - wid_set_text(w, s); - wid_set_style(w, UI_WID_STYLE_NORMAL); - wid_set_shape_none(w); - myfree(s); - } - - if (0) { - y_at++; - TRACE_AND_INDENT(); - auto w = wid_new_plain(wid_rightbar, "Seed"); - point tl(0, y_at); - point br(width - 1, y_at); - - auto s = dynprintf("Seed: %%fg=gray$%s", game_seed_name_get(game)); - wid_set_pos(w, tl, br); - wid_set_text(w, s); - wid_set_shape_none(w); - myfree(s); - } - - y_at = 8; - { - TRACE_AND_INDENT(); - auto w = wid_new_square_button(wid_rightbar, "player1"); - point tl(0, y_at); - point br(width - 1, y_at); - auto s = dynprintf("%04u %04u", 0, 100); - wid_set_pos(w, tl, br); - wid_set_text(w, s); - wid_set_style(w, UI_WID_STYLE_NORMAL); - wid_set_color(w, WID_COLOR_TEXT_FG, RED); - wid_set_shape_none(w); - myfree(s); - } - - y_at = 13; - { - TRACE_AND_INDENT(); - auto w = wid_new_square_button(wid_rightbar, "player2"); - point tl(0, y_at); - point br(width - 1, y_at); - auto s = dynprintf("%4u %4u", 0, 100); - wid_set_pos(w, tl, br); - wid_set_text(w, s); - wid_set_style(w, UI_WID_STYLE_NORMAL); - wid_set_color(w, WID_COLOR_TEXT_FG, DODGERBLUE); - wid_set_shape_none(w); - myfree(s); - } - - y_at = 18; - { - TRACE_AND_INDENT(); - auto w = wid_new_square_button(wid_rightbar, "player2"); - point tl(0, y_at); - point br(width - 1, y_at); - auto s = dynprintf("%4u %4u", 0, 100); - wid_set_pos(w, tl, br); - wid_set_text(w, s); - wid_set_style(w, UI_WID_STYLE_NORMAL); - wid_set_color(w, WID_COLOR_TEXT_FG, YELLOW); - wid_set_shape_none(w); - myfree(s); - } - - y_at = 23; - { - TRACE_AND_INDENT(); - auto w = wid_new_square_button(wid_rightbar, "player2"); - point tl(0, y_at); - point br(width - 1, y_at); - auto s = dynprintf("%4u %4u", 0, 100); - wid_set_pos(w, tl, br); - wid_set_text(w, s); - wid_set_style(w, UI_WID_STYLE_NORMAL); - wid_set_color(w, WID_COLOR_TEXT_FG, GREEN); - wid_set_shape_none(w); - myfree(s); - } - - wid_update(wid_rightbar); - - DBG2("Remade rightbar"); - - return true; -}