Example #1
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 );
}
 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 );
    }
 }
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

   }
}
Example #4
0
//UNSAFE
void SimSet::deleteAllObjects()
{
   lock();
   while( !empty() )
   {
      SimObject* object = objectList.last();
      objectList.pop_back();

      object->deleteObject();
   }
   unlock();
}
//-----------------------------------------------------------------------------
// 
// 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();
    }
}
Example #6
0
SimGroup* SimGroup::clone()
{
   // Skip SimSet::clone since we do not want to steal the child objects
   // from this group.
   
   SimObject* object = SimObject::clone();
   SimGroup* group = dynamic_cast< SimGroup* >( object );
   if( !group )
   {
      object->deleteObject();
      return NULL;
   }
   
   return group;
}
Example #7
0
SimGroup* SimGroup::deepClone()
{
   // Clone the group object.
   
   SimObject* object = Parent::deepClone();
   SimGroup* group = dynamic_cast< SimGroup* >( object );
   if( !group )
   {
      object->deleteObject();
      return NULL;
   }
   
   // Clone all child objects.
   
   for( iterator iter = begin(); iter != end(); ++ iter )
      group->addObject( ( *iter )->deepClone() );
   
   return group;
}
Example #8
0
SimSet* SimSet::clone()
{
   // Clone the set object.
   
   SimObject* object = Parent::clone();
   SimSet* set = dynamic_cast< SimSet* >( object );
   if( !set )
   {
      object->deleteObject();
      return NULL;
   }
   
   // Add all object in the set.
   
   for( iterator iter = begin(); iter != end(); ++ iter )
      set->addObject( *iter );
   
   return set;
}
void SimTreeView::onCommand( int id, HWND hwndCtl, UINT codeNotify )
{
   hwndCtl, codeNotify;
   SimObject   *obj;
   SimSet    *prnt;
	lockManager();

   switch( id )
   {
      case IDM_EXIT:
         destroyWindow();
         break;

      case IDM_CUT:
         if ( (obj = getSelectedObject()) !=  NULL )
         {
            // persist selected object
            obj->fileStore( "temp\\clip.tmp" );

            // remove it from parent
            obj->deleteObject();
            delItem( getSelection() );
            state.set(STV_MODIFIED);
         }
         break;

      case IDM_COPY:
         if ( (obj = getSelectedObject()) !=  NULL )
            obj->fileStore( "temp\\clip.tmp" );
         break;

      case IDM_PASTE:
         {
            // unpersist object to get a duplicate
            Persistent::Base::Error err;
            obj = (SimObject*)Persistent::Base::fileLoad( "temp\\clip.tmp", &err );
            if ( err != Ok )
               return;

            // add to simTree
            HTREEITEM hParent = getSelection();
            if ( !isItemFolder(hParent) )
               hParent = getParent( hParent );

            prnt = (SimSet*)getObject( hParent );
            prnt->getManager()->addObject( obj );
				prnt->addObject(obj);
            HTREEITEM hItem = addSet( obj, hParent );
            selectItem( hItem );
            state.set(STV_MODIFIED);
         }
         break;

      case IDM_DELETE:
         obj = getSelectedObject();
         if ( obj )
         {
            obj->deleteObject();
            delItem( getSelection() );
            state.set(STV_MODIFIED);
         }
         break;

      case IDM_REMOVE:
         obj = getSelectedObject();
         if ( obj )
         {
            prnt = getSelectedParent();
				prnt->removeObject(obj);
            delItem( getSelection() );
            state.set(STV_MODIFIED);
         }
         break;

      case IDM_DUPLICATE:
         {
            obj = getSelectedObject();
            
            // persist object to get a duplicate
            if ( obj->fileStore( "temp\\clip.tmp" ) != Ok )
            {
					unlockManager();
               return;
            }

            Persistent::Base::Error err;
            obj = (SimObject*)Persistent::Base::fileLoad( "temp\\clip.tmp", &err );
            if ( err != Ok )
            {
					unlockManager();
               return;
            }
            // perhaps delete clip.tmp to clean up directory

            HTREEITEM hParent = getSelection();
            if ( !isItemFolder(hParent) )
               hParent = getParent( hParent );

            prnt = (SimSet*)getObject( hParent );
            prnt->getManager()->addObject( obj );
            prnt->addObject( obj );
            HTREEITEM hItem = addSet( obj, getParent(getSelection()) );
            selectItem( hItem );
            state.set(STV_MODIFIED);
         }
         break;

      case IDM_EDIT:
         inspectObject( getSelectedObject() );
         state.set(STV_MODIFIED);
         break;

      case IDM_LOCK:
         lockObject( getSelectedObject(), true );
         state.set( STV_MODIFIED );
         break;
         
      case IDM_UNLOCK:
         lockObject( getSelectedObject(), false );
         state.set( STV_MODIFIED );
         break;
         
      default:
         if ( (id>=IDM_SCRIPT_START) && (id<=scriptMenu_IDM) )
         {
            int scriptIndex = id-IDM_SCRIPT_START;
            CMDConsole::getLocked()->evaluate( script[scriptIndex], false );
         }
         // let parent handle its default menu items
         WinParent::handleContextMenuItemSelection( id );
   }
   checkMenu( hMainMenu );
	unlockManager();
}
const char * FearMissionPlugin::consoleCallback( CMDConsole *, int id, int argc, const char * argv[] )
{
   SimManager * clientManager = SimGame::get()->getManager( SimGame::CLIENT );
   SimManager * serverManager = SimGame::get()->getManager( SimGame::SERVER );
   
   FearMissionEditor * me = NULL;
   
   // get the missioneditor
   if( SimObject * obj = clientManager->findObject( "MissionEditor" ) )
      me = dynamic_cast<FearMissionEditor *>( obj );
   
   // check for the editor object
   if(id != Create)
   {
      if(!me)
      {
         console->printf( "%s: Must call ME::Create first", argv[0] );
         return(ME_Failure);
      }
   }
   
   // look at the command
   switch( id )
   {
      case Create:
      {
         if( argc > 1 )
         {
            // check for the missioneditor
            if(me)
               me->deleteObject();
            
            // grab the canvas
            SimGui::Canvas * sc = dynamic_cast< SimGui::Canvas * >( manager->findObject( argv[1] ) );
            if(!sc)
            {
               console->printf( "%s: can't find parent canvas [%s]", argv[0], argv[1] );
               break;
            }
         
            me = new FearMissionEditor();
            clientManager->addObject(me, "MissionEditor");
            clientManager->assignId(me, SimMissionEditorId);
            
            // set the manager and canvas for the missioneditor
            me->setManager(serverManager);
            me->setCanvas(sc);

            // need to get rid of the missioneditor on deletion of server, so
            // add it to an object that is always in the server...
            SimObject * notifyObj = serverManager->findObject("ConsoleScheduler");
            if(notifyObj)
               me->deleteNotify(notifyObj);
            
            // init the missionEditor
            if(!me->init())
               console->printf( "%s: failed to initialize MissionEditor", argv[0] );
               
            return(ME_Success);
         }
         else
            console->printf( "%s: simCanvasName", argv[0] );
            
         break;
      }
      
      case RegisterType:
      {
         if( argc >= 3 )
         {
            // check for bitmap names
            if( !me->addTypeInfo( argv[1], atoi(argv[2]),
               ( argc > 3 ) ? argv[3] : NULL,
               ( argc > 4 ) ? argv[4] : NULL ) )
               console->printf( "%s: failed to add type [%s]", argv[0], argv[1] );
            else
               return(ME_Success);
         }
         else
            console->printf( "%s: ClassDescription, BitPos, <BmpSelected>, <BmpUnselected>", argv[0] );

         break;
      }
      
      case SetGrabMask:
      {
         if( argc == 2 )
         {
            me->setGrabMask( atoi( argv[1] ) );   
            return(ME_Success);
         }
         else
            console->printf( "%s: grab mask", argv[0] );
            
         break;
      }
      
      case SetPlaceMask:
      {
         if( argc >= 2 )
         {
            if( argc == 2 )
            {
               me->removeTypeInfo( argv[1] );
               return(ME_Success);
            }
            else
            {
               FearMissionEditor::TypeInfo * dest = me->getTypeInfo( argv[1] );
               if( !dest )
               {
                  console->printf( "%s: improper type [%s]", argv[0], argv[1] );
                  break;
               }
               dest->mPlaceMask = atoi( argv[2] );
               return(ME_Success);
            }
         }
         else
            console->printf( "%s: ObjectType <mask>", argv[0] );
            
         break;
      }
      
      case SetDefaultPlaceMask:
      {
         if( argc == 2 )
         {
            me->setDefPlaceMask( atoi( argv[1] ) );   
            return(ME_Success);
         }
         else
            console->printf( "%s: placement mask", argv[0] );
            
         break;
      }
      
      case GetConsoleOptions:
      {
         me->getConsoleOptions();
         return(ME_Success);
      }

      case ObjectToCamera:
      case CameraToObject:
      case ObjectToSC:
      {
         int objId = atoi( console->getVariable( "ME::InspectObject" ) );
         SimObject * obj = me->getObject( static_cast< UINT >( objId ) );

         if( !obj )
         {
            console->printf( "%s: failed to get inspect object", argv[0] );
            break;         
         }

         switch( id )
         {
            case ObjectToCamera:
            {
               if( obj->isLocked() )
               {
                  console->printf("%s: object is locked", argv[0]);
                  break;
               }
                  
               TMat3F objMat;
               me->saveInfo( obj );
               me->getTransform( obj, objMat );
               objMat.p.set( 0.f, 0.f, 0.f );
               me->setTransform( obj, objMat );
               me->onDrop( obj, FearMissionEditor::DropAtCamera );
               break;
            }
            case CameraToObject:
            {
               SimObject * cam = me->getCamera();
               if( !cam )
               {
                  console->printf( "%s: failed to get camera", argv[0] );
                  break;
               }
               
               TMat3F camMat;
               TMat3F objMat;
               
               me->getTransform( obj, objMat );
               me->getTransform( cam, camMat );
               me->saveInfo( cam );
               
               // move her
               camMat.p = objMat.p;
               camMat.flags |= TMat3F::Matrix_HasTranslation;
               if( !me->setTransform( cam, camMat ) )
               {
                  console->printf( "%s: failed to move camera", argv[0] );
                  break;
               }
               
               return(ME_Success);
            }
            case ObjectToSC:
            {
               if( obj->isLocked() )
               {
                  console->printf("%s: object is locked", argv[0]);
                  break;
               }

               TMat3F objMat;
               me->saveInfo( obj );
               me->getTransform( obj, objMat );
               objMat.p.set( 0.f, 0.f, 0.f );
               me->setTransform( obj, objMat );
               me->onDrop( obj, FearMissionEditor::DropToScreenCenter );
               return(ME_Success);
            }
         }
         
         break;
      }
 
      case CreateObject:
      {
         serverManager->lock();
            
         if ( argc >= 3 )
         {
            // find a name to use
            char strname[255];
            int count = 1;
            do 
            {
               sprintf(strname, "%s%d", argv[1], count);
               count++;
            }
            while( serverManager->findObject( strname ) );
            
            // must have mission editor for this command
            if( me )
            {
   				Persistent::Base * obj = reinterpret_cast< Persistent::Base* >
	   				( Persistent::create( argv[2] ) );
               SimObject *simObj;
               if( obj )
               {
                  simObj = dynamic_cast<SimObject *>( obj );
                  if(simObj)
                  {
                     if(!serverManager->addObject( simObj ))
                     {
                        console->printf("MissionCreateObject: failed on addObject");
                        break;
                     }
                     
                     serverManager->assignName( simObj, strname );
                     
                     if( !simObj->processArguments( argc - 3, argv + 3 ) )
                     {
                        simObj->deleteObject();
                        console->printf("MissionCreateObject: failed argument list");
                     }
                     else
                     {
                        // add to the mission editor
                        if( !me->addObject( simObj ) )
                           simObj->deleteObject();

                        // grab the centroid for 'DropToSelectedObj'
                        me->mSelection.calcCentroid();
                                                      
                        // make this the only selection
                        console->evaluatef( "MissionObjectList::ClearSelection();" );
                        console->evaluatef( "MissionObjectList::SelectObject( %d, %d );", 
                           me->getWorldId( simObj ), simObj->getId() );

                        // move the item where we want it...
                        me->onDrop( simObj, me->mDropType );

                        // re-select to get inspect...   
                        console->evaluatef( "MissionObjectList::Inspect( %d, %d );", 
                           me->getWorldId( simObj ), simObj->getId() );
                        
                        // check if should drop to ground
                        if( me->mFlags.test( FearMissionEditor::DropToGround ) )
                           me->dropObjectDown( simObj );

                        serverManager->unlock();
                        return(avar("%d", simObj->getId()));
                     }
                  }
               }
               else
                  console->printf(avar("MissionCreateObject: Unable to instantiate object of class type: %s",argv[2]));
            }
            else
               console->printf("MissionCreateObject:  Must call MissionCreate first");
         }
         else
            console->printf("MissionCreateObject objtypename className arglist");

         serverManager->unlock();
         return("0");
      }
      
      case onSelected:
      {
         // ignores worldid...
         if( argc == 3 )
         {
            me->mSelection.addObject( me->getObject( atoi( argv[2] ) ) );
            return(ME_Success);
         }
         else
            console->printf( "%s: WorldId, ObjId", argv[0] );
            
         break;
      }

      case onUnselected:
      {
         // ignores worldid...
         if( argc == 3 )
         {
            me->mSelection.removeObject( me->getObject( atoi( argv[2] ) ) );
            return(ME_Success);
         }
         else
            console->printf( "%s: WorldId, ObjId", argv[0] );
            
         break;
      }
      
      case onSelectionCleared:
      {
         me->mSelection.clearSet();
         return(ME_Success);
      }
      
      case onUseTerrainGrid:
      {
         if( me->getManager() )
         {
            SimObject * obj = me->getManager()->findObject( SimTerrainId );
            if( obj )
            {
               SimTerrain * stObj = dynamic_cast< SimTerrain * >( obj );
               if( stObj )
               {
                  float granularity = 1 << stObj->getGridFile()->getScale();
                  console->setVariable( "ME::XGridSnap", avar( "%5.3f", granularity ) );
                  console->setVariable( "ME::YGridSnap", avar( "%5.3f", granularity ) );
                  return(ME_Success);
               }
            }
            console->printf( "%s: failed to get SimTerrain object", argv[0] );
         }
         else
            console->printf( "%s: failed to get manager", argv[0] );
            
         break;
      }

      case DeleteSelection:
      {
         me->deleteSelection();
         return(ME_Success);
      }
         
      case CopySelection:
      {
         me->copySelection();
         return(ME_Success);
      }
      
      case PasteFile:
      {
         if(argc != 2)
            break;
            
         me->pasteFile(argv[1]);
         return(ME_Success);
      }
         
      case CutSelection:
      {
         me->copySelection();
         me->deleteSelection();
         return(ME_Success);
      }
         
      case PasteSelection:
      {
         me->pasteSelection();
         return(ME_Success);
      }
         
      case DuplicateSelection:
      {
         me->copySelection();
         me->pasteSelection();
         return(ME_Success);
      }

      case DropSelection:
      {  
         me->dropSelection();
         return(ME_Success);
      }      
      case CreateGroup:
      {
         SimGroup * sg = new SimGroup;
         serverManager->addObject( sg );
         serverManager->assignName( sg, "SimGroup" );
         if( !me->addObject( sg ) )
            delete sg;
         else
            return(ME_Success);
            
         break;
      }

      case PlaceBookmark:
      {
         if( argc == 2 )
         {
            int num = atoi( argv[1] );
            if( num >= 0 && num <= 9 )
            {
               me->placeBookmark( num );
               return(ME_Success);
            }
         }
         console->printf( "%s: Invalid bookmark [%d] use [0-9]", argv[0], atoi( argv[1] ) );
         break;
      }
      
      case GotoBookmark:
      {
         if( argc == 2 )
         {
            int num = atoi( argv[1] );
            if( num >= 0 && num <= 9 )
            {
               me->gotoBookmark( num );
               return(ME_Success);
            }
         }

         console->printf( "%s: Invalid bookmark [%d] use [0-9]", argv[0], atoi( argv[1] ) );
         
         break;
      }

      case Undo:
      {
         me->restoreInfo();
         return(ME_Success);
      }
         
      case Redo:
         break;
         
      case Save:
      {
         char * missionName = const_cast<char*>(console->getVariable( "$missionFile" ));
         if( missionName && strlen( missionName ) )
         {
            // remove any base\\...
            char * baseName = strrchr(missionName, '\\');
            baseName ? baseName++ : baseName = missionName;

            // get the full path of the mission file            
            ResourceManager * rm = SimResource::get(serverManager);
            char fileBuf[MAX_FILE];
            rm->getFullPath(baseName, fileBuf);

            // check the files
            if(!isWriteable(console->getVariable("$Ted::currFile")) ||
               !isWriteable(fileBuf))
            {
               console->printf("Failed to save mission - terrain and mission files need write access");
               break;
            }
               
            // save ted
            console->evaluate( "Ted::save($Ted::currFile);", false );
            if(!console->getBoolVariable("$TED::success"))
               break;
               
            // save med
            SimObject * obj = serverManager->findObject( "MissionGroup" );
            if( obj )
            {
               console->executef( 3, "saveMission", avar( "%d", obj->getId() ), fileBuf );
               return(ME_Success);
            }
            else
               console->printf( "%s: failed to save mission '%s'", argv[0], missionName );
         }
         else
            console->printf( "%s: missionName not found", argv[0] );
       
         break;
      }
      
      case MissionLight:
      {
         bool quick = false;
         if(argc == 2)
            quick = boolify(argv[1]);
            
         // save the mission
         if(stricmp(console->evaluate("ME::Save();", false), "true"))
            break;
            
         // make sure non-fullscreen
         console->evaluate("setFullscreenMode(mainWindow, false);", false);

         // get the mission name, remove the base\\...
         char * missionName = const_cast<char*>(console->getVariable("$missionFile"));
         char * baseName = strrchr(missionName, '\\');
         baseName ? baseName++ : baseName = missionName;

         ResourceManager * rm = SimResource::get(serverManager);
         char fileBuf[MAX_FILE];
         rm->getFullPath(baseName, fileBuf);
         
         AssertISV(ResourceManager::sm_pManager == NULL ||
            ResourceManager::sm_pManager->isValidWriteFileName(fileBuf) == true,
            avar("Attempted write to file: %s.\n"
                  "File is not in a writable directory.", fileBuf));
         
         // spawn missionlighting on mission
         char * argv[4];
         argv[0] = "missionlighting.exe";
         argv[1] = fileBuf;
         argv[2] = quick ? "-q" : 0;
         argv[3] = 0;
         spawnvp(P_WAIT, "missionlighting.exe", argv);
         
         console->evaluate("ME::ReloadMission();, 3);", false);
         break;
  
      }
      
      case RebuildCommandMap:
      {
         if(argc != 1)
            break;
            
         me->rebuildCommandMap();
         return(ME_Success);
      }
   }
   
   return("false");
}