Threaded the barriers through the networking system
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "barrier_packet.hpp"
|
||||
|
||||
#include "serial_utility.hpp"
|
||||
|
||||
void serializeBarrier(void* buffer, BarrierPacket* packet) {
|
||||
serialCopy(&buffer, &packet->type, sizeof(SerialPacketType));
|
||||
|
||||
//identify the barrier
|
||||
serialCopy(&buffer, &packet->barrierIndex, sizeof(int));
|
||||
|
||||
//bounds
|
||||
serialCopy(&buffer, &packet->bounds.x, sizeof(int));
|
||||
serialCopy(&buffer, &packet->bounds.y, sizeof(int));
|
||||
serialCopy(&buffer, &packet->bounds.w, sizeof(int));
|
||||
serialCopy(&buffer, &packet->bounds.h, sizeof(int));
|
||||
|
||||
|
||||
//location
|
||||
serialCopy(&buffer, &packet->roomIndex, sizeof(int));
|
||||
serialCopy(&buffer, &packet->origin.x, sizeof(double));
|
||||
serialCopy(&buffer, &packet->origin.y, sizeof(double));
|
||||
serialCopy(&buffer, &packet->motion.x, sizeof(double));
|
||||
serialCopy(&buffer, &packet->motion.y, sizeof(double));
|
||||
|
||||
//graphical data
|
||||
for (int i = 0; i < 8; i++) {
|
||||
serialCopy(&buffer, &packet->status[i], sizeof(int));
|
||||
}
|
||||
}
|
||||
|
||||
void deserializeBarrier(void* buffer, BarrierPacket* packet) {
|
||||
deserialCopy(&buffer, &packet->type, sizeof(SerialPacketType));
|
||||
|
||||
//identify the barrier
|
||||
deserialCopy(&buffer, &packet->barrierIndex, sizeof(int));
|
||||
|
||||
//bounds
|
||||
deserialCopy(&buffer, &packet->bounds.x, sizeof(int));
|
||||
deserialCopy(&buffer, &packet->bounds.y, sizeof(int));
|
||||
deserialCopy(&buffer, &packet->bounds.w, sizeof(int));
|
||||
deserialCopy(&buffer, &packet->bounds.h, sizeof(int));
|
||||
|
||||
|
||||
//location
|
||||
deserialCopy(&buffer, &packet->roomIndex, sizeof(int));
|
||||
deserialCopy(&buffer, &packet->origin.x, sizeof(double));
|
||||
deserialCopy(&buffer, &packet->origin.y, sizeof(double));
|
||||
deserialCopy(&buffer, &packet->motion.x, sizeof(double));
|
||||
deserialCopy(&buffer, &packet->motion.y, sizeof(double));
|
||||
|
||||
//graphical data
|
||||
for (int i = 0; i < 8; i++) {
|
||||
deserialCopy(&buffer, &packet->status[i], sizeof(int));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "serial_packet_base.hpp"
|
||||
|
||||
#include "bounding_box.hpp"
|
||||
#include "vector2.hpp"
|
||||
|
||||
struct BarrierPacket : SerialPacketBase {
|
||||
//identify the barrier
|
||||
int barrierIndex;
|
||||
BoundingBox bounds;
|
||||
|
||||
//location
|
||||
int roomIndex;
|
||||
Vector2 origin;
|
||||
Vector2 motion;
|
||||
|
||||
//graphical data: 0 blank, 1 green, 2 red
|
||||
int status[8];
|
||||
};
|
||||
|
||||
void serializeBarrier(void* buffer, BarrierPacket* packet);
|
||||
void deserializeBarrier(void* buffer, BarrierPacket* packet);
|
||||
@@ -22,6 +22,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "serial_packet_base.hpp"
|
||||
#include "barrier_packet.hpp"
|
||||
#include "character_packet.hpp"
|
||||
#include "client_packet.hpp"
|
||||
#include "creature_packet.hpp"
|
||||
|
||||
@@ -142,6 +142,20 @@ enum class SerialPacketType {
|
||||
|
||||
FORMAT_END_CREATURE = 599,
|
||||
|
||||
//-------------------------
|
||||
//BarrierPacket
|
||||
// barrier index,
|
||||
// bounds,
|
||||
// roomIndex, origin, motion
|
||||
// status
|
||||
//-------------------------
|
||||
|
||||
FORMAT_COMBAT = 700,
|
||||
|
||||
BARRIER_UPDATE = 701,
|
||||
|
||||
FORMAT_END_COMBAT = 799,
|
||||
|
||||
//-------------------------
|
||||
//TextPacket
|
||||
// name, text
|
||||
@@ -169,5 +183,5 @@ enum class SerialPacketType {
|
||||
//not used
|
||||
//-------------------------
|
||||
|
||||
LAST = 700
|
||||
LAST = 800
|
||||
};
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "serial_utility.hpp"
|
||||
|
||||
//packet types
|
||||
#include "barrier_packet.hpp"
|
||||
#include "character_packet.hpp"
|
||||
#include "client_packet.hpp"
|
||||
#include "creature_packet.hpp"
|
||||
@@ -69,6 +70,10 @@ void serializePacket(void* buffer, SerialPacketBase* packet) {
|
||||
serializeCreature(buffer, static_cast<CreaturePacket*>(packet));
|
||||
}
|
||||
|
||||
if (BOUNDS(packet->type, SerialPacketType::FORMAT_COMBAT, SerialPacketType::FORMAT_END_COMBAT)) {
|
||||
serializeBarrier(buffer, static_cast<BarrierPacket*>(packet));
|
||||
}
|
||||
|
||||
if (BOUNDS(packet->type, SerialPacketType::FORMAT_TEXT, SerialPacketType::FORMAT_END_TEXT)) {
|
||||
serializeText(buffer, static_cast<TextPacket*>(packet));
|
||||
}
|
||||
@@ -99,6 +104,10 @@ void deserializePacket(void* buffer, SerialPacketBase* packet) {
|
||||
deserializeCreature(buffer, static_cast<CreaturePacket*>(packet));
|
||||
}
|
||||
|
||||
if (BOUNDS(type, SerialPacketType::FORMAT_COMBAT, SerialPacketType::FORMAT_END_COMBAT)) {
|
||||
deserializeBarrier(buffer, static_cast<BarrierPacket*>(packet));
|
||||
}
|
||||
|
||||
if (BOUNDS(type, SerialPacketType::FORMAT_TEXT, SerialPacketType::FORMAT_END_TEXT)) {
|
||||
deserializeText(buffer, static_cast<TextPacket*>(packet));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user