Add OOGABOOGA_HEADLESS option
This commit is contained in:
parent
28898b026e
commit
5509c7166e
5 changed files with 84 additions and 51 deletions
|
@ -123,35 +123,6 @@ void CALLBACK d3d11_debug_callback(D3D11_MESSAGE_CATEGORY category, D3D11_MESSAG
|
|||
}
|
||||
}
|
||||
|
||||
#define win32_check_hr(hr) win32_check_hr_impl(hr, __LINE__, __FILE__);
|
||||
void win32_check_hr_impl(HRESULT hr, u32 line, const char* file_name) {
|
||||
if (hr != S_OK) {
|
||||
|
||||
LPVOID errorMsg;
|
||||
DWORD dwFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS;
|
||||
|
||||
DWORD messageLength = FormatMessageW(
|
||||
dwFlags,
|
||||
NULL,
|
||||
hr,
|
||||
MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT),
|
||||
(LPWSTR) &errorMsg,
|
||||
0,
|
||||
NULL );
|
||||
|
||||
if (messageLength > 0) {
|
||||
MessageBoxW(NULL, (LPWSTR)errorMsg, L"Error", MB_OK | MB_ICONERROR);
|
||||
} else {
|
||||
MessageBoxW(NULL, L"Failed to retrieve error message.", L"Error", MB_OK | MB_ICONERROR);
|
||||
}
|
||||
|
||||
|
||||
panic("win32 hr failed in file %cs on line %d, hr was %d", file_name, line, hr);
|
||||
}
|
||||
}
|
||||
|
||||
void d3d11_update_swapchain() {
|
||||
|
||||
HRESULT hr;
|
||||
|
|
|
@ -281,10 +281,6 @@ typedef u8 bool;
|
|||
/////
|
||||
|
||||
#include "concurrency.c"
|
||||
#include "gfx_interface.c"
|
||||
|
||||
|
||||
#include "font.c"
|
||||
|
||||
#include "profiling.c"
|
||||
#include "random.c"
|
||||
|
@ -292,31 +288,40 @@ typedef u8 bool;
|
|||
#include "memory.c"
|
||||
#include "input.c"
|
||||
|
||||
#include "drawing.c"
|
||||
#ifndef OOGABOOGA_HEADLESS
|
||||
|
||||
#include "audio.c"
|
||||
#include "gfx_interface.c"
|
||||
|
||||
// #Portability
|
||||
#if GFX_RENDERER == GFX_RENDERER_D3D11
|
||||
#include "gfx_impl_d3d11.c"
|
||||
#elif GFX_RENDERER == GFX_RENDERER_VULKAN
|
||||
#error "We only have a D3D11 renderer at the moment"
|
||||
#elif GFX_RENDERER == GFX_RENDERER_METAL
|
||||
#error "We only have a D3D11 renderer at the moment"
|
||||
#else
|
||||
#error "Unknown renderer GFX_RENDERER defined"
|
||||
#include "font.c"
|
||||
|
||||
#include "drawing.c"
|
||||
|
||||
#include "audio.c"
|
||||
#endif
|
||||
|
||||
#if TARGET_OS == WINDOWS
|
||||
#include "os_impl_windows.c"
|
||||
#elif TARGET_OS == LINUX
|
||||
#error "Linux is not supported yet"
|
||||
#include "os_impl_linux.c"
|
||||
#elif TARGET_OS == MACOS
|
||||
#error "Macos is not supported yet"
|
||||
#else
|
||||
#error "Current OS is not supported"
|
||||
#endif
|
||||
|
||||
#ifndef OOGABOOGA_HEADLESS
|
||||
// #Portability
|
||||
#if GFX_RENDERER == GFX_RENDERER_D3D11
|
||||
#include "gfx_impl_d3d11.c"
|
||||
#elif GFX_RENDERER == GFX_RENDERER_VULKAN
|
||||
#error "We only have a D3D11 renderer at the moment"
|
||||
#elif GFX_RENDERER == GFX_RENDERER_METAL
|
||||
#error "We only have a D3D11 renderer at the moment"
|
||||
#else
|
||||
#error "Unknown renderer GFX_RENDERER defined"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "tests.c"
|
||||
|
||||
#define malloc please_use_alloc_for_memory_allocations_instead_of_malloc
|
||||
|
@ -350,7 +355,11 @@ void oogabooga_init(u64 program_memory_size) {
|
|||
heap_init();
|
||||
temporary_storage_init();
|
||||
log_info("Ooga booga version is %d.%02d.%03d", OGB_VERSION_MAJOR, OGB_VERSION_MINOR, OGB_VERSION_PATCH);
|
||||
#ifndef OOGABOOGA_HEADLESS
|
||||
gfx_init();
|
||||
#else
|
||||
log_info("Headless mode on");
|
||||
#endif
|
||||
log_verbose("CPU has sse1: %cs", features.sse1 ? "true" : "false");
|
||||
log_verbose("CPU has sse2: %cs", features.sse2 ? "true" : "false");
|
||||
log_verbose("CPU has sse3: %cs", features.sse3 ? "true" : "false");
|
||||
|
|
|
@ -12,6 +12,37 @@
|
|||
void* heap_alloc(u64);
|
||||
void heap_dealloc(void*);
|
||||
|
||||
#define win32_check_hr(hr) win32_check_hr_impl(hr, __LINE__, __FILE__);
|
||||
void win32_check_hr_impl(HRESULT hr, u32 line, const char* file_name) {
|
||||
if (hr != S_OK) {
|
||||
|
||||
LPVOID errorMsg;
|
||||
DWORD dwFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS;
|
||||
|
||||
DWORD messageLength = FormatMessageW(
|
||||
dwFlags,
|
||||
NULL,
|
||||
hr,
|
||||
MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT),
|
||||
(LPWSTR) &errorMsg,
|
||||
0,
|
||||
NULL );
|
||||
|
||||
if (messageLength > 0) {
|
||||
MessageBoxW(NULL, (LPWSTR)errorMsg, L"Error", MB_OK | MB_ICONERROR);
|
||||
} else {
|
||||
MessageBoxW(NULL, L"Failed to retrieve error message.", L"Error", MB_OK | MB_ICONERROR);
|
||||
}
|
||||
|
||||
|
||||
panic("win32 hr failed in file %cs on line %d, hr was %d", file_name, line, hr);
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef OOGABOOGA_HEADLESS
|
||||
|
||||
// Persistent
|
||||
Input_State_Flags win32_key_states[INPUT_KEY_CODE_COUNT];
|
||||
|
||||
|
@ -202,6 +233,7 @@ void
|
|||
win32_audio_poll_default_device_thread(Thread *t);
|
||||
|
||||
bool win32_has_audio_thread_started = false;
|
||||
#endif /* OOGABOOGA_HEADLESS */
|
||||
|
||||
void os_init(u64 program_memory_size) {
|
||||
|
||||
|
@ -214,9 +246,9 @@ void os_init(u64 program_memory_size) {
|
|||
win32_check_hr(hr);
|
||||
|
||||
context.thread_id = GetCurrentThreadId();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if CONFIGURATION == RELEASE
|
||||
SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
|
||||
#endif
|
||||
|
@ -256,9 +288,9 @@ void os_init(u64 program_memory_size) {
|
|||
os.crt_vsnprintf = (Crt_Vsnprintf_Proc)os_dynamic_library_load_symbol(os.crt, STR("vsnprintf"));
|
||||
assert(os.crt_vsnprintf, "Missing vsnprintf in crt");
|
||||
|
||||
#ifndef OOGABOOGA_HEADLESS
|
||||
win32_init_window();
|
||||
|
||||
|
||||
local_persist Thread audio_thread, audio_poll_default_device_thread;
|
||||
|
||||
os_thread_init(&audio_thread, win32_audio_thread);
|
||||
|
@ -268,6 +300,7 @@ void os_init(u64 program_memory_size) {
|
|||
os_thread_start(&audio_poll_default_device_thread);
|
||||
|
||||
while (!win32_has_audio_thread_started) { os_yield_thread(); }
|
||||
#endif /* NOT OOGABOOGA_HEADLESS */
|
||||
}
|
||||
|
||||
void s64_to_null_terminated_string_reverse(char str[], int length)
|
||||
|
@ -1103,6 +1136,9 @@ os_get_stack_trace(u64 *trace_count, Allocator allocator) {
|
|||
#endif // NOT DEBUG
|
||||
}
|
||||
|
||||
|
||||
#ifndef OOGABOOGA_HEADLESS
|
||||
|
||||
// Actually fuck you bill gates
|
||||
const GUID CLSID_MMDeviceEnumerator = {0xbcde0395, 0xe52f, 0x467c, {0x8e,0x3d, 0xc4,0x57,0x92,0x91,0x69,0x2e}};
|
||||
const GUID IID_IMMDeviceEnumerator = {0xa95664d2, 0x9614, 0x4f35, {0xa7,0x46, 0xde,0x8d,0xb6,0x36,0x17,0xe6}};
|
||||
|
@ -1395,9 +1431,11 @@ win32_audio_thread(Thread *t) {
|
|||
|
||||
}
|
||||
}
|
||||
#endif /* OOGABOOGA_HEADLESS */
|
||||
|
||||
void os_update() {
|
||||
|
||||
#ifndef OOGABOOGA_HEADLESS
|
||||
UINT dpi = GetDpiForWindow(window._os_handle);
|
||||
float dpi_scale_factor = dpi / 96.0f;
|
||||
|
||||
|
@ -1512,8 +1550,10 @@ void os_update() {
|
|||
if (window.should_close) {
|
||||
win32_window_proc(window._os_handle, WM_CLOSE, 0, 0);
|
||||
}
|
||||
#endif /* OOGABOOGA_HEADLESS */
|
||||
}
|
||||
|
||||
#ifndef OOGABOOGA_HEADLESS
|
||||
Input_Key_Code os_key_to_key_code(void* os_key) {
|
||||
|
||||
UINT win32_key = (UINT)(u64)os_key;
|
||||
|
@ -1624,4 +1664,5 @@ void* key_code_to_os_key(Input_Key_Code key_code) {
|
|||
|
||||
panic("Invalid key code %d", key_code);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif /* OOGABOOGA_HEADLESS */
|
|
@ -8,6 +8,9 @@
|
|||
typedef HANDLE File;
|
||||
|
||||
#elif defined(__linux__)
|
||||
#ifndef OOGABOOGA_HEADLESS
|
||||
#define "Linux is only supported for headless builds"
|
||||
#endif
|
||||
typedef SOMETHING Mutex_Handle;
|
||||
typedef SOMETHING Thread_Handle;
|
||||
typedef SOMETHING Dynamic_Library_Handle;
|
||||
|
@ -282,6 +285,8 @@ void dump_stack_trace() {
|
|||
}
|
||||
}
|
||||
|
||||
#ifndef OOGABOOGA_HEADLESS
|
||||
|
||||
///
|
||||
///
|
||||
// Window management
|
||||
|
@ -308,4 +313,6 @@ typedef struct Os_Window {
|
|||
} Os_Window;
|
||||
Os_Window window;
|
||||
|
||||
#endif
|
||||
|
||||
void os_update();
|
|
@ -1151,6 +1151,7 @@ void test_mutex() {
|
|||
mutex_destroy(&data.mutex);
|
||||
}
|
||||
|
||||
#ifndef OOGABOOGA_HEADLESS
|
||||
int compare_draw_quads(const void *a, const void *b) {
|
||||
return ((Draw_Quad*)a)->z-((Draw_Quad*)b)->z;
|
||||
}
|
||||
|
@ -1220,6 +1221,8 @@ void test_sort() {
|
|||
|
||||
print("Merge sort took on average %llu cycles and %.2f ms\n", cycles / num_samples, (seconds * 1000.0) / (float64)num_samples);
|
||||
}
|
||||
#endif /* OOGABOOGA_HEADLESS */
|
||||
|
||||
void oogabooga_run_tests() {
|
||||
|
||||
|
||||
|
@ -1258,10 +1261,12 @@ void oogabooga_run_tests() {
|
|||
print("Testing mutex... ");
|
||||
test_mutex();
|
||||
print("OK!\n");
|
||||
|
||||
|
||||
#ifndef OOGABOOGA_HEADLESS
|
||||
print("Testing radix sort... ");
|
||||
test_sort();
|
||||
print("OK!\n");
|
||||
#endif
|
||||
|
||||
print("All tests ok!\n");
|
||||
}
|
Reference in a new issue