Ejemplo n.º 1
0
bool Arbiter::setSlotBehaviors(Basic::PairStream* const x)
{
   bool ok = true;

   // First, make sure they are all behaviors
   {
      Basic::List::Item* item = x->getFirstItem();
      while (item != nullptr && ok) {
         Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue());
         item = item->getNext();
         Behavior* b = dynamic_cast<Behavior*>( pair->object() );
         if (b == nullptr) {
            // Item is NOT a behavior
            std::cerr << "setSlotBehaviors: slot: " << *pair->slot() << " is NOT of a Behavior type!" << std::endl;
            ok = false;
         }
      }
   }

   // next, add behaviors to our list
   if (ok) {
      Basic::List::Item* item = x->getFirstItem();
      while (item != nullptr) {
         Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue());
         item = item->getNext();
         Behavior* b = static_cast<Behavior*>(pair->object());
         addBehavior(b);
      }
   }

   return ok;
}
Ejemplo n.º 2
0
//------------------------------------------------------------------------------
// processBackgroundTasks() -- Process the background models and interfaces
//------------------------------------------------------------------------------
void Station::processBackgroundTasks(const LCreal dt)
{
   // Note: interoperability networks are handled by
   // processNetworkInputTasks() and processNetworkOutputTasks()

   // The I/O handers
   if (ioHandlers != 0) {
      Basic::List::Item* item = ioHandlers ->getFirstItem();
      while (item != 0) {
         Basic::Pair* pair = (Basic::Pair*)(item->getValue());
         Basic::IoHandler* p = (Basic::IoHandler*)( pair->object() );
         p->updateData(dt);
         item = item->getNext();
      }
   }

   // Our simulation model
   if (sim != 0) sim->updateData(dt);

   // The OTW interfaces
   if (otw != 0) {
      Basic::List::Item* item = otw ->getFirstItem();
      while (item != 0) {
         Basic::Pair* pair = (Basic::Pair*)(item->getValue());
         Otw* p = (Otw*)( pair->object() );
         p->updateData(dt);
         item = item->getNext();
      }
   }
}
Ejemplo n.º 3
0
//------------------------------------------------------------------------------
// setSlotNetworks() -- Set our list of networks
//------------------------------------------------------------------------------
bool Station::setSlotNetworks(Basic::PairStream* const a)
{
    bool ok = true;

    // Remove the old networks list
    if (networks != 0) {
        // we are no longer the container for these networks
        for (Basic::List::Item* item = networks->getFirstItem(); item != 0; item = item->getNext()) {
            Basic::Pair* pair = (Basic::Pair*)(item->getValue());
            NetIO* p = (NetIO*)( pair->object() );
            p->container(0);
        }
    }

    // Set our network list pointer
    networks = a;

    // Make sure the new network list is setup correctly
    if (networks != 0) {
        for (Basic::List::Item* item = networks->getFirstItem(); item != 0; item = item->getNext()) {
            Basic::Pair* pair = (Basic::Pair*)(item->getValue());
            NetIO* p = dynamic_cast<NetIO*>( pair->object() );
            if (p != 0) {
                // We are this network's container
                p->container(this);
            }
            else {
                // Not of the proper type
                std::cerr << "Player::setSlotNetworks: network at slot \"" << pair->slot() << "\" is not of class type NetIO" << std::endl;
                ok = false;
            }
        }
    }
    return ok;
}
Ejemplo n.º 4
0
//------------------------------------------------------------------------------
// shutdownNotification() -- We're shutting down
//------------------------------------------------------------------------------
bool Station::shutdownNotification()
{
   // Tell the interoperability networks that we're shutting down
   if (networks != 0) {
      Basic::List::Item* item = networks->getFirstItem();
      while (item != 0) {
         Basic::Pair* pair = (Basic::Pair*)(item->getValue());
         Basic::Component* p = dynamic_cast<Basic::Component*>(pair->object());
         p->event(SHUTDOWN_EVENT);
         item = item->getNext();
      }
   }
   setSlotNetworks(0);

   // Tell the I/O devices that we're shutting down
   if (ioHandlers != 0) {
      Basic::List::Item* item = ioHandlers->getFirstItem();
      while (item != 0) {
         Basic::Pair* pair = (Basic::Pair*)(item->getValue());
         Basic::Component* p = dynamic_cast<Basic::Component*>(pair->object());
         p->event(SHUTDOWN_EVENT);
         item = item->getNext();
      }
   }
   setSlotIoHandler((Basic::PairStream*)0);

   // Tell our simulation to shut down
   Simulation* s = getSimulation();
   if (s != 0) {
      s->event(SHUTDOWN_EVENT);
   }
   setOwnshipPlayer(0);

   // Inform our OTW interfaces
   if (otw != 0) {
      Basic::List::Item* item = otw ->getFirstItem();
      while (item != 0) {
         Basic::Pair* pair = (Basic::Pair*)(item->getValue());
         Basic::Component* p = dynamic_cast<Basic::Component*>(pair->object());
         p->event(SHUTDOWN_EVENT);
         item = item->getNext();
      }
   }
   setSlotOutTheWindow((Basic::PairStream*)0);

   // Zero (unref) our thread objects (of any).  The thread's functions have ref()'d
   // these objects, so they won't be deleted until the threads terminate, which they
   // will based on our BaseClass::isShutdown() function.  But at least we won't
   // mistakenly think that they're still around.
   tcThread = 0;
   netThread = 0;
   bgThread = 0;

   // remove the reset timer
   setSlotStartupResetTime(0);

   return BaseClass::shutdownNotification();
}
Ejemplo n.º 5
0
//------------------------------------------------------------------------------
// addSymbol() - adds a symbol to our array list;
// -- return the symbol's index; range [ 1 .. getMaxSymbols() ]
//    or zero if not added.
//------------------------------------------------------------------------------
int SymbolLoader::addSymbol(const int nType, const char* const id, int specName)
{
    int idx = 0;

    if (templates != 0) {

        // Find the graphic template for this type symbol, and make
        // sure that the template is a BasicGL::Graphic, since it
        // will be use as the symbol's graphical component.
        Basic::Pair* tpair = templates->getPosition(nType);
        if (tpair != 0) {
            BasicGL::Graphic* tg = dynamic_cast<BasicGL::Graphic*>(tpair->object());
            if (tg != 0) {

                // Find an empty symbol slot in our master symbol table
                for (int i = 0; i < MAX_SYMBOLS && idx == 0; i++) {
                    if ( symbols[i] == 0 ) {

                        // Create a new SlSymbol object to manage this symbol.
                        symbols[i] = symbolFactory();

                        // Clone the graphic template and set it as the
                        // symbol's graphical component.
                        Basic::Pair* newPair = tpair->clone();
                        BasicGL::Graphic* newGraph = (BasicGL::Graphic*)(newPair->object());

                        // Set the new graphical component's select name
                        GLuint mySelName = 0;
                        if (specName > 0) mySelName = specName;
                        else mySelName = BasicGL::Graphic::getNewSelectName();
                        newGraph->setSelectName(mySelName);

                        // Add the symbol's graphical component to our component list.
                        {
                            Basic::PairStream* comp = getComponents();
                            Basic::Component::processComponents(comp, typeid(BasicGL::Graphic), newPair);
                            if (comp != 0) comp->unref();
                        }

                        // Set the symbol's graphical component pointer
                        symbols[i]->setSymbolPair( newPair );
                        newPair->unref(); // symbol[i] now owns it.

                        // Set the symbol's type and ID.
                        symbols[i]->setType( nType );
                        symbols[i]->setId( id );

                        // And this is the new symbol's index
                        idx = (i + 1);
                    }
                }
            }
        }
    }

    return idx;
}
Ejemplo n.º 6
0
//------------------------------------------------------------------------------
// reset() -- Reset the station 
//------------------------------------------------------------------------------
void Station::reset()
{
   if (isMessageEnabled(MSG_INFO)) {
      std::cout << "Station::reset()" << std::endl;
   }

   // Reset our major subsystems
   if (sim != 0) sim->event(RESET_EVENT);

   // ---
   // Reset the ownship pointer
   // ---
   if (ownshipName != 0) {
      setOwnshipByName( *ownshipName );
      if (ownship == 0) {
         // Ok, we had a list of players and an ownship player name, but still
         // don't have an ownship pointer -- print an error message.
         std::cerr << "Station::reset(): ownship not found: " << *ownshipName << std::endl;
      }
   }

   // Reset the I/O Handlers
   if (ioHandlers != 0) {
      Basic::List::Item* item = ioHandlers ->getFirstItem();
      while (item != 0) {
         Basic::Pair* pair = (Basic::Pair*)(item->getValue());
         Basic::IoHandler* p = (Basic::IoHandler*)( pair->object() );
         p->event(RESET_EVENT);
         item = item->getNext();
      }
   }

   // Reset the OTW subsystems
   if (otw != 0) {
      Basic::List::Item* item = otw ->getFirstItem();
      while (item != 0) {
         Basic::Pair* pair = (Basic::Pair*)(item->getValue());
         Otw* p = (Otw*)( pair->object() );
         p->event(RESET_EVENT);
         item = item->getNext();
      }
   }

   // Reset the networks
   if (networks != 0) {
      Basic::List::Item* item = networks ->getFirstItem();
      while (item != 0) {
         Basic::Pair* pair = (Basic::Pair*)(item->getValue());
         NetIO* p = (NetIO*)( pair->object() );
         p->event(RESET_EVENT);
         item = item->getNext();
      }
   }

   BaseClass::reset();
}
Ejemplo n.º 7
0
//------------------------------------------------------------------------------
// setSymbolType() - change an existing symbol type to another type
//------------------------------------------------------------------------------
bool SymbolLoader::setSymbolType(const int idx, const int nType)
{
    bool ok = false;

    // Find the symbol
    if (idx >= 1 && idx <= MAX_SYMBOLS) {
        const int i = (idx - 1);
        if (symbols[i] != 0) {

            // Find the graphic template for this type symbol, and make
            // sure that the template is a BasicGL::Graphic, since it
            // will be use as the symbol's graphical component.
            if (templates != 0) {
                Basic::Pair* tpair = templates->getPosition(nType);
                if (tpair != 0) {
                    BasicGL::Graphic* tg = dynamic_cast<BasicGL::Graphic*>(tpair->object());
                    if (tg != 0) {

                        // Get the symbol's old graphical component
                        Basic::Pair* oldPair = (Basic::Pair*) symbols[i]->getSymbolPair();
                        BasicGL::Graphic* oldG = (BasicGL::Graphic*) (oldPair->object());

                        // Clone the new graphical component from the template
                        Basic::Pair* newPair = tpair->clone();

                        // Set the new graphical component's select name using the old's
                        BasicGL::Graphic* newGraph = (BasicGL::Graphic*) newPair->object();
                        GLuint mySelName = oldG->getSelectName();
                        newGraph->setSelectName(mySelName);

                        // Add the new and remove the old components from our subcomponent list
                        {
                            Basic::PairStream* comp = getComponents();
                            Basic::Component::processComponents(comp, typeid(BasicGL::Graphic), newPair, oldG);
                            if (comp != 0) comp->unref();
                        }

                        // Set the symbol's graphical component pointer
                        symbols[i]->setSymbolPair( newPair );
                        newPair->unref(); // symbol[i] now owns it.

                        // Set new type
                        symbols[i]->setType( nType );

                        ok = true;
                    }

                }
            }
        }

    }
    return ok;
}
Ejemplo n.º 8
0
//------------------------------------------------------------------------------
// processSubpages() -- process our subpages; make sure they are all of
//	type Page (or derived from it)and tell them that we are their
//	container.
//------------------------------------------------------------------------------
bool Page::processSubpages()
{
    bool ok = true;
    if (subpages != 0) {
        // Make sure we have only Pages and tell all of the pages
        // that we are their container.
        const Basic::List::Item* item = subpages->getFirstItem();
        while (ok && item != 0) {
            Basic::Pair* p = (Basic::Pair*) item->getValue();
            item = item->getNext();
            Page* g = dynamic_cast<Page*>(p->object());
            if (g != 0) {
                // It MUST be of type Page
                g->container(this);
            }
            else {
                // Delete components that are not of Page type
                if (isMessageEnabled(MSG_ERROR)) {
                    std::cerr << "Page::processSubpages(): " << *p->slot() << " is not a Page!" << std::endl;
                }
                ok = false;
            }
        }
    }
    return ok;
}
Ejemplo n.º 9
0
//------------------------------------------------------------------------------
// determineColors() - take our value, and look for a corresponding color
// and breakpoint
//------------------------------------------------------------------------------
bool ColorRotary::determineColor(const LCreal value)
{
    bool ok = false;
    int breakPoint = 0;

    // find out where we are in the break table
    unsigned int i = 0;
    // do an endpoint check while we are at it
    if (value >= myValues[numVals-1]) breakPoint = numVals;
    while (!ok && i < numVals) {
        if (value >= myValues[i] && value < myValues[i+1]){
            breakPoint = (i + 1);
            ok = true;
        }
        else i++;
    }

    // now set the proper color (using the breakpoint index)
    if (myColors != nullptr) {
        Basic::Pair* pair = myColors->getPosition(breakPoint);
        if (pair != nullptr) {
            Basic::Color* listcolor = dynamic_cast<Basic::Color*>(pair->object());
            if (listcolor != nullptr) {
               const osg::Vec4* vec = static_cast<const osg::Vec4*>(listcolor->getRGBA());
               color = *vec;
               ok = true;
            }
        }
    }
    return ok;
}
Ejemplo n.º 10
0
//------------------------------------------------------------------------------
// setOwnshipByName() -- set our ownship by name
//------------------------------------------------------------------------------
bool Station::setOwnshipByName(const char* const newOS)
{
   bool set = false;
   Basic::PairStream* pl = 0;
   if (sim != 0) pl = sim->getPlayers();

   // Look for this ownship in our list of players
   if (newOS != 0 && pl != 0) {
      Basic::Pair* p = pl->findByName(newOS);
      if (p != 0) {
         Player* newOwnship = (Player*) p->object();
         if (newOwnship != ownship) {
            // Ok, we found the new ownship and it IS a different 
            // player then the previous ownship ...
            setOwnshipPlayer( newOwnship );
            set = true;
         }
      }

      // Cleanup
      pl->unref();
      pl = 0;
   }

   return set;
}
Ejemplo n.º 11
0
//------------------------------------------------------------------------------
// mapPlayers2ElevTable() - Map the player list to the model table
//------------------------------------------------------------------------------
void Otw::mapPlayers2ElevTable()
{
   // Set all entries as unciecked
   for (unsigned int i = 0; i < getElevationTableSize(); i++) {
      hotTbl[i]->setCheckedFlag(false);
   }

   // When we have a player list ...
   if (playerList != 0) {

      // ---
      // Find players that are alive and require terrain elevation from the visual system ...
      // ---
      Basic::List::Item* item = playerList->getFirstItem();
      while (item != 0) {

         // Get a pointer to the player, 'p'
         Basic::Pair* pair = dynamic_cast<Basic::Pair*>(item->getValue());
         Player* p = (Player*) pair->object();

         // Check if this player is alive and within range.
         if ( p->isActive() && p->isTerrainElevationRequired() ) {

            // Check if in-range
            bool inRange = computeRangeToPlayer(p) <= maxRange;
            
            if (inRange) {
            
               // Find the player's model entry (if any)
               OtwModel* model = findModel(p, HOT_TABLE);

               if (model != 0) {
                  // The player has a valid entry.
                  model->incReqCount();
               }
               else {
                  // Player doesn't have an entry, so create one.
                  model = newElevEntry(p);
               }
               if (model != 0) model->setCheckedFlag(true);
            }

         }

         //completed  = p->isNetworkedPlayer();
         item = item->getNext(); // Next player
      }
   }

   // ---
   // Remove unmatched model entries; their players are inactive or no longer
   // require terrain elevation
   // ---
   for (int i = getElevationTableSize(); i > 0; --i) {
      if ( hotTbl[i-1]->isNotChecked() ) {
         // Deleting this entry
         removeModelFromList( (i-1), HOT_TABLE);
      }
   }
}
Ejemplo n.º 12
0
// Get the next free missile of type 'missileType'
Missile* SimpleStoresMgr::getSpecificMissile(const Basic::String* const missileType)
{
   Missile* msl = 0;
   if (missileType != 0) {

      Basic::PairStream* list = getWeapons();
      if (list != 0) {

         // Find the first free (inactive) missile of type weaponType
         Basic::List::Item* item = list->getFirstItem();
         while (item != 0 && msl == 0) {
            Basic::Pair* pair = (Basic::Pair*)(item->getValue());
            Missile* p = dynamic_cast<Missile*>( pair->object() );
            if (p != 0 && p->isInactive()) {
               // Ok, we have a missile, but is it the type we want?
               if (*p->getType() == *missileType) {
                  p->ref();
                  msl = p;
               }
            }
            item = item->getNext();
         }

         list->unref();
      }

   }
   return msl;
}
//-----------------------------------------------------------------------------
// reshape it function, for reshaping our subdisplays
//-----------------------------------------------------------------------------
void GlutDisplay::reshapeIt(int w, int h)
{
   //std::cout << "reshapeIt() winID = " << winId;
   //std::cout << "; size(" << w << ", " << h << ")";
   //std::cout << std::endl;
   // make sure we have a min height and width or our displays will get destroyed
   if (w > 10 && h > 10) {
      BaseClass::reshapeIt(w, h);

      if (subDisplays() != nullptr && okToResize) {

         // go through and put our new numbers in
         Basic::List::Item* item = subDisplays()->getFirstItem();
         while (item != nullptr) {
            Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue());
            if (pair != nullptr) {
               GlutDisplay* gd = dynamic_cast<GlutDisplay*>(pair->object());
               if (gd != nullptr) gd->reshapeSubWindow();
            }
            item = item->getNext();
         }

         // Restore our window ID
         glutSetWindow(this->getWindowId());
      }
   }
}
Ejemplo n.º 14
0
//------------------------------------------------------------------------------
// Compute nav steering data for each steerpoint.
//------------------------------------------------------------------------------
void Route::computeSteerpointData(const LCreal, const Navigation* const nav)
{
   if (nav != nullptr) {
      Basic::PairStream* steerpoints = getComponents();
      if (steerpoints != nullptr) {

         // Until we pass the 'to' steerpoint, the 'from' pointer will be
         // null(0) and the steerpoint's compute() function will compute
         // direct-to the steerpoint.  After the 'to' steerpoint, the 'from'
         // pointer will help compute each from-to leg of the route.
         Steerpoint* from = nullptr;

         Basic::List::Item* item = steerpoints->getFirstItem();
         while (item != nullptr) {
            Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue());
            Steerpoint* stpt = static_cast<Steerpoint*>(pair->object());
            stpt->compute(nav,from);
            if (pair == to || from != nullptr) from = stpt;
            item = item->getNext();
         }

         steerpoints->unref();
         steerpoints = nullptr;
      }
   }
}
Ejemplo n.º 15
0
//------------------------------------------------------------------------------
// updateData()
//------------------------------------------------------------------------------
void Instrument::updateData(const LCreal dt)
{
   // update our base class
   BaseClass::updateData(dt);

   // check for a color rotary, just in case we need one
   BasicGL::ColorRotary* cr = dynamic_cast<BasicGL::ColorRotary*>(getColor());
   if (cr != 0) cr->determineColor(preScaleInstVal);

   // only tell the rest of our instruments our value if we want them to know it
   if (allowPassing) {
      // sort out the instruments from our components
      Basic::PairStream* ps = getComponents();
      if (ps != 0) {
         Basic::List::Item* item = ps->getFirstItem();
         while(item != 0) {
            Basic::Pair* pair = (Basic::Pair*) item->getValue();
            if (pair != 0) {
               // send the value down to all of our instrument components
               Instrument* myInst = dynamic_cast<Instrument*>(pair->object());
               Basic::Number n = preScaleInstVal;
               if (myInst != 0) myInst->event(UPDATE_INSTRUMENTS, &n);
            }
            item = item->getNext();
         }
         ps->unref();
         ps = 0;
      }
   }
}
Ejemplo n.º 16
0
//------------------------------------------------------------------------------
// Search all of the objects in the main list for objects of 'type' and add
// them to the sublist.  Also check all Stores type objects for any 'type' objects.
//------------------------------------------------------------------------------
void StoresMgr::searchAndAdd(Basic::PairStream* const mainList, const std::type_info& type, Basic::PairStream* sublist)
{
   if (mainList != 0 && sublist != 0) {

      const Basic::List::Item* item = mainList->getFirstItem();
      while (item != 0) {

         Basic::Pair* pair = (Basic::Pair*)(item->getValue());
         Basic::Component* p = (Basic::Component*)( pair->object() );

         // Check the type and add to the list
         bool isType = p->isClassType(type);
         if (isType) sublist->put(pair);

         // If this is a Stores object then check its stores for 'type' objects as well
         Stores* sp = dynamic_cast<Stores*>(p);
         if ( sp != 0 ) {
            Basic::PairStream* pstores = sp->getStores();
            searchAndAdd(pstores, type, sublist);
            pstores->unref();
         }

         item = item->getNext();
      }
   }  
}
Ejemplo n.º 17
0
//------------------------------------------------------------------------------
// stepOwnshipPlayer() -- Step to the next local player
//------------------------------------------------------------------------------
void SimStation::stepOwnshipPlayer()
{
   Basic::PairStream* pl = getSimulation()->getPlayers();
   if (pl != nullptr) {

      Simulation::Player* f = nullptr;
      Simulation::Player* n = nullptr;
      bool found = false;

      // Find the next player
      Basic::List::Item* item = pl->getFirstItem();
      while (item != nullptr) {
         Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue());
         if (pair != nullptr) {
            Simulation::Player* ip = static_cast<Simulation::Player*>(pair->object());
            if ( ip->isMode(Simulation::Player::ACTIVE) &&
               ip->isLocalPlayer() &&
               ip->isClassType(typeid(Simulation::AirVehicle))
               ) {
                  if (f == nullptr) { f = ip; }  // Remember the first
                  if (found)        { n = ip; ; break; }
                  if (ip == getOwnship()) found = true;
            }
         }
         item = item->getNext();
      }
      if (found && n == nullptr) n = f;
      if (n != nullptr) setOwnshipPlayer(n);

      pl->unref();
    }
}
Ejemplo n.º 18
0
		//-----------------------------------------------------------------------------
		// Eaagles::Swarms::builder() -- builds simulation tree
		//-----------------------------------------------------------------------------
		static void builder()
		{
			cout << "Reading file : " << configFile << endl;

			// Read the description file
			int errors = 0;
			Basic::Object* q1 = Basic::lcParser(configFile, Factory::createObj, &errors);
			if (errors > 0) {
				cerr << "File: " << configFile << ", errors: " << errors << endl;
				exit(1);
			}

			station = 0;
			if (q1 != 0) {
				// When we were given a Basic::Pair, get the pointer to its object.
				Basic::Pair* pp = dynamic_cast<Basic::Pair*>(q1);
				if (pp != 0) {
					q1 = pp->object();
				}

				// What we should have here is the Station object
				station = dynamic_cast<Simulation::Station*>(q1);
			}

			// Make sure we did get a valid Station object (we must have one!)
			if (station == 0) {
				cout << "Invalid description file!" << endl;
				exit(EXIT_FAILURE);
			}
		}
Ejemplo n.º 19
0
// Get the next free weapon of this 'type'
Weapon* SimpleStoresMgr::getSpecificWeapon(const std::type_info& type)
{
   Weapon* wpn = 0;
   if (&type != 0) {

      Basic::PairStream* list = getWeapons();
      if (list != 0) {

         // Find the first free (inactive) bomb
         Basic::List::Item* item = list->getFirstItem();
         while (item != 0 && wpn == 0) {
            Basic::Pair* pair = (Basic::Pair*)(item->getValue());
            Weapon* p = dynamic_cast<Weapon*>( pair->object() );
            if (p != 0 && p->isInactive() && p->isClassType(type)) {
               p->ref();
               wpn = p;
            }
            item = item->getNext();
         }

         list->unref();
      }

   }
   return wpn;
}
Ejemplo n.º 20
0
// Get the next free bomb of type 'bombType'
Bomb* SimpleStoresMgr::getSpecificBomb(const Basic::String* const bombType)
{
   Bomb* bomb = 0;
   if (bombType != 0)  {

      Basic::PairStream* list = getWeapons();
      if (list != 0)  {

         // Find the first free (inactive) bomb
         Basic::List::Item* item = list->getFirstItem();
         while (item != 0 && bomb == 0) {
            Basic::Pair* pair = (Basic::Pair*)(item->getValue());
            Bomb* p = dynamic_cast<Bomb*>( pair->object() );
            if (p != 0 && p->isInactive()) {
               // Ok, we have a bomb, but is it the type we want?
               if (*p->getType() == *bombType) {
                  p->ref();
                  bomb = p;
               }
            }
            item = item->getNext();
         }

         list->unref();
      }

   }
   return bomb;
}
Ejemplo n.º 21
0
//------------------------------------------------------------------------------
// setSlotHighlight() -- 
//------------------------------------------------------------------------------                          
bool Field::setSlotHighlight(const Basic::Number* const shobj)
{
    if (shobj != 0) {
        // Set our mode
        if (shobj->getBoolean()) {
            setDisplayMode(highlight);
            setDisplayMode(highlight1);
        }
        else {
            setDisplayMode(highlight);
            setDisplayMode(highlight1);
        }

        Basic::PairStream* subcomponents = getComponents();
        if (subcomponents != 0) {

            const Basic::List::Item* item = subcomponents->getFirstItem();
            while (item != 0) {
                Basic::Pair* p = (Basic::Pair*) item->getValue();
                Field* child = dynamic_cast<Field*>(p->object());
                if (child != 0) child->setSlotHighlight(shobj); //changed from obj
                item = item->getNext();
            }

            subcomponents->unref();
            subcomponents = 0;
        }
    }
    return true;
}   
Ejemplo n.º 22
0
// Default weapon jettison event handler
bool Stores::onJettisonEvent(Weapon* const wpn)
{
   bool ok = false;
   if (wpn != nullptr) {

      Basic::PairStream* list = getStores();
      if (list != nullptr) {

         // First, make sure it's one of ours!
         bool found = false;
         Basic::List::Item* item = list->getFirstItem();
         while (item != nullptr && !found) {
            Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue());
            found = (wpn == pair->object());  // is it a match?
            item = item->getNext();
         }

         if (found) {
            // Send a jettison event to the weapon
            ok = wpn->event(JETTISON_EVENT);
         }

         list->unref();
         list = nullptr;
      }
   }
   return ok;
}
Ejemplo n.º 23
0
//------------------------------------------------------------------------------
// setSlotReversed() -- 
//------------------------------------------------------------------------------                          
bool Field::setSlotReversed(const Basic::Number* const srobj)
{
   
    if (srobj != 0) {

        // Set our mode
        if (srobj->getBoolean()) {
            setDisplayMode(reversed);
            setDisplayMode(reversed1);
        }
        else {
            clearDisplayMode(reversed);
            clearDisplayMode(reversed1);
        }

        // Set our children's mode
        Basic::PairStream* subcomponents = getComponents();
        if (subcomponents != 0) {

            const Basic::List::Item* item = subcomponents->getFirstItem();
            while (item != 0) {
                Basic::Pair* p = (Basic::Pair*) item->getValue();
                Field* child = dynamic_cast<Field*>(p->object());
                if (child != 0) child->setSlotReversed(srobj);
                item = item->getNext();
            }

            subcomponents->unref();
            subcomponents = 0;
        }
    }
    return true;
}
//-----------------------------------------------------------------------------
// createWindow() -- create the main window
//-----------------------------------------------------------------------------
int GlutDisplay::createWindow()
{
   winId = -1;

#ifdef __FREEGLUT_EXT_H__     /* freeglut only */
      glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);
#endif

   unsigned int wmode = GLUT_DOUBLE | GLUT_RGB | GLUT_ALPHA;
   if (getClearDepth() >= 0.0f) { wmode = wmode | GLUT_DEPTH; }
   if (accumBuff) { wmode = wmode | GLUT_ACCUM; }
   if (stencilBuff) { wmode = wmode | GLUT_STENCIL; }
   glutInitDisplayMode( wmode );

   GLint  vpX(0), vpY(0);                   // our initial viewport position
   GLsizei vpWidth(0), vpHeight(0);    // our initial viewport size
   getViewport(&vpX, &vpY, &vpWidth, &vpHeight);
   glutInitWindowPosition(vpX, vpY);
   glutInitWindowSize(vpWidth, vpHeight);
   winId = glutCreateWindow(getName());
   if (winId > 0) {
      if (isMessageEnabled(MSG_INFO)) {
         std::cout << "GlutDisplay::createWindow() name = " << getName() << ", winId = " << winId << std::endl;
      }

      // Configure the new window
      if (fullScreenFlg) glutFullScreen();
      glutDisplayFunc(drawFuncCB);
      glutReshapeFunc(reshapeItCB);
      glutIdleFunc(idleCB);
      glutPassiveMotionFunc(passiveMotionFuncCB);
      glutMotionFunc(motionFuncCB);
      glutKeyboardFunc(keyboardFuncCB);
      glutSpecialFunc(specialFuncCB);
      glutMouseFunc(mouseFuncCB);
      glutEntryFunc(entryFuncCB);
      registerGlutDisplay(winId, this);
      glutSetWindow(winId);
      configure();
      loadTextures();

      // Create sub windows (if any)
      if (subDisplays() != nullptr) {
         Basic::List::Item* item = subDisplays()->getFirstItem();
         while (item != nullptr) {
            Basic::Pair* pair = dynamic_cast<Basic::Pair*>(item->getValue());
            if (pair != nullptr) {
               GlutDisplay* dobj = dynamic_cast<GlutDisplay*>( pair->object() );
               if (dobj != nullptr) dobj->createSubWindow(winId);
            }
            item = item->getNext();
         }
      }

      // Select this window
      select();
   }

   return winId;
}
Ejemplo n.º 25
0
//------------------------------------------------------------------------------
// getRCS() -- Get the RCS
//------------------------------------------------------------------------------
LCreal SigSwitch::getRCS(const Emission* const em)
{
   LCreal rcs = 0.0;

   // Find our ownship player ...
   const Player* ownship = static_cast<const Player*>(findContainerByType(typeid(Player)));
   if (ownship != 0) {

      // get our ownship's camouflage type
      unsigned int camouflage = ownship->getCamouflageType();
      camouflage++; // our components are one based

      // find a RfSignature with this index
      Basic::Pair* pair = findByIndex(camouflage);
      if (pair != 0) {
         RfSignature* sig = dynamic_cast<RfSignature*>( pair->object() );
         if (sig != 0) {

            // OK -- we've found the correct RfSignature subcomponent
            // now let it do all of the work
            rcs = sig->getRCS(em);

         }
      }

   }

   return rcs;
}
Ejemplo n.º 26
0
//------------------------------------------------------------------------------
// Set slot functions
//------------------------------------------------------------------------------
bool StoresMgr::setSlotStores(const Basic::PairStream* const msg)
{
   // First let our base class do everything that it needs to.
   BaseClass::setSlotStores(msg);

   // ---
   // Clear all previous stores and assigned weapons
   // ---
   weaponsList = 0;
   externalList = 0;
   fuelList = 0;
   gunPtr = 0;

   // ---
   // Use the stores list that the Stores class just processed.
   Basic::PairStream* stores = getStores();
   if (stores != 0){

      // Create the new weapons list that contains all weapons
      {
         Basic::PairStream* newWeapons = new Basic::PairStream();
         searchAndAdd(stores, typeid(Weapon), newWeapons);
         if (newWeapons->entries() > 0) weaponsList = newWeapons;
         newWeapons->unref();
      }

      // Create the new external stores list that contains all
      // non-weapon, external stores (e.g., fuel tanks, pods, guns)
      {
         Basic::PairStream* newExternal = new Basic::PairStream();
         searchAndAdd(stores, typeid(ExternalStore), newExternal);
         if (newExternal->entries() > 0) externalList = newExternal;
         newExternal->unref();
      }

      // Create the new fuel tank list that contains all fuel tanks
      {
         Basic::PairStream* newFuel = new Basic::PairStream();
         searchAndAdd(stores, typeid(FuelTank), newFuel);
         if (newFuel->entries() > 0) fuelList = newFuel;
         newFuel->unref();
      }

      // Find the primary gun; i.e., the first gun found on our stores
      Basic::List::Item* item = stores->getFirstItem();
      while (item != 0 && gunPtr == 0) {
         Basic::Pair* pair = (Basic::Pair*)(item->getValue());

         Gun* p = dynamic_cast<Gun*>( pair->object() );
         if (p != 0) gunPtr = p;

         item = item->getNext();
      }

      stores->unref();
      stores = 0;
   }

   return true;
}
Ejemplo n.º 27
0
// test station builder
static TestStation* builder(const char* const filename)
{
   // read configuration file
   int errors = 0;
   Basic::Object* obj = Basic::lcParser(filename, Factory::createObj, &errors);
   if (errors > 0) {
      std::cerr << "File: " << filename << ", errors: " << errors << std::endl;
      std::exit(EXIT_FAILURE);
   }

   // test to see if an object was created
   if (obj == nullptr) {
      std::cerr << "Invalid configuration file, no objects defined!" << std::endl;
      std::exit(EXIT_FAILURE);
   }

   // do we have a Basic::Pair, if so, point to object in Pair, not Pair itself
   Basic::Pair* pair = dynamic_cast<Basic::Pair*>(obj);
   if (pair != nullptr) {
      obj = pair->object();
      obj->ref();
      pair->unref();
   }

   // try to cast to proper object, and check
   TestStation* testStation = dynamic_cast<TestStation*>(obj);
   if (testStation == nullptr) {
      std::cerr << "Invalid configuration file!" << std::endl;
      std::exit(EXIT_FAILURE);
   }
   return testStation;
}
Ejemplo n.º 28
0
//------------------------------------------------------------------------------
// Removes a symbol from the master symbol table
//------------------------------------------------------------------------------
bool SymbolLoader::removeSymbol(const int idx)
{
    bool ok = false;

    // Find the symbol
    if (idx >= 1 && idx <= MAX_SYMBOLS) {
        const int i = (idx - 1);
        if (symbols[i] != 0) {

            // ---
            // remove the symbol's graphical component from our subcomponent list
            // ---
            {
                // Get the symbol's graphical component
                Basic::Pair* pair = symbols[i]->getSymbolPair();
                BasicGL::Graphic* g = (BasicGL::Graphic*) pair->object();

                Basic::PairStream* x = getComponents();
                Basic::Component::processComponents(x, typeid(BasicGL::Graphic), 0, g);
                x->unref();
            }

            // ---
            // and remove it from our master symbol table
            // ---
            symbols[i]->setSymbolPair(0);
            symbols[i]->unref();
            symbols[i] = 0;

            ok = true;
        }

    }
    return ok;
}
Ejemplo n.º 29
0
//------------------------------------------------------------------------------
// getSteerpoints() -- Get the route we're flying to (starting at 'to')
//------------------------------------------------------------------------------
unsigned int Route::getSteerpoints(Basic::safe_ptr<Steerpoint>* const stptList, const unsigned int max)
{
    unsigned int i = 0;
    Basic::PairStream* steerpoints = getComponents();
    if (stptList != nullptr && max > 0 && steerpoints != nullptr) {

        // Find our 'to' steerpoint
        bool found = false;
        Basic::List::Item* item = steerpoints->getFirstItem();
        while (item != nullptr && !found) {
            Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue());
            found = (pair == to);
            if (!found) {
                item = item->getNext();
            }
        }

        // Get the route we're flying 'to'
        while (item != nullptr && i < max) {
            Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue());
            Steerpoint* p = dynamic_cast<Steerpoint*>(pair->object());
            if (p != nullptr) {
                stptList[i++] = p;
            }
            item = item->getNext();
        }
    }

    if (steerpoints != nullptr) {
       steerpoints->unref();
       steerpoints = nullptr;
    }

    return i;
}
Ejemplo n.º 30
0
// Default external equipment jettison event handler
bool Stores::onJettisonEvent(ExternalStore* const sys)
{
   bool ok = false;
   if (sys != 0) {

      Basic::PairStream* list = getStores();
      if (list != 0) {

         // First, make sure it's one of ours!
         bool found = false;
         Basic::List::Item* item = list->getFirstItem();
         while (item != 0 && !found) {
            Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue());
            found = (sys == pair->object());  // is it a match?
            item = item->getNext();
         }

         if (found) {
            // Send a jettison event to the system
            ok = sys->event(JETTISON_EVENT);
         }

         list->unref();
         list = 0;
      }
   }
   return ok;
}