charles wrote: ↑Sun Oct 08, 2017 2:48 am
Grumblesaur wrote: ↑Sat Oct 07, 2017 9:25 pm
If the scripting portion of the engine is multithreaded, and you assign a thread for every script, threads will be distributed by the operating system across as many cores as the engine is made aware of.
from the
Lua reference manual
Lua supports coroutines, also called collaborative multithreading. A coroutine in Lua represents an independent thread of execution. Unlike threads in multithread systems, however, a coroutine only suspends its execution by explicitly calling a yield function.
Now that doesn't stop the game engine using O/S mutlithreading for, possibly as an example, graphics rendering and display.
regards,
Charles
JoshParnell wrote: ↑Wed Oct 04, 2017 1:13 pm
(note the symmetry with how we store 'as little data as possible' in CTypes by using native memory, pools, static typing, etc.) This means, for example, that an AI player who is travelling to a location does not enter a state where the script constantly checks whether the player has arrived at the destination. This is wasteful and fails to exploit the sparsity of the situation (the probability of arrival is exceptionally low on any given frame). Instead, the script informs the engine of the specific condition(s) upon which it should be resumed: "Dear engine, I am writing to inform you that I no longer require CPU cycles until my client, Sir NotEdisonTrent III, aka 'Trent', arrives within 100 metres of the asteroid @ memory address 0xA513701D.
This is beautiful.
Another reason to use Lua.
It's simplicity is amazing, and isn't that the whole concept of limit theory?
Wow, I'm so blown away I'm lost for words
A coroutine can terminate its execution in two ways: normally, when its main function returns (explicitly or implicitly, after the last instruction); and abnormally, if there is an unprotected error. In case of normal termination, coroutine.resume returns true, plus any values returned by the coroutine main function. In case of errors, coroutine.resume returns false plus an error object.
And in this scenario, the False could be the ship flying into an asteroid (oops!) or got blown up by a pirate!
JoshParnell wrote: ↑Wed Oct 04, 2017 1:13 pm
Alternatively, if my client should be the victim of an attack, I would like to be notified in spite of not having arrived at said asteroid.
JoshParnell wrote: ↑Wed Oct 04, 2017 1:13 pm
If the underlying logic engine is clever with respect to how it services such a request, then the difference here is the difference between being able to run a few hundred AI units vs. being able to run a few hundred thousand (not that we need to run a few hundred thousand -- but keep in mind that if we consider all the
other logic going on in the game, then indeed, we are looking at on the order of a few hundred thousand bits of logic). It's an orders-of-magnitude subject, like many things in computing.
Thanks again Adam, not only are we receiving excellent posts from both of you, we can now link how both of you are working on similar items, I'm not an American, but I just have to say one word: Awesome!
Have FUN!
P.S. The crashing into the asteroid could even be one of those darn-fangled 'roids with engines attached - someone's moving their mobile base from La Grange to a space lane to disrupt transit routes for the Inner worlds. Stock markets will be affected and oh, Sir NotEdisonTrent III, buys the farm.
I'm loving the chances for so many emergent gameplay elements from narky AI, to faction warefare just let rip - am I getting too excited?