update
This commit is contained in:
111
src/handmade.h
111
src/handmade.h
@@ -6,6 +6,38 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* ---------------
|
||||
* Global flags:
|
||||
* ---------------
|
||||
*
|
||||
* HANDMADE_SLOW
|
||||
* 0 - No slow code allowed
|
||||
* 1 - Slow code welcome
|
||||
*
|
||||
* HANDMADE_INTERNAL
|
||||
* 0 - Build for public release
|
||||
* 1 - Build for developer only
|
||||
*
|
||||
* HANDMADE_WIN32
|
||||
* 0 - Not a windows build
|
||||
* 1 - This is a windows build
|
||||
*
|
||||
*/
|
||||
|
||||
#if HANDMADE_SLOW
|
||||
#define Assert(Expression) if (!(Expression)) {*(int *)0 = 0;}
|
||||
#else
|
||||
#define Assert(Expression)
|
||||
#endif
|
||||
|
||||
#define Kilobytes(Value) (Value*1024)
|
||||
#define Megabytes(Value) (Kilobytes(Value)*1024)
|
||||
#define Gigabytes(Value) (Megabytes(Value)*1024)
|
||||
#define Terabytes(Value) (Gigabytes(Value)*1024)
|
||||
|
||||
#define ArrayCount(Array) (sizeof(Array) / sizeof((Array)[0]))
|
||||
|
||||
#define internal static // for functions
|
||||
#define local_persist static // for static variables in a scope
|
||||
#define global static // for global variables
|
||||
@@ -25,14 +57,14 @@ typedef double real64;
|
||||
|
||||
typedef int32_t bool32;
|
||||
|
||||
void debug_printf(wchar_t* format, ...);
|
||||
#define MAX_SAFE_UINT32 0xFFFFFFFF
|
||||
|
||||
inline uint32 safeTruncateUInt64(uint64 val) {
|
||||
Assert(val <= MAX_SAFE_UINT32);
|
||||
return (uint32)val;
|
||||
}
|
||||
|
||||
// Game to platform layer services
|
||||
struct GameInput {
|
||||
int xOffset;
|
||||
int yOffset;
|
||||
};
|
||||
|
||||
struct GameSoundOutputBuffer {
|
||||
int samplesPerSecond;
|
||||
int sampleCount;
|
||||
@@ -45,6 +77,69 @@ struct GameOffscreenBuffer {
|
||||
int height;
|
||||
};
|
||||
|
||||
void gameUpdateAndRender(GameOffscreenBuffer *videoBuf, GameInput *input, GameSoundOutputBuffer *soundBuf);
|
||||
struct GameButtonState {
|
||||
int halfTransitionCount;
|
||||
bool32 endedDown;
|
||||
};
|
||||
|
||||
struct GameControllerInput {
|
||||
bool32 isAnalog;
|
||||
|
||||
real32 stickAvgY;
|
||||
real32 stickAvgX;
|
||||
|
||||
union {
|
||||
GameButtonState buttons[6];
|
||||
struct {
|
||||
GameButtonState stickUp;
|
||||
GameButtonState stickDown;
|
||||
GameButtonState stickLeft;
|
||||
GameButtonState stickRight;
|
||||
GameButtonState btnUp;
|
||||
GameButtonState btnDown;
|
||||
GameButtonState btnLeft;
|
||||
GameButtonState btnRight;
|
||||
GameButtonState leftShoulder;
|
||||
GameButtonState rightShoulder;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
struct GameInput {
|
||||
GameControllerInput controllers[5];
|
||||
};
|
||||
|
||||
struct GameMemory {
|
||||
bool32 isInitialised;
|
||||
uint64 permanentStorageSize;
|
||||
void *permanentStorage; // required to be initialised to zero at startup
|
||||
uint64 transientStorageSize;
|
||||
void *transientStorage; // required to be initialised to zero at startup
|
||||
};
|
||||
|
||||
struct GameState {
|
||||
int toneHz;
|
||||
int greenOffset;
|
||||
int blueOffset;
|
||||
real32 tSine;
|
||||
};
|
||||
|
||||
// === Game to platform services ===
|
||||
void gameUpdateAndRender(GameMemory *memory, GameInput *input, GameOffscreenBuffer *videoBuf, GameSoundOutputBuffer *soundBuf);
|
||||
|
||||
// === Platform to game services ===
|
||||
#if HANDMADE_INTERNAL
|
||||
|
||||
struct DebugReadFileResult {
|
||||
uint32 contentsSize;
|
||||
void *contents;
|
||||
};
|
||||
|
||||
DebugReadFileResult DEBUG_platformReadEntireFile(char *filename);
|
||||
void DEBUG_platformFreeFileMemory(void *memory);
|
||||
bool32 DEBUG_platformWriteEntireFile(char *filename, uint32 memorySize, void *memory);
|
||||
void debug_printf(wchar_t* format, ...);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// Platform to game services
|
||||
|
||||
Reference in New Issue
Block a user