change rate limitting in win32 a bit, fixed up bad calls to BeginPaint, and got rid of OWNDC
This commit is contained in:
parent
319bae8799
commit
c56703cbc8
7
4ed.cpp
7
4ed.cpp
|
@ -1148,7 +1148,6 @@ COMMAND_DECL(to_lowercase){
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND_DECL(clean_all_lines){
|
COMMAND_DECL(clean_all_lines){
|
||||||
|
|
||||||
USE_MODELS(models);
|
USE_MODELS(models);
|
||||||
REQ_OPEN_VIEW(view);
|
REQ_OPEN_VIEW(view);
|
||||||
REQ_FILE(file, view);
|
REQ_FILE(file, view);
|
||||||
|
@ -1157,21 +1156,19 @@ COMMAND_DECL(clean_all_lines){
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND_DECL(eol_dosify){
|
COMMAND_DECL(eol_dosify){
|
||||||
|
|
||||||
REQ_READABLE_VIEW(view);
|
REQ_READABLE_VIEW(view);
|
||||||
REQ_FILE(file, view);
|
REQ_FILE(file, view);
|
||||||
|
|
||||||
file->settings.dos_write_mode = 1;
|
file->settings.dos_write_mode = 1;
|
||||||
file->state.last_4ed_edit_time = system->time();
|
file->state.last_4ed_edit_time = system->now_time_stamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND_DECL(eol_nixify){
|
COMMAND_DECL(eol_nixify){
|
||||||
|
|
||||||
REQ_READABLE_VIEW(view);
|
REQ_READABLE_VIEW(view);
|
||||||
REQ_FILE(file, view);
|
REQ_FILE(file, view);
|
||||||
|
|
||||||
file->settings.dos_write_mode = 0;
|
file->settings.dos_write_mode = 0;
|
||||||
file->state.last_4ed_edit_time = system->time();
|
file->state.last_4ed_edit_time = system->now_time_stamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND_DECL(auto_tab_range){
|
COMMAND_DECL(auto_tab_range){
|
||||||
|
|
|
@ -1162,8 +1162,9 @@ file_post_redo(General_Memory *general, Editing_File *file, Edit_Step step){
|
||||||
inv_step.child_count = step.inverse_child_count;
|
inv_step.child_count = step.inverse_child_count;
|
||||||
inv_step.inverse_child_count = step.child_count;
|
inv_step.inverse_child_count = step.child_count;
|
||||||
|
|
||||||
if (redo->edit_count == redo->edit_max)
|
if (redo->edit_count == redo->edit_max){
|
||||||
undo_stack_grow_edits(general, redo);
|
undo_stack_grow_edits(general, redo);
|
||||||
|
}
|
||||||
redo->edits[redo->edit_count++] = inv_step;
|
redo->edits[redo->edit_count++] = inv_step;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1805,7 +1806,7 @@ file_pre_edit_maintenance(System_Functions *system,
|
||||||
file->state.swap_stack.tokens = 0;
|
file->state.swap_stack.tokens = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
file->state.last_4ed_edit_time = system->time();
|
file->state.last_4ed_edit_time = system->now_time_stamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Cursor_Fix_Descriptor{
|
struct Cursor_Fix_Descriptor{
|
||||||
|
|
17
4ed_system.h
17
4ed_system.h
|
@ -35,9 +35,16 @@ uhash_equal(Unique_Hash a, Unique_Hash b){
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NOTE(allen): These two time functions should return values
|
||||||
|
// in the same time space. There is no requirement about
|
||||||
|
// resolution but the higher the better. These functions
|
||||||
|
// should not be used for profiling purposes.
|
||||||
#define Sys_File_Time_Stamp_Sig(name) u64 name(char *filename)
|
#define Sys_File_Time_Stamp_Sig(name) u64 name(char *filename)
|
||||||
typedef Sys_File_Time_Stamp_Sig(System_File_Time_Stamp);
|
typedef Sys_File_Time_Stamp_Sig(System_File_Time_Stamp);
|
||||||
|
|
||||||
|
#define Sys_Now_Time_Stamp_Sig(name) u64 name()
|
||||||
|
typedef Sys_Now_Time_Stamp_Sig(System_Now_Time_Stamp);
|
||||||
|
|
||||||
// TODO(allen): make directory a char* to signal that it must be null terminated
|
// TODO(allen): make directory a char* to signal that it must be null terminated
|
||||||
#define Sys_Set_File_List_Sig(name) void name(File_List *file_list, String directory)
|
#define Sys_Set_File_List_Sig(name) void name(File_List *file_list, String directory)
|
||||||
typedef Sys_Set_File_List_Sig(System_Set_File_List);
|
typedef Sys_Set_File_List_Sig(System_Set_File_List);
|
||||||
|
@ -66,13 +73,9 @@ typedef Sys_File_Load_End_Sig(System_File_Load_End);
|
||||||
#define Sys_File_Save_Sig(name) b32 name(char *filename, char *buffer, i32 size)
|
#define Sys_File_Save_Sig(name) b32 name(char *filename, char *buffer, i32 size)
|
||||||
typedef Sys_File_Save_Sig(System_File_Save);
|
typedef Sys_File_Save_Sig(System_File_Save);
|
||||||
|
|
||||||
|
|
||||||
#define Sys_Post_Clipboard_Sig(name) void name(String str)
|
#define Sys_Post_Clipboard_Sig(name) void name(String str)
|
||||||
typedef Sys_Post_Clipboard_Sig(System_Post_Clipboard);
|
typedef Sys_Post_Clipboard_Sig(System_Post_Clipboard);
|
||||||
|
|
||||||
#define Sys_Time_Sig(name) u64 name()
|
|
||||||
typedef Sys_Time_Sig(System_Time);
|
|
||||||
|
|
||||||
// cli
|
// cli
|
||||||
struct CLI_Handles{
|
struct CLI_Handles{
|
||||||
Plat_Handle proc;
|
Plat_Handle proc;
|
||||||
|
@ -217,8 +220,9 @@ typedef INTERNAL_Sys_Get_Thread_States_Sig(INTERNAL_System_Get_Thread_States);
|
||||||
typedef INTERNAL_Sys_Debug_Message_Sig(INTERNAL_System_Debug_Message);
|
typedef INTERNAL_Sys_Debug_Message_Sig(INTERNAL_System_Debug_Message);
|
||||||
|
|
||||||
struct System_Functions{
|
struct System_Functions{
|
||||||
// files: 6
|
// files: 7
|
||||||
System_File_Time_Stamp *file_time_stamp;
|
System_File_Time_Stamp *file_time_stamp;
|
||||||
|
System_Now_Time_Stamp *now_time_stamp;
|
||||||
System_Set_File_List *set_file_list;
|
System_Set_File_List *set_file_list;
|
||||||
System_File_Unique_Hash *file_unique_hash;
|
System_File_Unique_Hash *file_unique_hash;
|
||||||
System_File_Track *file_track;
|
System_File_Track *file_track;
|
||||||
|
@ -235,9 +239,6 @@ struct System_Functions{
|
||||||
// clipboard: 1
|
// clipboard: 1
|
||||||
System_Post_Clipboard *post_clipboard;
|
System_Post_Clipboard *post_clipboard;
|
||||||
|
|
||||||
// time: 1
|
|
||||||
System_Time *time;
|
|
||||||
|
|
||||||
// coroutine: 4
|
// coroutine: 4
|
||||||
System_Create_Coroutine *create_coroutine;
|
System_Create_Coroutine *create_coroutine;
|
||||||
System_Launch_Coroutine *launch_coroutine;
|
System_Launch_Coroutine *launch_coroutine;
|
||||||
|
|
466
win32_4ed.cpp
466
win32_4ed.cpp
|
@ -114,31 +114,9 @@ struct Sys_Bubble : public Bubble{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct Win32_Vars{
|
struct Win32_Vars{
|
||||||
HWND window_handle;
|
System_Functions system;
|
||||||
Render_Target target;
|
App_Functions app;
|
||||||
|
Custom_API custom_api;
|
||||||
Win32_Input_Chunk input_chunk;
|
|
||||||
b32 lctrl_lalt_is_altgr;
|
|
||||||
b32 got_useful_event;
|
|
||||||
|
|
||||||
HCURSOR cursor_ibeam;
|
|
||||||
HCURSOR cursor_arrow;
|
|
||||||
HCURSOR cursor_leftright;
|
|
||||||
HCURSOR cursor_updown;
|
|
||||||
String clipboard_contents;
|
|
||||||
b32 next_clipboard_is_self;
|
|
||||||
DWORD clipboard_sequence;
|
|
||||||
|
|
||||||
Thread_Group groups[THREAD_GROUP_COUNT];
|
|
||||||
CRITICAL_SECTION locks[LOCK_COUNT];
|
|
||||||
CRITICAL_SECTION DEBUG_sysmem_lock;
|
|
||||||
|
|
||||||
Thread_Memory *thread_memory;
|
|
||||||
|
|
||||||
u64 performance_frequency;
|
|
||||||
u64 start_pcount;
|
|
||||||
u64 start_time;
|
|
||||||
|
|
||||||
#if UseWinDll
|
#if UseWinDll
|
||||||
HMODULE app_code;
|
HMODULE app_code;
|
||||||
HMODULE custom;
|
HMODULE custom;
|
||||||
|
@ -147,22 +125,44 @@ struct Win32_Vars{
|
||||||
DLL_Loaded custom_dll;
|
DLL_Loaded custom_dll;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Plat_Settings settings;
|
||||||
|
|
||||||
|
|
||||||
|
Thread_Group groups[THREAD_GROUP_COUNT];
|
||||||
|
CRITICAL_SECTION locks[LOCK_COUNT];
|
||||||
|
CRITICAL_SECTION DEBUG_sysmem_lock;
|
||||||
|
Thread_Memory *thread_memory;
|
||||||
|
Win32_Coroutine coroutine_data[18];
|
||||||
|
Win32_Coroutine *coroutine_free;
|
||||||
|
|
||||||
|
|
||||||
|
Win32_Input_Chunk input_chunk;
|
||||||
|
b32 lctrl_lalt_is_altgr;
|
||||||
|
b32 got_useful_event;
|
||||||
|
|
||||||
|
|
||||||
|
HCURSOR cursor_ibeam;
|
||||||
|
HCURSOR cursor_arrow;
|
||||||
|
HCURSOR cursor_leftright;
|
||||||
|
HCURSOR cursor_updown;
|
||||||
|
String clipboard_contents;
|
||||||
|
b32 next_clipboard_is_self;
|
||||||
|
DWORD clipboard_sequence;
|
||||||
|
|
||||||
|
|
||||||
|
HWND window_handle;
|
||||||
|
Render_Target target;
|
||||||
Partition font_part;
|
Partition font_part;
|
||||||
|
|
||||||
Plat_Settings settings;
|
|
||||||
System_Functions *system;
|
u64 count_per_usecond;
|
||||||
App_Functions app;
|
|
||||||
Custom_API custom_api;
|
|
||||||
b32 first;
|
b32 first;
|
||||||
|
i32 running_cli;
|
||||||
|
|
||||||
|
|
||||||
#if FRED_INTERNAL
|
#if FRED_INTERNAL
|
||||||
Sys_Bubble internal_bubble;
|
Sys_Bubble internal_bubble;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Win32_Coroutine coroutine_data[18];
|
|
||||||
Win32_Coroutine *coroutine_free;
|
|
||||||
|
|
||||||
i32 running_cli;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
globalvar Win32_Vars win32vars;
|
globalvar Win32_Vars win32vars;
|
||||||
|
@ -366,13 +366,6 @@ Sys_File_Save_Sig(system_file_save){
|
||||||
return(success);
|
return(success);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(allen): THIS system does not really work.
|
|
||||||
// I want to eliminate them both entirely and find a better
|
|
||||||
// way to track the dirty state of files. It shouldn't be too
|
|
||||||
// hard to get the * part right. The trick is how we will know
|
|
||||||
// when a file is updated... hmm... maybe we can keep the
|
|
||||||
// file_time_stamp part.
|
|
||||||
|
|
||||||
internal
|
internal
|
||||||
Sys_File_Time_Stamp_Sig(system_file_time_stamp){
|
Sys_File_Time_Stamp_Sig(system_file_time_stamp){
|
||||||
u64 result = 0;
|
u64 result = 0;
|
||||||
|
@ -383,21 +376,18 @@ Sys_File_Time_Stamp_Sig(system_file_time_stamp){
|
||||||
last_write = data.ftLastWriteTime;
|
last_write = data.ftLastWriteTime;
|
||||||
|
|
||||||
result = ((u64)last_write.dwHighDateTime << 32) | (last_write.dwLowDateTime);
|
result = ((u64)last_write.dwHighDateTime << 32) | (last_write.dwLowDateTime);
|
||||||
result /= 10;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal
|
internal
|
||||||
Sys_Time_Sig(system_time){
|
Sys_Now_Time_Stamp_Sig(system_now_time_stamp){
|
||||||
u64 result = 0;
|
u64 result = 0;
|
||||||
LARGE_INTEGER time;
|
FILETIME filetime;
|
||||||
if (QueryPerformanceCounter(&time)){
|
GetSystemTimeAsFileTime(&filetime);
|
||||||
result = (u64)(time.QuadPart - win32vars.start_pcount) * 1000000 / win32vars.performance_frequency;
|
result = ((u64)filetime.dwHighDateTime << 32) | (filetime.dwLowDateTime);
|
||||||
result += win32vars.start_time;
|
return(result);
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal
|
internal
|
||||||
|
@ -633,6 +623,29 @@ Sys_Post_Clipboard_Sig(system_post_clipboard){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal b32
|
||||||
|
Win32ReadClipboardContents(){
|
||||||
|
b32 result = 0;
|
||||||
|
|
||||||
|
if (IsClipboardFormatAvailable(CF_TEXT)){
|
||||||
|
result = 1;
|
||||||
|
if (OpenClipboard(win32vars.window_handle)){
|
||||||
|
HANDLE clip_data;
|
||||||
|
clip_data = GetClipboardData(CF_TEXT);
|
||||||
|
if (clip_data){
|
||||||
|
win32vars.clipboard_contents.str = (char*)GlobalLock(clip_data);
|
||||||
|
if (win32vars.clipboard_contents.str){
|
||||||
|
win32vars.clipboard_contents.size = str_size((char*)win32vars.clipboard_contents.str);
|
||||||
|
GlobalUnlock(clip_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CloseClipboard();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Multithreading
|
// Multithreading
|
||||||
//
|
//
|
||||||
|
@ -660,7 +673,7 @@ JobThreadProc(LPVOID lpParameter){
|
||||||
u32 next_read_index = (read_index + 1) % JOB_ID_WRAP;
|
u32 next_read_index = (read_index + 1) % JOB_ID_WRAP;
|
||||||
u32 safe_read_index =
|
u32 safe_read_index =
|
||||||
InterlockedCompareExchange(&queue->read_position,
|
InterlockedCompareExchange(&queue->read_position,
|
||||||
next_read_index, read_index);
|
next_read_index, read_index);
|
||||||
|
|
||||||
if (safe_read_index == read_index){
|
if (safe_read_index == read_index){
|
||||||
Full_Job_Data *full_job = queue->jobs + (safe_read_index % QUEUE_WRAP);
|
Full_Job_Data *full_job = queue->jobs + (safe_read_index % QUEUE_WRAP);
|
||||||
|
@ -670,7 +683,7 @@ JobThreadProc(LPVOID lpParameter){
|
||||||
|
|
||||||
i32 safe_running_thread =
|
i32 safe_running_thread =
|
||||||
InterlockedCompareExchange(&full_job->running_thread,
|
InterlockedCompareExchange(&full_job->running_thread,
|
||||||
thread->id, THREAD_NOT_ASSIGNED);
|
thread->id, THREAD_NOT_ASSIGNED);
|
||||||
|
|
||||||
if (safe_running_thread == THREAD_NOT_ASSIGNED){
|
if (safe_running_thread == THREAD_NOT_ASSIGNED){
|
||||||
thread->job_id = full_job->id;
|
thread->job_id = full_job->id;
|
||||||
|
@ -689,8 +702,8 @@ JobThreadProc(LPVOID lpParameter){
|
||||||
thread_memory->size = new_size;
|
thread_memory->size = new_size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
full_job->job.callback(win32vars.system, thread, thread_memory,
|
full_job->job.callback(&win32vars.system, thread, thread_memory,
|
||||||
&exchange_vars.thread, full_job->job.data);
|
&exchange_vars.thread, full_job->job.data);
|
||||||
PostMessage(win32vars.window_handle, WM_4coder_ANIMATE, 0, 0);
|
PostMessage(win32vars.window_handle, WM_4coder_ANIMATE, 0, 0);
|
||||||
full_job->running_thread = 0;
|
full_job->running_thread = 0;
|
||||||
thread->running = 0;
|
thread->running = 0;
|
||||||
|
@ -1129,45 +1142,45 @@ Win32LoadAppCode(){
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
Win32LoadSystemCode(){
|
Win32LoadSystemCode(){
|
||||||
win32vars.system->file_time_stamp = system_file_time_stamp;
|
win32vars.system.file_time_stamp = system_file_time_stamp;
|
||||||
win32vars.system->file_unique_hash = system_file_unique_hash;
|
win32vars.system.now_time_stamp = system_now_time_stamp;
|
||||||
win32vars.system->set_file_list = system_set_file_list;
|
win32vars.system.file_unique_hash = system_file_unique_hash;
|
||||||
win32vars.system->file_track = system_file_track;
|
win32vars.system.set_file_list = system_set_file_list;
|
||||||
win32vars.system->file_untrack = system_file_untrack;
|
win32vars.system.file_track = system_file_track;
|
||||||
win32vars.system->file_load_begin = system_file_load_begin;
|
win32vars.system.file_untrack = system_file_untrack;
|
||||||
win32vars.system->file_load_end = system_file_load_end;
|
win32vars.system.file_load_begin = system_file_load_begin;
|
||||||
win32vars.system->file_save = system_file_save;
|
win32vars.system.file_load_end = system_file_load_end;
|
||||||
|
win32vars.system.file_save = system_file_save;
|
||||||
|
|
||||||
win32vars.system->file_exists = system_file_exists;
|
win32vars.system.file_exists = system_file_exists;
|
||||||
win32vars.system->directory_cd = system_directory_cd;
|
win32vars.system.directory_cd = system_directory_cd;
|
||||||
win32vars.system->get_4ed_path = system_get_4ed_path;
|
win32vars.system.get_4ed_path = system_get_4ed_path;
|
||||||
|
|
||||||
win32vars.system->post_clipboard = system_post_clipboard;
|
win32vars.system.post_clipboard = system_post_clipboard;
|
||||||
win32vars.system->time = system_time;
|
|
||||||
|
|
||||||
win32vars.system->create_coroutine = system_create_coroutine;
|
win32vars.system.create_coroutine = system_create_coroutine;
|
||||||
win32vars.system->launch_coroutine = system_launch_coroutine;
|
win32vars.system.launch_coroutine = system_launch_coroutine;
|
||||||
win32vars.system->resume_coroutine = system_resume_coroutine;
|
win32vars.system.resume_coroutine = system_resume_coroutine;
|
||||||
win32vars.system->yield_coroutine = system_yield_coroutine;
|
win32vars.system.yield_coroutine = system_yield_coroutine;
|
||||||
|
|
||||||
win32vars.system->cli_call = system_cli_call;
|
win32vars.system.cli_call = system_cli_call;
|
||||||
win32vars.system->cli_begin_update = system_cli_begin_update;
|
win32vars.system.cli_begin_update = system_cli_begin_update;
|
||||||
win32vars.system->cli_update_step = system_cli_update_step;
|
win32vars.system.cli_update_step = system_cli_update_step;
|
||||||
win32vars.system->cli_end_update = system_cli_end_update;
|
win32vars.system.cli_end_update = system_cli_end_update;
|
||||||
|
|
||||||
win32vars.system->post_job = system_post_job;
|
win32vars.system.post_job = system_post_job;
|
||||||
win32vars.system->cancel_job = system_cancel_job;
|
win32vars.system.cancel_job = system_cancel_job;
|
||||||
win32vars.system->grow_thread_memory = system_grow_thread_memory;
|
win32vars.system.grow_thread_memory = system_grow_thread_memory;
|
||||||
win32vars.system->acquire_lock = system_acquire_lock;
|
win32vars.system.acquire_lock = system_acquire_lock;
|
||||||
win32vars.system->release_lock = system_release_lock;
|
win32vars.system.release_lock = system_release_lock;
|
||||||
|
|
||||||
#if FRED_INTERNAL
|
#if FRED_INTERNAL
|
||||||
win32vars.system->internal_sentinel = INTERNAL_system_sentinel;
|
win32vars.system.internal_sentinel = INTERNAL_system_sentinel;
|
||||||
win32vars.system->internal_get_thread_states = INTERNAL_get_thread_states;
|
win32vars.system.internal_get_thread_states = INTERNAL_get_thread_states;
|
||||||
win32vars.system->internal_debug_message = INTERNAL_system_debug_message;
|
win32vars.system.internal_debug_message = INTERNAL_system_debug_message;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
win32vars.system->slash = '/';
|
win32vars.system.slash = '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
|
@ -1228,15 +1241,6 @@ Win32RedrawScreen(HDC hdc){
|
||||||
SwapBuffers(hdc);
|
SwapBuffers(hdc);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
|
||||||
Win32RedrawFromUpdate(){
|
|
||||||
PAINTSTRUCT ps;
|
|
||||||
HWND hwnd = win32vars.window_handle;
|
|
||||||
HDC hdc = BeginPaint(hwnd, &ps);
|
|
||||||
Win32RedrawScreen(hdc);
|
|
||||||
EndPaint(hwnd, &ps);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
Win32Resize(i32 width, i32 height){
|
Win32Resize(i32 width, i32 height){
|
||||||
if (width > 0 && height > 0){
|
if (width > 0 && height > 0){
|
||||||
|
@ -1268,6 +1272,18 @@ Win32SetCursorFromUpdate(Application_Mouse_Cursor cursor){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal u64
|
||||||
|
Win32HighResolutionTime(){
|
||||||
|
u64 result = 0;
|
||||||
|
LARGE_INTEGER t;
|
||||||
|
if (QueryPerformanceCounter(&t)){
|
||||||
|
result = (u64)t.QuadPart / win32vars.count_per_usecond;
|
||||||
|
}
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
internal LRESULT
|
internal LRESULT
|
||||||
Win32Callback(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
|
Win32Callback(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
|
||||||
LRESULT result = {};
|
LRESULT result = {};
|
||||||
|
@ -1686,9 +1702,6 @@ WinMain(HINSTANCE hInstance,
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
System_Functions system_;
|
|
||||||
System_Functions *system = &system_;
|
|
||||||
win32vars.system = system;
|
|
||||||
Win32LoadSystemCode();
|
Win32LoadSystemCode();
|
||||||
|
|
||||||
Win32LoadRenderCode();
|
Win32LoadRenderCode();
|
||||||
|
@ -1698,9 +1711,7 @@ WinMain(HINSTANCE hInstance,
|
||||||
// Read Command Line
|
// Read Command Line
|
||||||
//
|
//
|
||||||
|
|
||||||
DWORD required = GetCurrentDirectory(0, 0);
|
DWORD required = (GetCurrentDirectory(0, 0)*4) + 1;
|
||||||
required += 1;
|
|
||||||
required *= 4;
|
|
||||||
char *current_directory_mem = (char*)system_get_memory(required);
|
char *current_directory_mem = (char*)system_get_memory(required);
|
||||||
DWORD written = GetCurrentDirectory(required, current_directory_mem);
|
DWORD written = GetCurrentDirectory(required, current_directory_mem);
|
||||||
|
|
||||||
|
@ -1712,13 +1723,10 @@ WinMain(HINSTANCE hInstance,
|
||||||
clparams.argv = argv;
|
clparams.argv = argv;
|
||||||
clparams.argc = argc;
|
clparams.argc = argc;
|
||||||
|
|
||||||
char **files;
|
char **files = 0;
|
||||||
i32 *file_count;
|
i32 *file_count = 0;
|
||||||
|
|
||||||
files = 0;
|
win32vars.app.read_command_line(&win32vars.system,
|
||||||
file_count = 0;
|
|
||||||
|
|
||||||
win32vars.app.read_command_line(system,
|
|
||||||
&memory_vars,
|
&memory_vars,
|
||||||
current_directory,
|
current_directory,
|
||||||
&win32vars.settings,
|
&win32vars.settings,
|
||||||
|
@ -1751,7 +1759,7 @@ WinMain(HINSTANCE hInstance,
|
||||||
|
|
||||||
if (win32vars.custom_api.get_alpha_4coder_version == 0 ||
|
if (win32vars.custom_api.get_alpha_4coder_version == 0 ||
|
||||||
win32vars.custom_api.get_alpha_4coder_version(MAJOR, MINOR, PATCH) == 0){
|
win32vars.custom_api.get_alpha_4coder_version(MAJOR, MINOR, PATCH) == 0){
|
||||||
OutputDebugStringA("Error: application and custom version numbers don't match");
|
OutputDebugStringA("Error: application and custom version numbers don't match\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
win32vars.custom_api.get_bindings = (Get_Binding_Data_Function*)
|
win32vars.custom_api.get_bindings = (Get_Binding_Data_Function*)
|
||||||
|
@ -1903,7 +1911,6 @@ WinMain(HINSTANCE hInstance,
|
||||||
//
|
//
|
||||||
|
|
||||||
win32vars.clipboard_sequence = GetClipboardSequenceNumber();
|
win32vars.clipboard_sequence = GetClipboardSequenceNumber();
|
||||||
|
|
||||||
if (win32vars.clipboard_sequence == 0){
|
if (win32vars.clipboard_sequence == 0){
|
||||||
system_post_clipboard(make_lit_string(""));
|
system_post_clipboard(make_lit_string(""));
|
||||||
|
|
||||||
|
@ -1911,38 +1918,13 @@ WinMain(HINSTANCE hInstance,
|
||||||
win32vars.next_clipboard_is_self = 0;
|
win32vars.next_clipboard_is_self = 0;
|
||||||
|
|
||||||
if (win32vars.clipboard_sequence == 0){
|
if (win32vars.clipboard_sequence == 0){
|
||||||
// TODO(allen): diagnostics
|
OutputDebugStringA("Failure while initializing clipboard\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else{
|
else{
|
||||||
if (IsClipboardFormatAvailable(CF_TEXT)){
|
Win32ReadClipboardContents();
|
||||||
if (OpenClipboard(win32vars.window_handle)){
|
|
||||||
HANDLE clip_data;
|
|
||||||
clip_data = GetClipboardData(CF_TEXT);
|
|
||||||
if (clip_data){
|
|
||||||
win32vars.clipboard_contents.str = (char*)GlobalLock(clip_data);
|
|
||||||
if (win32vars.clipboard_contents.str){
|
|
||||||
win32vars.clipboard_contents.size = str_size((char*)win32vars.clipboard_contents.str);
|
|
||||||
GlobalUnlock(clip_data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
CloseClipboard();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LARGE_INTEGER lpf;
|
|
||||||
QueryPerformanceFrequency(&lpf);
|
|
||||||
win32vars.performance_frequency = lpf.QuadPart;
|
|
||||||
QueryPerformanceCounter(&lpf);
|
|
||||||
win32vars.start_pcount = lpf.QuadPart;
|
|
||||||
|
|
||||||
FILETIME filetime;
|
|
||||||
GetSystemTimeAsFileTime(&filetime);
|
|
||||||
win32vars.start_time = ((u64)filetime.dwHighDateTime << 32) | (filetime.dwLowDateTime);
|
|
||||||
win32vars.start_time /= 10;
|
|
||||||
|
|
||||||
Win32KeycodeInit();
|
Win32KeycodeInit();
|
||||||
|
|
||||||
win32vars.cursor_ibeam = LoadCursor(NULL, IDC_IBEAM);
|
win32vars.cursor_ibeam = LoadCursor(NULL, IDC_IBEAM);
|
||||||
|
@ -1950,12 +1932,21 @@ WinMain(HINSTANCE hInstance,
|
||||||
win32vars.cursor_leftright = LoadCursor(NULL, IDC_SIZEWE);
|
win32vars.cursor_leftright = LoadCursor(NULL, IDC_SIZEWE);
|
||||||
win32vars.cursor_updown = LoadCursor(NULL, IDC_SIZENS);
|
win32vars.cursor_updown = LoadCursor(NULL, IDC_SIZENS);
|
||||||
|
|
||||||
|
LARGE_INTEGER f;
|
||||||
|
if (QueryPerformanceFrequency(&f)){
|
||||||
|
win32vars.count_per_usecond = (u64)f.QuadPart / 1000000;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// NOTE(allen): Just guess.
|
||||||
|
win32vars.count_per_usecond = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Main Loop
|
// Main Loop
|
||||||
//
|
//
|
||||||
|
|
||||||
win32vars.app.init(win32vars.system, &win32vars.target,
|
win32vars.app.init(&win32vars.system, &win32vars.target,
|
||||||
&memory_vars, &exchange_vars,
|
&memory_vars, &exchange_vars,
|
||||||
win32vars.clipboard_contents, current_directory,
|
win32vars.clipboard_contents, current_directory,
|
||||||
win32vars.custom_api);
|
win32vars.custom_api);
|
||||||
|
@ -1966,9 +1957,11 @@ WinMain(HINSTANCE hInstance,
|
||||||
win32vars.first = 1;
|
win32vars.first = 1;
|
||||||
timeBeginPeriod(1);
|
timeBeginPeriod(1);
|
||||||
|
|
||||||
|
|
||||||
SetForegroundWindow(win32vars.window_handle);
|
SetForegroundWindow(win32vars.window_handle);
|
||||||
SetActiveWindow(win32vars.window_handle);
|
SetActiveWindow(win32vars.window_handle);
|
||||||
|
|
||||||
|
u64 timer_start = Win32HighResolutionTime();
|
||||||
system_acquire_lock(FRAME_LOCK);
|
system_acquire_lock(FRAME_LOCK);
|
||||||
MSG msg;
|
MSG msg;
|
||||||
for (;win32vars.input_chunk.pers.keep_playing;){
|
for (;win32vars.input_chunk.pers.keep_playing;){
|
||||||
|
@ -1977,12 +1970,12 @@ WinMain(HINSTANCE hInstance,
|
||||||
// Looks like we can ReadFile with a size of zero
|
// Looks like we can ReadFile with a size of zero
|
||||||
// in an IOCP for this effect.
|
// in an IOCP for this effect.
|
||||||
|
|
||||||
|
system_release_lock(FRAME_LOCK);
|
||||||
|
|
||||||
if (win32vars.running_cli == 0){
|
if (win32vars.running_cli == 0){
|
||||||
win32vars.got_useful_event = 0;
|
win32vars.got_useful_event = 0;
|
||||||
for (;win32vars.got_useful_event == 0;){
|
for (;win32vars.got_useful_event == 0;){
|
||||||
system_release_lock(FRAME_LOCK);
|
|
||||||
if (GetMessage(&msg, 0, 0, 0)){
|
if (GetMessage(&msg, 0, 0, 0)){
|
||||||
system_acquire_lock(FRAME_LOCK);
|
|
||||||
if (msg.message == WM_QUIT){
|
if (msg.message == WM_QUIT){
|
||||||
win32vars.input_chunk.pers.keep_playing = 0;
|
win32vars.input_chunk.pers.keep_playing = 0;
|
||||||
}else{
|
}else{
|
||||||
|
@ -1990,9 +1983,6 @@ WinMain(HINSTANCE hInstance,
|
||||||
DispatchMessage(&msg);
|
DispatchMessage(&msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
|
||||||
system_acquire_lock(FRAME_LOCK);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2005,117 +1995,111 @@ WinMain(HINSTANCE hInstance,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
system_acquire_lock(FRAME_LOCK);
|
||||||
i64 timer_start = system_time();
|
|
||||||
|
|
||||||
POINT mouse_point;
|
POINT mouse_point;
|
||||||
if (GetCursorPos(&mouse_point) && ScreenToClient(win32vars.window_handle, &mouse_point)){
|
if (GetCursorPos(&mouse_point) &&
|
||||||
if (!hit_check(mouse_point.x, mouse_point.y,
|
ScreenToClient(win32vars.window_handle, &mouse_point)){
|
||||||
0, 0, win32vars.target.width, win32vars.target.height)){
|
|
||||||
win32vars.input_chunk.trans.out_of_window = 1;
|
i32_Rect screen =
|
||||||
}
|
i32R(0, 0, win32vars.target.width, win32vars.target.height);
|
||||||
win32vars.input_chunk.pers.mouse_x = mouse_point.x;
|
|
||||||
win32vars.input_chunk.pers.mouse_y = mouse_point.y;
|
if (!hit_check(mouse_point.x, mouse_point.y, screen)){
|
||||||
}
|
|
||||||
else{
|
|
||||||
win32vars.input_chunk.trans.out_of_window = 1;
|
win32vars.input_chunk.trans.out_of_window = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Win32_Input_Chunk input_chunk = win32vars.input_chunk;
|
win32vars.input_chunk.pers.mouse_x = mouse_point.x;
|
||||||
win32vars.input_chunk.trans = win32_input_chunk_transient_zero();
|
win32vars.input_chunk.pers.mouse_y = mouse_point.y;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
win32vars.input_chunk.trans.out_of_window = 1;
|
||||||
|
}
|
||||||
|
|
||||||
input_chunk.pers.control_keys[MDFR_CAPS_INDEX] = GetKeyState(VK_CAPITAL) & 0x1;
|
Win32_Input_Chunk input_chunk = win32vars.input_chunk;
|
||||||
|
win32vars.input_chunk.trans = win32_input_chunk_transient_zero();
|
||||||
|
|
||||||
win32vars.clipboard_contents = string_zero();
|
input_chunk.pers.control_keys[MDFR_CAPS_INDEX] = GetKeyState(VK_CAPITAL) & 0x1;
|
||||||
if (win32vars.clipboard_sequence != 0){
|
|
||||||
DWORD new_number = GetClipboardSequenceNumber();
|
win32vars.clipboard_contents = string_zero();
|
||||||
if (new_number != win32vars.clipboard_sequence){
|
if (win32vars.clipboard_sequence != 0){
|
||||||
win32vars.clipboard_sequence = new_number;
|
DWORD new_number = GetClipboardSequenceNumber();
|
||||||
if (win32vars.next_clipboard_is_self){
|
if (new_number != win32vars.clipboard_sequence){
|
||||||
win32vars.next_clipboard_is_self = 0;
|
win32vars.clipboard_sequence = new_number;
|
||||||
}
|
if (win32vars.next_clipboard_is_self){
|
||||||
else if (IsClipboardFormatAvailable(CF_TEXT)){
|
win32vars.next_clipboard_is_self = 0;
|
||||||
if (OpenClipboard(win32vars.window_handle)){
|
}
|
||||||
HANDLE clip_data;
|
else{
|
||||||
clip_data = GetClipboardData(CF_TEXT);
|
Win32ReadClipboardContents();
|
||||||
if (clip_data){
|
|
||||||
win32vars.clipboard_contents.str = (char*)GlobalLock(clip_data);
|
|
||||||
if (win32vars.clipboard_contents.str){
|
|
||||||
win32vars.clipboard_contents.size = str_size((char*)win32vars.clipboard_contents.str);
|
|
||||||
GlobalUnlock(clip_data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
CloseClipboard();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Key_Input_Data input_data;
|
|
||||||
Mouse_State mouse;
|
|
||||||
Application_Step_Result result;
|
|
||||||
|
|
||||||
input_data = input_chunk.trans.key_data;
|
|
||||||
mouse.out_of_window = input_chunk.trans.out_of_window;
|
|
||||||
|
|
||||||
mouse.l = input_chunk.pers.mouse_l;
|
|
||||||
mouse.press_l = input_chunk.trans.mouse_l_press;
|
|
||||||
mouse.release_l = input_chunk.trans.mouse_l_release;
|
|
||||||
|
|
||||||
mouse.r = input_chunk.pers.mouse_r;
|
|
||||||
mouse.press_r = input_chunk.trans.mouse_r_press;
|
|
||||||
mouse.release_r = input_chunk.trans.mouse_r_release;
|
|
||||||
|
|
||||||
mouse.wheel = input_chunk.trans.mouse_wheel;
|
|
||||||
|
|
||||||
mouse.x = input_chunk.pers.mouse_x;
|
|
||||||
mouse.y = input_chunk.pers.mouse_y;
|
|
||||||
|
|
||||||
result.mouse_cursor_type = APP_MOUSE_CURSOR_DEFAULT;
|
|
||||||
result.lctrl_lalt_is_altgr = win32vars.lctrl_lalt_is_altgr;
|
|
||||||
result.trying_to_kill = input_chunk.trans.trying_to_kill;
|
|
||||||
result.perform_kill = 0;
|
|
||||||
|
|
||||||
// NOTE(allen): The expected dt given the frame limit in seconds.
|
|
||||||
f32 dt = frame_useconds / 1000000.f;
|
|
||||||
|
|
||||||
win32vars.app.step(win32vars.system,
|
|
||||||
&input_data,
|
|
||||||
&mouse,
|
|
||||||
&win32vars.target,
|
|
||||||
&memory_vars,
|
|
||||||
&exchange_vars,
|
|
||||||
win32vars.clipboard_contents,
|
|
||||||
dt, win32vars.first,
|
|
||||||
&result);
|
|
||||||
|
|
||||||
if (result.perform_kill){
|
|
||||||
win32vars.input_chunk.pers.keep_playing = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Win32SetCursorFromUpdate(result.mouse_cursor_type);
|
|
||||||
win32vars.lctrl_lalt_is_altgr = result.lctrl_lalt_is_altgr;
|
|
||||||
|
|
||||||
Win32RedrawFromUpdate();
|
|
||||||
|
|
||||||
win32vars.first = 0;
|
|
||||||
|
|
||||||
i64 timer_end = system_time();
|
|
||||||
i64 end_target = (timer_start + frame_useconds);
|
|
||||||
|
|
||||||
system_release_lock(FRAME_LOCK);
|
|
||||||
while (timer_end < end_target){
|
|
||||||
DWORD samount = (DWORD)((end_target - timer_end) / 1000);
|
|
||||||
if (samount > 0) Sleep(samount);
|
|
||||||
timer_end = system_time();
|
|
||||||
}
|
|
||||||
system_acquire_lock(FRAME_LOCK);
|
|
||||||
timer_start = system_time();
|
|
||||||
|
|
||||||
if (result.animating){
|
|
||||||
PostMessage(win32vars.window_handle, WM_4coder_ANIMATE, 0, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Key_Input_Data input_data;
|
||||||
|
Mouse_State mouse;
|
||||||
|
Application_Step_Result result;
|
||||||
|
|
||||||
|
input_data = input_chunk.trans.key_data;
|
||||||
|
mouse.out_of_window = input_chunk.trans.out_of_window;
|
||||||
|
|
||||||
|
mouse.l = input_chunk.pers.mouse_l;
|
||||||
|
mouse.press_l = input_chunk.trans.mouse_l_press;
|
||||||
|
mouse.release_l = input_chunk.trans.mouse_l_release;
|
||||||
|
|
||||||
|
mouse.r = input_chunk.pers.mouse_r;
|
||||||
|
mouse.press_r = input_chunk.trans.mouse_r_press;
|
||||||
|
mouse.release_r = input_chunk.trans.mouse_r_release;
|
||||||
|
|
||||||
|
mouse.wheel = input_chunk.trans.mouse_wheel;
|
||||||
|
|
||||||
|
mouse.x = input_chunk.pers.mouse_x;
|
||||||
|
mouse.y = input_chunk.pers.mouse_y;
|
||||||
|
|
||||||
|
result.mouse_cursor_type = APP_MOUSE_CURSOR_DEFAULT;
|
||||||
|
result.lctrl_lalt_is_altgr = win32vars.lctrl_lalt_is_altgr;
|
||||||
|
result.trying_to_kill = input_chunk.trans.trying_to_kill;
|
||||||
|
result.perform_kill = 0;
|
||||||
|
|
||||||
|
// NOTE(allen): The expected dt given the frame limit in seconds.
|
||||||
|
f32 dt = frame_useconds / 1000000.f;
|
||||||
|
|
||||||
|
win32vars.app.step(&win32vars.system,
|
||||||
|
&input_data,
|
||||||
|
&mouse,
|
||||||
|
&win32vars.target,
|
||||||
|
&memory_vars,
|
||||||
|
&exchange_vars,
|
||||||
|
win32vars.clipboard_contents,
|
||||||
|
dt, win32vars.first,
|
||||||
|
&result);
|
||||||
|
|
||||||
|
if (result.perform_kill){
|
||||||
|
win32vars.input_chunk.pers.keep_playing = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Win32SetCursorFromUpdate(result.mouse_cursor_type);
|
||||||
|
win32vars.lctrl_lalt_is_altgr = result.lctrl_lalt_is_altgr;
|
||||||
|
|
||||||
|
HDC hdc = GetDC(win32vars.window_handle);
|
||||||
|
Win32RedrawScreen(hdc);
|
||||||
|
ReleaseDC(win32vars.window_handle, hdc);
|
||||||
|
|
||||||
|
win32vars.first = 0;
|
||||||
|
|
||||||
|
if (result.animating){
|
||||||
|
PostMessage(win32vars.window_handle, WM_4coder_ANIMATE, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 timer_end = Win32HighResolutionTime();
|
||||||
|
u64 end_target = timer_start + frame_useconds;
|
||||||
|
|
||||||
|
system_release_lock(FRAME_LOCK);
|
||||||
|
while (timer_end < end_target){
|
||||||
|
DWORD samount = (DWORD)((end_target - timer_end) / 1000);
|
||||||
|
if (samount > 0) Sleep(samount);
|
||||||
|
timer_end = Win32HighResolutionTime();
|
||||||
|
}
|
||||||
|
system_acquire_lock(FRAME_LOCK);
|
||||||
|
timer_start = Win32HighResolutionTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
|
|
Loading…
Reference in New Issue