Anihilnine wrote:Sorry for being so quick to be negative.
I could be wrong but my understanding is
- multicoring is achieved through threading
- threading will desync immediately
Your understanding is wrong. For the game to not desync, there is a simple condition: Every player, provided with the game state of the previous tick and all actions of all players to be processed, needs to be able to calculate the game state at the next tick deterministically (-> have same result on any hardware/software). This is perfectly achievable with various forms of multi-threading, for example:
Say we have a given game state and player input, and x0, y0, u, v, x1, y1 are all just numbers / variables:
game_state_at_tick_0 = { unit_A_position : x0, unit_B_position : y0 }
player_input_at_tick_0 = move unit_A for u, move unit_B for v
Then we use single-threaded simulation code to cacluclate next game state:
Main thread:
unit_A_pos_new = x0 + u = x1
unit_B_pos_new = y0 + v = y1
game_state_at_tick_1 = { unit_A_position : x1, unit_B_position : y1 }
or we could use muti-threading:
Thread 1:
unit_A_pos_new = x0 + u = x1
Thread 2 (at the same time):
unit_B_pos_new = y0 + v = y1
Main thread (waiting until Thread 1 & 2 have finished and then collects results):
game_state_at_tick_1 = { unit_A_position : x1, unit_B_position : y1 }
Both methods will have calculated an identical, deterministic result, and there is no desync in the simulation. You could even run clients with and without multi-threading in same game. As long as they calculate the same things, everything is fine. WHO FAST this happenes, does not matter, because faster clients simply wait for the slowest until they proceed with next sim tick.
Now, of course things get more complicated if we get into Lua coroutines and how they could be multithreaded, and i don't think that would work very well. My understanding is that Lua supports coroutines in the same way that for example Javascript supports async function execution. BUT this is very different from real multithreading, because it doesn't require REAL synchronization, locks, semaphores or whatever you need when working with state that is shared accross multiple threads.
In javascript async function (unless using webworker), you never need to worry about what a will happen to a variable when two threads try to write to it ast the SAME time, because even if functions are async, they can never be executed at the same time. because the Javascript executor runs single-threaded, like a Lua host does as well i guess.
But maybe you can to very clever things in the Lua Host that the game using. Wich leads me to the question:
Which Lua Host does the game use ot execute Lua? There are massive differences in performance between some of them, There is for example this:
http://luajit.org/Which shows massive performance improvements in regard to control structures (control structures are things like "if", "for", "while", etc..), and probably also for pure calculations, but probably does not help too much if the Lua code is bottlenecked by memory access / bad cache layout.
Edit:
I think i misunderstood Franck. He doesn't want to parallelize the Lua execution, he simply wants to call native code FROM Lua (and this native code can, of course, be multi-threaded). That should work fine.