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

Pages: [1] 2 3
1
Graphics / RGB Profile of png files
« on: October 26, 2019, 08:10:43 am »
I'm saving my png files with Adobe RGB 1998 Profile in Photoshop, but they are not being displayed with this profile in my SFML application (the saturation difference is very obvious). Other image viewing software such as Windows 10 photos app is displaying them with the correct profile, but not SFML. How can I fix this?

2
General / Vsynch CPU usage is unusual
« on: July 05, 2019, 02:20:01 pm »
When I run my game with

Code: [Select]
Window.setFramerateLimit(60);
... the CPU usage of the program is at about 1% in task manager.

If I increase the frame rate to 120, the CPU usage is at about 2%. At 240 it's about 4% and so on. It's pretty consistent.

HOWEVER, when I enable Vsynch instead of using setFrameLimit(), the CPU usage jumps to around 30 percent.

Isn't this unusual considering my monitor refresh rate is 60hz?

3
Network / Build SFML for Steam on Windows
« on: June 21, 2019, 02:41:17 pm »
The "Build SFML for Steam on Linux" tutorial on the wiki claims that "... the steps for Windows and Mac are well covered in online tutorials".

Which tutorials might that be? My google searches did not come up with such tutorials (I'm looking for a Windows tutorial).

4
SFML website / Tutorial suggestion for VertexBuffer
« on: January 22, 2019, 03:04:31 pm »
Can we have a VertexBuffer tutorial similar to https://www.sfml-dev.org/tutorials/2.5/graphics-vertex-array.php?

5
Feature requests / Multiple Colors in sf::Text
« on: January 06, 2019, 09:26:10 am »
Would it be possible to have sf::Text use multiple colors? As far as implementation goes, it could hold a vector of strings instead of one and you could do something like

txtObject.addString("str", sf::Color::Red)

instead of just setString().

6
Graphics / Quick sf::RenderTexture question
« on: January 04, 2019, 07:58:50 pm »
I'm confused about something: If I'm drawing everything into sf::RenderTexture first, do I still need to batch for performance (like minimizing state changes) or does it not matter? I thought it did, but now some source is telling me that it doesn't matter because it's pre-rendering.

7
Graphics / Glyph space inconsistency is killing me
« on: December 23, 2018, 10:01:25 am »
See attached picture please.

sf::Text::setLetterSpacing isn't helping because the overall space sizes between glyphs is inconsistent.

Is there a way to fix this?

8
Graphics / Smooth sf::View movement from point to point
« on: November 19, 2018, 04:15:17 pm »
Hey folks, first a disclaimer: this is a general "gamedev" question, not an "I need help with SFML" question. I hope it's not irritating to the devs to ask this here but I just trust the regular posters here more than other boards and my code in question does use SFML.

The player controls multiple units in my game and the "camera", aka the game world sf::View, moves over to them when a unit is selected. In order to move long distances faster, I tell the view move a portion of the remaining distance between its current position and the destination.

My problem is with the last few frames of movement. I get a lot of "stuttering" which I know stems from the non-integer position of the view; but, if I ceil or floor the position of the view I get an accuracy problem: The view will be off by a large amount (like 8.f) on the x-axis when it reaches the exact desired point on the y-axis or vice versa. This causes a very unnatural jump at the end of movement.

The smoothest movement that I have been able to get is by not flooring/ceiling the floating values and telling the view to stop if the distance remaining in both the x-axis and the y-axis is less than 1.f. My code is posted below.

My questions would be: Would you consider this the ideal way to move the view from one point to another? Is there a way to get smoother movement?

void Camera::setDestination(sf::Vector2f V}
{
        Difference = V - viewWorld->getCenter();

        State = States::Moving;
}
 

void Camera::update()
{
 // if State == Moving

        viewWorld->move(Difference * Speed);
               
        Difference = Destination - viewWorld->getCenter();
               
        if ((std::abs(Difference.x) < 1.f) && (std::abs(Difference.y) < 1.f))
        {
                State = States::Stop;
                viewWorld->setCenter(Destination);
        }
}
 

9
General / Accommodating different resolutions in 2D games
« on: October 07, 2018, 11:41:01 am »
My current method for giving players more resolution options other than the "native" one - native being the resolution that the art assets were designed for - is to draw everything on a RenderTexture, call setSmooth(true) for it, and give the player various size options for window creation.

My first question is: Is this the only viable option? What other options are there and which do you prefer? Especially considering that the method I use is only good for resolutions of the same ratio.

My next question is regarding a problem that I'm facing with this method. The characters in my game are relatively small (140 pixels in height in native 1080p resolution), and so are their health bars (50 pixels wide, 6 pixels tall, with a 1 pixel thick border around them). In lower resolutions (when the RenderTexture is resized) the health bar bleeds over to the border, and the border becomes inconsistent: Random sides of it disappear (as they bleed/blur into neighbouring pixels) and so the health bar becomes quite ugly. Is there a way to keep 1-pixel thick lines consistent when the rendertexture is resized?

10
Feature requests / Font Smoothing
« on: August 27, 2018, 07:24:08 pm »
Please remember to have font smoothing enabled for 2.5.1! Thank you for all your hard work!

11
General / Tcp socket in sf::Thread CPU usage
« on: August 27, 2018, 02:56:41 pm »
Posting in General since it concerns both Network and System.

I'm running a blocking socket (tcp) in an sf::Thread. The program uses 1 percent CPU when I don't run the thread and 30 percent CPU when I do run it. VS Diagnostics show that the function that runs in the thread uses all that extra CPU (see the code for the function). Is this normal or am I doing this wrong?

        while (1)
        {
                sf::Packet packet;

                sf::Int32 code;

                if (Socket.receive(packet) == sf::Socket::Done)
                {
                        packet >> code;
                        PacketCodes.push_back(code);

                        switch (code)
                        {
                                // handle stuff
                        }
                }
        }
 

12
Network / (Beginner) Client won't receive packet
« on: August 14, 2018, 07:35:30 pm »
Hey people. I just started learning networking today and I've been reading all day so my brain is a bit fried at the moment. I made a server and client with SFML. I can successfully connect to the server and send packets to the server, but when I put a receive function inside the client it crashes the client. What am I doing wrong here?

SERVER

#include <SFML/Network.hpp>
#include <iostream>
#include <string>
#include <list>

int main()
{
        sf::TcpListener Listener;
        Listener.listen(55001);

        std::list<sf::TcpSocket*> Clients;

        sf::SocketSelector Selector;
        Selector.add(Listener);

        while (1)
        {
                if (Selector.wait())
                {
                        if (Selector.isReady(Listener))
                        {
                                sf::TcpSocket* ptrClient = new sf::TcpSocket;
                                if (Listener.accept(*ptrClient) == sf::Socket::Done)
                                {
                                        Clients.push_back(ptrClient);
                                        Selector.add(*ptrClient);
                                       
                                        std::cout << "New client connected: " << ptrClient->getRemoteAddress() << std::endl;

                                        // Receive a message from the client
                                        char buffer[1024];
                                        std::size_t received = 0;
                                        ptrClient->receive(buffer, sizeof(buffer), received);
                                        std::cout << "The client said: " << buffer << std::endl;

                                        // Send an answer
                                        std::string message = "Welcome, client";
                                        ptrClient->send(message.c_str(), message.size() + 1);

                                }
                                else
                                {
                                        // Error, we won't get a new connection, delete the socket
                                        delete ptrClient;
                                }
                        }
                        else
                        {
                                // The listener socket is not ready, test all other sockets (the clients)
                                for (std::list<sf::TcpSocket*>::iterator it = Clients.begin(); it != Clients.end(); ++it)
                                {
                                        sf::TcpSocket& client = **it;
                                        if (Selector.isReady(client))
                                        {
                                                sf::Packet packetReceived;

                                                if (client.receive(packetReceived) == sf::Socket::Done)
                                                {
                                                        // Receive

                                                        std::string strReceived;

                                                        if (packetReceived >> strReceived) { std::cout << strReceived << std::endl; }

                                                        // Send

                                                        std::string strSent = "I heard you.";

                                                        sf::Packet packetSent;
                                                        packetSent << strSent;

                                                        client.send(packetSent);
                                                }
                                        }
                                }
                        }
                }
        }

        return 0;
}
 

CLIENT

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

int main()
{
        sf::RenderWindow WINDOW(sf::VideoMode(800, 450), "SFML works!");
        WINDOW.setFramerateLimit(20);

        sf::TcpSocket Socket;
        Socket.connect("localhost", 55001);

        // Send a message to the connected host
        std::string message = "Hi, I am a client";
        Socket.send(message.c_str(), message.size() + 1);

        // Receive an answer from the server
        char buffer[1024];
        std::size_t received = 0;
        Socket.receive(buffer, sizeof(buffer), received);
        std::cout << "The server said: " << buffer << std::endl;

        while (WINDOW.isOpen())
        {
                sf::Event EVENT;

                while (WINDOW.pollEvent(EVENT))
                {
                        switch (EVENT.type)
                        {
                        case sf::Event::Closed: WINDOW.close(); break;

                        case sf::Event::KeyPressed:

                                if (EVENT.key.code == sf::Keyboard::Space)
                                {
                                        std::string strSent = "I pressed Space.";

                                        sf::Packet packetSent;
                                        packetSent << strSent;

                                        Socket.send(packetSent);
                                }

                                break;
                        }
                }


                sf::Packet packetReceived;

// This part crashes the program:

                if (Socket.receive(packetReceived) == sf::Socket::Done)
                {
                        std::string strReceived;
                        if (packetReceived >> strReceived) { std::cout << strReceived << std::endl; }
                }
               

                WINDOW.clear();        
                WINDOW.display();
        }

        return 0;
}
 

13
I was just about to put this into the wiki but my account was flagged for some reason. I'll just put it here for now and edit this to just include link when GitHub support fixes the issue.

This is my first contribution so all feedback is appreciated.

Title: How to use sf::Vector2f as a key-type in unordered associative containers

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

struct Key
{
        sf::Vector2f key;

        bool operator==(const Key &other) const
        {
                return (key.x == other.key.x && key.y == other.key.y);
        }
};

struct KeyHasher
{
        std::size_t operator()(const Key& k) const
        {
                return ((std::hash<float>()(k.key.x) ^ (std::hash<float>()(k.key.y) << 1)) >> 1);
        }
};

int main()
{
        std::unordered_map<Key, std::string, KeyHasher> Map =
        {
                { { sf::Vector2f(1, 1) }, "one" } ,
                { { sf::Vector2f(2, 2) }, "two" }
        };

        // Individual Call
        std::cout << Map[{ sf::Vector2f(2, 2) }];

        // Loop
        for (auto& k : Map)
        {
                std::cout << k.second << std::endl;
        }

        return 0;
}
 

14
Graphics / float / int difference in texture coordinates
« on: July 14, 2018, 07:07:43 pm »
This is something I wonder when I use both sf::VertexArray and sf::Sprite in a project. Why is it that sprites take integers to set their texture rect but vertex texcoords are in floats?

15
Graphics / RenderTarget* to RenderTexture, can't display()
« on: June 16, 2018, 05:03:17 pm »
My art assets are "native" to 1080p resolution which means if I'm going to offer other popular resolutions such as 900p or 768p, I have to adjust the view and use the setsmooth function on textures; otherwise everything looks like jagged crap.

I did that, then I noticed that sf::Text can't be smoothed the same way textures are. Instead I decided to draw everything on a RenderTexture and smooth that instead. Works perfectly.

Then it dawned on me that if the game will be run in 1080p, there's no need to do any of this. So, in order to save a draw call and the creation of a large texture, I tried this:
sf::RenderWindow Window;
sf::RenderTarget* ptrRenderTarget;
sf::RenderTexture RT;

if (Resolution == 1080p) { ptrRenderTarget = &Window; }

else { ptrRenderTarget = &RT; }
 
When I do this, I can clear and draw to the RenderTexture via RenderTarget pointer BUT I can't call display().

Is this whole idea redundant? Should I just always use the RenderTexture?

If this is actually a good idea, then how do I call display? What if I don't call it?

Pages: [1] 2 3