Skip to content

Commit

Permalink
add back z depth for display order
Browse files Browse the repository at this point in the history
  • Loading branch information
goblinhack committed Feb 9, 2025
1 parent 8feb8ac commit 944c238
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 51 deletions.
Binary file modified data/gfx.tgz
Binary file not shown.
2 changes: 1 addition & 1 deletion src/level_cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void level_cursor_set(Gamep g, Levelsp v, point p)
{
TRACE_AND_INDENT();

if (! is_oob( p)) {
if (! is_oob(p)) {
v->cursor_at = p;
}
}
Expand Down
21 changes: 14 additions & 7 deletions src/level_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,18 @@ static void level_display_cursor(Gamep g, Levelsp v, Levelp l, point p)
}
}

static void level_display_slot(Gamep g, Levelsp v, Levelp l, point p, int slot, int prio)
static void level_display_slot(Gamep g, Levelsp v, Levelp l, point p, int slot, int depth, int prio)
{
Tpp tp;
auto t = thing_and_tp_get_at(g, v, l, p, slot, &tp);
if (! tp) {
return;
}

if (tp_z_depth_get(tp) != depth) {
return;
}

if (tp_z_prio_get(tp) != prio) {
return;
}
Expand Down Expand Up @@ -198,12 +202,15 @@ void level_display(Gamep g, Levelsp v, Levelp l)
//
// Display tiles in z prio order
//
for (auto y = v->miny; y < v->maxy; y++) {
FOR_ALL_Z_PRIO(z_prio)
{
for (auto x = v->minx; x < v->maxx; x++) {
for (auto slot = 0; slot < MAP_SLOTS; slot++) {
level_display_slot(g, v, l, point(x, y), slot, z_prio);
FOR_ALL_Z_PRIO(z_depth)
{
for (auto y = v->miny; y < v->maxy; y++) {
FOR_ALL_Z_PRIO(z_prio)
{
for (auto x = v->minx; x < v->maxx; x++) {
for (auto slot = 0; slot < MAP_SLOTS; slot++) {
level_display_slot(g, v, l, point(x, y), slot, z_depth, z_prio);
}
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/level_tick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ static void level_tick_body(Gamep g, Levelsp v, Levelp l, float dt)
}

t->thing_dt += dt * ((float) t->speed / (float) player_speed);
if (thing_is_player(t)) {
TOPCON("at %u,%u moving_from %u,%u %f", t->at.x, t->at.y, t->moving_from.x, t->moving_from.y, t->thing_dt);
}

if (t->thing_dt >= 1.0) {
t->thing_dt = 1.0;
Expand Down
13 changes: 7 additions & 6 deletions src/my_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ enum {
TILE_LAYER_MAX,
};

enum {
MAP_Z_PRIO_BEHIND,
MAP_Z_PRIO_NORMAL, // e.g. player
MAP_Z_PRIO_INFRONT,
MAP_Z_PRIO_LAST
};
enum { MAP_Z_DEPTH_FLOOR, MAP_Z_DEPTH_OBJ, MAP_Z_DEPTH_LAST };
#define MAP_Z_DEPTH_FIRST MAP_Z_DEPTH_FLOOR

#define FOR_ALL_Z_DEPTH(_z_depth_) \
for (uint8_t _z_depth_ = MAP_Z_DEPTH_FIRST; _z_depth_ < MAP_Z_DEPTH_LAST; _z_depth_++)

enum { MAP_Z_PRIO_BEHIND, MAP_Z_PRIO_NORMAL, MAP_Z_PRIO_INFRONT, MAP_Z_PRIO_LAST };
#define MAP_Z_PRIO_FIRST MAP_Z_PRIO_BEHIND

#define FOR_ALL_Z_PRIO(_z_prio_) for (uint8_t _z_prio_ = MAP_Z_PRIO_FIRST; _z_prio_ < MAP_Z_PRIO_LAST; _z_prio_++)
Expand Down
2 changes: 1 addition & 1 deletion src/my_game_defs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
#define MAP_TILES_DOWN 20
#define MAP_SCROLL_BORDER 0.4
#define MAP_SCROLL_SPEED 5
#define TICK_DURATION_MS 1000
#define TICK_DURATION_MS 50

#endif
3 changes: 3 additions & 0 deletions src/my_tp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ void tp_random_dungeon_init(void);
bool tp_flag(Tpp tp, ThingFlag);
void tp_flag_set(Tpp tp, ThingFlag, bool val);

void tp_z_depth_set(Tpp tp, uint8_t val);
uint8_t tp_z_depth_get(Tpp tp);

void tp_z_prio_set(Tpp tp, uint8_t val);
uint8_t tp_z_prio_get(Tpp tp);

Expand Down
60 changes: 29 additions & 31 deletions src/thing_move.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void thing_set_dir_from_delta(Thingp t, int dx, int dy)
//
bool thing_move_to(Gamep g, Levelsp v, Levelp l, Thingp t, point to)
{
if (is_oob( to)) {
if (is_oob(to)) {
return false;
}

Expand All @@ -232,10 +232,6 @@ bool thing_move_to(Gamep g, Levelsp v, Levelp l, Thingp t, point to)
t->at = to;
t->is_moving = true;

if (thing_is_player(t)) {
CON("id %x moved %u,%u from %u,%u %f", t->id, t->at.x, t->at.y, t->moving_from.x, t->moving_from.y, t->thing_dt);
}

thing_push(g, v, l, t);

if (thing_is_player(t)) {
Expand All @@ -261,7 +257,7 @@ void thing_move_finish(Gamep g, Levelsp v, Levelp l, Thingp t)
//
bool thing_can_move_to(Gamep g, Levelsp v, Levelp l, Thingp t, point to)
{
if (is_oob( to)) {
if (is_oob(to)) {
return false;
}

Expand Down Expand Up @@ -313,7 +309,7 @@ void thing_push(Gamep g, Levelsp v, Levelp l, Thingp t)
TRACE_NO_INDENT();

point p = t->at;
if (is_oob( p)) {
if (is_oob(p)) {
return;
}

Expand Down Expand Up @@ -362,33 +358,35 @@ void thing_push(Gamep g, Levelsp v, Levelp l, Thingp t)
t->last_pushed_at = p;
l->thing_id[ p.x ][ p.y ][ slot ] = t->id;

//
// Sort the map slots by z prio for display order.
//
ThingId slots_sorted[ MAP_SLOTS ] = {};
auto slots_sorted_count = 0;

FOR_ALL_Z_PRIO(z_prio)
{
for (auto slot_tmp = 0; slot_tmp < MAP_SLOTS; slot_tmp++) {
auto slotp = &l->thing_id[ p.x ][ p.y ][ slot_tmp ];
ThingId oid = *slotp;
if (oid) {
Thingp o = thing_find(g, v, oid);
auto o_tp = thing_tp(o);
if (o && (tp_z_prio_get(o_tp) == z_prio)) {
slots_sorted[ slots_sorted_count++ ] = oid;
*slotp = 0;
if (0) {
//
// Sort the map slots by z prio for display order.
//
ThingId slots_sorted[ MAP_SLOTS ] = {};
auto slots_sorted_count = 0;

FOR_ALL_Z_PRIO(z_prio)
{
for (auto slot_tmp = 0; slot_tmp < MAP_SLOTS; slot_tmp++) {
auto slotp = &l->thing_id[ p.x ][ p.y ][ slot_tmp ];
ThingId oid = *slotp;
if (oid) {
Thingp o = thing_find(g, v, oid);
auto o_tp = thing_tp(o);
if (o && (tp_z_prio_get(o_tp) == z_prio)) {
slots_sorted[ slots_sorted_count++ ] = oid;
*slotp = 0;
}
}
}
}
}

//
// Copy the new sorted slots.
//
for (auto slot_tmp = 0; slot_tmp < MAP_SLOTS; slot_tmp++) {
l->thing_id[ p.x ][ p.y ][ slot_tmp ] = slots_sorted[ slot_tmp ];
//
// Copy the new sorted slots.
//
for (auto slot_tmp = 0; slot_tmp < MAP_SLOTS; slot_tmp++) {
l->thing_id[ p.x ][ p.y ][ slot_tmp ] = slots_sorted[ slot_tmp ];
}
}

return;
Expand All @@ -413,7 +411,7 @@ void thing_pop(Gamep g, Levelsp v, Levelp l, Thingp t)
}
point p = t->last_pushed_at;

if (is_oob( p)) {
if (is_oob(p)) {
return;
}

Expand Down
1 change: 1 addition & 0 deletions src/things/dungeon/tp_door.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ bool tp_load_door(void)
tp_flag_set(tp, is_obs_monst, true);
tp_flag_set(tp, is_obs_player, true);
tp_flag_set(tp, is_tiled, true);
tp_z_depth_set(tp, MAP_Z_DEPTH_OBJ);
tp_z_prio_set(tp, MAP_Z_PRIO_NORMAL);
// end sort marker1 }

Expand Down
1 change: 1 addition & 0 deletions src/things/dungeon/tp_exit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ bool tp_load_exit(void)
// begin sort marker1 {
tp_flag_set(tp, is_blit_on_ground, true);
tp_flag_set(tp, is_exit, true);
tp_z_depth_set(tp, MAP_Z_DEPTH_OBJ);
tp_z_prio_set(tp, MAP_Z_PRIO_NORMAL);
// end sort marker1 }

Expand Down
3 changes: 2 additions & 1 deletion src/things/dungeon/tp_floor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ bool tp_load_floor(void)
// begin sort marker1 {
tp_flag_set(tp, is_blit_centered, true);
tp_flag_set(tp, is_floor, true);
tp_z_prio_set(tp, MAP_Z_PRIO_NORMAL);
tp_z_depth_set(tp, MAP_Z_DEPTH_FLOOR);
tp_z_prio_set(tp, MAP_Z_PRIO_BEHIND);
// end sort marker1 }

tp_tiles_push_back(tp, tile_find_mand("floor.1"));
Expand Down
1 change: 1 addition & 0 deletions src/things/dungeon/tp_key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ bool tp_load_key(void)
// begin sort marker1 {
tp_flag_set(tp, is_blit_on_ground, true);
tp_flag_set(tp, is_key, true);
tp_z_depth_set(tp, MAP_Z_DEPTH_OBJ);
tp_z_prio_set(tp, MAP_Z_PRIO_NORMAL);
// end sort marker1 }

Expand Down
1 change: 1 addition & 0 deletions src/things/dungeon/tp_wall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ bool tp_load_wall(void)
tp_flag_set(tp, is_obs_player, true);
tp_flag_set(tp, is_tiled, true);
tp_flag_set(tp, is_wall, true);
tp_z_depth_set(tp, MAP_Z_DEPTH_OBJ);
tp_z_prio_set(tp, MAP_Z_PRIO_NORMAL);
// end sort marker1 }

Expand Down
3 changes: 2 additions & 1 deletion src/things/player/tp_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ bool tp_load_player(void)
tp_flag_set(tp, is_player, true);
tp_flag_set(tp, is_tickable, true);
tp_speed_set(tp, 100);
tp_z_prio_set(tp, MAP_Z_PRIO_INFRONT);
tp_z_depth_set(tp, MAP_Z_DEPTH_OBJ);
tp_z_prio_set(tp, MAP_Z_PRIO_NORMAL);
// end sort marker1 }

auto delay = 100;
Expand Down
11 changes: 11 additions & 0 deletions src/tp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ class Tp
public:
TpId id {};

//
// This allows us to draw floors, then objs and walls in order
//
uint8_t z_depth {};

//
// This is for objects at the same z depth
//
uint8_t z_prio {};

std::vector< class Tile * > tiles;
Expand Down Expand Up @@ -354,6 +362,9 @@ bool tp_flag(Tpp tp, ThingFlag f) { return tp->flag[ f ]; }

void tp_flag_set(Tpp tp, ThingFlag f, bool val) { tp->flag[ f ] = val; }

void tp_z_depth_set(Tpp tp, uint8_t val) { tp->z_depth = val; };
uint8_t tp_z_depth_get(Tpp tp) { return tp->z_depth; };

void tp_z_prio_set(Tpp tp, uint8_t val) { tp->z_prio = val; };
uint8_t tp_z_prio_get(Tpp tp) { return tp->z_prio; };

Expand Down

0 comments on commit 944c238

Please sign in to comment.