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

Pages: [1] 2 3
1
General / menu design
« on: July 06, 2016, 01:45:37 pm »
hi guys, i wonder what would be the best design for menu.
my menu will have
-START
-DIFFICULTY
-EXIT

take a look at my class: http://pastebin.com/WwhUCFn0
i dont know if this will be a good class design  for my menu

I EDITED THE LINK PLEASE LOOK AGAIN.

2
General / best practice
« on: June 20, 2016, 08:52:56 pm »
hello, is it only alright to update an object outside the event loop?
since it doesnt have to do anything with events.
 
while(window.isOpen())
    {
        sf::Event e;
        while(window.pollEvent(e))
        {
            if ( sf::Event::Closed == e.type)
                window.close();
        }

        w.update(timer.getElapsedTime().asSeconds());
        timer.restart();

        window.clear();
        w.draw(window);
        window.display();
    }

3
Window / sf::Event::Keypress problem
« on: April 27, 2016, 11:42:47 pm »
hello,
so i have this code
Paddle::Paddle()
{
        dir = sf::Keyboard::Unknown; // dir is of type sf::Keyboard::Key
}
void Paddle::update(bool isPlayer1,float delta)
{
    if ( isPlayer1 )
    {
        if ( dir == sf::Keyboard::Up  )
        {
            pad.move(0,(-speed)*delta);
        }
        if ( dir == sf::Keyboard::Down  )
        {
            pad.move(0,speed*delta);
        }
    }
    else
    {
        std::cout << dir << std::endl;
        if ( dir == sf::Keyboard::W  )
        {
            pad.move(0,(-speed)*delta);
        }
        if ( dir == sf::Keyboard::S  )
        {
            pad.move(0,speed*delta);
        }
    }
}

void Paddle::setDir(sf::Keyboard::Key key)
{
    dir = key;
}

 


on the Game class i have this

void Game::start()
{
while(window->isOpen())
{
  event();
  update();
  render();
}
}
void Game::event()
{
    sf::Event e;
    while(window->pollEvent(e))
    {
        if ( e.type == sf::Event::KeyPressed )
        {
            if ( e.key.code == sf::Keyboard::Up || e.key.code == sf::Keyboard::Down )
                player2.setDir(e.key.code); // player2 is a Paddle type
            else if ( e.key.code == sf::Keyboard::W || e.key.code == sf::Keyboard::S )
                player1.setDir(e.key.code); // player1 is a Paddle type
        }
        else if ( e.type == sf::Event::KeyReleased )
        {
            if ( e.key.code == sf::Keyboard::Up || e.key.code == sf::Keyboard::Down )
                player2.setDir(sf::Keyboard::Unknown);  // player2 is a Paddle type
            else if ( e.key.code == sf::Keyboard::W || e.key.code == sf::Keyboard::S )
                player1.setDir(sf::Keyboard::Unknown); // player1 is a Paddle type
        }
    }
}

void Game::update()
{
     player1.update(true,somedelta);
     player2.update(false,somedelta);
}
 

when ever i hold S key nothign happens.
the line
 std::cout << dir << std::endl;  
always output -1 which is its default value sf::Keyboard::Unknown it should output 18 which is sf::Keyboard::S

4
Graphics / sf::Texture getSize() crashes the program
« on: April 12, 2016, 08:57:38 pm »
Hello, i have a problem
my problem gets crashed whenever i get the size of square, even in circle and other shapes

int main()
{
     sf::RectangleShape square(sf::Vector2f(50,50));
     std::cout << square.getTexture()->getSize().x;
}

5
Audio / audio error
« on: December 06, 2015, 08:37:57 am »
Failed to play audio stream: sound parameters have not been initialized (call initialize() first)
can someone tell me the cause of that error?

6
Graphics / resource manager
« on: December 05, 2015, 03:15:04 pm »
std::map doesnt store the pair if the key  has conflict
ie:
std::map<std::string,int> test;
test["One"] = 1;
test["One"] = 2;
std::cout << test.size(); // outputs 1

so in the resource manager of sfml essentials book
why it still need to check if the requested resource to load is already loaded before loading?

7
Audio / stack allocated sf::Music
« on: November 29, 2015, 03:42:50 pm »
why cant I allocated sf::Music on stack

heres my code:
class Track
{
   public:
       Track(const std::string&);
       const std::string& getName() const;
       const sf::Music& getAudio() const;
   private:
       std::string name;
       sf::Music audio;
};
this spits out:
error: use of deleted function 'sf::Music::Music(const sf::Music&)'
error: use of deleted function 'sf::SoundStream::SoundStream(const sf::SoundStream&)'
error: use of deleted function 'sf::Mutex::Mutex(const sf::Mutex&)'
error: 'sf::NonCopyable::NonCopyable(const sf::NonCopyable&)' is private NonCopyable(const NonCopyable&);
error: use of deleted function 'sf::InputSoundFile::InputSoundFile(const sf::InputSoundFile&)'
 error: use of deleted function 'sf::Mutex::Mutex(const sf::Mutex&)'
 class SFML_AUDIO_API Music : public SoundStream
 error: use of deleted function 'Track::Track(Track&&)'

but when i allocate it on heap like this:

class Track
{
   public:
       Track(const std::string&);
       const std::string& getName() const;
       const sf::Music& getAudio() const;
   private:
       std::string name;
       sf::Music* audio;
};
it works fine

TIA.

8
Network / conflicting use of packet
« on: November 18, 2015, 07:11:43 pm »
should i have more than one packet in a class?
for example in chat app.

theres a:
- list of people in the chat room
     - people who joins the room
     - people who leaves the room
- messaging system


so i only have one sf::Packet in my class
class ClientManager
{
    public:
         void sendPacket();
         void receivePacket()
         {
                socket.receive(packet);
         }
         sf::Packet packet;
}


class MainWindow
{
     public:
 
          void leavesTheChatRoom()
          {
                 client.packet << "my name"; // send it, so everybody knows who leaves the room
                 client.sendPacket();
          }
          void sendMessage()
          {
                 client.packet << "my message"; // send the message to everybody
                 client.sendPacket();
          }
          void receiveMessage()
          {
                client.receivePacket();
          }
    private:
          ClientManager client;

}

as you can see in the code, 3 functions can use the packet at the same time
- you send a message at the same time someone leaves the room
- you receive a message at the same time you send a message
- etc.

so if thats happens, the packet will have your message and the message of other client and the name in it

9
Network / packet sending through tcpsocket corrupted
« on: November 16, 2015, 06:48:33 pm »
so im working with chat app using QT and SFML network. and ive been fixing this problem for 2 days T_T

i have a class in client side that runs SFML thread which is running a function to receive data from server:
void ClientManager::receiveMessage()
{
            sf::Packet packet;
            if ( client.receive(packet) == 0 )
            {
                qDebug() << "Message received!";
                std::string name;
                int a;
                packet >> a >> name;
                qDebug() << QString::fromStdString(name);
                qDebug() << a;
            }
}

here is how the client connects to server:
void ClientManager::connectToServer()
{
    if ( client.connect("192.168.1.101",5000) == 0 )
    {
        qDebug() << "Connected";
        sf::Packet name;
        name << Login::getName().toStdString(); // name of the client
        if ( client.send(name) == 0 ) // send the name to the server, then the server will send the name to other clients to know who joins the room
        {
            qDebug() << "Name sent!";
        }
    }
}


On the server side:
   
sf::Packet packet;
while(true)
    {
        if ( selector.wait() )
        {
            if ( selector.isReady(server) )
            {
                sf::TcpSocket* newClient = new sf::TcpSocket;
                if ( server.accept(*newClient) == 0 )
                {
                    selector.add(*newClient);
                    clients.push_back(newClient);
                    if ( newClient->receive(clientPacket) == 0 )
                    {
                        int identifier = 0; // for testing
                        clientPacket << identifier; // for testing
                        for ( std::vector<sf::TcpSocket*>::iterator it = clients.begin(); it != clients.end(); it++ )
                        {
                            if ( newClient != *it ) // dont send to the sender of the packet
                            {
                                if ( (*it)->send(clientPacket) == 0 )
                                {
                                    qDebug() << "Sent";
                                }
                            }
                        }
                    }
                }
            }
        }
    }

heres the flow:
in the 2nd snippet, the new client will join the chat room successfully and it will send his/her name to the server
then in the 3rd snippet, the server will send the name of the new client to the other client so they will know who joins the chat room.
in the first snippet, the other client will receive the name of the new client.

heres whats happening when the program is run
in the 2nd snippet, a new client joins succesfully ( so no problem in 2nd snippet) and sends his/her name to the server ( no problem again )
in the 3rd snippet, server receives the name of the new client (so no problem again, i extracted the packet's content when i tested the program, it successfully receives the name)
in the first snippet, it receives the packet successfully (so no problem again) so the if statement will be  executed, if you can see the 
packet >> a >> name;
in the first snippet, i exctracted it to test if the packet's content is the content i expected, but when                 
qDebug() << QString::fromStdString(name);
qDebug() << a;
is executed, the output is not what i expected.
the output i expect is the name of the client and 0 (int)
but the output is both garbage values.
now im lost, i dont know if the packet is corrupt since im using tcpsocket it is not corrupted, so i dont know now.


EDIT: the server and client side are separate project.


10
Network / sf::SocketSelector::wait() bug
« on: November 15, 2015, 11:02:50 am »
ive been fixing this for few hours:

this first snippet should output "Test" if a client is attempting to connect to server or a client is sending a packet, but it doest output "Test"
void ServerManager::socketSignal()
{
    if ( selector.wait() )
    {
        qDebug() << "Test";
        if ( selector.isReady(server) )
        {
            acceptClient();
        }
        else
        {
            receiveAndSendPacket();
        }
    }
}

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ServerManager server;
    while(true)
    {
        server.socketSignal();
    }
}
 

when i do this:
it works
int main()
{
    while(true)
    if ( selector.wait( ) )
    {
        qDebug() << "test";
    }

}

i dont know whats happening.
in the first snippet i tested if socketSignal() is executing, and yes its executing.

11
Network / sending while the send is processing
« on: November 03, 2015, 10:38:25 am »
in a chat app, using tcpSocket what will happen if the previous message is still in the process of sending and the client sends a new message, does the new message will be disregard? or it will queue and wait until the previous message sent

can you answer it in nonblock and blocking mode ?

TIA

12
Network / sf::NonCopyable
« on: November 02, 2015, 03:41:10 am »
void acceptClient(sf::TcpListener& server)
{

}
int main()
{
    sf::TcpListener server;
   
    sf::Thread thread(&acceptClient,server); //'sf::NonCopyable::NonCopyable(const sf::NonCopyable&)' is private
}

is the only way to pass classes that inheirts sf::NonCopyable class is to pass it by pointer?

13
Network / server can only receive 1 message
« on: November 01, 2015, 07:17:56 am »
here is my server: http://pastebin.com/rSqupQBm
here is the client: http://pastebin.com/ncnfsMu3

server can only receive one message, after that the send function of the socket's client keeps returning sf::Socket::Disconnected

14
Network / tcpsocket send function 3rd argument
« on: November 01, 2015, 12:08:20 am »
I noticed the documentation of sf::TcpSocket in SFML 2.3.1, theres a
send (const void *data, std::size_t size, std::size_t &sent) function, tcpsocket guarantees all data it send will be sent successfully, so whats the sense of the 3rd parameter of this function?

15
Network / TcpListener
« on: October 29, 2015, 04:45:22 pm »
can someone explain me how the TcpListener socket is waiting a connection by this

sf::TcpListener server;
server.listen(5000); // listens on port 5000
sf::TcpSocket socket;
server.accept(socket); // how does the server wait by doing this and accept automatically when a tcpsocket is attempting to connect to port 5000

i just want to understand it




https://github.com/SFML/SFML/blob/master/examples/sockets/TCP.cpp
after i read this, i realized that i really did something wrong

Pages: [1] 2 3
anything