Files
handmadehero/handmade.h
T

229 lines
6.1 KiB
C

#ifndef HANDMADE_H_SENTRY
#define HANDMADE_H_SENTRY
#include "core.h"
#include "handmade_tile.h"
/* --------------------------------------------------------------------- */
/* NOTE: Servcies that the platform layer provides to the game. */
/* --------------------------------------------------------------------- */
struct thread_context {
int Placeholder;
};
#if BUILD_INTERNAL
struct debug_read_file_result {
unsigned int ContentsSize;
void *Contents;
};
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
struct game_offscreen_buffer game_offscreen_buffer;
void SetProgramIcon(struct game_offscreen_buffer *ProgramIcon);
/* --------------------------------------------------------------------- */
/* NOTE: Servcies that the game provides to the platform layer. */
/* --------------------------------------------------------------------- */
struct game_offscreen_buffer {
/* Pixels are always 32-bit and have the bytes in BGRX (little-endian). */
void *Memory;
int Width;
int Height;
int BytesPerPixel;
int Pitch;
};
struct game_sound_output_buffer {
int SamplesPerSecond;
int SampleCount;
short *Samples;
};
struct game_button_state {
int HalfTransitionCount;
int EndedDown;
};
struct game_controller_input {
int IsConnected;
int IsAnalog;
float StickAverageX;
float StickAverageY;
union {
struct game_button_state Buttons[12];
struct {
struct game_button_state MoveUp;
struct game_button_state MoveDown;
struct game_button_state MoveLeft;
struct game_button_state MoveRight;
struct game_button_state ActionUp;
struct game_button_state ActionDown;
struct game_button_state ActionLeft;
struct game_button_state ActionRight;
struct game_button_state LeftShoulder;
struct game_button_state RightShoulder;
struct game_button_state Start;
struct game_button_state Back;
/* NOTE: All buttons must be added above this line. */
struct game_button_state Terminator;
} s;
} u;
};
struct game_input {
struct game_button_state MouseButtons[5];
int MouseX, MouseY, MouseZ; /* NOTE: MouseZ is the wheel. */
float dtForFrame;
struct game_controller_input Controllers[5];
};
struct game_controller_input *GetController(struct game_input *Input,
int ControllerIndex)
{
struct game_controller_input *Result;
ASSERT((unsigned int)ControllerIndex < ARRAY_SIZE(Input->Controllers));
Result = &(Input->Controllers[ControllerIndex]);
return Result;
}
struct game_memory {
int IsInitialized;
unsigned long long PermanentStorageSize;
void *PermanentStorage; /* 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
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
};
/*struct game_clocks {
unsigned long long Ticks;
float SecondsElapsed;
};*/
#if OS_WINDOWS
__declspec(dllexport)
#endif
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);
/*
*
*/
struct memory_arena {
unsigned long long Size;
unsigned char *Base;
unsigned long long Used;
};
static void InitializeArena(struct memory_arena *Arena,
unsigned long long Size, unsigned char *Base)
{
Arena->Size = Size;
Arena->Base = Base;
Arena->Used = 0;
}
#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_(struct memory_arena *Arena, unsigned long long Size)
{
void *Result;
ASSERT((Arena->Used + Size) <= Arena->Size);
Result = (void *)(Arena->Base + Arena->Used);
Arena->Used += Size;
return Result;
}
struct world {
struct tile_map *TileMap;
};
struct loaded_bitmap {
int Width;
int Height;
unsigned int *Pixels;
};
struct hero_bitmaps {
int AlignX;
int AlignY;
struct loaded_bitmap Head;
struct loaded_bitmap Cape;
struct loaded_bitmap Torso;
};
struct entity {
int Exists;
struct tile_map_position P;
struct v2 dP; /* velocity */
unsigned int FacingDirection;
float Height, Width;
};
struct game_state {
struct game_offscreen_buffer ProgramIcon;
struct loaded_bitmap ProgramIconBMP;
struct memory_arena WorldArena;
struct world *World;
unsigned int CameraFollowingEntityIndex;
struct tile_map_position CameraP;
/*unsigned int
*PlayerIndexForController[ARRAY_SIZE(((game_input *)0)->Controllers];*/
unsigned int PlayerIndexForController[5];
unsigned int EntityCount;
struct entity Entities[256];
struct loaded_bitmap Backdrop;
struct hero_bitmaps HeroBitmaps[4];
struct v2 rect_pos;
};
#endif