1
- module MainLoop
1
+ module MainLoopModule
2
2
using .. JulGame
3
3
using .. JulGame: Camera, Component, Input, Math, UI, SceneModule
4
4
import .. JulGame: Component
@@ -8,8 +8,8 @@ module MainLoop
8
8
include (" utils/Enums.jl" )
9
9
include (" utils/Constants.jl" )
10
10
11
- export Main
12
- mutable struct Main
11
+ export MainLoop
12
+ mutable struct MainLoop
13
13
assets:: String
14
14
autoScaleZoom:: Bool
15
15
close:: Bool
@@ -36,8 +36,8 @@ module MainLoop
36
36
windowName:: String
37
37
zoom:: Float64
38
38
39
- function Main (zoom:: Float64 = 1.0 )
40
- this:: Main = new ()
39
+ function MainLoop (zoom:: Float64 = 1.0 )
40
+ this:: MainLoop = new ()
41
41
42
42
SDL2. init ()
43
43
@@ -82,7 +82,7 @@ module MainLoop
82
82
end
83
83
end
84
84
85
- function initialize_new_scene (this:: Main )
85
+ function initialize_new_scene (this:: MainLoop )
86
86
@debug " Initializing new scene"
87
87
@debug " Deserializing and building scene"
88
88
SceneBuilderModule. deserialize_and_build_scene (this. level)
@@ -96,15 +96,15 @@ module MainLoop
96
96
end
97
97
end
98
98
99
- function reset_camera_position (this:: Main )
99
+ function reset_camera_position (this:: MainLoop )
100
100
@debug " Resetting camera position"
101
101
if this. scene. camera === nothing return end
102
102
103
103
cameraPosition = Math. Vector2f ()
104
104
JulGame. CameraModule. update (this. scene. camera, cameraPosition)
105
105
end
106
106
107
- function full_loop (this:: Main )
107
+ function full_loop (this:: MainLoop )
108
108
try
109
109
this. close = false
110
110
startTime = Ref (UInt64 (0 ))
@@ -162,22 +162,22 @@ module MainLoop
162
162
end
163
163
end
164
164
165
- function create_new_entity (this:: Main )
165
+ function create_new_entity (this:: MainLoop )
166
166
@debug " Creating new entity"
167
167
SceneBuilderModule. create_new_entity (this. level)
168
168
end
169
169
170
- function create_new_text_box (this:: Main )
170
+ function create_new_text_box (this:: MainLoop )
171
171
@debug " Creating new text box"
172
172
SceneBuilderModule. create_new_text_box (this. level)
173
173
end
174
174
175
- function create_new_screen_button (this:: Main )
175
+ function create_new_screen_button (this:: MainLoop )
176
176
@debug " Creating new screen button"
177
177
SceneBuilderModule. create_new_screen_button (this. level)
178
178
end
179
179
180
- function update_viewport (this:: Main , x,y)
180
+ function update_viewport (this:: MainLoop , x,y)
181
181
@debug " Updating viewport"
182
182
if ! this. autoScaleZoom
183
183
return
@@ -195,7 +195,7 @@ module MainLoop
195
195
SDL2. SDL_RenderSetScale (JulGame. Renderer:: Ptr{SDL2.SDL_Renderer} , this. zoom, this. zoom)
196
196
end
197
197
198
- function scale_zoom (this:: Main , x,y)
198
+ function scale_zoom (this:: MainLoop , x,y)
199
199
@debug " Scaling zoom"
200
200
if this. scene. camera === nothing
201
201
return
@@ -226,7 +226,7 @@ module MainLoop
226
226
end
227
227
228
228
function prepare_window (size = C_NULL , isResizable:: Bool = false , autoScaleZoom:: Bool = true )
229
- this:: Main = MAIN
229
+ this:: MainLoop = MAIN
230
230
this. autoScaleZoom = autoScaleZoom
231
231
scale_zoom (this, size. x, size. y)
232
232
@@ -243,7 +243,7 @@ module MainLoop
243
243
end
244
244
245
245
function initialize_scripts_and_components ()
246
- this:: Main = MAIN
246
+ this:: MainLoop = MAIN
247
247
scripts = []
248
248
for entity in this. scene. entities
249
249
for script in entity. scripts
@@ -308,7 +308,7 @@ Change the scene to the specified `sceneFileName`. This function destroys the cu
308
308
- `sceneFileName::String`: The name of the scene file to load.
309
309
"""
310
310
function JulGame. change_scene (sceneFileName:: String )
311
- this:: Main = MAIN
311
+ this:: MainLoop = MAIN
312
312
@debug " Changing scene to: $(sceneFileName) "
313
313
this. close = true
314
314
this. shouldChangeScene = true
@@ -419,7 +419,7 @@ Destroy the specified entity. This removes the entity's sprite from the sprite l
419
419
# Arguments
420
420
- `entity`: The entity to be destroyed.
421
421
"""
422
- function JulGame. destroy_entity (this:: Main , entity)
422
+ function JulGame. destroy_entity (this:: MainLoop , entity)
423
423
for i = eachindex (this. scene. entities)
424
424
if this. scene. entities[i] == entity
425
425
destroy_entity_components (this, entity)
@@ -430,7 +430,7 @@ function JulGame.destroy_entity(this::Main, entity)
430
430
end
431
431
end
432
432
433
- function JulGame. destroy_ui_element (this:: Main , uiElement)
433
+ function JulGame. destroy_ui_element (this:: MainLoop , uiElement)
434
434
for i = eachindex (this. scene. uiElements)
435
435
if this. scene. uiElements[i] == uiElement
436
436
deleteat! (this. scene. uiElements, i)
@@ -440,7 +440,7 @@ function JulGame.destroy_ui_element(this::Main, uiElement)
440
440
end
441
441
end
442
442
443
- function destroy_entity_components (this:: Main , entity)
443
+ function destroy_entity_components (this:: MainLoop , entity)
444
444
entitySprite = entity. sprite
445
445
if entitySprite != C_NULL
446
446
for j = eachindex (this. spriteLayers[" $(entitySprite. layer) " ])
@@ -489,7 +489,7 @@ Create a new entity. Adds the entity to the main game's entities array and adds
489
489
490
490
"""
491
491
function JulGame. create_entity (entity)
492
- this:: Main = MAIN
492
+ this:: MainLoop = MAIN
493
493
push! (this. scene. entities, entity)
494
494
if entity. sprite != C_NULL
495
495
if ! haskey (this. spriteLayers, " $(entity. sprite. layer) " )
@@ -513,7 +513,7 @@ function JulGame.create_entity(entity)
513
513
end
514
514
515
515
"""
516
- game_loop(this::Main , startTime::Ref{UInt64} = Ref(UInt64(0)), lastPhysicsTime::Ref{UInt64} = Ref(UInt64(0)), close::Ref{Bool} = Ref(Bool(false)), Vector{Any}} = C_NULL)
516
+ game_loop(this::MainLoop , startTime::Ref{UInt64} = Ref(UInt64(0)), lastPhysicsTime::Ref{UInt64} = Ref(UInt64(0)), close::Ref{Bool} = Ref(Bool(false)), Vector{Any}} = C_NULL)
517
517
518
518
Runs the game loop.
519
519
@@ -522,7 +522,7 @@ Parameters:
522
522
- `startTime`: A reference to the start time of the game loop.
523
523
- `lastPhysicsTime`: A reference to the last physics time of the game loop.
524
524
"""
525
- function game_loop (this:: Main , startTime:: Ref{UInt64} = Ref (UInt64 (0 )), lastPhysicsTime:: Ref{UInt64} = Ref (UInt64 (0 )), windowPos:: Math.Vector2 = Math. Vector2 (0 ,0 ), windowSize:: Math.Vector2 = Math. Vector2 (0 ,0 ))
525
+ function game_loop (this:: MainLoop , startTime:: Ref{UInt64} = Ref (UInt64 (0 )), lastPhysicsTime:: Ref{UInt64} = Ref (UInt64 (0 )), windowPos:: Math.Vector2 = Math. Vector2 (0 ,0 ), windowSize:: Math.Vector2 = Math. Vector2 (0 ,0 ))
526
526
if this. shouldChangeScene && ! JulGame. IS_EDITOR
527
527
this. shouldChangeScene = false
528
528
initialize_new_scene (this)
@@ -674,7 +674,7 @@ function game_loop(this::Main, startTime::Ref{UInt64} = Ref(UInt64(0)), lastPhys
674
674
end
675
675
end
676
676
677
- function render_scene_sprites_and_shapes (this:: Main , camera:: Camera )
677
+ function render_scene_sprites_and_shapes (this:: MainLoop , camera:: Camera )
678
678
cameraPosition = camera != = nothing ? camera. position : Math. Vector2f (0 ,0 )
679
679
cameraSize = camera != = nothing ? camera. size : Math. Vector2 (0 ,0 )
680
680
@@ -731,21 +731,21 @@ function game_loop(this::Main, startTime::Ref{UInt64} = Ref(UInt64(0)), lastPhys
731
731
end
732
732
end
733
733
734
- function start_game_in_editor (this:: Main , path:: String )
734
+ function start_game_in_editor (this:: MainLoop , path:: String )
735
735
this. isGameModeRunningInEditor = true
736
736
SceneBuilderModule. add_scripts_to_entities (path)
737
737
initialize_scripts_and_components ()
738
738
end
739
739
740
- function stop_game_in_editor (this:: Main )
740
+ function stop_game_in_editor (this:: MainLoop )
741
741
this. isGameModeRunningInEditor = false
742
742
SDL2. Mix_HaltMusic ()
743
743
if this. scene. camera != = nothing && this. scene. camera != C_NULL
744
744
this. scene. camera. target = C_NULL
745
745
end
746
746
end
747
747
748
- function render_scene_debug (this:: Main , cameraPosition, cameraSize, DEBUG)
748
+ function render_scene_debug (this:: MainLoop , cameraPosition, cameraSize, DEBUG)
749
749
colliderSkipCount = 0
750
750
colliderRenderCount = 0
751
751
for entity in this. scene. entities
0 commit comments