Thank you sooooo much for this project, it's really great!
I have a few questions, though:
To keep track of which lights and occluders belong to which object i not only use the "lightsystem.addLight(<light>)" to put a shared_ptr into the lightsystem but i also put shared_ptr of that same light in certain objects. For example for the flashlight of my player i currently have it like that:
class Player {
std::shared_ptr<ltbl::LightPointEmission> flashlight;
}
And when creating the light i put a shared_ptr in both the LTBL2 lightsystem object aswell as my player flashlight pointer, like that:
Player::Player() {
this->flashlight = std::make_shared<ltbl::LightPointEmission>();
...
this->game->getLightsystem().addLight(light);
}
Effectively both the player and the light system have now each a shared_ptr that point to the light object.
The problem is now: how do i actually delete/deactivate/turn off the lights (for example turn off a flashlight or turn off a light in a room)? For example if i want to switch the flashlight off with a toggleFlashlight method, how would i do that?
This doesn't work (in Player.cpp):
void Player::toggleFlashlight() {
this->game->getLightsystem().removeLight(this->flashlight);
}
because the shared_ptr from the player and the shared_ptr in the lightsystem are different, and the "removeLight()" method, as far as i can understand it, only checks for equality of the pointer (which isn't true, since the flashlight pointer of the player and the flashlight pointer in the light system have different adresses), not the actual light object that these pointers point to.
Do you have any suggestions how one could make lights that can be toggled on/off, and suggestions how to make object keep track of lights which belong to them while also being able to remove them at any time?
The only quick, but probably not smart, solution i found right now while writing this would be to set the scale to "0 ,0"
this->flashlight->_emissionSprite.setScale(0,0);
This causes the light sprite to be too small to be rendered, virtually making it invisible and thus "turn off", and then, when "turning the light back on", i would turn the scale back to what it was.
But that seems kinda silly, since then i'd have to keep track of the original sprite scale and still have many lights that still need to be calculated, just with a (0,0) scale.
Another wierd alternative would be, instead of turning the scale to (0,0), to set the sprite color to sf::Color::Transparent, in order to make the sprite invisible, and then sf::Color::White to make the light visible again.
Do you have any suggestions which one to choose, or even alternatives for turning lights on/off?
In addition to that, may i suggest an "setActive(bool)" method, similar to Box2Ds system, for lights and occluders?
In Box2d you can set bodies to active or inactive, and if they're set to "setActive(false)" then these bodies won't be used for almost any calculation.
Could maybe something similar be done with LTBL2, where we can toggle lights and occluders on and off via "setActive(bool)" method, and inactive lights won't be drawn/inactive occluders won't make any shadows?
This could give us more control over the lights while also possibly saving performance by ignoring inactive lights/occluders in the render/quadtree calculations?
This is a really great project.
Again, thank you so much for creating it! I hope you will continue working on it.