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

Author Topic: Thor 2.0 released!  (Read 368119 times)

0 Members and 1 Guest are viewing this topic.

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Thor 2.0
« Reply #165 on: March 26, 2013, 11:15:10 pm »
Quote
Thanks for the feedback, FRex.
Don't thank me for whining. ;)
Back to C++ gamedev with SFML in May 2023

Silvah

  • Guest
Re: Thor 2.0
« Reply #166 on: April 12, 2013, 01:48:34 pm »
I disowned the Thor package in AUR. It's still there, but I don't maintain it anymore, it'd be good if somebody picked it up from there.

The Terminator

  • Full Member
  • ***
  • Posts: 224
  • Windows and Mac C++ Developer
    • View Profile
Re: Thor 2.0
« Reply #167 on: April 14, 2013, 08:28:20 pm »
Hi there. I successfully compiled and linked Thor 2.0 into my current project, and I'm using actions to rework some of my buttons, key commands, etc. However, whenever you click once on mouse or whatever, it does the action atleast 5 times, and it's getting extremely annoying. Here's some example code:

I initialize the actions:

thor::Action m_exitAction;
thor::Action m_mouseClickedAction;
thor::Action m_fpsShortcut;

Init them with the constructor:

m_exitAction(sf::Event::Closed),
m_mouseClickedAction(sf::Mouse::Left),
m_fpsShortcut(sf::Keyboard::F)

I've also tried thor::Action::PressOnce, and that makes the key or mouse button click infinitely.

And set them to the corresponding enumators:

m_actions[EXITACTION] = m_exitAction;
m_actions[LMOUSECLICKACTION] = m_mouseClickedAction
m_actions[FPSSHORTCUTACTION] = m_fpsShortcut;

Then I actually use it:

void CIntroState::update() {
    while(m_game.screen.pollEvent(event))
        m_game.getActionMap().pushEvent(event);

        if (m_game.getActionMap().isActive(CGameEngine::Actions::EXITACTION))
        m_game.quit();

    else if (m_game.getActionMap().isActive(CGameEngine::Actions::LMOUSECLICKACTION))
    {
        if (m_play.isHoveredOver(m_game.screen))
            m_next = m_game.build<CIntroState>(true);
        else if (m_options.isHoveredOver(m_game.screen))
            m_next = m_game.build<CSettingsState>(true);
        else if (m_exit.isHoveredOver(m_game.screen))
            m_game.quit();
    }

    else if (m_game.getActionMap().isActive(CGameEngine::Actions::FPSSHORTCUTACTION))
    {
        if (m_game.getFPSOn())
            m_game.setFPSOn(false);
        else
            m_game.setFPSOn(true);

        m_game.saveOptions();

        std::cout << "FPS has the value: " << m_game.getFPSOn() << " now." << std::endl;
    }
}

I appreciate any answers.
Current Projects:
Technoport

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Thor 2.0
« Reply #168 on: April 14, 2013, 08:49:19 pm »
I disowned the Thor package in AUR. It's still there, but I don't maintain it anymore, it'd be good if somebody picked it up from there.
Okay. I don't really have the experience with AUR packages, so if anybody is willing to maintain it, feel free to do so :)

However, whenever you click once on mouse or whatever, it does the action atleast 5 times, and it's getting extremely annoying.
Without a second argument to the Action constructor, you choose real-time input (Action::Hold). That means the action is active all the time a button is pressed down. You want to use Action::PressOnce.

I've also tried thor::Action::PressOnce, and that makes the key or mouse button click infinitely.
You forgot to call ActionMap::clearEvents(). But you can directly call ActionMap::update() with the window, see here for its semantics.

Keep in mind that there may be more than a single action active per frame, so your else if should be if. Or you directly use callbacks.

By the way, you can keep your action and event variables local, there is no need to make them class members. In the case of event, you don't need the variable anyway if you call ActionMap::update().
m_actions[EXITACTION] = thor::Action(sf::Event::Closed, thor::Action::PressOnce);
...
sf::Event event;
while (m_game.screen.pollEvent(event));
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

The Terminator

  • Full Member
  • ***
  • Posts: 224
  • Windows and Mac C++ Developer
    • View Profile
Re: Thor 2.0
« Reply #169 on: April 15, 2013, 11:32:25 pm »
Thanks a lot for the help. You fixed my other problem, but I'm sort of confused on animations. I followed the example from the latest version (with the soldiers), but I'm having a problem with one thing. Whenever I try to add a frame, it'll crash the executable. Here's my code:

m_animation1.addFrame(1.0f, sf::IntRect(m_game.getEntityManager()("player")->getSprite().getTextureRect()));

m_animation2.addFrame(2.0f, sf::IntRect(m_game.getEntityManager()("platform1")->getSprite().getTextureRect()));

Thanks
Current Projects:
Technoport

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Thor 2.0
« Reply #170 on: April 16, 2013, 09:03:59 am »
With this information, I can't say where the problem is. Is the access to your entity manager defined (e.g. no dereferenced nullptr or similar)? What if you hardcode a sf::IntRect directly?

Have you already tried to debug your code, or maybe even to minimize it and track down the error? If you had a minimal and complete example, I could take a look at it...
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Re: Thor 2.0
« Reply #171 on: April 16, 2013, 09:09:58 am »
I'm having a problem with Thor's particle module regarding rendering: As far as I understand, all the particles use 2D positions and are rendered in one go. That however makes it impossible to render particles between objects I render myself.

For example let's say there are 3 layers. Layer 0 is the background, layer 1 holds objects, layer 2 is the sky. Because neither SFML nor Thor allow me to use custom z values for effectively making use of the z buffer, I'm not able to both render particles between layers 0/1 and 1/2. I can workaround that by creating 2 separate particle emitters/systems, but the example with 3 fixed layers is just a simple one.

Indeed I'm currently writing a game where aircrafts fly towards you. Some aircrafts are faster than others, so all of them have a "dynamic z ordering". For explosion effects I wanted to use Thor, but I can't see a way to properly render the particles at specific z positions, i.e. between aircrafts.

Any ideas? Is it even possible with SFML's current layout?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Thor 2.0
« Reply #172 on: April 16, 2013, 09:23:50 am »
This is currently not possible. Z ordering could be achieved in two ways:
  • Using the depth buffer. SFML does not support it at the moment, so the only option would be to do everything in raw OpenGL. I do not know how Laurent's plans are here, but this feature has already been requested a lot.
  • Sort the graphical objects before rendering. We would have to find a way to mix particles and other objects in a list. But then, we could not benefit of sf::VertexArray anymore.
Particle systems are only one of many situations where Z ordering is meaningful. I already thought about Z buffer functionality in Thor, but haven't found a good way to implement it generically, especially since SFML natively doesn't support it. How do you implement Z ordering for your own airplanes? You just sort them?

By the way, the affector/emitter API is going to change slightly; I will probably abandon shared_ptr and make the API simpler, like in the Animation module.
« Last Edit: April 16, 2013, 09:25:59 am by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Re: Thor 2.0
« Reply #173 on: April 16, 2013, 09:36:28 am »
Quote
How do you implement Z ordering for your own airplanes? You just sort them?
Yes, I sort them according to their z position. Since my plan is to only use SFML in my current game thingy, I had to do it the ugly way. ;) I'd definitely prefer making use of the depth buffer.

Quote
I already thought about Z buffer functionality in Thor, but haven't found a good way to implement it, especially since SFML natively doesn't support it
Yep, and that's the point. You'd have a hard time implementing z ordering using the depth buffer yourself if SFML does not support it. And working around that (which is painful, because it's such a low-level feature) can't be the solution.  At least I can't think of a clean solution for integrating it externally.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Thor 2.0
« Reply #174 on: April 16, 2013, 09:55:17 am »
Another important point is that depth buffering does not work with semi-transparent objects. So, manual sorting seems like the only way to go.

What I had in mind for a Z buffer was essentially a list of drawable objects that is sorted. This however opens up new questions, such as:
  • Who owns the entities? Does the Z buffer just hold pointers (so the caller can't use temporary sprites) or copies?
  • What do we do for sf::VertexArray? We would have to use sf::Sprites again. For example, Thor's particle system could have an affector that inserts sprites into a Z buffer. But thor::ParticleSystem is not designed this way, it's more a workaround.
  • Would it be possible to optimize the sorting and rendering? For particles, a Z buffer might become a performance bottleneck.
The idea is certainly interesting. For a long time, Z buffer was a feature on Thor's progress list, but considering the implementation and design difficulties, I didn't want to promise things that I weren't sure of ;)
« Last Edit: April 16, 2013, 09:57:21 am by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Re: Thor 2.0
« Reply #175 on: April 16, 2013, 10:02:11 am »
As I think more of it, it might be even possible. There could be a render queue that takes care of sorting drawables that you add to it. Something similar to this (but with a nicer interface):

sf::Sprite sprite;
sf::VertexArray array;
render_queue.add( sprite, 1.0f );
render_queue.add( array, 2.0f );

The floats determine the z position, as it can't be fetched from the drawables themselves. The queue will then insert the drawable into an internally sorted array. The sorting is dependent on things like z position and alpha color value (due to transparent stuff that has to be rendered front-to-back).

Ownership is very simple here: The queue only holds references (you'd store the drawables somewhere anyway). Also you can continue using SFML's drawables without any change.

To render it you'd only have to draw the queue:

render_window.draw( render_queue );

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Thor 2.0
« Reply #176 on: April 16, 2013, 10:05:25 am »
That's exactly the API I had in mind :)

But as far as I understood you, inserting a sf::VertexArray into the queue would not solve your problem, since you don't want it to be drawn at once. Therefore, one would have to split up the vertex array into single sprites (or at least smaller vertex arrays).
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Re: Thor 2.0
« Reply #177 on: April 16, 2013, 10:08:26 am »
Yes, because SFML does not support 3D positions and depth buffers. ;)

dragondgold

  • Newbie
  • *
  • Posts: 15
    • View Profile
    • Email
Re: Thor 2.0
« Reply #178 on: May 01, 2013, 06:05:00 am »
Hello! I am new at SFML 2.0 and I wanted to try Thor, I have successfully compiled SFML and Thor (with C++11 flag) and have it working on Eclipse CDT. The problem is when I try to run my program using Thor I get this:

/home/andres/Dropbox/workspace/PruebaSFML/Debug/PruebaSFML: error while loading shared libraries: libthor-d.so: cannot open shared object file: No such file or directory

I have /SFML-2.0/lib added to my linker and the library libthor-d.so exists and also I have copied it to /usr/local/lib but still the same error. I am on Ubuntu 12.04 x64. What I am missing?

PD: I have it running ok on Windows XP x86
« Last Edit: May 01, 2013, 06:42:49 am by dragondgold »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11001
    • View Profile
    • development blog
    • Email
Re: Thor 2.0
« Reply #179 on: May 01, 2013, 09:54:19 am »
I have /SFML-2.0/lib added to my linker and the library libthor-d.so
So is the libthor-d.so in the SFML directory? ???
Otherwise you'll also have to add /Thor/lib to the linking command.

exists and also I have copied it to /usr/local/lib but still the same error
/usr/local/lib is not set by default for the LD_PATH_LIBRARY, so you'll have to set LD_PATH_LIBRARY with /usr/local/lib manually first for the linker to search in that directory.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/