| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- /*
- * Copyright (c) 2014, Oculus VR, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- */
- // I tried to put most of the RakNet stuff here, but some of it had to go to CDemo.h too
- #ifndef __RAKNET_ADDITIONS_FOR_IRRLICHT_DEMO_H
- #define __RAKNET_ADDITIONS_FOR_IRRLICHT_DEMO_H
- #include "RakPeerInterface.h"
- #include "ReplicaManager3.h"
- #include "NatPunchthroughClient.h"
- #include "CloudClient.h"
- #include "FullyConnectedMesh2.h"
- #include "UDPProxyClient.h"
- #include "TCPInterface.h"
- #include "HTTPConnection.h"
- #include "../Samples/PHPDirectoryServer2/PHPDirectoryServer2.h"
- #include "vector3d.h"
- #include "IAnimatedMeshSceneNode.h"
- #include "MessageIdentifiers.h"
- class ReplicaManager3Irrlicht;
- class CDemo;
- class PlayerReplica;
- // All externs defined in the corresponding CPP file
- // Most of these classes has a manual entry, all of them have a demo
- extern RakNet::RakPeerInterface *rakPeer; // Basic communication
- extern RakNet::NetworkIDManager *networkIDManager; // Unique IDs per network object
- extern ReplicaManager3Irrlicht *replicaManager3; // Autoreplicate network objects
- extern RakNet::NatPunchthroughClient *natPunchthroughClient; // Connect peer to peer through routers
- extern RakNet::CloudClient *cloudClient; // Used to upload game instance to the cloud
- extern RakNet::FullyConnectedMesh2 *fullyConnectedMesh2; // Used to find out who is the session host
- extern PlayerReplica *playerReplica; // Network object that represents the player
- // A NAT punchthrough and proxy server Jenkins Software is hosting for free, should usually be online
- #define DEFAULT_NAT_PUNCHTHROUGH_FACILITATOR_PORT 61111
- #define DEFAULT_NAT_PUNCHTHROUGH_FACILITATOR_IP "natpunch.jenkinssoftware.com"
- void InstantiateRakNetClasses(void);
- void DeinitializeRakNetClasses(void);
- // Base RakNet custom classes for Replica Manager 3, setup peer to peer networking
- class BaseIrrlichtReplica : public RakNet::Replica3
- {
- public:
- BaseIrrlichtReplica();
- virtual ~BaseIrrlichtReplica();
- virtual RakNet::RM3ConstructionState QueryConstruction(RakNet::Connection_RM3 *destinationConnection, RakNet::ReplicaManager3 *replicaManager3) {return QueryConstruction_PeerToPeer(destinationConnection);}
- virtual bool QueryRemoteConstruction(RakNet::Connection_RM3 *sourceConnection) {return QueryRemoteConstruction_PeerToPeer(sourceConnection);}
- virtual void DeallocReplica(RakNet::Connection_RM3 *sourceConnection) {delete this;}
- virtual RakNet::RM3QuerySerializationResult QuerySerialization(RakNet::Connection_RM3 *destinationConnection) {return QuerySerialization_PeerToPeer(destinationConnection);}
- virtual void SerializeConstruction(RakNet::BitStream *constructionBitstream, RakNet::Connection_RM3 *destinationConnection);
- virtual bool DeserializeConstruction(RakNet::BitStream *constructionBitstream, RakNet::Connection_RM3 *sourceConnection);
- virtual RakNet::RM3SerializationResult Serialize(RakNet::SerializeParameters *serializeParameters);
- virtual void Deserialize(RakNet::DeserializeParameters *deserializeParameters);
- virtual void SerializeDestruction(RakNet::BitStream *destructionBitstream, RakNet::Connection_RM3 *destinationConnection) {}
- virtual bool DeserializeDestruction(RakNet::BitStream *destructionBitstream, RakNet::Connection_RM3 *sourceConnection) {return true;}
- virtual RakNet::RM3ActionOnPopConnection QueryActionOnPopConnection(RakNet::Connection_RM3 *droppedConnection) const {return QueryActionOnPopConnection_PeerToPeer(droppedConnection);}
- /// This function is not derived from Replica3, it's specific to this app
- /// Called from CDemo::UpdateRakNet
- virtual void Update(RakNet::TimeMS curTime);
- // Set when the object is constructed
- CDemo *demo;
- // real is written on the owner peer, read on the remote peer
- irr::core::vector3df position;
- RakNet::TimeMS creationTime;
- };
- // Game classes automatically updated by ReplicaManager3
- class PlayerReplica : public BaseIrrlichtReplica, irr::scene::IAnimationEndCallBack
- {
- public:
- PlayerReplica();
- virtual ~PlayerReplica();
- // Every function below, before Update overriding a function in Replica3
- virtual void WriteAllocationID(RakNet::Connection_RM3 *destinationConnection, RakNet::BitStream *allocationIdBitstream) const;
- virtual void SerializeConstruction(RakNet::BitStream *constructionBitstream, RakNet::Connection_RM3 *destinationConnection);
- virtual bool DeserializeConstruction(RakNet::BitStream *constructionBitstream, RakNet::Connection_RM3 *sourceConnection);
- virtual RakNet::RM3SerializationResult Serialize(RakNet::SerializeParameters *serializeParameters);
- virtual void Deserialize(RakNet::DeserializeParameters *deserializeParameters);
- virtual void PostDeserializeConstruction(RakNet::BitStream *constructionBitstream, RakNet::Connection_RM3 *destinationConnection);
- virtual void PreDestruction(RakNet::Connection_RM3 *sourceConnection);
- virtual void Update(RakNet::TimeMS curTime);
- void UpdateAnimation(irr::scene::EMD2_ANIMATION_TYPE anim);
- float GetRotationDifference(float r1, float r2);
- virtual void OnAnimationEnd(irr::scene::IAnimatedMeshSceneNode* node);
- void PlayAttackAnimation(void);
- // playerName is only sent in SerializeConstruction, since it doesn't change
- RakNet::RakString playerName;
- // Networked rotation
- float rotationAroundYAxis;
- // Interpolation variables, not networked
- irr::core::vector3df positionDeltaPerMS;
- float rotationDeltaPerMS;
- RakNet::TimeMS interpEndTime, lastUpdate;
- // Updated based on the keypresses, to control remote animation
- bool isMoving;
- // Only instantiated for remote systems, you never see yourself
- irr::scene::IAnimatedMeshSceneNode* model;
- irr::scene::EMD2_ANIMATION_TYPE curAnim;
- // deathTimeout is set from the local player
- RakNet::TimeMS deathTimeout;
- bool IsDead(void) const;
- // isDead is set from network packets for remote players
- bool isDead;
- // List of all players, including our own
- static DataStructures::List<PlayerReplica*> playerList;
- };
- class BallReplica : public BaseIrrlichtReplica
- {
- public:
- BallReplica();
- virtual ~BallReplica();
- // Every function except update is overriding a function in Replica3
- virtual void WriteAllocationID(RakNet::Connection_RM3 *destinationConnection, RakNet::BitStream *allocationIdBitstream) const;
- virtual void SerializeConstruction(RakNet::BitStream *constructionBitstream, RakNet::Connection_RM3 *destinationConnection);
- virtual bool DeserializeConstruction(RakNet::BitStream *constructionBitstream, RakNet::Connection_RM3 *sourceConnection);
- virtual RakNet::RM3SerializationResult Serialize(RakNet::SerializeParameters *serializeParameters);
- virtual void Deserialize(RakNet::DeserializeParameters *deserializeParameters);
- virtual void PostDeserializeConstruction(RakNet::BitStream *constructionBitstream, RakNet::Connection_RM3 *destinationConnection);
- virtual void PreDestruction(RakNet::Connection_RM3 *sourceConnection);
- virtual void Update(RakNet::TimeMS curTime);
- // shotDirection is networked
- irr::core::vector3df shotDirection;
- // shotlifetime is calculated, not networked
- RakNet::TimeMS shotLifetime;
- };
- class Connection_RM3Irrlicht : public RakNet::Connection_RM3 {
- public:
- Connection_RM3Irrlicht(const RakNet::SystemAddress &_systemAddress, RakNet::RakNetGUID _guid, CDemo *_demo) : RakNet::Connection_RM3(_systemAddress, _guid) {demo=_demo;}
- virtual ~Connection_RM3Irrlicht() {}
- virtual RakNet::Replica3 *AllocReplica(RakNet::BitStream *allocationId, RakNet::ReplicaManager3 *replicaManager3);
- protected:
- CDemo *demo;
- };
- class ReplicaManager3Irrlicht : public RakNet::ReplicaManager3
- {
- public:
- virtual RakNet::Connection_RM3* AllocConnection(const RakNet::SystemAddress &systemAddress, RakNet::RakNetGUID rakNetGUID) const {
- return new Connection_RM3Irrlicht(systemAddress,rakNetGUID,demo);
- }
- virtual void DeallocConnection(RakNet::Connection_RM3 *connection) const {
- delete connection;
- }
- CDemo *demo;
- };
- #endif
|