资源简介

多人网络开发技术,有利于游戏开发的童鞋们了解多人网络后台开发技术

资源截图

代码片段和文件信息

#include “RoboCatPCH.h“

shared_ptr< Command > Command::StaticReadAndCreate( InputMemoryBitStream& inInputStream )
{
CommandPtr retVal;

int type = CM_INVALID;
inInputStream.Read( type );
uint32_t networkId = 0;
inInputStream.Read( networkId );
uint64_t playerId = 0;
inInputStream.Read( playerId );

switch ( type )
{
case CM_ATTACK:
retVal = std::make_shared< AttackCommand >();
retVal->mNetworkId = networkId;
retVal->mPlayerId = playerId;
retVal->Read( inInputStream );
break;
case CM_MOVE:
retVal = std::make_shared< MoveCommand >();
retVal->mNetworkId = networkId;
retVal->mPlayerId = playerId;
retVal->Read( inInputStream );
break;
default:
LOG( “Read in an unknown command type??“ );
break;
}

return retVal;
}

void Command::Write( OutputMemoryBitStream& inOutputStream )
{
inOutputStream.Write( mCommandType );
inOutputStream.Write( mNetworkId );
inOutputStream.Write( mPlayerId );
}

AttackCommandPtr AttackCommand::StaticCreate( uint32_t inMyNetId uint32_t inTargetNetId )
{
AttackCommandPtr retVal;
GameobjectPtr me = NetworkManager::sInstance->GetGameobject( inMyNetId );
GameobjectPtr target = NetworkManager::sInstance->GetGameobject( inTargetNetId );
uint64_t playerId = NetworkManager::sInstance->GetMyPlayerId();
//can only issue commands to this unit if I own it and it‘s a cat
//and if the target is a cat that‘s on a different team
if ( me && me->GetClassId() == RoboCat::kClassId &&
me->GetPlayerId() ==  playerId &&
target && target->GetClassId() == RoboCat::kClassId &&
target->GetPlayerId() != me->GetPlayerId() )
{
retVal = std::make_shared< AttackCommand >();
retVal->mNetworkId = inMyNetId;
retVal->mPlayerId = playerId;
retVal->mTargetNetId = inTargetNetId;
}
return retVal;
}

void AttackCommand::Write( OutputMemoryBitStream& inOutputStream )
{
Command::Write( inOutputStream );
inOutputStream.Write( mTargetNetId );
}

void AttackCommand::Read( InputMemoryBitStream& inInputStream )
{
inInputStream.Read( mTargetNetId );
}

void AttackCommand::ProcessCommand()
{
GameobjectPtr obj = NetworkManager::sInstance->GetGameobject( mNetworkId );
if ( obj && obj->GetClassId() == RoboCat::kClassId &&
obj->GetPlayerId() == mPlayerId )
{
RoboCat* rc = obj->GetAsCat();
rc->EnterAttackState( mTargetNetId );
}
}

MoveCommandPtr MoveCommand::StaticCreate( uint32_t inNetworkId const Vector3& inTarget )
{
MoveCommandPtr retVal;
GameobjectPtr go = NetworkManager::sInstance->GetGameobject( inNetworkId );
uint64_t playerId = NetworkManager::sInstance->GetMyPlayerId();

//can only issue commands to this unit if I own it and it‘s a cat
if ( go && go->GetClassId() == RoboCat::kClassId && 
go->GetPlayerId() == playerId )
{
retVal = std::make_shared< MoveCommand >();
retVal->mNetworkId = inNetworkId;
retVal->mPlayerId = playerId;
retVal->mTarget = inTarget;
}
return retVal;
}

void MoveCommand::Write( OutputMemoryBitStream& inOutputStream )
{
Command::Write( inOutputStream

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        129  2017-08-19 21:31  多人网络\MultiplayerBook-master\.gitignore

     文件      14328  2017-08-19 21:31  多人网络\MultiplayerBook-master\Chapter 12\RoboCatRTS\Assets\8-BIT WONDER.TTF

     文件       2244  2017-08-19 21:31  多人网络\MultiplayerBook-master\Chapter 12\RoboCatRTS\Assets\8-BITWONDER-README.TXT

     文件        270  2017-08-19 21:31  多人网络\MultiplayerBook-master\Chapter 12\RoboCatRTS\Assets\Art-README.txt

     文件       4250  2017-08-19 21:31  多人网络\MultiplayerBook-master\Chapter 12\RoboCatRTS\Assets\Carlito-Regular-README.TXT

     文件     635996  2017-08-19 21:31  多人网络\MultiplayerBook-master\Chapter 12\RoboCatRTS\Assets\Carlito-Regular.ttf

     文件      22829  2017-08-19 21:31  多人网络\MultiplayerBook-master\Chapter 12\RoboCatRTS\Assets\cat.png

     文件       8669  2017-08-19 21:31  多人网络\MultiplayerBook-master\Chapter 12\RoboCatRTS\Assets\mouse.png

     文件          3  2017-08-19 21:31  多人网络\MultiplayerBook-master\Chapter 12\RoboCatRTS\Assets\steam_appid.txt

     文件      13543  2017-08-19 21:31  多人网络\MultiplayerBook-master\Chapter 12\RoboCatRTS\Assets\yarn.png

     文件          3  2017-08-19 21:31  多人网络\MultiplayerBook-master\Chapter 12\RoboCatRTS\Debug\steam_appid.txt

     文件          3  2017-08-19 21:31  多人网络\MultiplayerBook-master\Chapter 12\RoboCatRTS\Release\steam_appid.txt

     文件        215  2017-08-19 21:31  多人网络\MultiplayerBook-master\Chapter 12\RoboCatRTS\RoboCatRTS\Inc\Achieve.def

     文件       1786  2017-08-19 21:31  多人网络\MultiplayerBook-master\Chapter 12\RoboCatRTS\RoboCatRTS\Inc\Command.h

     文件        424  2017-08-19 21:31  多人网络\MultiplayerBook-master\Chapter 12\RoboCatRTS\RoboCatRTS\Inc\CommandList.h

     文件        434  2017-08-19 21:31  多人网络\MultiplayerBook-master\Chapter 12\RoboCatRTS\RoboCatRTS\Inc\Engine.h

     文件       2418  2017-08-19 21:31  多人网络\MultiplayerBook-master\Chapter 12\RoboCatRTS\RoboCatRTS\Inc\Gameobject.h

     文件        465  2017-08-19 21:31  多人网络\MultiplayerBook-master\Chapter 12\RoboCatRTS\RoboCatRTS\Inc\GameobjectRegistry.h

     文件       2352  2017-08-19 21:31  多人网络\MultiplayerBook-master\Chapter 12\RoboCatRTS\RoboCatRTS\Inc\GamerServices.h

     文件        383  2017-08-19 21:31  多人网络\MultiplayerBook-master\Chapter 12\RoboCatRTS\RoboCatRTS\Inc\GraphicsDriver.h

     文件        761  2017-08-19 21:31  多人网络\MultiplayerBook-master\Chapter 12\RoboCatRTS\RoboCatRTS\Inc\HUD.h

     文件         65  2017-08-19 21:31  多人网络\MultiplayerBook-master\Chapter 12\RoboCatRTS\RoboCatRTS\Inc\InputAction.h

     文件        578  2017-08-19 21:31  多人网络\MultiplayerBook-master\Chapter 12\RoboCatRTS\RoboCatRTS\Inc\InputManager.h

     文件        271  2017-08-19 21:31  多人网络\MultiplayerBook-master\Chapter 12\RoboCatRTS\RoboCatRTS\Inc\Leaderboards.def

     文件       4617  2017-08-19 21:31  多人网络\MultiplayerBook-master\Chapter 12\RoboCatRTS\RoboCatRTS\Inc\MemoryBitStream.h

     文件       5136  2017-08-19 21:31  多人网络\MultiplayerBook-master\Chapter 12\RoboCatRTS\RoboCatRTS\Inc\NetworkManager.h

     文件        504  2017-08-19 21:31  多人网络\MultiplayerBook-master\Chapter 12\RoboCatRTS\RoboCatRTS\Inc\RandGen.h

     文件        628  2017-08-19 21:31  多人网络\MultiplayerBook-master\Chapter 12\RoboCatRTS\RoboCatRTS\Inc\RenderManager.h

     文件       1231  2017-08-19 21:31  多人网络\MultiplayerBook-master\Chapter 12\RoboCatRTS\RoboCatRTS\Inc\RoboCat.h

     文件       1485  2017-08-19 21:31  多人网络\MultiplayerBook-master\Chapter 12\RoboCatRTS\RoboCatRTS\Inc\RoboCatPCH.h

............此处省略1364个文件信息

评论

共有 条评论