lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi there,

I use non-pre-emptive threading, ie. each thread controls the timing when
they relinquish control - this is normally what you want in a game because
"actors" tend to need fine control of time.

Right now, I have a full C++ based non-pre-emptive threading system - kind
of a very advanced callback system where actors register a no. of functions
to be called as "Jobs" and these Jobs are either sleeping, waiting for
"signals" or are being called each frame.  I use some cunning coder magic to
make these threads appear like co-routines with *persistent* local variables
etc. and it all works quite nicely, *but* it is C++ and C++ is very limited
in power when it comes to this kind of script thread system.

So I plan to allow Lua scripts to be slotted in under this system and hide
all the coroutine "yield" commands in a "Job" module so they pass back
internal info to my main job system (info like, "sleep until signal X",
"sleep 5 frames", "change this job's priority") etc etc.  The script writers
won't be allowed to use the yield command directly, unless of course they
are using it in its basic co-routine only form.

For each object that these jobs run on, I am thinking of creating a separate
Lua global environment, this means I can selectively allow only certain
functions to be used which sanitises the environment nicely.

One problem I'm trying to figure out at the moment is how to have fast
access to vector_xyz/vector_xyzw types - if these are implemented as a table
they'll be *slow*, if they are implemented as simply x, y and z float types
they are equally slow and *very* cumbersome to use.  So I think I need to
add a new integral type to Lua?  What do you reckon Nick?  I was thinking
maybe I could create a userdata with a metatable but because the userdata's
aren't typed, I would have to associate the metatable numerous times which
might be an overhead considering how often you use these types.  Also I'd
like to allow elemental access which I think would be difficult with
userdata - ie. I still want to do things like myvec1.x = myvec2.y + 10

Regards

-- 
---------------------------------
Q-Games, Dylan Cuthbert.
http://www.q-games.com

"anderson" <anderson@badmama.com.au> wrote in message
news:bdaa1f$8b7$1@main.gmane.org...
> Hello,
>
> I was reading Dylan Cuthbert and Nick Trout emails on gaming scripts ("Re:
> Re[2]: why no "continue" statement for loops?") and it sparked my
> interested, because the script some somewhat simular to the script design,
> I'm developing in my game.   However I thought I'd start a new thread,
> because this topic is slightly different (and the subject does not match
the
> header).
>
> I was wondering how others have dealt (plan to deal) with:
> * scripted events in their games (or apps)?
> * having scripts appear to run along side an app, without the use of
> multi-threading.
>
> My example is slightly different from Trout, because my game is slightly
> different (a space ship shooter game).
>
> ------------------------
>
> /*MissionInfo is a global object, kind like a logbook of missions.*/
> MissionInfo:AddMission = "Kill whats-his-name.";
>
> WhatHisName = new BigGuy1;
> WhatHisName:x = 1000;
> WhatHisName:y = 1000;
> WhatHisName:z = 0;
> WhatHisName:health = 1000;
> WhatHisName:AI = 0; /*Very dumb*/
>
> /* Add unit to the map */
> reqAddUnit(WhatHisName);
>
> /*
>  * This is called when WhatHisName is defeated.
>  * It mite do something like change a state of some other objects that
exist
> in the world
>  * ie Killed whathisname.spt
>  *
>  * //When NoNamePeople are visited, the script "give lost treasure" is
run.
>  * evVist(NoNamePeople, "give lost treasure");
>  */
> evKilled(WhatHisName, "Killed whathisname");
>
> /*
>  * Activates the one-time only, big-guy-taunt script, which
>  * basicly makes WhatHisName say something.
>  * Player is a global object.
>  */
> evNear(Player, WhatHisName, "Big Guy Taunt");
>
> ------------------------
>
> events (ev) and requests (req) are placed on a que. Events only leave the
> queue once the event has occured. I guess events could also be programmed
as
> lua functions, but at present may are hardcoded into the engine.
>
> At the moment, this example calls other scripts when the event occurs
(note
> I'm using luabind), which is reuse friendly but I'm finding a bother to
do.
> I'm thinking of perhaps passing a lua callback function to the events.  Is
> that possible in lua? Would the functions be destroyed at the end of the
> script?  Is there a better way to do this?
>
> Anyway any ideas/suggestions/comments would be welcome, as I'm still in
the
> design stage of the scripting.
>
> --
> Trout uses threads and Cuthbert uses co-routines (which are simular I
> guess). At least for my game in the case of events, I don't think threads
> are a very good idea, because there would need to be to may of them.
>
> (I won't repeat the messages here, because it just gets too long.)
>
> Thanks,
>
> Anderson
>
>
>
>