void ObjectManager::destroyObject(uint64 objectID) {
	Locker _locker(this);

	Reference<SceneObject*> object = objectMap->remove(objectID);

	if (object != NULL) {
		object->info("finalizing object");

		while (object->getSlottedObjectsSize() > 0) {
			Reference<SceneObject*> obj = object->getSlottedObject(0);

			object->removeObject(obj);

			destroyObject(obj->getObjectID());
		}

		while (object->getContainerObjectsSize() > 0) {
			Reference<SceneObject*> obj = object->getContainerObject(0);

			object->removeObject(obj);

			destroyObject(obj->getObjectID());
		}

		//object->finalize();
	}
}
示例#2
0
文件: objFuncs.c 项目: odeke-em/sym
inline KeyValue *destroyKvStruct(KeyValue *kv) {
  if (kv != NULL) {
    kv->key   = destroyObject(kv->key);
    kv->value = destroyObject(kv->value);
    free(kv);
    kv = NULL;
  }

  return kv;
}
示例#3
0
void AudioOutput::destroyContext() {
    ALOGI("enter AudioOutput::DestroyContext");
    // Destroy audio player object
    destroyObject(audioPlayerObject);
    ALOGI("after destroy audioPlayerObject");
    // Free the player buffer
    freePlayerBuffer();
    ALOGI("after FreePlayerBuffer");
    // Destroy output mix object
    destroyObject(outputMixObject);
    ALOGI("leave AudioOutput::DestroyContext");
}
uint32_t deserializeBlockHeaders(BlockHeaders * self){
	assert(self != NULL);
	ByteArray * bytes = getMessage(self)->bytes;
	if (!bytes) {
		getMessage(self)->onErrorReceived(ERROR_MESSAGE_DESERIALISATION_NULL_BYTES,"Attempting to deserialize a BlockHeaders with no bytes.");
		return 0;
	}
	if (bytes->length < 82) {
		getMessage(self)->onErrorReceived(ERROR_MESSAGE_DESERIALISATION_BAD_BYTES,"Attempting to deserialize a BlockHeaders with less bytes than required for one header.");
		return 0;
	}
	VarLenInt numOfHeaders = decodeVarLenInt(bytes, 0);
	if (numOfHeaders.value > 2000) {
		getMessage(self)->onErrorReceived(ERROR_MESSAGE_DESERIALISATION_BAD_BYTES,"Attempting to deserialize a BlockHeaders with a var int over 2000.");
		return 0;
	}
	/* Deserialise each header */
	self->blockHeaders = malloc(sizeof(*self->blockHeaders) * (size_t)numOfHeaders.value);
	if (! self->blockHeaders) {
		getMessage(self)->onErrorReceived(ERROR_OUT_OF_MEMORY,"Cannot allocate %i bytes of memory in deserializeBlockHeaders\n",sizeof(*self->blockHeaders) * (size_t)numOfHeaders.value);
		return 0;
	}
	self->numOfHeaders = numOfHeaders.value;
	uint16_t cursor = numOfHeaders.storageSize;
	uint16_t x;
	for ( x = 0; x < numOfHeaders.value; x++) {
		/* Make new Block from the rest of the data. */
		ByteArray * data = getByteArraySubsectionReference(bytes, cursor, bytes->length-cursor);
		if (! data) {
			getMessage(self)->onErrorReceived(ERROR_INIT_FAIL,"Cannot create a new ByteArray in deserializeBlockHeaders for the header number %u.",x);
			return 0;
		}
		self->blockHeaders[x] = createNewBlockFromByteArray(data, getMessage(self)->onErrorReceived);
		if (! self->blockHeaders[x]){
			getMessage(self)->onErrorReceived(ERROR_INIT_FAIL,"Cannot create a new Block in deserializeBlockHeaders for the header number %u.",x);
			destroyObject(data);
			return 0;
		}
		/* Deserialize */
		uint8_t len = deserializeBlock(self->blockHeaders[x],false); /* false for no transactions. Only the header. */
		if (! len){
			getMessage(self)->onErrorReceived(ERROR_MESSAGE_DESERIALISATION_BAD_BYTES,"BlockHeaders cannot be deserialised because of an error with the Block number %u.",x);
			destroyObject(data);
			return 0;
		}
		/* Adjust length */
		data->length = len;
		destroyObject(data);
		cursor += len;
	}
	return cursor;
}
示例#5
0
Object::singletons::~singletons() {
    while (!_stack.empty()) {
        Object *obj = _stack.top();
        _stack.pop();
        destroyObject(obj);
    }
}
示例#6
0
void GameWorld::destroyQueuedObjects()
{
	while( !deletionQueue.empty() ) {
		destroyObject( *deletionQueue.begin() );
		deletionQueue.erase( deletionQueue.begin() );
	}
}
示例#7
0
void CObjectList::deleteItem(CIntObject* item)
{
	if (!item)
		return;
	removeChild(item);
	destroyObject(item);
}
/**
 @fn void destroyByteArray(void * self)
 @brief destorys byte array
 @param self
 */
void destroyByteArray(void * self)
{
	assert(self != NULL);

	releaseByteArraySharedDataReference(self);
	destroyObject(getObject(self));
}
示例#9
0
Object* ObjectFactory::createObjectInternal(const std::string& path)
{
    if(path.length() > 0 && path[0] == '.')
    {
        const std::string className = path.substr(1);

        if(Object* object = createRawObject(className))
        {
            // Perform internal initialization
            object->createElements();
            return object;
        }
    }
    else
    {
        RafPrototypeHeader raf;
        raf.load(path);

        const RJNode& configuration = raf.getCustomJsonHeaderRef();

        Object* object = createObjectInternal(configuration["proto"]);
        Actor* actor = dynamic_cast<Actor*>(object);
        if(actor)
        {
            // Create dynamic components.
            const RJNode& dclJson = configuration["dcl"];
            for(RJNode::const_iterator it = dclJson.begin(); it != dclJson.end(); ++it)
            {
                const std::string componentName = it.key();
                const std::string className = it.value();

                Component* component = createComponent(className, componentName, actor);
                if(component)
                {
                    component->xiMarkAsDynamic();
                }
                else
                {
                    rLogErr(g_log, "[ObjectManager] Couldn`t create component \"" << componentName << "\". Skipping.");
                }
            }

            actor->siDeserialize(ESerializationHint::Definition, configuration);

            std::shared_ptr<PrototypeAsset> prototype = core::getAssetManager()->getPrototype(path);
            if(prototype && ji::hasChild(configuration, "script"))
            {
                prototype->xiEnsureScriptLoaded(ji::getChild(configuration, "script"));
            }

            return actor;
        }
        else
        {
            destroyObject(object);
        }
    }

    return nullptr;
}
示例#10
0
void ObjectController::_handleServerDestroyObject(uint64 targetId,Message* message,ObjectControllerCmdProperties* cmdProperties)
{
    string volume;

    message->getStringUnicode16(volume);

    destroyObject(targetId);
}
示例#11
0
/**
* Destroy a room and free all memory
*
* @param room A pointer to the room array to destroy
*
* @return None
*/
void destroyRoom(Object* (*room)[ROOM_HEIGHT][ROOM_WIDTH]) {

    for(int i=0; i<ROOM_HEIGHT; i++) {
        for(int j=0; j<ROOM_WIDTH; j++) {
            destroyObject((*room)[i][j]);
            (*room)[i][j] = 0;
        }
    }
}
void destroyBlockHeaders(void * vself){
	assert(vself != NULL);
	BlockHeaders * self = vself;
	uint16_t x;
	for ( x = 0; x < self->numOfHeaders; x++) {
		destroyObject(self->blockHeaders[x]);
	}
	free(self->blockHeaders);
	destroyMessage(self);
}
示例#13
0
void SchemeManager::destroy(const String& object_name)
{
    SchemeRegistry::iterator i(d_registeredSchemes.find(object_name));

    // exit if no such object.
    if (i == d_registeredSchemes.end())
        return;

    destroyObject(i);
}
示例#14
0
 /**
 @fn void destroyMessage(void * message)
 @brief destroy Message 
 @param message
 @returns
 */
void destroyMessage(void * message)
{
	assert(message != NULL);

	Message * self = message;
	if (self->bytes != NULL){
		decrementReferenceCount(self->bytes); /*Reduce number of references to these bytes*/
	}
	destroyObject(self);
}
void destroyAddressBroadcast(void * vself){
	AddressBroadcast * self = vself;
	uint8_t x;
	for (x = 0; x < self->addrNum; x++){
		decrementReferenceCount(self->addresses[x]);
	}
	if (self->addresses) {
		free(self->addresses);
	}
	destroyObject(self);
}
示例#16
0
int MemoryManager::garbageCollect()
{
    register int j;
    int c=1,f=0;

    if(noGC)
        return 0;

    if (debugging) 
        fprintf(stderr,"\ngarbage collecting ... \n");

    for(TObjectTableIterator x = objectTable.begin(), xend = objectTable.end(); x != xend; ++x)
        x->referenceCount = 0;
    objectTable[0].referenceCount = 1;
    /* visit symbols and firstProcess to toggle their referenceCount */

    visit(symbols);

    /* Visit any explicitly held references from the use of ObjectHandle */
    ObjectHandle* explicitRef = ObjectHandle::getListHead();
    while(explicitRef)
    {
        visit(*explicitRef);
        explicitRef = explicitRef->next();
    }

    /* add new garbage to objectFreeList 
    * toggle referenceCount 
    * count the objects
    */

    for (j=objectTable.size()-1; j>0; j--) 
    {
        if (objectTable[j].referenceCount == 0) 
        {
            if(destroyObject(j))
                f++;
        } 
        else
        {
            if (0!=(objectTable[j].referenceCount = -objectTable[j].referenceCount))
                c++;
        }
    }

    if (debugging)
    {
        fprintf(stderr," %d references.\n",ObjectHandle::numTotalHandles());
        fprintf(stderr," %d objects - %d freed.\n",c,f);
    }

    return f;
}
示例#17
0
void SchemeManager::destroy(const Scheme& object)
{
    // don't want to force a 'getName' function on T here, so we'll look for the
    // object the hard way.
    SchemeRegistry::iterator i(d_registeredSchemes.begin());
    for (; i != d_registeredSchemes.end(); ++i)
        if (i->second == &object)
        {
        destroyObject(i);
        return;
        }
}
示例#18
0
void ObjectController::_handleDestroyInstrument(Item* item)
{
    PlayerObject*	playerObject		= dynamic_cast<PlayerObject*>(mObject);
    Item*			tempInstrument		= NULL;
    Item*			permanentInstrument	= NULL;

    // first, stop playing, if its currently in use
    if(playerObject->getPerformingState() == PlayerPerformance_Music)
    {
        // equipped instrument
        if(item == dynamic_cast<Item*>(playerObject->getEquipManager()->getEquippedObject(CreatureEquipSlot_Instrument))
                || playerObject->getPlacedInstrumentId())
        {
            gEntertainerManager->stopEntertaining(playerObject);
        }
    }

    // handle destruction of instanced instruments, placed in world
    if(playerObject->getPlacedInstrumentId())
    {
        // get the instruments
        tempInstrument = dynamic_cast<Item*>(gWorldManager->getObjectById(playerObject->getPlacedInstrumentId()));

        if(!tempInstrument)
        {
            gLogger->logMsg("ObjectController::handleDestroyInstrument : no temporary Instrument\n");
            return;
        }

        permanentInstrument = dynamic_cast<Item*>(gWorldManager->getObjectById(tempInstrument->getPersistantCopy()));

        if(!permanentInstrument)
        {
            gLogger->logMsg("ObjectController::handleDestroyInstrument : no parent Instrument\n");
            return;
        }

        // the temporary gets ALWAYS deleted
        // update the attributes of the permanent Instrument
        if(tempInstrument == item)
        {
            permanentInstrument->setPlaced(false);
            permanentInstrument->setNonPersistantCopy(0);
            playerObject->setPlacedInstrumentId(0);
        }
        // it is the permanent Instrument delete the temporary copy too
        else if(permanentInstrument == item)
        {
            destroyObject(tempInstrument->getId());
        }
    }
}
示例#19
0
void ObjectController::_handleDestroyInstrument(Item* item)
{
    PlayerObject*	playerObject		= dynamic_cast<PlayerObject*>(mObject);
    Item*			tempInstrument		= NULL;
    Item*			permanentInstrument	= NULL;

	auto equip_service = gWorldManager->getKernel()->GetServiceManager()->GetService<swganh::equipment::EquipmentService>("EquipmentService");
	auto held_item = dynamic_cast<Item*>(equip_service->GetEquippedObject(playerObject, "hold_r"));

    // first, stop playing, if its currently in use
    if(playerObject->GetCreature()->getPerformingState() == PlayerPerformance_Music)
    {
        // equipped instrument
        if(item == held_item  || playerObject->getPlacedInstrumentId())
        {
            gEntertainerManager->stopEntertaining(playerObject);
        }
    }

    // handle destruction of instanced instruments, placed in world
    if(playerObject->getPlacedInstrumentId())
    {
        // get the instruments
        tempInstrument = dynamic_cast<Item*>(gWorldManager->getObjectById(playerObject->getPlacedInstrumentId()));

        if(!tempInstrument)
        {
            return;
        }

        permanentInstrument = dynamic_cast<Item*>(gWorldManager->getObjectById(tempInstrument->getPersistantCopy()));

        if(!permanentInstrument)
        {
            return;
        }

        // the temporary gets ALWAYS deleted
        // update the attributes of the permanent Instrument
        if(tempInstrument == item)
        {
            permanentInstrument->setPlaced(false);
            permanentInstrument->setNonPersistantCopy(0);
            playerObject->setPlacedInstrumentId(0);
        }
        // it is the permanent Instrument delete the temporary copy too
        else if(permanentInstrument == item)
        {
            destroyObject(tempInstrument->getId());
        }
    }
}
示例#20
0
文件: objFuncs.c 项目: odeke-em/sym
Chain *destroyChain(Chain *n) {
  if (n != NULL) {
    Chain *trav = n, *next = NULL;
    while (trav != NULL) {
      next = trav->next;
      trav->value = destroyObject(trav->value);
      free(trav);
      trav = next;
    }
    n = NULL;
  }
  
  return n;
}
示例#21
0
void MemoryManager::setFreeLists() 
{
    objectFreeList.clear();
    objectFreeListInv.clear();

    /* add free objects */
    for(int z=objectTable.size()-1; z>0; z--)
    {
        // If really unused, destroyObject will take care
        // of cleaning up and adding to the free list.
        if (objectTable[z].referenceCount == 0)
            destroyObject(z);
    }
}
示例#22
0
DynamicObjectList &DynamicObjectList::operator/=(const DynamicObjectList &o) {
    sort();

    for (unsigned int i = 0; i < getCount(); i++) {
        for(unsigned int j = 0; j < o.getCount(); i++){
            if(*getAt(i) == *o.getAt(j)){
                destroyObject(i);
                break;
            }
        }
    }

    return *this;
}
示例#23
0
DynamicObjectList &DynamicObjectList::operator&=(const DynamicObjectList &o) {
    for(int i = m_count - 1; i >= 0; i--){
        bool existsInO = false;
        const Object& oo = *getAt(i);
        for(unsigned int j = 0; j < o.getCount(); j++){
            if(oo == *o.getAt(j)){
                existsInO = true;
                break;
            }
        }
        if(!existsInO)
            destroyObject(i);
    }
    return *this;
}
示例#24
0
void randomizeMap()
{
	OBJECT *theRock = rockHeader;
	OBJECT *theRockSave = rockHeader;
	while (theRock != NULL)
	{
		theRockSave = theRock->next;
		destroyObject(theRock, &rockHeader);
		theRock = theRockSave;
	}
   pointHeader = NULL;
   for (int i = 0; i < NUMBLOCKS; i ++)
	{
   	createRock();
	}
}
示例#25
0
Actor* ObjectFactory::createActor(const std::string& path)
{
    if(Object* object = createObject(path))
    {
        if(Actor* actor = dynamic_cast<Actor*>(object))
        {
            return actor;
        }
        else
        {
            rLogErr(g_log, "[ObjectFactory] Given path \"" << path << "\" doesn`t describe an actor.");
            destroyObject(object);
        }
    }

    return nullptr;
}
示例#26
0
Scene* ObjectFactory::createScene(const std::string& path)
{
    // Just pass path to createObject function as currently scene prototypes are not supported.
    Object* object = createRawObject(path);
    Scene* scene = dynamic_cast<Scene*>(object);
    if(scene)
    {
        // Perform internal initialization
        scene->createElements();
    }
    else
    {
        rLogErr(g_log, "[ObjectFactory] Given class name \"" << path << "\" is not a scene class.");
        destroyObject(object);
    }

    return scene;
}
void WorldManager::savePlayerSync(uint32 accId,bool remove)
{
    PlayerObject* playerObject = getPlayerByAccId(accId);
    Ham* ham = playerObject->getHam();

    mDatabase->destroyResult(mDatabase->executeSynchSql("UPDATE characters SET parent_id=%"PRIu64",oX=%f,oY=%f,oZ=%f,oW=%f,x=%f,y=%f,z=%f,planet_id=%u WHERE id=%"PRIu64"",playerObject->getParentId()
                             ,playerObject->mDirection.x,playerObject->mDirection.y,playerObject->mDirection.z,playerObject->mDirection.w
                             ,playerObject->mPosition.x,playerObject->mPosition.y,playerObject->mPosition.z
                             ,mZoneId,playerObject->getId()));
   

    mDatabase->destroyResult(mDatabase->executeSynchSql("UPDATE character_attributes SET health_current=%u,action_current=%u,mind_current=%u"
                             ",health_wounds=%u,strength_wounds=%u,constitution_wounds=%u,action_wounds=%u,quickness_wounds=%u"
                             ",stamina_wounds=%u,mind_wounds=%u,focus_wounds=%u,willpower_wounds=%u,battlefatigue=%u,posture=%u,moodId=%u,title=\'%s\'"
                             ",character_flags=%u,states=%"PRIu64",language=%u, group_id=%"PRIu64" WHERE character_id=%"PRIu64"",
                             ham->mHealth.getCurrentHitPoints() - ham->mHealth.getModifier(), //Llloydyboy Added the -Modifier so that when buffs are reinitialised, it doesn't screw up HAM
                             ham->mAction.getCurrentHitPoints() - ham->mAction.getModifier(), //Llloydyboy Added the -Modifier so that when buffs are reinitialised, it doesn't screw up HAM
                             ham->mMind.getCurrentHitPoints() - ham->mMind.getModifier(),	 //Llloydyboy Added the -Modifier so that when buffs are reinitialised, it doesn't screw up HAM
                             ham->mHealth.getWounds(),
                             ham->mStrength.getWounds(),
                             ham->mConstitution.getWounds(),
                             ham->mAction.getWounds(),
                             ham->mQuickness.getWounds(),
                             ham->mStamina.getWounds(),
                             ham->mMind.getWounds(),
                             ham->mFocus.getWounds(),
                             ham->mWillpower.getWounds(),
                             ham->getBattleFatigue(),
                             playerObject->states.getPosture(),
                             playerObject->getMoodId(),
                             playerObject->getTitle().getAnsi(),
                             playerObject->getPlayerFlags(),
							 playerObject->states.getAction(),
                             playerObject->getLanguage(),
                             playerObject->getGroupId(),
                             playerObject->getId()));

    gBuffManager->SaveBuffs(playerObject, GetCurrentGlobalTick());
    if(remove)
        destroyObject(playerObject);
}
示例#28
0
/**
* Add the next room to the dungeon
*
* @param dungeon A pointer to the dungeon and game info
* @param dungeon_idx the location of the room in the dungeon
* @param last_move The last move made by the player
* @param moveNum The number of moves made by the player
*
* @return None
*/
void extendDungeon(Dungeon *dungeon, int dungeon_idx, char last_move, int moveNum) {
    int room_idx=2;
    Coordinate cornerStone;
    Room* new_room=NULL;
    Room* prev_room=NULL;

    if(last_move == dungeon->moveTypes.left)
        room_idx = 0;
    else if(last_move == dungeon->moveTypes.right)
        room_idx = 1;
    else if(last_move == dungeon->moveTypes.jump)
        room_idx = 0;
    else if(last_move == dungeon->moveTypes.jumpleft)
        room_idx = 1;
    else if(last_move == dungeon->moveTypes.jumpright)
        room_idx = 0;
    else if(last_move == dungeon->moveTypes.wait) {
        if(moveNum > SECRET_NUM)
            room_idx = 2;
        else
            room_idx = 1;
    }

    cornerStone.y=0;
    cornerStone.x= (dungeon_idx*ROOM_WIDTH);
    if(!(new_room = malloc(sizeof(Room))))
        _terminate(ALLOCATE_ERROR);
    addRoom(&new_room->contents, room_string[room_idx], cornerStone, moveNum);

    for(prev_room=dungeon->start; prev_room->next!=NULL; prev_room=prev_room->next);
    prev_room->next = new_room;

    // Open door
    Object* door;
    door = prev_room->contents[ROOM_HEIGHT-3][ROOM_WIDTH-1];
    destroyObject(door);
    prev_room->contents[ROOM_HEIGHT-3][ROOM_WIDTH-1] = makeObject(EMPTY_SYM, EMPTY_NUM, ROOM_HEIGHT-3, cornerStone.x-1, 0, 0, moveNum);
}
示例#29
0
Component* ObjectFactory::createComponent(const std::string& path, const std::string& name, Actor* owner)
{
    // Just pass path to createObject function as currently component prototypes are not supported.
    Object* object = createRawObject(path);
    Component* component = dynamic_cast<Component*>(object);
    if(component)
    {
        // Setup necessary information
        component->xiSetName(name);
        component->xiSetOwner(owner);
        owner->addComponent(component);

        // Perform internal initialization
        component->createElements();
    }
    else
    {
        rLogErr(g_log, "[ObjectFactory] Given class name \"" << path << "\" is not a component class.");
        destroyObject(object);
    }

    return component;
}
uint32_t serializeBlockHeaders(BlockHeaders * self){
	assert(self != NULL);
	ByteArray * bytes = getMessage(self)->bytes;
	if (! bytes) {
		getMessage(self)->onErrorReceived(ERROR_MESSAGE_SERIALISATION_NULL_BYTES,"Attempting to serialize a BlockHeaders with no bytes.");
		return 0;
	}
	if (bytes->length < 81 * self->numOfHeaders) {
		getMessage(self)->onErrorReceived(ERROR_MESSAGE_DESERIALISATION_BAD_BYTES,"Attempting to deserialize a BlockHeaders with less bytes than minimally required.");
		return 0;
	}
	VarLenInt num = createVarLenIntFromUInt64(self->numOfHeaders);
	encodeVarLenInt(bytes, 0, num);
	uint16_t cursor = num.storageSize;
	uint16_t x;
	for ( x = 0; x < num.value; x++) {
		getMessage(self->blockHeaders[x])->bytes = getByteArraySubsectionReference(bytes, cursor, bytes->length-cursor);
		if (! getMessage(self->blockHeaders[x])->bytes) {
			getMessage(self)->onErrorReceived(ERROR_INIT_FAIL,"Cannot create a new ByteArray sub reference in serializeBlockHeaders for the header number %u",x);
			return 0;
		}
		uint32_t len = serializeBlock(self->blockHeaders[x],false); /* false for no transactions.*/
		if (!len) {
			getMessage(self)->onErrorReceived(ERROR_MESSAGE_SERIALISATION_BAD_BYTES,"BlockHeaders cannot be serialized because of an error with the Block number %u.",x);
			/* Release ByteArray objects to avoid problems overwritting pointer without release, if serialisation is tried again. */
			uint8_t y;
			for ( y = 0; y < x + 1; y++) {
				destroyObject(getMessage(self->blockHeaders[y])->bytes);
			}
			return 0;
		}
		getMessage(self->blockHeaders[x])->bytes->length = len;
		cursor += len;
	}
	return cursor;
}