Skip to content

Commit 4bf6923

Browse files
committed
Merge remote-tracking branch 'origin/main' into feat/ecs
2 parents 9b5670b + 554b092 commit 4bf6923

33 files changed

+613
-310
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
.idea/
1515
.vs/
1616
.vscode/
17+
.zed/
1718
cmake-build-*/
1819

1920
## OS Junk files

Cargo.lock

+26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Limit Theory Redux is a fork of the now-cancelled open world space simulation ga
66

77
This repository continues the game and engine code from the second generation of LT's development, when all work was originally migrated to C/C++ and Lua, which we have since ported to Rust and Lua. For the older, C++/LTSL version of Limit Theory, see https://github.com/JoshParnell/ltheory-old.
88

9+
[Documentation](doc/README.md).
10+
911
## Contributing to Limit Theory Redux
1012
See [CONTRIBUTING.md](CONTRIBUTING.md) for more information.
1113

File renamed without changes.
File renamed without changes.

doc/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Limit Theory Redux documentation
2+
3+
1. [Engine](engine/README.md)
4+
- [Phx](../engine/lib/phx/README.md)
5+
- [HmGui](../engine/lib/phx/src/ui/hmgui/README.md)
6+
- [LuaJIT FFI](../engine/lib/luajit-ffi-gen/README.md)
7+
- [Engine Workers](../engine/lib/phx/src/engine/task_queue/README.md)
8+
2. [Scripting](script/README.md)
9+
- [Lua Workers](script/workers.md)
10+
- [HmGui](../script/UI/HmGui/README.md)
11+
3. [Full structure](LTheory%20Full%20Restructure.md)
12+
4. [Control keys](GameControlKeys.txt)

doc/engine/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# LTR Engine documentation
2+
3+
1. [Phx](../../engine/lib/phx/README.md)
4+
2. [HmGui](../../engine/lib/phx/src/ui/hmgui/README.md)
5+
3. [LuaJIT FFI](../../engine/lib/luajit-ffi-gen/README.md)
6+
4. [Engine Workers](../../engine/lib/phx/src/engine/task_queue/README.md)

doc/script/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# LTR Scripting documentation
2+
3+
1. [Lua Workers](workers.md)
4+
1. [HmGui](../../script/UI/HmGui/README.md)

doc/script/workers.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# LTR Lua Workers
2+
3+
Lua Worker is based on the engine worker and allows to run Lua code in the new Lua state in a separate thread.
4+
5+
[TaskQueue](../../engine/lib/phx/script/meta/TaskQueue.lua)([ext](../../engine/lib/phx/script/ffi_ext/TaskQueue.lua)) object is used to create and manage workers. To send data between workers and main thread [Payload](../../engine/lib/phx/script/meta/Payload.lua) object is used.
6+
7+
Steps to create a new worker and run it:
8+
1. Create a new worker function in a separate file, see [TestWorkerFunction](../../script/States/App/Tests/TestWorkerFunction.lua) for example.
9+
- Use `WorkerFunction.Create()` to create a worker function. As an input parameter it accepts a callback function with a single input parameter that can be either a simple type (integer, string, etc.) or **Payload**, and that returns an optional output of the same type (simple or **Payload**).
10+
2. Create and run worker, see [WorkerTest](../../script/States/App/Tests/WorkerTest.lua) for example.
11+
1. Create and start worker with a new worker type:
12+
```lua
13+
local workerId = TaskQueue:startWorker("MyWorker", "MyWorkerFunction.lua", 1)
14+
```
15+
It is possible to run multiple instances of the worker for load balancing purposes.
16+
Creation of the worker adds new element to the `WorkerId` table: `WorkerId.MyWorker`.
17+
2. To send message to the worker use `TaskQueue:sendTask()`:
18+
```lua
19+
local taskId = TaskQueue:sendTask(workerId, payload)
20+
```
21+
3. To read message from the worker:
22+
```lua
23+
local taskId, payload = TaskQueue:nextTaskResult(workerId)
24+
```
25+
If `taskId == nil` then worker queue doesn't have any output messages.
26+
27+
In the main game loop send messages to corresponding workers and then check each frame for response from them.
File renamed without changes.

engine/lib/phx/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ luajit-ffi-gen.workspace = true
1919
# external crates
2020
arboard = "3.4"
2121
chrono = "0.4"
22+
cli-table = { version = "0.4", default-features = false }
2223
crossbeam = "0.8"
2324
directories = "5.0"
2425
flate2 = "1.0"

engine/lib/phx/script/ffi_common/Profiler.lua

-33
This file was deleted.

engine/lib/phx/script/ffi_ext/TaskQueue.lua

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@ local libphx = require('libphx').lib
22
local PayloadConverter = require('Core.Util.PayloadConverter')
33

44
function onDef_TaskQueue_t(t, mt)
5-
mt.__index.startWorker = function(self, workerId, workerName, scriptPath, instancesCount)
5+
mt.__index.startWorker = function(self, workerName, scriptPath, instancesCount)
6+
-- TODO: fix this if possible
7+
-- -@class WorkerId
8+
-- -@field workerName integer
9+
WorkerId.Register(workerName)
10+
11+
local workerId = WorkerId[workerName]
612
if not libphx.TaskQueue_StartWorker(self, workerId, workerName, scriptPath, instancesCount) then
713
Log.Error("Cannot start worker: " .. workerName)
814
end
15+
return workerId
916
end
1017

1118
mt.__index.sendTask = function(self, workerId, data)

engine/lib/phx/script/ffi_ext/WorkerId.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ function onDef_WorkerId(t, mt)
44
---@class WorkerId
55
---@field Register fun(workers: table<string>) Register a new worker types to the WorkerId table. Fail if worker already exists.
66
t.Register = function(newWorkers)
7-
if type(newWorkers) ~= 'table' then
7+
if type(newWorkers) == 'string' then
8+
newWorkers = { newWorkers }
9+
elseif type(newWorkers) ~= 'table' then
810
Log.Error("new workers should be in a table")
911
return
1012
end
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
-- AUTO GENERATED. DO NOT MODIFY!
2+
-- Profiler --------------------------------------------------------------------
3+
local Loader = {}
4+
5+
function Loader.declareType()
6+
return 0, 'Profiler'
7+
end
8+
9+
function Loader.defineType()
10+
local ffi = require('ffi')
11+
local libphx = require('libphx').lib
12+
local Profiler
13+
14+
do -- C Definitions
15+
ffi.cdef [[
16+
void Profiler_Enable ();
17+
void Profiler_Disable ();
18+
void Profiler_Begin (cstr name);
19+
void Profiler_End ();
20+
void Profiler_SetValue (cstr name, int value);
21+
void Profiler_LoopMarker ();
22+
void Profiler_Backtrace ();
23+
]]
24+
end
25+
26+
do -- Global Symbol Table
27+
Profiler = {
28+
Enable = libphx.Profiler_Enable,
29+
Disable = libphx.Profiler_Disable,
30+
Begin = libphx.Profiler_Begin,
31+
End = libphx.Profiler_End,
32+
SetValue = libphx.Profiler_SetValue,
33+
LoopMarker = libphx.Profiler_LoopMarker,
34+
Backtrace = libphx.Profiler_Backtrace,
35+
}
36+
37+
if onDef_Profiler then onDef_Profiler(Profiler, mt) end
38+
Profiler = setmetatable(Profiler, mt)
39+
end
40+
41+
return Profiler
42+
end
43+
44+
return Loader

engine/lib/phx/script/ffi_gen/TimeStamp.lua

+19-17
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,26 @@ function Loader.defineType()
1717

1818
do -- C Definitions
1919
ffi.cdef [[
20-
void TimeStamp_Free (TimeStamp*);
21-
TimeStamp* TimeStamp_Now ();
22-
TimeStamp* TimeStamp_GetFuture (double seconds);
23-
double TimeStamp_GetDifference (TimeStamp const*, TimeStamp const* endTime);
24-
double TimeStamp_GetElapsed (TimeStamp const*);
25-
double TimeStamp_GetElapsedMs (TimeStamp const*);
26-
TimeStamp* TimeStamp_GetRelative (TimeStamp const*, double seconds);
27-
double TimeStamp_ToDouble (TimeStamp const*);
28-
uint64 TimeStamp_ToSeconds (TimeStamp const*);
20+
void TimeStamp_Free (TimeStamp*);
21+
TimeStamp* TimeStamp_Now ();
22+
TimeStamp* TimeStamp_GetFuture (double seconds);
23+
double TimeStamp_GetDifference (TimeStamp const*, TimeStamp const* endTime);
24+
double TimeStamp_GetElapsed (TimeStamp const*);
25+
double TimeStamp_GetElapsedMs (TimeStamp const*);
26+
TimeStamp* TimeStamp_GetRelative (TimeStamp const*, double seconds);
27+
double TimeStamp_ToDouble (TimeStamp const*);
28+
uint64 TimeStamp_ToSeconds (TimeStamp const*);
29+
uint32 TimeStamp_ToSubsecMillis (TimeStamp const*);
2930
]]
3031
end
3132

3233
do -- Global Symbol Table
3334
TimeStamp = {
34-
Now = function()
35+
Now = function()
3536
local _instance = libphx.TimeStamp_Now()
3637
return Core.ManagedObject(_instance, libphx.TimeStamp_Free)
3738
end,
38-
GetFuture = function(seconds)
39+
GetFuture = function(seconds)
3940
local _instance = libphx.TimeStamp_GetFuture(seconds)
4041
return Core.ManagedObject(_instance, libphx.TimeStamp_Free)
4142
end,
@@ -49,15 +50,16 @@ function Loader.defineType()
4950
local t = ffi.typeof('TimeStamp')
5051
local mt = {
5152
__index = {
52-
getDifference = libphx.TimeStamp_GetDifference,
53-
getElapsed = libphx.TimeStamp_GetElapsed,
54-
getElapsedMs = libphx.TimeStamp_GetElapsedMs,
55-
getRelative = function(self, seconds)
53+
getDifference = libphx.TimeStamp_GetDifference,
54+
getElapsed = libphx.TimeStamp_GetElapsed,
55+
getElapsedMs = libphx.TimeStamp_GetElapsedMs,
56+
getRelative = function(self, seconds)
5657
local _instance = libphx.TimeStamp_GetRelative(self, seconds)
5758
return Core.ManagedObject(_instance, libphx.TimeStamp_Free)
5859
end,
59-
toDouble = libphx.TimeStamp_ToDouble,
60-
toSeconds = libphx.TimeStamp_ToSeconds,
60+
toDouble = libphx.TimeStamp_ToDouble,
61+
toSeconds = libphx.TimeStamp_ToSeconds,
62+
toSubsecMillis = libphx.TimeStamp_ToSubsecMillis,
6163
},
6264
}
6365

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
-- AUTO GENERATED. DO NOT MODIFY!
2+
---@meta
3+
4+
---@class Profiler
5+
Profiler = {}
6+
7+
-- Enables profiling and initializes the profiler state
8+
function Profiler.Enable() end
9+
10+
-- Disables profiling and processes results
11+
function Profiler.Disable() end
12+
13+
-- Starts a new profiling scope
14+
---@param name string
15+
function Profiler.Begin(name) end
16+
17+
-- Ends the current profiling scope
18+
function Profiler.End() end
19+
20+
---@param name string
21+
---@param value integer
22+
function Profiler.SetValue(name, value) end
23+
24+
-- Records frame timing for each active scope
25+
function Profiler.LoopMarker() end
26+
27+
-- Prints backtrace of active scopes
28+
function Profiler.Backtrace() end
29+

engine/lib/phx/script/meta/TaskQueue.lua

+1-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
TaskQueue = {}
99

1010
-- Start Lua worker with provided script file.
11-
---@param workerId integer
12-
---@param workerName string
13-
---@param scriptPath string
14-
---@param instancesCount integer
15-
---@return boolean
11+
---@overload fun(self: table, workerName: string, scriptPath: string, instancesCount: integer): integer
1612
function TaskQueue:startWorker(workerId, workerName, scriptPath, instancesCount) end
1713

1814
-- Stop Lua worker and remove it from the queue.

engine/lib/phx/script/meta/TimeStamp.lua

+4
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,7 @@ function TimeStamp:toDouble() end
3939
---@return integer
4040
function TimeStamp:toSeconds() end
4141

42+
-- Returns the fractional part in whole milliseconds.
43+
---@return integer
44+
function TimeStamp:toSubsecMillis() end
45+

engine/lib/phx/src/engine/engine.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -429,10 +429,10 @@ impl Engine {
429429
}
430430

431431
pub fn update() {
432+
Profiler::begin("Engine_Update");
432433
unsafe {
433-
Profiler_Begin(c_str!("Engine_Update"));
434434
Metric_Reset();
435-
Profiler_End();
436435
}
436+
Profiler::end();
437437
}
438438
}

0 commit comments

Comments
 (0)