Inital boiler plate commit.
Initial setup done, debug mode, build script, simple entry point, simple game manager setup. Ideal starting point for my games.
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
out/
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Find the odin binary
|
||||||
|
export PATH="$HOME/.odin:$PATH"
|
||||||
|
|
||||||
|
SRC_DIR="src"
|
||||||
|
OUT_DIR="out"
|
||||||
|
OUT_NAME="pong"
|
||||||
|
|
||||||
|
BUILD_ONLY=0
|
||||||
|
OPTIMIZED=0
|
||||||
|
WEB=0
|
||||||
|
CLEAN=0
|
||||||
|
DEBUGGER=0
|
||||||
|
VALGRIND=0
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
echo "Usage: $0 [-b] [-o] [-w] [-d] [-v] [-c] [-h]"
|
||||||
|
echo " -b build only, don't run"
|
||||||
|
echo " -o optimized release build (-o:speed, no debug info)"
|
||||||
|
echo " -w web/WASM build (js_wasm32 target)"
|
||||||
|
echo " -d build then launch in debugger instead of running"
|
||||||
|
echo " -v build then run under Valgrind"
|
||||||
|
echo " -c clean build artifacts"
|
||||||
|
echo " -h show this help"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
while getopts "bowdvch" opt; do
|
||||||
|
case $opt in
|
||||||
|
b) BUILD_ONLY=1 ;;
|
||||||
|
o) OPTIMIZED=1 ;;
|
||||||
|
w) WEB=1 ;;
|
||||||
|
d) DEBUGGER=1 ;;
|
||||||
|
v) VALGRIND=1 ;;
|
||||||
|
c) CLEAN=1 ;;
|
||||||
|
h) usage ;;
|
||||||
|
*) usage ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
mkdir -p "$OUT_DIR"
|
||||||
|
|
||||||
|
if [ "$CLEAN" -eq 1 ]; then
|
||||||
|
echo "Cleaning..."
|
||||||
|
rm -rf "${OUT_DIR:?}"/*
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$WEB" -eq 1 ]; then
|
||||||
|
echo "Building web (WASM)..."
|
||||||
|
odin build "$SRC_DIR" \
|
||||||
|
-target:js_wasm32 \
|
||||||
|
-out:"$OUT_DIR/$OUT_NAME.wasm" \
|
||||||
|
$( [ "$OPTIMIZED" -eq 1 ] && echo "-o:speed" || echo "-debug" )
|
||||||
|
|
||||||
|
# Copy the HTML shell if one exists
|
||||||
|
if [ -f "web/index_template.html" ]; then
|
||||||
|
cp web/index_template.html "$OUT_DIR/index.html"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Web build complete -> $OUT_DIR/$OUT_NAME.wasm"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$OPTIMIZED" -eq 1 ]; then
|
||||||
|
echo "Building optimized ($SRC_DIR -> $OUT_DIR/$OUT_NAME)..."
|
||||||
|
odin build "$SRC_DIR" \
|
||||||
|
-out:"$OUT_DIR/$OUT_NAME" \
|
||||||
|
-o:speed \
|
||||||
|
-no-bounds-check
|
||||||
|
else
|
||||||
|
echo "Building debug ($SRC_DIR -> $OUT_DIR/$OUT_NAME)..."
|
||||||
|
odin build "$SRC_DIR" \
|
||||||
|
-out:"$OUT_DIR/$OUT_NAME" \
|
||||||
|
-debug \
|
||||||
|
-define:DEBUG_MODE=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Build complete."
|
||||||
|
|
||||||
|
if [ "$BUILD_ONLY" -eq 0 ]; then
|
||||||
|
echo "----------------------------------------"
|
||||||
|
|
||||||
|
if [ "$DEBUGGER" -eq 1 ]; then
|
||||||
|
lldb "$OUT_DIR/$OUT_NAME"
|
||||||
|
|
||||||
|
elif [ "$VALGRIND" -eq 1 ]; then
|
||||||
|
# --show-leak-kinds=definite,possible reduces tons of noise
|
||||||
|
# still shows the leaks you actually need to fix.
|
||||||
|
# to audit whole process, temporarily switch back to --show-leak-kinds=all
|
||||||
|
valgrind \
|
||||||
|
--leak-check=full \
|
||||||
|
--show-leak-kinds=definite,possible \
|
||||||
|
--track-origins=yes \
|
||||||
|
--errors-for-leak-kinds=definite,possible \
|
||||||
|
--error-exitcode=1 \
|
||||||
|
--log-file="$OUT_DIR/valgrind.log" \
|
||||||
|
"./$OUT_DIR/$OUT_NAME"
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo "Valgrind report written to $OUT_DIR/valgrind.log"
|
||||||
|
else
|
||||||
|
"./$OUT_DIR/$OUT_NAME"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
{
|
||||||
|
"folders":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"path": "."
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"build_systems":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "Run Build Script",
|
||||||
|
"cmd": ["/bin/bash", "build.sh"],
|
||||||
|
"working_dir": "$project_path",
|
||||||
|
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
|
||||||
|
"variants":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "Run with Arguments...",
|
||||||
|
"cmd": ["/bin/bash", "build.sh", "$select_args"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Build Only (-b)",
|
||||||
|
"cmd": ["/bin/bash", "build.sh", "-b"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Optimized (-o)",
|
||||||
|
"cmd": ["/bin/bash", "build.sh", "-o"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Debug in LLDB (-d)",
|
||||||
|
"cmd": ["/bin/bash", "build.sh", "-d"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Valgrind (-v)",
|
||||||
|
"cmd": ["/bin/bash", "build.sh", "-v"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Clean (-c)",
|
||||||
|
"cmd": ["/bin/bash", "build.sh", "-c"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,44 @@
|
|||||||
|
package game
|
||||||
|
|
||||||
|
import rl "vendor:raylib"
|
||||||
|
|
||||||
|
WINDOW_TITLE :: "Pong"
|
||||||
|
WINDOW_WIDTH :: 2560
|
||||||
|
WINDOW_HEIGHT :: 1440
|
||||||
|
|
||||||
|
State :: enum {
|
||||||
|
IN_GAME,
|
||||||
|
MENU,
|
||||||
|
LOADING,
|
||||||
|
PAUSED,
|
||||||
|
FINISHED
|
||||||
|
}
|
||||||
|
|
||||||
|
Game :: struct {
|
||||||
|
state: State
|
||||||
|
}
|
||||||
|
|
||||||
|
// @NOTE: procs ie: game_init, game should run etc is a convention to work with wasm
|
||||||
|
game_should_run :: proc() -> bool { return !rl.WindowShouldClose( )}
|
||||||
|
|
||||||
|
game_init :: proc(game: ^Game) {
|
||||||
|
rl.InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE)
|
||||||
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
|
game.state = .IN_GAME
|
||||||
|
}
|
||||||
|
|
||||||
|
game_update :: proc(game: ^Game) {
|
||||||
|
// get delta time for frame
|
||||||
|
dt := rl.GetFrameTime()
|
||||||
|
}
|
||||||
|
|
||||||
|
game_render :: proc(game: ^Game) {
|
||||||
|
rl.BeginDrawing()
|
||||||
|
rl.ClearBackground(rl.DARKGRAY)
|
||||||
|
rl.EndDrawing()
|
||||||
|
}
|
||||||
|
|
||||||
|
game_quit :: proc(game: ^Game) {
|
||||||
|
rl.CloseWindow()
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package game
|
||||||
|
|
||||||
|
import "core:log"
|
||||||
|
import "core:mem"
|
||||||
|
|
||||||
|
// compiler sets debug mode
|
||||||
|
DEBUG :: #config(DEBUG_MODE, false)
|
||||||
|
|
||||||
|
main :: proc() {
|
||||||
|
when DEBUG {
|
||||||
|
context.logger = log.create_console_logger()
|
||||||
|
defer log.destroy_console_logger(context.logger)
|
||||||
|
log.debug("--- DEBUG MODE ENABLED ---")
|
||||||
|
|
||||||
|
track: mem.Tracking_Allocator
|
||||||
|
mem.tracking_allocator_init(&track, context.allocator)
|
||||||
|
defer mem.tracking_allocator_destroy(&track)
|
||||||
|
context.allocator = mem.tracking_allocator(&track)
|
||||||
|
}
|
||||||
|
// ------------------------------------------------------
|
||||||
|
|
||||||
|
game := Game{}
|
||||||
|
|
||||||
|
game_init(&game)
|
||||||
|
|
||||||
|
for game_should_run() {
|
||||||
|
game_update(&game)
|
||||||
|
game_render(&game)
|
||||||
|
}
|
||||||
|
|
||||||
|
game_quit(&game)
|
||||||
|
|
||||||
|
// ------------------------------------------------------
|
||||||
|
// Check for any leaks!
|
||||||
|
when DEBUG {
|
||||||
|
if len(track.allocation_map) > 0 {
|
||||||
|
log.errorf("\nMEMORY LEAKS: %v allocation(s)", len(track.allocation_map))
|
||||||
|
for _, entry in track.allocation_map {
|
||||||
|
log.errorf(" %v bytes @ %v", entry.size, entry.location)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(track.bad_free_array) > 0 {
|
||||||
|
log.errorf("\nBAD FREES: %v", len(track.bad_free_array))
|
||||||
|
for entry in track.bad_free_array {
|
||||||
|
log.errorf(" %v @ %v", entry.memory, entry.location)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user