Finished library loading logic; added api definition system; defined system api (and related)

master
Allen Webster 2019-10-02 19:58:05 -07:00
parent 364d9ba63a
commit 19f3d7a641
23 changed files with 1218 additions and 89 deletions

276
4ed_api_definition.cpp Normal file
View File

@ -0,0 +1,276 @@
/*
* Mr. 4th Dimention - Allen Webster
*
* 02.10.2019
*
* System API definition program.
*
*/
// TOP
#include "4coder_base_types.h"
#include "4coder_base_types.cpp"
#include "4coder_stringf.cpp"
#include "4coder_malloc_allocator.cpp"
////////////////////////////////
struct API_Param{
API_Param *next;
String_Const_u8 type_name;
String_Const_u8 name;
};
struct API_Param_List{
API_Param *first;
API_Param *last;
i32 count;
};
struct API_Call{
API_Call *next;
String_Const_u8 name;
String_Const_u8 return_type;
API_Param_List params;
};
struct API_Definition{
API_Call *first;
API_Call *last;
i32 count;
String_Const_u8 name;
};
////////////////////////////////
function API_Definition*
begin_api(Arena *arena, char *name){
API_Definition *api = push_array_zero(arena, API_Definition, 1);
api->name = SCu8(name);
return(api);
}
function API_Call*
api_call(Arena *arena, API_Definition *api, char *name, char *return_type){
API_Call *call = push_array_zero(arena, API_Call, 1);
sll_queue_push(api->first, api->last, call);
api->count += 1;
call->name = SCu8(name);
call->return_type = SCu8(return_type);
return(call);
}
function API_Param*
api_param(Arena *arena, API_Call *call, char *type_name, char *name){
API_Param *param = push_array_zero(arena, API_Param, 1);
sll_queue_push(call->params.first, call->params.last, param);
call->params.count += 1;
param->type_name = SCu8(type_name);
param->name = SCu8(name);
return(param);
}
////////////////////////////////
function void
generate_header(Arena *scratch, API_Definition *api, FILE *out){
for (API_Call *call = api->first;
call != 0;
call = call->next){
fprintf(out, "#define %.*s_%.*s_sig() %.*s %.*s_%.*s(",
string_expand(api->name),
string_expand(call->name),
string_expand(call->return_type),
string_expand(api->name),
string_expand(call->name));
if (call->params.count == 0){
fprintf(out, "void");
}
else{
for (API_Param *param = call->params.first;
param != 0;
param = param->next){
fprintf(out, "%.*s %.*s",
string_expand(param->type_name),
string_expand(param->name));
if (param->next != 0){
fprintf(out, ", ");
}
}
}
fprintf(out, ")\n");
}
for (API_Call *call = api->first;
call != 0;
call = call->next){
fprintf(out, "typedef %.*s %.*s_%.*s_type(",
string_expand(call->return_type),
string_expand(api->name),
string_expand(call->name));
if (call->params.count == 0){
fprintf(out, "void");
}
else{
for (API_Param *param = call->params.first;
param != 0;
param = param->next){
fprintf(out, "%.*s %.*s",
string_expand(param->type_name),
string_expand(param->name));
if (param->next != 0){
fprintf(out, ", ");
}
}
}
fprintf(out, ");\n");
}
fprintf(out, "struct API_VTable_%.*s{\n", string_expand(api->name));
for (API_Call *call = api->first;
call != 0;
call = call->next){
fprintf(out, "%.*s_%.*s_type *",
string_expand(api->name),
string_expand(call->name));
fprintf(out, "%.*s",
string_expand(call->name));
fprintf(out, ";\n");
}
fprintf(out, "};\n");
fprintf(out, "#if defined(STATIC_LINK_API)\n");
for (API_Call *call = api->first;
call != 0;
call = call->next){
fprintf(out, "internal %.*s %.*s_%.*s(",
string_expand(call->return_type),
string_expand(api->name),
string_expand(call->name));
if (call->params.count == 0){
fprintf(out, "void");
}
else{
for (API_Param *param = call->params.first;
param != 0;
param = param->next){
fprintf(out, "%.*s %.*s",
string_expand(param->type_name),
string_expand(param->name));
if (param->next != 0){
fprintf(out, ", ");
}
}
}
fprintf(out, ");\n");
}
fprintf(out, "#undef STATIC_LINK_API\n");
fprintf(out, "#elif defined(DYNAMIC_LINK_API)\n");
for (API_Call *call = api->first;
call != 0;
call = call->next){
fprintf(out, "global %.*s_%.*s_type *%.*s_%.*s = 0;\n",
string_expand(api->name),
string_expand(call->name),
string_expand(api->name),
string_expand(call->name));
}
fprintf(out, "#undef DYNAMIC_LINK_API\n");
fprintf(out, "#endif\n");
}
function void
generate_cpp(Arena *scratch, API_Definition *api, FILE *out){
fprintf(out, "function void\n");
fprintf(out, "%.*s_api_fill_vtable(API_VTable_%.*s *vtable){\n",
string_expand(api->name),
string_expand(api->name));
for (API_Call *call = api->first;
call != 0;
call = call->next){
fprintf(out, "vtable->%.*s = %.*s_%.*s;\n",
string_expand(call->name),
string_expand(api->name),
string_expand(call->name));
}
fprintf(out, "}\n");
fprintf(out, "#if defined(DYNAMIC_LINK_API)\n");
fprintf(out, "function void\n");
fprintf(out, "%.*s_api_read_vtable(API_VTable_%.*s *vtable){\n",
string_expand(api->name),
string_expand(api->name));
for (API_Call *call = api->first;
call != 0;
call = call->next){
fprintf(out, "%.*s_%.*s = vtable->%.*s;\n",
string_expand(api->name),
string_expand(call->name),
string_expand(call->name));
}
fprintf(out, "}\n");
fprintf(out, "#undef DYNAMIC_LINK_API\n");
fprintf(out, "#endif\n");
}
////////////////////////////////
function API_Definition*
define_api(Arena *arena);
int
main(void){
Arena arena = make_arena_malloc();
API_Definition *api = define_api(&arena);
////////////////////////////////
// NOTE(allen): Arrange output files
String_Const_u8 path_to_self = string_u8_litexpr(__FILE__);
path_to_self = string_remove_last_folder(path_to_self);
String_Const_u8 fname_h = push_u8_stringf(&arena, "%.*sgenerated/%.*s_api.h",
string_expand(path_to_self),
string_expand(api->name));
String_Const_u8 fname_cpp = push_u8_stringf(&arena, "%.*sgenerated/%.*s_api.cpp",
string_expand(path_to_self),
string_expand(api->name));
FILE *out_file_h = fopen((char*)fname_h.str, "wb");
if (out_file_h == 0){
printf("could not open output file: '%s'\n", fname_h.str);
exit(1);
}
FILE *out_file_cpp = fopen((char*)fname_cpp.str, "wb");
if (out_file_cpp == 0){
printf("could not open output file: '%s'\n", fname_cpp.str);
exit(1);
}
printf("%s:1:\n", fname_h.str);
printf("%s:1:\n", fname_cpp.str);
////////////////////////////////
// NOTE(allen): Generate output
generate_header(&arena, api, out_file_h);
generate_cpp(&arena, api, out_file_cpp);
////////////////////////////////
fclose(out_file_h);
fclose(out_file_cpp);
return(0);
}
// BOTTOM

View File

@ -2648,7 +2648,7 @@ Push_4ed_Path(Application_Links *app, Arena *arena)
{
Models *models = (Models*)app->cmd_context;
System_Functions *system = models->system;
return(system->get_4ed_path(arena));
return(system->get_path(arena, SystemPath_Binary));
}
// TODO(allen): do(add a "shown but auto-hides on timer" setting for cursor show type)

29
4ed_font_api.cpp Normal file
View File

@ -0,0 +1,29 @@
/*
* Mr. 4th Dimention - Allen Webster
*
* 02.10.2019
*
* Font API definition program.
*
*/
// TOP
#include "4ed_api_definition.cpp"
function API_Definition*
define_api(Arena *arena){
API_Definition *api = begin_api(arena, "font");
{
API_Call *call = api_call(arena, api, "make_face", "Face*");
api_param(arena, call, "Arena*", "arena");
api_param(arena, call, "Face_Description*", "description");
api_param(arena, call, "f32", "scale_factor");
}
return(api);
}
// BOTTOM

View File

@ -164,7 +164,7 @@ internal Face*
ft__font_make_face(Arena *arena, Face_Description *description, f32 scale_factor){
String_Const_u8 file_name = {};
if (description->font.in_4coder_font_folder){
String_Const_u8 binary_path = sysfunc.get_4ed_path(arena);
String_Const_u8 binary_path = sysfunc.get_path(arena, SystemPath_Binary);
binary_path = string_mod_replace_character(binary_path, '\\', '/');
file_name = push_u8_stringf(arena, "%.*sfonts/%.*s", string_expand(binary_path),
string_expand(description->font.file_name));

37
4ed_graphics_api.cpp Normal file
View File

@ -0,0 +1,37 @@
/*
* Mr. 4th Dimention - Allen Webster
*
* 02.10.2019
*
* Graphics API definition program.
*
*/
// TOP
#include "4ed_api_definition.cpp"
function API_Definition*
define_api(Arena *arena){
API_Definition *api = begin_api(arena, "graphics");
{
API_Call *call = api_call(arena, api, "get_texture", "u32");
api_param(arena, call, "Vec3_i32", "dim");
api_param(arena, call, "Texture_Kind", "texture_kind");
}
{
API_Call *call = api_call(arena, api, "fill_texture", "b32");
api_param(arena, call, "Texture_Kind", "texture_kind");
api_param(arena, call, "u32", "texture");
api_param(arena, call, "Vec3_i32", "p");
api_param(arena, call, "Vec3_i32", "dim");
api_param(arena, call, "void*", "data");
}
return(api);
}
// BOTTOM

58
4ed_search_list.cpp Normal file
View File

@ -0,0 +1,58 @@
/*
* Mr. 4th Dimention - Allen Webster
*
* 01.10.2019
*
* Search list helper.
*
*/
// TOP
function void
search_list_add_path__inner(Arena *arena, Path_Search_List *list, String_Const_u8 path){
string_list_push(arena, &list->list, path);
list->max_member_length = max(list->max_member_length, path.size);
}
function void
search_list_add_path(Arena *arena, Path_Search_List *list, String_Const_u8 path){
search_list_add_path__inner(arena, list, push_string_copy(arena, path));
}
function void
search_list_add_system_path(System_Functions *system, Arena *arena, Path_Search_List *list, System_Path_Code path){
search_list_add_path__inner(arena, list, system->get_path(arena, path));
}
function String_Const_u8
get_full_path(System_Functions *system, Arena *arena, Path_Search_List *search_list, String_Const_u8 relative){
String_Const_u8 result = {};
Temp_Memory restore_point = begin_temp(arena);
umem buffer_cap = search_list->max_member_length + relative.size + 1;
u8 *buffer = push_array(arena, u8, buffer_cap);
u8 *opl = buffer + buffer_cap;
u8 *relative_base = opl - 1 - relative.size;
block_copy(relative_base, relative.str, relative.size);
relative_base[relative.size] = 0;
for (Node_String_Const_u8 *node = search_list->list.first;
node != 0;
node = node->next){
umem node_size = node->string.size;
u8 *path_base = relative_base - node_size;
block_copy(path_base, node->string.str, node_size);
String_Const_u8 name = SCu8(path_base, opl);
File_Attributes attribs = system->quick_file_attributes(arena, name);
if (attribs.size > 0){
result = name;
break;
}
}
if (result.size == 0){
end_temp(restore_point);
}
return(result);
}
// BOTTOM

23
4ed_search_list.h Normal file
View File

@ -0,0 +1,23 @@
/*
* Mr. 4th Dimention - Allen Webster
*
* 01.10.2019
*
* Search list helper.
*
*/
// TOP
#if !defined(FRED_SEARCH_LIST_H)
#define FRED_SEARCH_LIST_H
struct Path_Search_List{
List_String_Const_u8 list;
umem max_member_length;
};
#endif
// BOTTOM

View File

@ -18,6 +18,26 @@
struct Plat_Handle{
u32 d[4];
};
typedef Plat_Handle System_Library;
typedef Plat_Handle System_Thread;
typedef Plat_Handle System_Mutex;
typedef Plat_Handle System_Condition_Variable;
typedef void Thread_Function(void *ptr);
struct CLI_Handles{
Plat_Handle proc;
Plat_Handle out_read;
Plat_Handle out_write;
Plat_Handle in_read;
Plat_Handle in_write;
u32 scratch_space[4];
i32 exit;
};
typedef i32 System_Path_Code;
enum{
SystemPath_CurrentDirectory,
SystemPath_Binary,
};
// files
#define Sys_Get_Canonical_Sig(n) String_Const_u8 n(Arena *arena, String_Const_u8 name)
@ -42,9 +62,21 @@ typedef Sys_Load_File_Sig(System_Load_File);
#define Sys_Load_Close_Sig(name) b32 name(Plat_Handle handle)
typedef Sys_Load_Close_Sig(System_Load_Close);
#define Sys_Save_File_Sig(name) File_Attributes name(Arena *scratch, char *filename, String_Const_u8 data)
#define Sys_Save_File_Sig(name) \
File_Attributes name(Arena *scratch, char *filename, String_Const_u8 data)
typedef Sys_Save_File_Sig(System_Save_File);
// library
#define Sys_Load_Library_Sig(name) \
b32 name(Arena *scratch, String_Const_u8 file_name, System_Library *out)
typedef Sys_Load_Library_Sig(System_Load_Library);
#define Sys_Release_Library_Sig(name) b32 name(System_Library handle)
typedef Sys_Release_Library_Sig(System_Release_Library);
#define Sys_Get_Proc_Sig(name) Void_Func *name(System_Library handle, char *proc_name)
typedef Sys_Get_Proc_Sig(System_Get_Proc);
// time
#define Sys_Now_Time_Sig(name) u64 name()
typedef Sys_Now_Time_Sig(System_Now_Time);
@ -72,17 +104,8 @@ typedef Sys_Sleep_Sig(System_Sleep);
typedef Sys_Post_Clipboard_Sig(System_Post_Clipboard);
// cli
struct CLI_Handles{
Plat_Handle proc;
Plat_Handle out_read;
Plat_Handle out_write;
Plat_Handle in_read;
Plat_Handle in_write;
u32 scratch_space[4];
i32 exit;
};
#define Sys_CLI_Call_Sig(n, scratch, path, script, cli_out) b32 n(Arena *scratch, char *path, char *script, CLI_Handles *cli_out)
#define Sys_CLI_Call_Sig(n, scratch, path, script, cli_out) \
b32 n(Arena *scratch, char *path, char *script, CLI_Handles *cli_out)
typedef Sys_CLI_Call_Sig(System_CLI_Call, scratch, path, script, cli_out);
#define Sys_CLI_Begin_Update_Sig(name) void name(CLI_Handles *cli)
@ -95,7 +118,6 @@ typedef Sys_CLI_Update_Step_Sig(System_CLI_Update_Step);
typedef Sys_CLI_End_Update_Sig(System_CLI_End_Update);
//
#define Sys_Open_Color_Picker_Sig(name) void name(Color_Picker *picker)
typedef Sys_Open_Color_Picker_Sig(System_Open_Color_Picker);
@ -103,12 +125,8 @@ typedef Sys_Open_Color_Picker_Sig(System_Open_Color_Picker);
typedef Sys_Get_Screen_Scale_Factor_Sig(System_Get_Screen_Scale_Factor);
// thread
typedef Plat_Handle System_Thread;
typedef Plat_Handle System_Mutex;
typedef Plat_Handle System_Condition_Variable;
typedef void Thread_Function(void *ptr);
#define Sys_Thread_Launch_Sig(name) System_Thread name(Thread_Function *proc, void *ptr)
#define Sys_Thread_Launch_Sig(name) \
System_Thread name(Thread_Function *proc, void *ptr)
typedef Sys_Thread_Launch_Sig(System_Thread_Launch);
#define Sys_Thread_Join_Sig(name) void name(System_Thread thread)
@ -155,11 +173,8 @@ typedef Sys_Memory_Set_Protection_Sig(System_Memory_Set_Protection);
typedef Sys_Memory_Free_Sig(System_Memory_Free);
// file system
#define Sys_Get_Current_Path_Sig(name) String_Const_u8 name(Arena *arena)
typedef Sys_Get_Current_Path_Sig(System_Get_Current_Path);
#define Sys_Get_4ed_Path_Sig(name) String_Const_u8 name(Arena *arena)
typedef Sys_Get_4ed_Path_Sig(System_Get_4ed_Path);
#define Sys_Get_Path_Sig(name) String_Const_u8 name(Arena *arena, System_Path_Code code)
typedef Sys_Get_Path_Sig(System_Get_Path);
// behavior and appearance options
#define Sys_Show_Mouse_Cursor_Sig(name) void name(i32 show)
@ -186,6 +201,11 @@ struct System_Functions{
System_Load_Close *load_close;
System_Save_File *save_file;
// library
System_Load_Library *load_library;
System_Release_Library *release_library;
System_Get_Proc *get_proc;
// time
System_Now_Time *now_time;
System_Wake_Up_Timer_Create *wake_up_timer_create;
@ -226,8 +246,7 @@ struct System_Functions{
System_Memory_Set_Protection *memory_set_protection;
System_Memory_Free *memory_free;
System_Get_Current_Path *get_current_path;
System_Get_4ed_Path *get_4ed_path;
System_Get_Path *get_path;
System_Show_Mouse_Cursor *show_mouse_cursor;
System_Set_Fullscreen *set_fullscreen;

250
4ed_system_api.cpp Normal file
View File

@ -0,0 +1,250 @@
/*
* Mr. 4th Dimention - Allen Webster
*
* 02.10.2019
*
* System API definition program.
*
*/
// TOP
#include "4ed_api_definition.cpp"
function API_Definition*
define_api(Arena *arena){
API_Definition *api = begin_api(arena, "system");
{
API_Call *call = api_call(arena, api, "get_canonical", "String_Const_u8");
api_param(arena, call, "Arena*", "arena");
api_param(arena, call, "String_Const_u8", "name");
}
{
API_Call *call = api_call(arena, api, "get_file_list", "File_List");
api_param(arena, call, "Arena*", "arena");
api_param(arena, call, "String_Const_u8", "directory");
}
{
API_Call *call = api_call(arena, api, "quick_file_attributes", "File_Attributes");
api_param(arena, call, "Arena*", "scratch");
api_param(arena, call, "String_Const_u8", "file_name");
}
{
API_Call *call = api_call(arena, api, "load_handle", "b32");
api_param(arena, call, "Arena*", "scratch");
api_param(arena, call, "char*", "file_name");
api_param(arena, call, "Plat_Handle*", "out");
}
{
API_Call *call = api_call(arena, api, "load_attributes", "File_Attributes");
api_param(arena, call, "Plat_Handle", "handle");
}
{
API_Call *call = api_call(arena, api, "load_file", "b32");
api_param(arena, call, "Plat_Handle", "handle");
api_param(arena, call, "char*", "buffer");
api_param(arena, call, "u32", "size");
}
{
API_Call *call = api_call(arena, api, "load_close", "b32");
api_param(arena, call, "Plat_Handle", "handle");
}
{
API_Call *call = api_call(arena, api, "save_file", "File_Attributes");
api_param(arena, call, "Arena*", "scratch");
api_param(arena, call, "char*", "file_name");
api_param(arena, call, "String_Const_u8", "data");
}
{
API_Call *call = api_call(arena, api, "load_library", "b32");
api_param(arena, call, "Arena*", "scratch");
api_param(arena, call, "String_Const_u8", "file_name");
api_param(arena, call, "System_Library*", "out");
}
{
API_Call *call = api_call(arena, api, "release_library", "b32");
api_param(arena, call, "System_Library", "handle");
}
{
API_Call *call = api_call(arena, api, "get_proc", "Void_Func");
api_param(arena, call, "System_Library", "handle");
api_param(arena, call, "char*", "proc_name");
}
{
API_Call *call = api_call(arena, api, "now_time", "u64");
}
{
API_Call *call = api_call(arena, api, "wake_up_timer_create", "Plat_Handle");
}
{
API_Call *call = api_call(arena, api, "wake_up_timer_release", "void");
api_param(arena, call, "Plat_Handle", "handle");
}
{
API_Call *call = api_call(arena, api, "wake_up_timer_set", "void");
api_param(arena, call, "Plat_Handle", "handle");
api_param(arena, call, "u32", "time_milliseconds");
}
{
API_Call *call = api_call(arena, api, "signal_step", "void");
api_param(arena, call, "u32", "code");
}
{
API_Call *call = api_call(arena, api, "sleep", "void");
api_param(arena, call, "u64", "microseconds");
}
{
API_Call *call = api_call(arena, api, "post_clipboard", "void");
api_param(arena, call, "String_Const_u8", "str");
}
{
API_Call *call = api_call(arena, api, "cli_call", "b32");
api_param(arena, call, "Arena*", "scratch");
api_param(arena, call, "char*", "path");
api_param(arena, call, "char*", "script");
api_param(arena, call, "CLI_Handles*", "cli_out");
}
{
API_Call *call = api_call(arena, api, "cli_begin_update", "void");
api_param(arena, call, "CLI_Handles*", "cli");
}
{
API_Call *call = api_call(arena, api, "cli_update_step", "b32");
api_param(arena, call, "CLI_Handles*", "cli");
api_param(arena, call, "char*", "dest");
api_param(arena, call, "u32", "max");
api_param(arena, call, "u32*", "amount");
}
{
API_Call *call = api_call(arena, api, "cli_end_update", "b32");
api_param(arena, call, "CLI_Handles*", "cli");
}
{
API_Call *call = api_call(arena, api, "open_color_picker", "void");
api_param(arena, call, "Color_Picker*", "picker");
}
{
API_Call *call = api_call(arena, api, "get_screen_scale_factor", "f32");
}
{
API_Call *call = api_call(arena, api, "thread_launch", "System_Thread");
api_param(arena, call, "Thread_Function*", "proc");
api_param(arena, call, "void*", "ptr");
}
{
API_Call *call = api_call(arena, api, "thread_join", "void");
api_param(arena, call, "System_Thread", "thread");
}
{
API_Call *call = api_call(arena, api, "thread_free", "void");
api_param(arena, call, "System_Thread", "thread");
}
{
API_Call *call = api_call(arena, api, "thread_get_id", "i32");
}
{
API_Call *call = api_call(arena, api, "mutex_make", "System_Mutex");
}
{
API_Call *call = api_call(arena, api, "mutex_acquire", "void");
api_param(arena, call, "System_Mutex", "mutex");
}
{
API_Call *call = api_call(arena, api, "mutex_release", "void");
api_param(arena, call, "System_Mutex", "mutex");
}
{
API_Call *call = api_call(arena, api, "mutex_free", "void");
api_param(arena, call, "System_Mutex", "mutex");
}
{
API_Call *call = api_call(arena, api, "condition_variable_make",
"System_Condition_Variable");
}
{
API_Call *call = api_call(arena, api, "condition_variable_wait", "void");
api_param(arena, call, "System_Condition_Variable", "cv");
api_param(arena, call, "System_Mutex", "mutex");
}
{
API_Call *call = api_call(arena, api, "condition_variable_signal", "void");
api_param(arena, call, "System_Condition_Variable", "cv");
}
{
API_Call *call = api_call(arena, api, "condition_variable_free", "void");
api_param(arena, call, "System_Condition_Variable", "cv");
}
{
API_Call *call = api_call(arena, api, "memory_allocate", "void*");
api_param(arena, call, "umem", "size");
}
{
API_Call *call = api_call(arena, api, "memory_set_protection", "b32");
api_param(arena, call, "void*", "ptr");
api_param(arena, call, "umem", "size");
api_param(arena, call, "u32", "flags");
}
{
API_Call *call = api_call(arena, api, "memory_free", "void");
api_param(arena, call, "void*", "ptr");
api_param(arena, call, "umem", "size");
}
{
API_Call *call = api_call(arena, api, "show_mouse_cursor", "void");
api_param(arena, call, "i32", "show");
}
{
API_Call *call = api_call(arena, api, "set_fullscreen", "b32");
api_param(arena, call, "b32", "full_screen");
}
{
API_Call *call = api_call(arena, api, "is_fullscreen", "b32");
}
return(api);
}
// BOTTOM

11
generated/font_api.cpp Normal file
View File

@ -0,0 +1,11 @@
function void
font_api_fill_vtable(API_VTable_font *vtable){
vtable->make_face = font_make_face;
}
#if defined(DYNAMIC_LINK_API)
function void
font_api_read_vtable(API_VTable_font *vtable){
font_make_face = vtable->make_face;
}
#undef DYNAMIC_LINK_API
#endif

12
generated/font_api.h Normal file
View File

@ -0,0 +1,12 @@
#define font_make_face_sig() Face* font_make_face(Arena* arena, Face_Description* description, f32 scale_factor)
typedef Face* font_make_face_type(Arena* arena, Face_Description* description, f32 scale_factor);
struct API_VTable_font{
font_make_face_type *make_face;
};
#if defined(STATIC_LINK_API)
internal Face* font_make_face(Arena* arena, Face_Description* description, f32 scale_factor);
#undef STATIC_LINK_API
#elif defined(DYNAMIC_LINK_API)
global font_make_face_type *font_make_face = 0;
#undef DYNAMIC_LINK_API
#endif

View File

@ -0,0 +1,13 @@
function void
graphics_api_fill_vtable(API_VTable_graphics *vtable){
vtable->get_texture = graphics_get_texture;
vtable->fill_texture = graphics_fill_texture;
}
#if defined(DYNAMIC_LINK_API)
function void
graphics_api_read_vtable(API_VTable_graphics *vtable){
graphics_get_texture = vtable->get_texture;
graphics_fill_texture = vtable->fill_texture;
}
#undef DYNAMIC_LINK_API
#endif

17
generated/graphics_api.h Normal file
View File

@ -0,0 +1,17 @@
#define graphics_get_texture_sig() u32 graphics_get_texture(Vec3_i32 dim, Texture_Kind texture_kind)
#define graphics_fill_texture_sig() b32 graphics_fill_texture(Texture_Kind texture_kind, u32 texture, Vec3_i32 p, Vec3_i32 dim, void* data)
typedef u32 graphics_get_texture_type(Vec3_i32 dim, Texture_Kind texture_kind);
typedef b32 graphics_fill_texture_type(Texture_Kind texture_kind, u32 texture, Vec3_i32 p, Vec3_i32 dim, void* data);
struct API_VTable_graphics{
graphics_get_texture_type *get_texture;
graphics_fill_texture_type *fill_texture;
};
#if defined(STATIC_LINK_API)
internal u32 graphics_get_texture(Vec3_i32 dim, Texture_Kind texture_kind);
internal b32 graphics_fill_texture(Texture_Kind texture_kind, u32 texture, Vec3_i32 p, Vec3_i32 dim, void* data);
#undef STATIC_LINK_API
#elif defined(DYNAMIC_LINK_API)
global graphics_get_texture_type *graphics_get_texture = 0;
global graphics_fill_texture_type *graphics_fill_texture = 0;
#undef DYNAMIC_LINK_API
#endif

93
generated/system_api.cpp Normal file
View File

@ -0,0 +1,93 @@
function void
system_api_fill_vtable(API_VTable_system *vtable){
vtable->get_canonical = system_get_canonical;
vtable->get_file_list = system_get_file_list;
vtable->quick_file_attributes = system_quick_file_attributes;
vtable->load_handle = system_load_handle;
vtable->load_attributes = system_load_attributes;
vtable->load_file = system_load_file;
vtable->load_close = system_load_close;
vtable->save_file = system_save_file;
vtable->load_library = system_load_library;
vtable->release_library = system_release_library;
vtable->get_proc = system_get_proc;
vtable->now_time = system_now_time;
vtable->wake_up_timer_create = system_wake_up_timer_create;
vtable->wake_up_timer_release = system_wake_up_timer_release;
vtable->wake_up_timer_set = system_wake_up_timer_set;
vtable->signal_step = system_signal_step;
vtable->sleep = system_sleep;
vtable->post_clipboard = system_post_clipboard;
vtable->cli_call = system_cli_call;
vtable->cli_begin_update = system_cli_begin_update;
vtable->cli_update_step = system_cli_update_step;
vtable->cli_end_update = system_cli_end_update;
vtable->open_color_picker = system_open_color_picker;
vtable->get_screen_scale_factor = system_get_screen_scale_factor;
vtable->thread_launch = system_thread_launch;
vtable->thread_join = system_thread_join;
vtable->thread_free = system_thread_free;
vtable->thread_get_id = system_thread_get_id;
vtable->mutex_make = system_mutex_make;
vtable->mutex_acquire = system_mutex_acquire;
vtable->mutex_release = system_mutex_release;
vtable->mutex_free = system_mutex_free;
vtable->condition_variable_make = system_condition_variable_make;
vtable->condition_variable_wait = system_condition_variable_wait;
vtable->condition_variable_signal = system_condition_variable_signal;
vtable->condition_variable_free = system_condition_variable_free;
vtable->memory_allocate = system_memory_allocate;
vtable->memory_set_protection = system_memory_set_protection;
vtable->memory_free = system_memory_free;
vtable->show_mouse_cursor = system_show_mouse_cursor;
vtable->set_fullscreen = system_set_fullscreen;
vtable->is_fullscreen = system_is_fullscreen;
}
#if defined(DYNAMIC_LINK_API)
function void
system_api_read_vtable(API_VTable_system *vtable){
system_get_canonical = vtable->get_canonical;
system_get_file_list = vtable->get_file_list;
system_quick_file_attributes = vtable->quick_file_attributes;
system_load_handle = vtable->load_handle;
system_load_attributes = vtable->load_attributes;
system_load_file = vtable->load_file;
system_load_close = vtable->load_close;
system_save_file = vtable->save_file;
system_load_library = vtable->load_library;
system_release_library = vtable->release_library;
system_get_proc = vtable->get_proc;
system_now_time = vtable->now_time;
system_wake_up_timer_create = vtable->wake_up_timer_create;
system_wake_up_timer_release = vtable->wake_up_timer_release;
system_wake_up_timer_set = vtable->wake_up_timer_set;
system_signal_step = vtable->signal_step;
system_sleep = vtable->sleep;
system_post_clipboard = vtable->post_clipboard;
system_cli_call = vtable->cli_call;
system_cli_begin_update = vtable->cli_begin_update;
system_cli_update_step = vtable->cli_update_step;
system_cli_end_update = vtable->cli_end_update;
system_open_color_picker = vtable->open_color_picker;
system_get_screen_scale_factor = vtable->get_screen_scale_factor;
system_thread_launch = vtable->thread_launch;
system_thread_join = vtable->thread_join;
system_thread_free = vtable->thread_free;
system_thread_get_id = vtable->thread_get_id;
system_mutex_make = vtable->mutex_make;
system_mutex_acquire = vtable->mutex_acquire;
system_mutex_release = vtable->mutex_release;
system_mutex_free = vtable->mutex_free;
system_condition_variable_make = vtable->condition_variable_make;
system_condition_variable_wait = vtable->condition_variable_wait;
system_condition_variable_signal = vtable->condition_variable_signal;
system_condition_variable_free = vtable->condition_variable_free;
system_memory_allocate = vtable->memory_allocate;
system_memory_set_protection = vtable->memory_set_protection;
system_memory_free = vtable->memory_free;
system_show_mouse_cursor = vtable->show_mouse_cursor;
system_set_fullscreen = vtable->set_fullscreen;
system_is_fullscreen = vtable->is_fullscreen;
}
#undef DYNAMIC_LINK_API
#endif

217
generated/system_api.h Normal file
View File

@ -0,0 +1,217 @@
#define system_get_canonical_sig() String_Const_u8 system_get_canonical(Arena* arena, String_Const_u8 name)
#define system_get_file_list_sig() File_List system_get_file_list(Arena* arena, String_Const_u8 directory)
#define system_quick_file_attributes_sig() File_Attributes system_quick_file_attributes(Arena* scratch, String_Const_u8 file_name)
#define system_load_handle_sig() b32 system_load_handle(Arena* scratch, char* file_name, Plat_Handle* out)
#define system_load_attributes_sig() File_Attributes system_load_attributes(Plat_Handle handle)
#define system_load_file_sig() b32 system_load_file(Plat_Handle handle, char* buffer, u32 size)
#define system_load_close_sig() b32 system_load_close(Plat_Handle handle)
#define system_save_file_sig() File_Attributes system_save_file(Arena* scratch, char* file_name, String_Const_u8 data)
#define system_load_library_sig() b32 system_load_library(Arena* scratch, String_Const_u8 file_name, System_Library* out)
#define system_release_library_sig() b32 system_release_library(System_Library handle)
#define system_get_proc_sig() Void_Func system_get_proc(System_Library handle, char* proc_name)
#define system_now_time_sig() u64 system_now_time(void)
#define system_wake_up_timer_create_sig() Plat_Handle system_wake_up_timer_create(void)
#define system_wake_up_timer_release_sig() void system_wake_up_timer_release(Plat_Handle handle)
#define system_wake_up_timer_set_sig() void system_wake_up_timer_set(Plat_Handle handle, u32 time_milliseconds)
#define system_signal_step_sig() void system_signal_step(u32 code)
#define system_sleep_sig() void system_sleep(u64 microseconds)
#define system_post_clipboard_sig() void system_post_clipboard(String_Const_u8 str)
#define system_cli_call_sig() b32 system_cli_call(Arena* scratch, char* path, char* script, CLI_Handles* cli_out)
#define system_cli_begin_update_sig() void system_cli_begin_update(CLI_Handles* cli)
#define system_cli_update_step_sig() b32 system_cli_update_step(CLI_Handles* cli, char* dest, u32 max, u32* amount)
#define system_cli_end_update_sig() b32 system_cli_end_update(CLI_Handles* cli)
#define system_open_color_picker_sig() void system_open_color_picker(Color_Picker* picker)
#define system_get_screen_scale_factor_sig() f32 system_get_screen_scale_factor(void)
#define system_thread_launch_sig() System_Thread system_thread_launch(Thread_Function* proc, void* ptr)
#define system_thread_join_sig() void system_thread_join(System_Thread thread)
#define system_thread_free_sig() void system_thread_free(System_Thread thread)
#define system_thread_get_id_sig() i32 system_thread_get_id(void)
#define system_mutex_make_sig() System_Mutex system_mutex_make(void)
#define system_mutex_acquire_sig() void system_mutex_acquire(System_Mutex mutex)
#define system_mutex_release_sig() void system_mutex_release(System_Mutex mutex)
#define system_mutex_free_sig() void system_mutex_free(System_Mutex mutex)
#define system_condition_variable_make_sig() System_Condition_Variable system_condition_variable_make(void)
#define system_condition_variable_wait_sig() void system_condition_variable_wait(System_Condition_Variable cv, System_Mutex mutex)
#define system_condition_variable_signal_sig() void system_condition_variable_signal(System_Condition_Variable cv)
#define system_condition_variable_free_sig() void system_condition_variable_free(System_Condition_Variable cv)
#define system_memory_allocate_sig() void* system_memory_allocate(umem size)
#define system_memory_set_protection_sig() b32 system_memory_set_protection(void* ptr, umem size, u32 flags)
#define system_memory_free_sig() void system_memory_free(void* ptr, umem size)
#define system_show_mouse_cursor_sig() void system_show_mouse_cursor(i32 show)
#define system_set_fullscreen_sig() b32 system_set_fullscreen(b32 full_screen)
#define system_is_fullscreen_sig() b32 system_is_fullscreen(void)
typedef String_Const_u8 system_get_canonical_type(Arena* arena, String_Const_u8 name);
typedef File_List system_get_file_list_type(Arena* arena, String_Const_u8 directory);
typedef File_Attributes system_quick_file_attributes_type(Arena* scratch, String_Const_u8 file_name);
typedef b32 system_load_handle_type(Arena* scratch, char* file_name, Plat_Handle* out);
typedef File_Attributes system_load_attributes_type(Plat_Handle handle);
typedef b32 system_load_file_type(Plat_Handle handle, char* buffer, u32 size);
typedef b32 system_load_close_type(Plat_Handle handle);
typedef File_Attributes system_save_file_type(Arena* scratch, char* file_name, String_Const_u8 data);
typedef b32 system_load_library_type(Arena* scratch, String_Const_u8 file_name, System_Library* out);
typedef b32 system_release_library_type(System_Library handle);
typedef Void_Func system_get_proc_type(System_Library handle, char* proc_name);
typedef u64 system_now_time_type(void);
typedef Plat_Handle system_wake_up_timer_create_type(void);
typedef void system_wake_up_timer_release_type(Plat_Handle handle);
typedef void system_wake_up_timer_set_type(Plat_Handle handle, u32 time_milliseconds);
typedef void system_signal_step_type(u32 code);
typedef void system_sleep_type(u64 microseconds);
typedef void system_post_clipboard_type(String_Const_u8 str);
typedef b32 system_cli_call_type(Arena* scratch, char* path, char* script, CLI_Handles* cli_out);
typedef void system_cli_begin_update_type(CLI_Handles* cli);
typedef b32 system_cli_update_step_type(CLI_Handles* cli, char* dest, u32 max, u32* amount);
typedef b32 system_cli_end_update_type(CLI_Handles* cli);
typedef void system_open_color_picker_type(Color_Picker* picker);
typedef f32 system_get_screen_scale_factor_type(void);
typedef System_Thread system_thread_launch_type(Thread_Function* proc, void* ptr);
typedef void system_thread_join_type(System_Thread thread);
typedef void system_thread_free_type(System_Thread thread);
typedef i32 system_thread_get_id_type(void);
typedef System_Mutex system_mutex_make_type(void);
typedef void system_mutex_acquire_type(System_Mutex mutex);
typedef void system_mutex_release_type(System_Mutex mutex);
typedef void system_mutex_free_type(System_Mutex mutex);
typedef System_Condition_Variable system_condition_variable_make_type(void);
typedef void system_condition_variable_wait_type(System_Condition_Variable cv, System_Mutex mutex);
typedef void system_condition_variable_signal_type(System_Condition_Variable cv);
typedef void system_condition_variable_free_type(System_Condition_Variable cv);
typedef void* system_memory_allocate_type(umem size);
typedef b32 system_memory_set_protection_type(void* ptr, umem size, u32 flags);
typedef void system_memory_free_type(void* ptr, umem size);
typedef void system_show_mouse_cursor_type(i32 show);
typedef b32 system_set_fullscreen_type(b32 full_screen);
typedef b32 system_is_fullscreen_type(void);
struct API_VTable_system{
system_get_canonical_type *get_canonical;
system_get_file_list_type *get_file_list;
system_quick_file_attributes_type *quick_file_attributes;
system_load_handle_type *load_handle;
system_load_attributes_type *load_attributes;
system_load_file_type *load_file;
system_load_close_type *load_close;
system_save_file_type *save_file;
system_load_library_type *load_library;
system_release_library_type *release_library;
system_get_proc_type *get_proc;
system_now_time_type *now_time;
system_wake_up_timer_create_type *wake_up_timer_create;
system_wake_up_timer_release_type *wake_up_timer_release;
system_wake_up_timer_set_type *wake_up_timer_set;
system_signal_step_type *signal_step;
system_sleep_type *sleep;
system_post_clipboard_type *post_clipboard;
system_cli_call_type *cli_call;
system_cli_begin_update_type *cli_begin_update;
system_cli_update_step_type *cli_update_step;
system_cli_end_update_type *cli_end_update;
system_open_color_picker_type *open_color_picker;
system_get_screen_scale_factor_type *get_screen_scale_factor;
system_thread_launch_type *thread_launch;
system_thread_join_type *thread_join;
system_thread_free_type *thread_free;
system_thread_get_id_type *thread_get_id;
system_mutex_make_type *mutex_make;
system_mutex_acquire_type *mutex_acquire;
system_mutex_release_type *mutex_release;
system_mutex_free_type *mutex_free;
system_condition_variable_make_type *condition_variable_make;
system_condition_variable_wait_type *condition_variable_wait;
system_condition_variable_signal_type *condition_variable_signal;
system_condition_variable_free_type *condition_variable_free;
system_memory_allocate_type *memory_allocate;
system_memory_set_protection_type *memory_set_protection;
system_memory_free_type *memory_free;
system_show_mouse_cursor_type *show_mouse_cursor;
system_set_fullscreen_type *set_fullscreen;
system_is_fullscreen_type *is_fullscreen;
};
#if defined(STATIC_LINK_API)
internal String_Const_u8 system_get_canonical(Arena* arena, String_Const_u8 name);
internal File_List system_get_file_list(Arena* arena, String_Const_u8 directory);
internal File_Attributes system_quick_file_attributes(Arena* scratch, String_Const_u8 file_name);
internal b32 system_load_handle(Arena* scratch, char* file_name, Plat_Handle* out);
internal File_Attributes system_load_attributes(Plat_Handle handle);
internal b32 system_load_file(Plat_Handle handle, char* buffer, u32 size);
internal b32 system_load_close(Plat_Handle handle);
internal File_Attributes system_save_file(Arena* scratch, char* file_name, String_Const_u8 data);
internal b32 system_load_library(Arena* scratch, String_Const_u8 file_name, System_Library* out);
internal b32 system_release_library(System_Library handle);
internal Void_Func system_get_proc(System_Library handle, char* proc_name);
internal u64 system_now_time(void);
internal Plat_Handle system_wake_up_timer_create(void);
internal void system_wake_up_timer_release(Plat_Handle handle);
internal void system_wake_up_timer_set(Plat_Handle handle, u32 time_milliseconds);
internal void system_signal_step(u32 code);
internal void system_sleep(u64 microseconds);
internal void system_post_clipboard(String_Const_u8 str);
internal b32 system_cli_call(Arena* scratch, char* path, char* script, CLI_Handles* cli_out);
internal void system_cli_begin_update(CLI_Handles* cli);
internal b32 system_cli_update_step(CLI_Handles* cli, char* dest, u32 max, u32* amount);
internal b32 system_cli_end_update(CLI_Handles* cli);
internal void system_open_color_picker(Color_Picker* picker);
internal f32 system_get_screen_scale_factor(void);
internal System_Thread system_thread_launch(Thread_Function* proc, void* ptr);
internal void system_thread_join(System_Thread thread);
internal void system_thread_free(System_Thread thread);
internal i32 system_thread_get_id(void);
internal System_Mutex system_mutex_make(void);
internal void system_mutex_acquire(System_Mutex mutex);
internal void system_mutex_release(System_Mutex mutex);
internal void system_mutex_free(System_Mutex mutex);
internal System_Condition_Variable system_condition_variable_make(void);
internal void system_condition_variable_wait(System_Condition_Variable cv, System_Mutex mutex);
internal void system_condition_variable_signal(System_Condition_Variable cv);
internal void system_condition_variable_free(System_Condition_Variable cv);
internal void* system_memory_allocate(umem size);
internal b32 system_memory_set_protection(void* ptr, umem size, u32 flags);
internal void system_memory_free(void* ptr, umem size);
internal void system_show_mouse_cursor(i32 show);
internal b32 system_set_fullscreen(b32 full_screen);
internal b32 system_is_fullscreen(void);
#undef STATIC_LINK_API
#elif defined(DYNAMIC_LINK_API)
global system_get_canonical_type *system_get_canonical = 0;
global system_get_file_list_type *system_get_file_list = 0;
global system_quick_file_attributes_type *system_quick_file_attributes = 0;
global system_load_handle_type *system_load_handle = 0;
global system_load_attributes_type *system_load_attributes = 0;
global system_load_file_type *system_load_file = 0;
global system_load_close_type *system_load_close = 0;
global system_save_file_type *system_save_file = 0;
global system_load_library_type *system_load_library = 0;
global system_release_library_type *system_release_library = 0;
global system_get_proc_type *system_get_proc = 0;
global system_now_time_type *system_now_time = 0;
global system_wake_up_timer_create_type *system_wake_up_timer_create = 0;
global system_wake_up_timer_release_type *system_wake_up_timer_release = 0;
global system_wake_up_timer_set_type *system_wake_up_timer_set = 0;
global system_signal_step_type *system_signal_step = 0;
global system_sleep_type *system_sleep = 0;
global system_post_clipboard_type *system_post_clipboard = 0;
global system_cli_call_type *system_cli_call = 0;
global system_cli_begin_update_type *system_cli_begin_update = 0;
global system_cli_update_step_type *system_cli_update_step = 0;
global system_cli_end_update_type *system_cli_end_update = 0;
global system_open_color_picker_type *system_open_color_picker = 0;
global system_get_screen_scale_factor_type *system_get_screen_scale_factor = 0;
global system_thread_launch_type *system_thread_launch = 0;
global system_thread_join_type *system_thread_join = 0;
global system_thread_free_type *system_thread_free = 0;
global system_thread_get_id_type *system_thread_get_id = 0;
global system_mutex_make_type *system_mutex_make = 0;
global system_mutex_acquire_type *system_mutex_acquire = 0;
global system_mutex_release_type *system_mutex_release = 0;
global system_mutex_free_type *system_mutex_free = 0;
global system_condition_variable_make_type *system_condition_variable_make = 0;
global system_condition_variable_wait_type *system_condition_variable_wait = 0;
global system_condition_variable_signal_type *system_condition_variable_signal = 0;
global system_condition_variable_free_type *system_condition_variable_free = 0;
global system_memory_allocate_type *system_memory_allocate = 0;
global system_memory_set_protection_type *system_memory_set_protection = 0;
global system_memory_free_type *system_memory_free = 0;
global system_show_mouse_cursor_type *system_show_mouse_cursor = 0;
global system_set_fullscreen_type *system_set_fullscreen = 0;
global system_is_fullscreen_type *system_is_fullscreen = 0;
#undef DYNAMIC_LINK_API
#endif

View File

@ -24,6 +24,10 @@ link_system_code(void){
SYSLINK(load_close);
SYSLINK(save_file);
SYSLINK(load_library);
SYSLINK(release_library);
SYSLINK(get_proc);
SYSLINK(now_time);
SYSLINK(wake_up_timer_create);
SYSLINK(wake_up_timer_release);
@ -58,8 +62,7 @@ link_system_code(void){
SYSLINK(memory_set_protection);
SYSLINK(memory_free);
SYSLINK(get_current_path);
SYSLINK(get_4ed_path);
SYSLINK(get_path);
SYSLINK(set_fullscreen);
SYSLINK(is_fullscreen);

View File

@ -9,6 +9,9 @@
// TOP
#error remove this file
#if 0
#if !defined(FRED_SHARED_LIBRARY_CONSTANTS_H)
#define FRED_SHARED_LIBRARY_CONSTANTS_H
@ -87,6 +90,7 @@ system_load_library(Arena *scratch, Library *library, char *name, Load_Library_L
return(system_load_library(scratch, library, name, location, 0, 0));
}
#endif
#endif
// BOTTOM

View File

@ -20,17 +20,20 @@
#include "api/4coder_default_colors.h"
#include "api/4coder_types.h"
#include "4ed_font_interface.h"
#include "4ed_font_set.h"
#include "4ed_system.h"
#include "4ed_render_target.h"
#include "4ed_search_list.h"
#include "4ed.h"
#include "4coder_base_types.cpp"
#include "4coder_stringf.cpp"
#include "4coder_hash_functions.cpp"
#include "4coder_table.cpp"
#include "4coder_log.cpp"
#include "4ed_font_interface.h"
#include "4ed_font_set.h"
#include "4ed_system.h"
#include "4ed_render_target.h"
#include "4ed.h"
#include "4ed_search_list.cpp"
#undef function
#define UNICODE
@ -92,10 +95,6 @@ struct Win32_Input_Chunk{
#define SLASH '\\'
#define DLL "dll"
global System_Functions sysfunc;
#include "4ed_shared_library_constants.h"
#include "win32_library_wrapper.h"
#include "4ed_font_face.cpp"
#include "4ed_mem.cpp"
@ -106,6 +105,8 @@ global System_Functions sysfunc;
////////////////////////////////
global System_Functions sysfunc = {};
typedef i32 Win32_Object_Kind;
enum{
Win32ObjectKind_ERROR = 0,
@ -245,6 +246,31 @@ handle_type_ptr(void *ptr){
////////////////////////////////
internal
Sys_Load_Library_Sig(system_load_library){
HMODULE lib = LoadLibrary_utf8String(scratch, file_name);
b32 result = false;
if (lib != 0){
result = true;
*out = handle_type(lib);
}
return(result);
}
internal
Sys_Release_Library_Sig(system_release_library){
HMODULE lib = (HMODULE)handle_type(handle);
return(FreeLibrary(lib));
}
internal
Sys_Get_Proc_Sig(system_get_proc){
HMODULE lib = (HMODULE)handle_type(handle);
return((Void_Func*)(GetProcAddress(lib, proc_name)));
}
////////////////////////////////
internal void
system_schedule_step(u32 code){
PostMessage(win32vars.window_handle, WM_4coder_ANIMATE, code, 0);
@ -1505,13 +1531,17 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
}
// NOTE(allen): load core
Library core_library = {};
System_Library core_library = {};
App_Functions app = {};
{
App_Get_Functions *get_funcs = 0;
Scratch_Block scratch(win32vars.tctx, Scratch_Share);
if (system_load_library(scratch, &core_library, "4ed_app", LoadLibrary_BinaryDirectory)){
get_funcs = (App_Get_Functions*)system_get_proc(&core_library, "app_get_functions");
Path_Search_List search_list = {};
search_list_add_system_path(&sysfunc, scratch, &search_list, SystemPath_Binary);
String_Const_u8 core_path = get_full_path(&sysfunc, scratch, &search_list, SCu8("4ed_app.dll"));
if (system_load_library(scratch, core_path, &core_library)){
get_funcs = (App_Get_Functions*)system_get_proc(core_library, "app_get_functions");
if (get_funcs != 0){
app = get_funcs();
}
@ -1532,7 +1562,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
void *base_ptr = 0;
{
Scratch_Block scratch(win32vars.tctx, Scratch_Share);
String_Const_u8 curdir = sysfunc.get_current_path(scratch);
String_Const_u8 curdir = sysfunc.get_path(scratch, SystemPath_CurrentDirectory);
curdir = string_mod_replace_character(curdir, '\\', '/');
char **files = 0;
i32 *file_count = 0;
@ -1551,49 +1581,52 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
}
// NOTE(allen): load custom layer
Library custom_library = {};
System_Library custom_library = {};
Custom_API custom = {};
{
Scratch_Block scratch(win32vars.tctx, Scratch_Share);
char *default_file = "custom_4coder";
Load_Library_Location locations[] = {
LoadLibrary_CurrentDirectory,
LoadLibrary_BinaryDirectory,
};
char custom_not_found_msg[] = "Did not find a library for the custom layer.";
char custom_fail_version_msg[] = "Failed to load custom code due to missing version information or a version mismatch. Try rebuilding with buildsuper.";
char custom_fail_missing_get_bindings_msg[] = "Failed to load custom code due to missing 'get_bindings' symbol. Try rebuilding with buildsuper.";
char *custom_files[3] = {};
Scratch_Block scratch(win32vars.tctx, Scratch_Share);
String_Const_u8 default_file_name = string_u8_litexpr("custom_4coder.dll");
Path_Search_List search_list = {};
search_list_add_system_path(&sysfunc, scratch, &search_list, SystemPath_CurrentDirectory);
search_list_add_system_path(&sysfunc, scratch, &search_list, SystemPath_Binary);
String_Const_u8 custom_file_names[2] = {};
i32 custom_file_count = 1;
if (plat_settings.custom_dll != 0){
custom_files[0] = plat_settings.custom_dll;
custom_file_names[0] = SCu8(plat_settings.custom_dll);
if (!plat_settings.custom_dll_is_strict){
custom_files[1] = default_file;
custom_file_names[1] = default_file_name;
custom_file_count += 1;
}
}
else{
custom_files[0] = default_file;
custom_file_names[0] = default_file_name;
}
String_Const_u8 custom_file_name = {};
for (i32 i = 0; i < custom_file_count; i += 1){
custom_file_name = get_full_path(&sysfunc, scratch, &search_list, custom_file_names[i]);
if (custom_file_name.size > 0){
break;
}
}
char success_file[4096];
b32 has_library = false;
for (u32 i = 0; custom_files[i] != 0 && !has_library; ++i){
char *file = custom_files[i];
for (u32 j = 0; j < ArrayCount(locations) && !has_library; ++j){
if (system_load_library(scratch, &custom_library, file, locations[j], success_file, sizeof(success_file))){
has_library = true;
success_file[sizeof(success_file) - 1] = 0;
}
if (custom_file_name.size > 0){
if (system_load_library(scratch, custom_file_name, &custom_library)){
has_library = true;
}
}
if (!has_library){
system_error_box(scratch, custom_not_found_msg);
}
custom.get_alpha_4coder_version = (_Get_Version_Function*)system_get_proc(&custom_library, "get_alpha_4coder_version");
custom.get_alpha_4coder_version = (_Get_Version_Function*)system_get_proc(custom_library, "get_alpha_4coder_version");
if (custom.get_alpha_4coder_version == 0 || custom.get_alpha_4coder_version(MAJOR, MINOR, PATCH) == 0){
system_error_box(scratch, custom_fail_version_msg);
}
custom.get_bindings = (Get_Binding_Data_Function*)system_get_proc(&custom_library, "get_bindings");
custom.get_bindings = (Get_Binding_Data_Function*)system_get_proc(custom_library, "get_bindings");
if (custom.get_bindings == 0){
system_error_box(scratch, custom_fail_missing_get_bindings_msg);
}
@ -1678,7 +1711,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
{
Scratch_Block scratch(win32vars.tctx, Scratch_Share);
String_Const_u8 curdir = sysfunc.get_current_path(scratch);
String_Const_u8 curdir = sysfunc.get_path(scratch, SystemPath_CurrentDirectory);
curdir = string_mod_replace_character(curdir, '\\', '/');
app.init(&sysfunc, &target, base_ptr, win32vars.clipboard_contents, curdir, custom);
}

View File

@ -66,27 +66,34 @@ Sys_Memory_Free_Sig(system_memory_free){
//
internal
Sys_Get_Current_Path_Sig(system_get_current_path){
DWORD size = GetCurrentDirectory_utf8(arena, 0, 0);
u8 *out = push_array(arena, u8, size);
GetCurrentDirectory_utf8(arena, size, out);
return(SCu8(out, size - 1));
}
internal
Sys_Get_4ed_Path_Sig(system_get_4ed_path){
local_persist b32 has_stashed_4ed_path = false;
if (!has_stashed_4ed_path){
has_stashed_4ed_path = true;
local_const i32 binary_path_capacity = KB(32);
u8 *memory = (u8*)system_memory_allocate(binary_path_capacity);
i32 size = GetModuleFileName_utf8(arena, 0, memory, binary_path_capacity);
Assert(size <= binary_path_capacity - 1);
win32vars.binary_path = SCu8(memory, size);
win32vars.binary_path = string_remove_last_folder(win32vars.binary_path);
win32vars.binary_path.str[win32vars.binary_path.size] = 0;
Sys_Get_Path_Sig(system_get_path){
String_Const_u8 result = {};
switch (code){
case SystemPath_CurrentDirectory:
{
DWORD size = GetCurrentDirectory_utf8(arena, 0, 0);
u8 *out = push_array(arena, u8, size);
size = GetCurrentDirectory_utf8(arena, size, out);
result = SCu8(out, size);
}break;
case SystemPath_Binary:
{
local_persist b32 has_stashed_4ed_path = false;
if (!has_stashed_4ed_path){
has_stashed_4ed_path = true;
local_const i32 binary_path_capacity = KB(32);
u8 *memory = (u8*)system_memory_allocate(binary_path_capacity);
i32 size = GetModuleFileName_utf8(arena, 0, memory, binary_path_capacity);
Assert(size <= binary_path_capacity - 1);
win32vars.binary_path = SCu8(memory, size);
win32vars.binary_path = string_remove_last_folder(win32vars.binary_path);
win32vars.binary_path.str[win32vars.binary_path.size] = 0;
}
result = push_string_copy(arena, win32vars.binary_path);
}break;
}
return(push_string_copy(arena, win32vars.binary_path));
return(result);
}
//
@ -339,9 +346,7 @@ Sys_Save_File_Sig(system_save_file){
return(result);
}
//
// Color picker
//
////////////////////////////////
internal int_color
swap_r_and_b(int_color a){

View File

@ -9,6 +9,9 @@
// TOP
#error remove this file
#if 0
union Library{
HMODULE lib;
FixSize(LIBRARY_TYPE_SIZE);
@ -35,6 +38,7 @@ system_free_library(Library *library){
FreeLibrary(library->lib);
library->lib = 0;
}
#endif
// BOTTOM

View File

@ -156,6 +156,15 @@ GetFileAttributesEx_utf8String(Arena *scratch, String_Const_u8 file_name, GET_FI
return(result);
}
function HMODULE
LoadLibrary_utf8String(Arena *scratch, String_Const_u8 name){
Temp_Memory temp = begin_temp(scratch);
String_u16 string_16 = string_u16_from_string_u8(scratch, name, StringFill_NullTerminate);
HMODULE result = LoadLibraryW((LPWSTR)string_16.str);
end_temp(temp);
return(result);
}
#endif
// BOTTOM

View File

@ -42,6 +42,9 @@ SetWindowText_utf8(Arena *scratch, HWND window, u8 *string);
function BOOL
GetFileAttributesEx_utf8String(Arena *scratch, String_Const_u8 file_name, GET_FILEEX_INFO_LEVELS info_level_id, LPVOID file_info);
function HMODULE
LoadLibrary_utf8String(Arena *scratch, String_Const_u8 file_name);
#endif
// BOTTOM

View File

@ -43,10 +43,23 @@ command_list = {
{ .name = "build token tester",
.out = "*compilation*", .footer_panel = true, .save_dirty_files = true,
.cmd = { { "custom\\bin\\build_one_time custom\\languages\\4coder_cpp_lexer_test.cpp ..\\build", .os = "win" }, }, }
.cmd = { { "custom\\bin\\build_one_time custom\\languages\\4coder_cpp_lexer_test.cpp ..\\build", .os = "win" }, }, },
{ .name = "build system api",
.out = "*compilation*", .footer_panel = true, .save_dirty_files = true,
.cmd = { { "custom\\bin\\build_one_time 4ed_system_api.cpp ..\\build", .os = "win" }, }, },
{ .name = "build font api",
.out = "*compilation*", .footer_panel = true, .save_dirty_files = true,
.cmd = { { "custom\\bin\\build_one_time 4ed_font_api.cpp ..\\build", .os = "win" }, }, },
{ .name = "build graphics api",
.out = "*compilation*", .footer_panel = true, .save_dirty_files = true,
.cmd = { { "custom\\bin\\build_one_time 4ed_graphics_api.cpp ..\\build", .os = "win" }, }, },
};
fkey_command[1] = "build x64";
fkey_command[2] = "build graphics api";
fkey_command[4] = "run one time";
fkey_command[5] = "build C++ lexer generator";
fkey_command[6] = "build token tester";