Day 21 complete.

This commit is contained in:
2026-03-18 17:02:29 -07:00
parent b7cf0164c6
commit 92c5a75c05
3 changed files with 45 additions and 19 deletions
+10 -6
View File
@@ -3,20 +3,22 @@
#include <math.h>
static void GameOutputSound(game_sound_output_buffer *SoundBuffer, S32 ToneHz)
static void GameOutputSound(game_state *GameState, game_sound_output_buffer *SoundBuffer, S32 ToneHz)
{
static F32 tSine;
S16 ToneVolume = 8000;
S32 WavePeriod = SoundBuffer->SamplesPerSecond / ToneHz;
S16 *SampleOut = SoundBuffer->Samples;
for(S32 SampleIndex = 0; SampleIndex < SoundBuffer->SampleCount; SampleIndex++) {
F32 SineValue = sinf(tSine);
F32 SineValue = sinf(GameState->tSine);
S16 SampleValue = S16(SineValue * ToneVolume);
*SampleOut++ = SampleValue;
*SampleOut++ = SampleValue;
tSine += 2.0f * PI * 1.0f / (F32)WavePeriod;
GameState->tSine += 2.0f * (F32)PI * 1.0f / (F32)WavePeriod;
if(GameState->tSine > 2.0f*(F32)PI) {
GameState->tSine -= 2.0f*(F32)PI;
}
}
}
@@ -31,6 +33,7 @@ static void RenderWeirdGradient(game_offscreen_buffer *Buffer, S32 XOffset, S32
for(S32 X = 0; X < Width; X++) {
U8 Blue = (U8)(X + XOffset);
U8 Green = (U8)(Y + YOffset);
*Pixel = (Green << 8) | Blue;
Pixel++;
}
@@ -45,7 +48,7 @@ void UpdateAndRender(game_memory *Memory, game_input *Input, game_offscreen_buff
game_state *GameState = (game_state *)Memory->PermanentStorage;
if(!Memory->IsInitialized) {
char FileName[] = "/Users/igor/Developer/handmade_hero_course/handmade/code/sdl_handmade.cpp";
char FileName[] = "/home/igor/Developer/handmade/sdl_handmade.cpp";
debug_read_file_result BitmapMemory = Memory->DEBUGPlatformReadEntireFile(FileName);
if(BitmapMemory.Contents) {
Memory->DEBUGPlatformWriteEntireFile("test.out", BitmapMemory.ContentsSize, BitmapMemory.Contents);
@@ -53,6 +56,7 @@ void UpdateAndRender(game_memory *Memory, game_input *Input, game_offscreen_buff
}
GameState->ToneHz = 256;
GameState->tSine = 0.0f;
// TODO: Maybe more appropriate to do in the platform layer?
Memory->IsInitialized = true;
@@ -83,6 +87,6 @@ void UpdateAndRender(game_memory *Memory, game_input *Input, game_offscreen_buff
}
}
GameOutputSound(SoundBuffer, GameState->ToneHz);
GameOutputSound(GameState, SoundBuffer, GameState->ToneHz);
RenderWeirdGradient(Buffer, GameState->BlueOffset, GameState->GreenOffset);
}