From 713738b9f3efa8e9ea14cd6a16d702ca5ddeef24 Mon Sep 17 00:00:00 2001 From: igor Date: Tue, 14 Apr 2026 18:33:43 -0700 Subject: [PATCH] Day 33 complete. --- Makefile | 18 ++-- handmade.c | 284 ++++++++++++++++++++++++------------------------- handmade.h | 40 ++++--- sdl_handmade.c | 1 - 4 files changed, 167 insertions(+), 176 deletions(-) diff --git a/Makefile b/Makefile index 6a32872..00a098e 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ FLAGS = -ansi -pedantic -pedantic-errors -Wno-long-long \ ifeq ($(DETECTED_OS),macos) UFLAGS = -glldb - INCLUDE = -I./sdl/include/ + INCLUDE = -I./sdl/include/ LIBS = ./sdl/lib/arm-macos/libSDL2.a -lm FRAMEWORKS = -framework Cocoa -framework IOKit -framework CoreAudio \ -framework AudioToolbox -framework ForceFeedback \ @@ -38,18 +38,18 @@ ifeq ($(DETECTED_OS),macos) -framework Metal -framework QuartzCore \ -framework CoreHaptics else ifeq ($(DETECTED_OS),linux) - UFLAGS = -ggdb -D_POSIX_C_SOURCE=200809L + UFLAGS = -ggdb -D_POSIX_C_SOURCE=200809L INCLUDE = -I./sdl/include/ LIBS = ./sdl/lib/x86_64-linux/libSDL2.a -lm -lX11 - FRAMEWORKS = + FRAMEWORKS = else ifeq ($(DETECTED_OS),windows) - INCLUDE = - LIBS = - FRAMEWORKS = + INCLUDE = + LIBS = + FRAMEWORKS = else - INCLUDE = - LIBS = - FRAMEWORKS = + INCLUDE = + LIBS = + FRAMEWORKS = endif EXE=handmadehero diff --git a/handmade.c b/handmade.c index ba69244..7fa6192 100644 --- a/handmade.c +++ b/handmade.c @@ -94,68 +94,59 @@ static void DrawRectangle(game_offscreen_buffer *Buffer, } } -static tile_map *GetTileMap(world *World, S32 TileMapX, S32 TileMapY) +static tile_chunk *GetTileChunk(world *World, + S32 TileChunkX, S32 TileChunkY) { - tile_map *TileMap = NULL; + tile_chunk *TileChunk = NULL; - if((TileMapX >= 0) && (TileMapX < World->TileMapCountX) && - (TileMapY >= 0) && (TileMapY < World->TileMapCountY)) + if((TileChunkX >= 0) && (TileChunkX < World->TileChunkCountX) && + (TileChunkY >= 0) && (TileChunkY < World->TileChunkCountY)) { - TileMap = - &World->TileMaps[TileMapY*World->TileMapCountX + TileMapX]; + TileChunk = &World->TileChunks[TileChunkY * + World->TileChunkCountX + + TileChunkX]; } - return TileMap; + return TileChunk; } -static U32 GetTileValueUnchecked(world *World, tile_map *TileMap, S32 TileX, S32 TileY) +static U32 GetTileValueUnchecked(world *World, tile_chunk *TileChunk, + U32 TileX, U32 TileY) { - U32 TileMapValue; + U32 TileChunkValue; - ASSERT(TileMap); - ASSERT((TileX >= 0) && (TileX < World->CountX) && - (TileY >= 0) && (TileY < World->CountY)); + ASSERT(TileChunk); + ASSERT(TileX < World->ChunkDim); + ASSERT(TileY < World->ChunkDim); - TileMapValue = TileMap->Tiles[TileY*World->CountX + TileX]; - return TileMapValue; + TileChunkValue = TileChunk->Tiles[TileY * World->ChunkDim + TileX]; + return TileChunkValue; } -static B32 IsTileMapPointEmpty(world *World, tile_map *TileMap, - S32 TestTileX, S32 TestTileY) +static U32 GetTileChunkValue(world *World, tile_chunk *TileChunk, + U32 TestTileX, U32 TestTileY) { - B32 Empty = FALSE; + U32 TileChunkValue = 0; - if(TileMap) { - if((TestTileX >= 0) && (TestTileX < World->CountX) && - (TestTileY >= 0) && (TestTileY < World->CountY)) - { - U32 TileMapValue = - GetTileValueUnchecked(World, TileMap, TestTileX, TestTileY); - Empty = (TileMapValue == 0); - } + if(TileChunk) { + TileChunkValue = GetTileValueUnchecked(World, + TileChunk, + TestTileX, TestTileY); } - return Empty; + return TileChunkValue; } -static void CannonicalizeCoord(world *World, S32 TileCount, - S32 *TileMap, S32 *Tile, F32 *TileRel) +static void CannonicalizeCoord(world *World, U32 *Tile, F32 *TileRel) { + /* NOTE: The world is assumed to be toroidal topology. If you step off + one end, you come back on the other. */ S32 Offset = FloorF32toS32(*TileRel / World->TileSideInMeters); *Tile += Offset; *TileRel -= (F32)Offset * World->TileSideInMeters; ASSERT(*TileRel >= 0); ASSERT(*TileRel < World->TileSideInMeters); - - if(*Tile < 0) { - *Tile = TileCount + *Tile; - (*TileMap)--; - } - if(*Tile >= TileCount) { - *Tile = *Tile - TileCount; - (*TileMap)++; - } } static cannonical_position RecannonicalizePosition(world *World, @@ -163,20 +154,47 @@ static cannonical_position RecannonicalizePosition(world *World, { cannonical_position Result = Pos; - CannonicalizeCoord(World, World->CountX, - &Result.TileMapX, &Result.TileX, &Result.TileRelX); - CannonicalizeCoord(World, World->CountY, - &Result.TileMapY, &Result.TileY, &Result.TileRelY); + CannonicalizeCoord(World, &Result.AbsTileX, &Result.TileRelX); + CannonicalizeCoord(World, &Result.AbsTileY, &Result.TileRelY); return Result; } +static tile_chunk_position GetChunkPositionFor(world *World, + U32 AbsTileX, U32 AbsTileY) +{ + tile_chunk_position Result; + + Result.TileChunkX = AbsTileX >> World->ChunkShift; + Result.TileChunkY = AbsTileY >> World->ChunkShift; + Result.RelTileX = AbsTileX & World->ChunkMask; + Result.RelTileY = AbsTileY & World->ChunkMask; + + return Result; +} + +static U32 GetTileValue(world *World, U32 AbsTileX, U32 AbsTileY) +{ + tile_chunk_position ChunkPos = GetChunkPositionFor(World, + AbsTileX, + AbsTileY); + tile_chunk *TileMap = GetTileChunk(World, + ChunkPos.TileChunkX, + ChunkPos.TileChunkY); + U32 TileChunkValue = GetTileChunkValue(World, TileMap, + ChunkPos.RelTileX, + ChunkPos.RelTileY); + return TileChunkValue; +} + static B32 IsWorldPointEmpty(world *World, cannonical_position CanPos) { - B32 Empty = FALSE; + B32 Empty; - tile_map *TileMap = GetTileMap(World, CanPos.TileMapX, CanPos.TileMapY); - Empty = IsTileMapPointEmpty(World, TileMap, CanPos.TileX, CanPos.TileY); + U32 TileChunkValue = GetTileValue(World, + CanPos.AbsTileX, + CanPos.AbsTileY); + Empty = (TileChunkValue == 0); return Empty; } @@ -185,63 +203,39 @@ void UpdateAndRender(thread_context *Thread, game_memory *Memory, game_input *Input, game_offscreen_buffer *Buffer, game_sound_output_buffer *SoundBuffer) { -#define TILEMAP_COUNT_X 17 -#define TILEMAP_COUNT_Y 9 +#define TILEMAP_COUNT_X 256 +#define TILEMAP_COUNT_Y 256 game_state *GameState; U32 ControllerIndex; - S32 Row, Column; - U32 Tiles00[TILEMAP_COUNT_Y][TILEMAP_COUNT_X] = { - {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, - {1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1}, - {1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1}, - {1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1}, - {1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0}, - {1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1}, - {1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1}, - {1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1}, - {1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1}, - }; - U32 Tiles01[TILEMAP_COUNT_Y][TILEMAP_COUNT_X] = { - {1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1}, - {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, - {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, - {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, - {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {1, 0, 0, 0, 0, 0, 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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, }; - F32 PlayerR, PlayerG, PlayerB, PlayerWidth, PlayerHeight, + F32 PlayerR, PlayerG, PlayerB, + PlayerWidth, PlayerHeight, PlayerLeft, PlayerTop; + F32 CenterX, CenterY; - tile_map TileMaps[2][2]; - tile_map *TileMap; + tile_chunk TileChunk; world World; ASSERT((&Input->Controllers[0].u.buttons.Terminator - @@ -249,43 +243,39 @@ void UpdateAndRender(thread_context *Thread, game_memory *Memory, ARRAY_SIZE(Input->Controllers[0].u.Buttons)); ASSERT(sizeof(game_state) <= Memory->PermanentStorageSize); - TileMaps[0][0].Tiles = (U32 *)Tiles00; - TileMaps[0][1].Tiles = (U32 *)Tiles10; - TileMaps[1][0].Tiles = (U32 *)Tiles01; - TileMaps[1][1].Tiles = (U32 *)Tiles11; - memset(&World, 0, sizeof(World)); - World.TileMapCountX = 2; - World.TileMapCountY = 2; - World.CountX = TILEMAP_COUNT_X; - World.CountY = TILEMAP_COUNT_Y; + /* NOTE: This is set to using 256x256 tile chunks. */ + World.ChunkShift = 8; + World.ChunkMask = 0xFF; + World.ChunkDim = 256; + + World.TileChunkCountX = 1; + World.TileChunkCountY = 1; + + TileChunk.Tiles = (U32 *)TempTiles; + World.TileChunks = &TileChunk; + World.TileSideInMeters = 1.4f; World.TileSideInPixels = 60; World.MetersToPixels = (F32)World.TileSideInPixels / World.TileSideInMeters; - World.UpperLeftX = -((F32)World.TileSideInPixels / 2.0f); - World.UpperLeftY = 0.0f; - World.TileMaps = (tile_map *)TileMaps; PlayerHeight = 1.4f; PlayerWidth = 0.75f * PlayerHeight; + CenterX = 0.5f * (F32)Buffer->Width; + CenterY = 0.5f * (F32)Buffer->Height; + GameState = (game_state *)Memory->PermanentStorage; if(!Memory->IsInitialized) { - GameState->PlayerP.TileMapX = 0; - GameState->PlayerP.TileMapY = 0; - GameState->PlayerP.TileX = 3; - GameState->PlayerP.TileY = 3; + GameState->PlayerP.AbsTileX = 3; + GameState->PlayerP.AbsTileY = 3; GameState->PlayerP.TileRelX = 5.0f; GameState->PlayerP.TileRelY = 5.0f; Memory->IsInitialized = TRUE; } - TileMap = GetTileMap(&World, GameState->PlayerP.TileMapX, - GameState->PlayerP.TileMapY); - ASSERT(TileMap); - for(ControllerIndex = 0; ControllerIndex < ARRAY_SIZE(Input->Controllers); ControllerIndex++) @@ -300,10 +290,10 @@ void UpdateAndRender(thread_context *Thread, game_memory *Memory, cannonical_position NewPlayerP, PlayerLeft, PlayerRight; if(Controller->u.buttons.MoveUp.EndedDown) { - dPlayerY = -1.0f; + dPlayerY = 1.0f; } if(Controller->u.buttons.MoveDown.EndedDown) { - dPlayerY = 1.0f; + dPlayerY = -1.0f; } if(Controller->u.buttons.MoveLeft.EndedDown) { dPlayerX = -1.0f; @@ -338,46 +328,50 @@ void UpdateAndRender(thread_context *Thread, game_memory *Memory, } DrawRectangle(Buffer, 0.0f, 0.0f, - (F32)(Buffer->Width), (F32)(Buffer->Height), + (F32)Buffer->Width, (F32)Buffer->Height, 0.0f, 1.0f, 0.0f); + { + S32 RelRow, RelColumn; + for(RelRow = -10; RelRow < 10; RelRow++) { + for(RelColumn = -20; RelColumn < 20; RelColumn++) { + U32 Column = GameState->PlayerP.AbsTileX + RelColumn; + U32 Row = GameState->PlayerP.AbsTileY + RelRow; - for(Row = 0; Row < TILEMAP_COUNT_Y; Row++) { - for(Column = 0; Column < TILEMAP_COUNT_X; Column++) { - F32 MinX, MinY, MaxX, MaxY; - U32 TileID = GetTileValueUnchecked(&World, TileMap, Column, Row); - F32 Gray = 0.5f; - if(TileID) { - Gray = 1.0f; + U32 TileID = GetTileValue(&World, Column, Row); + F32 Gray = 0.5f; + + if(TileID) { + Gray = 1.0f; + } + + if((Column == GameState->PlayerP.AbsTileX) && + (Row == GameState->PlayerP.AbsTileY)) + { + Gray = 0.0f; + } + + { + F32 MinX, MinY, MaxX, MaxY; + MinX = CenterX + + (F32)RelColumn * (F32)World.TileSideInPixels; + MinY = CenterY - + (F32)RelRow * (F32)World.TileSideInPixels; + MaxX = MinX + (F32)World.TileSideInPixels; + MaxY = MinY - (F32)World.TileSideInPixels; + DrawRectangle(Buffer, + MinX, MaxY, MaxX, MinY, + Gray, Gray, Gray); + } } - - if((Column == GameState->PlayerP.TileX) && - (Row == GameState->PlayerP.TileY)) - { - Gray = 0.0f; - } - - MinX = World.UpperLeftX + - (F32)(Column) * (F32)World.TileSideInPixels; - MinY = - World.UpperLeftY + (F32)(Row) * (F32)World.TileSideInPixels; - MaxX = MinX + (F32)World.TileSideInPixels; - MaxY = MinY + (F32)World.TileSideInPixels; - DrawRectangle(Buffer, MinX, MinY, MaxX, MaxY, Gray, Gray, Gray); } } PlayerR = 1.0f; PlayerG = 0.0f; PlayerB = 0.0f; - PlayerLeft = World.UpperLeftX + - (F32)World.TileSideInPixels*(F32)GameState->PlayerP.TileX + - (F32)GameState->PlayerP.TileX + - World.MetersToPixels*GameState->PlayerP.TileRelX - + PlayerLeft = CenterX + World.MetersToPixels*GameState->PlayerP.TileRelX - 0.5f*World.MetersToPixels*PlayerWidth; - PlayerTop = World.UpperLeftY + - (F32)World.TileSideInPixels*(F32)GameState->PlayerP.TileY + - (F32)GameState->PlayerP.TileY + - World.MetersToPixels*GameState->PlayerP.TileRelY - + PlayerTop = CenterY - World.MetersToPixels*GameState->PlayerP.TileRelY - World.MetersToPixels*PlayerHeight; DrawRectangle(Buffer, PlayerLeft, PlayerTop, diff --git a/handmade.h b/handmade.h index 39272c1..c402053 100644 --- a/handmade.h +++ b/handmade.h @@ -136,42 +136,40 @@ void UpdateAndRender(thread_context *Thread, game_memory *Memory, * */ -typedef struct cannonical_position { -#if 1 - S32 TileMapX; - S32 TileMapY; +typedef struct tile_chunk_position { + U32 TileChunkX; + U32 TileChunkY; - S32 TileX; - S32 TileY; -#else - U32 _TileX; - U32 _TileY; -#endif + U32 RelTileX; + U32 RelTileY; +} tile_chunk_position; + +typedef struct cannonical_position { + U32 AbsTileX; + U32 AbsTileY; /* NOTE: Tile-relative X and Y. */ F32 TileRelX; F32 TileRelY; } cannonical_position; -typedef struct tile_map { +typedef struct tile_chunk { U32 *Tiles; -} tile_map; +} tile_chunk; typedef struct world { + U32 ChunkShift; + U32 ChunkMask; + U32 ChunkDim; + F32 TileSideInMeters; S32 TileSideInPixels; F32 MetersToPixels; - S32 CountX; - S32 CountY; + S32 TileChunkCountX; + S32 TileChunkCountY; - F32 UpperLeftX; - F32 UpperLeftY; - - S32 TileMapCountX; - S32 TileMapCountY; - - tile_map *TileMaps; + tile_chunk *TileChunks; } world; typedef struct game_state { diff --git a/sdl_handmade.c b/sdl_handmade.c index 84c0f50..4f80b90 100644 --- a/sdl_handmade.c +++ b/sdl_handmade.c @@ -486,7 +486,6 @@ static U32 GetLastWriteTime(const char *FileName) memset(&file_info, 0, sizeof(file_info)); if(stat(FileName, &file_info) != 0) { /* TODO: Diagnostic. perror("stat failed"); */ - perror("stat failed"); } return (U32)file_info.st_mtime;