Clean up.
This commit is contained in:
+138
-107
@@ -7,137 +7,154 @@
|
||||
/* NOTE: Servcies that the platform layer provides to the game. */
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
typedef struct thread_context {
|
||||
S32 Placeholder;
|
||||
} thread_context;
|
||||
struct thread_context {
|
||||
int Placeholder;
|
||||
};
|
||||
|
||||
#if BUILD_INTERNAL
|
||||
typedef struct debug_read_file_result {
|
||||
U32 ContentsSize;
|
||||
void *Contents;
|
||||
} debug_read_file_result;
|
||||
struct debug_read_file_result {
|
||||
unsigned int ContentsSize;
|
||||
void *Contents;
|
||||
};
|
||||
|
||||
debug_read_file_result DEBUGPlatformReadEntireFile(thread_context *Thread, const char *Filename);
|
||||
B32 DEBUGPlatformWriteEntireFile(thread_context *Thread, const char *Filename, U32 MemorySize, void *Memory);
|
||||
void DEBUGPlatformFreeFileMemory(thread_context *Thread, void *Memory);
|
||||
struct debug_read_file_result
|
||||
DEBUGPlatformReadEntireFile(struct thread_context *Thread,
|
||||
const char *Filename);
|
||||
int DEBUGPlatformWriteEntireFile(struct thread_context *Thread,
|
||||
const char *Filename,
|
||||
unsigned int MemorySize, void *Memory);
|
||||
void DEBUGPlatformFreeFileMemory(struct thread_context *Thread,
|
||||
void *Memory);
|
||||
#endif
|
||||
|
||||
typedef struct game_offscreen_buffer game_offscreen_buffer;
|
||||
void SetProgramIcon(game_offscreen_buffer *ProgramIcon);
|
||||
struct game_offscreen_buffer game_offscreen_buffer;
|
||||
void SetProgramIcon(struct game_offscreen_buffer *ProgramIcon);
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* NOTE: Servcies that the game provides to the platform layer. */
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
typedef struct game_offscreen_buffer {
|
||||
struct game_offscreen_buffer {
|
||||
/* Pixels are always 32-bit and have the bytes in BGRX (little-endian). */
|
||||
void *Memory;
|
||||
S32 Width;
|
||||
S32 Height;
|
||||
S32 BytesPerPixel;
|
||||
S32 Pitch;
|
||||
} game_offscreen_buffer;
|
||||
int Width;
|
||||
int Height;
|
||||
int BytesPerPixel;
|
||||
int Pitch;
|
||||
};
|
||||
|
||||
typedef struct game_sound_output_buffer {
|
||||
S32 SamplesPerSecond;
|
||||
S32 SampleCount;
|
||||
S16 *Samples;
|
||||
} game_sound_output_buffer;
|
||||
struct game_sound_output_buffer {
|
||||
int SamplesPerSecond;
|
||||
int SampleCount;
|
||||
short *Samples;
|
||||
};
|
||||
|
||||
typedef struct game_button_state {
|
||||
S32 HalfTransitionCount;
|
||||
B32 EndedDown;
|
||||
} game_button_state;
|
||||
struct game_button_state {
|
||||
int HalfTransitionCount;
|
||||
int EndedDown;
|
||||
};
|
||||
|
||||
typedef struct game_controller_input {
|
||||
B32 IsConnected;
|
||||
B32 IsAnalog;
|
||||
struct game_controller_input {
|
||||
int IsConnected;
|
||||
int IsAnalog;
|
||||
|
||||
F32 StickAverageX;
|
||||
F32 StickAverageY;
|
||||
float StickAverageX;
|
||||
float StickAverageY;
|
||||
|
||||
union {
|
||||
game_button_state Buttons[12];
|
||||
struct game_button_state Buttons[12];
|
||||
struct {
|
||||
game_button_state MoveUp;
|
||||
game_button_state MoveDown;
|
||||
game_button_state MoveLeft;
|
||||
game_button_state MoveRight;
|
||||
struct game_button_state MoveUp;
|
||||
struct game_button_state MoveDown;
|
||||
struct game_button_state MoveLeft;
|
||||
struct game_button_state MoveRight;
|
||||
|
||||
game_button_state ActionUp;
|
||||
game_button_state ActionDown;
|
||||
game_button_state ActionLeft;
|
||||
game_button_state ActionRight;
|
||||
struct game_button_state ActionUp;
|
||||
struct game_button_state ActionDown;
|
||||
struct game_button_state ActionLeft;
|
||||
struct game_button_state ActionRight;
|
||||
|
||||
game_button_state LeftShoulder;
|
||||
game_button_state RightShoulder;
|
||||
struct game_button_state LeftShoulder;
|
||||
struct game_button_state RightShoulder;
|
||||
|
||||
game_button_state Start;
|
||||
game_button_state Back;
|
||||
struct game_button_state Start;
|
||||
struct game_button_state Back;
|
||||
|
||||
/* NOTE: All buttons must be added above this line. */
|
||||
|
||||
game_button_state Terminator;
|
||||
struct game_button_state Terminator;
|
||||
};
|
||||
};
|
||||
} game_controller_input;
|
||||
};
|
||||
|
||||
typedef struct game_input {
|
||||
game_button_state MouseButtons[5];
|
||||
S32 MouseX, MouseY, MouseZ; /* NOTE: MouseZ is the wheel. */
|
||||
struct game_input {
|
||||
struct game_button_state MouseButtons[5];
|
||||
int MouseX, MouseY, MouseZ; /* NOTE: MouseZ is the wheel. */
|
||||
|
||||
F32 dtForFrame;
|
||||
float dtForFrame;
|
||||
|
||||
game_controller_input Controllers[5];
|
||||
} game_input;
|
||||
struct game_controller_input Controllers[5];
|
||||
};
|
||||
|
||||
game_controller_input *GetController(game_input *Input, S32 ControllerIndex)
|
||||
struct game_controller_input *GetController(struct game_input *Input,
|
||||
int ControllerIndex)
|
||||
{
|
||||
game_controller_input *Result;
|
||||
struct game_controller_input *Result;
|
||||
|
||||
ASSERT((U32)ControllerIndex < ARRAY_SIZE(Input->Controllers));
|
||||
ASSERT((unsigned int)ControllerIndex < ARRAY_SIZE(Input->Controllers));
|
||||
Result = &(Input->Controllers[ControllerIndex]);
|
||||
return Result;
|
||||
}
|
||||
|
||||
typedef struct game_memory {
|
||||
B32 IsInitialized;
|
||||
struct game_memory {
|
||||
int IsInitialized;
|
||||
|
||||
U64 PermanentStorageSize;
|
||||
void *PermanentStorage; /* WARNING: This memory is REQUIRED to be zero initialized!!! (Done by the OS layer.) */
|
||||
unsigned long long PermanentStorageSize;
|
||||
void *PermanentStorage; /* WARNING: This memory is REQUIRED to be zero
|
||||
initialized!!! (Done by the OS layer.) */
|
||||
|
||||
U64 TransientStorageSize;
|
||||
void *TransientStorage; /* WARNING: This memory is REQUIRED to be zero initialized!!! (Done by the OS layer.) */
|
||||
unsigned long long TransientStorageSize;
|
||||
void *TransientStorage; /* WARNING: This memory is REQUIRED to be zero
|
||||
initialized!!! (Done by the OS layer.) */
|
||||
|
||||
#if BUILD_INTERNAL
|
||||
debug_read_file_result (*DEBUGPlatformReadEntireFile)(thread_context *Thread,const char *);
|
||||
B32 (*DEBUGPlatformWriteEntireFile)(thread_context *Thread, const char *, U32, void *);
|
||||
void (*DEBUGPlatformFreeFileMemory)(thread_context *Thread, void *);
|
||||
void (*SetProgramIcon)(game_offscreen_buffer *ProgramIcon);
|
||||
struct debug_read_file_result
|
||||
(*DEBUGPlatformReadEntireFile)(struct thread_context *Thread,
|
||||
const char *);
|
||||
int (*DEBUGPlatformWriteEntireFile)(struct thread_context *Thread,
|
||||
const char *, unsigned int, void *);
|
||||
void (*DEBUGPlatformFreeFileMemory)(struct thread_context *Thread,
|
||||
void *);
|
||||
void (*SetProgramIcon)(struct game_offscreen_buffer *ProgramIcon);
|
||||
#endif
|
||||
} game_memory;
|
||||
};
|
||||
|
||||
/*typedef struct game_clocks {
|
||||
U64 Ticks;
|
||||
F32 SecondsElapsed;
|
||||
} game_clocks;*/
|
||||
/*struct game_clocks {
|
||||
unsigned long long Ticks;
|
||||
float SecondsElapsed;
|
||||
};*/
|
||||
|
||||
#if OS_WINDOWS
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
void UpdateAndRender(thread_context *Thread, game_memory *Memory, game_input *Input, game_offscreen_buffer *Buffer, game_sound_output_buffer *SoundBuffer);
|
||||
void UpdateAndRender(struct thread_context *Thread,
|
||||
struct game_memory *Memory,
|
||||
struct game_input *Input,
|
||||
struct game_offscreen_buffer *Buffer,
|
||||
struct game_sound_output_buffer *SoundBuffer);
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
typedef struct memory_arena {
|
||||
U64 Size;
|
||||
U8 *Base;
|
||||
U64 Used;
|
||||
} memory_arena;
|
||||
struct memory_arena {
|
||||
unsigned long long Size;
|
||||
unsigned char *Base;
|
||||
unsigned long long Used;
|
||||
};
|
||||
|
||||
static void InitializeArena(memory_arena *Arena, U64 Size, U8 *Base)
|
||||
static void InitializeArena(struct memory_arena *Arena,
|
||||
unsigned long long Size, unsigned char *Base)
|
||||
{
|
||||
Arena->Size = Size;
|
||||
Arena->Base = Base;
|
||||
@@ -145,8 +162,9 @@ static void InitializeArena(memory_arena *Arena, U64 Size, U8 *Base)
|
||||
}
|
||||
|
||||
#define PUSH_STRUCT(Arena, type) (type *)PushSize_(Arena, sizeof(type))
|
||||
#define PUSH_ARRAY(Arena, Count, type) (type *)PushSize_(Arena, (Count)*sizeof(type))
|
||||
static void *PushSize_(memory_arena *Arena, U64 Size)
|
||||
#define PUSH_ARRAY(Arena, Count, type) \
|
||||
(type *)PushSize_(Arena, (Count)*sizeof(type))
|
||||
static void *PushSize_(struct memory_arena *Arena, unsigned long long Size)
|
||||
{
|
||||
void *Result;
|
||||
|
||||
@@ -157,41 +175,54 @@ static void *PushSize_(memory_arena *Arena, U64 Size)
|
||||
return Result;
|
||||
}
|
||||
|
||||
typedef struct world {
|
||||
tile_map *TileMap;
|
||||
} world;
|
||||
struct world {
|
||||
struct tile_map *TileMap;
|
||||
};
|
||||
|
||||
typedef struct loaded_bitmap {
|
||||
S32 Width;
|
||||
S32 Height;
|
||||
U32 *Pixels;
|
||||
} loaded_bitmap;
|
||||
struct loaded_bitmap {
|
||||
int Width;
|
||||
int Height;
|
||||
unsigned int *Pixels;
|
||||
};
|
||||
|
||||
typedef struct hero_bitmaps {
|
||||
S32 AlignX;
|
||||
S32 AlignY;
|
||||
struct hero_bitmaps {
|
||||
int AlignX;
|
||||
int AlignY;
|
||||
|
||||
loaded_bitmap Head;
|
||||
loaded_bitmap Cape;
|
||||
loaded_bitmap Torso;
|
||||
} hero_bitmaps;
|
||||
struct loaded_bitmap Head;
|
||||
struct loaded_bitmap Cape;
|
||||
struct loaded_bitmap Torso;
|
||||
};
|
||||
|
||||
typedef struct game_state {
|
||||
game_offscreen_buffer ProgramIcon;
|
||||
loaded_bitmap ProgramIconBMP;
|
||||
struct entity {
|
||||
int Exists;
|
||||
struct tile_map_position P;
|
||||
struct v2 dP; // velocity
|
||||
unsigned int FacingDirection;
|
||||
float Height, Width;
|
||||
};
|
||||
|
||||
memory_arena WorldArena;
|
||||
world *World;
|
||||
struct game_state {
|
||||
struct game_offscreen_buffer ProgramIcon;
|
||||
struct loaded_bitmap ProgramIconBMP;
|
||||
|
||||
tile_map_position CameraP;
|
||||
tile_map_position PlayerP;
|
||||
v2 dPlayerP; // velocity
|
||||
struct memory_arena WorldArena;
|
||||
struct world *World;
|
||||
|
||||
unsigned int CameraFollowingEntityIndex;
|
||||
struct tile_map_position CameraP;
|
||||
|
||||
loaded_bitmap Backdrop;
|
||||
/*unsigned int
|
||||
*PlayerIndexForController[ARRAY_SIZE(((game_input *)0)->Controllers];*/
|
||||
unsigned int PlayerIndexForController[5];
|
||||
unsigned int EntityCount;
|
||||
struct entity Entities[256];
|
||||
|
||||
U32 FacingDirection;
|
||||
hero_bitmaps HeroBitmaps[4];
|
||||
} game_state;
|
||||
struct loaded_bitmap Backdrop;
|
||||
|
||||
struct hero_bitmaps HeroBitmaps[4];
|
||||
|
||||
struct v2 rect_pos;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user