Better saving/loading
This commit is contained in:
parent
ebd0ef76d3
commit
e6bb0cb1f7
3 changed files with 139 additions and 43 deletions
31
project.odin
31
project.odin
|
|
@ -17,27 +17,28 @@ ProjectData :: struct {
|
|||
version: u32,
|
||||
matrix_count: u32,
|
||||
matrices: []f32,
|
||||
grid: Grid,
|
||||
animation: Animation,
|
||||
}
|
||||
|
||||
WriteProjectError :: union {
|
||||
ProjectWriteError :: union {
|
||||
os.Error,
|
||||
io.Error,
|
||||
}
|
||||
|
||||
WriteProjectErrorType :: enum {
|
||||
IncompatibleVersion,
|
||||
}
|
||||
|
||||
project_write :: proc(project: ^ProjectData, path: string) -> os.Error {
|
||||
project_write :: proc(project: ^ProjectData, path: string) -> ProjectWriteError {
|
||||
f := os.open(path, {.Create, .Trunc, .Write}) or_return
|
||||
defer os.close(f)
|
||||
w := io.to_writer(os.to_stream(f))
|
||||
version: u32 = PROJECT_DATA_VERSION
|
||||
header := PROJECT_DATA_HEADER
|
||||
|
||||
io.write_full(w, transmute([]u8)header)
|
||||
io.write_ptr(w, &version, size_of(version))
|
||||
io.write_ptr(w, &project.matrix_count, size_of(project.matrix_count))
|
||||
io.write_ptr(w, raw_data(project.matrices), int(project.matrix_count) * 9 * size_of(f32))
|
||||
io.write_full(w, transmute([]u8)header) or_return
|
||||
io.write_ptr(w, &version, size_of(version)) or_return
|
||||
io.write_ptr(w, &project.matrix_count, size_of(project.matrix_count)) or_return
|
||||
n := io.write_ptr(w, raw_data(project.matrices), int(project.matrix_count) * 9 * size_of(f32)) or_return
|
||||
fmt.println(n)
|
||||
// io.write_ptr(w, &project.grid, size_of(Grid))
|
||||
os.close(f)
|
||||
return nil
|
||||
}
|
||||
|
|
@ -54,7 +55,9 @@ ProjectReadErrorType :: enum {
|
|||
VersionNeedsUpgrade,
|
||||
}
|
||||
|
||||
project_read :: proc(project: ^ProjectData, path: string, allocator: mem.Allocator) -> ProjectReadError {
|
||||
import "core:fmt"
|
||||
|
||||
project_read :: proc(project: ^ProjectData, path: string) -> ProjectReadError {
|
||||
f := os.open(path, {.Read}) or_return
|
||||
defer os.close(f)
|
||||
r := io.to_reader(os.to_stream(f))
|
||||
|
|
@ -71,7 +74,9 @@ project_read :: proc(project: ^ProjectData, path: string, allocator: mem.Allocat
|
|||
return ProjectReadErrorType.VersionNeedsUpgrade
|
||||
}
|
||||
_ = 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
|
||||
n := io.read_ptr(r, raw_data(project.matrices), size_of(f32) * len(project.matrices)) or_return
|
||||
fmt.println(n)
|
||||
// _ = io.read_ptr(r, &project.grid, size_of(Grid)) or_return
|
||||
// _ = io.read_ptr(r, &project.animation, size_of(Animation)) or_return
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue