Setting up multithreading code is complicated!
Here’s what’s new:
- Set up a generic “task management” system for MMORPG Tycoon 2. Systems generate “tasks”, and tasks are assigned out to worker threads, which work on those tasks, and then let the main game know when the tasks finish. Heightmap building now uses these generic worker threads, instead of having their own threads. Right now, there are eight worker threads. But in theory, it’s probably best to have the same number of threads as the user’s CPU has cores, potentially plus one.
- Clutter generation stuff occurs using dedicated threads. I need to convert these over to use the new generic worker threads.
- The game now waits for all queued up tasks to complete, before rendering the next frame. This fixes some problems I was having before, where different blocks of terrain were updating at different times and not matching each other, just due to how long they took to calculate in the background threads.
- Fixed some issues with my OS X semaphore implementation (since OS X doesn’t support unnamed semaphores, for unknowable reasons).
- Worked around a renderer bug, where anything which had no texture was being drawn opaque, regardless of its material settings. This affects the live trunk, too; I’ll bring the fix across at the same time as the various threading fixes I’ve mentioned in the past week or so. (If anyone needs a quick workaround in the meantime, just remove the line “m_state_SetBool( vsRendererState::Bool_Blend, false );” from vsRendererSimple::SetMaterial() on VS_RendererSimple.cpp, line 958.)
And now, I’m completely sick of dealing with the complexity of threads, and so the next thing on my list will be more player AI. I think I’m going to work on making players assemble into parties that do quests together. That ought to be entertaining.
And it raises some interesting questions, which actually come up in the development of real MMORPGs; how to handle characters who are of differing levels, but who want to team up — ignore it? Boost the level of the lower character? Lower the level of the higher player? Not allow teaming between those characters? And worse, what do we do when a character completes a quest multiple times, accompanying different party members. Do they get the reward multiple times?
My understanding is that most modern MMORPGs now give credit for completing a quest again in this sort of situation, but older MMORPGs often will not give repeated completion XP. I wonder whether I need to make this configurable for players, or whether I should just take the modern approach and assume that that’s what everyone will want.
Lots of stuff to think about!