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

Pages: [1] 2
1
Network / Packet::Append
« on: July 21, 2011, 06:42:24 pm »
yeah dude but all data is IN the packet. to get the rest i need the starting pointer of rest. To do that i need to know what is the size of [sf::Uint8 type ][sf::Uint32 id ][std::string lobbyname ]

2
Network / Packet::Append
« on: July 21, 2011, 06:34:56 pm »
I get packet from client [sf::Uint8 type ][sf::Uint32 id ][std::string lobbyname ][rest]

i want to send from server packet without id and lobbyname, only packet type and the rest.

3
Network / Packet::Append
« on: July 21, 2011, 06:22:46 pm »
I got a packet like this:
[sf::Uint8][sf::Uint32][std::string][rest..]
now i want to make a new packet which has only sf::Uint8 and rest. How do i do that using append?(the problem is std::string..)

4
Graphics / Strange redrawing. Thats important
« on: July 18, 2011, 02:53:21 pm »
Quote from: "Nexus"
Before you make your life more complicated than necessary, you should test if the normal draw approach is really too slow. Test in Release mode with enabled optimizations.

i think 1000+ glbegin() per frame is extremally slow.

I used glOrtho, and then drawing with glBegin(GL_LINES)

5
Graphics / Strange redrawing. Thats important
« on: July 17, 2011, 11:09:06 pm »
Nooooooooooooooooooooooooo......
I need to draw many,many lines. The solution is OpenGL or sfml 2.0 with drawing to an image, right?

6
Graphics / Strange redrawing. Thats important
« on: July 17, 2011, 10:24:32 pm »
I wrote that code.
Code: [Select]

sf::RenderWindow w(sf::VideoMode(800,600,32),"a");
w.Clear(sf::Color(255,0,0));
w.SetFramerateLimit(100);
while(true){
w.Display();
cout<<"after disp: "<<endl;
sf::Sleep(1.0f);
}

On my PC everything works fine.
On my Notebook window once displays the red screen(good) and once the OLD BUFFER(which is totally mess). I really need help with that. I can't redraw everything each frame(the program is kinda bigger but its the minimal code).

7
Network / Effective SFML networking..
« on: July 15, 2011, 01:08:39 pm »
So...big applications work like this? 3 threads and a selector?Iis that a well projected loop ? Btw in my code i meant i waste 1/3 CPU time for loop that only checks whether there is a message to sent .

8
Network / Effective SFML networking..
« on: July 14, 2011, 10:00:45 pm »
Quote from: "Laurent"
Quote
Anyway thats only a few lines to watch

... or to edit. Since it was only a few lines, I did it. Avoid tabs, use spaces instead. Tabs are the best way to make our code unreadable across editors/viewers. Spaces are consistent.

Which one si slow, the client or the server?

TBH i think client.

9
Network / Effective SFML networking..
« on: July 14, 2011, 08:53:32 pm »
Anyway thats only a few lines to watch.

10
Network / Effective SFML networking..
« on: July 13, 2011, 10:42:41 pm »
Well I thought its kinda well indented :) I changed some ;p
Oh the result differs between a textbox i wrote that.. sort of hard to make it clear ;d Hope you can read it since its the minimal code.

11
Network / Effective SFML networking..
« on: July 13, 2011, 12:49:19 pm »
I've got a Client application which sends packet to the server, and server replies to client everything he sents. The problem is everything works perfectly after 1-2 first packets and then it goes really sloooooow. Need your help :)

Server code:
Code: [Select]

void runServer(unsigned short Port)
{
    if (!Listener.Listen(Port))
        return;
    sf::IPAddress Address;
    Listener.Accept(Client, &Address);
    while(true)
    {
        sf::Packet Packet;
        if (Client.Receive(Packet) == sf::Socket::Done)
            Client.Send(Packet);
    }
}



Client works on 3 threads.
1 is the main loop -getting events, drawing,pushing packets on queue(which will be sent). This code runs when i push a button
Code: [Select]

void Internet::queuePacket(sf::Packet* p)
{
    {
        sf::Lock Lock(sendMutex);
        toSend.push(p);
    }
}

2 is a loop which observes if there are any packets in queue to send, and it sends it .

Code: [Select]
void sendingLoop(void* UserData)
{
    queue<sf::Packet*>& toSend= *static_cast< queue<sf::Packet*>* >(UserData);
    while(runningThread)
    {
        if(!toSend.empty())
        {
            sf::Packet* p=NULL;
            {
                sf::Lock Lock(sendMutex);
                p=toSend.front();
                toSend.pop();
            }

            sf::Socket::Status st;
            st=Application::instance->internet.Send(*p);
            while(st==sf::Socket::NotReady)
            {
                sf::Sleep(0.01f);
                st=Application::instance->internet.Send(*p);
            }
            delete p;
        }
        else
            sf::Sleep(0.01f);
    }
}


3 is a loop receiving packets.
Code: [Select]

void receivingLoop(void* UserData)
{
    sf::SelectorTCP Selector;
    Selector.Add(Application::instance->internet);
    while(runningThread)
    {
        if(Selector.Wait(0.5f)>0)
        {
            sf::SocketTCP socket = Selector.GetSocketReady(0);
            sf::Packet pac;
            if(socket.Receive(pac)!=sf::Socket::Done)
                out<<"Err receiving"<<endl;
            sf::Uint8 type;
            pac>>type;
            switch(type)
            {
            case OBJECT:
                out<<"type=OBJECT"<<endl;
                break;
            default:
                out<<"Unknown packet type"<<endl;
                break;
            }
        }
    }
}

Blocking in client app is set to false, and in server to true.
Hlp!:D

12
Network / sf::Socket::Done
« on: July 10, 2011, 11:23:46 pm »
Okay ... the problem was on OnProcess samples - function returned false stopping streaming

the solution:
Code: [Select]

bool  NetworkRecorder::OnProcessSamples(const sf::Int16* Samples, std::size_t SamplesCount){
        sf::Packet PacketOut;
        PacketOut << AUDIODATA;
        PacketOut.Append(Samples, SamplesCount * sizeof(sf::Int16));
sf::Socket::Status st=Application::instance->internet.Send(PacketOut);

while(st==sf::Socket::NotReady){
st=Application::instance->internet.Send(PacketOut);
Sleep(0.001f);
}
return st==sf::Socket::Done;
    }

not sure if i lose some voice i say coz of blocking the function, im not sure if another thread executes this function on another stack

13
Network / sf::Socket::Done
« on: July 10, 2011, 03:04:58 pm »
i have client-server application
Client-streaming voice and sending movement messages
Server-gets messages from every client and replies to everyone
Blocking is set to false.
My app works perfectly but suddenly when i send a packet with my movement.

Code: [Select]
if (Send(pac) != sf::Socket::Done){
cout<<err<<endl;
}


It printfs "err" and my voice is no longer streamed.

my mainloop looks like this:
Code: [Select]

while(1){
/*...*/
getpac();
sendpac();
/*...*/
}

14
Network / VOIP example
« on: July 06, 2011, 04:47:27 pm »
i used some code from VOIP example and i set blocking sockets to none so my application is real-time etc. Here is the code from example which makes my program working sloooooooow.

Code: [Select]
while ((myOffset == mySamples.size()) && !myHasFinished)
            sf::Sleep(0.01f);

When i remove this receiving the sound doesnt work. How do i change this?[/code]

15
Network / Switching packets
« on: July 05, 2011, 12:12:22 am »
I want after getting a packet check what is the type of the packet(a line, a guy entering lobby)

Code: [Select]
class MyPacket: public sf::Packet{

private :
    virtual const char* OnSend(std::size_t& DataSize)
    {
Append(type.c_str(),type.length());
DataSize = GetDataSize();
return this->GetData();
    }

    virtual void OnReceive(const char* Data, std::size_t DataSize)
    {
        //HERE
    }
public:
string type;
};


How do i retrieve the type from const char* Data?

Pages: [1] 2
anything