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
|
2023-09-23 18:52:38 -07:00
|
|
|
#include "platform/platform.hpp"
|
2023-10-11 14:52:13 -07:00
|
|
|
#include "engine_module.hpp"
|
|
|
|
#include "tile_map.hpp"
|
2023-10-10 10:08:08 -07:00
|
|
|
#endif
|
|
|
|
|
2023-09-15 18:35:27 -07:00
|
|
|
NS_ENGINE_BEGIN
|
|
|
|
|
2023-09-18 17:16:40 -07:00
|
|
|
struct Clocks
|
|
|
|
{
|
|
|
|
// TODO(Ed) : Clock values...
|
2023-09-30 07:05:37 -07:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2023-10-11 14:52:13 -07:00
|
|
|
|
|
|
|
enum ReplayMode : s32
|
|
|
|
{
|
|
|
|
ReplayMode_Off,
|
|
|
|
ReplayMode_Record,
|
|
|
|
ReplayMode_Playback
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ReplayData
|
|
|
|
{
|
|
|
|
static constexpr
|
|
|
|
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.
|
|
|
|
|
|
|
|
ReplayMode replay_mode;
|
|
|
|
platform::File active_input_replay_file;
|
|
|
|
|
|
|
|
// Engine-wide recording & playback loop.
|
|
|
|
s32 engine_loop_active;
|
|
|
|
s32 game_loop_active;
|
|
|
|
};
|
|
|
|
|
2023-09-18 17:16:40 -07:00
|
|
|
struct Memory
|
|
|
|
{
|
|
|
|
// All memory for the engine is required to be zero initialized.
|
|
|
|
|
|
|
|
// Wiped on shutdown
|
2023-10-11 14:52:13 -07:00
|
|
|
Byte* persistent;
|
|
|
|
ssize 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?
|
2023-10-11 14:52:13 -07:00
|
|
|
Byte* transient;
|
|
|
|
ssize transient_size;
|
2023-09-30 07:05:37 -07:00
|
|
|
|
2023-10-11 14:52:13 -07:00
|
|
|
// TODO(Ed) : Move this to state & replay archive definitions?
|
2023-09-30 12:40:27 -07:00
|
|
|
#if Build_Development
|
2023-09-30 07:05:37 -07:00
|
|
|
static constexpr
|
2023-10-01 17:17:14 -07:00
|
|
|
s32 Num_Snapshot_Slots = 3;
|
2023-09-30 07:05:37 -07:00
|
|
|
// 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;
|
2023-09-30 07:05:37 -07:00
|
|
|
|
|
|
|
// Engine-wide recording & playback loop.
|
|
|
|
s32 engine_loop_active;
|
|
|
|
s32 game_loop_active;
|
2023-10-17 20:50:28 -07:00
|
|
|
|
2023-10-11 14:52:13 -07:00
|
|
|
//ReplayData replay;
|
2023-09-30 12:40:27 -07:00
|
|
|
#endif
|
2023-10-17 20:50:28 -07:00
|
|
|
|
2023-10-19 11:16:50 -07:00
|
|
|
// The game will have 1/2 of persistent's memory available ot it.
|
2023-10-11 14:52:13 -07:00
|
|
|
static constexpr
|
2023-10-19 11:16:50 -07:00
|
|
|
ssize game_memory_factor = 2;
|
2023-10-17 20:50:28 -07:00
|
|
|
|
2023-10-11 14:52:13 -07:00
|
|
|
ssize engine_persistent_size()
|
|
|
|
{
|
|
|
|
return persistent_size - persistent_size / game_memory_factor;
|
|
|
|
}
|
2023-10-17 20:50:28 -07:00
|
|
|
|
2023-10-11 14:52:13 -07:00
|
|
|
ssize total_size()
|
2023-09-30 07:05:37 -07:00
|
|
|
{
|
|
|
|
return persistent_size + transient_size;
|
|
|
|
}
|
2023-09-18 17:16:40 -07:00
|
|
|
};
|
|
|
|
|
2023-10-17 20:50:28 -07:00
|
|
|
// Allocator member-interface macros
|
|
|
|
#define push_struct( type ) push__struct<type>()
|
|
|
|
#define push_array( type, num ) push__array<type>( num )
|
|
|
|
|
2023-10-11 14:52:13 -07:00
|
|
|
struct MemoryArena
|
|
|
|
{
|
|
|
|
Byte* storage;
|
|
|
|
ssize size;
|
|
|
|
ssize used;
|
2023-10-17 20:50:28 -07:00
|
|
|
|
|
|
|
static
|
|
|
|
void init( MemoryArena* arena, ssize size, Byte* storage )
|
|
|
|
{
|
|
|
|
arena->storage = storage;
|
|
|
|
arena->size = size;
|
|
|
|
arena->used = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template< typename Type >
|
|
|
|
Type* push__struct()
|
|
|
|
{
|
|
|
|
ssize type_size = sizeof( Type );
|
|
|
|
assert( used + type_size <= size );
|
|
|
|
|
|
|
|
Type* result = rcast(Type*, storage + used);
|
|
|
|
used += type_size;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
template< typename Type >
|
|
|
|
Type* push__array( ssize num )
|
|
|
|
{
|
|
|
|
ssize mem_amount = sizeof( Type ) * num;
|
|
|
|
assert( used + mem_amount <= size );
|
|
|
|
|
|
|
|
Type* result = rcast(Type*, storage + used);
|
|
|
|
used += mem_amount;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2023-10-11 14:52:13 -07:00
|
|
|
};
|
|
|
|
|
2023-09-15 18:35:27 -07:00
|
|
|
struct OffscreenBuffer
|
|
|
|
{
|
2023-09-30 07:05:37 -07:00
|
|
|
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
|
|
|
{
|
2023-09-30 07:05:37 -07:00
|
|
|
s16* samples;
|
|
|
|
u32 running_sample_index;
|
|
|
|
s32 samples_per_second;
|
|
|
|
s32 num_samples;
|
2023-09-16 15:41:07 -07:00
|
|
|
};
|
|
|
|
|
2023-10-04 10:55:15 -07:00
|
|
|
struct World
|
|
|
|
{
|
2023-10-10 21:56:16 -07:00
|
|
|
f32 tile_lower_left_x;
|
|
|
|
f32 tile_lower_left_y;
|
|
|
|
|
2023-10-17 20:50:28 -07:00
|
|
|
f32 tile_meters_to_pixels;
|
|
|
|
s32 tile_size_in_pixels;
|
2023-10-21 19:21:53 -07:00
|
|
|
|
|
|
|
s32 tiles_per_screen_x;
|
|
|
|
s32 tiles_per_screen_y;
|
2023-10-17 20:50:28 -07:00
|
|
|
|
2023-10-11 14:52:13 -07:00
|
|
|
TileMap* tile_map;
|
2023-10-06 10:06:40 -07:00
|
|
|
};
|
|
|
|
|
2023-10-19 11:16:50 -07:00
|
|
|
#pragma pack(push, 1)
|
|
|
|
struct BitmapHeaderPacked
|
|
|
|
{
|
|
|
|
u16 file_type;
|
|
|
|
u32 file_size;
|
|
|
|
u16 _reserved_1_;
|
|
|
|
u16 _reserved_2_;
|
|
|
|
u32 bitmap_offset;
|
|
|
|
u32 size;
|
|
|
|
s32 width;
|
|
|
|
s32 height;
|
|
|
|
u16 planes;
|
|
|
|
u16 bits_per_pixel;
|
2023-10-20 20:15:35 -07:00
|
|
|
u32 compression;
|
|
|
|
u32 size_of_bitmap;
|
|
|
|
s32 horizontal_resolution;
|
|
|
|
s32 vertical_resolution;
|
|
|
|
u32 colors_used;
|
|
|
|
u32 colors_important;
|
|
|
|
|
|
|
|
u32 red_mask;
|
|
|
|
u32 green_mask;
|
|
|
|
u32 blue_mask;
|
2023-10-19 11:16:50 -07:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
struct Bitmap
|
|
|
|
{
|
|
|
|
u32* pixels;
|
|
|
|
s32 width;
|
|
|
|
s32 height;
|
|
|
|
u32 bits_per_pixel;
|
|
|
|
};
|
|
|
|
|
2023-09-15 18:35:27 -07:00
|
|
|
NS_ENGINE_END
|