This repository has been archived on 2025-02-04. You can view files and clone it, but cannot push or open issues or pull requests.
helpless/oogabooga/oogabooga.c
Charlie 6879130bb0 - File IO
- os_file_open(string path, Os_Io_Open_Flags flags)
	- os_file_close(File f)
	- os_file_delete(string path)
	- os_file_write_string(File f, string s)
	- os_file_write_bytes(File f, void *buffer, u64 size_in_bytes)
	- os_file_read(File f, void* buffer, u64 bytes_to_read, u64 *actual_read_bytes)
	- os_write_entire_file_handle(File f, string data)
	- os_write_entire_file(string path, string data)
	- os_read_entire_file_handle(File f, string *result)
	- os_read_entire_file(string path, string *result)
	- fprint(File, string/char*, ...)
	- Buncha tests

- os_high_precision_sleep
- talloc_string
- Program memory is touched on VirtualAlloc so it actually allocates physical memory (and we can tell when an address is untouched)
2024-06-29 20:55:43 +02:00

159 lines
No EOL
3.2 KiB
C

#define DEBUG 0
#define VERY_DEBUG 1
#define RELEASE 2
#if !defined(CONFIGURATION)
#if defined(NDEBUG)
#define CONFIGURATION RELEASE
#else
#define CONFIGURATION DEBUG
#endif
#endif
#ifndef ENTRY_PROC
#define ENTRY_PROC entry
#endif
#define WINDOWS 0
#define LINUX 1
#define MACOS 2
// This needs to be included before dependencies
#include "base.c"
///
///
// Dependencies
///
#include <math.h>
// Custom allocators for lodepng
void* lodepng_malloc(size_t size) {
return context.allocator.proc((u64)size, 0, ALLOCATOR_ALLOCATE);
}
void* lodepng_realloc(void* ptr, size_t new_size) {
return context.allocator.proc((u64)new_size, 0, ALLOCATOR_REALLOCATE);
}
void lodepng_free(void* ptr) {
context.allocator.proc(0, ptr, ALLOCATOR_DEALLOCATE);
}
#define LODEPNG_NO_COMPILE_ALLOCATORS
#include "third_party/lodepng.c"
/////
#ifdef _WIN32
#include <Windows.h>
#define TARGET_OS WINDOWS
#elif defined(__linux__)
// Include whatever #Incomplete #Portability
#define TARGET_OS LINUX
#error "Linux is not supported yet";
#elif defined(__APPLE__) && defined(__MACH__)
// Include whatever #Incomplete #Portability
#define TARGET_OS MACOS
#error "Mac is not supported yet";
#else
#error "Current OS not supported!";
#endif
#define GFX_RENDERER_D3D11 0
#define GFX_RENDERER_VULKAN 1
#define GFX_RENDERER_METAL 2
#define GFX_RENDERER_LEGACY_OPENGL 3 // #Temporary #Cleanup
// #Temporary #Cleanup
#undef GFX_RENDERER
#define GFX_RENDERER GFX_RENDERER_LEGACY_OPENGL
#ifndef GFX_RENDERER
// #Portability
#if TARGET_OS == WINDOWS
#define GFX_RENDERER GFX_RENDERER_D3D11
#elif TARGET_OS == LINUX
#define GFX_RENDERER GFX_RENDERER_VULKAN
#elif TARGET_OS == MACOS
#define GFX_RENDERER GFX_RENDERER_METAL
#endif
#endif
#include "string.c"
#include "unicode.c"
#include "string_format.c"
#include "os_interface.c"
#include "random.c"
#include "linmath.c"
#include "memory.c"
#include "input.c"
#include "drawing.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"
#elif GFX_RENDERER == GFX_RENDERER_LEGACY_OPENGL
#include "gfx_impl_legacy_opengl.c"
#else
#error "Unknown renderer defined in GFX_RENDERER"
#endif
#if TARGET_OS == WINDOWS
#include "os_impl_windows.c"
#elif TARGET_OS == LINUX
#elif TARGET_OS == MACOS
#endif
#include "tests.c"
void oogabooga_init(u64 program_memory_size) {
os_init(program_memory_size);
gfx_init();
heap_init();
temporary_storage_init();
}
#ifndef INITIAL_PROGRAM_MEMORY_SIZE
#define INITIAL_PROGRAM_MEMORY_SIZE (1024ULL * 1024ULL * 100ULL) // Start with 100mb program memory
#endif
#ifndef RUN_TESTS
#define RUN_TESTS 0
#endif
int ENTRY_PROC(int argc, char **argv);
int main(int argc, char **argv) {
context.allocator.proc = initialization_allocator_proc;
oogabooga_init(INITIAL_PROGRAM_MEMORY_SIZE);
printf("Ooga booga program started\n");
// This can be disabled in build.c
#if RUN_TESTS
oogabooga_run_tests();
#endif
int code = ENTRY_PROC(argc, argv);
printf("Ooga booga program exit with code %i\n", code);
return code;
}