@quenty/spawning 1.1.0-canary.252.9753dcc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/LICENSE.md +21 -0
- package/README.md +21 -0
- package/default.project.json +6 -0
- package/package.json +39 -0
- package/src/Client/SpawnServiceClient.lua +16 -0
- package/src/Server/SpawnBinderGroupsServer.lua +30 -0
- package/src/Server/SpawnCmdrService.lua +29 -0
- package/src/Server/SpawnService.lua +101 -0
- package/src/Shared/SpawnerUtils.lua +26 -0
- package/src/node_modules.project.json +7 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
# 1.1.0-canary.252.9753dcc.0 (2022-03-10)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Add spawning package for centralized performance tracked spawning ([dc21714](https://github.com/Quenty/NevermoreEngine/commit/dc21714f03bfe510670d65072dfcdbdb3392d3ce))
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014-2021 Quenty
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
## SoundPromiseUtils
|
|
2
|
+
<div align="center">
|
|
3
|
+
<a href="http://quenty.github.io/NevermoreEngine/">
|
|
4
|
+
<img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/docs.yml/badge.svg" alt="Documentation status" />
|
|
5
|
+
</a>
|
|
6
|
+
<a href="https://discord.gg/mhtGUS8">
|
|
7
|
+
<img src="https://img.shields.io/discord/385151591524597761?color=5865F2&label=discord&logo=discord&logoColor=white" alt="Discord" />
|
|
8
|
+
</a>
|
|
9
|
+
<a href="https://github.com/Quenty/NevermoreEngine/actions">
|
|
10
|
+
<img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/build.yml/badge.svg" alt="Build and release status" />
|
|
11
|
+
</a>
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
Centralized spawning service
|
|
15
|
+
|
|
16
|
+
<div align="center"><a href="https://quenty.github.io/NevermoreEngine/api/SpawnService">View docs →</a></div>
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
```
|
|
20
|
+
npm install @quenty/spawning --save
|
|
21
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@quenty/spawning",
|
|
3
|
+
"version": "1.1.0-canary.252.9753dcc.0",
|
|
4
|
+
"description": "Centralized spawning system",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"Roblox",
|
|
7
|
+
"Nevermore",
|
|
8
|
+
"Lua"
|
|
9
|
+
],
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/Quenty/NevermoreEngine/issues"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/Quenty/NevermoreEngine.git",
|
|
16
|
+
"directory": "src/spawning/"
|
|
17
|
+
},
|
|
18
|
+
"funding": {
|
|
19
|
+
"type": "patreon",
|
|
20
|
+
"url": "https://www.patreon.com/quenty"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"contributors": [
|
|
24
|
+
"Quenty"
|
|
25
|
+
],
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@quenty/binder": "5.1.0-canary.252.9753dcc.0",
|
|
28
|
+
"@quenty/cmdrservice": "4.1.0-canary.252.9753dcc.0",
|
|
29
|
+
"@quenty/loader": "4.0.0",
|
|
30
|
+
"@quenty/maid": "2.2.0-canary.252.9753dcc.0",
|
|
31
|
+
"@quenty/randomutils": "2.1.1",
|
|
32
|
+
"@quenty/servicebag": "4.1.0-canary.252.9753dcc.0",
|
|
33
|
+
"@quentystudios/t": "^1.2.5"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"gitHead": "9753dcc02d4600d2706d8003cebb325ccfcde523"
|
|
39
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
--[=[
|
|
2
|
+
@class SpawnServiceClient
|
|
3
|
+
]=]
|
|
4
|
+
|
|
5
|
+
local require = require(script.Parent.loader).load(script)
|
|
6
|
+
|
|
7
|
+
local SpawnServiceClient = {}
|
|
8
|
+
|
|
9
|
+
function SpawnServiceClient:Init(serviceBag)
|
|
10
|
+
assert(not self._serviceBag, "Already initialized")
|
|
11
|
+
self._serviceBag = assert(serviceBag, "No serviceBag")
|
|
12
|
+
|
|
13
|
+
self._serviceBag:GetService(require("CmdrServiceClient"))
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
return SpawnServiceClient
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
--[=[
|
|
2
|
+
@class SpawnBinderGroupsServer
|
|
3
|
+
]=]
|
|
4
|
+
|
|
5
|
+
local require = require(script.Parent.loader).load(script)
|
|
6
|
+
|
|
7
|
+
local BinderGroup = require("BinderGroup")
|
|
8
|
+
local t = require("t")
|
|
9
|
+
|
|
10
|
+
return require("BinderGroupProvider").new(function(self, _serviceBag)
|
|
11
|
+
|
|
12
|
+
-- SpawnProvider
|
|
13
|
+
-- self:Add("SpawnProviders", BinderGroup.new(
|
|
14
|
+
-- {
|
|
15
|
+
-- },
|
|
16
|
+
-- t.interface({
|
|
17
|
+
-- GetSpawnPosition = t.callback;
|
|
18
|
+
-- })
|
|
19
|
+
-- ))
|
|
20
|
+
|
|
21
|
+
-- Item / asset spawning
|
|
22
|
+
self:Add("Spawners", BinderGroup.new(
|
|
23
|
+
{
|
|
24
|
+
},
|
|
25
|
+
t.interface({
|
|
26
|
+
SpawnUpdate = t.callback;
|
|
27
|
+
Regenerate = t.callback;
|
|
28
|
+
})
|
|
29
|
+
))
|
|
30
|
+
end)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
--[=[
|
|
2
|
+
@class SpawnCmdrService
|
|
3
|
+
]=]
|
|
4
|
+
|
|
5
|
+
local require = require(script.Parent.loader).load(script)
|
|
6
|
+
|
|
7
|
+
local SpawnCmdrService = {}
|
|
8
|
+
|
|
9
|
+
function SpawnCmdrService:Init(serviceBag)
|
|
10
|
+
assert(not self._serviceBag, "Already initialized")
|
|
11
|
+
self._serviceBag = assert(serviceBag, "No serviceBag")
|
|
12
|
+
|
|
13
|
+
self._spawnService = self._serviceBag:GetService(require("SpawnService"))
|
|
14
|
+
self._cmdrService = self._serviceBag:GetService(require("CmdrService"))
|
|
15
|
+
|
|
16
|
+
self._cmdrService:RegisterCommand({
|
|
17
|
+
Name = "regen";
|
|
18
|
+
Aliases = {};
|
|
19
|
+
Description = "Forces all spawners to regenerate.";
|
|
20
|
+
Group = "Spawn";
|
|
21
|
+
Args = {};
|
|
22
|
+
}, function(_context)
|
|
23
|
+
self._spawnService:Regenerate()
|
|
24
|
+
|
|
25
|
+
return "Regenerated every spawner in the game."
|
|
26
|
+
end)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
return SpawnCmdrService
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
--[=[
|
|
2
|
+
Handles spawning stuff in the game
|
|
3
|
+
@class SpawnService
|
|
4
|
+
]=]
|
|
5
|
+
|
|
6
|
+
local require = require(script.Parent.loader).load(script)
|
|
7
|
+
|
|
8
|
+
local RunService = game:GetService("RunService")
|
|
9
|
+
|
|
10
|
+
local RandomUtils = require("RandomUtils")
|
|
11
|
+
local Maid = require("Maid")
|
|
12
|
+
|
|
13
|
+
local UPDATE_PERIOD_SEC = 5
|
|
14
|
+
local SPAWN_AFTER_GAME_START = 1
|
|
15
|
+
local MAX_BUDGET_PER_CLASS = 0.05
|
|
16
|
+
local WARN_ON_CLASS_BUDGET_EXHAUST = false
|
|
17
|
+
local TOTAL_BUDGET_BEFORE_WARN = 0.1
|
|
18
|
+
|
|
19
|
+
local SpawnService = {}
|
|
20
|
+
|
|
21
|
+
function SpawnService:Init(serviceBag)
|
|
22
|
+
self._serviceBag = assert(serviceBag, "No serviceBag")
|
|
23
|
+
self._maid = Maid.new()
|
|
24
|
+
|
|
25
|
+
-- External
|
|
26
|
+
self._serviceBag:GetService(require("CmdrService"))
|
|
27
|
+
|
|
28
|
+
-- Internal
|
|
29
|
+
self._spawnBinderGroupsServer = self._serviceBag:GetService(require("SpawnBinderGroupsServer"))
|
|
30
|
+
self._serviceBag:GetService(require("SpawnCmdrService"))
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
function SpawnService:Start()
|
|
34
|
+
local lastUpdateTime = (tick() - UPDATE_PERIOD_SEC + SPAWN_AFTER_GAME_START)
|
|
35
|
+
|
|
36
|
+
-- TODO: Smear across update pipeline
|
|
37
|
+
self._maid:GiveTask(RunService.Stepped:Connect(function()
|
|
38
|
+
if (lastUpdateTime + UPDATE_PERIOD_SEC) <= tick() then
|
|
39
|
+
lastUpdateTime = tick()
|
|
40
|
+
self:Update()
|
|
41
|
+
end
|
|
42
|
+
end))
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
function SpawnService:AddSpawnerBinder(spawnerBinder)
|
|
46
|
+
self._spawnBinderGroupsServer.Spawners:Add(spawnerBinder)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
function SpawnService:Regenerate()
|
|
50
|
+
local startTime = tick()
|
|
51
|
+
|
|
52
|
+
for _, binder in pairs(self._spawnBinderGroupsServer.Spawners:GetBinders()) do
|
|
53
|
+
for _, spawner in pairs(binder:GetAll()) do
|
|
54
|
+
spawner:Regenerate()
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
if (tick() - startTime) >= 0.05 then
|
|
59
|
+
warn(("SpawnService regenerate time: %0.4f ms"):format((tick() - startTime)*1000))
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
function SpawnService:Update()
|
|
64
|
+
debug.profilebegin("spawnService")
|
|
65
|
+
|
|
66
|
+
local startTime = tick()
|
|
67
|
+
local spawnerCount = 0
|
|
68
|
+
|
|
69
|
+
for _, binder in pairs(self._spawnBinderGroupsServer.Spawners:GetBinders()) do
|
|
70
|
+
local classStartTime = tick()
|
|
71
|
+
local classes = RandomUtils.shuffledCopy(binder:GetAll())
|
|
72
|
+
|
|
73
|
+
for _, spawner in pairs(classes) do
|
|
74
|
+
spawnerCount = spawnerCount + 1
|
|
75
|
+
spawner:SpawnUpdate(false)
|
|
76
|
+
|
|
77
|
+
if (tick() - classStartTime) >= MAX_BUDGET_PER_CLASS then
|
|
78
|
+
if WARN_ON_CLASS_BUDGET_EXHAUST then
|
|
79
|
+
warn(("[SpawnService.Update] - Class %q ran out of execution budget at %0.4f ms")
|
|
80
|
+
:format(binder:GetTag(), (tick() - classStartTime)*1000))
|
|
81
|
+
end
|
|
82
|
+
break
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
-- watch dog
|
|
88
|
+
if (tick() - startTime) >= TOTAL_BUDGET_BEFORE_WARN then
|
|
89
|
+
warn(("[SpawnService.Update] - Update time: %0.4f ms for %d spawners")
|
|
90
|
+
:format((tick() - startTime)*1000, spawnerCount))
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
debug.profileend()
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
function SpawnService:Destroy()
|
|
97
|
+
self._maid:DoCleaning()
|
|
98
|
+
self._maid = nil
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
return SpawnService
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
--[=[
|
|
2
|
+
@class SpawnerUtils
|
|
3
|
+
]=]
|
|
4
|
+
|
|
5
|
+
local SpawnerUtils = {}
|
|
6
|
+
|
|
7
|
+
function SpawnerUtils.getSpawnLocation(spawnPart, raycaster)
|
|
8
|
+
local size = spawnPart.Size
|
|
9
|
+
local sy = size.y
|
|
10
|
+
|
|
11
|
+
local ox = (math.random() - 0.5)*size.x
|
|
12
|
+
local oz = (math.random() - 0.5)*size.z
|
|
13
|
+
|
|
14
|
+
local point = spawnPart.CFrame:pointToWorldSpace(Vector3.new(ox, sy/2, oz))
|
|
15
|
+
|
|
16
|
+
local ray = Ray.new(point, Vector3.new(0, -sy*2, 0))
|
|
17
|
+
|
|
18
|
+
local data = raycaster:FindPartOnRay(ray)
|
|
19
|
+
if not data then
|
|
20
|
+
return point
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
return data.Position, data
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
return SpawnerUtils
|