int PhysicsServer::GetObjectID( const char* name, JObject* context ) { int nObj = m_Objects.size(); for (int i = 0; i < nObj; i++) { JObject* pObject = m_Objects[i]; if (!pObject) continue; if (!stricmp( name, pObject->GetName() ) && (!context || pObject->GetParent() == context )) return i; } if (context == NULL) { context = this; } PhysObject* pObj = g_pObjectServer->FindObject<PhysObject>( name, context ); if (pObj) { m_Objects.push_back( pObj ); int id = m_Objects.size() - 1; pObj->SetID( id ); return id; } return -1; } // PhysicsServer::GetObjectID
int JLuaServer::FnSetParent( lua_State* pLua ) { if (lua_gettop( pLua ) != 2) { rlog.err( "LUA: Incorrect command usage: <setparent>. " "Function takes 2 arguments, but %d is provided", lua_gettop( pLua ) ); lua_settop( pLua, 0 ); lua_pushnil( pLua ); return 1; } JObject* pParent = reinterpret_cast<JObject*>( lua_touserdata( pLua, 2 ) ); JObject* pObj = reinterpret_cast<JObject*>( lua_touserdata( pLua, 1 ) ); if (!pObj) { lua_pushnil( pLua ); return 0; } // set new parent for the object JObject* pOldParent = pObj->GetParent(); if (pParent) { pParent->AddChild( pObj ); } if (pOldParent) { pOldParent->RemoveChild( pObj ); } pObj->SetParent( pParent ); return 0; } // JLuaServer::FnSetParent
int JLuaServer::FnParent( lua_State* pLua ) { if (lua_gettop( pLua ) != 1) { rlog.err( "LUA: Incorrect command usage: <parent>. " "Function takes 1 argument, but %d is provided", lua_gettop( pLua ) ); lua_settop( pLua, 0 ); lua_pushnil( pLua ); return 1; } JObject* pObj = NULL; const char* pPath = lua_tostring( pLua, -1 ); if (pPath) { JLuaThread* pThread = reinterpret_cast<JLuaThread*>( pLua->userdata ); assert( pThread->m_pLua == pLua ); JObject* pRootObj = pThread->m_pRootObj; pObj = g_pObjectServer->FindObject( pPath, NULL, pRootObj ); } else { pObj = reinterpret_cast<JObject*>( lua_touserdata( pLua, -1 ) ); } if (!pObj) { lua_pushnil( pLua ); return 1; } lua_pushlightuserdata( pLua, pObj->GetParent() ); return 1; } // JLuaServer::FnParent
void JBlotPiece::Init() { JObject* pParent = GetParent(); m_pBlot = NULL; while (pParent && !m_pBlot) { m_pBlot = dynamic_cast<JBlotGame*>( pParent ); pParent = pParent->GetParent(); } } // JBlotPiece:Init
void JSlidePiece::Init() { JObject* pParent = GetParent(); m_pSlideGame = NULL; while (pParent && !m_pSlideGame) { m_pSlideGame = dynamic_cast<JSlideGame*>( pParent ); pParent = pParent->GetParent(); } } // JSlidePiece:Init
void JObjectTree::Traverse( TraverseCallback callback, void* pContext ) const { if (!m_pRoot) return; float nodeW = m_NodeWidth; float nodeVisH = m_NodeHeight; Frame ext( m_RootPos.x, m_RootPos.y, nodeW, nodeVisH ); // find node path for tree expansion static std::vector<int> nodePath; nodePath.clear(); JObject* pCurObj = m_pExpanded; if (pCurObj) nodePath.push_back( 0 ); while (pCurObj && pCurObj != m_pRoot) { JObject* pParent = pCurObj->GetParent(); if (!pParent) break; nodePath.push_back( pParent->GetChildIndex( pCurObj ) ); pCurObj = pParent; } // traverse root node (which is never collapsed) if ((this->*callback)( ext, m_pRoot, (m_pExpanded != NULL), pContext ) == false) return; // traverse along expansion path pCurObj = m_pRoot; for (int i = nodePath.size() - 1; i >= 0; i--) { int childIdx = nodePath[i]; if (!pCurObj) break; int nCh = pCurObj->GetNChildren(); if (childIdx >= nCh) break; float blockH = float( nCh )*nodeVisH; ext.y = ext.y - blockH*0.5f + nodeVisH*0.5f; ext.x += nodeW; float cY = ext.y; for (int j = 0; j < nCh; j++) { JObject* pChild = pCurObj->GetChild( j ); Frame chExt( ext ); chExt.y = cY; bool bExpanded = (j == childIdx)&&(pCurObj != m_pExpanded); if ((this->*callback)( chExt, pChild, bExpanded, pContext ) == false) { return; } cY += nodeVisH; } pCurObj = pCurObj->GetChild( childIdx ); ext.y += float( childIdx )*nodeVisH; } } // JObjectTree::Traverse