devilutionX icon indicating copy to clipboard operation
devilutionX copied to clipboard

Draft: allow for more light sources

Open ThomasChr opened this issue 3 years ago • 17 comments

I'm capping this to 255 for the moment because we're using it with an uint_8. Can be further increased if we change the uint_8 in lighting.h and lighting.cpp.

lighting.h, Line 43 extern uint8_t ActiveLights[MAXLIGHTS];

lighting.cpp, Line 21 uint8_t ActiveLights[MAXLIGHTS];

ThomasChr avatar Oct 14 '21 10:10 ThomasChr

Draft because: Untested. See also PR #3122

ThomasChr avatar Oct 14 '21 10:10 ThomasChr

In LoadGame() (loadsave.cpp:1751) loading a non-town save file expects exactly 32 light indexes/IDs followed by a max of 32 chunks of data representing each light. This will need to have logic added to save the first 32 active lights, then put the rest somewhere else while also ensuring that ActiveLightCount is 32 in old versions but gets the correct value for versions supporting more lights.

ephphatha avatar Oct 14 '21 10:10 ephphatha

Draft because: Untested. See also PR #3122

When you're ready you can use the Ready for review button that appears in the workflow status area: image

The mark as draft "button" is disguised as a text link, that appears in the side menu at the bottom of the Reviewers section, it'll be in the region I marked with a yellow box in this screenshot, but looks like a link: image

ephphatha avatar Oct 14 '21 10:10 ephphatha

I'm capping this to 255 for the moment because we're using it with an uint_8.

It is used with int_8, cap it to 127.

https://github.com/diasurgical/devilutionX/blob/master/Source/monster.h#L218

AJenbo avatar Oct 14 '21 11:10 AJenbo

It's a lot of noise for a single int change 😉

AJenbo avatar Oct 22 '21 09:10 AJenbo

I'm working on the save right now. Should have a test version today... It's a little bit more tricky then I thought.

ThomasChr avatar Oct 22 '21 09:10 ThomasChr

Just to note here: We‘re also saving:

  1. The number of active lights - which we need to reduce by the number of berserk light.
  2. The whole active lights array. Which has MAXLIGHTS Entrys. Also here we need only save 32 id's and no berserk light ids.
  3. For every active light the details.

So there are little more tricks to do. I find it strange that we‘re saving the whole activelights array even if most of them are in fact not really active.

ThomasChr avatar Oct 23 '21 07:10 ThomasChr

It was much more complicated then I thought at first. The code does seem to work right now. I will test a little more and remove the debug messages.

ThomasChr avatar Oct 25 '21 10:10 ThomasChr

crashes when saving with active firewall (missle light)...

ThomasChr avatar Oct 25 '21 11:10 ThomasChr

crash solved. Needs more testing and tidying up

ThomasChr avatar Oct 25 '21 12:10 ThomasChr

@AJenbo Do we favor single line if-, or for-loops with-, or without braces?

if (true)
    doWork();

for (int i; i <= 10; i++)
    doWork(i);

or

if (true) {
    doWork();
}

for (int i; i <= 10; i++) {
    doWork(i);
}

I did find both styles

ThomasChr avatar Oct 25 '21 12:10 ThomasChr

With is usually best since it's safer

AJenbo avatar Oct 25 '21 13:10 AJenbo

Perfect. I personally prefer with braces!

ThomasChr avatar Oct 25 '21 13:10 ThomasChr

Once this gets merged it would be nice if you wold work on the same for missiles :)

AJenbo avatar Oct 25 '21 13:10 AJenbo

... you change the line endings in loadsave.cpp so now it looks like all of it is rewritten

AJenbo avatar Oct 25 '21 15:10 AJenbo

Yay! Seems that I've triggered a bug... https://youtrack.jetbrains.com/issue/IDEA-262067

ThomasChr avatar Oct 25 '21 16:10 ThomasChr

As noted in https://github.com/diasurgical/devilutionX/pull/3292 It should also be possible to not save lights for light objects (torches...). Because they will be applied in the game loop anyways. So we don't save:

  • Berserk Monsters
  • Missiles
  • Light Objects

What else is there left? I know that we have light sources for unique monsters (which also can be applied after loading), and all the other light sources I can think of (player, golem...) can also be applied AFTER loading. To me there is no sense in saving lights at all. Am I wrong?

ThomasChr avatar Oct 27 '21 05:10 ThomasChr