PDA

View Full Version : lag



Mr beef
January 7th, 2008, 03:32 PM
LAG - Latency Against Gamers.
Ok enough of the fun for now. Today I decided to test my game on some other computers. I soon founf out I had some weird bugs, but thats not the point. These computers weren't the best, infact they are probably pieces from computers from years ago. My computer runs the game at 20FPS, my FPS meter counts 21-22 Lowest is around 17. When I post it online i see it drop by 5 FPS, so I bumped the FPS up by 5.

On the computers I tested it on one was fine on High detail until I entered the place I expected it to lag, it dropped to about 15 from 20. On the second computer on high detail it was at 11 FPS on high detail, and 4FPS lowest. I want even the crappy computers to play decently. On medium quality I have no lag at all. Ok so here are my questions:

Is there any way I can change the FPS on certain frames?

Would caching my MCs as bitmaps,which is causing the lag, reduce lag. Or should I change the images into bitmap pictures and replace the graphics inside the Mc with the same drawing, but as a bitmap.

And a question not related to the above. To increase accurate hitTesting and stopping walking through walls could I check to see if you are going to hit but at different distances. For example:

if(this._x +10 hitTest(_root.object)== false){
this._x +=10
}else if(this._x +9 hitTest(_root.object)==false){
this._x += 9
}else{
//and so on
}

Would mean alot more code, but would it be worth it?

ArmoredSandwich
January 7th, 2008, 05:15 PM
ill answer your second question first. NO

Okay. Well, let me explain. hittesting is extremely cpu intensive.. wait.. flash memory usage intensive. You say you already have lag imagine that lag and then double it, double it again and double it again.

The lag is the worst thing about flash. Unlike other games, flash cant really use cpu. That sucks balls (like a black hole indeed). That means that you (yes you) have to think of tricks in order to calculate less things then ur game is doing now. It can be done, i know so. Im not really sure about the what exactly flash can use. I would like to know it exactly though. So If anyone reads it and finds out, please tell me.

Another reason why flash is slow is because it renders in vectors. ( http://www.wonima.demon.nl/try_out_bitmap_rendering.html ). You could start copypixeling your game which increases it ALOT. See the difference between project Ai battle and Flash RTS at www.wonima.demon.nl (http://www.wonima.demon.nl) (no, im not trying to sell my games, really!). The problem with that is that you will need to recode your total game. Not only that but you also need to know oop, or else it is going to be REALLY tricky.

In my opinion, when you NEED to bitmap render, you can just as well go ahead and start programming real games with languages such as c#. I say this because the advantage of flash is to create online games without any installation needed and you can create em fast, because you do not need to think about things such as bitmap rendering. When you start to bitmap render, you are basically doing something that was not intended to be done by the programmers. I think bitmap rendering is rather used for graphical effects than creating games (could be wrong tho).

Maybe an easier way and maybe also a way you should seriously consider either way. Is using the tile system. (See http://oos.moxiecode.com/ and http://www.tonypa.pri.ee/tbw/ for AWESOME tutorials). You can really easy create, edit and spread your maps. It has alot of really good uses. It might not be as pretty as graphics but it sure is handy, for pathfinding too! Game such as Age of empires, starcraft, mario, sun age and many more (classics) use this system.

Yes, this would also mean you'd have to recode your game. And I tell you this: its not gonna be fun. I've more than enough experience in restarting games that you might think xD.

To know more about your lag problem see this topics (forget about my hijacking the first one, especially the second one is VERY good!):
http://www.kirupa.com/forum/showthread.php?t=281686
http://www.kirupa.com/forum/showthread.php?t=276114


gl hf!

Mr beef
January 7th, 2008, 06:33 PM
it doesnt lag that badly its, infact it makes it more how I intended to. The problem is that the FPS changes per frame, so the animation etc will speed up/down. Would I be better off ripping out the vector images and replacing them with bitmaps, or for me to go try learn the bitmap stuff? Either way I wont be using it yet, I'ld rather get this project finished and draw a conclusion on what I need to do next.

Gundark
January 7th, 2008, 06:48 PM
Replacing your static vector images with bitmaps would probably help some. Are you doing "cache as bitmap"? It is much quicker for Flash to render a movieclip with a bitmap in it rather than one filled with vector data.

That shouldn't be that difficult (unless you've got a huge number of images) and you'd probably see some speed increase.

Mr beef
January 7th, 2008, 06:59 PM
Theyre not cached as bitmaps yet. So would replacing them with bitmaps increase it better or caching them? Or both :p

Gundark
January 7th, 2008, 07:09 PM
I wouldn't be able to tell you the speed difference without testing, but I'd assume actually using bitmaps would be faster as it wouldn't even have to calculate the vector graphics even once. I don't think caching bitmaps to bitmaps will gain you anything, if anything it might even slow you down (I've never tested so I could be wrong).

Mr beef
January 7th, 2008, 07:18 PM
Ok Well Ill try it tomorrow and note the difference and conclude from there. Thanks, cya later.

Mr beef
January 9th, 2008, 07:21 PM
Ok it went well with the bitmaps but I would still like to control FPS. I want it to be at 30 FPS but to cap at 20FPS. Is that possible?

I got Flash CS3 today so that made me quite happy. I've heard a few people say that you can do something with frames and FPS in CS3 but is it true and how. I should get started on learning AS3 now lol, havent even learnt AS2 as much as I'ld like to but if I dont learn soon I'll never learn it. Besides it cant be too different.

Ok ignore the unimportant parts. Can I set a maximum FPS rate but still compile it at 30FPS.

Second question is I've been advised to use setInterval instead of onEnterFrame so it no longer relies on frame rates, but I've tried it and failed. Something like setInterval(function(){},50) but that wont work because it starts off with the delay but then it no longer continues the delay between redoing the function.:hangover:

Blackcat
January 9th, 2008, 07:27 PM
Hi

if have CS3, too

and i have found a function:

public function get FPS():Number
public function set FPS(value:Number):void

but i don't know how to use it
I hope this will help you

Jerryscript
January 10th, 2008, 02:42 AM
You need to work on the issue giving you the lag. There is most likely a fix for it instead of trying to work around the issue by changing the framerate.

When using setInterval to achieve a consistent rate, you don't use the same number of milliseconds each time. Instead, you have to clear the interval, and then setInterval again with the number of milliseconds determined by how long it took to process the code. Example:
var millsecondRate = 50; // this is the value for your true rate
function foo(){
var startTime = getTimer();
clearInterval(consistentRate);
// code to process here
var elapsedTime = getTimer() - startTime;
var timeLeft = millisecondRate - elapsedTime;
timeLeft = timeLeft > 0 ? timeLeft : 1; // correct for negative values
consistentRate = setInterval(foo, timeLeft);
}
consistentRate = setInterval(foo, 1); // initial call set to start immediately

Mr beef
January 10th, 2008, 04:34 AM
Its not lagging its just I would like to set a max framerate so its more steady on all compters.

Thanks for explaining that I needed to clear it I had forgot. Cheers

Jerryscript
January 10th, 2008, 12:03 PM
There are a number of issues with your goal:

1- What would be the lowest level of computer you would target? I keep a 533mhz with Win98SE for testing, and even do alot of work on it still. If my progs run smoothly on it, they will run smoothly on just about anything

2- What processes are running on the computer in question? It seems these days everyone has at least one or two extra toolbars (google, yahoo, etc), and I've seen some client's computers with so many progs running at startup it amazes me they run at all. The more processes someone has running, the greater the chance the flash player's performance will be affected

3- How is the SWF being viewed? If it is viewed in the browser as a SWF file, it will be scaled to the browser window (unless you lock the stage scaling), and scaling always affects performance. If it is viewed within an HTML page with appropriate sizes in the object/embed tags, this isn't an issue. If it is viewed in the stand-alone player, it will perform even better.

Unless you can nail down the above issues, you can't guarantee consistent framerate across all computers.

One idea I've tossed around in my mind is using a test at loading time to determine the processing speed available. A timed loop calculating thousands of iterations could give you a baseline to adjust the framerate, which you could then use with setInterval or the AS3 framerate functions. I've never tried to implement it, but I imagine it could work (just be sure to time the test so that it wont coincide with any residual GC from loading).

Mr beef
January 10th, 2008, 02:36 PM
Ok nice valid points for me to consider there. I've tested it on a webpage on older computers and it runs smooth with no issues for me. I know people have alot of startup programs I have about 3-5 but I know people who load so many it takes 30 mins to actually use the computer.

I posted my previous response half asleep and rushed for time. When I mentioned consistient frame rates I meant so the overall RPS will allways try to keep to 20FPS. For example when you are doing nothing the RPS is nice and high, but when you start doing something it will drop a few. On the computers I tested it runs ar 24FPS doing nothing and around18-22 when doing something. I would like to keep this so it will be 20FPS no matter if your doing anything or not - keeping all framerates per frame consitient.

So it's not really a matter of latency on computers when playing my game, I just want the FPS to allways remain the same throughout the game - rather than jump around gicing varied speeds. Thankyou for your help so far :D,
~Mr Beef