Update dqn with CPP api for memstacks

This commit is contained in:
Doyle Thai 2017-06-23 19:03:36 +10:00
parent 26e6892d64
commit 54c6abd9d7
5 changed files with 903 additions and 454 deletions

View File

@ -935,8 +935,9 @@ extern "C" void DTR_Update(PlatformRenderBuffer *const platformRenderBuffer,
if (DTR_DEBUG)
{
DTRDebug_TestMeshFaceAndVertexParser(&state->mesh);
auto memRegion = DqnMemStackTempRegionScoped(&memory->tempStack);
if (memRegion.isInit)
bool regionValid;
auto memRegion = DqnMemStackTempRegionScoped(&memory->tempStack, &regionValid);
if (regionValid)
{
DTRBitmap test = {};
DTRAsset_LoadBitmap(input->api, assetStack, &memory->tempStack, &test,
@ -947,8 +948,9 @@ extern "C" void DTR_Update(PlatformRenderBuffer *const platformRenderBuffer,
}
{
auto tempMemRegion = DqnMemStackTempRegionScoped(&memory->tempStack);
if (tempMemRegion.isInit)
bool regionValid;
auto tempMemRegion = DqnMemStackTempRegionScoped(&memory->tempStack, &regionValid);
if (regionValid)
{
size_t debugSize = DQN_MEGABYTE(1);
u8 *debugMemory = (u8 *)DqnMemStack_Push(&memory->tempStack, debugSize);

View File

@ -634,8 +634,9 @@ bool DTRAsset_LoadFontToBitmap(const PlatformAPI api, DqnMemStack *const memStac
stbtt_pack_context fontPackContext = {};
bool result = false;
auto tmpMemRegion = DqnMemStackTempRegionScoped(tmpMemStack);
if (!tmpMemRegion.isInit)
bool regionValid;
auto tmpMemRegion = DqnMemStackTempRegionScoped(tmpMemStack, &regionValid);
if (!regionValid)
{
// TODO(doyle): Logging
DQN_ASSERT(DQN_INVALID_CODE_PATH);
@ -766,13 +767,7 @@ bool DTRAsset_LoadBitmap(const PlatformAPI api, DqnMemStack *const memStack,
if (!api.FileOpen(path, &file, PlatformFilePermissionFlag_Read, PlatformFileAction_OpenOnly))
return result;
auto tmpMemRegion = DqnMemStackTempRegionScoped(tempStack);
if (!tmpMemRegion.isInit)
{
// TODO(doyle): Logging
DQN_ASSERT(DQN_INVALID_CODE_PATH);
goto cleanup;
}
DqnMemStackTempRegionScoped tmpMemRegion = tempStack->TempRegionScoped();
u8 *const rawData = (u8 *)DqnMemStack_Push(tempStack, file.size);
size_t bytesRead = api.FileRead(&file, rawData, file.size);

View File

@ -77,8 +77,9 @@ void DTRDebug_DumpZBuffer(DTRRenderBuffer *const renderBuffer, DqnMemStack *cons
}
}
auto memRegion = DqnMemStackTempRegionScoped(tempStack);
if (memRegion.isInit)
bool regionValid;
auto memRegion = DqnMemStackTempRegionScoped(tempStack, &regionValid);
if (regionValid)
{
size_t bufSize = DQN_MEGABYTE(16);
char *bufString = (char *)DqnMemStack_Push(tempStack, bufSize);

View File

@ -1,3 +1,6 @@
#define UNICODE
#define _UNICODE
#include "DTRenderer.h"
#include "DTRendererPlatform.h"
@ -5,9 +8,6 @@
#define DQN_IMPLEMENTATION
#include "dqn.h"
#define UNICODE
#define _UNICODE
#include <Windows.h>
#include <Windowsx.h> // For GET_X|Y_LPARAM(), mouse input
#include <Psapi.h> // For win32 GetProcessMemoryInfo()
@ -176,7 +176,7 @@ FILE_SCOPE inline DqnFile PlatformFileToDqnFileInternal(const PlatformFile file)
void Platform_Print(const char *const string)
{
if (!string) return;
OutputDebugString(string);
OutputDebugStringA(string);
}
bool Platform_FileOpen(const char *const path, PlatformFile *const file, const u32 permissionFlags,
@ -287,7 +287,7 @@ FILETIME Win32GetLastWriteTime(const char *const srcName)
{
FILETIME lastWriteTime = {};
WIN32_FILE_ATTRIBUTE_DATA attribData = {};
if (GetFileAttributesEx(srcName, GetFileExInfoStandard, &attribData) != 0)
if (GetFileAttributesExA(srcName, GetFileExInfoStandard, &attribData) != 0)
{
lastWriteTime = attribData.ftLastWriteTime;
}
@ -301,7 +301,7 @@ FILE_SCOPE Win32ExternalCode Win32LoadExternalDLL(const char *const srcPath,
{
Win32ExternalCode result = {};
result.lastWriteTime = lastWriteTime;
CopyFile(srcPath, tmpPath, false);
CopyFileA(srcPath, tmpPath, false);
DTR_UpdateFunction *updateFunction = NULL;
result.dll = LoadLibraryA(tmpPath);
@ -332,10 +332,10 @@ FILE_SCOPE void Win32CreateMenu(HWND window)
HMENU menuBar = CreateMenu();
{ // File Menu
HMENU menu = CreatePopupMenu();
AppendMenu(menuBar, MF_STRING | MF_POPUP, (UINT_PTR)menu, "File");
AppendMenu(menu, MF_STRING, Win32Menu_FileOpen, "Open");
AppendMenu(menu, MF_STRING, Win32Menu_FileFlushMemory, "Flush Memory");
AppendMenu(menu, MF_STRING, Win32Menu_FileExit, "Exit");
AppendMenuA(menuBar, MF_STRING | MF_POPUP, (UINT_PTR)menu, "File");
AppendMenuA(menu, MF_STRING, Win32Menu_FileOpen, "Open");
AppendMenuA(menu, MF_STRING, Win32Menu_FileFlushMemory, "Flush Memory");
AppendMenuA(menu, MF_STRING, Win32Menu_FileExit, "Exit");
}
SetMenu(window, menuBar);
}
@ -774,7 +774,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
////////////////////////////////////////////////////////////////////////
// Update State
////////////////////////////////////////////////////////////////////////
f64 startFrameTimeInS = DqnTime_NowInS();
f64 startFrameTimeInS = DqnTimer_NowInS();
FILETIME lastWriteTime = Win32GetLastWriteTime(dllPath);
if (CompareFileTime(&lastWriteTime, &dllCode.lastWriteTime) != 0)
@ -785,7 +785,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
}
{
platformInput.timeNowInS = DqnTime_NowInS();
platformInput.timeNowInS = DqnTimer_NowInS();
platformInput.deltaForFrame = (f32)frameTimeInS;
Win32ProcessMessages(mainWindow, &platformInput);
@ -823,7 +823,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
// Frame Limiting
////////////////////////////////////////////////////////////////////////
{
f64 workTimeInS = DqnTime_NowInS() - startFrameTimeInS;
f64 workTimeInS = DqnTimer_NowInS() - startFrameTimeInS;
if (workTimeInS < targetSecondsPerFrame)
{
DWORD remainingTimeInMs =
@ -832,7 +832,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
}
}
frameTimeInS = DqnTime_NowInS() - startFrameTimeInS;
frameTimeInS = DqnTimer_NowInS() - startFrameTimeInS;
f32 msPerFrame = 1000.0f * (f32)frameTimeInS;
f32 framesPerSecond = 1.0f / (f32)frameTimeInS;

1259
src/dqn.h

File diff suppressed because it is too large Load Diff