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

Pages: [1]
1
Audio / Sound randomly stops playing
« on: October 18, 2016, 01:20:30 am »
Hi, I think I found the problem of sfml sounds or something with what...
Lets say, I have explosion1..5.wav sounds which's length is 4seconds.

In example:
I have the sound buffer array with 5 elements
Then, I have another array of the objects(classes), with sf::Sound variable...
Every sf::Sound has its own buffer

Now, the intresting part:
For the first object i writing sounds[0].play()... Then - "Sleep(3000)"
And then next object starting to play... But only 1sec... Not 4 as it should... Why ?
The sound randomly stops and that's it...

The sequence:
sound[0].play(); (4s of the explosion sound...)
Sleep(3000) (1s left of playing sound for sound[0])
sound[1].play(); (4s of the explosion sound...)
<sound[1] stops after 1 second>
Sleep(3000) (randomly 2 seconds of "nothing")
sound[2].play();
Sleep(3000) (again everything is good, 1s left for sound[2])
sound[3].play() (again, sound[3] stops after 1 second...)

Why this is happening? How to fix that?

2
Network / Re: Client->Server->Clients
« on: June 03, 2014, 01:01:39 am »
main.cpp:
std::string MyName, IP = "xx.xx.xx.xx";
sf::TcpSocket Client;
cout << "Tipe your name: ";
cin >> MyName;
Client.connect(IP, xxxx);
vector<PLAYER> Players;

Client.setBlocking(false);
sf::Packet Packet;
PLAYER MainPlayer;
MainPlayer.SetName(MyName);
Players.push_back(MainPlayer);
Packet << Players[0].GetPosition().x << Players[0].GetPosition().y << Players[0].GetPlayerName();
Client.send(Packet);

float xCord = Players[0].GetLastCoordiantes().x, yCord = Players[0].GetLastCoordiantes().y;

while (GameWindow.isOpen())
{
sf::Packet GetPacket;
float PosX, PosY;
string Name;
Client.receive(GetPacket);
if (GetPacket >> PosX >> PosY >> Name)
{
cout << "Player Name: " << Name << " x:" << PosX << " y:" << PosY << endl;
}

if (Players[0].GetPosition().x != xCord || Players[0].GetPosition().y != yCord)
{
sf::Packet SendPacket;
SendPacket << Players[0].GetPosition().x << Players[0].GetPosition().y << Players[0].GetPlayerName();
Client.send(SendPacket);
}
xCord = Players[0].GetLastCoordiantes().x, yCord = Players[0].GetLastCoordiantes().y;

Players[0].Draw(GameWindow);
GameWindow.display();
GameWindow.clear();

}
 

I need to draw new clients, but how I should do this ?

3
Network / Client->Server->Clients
« on: June 02, 2014, 11:26:03 pm »
Hi, I need some help. I have server which can hold multiple clients. One client sends info to the server and server sends that info to the other clients (coordinates, name).. But the problem is that client can't see other clients on the map.. And I dont know how to do that... Can you help me a bit ?

server:
#include<SFML/Graphics.hpp>
#include<SFML/Network.hpp>
#include<string>
#include<iostream>
#include<conio.h>
#include<vector>
int main()
{
        std::cout << "Server Running" << std::endl;
        sf::TcpListener listener;
        sf::SocketSelector selector;
        std::vector<sf::TcpSocket*> clients;
        listener.listen(2000);
        selector.add(listener);

        while (1)
        {
                if (selector.wait())
                {
                        if (selector.isReady(listener))
                        {
                                sf::TcpSocket *socket = new sf::TcpSocket;
                                listener.accept(*socket);
                                sf::Packet packet;
                                std::string Name;
                                float xCoord, yCoord;

                                if (socket->receive(packet) == sf::Socket::Done) packet >> xCoord >> yCoord >> Name;
                                std::cout << Name << " has connected to the chat room (x:" << xCoord << ", y:" << yCoord << ")" << std::endl;

                                clients.push_back(socket);
                                selector.add(*socket);
                        }
                        else
                        {
                                for (int i = 0; i < clients.size(); i++)
                                {
                                        if (selector.isReady(*clients[i]))
                                        {
                                                sf::Packet packet, sendPacket;
                                                if (clients[i]->receive(packet) == sf::Socket::Done)
                                                {
                                                        float PosX, PosY;
                                                        std::string Name;
                                                        packet >> PosX >> PosY >> Name;
                                                        sendPacket << PosX << PosY << Name;

                                                        std::cout << "[" << Name << "]" << "[x:" << PosX << "]" << "[y:" << PosY << "]" << endl;

                                                        for (int j = 0; j < clients.size(); j++)
                                                        {
                                                                if (i != j)
                                                                {
                                                                        clients[j]->send(sendPacket);
                                                                }
                                                        }
                                                }
                                        }
                                }
                        }
                }
        }

        for (std::vector<sf::TcpSocket*>::iterator it = clients.begin(); it != clients.end(); it++)
                delete *it;

        return 0;
}

Pages: [1]