Jump to content

Regarding World::Update()


StOneDOes
 Share

Go to solution Solved by Josh,

Recommended Posts

I'm not sure I understand the documentation for this function World::Update(). The first param is:

frequency    number of updates per second

I would have thought that this would not be necessary, rather you would just call this function on each game frame? Think of a game server where you are essentially simulating the world, and likely capping the FPS to a suitable amount - lets say 100 frames per second. Do I call world->Update( 100 ) in some arbitrary place, or do I just called world->Update() on each frame, which is already capped out at 100 frames per second by some thread sleeping code that already ran in the given iteration of the game loop? What happens if I call world->Update( 100 ) on each game loop iteration?

Link to comment
Share on other sites

Game logic runs in own thread with 60 Hz by default. This param can change it. FPS can be way higher, but game logic would still run with this stable frequency. Most likely internally at the very end of what Update is doing sleep with left time till next game cycle iteration happens.

  • Upvote 1
Link to comment
Share on other sites

Ok thanks for the repply, but how is it running in its own thread if I'm calling the Update() function? I guess this begs the question, of what happens if I do not call World::Update()?

I'm not sure that this will be suitable for a game server, unless I don't understand correctly. I need to be able to simulate/update the world on command, and essentially pause simulation when I want, so that I can rewind play for things like lag compensation. If objects are still being moved around the world while I'm doing hit calculating then this would end badly. I hope I'm just misunderstanding here. Unless @Josh can you please provide a breakdown of how threads are handling things in the breakdown, thanks

 

Link to comment
Share on other sites

From my understanding World::Update do update physics, calls components Update() methods, etc.

There are undocumented methods Update() and Resume() for World, which probably is what you you need to be sure that nothing will happen even without calling Wolrd::Update().

Link to comment
Share on other sites

This parameter is intended to allow you to change the update frequency of the game, so you can do things like run physics at 90 updates per second, which may be appropriate for some driving games to perhaps twitch shooters. I do not recommend using this parameter as it is not used frequently and might not work totally correctly.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

On 1/21/2025 at 12:17 AM, Dreikblack said:

There are undocumented methods Update() and Resume() for World, which probably is what you you need to be sure that nothing will happen even without calling Wolrd::Update().

World::Pause() and Resume() only affect the world's clock, which updates once per call to World::Update. This is meant for pausing a game when a menu system is opened, or something like that. This will "trick" World::GetTime() into not noticing the paused time when the menu was open.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. 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.

 Share

×
×
  • Create New...