more work zipping together the library handling
parent
8f7cab3217
commit
681f53fae1
38
4ed_system.h
38
4ed_system.h
|
@ -195,6 +195,9 @@ typedef Sys_File_Exists_Sig(System_File_Exists);
|
|||
#define Sys_Directory_CD_Sig(name) bool32 name(char *dir, i32 *len, i32 cap, char *rel_path, i32 rel_len)
|
||||
typedef Sys_Directory_CD_Sig(System_Directory_CD);
|
||||
|
||||
#define Sys_Get_Current_Path_Sig(name) int32_t name(char *out, i32 capacity)
|
||||
typedef Sys_Get_Current_Path_Sig(System_Get_Current_Path);
|
||||
|
||||
#define Sys_Get_4ed_Path_Sig(name) int32_t name(char *out, i32 capacity)
|
||||
typedef Sys_Get_4ed_Path_Sig(System_Get_4ed_Path);
|
||||
|
||||
|
@ -222,16 +225,16 @@ struct System_Functions{
|
|||
Font_Functions font;
|
||||
|
||||
// files (tracked api): 10
|
||||
System_Set_File_List *set_file_list;
|
||||
System_Get_Canonical *get_canonical;
|
||||
System_Add_Listener *add_listener;
|
||||
System_Set_File_List *set_file_list;
|
||||
System_Get_Canonical *get_canonical;
|
||||
System_Add_Listener *add_listener;
|
||||
System_Remove_Listener *remove_listener;
|
||||
System_Get_File_Change *get_file_change;
|
||||
System_Load_Handle *load_handle;
|
||||
System_Load_Size *load_size;
|
||||
System_Load_File *load_file;
|
||||
System_Load_Close *load_close;
|
||||
System_Save_File *save_file;
|
||||
System_Load_Handle *load_handle;
|
||||
System_Load_Size *load_size;
|
||||
System_Load_File *load_file;
|
||||
System_Load_Close *load_close;
|
||||
System_Save_File *save_file;
|
||||
|
||||
// time: 1
|
||||
System_Now_Time *now_time;
|
||||
|
@ -243,21 +246,21 @@ struct System_Functions{
|
|||
System_Create_Coroutine *create_coroutine;
|
||||
System_Launch_Coroutine *launch_coroutine;
|
||||
System_Resume_Coroutine *resume_coroutine;
|
||||
System_Yield_Coroutine *yield_coroutine;
|
||||
System_Yield_Coroutine *yield_coroutine;
|
||||
|
||||
// cli: 4
|
||||
System_CLI_Call *cli_call;
|
||||
System_CLI_Call *cli_call;
|
||||
System_CLI_Begin_Update *cli_begin_update;
|
||||
System_CLI_Update_Step *cli_update_step;
|
||||
System_CLI_End_Update *cli_end_update;
|
||||
System_CLI_Update_Step *cli_update_step;
|
||||
System_CLI_End_Update *cli_end_update;
|
||||
|
||||
// threads: 6
|
||||
System_Post_Job *post_job;
|
||||
System_Cancel_Job *cancel_job;
|
||||
System_Check_Cancel *check_cancel;
|
||||
System_Post_Job *post_job;
|
||||
System_Cancel_Job *cancel_job;
|
||||
System_Check_Cancel *check_cancel;
|
||||
System_Grow_Thread_Memory *grow_thread_memory;
|
||||
System_Acquire_Lock *acquire_lock;
|
||||
System_Release_Lock *release_lock;
|
||||
System_Acquire_Lock *acquire_lock;
|
||||
System_Release_Lock *release_lock;
|
||||
|
||||
// custom: 10
|
||||
System_Memory_Allocate *memory_allocate;
|
||||
|
@ -265,6 +268,7 @@ struct System_Functions{
|
|||
System_Memory_Free *memory_free;
|
||||
System_File_Exists *file_exists;
|
||||
System_Directory_CD *directory_cd;
|
||||
System_Get_Current_Path *get_current_path;
|
||||
System_Get_4ed_Path *get_4ed_path;
|
||||
System_Show_Mouse_Cursor *show_mouse_cursor;
|
||||
System_Set_Fullscreen *set_fullscreen;
|
||||
|
|
|
@ -32,7 +32,7 @@ static i32 prev_error = 0;
|
|||
#endif
|
||||
|
||||
#define systemf(...) do{ \
|
||||
int32_t n = snprintf(SF_CMD, sizeof(SF_CMD), __VA_ARGS__); \
|
||||
i32 n = snprintf(SF_CMD, sizeof(SF_CMD), __VA_ARGS__); \
|
||||
AllowLocal(n); \
|
||||
Assert(n < sizeof(SF_CMD)); \
|
||||
SYSTEMF_PRINTF("%s\n", SF_CMD); \
|
||||
|
@ -49,8 +49,8 @@ internal void fm_init_system();
|
|||
internal u64 fm_get_time();
|
||||
|
||||
#define LLU_CAST(n) (long long unsigned int)(n)
|
||||
#define BEGIN_TIME_SECTION() uint64_t start = fm_get_time()
|
||||
#define END_TIME_SECTION(n) uint64_t total = fm_get_time() - start; printf("%-20s: %.2llu.%.6llu\n", (n), LLU_CAST(total/1000000), LLU_CAST(total%1000000));
|
||||
#define BEGIN_TIME_SECTION() u64 start = fm_get_time()
|
||||
#define END_TIME_SECTION(n) u64 total = fm_get_time() - start; printf("%-20s: %.2llu.%.6llu\n", (n), LLU_CAST(total/1000000), LLU_CAST(total%1000000));
|
||||
|
||||
// Files and Folders Manipulation
|
||||
internal void fm_make_folder_if_missing(char *dir);
|
||||
|
@ -228,12 +228,12 @@ fm_align(){
|
|||
|
||||
#if defined(IS_WINDOWS)
|
||||
|
||||
typedef uint32_t DWORD;
|
||||
typedef int32_t LONG;
|
||||
typedef int64_t LONGLONG;
|
||||
typedef u32 DWORD;
|
||||
typedef i32 LONG;
|
||||
typedef i64 LONGLONG;
|
||||
typedef char* LPTSTR;
|
||||
typedef char* LPCTSTR;
|
||||
typedef int32_t BOOL;
|
||||
typedef i32 BOOL;
|
||||
typedef void* LPSECURITY_ATTRIBUTES;
|
||||
typedef union _LARGE_INTEGER {
|
||||
struct {
|
||||
|
@ -302,7 +302,7 @@ extern "C"{
|
|||
#define FILE_ATTRIBUTE_NORMAL 0x00000080
|
||||
#define FILE_ATTRIBUTE_TEMPORARY 0x00000100
|
||||
|
||||
static uint64_t perf_frequency;
|
||||
static u64 perf_frequency;
|
||||
|
||||
static void
|
||||
fm_init_system(){
|
||||
|
@ -326,9 +326,9 @@ fm_popdir(Temp_Dir temp){
|
|||
SetCurrentDirectoryA(temp.dir);
|
||||
}
|
||||
|
||||
static uint64_t
|
||||
static u64
|
||||
fm_get_time(){
|
||||
uint64_t time = 0;
|
||||
u64 time = 0;
|
||||
LARGE_INTEGER lint;
|
||||
if (QueryPerformanceCounter(&lint)){
|
||||
time = lint.QuadPart;
|
||||
|
@ -337,9 +337,9 @@ fm_get_time(){
|
|||
return(time);
|
||||
}
|
||||
|
||||
static int32_t
|
||||
fm_get_current_directory(char *buffer, int32_t max){
|
||||
int32_t result = GetCurrentDirectoryA(max, buffer);
|
||||
static i32
|
||||
fm_get_current_directory(char *buffer, i32 max){
|
||||
i32 result = GetCurrentDirectoryA(max, buffer);
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
@ -368,7 +368,7 @@ fm_execute_in_dir(char *dir, char *str, char *args){
|
|||
static void
|
||||
fm_slash_fix(char *path){
|
||||
if (path != 0){
|
||||
for (int32_t i = 0; path[i]; ++i){
|
||||
for (i32 i = 0; path[i]; ++i){
|
||||
if (path[i] == '/') path[i] = '\\';
|
||||
}
|
||||
}
|
||||
|
@ -458,7 +458,7 @@ static Temp_Dir
|
|||
fm_pushdir(char *dir){
|
||||
Temp_Dir temp;
|
||||
char *result = getcwd(temp.dir, sizeof(temp.dir));
|
||||
int32_t chresult = chdir(dir);
|
||||
i32 chresult = chdir(dir);
|
||||
if (result == 0 || chresult != 0){
|
||||
printf("trying pushdir %s\n", dir);
|
||||
Assert(result != 0);
|
||||
|
@ -477,18 +477,18 @@ fm_init_system(){
|
|||
fm__init_memory();
|
||||
}
|
||||
|
||||
static uint64_t
|
||||
static u64
|
||||
fm_get_time(){
|
||||
struct timespec spec;
|
||||
uint64_t result;
|
||||
u64 result;
|
||||
clock_gettime(CLOCK_MONOTONIC, &spec);
|
||||
result = (spec.tv_sec * (uint64_t)(1000000)) + (spec.tv_nsec / (uint64_t)(1000));
|
||||
result = (spec.tv_sec * (u64)(1000000)) + (spec.tv_nsec / (u64)(1000));
|
||||
return(result);
|
||||
}
|
||||
|
||||
static int32_t
|
||||
fm_get_current_directory(char *buffer, int32_t max){
|
||||
int32_t result = 0;
|
||||
static i32
|
||||
fm_get_current_directory(char *buffer, i32 max){
|
||||
i32 result = 0;
|
||||
char *d = getcwd(buffer, max);
|
||||
if (d == buffer){
|
||||
result = strlen(buffer);
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#define SYSLINK(name) sysfunc.name = system_##name
|
||||
|
||||
internal void
|
||||
link_system_code(System_Functions *system){
|
||||
link_system_code(){
|
||||
SYSLINK(set_file_list);
|
||||
SYSLINK(get_canonical);
|
||||
SYSLINK(add_listener);
|
||||
|
@ -52,6 +52,7 @@ link_system_code(System_Functions *system){
|
|||
SYSLINK(memory_free);
|
||||
SYSLINK(file_exists);
|
||||
SYSLINK(directory_cd);
|
||||
SYSLINK(get_current_path);
|
||||
SYSLINK(get_4ed_path);
|
||||
SYSLINK(set_fullscreen);
|
||||
SYSLINK(is_fullscreen);
|
||||
|
|
|
@ -47,7 +47,7 @@ internal void
|
|||
load_app_code(){
|
||||
App_Get_Functions *get_funcs = 0;
|
||||
|
||||
if (system_load_library(&libraries.app_code, "4ed_app")){
|
||||
if (system_load_library(&libraries.app_code, "4ed_app", LoadLibrary_BinaryDirectory)){
|
||||
get_funcs = (App_Get_Functions*)system_get_proc(&libraries.app_code, "app_get_functions");
|
||||
}
|
||||
else{
|
||||
|
@ -64,5 +64,61 @@ load_app_code(){
|
|||
}
|
||||
}
|
||||
|
||||
global char custom_fail_version_msg[] = "Failed to load custom code due to missing version information or a version mismatch. Try rebuilding with buildsuper.";
|
||||
|
||||
global char custom_fail_missing_get_bindings_msg[] = "Failed to load custom code due to missing 'get_bindings' symbol. Try rebuilding with buildsuper.";
|
||||
|
||||
internal void
|
||||
load_custom_code(){
|
||||
local_persist char *default_file = "custom_4coder";
|
||||
local_persist Load_Library_Location locations[] = {
|
||||
LoadLibrary_CurrentDirectory,
|
||||
LoadLibrary_BinaryDirectory,
|
||||
};
|
||||
|
||||
char *custom_files[3] = {0};
|
||||
if (plat_settings.custom_dll != 0){
|
||||
custom_files[0] = plat_settings.custom_dll;
|
||||
if (!plat_settings.custom_dll_is_strict){
|
||||
custom_files[1] = default_file;
|
||||
}
|
||||
}
|
||||
else{
|
||||
custom_files[0] = default_file;
|
||||
}
|
||||
|
||||
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(&libraries.custom, file, locations[j], success_file, sizeof(success_file))){
|
||||
has_library = true;
|
||||
success_file[sizeof(success_file) - 1] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!has_library){
|
||||
system_error_box("Did not find a library for the custom layer.");
|
||||
}
|
||||
|
||||
custom_api.get_alpha_4coder_version = (_Get_Version_Function*)
|
||||
system_get_proc(&libraries.custom, "get_alpha_4coder_version");
|
||||
|
||||
if (custom_api.get_alpha_4coder_version == 0 || custom_api.get_alpha_4coder_version(MAJOR, MINOR, PATCH) == 0){
|
||||
system_error_box(custom_fail_version_msg);
|
||||
}
|
||||
|
||||
custom_api.get_bindings = (Get_Binding_Data_Function*)
|
||||
system_get_proc(&libraries.custom, "get_bindings");
|
||||
|
||||
if (custom_api.get_bindings == 0){
|
||||
system_error_box(custom_fail_missing_get_bindings_msg);
|
||||
}
|
||||
|
||||
LOGF("Loaded custom file: %s\n", success_file);
|
||||
}
|
||||
|
||||
// BOTTOM
|
||||
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Mr. 4th Dimention - Allen Webster
|
||||
*
|
||||
* 19.07.2017
|
||||
*
|
||||
* Cross platform library constants
|
||||
*
|
||||
*/
|
||||
|
||||
// TOP
|
||||
|
||||
#if !defined(FRED_SHARED_LIBRARY_CONSTANTS_H)
|
||||
#define FRED_SHARED_LIBRARY_CONSTANTS_H
|
||||
|
||||
// Wrapper functions
|
||||
union Library;
|
||||
|
||||
internal b32
|
||||
system_load_library_direct(Library *library, char *name);
|
||||
|
||||
internal void*
|
||||
system_get_proc(Library *library, char *name);
|
||||
|
||||
internal void
|
||||
system_free_library(Library *library);
|
||||
|
||||
// Shared logic
|
||||
#define LIBRARY_TYPE_SIZE 32
|
||||
|
||||
#define AssertLibrarySizes() Assert(sizeof(Library) == LIBRARY_TYPE_SIZE)
|
||||
|
||||
typedef u32 Load_Library_Location;
|
||||
enum{
|
||||
LoadLibrary_CurrentDirectory,
|
||||
LoadLibrary_BinaryDirectory,
|
||||
};
|
||||
|
||||
internal b32
|
||||
system_load_library(Library *library, char *name, Load_Library_Location location, char *full_file_out, u32 full_file_max){
|
||||
char space[4096];
|
||||
String extension = file_extension(make_string_slowly(name));
|
||||
if (!match(extension, DLL)){
|
||||
String full_name = make_fixed_width_string(space);
|
||||
append(&full_name, name);
|
||||
append(&full_name, "."DLL);
|
||||
if (terminate_with_null(&full_name)){
|
||||
name = space;
|
||||
}
|
||||
else{
|
||||
name = 0;
|
||||
}
|
||||
}
|
||||
|
||||
char path_space[4096];
|
||||
String path = make_fixed_width_string(path_space);
|
||||
switch (location){
|
||||
case LoadLibrary_CurrentDirectory:
|
||||
{
|
||||
path.size = sysfunc.get_current_path(path.str, path.memory_size);
|
||||
}break;
|
||||
|
||||
case LoadLibrary_BinaryDirectory:
|
||||
{
|
||||
path.size = sysfunc.get_4ed_path(path.str, path.memory_size);
|
||||
}break;
|
||||
|
||||
default: LOG("Invalid library location passed.\n"); break;
|
||||
}
|
||||
|
||||
b32 success = false;
|
||||
if (path.size > 0){
|
||||
append(&path, SLASH);
|
||||
append(&path, name);
|
||||
terminate_with_null(&path);
|
||||
success = system_load_library_direct(library, path.str);
|
||||
if (success && full_file_out != 0){
|
||||
String out = make_string_cap(full_file_out, 0, full_file_max);
|
||||
copy(&out, path);
|
||||
terminate_with_null(&out);
|
||||
}
|
||||
}
|
||||
|
||||
return(success);
|
||||
}
|
||||
|
||||
internal b32
|
||||
system_load_library(Library *library, char *name, Load_Library_Location location){
|
||||
system_load_library(library, name, location, 0, 0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// BOTTOM
|
||||
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
struct Libraries{
|
||||
Library app_code;
|
||||
Library custom;
|
||||
};
|
||||
|
||||
// BOTTOM
|
||||
|
|
|
@ -223,31 +223,9 @@ sysshared_to_binary_path(String *out_filename, char *filename){
|
|||
}
|
||||
|
||||
//
|
||||
// Rendering
|
||||
// Rendering Interface
|
||||
//
|
||||
|
||||
inline void
|
||||
draw_set_clip(Render_Target *target, i32_Rect clip_box){
|
||||
glScissor(clip_box.x0, target->height - clip_box.y1, clip_box.x1 - clip_box.x0, clip_box.y1 - clip_box.y0);
|
||||
}
|
||||
|
||||
inline void
|
||||
draw_bind_texture(Render_Target *target, i32 texid){
|
||||
if (target->bound_texture != texid){
|
||||
glBindTexture(GL_TEXTURE_2D, texid);
|
||||
target->bound_texture = texid;
|
||||
}
|
||||
}
|
||||
|
||||
inline void
|
||||
draw_set_color(Render_Target *target, u32 color){
|
||||
if (target->color != color){
|
||||
target->color = color;
|
||||
Vec4 c = unpack_color4(color);
|
||||
glColor4f(c.r, c.g, c.b, c.a);
|
||||
}
|
||||
}
|
||||
|
||||
inline void
|
||||
draw_safe_push(Render_Target *target, i32 size, void *x){
|
||||
if (size + target->size <= target->max){
|
||||
|
@ -327,8 +305,41 @@ draw_pop_clip(Render_Target *target){
|
|||
return(result);
|
||||
}
|
||||
|
||||
internal void
|
||||
link_rendering(){
|
||||
target.push_clip = draw_push_clip;
|
||||
target.pop_clip = draw_pop_clip;
|
||||
target.push_piece = draw_push_piece;
|
||||
}
|
||||
|
||||
//
|
||||
// OpenGL
|
||||
//
|
||||
|
||||
#define ExtractStruct(s) ((s*)cursor); cursor += sizeof(s)
|
||||
|
||||
inline void
|
||||
draw_set_clip(Render_Target *target, i32_Rect clip_box){
|
||||
glScissor(clip_box.x0, target->height - clip_box.y1, clip_box.x1 - clip_box.x0, clip_box.y1 - clip_box.y0);
|
||||
}
|
||||
|
||||
inline void
|
||||
draw_bind_texture(Render_Target *target, i32 texid){
|
||||
if (target->bound_texture != texid){
|
||||
glBindTexture(GL_TEXTURE_2D, texid);
|
||||
target->bound_texture = texid;
|
||||
}
|
||||
}
|
||||
|
||||
inline void
|
||||
draw_set_color(Render_Target *target, u32 color){
|
||||
if (target->color != color){
|
||||
target->color = color;
|
||||
Vec4 c = unpack_color4(color);
|
||||
glColor4f(c.r, c.g, c.b, c.a);
|
||||
}
|
||||
}
|
||||
|
||||
inline void
|
||||
private_draw_rectangle(Render_Target *target, f32_Rect rect, u32 color){
|
||||
draw_set_color(target, color);
|
||||
|
|
|
@ -121,8 +121,12 @@ internal void LinuxStringDup(String*, void*, size_t);
|
|||
|
||||
////////////////////////////////
|
||||
|
||||
#define SLASH '/'
|
||||
#define DLL "so"
|
||||
|
||||
global System_Functions sysfunc;
|
||||
#include "linux_4ed_libraries.cpp"
|
||||
#include "4ed_shared_library_constants.h"
|
||||
#include "linux_library_wrapper.h"
|
||||
#include "4ed_standard_libraries.cpp"
|
||||
|
||||
////////////////////////////////
|
||||
|
@ -174,13 +178,10 @@ struct Linux_Vars{
|
|||
b32 hide_cursor;
|
||||
Cursor hidden_cursor;
|
||||
|
||||
void *custom;
|
||||
|
||||
sem_t thread_semaphore;
|
||||
|
||||
i32 dpi_x, dpi_y;
|
||||
|
||||
Custom_API custom_api;
|
||||
b32 vsync;
|
||||
|
||||
Linux_Coroutine coroutine_data[18];
|
||||
|
@ -196,6 +197,7 @@ global Plat_Settings plat_settings;
|
|||
|
||||
global Libraries libraries;
|
||||
global App_Functions app;
|
||||
global Custom_API custom_api;
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
|
@ -210,9 +212,6 @@ linux_set_icon(Display* d, Window w){
|
|||
|
||||
////////////////////////////////
|
||||
|
||||
#define SLASH '/'
|
||||
#define DLL "so"
|
||||
|
||||
internal sem_t*
|
||||
handle_sem(Plat_Handle h){
|
||||
return(*(sem_t**)&h);
|
||||
|
@ -537,17 +536,6 @@ Sys_CLI_End_Update_Sig(system_cli_end_update){
|
|||
// End of system funcs
|
||||
//
|
||||
|
||||
//
|
||||
// Linux init functions
|
||||
//
|
||||
|
||||
internal void
|
||||
LinuxLoadRenderCode(){
|
||||
target.push_clip = draw_push_clip;
|
||||
target.pop_clip = draw_pop_clip;
|
||||
target.push_piece = draw_push_piece;
|
||||
}
|
||||
|
||||
//
|
||||
// Renderer
|
||||
//
|
||||
|
@ -1636,18 +1624,36 @@ LinuxHandleX11Events(void)
|
|||
|
||||
int
|
||||
main(int argc, char **argv){
|
||||
//
|
||||
// System & Memory init
|
||||
//
|
||||
memset(&linuxvars, 0, sizeof(linuxvars));
|
||||
memset(&target, 0, sizeof(target));
|
||||
memset(&memory_vars, 0, sizeof(memory_vars));
|
||||
memset(&plat_settings, 0, sizeof(plat_settings));
|
||||
|
||||
load_app_code();
|
||||
link_system_code(&sysfunc);
|
||||
LinuxLoadRenderCode();
|
||||
|
||||
system_memory_init();
|
||||
memset(&libraries, 0, sizeof(libraries));
|
||||
memset(&app, 0, sizeof(app));
|
||||
memset(&custom_api, 0, sizeof(custom_api));
|
||||
|
||||
init_shared_vars();
|
||||
|
||||
//
|
||||
// Linkage
|
||||
//
|
||||
|
||||
link_system_code();
|
||||
load_app_code();
|
||||
link_rendering();
|
||||
#if defined(FRED_SUPER)
|
||||
load_custom_code();
|
||||
#else
|
||||
custom_api.get_bindings = get_bindings;
|
||||
#endif
|
||||
|
||||
//
|
||||
// Memory init
|
||||
//
|
||||
|
||||
system_memory_init();
|
||||
|
||||
//
|
||||
// Read command line
|
||||
//
|
||||
|
@ -1680,68 +1686,6 @@ main(int argc, char **argv){
|
|||
|
||||
sysshared_filter_real_files(files, file_count);
|
||||
|
||||
//
|
||||
// Custom layer linkage
|
||||
//
|
||||
|
||||
#ifdef FRED_SUPER
|
||||
|
||||
char base_dir_mem[PATH_MAX];
|
||||
String base_dir = make_fixed_width_string(base_dir_mem);
|
||||
|
||||
char *custom_file_default = "custom_4coder.so";
|
||||
sysshared_to_binary_path(&base_dir, custom_file_default);
|
||||
custom_file_default = base_dir.str;
|
||||
|
||||
char *custom_file;
|
||||
if (plat_settings.custom_dll){
|
||||
custom_file = plat_settings.custom_dll;
|
||||
}
|
||||
else{
|
||||
custom_file = custom_file_default;
|
||||
}
|
||||
|
||||
linuxvars.custom = dlopen(custom_file, RTLD_LAZY);
|
||||
if (!linuxvars.custom && custom_file != custom_file_default){
|
||||
if (!plat_settings.custom_dll_is_strict){
|
||||
linuxvars.custom = dlopen(custom_file_default, RTLD_LAZY);
|
||||
}
|
||||
}
|
||||
|
||||
if (linuxvars.custom){
|
||||
linuxvars.custom_api.get_alpha_4coder_version = (_Get_Version_Function*)
|
||||
dlsym(linuxvars.custom, "get_alpha_4coder_version");
|
||||
|
||||
if (linuxvars.custom_api.get_alpha_4coder_version == 0 ||
|
||||
linuxvars.custom_api.get_alpha_4coder_version(MAJOR, MINOR, PATCH) == 0){
|
||||
system_error_box("Failed to load 'custom_4coder.so': Version mismatch. Try rebuilding it with 'buildsuper.sh'.");
|
||||
}
|
||||
else{
|
||||
linuxvars.custom_api.get_bindings = (Get_Binding_Data_Function*)
|
||||
dlsym(linuxvars.custom, "get_bindings");
|
||||
|
||||
if (linuxvars.custom_api.get_bindings == 0){
|
||||
system_error_box("Failed to load 'custom_4coder.so': "
|
||||
"It does not export the required 'get_bindings' function. "
|
||||
"Try rebuilding it with 'buildsuper.sh'.");
|
||||
}
|
||||
else{
|
||||
LOG("Successfully loaded custom_4coder.so\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
char buf[4096];
|
||||
const char* error = dlerror();
|
||||
snprintf(buf, sizeof(buf), "Error loading custom: %s. "
|
||||
"Make sure this file is in the same directory as the main '4ed' executable.",
|
||||
error ? error : "'custom_4coder.so' missing");
|
||||
system_error_box(buf);
|
||||
}
|
||||
#else
|
||||
linuxvars.custom_api.get_bindings = get_bindings;
|
||||
#endif
|
||||
|
||||
//
|
||||
// Coroutines
|
||||
//
|
||||
|
@ -1760,8 +1704,8 @@ main(int argc, char **argv){
|
|||
//
|
||||
// Threads
|
||||
//
|
||||
system_init_threaded_work_system();
|
||||
|
||||
system_init_threaded_work_system();
|
||||
|
||||
//
|
||||
// X11 init
|
||||
|
@ -1892,7 +1836,7 @@ main(int argc, char **argv){
|
|||
|
||||
XAddConnectionWatch(linuxvars.XDisplay, &LinuxX11ConnectionWatch, NULL);
|
||||
|
||||
app.init(&sysfunc, &target, &memory_vars, linuxvars.clipboard_contents, current_directory, linuxvars.custom_api);
|
||||
app.init(&sysfunc, &target, &memory_vars, linuxvars.clipboard_contents, current_directory, custom_api);
|
||||
|
||||
LinuxResizeTarget(window_width, window_height);
|
||||
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
/*
|
||||
* Mr. 4th Dimention - Allen Webster
|
||||
*
|
||||
* 18.07.2017
|
||||
*
|
||||
* Linux library wrapper.
|
||||
*
|
||||
*/
|
||||
|
||||
// TOP
|
||||
|
||||
struct Library{
|
||||
void *lib;
|
||||
};
|
||||
|
||||
internal b32
|
||||
system_load_library(Library *library, char *name){
|
||||
String extension = file_extension(make_string_slowly(name));
|
||||
char space[4096];
|
||||
if (!match(extension, "so")){
|
||||
String full_name = make_fixed_width_string(space);
|
||||
append(&full_name, name);
|
||||
append(&full_name, ".so");
|
||||
terminate_with_null(&full_name);
|
||||
name = space;
|
||||
}
|
||||
|
||||
char path_space[4096];
|
||||
i32 size = sysfunc.get_4ed_path(path_space, sizeof(path_space));
|
||||
String full_path = make_string(path_space, size, sizeof(path_space));
|
||||
append(&full_path, "/");
|
||||
append(&full_path, name);
|
||||
terminate_with_null(&full_path);
|
||||
|
||||
library->lib = dlopen(full_path.str, RTLD_LAZY);
|
||||
b32 success = (library->lib != 0);
|
||||
return(success);
|
||||
}
|
||||
|
||||
internal void*
|
||||
system_get_proc(Library *library, char *name){
|
||||
void *result = dlsym(library->lib, name);
|
||||
return(result);
|
||||
}
|
||||
|
||||
internal void
|
||||
system_free_library(Library *library){
|
||||
dlclose(library->lib);
|
||||
library->lib = 0;
|
||||
}
|
||||
|
||||
// BOTTOM
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Mr. 4th Dimention - Allen Webster
|
||||
*
|
||||
* 18.07.2017
|
||||
*
|
||||
* Linux library wrapper.
|
||||
*
|
||||
*/
|
||||
|
||||
// TOP
|
||||
|
||||
union Library{
|
||||
void *lib;
|
||||
FixSize(LIBRARY_TYPE_SIZE);
|
||||
};
|
||||
|
||||
internal b32
|
||||
system_load_library_direct(Library *library, char *name){
|
||||
AssertLibrarySizes();
|
||||
library->lib = dlopen(name, RTLD_LAZY);
|
||||
b32 success = (library->lib != 0);
|
||||
return(success);
|
||||
}
|
||||
|
||||
internal void*
|
||||
system_get_proc(Library *library, char *name){
|
||||
void *result = dlsym(library->lib, name);
|
||||
return(result);
|
||||
}
|
||||
|
||||
internal void
|
||||
system_free_library(Library *library){
|
||||
dlclose(library->lib);
|
||||
library->lib = 0;
|
||||
}
|
||||
|
||||
// BOTTOM
|
||||
|
|
@ -18,6 +18,16 @@ global Unix_Vars unixvars;
|
|||
// 4ed Path
|
||||
//
|
||||
|
||||
internal
|
||||
Sys_Get_Current_Path_Sig(system_get_current_path){
|
||||
i32 result = 0;
|
||||
char *d = getcwd(out, capacity);
|
||||
if (d == out){
|
||||
result = strlen(out);
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
internal
|
||||
Sys_Get_4ed_Path_Sig(system_get_4ed_path){
|
||||
ssize_t size = readlink("/proc/self/exe", out, capacity - 1);
|
||||
|
|
|
@ -113,15 +113,18 @@ struct Win32_Coroutine{
|
|||
|
||||
////////////////////////////////
|
||||
|
||||
#define SLASH '\\'
|
||||
#define DLL "dll"
|
||||
|
||||
global System_Functions sysfunc;
|
||||
#include "win32_4ed_libraries.cpp"
|
||||
#include "4ed_shared_library_constants.h"
|
||||
#include "win32_library_wrapper.h"
|
||||
#include "4ed_standard_libraries.cpp"
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
struct Win32_Vars{
|
||||
Custom_API custom_api;
|
||||
HMODULE custom;
|
||||
|
||||
Win32_Coroutine coroutine_data[18];
|
||||
Win32_Coroutine *coroutine_free;
|
||||
|
@ -172,9 +175,6 @@ global App_Functions app;
|
|||
|
||||
////////////////////////////////
|
||||
|
||||
#define SLASH '\\'
|
||||
#define DLL "dll"
|
||||
|
||||
internal HANDLE
|
||||
handle_type(Plat_Handle h){
|
||||
HANDLE result;
|
||||
|
@ -577,13 +577,6 @@ Sys_CLI_End_Update_Sig(system_cli_end_update){
|
|||
#include "4ed_font_data.h"
|
||||
#include "4ed_system_shared.cpp"
|
||||
|
||||
internal void
|
||||
Win32LoadRenderCode(){
|
||||
target.push_clip = draw_push_clip;
|
||||
target.pop_clip = draw_pop_clip;
|
||||
target.push_piece = draw_push_piece;
|
||||
}
|
||||
|
||||
//
|
||||
// Helpers
|
||||
//
|
||||
|
@ -1069,9 +1062,39 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
|
|||
i32 argc = __argc;
|
||||
char **argv = __argv;
|
||||
|
||||
memset(&win32vars, 0, sizeof(win32vars));
|
||||
memset(&linuxvars, 0, sizeof(linuxvars));
|
||||
memset(&target, 0, sizeof(target));
|
||||
memset(&memory_vars, 0, sizeof(memory_vars));
|
||||
memset(&plat_settings, 0, sizeof(plat_settings));
|
||||
|
||||
win32vars.bordered_win_pos.length = sizeof(win32vars.bordered_win_pos);
|
||||
memset(&libraries, 0, sizeof(libraries));
|
||||
memset(&app, 0, sizeof(app));
|
||||
memset(&custom_api, 0, sizeof(custom_api));
|
||||
|
||||
init_shared_vars();
|
||||
|
||||
//
|
||||
// Linkage
|
||||
//
|
||||
|
||||
link_system_code();
|
||||
load_app_code();
|
||||
link_rendering();
|
||||
#if defined(FRED_SUPER)
|
||||
load_custom_code();
|
||||
#else
|
||||
custom_api.get_bindings = get_bindings;
|
||||
#endif
|
||||
|
||||
//
|
||||
// Memory Initialization
|
||||
//
|
||||
|
||||
system_memory_init();
|
||||
|
||||
//
|
||||
// Threads
|
||||
//
|
||||
|
||||
system_init_threaded_work_system();
|
||||
|
||||
|
@ -1085,26 +1108,6 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
|
|||
win32vars.coroutine_data[i].next = &win32vars.coroutine_data[i + 1];
|
||||
}
|
||||
|
||||
//
|
||||
// Memory Initialization
|
||||
//
|
||||
|
||||
system_memory_init();
|
||||
|
||||
//
|
||||
// System and Application Layer Linkage
|
||||
//
|
||||
|
||||
load_app_code();
|
||||
link_system_code(&sysfunc);
|
||||
Win32LoadRenderCode();
|
||||
|
||||
//
|
||||
// Shared Systems Init
|
||||
//
|
||||
|
||||
init_shared_vars();
|
||||
|
||||
//
|
||||
// Read Command Line
|
||||
//
|
||||
|
@ -1130,47 +1133,6 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
|
|||
sysshared_filter_real_files(files, file_count);
|
||||
LOG("Loaded system code, read command line.\n");
|
||||
|
||||
//
|
||||
// Custom Layer Linkage
|
||||
//
|
||||
|
||||
#if defined(FRED_SUPER)
|
||||
char *custom_file_default = "custom_4coder.dll";
|
||||
char *custom_file = 0;
|
||||
if (plat_settings.custom_dll){
|
||||
custom_file = plat_settings.custom_dll;
|
||||
}
|
||||
else{
|
||||
custom_file = custom_file_default;
|
||||
}
|
||||
|
||||
LOGF("Trying to load custom DLL: %s\n", custom_file);
|
||||
win32vars.custom = LoadLibraryA(custom_file);
|
||||
if (!win32vars.custom && custom_file != custom_file_default){
|
||||
if (!plat_settings.custom_dll_is_strict){
|
||||
LOGF("Trying to load custom DLL: %s\n", custom_file_default);
|
||||
win32vars.custom = LoadLibraryA(custom_file_default);
|
||||
}
|
||||
}
|
||||
|
||||
if (win32vars.custom){
|
||||
win32vars.custom_api.get_alpha_4coder_version = (_Get_Version_Function*)GetProcAddress(win32vars.custom, "get_alpha_4coder_version");
|
||||
|
||||
if (win32vars.custom_api.get_alpha_4coder_version == 0 || win32vars.custom_api.get_alpha_4coder_version(MAJOR, MINOR, PATCH) == 0){
|
||||
system_error_box("The application and custom version numbers don't match.");
|
||||
}
|
||||
|
||||
win32vars.custom_api.get_bindings = (Get_Binding_Data_Function*)GetProcAddress(win32vars.custom, "get_bindings");
|
||||
}
|
||||
|
||||
if (win32vars.custom_api.get_bindings == 0){
|
||||
system_error_box("The custom dll is missing.");
|
||||
}
|
||||
|
||||
#else
|
||||
win32vars.custom_api.get_bindings = (Get_Binding_Data_Function*)get_bindings;
|
||||
#endif
|
||||
|
||||
//
|
||||
// Window and GL Initialization
|
||||
//
|
||||
|
|
|
@ -9,22 +9,14 @@
|
|||
|
||||
// TOP
|
||||
|
||||
struct Library{
|
||||
union Library{
|
||||
HMODULE lib;
|
||||
FixSize(LIBRARY_TYPE_SIZE);
|
||||
};
|
||||
|
||||
internal b32
|
||||
system_load_library(Library *library, char *name){
|
||||
String extension = file_extension(make_string_slowly(name));
|
||||
char space[4096];
|
||||
if (!match(extension, "dll")){
|
||||
String full_name = make_fixed_width_string(space);
|
||||
append(&full_name, name);
|
||||
append(&full_name, ".dll");
|
||||
terminate_with_null(&full_name);
|
||||
name = space;
|
||||
}
|
||||
|
||||
system_load_library_direct(Library *library, char *name){
|
||||
AssertLibrarySizes();
|
||||
library->lib = LoadLibraryA(name);
|
||||
b32 success = (library->lib != 0);
|
||||
return(success);
|
Loading…
Reference in New Issue