Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


Multithreaded Scripting (LUA?)


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 BenS1   Members   -  Reputation: 337

Like
0Likes
Like

Posted 21 November 2012 - 03:36 AM

Hi,

I'm planning on adding a scripting interface to my game to my RTS game, however most stuff I've read on scripting interfaces seems to only allow a single thread of script execution where as I would like to make use of all the available cores.

For example, lets imagine I have 50 units in play at a particular instant in time. For each unit I may periodically fire an Update event that causes a piece of script to be executed. The script can then do whatever it likes, such as initiate a move order, or fire a weapon etc.

In a single threaded scripting engine I'd have to call the Update() script code for each of the 50 units one after the other, but if I have a machine with 8 cores then I might want to allow 6 threads of scripting (Leaving 2 for the main game and rendering etc), so multiple Updates scripts can run in parallel.

I'd obviously need to manage the usual multithreading data sharing type things, so for example any 2 functions running in parallel would not be able to access the same data (Unless its constant or has some kind of mutex type access control, but I'd rather not expose that to the script).

I could allow per Unit read/writable data by guaranteeing that for any one unit only a single thread of execution is running (For example, if an Update event and a HitDamage event is fired for a single unit then each of the associated functions must be run sequentially, not in parallel).

So, getting to the actual question... are there any scripting languages out there that support this (Plus the other usual prereq's such as being relatively fast, simple to learn\understand etc)?

As LUA seems to be the language of choice for game scripting (Although I'm not 100% sure why), do you know if LUA supports multithreading?

Note that I don't want explicit multithreading from the scripts. i.e. I don't want the scripts to have functions to launch threads, have synchronisation functions etc. I think things such a LUA Lanes are explicit threading libraries for LUA, and so doesn't meet this requirement.

I've actually written such a scripting system before as part of my day job, but that was about 10 years ago, and the code isn't really suitable for inclusion in a game.

Any help would be appreciated.

Thanks
Ben

Sponsor:

#2 slicer4ever   Crossbones+   -  Reputation: 3942

Like
1Likes
Like

Posted 21 November 2012 - 03:53 AM

angelscript supports multithreaded environments, i'd highly recommend it over LUA.
Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

#3 Hodgman   Moderators   -  Reputation: 30882

Like
2Likes
Like

Posted 21 November 2012 - 04:28 AM

I've not used Lua across multiple threads before, but from what I understand, you have to create a separate Lua state for each thread to use, and have to disable the garbage collector from automatically triggering.
The issue is that the Lua GC interacts with every Lua state, so you have to manually trigger the GC process at appropriate times (when you know that no Lua states are in use).

#4 BenS1   Members   -  Reputation: 337

Like
0Likes
Like

Posted 21 November 2012 - 07:17 AM

angelscript supports multithreaded environments, i'd highly recommend it over LUA.


Thanks slicer4ever,

Other than the multithreading, what other reasons do you recommend AngelScript over LUA?

To be honest, I'm a little surprised that more traditional/established languages aren't used such as Javascript, BASIC, PASCAL etc.

Thanks
Ben

#5 BenS1   Members   -  Reputation: 337

Like
0Likes
Like

Posted 21 November 2012 - 07:18 AM

I've not used Lua across multiple threads before, but from what I understand, you have to create a separate Lua state for each thread to use, and have to disable the garbage collector from automatically triggering.
The issue is that the Lua GC interacts with every Lua state, so you have to manually trigger the GC process at appropriate times (when you know that no Lua states are in use).


Thanks Hodgeman, I'll see if I can find out some more info about that.

Thanks
Ben

#6 Toothpix   Crossbones+   -  Reputation: 810

Like
0Likes
Like

Posted 21 November 2012 - 09:43 AM

You could always use AngelScript, which has gained popularity recently, and you could also add that functionality yourself in LUA with POSIX threads or something. LUA is written in ANSI C.

C dominates the world of linear procedural computing, which won't advance. The future lies in MASSIVE parallelism.


#7 slicer4ever   Crossbones+   -  Reputation: 3942

Like
0Likes
Like

Posted 21 November 2012 - 09:54 AM


angelscript supports multithreaded environments, i'd highly recommend it over LUA.


Thanks slicer4ever,

Other than the multithreading, what other reasons do you recommend AngelScript over LUA?

To be honest, I'm a little surprised that more traditional/established languages aren't used such as Javascript, BASIC, PASCAL etc.

Thanks
Ben


it's a bit of personal taste, but i personally hate type-less languages, i use them, but i absolutely hate what they can imply.

also, angelscript is hands down far easier to register with your game, lua requires a bit of hassle to easily and dynamically register functions from your game/engine to be used, where as angelscript is incredible simple, i can also completely disable GC on all my types, by passing one simple flag when creating a new type.

it's really leagues better imo, but that is just my opinion.
Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

#8 Necrolis   Members   -  Reputation: 1354

Like
0Likes
Like

Posted 21 November 2012 - 10:40 AM

it's a bit of personal taste, but i personally hate type-less languages, i use them, but i absolutely hate what they can imply.

also, angelscript is hands down far easier to register with your game, lua requires a bit of hassle to easily and dynamically register functions from your game/engine to be used, where as angelscript is incredible simple, i can also completely disable GC on all my types, by passing one simple flag when creating a new type.

it's really leagues better imo, but that is just my opinion.

LuaJIT's FFI totally elimination the no-so-fun binding process to register script function, it also has many other advances over standard Lua, plus it just came out of beta :) there is a far better GC in the works as well to eliminate a lot of common problems with the GC's too. IMO, for game stuff, if your going to look at Lua, skip vanilla Lua and go straight to LuaJIT




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS