July 11th 2005

Woah, it's been a while since I wrote something here. Well, to sum up the last few months: I released IAD, some people played it, I fixed a lot of issues and added new stuff here and there. I moved to a new server and improved the house manager and was about to add new cities that would connect all three main cities with each other to make a complete world. But then the server went away. My host said that my websites were responsible for a recent crash and I had to remove IAD and the PHQ chat in order to be able to stay in the contract.

I've been working on IAD until May 13th, that was the "Day of Defeat", literally. Then it was dead for a while. I didn't know what to do, also there were some real life issues going on, about my job and everything, so everything was going down a bit. I also started playing Starwars Galaxies, probably to distract myself and give myself a break. I also started to work with Flash, I made one flash movie and a game called Phabetal (somewhere available on Newgrounds.com). And now, two days ago an old friend of mine (Nine, the voice of the oh so famous dragon) told me to install Linux on my machine and run a webserver on my local machine, so that I'd be able to play and improve IAD while I can't run it on the server.

And that's what I did, and when I fired up IAD on my local webserver - I was really shocked. Every move I made - and even though it was on my LOCAL machine! - took about 1-2 seconds to be done. I mean, I knew that IAD was complex and had a lot of stuff going on every click you do, but I didn't know how bad it really was.

There has to be a solution to this. And the only solution right now would be something I've been thinking about for a long time.

Basically, in an online game you gotta work as much as you can on the client machines to let the server breathe. I tried to do that by reducing the files to download to almost nothing, but I forgot that I still had a LOT of stuff going on in the scripts themselves, especially a lot of database queries. Now my solution would be to make at least the field completely in flash.

Why in flash? I got some reasons. First of all, let me explain my idea further. As I said, it is important to do as much as you can on the local client machines. So, I've been thinking about when it is really necessary to contact the server. And basically, it's only necessary to contact the server when you interact with other players or somehow change the world (house manager, kill creatures, pick up pictures, change your position, etc.). At the moment everytime you click on the field it checks on EVERY field you move on if you're allowed to be here, what is on this field, and lastly when you stop it sends all the objects that are on the field including all the mouseover descriptions. I just checked, and it's about 900 lines it has to go through for every click. Now my idea was to put the coordinates of obstacles (stuff you can't go on and have to avoid) into the flash file, and let the movement happen in the flash client, and when you're standing still again, it sends a small request to the server and the server just checks if you're allowed to stand there or not. It also sends the info of the player positions in range (if there are any). Apart from obstacle positions, I'd also load positions of NPC's, houses and all that stuff into the flash file, so that when you're stepping on an NPC it reloads the dialogue window in the upper left corner.

The next advantage would be that all the images IAD needs could be in the flash file already and won't have to be reloaded from the server all the time. All the positions of objects and NPC's and everything else that is static and can't be changed would be loaded either upon entering a map, or by feeding the information directly into the flash file.

Here's a little problem though and I think I'd go for the first option, to load all the static objects information at the entry of a new map. Because player rooms don't have "static" objects, they can be changed all the time, and I can't update the flash file everytime a player moves a wall up 1 field. This however can be a problem. Some maps have a size of 50x50 or even 100x100, which means it would have to load up to 2500-10000 objects everytime you go to another map!

So here's another idea: Save map files on the client machines. For example, if you're in Dragonland and the "room" of Dragonland has the ID 1 in the database of the server, it will create a "map" on the local machine called "map1" or something. Then it will load like 100 objects every move of your character, or every 10 seconds and slowly build up the map and save it kinda like this: ID-Name-X-Y-Type-Look;ID-Name-X-Y-Type-Look;(etc.)

Type would be a number, like 1 would mean obstacle (walls), 2 would mean NPCs, 3 would mean houses, 4 shops and so on. Look saves the name of the image the object uses, Name is the mouseover "description" and X/Y are the coordinates. The ID is the same as the ID in the database of the server. This will be necessary when checking for updated objects on the map. Actually, to save up space in the local map files, I could "compromise" the data a bit, like if I have 5 walls with the same name and same look, I could just write: Name-Look-Type-(ID+X+Y,ID+X+Y,ID+X+Y,ID+X+Y,ID+X+Y);

When would be a good time to update those map files? Well, I'd say I could set variables in the database to 1 if I've changed anything in the IAD maps, so that client programs will automatically check for updated maps at startup. Although for player rooms it would be a bit more difficult. I could let the local maps update everytime you log on, but it would take a while (if you have 20 maps on your local machine, with at least 25x25 average size each, that would mean about 12500 entries to update!), so maybe I can update the maps everytime you enter a player room. But what happens if the owner of the player room is online at the same time and changes stuff in there? That would mean that I have to check the maps every click, which could kinda slowdown the server again.

Well, a solution to this might be that players need to set their rooms to "under construction" if they want to change anything. And other players can't go into places that are currently under construction (unless you're the creator of it?).

The next problem would be that those map files are accessable on the local machine, so that basically means you can change the local look of IAD until the client program validates the maps and its coordinates again. Like, you could remove walls and move into places not meant to be seen and all that stuff.

A kinda complicated solution to this is to mark every entry with a validation key that gets calculated using the name, id, type, look, x and y coordinates. And everytime you move it also checks the validation of the key to every object in range. If it's not a valid key, the map has to be reloaded. The problem with the key validation on the local machine would be that the flash files can be decompiled and people might find out how the keys work. But who wants to spend hours of work just to see something rare in IAD anyway?

So anyway, all those problems aside - how should I update the map files? It's definitely not a good idea to let the server work up a database query for 10000 objects. So, probably the solution to all of this: The maps get created and stored on the server, and if a client needs it, they'll just download the map files. So, everytime I change something in the IAD world, the server creates a map file. Everytime a player finishes his "under construction" session, the server creates a map file.

I just made a test file with 10000 entries and it has about 540KB, though in ZIP format it only uses 1.4KB. So it might be possible that people will have to download bigger maps manually. We'll see.

That's it so far! Next time I'll probably look into how those map files are read and how to display the objects in the flash file.