Moved stuff
This commit is contained in:
parent
a4dd76a186
commit
5377458895
234 changed files with 12 additions and 1 deletions
75
project.odin
75
project.odin
|
|
@ -1,75 +0,0 @@
|
|||
package main
|
||||
|
||||
/*
|
||||
TODO (synthas): Things to save to the project file
|
||||
- Grid configuration
|
||||
- Shape configuration
|
||||
*/
|
||||
|
||||
import "core:os"
|
||||
import "core:io"
|
||||
import "core:mem"
|
||||
|
||||
PROJECT_DATA_HEADER :: "WOWOWOW THIS IS HEADER WOWOWOW"
|
||||
PROJECT_DATA_VERSION :: 1
|
||||
|
||||
ProjectData :: struct {
|
||||
version: u32,
|
||||
matrix_count: u32,
|
||||
matrices: []f32,
|
||||
grid: Grid,
|
||||
animation: Animation,
|
||||
}
|
||||
|
||||
ProjectWriteError :: union {
|
||||
os.Error,
|
||||
io.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) 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
|
||||
os.close(f)
|
||||
return nil
|
||||
}
|
||||
|
||||
ProjectReadError :: union {
|
||||
os.Error,
|
||||
io.Error,
|
||||
ProjectReadErrorType,
|
||||
}
|
||||
|
||||
ProjectReadErrorType :: enum {
|
||||
FailedReadingHeader,
|
||||
BadHeader,
|
||||
VersionNeedsUpgrade,
|
||||
}
|
||||
|
||||
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))
|
||||
header := PROJECT_DATA_HEADER
|
||||
header_buffer: [len(PROJECT_DATA_HEADER)]byte
|
||||
if num, err := io.read_full(r, header_buffer[:]); err != nil {
|
||||
return ProjectReadErrorType.FailedReadingHeader
|
||||
}
|
||||
if mem.compare(transmute([]byte)header, header_buffer[:]) != 0 {
|
||||
return ProjectReadErrorType.BadHeader
|
||||
}
|
||||
_ = io.read_ptr(r, &project.version, size_of(project.matrix_count)) or_return
|
||||
if project.version != PROJECT_DATA_VERSION {
|
||||
return ProjectReadErrorType.VersionNeedsUpgrade
|
||||
}
|
||||
_ = io.read_ptr(r, &project.matrix_count, size_of(project.matrix_count)) or_return
|
||||
n := io.read_ptr(r, raw_data(project.matrices), size_of(f32) * len(project.matrices)) or_return
|
||||
return nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue