bprinting loaded project into string fields
This commit is contained in:
parent
c3999f8ade
commit
6bbcd80268
2 changed files with 15 additions and 9 deletions
11
program.odin
11
program.odin
|
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import rl "libraries/raylib"
|
import rl "libraries/raylib"
|
||||||
import ui "libraries/snths_ui"
|
import ui "libraries/snths_ui"
|
||||||
|
import "core:mem"
|
||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
import "core:math/linalg"
|
import "core:math/linalg"
|
||||||
import "core:math/ease"
|
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 {
|
program_load_project :: proc(program: ^Program, path: string) -> ProjectReadError {
|
||||||
project: ProjectData
|
project: ProjectData
|
||||||
project_read(&project, path) or_return
|
project_read(&project, path, context.temp_allocator) or_return
|
||||||
fmt.println(project.version)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -280,7 +285,7 @@ program_init :: proc(allocator := context.allocator) {
|
||||||
program.animation_ease = .Quadratic_Out
|
program.animation_ease = .Quadratic_Out
|
||||||
|
|
||||||
if err := program_load_project(&program, DEFAULT_PROJECT_LOAD_LOCATION); err != nil {
|
if err := program_load_project(&program, DEFAULT_PROJECT_LOAD_LOCATION); err != nil {
|
||||||
fmt.println(err)
|
fmt.println("ERROR:", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
13
project.odin
13
project.odin
|
|
@ -48,7 +48,7 @@ ProjectReadErrorType :: enum {
|
||||||
VersionNeedsUpgrade,
|
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
|
f := os.open(path, {.Read}) or_return
|
||||||
defer os.close(f)
|
defer os.close(f)
|
||||||
r := io.to_reader(os.to_stream(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 {
|
if num, err := io.read_full(r, header_buffer[:]); err != nil {
|
||||||
return ProjectReadErrorType.FailedReadingHeader
|
return ProjectReadErrorType.FailedReadingHeader
|
||||||
}
|
}
|
||||||
if mem.compare(transmute([]byte)header[:], header_buffer[:]) != 0 {
|
if mem.compare(transmute([]byte)header, header_buffer[:]) != 0 {
|
||||||
return ProjectReadErrorType.BadHeader
|
return ProjectReadErrorType.BadHeader
|
||||||
}
|
}
|
||||||
version: u32
|
_ = io.read_ptr(r, &project.version, size_of(project.matrix_count)) or_return
|
||||||
_ = io.read_ptr(r, &version, size_of(u32)) or_return
|
if project.version != PROJECT_DATA_VERSION {
|
||||||
if version != PROJECT_DATA_VERSION {
|
|
||||||
return ProjectReadErrorType.VersionNeedsUpgrade
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue