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

Pages: [1]
1
Network / Broadcast Linux-Window
« on: August 18, 2023, 05:38:11 pm »
I have a small network code (receiving data to linux, sending data to windows) that sends some information either to a specific local IP or to a broadcastcast. And if the first method works, then the second one only works if Windows receiving data and Linux sending data(linux receives absolutely nothing).

Some information:
SFML 2.6.0
Communication works in both side via tcp

Client(on Windows)
#include <SFML/Network.hpp>
#include <iostream>
#include <string>

int main() {
    sf::UdpSocket socket;
    socket.bind(sf::Socket::AnyPort);
    unsigned short port = 6885;

    std::string data = "Hello, Server";
    //socket.send(data.c_str(), data.size() + 1, sf::IpAddress::IpAddress("192.168.100.148"), port); //It work
    socket.send(data.c_str(), data.size() + 1, sf::IpAddress::Broadcast, port); //It not work, sf::IpAddress::Broadcast is a 255.255.255.255 on both PC


    return 0;
}



Server(on Linux)
#include <SFML/Network.hpp>
#include <iostream>
#include <string>

int main() {
    sf::UdpSocket socket;
    socket.bind(6885);
    std::cout << sf::IpAddress::getLocalAddress() << std::endl;

    char data[128];
    std::size_t received;
    sf::IpAddress remote;
    unsigned short port;
    socket.receive(data, 128, received, remote, port); //Work only if sent to a this IP
    std::cout << data[0];
   

    return 0;
}

2
Graphics / A 3d(2d?) array of textures
« on: May 21, 2023, 03:50:38 pm »
I want to make an efficient rendering of the tile map. However, I have a problem with the lines between the tiles (as I understand it, it is a problem in the inaccuracy of the UV). I found such a thing as 3d texture array(rather 2d?), but I didn't find any explicit mention of it in the SFML.

Which way should I look for information about it? Or is it better to use other ways?

3
General / CodeLite. Problem with SMFL + Imgui + ImguiSMFL
« on: December 03, 2022, 06:54:26 pm »
Hi all. There was such a problem: when trying to create and draw completely imgui-details, the application crashes (without any error. Just a standard random set of a number as an exit code). The .dll libraries are added and the SFML window appears for a split second without imgui(without imgui everything works fine). The imgui and imguiSFML code has not changed, except for adding the Glad header to imgui-SFML.h. I hope someone can help me with this problem

The code:
#include "imgui.h"
#include "imgui-SFML.h"


#include <SFML/Graphics/CircleShape.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/System/Clock.hpp>
#include <SFML/Window/Event.hpp>

int main() {
    sf::RenderWindow window(sf::VideoMode(640, 480), "ImGui + SFML = <3");
    window.setFramerateLimit(60);
    ImGui::SFML::Init(window);

    sf::Clock deltaClock;

    while (window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {
            ImGui::SFML::ProcessEvent(window, event);

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

        ImGui::SFML::Update(window, deltaClock.restart());

        ImGui::Begin("Hello, world!");
        ImGui::Button("Look at this pretty button");
        ImGui::End();

        window.clear();
        ImGui::SFML::Render(window);
        window.display();
    }

    ImGui::SFML::Shutdown();
}
 

Screenshots:

4
General / The problem with the collision of a circle and squares
« on: September 04, 2022, 02:58:22 pm »
The problem is in the intersects method. Everything works fine exactly until the circle starts to go into the wall and to the left / up. The circle stops sliding along the wall on the verge of the square and the next square, as if resting on an invisible wall. I tried to change the pass through the objects (if before it started from the first object, now from the last one) and the blocking directions were inverted, that is, the problem is at least partially in this. How can the circle be allowed to slide along the walls regardless of direction?

Code:
#include "math.h"
#include "SFML/Graphics.hpp"

sf::RenderWindow window;
sf::Event event;
sf::View camera;

const int amountOfTile = 32;
sf::RectangleShape tiles[amountOfTile][amountOfTile];
sf::CircleShape player;

void intersects(sf::CircleShape &player, sf::RectangleShape &rect) {
    bool leftIsBlocked = 0;
    bool rightIsBlocked = 0;
    bool topIsBlocked = 0;
    bool bottomIsBlocked = 0;

    float testX = player.getPosition().x;
    float testY = player.getPosition().y;

    //checking which faces the circle intersects
    //originally there were positions of the points of the square, and not a distance from the center. However, the situation is the same in both cases!
    if (player.getPosition().x < rect.getPosition().x - 16) { testX = rect.getPosition().x - 16; leftIsBlocked = 1; } //left
    else if (player.getPosition().x > rect.getPosition().x + 16) { testX = rect.getPosition().x + 16; rightIsBlocked = 1; } //right
    if (player.getPosition().y < rect.getPosition().y - 16) { testY = rect.getPosition().y - 16; topIsBlocked = 1; }  //top
    else if (player.getPosition().y > rect.getPosition().y + 16) { testY = rect.getPosition().y + 16; bottomIsBlocked = 1; } //bottom

    float distX = abs(player.getPosition().x - testX);
    float distY = abs(player.getPosition().y - testY);
    float distance = sqrt((distX * distX) + (distY * distY));

    //if the distance is less than the radius of the circle, then it's time for a collision
    if (distance <= 16) {
        //if any boolean value is active, the distance to the point on the edge of the square is calculated and already it is subtracted / added to the player's position
        //I assume that the error is somewhere here, however, no matter what I change here, it did not help
        if (leftIsBlocked) player.setPosition(player.getPosition().x - abs(16 - distance), player.getPosition().y);
        else if (rightIsBlocked) player.setPosition(player.getPosition().x + abs(16 - distance), player.getPosition().y);
        if (topIsBlocked) player.setPosition(player.getPosition().x, player.getPosition().y - abs(16 - distance));
        else if (bottomIsBlocked) player.setPosition(player.getPosition().x, player.getPosition().y + abs(16 - distance));
    }
}

int main() {
    srand(time(0));
    window.create(sf::VideoMode(1000, 1000), "sfml");
    window.setFramerateLimit(60);

    for (int i = 0; i < amountOfTile; ++i) {
        for (int j = 0; j < amountOfTile; ++j) {
            tiles[i][j].setSize(sf::Vector2f(32, 32));
            tiles[i][j].setOrigin(sf::Vector2f(16, 16));
            tiles[i][j].setFillColor(sf::Color::Red);
            tiles[i][j].setPosition(sf::Vector2f((i + 0) * 32, (j + 0) * 32));
            tiles[i][j].setOutlineThickness(1);
            tiles[i][j].setOutlineColor(sf::Color::Blue);
        }
    }

    for (int i = 0; i < amountOfTile; ++i) {
        for (int j = 0; j < amountOfTile; ++j) {
            if (rand() % 100 > 90) {
                tiles[i][j].setFillColor(sf::Color::Green);
            }
        }
    }

    player.setRadius(16);
    player.setOrigin(sf::Vector2f(16, 16));
    player.setFillColor(sf::Color::White);
    player.setPosition(sf::Vector2f(256, 128));

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

            //resize window
            if (event.type == sf::Event::Resized) {
                sf::Vector2f cameraCenter = camera.getCenter();
                camera.setSize(event.size.width, event.size.height);
                camera.setCenter(cameraCenter);
            }
        }

        if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)) player.move(0, -2.0f);
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) player.move(0, 2.0f);
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) player.move(-2.0f, 0);
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) player.move(2.0f, 0);

        //checking all possible collisions (in the future, the nearest ones will be checked)
        for (int i = 0; i < amountOfTile; ++i) {
            for (int j = 0; j < amountOfTile; ++j) {
                if (tiles[i][j].getFillColor() == sf::Color::Green) {
                    intersects(player, tiles[i][j]);
                }
            }
        }
       
        camera.setCenter(player.getPosition());
        window.setView(camera);
        window.clear();

        //in the future I will put tiles in vertex arrays
        for (int i = 0; i < amountOfTile; ++i) {
            for (int j = 0; j < amountOfTile; ++j) {
                window.draw(tiles[i][j]);
            }
        }
        window.draw(player);
        window.display();
    }
    return 0;
}
 

5
Graphics / Re: Optimizing variable tile map rendering
« on: July 20, 2022, 05:54:55 pm »
Yes. Thank you. I recently learned about vertex array and this is what I need

6
Graphics / Optimizing variable tile map rendering
« on: July 20, 2022, 02:22:36 pm »
Hi everyone who stopped by here. My problem is that I want to draw a tile map of about 512x512 tiles. This loads the CPU by half and the FPS is about 5-10. If I draw every other tile, the FPS increases several times. Because each tile can be changed, I can't merge all the sprites into one, or merge everything into one sprite every time. I had the idea of merging sprites into chunks(i.e. the same thing as before, but only a small part of the sprite would be recreated into one), but I don't know if that would work correctly. How good is this idea and are there any better ideas?

Pages: [1]