예제 #1
0
void PrefWindow::OnDealFinished()
{
	windowState.Reset();
	updateGameView();
	windowState.WaitingState = WWS_WaitClick;
	const Preference::PrefGameModel* model = PrefSlots::getGameModel();
	PrefAssert( model != 0 );
	std::vector<int> bullets(3);
	std::vector<int> mountains(3);
	std::vector< std::vector<int> > whists(3, std::vector<int>(3));
	for( int i = 0; i < 3; i++ ) {
		bullets[i] = model->GetBullet(i);
		mountains[i] = model->GetMountain(i);
		for( int j = 0; j < 3; j++ ) {
			whists[i][j] = model->GetWhists(i, j);
		}
	}
	gameView->UpdateBulletInfo(bullets, mountains, whists);
	gameView->ShowBullet();
}
예제 #2
0
파일: world.cpp 프로젝트: DZvO/awesome
void motor::World::generate()
{
	//DEBUG
	for (int z = 0; z < int(worldDimZ * chunkSizeZ); ++z)
		for (int x = 0; x < int(worldDimX * chunkSizeX); ++x)
		{
			for (int y = 0; y < int(worldDimY * chunkSizeY); ++y)
			{
				setBlock(x, y, z, BLOCK_AIR);
			}
		}
	//DEBUG
	memoryAllocationRam = memoryAllocationGfx = 0;

	float random = 0;
	int mX, mY;
	SDL_GetMouseState(&mX, &mY);
	random = (mX * mY);
	cout << "random seed: " << random << "\n";
//#define DEBUG
#ifndef DEBUG
	PerlinNoise base(0, 0, 0, 0, random);
	base.setPersistence(0.4);
	base.setFrequency(0.4);
	base.setAmplitude(1.5);
	base.setOctaves(6);

	PerlinNoise mountains(0, 0, 0, 0, random);
	mountains.setPersistence(1.0);
	mountains.setFrequency(0.1);
	mountains.setAmplitude(14.5);
	mountains.setOctaves(1);

	PerlinNoise sand(0.6, 0.15, 0.8, 3, random);

	for (int z = 0; z < int(worldDimZ * chunkSizeZ); ++z)
		for (int x = 0; x < int(worldDimX * chunkSizeX); ++x)
		{
			float fBase = base.getHeight(x, z);
			float fMountains = mountains.getHeight(x, z);
			float fSand = sand.getHeight(x, z);

			float Height = fBase * worldDimY / 4 + worldDimY / 3;
			Height += fMountains > 0 ? fMountains : 0;

			if(Height < 0)
				Height = 1;

			for (int y = 0; y < Height; ++y)
			{
				if(fMountains > 1.4)
					setBlock(x, y, z, BLOCK_DIRT);
				else if(Height == 1)
					setBlock(x, y, z, BLOCK_DIRT);
				else
					setBlock(x, y, z, BLOCK_STONE);
			}

			if(fSand > 0.5)
				setBlock(x, int(Height), z, BLOCK_SAND);
		}
#else
	//for (int z = 0; z < int(worldDimZ * chunkSizeZ); ++z)
		//for (int x = 0; x < int(worldDimX * chunkSizeX); ++x)
		//{
//
			//float Height = 1;
			//for (int y = 0; y < Height; ++y)
			//{
				//setBlock(x, y, z, BLOCK_STONE);
			//}
		//}
	for (int z = 0; z < int(worldDimZ * chunkSizeZ); ++z)
		for (int x = 0; x < int(worldDimX * chunkSizeX); ++x)
		{
			for (int y = 0; y < int(worldDimY * chunkSizeY); ++y)
			{
				setBlock(x, y, z, BLOCK_STONE);
			}
		}
#endif

	unsigned int vertices = 0;
	for(unsigned int i = 0; i < worldDimX; i++)
		for(unsigned int j = 0; j < worldDimY; j++)
			for(unsigned int k = 0; k < worldDimZ; k++)
			{
				vertices += chunks[i][j][k].calculateVisibleSides(i * chunkSizeX, j * chunkSizeY, k * chunkSizeZ, false);
				chunks[i][j][k].uploadToVbo();

				memoryAllocationRam += chunks[i][j][k].memoryAllocationRam;
				memoryAllocationGfx += chunks[i][j][k].memoryAllocationGfx;
			}
	cout << worldDimX * worldDimY * worldDimZ << " chunks, " << vertices << " vertices, with a ";
	cout << "total of " << float(memoryAllocationRam) / 1000.f << " kB RAM, " << float(memoryAllocationGfx) / 1000.f << " kB Gfx memory used (probably more :>)" << endl;
}