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 - P@u1

Pages: [1] 2
1
Window / Request: Move EventLoop processing to background thread
« on: April 01, 2012, 01:32:00 pm »
Hi,

currently when dragging the window with the mouse, the game stops (with most common implementations, atleast under ms windows), as the main thread hangs in the event loop.
By moving the event loop processing to a background thread this can be fixed.

My suggestion is to make this part of sfml.
Imo it's surely not a feature, that the game freezes when the window is moved.

Here is a sample implementation with C#, which atm is missing a method to stop the background thread. This could be implemented with a WaitEvent method with a timeout and then the main thread calls Dispose, which makes the background thread terminate as soon as it returns from the WaitEvent method:

public class ThreadedEventLoopRenderWindow : RenderWindow
{
    private ConcurrentQueue<Event> eventQueue = new ConcurrentQueue<Event>();

    public static ThreadedEventLoopRenderWindow Create(VideoMode mode, string title, Styles style, ContextSettings settings)
    {
         ThreadedEventLoopRenderWindow result = null;
         bool windowCreated = false;
        //the window must be created from the background thread
         Thread eventThread = new Thread(() =>
         {
                result = new ThreadedEventLoopRenderWindow(mode, title, style, settings);
                windowCreated = true;
                result.ProcessEvents();              
         });
         eventThread.IsBackground = true;
         eventThread.Start();
         while (!windowCreated) ;
         return result;
    }

        private ThreadedEventLoopRenderWindow(VideoMode mode, string title, Styles style, ContextSettings settings)
            : base(mode, title, style, settings)
        {
            SetActive(false);
        }

         private void ProcessEvents()
        {
            while (true) //replace this with sthg like while(!interrupted) and use a WaitEvent call with timeout
            {
                Event evt;
                bool ok = base.WaitEvent(out evt);
                if (ok)
                {
                    eventQueue.Enqueue(evt);
                }
            }
        }

        protected override bool PollEvent(out Event eventToFill)
        {
            return eventQueue.TryDequeue(out eventToFill);
        }
}
 

Note that for this to work the window must be created from a background thread.
That's the reason, why the constructor is private and a factory method is used to create.

If all this is implemented as part of sfml these ugly details can be hidden and fixed behind the same interface which was always used.
I think that many people find the default behaviour annoying.
With sfml thread classes and/or the new standard there should be a way to implement it in c++ as part of sfml.

Btw does this problem also occur on other OS'es than windows?

Another nice thing for the window class would be a method to make the window have focus (I think it's missing).

2
Network / Two physical packets per sf::Packet?
« on: October 22, 2011, 03:56:01 pm »
Hi everyone,

I just read some of the network source code and recognized a possible problem.

TcpSocket::Send(Packet& packet) looks like this:
Code: [Select]

TcpSocket::Send(Packet& packet)
//...
// First send the packet size
    Uint32 packetSize = htonl(static_cast<unsigned long>(size));
    Status status = Send(reinterpret_cast<const char*>(&packetSize), sizeof(packetSize));

//...
// Send the packet data
    if (packetSize > 0)
    {
        return Send(data, size);
    }
//...


And you also disable nagle-algorithm, so that if I understand it right every call to send directly sends a physical packet over the network.
You are calling send 2 times in a row with very low time between the calls.
If that really yields 2 phyiscal packets (and it should do as nagle algorithm is off) with tcp/ip-header then this is quite a big overhead, don't you think so?

3
Window / Application freezes when moving the window
« on: October 11, 2011, 11:37:32 am »
Hi,

I recognized that while I'm moving a window the game logic pauses.
It's most probably because the program is captured in the event loop.
Is there a fix for this other than using more than 1 thread?

4
General / Possible Bug in RenderWindow Destructor (SFML 2.0)
« on: October 09, 2011, 12:36:38 pm »
Hi,

I just started a new project and this time I used the singleton pattern for my game class.
I first implemented it so that in the static deinitializers the Game object is destroyed which invokes the RenderWindow destructor.
This yields a crash:
Quote
Unhandled exception at 0x77bb1c1d in LockstepMario.exe: 0xC0000005: Access violation reading location 0xfeeefef6.
    ntdll.dll!77bb1c1d()    
    [Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]   
>   LockstepMario.exe!sf::priv::MutexImpl::Lock()  Line 52 + 0xc bytes   C++
    LockstepMario.exe!sf::Mutex::Lock()  Line 62   C++
    LockstepMario.exe!sf::Lock::Lock(sf::Mutex & mutex)  Line 39   C++
    LockstepMario.exe!sf::GlResource::~GlResource()  Line 72 + 0xd bytes   C++
    LockstepMario.exe!sf::Renderer::~Renderer()  + 0x16 bytes   C++
    LockstepMario.exe!sf::RenderTarget::~RenderTarget()  Line 53 + 0xb bytes   C++
    LockstepMario.exe!sf::RenderWindow::~RenderWindow()  Line 60 + 0xe bytes   C++
    LockstepMario.exe!Game::~Game()  Line 14 + 0x8 bytes   C++
    LockstepMario.exe!Game::`scalar deleting destructor'()  + 0x2b bytes   C++
    LockstepMario.exe!std::default_delete<Game>::operator()(Game * _Ptr)  Line 2068 + 0x2b bytes   C++
    LockstepMario.exe!std::unique_ptr<Game,std::default_delete<Game> >::_Delete()  Line 2345   C++
    LockstepMario.exe!std::unique_ptr<Game,std::default_delete<Game> >::~unique_ptr<Game,std::default_delete<Game> >()  Line 2302   C++
    LockstepMario.exe!`dynamic atexit destructor for 'Game::instance_''()  + 0x28 bytes   C++
    LockstepMario.exe!doexit(int code, int quick, int retcaller)  Line 567   C
    LockstepMario.exe!exit(int code)  Line 393 + 0xd bytes   C
    LockstepMario.exe!__tmainCRTStartup()  Line 284   C
    LockstepMario.exe!mainCRTStartup()  Line 189   C
    kernel32.dll!760d3677()    
    ntdll.dll!77b89f02()    
    ntdll.dll!77b89ed5()    
(I'm using visual studio 2010).
I did some investigation and figured out that MutexImpl::myMutex has the address 0xfeefee which means that it is uninitialized.   

But when I put a call to release the singleton in atexit, it works.

Here is some code:
Code: [Select]
int main(int argc, char** argv)
{
Game::Instance().Run();
return 0;
}

//new file here
class Game
{
public:
Game();
~Game();
void Run();

static Game& Instance()
{
if(!instance_)
{
instance_.reset(new Game());
//atexit(Destroy); when I add this lines, everything works!
}
return *instance_;
}
private:
void Init();
void MainLoop();
void HandleEvents();
void Update();
void Draw();
sf::RenderWindow window_;

static void Destroy(){instance_.release();}
static std::unique_ptr<Game> instance_;
};


The other methods don't do anything interesting, but I can post them if you want.

Note: I'm using SFML 2.0, but not the latest build atm.

5
DotNet / Is it important to Dispose SFML objects?
« on: September 07, 2011, 10:26:36 am »
Hi everyone,

I wondered if it is important to call Dispose on every single sfml-object or not and what happens if I dont do it.

It probably means that the destructors are not called, but what does this mean?

Just that we loose some memory, or are there also resources which get lost until a computer restart?

I know that the destructor also disposes the objects, but that only happens when the garbage collector collects these objects.
I read that C# does usually not run the garbage collector on shutdown.

6
Network / No support for serializing a single char?
« on: August 04, 2011, 12:14:29 pm »
Hi,

I recognized that sf::Packet offers operator<< and operator>> for
sf::Int8 and sf::Uint8
which are at my platform typedefs for
signed char   and
unsigned char

But if I use
char
Then it won't compile, as it is a different type.

I know that there is support for 0-terminated char-arrays, but that's not what I need.
Laurent could you please add support for char?

7
Graphics / Alpha value of font for chat box
« on: July 26, 2011, 06:46:01 pm »
Hi everyone,

I'm planning to develop a chat box, which should be partially transparent.
I thought that this is a perfect job for alpha-values.
But how can I set the alpha-value which is used to draw the text?
Or is there any other good solution?

8
Network / No endianess problems for double/float?
« on: June 12, 2011, 05:56:27 pm »
Hi,

I recognized, that in SFML 1.6 the sf::packet code for float and double don't do anything about endianess.

Is there no endianess problem for float/double?

I used google and found some articles about how to convert endianess of float/double, so it seems if these datatypes also have endianess, but I'm not sure...

Another question:
With which header do you get access to functions like htonl?

9
Network / Need help with simple UDP game
« on: June 09, 2011, 11:24:24 pm »
Hi,

I'm trying to build a very simple game with UDP just for testing.
Unfortunately at the moment it works worse than it used to work with TCP...
I'm not exactly sure, what the problem is, I thought that you maybe can help me.

Here is the full code:
http://pastebin.com/2ERzSk1n
or
http://codepad.org/qsznZjow

And here are the two most important passages:

Code: [Select]

void Game::sendGameState()
{
sf::Packet toSend;
toSend << myServerPlayer.xPos << myServerPlayer.yPos << myServerPlayer.input
<< myClientPlayer.xPos << myClientPlayer.yPos;
sf::Socket::Status status = mySocket.Send(toSend, myIPAddress, PORT);
switch(status)
{
case sf::Socket::Disconnected:
cout << "Disconnected" << endl;
myIsConnected = false;
break;
case sf::Socket::Error:
cout << "Error sending" << endl;
break;
case sf::Socket::Done:
break;
case sf::Socket::NotReady:
//try again next time;
break;
}
}

void Game::receiveAndSyncGameState()
{
sf::Packet toReceive;
unsigned short port = PORT;
sf::Socket::Status status = mySocket.Receive(toReceive, myIPAddress, port);
switch(status)
{
case sf::Socket::Disconnected:
cout << "Disconnected" << endl;
myIsConnected = false;
break;
case sf::Socket::Error:
cout << "Error receiving game state" << endl;
break;
case sf::Socket::Done:
toReceive >> myServerPlayer.xPos >> myServerPlayer.yPos >> myServerPlayer.input
>> myClientPlayer.xPos >> myClientPlayer.yPos;
//no interpolation yet
break;
case sf::Socket::NotReady:
//try again next time;
break;
}
}


I'm sending gamestate data periodically from the server to the client and the client sends input data periodically to the server.
In the current code it is sent 100 times per second, which is quite huge, but I tried it with 20/s and it didn't work very well too.
At client side the rectangle controlled by the server is always "jumping" between two positions which aren't close to each other.
And after some time there also is quite big delay and some socket errors occur.
I'm not sure if the "jumping" is caused by UDP specific problems, maybe it is caused by lack of mechanism which ensure that data arrives correctly and in the right order?
Or it is just some silly bug i build into my code? :D

But there is also the delay... sending 20 times per second ~10bytes with UDP over LAN should be no problem, should it?

And I'm also not sure, if I'm using the asnyc sockets in the right way...

I can upload the .exe file if you want/need it.

It would be very nice, if you can help me :-)

10
Network / How to use non-blocking TCP?
« on: May 30, 2011, 03:35:13 pm »
Hi,

I'm trying to use an sf::SocketTCP in non-blocking mode.
I want to use it like this:
Code: [Select]

if(/*socket is ready*/)
{
   socket.Send(...);
}
//if not ready continue the next main loop and send the date next time if the socket has become ready


How can I do this?
I need a method like
socket.IsReady(), but there is none.
Send() returns a status, but I want to check the status without actually sending anything.

Please help :-)

11
Graphics / sf::Shape.SetPosition not properly working?
« on: May 24, 2011, 10:58:03 pm »
Hallo everyone,

I'm doing the following:
Code: [Select]
while(app.IsOpened)
{
  //event proccessing omitted

  app.Clear();
  sf::Shape shape(sf::Shape::Rectangle(100,100, 150, 150, sf::Color::Green));
  //shape.SetPosition(0,0);
  app.Draw(shape);
  app.Display();
}


When I comment out the SetPosition line it is just a rectangle with coords 100,100,150,150.
But when I uncomment it i expect it to move to
0,0,50,50
But it just doesent move...
Why is that and what do I have to do to set the position to absolute coords?

12
Graphics / How to move a line smoothly?
« on: May 19, 2011, 04:47:46 pm »
Hello everyone,

I want to move a line from left to right and it must look like a smooth movement.
Unfortuantely I didnt get this working so far, the movement seems not to be smooth, especially, when I maximize the screen.
I looks like sometimes the line jumps a bit and sometimes it seems to flicker and so, it just doesen't look good.

Here is the code which I used:
Code: [Select]
int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
   //both with and without verticalsync it doesent look good.
App.UseVerticalSync(true);
sf::Shape line(sf::Shape::Line(0,0,200,200,2,sf::Color::Green));
while (App.IsOpened())
{
sf::Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
}
App.Clear();

line.Move(App.GetFrameTime() * 50, 0);
if(line.GetPosition().x > App.GetWidth())
{
line.SetPosition(0, line.GetPosition().y);
}

App.Draw(line);
App.Display();
}

return EXIT_SUCCESS;
}


Would be nice if you have any suggestions to improve this.

Edit: I Just tested it on other pcs and there it just runs fine, so its probably a problem with the graphics driver or my hardware is too old (which I dont think).
I'm using a GForce 6200 Graphics card at this pc, which is indeed not very new, but I think it should be good enough to display some lines :-)

13
Graphics / Need to get pointers to OpenGL functions manually?
« on: May 10, 2011, 07:11:04 pm »
Hi,

I just tried to do some openGL with SFML and recognized some commands and keywords from openGL are not available:

Code: [Select]

glGenBuffers
GL_ARRAY_BUFFER


I am very new to OpenGL and just wanted to try some things from an tutorial. Somewhere else I read that for for openGL functions you somehow have to get pointers to these functions manually.
Is it true that SFML doesen't to that?
I this is true, how can I get acess to these functions?
Or do I maybe just need to add an include to get things working?

Thanks for your help in advance!

14
Graphics / Somtimes Black Line appears when drawing a sprite
« on: May 09, 2011, 06:05:42 pm »
Hi everyone,

I have a problem with drawing a simple sprite from an image.
Sometimes a black line at the right end of the image appears (its not regularly).
I created a minimal example to show this.
(I hope that you will see the same effect, a friend of mine already confirmed, that he has the same effects).
I uploaded the image I used here:
http://www.megaupload.com/?d=GPPOH5RP

Here is the source code:

Code: [Select]

#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>

int main()
{
sf::Image img;
img.LoadFromFile("marioandluigi.png");
img.SetSmooth(false);
sf::Sprite mario(img);
int x = 0;
mario.SetSubRect(sf::IntRect(1+17*x, 232, 1+17*x+16, 232+32));
mario.SetScale(5,5);
int xDir = 1;

sf::RenderWindow app(sf::VideoMode(800, 600, 32), "SFML Window");
while(app.IsOpened())
{
sf::Event event;
while (app.GetEvent(event))
{
if(event.Type == sf::Event::Closed)
{
app.Close();
}
}

app.Clear(sf::Color::Green);
app.Draw(mario);
if(mario.GetPosition().x > app.GetWidth() - mario.GetSize().x)
{
xDir = -1;
}
if(mario.GetPosition().x < 0)
{
xDir = 1;
}
mario.Move(app.GetFrameTime() * 100 * xDir, 0);
app.Display();
}
return 0;
}


Please tell me if you have any clue, why this line appears.

15
Graphics / Problems with Get and Set Position after setting Center
« on: May 02, 2011, 09:13:11 pm »
Hi everyone,

I'm facing huge problems with getting and setting the position of a sprite after I set the center.
I know that there are methods to transform to global/local coordinates, but I think that these methodes are not good here, because they also apply rotating and more things, which should not be taken into consideration.

By default the center is on the top left corner (0,0), but I need to set it to the real center (width/2, height/2) so that rotation works the way I need it.

But when I then want to get/set the position I get lots of problems, because the positions I get / set seem to be no longer the left top corner, but the middle (the real center).
I tried to handle this with methods which subtract the half of the center before getting/setting, but this doesent work good, because if i for example use somethign like

Code: [Select]
setPosition(getPosition); //modified setters/getters which subtract half of center

It will do strange changes...

I'm a bit confused, maybe I have to substract for getting and add for setting or the other way round?
There must be some better approches...

Please help :-)

Pages: [1] 2
anything