Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Browsing history while it is being generated  (Read 1258 times)

voliol

  • Bay Watcher
    • View Profile
    • Website
Browsing history while it is being generated
« on: January 23, 2022, 04:32:45 am »

In the last devlog, you pondered whether some legends should be browsable by clicking the events shown in the world generation screen. If browsable legends during world gen make it in, they should not pause the world generation when used.
It would turn browsing from something stalling your worldgen causing it to take longer, to a way to kill time while you are waiting. And as you are fun, the time passes even faster.

kontako

  • Bay Watcher
    • View Profile
Re: Browsing history while it is being generated
« Reply #1 on: January 23, 2022, 05:15:14 am »

Great idea.

I do imagine some difficulty navigating through a list that's receiving tens to hundreds of updates a second though. But that may just a problem in my imagination.

Related to that same point, judging by the last sentence in the devlog, world generation might need to be paused to enable timely player interaction (in the mythy-much-later update).
That's probably remedied with a pause and play button, with pause on by default.
Logged
"Confederacy of Businesses"?! By Armok's Blood! These Communist animals are CAPITALISTS!
"This town ain't big enough for the two of us, turkey"
*gobbles menacingly*

Mr Crabman

  • Bay Watcher
  • A person with the head and pincers of a crab.
    • View Profile
Re: Browsing history while it is being generated
« Reply #2 on: January 23, 2022, 05:41:03 am »

Related to that same point, judging by the last sentence in the devlog, world generation might need to be paused to enable timely player interaction (in the mythy-much-later update).

This sounds like a case where multithreading would be quite helpful and also not a massive ordeal (unlike the usual multithreading suggestions). You wouldn't be trying to separate individual events in a tangled web of cause and effect (like in fort mode), you'd just be making a browsing window in a separate thread to worldgen. Incidentally, this approach would also come with potential benefits other than just responsive windows for legends browsing, such as being able to generate multiple worlds at a time, each on its own CPU core, or even playing in an already created world while you generate a new one.

Worldgen would need to be paused occasionally to an extent if you wanted to pipe more information from the "worldgen thread" to the "legends browser thread", but this pausing could be done far less often than you would need to if you were trying to pause enough to keep a browser responsive (once every second or few seconds, vs the dozen times a second to make a browser responsive, and probably still feeling clunky).

You could also conceivably not update the legend browser automatically and just have a button to "update legends" with the new information.
« Last Edit: January 23, 2022, 05:48:28 am by Mr Crabman »
Logged

Quietust

  • Bay Watcher
  • Does not suffer fools gladly
    • View Profile
    • QMT Productions
Re: Browsing history while it is being generated
« Reply #3 on: January 24, 2022, 01:23:13 pm »

Related to that same point, judging by the last sentence in the devlog, world generation might need to be paused to enable timely player interaction (in the mythy-much-later update).

This sounds like a case where multithreading would be quite helpful and also not a massive ordeal (unlike the usual multithreading suggestions). You wouldn't be trying to separate individual events in a tangled web of cause and effect (like in fort mode), you'd just be making a browsing window in a separate thread to worldgen. Incidentally, this approach would also come with potential benefits other than just responsive windows for legends browsing, such as being able to generate multiple worlds at a time, each on its own CPU core, or even playing in an already created world while you generate a new one.

Worldgen would need to be paused occasionally to an extent if you wanted to pipe more information from the "worldgen thread" to the "legends browser thread", but this pausing could be done far less often than you would need to if you were trying to pause enough to keep a browser responsive (once every second or few seconds, vs the dozen times a second to make a browser responsive, and probably still feeling clunky).

You could also conceivably not update the legend browser automatically and just have a button to "update legends" with the new information.
One thing which never came up in your original thread is that before you could consider generating multiple worlds in multiple threads, the game would first need to be modified in order to allow multiple worlds to be loaded simultaneously, and that would actually require some very significant changes and likely result in a performance loss when playing with just one world (because everything would need to know which world it was looking at).

On the other hand, putting the UI on a separate thread from the actual world generation process (while still keeping it "one world at a time") would still require the addition of synchronization logic in many different places - otherwise, adding a new record to a list (e.g. a new civilization, site, historical figure, or just a history event) is likely to be non-atomic, and if the code that updates the list is interrupted by another thread, the list could very briefly end up in an inconsistent state where trying to access its contents could cause the game to crash, and even worse things could happen if worldgen tried to remove something while the UI was trying to display it (e.g. if a world got Rejected and it had to start over from scratch).
« Last Edit: January 24, 2022, 01:26:00 pm by Quietust »
Logged
P.S. If you don't get this note, let me know and I'll write you another.
It's amazing how dwarves can make a stack of bones completely waterproof and magmaproof.
It's amazing how they can make an entire floodgate out of the bones of 2 cats.

Mr Crabman

  • Bay Watcher
  • A person with the head and pincers of a crab.
    • View Profile
Re: Browsing history while it is being generated
« Reply #4 on: January 25, 2022, 09:05:07 am »

One thing which never came up in your original thread is that before you could consider generating multiple worlds in multiple threads, the game would first need to be modified in order to allow multiple worlds to be loaded simultaneously, and that would actually require some very significant changes and likely result in a performance loss when playing with just one world (because everything would need to know which world it was looking at).

I'm not convinced that having multiple worlds loaded at once would either be especially difficult or require "very" significant changes, or that having to know which world it's looking at would have any kind of performance hit.

Sure, there would be a slowdown of some amount if you have another world open at the same time, but certainly not if you only have one world loaded/generating, and doing multiple would sure be faster than generating the worlds one at a time (some people have actually done this by running more than one `Dwarf Fortress.exe` at a time), and as for playing in a world while others generate, this would indeed be slower both for playing and generating, but the idea is that you wouldn't just be staring at the screen (well, the new legends browsing info would make it less boring, but still).

And the performance hit while there are multiple loaded/active would have nothing at all to do with "everything needing to know which world it's looking at", it would be from bottlenecks caused by sharing the cache and RAM data channels with other worlds. I can't even tell what you mean by everything "needing to know which world it's looking at".

On the other hand, putting the UI on a separate thread from the actual world generation process (while still keeping it "one world at a time") would still require the addition of synchronization logic in many different places - otherwise, adding a new record to a list (e.g. a new civilization, site, historical figure, or just a history event) is likely to be non-atomic, and if the code that updates the list is interrupted by another thread, the list could very briefly end up in an inconsistent state where trying to access its contents could cause the game to crash, and even worse things could happen if worldgen tried to remove something while the UI was trying to display it (e.g. if a world got Rejected and it had to start over from scratch).

Well obviously synchronization logic would be needed, but I don't see why it would be in "many different places"; there's a very limited and specific set of data that needs to be sent to the UI, and it doesn't need to be sent continuously.

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: Browsing history while it is being generated
« Reply #5 on: February 15, 2022, 08:41:33 pm »

One thing which never came up in your original thread is that before you could consider generating multiple worlds in multiple threads, the game would first need to be modified in order to allow multiple worlds to be loaded simultaneously, and that would actually require some very significant changes and likely result in a performance loss when playing with just one world (because everything would need to know which world it was looking at).

I'm not convinced that having multiple worlds loaded at once would either be especially difficult or require "very" significant changes, or that having to know which world it's looking at would have any kind of performance hit.

It would only require the `world` structure to be replaced with a pointer to `worlds[0]` or, if worlds is itself a vector of pointers, a copy of `worlds[0]`, and that would only require every single `world.` in the code to be replaced with `world->`, which surely wouldn't be horrible! In the absolute best case scenario! And actually it would probably be horrible!

Sure, there would be a slowdown of some amount if you have another world open at the same time, but certainly not if you only have one world loaded/generating, and doing multiple would sure be faster than generating the worlds one at a time (some people have actually done this by running more than one `Dwarf Fortress.exe` at a time), and as for playing in a world while others generate, this would indeed be slower both for playing and generating, but the idea is that you wouldn't just be staring at the screen (well, the new legends browsing info would make it less boring, but still).

Well, see, that's the thing, just running multiple Dwarf Fortress.exe windows at a time is an option, and even a good one, since there's command-line options to generate worlds.

Well obviously synchronization logic would be needed, but I don't see why it would be in "many different places"; there's a very limited and specific set of data that needs to be sent to the UI, and it doesn't need to be sent continuously.

You're going to need a read-writer lock for the events vector, more than likely, which severely reduces the potential gain from the threading, since you're going to want a read lock while getting the data. Of course, you probably don't actually need that and can instead send every potentially-relevant event to a channel... which apparently you have to roll your own for C++, ow.