Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
SFML Game Development.pdf
Скачиваний:
194
Добавлен:
28.03.2016
Размер:
4.19 Mб
Скачать

Company Atop the Clouds – Co-op Multiplayer

This is as easy as it gets. You should notice the use of the operator <<. SFML implemented it to make it more simple and readable, allowing to chain many items in a single line, all being packed correctly within sf::Packet.

Then, on the other end of the network, the following code shows to unpack that same data:

sf::Packet packet; std::string myString; sf::Int32 myNumber; sf::Int8 myNumber2; mySocket.receive(packet);

packet >> myString >> myNumber >> myNumber2;

Easy enough, isn't it? Now we know to use sockets, send and receive data; but how do we know what data are we reading? An application will most likely want to act differently upon receiving different packets, right? This is where it comes handy to implement a custom protocol—a way to understand what the data really is for and what to do with it.

Network architectures

Regardless of socket types and protocols, games take different approaches in the architecture of the multiplayer mode.

We call the playable game application a client, network-wise, and this part of the book concerns how clients communicate with each other and who they communicate with.

There are at least two major approaches to a networked simulation.

Peer-to-peer

This architecture was and still is used in online games; however, it fits a very specific set of purposes and is used less widely than its counterpart client-server architecture.

Nevertheless, its importance should be noticed and mentioned every time networking is the topic. What defines this architecture is essentially the fact that every game client in the simulation connects to each other. You can see it in the following figure:

[ 242 ]

www.it-ebooks.info

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]