void BasicDemo::CreateObjects() {

/*REM*		// create a box shape of size (1,1,1) **/
/*REM*		btBoxShape* pBoxShape = new btBoxShape(btVector3(1.0f, 1.0f, 1.0f)); **/
/*REM*		// give our box an initial position of (0,0,0) **/
/*REM*		btTransform transform; **/
/*REM*		transform.setIdentity(); **/
/*REM*		transform.setOrigin(btVector3(0.0f, 0.0f, 0.0f)); **/
/*REM*		// create a motion state **/
/*REM*		m_pMotionState = new OpenGLMotionState(transform); **/
/*REM*		// create the rigid body construction info object, giving it a  **/
/*REM*		// mass of 1, the motion state, and the shape **/
/*REM*		btRigidBody::btRigidBodyConstructionInfo rbInfo(1.0f, m_pMotionState, pBoxShape); **/
/*REM*		btRigidBody* pRigidBody = new btRigidBody(rbInfo); **/
/*REM*		// inform our world that we just created a new rigid body for  **/
/*REM*		// it to manage **/
/*REM*		m_pWorld->addRigidBody(pRigidBody); **/

/*ADD*/	// create a ground plane
/*ADD*/	CreateGameObject(new btBoxShape(btVector3(1,50,50)), 0, btVector3(0.2f, 0.6f, 0.6f), btVector3(0.0f, 0.0f, 0.0f));
/*ADD*/
/*ADD*/	// create our original red box
/*ADD*/	CreateGameObject(new btBoxShape(btVector3(1,1,1)), 1.0, btVector3(1.0f, 0.2f, 0.2f), btVector3(0.0f, 10.0f, 0.0f));
/*ADD*/
/*ADD*/	// create a second box
/*ADD*/	CreateGameObject(new btBoxShape(btVector3(1,1,1)), 1.0, btVector3(0.0f, 0.2f, 0.8f), btVector3(1.25f, 20.0f, 0.0f));
}
void KeyboardBehaviour::PlaceObject()
{
    if(BindArray.size() > 0 && BindArray.at(0).pickedUp == true && GetKeyDown(sf::Keyboard::Num0))
    {
        std::cout << "Placing Object" << std::endl;
        CreateGameObject(BindArray.at(0).mesh, BindArray.at(0).PositionToPlace, BindArray.at(0).IDname, 0, BindArray.at(0).textureMaterial);
        BindArray.at(0).pickedUp = false;
    }
    else if(BindArray.size() > 1 && BindArray.at(1).pickedUp == true && GetKeyDown(sf::Keyboard::Num1))
    {
        std::cout << "Placing Object" << std::endl;
        CreateGameObject(BindArray.at(1).mesh, BindArray.at(1).PositionToPlace, BindArray.at(1).IDname, 1, BindArray.at(1).textureMaterial);
        BindArray.at(1).pickedUp = false;
    }
    else if(BindArray.size() > 2 && BindArray.at(2).pickedUp == true && GetKeyDown(sf::Keyboard::Num2))
    {
        CreateGameObject(BindArray.at(2).mesh, BindArray.at(2).PositionToPlace, BindArray.at(2).IDname, 2, BindArray.at(2).textureMaterial);
        BindArray.at(2).pickedUp = false;
    }
    else if(BindArray.size() > 3 && BindArray.at(3).pickedUp == true && GetKeyDown(sf::Keyboard::Num3))
    {
        CreateGameObject(BindArray.at(3).mesh, BindArray.at(3).PositionToPlace, BindArray.at(3).IDname, 3, BindArray.at(3).textureMaterial);
        BindArray.at(3).pickedUp = false;
    }
    else if(BindArray.size() > 4 && BindArray.at(4).pickedUp == true && GetKeyDown(sf::Keyboard::Num4))
    {
        CreateGameObject(BindArray.at(4).mesh, BindArray.at(4).PositionToPlace, BindArray.at(4).IDname, 4, BindArray.at(4).textureMaterial);
        BindArray.at(4).pickedUp = false;
    }
    else if(BindArray.size() > 5 && BindArray.at(5).pickedUp == true && GetKeyDown(sf::Keyboard::Num5))
    {
        CreateGameObject(BindArray.at(5).mesh, BindArray.at(5).PositionToPlace, BindArray.at(5).IDname, 5, BindArray.at(5).textureMaterial);
        BindArray.at(5).pickedUp = false;
    }
    else if(BindArray.size() > 6 && BindArray.at(6).pickedUp == true && GetKeyDown(sf::Keyboard::Num6))
    {
        CreateGameObject(BindArray.at(6).mesh, BindArray.at(6).PositionToPlace, BindArray.at(6).IDname, 6, BindArray.at(6).textureMaterial);
        BindArray.at(6).pickedUp = false;
    }
    else if(BindArray.size() > 7 && BindArray.at(7).pickedUp == true && GetKeyDown(sf::Keyboard::Num7))
    {
        CreateGameObject(BindArray.at(7).mesh, BindArray.at(7).PositionToPlace, BindArray.at(7).IDname, 7, BindArray.at(7).textureMaterial);
        BindArray.at(7).pickedUp = false;
    }
    else if(BindArray.size() > 8 && BindArray.at(8).pickedUp == true && GetKeyDown(sf::Keyboard::Num8))
    {
        CreateGameObject(BindArray.at(8).mesh, BindArray.at(8).PositionToPlace, BindArray.at(8).IDname, 8, BindArray.at(8).textureMaterial);
        BindArray.at(8).pickedUp = false;
    }
    else if(BindArray.size() > 9 && BindArray.at(9).pickedUp == true && GetKeyDown(sf::Keyboard::Num9))
    {
        CreateGameObject(BindArray.at(9).mesh, BindArray.at(9).PositionToPlace, BindArray.at(9).IDname, 9, BindArray.at(9).textureMaterial);
        BindArray.at(9).pickedUp = false;
    }
}
void BasicDemo::CollisionEvent(btRigidBody* pBody0, btRigidBody* pBody1) {
	// did the box collide with the trigger?
	if (pBody0 == m_pBox->GetRigidBody() && pBody1 == m_pTrigger ||
		pBody1 == m_pBox->GetRigidBody() && pBody0 == m_pTrigger) {
			// if yes, create a big green box nearby
			CreateGameObject(new btBoxShape(btVector3(2,2,2)), 2.0, btVector3(0.3, 0.7, 0.3), btVector3(5, 10, 0));
	}

	// Impulse testing
	if (pBody0 == m_pExplosion || pBody1 == m_pExplosion) {
		// get the pointer of the other object
		btRigidBody* pOther;
		pBody0 == m_pExplosion ? pOther = (btRigidBody*)pBody1 : pOther = (btRigidBody*)pBody0;
		// wake the object up
		pOther->setActivationState(ACTIVE_TAG);
		// calculate the vector between the object and
		// the center of the explosion
		btVector3 dir = pOther->getWorldTransform().getOrigin() - m_pExplosion->getWorldTransform().getOrigin();
		// get the distance
		float dist = dir.length();
		// calculate the impulse strength
		float strength = EXPLOSION_STRENGTH;
		// follow an inverse-distance rule
		if (dist != 0.0) strength /= dist;
		// normalize the direction vector
		dir.normalize();
		// apply the impulse
		pOther->applyCentralImpulse(dir * strength);
	}
}
	GameObjectPtr SceneManager::AddLevelMesh(Ogre::String meshname)
	{
		Ice::GameObjectPtr object = CreateGameObject();
		//object->SetGlobalScale(Ogre::Vector3(0.1, 0.1, 0.1));	//test
		object->AddComponent(Ice::GOComponentPtr(new Ice::GOCMeshRenderable(meshname, true)));
		object->AddComponent(Ice::GOComponentPtr(new Ice::GOCStaticBody(meshname)));
		object->SetSelectable(false);
		AIManager::Instance().GetNavigationMesh()->AddOgreMesh(object->GetComponent<GOCMeshRenderable>()->GetEntity()->getMesh());
		return object;
	}
void BulletOpenGLApplication::ShootBox(const btVector3 &direction) {
 	// create a new box object
 	GameObject* pObject = CreateGameObject(new btBoxShape(btVector3(1, 1, 1)), 1, btVector3(0.4f, 0.f, 0.4f), m_cameraPosition);
 		
 	// calculate the velocity
 	btVector3 velocity = direction; 
 	velocity.normalize();
 	velocity *= 25.0f;
 		
 	// set the linear velocity of the box
 	pObject->GetRigidBody()->setLinearVelocity(velocity);
}
Example #6
0
// Spawns the object too, without which you can not interact with the object
GameObject* MapMgr::CreateAndSpawnGameObject(uint32 entryID, float x, float y, float z, float o, float scale)
{
	GameObjectInfo* goi = GameObjectNameStorage.LookupEntry(entryID);
	if(!goi)
	{
		LOG_DEBUG("Error looking up entry in CreateAndSpawnGameObject");
		return NULL;
	}

	LOG_DEBUG("CreateAndSpawnGameObject: By Entry '%u'", entryID);

	GameObject* go = CreateGameObject(entryID);

	//Player *chr = m_session->GetPlayer();
	uint32 mapid = GetMapId();
	// Setup game object
	go->CreateFromProto(entryID, mapid, x, y, z, o);
	go->SetScale(scale);
	go->InitAI();
	go->PushToWorld(this);

	// Create spawn instance
	GOSpawn* gs = new GOSpawn;
	gs->entry = go->GetEntry();
	gs->facing = go->GetOrientation();
	gs->faction = go->GetFaction();
	gs->flags = go->GetUInt32Value(GAMEOBJECT_FLAGS);
	gs->id = objmgr.GenerateGameObjectSpawnID();
	gs->o = 0.0f;
	gs->o1 = go->GetParentRotation(0);
	gs->o2 = go->GetParentRotation(2);
	gs->o3 = go->GetParentRotation(3);
	gs->scale = go->GetScale();
	gs->x = go->GetPositionX();
	gs->y = go->GetPositionY();
	gs->z = go->GetPositionZ();
	gs->state = go->GetByte(GAMEOBJECT_BYTES_1, 0);
	//gs->stateNpcLink = 0;
	gs->overrides = go->GetOverrides();

	uint32 cx = GetPosX(x);
	uint32 cy = GetPosY(y);

	GetBaseMap()->GetSpawnsListAndCreate(cx, cy)->GOSpawns.push_back(gs);
	go->m_spawn = gs;

	MapCell* mCell = GetCell(cx, cy);

	if(mCell != NULL)
		mCell->SetLoaded();

	return go;
}
void ImperialStarDestroyer::InitSpaceship( float startX, float startY, float startZ, float startRotDeg, float rotX, float rotY, float rotZ, float dirVecX, float dirVecY, float dirVecZ )
{
	BaseEnemyShip::InitSpaceship(startX, startY, startZ,
		startRotDeg, rotX, rotY, rotZ,
		dirVecX, dirVecY, dirVecZ);
	BaseEnemyShip::ShipSpeed = 50;
	GameObject::SetScale(0.4f, 0.4f, 0.4f);

	if(!WasInited)
	{
		CreateGameObject();
	}
}
/*ADD*/	
/*ADD*/	void CollisionFilteringDemo::CreateObjects() {
/*ADD*/		// create a ground plane
/*ADD*/		CreateGameObject(new btBoxShape(btVector3(1,50,50)), 
/*ADD*/			0, btVector3(0.2f, 0.6f, 0.6f), btVector3(0.0f, 0.0f, 0.0f),
/*ADD*/			COLGROUP_STATIC,
/*ADD*/			/*the ground plane can collide with boxes and spheres*/
/*ADD*/			COLGROUP_BOX | COLGROUP_SPHERE);
/*ADD*/	
/*ADD*/		// create 25 boxes and spheres in a 5x5 stack formation 
/*ADD*/		float yPos = 0;
/*ADD*/		for (int i = 0; i < 25; i++) {
/*ADD*/			// calculate the x and y for the object
/*ADD*/			float xPos = -5 + 2*(float)(i % 5);
/*ADD*/			if (i % 5 == 0) yPos += 2;
/*ADD*/			// create a btVector3 for the position
/*ADD*/			btVector3 position(xPos, yPos, 4);
/*ADD*/	
/*ADD*/			// create a box
/*ADD*/			CreateGameObject(new btBoxShape(btVector3(1,1,1)),
/*ADD*/				1.0f,
/*ADD*/				/*alternate colors*/
/*ADD*/				btVector3(1.0f, 0.2f, i%2),
/*ADD*/				position,
/*ADD*/				COLGROUP_BOX,
/*ADD*/				/*boxes can collide with the ground plane and other boxes*/
/*ADD*/				COLGROUP_BOX | COLGROUP_STATIC);
/*ADD*/	
/*ADD*/			// create a sphere in the same location
/*ADD*/			CreateGameObject(new btSphereShape(1.2),
/*ADD*/				1.0f,
/*ADD*/				/*alternate colors*/
/*ADD*/				btVector3(i%2, 1.0f, 0.2f),
/*ADD*/				position,
/*ADD*/				COLGROUP_SPHERE,
/*ADD*/				/*spheres can collide with the ground plane and other spheres*/
/*ADD*/				COLGROUP_SPHERE | COLGROUP_STATIC);
/*ADD*/		}
/*ADD*/	}
void PlayerSpaceShip::InitSpaceship( float startX, float startY, float startZ,
	float startRotDeg, float rotX, float rotY, float rotZ,
	float dirVecX, float dirVecY, float dirVecZ)
{
	SpaceShip::InitSpaceship(startX, startY, startZ,
		startRotDeg, rotX, rotY, rotZ,
		dirVecX, dirVecY, dirVecZ);
	GameObject::SetScale(0.5f, 0.5f, 0.5f);

	if(!WasInited)
	{
		CreateGameObject();
	}
}
void ImperialTieInterceptor::InitSpaceship(float startX, float startY, float startZ,
	float startRotDeg, float rotX, float rotY, float rotZ,
	float dirVecX, float dirVecY, float dirVecZ)
{
	BaseEnemyShip::InitSpaceship(startX, startY, startZ,
		startRotDeg, rotX, rotY, rotZ,
		dirVecX, dirVecY, dirVecZ);
	BaseEnemyShip::ShipSpeed = 75;
	GameObject::SetScale(0.7f, 0.7f, 0.7f);

	if(!WasInited)
	{
		CreateGameObject();
	}
}
Example #11
0
	void CFactory::TraversePrototypeNode(CXMLNode *ANode, CGameObject *AObject, CGameObject *CurrentProto)
	{
		CGameObject *child;
		string NodeName;
		string ChildName;
		string LocalChildName;

		for (CXMLChildrenList::Iterator it = ANode->Children.Begin(); it != ANode->Children.End(); ++it)
		{
			if ((*it)->GetType() != CXMLNode::XML_NODE_TYPE_NORMAL)
				continue;

			NodeName = (*it)->GetName(); 

			int recursionsLeft = GetRecursionsLeft(NodeName);
			if (recursionsLeft < 1)
			{
				if (recursionsLeft == -1)
					Log("ERROR", "Unlimited recursive reference of prototype '%s'", NodeName.c_str());

				continue;
			}

			IncreaseUsedCount(NodeName);

			ChildName = (*it)->SafeGetAttribute("Name");
			LocalChildName = (*it)->SafeGetAttribute("LocalName");

			child = CreateGameObject(NodeName, ChildName, false);
			if (!child)
			{
				Log("ERROR", "Can't create object of class '%s' from prototype", NodeName.c_str());
				continue;
			}

			CurrentProto->AddLocalName(LocalChildName, child);

			child->Deserialize(*it);
			AObject->Attach(child);

			if (!child->IsPrototype())
				child->FinalizeCreation();

			TraversePrototypeNode(*it, child, CurrentProto);

			DecreaseUsedCount(NodeName);
		}
	}
	//To create GameObjects using Lua file generated LuaActors
	SharedPointer<GameObject> GameObject::CreateGameObject(LuaUtilityHelper::LuaActor i_luaActor)
	{
		SharedPointer<GameObject> temp = CreateGameObject(i_luaActor.position);
		temp->setName(i_luaActor.name);
		
		temp->setGameObjectController(EngineController::GameEngine::getGameObjectController(EngineController::GameEngine::getStringPool()->findString(i_luaActor.gameController)));
		
		if (i_luaActor.collisionHandler != "\0")
			temp->getCollider()->setCollisionHandler(EngineController::GameEngine::getCollisionHandler(EngineController::GameEngine::getStringPool()->findString(i_luaActor.collisionHandler)));
		else 
			temp->getCollider()->setCollisionHandler(EngineController::GameEngine::getCollisionHandler(EngineController::GameEngine::getStringPool()->findString("Default")));

		
		for (unsigned __int16 i = 0; i < i_luaActor.collidingWith.size(); i++)
			temp->getCollider()->addToCollideWith(EngineController::GameEngine::getStringPool()->findString(i_luaActor.collidingWith[i]));
				temp->getPhysicsComponent()->setMaxAcceleration(i_luaActor.velocity.length());

		temp->getPhysicsComponent()->setMass(i_luaActor.mass);
		temp->getCollider()->setBoundingBox(i_luaActor.collisionBox);
		temp->type = i_luaActor.category;

		
		if (myEngine::utils::StringHash(i_luaActor.category) == myEngine::utils::StringHash( "Player"))
		{
			temp->initializeSprite(myEngine::World::getWorld()->getGameConfiguration().playerTexture,
				myEngine::getAsCheesyDimension(i_luaActor.spriteSize.getX(), i_luaActor.spriteSize.getY()),
				myEngine::getAsCheesyRGBA(i_luaActor.color));

		}
		else 
			temp->initializeSprite(myEngine::World::getWorld()->getGameConfiguration().monsterTexture,
			myEngine::getAsCheesyDimension(i_luaActor.spriteSize.getX(), i_luaActor.spriteSize.getY()),
			myEngine::getAsCheesyRGBA(i_luaActor.color));

		return temp;
	}
void BasicDemo::CreateObjects() {
	// create a ground plane
	CreateGameObject(new btBoxShape(btVector3(1,50,50)), 0, btVector3(0.2f, 0.6f, 0.6f), btVector3(0.0f, 0.0f, 0.0f));

	// create our red box, but store the pointer for future usage
	m_pBox = CreateGameObject(new btBoxShape(btVector3(1,1,1)), 1.0, btVector3(1.0f, 0.2f, 0.2f), btVector3(0.0f, 10.0f, 0.0f));

	// create a second box
	CreateGameObject(new btBoxShape(btVector3(1,1,1)), 1.0, btVector3(0.0f, 0.2f, 0.8f), btVector3(1.25f, 20.0f, 0.0f));

	// create a trigger volume
	m_pTrigger = new btCollisionObject();
	// create a box for the trigger's shape
	m_pTrigger->setCollisionShape(new btBoxShape(btVector3(1,0.25,1)));
	// set the trigger's position
	btTransform triggerTrans;
	triggerTrans.setIdentity();
	triggerTrans.setOrigin(btVector3(0,1.5,0));
	m_pTrigger->setWorldTransform(triggerTrans);
	// flag the trigger to ignore contact responses
	m_pTrigger->setCollisionFlags(btCollisionObject::CF_NO_CONTACT_RESPONSE);
	// add the trigger to our world
	m_pWorld->addCollisionObject(m_pTrigger);

	// create a yellow sphere
	CreateGameObject(new btSphereShape(1.0f), 1.0, btVector3(0.7f, 0.7f, 0.0f), btVector3(-5.0, 10.0f, 0.0f));

	// create a green cylinder
	CreateGameObject(new btCylinderShape(btVector3(1,1,1)), 1.0, btVector3(0.0f, 0.7f, 0.0f), btVector3(-2, 10.0f, 0.0f));

	// create a vertex cloud defining a square-based pyramid
	btVector3 points[5] = {btVector3(-0.5,1,1),
		btVector3(-0.5,1,-1),
		btVector3(-0.5,-1,1),
		btVector3(-0.5,-1,-1),
		btVector3(1,0,0)};
	// create our convex hull
	btConvexHullShape* pShape = new btConvexHullShape(&points[0].getX(),5);
	// initialize the object as a polyhedron
	pShape->initializePolyhedralFeatures();
	// create the game object using our convex hull shape
	CreateGameObject(pShape, 1.0, btVector3(1,1,1), btVector3(5, 15, 0));

/*ADD*/		// create two shapes for the rod and the load
/*ADD*/		btCollisionShape* pRod = new btBoxShape(btVector3(1.5f, 0.2f, 0.2f));
/*ADD*/		btCollisionShape* pLoad = new btSphereShape(0.5f);
/*ADD*/		// create a transform we'll use to set each object's position
/*ADD*/		btTransform trans;
/*ADD*/		trans.setIdentity();
/*ADD*/		// create our compound shape
/*ADD*/		btCompoundShape* pCompound = new btCompoundShape();
/*ADD*/		// add the rod
/*ADD*/		pCompound->addChildShape(trans, pRod);
/*ADD*/		trans.setOrigin(btVector3(-1.75f, 0.0f, 0.0f));
/*ADD*/		// add the top load
/*ADD*/		pCompound->addChildShape(trans, pLoad);
/*ADD*/		trans.setIdentity();
/*ADD*/		// add the bottom load
/*ADD*/		trans.setOrigin(btVector3(1.75f, 0.0f, 0.0f));
/*ADD*/		pCompound->addChildShape(trans, pLoad);
/*ADD*/		// create a game object using the compound shape
/*ADD*/		CreateGameObject(pCompound, 2.0f, btVector3(0.8,0.4,0.1), btVector3(-4, 10.0f, 0.0f));

}
Example #14
0
bool MapMgr::Do()
{
#ifdef WIN32
	threadid=GetCurrentThreadId();
#endif
	thread_running = true;
	ThreadState =THREADSTATE_BUSY;
	SetThreadName("Map mgr - M%u|I%u",this->_mapId ,this->m_instanceID);
	ObjectSet::iterator i;
	uint32 last_exec=getMSTime();

	/* create static objects */
	for(GOSpawnList::iterator itr = _map->staticSpawns.GOSpawns.begin(); itr != _map->staticSpawns.GOSpawns.end(); ++itr)
	{
		GameObject * obj = CreateGameObject((*itr)->entry);
		obj->Load((*itr));
		_mapWideStaticObjects.insert(obj);
	}

	for(CreatureSpawnList::iterator itr = _map->staticSpawns.CreatureSpawns.begin(); itr != _map->staticSpawns.CreatureSpawns.end(); ++itr)
	{
		Creature * obj = CreateCreature((*itr)->entry);
		obj->Load(*itr, 0, pMapInfo);
		_mapWideStaticObjects.insert(obj);
	}

	/* add static objects */
	for(set<Object*>::iterator itr = _mapWideStaticObjects.begin(); itr != _mapWideStaticObjects.end(); ++itr)
		PushStaticObject(*itr);

	/* load corpses */
	objmgr.LoadCorpses(this);

	// always declare local variables outside of the loop!
	// otherwise theres a lot of sub esp; going on.

	uint32 exec_time, exec_start;
#ifdef WIN32
	HANDLE hThread = GetCurrentThread();
#endif
	while((ThreadState != THREADSTATE_TERMINATE) && !_shutdown)
	{
		exec_start=getMSTime();
		//first push to world new objects
		m_objectinsertlock.Acquire();//<<<<<<<<<<<<<<<<
		if(m_objectinsertpool.size())
		{
			for(i=m_objectinsertpool.begin();i!=m_objectinsertpool.end();i++)
			{
				//PushObject(*i);
				(*i)->PushToWorld(this);
			}
			m_objectinsertpool.clear();
		}
		m_objectinsertlock.Release();//>>>>>>>>>>>>>>>>
		//-------------------------------------------------------
				
		//Now update sessions of this map + objects
		_PerformObjectDuties();

		last_exec=getMSTime();
		exec_time=last_exec-exec_start;
		if(exec_time<MAP_MGR_UPDATE_PERIOD)
		{
			/*
				The common place I see this is waiting for a Win32 thread to exit. I used to come up with all sorts of goofy,
				elaborate event-based systems to do this myself until I discovered that thread handles are waitable. Just use
				WaitForSingleObject() on the thread handle and you're done. No risking race conditions with the thread exit code.
				I think pthreads has pthread_join() for this too.

				- http://www.virtualdub.org/blog/pivot/entry.php?id=62
			*/

#ifdef WIN32
			WaitForSingleObject(hThread, MAP_MGR_UPDATE_PERIOD-exec_time);
#else
			Sleep(MAP_MGR_UPDATE_PERIOD-exec_time);
#endif
		}

		//////////////////////////////////////////////////////////////////////////
		// Check if we have to die :P
		//////////////////////////////////////////////////////////////////////////
		if(InactiveMoveTime && UNIXTIME >= InactiveMoveTime)
			break;
	}

	// Clear the instance's reference to us.
	if(m_battleground)
	{
		BattlegroundManager.DeleteBattleground(m_battleground);
		sInstanceMgr.DeleteBattlegroundInstance( GetMapId(), GetInstanceID() );
	}

	if(pInstance)
	{
		// check for a non-raid instance, these expire after 10 minutes.
		if(GetMapInfo()->type == INSTANCE_NONRAID || pInstance->m_isBattleground)
		{
			pInstance->m_mapMgr = NULL;
			sInstanceMgr._DeleteInstance(pInstance, true);
		}
		else
		{
			// just null out the pointer
			pInstance->m_mapMgr=NULL;
		}
	}
	else if(GetMapInfo()->type == INSTANCE_NULL)
		sInstanceMgr.m_singleMaps[GetMapId()] = NULL;

	// Teleport any left-over players out.
	TeleportPlayers();	

	thread_running = false;
	if(thread_kill_only)
		return false;

	// delete ourselves
	delete this;

	// already deleted, so the threadpool doesn't have to.
	return false;
}
Example #15
0
bool MapMgr::Do()
{
#ifdef WIN32
	threadid = GetCurrentThreadId();
#endif

	t_currentMapContext.set(this);

	thread_running = true;
	ThreadState.SetVal(THREADSTATE_BUSY);
	SetThreadName("Map mgr - M%u|I%u", this->_mapId , this->m_instanceID);
	ObjectSet::iterator i;
	uint32 last_exec = getMSTime();

	// Create Instance script
	LoadInstanceScript();

	/* create static objects */
	for(GOSpawnList::iterator itr = _map->staticSpawns.GOSpawns.begin(); itr != _map->staticSpawns.GOSpawns.end(); ++itr)
	{
		GameObject* obj = CreateGameObject((*itr)->entry);
		obj->Load((*itr));
		PushStaticObject(obj);
	}

	// Call script OnLoad virtual procedure
	CALL_INSTANCE_SCRIPT_EVENT(this, OnLoad)();

	for(CreatureSpawnList::iterator itr = _map->staticSpawns.CreatureSpawns.begin(); itr != _map->staticSpawns.CreatureSpawns.end(); ++itr)
	{
		Creature* obj = CreateCreature((*itr)->entry);
		obj->Load(*itr, 0, pMapInfo);
		PushStaticObject(obj);
	}

	/* load corpses */
	objmgr.LoadCorpses(this);
	worldstateshandler.InitWorldStates( objmgr.GetWorldStatesForMap( _mapId ) );
	worldstateshandler.setObserver( this );

	// always declare local variables outside of the loop!
	// otherwise there's a lot of sub esp; going on.

	uint32 exec_time, exec_start;

	while((GetThreadState() != THREADSTATE_TERMINATE) && !_shutdown)
	{
		exec_start = getMSTime();

///////////////////////////////////////////// first push to world new objects ////////////////////////////////////////////

		m_objectinsertlock.Acquire();

		if(m_objectinsertpool.size())
		{
			for(i = m_objectinsertpool.begin(); i != m_objectinsertpool.end(); ++i)
			{
				Object* o = *i;

				o->PushToWorld(this);
			}

			m_objectinsertpool.clear();
		}

		m_objectinsertlock.Release();

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

		//Now update sessions of this map + objects
		_PerformObjectDuties();

		last_exec = getMSTime();
		exec_time = last_exec - exec_start;
		if(exec_time < MAP_MGR_UPDATE_PERIOD)
		{

			Arcemu::Sleep(MAP_MGR_UPDATE_PERIOD - exec_time);

		}

		//////////////////////////////////////////////////////////////////////////
		// Check if we have to die :P
		//////////////////////////////////////////////////////////////////////////
		if(InactiveMoveTime && UNIXTIME >= InactiveMoveTime)
			break;
	}

	// Teleport any left-over players out.
	TeleportPlayers();

	// Clear the instance's reference to us.
	if(m_battleground)
	{
		BattlegroundManager.DeleteBattleground(m_battleground);
		sInstanceMgr.DeleteBattlegroundInstance(GetMapId(), GetInstanceID());
	}

	if(pInstance)
	{
		// check for a non-raid instance, these expire after 10 minutes.
		if(GetMapInfo()->type == INSTANCE_NONRAID || pInstance->m_isBattleground)
		{
			pInstance->m_mapMgr = NULL;
			sInstanceMgr._DeleteInstance(pInstance, true);
			pInstance = NULL;
		}
		else
		{
			// just null out the pointer
			pInstance->m_mapMgr = NULL;
		}
	}
	else if(GetMapInfo()->type == INSTANCE_NULL)
		sInstanceMgr.m_singleMaps[GetMapId()] = NULL;

	thread_running = false;
	if(thread_kill_only)
		return false;

	// delete ourselves
	delete this;

	// already deleted, so the threadpool doesn't have to.
	return false;
}