GameObjectPtr Level::CreateObject(std::string type, std::string name) { GameObjectPtr gameObj = GameClassRegistry::Get().Create(type); gameObj->SetLevel(this); if(name != "") gameObj->SetName(name); mGameObjects[gameObj->GetName()] = gameObj; return gameObj; }
bool Scene::SerializeObject(GameObjectPtr pObj, DataStream* pStream) { const std::string& name = pObj->GetName(); pStream->WriteString(name); const math::Matrix44& local = pObj->GetLocalTransform(); pStream->Write((void*)&local, sizeof(local)); uint16 nCom = pObj->GetComponentCount(); pStream->WriteInt16(nCom - 1); for(int i = 0; i < nCom; ++i) { GameObjectComponentPtr pCom = pObj->GetComponent(i); pStream->WriteString(pCom->GetName()); if(false == pCom->Serialize(pStream)) { logger() << "failed to save component: " << pCom->GetName() << "\n"; return false; } } uint16 nChild = 0; GameObjectPtr pChild = pObj->GetFirstChild(); while(pChild) { ++nChild; pChild = pChild->GetNextNode(); } pStream->WriteInt16(nChild); pChild = pObj->GetFirstChild(); while(pChild) { if(false == SerializeObject(pChild, pStream)) { return false; } pChild = pChild->GetNextNode(); } return true; }
void EditablePagedLevel::OnMouseDown( int btn, int x, int y ) { #ifdef USE_INVOKER if (NeedInvoke()) { BeginInvoke(std::bind(&EditablePagedLevel::OnMouseDown, this, btn, x, y)); } else #endif { m_MouseEvtPos.X = x; m_MouseEvtPos.Y = y; m_BtnId = btn; if (EMB_LEFT == btn) { core::position2df onpos = core::position2df(float(x), float(y)); SelectPageByPoint(onpos); GameObjectPtr obj = GetEditablePage()->GetGameObjectByPoint(onpos); if (obj) { ChangeState(LEVEL_STATE_MOVE_OBJECT); LogDebug("Selected object: " << obj->GetName().c_str()); } m_SelectedObject = obj; //Can be NULL //m_OnGameObjectSelectedSignal(obj); } else if (EMB_RIGHT == btn) { ChangeState(LEVEL_STATE_MOVE_LEVEL); } } }
void Level::Load(std::string name) { GameObjectPtr game = GameClassRegistry::Get().Create("ShooterGame"); game->SetLevel(this); mGameObjects[game->GetName()] = game; }