#ifndef HANDMADE_H_SENTRY #define HANDMADE_H_SENTRY #include "helpers.h" #include "handmade_tile.h" #include /* --------------------------------------------------------------------- */ /* NOTE: Servcies that the platform layer provides to the game. */ /* --------------------------------------------------------------------- */ struct thread_context { int placeholder; }; struct debug_read_file_result { unsigned int contents_size; void *contents; }; struct debug_read_file_result 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 set_program_icon(struct game_offscreen_buffer *program_icon); /* --------------------------------------------------------------------- */ /* 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 bytes_per_pixel; int pitch; }; struct game_sound_output_buffer { int samples_per_second; int sample_count; short *samples; }; struct game_button_state { int half_transition_count; int ended_down; }; struct game_controller_input { int is_connected; int is_analog; float stick_average_x; float stick_average_y; union { struct game_button_state buttons[12]; struct { 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 action_up; struct game_button_state action_down; struct game_button_state action_left; struct game_button_state action_right; struct game_button_state left_shoulder; struct game_button_state right_shoulder; 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 mouse_buttons[5]; int mouse_x, mouse_y, mouse_z; /* NOTE: MouseZ is the wheel. */ float dt_for_frame; 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 is_initialized; 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 transient_storage_size; void *transient_storage; /* WARNING: This memory is REQUIRED to be zero initialized!!! (Done by the OS layer.) */ struct debug_read_file_result (*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); }; /*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 *tile_map; }; struct loaded_bitmap { int width; int height; unsigned int *pixels; }; struct hero_bitmaps { int align_x; int align_y; 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 facing_direction; float height, width; }; struct game_state { struct game_offscreen_buffer program_icon; struct loaded_bitmap program_icon_bmp; struct memory_arena world_arena; struct world *world; unsigned int camera_following_entity_index; struct tile_map_position camera_p; /*unsigned int *PlayerIndexForController[ARRAY_SIZE(((game_input *)0)->Controllers];*/ unsigned int player_index_for_controller[5]; unsigned int entity_count; struct entity entities[256]; struct loaded_bitmap backdrop; struct hero_bitmaps hero_bitmaps[4]; struct v2 rect_pos; }; #endif