2016-02-20 21:36:16 +00:00
|
|
|
/*
|
|
|
|
* Mr. 4th Dimention - Allen Webster
|
|
|
|
*
|
|
|
|
* 12.12.2014
|
|
|
|
*
|
2017-01-07 02:59:55 +00:00
|
|
|
* Win32 layer for 4coder
|
2016-02-20 21:36:16 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
// TOP
|
|
|
|
|
2017-06-30 21:28:09 +00:00
|
|
|
#define IS_PLAT_LAYER
|
2017-02-25 01:53:40 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Program setup
|
|
|
|
//
|
|
|
|
|
2017-03-18 21:07:25 +00:00
|
|
|
#define UNICODE
|
|
|
|
|
|
|
|
#define FPS 60
|
|
|
|
#define frame_useconds (1000000 / FPS)
|
|
|
|
|
2019-02-24 07:22:16 +00:00
|
|
|
#include "4coder_base_types.h"
|
2019-07-21 18:16:34 +00:00
|
|
|
#include "4coder_table.h"
|
2019-10-01 21:07:39 +00:00
|
|
|
#include "api/4coder_version.h"
|
2016-08-30 19:30:41 +00:00
|
|
|
|
2017-06-30 01:13:20 +00:00
|
|
|
#include <string.h>
|
2017-02-18 01:04:41 +00:00
|
|
|
|
2016-08-31 02:18:47 +00:00
|
|
|
#if defined(FRED_SUPER)
|
2019-10-01 21:07:39 +00:00
|
|
|
# include "api/4coder_keycodes.h"
|
|
|
|
# include "api/4coder_default_colors.h"
|
|
|
|
# include "api/4coder_types.h"
|
|
|
|
|
2019-07-21 18:16:34 +00:00
|
|
|
# include "4coder_base_types.cpp"
|
2019-08-16 02:54:06 +00:00
|
|
|
# include "4coder_stringf.cpp"
|
2019-07-21 18:16:34 +00:00
|
|
|
# include "4coder_hash_functions.cpp"
|
|
|
|
# include "4coder_table.cpp"
|
2019-08-16 02:54:06 +00:00
|
|
|
# include "4coder_log.cpp"
|
2016-08-28 17:31:43 +00:00
|
|
|
#else
|
|
|
|
# include "4coder_default_bindings.cpp"
|
2016-08-30 19:30:41 +00:00
|
|
|
#endif
|
2016-08-29 02:14:02 +00:00
|
|
|
|
2019-07-24 07:41:40 +00:00
|
|
|
#include "4ed_font_interface.h"
|
|
|
|
#include "4ed_font_set.h"
|
2016-02-20 21:36:16 +00:00
|
|
|
#include "4ed_system.h"
|
2017-11-10 18:27:39 +00:00
|
|
|
#include "4ed_render_target.h"
|
2016-02-20 21:36:16 +00:00
|
|
|
#include "4ed.h"
|
|
|
|
|
2016-08-29 02:14:02 +00:00
|
|
|
#include <Windows.h>
|
2017-01-29 00:03:23 +00:00
|
|
|
#include "win32_gl.h"
|
2016-08-29 13:57:05 +00:00
|
|
|
|
2017-03-18 21:07:25 +00:00
|
|
|
//////////////////////////////
|
2016-06-01 16:03:45 +00:00
|
|
|
|
2018-11-28 04:36:09 +00:00
|
|
|
enum{
|
|
|
|
ErrorString_UseLog = 0,
|
|
|
|
ErrorString_UseErrorBox = 1,
|
|
|
|
};
|
|
|
|
|
2017-11-28 19:11:44 +00:00
|
|
|
internal void
|
2019-08-16 15:01:17 +00:00
|
|
|
win32_output_error_string(Arena *scratch, i32 error_string_type);
|
2017-11-28 19:11:44 +00:00
|
|
|
|
|
|
|
//////////////////////////////
|
|
|
|
|
2017-03-23 22:45:32 +00:00
|
|
|
#include "win32_utf8.h"
|
|
|
|
|
2017-03-18 21:07:25 +00:00
|
|
|
#include "4ed_system_shared.h"
|
2016-02-20 21:36:16 +00:00
|
|
|
|
2017-03-18 21:07:25 +00:00
|
|
|
#define WM_4coder_ANIMATE (WM_USER + 0)
|
|
|
|
|
2016-02-20 21:36:16 +00:00
|
|
|
struct Control_Keys{
|
|
|
|
b8 l_ctrl;
|
|
|
|
b8 r_ctrl;
|
|
|
|
b8 l_alt;
|
|
|
|
b8 r_alt;
|
|
|
|
};
|
2018-11-20 08:18:54 +00:00
|
|
|
global Control_Keys null_control_keys = {};
|
2016-02-20 21:36:16 +00:00
|
|
|
|
|
|
|
struct Win32_Input_Chunk_Transient{
|
|
|
|
Key_Input_Data key_data;
|
2018-12-17 04:31:04 +00:00
|
|
|
b8 mouse_l_press;
|
|
|
|
b8 mouse_l_release;
|
|
|
|
b8 mouse_r_press;
|
|
|
|
b8 mouse_r_release;
|
2016-02-27 07:44:17 +00:00
|
|
|
b8 out_of_window;
|
|
|
|
i8 mouse_wheel;
|
2016-03-16 16:50:26 +00:00
|
|
|
b8 trying_to_kill;
|
2016-02-20 21:36:16 +00:00
|
|
|
};
|
2018-11-20 08:18:54 +00:00
|
|
|
global Win32_Input_Chunk_Transient null_input_chunk_transient = {};
|
2016-02-20 21:36:16 +00:00
|
|
|
|
|
|
|
struct Win32_Input_Chunk_Persistent{
|
2019-02-25 23:42:13 +00:00
|
|
|
Vec2_i32 mouse;
|
2016-02-20 21:36:16 +00:00
|
|
|
Control_Keys controls;
|
2019-02-04 01:33:44 +00:00
|
|
|
b8 mouse_l;
|
|
|
|
b8 mouse_r;
|
2016-02-26 17:40:51 +00:00
|
|
|
b8 control_keys[MDFR_INDEX_COUNT];
|
2016-02-20 21:36:16 +00:00
|
|
|
};
|
|
|
|
|
2017-07-18 16:41:40 +00:00
|
|
|
struct Win32_Input_Chunk{
|
2016-02-20 21:36:16 +00:00
|
|
|
Win32_Input_Chunk_Transient trans;
|
|
|
|
Win32_Input_Chunk_Persistent pers;
|
2017-07-18 16:41:40 +00:00
|
|
|
};
|
2016-02-20 21:36:16 +00:00
|
|
|
|
2017-07-19 00:19:38 +00:00
|
|
|
////////////////////////////////
|
|
|
|
|
2017-07-19 16:33:12 +00:00
|
|
|
#define SLASH '\\'
|
|
|
|
#define DLL "dll"
|
|
|
|
|
2017-07-19 00:23:38 +00:00
|
|
|
global System_Functions sysfunc;
|
2017-07-19 16:33:12 +00:00
|
|
|
#include "4ed_shared_library_constants.h"
|
|
|
|
#include "win32_library_wrapper.h"
|
2017-07-19 00:19:38 +00:00
|
|
|
|
2017-11-16 23:03:36 +00:00
|
|
|
#include "4ed_standard_libraries.cpp"
|
2019-07-24 07:41:40 +00:00
|
|
|
#include "4ed_font_face.cpp"
|
2017-07-19 20:07:50 +00:00
|
|
|
|
2018-12-18 01:56:21 +00:00
|
|
|
#include "4ed_mem.cpp"
|
2019-04-01 06:14:31 +00:00
|
|
|
#include "4coder_hash_functions.cpp"
|
2018-12-18 01:56:21 +00:00
|
|
|
|
2019-07-21 18:16:34 +00:00
|
|
|
#include "4ed_system_allocator.cpp"
|
2019-07-24 07:41:40 +00:00
|
|
|
#include "4ed_font_set.cpp"
|
2019-07-21 18:16:34 +00:00
|
|
|
|
2017-07-19 00:19:38 +00:00
|
|
|
////////////////////////////////
|
|
|
|
|
2019-02-04 01:33:44 +00:00
|
|
|
typedef i32 Win32_Object_Kind;
|
|
|
|
enum{
|
|
|
|
Win32ObjectKind_ERROR = 0,
|
|
|
|
Win32ObjectKind_Timer = 1,
|
2019-08-04 05:36:13 +00:00
|
|
|
Win32ObjectKind_Thread = 2,
|
|
|
|
Win32ObjectKind_Mutex = 3,
|
|
|
|
Win32ObjectKind_CV = 4,
|
2019-02-04 01:33:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Win32_Object{
|
|
|
|
Node node;
|
|
|
|
Win32_Object_Kind kind;
|
|
|
|
union{
|
|
|
|
struct{
|
|
|
|
UINT_PTR id;
|
|
|
|
} timer;
|
2019-08-04 05:36:13 +00:00
|
|
|
struct{
|
|
|
|
HANDLE thread;
|
|
|
|
Thread_Function *proc;
|
|
|
|
void *ptr;
|
|
|
|
} thread;
|
|
|
|
CRITICAL_SECTION mutex;
|
|
|
|
CONDITION_VARIABLE cv;
|
2019-02-04 01:33:44 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-06-12 21:35:06 +00:00
|
|
|
struct Win32_Vars{
|
2019-10-01 02:06:21 +00:00
|
|
|
Thread_Context *tctx;
|
2019-08-16 15:01:17 +00:00
|
|
|
|
2016-05-29 19:05:27 +00:00
|
|
|
Win32_Input_Chunk input_chunk;
|
2019-02-04 01:33:44 +00:00
|
|
|
b8 lctrl_lalt_is_altgr;
|
|
|
|
b8 got_useful_event;
|
2016-05-29 19:05:27 +00:00
|
|
|
|
2019-02-04 01:33:44 +00:00
|
|
|
b8 full_screen;
|
|
|
|
b8 do_toggle;
|
2017-07-18 22:34:57 +00:00
|
|
|
WINDOWPLACEMENT bordered_win_pos;
|
2016-09-01 20:29:07 +00:00
|
|
|
b32 send_exit_signal;
|
2016-05-29 19:05:27 +00:00
|
|
|
|
|
|
|
HCURSOR cursor_ibeam;
|
|
|
|
HCURSOR cursor_arrow;
|
|
|
|
HCURSOR cursor_leftright;
|
|
|
|
HCURSOR cursor_updown;
|
2017-10-31 17:29:52 +00:00
|
|
|
i32 cursor_show;
|
|
|
|
i32 prev_cursor_show;
|
2017-03-23 23:40:16 +00:00
|
|
|
|
2019-07-21 18:16:34 +00:00
|
|
|
String_Const_u8 binary_path;
|
2019-02-14 03:53:55 +00:00
|
|
|
|
2019-10-01 20:04:45 +00:00
|
|
|
Arena *clipboard_arena;
|
2019-07-21 18:16:34 +00:00
|
|
|
String_Const_u8 clipboard_contents;
|
2016-05-29 19:05:27 +00:00
|
|
|
b32 next_clipboard_is_self;
|
|
|
|
DWORD clipboard_sequence;
|
|
|
|
|
2019-06-01 23:33:31 +00:00
|
|
|
Arena clip_post_arena;
|
|
|
|
String_Const_u8 clip_post;
|
2017-11-13 22:12:04 +00:00
|
|
|
|
2016-05-29 19:05:27 +00:00
|
|
|
HWND window_handle;
|
2019-09-28 00:49:59 +00:00
|
|
|
f32 screen_scale_factor;
|
2016-05-29 19:05:27 +00:00
|
|
|
|
2017-06-16 20:57:02 +00:00
|
|
|
f64 count_per_usecond;
|
2016-02-20 21:36:16 +00:00
|
|
|
b32 first;
|
2016-05-29 19:05:27 +00:00
|
|
|
i32 running_cli;
|
|
|
|
|
2019-02-04 01:33:44 +00:00
|
|
|
Node free_win32_objects;
|
|
|
|
Node timer_objects;
|
|
|
|
UINT_PTR timer_counter;
|
|
|
|
|
2019-08-04 05:36:13 +00:00
|
|
|
CRITICAL_SECTION thread_launch_mutex;
|
|
|
|
CONDITION_VARIABLE thread_launch_cv;
|
|
|
|
b32 waiting_for_launch;
|
|
|
|
|
2019-08-16 02:54:06 +00:00
|
|
|
Log_Function *log_string;
|
2017-06-12 21:35:06 +00:00
|
|
|
};
|
2016-02-20 21:36:16 +00:00
|
|
|
|
2017-07-18 19:52:41 +00:00
|
|
|
////////////////////////////////
|
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
global Win32_Vars win32vars;
|
2017-07-18 23:17:40 +00:00
|
|
|
global Render_Target target;
|
2017-07-18 21:19:28 +00:00
|
|
|
global Plat_Settings plat_settings;
|
2016-02-20 21:36:16 +00:00
|
|
|
|
2017-07-19 00:19:38 +00:00
|
|
|
global Libraries libraries;
|
|
|
|
global App_Functions app;
|
2017-07-19 20:07:50 +00:00
|
|
|
global Custom_API custom_api;
|
|
|
|
|
2017-07-18 17:44:54 +00:00
|
|
|
////////////////////////////////
|
|
|
|
|
2019-08-16 15:01:17 +00:00
|
|
|
internal void
|
|
|
|
system_error_box(Arena *scratch, char *msg, b32 shutdown = true){
|
|
|
|
//LOGF("error box: %s\n", msg);
|
|
|
|
MessageBox_utf8(scratch, 0, (u8*)msg, (u8*)"Error", 0);
|
|
|
|
if (shutdown){
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2017-07-18 23:41:28 +00:00
|
|
|
|
|
|
|
////////////////////////////////
|
|
|
|
|
2017-11-10 21:13:02 +00:00
|
|
|
internal void
|
2019-08-16 15:01:17 +00:00
|
|
|
win32_output_error_string(Arena *scratch, b32 use_error_box){
|
2017-11-10 21:13:02 +00:00
|
|
|
DWORD error = GetLastError();
|
|
|
|
|
|
|
|
char *str = 0;
|
|
|
|
char *str_ptr = (char*)&str;
|
|
|
|
if (FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 0, error, 0, str_ptr, 0, 0)){
|
2017-11-13 20:22:49 +00:00
|
|
|
if (use_error_box){
|
2019-08-16 15:01:17 +00:00
|
|
|
system_error_box(scratch, str, false);
|
2017-11-13 20:22:49 +00:00
|
|
|
}
|
2017-11-10 21:13:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////
|
|
|
|
|
2017-07-18 17:44:54 +00:00
|
|
|
internal HANDLE
|
|
|
|
handle_type(Plat_Handle h){
|
|
|
|
HANDLE result;
|
2019-02-04 01:33:44 +00:00
|
|
|
block_copy(&result, &h, sizeof(result));
|
2017-07-18 17:44:54 +00:00
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal Plat_Handle
|
|
|
|
handle_type(HANDLE h){
|
2018-11-20 08:18:54 +00:00
|
|
|
Plat_Handle result = {};
|
2019-02-04 01:33:44 +00:00
|
|
|
block_copy(&result, &h, sizeof(h));
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void*
|
|
|
|
handle_type_ptr(Plat_Handle h){
|
|
|
|
void *result;
|
|
|
|
block_copy(&result, &h, sizeof(result));
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal Plat_Handle
|
|
|
|
handle_type_ptr(void *ptr){
|
|
|
|
Plat_Handle result = {};
|
|
|
|
block_copy(&result, &ptr, sizeof(ptr));
|
2017-07-18 17:44:54 +00:00
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////
|
|
|
|
|
2017-07-18 21:29:39 +00:00
|
|
|
#include "win32_4ed_functions.cpp"
|
2017-07-18 19:52:41 +00:00
|
|
|
|
2017-07-18 20:51:44 +00:00
|
|
|
////////////////////////////////
|
|
|
|
|
2019-02-25 23:42:13 +00:00
|
|
|
internal void
|
2019-08-13 04:19:02 +00:00
|
|
|
system_schedule_step(u32 code){
|
|
|
|
PostMessage(win32vars.window_handle, WM_4coder_ANIMATE, code, 0);
|
2017-07-18 20:51:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////
|
|
|
|
|
2017-07-18 22:09:16 +00:00
|
|
|
internal void
|
|
|
|
win32_toggle_fullscreen(){
|
2017-07-18 22:34:57 +00:00
|
|
|
HWND win = win32vars.window_handle;
|
|
|
|
DWORD style = GetWindowLongW(win, GWL_STYLE);
|
2017-10-31 16:52:39 +00:00
|
|
|
b32 is_full = ((style & WS_OVERLAPPEDWINDOW) == 0);
|
|
|
|
if (!is_full){
|
2017-07-18 22:34:57 +00:00
|
|
|
MONITORINFO info = {sizeof(MONITORINFO)};
|
|
|
|
if (GetWindowPlacement(win, &win32vars.bordered_win_pos) && GetMonitorInfo(MonitorFromWindow(win, MONITOR_DEFAULTTOPRIMARY), &info)){
|
|
|
|
SetWindowLongW(win, GWL_STYLE, style & ~WS_OVERLAPPEDWINDOW);
|
|
|
|
|
|
|
|
i32 x = info.rcMonitor.left;
|
|
|
|
i32 y = info.rcMonitor.top;
|
|
|
|
i32 w = info.rcMonitor.right - info.rcMonitor.left;
|
|
|
|
i32 h = info.rcMonitor.bottom - info.rcMonitor.top;
|
|
|
|
|
|
|
|
SetWindowPos(win, HWND_TOP, x, y, w, h, SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_SHOWWINDOW);
|
2017-07-18 22:09:16 +00:00
|
|
|
win32vars.full_screen = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
2017-07-18 22:34:57 +00:00
|
|
|
SetWindowLongW(win, GWL_STYLE, style | WS_OVERLAPPEDWINDOW);
|
|
|
|
SetWindowPlacement(win, &win32vars.bordered_win_pos);
|
|
|
|
SetWindowPos(win, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
|
2017-07-18 22:09:16 +00:00
|
|
|
win32vars.full_screen = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(allen): add a "shown but auto-hides on timer" setting here.
|
|
|
|
internal
|
|
|
|
Sys_Show_Mouse_Cursor_Sig(system_show_mouse_cursor){
|
2017-10-31 17:29:52 +00:00
|
|
|
win32vars.cursor_show = show;
|
2017-07-18 22:09:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_Set_Fullscreen_Sig(system_set_fullscreen){
|
2017-07-18 22:34:57 +00:00
|
|
|
// NOTE(allen): If the new value of full_screen does not match the current value,
|
|
|
|
// set toggle to true.
|
|
|
|
win32vars.do_toggle = (win32vars.full_screen != full_screen);
|
|
|
|
b32 success = true;
|
2017-07-18 22:09:16 +00:00
|
|
|
return(success);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_Is_Fullscreen_Sig(system_is_fullscreen){
|
|
|
|
// NOTE(allen): Report the fullscreen status as it would be set at the beginning of the next frame.
|
|
|
|
// That is, take into account all fullscreen toggle requests that have come in already this frame.
|
|
|
|
// Read: "full_screen XOR do_toggle"
|
|
|
|
b32 result = (win32vars.full_screen != win32vars.do_toggle);
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2017-11-13 22:12:04 +00:00
|
|
|
#include "4ed_system_shared.cpp"
|
|
|
|
|
2016-05-29 19:28:29 +00:00
|
|
|
//
|
|
|
|
// Clipboard
|
|
|
|
//
|
2016-02-27 07:44:17 +00:00
|
|
|
|
2017-11-13 22:12:04 +00:00
|
|
|
internal void
|
2019-08-16 15:01:17 +00:00
|
|
|
win32_post_clipboard(Arena *scratch, char *text, i32 len){
|
2017-01-03 20:05:35 +00:00
|
|
|
if (OpenClipboard(win32vars.window_handle)){
|
2017-11-13 20:22:49 +00:00
|
|
|
if (!EmptyClipboard()){
|
2019-08-16 15:01:17 +00:00
|
|
|
win32_output_error_string(scratch, ErrorString_UseLog);
|
2017-11-13 20:22:49 +00:00
|
|
|
}
|
2017-11-13 22:12:04 +00:00
|
|
|
HANDLE memory_handle = GlobalAlloc(GMEM_MOVEABLE, len + 1);
|
2017-01-03 20:05:35 +00:00
|
|
|
if (memory_handle){
|
|
|
|
char *dest = (char*)GlobalLock(memory_handle);
|
2017-11-21 19:48:04 +00:00
|
|
|
memmove(dest, text, len);
|
|
|
|
dest[len] = 0;
|
2017-01-03 20:05:35 +00:00
|
|
|
GlobalUnlock(memory_handle);
|
|
|
|
SetClipboardData(CF_TEXT, memory_handle);
|
2017-11-13 20:22:49 +00:00
|
|
|
win32vars.next_clipboard_is_self = true;
|
2017-01-03 20:05:35 +00:00
|
|
|
}
|
|
|
|
CloseClipboard();
|
|
|
|
}
|
2016-02-26 05:50:19 +00:00
|
|
|
}
|
|
|
|
|
2017-11-13 22:12:04 +00:00
|
|
|
internal
|
|
|
|
Sys_Post_Clipboard_Sig(system_post_clipboard){
|
2019-06-01 23:33:31 +00:00
|
|
|
Arena *arena = &win32vars.clip_post_arena;
|
|
|
|
if (arena->base_allocator == 0){
|
|
|
|
*arena = make_arena_system(&sysfunc);
|
2017-11-17 19:22:12 +00:00
|
|
|
}
|
|
|
|
else{
|
2019-06-01 23:33:31 +00:00
|
|
|
linalloc_clear(arena);
|
|
|
|
}
|
|
|
|
win32vars.clip_post.str = push_array(arena, u8, str.size + 1);
|
|
|
|
if (win32vars.clip_post.str != 0){
|
|
|
|
block_copy(win32vars.clip_post.str, str.str, str.size);
|
|
|
|
win32vars.clip_post.str[str.size] = 0;
|
|
|
|
win32vars.clip_post.size = str.size;
|
|
|
|
}
|
|
|
|
else{
|
2019-07-21 18:16:34 +00:00
|
|
|
//LOGF("Failed to allocate buffer for clipboard post (%d)\n", (i32)str.size + 1);
|
2017-11-17 19:22:12 +00:00
|
|
|
}
|
2017-11-13 22:12:04 +00:00
|
|
|
}
|
|
|
|
|
2016-05-29 19:28:29 +00:00
|
|
|
internal b32
|
2019-08-16 15:01:17 +00:00
|
|
|
win32_read_clipboard_contents(Arena *scratch){
|
2019-06-01 23:33:31 +00:00
|
|
|
Temp_Memory temp = begin_temp(scratch);
|
2018-05-07 02:47:22 +00:00
|
|
|
|
2017-03-23 23:40:16 +00:00
|
|
|
b32 result = false;
|
2016-02-26 17:40:51 +00:00
|
|
|
|
2018-05-07 02:47:22 +00:00
|
|
|
b32 has_text = false;
|
|
|
|
b32 has_unicode = IsClipboardFormatAvailable(CF_UNICODETEXT);
|
|
|
|
if (!has_unicode){
|
|
|
|
has_text = IsClipboardFormatAvailable(CF_TEXT);
|
|
|
|
}
|
|
|
|
b32 can_read = has_unicode || has_text;
|
|
|
|
|
|
|
|
if (can_read){
|
2016-05-29 19:28:29 +00:00
|
|
|
if (OpenClipboard(win32vars.window_handle)){
|
2018-05-07 02:47:22 +00:00
|
|
|
result = true;
|
2019-10-01 20:04:45 +00:00
|
|
|
String_u8 contents = {};
|
|
|
|
Arena *clip_arena = win32vars.clipboard_arena;
|
2018-05-07 02:47:22 +00:00
|
|
|
if (has_unicode){
|
2019-10-01 20:04:45 +00:00
|
|
|
HANDLE clip_data = GetClipboardData(CF_UNICODETEXT);
|
2018-05-07 02:47:22 +00:00
|
|
|
if (clip_data != 0){
|
2019-10-01 20:04:45 +00:00
|
|
|
u16 *clip_16_ptr = (u16*)GlobalLock(clip_data);
|
|
|
|
if (clip_16_ptr != 0){
|
|
|
|
linalloc_clear(clip_arena);
|
|
|
|
String_Const_u16 clip_16 = SCu16(clip_16_ptr);
|
|
|
|
contents = string_u8_from_string_u16(clip_arena, clip_16, StringFill_NullTerminate);
|
2017-03-23 23:40:16 +00:00
|
|
|
}
|
|
|
|
}
|
2019-10-01 20:04:45 +00:00
|
|
|
GlobalUnlock(clip_data);
|
2018-05-07 02:47:22 +00:00
|
|
|
}
|
|
|
|
else{
|
2019-10-01 20:04:45 +00:00
|
|
|
HANDLE clip_data = GetClipboardData(CF_TEXT);
|
2018-05-07 02:47:22 +00:00
|
|
|
if (clip_data != 0){
|
2019-10-01 20:04:45 +00:00
|
|
|
char *clip_ascii_ptr = (char*)GlobalLock(clip_data);
|
|
|
|
if (clip_ascii_ptr != 0){
|
|
|
|
linalloc_clear(clip_arena);
|
|
|
|
String_Const_char clip_ascii = SCchar(clip_ascii_ptr);
|
|
|
|
contents = string_u8_from_string_char(clip_arena, clip_ascii, StringFill_NullTerminate);
|
2018-05-07 02:47:22 +00:00
|
|
|
}
|
2016-05-29 19:28:29 +00:00
|
|
|
}
|
2019-10-01 20:04:45 +00:00
|
|
|
GlobalUnlock(clip_data);
|
2016-05-29 19:28:29 +00:00
|
|
|
}
|
2018-05-07 02:47:22 +00:00
|
|
|
|
2019-10-01 20:04:45 +00:00
|
|
|
win32vars.clipboard_contents = contents.string;
|
2018-05-07 02:47:22 +00:00
|
|
|
|
2016-05-29 19:28:29 +00:00
|
|
|
CloseClipboard();
|
|
|
|
}
|
2016-02-26 17:40:51 +00:00
|
|
|
}
|
|
|
|
|
2019-06-01 23:33:31 +00:00
|
|
|
end_temp(temp);
|
2018-05-07 02:47:22 +00:00
|
|
|
|
2016-05-29 19:28:29 +00:00
|
|
|
return(result);
|
2016-02-26 05:50:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-29 03:12:12 +00:00
|
|
|
//
|
|
|
|
// Command Line Exectuion
|
|
|
|
//
|
|
|
|
|
2016-02-20 21:36:16 +00:00
|
|
|
internal
|
2019-08-16 15:01:17 +00:00
|
|
|
Sys_CLI_Call_Sig(system_cli_call, scratch, path, script_name, cli_out){
|
2017-11-28 19:11:44 +00:00
|
|
|
Assert(sizeof(Plat_Handle) >= sizeof(HANDLE));
|
|
|
|
|
2016-02-20 21:36:16 +00:00
|
|
|
char cmd[] = "c:\\windows\\system32\\cmd.exe";
|
2017-03-23 19:14:39 +00:00
|
|
|
char *env_variables = 0;
|
2016-02-20 21:36:16 +00:00
|
|
|
|
2019-07-21 18:16:34 +00:00
|
|
|
Temp_Memory temp = begin_temp(scratch);
|
|
|
|
String_Const_u8 s = push_u8_stringf(scratch, "/C %s", script_name);
|
|
|
|
|
|
|
|
b32 success = false;
|
|
|
|
|
|
|
|
*(HANDLE*)&cli_out->proc = INVALID_HANDLE_VALUE;
|
|
|
|
*(HANDLE*)&cli_out->out_read = INVALID_HANDLE_VALUE;
|
|
|
|
*(HANDLE*)&cli_out->out_write = INVALID_HANDLE_VALUE;
|
|
|
|
*(HANDLE*)&cli_out->in_read = INVALID_HANDLE_VALUE;
|
|
|
|
*(HANDLE*)&cli_out->in_write = INVALID_HANDLE_VALUE;
|
|
|
|
|
|
|
|
SECURITY_ATTRIBUTES security_atrb = {};
|
|
|
|
security_atrb.nLength = sizeof(SECURITY_ATTRIBUTES);
|
|
|
|
security_atrb.bInheritHandle = TRUE;
|
|
|
|
|
|
|
|
HANDLE out_read = INVALID_HANDLE_VALUE;
|
|
|
|
HANDLE out_write = INVALID_HANDLE_VALUE;
|
|
|
|
if (CreatePipe(&out_read, &out_write, &security_atrb, 0)){
|
|
|
|
if (SetHandleInformation(out_read, HANDLE_FLAG_INHERIT, 0)){
|
|
|
|
STARTUPINFO startup = {};
|
|
|
|
startup.cb = sizeof(STARTUPINFO);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
|
|
|
|
|
|
|
|
HANDLE in_read = CreateFileA("nul", GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, &security_atrb, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
|
|
|
|
|
|
|
startup.hStdInput = in_read;
|
|
|
|
startup.hStdOutput = out_write;
|
|
|
|
startup.hStdError = out_write;
|
|
|
|
startup.wShowWindow = SW_HIDE;
|
|
|
|
|
|
|
|
PROCESS_INFORMATION info = {};
|
2019-08-16 15:01:17 +00:00
|
|
|
if (CreateProcess_utf8(scratch, (u8*)cmd, s.str, 0, 0, TRUE, 0, env_variables, (u8*)path, &startup, &info)){
|
2019-07-21 18:16:34 +00:00
|
|
|
success = true;
|
|
|
|
CloseHandle(info.hThread);
|
|
|
|
*(HANDLE*)&cli_out->proc = info.hProcess;
|
|
|
|
*(HANDLE*)&cli_out->out_read = out_read;
|
|
|
|
*(HANDLE*)&cli_out->out_write = out_write;
|
2016-06-29 17:16:08 +00:00
|
|
|
|
2019-07-21 18:16:34 +00:00
|
|
|
++win32vars.running_cli;
|
2016-02-20 21:36:16 +00:00
|
|
|
}
|
|
|
|
else{
|
2016-05-10 17:36:53 +00:00
|
|
|
CloseHandle(out_read);
|
|
|
|
CloseHandle(out_write);
|
2019-07-21 18:16:34 +00:00
|
|
|
CloseHandle(in_read);
|
2016-02-20 21:36:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
2019-07-21 18:16:34 +00:00
|
|
|
// TODO(allen): failed SetHandleInformation
|
|
|
|
CloseHandle(out_read);
|
|
|
|
CloseHandle(out_write);
|
2016-02-20 21:36:16 +00:00
|
|
|
}
|
|
|
|
}
|
2019-07-21 18:16:34 +00:00
|
|
|
else{
|
|
|
|
// TODO(allen): failed CreatePipe
|
|
|
|
}
|
|
|
|
|
|
|
|
end_temp(temp);
|
2016-08-28 19:25:24 +00:00
|
|
|
|
2019-07-21 18:16:34 +00:00
|
|
|
return(success);
|
2016-02-20 21:36:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct CLI_Loop_Control{
|
|
|
|
u32 remaining_amount;
|
|
|
|
};
|
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_CLI_Begin_Update_Sig(system_cli_begin_update){
|
|
|
|
Assert(sizeof(cli->scratch_space) >= sizeof(CLI_Loop_Control));
|
|
|
|
CLI_Loop_Control *loop = (CLI_Loop_Control*)cli->scratch_space;
|
|
|
|
loop->remaining_amount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_CLI_Update_Step_Sig(system_cli_update_step){
|
|
|
|
HANDLE handle = *(HANDLE*)&cli->out_read;
|
|
|
|
CLI_Loop_Control *loop = (CLI_Loop_Control*)cli->scratch_space;
|
|
|
|
b32 has_more = 0;
|
|
|
|
DWORD remaining = loop->remaining_amount;
|
|
|
|
u32 pos = 0;
|
|
|
|
DWORD read_amount = 0;
|
2016-08-28 19:25:24 +00:00
|
|
|
|
2016-02-20 21:36:16 +00:00
|
|
|
for (;;){
|
|
|
|
if (remaining == 0){
|
|
|
|
if (!PeekNamedPipe(handle, 0, 0, 0, &remaining, 0)) break;
|
|
|
|
if (remaining == 0) break;
|
|
|
|
}
|
2016-08-28 19:25:24 +00:00
|
|
|
|
2016-02-20 21:36:16 +00:00
|
|
|
if (remaining + pos < max){
|
|
|
|
has_more = 1;
|
|
|
|
ReadFile(handle, dest + pos, remaining, &read_amount, 0);
|
2019-06-01 23:33:31 +00:00
|
|
|
Assert(remaining == read_amount);
|
2016-02-20 21:36:16 +00:00
|
|
|
pos += remaining;
|
|
|
|
remaining = 0;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
has_more = 1;
|
|
|
|
ReadFile(handle, dest + pos, max - pos, &read_amount, 0);
|
2019-06-01 23:33:31 +00:00
|
|
|
Assert(max - pos == read_amount);
|
2016-02-20 21:36:16 +00:00
|
|
|
loop->remaining_amount = remaining - (max - pos);
|
|
|
|
pos = max;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*amount = pos;
|
2016-08-28 19:25:24 +00:00
|
|
|
|
|
|
|
return(has_more);
|
2016-02-20 21:36:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_CLI_End_Update_Sig(system_cli_end_update){
|
2017-11-10 18:27:39 +00:00
|
|
|
b32 close_me = false;
|
2016-02-20 21:36:16 +00:00
|
|
|
HANDLE proc = *(HANDLE*)&cli->proc;
|
|
|
|
DWORD result = 0;
|
2016-08-28 19:25:24 +00:00
|
|
|
|
2016-02-20 21:36:16 +00:00
|
|
|
if (WaitForSingleObject(proc, 0) == WAIT_OBJECT_0){
|
2017-01-23 06:19:43 +00:00
|
|
|
if (GetExitCodeProcess(proc, &result) == 0){
|
2016-03-21 03:58:34 +00:00
|
|
|
cli->exit = -1;
|
2017-01-23 06:19:43 +00:00
|
|
|
}
|
|
|
|
else{
|
2016-03-21 03:58:34 +00:00
|
|
|
cli->exit = (i32)result;
|
2017-01-23 06:19:43 +00:00
|
|
|
}
|
2016-08-28 19:25:24 +00:00
|
|
|
|
2017-11-10 18:27:39 +00:00
|
|
|
close_me = true;
|
2016-03-21 03:58:34 +00:00
|
|
|
CloseHandle(*(HANDLE*)&cli->proc);
|
|
|
|
CloseHandle(*(HANDLE*)&cli->out_read);
|
|
|
|
CloseHandle(*(HANDLE*)&cli->out_write);
|
2017-11-28 19:11:44 +00:00
|
|
|
if (*(HANDLE*)&cli->in_read != INVALID_HANDLE_VALUE){
|
|
|
|
CloseHandle(*(HANDLE*)&cli->in_read);
|
|
|
|
}
|
|
|
|
if (*(HANDLE*)&cli->in_write != INVALID_HANDLE_VALUE){
|
|
|
|
CloseHandle(*(HANDLE*)&cli->in_write);
|
|
|
|
}
|
2016-05-10 17:36:53 +00:00
|
|
|
|
|
|
|
--win32vars.running_cli;
|
2016-02-20 21:36:16 +00:00
|
|
|
}
|
2017-11-10 18:27:39 +00:00
|
|
|
|
2016-08-28 19:25:24 +00:00
|
|
|
return(close_me);
|
2016-02-20 21:36:16 +00:00
|
|
|
}
|
|
|
|
|
2017-11-16 23:03:36 +00:00
|
|
|
#include "4ed_font_provider_freetype.h"
|
|
|
|
#include "4ed_font_provider_freetype.cpp"
|
2017-11-17 19:22:12 +00:00
|
|
|
|
2017-11-14 23:37:38 +00:00
|
|
|
#include <GL/gl.h>
|
2017-11-11 00:58:47 +00:00
|
|
|
#include "opengl/4ed_opengl_render.cpp"
|
2017-03-23 23:40:16 +00:00
|
|
|
|
2016-05-29 03:12:12 +00:00
|
|
|
//
|
|
|
|
// Helpers
|
|
|
|
//
|
2016-05-27 02:48:20 +00:00
|
|
|
|
2017-02-12 06:01:01 +00:00
|
|
|
global Key_Code keycode_lookup_table[255];
|
2016-05-14 20:08:11 +00:00
|
|
|
|
|
|
|
internal void
|
2019-07-21 18:16:34 +00:00
|
|
|
win32_keycode_init(void){
|
2016-05-14 20:08:11 +00:00
|
|
|
keycode_lookup_table[VK_BACK] = key_back;
|
|
|
|
keycode_lookup_table[VK_DELETE] = key_del;
|
|
|
|
keycode_lookup_table[VK_UP] = key_up;
|
|
|
|
keycode_lookup_table[VK_DOWN] = key_down;
|
|
|
|
keycode_lookup_table[VK_LEFT] = key_left;
|
|
|
|
keycode_lookup_table[VK_RIGHT] = key_right;
|
|
|
|
keycode_lookup_table[VK_INSERT] = key_insert;
|
|
|
|
keycode_lookup_table[VK_HOME] = key_home;
|
|
|
|
keycode_lookup_table[VK_END] = key_end;
|
|
|
|
keycode_lookup_table[VK_PRIOR] = key_page_up;
|
|
|
|
keycode_lookup_table[VK_NEXT] = key_page_down;
|
|
|
|
keycode_lookup_table[VK_ESCAPE] = key_esc;
|
2016-05-14 20:11:52 +00:00
|
|
|
|
2019-02-13 22:14:27 +00:00
|
|
|
keycode_lookup_table[VK_CONTROL] = key_ctrl;
|
|
|
|
keycode_lookup_table[VK_LCONTROL] = key_ctrl;
|
|
|
|
keycode_lookup_table[VK_RCONTROL] = key_ctrl;
|
|
|
|
|
|
|
|
keycode_lookup_table[VK_MENU] = key_alt;
|
|
|
|
keycode_lookup_table[VK_LMENU] = key_alt;
|
|
|
|
keycode_lookup_table[VK_RMENU] = key_alt;
|
|
|
|
|
|
|
|
keycode_lookup_table[VK_SHIFT] = key_shift;
|
|
|
|
keycode_lookup_table[VK_LSHIFT] = key_shift;
|
|
|
|
keycode_lookup_table[VK_RSHIFT] = key_shift;
|
|
|
|
|
|
|
|
keycode_lookup_table[VK_PAUSE] = key_pause;
|
|
|
|
keycode_lookup_table[VK_CAPITAL] = key_caps;
|
|
|
|
keycode_lookup_table[VK_NUMLOCK] = key_num_lock;
|
|
|
|
keycode_lookup_table[VK_SCROLL] = key_scroll_lock;
|
2019-02-24 07:22:16 +00:00
|
|
|
keycode_lookup_table[VK_APPS] = key_menu;
|
2019-02-13 22:14:27 +00:00
|
|
|
|
2016-05-14 20:11:52 +00:00
|
|
|
keycode_lookup_table[VK_F1] = key_f1;
|
|
|
|
keycode_lookup_table[VK_F2] = key_f2;
|
|
|
|
keycode_lookup_table[VK_F3] = key_f3;
|
|
|
|
keycode_lookup_table[VK_F4] = key_f4;
|
|
|
|
keycode_lookup_table[VK_F5] = key_f5;
|
|
|
|
keycode_lookup_table[VK_F6] = key_f6;
|
|
|
|
keycode_lookup_table[VK_F7] = key_f7;
|
|
|
|
keycode_lookup_table[VK_F8] = key_f8;
|
|
|
|
keycode_lookup_table[VK_F9] = key_f9;
|
|
|
|
|
|
|
|
keycode_lookup_table[VK_F10] = key_f10;
|
|
|
|
keycode_lookup_table[VK_F11] = key_f11;
|
|
|
|
keycode_lookup_table[VK_F12] = key_f12;
|
|
|
|
keycode_lookup_table[VK_F13] = key_f13;
|
|
|
|
keycode_lookup_table[VK_F14] = key_f14;
|
|
|
|
keycode_lookup_table[VK_F15] = key_f15;
|
|
|
|
keycode_lookup_table[VK_F16] = key_f16;
|
2016-05-14 20:08:11 +00:00
|
|
|
}
|
|
|
|
|
2016-05-29 03:12:12 +00:00
|
|
|
internal void
|
2019-07-21 18:16:34 +00:00
|
|
|
win32_resize(i32 width, i32 height){
|
2016-05-29 03:12:12 +00:00
|
|
|
if (width > 0 && height > 0){
|
2017-07-18 23:17:40 +00:00
|
|
|
target.width = width;
|
|
|
|
target.height = height;
|
2016-05-29 03:12:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-21 18:16:34 +00:00
|
|
|
#if 0
|
2017-01-29 00:03:23 +00:00
|
|
|
internal void
|
2017-11-10 21:13:02 +00:00
|
|
|
win32_init_gl(HDC hdc){
|
2019-07-21 18:16:34 +00:00
|
|
|
//LOG("trying to load wgl extensions...\n");
|
2017-11-10 21:13:02 +00:00
|
|
|
|
|
|
|
#define GLInitFail(s) system_error_box(FNLN "\nOpenGL init fail - " s )
|
|
|
|
|
|
|
|
// Init First Context
|
2018-11-20 08:18:54 +00:00
|
|
|
WNDCLASSA wglclass = {};
|
2017-11-10 21:13:02 +00:00
|
|
|
wglclass.lpfnWndProc = DefWindowProcA;
|
|
|
|
wglclass.hInstance = GetModuleHandle(0);
|
|
|
|
wglclass.lpszClassName = "4ed-wgl-loader";
|
|
|
|
if (RegisterClassA(&wglclass) == 0){
|
|
|
|
GLInitFail("RegisterClassA");
|
|
|
|
}
|
|
|
|
|
|
|
|
HWND hwglwnd = CreateWindowExA(0, wglclass.lpszClassName, "", 0, 0, 0, 0, 0, 0, 0, wglclass.hInstance, 0);
|
|
|
|
if (hwglwnd == 0){
|
|
|
|
GLInitFail("CreateWindowExA");
|
|
|
|
}
|
|
|
|
|
|
|
|
HDC hwgldc = GetDC(hwglwnd);
|
|
|
|
|
2018-11-20 08:18:54 +00:00
|
|
|
PIXELFORMATDESCRIPTOR format = {};
|
2017-07-18 23:23:36 +00:00
|
|
|
format.nSize = sizeof(format);
|
|
|
|
format.nVersion = 1;
|
2018-06-02 23:02:14 +00:00
|
|
|
//format.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
|
|
|
|
format.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
|
2017-07-18 23:23:36 +00:00
|
|
|
format.iPixelType = PFD_TYPE_RGBA;
|
|
|
|
format.cColorBits = 32;
|
2017-11-10 21:13:02 +00:00
|
|
|
format.cAlphaBits = 8;
|
2017-07-18 23:23:36 +00:00
|
|
|
format.cDepthBits = 24;
|
|
|
|
format.iLayerType = PFD_MAIN_PLANE;
|
2017-11-10 21:13:02 +00:00
|
|
|
i32 suggested_format_index = ChoosePixelFormat(hwgldc, &format);
|
|
|
|
if (suggested_format_index == 0){
|
2018-11-28 04:36:09 +00:00
|
|
|
win32_output_error_string(ErrorString_UseErrorBox);
|
2017-11-10 21:13:02 +00:00
|
|
|
GLInitFail("ChoosePixelFormat");
|
|
|
|
}
|
|
|
|
|
|
|
|
DescribePixelFormat(hwgldc, suggested_format_index, sizeof(format), &format);
|
|
|
|
if (!SetPixelFormat(hwgldc, suggested_format_index, &format)){
|
2018-11-28 04:36:09 +00:00
|
|
|
win32_output_error_string(ErrorString_UseErrorBox);
|
2017-11-10 21:13:02 +00:00
|
|
|
GLInitFail("SetPixelFormat");
|
|
|
|
}
|
|
|
|
|
|
|
|
HGLRC wglcontext = wglCreateContext(hwgldc);
|
|
|
|
if (wglcontext == 0){
|
2018-11-28 04:36:09 +00:00
|
|
|
win32_output_error_string(ErrorString_UseErrorBox);
|
2017-11-10 21:13:02 +00:00
|
|
|
GLInitFail("wglCreateContext");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!wglMakeCurrent(hwgldc, wglcontext)){
|
2018-11-28 04:36:09 +00:00
|
|
|
win32_output_error_string(ErrorString_UseErrorBox);
|
2017-11-10 21:13:02 +00:00
|
|
|
GLInitFail("wglMakeCurrent");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load wgl Extensions
|
|
|
|
#define LoadWGL(f, s) f = (f##_Function*)wglGetProcAddress(#f); b32 got_##f = GLFuncGood(f); \
|
|
|
|
if (!got_##f) { if (s) { GLInitFail(#f " missing"); } else { f = 0; } }
|
|
|
|
LoadWGL(wglCreateContextAttribsARB, true);
|
|
|
|
LoadWGL(wglChoosePixelFormatARB, true);
|
|
|
|
LoadWGL(wglGetExtensionsStringEXT, true);
|
|
|
|
|
2019-07-21 18:16:34 +00:00
|
|
|
//LOG("got wgl functions\n");
|
2017-11-10 21:13:02 +00:00
|
|
|
|
|
|
|
char *extensions_c = wglGetExtensionsStringEXT();
|
|
|
|
String extensions = make_string_slowly(extensions_c);
|
|
|
|
if (has_substr(extensions, make_lit_string("WGL_EXT_swap_interval"))){
|
|
|
|
LoadWGL(wglSwapIntervalEXT, false);
|
|
|
|
if (wglSwapIntervalEXT != 0){
|
2019-07-21 18:16:34 +00:00
|
|
|
//LOG("got wglSwapIntervalEXT\n");
|
2017-01-29 00:03:23 +00:00
|
|
|
}
|
2017-07-18 23:23:36 +00:00
|
|
|
}
|
|
|
|
|
2017-11-10 21:13:02 +00:00
|
|
|
// Init the Second Context
|
|
|
|
int pixel_attrib_list[] = {
|
|
|
|
WGL_DRAW_TO_WINDOW_ARB, TRUE,
|
|
|
|
WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
|
|
|
|
WGL_SUPPORT_OPENGL_ARB, TRUE,
|
2018-06-02 23:02:14 +00:00
|
|
|
//WGL_DOUBLE_BUFFER_ARB, TRUE,
|
|
|
|
WGL_DOUBLE_BUFFER_ARB, FALSE,
|
2017-11-10 21:13:02 +00:00
|
|
|
WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
u32 ignore = 0;
|
|
|
|
if (!wglChoosePixelFormatARB(hdc, pixel_attrib_list, 0, 1, &suggested_format_index, &ignore)){
|
|
|
|
GLInitFail("wglChoosePixelFormatARB");
|
|
|
|
}
|
|
|
|
|
|
|
|
DescribePixelFormat(hdc, suggested_format_index, sizeof(format), &format);
|
|
|
|
if (!SetPixelFormat(hdc, suggested_format_index, &format)){
|
|
|
|
GLInitFail("SetPixelFormat");
|
|
|
|
}
|
|
|
|
|
|
|
|
i32 context_attrib_list[] = {
|
|
|
|
WGL_CONTEXT_MAJOR_VERSION_ARB, 2,
|
|
|
|
WGL_CONTEXT_MINOR_VERSION_ARB, 1,
|
|
|
|
WGL_CONTEXT_FLAGS_ARB, 0,
|
|
|
|
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
HGLRC context = wglCreateContextAttribsARB(hdc, 0, context_attrib_list);
|
|
|
|
if (context == 0){
|
|
|
|
GLInitFail("wglCreateContextAttribsARB");
|
2017-07-18 23:23:36 +00:00
|
|
|
}
|
|
|
|
|
2017-11-10 21:13:02 +00:00
|
|
|
wglMakeCurrent(hdc, context);
|
|
|
|
|
|
|
|
if (wglSwapIntervalEXT != 0){
|
2019-07-21 18:16:34 +00:00
|
|
|
//LOGF("setting swap interval %d\n", 1);
|
2017-11-10 21:13:02 +00:00
|
|
|
wglSwapIntervalEXT(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
ReleaseDC(hwglwnd, hwgldc);
|
|
|
|
DestroyWindow(hwglwnd);
|
|
|
|
wglDeleteContext(wglcontext);
|
|
|
|
|
2019-07-21 18:16:34 +00:00
|
|
|
//LOG("successfully enabled opengl\n");
|
2017-01-29 00:03:23 +00:00
|
|
|
}
|
2019-07-21 18:16:34 +00:00
|
|
|
#endif
|
2017-01-29 00:03:23 +00:00
|
|
|
|
2016-05-29 03:12:12 +00:00
|
|
|
internal void
|
|
|
|
Win32SetCursorFromUpdate(Application_Mouse_Cursor cursor){
|
|
|
|
switch (cursor){
|
|
|
|
case APP_MOUSE_CURSOR_ARROW:
|
2017-10-31 17:29:52 +00:00
|
|
|
{
|
|
|
|
SetCursor(win32vars.cursor_arrow);
|
|
|
|
}break;
|
2016-05-29 03:12:12 +00:00
|
|
|
|
|
|
|
case APP_MOUSE_CURSOR_IBEAM:
|
2017-10-31 17:29:52 +00:00
|
|
|
{
|
|
|
|
SetCursor(win32vars.cursor_ibeam);
|
|
|
|
}break;
|
2016-05-29 03:12:12 +00:00
|
|
|
|
|
|
|
case APP_MOUSE_CURSOR_LEFTRIGHT:
|
2017-10-31 17:29:52 +00:00
|
|
|
{
|
|
|
|
SetCursor(win32vars.cursor_leftright);
|
|
|
|
}break;
|
2016-05-29 03:12:12 +00:00
|
|
|
|
|
|
|
case APP_MOUSE_CURSOR_UPDOWN:
|
2017-10-31 17:29:52 +00:00
|
|
|
{
|
|
|
|
SetCursor(win32vars.cursor_updown);
|
|
|
|
}break;
|
2016-05-29 03:12:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-04 01:33:44 +00:00
|
|
|
internal Win32_Object*
|
2019-08-04 05:36:13 +00:00
|
|
|
win32_alloc_object(Win32_Object_Kind kind){
|
2019-02-04 01:33:44 +00:00
|
|
|
Win32_Object *result = 0;
|
|
|
|
if (win32vars.free_win32_objects.next != &win32vars.free_win32_objects){
|
|
|
|
result = CastFromMember(Win32_Object, node, win32vars.free_win32_objects.next);
|
|
|
|
}
|
|
|
|
if (result == 0){
|
|
|
|
i32 count = 512;
|
|
|
|
Win32_Object *objects = (Win32_Object*)system_memory_allocate(count*sizeof(Win32_Object));
|
|
|
|
objects[0].node.prev = &win32vars.free_win32_objects;
|
|
|
|
win32vars.free_win32_objects.next = &objects[0].node;
|
|
|
|
for (i32 i = 1; i < count; i += 1){
|
|
|
|
objects[i - 1].node.next = &objects[i].node;
|
|
|
|
objects[i].node.prev = &objects[i - 1].node;
|
|
|
|
}
|
|
|
|
objects[count - 1].node.next = &win32vars.free_win32_objects;
|
|
|
|
win32vars.free_win32_objects.prev = &objects[count - 1].node;
|
|
|
|
result = CastFromMember(Win32_Object, node, win32vars.free_win32_objects.next);
|
|
|
|
}
|
|
|
|
Assert(result != 0);
|
|
|
|
dll_remove(&result->node);
|
2019-08-04 05:36:13 +00:00
|
|
|
block_zero_struct(result);
|
|
|
|
result->kind = kind;
|
2019-02-04 01:33:44 +00:00
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
|
|
|
win32_free_object(Win32_Object *object){
|
|
|
|
if (object->node.next != 0){
|
|
|
|
dll_remove(&object->node);
|
|
|
|
}
|
|
|
|
dll_insert(&win32vars.free_win32_objects, &object->node);
|
|
|
|
}
|
|
|
|
|
2019-08-04 05:36:13 +00:00
|
|
|
////////////////////////////////
|
|
|
|
|
2018-12-17 04:31:04 +00:00
|
|
|
internal
|
|
|
|
Sys_Now_Time_Sig(system_now_time){
|
2016-05-29 19:05:27 +00:00
|
|
|
u64 result = 0;
|
|
|
|
LARGE_INTEGER t;
|
|
|
|
if (QueryPerformanceCounter(&t)){
|
2019-02-04 01:33:44 +00:00
|
|
|
result = (u64)(t.QuadPart/win32vars.count_per_usecond);
|
2016-05-29 19:05:27 +00:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2019-02-04 01:33:44 +00:00
|
|
|
internal
|
|
|
|
Sys_Wake_Up_Timer_Create_Sig(system_wake_up_timer_create){
|
2019-08-04 05:36:13 +00:00
|
|
|
Win32_Object *object = win32_alloc_object(Win32ObjectKind_Timer);
|
2019-02-04 01:33:44 +00:00
|
|
|
dll_insert(&win32vars.timer_objects, &object->node);
|
|
|
|
object->timer.id = ++win32vars.timer_counter;
|
|
|
|
return(handle_type(object));
|
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_Wake_Up_Timer_Release_Sig(system_wake_up_timer_release){
|
|
|
|
Win32_Object *object = (Win32_Object*)handle_type_ptr(handle);
|
|
|
|
if (object->kind == Win32ObjectKind_Timer){
|
|
|
|
KillTimer(win32vars.window_handle, object->timer.id);
|
|
|
|
win32_free_object(object);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_Wake_Up_Timer_Set_Sig(system_wake_up_timer_set){
|
|
|
|
Win32_Object *object = (Win32_Object*)handle_type_ptr(handle);
|
|
|
|
if (object->kind == Win32ObjectKind_Timer){
|
|
|
|
object->timer.id = SetTimer(win32vars.window_handle, object->timer.id, time_milliseconds, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-13 04:19:02 +00:00
|
|
|
internal
|
|
|
|
Sys_Signal_Step_Sig(system_signal_step){
|
|
|
|
system_schedule_step(code);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_Sleep_Sig(system_sleep){
|
|
|
|
u32 milliseconds = (u32)(microseconds/Thousand(1));
|
|
|
|
Sleep(milliseconds);
|
|
|
|
}
|
|
|
|
|
2019-08-04 05:36:13 +00:00
|
|
|
////////////////////////////////
|
|
|
|
|
|
|
|
internal DWORD
|
|
|
|
win32_thread_wrapper(void *ptr){
|
|
|
|
Win32_Object *object = (Win32_Object*)ptr;
|
|
|
|
Thread_Function *proc = object->thread.proc;
|
|
|
|
void *object_ptr = object->thread.ptr;
|
2019-08-24 01:34:42 +00:00
|
|
|
EnterCriticalSection(&win32vars.thread_launch_mutex);
|
2019-08-04 05:36:13 +00:00
|
|
|
win32vars.waiting_for_launch = false;
|
|
|
|
WakeConditionVariable(&win32vars.thread_launch_cv);
|
2019-08-24 01:34:42 +00:00
|
|
|
LeaveCriticalSection(&win32vars.thread_launch_mutex);
|
2019-08-04 05:36:13 +00:00
|
|
|
proc(object_ptr);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_Thread_Launch_Sig(system_thread_launch){
|
|
|
|
Win32_Object *object = win32_alloc_object(Win32ObjectKind_Thread);
|
|
|
|
object->thread.proc = proc;
|
|
|
|
object->thread.ptr = ptr;
|
|
|
|
EnterCriticalSection(&win32vars.thread_launch_mutex);
|
|
|
|
win32vars.waiting_for_launch = true;
|
|
|
|
object->thread.thread = CreateThread(0, 0, win32_thread_wrapper, object, 0, 0);
|
|
|
|
for (;win32vars.waiting_for_launch;){
|
|
|
|
SleepConditionVariableCS(&win32vars.thread_launch_cv, &win32vars.thread_launch_mutex, INFINITE);
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(&win32vars.thread_launch_mutex);
|
|
|
|
return(handle_type(object));
|
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_Thread_Join_Sig(system_thread_join){
|
|
|
|
Win32_Object *object = (Win32_Object*)handle_type_ptr(thread);
|
|
|
|
if (object->kind == Win32ObjectKind_Thread){
|
|
|
|
WaitForSingleObject(object->thread.thread, INFINITE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_Thread_Free_Sig(system_thread_free){
|
|
|
|
Win32_Object *object = (Win32_Object*)handle_type_ptr(thread);
|
|
|
|
if (object->kind == Win32ObjectKind_Thread){
|
|
|
|
CloseHandle(object->thread.thread);
|
|
|
|
win32_free_object(object);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-16 02:54:06 +00:00
|
|
|
internal
|
|
|
|
Sys_Thread_Get_ID_Sig(system_thread_get_id){
|
|
|
|
DWORD result = GetCurrentThreadId();
|
|
|
|
return((i32)result);
|
|
|
|
}
|
|
|
|
|
2019-08-04 05:36:13 +00:00
|
|
|
internal
|
|
|
|
Sys_Mutex_Make_Sig(system_mutex_make){
|
|
|
|
Win32_Object *object = win32_alloc_object(Win32ObjectKind_Mutex);
|
|
|
|
InitializeCriticalSection(&object->mutex);
|
|
|
|
return(handle_type(object));
|
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_Mutex_Acquire_Sig(system_mutex_acquire){
|
|
|
|
Win32_Object *object = (Win32_Object*)handle_type_ptr(mutex);
|
|
|
|
if (object->kind == Win32ObjectKind_Mutex){
|
|
|
|
EnterCriticalSection(&object->mutex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_Mutex_Release_Sig(system_mutex_release){
|
|
|
|
Win32_Object *object = (Win32_Object*)handle_type_ptr(mutex);
|
|
|
|
if (object->kind == Win32ObjectKind_Mutex){
|
|
|
|
LeaveCriticalSection(&object->mutex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_Mutex_Free_Sig(system_mutex_free){
|
|
|
|
Win32_Object *object = (Win32_Object*)handle_type_ptr(mutex);
|
|
|
|
if (object->kind == Win32ObjectKind_Mutex){
|
|
|
|
DeleteCriticalSection(&object->mutex);
|
|
|
|
win32_free_object(object);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_Condition_Variable_Make_Sig(system_condition_variable_make){
|
|
|
|
Win32_Object *object = win32_alloc_object(Win32ObjectKind_CV);
|
|
|
|
InitializeConditionVariable(&object->cv);
|
|
|
|
return(handle_type(object));
|
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_Condition_Variable_Wait_Sig(system_condition_variable_wait){
|
|
|
|
Win32_Object *object_cv = (Win32_Object*)handle_type_ptr(cv);
|
|
|
|
Win32_Object *object_mutex = (Win32_Object*)handle_type_ptr(mutex);
|
|
|
|
if (object_cv->kind == Win32ObjectKind_CV &&
|
|
|
|
object_mutex->kind == Win32ObjectKind_Mutex){
|
|
|
|
SleepConditionVariableCS(&object_cv->cv, &object_mutex->mutex, INFINITE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_Condition_Variable_Signal_Sig(system_condition_variable_signal){
|
|
|
|
Win32_Object *object = (Win32_Object*)handle_type_ptr(cv);
|
|
|
|
if (object->kind == Win32ObjectKind_CV){
|
|
|
|
WakeConditionVariable(&object->cv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
|
|
|
Sys_Condition_Variable_Free_Sig(system_condition_variable_free){
|
|
|
|
Win32_Object *object = (Win32_Object*)handle_type_ptr(cv);
|
|
|
|
if (object->kind == Win32ObjectKind_CV){
|
|
|
|
win32_free_object(object);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////
|
|
|
|
|
2016-02-20 21:36:16 +00:00
|
|
|
internal LRESULT
|
2017-11-27 19:38:48 +00:00
|
|
|
win32_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
|
2016-06-13 11:50:28 +00:00
|
|
|
LRESULT result = 0;
|
2019-10-01 02:06:21 +00:00
|
|
|
Scratch_Block scratch(win32vars.tctx);
|
2016-09-01 00:26:52 +00:00
|
|
|
|
2016-02-20 21:36:16 +00:00
|
|
|
switch (uMsg){
|
2017-01-29 00:03:23 +00:00
|
|
|
case WM_MENUCHAR:break;
|
2016-06-07 17:22:42 +00:00
|
|
|
|
2016-03-21 03:58:34 +00:00
|
|
|
case WM_SYSKEYDOWN:
|
|
|
|
case WM_SYSKEYUP:
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
case WM_KEYUP:
|
2016-02-20 21:36:16 +00:00
|
|
|
{
|
2019-06-01 23:33:31 +00:00
|
|
|
b8 release = HasFlag(lParam, bit_32);
|
|
|
|
b8 down = !release;
|
|
|
|
b8 is_right = HasFlag(lParam, bit_25);
|
|
|
|
|
2016-03-21 03:58:34 +00:00
|
|
|
switch (wParam){
|
|
|
|
case VK_CONTROL:case VK_LCONTROL:case VK_RCONTROL:
|
|
|
|
case VK_MENU:case VK_LMENU:case VK_RMENU:
|
|
|
|
case VK_SHIFT:case VK_LSHIFT:case VK_RSHIFT:
|
2016-02-20 21:36:16 +00:00
|
|
|
{
|
2017-01-14 03:01:35 +00:00
|
|
|
Control_Keys *controls = &win32vars.input_chunk.pers.controls;
|
|
|
|
b8 *control_keys = win32vars.input_chunk.pers.control_keys;
|
2016-06-07 17:22:42 +00:00
|
|
|
|
2016-03-21 03:58:34 +00:00
|
|
|
if (wParam != 255){
|
|
|
|
switch (wParam){
|
|
|
|
case VK_SHIFT:
|
|
|
|
{
|
|
|
|
control_keys[MDFR_SHIFT_INDEX] = down;
|
|
|
|
}break;
|
|
|
|
case VK_CONTROL:
|
|
|
|
{
|
2019-06-01 23:33:31 +00:00
|
|
|
if (is_right){
|
|
|
|
controls->r_ctrl = down;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
controls->l_ctrl = down;
|
|
|
|
}
|
2016-03-21 03:58:34 +00:00
|
|
|
}break;
|
|
|
|
case VK_MENU:
|
|
|
|
{
|
2019-06-01 23:33:31 +00:00
|
|
|
if (is_right){
|
|
|
|
controls->r_alt = down;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
controls->l_alt = down;
|
|
|
|
}
|
2016-03-21 03:58:34 +00:00
|
|
|
}break;
|
2016-03-15 14:12:06 +00:00
|
|
|
}
|
2016-06-07 17:22:42 +00:00
|
|
|
|
2017-01-29 00:03:23 +00:00
|
|
|
b8 ctrl = (controls->r_ctrl || (controls->l_ctrl && !controls->r_alt));
|
|
|
|
b8 alt = (controls->l_alt || (controls->r_alt && !controls->l_ctrl));
|
2019-06-01 23:33:31 +00:00
|
|
|
if (win32vars.lctrl_lalt_is_altgr && controls->l_alt && controls->l_ctrl){
|
|
|
|
ctrl = false;
|
|
|
|
alt = false;
|
2016-03-15 14:12:06 +00:00
|
|
|
}
|
2016-03-21 03:58:34 +00:00
|
|
|
control_keys[MDFR_CONTROL_INDEX] = ctrl;
|
|
|
|
control_keys[MDFR_ALT_INDEX] = alt;
|
|
|
|
}
|
|
|
|
}break;
|
2019-02-13 22:14:27 +00:00
|
|
|
}
|
|
|
|
|
2019-06-01 23:33:31 +00:00
|
|
|
if (down){
|
2019-02-13 22:14:27 +00:00
|
|
|
Key_Code key = keycode_lookup_table[(u8)wParam];
|
|
|
|
if (key != 0){
|
|
|
|
i32 *count = &win32vars.input_chunk.trans.key_data.count;
|
|
|
|
Key_Event_Data *data = win32vars.input_chunk.trans.key_data.keys;
|
|
|
|
b8 *control_keys = win32vars.input_chunk.pers.control_keys;
|
|
|
|
i32 control_keys_size = sizeof(win32vars.input_chunk.pers.control_keys);
|
2016-05-05 23:32:46 +00:00
|
|
|
|
2019-02-24 22:54:57 +00:00
|
|
|
if (*count < KEY_INPUT_BUFFER_SIZE){
|
|
|
|
data[*count].character = 0;
|
|
|
|
data[*count].character_no_caps_lock = 0;
|
|
|
|
data[*count].keycode = key;
|
|
|
|
memcpy(data[*count].modifiers, control_keys, control_keys_size);
|
|
|
|
++(*count);
|
|
|
|
}
|
2019-02-13 22:14:27 +00:00
|
|
|
|
|
|
|
win32vars.got_useful_event = true;
|
|
|
|
}
|
|
|
|
}
|
2016-03-21 03:58:34 +00:00
|
|
|
}break;
|
2016-05-05 23:32:46 +00:00
|
|
|
|
2017-01-29 00:03:23 +00:00
|
|
|
case WM_CHAR: case WM_SYSCHAR: case WM_UNICHAR:
|
|
|
|
{
|
2017-02-12 06:01:01 +00:00
|
|
|
u16 character = (u16)wParam;
|
2017-01-29 00:03:23 +00:00
|
|
|
|
|
|
|
if (character == '\r'){
|
|
|
|
character = '\n';
|
|
|
|
}
|
2017-02-12 06:01:01 +00:00
|
|
|
else if (character == '\t'){
|
2018-03-03 07:46:44 +00:00
|
|
|
// Do nothing
|
2017-02-12 06:01:01 +00:00
|
|
|
}
|
|
|
|
else if (character < 32 || character == 127){
|
2017-01-29 00:03:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-02-12 06:01:01 +00:00
|
|
|
u16 character_no_caps_lock = character;
|
2017-01-29 00:03:23 +00:00
|
|
|
|
|
|
|
i32 *count = &win32vars.input_chunk.trans.key_data.count;
|
|
|
|
Key_Event_Data *data = win32vars.input_chunk.trans.key_data.keys;
|
|
|
|
b8 *control_keys = win32vars.input_chunk.pers.control_keys;
|
|
|
|
i32 control_keys_size = sizeof(win32vars.input_chunk.pers.control_keys);
|
|
|
|
|
|
|
|
BYTE state[256];
|
|
|
|
GetKeyboardState(state);
|
|
|
|
if (state[VK_CAPITAL]){
|
|
|
|
if (character_no_caps_lock >= 'a' && character_no_caps_lock <= 'z'){
|
2017-02-12 06:01:01 +00:00
|
|
|
character_no_caps_lock -= (u8)('a' - 'A');
|
2017-01-29 00:03:23 +00:00
|
|
|
}
|
|
|
|
else if (character_no_caps_lock >= 'A' && character_no_caps_lock <= 'Z'){
|
|
|
|
character_no_caps_lock += (u8)('a' - 'A');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-24 22:54:57 +00:00
|
|
|
if (*count < KEY_INPUT_BUFFER_SIZE){
|
|
|
|
data[*count].character = character;
|
|
|
|
data[*count].character_no_caps_lock = character_no_caps_lock;
|
|
|
|
data[*count].keycode = character_no_caps_lock;
|
|
|
|
memcpy(data[*count].modifiers, control_keys, control_keys_size);
|
|
|
|
++(*count);
|
|
|
|
}
|
2017-01-29 00:03:23 +00:00
|
|
|
|
2017-06-20 20:37:45 +00:00
|
|
|
win32vars.got_useful_event = true;
|
2017-01-29 00:03:23 +00:00
|
|
|
}break;
|
|
|
|
|
2016-03-21 03:58:34 +00:00
|
|
|
case WM_MOUSEMOVE:
|
|
|
|
{
|
2019-02-25 23:42:13 +00:00
|
|
|
Vec2_i32 new_m = V2i32(LOWORD(lParam), HIWORD(lParam));
|
|
|
|
if (new_m != win32vars.input_chunk.pers.mouse){
|
|
|
|
win32vars.input_chunk.pers.mouse = new_m;
|
2017-06-20 20:37:45 +00:00
|
|
|
win32vars.got_useful_event = true;
|
2016-05-04 23:21:30 +00:00
|
|
|
}
|
2016-03-21 03:58:34 +00:00
|
|
|
}break;
|
2016-06-07 17:22:42 +00:00
|
|
|
|
2016-03-21 03:58:34 +00:00
|
|
|
case WM_MOUSEWHEEL:
|
|
|
|
{
|
2017-06-20 20:37:45 +00:00
|
|
|
win32vars.got_useful_event = true;
|
2017-03-25 03:42:16 +00:00
|
|
|
i32 rotation = GET_WHEEL_DELTA_WPARAM(wParam);
|
2016-03-21 03:58:34 +00:00
|
|
|
if (rotation > 0){
|
2017-11-11 01:21:50 +00:00
|
|
|
win32vars.input_chunk.trans.mouse_wheel = -100;
|
2016-03-21 03:58:34 +00:00
|
|
|
}
|
|
|
|
else{
|
2017-11-11 01:21:50 +00:00
|
|
|
win32vars.input_chunk.trans.mouse_wheel = 100;
|
2016-03-21 03:58:34 +00:00
|
|
|
}
|
|
|
|
}break;
|
2016-06-07 17:22:42 +00:00
|
|
|
|
2016-03-21 03:58:34 +00:00
|
|
|
case WM_LBUTTONDOWN:
|
|
|
|
{
|
2017-06-20 20:37:45 +00:00
|
|
|
win32vars.got_useful_event = true;
|
2016-03-21 03:58:34 +00:00
|
|
|
win32vars.input_chunk.trans.mouse_l_press = 1;
|
|
|
|
win32vars.input_chunk.pers.mouse_l = 1;
|
|
|
|
}break;
|
2016-06-07 17:22:42 +00:00
|
|
|
|
2016-03-21 03:58:34 +00:00
|
|
|
case WM_RBUTTONDOWN:
|
|
|
|
{
|
2017-06-20 20:37:45 +00:00
|
|
|
win32vars.got_useful_event = true;
|
2016-03-21 03:58:34 +00:00
|
|
|
win32vars.input_chunk.trans.mouse_r_press = 1;
|
|
|
|
win32vars.input_chunk.pers.mouse_r = 1;
|
|
|
|
}break;
|
2016-06-07 17:22:42 +00:00
|
|
|
|
2016-03-21 03:58:34 +00:00
|
|
|
case WM_LBUTTONUP:
|
|
|
|
{
|
2017-06-20 20:37:45 +00:00
|
|
|
win32vars.got_useful_event = true;
|
2016-03-21 03:58:34 +00:00
|
|
|
win32vars.input_chunk.trans.mouse_l_release = 1;
|
|
|
|
win32vars.input_chunk.pers.mouse_l = 0;
|
|
|
|
}break;
|
2016-06-07 17:22:42 +00:00
|
|
|
|
2016-03-21 03:58:34 +00:00
|
|
|
case WM_RBUTTONUP:
|
|
|
|
{
|
2017-06-20 20:37:45 +00:00
|
|
|
win32vars.got_useful_event = true;
|
2016-03-21 03:58:34 +00:00
|
|
|
win32vars.input_chunk.trans.mouse_r_release = 1;
|
|
|
|
win32vars.input_chunk.pers.mouse_r = 0;
|
|
|
|
}break;
|
2016-06-07 17:22:42 +00:00
|
|
|
|
2016-03-21 03:58:34 +00:00
|
|
|
case WM_KILLFOCUS:
|
|
|
|
case WM_SETFOCUS:
|
|
|
|
{
|
2017-06-20 20:37:45 +00:00
|
|
|
win32vars.got_useful_event = true;
|
2016-03-21 03:58:34 +00:00
|
|
|
win32vars.input_chunk.pers.mouse_l = 0;
|
|
|
|
win32vars.input_chunk.pers.mouse_r = 0;
|
2017-01-14 03:01:35 +00:00
|
|
|
for (i32 i = 0; i < MDFR_INDEX_COUNT; ++i){
|
2016-09-08 22:03:43 +00:00
|
|
|
win32vars.input_chunk.pers.control_keys[i] = 0;
|
|
|
|
}
|
2016-09-08 00:32:31 +00:00
|
|
|
win32vars.input_chunk.pers.controls = null_control_keys;
|
2016-03-21 03:58:34 +00:00
|
|
|
}break;
|
2016-06-07 17:22:42 +00:00
|
|
|
|
2016-03-21 03:58:34 +00:00
|
|
|
case WM_SIZE:
|
|
|
|
{
|
2017-06-20 20:37:45 +00:00
|
|
|
win32vars.got_useful_event = true;
|
2017-01-29 00:03:23 +00:00
|
|
|
i32 new_width = LOWORD(lParam);
|
|
|
|
i32 new_height = HIWORD(lParam);
|
|
|
|
|
2019-07-21 18:16:34 +00:00
|
|
|
win32_resize(new_width, new_height);
|
2016-03-21 03:58:34 +00:00
|
|
|
}break;
|
2016-06-07 17:22:42 +00:00
|
|
|
|
2017-03-27 22:36:42 +00:00
|
|
|
case WM_DISPLAYCHANGE:
|
|
|
|
{
|
2017-06-20 20:37:45 +00:00
|
|
|
win32vars.got_useful_event = true;
|
2017-03-27 22:36:42 +00:00
|
|
|
|
|
|
|
LONG_PTR style = GetWindowLongPtr(hwnd, GWL_STYLE);
|
|
|
|
if (!(style & WS_OVERLAPPEDWINDOW)){
|
|
|
|
MONITORINFO monitor_info = {sizeof(MONITORINFO)};
|
|
|
|
if(GetMonitorInfo(MonitorFromWindow(hwnd, MONITOR_DEFAULTTOPRIMARY), &monitor_info))
|
|
|
|
{
|
|
|
|
SetWindowPos(hwnd, HWND_TOP,
|
|
|
|
monitor_info.rcMonitor.left, monitor_info.rcMonitor.top,
|
|
|
|
monitor_info.rcMonitor.right - monitor_info.rcMonitor.left,
|
|
|
|
monitor_info.rcMonitor.bottom - monitor_info.rcMonitor.top,
|
|
|
|
SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}break;
|
|
|
|
|
2016-03-21 03:58:34 +00:00
|
|
|
case WM_PAINT:
|
|
|
|
{
|
2017-06-20 20:37:45 +00:00
|
|
|
win32vars.got_useful_event = true;
|
2016-03-21 03:58:34 +00:00
|
|
|
PAINTSTRUCT ps;
|
|
|
|
HDC hdc = BeginPaint(hwnd, &ps);
|
2017-11-10 18:27:39 +00:00
|
|
|
// NOTE(allen): Do nothing?
|
2016-03-21 03:58:34 +00:00
|
|
|
EndPaint(hwnd, &ps);
|
|
|
|
}break;
|
2016-06-07 17:22:42 +00:00
|
|
|
|
2017-11-27 19:38:48 +00:00
|
|
|
case WM_CLIPBOARDUPDATE:
|
|
|
|
{
|
|
|
|
win32vars.got_useful_event = true;
|
2019-08-16 15:01:17 +00:00
|
|
|
LogEventLit(win32vars.log_string(M), scratch, 0, 0, system_thread_get_id(),
|
2019-08-16 02:54:06 +00:00
|
|
|
"new clipboard contents");
|
2017-11-27 19:38:48 +00:00
|
|
|
}break;
|
|
|
|
|
2016-05-27 17:11:38 +00:00
|
|
|
case WM_CLOSE:
|
2016-03-21 03:58:34 +00:00
|
|
|
case WM_DESTROY:
|
|
|
|
{
|
2017-06-20 20:37:45 +00:00
|
|
|
win32vars.got_useful_event = true;
|
2017-11-07 21:35:26 +00:00
|
|
|
win32vars.input_chunk.trans.trying_to_kill = true;
|
2016-03-21 03:58:34 +00:00
|
|
|
}break;
|
2016-06-07 17:22:42 +00:00
|
|
|
|
2019-02-04 01:33:44 +00:00
|
|
|
case WM_TIMER:
|
|
|
|
{
|
|
|
|
UINT_PTR timer_id = (UINT_PTR)wParam;
|
|
|
|
KillTimer(win32vars.window_handle, timer_id);
|
|
|
|
win32vars.got_useful_event = true;
|
|
|
|
}break;
|
|
|
|
|
2016-05-04 23:21:30 +00:00
|
|
|
case WM_4coder_ANIMATE:
|
2017-02-03 00:52:39 +00:00
|
|
|
{
|
2017-06-20 20:37:45 +00:00
|
|
|
win32vars.got_useful_event = true;
|
2017-02-03 00:52:39 +00:00
|
|
|
}break;
|
2016-05-04 23:21:30 +00:00
|
|
|
|
2016-03-21 03:58:34 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
result = DefWindowProc(hwnd, uMsg, wParam, lParam);
|
|
|
|
}break;
|
|
|
|
}
|
2016-09-01 00:26:52 +00:00
|
|
|
|
2016-05-26 02:42:02 +00:00
|
|
|
return(result);
|
2016-02-20 21:36:16 +00:00
|
|
|
}
|
|
|
|
|
2019-07-21 18:16:34 +00:00
|
|
|
////////////////////////////////
|
|
|
|
|
|
|
|
internal b32
|
|
|
|
win32_wgl_good(Void_Func *f){
|
|
|
|
return(f != 0 &&
|
|
|
|
f != (Void_Func*)1 &&
|
|
|
|
f != (Void_Func*)2 &&
|
|
|
|
f != (Void_Func*)3 &&
|
|
|
|
f != (Void_Func*)-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef HGLRC (wglCreateContextAttribsARB_Function)(HDC,HGLRC,i32*);
|
|
|
|
typedef BOOL (wglChoosePixelFormatARB_Function)(HDC,i32*,f32*,u32,i32*,u32*);
|
|
|
|
typedef char* (wglGetExtensionsStringEXT_Function)();
|
|
|
|
typedef VOID (wglSwapIntervalEXT_Function)(i32);
|
|
|
|
|
|
|
|
global wglCreateContextAttribsARB_Function *wglCreateContextAttribsARB = 0;
|
|
|
|
global wglChoosePixelFormatARB_Function *wglChoosePixelFormatARB = 0;
|
|
|
|
global wglGetExtensionsStringEXT_Function *wglGetExtensionsStringEXT = 0;
|
|
|
|
global wglSwapIntervalEXT_Function *wglSwapIntervalEXT = 0;
|
|
|
|
|
|
|
|
// TODO(allen): This requires all windows to be handled on a single thread.
|
|
|
|
// We would need a platform side thread context to get around this which would
|
|
|
|
// probably mean thread local storage would have to get involved.
|
|
|
|
global HWND win32_current_gl_window = 0;
|
|
|
|
|
|
|
|
internal b32
|
|
|
|
win32_gl_create_window(HWND *wnd_out, HGLRC *context_out, DWORD style, RECT rect){
|
|
|
|
HINSTANCE this_instance = GetModuleHandle(0);
|
|
|
|
|
|
|
|
local_persist b32 srgb_support = false;
|
|
|
|
local_persist b32 register_success = true;
|
|
|
|
local_persist b32 first_call = true;
|
|
|
|
if (first_call){
|
|
|
|
first_call = false;
|
|
|
|
|
|
|
|
// NOTE(allen): Create the GL bootstrap window
|
|
|
|
WNDCLASSW wglclass = {};
|
|
|
|
wglclass.lpfnWndProc = DefWindowProcW;
|
|
|
|
wglclass.hInstance = this_instance;
|
|
|
|
wglclass.lpszClassName = L"wgl-loader";
|
|
|
|
if (RegisterClassW(&wglclass) == 0){
|
|
|
|
register_success = false;
|
|
|
|
goto fail_register;
|
|
|
|
}
|
|
|
|
|
|
|
|
HWND wglwindow = CreateWindowW(wglclass.lpszClassName, L"", 0, 0, 0, 0, 0,
|
|
|
|
0, 0, this_instance, 0);
|
|
|
|
if (wglwindow == 0){
|
|
|
|
register_success = false;
|
|
|
|
goto fail_register;
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE(allen): Create the GL bootstrap context
|
|
|
|
HDC wgldc = GetDC(wglwindow);
|
|
|
|
|
|
|
|
PIXELFORMATDESCRIPTOR format = {};
|
|
|
|
format.nSize = sizeof(format);
|
|
|
|
format.nVersion = 1;
|
|
|
|
format.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
|
|
|
|
format.iPixelType = PFD_TYPE_RGBA;
|
|
|
|
format.cColorBits = 32;
|
|
|
|
format.cAlphaBits = 8;
|
|
|
|
format.cDepthBits = 24;
|
|
|
|
format.iLayerType = PFD_MAIN_PLANE;
|
|
|
|
i32 suggested_format_index = ChoosePixelFormat(wgldc, &format);
|
|
|
|
if (!SetPixelFormat(wgldc, suggested_format_index, &format)){
|
|
|
|
register_success = false;
|
|
|
|
goto fail_register;
|
|
|
|
}
|
|
|
|
|
|
|
|
HGLRC wglcontext = wglCreateContext(wgldc);
|
|
|
|
if (wglcontext == 0){
|
|
|
|
register_success = false;
|
|
|
|
goto fail_register;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!wglMakeCurrent(wgldc, wglcontext)){
|
|
|
|
register_success = false;
|
|
|
|
goto fail_register;
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE(allen): Load wgl extensions
|
|
|
|
#define LoadWGL(f,l) Stmnt((f) = (f##_Function*)wglGetProcAddress(#f); \
|
|
|
|
(l) = (l) && win32_wgl_good((Void_Func*)(f));)
|
|
|
|
|
|
|
|
b32 load_success = true;
|
|
|
|
LoadWGL(wglCreateContextAttribsARB, load_success);
|
|
|
|
LoadWGL(wglChoosePixelFormatARB, load_success);
|
|
|
|
LoadWGL(wglGetExtensionsStringEXT, load_success);
|
|
|
|
|
|
|
|
if (!load_success){
|
|
|
|
register_success = false;
|
|
|
|
goto fail_register;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *extensions_c = wglGetExtensionsStringEXT();
|
|
|
|
String_Const_u8 extensions = SCu8((u8*)extensions_c);
|
|
|
|
|
|
|
|
{
|
|
|
|
String_Const_u8 s = string_skip_whitespace(extensions);
|
|
|
|
for (;s.size > 0;){
|
|
|
|
umem end = string_find_first_whitespace(s);
|
|
|
|
String_Const_u8 m = string_prefix(s, end);
|
|
|
|
if (string_match(m, string_u8_litexpr("WGL_EXT_framebuffer_sRGB")) ||
|
|
|
|
string_match(m, string_u8_litexpr("WGL_ARB_framebuffer_sRGB"))){
|
|
|
|
srgb_support = true;
|
|
|
|
}
|
|
|
|
else if (string_match(m, string_u8_litexpr("WGL_EXT_swap_interval"))){
|
|
|
|
b32 wgl_swap_interval_ext = true;
|
|
|
|
LoadWGL(wglSwapIntervalEXT, wgl_swap_interval_ext);
|
|
|
|
if (!wgl_swap_interval_ext){
|
|
|
|
wglSwapIntervalEXT = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s = string_skip_whitespace(string_skip(s, end));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE(allen): Load gl functions
|
|
|
|
#define GL_FUNC(f,R,P) LoadWGL(f,load_success);
|
|
|
|
#include "opengl/4ed_opengl_funcs.h"
|
|
|
|
|
|
|
|
if (!load_success){
|
|
|
|
register_success = false;
|
|
|
|
goto fail_register;
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE(allen): Cleanup the GL bootstrap resources
|
|
|
|
ReleaseDC(wglwindow, wgldc);
|
|
|
|
DestroyWindow(wglwindow);
|
|
|
|
wglDeleteContext(wglcontext);
|
|
|
|
|
|
|
|
// NOTE(allen): Register the graphics window class
|
|
|
|
WNDCLASSW wndclass = {};
|
|
|
|
wndclass.style = CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS;
|
|
|
|
wndclass.lpfnWndProc = win32_proc;
|
|
|
|
wndclass.hInstance = this_instance;
|
|
|
|
wndclass.lpszClassName = L"GRAPHICS-WINDOW-NAME";
|
|
|
|
if (RegisterClassW(&wndclass) == 0){
|
|
|
|
register_success = false;
|
|
|
|
goto fail_register;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fail_register:;
|
|
|
|
|
|
|
|
b32 result = false;
|
|
|
|
if (register_success){
|
|
|
|
// NOTE(allen): Create the graphics window
|
|
|
|
HWND wnd = CreateWindowExW(0, L"GRAPHICS-WINDOW-NAME", L"GRAPHICS", style,
|
|
|
|
CW_USEDEFAULT, CW_USEDEFAULT, rect.right - rect.left, rect.bottom - rect.top,
|
|
|
|
0, 0, this_instance, 0);
|
|
|
|
|
|
|
|
*wnd_out = 0;
|
|
|
|
*context_out = 0;
|
|
|
|
if (wnd != 0){
|
|
|
|
HDC dc = GetDC(wnd);
|
|
|
|
|
|
|
|
PIXELFORMATDESCRIPTOR format = {};
|
|
|
|
|
|
|
|
i32 pixel_attrib_list[] = {
|
|
|
|
/* 0*/WGL_DRAW_TO_WINDOW_ARB, TRUE,
|
|
|
|
/* 2*/WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
|
|
|
|
/* 4*/WGL_SUPPORT_OPENGL_ARB, TRUE,
|
|
|
|
/* 6*/WGL_DOUBLE_BUFFER_ARB, false,
|
|
|
|
/* 8*/WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
|
|
|
|
/*10*/WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB, GL_TRUE,
|
|
|
|
/*12*/0,
|
|
|
|
};
|
|
|
|
if (!srgb_support){
|
|
|
|
pixel_attrib_list[10] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
i32 suggested_format_index = 0;
|
|
|
|
u32 ignore = 0;
|
|
|
|
if (!wglChoosePixelFormatARB(dc, pixel_attrib_list, 0, 1, &suggested_format_index, &ignore)){
|
|
|
|
goto fail_window_init;
|
|
|
|
}
|
|
|
|
|
|
|
|
DescribePixelFormat(dc, suggested_format_index, sizeof(format), &format);
|
|
|
|
if (!SetPixelFormat(dc, suggested_format_index, &format)){
|
|
|
|
goto fail_window_init;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
i32 context_attrib_list[] = {
|
|
|
|
/*0*/WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
|
|
|
|
/*2*/WGL_CONTEXT_MINOR_VERSION_ARB, 2,
|
|
|
|
/*4*/WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
|
|
|
|
#if GL_DEBUG_MODE
|
|
|
|
|WGL_CONTEXT_DEBUG_BIT_ARB
|
|
|
|
#endif
|
|
|
|
,
|
|
|
|
/*6*/WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
|
|
|
|
/*8*/0
|
|
|
|
};
|
|
|
|
#else
|
|
|
|
i32 context_attrib_list[] = {
|
|
|
|
WGL_CONTEXT_MAJOR_VERSION_ARB, 2,
|
|
|
|
WGL_CONTEXT_MINOR_VERSION_ARB, 1,
|
|
|
|
WGL_CONTEXT_FLAGS_ARB, 0,
|
|
|
|
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
HGLRC context = wglCreateContextAttribsARB(dc, 0, context_attrib_list);
|
|
|
|
if (context == 0){
|
|
|
|
goto fail_window_init;
|
|
|
|
}
|
|
|
|
|
|
|
|
wglMakeCurrent(dc, context);
|
|
|
|
win32_current_gl_window = wnd;
|
|
|
|
if (wglSwapIntervalEXT != 0){
|
|
|
|
wglSwapIntervalEXT(1);
|
|
|
|
}
|
|
|
|
*wnd_out = wnd;
|
|
|
|
*context_out = context;
|
|
|
|
result = true;
|
|
|
|
|
|
|
|
if (false){
|
|
|
|
fail_window_init:;
|
|
|
|
DWORD error = GetLastError();
|
|
|
|
ReleaseDC(wnd, dc);
|
|
|
|
DestroyWindow(wnd);
|
|
|
|
SetLastError(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////
|
|
|
|
|
2017-07-18 17:19:59 +00:00
|
|
|
#include "4ed_link_system_functions.cpp"
|
2017-07-18 23:17:40 +00:00
|
|
|
#include "4ed_shared_init_logic.cpp"
|
2017-07-18 17:19:59 +00:00
|
|
|
|
2017-02-25 01:53:40 +00:00
|
|
|
int CALL_CONVENTION
|
2017-02-03 00:52:39 +00:00
|
|
|
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
|
2016-08-29 01:03:26 +00:00
|
|
|
i32 argc = __argc;
|
2016-05-10 17:36:53 +00:00
|
|
|
char **argv = __argv;
|
|
|
|
|
2017-07-19 20:23:39 +00:00
|
|
|
//
|
|
|
|
// System Linkage
|
|
|
|
//
|
|
|
|
|
2019-07-24 07:41:40 +00:00
|
|
|
sysfunc.font_make_face = ft__font_make_face;
|
|
|
|
sysfunc.get_texture = gl__get_texture;
|
|
|
|
sysfunc.fill_texture = gl__fill_texture;
|
2017-07-19 20:23:39 +00:00
|
|
|
link_system_code();
|
|
|
|
|
|
|
|
//
|
|
|
|
// Memory init
|
|
|
|
//
|
|
|
|
|
2019-10-01 02:06:21 +00:00
|
|
|
Thread_Context _tctx = {};
|
|
|
|
thread_ctx_init(&_tctx, get_base_allocator_system(&sysfunc));
|
2019-08-16 15:01:17 +00:00
|
|
|
|
2019-10-01 02:06:21 +00:00
|
|
|
block_zero_struct(&win32vars);
|
|
|
|
win32vars.tctx = &_tctx;
|
|
|
|
|
|
|
|
// TODO(allen): *arena;
|
|
|
|
target.arena = make_arena_system(&sysfunc);
|
2016-05-29 17:07:24 +00:00
|
|
|
|
2019-10-01 02:06:21 +00:00
|
|
|
memset(&plat_settings, 0, sizeof(plat_settings));
|
2019-08-16 15:21:32 +00:00
|
|
|
|
2017-07-19 16:33:12 +00:00
|
|
|
memset(&libraries, 0, sizeof(libraries));
|
|
|
|
memset(&app, 0, sizeof(app));
|
|
|
|
memset(&custom_api, 0, sizeof(custom_api));
|
2016-09-01 20:29:07 +00:00
|
|
|
|
2017-10-31 17:29:52 +00:00
|
|
|
win32vars.cursor_show = MouseCursorShow_Always;
|
|
|
|
win32vars.prev_cursor_show = MouseCursorShow_Always;
|
|
|
|
|
2019-02-04 01:33:44 +00:00
|
|
|
dll_init_sentinel(&win32vars.free_win32_objects);
|
|
|
|
dll_init_sentinel(&win32vars.timer_objects);
|
|
|
|
|
2019-08-04 05:36:13 +00:00
|
|
|
InitializeCriticalSection(&win32vars.thread_launch_mutex);
|
|
|
|
InitializeConditionVariable(&win32vars.thread_launch_cv);
|
|
|
|
|
2017-07-19 20:23:39 +00:00
|
|
|
//
|
2018-12-17 04:31:04 +00:00
|
|
|
// HACK(allen):
|
2017-07-19 20:23:39 +00:00
|
|
|
// Previously zipped stuff is here, it should be zipped in the new pattern now.
|
|
|
|
//
|
|
|
|
|
2017-07-19 16:33:12 +00:00
|
|
|
init_shared_vars();
|
2017-07-18 19:52:41 +00:00
|
|
|
|
2019-10-01 02:06:21 +00:00
|
|
|
load_app_code(win32vars.tctx);
|
2019-08-16 02:54:06 +00:00
|
|
|
win32vars.log_string = app.get_logger(&sysfunc);
|
2019-10-01 02:06:21 +00:00
|
|
|
void *base_ptr = read_command_line(win32vars.tctx, argc, argv);
|
2016-05-29 17:07:24 +00:00
|
|
|
|
2017-11-28 19:11:44 +00:00
|
|
|
//
|
|
|
|
// Load Custom Code
|
|
|
|
//
|
|
|
|
|
|
|
|
#if defined(FRED_SUPER)
|
2019-10-01 02:06:21 +00:00
|
|
|
load_custom_code(win32vars.tctx);
|
2017-11-28 19:11:44 +00:00
|
|
|
#else
|
|
|
|
custom_api.get_bindings = get_bindings;
|
|
|
|
#endif
|
|
|
|
|
2019-09-28 00:49:59 +00:00
|
|
|
SetProcessDPIAware();
|
|
|
|
|
|
|
|
{
|
|
|
|
HDC dc = GetDC(0);
|
|
|
|
i32 x_dpi = GetDeviceCaps(dc, LOGPIXELSX);
|
|
|
|
i32 y_dpi = GetDeviceCaps(dc, LOGPIXELSY);
|
|
|
|
i32 max_dpi = max(x_dpi, y_dpi);
|
|
|
|
win32vars.screen_scale_factor = ((f32)max_dpi)/96.f;
|
|
|
|
ReleaseDC(0, dc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-29 17:07:24 +00:00
|
|
|
//
|
|
|
|
// Window and GL Initialization
|
|
|
|
//
|
2016-05-10 17:36:53 +00:00
|
|
|
|
2018-11-20 08:18:54 +00:00
|
|
|
RECT window_rect = {};
|
2017-07-18 21:19:28 +00:00
|
|
|
if (plat_settings.set_window_size){
|
|
|
|
window_rect.right = plat_settings.window_w;
|
|
|
|
window_rect.bottom = plat_settings.window_h;
|
2016-02-20 21:36:16 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
window_rect.right = 800;
|
|
|
|
window_rect.bottom = 600;
|
|
|
|
}
|
2016-05-29 17:07:24 +00:00
|
|
|
|
2016-02-20 21:36:16 +00:00
|
|
|
if (!AdjustWindowRect(&window_rect, WS_OVERLAPPEDWINDOW, false)){
|
2019-07-21 18:16:34 +00:00
|
|
|
//LOG("Could not get adjusted window.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
i32 window_style = WS_OVERLAPPEDWINDOW;
|
|
|
|
if (!plat_settings.fullscreen_window && plat_settings.maximize_window){
|
|
|
|
window_style |= WS_MAXIMIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
HGLRC window_opengl_context = 0;
|
|
|
|
if (!win32_gl_create_window(&win32vars.window_handle, &window_opengl_context, window_style, window_rect)){
|
|
|
|
exit(1);
|
|
|
|
}
|
2017-03-13 23:48:11 +00:00
|
|
|
|
2019-07-21 18:16:34 +00:00
|
|
|
GetClientRect(win32vars.window_handle, &window_rect);
|
|
|
|
win32_resize(window_rect.right - window_rect.left, window_rect.bottom - window_rect.top);
|
2016-05-29 17:07:24 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Misc System Initializations
|
|
|
|
//
|
|
|
|
|
2017-11-27 19:38:48 +00:00
|
|
|
if (!AddClipboardFormatListener(win32vars.window_handle)){
|
2019-10-01 02:06:21 +00:00
|
|
|
Scratch_Block scratch(win32vars.tctx, Scratch_Share);
|
|
|
|
win32_output_error_string(scratch, ErrorString_UseLog);
|
2017-11-27 19:38:48 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 20:04:45 +00:00
|
|
|
win32vars.clipboard_arena = reserve_arena(win32vars.tctx);
|
2017-03-23 23:40:16 +00:00
|
|
|
|
2016-02-20 21:36:16 +00:00
|
|
|
win32vars.clipboard_sequence = GetClipboardSequenceNumber();
|
|
|
|
if (win32vars.clipboard_sequence == 0){
|
2019-10-01 02:06:21 +00:00
|
|
|
Scratch_Block scratch(win32vars.tctx, Scratch_Share);
|
|
|
|
win32_post_clipboard(scratch, "", 0);
|
2016-05-29 17:07:24 +00:00
|
|
|
|
2016-02-20 21:36:16 +00:00
|
|
|
win32vars.clipboard_sequence = GetClipboardSequenceNumber();
|
|
|
|
win32vars.next_clipboard_is_self = 0;
|
2016-05-29 17:07:24 +00:00
|
|
|
|
2016-02-20 21:36:16 +00:00
|
|
|
if (win32vars.clipboard_sequence == 0){
|
2016-05-29 19:05:27 +00:00
|
|
|
OutputDebugStringA("Failure while initializing clipboard\n");
|
2016-02-20 21:36:16 +00:00
|
|
|
}
|
2016-05-03 16:15:08 +00:00
|
|
|
}
|
2016-02-20 21:36:16 +00:00
|
|
|
else{
|
2019-10-01 02:06:21 +00:00
|
|
|
Scratch_Block scratch(win32vars.tctx, Scratch_Share);
|
|
|
|
win32_read_clipboard_contents(scratch);
|
2016-02-20 21:36:16 +00:00
|
|
|
}
|
2016-05-29 17:07:24 +00:00
|
|
|
|
2019-07-21 18:16:34 +00:00
|
|
|
win32_keycode_init();
|
2016-05-29 17:07:24 +00:00
|
|
|
|
|
|
|
win32vars.cursor_ibeam = LoadCursor(NULL, IDC_IBEAM);
|
|
|
|
win32vars.cursor_arrow = LoadCursor(NULL, IDC_ARROW);
|
|
|
|
win32vars.cursor_leftright = LoadCursor(NULL, IDC_SIZEWE);
|
|
|
|
win32vars.cursor_updown = LoadCursor(NULL, IDC_SIZENS);
|
|
|
|
|
2016-05-29 19:05:27 +00:00
|
|
|
LARGE_INTEGER f;
|
|
|
|
if (QueryPerformanceFrequency(&f)){
|
2017-06-16 20:57:02 +00:00
|
|
|
win32vars.count_per_usecond = (f32)f.QuadPart / 1000000.f;
|
2016-05-29 19:05:27 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
// NOTE(allen): Just guess.
|
2017-06-16 20:57:02 +00:00
|
|
|
win32vars.count_per_usecond = 1.f;
|
2016-05-29 19:05:27 +00:00
|
|
|
}
|
2017-06-16 20:57:02 +00:00
|
|
|
Assert(win32vars.count_per_usecond > 0.f);
|
2016-05-29 19:05:27 +00:00
|
|
|
|
2016-05-29 17:07:24 +00:00
|
|
|
//
|
2017-07-19 20:13:38 +00:00
|
|
|
// App init
|
2016-05-29 17:07:24 +00:00
|
|
|
//
|
|
|
|
|
2019-07-24 07:41:40 +00:00
|
|
|
{
|
2019-10-01 02:06:21 +00:00
|
|
|
Scratch_Block scratch(win32vars.tctx, Scratch_Share);
|
|
|
|
String_Const_u8 curdir = sysfunc.get_current_path(scratch);
|
2019-07-24 07:41:40 +00:00
|
|
|
curdir = string_mod_replace_character(curdir, '\\', '/');
|
2019-10-01 02:06:21 +00:00
|
|
|
app.init(&sysfunc, &target, base_ptr, win32vars.clipboard_contents, curdir, custom_api);
|
2019-07-24 07:41:40 +00:00
|
|
|
}
|
2016-05-29 17:07:24 +00:00
|
|
|
|
2017-07-19 20:13:38 +00:00
|
|
|
//
|
|
|
|
// Main loop
|
|
|
|
//
|
|
|
|
|
2017-07-18 22:09:16 +00:00
|
|
|
b32 keep_running = true;
|
2017-06-16 20:57:02 +00:00
|
|
|
win32vars.first = true;
|
2016-05-03 16:15:08 +00:00
|
|
|
timeBeginPeriod(1);
|
2016-05-10 17:36:53 +00:00
|
|
|
|
2017-07-18 21:19:28 +00:00
|
|
|
if (plat_settings.fullscreen_window){
|
2017-07-18 22:09:16 +00:00
|
|
|
win32_toggle_fullscreen();
|
2016-09-01 03:06:46 +00:00
|
|
|
}
|
2016-05-29 19:05:27 +00:00
|
|
|
|
2016-05-29 17:07:24 +00:00
|
|
|
SetForegroundWindow(win32vars.window_handle);
|
|
|
|
SetActiveWindow(win32vars.window_handle);
|
2016-09-01 00:26:52 +00:00
|
|
|
ShowWindow(win32vars.window_handle, SW_SHOW);
|
2016-05-10 17:36:53 +00:00
|
|
|
|
2019-07-21 18:16:34 +00:00
|
|
|
//LOG("Beginning main loop\n");
|
2018-12-17 04:31:04 +00:00
|
|
|
u64 timer_start = system_now_time();
|
2016-02-20 21:36:16 +00:00
|
|
|
MSG msg;
|
2017-07-18 22:09:16 +00:00
|
|
|
for (;keep_running;){
|
2016-05-10 17:36:53 +00:00
|
|
|
// TODO(allen): Find a good way to wait on a pipe
|
2017-11-11 00:58:47 +00:00
|
|
|
// without interfering with the reading process.
|
2018-12-17 04:31:04 +00:00
|
|
|
// NOTE(allen): Looks like we can ReadFile with a
|
2017-11-11 00:58:47 +00:00
|
|
|
// size of zero in an IOCP for this effect.
|
2017-07-18 22:34:57 +00:00
|
|
|
if (!win32vars.first){
|
2017-02-03 00:52:39 +00:00
|
|
|
if (win32vars.running_cli == 0){
|
|
|
|
win32vars.got_useful_event = false;
|
|
|
|
}
|
|
|
|
|
2017-01-29 00:03:23 +00:00
|
|
|
b32 get_more_messages = true;
|
|
|
|
do{
|
2018-08-05 07:09:18 +00:00
|
|
|
if (win32vars.got_useful_event == 0){
|
2017-01-29 00:03:23 +00:00
|
|
|
get_more_messages = GetMessage(&msg, 0, 0, 0);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
get_more_messages = PeekMessage(&msg, 0, 0, 0, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_more_messages){
|
|
|
|
if (msg.message == WM_QUIT){
|
2017-07-18 22:09:16 +00:00
|
|
|
keep_running = false;
|
2017-01-29 00:03:23 +00:00
|
|
|
}else{
|
|
|
|
b32 treat_normally = true;
|
|
|
|
if (msg.message == WM_KEYDOWN || msg.message == WM_SYSKEYDOWN){
|
|
|
|
switch (msg.wParam){
|
|
|
|
case VK_CONTROL:case VK_LCONTROL:case VK_RCONTROL:
|
|
|
|
case VK_MENU:case VK_LMENU:case VK_RMENU:
|
|
|
|
case VK_SHIFT:case VK_LSHIFT:case VK_RSHIFT:break;
|
|
|
|
|
|
|
|
default: treat_normally = false; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (treat_normally){
|
2016-09-02 15:58:04 +00:00
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
2017-01-29 00:03:23 +00:00
|
|
|
else{
|
|
|
|
Control_Keys *controls = &win32vars.input_chunk.pers.controls;
|
|
|
|
|
|
|
|
b8 ctrl = (controls->r_ctrl || (controls->l_ctrl && !controls->r_alt));
|
|
|
|
b8 alt = (controls->l_alt || (controls->r_alt && !controls->l_ctrl));
|
|
|
|
|
|
|
|
if (win32vars.lctrl_lalt_is_altgr){
|
|
|
|
if (controls->l_alt && controls->l_ctrl){
|
|
|
|
ctrl = 0;
|
|
|
|
alt = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BYTE ctrl_state = 0, alt_state = 0;
|
|
|
|
BYTE state[256];
|
|
|
|
if (ctrl || alt){
|
|
|
|
GetKeyboardState(state);
|
|
|
|
if (ctrl){
|
|
|
|
ctrl_state = state[VK_CONTROL];
|
|
|
|
state[VK_CONTROL] = 0;
|
|
|
|
}
|
|
|
|
if (alt){
|
|
|
|
alt_state = state[VK_MENU];
|
|
|
|
state[VK_MENU] = 0;
|
|
|
|
}
|
|
|
|
SetKeyboardState(state);
|
|
|
|
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
|
|
|
|
if (ctrl){
|
|
|
|
state[VK_CONTROL] = ctrl_state;
|
|
|
|
}
|
|
|
|
if (alt){
|
|
|
|
state[VK_MENU] = alt_state;
|
|
|
|
}
|
|
|
|
SetKeyboardState(state);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
|
|
|
}
|
2016-05-10 17:36:53 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-18 22:34:57 +00:00
|
|
|
}while (get_more_messages);
|
2016-05-04 23:21:30 +00:00
|
|
|
}
|
|
|
|
|
2017-11-11 00:58:47 +00:00
|
|
|
// NOTE(allen): Mouse Out of Window Detection
|
2016-05-29 19:05:27 +00:00
|
|
|
POINT mouse_point;
|
|
|
|
if (GetCursorPos(&mouse_point) &&
|
|
|
|
ScreenToClient(win32vars.window_handle, &mouse_point)){
|
2016-05-27 17:11:38 +00:00
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
i32_Rect screen;
|
|
|
|
screen.x0 = 0;
|
|
|
|
screen.y0 = 0;
|
2017-07-18 23:17:40 +00:00
|
|
|
screen.x1 = target.width;
|
|
|
|
screen.y1 = target.height;
|
2017-01-23 06:19:43 +00:00
|
|
|
|
|
|
|
i32 mx = mouse_point.x;
|
|
|
|
i32 my = mouse_point.y;
|
|
|
|
|
|
|
|
b32 is_hit = false;
|
|
|
|
if (mx >= screen.x0 && mx < screen.x1 && my >= screen.y0 && my < screen.y1){
|
|
|
|
is_hit = true;
|
|
|
|
}
|
2016-05-29 19:05:27 +00:00
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
if (!is_hit){
|
2017-11-11 00:58:47 +00:00
|
|
|
win32vars.input_chunk.trans.out_of_window = true;
|
2016-05-27 17:11:38 +00:00
|
|
|
}
|
|
|
|
|
2019-02-25 23:42:13 +00:00
|
|
|
win32vars.input_chunk.pers.mouse = V2i32(mouse_point.x, mouse_point.y);
|
2016-05-29 19:05:27 +00:00
|
|
|
}
|
|
|
|
else{
|
2017-11-11 00:58:47 +00:00
|
|
|
win32vars.input_chunk.trans.out_of_window = true;
|
2016-05-29 19:05:27 +00:00
|
|
|
}
|
|
|
|
|
2017-11-11 00:58:47 +00:00
|
|
|
// NOTE(allen): Prepare the Frame Input
|
|
|
|
|
|
|
|
// TODO(allen): CROSS REFERENCE WITH LINUX SPECIAL CODE "TIC898989"
|
2016-05-29 19:05:27 +00:00
|
|
|
Win32_Input_Chunk input_chunk = win32vars.input_chunk;
|
2016-09-01 20:29:07 +00:00
|
|
|
win32vars.input_chunk.trans = null_input_chunk_transient;
|
2016-05-29 19:05:27 +00:00
|
|
|
|
|
|
|
input_chunk.pers.control_keys[MDFR_CAPS_INDEX] = GetKeyState(VK_CAPITAL) & 0x1;
|
|
|
|
|
2018-11-20 08:18:54 +00:00
|
|
|
Application_Step_Input input = {};
|
2016-05-29 19:28:29 +00:00
|
|
|
|
2018-08-05 07:09:18 +00:00
|
|
|
input.first_step = win32vars.first;
|
|
|
|
input.dt = frame_useconds/1000000.f;
|
|
|
|
|
|
|
|
input.keys = input_chunk.trans.key_data;
|
2018-12-17 04:31:04 +00:00
|
|
|
memcpy(input.keys.modifiers, input_chunk.pers.control_keys, sizeof(input.keys.modifiers));
|
2018-08-05 07:09:18 +00:00
|
|
|
|
|
|
|
input.mouse.out_of_window = input_chunk.trans.out_of_window;
|
|
|
|
|
|
|
|
input.mouse.l = input_chunk.pers.mouse_l;
|
|
|
|
input.mouse.press_l = input_chunk.trans.mouse_l_press;
|
|
|
|
input.mouse.release_l = input_chunk.trans.mouse_l_release;
|
|
|
|
|
|
|
|
input.mouse.r = input_chunk.pers.mouse_r;
|
|
|
|
input.mouse.press_r = input_chunk.trans.mouse_r_press;
|
|
|
|
input.mouse.release_r = input_chunk.trans.mouse_r_release;
|
|
|
|
|
|
|
|
input.mouse.wheel = input_chunk.trans.mouse_wheel;
|
2019-02-25 23:42:13 +00:00
|
|
|
input.mouse.p = input_chunk.pers.mouse;
|
2018-08-05 07:09:18 +00:00
|
|
|
|
|
|
|
input.trying_to_kill = input_chunk.trans.trying_to_kill;
|
|
|
|
|
|
|
|
// TODO(allen): Not really appropriate to round trip this all the way to the OS layer, redo this system.
|
|
|
|
// NOTE(allen): Ask the Core About Exiting if We Have an Exit Signal
|
|
|
|
if (win32vars.send_exit_signal){
|
|
|
|
input.trying_to_kill = true;
|
|
|
|
win32vars.send_exit_signal = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE(allen): Frame Clipboard Input
|
2019-08-16 15:01:17 +00:00
|
|
|
block_zero_struct(&win32vars.clipboard_contents);
|
2019-03-15 08:38:28 +00:00
|
|
|
input.clipboard_changed = false;
|
2018-08-05 07:09:18 +00:00
|
|
|
if (win32vars.clipboard_sequence != 0){
|
|
|
|
DWORD new_number = GetClipboardSequenceNumber();
|
|
|
|
if (new_number != win32vars.clipboard_sequence){
|
|
|
|
if (win32vars.next_clipboard_is_self){
|
|
|
|
win32vars.next_clipboard_is_self = false;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
for (i32 R = 0; R < 4; ++R){
|
2019-10-01 02:06:21 +00:00
|
|
|
Scratch_Block scratch(win32vars.tctx, Scratch_Share);
|
|
|
|
if (win32_read_clipboard_contents(scratch)){
|
2019-03-15 08:38:28 +00:00
|
|
|
input.clipboard_changed = true;
|
2018-08-05 07:09:18 +00:00
|
|
|
break;
|
2018-05-07 02:47:22 +00:00
|
|
|
}
|
2018-03-03 07:46:44 +00:00
|
|
|
}
|
2017-11-11 00:58:47 +00:00
|
|
|
}
|
2019-03-15 08:38:28 +00:00
|
|
|
win32vars.clipboard_sequence = new_number;
|
2017-11-11 00:58:47 +00:00
|
|
|
}
|
|
|
|
}
|
2019-07-21 18:16:34 +00:00
|
|
|
input.clipboard = win32vars.clipboard_contents;
|
2016-05-29 19:05:27 +00:00
|
|
|
|
2019-06-01 23:33:31 +00:00
|
|
|
win32vars.clip_post.size = 0;
|
2017-11-13 22:12:04 +00:00
|
|
|
|
2016-09-01 20:29:07 +00:00
|
|
|
|
2017-11-11 00:58:47 +00:00
|
|
|
// NOTE(allen): Application Core Update
|
2018-11-20 08:18:54 +00:00
|
|
|
Application_Step_Result result = {};
|
2017-11-12 19:15:11 +00:00
|
|
|
if (app.step != 0){
|
2019-10-01 02:06:21 +00:00
|
|
|
result = app.step(&sysfunc, &target, base_ptr, &input);
|
2017-11-12 19:13:04 +00:00
|
|
|
}
|
2017-11-12 19:15:11 +00:00
|
|
|
else{
|
2019-07-21 18:16:34 +00:00
|
|
|
//LOG("app.step == 0 -- skipping\n");
|
2017-11-12 19:15:11 +00:00
|
|
|
}
|
2016-05-29 19:05:27 +00:00
|
|
|
|
2017-11-11 00:58:47 +00:00
|
|
|
// NOTE(allen): Finish the Loop
|
2016-05-29 19:05:27 +00:00
|
|
|
if (result.perform_kill){
|
2017-07-18 22:09:16 +00:00
|
|
|
keep_running = false;
|
2016-05-29 19:05:27 +00:00
|
|
|
}
|
|
|
|
|
2017-11-13 22:12:04 +00:00
|
|
|
// NOTE(allen): Post New Clipboard Content
|
2019-06-01 23:33:31 +00:00
|
|
|
if (win32vars.clip_post.size > 0){
|
2019-10-01 02:06:21 +00:00
|
|
|
Scratch_Block scratch(win32vars.tctx, Scratch_Share);
|
|
|
|
win32_post_clipboard(scratch, (char*)win32vars.clip_post.str, (i32)win32vars.clip_post.size);
|
2017-11-13 22:12:04 +00:00
|
|
|
}
|
|
|
|
|
2017-11-30 19:02:37 +00:00
|
|
|
// NOTE(allen): Switch to New Title
|
|
|
|
if (result.has_new_title){
|
2019-10-01 02:06:21 +00:00
|
|
|
Scratch_Block scratch(win32vars.tctx, Scratch_Share);
|
|
|
|
SetWindowText_utf8(scratch, win32vars.window_handle, (u8*)result.title_string);
|
2017-11-30 19:02:37 +00:00
|
|
|
}
|
|
|
|
|
2017-11-11 00:58:47 +00:00
|
|
|
// NOTE(allen): Switch to New Cursor
|
2016-05-29 19:05:27 +00:00
|
|
|
Win32SetCursorFromUpdate(result.mouse_cursor_type);
|
2017-10-31 17:29:52 +00:00
|
|
|
if (win32vars.cursor_show != win32vars.prev_cursor_show){
|
|
|
|
win32vars.prev_cursor_show = win32vars.cursor_show;
|
|
|
|
switch (win32vars.cursor_show){
|
|
|
|
case MouseCursorShow_Never:
|
|
|
|
{
|
|
|
|
i32 counter = 0;
|
|
|
|
do{
|
|
|
|
counter = ShowCursor(false);
|
|
|
|
}while(counter >= 0);
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case MouseCursorShow_Always:
|
|
|
|
{
|
|
|
|
i32 counter = 0;
|
|
|
|
do{
|
|
|
|
counter = ShowCursor(true);
|
|
|
|
}while(counter <= 0);
|
|
|
|
}break;
|
|
|
|
|
|
|
|
// TODO(allen): MouseCursorShow_HideWhenStill
|
|
|
|
}
|
|
|
|
}
|
2017-11-11 00:58:47 +00:00
|
|
|
|
2019-02-04 01:33:44 +00:00
|
|
|
// NOTE(allen): update lctrl_lalt_is_altgr status
|
|
|
|
win32vars.lctrl_lalt_is_altgr = (b8)result.lctrl_lalt_is_altgr;
|
2016-05-29 19:05:27 +00:00
|
|
|
|
2019-02-04 01:33:44 +00:00
|
|
|
// NOTE(allen): render
|
2016-05-29 19:05:27 +00:00
|
|
|
HDC hdc = GetDC(win32vars.window_handle);
|
2019-07-21 18:16:34 +00:00
|
|
|
gl_render(&target, &shared_vars.pixel_scratch);
|
2017-11-10 18:27:39 +00:00
|
|
|
SwapBuffers(hdc);
|
2016-05-29 19:05:27 +00:00
|
|
|
ReleaseDC(win32vars.window_handle, hdc);
|
2016-07-19 23:47:27 +00:00
|
|
|
|
2019-02-04 01:33:44 +00:00
|
|
|
// NOTE(allen): toggle full screen
|
2017-11-11 00:58:47 +00:00
|
|
|
if (win32vars.do_toggle){
|
|
|
|
win32_toggle_fullscreen();
|
|
|
|
win32vars.do_toggle = false;
|
|
|
|
}
|
2016-05-29 19:05:27 +00:00
|
|
|
|
2019-02-04 01:33:44 +00:00
|
|
|
// NOTE(allen): schedule another step if needed
|
2016-05-29 19:05:27 +00:00
|
|
|
if (result.animating){
|
2019-08-13 04:19:02 +00:00
|
|
|
system_schedule_step(0);
|
2016-05-29 19:05:27 +00:00
|
|
|
}
|
|
|
|
|
2019-02-04 01:33:44 +00:00
|
|
|
// NOTE(allen): sleep a bit to cool off :)
|
2018-12-17 04:31:04 +00:00
|
|
|
u64 timer_end = system_now_time();
|
2016-05-29 19:05:27 +00:00
|
|
|
u64 end_target = timer_start + frame_useconds;
|
|
|
|
|
2019-02-04 01:33:44 +00:00
|
|
|
for (;timer_end < end_target;){
|
|
|
|
DWORD samount = (DWORD)((end_target - timer_end)/1000);
|
|
|
|
if (samount > 0){
|
|
|
|
Sleep(samount);
|
|
|
|
}
|
2018-12-17 04:31:04 +00:00
|
|
|
timer_end = system_now_time();
|
2016-05-29 19:05:27 +00:00
|
|
|
}
|
2018-12-17 04:31:04 +00:00
|
|
|
timer_start = system_now_time();
|
2017-11-11 00:58:47 +00:00
|
|
|
|
2019-02-04 01:33:44 +00:00
|
|
|
win32vars.first = false;
|
2016-02-20 21:36:16 +00:00
|
|
|
}
|
2016-05-27 17:11:38 +00:00
|
|
|
|
2016-05-29 17:07:24 +00:00
|
|
|
return(0);
|
2016-02-20 21:36:16 +00:00
|
|
|
}
|
|
|
|
|
2017-03-23 22:45:32 +00:00
|
|
|
#include "win32_utf8.cpp"
|
2017-03-12 01:20:24 +00:00
|
|
|
|
2016-05-29 03:12:12 +00:00
|
|
|
#if 0
|
2017-03-27 01:52:06 +00:00
|
|
|
// NOTE(allen): In case I want to switch back to a console application at some point.
|
2016-05-29 03:12:12 +00:00
|
|
|
int main(int argc, char **argv){
|
|
|
|
HINSTANCE hInstance = GetModuleHandle(0);
|
2017-03-12 01:20:24 +00:00
|
|
|
}
|
2016-05-29 03:12:12 +00:00
|
|
|
#endif
|
2017-03-12 01:20:24 +00:00
|
|
|
|
|
|
|
// BOTTOM
|
|
|
|
|