diff options
author | Raymaekers Luca <luca@spacehb.net> | 2025-07-10 14:18:19 +0200 |
---|---|---|
committer | Raymaekers Luca <luca@spacehb.net> | 2025-07-10 14:18:19 +0200 |
commit | e239c0a12909e434efc1854d8992df145c567e4a (patch) | |
tree | c8fc9192c9a6a04e2af47228eeea16ca55094306 /code | |
parent | 71baed6f2ceb93ee8b3830b3049ad9487e5de234 (diff) |
checkpoint
Diffstat (limited to 'code')
-rw-r--r-- | code/handmade.cpp | 47 | ||||
-rw-r--r-- | code/handmade.h | 5 | ||||
-rw-r--r-- | code/handmade_platform.h | 3 | ||||
-rw-r--r-- | code/linux_handmade.cpp | 39 |
4 files changed, 47 insertions, 47 deletions
diff --git a/code/handmade.cpp b/code/handmade.cpp index 41155cd..15abc6e 100644 --- a/code/handmade.cpp +++ b/code/handmade.cpp @@ -9,7 +9,6 @@ #if HANDMADE_INTERNAL #include <stdio.h> -#define NoOp { int X = 3; } #endif internal s16 @@ -373,7 +372,6 @@ DrawText(game_state *GameState, game_offscreen_buffer *Buffer, r32 FontScale, char *Text, u32 TextLen, v2 Offset, color_rgb Color) { - for(u32 TextIndex = 0; TextIndex < TextLen; TextIndex++) @@ -401,7 +399,6 @@ DrawText(game_state *GameState, game_offscreen_buffer *Buffer, Offset.X += (AdvanceWidth*FontScale); free(FontBitmap); } - } internal b32 @@ -440,7 +437,7 @@ extern "C" GAME_UPDATE_AND_RENDER(GameUpdateAndRender) if(!Memory->IsInitialized) { - debug_read_file_result File = Memory->DEBUGPlatformReadEntireFile(Thread, "data/font.ttf"); + debug_read_file_result File = Memory->DEBUGPlatformReadEntireFile(Thread, "../data/font.ttf"); if(stbtt_InitFont(&GameState->FontInfo, (u8 *)File.Contents, stbtt_GetFontOffsetForIndex((u8 *)File.Contents, 0))) { GameState->FontInfo.data = (u8 *)File.Contents; @@ -451,8 +448,6 @@ extern "C" GAME_UPDATE_AND_RENDER(GameUpdateAndRender) GameState->FontBoundingBox[0] = v2{(r32)X0, (r32)Y0}; GameState->FontBoundingBox[1] = v2{(r32)X1, (r32)Y1}; stbtt_GetFontVMetrics(&GameState->FontInfo, &GameState->FontAscent, &GameState->FontDescent, &GameState->FontLineGap); - - } else { @@ -460,6 +455,7 @@ extern "C" GAME_UPDATE_AND_RENDER(GameUpdateAndRender) } GameState->SelectedColor = SquareColor_Yellow; + GameState->ExportedPatternIndex = 0; Memory->IsInitialized = true; } @@ -471,7 +467,6 @@ extern "C" GAME_UPDATE_AND_RENDER(GameUpdateAndRender) game_controller_input *Controller = GetController(Input, ControllerIndex); if(Controller->IsConnected) { - if(Controller->IsAnalog) { @@ -483,25 +478,12 @@ extern "C" GAME_UPDATE_AND_RENDER(GameUpdateAndRender) GameState->SelectedColor = (GameState->SelectedColor < SquareColor_Count- 1) ? GameState->SelectedColor + 1: 0; } - } } } - - - char Text[256] = {}; - int TextLen = 0; - - r32 FontScale = 0.0f; - r32 YAdvance = 0.0f; - r32 Baseline = 0.0f; - v2 TextOffset = {}; - int AdvanceWidth = 0; - Assert(GameState->SelectedColor < SquareColor_Count); r32 Width = 48.0f; - v2 Min = {0.0f, 0.0f}; v2 Max = {Width, Width}; v2 Padding = {2.0f, 2.0f}; @@ -509,12 +491,11 @@ extern "C" GAME_UPDATE_AND_RENDER(GameUpdateAndRender) color_rgb ColorGray = {0.23f, 0.23f, 0.24f}; color_rgb ColorYellow = {0.71f, 0.62f, 0.23f}; color_rgb ColorGreen = {0.32f, 0.55f, 0.31f}; - s32 Rows = 6; s32 Columns = 5; + Base.X = 0.5f*(Buffer->Width - Columns*Width); Base.Y = 0.5f*(Buffer->Height - Rows*Width); - s32 SelectedX = CeilReal32ToInt32((r32)(Input->MouseX - Base.X)/(r32)(Width + Padding.X)) - 1; s32 SelectedY = CeilReal32ToInt32((r32)(Input->MouseY - Base.Y)/(r32)(Width + Padding.Y)) - 1; @@ -587,6 +568,14 @@ extern "C" GAME_UPDATE_AND_RENDER(GameUpdateAndRender) Min.Y += Padding.Y + Width; } + char Text[256] = {}; + int TextLen = 0; + r32 FontScale = 0.0f; + r32 YAdvance = 0.0f; + r32 Baseline = 0.0f; + v2 TextOffset = {}; + int AdvanceWidth = 0; + // Prepare drawing of the guesses. FontScale = stbtt_ScaleForPixelHeight(&GameState->FontInfo, 24.0f); YAdvance = FontScale*(GameState->FontAscent - @@ -596,18 +585,16 @@ extern "C" GAME_UPDATE_AND_RENDER(GameUpdateAndRender) TextOffset = v2{16.0f, 16.0f + Baseline}; { - char Text[] = "\"novel\""; + char Text[] = "\"jumpy\""; int TextLen = sizeof(Text) - 1; - DrawText(GameState, Buffer, FontScale, Text, TextLen, TextOffset + -v2{8.0f, 0.0f}, ColorGreen); + DrawText(GameState, Buffer, FontScale, Text, TextLen, TextOffset + -v2{8.0f, 0.0f}, ColorYellow); } TextOffset.Y += YAdvance*2.0f; - //-Matche the pattern - - char *Word = "novel"; - debug_read_file_result File = Memory->DEBUGPlatformReadEntireFile(Thread, "data/words.txt"); + char *Word = "jumpy"; + debug_read_file_result File = Memory->DEBUGPlatformReadEntireFile(Thread, "../data/words.txt"); int WordsCount = File.ContentsSize / WORDLE_LENGTH; if(File.Contents) @@ -706,11 +693,9 @@ extern "C" GAME_UPDATE_AND_RENDER(GameUpdateAndRender) PatternRowAt++; } } - - //-Display the words - } + Memory->DEBUGPlatformFreeFileMemory(Thread, File.Contents, File.ContentsSize); } diff --git a/code/handmade.h b/code/handmade.h index 3cb98e1..59d3330 100644 --- a/code/handmade.h +++ b/code/handmade.h @@ -76,15 +76,14 @@ struct color_rgb struct game_state { u32 PatternGrid[6][5]; - - u32 SelectedColor;; + u32 SelectedColor; + u32 ExportedPatternIndex; stbtt_fontinfo FontInfo; s32 FontAscent; s32 FontDescent; s32 FontLineGap; v2 FontBoundingBox[2]; - }; #define HANDMADE_H diff --git a/code/handmade_platform.h b/code/handmade_platform.h index 64716a7..4cdf388 100644 --- a/code/handmade_platform.h +++ b/code/handmade_platform.h @@ -59,6 +59,9 @@ extern "C" { #define Assert(Expression) #endif +#define NullExpression { int X = 4; } + + #define Kilobytes(Value) ((Value)*1024LL) #define Megabytes(Value) (Kilobytes(Value)*1024LL) #define Gigabytes(Value) (Megabytes(Value)*1024LL) diff --git a/code/linux_handmade.cpp b/code/linux_handmade.cpp index fce276f..bf33f72 100644 --- a/code/linux_handmade.cpp +++ b/code/linux_handmade.cpp @@ -329,10 +329,8 @@ internal void LinuxProcessKeyPress(game_button_state *ButtonState, b32 IsDown) internal void LinuxBeginRecordingInput(linux_state *State, int SlotIndex) { - char Temp[64]; - sprintf(Temp, "loop_edit_%d.hmi", SlotIndex); - char FileName[PATH_MAX] = {}; - LinuxBuildFileNameFromExecutable(FileName, State, Temp); + char FileName[64]; + sprintf(FileName, "loop_edit_%d.hmi", SlotIndex); int File = open(FileName, O_WRONLY|O_CREAT|O_TRUNC|O_APPEND, 0600); if(State->InputRecordingFile != -1) @@ -376,10 +374,8 @@ internal void LinuxEndRecordingInput(linux_state *State, int SlotIndex) internal void LinuxBeginInputPlayBack(linux_state *State, int SlotIndex) { - char Temp[64]; - sprintf(Temp, "loop_edit_%d.hmi", SlotIndex); - char FileName[PATH_MAX] = {}; - LinuxBuildFileNameFromExecutable(FileName, State, Temp); + char FileName[64]; + sprintf(FileName, "loop_edit_%d.hmi", SlotIndex); int File = open(FileName, O_RDONLY, 0400); if(File != -1) @@ -723,6 +719,27 @@ void LinuxDebugVerticalLine(game_offscreen_buffer *Buffer, int X, int Y, u32 Col int main(int ArgC, char *Args[]) { + // NOTE(luca): Change to executable's current directory such that file paths are relative to that in the game code. + char *ExePath = Args[0]; + int Length = StrLen(ExePath); + char ExecutableDirPath[Length]; + int LastSlash = 0; + for(int At = 0; + At < Length; + At++) + { + if(ExePath[At] == '/') + { + LastSlash = At; + } + } + MemCpy(ExecutableDirPath, ExePath, LastSlash); + ExecutableDirPath[LastSlash] = 0; + if(chdir(ExecutableDirPath) == -1) + { + // TODO(luca): Logging + } + Display *DisplayHandle = XOpenDisplay(0); if(DisplayHandle) @@ -774,13 +791,10 @@ int main(int ArgC, char *Args[]) XImage *WindowImage = XCreateImage(DisplayHandle, WindowVisualInfo.visual, WindowVisualInfo.depth, ZPixmap, 0, WindowBuffer, Width, Height, BitsPerPixel, 0); GC DefaultGC = DefaultGC(DisplayHandle, Screen); - linux_state LinuxState = {}; MemCpy(LinuxState.ExecutablePath, Args[0], strlen(Args[0])); - char LibraryFullPath[PATH_MAX] = {}; - char LibraryName[] = "handmade.so"; - LinuxBuildFileNameFromExecutable(LibraryFullPath, &LinuxState, LibraryName); + char LibraryFullPath[] = "handmade.so"; linux_game_code Game = LinuxLoadGameCode(LibraryFullPath); Game.LibraryLastWriteTime = LinuxGetLastWriteTime(LibraryFullPath); @@ -797,7 +811,6 @@ int main(int ArgC, char *Args[]) #else void *BaseAddress = 0; #endif - // TODO(casey): TransientStorage needs to be broken into game transient and cache transient LinuxState.TotalSize = GameMemory.PermanentStorageSize + GameMemory.TransientStorageSize; LinuxState.GameMemoryBlock = mmap(BaseAddress, LinuxState.TotalSize, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_SHARED, -1, 0); |