diff options
author | Raymaekers Luca <luca@spacehb.net> | 2025-08-14 07:14:25 +0200 |
---|---|---|
committer | Raymaekers Luca <luca@spacehb.net> | 2025-08-14 07:14:25 +0200 |
commit | 847a55b2b5f7150fad5cedd6899708df94ba7ee5 (patch) | |
tree | 723f12bbca0e145aa95b6c14c3431f5e5f5ecfbe /code | |
parent | 2445ab8aa5bcad6dfd234bc57ef16f5ebbad1b04 (diff) |
checkpoint
Diffstat (limited to 'code')
-rwxr-xr-x | code/build.sh | 62 | ||||
-rw-r--r-- | code/handmade.cpp | 69 | ||||
-rw-r--r-- | code/handmade.h | 1 | ||||
m--------- | code/libs/linuxhmh | 0 |
4 files changed, 102 insertions, 30 deletions
diff --git a/code/build.sh b/code/build.sh index e6c0b5f..e083327 100755 --- a/code/build.sh +++ b/code/build.sh @@ -5,11 +5,63 @@ cd "$ThisDir" mkdir ../build > /dev/null 2>&1 -CompilerFlags="-ggdb -DHANDMADE_SLOW -DHANDMADE_INTERNAL" -WarningFlags="-Wall -Wextra -Wno-unused-but-set-variable -Wno-unused-variable -Wno-write-strings -Wno-unused-parameter -Wno-unused-function" +# Supported: clang, g++ +Compiler="clang" -printf 'handmade.cpp\n' -g++ $CompilerFlags $WarningFlags -shared -o ../build/handmade.so handmade.cpp +CompilerFlags=" +-O0 +-ggdb +-DHANDMADE_INTERNAL +-DHANDMADE_SLOW +-DOS_LINUX +-nostdinc++ +" + +WarningFlags="-Wall +-Wextra +-Wno-unused-but-set-variable +-Wno-unused-variable +-Wno-write-strings +-Wno-pointer-arith +-Wno-unused-parameter +-Wno-unused-function" + +ClangCompilerFlags=" +-ftime-trace +" +ClangWarningFlags=" +-Wno-null-dereference +-Wno-missing-braces +-Wno-vla-cxx-extension +-Wno-writable-strings +" + +# Platform specific linker flags +LinuxLinkerFlags=" +-lpthread +-lasound +-lm +-lX11 +-lXfixes" + +if [ "$Compiler" = "clang" ] +then + CompilerFlags="$CompilerFlags $ClangCompilerFlags" + WarningFlags="$WarningFlags $ClangWarningFlags" +fi printf 'linux_handmade.cpp\n' -g++ $CompilerFlags $WarningFlags -o ../build/linux_handmade libs/linuxhmh/linux_handmade.cpp -lasound -lm -lX11 -lXfixes +$Compiler \ + $CompilerFlags \ + $WarningFlags \ + -o ../build/linux_handmade \ + $LinuxLinkerFlags \ + libs/linuxhmh/linux_handmade.cpp + +printf 'handmade.cpp\n' +$Compiler \ + $CompilerFlags \ + $WarningFlags \ + -shared \ + -o ../build/handmade.so \ + handmade.cpp diff --git a/code/handmade.cpp b/code/handmade.cpp index b29be68..d272abb 100644 --- a/code/handmade.cpp +++ b/code/handmade.cpp @@ -2,14 +2,13 @@ #include "handmade_random.h" #include "handmade_graph.cpp" -#if 1 #define STB_TRUETYPE_IMPLEMENTATION #include "libs/stb_truetype.h" -#endif // TODO(luca): Get rid of these. #include <time.h> #include <stdio.h> +#include <stdlib.h> internal s16 GetSineSound(u32 SampleRate) @@ -356,19 +355,23 @@ DrawCharacter(game_offscreen_buffer *Buffer, u8 *FontBitmap, X++) { u8 Brightness = FontBitmap[Y*FontWidth+X]; - if(Brightness > 0) - { - u32 Value = ((0xFF << 24) | - ((u32)(Color.R*Brightness) << 16) | - ((u32)(Color.G*Brightness) << 8) | - ((u32)(Color.B*Brightness) << 0)); - *Pixel++ = Value; - } - else - { - Pixel++; - } + r32 Alpha = ((r32)Brightness/255.0f); + + r32 DR = (r32)((*Pixel >> 16) & 0xFF); + r32 DG = (r32)((*Pixel >> 8) & 0xFF); + r32 DB = (r32)((*Pixel >> 0) & 0xFF); + + r32 R = Color.R*255.0f*Alpha + DR*(1-Alpha); + r32 G = Color.G*255.0f*Alpha + DG*(1-Alpha); + r32 B = Color.B*255.0f*Alpha + DB*(1-Alpha); + + u32 Value = ((0xFF << 24) | + ((u32)(R) << 16) | + ((u32)(G) << 8) | + ((u32)(B) << 0)); + *Pixel++ = Value; } + Row += Buffer->Pitch; } } @@ -494,7 +497,7 @@ GetTodaysWordle(thread_context *Thread, game_memory *Memory, char *Word) while(OutputBuffer[Scan] != '"' && Scan < BytesOutputted) Scan++; End = Scan; - memcpy(Word, OutputBuffer+Start, End-Start); + MemCpy(Word, OutputBuffer+Start, End-Start); } } @@ -588,8 +591,24 @@ extern "C" GAME_UPDATE_AND_RENDER(GameUpdateAndRender) InputIndex < Controller->Keyboard.TextInputCount; InputIndex++) { - rune Codepoint = Controller->Keyboard.TextInputBuffer[InputIndex].Codepoint; - AppendCharToInputText(GameState, Codepoint); + game_text_button Button = Controller->Keyboard.TextInputBuffer[InputIndex]; + if(0) {} + else if(Button.Codepoint == 'u' && Button.Control) + { + GameState->TextInputCount = 0; + } + else if(Button.Codepoint == 'd' && Button.Control) + { + if(GameState->TextInputCount) + { + GameState->TextInputCount--; + } + } + else + { + AppendCharToInputText(GameState, Button.Codepoint); + } + } if(WasPressed(Input->MouseButtons[PlatformMouseButton_ScrollUp])) @@ -834,7 +853,7 @@ extern "C" GAME_UPDATE_AND_RENDER(GameUpdateAndRender) #if 1 { r32 FontScale = stbtt_ScaleForPixelHeight(&GameState->FontInfo, 20.0f); - color_rgb Color = {1.0f, 0.0f, 0.5f}; + v2 Offset = {100.0f, 30.0f}; r32 TextHeight = FontScale*(GameState->FontAscent - @@ -856,25 +875,25 @@ extern "C" GAME_UPDATE_AND_RENDER(GameUpdateAndRender) v2 Min = {Offset.X, Offset.Y - Baseline}; v2 Max = {Offset.X + TextWidth, Min.Y + TextHeight}; - color_rgb ColorWhite = {1.0f, 1.0f, 1.0f}; - color_rgb ColorBlue = {0.2f, 0.0f, 1.0f}; + color_rgb ColorBorder = {0.017f, 0.017f, 0.017f}; + color_rgb ColorBG = {0.007f, 0.007f, 0.007f}; + color_rgb ColorFG = {0.682f, 0.545f, 0.384f}; - DrawRectangle(Buffer, Min + -1, Max + 1, ColorBlue); - DrawRectangle(Buffer, Min, Max, ColorWhite); + DrawRectangle(Buffer, Min + -1, Max + 1, ColorBorder); + DrawRectangle(Buffer, Min, Max, ColorBG); DrawText(GameState, Buffer, FontScale, GameState->TextInputText, GameState->TextInputCount, - Offset, Color); + Offset, ColorFG); Assert(GameState->TextInputCount < ArrayCount(GameState->TextInputText)); } #endif - } extern "C" GAME_GET_SOUND_SAMPLES(GameGetSoundSamples) { game_state *GameState = (game_state *)Memory->PermanentStorage; GameOutputSound(GameState, SoundBuffer); -}
\ No newline at end of file +} diff --git a/code/handmade.h b/code/handmade.h index 30daa99..b844fd8 100644 --- a/code/handmade.h +++ b/code/handmade.h @@ -10,6 +10,7 @@ #include "libs/linuxhmh/handmade_platform.h" #include "handmade_math.h" +#undef STB_TRUETYPE_IMPLEMENTATION #include "libs/stb_truetype.h" #define WORDLE_LENGTH 5 diff --git a/code/libs/linuxhmh b/code/libs/linuxhmh -Subproject 2a383443b4a9f1b1c8060fef5dd2166bd597c2d +Subproject 081734498164749afab5791efb55298c4ad3d97 |