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 - Paul

Pages: [1] 2 3 ... 6
SFML development / Re: Introduce chrono to sf::Time
« on: August 21, 2022, 11:53:55 am »
I would say that sf::Time unnecessarily duplicates the code of std::chrono and greatly limits the flexibility of working with time. Using time units, conversions and other operations through std::chrono is much more natural and clear. Why should there be a default unit of something called "Int64 m_microseconds;" or "second = float". The user himself should determine the precision he needs for a given operation or what a given time period represents.

Instead of "time.AsSeconds", sf::Clock can be extended to "clock.getElapsedAsSeconds()", but basically it doesn't have much use. Perhaps make more sf::Clock alternatives like stopwatch, pauseable clock and so on would be better idea how improve work with time.

For the stated drawback (even if it's not important at all):

// Instead of
std::cout << "Time: " << duration<float>(t).count() << " second(s)\n";

// You can write
std::cout << "Time: " << duration<float>(t) << "\n";

// Output: Time: 1.001s

Graphics / Re: 2D animation
« on: July 30, 2022, 10:45:42 am »
That's way advanced, it's possible if you program entire backend including triangulation, IK.. :)

General / Re: Share SFML Project with others
« on: December 19, 2021, 08:05:35 pm »
Everyone has these dll's in SysWOW64 folder, if they have Windows of course. You rather need share dll's from compiler and SFML dll's.

SFML projects / Re: Golden Spike - Public Transport Simulation
« on: October 15, 2021, 08:31:01 pm »
I like the network construction, it's very smooth.

Btw. when you press "M", mouse click on minimap should move view to given point.

General / Re: Jittering in Player Sprite and Camera Movement
« on: October 10, 2021, 11:42:33 pm »
Hi, it's not entirely easy to achieve 100% smooth movement on todays computers, you can check articles like https://gafferongames.com/post/fix_your_timestep/. Each step gives better result. There is also Kairos library which implements it via SFML - https://github.com/Hapaxia/Kairos/.

About your code, I guess it can't work if dt lacks precision and you have locked framerate:

Code: [Select]

It should be constant: dt = 1 / 60.f

Calculation formulas seems overcomplicated. Is hard to say what is going on, whereas it's just player character movement, camera tied somehow to player and camera lag. Same for the rest, forget about rendertexture, keep it simple first. Do not add a camera until the character's movement isn't smooth. It's better to use sf::Vector2f everywhere for coordinates instead of variables like fix_minPosX and fix_minPosY.

If you implement approach mentioned in article + vsync on + clearer and unified code, it will be way better and you can fix minor issues.

Graphics / Re: Drawing Visual Noise Quickly
« on: September 03, 2021, 08:12:19 pm »
You can fake it in some way, for example prerender noise into few textures and during game loop draw them randomly. Or use shaders.

You don't need render whole minimap each frame, especially terrain or another elements which never changes. Render it once to texture.

Ok, thanks.

After update to actual Radeon drivers (21.4.1) I have this message when running any SFML program with console.

It's also described by someone on Reddit https://www.reddit.com/r/sfml/comments/lowcus/error_message_on_window_creation/

General / Re: Entire game in single cpp file?
« on: April 14, 2021, 09:46:56 pm »
Cherno's C++


Graphics / Re: Tilemap cell ID
« on: April 13, 2021, 12:37:00 pm »
Good :) Map and terrain implementation in 2D is interesting topic but it's rather outside of SFML related problems to deal with all issues in code. In addition, specific advice can be misleading because no one knows the project.

It would be more interesting to address various techniques that can be used in general (SFML, graphical API). Like terrain texture blending, another options how deal with height, 2D sprites vs 3D terrain, layer rendering, overlapping (depth), use of shaders..

Graphics / Re: Tilemap cell ID
« on: April 10, 2021, 08:56:14 am »
It's calculation whether point (mouse) is inside polygon (4 verticles of map tile).

Checking all map tiles vs mouse cursor can be slow with such algorithm, you can get approximate region of nearest tiles first (like sf::Vector2i current_tile(sf::Mouse::getPosition(window).x/tile_size.x, sf::Mouse::getPosition(window).y/tile_size.y); for 2x2 tiles etc.) and check those only.

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

int PointInPolygon(const sf::Vector2f& p, const std::vector<sf::Vector2f>& v)
        int i, j, c = 0;
        for (i = 0, j = v.size() - 1; i < v.size(); j = i++)
                if (((v[i].y > p.y) != (v[j].y > p.y)) &&
                        (p.x < (v[j].x - v[i].x) * (p.y - v[i].y) / (v[j].y - v[i].y) + v[i].x))
                        c = !c;
        return c;

int main()
        sf::RenderWindow window(sf::VideoMode(800, 600), "SFML works!");

        std::vector<sf::Vector2f> v{ {25 , 50}, {100 , 50}, {100 , 150}, {45 , 160} };

        sf::ConvexShape polygon;
        polygon.setPoint(0, v[0]);
        polygon.setPoint(1, v[1]);
        polygon.setPoint(2, v[2]);
        polygon.setPoint(3, v[3]);

        while (window.isOpen())
                sf::Event event;
                while (window.pollEvent(event))
                        switch (event.type)
                        case sf::Event::Closed:

                        default: break;

                if (PointInPolygon(static_cast<sf::Vector2f>(sf::Mouse::getPosition(window)), v))

        return 0;

Graphics / Re: Tilemap cell ID
« on: April 09, 2021, 11:57:10 pm »
Use point in polygon calculation in all cases (you can find various implementations). Actually you must have all 4 coordinates already since you are able to draw them. Based on your previous code, you know x, y, tile_width and tile_height of each tile. Let's say tile in base is rectangle with size 64 x 64 pix. Plus you have y offset from m_heightmap.

In the for loop will be:
int current_tile = -1; // Not valid
int id = 0;

top_left.x = tile.x;
top_left.y = tile.y + m_heightmap[some_index];

top_right.x = tile.x + tile_width;
top_right.y = tile.y + m_heightmap[some_index];

bottom_right.x = tile.x + tile_width;
bottom_right.y = tile.y + tile_height + m_heightmap[some_index];

bottom_left.x = tile.x;
bottom_left.y = tile.y + tile_height + m_heightmap[some_index];

if (PointInPolygon(mouse, top_left, top_right, bottom_right, bottom_left)
    current_tile = id;

There are probably two concepts in the basics
1) Calculate tile coordinates in for loop
2) Pre-generate coordinates when creating a map and store it in tile classes or structs

Second approach is less messy (at least from my experience) and you can use data wherever it is needed.

There is no simple way how to get tile id in 3D or pseudo 3D maps, it leads into various problems. Thats why games have often flat maps or height is rather an illusion like in Transport Tycoon :) For example if height offset will be extend to other tile above, point in polygon can be valid in more than 1 case (>1 tile is selected). There is more ways, you can fill tiles with color and check ID based on that, use some raycast etc.

Graphics / Re: 2D or 3D?
« on: March 13, 2021, 07:08:37 pm »
I don't know what the rest of the code looks like, if there is any structure for each tile. Anyway while you are generating x and y positions during for loop, the heights for all tiles must be stored somewhere. For example in std::vector<int> m_heightmap[width * height - 1].

Then just add height to all y axis:
quad[0].position = sf::Vector2f(i * tileSize.x, j * tileSize.y + m_heightmap[this_tile_index]);
quad[1].position = sf::Vector2f((i + 1) * tileSize.x, j * tileSize.y + m_heightmap[this_tile_index + 1]);
quad[2].position = sf::Vector2f((i + 1) * tileSize.x, (j + 1) * tileSize.y + m_heightmap[this_tile_index + 1 + row_bellow]);
quad[3].position = sf::Vector2f(i * tileSize.x, (j + 1) * tileSize.y + m_heightmap[index_of_tile_row_bellow]);

You must be carefull about index, it will be different in each line because quads have separated coordinates and you're counting with neighboring tiles which follow the changed height. It is probably not the best described, but the logic behind is straightforward.

Graphics / Re: 2D or 3D?
« on: March 13, 2021, 12:41:20 pm »
As you can see on picture it can be 2D grid [x;y] with offsets for vertices (height). Use sf::VertexArray, map texture and use black color for shading (texture will have a burnt contrast in the base).

For the visual can be problem to highlight the terrain line, then you probably need to use shaders somehow.

Pages: [1] 2 3 ... 6