SFML community forums

General => SFML projects => Topic started by: Glocke on January 06, 2015, 09:49:31 am

Title: SfmlExt: An extension to SFML using Thor and C++11
Post by: Glocke on January 06, 2015, 09:49:31 am
Hi there,

during the last months, I was working on my Isometric Coop Rogue-like Game Rage (http://en.sfml-dev.org/forums/index.php?topic=16367.0), which is currently paused because of too less spare time. So I started reworking/refactoring the entier codebase. During this process I found some pieces of code which are solving several problems I faced during development. So I started to isolate those solutions to make them reusable. Finally, I decided to put those solutions on github and call this repository "SfmlExt" - because it seems like an extension - at least to me.

It requires C++11 (which should be wide-spread by now), works with SFML 2.2 and can be found here: https://github.com/cgloeckner/SfmlExt

Briefly, it's a set of functionality which is distinct from the current SFML release as well as from Thor. Currently, there the following "sub-projects" are included:
This list is outdated. View README on github for further details.
(click to show/hide)

So, stay tuned for future commits :o For updated examples view the GitHub repository!

Thanks for reading! I'm looking forward to your feedback.

Kind regards
Glocke

/EDIT: (10.01.15) Major API Update (removed outdated examples from this post)
/EDIT: (21.01.15) Moved outdated feature-list (see spoiler)
Title: Re: SfmlExt
Post by: Mutoh on January 06, 2015, 04:35:25 pm
Aw, no namespace? That is always nice having in libraries you want to distribute.

Also, in your second example code:

    // load that archive
    TexArchiveReader reader;
    assert(reader.open("out.bin"));

Even if is just example code, I heard that it's not wise to put fundamental actions inside assert's, because in some compilation settings the entire assert line might be optimized away - and with it, reader would never open "out.bin".
Title: Re: SfmlExt
Post by: Glocke on January 06, 2015, 05:41:47 pm
Aw, no namespace? That is always nice having in libraries you want to distribute.
Yes, that's right! The code pieces are small and not really related to each other. So I don't see a necessary to introduce namespaces. But this might change in future ;)

Also, in your second example code:

    // load that archive
    TexArchiveReader reader;
    assert(reader.open("out.bin"));

Even if is just example code, I heard that it's not wise to put fundamental actions inside assert's, because in some compilation settings the entire assert line might be optimized away - and with it, reader would never open "out.bin".
Well good point! I'm not quite sure whether the checking is the only thing that's "optimized away". If the entire expression is dropped, you're totally right! But maybe only the checking is optimized away. So the assertion might be replaced by the previous evaluation - without asserting it at runtime. If the expression is pure const, the compiler might also optimize it away... don't know how it's done, sry.

But thanks ;D
Title: Re: SfmlExt
Post by: Jesper Juhl on January 06, 2015, 06:13:31 pm
assert()s are usually macros that are simply not defined in release builds, so they go away completely. That includes any code passed as arguments. So you should never put any code with side effects in an assert.
Title: Re: SfmlExt
Post by: Glocke on January 06, 2015, 06:21:44 pm
assert()s are usually macros that are simply not defined in release builds, so they go away completely. That includes any code passed as arguments. So you should never put any code with side effects in an assert.

Ok thanks! I'll change this soon!
Title: Re: SfmlExt
Post by: Glocke on January 10, 2015, 02:15:01 pm
Hi there!

I just pushed a major API change / repository cleanup to the repository. Here's a (brief) list of changes:

General:

Image Atlas:

Resource Caching:

Thanks for reading :) View the repository https://github.com/cgloeckner/SfmlExt for further details ;)

And thanks for your feedback (see red changes)

Kind regards,
Glocke
Title: Re: SfmlExt
Post by: Glocke on January 10, 2015, 07:27:50 pm
And currently, I'm working on a tiling implementation. A attached an example screenshot.
Title: Re: SfmlExt
Post by: SpeCter on January 10, 2015, 08:21:20 pm
Any reason you use push_back in your atlas.hpp to add the chunk instead of defining a constructor and using emplace_back instead?
Title: Re: SfmlExt
Post by: Glocke on January 10, 2015, 08:37:05 pm
Any reason you use push_back in your atlas.hpp to add the chunk instead of defining a constructor and using emplace_back instead?

No, it's just laziness.. But that's a good idea! :)

/EDIT: But another solution (without defining a ctor) might be: emplace_back without arguments, calling back() to get the reference and than set the properties. Writing a ctor isn't really necessary, because there's only one spot where a chunk is initialized, and there is no RAII-critical data access.
Title: Re: SfmlExt
Post by: Ixrec on January 10, 2015, 09:32:18 pm
I suspect a push_back(args) isn't all that different from an emplace_back() followed by thing.setArgs(args).  Probably shouldn't worry about it until you have profiler data showing it makes a difference.
Title: Re: SfmlExt
Post by: SpeCter on January 10, 2015, 10:06:31 pm
I only asked because emplace_back describes more clearly that he only wants to move a temporary into the vector, not for performance reasons  ;)
Title: Re: SfmlExt
Post by: Glocke on January 13, 2015, 01:50:26 pm
Hi, about that push_back/emplace_back: I'll think about it which fit's the code best!

Update on SfmlExt:
I just finished an initial tiling implementation. It's main use is to encapsulate common tiling operations like iterating all visible tiles - or briefly:
for (auto const & tile_pos: scene) {
    // ... render this tile
}

Here's a list of features:
There's also an example you can check out! Again, everything is located at http://github.com/cgloeckner/SfmlExt (http://github.com/cgloeckner/SfmlExt) (including compilable examples).

About the implementation and possible usage:

Feel free to discuss about implementation or API details.

Kind regards
Glocke
Title: Re: SfmlExt
Post by: Glocke on January 21, 2015, 08:56:44 pm
Hi, today I had enough time to finish working on a simple menu-gui-system. The commit (https://github.com/cgloeckner/SfmlExt/commit/44425a10778a565f3744dc6ab37dc89769723bf8) was just pushed, so implementation and example code can be found on GitHub!

An overview:

See the example code for further details! Feel free to feedback about this commit ;)

Kind regards
Glocke

PS: A screenshot of very simple menu example is attached.
Title: Re: SfmlExt: An extension to SFML using Thor and C++11
Post by: Glocke on January 23, 2015, 05:49:10 pm
Meanwhile, initial implementations for a context-related state machine / application wrapper class and a blueprint for logging mechanics with support for various SFML-types (like Vector2<T>) has been finished.

Feel free to feedback ::)
Title: Re: SfmlExt: An extension to SFML using Thor and C++11
Post by: Glocke on March 07, 2015, 07:11:42 pm
Today, I added an initial implementation for audio fading. The fading is determine by two lambda functions (for fading in and fading out) which can be modified during runtime.

There's a MusicManager class which is able to fade between two music track just by triggering another one to be played! Full commit can be viewed here (https://github.com/cgloeckner/SfmlExt/commit/33049739f5dd2beeabb07a20d2aff2f829b08f17). The code is currently out of comments - this will be fixed soon! :)

A runnable example is located at the github repository. But here is "fader in a nutshell" - hope you like it!

#include <SFML/Window.hpp>
#include <SFML/Audio.hpp>

#include <SfmlExt/fader.hpp>

int main() {
        auto t = sf::milliseconds(50);
        sfext::MusicManager manager;
        float volume = 100.f;
       
        manager.play("data/wesnoth.org/battle_edit.ogg");
       
        while (true) {
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Return)) {
                        // fade-in / cross-fade
                        manager.play("data/wesnoth.org/battle_edit.ogg");
                }
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) {
                        // fade-out
                        manager.stop();
                }
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
                        // volume up
                        volume = std::min(100.f, volume + 5.f);
                        manager.setMaxVolume(volume);
                }
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
                        // volume down
                        volume = std::max(0.f, volume - 5.f);
                        manager.setMaxVolume(volume);
                }
               
                manager.update(t);
                sf::sleep(t);
        }
}
Title: Re: SfmlExt: An extension to SFML using Thor and C++11
Post by: Glocke on June 14, 2015, 09:45:06 pm
Meanwhile I started a branch SfmlExt/unit-testing (https://github.com/cgloeckner/SfmlExt/tree/unit-testing) which is currently under development. Once this is done, I'll move the framework to a pure header-only framework. This seems suitable for me, because most of the code is already heavy-templated.

Sooo this stuff IS still an active sub-project of mine :)