|
| 1 | +-- Services |
| 2 | +local RS = game:GetService("RunService") |
| 3 | +local Rep = game:GetService("ReplicatedStorage") |
| 4 | +local UIS = game:GetService("UserInputService") |
| 5 | +local RepFirst = game:GetService("ReplicatedFirst") |
| 6 | + |
| 7 | +-- Requires |
| 8 | +local FastCastM = require(Rep:WaitForChild("FastCast2")) |
| 9 | + |
| 10 | +-- Variables |
| 11 | +local ProjectileContainer = Instance.new("Folder") |
| 12 | +ProjectileContainer.Name = "FastCast2PJ" |
| 13 | +ProjectileContainer.Parent = workspace |
| 14 | +local ProjectileTemplate = Instance.new("Part") |
| 15 | +ProjectileTemplate.Name = "Projectile" |
| 16 | +ProjectileTemplate.Parent = Rep |
| 17 | +ProjectileTemplate.Size = Vector3.new(1,1,1) |
| 18 | +ProjectileTemplate.CanCollide = false |
| 19 | +ProjectileTemplate.Anchored = true |
| 20 | +ProjectileTemplate.CanQuery = false |
| 21 | +ProjectileTemplate.CanTouch = false |
| 22 | +ProjectileTemplate.Position = Vector3.new(1,1,1) |
| 23 | +ProjectileTemplate.Massless = true |
| 24 | + |
| 25 | +-- FPS rs |
| 26 | +local start = tick() |
| 27 | +local updateRate = 0.5 |
| 28 | +local fpsTable = {} |
| 29 | +local averageFps = 0 |
| 30 | +local maxFps = 0 |
| 31 | +local minFps = 0 |
| 32 | +local delta = 0 |
| 33 | + |
| 34 | +RS.Heartbeat:Connect(function(dt: number) |
| 35 | + local fps = 1/dt -- NOTE: You can math.floor this |
| 36 | + if fps > maxFps then |
| 37 | + maxFps = fps |
| 38 | + end |
| 39 | + |
| 40 | + if fps < minFps then |
| 41 | + minFps = fps |
| 42 | + end |
| 43 | + |
| 44 | + delta = fps |
| 45 | + table.insert(fpsTable, fps) |
| 46 | + |
| 47 | + if tick() >= start + updateRate then |
| 48 | + local totalFps = 0 |
| 49 | + for _, vFps in fpsTable do |
| 50 | + totalFps += vFps |
| 51 | + end |
| 52 | + |
| 53 | + averageFps = totalFps / #fpsTable |
| 54 | + fpsTable = {} |
| 55 | + start = tick() |
| 56 | + end |
| 57 | +end) |
| 58 | + |
| 59 | +-- CastParams |
| 60 | +local CastParams = RaycastParams.new() |
| 61 | +CastParams.FilterDescendantsInstances = {character} |
| 62 | +CastParams.FilterType = Enum.RaycastFilterType.Exclude |
| 63 | +CastParams.IgnoreWater = true |
| 64 | + |
| 65 | +-- Behavior |
| 66 | +local castBehavior = FastCastM.newBehavior() |
| 67 | +castBehavior.MaxDistance = 999999999 |
| 68 | +castBehavior.RaycastParams = CastParams |
| 69 | +castBehavior.HighFidelityBehavior = 1 |
| 70 | +castBehavior.HighFidelitySegmentSize = 1 |
| 71 | +castBehavior.Acceleration = Vector3.new(0, 0, 0) |
| 72 | +castBehavior.AutoIgnoreContainer = true |
| 73 | +castBehavior.CosmeticBulletContainer = ProjectileContainer |
| 74 | +castBehavior.CosmeticBulletTemplate = ProjectileTemplate |
| 75 | +for i, v in castBehavior.FastCastEventsConfig do |
| 76 | + v = false |
| 77 | +end |
| 78 | + |
| 79 | +for i, v in castBehavior.FastCastEventsModuleConfig do |
| 80 | + v = false |
| 81 | +end |
| 82 | +castBehavior.FastCastEventsConfig.UseCastFire = true |
| 83 | + |
| 84 | + |
| 85 | +-- Caster |
| 86 | +local activeCasts = {} |
| 87 | +local Caster = FastCastM.new() |
| 88 | +Caster:Init( |
| 89 | + 4, |
| 90 | + RepFirst, |
| 91 | + "CastVMs", |
| 92 | + RepFirst, |
| 93 | + "CastVMContainer", |
| 94 | + "CastVM", |
| 95 | + true |
| 96 | +) |
| 97 | +Caster.CastFire = function(cast) |
| 98 | + table.insert(activeCasts, cast) |
| 99 | +end |
| 100 | + |
| 101 | +-- Functions |
| 102 | +local function summary() |
| 103 | + print("Delta: " .. tostring(delta)) |
| 104 | + print("Average fps: " .. tostring(averageFps)) |
| 105 | + print("Max fps: " .. tostring(maxFps)) |
| 106 | + print("Min fps: " .. tostring(minFps)) |
| 107 | +end |
| 108 | + |
| 109 | +-- Benchmark |
| 110 | +local isBenchmarking = false |
| 111 | +local AMOUNT = 5000 |
| 112 | +local BENCH_TIME = 5 |
| 113 | +local VEC = 35 |
| 114 | + |
| 115 | +UIS.InputBegan:Connect(function(input, gp) |
| 116 | + if gp then return end |
| 117 | + if isBenchmarking then return end |
| 118 | + if input.KeyCode == Enum.KeyCode.E then |
| 119 | + isBenchmarking = true |
| 120 | + for i = 1, AMOUNT do |
| 121 | + Caster:RaycastFire( |
| 122 | + Vector3.new( |
| 123 | + math.random(-1, 1) |
| 124 | + 5000 |
| 125 | + math.random(-1, 1) |
| 126 | + ), |
| 127 | + Vector3.new( |
| 128 | + math.random(-1, 1) |
| 129 | + 5000, |
| 130 | + math.random(-1, 1) |
| 131 | + ), |
| 132 | + VEC, |
| 133 | + castBehavior |
| 134 | + ) |
| 135 | + end |
| 136 | + print("Creating activeCasts") |
| 137 | + print("--------------------") |
| 138 | + summary() |
| 139 | + print("--------------------") |
| 140 | + task.wait(BENCH_TIME) |
| 141 | + print("Simulate") |
| 142 | + print("--------------------") |
| 143 | + summary() |
| 144 | + print("--------------------") |
| 145 | + for i, v in activeCasts do |
| 146 | + FastCastM:TerminateCast(v) |
| 147 | + end |
| 148 | + print("DESTROY") |
| 149 | + print("--------------------") |
| 150 | + summary() |
| 151 | + print("--------------------") |
| 152 | + isBenchmarking = false |
| 153 | + end |
| 154 | +end) |
0 commit comments