1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
#ifndef BASE_PLATFORM_H
#define BASE_PLATFORM_H
//- window handle (platform-agnostic)
typedef struct PlatformWindow PlatformWindow;
struct PlatformWindow
{
void *window_handle;
int width;
int height;
int display_x;
int display_y;
const char *name;
};
// TODO: merge the 2 different header files. they should be working correctly
// at the moment but it's kind of a mess.
#if PLATFORM_LINUX
#include "base_platform_linux.h"
#elif PLATFORM_WINDOWS
#include "base_platform_win32.h"
#endif // PLATFORM_LINUX || PLATFORM_WINDOWS
//- linux layer
#if PLATFORM_LINUX
#define PlatformCreateWindow(arena, height, width, display_x, display_y) \
LinuxCreateWindow(arena, height, width, display_x, display_y)
#define PlatformGetDisplayWidth(display, screen_num) \
LinuxDisplayWidth(display, screen_num)
#define PlatformGetDisplayHeight(display, screen_num) \
LinuxDisplayHeight(display, screen_num)
#define PlatformLoadBitmapFromFile(display, window, path, width, height, out, hotspot_x, hotspot_y) \
LinuxLoadBitMapFromFile(display, window, path, width, height, out, hotspot_x, hotspot_y)
#define ENTRYPOINT() int main(int argument_count, char **arguments)
//- windows layer
#elif PLATFORM_WINDOWS
global_variable b32 Win32Running = true;
#pragma warning(disable : 28251) // annotation mismatch warnings from winbase.h
#define ENTRYPOINT() \
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, \
LPSTR lpCmdLine, int nCmdShow)
#define PlatformCreateWindow(instance, height, width, display_x, display_y) \
Win32CreateWindow(instance, height, width, display_x, display_y)
#endif // PLATFORM_LINUX || PLATFORM_WINDOWS
//- standard file descriptors
#define STDIN 0
#define STDOUT 1
#define STDERR 2
//- windows declarations
#if PLATFORM_WINDOWS
void PlatformHandleInput_(void);
#define PlatformHandleInput() PlatformHandleInput_()
internal void win32_log(String8List messages);
internal b32 win32_os_exit(void);
internal b32 win32_file_exists(u8 *path);
internal b32 win32_file_write(String8 data, String8 path);
internal u64 safe_truncate_64(u64 value);
internal String8 win32_file_load(MemArena *arena, u8 *file);
#define FileLoad(arena, path) win32_file_load(arena, path)
#define FileWrite(data, path) win32_file_write(data, path)
#define FileExists(path) win32_file_exists(path)
#define OSExit() win32_os_exit()
//- windows logging (compiler-specific format-string annotations)
#if COMPILER_GCC || COMPILER_CLANG
#define PRINTF_FORMAT(fmt_index, args_index) \
__attribute__((format(printf, fmt_index, args_index)))
internal void win32_logf(const char *fmt, ...) PRINTF_FORMAT(1, 2);
#elif COMPILER_MSVC
internal void win32_logf(_Printf_format_string_ const char *fmt, ...);
#endif // COMPILER_GCC || COMPILER_CLANG
#define Log(fmt, ...) win32_logf(fmt, __VA_ARGS__)
#endif // PLATFORM_WINDOWS
//- linux/unix declarations
#if PLATFORM_LINUX || PLATFORM_UNIX
internal String8 unix_file_write(String8 data, String8 path);
internal String8 unix_file_load(MemArena *arena, String8 path);
internal b32 unix_file_exists(String8 path);
internal b32 unix_os_exit(void);
internal s64 unix_read(int fd, const void *buf, u64 count);
internal s64 unix_log(int fd, const void *buf, u64 count);
internal void unix_log_with_args(const char *format, ...);
#define FileLoad(arena, path) unix_file_load(arena, path)
#define FileWrite(data, path) unix_file_write(data, path)
#define FileExists(path) unix_file_exists(path)
#define OSExit() unix_os_exit()
// TODO: confirm __VA_ARGS__ behaves the same under clang as gcc here
#define Log(...) unix_log_with_args(__VA_ARGS__)
#endif // PLATFORM_LINUX || PLATFORM_UNIX
#endif // BASE_PLATFORM_H
|