bool Tile::hasAStructure() const { if(!hasANonInfantryGroundObject()) { return false; } ObjectBase* pObject = currentGame->getObjectManager().getObject(assignedNonInfantryGroundObjectList.front()); return ( (pObject != NULL) && pObject->isAStructure() ); }
void rsi_ObjDestroy(Context *rsc, void *optr) { static int cnt = 0; ALOGD_IF(cnt++ % 3000 == 0, "%p rsi_ObjDestroy, cnt: %d", rsc, cnt); ObjectBase *ob = static_cast<ObjectBase *>(optr); rsc->removeName(ob); ob->decUserRef(); }
void GameServer::removeObject(ObjectBase &obj) { Geometry aoi(Circle(obj.pos, areaOfInfluenceRadius)); std::vector<PlayerBase *> aoiplayers; om.collidingPlayers(aoi, obj.pos, aoiplayers); for(unsigned i = 0; i < aoiplayers.size(); i++) { Player &player = *static_cast<Player *>(aoiplayers[i]); clientSendPacket(Signal(Signal::remove, obj.getId()), player.getId()); } om.remove(obj.getId()); }
//============================================================================= // リンク解除 //============================================================================= void DrawList::UnLink(ObjectBase* object) { // 存在チェック if(object->drawList(m_shaderPatternId) == nullptr) return; ObjectBase* prev = object->drawPrev(m_shaderPatternId); ObjectBase* next = object->drawNext(m_shaderPatternId); int priority = object->priority(m_shaderPatternId); //---------------------------- // 前オブジェクトの再設定 //---------------------------- object->drawPrev(m_shaderPatternId, nullptr); if(prev != nullptr) { // 前オブジェクトに次オブジェクトを連結 prev->drawNext(m_shaderPatternId, next); } else { // 先頭オブジェクトを変更 m_top[priority] = next; if(m_top[priority] != nullptr) // 先頭の前をnullptrに m_top[priority]->drawPrev(m_shaderPatternId, nullptr); } //---------------------------- // 次オブジェクトの再設定 //---------------------------- object->drawNext(m_shaderPatternId, nullptr); if(next != nullptr) { // 次オブジェクトに前オブジェクトを連結 next->drawPrev(m_shaderPatternId, prev); } else { // 終端オブジェクトを変更 m_end[priority] = prev; if(m_end[priority] != nullptr) // 終端をnullptrに m_end[priority]->drawNext(m_shaderPatternId, nullptr); } //---------------------------- // 描画リストを解除 //---------------------------- object->drawList(nullptr, m_shaderPatternId); }
void Tile::blitNonInfantryGroundUnits(int xPos, int yPos) { if(hasANonInfantryGroundObject() && !isFogged(pLocalHouse->getHouseID())) { std::list<Uint32>::const_iterator iter; for(iter = assignedNonInfantryGroundObjectList.begin(); iter != assignedNonInfantryGroundObjectList.end() ; ++iter) { ObjectBase* current = currentGame->getObjectManager().getObject(*iter); if(current->isAUnit() && current->isVisible(pLocalHouse->getTeam())) { if(location == current->getLocation()) { current->blitToScreen(); } } } } }
//============================================================================= // 全オブジェクトの描画 //============================================================================= void DrawList::AllDraw(LPD3DXCONSTANTTABLE vsc, LPD3DXCONSTANTTABLE psc, D3DXMATRIX vp) { ObjectBase* cur = nullptr; for(int cnt = 0; cnt < m_priorityLevel; ++cnt) { cur = m_top[cnt]; while(cur) { cur->Draw(vsc, psc, vp); cur = cur->drawNext(m_shaderPatternId); } } }
void ObjectBase::dumpCreatedObjects() { #ifdef OXYGINE_DEBUG_TRACE_LEAKS MutexAutoLock m(getMutex()); log::messageln("\n\n\nallocated objects:"); int n = 0; __createdObjects& objs = __getCreatedObjects(); for (__createdObjects::iterator i = objs.begin(); i != objs.end(); ++i) { ObjectBase* object = *i; //log::message("%d)", n); object->dumpObject(); ++n; } log::message("total: %d -----------------------------\n\n\n", (int)objs.size()); #endif }
void ObjectBase::freeAllChildren(Context *rsc) { if (rsc->props.mLogObjects) { LOGV("Forcing release of all child objects."); } // This operation can be slow, only to be called during context cleanup. ObjectBase * o = (ObjectBase *)rsc->mObjHead; while (o) { if (o->freeChildren()) { // deleted ref to self and possibly others, restart from head. o = (ObjectBase *)rsc->mObjHead; } else { o = (ObjectBase *)o->mNext; } } if (rsc->props.mLogObjects) { LOGV("Objects remaining."); dumpAll(rsc); } }
void Element::decRefs(const void *ptr) const { if (!mFieldCount) { if (mComponent.isReference()) { ObjectBase *const*obp = static_cast<ObjectBase *const*>(ptr); ObjectBase *ob = obp[0]; if (ob) ob->decSysRef(); } return; } const uint8_t *p = static_cast<const uint8_t *>(ptr); for (uint32_t i=0; i < mFieldCount; i++) { if (mFields[i].e->mHasReference) { const uint8_t *p2 = &p[mFields[i].offsetBits >> 3]; for (uint32_t ct=0; ct < mFields[i].arraySize; ct++) { mFields[i].e->decRefs(p2); p2 += mFields[i].e->getSizeBytes(); } } } }
void UnitBase::handleActionClick(int xPos, int yPos) { if(respondable) { if(currentGameMap->tileExists(xPos, yPos)) { if(currentGameMap->getTile(xPos,yPos)->hasAnObject()) { // attack unit/structure or move to structure ObjectBase* tempTarget = currentGameMap->getTile(xPos,yPos)->getObject(); if(tempTarget->getOwner()->getTeam() != getOwner()->getTeam()) { // attack currentGame->getCommandManager().addCommand(Command(pLocalPlayer->getPlayerID(), CMD_UNIT_ATTACKOBJECT,objectID,tempTarget->getObjectID())); } else { // move to object/structure currentGame->getCommandManager().addCommand(Command(pLocalPlayer->getPlayerID(), CMD_UNIT_MOVE2OBJECT,objectID,tempTarget->getObjectID())); } } else { // move this unit currentGame->getCommandManager().addCommand(Command(pLocalPlayer->getPlayerID(), CMD_UNIT_MOVE2POS,objectID,(Uint32) xPos, (Uint32) yPos, (Uint32) true)); } } } }
void Tile::setType(int newType) { type = newType; destroyedStructureTile = DestroyedStructure_None; if (type == Terrain_Spice) { spice = currentGame->randomGen.rand(RANDOMSPICEMIN, RANDOMSPICEMAX); } else if (type == Terrain_ThickSpice) { spice = currentGame->randomGen.rand(RANDOMTHICKSPICEMIN, RANDOMTHICKSPICEMAX); } else if (type == Terrain_Dunes) { } else { spice = 0; if (isRock()) { sandRegion = NONE; if (hasAnUndergroundUnit()) { ObjectBase* current; std::list<Uint32>::const_iterator iter; iter = assignedUndergroundUnitList.begin(); do { current = currentGame->getObjectManager().getObject(*iter); ++iter; if(current == NULL) continue; unassignUndergroundUnit(current->getObjectID()); current->destroy(); } while(iter != assignedUndergroundUnitList.end()); } if(type == Terrain_Mountain) { if(hasANonInfantryGroundObject()) { ObjectBase* current; std::list<Uint32>::const_iterator iter; iter = assignedNonInfantryGroundObjectList.begin(); do { current = currentGame->getObjectManager().getObject(*iter); ++iter; if(current == NULL) continue; unassignNonInfantryGroundObject(current->getObjectID()); current->destroy(); } while(iter != assignedNonInfantryGroundObjectList.end()); } } } } for (int i=location.x; i <= location.x+3; i++) { for (int j=location.y; j <= location.y+3; j++) { if (currentGameMap->tileExists(i, j)) { currentGameMap->getTile(i, j)->clearTerrain(); } } } }
void XMLSerialization::Serialize(ObjectBase const & object) { const TypeInfo* typeInfo = object.GetTypeInfo(); assert(typeInfo != nullptr); XMLElement * elem = _xmldoc.NewElement("Object"); if (_rootNode == nullptr) { _xmldoc.InsertFirstChild(elem); } else { _rootNode->InsertEndChild(elem); } SetClassAttributes(elem, typeInfo); SerializeObjectMembers(elem, object, typeInfo); _retElem = elem; }
void XMLSerialization::SerializeObjectMembers(XMLElement * elem, ObjectBase const & object, const TypeInfo* typeInfo) { const TypeInfo* parent = typeInfo->GetParent(); if (parent != nullptr) SerializeObjectMembers(elem, object, parent); for (auto mi : typeInfo->GetMembers()) { if (mi->GetSerializable()) { _retElem = nullptr; object.SerializeMember(*this, mi); if (_retElem != nullptr) { _retElem->SetName("Member"); SetMemberAttributes(_retElem, mi); elem->InsertEndChild(_retElem); } } } }
// Only to be called at a3d load time, before object is visible to user // not thread safe void rsaGetName(RsContext con, void * obj, const char **name) { ObjectBase *ob = static_cast<ObjectBase *>(obj); (*name) = ob->getName(); }
void rsi_ObjDestroy(Context *rsc, void *optr) { ObjectBase *ob = static_cast<ObjectBase *>(optr); rsc->removeName(ob); ob->decUserRef(); }
Uint32 Tile::getRadarColor(House* pHouse, bool radar) { if(isExplored(pHouse->getHouseID()) || debug) { if(isFogged(pHouse->getHouseID()) && radar) { return fogColor; } else { ObjectBase* pObject = getObject(); if(pObject != NULL) { int color; if(pObject->getItemID() == Unit_Sandworm) { color = COLOR_WHITE; } else { switch(pObject->getOwner()->getHouseID()) { case HOUSE_HARKONNEN: color = COLOR_HARKONNEN; break; case HOUSE_ATREIDES: color = COLOR_ATREIDES; break; case HOUSE_ORDOS: color = COLOR_ORDOS; break; case HOUSE_FREMEN: color = COLOR_FREMEN; break; case HOUSE_SARDAUKAR: color = COLOR_SARDAUKAR; break; case HOUSE_MERCENARY: color = COLOR_MERCENARY; break; default: color = COLOR_BLACK; break; } } if(pObject->isAUnit()) { fogColor = getColorByTerrainType(getType()); } else { fogColor = color; } // units and structures of the enemy are not visible if no radar if(!radar && !debug && (pObject->getOwner()->getTeam() != pHouse->getTeam())) { return COLOR_BLACK; } else { return color; } } else { fogColor = getColorByTerrainType(getType()); if(!radar && !debug) { return COLOR_BLACK; } else { return fogColor; } } } } else { return COLOR_BLACK; } }
void Tile::blitSelectionRects(int xPos, int yPos) { // draw underground selection rectangles if(hasAnUndergroundUnit() && !isFogged(pLocalHouse->getHouseID())) { UnitBase* current = getUndergroundUnit(); if(current != NULL) { if(current->isVisible(pLocalHouse->getTeam()) && (location == current->getLocation())) { if(current->isSelected()) { current->drawSelectionBox(); } if(current->isSelectedByOtherPlayer()) { current->drawOtherPlayerSelectionBox(); } } } } // draw infantry selection rectangles if(hasInfantry() && !isFogged(pLocalHouse->getHouseID())) { std::list<Uint32>::const_iterator iter; for(iter = assignedInfantryList.begin(); iter != assignedInfantryList.end() ; ++iter) { InfantryBase* current = dynamic_cast<InfantryBase*>(currentGame->getObjectManager().getObject(*iter)); if(current == NULL) { continue; } if(current->isVisible(pLocalHouse->getTeam()) && (location == current->getLocation())) { if(current->isSelected()) { current->drawSelectionBox(); } if(current->isSelectedByOtherPlayer()) { current->drawOtherPlayerSelectionBox(); } } } } // draw non infantry ground object selection rectangles if(hasANonInfantryGroundObject() && !isFogged(pLocalHouse->getHouseID())) { std::list<Uint32>::const_iterator iter; for(iter = assignedNonInfantryGroundObjectList.begin(); iter != assignedNonInfantryGroundObjectList.end() ; ++iter) { ObjectBase* current = currentGame->getObjectManager().getObject(*iter); if(current == NULL) { continue; } if(current->isVisible(pLocalHouse->getTeam()) && (location == current->getLocation())) { if(current->isSelected()) { current->drawSelectionBox(); } if(current->isSelectedByOtherPlayer()) { current->drawOtherPlayerSelectionBox(); } } } } // draw air unit selection rectangles if(hasAnAirUnit() && !isFogged(pLocalHouse->getHouseID())) { std::list<Uint32>::const_iterator iter; for(iter = assignedAirUnitList.begin(); iter != assignedAirUnitList.end() ; ++iter) { AirUnit* airUnit = dynamic_cast<AirUnit*>(currentGame->getObjectManager().getObject(*iter)); if(airUnit == NULL) { continue; } if(airUnit->isVisible(pLocalHouse->getTeam()) && (location == airUnit->getLocation())) { if(airUnit->isSelected()) { airUnit->drawSelectionBox(); } if(airUnit->isSelectedByOtherPlayer()) { airUnit->drawOtherPlayerSelectionBox(); } } } } }
static bool LoadFromRecord( typename TreeNodeField<C, T>::Type& fieldObject, ObjectBase& object, const Record& record, const util::Env& env ){ assert(dynamic_cast<T*>(&object)); T& t(static_cast<T&>(object)); bool result(false); if(record.isDefined(ComplexObjectFieldDefinition<C>::FIELDS[2].name)) { size_t value( record.getDefault<size_t>( ComplexObjectFieldDefinition<C>::FIELDS[2].name, 0 ) ); if(value != t.getRank()) { result = true; t.setRank(value); } } if(record.isDefined(ComplexObjectFieldDefinition<C>::FIELDS[1].name)) { util::RegistryKeyType up_id( record.getDefault<util::RegistryKeyType>( ComplexObjectFieldDefinition<C>::FIELDS[1].name, 0 ) ); if(up_id > 0) { try { T* value( env.getEditable<T>(up_id).get() ); if(value != t.getParent(true)) { t.setParent(env.getEditable<T>(up_id).get()); result = true; } } catch(util::ObjectNotFoundException<T>&) { util::Log::GetInstance().warn( "Data corrupted in on node " + boost::lexical_cast<std::string>(object.getKey()) +" : up node " + boost::lexical_cast<std::string>(up_id) + " not found" ); } } else { if( !t.isParentDefined() || t.getParent() != NULL ){ t.setParent(NULL); result = true; } } } if(record.isDefined(ComplexObjectFieldDefinition<C>::FIELDS[0].name)) { util::RegistryKeyType id( record.getDefault<util::RegistryKeyType>( ComplexObjectFieldDefinition<C>::FIELDS[0].name, 0 ) ); if(id > 0) { try { typename T::RootType* value(env.getEditable<typename T::RootType>(id).get()); if(t.getRoot() != value) { t.setRoot(value); result = true; } } catch(util::ObjectNotFoundException<typename T::RootType>&) { util::Log::GetInstance().warn( "Data corrupted in on node " + boost::lexical_cast<std::string>(object.getKey()) +" : root " + boost::lexical_cast<std::string>(id) + " not found" ); } } } return result; }