Esempio n. 1
0
SEXP logp(SEXP x_, SEXP rho_) {
    const int eval_limit = 10;
    double ans = std::numeric_limits<double>::quiet_NaN();
    cppbugs::MCMCObject* node(NULL);
    vpArmaMapT armaMap;

    if(rho_ == R_NilValue || TYPEOF(rho_) != ENVSXP) {
        REprintf("ERROR: bad environment passed to logp (contact the package maintainer).");
    }

    try {
        x_ = forceEval(x_, rho_, eval_limit);
        ArmaContext* ap = mapOrFetch(x_, armaMap);
        node = createMCMC(x_,armaMap);
    } catch (std::logic_error &e) {
        releaseMap(armaMap);
        UNPROTECT(armaMap.size());
        REprintf("%s\n",e.what());
        return R_NilValue;
    }

    cppbugs::Stochastic* sp = dynamic_cast<cppbugs::Stochastic*>(node);
    if(sp) {
        ans = sp->loglik();
    } else {
        REprintf("ERROR: could not convert node to stochastic.\n");
    }
    releaseMap(armaMap);
    UNPROTECT(armaMap.size());
    return Rcpp::wrap(ans);
}
Esempio n. 2
0
void Map_Manager::Deinitialize() {
	logWrite("Deinitializing maps");
	for (uint i = 0; i < cacheCityscape.Count; i++) {
		releaseMap(*cacheCityscape[i]);
	}
	mapsInfo.Release();
	cacheCityscape.Release();
}
Esempio n. 3
0
Parallax1::Parallax1()
{
    // Top Layer, a simple image
    auto cocosImage = Sprite::create(s_Power);
    // scale the image (optional)
    cocosImage->setScale( 2.5f );
    // change the transform anchor point to 0,0 (optional)
    cocosImage->setAnchorPoint( Vec2(0,0) );
    

    // Middle layer: a Tile map atlas
    auto tilemap = TileMapAtlas::create(s_TilesPng, s_LevelMapTga, 16, 16);
    tilemap->releaseMap();
    
    // change the transform anchor to 0,0 (optional)
    tilemap->setAnchorPoint( Vec2(0, 0) );

    // Anti Aliased images
    tilemap->getTexture()->setAntiAliasTexParameters();
    

    // background layer: another image
    auto background = Sprite::create(s_back);
    // scale the image (optional)
    background->setScale( 1.5f );
    // change the transform anchor point (optional)
    background->setAnchorPoint( Vec2(0,0) );

    
    // create a void node, a parent node
    auto voidNode = ParallaxNode::create();
    
    // NOW add the 3 layers to the 'void' node

    // background image is moved at a ratio of 0.4x, 0.5y
    voidNode->addChild(background, -1, Vec2(0.4f,0.5f), Vec2::ZERO);
    
    // tiles are moved at a ratio of 2.2x, 1.0y
    voidNode->addChild(tilemap, 1, Vec2(2.2f,1.0f), Vec2(0,-200) );
    
    // top image is moved at a ratio of 3.0x, 2.5y
    voidNode->addChild(cocosImage, 2, Vec2(3.0f,2.5f), Vec2(200,800) );
    
    
    // now create some actions that will move the 'void' node
    // and the children of the 'void' node will move at different
    // speed, thus, simulation the 3D environment
    auto goUp = MoveBy::create(4, Vec2(0,-500) );
    auto goDown = goUp->reverse();
    auto go = MoveBy::create(8, Vec2(-1000,0) );
    auto goBack = go->reverse();
    auto seq = Sequence::create(goUp, go, goDown, goBack, nullptr);
    voidNode->runAction( (RepeatForever::create(seq) ));
    
    addChild( voidNode );
}
Esempio n. 4
0
Parallax2::Parallax2()
{
    auto listener = EventListenerTouchAllAtOnce::create();
    listener->onTouchesMoved = CC_CALLBACK_2(Parallax2::onTouchesMoved, this);
    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
    
    // Top Layer, a simple image
    auto cocosImage = Sprite::create(s_Power);
    // scale the image (optional)
    cocosImage->setScale( 2.5f );
    // change the transform anchor point to 0,0 (optional)
    cocosImage->setAnchorPoint( Vec2(0,0) );
    
    
    // Middle layer: a Tile map atlas
    auto tilemap = TileMapAtlas::create(s_TilesPng, s_LevelMapTga, 16, 16);
    tilemap->releaseMap();
    
    // change the transform anchor to 0,0 (optional)
    tilemap->setAnchorPoint( Vec2(0, 0) );
    
    // Anti Aliased images
    tilemap->getTexture()->setAntiAliasTexParameters();
    
    
    // background layer: another image
    auto background = Sprite::create(s_back);
    // scale the image (optional)
    background->setScale( 1.5f );
    // change the transform anchor point (optional)
    background->setAnchorPoint( Vec2(0,0) );
    
    
    // create a void node, a parent node
    auto voidNode = ParallaxNode::create();
    
    // NOW add the 3 layers to the 'void' node
    
    // background image is moved at a ratio of 0.4x, 0.5y
    voidNode->addChild(background, -1, Vec2(0.4f,0.5f), Vec2::ZERO);
    
    // tiles are moved at a ratio of 1.0, 1.0y
    voidNode->addChild(tilemap, 1, Vec2(1.0f,1.0f), Vec2(0,-200) );
    
    // top image is moved at a ratio of 3.0x, 2.5y
    voidNode->addChild( cocosImage, 2, Vec2(3.0f,2.5f), Vec2(200,1000) );
    addChild(voidNode, 0, kTagNode);
}
Esempio n. 5
0
void Map_Manager::cellUncache(int cx, int cy) {
	LockID lockID = Thread.EnterLock(MUTEX_MAP);
		int idx = cellCacheIndex(cx,cy);
		if (idx == BAD_ID) {
			logWritem("cellUncache: map [%d;%d] is not cached",cx,cy);
			Thread.LeaveLock(lockID);
			return;
		}
	
		releaseMap(*cacheCityscape[idx]);
		cacheCityscape.Count--;
		if (cacheCityscape.Count > 0) {
			*cacheCityscape[idx] = *cacheCityscape[cacheCityscape.Count];
		}
		logWritem("cellUncache: map [%d;%d] removed from cache",cx,cy);
	Thread.LeaveLock(lockID);
}
Esempio n. 6
0
//------------------------------------------------------------------
//
// TileMapTestNew
//
//------------------------------------------------------------------
TileMapTestNew::TileMapTestNew()
{
    auto map = TileMapAtlas::create(s_TilesPng,  s_LevelMapTga, 16, 16);
    // Convert it to "alias" (GL_LINEAR filtering)
    map->getTexture()->setAntiAliasTexParameters();
    
    Size CC_UNUSED s = map->getContentSize();
    CCLOG("ContentSize: %f, %f", s.width,s.height);

    // If you are not going to use the Map, you can free it now
    // NEW since v0.7
    map->releaseMap();
    
    addChild(map, 0, kTagTileMap);
    
    map->setAnchorPoint( Vec2(0, 0.5f) );

    auto scale = ScaleBy::create(4, 0.8f);
    auto scaleBack = scale->reverse();

    auto seq = Sequence::create(scale, scaleBack, nullptr);

    map->runAction(RepeatForever::create(seq));
}
Esempio n. 7
0
SEXP runModel(SEXP m_, SEXP iterations, SEXP burn_in, SEXP adapt, SEXP thin) {
    const int eval_limit = 10;

    SEXP env_ = Rf_getAttrib(m_,Rf_install("env"));
    if(env_ == R_NilValue || TYPEOF(env_) != ENVSXP) {
        throw std::logic_error("ERROR: bad environment passed to deterministic.");
    }

    vpArmaMapT armaMap;
    vpMCMCMapT mcmcMap;
    std::vector<cppbugs::MCMCObject*> mcmcObjects;

    arglistT arglist;
    std::vector<const char*> argnames;

    initArgList(m_, arglist, 1);
    for(size_t i = 0; i < arglist.size(); i++) {

        // capture arg name
        // FIXME: check class of args to make sure it's mcmc
        if(TYPEOF(arglist[i])==SYMSXP) {
            argnames.push_back(CHAR(PRINTNAME(arglist[i])));
        }

        // force eval of late bindings
        arglist[i] = forceEval(arglist[i],env_,eval_limit);

        try {
            ArmaContext* ap = mapOrFetch(arglist[i], armaMap);
            cppbugs::MCMCObject* node = createMCMC(arglist[i],armaMap);
            mcmcMap[rawAddress(arglist[i])] = node;
            mcmcObjects.push_back(node);
        } catch (std::logic_error &e) {
            releaseMap(armaMap);
            releaseMap(mcmcMap);
            UNPROTECT(armaMap.size());
            REprintf("%s\n",e.what());
            return R_NilValue;
        }
    }

    int iterations_ = Rcpp::as<int>(iterations);
    int burn_in_ = Rcpp::as<int>(burn_in);
    int adapt_ = Rcpp::as<int>(adapt);
    int thin_ = Rcpp::as<int>(thin);
    SEXP ar;
    PROTECT(ar = Rf_allocVector(REALSXP,1));
    try {
        cppbugs::RMCModel m(mcmcObjects);
        m.sample(iterations_, burn_in_, adapt_, thin_);
        //std::cout << "acceptance_ratio: " << m.acceptance_ratio() << std::endl;
        REAL(ar)[0] = m.acceptance_ratio();
    } catch (std::logic_error &e) {
        releaseMap(armaMap);
        releaseMap(mcmcMap);
        UNPROTECT(armaMap.size());
        UNPROTECT(1); // ar
        REprintf("%s\n",e.what());
        return R_NilValue;
    }

    SEXP ans;
    PROTECT(ans = createTrace(arglist,armaMap,mcmcMap));
    releaseMap(armaMap);
    releaseMap(mcmcMap);
    UNPROTECT(armaMap.size());
    Rf_setAttrib(ans, R_NamesSymbol, makeNames(argnames));
    Rf_setAttrib(ans, Rf_install("acceptance.ratio"), ar);
    UNPROTECT(2); // ans + ar
    return ans;
}