Updated game to use new scene stack.
This commit is contained in:
+14
-16
@@ -10,8 +10,7 @@ WINDOW_TITLE :: "Pong"
|
|||||||
|
|
||||||
Game :: struct {
|
Game :: struct {
|
||||||
viewport: rl.RenderTexture2D,
|
viewport: rl.RenderTexture2D,
|
||||||
scene: Scene,
|
scene_stack: [dynamic]Scene,
|
||||||
overlay_scene: Maybe(Scene),
|
|
||||||
should_close: bool,
|
should_close: bool,
|
||||||
audio: Audio_Manager,
|
audio: Audio_Manager,
|
||||||
}
|
}
|
||||||
@@ -29,22 +28,19 @@ game_init :: proc(game: ^Game) {
|
|||||||
// allocate some event capacity to stop early dynamic reallocations
|
// allocate some event capacity to stop early dynamic reallocations
|
||||||
GLOBAL_EVENTS = make([dynamic]Event, 0, 16)
|
GLOBAL_EVENTS = make([dynamic]Event, 0, 16)
|
||||||
|
|
||||||
|
game.scene_stack = make([dynamic]Scene, 0, 8)
|
||||||
game.viewport = rl.LoadRenderTexture(VIEWPORT_W, VIEWPORT_H)
|
game.viewport = rl.LoadRenderTexture(VIEWPORT_W, VIEWPORT_H)
|
||||||
game.scene = make_main_menu()
|
|
||||||
game.overlay_scene = nil
|
|
||||||
game.should_close = false
|
game.should_close = false
|
||||||
|
set_root_scene(game, make_main_menu())
|
||||||
}
|
}
|
||||||
|
|
||||||
game_update :: proc(game: ^Game) {
|
game_update :: proc(game: ^Game) {
|
||||||
dt := rl.GetFrameTime()
|
dt := rl.GetFrameTime()
|
||||||
input := poll_input()
|
input := poll_input()
|
||||||
|
|
||||||
// Pass direct pointers (^Scene) so modifications persist
|
active_scene := get_active_scene(game)
|
||||||
// only update the overlay, if it currently exists
|
if active_scene != nil {
|
||||||
if overlay, ok := &game.overlay_scene.?; ok {
|
scene_update(active_scene, game, input, dt)
|
||||||
scene_update(overlay, game, input, dt)
|
|
||||||
} else {
|
|
||||||
scene_update(&game.scene, game, input, dt)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// background music buffer streaming
|
// background music buffer streaming
|
||||||
@@ -61,12 +57,10 @@ game_render :: proc(game: ^Game) {
|
|||||||
rl.BeginTextureMode(game.viewport)
|
rl.BeginTextureMode(game.viewport)
|
||||||
rl.ClearBackground(rl.BLACK)
|
rl.ClearBackground(rl.BLACK)
|
||||||
|
|
||||||
// Render base scene
|
// @note: fine for now but probably not a good idea...
|
||||||
scene_render(&game.scene)
|
// Render all scenes in the stack from bottom to top
|
||||||
|
for i in 0 ..< len(game.scene_stack) {
|
||||||
// Render active overlay on top if present
|
scene_render(&game.scene_stack[i])
|
||||||
if overlay, ok := &game.overlay_scene.?; ok {
|
|
||||||
scene_render(overlay)
|
|
||||||
}
|
}
|
||||||
rl.EndTextureMode()
|
rl.EndTextureMode()
|
||||||
|
|
||||||
@@ -83,6 +77,10 @@ game_quit :: proc(game: ^Game) {
|
|||||||
// cleanup global managers
|
// cleanup global managers
|
||||||
audio_manager_quit(&game.audio)
|
audio_manager_quit(&game.audio)
|
||||||
|
|
||||||
|
rl.UnloadRenderTexture(game.viewport)
|
||||||
|
delete(GLOBAL_EVENTS)
|
||||||
|
delete(game.scene_stack)
|
||||||
|
|
||||||
rl.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user