Console works again | UI crash fixes

This commit is contained in:
2024-12-22 00:49:35 +01:00
parent 664626c838
commit f8b540f583
7 changed files with 119 additions and 9 deletions

View File

@@ -1,10 +1,8 @@
#import "File_Utilities";
console : *Console;
Command_Proc :: struct {
name: string;
proc: (arguments: [] string, buffer: *[..] Buffer_Entry);
proc: (arguments: [] string);
}
Buffer_Entry :: struct {
@@ -30,7 +28,15 @@ Console :: struct {
verts: [..] Colored_Vert;
}
add_command :: (console: *Console, cmd: string, proc: (arguments: [] string, buffer: *[..] Buffer_Entry)) {
console_error :: (str: string, args: ..Any) {
array_add(*console.buffer, .{sprint(str, ..args), .{1,0,0,1}});
}
console_success :: (str: string, args: ..Any) {
array_add(*console.buffer, .{sprint(str, ..args), .{0,1,0,1}});
}
add_command :: (console: *Console, cmd: string, proc: (arguments: [] string)) {
command : Command_Proc;
command.name = copy_string(cmd);
command.proc = proc;
@@ -40,7 +46,7 @@ add_command :: (console: *Console, cmd: string, proc: (arguments: [] string, buf
init_console :: () {
console = New(Console);
console.verts.allocator = temp;
//console.verts.allocator = temp;
buffer_size := size_of(Colored_Vert) * 12;
console.vb = create_vertex_buffer(engine.renderer, null, xx buffer_size, stride=size_of(Colored_Vert), mappable=true);
console.cursor_vb = create_vertex_buffer(engine.renderer, null, xx buffer_size, stride=size_of(Colored_Vert), mappable=true);
@@ -80,6 +86,8 @@ init_console :: () {
//add_command(console, "copy", copy_scene);
//add_command(console, "vsync", set_vsync);
add_engine_console_commands();
//engine.console = console;
}
@@ -112,12 +120,16 @@ update_console :: () {
// So each subsequent space will be an argument itself.
// This is a bit of a hacky fix for now
arguments := split(console.current_string, " ");
index := 0;
command := arguments[0];
while index < arguments.count - 1 {
if arguments[index].count == 0 {
arguments[index] = arguments[arguments.count - 1];
arguments.count -= 1;
} else {
if index > 0 {
}
index += 1;
}
}
@@ -126,12 +138,21 @@ update_console :: () {
arguments.count -= 1;
}
for_cmd : [..] string;
for_cmd.allocator = temp;
array_reserve(*for_cmd, arguments.count-1);
for arguments {
if it_index == 0 continue;
array_add(*for_cmd, it);
}
cmd, success := find_command(console, arguments[0]);
push_entry(*console.buffer, console.current_string, .{1,1,1,1});
if success {
cmd.proc(arguments, *console.buffer);
cmd.proc(for_cmd);
} else {
push_entry(*console.buffer, console.current_string, .{1,0,0,1});
}
@@ -269,3 +290,6 @@ push_entry :: (buffer: *[..] Buffer_Entry, text: string, color: Color) {
entry.color = color;
array_add(buffer, entry);
}
#import "File_Utilities";
#load "console_commands.jai";