//-------------------------------------------------------------- // rebuild a chunk of terrain off the buildList BOOL Landscape::rebuildTerrain() { BOOL moreWork = false; // rebuild a chunk off the build list if (m_buildList.length() > 0) { Terrain* chunk = (Terrain*) m_buildList.pop(); chunk->createHeightmap(); chunk->m_rebuildBuffers = true; moreWork = m_buildList.length() > 0; } return moreWork; }
//-------------------------------------------------------------- // initialize application void Landscape::appInit() { MovementApp::appInit(); mgPlatform->setWindowTitle("Landscape, Part 58"); // create the help pane m_help = new HelpUI(m_options); setUI(m_help); // load textures loadTextures(); // load shaders mgVertex::loadShader("litTexture"); mgVertex::loadShader("unlitTexture"); mgVertexTA::loadShader("litTextureArray"); VertexTerrain::loadShader("terrain"); mgVertex::loadShader("water"); // create the sky m_lightDir = mgPoint3(0.0, 0.5, 1.0); m_lightColor = mgPoint3(0.8, 0.8, 0.8); m_lightAmbient = mgPoint3(0.2, 0.2, 0.2); m_fogColor = mgPoint3(0.8, 0.8, 0.8); m_fogMaxDist = 13000.0; m_fogTopHeight = 2000.0; // WATER_LEVEL + 128.0;// m_fogMaxDist; m_fogBotHeight = WATER_LEVEL; m_fogBotInten = 1.0; m_fogTopInten = 0.8; m_sky = new StarrySky(m_options); m_sky->setFogInten(m_fogBotInten, m_fogTopInten); m_sky->setMoonDir(m_lightDir); m_sky->setSunDir(m_lightDir); setDayLight(true); m_maxCount = 0; // number of terrain chunks in use // generate the initial terrain for (int x = 0; x <= 2; x++) { for (int z = 0; z <= 2; z++) { Terrain* chunk = new Terrain( (x-1) * HORIZON_SIZE - HORIZON_SIZE/2, (z-1) * HORIZON_SIZE - HORIZON_SIZE/2, HORIZON_SIZE, HORIZON_SIZE); chunk->createHeightmap(); m_terrain[x][z] = chunk; } } // subdivide terrain around the eye checkTerrainResolution(); m_mapView = false; m_terrainGrid = GRID_TERRAIN; m_mapGrid = GRID_CHUNKS; m_eyeHeight = 1.75; m_eyePt = mgPoint3(7012.1, 358.22, -6287.94); // nice area for initial coordinate double ht = Terrain::heightAtPt(m_eyePt.x, m_eyePt.z); ht = max(ht, WATER_LEVEL); m_eyePt.y = ht + m_eyeHeight; m_eyeRotX = 4.4; m_eyeRotY = 2.84; m_eyeRotZ = 0.0; // init threads m_threadCount = m_options.getInteger("threadCount", 1); m_buildLock = mgOSLock::create(); m_shutdown = false; if (m_threadCount > 0) { m_buildEvent = mgOSEvent::create(); m_buildThreads = mgOSThread::create(m_threadCount, buildThreadProc, mgOSThread::PRIORITY_LOW, this, NULL); } }