Jump to content
  • Advertisement
Sign in to follow this  
mwmey1

Need guidance on concurrent scripts

This topic is 3607 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all, My aim is to have a script executing for each NPC in my game, often several at once (C++, Lua). Using one state corrupts the stack and I end up with a bunch of runtime errors because I've popped a bad value. Giving each NPC it's own lua-state seems like overkill to me. Especially since I would (correct me if I'm wrong) have to register my C++ utility functions for every state. I'm happy to do it if there's no better way. Co-routines make scripts take turns running (?), is this ideal when various scripts will be running constantly. The question really is: conceptually, how should I approach this scenario? Importance is placed on performance/reliability. Help is greatly appreciated, M [Edited by - mwmey1 on December 3, 2008 12:43:06 AM]

Share this post


Link to post
Share on other sites
Advertisement
/seconded im in EXACTLY the same quagmire atm! Im amazed how few tutorials/dicussions there are on the net regarding this. It must be such an almost fundamental issue that crops up with regard to game scripting, yet i can find practically nothing!

Im currently faced with inplementing a lua_State for EACH entitity instance. However... im actually getting (very unhelpful!) runtime errors even trying to doing that!

Share this post


Link to post
Share on other sites
Scripting isnt any different than writting code in C or C++. Do what you would normally do in those lanagues.

Rarely do you need true concurrent exectuion (ie true threads) for game logic. Normally it's done in several forms, depending upon the requirements of the game.

-Simply iterate over each entity, which contains both its logic and context within a single unit (in C++ this would be a instance of a class, in Lua it would be a table with associated metamethods etc.. ). Your entites will be stored in a container of some sort, be it table, list, array, map, etc..

-More procedrual update, where entites register with a scheduler if they have something to do. Scheduler sorts the updates in time and iterates over them, with hard timeouts if the updates exceed a given allocation. This allows you to support more entites than the brute force method but its also more complex.

If you really need true concurrent exection you will have to use external threads, as Lua doens't natively support true threads. You can run a VM in each thread, sync up any global data manually through protected accessors and use some sort of message driven programming to get around problems of locking. This is almost never worth it for game logic.

Good Luck!

-ddn

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!