Skip to content

Commit 386d163

Browse files
committed
feat(ecs): add basic component & entity structure
- as discussed add as an independent temporary folder "_ECS_WIP_TEMP"
1 parent 84a0a25 commit 386d163

File tree

104 files changed

+810
-129
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+810
-129
lines changed

script/Core/Structures/Class.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
Example:
88
9-
local Ship = class(function (self, name, hp)
9+
local Ship = Class(function (self, name, hp)
1010
self.name = name
1111
self.health = hp
1212
self.healthMax = hp
@@ -15,7 +15,7 @@
1515
function Ship:addHangar (unit) assert(false, "No hangar!") end
1616
function Ship:getHangar () return {} end
1717
18-
local Carrier = subclass(Ship, function (self)
18+
local Carrier = Subclass(Ship, function (self)
1919
self.hanger = {}
2020
end)
2121
@@ -24,7 +24,7 @@
2424
----------------------------------------------------------------------------]]
2525
--
2626

27-
function class(ctor)
27+
function Class(ctor)
2828
local cls = {}
2929
cls.__index = cls
3030
setmetatable(cls, {
@@ -38,7 +38,7 @@ function class(ctor)
3838
return cls
3939
end
4040

41-
function subclass(base, ctor)
41+
function Subclass(base, ctor)
4242
local cls = {}
4343
cls.__index = cls
4444
setmetatable(cls, {

script/Core/Structures/List.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Includes some useful generic algorithms for common linear list operations.
44
----------------------------------------------------------------------------]]
55
--
6-
local List = class(function(self, ...)
6+
local List = Class(function(self, ...)
77
local args = { ... }
88
for i = 1, #args do
99
self[i] = args[i]

script/Core/Structures/Map.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
local Map = class(function(self, ctor)
1+
local Map = Class(function(self, ctor)
22
self.__ctor = ctor
33
end)
44

script/Core/Util/Distribution.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
TODO : Implement Alias Method for O(1) sampling. Sampling is currently O(n).
99
----------------------------------------------------------------------------]]
1010

11-
local Distribution = class(function(self)
11+
local Distribution = Class(function(self)
1212
self.values = {}
1313
self.weights = {}
1414
end)

script/Core/Util/Iterator.lua

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---@class Iterator
12
function Iterator(t)
23
local i = 0
34
local n = #t
@@ -7,6 +8,16 @@ function Iterator(t)
78
end
89
end
910

11+
---@class IteratorIndexed
12+
function IteratorIndexed(t)
13+
local i = 0
14+
local n = #t
15+
return function()
16+
i = i + 1
17+
if i <= n then return i, t[i] end
18+
end
19+
end
20+
1021
--[[
1122
example of usage:
1223

script/Enums/EntityType.lua

+29-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,30 @@
1+
---@enum EntityType
12
Enums.EntityType = {
2-
Player = 1,
3-
Station = 2,
4-
Ship = 3,
5-
Component = 4,
6-
Faction = 5
7-
}
3+
Unknown = 1,
4+
Reserved = 2,
5+
StarSector = 3,
6+
StarSystem = 4,
7+
Zone = 5,
8+
Star = 6,
9+
Planet = 7,
10+
Colony = 8,
11+
Station = 9,
12+
Ship = 10,
13+
Asteroid = 11,
14+
Player = 12
15+
}
16+
17+
Enums.EntityTypeNames = {
18+
"Unknown",
19+
"Reserved",
20+
"StarSector",
21+
"StarSystem",
22+
"Zone",
23+
"Star",
24+
"Planet",
25+
"Colony",
26+
"Station",
27+
"Ship",
28+
"Asteroid",
29+
"Player"
30+
}

script/GameObjects/Action.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
----------------------------------------------------------------------------]]
1515
--
1616

17-
local Action = class(function(self) end)
17+
local Action = Class(function(self) end)
1818

1919
-- Virtual ---------------------------------------------------------------------
2020

script/GameObjects/Actions/Attack.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local SocketType = require('GameObjects.Entities.Ship.SocketType')
44
-- temp settings
55
local outOfRangeCancel = 30
66

7-
local Attack = subclass(Action, function(self, target)
7+
local Attack = Subclass(Action, function(self, target)
88
self.target = target
99
end)
1010

script/GameObjects/Actions/CriminalThink.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ local Player = require('GameObjects.Entities.Player')
33

44
-- Temporary File until other systems are more fleshed out, to be merged into a general AI script that handles all the THINKING
55

6-
local CriminalThink = subclass(Action, function(self)
6+
local CriminalThink = Subclass(Action, function(self)
77
self.timer = 0
88
self.rng = RNG.FromTime()
99
end)

script/GameObjects/Actions/DockAt.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local rng = RNG.FromTime()
55
-- TODO : Dock range should be specified by the dockable component
66
local kDockRange = 2000 -- ships are getting "stuck" at 250
77

8-
local DockAt = subclass(Action, function(self, target)
8+
local DockAt = Subclass(Action, function(self, target)
99
self.target = target
1010
end)
1111

script/GameObjects/Actions/Escort.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local Action = require('GameObjects.Action')
22

3-
local Escort = subclass(Action, function(self, target, offset)
3+
local Escort = Subclass(Action, function(self, target, offset)
44
self.target = target
55
self.offset = offset
66
end)

script/GameObjects/Actions/MaraudAt.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local Action = require('GameObjects.Action')
22

3-
local MaraudAt = subclass(Action, function(self, zone, radius)
3+
local MaraudAt = Subclass(Action, function(self, zone, radius)
44
self.radius = radius
55
self.targetPosition = nil
66
self.system = nil

script/GameObjects/Actions/MineAt.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ local Action = require('GameObjects.Action')
33
local kLeadTime = 1.0
44
local orbitTime = 30
55

6-
local MineAt = subclass(Action, function(self, source, target, miningTimePerItem)
6+
local MineAt = Subclass(Action, function(self, source, target, miningTimePerItem)
77
assert(source:hasYield())
88
self.source = source
99
self.target = target

script/GameObjects/Actions/MoveTo.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local Action = require('GameObjects.Action')
44
local rng = RNG.FromTime()
55
local timeUntilTravelDrive = 15 -- temporary local setting
66

7-
local MoveTo = subclass(Action, function(self, target, range, useTravelDrive)
7+
local MoveTo = Subclass(Action, function(self, target, range, useTravelDrive)
88
self.target = target
99
self.range = range
1010
self.useTravelDrive = useTravelDrive

script/GameObjects/Actions/MoveToPos.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local Action = require('GameObjects.Action')
44
local rng = RNG.FromTime()
55
local timeUntilTravelDrive = 15 -- temporary local setting
66

7-
local MoveToPos = subclass(Action, function(self, targetPos, range, useTravelDrive)
7+
local MoveToPos = Subclass(Action, function(self, targetPos, range, useTravelDrive)
88
self.targetPos = targetPos
99
self.range = range
1010
self.useTravelDrive = useTravelDrive

script/GameObjects/Actions/Orbit.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local Action = require('GameObjects.Action')
22

3-
local Orbit = subclass(Action, function(self, target, radius, orbitTime)
3+
local Orbit = Subclass(Action, function(self, target, radius, orbitTime)
44
self.target = target
55
self.orbitRadius = radius
66
self.orbitTime = orbitTime

script/GameObjects/Actions/Patrol.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local Action = require('GameObjects.Action')
22

3-
local Patrol = subclass(Action, function(self, patrolNodes)
3+
local Patrol = Subclass(Action, function(self, patrolNodes)
44
self.patrolNodes = patrolNodes
55
self.patrolCurrentNodeIndex = 1
66
self.system = nil

script/GameObjects/Actions/Repeat.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local Action = require('GameObjects.Action')
22

3-
local Repeat = subclass(Action, function(self, actions)
3+
local Repeat = Subclass(Action, function(self, actions)
44
self.actions = actions
55
end)
66

script/GameObjects/Actions/Think.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
local Action = require('GameObjects.Action')
22
local Player = require('GameObjects.Entities.Player')
33

4-
local Think = subclass(Action, function(self)
4+
local Think = Subclass(Action, function(self)
55
self.timer = 0
66
self.rng = RNG.FromTime()
77
end)
@@ -51,7 +51,7 @@ function Think:manageAsset(asset)
5151
asset:pushAction(bestJob)
5252
end
5353
end
54-
]]--
54+
]] --
5555

5656
-- Use payout, not flow
5757
function Think:manageAsset(asset)

script/GameObjects/Actions/Undock.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local Action = require('GameObjects.Action')
22

3-
local Undock = subclass(Action, function(self) end)
3+
local Undock = Subclass(Action, function(self) end)
44

55
function Undock:clone()
66
return Undock()

script/GameObjects/Actions/Wait.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local Action = require('GameObjects.Action')
22

3-
local Wait = subclass(Action, function(self, duration)
3+
local Wait = Subclass(Action, function(self, duration)
44
self.duration = duration
55
self.t = 0
66
end)

script/GameObjects/Elements/Components/Armor.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
local Entity = require('GameObjects.Entity')
22
local SocketType = require('GameObjects.Entities.Ship.SocketType')
33

4-
local Armor = subclass(Entity, function(self)
4+
local Armor = Subclass(Entity, function(self)
55
self.name = Config.gen.compArmorStats.name
66
self.healthCurr = Config.gen.compArmorStats.healthCurr
77
self.healthMax = Config.gen.compArmorStats.healthMax

script/GameObjects/Elements/Components/Capacitor.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ local Bindings = require('States.ApplicationBindings')
1717
local shared
1818
local rng = RNG.FromTime()
1919

20-
local Capacitor = subclass(Entity, function(self)
20+
local Capacitor = Subclass(Entity, function(self)
2121
-- All of this crap is completely worthless, but updateCapacitor() will not be called without it
2222
if not shared then
2323
shared = {}

script/GameObjects/Elements/Components/Cloak.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local SocketType = require('GameObjects.Entities.Ship.SocketType')
55
local shared
66
local rng = RNG.FromTime()
77

8-
local Cloak = subclass(Entity, function(self)
8+
local Cloak = Subclass(Entity, function(self)
99
-- All of this crap is completely worthless, but updateCloak() will not be called without it
1010
if not shared then
1111
shared = {}

script/GameObjects/Elements/Components/Communicator.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local SocketType = require('GameObjects.Entities.Ship.SocketType')
55
local shared
66
local rng = RNG.FromTime()
77

8-
local Communicator = subclass(Entity, function(self)
8+
local Communicator = Subclass(Entity, function(self)
99
-- All of this crap is completely worthless, but updateCommunicator() will not be called without it
1010
if not shared then
1111
shared = {}

script/GameObjects/Elements/Components/Computer.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local SocketType = require('GameObjects.Entities.Ship.SocketType')
55
local shared
66
local rng = RNG.FromTime()
77

8-
local Computer = subclass(Entity, function(self)
8+
local Computer = Subclass(Entity, function(self)
99
-- All of this crap is completely worthless, but updateComputer() will not be called without it
1010
if not shared then
1111
shared = {}

script/GameObjects/Elements/Components/Hull.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
local Entity = require('GameObjects.Entity')
22
local SocketType = require('GameObjects.Entities.Ship.SocketType')
33

4-
local Hull = subclass(Entity, function(self)
4+
local Hull = Subclass(Entity, function(self)
55
self.name = Config.gen.compHullStats.name
66
self.healthCurr = Config.gen.compHullStats.healthCurr
77
self.healthMax = Config.gen.compHullStats.healthMax

script/GameObjects/Elements/Components/Inventory.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local SocketType = require('GameObjects.Entities.Ship.SocketType')
55
local shared
66
local rng = RNG.FromTime()
77

8-
local Inventory = subclass(Entity, function(self)
8+
local Inventory = Subclass(Entity, function(self)
99
-- Required to be able to use plugs
1010
if not shared then
1111
shared = {}

script/GameObjects/Elements/Components/Sensor.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local SocketType = require('GameObjects.Entities.Ship.SocketType')
55
local shared
66
local rng = RNG.FromTime()
77

8-
local Sensor = subclass(Entity, function(self)
8+
local Sensor = Subclass(Entity, function(self)
99
-- All of this crap is completely worthless, but updateSensor() will not be called without it
1010
if not shared then
1111
shared = {}

script/GameObjects/Elements/Components/Shield.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ local Bindings = require('States.ApplicationBindings')
2020
local shared
2121
local rng = RNG.FromTime()
2222

23-
local Shield = subclass(Entity, function(self)
23+
local Shield = Subclass(Entity, function(self)
2424
-- All of this crap is completely worthless, but updateShield() will not be called without it
2525
if not shared then
2626
shared = {}

script/GameObjects/Elements/Economy/BlackMarket.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ local function addOrder(type, self, actor, item, count, price)
3838
sort(orders, type.comparator)
3939
end
4040

41-
local BlackMarket = class(function(self)
41+
local BlackMarket = Class(function(self)
4242
self.data = {}
4343
self.escrow = {}
4444
end)

script/GameObjects/Elements/Economy/Economy.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ local updateRates = {
1111
[4] = 2 -- Patrolling
1212
}
1313

14-
local Economy = class(function(self, parent)
14+
local Economy = Class(function(self, parent)
1515
self.parent = parent
1616
self.factories = {}
1717
self.flows = {}

script/GameObjects/Elements/Economy/Factory.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ local Item = require('Systems.Economy.Item')
33

44
--------------------------------------------------------------------------------
55

6-
local Factory = class(function(self, parent)
6+
local Factory = Class(function(self, parent)
77
self.parent = parent
88
self.prods = {}
99
self.time = 0

script/GameObjects/Elements/Economy/Market.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ local function addOrder(type, self, actor, item, count, price)
3838
sort(orders, type.comparator)
3939
end
4040

41-
local Market = class(function(self)
41+
local Market = Class(function(self)
4242
self.data = {}
4343
self.escrow = {}
4444
end)

script/GameObjects/Elements/Economy/Yield.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ local Entity = require('GameObjects.Entity')
33
-- NOTE : The 'size' of an entity's yield serves as a rate limiter. No more
44
-- than 'size' (energy-normalized) units of item may be extracted per
55
-- unit time from the Entity.
6-
local Yield = class(function(self, item, size)
6+
local Yield = Class(function(self, item, size)
77
self.item = item
88
self.size = size
99
self.maxSize = size

script/GameObjects/Elements/NPC/BlackMarketTrader.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ local Item = require('Systems.Economy.Item')
77
-- NOTE: All the evaluations below are made from the perspective of what is most
88
-- advantageous to _this trader_ (self).
99

10-
local BlackMarketTrader = class(function(self, parent)
10+
local BlackMarketTrader = Class(function(self, parent)
1111
self.parent = parent
1212
self.elems = {}
1313
end)

0 commit comments

Comments
 (0)