Skip to content

Commit c7d6dfc

Browse files
committed
cleanup and improving rigidbody
1 parent be085b9 commit c7d6dfc

File tree

9 files changed

+231
-228
lines changed

9 files changed

+231
-228
lines changed

src/Main.jl

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,10 @@ function JulGame.change_scene(sceneFileName::String)
342342
JulGame.destroy_entity(this, entity)
343343
count += 1
344344
end
345-
# println("Destroyed $count entities")
346-
# println("Skipped $skipcount entities")
345+
@debug "Destroyed $count entities while changing scenes"
346+
@debug "Skipped $skipcount entities while changing scenes"
347347

348-
# println("Entities left after destroying: ", length(persistentEntities))
348+
@debug "Entities left after destroying while changing scenes (persistent): $(length(persistentEntities)) "
349349

350350
persistentUIElements = []
351351
# delete all UIElements
@@ -632,21 +632,21 @@ function game_loop(this::Main, startTime::Ref{UInt64} = Ref(UInt64(0)), lastPhys
632632
"Mouse pos world: $(this.mousePositionWorld.x),$(this.mousePositionWorld.y)"
633633
]
634634

635-
if length(this.debugTextBoxes) == 0
636-
fontPath = joinpath(this.assets, "fonts", "FiraCode-Regular.ttf")
637-
638-
for i = eachindex(statTexts)
639-
textBox = UI.TextBoxModule.TextBox("Debug text", fontPath, 40, Math.Vector2(0, 35 * i), statTexts[i], false, false)
640-
push!(this.debugTextBoxes, textBox)
641-
JulGame.initialize(textBox)
642-
end
643-
else
644-
for i = eachindex(this.debugTextBoxes)
645-
db_textbox = this.debugTextBoxes[i]
646-
JulGame.update_text(db_textbox, statTexts[i])
647-
JulGame.render(db_textbox, false)
648-
end
649-
end
635+
# if length(this.debugTextBoxes) == 0
636+
# fontPath = joinpath(this.assets, "fonts", "FiraCode-Regular.ttf")
637+
638+
# for i = eachindex(statTexts)
639+
# textBox = UI.TextBoxModule.TextBox("Debug text", fontPath, 40, Math.Vector2(0, 35 * i), statTexts[i], false, false)
640+
# push!(this.debugTextBoxes, textBox)
641+
# JulGame.initialize(textBox)
642+
# end
643+
# else
644+
# for i = eachindex(this.debugTextBoxes)
645+
# db_textbox = this.debugTextBoxes[i]
646+
# JulGame.update_text(db_textbox, statTexts[i])
647+
# JulGame.render(db_textbox, false)
648+
# end
649+
# end
650650
end
651651

652652
if !JulGame.IS_EDITOR
@@ -743,6 +743,8 @@ function game_loop(this::Main, startTime::Ref{UInt64} = Ref(UInt64(0)), lastPhys
743743
end
744744

745745
if DEBUG && entity.collider != C_NULL
746+
rgba = (r = Ref(UInt8(0)), g = Ref(UInt8(0)), b = Ref(UInt8(0)), a = Ref(UInt8(255)))
747+
SDL2.SDL_GetRenderDrawColor(JulGame.Renderer::Ptr{SDL2.SDL_Renderer}, rgba.r, rgba.g, rgba.b, rgba.a)
746748
SDL2.SDL_SetRenderDrawColor(JulGame.Renderer::Ptr{SDL2.SDL_Renderer}, 0, 255, 0, SDL2.SDL_ALPHA_OPAQUE)
747749
pos = entity.transform.position
748750
scale = entity.transform.scale
@@ -754,23 +756,18 @@ function game_loop(this::Main, startTime::Ref{UInt64} = Ref(UInt64(0)), lastPhys
754756
colliderRenderCount += 1
755757
collider = entity.collider
756758

757-
if Component.get_type(collider) == "CircleCollider"
758-
SDL2E.SDL_RenderDrawCircle(
759-
round(Int32, (pos.x - cameraPosition.x) * SCALE_UNITS - ((entity.transform.scale.x * SCALE_UNITS - SCALE_UNITS) / 2)),
760-
round(Int32, (pos.y - cameraPosition.y) * SCALE_UNITS - ((entity.transform.scale.y * SCALE_UNITS - SCALE_UNITS) / 2)),
761-
round(Int32, collider.diameter/2 * SCALE_UNITS))
762-
else
763-
colSize = Component.get_size(collider)
764-
colSize = Math.Vector2f(colSize.x, colSize.y)
765-
colOffset = collider.offset
766-
colOffset = Math.Vector2f(colOffset.x, colOffset.y)
759+
760+
colSize = collider.size
761+
colSize = Math.Vector2f(colSize.x, colSize.y)
762+
colOffset = collider.offset
763+
colOffset = Math.Vector2f(colOffset.x, colOffset.y)
767764

768-
SDL2.SDL_RenderDrawRectF(JulGame.Renderer::Ptr{SDL2.SDL_Renderer},
769-
Ref(SDL2.SDL_FRect((pos.x + colOffset.x - cameraPosition.x) * SCALE_UNITS - ((colSize.x * SCALE_UNITS - SCALE_UNITS) / 2),
770-
(pos.y + colOffset.y - cameraPosition.y) * SCALE_UNITS - ((colSize.y * SCALE_UNITS - SCALE_UNITS) / 2),
771-
entity.transform.scale.x * colSize.x * SCALE_UNITS,
772-
entity.transform.scale.y * colSize.y * SCALE_UNITS)))
773-
end
765+
SDL2.SDL_RenderDrawRectF(JulGame.Renderer::Ptr{SDL2.SDL_Renderer},
766+
Ref(SDL2.SDL_FRect((pos.x + colOffset.x - cameraPosition.x) * SCALE_UNITS,
767+
(pos.y + colOffset.y - cameraPosition.y) * SCALE_UNITS,
768+
entity.transform.scale.x * colSize.x * SCALE_UNITS,
769+
entity.transform.scale.y * colSize.y * SCALE_UNITS)))
770+
SDL2.SDL_SetRenderDrawColor(JulGame.Renderer::Ptr{SDL2.SDL_Renderer}, rgba.r[], rgba.g[], rgba.b[], rgba.a[]);
774771
end
775772
end
776773
end

src/editor/JulGameEditor/Utils/FileContents.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ end
7777

7878
function newScriptContent(scriptName)
7979
return "module $(scriptName)Module
80-
using JulGame
80+
using ..JulGame
8181
mutable struct $scriptName
8282
parent # do not remove this line, this is a reference to the entity that this script is attached to
8383
# This is where you define your script's fields

src/editor/JulGameEditor/src/imgui.ini

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Collapsed=0
55

66
[Window][Hierarchy]
77
Pos=0,19
8-
Size=307,332
8+
Size=475,332
99
Collapsed=0
1010
DockId=0x00000006,0
1111

@@ -20,14 +20,14 @@ Size=825,481
2020
Collapsed=0
2121

2222
[Window][Debug]
23-
Pos=309,494
24-
Size=539,226
23+
Pos=477,688
24+
Size=371,32
2525
Collapsed=0
2626
DockId=0x00000003,0
2727

2828
[Window][Scene]
29-
Pos=309,19
30-
Size=539,473
29+
Pos=477,19
30+
Size=371,667
3131
Collapsed=0
3232
DockId=0x00000002,0
3333

@@ -42,20 +42,20 @@ Size=825,1358
4242
Collapsed=0
4343

4444
[Window][Controls]
45-
Pos=309,494
46-
Size=539,226
45+
Pos=477,688
46+
Size=371,32
4747
Collapsed=0
4848
DockId=0x00000003,1
4949

5050
[Window][Dear ImGui Demo]
5151
Pos=850,19
52-
Size=430,701
52+
Size=430,451
5353
Collapsed=0
54-
DockId=0x0000000A,1
54+
DockId=0x00000001,1
5555

5656
[Window][Open Scene]
57-
Pos=1092,19
58-
Size=746,1358
57+
Pos=777,19
58+
Size=500,114
5959
Collapsed=0
6060

6161
[Window][ResetCamera]
@@ -71,13 +71,13 @@ DockId=0x00000009,0
7171

7272
[Window][Entity Inspector]
7373
Pos=0,353
74-
Size=307,367
74+
Size=475,367
7575
Collapsed=0
7676
DockId=0x0000000B,1
7777

7878
[Window][UI Inspector]
7979
Pos=0,353
80-
Size=307,367
80+
Size=475,367
8181
Collapsed=0
8282
DockId=0x0000000B,0
8383

@@ -88,9 +88,9 @@ Collapsed=0
8888

8989
[Window][Scene List]
9090
Pos=850,19
91-
Size=430,701
91+
Size=430,451
9292
Collapsed=0
93-
DockId=0x0000000A,0
93+
DockId=0x00000001,0
9494

9595
[Window][Example: Custom rendering]
9696
Pos=99,110
@@ -132,7 +132,7 @@ DockId=0x00000002,1
132132
Pos=1264,19
133133
Size=656,998
134134
Collapsed=0
135-
DockId=0x0000000A,2
135+
DockId=0x00000001,2
136136

137137
[Window][Animation - frame 3]
138138
Pos=427,19
@@ -144,7 +144,7 @@ DockId=0x00000002,1
144144
Pos=1506,19
145145
Size=414,998
146146
Collapsed=0
147-
DockId=0x0000000A,2
147+
DockId=0x00000001,2
148148

149149
[Window][Animation - frame 5]
150150
Pos=427,19
@@ -153,8 +153,8 @@ Collapsed=0
153153
DockId=0x00000002,1
154154

155155
[Window][Game]
156-
Pos=309,19
157-
Size=1053,718
156+
Pos=477,19
157+
Size=371,667
158158
Collapsed=0
159159
DockId=0x00000002,1
160160

@@ -168,6 +168,29 @@ Pos=390,303
168168
Size=500,114
169169
Collapsed=0
170170

171+
[Window][Camera]
172+
Pos=850,472
173+
Size=430,248
174+
Collapsed=0
175+
DockId=0x0000000C,0
176+
177+
[Window][Project Config]
178+
Pos=850,472
179+
Size=430,248
180+
Collapsed=0
181+
DockId=0x0000000C,1
182+
183+
[Window][Start/Stop Game]
184+
Pos=700,553
185+
Size=577,88
186+
Collapsed=0
187+
188+
[Window][Sprite crop]
189+
Pos=477,19
190+
Size=1011,776
191+
Collapsed=0
192+
DockId=0x00000002,2
193+
171194
[Table][0x45A0E60D,7]
172195
RefScale=13
173196
Column 0 Width=49
@@ -223,13 +246,15 @@ Column 2 Weight=1.0000
223246
[Docking][Data]
224247
DockSpace ID=0x7C6B3D9B Window=0xA87D555D Pos=0,19 Size=1280,701 Split=X
225248
DockNode ID=0x00000007 Parent=0x7C6B3D9B SizeRef=848,828 Split=X
226-
DockNode ID=0x00000004 Parent=0x00000007 SizeRef=307,828 Split=Y Selected=0xC7219E3D
249+
DockNode ID=0x00000004 Parent=0x00000007 SizeRef=475,828 Split=Y Selected=0xC7219E3D
227250
DockNode ID=0x00000006 Parent=0x00000004 SizeRef=316,473 Selected=0x29EABFBD
228251
DockNode ID=0x0000000B Parent=0x00000004 SizeRef=316,523 Selected=0x60AF69E6
229-
DockNode ID=0x00000005 Parent=0x00000007 SizeRef=539,828 Split=Y
230-
DockNode ID=0x00000002 Parent=0x00000005 SizeRef=1440,473 Selected=0xE192E354
231-
DockNode ID=0x00000003 Parent=0x00000005 SizeRef=1440,226 CentralNode=1 Selected=0x67284010
252+
DockNode ID=0x00000005 Parent=0x00000007 SizeRef=1651,828 Split=Y
253+
DockNode ID=0x00000002 Parent=0x00000005 SizeRef=1440,776 Selected=0xE192E354
254+
DockNode ID=0x00000003 Parent=0x00000005 SizeRef=1440,214 CentralNode=1 Selected=0x67284010
232255
DockNode ID=0x00000008 Parent=0x7C6B3D9B SizeRef=430,828 Split=Y Selected=0xD04A4B96
233256
DockNode ID=0x00000009 Parent=0x00000008 SizeRef=503,414 Selected=0xD04A4B96
234-
DockNode ID=0x0000000A Parent=0x00000008 SizeRef=503,412 Selected=0x77FEF510
257+
DockNode ID=0x0000000A Parent=0x00000008 SizeRef=503,412 Split=Y Selected=0x77FEF510
258+
DockNode ID=0x00000001 Parent=0x0000000A SizeRef=430,451 Selected=0x77FEF510
259+
DockNode ID=0x0000000C Parent=0x0000000A SizeRef=430,248 Selected=0x0545BD69
235260

src/engine/Camera/Camera.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module CameraModule
3636
rgba = (r = Ref(UInt8(0)), g = Ref(UInt8(0)), b = Ref(UInt8(0)), a = Ref(UInt8(255)))
3737
SDL2.SDL_GetRenderDrawColor(JulGame.Renderer::Ptr{SDL2.SDL_Renderer}, rgba.r, rgba.g, rgba.b, rgba.a)
3838
SDL2.SDL_SetRenderDrawColor(Renderer, this.backgroundColor[1], this.backgroundColor[2], this.backgroundColor[3], this.backgroundColor[4]);
39-
SDL2.SDL_RenderFillRectF(Renderer, Ref(SDL2.SDL_FRect(this.windowPos.x, this.windowPos.y, this.size.x, this.size.y)))
39+
#SDL2.SDL_RenderFillRectF(Renderer, Ref(SDL2.SDL_FRect(this.windowPos.x, this.windowPos.y, this.size.x, this.size.y)))
4040
SDL2.SDL_SetRenderDrawColor(JulGame.Renderer::Ptr{SDL2.SDL_Renderer}, rgba.r[], rgba.g[], rgba.b[], rgba.a[]);
4141

4242
center = Vector2f(this.size.x/SCALE_UNITS/2, this.size.y/SCALE_UNITS/2)

src/engine/Component/CircleCollider.jl

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ module CircleColliderModule
5757

5858
for i in eachindex(colliders)
5959
#TODO: Skip any out of a certain range of this. This will prevent a bunch of unnecessary collision checks
60-
if !Component.get_parent(colliders[i]).isActive || !colliders[i].enabled
60+
if !colliders[i].parent.isActive || !colliders[i].enabled
6161
if this.parent.rigidbody.grounded && i == length(colliders)
6262
this.parent.rigidbody.grounded = false
6363
end
@@ -68,13 +68,13 @@ module CircleColliderModule
6868
if CheckIfResting(this, colliders[i])[1] == true && length(this.currentRests) > 0 && !(colliders[i] in this.currentRests)
6969
# if this collider isn't already in the list of current rests, check if it is on the same Y level and the same size as any of the current rests, if it is, then add it to current rests
7070
for j in eachindex(this.currentRests)
71-
if Component.get_parent(this.currentRests[j]).transform.position.y == Component.get_parent(colliders[i]).transform.position.y && Component.get_size(this.currentRests[j]).y == Component.get_size(colliders[i]).y
71+
if this.currentRests[j].parent.transform.position.y == colliders[i].parent.transform.position.y && Component.get_size(this.currentRests[j]).y == Component.get_size(colliders[i]).y
7272
push!(this.currentRests, colliders[i])
7373
break
7474
end
7575
end
7676
end
77-
transform = Component.get_parent(this).transform
77+
transform = this.parent.transform
7878
# if collision[1] == Top::CollisionDirection
7979
# push!(this.currentCollisions, colliders[i])
8080
# for eventToCall in this.collisionEvents
@@ -130,18 +130,10 @@ module CircleColliderModule
130130
this.currentCollisions = []
131131
end
132132

133-
function Component.get_parent(this::CircleCollider)
134-
return this.parent
135-
end
136-
137133
function Component.add_collision_event(this::CircleCollider, event)
138134
push!(this.collisionEvents, event)
139135
end
140136

141-
function Component.get_type(this::CircleCollider)
142-
return "CircleCollider"
143-
end
144-
145137
function check_collision(a::CircleCollider, b::CircleCollider)
146138
# Calculate total radius squared
147139
totalRadiusSquared::Float64 = (a.diameter + b.diameter)^2
@@ -158,8 +150,8 @@ module CircleColliderModule
158150
# Closest point on collision box
159151
cX, cY = 0, 0
160152

161-
posA = Component.get_parent(a).transform.position + a.offset
162-
posB = Component.get_parent(b).transform.position + b.offset
153+
posA = a.parent.transform.position + a.offset
154+
posB = b.parent.transform.position + b.offset
163155

164156
# Find closest x offset
165157
if posA.x < posB.x
@@ -194,8 +186,8 @@ module CircleColliderModule
194186
# Closest point on collision box
195187
cX = 0
196188

197-
posA = Component.get_parent(a).transform.position + a.offset
198-
posB = Component.get_parent(b).transform.position + b.offset
189+
posA = a.parent.transform.position + a.offset
190+
posB = b.parent.transform.position + b.offset
199191
radius = a.diameter / 2
200192

201193
# Find closest x offset

0 commit comments

Comments
 (0)