コード例 #1
0
ファイル: OSegScenario.cpp プロジェクト: AsherBond/sirikata
void OSegScenario::sendPings() {
    mPingProfiler->started();

    Time newTime=mContext->simTime();
    int64 howManyPings = (newTime-mStartTime).toSeconds()*mNumPingsPerSecond;

    bool broke=false;
    // NOTE: We limit here because we can get in lock-step with the generator,
    // causing this to run for excessively long when we fall behind on pings.
    int64 limit = std::min((int64)howManyPings-mNumTotalPings, mMaxPingsPerRound);
    int64 i;
    for (i=0;i<limit;++i) {
        Time t(mContext->simTime());
        PingInfo result;
        if (!mPings->pop(result)) {
            OH_LOG(insane,"Ping queue underflowed.");
            break;
        }
        bool sent_success = mContext->objectHost->sendPing(t, result.objA, result.objB, result.ping);
        delete result.ping;
        if (!sent_success)
            break;
    }
    mNumTotalPings += i;

    mPingProfiler->finished();

    static bool printed=false;
    if ( (i-limit) > (10*(int64)mNumPingsPerSecond) && !printed) {
        OH_LOG(debug,i-limit<<" pending ");
        printed=true;
    }

}
コード例 #2
0
ファイル: ObjectHost.cpp プロジェクト: SinSiXX/sirikata
void ObjectHost::handleObjectMessage(const SpaceObjectReference& sporef_internalID, const SpaceID& space, Sirikata::Protocol::Object::ObjectMessage* msg) {
    // Either we know the object and deliver, or somethings gone wacky
    HostedObjectPtr obj = getHostedObject(sporef_internalID);
    if (obj) {
        obj->receiveMessage(space, msg);
    }
    else {
        OH_LOG(warn, "Got message for " << sporef_internalID << " but no such object exists.");
        delete msg;
    }
}
コード例 #3
0
ファイル: OSegScenario.cpp プロジェクト: SinSiXX/sirikata
void OSegScenario::generatePairs() {

    if (mSendCDF.empty()) {
        std::vector<Object*> floodedObjects;
        Time t=mContext->simTime();

        for (int i=0;i<(int)mObjectTracker->numServerIDs();++i) {
            if (mObjectTracker->numObjectsConnected(mObjectTracker->getServerID(i))<mNumObjectsPerServer) {
                return;
            }
        }
        OH_LOG(debug, "Beginning object seed phase at " << (t-mStartTime)<<"\n");
        Object* first=mObjectTracker->roundRobinObject(mFloodServer);
        if (!first) {
            assert(0);
            return;
        }
        Object* cur=first;
        do {
            floodedObjects.push_back(cur);
            cur=mObjectTracker->roundRobinObject(mFloodServer);
        }while(cur!=first);
        for (size_t i=0;i<mObjectTracker->numServerIDs();++i) {
            ServerID sid=mObjectTracker->getServerID(i);
            if (sid==mFloodServer) continue;
            Object* first=mObjectTracker->roundRobinObject(sid);
            if (!first) {
                assert(0);
                return;
            }
            Object* cur=first;
            do {
                //generate message from/to cur to a floodedObject
                Object* dest=floodedObjects[rand()%floodedObjects.size()];
                assert(dest);
                Object* src=cur=mObjectTracker->roundRobinObject(sid);
                assert(src);
                if (mSourceFloodServer) {
                    std::swap(src,dest);
                }
                MessageFlow pi;
                pi.dest=dest->uuid();
                pi.source=src->uuid();
                pi.dist=(src->location().position(t)-dest->location().position(t)).length();
/*
                printf ("Sending data from object size %f to object size %f, %f meters away\n",
                        src->bounds().radius(),
                        dest->bounds().radius(),
                        pi.dist);
*/
                BoundingBox3f srcbb(src->location().position(t),src->bounds().radius());
                BoundingBox3f dstbb(dest->location().position(t),dest->bounds().radius());
                pi.cumulativeProbability= this->mWeightCalculator->weight(srcbb,dstbb);
                mSendCDF.push_back(pi);

            }while(cur!=first);
        }
        std::sort(mSendCDF.begin(),mSendCDF.end());
        double cumulative=0;
        for (size_t i=0;i<mSendCDF.size();++i) {
            cumulative+=mSendCDF[i].cumulativeProbability;
            mSendCDF[i].cumulativeProbability=cumulative;
        }

        for (size_t i=0;i<mSendCDF.size();++i) {
            mSendCDF[i].cumulativeProbability/=cumulative;
        }
    }

}