Better build and project file platform layer
This commit is contained in:
parent
db99033197
commit
2469b45694
8 changed files with 137 additions and 70 deletions
1
TODO.MD
1
TODO.MD
|
|
@ -4,3 +4,4 @@
|
||||||
- Make web build
|
- Make web build
|
||||||
- Center line
|
- Center line
|
||||||
- Zoom sensitivity
|
- Zoom sensitivity
|
||||||
|
- Web read/write
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,26 @@
|
||||||
#!/bin/bash -eu
|
#!/bin/bash -eu
|
||||||
|
|
||||||
|
EXE_NAME="Transformation Visualizer"
|
||||||
OUT_DIR="build/desktop"
|
OUT_DIR="build/desktop"
|
||||||
|
ASSETS_DIR="src/assets/"
|
||||||
|
|
||||||
|
if [[ -v 1 ]]; then
|
||||||
|
if [ "$1" = "DEBUG" ]; then
|
||||||
|
ODIN_FLAGS="-debug"
|
||||||
|
elif [ "$1" = "RELEASE" ]; then
|
||||||
|
ODIN_FLAGS="-no-bounds-check -disable-assert -o:size -extra-linker-flags:\"-Wl,--gc-sections,-s\""
|
||||||
|
elif [ "$1" = "TEST" ]; then
|
||||||
|
ODIN_FLAGS="-o:minimal -no-bounds-check -disable-assert -extra-linker-flags:\"-Wl,--gc-sections,-s\""
|
||||||
|
else
|
||||||
|
echo "Usage: <script> <DEBUG/RELEASE>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Usage: <script> <DEBUG/RELEASE>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
mkdir -p $OUT_DIR
|
mkdir -p $OUT_DIR
|
||||||
odin build . -out:$OUT_DIR/game -no-bounds-check -disable-assert -o:size -extra-linker-flags:"-Wl,--gc-sections,-s"
|
odin build src/ -out:"$OUT_DIR/$EXE_NAME" $ODIN_FLAGS
|
||||||
cp -R ./assets/ ./$OUT_DIR/
|
cp -R $ASSETS_DIR ./$OUT_DIR/
|
||||||
echo "Desktop build created in ${OUT_DIR}"
|
echo "Desktop build created in ${OUT_DIR}"
|
||||||
|
|
|
||||||
31
build_web.sh
31
build_web.sh
|
|
@ -1,9 +1,25 @@
|
||||||
#!/bin/bash -eu
|
#!/bin/bash -eu
|
||||||
|
|
||||||
# Point this to where you installed emscripten. Optional on systems that already
|
if [[ -v 1 ]]; then
|
||||||
# have `emcc` in the path.
|
if [ "$1" = "DEBUG" ]; then
|
||||||
|
ODIN_FLAGS="-debug"
|
||||||
|
elif [ "$1" = "RELEASE" ]; then
|
||||||
|
ODIN_FLAGS="-no-bounds-check -disable-assert -o:size -extra-linker-flags:\"-Wl,--gc-sections,-s\""
|
||||||
|
elif [ "$1" = "TEST" ]; then
|
||||||
|
ODIN_FLAGS="-o:minimal -extra-linker-flags:\"-Wl,--gc-sections,-s\""
|
||||||
|
else
|
||||||
|
echo "Usage: <script> <DEBUG/RELEASE>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Usage: <script> <DEBUG/RELEASE>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
RAYLIB_PATH="src/libraries/raylib"
|
||||||
EMSCRIPTEN_SDK_DIR="$HOME/programs/emsdk"
|
EMSCRIPTEN_SDK_DIR="$HOME/programs/emsdk"
|
||||||
OUT_DIR="build/web"
|
OUT_DIR="build/web"
|
||||||
|
WASM_OBJ_NAME="transformation_visulalizer.wasm.obj"
|
||||||
|
|
||||||
mkdir -p $OUT_DIR
|
mkdir -p $OUT_DIR
|
||||||
|
|
||||||
|
|
@ -15,23 +31,22 @@ export EMSDK_QUIET=1
|
||||||
#
|
#
|
||||||
# The emcc call will be fed the actual raylib library file. That stuff will end
|
# The emcc call will be fed the actual raylib library file. That stuff will end
|
||||||
# up in env.o
|
# up in env.o
|
||||||
#
|
ODIN_DEFINES="-define:RAYLIB_WASM_LIB=env.o -define:RAYGUI_WASM_LIB=env.o"
|
||||||
# Note that there is a rayGUI equivalent: -define:RAYGUI_WASM_LIB=env.o
|
odin build src/ -target:js_wasm32 -build-mode:obj $ODIN_DEFINES $ODIN_FLAGS -out:$OUT_DIR/$WASM_OBJ_NAME
|
||||||
odin build . -target:js_wasm32 -build-mode:obj -define:RAYLIB_WASM_LIB=env.o -define:RAYGUI_WASM_LIB=env.o -vet -strict-style -out:$OUT_DIR/game.wasm.obj
|
|
||||||
|
|
||||||
ODIN_PATH=$(odin root)
|
ODIN_PATH=$(odin root)
|
||||||
|
|
||||||
cp $ODIN_PATH/core/sys/wasm/js/odin.js $OUT_DIR
|
cp $ODIN_PATH/core/sys/wasm/js/odin.js $OUT_DIR
|
||||||
|
|
||||||
files="$OUT_DIR/game.wasm.obj libraries/raylib/wasm/libraylib.a libraries/raylib/wasm/libraygui.a"
|
files="$OUT_DIR/$WASM_OBJ_NAME $RAYLIB_PATH/wasm/libraylib.a $RAYLIB_PATH/wasm/libraygui.a"
|
||||||
|
|
||||||
# index_template.html contains the javascript code that calls the procedures in
|
# index_template.html contains the javascript code that calls the procedures in
|
||||||
# source/main_web/main_web.odin
|
# source/main_web/main_web.odin
|
||||||
flags="-Oz -sASSERTIONS=0 --closure 0 -sEXPORTED_RUNTIME_METHODS=['HEAPF32'] -sUSE_GLFW=3 -sWASM_BIGINT -sWARN_ON_UNDEFINED_SYMBOLS=0 -sDECLARE_ASM_MODULE_EXPORTS=0 --shell-file index_template.html --preload-file assets"
|
flags="-Oz -sASSERTIONS=0 --closure 0 -sEXPORTED_RUNTIME_METHODS=['HEAPF32'] -sUSE_GLFW=3 -sWASM_BIGINT -sWARN_ON_UNDEFINED_SYMBOLS=0 -sDECLARE_ASM_MODULE_EXPORTS=0 --shell-file index_template.html --preload-file src/assets"
|
||||||
|
|
||||||
# For debugging: Add `-g` to `emcc` (gives better error callstack in chrome)
|
# For debugging: Add `-g` to `emcc` (gives better error callstack in chrome)
|
||||||
emcc -o $OUT_DIR/index.html $files $flags
|
emcc -o $OUT_DIR/index.html $files $flags
|
||||||
|
|
||||||
rm $OUT_DIR/game.wasm.obj
|
rm -f $OUT_DIR/$WASM_OBJ_NAME
|
||||||
|
|
||||||
echo "Web build created in ${OUT_DIR}"
|
echo "Web build created in ${OUT_DIR}"
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import rl "libraries/raylib"
|
import rl "libraries/raylib"
|
||||||
import "libraries/back"
|
|
||||||
import "core:log"
|
import "core:log"
|
||||||
|
|
||||||
main :: proc() {
|
main :: proc() {
|
||||||
|
|
@ -9,8 +8,8 @@ main :: proc() {
|
||||||
// exe_dir := filepath.dir(string(exe_path))
|
// exe_dir := filepath.dir(string(exe_path))
|
||||||
// os.set_working_directory(exe_dir)
|
// os.set_working_directory(exe_dir)
|
||||||
rl.ChangeDirectory(rl.GetApplicationDirectory())
|
rl.ChangeDirectory(rl.GetApplicationDirectory())
|
||||||
back.register_segfault_handler()
|
// back.register_segfault_handler()
|
||||||
context.assertion_failure_proc = back.assertion_failure_proc
|
// context.assertion_failure_proc = back.assertion_failure_proc
|
||||||
register_illegal_instruction_handler()
|
register_illegal_instruction_handler()
|
||||||
|
|
||||||
context.logger = log.create_console_logger()
|
context.logger = log.create_console_logger()
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,5 @@
|
||||||
package main
|
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_HEADER :: "WOWOWOW THIS IS HEADER WOWOWOW"
|
||||||
PROJECT_DATA_VERSION :: 1
|
PROJECT_DATA_VERSION :: 1
|
||||||
|
|
||||||
|
|
@ -21,55 +11,10 @@ ProjectData :: struct {
|
||||||
animation: Animation,
|
animation: Animation,
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectWriteError :: union {
|
|
||||||
os.Error,
|
|
||||||
io.Error,
|
|
||||||
}
|
|
||||||
|
|
||||||
project_write :: proc(project: ^ProjectData, path: string) -> ProjectWriteError {
|
project_write :: proc(project: ^ProjectData, path: string) -> ProjectWriteError {
|
||||||
f := os.open(path, {.Create, .Trunc, .Write}) or_return
|
return _project_write(project, path)
|
||||||
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 {
|
project_read :: proc(project: ^ProjectData, path: string) -> ProjectReadError {
|
||||||
f := os.open(path, {.Read}) or_return
|
return _project_read(project, path)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
61
src/project_default.odin
Normal file
61
src/project_default.odin
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
#+build !wasm32
|
||||||
|
#+build !wasm64p32
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "core:os"
|
||||||
|
import "core:io"
|
||||||
|
import "core:mem"
|
||||||
|
|
||||||
|
ProjectReadErrorType :: enum {
|
||||||
|
FailedReadingHeader,
|
||||||
|
BadHeader,
|
||||||
|
VersionNeedsUpgrade,
|
||||||
|
}
|
||||||
|
|
||||||
|
ProjectWriteError :: union {
|
||||||
|
os.Error,
|
||||||
|
io.Error,
|
||||||
|
}
|
||||||
|
|
||||||
|
ProjectReadError :: union {
|
||||||
|
os.Error,
|
||||||
|
io.Error,
|
||||||
|
ProjectReadErrorType,
|
||||||
|
}
|
||||||
|
|
||||||
|
_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
|
||||||
|
}
|
||||||
|
|
||||||
|
_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
|
||||||
|
}
|
||||||
26
src/project_web.odin
Normal file
26
src/project_web.odin
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
#+build wasm32, wasm64p32
|
||||||
|
package main
|
||||||
|
|
||||||
|
ProjectReadErrorType :: enum {
|
||||||
|
LoadingProjectNotSupportedOnWeb,
|
||||||
|
}
|
||||||
|
|
||||||
|
ProjectWriteErrorType :: enum {
|
||||||
|
SavingProjectNotSupportedOnWeb,
|
||||||
|
}
|
||||||
|
|
||||||
|
ProjectWriteError :: union {
|
||||||
|
ProjectWriteErrorType,
|
||||||
|
}
|
||||||
|
|
||||||
|
ProjectReadError :: union {
|
||||||
|
ProjectReadErrorType,
|
||||||
|
}
|
||||||
|
|
||||||
|
_project_write :: proc(project: ^ProjectData, path: string) -> ProjectWriteError {
|
||||||
|
return ProjectWriteErrorType.SavingProjectNotSupportedOnWeb;
|
||||||
|
}
|
||||||
|
|
||||||
|
_project_read :: proc(project: ^ProjectData, path: string) -> ProjectReadError {
|
||||||
|
return ProjectReadErrorType.LoadingProjectNotSupportedOnWeb;
|
||||||
|
}
|
||||||
1
test_web.sh
Executable file
1
test_web.sh
Executable file
|
|
@ -0,0 +1 @@
|
||||||
|
python3 -m http.server --directory build/web
|
||||||
Loading…
Add table
Add a link
Reference in a new issue