Okay, took a peek at your map code...
I suggest that you add a display of the clocks millisecond counter before and after the mapping routines.
This would show if any of these ideas actually speed up your mapping. I think some will. Display the time
it actually takes on your server and subtract the ending from the start and you will see how fast both are.
------------------------------------------
First, the routine goes thru 81 loops. Inside that loop is a complicated IF clause that has a LOT of compares in it. So, 81 times all this is a huge hit on performance. Of course, this really depends on how many players are active. So, there are several ways to improve it.
Start with this line: if ($X < 1 || $X > 1000 || $Y < 1 || $Y > 1000) {
Four "compares" and three "ands" repeated 9x9 times... Lots!
So, this IF clause is to figure out if we are at the edge of the map. I would calculate this BEFORE creating the map and use a 11x11 map instead of 9x9. You would only display the 9x9. Just use an offset created before the map is started. In each part of the map, add the offset to the x,y to see where it is in the 1000x1000 map. If it is on the 3 row, the offset would adjust for the edge and adjust to point at the 5th square instead. The mapend pix would always be in place. In that manner, the above is no longer needed and saves a large number of calculation cycles.
Next, 0 to 8 is the same as 1 to 9 That is if you do not need to use the 1 as a start. So, what I mean about this is that two for loops 0-8,0-8 is 81 and 1-9,1-9 is 81... Same. Make sense?
So, logically, this line: $TID = (($X * 1000) - 1000) + $Y;
could be altered if you use 0-8 as: $TID = $X * 1000 + $Y; this saves a lot of subtracting...
I am guessing in this map, you actually have it set up as 1000x1000+1000 to make up for this for loop...
Now the last speed up is a big one! During the displaying of the map, you locate the map picture number in the grid. Then, you use this to decode the picture name and display it. This is a bit hit on performance. So this:
if ($Graphic == 1) {
echo '<a href="game.php?X=' . $X . "&Y=" . $Y . '""><img src="images/Terrain/Forest1.png" alt="Tile" /></a>';
} elseif ($Graphic == 2) {
echo '<a href="game.php?X=' . $X . "&Y=" . $Y . '""><img src="images/Terrain/Forest2.png" alt="Tile" /></a>';
} elseif ($Graphic == 3) {
All of this loop can be replaced with just one line. This section of the loop goes thru a large number of IF clauses and if the first one doesn't match, it goes to the next. So, if the graphic number is 8 it has to go thru the first 7 IF clauses to get to the 8. Performance-wise, this is crazy! It would be so very easy to remove ALL of the IF's with the use of just a simple array... So, here is one short example how to do this. Before starting the FOR's and looping, you would have to create an array... Sample with just the first three tile names:
$graphics = array("Forest1.png", "Forest2.png", "Forest3.png", "etc..."); (Placed before the FOR's.)
Now the entire IF clause can be reduced to this one single line:
echo '<a href="game.php?X=' . $X . "&Y=" . $Y . '""><img src="images/Terrain/$graphics[$Graphic]" alt="Tile" /></a>';
What this will do is remove ALL of the repeated IF clauses from 1 to 17 and cut down on about 500+ IF's.
(during the full loop)
Well, that should speed it up a lot in the overall picture. It really doesn't matter if you have 10 people playing as that is low volume. But, if a 1000 are playing, it might matter. I just see these things logically and I have a bit of game experience. Do not change any of these things if you have plans for using them this way. You might have plans I am not aware of. I just see logical speed ups... LOL... Hope that helps.