FAQ Search
Memberlist Usergroups
Profile
  Forum Statistics Register
 Log in to check your private messages
Log in to check your private messages
Moonpod Homepage Starscape Information Mr. Robot Information Free Game Downloads Starscape Highscore Table
I'm a new independent game developer, here's my game video.
Goto page Previous  1, 2, 3, 4, 5, 6  Next
Post new topic   Reply to topic    Discussion Pod Forum Index -> Independent Game Development View previous topic :: View next topic  
 Author
Message
Poo Bear
Pod Team
Pod Team


Joined: 14 Oct 2002
Posts: 4121
Location: Sheffield, UK



PostPosted: Tue Apr 27, 2010 11:14 am    Post subject: Reply with quote

Slyh wrote:
Poo Bear wrote:
Starscape and MrRobot work by fixing the frame rate at 25fps Smile

How do you do this, code-wise?



The clock is just a count of number of frames since start up X 40mSecs, so if I need a timer I can have one, but some things don't even need that as you can just assume you will update at 25fps.

I accurately time how long one frame takes and if it's less than 40mSec then the main thread sleeps to make up the difference. If it takes longer than 40mSec I just carry on. The main issue is keeping a close eye on frame rate on min-spec hardware during development and ensuring you very rarely take longer than 40mS.

I'm not advocating doing it this way of course, it's just a hack to simplify things with some known disadvantages.
Back to top
View user's profile Visit poster's website
codergames



Joined: 20 Apr 2010
Posts: 167



PostPosted: Tue Apr 27, 2010 12:28 pm    Post subject: Reply with quote

One of disadvantages is that you can get slight speedup or slowdown every random number of frames, like a sudden jump. But, I've seen other open source engines do this as well, like ClanLib. Its not that they don't know what they're doing, its just that they assumed most of the people have high-end configurations.

In the beginning I did exactly the same thing with sleep(), but it gave inconsistent results ... or I did not do it properly, which might be the case.

I tried to make my code execute fast on old configurations and it does, very smoothly.

Anyway, please download again and test it for me, if you want, when you get the chance. I removed the code that might have affected the calculations, although can't see the reason why, and it couldn't affect it more than on couple of first frames.
Back to top
View user's profile Visit poster's website
Poo Bear
Pod Team
Pod Team


Joined: 14 Oct 2002
Posts: 4121
Location: Sheffield, UK



PostPosted: Tue Apr 27, 2010 12:45 pm    Post subject: Reply with quote

Still running running too fast I'm afraid Sad
Back to top
View user's profile Visit poster's website
codergames



Joined: 20 Apr 2010
Posts: 167



PostPosted: Tue Apr 27, 2010 1:03 pm    Post subject: Reply with quote

But the GetTickCount is executing the same as timeGetTime:

The return value wraps around to 0 every 2^32 milliseconds, which is about 49.71 days.

http://msdn.microsoft.com/en-us/library/ms724408%28VS.85%29.aspx

http://msdn.microsoft.com/en-us/library/dd757629%28VS.85%29.aspx

although its a different library ... hm ... one is kernel32 and the other winmm


Thanks for testing it again!
Back to top
View user's profile Visit poster's website
Konedima
Grammar Police
Grammar Police


Joined: 25 Oct 2003
Posts: 1068
Location: Sydney, Land of Censorship



PostPosted: Tue Apr 27, 2010 1:39 pm    Post subject: Reply with quote

If it helps, War Pong uses a timer built into Allegro (install_int_ex - not sure if equivalents exist in other languages) to execute a function 60 times a second - what does that function do? It sets a boolean to true. The main game loop will only execute if that is true (and sets it back to false as part of the loop). I'm not saying it's the best way to do it, but it works for me.
Back to top
View user's profile Visit poster's website
codergames



Joined: 20 Apr 2010
Posts: 167



PostPosted: Tue Apr 27, 2010 1:58 pm    Post subject: Reply with quote

Ouch, I looked at timer.c ... they wrote their own timer driver to make it totally independent of the platform. I though I got that since SDL is cross-platform. Allegro is much much slower than my engine, its not smooth and it has tearing and all other problems, I don't like it. But, thank you man, for trying to help!

You run the game under your configuration, please tell me which OS you're using?


Mark, could you please try it again, I'm sorry for bothering you like this?[/b]
Back to top
View user's profile Visit poster's website
Slyh



Joined: 25 Nov 2004
Posts: 480
Location: Karlsruhe, Germany



PostPosted: Tue Apr 27, 2010 9:42 pm    Post subject: Reply with quote

Poo Bear wrote:
Slyh wrote:

How do you do this, code-wise?

I accurately time how long one frame takes and if it's less than 40mSec then the main thread sleeps to make up the difference. If it takes longer than 40mSec I just carry on. The main issue is keeping a close eye on frame rate on min-spec hardware during development and ensuring you very rarely take longer than 40mS.

Thanks. I actually wanted to find out if you suspend/park the main thread to achieve the fixed framerate. In my experience the thread-sleep-approach was not precise enough, as Windows (or any other OS really) does not guarantee that the sleeping thread is woken up after the specified amount of time. So instead of sleeping for 1ms as requested, Windows may give execution back to the thread only after 5ms (or sometimes even later).

While this behavior certainly exists and may pose a problem, it was not actually the problem that caused the problem in the game(*) I'm currently working on, which is why I was asking. (The game had some strange lags, where it seemed as if the graphics were not updated for at least 100ms and more between random frames. This happened about 1-3 times a second.)

Thanks to this discussion and your answer I looked into my code (again) and made a lot of measurements, but with no luck; everything looked fine. So I finally looked into the low-level OpenGL stuff I'm doing and tried a different (manual) approach to swap the backbuffers after rendering. And this actually fixed the problem. Now everyhting is smooth, even when the thread sleeps some ms longer than required.
The problems seems to have been caused by a bug in Jogl. *sigh*

So, thank you, codergames, for this thread, and thank you, Poo Bear, for your answer, which motivated me to look into the code again. Helped me a lot. :)

(Or maybe not, as I plan switching to jMonkeyEngine soon, where this problem does not exist anyway. D'oh. ;-))

* About the game: It's a clone of a famous simulation game from 1991, created by a German game company that no longer exists. I'd love to show some screenshots or give some more info about it. But as I currently use the art of the original game -- well, vectorized versions of the graphics -- posting screenshots probably wouldn't be a good idea. The reason I plan switching to jMonkeyEngine is that I want do redo the graphics from scratch in 3D. As soon as there is something to show, you'll be among the first to see. :)
Although I've been working on the game since 2006 in my spare time with a lot of long pauses between programming, I don't expect to earn anything with it.
Back to top
View user's profile
codergames



Joined: 20 Apr 2010
Posts: 167



PostPosted: Wed Apr 28, 2010 5:52 am    Post subject: Reply with quote

Slyh, don't mention it man, glad I could help. The sleeping problem will always be there if you use sleep. Its not noticeable that much on high-end machines as on low-end, like Mark said.

So, Mark (Poo Bear), is it working, my game?

I've finally understood the difference between getTickCount I was using and timeGetTime, you suggested. Its the precision and although I don't need high precision at all, its just a game, timeGetTime is giving a bit smoother results, but it takes more CPU time as its updated more often than the other function. Other than that, its giving exactly the same info, milliseconds since the system was started and since I'm only using the difference between times, if the function returns zero, it does not matter as its not relevant, the difference will still be there.
Back to top
View user's profile Visit poster's website
Konedima
Grammar Police
Grammar Police


Joined: 25 Oct 2003
Posts: 1068
Location: Sydney, Land of Censorship



PostPosted: Wed Apr 28, 2010 7:17 am    Post subject: Reply with quote

I just tried the latest version - still going way too fast.
Back to top
View user's profile Visit poster's website
codergames



Joined: 20 Apr 2010
Posts: 167



PostPosted: Wed Apr 28, 2010 8:02 am    Post subject: Reply with quote

Who knows what it is ... I'm submitting to various download sites and they all seem to test and post their own screenshots of the game while testing, so I don't get it, most of them classified it under windows versions I haven't even heard of, like 2003, 2008 or something.
Back to top
View user's profile Visit poster's website
Poo Bear
Pod Team
Pod Team


Joined: 14 Oct 2002
Posts: 4121
Location: Sheffield, UK



PostPosted: Wed Apr 28, 2010 8:09 am    Post subject: Reply with quote

I think the best thing to do if at all possible would be to get a second hand laptop or low spec PC to stick windows7 on just for testing. It might be possible to dual boot and install win7 on your current machine, not sure. I bet if you could actually debug on win7 you'd fix it in 10mins.

I got an OEM version of win7 for 65, so a bit expensive but not too bad.
Back to top
View user's profile Visit poster's website
Slyh



Joined: 25 Nov 2004
Posts: 480
Location: Karlsruhe, Germany



PostPosted: Wed Apr 28, 2010 8:16 am    Post subject: Reply with quote

Or try installing it in a VM, for example in VirtualBox. This helped me a lot when I tried to find a texture loading problem that was not reproducible on my system. Fortunately it was reproducible in the XP image I installed in VirtualBox.
Back to top
View user's profile
codergames



Joined: 20 Apr 2010
Posts: 167



PostPosted: Wed Apr 28, 2010 8:42 am    Post subject: Reply with quote

Thanks guys, but I don't have a Win7, don't want to buy it. Nobody complained, so until I get complains like its not working or something similar. I thought people don't complain about that problem because they are shy or something, but since I got complains about the price and requests for an alternative payment option, that doesn't seem to bother them. Its possible that everyone who played it, played on XP. All complains I got were related to the price and insults about how such small game could cost that much. I'm guessing it works for them.
Back to top
View user's profile Visit poster's website
codergames



Joined: 20 Apr 2010
Posts: 167



PostPosted: Wed Apr 28, 2010 9:04 am    Post subject: Reply with quote

Just to add that I tested it again on 3 different configurations with new time function:

1. 1Ghz Celeron 256Mb 32Mb video nVidia 4 indeo (not even the official card that supports directx fully) with XP SP3

2. 1.6Ghz Celeron 512Mb video nVidia 128Mb 6600 GT, running Vista with service pack

3. core2duo 2.2Ghz 2Gb, nVidia 8900 running XP with SP2


The result of tests is an exact match, I mean exact match of everything, frame rate always constant, with 0.00000000000000000000000 ... something difference between the 3 configurations.

I made it write log file with real frame-rate, speed factor and current game frame rate and all in double precision.

I really don't know what to say ... I don't get it, its an exact match, no slowdowns no speedups, nothing!
Back to top
View user's profile Visit poster's website
codergames



Joined: 20 Apr 2010
Posts: 167



PostPosted: Wed Apr 28, 2010 9:09 am    Post subject: Reply with quote

And even visually, when you play the game on one configuration and then on another and then a little bit on the third ... all exactly the same.
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Discussion Pod Forum Index -> Independent Game Development All times are GMT
Goto page Previous  1, 2, 3, 4, 5, 6  Next
Page 4 of 6

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group