Removed the 80 character column rule. Becoming impractical.
This commit is contained in:
+50
-107
@@ -9,9 +9,7 @@
|
||||
|
||||
#include <string.h> /* 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user