vn/code/vn_platform.h

213 lines
4.9 KiB
C

/* date = April 26th 2023 5:12 pm */
#ifndef VN_PLATFORM_H
#define VN_PLATFORM_H
#include "vn_core.h"
// sixten: Services the platform provides to the game
struct platform_memory_block
{
u8 *Base;
u64 Size;
u64 Used;
platform_memory_block *ArenaPrev;
};
#define PLATFORM_ALLOCATE_MEMORY(name) platform_memory_block *name(u64 Size)
typedef PLATFORM_ALLOCATE_MEMORY(platform_allocate_memory);
#define PLATFORM_DEALLOCATE_MEMORY(name) b32 name(platform_memory_block *Block)
typedef PLATFORM_DEALLOCATE_MEMORY(platform_deallocate_memory);
enum
{
PlatformAccess_Read = 0x1,
PlatformAccess_Write = 0x2,
};
typedef u32 platform_access_flags;
struct platform_file_handle
{
u64 Platform;
b32 IsValid;
};
#define PLATFORM_OPEN_FILE(name) platform_file_handle name(string Path, platform_access_flags FileAccess)
typedef PLATFORM_OPEN_FILE(platform_open_file);
#define PLATFORM_CLOSE_FILE(name) void name(platform_file_handle Handle)
typedef PLATFORM_CLOSE_FILE(platform_close_file);
#define PLATFORM_READ_FILE(name) void name(platform_file_handle Handle, void *Dest, u64 Offset, u64 Size)
typedef PLATFORM_READ_FILE(platform_read_file);
#define PLATFORM_GET_FILE_SIZE(name) u64 name(platform_file_handle Handle)
typedef PLATFORM_GET_FILE_SIZE(platform_get_file_size);
enum platform_cursor
{
PlatformCursor_Arrow,
PlatformCursor_Cross,
PlatformCursor_Hand,
PlatformCursor_Help,
PlatformCursor_IBeam,
PlatformCursor_SlashedCircle,
PlatformCursor_ArrowAll,
PlatformCursor_ArrowNESW,
PlatformCursor_ArrowVertical,
PlatformCursor_ArrowNWSE,
PlatformCursor_ArrowHorizontal,
PlatformCursor_Wait,
PlatformCursor_Count
};
#define PLATFORM_SET_CURSOR(name) void name(platform_cursor Cursor)
typedef PLATFORM_SET_CURSOR(platform_set_cursor);
#define PLATFORM_TOGGLE_FULLSCREEN(name) void name(void)
typedef PLATFORM_TOGGLE_FULLSCREEN(platform_toggle_fullscreen);
struct platform_api
{
platform_allocate_memory *AllocateMemory;
platform_deallocate_memory *DeallocateMemory;
platform_open_file *OpenFile;
platform_close_file *CloseFile;
platform_read_file *ReadFile;
platform_get_file_size *GetFileSize;
platform_set_cursor *SetCursor;
platform_toggle_fullscreen *ToggleFullscreen;
};
enum platform_event_type
{
PlatformEvent_Press,
PlatformEvent_Release,
PlatformEvent_Text,
PlatformEvent_MouseScroll,
};
enum platform_key
{
Key_Invalid,
Key_A, Key_B, Key_C, Key_D,
Key_E, Key_F, Key_G, Key_H,
Key_I, Key_J, Key_K, Key_L,
Key_M, Key_N, Key_O, Key_P,
Key_Q, Key_R, Key_S, Key_T,
Key_U, Key_V, Key_W, Key_X,
Key_Y, Key_Z,
Key_F1, Key_F2, Key_F3, Key_F4,
Key_F5, Key_F6, Key_F7, Key_F8,
Key_F9, Key_F10, Key_F11, Key_F12,
Key_Left, Key_Right, Key_Up, Key_Down,
Key_Space,
Key_PageUp, Key_PageDown,
Key_Home, Key_End,
Key_Backspace, Key_Delete,
Key_MouseLeft, Key_MouseMiddle, Key_MouseRight,
};
typedef u32 platform_modifiers;
enum
{
PlatformModifier_Ctrl = (1 << 0),
PlatformModifier_Shift = (1 << 1),
PlatformModifier_Alt = (1 << 2),
PlatformModifier_DoesNotMatter = -1
};
struct platform_event
{
platform_event *Next;
platform_event *Prev;
platform_event_type Type;
platform_modifiers Modifiers;
platform_key Key;
u32 Codepoint;
v2 P;
v2 Scroll;
};
struct platform_event_list
{
platform_event *First;
platform_event *Last;
};
static platform_api Platform;
// sixten: Services that the render backend provides to the game
#include "vn_render.h"
#define RENDER_ALLOCATE_TEXTURE(name) render_handle name(v2s Dim, render_texture_format Format, void *Data)
typedef RENDER_ALLOCATE_TEXTURE(render_allocate_texture);
#define RENDER_FILL_REGION(name) void name(render_handle Handle, v2s DestP, v2s DestDim, void *Data)
typedef RENDER_FILL_REGION(render_fill_region);
struct vn_render_commands
{
render_allocate_texture *AllocateTexture;
render_fill_region *FillRegion;
render_handle WhiteTexture;
u64 MaxPushBufferSize;
u8 *PushBufferBase;
u8 *PushBufferAt;
s32 MaxQuadVertexCount;
quad_vertex *QuadVertexBase;
s32 QuadVertexCount;
s32 MaxQuadIndexCount;
s32 *QuadIndexBase;
s32 QuadIndexCount;
v2 RenderDim;
};
#include "vn_memory.h"
#include "vn_string.h"
#include "vn_thread_context.h"
// sixten: Services the game provides to the platform
struct vn_input
{
platform_event_list *EventList;
v2 MouseP;
v2 dMouseP;
r32 dtForFrame;
};
struct vn_memory
{
platform_api PlatformAPI;
struct vn_state *State;
};
#define VN_UPDATE_AND_RENDER(name) void name(thread_context *ThreadContext, vn_memory *Memory, vn_input *Input, vn_render_commands *RenderCommands)
typedef VN_UPDATE_AND_RENDER(vn_update_and_render);
#endif //VN_PLATFORM_H