Skip to content

Commit 59d815c

Browse files
committed
Renamed main
1 parent 0148859 commit 59d815c

File tree

10 files changed

+48
-45
lines changed

10 files changed

+48
-45
lines changed

src/JulGame.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ module JulGame
7171
using .SceneManagement
7272
export SceneBuilderModule, SceneLoaderModule, SceneReaderModule, SceneWriterModule
7373

74-
include("Main.jl")
75-
using .MainLoop: Main
76-
export Main
74+
include("MainLoop.jl")
75+
using .MainLoopModule: MainLoop
76+
export MainLoop
7777
end

src/Main.jl renamed to src/MainLoop.jl

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module MainLoop
1+
module MainLoopModule
22
using ..JulGame
33
using ..JulGame: Camera, Component, Input, Math, UI, SceneModule
44
import ..JulGame: Component
@@ -8,8 +8,8 @@ module MainLoop
88
include("utils/Enums.jl")
99
include("utils/Constants.jl")
1010

11-
export Main
12-
mutable struct Main
11+
export MainLoop
12+
mutable struct MainLoop
1313
assets::String
1414
autoScaleZoom::Bool
1515
close::Bool
@@ -36,8 +36,8 @@ module MainLoop
3636
windowName::String
3737
zoom::Float64
3838

39-
function Main(zoom::Float64 = 1.0)
40-
this::Main = new()
39+
function MainLoop(zoom::Float64 = 1.0)
40+
this::MainLoop = new()
4141

4242
SDL2.init()
4343

@@ -82,7 +82,7 @@ module MainLoop
8282
end
8383
end
8484

85-
function initialize_new_scene(this::Main)
85+
function initialize_new_scene(this::MainLoop)
8686
@debug "Initializing new scene"
8787
@debug "Deserializing and building scene"
8888
SceneBuilderModule.deserialize_and_build_scene(this.level)
@@ -96,15 +96,15 @@ module MainLoop
9696
end
9797
end
9898

99-
function reset_camera_position(this::Main)
99+
function reset_camera_position(this::MainLoop)
100100
@debug "Resetting camera position"
101101
if this.scene.camera === nothing return end
102102

103103
cameraPosition = Math.Vector2f()
104104
JulGame.CameraModule.update(this.scene.camera, cameraPosition)
105105
end
106106

107-
function full_loop(this::Main)
107+
function full_loop(this::MainLoop)
108108
try
109109
this.close = false
110110
startTime = Ref(UInt64(0))
@@ -162,22 +162,22 @@ module MainLoop
162162
end
163163
end
164164

165-
function create_new_entity(this::Main)
165+
function create_new_entity(this::MainLoop)
166166
@debug "Creating new entity"
167167
SceneBuilderModule.create_new_entity(this.level)
168168
end
169169

170-
function create_new_text_box(this::Main)
170+
function create_new_text_box(this::MainLoop)
171171
@debug "Creating new text box"
172172
SceneBuilderModule.create_new_text_box(this.level)
173173
end
174174

175-
function create_new_screen_button(this::Main)
175+
function create_new_screen_button(this::MainLoop)
176176
@debug "Creating new screen button"
177177
SceneBuilderModule.create_new_screen_button(this.level)
178178
end
179179

180-
function update_viewport(this::Main, x,y)
180+
function update_viewport(this::MainLoop, x,y)
181181
@debug "Updating viewport"
182182
if !this.autoScaleZoom
183183
return
@@ -195,7 +195,7 @@ module MainLoop
195195
SDL2.SDL_RenderSetScale(JulGame.Renderer::Ptr{SDL2.SDL_Renderer}, this.zoom, this.zoom)
196196
end
197197

198-
function scale_zoom(this::Main, x,y)
198+
function scale_zoom(this::MainLoop, x,y)
199199
@debug "Scaling zoom"
200200
if this.scene.camera === nothing
201201
return
@@ -226,7 +226,7 @@ module MainLoop
226226
end
227227

228228
function prepare_window(size = C_NULL, isResizable::Bool = false, autoScaleZoom::Bool = true)
229-
this::Main = MAIN
229+
this::MainLoop = MAIN
230230
this.autoScaleZoom = autoScaleZoom
231231
scale_zoom(this, size.x, size.y)
232232

@@ -243,7 +243,7 @@ module MainLoop
243243
end
244244

245245
function initialize_scripts_and_components()
246-
this::Main = MAIN
246+
this::MainLoop = MAIN
247247
scripts = []
248248
for entity in this.scene.entities
249249
for script in entity.scripts
@@ -308,7 +308,7 @@ Change the scene to the specified `sceneFileName`. This function destroys the cu
308308
- `sceneFileName::String`: The name of the scene file to load.
309309
"""
310310
function JulGame.change_scene(sceneFileName::String)
311-
this::Main = MAIN
311+
this::MainLoop = MAIN
312312
@debug "Changing scene to: $(sceneFileName)"
313313
this.close = true
314314
this.shouldChangeScene = true
@@ -419,7 +419,7 @@ Destroy the specified entity. This removes the entity's sprite from the sprite l
419419
# Arguments
420420
- `entity`: The entity to be destroyed.
421421
"""
422-
function JulGame.destroy_entity(this::Main, entity)
422+
function JulGame.destroy_entity(this::MainLoop, entity)
423423
for i = eachindex(this.scene.entities)
424424
if this.scene.entities[i] == entity
425425
destroy_entity_components(this, entity)
@@ -430,7 +430,7 @@ function JulGame.destroy_entity(this::Main, entity)
430430
end
431431
end
432432

433-
function JulGame.destroy_ui_element(this::Main, uiElement)
433+
function JulGame.destroy_ui_element(this::MainLoop, uiElement)
434434
for i = eachindex(this.scene.uiElements)
435435
if this.scene.uiElements[i] == uiElement
436436
deleteat!(this.scene.uiElements, i)
@@ -440,7 +440,7 @@ function JulGame.destroy_ui_element(this::Main, uiElement)
440440
end
441441
end
442442

443-
function destroy_entity_components(this::Main, entity)
443+
function destroy_entity_components(this::MainLoop, entity)
444444
entitySprite = entity.sprite
445445
if entitySprite != C_NULL
446446
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
489489
490490
"""
491491
function JulGame.create_entity(entity)
492-
this::Main = MAIN
492+
this::MainLoop = MAIN
493493
push!(this.scene.entities, entity)
494494
if entity.sprite != C_NULL
495495
if !haskey(this.spriteLayers, "$(entity.sprite.layer)")
@@ -513,7 +513,7 @@ function JulGame.create_entity(entity)
513513
end
514514

515515
"""
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)
517517
518518
Runs the game loop.
519519
@@ -522,7 +522,7 @@ Parameters:
522522
- `startTime`: A reference to the start time of the game loop.
523523
- `lastPhysicsTime`: A reference to the last physics time of the game loop.
524524
"""
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))
526526
if this.shouldChangeScene && !JulGame.IS_EDITOR
527527
this.shouldChangeScene = false
528528
initialize_new_scene(this)
@@ -674,7 +674,7 @@ function game_loop(this::Main, startTime::Ref{UInt64} = Ref(UInt64(0)), lastPhys
674674
end
675675
end
676676

677-
function render_scene_sprites_and_shapes(this::Main, camera::Camera)
677+
function render_scene_sprites_and_shapes(this::MainLoop, camera::Camera)
678678
cameraPosition = camera !== nothing ? camera.position : Math.Vector2f(0,0)
679679
cameraSize = camera !== nothing ? camera.size : Math.Vector2(0,0)
680680

@@ -731,21 +731,21 @@ function game_loop(this::Main, startTime::Ref{UInt64} = Ref(UInt64(0)), lastPhys
731731
end
732732
end
733733

734-
function start_game_in_editor(this::Main, path::String)
734+
function start_game_in_editor(this::MainLoop, path::String)
735735
this.isGameModeRunningInEditor = true
736736
SceneBuilderModule.add_scripts_to_entities(path)
737737
initialize_scripts_and_components()
738738
end
739739

740-
function stop_game_in_editor(this::Main)
740+
function stop_game_in_editor(this::MainLoop)
741741
this.isGameModeRunningInEditor = false
742742
SDL2.Mix_HaltMusic()
743743
if this.scene.camera !== nothing && this.scene.camera != C_NULL
744744
this.scene.camera.target = C_NULL
745745
end
746746
end
747747

748-
function render_scene_debug(this::Main, cameraPosition, cameraSize, DEBUG)
748+
function render_scene_debug(this::MainLoop, cameraPosition, cameraSize, DEBUG)
749749
colliderSkipCount = 0
750750
colliderRenderCount = 0
751751
for entity in this.scene.entities

src/editor/JulGameEditor/Editor.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Editor
77
using CImGui: ImVec2, ImVec4, IM_COL32, ImS32, ImU32, ImS64, ImU64
88
using CImGui.CImGui
99
using Dates
10-
using JulGame: Component, MainLoop, Math, SceneLoaderModule, SDL2, UI
10+
using JulGame: Component, MainLoopModule, Math, SceneLoaderModule, SDL2, UI
1111
using NativeFileDialog
1212

1313
global sdlVersion = "2.0.0"
@@ -252,10 +252,10 @@ module Editor
252252
sceneWindowSize = show_scene_window(currentSceneMain, sceneTexture, scrolling, zoom_level, duplicationMode, camera)
253253
if playMode != wasPlaying && currentSceneMain !== nothing
254254
if playMode
255-
JulGame.MainLoop.start_game_in_editor(currentSceneMain, currentSelectedProjectPath[])
255+
JulGame.MainLoopModule.start_game_in_editor(currentSceneMain, currentSelectedProjectPath[])
256256
currentSceneMain.scene.camera = gameCamera
257257
elseif !playMode
258-
JulGame.MainLoop.stop_game_in_editor(currentSceneMain)
258+
JulGame.MainLoopModule.stop_game_in_editor(currentSceneMain)
259259
JulGame.change_scene(String(currentSceneName))
260260
end
261261
end
@@ -295,7 +295,7 @@ module Editor
295295
CImGui.MenuItem("Add", C_NULL, false, false)
296296
if CImGui.BeginMenu("New")
297297
if CImGui.MenuItem("Entity")
298-
JulGame.MainLoop.create_new_entity(currentSceneMain)
298+
JulGame.MainLoopModule.create_new_entity(currentSceneMain)
299299
end
300300

301301
CImGui.EndMenu()
@@ -345,10 +345,10 @@ module Editor
345345
CImGui.MenuItem("Add", C_NULL, false, false)
346346
if CImGui.BeginMenu("New")
347347
if CImGui.MenuItem("TextBox")
348-
JulGame.MainLoop.create_new_text_box(currentSceneMain)
348+
JulGame.MainLoopModule.create_new_text_box(currentSceneMain)
349349
end
350350
if CImGui.MenuItem("Screen Button")
351-
JulGame.MainLoop.create_new_screen_button(currentSceneMain)
351+
JulGame.MainLoopModule.create_new_screen_button(currentSceneMain)
352352
end
353353

354354
CImGui.EndMenu()
@@ -479,7 +479,7 @@ module Editor
479479
SDL2.SDL_RenderClear(renderer)
480480
try
481481
if currentSceneMain !== nothing
482-
JulGame.MainLoop.render_scene_sprites_and_shapes(currentSceneMain, camera)
482+
JulGame.MainLoopModule.render_scene_sprites_and_shapes(currentSceneMain, camera)
483483
end
484484
catch e
485485
handle_editor_exceptions("Scene window:", latest_exceptions, e, is_test_mode)
@@ -490,14 +490,14 @@ module Editor
490490
try
491491
if currentSceneMain !== nothing
492492
JulGame.CameraModule.update(gameCamera)
493-
JulGame.MainLoop.render_scene_sprites_and_shapes(currentSceneMain, gameCamera)
493+
JulGame.MainLoopModule.render_scene_sprites_and_shapes(currentSceneMain, gameCamera)
494494
end
495495
catch e
496496
handle_editor_exceptions("Game window:", latest_exceptions, e, is_test_mode)
497497
end
498498

499499
try
500-
gameInfo = currentSceneMain === nothing ? [] : JulGame.MainLoop.game_loop(currentSceneMain, startTime, lastPhysicsTime, Math.Vector2(sceneWindowPos.x + 8, sceneWindowPos.y + 25), Math.Vector2(sceneWindowSize.x, sceneWindowSize.y)) # Magic numbers for the border of the imgui window. TODO: Make this dynamic if possible
500+
gameInfo = currentSceneMain === nothing ? [] : JulGame.MainLoopModule.game_loop(currentSceneMain, startTime, lastPhysicsTime, Math.Vector2(sceneWindowPos.x + 8, sceneWindowPos.y + 25), Math.Vector2(sceneWindowSize.x, sceneWindowSize.y)) # Magic numbers for the border of the imgui window. TODO: Make this dynamic if possible
501501
catch e
502502
handle_editor_exceptions("Game loop:", latest_exceptions, e, is_test_mode)
503503
end

src/editor/JulGameEditor/Utils/FileContents.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function mainFileContent(projectName)
4343
4444
function run()
4545
scene = SceneBuilderModule.Scene(\"scene.json\")
46-
SceneBuilderModule.load_and_prepare_scene(JulGame.Main(Float64(1.0));this=scene)
46+
SceneBuilderModule.load_and_prepare_scene(JulGame.MainLoop(Float64(1.0));this=scene)
4747
end
4848
4949
julia_main() = run()

src/engine/3D/example3d.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ function main()
139139
println( "Failed to initialize!\n" )
140140
else
141141

142-
#Main loop flag
142+
#MainLoop loop flag
143143
quit = false
144144

145145
#Event handler

src/engine/Input/Input.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ module InputModule
117117

118118
insideAnyButton = false
119119
for uiElement in MAIN.scene.uiElements
120+
if !uiElement.isActive
121+
return
122+
end
120123
# Check position of button to see which we are interacting with
121124
eventWasInsideThisButton = true
122125
if x[1] < uiElement.position.x + MAIN.scene.camera.startingCoordinates.x
@@ -253,7 +256,7 @@ module InputModule
253256
elseif windowEvent == SDL2.SDL_WINDOWEVENT_RESIZED # todo: update zoom and viewport size here
254257
if !JulGame.IS_EDITOR
255258
@debug(string("Window $(event.window.windowID) resized to $(event.window.data1)x$(event.window.data2)"))
256-
JulGame.MainLoop.update_viewport(MAIN, event.window.data1, event.window.data2)
259+
JulGame.MainLoopModule.update_viewport(MAIN, event.window.data1, event.window.data2)
257260
end
258261
elseif windowEvent == SDL2.SDL_WINDOWEVENT_SIZE_CHANGED
259262
@debug(string("Window $(event.window.windowID) size changed to $(event.window.data1)x$(event.window.data2)"))

src/engine/SceneManagement/SceneBuilder.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ module SceneBuilderModule
158158
add_scripts_to_entities(BasePath)
159159

160160
MAIN.assets = joinpath(BasePath, "assets")
161-
JulGame.MainLoop.prepare_window_scripts_and_start_loop(size, isResizable, autoScaleZoom)
161+
JulGame.MainLoopModule.prepare_window_scripts_and_start_loop(size, isResizable, autoScaleZoom)
162162
end
163163

164164
function deserialize_and_build_scene(this::Scene)

src/engine/SceneManagement/SceneLoader.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module SceneLoaderModule
4949
@debug ("Loading scene $sceneFileName from $projectPath")
5050
scene = Scene("$sceneFileName", "$projectPath")
5151

52-
SceneBuilderModule.load_and_prepare_scene(JulGame.Main(Float64(1.0)); this=scene)
52+
SceneBuilderModule.load_and_prepare_scene(JulGame.MainLoop(Float64(1.0)); this=scene)
5353

5454
return MAIN
5555
end

test/projects/ProfilingTest/Platformer/src/Platformer.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module PlatformerModule
22
using JulGame
33
function run_platformer()
4-
JulGame.MAIN = JulGame.Main(Float64(1.0))
4+
JulGame.MAIN = JulGame.MainLoop(Float64(1.0))
55
MAIN.testMode = true
66
MAIN.testLength = 30.0
77
MAIN.currentTestTime = 0.0

test/projects/SmokeTest/src/SmokeTest.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module SmokeTest
22
using JulGame
33
function run(SMOKETESTDIR, Test)
4-
JulGame.MAIN = JulGame.Main(Float64(1.0))
4+
JulGame.MAIN = JulGame.MainLoop(Float64(1.0))
55
MAIN.testMode = true
66
MAIN.testLength = 10.0
77
MAIN.currentTestTime = 0.0

0 commit comments

Comments
 (0)