HandmadeHero/project/engine/engine.hpp

264 lines
4.3 KiB
C++
Raw Normal View History

2023-09-15 18:35:27 -07:00
/*
Services the engine provides to the platform layer
*/
#pragma once
#include "platform/platform.hpp"
2023-09-15 18:35:27 -07:00
#define NS_ENGINE_BEGIN namespace engine {
#define NS_ENGINE_END }
NS_ENGINE_BEGIN
2023-09-18 17:16:40 -07:00
struct Clocks
{
// TODO(Ed) : Clock values...
f32 seconds_elapsed;
};
struct ThreadContext
{
u32 placeholder;
};
struct MemorySnapshot
{
Str file_path;
void* memory;
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?
static constexpr
s32 Num_Snapshot_Slots = 4;
// 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.
s32 input_recording_index;
s32 input_playback_index;
platform::File active_recording_file;
platform::File active_playback_file;
// Engine-wide recording & playback loop.
s32 engine_loop_active;
s32 game_loop_active;
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 {
DigitalBtn row_1;
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;
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-09-15 18:35:27 -07:00
NS_ENGINE_END