Ejemplo n.º 1
0
void SimSet::write(Stream &stream, U32 tabStop, U32 flags)
{
   MutexHandle handle;
   handle.lock(mMutex);

   // export selected only?
   if((flags & SelectedOnly) && !isSelected())
   {
      for(U32 i = 0; i < size(); i++)
         (*this)[i]->write(stream, tabStop, flags);

      return;

   }

   stream.writeTabs( tabStop );
   char buffer[ 2048 ];
   const U32 bufferWriteLen = dSprintf( buffer, sizeof( buffer ), "new %s(%s) {\r\n", getClassName(), getName() && !( flags & NoName ) ? getName() : "" );
   stream.write( bufferWriteLen, buffer );
   writeFields( stream, tabStop + 1 );

   if(size())
   {
      stream.write(2, "\r\n");
      for(U32 i = 0; i < size(); i++)
      {
         SimObject* child = ( *this )[ i ];
         if( child->getCanSave() )
            child->write(stream, tabStop + 1, flags);
      }
   }

   stream.writeTabs(tabStop);
   stream.write(4, "};\r\n");
}
Ejemplo n.º 2
0
void CustomModel::createModel(bool ignorePhysicsManager) {

	QString pathName = "/";
	pathName = pathName.append(getName());

	for(QListIterator<SimObject*> i(mSimObjects); i.hasNext();) {
		SimObject *object = i.next();
		object->setName(object->getName().prepend("/"));

		if(!ignorePhysicsManager) {
			QList<Value*> parameters = object->getParameters();
			for(QListIterator<Value*> j(parameters); j.hasNext();) {
				StringValue *stringValue = dynamic_cast<StringValue*>(j.next());
				if(stringValue != 0) {
					if(stringValue->get().contains("$name$")) {
						QString replacedString = stringValue->get().replace("$name$", pathName);
						stringValue->set(replacedString);
					}
				}
			}
		}
		mAgent->addObject(object);
	}

	if(!ignorePhysicsManager) {
		Physics::getPhysicsManager()->addSimObjectGroup(mAgent);
	}
	else {
		delete mAgent;
	}
}
 void run()
 {
    for( AbstractClassRep* classRep = AbstractClassRep::getClassList();
         classRep != NULL;
         classRep = classRep->getNextClass() )
    {
       // Create object.
       
       ConsoleObject* object = classRep->create();
       test( object, avar( "AbstractClassRep::create failed for class '%s'", classRep->getClassName() ) );
       if( !object )
          continue;
       
       // Make sure it's a SimObject.
       
       SimObject* simObject = dynamic_cast< SimObject* >( object );
       if( !simObject )
       {
          SAFE_DELETE( object );
          continue;
       }
       
       // Register the object.
       
       bool result = simObject->registerObject();
       test( result, avar( "registerObject failed for object of class '%s'", classRep->getClassName() ) );
       
       if( result )
          simObject->deleteObject();
       else
          SAFE_DELETE( simObject );
    }
 }
Ejemplo n.º 4
0
SimObject *loadObjectStream(Stream *stream)
{
   const char *className = stream->readSTString(true);
   ConsoleObject *conObj = ConsoleObject::create(className);
   if(conObj == NULL)
   {
      Con::errorf("Sim::restoreObjectStream - Could not create object of class \"%s\"", className);
      return NULL;
   }

   SimObject *simObj = dynamic_cast<SimObject *>(conObj);
   if(simObj == NULL)
   {
      Con::errorf("Sim::restoreObjectStream - Object of class \"%s\" is not a SimObject", className);
      delete simObj;
      return NULL;
   }

   if( simObj->readObject(stream)
       && simObj->registerObject() )
      return simObj;

   delete simObj;
   return NULL;
}
Ejemplo n.º 5
0
SimObject* SimSet::findObjectByLineNumber(const char* fileName, S32 declarationLine, bool searchChildren)
{
   if (!fileName)
      return NULL;

   if (declarationLine < 0)
      return NULL;

   StringTableEntry fileEntry = StringTable->insert(fileName);

   for (iterator i = begin(); i != end(); i++)
   {
      SimObject *childObj = static_cast<SimObject*>(*i);

      if(childObj->getFilename() == fileEntry && childObj->getDeclarationLine() == declarationLine)
         return childObj;
      else if (searchChildren)
      {
         SimSet* childSet = dynamic_cast<SimSet*>(*i);

         if (childSet)
         {
            SimObject* found = childSet->findObjectByLineNumber(fileName, declarationLine, searchChildren);
            if (found)
               return found;
         }
      }
   }

   return NULL;
}
Ejemplo n.º 6
0
   S32 script_simobject_find(const char* classname, const char* name)
   {
      SimObject *object;
      if( Sim::findObject( name, object ) )
      {
         // if we specified a classname do type checking
         if (classname && dStrlen(classname))
         {
            AbstractClassRep* ocr = object->getClassRep();
            while (ocr)
            {
               if (!dStricmp(ocr->getClassName(), classname))
                  return object->getId();
               ocr = ocr->getParentClass();
            }

         }

         // invalid type
         return 0;
      }

      // didn't find object
      return 0;
   }
Ejemplo n.º 7
0
void SimGroup::popObject()
{
   MutexHandle handle;
   handle.lock( mMutex );

   if( objectList.empty() )
   {
      AssertWarn( false, "SimGroup::popObject - Stack underflow" );
      return;
   }

   SimObject* object = objectList.last();
   objectList.pop_back();

   object->onGroupRemove();
   object->mGroup = NULL;

   clearNotify( object );
   mNameDictionary.remove( object );
      
   getSetModificationSignal().trigger( SetObjectAdded, this, object );
   if( object->isProperlyAdded() )
      onObjectRemoved_callback( object );
   
   object->decRefCount();
}
Ejemplo n.º 8
0
void SimGroup::clear()
{
   lock();
   while( size() > 0 )
   {
      SimObject* object = objectList.last();
      object->onGroupRemove();
      
      objectList.pop_back();
      mNameDictionary.remove( object );
      object->mGroup = 0;

      getSetModificationSignal().trigger( SetObjectRemoved, this, object );
      if( object->isProperlyAdded() )
         onObjectRemoved_callback( object );

      if( engineAPI::gUseConsoleInterop )
         object->deleteObject();
      else
         object->decRefCount();      
   }
   unlock();

   getSetModificationSignal().trigger( SetCleared, this, NULL );
}
//-----------------------------------------------------------
// Function name:  SimComponent::handlesConsoleMethod
// Summary:
//-----------------------------------------------------------
bool DynamicConsoleMethodComponent::handlesConsoleMethod( const char *fname, S32 *routingId )
{
   // CodeReview: Host object is now given priority over components for method
   // redirection. [6/23/2007 Pat]

   // On this object?
   if( isMethod( fname ) )
   {
      *routingId = -1; // -1 denotes method on object
      return true;
   }

   // on this objects components?
   S32 nI = 0;
   VectorPtr<SimComponent*> &componentList = lockComponentList();
   for( SimComponentIterator nItr = componentList.begin(); nItr != componentList.end(); nItr++, nI++ )
   {
      SimObject *pComponent = dynamic_cast<SimObject*>(*nItr);
      if( pComponent != NULL && pComponent->isMethod( fname ) )
      {
         *routingId = -2; // -2 denotes method on component
         unlockComponentList();
         return true;
      }
   }
   unlockComponentList();

   return false;
}
Ejemplo n.º 10
0
void advanceToTime(SimTime targetTime)
{
   AssertFatal(targetTime >= getCurrentTime(), 
      "Sim::advanceToTime() - Target time is less than the current time." );

   Mutex::lockMutex(gEventQueueMutex);

   gTargetTime = targetTime;
   while(gEventQueue && gEventQueue->time <= targetTime)
   {
      SimEvent *event = gEventQueue;
      gEventQueue = gEventQueue->nextEvent;
      AssertFatal(event->time >= gCurrentTime,
         "Sim::advanceToTime() - Event time is less than current time.");
      gCurrentTime = event->time;
      SimObject *obj = event->destObject;

      if(!obj->isDeleted())
         event->process(obj);
      delete event;
   }
	gCurrentTime = targetTime;

   Mutex::unlockMutex(gEventQueueMutex);
}
Ejemplo n.º 11
0
 void script_simobject_setfield_bool(U32 objectId, const char* fieldName, bool v)
 {
    SimObject *object = Sim::findObject( objectId );
    if( object )
    {
       object->setDataField(fieldName, "", v ? "1" : "0");
    }
 }
Ejemplo n.º 12
0
 void script_simobject_setfield_string(U32 objectId, const char* fieldName, const char* v)
 {
    SimObject *object = Sim::findObject( objectId );
    if( object )
    {
       object->setDataField(fieldName, "", v);
    }
 }
Ejemplo n.º 13
0
 const char* script_simobject_getfield_string(U32 id, const char* fieldName)
 {
    SimObject *object = Sim::findObject( id );
    if( object )
    {
       return (const char *) object->getDataField(fieldName, "");
    }
    return "";
 }
Ejemplo n.º 14
0
void SimDataBlockEvent::unpack(NetConnection *cptr, BitStream *bstream)
{
   if(bstream->readFlag())
   {
      mProcess = true;
      id = bstream->readInt(DataBlockObjectIdBitSize) + DataBlockObjectIdFirst;
      S32 classId = bstream->readClassId(NetClassTypeDataBlock, cptr->getNetClassGroup());
      mIndex = bstream->readInt(DataBlockObjectIdBitSize);
      mTotal = bstream->readInt(DataBlockObjectIdBitSize + 1);
      
      SimObject* ptr;
      if( Sim::findObject( id, ptr ) )
      {
         // An object with the given ID already exists.  Make sure it has the right class.
         
         AbstractClassRep* classRep = AbstractClassRep::findClassRep( cptr->getNetClassGroup(), NetClassTypeDataBlock, classId );
         if( classRep && dStrcmp( classRep->getClassName(), ptr->getClassName() ) != 0 )
         {
            Con::warnf( "A '%s' datablock with id: %d already existed. "
                        "Clobbering it with new '%s' datablock from server.",
                        ptr->getClassName(), id, classRep->getClassName() );
            ptr->deleteObject();
            ptr = NULL;
         }
      }
      
      if( !ptr )
         ptr = ( SimObject* ) ConsoleObject::create( cptr->getNetClassGroup(), NetClassTypeDataBlock, classId );
         
      mObj = dynamic_cast< SimDataBlock* >( ptr );
      if( mObj != NULL )
      {
         #ifdef DEBUG_SPEW
         Con::printf(" - SimDataBlockEvent: unpacking event of type: %s", mObj->getClassName());
         #endif
         
         mObj->unpackData( bstream );
      }
      else
      {
         #ifdef DEBUG_SPEW
         Con::printf(" - SimDataBlockEvent: INVALID PACKET!  Could not create class with classID: %d", classId);
         #endif
         
         delete ptr;
         cptr->setLastError("Invalid packet in SimDataBlockEvent::unpack()");
      }

#ifdef TORQUE_DEBUG_NET
      U32 checksum = bstream->readInt(32);
      AssertISV( (checksum ^ DebugChecksum) == (U32)classId,
         avar("unpack did not match pack for event of class %s.",
            mObj->getClassName()) );
#endif

   }
}
Ejemplo n.º 15
0
 void script_simobject_setfield_float(U32 objectId, const char* fieldName, F32 v)
 {
    SimObject *object = Sim::findObject( objectId );
    if( object )
    {
       char buf[256];
       dSprintf(buf, 256, "%g", v );
       object->setDataField(fieldName, "", buf);
    }
 }
Ejemplo n.º 16
0
const char *SimDataBlockEvent::getDebugName()
{
   SimObject *obj = Sim::findObject(id);
   static char buffer[256];
   dSprintf(buffer, sizeof(buffer), "%s [%s - %s]",
            getClassName(),
            obj ? obj->getName() : "",
            obj ? obj->getClassName() : "NONE");
   return buffer;
}
Ejemplo n.º 17
0
SimObject* findObject(const char* name)
{
   PROFILE_SCOPE(SimFindObject);

   // Play nice with bad code - JDD
   if( !name )
      return NULL;

   SimObject *obj;
   char c = *name;

   if (c == '%')
   {
      if (gEvalState.getStackDepth())
      {
         Dictionary::Entry* ent = gEvalState.getCurrentFrame().lookup(StringTable->insert(name));

         if (ent)
            return Sim::findObject(ent->getIntValue());
      }
   }
   if(c == '/')
      return gRootGroup->findObject(name + 1 );
   if(c >= '0' && c <= '9')
   {
      // it's an id group
      const char* temp = name + 1;
      for(;;)
      {
         c = *temp++;
         if(!c)
            return findObject(dAtoi(name));
         else if(c == '/')
         {
            obj = findObject(dAtoi(name));
            if(!obj)
               return NULL;
            return obj->findObject(temp);
         }
      }
   }
   S32 len;

   for(len = 0; name[len] != 0 && name[len] != '/'; len++)
      ;
   StringTableEntry stName = StringTable->lookupn(name, len);
   if(!stName)
      return NULL;
   obj = gNameDictionary->find(stName);
   if(!name[len])
      return obj;
   if(!obj)
      return NULL;
   return obj->findObject(name + len + 1);
}
Ejemplo n.º 18
0
void GuiInspectorField::resetData()
{
   if( !mField )
      return;
      
   SimObject* inspectObject = getInspector()->getInspectObject();
   
   SimObject* tempObject = static_cast< SimObject* >( inspectObject->getClassRep()->create() );
   setData( tempObject->getDataField( mField->pFieldname, mFieldArrayIndex ) );
   delete tempObject;
}
Ejemplo n.º 19
0
 void script_simobject_setfield_int(U32 objectId, const char* fieldName, S32 v)
 {
    SimObject *object = Sim::findObject( objectId );
    if( object )
    {
       // this seems pretty lame, though it is how it is handled in consoleType.cpp
       char buf[256];
       dSprintf(buf, 256, "%d", v );
       object->setDataField(fieldName, "", buf);
    }
 }
Ejemplo n.º 20
0
void ProcessList::dumpToConsole()
{
   for (ProcessObject * pobj = mHead.mProcessLink.next; pobj != &mHead; pobj = pobj->mProcessLink.next)
   {
      SimObject * obj = dynamic_cast<SimObject*>(pobj);
      if (obj)
         Con::printf("id %i, order guid %i, type %s", obj->getId(), pobj->mOrderGUID, obj->getClassName());
      else
         Con::printf("---unknown object type, order guid %i", pobj->mOrderGUID);
   }
}
Ejemplo n.º 21
0
void EditManager::editorDisabled()
{
   for(SimGroupIterator itr(Sim::getRootGroup());  *itr; ++itr)
   {
      SimObject *so = *itr;
      AssertFatal(so->isProperlyAdded() && !so->isRemoved(), "bad");
      so->onEditorDisable();
   }

   gEditingMission = false;
}
Ejemplo n.º 22
0
//UNSAFE
void SimSet::deleteAllObjects()
{
   lock();
   while( !empty() )
   {
      SimObject* object = objectList.last();
      objectList.pop_back();

      object->deleteObject();
   }
   unlock();
}
Ejemplo n.º 23
0
char* SimTreeView::handleItemNameChange( HTREEITEM hItem, char *name )
{
	lockManager();
   SimObject *obj = getObject( hItem );
   if ( !obj )
      return NULL;

   obj->assignName( name );
	unlockManager();

   return ( (char*)avar("%4i,\"%s\", %s",obj->getId(),obj->getName(),obj->getClassName()) );
}   
Ejemplo n.º 24
0
SimObject* SimObject::clone() const
{
  SimObject* newObject = new SimObject();
  newObject->copyStandardMembers(this);
  ObjectList::const_iterator pos;
  for(pos = childNodes.begin(); pos != childNodes.end(); ++pos)
  {
    SimObject* childNode = (*pos)->clone();
    newObject->addChildNode(childNode, false);
  }
  return newObject;
}
Ejemplo n.º 25
0
   F32 script_simobject_getfield_float(U32 objectId, const char* fieldName)
   {
      SimObject *object = Sim::findObject( objectId );
      if( object )
      {
         const char *v = object->getDataField(fieldName, "");

         return dAtof(v);
      }

      return false;
   }
Ejemplo n.º 26
0
bool DropPointGroup::onDropPointQuery (DropPointQuery *query)
{
	SimObject *obj = NULL;

	// See if we can find the one they want, check first in
	// our group, then the named group.
	if (query->dropPointName) {
		if ((obj = findObject(query->dropPointName)) == 0) {
			if (SimObject* op = findObject(NamedDropPoints))
				if (SimGroup* gp = dynamic_cast<SimGroup*>(op))
					obj = gp->findObject(query->dropPointName);
		}
	}

	// If we can't find the one they asked for, we'll pick one.
	if (!obj && size()) {

		// Build a list to simplify selection (have to skip
		// over the named group).
		SimObjectList list;
		list.reserve(size());
		for (int i = 0; i < size(); i++) {
			obj = (*this)[i];
			const char* name = obj->getName();
			if (!name || strcmp(name,NamedDropPoints))
				list.push_back(obj);
		}

		if (list.size()) {
			if (random) {
				// Random selection (more or less)
				int seed = (int)manager->getCurrentTime();
				currentIndex = seed%(list.size());
			}
			else {
				// Sequenced selection
				if (++currentIndex >= list.size())
					currentIndex = 0;
			}
			obj = list[currentIndex];
		}
	}

	//
	if (obj) {
		SimObjectTransformQuery transQ;
		if (obj->processQuery (&transQ)) {
			query->tmat = transQ.tmat;
			return true;
		}
	}
	return false;
}
Ejemplo n.º 27
0
//-----------------------------------------------------------------------------
// 
// VSpawnSphereSpawnTargetTrack::despawnTargets();
// 
// Despawn all of the objects spawned by this track.
// 
//-----------------------------------------------------------------------------
void VSpawnSphereSpawnTargetTrack::despawnTargets( void )
{
    while( mSpawnList.size() > 0 )
    {
        // Fetch the Last Object
        SimObject *object = mSpawnList.last();
        // Remove it.
        mSpawnList.popObject();

        // Delete the Object.
        object->deleteObject();
    }
}
void
FighterTacticalAI::SelectTarget()
{
	TacticalAI::SelectTarget();

	SimObject* target = ship_ai->GetTarget();

	if (target && (target->Type() == SimObject::SIM_SHIP) &&
			(Game::GameTime() - secondary_selection_time) > THREAT_REACTION_TIME) {
		SelectSecondaryForTarget((Ship*) target);
		secondary_selection_time = Game::GameTime();
	}
}
Ejemplo n.º 29
0
bool
TacticalAI::CheckObjectives()
{
    bool     processed = false;
    Ship*    ward      = 0;
    Element* elem      = ship->GetElement();

    if (elem) {
        Instruction* obj = elem->GetTargetObjective();

        if (obj) {
            ship_ai->ClearPatrol();

            if (obj->Action()) {
                switch (obj->Action()) {
                case Instruction::INTERCEPT:
                case Instruction::STRIKE:
                case Instruction::ASSAULT:
                    {
                        SimObject* tgt = obj->GetTarget();
                        if (tgt && tgt->Type() == SimObject::SIM_SHIP) {
                            roe = DIRECTED;
                            SelectTargetDirected((Ship*) tgt);
                        }
                    }
                    break;

                case Instruction::DEFEND:
                case Instruction::ESCORT:
                    {
                        SimObject* tgt = obj->GetTarget();
                        if (tgt && tgt->Type() == SimObject::SIM_SHIP) {
                            roe = DEFENSIVE;
                            ward = (Ship*) tgt;
                        }
                    }
                    break;

                default:
                    break;
                }
            }

            orders    = obj;
            processed = true;
        }
    }

    ship_ai->SetWard(ward);
    return processed;
}
Ejemplo n.º 30
0
/**
 * Called during the shutdown phase.
 */
bool PhysicsManager::cleanUp() {

	ValueManager *vm = Core::getInstance()->getValueManager();

	//remove all parameter values from the valuemanager.
	for(QListIterator<SimObject*> i(mSimObjects); i.hasNext();) {
		SimObject *obj = i.next();
		obj->clear();

		//TODO speed up! Iterate over hashtable instead of name and getParameter.
		vm->removeValues(obj->getParameters());
		
	}
	return true;
}