update
This commit is contained in:
@@ -16,8 +16,8 @@ set commonCompilerFlags=^
|
|||||||
|
|
||||||
pushd .\build
|
pushd .\build
|
||||||
|
|
||||||
cl %commonCompilerFlags% -Fe:handmade.dll ..\src\handmade.cpp -Fmhandmade.map /link /DLL /EXPORT:gameGetSoundSamples /EXPORT:gameUpdateAndRender
|
cl %commonCompilerFlags% ..\src\handmade.cpp -Fmhandmade.map -LD /link -incremental:no -EXPORT:gameGetSoundSamples -EXPORT:gameUpdateAndRender
|
||||||
cl %commonCompilerFlags% -Fe:handmade_win32.exe ..\src\win32_handmade.cpp -Fmwin32_handmade.map /link %commonLinkerFlags%
|
cl %commonCompilerFlags% -Fe:handmade_win32.exe ..\src\win32_handmade.cpp -Fmwin32_handmade.map /link -incremental:no %commonLinkerFlags%
|
||||||
popd
|
popd
|
||||||
exit /b
|
exit /b
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ internal void renderWeirdGradient(GameOffscreenBuffer *buffer, int xOffset, int
|
|||||||
for (int x = 0; x < buffer->width; x++) {
|
for (int x = 0; x < buffer->width; x++) {
|
||||||
uint8 blue = (uint8)(x + xOffset);
|
uint8 blue = (uint8)(x + xOffset);
|
||||||
uint8 green = (uint8)(y + yOffset);
|
uint8 green = (uint8)(y + yOffset);
|
||||||
*pixel++ = (green << 16) | blue;
|
*pixel++ = (green << 8) | blue;
|
||||||
}
|
}
|
||||||
row += pitch;
|
row += pitch;
|
||||||
}
|
}
|
||||||
@@ -77,11 +77,3 @@ extern "C" GAME_UPDATE_AND_RENDER(gameUpdateAndRender) {
|
|||||||
extern "C" GAME_GET_SOUND_SAMPLES(gameGetSoundSamples) {
|
extern "C" GAME_GET_SOUND_SAMPLES(gameGetSoundSamples) {
|
||||||
outputSineSound(soundBuf, (GameState*)memory->permanentStorage);
|
outputSineSound(soundBuf, (GameState*)memory->permanentStorage);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if HANDMADE_WIN32
|
|
||||||
#include "windows.h"
|
|
||||||
|
|
||||||
BOOL DllMain() {
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -143,13 +143,27 @@ struct Win32GameCode {
|
|||||||
GameUpdateAndRenderFn *updateAndRender;
|
GameUpdateAndRenderFn *updateAndRender;
|
||||||
GameGetSoundSamplesFn *getSoundSamples;
|
GameGetSoundSamplesFn *getSoundSamples;
|
||||||
bool isValid;
|
bool isValid;
|
||||||
|
FILETIME lastWriteTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
internal Win32GameCode win32LoadGameCode() {
|
inline FILETIME win32GetLastWriteTime(char *filename) {
|
||||||
|
FILETIME lastWriteTime = {};
|
||||||
|
WIN32_FIND_DATA findData;
|
||||||
|
HANDLE findHandle = FindFirstFileA(filename, &findData);
|
||||||
|
if (findHandle != INVALID_HANDLE_VALUE) {
|
||||||
|
lastWriteTime = findData.ftLastWriteTime;
|
||||||
|
FindClose(findHandle);
|
||||||
|
}
|
||||||
|
return lastWriteTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal Win32GameCode win32LoadGameCode(char *filename, char *tempname) {
|
||||||
Win32GameCode result = {};
|
Win32GameCode result = {};
|
||||||
|
|
||||||
CopyFile("handmade.dll", "handmade_temp.dll", FALSE);
|
result.lastWriteTime = win32GetLastWriteTime(filename);
|
||||||
HMODULE gameCodeLib = LoadLibrary("handmade_temp.dll");
|
|
||||||
|
CopyFile(filename, tempname, FALSE);
|
||||||
|
HMODULE gameCodeLib = LoadLibrary(tempname);
|
||||||
result.gameCodeLib = gameCodeLib;
|
result.gameCodeLib = gameCodeLib;
|
||||||
|
|
||||||
if (gameCodeLib) {
|
if (gameCodeLib) {
|
||||||
@@ -453,7 +467,38 @@ internal void win32DebugSyncDisplay(Win32OffscreenBuffer *screenBuffer, int mark
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void catStrings(size_t sourceACount, char *sourceA, size_t sourceBCount, char *sourceB, size_t destCount, char *dest) {
|
||||||
|
for (int i = 0; i < sourceACount; i++) {
|
||||||
|
*dest++ = *sourceA++;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < sourceBCount; i++) {
|
||||||
|
*dest++ = *sourceB++;
|
||||||
|
}
|
||||||
|
*dest++ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
int APIENTRY WinMain(HINSTANCE instance, HINSTANCE prevInstance, PSTR commandLine, int commandShow) {
|
int APIENTRY WinMain(HINSTANCE instance, HINSTANCE prevInstance, PSTR commandLine, int commandShow) {
|
||||||
|
char exeFileName[MAX_PATH];
|
||||||
|
DWORD sizeOfFilename = GetModuleFileNameA(NULL, exeFileName, sizeof(exeFileName));
|
||||||
|
char *onePastLastSlash = exeFileName;
|
||||||
|
for (char *scan = exeFileName; *scan; scan++) {
|
||||||
|
if (*scan == '\\') {
|
||||||
|
onePastLastSlash = scan + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char sourceGameCodeDLLFilename[] = "handmade.dll";
|
||||||
|
char sourceGameCodeDLLFullPath[MAX_PATH];
|
||||||
|
catStrings(onePastLastSlash - exeFileName, exeFileName,
|
||||||
|
sizeof(sourceGameCodeDLLFilename) - 1, sourceGameCodeDLLFilename,
|
||||||
|
sizeof(sourceGameCodeDLLFullPath) - 1, sourceGameCodeDLLFullPath);
|
||||||
|
|
||||||
|
char tempGameCodeDLLFilename[] = "handmade_temp.dll";
|
||||||
|
char tempGameCodeDLLFullPath[MAX_PATH];
|
||||||
|
catStrings(onePastLastSlash - exeFileName, exeFileName,
|
||||||
|
sizeof(tempGameCodeDLLFilename) - 1, tempGameCodeDLLFilename,
|
||||||
|
sizeof(tempGameCodeDLLFullPath) - 1, tempGameCodeDLLFullPath);
|
||||||
|
|
||||||
LARGE_INTEGER performanceFrequencyResult;
|
LARGE_INTEGER performanceFrequencyResult;
|
||||||
QueryPerformanceFrequency(&performanceFrequencyResult);
|
QueryPerformanceFrequency(&performanceFrequencyResult);
|
||||||
globalPerfCountFrequency = performanceFrequencyResult.QuadPart;
|
globalPerfCountFrequency = performanceFrequencyResult.QuadPart;
|
||||||
@@ -506,7 +551,7 @@ int APIENTRY WinMain(HINSTANCE instance, HINSTANCE prevInstance, PSTR commandLin
|
|||||||
soundOutput.runningSampleIndex = 0;
|
soundOutput.runningSampleIndex = 0;
|
||||||
soundOutput.bytesPerSample = sizeof(int16)*2;
|
soundOutput.bytesPerSample = sizeof(int16)*2;
|
||||||
soundOutput.secondaryBufferSize = soundOutput.samplesPerSecond*soundOutput.bytesPerSample;
|
soundOutput.secondaryBufferSize = soundOutput.samplesPerSecond*soundOutput.bytesPerSample;
|
||||||
soundOutput.safetyBytes = (soundOutput.samplesPerSecond * soundOutput.bytesPerSample / gameUpdateHz) / 3;
|
soundOutput.safetyBytes = (soundOutput.samplesPerSecond * soundOutput.bytesPerSample / gameUpdateHz) / 2;
|
||||||
|
|
||||||
int16 *samples = (int16*)VirtualAlloc(NULL, soundOutput.secondaryBufferSize, MEM_COMMIT, PAGE_READWRITE);
|
int16 *samples = (int16*)VirtualAlloc(NULL, soundOutput.secondaryBufferSize, MEM_COMMIT, PAGE_READWRITE);
|
||||||
|
|
||||||
@@ -539,16 +584,14 @@ int APIENTRY WinMain(HINSTANCE instance, HINSTANCE prevInstance, PSTR commandLin
|
|||||||
real32 audioLatencySeconds = 0;
|
real32 audioLatencySeconds = 0;
|
||||||
bool soundIsValid = false;
|
bool soundIsValid = false;
|
||||||
|
|
||||||
Win32GameCode game = win32LoadGameCode();
|
Win32GameCode game = win32LoadGameCode(sourceGameCodeDLLFullPath, tempGameCodeDLLFullPath);
|
||||||
uint32 loadCounter = 0;
|
|
||||||
|
|
||||||
int64 lastCycleCount = __rdtsc();
|
int64 lastCycleCount = __rdtsc();
|
||||||
while (globalRunning) {
|
while (globalRunning) {
|
||||||
if (loadCounter++ > 60) {
|
FILETIME newWriteTime = win32GetLastWriteTime(sourceGameCodeDLLFullPath);
|
||||||
|
if (CompareFileTime(&newWriteTime, &game.lastWriteTime) != 0) {
|
||||||
win32UnloadGameCode(&game);
|
win32UnloadGameCode(&game);
|
||||||
game = win32LoadGameCode();
|
game = win32LoadGameCode(sourceGameCodeDLLFullPath, tempGameCodeDLLFullPath);
|
||||||
loadCounter = 0;
|
|
||||||
// TODO(dledda): handmade hero episode 22 (from the beginning)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GameControllerInput *oldKeyboardController = &oldInput->controllers[0];
|
GameControllerInput *oldKeyboardController = &oldInput->controllers[0];
|
||||||
|
|||||||
Reference in New Issue
Block a user