got command line working

This commit is contained in:
Allen Webster 2017-06-12 17:35:06 -04:00
parent 1349308c81
commit e65be95289
3 changed files with 102 additions and 34 deletions

49
4ed_log.h Normal file
View File

@ -0,0 +1,49 @@
/*
* Mr. 4th Dimention - Allen Webster
*
* 12.06.2017
*
* Setup macro wrappers for the logging system.
*
*/
// TOP
#define GEN_LOG(l,m) l(m, sizeof(m)-1)
#define GEN_LOGF(l,...) do{ char space[4096]; \
i32 length = snprintf(space, sizeof(space), __VA_ARGS__); \
l(space, length); \
}while(0)
#if defined(IS_PLAT_LAYER)
# if defined(USE_LOG)
# define LOG(m) GEN_LOG(system_log, m)
# else
# define LOG(m)
# endif
# if defined(USE_LOGF)
# define LOGF(...) GEN_LOGF(system_log, __VA_ARGS__)
# else
# define LOGF(...)
# endif
#else
# if defined(USE_LOG)
# define LOG(s,m) GEN_LOG((s)->log, m)
# else
# define LOG(s,m)
# endif
# if defined(USE_LOGF)
# define LOGF(s,...) GEN_LOGF((s)->log, __VA_ARGS__)
# else
# define LOGF(s,...)
# endif
#endif
// BOTTOM

View File

@ -83,6 +83,7 @@ enum{
KEEP_ASSERT = 0x200, KEEP_ASSERT = 0x200,
SITE_INCLUDES = 0x400, SITE_INCLUDES = 0x400,
X86 = 0x800, X86 = 0x800,
LOG = 0x1000,
}; };
@ -168,6 +169,10 @@ build_cl(u32 flags, char *code_path, char *code_file, char *out_path, char *out_
build_ap(line, "/DFTECH_32_BIT"); build_ap(line, "/DFTECH_32_BIT");
} }
if (flags & LOG){
build_ap(line, "/DUSE_LOG /DUSE_LOGF");
}
if (flags & INCLUDES){ if (flags & INCLUDES){
build_ap(line, CL_INCLUDES); build_ap(line, CL_INCLUDES);
} }
@ -306,6 +311,10 @@ build_gcc(u32 flags, char *code_path, char *code_file, char *out_path, char *out
build_ap(line, "-shared"); build_ap(line, "-shared");
} }
if (flags & LOG){
build_ap(line, "-DUSE_LOG -DUSE_LOGF");
}
if (flags & SUPER){ if (flags & SUPER){
build_ap(line, "-DFRED_SUPER"); build_ap(line, "-DFRED_SUPER");
} }
@ -632,7 +641,7 @@ package(char *cdir){
Assert(ArrayCount(dest_dirs) == ArrayCount(dest_par_dirs)); Assert(ArrayCount(dest_dirs) == ArrayCount(dest_par_dirs));
u32 count = ArrayCount(dest_dirs); u32 count = ArrayCount(dest_dirs);
u32 base_flags = OPTIMIZATION | KEEP_ASSERT | DEBUG_INFO; u32 base_flags = OPTIMIZATION | KEEP_ASSERT | DEBUG_INFO | LOG;
u32 flags[] = { u32 flags[] = {
0, 0,
X86, X86,
@ -707,7 +716,7 @@ package(char *cdir){
Assert(ArrayCount(dest_dirs) == ArrayCount(dest_par_dirs)); Assert(ArrayCount(dest_dirs) == ArrayCount(dest_par_dirs));
u32 count = ArrayCount(dest_dirs); u32 count = ArrayCount(dest_dirs);
u32 base_flags = OPTIMIZATION | KEEP_ASSERT | DEBUG_INFO | SUPER; u32 base_flags = OPTIMIZATION | KEEP_ASSERT | DEBUG_INFO | SUPER | LOG;
u32 flags[] = { u32 flags[] = {
0, 0,
X86, X86,
@ -804,7 +813,7 @@ int main(int argc, char **argv){
assert(n < sizeof(cdir)); assert(n < sizeof(cdir));
END_TIME_SECTION("current directory"); END_TIME_SECTION("current directory");
u32 flags = DEBUG_INFO | SUPER | INTERNAL; u32 flags = DEBUG_INFO | SUPER | INTERNAL | LOG;
#if defined(OPT_BUILD) #if defined(OPT_BUILD)
flags |= OPTIMIZATION; flags |= OPTIMIZATION;
#endif #endif
@ -826,7 +835,9 @@ int main(int argc, char **argv){
assert(n < sizeof(cdir)); assert(n < sizeof(cdir));
END_TIME_SECTION("current directory"); END_TIME_SECTION("current directory");
standard_build(cdir, DEBUG_INFO | SUPER | INTERNAL | X86); u32 floags = DEBUG_INFO | SUPER | INTERNAL | X86 | LOG;
standard_build(cdir, flags);
return(error_state); return(error_state);
} }

View File

@ -60,6 +60,7 @@
#include "4ed_math.h" #include "4ed_math.h"
#include "4ed_system.h" #include "4ed_system.h"
#include "4ed_log.h"
#include "4ed_rendering.h" #include "4ed_rendering.h"
#include "4ed.h" #include "4ed.h"
@ -154,7 +155,7 @@ enum CV_ID{
CV_COUNT CV_COUNT
}; };
typedef struct Win32_Vars{ struct Win32_Vars{
System_Functions system; System_Functions system;
App_Functions app; App_Functions app;
Custom_API custom_api; Custom_API custom_api;
@ -204,11 +205,37 @@ typedef struct Win32_Vars{
u32 log_position; u32 log_position;
} Win32_Vars; };
global Win32_Vars win32vars; global Win32_Vars win32vars;
global Application_Memory memory_vars; global Application_Memory memory_vars;
//
// Logging
//
internal
Sys_Log_Sig(system_log){
if (win32vars.settings.use_log){
u8 space[4096];
String str = make_fixed_width_string(space);
system_get_binary_path(&str);
append_sc(&str, "4coder_log.txt");
terminate_with_null(&str);
HANDLE file = CreateFile_utf8(space, GENERIC_WRITE, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if (file != INVALID_HANDLE_VALUE){
SetFilePointer(file, win32vars.log_position, 0, FILE_BEGIN);
win32vars.log_position += length;
DWORD written = 0;
DWORD total_written = 0;
do{
WriteFile(file, message + total_written, length - total_written, &written, 0);
total_written += written;
}while(total_written < length);
CloseHandle(file);
}
}
}
// //
// Helpers // Helpers
@ -1091,29 +1118,6 @@ Sys_Get_4ed_Path_Sig(system_get_4ed_path){
return(size); return(size);
} }
internal
Sys_Log_Sig(system_log){
if (win32vars.settings.use_log){
u8 space[4096];
String str = make_fixed_width_string(space);
system_get_binary_path(&str);
append_sc(&str, "4coder_log.txt");
terminate_with_null(&str);
HANDLE file = CreateFile_utf8(space, GENERIC_WRITE, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if (file != INVALID_HANDLE_VALUE){
SetFilePointer(file, win32vars.log_position, 0, FILE_BEGIN);
win32vars.log_position += length;
DWORD written = 0;
DWORD total_written = 0;
do{
WriteFile(file, message + total_written, length - total_written, &written, 0);
total_written += written;
}while(total_written < length);
CloseHandle(file);
}
}
}
/* /*
NOTE(casey): This follows Raymond Chen's prescription NOTE(casey): This follows Raymond Chen's prescription
for fullscreen toggling, see: for fullscreen toggling, see:
@ -1989,7 +1993,6 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
InitializeConditionVariable(&win32vars.condition_vars[i]); InitializeConditionVariable(&win32vars.condition_vars[i]);
} }
Thread_Context background[4]; Thread_Context background[4];
memset(background, 0, sizeof(background)); memset(background, 0, sizeof(background));
win32vars.groups[BACKGROUND_THREADS].threads = background; win32vars.groups[BACKGROUND_THREADS].threads = background;
@ -2076,9 +2079,12 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
exit(1); exit(1);
} }
Win32LoadSystemCode(); Win32LoadSystemCode();
Win32LoadRenderCode(); Win32LoadRenderCode();
System_Functions *system = &win32vars.system;
// //
// Shared Systems Init // Shared Systems Init
// //
@ -2089,6 +2095,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
// Read Command Line // Read Command Line
// //
LOG(system, "Reading command line\n");
DWORD required = (GetCurrentDirectory(0, 0)*4) + 1; DWORD required = (GetCurrentDirectory(0, 0)*4) + 1;
u8 *current_directory_mem = (u8*)system_memory_allocate(required); u8 *current_directory_mem = (u8*)system_memory_allocate(required);
DWORD written = GetCurrentDirectory_utf8(required, current_directory_mem); DWORD written = GetCurrentDirectory_utf8(required, current_directory_mem);
@ -2104,9 +2111,10 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
char **files = 0; char **files = 0;
i32 *file_count = 0; i32 *file_count = 0;
win32vars.app.read_command_line(&win32vars.system, &memory_vars, current_directory, &win32vars.settings, &files, &file_count, clparams); win32vars.app.read_command_line(system, &memory_vars, current_directory, &win32vars.settings, &files, &file_count, clparams);
sysshared_filter_real_files(files, file_count); sysshared_filter_real_files(files, file_count);
LOG(system, "Loaded system code, read command line.\n");
// //
// Custom Layer Linkage // Custom Layer Linkage
@ -2222,7 +2230,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
// Font System Init // Font System Init
// //
system_font_init(&win32vars.system.font, 0, 0, win32vars.settings.font_size, win32vars.settings.use_hinting); system_font_init(&system->font, 0, 0, win32vars.settings.font_size, win32vars.settings.use_hinting);
// //
// Misc System Initializations // Misc System Initializations
@ -2267,7 +2275,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
// Main Loop // Main Loop
// //
win32vars.app.init(&win32vars.system, &win32vars.target, &memory_vars, win32vars.clipboard_contents, current_directory, win32vars.custom_api); win32vars.app.init(system, &win32vars.target, &memory_vars, win32vars.clipboard_contents, current_directory, win32vars.custom_api);
system_memory_free(current_directory.str, 0); system_memory_free(current_directory.str, 0);
@ -2467,7 +2475,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
win32vars.send_exit_signal = 0; win32vars.send_exit_signal = 0;
} }
win32vars.app.step(&win32vars.system, &win32vars.target, &memory_vars, &input, &result, clparams); win32vars.app.step(system, &win32vars.target, &memory_vars, &input, &result, clparams);
if (result.perform_kill){ if (result.perform_kill){
keep_playing = 0; keep_playing = 0;