Example #1
0
bool Object_writeLocalData(const Object &obj, Output &fw)
{
    switch (obj.getDataVariance())
    {
    case (osg::Object::STATIC):      fw.indent() << "DataVariance STATIC" << std::endl; break;

    case (osg::Object::DYNAMIC):     fw.indent() << "DataVariance DYNAMIC" << std::endl; break;

    case (osg::Object::UNSPECIFIED): break;    // fw.indent() << "DataVariance UNSPECIFIED" << std::endl;break;
    }

    if (!obj.getName().empty())
        fw.indent() << "name " << fw.wrapString(obj.getName()) << std::endl;

    if (obj.getUserData())
    {
        const Object *object = dynamic_cast<const Object*>(obj.getUserData());
        if (object)
        {
            fw.indent() << "UserData {" << std::endl;
            fw.moveIn();
            fw.writeObject(*object);
            fw.moveOut();
            fw.indent() << "}" << std::endl;
        }
    }

    return true;
}
Example #2
0
SecurityHandler *SecurityHandler::make(PDFDoc *docA, Object *encryptDictA) {
    Object filterObj;
    SecurityHandler *secHdlr;
#ifdef ENABLE_PLUGINS
    XpdfSecurityHandler *xsh;
#endif

    encryptDictA->dictLookup("Filter", &filterObj);
    if (filterObj.isName("Standard")) {
        secHdlr = new StandardSecurityHandler(docA, encryptDictA);
    } else if (filterObj.isName()) {
#ifdef ENABLE_PLUGINS
        if ((xsh = globalParams->getSecurityHandler(filterObj.getName()))) {
            secHdlr = new ExternalSecurityHandler(docA, encryptDictA, xsh);
        } else {
#endif
            error(-1, "Couldn't find the '%s' security handler",
                  filterObj.getName());
            secHdlr = NULL;
#ifdef ENABLE_PLUGINS
        }
#endif
    } else {
        error(-1, "Missing or invalid 'Filter' entry in encryption dictionary");
        secHdlr = NULL;
    }
    filterObj.free();
    return secHdlr;
}
Example #3
0
	virtual void doWith(const std::string &parameter1, const std::string &parameter2) const 
	{
		Location *curLocation = player.getLocation() ;
		Object *curObject = curLocation->getObject(parameter1) ;
		if (curObject != NULL)
		{
			if (curObject->canTalk()) 
			{
				if ((getStateFlag(FlagShishka)) == FVShishkaYes)
				{
					std::cout << "(" << curObject->getName() << ") Какой-то ты странный сегодня... Эй, ты чего смеёшься?\n"
						"(Вы) У-ха-ха-ха!! А-ха-ха-хах!! Это так смешно звучит, ой я не могу.. Аааа, мой мозг! А-ха-ха-хах!\n"
						"(" << curObject->getName() << ") Э-э-э-й! Ты тут вообще?..\n"
						"(Вы) Да... Да? Да! Тута я! Ля-ля-ля! Блин, как жрать хочу... Ку-ку!!!\n"
						"(" << curObject->getName() << ") О ужас! Ты выкурил шишку!!\n" 
						"(Вы) Ку-кууу?...\n\n"
						"Через пару часов Вы успокоились и перестали нести чушь. Вас исключили из лагеря и вскоре Вас "
						"забрали домой родители. А вот нечего курить всякую гадость в лесу! "
						"Вы не смогли осуществить своих гениальных замыслов, игра закончена. До свидания!\n";
					system("pause");
					exitGame();

				}
				curObject->talk();
				
			}
			else std::cout << "Предметы не разговаривают!\n";
		} 
		else 
		{
			std::cout << "Такого человека здесь нет!\n";
		}
	}
Example #4
0
bool Object::operator==(const Object &other) const
{
    if (d() == other.d()) {
        assert(getName() == other.getName());
    } else {
        assert(getName() != other.getName());
    }
    return d() == other.d();
}
Example #5
0
Object *Scene::getObject(const char *name)
{
	for (unsigned int i = 0; i < objects.size(); i++)
	{
		Object *o = objects.at(i);

		const char *oName = o->getName();

		if (strcmp(o->getName(), name) == 0)
			return o;
	}

	return NULL;
}
Example #6
0
void Obj2::save(std::string const& path) const {
	ofstream file;
	file.open(path);

	//check ouverture
	if (!file.good()) {
		throw FileError(0,"Error in OBJ save : \n\timpossible to create " + path + ".");
	}
	file << "# OBJ File" << endl;
	file << "# " << vertices.size() << " vertices" << endl;
	file << "# " << objects.size() << " objects" << endl;
	//écrire les sommets
	Vertex v;
	for (unsigned int i = 0; i < vertices.size(); i++) {//écrire tous les vertexes
		v = vertices[i];
		file << "v " << v.x << " " << v.y << " " << v.z << endl;
	}
	//écrire les objets
	Object o;
	vector<Object::face> faces;
	Object::face f;
	for (unsigned int i = 0; i < objects.size(); i++) {//pour chaque objet
		o = objects[i];
		file << "o " << o.getName() << endl;//écrire le nom
		faces = o.getFaces();
		for (unsigned int j = 0; j < faces.size(); j++) {//puis pour chacune des faces
			f = faces[j];
			file << "f ";
			for (unsigned int k = 0; k < f.size(); k++) {//écrire les coordonnées
				file << f[k] << " ";
			}
			file << endl;
		}
	}
}
Example #7
0
bool operator < (const Object &lhs, const Object &rhs)
{
	if(lhs.getName() == rhs.getParentName())
		return false;

	return true;
}	
Example #8
0
Variant 
Server::callMeta( const std::string& method, const Variant::list& args ) {
    Variant v;
    if( method == "stop" ) {
        std::lock_guard<std::mutex> lock ( write_lock );
        _stop =true;
        return v;
    } else if( method == "getDataConnection" ) {
        return Variant( data_connection );
    } else if( method == "setDataConnection" ) {
        if( args.size() > 0 ) {
            Object *obj =args[0].toObject();
            //log << typeid(*obj).name() << " - " << typeid(Connection).name() << std::endl;
        
            try {
                if( typeid(*obj) == typeid(Connection) ) {
                    std::lock_guard<std::mutex> lock ( write_lock );
                    v.set( std::string( "Sending data to " ) +
                    obj->getName() );
                    Connection* conn= dynamic_cast<Connection*>(obj);
                    setDataConnection( conn );
                    return v;
                }
                else
                    setDataConnection( 0 );
            } catch( std::bad_typeid& e ) { setDataConnection( 0 ); }
        }
    }

    return Object::callMeta( method, args );
}
Example #9
0
unsigned int DefaultUserDataContainer::getUserObjectIndex(const std::string& name, unsigned int startPos) const
{
    for(unsigned int i = startPos; i < _objectList.size(); ++i)
    {
        Object* obj = _objectList[i].get();
        if (obj && obj->getName()==name) return i;
    }
    return _objectList.size();
}
Example #10
0
   // TODO: consider custom messages
   void DropAction::execute(Player *player, Command *command, Game *game) {

      Place             *location = player->getLocation();
      ObjectListCItPair invItems;

      invItems = player->getInventoryObjectsByName(command->getDirectObject());

      if (invItems.begin == invItems.end) {
         player->out("display") << "You don't have a " << command->getDirectObject()
            << "!" << endl;
         return;
      }

      try {

         Object *object =
            Entity::clarifyEntity<ObjectListCItPair, ObjectListCIt, Object *>(invItems,
            player);

         try {
 
            player->drop(object);

            string message = object->getMessage("drop");
            if (message.length() > 0) {
               player->out("display") << message << endl;
            }

            else {
               player->out("display") << "You drop the " << object->getName()
                  << "." << endl;
            }
         }

         catch (enum Being::dropError error) {

            switch (error) {

               case Being::DROP_UNDROPPABLE:
                  // TODO: add message for this (named undroppable)
                  player->out("display") << "You can't drop that!" << endl;
                  break;

               default:
                  player->err() << "Unknown error dropping object.  This is a "
                     << "bug." << endl;
                  break;
            }
         }
      }

      catch (string name) {
         player->out("display") << "You don't have a " << name << "!" << endl;
      }
   }
Example #11
0
std::string Debug::Detail::ToString(const Object& node, uint32_t level) {
    std::stringstream stream;
    stream << "Object {" << std::endl
    << Debug::indent(level + 1) << "Name: \"" << node.getName() << "\"" << std::endl    
    << Debug::indent(level + 1) << "Position: " << node.getPosition() << std::endl
    << Debug::indent(level + 1) << "Material: " << node.getMaterial() << std::endl
    << Debug::Detail::ToStringNodeChilds(node, level + 1)
    << Debug::indent(level) << "}"
    ;
    return stream.str();
}
Example #12
0
void World::find(const char* wildcard, ObjectResultSet& outResults, bool activeOnly, bool ignoreCase)
{
	for (ObjectSet::iterator itr = _attached.begin(), end = _attached.end(); itr != end; ++itr)
	{
		Object* o = *itr;

		if (activeOnly && !o->isActivated())
			continue;

		if (Wildcard::match(wildcard, o->getName(), ignoreCase))
			outResults.push_back(o);
	}
}
Mario* ObjectManager::getMario(){
	for (int i = 0; i < mListObject.size(); ++i){
		Object* ob = mListObject[i];
		if (ob == NULL){
			return NULL;
		}
		string obName = ob->getName();

		if (obName == Mario::OBJECT_NAME){
			return (Mario*)ob;
		}
	}
	return NULL;
}
// Recursively dump out contents of an object and its properties.
static void dumpObj(const Object& obj, int nSpaces) {
    indent(nSpaces);
    cout << obj.getConcreteClassName() << " Object " 
         << (obj.getName().empty()?"NONAME":obj.getName())
         << endl;
    for (int p=0; p < obj.getNumProperties(); ++p) {
        const AbstractProperty& ap = obj.getPropertyByIndex(p); 
        indent(nSpaces+2);
        cout << ap.getName() << "=" << ap.toString() << endl;
        // Check return values from Property API for debugging purposes
        bool t1 = ap.isListProperty();
        bool t2 = ap.isObjectProperty();
        bool t3 = ap.isOneObjectProperty();
        bool t4 = ap.isOneValueProperty();
        string ts = ap.getTypeName();
        indent(nSpaces+2);
        cout << "isList, isObject, isOneObject, isOneValue, typeName = " <<
            t1 <<", "<< t2 <<", "<< t3 <<", "<< t4 <<", "<< ts << endl;
        if (ap.isObjectProperty()) {
            for (int i=0; i < ap.size(); ++i)
                dumpObj(ap.getValueAsObject(i), nSpaces+4);
        }
    }
}
Example #15
0
void Dialog::updateBox() {
	GfxMan.lockFrame();

	_dlgBox->clear();

	// Entry


	const Aurora::DLGFile::Line *entry = _dlg->getCurrentEntry();
	if (entry) {
		// Name and portrait

		Object *speaker = getSpeaker();

		if (speaker) {
			_dlgBox->setPortrait(speaker->getPortrait());
			_dlgBox->setName(speaker->getName());
		} else
			_dlgBox->setName("[INVALID NPC]");

		// Text
		_dlgBox->setEntry(entry->text.getString());
	}

	// Replies

	const std::vector<const Aurora::DLGFile::Line *> &replies = _dlg->getCurrentReplies();
	if (!replies.empty()) {
		for (std::vector<const Aurora::DLGFile::Line *>::const_iterator r = replies.begin();
				 r != replies.end(); ++r) {

			Common::UString text = (*r)->text.getString();
			if (text.empty())
				text = TalkMan.getString((*r)->isEnd ? kEndDialog : kContinue);

			_dlgBox->addReply(text, (*r)->id);
		}
	} else
		_dlgBox->addReply(TalkMan.getString(kEndDialog), Aurora::DLGFile::kEndLine);

	_dlgBox->finishReplies();

	GfxMan.unlockFrame();
}
Example #16
0
int World::_destroy(lua_State* L)
{
	World* world = *topWorld(L);
	
	const char* name;

	if (lua_isstring(L, 2))
	{
		name = luaL_checkstring(L, 2);
	}
	else
	{
		Object* obj = *((Object **)lua_touserdata(L, 2));
		name = obj->getName().c_str();
	}

	ObjectManager::getSingleton().destroyInstance(name);

	return 0;
}
Example #17
0
bool PdfExport::addPopplerPage(XojPopplerPage* pdf, XojPopplerDocument doc)
{
    XOJ_CHECK_TYPE(PdfExport);

    Page* page = pdf->getPage();
    static int otherObjectId = 1;

    this->resources = page->getResourceDict();

    GList* replacementList = NULL;

    Dict* dict = page->getResourceDict();
    for (int i = 0; i < dict->getLength(); i++)
    {
        const char* cDictName = dict->getKey(i);
        PdfRefList* refList = (PdfRefList*) g_hash_table_lookup(this->refListsOther,
                              cDictName);
        if (!refList)
        {
            char* indexName = NULL;
            if (strcmp(cDictName, "Font") == 0)
            {
                indexName = g_strdup("F");
            }
            else if (strcmp(cDictName, "XObject") == 0)
            {
                indexName = g_strdup("I");
            }
            else if (strcmp(cDictName, "ExtGState") == 0)
            {
                indexName = g_strdup("Gs");
            }
            else if (strcmp(cDictName, "Pattern") == 0)
            {
                indexName = g_strdup("p");
            }
            else
            {
                indexName = g_strdup_printf("o%i-", otherObjectId++);
            }

            refList = new PdfRefList(this->xref, this->objectWriter, this->writer,
                                     indexName);
            char* dictName = g_strdup(dict->getKey(i));

            // insert the new RefList into the hash table
            g_hash_table_insert(this->refListsOther, dictName, refList);
        }

        refList->parse(dict, i, doc, replacementList);

    }

    Object* o = new Object();
    page->getContents(o);

    if (o->getType() == objStream)
    {
        Dict* dict = o->getStream()->getDict();

        Object filter;
        dict->lookup("Filter", &filter);
        //			// this may would be better, but not working...:-/
        //			Object oDict;
        //			oDict.initDict(dict);
        //			Stream * txtStream = stream->addFilters(oDict);
        //			writePlainStream(txtStream);

        if (filter.isNull())
        {
            writePlainStream(o->getStream(), replacementList);
        }
        else if (filter.isName("FlateDecode"))
        {
            writeGzStream(o->getStream(), replacementList);
        }
        else if (filter.isName())
        {
            g_warning("Unhandled stream filter: %s\n", filter.getName());
        }
    }
    else
    {
        g_warning("other poppler type: %i\n", o->getType());
    }

    for (GList* l = replacementList; l != NULL; l = l->next)
    {
        RefReplacement* f = (RefReplacement*) l->data;
        delete f;
    }
    g_list_free(replacementList);

    o->free();
    delete o;
    this->resources = NULL;

    return true;
}
Example #18
0
unsigned int arlCore::PlaneSystem::add3DPlane ( const Object &o )
{   // ID [1,..[
    return add3DPlane( o.getName() );
}
 bool operator==(const Object& other){
     return this->getName() == other.getName();
 }
//template <typename T>
void testComponent(const Component& instanceToTest)
{
    // Empty model used to serve as the aggregate Component
    Model model;
    model.setName("TheModel");

    // Make a copy so that we can modify the instance.
    Component* instance = instanceToTest.clone();
    const string& className = instance->getConcreteClassName();

    cout << "\n**********************************************************\n";
    cout << "* Testing " << className << endl;
    cout << "**********************************************************" << endl;

    // 1. Set properties to random values.
    // -----------------------------------
    cout << "Randomizing the component's properties." << endl;
    randomize(instance);

    // 2. Ensure that cloning produces an exact copy.
    // ----------------------------------------------
    // This will find missing calls to copyProperty_<name>().
    testCloning(instance);

    // 3. Serialize and de-serialize.
    // ------------------------------
    // This will find issues with de/serialization.
    cout << "Serializing and deserializing component." << endl;
    testSerialization(instance);

    const size_t instanceSize = getCurrentRSS();

    // 4. Verify Components structural attributes

    // -------------------------------------------------------------------
    cout << "Set up aggregate component." << endl;
    // 5. Add this component to an aggregate component.
    // ------------------------------------------------
    addObjectAsComponentToModel(instance, model);


    // 6. Connect up the aggregate; check that connections are correct.
    // ----------------------------------------------------------------
    // First make sure Connectors are satisfied.
    Component* sub = instance;
    ComponentList<Component> comps = instance->getComponentList<Component>();
    ComponentList<Component>::const_iterator it = comps.begin();

    while(sub) {
        int nc = sub->getNumConnectors();
        for (int i = 0; i < nc; ++i){
            AbstractConnector& connector = sub->updConnector(i);
            string dependencyTypeName = connector.getConnecteeTypeName();
            cout << "Connector '" << connector.getName() <<
                "' has dependency on: " << dependencyTypeName << endl;
            Object* dependency =
                Object::newInstanceOfType(dependencyTypeName);

            if (dependency == nullptr){
                // Get a concrete instance of a PhysicalFrame, which is a Body
                if (dependencyTypeName == "PhysicalFrame"){
                    dependency = Object::newInstanceOfType("Body");
                }
            }

            if (dependency) {
                //give it some random values including a name
                randomize(dependency);
                connector.setConnecteeName(dependency->getName());

                // add the dependency 
                addObjectAsComponentToModel(dependency, model);
            }
        }
        const Component& next = *it;
        //Now keep checking the subcomponents
        sub = const_cast<Component *>(&next);
        it++;
    }

    // This method calls connect().
    cout << "Call Model::setup()." << endl;
    try{
        model.setup();
    }
    catch (const std::exception &x) {
        cout << "testComponents::" << className << " unable to connect to model:" << endl;
        cout << " '" << x.what() << "'" <<endl;
        cout << "Error is likely due to " << className;
        cout << " having structural dependencies that are not specified as Connectors.";
        cout << endl;
    }


    // 7. Build the system.
    // --------------------
    SimTK::State initState;
    try{
        initState = model.initSystem();
    }
    catch (const std::exception &x) {
        cout << "testComponents::" << className << " unable to initialize the system:" << endl;
        cout << " '" << x.what() << "'" << endl;
        cout << "Skipping ... " << endl;
    }

    // Outputs.
    // --------
    cout << "Invoking Output's." << endl;
    for (auto it = instance->getOutputsBegin();
            it != instance->getOutputsEnd(); ++it)
    {
        const std::string thisName = it->first;
        const AbstractOutput* thisOutput = it->second.get();

        cout << "Testing Output " << thisName << ", dependent on " <<
            thisOutput->getDependsOnStage().getName() << endl;

        // Start fresh.
        SimTK::State state(initState);

        // 8. Check that each output throws an exception if we're below its
        // dependsOnStage. Model::initSystem() gives us a state that is already
        // realized to Model.
        if (thisOutput->getDependsOnStage() > SimTK::Stage::Model)
        {
            model.getSystem().realize(state,
                    thisOutput->getDependsOnStage().prev());
            ASSERT_THROW(SimTK::Exception::StageTooLow,
                    thisOutput->getValueAsString(state);
            );
        }
//template <typename T>
void testComponent(const Component& instanceToTest)
{
    // Empty model used to serve as the aggregate Component
    Model model;

    // Make a copy so that we can modify the instance.
    Component* instance = instanceToTest.clone();
    const string& className = instance->getConcreteClassName();

    cout << "\n**********************************************************\n";
    cout << "* Testing " << className << endl;
    cout << "**********************************************************" << endl;

    // 1. Set properties to random values.
    // -----------------------------------
    cout << "Randomizing the component's properties." << endl;
    randomize(instance); 

    // 2. Ensure that cloning produces an exact copy.
    // ----------------------------------------------
    // This will find missing calls to copyProperty_<name>().
    cout << "Cloning the component." << endl;
    Component* copyInstance = instance->clone();
    if (!(*copyInstance == *instance))
    {
        cout << "XML serialization for the first instance:" << endl;
        cout << instance->dump() << endl;
        cout << "XML serialization for the clone:" << endl;
        cout << copyInstance->dump() << endl;
        throw Exception(
                "testComponents: for " + className +
                ", clone() did not produce an identical object.",
                __FILE__, __LINE__);
    }
    // TODO should try to delete even if exception is thrown.
    delete copyInstance;
    
    // 3. Serialize and de-serialize.
    // ------------------------------
    // This will find issues with serialization.
    cout << "Serializing and deserializing component." << endl;
    string serializationFilename =
        "testing_serialization_" + className + ".xml";
    instance->print(serializationFilename);
    Object* deserializedInstance =
        static_cast<Object*>(Object::makeObjectFromFile(serializationFilename));
    if (!(*deserializedInstance == *instance))
    {
        cout << "XML for serialized instance:" << endl;
        instance->dump();
        cout << "XML for seriaization of deseralized instance:" <<
            endl;
        deserializedInstance->dump();
        throw Exception(
                "testComponents: for " + className +
                ", deserialization did not produce an identical object.",
                __FILE__, __LINE__);
    }
    // TODO should try to delete even if exception is thrown.
    delete deserializedInstance;

    // 4. Set up the aggregate component.
    // -------------------------------------------------------------------
    cout << "Set up aggregate component." << endl;
    if (model.getName() == "dummyModel")
    {
        // User did not provide a model; create a fresh model.
        model = Model();
    }

    // 5. Add this component to an aggregate component.
    // ------------------------------------------------
    addObjectAsComponentToModel(instance, model);

    // 6. Connect up the aggregate; check that connections are correct.
    // ----------------------------------------------------------------
    // First make sure Connectors are satisfied.
    int nc = instance->getNumConnectors();
    for (int i = 0; i < nc; ++i){
        AbstractConnector& connector = instance->updConnector(i);
        string dependencyTypeName = connector.getConnectedToTypeName();
        cout << "Connector '" << connector.getName() << 
            "' has dependency on: " << dependencyTypeName << endl;
        Object* dependency =
            Object::newInstanceOfType(dependencyTypeName);
        
        if (dependency == nullptr){
            // Get a concrete instance of a PhysicalFrame, which is a Body
            if (dependencyTypeName == "PhysicalFrame"){
                dependency = Object::newInstanceOfType("Body");
            }
        }
        
        //give it some random values including a name
        randomize(dependency);
        connector.set_connected_to_name(dependency->getName());

        // add the dependency 
        addObjectAsComponentToModel(dependency, model);
    }

    // This method calls connect().
    cout << "Call Model::setup()." << endl;
    try{
        model.setup();
    }
    catch (const std::exception &x) {
        cout << "testComponents::" << className << " unable to connect to model:" << endl;
        cout << " '" << x.what() << "'" <<endl;
        cout << "Error is likely due to " << className;
        cout << " having structural dependencies that are not specified as Connectors.";
        cout << endl;
    }

    // 7. Build the system.
    // --------------------
    SimTK::State initState;
    try{
        initState = model.initSystem();
    }
    catch (const std::exception &x) {
        cout << "testComponents::" << className << " unable to initialize the system:" << endl;
        cout << " '" << x.what() << "'" << endl;
        cout << "Skipping ... " << endl;
    }

    // Outputs.
    // --------
    cout << "Invoking Output's." << endl;
    for (auto it = instance->getOutputsBegin();
            it != instance->getOutputsEnd(); ++it)
    {
        const std::string thisName = it->first;
        const AbstractOutput* thisOutput = it->second.get();

        cout << "Testing Output " << thisName << ", dependent on " <<
            thisOutput->getDependsOnStage().getName() << endl;

        // Start fresh.
        SimTK::State state(initState);

        // 8. Check that each output throws an exception if we're below its
        // dependsOnStage. Model::initSystem() gives us a state that is already
        // realized to Model.
        if (thisOutput->getDependsOnStage() > SimTK::Stage::Model)
        {
            model.getSystem().realize(state,
                    thisOutput->getDependsOnStage().prev());
            ASSERT_THROW(Exception,
                    thisOutput->getValueAsString(state);
            );
        }
int main()
{
	try {
		Model testModel;
        srand((unsigned)time(0));
        // for Body, Joint, Constraint, Force, Marker, ContactGeometry, Controller and Probe
        ArrayPtrs<OpenSim::Body> availableBodyTypes;
        Object::getRegisteredObjectsOfGivenType<OpenSim::Body>(availableBodyTypes);
        for (int i=0; i< availableBodyTypes.getSize(); i++){
            Object* clone = availableBodyTypes[i]->clone();
            Object* randClone = randomize(clone);
            testModel.addBody(Body::safeDownCast(randClone));
			const Body& inModel = testModel.getBodySet().get(randClone->getName());
			ASSERT(inModel == *randClone);
			randClone->print("bodyTestPrint.xml");
        }

		ArrayPtrs<OpenSim::Joint> availablJointTypes;
		Object::getRegisteredObjectsOfGivenType<OpenSim::Joint>(availablJointTypes);
		for (int i = 0; i< availablJointTypes.getSize(); i++){
			Object* clone = availablJointTypes[i]->clone();
			Object* randClone = randomize(clone);
			testModel.addJoint(Joint::safeDownCast(randClone));
		}

		ArrayPtrs<OpenSim::Constraint> availableConstraintTypes;
		Object::getRegisteredObjectsOfGivenType<OpenSim::Constraint>(availableConstraintTypes);
		for (int i = 0; i< availableConstraintTypes.getSize(); i++){
			Object* clone = availableConstraintTypes[i]->clone();
			Object* randClone = randomize(clone);
			testModel.addConstraint(Constraint::safeDownCast(randClone));
		}

        ArrayPtrs<OpenSim::Force> availableForceTypes;
        Object::getRegisteredObjectsOfGivenType<OpenSim::Force>(availableForceTypes);
        for (int i=0; i< availableForceTypes.getSize(); i++){
            Object* clone = availableForceTypes[i]->clone();
            Object* randClone = randomize(clone);
            testModel.addForce(Force::safeDownCast(randClone));
        }

        ArrayPtrs<OpenSim::Controller> availableControllerTypes;
        Object::getRegisteredObjectsOfGivenType<OpenSim::Controller>(availableControllerTypes);
        for (int i=0; i< availableControllerTypes.getSize(); i++){
            Object* clone = availableControllerTypes[i]->clone();
            Object* randClone = randomize(clone);
            testModel.addController(Controller::safeDownCast(randClone));
        }

        ArrayPtrs<OpenSim::Probe> availableProbeTypes;
        Object::getRegisteredObjectsOfGivenType<OpenSim::Probe>(availableProbeTypes);
        for (int i=0; i< availableProbeTypes.getSize(); i++){
            Object* clone = availableProbeTypes[i]->clone();
            Object* randClone = randomize(clone);
            testModel.addProbe(Probe::safeDownCast(randClone));
        }

        testModel.print("allComponents.osim");

        Model deserializedModel("allComponents.osim", false);
		ASSERT(testModel == deserializedModel,  
			"deserializedModel FAILED to match original model.");       
	}
	catch (const Exception& e) {
        e.print(cerr);
        return 1;
    }
    cout << "Done" << endl;
	return 0;
}
Example #23
0
int main()
{
	srand((unsigned)time(NULL));		//initialize random number generator
	bool done = false;					//for game exit
	bool death = false;					//player death flag
	bool happyLeprechaun = false;		//Leprechaun mood flag
	int move = 0;						//move option
	Space* location = NULL;				//current location pointer
	int turnsRemaining = 30;			//counter for number of turns
	int hydration = 10;					//hydration "tank"
	bool flashlightOn = false;			//flashlight state
	int flashDeath = 0;					//counter for death by ghost in tower
	Object* backpack[4];				//pointer to backpack array
	for (int i = 0; i < 4; i++)
	{
		backpack[i] = NULL;				//set backpack object pointers to NULL
	}
	Object* currentObject = NULL;		//object currently being held by player

	//seed the world
	//create the spaces
	Space* ravine = new Ravine("Mossy ravine", "A narrow ravine with steep moss covered sides, a stream, and gently moving dense mist...", "You are in a ravine.", "You see a gently flowing stream, a dark wet cave to your left \nthat the stream comes out of, another cave behind you, \nand in front of you is a bridge to two stone stairways, \nboth leading up into the mist. \nAt the bridge there is a clear orb atop a marble obelisk,  \nand the following items:", "");
	Space* cave1 = new Cave("Wet Cave", "A pitch black, very wet cave with a stream flowing towards the entrance.", "You are in a very wet & dark cave.", "All you can see is dim light in the direction of the cave mouth and \na black orb atop a marble obelisk. \nYou will need a light source to see what else may be here.", "You can see the dim light in the direction of the cave mouth, \na giant menacing spider furter back in the cave, \na black orb atop a marble obelisk, and the following items:");
	Space* cave2 = new Cave("Dry Cave", "A pitch black cave", "You are in a dark cave.", "All you can see is dim light in the direction of the cave mouth and \na black orb atop a marble obelisk. \nYou will need a light source to see what else may be here.", "You can see the dim light in the direction of the cave mouth, \na giant menacing spider further back in the cave, \na black orb atop a marble obelisk, and the following items:");
	Space* tower1 = new Tower("Stone Tower", "A circular room with open windows at the top of a high stone tower.", "You are in a circular room at the top of a stone tower.", "You are in a dim circular room with windows at the top of a stone tower. \nIt is very misty outside. \nYou can see stairs going down, a white orb atop a marble obelisk, \na rope bridge leading into the mist, and the following items:", "");
	Space* treehouse1 = new Treehouse("Tree House", "A rustic, weathered tree house surrounded by mist.", "You are in a rustic, weathered tree house.", "You can see stairs going down, a bright green orb atop a wooden post, \na rope bridge leading into the mist, and the following items:", "");

	//set pointers of the spaces
	ravine->setPointers(cave1, cave2, tower1, treehouse1);
	cave1->setPointers(ravine, NULL, NULL, NULL);
	cave2->setPointers(ravine, NULL, NULL, NULL);
	tower1->setPointers(ravine, treehouse1, NULL, NULL);
	treehouse1->setPointers(ravine, tower1, NULL, NULL);

	//create objects
	Object* water1 = new Object(1, "Sealed water bottle");
	Object* water2 = new Object(1, "Sealed water bottle");
	Object* water3 = new Object(1, "Sealed water bottle");
	Object* water4 = new Object(2, "1/2 empty water bottle");
	Object* water5 = new Object(2, "1/2 empty water bottle");
	Object* orb = new Object(3, "Irish green glass orb.");
	Object* knife = new Object(4, "Hunting knife");
	Object* flashlight = new Object(5, "Flashlight");

	//place objects
	cave1->addObject(water1);	 //good water to wet cave
	cave1->addObject(knife);	 //knife to wet cave
	cave1->addObject(water5);	 //bad water to wet cave
	cave2->addObject(water2);	 //good water to dry cave
	cave2->addObject(orb);		 //green orb to dry cave
	cave2->addObject(water4);	 //bad water to dry cave
	tower1->addObject(flashlight); //flashlight to tower
	treehouse1->addObject(water3);	 //good water to treehouse

	//set start location
	location = ravine;

	//test spaces
	//cout << ravine->getName() << endl << ravine->getDescription() << endl << ravine->getEntryMessage() << endl << ravine->getLook1() << endl << ravine->getLook2() << endl;
	//cout << endl;
	//cout << cave1->getName() << endl << cave1->getDescription() << endl << cave1->getEntryMessage() << endl << cave1->getLook1() << endl << cave1->getLook2() << endl;
	//cout << endl;
	//cout << cave2->getName() << endl << cave2->getDescription() << endl << cave2->getEntryMessage() << endl << cave2->getLook1() << endl << cave2->getLook2() << endl;
	//cout << endl;
	//cout << tower1->getName() << endl << tower1->getDescription() << endl << tower1->getEntryMessage() << endl << tower1->getLook1() << endl << tower1->getLook2() << endl;
	//cout << endl;
	//cout << treehouse1->getName() << endl << treehouse1->getDescription() << endl << treehouse1->getEntryMessage() << endl << treehouse1->getLook1() << endl << treehouse1->getLook2() << endl;
	//cout << endl;

	//display instructions
	cout << endl;
	cout << endl;
	cout << "****************************************" << endl;
	cout << "Welcome to \"Make the Leprechaun Happy\" game" << endl;
	cout << endl;
	cout << "You will have 30 moves to find and please the Leprechaun. " << endl;
	cout << "Your current hydration level is 10. You loose one hydration level" << endl;
	cout << "every time you move or cancel a move." << endl;
	cout << "Drinking safe water adds 5 to your hydration level." << endl;
	cout << "This is important because if your hydration level reaches zero you die." << endl;
	cout << "You can only hold and use one item at a time, but you have a" << endl;
	cout << "backpack that holds up to three items." << endl;
	cout << "You can drop items wherever you are and they keep working..." << endl;
	cout << "Orbs exist in many places and you can touch them." << endl;
	cout << endl;
	cout << "Most importantly, if the Leprechaun doesn't laugh the world ends." << endl;
	cout << endl;
	cout << "Dangerous things exist here..." << endl;
	cout << endl;
	cout << "Please save the world!" << endl;
	cout << endl;
	cout << "HINT: " << endl;
	cout << "This puzzle / game can be solved in only 5 moves" << endl;
	cout << "and 5 \"actions\" (pick up, drop, use, touch)." << endl;
	cout << "Good luck..." << endl;
	cout << endl;
	cout << "Press enter to continue..." << endl;
	cin.get();
	cout << "You begin your journey in a cool and damp ravine." << endl;
	cout << "The steep walls are thickly covered in ferns and moss." << endl;
	cout << "A crystal clear stream gently flows by in front of you." << endl;
	cout << "Mist continually moves through the ravine creating a serene" << endl;
	cout << "feel, but visibility is limited... " << endl;
	cout << endl;
	cout << "Let the game begin..." << endl;
	

	while (done != true)
	{
		//death checks
		if (turnsRemaining < 1)
		{
			done = true;
			death = true;
		}
		else if (hydration < 1)
		{
			done = true;
			death = true;
		}
		//status update to user
		else cout << endl << "You have " << turnsRemaining << " turns left and your hydration level is " << hydration << "." << endl;
		cout << endl;
		if (hydration < 3 && hydration > 0) cout << "You are dangerously close to dying from dehydration..." << endl;
		cout << endl;
		if (!death)
		{
			cout << "Press enter to continue..." << endl;
			//cin.clear();
			//cin.ignore(256, '\n');
			cin.clear();
			//cin.get();
			cin.get();
			cout << endl;
			displayMenu();
			int menuChoice = 0;			//for menu/user inputs
			menuChoice = getInput();
			switch (menuChoice) {
			case 0:		//exit option
			{
				done = true;
				break;
			}
			case 1:		//look
			{
				if ((location == cave1 || location == cave2) && flashlightOn)
				{
					cout << endl << location->getLook2() << endl << endl;
					location->displayObjects();
				}
				else if ((location == cave1 || location == cave2) && !flashlightOn)
				{
					cout << endl << location->getLook1() << endl << endl;
				}
				else
				{
					//display location view
					cout << endl << location->getLook1() << endl << endl;
					//display objects present
					location->displayObjects();
				}
				cin.ignore(256, '\n');
				break;
			}
			case 2:		//move
			{
				move = location->move();
				switch (move)
				{
				case 1:
				{
					location = location->getPointer(1);
					cout << endl << location->getEntryMessage() << endl;
					turnsRemaining -= 1;
					hydration -= 1;
				}
				break;
				case 2:
				{
					location = location->getPointer(2);
					cout << endl << location->getEntryMessage() << endl;
					turnsRemaining -= 1;
					hydration -= 1;
				}
				break;
				case 3:
				{
					location = location->getPointer(3);
					cout << endl << location->getEntryMessage() << endl;
					turnsRemaining -= 1;
					hydration -= 1;
				}
				break;
				case 4:
				{
					location = location->getPointer(4);
					cout << endl << location->getEntryMessage() << endl;
					turnsRemaining -= 1;
					hydration -= 1;
				}
				break;
				case 5:
				{
					cout << endl << "You have not moved. You still lose hydration when you don't move." << endl;
					cout << endl << location->getEntryMessage() << endl;
					hydration -= 1;
				}
				break;
				case 9:
				{
					cout << endl << "You have been stung by a giant spider and are being packaged" << endl;
					cout << "for future enjoyment. Game over." << endl;
					cout << "Press enter to continue." << endl;
					death = true;
					done = true;
				}
				cin.ignore(256, '\n');
				break;
				} //end of move switch
			}
			break;
			case 3:		//use item
			{
				//test if object being held
				if (currentObject != NULL)
				{
					int id = currentObject->getId();
					switch (id)
					{
					case 1:		//sealed water bottle
					{
						cout << "You are holding a sealed water bottle." << endl;
						cout << "Do you want to drink it? (1 for Yes, 2 for No)" << endl;
						int choice = getInput();
						if (choice == 1)
						{
							hydration += 5;
							cout << "Your hydration level is now " << hydration << endl;
							currentObject->setId(6);
							currentObject->setName("Empty water bottle");
							cout << "FYI, you are holding an empty bottle." << endl;
						}
						else if (choice == 2)
						{
							cout << "OK, you did not drink the water. You are still holdling the bottle." << endl;
						}
						else cout << "Invalid response. Item has not been used." << endl << endl;
					}
					break;
					case 2:		//comprimised water bottle
					{
						cout << "You are holding a 1/2 full water bottle." << endl;
						cout << "Do you want to drink it? (1 for Yes, 2 for No)" << endl;
						int choice = getInput();
						if (choice == 1)
						{
							cout << "Bad choice...you are now dead." << endl;
							currentObject->setId(6);
							currentObject->setName("Empty water bottle");
							death = true;
							done = true;
						}
						else if (choice == 2)
						{
							cout << "OK, you did not drink the water. You are still holdling the bottle." << endl;
						}
						else cout << "Invalid response. Item has not been used." << endl << endl;
					}
					break;
					case 3:		//glass orb
					{
						cout << "You are holding a glass orb." << endl;
						cout << "Do you want to use it? (1 for Yes, 2 for No)" << endl;
						int choice = getInput();
						if (choice == 1)
						{
							if (location == tower1)
							{
								cout << "Congratulations you have completed the game." << endl;
								done = true;
							}
							else cout << "The orb doesn't seem to do anything here..." << endl;
						}
						else if (choice == 2)
						{
							cout << "OK, you are still holdling the orb." << endl;
						}
						else cout << "Invalid response. Orb has not been used." << endl << endl;
					}
					break;
					case 4:		//knife
					{
						cout << "You are holding a very sharp hunting knife." << endl;
						cout << "Do you want to use it? (1 for Yes, 2 for No)" << endl;
						int choice = getInput();
						if (choice == 1)
						{
							if (location == cave1 || location == cave2)
							{
								int choice;
								cout << "Enter 1 to kill yourself. This will save time..." << endl;
								cout << "Enter 2 to throw the kife towards the back of the cave." << endl;
								choice = getInput();
								if (choice == 1)
								{
									cout << "You are dead. Game over..." << endl;
									death = true;
									done = true;
								}
								else if (choice == 2) cout << "Congratulations, you have killed a giant spider." << endl;
								else cout << "Invalid choice nothing has been done, you are still holding the knife." << endl;
							}
							else
							{
								int choice;
								cout << "Enter 1 to kill yourself. This will save time..." << endl;
								cout << "Enter 2 to throw the kife." << endl;
								choice = getInput();
								if (choice == 1)
								{
									cout << "You are dead. Game over..." << endl;
									death = true;
									done = true;
								}
								else if (choice == 2)
								{
									cout << "Such bravado..." << endl;
									location->addObject(currentObject);
									currentObject = NULL;
								}
								else cout << "Invalid choice nothing has been done, you are still holding the knife." << endl;
							}
						}
						else if (choice == 2)
						{
							cout << "OK, you are still holdling the knife." << endl;
						}
						else cout << "Invalid response. Knife has not been used." << endl << endl;
					}
					break;
					case 5:		//flashlight
					{
						cout << "You are holding a flashlight." << endl;
						if (flashlightOn == true) cout << "It is already on...." << endl;
						if (location == tower1 && flashlightOn)
						{
							cout << "The tower ghost doesn't like flashlights." << endl;
							cout << "He turned it off." << endl;
							cout << "Press enter to continue..." << endl;
							//cin.clear();
							cin.ignore(256, '\n');
							cin.get();
							flashlightOn = false;
							flashDeath += 1;
							if (flashDeath >= 3)
							{
								cout << "You really pissed off the tower ghost. He pushed you out the" << endl;
								cout << "window to your death. Game over." << endl;
								death = true;
								done = true;
							}
						}
						cout << "Do you want the flashlight on or off? (1 for On, 2 for Off)" << endl;
						int choice = getInput();
						if (choice == 1)
						{
							flashlightOn = true;
							cout << "Flashlight on." << endl;
							if (location == cave1 || location == cave2)
							{
								cout << "You may want to have a look around..." << endl;
							}
							else if (location == tower1)
							{
								cout << "The tower ghost doesn't like flashlights." << endl;
								cout << "He turned it off and threw it out the window." << endl;
								cout << "Press enter to continue..." << endl;
								//cin.clear();
								//cin.ignore(256, '\n');
								cin.get();
								flashDeath += 1;
								flashlightOn = false;
								ravine->addObject(currentObject);
								currentObject = NULL;
								if (flashDeath >= 3)
								{
									cout << "You really pissed off the tower ghost. He pushed you out the" << endl;
									cout << "window to your death. Game over." << endl;
									death = true;
									done = true;
								}
							}
							else if (location == ravine)
							{
								cout << "A flashlight doesn't do much here..." << endl;
								cout << "Press enter to continue..." << endl;
								//cin.clear();
								//cin.ignore(256, '\n');
								cin.get();
							}
							else cout << "You might want to have a look around..." << endl;
						}
						else if (choice == 2)
						{
							cout << "Flashlight is off." << endl;
						}
						else cout << "Invalid response. No change to flashlight." << endl << endl;
					}
					break;
					case 6:
					{
						cout << "You are holding an empty water bottle." << endl;
						cout << "Not much you can do with that..." << endl;
					}
					break;
					default:
						cout << "Not a valid choice" << endl;
						break;
					}
				}
				else
				{
					cout << "You are not holding anything." << endl;
				}
				cin.ignore(256, '\n');
				break;
			}
			case 4:		//pick up item
			{
				//test if object already being held
				if (currentObject == NULL)
				{
					if ((location == cave1 || location == cave2) && !flashlightOn)	//in cave but no light
					{
						cout << "It's too dark to see any items. Some light may help." << endl;
					}
					//test for cave location and flashlight status   OR   any other location
					else if (((location == cave1 || location == cave2) && flashlightOn) || (location != cave1 || location != cave2))
					{
						//test for items
						if (location->objectsPresent())
						{
							int choice = -1;
							int getComplete = false;
							while (choice = -1 && getComplete == false)
							{
								location->displayObjects();		//display item list
								cout << endl;
								cout << "Enter the Item # and press enter." << endl;
								choice = getInput();			//user selects item
								if (choice > -1 && choice < 10)	//test for valid choice
								{
									if (location->getObject(choice) != NULL)
									{
										currentObject = (location->getObject(choice)); //add object to currentObject
										location->removeObject(choice);		//remove object from space
										cout << "You are now holding " << currentObject->getName() << endl;
										getComplete = true;
									}
									else
									{
										cout << "Incorrect choice. Try again" << endl;
										choice = -1;
									}
								}
							}
						}
						else
						{
							cout << "No items to pick up here." << endl;
						}
					}
					/*else if ((location == cave1 || location == cave2) && !flashlightOn)
					{
						cout << endl << location->getLook1() << endl << endl;
					}*/
					//else
						//{
						//	//display location view
						//	cout << endl << location->getLook1() << endl << endl;
						//	//display objects present
						//	location->displayObjects();
						//}
				}
				else
				{
					cout << "You cannot pick up another item because you are already holding something" << endl;
				}
				cin.ignore(256, '\n');
				break;
			}
			case 5:		//drop item
			{
				//test if object already being held
				if (currentObject != NULL)
				{
					//int complete = false;
					//add object to space
					location->addObject(currentObject);
					currentObject = NULL;
					cout << "You have dropped the item." << endl;
					//complete = true;
				}
				else
				{
					cout << "You are not holding anything, nothing to drop" << endl;
				}
				cin.ignore(256, '\n');
				break;
			}
			case 6:		//list backpack & item held
			{
				if (currentObject != NULL) cout << "You are holdling: " << endl << currentObject->getName() << endl;
				else cout << "You are not holding anything" << endl;
				cout << endl;
				bool noObjects = true;
				cout << "Backpack contents: " << endl;
				for (int i = 0; i < 4; i++)
				{
					if (backpack[i] != NULL)
					{
						cout << "Item # " << i << "   " << backpack[i]->getName() << endl;
						noObjects = false;
					}
				}
				if (noObjects) cout << "No items." << endl;
				cout << endl;
				cin.ignore(256, '\n');
				break;
			}
			case 7:		//put item in backpack
			{
				//test if object being held
				if (currentObject != NULL)
				{
					int complete = false;
					for (int i = 0; i < 4; i++)
					{
						if (!complete && backpack[i] == NULL)
						{
							backpack[i] = currentObject;
							complete = true;
						}
					}
					if (complete)
					{
						currentObject = NULL;
						cout << "The item has been placed in your backpack." << endl;
					}
					else cout << "Backpack is full. Item not placed in backpack.";
				}
				else
				{
					cout << "You are not holding anything to put in the backpack." << endl;
				}
				cin.ignore(256, '\n');
				break;
			}
			case 8:		//get item from backpack
			{
				//test if object already being held
				if (currentObject == NULL)
				{
					int choice = -1;
					int complete = false;
					//test for items
					bool isEmpty = true;
					for (int i = 0; i < 4; i++)
					{
						if (isEmpty && backpack[i] != NULL) isEmpty = false;
					}
					if (!isEmpty)
					{
						while (choice == -1 && complete == false)
						{
							//display item list
							for (int i = 0; i < 4; i++)
							{
								if (backpack[i] != NULL)
								{
									cout << "Item # " << i << "   " << backpack[i]->getName() << endl;
								}
							}
							cout << endl;
							cout << "Enter the Item # and press enter." << endl;
							choice = getInput();			//user selects item
							if (choice > -1 && choice < 4)	//test for valid choice
							{
								if (backpack[choice] != NULL)
								{
									currentObject = backpack[choice];
									backpack[choice] = NULL;			//remove object from backpack
									cout << "You are now holding " << currentObject->getName() << endl;
									complete = true;
								}
								else
								{
									cout << "Incorrect choice. Try again" << endl;
									choice = -1;
								}
							}
							else
							{
								cout << "Incorrect choice. Try again" << endl;
								choice = -1;
							}
						}
					}
					else
					{
						cout << "No items in backpack." << endl;
					}
				}
				else
				{
					cout << "You cannot get something from the backpack because you are already holding something" << endl;
				}
				cin.ignore(256, '\n');
				break;
			}
			case 9:		//special option
			{
				int specialResult = location->special();
				switch (specialResult)
				{
				case 1:			//cases 1 to 4 are result from transporting after touching ravine orb
					location = location->getPointer(specialResult);
					turnsRemaining -= 1;
					break;
				case 2:
					location = location->getPointer(specialResult);
					turnsRemaining -= 1;
					break;
				case 3:
					location = location->getPointer(specialResult);
					turnsRemaining -= 1;
					break;
				case 4:
					location = location->getPointer(specialResult);
					turnsRemaining -= 1;
					break;
				case 5:		//touching orb in a cave
					turnsRemaining -= 3;
					hydration -= 2;
					cout << location->getEntryMessage() << endl;
					break;
				case 6:		//touching orb in tower
					hydration += 1;
					cout << "The mist has increased your hydration level 1 point." << endl;
					cout << location->getEntryMessage() << endl;
					break;
				case 7:		//touching orb in treehouse
					if (currentObject == orb)
					{
						cout << "The Leprechaun looks at the orb in your hand and begins to laugh hysterically." << endl;
						cout << "He snatches the orb from your hand and jumps out of the window!" << endl;
						happyLeprechaun = true;
						done = true;
					}
					else
					{
						cout << "The Leprechaun looks at your hand, then to the ground. \nHe stands for a moment, then retreats to behind the chair." << endl;
					}
					break;
				}
				//cin.ignore(256, '\n');
				break;  //break out of menu case 9
			}
			default:
				cout << "Not a valid choice" << endl;
				cin.ignore(256, '\n');
				break;
			}	//end of menu loop
		}
	}	//end of game while loop
	if (hydration < 1) cout << "You died from dehydration." << endl;
	if (turnsRemaining < 1) cout << "You have died from exhaustion." << endl;
	if (death) cout << endl << "Sorry you didn't make it. Try again ;-)" << endl;
	if (happyLeprechaun) cout << endl << "You are a hero! \nYou made him happy! \nYou have saved the world! \n******* Well Done! *******" << endl;
	cout << "\n\n";
	return 0;
}
Example #24
0
Magic3D::Object* Magic3D::Object::spawn(std::string name, std::string layerName, bool keepChildrenLayer)
{
    void* result = NULL;
    Layer* layer = Scene::getInstance()->getLayer(layerName);

    if (!layer)
    {
        layer = Scene::getInstance()->getLayer(M3D_MAIN_LAYER_NAME);
    }

    result = getObject(name);
    if (!result && layer)
    {
        bool allchildren = true;

        std::vector<Object*>::const_iterator it_o = children.begin();
        while (it_o != children.end())
        {
            Object* child = *it_o++;

            std::string childName = child->getName();
            size_t separator = childName.rfind('.');
            childName = name + "." + (separator == childName.npos ? childName : childName.substr(separator + 1));

            if (getObject(childName))
            {
                allchildren = false;
                break;
            }
        }

        if (allchildren)
        {
            result = spawn(name);
            ResourceManager::getObjects()->add(static_cast<Object*>(result));
            Scene::getInstance()->addObject(layer, static_cast<Object*>(result));

            it_o = children.begin();
            while (it_o != children.end())
            {
                Object* child = *it_o++;

                std::string childName = child->getName();
                size_t separator = childName.rfind('.');
                childName = name + "." + (separator == childName.npos ? childName : childName.substr(separator + 1));

                Object* spawned = child->spawn(childName, keepChildrenLayer && child->getLayer() ? child->getLayer()->getName() : layerName, keepChildrenLayer);
                if (spawned != child)
                {
                    spawned->setParent(static_cast<Object*>(result));
                    if (child->getParentBone() && static_cast<Object*>(result)->getType() == eOBJECT_MODEL)
                    {
                        Bone* bone = static_cast<Model*>(result)->getSkeleton()->getBoneByName(child->getParentBone()->getName());
                        spawned->setParentBone(bone);
                    }
                }
            }
        }
        else
        {
            result = this;
        }
    }

    if (result && getRigidBody())
    {
        Physics::getInstance()->add(static_cast<Object*>(result));
    }

    return static_cast<Object*>(result);
}