I know, this bug is reported at least 1000 times
Because this bug happens to me almost every time I log into the game, I spent some time trying to find out why it happens. So here are my findings. Maybe they can be used to fix the \"darkness\" bug once and forever.
Normal players who do not have the privilege to modify their source files and recompile Planesift may look at the end of this long post for a workaround.
Lights in the game are updated when crossing sectors or when the time changes. After starting up the client, sectors are changed from NULL to SectorWhereWeKeepEntitiesResidingInUnloadedMaps and then to the final sector (hydlaa_plaza in my test case).
Once the sector is changed, the
ModeHandler::ClearLightFadeSettings() function in the modehandler.cpp file is called. There is the following line in that function:
last_interpolation_reset = csGetTicks() - interpolation_time - 1000;
csGetTicks() returns the number of milliseconds since the CS engine was initialized and
interpolation_time is 40000.
Now, the number of milliseconds since the CS engine was initialized depends on a) speed of the computer, b) ping time to the server and c) how fast the user clicks on buttons to get into the game. In my case it is usually somewhere between 32000 and 38000.
So what would be the result if
csGetTicks() returns 38000? It would be -3000 (actually a very large positive number because the variable is of type unsigned int, but it is easier to use negative numbers here).
Then the
ModeHandler::UpdateLights(csTicks when) function is called in the same file with
when set to the same value than
last_interpolation_reset or -3000 in our case.
This function is supposed to update lights in a smooth way that the lights do not get switched on/off. It needs at least two runs to get lights updated where the first run initializes some light and color values.
If this function is now called with the value -3000, we run into the \"darkness\" bug, because there is this line:
if (when > last_interpolation_reset + interpolation_time)
-3000 + 40000 would be 37000. Since all these variables are actually unsigned integers, -3000 is a very large positive value (4294964296) and the equation is TRUE.
The function gets called only once, lights are updated with uninitialized light and color values and we have the \"darkness\" bug and/or strange colors on the screen.
In my client I changed the
ModeHandler::ClearLightFadeSettings() function in the following way:
csTicks current_ticks;
current_ticks = csGetTicks();
if (current_ticks >= (interpolation_time - 1000))
last_interpolation_reset = current_ticks - interpolation_time - 1000;
else
last_interpolation_reset = 0;
Seems to be working and I haven\'t seen any more problems.
All others who have to wait for official updates, there is a workaround for you:
After you start up Planeshift, wait at least 41 seconds before you enter the game. This makes sure that your lights and colors are properly updated.