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