From 9bc7fa3b52e25dae8fcd96f3554c49f0c00d9e10 Mon Sep 17 00:00:00 2001 From: igor Date: Fri, 17 Apr 2026 03:19:13 -0700 Subject: [PATCH] Removed the 80 character column rule. Becoming impractical. --- handmade.c | 157 +++++++-------------- handmade.h | 10 +- handmade_tile.c | 93 +++--------- sdl_handmade.c | 367 ++++++++++++------------------------------------ 4 files changed, 163 insertions(+), 464 deletions(-) diff --git a/handmade.c b/handmade.c index 407252f..b0d7143 100644 --- a/handmade.c +++ b/handmade.c @@ -9,9 +9,7 @@ #include /* memset */ -static void GameOutputSound(game_state *GameState, - game_sound_output_buffer *SoundBuffer, - S32 ToneHz) +static void GameOutputSound(game_state *GameState, game_sound_output_buffer *SoundBuffer, S32 ToneHz) { /* S16 ToneVolume, *SampleOut; @@ -53,10 +51,7 @@ static void ClearBackground(game_offscreen_buffer *Buffer) } } -static void DrawRectangle(game_offscreen_buffer *Buffer, - F32 RealMinX, F32 RealMinY, - F32 RealMaxX, F32 RealMaxY, - F32 R, F32 G, F32 B) +static void DrawRectangle(game_offscreen_buffer *Buffer, F32 RealMinX, F32 RealMinY, F32 RealMaxX, F32 RealMaxY, F32 R, F32 G, F32 B) { S32 MinX = RoundF32toS32(RealMinX); S32 MinY = RoundF32toS32(RealMinY); @@ -76,12 +71,9 @@ static void DrawRectangle(game_offscreen_buffer *Buffer, if(MaxY > Height) MaxY = Height; - U32 Color = (U32)((RoundF32toS32(R * 255.0f) << 16) | - (RoundF32toS32(G * 255.0f) << 8) | - (RoundF32toS32(B * 255.0f) << 0)); + U32 Color = (U32)((RoundF32toS32(R * 255.0f) << 16) | (RoundF32toS32(G * 255.0f) << 8) | (RoundF32toS32(B * 255.0f) << 0)); - U8 *Row = ((U8 *)Buffer->Memory + MinX*Buffer->BytesPerPixel + - MinY*Buffer->Pitch); + U8 *Row = ((U8 *)Buffer->Memory + MinX*Buffer->BytesPerPixel + MinY*Buffer->Pitch); for(S32 Y = MinY; Y < MaxY; Y++) { U32 *Pixel = (U32 *)Row; for(S32 X = MinX; X < MaxX; X++) { @@ -92,14 +84,10 @@ static void DrawRectangle(game_offscreen_buffer *Buffer, } } -void UpdateAndRender(thread_context *Thread, game_memory *Memory, - game_input *Input, game_offscreen_buffer *Buffer, - game_sound_output_buffer *SoundBuffer) +void UpdateAndRender(thread_context *Thread, game_memory *Memory, game_input *Input, game_offscreen_buffer *Buffer, game_sound_output_buffer *SoundBuffer) { - ASSERT((&Input->Controllers[0].u.buttons.Terminator - - &Input->Controllers[0].u.Buttons[0]) == - ARRAY_SIZE(Input->Controllers[0].u.Buttons)); + ASSERT((&Input->Controllers[0].Terminator - &Input->Controllers[0].Buttons[0]) == ARRAY_SIZE(Input->Controllers[0].Buttons)); ASSERT(sizeof(game_state) <= Memory->PermanentStorageSize); #define TILEMAP_COUNT_X 256 @@ -117,9 +105,7 @@ void UpdateAndRender(thread_context *Thread, game_memory *Memory, GameState->PlayerP.OffsetX = 5.0f; GameState->PlayerP.OffsetY = 5.0f; - InitializeArena(&GameState->WorldArena, - Memory->PermanentStorageSize - sizeof(game_state), - (U8 *)Memory->PermanentStorage + sizeof(game_state)); + InitializeArena(&GameState->WorldArena, Memory->PermanentStorageSize - sizeof(game_state), (U8 *)Memory->PermanentStorage + sizeof(game_state)); GameState->World = PUSH_STRUCT(&GameState->WorldArena, world); world *World = GameState->World; @@ -135,12 +121,7 @@ void UpdateAndRender(thread_context *Thread, game_memory *Memory, TileMap->TileChunkCountY = 128; TileMap->TileChunkCountZ = 2; - TileMap->TileChunks = - PUSH_ARRAY(&GameState->WorldArena, - TileMap->TileChunkCountX * - TileMap->TileChunkCountY * - TileMap->TileChunkCountZ, - tile_chunk); + TileMap->TileChunks = PUSH_ARRAY(&GameState->WorldArena, TileMap->TileChunkCountX * TileMap->TileChunkCountY * TileMap->TileChunkCountZ, tile_chunk); TileMap->TileSideInMeters = 1.4f; @@ -192,27 +173,19 @@ void UpdateAndRender(thread_context *Thread, game_memory *Memory, U32 AbsTileY = ScreenY * TilesPerHeight + TileY; U32 TileValue = 1; - if((TileX == 0) && - (!DoorLeft || (TileY != (TilesPerHeight/2)))) - { + if((TileX == 0) && (!DoorLeft || (TileY != (TilesPerHeight/2)))) { TileValue = 2; } - if(((TileX == (TilesPerWidth - 1)) && - (!DoorRight || (TileY != (TilesPerHeight/2))))) - { + if(((TileX == (TilesPerWidth - 1)) && (!DoorRight || (TileY != (TilesPerHeight/2))))) { TileValue = 2; } - if((TileY == 0) && - (!DoorBottom || (TileX != (TilesPerWidth/2)))) - { + if((TileY == 0) && (!DoorBottom || (TileX != (TilesPerWidth/2)))) { TileValue = 2; } - if((TileY == (TilesPerHeight - 1)) && - (!DoorTop || (TileX != (TilesPerWidth/2)))) - { + if((TileY == (TilesPerHeight - 1)) && (!DoorTop || (TileX != (TilesPerWidth/2)))) { TileValue = 2; } @@ -225,10 +198,7 @@ void UpdateAndRender(thread_context *Thread, game_memory *Memory, } } - SetTileValue(&GameState->WorldArena, - World->TileMap, - AbsTileX, AbsTileY, AbsTileZ, - TileValue); + SetTileValue(&GameState->WorldArena, World->TileMap, AbsTileX, AbsTileY, AbsTileZ, TileValue); } } @@ -268,33 +238,29 @@ void UpdateAndRender(thread_context *Thread, game_memory *Memory, S32 TileSideInPixels = 60; F32 MetersToPixels = (F32)TileSideInPixels / TileMap->TileSideInMeters; - for(U32 ControllerIndex = 0; - ControllerIndex < ARRAY_SIZE(Input->Controllers); - ControllerIndex++) - { - game_controller_input *Controller = - GetController(Input, ControllerIndex); + for(U32 ControllerIndex = 0; ControllerIndex < ARRAY_SIZE(Input->Controllers); ControllerIndex++) { + game_controller_input *Controller = GetController(Input, ControllerIndex); if(Controller->IsAnalog) { } else { F32 dPlayerX = 0.0f; F32 dPlayerY = 0.0f; - if(Controller->u.buttons.MoveUp.EndedDown) { + if(Controller->MoveUp.EndedDown) { dPlayerY = 1.0f; } - if(Controller->u.buttons.MoveDown.EndedDown) { + if(Controller->MoveDown.EndedDown) { dPlayerY = -1.0f; } - if(Controller->u.buttons.MoveLeft.EndedDown) { + if(Controller->MoveLeft.EndedDown) { dPlayerX = -1.0f; } - if(Controller->u.buttons.MoveRight.EndedDown) { + if(Controller->MoveRight.EndedDown) { dPlayerX = 1.0f; } F32 PlayerSpeed = 2.0f; - if(Controller->u.buttons.ActionUp.EndedDown) + if(Controller->ActionUp.EndedDown) PlayerSpeed = 10.0f; dPlayerX *= PlayerSpeed; @@ -316,13 +282,9 @@ void UpdateAndRender(thread_context *Thread, game_memory *Memory, PlayerRight.OffsetX += 0.5f*PlayerWidth; PlayerRight = RecannonicalizePosition(TileMap, PlayerRight); - if(IsTileMapPointEmpty(TileMap, NewPlayerP) && - IsTileMapPointEmpty(TileMap, PlayerLeft) && - IsTileMapPointEmpty(TileMap, PlayerRight)) - { + if(IsTileMapPointEmpty(TileMap, NewPlayerP) && IsTileMapPointEmpty(TileMap, PlayerLeft) && IsTileMapPointEmpty(TileMap, PlayerRight)) { if(!AreOnSameTile(&GameState->PlayerP, &NewPlayerP)) { - U32 NewTileValue = - GetTileValueByPos(TileMap, NewPlayerP); + U32 NewTileValue = GetTileValueByPos(TileMap, NewPlayerP); if(NewTileValue == 3) { NewPlayerP.AbsTileZ++; @@ -338,51 +300,36 @@ void UpdateAndRender(thread_context *Thread, game_memory *Memory, F32 ScreenCenterX = 0.5f * (F32)Buffer->Width; F32 ScreenCenterY = 0.5f * (F32)Buffer->Height; - DrawRectangle(Buffer, 0.0f, 0.0f, - (F32)Buffer->Width, (F32)Buffer->Height, - 0.0f, 1.0f, 0.0f); - { - for(S32 RelRow = -10; RelRow < 10; RelRow++) { - for(S32 RelColumn = -20; RelColumn < 20; RelColumn++) { - U32 Column = GameState->PlayerP.AbsTileX + RelColumn; - U32 Row = GameState->PlayerP.AbsTileY + RelRow; + DrawRectangle(Buffer, 0.0f, 0.0f, (F32)Buffer->Width, (F32)Buffer->Height, 0.0f, 1.0f, 0.0f); + for(S32 RelRow = -10; RelRow < 10; RelRow++) { + for(S32 RelColumn = -20; RelColumn < 20; RelColumn++) { + U32 Column = GameState->PlayerP.AbsTileX + RelColumn; + U32 Row = GameState->PlayerP.AbsTileY + RelRow; - U32 TileID = GetTileValue(TileMap, - Column, - Row, - GameState->PlayerP.AbsTileZ); + U32 TileID = GetTileValue(TileMap, Column, Row, GameState->PlayerP.AbsTileZ); - if(TileID > 0) { - F32 Gray = 0.5f; - if(TileID == 2) { - Gray = 1.0f; - } - - if(TileID > 2) { - Gray = 0.25f; - } - - if((Column == GameState->PlayerP.AbsTileX) && - (Row == GameState->PlayerP.AbsTileY)) - { - Gray = 0.0f; - } - - - F32 CenterX = ScreenCenterX - - MetersToPixels*GameState->PlayerP.OffsetX + - (F32)RelColumn*(F32)TileSideInPixels; - F32 CenterY = ScreenCenterY + - MetersToPixels*GameState->PlayerP.OffsetY - - (F32)RelRow*(F32)TileSideInPixels; - F32 MinX = CenterX - 0.5f*(F32)TileSideInPixels; - F32 MinY = CenterY - 0.5f*(F32)TileSideInPixels; - F32 MaxX = CenterX + 0.5f*(F32)TileSideInPixels; - F32 MaxY = CenterY + 0.5f*(F32)TileSideInPixels; - DrawRectangle(Buffer, - MinX, MinY, MaxX, MaxY, - Gray, Gray, Gray); + if(TileID > 0) { + F32 Gray = 0.5f; + if(TileID == 2) { + Gray = 1.0f; } + + if(TileID > 2) { + Gray = 0.25f; + } + + if((Column == GameState->PlayerP.AbsTileX) && (Row == GameState->PlayerP.AbsTileY)) { + Gray = 0.0f; + } + + + F32 CenterX = ScreenCenterX - MetersToPixels*GameState->PlayerP.OffsetX + (F32)RelColumn*(F32)TileSideInPixels; + F32 CenterY = ScreenCenterY + MetersToPixels*GameState->PlayerP.OffsetY - (F32)RelRow*(F32)TileSideInPixels; + F32 MinX = CenterX - 0.5f*(F32)TileSideInPixels; + F32 MinY = CenterY - 0.5f*(F32)TileSideInPixels; + F32 MaxX = CenterX + 0.5f*(F32)TileSideInPixels; + F32 MaxY = CenterY + 0.5f*(F32)TileSideInPixels; + DrawRectangle(Buffer, MinX, MinY, MaxX, MaxY, Gray, Gray, Gray); } } } @@ -392,11 +339,7 @@ void UpdateAndRender(thread_context *Thread, game_memory *Memory, F32 PlayerB = 0.0f; F32 PlayerLeft = ScreenCenterX - 0.5f * MetersToPixels*PlayerWidth; F32 PlayerTop = ScreenCenterY - MetersToPixels*PlayerHeight; - DrawRectangle(Buffer, - PlayerLeft, PlayerTop, - PlayerLeft + MetersToPixels*PlayerWidth, - PlayerTop + MetersToPixels*PlayerHeight, - PlayerR, PlayerG, PlayerB); + DrawRectangle(Buffer, PlayerLeft, PlayerTop, PlayerLeft + MetersToPixels*PlayerWidth, PlayerTop + MetersToPixels*PlayerHeight, PlayerR, PlayerG, PlayerB); GameOutputSound(GameState, SoundBuffer, 400); } diff --git a/handmade.h b/handmade.h index 57312db..39ea544 100644 --- a/handmade.h +++ b/handmade.h @@ -80,8 +80,8 @@ typedef struct game_controller_input { /* NOTE: All buttons must be added above this line. */ game_button_state Terminator; - } buttons; - } u; + }; + }; } game_controller_input; typedef struct game_input { @@ -116,10 +116,8 @@ typedef struct game_memory { layer.) */ #if BUILD_INTERNAL - debug_read_file_result (*DEBUGPlatformReadEntireFile)( - thread_context *Thread,const char *); - B32 (*DEBUGPlatformWriteEntireFile)(thread_context *Thread, - const char *, U32, void *); + debug_read_file_result (*DEBUGPlatformReadEntireFile)(thread_context *Thread,const char *); + B32 (*DEBUGPlatformWriteEntireFile)(thread_context *Thread, const char *, U32, void *); void (*DEBUGPlatformFreeFileMemory)(thread_context *Thread, void *); #endif } game_memory; diff --git a/handmade_tile.c b/handmade_tile.c index 525c71b..54c6e8b 100644 --- a/handmade_tile.c +++ b/handmade_tile.c @@ -1,9 +1,6 @@ #include "handmade_tile.h" -static tile_chunk *GetTileChunk(tile_map *TileMap, - U32 TileChunkX, - U32 TileChunkY, - U32 TileChunkZ) +static tile_chunk *GetTileChunk(tile_map *TileMap, U32 TileChunkX, U32 TileChunkY, U32 TileChunkZ) { tile_chunk *TileChunk = NULL; @@ -11,20 +8,13 @@ static tile_chunk *GetTileChunk(tile_map *TileMap, (TileChunkY >= 0) && (TileChunkY < TileMap->TileChunkCountY) && (TileChunkZ >= 0) && (TileChunkZ < TileMap->TileChunkCountZ)) { - TileChunk = - &TileMap->TileChunks[ - (TileChunkZ*TileMap->TileChunkCountY*TileMap->TileChunkCountX) + - (TileChunkY*TileMap->TileChunkCountX) + - TileChunkX]; + TileChunk = &TileMap->TileChunks[ (TileChunkZ*TileMap->TileChunkCountY*TileMap->TileChunkCountX) + (TileChunkY*TileMap->TileChunkCountX) + TileChunkX]; } return TileChunk; } -static tile_chunk_position GetChunkPositionFor(tile_map *TileMap, - U32 AbsTileX, - U32 AbsTileY, - U32 AbsTileZ) +static tile_chunk_position GetChunkPositionFor(tile_map *TileMap, U32 AbsTileX, U32 AbsTileY, U32 AbsTileZ) { tile_chunk_position Result; @@ -37,8 +27,7 @@ static tile_chunk_position GetChunkPositionFor(tile_map *TileMap, return Result; } -static U32 GetTileValueUnchecked(tile_map *TileMap, tile_chunk *TileChunk, - U32 TileX, U32 TileY) +static U32 GetTileValueUnchecked(tile_map *TileMap, tile_chunk *TileChunk, U32 TileX, U32 TileY) { ASSERT(TileChunk); ASSERT(TileX < TileMap->ChunkDim); @@ -48,49 +37,32 @@ static U32 GetTileValueUnchecked(tile_map *TileMap, tile_chunk *TileChunk, return TileChunkValue; } -static U32 GetTileChunkValue(tile_map *TileMap, tile_chunk *TileChunk, - U32 TestTileX, U32 TestTileY) +static U32 GetTileChunkValue(tile_map *TileMap, tile_chunk *TileChunk, U32 TestTileX, U32 TestTileY) { U32 TileChunkValue = 0; if(TileChunk && TileChunk->Tiles) { - TileChunkValue = GetTileValueUnchecked(TileMap, - TileChunk, - TestTileX, - TestTileY); + TileChunkValue = GetTileValueUnchecked(TileMap, TileChunk, TestTileX, TestTileY); } return TileChunkValue; } -static U32 GetTileValue(tile_map *TileMap, - U32 AbsTileX, U32 AbsTileY, U32 AbsTileZ) +static U32 GetTileValue(tile_map *TileMap, U32 AbsTileX, U32 AbsTileY, U32 AbsTileZ) { - tile_chunk_position ChunkPos = GetChunkPositionFor(TileMap, - AbsTileX, - AbsTileY, - AbsTileZ); - tile_chunk *TileChunk = GetTileChunk(TileMap, - ChunkPos.TileChunkX, - ChunkPos.TileChunkY, - ChunkPos.TileChunkZ); - U32 TileChunkValue = GetTileChunkValue(TileMap, TileChunk, - ChunkPos.RelTileX, - ChunkPos.RelTileY); + tile_chunk_position ChunkPos = GetChunkPositionFor(TileMap, AbsTileX, AbsTileY, AbsTileZ); + tile_chunk *TileChunk = GetTileChunk(TileMap, ChunkPos.TileChunkX, ChunkPos.TileChunkY, ChunkPos.TileChunkZ); + U32 TileChunkValue = GetTileChunkValue(TileMap, TileChunk, ChunkPos.RelTileX, ChunkPos.RelTileY); return TileChunkValue; } static U32 GetTileValueByPos(tile_map *TileMap, tile_map_position Pos) { - U32 TileChunkValue = GetTileValue(TileMap, - Pos.AbsTileX, - Pos.AbsTileY, - Pos.AbsTileZ); + U32 TileChunkValue = GetTileValue(TileMap, Pos.AbsTileX, Pos.AbsTileY, Pos.AbsTileZ); return TileChunkValue; } -static void SetTileValueUnchecked(tile_map *TileMap, tile_chunk *TileChunk, - U32 TileX, U32 TileY, U32 TileValue) +static void SetTileValueUnchecked(tile_map *TileMap, tile_chunk *TileChunk, U32 TileX, U32 TileY, U32 TileValue) { ASSERT(TileChunk); ASSERT(TileX < TileMap->ChunkDim); @@ -99,41 +71,25 @@ static void SetTileValueUnchecked(tile_map *TileMap, tile_chunk *TileChunk, TileChunk->Tiles[TileY * TileMap->ChunkDim + TileX] = TileValue; } -static void SetTileChunkValue(tile_map *TileMap, tile_chunk *TileChunk, - U32 TestTileX, U32 TestTileY, - U32 TileValue) +static void SetTileChunkValue(tile_map *TileMap, tile_chunk *TileChunk, U32 TestTileX, U32 TestTileY, U32 TileValue) { if(TileChunk && TileChunk->Tiles) { - SetTileValueUnchecked(TileMap, - TileChunk, - TestTileX, TestTileY, - TileValue); + SetTileValueUnchecked(TileMap, TileChunk, TestTileX, TestTileY, TileValue); } } static B32 IsTileMapPointEmpty(tile_map *TileMap, tile_map_position Pos) { U32 TileChunkValue = GetTileValueByPos(TileMap, Pos); - B32 Empty = ((TileChunkValue == 1) || - (TileChunkValue == 3) || - (TileChunkValue == 4)); + B32 Empty = ((TileChunkValue == 1) || (TileChunkValue == 3) || (TileChunkValue == 4)); return Empty; } -static void SetTileValue(memory_arena *Arena, - tile_map *TileMap, - U32 AbsTileX, U32 AbsTileY, U32 AbsTileZ, - U32 TileValue) +static void SetTileValue(memory_arena *Arena, tile_map *TileMap, U32 AbsTileX, U32 AbsTileY, U32 AbsTileZ, U32 TileValue) { - tile_chunk_position ChunkPos = GetChunkPositionFor(TileMap, - AbsTileX, - AbsTileY, - AbsTileZ); - tile_chunk *TileChunk = GetTileChunk(TileMap, - ChunkPos.TileChunkX, - ChunkPos.TileChunkY, - ChunkPos.TileChunkZ); + tile_chunk_position ChunkPos = GetChunkPositionFor(TileMap, AbsTileX, AbsTileY, AbsTileZ); + tile_chunk *TileChunk = GetTileChunk(TileMap, ChunkPos.TileChunkX, ChunkPos.TileChunkY, ChunkPos.TileChunkZ); ASSERT(TileChunk); if(!TileChunk->Tiles) { @@ -143,13 +99,9 @@ static void SetTileValue(memory_arena *Arena, for(U32 TileIndex = 0; TileIndex < TileCount; TileIndex++) { TileChunk->Tiles[TileIndex] = 1; } - } - SetTileChunkValue(TileMap, TileChunk, - ChunkPos.RelTileX, - ChunkPos.RelTileY, - TileValue); + SetTileChunkValue(TileMap, TileChunk, ChunkPos.RelTileX, ChunkPos.RelTileY, TileValue); } // @@ -168,8 +120,7 @@ static void CannonicalizeCoord(tile_map *TileMap, U32 *Tile, F32 *TileRel) ASSERT(*TileRel <= 0.5f*TileMap->TileSideInMeters); } -static tile_map_position RecannonicalizePosition(tile_map *TileMap, - tile_map_position Pos) +static tile_map_position RecannonicalizePosition(tile_map *TileMap, tile_map_position Pos) { tile_map_position Result = Pos; @@ -181,8 +132,6 @@ static tile_map_position RecannonicalizePosition(tile_map *TileMap, static B32 AreOnSameTile(tile_map_position *A, tile_map_position *B) { - B32 Result = ((A->AbsTileX == B->AbsTileX) && - (A->AbsTileY == B->AbsTileY) && - (A->AbsTileZ == B->AbsTileZ)); + B32 Result = ((A->AbsTileX == B->AbsTileX) && (A->AbsTileY == B->AbsTileY) && (A->AbsTileZ == B->AbsTileZ)); return Result; } diff --git a/sdl_handmade.c b/sdl_handmade.c index 839ca3f..acd1f9d 100644 --- a/sdl_handmade.c +++ b/sdl_handmade.c @@ -55,8 +55,7 @@ static U32 SafeTruncateUInt64(U64 Value) return Result; } -debug_read_file_result DEBUGPlatformReadEntireFile(thread_context *Thread, - const char *Filename) +debug_read_file_result DEBUGPlatformReadEntireFile(thread_context *Thread, const char *Filename) { debug_read_file_result Result; memset(&Result, 0, sizeof(Result)); @@ -100,12 +99,9 @@ debug_read_file_result DEBUGPlatformReadEntireFile(thread_context *Thread, return Result; } -B32 DEBUGPlatformWriteEntireFile(thread_context *Thread, - const char *Filename, U32 MemorySize, - void *Memory) +B32 DEBUGPlatformWriteEntireFile(thread_context *Thread, const char *Filename, U32 MemorySize, void *Memory) { - S32 FileHandle = open(Filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | - S_IRGRP | S_IROTH); + S32 FileHandle = open(Filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if(FileHandle == -1) return FALSE; @@ -141,8 +137,7 @@ static sdl_window_dimension SDLGetWindowDimension(SDL_Window *Window) return Dimension; } -static void SDLResizeTexture(offscreen_buffer *Buffer, - SDL_Renderer *Renderer, int Width, int Height) +static void SDLResizeTexture(offscreen_buffer *Buffer, SDL_Renderer *Renderer, int Width, int Height) { if(Buffer->Texture) SDL_DestroyTexture(Buffer->Texture); @@ -152,9 +147,7 @@ static void SDLResizeTexture(offscreen_buffer *Buffer, S32 BytesPerPixel = 4; - Buffer->Texture = SDL_CreateTexture(Renderer, SDL_PIXELFORMAT_ARGB8888, - SDL_TEXTUREACCESS_STREAMING, - Width, Height); + Buffer->Texture = SDL_CreateTexture(Renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, Width, Height); Buffer->Memory = malloc(Width * Height * BytesPerPixel); Buffer->Height = Height; @@ -162,9 +155,7 @@ static void SDLResizeTexture(offscreen_buffer *Buffer, Buffer->Pitch = Width * BytesPerPixel; } -static void SDLDisplayBufferInWindow(offscreen_buffer Buffer, - SDL_Window *Window, - SDL_Renderer *Renderer) +static void SDLDisplayBufferInWindow(offscreen_buffer Buffer, SDL_Window *Window, SDL_Renderer *Renderer) { S32 OffsetX = 10; S32 OffsetY = 10; @@ -179,8 +170,7 @@ static void SDLDisplayBufferInWindow(offscreen_buffer Buffer, /* TODO: We temporarily introduce the target rectangle to avoid * stretching the canvas. */ /* SDL_RenderCopy(Renderer, Buffer.Texture, 0, 0); */ - SDL_Rect dest_rect = { OffsetX, OffsetY, - RESOLUTION_WIDTH, RESOLUTION_HEIGHT }; + SDL_Rect dest_rect = { OffsetX, OffsetY, RESOLUTION_WIDTH, RESOLUTION_HEIGHT }; SDL_RenderCopy(Renderer, Buffer.Texture, 0, (const SDL_Rect *)(&dest_rect)); SDL_RenderPresent(Renderer); } @@ -194,8 +184,7 @@ static void SDLInitControllers() continue; if(ControllerIndex >= MAX_CONTROLLERS) break; - ControllerHandles[ControllerIndex] = - SDL_GameControllerOpen(JoystickIndex); + ControllerHandles[ControllerIndex] = SDL_GameControllerOpen(JoystickIndex); ControllerIndex++; } } @@ -203,10 +192,7 @@ static void SDLInitControllers() /* static void SDLDeinitControllers() { - for(S32 ControllerIndex = 0; - ControllerIndex < MAX_CONTROLLERS; - ControllerIndex++) - { + for(S32 ControllerIndex = 0; ControllerIndex < MAX_CONTROLLERS; ControllerIndex++) { if(ControllerHandles[ControllerIndex]) SDL_GameControllerClose(ControllerHandles[ControllerIndex]); } @@ -230,8 +216,7 @@ static void SDLInitSound(S32 SamplesPerSecond, S32 BufferSize) } } -static void SDLFillSoundBuffer(sdl_sound_output *SoundOutput, - S32 BytesToWrite) +static void SDLFillSoundBuffer(sdl_sound_output *SoundOutput, S32 BytesToWrite) { SDL_QueueAudio(1, SoundOutput->Samples, BytesToWrite); } @@ -241,8 +226,7 @@ static void SDLClearSoundBuffer(sdl_sound_output *SoundOutput) memset(SoundOutput->Samples, 0, SoundOutput->SecondaryBufferSize); } -static void SDLProcessKeyboardMessage(game_button_state *NewState, - B32 IsDown) +static void SDLProcessKeyboardMessage(game_button_state *NewState, B32 IsDown) { if(NewState->EndedDown != IsDown) { NewState->EndedDown = IsDown; @@ -250,14 +234,10 @@ static void SDLProcessKeyboardMessage(game_button_state *NewState, } } -static void SDLProcessInputDigitalButton(SDL_GameController *Controller, - game_button_state *OldState, - SDL_GameControllerButton Button, - game_button_state *NewState) +static void SDLProcessInputDigitalButton(SDL_GameController *Controller, game_button_state *OldState, SDL_GameControllerButton Button, game_button_state *NewState) { NewState->EndedDown = SDL_GameControllerGetButton(Controller, Button); - NewState->HalfTransitionCount = - (OldState->EndedDown != NewState->EndedDown) ? 1 : 0; + NewState->HalfTransitionCount = (OldState->EndedDown != NewState->EndedDown) ? 1 : 0; } static void HandleEvent(SDL_Event *Event) @@ -274,14 +254,12 @@ static void HandleEvent(SDL_Event *Event) switch(Event->window.event) { /* TODO: We temporarily disable for ease of writing the * rendering code. */ -#if 0 - case SDL_WINDOWEVENT_SIZE_CHANGED: { - sdl_window_dimension Dimension; - Dimension = SDLGetWindowDimension(Window); - /* TODO: For now we fix the width and height. */ - SDLResizeTexture(&GlobalBackbuffer, Renderer, - Dimension.Width, Dimension.Height); +#if 0 + /* TODO: For now we fix the width and height. */ + case SDL_WINDOWEVENT_SIZE_CHANGED: { + sdl_window_dimension Dimension = SDLGetWindowDimension(Window); + SDLResizeTexture(&GlobalBackbuffer, Renderer, Dimension.Width, Dimension.Height); } break; #endif @@ -328,53 +306,29 @@ static void SDLProcessMessages(sdl_state *SDLState, if(Event.key.repeat == 0) { if(KeyCode == SDLK_w) { - SDLProcessKeyboardMessage( - &KeyboardController->u.buttons.MoveUp, - IsDown); + SDLProcessKeyboardMessage(&KeyboardController->MoveUp, IsDown); } else if(KeyCode == SDLK_s) { - SDLProcessKeyboardMessage( - &KeyboardController->u.buttons.MoveDown, - IsDown); + SDLProcessKeyboardMessage(&KeyboardController->MoveDown, IsDown); } else if(KeyCode == SDLK_a) { - SDLProcessKeyboardMessage( - &KeyboardController->u.buttons.MoveLeft, - IsDown); + SDLProcessKeyboardMessage(&KeyboardController->MoveLeft, IsDown); } else if(KeyCode == SDLK_d) { - SDLProcessKeyboardMessage( - &KeyboardController->u.buttons.MoveRight, - IsDown); + SDLProcessKeyboardMessage(&KeyboardController->MoveRight, IsDown); } else if(KeyCode == SDLK_q) { - SDLProcessKeyboardMessage( - &KeyboardController->u.buttons.LeftShoulder, - IsDown); + SDLProcessKeyboardMessage(&KeyboardController->LeftShoulder, IsDown); } else if(KeyCode == SDLK_e) { - SDLProcessKeyboardMessage( - &KeyboardController->u.buttons.RightShoulder, - IsDown); + SDLProcessKeyboardMessage(&KeyboardController->RightShoulder, IsDown); } else if(KeyCode == SDLK_UP) { - SDLProcessKeyboardMessage( - &KeyboardController->u.buttons.ActionUp, - IsDown); + SDLProcessKeyboardMessage(&KeyboardController->ActionUp, IsDown); } else if(KeyCode == SDLK_DOWN) { - SDLProcessKeyboardMessage( - &KeyboardController->u.buttons.ActionDown, - IsDown); + SDLProcessKeyboardMessage(&KeyboardController->ActionDown, IsDown); } else if(KeyCode == SDLK_LEFT) { - SDLProcessKeyboardMessage( - &KeyboardController->u.buttons.ActionLeft, - IsDown); + SDLProcessKeyboardMessage(&KeyboardController->ActionLeft, IsDown); } else if(KeyCode == SDLK_RIGHT) { - SDLProcessKeyboardMessage( - &KeyboardController->u.buttons.ActionRight, - IsDown); + SDLProcessKeyboardMessage(&KeyboardController->ActionRight, IsDown); } else if(KeyCode == SDLK_ESCAPE) { - SDLProcessKeyboardMessage( - &KeyboardController->u.buttons.Start, - IsDown); + SDLProcessKeyboardMessage(&KeyboardController->Start, IsDown); } else if(KeyCode == SDLK_SPACE) { - SDLProcessKeyboardMessage( - &KeyboardController->u.buttons.Back, - IsDown); + SDLProcessKeyboardMessage(&KeyboardController->Back, IsDown); } } @@ -404,11 +358,9 @@ static F32 SDLProcessInputStickValue(F32 Value, S32 DeadZoneThreshold) { F32 Result = 0.0f; if(Value < -(F32)DeadZoneThreshold) - Result = ((Value + (F32)DeadZoneThreshold) / - (32768.0f - (F32)DeadZoneThreshold)); + Result = ((Value + (F32)DeadZoneThreshold) / (32768.0f - (F32)DeadZoneThreshold)); else if(Value > (F32)DeadZoneThreshold) - Result = ((Value + (F32)DeadZoneThreshold) / - (32767.0f - (F32)DeadZoneThreshold)); + Result = ((Value + (F32)DeadZoneThreshold) / (32767.0f - (F32)DeadZoneThreshold)); return Result; } @@ -441,9 +393,7 @@ typedef struct sdl_game_code { void *GameCodeDLL; U32 DLLLastWriteTime; - void (*UpdateAndRender)(thread_context *Thread, game_memory *, - game_input *, game_offscreen_buffer *, - game_sound_output_buffer *); + void (*UpdateAndRender)(thread_context *Thread, game_memory *, game_input *, game_offscreen_buffer *, game_sound_output_buffer *); B32 IsValid; } sdl_game_code; @@ -470,10 +420,7 @@ static sdl_game_code SDLLoadGameCode(char *DLLPath) if(Result.GameCodeDLL) { Result.DLLLastWriteTime = GetLastWriteTime(DLLPath); - Result.UpdateAndRender = - (void(*)(thread_context *, game_memory *, game_input *, - game_offscreen_buffer *, game_sound_output_buffer *)) - dlsym(Result.GameCodeDLL, "UpdateAndRender"); + Result.UpdateAndRender = (void(*)(thread_context *, game_memory *, game_input *, game_offscreen_buffer *, game_sound_output_buffer *)) dlsym(Result.GameCodeDLL, "UpdateAndRender"); if(!Result.UpdateAndRender) { /* TODO: Diagnostic. dlerror() */ } @@ -590,12 +537,9 @@ S32 main(S32 argc, char *argv[]) memset(&SDLState, 0, sizeof(SDLState)); SDLGetEXEDirPath(SDLState.EXEDirPath, sizeof(SDLState.EXEDirPath)); - SDLGetDLLPath(SDLState.DLLPath, sizeof(SDLState.DLLPath), - SDLState.EXEDirPath); + SDLGetDLLPath(SDLState.DLLPath, sizeof(SDLState.DLLPath), SDLState.EXEDirPath); - if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | - SDL_INIT_AUDIO)) - { + if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_AUDIO)) { /* TODO: This didn't work . . . */ } @@ -604,11 +548,7 @@ S32 main(S32 argc, char *argv[]) /* NOTE: Floating windows are not supported oficially by Wayland * protocol. However, SDL_WINDOW_ALWAYS_ON_TOP does work on KDE * under Wayland. I have not tested GNOME. */ - SDL_Window *Window = SDL_CreateWindow("Handmade Hero", - SDL_WINDOWPOS_UNDEFINED, - SDL_WINDOWPOS_UNDEFINED, - RESOLUTION_WIDTH, RESOLUTION_HEIGHT, - SDL_WINDOW_RESIZABLE); + SDL_Window *Window = SDL_CreateWindow("Handmade Hero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, RESOLUTION_WIDTH, RESOLUTION_HEIGHT, SDL_WINDOW_RESIZABLE); /*SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALWAYS_ON_TOP);*/ @@ -616,10 +556,8 @@ S32 main(S32 argc, char *argv[]) SDL_DisplayMode display_mode; SDL_GetCurrentDisplayMode(0, &display_mode); - SDL_Renderer *Renderer = - SDL_CreateRenderer(Window, -1, SDL_RENDERER_PRESENTVSYNC); - SDL_SetWindowPosition(Window, (display_mode.w - RESOLUTION_WIDTH), - (display_mode.h - RESOLUTION_HEIGHT)); + SDL_Renderer *Renderer = SDL_CreateRenderer(Window, -1, SDL_RENDERER_PRESENTVSYNC); + SDL_SetWindowPosition(Window, (display_mode.w - RESOLUTION_WIDTH), (display_mode.h - RESOLUTION_HEIGHT)); /* "Wayland needs an event loop and rendering or it won't function." * https://github.com/libsdl-org/SDL/issues/7699#issuecomment-1545684792 */ @@ -644,27 +582,20 @@ S32 main(S32 argc, char *argv[]) GlobalRunning = TRUE; sdl_window_dimension Dimension = SDLGetWindowDimension(Window); - SDLResizeTexture(&GlobalBackbuffer, Renderer, Dimension.Width, - Dimension.Height); + SDLResizeTexture(&GlobalBackbuffer, Renderer, Dimension.Width, Dimension.Height); sdl_sound_output SoundOutput; memset(&SoundOutput, 0, sizeof(SoundOutput)); SoundOutput.SamplesPerSecond = 48000; SoundOutput.BytesPerSample = sizeof(S16) * 2; - SoundOutput.SecondaryBufferSize = - SoundOutput.SamplesPerSecond * SoundOutput.BytesPerSample; + SoundOutput.SecondaryBufferSize = SoundOutput.SamplesPerSecond * SoundOutput.BytesPerSample; SoundOutput.tSine = 0; - SoundOutput.LatencySampleCount = - SoundOutput.SamplesPerSecond / 15; + SoundOutput.LatencySampleCount = SoundOutput.SamplesPerSecond / 15; - SDLInitSound(SoundOutput.SamplesPerSecond, - SoundOutput.SamplesPerSecond * SoundOutput.BytesPerSample / - 60); + SDLInitSound(SoundOutput.SamplesPerSecond, SoundOutput.SamplesPerSecond * SoundOutput.BytesPerSample / 60); SDL_PauseAudio(0); - SoundOutput.Samples = - calloc(SoundOutput.SamplesPerSecond, - SoundOutput.BytesPerSample); + SoundOutput.Samples = calloc(SoundOutput.SamplesPerSecond, SoundOutput.BytesPerSample); /* SoundOutput.Samples = * malloc(SoundOutput.SecondaryBufferSize); */ /* NOTE: calloc auto clears to zero */ @@ -674,30 +605,18 @@ S32 main(S32 argc, char *argv[]) memset(&GameMemory, 0, sizeof(GameMemory)); GameMemory.PermanentStorageSize = MB(64); GameMemory.TransientStorageSize = GB(1); - GameMemory.DEBUGPlatformReadEntireFile = - &DEBUGPlatformReadEntireFile; - GameMemory.DEBUGPlatformWriteEntireFile = - &DEBUGPlatformWriteEntireFile; - GameMemory.DEBUGPlatformFreeFileMemory = - &DEBUGPlatformFreeFileMemory; + GameMemory.DEBUGPlatformReadEntireFile = &DEBUGPlatformReadEntireFile; + GameMemory.DEBUGPlatformWriteEntireFile = &DEBUGPlatformWriteEntireFile; + GameMemory.DEBUGPlatformFreeFileMemory = &DEBUGPlatformFreeFileMemory; - SDLState.TotalSize = - GameMemory.PermanentStorageSize + - GameMemory.TransientStorageSize; + SDLState.TotalSize = GameMemory.PermanentStorageSize + GameMemory.TransientStorageSize; /* NOTE: On MacOS and Linux, mmap seems to zero-fill anonymous * memory as a side-effect of security. */ - SDLState.GameMmemoryBlock = - mmap(BaseAddress, (size_t)SDLState.TotalSize, PROT_READ | - PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); + SDLState.GameMmemoryBlock = mmap(BaseAddress, (size_t)SDLState.TotalSize, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); GameMemory.PermanentStorage = SDLState.GameMmemoryBlock; - GameMemory.TransientStorage = - (U8 *)(GameMemory.PermanentStorage) + - GameMemory.PermanentStorageSize; + GameMemory.TransientStorage = (U8 *)(GameMemory.PermanentStorage) + GameMemory.PermanentStorageSize; - if(SoundOutput.Samples && - GameMemory.PermanentStorage && - GameMemory.TransientStorage) - { + if(SoundOutput.Samples && GameMemory.PermanentStorage && GameMemory.TransientStorage) { game_input Input[2]; U64 LastCounter; @@ -734,193 +653,83 @@ S32 main(S32 argc, char *argv[]) Game = SDLLoadGameCode(SDLState.DLLPath); } - U32 SDLMouseButtons = - SDL_GetMouseState(&(NewInput->MouseX), - &(NewInput->MouseY)); + U32 SDLMouseButtons = SDL_GetMouseState(&(NewInput->MouseX), &(NewInput->MouseY)); NewInput->MouseZ = 0; /* TODO: Support mouse wheel? */ - SDLProcessKeyboardMessage(&(NewInput->MouseButtons[0]), - SDL_BUTTON_LMASK & SDLMouseButtons); - SDLProcessKeyboardMessage(&(NewInput->MouseButtons[1]), - SDL_BUTTON_MMASK & SDLMouseButtons); - SDLProcessKeyboardMessage(&(NewInput->MouseButtons[2]), - SDL_BUTTON_RMASK & SDLMouseButtons); - /* WARNING: TODO: SDL_BUTTON_X1MASK and - * SDL_BUTTON_X2MASK cannot be on at the + SDLProcessKeyboardMessage(&(NewInput->MouseButtons[0]), SDL_BUTTON_LMASK & SDLMouseButtons); + SDLProcessKeyboardMessage(&(NewInput->MouseButtons[1]), SDL_BUTTON_MMASK & SDLMouseButtons); + SDLProcessKeyboardMessage(&(NewInput->MouseButtons[2]), SDL_BUTTON_RMASK & SDLMouseButtons); + /* WARNING: TODO: SDL_BUTTON_X1MASK and SDL_BUTTON_X2MASK cannot be on at the * same time for some reason. */ - SDLProcessKeyboardMessage(&(NewInput->MouseButtons[3]), - SDL_BUTTON_X1MASK & SDLMouseButtons); - SDLProcessKeyboardMessage(&(NewInput->MouseButtons[4]), - SDL_BUTTON_X2MASK & SDLMouseButtons); + SDLProcessKeyboardMessage(&(NewInput->MouseButtons[3]), SDL_BUTTON_X1MASK & SDLMouseButtons); + SDLProcessKeyboardMessage(&(NewInput->MouseButtons[4]), SDL_BUTTON_X2MASK & SDLMouseButtons); - game_controller_input *OldKeyboardController = - GetController(OldInput, 0); - game_controller_input *NewKeyboardController = - GetController(NewInput, 0); + game_controller_input *OldKeyboardController = GetController(OldInput, 0); + game_controller_input *NewKeyboardController = GetController(NewInput, 0); game_controller_input ZeroController; memset(&ZeroController, 0, sizeof(ZeroController)); *NewKeyboardController = ZeroController; NewKeyboardController->IsConnected = TRUE; - for(U32 ButtonIndex = 0; - ButtonIndex < ARRAY_SIZE( - NewKeyboardController->u.Buttons); - ButtonIndex++) - { - NewKeyboardController-> - u.Buttons[ButtonIndex].EndedDown = - OldKeyboardController-> - u.Buttons[ButtonIndex]. - EndedDown; + for(U32 ButtonIndex = 0; ButtonIndex < ARRAY_SIZE(NewKeyboardController->Buttons); ButtonIndex++) { + NewKeyboardController->Buttons[ButtonIndex].EndedDown = OldKeyboardController->Buttons[ButtonIndex].EndedDown; } SDLProcessMessages(&SDLState, NewKeyboardController); - for(U32 ControllerIndex = 0; - ControllerIndex < MAX_CONTROLLERS; - ControllerIndex++) - { - game_controller_input *OldController, - *NewController; + for(U32 ControllerIndex = 0; ControllerIndex < MAX_CONTROLLERS; ControllerIndex++) { + game_controller_input *OldController = GetController(OldInput, ControllerIndex+1); + game_controller_input *NewController = GetController(NewInput, ControllerIndex+1); - OldController = - GetController(OldInput, ControllerIndex+1); - NewController = - GetController(NewInput, ControllerIndex+1); - - if(ControllerHandles[ControllerIndex] != 0 && - SDL_GameControllerGetAttached( - ControllerHandles[ControllerIndex])) - { - NewController->IsAnalog = - OldController->IsAnalog; + if(ControllerHandles[ControllerIndex] != 0 && SDL_GameControllerGetAttached(ControllerHandles[ControllerIndex])) { + NewController->IsAnalog = OldController->IsAnalog; NewController->IsConnected = TRUE; - S16 StickX = - SDL_GameControllerGetAxis( - ControllerHandles[ControllerIndex], - SDL_CONTROLLER_AXIS_LEFTX); - S16 StickY = - SDL_GameControllerGetAxis( - ControllerHandles[ControllerIndex], - SDL_CONTROLLER_AXIS_LEFTY); + S16 StickX = SDL_GameControllerGetAxis(ControllerHandles[ControllerIndex], SDL_CONTROLLER_AXIS_LEFTX); + S16 StickY = SDL_GameControllerGetAxis(ControllerHandles[ControllerIndex], SDL_CONTROLLER_AXIS_LEFTY); NewController->IsAnalog = TRUE; - NewController->StickAverageX = - SDLProcessInputStickValue((F32)StickX, - CONTROLLER_LEFT_THUMB_DEADZONE); - NewController->StickAverageY = - SDLProcessInputStickValue((F32)StickY, - CONTROLLER_LEFT_THUMB_DEADZONE); + NewController->StickAverageX = SDLProcessInputStickValue((F32)StickX, CONTROLLER_LEFT_THUMB_DEADZONE); + NewController->StickAverageY = SDLProcessInputStickValue((F32)StickY, CONTROLLER_LEFT_THUMB_DEADZONE); - if((NewController->StickAverageX != 0.0f) || - (NewController->StickAverageY != 0.0f)) - { + if((NewController->StickAverageX != 0.0f) || (NewController->StickAverageY != 0.0f)) { NewController->IsAnalog = TRUE; } - if(SDL_GameControllerGetButton( - ControllerHandles[ControllerIndex], - SDL_CONTROLLER_BUTTON_DPAD_UP)) - { + if(SDL_GameControllerGetButton(ControllerHandles[ControllerIndex], SDL_CONTROLLER_BUTTON_DPAD_UP)) { NewController->StickAverageY = -1.0f; NewController->IsAnalog = FALSE; } - if(SDL_GameControllerGetButton( - ControllerHandles[ControllerIndex], - SDL_CONTROLLER_BUTTON_DPAD_DOWN)) - { + if(SDL_GameControllerGetButton(ControllerHandles[ControllerIndex], SDL_CONTROLLER_BUTTON_DPAD_DOWN)) { NewController->StickAverageY = 1.0f; NewController->IsAnalog = FALSE; } - if(SDL_GameControllerGetButton( - ControllerHandles[ControllerIndex], - SDL_CONTROLLER_BUTTON_DPAD_LEFT)) - { + if(SDL_GameControllerGetButton(ControllerHandles[ControllerIndex], SDL_CONTROLLER_BUTTON_DPAD_LEFT)) { NewController->StickAverageX = -1.0f; NewController->IsAnalog = FALSE; } - if(SDL_GameControllerGetButton( - ControllerHandles[ControllerIndex], - SDL_CONTROLLER_BUTTON_DPAD_RIGHT)) - { + if(SDL_GameControllerGetButton(ControllerHandles[ControllerIndex], SDL_CONTROLLER_BUTTON_DPAD_RIGHT)) { NewController->StickAverageX = 1.0f; NewController->IsAnalog = FALSE; } F32 Threshold = 0.5f; - SDLProcessInputDigitalButton( - ControllerHandles[ - (NewController->StickAverageY < - -Threshold) ? 1 : 0], - &OldController->u.buttons.MoveUp, - SDL_CONTROLLER_BUTTON_A, - &NewController->u.buttons.MoveUp); - SDLProcessInputDigitalButton( - ControllerHandles[ - (NewController->StickAverageY > - Threshold) ? 1 : 0], - &OldController->u.buttons.MoveDown, - SDL_CONTROLLER_BUTTON_A, - &NewController->u.buttons.MoveDown); - SDLProcessInputDigitalButton( - ControllerHandles[ - (NewController->StickAverageX < - -Threshold) ? 1 : 0], - &OldController->u.buttons.MoveLeft, - SDL_CONTROLLER_BUTTON_A, - &NewController->u.buttons.MoveLeft); - SDLProcessInputDigitalButton( - ControllerHandles[ - (NewController->StickAverageX > - Threshold) ? 1 : 0], - &OldController->u.buttons.MoveRight, - SDL_CONTROLLER_BUTTON_A, - &NewController->u.buttons.MoveRight); + SDLProcessInputDigitalButton(ControllerHandles[(NewController->StickAverageY < -Threshold) ? 1 : 0], &OldController->MoveUp, SDL_CONTROLLER_BUTTON_A, &NewController->MoveUp); + SDLProcessInputDigitalButton(ControllerHandles[(NewController->StickAverageY > Threshold) ? 1 : 0], &OldController->MoveDown, SDL_CONTROLLER_BUTTON_A, &NewController->MoveDown); + SDLProcessInputDigitalButton(ControllerHandles[(NewController->StickAverageX < -Threshold) ? 1 : 0], &OldController->MoveLeft, SDL_CONTROLLER_BUTTON_A, &NewController->MoveLeft); + SDLProcessInputDigitalButton(ControllerHandles[(NewController->StickAverageX > Threshold) ? 1 : 0], &OldController->MoveRight, SDL_CONTROLLER_BUTTON_A, &NewController->MoveRight); - SDLProcessInputDigitalButton( - ControllerHandles[ControllerIndex], - &OldController->u.buttons.ActionDown, - SDL_CONTROLLER_BUTTON_A, - &NewController->u.buttons.ActionDown); - SDLProcessInputDigitalButton( - ControllerHandles[ControllerIndex], - &OldController->u.buttons.ActionRight, - SDL_CONTROLLER_BUTTON_B, - &NewController->u.buttons.ActionRight); - SDLProcessInputDigitalButton( - ControllerHandles[ControllerIndex], - &OldController->u.buttons.ActionLeft, - SDL_CONTROLLER_BUTTON_X, - &NewController->u.buttons.ActionLeft); - SDLProcessInputDigitalButton( - ControllerHandles[ControllerIndex], - &OldController->u.buttons.ActionUp, - SDL_CONTROLLER_BUTTON_Y, - &NewController->u.buttons.ActionUp); - SDLProcessInputDigitalButton( - ControllerHandles[ControllerIndex], - &OldController->u.buttons.LeftShoulder, - SDL_CONTROLLER_BUTTON_LEFTSHOULDER, - &NewController->u.buttons.LeftShoulder); - SDLProcessInputDigitalButton( - ControllerHandles[ControllerIndex], - &OldController->u.buttons.RightShoulder, - SDL_CONTROLLER_BUTTON_RIGHTSHOULDER, - &NewController->u.buttons.RightShoulder); + SDLProcessInputDigitalButton(ControllerHandles[ControllerIndex], &OldController->ActionDown, SDL_CONTROLLER_BUTTON_A, &NewController->ActionDown); + SDLProcessInputDigitalButton(ControllerHandles[ControllerIndex], &OldController->ActionRight, SDL_CONTROLLER_BUTTON_B, &NewController->ActionRight); + SDLProcessInputDigitalButton(ControllerHandles[ControllerIndex], &OldController->ActionLeft, SDL_CONTROLLER_BUTTON_X, &NewController->ActionLeft); + SDLProcessInputDigitalButton(ControllerHandles[ControllerIndex], &OldController->ActionUp, SDL_CONTROLLER_BUTTON_Y, &NewController->ActionUp); + SDLProcessInputDigitalButton(ControllerHandles[ControllerIndex], &OldController->LeftShoulder, SDL_CONTROLLER_BUTTON_LEFTSHOULDER, &NewController->LeftShoulder); + SDLProcessInputDigitalButton( ControllerHandles[ControllerIndex], &OldController->RightShoulder, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER, &NewController->RightShoulder); - SDLProcessInputDigitalButton( - ControllerHandles[ControllerIndex], - &OldController->u.buttons.Start, - SDL_CONTROLLER_BUTTON_START, - &NewController->u.buttons.Start); - SDLProcessInputDigitalButton( - ControllerHandles[ControllerIndex], - &OldController->u.buttons.Back, - SDL_CONTROLLER_BUTTON_BACK, - &NewController->u.buttons.Back); + SDLProcessInputDigitalButton(ControllerHandles[ControllerIndex], &OldController->Start, SDL_CONTROLLER_BUTTON_START, &NewController->Start); + SDLProcessInputDigitalButton( ControllerHandles[ControllerIndex], &OldController->Back, SDL_CONTROLLER_BUTTON_BACK, &NewController->Back); } else { /* NOTE: This controller is not plugged in. */ NewController->IsConnected = FALSE;