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

Pages: [1]
1
Network / Re: UdpSocket question
« on: May 05, 2017, 05:13:45 pm »
Thank you for a clear answer. I get it know.

2
Network / UdpSocket question
« on: May 05, 2017, 03:05:57 pm »
Hi. I have a question more related to network functionality rather than to programming.

Code below is responsible for sending packet:

std::string ipString;
sf::UdpSocket socket;
sf::Packet packet;
unsigned short port;

std::cout << "Set recipient IP: ";
std::cin >> ipString;
std::cout << "Set recipient port: ";
std::cin >> port;
sf::IpAddress ipAddress(ipString);

socket.send(packet, ipAddress, port);
 

As a sender I have to set IP address of recipient and recipient's port.

And this code is responsible for receiving packet:

unsigned short port;
sf::UdpSocket socket;
sf::IpAddress ipAddress;
sf::Packet packet;

std::cout << "Set server port: ";
std::cin >> port;
socket.setBlocking(false);
socket.bind(port);
while(true)
{
     if(socket.receive(packet, ipAddress, port) == sf::Socket::Done)
     {
           std::cout << "IP Address: " << ipAddress << " port: " << port << std::endl;
     }
}
 

After receiving a packet, variables ipAddress and port are filled with sender's IP and port number.

So let's say, I want to set server at port 4096 and try to send packet from client. So as a client I set server's IP and port number. Everything is ok, my packet went to server. But here is my question. Server's output is good as far as IP address is concerned, but port number is different than 4096. I presume that it should be like that and everything is good, but I don't understand why client's port is different than 4096. I'm looking forward your answer.

3
Graphics / Double inheritance
« on: October 25, 2016, 08:26:04 pm »
Hi, I have a short question. Is it possible to do something like this:
class A : public sf::Drawable;
class B : public A;
B object;
window.draw(object);
 
Thank you in advance.


4
General / Re: Problem with fixed time step
« on: September 29, 2016, 10:01:38 pm »
Thank you for the explanation.  :D I added link to video in my previous post. Check it out, because it shows what is my problem while using v-sync. FPS is set 60 and no, my computer is not that slow.  :D

5
General / Re: Problem with fixed time step
« on: September 29, 2016, 09:38:09 pm »
In my case, if I'm trying to use both at the same time - application is lagging. Anyway, this is a quote from sfml tutorial page:

Quote
Never use both setVerticalSyncEnabled and setFramerateLimit at the same time! They would badly mix and make things worse.

And this is a code of setFrameLimit function:

void Window::setFramerateLimit(unsigned int limit)
{
    if (limit > 0)
        m_frameTimeLimit = seconds(1.f / limit);
    else
        m_frameTimeLimit = Time::Zero;
}

This is display function:

void Window::display()
{
    // Display the backbuffer on screen
    if (setActive())
        m_context->display();

    // Limit the framerate if needed
    if (m_frameTimeLimit != Time::Zero)
    {
        sleep(m_frameTimeLimit - m_clock.getElapsedTime());
        m_clock.restart();
    }
}

I think that my "fixed time step" loop looks almost the same. So I assume that I shouldn't use them at the same time. Even though it's not true, my program is lagging when I use both. What causes it? This is so simple piece of code, I'm feeling bad having problems with it.  :-\

@Edit: This is video showing what is going on when I'm trying to use both of them: http://sendvid.com/6vr22pn2

6
General / Re: Problem with fixed time step
« on: September 29, 2016, 06:26:37 pm »
What exactly is wrong with my game loop? Problem which I described takes place on every PC where I tried to use my program. So, I think it's not related with GPU. This code is quite simple, so I have no idea what's wrong.

7
General / Problem with fixed time step
« on: September 29, 2016, 12:43:57 pm »
I have a short question. I am learning SFML and I made few apps by using it. Someday I learned about using fixed time step while coding games and it would be great if it worked. BUT. Even though I am making simple project like square moving from left to right side of the window - it is lagging! What could be a cause of this problem? This is some simple code, which contains this problem:

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "Window");
    sf::Event event;
    sf::Clock clock;
    sf::Time accumulator = sf::Time::Zero;
    const sf::Time timePerFrame = sf::seconds(1.f / 60.f);
    sf::RectangleShape square;
    square.setSize(sf::Vector2f(32, 32));
    square.setOrigin(16, 16);
    square.setPosition(400, 300);
    square.setFillColor(sf::Color::Red);
    int direction = 1;
    int speed = 300;
    while(window.isOpen())
    {
        while(window.pollEvent(event))
        {
            if(event.type == sf::Event::Closed)
            {
                window.close();
            }
        }
        while(accumulator >= timePerFrame)
        {
            if(square.getPosition().x <= 16 || square.getPosition().x >= 784) direction *= (-1);
            square.move(sf::Vector2f(speed * direction * timePerFrame.asSeconds(), 0));
            accumulator -= timePerFrame;
        }
        accumulator += clock.restart();
        window.clear(sf::Color::Black);
        window.draw(square);
        window.display();
    }
    return 0;
}
 

I don't want to use vertical synchronization, because I read that it shouldn't be used with fixed time step. Any help is appreciated!

@Edit: My problem looks similar to this:

Pages: [1]