A Serious Speed Issue
Author |
Message |
copthesaint
|
Posted: Sat Mar 13, 2010 12:20 am Post subject: A Serious Speed Issue |
|
|
I made this Debris Class for my game I'm making and the only problem is with its speed which is slow as *Word of choice*. Right now, Any Idea's on how I can improve the code?
I have included everything you need to see this your self, please comment back.
Description: |
|
Download |
Filename: |
Include.zip |
Filesize: |
279.72 KB |
Downloaded: |
71 Time(s) |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
TerranceN
|
Posted: Sat Mar 13, 2010 9:54 am Post subject: Re: A Serious Speed Issue |
|
|
Simply put, you need to cap the framerate. What this means is that you have to make sure each time your program goes around the loop, it must take the same amount of time. Since you already figured out how long it takes each loop, lets choose an amount to delay that is greater than that, like 33 (because 1000ms / 30fps = 33ms). If we just put a delay of 33 at the end, the total delay will be longer that what we want because updating/drawing the frame takes time too. Lets express this in an equation: 33 = t + n, where t is how long the frame took and n is the number of milliseconds we need to make the delay 33. If we rearrange this we get: n = 33 - t, therefore if we delay the loop by 33 - t each frame, it will keep your loop going around at a constant speed.
Edit: Of course I almost forgot Turing has this built in, as the command Time.DelaySinceLast(int millisecs).
Edit2 : Woah, I think I completely misread your question... Ok, some things I noticed:
Instead of re-calculating velocity every frame, store the x and y velocity amount in variables.
Instead of re-calculating each point every frame, keep the shape constant and calculate and store all the points only when you first create it.
Just try to keep the calculations per frame to a minimum on particles, because those calculations quickly add up.
|
|
|
|
|
|
Zren
|
Posted: Sat Mar 13, 2010 11:03 am Post subject: Re: A Serious Speed Issue |
|
|
What happens when t is greater than n? n can't be negative and then your experiencing major slowdowns.
The method you wrote is good for when programs run faster most of the time. However when your running behind it's noticeable all the same. Rather then delay, it's better to scale the distance traveled by the current time it takes to generate a frame.
In practice:
Turing: |
dots (i ).x + = delta_t * dots (i ).vel * cos (dots (i ).ang )
dots (i ).y + = delta_t * dots (i ).vel * sin (dots (i ).ang )
|
The part you should be focusing on is delta_t. This should be measured in seconds. Also you velocity should be in units/sec. So all in all, if your last frame took half the target time to generate the frame, the next frame will scale the velocity in half.
Check out this example, and try changing the max_dots from 100 (guarenteed over 60FPS) to something along the lines of 10000. You'll notice the lines will be longer when with the lower fps, and shorter with higher fps. With both cases, the speed of the dots clearing the screen should~ be the same.
Description: |
|
Download |
Filename: |
FPS Controls attempt.t |
Filesize: |
1.29 KB |
Downloaded: |
66 Time(s) |
|
|
|
|
|
|
copthesaint
|
Posted: Sat Mar 13, 2010 1:34 pm Post subject: RE:A Serious Speed Issue |
|
|
Im not trying to control the fps. . . Im trying to reduce how long it takes to finish the loop.
TerranceN, you are posting the wrong thing to the wrong person, seriously, also like Zren said, That will cause alot of program errors, basicly every time you move the run window, you will get an error. This is a VERY bad way of doing this. now I read Zrens post, find out how useless that it too, I KNOW HOW TO CHANGE VALUES BASED ON FPS, DONT WORRY ABOUT THAT lol. I am not worried about having consistent fps, Because I NEED to know how fast everything will run, and this debris class right now can consume up to 9 ms clicking alone.
Help Me With the StarDebrisClass, and inproving the code! Like I had said in my first post...
Where's DemonWasp when you need him lol...
Btw, Im not saying what you have post is useless, but really it has nothing to do with what I need help with.
Edit: added old file I made about 2 1/2 months ago for a tutorial, but never finished it, Think I may have had an error, not sure.
I know fps...
Description: |
|
Download |
Filename: |
Game BackGround.t |
Filesize: |
7 KB |
Downloaded: |
56 Time(s) |
|
|
|
|
|
|
TerranceN
|
Posted: Sat Mar 13, 2010 2:16 pm Post subject: RE:A Serious Speed Issue |
|
|
@Zren: That method is not always better. Consider two objects moving twards each other, and you are trying to detect collision. If (for whatever reason) there was a dip in the framerate, the objects might pass right through each other. I suppose you could use a more complicated method of collision detection, but I find it easier just to keep everything simpler unless there is a good reason not to.
@copthesaint: How will that "cause alot of program errors"? Also, Time.Delay does not give an error when you give it a negative number, so I dont understand how moving the window will give an error. Also, did you not read the last edit I made to my post? I realized my mistake, and tried to help with what you had asked.
|
|
|
|
|
|
copthesaint
|
Posted: Sat Mar 13, 2010 3:34 pm Post subject: RE:A Serious Speed Issue |
|
|
Kk stop talikng about It, this is supposed to be my help thread, I DONT WANNA MAKE A NEW ONE! :/ Seriously.... As far as I'm conserned, this is off topic.
'"Help Me With the StarDebrisClass, and inproving the code! Like I had said in my first post...
Where's DemonWasp when you need him lol..."
|
|
|
|
|
|
chrisbrown
|
Posted: Sat Mar 13, 2010 3:43 pm Post subject: RE:A Serious Speed Issue |
|
|
Shooting down every effort isn't going to improve your odds of getting what you want.
Have you considered that you may just need better hardware? There aren't significant improvements you can make; you're trying to model a lot of polys there. I have a fairly new machine and I don't go above 2 ms.
|
|
|
|
|
|
copthesaint
|
Posted: Sat Mar 13, 2010 4:16 pm Post subject: Re: A Serious Speed Issue |
|
|
methodoxx: "Shooting down every effort isn't going to improve your odds of getting what you want. "
true enough, but whats the point of effort with no meaning? Their help is like an essance that is there, but isnt used, basicly if a tree falls in a forest and none are around to hear it, does it make a sound? and in essance sound is something heard, and help is supposed to help, but when it is not heard, or it doesnt help, then it isnt what it is meant to be.
I have to apoligise to TerranceN though, since he did say what he originaly post had nothing to do with the acual question and then he did add something to try and help with the accual issue. Thanks and sorry I didn't read your full posts, Although I do think you should delete the first part.
... Again this isnt helping saying I need a better computer, since I have 4 gb ram 512mb deticated graphics card, and dual 2.01 ghz, hard drive write speed of 6400 rpm, this also being on a labtop. Its the program that is slow, I know it can run at 2 ms if you click normally(* I can click to get it up to 9 ms), but I also want it to run faster, because when I use this later, it wont simply create 1 instance for this effect, it will create several. This is just a small part of my program I am making, but still important enough that I need to make it faster.
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|