示例#1
0
template <class T, typename S> T* ArrayBase<T,S>::add(const ArrayBase<T,S>& other)
{
    return replace(getSize(), getSize(), other);
}
void PointChunk::changeFrom(DrawEnv    *pEnv, 
                            StateChunk *old_chunk, 
                            UInt32               )
{
    PointChunk *old = dynamic_cast<PointChunk *>(old_chunk);

#ifndef OSG_OGL_ES2
    if(getSize() != old->getSize())
        glPointSize(getSize());
#endif

#if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
    if(getSmooth() && !old->getSmooth())
    {
        glEnable(GL_POINT_SMOOTH);
    }
    else if(!getSmooth() && old->getSmooth())
    {
        glDisable(GL_POINT_SMOOTH);
    }
#endif

    Window *pWin = pEnv->getWindow();

    osgSinkUnusedWarning(pWin);

#if GL_ARB_point_parameters
    if(getMinSize() >= 0.f)
    {
        if(pEnv->getWindow()->hasExtOrVersion(_extPointParameters, 0x0104))
        {
            OSGGETGLFUNCBYID_GL3( glPointParameterf,
                                  osgGlPointParameterf,
                                 _funcIdPointParameterf,
                                  pWin);
#if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
            OSGGETGLFUNCBYID_GL3( glPointParameterfv,
                                  osgGlPointParameterfv,
                                 _funcIdPointParameterfv,
                                  pWin);

            osgGlPointParameterf(GL_POINT_SIZE_MIN_ARB, getMinSize());
            osgGlPointParameterf(GL_POINT_SIZE_MAX_ARB, getMaxSize());
#endif
            osgGlPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_ARB, 
                                 getFadeThreshold());
            
#if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
            GLfloat att[3] = { getConstantAttenuation (),
                               getLinearAttenuation   (),
                               getQuadraticAttenuation() };
            
            osgGlPointParameterfv(GL_POINT_DISTANCE_ATTENUATION_ARB, att);
#endif
        }
        
    }
    else if(old->getMinSize() >= 0.f)
    {
        if(pEnv->getWindow()->hasExtOrVersion(_extPointParameters, 0x0104))
        {
            OSGGETGLFUNCBYID_GL3( glPointParameterf,
                                  osgGlPointParameterf,
                                 _funcIdPointParameterf,
                                  pWin);
#if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
            OSGGETGLFUNCBYID_GL3( glPointParameterfv,
                                  osgGlPointParameterfv,
                                 _funcIdPointParameterfv,
                                  pWin);

            osgGlPointParameterf(GL_POINT_SIZE_MIN_ARB, 0);
            osgGlPointParameterf(GL_POINT_SIZE_MAX_ARB, 1e10);
#endif
            osgGlPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_ARB, 1);
            
#if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
            GLfloat att[3] = { 1, 0, 0 };
            
            osgGlPointParameterfv(GL_POINT_DISTANCE_ATTENUATION_ARB, att);
#endif
        }
    }
#endif

#if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
#if GL_ARB_point_sprite
    if(getSprite() && !old->getSprite())
    {
        if(pEnv->getWindow()->hasExtOrVersion(_extPointSpriteARB, 0x0200))
        {
#if GL_NV_point_sprite
            if(pEnv->getWindow()->hasExtension(_extPointSpriteNV))
            {
                OSGGETGLFUNCBYID_GL3( glPointParameterf,
                                      osgGlPointParameterf,
                                     _funcIdPointParameterf,
                                      pWin);

                osgGlPointParameterf(GL_POINT_SPRITE_R_MODE_NV, 
                                     Real32(getRMode()));
            }
#endif
            
            glEnable(GL_POINT_SPRITE_ARB);
        }
        
    }
    else if(!getSprite() && old->getSprite())
    {
        if(pEnv->getWindow()->hasExtOrVersion(_extPointSpriteARB, 0x0200))
        {
           glDisable(GL_POINT_SPRITE_ARB);
        }
        
    }
#endif
#endif

#if ! defined(GL_ARB_point_parameters) && ! defined(GL_ARB_point_sprite)
    pEnv;
#endif
}
示例#3
0
    void BackgroundSync::produce() {
        // this oplog reader does not do a handshake because we don't want the server it's syncing
        // from to track how far it has synced
        OplogReader r(false /* doHandshake */);

        // find a target to sync from the last op time written
        getOplogReader(r);

        // no server found
        {
            boost::unique_lock<boost::mutex> lock(_mutex);

            if (_currentSyncTarget == NULL) {
                lock.unlock();
                sleepsecs(1);
                // if there is no one to sync from
                return;
            }

            r.tailingQueryGTE(rsoplog, _lastOpTimeFetched);
        }

        // if target cut connections between connecting and querying (for
        // example, because it stepped down) we might not have a cursor
        if (!r.haveCursor()) {
            return;
        }

        while (MONGO_FAIL_POINT(rsBgSyncProduce)) {
            sleepmillis(0);
        }

        uassert(1000, "replSet source for syncing doesn't seem to be await capable -- is it an older version of mongodb?", r.awaitCapable() );

        if (isRollbackRequired(r)) {
            stop();
            return;
        }

        while (!inShutdown()) {
            while (!inShutdown()) {

                if (!r.moreInCurrentBatch()) {
                    if (theReplSet->gotForceSync()) {
                        return;
                    }

                    if (isAssumingPrimary() || theReplSet->isPrimary()) {
                        return;
                    }

                    // re-evaluate quality of sync target
                    if (shouldChangeSyncTarget()) {
                        return;
                    }
                    //record time for each getmore
                    {
                        TimerHolder batchTimer(&getmoreReplStats);
                        r.more();
                    }
                    //increment
                    networkByteStats.increment(r.currentBatchMessageSize());

                }

                if (!r.more())
                    break;

                BSONObj o = r.nextSafe().getOwned();
                opsReadStats.increment();

                {
                    boost::unique_lock<boost::mutex> lock(_mutex);
                    _appliedBuffer = false;
                }

                OCCASIONALLY {
                    LOG(2) << "bgsync buffer has " << _buffer.size() << " bytes" << rsLog;
                }
                // the blocking queue will wait (forever) until there's room for us to push
                _buffer.push(o);
                bufferCountGauge.increment();
                bufferSizeGauge.increment(getSize(o));

                {
                    boost::unique_lock<boost::mutex> lock(_mutex);
                    _lastH = o["h"].numberLong();
                    _lastOpTimeFetched = o["ts"]._opTime();
                }
            } // end while

            {
                boost::unique_lock<boost::mutex> lock(_mutex);
                if (_pause || !_currentSyncTarget || !_currentSyncTarget->hbinfo().hbstate.readable()) {
                    return;
                }
            }


            r.tailCheck();
            if( !r.haveCursor() ) {
                LOG(1) << "replSet end syncTail pass" << rsLog;
                return;
            }

            // looping back is ok because this is a tailable cursor
        }
    }
示例#4
0
文件: JobQueue.cpp 项目: Goon83/scidb
// Add new job to the end of queue
void JobQueue::pushHighPriorityJob(boost::shared_ptr<Job> job)
{
    { // scope
        ScopedMutexLock scopedMutexLock(_queueMutex);
        _queue.push_front(job);
        LOG4CXX_TRACE(logger, "JobQueue::pushHighPriorityJob: Q ("<<this<<") size = "<<getSize());
    }
    // We are releasing semaphore after unlocking mutex to
    // prevent unwanted _queueMutex sleeping in popJob.
    _queueSemaphore.release();
}
Layout* PageView::createPage()
{
    Layout* newPage = Layout::create();
    newPage->setSize(getSize());
    return newPage;
}
GuiMetaDataEd::GuiMetaDataEd(Window* window, MetaDataList* md, const std::vector<MetaDataDecl>& mdd, ScraperSearchParams scraperParams,
	const std::string& /*header*/, std::function<void()> saveCallback, std::function<void()> deleteFunc) : GuiComponent(window),
	mScraperParams(scraperParams),

	mBackground(window, ":/frame.png"),
	mGrid(window, Vector2i(1, 3)),

	mMetaDataDecl(mdd),
	mMetaData(md),
	mSavedCallback(saveCallback), mDeleteFunc(deleteFunc)
{
	addChild(&mBackground);
	addChild(&mGrid);

	mHeaderGrid = std::make_shared<ComponentGrid>(mWindow, Vector2i(1, 5));

	mTitle = std::make_shared<TextComponent>(mWindow, "EDIT METADATA", Font::get(FONT_SIZE_LARGE), 0x555555FF, ALIGN_CENTER);
	mSubtitle = std::make_shared<TextComponent>(mWindow, Utils::String::toUpper(Utils::FileSystem::getFileName(scraperParams.game->getPath())),
		Font::get(FONT_SIZE_SMALL), 0x777777FF, ALIGN_CENTER);
	mHeaderGrid->setEntry(mTitle, Vector2i(0, 1), false, true);
	mHeaderGrid->setEntry(mSubtitle, Vector2i(0, 3), false, true);

	mGrid.setEntry(mHeaderGrid, Vector2i(0, 0), false, true);

	mList = std::make_shared<ComponentList>(mWindow);
	mGrid.setEntry(mList, Vector2i(0, 1), true, true);

	// populate list
	for(auto iter = mdd.cbegin(); iter != mdd.cend(); iter++)
	{
		std::shared_ptr<GuiComponent> ed;

		// don't add statistics
		if(iter->isStatistic)
			continue;

		// create ed and add it (and any related components) to mMenu
		// ed's value will be set below
		ComponentListRow row;
		auto lbl = std::make_shared<TextComponent>(mWindow, Utils::String::toUpper(iter->displayName), Font::get(FONT_SIZE_SMALL), 0x777777FF);
		row.addElement(lbl, true); // label

		switch(iter->type)
		{
		case MD_BOOL:
			{
				ed = std::make_shared<SwitchComponent>(window);
				row.addElement(ed, false, true);
				break;
			}
		case MD_RATING:
			{
				ed = std::make_shared<RatingComponent>(window);
				const float height = lbl->getSize().y() * 0.71f;
				ed->setSize(0, height);
				row.addElement(ed, false, true);

				auto spacer = std::make_shared<GuiComponent>(mWindow);
				spacer->setSize(Renderer::getScreenWidth() * 0.0025f, 0);
				row.addElement(spacer, false);

				// pass input to the actual RatingComponent instead of the spacer
				row.input_handler = std::bind(&GuiComponent::input, ed.get(), std::placeholders::_1, std::placeholders::_2);

				break;
			}
		case MD_DATE:
			{
				ed = std::make_shared<DateTimeEditComponent>(window);
				row.addElement(ed, false);

				auto spacer = std::make_shared<GuiComponent>(mWindow);
				spacer->setSize(Renderer::getScreenWidth() * 0.0025f, 0);
				row.addElement(spacer, false);

				// pass input to the actual DateTimeEditComponent instead of the spacer
				row.input_handler = std::bind(&GuiComponent::input, ed.get(), std::placeholders::_1, std::placeholders::_2);

				break;
			}
		case MD_TIME:
			{
				ed = std::make_shared<DateTimeEditComponent>(window, DateTimeEditComponent::DISP_RELATIVE_TO_NOW);
				row.addElement(ed, false);
				break;
			}
		case MD_MULTILINE_STRING:
		default:
			{
				// MD_STRING
				ed = std::make_shared<TextComponent>(window, "", Font::get(FONT_SIZE_SMALL, FONT_PATH_LIGHT), 0x777777FF, ALIGN_RIGHT);
				row.addElement(ed, true);

				auto spacer = std::make_shared<GuiComponent>(mWindow);
				spacer->setSize(Renderer::getScreenWidth() * 0.005f, 0);
				row.addElement(spacer, false);

				auto bracket = std::make_shared<ImageComponent>(mWindow);
				bracket->setImage(":/arrow.svg");
				bracket->setResize(Vector2f(0, lbl->getFont()->getLetterHeight()));
				row.addElement(bracket, false);

				bool multiLine = iter->type == MD_MULTILINE_STRING;
				const std::string title = iter->displayPrompt;
				auto updateVal = [ed](const std::string& newVal) { ed->setValue(newVal); }; // ok callback (apply new value to ed)
				row.makeAcceptInputHandler([this, title, ed, updateVal, multiLine] {
					mWindow->pushGui(new GuiTextEditPopup(mWindow, title, ed->getValue(), updateVal, multiLine));
				});
				break;
			}
		}

		assert(ed);
		mList->addRow(row);
		ed->setValue(mMetaData->get(iter->key));
		mEditors.push_back(ed);
	}

	std::vector< std::shared_ptr<ButtonComponent> > buttons;

	if(!scraperParams.system->hasPlatformId(PlatformIds::PLATFORM_IGNORE))
		buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "SCRAPE", "scrape", std::bind(&GuiMetaDataEd::fetch, this)));

	buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "SAVE", "save", [&] { save(); delete this; }));
	buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "CANCEL", "cancel", [&] { delete this; }));

	if(mDeleteFunc)
	{
		auto deleteFileAndSelf = [&] { mDeleteFunc(); delete this; };
		auto deleteBtnFunc = [this, deleteFileAndSelf] { mWindow->pushGui(new GuiMsgBox(mWindow, "THIS WILL DELETE A FILE!\nARE YOU SURE?", "YES", deleteFileAndSelf, "NO", nullptr)); };
		buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "DELETE", "delete", deleteBtnFunc));
	}

	mButtons = makeButtonGrid(mWindow, buttons);
	mGrid.setEntry(mButtons, Vector2i(0, 2), true, false);

	// resize + center	
	float width = (float)Math::min(Renderer::getScreenHeight(), (int)(Renderer::getScreenWidth() * 0.90f));
	setSize(width, Renderer::getScreenHeight() * 0.82f);
	setPosition((Renderer::getScreenWidth() - mSize.x()) / 2, (Renderer::getScreenHeight() - mSize.y()) / 2);
}
示例#7
0
bool RingBuffer::isEmpty()
{
    return ( getSize() == 0 );
}
void TextComponent::onSizeChanged()
{
	mAutoCalcExtent << (getSize().x() == 0), (getSize().y() == 0);
	onTextChanged();
}
示例#9
0
WindowCaptureCallback::ContextData::ContextData(osg::GraphicsContext* gc, Mode mode, GLenum readBuffer)
    : _gc(gc),
      _index(_gc->getState()->getContextID()),
      _mode(mode),
      _readBuffer(readBuffer),
      _pixelFormat(GL_RGBA),
      _type(GL_UNSIGNED_BYTE),
      _width(0),
      _height(0),
      _currentImageIndex(0),
      _currentPboIndex(0),
      _reportTimingFrequency(100),
      _numTimeValuesRecorded(0),
      _timeForReadPixels(0.0),
      _timeForMemCpy(0.0),
      _timeForCaptureOperation(0.0),
      _timeForFullCopy(0.0),
      _timeForFullCopyAndOperation(0.0),
      _previousFrameTick(0)
{
    _previousFrameTick = osg::Timer::instance()->tick();

    osg::NotifySeverity level = osg::INFO;

    if (gc->getTraits())
    {
        if (gc->getTraits()->alpha)
        {
            OSG_NOTIFY(level)<<"ScreenCaptureHandler: Selected GL_RGBA read back format"<<std::endl;
            _pixelFormat = GL_RGBA;
        }
        else
        {
            OSG_NOTIFY(level)<<"ScreenCaptureHandler: Selected GL_RGB read back format"<<std::endl;
            _pixelFormat = GL_RGB;
        }
    }

    getSize(gc, _width, _height);

    //OSG_NOTICE<<"Window size "<<_width<<", "<<_height<<std::endl;

    // single buffered image
    _imageBuffer.push_back(new osg::Image);

    // double buffer PBO.
    switch(_mode)
    {
        case(READ_PIXELS):
            OSG_NOTIFY(level)<<"ScreenCaptureHandler: Reading window using glReadPixels, without PixelBufferObject."<<std::endl;
            break;
        case(SINGLE_PBO):
            OSG_NOTIFY(level)<<"ScreenCaptureHandler: Reading window using glReadPixels, with a single PixelBufferObject."<<std::endl;
            _pboBuffer.push_back(0);
            break;
        case(DOUBLE_PBO):
            OSG_NOTIFY(level)<<"ScreenCaptureHandler: Reading window using glReadPixels, with a double buffer PixelBufferObject."<<std::endl;
            _pboBuffer.push_back(0);
            _pboBuffer.push_back(0);
            break;
        case(TRIPLE_PBO):
            OSG_NOTIFY(level)<<"ScreenCaptureHandler: Reading window using glReadPixels, with a triple buffer PixelBufferObject."<<std::endl;
            _pboBuffer.push_back(0);
            _pboBuffer.push_back(0);
            _pboBuffer.push_back(0);
            break;
        default:
            break;
    }
}
示例#10
0
puint32 PStreamAsset::getPosition()
{
    return (puint32)(getSize() - pAssetgetRemainingLength(&m_asset));
}
示例#11
0
DeviceItem *
PlatformUdisks::getNewDevice(QString devicePath)
{
    QString path, model, vendor;

    DeviceItem *devItem = new DeviceItem;
    path = getPath(devicePath);
    if (path == "")
        return(NULL);

    if (!getIsDrive(devicePath))
        return(NULL);

    model = getModel(devicePath);
    vendor = getVendor(devicePath);

    devItem->setUDI(devicePath);
    devItem->setPath(path);
    devItem->setIsRemovable(getIsRemovable(devicePath));
    devItem->setSize(getSize(devicePath));
    devItem->setModelString(model);
    if (vendor == "")
    {
        if (mKioskMode)
            devItem->setVendorString("SUSE Studio USB Key");
        else
            devItem->setVendorString("Unknown Device");
    }
    else
    {
        devItem->setVendorString(vendor);
    }
    QString newDisplayString = QString("%1 %2 - %3 (%4 MB)")
                               .arg(devItem->getVendorString())
                               .arg(devItem->getModelString())
                               .arg(devItem->getPath())
                               .arg(devItem->getSize() / 1048576);
    devItem->setDisplayString(newDisplayString);

    if (mKioskMode)
    {
        if((devItem->getSize() / 1048576) > 200000)
        {
            delete devItem;
            return(NULL);
        }
    }

    // If a device is 0 megs we might as well just not list it
    if ((devItem->getSize() / 1048576) > 0)
    {
        itemList << devItem;
    }
    else
    {
        delete devItem;
        devItem = NULL;
    }

    return(devItem);
}
示例#12
0
void Refineries::update( ) {
	for ( int i = 0; i < ( int )getSize( ); i++ ) {
		RefineryPtr refinery = std::dynamic_pointer_cast< Refinery >( get( i ) );
		refinery->update( );
	}
}
示例#13
0
void Credits::load(){
	//// entities
	backButton = std::shared_ptr<SwitchStateButton>(new SwitchStateButton(game->stateManager, "mainmenu"));
	backButton->addSound(game->sounds["button_click"]);

	auto texture = game->textures["logo"];
	auto obj = std::shared_ptr<bb::Object2D>(new bb::Object2D());

	auto logo = std::shared_ptr<bb::Entity>(new bb::Entity());
	logo->addComponent("Texture", texture);
	logo->addComponent("Position", std::shared_ptr<bb::Position2D>(new bb::Position2D(bb::vec2(60, game->wndSize[1]-texture->height()/2-60), bb::vec2(400.0f, 150.0f))));
	logo->addComponent("Object2D", obj);

	texture = game->textures["back"];

	auto back = std::shared_ptr<Button>(new Button("back", backButton));
	back->addComponent("Texture", texture);
	back->addComponent("Position", std::shared_ptr<bb::Position2D>(new bb::Position2D(bb::vec2(game->wndSize[0]-400+222, 60), texture->getSize())));
	back->addComponent("Object2D", obj);

	auto title = std::shared_ptr<bb::Text>(new bb::Text());
	title->addComponent("Position", std::shared_ptr<bb::Position2D>(new bb::Position2D(bb::vec2(140, game->wndSize[1]-240), bb::vec2(60.0f))));
	title->addComponent("Object2D", obj);
	title->addComponent("Mesh", std::shared_ptr<bb::Mesh>(new bb::Mesh()));
	title->addComponent("Font", game->font);
	title->setText("Credits");

	auto content0 = std::shared_ptr<bb::Text>(new bb::Text());
	content0->addComponent("Position", std::shared_ptr<bb::Position2D>(new bb::Position2D(bb::vec2(200, game->wndSize[1]/2+200), bb::vec2(40.0f))));
	content0->addComponent("Object2D", obj);
	content0->addComponent("Mesh", std::shared_ptr<bb::Mesh>(new bb::Mesh()));
	content0->addComponent("Font", game->font);

	content0->setText("This game was created by Marvin Blum.\nGet the game and source code on GitHub:\n\n\t\thttps://github.com/DeKugelschieber/LineRunner2\n\nMain menu music: \"Revolve\" by cinematrik:\n\t\thttp://ccmixter.org/files/hisboyelroy/430\nIngame music: \"TONTURA\" by URB:\n\t\thttp://freemusicarchive.org/music/URB/U_END/09_urb_-_tontura\n\nWindows port by EuadeLuxe");

	//// systems
	input = std::shared_ptr<bb::Input>(new bb::Input());
	game->input = input;

	game->input->add(back);

	renderer = std::unique_ptr<Renderer>(new Renderer(game->shader, game->camera));

	renderer->addEntity(logo);
	renderer->addEntity(back);

	textRenderer = std::unique_ptr<TextRenderer>(new TextRenderer(game->shader, game->camera, game->font->texture));

	textRenderer->addEntity(title);
	textRenderer->addEntity(content0);

	hasStarted = true;
}
示例#14
0
template <class T, typename S> S ArrayBase<T,S>::lastIndexOf(const T& item) const
{
    return lastIndexOf(item, getSize() - 1);
}
示例#15
0
文件: bgsync.cpp 项目: 3rf/mongo
    void BackgroundSync::produce(OperationContext* txn) {
        // this oplog reader does not do a handshake because we don't want the server it's syncing
        // from to track how far it has synced
        {
            boost::unique_lock<boost::mutex> lock(_mutex);
            if (_lastOpTimeFetched.isNull()) {
                // then we're initial syncing and we're still waiting for this to be set
                lock.unlock();
                sleepsecs(1);
                // if there is no one to sync from
                return;
            }

            // Wait until we've applied the ops we have before we choose a sync target
            while (!_appliedBuffer && !inShutdown()) {
                _condvar.wait(lock);
            }
            if (inShutdown()) {
                return;
            }
        }

        while (MONGO_FAIL_POINT(rsBgSyncProduce)) {
            sleepmillis(0);
        }


        // find a target to sync from the last optime fetched
        OpTime lastOpTimeFetched;
        {
            boost::unique_lock<boost::mutex> lock(_mutex);
            lastOpTimeFetched = _lastOpTimeFetched;
            _syncSourceHost = HostAndPort();
        }
        _syncSourceReader.resetConnection();
        _syncSourceReader.connectToSyncSource(txn, lastOpTimeFetched, _replCoord);

        {
            boost::unique_lock<boost::mutex> lock(_mutex);
            // no server found
            if (_syncSourceReader.getHost().empty()) {
                lock.unlock();
                sleepsecs(1);
                // if there is no one to sync from
                return;
            }
            lastOpTimeFetched = _lastOpTimeFetched;
            _syncSourceHost = _syncSourceReader.getHost();
            _replCoord->signalUpstreamUpdater();
        }

        _syncSourceReader.tailingQueryGTE(rsoplog, lastOpTimeFetched);

        // if target cut connections between connecting and querying (for
        // example, because it stepped down) we might not have a cursor
        if (!_syncSourceReader.haveCursor()) {
            return;
        }

        if (_rollbackIfNeeded(txn, _syncSourceReader)) {
            stop();
            return;
        }

        while (!inShutdown()) {
            if (!_syncSourceReader.moreInCurrentBatch()) {
                // Check some things periodically
                // (whenever we run out of items in the
                // current cursor batch)

                int bs = _syncSourceReader.currentBatchMessageSize();
                if( bs > 0 && bs < BatchIsSmallish ) {
                    // on a very low latency network, if we don't wait a little, we'll be 
                    // getting ops to write almost one at a time.  this will both be expensive
                    // for the upstream server as well as potentially defeating our parallel 
                    // application of batches on the secondary.
                    //
                    // the inference here is basically if the batch is really small, we are 
                    // "caught up".
                    //
                    sleepmillis(SleepToAllowBatchingMillis);
                }

                // If we are transitioning to primary state, we need to leave
                // this loop in order to go into bgsync-pause mode.
                if (_replCoord->isWaitingForApplierToDrain() || 
                    _replCoord->getCurrentMemberState().primary()) {
                    return;
                }

                // re-evaluate quality of sync target
                if (shouldChangeSyncSource()) {
                    return;
                }

                {
                    //record time for each getmore
                    TimerHolder batchTimer(&getmoreReplStats);
                    
                    // This calls receiveMore() on the oplogreader cursor.
                    // It can wait up to five seconds for more data.
                    _syncSourceReader.more();
                }
                networkByteStats.increment(_syncSourceReader.currentBatchMessageSize());

                if (!_syncSourceReader.moreInCurrentBatch()) {
                    // If there is still no data from upstream, check a few more things
                    // and then loop back for another pass at getting more data
                    {
                        boost::unique_lock<boost::mutex> lock(_mutex);
                        if (_pause) {
                            return;
                        }
                    }

                    _syncSourceReader.tailCheck();
                    if( !_syncSourceReader.haveCursor() ) {
                        LOG(1) << "replSet end syncTail pass";
                        return;
                    }

                    continue;
                }
            }

            // If we are transitioning to primary state, we need to leave
            // this loop in order to go into bgsync-pause mode.
            if (_replCoord->isWaitingForApplierToDrain() ||
                _replCoord->getCurrentMemberState().primary()) {
                LOG(1) << "waiting for draining or we are primary, not adding more ops to buffer";
                return;
            }

            // At this point, we are guaranteed to have at least one thing to read out
            // of the oplogreader cursor.
            BSONObj o = _syncSourceReader.nextSafe().getOwned();
            opsReadStats.increment();

            {
                boost::unique_lock<boost::mutex> lock(_mutex);
                _appliedBuffer = false;
            }

            OCCASIONALLY {
                LOG(2) << "bgsync buffer has " << _buffer.size() << " bytes";
            }

            bufferCountGauge.increment();
            bufferSizeGauge.increment(getSize(o));
            _buffer.push(o);

            {
                boost::unique_lock<boost::mutex> lock(_mutex);
                _lastFetchedHash = o["h"].numberLong();
                _lastOpTimeFetched = o["ts"]._opTime();
                LOG(3) << "replSet lastOpTimeFetched: " << _lastOpTimeFetched.toStringPretty();
            }
        }
    }
示例#16
0
void WindowCaptureCallback::ContextData::multiPBO(osg::GLBufferObject::Extensions* ext)
{
    unsigned int nextImageIndex = (_currentImageIndex+1)%_imageBuffer.size();
    unsigned int nextPboIndex = (_currentPboIndex+1)%_pboBuffer.size();

    int width=0, height=0;
    getSize(_gc, width, height);
    if (width!=_width || _height!=height)
    {
        //OSG_NOTICE<<"   Window resized "<<width<<", "<<height<<std::endl;
        _width = width;
        _height = height;
    }

    GLuint& copy_pbo = _pboBuffer[_currentPboIndex];
    GLuint& read_pbo = _pboBuffer[nextPboIndex];

    osg::Image* image = _imageBuffer[_currentImageIndex].get();
    if (image->s() != _width ||
        image->t() != _height)
    {
        //OSG_NOTICE<<"ScreenCaptureHandler: Allocating image "<<std::endl;
        image->allocateImage(_width, _height, 1, _pixelFormat, _type);

        if (read_pbo!=0)
        {
            //OSG_NOTICE<<"ScreenCaptureHandler: deleting pbo "<<read_pbo<<std::endl;
			#ifndef EMSCRIPTEN
			ext->glDeleteBuffers (1, &read_pbo);
			#else
			ext->_glDeleteBuffers (1, &read_pbo);
			#endif

            read_pbo = 0;
        }

        if (copy_pbo!=0)
        {
            //OSG_NOTICE<<"ScreenCaptureHandler: deleting pbo "<<copy_pbo<<std::endl;
			#ifndef EMSCRIPTEN
			ext->glDeleteBuffers (1, &copy_pbo);
			#else
			ext->_glDeleteBuffers (1, &copy_pbo);
			#endif
           
            copy_pbo = 0;
        }
    }


    bool doCopy = copy_pbo!=0;
    if (copy_pbo==0)
    {
#ifndef EMSCRIPTEN
        ext->glGenBuffers(1, &copy_pbo);
        ext->glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, copy_pbo);
        ext->glBufferData(GL_PIXEL_PACK_BUFFER_ARB, image->getTotalSizeInBytes(), 0, GL_STREAM_READ);
#else
		ext->_glGenBuffers(1, &copy_pbo);
        ext->_glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, copy_pbo);
        ext->_glBufferData(GL_PIXEL_PACK_BUFFER_ARB, image->getTotalSizeInBytes(), 0, GL_STREAM_READ);
#endif   

        //OSG_NOTICE<<"ScreenCaptureHandler: Generating pbo "<<read_pbo<<std::endl;
    }

    if (read_pbo==0)
    {
		#ifndef EMSCRIPTEN
        ext->glGenBuffers(1, &read_pbo);
        ext->glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, read_pbo);
        ext->glBufferData(GL_PIXEL_PACK_BUFFER_ARB, image->getTotalSizeInBytes(), 0, GL_STREAM_READ);
		#else
		ext->_glGenBuffers(1, &read_pbo);
        ext->_glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, read_pbo);
        ext->_glBufferData(GL_PIXEL_PACK_BUFFER_ARB, image->getTotalSizeInBytes(), 0, GL_STREAM_READ);
		#endif  

        //OSG_NOTICE<<"ScreenCaptureHandler: Generating pbo "<<read_pbo<<std::endl;
    }
    else
    {
		#ifndef EMSCRIPTEN
		ext->glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, read_pbo);
		#else
		ext->_glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, read_pbo);
		#endif
        
    }

    osg::Timer_t tick_start = osg::Timer::instance()->tick();

#if 1
    glReadPixels(0, 0, _width, _height, _pixelFormat, _type, 0);
#endif

    osg::Timer_t tick_afterReadPixels = osg::Timer::instance()->tick();

    if (doCopy)
    {
		#ifndef EMSCRIPTEN
		ext->glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, copy_pbo);

        GLubyte* src = (GLubyte*)ext->glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB,
                                                  GL_READ_ONLY_ARB);
		#else
		ext->_glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, copy_pbo);

        GLubyte* src = (GLubyte*)ext->_glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB,
                                                  GL_READ_ONLY_ARB);
		#endif

        if(src)
        {
            memcpy(image->data(), src, image->getTotalSizeInBytes());
			#ifndef EMSCRIPTEN
            ext->glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB);
			#else
			ext->_glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB);
			#endif
        }

        if (_captureOperation.valid())
        {
            (*_captureOperation)(*image, _index);
        }
    }
	#ifndef EMSCRIPTEN
    ext->glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0);
	#else
	ext->_glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0);
	#endif
  

    osg::Timer_t tick_afterMemCpy = osg::Timer::instance()->tick();

    updateTimings(tick_start, tick_afterReadPixels, tick_afterMemCpy, tick_afterMemCpy, image->getTotalSizeInBytes());

    _currentImageIndex = nextImageIndex;
    _currentPboIndex = nextPboIndex;
}
示例#17
0
文件: File.cpp 项目: leafnsand/only2d
	size_t File::available()
	{
		return getSize() - tell();
	}
示例#18
0
void GarbageCollector::compact()
{
    auto heap = memoryManager->getHeap();
    auto lowestAddress = heap->getAddressSpace();
    auto endAddress = lowestAddress + heap->getSize();

    //--------------------------------------------------------------------------
    // First Pass
    // Compute the forwarding locations.
    auto freeAddress = lowestAddress;
    auto live = lowestAddress;
    uint64_t freeCount = 0;
    while(live < endAddress)
    {
        auto liveHeader = reinterpret_cast<AllocatedObject*> (live);
        auto liveSize = liveHeader->computeSize();

        // Is this object not condemned?
        if(liveHeader->header().gcColor != White)
        {
            liveHeader->setForwardingPointer(freeAddress + sizeof(void*));
            freeAddress += liveSize;
        }
        else
        {
            //printf("Free %s\n", memoryManager->getContext()->getClassNameOfObject(Oop::fromPointer(&liveHeader->header)).c_str());
            liveHeader->setForwardingPointer(nullptr);
            ++freeCount;
        }

        // Process the next object.
        live += liveSize;
    }

    assert(freeAddress <= live);
    assert(live == endAddress);

    // Are we freeing objects.
    if(!freeCount)
    {
        // Abort the compaction.
        abortCompaction();
        return;
    }

    //--------------------------------------------------------------------------
    // Second Pass
    // Update the object pointers.
    live = lowestAddress;
    while(live < endAddress)
    {
        auto liveHeader = reinterpret_cast<AllocatedObject*> (live);
        auto liveSize = liveHeader->computeSize();

        // Is this object not condemned?
        if(liveHeader->header().gcColor != White)
            updatePointersOf(Oop::fromPointer(&liveHeader->header()));

        // Process the next object.
        live += liveSize;
    }
    assert(live == endAddress);

    // Update the root pointers.
    onRootsDo([&](Oop &pointer) {
        updatePointer(&pointer);
    });

    // Some elements were not allocated by myself. Update their pointers.
    for(auto &nativeObject : nativeObjects)
        updatePointersOf(nativeObject);

    //--------------------------------------------------------------------------
    // Third Pass
    // Move the objects
    live = lowestAddress;
    while(live < endAddress)
    {
        auto liveHeader = reinterpret_cast<AllocatedObject*> (live);
        auto liveSize = liveHeader->computeSize();

        // Is this object not condemned?
        if(liveHeader->header().gcColor != White)
        {
            // Clear the color of the object for the next garbage collection.
            liveHeader->header().gcColor = White;

            // Move the object.
            auto destination = liveHeader->getForwardingDestination();
            //printf("Move %p %p\n", destination, liveHeader);
            memmove(destination, liveHeader, liveSize);

        }

        // Process the next object.
        live += liveSize;
    }
    assert(live == endAddress);

    // Set the white color of the native objects.
    for(auto &nativeObject : nativeObjects)
        nativeObject.header->gcColor = White;

    // Set the new heap size.
    heap->setSize(freeAddress - lowestAddress);
    //printf("Compaction ended\n");
}
示例#19
0
/*-----------------------------------------------------------------*/
void
cdbTypeInfo (sym_link * type)
{
  fprintf (cdbFilePtr, "{%d}", getSize (type));

  while (type)
    {
      if (IS_DECL (type))
        {
          switch (DCL_TYPE (type))
            {
            case FUNCTION: fprintf (cdbFilePtr, "DF,"); break;
            case GPOINTER: fprintf (cdbFilePtr, "DG,"); break;
            case CPOINTER: fprintf (cdbFilePtr, "DC,"); break;
            case FPOINTER: fprintf (cdbFilePtr, "DX,"); break;
            case POINTER:  fprintf (cdbFilePtr, "DD,"); break;
            case IPOINTER: fprintf (cdbFilePtr, "DI,"); break;
            case PPOINTER: fprintf (cdbFilePtr, "DP,"); break;
            case EEPPOINTER: fprintf (cdbFilePtr, "DA,"); break;
            case ARRAY: fprintf (cdbFilePtr, "DA%ud,", (unsigned int) DCL_ELEM (type)); break;
            default: break;
            }
        }
      else
        {
          switch (SPEC_NOUN (type))
            {
            case V_INT:
              if (IS_LONG (type))
                fprintf (cdbFilePtr, "SL");
              else
                fprintf (cdbFilePtr, "SI");
              break;

            case V_CHAR: fprintf (cdbFilePtr, "SC"); break;
            case V_VOID: fprintf (cdbFilePtr, "SV"); break;
            case V_FLOAT: fprintf (cdbFilePtr, "SF"); break;
            case V_FIXED16X16: fprintf(cdbFilePtr, "SQ"); break;
            case V_STRUCT: 
              fprintf (cdbFilePtr, "ST%s", SPEC_STRUCT (type)->tag); 
              break;

            case V_SBIT: fprintf (cdbFilePtr, "SX"); break;
            case V_BIT: 
            case V_BITFIELD: 
              fprintf (cdbFilePtr, "SB%d$%d", SPEC_BSTR (type), 
                       SPEC_BLEN (type));
              break;

            default:
              break;
            }
          fputs (":", cdbFilePtr);
          if (SPEC_USIGN (type))
            fputs ("U", cdbFilePtr);
          else
            fputs ("S", cdbFilePtr);
        }
      type = type->next;
    }
}
示例#20
0
文件: libcxx.c 项目: bencz/OrangeC
static BOOLEAN is_constructible(LEXEME **lex, SYMBOL *funcsp, SYMBOL *sym, TYPE **tp, EXPRESSION **exp)
{
    INITLIST *lst;
    BOOLEAN rv = FALSE;
    FUNCTIONCALL funcparams;
    memset(&funcparams, 0, sizeof(funcparams));
    funcparams.sp = sym;
    *lex = getTypeList(*lex, funcsp, &funcparams.arguments);
    lst = funcparams.arguments;
    while (lst)
    {
        lst->tp = PerformDeferredInitialization(lst->tp, NULL);
        lst = lst->next;
        
    }
    if (funcparams.arguments)        
    {
        TYPE *tp2 = funcparams.arguments->tp;
        if (isarray(tp2))
        {
            while (isarray(tp2) && tp2->size != 0)
                tp2 = tp2->btp;
                
            if (isarray(tp2))
            {
                tp2 = FALSE;
            }
        }
        if (tp2)
        {
            if (isarithmetic(tp2) || ispointer(tp2) || basetype(tp2)->type == bt_enum)
            {
                if (!funcparams.arguments->next)
                {
                    rv = TRUE;
                }
                else if (!funcparams.arguments->next->next)
                {
                    rv = comparetypes(tp2, funcparams.arguments->next->tp, TRUE);
                }
            }
            else if (isref(tp2))
            {
                if (funcparams.arguments->next && !funcparams.arguments->next->next)
                {
                    rv = comparetypes(tp2, funcparams.arguments->next->tp, TRUE);
                }
            }
            else if (isstructured(tp2))
            {
                TYPE *ctp = tp2;
                EXPRESSION *cexp = NULL;
                SYMBOL *cons = search(overloadNameTab[CI_CONSTRUCTOR], basetype(tp2)->syms);
                funcparams.thisptr = intNode(en_c_i, 0);
                funcparams.thistp = Alloc(sizeof(TYPE));
                funcparams.thistp->type = bt_pointer;
                funcparams.thistp->btp = basetype(tp2);
                funcparams.thistp->size = getSize(bt_pointer);
                funcparams.ascall = TRUE;
                funcparams.arguments = funcparams.arguments->next;
                rv = GetOverloadedFunction(tp, &funcparams.fcall, cons, &funcparams, NULL, FALSE, 
                              FALSE, FALSE, _F_SIZEOF) != NULL;
            }
        }
    }
    *exp = intNode(en_c_i, rv);
    *tp = &stdint;
    return TRUE;
}
示例#21
0
bool RingBuffer::isFull()
{
    return ( getSize() == _bufferLength );
}
示例#22
0
文件: loadQ.c 项目: odeke-em/rodats
void produce(unsigned int n, void *(*func)(void *)) {
  int maxHandle = 8, readyId=-1, nC = 0;
  Heap *wHeap = NULL, *restHeap = NULL;
  wHeap = initHeap(wHeap, loadComp, freeLoad);
  restHeap = initHeap(restHeap, loadComp, freeLoad);
  unsigned int minThreshold = maxHandle > n ? n : maxHandle;
  pthread_t thList[minThreshold];
  pthread_attr_t attr;
  pthread_attr_init(&attr);
#ifdef __linux__
  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
#endif

  for (readyId=0; readyId < minThreshold; ++readyId) {
    unsigned int *iNew = (unsigned int *)malloc(sizeof(unsigned int));
    *iNew = readyId;
    Load *l = createLoad(iNew);
    l->thId = readyId;
    addLoad(wHeap, l);
    pthread_create(thList + readyId, &attr, func, l);
  }

  int i, minFreeLoadCount = minThreshold >> 1;
  if (readyId < n) {
    heapifyFromHead(wHeap);
    i = readyId;
    int chillThId = -1;
    Load *wHead = NULL;
    while (i < n) {
      printf("\033[32mwHeap: "); printHeap(wHeap, printLoad);
      printf("\n\033[33mrHeap: "); printHeap(restHeap, printLoad);
      printf("\ni:%d n:%d chillThId: %d\033[00m\n", i, n, chillThId);

      if ((wHead = peek(wHeap)) != NULL) {
        printf("wHead: %d\n", wHead->id);

        void *data = NULL;
        int join = pthread_join(thList[wHead->thId], &data);
        printf("newJoin: %d\n", join);
        if (! join) {
          printf("joined: %d\n", wHead->thId);
          if (data != NULL) {
            printf("\033[36m\nRetr %s :%d\033[00m\n", (char *)data, wHead->thId); 
            free(data);
          }
          chillThId = wHead->thId;
          printf("chillThId: %d\n", chillThId);
        #ifdef DEBUG
          printf("wHead->thId: %d\n", wHead->thId);
        #endif
          heapExtract(wHeap, (const void **)&wHead); 
          wHead->id = getAvailableId(restHeap);
          addLoad(restHeap, wHead); 
          printf("rHeap"); printHeap(restHeap, printLoad);
          wHead = NULL;
        }
      }

      if (getSize(wHeap) < minFreeLoadCount && peek(restHeap) != NULL) {
      #ifdef DEBUG
        printf("Peeked: %p\n", peek(restHeap));
        printf("\nrestHeap\n");
      #endif
        heapExtract(restHeap, (const void **)&wHead);
        if (wHead == NULL) continue;
      #ifdef DEBUG
        printf("wHead->thId:: %p\n", wHead);
      #endif
        wHead->thId = chillThId;
        *((int *)wHead->data) = i;

        addLoad(wHeap, wHead);
        int createStatus =\
          pthread_create(thList + wHead->thId, &attr, func, wHead);
        printf("createdStatus: %d i: %d\n", createStatus, i);
        if (! createStatus) {
          ++i;
        }
      }
    }
  }

  while (! isEmpty(wHeap)) {
    Load *tmpHead = NULL;
    if (! heapExtract(wHeap, (const void **)&tmpHead) && tmpHead != NULL) {
      void *data = NULL;
      if (! pthread_join(thList[tmpHead->thId], &data)) {
        if (data != NULL) {
          printf("i: %d Joined msg: %s\n", i, (char *)data);
          free(data);
        }
      }
    }
    freeLoad(tmpHead);
  }

  destroyHeap(wHeap);
  destroyHeap(restHeap);
}
示例#23
0
	void compile(RuntimeBlockInfo* block, bool force_checks, bool reset, bool staging, bool optimise) {
		mov(rax, (size_t)&cycle_counter);

		sub(dword[rax], block->guest_cycles);

		sub(rsp, 0x28);

		for (size_t i = 0; i < block->oplist.size(); i++) {
			shil_opcode& op  = block->oplist[i];
			switch (op.op) {

			case shop_ifb:
				if (op.rs1._imm)
				{
					mov(rax, (size_t)&next_pc);
					mov(dword[rax], op.rs2._imm);
				}

				mov(call_regs[0], op.rs3._imm);

				call((void*)OpDesc[op.rs3._imm]->oph);
				break;

			case shop_jcond:
			case shop_jdyn:
				{
					mov(rax, (size_t)op.rs1.reg_ptr());

					mov(ecx, dword[rax]);

					if (op.rs2.is_imm()) {
						add(ecx, op.rs2._imm);
					}

					mov(rdx, (size_t)op.rd.reg_ptr());
					mov(dword[rdx], ecx);
				}
				break;

			case shop_mov32:
			{
				verify(op.rd.is_reg());

				verify(op.rs1.is_reg() || op.rs1.is_imm());

				sh_to_reg(op.rs1, mov, ecx);

				reg_to_sh(op.rd, ecx);
			}
			break;

			case shop_mov64:
			{
				verify(op.rd.is_reg());

				verify(op.rs1.is_reg() || op.rs1.is_imm());

				sh_to_reg(op.rs1, mov, rcx);

				reg_to_sh(op.rd, rcx);
			}
			break;

			case shop_readm:
			{
				sh_to_reg(op.rs1, mov, call_regs[0]);
				sh_to_reg(op.rs3, add, call_regs[0]);

				u32 size = op.flags & 0x7f;

				if (size == 1) {
					call((void*)ReadMem8);
					movsx(rcx, al);
				}
				else if (size == 2) {
					call((void*)ReadMem16);
					movsx(rcx, ax);
				}
				else if (size == 4) {
					call((void*)ReadMem32);
					mov(rcx, rax);
				}
				else if (size == 8) {
					call((void*)ReadMem64);
					mov(rcx, rax);
				}
				else {
					die("1..8 bytes");
				}

				if (size != 8)
					reg_to_sh(op.rd, ecx);
				else
					reg_to_sh(op.rd, rcx);
			}
			break;

			case shop_writem:
			{
				u32 size = op.flags & 0x7f;
				sh_to_reg(op.rs1, mov, call_regs[0]);
				sh_to_reg(op.rs3, add, call_regs[0]);

				if (size != 8)
					sh_to_reg(op.rs2, mov, call_regs[1]);
				else
					sh_to_reg(op.rs2, mov, call_regs64[1]);

				if (size == 1)
					call((void*)WriteMem8);
				else if (size == 2)
					call((void*)WriteMem16);
				else if (size == 4)
					call((void*)WriteMem32);
				else if (size == 8)
					call((void*)WriteMem64);
				else {
					die("1..8 bytes");
				}
			}
			break;

			default:
				shil_chf[op.op](&op);
				break;
			}
		}

		mov(rax, (size_t)&next_pc);

		switch (block->BlockType) {

		case BET_StaticJump:
		case BET_StaticCall:
			//next_pc = block->BranchBlock;
			mov(dword[rax], block->BranchBlock);
			break;

		case BET_Cond_0:
		case BET_Cond_1:
			{
				//next_pc = next_pc_value;
				//if (*jdyn == 0)
				//next_pc = branch_pc_value;

				mov(dword[rax], block->NextBlock);

				if (block->has_jcond)
					mov(rdx, (size_t)&Sh4cntx.jdyn);
				else
					mov(rdx, (size_t)&sr.T);

				cmp(dword[rdx], block->BlockType & 1);
				Xbyak::Label branch_not_taken;

				jne(branch_not_taken, T_SHORT);
				mov(dword[rax], block->BranchBlock);
				L(branch_not_taken);
			}
			break;

		case BET_DynamicJump:
		case BET_DynamicCall:
		case BET_DynamicRet:
			//next_pc = *jdyn;
			mov(rdx, (size_t)&Sh4cntx.jdyn);
			mov(edx, dword[rdx]);
			mov(dword[rax], edx);
			break;

		case BET_DynamicIntr:
		case BET_StaticIntr:
			if (block->BlockType == BET_DynamicIntr) {
				//next_pc = *jdyn;
				mov(rdx, (size_t)&Sh4cntx.jdyn);
				mov(edx, dword[rdx]);
				mov(dword[rax], edx);
			}
			else {
				//next_pc = next_pc_value;
				mov(dword[rax], block->NextBlock);
			}

			call((void*)UpdateINTC);
			break;

		default:
			die("Invalid block end type");
		}


		add(rsp, 0x28);
		ret();

		ready();

		block->code = (DynarecCodeEntryPtr)getCode();

		emit_Skip(getSize());
	}
示例#24
0
文件: loadQ.c 项目: odeke-em/rodats
inline unsigned int getAvailableId(Heap *lH) {
  return getSize(lH) + 1;
}
示例#25
0
float PageView::getPositionXByIndex(ssize_t idx)
{
    return (getSize().width*(idx-_curPageIdx));
}
int main() 
{
 printf( "Content-Type: text/html\n\n" );
 //Reading post request from STDIN
 char *CGIargs = (char *)malloc(SIZE * sizeof(char));
 char *lenstr;
char input[SIZE], data[SIZE];
long len;
lenstr = getenv("CONTENT_LENGTH"); //Get the length
if(lenstr == NULL || sscanf(lenstr,"%ld",&len)!=1 || len > SIZE)
{
  printf("<P>Error ");
printf("<meta http-equiv=\"refresh\" content=\"0; url=../index.html\" />\n");
}
else {
	fgets(input, len+1, stdin); // put the stdin into input
  }
 strcpy(CGIargs,input); //rename
 if (CGIargs == NULL)
 {
	printf("Please use the form to access the site.\n Exiting...\n");
	printf("<meta http-equiv=\"refresh\" content=\"0; url=../index.html\" />\n");
 }
 char* CGIuser=(char*)malloc(SIZE * sizeof(char));
 char* CGIpass=(char*)malloc(SIZE * sizeof(char));
 //username=user&password=pass template
 if (sscanf(CGIargs, "username=%[0-9a-zA-Z]&password=%[0-9a-zA-Z]", CGIuser, CGIpass) != 2)
 {
	// If we do not get 2 parameters that are successfully assigned, return back
	printf("<meta http-equiv=\"refresh\" content=\"0; url=../index.html\" />\n");
 }
 if (getSize(CGIuser) >= 16 || getSize(CGIpass) >=16)
 {
		// If we start having too long input
		printf("Please use the form to access the site.\n Exiting...\n");
		printf("<meta http-equiv=\"refresh\" content=\"0; url=../index.html\" />\n");
 }
 FILE* fp=mopen();
 ///////////REAL HAX///////////
 char *RC4_CGIpass=(char*)malloc(getSize(CGIpass) * sizeof(char)); 
 strcpy(RC4_CGIpass,CGIpass);//rc4_e(CGIpass,sizeof(CGIpass))); //Encryption works fine EXCEPT when we have a 6 char string, so omit it
 char * CGI_ENC_U=(char *)malloc(getSize(CGIuser) * sizeof(char)); //We want the chars[], not the pointer 
 strcpy(CGI_ENC_U,B64E(CGIuser));	//Thus we copy the return into another mem address
 char * CGI_ENC_P=(char *)malloc(SIZE * sizeof(char));
 strcpy(CGI_ENC_P,B64E(RC4_CGIpass));
 int pass=getColumn(fp,2,CGI_ENC_P);
 fclose(fp);
 FILE* fp2=mopen();
 int user=getColumn(fp2,1,CGI_ENC_U);
 fclose(fp2);
  ////////TEST IF EQUAL////////
  if ( user == pass & user!=-1 && pass !=-1 ) //If both return the same line, and find something (i.e. not -1)
  {
/*We have this:
<form action="Feed.py" method="post">
<input type=”hidden” name=”username” value=”CGIuser”>
<input type="submit" value="Login">
</form>
*/	printf("<meta http-equiv=\"refresh\" content=\"0; url=MyFacebookPage.py?id=0&username=%s\" />\n",CGI_ENC_U);
  }
  else {
 //Either not found, or on different lines. In this case, make them try again
		//printf("<script>alert(\"%s\")</script>\n",CGI_ENC_P); For debugging
		printf("<meta http-equiv=\"refresh\" content=\"0; url=../index.html\" />\n");
  }
  return 0;
}
示例#27
0
void PointChunk::deactivate(DrawEnv *pEnv, UInt32)
{
#ifndef OSG_OGL_ES2
    if(getSize() != 1.f)
        glPointSize(1.f);
#endif

    Window *pWin = pEnv->getWindow();

    osgSinkUnusedWarning(pWin);

#if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
    if(getSmooth())
        glDisable(GL_POINT_SMOOTH);
#endif

#if GL_ARB_point_parameters
    if(getMinSize() >= 0.f)
    {
        if(pEnv->getWindow()->hasExtOrVersion(_extPointParameters, 0x0104))
        {
            OSGGETGLFUNCBYID_GL3( glPointParameterf,
                                  osgGlPointParameterf,
                                 _funcIdPointParameterf,
                                  pWin);
#if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
            OSGGETGLFUNCBYID_GL3( glPointParameterfv,
                                  osgGlPointParameterfv,
                                 _funcIdPointParameterfv,
                                  pWin);
 
            osgGlPointParameterf(GL_POINT_SIZE_MIN_ARB, 0);
            osgGlPointParameterf(GL_POINT_SIZE_MAX_ARB, 1e10);
#endif
            osgGlPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE_ARB, 1);
            
#if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
            GLfloat att[3] = { 1, 0, 0 };
            
            osgGlPointParameterfv(GL_POINT_DISTANCE_ATTENUATION_ARB, att);
#endif
        }
        
    }
#endif

#if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
#if GL_ARB_point_sprite
    if(getSprite())
    {
        if(pEnv->getWindow()->hasExtOrVersion(_extPointSpriteARB, 0x0200))
        {
            glDisable(GL_POINT_SPRITE_ARB);
        }
        
    }
#endif
#endif

#if ! defined(GL_ARB_point_parameters) && ! defined(GL_ARB_point_sprite)
    pEnv;
#endif
}
示例#28
0
void Entity::draw(tSpriteBatch* spriteBatch)
{
    spriteBatch->draw(1, mImage, tPoint2f((int32_t)mPosition.x, (int32_t)mPosition.y), tOptional<tRectf>(), mColor,
                     mOrientation, getSize() / 2, tVector2f(1,1));
}
示例#29
0
void WindowCaptureCallback::ContextData::multiPBO(osg::BufferObject::Extensions* ext)
{
    // std::cout<<"multiPBO(  "<<_fileName<<" image "<<_currentImageIndex<<" "<<_currentPboIndex<<std::endl;
    unsigned int nextImageIndex = (_currentImageIndex+1)%_imageBuffer.size();
    unsigned int nextPboIndex = (_currentPboIndex+1)%_pboBuffer.size();

    int width=0, height=0;
    getSize(_gc, width, height);
    if (width!=_width || _height!=height)
    {
        std::cout<<"   Window resized "<<width<<", "<<height<<std::endl;
        _width = width;
        _height = height;
    }

    GLuint& copy_pbo = _pboBuffer[_currentPboIndex];
    GLuint& read_pbo = _pboBuffer[nextPboIndex];

    osg::Image* image = _imageBuffer[_currentImageIndex].get();
    if (image->s() != _width ||
            image->t() != _height)
    {
        osg::notify(osg::NOTICE)<<"Allocating image "<<std::endl;
        image->allocateImage(_width, _height, 1, _pixelFormat, _type);

        if (read_pbo!=0)
        {
            osg::notify(osg::NOTICE)<<"deleting pbo "<<read_pbo<<std::endl;
            ext->glDeleteBuffers (1, &read_pbo);
            read_pbo = 0;
        }

        if (copy_pbo!=0)
        {
            osg::notify(osg::NOTICE)<<"deleting pbo "<<copy_pbo<<std::endl;
            ext->glDeleteBuffers (1, &copy_pbo);
            copy_pbo = 0;
        }
    }


    bool doCopy = copy_pbo!=0;
    if (copy_pbo==0)
    {
        ext->glGenBuffers(1, &copy_pbo);
        ext->glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, copy_pbo);
        ext->glBufferData(GL_PIXEL_PACK_BUFFER_ARB, image->getTotalSizeInBytes(), 0, GL_STREAM_READ);

        osg::notify(osg::NOTICE)<<"Generating pbo "<<read_pbo<<std::endl;
    }

    if (read_pbo==0)
    {
        ext->glGenBuffers(1, &read_pbo);
        ext->glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, read_pbo);
        ext->glBufferData(GL_PIXEL_PACK_BUFFER_ARB, image->getTotalSizeInBytes(), 0, GL_STREAM_READ);

        osg::notify(osg::NOTICE)<<"Generating pbo "<<read_pbo<<std::endl;
    }
    else
    {
        ext->glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, read_pbo);
    }

    osg::Timer_t tick_start = osg::Timer::instance()->tick();

#if 1
    glReadPixels(0, 0, _width, _height, _pixelFormat, _type, 0);
#endif

    osg::Timer_t tick_afterReadPixels = osg::Timer::instance()->tick();

    if (doCopy)
    {

        ext->glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, copy_pbo);

        GLubyte* src = (GLubyte*)ext->glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB,
                       GL_READ_ONLY_ARB);
        if(src)
        {
            memcpy(image->data(), src, image->getTotalSizeInBytes());
            ext->glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB);
        }

        if (!_fileName.empty())
        {
            // osgDB::writeImageFile(*image, _fileName);
        }
    }

    ext->glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0);

    osg::Timer_t tick_afterMemCpy = osg::Timer::instance()->tick();

    updateTimings(tick_start, tick_afterReadPixels, tick_afterMemCpy, image->getTotalSizeInBytes());

    _currentImageIndex = nextImageIndex;
    _currentPboIndex = nextPboIndex;
}
示例#30
0
template <class T, typename S> T& ArrayBase<T,S>::getLast(void)
{
    return get(getSize() - 1);
}