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

Pages: [1] 2
1
General / Re: [CMake]Could NOT find SFML
« on: June 23, 2016, 10:44:06 pm »
Can anyone help me, please? :(

2
General / Re: [CMake]Could NOT find SFML
« on: June 23, 2016, 05:40:37 pm »
Oh! My bad, sorry!
Quote
find_package(SFML 2 COMPONENTS system window graphics network audio)


Hm... But my problem still actual:
Quote
18:56:56: Выполняются этапы для проекта ECS_GameEngine...
18:56:56: Запускается: «/usr/bin/cmake» --build . --target all
Linking CXX executable /home/saitei/Projects/ECS_GameEngine/bin/ECS_GameEngine
CMakeFiles/ECS_GameEngine.dir/main.cpp.o: In function `main':
main.cpp:(.text.startup+0x4b): undefined reference to `sf::String::String(char const*, std::locale const&)'
main.cpp:(.text.startup+0x64): undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
main.cpp:(.text.startup+0x87): undefined reference to `sf::Window::Window(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
main.cpp:(.text.startup+0xae): undefined reference to `sf::Window::isOpen() const'
main.cpp:(.text.startup+0xd3): undefined reference to `sf::Window::pollEvent(sf::Event&)'
main.cpp:(.text.startup+0xe1): undefined reference to `sf::Window::display()'
main.cpp:(.text.startup+0xf6): undefined reference to `sf::Window::close()'
main.cpp:(.text.startup+0x102): undefined reference to `sf::Window::~Window()'
main.cpp:(.text.startup+0x13d): undefined reference to `sf::Window::~Window()'
collect2: error: ld returned 1 exit status
make[2]: *** [/home/saitei/Projects/ECS_GameEngine/bin/ECS_GameEngine] Error 1
make[1]: *** [CMakeFiles/ECS_GameEngine.dir/all] Error 2
make: *** [all] Error 2
18:56:56: Процесс «/usr/bin/cmake» завершился с кодом 2.
Ошибка при сборке/установке проекта ECS_GameEngine (комплект: Desktop Qt 5.6.0 GCC 64bit)
Во время выполнения этапа «Сборка»
18:56:56: Прошло времени: 00:00.

#include <SFML/Graphics.hpp>

int main(int argc, char* argv[])
{
  sf::Window App(sf::VideoMode(800, 600), "myproject");

  while (App.isOpen())
  {
    sf::Event Event;
    while (App.pollEvent(Event))
    {
      if (Event.type == sf::Event::Closed)
        App.close();
    }
    App.display();
  }

Quote
cmake_minimum_required(VERSION 2.8)
project(ECS_GameEngine)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")

set(SRC_LIST ${SRC_LIST} main.cpp entity.h component.cpp system.cpp channel.cpp
    gamestate.h engine.h)
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

set(SFML_ROOT "${CMAKE_BINARY_DIR}/deps/SFML-2.3.2")
set(SFML_STATIC_LIBRARIES TRUE)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_BINARY_DIR}/deps/SFML-2.3.2/cmake/Modules")
find_package(SFML 2 COMPONENTS system window graphics network audio)

include_directories(${SFML_INCLUDE_DIR})
add_executable(${PROJECT_NAME} ${SRC_LIST})
target_link_libraries(${PROJECT_NAME} ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})

3
General / [CMake]Could NOT find SFML
« on: June 23, 2016, 05:39:17 pm »
Quote
cmake_minimum_required(VERSION 2.8)
project(ECS_GameEngine)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")

#aux_source_directory(. SRC_LIST)
set(SRC_LIST ${SRC_LIST} main.cpp entity.h component.cpp system.cpp channel.cpp
    gamestate.h engine.h)
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

add_executable(${PROJECT_NAME} ${SRC_LIST})

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_BINARY_DIR}/deps/SFML-2.3.2/cmake/Modules")
set(SFML_ROOT "${CMAKE_BINARY_DIR}/deps/SFML-2.3.2")
set(SFML_STATIC_LIBRARIES TRUE)
find_package(SFML 2 REQUIRED system window graphics network audio)

if(SFML_FOUND)
  include_directories(${SFML_INCLUDE_DIR})
  target_link_libraries(${PROJECT_NAME} ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
endif()

Also I install the following libraries:
Quote
sudo apt-get install libpthread-stubs0-dev
sudo apt-get install libgl1-mesa-dev
sudo apt-get install libx11-dev
sudo apt-get install libxrandr-dev
sudo apt-get install libfreetype6-dev
sudo apt-get install libglew1.5-dev
sudo apt-get install libjpeg8-dev
sudo apt-get install libsndfile1-dev
sudo apt-get install libopenal-dev
sudo apt-get install cmake
sudo apt-get install g++

Error:
Quote
/home/saitei/Projects/ECS_GameEngine/deps/SFML-2.3.2/cmake/Modules/FindSFML.cmake:358: ошибка: Could NOT find SFML (missing: SFML_SYSTEM_LIBRARY SFML_WINDOW_LIBRARY SFML_GRAPHICS_LIBRARY SFML_NETWORK_LIBRARY SFML_AUDIO_LIBRARY) CMakeLists.txt:23 (find_package)


How can I fix this problem?

4
Network / Re: Many TCP connections?
« on: August 26, 2014, 11:28:33 pm »
Do yourself a favor and forget about threads...
Неа, не забуду. Я обдумал свои ошибки и наконец-то создал более-менее оправданную архитектуру адаптивного многопоточного сервера.

I do not forget them.

5
Network / Re: Many TCP connections?
« on: August 26, 2014, 11:12:35 pm »
sf::TcpListener/sf::TcpSocket is a thread-safe?

6
Network / Re: Many TCP connections?
« on: August 25, 2014, 12:44:01 pm »
Thanks!

oh... It is possible use TCP and UDP together?

7
Network / Re: Many TCP connections?
« on: August 24, 2014, 05:58:56 pm »
Oh! Thank you very much! Thanks to you, I realized how lousy server I wrote. Incidentally, I came up with a multithreaded server architecture ... I'll rewrite it.





Is it possible to send and receive packets at the same time? And what is meant by "blocking socket"?

8
Network / Re: Many TCP connections?
« on: August 23, 2014, 10:17:27 pm »
  • Forget multithreading, you failed at it miserably
  • You entirely used mutexts wrong
  • None of your concurrently accessed varibles are protected
  • Learn how memory management works in C++, you failed again with a memory leak
  • 'using' statements at header level aren't good ideas
  • Probably other things are wrong, you should really just stick to a single threaded server as already mentioned
You can paint detail my mistakes? I would be very grateful

9
Network / Re: Many TCP connections?
« on: August 23, 2014, 09:52:26 pm »
It is a bad server?
#include <iostream>
#include <thread>
#include <mutex>
#include <unordered_map>
#include <SFML/Network.hpp>
using namespace std;

typedef sf::Uint8 PacketType;
const PacketType MSG = 0;


const unsigned short PORT = 5000;
typedef std::unordered_map<sf::TcpSocket *, std::string> Clients;
Clients clients;
sf::TcpListener listner;
mutex sMutex;
bool ServerWorks = true;

void CheckConnectionsThr()
{
        sMutex.lock();
        cout<<"Thread \"CheckConnectionsThr\" started"<<endl;
        sMutex.unlock();

        sf::TcpSocket* nextClient = nullptr;
        while(ServerWorks)
        {
                if(nextClient == nullptr)
                {
                        sMutex.lock();
                        nextClient = new sf::TcpSocket;
                        sMutex.unlock();

                        nextClient->setBlocking(false);
                }
                if(listner.accept(*nextClient) == sf::Socket::Done)
                {
                        clients.insert(std::make_pair(nextClient, ""));
                        nextClient = nullptr;
                }
        }
}

void BroadCast(PacketType type, std::string& msg)
{
        for(Clients::iterator it=clients.begin(); it!=clients.end(); ++it)
        {
                sf::Packet pack;
                pack<<type<<msg;
                it->first->send(pack);
        }
}

void HandlePacketsThr()
{
       
        sMutex.lock();
        cout<<"Thread \"HandlePacketsThr\" started"<<endl;
        sMutex.unlock();
        while(ServerWorks)
        {
                for(Clients::iterator it=clients.begin(); it!=clients.end();)
                {
                        sf::Packet packet;
                        sf::Socket::Status status=it->first->receive(packet);
                        switch(status)
                        {
                                case sf::Socket::Done:
                                {
                                        PacketType type;
                                        packet >> type;
                                        if(type == MSG)
                                        {
                                                std::string msg;
                                                packet>>msg;
                                                sMutex.lock();
                                                cout<<msg<<endl;
                                                BroadCast(MSG,msg);
                                                sMutex.unlock();
                                        }
                                        ++it;
                                        break;
                                }
                                case sf::Socket::Disconnected:
                                {
                                        sMutex.lock();
                                        cout<<it->second<<" has been disconnected"<<endl;
                                        BroadCast(MSG, it->second+" has been disconnected\n");
                                        sMutex.unlock();
                                        it=clients.erase(it);
                                        break;
                                }
                                default:
                                {
                                        ++it;
                                }
                        }
                }
        }
}

int main()
{
        listner.listen(PORT);
        listner.setBlocking(false);
        cout<<"Starting the server..."<<endl;
        cout<<"Port:"<<PORT<<endl;
        thread checkConnectionsThr(CheckConnectionsThr);
        thread packetHandlerThr(HandlePacketsThr);
        checkConnectionsThr.detach();
        packetHandlerThr.detach();
        while(ServerWorks)
        {
                std::string s;
                cin>>s;
                if(s=="exit")
                {
                        ServerWorks = false;
                }
                else if(!s.empty())
                {
                        sMutex.lock();
                        BroadCast(MSG,s);
                        cout<<s<<endl;
                        sMutex.unlock();
                }
        }
        return EXIT_SUCCESS;
}

P.S: it's my code (but some peace i founded at the github). Now I'm going to create client...

10
Network / Re: Many TCP connections?
« on: August 23, 2014, 07:59:43 pm »
Quote
Since I'm trying to write a chat room for N users, my server must be able to communicate with different clients on TCP. As planned, I was trying to do thread "CheckConnectionsThr": but i really do not understand how to support multiple TCP connections. I would like to allocate stream to each client...
The documentation of sf::SocketSelector shows how to accept multiple connections and then manage one socket per client in a selector.

Quote
But... How do I know what socket finished receiving information?
Have you read the tutorial and documentation? It's clearly explained, with examples.

I don't know what else to say. We can't teach you how networking works, only how to do it with SFML, and the documentation / tutorials already cover that quite well. You may need to read more articles about generic networking, that explain the concepts of sockets, selectors, etc. before you try to implement something with SFML.
But nothing about threads for server

11
Network / Re: Many TCP connections?
« on: August 23, 2014, 06:50:11 pm »
Quote
>>>Once connected, a TCP socket can only send and receive to/from the connected socket. So you'll need one TCP >>>socket for each client in your application.
This means that one and the same socket works for all clients? Oh... Still, I think in Russian and there are problems with the translation...

12
Network / Re: Many TCP connections?
« on: August 23, 2014, 06:39:53 pm »
Quote
1)I do not know how to create a lot of TCP connections in many threads.
You'll have to be more specific about what your problem is, not what you think you need to solve it.
Okay, I will try to describe the problem more formally...
I had read that
Quote
Once connected, a TCP socket can only send and receive to/from the connected socket. So you'll need one TCP socket for each client in your application.

Since I'm trying to write a chat room for N users, my server must be able to communicate with different clients on TCP. As planned, I was trying to do thread "CheckConnectionsThr": but i really do not understand how to support multiple TCP connections. I would like to allocate stream to each client...

Quote
// the selector will tell you which socket has received data, and you can call "receive" on it directly
But... How do I know what socket finished receiving information?

If it's still not clear then play with a server that accepts more than 1 client. You'll understand the problem quickly ;)
...I'm trying to create a server for more than 1 clients... And I got confused with the TCP.. With 1 client no problems.

13
Network / Many TCP connections?
« on: August 23, 2014, 05:40:28 pm »
I tried to understand the SFML network and I'm making some progress.
It seems to be good, but there were problems:
1)I do not know how to create a lot of TCP connections in many threads.
2)I do not understand what is sf::SocketSelector (many times re-read the documentation, but could not understand the essence.)

Honestly, I used the search and read other people's posts ... My level of English is not good enough to understand everything 100% ... 

14
Graphics / Re: RenderTarget - Multiply mode?
« on: August 20, 2014, 01:31:49 pm »
The documentation is your friend. ;D

http://sfml-dev.org/documentation/2.1/classsf_1_1RenderTarget.php#a12417a3bcc245c41d957b29583556f39
http://sfml-dev.org/documentation/2.1/classsf_1_1RenderStates.php#ad29672df29f19ce50c3021d95f2bb062
http://sfml-dev.org/documentation/2.1/group__graphics.php#ga80c52fe2f7050d7f7573b7ed3c995388

Also this forum has a search, I'm 100% certain you'd have found an answer that way as well.
When i call method "draw" at RenderTexture - all draws at the texture, when i call method "draw" at RenderWindow - all draw at the window - do I understand correctly?

If it is thanks for the help!

15
Graphics / Re: RenderTarget - Multiply mode?
« on: August 20, 2014, 10:50:50 am »
The same way as with a RenderWindow, by applying blend modes.

Also use the edit function if you want to add something and nobody has replied yet.
Sorry, more of this will not happen again.

Also, I founded sf::BlendMode::BlendMultiply... But I do not understand how to use it.
I want draw my rendertarget over the window with multiply mode. Sprites already drawed at the window, render target ready too.



Pages: [1] 2