Day 33 complete.
This commit is contained in:
+134
-140
@@ -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) &&
|
if((TileChunkX >= 0) && (TileChunkX < World->TileChunkCountX) &&
|
||||||
(TileMapY >= 0) && (TileMapY < World->TileMapCountY))
|
(TileChunkY >= 0) && (TileChunkY < World->TileChunkCountY))
|
||||||
{
|
{
|
||||||
TileMap =
|
TileChunk = &World->TileChunks[TileChunkY *
|
||||||
&World->TileMaps[TileMapY*World->TileMapCountX + TileMapX];
|
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(TileChunk);
|
||||||
ASSERT((TileX >= 0) && (TileX < World->CountX) &&
|
ASSERT(TileX < World->ChunkDim);
|
||||||
(TileY >= 0) && (TileY < World->CountY));
|
ASSERT(TileY < World->ChunkDim);
|
||||||
|
|
||||||
TileMapValue = TileMap->Tiles[TileY*World->CountX + TileX];
|
TileChunkValue = TileChunk->Tiles[TileY * World->ChunkDim + TileX];
|
||||||
return TileMapValue;
|
return TileChunkValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
static B32 IsTileMapPointEmpty(world *World, tile_map *TileMap,
|
static U32 GetTileChunkValue(world *World, tile_chunk *TileChunk,
|
||||||
S32 TestTileX, S32 TestTileY)
|
U32 TestTileX, U32 TestTileY)
|
||||||
{
|
{
|
||||||
B32 Empty = FALSE;
|
U32 TileChunkValue = 0;
|
||||||
|
|
||||||
if(TileMap) {
|
if(TileChunk) {
|
||||||
if((TestTileX >= 0) && (TestTileX < World->CountX) &&
|
TileChunkValue = GetTileValueUnchecked(World,
|
||||||
(TestTileY >= 0) && (TestTileY < World->CountY))
|
TileChunk,
|
||||||
{
|
TestTileX, TestTileY);
|
||||||
U32 TileMapValue =
|
}
|
||||||
GetTileValueUnchecked(World, TileMap, TestTileX, TestTileY);
|
|
||||||
Empty = (TileMapValue == 0);
|
return TileChunkValue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
static void CannonicalizeCoord(world *World, U32 *Tile, F32 *TileRel)
|
||||||
return Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void CannonicalizeCoord(world *World, S32 TileCount,
|
|
||||||
S32 *TileMap, S32 *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);
|
S32 Offset = FloorF32toS32(*TileRel / World->TileSideInMeters);
|
||||||
*Tile += Offset;
|
*Tile += Offset;
|
||||||
*TileRel -= (F32)Offset * World->TileSideInMeters;
|
*TileRel -= (F32)Offset * World->TileSideInMeters;
|
||||||
|
|
||||||
ASSERT(*TileRel >= 0);
|
ASSERT(*TileRel >= 0);
|
||||||
ASSERT(*TileRel < World->TileSideInMeters);
|
ASSERT(*TileRel < World->TileSideInMeters);
|
||||||
|
|
||||||
if(*Tile < 0) {
|
|
||||||
*Tile = TileCount + *Tile;
|
|
||||||
(*TileMap)--;
|
|
||||||
}
|
|
||||||
if(*Tile >= TileCount) {
|
|
||||||
*Tile = *Tile - TileCount;
|
|
||||||
(*TileMap)++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static cannonical_position RecannonicalizePosition(world *World,
|
static cannonical_position RecannonicalizePosition(world *World,
|
||||||
@@ -163,20 +154,47 @@ static cannonical_position RecannonicalizePosition(world *World,
|
|||||||
{
|
{
|
||||||
cannonical_position Result = Pos;
|
cannonical_position Result = Pos;
|
||||||
|
|
||||||
CannonicalizeCoord(World, World->CountX,
|
CannonicalizeCoord(World, &Result.AbsTileX, &Result.TileRelX);
|
||||||
&Result.TileMapX, &Result.TileX, &Result.TileRelX);
|
CannonicalizeCoord(World, &Result.AbsTileY, &Result.TileRelY);
|
||||||
CannonicalizeCoord(World, World->CountY,
|
|
||||||
&Result.TileMapY, &Result.TileY, &Result.TileRelY);
|
|
||||||
|
|
||||||
return Result;
|
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)
|
static B32 IsWorldPointEmpty(world *World, cannonical_position CanPos)
|
||||||
{
|
{
|
||||||
B32 Empty = FALSE;
|
B32 Empty;
|
||||||
|
|
||||||
tile_map *TileMap = GetTileMap(World, CanPos.TileMapX, CanPos.TileMapY);
|
U32 TileChunkValue = GetTileValue(World,
|
||||||
Empty = IsTileMapPointEmpty(World, TileMap, CanPos.TileX, CanPos.TileY);
|
CanPos.AbsTileX,
|
||||||
|
CanPos.AbsTileY);
|
||||||
|
Empty = (TileChunkValue == 0);
|
||||||
|
|
||||||
return Empty;
|
return Empty;
|
||||||
}
|
}
|
||||||
@@ -185,63 +203,39 @@ void UpdateAndRender(thread_context *Thread, game_memory *Memory,
|
|||||||
game_input *Input, game_offscreen_buffer *Buffer,
|
game_input *Input, game_offscreen_buffer *Buffer,
|
||||||
game_sound_output_buffer *SoundBuffer)
|
game_sound_output_buffer *SoundBuffer)
|
||||||
{
|
{
|
||||||
#define TILEMAP_COUNT_X 17
|
#define TILEMAP_COUNT_X 256
|
||||||
#define TILEMAP_COUNT_Y 9
|
#define TILEMAP_COUNT_Y 256
|
||||||
|
|
||||||
game_state *GameState;
|
game_state *GameState;
|
||||||
U32 ControllerIndex;
|
U32 ControllerIndex;
|
||||||
S32 Row, Column;
|
|
||||||
|
|
||||||
U32 Tiles00[TILEMAP_COUNT_Y][TILEMAP_COUNT_X] = {
|
U32 TempTiles[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, 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, 1, 1, 1, 1, 1, 1, 1},
|
||||||
{1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 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0, 0, 0, 0, 0, 1},
|
|
||||||
{0, 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, 1},
|
|
||||||
{1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1},
|
|
||||||
};
|
|
||||||
U32 Tiles11[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},
|
|
||||||
{0, 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, 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;
|
PlayerLeft, PlayerTop;
|
||||||
|
F32 CenterX, CenterY;
|
||||||
|
|
||||||
tile_map TileMaps[2][2];
|
tile_chunk TileChunk;
|
||||||
tile_map *TileMap;
|
|
||||||
world World;
|
world World;
|
||||||
|
|
||||||
ASSERT((&Input->Controllers[0].u.buttons.Terminator -
|
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));
|
ARRAY_SIZE(Input->Controllers[0].u.Buttons));
|
||||||
ASSERT(sizeof(game_state) <= Memory->PermanentStorageSize);
|
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));
|
memset(&World, 0, sizeof(World));
|
||||||
World.TileMapCountX = 2;
|
/* NOTE: This is set to using 256x256 tile chunks. */
|
||||||
World.TileMapCountY = 2;
|
World.ChunkShift = 8;
|
||||||
World.CountX = TILEMAP_COUNT_X;
|
World.ChunkMask = 0xFF;
|
||||||
World.CountY = TILEMAP_COUNT_Y;
|
World.ChunkDim = 256;
|
||||||
|
|
||||||
|
World.TileChunkCountX = 1;
|
||||||
|
World.TileChunkCountY = 1;
|
||||||
|
|
||||||
|
TileChunk.Tiles = (U32 *)TempTiles;
|
||||||
|
World.TileChunks = &TileChunk;
|
||||||
|
|
||||||
World.TileSideInMeters = 1.4f;
|
World.TileSideInMeters = 1.4f;
|
||||||
World.TileSideInPixels = 60;
|
World.TileSideInPixels = 60;
|
||||||
World.MetersToPixels =
|
World.MetersToPixels =
|
||||||
(F32)World.TileSideInPixels / World.TileSideInMeters;
|
(F32)World.TileSideInPixels / World.TileSideInMeters;
|
||||||
World.UpperLeftX = -((F32)World.TileSideInPixels / 2.0f);
|
|
||||||
World.UpperLeftY = 0.0f;
|
|
||||||
World.TileMaps = (tile_map *)TileMaps;
|
|
||||||
|
|
||||||
PlayerHeight = 1.4f;
|
PlayerHeight = 1.4f;
|
||||||
PlayerWidth = 0.75f * PlayerHeight;
|
PlayerWidth = 0.75f * PlayerHeight;
|
||||||
|
|
||||||
|
CenterX = 0.5f * (F32)Buffer->Width;
|
||||||
|
CenterY = 0.5f * (F32)Buffer->Height;
|
||||||
|
|
||||||
GameState = (game_state *)Memory->PermanentStorage;
|
GameState = (game_state *)Memory->PermanentStorage;
|
||||||
if(!Memory->IsInitialized) {
|
if(!Memory->IsInitialized) {
|
||||||
GameState->PlayerP.TileMapX = 0;
|
GameState->PlayerP.AbsTileX = 3;
|
||||||
GameState->PlayerP.TileMapY = 0;
|
GameState->PlayerP.AbsTileY = 3;
|
||||||
GameState->PlayerP.TileX = 3;
|
|
||||||
GameState->PlayerP.TileY = 3;
|
|
||||||
GameState->PlayerP.TileRelX = 5.0f;
|
GameState->PlayerP.TileRelX = 5.0f;
|
||||||
GameState->PlayerP.TileRelY = 5.0f;
|
GameState->PlayerP.TileRelY = 5.0f;
|
||||||
|
|
||||||
Memory->IsInitialized = TRUE;
|
Memory->IsInitialized = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
TileMap = GetTileMap(&World, GameState->PlayerP.TileMapX,
|
|
||||||
GameState->PlayerP.TileMapY);
|
|
||||||
ASSERT(TileMap);
|
|
||||||
|
|
||||||
for(ControllerIndex = 0;
|
for(ControllerIndex = 0;
|
||||||
ControllerIndex < ARRAY_SIZE(Input->Controllers);
|
ControllerIndex < ARRAY_SIZE(Input->Controllers);
|
||||||
ControllerIndex++)
|
ControllerIndex++)
|
||||||
@@ -300,10 +290,10 @@ void UpdateAndRender(thread_context *Thread, game_memory *Memory,
|
|||||||
cannonical_position NewPlayerP, PlayerLeft, PlayerRight;
|
cannonical_position NewPlayerP, PlayerLeft, PlayerRight;
|
||||||
|
|
||||||
if(Controller->u.buttons.MoveUp.EndedDown) {
|
if(Controller->u.buttons.MoveUp.EndedDown) {
|
||||||
dPlayerY = -1.0f;
|
dPlayerY = 1.0f;
|
||||||
}
|
}
|
||||||
if(Controller->u.buttons.MoveDown.EndedDown) {
|
if(Controller->u.buttons.MoveDown.EndedDown) {
|
||||||
dPlayerY = 1.0f;
|
dPlayerY = -1.0f;
|
||||||
}
|
}
|
||||||
if(Controller->u.buttons.MoveLeft.EndedDown) {
|
if(Controller->u.buttons.MoveLeft.EndedDown) {
|
||||||
dPlayerX = -1.0f;
|
dPlayerX = -1.0f;
|
||||||
@@ -338,46 +328,50 @@ void UpdateAndRender(thread_context *Thread, game_memory *Memory,
|
|||||||
}
|
}
|
||||||
|
|
||||||
DrawRectangle(Buffer, 0.0f, 0.0f,
|
DrawRectangle(Buffer, 0.0f, 0.0f,
|
||||||
(F32)(Buffer->Width), (F32)(Buffer->Height),
|
(F32)Buffer->Width, (F32)Buffer->Height,
|
||||||
0.0f, 1.0f, 0.0f);
|
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++) {
|
U32 TileID = GetTileValue(&World, Column, 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;
|
F32 Gray = 0.5f;
|
||||||
|
|
||||||
if(TileID) {
|
if(TileID) {
|
||||||
Gray = 1.0f;
|
Gray = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((Column == GameState->PlayerP.TileX) &&
|
if((Column == GameState->PlayerP.AbsTileX) &&
|
||||||
(Row == GameState->PlayerP.TileY))
|
(Row == GameState->PlayerP.AbsTileY))
|
||||||
{
|
{
|
||||||
Gray = 0.0f;
|
Gray = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
MinX = World.UpperLeftX +
|
{
|
||||||
(F32)(Column) * (F32)World.TileSideInPixels;
|
F32 MinX, MinY, MaxX, MaxY;
|
||||||
MinY =
|
MinX = CenterX +
|
||||||
World.UpperLeftY + (F32)(Row) * (F32)World.TileSideInPixels;
|
(F32)RelColumn * (F32)World.TileSideInPixels;
|
||||||
|
MinY = CenterY -
|
||||||
|
(F32)RelRow * (F32)World.TileSideInPixels;
|
||||||
MaxX = MinX + (F32)World.TileSideInPixels;
|
MaxX = MinX + (F32)World.TileSideInPixels;
|
||||||
MaxY = MinY + (F32)World.TileSideInPixels;
|
MaxY = MinY - (F32)World.TileSideInPixels;
|
||||||
DrawRectangle(Buffer, MinX, MinY, MaxX, MaxY, Gray, Gray, Gray);
|
DrawRectangle(Buffer,
|
||||||
|
MinX, MaxY, MaxX, MinY,
|
||||||
|
Gray, Gray, Gray);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerR = 1.0f;
|
PlayerR = 1.0f;
|
||||||
PlayerG = 0.0f;
|
PlayerG = 0.0f;
|
||||||
PlayerB = 0.0f;
|
PlayerB = 0.0f;
|
||||||
PlayerLeft = World.UpperLeftX +
|
PlayerLeft = CenterX + World.MetersToPixels*GameState->PlayerP.TileRelX -
|
||||||
(F32)World.TileSideInPixels*(F32)GameState->PlayerP.TileX +
|
|
||||||
(F32)GameState->PlayerP.TileX +
|
|
||||||
World.MetersToPixels*GameState->PlayerP.TileRelX -
|
|
||||||
0.5f*World.MetersToPixels*PlayerWidth;
|
0.5f*World.MetersToPixels*PlayerWidth;
|
||||||
PlayerTop = World.UpperLeftY +
|
PlayerTop = CenterY - World.MetersToPixels*GameState->PlayerP.TileRelY -
|
||||||
(F32)World.TileSideInPixels*(F32)GameState->PlayerP.TileY +
|
|
||||||
(F32)GameState->PlayerP.TileY +
|
|
||||||
World.MetersToPixels*GameState->PlayerP.TileRelY -
|
|
||||||
World.MetersToPixels*PlayerHeight;
|
World.MetersToPixels*PlayerHeight;
|
||||||
DrawRectangle(Buffer,
|
DrawRectangle(Buffer,
|
||||||
PlayerLeft, PlayerTop,
|
PlayerLeft, PlayerTop,
|
||||||
|
|||||||
+19
-21
@@ -136,42 +136,40 @@ void UpdateAndRender(thread_context *Thread, game_memory *Memory,
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct cannonical_position {
|
typedef struct tile_chunk_position {
|
||||||
#if 1
|
U32 TileChunkX;
|
||||||
S32 TileMapX;
|
U32 TileChunkY;
|
||||||
S32 TileMapY;
|
|
||||||
|
|
||||||
S32 TileX;
|
U32 RelTileX;
|
||||||
S32 TileY;
|
U32 RelTileY;
|
||||||
#else
|
} tile_chunk_position;
|
||||||
U32 _TileX;
|
|
||||||
U32 _TileY;
|
typedef struct cannonical_position {
|
||||||
#endif
|
U32 AbsTileX;
|
||||||
|
U32 AbsTileY;
|
||||||
|
|
||||||
/* NOTE: Tile-relative X and Y. */
|
/* NOTE: Tile-relative X and Y. */
|
||||||
F32 TileRelX;
|
F32 TileRelX;
|
||||||
F32 TileRelY;
|
F32 TileRelY;
|
||||||
} cannonical_position;
|
} cannonical_position;
|
||||||
|
|
||||||
typedef struct tile_map {
|
typedef struct tile_chunk {
|
||||||
U32 *Tiles;
|
U32 *Tiles;
|
||||||
} tile_map;
|
} tile_chunk;
|
||||||
|
|
||||||
typedef struct world {
|
typedef struct world {
|
||||||
|
U32 ChunkShift;
|
||||||
|
U32 ChunkMask;
|
||||||
|
U32 ChunkDim;
|
||||||
|
|
||||||
F32 TileSideInMeters;
|
F32 TileSideInMeters;
|
||||||
S32 TileSideInPixels;
|
S32 TileSideInPixels;
|
||||||
F32 MetersToPixels;
|
F32 MetersToPixels;
|
||||||
|
|
||||||
S32 CountX;
|
S32 TileChunkCountX;
|
||||||
S32 CountY;
|
S32 TileChunkCountY;
|
||||||
|
|
||||||
F32 UpperLeftX;
|
tile_chunk *TileChunks;
|
||||||
F32 UpperLeftY;
|
|
||||||
|
|
||||||
S32 TileMapCountX;
|
|
||||||
S32 TileMapCountY;
|
|
||||||
|
|
||||||
tile_map *TileMaps;
|
|
||||||
} world;
|
} world;
|
||||||
|
|
||||||
typedef struct game_state {
|
typedef struct game_state {
|
||||||
|
|||||||
@@ -486,7 +486,6 @@ static U32 GetLastWriteTime(const char *FileName)
|
|||||||
memset(&file_info, 0, sizeof(file_info));
|
memset(&file_info, 0, sizeof(file_info));
|
||||||
if(stat(FileName, &file_info) != 0) {
|
if(stat(FileName, &file_info) != 0) {
|
||||||
/* TODO: Diagnostic. perror("stat failed"); */
|
/* TODO: Diagnostic. perror("stat failed"); */
|
||||||
perror("stat failed");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (U32)file_info.st_mtime;
|
return (U32)file_info.st_mtime;
|
||||||
|
|||||||
Reference in New Issue
Block a user