static bool AddObjectToList(CBaseEditObj* pGroup, const char* pszName)
{
	CPropList& PropList = pGroup->m_PropList;

	//we need to run through the property list and make sure that this name
	//isn't already in there, and also tag a blank space to put it in. 
	CStringProp*	pPutIn		= NULL;
	uint32			nCurrProp	= STARTING_PROPERTY;

	while(1)
	{
		//build up the property name
		char pszPropName[256];
		sprintf(pszPropName, PROPERTY_NAME, nCurrProp);

		CBaseProp* pProp = PropList.GetProp(pszPropName);

		//see if we have hit the end
		if(!pProp)
			break;

		//make sure that this is a string property
		if(pProp->GetType() == LT_PT_STRING)
		{
			//we have a string
			CStringProp* pString = (CStringProp*)pProp;

			//see if this matches
			if(stricmp(pszName, pString->m_String) == 0)
			{
				//it does match, we don't need to add it
				return true;
			}

			//see if this is blank
			if(!pPutIn && (strlen(pString->m_String) == 0))
			{
				pPutIn = pString;
			}
		}

		//next property
		nCurrProp++;
	}

	//see if we had room
	if(!pPutIn)
	{
		//no room
		DrawStatusText(eST_Error, "There was not enough room in group object %s to add the object %s", pGroup->GetName(), pszName);
		return false;
	}

	//ok, we have room
	strncpy(pPutIn->m_String, pszName, MAX_STRINGPROP_LEN);

	//success
	return true;
}
Exemple #2
0
bool CPCRenderTree::Optimize(bool bDisplayStats)
{
	CPCRenderTreeNode::SOptimizeStats sOptStats;

	m_pRoot->ReduceTriCount();

	std::stack<CPCRenderTreeNode*> cNodeStack;
	cNodeStack.push(m_pRoot);
	while (!cNodeStack.empty())
	{
		// Get the current node off the top
		CPCRenderTreeNode *pCurNode = cNodeStack.top();
		cNodeStack.pop();

		// Optimize it
		pCurNode->Optimize(&sOptStats);

		// Add the light group data
		pCurNode->ReadLightGroups( &(*(m_aLightGroupList.begin())), m_aLightGroupList.size());

		// Push the children on the stack
		for (uint32 nChildLoop = 0; nChildLoop < CPCRenderTreeNode::k_NumChildren; ++nChildLoop)
		{
			CPCRenderTreeNode *pChild = pCurNode->GetChild(nChildLoop);
			if (pChild)
				cNodeStack.push(pChild);
		}

	}

	if (sOptStats.m_nLMPages && bDisplayStats)
	{
		float fWastedSpace = ((float)sOptStats.m_nLMPageArea - (float)sOptStats.m_nLMArea) / (float)sOptStats.m_nLMPageArea;
		DrawStatusText(eST_Normal, "    LM Data: %d pages, %d bytes, %d%% wasted",
			sOptStats.m_nLMPages, sOptStats.m_nLMPageArea * 4, (uint32)((fWastedSpace * 100.0f) + 0.5f));
	}

	return true;
}
Exemple #3
0
void nGraphics::Render()
{
	// Check if we have a valid render device, if not we don't have anything to render with
	if(!m_pDevice)
		return;

	HRESULT hr = NULL;

	// Check if device ok
	if(FAILED(hr = m_pDevice->TestCooperativeLevel()))
	{
		// Yield some CPU time to other processes
		Trace(__FUNCTION__" Sleeping on test coop level (100 ms).\n");
		Sleep(100);

		// The device has been lost but cannot be reset at this time. 
		// Therefore, rendering is not possible and we'll have to return 
		// and try again at a later time.
		if(hr == D3DERR_DEVICELOST)
		{
			nMainFrame::LastError("Display Device lost.");
			Trace(__FUNCTION__" Display Device lost.\n");
			return;
		}

		// The device has been lost but it can be reset at this time. 
		if(hr == D3DERR_DEVICENOTRESET)
		{
			// If the device can be restored, the application prepares the 
			// device by destroying all video-memory resources and any 
			// swap chains. 
			this->InvalidateDeviceObjects();

			if(FAILED(m_pDevice->Reset(&m_PresentParameters)))
			{
				nMainFrame::LastError("Failed to reset Display Device.");
				Trace(__FUNCTION__" Failed to reset Display Device.\n");
				return;
			}

			Trace(__FUNCTION__" Display Device reset.\n");

			// Finally, a lost device must re-create resources (including  
			// video memory resources) after it has been reset.

			this->RestoreDeviceObjects();
		}
	}

	// Clear the screen with the backgroun color
	m_pDevice->Clear(0,0,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,COLOR_BACKGROUND,1.0f,0);

	// Begin the scene
	if(SUCCEEDED(m_pDevice->BeginScene()))
	{
		// Begin sprite drawing
		SpriteBegin();

		// Draw the game
		nGetInstance()->GetGame()->Render();

		// Draw the status text
		DrawStatusText();

		// End 2D drawing
		SpriteEnd();

		// End the scene
		m_pDevice->EndScene();
	}

	// Present the scene to the user
	m_pDevice->Present(0,0,0,0);
}