Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / To give up, or not to give up

Author
Message
TKF15H
21
Years of Service
User Offline
Joined: 20th Jul 2003
Location: Rio de Janeiro
Posted: 21st Oct 2005 15:44 Edited at: 21st Oct 2005 16:06
As so many programming jobs today require some sort of web-based experience, I decided it was time I learned some PHP. To do this, I started a little game project.

Everything was going fine while I ran it locally, but when I uploaded it to a free webserver, I noticed it was toooo slooooowwwww. Now I'm not sure if it's my connection that is slow, or if it's the server. The PHP code is actually running faster than it would on my own computer, but the transmition time kills it. If anybody has any ideas on speeding this up, I'd love to hear em.
I know the graphics aren't the problem, because they get cached (first time is very slow, but from then on it gets faster, but still unplayably slow). It's the actual HTML that is taking long to load.
Here's the site:
http://fishman.6te.net/
Go ahead and create an account. The e-mail doesn't have to be valid, so long as it isn't blank.

Here's a screenshot

[edit] BTW, n00bs look like nosebleeds at first, I'll have to change that later.
There's a bunch of stuff missing still:
bigger world, fighting, character appearance changing, observing, monsters, etc.
I'm not gonna do any of it until I know it can be done at a playable speed.

WarBasic Scripting engine for DarkBasicPro
DC emulator code size: 14.3MB, 553,214 lines
Seppuku Arts
Moderator
20
Years of Service
User Offline
Joined: 18th Aug 2004
Location: Cambridgeshire, England
Posted: 21st Oct 2005 16:09
Its not slow, I don't like the fact it refreshes the images each time you click, but its PHP not java, so I guess it would do that to work like a game, but its not slow for me, looks pretty sweet, something I wouldn't have patience to do

The name is back dudes!
http://seppukuarts.afraid.org
spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 21st Oct 2005 16:15
Yep, VERY slow indeed. Viewing source code of html shows you are generating LOTS of tables within tables which is certainly not good for speed. There should only be ONE table, with 10 rows (TR's) and 10 columns per row (TD's). Even so, page is small enough to render quickly. How are you generating page load time? Are you doing a database query to get tiles? I suggest timing the different parts of showing a page and see what is taking so long.

Don't like being a nosebleed.

Boo!
TKF15H
21
Years of Service
User Offline
Joined: 20th Jul 2003
Location: Rio de Janeiro
Posted: 21st Oct 2005 16:19 Edited at: 21st Oct 2005 16:29
I put tables within tables so I can put one image on top of the other, something I can't do with <tr><td> alone.
[edit] Yeah, database query for tiles. But that's not the bottleneck, it would run at a nice speed locally. That and "Page generation time" (on the bottom) is sometimes faster on the server than on my own PC.
Who wants to stop looking like a nosebleed? I'll change your avatars manually. Male or female?

WarBasic Scripting engine for DarkBasicPro
DC emulator code size: 14.3MB, 553,214 lines
spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 21st Oct 2005 16:58
Course you can. The TD can have a 'background' tag to show background tile, like path, grass, etc, then inside the TD you just do a normal IMG tag to show character. It will overlay the background just fine.

Ideally you should use layers and draw all the background tiles on one layer, and the characters on a foreground layer. This means you could use AJAX to regularly query database to see if any characters have moved and then update their onscreen positions without having to redraw rest of page. This is quite tricky to do but should not take too long for you to do.

Also, when you move, you should use AJAX to leave rest of page alone and just update the bits of page you want updated. Makes things much faster but I don't know your coding abilities.

Updating just the table will also be good for bandwidth usage as server only sends html needed to update table, not all the other stuff around the page.

Good Luck!

Boo!
TKF15H
21
Years of Service
User Offline
Joined: 20th Jul 2003
Location: Rio de Janeiro
Posted: 21st Oct 2005 17:04 Edited at: 21st Oct 2005 17:08
Quote: "The TD can have a 'background' tag to show background tile, like path, grass, etc, then inside the TD you just do a normal IMG tag to show character. It will overlay the background just fine."

That's what I'm doing. There's a grass tile, maybe a treetop tile, and finally a player piled up.
About layers... aren't they netscape only? Or did you mean something else?

Quote: "
Also, when you move, you should use AJAX to leave rest of page alone and just update the bits of page you want updated. Makes things much faster but I don't know your coding abilities."

I don't think using AJAX for this would gain much. When the player moves, everything moves, and since there's little else on the page (other than <head> tags and the logout button) I don't think it will make that much of a difference.

oh, and you don't look like a nosebleed anymore, spooky.

WarBasic Scripting engine for DarkBasicPro
DC emulator code size: 14.3MB, 553,214 lines
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 21st Oct 2005 17:09
Alternatively, define the map in PHP (maybe in an Array to start with) and have the tiles in a protected folder. Then you can get PHP to create 1 big image full of those tiles. ITs pretty easy one you get the hang of it.

Tables suck. What browser are you using? Crappy browsers have a hard time with tables as they often dont render the whole table until they know they size of the contents of the table itself.

You could try making it generate Styles DIVS with either relative or absolute positions.

I have to say though - once that is done, it'll be FANTASTIC. It might slaughter bandwidth though....

TKF15H
21
Years of Service
User Offline
Joined: 20th Jul 2003
Location: Rio de Janeiro
Posted: 21st Oct 2005 17:14
Quote: "Alternatively, define the map in PHP (maybe in an Array to start with) and have the tiles in a protected folder. Then you can get PHP to create 1 big image full of those tiles. ITs pretty easy one you get the hang of it."

That will make the player have to download the entire image each time he moves, making the browser's cache useless. And uniting the tiles into one image will probably also weigh down on the server a bit. The DIVs thing may work.

WarBasic Scripting engine for DarkBasicPro
DC emulator code size: 14.3MB, 553,214 lines
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 21st Oct 2005 17:22
Ahh good point - didn't think of that.

spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 21st Oct 2005 17:36
Ah, I didn't realise you could walk behind treetops which means you have 3 layers going on.

I would certainly go with the layers idea. Create one RELATIVE div encompassing game area and then position each tile using ABSOLUITE divs.

You can probably get away with just pasting the main background tiles next to each other, then had a div for each player, positioned absolutely, then a div for each topmost tile that is to appear in front of player, like tree tops, lamposts, etc. Should be pretty good then.

Boo!
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 21st Oct 2005 17:49 Edited at: 21st Oct 2005 17:50
In the good old tradition of my motivation running away on a friday afternoon, I have neatened the code up.. well TidyUI did

EDIT: I'm also gonna try to do it by DIV for you

TKF15H
21
Years of Service
User Offline
Joined: 20th Jul 2003
Location: Rio de Janeiro
Posted: 21st Oct 2005 18:09
lol. PHP tends to output one-liners if you use echo too much. Pitty it got cut near the end.

I want to see how you do it by DIV, I'm not very good at HTML so it'll really help.

WarBasic Scripting engine for DarkBasicPro
DC emulator code size: 14.3MB, 553,214 lines
David T
Retired Moderator
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 21st Oct 2005 18:38
I agree with spooky. Divs are the way to go here. As many as possible can be layered.

Going with the tile based idea, it's not surprising it's slow. Thigns run like lightning on your own PC because there's 0 load time - whereas in real life it takes time to download loads of separate images.

Google Maps gets around this nicely by having a series of images, which move around on screen. Once one goes off screen it is marked as unactive, so when the user drags around and a new tile is shown the unactive one can be given a new picture and shown. Pretty clever. It only loads the new stuff, and no refreshes

"A book. If u know something why cant u make a kool game or prog.
come on now. A book. I hate books. book is stupid. I know that I need codes but I dont know the codes"
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 21st Oct 2005 18:46 Edited at: 21st Oct 2005 18:53
Ok - here is my attempt...
http://www.thingy-ma-jig.co.uk/zombie/ZombieRPG2.html

Or, as I'm kind, I've also attached a ZIP file with it all in.

Basically, I've used CSS and DIVS. It seems MUCH faster on my PC, and much easier to read.

I've defined columns and rows. This will required a semi-decent browser that can handle multiple classes in the class="" part of an element. IE6 and Firefox can and I think pretty much everything can...

Lemme now what you think

EDIT: Btw, where it has the player over the lava... Thats 3 DIV's on top of each other

Attachments

Login to view attachments
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 21st Oct 2005 19:04 Edited at: 21st Oct 2005 19:06
Never, ever give up! NEVER!

Here's an example of DIVs for you:

Let's say that you're using a 10x10 tileset on a 10x10 map ( to make things easy for me ), your images are logically named, and you're using a top-left coordinate based system, then you'd set up something like:

style.css:


main php file:


I can't guaentee anything, but that should work, and would be a hell of a lot faster than using ugly tables

That's only my take on how I would go about it, and I'd say Nick's in a much better position to give good advice.

Jess.

[EDIT]
Whoah, ok, Nick posted whilst I was writting mine up. See what I mean? His is much sexier, he uses classes... Something I'd never used. I'm so noob
[/EDIT]

Team EOD :: All-Round Nice Guy
Want Better dbHelp Files?
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 21st Oct 2005 19:10 Edited at: 21st Oct 2005 19:11
Hehehe.. I'm a sneaky blighter I've learned to always refresh the page before posting :-P

Btw: Here is my code in code boxes, I forgot to do that but Jess's post reminded me:

html:


CSS:


EDIT:
Advantages of Jess's one is that its probably a little more compatible with weird browsers than mine.. But the advantage of mine is that your browser will cache the CSS file - so once they have all the rules for your game, there is nothing holding them back!! MWUHAHAHAHA

TKF15H
21
Years of Service
User Offline
Joined: 20th Jul 2003
Location: Rio de Janeiro
Posted: 21st Oct 2005 20:16 Edited at: 21st Oct 2005 20:24
Quote: "in real life it takes time to download loads of separate images."

The images are only downloaded once, then held in the cache. It's just the HTML transmission that's getting in the way.

Jess+Nick: Thanks for the help! Now I'll go study your posts.

[edit] Does the CSS file have to have the CSS extension? Because I'd like to generate it with PHP code.
Lava? Oh, you mean the nose-bleed?

WarBasic Scripting engine for DarkBasicPro
DC emulator code size: 14.3MB, 553,214 lines
Teh Go0rfmeister
21
Years of Service
User Offline
Joined: 17th Aug 2003
Location:
Posted: 21st Oct 2005 20:58
no-one else just getting a grey square then?

AluminumPork
21
Years of Service
User Offline
Joined: 28th Oct 2003
Location: Duluth, MN, USA
Posted: 21st Oct 2005 22:13
Umm, it was very quick for me. Very playable. I'm on a 7mb down/3mb up connection right now at work so who knows, but still very quick.

P4 2.4Ghz HT, 512MB RAM, ATI Radeon 9600 128MB, 19" Samsung SyncMaster 997DF, 80GB HD

Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 21st Oct 2005 22:24
The problem with IE is that, by default, it will only download 4 things at once. I think firefox does 10 at once. The biggest delay on small files is probably the overhead produced from connections!

@TKF15H: You CAN make the PHP generate inline CSS in the HEAD section, however that would be downloaded wiuth every page - adding about 1-2Kb per page. If you make 1 [6/7/8/9/10]Kb CSS file, once its been downloaded once it stays in the cache and reused (unless the user does a complete reresh (Ctrl+F5 in most apps)). This should speed a lot of things up. In you code, instead of stating things like:
STYLE="LEFT: 400px; TOP: 100px; position: absolute; background-image: url('i/file.gif');"

you'd do:
CLASS="col1 row1 img15"

Much smaller

If you need ANY help whatsoever with it, post back here or email me. I'm pretty nifty with PHP, HTML and CSS (it being my job and all)

TKF15H
21
Years of Service
User Offline
Joined: 20th Jul 2003
Location: Rio de Janeiro
Posted: 22nd Oct 2005 01:10
I think I'll make PHP alter a CSS file (using fopen) rather than embedding the CSS code to the main page.

WarBasic Scripting engine for DarkBasicPro
DC emulator code size: 14.3MB, 553,214 lines
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 22nd Oct 2005 01:50
why?

TKF15H
21
Years of Service
User Offline
Joined: 20th Jul 2003
Location: Rio de Janeiro
Posted: 22nd Oct 2005 02:49
Dynamic tiles. Don't wanna edit the CSS each time I add a tile.

WarBasic Scripting engine for DarkBasicPro
DC emulator code size: 14.3MB, 553,214 lines

Login to post a reply

Server time is: 2024-11-16 00:58:21
Your offset time is: 2024-11-16 00:58:21