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

Pages: [1] 2 3 4
1
General / Re: Failed to load image
« on: March 11, 2024, 07:21:02 am »
Do you run the program directly or through IDE? Usually, IDE has working space and could be different than where you have exe files.

2
System / Vector2 - type safety between Point and Vector (dimension)
« on: March 10, 2024, 09:31:46 am »
I have recently used Vector2 for several functions, in some cases as Point and in some cases as Vector (dimension).
I have found that it is not the best especially if function parameters need both, point/s and vector/s.
I have created class Line which just has two points and an enum for line type (straight, ray, segment).
It was much better and safe however, it needs to create a line and sometimes you have just a point and vector or two points.

So another step is to split general sf::Vector2 into two types:
- Point2
- Vec2
And define operations over them. I found it as really big advantage as it can forbid meaningless operations.
Point2f pointA {1.f,1.f};
Point2f pointB {2.f,2.f};
Vec2f vecA {3.f, 0.f};

auto bLessA = pointB - pointA; // bLessA is Vec2f because operand- for two points are not defined
auto pointC = bLessA + vecA; // Error as there is no overloaded operand+ for two points
auto aAddVecA = pointA + vecA; // type is Point2f

This allows me to define function parameters much more safely (used C++20):

template <typename T>
concept arithmetic = std::integral<T> || std::floating_point<T>; // more strict definition to general definition

template <arithmetic T>
auto linesIntersection (const Point<T>& pointA, const Vec<T>& vecA, const Point<T> pointP, const Vec<T>& vecP)
-> std::optional<Point<T>>;

template <arithmetic T>
auto linesIntersection (const Point<T>& pointA, const Point<T>& pointB, const Point<T>& pointP, const Point<T>& pointQ)
-> std::optional<Point<T>>;
 

Would not be useful that type safety even for SFML?

3
Graphics / Re: setFrameLimit - curious effect
« on: February 20, 2024, 09:18:26 am »


Thanks for confirming, that I am not completely out of mind.
It should be no problem as if the application is more processor demanding, there will be less sleep, so no slow down.

4
Graphics / Re: setFrameLimit - curious effect
« on: February 15, 2024, 07:34:04 pm »
setFramerate() sleeps the thread.
This helps with "over-producing" with no limit and can reduce power used. However, it's not strictly set to that rate.
Once a thread is "slept", it has the possibility of "over-sleeping" as there's no real way of insisting on coming back by a specific time (accurately); this is dependent on operating system's task scheduler.

So, I'd guess that the framerate limit is sleeping during each frame and then the operating system is keeping it a little longer than your hoped-for length of time before returning it.

I would expect it to be faster (shorter frame time) without a framerate limit.

This I would understand but if the measurement of the function is just 2 time points one before that function and after that function which has no call to SFML except sf::Vector2f, that I cannot see how sleep will interfere with it. I do not measure and compare whole loop but only one function inside the loop.

5
Graphics / setFrameLimit - curious effect
« on: February 14, 2024, 05:50:43 pm »
I am just curious as it is nothing really important.

I have just measured in average on function that generate Voronoi diagram which is inside the main sfml event loop.

auto vorStartTime = std::chrono::steady_clock::now();
            voronoi.generate();
auto vorEndTime = std::chrono::steady_clock::now();
 

Then I print each second the average for this function. Each iteration I add vorEndTime - vorStartTime to the overall time and then divide by a number of loops for that time. Than just checking if elapsed at least 1 second from the last loop and if so print the average.

But what is really strange that it gives me 0.3 - 0.6 ms with setFrameLimit to 60.
But if I switch off any FrameLimit, i get 0.14 - 0.16 ms.

The function
voronoi.generate() is using only sf::Vector2f from the whole SFML library for points.
 


I am just curious how it can be possible that setting frame limit has effect on function with has practically nothing to do with SFML. Or it can be possible that setting the frame limit makes the processor more idle so that the max turbo frequency of processor is not used (intel i7-1265u 1.8 MHz)

6
Graphics / Re: sf::Rect
« on: February 10, 2024, 12:16:00 pm »
Good, there is static_cast to show an intention.

However, a much more difficult area is floating point math and comparison of floating points. Mostly, you want the warning as it is unintentional but there are cases in which you want to compare floating points for equality and there is no way to tell the compiler to ignore this case and not issue a warning.

7
Graphics / Re: sf::Rect
« on: February 05, 2024, 05:29:14 pm »
I would guess it's there to make sure the type is T to match the min and max signature.
For integer datatypes, the type of the result of a + is not always the type of the two operands. If you have a Rect<short>, then left and width are shorts, but left+width is an int.
(From cppreference.com: "In particular, arithmetic operators do not accept types smaller than int as arguments")
Thanks, forgot about this specifiation.

8
Graphics / sf::Rect
« on: February 04, 2024, 09:12:06 am »
I have looked at the implementation of the Rectangle class and I was surprised to find static_cast.

Why is static_cast there?

from SFML 3.0 branch
template <typename T>
constexpr bool Rect<T>::contains(const Vector2<T>& point) const
{
    // Not using &#39;std::min&#39; and &#39;std::max&#39; to avoid depending on &#39;<algorithm>&#39;
    const auto min = [](T a, T b) { return (a < b) ? a : b; };
    const auto max = [](T a, T b) { return (a < b) ? b : a; };

    // Rectangles with negative dimensions are allowed, so we must handle them correctly

    // Compute the real min and max of the rectangle on both axes
    const T minX = min(left, static_cast<T>(left + width));
    const T maxX = max(left, static_cast<T>(left + width));
    const T minY = min(top, static_cast<T>(top + height));
    const T maxY = max(top, static_cast<T>(top + height));

    return (point.x >= minX) && (point.x < maxX) && (point.y >= minY) && (point.y < maxY);
}
 

9
Graphics / Re: 2 questions about VertexArray / VertexBuffer
« on: December 21, 2023, 02:34:17 pm »
You can both, look at the documentation.
void    draw (const Vertex *vertices, std::size_t vertexCount, PrimitiveType type, const RenderStates &states=RenderStates::Default)

So you can use any container/build in array of sf::Vertex that uses continuous memory.  Just pass to draw call the pointer to the first Vertex, number of vertices, and primitive type.

But as for each PrimitiveType you need a separate draw call, it does not bring the advantage of limiting draw calls.

10
General discussions / Re: [Rendering] Create sprite each frame?
« on: December 17, 2023, 08:38:52 am »
It is better to store sprites in some container, vector is an obvious option.
Then you can change sprite properties if needed. If you need a link to the exact sprite, you can store ID of sprite as it is not invalidated if the reallocation of the vector occurs.

If your number of sprites is not big, you will not mention the difference.

11
Graphics / Re: Error compiling with gcc++
« on: December 13, 2023, 07:08:43 pm »
Not exactly. I used same setting from beginning finding that it optimalize functions calls between compilation units.
But I got this error with new version of SMFL, which is strange.

I disable it for time being but have not found anything useful on internet, usually some very old reports of gcc bugs, but it was about version gcc 4.

12
Graphics / Re: Error compiling with gcc++
« on: December 11, 2023, 08:28:23 pm »
I get more detailed error but so far do not know what to do with it ....

`_ZThn8_N2sf11CircleShapeD1Ev' referenced in section `.rdata$_ZTVN2sf11CircleShapeE[_ZTVN2sf11CircleShapeE]' of ...\_LIB\SFML-2.6.1\lib\libsfml-graphics-s.a(CircleShape.cpp.obj): defined in discarded section `.gnu.linkonce.t._ZN2sf11CircleShapeD1Ev[_ZThn8_N2sf11CircleShapeD1Ev]' of obj\Release\Test.o (symbol from plugin)

13
Graphics / Re: Error compiling with gcc++
« on: December 09, 2023, 07:35:29 pm »
I find what is doing the issue. But I do not understand why.
If somebody has any clue, it would be helpful.


Simple example code with MinGW 13.1 (version used by SFML) on Codeblocks - Windows 11.
#include <SFML/System/Vector2.hpp>
#include "SFML/Graphics.hpp"

#include <vector>

int main ()
{
    std::vector<sf::Vector2f> inputPoints;
    std::vector<sf::RectangleShape> circles;

    return 0;
}
 

As soon as I add this:
std::vector<sf::RectangleShape> circles;
I get the error:
error: ld returned 1 exit status
without any additional information.

So why just declaring vector of RectangleShape can cause such error.

But if I switch off "-flto" for gcc, it compiles without any issue.

14
System / Re: std::istream& operator >> for sf::String
« on: December 09, 2023, 06:54:28 pm »
Thanks, in this case, where I parse whole string, I can.

15
System / std::istream& operator >> for sf::String
« on: December 02, 2023, 11:52:54 am »
I overloaded operator >> for std::istream and sf::String to handle UTF8 encoding.
However I can see there are a lot of copies there:
- from stream to std::string (UTF8)
- from std::string (UTF8) to std::basic_string<sf::Uint32> using sfml function decode
- from std::basic_string<sf::Uint32> to sf::String

I need to use the middle step through std::basic_string<sf::Uint32> as there is no std::back_inserter for sf::String. Is there possibility to decrease number of steps.
note: SFML 2.6.1

Some ideas I have:
- making std::basic_string<sf::Uint32> static and add clear at the end of overload so there is no need to for memory allocation each time

std::istream& operator>> (std::istream& in, sf::String& string)
{
    std::string u8string;
    in >> u8string;
    auto begin = u8string.begin();
    auto end = u8string. end();
    std::basic_string<sf::Uint32> stringUint32;
    auto output = std::back_inserter(stringUint32);
    while (begin < end)
    {
        sf::Uint32 codepoint;
        begin = sf::Utf<8>::decode(begin, end, codepoint);
        *output++ = codepoint;
    }
    string = stringUint32;
    return in;
}
 

Pages: [1] 2 3 4