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

Pages: [1]
1
Feature requests / Re: Axis 9 and 10 for proper Xbox trigger support
« on: January 29, 2021, 05:13:00 pm »
May I dig up this topic to ask if anyone knows how to fix it without recompiling ?
As sf::Joystick::Axis is public, would it be possible to directly change the values or overwrite it ?
Thanks for your help

2
Graphics / Re: creating a texture through code
« on: January 14, 2021, 02:31:52 pm »
Indeed...

Thanks for your help jacmoe !

3
Graphics / Re: creating a texture through code
« on: January 14, 2021, 12:18:22 pm »
Thanks for your reply, Laurent.

I'm trying yo optimize fps in my game and realized my entire minimap took more than 16300 microseconds to draw with this code :
void Application::DrawMiniMap(){
    sf::RectangleShape rs;
    for(int i = 0; i < 100; i++) {
        for(int j = 0; j < 100; j++) {
                    rs.setPosition(2 * i, 2 * j);
                    rs.setSize(sf::Vector2f(2,2));
                    rs.setFillColor(img.tuile[game.carte.terrainType[i][j]].GetColor());
                    window.draw(rs);
        }
    }
}

I tried this code and it only takes about 300 microseconds now, but.. it doesn't work  ;D
void Application::DrawMiniMap(){

    sf::Texture tx;
    tx.create(100,100);
    std::vector<sf::Uint8> image(100 * 100 * 4);

    for(int x = 0; x < 100; x++) {
        for(int y = 0; y < 100; y++) {
            image[(x + y * 100) * 4 + 0] = img.tuile[game.carte.terrainType[x][y]].GetColor().r;
            image[(x + y * 100) * 4 + 1] = img.tuile[game.carte.terrainType[x][y]].GetColor().g;
            image[(x + y * 100) * 4 + 2] = img.tuile[game.carte.terrainType[x][y]].GetColor().b;
            image[(x + y * 100) * 4 + 3] = img.tuile[game.carte.terrainType[x][y]].GetColor().a;
        }
    }

    // update texture:
    tx.update(image.data());
    sf::Sprite spt;
    spt.setPosition(576,24);
    spt.setTexture(tx);
    window.draw(spt);
}

EDIT : I forgot to texture.create() and now it perfectly works with only ~350 microseconds, thanks a lot Laurent :)

EDIT 2: As my minimap is 200x200 and not 100, it actually takes 1250 microseconds to draw the minimap this way. Do you know a way to optimize even more ?

4
Network / Re: Packets : Vector Transfers and sf::objects
« on: April 30, 2020, 11:53:03 am »
It seems std::map doesn't want me to send datas. This code compiles but the app shuts down at "packet << s1" :
inline sf::Packet& operator <<(sf::Packet& packet, const std::map<std::string,sf::Int16>& a)
{
    std::string s1;
    for(auto& x : a) {
        std::cout << x.first << std::endl ; // Works, displays the right string
        s1 = (std::string) x.first;  // I tried everything but
        packet << s1 ; // My app shuts down, packet << x.first doesn't work either
    }
    return packet;
}

Thank you again for your help :)

5
Network / Re: Packets : Vector Transfers and sf::objects
« on: April 29, 2020, 07:35:30 pm »
Hello, thank you for your answer.

I didn't try for vectors actually, only for maps.

My overload operator for vectors seems to work (I don't know how to use templates, I'll try someday) :
inline sf::Packet& operator <<(sf::Packet& packet, const std::vector<Plateforme>& p)
{
    packet << p.size();
    for(int i = 0; i < p.size();  i++) packet << p.at(i) ;
    return packet;
}
inline sf::Packet& operator >>(sf::Packet& packet, std::vector<Plateforme>& p)
{
    int n;
    Plateforme x;
    packet >> n;
    p.clear();
    for(int i =0; i < n ;i++) { packet >> x; p.push_back(x);}
    return packet;
}

But for maps, I get an error whenever I try to use an iterator in the function :
inline sf::Packet& operator <<(sf::Packet& packet, const std::map<std::string,int[20][2]>& a)
{
    std::map<std::string,int[20][2]>::iterator it = a.end(); // Get length of the map : ERROR
    // Rest of the code
}

Error : conversion from 'std::map<std::__cxx11::basic_string<char>, int [20][2]>::const_iterator {aka std::_Rb_tree_const_iterator<std::pair<const std::__cxx11::basic_string<char>, int [20][2]> >}' to non-scalar type 'std::map<std::__cxx11::basic_string<char>, int [20][2]>::iterator {aka std::_Rb_tree_iterator<std::pair<const std::__cxx11::basic_string<char>, int [20][2]> >}' requested|

Anyway I'm not sure this is related to SFML. But this works normally outside the overload operator.

Anyway, thanks for your help !

6
Network / Packets : Vector Transfers and sf::objects
« on: April 29, 2020, 03:54:26 pm »
Hello,

I feel like I'm  kind alone on this forum but I still try :)

I have two question :

1- Is it possible to send a structure (or whatever) with vectors in it by packet >> ?
Like this :
typedef struct BMMaps BMMap;
        struct BMMaps
        {
            std::string nom = "Map par défaut" ;
            int background = 0;
            std::vector<Plateforme> plateformes;

        };
inline sf::Packet& operator <<(sf::Packet& packet, const BMMap& m)
{
    return packet << m.nom << m.background << m.plateformes ;
}
inline sf::Packet& operator >>(sf::Packet& packet, BMMap& m)
{
    return packet >> m.nom >> m.background >> m.plateformes ;
}
 

This doesn't work of course, and when I try to send the size of the vector then every element in it with a for(i=0; i < myVector.size() ; i++) , it gives me an error as well .

2- Is it possible to send sf::objects in packet ?
I'd like to send a lot of sf::RectangleShape , or CircleShape, but this :
sf::RectangleShape r;
sf::Packet p << r;
 
doesn't work. I mean, I guess sfml made its own packet object compatible with its own others objetcs ?


Thanks for your help,

Cya

7
Network / Non-blocking UDP socket doesn't receive any data
« on: April 20, 2020, 09:33:27 am »
Hi, I'm wondering why when I put my socket in non-blocking I don't receive anything ?

When I send data to this socket, the following code works :
broadcastSocket.setBlocking(true);
            broadcastSocket.bind(52001);
            if(broadcastSocket.receive(udpp,ip,port) == sf::Socket::Done)
            cout << "Data received" << endl;

but this one doesn't :
broadcastSocket.setBlocking(false);
            broadcastSocket.bind(52001);
while(1)
{
            if(broadcastSocket.receive(udpp,ip,port) == sf::Socket::Done)
            cout << "Data received" << endl;
}

Thanks for your help !

Pages: [1]