bprinting loaded project into string fields

This commit is contained in:
Synthasmagoria 2026-08-22 18:49:11 +02:00
commit 6bbcd80268
2 changed files with 15 additions and 9 deletions

View file

@ -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)
}
}

View file

@ -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
}