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.


Topics - Glocke

Pages: [1] 2
1
General discussions / Module membership for sf::Packet
« on: June 27, 2016, 04:01:06 pm »
Hi, I've been using sf::Packet quite a while to prepare game data for being written to binary files (because of the builtin byte order handling). This makes e.g. savegames easily cross-platform. I understand that this functionality is also used while networking. But is it really necessary to attach the class to the networking module?

It isn't a big deal .. but more a question of grouping. Personally, I'd expect such things within the system module of SFML. Any thoughts on that?

Glocke

2
Graphics / Broken TexCoords when zooming sf::View
« on: June 18, 2016, 11:59:40 am »
Hi, I use a tileset texture with multiple tiles on it and sometimes - when the view is zoomed - a line from the next tile is drawn. So I expect the tex coords to be broken somehow ... but why?

Minimal example code:
#include <iostream>
#include <SFML/Graphics.hpp>

void add(sf::VertexArray& array, sf::Vector2u const & world_pos, unsigned int tile_offset, unsigned int tile_size) {
        sf::Vertex tl, tr, br, bl; // [t]op[r]ight etc.
        // setup positions
        tl.position = sf::Vector2f(             world_pos.x             * tile_size,             world_pos.y    * tile_size);
        tr.position = sf::Vector2f((1 + world_pos.x)    * tile_size,             world_pos.y    * tile_size);
        br.position = sf::Vector2f((1 + world_pos.x)    * tile_size,    (1 + world_pos.y)       * tile_size);
        bl.position = sf::Vector2f(             world_pos.x             * tile_size,    (1 + world_pos.y)       * tile_size);
        // setup texture coords
        tl.texCoords = sf::Vector2f(0.f,                tile_offset                     * tile_size);
        tr.texCoords = sf::Vector2f(tile_size,  tile_offset                     * tile_size);
        br.texCoords = sf::Vector2f(tile_size,  (tile_offset + 1)       * tile_size);
        bl.texCoords = sf::Vector2f(0.f,                (tile_offset + 1)       * tile_size);
        // add tiles
        array.append(tl);
        array.append(tr);
        array.append(br);
        array.append(bl);
}

int main() {
        sf::RenderWindow window{{800u, 600u}, "test"};
        sf::Texture tileset;
        tileset.loadFromFile("tileset.png");
        unsigned int tile_size{16u};
       
        sf::VertexArray array{sf::Quads};
        for (auto y = 0u; y < 20; ++y) {
                for (auto x = 0u; x < 20; ++x) {
                        unsigned int offset{0u};
                        if (y == 0 || y == 19 || x == 0 || x == 19) {
                                offset = 1u;
                        }
                        add(array, {x, y}, offset, tile_size);
                }
        }
       
        auto view = window.getDefaultView();
        float zoom{1.f};
       
        while (window.isOpen()) {
                sf::Event event;
                while (window.pollEvent(event)) {
                        if (event.type == sf::Event::Closed) {
                                window.close();
                        }
                }
               
                window.clear(sf::Color::Black);
               
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) { view.move(0, -1); }
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { view.move(0, 1); }
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { view.move(-1, 0); }
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { view.move(1, 0); }
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Q)) { view.zoom(1.01f); zoom *= 1.01f; std::cout << "zoom: " << zoom << "\n"; }
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::E)) { view.zoom(0.99f); zoom *= 0.99f; std::cout << "zoom: " << zoom << "\n"; }
               
                window.setView(view);
                window.draw(array, &tileset);
                window.display();
        }
}
 

Tileset png and screenshots are attached. Any ideas what's wrong with my implementation? (btw using SFML 2.3 from ubuntu wily repos)

3
Graphics / Performance on Drawing Lightened Scene
« on: May 25, 2016, 12:35:15 pm »
Hi, I'm aware of the existence of LTBL ^^
Atm I'm working on the overall performance of my RPG - its current bottleneck is my lighting implementation. That's why I cut it out to a minimal example. The code can be found on https://github.com/cgloeckner/sfml-lighting-test

On my laptop (Intel i7, GeForce GT 540M using NVIDIA binary driver 352.63 @ Ubuntu wily - btw other drivers cause major problems) the example code runs with
  • ~90 FPS for 20 Edges + 1 Light
  • ~80 FPS for 100 Edges + 1 Light
  • ~30 FPS for 100 Edges + 5 Lights
  • ~10 FPS for 1000 Edges + 5 Lights
I guess this is an issue related to my implementation. Got anybody an idea how I can find the bottleneck?

About the code: I seperated "light", "shadow" and "fog" layers because of my rendering order:
  • floor tiles
  • light layer (might colorize the floor)
  • objects (so they are not colorized by the lights)
  • shadow layer (hides objects behind obstacles
  • wall tiles (if I render those before the shadows, no walls will be visible)
  • fog layer (hides walls that are far away from light sources)
Maybe there even are ways to improve this :)

Thanks in advance!! :)

4
SFML projects / Seegurke - A Naval Minigame
« on: October 29, 2015, 01:12:48 pm »
Hi,

I just started a mini project about naval combat. The major inspiration was the third chapter of "The Curse of Monkey Island", which offered a very fun naval combat system. So I started a small prototype, because I'd like to build such a minigame as standalone application. The project's name is taken from the German version of Monkey Island 3; the name of Guybrush's ship is "Seegurke".



The code and art can be found on GitHub: https://github.com/cgloeckner/seegurke - it's build with C++11, SFML 2.2 and Thor 2.0, a CMake script is contained.

The current features are very limited, because I just started: Moving (W/S) and stearing (A/D), as well as shooting (Space) are implemented. Another ship is moving, but no collision is implemented yet (neither between ships nor between ship and cannonball).

Hope you like it anyway ^^ As I have enough time, I'll enhance the code. So keep in mind: It's only a prototype.

5
Hi, I'm going to refactor my animation system. That's why I'm here! My game has the following claims to my animation system:
  • Common frame animations (clipping rect, origin pos, durations, nothing special)
  • Multiple sprite layers: I separated my assets to multiple layers (BodyLegs, BodyTorso, ArmorLegs, ArmorTorso, Helmet, Weapon, Offhand). Each animation (e.g. Attack) has always the same number of frames and always the same duration per frame - nevertheless which layer. This will easly synchronize all layers.
  • I also seperated Moving from other Actions to allow some kind of "Run'n'Gun" - aka shoot the enemy while yourself is moving
  • Additionally, movement should be looped until it's stopped from outside. Actions should be animated only once.

Previously, I was using Thor's Animation handling, but those multiple layers forced me to use lots of animators for one single entity. Also, because I'm heavily focused on Data-oriented design, I'd like to animate my entities in a tight loop. So (at least in my opinion) Thor's Animation handling isn't what I'm looking for. Also, because I want to the same number of frames and duration across multiple layers, another solution might be more suitable.

Here is what my current approach looks like. The code is just typed in without smashing the compiler on it ;D So it might be broken. A word about utils::enum_map: I wrote that thin wrapper around std::array using some std::numeric_limits-magic in order to be easily able to organize enum-value-keyed stuff without using std::(unordered_)map. In fact, its API is working very similar and the example code should be very clear (at least I think :D )... So, here's my code:

// ----------------------------------------------------------------------------
// common.hpp

enum class Action {
        Idle=0, Use, Attack, Shoot, Cast, Die
};

enum class Layer {
        // Responsible for moving
        BodyLegs=0, ArmorLegs,
        // Responsible for actions
        BodyTorso, ArmorTorso, Helmet, Weapon, Offhand
};

struct Frame {
        sf::IntRect clipping;
        sf::Vector2f origin;
};

// ----------------------------------------------------------------------------
// graphics.hpp

struct RenderComponent {
        utils::enum_map<Layer, sf::Sprite> layers;
};

void apply_position(RenderComponent& data, sf::Vector2f const & pos) {
        // apply position to all layers
        for (auto& pair: data.layers) {
                pair.second.setPosition(pos);
        }
}

void apply_animation(RenderComponent& data, utils::enum_map<Layer, Frame> const & frames) {
        // apply animation to all layers
        for (auto const & pair: frames) {
                auto& sprite = data.layers[pair.first];
                sprite.setTextureRect(pair.second.clipping);
                sprite.setOrigin(pair.second.origin);
        }
}

void draw_sprite(RenderTarget& target, RenderComponent const & data) {
        // draw all layers
        for (auto const & pair: data.layers) {
                target.draw(pair.second);
        }
}

// ----------------------------------------------------------------------------
// animation.hpp

// hold a single frame and a duration for _all_ layers
struct AnimationFrame {
        utils::enum_map<Layer, Frame> frames;
        sf::Time duration;
};

// holds multiple frames
struct EntireAnimation {
        std::vector<AnimationFrame> frames;
};

// holds entire animation configuration: frames per action, frames for movement
struct SpriteAnimation {
        utils::enum_map<Action, EntireAnimation> actions;
        EntireAnimation move;
};

struct AnimationComponent {
        SpriteAnimation const * animation; // non-owning ptr, owned by external system
        bool move;
        Action action;
        std::size_t move_index, action_index; // current frame indices
        sf::Time move_time, action_time; // current frame times
};

void update(std::size_t& index, sf::Time& time, EntireAnimation& animation,
                bool loop, bool& updated, bool& finished) {
        // skip if frame over
        finished = false;
        updated = false;
        while (time >= animation.frames[index].duration) {
                time -= animation.frames[index].duration;
                ++index;
                updated = true;
                if (index >= animation.frames.size() && ) {
                        if (!loop) {
                                // animation finished
                                index = 0u;
                                time = sf::Time::Zero;
                                finished = true;
                                break;
                        } else {
                                // restart animation
                                index = 0u;
                        }
                }
        }
}

void animate(AnimationComponent& AnimationComponent, sf::Time elapsed) {
        if (AnimationComponent.animation == nullptr) {
                return;
        }
        auto const & ani = *(AnimationComponent.animation);
        bool move_updated, action_updated, finished;
        // animate movement if moving
        if (AnimationComponent.move) {
                AnimationComponent.move_time += elapsed;
                update(
                        AnimationComponent.move_index, AnimationComponent.move_time,
                        ani.move, false, move_updated, finished
                );
        }
        // animate any action
        AnimationComponent.action_time += elapsed;
        update(
                AnimationComponent.action_index, AnimationComponent.action_time,
                ani[AnimationComponent.action], true, action_udpated finished
        );
        if (finished) {
                // stop action
                AnimationComponent.action = Action::Idle;
        }
        if (move_updated || action_updated) {
                // apply animation to the corresponding graphics component
        }
}
 

I skipped the "lets-notify-the-graphics-system-about-the-changes"-part because it's out of scope here :) Can anyone recommend this or a different approach? Or does someone has an idea how to solve this with Thor? (I'm not completly sure whether Thor can help here or not).

This solution isn't perfect either: I smashed _all_ layers into one AnimationFrame, so moving is forced to have the same number of frames and duration as e.g. attacking (which is not necessary). But else this example code would be much larger :-\

Greetzs,
Glocke

6
Graphics / Random graphics glitch
« on: April 07, 2015, 12:44:21 pm »
Hi, I'm facing a random graphics glitch. The glitch is shown in the following video:


It occures at some random position... sometimes while drawing render textures to the screen, sometimes without doing so. Toggling between drawing those or not always fixes the glitch (temporarily).
Unfortunately I cannot reproduce this behavior, because the positions seem to be "random". Sometimes the behavior does not occur. Sorry, but I cannot test the entire problem on a different machine. I also cannot reduce the problem to a minimal code example - the problem occures too randomly :(

I'm using SFML 2.2 (Release source + small joystick fix). But I was facing this problem also with a prior version (maybe 2.1) some months ago (within another project using SFML)
The machine is a netbook (running Ubuntu) with an Intel GPU. I know that those GPUs (especially with linux graphics drivers) often cause problems. I also upgraded my graphics card driver to the latest version using a tool by Intel.

I'd like to know whether other people also faced similar behaviors at their projects.

Kind regards

7
SFML website / [SOLVED] [Forum] View message outbox
« on: April 02, 2015, 12:31:14 pm »
Hi, is there any way to get to my message outbox to check a previously sent message? I can only access the inbox at "My Messages" and there's no additional submenu where to select "Outbox" instead "Inbox".

Kind regards

PS: I hope that's the right forum section ;D

8
Hi, I'm using two views: Scene and GUI view. Both are resized if the window gets resized. Additionally, the scene view is moved and zoomed by the players' movement. Now I'd like to draw some "damage labels" (those flying text labels with e.g. damage values). I don't know which view to use:
  • If I use the GUI view, then moving the scene (e.g. by moving the player) would move all damage labels - they would chase the players ... not good! The labels should stay at their initial (map) position but flying upwards (along -y axis)
  • If I use the Scene view, the damage labels are also scaled referring to the zoom that is applied to the view. But zooming the labels isn't what I want: I'd like to keep their size constant in both cases: scene zoomed or not.

Using the scene view's position won't work, because: If the scene is zoomed, the transformation (that is applied to all positions while drawing) will zoom the position and dimension of any drawable. Those damage labels' positions should be scaled but not the labels theirselves.

Any suggestions? Or does anyone have an idea how to solve the entire problem else? Doing the calculations (translation and scaling to the damage labels positions) on my own should work - but I hope there's another solution :)

Kind regards
Glocke

9
Window / [SOLVED] Proper way to handle Resize
« on: March 20, 2015, 09:04:19 am »
Hi, I'm working with window resize events in order to realign the user interface depending on the window's size. Therefore I discovered RenderWindow::mapPixelToCoords() in order to align the position correctly. But unfortunately the dimension of the interface components (e.g. a CircleShape) is stretched.

So I started handling my "own default view" by resizing it, so the shape isn't streched anymore. But I'm not sure whether this is the proper way to handle window resize or not. Any suggestions? Here's a minimal example code:

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

int main() {
        sf::RenderWindow window{{640, 480}, "Resize Test"};
        sf::CircleShape shape{50.f};
        shape.setOrigin({50.f, 50.f});
       
        // create own view
        sf::View view = window.getDefaultView();
       
        while (window.isOpen()) {
                sf::Event event;
                while (window.pollEvent(event)) {
                        if (event.type == sf::Event::Closed) {
                                window.close();
                        } else if (event.type == sf::Event::Resized) {
                                // resize my view
                                view.setSize({
                                        static_cast<float>(event.size.width),
                                        static_cast<float>(event.size.height)
                                });
                                window.setView(view);
                                // and align shape
                                shape.setPosition(window.mapPixelToCoords(sf::Vector2i{window.getSize() / 2u}));
                        }
                }
               
                window.clear();
                window.draw(shape);
                window.display();
        }
}
 

Kind regards
Glocke

10
Window / [SOLVED] Change Window-Style on the Fly
« on: March 17, 2015, 05:43:23 pm »
Hi, I wrote a loading screen which shouldn't allow resizing the window while loading. Is there any possibility to change the window style on the fly? The only approach I found, is closing the window and recreating it with the right style. It is working but I don't like that close-open-close-open, when entering the loading screen and leaving it (so resizing should be reallowed).

The approach works great if you want to have a splash screen before the actual startup, but looks weird if the it appears during a loading in the middle of the application. Additionally, I'd need to track the window title on my own, because there is nothing like getTitle() either. I'm not quite sure how to deal this situation.. :-[

Kind regards
Glocke

11
Audio / [SOLVED] Crossfade between music
« on: March 07, 2015, 04:51:41 pm »
Hi, what would be the best way to implement crossfading between two instances of sf::Music - or is there a library based on SFML which provides such stuff - as Thor does for other purposes?

My basic idea would be: having two instances of sf::Music. One holds the current track, the other the new track. Then fading can be done by changing the music's volume per frame. So the current music fades out by decreasing volume and the new music fades in by increasing music. After fading, the old instance (which played the previous track) will be used as "fade-in"-instance when fading again - and vice versa.

Of course, this change might be linear or not, depending on the desired result. But would this be the most suitable way?

Kind regards
Glocke

12
Window / [Linux with Fluxbox] Weird Focus Gain/Lose on Alt-Tab / Alt-F4
« on: February 24, 2015, 03:25:15 pm »
Hi, I'm using Linux (Ubuntu Trusty) with fluxbox (1.3.5) as window manager. When alt-tab'ing, my program behaves weird referring to GainFocus and LostFocus. Here's the Code:

#include <iostream>
#include <SFML/Graphics.hpp>

int main() {
    sf::RenderWindow window(sf::VideoMode(320, 240), "Test");

        window.clear();
        while (window.isOpen()) {
                sf::Event event;
                while (window.pollEvent(event)) {
                        switch (event.type) {
                                case sf::Event::Closed:
                                        window.close();
                                        break;
                                case sf::Event::LostFocus:
                                        std::cout << "Focus Lost" << std::endl;
                                        break;
                                case sf::Event::GainedFocus:
                                        std::cout << "Focus Gained" << std::endl;
                                        break;
                                default:
                                        break;
                        }
                }
                window.display();
        }
}

  • On startup it gains focus (ok).
  • Alt-Tab'ing to unfocus the window causes "Lost, Gained, Lost, Lost"
  • Alt-Tab'ing to refocus the window causes "Gained, Gained"

I think that's weird! Is the problem fluxbox's fault?
I also attached a very short video showing that the behavior can be reproduced.

Kind regards

/EDIT: Changing focus by clicking behaves as expected. Closing by Alt-F4 causes "Lost, Lost, Gained".

13
Audio / [SOLVED] How to organize my audio system
« on: February 24, 2015, 10:59:41 am »
Hi, I just read the tutorial and api documentation for the audio module: It sounds awesome! ;) I plan to introduce an audio system to my game, which is already using SFML. But I wonder how to organize the system itself. I'm going to build an entity-component-based topdown dungeoncrawler. So my physics system holds physics-related data, such as position, face direction etc. My render system holds the corresponding sprites and lights per object.

I'd design my audio system in order to allow playing two instances of sf::Music: One as music itself and one as ambience track. So holding two instances and calling openFromFile() and play etc. would be the best solution. But I wonder how to organize entity sounds. Of course all sf::SoundBuffer instances should be cached to avoid double loading etc. My caching also guarantees that the buffer will be valid until the game session is closed.

For instance: An entity might cast a fireball, so a fireball-ish sound could be played when the fireball is created and starts flying towards its target. But what's the most suitable way to organize those sounds? After reading about sf::Listener, I'd also like to spatialize entity-related sounds.

Because the number of parallel sounds is limited, storing a sf::Sound per entity wouldn't be that great. So I think of a pool of reusable sounds: When a sound effect is triggered (e.g. with parameters sfx-name, entity position and other spatilization details) it might work that way:
  • Grab the next (yet unused) sf::Sound.
  • Grab the sf::SoundBuffer from the cache and apply it
  • Setup sound position and other spatialization details.
  • Finally play it

Would this be suitable? If yes, here's my next question :D
How to organize that pool? Having a set of (let's say 50) instances of sf::Sound inside a std::vector, beeing preinitialized at the system's startup. Searching for a "free spot" (where the sound is currently not playing) would lead to linear search and O(n). Well, depending on n, it might be fast. But is that a good solution? Previously, I was working with SDL. If I remember correctly there is an opportunity to specify a callback, which is called when the sound stops. I didn't find something similar in the API docs... Is there such a solution?

And yet another question: If no free spot can be found, because there are many sounds currently played... How to handle this? The "intuitive" solution might be to stop the sound which was played first, but that would imply sorting the sounds by the order of playback. Another solution would be to ignore the sound (or even throw an exception). I don't like this solution :-[
Or: Is that situation utopy or even/ bad design?

/EDIT: And the final question: If working with spatialized audio... I'd set the listener position to the player's position. But what if multiple players share one screen (doesn't matter whether splitted or shared)... I could calculate the bary point of those players and set the listener position to that bary point. But this would lead to wrong results if the players are too far away from each other. Can spatialization be applied to such situations?

Kind regards
Glocke

14
Graphics / Blending Mode "Intersection"?
« on: February 21, 2015, 06:47:57 pm »
Hi, I'm not quite sure whether there is already such a blend mode or not. I also don't know how to build my own sf::BlendMode.

Here's what I want to do: I draw shadows using a vertex array of black triangles onto a white rendering buffer. Each vertex array contains all shadow triangles referring to one light source. When drawing the array via default blend mode, both shadows are united. When applying sf::BlendMultiply, they are also united, but the intersection part is made darker by the multiplication.

Because I'm going to build a coop-game, I want the shadows to intersect only. I added two screenshots (default blend, multiplicative blend) and a gimp-made example of what I tried to describe ^^
The example contains black lines, which indicate the lines of sight from each light source / player to each visible edge.

Is there already such an "BlendIntersect" or "BlendAnd" mode? I haven't found it, yet :-[

About the multiplicative one: I know it's not working correctly, because I'm using not only the visible edges (I use all for simplicity). So I'd like to draw the entire array (which triangles might overlap, but those overlaps should be done by default blending) to the buffer using an intersection/and mode.

Kind regards
Glocke

15
Graphics / Slow window.clear() after drawing to RenderTexture [Intel GPU]
« on: February 21, 2015, 11:36:10 am »
Hi, I'm experimenting with my lighting system adding more lights. Unfortunately, having ~25 lights sources is extremly slow on my netbook. So I started cleaning up the code to a minimal example and here it is (see spoiler)
(click to show/hide)
(shader code)
(click to show/hide)

I removed the entire scene-drawing-process and left (A) drawing the lighting texture to a render texture and (B) clearing the scene. So the texture isn't drawn at all - but clearing the window takes a lot of time - but it's empty! Here's the output from on my machine:
146ms to clear scene
0ms to clear scene
144ms to clear scene
0ms to clear scene
145ms to clear scene
1ms to clear scene
70ms to clear scene
0ms to clear scene
147ms to clear scene
0ms to clear scene
147ms to clear scene
0ms to clear scene
145ms to clear scene
0ms to clear scene
144ms to clear scene
0ms to clear scene
145ms to clear scene
0ms to clear scene
71ms to clear scene
1ms to clear scene
94ms to clear scene
59ms to clear scene
68ms to clear scene
71ms to clear scene
55ms to clear scene
72ms to clear scene
146ms to clear scene
0ms to clear scene
70ms to clear scene
 
I'm not sure where those "0ms" come from - but maybe my graphics card is limiting the framerate on its own.
So, those many many ms for only clearing the screen... I experimented a bit:
The more light sources are drawn to the render texture the longer it takes to clear the window.

Somewhere at the forum I read that Render Textures are using FBO if available. But glxinfo says GL_EXT_framebuffer_object is available.

So I don't know what's wrong :S I already have the latest version of my graphics card (which is a no-name intel chip) using the official repository of my ubuntu distribution (which isn't outdated either^^). Going to the journey about "finding a non-official driver which is more up-to-date" is currently too dangerous for me. I'm glad my netbook is working great - so I don't want to touch the running machine :P I the past, I always had problems after trying to update my graphics drivers (doesn't matter which machine :S )...

So maybe you've got an idea except "update your graphics card driver" .. it is up-to-date (from my distributions point of view).

Kind regards

/EDIT: Improved Thread Titel

Pages: [1] 2