Remove core.h, SDL2->SDL3, Makefile cleanup, ansi C, 80 char.

This commit is contained in:
2026-08-04 04:52:46 -07:00
parent a829ac8647
commit 14d87eac10
162 changed files with 57434 additions and 31335 deletions
+101 -99
View File
@@ -1,34 +1,37 @@
#ifndef HANDMADE_H_SENTRY
#define HANDMADE_H_SENTRY
#include "core.h"
#include "helpers.h"
#include "handmade_tile.h"
#include <assert.h>
/* --------------------------------------------------------------------- */
/* NOTE: Servcies that the platform layer provides to the game. */
/* --------------------------------------------------------------------- */
struct thread_context {
int Placeholder;
int placeholder;
};
#if BUILD_INTERNAL
struct debug_read_file_result {
unsigned int ContentsSize;
void *Contents;
unsigned int contents_size;
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
debug_platform_read_entire_file(struct thread_context *thread,
const char *filename);
int debug_platform_write_entire_file(struct thread_context *thread,
const char *filename,
unsigned int memory_size,
void *memory);
void debug_platform_free_file_memory(struct thread_context *thread,
void *memory);
struct game_offscreen_buffer game_offscreen_buffer;
void SetProgramIcon(struct game_offscreen_buffer *ProgramIcon);
void set_program_icon(struct game_offscreen_buffer *program_icon);
/* --------------------------------------------------------------------- */
/* NOTE: Servcies that the game provides to the platform layer. */
@@ -36,64 +39,64 @@ void SetProgramIcon(struct game_offscreen_buffer *ProgramIcon);
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;
void *memory;
int width;
int height;
int bytes_per_pixel;
int pitch;
};
struct game_sound_output_buffer {
int SamplesPerSecond;
int SampleCount;
short *Samples;
int samples_per_second;
int sample_count;
short *samples;
};
struct game_button_state {
int HalfTransitionCount;
int EndedDown;
int half_transition_count;
int ended_down;
};
struct game_controller_input {
int IsConnected;
int IsAnalog;
int is_connected;
int is_analog;
float StickAverageX;
float StickAverageY;
float stick_average_x;
float stick_average_y;
union {
struct game_button_state Buttons[12];
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 move_up;
struct game_button_state move_down;
struct game_button_state move_left;
struct game_button_state move_right;
struct game_button_state ActionUp;
struct game_button_state ActionDown;
struct game_button_state ActionLeft;
struct game_button_state ActionRight;
struct game_button_state action_up;
struct game_button_state action_down;
struct game_button_state action_left;
struct game_button_state action_right;
struct game_button_state LeftShoulder;
struct game_button_state RightShoulder;
struct game_button_state left_shoulder;
struct game_button_state right_shoulder;
struct game_button_state Start;
struct game_button_state Back;
struct game_button_state start;
struct game_button_state back;
/* NOTE: All buttons must be added above this line. */
struct game_button_state Terminator;
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. */
struct game_button_state mouse_buttons[5];
int mouse_x, mouse_y, mouse_z; /* NOTE: MouseZ is the wheel. */
float dtForFrame;
float dt_for_frame;
struct game_controller_input Controllers[5];
struct game_controller_input controllers[5];
};
struct game_controller_input *GetController(struct game_input *Input,
@@ -101,32 +104,31 @@ struct game_controller_input *GetController(struct game_input *Input,
{
struct game_controller_input *Result;
ASSERT((unsigned int)ControllerIndex < ARRAY_SIZE(Input->Controllers));
Result = &(Input->Controllers[ControllerIndex]);
assert((unsigned int)ControllerIndex < ARRAY_SIZE(Input->controllers));
Result = &(Input->controllers[ControllerIndex]);
return Result;
}
struct game_memory {
int IsInitialized;
int is_initialized;
unsigned long long PermanentStorageSize;
void *PermanentStorage; /* WARNING: This memory is REQUIRED to be zero
initialized!!! (Done by the OS layer.) */
unsigned long long permanent_storage_size;
void *permanent_storage; /* 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.) */
unsigned long long transient_storage_size;
void *transient_storage; /* 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 *);
(*debug_platform_read_entire_file)(struct thread_context *Thread,
const char *);
int (*debug_platform_write_entire_file)(struct thread_context *Thread,
const char *, unsigned int,
void *);
void (*debug_platform_free_file_memory)(struct thread_context *Thread,
void *);
void (*SetProgramIcon)(struct game_offscreen_buffer *ProgramIcon);
#endif
};
/*struct game_clocks {
@@ -148,17 +150,17 @@ void UpdateAndRender(struct thread_context *Thread,
*/
struct memory_arena {
unsigned long long Size;
unsigned char *Base;
unsigned long long Used;
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)
static void InitializeArena(struct memory_arena *arena,
unsigned long long size, unsigned char *base)
{
Arena->Size = Size;
Arena->Base = Base;
Arena->Used = 0;
arena->size = size;
arena->base = base;
arena->used = 0;
}
#define PUSH_STRUCT(Arena, type) (type *)PushSize_(Arena, sizeof(type))
@@ -168,59 +170,59 @@ static void *PushSize_(struct memory_arena *Arena, unsigned long long Size)
{
void *Result;
ASSERT((Arena->Used + Size) <= Arena->Size);
assert((Arena->used + Size) <= Arena->size);
Result = (void *)(Arena->Base + Arena->Used);
Arena->Used += Size;
Result = (void *)(Arena->base + Arena->used);
Arena->used += Size;
return Result;
}
struct world {
struct tile_map *TileMap;
struct tile_map *tile_map;
};
struct loaded_bitmap {
int Width;
int Height;
unsigned int *Pixels;
int width;
int height;
unsigned int *pixels;
};
struct hero_bitmaps {
int AlignX;
int AlignY;
int align_x;
int align_y;
struct loaded_bitmap Head;
struct loaded_bitmap Cape;
struct loaded_bitmap Torso;
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;
int exists;
struct tile_map_position p;
struct v2 dp; /* velocity */
unsigned int facing_direction;
float height, width;
};
struct game_state {
struct game_offscreen_buffer ProgramIcon;
struct loaded_bitmap ProgramIconBMP;
struct game_offscreen_buffer program_icon;
struct loaded_bitmap program_icon_bmp;
struct memory_arena WorldArena;
struct world *World;
struct memory_arena world_arena;
struct world *world;
unsigned int CameraFollowingEntityIndex;
struct tile_map_position CameraP;
unsigned int camera_following_entity_index;
struct tile_map_position camera_p;
/*unsigned int
*PlayerIndexForController[ARRAY_SIZE(((game_input *)0)->Controllers];*/
unsigned int PlayerIndexForController[5];
unsigned int EntityCount;
struct entity Entities[256];
unsigned int player_index_for_controller[5];
unsigned int entity_count;
struct entity entities[256];
struct loaded_bitmap Backdrop;
struct loaded_bitmap backdrop;
struct hero_bitmaps HeroBitmaps[4];
struct hero_bitmaps hero_bitmaps[4];
struct v2 rect_pos;
};