HandmadeHero/project/engine/engine.hpp

334 lines
5.4 KiB
C++
Raw Normal View History

2023-09-15 18:35:27 -07:00
/*
Services the engine provides to the platform layer
*/
#pragma once
2023-10-06 23:33:39 -07:00
#if INTELLISENSE_DIRECTIVES
#include "platform/platform.hpp"
2023-10-06 23:33:39 -07:00
#endif
2023-09-15 18:35:27 -07:00
#define NS_ENGINE_BEGIN namespace engine {
#define NS_ENGINE_END }
NS_ENGINE_BEGIN
2023-09-30 12:40:27 -07:00
enum ReplayMode : s32
{
ReplayMode_Off,
ReplayMode_Record,
ReplayMode_Playback
};
2023-09-18 17:16:40 -07:00
struct Clocks
{
// TODO(Ed) : Clock values...
f32 seconds_elapsed;
};
struct ThreadContext
{
u32 placeholder;
};
struct MemorySnapshot
{
2023-09-30 12:40:27 -07:00
StrPath file_path;
void* opaque_handle;
void* opaque_handle_2;
void* memory;
2023-10-01 17:17:14 -07:00
u64 age;
2023-09-18 17:16:40 -07:00
};
struct Memory
{
// All memory for the engine is required to be zero initialized.
// Wiped on shutdown
void* persistent;
u64 persistent_size;
2023-09-18 17:16:40 -07:00
// Wiped on a per-frame basis
// void* Frame;
// u64 FrameSize;
// Wiped whenever the engine wants to?
void* transient;
u64 transient_size;
// TODO(Ed) : Move this crap to state & replay archive definitions?
2023-09-30 12:40:27 -07:00
#if Build_Development
static constexpr
2023-10-01 17:17:14 -07:00
s32 Num_Snapshot_Slots = 3;
// Abuse RAM to store snapshots of the Engine or Game state.
MemorySnapshot snapshots[ Num_Snapshot_Slots ];
s32 active_snapshot_slot;
// Recording and playback info is the same for either engine or game.
2023-09-30 12:40:27 -07:00
ReplayMode replay_mode;
platform::File active_input_replay_file;
// Engine-wide recording & playback loop.
s32 engine_loop_active;
s32 game_loop_active;
2023-09-30 12:40:27 -07:00
#endif
u64 total_size()
{
return persistent_size + transient_size;
}
2023-09-18 17:16:40 -07:00
};
2023-09-15 18:35:27 -07:00
struct OffscreenBuffer
{
void* memory; // Lets use directly mess with the "pixel's memory buffer"
u32 width;
u32 height;
u32 pitch;
u32 bytes_per_pixel;
2023-09-15 18:35:27 -07:00
};
2023-09-17 18:20:11 -07:00
// TODO : Will be gutting this once we have other stuff lifted.
2023-09-24 19:37:05 -07:00
struct AudioBuffer
2023-09-16 15:41:07 -07:00
{
s16* samples;
u32 running_sample_index;
s32 samples_per_second;
s32 num_samples;
2023-09-16 15:41:07 -07:00
};
2023-09-17 18:20:11 -07:00
struct DigitalBtn
{
s32 half_transitions;
b32 ended_down;
2023-09-17 18:20:11 -07:00
};
struct AnalogAxis
{
f32 start;
f32 end;
f32 min;
f32 max;
2023-09-21 23:16:40 -07:00
// Platform doesn't provide this, we process in the engine layer.
f32 average;
2023-09-17 18:20:11 -07:00
};
struct AnalogStick
{
AnalogAxis X;
AnalogAxis Y;
};
2023-09-21 23:16:40 -07:00
union KeyboardState
2023-09-17 18:20:11 -07:00
{
DigitalBtn keys[12];
2023-09-21 23:16:40 -07:00
struct {
2023-09-30 12:40:27 -07:00
DigitalBtn _1;
DigitalBtn _2;
DigitalBtn _3;
DigitalBtn _4;
2023-09-21 23:16:40 -07:00
DigitalBtn Q;
DigitalBtn E;
DigitalBtn W;
DigitalBtn A;
DigitalBtn S;
DigitalBtn D;
DigitalBtn K;
2023-09-28 10:44:43 -07:00
DigitalBtn L;
DigitalBtn escape;
DigitalBtn backspace;
DigitalBtn up;
DigitalBtn down;
DigitalBtn left;
DigitalBtn right;
DigitalBtn space;
DigitalBtn pause;
2023-09-30 12:40:27 -07:00
DigitalBtn left_alt;
DigitalBtn right_alt;
DigitalBtn right_shift;
DigitalBtn left_shift;
2023-09-21 23:16:40 -07:00
};
2023-09-17 18:20:11 -07:00
};
struct MousesState
{
DigitalBtn left;
DigitalBtn middle;
DigitalBtn right;
AnalogAxis X;
AnalogAxis Y;
AnalogAxis vertical_wheel;
AnalogAxis horizontal_wheel;
2023-09-17 18:20:11 -07:00
};
struct XInputPadState
{
struct
{
AnalogStick left;
AnalogStick right;
} stick;
2023-09-17 18:20:11 -07:00
AnalogAxis left_trigger;
AnalogAxis right_trigger;
2023-09-17 18:20:11 -07:00
union {
DigitalBtn btns[14];
2023-09-17 18:20:11 -07:00
struct {
struct {
DigitalBtn up;
DigitalBtn down;
DigitalBtn left;
DigitalBtn right;
} dpad;
2023-09-17 18:20:11 -07:00
DigitalBtn A;
DigitalBtn B;
DigitalBtn X;
DigitalBtn Y;
DigitalBtn back;
DigitalBtn start;
DigitalBtn left_shoulder;
DigitalBtn right_shoulder;
2023-09-17 18:20:11 -07:00
};
};
};
struct DualsensePadState
{
struct
{
AnalogStick left;
AnalogStick right;
} stick;
2023-09-17 18:20:11 -07:00
AnalogAxis L2;
AnalogAxis R2;
union {
DigitalBtn btns[14];
2023-09-17 18:20:11 -07:00
struct {
struct {
DigitalBtn up;
DigitalBtn down;
DigitalBtn left;
DigitalBtn right;
} dpad;
DigitalBtn cross;
DigitalBtn circle;
DigitalBtn square;
DigitalBtn triangle;
DigitalBtn share;
DigitalBtn options;
2023-09-17 18:20:11 -07:00
DigitalBtn L1;
DigitalBtn R1;
};
};
};
struct ControllerState
{
KeyboardState* keyboard;
MousesState* mouse;
XInputPadState* xpad;
DualsensePadState* ds_pad;
2023-09-17 18:20:11 -07:00
};
2023-09-28 10:44:43 -07:00
struct ControllerStateSnapshot
{
KeyboardState keyboard;
MousesState mouse;
XInputPadState xpad;
DualsensePadState ds_pad;
2023-09-28 10:44:43 -07:00
};
2023-09-17 18:20:11 -07:00
struct InputState
{
ControllerState controllers[4];
2023-09-17 18:20:11 -07:00
};
2023-09-28 10:44:43 -07:00
struct InputStateSnapshot
{
ControllerStateSnapshot controllers[4];
2023-09-28 10:44:43 -07:00
};
2023-09-21 23:16:40 -07:00
using InputBindCallback = void( void* );
using InputBindCallback_DigitalBtn = void( engine::DigitalBtn* button );
using InputBindCallback_AnalogAxis = void( engine::AnalogAxis* axis );
using InputBindCallback_AnalogStick = void( engine::AnalogStick* stick );
2023-09-21 23:16:40 -07:00
struct InputMode
{
InputBindCallback* binds;
s32 num_binds;
2023-09-21 23:16:40 -07:00
};
void input_mode_pop( InputMode* mode );
void input_mode_pop( InputMode* mode );
2023-09-17 18:20:11 -07:00
2023-09-28 10:44:43 -07:00
#if 0
struct RecordedInput
{
s32 num;
InputState* stream;
2023-09-28 10:44:43 -07:00
};
#endif
2023-10-04 10:55:15 -07:00
struct TileMap
{
u32* tiles;
};
struct World
{
2023-10-06 23:33:39 -07:00
f32 tile_size_in_meters;
s32 tile_size_in_pixels;
2023-10-06 10:06:40 -07:00
f32 tile_upper_left_x;
f32 tile_upper_left_y;
s32 num_tiles_x; // Number of tiles on the x-axis for a tilemap.
s32 num_tiles_y; // Number of tiles on the y-axis for a tilemap.
2023-10-04 10:55:15 -07:00
// TODO(Ed) : Beginner's sparseness
s32 tilemaps_num_x;
s32 tilemaps_num_y;
TileMap* tile_maps;
};
2023-10-06 10:06:40 -07:00
struct CanonPosition
{
2023-10-06 23:33:39 -07:00
// TODO(Ed): Convert these to resolution-indenpent rep of world units (a proper vector space?))
2023-10-06 10:06:40 -07:00
// Note: Tile-Relative position
f32 x;
f32 y;
2023-10-06 23:33:39 -07:00
/* TODO(Ed) :
Take the tile map x & y and the tile x & y
where there is some low bits for the tile index
and the high bits are the tile "page".
*/
2023-10-06 10:06:40 -07:00
s32 tile_map_x;
s32 tile_map_y;
s32 tile_x;
s32 tile_y;
};
// TODO(Ed) : Is this necessary?
struct RawPosition
{
// Note: TileMap-Relative position
f32 x;
f32 y;
s32 tile_map_x;
s32 tile_map_y;
};
2023-09-15 18:35:27 -07:00
NS_ENGINE_END