コード例 #1
0
ファイル: CET_GameRules.cpp プロジェクト: aronarts/FireNET
	EContextEstablishTaskResult OnStep( SContextEstablishState& state )
	{
		CCryAction * pFramework = CCryAction::GetCryAction();
		if (CGameClientNub * pClientNub = pFramework->GetGameClientNub())
		{
			CGameClientChannel * pChannel = pClientNub->GetGameClientChannel();
			if (pChannel)
			{
				switch (pChannel->GetClock().GetSyncState())
				{
				case CClientClock::eSS_NotDone:
					{
						pChannel->GetClock().StartSync();
					}
					break;
				case CClientClock::eSS_Done:
					{
						return eCETR_Ok;
					}
					break;
				}
			}
		}
		return eCETR_Wait;
	}
//------------------------------------------------------------------------
void CInventory::PostReloadExtension( IGameObject * pGameObject, const SEntitySpawnParams &params )
{
	// attach script bind
	CCryAction *pCryAction = static_cast<CCryAction *>(gEnv->pGame->GetIGameFramework());
	pCryAction->GetInventoryScriptBind()->AttachTo(this);

	m_pActor = pCryAction->GetIActorSystem()->GetActor(pGameObject->GetEntityId());
}
void CGameServerChannel::DefineProtocol(IProtocolBuilder *pBuilder)
{
	pBuilder->AddMessageSink(this, CGameClientChannel::GetProtocolDef(), CGameServerChannel::GetProtocolDef());
	CCryAction *cca = CCryAction::GetCryAction();
	if (cca->GetIGameObjectSystem())
		cca->GetIGameObjectSystem()->DefineProtocol( true, pBuilder );
	if (cca->GetGameContext())
		cca->GetGameContext()->DefineContextProtocols(pBuilder, true);
}
//------------------------------------------------------------------------
bool CInventory::Init( IGameObject * pGameObject )
{
	SetGameObject(pGameObject);
	// attach script bind
	CCryAction *pCryAction = static_cast<CCryAction *>(gEnv->pGame->GetIGameFramework());
	pCryAction->GetInventoryScriptBind()->AttachTo(this);

	m_pGameFrameWork = pCryAction;

	m_pActor = pCryAction->GetIActorSystem()->GetActor(pGameObject->GetEntityId());

	return true;
}
void CGameQueryListener::ConnectToServer(const char* server)
{
	//first check the version of the server ...
	char myVersion[32];
	GetISystem()->GetProductVersion().ToShortString(myVersion);
	string version(myVersion);

	SGameServer* targetServer = FindServer(server);
	if(!targetServer)
	{
		CryWarning(VALIDATOR_MODULE_NETWORK, VALIDATOR_WARNING, "Selected server not found in list!");
		return;
	}

	if(version.compare(targetServer->GetServerGameVersion()) != 0)
	{
		CryWarning(VALIDATOR_MODULE_NETWORK, VALIDATOR_WARNING, "Game versions differ - not connecting!");
		return;
	}

	string addr(server);
	string port;
	int pos = addr.find(":");
	if(pos != string::npos)	//space for port
	{
		port = addr.substr(pos+1, addr.size()-pos);
		addr.erase(pos, addr.size()-pos);
	}

	IConsole* pConsole = gEnv->pConsole;

	pConsole->GetCVar("cl_serveraddr")->Set(addr.c_str());
	if(port.size() > 0)
		pConsole->GetCVar("cl_serverport")->Set(port.c_str());

	string tempHost = pConsole->GetCVar("cl_serveraddr")->GetString();

	SGameStartParams params;	//this would connect to a server
	params.flags = eGSF_Client;
	params.hostname = tempHost.c_str();
	params.pContextParams = NULL;
	params.port = pConsole->GetCVar("cl_serverport")->GetIVal();

	CCryAction *action = (CCryAction*) (gEnv->pGame->GetIGameFramework());
	if(action)
	{
		gEnv->pConsole->ExecuteString("net_lanbrowser 0");
		action->StartGameContext(&params);
	}
}
//------------------------------------------------------------------------
CInventory::~CInventory()
{
	CCryAction *pCryAction = static_cast<CCryAction *>(gEnv->pGame->GetIGameFramework());
	pCryAction->GetInventoryScriptBind()->DetachFrom(this);
}
コード例 #7
0
ファイル: ScriptRMI.cpp プロジェクト: aronarts/FireNET
// send a call
int CScriptRMI::ProxyFunction( IFunctionHandler* pH, void *pBuffer, int nSize )
{
	if (!m_pThis->m_pParent)
	{
		pH->GetIScriptSystem()->RaiseError( "Trying to proxy a remote method invocation with no game started... failing" );
		return pH->EndFunction();
	}

	string funcInfo;
	string dispatchInfo;
	bool gatherDebugInfo = pLogRMIEvents && pLogRMIEvents->GetIVal() != 0;

	IScriptSystem * pSS = pH->GetIScriptSystem();
	const SFunctionInfo * pFunctionInfo = static_cast<const SFunctionInfo *>(pBuffer);

	SmartScriptTable proxyTable;
	if (!pH->GetParam( 1, proxyTable ))
		return pH->EndFunction( false );

	ScriptHandle flags;
	ScriptHandle id;
	if (!proxyTable->GetValue(FLAGS_FIELD, flags))
		return pH->EndFunction( false );
	if (!proxyTable->GetValue(ID_FIELD, id))
		return pH->EndFunction( false );

	int formatStart = 2;
	if (uint32 flagsMask = flags.n & (eDF_ToClientOnChannel | eDF_ToClientOnOtherChannels))
	{
		if (flagsMask != (eDF_ToClientOnChannel | eDF_ToClientOnOtherChannels))
			formatStart ++;
	}

	_smart_ptr<CScriptMessage> pMsg = new CScriptMessage( 
		pFunctionInfo->reliability,
		pFunctionInfo->attachment,
		(EntityId)id.n, 
		pFunctionInfo->funcID, 
		pFunctionInfo->format );
	if (!pMsg->SetFromFunction( pH, formatStart ))
	{
		return pH->EndFunction( false );
	}

	if (gatherDebugInfo)
		funcInfo = pMsg->DebugInfo();

	INetContext * pNetContext = m_pThis->m_pParent->GetNetContext();
	CCryAction * pFramework = m_pThis->m_pParent->GetFramework();

	if (flags.n & eDF_ToServer)
	{
		CGameClientNub * pClientNub = pFramework->GetGameClientNub();
		bool called = false;
		if (pClientNub)
		{
			CGameClientChannel * pChannel = pClientNub->GetGameClientChannel();
			if (pChannel)
			{
				DispatchRMI( pChannel->GetNetChannel(), pMsg, false );
				called = true;
			}
		}
		if (!called)
		{
			pSS->RaiseError( "RMI via client (to server) requested but we are not a client" );
		}

		if (gatherDebugInfo)
			dispatchInfo = "server";
	}
	else if (flags.n & (eDF_ToClientOnChannel | eDF_ToClientOnOtherChannels))
	{
		CGameServerNub * pServerNub = pFramework->GetGameServerNub();
		if (pServerNub)
		{
			int myChannelId = 0;
			bool ok = true;
			if (flags.n != (eDF_ToClientOnChannel | eDF_ToClientOnOtherChannels))
			{
				if (!pH->GetParam( 2, myChannelId ))
				{
					pSS->RaiseError( "RMI onClient or otherClients must have a valid channel id for its first argument" );
					ok = false;
				}
				else if (pServerNub->GetServerChannelMap()->find(myChannelId) == pServerNub->GetServerChannelMap()->end())
				{
					pSS->RaiseError( "RMI No such server channel %d", myChannelId );
					ok = false;
				}
			}
			if (ok)
			{
				TServerChannelMap * pChannelMap = pServerNub->GetServerChannelMap();
				for (TServerChannelMap::iterator iter = pChannelMap->begin(); iter != pChannelMap->end(); ++iter)
				{
					bool isOwn = iter->first == myChannelId;
					if (isOwn && !(flags.n & eDF_ToClientOnChannel))
						continue;
					if (!isOwn && !(flags.n & eDF_ToClientOnOtherChannels))
						continue;

					if (iter->second->GetNetChannel())
						DispatchRMI( iter->second->GetNetChannel(), pMsg, true );
				}
				if (gatherDebugInfo)
				{
					dispatchInfo = "client: ";
					bool appendChannel = false;
					switch (flags.n)
					{
					case eDF_ToClientOnChannel:
						dispatchInfo += "specificChannel";
						appendChannel = true;
						break;
					case eDF_ToClientOnOtherChannels:
						dispatchInfo += "otherChannels";
						appendChannel = true;
						break;
					case eDF_ToClientOnChannel | eDF_ToClientOnOtherChannels:
						dispatchInfo += "allChannels";
						break;
					default:
						dispatchInfo += "UNKNOWN(BUG)";
						appendChannel = true;
						CRY_ASSERT(false);
					}
					if (appendChannel)
					{
						string temp;
						temp.Format(" %d", myChannelId);
						dispatchInfo += temp;
					}
				}
			}
		}
		else
		{
			pSS->RaiseError( "RMI via server (to client) requested but we are not a server" );
		}
	}

	if (gatherDebugInfo)
	{
		IEntity * pEntity = gEnv->pEntitySystem->GetEntity((EntityId)id.n);
		const char * name = "<invalid>";
		if (pEntity) name = pEntity->GetName();
		CryLogAlways("[rmi] %s(%s) [%s] on entity[%d] %s", 
			pH->GetFuncName(), funcInfo.c_str(), dispatchInfo.c_str(), (int)id.n, name);
	}

	return pH->EndFunction( true );
}
コード例 #8
0
ファイル: View.cpp プロジェクト: joewan/pycmake
//------------------------------------------------------------------------
void CView::Update(float frameTime,bool isActive)
{
	//FIXME:some cameras may need to be updated always
	if (!isActive)
		return;

	CGameObject* pLinkedTo = GetLinkedGameObject();
	if (pLinkedTo && !pLinkedTo->CanUpdateView())
		pLinkedTo = nullptr;
	IEntity* pEntity = pLinkedTo ? 0 : GetLinkedEntity();

	if (pLinkedTo || pEntity)
	{
		m_viewParams.SaveLast();

		CCamera* pSysCam = &m_pSystem->GetViewCamera();

		//process screen shaking
		ProcessShaking(frameTime);

		//FIXME:to let the updateView implementation use the correct shakeVector
		m_viewParams.currentShakeShift = m_viewParams.rotation * m_viewParams.currentShakeShift;

		m_viewParams.frameTime = frameTime;
		//update view position/rotation
		if (pLinkedTo)
		{
			pLinkedTo->UpdateView(m_viewParams);
			if (!m_viewParams.position.IsValid())
			{
				m_viewParams.position = m_viewParams.GetPositionLast();
				CRY_ASSERT_MESSAGE(0, "Camera position is invalid, reverting to old position");
			}
			if (!m_viewParams.rotation.IsValid())
			{
				m_viewParams.rotation = m_viewParams.GetRotationLast();
				CRY_ASSERT_MESSAGE(0, "Camera rotation is invalid, reverting to old rotation");
			}
		}
		else
		{
			Matrix34 mat = pEntity->GetWorldTM();
			mat.OrthonormalizeFast();
			m_viewParams.position = mat.GetTranslation();
			m_viewParams.rotation = Quat(mat);
		}

		ApplyFrameAdditiveAngles(m_viewParams.rotation);

		if (pLinkedTo)
		{
			pLinkedTo->PostUpdateView(m_viewParams);
		}

		const float fNearZ = gEnv->pGame->GetIGameFramework()->GetIViewSystem()->GetDefaultZNear();

		//see if the view have to use a custom near clipping plane
		const float nearPlane = (m_viewParams.nearplane >= 0.01f) ? (m_viewParams.nearplane) : fNearZ;
		const float farPlane  = gEnv->p3DEngine->GetMaxViewDistance();
		float       fov       = (m_viewParams.fov < 0.001f) ? DEFAULT_FOV : m_viewParams.fov;

		// [VR] specific
		// Modify FOV based on the HDM device configuration
		IHmdManager* pHmdManager         = gEnv->pSystem->GetHmdManager();
		IHmdDevice*  pHmdDevice          = nullptr;
		bool         bHmdTrackingEnabled = false;
		if (pHmdManager)
		{
			pHmdDevice = pHmdManager->GetHmdDevice();
			if (pHmdDevice)
			{
				const HmdTrackingState &sensorState = pHmdDevice->GetLocalTrackingState();
				if (sensorState.CheckStatusFlags(eHmdStatus_IsUsable))
				{
					bHmdTrackingEnabled = true;
				}
			}
		}

		if (pHmdManager->IsStereoSetupOk())
		{
			const IHmdDevice*       pDev        = pHmdManager->GetHmdDevice();
			const HmdTrackingState &sensorState = pDev->GetLocalTrackingState();
			if (sensorState.CheckStatusFlags(eHmdStatus_IsUsable))
			{
				float arf_notUsed;
				pDev->GetCameraSetupInfo(fov, arf_notUsed);
			}
		}

		m_camera.SetFrustum(pSysCam->GetViewSurfaceX(), pSysCam->GetViewSurfaceZ(), fov, nearPlane, farPlane, pSysCam->GetPixelAspectRatio());

		//TODO: (14, 06, 2010, "the player view should always get updated, this due to the hud being visable, without shocking, in cutscenes - todo is to see if we can optimise this code");
		IActor* pActor = gEnv->pGame->GetIGameFramework()->GetClientActor();
		if (pActor)
		{
			CGameObject* const linkToObj = static_cast<CGameObject*>(pActor->GetEntity()->GetProxy(ENTITY_PROXY_USER));

			if (linkToObj && linkToObj != pLinkedTo)
			{
				linkToObj->PostUpdateView(m_viewParams);
			}
		}

		//apply shake & set the view matrix
		m_viewParams.rotation *= m_viewParams.currentShakeQuat;
		m_viewParams.rotation.NormalizeSafe();
		m_viewParams.position += m_viewParams.currentShakeShift;

		// Camera space Rendering calculations on Entity
		if (pLinkedTo)
		{
			IEntity* pLinkedToEntity = pLinkedTo->GetEntity();
			if (pLinkedToEntity)
			{
				const int slotIndex   = 0;
				uint32    entityFlags = pLinkedToEntity->GetSlotFlags(slotIndex);
				if (entityFlags & ENTITY_SLOT_RENDER_NEAREST)
				{
					// Get camera pos relative to entity
					const Vec3 cameraLocalPos = m_viewParams.position;

					// Set entity's camera space position
					const Vec3 cameraSpacePos(-cameraLocalPos * m_viewParams.rotation);
					pLinkedToEntity->SetSlotCameraSpacePos(slotIndex,cameraSpacePos);

					// Add world pos onto camera local pos
					m_viewParams.position = pLinkedToEntity->GetWorldPos() + cameraLocalPos;
				}
			}
		}

		// Blending between cameras needs to happen after Camera space rendering calculations have been applied
		// so that the m_viewParams.position is in World Space again
		m_viewParams.UpdateBlending(frameTime);

		// [VR] specific
		// Add HMD's pose tracking on top of current camera pose
		// Each game-title can decide whether to keep this functionality here or (most likely)
		// move it somewhere else.

		Quat q   = m_viewParams.rotation;
		Vec3 pos = m_viewParams.position;
		Vec3 p   = Vec3(ZERO);

		// Uses the recorded tracking if time demo is on playback
		// Otherwise uses real tracking from device
		ITimeDemoRecorder* pTimeDemoRecorder = gEnv->pGame->GetIGameFramework()->GetITimeDemoRecorder();

		if (pTimeDemoRecorder && pTimeDemoRecorder->IsPlaying())
		{
			STimeDemoFrameRecord record;
			pTimeDemoRecorder->GetCurrentFrameRecord(record);

			p = q * record.hmdPositionOffset;
			q = q * record.hmdViewRotation;
		}
		else if (bHmdTrackingEnabled)
		{
			pHmdDevice->SetAsynCameraCallback(this);
			if (pHmdReferencePoint && pHmdReferencePoint->GetIVal() == 1) // actor-centered HMD offset
			{
				const IEntity* pEnt = GetLinkedEntity();
				if (const IActor* pActor = gEnv->pGame->GetIGameFramework()->GetClientActor())
				{
					if (pEnt && pActor->GetEntity() == pEnt)
					{
						q   = pEnt->GetWorldRotation();
						pos = pEnt->GetWorldPos();
					}
				}
			}

			const HmdTrackingState &sensorState = pHmdDevice->GetLocalTrackingState();
			p = q * sensorState.pose.position;
			q = q * sensorState.pose.orientation;
		}

		Matrix34 viewMtx(q);
		viewMtx.SetTranslation(pos + p);
		m_camera.SetMatrix(viewMtx);
	}
	else
	{
		m_linkedTo = 0;

		CCryAction* pCryAction = CCryAction::GetCryAction();
		if (!pCryAction->IsGameSessionMigrating())    // If we're host migrating, leave the camera where it was
		{
			// Check if we're leaving a game mid way through - if we are then stop the camera from being reset for a frame or 2 before the unload happens
			if (!pCryAction->GetIGameSessionHandler()->IsMidGameLeaving())
			{
				m_camera.SetPosition(Vec3(1,1,1));
			}
		}
	}
}
コード例 #9
0
ファイル: View.cpp プロジェクト: aronarts/FireNET
//------------------------------------------------------------------------
void CView::Update(float frameTime,bool isActive)
{
	//FIXME:some cameras may need to be updated always
	if (!isActive)
		return;

	CGameObject * pLinkedTo = GetLinkedGameObject();
	if (pLinkedTo && !pLinkedTo->CanUpdateView())
	  pLinkedTo = NULL;
	IEntity* pEntity = pLinkedTo ? 0 : GetLinkedEntity();

	if (pLinkedTo || pEntity)
	{
		m_viewParams.SaveLast();

		CCamera *pSysCam = &m_pSystem->GetViewCamera();

		//process screen shaking
		ProcessShaking(frameTime);
		
		//FIXME:to let the updateView implementation use the correct shakeVector
		m_viewParams.currentShakeShift = m_viewParams.rotation * m_viewParams.currentShakeShift;
		
    m_viewParams.frameTime=frameTime;
		//update view position/rotation
		if (pLinkedTo)
		{
			pLinkedTo->UpdateView(m_viewParams);
			if (!m_viewParams.position.IsValid())
			{
				m_viewParams.position = m_viewParams.GetPositionLast();
				CRY_ASSERT_MESSAGE(0, "Camera position is invalid, reverting to old position");
			}
			if (!m_viewParams.rotation.IsValid())
			{
				m_viewParams.rotation = m_viewParams.GetRotationLast();
				CRY_ASSERT_MESSAGE(0, "Camera rotation is invalid, reverting to old rotation");
			}
		}
		else
		{
			Matrix34 mat = pEntity->GetWorldTM();
			mat.OrthonormalizeFast();
			m_viewParams.position = mat.GetTranslation();
			m_viewParams.rotation = Quat(mat);
		}

		ApplyFrameAdditiveAngles(m_viewParams.rotation);

    if (pLinkedTo)
    {
      pLinkedTo->PostUpdateView(m_viewParams);
    }

		float fNearZ  = gEnv->pGame->GetIGameFramework()->GetIViewSystem()->GetDefaultZNear();
		
		//see if the view have to use a custom near clipping plane
		float nearPlane = (m_viewParams.nearplane > 0.01f)?(m_viewParams.nearplane):(fNearZ/*pSysCam->GetNearPlane()*/);
		float farPlane = gEnv->p3DEngine->GetMaxViewDistance();
		float fov = m_viewParams.fov < 0.001 ? DEFAULT_FOV : m_viewParams.fov;
		
		m_camera.SetFrustum(pSysCam->GetViewSurfaceX(),pSysCam->GetViewSurfaceZ(),fov,nearPlane,farPlane, pSysCam->GetPixelAspectRatio());

    //TODO: (14, 06, 2010, "the player view should always get updated, this due to the hud being visable, without shocking, in cutscenes - todo is to see if we can optimise this code");
    IActor * pActor = gEnv->pGame->GetIGameFramework()->GetClientActor();
    if (pActor)
    {
      CGameObject * linkToObj = (CGameObject*)pActor->GetEntity()->GetProxy( ENTITY_PROXY_USER );
      if (linkToObj && linkToObj != pLinkedTo)
      {
        linkToObj->PostUpdateView(m_viewParams);
      }
    }

		//apply shake & set the view matrix
		m_viewParams.rotation *= m_viewParams.currentShakeQuat;
		m_viewParams.rotation.NormalizeSafe();
		m_viewParams.position += m_viewParams.currentShakeShift;

		// Camera space Rendering calculations on Entity
		if(pLinkedTo)
		{
			IEntity* pLinkedToEntity = pLinkedTo->GetEntity();
			if(pLinkedToEntity)
			{
				const int slotIndex = 0;
				uint32 entityFlags = pLinkedToEntity->GetSlotFlags(slotIndex);
				if(entityFlags & ENTITY_SLOT_RENDER_NEAREST)
				{
					// Get camera pos relative to entity
					const Vec3 cameraLocalPos = m_viewParams.position;

					// Set entity's camera space position
					const Vec3 cameraSpacePos(-cameraLocalPos * m_viewParams.rotation);
					pLinkedToEntity->SetSlotCameraSpacePos(slotIndex,cameraSpacePos);

					// Add world pos onto camera local pos
					m_viewParams.position = pLinkedToEntity->GetWorldPos() + cameraLocalPos;
				}
			}
		}

		// Blending between cameras needs to happen after Camera space rendering calculations have been applied
		// so that the m_viewParams.position is in World Space again
		m_viewParams.UpdateBlending(frameTime);

		Matrix34 viewMtx(m_viewParams.rotation);
		viewMtx.SetTranslation(m_viewParams.position);
		m_camera.SetMatrix(viewMtx);
	}
	else
	{
		m_linkedTo = 0;

		CCryAction *pCryAction = CCryAction::GetCryAction();
		if (!pCryAction->IsGameSessionMigrating())		// If we're host migrating, leave the camera where it was
		{
			// Check if we're leaving a game mid way through - if we are then stop the camera from being reset for a frame or 2 before the unload happens
			if (!pCryAction->GetIGameSessionHandler()->IsMidGameLeaving())
			{
				m_camera.SetPosition(Vec3(1,1,1));
			}
		}
	}
}