Ejemplo n.º 1
0
void Object::SerializeTo(SerializerElement & element) const
{
    element.SetAttribute( "name", GetName() );
    element.SetAttribute( "type", GetType() );
    objectVariables.SerializeTo(element.AddChild("variables"));

    SerializerElement & behaviorsElement = element.AddChild("behaviors");
    behaviorsElement.ConsiderAsArrayOf("behavior");
    std::vector < gd::String > allBehaviors = GetAllBehaviorNames();
    for (std::size_t i = 0;i<allBehaviors.size();++i)
    {
        SerializerElement & behaviorElement = behaviorsElement.AddChild("behavior");

        behaviorElement.SetAttribute( "type", GetBehavior(allBehaviors[i]).GetTypeName() );
        behaviorElement.SetAttribute( "name", GetBehavior(allBehaviors[i]).GetName() );
        GetBehavior(allBehaviors[i]).SerializeTo(behaviorElement);
    }

    DoSerializeTo(element);
}
Ejemplo n.º 2
0
    void AIUpdate()
    {
		if(GetHealthPercent() <= 10 && GetBehavior() != Behavior_Flee)
		{
			Emote("Skum tries to run away in fear", Text_Emote);
			SetBehavior(Behavior_Flee);
			SetAllowMelee(false);
			SetAllowRanged(false);
			SetAllowSpell(false);
			MoveTo(-262.829742f, -299.363159f, -68.293579f, true);
		}
		ParentClass::AIUpdate();
	}
Ejemplo n.º 3
0
	void SteeringBehaviorSystem::Update(float elapsedTime)
	{
		auto entities = std::move(_layer->GetEntities());
		for (auto entity : entities)
		{
			if (entity->HasC<TransformComponent>() &&
				entity->HasC<SteeringBehaviorComponent>() &&
				entity->HasC<MovementComponent>())
			{
				auto sbc = entity->GetC<SteeringBehaviorComponent>();
				auto type = sbc->GetType();
				auto& behavior = sbc->GetBehavior();

				if (!behavior.valid())
					SetBehavior(entity, type, behavior);

				behavior->Update(elapsedTime);
			}
		}
	}
Ejemplo n.º 4
0
bool RenderCore::Init(const RenderCoreDesc& rcdesc)
{
	m_pD3D = Direct3DCreate9(D3D_SDK_VERSION);
	if(!m_pD3D)
	{
		// Push error-code into the error-pipeline
		return false;
	}

	m_RCDesc = rcdesc;

	AppMinStencilBits = m_RCDesc.HR_MinStencilBits;
	AppUsesDepthBuffer = true;
    AppUsesMixedVP = m_RCDesc.HR_UsesMixedVP;
	if(m_RCDesc.m_PresentParameters.Windowed)
	{
		AppRequiresWindowed = true;
	}
	else
	{
		AppRequiresFullscreen = true;
	}

	if(FAILED(Enumerate()))
	{
		// Push error-code into the error-pipeline
		return false;
	}
	else
	{
		if(m_AdapterInfoList.empty())
		{
			// Push error-code into the error-pipeline
			return false;
		}
	}

	unsigned int AdapterInfoID = 0xFFFFFFFF;
	unsigned int DeviceInfoID = 0xFFFFFFFF;
	unsigned int DeviceComboID = 0xFFFFFFFF;
	for(unsigned int iAdapter = 0; iAdapter < m_AdapterInfoList.size(); ++iAdapter)
	{
		D3DAdapterInfo AdapterInfo = m_AdapterInfoList[iAdapter];

		if(AdapterInfo.AdapterOrdinal == m_RCDesc.m_Adapter)
		{
			m_AdapterInfo = AdapterInfo;
			AdapterInfoID = iAdapter;

			if(FAILED(m_pD3D->GetAdapterDisplayMode(AdapterInfo.AdapterOrdinal, &m_DisplayMode)))
			{
				// Push error-code into error-pipeline
				return false;
			}

			for(unsigned int iDevice = 0; iDevice < m_AdapterInfo.DeviceInfoList.size(); ++iDevice)
			{
				D3DDeviceInfo DeviceInfo = m_AdapterInfo.DeviceInfoList[iDevice];

				if(DeviceInfo.DevType == m_RCDesc.m_DeviceType)
				{
					m_DeviceInfo = DeviceInfo;
					DeviceInfoID = iDevice;

					unsigned int NumOfDeviceCombos = m_DeviceInfo.DeviceComboList.size();

					for(unsigned int iDeviceCombo = 0; iDeviceCombo < m_DeviceInfo.DeviceComboList.size(); ++iDeviceCombo)
					{
						D3DDeviceCombo DeviceCombo = m_DeviceInfo.DeviceComboList[iDeviceCombo];

						if(m_RCDesc.m_PresentParameters.Windowed)  // 窗口模式
						{
							if(DeviceCombo.AdapterFormat == m_DisplayMode.Format)  // 此适配器的显示模式必须与桌面模式一致
							{
								if(DeviceCombo.IsWindowed == true)  // 此适配器必须支持桌面模式
								{
									m_RCDesc.m_DisplayColorBits = FormatToColorBits(DeviceCombo.BackBufferFormat);

									m_DeviceCombo = DeviceCombo;
									DeviceComboID = iDeviceCombo;
									break;
								}
							}
						}
						else  // 全屏幕,不要求适配器的显示模式与桌面模式一致
						{
							if(FormatToColorBits(DeviceCombo.BackBufferFormat) == m_RCDesc.m_DisplayColorBits && DeviceCombo.IsWindowed == false)
							{
								m_DeviceCombo = DeviceCombo;
								DeviceComboID = iDeviceCombo;

								break;
							}
						}
					}

					break;
				}
			}

			break;
		}
	}

	if(AdapterInfoID == 0xFFFFFFFF || DeviceInfoID == 0xFFFFFFFF || DeviceComboID == 0xFFFFFFFF)
	{
		// Push error-code into error-line
		return false;
	}


	if(m_RCDesc.HR_UsesMixedVP)
	{
		m_RCDesc.m_dwBehaviors = D3DCREATE_MIXED_VERTEXPROCESSING;
	}
	else
	{
		if(!GetBehavior(m_RCDesc.m_dwBehaviors, SOFTWARE_VP))
		{
			if(!GetBehavior(m_RCDesc.m_dwBehaviors, HARDWARE_VP))
			{
				if(!GetBehavior(m_RCDesc.m_dwBehaviors, PURE_HARDWARE_VP))
				{
					// Push error-code into error-pipeline
					return false;
				}
			}
		}
	}


	m_DisplayMode.Width = m_RCDesc.m_PresentParameters.BackBufferWidth;
	m_DisplayMode.Height = m_RCDesc.m_PresentParameters.BackBufferHeight;
	if(m_RCDesc.m_PresentParameters.Windowed)
	{
		D3DDISPLAYMODE DesktopMode;
		if(FAILED(m_pD3D->GetAdapterDisplayMode(m_AdapterInfo.AdapterOrdinal, &DesktopMode)))
		{
			// Push error-code into error-pipeline
			return false;
		}

		m_RCDesc.m_PresentParameters.BackBufferFormat = DesktopMode.Format;

		m_DisplayMode.Width = DesktopMode.Width;
		m_DisplayMode.Height = DesktopMode.Height;
		m_DisplayMode.Format = DesktopMode.Format;
	}
	else
	{
		m_RCDesc.m_PresentParameters.BackBufferFormat = m_DeviceCombo.BackBufferFormat;

		m_DisplayMode.Format = m_RCDesc.m_PresentParameters.BackBufferFormat;
	}

	m_RCDesc.m_PresentParameters.BackBufferCount = 0;

	vector<DSMSPair> AvailableDSMSPairs;
	for(unsigned int iDSF = 0; iDSF < m_DeviceCombo.DepthStencilFormatList.size(); ++iDSF)
	{
		D3DFORMAT dsf = m_DeviceCombo.DepthStencilFormatList[iDSF];

		for(unsigned int iMS = 0; iMS < m_DeviceCombo.MultiSampleTypeList.size(); ++iMS)
		{
			D3DMULTISAMPLE_TYPE ms = m_DeviceCombo.MultiSampleTypeList[iMS];

			bool bConflict = false;
			for(unsigned int iDSMSConflict = 0; iDSMSConflict < m_DeviceCombo.DSMSConflictList.size(); ++iDSMSConflict)
			{
				D3DDSMSConflict DSMSConflict = m_DeviceCombo.DSMSConflictList[iDSMSConflict];

				if(DSMSConflict.DSFormat == dsf && DSMSConflict.MSType == ms)
				{
					bConflict = true;
					break;
				}
			}
			if(!bConflict)
			{
				DSMSPair dsms = {dsf, iMS};
				AvailableDSMSPairs.push_back(dsms);
			}
		}
	}

	unsigned int itemp = AvailableDSMSPairs.size();
	if(AvailableDSMSPairs.empty())
	{
		// Push error-code into error-pipeline
		return false;
	}

	DSMSPair dsms = AvailableDSMSPairs[AvailableDSMSPairs.size() - 1];

	m_RCDesc.m_PresentParameters.MultiSampleType = m_DeviceCombo.MultiSampleTypeList[dsms.MSID];
	m_RCDesc.m_PresentParameters.MultiSampleQuality = m_DeviceCombo.MultiSampleQualityList[dsms.MSID] - 1;
	m_RCDesc.m_PresentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
	m_RCDesc.m_PresentParameters.EnableAutoDepthStencil = true;
	m_RCDesc.m_PresentParameters.AutoDepthStencilFormat = dsms.DSFormat;
	m_RCDesc.m_PresentParameters.Flags = 0;
	if(m_RCDesc.m_PresentParameters.Windowed)
	{
		m_RCDesc.m_PresentParameters.Flags = D3DPRESENTFLAG_DEVICECLIP;
	}


	m_RCDesc.m_PresentParameters.FullScreen_RefreshRateInHz = 0;
	if(!m_RCDesc.m_PresentParameters.Windowed)
	{
		for(unsigned int iDM = 0; iDM < m_AdapterInfo.DisplayModeList.size(); ++iDM)
		{
			D3DDISPLAYMODE dm = m_AdapterInfo.DisplayModeList[iDM];
			if(dm.Width == m_DisplayMode.Width && dm.Height == m_DisplayMode.Height && dm.Format == m_DisplayMode.Format)
			{
				if(m_RCDesc.m_PresentParameters.FullScreen_RefreshRateInHz < dm.RefreshRate)
				{
					m_RCDesc.m_PresentParameters.FullScreen_RefreshRateInHz = dm.RefreshRate;
				}
			}

		}
	}
	m_RCDesc.m_PresentParameters.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;


	//m_RCDesc.m_PresentParameters.MultiSampleQuality = 0;
	//m_RCDesc.m_PresentParameters.SwapEffect = D3DSWAPEFFECT_COPY;

	HRESULT hr = m_pD3D->CreateDevice(m_AdapterInfo.AdapterOrdinal, m_DeviceInfo.DevType, m_RCDesc.m_hWnd, m_RCDesc.m_dwBehaviors, &m_RCDesc.m_PresentParameters, &m_pD3DDevice);
	if(FAILED(hr))
	{
		// Push error-code into the error-pipeline
		throw Common::Exception(Common::EL_BAD, "RenderCore::Initiate", "Failed to create D3DDevice!");

		return false;
	}

	// Initialize The RenderState registry
	InitRSRegistry();

	return true;
}
Ejemplo n.º 5
0
//----------------------------------------------------------------------------
//Summary:
//		step on conflict crosswalk
//----------------------------------------------------------------------------
void CFreeMovingLogic::StepConflictEvent( ElapsedTime& time )
{
	LandsideTrafficGraphVertex& vertex = m_routePath.back();
	if (vertex.GetTrafficObjectType() == CLandsideWalkTrafficObjectInSim::CrossWalk_Type)
	{
		CCrossWalkInSim* pCrossWalkInSim = (CCrossWalkInSim*)vertex.GetTrafficInSim();

		if (pCrossWalkInSim->getCrossType()==Cross_Zebra)
		{
			if (!pCrossWalkInSim->PaxValid())
			{
				pCrossWalkInSim->AddPaxApproach(this);
			}
			else
			{
				pCrossWalkInSim->StepOnCrossWalk(time,m_routePath,this);
			}
		}else if (pCrossWalkInSim->getCrossType()==Cross_Pelican)
		{
			if (pCrossWalkInSim->getPaxLightState()==CROSSLIGHT_RED)
			{
				pCrossWalkInSim->pressCtrlButton();
				pCrossWalkInSim->AddPaxApproach(this);
				
				CPoint2008 tmpCrossPos0 = pCrossWalkInSim->GetRightPath()[0];
				CPoint2008 tmpCrossPos1 = pCrossWalkInSim->GetRightPath()[1];

				ARCVector3 paxPos=GetBehavior()->getPoint();

				ARCVector3 dir;
				ARCVector3 crossPos0(tmpCrossPos0.x,tmpCrossPos0.y,tmpCrossPos0.z);
				ARCVector3 crossPos1(tmpCrossPos1.x,tmpCrossPos1.y,tmpCrossPos1.z);

				if (paxPos.DistanceTo(crossPos0)<paxPos.DistanceTo(crossPos1))
				{
                    dir=crossPos1-crossPos0;
				}else
				{
					dir=crossPos0-crossPos1;
				}
//                 GetBehavior()->setDestination(GetBehavior()->getPoint()+dir/100);
// 				GetBehavior()->setDestination(GetBehavior()->getPoint()+dir);
				GetBehavior()->setDestination(GetBehavior()->getPoint()+dir.Normalize()*100);
				GetBehavior()->WriteLogEntry(time + GetBehavior()->moveTime());
				m_routePath.pop_back();
			}else if(pCrossWalkInSim->getPaxLightState()==CROSSLIGHT_BUFFER)
			{
				pCrossWalkInSim->AddPaxApproach(this);
			}else if (pCrossWalkInSim->getPaxLightState()==CROSSLIGHT_GREEN)
			{
				if (pCrossWalkInSim->PaxValid())
				{					
					pCrossWalkInSim->StepOnCrossWalk(time,m_routePath,this);
				}
			}
		}else if (pCrossWalkInSim->getCrossType()==Cross_Intersection)
		{
			if (pCrossWalkInSim->getPaxLightState()==CROSSLIGHT_RED)
			{
				pCrossWalkInSim->AddPaxApproach(this);

				CPoint2008 tmpCrossPos0 = pCrossWalkInSim->GetRightPath()[0];
				CPoint2008 tmpCrossPos1 = pCrossWalkInSim->GetRightPath()[1];

				ARCVector3 paxPos=GetBehavior()->getPoint();

				ARCVector3 dir;
				ARCVector3 crossPos0(tmpCrossPos0.x,tmpCrossPos0.y,tmpCrossPos0.z);
				ARCVector3 crossPos1(tmpCrossPos1.x,tmpCrossPos1.y,tmpCrossPos1.z);

				if (paxPos.DistanceTo(crossPos0)<paxPos.DistanceTo(crossPos1))
				{
					dir=crossPos1-crossPos0;
				}else
				{
					dir=crossPos0-crossPos1;
				}
// 				GetBehavior()->setDestination(GetBehavior()->getPoint()+dir/100);
// 				GetBehavior()->setDestination(GetBehavior()->getPoint()+dir);
				GetBehavior()->setDestination(GetBehavior()->getPoint()+dir.Normalize()*100);
				GetBehavior()->WriteLogEntry(time + GetBehavior()->moveTime());
				m_routePath.pop_back();
			}else if(pCrossWalkInSim->getPaxLightState()==CROSSLIGHT_BUFFER)
			{
				pCrossWalkInSim->AddPaxApproach(this);

				CPoint2008 tmpCrossPos0 = pCrossWalkInSim->GetRightPath()[0];
				CPoint2008 tmpCrossPos1 = pCrossWalkInSim->GetRightPath()[1];

				ARCVector3 paxPos=GetBehavior()->getPoint();

				ARCVector3 dir;
				ARCVector3 crossPos0(tmpCrossPos0.x,tmpCrossPos0.y,tmpCrossPos0.z);
				ARCVector3 crossPos1(tmpCrossPos1.x,tmpCrossPos1.y,tmpCrossPos1.z);

				if (paxPos.DistanceTo(crossPos0)<paxPos.DistanceTo(crossPos1))
				{
					dir=crossPos1-crossPos0;
				}else
				{
					dir=crossPos0-crossPos1;
				}
// 				GetBehavior()->setDestination(GetBehavior()->getPoint()+dir/100);
// 				GetBehavior()->setDestination(GetBehavior()->getPoint()+dir);
				GetBehavior()->setDestination(GetBehavior()->getPoint()+dir.Normalize()*100);
				GetBehavior()->WriteLogEntry(time + GetBehavior()->moveTime());
				m_routePath.pop_back();
			}else if (pCrossWalkInSim->getPaxLightState()==CROSSLIGHT_GREEN)
			{
				if (pCrossWalkInSim->PaxValid())
				{					
					pCrossWalkInSim->StepOnCrossWalk(time,m_routePath,this);
				}
			}
		}
	}
}