Use physfs for all file loading
This commit is contained in:
parent
1095afb510
commit
a9f007a90e
@ -7,12 +7,12 @@ import "core:io"
|
|||||||
import "core:log"
|
import "core:log"
|
||||||
import "core:math"
|
import "core:math"
|
||||||
import lg "core:math/linalg"
|
import lg "core:math/linalg"
|
||||||
import "core:os/os2"
|
|
||||||
import "core:strconv"
|
import "core:strconv"
|
||||||
import "game:debug"
|
import "game:debug"
|
||||||
import "game:halfedge"
|
import "game:halfedge"
|
||||||
import "game:physics/bvh"
|
import "game:physics/bvh"
|
||||||
import "game:physics/collision"
|
import "game:physics/collision"
|
||||||
|
import "libs:physfs"
|
||||||
import "libs:tracy"
|
import "libs:tracy"
|
||||||
import rl "vendor:raylib"
|
import rl "vendor:raylib"
|
||||||
import "vendor:raylib/rlgl"
|
import "vendor:raylib/rlgl"
|
||||||
@ -188,9 +188,9 @@ get_bvh :: proc(assetman: ^Asset_Manager, path: cstring) -> Loaded_BVH {
|
|||||||
// TODO: cache result
|
// TODO: cache result
|
||||||
// Reads a two column comma separated csv file as a curve
|
// Reads a two column comma separated csv file as a curve
|
||||||
get_curve_2d :: proc(assetman: ^Asset_Manager, path: string) -> (curve: Loaded_Curve_2D) {
|
get_curve_2d :: proc(assetman: ^Asset_Manager, path: string) -> (curve: Loaded_Curve_2D) {
|
||||||
data, err := os2.read_entire_file_from_path(path, context.temp_allocator)
|
data, err := physfs.read_entire_file(path, context.temp_allocator)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.errorf("Failed to read curve: %s", path)
|
log.errorf("Failed to read curve: %s, %v", path, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,7 +250,7 @@ get_curve_2d :: proc(assetman: ^Asset_Manager, path: string) -> (curve: Loaded_C
|
|||||||
}
|
}
|
||||||
|
|
||||||
get_convex :: proc(assetman: ^Asset_Manager, path: cstring) -> (result: Loaded_Convex) {
|
get_convex :: proc(assetman: ^Asset_Manager, path: cstring) -> (result: Loaded_Convex) {
|
||||||
bytes, err := os2.read_entire_file(string(path), context.temp_allocator)
|
bytes, err := physfs.read_entire_file(string(path), context.temp_allocator)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.errorf("error reading file %v %s", err)
|
log.errorf("error reading file %v %s", err)
|
||||||
return
|
return
|
||||||
|
36
libs/physfs/helpers.odin
Normal file
36
libs/physfs/helpers.odin
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package physfs
|
||||||
|
|
||||||
|
import "core:strings"
|
||||||
|
|
||||||
|
read_entire_file :: proc(
|
||||||
|
path: string,
|
||||||
|
allocator := context.allocator,
|
||||||
|
) -> (
|
||||||
|
data: []byte,
|
||||||
|
err: ErrorCode,
|
||||||
|
) {
|
||||||
|
pathc := strings.clone_to_cstring(path, context.temp_allocator)
|
||||||
|
file := openRead(pathc)
|
||||||
|
if file == nil {
|
||||||
|
return nil, getLastErrorCode()
|
||||||
|
}
|
||||||
|
defer close(file)
|
||||||
|
|
||||||
|
size := fileLength(file)
|
||||||
|
if size == -1 {
|
||||||
|
return nil, getLastErrorCode()
|
||||||
|
}
|
||||||
|
|
||||||
|
if size == 0 {
|
||||||
|
return nil, .OK
|
||||||
|
}
|
||||||
|
|
||||||
|
data = make([]byte, int(size), allocator)
|
||||||
|
bytes_read := readBytes(file, raw_data(data), u64(size))
|
||||||
|
if bytes_read != size {
|
||||||
|
delete_slice(data, allocator)
|
||||||
|
return nil, getLastErrorCode()
|
||||||
|
}
|
||||||
|
|
||||||
|
return data, .OK
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user