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

Pages: [1]
1
Network / Re: Difference between remote port and bind port
« on: December 15, 2013, 02:03:56 am »
After researching I found the following on Wikipedia:
Quote
Source port number
This field identifies the sender's port when meaningful and should be assumed to be the port to reply to if needed. If not used, then it should be zero. If the source host is the client, the port number is likely to be an ephemeral port number. If the source host is the server, the port number is likely to be a well-known port number

I still don't quite understand the concept of the source port though. If the receiver is to reply to the sender using the source port then surely the sender must have already bound to the source port? I do not see any way of getting/setting the source port when sending something using SFML.

Edit: Okay so after reading the documentation like I should have done in the first place I found that the source port is whatever port the sender's socket was bound to. I'm not quite sure as to the behaviour when the sender's socket is not bound but it shouldn't matter as the receiver cannot respond to a sender that is not bound.

2
Network / [SOLVED]Difference between remote port and bind port
« on: December 15, 2013, 01:46:44 am »
I'm trying to implement UDP hole punching to allow peer-to-peer connections but I don't understand exactly how UDP endpoints work. Specifically, what is the difference between the the_port in

sf::Packet packet;
sf::IpAddress ip;
unsigned short the_port;
socket.receive(packet, ip, the_port);
 

and

socket.bind(the_port);
 

3
System / Re: Strange sf::Clock issue with SFML 2.1
« on: December 13, 2013, 08:15:05 pm »
Thank you! I should have realised I should be measuring time right before logic.

4
Feature requests / Re: Message Boxes
« on: December 13, 2013, 06:43:14 pm »
I support the idea of adding a MessageBox function to SFML. Sure, they suck for debugging, but they are very useful for errors that should be reported to a user. For example, when you need to tell a user that a font failed to load.

Currently, one has to do:
#ifdef _WIN32
#include <windows.h>
#endif

...

#ifdef _WIN32
MessageBox(NULL, "text", "caption", MB_OK);
#endif
 

And you'd also obviously have to account for OSes other than Windows.

SFML might be a multimedia library but keep in mind there is a system module that basically consists of useful things that are painful to do in a cross-platform way. sf::Clock and sf::Thread don't exactly have much to do with multimedia.

5
System / Re: Strange sf::Clock issue with SFML 2.1
« on: December 13, 2013, 06:22:48 pm »
The reason I use 16.66666667 is to achieve something similar to "pixels per frame if the program was running at 60fps". I'm not absolutely certain as to whether the division is actually correct but using the division allows me to have a much more natural unit for speed - I'm currently using 60.0 * delta for the speed of the player. Without the division, I have to use something like 0.0001 * delta. In any case, removing the division doesn't make any difference except I have to use much smaller constants.

Any other ideas?

6
Graphics / Re: Positioning button sides equally
« on: December 13, 2013, 03:20:55 pm »
I'm not really sure as to what you're doing, but here's how to centre text and a rectangle on the screen.
const int SCREEN_WIDTH = 1280;
const int SCREEN_HEIGHT = 720;

sf::Text centredText("hello", myFont);
sf::RectangleShape centredRectangle(sf::Vector2f(20.0f, 20.0f));

const sf::FloatRect textBounds = centredText.getLocalBounds();
const sf::FloatRect rectBounds = centredRectangle.getLocalBounds();

//Note that you have to add textBounds.left and textBounds.top because text can have non-zero left and top bounds
centredText.setOrigin(textBounds.width / 2.0f + textBounds.left, textBounds.height / 2.0f + textBounds.top);
centredRectangle.setOrigin(rectBounds.width / 2.0f, rectBounds.height / 2.0f);

centredText.setPosition(SCREEN_WIDTH / 2.0f);
centredRectangle.setPosition(SCREEN_HEIGHT / 2.0f);
 

I'm fairly certain the answer you're looking for is somewhere there.

7
System / [SOLVED] Strange sf::Clock issue with SFML 2.1
« on: December 13, 2013, 02:55:42 pm »
Hey guys,

I've always used sf::Clock to get the delta time between frames to allow for frame-independent movement. On a new project of mine, however, I have encountered some odd behaviour:

        sf::Clock frameClock;
        double timeLast = 0.1;
        while (window.isOpen())
        {
                //This code works correctly.
                const double timeNow = frameClock.getElapsedTime().asMilliseconds() / 16.66666667;
                const double delta = timeNow - timeLast;
                timeLast = timeNow;
 

        sf::Clock frameClock;
        while (window.isOpen())
        {
                //This code works incorrectly; "delta" is all over the place and my sprites move at visibly different
                //speeds at different times.
                const double delta = frameClock.restart().asMilliseconds() / 16.66666667;
 

This is very strange considering I've used the latter method in other projects where it worked correctly. The only difference between this project and the others is, in the others, frameClock is a member of a class.

I looked at the source of sf::Clock on git and it appears to be doing exactly what the former method does. I tried to debug using VS2012 but I don't have pdb files for SFML and I'm unsure as to how to acquire them although I presume one has to compile from source.

For my entire main.cpp, see http://pastebin.com/xK46pjyC.

8
Graphics / Re: Static RenderWindow Access Vialation
« on: September 07, 2013, 07:46:52 pm »
Thanks for responding so quickly! I should have realised that's a necessary requirement considering what's happening under the hood.

9
Graphics / [SOLVED] Static RenderWindow Access Vialation
« on: September 07, 2013, 07:19:37 pm »
Hey,

I've been using SFML to create a game. I've decided to make the main game class completely static because passing around parent classes in C++ is somewhat messy. This does, of course, mean that all classes have access to the game class even if they don't deserve it but I'm willing to make that sacrifice.

When I tried to add a static RenderWindow to the class, however, I started getting access violations at 0x00000004 on the initializer line in the implementation of the class.

Here's the code necessary to reproduce the problem:
StaticClass.h:
#include <SFML/Graphics.hpp>

class StaticClass
{
public:
        static sf::RenderWindow renderWindow;
};
StaticClass.cpp:
#include "StaticClass.h"

sf::RenderWindow StaticClass::renderWindow;

Is this a bug? I don't get an access violation if I replace the class of the static member variable; I changed it to sf::Text and everything worked.

Thanks.

Edit: I'm using SFML 2.1

Pages: [1]