Skip to content

Commit dac77ee

Browse files
Merge pull request #36 from weenachuangkud/fix
Fix bugs, clean up docs, and improve code quality
2 parents 3dc9676 + 02b5573 commit dac77ee

File tree

3 files changed

+90
-107
lines changed

3 files changed

+90
-107
lines changed

src/FastCast2/ActiveCast.luau

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ local EnumCastTypes = FastCastEnums.CastType
3030

3131
-- Debugging
3232
local DBG_SEGMENT_SUB_COLOR = Color3.new(0.286275, 0.329412, 0.247059)
33-
local DBG_SEGMENT_SUB_COLOR2 = Color3.new(0.286275, 0.329412, 0.247059)
33+
local DBG_SEGMENT_SUB_COLOR2 = Color3.new(0.454902, 0.933333, 0.011765)
3434

3535
local DBG_HIT_SUB_COLOR = Color3.new(0.0588235, 0.87451, 1)
3636

@@ -395,13 +395,13 @@ local function SimulateCast(
395395

396396
local point = currentTarget
397397
local part: Instance? = nil
398-
local material = Enum.Material.Air
398+
--local material = Enum.Material.Air
399399
--local normal = Vector3.new()
400400

401401
if resultOfCast ~= nil then
402402
point = resultOfCast.Position
403403
part = resultOfCast.Instance
404-
material = resultOfCast.Material
404+
--material = resultOfCast.Material
405405
--normal = resultOfCast.Normal
406406
end
407407

@@ -510,6 +510,7 @@ local function SimulateCast(
510510
warn(
511511
"Cascading cast lag encountered! The caster attempted to perform a high fidelity cast before the previous one completed, resulting in exponential cast lag. Consider increasing HighFidelitySegmentSize."
512512
)
513+
return
513514
end
514515

515516
cast.StateInfo.IsActivelyResimulating = true
@@ -875,6 +876,7 @@ function ActiveCast.createCastData(
875876
warn(
876877
"Cascading cast lag encountered! The caster attempted to perform a high fidelity cast before the previous one completed, resulting in exponential cast lag. Consider increasing HighFidelitySegmentSize."
877878
)
879+
return
878880
end
879881

880882
cast.StateInfo.IsActivelyResimulating = true
@@ -928,7 +930,7 @@ function ActiveCast.createCastData(
928930
end
929931

930932
for segmentIndex = 1, numSegmentsReal do
931-
if cast == nil or next(cast) == nil then
933+
if next(cast) == nil then
932934
return
933935
end
934936
if cast.StateInfo.CancelHighResCast then
@@ -944,7 +946,7 @@ function ActiveCast.createCastData(
944946
SimulateCast(cast, timeIncrement, FastCastEvents, variant)
945947
end
946948

947-
if cast == nil or next(cast) == nil then
949+
if next(cast) == nil then
948950
return
949951
end
950952
cast.StateInfo.IsActivelyResimulating = false

src/FastCast2/BaseCast.luau

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ local ActiveCastCleaner: BindableEvent = nil
4545
local ObjectCache: BindableEvent? = nil
4646
local CacheHolder = nil
4747
local NextProjectileID = 0
48-
4948
local SyncChanges: BindableEvent = nil
49+
local CastFireFunc = nil
5050

5151
-- Private functions
5252

@@ -76,7 +76,7 @@ local function HandleBulkMoveTo()
7676
end
7777

7878
local function SendCastFire(
79-
cast: TypeDefinitions.ActiveCastData,
79+
cast: TypeDef.ActiveCastData,
8080
origin: Vector3,
8181
direction: Vector3,
8282
velocity: Vector3 | number,
@@ -85,13 +85,6 @@ local function SendCastFire(
8585
cast.Caster.Output:Fire("CastFire", cast, origin, direction, velocity, behavior)
8686
end
8787

88-
local function GetCastFireFunction()
89-
if FastCastEventsModule then
90-
local loadedModule = require(FastCastEventsModule)
91-
return loadedModule.CastFire
92-
end
93-
end
94-
9588
--[=[
9689
9790
@function Init
@@ -143,7 +136,7 @@ function BaseCast.Init(BindableOutput: BindableEvent, Data: any)
143136
SyncChanges.Name = "SyncChanges"
144137
SyncChanges.Parent = Actor
145138

146-
SyncChanges.Event:Connect(function(cast: TypeDef.ActiveCastCompement)
139+
SyncChanges.Event:Connect(function(cast: TypeDef.ActiveCastData)
147140
local ID = cast.ID
148141
local TargetCast = Actives[ID]
149142

@@ -196,9 +189,8 @@ function BaseCast:Raycast(
196189
SendCastFire(Actives[NextProjectileID], Origin, Direction, Velocity, Behavior)
197190
end
198191
if Behavior.FastCastEventsModuleConfig.UseCastFire then
199-
local CastFireFunction = GetCastFireFunction()
200-
if CastFireFunction then
201-
CastFireFunction(Actives[NextProjectileID], Origin, Direction, Velocity, Behavior)
192+
if CastFireFunc then
193+
CastFireFunc(Actives[NextProjectileID], Origin, Direction, Velocity, Behavior)
202194
end
203195
end
204196
end
@@ -213,6 +205,14 @@ end
213205
]=]
214206
function BaseCast:SetFastCastEventsModule(moduleScript: ModuleScript)
215207
FastCastEventsModule = moduleScript
208+
if moduleScript and typeof(moduleScript) == "Instance" and moduleScript:IsA("ModuleScript") then
209+
CastFireFunc = require(moduleScript)
210+
if CastFireFunc.CastFire then
211+
CastFireFunc = CastFireFunc.CastFire
212+
else
213+
CastFireFunc = nil
214+
end
215+
end
216216
end
217217

218218
--[=[
@@ -253,9 +253,8 @@ function BaseCast:Blockcast(
253253
SendCastFire(Actives[NextProjectileID], Origin, Direction, Velocity, Behavior)
254254
end
255255
if Behavior.FastCastEventsModuleConfig.UseCastFire then
256-
local CastFireFunction = GetCastFireFunction()
257-
if CastFireFunction then
258-
CastFireFunction(Actives[NextProjectileID], Origin, Direction, Velocity, Behavior)
256+
if CastFireFunc then
257+
CastFireFunc(Actives[NextProjectileID], Origin, Direction, Velocity, Behavior)
259258
end
260259
end
261260
end
@@ -298,9 +297,8 @@ function BaseCast:Spherecast(
298297
SendCastFire(Actives[NextProjectileID], Origin, Direction, Velocity, Behavior)
299298
end
300299
if Behavior.FastCastEventsModuleConfig.UseCastFire then
301-
local CastFireFunction = GetCastFireFunction()
302-
if CastFireFunction then
303-
CastFireFunction(Actives[NextProjectileID], Origin, Direction, Velocity, Behavior)
300+
if CastFireFunc then
301+
CastFireFunc(Actives[NextProjectileID], Origin, Direction, Velocity, Behavior)
304302
end
305303
end
306304
end
@@ -317,7 +315,9 @@ Enables or disables the BulkMoveTo feature.
317315
]=]
318316
function BaseCast:BindBulkMoveTo(bool: boolean)
319317
if bool then
320-
BulkMoveToConnection = RS.PreRender:ConnectParallel(HandleBulkMoveTo)
318+
if not BulkMoveToConnection then
319+
BulkMoveToConnection = RS.PreRender:ConnectParallel(HandleBulkMoveTo)
320+
end
321321
else
322322
if BulkMoveToConnection then
323323
BulkMoveToConnection:Disconnect()

0 commit comments

Comments
 (0)