コード例 #1
0
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void CoreObjectManager::RemoveObject(CoreObject* pCoreObject)
{
    if(m_activeEntryCount == 0)
    {
        COREDEBUG_PrintDebugMessage("INSANE ERROR: Tried to remove an object when there are no used handles.");
        return;
    }
    
#if COREOBJECTMANAGER_DEBUG
	assert(pCoreObject->m_markedForDeletion == true);
#endif
	const CoreObjectHandle handle = pCoreObject->GetHandle();
	
	//Invalidate the object's handle
	pCoreObject->handle = CoreObjectHandle();
	
	const s32 index = handle.m_index;
	
	//Make sure that the handle is valid.
	//If it's not, we could be leaking.
#if COREOBJECTMANAGER_DEBUG
	assert(m_entries[index].m_counter == handle.m_counter);
	assert(m_entries[index].m_active == true);
#endif	
	m_entries[index].m_nextFreeIndex = m_firstFreeEntry;
	m_entries[index].m_active = false;
	
	m_firstFreeEntry = index;
	
	--m_activeEntryCount;
	
	//COREDEBUG_PrintDebugMessage("Removed Handle: %u, for type: %u", (u32)handle, pCoreObject->GetEntityType());
}
コード例 #2
0
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
bool CoreObjectManager::AddObject(CoreObject *pCoreObject)
{
#if COREOBJECTMANAGER_DEBUG
	assert(pCoreObject->m_markedForDeletion == false);
	assert(m_activeEntryCount < COREOBJECT_MAX_OBJECTS - 1);
#endif
	const s32 newIndex = m_firstFreeEntry;
	
	if(newIndex >= COREOBJECT_MAX_OBJECTS)
	{
		pCoreObject->handle = 0;
		
		return false;
	}

#if COREOBJECTMANAGER_DEBUG
	assert(newIndex < COREOBJECT_MAX_OBJECTS);
	assert(m_entries[newIndex].m_active == false);
	assert(!m_entries[newIndex].m_endOfList);
#endif
	
	m_firstFreeEntry = m_entries[newIndex].m_nextFreeIndex;
	
	m_entries[newIndex].m_nextFreeIndex = 0;
	
	//Increment useage counter for this entry
	//If it is above 2, then the entry has been used
	//multiple times and the system could be leaking.
	++m_entries[newIndex].m_counter;
	
	//Handle wrapping
	if (m_entries[newIndex].m_counter == 0)
	{
		m_entries[newIndex].m_counter = 1;
	}
	
	//The entry has been used so it is now active
	m_entries[newIndex].m_active = true;
	
	//Save the pointer to the CoreObject
	m_entries[newIndex].m_pObject = pCoreObject;
	
	//Increase the amount of active entries
	++m_activeEntryCount;
	
	//Create a handle
	const CoreObjectHandle newHandle = CoreObjectHandle(newIndex, m_entries[newIndex].m_counter, 0);
	
	//Copy the handle to the CoreObject
	pCoreObject->handle = newHandle;
	
	//COREDEBUG_PrintDebugMessage("Created Handle: %u, for type: %u", (u32)newHandle, pCoreObject->GetEntityType());

	return true;
}
コード例 #3
0
ファイル: Spawner.cpp プロジェクト: spencerkohan/CoreEngine3D
bool Spawner::SpawnInit(void* pSpawnStruct)
{
	m_hSpawnObject = CoreObjectHandle();
	
	m_spawnTimer = -1.0f;
	m_spawnTimeMin = 5.0f;
	m_spawnTimeMax = 5.0f;
	m_requiresTrigger = false;
	
	m_launchSpeed = 0.0f;

	SpawnableEntity* pSpawnableEnt = (SpawnableEntity*)pSpawnStruct;
	if(pSpawnableEnt == NULL)
	{
		return false;
	}
	
	CopyVec3(&m_position,&pSpawnableEnt->position);
	
	for (pugi::xml_node property = pSpawnableEnt->pProperties.child("property"); property; property = property.next_sibling("property"))
	{
		const char* propNameString = property.attribute("name").value();
		const char* valueString = property.attribute("value").value();
		
		if(strcmp(propNameString, "SpawnObject") == 0)
		{
			const u32 uniqueID = atoi(valueString);
			m_pEntityToSpawn = GAME->GetSpawnableEntityByTiledUniqueID(uniqueID);
		}
		else if(strcmp(propNameString, "SpawnTimeMin") == 0)
		{
			m_spawnTimeMin = atof(valueString);
		}
		else if(strcmp(propNameString, "SpawnTimeMax") == 0)
		{
			m_spawnTimeMax = atof(valueString);
		}
		else if(strcmp(propNameString, "LaunchSpeed") == 0)
		{
			m_launchSpeed = atof(valueString);
		}
		else if(strcmp(propNameString, "RequiresTrigger") == 0)
		{
			if(strcmp(valueString, "true") == 0)
			{
				m_requiresTrigger = true;
			}
		}
	}
	
	m_spawnTimer = rand_FloatRange(m_spawnTimeMin, m_spawnTimeMax);

	return false;
}