diff --git a/src/test.cpp b/src/test.cpp deleted file mode 100644 index c981900..0000000 --- a/src/test.cpp +++ /dev/null @@ -1,86 +0,0 @@ -#include "handmade.h" - -#define PI32 3.141592653589f - -void debug_printf(wchar_t* format, ...) { - size_t bufsize = wcslen(format)*10; - wchar_t *output = (wchar_t*)malloc(bufsize); - va_list list; - va_start(list, format); - vswprintf(output, bufsize, format, list); - OutputDebugStringW(output); - free(output); -} - -internal void outputSineSound(GameSoundOutputBuffer *soundBuffer, GameState *state) { - int16 toneVolume = 3000; - int wavePeriod = soundBuffer->samplesPerSecond/state->toneHz; - - int16 *sampleOut = soundBuffer->samples; - for (int sampleIndex = 0; sampleIndex < soundBuffer->sampleCount; sampleIndex++) { - int16 sampleValue = (int16)(sin(state->tSine) * (real32)toneVolume); - *sampleOut++ = sampleValue; - *sampleOut++ = sampleValue; - state->tSine += 2.0f * PI32 / (real32)wavePeriod; - } -} - -internal void renderWeirdGradient(GameOffscreenBuffer *buffer, int xOffset, int yOffset) { - int bytesPerPixel = 4; - int pitch = buffer->width*bytesPerPixel; - uint8 *row = (uint8 *)buffer->memory; - for (int y = 0; y < buffer->height; y++) { - uint32 *pixel = (uint32*)row; - for (int x = 0; x < buffer->width; x++) { - uint8 blue = (uint8)(x + xOffset); - uint8 green = (uint8)(y + yOffset); - *pixel++ = (green << 8) | blue; - } - row += pitch; - } -} - -internal void gameUpdateAndRender(GameMemory *memory, GameOffscreenBuffer *videoBuf, GameInput *input, GameSoundOutputBuffer *soundBuf) { - Assert(sizeof(GameState) <= memory->permanentStorageSize); - - GameState *state = (GameState*)memory->permanentStorage; - - if (!memory->isInitialised) { - DebugReadFileResult bmpMem = DEBUG_platformReadEntireFile(__FILE__); - if (bmpMem.contents) { - DEBUG_platformWriteEntireFile("c:/source/repos/handmade/src/test.cpp", bmpMem.contentsSize, bmpMem.contents); - DEBUG_platformFreeFileMemory(bmpMem.contents); - } - - state->toneHz = 440; - state->tSine = 0; - memory->isInitialised = true; - } - - for (int controllerIndex = 0; controllerIndex < ArrayCount(input->controllers); controllerIndex++) { - GameControllerInput *controllerInput = &input->controllers[controllerIndex]; - if (controllerInput->isAnalog) { - //state->toneHz = 440 + (int)(128.0f*controllerInput->stickAvgX); - //state->greenOffset -= (int)(4.0f*controllerInput->stickAvgX); - //state->blueOffset += (int)(4.0f*controllerInput->stickAvgY); - } else { - if (controllerInput->stickRight.endedDown) { - state->toneHz = 440 + 128; - state->greenOffset -= 4; - } else if (controllerInput->stickLeft.endedDown) { - state->toneHz = 440 - 128; - state->greenOffset += 4; - } else { - state->toneHz = 440; - } - if (controllerInput->stickUp.endedDown) { - state->blueOffset += 4; - } else if (controllerInput->stickDown.endedDown) { - state->blueOffset -= 4; - } - } - } - - outputSineSound(soundBuf, state); - renderWeirdGradient(videoBuf, state->greenOffset, state->blueOffset); -}