[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Embedding LUA/Multithread
- From: Adolf Mathias <dolfi@...>
- Date: Mon, 15 Jan 2001 09:47:08 +0000
David Diaz wrote:
>
> I've been taking a look to messages that talk about co-routines
> but I still don't understand what they are. I've seen some
> examples but I don't understand them. It seemed like routines
> call themselves in such a recursive way but I need multithred
> to be transparent to the script designers.
I assume that script designers write scripts that direct the behavior of
game characters. But doesn't multithreading make the issue of
communication between the actors much more difficult than necessary?
Also, who guarantees you that each character handler thread gets invoked
once per video frame? I would suggest the following approach: each
character has (at least) an update and a draw routine, e.g.
(please forgive the militaristic example)
function update_enemy(self, dt)
-- simulate hostility
self.xpos = dt*self.xspeed
self.xpos = dt*self.yspeed
self.firing_counter = self.firing_counter+1
if self.firing and self.firing_counter>=self.firing_rate then
create_missile(self.xpos, self.ypos, self.firing_xdir,
self.firing_ydir)
self.firing_counter = self.firing_counter-self.firing_rate
end
end
function draw_enemy(self)
...
end
function update_missile(self, dt) ... end
function draw_missile(self) ... end
function check_collisions(living_enemies, active_missiles)
function main_update
local dt = 0.02
-- deal with input...
for i, v in living_enemies do update_enemy(v, dt) end
for i, v in active_missiles do update_missile(v, dt) end
check_collisions(living_enemies, active_missiles)
for i, v in living_enemies do draw_enemy(v, dt) end
for i, v in active_missiles do draw_missile(v, dt) end
end
With update_enemy I've tried to point out the programming style your
character scripters would have to adopt, which in my eyes is
significantly less complex than the multithreaded variety. They would
have to deal with some sort of synchronization among each other and the
redraw cycle (mutexes or semaphores)
Please forgive if I haven't got the right idea about how your style of
game -- but the real-time games that come into my mind would fit into
the above structure. Just replace enemy and missile with whatever entity
you have in the game, be it monsters, a pacman, asteroids, hideous quake
creatures, racing cars, skiers...
Dolfi
--
Adolf Mathias EMail: dolfi at zkm dot de Web: www.zkm.de
|||| / |< ||| ZKM Institute for Visual Media - Institut für Bildmedien
P.B. 6919 D-76049 Karlsruhe, Germany; fon +49 721-8100-1544, fax -1509