Clean up.

This commit is contained in:
2026-03-31 22:05:40 -07:00
parent 165ba90102
commit 34727294b7
3 changed files with 40 additions and 86 deletions
+33 -80
View File
@@ -8,6 +8,7 @@ static void GameOutputSound(game_state *GameState,
game_sound_output_buffer *SoundBuffer, game_sound_output_buffer *SoundBuffer,
S32 ToneHz) S32 ToneHz)
{ {
/*
S16 ToneVolume, *SampleOut; S16 ToneVolume, *SampleOut;
S32 WavePeriod, SampleIndex; S32 WavePeriod, SampleIndex;
@@ -33,34 +34,7 @@ static void GameOutputSound(game_state *GameState,
GameState->tSine -= 2.0f*(F32)PI; GameState->tSine -= 2.0f*(F32)PI;
} }
} }
} */
static void RenderWeirdGradient(game_offscreen_buffer *Buffer, S32 XOffset,
S32 YOffset)
{
S32 Width, Height, Y;
U8 *Row;
Width = Buffer->Width;
Height = Buffer->Height;
Row = (U8 *)Buffer->Memory;
for(Y = 0; Y < Height; Y++) {
U32 *Pixel = (U32 *)Row;
S32 X;
Pixel = (U32 *)Row;
for(X = 0; X < Width; X++) {
U8 Blue, Green;
Blue = (U8)(X + XOffset);
Green = (U8)(Y + YOffset);
*Pixel = (Green << 8) | Blue;
Pixel++;
}
Row += Buffer->Pitch;
}
} }
static void RenderRectangle(game_offscreen_buffer *Buffer, S32 MouseX, static void RenderRectangle(game_offscreen_buffer *Buffer, S32 MouseX,
@@ -99,30 +73,8 @@ void UpdateAndRender(thread_context *Thread, game_memory *Memory,
GameState = (game_state *)Memory->PermanentStorage; GameState = (game_state *)Memory->PermanentStorage;
if(!Memory->IsInitialized) { if(!Memory->IsInitialized) {
#if BUILD_INTERNAL
char *FileName;
debug_read_file_result BitmapMemory;
FileName = "/home/igor/Developer/handmade/sdl_handmade.cpp";
BitmapMemory = Memory->DEBUGPlatformReadEntireFile(Thread, FileName);
if(BitmapMemory.Contents) {
Memory->DEBUGPlatformWriteEntireFile(Thread, "test.out",
BitmapMemory.ContentsSize,
BitmapMemory.Contents);
Memory->DEBUGPlatformFreeFileMemory(Thread,
BitmapMemory.Contents);
}
#endif
GameState->ToneHz = 256;
GameState->tSine = 0.0f;
/* TODO: Maybe more appropriate to do in the platform layer? */
Memory->IsInitialized = TRUE; Memory->IsInitialized = TRUE;
} }
/* GameState.ToneHz; */
/* GameState.GreenOffset; */
/* GameState.BlueOffset; */
for(ControllerIndex = 0; for(ControllerIndex = 0;
ControllerIndex < ARRAY_SIZE(Input->Controllers); ControllerIndex < ARRAY_SIZE(Input->Controllers);
@@ -131,38 +83,39 @@ void UpdateAndRender(thread_context *Thread, game_memory *Memory,
game_controller_input *Controller = game_controller_input *Controller =
GetController(Input, ControllerIndex); GetController(Input, ControllerIndex);
if(Controller->IsAnalog) { if(Controller->IsAnalog) {
GameState->GreenOffset +=
(int)(4.0f*(Controller->StickAverageY));
GameState->BlueOffset +=
(int)(4.0f*(Controller->StickAverageX));
GameState->ToneHz =
256 + (S32)(128.0f*(Controller->StickAverageY));
} else { } else {
if(Controller->u.buttons.MoveUp.EndedDown) {
GameState->GreenOffset -= 5;
}
if(Controller->u.buttons.MoveDown.EndedDown) {
GameState->GreenOffset += 5;
}
if(Controller->u.buttons.MoveLeft.EndedDown) {
GameState->BlueOffset -= 5;
}
if(Controller->u.buttons.MoveRight.EndedDown) {
GameState->BlueOffset += 5;
}
} }
} }
GameOutputSound(GameState, SoundBuffer, GameState->ToneHz); GameOutputSound(GameState, SoundBuffer, 400);
RenderWeirdGradient(Buffer, GameState->BlueOffset,
GameState->GreenOffset);
{
S32 i;
for(i = 0; i < (S32)ARRAY_SIZE(Input->MouseButtons); i++) {
if(Input->MouseButtons[i].EndedDown)
RenderRectangle(Buffer, 10 + 20 * i, 10);
}
}
RenderRectangle(Buffer, Input->MouseX, Input->MouseY);
} }
/*
static void RenderWeirdGradient(game_offscreen_buffer *Buffer, S32 XOffset,
S32 YOffset)
{
S32 Width, Height, Y;
U8 *Row;
Width = Buffer->Width;
Height = Buffer->Height;
Row = (U8 *)Buffer->Memory;
for(Y = 0; Y < Height; Y++) {
U32 *Pixel = (U32 *)Row;
S32 X;
Pixel = (U32 *)Row;
for(X = 0; X < Width; X++) {
U8 Blue, Green;
Blue = (U8)(X + XOffset);
Green = (U8)(Y + YOffset);
*Pixel = (Green << 8) | Blue;
Pixel++;
}
Row += Buffer->Pitch;
}
}
*/
+3 -6
View File
@@ -86,7 +86,8 @@ typedef struct game_input {
game_button_state MouseButtons[5]; game_button_state MouseButtons[5];
S32 MouseX, MouseY, MouseZ; /* NOTE: MouseZ is the wheel. */ S32 MouseX, MouseY, MouseZ; /* NOTE: MouseZ is the wheel. */
/* TODO: Insert clock value here . . . */ F32 SecondsToAdvanceOverUpdate;
game_controller_input Controllers[5]; game_controller_input Controllers[5];
} game_input; } game_input;
@@ -135,11 +136,7 @@ void UpdateAndRender(thread_context *Thread, game_memory *Memory,
*/ */
typedef struct game_state { typedef struct game_state {
S32 ToneHz; void *filler;
S32 GreenOffset;
S32 BlueOffset;
F32 tSine;
} game_state; } game_state;
#endif #endif
+4
View File
@@ -712,6 +712,8 @@ S32 main(S32 argc, char *argv[])
SDL_Renderer *Renderer; SDL_Renderer *Renderer;
Renderer = SDL_CreateRenderer(Window, -1, SDL_RENDERER_PRESENTVSYNC); Renderer = SDL_CreateRenderer(Window, -1, SDL_RENDERER_PRESENTVSYNC);
SDL_SetWindowPosition(Window, 900, 300); /* TODO: Check that this
works on Linux. */
/* "Wayland needs an event loop and rendering or it won't function." /* "Wayland needs an event loop and rendering or it won't function."
* https://github.com/libsdl-org/SDL/issues/7699#issuecomment-1545684792 */ * https://github.com/libsdl-org/SDL/issues/7699#issuecomment-1545684792 */
/* NOTE: This means that we need to readraw to even resize the /* NOTE: This means that we need to readraw to even resize the
@@ -821,6 +823,8 @@ S32 main(S32 argc, char *argv[])
OldInput = &Input[1]; OldInput = &Input[1];
memset(&Input, 0, sizeof(Input)); memset(&Input, 0, sizeof(Input));
NewInput->SecondsToAdvanceOverUpdate = TargetSecondsPerFrame;
GlobalPerfCountFrequency = SDL_GetPerformanceFrequency(); GlobalPerfCountFrequency = SDL_GetPerformanceFrequency();
Game = SDLLoadGameCode(SDLState.DLLPath); Game = SDLLoadGameCode(SDLState.DLLPath);