eco2d/code/game/src/debug_ui_actions.c

163 lines
3.5 KiB
C
Raw Normal View History

2021-05-13 12:36:07 +00:00
#include "debug_ui.h"
2021-08-10 15:21:25 +00:00
2021-05-13 12:36:07 +00:00
static inline void
ActExitGame(void) {
2021-05-13 14:12:18 +00:00
game_request_close();
2021-08-09 13:35:47 +00:00
}
static inline void
ActSpawnCar(void) {
2021-08-09 17:30:39 +00:00
ecs_entity_t e = vehicle_spawn();
ecs_entity_t plr = camera_get().ent_id;
Position const* origin = ecs_get(world_ecs(), plr, Position);
Position * dest = ecs_get_mut(world_ecs(), e, Position, NULL);
*dest = *origin;
debug_replay_special_action(RPKIND_SPAWN_CAR);
2021-08-09 17:30:39 +00:00
}
2021-08-10 15:21:25 +00:00
// NOTE(zaklaus): Replay system
static inline uint8_t
CondReplayStatusOn(void) {
2021-08-10 23:06:12 +00:00
return is_recording && !is_playing;
2021-08-10 15:21:25 +00:00
}
static inline uint8_t
CondReplayStatusOff(void) {
2021-08-10 23:06:12 +00:00
return !is_recording && !is_playing;
2021-08-10 15:21:25 +00:00
}
static inline uint8_t
2021-08-10 23:06:12 +00:00
CondReplayDataPresentAndNotPlaying(void) {
return records != NULL && !is_recording && !is_playing;
}
static inline uint8_t
CondReplayIsPlaying(void) {
return records != NULL && !is_recording && is_playing;
}
static inline uint8_t
CondReplayIsNotPlaying(void) {
return !is_recording && !is_playing;
}
static inline uint8_t
CondReplayIsNotPlayingOrRecordsNotClear(void) {
return records != NULL && !is_recording && !is_playing;
2021-08-10 15:21:25 +00:00
}
static inline void
ActReplayBegin(void) {
debug_replay_start();
}
static inline void
ActReplayEnd(void) {
debug_replay_stop();
}
static inline void
ActReplayRun(void) {
debug_replay_run();
}
static inline void
ActReplayClear(void) {
debug_replay_clear();
}
static inline void
ActReplayNew(void) {
debug_replay_clear();
zpl_zero_size(replay_filename, sizeof(replay_filename));
}
static inline void
ActReplaySaveAs(void) {
if (!records) return;
char const *workdir = GetWorkingDirectory();
sfd_Options sfd = {
.title = "Save Macro",
.path = "art",
.filter_name = "eco2d Macro",
.filter = "*.dem",
};
char const *path = sfd_save_dialog(&sfd);
ChangeDirectory(workdir);
if (path) {
zpl_strcpy(replay_filename, zpl_bprintf("%s.dem", path));
debug_replay_store();
}
}
static inline void
ActReplaySave(void) {
if (!replay_filename[0]) {
ActReplaySaveAs();
}
else debug_replay_store();
}
static inline void
ActReplayLoad(void) {
char const *workdir = GetWorkingDirectory();
sfd_Options sfd = {
.title = "Load Macro",
.path = "art",
.filter_name = "eco2d Macro",
.filter = "*.dem",
};
char const *path = sfd_open_dialog(&sfd);
ChangeDirectory(workdir);
if (path) {
zpl_strcpy(replay_filename, path);
debug_replay_clear();
debug_replay_load();
}
}
2021-08-10 22:02:11 +00:00
// NOTE(zaklaus): Demo NPCs
static ecs_entity_t *demo_npcs = NULL;
static inline void
ActSpawnDemoNPCs(void) {
if (!demo_npcs) zpl_array_init(demo_npcs, zpl_heap());
if (zpl_array_count(demo_npcs) >= 10000) return;
for (uint32_t i = 0; i < 1000; i++) {
uint64_t e = entity_spawn(EKIND_DEMO_NPC);
ecs_add(world_ecs(), e, EcsDemoNPC);
Position *pos = ecs_get_mut(world_ecs(), e, Position, NULL);
pos->x=rand() % world_dim();
pos->y=rand() % world_dim();
Velocity *v = ecs_get_mut(world_ecs(), e, Velocity, NULL);
v->x = (rand()%3-1) * 100;
v->y = (rand()%3-1) * 100;
zpl_array_append(demo_npcs, e);
}
}
static inline void
ActDespawnDemoNPCs(void) {
if (!demo_npcs) return;
for (uint32_t i = 0; i < zpl_array_count(demo_npcs); i++) {
entity_despawn(demo_npcs[i]);
}
zpl_array_free(demo_npcs);
demo_npcs = 0;
}