2009-05-15 07:04:50 +00:00
|
|
|
/*
|
|
|
|
OpenMW - The completely unofficial reimplementation of Morrowind
|
|
|
|
Copyright (C) 2009 Jacob Essex, Nicolay Korslund
|
|
|
|
WWW: http://openmw.sourceforge.net/
|
|
|
|
|
|
|
|
This file (cpp_terrain.cpp) is part of the OpenMW package.
|
|
|
|
|
|
|
|
OpenMW is distributed as free software: you can redistribute it
|
|
|
|
and/or modify it under the terms of the GNU General Public License
|
|
|
|
version 3, as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
version 3 along with this program. If not, see
|
|
|
|
http://www.gnu.org/licenses/ .
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Shader names
|
|
|
|
#define MORPH_VERTEX_PROGRAM "mw_terrain_VS"
|
|
|
|
#define FADE_FRAGMENT_PROGRAM "mw_terrain_texfade_FP"
|
|
|
|
|
|
|
|
// Directories
|
|
|
|
#define TEXTURE_OUTPUT "cache/terrain/"
|
|
|
|
#define TERRAIN_OUTPUT "cache/terrain/landscape"
|
|
|
|
|
|
|
|
///no texture assigned
|
|
|
|
const int LAND_LTEX_NONE = 0;
|
|
|
|
|
|
|
|
///the default land height that it defaults to in the TESCS
|
|
|
|
const int LAND_DEFAULT_HEIGHT = -2048;
|
|
|
|
|
|
|
|
///how many verts wide (and long) the cell is
|
|
|
|
const int LAND_VERT_WIDTH = 65;
|
|
|
|
|
|
|
|
///Number of verts that make up a cell
|
|
|
|
const int LAND_NUM_VERTS = LAND_VERT_WIDTH*LAND_VERT_WIDTH;
|
|
|
|
|
|
|
|
const int LAND_LTEX_WIDTH = 16;
|
|
|
|
const int LAND_NUM_LTEX = LAND_LTEX_WIDTH*LAND_LTEX_WIDTH;
|
|
|
|
|
2009-05-16 17:58:08 +00:00
|
|
|
// Multiplied with the size of the quad. If these are too close, a
|
|
|
|
// quad might end up splitting/unsplitting continuously, since the
|
|
|
|
// quad size changes when we split.
|
|
|
|
const float SPLIT_FACTOR = 0.5;
|
|
|
|
const float UNSPLIT_FACTOR = 2.0;
|
|
|
|
|
2009-05-15 07:04:50 +00:00
|
|
|
//stops it crashing, now it leaks.
|
|
|
|
#define ENABLED_CRASHING 0
|
|
|
|
|
|
|
|
class Quad;
|
|
|
|
class QuadData;
|
2009-05-16 17:58:08 +00:00
|
|
|
class MaterialGenerator;
|
2009-05-16 18:47:49 +00:00
|
|
|
class HeightMap;
|
2009-05-16 20:13:33 +00:00
|
|
|
class TerrainMesh;
|
2009-05-16 17:58:08 +00:00
|
|
|
|
2009-05-16 18:47:49 +00:00
|
|
|
HeightMap *g_heightMap;
|
2009-05-16 20:13:33 +00:00
|
|
|
Quad *g_rootQuad;
|
2009-05-16 17:58:08 +00:00
|
|
|
MaterialGenerator *g_materialGen;
|
|
|
|
|
|
|
|
#undef TRACE
|
|
|
|
#define TRACE(x)
|
2009-05-15 07:04:50 +00:00
|
|
|
|
|
|
|
// Prerequisites
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
|
|
|
#include <fstream>
|
|
|
|
#include <string>
|
|
|
|
#include <list>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
#include <boost/archive/binary_iarchive.hpp>
|
|
|
|
#include <boost/archive/binary_oarchive.hpp>
|
|
|
|
#include <boost/serialization/string.hpp>
|
|
|
|
#include <boost/serialization/vector.hpp>
|
|
|
|
#include <boost/serialization/map.hpp>
|
|
|
|
|
|
|
|
// For generation
|
2009-05-16 17:58:08 +00:00
|
|
|
#include "cpp_materialgen.cpp"
|
2009-05-15 07:04:50 +00:00
|
|
|
#include "cpp_esm.cpp"
|
|
|
|
#include "cpp_landdata.cpp"
|
|
|
|
#include "cpp_quaddata.cpp"
|
|
|
|
#include "cpp_index.cpp"
|
|
|
|
#include "cpp_palette.cpp"
|
2009-05-16 17:58:08 +00:00
|
|
|
#include "cpp_point2.cpp"
|
2009-05-15 07:04:50 +00:00
|
|
|
#include "cpp_generator.cpp"
|
|
|
|
|
|
|
|
// For rendering
|
|
|
|
#include "cpp_baseland.cpp"
|
2009-05-16 18:47:49 +00:00
|
|
|
#include "cpp_heightmap.cpp"
|
2009-05-15 07:04:50 +00:00
|
|
|
#include "cpp_terrainmesh.cpp"
|
2009-05-16 18:47:49 +00:00
|
|
|
#include "cpp_quad.cpp"
|
2009-05-15 07:04:50 +00:00
|
|
|
#include "cpp_framelistener.cpp"
|
|
|
|
|
|
|
|
TerrainFrameListener terrainListener;
|
|
|
|
|
|
|
|
extern "C" void d_superman();
|
|
|
|
|
|
|
|
// Set up the rendering system
|
|
|
|
extern "C" void terr_setupRendering()
|
|
|
|
{
|
2009-05-16 17:58:08 +00:00
|
|
|
if(!g_materialGen)
|
|
|
|
g_materialGen = new MaterialGenerator;
|
|
|
|
|
2009-05-15 07:04:50 +00:00
|
|
|
// Add the terrain directory
|
|
|
|
ResourceGroupManager::getSingleton().
|
|
|
|
addResourceLocation(TEXTURE_OUTPUT, "FileSystem", "General");
|
|
|
|
|
|
|
|
// Set up the terrain frame listener
|
|
|
|
terrainListener.setup();
|
|
|
|
|
|
|
|
// Enter superman mode
|
|
|
|
mCamera->setFarClipDistance(32*8192);
|
|
|
|
d_superman();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate all cached data.
|
|
|
|
extern "C" void terr_genData()
|
2009-05-16 17:58:08 +00:00
|
|
|
{
|
|
|
|
if(!g_materialGen)
|
|
|
|
g_materialGen = new MaterialGenerator;
|
|
|
|
|
2009-05-15 07:04:50 +00:00
|
|
|
Ogre::Root::getSingleton().renderOneFrame();
|
|
|
|
|
|
|
|
Generator mhm(TERRAIN_OUTPUT);
|
|
|
|
{
|
|
|
|
ESM esm;
|
|
|
|
|
|
|
|
const std::string fn("data/Morrowind.esm");
|
|
|
|
|
|
|
|
esm.addRecordType("LAND", "INTV");
|
|
|
|
esm.addRecordType("LTEX", "INTV");
|
|
|
|
|
|
|
|
esm.loadFile(fn);
|
|
|
|
RecordListPtr land = esm.getRecordsByType("LAND");
|
|
|
|
for ( RecordListItr itr = land->begin(); itr != land->end(); ++itr )
|
|
|
|
mhm.addLandData(*itr, fn);
|
|
|
|
|
|
|
|
RecordListPtr ltex = esm.getRecordsByType("LTEX");
|
|
|
|
for ( RecordListItr itr = ltex->begin(); itr != ltex->end(); ++itr )
|
|
|
|
mhm.addLandTextureData(*itr, fn);
|
|
|
|
}
|
|
|
|
|
|
|
|
mhm.beginGeneration();
|
|
|
|
|
|
|
|
mhm.generateLODLevel(6, true, 1024);
|
|
|
|
mhm.generateLODLevel(5, true, 512);
|
|
|
|
mhm.generateLODLevel(4, true, 256);
|
|
|
|
mhm.generateLODLevel(3, true, 256);
|
|
|
|
mhm.generateLODLevel(2, true, 256);
|
|
|
|
mhm.generateLODLevel(1, false, 128);
|
|
|
|
|
|
|
|
mhm.endGeneration();
|
|
|
|
}
|