Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Sayuri

Pages: [1]
1
SFML projects / Re: Let There Be Light 2
« on: October 24, 2015, 09:37:00 am »
Why not make a pull request? ;)
Good idea, for some reason i didn't think about that option, thank you.
I'll do it later after work (and a bit of code cleanup, i accidently forgot to remove some unneccessary commented out code).

2
SFML projects / Re: Let There Be Light 2
« on: October 24, 2015, 02:01:21 am »
I hope lolz123 does not mind me posting this here:

For those interested in better LTBL2 performance and lights that can be switched on/off:
I've made a few small changes in the LTBL2 code by adding two boolean member variables (_isAwake and _isTurnedOn) aswell as appropiate get/set/toggle methods to the QuadtreeOccupant object.

Both the occluders aswell as the lights are initialized as both awake and on by default (so nothing changed in the behaviour of LTBL2 unless you manually switch them off/make them sleep).

namespace ltbl {
        class QuadtreeOccupant {

        public:
                bool _isAwake;
                bool _isTurnedOn;

                QuadtreeOccupant()
                        : _pQuadtreeNode(nullptr), _pQuadtree(nullptr), _isAwake(true), _isTurnedOn(true)
                {}


                bool isAwake();
                void setAwake(bool);
                void toggleAwake();

                void setTurnedOn(bool);
                bool isTurnedOn();
                void toggleTurnedOn();
        };
}

And then each time in the code when i found LTBL2 looping through all the Quadtree occupants (occluders and light objects) to do shadow/light calculations or rendering i inserted a single if-statement that first checks if the occluder/lightobject is actually active AND switched on before actually doing AABB-checks, any shadow calculations or any rendering.

Example in the render method:
void LightDirectionEmission::render(const sf::View &view, sf::RenderTexture &lightTempTexture, sf::RenderTexture &antumbraTempTexture, const std::vector<QuadtreeOccupant*> &shapes, sf::Shader &unshadowShader, float shadowExtension) {
        lightTempTexture.setView(view);

        LightSystem::clear(lightTempTexture, sf::Color::White);

        // Mask off light shape (over-masking - mask too much, reveal penumbra/antumbra afterwards)
        for (int i = 0; i < shapes.size(); i++) {
                LightShape* pLightShape = static_cast<LightShape*>(shapes[i]);
        //Check if Light is awake and turned on
                if (pLightShape->isAwake() && pLightShape->isTurnedOn()) {
        //...
        // Down here comes all the calculate/render stuff, which only gets done if light is awake and on
        //...
 

What's the advantage?
Turning lights/shadows on and off
Well, first of all you can turn lights and occluders(and thus shadows) on and off by using the
      void setTurnedOn(bool);
      void toggleTurnedOn();
methods, without having to delete the lights/occluders just to turn the light off or remove the shadow casting occluder. You can use for example light switches in your game that have a pointer/reference to the light object and by activating the switch you invoke the toggleTurnedOn() method of the pointed-to light.

Performance boost by putting offscreen/not-in-same-room LTBL2-objects to sleep
In addition to that, you can put your lights and occluders to sleep (similar to sleep/awake in Box2d) by using the
      void setAwake(bool);
      void toggleAwake();.
methods.
These methods allow LTBL2 to skip calculations for the light/occluder without modifying whether the light/shadow, from the game world perspective, is switched on or off (by a light switch in the level, for example).

How would we use that?
Lets say you have a game with several rooms or zones, which all have light objects. It'd be very inefficient if the game calculates and AABB-checks all the lights of your loaded level if you are not in the same room/zone of the light/occluder, regardless whether they are switched on or off (by switches in the level).
For that there is the "setAwake(bool)" method:
If you leave a room or zone then, on room/zone change, you could invoke a method that loops through all the lights/occluders in said room/zone and setAwake(false) for each of it. In the now new entered room/zone you would then loop through all occluders/lights and invoke setAwake(true) on each.
That way only the lights/occluders that are in the players zone/room get calculated/AABB-checked/rendered.

Example code:
(click to show/hide)


In short:
By using these modifications your game
-allows turning on/off of lights/occluders without having to constantly create/delete them
-the game keeps memorized which lights are turned on and off, since you don't create/destroy them all the time but just turn them off/on
-can get a huge performance boost by putting out-of-zone/out-of-room LTBL2 objects to sleep via setAwake(false) and only setAwake(true) if they are near the player/in the same zone or room as the player.

You can download the modified version here
https://www.dropbox.com/s/amk8v17btth6lmq/ltbl2_toggleable.zip?dl=0

Feel free to leave feedback or any errors (i couldn't find any, it's only about 15~20 lines of code that i added).

3
SFML projects / Re: PONG SFML C++
« on: July 30, 2015, 02:47:22 pm »
I am a maths student with limited knowledge of coding and I'm not entirely certain I have set up visual studio correctly yet...
Just curious : why does a math student have to take a course about game programming/sfml? Or is it an elective course? Just curious, since i'm an informatics student. But yea, expl0it3r is correct, it's your teachers job to help you setting up visual studio and sfml and teaching you the basics about game progrmaming and sfml.

Anyway, if you want to read some guides:
About SFML and setting it up for visual studio:
http://www.sfml-dev.org/tutorials/2.3/start-vc.php

Someone already made a tutorial about pong in sfml, you can find it here (it has 2 parts : #1 is basics of SFML and #2 is about pong)
http://www.gamedev.net/topic/628110-sfml-2-tutorial-pong/

4
SFML projects / Re: Let There Be Light 2
« on: July 28, 2015, 05:03:53 am »
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:

Code: [Select]
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:

Code: [Select]
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):

Code: [Select]
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"
Code: [Select]
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.

Pages: [1]