Game architecture

Discussions related to programming Transport Empire.

Moderator: Transport Empire Moderators

fujitsu
Engineer
Engineer
Posts: 32
Joined: 12 Jul 2005 08:14
Location: Melbourne suburbs, Victoria, Australia (GMT+10)

Post by fujitsu »

uzurpator wrote:Ok - I think we should really disregard this thread and build the tree on the fly.

For now it would constitute something like this:

Code: Select all

God             Satan
 |               |
 |-Server        |-Client
 \-Network       \-Network
[snip]

BTW - I name classes by their level in the tree:

God
Seraph
Cherub
Angel
Saint
Blessed

Satan
Daemon
Devil
Imp
Sinner
Damned

Call me creative.
Creative, maybe, but WRONG. Should be the other way around (ie Satan as the server), as a server process is generally a DAEMON! :P

William.
Hellfire
Transport Empire Developer
Transport Empire Developer
Posts: 699
Joined: 03 Feb 2003 09:30
Location: Back at the office

Post by Hellfire »

There's only a very small chance that our architecture will be right the first time. So, I propose to do things incrementally.

When looking at the (preliminary?) task list, I think that the small demo I've posted earlier today satisfies task 1 and a part of task 2.

Now, for the rest of task 2 and 3, I propose the following architecture:

Both the Server and the Client application will be constructed following the Model-View-Controller paradigm. Because I'd like to keep things simple for this step, the applications will be console based. Instead of transmitting the timestamp of the game, the applications will transmit the map.

The View and Controller part of both applications will be done properly at a later time. We will focus on the model, for now.

The model of the client will look like this:
Image
Omg... Visio 2000 gives really bad images

The Map interface is used by the View and the Controller to access the map. It is implemented by the MapCache class, which stores (caches) individual Tiles. The tiles are retrieved from the server through the ClientSocket class. Communication is done with Packets, which are created by the PacketFactory.

Everybody still reading? ;)

Now the server:
Image

The server has a ServerSocket which is comparable to the ClientSocket class in the client, but still quite different. Perhaps those two classes can share a super class. We'll see. We can always refactor in the future. The ServerSocket connects to the real Map, which happens to support all the same actions as the Map interface in the Client.

Notice that some classes are shared between Server and Client:
  • Packet
  • PacketFactory
Packets are only a medium to transmit information. Hence, it makes perfect sense to share these classes between the two applications.


Now... What is the purpose of all this. A prototype/demo/pre-alpha/whatever version of Transport Empire must satisfy these requirements:
  • The server must store a map of at least 16x16 tiles, with each tile having a height.
  • This map will be generated at random when the server is started.
  • The client will subsequently ask for two snapshots of 8x8 tiles and displays them on the console. After the second snapshot, the first is requested again. Here's where the cache should prevent excessive network communication.
The following items will be milestones for task 3:
  1. Creating the two Socket classes. Creating a Packet object, serializing it, transmitting and reconstructing it on the other side.
  2. Answering to an arrived packet
  3. Creating a random map at the server
  4. Requesting and receiving the map by the client
  5. Caching the map
Anyone willing to help is welcome. ;)
Last edited by Hellfire on 06 Mar 2006 23:02, edited 2 times in total.
Feel free to contact me over Email! My current timezone: Europe/Amsterdam (GMT+1 or GMT+2)

Code: Select all

+------------Oo.------+
| Transport Empire -> |
+---------------------+
[ General TE Discussion ] [ TE Development ] [ TE Coding ]
Under construction...
Hellfire
Transport Empire Developer
Transport Empire Developer
Posts: 699
Joined: 03 Feb 2003 09:30
Location: Back at the office

Post by Hellfire »

This post is only for the images.
Attachments
client.model.png
client.model.png (3.96 KiB) Viewed 15894 times
server.model.png
server.model.png (3.6 KiB) Viewed 15893 times
Feel free to contact me over Email! My current timezone: Europe/Amsterdam (GMT+1 or GMT+2)

Code: Select all

+------------Oo.------+
| Transport Empire -> |
+---------------------+
[ General TE Discussion ] [ TE Development ] [ TE Coding ]
Under construction...
Hellfire
Transport Empire Developer
Transport Empire Developer
Posts: 699
Joined: 03 Feb 2003 09:30
Location: Back at the office

Post by Hellfire »

Hellfire wrote:The following items will be milestones for task 3:
  1. Creating the two Socket classes. Creating a Packet object, serializing it, transmitting and reconstructing it on the other side.
  2. Answering to an arrived packet
  3. Creating a random map at the server
  4. Requesting and receiving the map by the client
  5. Caching the map
Milestone 1 has been reached. :)

In the zipfile is a _very_ simple application that meets the requirements. It's basically the same as the demo I made earlier, except that this is Object Oriented and uses some form of abstraction over the data traffic.

The same condition holds nevertheless: compile it on linux or mingw on windows and run from a console. Start the Server first, then the Client.
Attachments
task-3.1.zip
(620.93 KiB) Downloaded 428 times
Feel free to contact me over Email! My current timezone: Europe/Amsterdam (GMT+1 or GMT+2)

Code: Select all

+------------Oo.------+
| Transport Empire -> |
+---------------------+
[ General TE Discussion ] [ TE Development ] [ TE Coding ]
Under construction...
Hellfire
Transport Empire Developer
Transport Empire Developer
Posts: 699
Joined: 03 Feb 2003 09:30
Location: Back at the office

Post by Hellfire »

Hellfire wrote:The following items will be milestones for task 3:
  1. Creating the two Socket classes. Creating a Packet object, serializing it, transmitting and reconstructing it on the other side.
  2. Answering to an arrived packet
  3. Creating a random map at the server
  4. Requesting and receiving the map by the client
  5. Caching the map
A little refactoring and a few new classes and voila! Milestone 2. :)

The same rules hold for this program: compile it on linux or mingw on windows and run from a console. Start the Server first, then the Client. Windows executables are included.

Talking into an empty room sucks... I hope at least someone will show up sooner or later and read these posts. ;)
Attachments
task-3.2.zip
(631.96 KiB) Downloaded 423 times
Feel free to contact me over Email! My current timezone: Europe/Amsterdam (GMT+1 or GMT+2)

Code: Select all

+------------Oo.------+
| Transport Empire -> |
+---------------------+
[ General TE Discussion ] [ TE Development ] [ TE Coding ]
Under construction...
Hellfire
Transport Empire Developer
Transport Empire Developer
Posts: 699
Joined: 03 Feb 2003 09:30
Location: Back at the office

Post by Hellfire »

Hellfire wrote:The following items will be milestones for task 3:
  1. Creating the two Socket classes. Creating a Packet object, serializing it, transmitting and reconstructing it on the other side.
  2. Answering to an arrived packet
  3. Creating a random map at the server
  4. Requesting and receiving the map by the client
  5. Caching the map
Milestone 3 should have been a part of milestone 4...
Attachments
task-3.3.zip
No binaries this time. From the user's point of view, there's no difference between 3.2 and 3.3
(15.21 KiB) Downloaded 411 times
Feel free to contact me over Email! My current timezone: Europe/Amsterdam (GMT+1 or GMT+2)

Code: Select all

+------------Oo.------+
| Transport Empire -> |
+---------------------+
[ General TE Discussion ] [ TE Development ] [ TE Coding ]
Under construction...
Hellfire
Transport Empire Developer
Transport Empire Developer
Posts: 699
Joined: 03 Feb 2003 09:30
Location: Back at the office

Post by Hellfire »

Hellfire wrote:The following items will be milestones for task 3:
  1. Creating the two Socket classes. Creating a Packet object, serializing it, transmitting and reconstructing it on the other side.
  2. Answering to an arrived packet
  3. Creating a random map at the server
  4. Requesting and receiving the map by the client
  5. Caching the map
Task 4 is done now. The included source code is based on RakNet. This wasn't really necessary, but I think we should go with RakNet anyway. I can still rip it out later if other people think otherwise.

One sidenote: both the server and the client application do not terminate anymore. I did this for two reasons:
1. I'm too lazy to write exit code.
2. The transition to milestone 5 is easier this way.

Another note: I have not tested the code on Linux yet.
Edit: The code werks perfectly on Linux, but it does not compile without libpthread, which should be present on almost all Linux installations. I've changed Makefile.var to add the library on non-windows systems. When I upload milestone 5, this glitch will be fixed.
Attachments
task-3.4.zip
Executables are available on request. :)
(20.72 KiB) Downloaded 429 times
Last edited by Hellfire on 14 Mar 2006 10:59, edited 1 time in total.
Feel free to contact me over Email! My current timezone: Europe/Amsterdam (GMT+1 or GMT+2)

Code: Select all

+------------Oo.------+
| Transport Empire -> |
+---------------------+
[ General TE Discussion ] [ TE Development ] [ TE Coding ]
Under construction...
User avatar
Hyronymus
Tycoon
Tycoon
Posts: 13233
Joined: 03 Dec 2002 10:36
Location: The Netherlands
Contact:

Post by Hyronymus »

Can you send me an executable. I don't know if it will fit on a PM?!
Hellfire
Transport Empire Developer
Transport Empire Developer
Posts: 699
Joined: 03 Feb 2003 09:30
Location: Back at the office

Post by Hellfire »

Just to show off, here's a screenshot of a terminal session to my Linux box and a command prompt on my Windows box. The server application is running on the Linux box, the client application is running on the Windows box. All communication is done over the network.
Attachments
two-clients.png
Just for fun, I added another client. It connects nicely, but because some small design decision, all packets from server to client are broadcasted. That's why the first client receives the map fragment twice.
(74.17 KiB) Downloaded 56 times
Show off picture. :P<br /><br />The server is a Linux machine<br />The client is a Windows machine
Show off picture. :P

The server is a Linux machine
The client is a Windows machine
cross-platform.png (41.22 KiB) Viewed 3442 times
Feel free to contact me over Email! My current timezone: Europe/Amsterdam (GMT+1 or GMT+2)

Code: Select all

+------------Oo.------+
| Transport Empire -> |
+---------------------+
[ General TE Discussion ] [ TE Development ] [ TE Coding ]
Under construction...
Hellfire
Transport Empire Developer
Transport Empire Developer
Posts: 699
Joined: 03 Feb 2003 09:30
Location: Back at the office

Post by Hellfire »

Hellfire wrote:The following items will be milestones for task 3:
  1. Creating the two Socket classes. Creating a Packet object, serializing it, transmitting and reconstructing it on the other side.
  2. Answering to an arrived packet
  3. Creating a random map at the server
  4. Requesting and receiving the map by the client
  5. Caching the map
Tadah! Task 3 is now complete.

Conclusions from this exercise:
  • Managing makefiles by hand can get very annoying
  • Caching works.
  • Asynchronous communication works very well.
  • Time spent: 8 days, roughly 32 hours coding and debugging.
  • The loops in servermain.cpp and clientmain.cpp have an interesting feature: if (nothing to do) { sleep(a while); }. This keeps CPU usage down and gives us better overall system performance.
  • RakNet is an interesting library. We should look deeper into it.
Attachments
Yet Another Useless Screen Shot
Yet Another Useless Screen Shot
screenshot.png (44.39 KiB) Viewed 3440 times
task-3.5.zip
The Source (tm)
(23.02 KiB) Downloaded 424 times
Feel free to contact me over Email! My current timezone: Europe/Amsterdam (GMT+1 or GMT+2)

Code: Select all

+------------Oo.------+
| Transport Empire -> |
+---------------------+
[ General TE Discussion ] [ TE Development ] [ TE Coding ]
Under construction...
Post Reply

Return to “Transport Empire Coding”

Who is online

Users browsing this forum: No registered users and 2 guests