Jump to content

Proper way to define character move speed


Shekn

Recommended Posts

Posted

I am trying to extend the demo game for GemRB. I am rendering sprites with animations for the character and want to use these sprites in the game. When I use the walk animation with 30 frames, the character moves too fast, when I rescale the animation and render it with only 15 frames, the character moves slowly. It looks like the length of the walk animation determines the speed at which the character moves. Is this the correct way to define the character's movement speed? Or are there some constants that allow you to tweak it?

Another related question. By default all animations are drawn at 15 fps. Is it possible to draw animations in the game with (at least) 30 fps? Because with higher fps it looks smoother and nicer. I notice that there is a constant

#define ANI_DEFAULT_FRAMERATE	15.0f

Is it possible to simply change this constant and recompile GemRB? Or it's not that simple.

Posted

Three things:

- movement rate is defined per animation type in moverate.2da

- when missing, the frame count of the first walking animation is used (this is currently the case for the pc)

- how that converts to pixel speed is determined by the empirical StepTime parameter in gemrb.ini

 

You can set the drawing FPS for everything in your config file (CapFPS key). That would mean doubled frames if the animation is at just 15 FPS, otherwise more will be displayed.

Posted

I am not fully understand how to increase the animation frame rate. Here is a simple example. I render a simple iddle animation of the jumping ball. It contains 29 frames.

zSSEyWM.gif

I set CapFPS to 60 (it's visible on the gif). The length of the animation is nearly 2 seconds, because used frame rate is 15 fps. I would like to setup it 30 fps and output the full animation during 1 second.

 

For creating sprites I render it into png and gather into one bam-file by using convert tool from Near Infinity. It's more convenient than DLTCEP. But there is a problem, that I don't know how to solve yet. I would like to use rendered sprites with soft shadows from objects. It required non-clamped alpha channel. As i understand, in this case the bam-file should be saved in PVRZ-based format. But when Near Infinity save this bam, it store sprite information in the separate pvrz-file with default name MOS1000.pvrz. So, when I save another file, it overwrite the previous one. How it's possible to set unique name for each pvrz-file? Or may be the bam-file with non-clamped alpha can be saved by using other software?

Posted (edited)

Hmm, you are right, I see nothing can set the FPS for regular animations, which include the character ones. Will open an issue. The BAM formats don't have any fields for this, so either we'll have to extend them and fix the tooling or provide a workaround like an extra column in avatars.2da or a separate table (which would only fix it for actors).

As for PVRZ BAMs, you are right, the prefix is hardcoded. What you can do is change the default index in the Options of the BAM window. Each time. I'll suggest it gets fixed upstream — thanks for the insight. In the interim Argent77 says:

Quote

Btw, only the default PVRZ start index is set in the converter options. The start index for the current session can be modified directly in the BAM converter Frames tab when you select BAM V2 output.

 

Edited by lynx
Posted (edited)

How much FPS variability do you envision? So far the best idea from the standpoint of power and simplicity for the end user is to have an extra table where one can specify the FPS per BAM file.

EDIT: it's now done. You can edit demo/override/animfps.2da and set FPS as you will per-file. You'll have to grab the latest build though.

Edited by lynx
Posted

Great. Thank you very much. But there is an issue. When I setup 5 fps (for example), then the engine properly show each frame a long time. But with 30 fps it simply skip odd frames. During the one second the engine show only 15 different frames with step of two frames.

I create a test animation with number of frames. Then set 30 fps and record the screen. This gif show the animation frame-by-frame

c34UB7a.gif

It looks like in the NextFrame method from the Animation.cpp:86 the value

tick_t inc = (time - starttime) / delta;

is equal to 2. May be it's because this methods called only 15 times per second.

Posted

I guess this is still a test with an avatar? That's surely matching the gameAnimation test, which only then updates the time depending on the AI framerate. Btw the chain starts in Interface::Main, where the GameLoop is throttled, but not drawing (the DrawWindows call).

So it should work fine if you add a line to demo/gem-demo.ini (Time.ticksPerSec gets set to half this value):

Quote

Maximum Frame Rate = 60

Not ideal though, since it means everything will be sped up, so we need to figure out a better solution. It has to remain a game animation, so it doesn't continue animating when the game is paused. I don't think this decoupling will be a simple fix; of the top of my head I can't think of anything better than to refactor it to check the pause state directly. Will open a reminder.

Posted

I think that setting Maximum Frame Rate = 60 is an acceptable solution. As I understand, it forces to make 30 updates per second for calculating the world state (in particular executing scripts and so on). It looks like normal behavior. Of course, some actions can be executed less often (15 times per second), but this requires more complex behavior of the engine.

I also noticed that with Maximum Frame Rate = 60 the meaning of FPS in animfps.2da is not consistent. At 15 the engine draws all frames (so the animation frame rate is 30), but at 30 it starts skipping odd frames (the animation frame rate becomes 60).

In any case, thank you for your remarks and explanations.

Posted

I gave it some more thought between fighting our build bots and the needed change will be localized. I guess you can't test patches, so expect the change sometime this coming week. Then there won't be any need to even consider maximum AI frame rate.

Posted

Just went ahead and did it, you should be able to retest once the build completes. You can remove the change to Maximum Frame Rate, but of course keep the one in animfps.2da.

Posted

Thank you very much again. I downloaded the latest build and 30fps animation works fine. Now it's more visible that the character movement process is also running 15 times per second. This results in a little stroboscope effect. This is because two different frames are drawn at the same character position. In any case, this effect can be eliminated by increasing the total fps.

Posted

It's probably better to change the movement speed factor, since that's something that users won't touch, while their max FPS could be arbitrary when uncapped or with vsync.

Posted

Ah, that doesn't help. Your assessment was correct, it stems from the slower script updates, which is what triggers walking. I don't think that's something we can decouple though, since it obviously affects the position. So for uses like this, a higher AI FPS is required.

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...