Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ add_library(ProjectDelta SHARED
"include/delta/definitions.h"
"src/delta/platform/os_internal.h"
"src/delta/platform/os_win32.cpp"
"include/delta/platform/os_types.h"
"include/delta/platform/os.h"
"include/delta/pch.h"
"src/delta/pch.h"
Expand All @@ -31,7 +32,7 @@ add_library(ProjectDelta SHARED
"src/delta/core/MemoryConfig.cpp"
"src/delta/core/Worker.h"
"src/delta/core/Worker.cpp"
)
"src/delta/platform/os_internal_types.h")

target_compile_definitions(ProjectDelta
PRIVATE DLT_EXPORT_SYMBOLS
Expand Down
2 changes: 2 additions & 0 deletions Engine/include/delta/core/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
*/

#include <delta/definitions.h>
#include <delta/platform/os_types.h>

namespace delta::Engine
{
struct Context
{
delta::platform::WindowHandle window;
bool isRunning;
};

Expand Down
37 changes: 12 additions & 25 deletions Engine/include/delta/platform/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,21 @@
*/

#pragma once
#include <delta/platform/os_types.h>

namespace delta::platform
{
struct OSInfo
{
const char* cpuArchitecture;

uint32_t cpuPhysicalCoreCount;
uint32_t cpuLogicalProcessorCount;
uint32_t osPageSize;

char cpuBrandString[sizeof(int) * 12 + 1];
char cpuManufacturerId[13];

bool cpuHasSMT;
bool cpuHasAVX2;
bool cpuHasAVX512f;
bool cpuHasAVX512cd;
bool cpuHasAVX512er;
bool cpuHasAVX512pf;
};

struct MemoryStatus
{
uint64_t physicalInstalled;
uint64_t physicalFree;
};

// General
// TODO: Change names to the adequate ones
DLT_API const OSInfo* getOSInfo() noexcept;
DLT_API MemoryStatus getMemoryStatus();

// Window API
DLT_API void Window_SetTitle(WindowHandle window, const char* newTitle);
DLT_API void Window_Show(WindowHandle window);
DLT_API void Window_Hide(WindowHandle window);
DLT_API void Window_SetSize(WindowHandle window, uint32_t w, uint32_t h);
DLT_API void Window_SetPos(WindowHandle window, uint32_t x, uint32_t y);
DLT_API void Window_ShowCursor(WindowHandle window);
DLT_API void Window_HideCursor(WindowHandle window);
}
36 changes: 36 additions & 0 deletions Engine/include/delta/platform/os_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once

#define DLT_DEFINE_HANDLE(name)\
struct name;\
using name##Handle = name*;\
inline constexpr name##Handle INVALID_##name##_HANDLE = nullptr

namespace delta::platform
{
DLT_DEFINE_HANDLE(Window);

struct OSInfo
{
const char* cpuArchitecture;

uint32_t cpuPhysicalCoreCount;
uint32_t cpuLogicalProcessorCount;
uint32_t osPageSize;

char cpuBrandString[sizeof(int) * 12 + 1];
char cpuManufacturerId[13];

bool cpuHasSMT;
bool cpuHasAVX2;
bool cpuHasAVX512f;
bool cpuHasAVX512cd;
bool cpuHasAVX512er;
bool cpuHasAVX512pf;
};

struct MemoryStatus
{
uint64_t physicalInstalled;
uint64_t physicalFree;
};
}
2 changes: 1 addition & 1 deletion Engine/src/delta/core/ThreadContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ namespace delta::core
WorkerExecutionContext& ctx = GetExecutionContext<WorkerExecutionContext>(i);
ctx.generic.type = ThreadType::WORKER;
ctx.generic.threadIx = i;
ctx.generic.threadHandle = delta::platform::INVALID_THREAD_HANDLE; // Initialized when thread starts
ctx.generic.threadHandle = delta::platform::INVALID_Thread_HANDLE; // Initialized when thread starts
ctx.isAsleep.store(false, std::memory_order_relaxed);
ctx.shouldClose.store(false, std::memory_order_relaxed);
ctx.sleepSemaphore = delta::platform::Sync_CreateSemaphore();
Expand Down
9 changes: 8 additions & 1 deletion Engine/src/delta/core/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,25 @@ namespace delta::Engine
delta::platform::ThreadHandle th = delta::platform::Thread_GetCurrentHandle();
delta::platform::Thread_AssignPhysicalCore(th, 0);
delta::core::Worker_Init(totalThreads-1);

context.window = delta::platform::Window_Create();
delta::platform::Window_Show(context.window);
delta::platform::Window_Win32_Update(context.window);
}

void Update(Context& context)
{
// blah blah blah
// do something
delta::platform::Sync_Sleep(100);

delta::platform::Window_ProcessEvents();
delta::platform::Sync_Sleep(10);
delta::core::ThreadArena_Reset(delta::core::GetTransientArena());
}

void Shutdown(Context& context)
{
Engine::Free(context.window);
delta::core::Worker_Shutdown();
delta::core::ThreadContext_Shutdown();
delta::core::MemoryConfig_Shutdown();
Expand Down
26 changes: 7 additions & 19 deletions Engine/src/delta/platform/os_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

#pragma once
#include <delta/platform/os_internal_types.h>

namespace delta::platform
{
Expand All @@ -31,28 +32,12 @@ namespace delta::platform
bool Memory_ElevateLockLimit(size_t maxBytesToLock);

// Timer API
struct Timer_Internal;
struct Timer
{
alignas(8) uint8_t opaqueData[32];
};

void Timer_Initialize(Timer* timer);
int64_t Timer_GetTimestamp();
double Timer_TicksToMilliseconds(const Timer* timer, int64_t startTicks, int64_t endTicks);
double Timer_TicksToMicroseconds(const Timer* timer, int64_t startTicks, int64_t endTicks);

// Thread API
struct Thread;
using ThreadHandle = Thread*;
inline constexpr ThreadHandle INVALID_THREAD_HANDLE = nullptr; // random number 696767

struct ThreadCreateInfo
{
void (*fn)(void*);
void* args;
};

uint32_t Thread_GetCurrentId();
uint32_t Thread_GetId(ThreadHandle thread);
ThreadHandle Thread_GetCurrentHandle();
Expand All @@ -63,12 +48,15 @@ namespace delta::platform
void Thread_JoinMultiple(ThreadHandle* threads, uint32_t count);

// Sync API
struct Semaphore;
using SemaphoreHandle = Semaphore*;

SemaphoreHandle Sync_CreateSemaphore();
void Sync_DestroySemaphore(SemaphoreHandle sem);
void Sync_SignalSemaphore(SemaphoreHandle sem);
void Sync_WaitSemaphore(SemaphoreHandle sem);
void Sync_Sleep(uint32_t milliseconds);

// Window API
WindowHandle Window_Create();
void Window_Win32_Update(WindowHandle window);
void Window_ProcessEvents();
void Window_Destroy(WindowHandle window);
}
27 changes: 27 additions & 0 deletions Engine/src/delta/platform/os_internal_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once
#include <delta/platform/os_types.h>

namespace delta::platform
{
// Timer API
struct Timer_Internal;
struct Timer
{
alignas(8) uint8_t opaqueData[32];
};

// Thread API
DLT_DEFINE_HANDLE(Thread);

struct ThreadCreateInfo
{
void (*fn)(void*);
void* args;
};

// Sync API
DLT_DEFINE_HANDLE(Semaphore);

// Window API
// Window defined in the public header
}
Loading