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 - Elias Daler

Pages: 1 [2]
16
My game has in-game level editor and I've been noticing that sometimes it hurts code readability.
Here's an example: in the level editor class I have bool drawObjects which indicates whether objects are drawn or not. If it's changed I call code like this:
renderingSystem->setDrawObjects(drawObjects)
and in rendering system I have a code like this:
void RenderingSystem::render() {
    ...
    if(drawObjects) {
        ... // draw objects
    }
}
Or suppose that I don't want to draw effects and shadows while in Level editor, I'll have to do this:
void RenderingSystem::render() {
    ...
    if(!isEditingLevel) {
        ... // draw effects
    }

    ...

    if(!isEditingLevel) {
         ... // draw fog
    }
}
As you can see, there's some coupling going on between LevelEditor and RenderingSystem which doesn't feel right. It also hurts readability because rendering code is now polluted with level editor stuff.
The only solution I have in mind is to have two functions: render and renderInLevelEditor but this may produce a lot of code duplication which is even worse.

So, what are some common ways to keep level editor code separate from main game/engine code? (Not only in rendering but everywhere else too). Maybe there are some patterns/cool articles about level editors which I need to read?

17
SFML projects / [Release][GUI] ImGui-SFML
« on: April 12, 2016, 11:49:01 am »
Github

ImGui is a wonderful library which lets you easily add debug / tools GUI for your game.
A while ago this back-end was released and my repository is based on it while improving(?) / changing some stuff.

Here's how I use ImGui in level editor of Re:creation:

I also use it for my in-game console.


You can find an example code inside of README for repository.
I'm not sure it's 100% complete, so let's discuss it! :)

18
General / How can I do culling in top-down (Zelda like) tile map?
« on: March 14, 2016, 08:06:15 am »
Here are some pictures for better understanding of culling problem

There are two ways of storing tiles in top-down games. One ("Flat") is to store it as it is seen, manually putting all the tiles to create illustion of height.
Another one ("3d") is what I'm doing right now. It's greatly simplified for brevity, so in this example I just specify the height of cells on the map. So the "1" in array tells us that the block is one tile high. Drawing is a bit trickier, because I have to draw "top" of the tile automatically, but it's pretty easy: I just draw it if it's the last one in the column.

And here are where culling problem starts...
Suppose that the player can only see what's inside the red rectangle:

Culling with "flat" way of storing map is easy, you just draw all tiles which intersect the viewport.
But it's not so easy with "3d" way, because you have to manually check if there are some high tiles below the viewport some part of which can be seen.
One obvious solution would be to find the biggest height on the map (let's call it Z_max) and then check Z_max tile rows below the lowest visible tile row to see if there are some visible tile columns.
But this seems like a waste of time, because there might be just several really high columns while the level will be mostly flat, so it won't be very efficient to look Z_max rows down every time.
So, what's the easier way to do culling in this scenario?

19
Graphics / [Solved] Creating sf::RenderTexture in a separate thread
« on: July 28, 2015, 10:51:13 am »
When my game loads its resources, it also creates some sf::RenderTexture's. While this happens, I draw loading animation on the screen. Strangely enough, sf::RenderTexture's are not created and don't display anything drawn on them. Here's a minimal example:

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

bool created;

void createTexture(sf::RenderTexture& rt, sf::Sprite& sprite) {
    rt.create(512, 480);
    sprite.setTexture(rt.getTexture(), true);
    created = true;
}

int main()
{
    sf::RenderWindow window(sf::VideoMode(512, 480), "Test");
    window.setFramerateLimit(60);

    sf::RenderTexture rt;
    sf::Sprite sprite;

    created = false;

    // just a triangle to draw for tests
    sf::VertexArray triangle(sf::Triangles, 3);
    triangle[0].position = sf::Vector2f(10, 10);
    triangle[1].position = sf::Vector2f(100, 10);
    triangle[2].position = sf::Vector2f(100, 100);
    triangle[0].color = sf::Color::Red;
    triangle[1].color = sf::Color::Blue;
    triangle[2].color = sf::Color::Green;

    std::thread loadingThread(&createTexture, std::ref(rt), std::ref(sprite));
    loadingThread.detach();

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();

        if (created) {
            // the createTexture function is finished by this point
            rt.clear();      
            rt.draw(triangle);
            rt.display();

            window.draw(sprite);
        }
       
        window.display();
    }
}

Note that a global "created" bool variable is used. This makes sure that sf::RenderTexture is not used when it's created.

If I don't use a thread there and just call createTexture directly, then the code works as expected: the triangle is displayed. But if the thread is used, the triangle is not displayed.

Maybe I'm doing something wrong and I need to suspend the main thread when I create a sf::RenderTexture? Or is this a bug in SFML?

20

Site: https://eliasdaler.github.io/re-creation
Developers: Elias Daler (programming, art, game and level design, story, etc.), Torchkas (music and sound effects)
Dev logs (old): https://eliasdaler.wordpress.com/tag/devlog/
Dev logs (new): https://eliasdaler.github.io/tags/#Dev+log
Progress screenshot album: http://imgur.com/a/luoFe
Twitter: @eliasdaler
Platforms: PC, Mac, Linux
Release date: When it's done



The coolest screenshot yet (January 2016):


Hello, my name is Elias Daler and this will be a dev log of my game!
I'm a solo hobby developer and work on the game in my free time so the progress won't be very fast I hope I'll post some interesting stuff from time to time! You can read previous dev logs here.

The development of this game started in October 2013.
I'm writing the game in C++ and use SFML. I also use Lua for scripting. I'll try to explain how my game works in next posts. I'll write about how I use scripting, how my entity/component/system works and lots of more programming stuff!

Story
The main hero is an undead knight who was betrayed by his partner, Necromancer, during a fight with a giant demon. When the hero raises from the dead, he realizes that lots of time has passed since his death. The Great War between humans and undeads is being fought for several centuries. Necromancer is still alive. He actually became a Lich. He has lots of power and uses undeads as a cheap working force. The hero explores society of undeads and finds out that they don’t actually want to kill humans. They just don’t want people to use them for training and steal their treasure! The hero decides to stop the war and prove that undeads are not that evil as it seems.


Undead City becomes hero's new home.

Gameplay
The gameplay is very similar to top-down 2D Zelda games with the exception of the main mechanic of the game, called recreation.
At any point of the game, you can become a ghost and travel through objects easily.
You can also control enemies you killed with it to get their abilities and solve various puzzles. Here's how it works:



You can't carry any weapons other than a hammer in the game, so you need to control enemies with bows to be able to use arrows, enemies with shields, to be able to block attacks etc. If you're killed when you're controlling someone else, your ghost will automatically return to your body and the person which you were in will respawn shortly after (because you can't solve some puzzles without other bodies).

Here's are some puzzles which you can solve with recreation mechanic:





Other gifs / screenshots:


NPC's are interesting...


Hero reacting to items he gets from chests


Boss fight

As this is the first post, I'll edit it from time to time to add the latest and coolest screenshots and gifs.

21
My original screen size is 256x240 and it scales nicely when the window has the same aspect ratio(512x480, for example)

But when I change window size to 640x480, it scales pretty badly(notice that text doesn't scale at all, which is another problem connected to this because it scales when window is resized during runtime)

What I want to have is this:


How can I achieve this? I realize that this has something to do with sf::View's setViewport() function, but I can't figure out how to use it.

22
Graphics / [SOLVED]How can I do this screen transition effect?
« on: July 31, 2014, 05:11:30 pm »
When you select a level in Super Mario World the screen fades to black and image becomes more and more pixelated over a short period of time. When the level is loaded the same transition happens in reverse.
How can I do something similar in SFML?

23
Graphics / How do I implement smooth scrolling? (example inside)
« on: February 28, 2013, 08:27:52 pm »
I've seen those threads here before but none of them really helped me
Here's a code


#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
int main()
{
        sf::RenderWindow window(sf::VideoMode(256 * 3, 240 * 3), "My window");
        window.setVerticalSyncEnabled(true);

        sf::Texture backgroundTexture;
        backgroundTexture.loadFromFile("background.png");
        sf::Clock mainClock;
        sf::View view(sf::FloatRect(0, 0, 256, 240));
        sf::Sprite backgroundSprite;
        backgroundSprite.setTexture(backgroundTexture);
        sf::Vector2f cameraPos(0.0f, 0.0f);

        float backWidth = backgroundTexture.getSize().x;
        float backHeight = backgroundTexture.getSize().y;
       

    // run the program as long as the window is open
    while (window.isOpen())
    {
                int dt = mainClock.restart().asMilliseconds();      
                sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();

                       
                }

                float dx = 0.075f * dt;
                cameraPos.x += dx;
                view.move(dx, 0);
                window.setView(view);

                // I just render two sprites side by side
                int k = cameraPos.x / backWidth;
                backgroundSprite.setPosition(backWidth * k, 0);
                window.draw(backgroundSprite);
                backgroundSprite.setPosition(backWidth * (k + 1), 0);
                window.draw(backgroundSprite);

                window.display();
    }

    return 0;
}
 
Here's the image I'm using: http://i.imgur.com/u0wzBX2.png

What's strange is that my laptop monitor shows very bad results. Scrolling is not smooth at all. My second monitor is showing much better results, but sometimes they're bad too, which is odd. What am I doing wrong?  >:(

Pages: 1 [2]