moved file exchange struct into application side
parent
885e5b424f
commit
4f55fca356
73
4ed.cpp
73
4ed.cpp
|
@ -913,16 +913,14 @@ view_file_in_panel(Command_Data *cmd, Panel *panel, Editing_File *file){
|
||||||
// - Keep current version open and do some sort of diff to keep
|
// - Keep current version open and do some sort of diff to keep
|
||||||
// the cursor position correct
|
// the cursor position correct
|
||||||
COMMAND_DECL(reopen){
|
COMMAND_DECL(reopen){
|
||||||
|
|
||||||
USE_VARS(vars);
|
USE_VARS(vars);
|
||||||
USE_MODELS(models);
|
USE_MODELS(models);
|
||||||
USE_VIEW(view);
|
USE_VIEW(view);
|
||||||
REQ_FILE(file, view);
|
REQ_FILE(file, view);
|
||||||
USE_EXCHANGE(exchange);
|
|
||||||
|
|
||||||
if (match(file->name.source_path, file->name.live_name)) return;
|
if (match(file->name.source_path, file->name.live_name)) return;
|
||||||
|
|
||||||
i32 file_id = exchange_request_file(exchange, expand_str(file->name.source_path));
|
i32 file_id = exchange_request_file(&models->files, expand_str(file->name.source_path));
|
||||||
i32 index = 0;
|
i32 index = 0;
|
||||||
if (file_id){
|
if (file_id){
|
||||||
file_set_to_loading(file);
|
file_set_to_loading(file);
|
||||||
|
@ -3217,34 +3215,34 @@ App_Init_Sig(app_init){
|
||||||
target->partition = partition;
|
target->partition = partition;
|
||||||
|
|
||||||
{
|
{
|
||||||
//exchange
|
File_Exchange *files = &models->files;
|
||||||
File_Slot *slots = vars->slots;
|
File_Slot *slots = vars->slots;
|
||||||
i32 max = ArrayCount(vars->slots);
|
i32 max = ArrayCount(vars->slots);
|
||||||
{
|
{
|
||||||
char *filename_space;
|
char *filename_space;
|
||||||
i32 i;
|
i32 i;
|
||||||
|
|
||||||
exchange->file.max = max;
|
files->max = max;
|
||||||
exchange->file.available = file_slot_zero();
|
files->available = file_slot_zero();
|
||||||
exchange->file.available.next = &exchange->file.available;
|
files->available.next = &files->available;
|
||||||
exchange->file.available.prev = &exchange->file.available;
|
files->available.prev = &files->available;
|
||||||
|
|
||||||
exchange->file.active = file_slot_zero();
|
files->active = file_slot_zero();
|
||||||
exchange->file.active.next = &exchange->file.active;
|
files->active.next = &files->active;
|
||||||
exchange->file.active.prev = &exchange->file.active;
|
files->active.prev = &files->active;
|
||||||
|
|
||||||
exchange->file.free_list = file_slot_zero();
|
files->free_list = file_slot_zero();
|
||||||
exchange->file.free_list.next = &exchange->file.free_list;
|
files->free_list.next = &files->free_list;
|
||||||
exchange->file.free_list.prev = &exchange->file.free_list;
|
files->free_list.prev = &files->free_list;
|
||||||
|
|
||||||
exchange->file.files = slots;
|
files->files = slots;
|
||||||
memset(slots, 0, sizeof(File_Slot)*max);
|
memset(slots, 0, sizeof(File_Slot)*max);
|
||||||
|
|
||||||
filename_space = vars->filename_space;
|
filename_space = vars->filename_space;
|
||||||
|
|
||||||
File_Slot *slot = slots;
|
File_Slot *slot = slots;
|
||||||
for (i = 0; i < exchange->file.max; ++i, ++slot){
|
for (i = 0; i < files->max; ++i, ++slot){
|
||||||
ex__file_insert(&exchange->file.available, slot);
|
ex__file_insert(&files->available, slot);
|
||||||
slot->filename = filename_space;
|
slot->filename = filename_space;
|
||||||
filename_space += FileNameMax;
|
filename_space += FileNameMax;
|
||||||
}
|
}
|
||||||
|
@ -3562,7 +3560,7 @@ App_Init_Sig(app_init){
|
||||||
vars->cli_processes.count = 0;
|
vars->cli_processes.count = 0;
|
||||||
|
|
||||||
// NOTE(allen): sys app binding setup
|
// NOTE(allen): sys app binding setup
|
||||||
vars->sys_app_max = exchange->file.max;
|
vars->sys_app_max = models->files.max;
|
||||||
vars->sys_app_count = 0;
|
vars->sys_app_count = 0;
|
||||||
vars->sys_app_bindings = (Sys_App_Binding*)push_array(partition, Sys_App_Binding, vars->sys_app_max);
|
vars->sys_app_bindings = (Sys_App_Binding*)push_array(partition, Sys_App_Binding, vars->sys_app_max);
|
||||||
|
|
||||||
|
@ -4430,11 +4428,12 @@ App_Step_Sig(app_step){
|
||||||
// NOTE(allen): Simulate what use to happen on the system side
|
// NOTE(allen): Simulate what use to happen on the system side
|
||||||
// for processing file exchange.
|
// for processing file exchange.
|
||||||
{
|
{
|
||||||
|
File_Exchange *files = &models->files;
|
||||||
File_Slot *file;
|
File_Slot *file;
|
||||||
int d = 0;
|
int d = 0;
|
||||||
|
|
||||||
for (file = exchange->file.active.next;
|
for (file = files->active.next;
|
||||||
file != &exchange->file.active;
|
file != &files->active;
|
||||||
file = file->next){
|
file = file->next){
|
||||||
++d;
|
++d;
|
||||||
|
|
||||||
|
@ -4475,25 +4474,26 @@ App_Step_Sig(app_step){
|
||||||
}
|
}
|
||||||
|
|
||||||
int free_list_count = 0;
|
int free_list_count = 0;
|
||||||
for (file = exchange->file.free_list.next;
|
for (file = files->free_list.next;
|
||||||
file != &exchange->file.free_list;
|
file != &files->free_list;
|
||||||
file = file->next){
|
file = file->next){
|
||||||
++free_list_count;
|
++free_list_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exchange->file.free_list.next != &exchange->file.free_list){
|
if (files->free_list.next != &files->free_list){
|
||||||
Assert(free_list_count != 0);
|
Assert(free_list_count != 0);
|
||||||
ex__insert_range(exchange->file.free_list.next,
|
ex__insert_range(files->free_list.next,
|
||||||
exchange->file.free_list.prev,
|
files->free_list.prev,
|
||||||
&exchange->file.available);
|
&files->available);
|
||||||
exchange->file.num_active -= free_list_count;
|
files->num_active -= free_list_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
ex__check(&exchange->file);
|
ex__check(files);
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE(allen): processing sys app bindings
|
// NOTE(allen): processing sys app bindings
|
||||||
{
|
{
|
||||||
|
File_Exchange *files = &models->files;
|
||||||
Mem_Options *mem = &models->mem;
|
Mem_Options *mem = &models->mem;
|
||||||
General_Memory *general = &mem->general;
|
General_Memory *general = &mem->general;
|
||||||
|
|
||||||
|
@ -4509,13 +4509,13 @@ App_Step_Sig(app_step){
|
||||||
|
|
||||||
Working_Set *working_set = &models->working_set;
|
Working_Set *working_set = &models->working_set;
|
||||||
File_Ready_Result file_result =
|
File_Ready_Result file_result =
|
||||||
exchange_file_ready(exchange, binding->sys_id);
|
exchange_file_ready(files, binding->sys_id);
|
||||||
|
|
||||||
if (file_result.ready){
|
if (file_result.ready){
|
||||||
ed_file = working_set_get_active_file(working_set, binding->app_id);
|
ed_file = working_set_get_active_file(working_set, binding->app_id);
|
||||||
Assert(ed_file);
|
Assert(ed_file);
|
||||||
|
|
||||||
filename = exchange_file_filename(exchange, binding->sys_id);
|
filename = exchange_file_filename(files, binding->sys_id);
|
||||||
preload_settings = ed_file->preload;
|
preload_settings = ed_file->preload;
|
||||||
if (file_result.exists){
|
if (file_result.exists){
|
||||||
String val = make_string((char*)file_result.data, file_result.size);
|
String val = make_string((char*)file_result.data, file_result.size);
|
||||||
|
@ -4549,7 +4549,7 @@ App_Step_Sig(app_step){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exchange_free_file(exchange, binding->sys_id);
|
exchange_free_file(files, binding->sys_id);
|
||||||
remove = 1;
|
remove = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4557,12 +4557,12 @@ App_Step_Sig(app_step){
|
||||||
byte *data;
|
byte *data;
|
||||||
i32 size, max;
|
i32 size, max;
|
||||||
|
|
||||||
if (exchange_file_save_complete(exchange, binding->sys_id, &data, &size, &max, &failed)){
|
if (exchange_file_save_complete(files, binding->sys_id, &data, &size, &max, &failed)){
|
||||||
Assert(remove == 0);
|
Assert(remove == 0);
|
||||||
|
|
||||||
if (data){
|
if (data){
|
||||||
general_memory_free(general, data);
|
general_memory_free(general, data);
|
||||||
exchange_clear_file(exchange, binding->sys_id);
|
exchange_clear_file(files, binding->sys_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
Editing_File *file = working_set_get_active_file(working_set, binding->app_id);
|
Editing_File *file = working_set_get_active_file(working_set, binding->app_id);
|
||||||
|
@ -4570,7 +4570,7 @@ App_Step_Sig(app_step){
|
||||||
file_synchronize_times(system, file, file->name.source_path.str);
|
file_synchronize_times(system, file, file->name.source_path.str);
|
||||||
}
|
}
|
||||||
|
|
||||||
exchange_free_file(exchange, binding->sys_id);
|
exchange_free_file(files, binding->sys_id);
|
||||||
remove = 1;
|
remove = 1;
|
||||||
|
|
||||||
// if (failed) { TODO(allen): saving error, now what? }
|
// if (failed) { TODO(allen): saving error, now what? }
|
||||||
|
@ -4587,6 +4587,7 @@ App_Step_Sig(app_step){
|
||||||
|
|
||||||
// NOTE(allen): process as many delayed actions as possible
|
// NOTE(allen): process as many delayed actions as possible
|
||||||
if (models->delay1.count > 0){
|
if (models->delay1.count > 0){
|
||||||
|
File_Exchange *files = &models->files;
|
||||||
Working_Set *working_set = &models->working_set;
|
Working_Set *working_set = &models->working_set;
|
||||||
Mem_Options *mem = &models->mem;
|
Mem_Options *mem = &models->mem;
|
||||||
General_Memory *general = &mem->general;
|
General_Memory *general = &mem->general;
|
||||||
|
@ -4624,7 +4625,7 @@ App_Step_Sig(app_step){
|
||||||
result.is_new = 1;
|
result.is_new = 1;
|
||||||
result.file = working_set_alloc_always(working_set, general);
|
result.file = working_set_alloc_always(working_set, general);
|
||||||
if (result.file){
|
if (result.file){
|
||||||
file_id = exchange_request_file(exchange, filename.str, filename.size);
|
file_id = exchange_request_file(files, filename.str, filename.size);
|
||||||
if (file_id){
|
if (file_id){
|
||||||
file_init_strings(result.file);
|
file_init_strings(result.file);
|
||||||
file_set_name(working_set, result.file, filename.str);
|
file_set_name(working_set, result.file, filename.str);
|
||||||
|
@ -4698,7 +4699,7 @@ App_Step_Sig(app_step){
|
||||||
// TODO(allen): We could handle the case where someone tries to save the same thing
|
// TODO(allen): We could handle the case where someone tries to save the same thing
|
||||||
// twice... that would be nice to have under control.
|
// twice... that would be nice to have under control.
|
||||||
if (file && buffer_get_sync(file) != SYNC_GOOD){
|
if (file && buffer_get_sync(file) != SYNC_GOOD){
|
||||||
i32 sys_id = file_save(system, exchange, mem, file, file->name.source_path.str);
|
i32 sys_id = file_save(system, files, mem, file, file->name.source_path.str);
|
||||||
if (sys_id){
|
if (sys_id){
|
||||||
if (act->type == DACT_SAVE_AS){
|
if (act->type == DACT_SAVE_AS){
|
||||||
file_set_name(working_set, file, string.str);
|
file_set_name(working_set, file, string.str);
|
||||||
|
|
|
@ -64,6 +64,8 @@ struct Models{
|
||||||
|
|
||||||
Custom_API config_api;
|
Custom_API config_api;
|
||||||
Scroll_Rule_Function *scroll_rule;
|
Scroll_Rule_Function *scroll_rule;
|
||||||
|
|
||||||
|
File_Exchange files;
|
||||||
};
|
};
|
||||||
|
|
||||||
// BOTTOM
|
// BOTTOM
|
||||||
|
|
|
@ -9,6 +9,21 @@
|
||||||
|
|
||||||
// TOP
|
// TOP
|
||||||
|
|
||||||
|
enum File_Exchange_Flag{
|
||||||
|
FEx_Request = 0x1,
|
||||||
|
FEx_Ready = 0x2,
|
||||||
|
FEx_Not_Exist = 0x4,
|
||||||
|
FEx_Save = 0x8,
|
||||||
|
FEx_Save_Complete = 0x10,
|
||||||
|
FEx_Save_Failed = 0x20
|
||||||
|
};
|
||||||
|
|
||||||
|
struct File_Exchange{
|
||||||
|
File_Slot available, active, free_list;
|
||||||
|
File_Slot *files;
|
||||||
|
i32 num_active, max;
|
||||||
|
};
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
ex__file_insert(File_Slot *pos, File_Slot *file){
|
ex__file_insert(File_Slot *pos, File_Slot *file){
|
||||||
pos->next->prev = file;
|
pos->next->prev = file;
|
||||||
|
@ -63,8 +78,7 @@ ex__clear(File_Slot *file){
|
||||||
}
|
}
|
||||||
|
|
||||||
internal File_Slot*
|
internal File_Slot*
|
||||||
ex__get_file(Exchange *exchange){
|
ex__get_file(File_Exchange *files){
|
||||||
File_Exchange *files = &exchange->file;
|
|
||||||
File_Slot *file;
|
File_Slot *file;
|
||||||
|
|
||||||
++files->num_active;
|
++files->num_active;
|
||||||
|
@ -86,13 +100,12 @@ ex__set_filename(File_Slot *file, char *filename, int len){
|
||||||
}
|
}
|
||||||
|
|
||||||
internal i32
|
internal i32
|
||||||
exchange_request_file(Exchange *exchange, char *filename, int len){
|
exchange_request_file(File_Exchange *files, char *filename, int len){
|
||||||
File_Exchange *files = &exchange->file;
|
|
||||||
i32 result = 0;
|
i32 result = 0;
|
||||||
|
|
||||||
if (len+1 < FileNameMax){
|
if (len+1 < FileNameMax){
|
||||||
if (files->num_active < files->max){
|
if (files->num_active < files->max){
|
||||||
File_Slot *file = ex__get_file(exchange);
|
File_Slot *file = ex__get_file(files);
|
||||||
ex__set_filename(file, filename, len);
|
ex__set_filename(file, filename, len);
|
||||||
|
|
||||||
file->flags |= FEx_Request;
|
file->flags |= FEx_Request;
|
||||||
|
@ -112,9 +125,8 @@ struct File_Ready_Result{
|
||||||
};
|
};
|
||||||
|
|
||||||
internal File_Ready_Result
|
internal File_Ready_Result
|
||||||
exchange_file_ready(Exchange *exchange, i32 file_id){
|
exchange_file_ready(File_Exchange *files, i32 file_id){
|
||||||
File_Ready_Result result = {0};
|
File_Ready_Result result = {0};
|
||||||
File_Exchange *files = &exchange->file;
|
|
||||||
File_Slot *file = 0;
|
File_Slot *file = 0;
|
||||||
|
|
||||||
if (file_id > 0 && file_id <= files->max){
|
if (file_id > 0 && file_id <= files->max){
|
||||||
|
@ -139,8 +151,7 @@ exchange_file_ready(Exchange *exchange, i32 file_id){
|
||||||
}
|
}
|
||||||
|
|
||||||
internal b32
|
internal b32
|
||||||
exchange_file_does_not_exist(Exchange *exchange, i32 file_id){
|
exchange_file_does_not_exist(File_Exchange *files, i32 file_id){
|
||||||
File_Exchange *files = &exchange->file;
|
|
||||||
b32 result = 1;
|
b32 result = 1;
|
||||||
File_Slot *slot;
|
File_Slot *slot;
|
||||||
|
|
||||||
|
@ -155,14 +166,13 @@ exchange_file_does_not_exist(Exchange *exchange, i32 file_id){
|
||||||
}
|
}
|
||||||
|
|
||||||
internal i32
|
internal i32
|
||||||
exchange_save_file(Exchange *exchange, char *filename, int len,
|
exchange_save_file(File_Exchange *files, char *filename, int len,
|
||||||
byte *data, int size, int max){
|
byte *data, int size, int max){
|
||||||
File_Exchange *files = &exchange->file;
|
|
||||||
i32 result = 0;
|
i32 result = 0;
|
||||||
|
|
||||||
if (len+1 < FileNameMax){
|
if (len+1 < FileNameMax){
|
||||||
if (files->num_active < files->max){
|
if (files->num_active < files->max){
|
||||||
File_Slot *file = ex__get_file(exchange);
|
File_Slot *file = ex__get_file(files);
|
||||||
ex__set_filename(file, filename, len);
|
ex__set_filename(file, filename, len);
|
||||||
|
|
||||||
file->flags |= FEx_Save;
|
file->flags |= FEx_Save;
|
||||||
|
@ -178,8 +188,8 @@ exchange_save_file(Exchange *exchange, char *filename, int len,
|
||||||
}
|
}
|
||||||
|
|
||||||
internal b32
|
internal b32
|
||||||
exchange_file_save_complete(Exchange *exchange, i32 file_id, byte **data, int *size, int *max, int *failed){
|
exchange_file_save_complete(File_Exchange *files, i32 file_id,
|
||||||
File_Exchange *files = &exchange->file;
|
byte **data, int *size, int *max, int *failed){
|
||||||
b32 result = 0;
|
b32 result = 0;
|
||||||
|
|
||||||
if (file_id > 0 && file_id <= files->max){
|
if (file_id > 0 && file_id <= files->max){
|
||||||
|
@ -198,8 +208,7 @@ exchange_file_save_complete(Exchange *exchange, i32 file_id, byte **data, int *s
|
||||||
}
|
}
|
||||||
|
|
||||||
internal char*
|
internal char*
|
||||||
exchange_file_filename(Exchange *exchange, i32 file_id, i32 *size = 0){
|
exchange_file_filename(File_Exchange *files, i32 file_id, i32 *size = 0){
|
||||||
File_Exchange *files = &exchange->file;
|
|
||||||
char *result = 0;
|
char *result = 0;
|
||||||
|
|
||||||
if (file_id > 0 && file_id <= files->max){
|
if (file_id > 0 && file_id <= files->max){
|
||||||
|
@ -212,9 +221,7 @@ exchange_file_filename(Exchange *exchange, i32 file_id, i32 *size = 0){
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
exchange_free_file(Exchange *exchange, i32 file_id){
|
exchange_free_file(File_Exchange *files, i32 file_id){
|
||||||
File_Exchange *files = &exchange->file;
|
|
||||||
|
|
||||||
if (file_id > 0 && file_id <= files->max){
|
if (file_id > 0 && file_id <= files->max){
|
||||||
File_Slot *file = files->files + file_id - 1;
|
File_Slot *file = files->files + file_id - 1;
|
||||||
ex__file_remove(file);
|
ex__file_remove(file);
|
||||||
|
@ -224,9 +231,7 @@ exchange_free_file(Exchange *exchange, i32 file_id){
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
exchange_clear_file(Exchange *exchange, i32 file_id){
|
exchange_clear_file(File_Exchange *files, i32 file_id){
|
||||||
File_Exchange *files = &exchange->file;
|
|
||||||
|
|
||||||
if (file_id > 0 && file_id <= files->max){
|
if (file_id > 0 && file_id <= files->max){
|
||||||
File_Slot *file = files->files + file_id - 1;
|
File_Slot *file = files->files + file_id - 1;
|
||||||
ex__clear(file);
|
ex__clear(file);
|
||||||
|
|
|
@ -436,7 +436,7 @@ file_synchronize_times(System_Functions *system, Editing_File *file, char *filen
|
||||||
}
|
}
|
||||||
|
|
||||||
internal i32
|
internal i32
|
||||||
file_save(System_Functions *system, Exchange *exchange, Mem_Options *mem,
|
file_save(System_Functions *system, File_Exchange *files, Mem_Options *mem,
|
||||||
Editing_File *file, char *filename){
|
Editing_File *file, char *filename){
|
||||||
i32 result = 0;
|
i32 result = 0;
|
||||||
|
|
||||||
|
@ -458,7 +458,7 @@ file_save(System_Functions *system, Exchange *exchange, Mem_Options *mem,
|
||||||
else
|
else
|
||||||
buffer_stringify(buffer, 0, size = max, data);
|
buffer_stringify(buffer, 0, size = max, data);
|
||||||
|
|
||||||
result = exchange_save_file(exchange, filename, str_size(filename), (byte*)data, size, max);
|
result = exchange_save_file(files, filename, str_size(filename), (byte*)data, size, max);
|
||||||
|
|
||||||
if (result == 0){
|
if (result == 0){
|
||||||
general_memory_free(&mem->general, data);
|
general_memory_free(&mem->general, data);
|
||||||
|
@ -470,11 +470,11 @@ file_save(System_Functions *system, Exchange *exchange, Mem_Options *mem,
|
||||||
}
|
}
|
||||||
|
|
||||||
inline b32
|
inline b32
|
||||||
file_save_and_set_names(System_Functions *system, Exchange *exchange,
|
file_save_and_set_names(System_Functions *system, File_Exchange *files,
|
||||||
Mem_Options *mem, Working_Set *working_set, Editing_File *file,
|
Mem_Options *mem, Working_Set *working_set, Editing_File *file,
|
||||||
char *filename){
|
char *filename){
|
||||||
b32 result = 0;
|
b32 result = 0;
|
||||||
result = file_save(system, exchange, mem, file, filename);
|
result = file_save(system, files, mem, file, filename);
|
||||||
if (result){
|
if (result){
|
||||||
file_set_name(working_set, file, filename);
|
file_set_name(working_set, file, filename);
|
||||||
}
|
}
|
||||||
|
|
16
4ed_system.h
16
4ed_system.h
|
@ -282,21 +282,6 @@ file_slot_zero(){
|
||||||
return(slot);
|
return(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum File_Exchange_Flag{
|
|
||||||
FEx_Request = 0x1,
|
|
||||||
FEx_Ready = 0x2,
|
|
||||||
FEx_Not_Exist = 0x4,
|
|
||||||
FEx_Save = 0x8,
|
|
||||||
FEx_Save_Complete = 0x10,
|
|
||||||
FEx_Save_Failed = 0x20
|
|
||||||
};
|
|
||||||
|
|
||||||
struct File_Exchange{
|
|
||||||
File_Slot available, active, free_list;
|
|
||||||
File_Slot *files;
|
|
||||||
i32 num_active, max;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Write_Event{
|
struct Write_Event{
|
||||||
Write_Event *next, *prev;
|
Write_Event *next, *prev;
|
||||||
String filename;
|
String filename;
|
||||||
|
@ -305,7 +290,6 @@ struct Write_Event{
|
||||||
|
|
||||||
struct Exchange{
|
struct Exchange{
|
||||||
Thread_Exchange thread;
|
Thread_Exchange thread;
|
||||||
File_Exchange file;
|
|
||||||
Write_Event write_event_sentinel;
|
Write_Event write_event_sentinel;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -66,83 +66,6 @@ sysshared_filter_real_files(char **files, i32 *file_count){
|
||||||
*file_count = j;
|
*file_count = j;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
void
|
|
||||||
ex__file_insert(File_Slot *pos, File_Slot *file){
|
|
||||||
file->next = pos->next;
|
|
||||||
file->next->prev = file;
|
|
||||||
file->prev = pos;
|
|
||||||
pos->next = file;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
ex__insert_range(File_Slot *start, File_Slot *end, File_Slot *pos){
|
|
||||||
end->next->prev = start->prev;
|
|
||||||
start->prev->next = end->next;
|
|
||||||
|
|
||||||
end->next = pos->next;
|
|
||||||
start->prev = pos;
|
|
||||||
pos->next->prev = end;
|
|
||||||
pos->next = start;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void
|
|
||||||
ex__check_file(File_Slot *pos){
|
|
||||||
File_Slot *file = pos;
|
|
||||||
|
|
||||||
Assert(pos == pos->next->prev);
|
|
||||||
|
|
||||||
for (pos = pos->next;
|
|
||||||
file != pos;
|
|
||||||
pos = pos->next){
|
|
||||||
Assert(pos == pos->next->prev);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void
|
|
||||||
ex__check(File_Exchange *file_exchange){
|
|
||||||
ex__check_file(&file_exchange->available);
|
|
||||||
ex__check_file(&file_exchange->active);
|
|
||||||
ex__check_file(&file_exchange->free_list);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void
|
|
||||||
sysshared_init_file_exchange(
|
|
||||||
Exchange *exchange, File_Slot *slots, i32 max,
|
|
||||||
char **filename_space_out){
|
|
||||||
char *filename_space;
|
|
||||||
i32 i;
|
|
||||||
|
|
||||||
exchange->file.max = max;
|
|
||||||
exchange->file.available = file_slot_zero();
|
|
||||||
exchange->file.available.next = &exchange->file.available;
|
|
||||||
exchange->file.available.prev = &exchange->file.available;
|
|
||||||
|
|
||||||
exchange->file.active = file_slot_zero();
|
|
||||||
exchange->file.active.next = &exchange->file.active;
|
|
||||||
exchange->file.active.prev = &exchange->file.active;
|
|
||||||
|
|
||||||
exchange->file.free_list = file_slot_zero();
|
|
||||||
exchange->file.free_list.next = &exchange->file.free_list;
|
|
||||||
exchange->file.free_list.prev = &exchange->file.free_list;
|
|
||||||
|
|
||||||
exchange->file.files = slots;
|
|
||||||
memset(slots, 0, sizeof(File_Slot)*max);
|
|
||||||
|
|
||||||
filename_space = (char*)
|
|
||||||
system_get_memory(FileNameMax*exchange->file.max);
|
|
||||||
|
|
||||||
File_Slot *slot = slots;
|
|
||||||
for (i = 0; i < exchange->file.max; ++i, ++slot){
|
|
||||||
ex__file_insert(&exchange->file.available, slot);
|
|
||||||
slot->filename = filename_space;
|
|
||||||
filename_space += FileNameMax;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filename_space_out) *filename_space_out = filename_space;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
internal Partition
|
internal Partition
|
||||||
sysshared_scratch_partition(i32 size){
|
sysshared_scratch_partition(i32 size){
|
||||||
void *data = system_get_memory(size);
|
void *data = system_get_memory(size);
|
||||||
|
|
|
@ -1906,11 +1906,6 @@ int main(int argc, char **argv){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
File_Slot file_slots[32];
|
|
||||||
sysshared_init_file_exchange(&exchange_vars, file_slots, ArrayCount(file_slots), 0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
win32vars.app.init(win32vars.system, &win32vars.target,
|
win32vars.app.init(win32vars.system, &win32vars.target,
|
||||||
&memory_vars, &exchange_vars,
|
&memory_vars, &exchange_vars,
|
||||||
|
@ -2058,66 +2053,6 @@ int main(int argc, char **argv){
|
||||||
|
|
||||||
win32vars.first = 0;
|
win32vars.first = 0;
|
||||||
|
|
||||||
#if 0
|
|
||||||
{
|
|
||||||
File_Slot *file;
|
|
||||||
int d = 0;
|
|
||||||
|
|
||||||
for (file = exchange_vars.file.active.next;
|
|
||||||
file != &exchange_vars.file.active;
|
|
||||||
file = file->next){
|
|
||||||
++d;
|
|
||||||
|
|
||||||
if (file->flags & FEx_Save){
|
|
||||||
Assert((file->flags & FEx_Request) == 0);
|
|
||||||
file->flags &= (~FEx_Save);
|
|
||||||
if (sysshared_save_file(file->filename, (char*)file->data, file->size)){
|
|
||||||
file->flags |= FEx_Save_Complete;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
file->flags |= FEx_Save_Failed;
|
|
||||||
}
|
|
||||||
PostMessage(win32vars.window_handle, WM_4coder_ANIMATE, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (file->flags & FEx_Request){
|
|
||||||
Assert((file->flags & FEx_Save) == 0);
|
|
||||||
file->flags &= (~FEx_Request);
|
|
||||||
File_Data sysfile = sysshared_load_file(file->filename);
|
|
||||||
if (!sysfile.got_file){
|
|
||||||
file->flags |= FEx_Not_Exist;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
file->flags |= FEx_Ready;
|
|
||||||
file->data = sysfile.data.data;
|
|
||||||
file->size = sysfile.data.size;
|
|
||||||
}
|
|
||||||
PostMessage(win32vars.window_handle, WM_4coder_ANIMATE, 0, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int free_list_count = 0;
|
|
||||||
for (file = exchange_vars.file.free_list.next;
|
|
||||||
file != &exchange_vars.file.free_list;
|
|
||||||
file = file->next){
|
|
||||||
++free_list_count;
|
|
||||||
if (file->data){
|
|
||||||
system_free_memory(file->data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (exchange_vars.file.free_list.next != &exchange_vars.file.free_list){
|
|
||||||
Assert(free_list_count != 0);
|
|
||||||
ex__insert_range(exchange_vars.file.free_list.next, exchange_vars.file.free_list.prev,
|
|
||||||
&exchange_vars.file.available);
|
|
||||||
|
|
||||||
exchange_vars.file.num_active -= free_list_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
ex__check(&exchange_vars.file);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
i64 timer_end = system_time();
|
i64 timer_end = system_time();
|
||||||
i64 end_target = (timer_start + frame_useconds);
|
i64 end_target = (timer_start + frame_useconds);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue