Introduce Game_API and move model loading example to game
This commit is contained in:
+43
-6
@@ -8,6 +8,7 @@ package game
|
||||
|
||||
import "core:fmt"
|
||||
import "core:time"
|
||||
import "sindri:platform"
|
||||
|
||||
import "sindri:base"
|
||||
import "sindri:core"
|
||||
@@ -30,8 +31,11 @@ Test_Memory :: struct {
|
||||
g: Game_Memory
|
||||
t: Test_Memory
|
||||
|
||||
engine: ^core.Engine_API
|
||||
|
||||
game_api := core.Game_API {
|
||||
settings = settings,
|
||||
register_api = register_api,
|
||||
register_memory = register_memory,
|
||||
init_once = init_once,
|
||||
init = init,
|
||||
@@ -61,19 +65,52 @@ settings :: proc() -> base.Settings {
|
||||
}
|
||||
}
|
||||
|
||||
register_api :: proc(api: ^core.Engine_API) {
|
||||
engine = api
|
||||
}
|
||||
|
||||
register_memory :: proc() {
|
||||
base.register_region("game_memory", &g, size_of(Game_Memory))
|
||||
base.register_region("test_memory", &t, size_of(Test_Memory))
|
||||
}
|
||||
|
||||
init :: proc() {
|
||||
fmt.println("hello from .dll!")
|
||||
|
||||
g.should_close = false
|
||||
}
|
||||
|
||||
init_once :: proc() {
|
||||
fmt.println("init once")
|
||||
|
||||
camera := core.thing_add(engine.things)
|
||||
player := core.thing_add(engine.things)
|
||||
}
|
||||
|
||||
init :: proc() {
|
||||
fmt.println("hello from the game!")
|
||||
|
||||
g.should_close = false
|
||||
|
||||
cube_ref := core.asset_load_model(engine.assets, "assets/cube.obj")
|
||||
suzanne_ref := core.asset_load_model(engine.assets, "assets/suzanne.obj")
|
||||
|
||||
cube := core.asset_get(engine.assets, cube_ref).data.(core.Model)
|
||||
suzanne := core.asset_get(engine.assets, suzanne_ref).data.(core.Model)
|
||||
|
||||
platform.create_material("dummy")
|
||||
platform.create_renderable(
|
||||
"assets/cube.obj",
|
||||
cube.vertices,
|
||||
cube.indices,
|
||||
0,
|
||||
)
|
||||
platform.create_renderable(
|
||||
"assets/suzanne.obj",
|
||||
suzanne.vertices,
|
||||
suzanne.indices,
|
||||
3,
|
||||
)
|
||||
platform.create_renderable(
|
||||
"assets/suzanne.obj",
|
||||
suzanne.vertices,
|
||||
suzanne.indices,
|
||||
-3,
|
||||
)
|
||||
}
|
||||
|
||||
update :: proc(dt: f32) {
|
||||
|
||||
@@ -11,8 +11,16 @@ import "sindri:base"
|
||||
// -----------------------------------------
|
||||
// Types
|
||||
|
||||
// API for when the Game talks to the Engine.
|
||||
Engine_API :: struct {
|
||||
assets: ^Assets,
|
||||
things: ^Things,
|
||||
}
|
||||
|
||||
// API for when the Engine talks to the Game.
|
||||
Game_API :: struct {
|
||||
settings: proc() -> base.Settings,
|
||||
register_api: proc(api: ^Engine_API),
|
||||
register_memory: proc(),
|
||||
init_once: proc(),
|
||||
init: proc(),
|
||||
|
||||
+10
-41
@@ -66,28 +66,32 @@ main :: proc() {
|
||||
// Large Array of Things
|
||||
things := new(core.Things, allocator)
|
||||
defer free(things, allocator)
|
||||
camera := core.thing_add(things)
|
||||
|
||||
// Register engine API
|
||||
engine_api := core.Engine_API {
|
||||
assets = &assets,
|
||||
things = things,
|
||||
}
|
||||
api.register_api(&engine_api)
|
||||
|
||||
// Register memory regions
|
||||
base.register_region("assets", cast(rawptr)&assets, size_of(core.Assets))
|
||||
base.register_region("things", things, size_of(core.Things))
|
||||
api.register_memory()
|
||||
|
||||
// Init
|
||||
// Read memory snapshot
|
||||
fresh, err := base.read_snapshot()
|
||||
fmt.assertf(err == nil, "[main] failed to read snapshot", err)
|
||||
assets.allocator = allocator
|
||||
api.init()
|
||||
|
||||
// Init once
|
||||
// Init
|
||||
if fresh {
|
||||
api.init_once()
|
||||
load_test_model(&assets) // tmp
|
||||
}
|
||||
else {
|
||||
core.asset_reload_after_hot_reload(&assets, "assets")
|
||||
}
|
||||
upload_test_model(&assets) // tmp
|
||||
api.init()
|
||||
|
||||
dt: f64
|
||||
gt: f64
|
||||
@@ -128,38 +132,3 @@ test :: proc(e: ^base.Key_Press_Event, _: rawptr) -> bool {
|
||||
fmt.println("main: @@@@@@@@@@@", e)
|
||||
return true
|
||||
}
|
||||
|
||||
// Load model from disk and upload it
|
||||
load_test_model :: proc(a: ^core.Assets) {
|
||||
cube_ref := core.asset_load_model(a, "assets/cube.obj")
|
||||
suzanne_ref := core.asset_load_model(a, "assets/suzanne.obj")
|
||||
}
|
||||
|
||||
// Load model from disk and upload it
|
||||
upload_test_model :: proc(a: ^core.Assets) {
|
||||
cube_ref := core.asset_load_model(a, "assets/cube.obj")
|
||||
suzanne_ref := core.asset_load_model(a, "assets/suzanne.obj")
|
||||
|
||||
cube := core.asset_get(a, cube_ref).data.(core.Model)
|
||||
suzanne := core.asset_get(a, suzanne_ref).data.(core.Model)
|
||||
|
||||
platform.create_material("dummy")
|
||||
platform.create_renderable(
|
||||
"assets/cube.obj",
|
||||
cube.vertices,
|
||||
cube.indices,
|
||||
0,
|
||||
)
|
||||
platform.create_renderable(
|
||||
"assets/suzanne.obj",
|
||||
suzanne.vertices,
|
||||
suzanne.indices,
|
||||
3,
|
||||
)
|
||||
platform.create_renderable(
|
||||
"assets/suzanne.obj",
|
||||
suzanne.vertices,
|
||||
suzanne.indices,
|
||||
-3,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user