Skip to content

Commit

Permalink
Remove rethrows and load scripts when package compiled
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyjor committed Feb 17, 2025
1 parent a0c7a5d commit fd634cd
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 21 deletions.
16 changes: 8 additions & 8 deletions src/MainLoop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ module MainLoopModule
if this.testMode
throw(e)
else
if JulGame.IS_EDITOR || this.testMode
if this.testMode
rethrow(e)
else
@error string(e)
Expand All @@ -133,7 +133,7 @@ module MainLoopModule
try
Base.invokelatest(JulGame.on_shutdown, script)
catch e
if JulGame.IS_EDITOR || this.testMode
if this.testMode
rethrow(e)
else
if typeof(e) != ErrorException
Expand Down Expand Up @@ -212,7 +212,7 @@ function initialize_scripts_and_components()
try
Base.invokelatest(JulGame.initialize, script)
catch e
if JulGame.IS_EDITOR || this.testMode
if this.testMode
rethrow(e)
else
@error string(e)
Expand Down Expand Up @@ -280,7 +280,7 @@ function JulGame.change_scene(sceneFileName::String)
try
Base.invokelatest(JulGame.on_shutdown, script)
catch e
if JulGame.IS_EDITOR || this.testMode
if this.testMode
rethrow(e)
else
if typeof(e) != ErrorException
Expand Down Expand Up @@ -521,7 +521,7 @@ function game_loop(this::MainLoop, startTime::Ref{UInt64} = Ref(UInt64(0)), last
try
JulGame.update(rigidbody, deltaTime)
catch e
if JulGame.IS_EDITOR || this.testMode
if this.testMode
rethrow(e)
else
println(rigidbody.parent.name, " with id: ", rigidbody.parent.id, " has a problem with it's rigidbody")
Expand Down Expand Up @@ -552,7 +552,7 @@ function game_loop(this::MainLoop, startTime::Ref{UInt64} = Ref(UInt64(0)), last
return
end
catch e
if JulGame.IS_EDITOR || this.testMode
if this.testMode
rethrow(e)
else
println(entity.name, " with id: ", entity.id, " has a problem with it's update")
Expand Down Expand Up @@ -642,7 +642,7 @@ function game_loop(this::MainLoop, startTime::Ref{UInt64} = Ref(UInt64(0)), last
return entt
end
catch e
if JulGame.IS_EDITOR || this.testMode
if this.testMode
rethrow(e)
else
@error string(e)
Expand Down Expand Up @@ -697,7 +697,7 @@ function game_loop(this::MainLoop, startTime::Ref{UInt64} = Ref(UInt64(0)), last
rendercount += 1
Component.draw(renderOrder[i][2], camera)
catch e
if JulGame.IS_EDITOR || this.testMode
if this.testMode
rethrow(e)
else
println(renderOrder[i][2].parent.name, " with id: ", renderOrder[i][2].parent.id, " has a problem with it's sprite")
Expand Down
2 changes: 0 additions & 2 deletions src/editor/JulGameEditor/Components/ComponentInputs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ function show_animator_properties(animator, animation_window_dict, animator_prev
end
end
catch e
rethrow(e)
end
end
end
Expand All @@ -290,7 +289,6 @@ function show_animator_properties(animator, animation_window_dict, animator_prev
end
end
catch e
rethrow(e)
end
end

Expand Down
4 changes: 0 additions & 4 deletions src/editor/JulGameEditor/Utils/SceneUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ function load_scene(scenePath::String)
try
game = SceneLoaderModule.load_scene_from_editor(scenePath);
catch e
rethrow(e)
end

return game
Expand Down Expand Up @@ -47,7 +46,6 @@ function get_all_scenes_from_folder(projectPath::String)
end
end
catch e
rethrow(e)
end

return sceneFiles
Expand All @@ -69,7 +67,6 @@ function get_all_scenes_from_base_folder(projectPath::String)
end
end
catch e
rethrow(e)
end

return sceneFiles
Expand Down Expand Up @@ -108,7 +105,6 @@ function load_scene(scenePath::String, renderer)
try
game = SceneLoaderModule.load_scene_from_editor(scenePath, renderer);
catch e
rethrow(e)
end

return game
Expand Down
1 change: 0 additions & 1 deletion src/engine/Entity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ module EntityModule
catch e
@error string(e)
Base.show_backtrace(stdout, catch_backtrace())
rethrow(e)
end
end

Expand Down
1 change: 0 additions & 1 deletion src/engine/Input/Input.jl
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,6 @@ end
"""
function set_cursor_with_image(this::Input, imagePath::String, x::Int, y::Int, scale_factor::Float64=1.0)
surface = nothing
println("Keys in countDict: ", collect(keys(JulGame.IMAGE_CACHE)))
if haskey(JulGame.IMAGE_CACHE, get_comma_separated_path(imagePath))
raw_data = JulGame.IMAGE_CACHE[get_comma_separated_path(imagePath)]
rw = SDL2.SDL_RWFromConstMem(pointer(raw_data), length(raw_data))
Expand Down
40 changes: 39 additions & 1 deletion src/engine/SceneManagement/SceneBuilder.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,45 @@ module SceneBuilderModule
using ..SceneReaderModule
using JSON3

function init()
if isdir(joinpath(pwd(), "..", "scripts")) #dev builds
# println("Loading scripts...")
include.(filter(contains(r".jl$"), readdir(joinpath(pwd(), "..", "scripts"); join=true)))
foreach(file -> try
Base.include(JulGame.ScriptModule, file)
catch e
println("Error including $file: ", e)
end, filter(contains(r".jl$"), readdir(joinpath(pwd(), "..", "scripts"); join=true)))
@info "Loaded scripts"
else
script_folder_name = "scripts"
current_dir = pwd()

# Find all folders in the current directory
folders = filter(isdir, readdir(current_dir))

# Check each folder for the "scripts" subfolder
for folder in folders
scripts_path = joinpath(current_dir, folder, script_folder_name)
if isdir(scripts_path)
println("Loading scripts in $scripts_path...")
include.(filter(contains(r".jl$"), readdir(scripts_path; join=true)))
foreach(file -> try
Base.include(JulGame.ScriptModule, file)
catch e
println("Error including $file: ", e)
end, filter(contains(r".jl$"), readdir(scripts_path; join=true)))
break # Exit loop if "scripts" folder is found in any parent folder
end
end
@info "Loaded scripts"
end
end

if ccall(:jl_generating_output, Cint, ()) == 1
init()
end

export Scene
mutable struct Scene
scene
Expand Down Expand Up @@ -221,7 +260,6 @@ module SceneBuilderModule
catch e
@error string(e)
Base.show_backtrace(stdout, catch_backtrace())
rethrow(e)
end
if newScript != C_NULL && newScript !== nothing
entity.scripts[scriptCounter] = newScript
Expand Down
3 changes: 0 additions & 3 deletions src/engine/SceneManagement/SceneReader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ module SceneReaderModule
catch e
@error string(e)
Base.show_backtrace(stdout, catch_backtrace())
rethrow(e)
end
end

Expand All @@ -134,7 +133,6 @@ module SceneReaderModule
catch e
@error string(e)
Base.show_backtrace(stdout, catch_backtrace())
rethrow(e)
end
end

Expand Down Expand Up @@ -195,7 +193,6 @@ module SceneReaderModule
catch e
@error string(e)
Base.show_backtrace(stdout, catch_backtrace())
rethrow(e)
end
end
end
1 change: 0 additions & 1 deletion src/engine/SceneManagement/SceneWriter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ module SceneWriterModule
catch e
@error string(e)
Base.show_backtrace(stdout, catch_backtrace())
rethrow(e)
end
end

Expand Down

0 comments on commit fd634cd

Please sign in to comment.