diff --git a/program.odin b/program.odin index 20f7fc1..6b0986e 100644 --- a/program.odin +++ b/program.odin @@ -2,6 +2,7 @@ package main import rl "libraries/raylib" import ui "libraries/snths_ui" +import "core:mem" import "core:fmt" import "core:math/linalg" import "core:math/ease" @@ -236,8 +237,12 @@ program_save_project :: proc(program: ^Program, path: string) -> os.Error { program_load_project :: proc(program: ^Program, path: string) -> ProjectReadError { project: ProjectData - project_read(&project, path) or_return - fmt.println(project.version) + project_read(&project, path, context.temp_allocator) or_return + program.matrix_count = int(project.matrix_count) + mem.copy(raw_data(program.matrix_float_pool), raw_data(project.matrices), len(project.matrices) * size_of(f32) * 9) + for val, i in program.matrix_float_pool[:program.matrix_count * 9] { + fmt.bprint(program.matrix_value_string_pool[i][:], val) + } return nil } @@ -280,7 +285,7 @@ program_init :: proc(allocator := context.allocator) { program.animation_ease = .Quadratic_Out if err := program_load_project(&program, DEFAULT_PROJECT_LOAD_LOCATION); err != nil { - fmt.println(err) + fmt.println("ERROR:", err) } } diff --git a/project.odin b/project.odin index 924c9db..717e69e 100644 --- a/project.odin +++ b/project.odin @@ -48,7 +48,7 @@ ProjectReadErrorType :: enum { VersionNeedsUpgrade, } -project_read :: proc(project: ^ProjectData, path: string) -> ProjectReadError { +project_read :: proc(project: ^ProjectData, path: string, allocator: mem.Allocator) -> ProjectReadError { f := os.open(path, {.Read}) or_return defer os.close(f) r := io.to_reader(os.to_stream(f)) @@ -57,14 +57,15 @@ project_read :: proc(project: ^ProjectData, path: string) -> ProjectReadError { if num, err := io.read_full(r, header_buffer[:]); err != nil { return ProjectReadErrorType.FailedReadingHeader } - if mem.compare(transmute([]byte)header[:], header_buffer[:]) != 0 { + if mem.compare(transmute([]byte)header, header_buffer[:]) != 0 { return ProjectReadErrorType.BadHeader } - version: u32 - _ = io.read_ptr(r, &version, size_of(u32)) or_return - if version != PROJECT_DATA_VERSION { + _ = io.read_ptr(r, &project.version, size_of(project.matrix_count)) or_return + if project.version != PROJECT_DATA_VERSION { return ProjectReadErrorType.VersionNeedsUpgrade } - project.version = version + _ = io.read_ptr(r, &project.matrix_count, size_of(project.matrix_count)) or_return + project.matrices = make([]f32, size_of(f32) * int(project.matrix_count) * 9) + _ = io.read_ptr(r, raw_data(project.matrices), size_of(f32) * len(project.matrices)) or_return return nil }