CSM3ReadMap::CSM3ReadMap(const std::string& mapName) : groundDrawer(NULL) , minimapTexture(0) , numFeatures(0) { loadscreen->SetLoadMessage("Loading " + mapName); if (!mapInfo->sm3.minimap.empty()) { CBitmap bmp; if (bmp.Load(mapInfo->sm3.minimap)) { minimapTexture = bmp.CreateMipMapTexture(); } } renderer = new terrain::Terrain(); { // load the heightmap in advance Sm3LoadCB cb; renderer->LoadHeightMap(GetMapDefParser(), &cb); heightMapSyncedPtr = &renderer->GetCornerHeightMapSynced(); heightMapUnsyncedPtr = &renderer->GetCornerHeightMapUnsynced(); mapDims.mapx = renderer->GetHeightmapWidth() - 1; mapDims.mapy = renderer->GetHeightmapWidth() - 1; // note: not height (SM3 only supports square maps!) } CReadMap::Initialize(); if (GetMapDefParser().SectionExist("map\\featuretypes")) { const int numTypes = atoi(GetMapDefParser().SGetValueDef("0", "map\\featuretypes\\numtypes").c_str()); for (int a = 0; a < numTypes; a++) { char loc[100]; SNPRINTF(loc, 100, "map\\featuretypes\\type%d", a); featureTypes.push_back(new std::string(GetMapDefParser().SGetValueDef("TreeType0", loc))); } } LoadFeatureData(); }
CSM3ReadMap::CSM3ReadMap(const std::string& mapName) { groundDrawer = 0; minimapTexture = 0; numFeatures = 0; loadscreen->SetLoadMessage("Loading " + mapName); if (!mapInfo->sm3.minimap.empty()) { CBitmap bmp; if (bmp.Load(mapInfo->sm3.minimap)) { minimapTexture = bmp.CreateTexture(true); } } renderer = new terrain::Terrain(); { // load the heightmap in advance Sm3LoadCB cb; renderer->LoadHeightMap(GetMapDefParser(), &cb); width = renderer->GetHeightmapWidth() - 1; height = renderer->GetHeightmapWidth() - 1; //! note: not height } CReadMap::Initialize(); if (GetMapDefParser().SectionExist("map\\featuretypes")) { const int numTypes = atoi(GetMapDefParser().SGetValueDef("0", "map\\featuretypes\\numtypes").c_str()); for (int a = 0; a < numTypes; a++) { char loc[100]; SNPRINTF(loc, 100, "map\\featuretypes\\type%d", a); featureTypes.push_back(new std::string(GetMapDefParser().SGetValueDef("TreeType0", loc))); } } LoadFeatureData(); }
void CSM3ReadMap::LoadFeatureData() { // returns MapFeatureInfo[GetNumFeatures()] std::string fd = GetMapDefParser().SGetValueDef(std::string(),"map\\featuredata"); if (!fd.empty()) { CFileHandler fh(fd); if (!fh.FileExists()) throw content_error("Failed to open feature data file: " + fd); unsigned char version; fh.Read(&version, 1); if (version > 0) throw content_error("Map feature data has incorrect version, you are probably using an outdated spring version."); unsigned int nf; fh.Read(&nf, 4); numFeatures = swabDWord(nf); featureInfo = new MapFeatureInfo[numFeatures]; for (unsigned int a=0;a<numFeatures;a++) { MapFeatureInfo& fi = featureInfo[a]; fh.Read(&fi.featureType, 4); fh.Read(&fi.pos, 12); fh.Read(&fi.rotation, 4); fi.featureType = swabDWord(fi.featureType); fi.pos.x = swabFloat(fi.pos.x); fi.pos.y = swabFloat(fi.pos.y); fi.pos.z = swabFloat(fi.pos.z); fi.rotation = swabFloat(fi.rotation); } }/* //testing features... else { featureTypes.push_back(new std::string("TreeType0")); numFeatures = 1000; featureInfo = new MapFeatureInfo[numFeatures]; for (int a=0;a<numFeatures;a++) { MapFeatureInfo& fi = featureInfo[a]; fi.featureType = featureTypes.size()-1; fi.pos.x = gs->randFloat() * mapDims.mapx * SQUARE_SIZE; fi.pos.z = gs->randFloat() * mapDims.mapy * SQUARE_SIZE; fi.rotation = 0.0f; } }*/ }
// Bitmaps (such as metal map, grass map, ...), handling them with a string as type seems flexible... // Some map types: // "metal" - metalmap // "grass" - grassmap unsigned char* CSM3ReadMap::GetInfoMap(const std::string& name, MapBitmapInfo* bm) { std::string map; if (!GetMapDefParser().SGetValue(map, "MAP\\INFOMAPS\\" + name)) return 0; CBitmap img; // all infomaps are grayscale if (!img.LoadGrayscale(map)) return 0; InfoMap& im = infoMaps[name]; bm->width = im.w = img.xsize; bm->height = im.h = img.ysize; im.data = img.mem; img.mem = 0; return im.data; }
void CSM3ReadMap::InitGroundDrawer() { renderer->config.cacheTextures = false; renderer->config.forceFallbackTexturing = configHandler->GetBool("SM3ForceFallbackTex"); if (!renderer->config.forceFallbackTexturing && GLEW_ARB_fragment_shader && GLEW_ARB_shading_language_100) { renderer->config.useBumpMaps = true; renderer->config.anisotropicFiltering = 0.0f; } renderer->config.useStaticShadow = false; renderer->config.useShadowMaps = shadowHandler->ShadowsLoaded(); renderer->config.terrainNormalMaps = false; renderer->config.normalMapLevel = 3; /* int numStages = atoi(mapDefParser.SGetValueDef("0", "map\\terrain\\numtexturestages").c_str()); int maxStages = configHandler->GetInt("SM3MaxTextureStages"); if (numStages > maxStages) { renderer->config.cacheTextures = true; renderer->config.cacheTextureSize = 256; // renderer->config.detailMod } */ Sm3LoadCB loadcb; terrain::LightingInfo lightInfo; lightInfo.ambient = sunLighting->groundAmbientColor; terrain::StaticLight light; light.color = sunLighting->groundDiffuseColor; light.directional = false; light.position = sunLighting->sunDir * 1000000.0f; lightInfo.staticLights.push_back(light); renderer->Load(GetMapDefParser(), &lightInfo, &loadcb); groundDrawer = new CSM3GroundDrawer(this); configHandler->NotifyOnChange(this); }
void CSm3ReadMap::Initialize (const char *mapname) { try { string lmsg = "Loading " + string(mapname); PrintLoadMsg(lmsg.c_str()); GLint tu; glGetIntegerv(GL_MAX_TEXTURE_UNITS, &tu); renderer = new terrain::Terrain; renderer->config.cacheTextures=false; renderer->config.forceFallbackTexturing = !!configHandler->Get("SM3ForceFallbackTex", 0); if (!renderer->config.forceFallbackTexturing && GLEW_ARB_fragment_shader && GLEW_ARB_shading_language_100) { renderer->config.useBumpMaps = true; renderer->config.anisotropicFiltering = 0.0f; } renderer->config.useStaticShadow = false; renderer->config.terrainNormalMaps = false; renderer->config.normalMapLevel = 3; if (shadowHandler->drawShadows) renderer->config.useShadowMaps = true; if (!mapInfo->sm3.minimap.empty()) { CBitmap bmp; if(bmp.Load(mapInfo->sm3.minimap)) minimapTexture=bmp.CreateTexture(true); } /* int numStages=atoi(mapDefParser.SGetValueDef("0", "map\\terrain\\numtexturestages").c_str()); int maxStages=configHandler->Get("SM3MaxTextureStages", 10); if (numStages > maxStages) { renderer->config.cacheTextures = true; renderer->config.cacheTextureSize = 256; // renderer->config.detailMod } */ Sm3LoadCB loadcb; terrain::LightingInfo lightInfo; lightInfo.ambient = mapInfo->light.groundAmbientColor; terrain::StaticLight light; light.color = mapInfo->light.groundSunColor; light.directional = false; light.position = mapInfo->light.sunDir *1000000; lightInfo.staticLights.push_back (light); renderer->Load (GetMapDefParser(), &lightInfo, &loadcb); height = width = renderer->GetHeightmapWidth() - 1; // Set global map info gs->mapx=width; gs->mapy=height; gs->mapSquares = width*height; gs->hmapx=width/2; gs->hmapy=height/2; gs->pwr2mapx=next_power_of_2(width); gs->pwr2mapy=next_power_of_2(height); float3::maxxpos=width*SQUARE_SIZE-1; float3::maxzpos=height*SQUARE_SIZE-1; CReadMap::Initialize(); const TdfParser& mapDefParser = GetMapDefParser(); if (mapDefParser.SectionExist("map\\featuretypes")) { int numTypes = atoi(mapDefParser.SGetValueDef("0", "map\\featuretypes\\numtypes").c_str()); for (int a=0;a<numTypes;a++) { char loc[100]; SNPRINTF(loc, 100, "map\\featuretypes\\type%d", a); featureTypes.push_back (new std::string(mapDefParser.SGetValueDef("TreeType0", loc))); } } LoadFeatureData(); groundDrawer = new CSm3GroundDrawer (this); } catch(content_error& e) { ErrorMessageBox(e.what(), "Error:", MBF_OK); } }