• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
BenS1

Multithreaded Scripting (LUA?)

7 posts in this topic

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
0

Share this post


Link to post
Share on other sites
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 ([i]when you know that no Lua states are in use[/i]).
2

Share this post


Link to post
Share on other sites
[quote name='slicer4ever' timestamp='1353491588' post='5002875']
angelscript supports multithreaded environments, i'd highly recommend it over LUA.
[/quote]

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
0

Share this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1353493715' post='5002884']
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 ([i]when you know that no Lua states are in use[/i]).
[/quote]

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

Thanks
Ben
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
[quote name='BenS1' timestamp='1353503852' post='5002907']
[quote name='slicer4ever' timestamp='1353491588' post='5002875']
angelscript supports multithreaded environments, i'd highly recommend it over LUA.
[/quote]

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
[/quote]

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.
0

Share this post


Link to post
Share on other sites
[quote name='slicer4ever' timestamp='1353513261' post='5002925']
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.
[/quote]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
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0