diff --git a/src/game.cpp b/src/game.cpp index 3a615db..d150f95 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -183,10 +183,12 @@ class Game // // These are the onscreen map pixel co-ords. // - int onscreen_map_tl_x; - int onscreen_map_tl_y; - int onscreen_map_br_x; - int onscreen_map_br_y; + int visible_map_tl_x; + int visible_map_tl_y; + int visible_map_br_x; + int visible_map_br_y; + int visible_map_mouse_x; + int visible_map_mouse_y; ///////////////////////////////////////////////////////////////////////// // not worth saving @@ -361,6 +363,7 @@ void Game::display(void) if (level) { level_tick(level); level_anim(level); + level_cursor_reset(level); level_display(level); } } @@ -450,20 +453,34 @@ void game_load_config(class Game *game) { game->load_config(); } class HiScores *game_hiscores_get(class Game *game) { return &game->config.hiscores; } -void game_onscreen_map_get(class Game *game, int *onscreen_map_tl_x, int *onscreen_map_tl_y, int *onscreen_map_br_x, - int *onscreen_map_br_y) +void game_visible_map_get(class Game *game, int *visible_map_tl_x, int *visible_map_tl_y, int *visible_map_br_x, + int *visible_map_br_y) { - *onscreen_map_tl_x = game->onscreen_map_tl_x, *onscreen_map_tl_y = game->onscreen_map_tl_y, - *onscreen_map_br_x = game->onscreen_map_br_x, *onscreen_map_br_y = game->onscreen_map_br_y; + *visible_map_tl_x = game->visible_map_tl_x; + *visible_map_tl_y = game->visible_map_tl_y; + *visible_map_br_x = game->visible_map_br_x; + *visible_map_br_y = game->visible_map_br_y; } -void game_onscreen_map_set(class Game *game, int onscreen_map_tl_x, int onscreen_map_tl_y, int onscreen_map_br_x, - int onscreen_map_br_y) +void game_visible_map_set(class Game *game, int visible_map_tl_x, int visible_map_tl_y, int visible_map_br_x, + int visible_map_br_y) { - game->onscreen_map_tl_x = onscreen_map_tl_x; - game->onscreen_map_tl_y = onscreen_map_tl_y; - game->onscreen_map_br_x = onscreen_map_br_x; - game->onscreen_map_br_y = onscreen_map_br_y; + game->visible_map_tl_x = visible_map_tl_x; + game->visible_map_tl_y = visible_map_tl_y; + game->visible_map_br_x = visible_map_br_x; + game->visible_map_br_y = visible_map_br_y; +} + +void game_visible_map_mouse_get(class Game *game, int *visible_map_mouse_x, int *visible_map_mouse_y) +{ + *visible_map_mouse_x = game->visible_map_mouse_x; + *visible_map_mouse_y = game->visible_map_mouse_y; +} + +void game_visible_map_mouse_set(class Game *game, int visible_map_mouse_x, int visible_map_mouse_y) +{ + game->visible_map_mouse_x = visible_map_mouse_x; + game->visible_map_mouse_y = visible_map_mouse_y; } uint32_t game_last_mouse_down_get(class Game *game) { return game->last_mouse_down; } diff --git a/src/level_cursor.cpp b/src/level_cursor.cpp index aa47dad..8561643 100644 --- a/src/level_cursor.cpp +++ b/src/level_cursor.cpp @@ -3,7 +3,9 @@ // #include "my_callstack.hpp" +#include "my_game.hpp" #include "my_level.hpp" +#include "my_sdl_event.hpp" #include "my_tp.hpp" #include @@ -28,3 +30,40 @@ int level_cursor_get(Level *l, int x, int y) return l->cursor[ x ][ y ]; } + +// +// Clear all cursors and get the mouse position, so when displaying tiles +// we can work out where the cursor is now. +// +void level_cursor_reset(Levelp l) +{ + TRACE_NO_INDENT(); + + memset(l->cursor, 0, sizeof(l->cursor)); + + // + // Get the visible map bounds + // + int visible_map_tl_x; + int visible_map_tl_y; + int visible_map_br_x; + int visible_map_br_y; + int visible_map_mouse_x; + int visible_map_mouse_y; + game_visible_map_get(game, &visible_map_tl_x, &visible_map_tl_y, &visible_map_br_x, &visible_map_br_y); + + // + // Find out what pixel on the map the mouse is over + // + visible_map_mouse_x = sdl.mouse_x - visible_map_tl_x; + visible_map_mouse_y = sdl.mouse_y; + float scale_x = (float) game_pix_width_get(game) / (float) game_window_pix_width_get(game); + float scale_y = (float) game_pix_height_get(game) / (float) game_window_pix_height_get(game); + visible_map_mouse_x = (int) ((float) visible_map_mouse_x * scale_x); + visible_map_mouse_y = (int) ((float) visible_map_mouse_y * scale_y); + + // + // Now we wait for level_display to find the cursor + // + game_visible_map_mouse_set(game, visible_map_mouse_x, visible_map_mouse_y); +} diff --git a/src/level_display.cpp b/src/level_display.cpp index 19070dc..1bc13ce 100644 --- a/src/level_display.cpp +++ b/src/level_display.cpp @@ -8,19 +8,14 @@ #include "my_gl.hpp" #include "my_level.hpp" #include "my_main.hpp" -#include "my_sdl_event.hpp" #include "my_tex.hpp" #include "my_tile.hpp" #include "my_tp.hpp" -static int onscreen_map_tl_x; -static int onscreen_map_tl_y; -static int onscreen_map_br_x; -static int onscreen_map_br_y; -static int onscreen_map_mouse_x; -static int onscreen_map_mouse_y; +static int visible_map_mouse_x; +static int visible_map_mouse_y; -static void level_display_tile(Levelp l, Tpp tp, uint16_t tile_index, point tl, point br, point offset) +static void level_display_tile_index(Levelp l, Tpp tp, uint16_t tile_index, point tl, point br, point offset) { auto tile = tile_index_to_tile(tile_index); if (! tile) { @@ -39,7 +34,7 @@ static void level_display_tile(Levelp l, Tpp tp, uint16_t tile_index, point tl, } } -static void level_display_z_layer(Levelp l, int x, int y, int slot, int z, bool deco) +static void level_display_obj(Levelp l, int x, int y, Tpp tp, Thingp t, ThingOrTp *obj, bool deco) { int dw = TILE_WIDTH; int dh = TILE_HEIGHT; @@ -47,18 +42,15 @@ static void level_display_z_layer(Levelp l, int x, int y, int slot, int z, bool point tl; point br; - Tpp tp; - auto t = level_thing_or_tp_get(l, x, y, slot, &tp); - if (! tp) { - return; - } + int tile_index; - if (tp_z_depth_get(tp) != z) { - return; + if (obj) { + tile_index = obj->tile; + } else { + Tilep tile = tp_tiles_get(tp, 0); + tile_index = tile_global_index(tile); } - auto obj = &l->obj[ x ][ y ][ slot ]; - auto tile_index = obj->tile; if (! tile_index) { return; } @@ -108,12 +100,10 @@ static void level_display_z_layer(Levelp l, int x, int y, int slot, int z, bool // // Is the cursor here? // - if (z == MAP_DEPTH_FLOOR) { - if ((onscreen_map_mouse_x >= tl.x) && (onscreen_map_mouse_x < br.x) && (onscreen_map_mouse_y >= tl.y) - && (onscreen_map_mouse_y < br.y)) { - CON("CURSOR %d %d %d,%d -> %d,%d", onscreen_map_mouse_x, onscreen_map_mouse_y, tl.x, tl.y, br.x, br.y); + if (tp_is_floor(tp)) { + if ((visible_map_mouse_x >= tl.x) && (visible_map_mouse_x < br.x) && (visible_map_mouse_y >= tl.y) + && (visible_map_mouse_y < br.y)) { level_cursor_set(l, x, y, CURSOR_AT); - return; } } @@ -130,7 +120,69 @@ static void level_display_z_layer(Levelp l, int x, int y, int slot, int z, bool tile_index += 47; } - level_display_tile(l, tp, tile_index, tl, br, point(0, 0)); + level_display_tile_index(l, tp, tile_index, tl, br, point(0, 0)); +} + +static void level_display_cursor(Levelp l, int x, int y) +{ + Tpp tp = nullptr; + + switch (l->cursor[ x ][ y ]) { + case CURSOR_NONE : + // + // Normal case. No cursor or anything else here. + // + return; + case CURSOR_PATH : + { + // + // Cursors do not use up slots on the map, to avoid them interacting with anything + // + static Tpp tp_once; + if (! tp_once) { + tp_once = tp_find("cursor_at"); + } + tp = tp_once; + break; + } + case CURSOR_AT : + { + // + // Cursors do not use up slots on the map, to avoid them interacting with anything + // + static Tpp tp_once; + if (! tp_once) { + tp_once = tp_find("cursor_at"); + } + tp = tp_once; + break; + } + } + + if (tp) { + level_display_obj(l, x, y, tp, NULL_THING, NULL_OBJ, false); + } +} + +static void level_display_slot(Levelp l, int x, int y, int slot, int z, bool deco) +{ + Tpp tp; + auto t = level_thing_or_tp_get(l, x, y, slot, &tp); + if (! tp) { + return; + } + + if (tp_z_depth_get(tp) != z) { + return; + } + + ThingOrTp *obj = &l->obj[ x ][ y ][ slot ]; + auto tile_index = obj->tile; + if (! tile_index) { + return; + } + + level_display_obj(l, x, y, tp, t, obj, deco); } void level_display(Levelp l) @@ -151,25 +203,15 @@ void level_display(Levelp l) const bool no_deco = false; // - // Get the visible map bounds - // - game_onscreen_map_get(game, &onscreen_map_tl_x, &onscreen_map_tl_y, &onscreen_map_br_x, &onscreen_map_br_y); - - // - // Find out what pixel on the map the mouse is over + // We need to find out what pixel on the map the mouse is over // - onscreen_map_mouse_x = sdl.mouse_x - onscreen_map_tl_x; - onscreen_map_mouse_y = sdl.mouse_y; - float scale_x = (float) game_pix_width_get(game) / (float) game_window_pix_width_get(game); - float scale_y = (float) game_pix_height_get(game) / (float) game_window_pix_height_get(game); - onscreen_map_mouse_x = (int) ((float) onscreen_map_mouse_x * scale_x); - onscreen_map_mouse_y = (int) ((float) onscreen_map_mouse_y * scale_y); + game_visible_map_mouse_get(game, &visible_map_mouse_x, &visible_map_mouse_y); for (auto y = l->miny; y < l->maxy; y++) { for (auto x = l->maxx - 1; x >= l->minx; x--) { for (auto slot = 0; slot < MAP_SLOTS; slot++) { - level_display_z_layer(l, x, y, slot, MAP_DEPTH_FLOOR, no_deco); - level_display_z_layer(l, x, y, slot, MAP_DEPTH_WALL, no_deco); + level_display_slot(l, x, y, slot, MAP_DEPTH_FLOOR, no_deco); + level_display_slot(l, x, y, slot, MAP_DEPTH_WALL, no_deco); } } } @@ -180,10 +222,10 @@ void level_display(Levelp l) for (auto y = l->miny; y < l->maxy; y++) { for (auto x = l->maxx - 1; x >= l->minx; x--) { for (auto slot = 0; slot < MAP_SLOTS; slot++) { - level_display_z_layer(l, x, y, slot, MAP_DEPTH_DOOR, no_deco); - level_display_z_layer(l, x, y, slot, MAP_DEPTH_OBJ1, no_deco); - level_display_z_layer(l, x, y, slot, MAP_DEPTH_OBJ2, no_deco); - level_display_z_layer(l, x, y, slot, MAP_DEPTH_PLAYER, no_deco); + level_display_slot(l, x, y, slot, MAP_DEPTH_DOOR, no_deco); + level_display_slot(l, x, y, slot, MAP_DEPTH_OBJ1, no_deco); + level_display_slot(l, x, y, slot, MAP_DEPTH_OBJ2, no_deco); + level_display_slot(l, x, y, slot, MAP_DEPTH_PLAYER, no_deco); } } } @@ -194,8 +236,8 @@ void level_display(Levelp l) for (auto y = l->miny; y < l->maxy; y++) { for (auto x = l->maxx - 1; x >= l->minx; x--) { for (auto slot = 0; slot < MAP_SLOTS; slot++) { - level_display_z_layer(l, x, y, slot, MAP_DEPTH_WALL, deco); - level_display_z_layer(l, x, y, slot, MAP_DEPTH_DOOR, deco); + level_display_slot(l, x, y, slot, MAP_DEPTH_WALL, deco); + level_display_slot(l, x, y, slot, MAP_DEPTH_DOOR, deco); } } } @@ -205,7 +247,7 @@ void level_display(Levelp l) // for (auto y = l->miny; y < l->maxy; y++) { for (auto x = l->maxx - 1; x >= l->minx; x--) { - level_display_z_layer(l, x, y, 0, MAP_DEPTH_CURSOR, no_deco); + level_display_cursor(l, x, y); } } diff --git a/src/level_player.cpp b/src/level_player.cpp index 137ce8b..5c3b51c 100644 --- a/src/level_player.cpp +++ b/src/level_player.cpp @@ -23,7 +23,7 @@ void level_thing_player_create_and_place(Levelp l) continue; } - if (! tp_is_player_get(tp)) { + if (! tp_is_player(tp)) { continue; } diff --git a/src/level_thing.cpp b/src/level_thing.cpp index 7a78fc0..980c2d0 100644 --- a/src/level_thing.cpp +++ b/src/level_thing.cpp @@ -34,39 +34,6 @@ Thingp level_thing_or_tp_get(Levelp l, int x, int y, uint8_t slot, Tpp *out) } if (! id) { - if (out) { - switch (l->cursor[ x ][ y ]) { - case CURSOR_NONE : - // - // Normal case. No cursor or anything else here. - // - return nullptr; - case CURSOR_PATH : - { - // - // Cursors do not use up slots on the map, to avoid them interacting with anything - // - static Tpp tp; - if (! tp) { - tp = tp_find("cursor_at"); - } - *out = tp; - return nullptr; - } - case CURSOR_AT : - { - // - // Cursors do not use up slots on the map, to avoid them interacting with anything - // - static Tpp tp; - if (! tp) { - tp = tp_find("cursor_at"); - } - *out = tp; - return nullptr; - } - } - } return nullptr; } diff --git a/src/level_tiles.cpp b/src/level_tiles.cpp index ae2456a..c9da823 100644 --- a/src/level_tiles.cpp +++ b/src/level_tiles.cpp @@ -176,7 +176,7 @@ void level_assign_tiles(Levelp l) // // Switch the door direction if next to walls // - if (tp_is_door_get(tp)) { + if (tp_is_door(tp)) { if (level_tp_get(l, x, y - 1, MAP_DEPTH_WALL) && level_tp_get(l, x, y + 1, MAP_DEPTH_WALL)) { block_type = IS_JOIN_TOP; } diff --git a/src/my_game.hpp b/src/my_game.hpp index 25a6b8a..b4781c7 100644 --- a/src/my_game.hpp +++ b/src/my_game.hpp @@ -23,11 +23,13 @@ extern class Game *game; class HiScores *game_hiscores_get(class Game *); -void game_onscreen_map_get(class Game *, int *onscreen_map_tl_x, int *onscreen_map_tl_y, int *onscreen_map_br_x, - int *onscreen_map_br_y); +void game_visible_map_get(class Game *, int *visible_map_tl_x, int *visible_map_tl_y, int *visible_map_br_x, + int *visible_map_br_y); +void game_visible_map_set(class Game *, int visible_map_tl_x, int visible_map_tl_y, int visible_map_br_x, + int visible_map_br_y); -void game_onscreen_map_set(class Game *, int onscreen_map_tl_x, int onscreen_map_tl_y, int onscreen_map_br_x, - int onscreen_map_br_y); +void game_visible_map_mouse_get(class Game *game, int *visible_map_mouse_x, int *visible_map_mouse_y); +void game_visible_map_mouse_set(class Game *game, int visible_map_mouse_x, int visible_map_mouse_y); uint32_t game_last_mouse_down_get(class Game *); void game_last_mouse_down_set(class Game *, uint32_t); diff --git a/src/my_level.hpp b/src/my_level.hpp index ce2456d..30e3063 100644 --- a/src/my_level.hpp +++ b/src/my_level.hpp @@ -191,6 +191,7 @@ void level_thing_pop(Levelp, Thingp); void level_thing_push(Levelp, Thingp); void level_thing_update(Levelp, Thingp); void level_tick_begin(Levelp); +void level_cursor_reset(Levelp); void level_tick_begin_requested(Levelp, const char *); void level_tick_body(Levelp, float dt); void level_tick_end_requested(Levelp); diff --git a/src/my_minimal.hpp b/src/my_minimal.hpp index 4c279f6..94cde48 100644 --- a/src/my_minimal.hpp +++ b/src/my_minimal.hpp @@ -165,12 +165,8 @@ class Font; class Game; class HiScore; class HiScores; -class LevelPh2Room; -class LevelPh3Obstacles; -class LevelPh4Block; class Tex; class Tile; -class Tilemap; class Tp; class Wid; class WidPopup; @@ -179,22 +175,23 @@ struct Level_; struct Thing_; struct Dmap_; struct SDL_Surface; - -using Dmapp = struct Dmap_ *; -using Fontp = class Font *; -using Id = unsigned int; -using LevelPh2Roomp = class LevelPh2Room *; -using LevelPh3Obstaclesp = class LevelPh3Obstacles *; -using LevelPh4Blockp = class LevelPh4Block *; -using Levelp = struct Level_ *; -using Lightp = class Light *; -using Texp = class Tex *; -using ThingId = Id; -using Thingp = struct Thing_ *; -using Tilemapp = class Tilemap *; -using Tilep = class Tile *; -using TpId = Id; -using Tpp = class Tp *; -using Widp = class Wid *; +struct ThingOrTp_; + +using Dmapp = struct Dmap_ *; +using Fontp = class Font *; +using Id = unsigned int; +using Levelp = struct Level_ *; +using Lightp = class Light *; +using Texp = class Tex *; +using ThingId = Id; +using Thingp = struct Thing_ *; +using Tilep = class Tile *; +using TpId = Id; +using Tpp = class Tp *; +using Widp = class Wid *; + +#define NULL_TP ((Tpp) nullptr) +#define NULL_THING ((Thingp) nullptr) +#define NULL_OBJ ((struct ThingOrTp_ *) nullptr) #endif diff --git a/src/my_thing.hpp b/src/my_thing.hpp index b2258fa..1ad1449 100644 --- a/src/my_thing.hpp +++ b/src/my_thing.hpp @@ -15,6 +15,8 @@ // // IDs below this are for templates // +// Entropy is always > 0 for Thing IDs to distinguish them +// #define THING_ID_BASE (1U << (THING_ID_X_BITS + THING_ID_Y_BITS)) // diff --git a/src/my_tile.hpp b/src/my_tile.hpp index b399922..edeaa19 100644 --- a/src/my_tile.hpp +++ b/src/my_tile.hpp @@ -19,6 +19,9 @@ class Tile; class Tex *tile_tex(Tilep); +bool tile_init(void); +void tile_fini(void); + int tile_height(Tilep); int tile_width(Tilep); @@ -28,7 +31,7 @@ Tilep string2tile(const char **s); Tilep string2tile(std::string &s, int *len); Tilep tile_find_mand(std::string name); Tilep tile_from_surface(struct SDL_Surface *surface, std::string optional_file, std::string name); -Tilep tile_index_to_tile(uint16_t i); +Tilep tile_index_to_tile(int i); Tilep tile_find(std::string name); uint32_t tile_delay_ms(Tilep); @@ -37,30 +40,17 @@ void tile_delay_ms_set(Tilep, uint32_t); uint32_t tile_global_index(Tilep); void tile_global_index_set(Tilep, uint32_t); -uint32_t tile_frame(Tilep); uint32_t tile_index(Tilep); uint32_t tile_move(Tilep); -uint8_t gfx_outline_index_offset(Tilep); -uint8_t tile_init(void); -uint8_t tile_is_alive_on_end_of_anim(Tilep); -uint8_t tile_is_dead_on_end_of_anim(Tilep); -uint8_t tile_is_dead(Tilep); -uint8_t tile_is_dir_bl(Tilep); -uint8_t tile_is_dir_br(Tilep); -uint8_t tile_is_dir_down(Tilep); -uint8_t tile_is_dir_left(Tilep); -uint8_t tile_is_dir_none(Tilep); -uint8_t tile_is_dir_right(Tilep); -uint8_t tile_is_dir_tl(Tilep); -uint8_t tile_is_dir_tr(Tilep); -uint8_t tile_is_dir_up(Tilep); -uint8_t tile_is_end_of_anim(Tilep); -uint8_t tile_is_invisible(Tilep); -uint8_t tile_is_moving(Tilep); -uint8_t tile_is_open(Tilep); -uint8_t tile_is_resurrecting(Tilep); -uint8_t tile_is_sleeping(Tilep); +bool tile_is_alive_on_end_of_anim(Tilep); +bool tile_is_dead_on_end_of_anim(Tilep); +bool tile_is_dead(Tilep); +bool tile_is_end_of_anim(Tilep); +bool tile_is_moving(Tilep); +bool tile_is_open(Tilep); +bool tile_is_resurrecting(Tilep); +bool tile_is_sleeping(Tilep); void tile_blit(const Tilep &tile, const point tl, const point br); void tile_blit_mask(const Tilep &tile, const point tl, const point br); @@ -109,7 +99,6 @@ void tile_blit_shadow_section(const class Tp *&tp, const Tilep &tile, const poin const point tl, const point br); void tile_blit_shadow_section(const class Tp *&tp, uint16_t index, const point tile_tl, const point tile_br, const point tl, const point br); -void tile_fini(void); void tile_free(Tilep); void tile_coords(Tilep, float *x1, float *y1, float *x2, float *y2); void tile_load(std::string file, uint32_t width, uint32_t height, uint32_t nargs, ...); diff --git a/src/my_tp.hpp b/src/my_tp.hpp index bf5cb60..73686f8 100644 --- a/src/my_tp.hpp +++ b/src/my_tp.hpp @@ -297,19 +297,19 @@ void tp_is_blit_square_outlined_set(Tpp tp, bool val); bool tp_is_blit_tiled_get(Tpp tp); void tp_is_blit_tiled_set(Tpp tp, bool val); -bool tp_is_cursor_get(Tpp tp); +bool tp_is_cursor(Tpp tp); void tp_is_cursor_set(Tpp tp, bool val); -bool tp_is_door_get(Tpp tp); +bool tp_is_door(Tpp tp); void tp_is_door_set(Tpp tp, bool val); bool tp_is_dungeon_entrance_get(Tpp tp); void tp_is_dungeon_entrance_set(Tpp tp, bool val); -bool tp_is_exit_get(Tpp tp); +bool tp_is_exit(Tpp tp); void tp_is_exit_set(Tpp tp, bool val); -bool tp_is_floor_get(Tpp tp); +bool tp_is_floor(Tpp tp); void tp_is_floor_set(Tpp tp, bool val); bool tp_is_unused1_get(Tpp tp); @@ -912,10 +912,10 @@ void tp_is_cursor_at_set(Tpp tp, bool val); bool tp_is_cursor_path_get(Tpp tp); void tp_is_cursor_path_set(Tpp tp, bool val); -bool tp_is_key_get(Tpp tp); +bool tp_is_key(Tpp tp); void tp_is_key_set(Tpp tp, bool val); -bool tp_is_monst_get(Tpp tp); +bool tp_is_monst(Tpp tp); void tp_is_monst_set(Tpp tp, bool val); bool tp_is_monst_class_get(Tpp tp, int val); @@ -927,10 +927,10 @@ void tp_is_obs_monst_set(Tpp tp, bool val); bool tp_is_obs_player_get(Tpp tp); void tp_is_obs_player_set(Tpp tp, bool val); -bool tp_is_player_get(Tpp tp); +bool tp_is_player(Tpp tp); void tp_is_player_set(Tpp tp, bool val); -bool tp_is_wall_get(Tpp tp); +bool tp_is_wall(Tpp tp); void tp_is_wall_set(Tpp tp, bool val); uint8_t tp_player_index_get(Tpp tp); diff --git a/src/sdl_display.cpp b/src/sdl_display.cpp index d058f16..e74f517 100644 --- a/src/sdl_display.cpp +++ b/src/sdl_display.cpp @@ -30,16 +30,16 @@ void sdl_display(void) x_offset *= (float) game_window_pix_width_get(game); x_offset = floor(x_offset); - int onscreen_map_tl_x = x_offset; - int onscreen_map_tl_y = 0; - int onscreen_map_br_x = game_window_pix_height_get(game) + x_offset; - int onscreen_map_br_y = game_window_pix_height_get(game); + int visible_map_tl_x = x_offset; + int visible_map_tl_y = 0; + int visible_map_br_x = game_window_pix_height_get(game) + x_offset; + int visible_map_br_y = game_window_pix_height_get(game); - game_onscreen_map_set(game, onscreen_map_tl_x, onscreen_map_tl_y, onscreen_map_br_x, onscreen_map_br_y); + game_visible_map_set(game, visible_map_tl_x, visible_map_tl_y, visible_map_br_x, visible_map_br_y); blit_init(); - blit(fbo_tex_id[ FBO_MAP ], 0.0, 1.0, 1.0, 0.0, onscreen_map_tl_x, onscreen_map_tl_y, onscreen_map_br_x, - onscreen_map_br_y); + blit(fbo_tex_id[ FBO_MAP ], 0.0, 1.0, 1.0, 0.0, visible_map_tl_x, visible_map_tl_y, visible_map_br_x, + visible_map_br_y); blit_flush(); } else { diff --git a/src/thing_move.cpp b/src/thing_move.cpp index 20354df..bbd0530 100644 --- a/src/thing_move.cpp +++ b/src/thing_move.cpp @@ -226,11 +226,11 @@ bool level_thing_can_move_to(Levelp l, Thingp t, int new_loc_x, int new_loc_y) FOR_ALL_TPS_AT(l, it, it_tp, new_loc_x, new_loc_y) { - if (tp_is_player_get(my_tp) && tp_is_obs_player_get(it_tp)) { + if (tp_is_player(my_tp) && tp_is_obs_player_get(it_tp)) { return false; } - if (tp_is_monst_get(my_tp) && tp_is_obs_monst_get(it_tp)) { + if (tp_is_monst(my_tp) && tp_is_obs_monst_get(it_tp)) { return false; } } diff --git a/src/tile.cpp b/src/tile.cpp index 5b2ab17..a0b20ed 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -20,9 +20,7 @@ std::map< std::string, class Tile * > all_tiles; std::vector< class Tile * > all_tiles_array; -using Tilevec = std::vector< class Tile * >; - -static uint8_t tile_init_done; +static bool tile_init_done; class Tile { @@ -36,16 +34,16 @@ class Tile // // Grabbed by a template // - uint8_t in_use {}; - uint16_t global_index; + uint8_t in_use {}; + int global_index; // // Index within the overall texture, left to right, top to bottom. // - uint16_t index {}; + int index {}; - uint16_t pix_width {}; - uint16_t pix_height {}; + int pix_width {}; + int pix_height {}; float pct_width {}; float pct_height {}; @@ -119,9 +117,10 @@ Tile::Tile(void) { newptr(MTYPE_TILE, this, "Tile"); } Tile::~Tile(void) { oldptr(MTYPE_TILE, this); } -uint8_t tile_init(void) +bool tile_init(void) { TRACE_AND_INDENT(); + tile_init_done = true; return true; @@ -130,6 +129,7 @@ uint8_t tile_init(void) void tile_fini(void) { TRACE_AND_INDENT(); + if (tile_init_done) { tile_init_done = false; } @@ -919,12 +919,14 @@ Tilep string2tile(std::string &s, int *len) return result->second; } -Tilep tile_index_to_tile(uint16_t i) +Tilep tile_index_to_tile(int i) { extern std::vector< class Tile * > all_tiles_array; + if (unlikely(! i)) { return nullptr; } + return all_tiles_array[ i - 1 ]; } // @@ -971,83 +973,21 @@ void tile_delay_ms_set(Tilep t, uint32_t val) { t->delay_ms = val; } uint32_t tile_global_index(Tilep t) { return t->global_index; } void tile_global_index_set(Tilep t, uint32_t val) { t->global_index = val; } -uint8_t tile_is_moving(Tilep t) { return t->is_moving; } +bool tile_is_moving(Tilep t) { return t->is_moving ? true : false; } -uint8_t tile_is_sleeping(Tilep t) { return t->is_sleeping; } +bool tile_is_sleeping(Tilep t) { return t->is_sleeping ? true : false; } -uint8_t tile_is_open(Tilep t) { return t->is_open; } +bool tile_is_open(Tilep t) { return t->is_open ? true : false; } -uint8_t tile_is_dead(Tilep t) { return t->is_dead; } +bool tile_is_dead(Tilep t) { return t->is_dead ? true : false; } -uint8_t tile_is_end_of_anim(Tilep t) { return t->is_end_of_anim; } +bool tile_is_end_of_anim(Tilep t) { return t->is_end_of_anim ? true : false; } -uint8_t tile_is_dead_on_end_of_anim(Tilep t) { return t->is_dead_on_end_of_anim; } - -uint8_t tile_is_alive_on_end_of_anim(Tilep t) { return t->is_alive_on_end_of_anim; } - -uint8_t tile_is_resurrecting(Tilep t) { return t->is_resurrecting; } - -Tilep tile_random(Tilevec *tmap) -{ - if (unlikely(! tmap)) { - return nullptr; - } - std::vector< Tilep > *tiles = &((*tmap)); - if (unlikely(! tiles)) { - return nullptr; - } - if (unlikely(tiles->empty())) { - return nullptr; - } +bool tile_is_dead_on_end_of_anim(Tilep t) { return t->is_dead_on_end_of_anim ? true : false; } - int tries = 999999; - while (tries--) { - auto index = pcg_rand() % tiles->size(); - auto tile = (*tiles)[ index ]; +bool tile_is_alive_on_end_of_anim(Tilep t) { return t->is_alive_on_end_of_anim ? true : false; } - // - // Don't really want dead tiles when choosing a random start tile. - // - if (tile->is_dead) { - continue; - } - if (unlikely(! tile)) { - ERR("no tile at index #%d, max %d", (int) index, (int) tiles->size()); - return nullptr; - } - return tile_index_to_tile(tile->global_index); - } - - DIE("failed to choose a random tile"); -} - -Tilep tile_frame(Tilevec *tmap, uint32_t frame) -{ - for (const auto t : *tmap) { - if (t->frame == frame) { - return t; - } - } - return nullptr; -} - -Tilep tile_next(Tilevec *tmap, Tilep in) -{ - if (unlikely(! tmap)) { - return nullptr; - } - std::vector< Tilep > *tiles = &((*tmap)); - if (unlikely(tiles->empty())) { - return nullptr; - } - auto cursor = in->index; - cursor++; - if (cursor >= tiles->size()) { - cursor = 0; - } - auto tile = ((*tiles)[ cursor ]); - return tile_index_to_tile(tile->global_index); -} +bool tile_is_resurrecting(Tilep t) { return t->is_resurrecting ? true : false; } int Tile::gl_binding(void) const { return _gl_binding; } @@ -1138,7 +1078,7 @@ void tile_blit_outline(const Tilep &tile, const point tl, const point br, const blit(binding, x1, y2, x2, y1, tl.x, br.y, br.x, tl.y); } -void tile_blit_outline(uint16_t index, const point tl, const point br, const color &c, bool square) +void tile_blit_outline(int index, const point tl, const point br, const color &c, bool square) { tile_blit_outline(tile_index_to_tile(index), tl, br, c, square); } @@ -1262,7 +1202,7 @@ void tile_blit(const Tilep &tile, const point tl, const point tr, const point bl blit(tile->gl_binding(), x1, y2, x2, y1, tl, tr, bl, br); } -void tile_blit(uint16_t index, const point tl, const point br) { tile_blit(tile_index_to_tile(index), tl, br); } +void tile_blit(int index, const point tl, const point br) { tile_blit(tile_index_to_tile(index), tl, br); } void tile_blit_section(const Tilep &tile, const point tile_tl, const point tile_br, const point tl, const point br) { @@ -1287,7 +1227,7 @@ void tile_blit_section(const Tilep &tile, const point tile_tl, const point tile_ blit(tile->gl_binding(), x1, y2, x2, y1, tl.x, br.y, br.x, tl.y); } -void tile_blit_section(uint16_t index, const point tile_tl, const point tile_br, const point tl, const point br) +void tile_blit_section(int index, const point tile_tl, const point tile_br, const point tl, const point br) { tile_blit_section(tile_index_to_tile(index), tile_tl, tile_br, tl, br); } @@ -1316,7 +1256,7 @@ void tile_blit_section_colored(const Tilep &tile, const fpoint &tile_tl, const f blit_colored(tile->gl_binding(), x1, y2, x2, y1, tl.x, br.y, br.x, tl.y, color_tl, color_tr, color_bl, color_br); } -void tile_blit_section_colored(uint16_t index, const fpoint &tile_tl, const fpoint &tile_br, const point tl, +void tile_blit_section_colored(int index, const fpoint &tile_tl, const fpoint &tile_br, const point tl, const point br, color color_tl, color color_tr, color color_bl, color color_br) { tile_blit_section_colored(tile_index_to_tile(index), tile_tl, tile_br, tl, br, color_tl, color_tr, color_bl, @@ -1330,7 +1270,7 @@ void tile_blit_outline_section_colored(const Tilep &tile, const fpoint &tile_tl, tile_blit_outline_section(tile, tile_tl, tile_br, tl, br, 0.75); } -void tile_blit_outline_section_colored(uint16_t index, const fpoint &tile_tl, const fpoint &tile_br, const point tl, +void tile_blit_outline_section_colored(int index, const fpoint &tile_tl, const fpoint &tile_br, const point tl, const point br, color color_tl, color color_tr, color color_bl, color color_br) { tile_blit_outline_section_colored(tile_index_to_tile(index), tile_tl, tile_br, tl, br, color_tl, color_tr, color_bl, @@ -1344,7 +1284,7 @@ void tile_blit_outline_section_colored(const Tilep &tile, const fpoint &tile_tl, tile_blit_outline_section(tile, tile_tl, tile_br, tl, br, scale); } -void tile_blit_outline_section_colored(uint16_t index, const fpoint &tile_tl, const fpoint &tile_br, const point tl, +void tile_blit_outline_section_colored(int index, const fpoint &tile_tl, const fpoint &tile_br, const point tl, const point br, color color_tl, color color_tr, color color_bl, color color_br, float scale) { diff --git a/src/tp.cpp b/src/tp.cpp index 5f1f70e..7a77123 100644 --- a/src/tp.cpp +++ b/src/tp.cpp @@ -3615,19 +3615,19 @@ void tp_is_blit_square_outlined_set(Tpp tp, bool val) { tp->is_blit_square_outli bool tp_is_blit_tiled_get(Tpp tp) { return tp->is_blit_tiled; } void tp_is_blit_tiled_set(Tpp tp, bool val) { tp->is_blit_tiled = val; } -bool tp_is_cursor_get(Tpp tp) { return tp->is_cursor; } +bool tp_is_cursor(Tpp tp) { return tp->is_cursor; } void tp_is_cursor_set(Tpp tp, bool val) { tp->is_cursor = val; } -bool tp_is_door_get(Tpp tp) { return tp->is_door; } +bool tp_is_door(Tpp tp) { return tp->is_door; } void tp_is_door_set(Tpp tp, bool val) { tp->is_door = val; } bool tp_is_dungeon_entrance_get(Tpp tp) { return tp->is_dungeon_entrance; } void tp_is_dungeon_entrance_set(Tpp tp, bool val) { tp->is_dungeon_entrance = val; } -bool tp_is_exit_get(Tpp tp) { return tp->is_exit; } +bool tp_is_exit(Tpp tp) { return tp->is_exit; } void tp_is_exit_set(Tpp tp, bool val) { tp->is_exit = val; } -bool tp_is_floor_get(Tpp tp) { return tp->is_floor; } +bool tp_is_floor(Tpp tp) { return tp->is_floor; } void tp_is_floor_set(Tpp tp, bool val) { tp->is_floor = val; } bool tp_is_unused1_get(Tpp tp) { return tp->is_unused1; } @@ -4230,10 +4230,10 @@ void tp_is_cursor_at_set(Tpp tp, bool val) { tp->is_cursor_at = val; } bool tp_is_cursor_path_get(Tpp tp) { return tp->is_cursor_path; } void tp_is_cursor_path_set(Tpp tp, bool val) { tp->is_cursor_path = val; } -bool tp_is_key_get(Tpp tp) { return tp->is_key; } +bool tp_is_key(Tpp tp) { return tp->is_key; } void tp_is_key_set(Tpp tp, bool val) { tp->is_key = val; } -bool tp_is_monst_get(Tpp tp) { return tp->is_monst; } +bool tp_is_monst(Tpp tp) { return tp->is_monst; } void tp_is_monst_set(Tpp tp, bool val) { tp->is_monst = val; } bool tp_is_monst_class_get(Tpp tp, int val) { return tp->is_monst_class[ val ]; } @@ -4245,10 +4245,10 @@ void tp_is_obs_monst_set(Tpp tp, bool val) { tp->is_obs_monst = val; } bool tp_is_obs_player_get(Tpp tp) { return tp->is_obs_player; } void tp_is_obs_player_set(Tpp tp, bool val) { tp->is_obs_player = val; } -bool tp_is_player_get(Tpp tp) { return tp->is_player; } +bool tp_is_player(Tpp tp) { return tp->is_player; } void tp_is_player_set(Tpp tp, bool val) { tp->is_player = val; } -bool tp_is_wall_get(Tpp tp) { return tp->is_wall; } +bool tp_is_wall(Tpp tp) { return tp->is_wall; } void tp_is_wall_set(Tpp tp, bool val) { tp->is_wall = val; } uint8_t tp_player_index_get(Tpp tp) { return tp->player_index; };