Ejemplo n.º 1
0
void Missile::update(const float elapsed_time, bool force)
{
    OpenSteer::Vec3 steer = m_last_steer;
    if (force ||
        m_pathing_engine->UpdateNumber() % PathingEngine::UPDATE_SETS ==
        serialNumber % PathingEngine::UPDATE_SETS) {
        const float AT_DESTINATION = speed();
        const float AT_DEST_SQUARED = AT_DESTINATION * AT_DESTINATION;
        float distance_squared = (m_destination - position()).lengthSquared();
        CombatObjectPtr target = m_target.lock();
        if (distance_squared < AT_DEST_SQUARED) {
            if (target) {
                Listener().MissileExploded(shared_from_this());
                target->Damage(Stats().m_damage, NON_PD_DAMAGE);
            } else {
                Listener().MissileRemoved(shared_from_this());
            }
            delete m_proximity_token;
            m_proximity_token = 0;
            m_pathing_engine->RemoveObject(shared_from_this());
            return;
        } else {
            if (target)
                m_destination = target->position();
        }
        steer = Steer();
    }
    applySteeringForce(steer, elapsed_time);
    m_last_steer = steer;
    m_proximity_token->UpdatePosition(position());
}
Ejemplo n.º 2
0
void CombatShip::FireAt(CombatObjectPtr target)
{
    float range_squared = (target->position() - position()).lengthSquared();
    float structure_factor = FractionalStructure();

    for (CombatShip::SRVec::reverse_iterator it = m_unfired_SR_weapons.rbegin();
         it != m_unfired_SR_weapons.rend();
         ++it) {
        if (range_squared < it->m_range * it->m_range) {
            Listener().ShipFired(shared_from_this(), target, it->m_name);
            target->Damage(it->m_damage, CombatObject::NON_PD_DAMAGE);
        } else {
            m_unfired_SR_weapons.resize(std::distance(it, m_unfired_SR_weapons.rend()));
            break;
        }
    }
    std::size_t i = 0;
    for (std::multimap<float, const PartType*>::const_iterator it =
             GetShip()->Design()->LRWeapons().begin();
         it != GetShip()->Design()->LRWeapons().end();
         ++it, ++i)
    {
        if (m_next_LR_fire_turns[i] < m_turn) {
            float weapon_range_squared = it->first * it->first;
            if (range_squared < weapon_range_squared) {
                OpenSteer::Vec3 direction = (target->position() - position()).normalize();
                MissilePtr missile(
                    new Missile(GetShip(), *it->second, target,
                                position(), direction, *m_pathing_engine));
                m_pathing_engine->AddObject(missile);
                GetShip()->RemoveMissiles(it->second->Name(), 1);
                if (m_next_LR_fire_turns[i] == INVALID_TURN)
                    m_next_LR_fire_turns[i] = m_turn;
                m_next_LR_fire_turns[i] +=
                    GetShip()->GetPartMeter(METER_ROF, it->second->Name())->Current() * structure_factor;
                Listener().MissileLaunched(missile);
            }
        }
    }
    for (CombatShip::PDList::iterator it = m_unfired_PD_weapons.begin();
         it != m_unfired_PD_weapons.end();
         ++it) {
        if (range_squared < it->m_range * it->m_range) {
            Listener().ShipFired(shared_from_this(), target, it->m_name);
            target->Damage(it->m_damage, CombatObject::PD_DAMAGE);
        } else {
            m_unfired_PD_weapons.erase(it, m_unfired_PD_weapons.end());
            break;
        }
    }
}
Ejemplo n.º 3
0
void
RPCChannel::Incall(const Message& call, size_t stackDepth)
{
    AssertWorkerThread();
    mMonitor->AssertNotCurrentThreadOwns();
    RPC_ASSERT(call.is_rpc() && !call.is_reply(), "wrong message type");

    // Race detection: see the long comment near
    // mRemoteStackDepthGuess in RPCChannel.h.  "Remote" stack depth
    // means our side, and "local" means other side.
    if (call.rpc_remote_stack_depth_guess() != RemoteViewOfStackDepth(stackDepth)) {
        // RPC in-calls have raced.
        // the "winner", if there is one, gets to defer processing of
        // the other side's in-call
        bool defer;
        const char* winner;
        switch (Listener()->MediateRPCRace(mChild ? call : mStack.top(),
                                           mChild ? mStack.top() : call)) {
        case RRPChildWins:
            winner = "child";
            defer = mChild;
            break;
        case RRPParentWins:
            winner = "parent";
            defer = !mChild;
            break;
        case RRPError:
            NS_RUNTIMEABORT("NYI: 'Error' RPC race policy");
            return;
        default:
            NS_RUNTIMEABORT("not reached");
            return;
        }

        if (LoggingEnabled()) {
            printf_stderr("  (%s: %s won, so we're%sdeferring)\n",
                          mChild ? "child" : "parent", winner,
                          defer ? " " : " not ");
        }

        if (defer) {
            // we now know the other side's stack has one more frame
            // than we thought
            ++mRemoteStackDepthGuess; // decremented in MaybeProcessDeferred()
            mDeferred.push(call);
            return;
        }

        // we "lost" and need to process the other side's in-call.
        // don't need to fix up the mRemoteStackDepthGuess here,
        // because we're just about to increment it in DispatchCall(),
        // which will make it correct again
    }

#ifdef OS_WIN
    SyncStackFrame frame(this, true);
#endif

    DispatchIncall(call);
}
Ejemplo n.º 4
0
// ============================================================================
// Inherited IIncidentSvc overrides:
// ============================================================================
void IncidentSvc::addListener
( IIncidentListener* lis ,
  const std::string& type ,
  long prio, bool rethrow, bool singleShot)
{

  boost::recursive_mutex::scoped_lock lock(m_listenerMapMutex);

  std::string ltype;
  if( type == "" ) ltype = "ALL";
  else             ltype = type;
  // find if the type already exists
  ListenerMap::iterator itMap = m_listenerMap.find( ltype );
  if( itMap == m_listenerMap.end() ) {
    // if not found, create and insert now a list of listeners
    ListenerList* newlist = new ListenerList();
    std::pair<ListenerMap::iterator, bool> p;
    p = m_listenerMap.insert(ListenerMap::value_type(ltype, newlist));
    if( p.second ) itMap = p.first;
  }
  ListenerList* llist = (*itMap).second;
  // add Listener in the ListenerList according to the priority
  ListenerList::iterator itlist;
  for( itlist = llist->begin(); itlist != llist->end(); itlist++ ) {
    if( (*itlist).priority < prio ) {
      // We insert before the current position
      break;
    }
  }

  DEBMSG << "Adding [" << type << "] listener '" << getListenerName(lis)
         << "' with priority " << prio << endmsg;

  llist->insert(itlist, Listener(lis, prio, rethrow, singleShot));
}
Ejemplo n.º 5
0
void CombatFighter::FireAtHostiles()
{
    assert(m_leader);
    assert(!m_formation->empty());
    assert(!m_mission_queue.empty());

    OpenSteer::Vec3 position_to_use = m_formation->Centroid();
    const double WEAPON_RANGE = Stats().m_fighter_weapon_range;
    const double WEAPON_RANGE_SQUARED = WEAPON_RANGE * WEAPON_RANGE;

    CombatObjectPtr target = m_mission_subtarget.lock();
    if (!target && m_mission_queue.back().m_type == FighterMission::ATTACK_THIS) {
        assert(m_mission_queue.back().m_target.lock());
        target = m_mission_queue.back().m_target.lock();
        if (WEAPON_RANGE_SQUARED < (target->position() - position_to_use).lengthSquared())
            target.reset();
    }

    // find a target of opportunity
    if (!target) {
        target = m_pathing_engine->NearestHostileFighterInRange(
            position_to_use, m_empire_id, WEAPON_RANGE);
    }
    if (!target) {
        target = m_pathing_engine->NearestHostileNonFighterInRange(
            position_to_use, m_empire_id, WEAPON_RANGE);
    }

    if (target) {
        target->Damage(shared_from_this());
        m_last_fired_turn = m_turn;
        Listener().FighterFired(shared_from_this(), target);
    }
}
Ejemplo n.º 6
0
  virtual void SetUp() {
    Listener listener;
    listener = Listener(&listeners_[0]);
    listener.SetLocation(mathfu::Vector<float, 3>(0.0f, 0.0f, 0.0f));
    listener = Listener(&listeners_[1]);
    listener.SetLocation(mathfu::Vector<float, 3>(10.0f, 0.0f, 0.0f));
    listener = Listener(&listeners_[2]);
    listener.SetLocation(mathfu::Vector<float, 3>(10.0f, 0.0f, 10.0f));
    listener = Listener(&listeners_[3]);
    listener.SetLocation(mathfu::Vector<float, 3>(0.0f, 0.0f, 10.0f));

    listener_list_.InsertAfter(&listeners_[0]);
    listeners_[0].InsertAfter(&listeners_[1]);
    listeners_[1].InsertAfter(&listeners_[2]);
    listeners_[2].InsertAfter(&listeners_[3]);
  }
Ejemplo n.º 7
0
void
RPCChannel::DispatchIncall(const Message& call)
{
    AssertWorkerThread();
    mMonitor->AssertNotCurrentThreadOwns();
    RPC_ASSERT(call.is_rpc() && !call.is_reply(),
               "wrong message type");

    Message* reply = nullptr;

    ++mRemoteStackDepthGuess;
    Result rv = Listener()->OnCallReceived(call, reply);
    --mRemoteStackDepthGuess;

    if (!MaybeHandleError(rv, "RPCChannel")) {
        delete reply;
        reply = new Message();
        reply->set_rpc();
        reply->set_reply();
        reply->set_reply_error();
    }

    reply->set_seqno(call.seqno());

    {
        MonitorAutoLock lock(*mMonitor);
        if (ChannelConnected == mChannelState)
            mLink->SendMessage(reply);
    }
}
Ejemplo n.º 8
0
int _tmain(int argc, _TCHAR* argv[])
{
	Console::Title = "rAPB Client Authorization Server";
	Log_Clear();
	Listener ^list = gcnew Listener("127.0.0.1", 2255);
    return 0;
}
Ejemplo n.º 9
0
int Contact::connectListener(PyObject* pMotionCallback, PyObject* pUpCallback)
{
    avgDeprecationWarning("1.8", "Contact.connectListener()", "Contact.subscribe()");
    s_LastListenerID++;
    pair<int, Listener> val = 
            pair<int, Listener>(s_LastListenerID, Listener(pMotionCallback, pUpCallback));
    m_ListenerMap.insert(val);
    return s_LastListenerID;
}
Ejemplo n.º 10
0
void
RPCChannel::ExitedCxxStack()
{
    Listener()->OnExitedCxxStack();
    if (mSawRPCOutMsg) {
        MonitorAutoLock lock(*mMonitor);
        // see long comment in OnMaybeDequeueOne()
        EnqueuePendingMessages();
        mSawRPCOutMsg = false;
    }
}
Ejemplo n.º 11
0
void NetworkBinding::AddConnectivityListener(const ValueList& args, SharedValue result)
{
    ArgUtils::VerifyArgsException("addConnectivityListener", args, "m");
    SharedBoundMethod target = args.at(0)->ToMethod();

    Listener listener = Listener();
    listener.id = this->next_listener_id++;
    listener.callback = target;
    this->listeners.push_back(listener);
    result->SetInt(listener.id);
}
Ejemplo n.º 12
0
void Network::_AddConnectivityListener(const ValueList& args, KValueRef result)
{
    args.VerifyException("addConnectivityListener", "m");
    KMethodRef target = args.at(0)->ToMethod();

    static long nextListenerId = 0;
    Listener listener = Listener();
    listener.id = nextListenerId++;
    listener.callback = target;
    this->listeners.push_back(listener);
    result->SetInt(listener.id);
}
Ejemplo n.º 13
0
void
ClientFace::listen(const Name& prefix, const OnInterest& onInterest, bool wantRegister)
{
  if (wantRegister) {
    this->registerPrefix(prefix);
  }

  m_listeners.push_back(Listener());
  Listener& listener = m_listeners.back();
  listener.prefix = prefix;
  listener.onInterest = onInterest;
}
QT_BEGIN_NAMESPACE

bool QLocalServerPrivate::addListener()
{
    // The object must not change its address once the
    // contained OVERLAPPED struct is passed to Windows.
    listeners << Listener();
    Listener &listener = listeners.last();

    listener.handle = CreateNamedPipe(
                 (const wchar_t *)fullServerName.utf16(), // pipe name
                 PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,       // read/write access
                 PIPE_TYPE_BYTE |          // byte type pipe
                 PIPE_READMODE_BYTE |      // byte-read mode
                 PIPE_WAIT,                // blocking mode
                 PIPE_UNLIMITED_INSTANCES, // max. instances
                 BUFSIZE,                  // output buffer size
                 BUFSIZE,                  // input buffer size
                 3000,                     // client time-out
                 NULL);

    if (listener.handle == INVALID_HANDLE_VALUE) {
        setError(QLatin1String("QLocalServerPrivate::addListener"));
        listeners.removeLast();
        return false;
    }

    memset(&listener.overlapped, 0, sizeof(listener.overlapped));
    listener.overlapped.hEvent = eventHandle;
    if (!ConnectNamedPipe(listener.handle, &listener.overlapped)) {
        switch (GetLastError()) {
        case ERROR_IO_PENDING:
            listener.connected = false;
            break;
        case ERROR_PIPE_CONNECTED:
            listener.connected = true;
            SetEvent(eventHandle);
            break;
        default:
            CloseHandle(listener.handle);
            setError(QLatin1String("QLocalServerPrivate::addListener"));
            listeners.removeLast();
            return false;
        }
    } else {
        Q_ASSERT_X(false, "QLocalServerPrivate::addListener", "The impossible happened");
        SetEvent(eventHandle);
    }
    return true;
}
Ejemplo n.º 15
0
  virtual void SetUp() {
    Listener listener;

    // The Matrix::LookAt function is hardcoded to be left handed
    listener = Listener(&state_1_);
    listener.SetOrientation(mathfu::Vector<float, 3>(0.0f, 0.0f, 0.0f),
                            mathfu::Vector<float, 3>(0.0f, 1.0f, 0.0f),
                            -mathfu::kAxisZ3f);

    listener = Listener(&state_2_);
    listener.SetOrientation(mathfu::Vector<float, 3>(12.0f, 34.0f, 56.0f),
                            mathfu::Vector<float, 3>(0.0f, 0.0f, 78.0f),
                            -mathfu::kAxisX3f);

    listener = Listener(&state_3_);
    listener.SetOrientation(mathfu::Vector<float, 3>(10.0f, 10.0f, 10.0f),
                            mathfu::Vector<float, 3>(20.0f, 0.0f, 0.0f),
                            -mathfu::kAxisY3f);

    listener_list_1_.InsertAfter(&state_1_);
    listener_list_2_.InsertAfter(&state_2_);
    listener_list_3_.InsertAfter(&state_3_);
  }
void EventDispatcher::AttachEvent(const String& type, EventListener* listener, bool in_capture_phase)
{
	// Look up the event
	Events::iterator event_itr = events.find(type);

	// Ensure the event is in the event list
	if (event_itr == events.end())
	{
		event_itr = events.insert(std::pair< String, Listeners >(type, Listeners())).first;
	}

	// Add the action to the events
	(*event_itr).second.push_back(Listener(listener, in_capture_phase));

	listener->OnAttach(element);
}
Ejemplo n.º 17
0
void CombatShip::FirePDDefensively()
{
    if (m_unfired_PD_weapons.empty())
        return;

    OpenSteer::AVGroup all;
    m_pathing_engine->GetProximityDB().FindInRadius(
        position(), MaxPDRange(), all,
        FIGHTER_FLAGS | MISSILE_FLAG, EnemyOfEmpireFlags(m_empire_id));
    for (std::size_t i = 0; i < all.size(); ++i) {
        CombatObject* obj = boost::polymorphic_downcast<CombatObject*>(all[i]);
        float distance_squared = (obj->position() - position()).lengthSquared();
        for (PDList::reverse_iterator it = m_unfired_PD_weapons.rbegin();
             it != m_unfired_PD_weapons.rend(); ) {
            if (distance_squared < it->m_range * it->m_range) {
                CombatObjectPtr shared_obj;
                if (obj->IsFighter()) {
                    shared_obj =
                        boost::polymorphic_downcast<CombatFighter*>(obj)->shared_from_this();
                } else {
                    shared_obj =
                        boost::polymorphic_downcast<Missile*>(obj)->shared_from_this();
                }
                Listener().ShipFired(shared_from_this(), shared_obj, it->m_name);
                float damage = std::min(obj->StructureAndShield(), it->m_damage);
                // HACK! This looks weird, but does what we want.  Non-PD
                // damage on a fighter only affects the fighter itself -- it
                // is not spread out over its formation mates.  This is
                // appropriate here, since we already have our in-range
                // targets.  Finally, since non-PD damage on fighters and
                // missiles gets multiplied by CombatShip::
                // NON_PD_VS_FIGHTER_FACTOR, we divide by it here.
                obj->Damage(damage / CombatShip::NON_PD_VS_FIGHTER_FACTOR, NON_PD_DAMAGE);
                it->m_damage -= damage;
                if (!it->m_damage) {
                    PDList::reverse_iterator temp = boost::next(it);
                    m_unfired_PD_weapons.erase((--it).base());
                    it = temp;
                }
                if (!obj->StructureAndShield())
                    break;
            }
        }
    }
}
Ejemplo n.º 18
0
void CombatShip::TurnStarted(unsigned int number)
{
    m_turn = number;
    m_turn_start_structure = Structure();
    if (m_turn - m_enter_starlane_start_turn == ENTER_STARLANE_DELAY_TURNS) {
        Listener().ShipEnteredStarlane(shared_from_this());
        delete m_proximity_token;
        m_proximity_token = 0;
        m_pathing_engine->RemoveObject(shared_from_this());
    } else {
        const ShipDesign& design = *GetShip()->Design();
        m_unfired_SR_weapons.resize(design.SRWeapons().size());
        m_unfired_PD_weapons.clear();
        std::transform(design.SRWeapons().begin(), design.SRWeapons().end(),
                       m_unfired_SR_weapons.begin(),
                       CopyStats<DirectFireStats>(GetShip(), FractionalStructure()));
        std::transform(design.PDWeapons().begin(), design.PDWeapons().end(),
                       std::back_inserter(m_unfired_PD_weapons),
                       CopyStats<DirectFireStats>(GetShip(), FractionalStructure()));
    }
}
Ejemplo n.º 19
0
void CombatFighter::EnterSpace()
{
    if (m_leader) {
        m_proximity_token =
            m_pathing_engine->GetProximityDB().Insert(
                this,
                Stats().m_type == INTERCEPTOR ? INTERCEPTOR_FLAG : BOMBER_FLAG,
                EmpireFlag(m_empire_id));
    }

    SimpleVehicle::reset();
    SimpleVehicle::setMaxForce(3.0 * 9.0);
    SimpleVehicle::setMaxSpeed(Stats().m_speed);

    // TODO: setMass()

    if (m_leader) {
        CombatObjectPtr base = m_base.lock();
        assert(base);
        SimpleVehicle::setPosition(base->position());
        SimpleVehicle::regenerateOrthonormalBasis(base->forward(), base->up());
        SimpleVehicle::setSpeed(CombatFighter::maxSpeed());
    } else {
        SimpleVehicle::regenerateOrthonormalBasis(m_formation->Leader().forward(),
                                                  m_formation->Leader().up());
        SimpleVehicle::setPosition(GlobalFormationPosition());
        SimpleVehicle::setSpeed(0.0);
    }

    if (m_leader)
        m_proximity_token->UpdatePosition(position());

    m_mission_queue.push_front(FighterMission(FighterMission::NONE));

    Listener().FighterLaunched(shared_from_this());
}
Ejemplo n.º 20
0
void Missile::SignalDestroyed()
{ Listener().MissileRemoved(shared_from_this()); }
Ejemplo n.º 21
0
void CombatFighter::SignalDestroyed()
{ Listener().FighterDestroyed(shared_from_this()); }
Ejemplo n.º 22
0
void CombatFighter::ExitSpace()
{
    delete m_proximity_token;
    m_proximity_token = 0;
    Listener().FighterDocked(shared_from_this());
}
Ejemplo n.º 23
0
void CombatShip::SignalDestroyed()
{ Listener().ShipDestroyed(shared_from_this()); }