Hejsa,
Jeg poster lige et indlæg, som jeg har postet i en udenbysk nyhedsgruppe, og
som jeg er for doven til at oversætte til dansk -- jeg håber at I alligevel
kan og gider læse det. Svarene må gerne være på dansk =)
Hi there,
I am currently designing a game which hopefully eventually will end up with
something similar to Day of The Tencale, Monkey Island, Space Quest -- with a
Diablo or Myth2 perspective (if you leave out the 3D of Myth2).
Basically an adventure game =). But I have never coded anything this big and
complicated before.
I'm writing this in C++/Linux (will hopefully be portable) and so far I've come
up with a pretty neat class design, if I may say so. Now, before I can move
on, I need to put the pieces together: Establish communication between the
game's main loop (I like to refer to this as the "server") and all the
characters (player and NPC), dorations (houses, flowers, etc.) and so forth --
these I refer to as "objects".
I was planning on implementing multiplayer/netgame, but this I've left out so
far. Still, I'd like to implement game now, so that I can expand it later with
multiplayer option. (This is why I call the main-loop "server").
Basically, what (I think) I need, is a design pattern of some sort.
I have one Server and many Objects. The server has an ObjectPool of Objects.
As I see it, there're two ways of making this work:
1) An Object have these public methods:
ObjectResponse tick( Environment e );
Image* get_image();
Location get_location();
The server iterates though its ObjectPool and calls the tick()-method of
each Object, parsing it Environmental information such as visible Objects.
The Objects (consider an NPC) then perform what they need to do, like
making a movement. If a movement is made, it changes its position,
switches to the next image in its list of walk-animation-images. It sets a
flag, say, bool got_new_image = true, in ObjectResponse and returns it to
the server. The server then reads the response, calls get_image() and
displays the new image. And off it goes to the next Object in its pool.
However, if an object takes too much time to make its move, the game would
pause every time, the server polls that particular Object. In a network
sceneario, this could be an Object on a remote client with a slow modem
connection. This leads me to option 2:
2) The clients poll the server for an Environment, do their tick() and report
back the ObjectReponse. I have not really though this though, since it
seems a bit complicated, but the other option (1) appears to have a
problem with slow Object responses.
But first of all, I don't run in a network. So should all clients be
simulated with threads? One thread pr. Object?
I'd also like some sort of security in the game, if it ever gets packets
broadcast over a network, so that it would be possible (I know..) to cheat.
Any suggestions are welcome.
--
Stephan Henningsen /
/ tisprut productions[tm]
|