ScummVM....how about some smooth scrolling in ScummEngine?

General chat related to ScummVM, adventure gaming, and so on.

Moderator: ScummVM Team

Post Reply
NovaCoder
Posts: 74
Joined: Wed Sep 23, 2009 11:53 pm

ScummVM....how about some smooth scrolling in ScummEngine?

Post by NovaCoder »

Hiya,

I've been looking at the latest version of the ScummEngine and it looks like the main game world update still uses an integer based delta. With this approach, I don't see how I will ever get more than 10fps out of my game (apart from multi-threading the sucker).

This is how I think it basically works at the moment:

Code: Select all

ScummEngine::go {
   // Determine how long to wait before the next loop iteration should start
 int delta = (VAR_TIMER_NEXT != 0xFF) ? VAR(VAR_TIMER_NEXT) : 4;

 // Wait...(Yawn...)
 waitForTimer(delta * 1000 / 60 - diff);

 ScummEngine::scummLoop(delta);
}

ScummEngine::scummLoop(int delta) {
  // Update game-world based on units
}
This is a very strange way of doing it, it's better to use this kind of approach.

Code: Select all

void main loop() {
  while(!shouldQuit()) {
    // Calulate how much time has passed since the last loop.
    float delta = (some code).

    scummLoop(delta);

    renderScreen();
    getUserInput();
 }
} 

ScummEngine::scummLoop(float delta) {
  // Update game-world based on units
} 
The second approach will ensure that the game runs at a constant speed no matter how fast the machine whereas a slower machine will just display less FPS.
User avatar
Julien
ScummVM Developer
Posts: 25
Joined: Wed Jul 11, 2007 2:45 am
Location: Boston, USA

Post by Julien »

Hi NovaCoder!

Thanks for the feedback. Features requests are better posted here: http://sourceforge.net/tracker/?group_i ... tid=418823

Not all developers read the forums so the right person might not see your post.

Also, contributing a patch (even a work in progress one) would go a long way. Dev time is limited, so implementing such a feature could take a long time or not happen at all unless someone takes interest in working on it (especially since there might be regressions and side-effects and so retesting games would be needed).
fingolfin
Retired
Posts: 1452
Joined: Wed Sep 21, 2005 4:12 pm

Post by fingolfin »

NovaCoder, you misunderstand the code. While it doesn't use floats, it still ensures that everything runs at a constant speed, albeit using integer arithmetic. The speed to be used is controlled by the scripts, by the way, and a multiple of 60 Hz (or, as gamers seem to put it, 60 FPS).

It is true that the integer based approach is not quite exact; it may cause the base framerate to be slightly higher/lower than 60Hz (say 59 or 61 Hz), but that shouldn't be perceptible.

It would be possibel to make it "fully" accurate by using an Audio::Timestamp (and its integer based, rounding free approach to counting frames and milliseconds accurately), although I don't think that it would have any perceptible impact.
User avatar
bobdevis
Posts: 567
Joined: Fri Jan 16, 2009 10:52 am

Post by bobdevis »

I am not intimately familiar with the ScummVM code, but I am working on an other project that uses libSDL.
You basically works with a millisecond clock and its use of integers is just fine.

int bla = SDL_GetTicks();
This gives you the amount of milliseconds since the program started running.

SDL_Delay(10);
This makes the program stop for 10 milliseconds.

With some these commands and some math you can make any kind of timer you like. The rounding error of one millisecond is WAAAY to small for a human to detect, so it's not much use for a game to go more precise then that.
fingolfin
Retired
Posts: 1452
Joined: Wed Sep 21, 2005 4:12 pm

Post by fingolfin »

Just for completeness, in addition to what's been said: Yes, the rounding error is too small for the human eye to notice, but when syncing audio & video these small differences can make a difference if they accumulate over a long time. 1/3 ms lag per second run over 10 minutes = 600 secs adds up to 200ms lag, which *is* perceptible.

Even when using floats, this accumulative rounding error can strike. Using integral fractions and exact computations (as Audio::Timestamp does), this problem is entierly avoided.
fischkopf
Posts: 113
Joined: Sun Mar 22, 2009 1:08 pm
Location: germany

Post by fischkopf »

i would like to be able to set my custom resolution.
User avatar
md5
ScummVM Developer
Posts: 2250
Joined: Thu Nov 03, 2005 9:31 pm
Location: Athens, Greece

Post by md5 »

fischkopf wrote:i would like to be able to set my custom resolution.
...which has nothing to do with the topic of this thread
NovaCoder
Posts: 74
Joined: Wed Sep 23, 2009 11:53 pm

Post by NovaCoder »

fingolfin wrote:NovaCoder, you misunderstand the code. While it doesn't use floats, it still ensures that everything runs at a constant speed, albeit using integer arithmetic. The speed to be used is controlled by the scripts, by the way, and a multiple of 60 Hz (or, as gamers seem to put it, 60 FPS).
Hiya,

Ok so you are staying that if the inner loop is already running at 60FPS this code will not do anything?

Code: Select all

 waitForTimer(delta * 1000 / 60 - diff); 
And if the loop is running at less than 60FPS (eg the machine is a bit slow) then delta will be updated to 'skip' the scripts forward to the correct place (to maintain a constant game-world speed)?

Thanks,
Chris
User avatar
ezekiel000
Posts: 443
Joined: Mon Aug 25, 2008 5:17 pm
Location: Surrey, England

Post by ezekiel000 »

If you skip the scripts forwards wouldn't that cause errors in the game?
fingolfin
Retired
Posts: 1452
Joined: Wed Sep 21, 2005 4:12 pm

Post by fingolfin »

(Just for the record, note that most SCUMM games don't run at 60 Hz, but rather at a fraction of that; typically 15 Hz.)

Things are never "skipped ahead". This is impossible to do in a scripting based system.

However, you do have a point in that the engine currently does not handl if a script engine iteration unexpectedly takes very, very long. The next iteration after that will have a delay of 0, but future frames won't delay further.
The engine could try to adapt to that by letting several future delays be 0, instead of just one, until the lag has been caught up with. We don't currently try to do this -- mainly to precisely match the behavior of the original engine, which didn't try to do this either.
User avatar
lazylazyjoe
Posts: 131
Joined: Mon Oct 01, 2007 4:14 pm

Post by lazylazyjoe »

I'm a little out of my league here, but wouldn't it be a bad idea to use floating point arithmatic in a game engine as some of the platforms (DS, GP2X) don't have FPU's?
fischkopf
Posts: 113
Joined: Sun Mar 22, 2009 1:08 pm
Location: germany

Post by fischkopf »

smooth scrolling for all the lucas arts games would be great.
Post Reply