示例#1
0
void WorldState::Init(RenderContext& ctx,Scene* m_scene){
	std::cout << "Initializing WorldState\n";
    ctx.checkFS(isFullscreen = false);
    Tiles* tile;
    tile->CreateMap(ctx,m_scene);
    m_scene->add(GameObject(ctx, std::string("res/hero1.png"), std::string("hero")), 0, {300, 200}, true);
}
示例#2
0
文件: parallel.cpp 项目: stastaj/Svit
	Tiles
	ParallelRenderer::worker (TaskDispatcher& _task_dispatcher, World& _world, 
	    Settings& _settings, Engine& _engine, SuperSampling& _super_sampling)
	{
		Tiles result;
		SerialRenderer serial_renderer;
		Settings settings = _settings;
		
		while (1)
		{
			boost::optional<Task> optional_task = _task_dispatcher.get_task();
			if (!optional_task)
				break;

			Task task = optional_task.get();
			settings.area = task;

			Image rendered_image = serial_renderer.render(_world, settings, _engine,
			    _super_sampling);

			Tile tile;
			tile.task = task;
			tile.image = rendered_image;
			result.push_back(tile);
		}

		return result;
	}
示例#3
0
文件: parallel.cpp 项目: stastaj/Svit
	Image
	ParallelRenderer::render (World& _world, Settings& _settings, Engine&
	    _engine, SuperSampling& _super_sampling)
	{
		TaskDispatcher task_dispatcher(_settings);
		std::vector<std::future<Tiles>> futures(0);

		for (unsigned i = 0; i < _settings.max_thread_count; i++)
		{
			// TODO can this be done better? it must be possible
			futures.push_back(std::async(std::launch::async, [this, &task_dispatcher,
			    &_world, &_settings, &_engine, &_super_sampling] () { 
					return worker(task_dispatcher, _world, _settings, _engine,
					_super_sampling); }));
		}

		for (unsigned i = 0; i < futures.size(); i++)
		{
			futures[i].wait();
		}

		Image final_image(_settings.area.size);
		for (unsigned i = 0; i < futures.size(); i++)
		{
			Tiles tiles = futures[i].get();
			for (unsigned j = 0; j < tiles.size(); j++)
			{
				final_image.paste(tiles[j].task.start, tiles[j].image);
			}
		}

		return final_image;
	}
示例#4
0
    int hitTile(Tiles &tiles, int x, int y)
    {
      int ty =(y - TILES_TOP)/ TILE_H;
      int tx =(x - TILES_LEFT)/ TILE_W;
    
      const boolean hit = ty >= 0 && ty < ROWS && tx >= 0 && tx < COLS && tiles.exists(tx,ty);
    
      if (!hit) return 0;
    
      tiles.clearTile( tx, ty );
    
      const int score = ROWS - ty;
    
      ty*= TILE_H;
      ty+= TILES_TOP;

      tft.fillRectangle(TILES_LEFT + tx * TILE_W, ty, TILE_W - 2, TILE_H - 2, BACKGROUND_COLOR);
        
      const int ty2= ty + TILE_H;

      if ( (yi > 0 && y > ty) || (yi < 0 && y > ty2))
      {
        xi *=-1;
      }
      else
      {
        yi *=-1;
      }

      return score;
    }
static Tiles	make_tiles(void)
{
	Tiles		t;

	t.init(WIN_SIZEVI);
	return t;
}
示例#6
0
static void trace(Node *n, Tiles &v) {
  v.clear();
  while (n) {
    v.push_back(n->tile);
    n = n->next;
  }
  std::reverse(v.begin(), v.end());
}
示例#7
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Tiles w;
    w.readPositionSettings();
    w.show();
    return a.exec();
}
示例#8
0
// return the largest subset of mutually compatible tiles
Tiles Tiles::LongestRun(void) const {
    // clones are never compatible, so consider only the unique tiles
    Tiles const unique = UniqueTiles();

    Tiles result;
    Tiles const empty_run;
    unique.BuildRuns(empty_run, result);

    ASSERT(result.AreAllCompatible());
    return result;
}
示例#9
0
// return a new set containing only one instance of each clone
Tiles Tiles::UniqueTiles(void) const {
    Tiles result;

    ConstIterator i_tile;
    for (i_tile = begin(); i_tile != end(); i_tile++) {
        Tile const tile = *i_tile;
        if (!result.ContainsOpt(tile)) {
            result.Add(tile);
        }
    }

    return result; 
}
示例#10
0
Tiles Tiles::PullRandomTiles(SizeType tileCnt) {
    Tiles result;

    for (SizeType i_tile = 0; i_tile < tileCnt; i_tile++) {
        if (IsEmpty()) {
            break;
        }
        Tile const tile = PullRandomTile();
        result.Add(tile);
    }

    return result;
}
示例#11
0
void UpgradeWork::finish(Island* island, const Event& e) {
	Tiles* tiles = island->getTiles();
	tiles->clear_state(e.tile_x,e.tile_y,TS_ACTIVE);
	Tile& t = tiles->get(e.tile_x, e.tile_y);
	++t.level;
	// remove old regular work
	island->removeWork(PT_REGULAR,e.tile_x, e.tile_y);
	// create new
	island->calculateMaxResources();
	Resources tmp;
	if (gContext->price_registry.get(PT_REGULAR, 0, t.building_id, t.level, &tmp)) {
		island->createWork(PT_REGULAR, e.tile_x, e.tile_y, t.building_id, t.level);
	}
}
static Tiles	make_tiles(void)
{
	Tiles		t;

	t.init(WIN_SIZEVI
		   , /*ft::Vec2<int> const triangleSize =*/ ft::Vec2<int>(95, 95)
		   , /*int const pointRandomRadius =*/ 30
		   , /*float const percentGray =*/ 0.33f
		   , /*ft::Vec3<int> const gray =*/ ft::Vec3<int>(120, 181, 129)
		   , /*ft::Vec3<int> const pink =*/ ft::Vec3<int>(10, 150, 10)
		   // , /*ft::Vec3<int> const pink =*/ ft::Vec3<int>(230, 46, 77)
		   , /*ft::Vec3<int> const deltaPink =*/ ft::Vec3<int>(10, 45, 10));
		   // , /*ft::Vec3<int> const deltaPink =*/ ft::Vec3<int>(50, 10, 77));
	return t;
}
示例#13
0
 void move(int dir) {
     switch(dir) {
         case DIRECTION_LEFT:
             if(x > 0 && matrix.tileAt(x-1, y) >= 1) x -= speed;
             break;
         case DIRECTION_RIGHT:
             if(x+1 < width && matrix.tileAt(x+1,y) >= 1)
                 x += speed;
             break;
         case DIRECTION_UP:
             if(y > 0 && matrix.tileAt(x,y-1) >= 1) y -= speed;
             break;
         case DIRECTION_DOWN:
             if(y+1 < height && matrix.tileAt(x,y+1) >= 1)
             y += speed;
             break;
     }
 }
示例#14
0
// construct "runs":  subsets of mutually-compatible tiles - RECURSIVE
void Tiles::BuildRuns(Tiles const& rRunSoFar, Tiles& rLongestRun) const {
    if (IsEmpty()) {
        if (rRunSoFar.Count() > rLongestRun.Count()) {
            rLongestRun = rRunSoFar;
        }
    } else {
        Tiles run(rRunSoFar);
        Tiles remainder(*this);
        Tile const first = remainder.PullFirstTile();

        // build runs without the first tile
        remainder.BuildRuns(run, rLongestRun);

        if (run.AreAllCompatibleWith(first)) {
            // build runs with the first tile
            run.Add(first);
            remainder.BuildRuns(run, rLongestRun);
        }
    }
}
示例#15
0
文件: vis.cpp 项目: amecky/space
	// ------------------------------------------------------
	// describe building
	// ------------------------------------------------------
	bool describe_building(Island* island,int x, int y) {
		Tiles* tiles = island->getTiles();
		int idx = x + y * tiles->width;
		if (tiles->getBuildingID(idx) == -1) {
			gContext->messages.report_error("There is no building at %d %d", x, y);
			return false;
		}
		const Tile& t = tiles->get(x, y);
		printf("Building: %s\n", gContext->building_definitions.getName(t.building_id));
		printf("   Level: %d\n", t.level);
		Resources tmp;
		if (gContext->price_registry.get(PT_REGULAR, 2, t.building_id, t.level, &tmp)) {
			printf("Regular income:\n");
			printf("Duration: %d\n", gContext->price_registry.getDuration(PT_REGULAR, t.building_id, t.level));
			res::show_resources(gContext->resource_registry, tmp, false);
		}
		printf("Available work:\n");
		for (int i = 1; i <= t.level; ++i) {
			if (gContext->price_registry.get(PT_WORK, 0, t.building_id, i, &tmp)) {
				printf(" Level %d\n", i);
				printf("Duration: %d\n", gContext->price_registry.getDuration(PT_WORK, t.building_id, i));
				printf("Costs:\n");
				res::show_resources(gContext->resource_registry, tmp, false);
			}
			if (gContext->price_registry.get(PT_WORK, 1, t.building_id, i, &tmp)) {
				printf("Income:\n");
				Resources collect;
				if (gContext->price_registry.get(PT_WORK, 2, t.building_id, i, &collect)) {
					tmp.add(collect);

				}
				res::show_resources(gContext->resource_registry, tmp, false);
			}
		}
		// FIXME: list start options
		return true;
	}
  const Tile* get(uint32_t id) const
  {
    //FIXME: Commenting out tiles in sprites.strf makes tiles.size() fail - it's being set to the first tile commented out.
    assert(id < tiles.size());
    Tile* tile = tiles[id];
    if(!tile) {
      log_warning << "Invalid tile: " << id << std::endl;
      return tiles[0];
    }

    if(tile->images.size() == 0 && tile->imagespecs.size() != 0)
      tile->load_images(tiles_path);

    return tile;
  }
示例#17
0
// ------------------------------------------------------
// StartWork
// ------------------------------------------------------
bool UpgradeWork::start(Island* island, const TextLine& line) {
	int x = line.get_int(1);
	int y = line.get_int(2);
	Tiles* tiles = island->getTiles();
	int idx = x + y * tiles->width;
	if ( tiles->getBuildingID(idx) == -1 ) {
		gContext->messages.report_error("There is no building at %d %d",x,y);
		return false;
	}
	// FIXME: check if there is only a regular work item
	if ( tiles->isActive(idx)) {
		gContext->messages.report_error("The building is active - upgrade is not available");
		return false;
	}
	if (island->checkRequirements(tiles->getBuildingID(idx), tiles->getLevel(idx) + 1)) {
		tiles->set_state(x,y,TS_ACTIVE);
		island->createWork(PT_UPGRADE,x,y,tiles->getBuildingID(idx),tiles->getLevel(idx)+1);
		return true;
	}
	return false;
}
示例#18
0
inline Tile* Map::GetRandomTile(){
	int randomTileIndex = GetRandomIntInRange(1, m_tiles.size()-1);

	return &(m_tiles[randomTileIndex]);

}
示例#19
0
文件: vis.cpp 项目: amecky/space
	void print_map(Island* island, int centerX, int centerY, int size) {
		Tiles* tiles = island->getTiles();
		int xmin = centerX - size;
		int xmax = centerX + size;
		int ymin = centerY - size;
		int ymax = centerY + size;
		if (xmin < 0) {
			xmin = 0;
			xmax = 2 * size;
		}
		if (xmax >= tiles->width) {
			xmin = tiles->width - 2 * size;
			xmax = tiles->width;
		}
		if (ymin < 0) {
			ymin = 0;
			ymax = 2 * size;
		}
		if (ymax >= tiles->height) {
			ymin = tiles->height - 2 * size;
			ymax = tiles->height;
		}
		for ( int y = ymax - 1; y >= ymin; --y ) {
			printf("%2d | ", y);
			for ( int x = xmin; x < xmax; ++x ) {
				int idx = x + y * tiles->width;
				if ( tiles->has_state(x,y,TS_LOCKED)) {
					printf("??  ");
				}
				else if ( tiles->has_state(x,y,TS_UNDEFINED)) {
					printf("    ");
				}
				else {
					if ( tiles->getBuildingID(idx) != -1 ) {
						printf("%s", gContext->building_definitions.getSign(tiles->getBuildingID(idx)));
						if ( tiles->isActive(idx)) {			
							printf("# ");
						}
						else if ( tiles->has_state(x,y,TS_COLLECTABLE)) {
							printf("* ");
						}
						else {
							printf("  ");
						}
					}
					else if ( tiles->_tiles[idx].ref_id != -1 ) {
						printf("xx  ");
					}
					else {
						printf("-   ");
					}
				}
			}
			printf("\n");
		}
		printf("   -----------------------------------------------------------------\n");
		printf("     ");
		for (int i = xmin; i < xmax; ++i) {
			printf("%2d  ", i);
		}
		printf("\n");
	}
 uint32_t get_max_tileid() const
 {
   return tiles.size();
 }
示例#21
0
//--------------------------------------------------------------
void testApp::setup(){
    
	ofSetVerticalSync(true);
	ofSetFrameRate(60);
	ofEnableSmoothing();
	ofBackground(0);
    
    /*------------------ SYPHON ------------------*/
//	syphon.setName("ciel_etoile");
    individualTextureSyphonServer.setName("Texture Output");
	mClient.setup();
    mClient.set("","Simple Server");
    /*--------------------------------------------*/

    
    /*-------------------- FBO -------------------*/
    fbo.allocate(ofGetWidth(), ofGetHeight(), GL_RGBA);
    fbo.begin();
    ofClear(0);
    fbo.end();
    /*---------------------------------------------*/
    
    /*------------------- WI-FLY ------------------*/
    //create the socket and bind to port 11999
	udpConnection.Create();
	udpConnection.Bind(11999);
	udpConnection.SetNonBlocking(true);
    /*---------------------------------------------*/

    /*-------------------- FOG --------------------*/
    //    fogMovie.loadMovie("movies/fog.mov");
    fogMovie.loadMovie("movies/smoke_duck.mp4");
	fogMovie.play();
    //    fogMovie.setLoopState();
    videoAlpha = 100;
    /*---------------------------------------------*/
    
    /*------------------- SOUND -------------------*/
    soundStream.listDevices();
  	soundStream.setDeviceID(2);
    
    //soundstream setup
    soundStream.setup(this, 0, 2, 44100, BUFFER_SIZE, 4);
    
	FFTanalyzer.setup(44100, BUFFER_SIZE/2, 2);
	
	FFTanalyzer.peakHoldTime = 15; // hold longer
	FFTanalyzer.peakDecayRate = 0.95f; // decay slower
	FFTanalyzer.linearEQIntercept = 0.9f; // reduced gain at lowest frequency
	FFTanalyzer.linearEQSlope = 0.01f; // increasing gain at higher frequencies
    /*---------------------------------------------*/
    
    
    /*----------------- PARTICLES -----------------*/
    modes.push_back("static");
    modes.push_back("walk");
    modes.push_back("fuzz");
    selectedMode = modes[2];
    
    shapes.push_back("circle");
    shapes.push_back("spiral");
    shapes.push_back("star");
    shapes.push_back("grid");
    selectedShape = shapes[0];
    
    expansion = 0;
    rotation = 0;
    shapeSize = ofGetHeight()/2 - 100;
    particleSize = 1;
    nVertices = 1;
    
    particleGUImode = true;
    
    for(int i=0; i < NUM_PARTICLES; i++){
        Particle thisParticle;
        thisParticle.init(NUM_PARTICLES, i, shapeSize, particleSize, selectedShape);
        myParticles.push_back(thisParticle);
    }
    /*---------------------------------------------*/
    
    
    /*---------------- BACKGROUND -----------------*/
	tileModes.push_back("3D");
	tileModes.push_back("fragments");
	tileModes.push_back("rotation");
    selectedTileMode = tileModes[0];
    
    int nTiles = int(ofGetWidth()/40) *  int(ofGetHeight()/40);
    int i = 0;
	for (int gridY=0; gridY <= ofGetHeight(); gridY += 40) {
		for (int gridX=0; gridX <= ofGetWidth(); gridX+= 40) {
			Tiles thisTile;
			thisTile.setup(nTiles, i, selectedTileMode, gridX, gridY);
			myTiles.push_back(thisTile);
            //            cout << gridX << endl;
            i++;
		}
	}
    /*---------------------------------------------*/
    
    setGUI1();
    setGUI2();
    
}
 void apply(osg::Group& group)
 {
     osgVolume::VolumeTile* tile = dynamic_cast<osgVolume::VolumeTile*>(&group);
     if (tile) _tiles.push_back(tile);
     else traverse(group);
 }
示例#23
0
		TileData()
		{
			m_class_name = "TileData";
			m_tile.reserve(255);
		}
示例#24
0
namespace game {
    
    // the Tile Matrix
    
    template<typename T, int w, int h>
    class Tiles {
    protected:
        std::array<std::array<T, h>, w> tile_matrix;
     public:
        Tiles() { loadTiles("tiles.txt"); }
        
        T operator()(int x, int y) {
            return tileAt(x,y);
        }
        T tileAt(int x, int y) {
            return tile_matrix[x][y];
        }
        // load tile matrix
        void loadTiles(std::string fileName) {
            for(int x = 0; x < w; ++x) {
                for(int y = 0; y < h; ++y)
                    tile_matrix[x][y] = 1+rand()%255;
            }
        }
    };
    
    class Position {
    protected:
        Position() = default;
        Position(int cx, int cy, int cw, int ch) : x{cx}, y{cy}, w{cw}, h{ch}, cur_frame{0} {}
        int x,y,w,h;
        int cur_frame;
    };
    
    const int width = 640;
    const int height = 480;
    
    Tiles<int, width, height> matrix;
    
    enum {DIRECTION_LEFT=0, DIRECTION_RIGHT, DIRECTION_UP, DIRECTION_DOWN};
    
    class Hero : protected Position {
    public:
        Hero();
        Hero(int x, int y, int w, int h) : Position(x,y,w,h) , speed{1}, direction{DIRECTION_RIGHT} {}
        Hero(int x, int y) : Position(x,y,0,0), speed{1}, direction{DIRECTION_RIGHT} {}
        void move(int dir) {
            switch(dir) {
                case DIRECTION_LEFT:
                    if(x > 0 && matrix.tileAt(x-1, y) >= 1) x -= speed;
                    break;
                case DIRECTION_RIGHT:
                    if(x+1 < width && matrix.tileAt(x+1,y) >= 1)
                        x += speed;
                    break;
                case DIRECTION_UP:
                    if(y > 0 && matrix.tileAt(x,y-1) >= 1) y -= speed;
                    break;
                case DIRECTION_DOWN:
                    if(y+1 < height && matrix.tileAt(x,y+1) >= 1)
                    y += speed;
                    break;
            }
        }
        
        std::string toString() {
            std::ostringstream stream;
            stream << "Hero is at: " << x << ", " << y << ", " << w << ", " << h << "\n";
            stream << "Hero speed: " << speed << "\n";
            return stream.str();
        }
        
    protected:
        int speed, direction;
    };
    
}