Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ECS.lua

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions ECS_concat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,9 @@ __F__["ECS"] = function()
if (game and game.ClassName == "DataModel") then
-- is roblox
setLoopManager(__REQUIRE__("RobloxLoopManager")())
elseif (CreateThread and Wait and GetGameTimer and IsDuplicityVersion) then
-- is FiveM (CitizenFX)
setLoopManager(__REQUIRE__("FiveMLoopManager")())
end
end)

Expand Down Expand Up @@ -1399,6 +1402,45 @@ __F__["Event"] = function()

end

__F__["FiveMLoopManager"] = function()
-- src/FiveMLoopManager.lua
local function InitManager()

return {
Register = function(world)
local running = true

-- IsDuplicityVersion() returns true on the server. On the server there is
-- nothing to render, so the "render" step is skipped there.
local isServer = IsDuplicityVersion()

CreateThread(function()
while running do
-- GetGameTimer() returns milliseconds, the Timer expects seconds
local now = GetGameTimer() / 1000

world:Update("process", now)
world:Update("transform", now)

if (not isServer) then
world:Update("render", now)
end

Wait(0)
end
end)

return function()
running = false
end
end
}
end

return InitManager

end

__F__["Query"] = function()
-- src/Query.lua

Expand Down
21 changes: 11 additions & 10 deletions build.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ local SRC_FILES = {
"Entity",
"EntityRepository",
"Event",
"FiveMLoopManager",
"Query",
"QueryResult",
"RobloxLoopManager",
Expand Down Expand Up @@ -69,22 +70,22 @@ local function concat()
" __M__[m] = { r = __F__[m]() }",
" end",
" return __M__[m].r",
"end",
"",
"end",
"",
}

for i,name in ipairs(SRC_FILES) do
local sourceFile = io.open("./src/"..name..".lua", "r")
if not sourceFile then
error("Could not open the input file `" .. OUTPUT_MINIFIED .. "`", 0)
end

local content = sourceFile:read( "*a" )

for _,oname in ipairs(SRC_FILES) do
content = content:gsub('require[(]["\']'..oname..'["\'][)]', '__REQUIRE__("'..oname..'")')
end

table.insert(concatContent, table.concat({
'__F__["'..name..'"] = function()',
(" -- src/"..name..".lua\n"..content):gsub("\n", "\n "),
Expand All @@ -93,14 +94,14 @@ local function concat()
}, "\n"))
sourceFile:close()
end

table.insert(concatContent, 'return __REQUIRE__("ECS")')

-- write ECS_concat.lua
local fileConcat = io.open(OUTPUT_CONCAT..".lua", "w" )
fileConcat:write( table.concat(concatContent, "\n"))
fileConcat:close()
fileConcat:close()

-- teste import
local ecsConcat = require(OUTPUT_CONCAT)
_G.ECS = nil
Expand Down
3 changes: 3 additions & 0 deletions src/ECS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ pcall(function()
if (game and game.ClassName == "DataModel") then
-- is roblox
setLoopManager(require("RobloxLoopManager")())
elseif (CreateThread and Wait and GetGameTimer and IsDuplicityVersion) then
-- is FiveM (CitizenFX)
setLoopManager(require("FiveMLoopManager")())
end
end)

Expand Down
34 changes: 34 additions & 0 deletions src/FiveMLoopManager.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
local function InitManager()

return {
Register = function(world)
local running = true

-- IsDuplicityVersion() returns true on the server. On the server there is
-- nothing to render, so the "render" step is skipped there.
local isServer = IsDuplicityVersion()

CreateThread(function()
while running do
-- GetGameTimer() returns milliseconds, the Timer expects seconds
local now = GetGameTimer() / 1000

world:Update("process", now)
world:Update("transform", now)

if (not isServer) then
world:Update("render", now)
end

Wait(0)
end
end)

return function()
running = false
end
end
}
end

return InitManager