Пример #1
0
void Level::spawnLevel()
{
  setupSettingsBasedGlobals();
  
  generateTerrain(terrain);

  cannonL.live();
  cannonR.live();
  is_a_player_dead = false;

  // find placement for left cannon, top ground pixel at randomized x
  int cannonL_cx = 100 + nrand(200); // center x of cannon
  auto lt = std::find_if(terrain.begin(), terrain.end(),
      [&cannonL_cx](Pixel p)
      {
        if (p.x == cannonL_cx && p.status)
          return true;
        else
          return false;
      });

  cannonL.setPosition(cannonL_cx - CANNON_WIDTH/2, lt->y - CANNON_HEIGHT);
  fixTerrain(terrain, cannonL.getRect());

  // find placement for right cannon, top ground pixel at randomized x
  int cannonR_cx = 500 + nrand(200);
  auto rt = std::find_if(terrain.begin(), terrain.end(),
      [&cannonR_cx](Pixel p)
      {
        if (p.x == cannonR_cx && p.status)
          return true;
        else
          return false;
      });

  cannonR.setPosition(cannonR_cx - CANNON_WIDTH/2, rt->y - CANNON_HEIGHT);
  fixTerrain(terrain, cannonR.getRect());


  // find positions for obstacles
  // make sure they don't collide with cannons or themselves
  std::vector<SDL_Rect *> rects;
  rects.push_back(cannonL.getRect());
  rects.push_back(cannonR.getRect());
  for (int i = 0; i < gObstacleTotal; i++)
  {
    obstacles[i].findPosition(terrain, rects);
    if (i < 10) // don't worry about trees colliding after 10+ obstacles
      rects.push_back(obstacles[i].getRect());
  }
    
  missed_left = false;
  missed_right = false;
  missed_distance = 0;
  last_ai_angle = -60.0;
  last_ai_shot_dt = 1.0;
  
  // copy terrain vector to SDL_Points array for faster rendering
  copyTerrainToPointsArray();
}
Пример #2
0
void MainWindow::generateParticles() {
    sbTDist->setRange(0.0, sbPSSize->value() / 2);
    viewer->initParticles(sbPCount->value(), ":/textures/snowflakes.jpg");
    viewer->initTerrain(sbPSSize->value(), sbTCSize->value());
    generateTerrain();
    viewer->generateParticles(sbPSSize->value());
    viewer->setFocus();
}
Пример #3
0
void TriangleWindow::initialize()
{
    generateTerrain();
    initFall();

    m_program = new QOpenGLShaderProgram(this);
    m_program->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/map.vert");
    m_program->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/map.frag");
    m_program->link();
    m_posAttr = m_program->attributeLocation("posAttr");
    m_colAttr = m_program->attributeLocation("colAttr");
    m_normal = m_program->attributeLocation("normal");
    m_texCoord = m_program->attributeLocation("texCoord");
    m_matrixUniform = m_program->uniformLocation("matrix");
    m_texAttr = glGetUniformLocation(m_program->programId(), "texture");
    glUniform1i(m_texAttr, 0);

    size_t verticesSize = _map.size()*sizeof(QVector3D), colorsSize = _color.size()*sizeof(QVector3D),
            normalSize = _normal.size()*sizeof(QVector3D), texCoordSize = _texture.size()*sizeof(GLfloat);

    vao.create();

    vao.bind();

    vbo.create();
    vbo.setUsagePattern(QOpenGLBuffer::StaticDraw);
    vbo.bind();

    vbo.allocate(verticesSize + colorsSize + normalSize + texCoordSize);

    vbo.bind();
    vbo.write(0, _map.constData(), verticesSize);
    vbo.write(verticesSize, _color.constData(), colorsSize);
    vbo.write(verticesSize + colorsSize, _normal.constData(), normalSize);
    vbo.write(verticesSize + colorsSize + normalSize, _texture.constData(), texCoordSize);

    m_program->setAttributeBuffer(m_posAttr, GL_FLOAT, 0, 3, 0);
    m_program->setAttributeBuffer(m_colAttr, GL_FLOAT, verticesSize, 3, 0);
    m_program->setAttributeBuffer(m_normal, GL_FLOAT, verticesSize + colorsSize, 3, 0);
    m_program->setAttributeBuffer(m_texCoord, GL_FLOAT, verticesSize + colorsSize + normalSize, 2, 0);

    m_program->enableAttributeArray(m_posAttr);
    m_program->enableAttributeArray(m_colAttr);
    m_program->enableAttributeArray(m_normal);
    m_program->enableAttributeArray(m_texCoord);

    vao.release();

    QImage image(QString(":/heightmap-2.png"));
    texture = new QOpenGLTexture(image);

    m_program->bind();
    m_program->setUniformValue("ambiant_color", QVector4D(0.7, 0.7, 0.7, 1.0));
    m_program->setUniformValue("light_direction", QVector4D(0.0, 0.0, 1.0, 1.0));
    m_program->release();

    glEnable(GL_DEPTH_TEST);
}
Пример #4
0
void Environment::init()
{
	vbase::Loadable::Begin b(this);

	generateTerrain(seedToUse());
	mAssetManager.loadMeshesFromDirectory(gDefaultPathMeshes);
	mEntityManager.init(&mAssetManager);
	generateEntities();
}
Пример #5
0
Terrain::Terrain(float gridX, float gridZ, float max_height, Loader &loader, TerrainTexturePack *texturePack,ModelTexture *blendMap, std::string heightMapFile)
{
	this->blendMap = blendMap;
	this->max_height = max_height;
	this->x = gridX * size;
	this->z = gridZ * size;
	this->texturePack = texturePack;
	transform = MyMaths::createTransformationmatrix(glm::vec3(x, 0, z), 0, 0, 0, glm::vec3(1, 1, 1));
	model = generateTerrain(loader, heightMapFile);
}
Пример #6
0
 void display(void) {
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glEnable(GL_DEPTH_TEST);
  // glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
   glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
   matrixPush(ModelView);
   generateTerrain();
   matrixPop(ModelView);
   glutSwapBuffers();
 }
Пример #7
0
void Environment::refresh()
{
	vbase::Loadable::Begin b(this);

	if (mNeedsToRefresh)
	{
		generateTerrain(seedToUse());
		generateEntities();
	}
}
Пример #8
0
void TerrainGenerator::initialize()
{
    m_program = new QOpenGLShaderProgram(this);
    m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSource);
    m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource);
    m_program->link();
    m_posAttr = m_program->attributeLocation("posAttr");
    m_colAttr = m_program->attributeLocation("colAttr");
    m_matrixUniform = m_program->uniformLocation("matrix");

    generateTerrain();
}
Пример #9
0
void CvMapGenerator::generateRandomMap()
{
	PROFILE_FUNC();

	gDLL->getPythonIFace()->callFunction(gDLL->getPythonIFace()->getMapScriptModule(), "beforeGeneration");

	if (gDLL->getPythonIFace()->pythonGenerateRandomMap() && !gDLL->getPythonIFace()->pythonUsingDefaultImpl())
	{
		return; // Python override
	}

	char buf[256];

	sprintf(buf, "Generating Random Map %S, %S...", gDLL->getMapScriptName().GetCString(), GC.getWorldInfo(GC.getMapINLINE().getWorldSize()).getDescription());
	gDLL->NiTextOut(buf);

	generatePlotTypes();
	generateTerrain();
}
Пример #10
0
void MapgenV7::makeChunk(BlockMakeData *data)
{
	assert(data->vmanip);
	assert(data->nodedef);
	assert(data->blockpos_requested.X >= data->blockpos_min.X &&
		   data->blockpos_requested.Y >= data->blockpos_min.Y &&
		   data->blockpos_requested.Z >= data->blockpos_min.Z);
	assert(data->blockpos_requested.X <= data->blockpos_max.X &&
		   data->blockpos_requested.Y <= data->blockpos_max.Y &&
		   data->blockpos_requested.Z <= data->blockpos_max.Z);

	this->generating = true;
	this->vm   = data->vmanip;
	this->ndef = data->nodedef;
	//TimeTaker t("makeChunk");

	v3s16 blockpos_min = data->blockpos_min;
	v3s16 blockpos_max = data->blockpos_max;
	node_min = blockpos_min * MAP_BLOCKSIZE;
	node_max = (blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1);
	full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE;
	full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3s16(1, 1, 1);

	blockseed = getBlockSeed2(full_node_min, seed);

	// Make some noise
	calculateNoise();

	// Generate base terrain, mountains, and ridges with initial heightmaps
	s16 stone_surface_max_y = generateTerrain();

	updateHeightmap(node_min, node_max);

	// Calculate biomes
	bmgr->calcBiomes(csize.X, csize.Z, noise_heat->result,
		noise_humidity->result, heightmap, biomemap);

	// Actually place the biome-specific nodes and what not
	generateBiomes();

	if (flags & MG_CAVES)
		generateCaves(stone_surface_max_y);

	if ((flags & MG_DUNGEONS) && (stone_surface_max_y >= node_min.Y)) {
		DungeonGen dgen(this, NULL);
		dgen.generate(blockseed, full_node_min, full_node_max);
	}

	// Generate the registered decorations
	m_emerge->decomgr->placeAllDecos(this, blockseed, node_min, node_max);

	// Generate the registered ores
	m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max);

	// Sprinkle some dust on top after everything else was generated
	dustTopNodes();

	//printf("makeChunk: %dms\n", t.stop());

	updateLiquid(&data->transforming_liquid, full_node_min, full_node_max);

	if (flags & MG_LIGHT)
		calcLighting(node_min, node_max);
	//setLighting(node_min - v3s16(1, 0, 1) * MAP_BLOCKSIZE,
	//			node_max + v3s16(1, 0, 1) * MAP_BLOCKSIZE, 0xFF);

	this->generating = false;
}
Пример #11
0
void MapgenV7::makeChunk(BlockMakeData *data)
{
	// Pre-conditions
	assert(data->vmanip);
	assert(data->nodedef);
	assert(data->blockpos_requested.X >= data->blockpos_min.X &&
		data->blockpos_requested.Y >= data->blockpos_min.Y &&
		data->blockpos_requested.Z >= data->blockpos_min.Z);
	assert(data->blockpos_requested.X <= data->blockpos_max.X &&
		data->blockpos_requested.Y <= data->blockpos_max.Y &&
		data->blockpos_requested.Z <= data->blockpos_max.Z);

	this->generating = true;
	this->vm   = data->vmanip;
	this->ndef = data->nodedef;
	//TimeTaker t("makeChunk");

	v3s16 blockpos_min = data->blockpos_min;
	v3s16 blockpos_max = data->blockpos_max;
	node_min = blockpos_min * MAP_BLOCKSIZE;
	node_max = (blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1);
	full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE;
	full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3s16(1, 1, 1);

	blockseed = getBlockSeed2(full_node_min, seed);

	// Generate base and mountain terrain
	// An initial heightmap is no longer created here for use in generateRidgeTerrain()
	s16 stone_surface_max_y = generateTerrain();

	// Generate rivers
	if (spflags & MGV7_RIDGES)
		generateRidgeTerrain();

	// Create heightmap
	updateHeightmap(node_min, node_max);

	// Init biome generator, place biome-specific nodes, and build biomemap
	biomegen->calcBiomeNoise(node_min);
	MgStoneType stone_type = generateBiomes();

	if (flags & MG_CAVES)
		generateCaves(stone_surface_max_y, water_level);

	if (flags & MG_DUNGEONS)
		generateDungeons(stone_surface_max_y, stone_type);

	// Generate the registered decorations
	if (flags & MG_DECORATIONS)
		m_emerge->decomgr->placeAllDecos(this, blockseed, node_min, node_max);

	// Generate the registered ores
	m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max);

	// Sprinkle some dust on top after everything else was generated
	dustTopNodes();

	//printf("makeChunk: %dms\n", t.stop());

	updateLiquid(&data->transforming_liquid, full_node_min, full_node_max);

	// Limit floatland shadow
	bool propagate_shadow = !((spflags & MGV7_FLOATLANDS) &&
		node_min.Y <= shadow_limit && node_max.Y >= shadow_limit);

	if (flags & MG_LIGHT)
		calcLighting(node_min - v3s16(0, 1, 0), node_max + v3s16(0, 1, 0),
			full_node_min, full_node_max, propagate_shadow);

	//setLighting(node_min - v3s16(1, 0, 1) * MAP_BLOCKSIZE,
	//			node_max + v3s16(1, 0, 1) * MAP_BLOCKSIZE, 0xFF);

	this->generating = false;
}
Пример #12
0
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
    QGLFormat glFormat;
    glFormat.setVersion(3, 3);
    glFormat.setProfile(QGLFormat::CoreProfile);
    glFormat.setSampleBuffers(true);

    viewer = new ModelViewer(glFormat, this);    
    connect(viewer, SIGNAL(openGLInitialized()), this, SLOT(setTerrain()));

    //--------------------------------------------------------------------------------

    QGroupBox *gbStaticOptions = new QGroupBox("Static", this);
    gbStaticOptions->setFlat(true);

    sbPCount = new QSpinBox(this);
    sbPCount->setRange(4, 100000);
    sbPCount->setSingleStep(50);
    sbPCount->setValue(10000);

    sbPSSize = new QSpinBox(this);
    sbPSSize->setRange(50, 1000);
    sbPSSize->setSingleStep(50);
    sbPSSize->setValue(400);

    sbTCSize = new QSpinBox(this);
    sbTCSize->setRange(1, 400);
    sbTCSize->setSingleStep(1);
    sbTCSize->setValue(2);

    QGridLayout *statLayout = new QGridLayout();
    statLayout->setContentsMargins(0, 0, 0, 0);
    statLayout->setSpacing(5);
    statLayout->setColumnStretch(0, 0);
    statLayout->setColumnStretch(1, 1);
    statLayout->addWidget(new QLabel("Max particles:", this), 1, 0);
    statLayout->addWidget(sbPCount, 1, 1);
    statLayout->addWidget(new QLabel("Cube size:", this), 2, 0);
    statLayout->addWidget(sbPSSize, 2, 1);
    statLayout->addWidget(new QLabel("Terrain grid size:", this), 3, 0);
    statLayout->addWidget(sbTCSize, 3, 1);
    gbStaticOptions->setLayout(statLayout);

    //--------------------------------------------------------------------------------

    QGroupBox *gbDynamicOptions = new QGroupBox("Dynamic", this);
    gbDynamicOptions->setFlat(true);

    QComboBox *cbBType = new QComboBox(this);
    cbBType->addItem("perspective");
    cbBType->addItem("fixed size");
    cbBType->setCurrentIndex(0);
    connect(cbBType, SIGNAL(currentIndexChanged(int)), viewer, SLOT(setBillboardType(int)));

    sbTDist = new QDoubleSpinBox(this);
    sbTDist->setRange(0, 100);
    sbTDist->setSingleStep(1);
    sbTDist->setValue(50);
    connect(sbTDist, SIGNAL(valueChanged(double)), viewer, SLOT(setDistanceThreshold(double)));

    QCheckBox *cbShowTerrain = new QCheckBox("Show skybox", this);
    cbShowTerrain->setChecked(true);
    connect(cbShowTerrain, SIGNAL(toggled(bool)), viewer, SLOT(setShowTerrain(bool)));

    QCheckBox *cbShowWireframe = new QCheckBox("Wireframe", this);
    cbShowWireframe->setChecked(false);
    connect(cbShowWireframe, SIGNAL(toggled(bool)), viewer, SLOT(setWireframeMode(bool)));

    QPushButton *pbGenerate = new QPushButton("Generate", this);
    connect(pbGenerate, SIGNAL(clicked()), this, SLOT(generateParticles()));

    QGridLayout *dynLayout = new QGridLayout();
    dynLayout->setContentsMargins(0, 0, 0, 0);
    dynLayout->setSpacing(5);
    dynLayout->setColumnStretch(0, 0);
    dynLayout->setColumnStretch(1, 1);
    dynLayout->addWidget(new QLabel("Billboard type:", this), 0, 0);
    dynLayout->addWidget(cbBType, 0, 1);
    dynLayout->addWidget(new QLabel("Thres distance:", this), 1, 0);
    dynLayout->addWidget(sbTDist, 1, 1);
    dynLayout->addWidget(cbShowTerrain, 2, 0, 1, 2);
    dynLayout->addWidget(cbShowWireframe, 3, 0, 1, 2);
    dynLayout->addWidget(pbGenerate, 4, 0, 1, 2);
    gbDynamicOptions->setLayout(dynLayout);

    //--------------------------------------------------------------------------------

    QGroupBox *gbTerrainOptions = new QGroupBox("Terrain", this);
    gbTerrainOptions->setFlat(true);

    cbTerrainTexture = new QComboBox(this);
    cbTerrainTexture->addItem("texture 1");
    connect(cbTerrainTexture, SIGNAL(currentIndexChanged(int)), this, SLOT(setTerrainTexture(int)));

    QComboBox *cbTerrainMode = new QComboBox(this);
    cbTerrainMode->addItem("texture");
    cbTerrainMode->addItem("normal");
    cbTerrainMode->addItem("facet norm.");
    cbTerrainMode->addItem("vertex norm.");
    connect(cbTerrainMode, SIGNAL(currentIndexChanged(int)), viewer, SLOT(setTerrainTexMode(int)));

    QDoubleSpinBox *sbContrast = new QDoubleSpinBox(this);
    sbContrast->setRange(0.1, 10.0);
    sbContrast->setSingleStep(0.1);
    sbContrast->setValue(1.0);
    connect(sbContrast, SIGNAL(valueChanged(double)), viewer, SLOT(setTerrainContrast(double)));

    sbTPers = new QSpinBox(this);
    sbTPers->setRange(1, 500);
//    sbTPers->setSingleStep(10);
    sbTPers->setValue(10);

    sbTFreq = new QSpinBox(this);
    sbTFreq->setRange(1, 500);
//    sbTFreq->setSingleStep(10);
    sbTFreq->setValue(10);

    sbTAmp = new QDoubleSpinBox(this);
    sbTAmp->setRange(0.1, 100.0);
    sbTAmp->setValue(30.0);

    sbTOct = new QSpinBox(this);
    sbTOct->setRange(1, 10);
    sbTOct->setValue(3);

    QPushButton *pbUpdateTerrain = new QPushButton("Update terrain", this);
    connect(pbUpdateTerrain, SIGNAL(clicked()), this, SLOT(generateTerrain()));

    QGridLayout *terLayout = new QGridLayout();
    terLayout->setContentsMargins(0, 0, 0, 0);
    terLayout->setSpacing(5);
    terLayout->addWidget(new QLabel("Texture:", this), 0, 0);
    terLayout->addWidget(cbTerrainTexture, 0, 1);
    terLayout->addWidget(new QLabel("Mode:", this), 1, 0);
    terLayout->addWidget(cbTerrainMode, 1, 1);
    terLayout->addWidget(new QLabel("Contrast:", this), 2, 0);
    terLayout->addWidget(sbContrast, 2, 1);
    terLayout->addWidget(new QLabel("Persistence:", this), 3, 0);
    terLayout->addWidget(sbTPers, 3, 1);
    terLayout->addWidget(new QLabel("Frequency:", this), 4, 0);
    terLayout->addWidget(sbTFreq, 4, 1);
    terLayout->addWidget(new QLabel("Amplitude:", this), 5, 0);
    terLayout->addWidget(sbTAmp, 5, 1);
    terLayout->addWidget(new QLabel("Octaves:", this), 6, 0);
    terLayout->addWidget(sbTOct, 6, 1);
    terLayout->addWidget(pbUpdateTerrain, 7, 0, 1, 2);
    gbTerrainOptions->setLayout(terLayout);

    //--------------------------------------------------------------------------------

    QGroupBox *gbCameraOptions = new QGroupBox("Camera", this);
    gbCameraOptions->setFlat(true);

    cbCameraMode = new QCheckBox("Single camera", this);
    cbCameraMode->setChecked(true);
    connect(cbCameraMode, SIGNAL(toggled(bool)), this, SLOT(setCameraMode(bool)));

    cbCurrentCamera = new QComboBox(this);
    cbCurrentCamera->addItem("particles");
    cbCurrentCamera->addItem("free");
    cbCurrentCamera->setEnabled(false);
    connect(cbCurrentCamera, SIGNAL(currentIndexChanged(int)), viewer, SLOT(setCurrentCamera(int)));

    QGridLayout *camLayout = new QGridLayout();
    camLayout->setContentsMargins(0, 0, 0, 0);
    camLayout->setSpacing(5);
    camLayout->addWidget(cbCameraMode, 0, 0, 1, 2);
    camLayout->addWidget(new QLabel("Camera:", this), 1, 0);
    camLayout->addWidget(cbCurrentCamera, 1, 1);
    gbCameraOptions->setLayout(camLayout);

    //--------------------------------------------------------------------------------

    QGroupBox *gbOptions = new QGroupBox("Options", this);
    QGridLayout *optLayout = new QGridLayout();
    optLayout->setSpacing(5);
    optLayout->setContentsMargins(5, 5, 5, 5);
    optLayout->setColumnStretch(0, 0);
    optLayout->setColumnStretch(1, 1);
    optLayout->addWidget(gbStaticOptions, 0, 0, 1, 2);
    optLayout->addWidget(gbDynamicOptions, 1, 0, 1, 2);
    optLayout->addWidget(gbTerrainOptions, 3, 0, 1, 2);
    optLayout->addWidget(gbCameraOptions, 4, 0, 1, 2);

    optLayout->setRowStretch(2, 1);
    gbOptions->setLayout(optLayout);

    QWidget *w = new QWidget(this);
    QHBoxLayout *layout = new QHBoxLayout();
    layout->setContentsMargins(5, 5, 5, 5);
    layout->setSpacing(5);
    layout->addWidget(viewer, 1);
    layout->addWidget(gbOptions, 0);
    w->setLayout(layout);

    this->setCentralWidget(w);
    this->setWindowTitle("CG Task 4");
}
Пример #13
0
void God::newGame(){
	redo = false;
	forgetAll();
	generateTerrain();
}
Пример #14
0
void MapgenV7::makeChunk(BlockMakeData *data) {
	assert(data->vmanip);
	assert(data->nodedef);
	assert(data->blockpos_requested.X >= data->blockpos_min.X &&
		   data->blockpos_requested.Y >= data->blockpos_min.Y &&
		   data->blockpos_requested.Z >= data->blockpos_min.Z);
	assert(data->blockpos_requested.X <= data->blockpos_max.X &&
		   data->blockpos_requested.Y <= data->blockpos_max.Y &&
		   data->blockpos_requested.Z <= data->blockpos_max.Z);
			
	this->generating = true;
	this->vm   = data->vmanip;	
	this->ndef = data->nodedef;
	//TimeTaker t("makeChunk");
	
	v3s16 blockpos_min = data->blockpos_min;
	v3s16 blockpos_max = data->blockpos_max;
	node_min = blockpos_min * MAP_BLOCKSIZE;
	node_max = (blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1);
	full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE;
	full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3s16(1, 1, 1);

	blockseed = emerge->getBlockSeed(full_node_min);  //////use getBlockSeed2()!
	
	// Make some noise
	calculateNoise();
	
	// Generate base terrain, mountains, and ridges with initial heightmaps
	s16 stone_surface_max_y = generateTerrain();
	
	updateHeightmap(node_min, node_max);
	
	// Calculate biomes
	BiomeNoiseInput binput;
	binput.mapsize      = v2s16(csize.X, csize.Z);
	binput.heat_map     = noise_heat->result;
	binput.humidity_map = noise_humidity->result;
	binput.height_map   = heightmap;
	bmgr->calcBiomes(&binput, biomemap);
	
	// Actually place the biome-specific nodes and what not
	generateBiomes();

	if (flags & MG_CAVES)
		generateCaves(stone_surface_max_y);

	if (flags & MG_DUNGEONS) {
		DungeonGen dgen(this, NULL);
		dgen.generate(blockseed, full_node_min, full_node_max);
	}

	for (size_t i = 0; i != emerge->decorations.size(); i++) {
		Decoration *deco = emerge->decorations[i];
		deco->placeDeco(this, blockseed + i, node_min, node_max);
	}

	for (size_t i = 0; i != emerge->ores.size(); i++) {
		Ore *ore = emerge->ores[i];
		ore->placeOre(this, blockseed + i, node_min, node_max);
	}
	
	// Sprinkle some dust on top after everything else was generated
	dustTopNodes();
	
	//printf("makeChunk: %dms\n", t.stop());
	
	updateLiquid(&data->transforming_liquid, full_node_min, full_node_max);
	
	if (flags & MG_LIGHT)
		calcLighting(node_min - v3s16(1, 0, 1) * MAP_BLOCKSIZE,
					 node_max + v3s16(1, 0, 1) * MAP_BLOCKSIZE);
	//setLighting(node_min - v3s16(1, 0, 1) * MAP_BLOCKSIZE,
	//			node_max + v3s16(1, 0, 1) * MAP_BLOCKSIZE, 0xFF);
	
	this->generating = false;
}
Пример #15
0
void MapgenCarpathian::makeChunk(BlockMakeData *data)
{
	// Pre-conditions
	assert(data->vmanip);
	assert(data->nodedef);
	assert(data->blockpos_requested.X >= data->blockpos_min.X &&
			data->blockpos_requested.Y >= data->blockpos_min.Y &&
			data->blockpos_requested.Z >= data->blockpos_min.Z);
	assert(data->blockpos_requested.X <= data->blockpos_max.X &&
			data->blockpos_requested.Y <= data->blockpos_max.Y &&
			data->blockpos_requested.Z <= data->blockpos_max.Z);

	this->generating = true;
	this->vm = data->vmanip;
	this->ndef = data->nodedef;

	v3s16 blockpos_min = data->blockpos_min;
	v3s16 blockpos_max = data->blockpos_max;
	node_min = blockpos_min * MAP_BLOCKSIZE;
	node_max = (blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1);
	full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE;
	full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3s16(1, 1, 1);

	// Create a block-specific seed
	blockseed = getBlockSeed2(full_node_min, seed);

	// Generate terrain
	s16 stone_surface_max_y = generateTerrain();

	// Create heightmap
	updateHeightmap(node_min, node_max);

	// Init biome generator, place biome-specific nodes, and build biomemap
	biomegen->calcBiomeNoise(node_min);

	MgStoneType mgstone_type;
	content_t biome_stone;
	generateBiomes(&mgstone_type, &biome_stone);

	// Generate caverns, tunnels and classic caves
	if (flags & MG_CAVES) {
		bool has_cavern = false;
		// Generate caverns
		if (spflags & MGCARPATHIAN_CAVERNS)
			has_cavern = generateCaverns(stone_surface_max_y);
		// Generate tunnels and classic caves
		if (has_cavern)
			// Disable classic caves in this mapchunk by setting
			// 'large cave depth' to world base. Avoids excessive liquid in
			// large caverns and floating blobs of overgenerated liquid.
			generateCaves(stone_surface_max_y, -MAX_MAP_GENERATION_LIMIT);
		else
			generateCaves(stone_surface_max_y, large_cave_depth);
	}

	// Generate dungeons
	if (flags & MG_DUNGEONS)
		generateDungeons(stone_surface_max_y, mgstone_type, biome_stone);

	// Generate the registered decorations
	if (flags & MG_DECORATIONS)
		m_emerge->decomgr->placeAllDecos(this, blockseed, node_min, node_max);

	// Generate the registered ores
	m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max);

	// Sprinkle some dust on top after everything else was generated
	dustTopNodes();

	// Update liquids
	updateLiquid(&data->transforming_liquid, full_node_min, full_node_max);

	// Calculate lighting
	if (flags & MG_LIGHT) {
		calcLighting(node_min - v3s16(0, 1, 0), node_max + v3s16(0, 1, 0),
				full_node_min, full_node_max);
	}

	this->generating = false;
}
Пример #16
0
void MapgenV7::makeChunk(BlockMakeData *data)
{
	// Pre-conditions
	assert(data->vmanip);
	assert(data->nodedef);
	assert(data->blockpos_requested.X >= data->blockpos_min.X &&
		data->blockpos_requested.Y >= data->blockpos_min.Y &&
		data->blockpos_requested.Z >= data->blockpos_min.Z);
	assert(data->blockpos_requested.X <= data->blockpos_max.X &&
		data->blockpos_requested.Y <= data->blockpos_max.Y &&
		data->blockpos_requested.Z <= data->blockpos_max.Z);

	this->generating = true;
	this->vm   = data->vmanip;
	this->ndef = data->nodedef;
	//TimeTaker t("makeChunk");

	v3s16 blockpos_min = data->blockpos_min;
	v3s16 blockpos_max = data->blockpos_max;
	node_min = blockpos_min * MAP_BLOCKSIZE;
	node_max = (blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1);
	full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE;
	full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3s16(1, 1, 1);

	blockseed = getBlockSeed2(full_node_min, seed);

	// Generate base and mountain terrain
	// An initial heightmap is no longer created here for use in generateRidgeTerrain()
	s16 stone_surface_max_y = generateTerrain();

	// Generate rivers
	if (spflags & MGV7_RIDGES)
		generateRidgeTerrain();

	// Create heightmap
	updateHeightmap(node_min, node_max);

	// Init biome generator, place biome-specific nodes, and build biomemap
	biomegen->calcBiomeNoise(node_min);

	MgStoneType mgstone_type;
	content_t biome_stone;
	generateBiomes(&mgstone_type, &biome_stone);

	// Generate caverns, tunnels and classic caves
	if (flags & MG_CAVES) {
		bool near_cavern = false;
		// Generate caverns
		if (spflags & MGV7_CAVERNS)
			near_cavern = generateCaverns(stone_surface_max_y);
		// Generate tunnels and classic caves
		if (near_cavern)
			// Disable classic caves in this mapchunk by setting
			// 'large cave depth' to world base. Avoids excessive liquid in
			// large caverns and floating blobs of overgenerated liquid.
			generateCaves(stone_surface_max_y, -MAX_MAP_GENERATION_LIMIT);
		else
			generateCaves(stone_surface_max_y, large_cave_depth);
	}

	// Generate dungeons
	if (flags & MG_DUNGEONS)
		generateDungeons(stone_surface_max_y, mgstone_type, biome_stone);

	// Generate the registered decorations
	if (flags & MG_DECORATIONS)
		m_emerge->decomgr->placeAllDecos(this, blockseed, node_min, node_max);

	// Generate the registered ores
	m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max);

	// Sprinkle some dust on top after everything else was generated
	dustTopNodes();

	//printf("makeChunk: %dms\n", t.stop());

	// Update liquids
	updateLiquid(&data->transforming_liquid, full_node_min, full_node_max);

	// Calculate lighting
	// Limit floatland shadow
	bool propagate_shadow = !((spflags & MGV7_FLOATLANDS) &&
		node_min.Y <= shadow_limit && node_max.Y >= shadow_limit);

	if (flags & MG_LIGHT)
		calcLighting(node_min - v3s16(0, 1, 0), node_max + v3s16(0, 1, 0),
			full_node_min, full_node_max, propagate_shadow);

	//setLighting(node_min - v3s16(1, 0, 1) * MAP_BLOCKSIZE,
	//			node_max + v3s16(1, 0, 1) * MAP_BLOCKSIZE, 0xFF);

	this->generating = false;
}
Пример #17
0
void MapgenFractal::makeChunk(BlockMakeData *data)
{
	// Pre-conditions
	assert(data->vmanip);
	assert(data->nodedef);
	assert(data->blockpos_requested.X >= data->blockpos_min.X &&
		data->blockpos_requested.Y >= data->blockpos_min.Y &&
		data->blockpos_requested.Z >= data->blockpos_min.Z);
	assert(data->blockpos_requested.X <= data->blockpos_max.X &&
		data->blockpos_requested.Y <= data->blockpos_max.Y &&
		data->blockpos_requested.Z <= data->blockpos_max.Z);

	this->generating = true;
	this->vm   = data->vmanip;
	this->ndef = data->nodedef;
	//TimeTaker t("makeChunk");

	v3s16 blockpos_min = data->blockpos_min;
	v3s16 blockpos_max = data->blockpos_max;
	node_min = blockpos_min * MAP_BLOCKSIZE;
	node_max = (blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1);
	full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE;
	full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3s16(1, 1, 1);

	blockseed = getBlockSeed2(full_node_min, seed);

	// Generate base terrain, mountains, and ridges with initial heightmaps
	s16 stone_surface_max_y = generateTerrain();

	// Create heightmap
	updateHeightmap(node_min, node_max);

	// Init biome generator, place biome-specific nodes, and build biomemap
	biomegen->calcBiomeNoise(node_min);
	generateBiomes();

	if (flags & MG_CAVES) {
		// Generate tunnels
		generateCavesNoiseIntersection(stone_surface_max_y);
		// Generate large randomwalk caves
		generateCavesRandomWalk(stone_surface_max_y, large_cave_depth);
	}

	if ((flags & MG_DUNGEONS) && full_node_min.Y >= dungeon_ymin &&
			full_node_max.Y <= dungeon_ymax)
		generateDungeons(stone_surface_max_y);

	// Generate the registered decorations
	if (flags & MG_DECORATIONS)
		m_emerge->decomgr->placeAllDecos(this, blockseed, node_min, node_max);

	// Generate the registered ores
	m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max);

	// Sprinkle some dust on top after everything else was generated
	dustTopNodes();

	//printf("makeChunk: %dms\n", t.stop());

	updateLiquid(&data->transforming_liquid, full_node_min, full_node_max);

	if (flags & MG_LIGHT)
		calcLighting(node_min - v3s16(0, 1, 0), node_max + v3s16(0, 1, 0),
			full_node_min, full_node_max);

	//setLighting(node_min - v3s16(1, 0, 1) * MAP_BLOCKSIZE,
	//			node_max + v3s16(1, 0, 1) * MAP_BLOCKSIZE, 0xFF);

	this->generating = false;
}
Пример #18
0
void MapgenValleys::makeChunk(BlockMakeData *data)
{
	// Pre-conditions
	assert(data->vmanip);
	assert(data->nodedef);
	assert(data->blockpos_requested.X >= data->blockpos_min.X &&
		data->blockpos_requested.Y >= data->blockpos_min.Y &&
		data->blockpos_requested.Z >= data->blockpos_min.Z);
	assert(data->blockpos_requested.X <= data->blockpos_max.X &&
		data->blockpos_requested.Y <= data->blockpos_max.Y &&
		data->blockpos_requested.Z <= data->blockpos_max.Z);

	this->generating = true;
	this->vm = data->vmanip;
	this->ndef = data->nodedef;

	//TimeTaker t("makeChunk");

	v3s16 blockpos_min = data->blockpos_min;
	v3s16 blockpos_max = data->blockpos_max;
	node_min = blockpos_min * MAP_BLOCKSIZE;
	node_max = (blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1);
	full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE;
	full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3s16(1, 1, 1);

	blockseed = getBlockSeed2(full_node_min, seed);

	// Generate noise maps and base terrain height.
	calculateNoise();

	// Generate biome noises.  Note this must be executed strictly before
	// generateTerrain, because generateTerrain depends on intermediate
	// biome-related noises.
	m_bgen->calcBiomeNoise(node_min);

	// Generate base terrain with initial heightmaps
	s16 stone_surface_max_y = generateTerrain();

	// Build biomemap
	m_bgen->getBiomes(heightmap);

	// Place biome-specific nodes
	MgStoneType stone_type = generateBiomes();

	// Cave creation.
	if (flags & MG_CAVES)
		generateCaves(stone_surface_max_y, large_cave_depth);

	// Dungeon creation
	if ((flags & MG_DUNGEONS) && node_max.Y < 50)
		generateDungeons(stone_surface_max_y, stone_type);

	// Generate the registered decorations
	if (flags & MG_DECORATIONS)
		m_emerge->decomgr->placeAllDecos(this, blockseed, node_min, node_max);

	// Generate the registered ores
	m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max);

	// Sprinkle some dust on top after everything else was generated
	dustTopNodes();

	//TimeTaker tll("liquid_lighting");

	updateLiquid(&data->transforming_liquid, full_node_min, full_node_max);

	if (flags & MG_LIGHT)
		calcLighting(
				node_min - v3s16(0, 1, 0),
				node_max + v3s16(0, 1, 0),
				full_node_min,
				full_node_max);

	//mapgen_profiler->avg("liquid_lighting", tll.stop() / 1000.f);
	//mapgen_profiler->avg("makeChunk", t.stop() / 1000.f);

	this->generating = false;
}
Пример #19
0
int game(SHIP ship, int seed) {
	srand(seed);
	int gamestate = DRAWINIT;
	int screenWidth = 240;
	int screenHeight = 160;
	int lives = 5;
	int timer = 0;
	int gravity = 1;
	int playing = 1;

	// Create old ship
	SHIP shipbase = ship;
	SHIP oldship = ship;

	// Create landing pad
	LANDINGPAD p = createLandingPad(ship);

	// Create terrain
	int NUMTERRAIN = screenWidth;
	TERRAIN *terrain = generateTerrain(p);

	int i;
	// Game Loop
	while(1){
	switch(gamestate) {
	case PAUSE:
		while(!(KEY_DOWN_NOW(BUTTON_LEFT) || 
		KEY_DOWN_NOW(BUTTON_RIGHT) || 
		KEY_DOWN_NOW(BUTTON_UP)||
		KEY_DOWN_NOW(BUTTON_SELECT)));

		if(KEY_DOWN_NOW(BUTTON_LEFT) || 
		KEY_DOWN_NOW(BUTTON_RIGHT) || 
		KEY_DOWN_NOW(BUTTON_UP));
		{
			gamestate = DRAWINIT;
			
		}
		// Return to title when select is pressed
		if(KEY_DOWN_NOW(BUTTON_SELECT))
		{
			return TITLE;
		}
		playing = 1;
		gamestate = START;
		break;
	case DRAWINIT:
		// Set initial background
		DMA[3].src = BG;
		DMA[3].dst = videoBuffer;
		DMA[3].cnt = DMA_ON | 38400;

		// Draw the ship
		drawShip(ship);

		// Draw Lives
		drawLives(lives);

		// Draw the landing pad
		drawRect(p.row, p.col, p.length, p.width, p.color);

		// Draw the terrain
		drawTerrain(terrain);

		gamestate = PAUSE;
		break;
	case START:

	while(playing) {
/////////////////// BUTTON CONTROLS //////////////////

		// Return to title when select is pressed
		if(KEY_DOWN_NOW(BUTTON_SELECT))
		{
			return TITLE;
		}
		// Left movement
		if(KEY_DOWN_NOW(BUTTON_LEFT) && ship.fuel > 0)
		{
			if(ship.col > 0)
			{
				ship.col-=ship.cdel;
				ship.fuel--;
			}
		}
		// Right movement
		if(KEY_DOWN_NOW(BUTTON_RIGHT) && ship.fuel > 0)
		{
			if(ship.col+ship.width < screenWidth)
			{
				ship.col+=ship.cdel;
				ship.fuel--;
			}
		}
		// Account for gravity and thrust
		if(KEY_DOWN_NOW(BUTTON_UP) && ship.fuel > 0)
		{
			if(timer > 5)
			{
				timer = 0;
				ship.rdel-=ship.thrust;
			}
			else
			{
				timer++;
			}
			ship.row+=ship.rdel;
			ship.fuel--;
		}
		else
		{
			ship.row+=ship.rdel;
			if(timer > 5)
			{
				timer = 0;
				ship.rdel+=gravity;
			}
			else
			{
				timer++;
			}
		}
		
		waitForVblank();

///////////////////////// Collision Check //////////////////////////

		// Check pad landing
		if((ship.row+ship.length >= p.row) && 
		(ship.row+ship.length/2 < p.row+p.length) &&
		(ship.col+ship.width/2 > p.col) && 
		(ship.col-ship.width/2 < p.col + p.width))
		{
			ship.row = p.row - ship.length;
			clearShip(oldship);
			drawShip(ship);
			return WIN;
		}
		// Check ground collision
		if((ship.row+ship.length >= screenHeight) && lives > 0)
		{
			clearShip(oldship);
			ship = shipbase;
			lives--;
			clearLives(lives);
			oldship = ship;
			gamestate = PAUSE;
			playing = 0;
		}

		// Check terrain collision
		for (i = 0; i < NUMTERRAIN; i += 1)
		{
			if((ship.row+ship.length >= terrain[i].row) && 				(ship.col+ship.width > terrain[i].col) && 
			(ship.col < terrain[i].col + terrain[i].width) && 				(ship.row <= terrain[i].row+terrain[i].length))
			{
				clearShip(oldship);
				ship = shipbase;
				lives--;
				clearLives(lives);
				oldship = ship;
				gamestate = PAUSE;
				playing = 0;
			}
		}

		// Draw if more lives after collision
		if(lives > 0) 
		{
			// Draw lives
			drawLives(lives);

			// Draw the ship
			clearShip(oldship);
			drawShip(ship);
		}

		// Check lives
		if(lives <= 0)
		{
			clearShip(oldship);
			drawShip(ship);
			return LOSE;
		}

		oldship = ship;
	}
		break;
	}
	}
	return TITLE;
}
GeometryTerrain::GeometryTerrain(int size, int patch_size, int num_hills, float smoothness, int smooth_passes )
: m_Width(size), 
  m_Length(size),
  m_patchSize(patch_size)
{
	if(patch_size < 2) patch_size = 2;
	if(patch_size > size) patch_size = size;

	m_pHeight	= new float*[m_Width+1];

	m_fOffsetX = 1.0f;
	m_fOffsetY = 1.0f;
	m_fOffsetZ = 1.0f;

	for(int i = 0; i <= m_Length; i++)
	{		
		m_pHeight[i] = new float[m_Width+1];
		memset(m_pHeight[i], 0, sizeof(float)*(m_Length+1));
	}

	m_pVertices = NULL;

	m_nVertexCount = ((unsigned int)GetWidth()+1)*((unsigned int)GetLength()+1);

	//memset(m_pVertices, 0, m_nVertexCount);
	//memset(m_pNormals, 0, m_nVertexCount);


	m_pVertices		= new flx_Vertex[m_nVertexCount];
	m_pTexCoords	= new flx_TexCoord[m_nVertexCount];
	m_pNormals		= new flx_Normal[m_nVertexCount];

	//Add some random Hills and smooth it
	generateTerrain(num_hills);
	for(int i = 0; i < smooth_passes; ++i)
		smoothTerrain(smoothness);

	int deg_x = 0, deg_z = 0;
	for(int z = 0; z <= GetLength(); z++)
	{
		for(int x = 0; x <= GetWidth(); x++)
		{
			//fill Vertex array with data
			m_pVertices[x + z * (GetWidth()+1)].x = (float)x * m_fOffsetX;
			m_pVertices[x + z * (GetWidth()+1)].y = getHeight(x, z);
			m_pVertices[x + z * (GetWidth()+1)].z = (float)z * m_fOffsetZ;

			//fill TexCoord array with data
			m_pTexCoords[x + z * (GetWidth()+1)].u = (float)((float)x/(GetWidth()+1));
			m_pTexCoords[x + z * (GetWidth()+1)].v = (float)((float)z/(GetWidth()+1));
		}
	}

	//Create Indices
	for(int z = 0; z < GetLength()-1; z++)
	{
		//Even rows move left to right
		if(z % 2 == 0)
		{
			int x;
			for(x = 0; x < GetWidth(); x++)
			{
				m_Indices.push_back( x + (z * GetWidth()) );
				m_Indices.push_back( x + (z * GetWidth()) + GetWidth() );
			}

			if(z != GetLength() - 2 ) 
				m_Indices.push_back( --x + (z * GetWidth()) );
		}
		else
		{
			//odd rows move right to left
			int x;
			for(x = GetWidth() -1; x >= 0; x--)
			{
				m_Indices.push_back( x + (z * GetWidth()) );
				m_Indices.push_back( x + (z * GetWidth()) + GetWidth() );
			}

			if(z != GetLength() - 2 ) 
				m_Indices.push_back( ++x + (z * GetWidth()) );
		}
	}

	
	//Fill the buffers with data
	//VertexBuffer.setElementList(m_pVertices, m_nVertexCount);
	//TexCoordBuffer.setElementList(m_pTexCoords, m_nVertexCount);

	//...and calculate the Normals
	computeNormals();

	//Buffers ready to bind!
	//NormalBuffer.build(GL_ARRAY_BUFFER, GL_NORMAL_ARRAY);
	//VertexBuffer.build(GL_ARRAY_BUFFER, GL_VERTEX_ARRAY);
	//TexCoordBuffer.build(GL_ARRAY_BUFFER, GL_TEXTURE_COORD_ARRAY);
	
	buildPatches(0);

	//delete [] m_pVertices; m_pVertices = NULL;
	//delete [] m_pTexCoords; m_pTexCoords = NULL;
	//delete [] m_pNormals; m_pNormals = NULL;
}
Пример #21
0
void MapgenV7P::makeChunk(BlockMakeData *data)
{
	// Pre-conditions
	assert(data->vmanip);
	assert(data->nodedef);
	assert(data->blockpos_requested.X >= data->blockpos_min.X &&
		data->blockpos_requested.Y >= data->blockpos_min.Y &&
		data->blockpos_requested.Z >= data->blockpos_min.Z);
	assert(data->blockpos_requested.X <= data->blockpos_max.X &&
		data->blockpos_requested.Y <= data->blockpos_max.Y &&
		data->blockpos_requested.Z <= data->blockpos_max.Z);

	this->generating = true;
	this->vm = data->vmanip;
	this->ndef = data->nodedef;

	v3s16 blockpos_min = data->blockpos_min;
	v3s16 blockpos_max = data->blockpos_max;
	node_min = blockpos_min * MAP_BLOCKSIZE;
	node_max = (blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1);
	full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE;
	full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3s16(1, 1, 1);

	blockseed = getBlockSeed2(full_node_min, seed);

	if (node_max.Y <= bedrock_level) {
		// Only generate bedrock
		generateBedrock();
	} else {
		// Generate base and mountain terrain
		s16 stone_surface_max_y = generateTerrain();

		// Generate rivers
		if (spflags & MGV7P_RIDGES)
			generateRidgeTerrain();

		// Create heightmap
		updateHeightmap(node_min, node_max);

		// Init biome generator, place biome-specific nodes, and build biomemap
		biomegen->calcBiomeNoise(node_min);
		MgStoneType stone_type = generateBiomes();

		// Generate mgv6 caves but not deep into bedrock
		if (flags & MG_CAVES)
			generateCaves(stone_surface_max_y, water_level);

		// Generate dungeons
		if (flags & MG_DUNGEONS)
			generateDungeons(stone_surface_max_y, stone_type);

		// Generate the registered decorations
		if (flags & MG_DECORATIONS)
			m_emerge->decomgr->placeAllDecos(this, blockseed, node_min, node_max);

		// Generate the registered ores
		m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max);

		// Sprinkle some dust on top after everything else was generated
		dustTopNodes();

		// Update liquids
		updateLiquid(&data->transforming_liquid, full_node_min, full_node_max);
	}

	// Calculate lighting
	if (flags & MG_LIGHT)
		calcLighting(node_min - v3s16(0, 1, 0), node_max + v3s16(0, 1, 0),
			full_node_min, full_node_max, true);

	this->generating = false;
}
Пример #22
0
void MapgenV7::makeChunk(BlockMakeData *data)
{
	// Pre-conditions
	assert(data->vmanip);
	assert(data->nodedef);
	assert(data->blockpos_requested.X >= data->blockpos_min.X &&
		data->blockpos_requested.Y >= data->blockpos_min.Y &&
		data->blockpos_requested.Z >= data->blockpos_min.Z);
	assert(data->blockpos_requested.X <= data->blockpos_max.X &&
		data->blockpos_requested.Y <= data->blockpos_max.Y &&
		data->blockpos_requested.Z <= data->blockpos_max.Z);

	this->generating = true;
	this->vm   = data->vmanip;
	this->ndef = data->nodedef;
	//TimeTaker t("makeChunk");

	v3s16 blockpos_min = data->blockpos_min;
	v3s16 blockpos_max = data->blockpos_max;
	node_min = blockpos_min * MAP_BLOCKSIZE;
	node_max = (blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1);
	full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE;
	full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3s16(1, 1, 1);

	blockseed = getBlockSeed2(full_node_min, seed);

	// Make some noise
	calculateNoise();

	// Generate base terrain, mountains, and ridges with initial heightmaps
	s16 stone_surface_max_y = generateTerrain();

	// Create heightmap
	updateHeightmap(node_min, node_max);

	// Create biomemap at heightmap surface
	bmgr->calcBiomes(csize.X, csize.Z, noise_heat->result,
		noise_humidity->result, heightmap, biomemap);

	// Actually place the biome-specific nodes
	MgStoneType stone_type = generateBiomes(noise_heat->result, noise_humidity->result);

	if (flags & MG_CAVES)
		generateCaves(stone_surface_max_y);

	if ((flags & MG_DUNGEONS) && (stone_surface_max_y >= node_min.Y)) {
		DungeonParams dp;

		dp.np_rarity  = nparams_dungeon_rarity;
		dp.np_density = nparams_dungeon_density;
		dp.np_wetness = nparams_dungeon_wetness;
		dp.c_water    = c_water_source;
		if (stone_type == STONE) {
			dp.c_cobble = c_cobble;
			dp.c_moss   = c_mossycobble;
			dp.c_stair  = c_stair_cobble;

			dp.diagonal_dirs = false;
			dp.mossratio     = 3.0;
			dp.holesize      = v3s16(1, 2, 1);
			dp.roomsize      = v3s16(0, 0, 0);
			dp.notifytype    = GENNOTIFY_DUNGEON;
		} else if (stone_type == DESERT_STONE) {
			dp.c_cobble = c_desert_stone;
			dp.c_moss   = c_desert_stone;
			dp.c_stair  = c_desert_stone;

			dp.diagonal_dirs = true;
			dp.mossratio     = 0.0;
			dp.holesize      = v3s16(2, 3, 2);
			dp.roomsize      = v3s16(2, 5, 2);
			dp.notifytype    = GENNOTIFY_TEMPLE;
		} else if (stone_type == SANDSTONE) {
			dp.c_cobble = c_sandstonebrick;
			dp.c_moss   = c_sandstonebrick;
			dp.c_stair  = c_sandstonebrick;

			dp.diagonal_dirs = false;
			dp.mossratio     = 0.0;
			dp.holesize      = v3s16(2, 2, 2);
			dp.roomsize      = v3s16(2, 0, 2);
			dp.notifytype    = GENNOTIFY_DUNGEON;
		}

		DungeonGen dgen(this, &dp);
		dgen.generate(blockseed, full_node_min, full_node_max);
	}

	// Generate the registered decorations
	m_emerge->decomgr->placeAllDecos(this, blockseed, node_min, node_max);

	// Generate the registered ores
	m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max);

	// Sprinkle some dust on top after everything else was generated
	dustTopNodes();

	//printf("makeChunk: %dms\n", t.stop());

	updateLiquid(&data->transforming_liquid, full_node_min, full_node_max);

	if (flags & MG_LIGHT)
		calcLighting(node_min - v3s16(0, 1, 0), node_max + v3s16(0, 1, 0),
			full_node_min, full_node_max);

	//setLighting(node_min - v3s16(1, 0, 1) * MAP_BLOCKSIZE,
	//			node_max + v3s16(1, 0, 1) * MAP_BLOCKSIZE, 0xFF);

	this->generating = false;
}
Пример #23
0
void MapgenV7::makeChunk(BlockMakeData *data) {
	assert(data->vmanip);
	assert(data->nodedef);
	assert(data->blockpos_requested.X >= data->blockpos_min.X &&
		   data->blockpos_requested.Y >= data->blockpos_min.Y &&
		   data->blockpos_requested.Z >= data->blockpos_min.Z);
	assert(data->blockpos_requested.X <= data->blockpos_max.X &&
		   data->blockpos_requested.Y <= data->blockpos_max.Y &&
		   data->blockpos_requested.Z <= data->blockpos_max.Z);
			
	this->generating = true;
	this->vm   = data->vmanip;	
	this->ndef = data->nodedef;
	//TimeTaker t("makeChunk");
	
	v3s16 blockpos_min = data->blockpos_min;
	v3s16 blockpos_max = data->blockpos_max;
	v3s16 blockpos_full_min = blockpos_min - v3s16(1, 1, 1);
	v3s16 blockpos_full_max = blockpos_max + v3s16(1, 1, 1);
	node_min = blockpos_min * MAP_BLOCKSIZE;
	node_max = (blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1);
	full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE;
	full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3s16(1, 1, 1);

	blockseed = emerge->getBlockSeed(full_node_min);  //////use getBlockSeed2()!

	// Make some noise
	calculateNoise();

	// Calculate height map
	s16 stone_surface_max_y = calcHeightMap();
	
	// Calculate biomes
	BiomeNoiseInput binput;
	binput.mapsize       = v2s16(csize.X, csize.Z);
	binput.heat_map      = noise_heat->result;
	binput.humidity_map  = noise_humidity->result;
	binput.height_map    = heightmap;
	bmgr->calcBiomes(&binput, biomemap);
	
	c_stone           = ndef->getId("mapgen_stone");
	c_dirt            = ndef->getId("mapgen_dirt");
	c_dirt_with_grass = ndef->getId("mapgen_dirt_with_grass");
	c_sand            = ndef->getId("mapgen_sand");
	c_water_source    = ndef->getId("mapgen_water_source");
	c_lava_source     = ndef->getId("mapgen_lava_source");
	
	generateTerrain();
	carveRidges();
	
	generateCaves(stone_surface_max_y);
	addTopNodes();
	//v3s16 central_area_size = node_max - node_min + v3s16(1,1,1);

	if (flags & MG_DUNGEONS) {
		DungeonGen dgen(ndef, data->seed, water_level);
		dgen.generate(vm, blockseed, full_node_min, full_node_max);
	}

	for (size_t i = 0; i != emerge->ores.size(); i++) {
		Ore *ore = emerge->ores[i];
		ore->placeOre(this, blockseed + i, node_min, node_max);
	}
	
	//printf("makeChunk: %dms\n", t.stop());
	
	updateLiquid(&data->transforming_liquid, full_node_min, full_node_max);
	
	calcLighting(node_min - v3s16(1, 0, 1) * MAP_BLOCKSIZE,
				 node_max + v3s16(1, 0, 1) * MAP_BLOCKSIZE);
	//setLighting(node_min - v3s16(1, 0, 1) * MAP_BLOCKSIZE,
	//			node_max + v3s16(1, 0, 1) * MAP_BLOCKSIZE, 0xFF);

	this->generating = false;
}