RESULT BehaviorManager::PopBehaviorFromGameObject( IN HGameObject hGameObject, IN StateMachineQueue queue ) { RESULT rval = S_OK; GameObject* pGameObject = NULL; StateMachineManager* pStateMachineManager = NULL; CHR(GOMan.GetGameObjectPointer( hGameObject, &pGameObject )); pStateMachineManager = pGameObject->GetStateMachineManager(); CPREx(pStateMachineManager, E_UNEXPECTED); pStateMachineManager->PopStateMachine( queue ); RETAILMSG(ZONE_STATEMACHINE | ZONE_VERBOSE, "BehaviorManager::PopBehaviorFromGameObject( \"%s\", queue: %d )", pGameObject->GetName().c_str(), queue); Exit: if (FAILED(rval)) { RETAILMSG(ZONE_ERROR, "ERROR: BehaviorManager::PopBehaviorFromGameObject( \"%s\" ) GO not found, or has no Behaviors", pGameObject ? pGameObject->GetName().c_str() : "NULL"); } return rval; }
void Layer::AddRemoveObjects() { for(std::list<string>::iterator iterator = m_deleteQueue.begin(); iterator != m_deleteQueue.end(); iterator++) { GameObject * n = GetObjectByName(*iterator); if (n!=NULL && n->isDestroyed == false) { n->isDestroyed = true; n->OnDestroy(); m_objectByRef.erase(*iterator); //delete(n); } } m_deleteQueue.clear(); for(std::list<GameObject *>::iterator iterator = m_addQueue.begin(); iterator != m_addQueue.end(); iterator++) { GameObject * nGo = *iterator; nGo->layer=layerIndex; nGo->isActive = true; string objectName = nGo->GetName(); string appendString = ""; int append = 0; bool insertOk = false; while(!insertOk) { string tmp = objectName + appendString; nGo->SetName(tmp); std::pair<ObjectMap::iterator, bool> res = m_objectByRef.insert(pair<string, GameObject*>(tmp,nGo)); if ( ! res.second ) { if (m_objectByRef[tmp] == nGo) { insertOk = true; } else { append++; stringstream streamVal; streamVal << append; appendString = streamVal.str(); int h = 4; } } else { insertOk = true; } } nGo->Start(); } m_addQueue.clear(); }
objectID GameObjectManager::GetIDByName( const char* name ) { std::map<int, GameObject*>::iterator b = m_allEntities.begin(); std::map<int, GameObject*>::iterator e = m_allEntities.end(); for ( ; b != e; b++) { GameObject* pkGameObject = (*b).second; if (strcmp(pkGameObject->GetName(), name) == 0) return pkGameObject->GetID(); } return (INVALID_OBJECT_ID); }
/*---------------------------------------------------------------------------* Name: Dump Description: Dumps the accumulated log of a particular object to the debug console. Arguments: id : ID of the object Returns: None. *---------------------------------------------------------------------------*/ void DebugLog::Dump( objectID id ) { GameObject* obj = g_database.Find( id ); printf( "DebugLog: %s, id=%d\n", obj->GetName(), id ); LoggingContainer::iterator i; for( i=m_log.begin(); i!=m_log.end(); ++i ) { LogEntry* log = *i; if( log && log->m_owner == id ) { PrintLogEntry( *log ); } } }
/// Search for a direct child of the specified object with the given name. /// /// @param[in] pObject GameObject for which to locate a child, or null to search through top-level objects. /// @param[in] name GameObject name. /// @param[in] instanceIndex GameObject instance index. /// /// @return Pointer to the child object if found, null if not found. GameObject* GameObject::FindChildOf( const GameObject* pObject, Name name, uint32_t instanceIndex ) { HELIUM_ASSERT( !name.IsEmpty() ); if( name.IsEmpty() ) { return NULL; } ScopeReadLock scopeLock( sm_objectListLock ); for( GameObject* pChild = ( pObject ? pObject->m_wpFirstChild : sm_wpFirstTopLevelObject ); pChild != NULL; pChild = pChild->m_wpNextSibling ) { if( pChild->GetName() == name && pChild->GetInstanceIndex() == instanceIndex ) { return pChild; } } return NULL; }
AEResult GameObjectTreeWidget::GameObjectNameChanged(uint64_t gameObjectID) { //////////////////////////////////////////// //No need to lock this function as it is internal //and only a name been reflected //////////////////////////////////////////// if(!m_IsReady) { return AEResult::NotReady; } AEAssert(m_EngineViewer != nullptr); if (m_EngineViewer == nullptr) { AETODO("Add new error GameAppNull"); return AEResult::NullObj; } GameObject* gameObject = m_EngineViewer->GetGameObjectManager()->GetGameObject(gameObjectID); if(gameObject == nullptr) { return AEResult::NotFound; } QTreeWidgetItem* item = FindBranch(gameObjectID); AEAssert(item != nullptr); if(item == nullptr) { return AEResult::NotFound; } QString name = QString::fromStdWString(gameObject->GetName()); item->setData(0, Qt::ItemDataRole::DisplayRole, name); return AEResult::Ok; }
void Player::Raycast(const GameContext& gameContext) { GameScene* scene = GetScene(); XMFLOAT3 pos = GetTransform()->GetPosition(); XMFLOAT3 fw = GetTransform()->GetForward(); PxVec3 rayOrigin(pos.x,pos.y + 1.f,pos.z), rayDirection(fw.x,fw.y,fw.z); rayOrigin.x += fw.x * 2.5f; rayOrigin.z += fw.z * 2.5f; const PxU32 bufSize = 20; PxRaycastHit hit[bufSize]; PxRaycastBuffer buf(hit, bufSize); // [out] Blocking and touching hits will be stored here if(scene->GetPhysxProxy()->Raycast(rayOrigin, rayDirection, 5000, buf)) { for(PxU32 i = 0; i < buf.nbTouches; ++i) { BaseComponent* component = static_cast<BaseComponent*>(buf.touches[i].actor->userData); GameObject* go = component->GetGameObject(); string name = go->GetName(); cout << "RAYCAST OBJECT: " << name << endl; if(name == "Enemy") { Enemy* enemy = reinterpret_cast<Enemy*>(go); int dmg = 12.5f; enemy->Damage(dmg); } } PxVec3 vel = rayDirection * 1000; auto laser = new Laser(XMFLOAT3(vel.x, vel.y, vel.z)); AddChild(laser); } }
static bool GOMove_Command(ChatHandler* handler, const char* args) { if (!args) return false; char* ID_t = strtok((char*)args, " "); if (!ID_t) return false; uint32 ID = (uint32)atol(ID_t); char* GObjectID_C = strtok(NULL, " "); uint32 GObjectID = 0; bool isHex = false; if (GObjectID_C) { GObjectID = strtoul(GObjectID_C, NULL, 0); // can take in hex as well as dec isHex = (std::string(GObjectID_C).find("0x") != std::string::npos); } char* ARG_t = strtok(NULL, " "); uint32 ARG = 0; if (ARG_t) ARG = (uint32)atol(ARG_t); WorldSession* session = handler->GetSession(); Player* player = session->GetPlayer(); uint64 playerGUID = player->GetGUID(); if (ID < SPAWN) // no args { if (ID >= DELET && ID <= GOTO) // has target (needs retrieve gameobject) { GameObject* target = GetObjectByGObjectID(player, GObjectID, isHex); if (!target) ChatHandler(player->GetSession()).PSendSysMessage("Object GUID: %u not found. Temp(%u)", GObjectID, isHex ? 1 : 0); else { float x,y,z,o; target->GetPosition(x,y,z,o); uint32 p = target->GetPhaseMask(); switch(ID) { case DELET: DeleteObject(target/*, isHex ? GObjectID : 0*/); SendSelectionInfo(player, GObjectID, isHex, false); break; case X: SpawnObject(player,player->GetPositionX(),y,z,o,p,true,GObjectID, isHex); break; case Y: SpawnObject(player,x,player->GetPositionY(),z,o,p,true,GObjectID, isHex); break; case Z: SpawnObject(player,x,y,player->GetPositionZ(),o,p,true,GObjectID, isHex); break; case O: SpawnObject(player,x,y,z,player->GetOrientation(),p,true,GObjectID, isHex); break; case GOTO: player->TeleportTo(target->GetMapId(), x,y,z,o); break; case RESPAWN: SpawnObject(player,x,y,z,o,p,false,target->GetEntry(), isHex); break; case GROUND: { float ground = target->GetMap()->GetHeight(target->GetPhaseMask(), x, y, MAX_HEIGHT); if(ground != INVALID_HEIGHT) SpawnObject(player,x,y,ground,o,p,true,GObjectID, isHex); } break; } } } else { switch(ID) { case TEST: session->SendAreaTriggerMessage(player->GetName().c_str()); break; case FACE: { float piper2 = M_PI/2; float multi = player->GetOrientation()/piper2; float multi_int = floor(multi); float new_ori = (multi-multi_int > 0.5f) ? (multi_int+1)*piper2 : multi_int*piper2; player->SetFacingTo(new_ori); } break; case SAVE: SaveObject(player, GObjectID, isHex); break; case SELECTNEAR: { GameObject* object = handler->GetNearbyGameObject(); object = GetClosestGObjectID(player, object); if (!object) ChatHandler(player->GetSession()).PSendSysMessage("No objects found"); else { bool isHex = (object->GetGUIDHigh() != HIGHGUID_GAMEOBJECT); SendSelectionInfo(player, isHex ? object->GetGUIDHigh() : object->GetDBTableGUIDLow() ? object->GetDBTableGUIDLow() : object->GetGUIDLow(), isHex, true); session->SendAreaTriggerMessage("Selected %s", object->GetName().c_str()); } } break; } } } else if (ARG && ID >= SPAWN) { if (ID >= NORTH && ID <= PHASE) { GameObject* target = GetObjectByGObjectID(player, GObjectID, isHex); if (!target) ChatHandler(player->GetSession()).PSendSysMessage("Object GUID: %u not found. Temporary: %s", GObjectID, isHex ? "true" : "false"); else { float x,y,z,o; target->GetPosition(x,y,z,o); uint32 p = target->GetPhaseMask(); switch(ID) { case NORTH: SpawnObject(player,x+((float)ARG/100),y,z,o,p,true,GObjectID, isHex); break; case EAST: SpawnObject(player,x,y-((float)ARG/100),z,o,p,true,GObjectID, isHex); break; case SOUTH: SpawnObject(player,x-((float)ARG/100),y,z,o,p,true,GObjectID, isHex); break; case WEST: SpawnObject(player,x,y+((float)ARG/100),z,o,p,true,GObjectID, isHex); break; case NORTHEAST: SpawnObject(player,x+((float)ARG/100),y-((float)ARG/100),z,o,p,true,GObjectID, isHex); break; case SOUTHEAST: SpawnObject(player,x-((float)ARG/100),y-((float)ARG/100),z,o,p,true,GObjectID, isHex); break; case SOUTHWEST: SpawnObject(player,x-((float)ARG/100),y+((float)ARG/100),z,o,p,true,GObjectID, isHex); break; case NORTHWEST: SpawnObject(player,x+((float)ARG/100),y+((float)ARG/100),z,o,p,true,GObjectID, isHex); break; case UP: SpawnObject(player,x,y,z+((float)ARG/100),o,p,true,GObjectID, isHex); break; case DOWN: SpawnObject(player,x,y,z-((float)ARG/100),o,p,true,GObjectID, isHex); break; case RIGHT: SpawnObject(player,x,y,z,o-((float)ARG/100),p,true,GObjectID, isHex); break; case LEFT: SpawnObject(player,x,y,z,o+((float)ARG/100),p,true,GObjectID, isHex); break; case PHASE: SpawnObject(player,x,y,z,o,ARG,true,GObjectID, isHex); break; } } } else { switch(ID) { case SPAWN: { if (SpawnObject(player, player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetOrientation(), player->GetPhaseMaskForSpawn(), false, ARG, false, true)) SpawnQue[player->GetGUID()] = ARG; } break; case SPAWNSPELL: { SpawnQue[player->GetGUID()] = ARG; } break; case SELECTALLNEAR: { if (ARG > 5000) ARG = 5000; QueryResult result = WorldDatabase.PQuery("SELECT guid, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM gameobject WHERE map = '%u' AND position_x BETWEEN '%f'-'%u' AND '%f'+'%u' AND position_y BETWEEN '%f'-'%u' AND '%f'+'%u' AND position_z BETWEEN '%f'-'%u' AND '%f'+'%u' ORDER BY order_ ASC LIMIT 100", player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetMapId(), player->GetPositionX(), ARG, player->GetPositionX(), ARG, player->GetPositionY(), ARG, player->GetPositionY(), ARG, player->GetPositionZ(), ARG, player->GetPositionZ(), ARG); if (result) { do { Field* fields = result->Fetch(); uint32 guidLow = fields[0].GetUInt32(); if (GameObject* object = GetObjectByGObjectID(player, guidLow, false)) SendSelectionInfo(player, guidLow, false, true); } while (result->NextRow()); } for(std::set<uint32>::const_iterator it = GObjects.begin(); it != GObjects.end();) { GameObject* temp = player->GetGameObject(*it); if(!temp) { GObjects.erase(*it++); continue; } if(temp->IsWithinDistInMap(player, ARG)) SendSelectionInfo(player, (*it), true, true); ++it; } } break; } } } else return false; return true; }
static void SendSelectionInfo(Player* player, uint32 GObjectID, bool isHex, bool add) // Sends an addon message for selected objects list { if (!player || !GObjectID) return; std::ostringstream ss; if (!add) if(!isHex) ss << "GOMOVE|REMOVE|" << std::dec << (uint32)GObjectID <<"||0"; else ss << "GOMOVE|REMOVE|" << "0x" << std::hex << GObjectID <<"||0"; else { GameObject* object = GetObjectByGObjectID(player, GObjectID, isHex); if(!object) return; if(!isHex) ss <<"GOMOVE|ADD|" << std::dec << (uint32)GObjectID << std::dec <<"|"<< object->GetName() <<"|"<< object->GetEntry(); else ss <<"GOMOVE|ADD|" << "0x" << std::hex << GObjectID << std::dec <<"|"<< object->GetName() <<"|"<< object->GetEntry(); } SendAddonMessage(player, ss.str().c_str()); }
int main(int argc, char *argv[]){ glutInit(&argc, argv); GameDebugger* debugger = GameDebugger::GetInstance(); assert(debugger->OpenDebugFile()); debugger->WriteDebugMessageToConsole("Hello, World", 31); debugger->WriteToDebugFile("Wrote to file", 32); TaskQueue *taskManager = new TaskQueue(NUM_THREADS); ConsoleCreateRoom(); GameRoom gr; if (argc > 1){ string path = pathCat(GAME_DATA_ROOMS_FOLDER, argv[1]); GameRoom::LoadRoom(path.c_str(), gr); } //For testing purposes. To make sure it reads debug.room char debugName[1000]; strcpy(debugName, GAME_DATA_ROOMS_FOLDER); strcat(debugName, "debug.room"); GameRoom debug; assert(GameRoom::LoadRoom(debugName, debug)); vector<GameObject*> obs = debug.GetGameObjects(); //map<string, GameWorldObject>::iterator wobs = debug.GetRoomWorldObjectsIterator(); for(unsigned int w = 0; w<obs.size(); w++){ //load starting meshes GameObject *gwo = obs[w]; cout<<gwo->GetName()<<endl; MyMesh *tmp = new MyMesh(); if (gwo->GetMeshFile()){ string fname = pathCat(".", gwo->GetMeshFile()); if (! MyMeshIO::LoadMesh(*tmp, fname)){ cerr<<"couldn't load (" << gwo->GetMeshFile() << ") for " <<gwo -> GetName() <<endl; gwo->SetMesh(NULL); }else{ gwo->SetMesh(tmp); NavShot::room = tmp; } } } ComputeBoundingBoxesAndPhysicsConstants(obs); //cin.ignore(1); /////////////////////////////////////////////////// //TODO: load from file GameState *gs = GameState::GetInstance(); Vector3f pos(0.0f, 0, -10.0f); Vector3f up(0, 1.0f, 0); Vector3f dir(0.0f, 0, 1.0f); float radius =0, n = 0.1, f = 600, fovy = 80, aspect = ((float)16.0/9.0); Camera cam(pos, dir, up, radius, n, f, fovy, aspect); gs->SetRoom(&debug); gs->SetCamera(&cam); Vector3f enemyPos(0.0f, 3.0f, 10.0f); gs->AddActor(new MetaballEnemy(enemyPos, 2, 2.0f)); Render::gameState = gs; Render::GlutInitialize(); SCollision::gameState = gs; RegisterControls(); Controller::Initialize(taskManager, gs); ///////////////////////////////////////////////// // TO DO: // Pass GameRoom debug to Render module. Render the // room. ///////////////////////////////////////////////// glutTimerFunc(0, Controller::GlutSync, 0); //glutMotionFunc(mouseMoveCB); //glutMouseFunc(mouseFunc); Sound::InitializeSounds(); Music *music = new Music("sounds/run2.ogg", 0.3f); music->Loop(); Sound *backgroundNoise = new Sound("sounds/metallic_roar.wav", 0.2f); backgroundNoise->Loop(); glutMainLoop(); //this should only be called once, and AT THE END of the initialization routine. Sound::UninitializeSounds(); assert(debugger->CloseDebugFile()); return 0; }