From 922df8e025410e307bdfd6a94b4dbe2fda55eab8 Mon Sep 17 00:00:00 2001 From: Titus Tscharntke Date: Fri, 25 Feb 2011 00:31:42 +0000 Subject: [PATCH] up to 36 units selectable; maps can set camera heigth now ( be careful with this for performance reasons! ) --- source/glest_game/game/game.cpp | 6 ++++- source/glest_game/graphics/renderer.cpp | 2 +- source/glest_game/gui/display.cpp | 26 ++++++++++++++++--- source/glest_game/gui/display.h | 13 ++++++++-- source/glest_game/gui/selection.h | 2 +- source/glest_game/world/map.cpp | 7 +++-- source/glest_game/world/map.h | 2 ++ source/glest_map_editor/main.cpp | 4 ++- source/glest_map_editor/program.cpp | 4 +-- source/glest_map_editor/program.h | 2 +- source/shared_lib/include/map/map_preview.h | 8 ++++-- source/shared_lib/sources/map/map_preview.cpp | 6 ++++- 12 files changed, 65 insertions(+), 17 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 4a0b49c2..ece7b570 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -552,7 +552,11 @@ void Game::init(bool initForPreviewOnly) gameCamera.init(map->getW(), map->getH()); - if(gameCamera.getCalculatedDefault()getMaxMapHeight()+13.0f){ + // camera default height calculation + if(map->getCameraHeight()>0 && gameCamera.getCalculatedDefault()getCameraHeight()){ + gameCamera.setCalculatedDefault(map->getCameraHeight()); + } + else if(gameCamera.getCalculatedDefault()getMaxMapHeight()+13.0f){ gameCamera.setCalculatedDefault(map->getMaxMapHeight()+13.0f); } diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 86e3707a..33f3c71e 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -3195,7 +3195,7 @@ void Renderer::renderDisplay(){ renderQuad( metrics.getDisplayX()+display->computeUpX(i), metrics.getDisplayY()+display->computeUpY(i), - Display::imageSize, Display::imageSize, display->getUpImage(i)); + display->getUpImageSize(), display->getUpImageSize(), display->getUpImage(i)); } } diff --git a/source/glest_game/gui/display.cpp b/source/glest_game/gui/display.cpp index 1b3698f9..19c51256 100644 --- a/source/glest_game/gui/display.cpp +++ b/source/glest_game/gui/display.cpp @@ -39,12 +39,21 @@ Display::Display(){ colors[8]= Vec4f(1.0f, 1.0f, 1.0f, 1.0f); currentColor= 0; - clear(); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } +void Display::calculateUpDimensions(int index) { + if(index>maxUpIndex){ + maxUpIndex=index; + if(maxUpIndex+1>upCellSideCount*upCellSideCount){ + upCellSideCount=upCellSideCount+1; + upImageSize=imageSize*cellSideCount/upCellSideCount+0.9f; + } + } +} + Vec4f Display::getColor() const { //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] currentColor = %d\n",__FILE__,__FUNCTION__,__LINE__,currentColor); if(currentColor < 0 || currentColor >= colorCount) { @@ -54,6 +63,13 @@ Vec4f Display::getColor() const { return colors[currentColor]; } +void Display::setUpImage(int i, const Texture2D *image) +{ + if(i>=upCellCount) throw runtime_error("i>=upCellCount in Display::setUpImage"); + upImages[i]= image; + calculateUpDimensions(i); +} + //misc void Display::clear(){ for(int i=0; ititle= formatString(title);} void setText(const string &text) {this->text= formatString(text);} void setInfoText(const string infoText) {this->infoText= formatString(infoText);} - void setUpImage(int i, const Texture2D *image) {upImages[i]= image;} + void setUpImage(int i, const Texture2D *image); void setDownImage(int i, const Texture2D *image) {downImages[i]= image;} void setCommandType(int i, const CommandType *ct) {commandTypes[i]= ct;} void setCommandClass(int i, const CommandClass cc) {commandClasses[i]= cc;} @@ -96,6 +102,9 @@ public: int computeDownY(int index) const; int computeUpX(int index) const; int computeUpY(int index) const; + +private: + void calculateUpDimensions(int index); }; }}//end namespace diff --git a/source/glest_game/gui/selection.h b/source/glest_game/gui/selection.h index c92f12ec..503fe7c9 100644 --- a/source/glest_game/gui/selection.h +++ b/source/glest_game/gui/selection.h @@ -35,7 +35,7 @@ public: public: static const int maxGroups= 10; - static const int maxUnits= 16; + static const int maxUnits= 36; private: int factionIndex; diff --git a/source/glest_game/world/map.cpp b/source/glest_game/world/map.cpp index 7674b224..7b285189 100644 --- a/source/glest_game/world/map.cpp +++ b/source/glest_game/world/map.cpp @@ -106,6 +106,7 @@ Map::Map() { waterLevel=0; heightFactor=0; cliffLevel=0; + cameraHeight=0; w=0; h=0; surfaceW=0; @@ -204,6 +205,7 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) { w= surfaceW*cellScale; h= surfaceH*cellScale; cliffLevel = 0; + cameraHeight = 0; if(header.version==1){ //desc = header.description; } @@ -212,8 +214,9 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) { if(header.version2.cliffLevel>0){ cliffLevel=static_cast((header.version2.cliffLevel-0.01f)/(heightFactor)); } - else { - cliffLevel=0; + if(header.version2.cameraHeight>0) + { + cameraHeight = header.version2.cameraHeight; } } diff --git a/source/glest_game/world/map.h b/source/glest_game/world/map.h index 5515d2b7..c2de3b41 100755 --- a/source/glest_game/world/map.h +++ b/source/glest_game/world/map.h @@ -157,6 +157,7 @@ private: float waterLevel; float heightFactor; float cliffLevel; + int cameraHeight; int w; int h; int surfaceW; @@ -195,6 +196,7 @@ public: float getHeightFactor() const {return heightFactor;} float getWaterLevel() const {return waterLevel;} float getCliffLevel() const {return cliffLevel;} + int getCameraHeight() const {return cameraHeight;} float getMaxMapHeight() const {return maxMapHeight;} Vec2i getStartLocation(int locationIndex) const; bool getSubmerged(const SurfaceCell *sc) const {return sc->getHeight()getMap()->getHeightFactor()),"(lower means map is more more zoomed in)"); simpleDialog.addValue("Water Level", intToStr(program->getMap()->getWaterLevel()),"(water is visible below this, and walkable until 1.5 less)"); simpleDialog.addValue("Cliff Level", intToStr(program->getMap()->getCliffLevel()),"(neighboring fields with at least this heights difference are cliffs)"); + simpleDialog.addValue("Camera Height", intToStr(program->getMap()->getCameraHeight()),"(you can give a camera heigth here default is 0 ;ignored if <20)"); if (!simpleDialog.show("Advanced")) return; try { program->setMapAdvanced( strToInt(simpleDialog.getValue("Height Factor")), strToInt(simpleDialog.getValue("Water Level")), - strToInt(simpleDialog.getValue("Cliff Level"))); + strToInt(simpleDialog.getValue("Cliff Level")), + strToInt(simpleDialog.getValue("Camera Height"))); } catch (const exception &e) { MsgDialog(this, ToUnicode(e.what()), wxT("Exception"), wxOK | wxICON_ERROR).ShowModal(); diff --git a/source/glest_map_editor/program.cpp b/source/glest_map_editor/program.cpp index 14b56b09..59eaada3 100644 --- a/source/glest_map_editor/program.cpp +++ b/source/glest_map_editor/program.cpp @@ -605,8 +605,8 @@ bool Program::setGridOnOff() { return grid; } -void Program::setMapAdvanced(int altFactor, int waterLevel, int cliffLevel) { - if(map) map->setAdvanced(altFactor, waterLevel, cliffLevel); +void Program::setMapAdvanced(int altFactor, int waterLevel, int cliffLevel , int cameraHeight) { + if(map) map->setAdvanced(altFactor, waterLevel, cliffLevel, cameraHeight); } void Program::loadMap(const string &path) { diff --git a/source/glest_map_editor/program.h b/source/glest_map_editor/program.h index ee9db32f..e4997261 100644 --- a/source/glest_map_editor/program.h +++ b/source/glest_map_editor/program.h @@ -148,7 +148,7 @@ public: bool setMapTitle(const string &title); bool setMapDesc(const string &desc); bool setMapAuthor(const string &author); - void setMapAdvanced(int altFactor, int waterLevel, int minimumCliffHeight); + void setMapAdvanced(int altFactor, int waterLevel, int minimumCliffHeight, int cameraHeight); //misc void renderMap(int w, int h); diff --git a/source/shared_lib/include/map/map_preview.h b/source/shared_lib/include/map/map_preview.h index 1c6ea11c..5024f2dc 100644 --- a/source/shared_lib/include/map/map_preview.h +++ b/source/shared_lib/include/map/map_preview.h @@ -75,7 +75,8 @@ struct MapFileHeader { int8 short_desc[MAX_DESCRIPTION_LENGTH_VERSION2]; int32 magic; // 0x01020304 for meta int32 cliffLevel; - int8 meta[120]; + int32 cameraHeight; + int8 meta[116]; } version2; }; }; @@ -113,6 +114,7 @@ private: int heightFactor; int waterLevel; int cliffLevel; + int cameraHeight; //Cell **cells; std::vector > cells; @@ -136,10 +138,12 @@ public: int getHeightFactor() const{return heightFactor;} int getWaterLevel() const{return waterLevel;} int getCliffLevel() const{return cliffLevel;} + int getCameraHeight() const{return cameraHeight;} + bool inside(int x, int y); void setRefAlt(int x, int y); - void setAdvanced(int heightFactor, int waterLevel, int cliffLevel); + void setAdvanced(int heightFactor, int waterLevel, int cliffLevel, int cameraHeight); void setTitle(const string &title); void setDesc(const string &desc); void setAuthor(const string &author); diff --git a/source/shared_lib/sources/map/map_preview.cpp b/source/shared_lib/sources/map/map_preview.cpp index b377be62..e8cd70c3 100644 --- a/source/shared_lib/sources/map/map_preview.cpp +++ b/source/shared_lib/sources/map/map_preview.cpp @@ -32,6 +32,7 @@ MapPreview::MapPreview() { heightFactor = DEFAULT_MAP_CELL_HEIGHT_FACTOR; waterLevel = DEFAULT_MAP_WATER_DEPTH; cliffLevel = DEFAULT_CLIFF_HEIGHT; + cameraHeight = 0; //cells = NULL; cells.clear(); //startLocations = NULL; @@ -630,10 +631,11 @@ void MapPreview::setAuthor(const string &author) { this->author = author; } -void MapPreview::setAdvanced(int heightFactor, int waterLevel, int cliffLevel) { +void MapPreview::setAdvanced(int heightFactor, int waterLevel, int cliffLevel, int cameraHeight) { this->heightFactor = heightFactor; this->waterLevel = waterLevel; this->cliffLevel = cliffLevel; + this->cameraHeight = cameraHeight; } void MapPreview::randomizeHeights() { @@ -697,6 +699,7 @@ void MapPreview::loadFromFile(const string &path) { else if(header.version==2){ desc = header.version2.short_desc; cliffLevel=header.version2.cliffLevel; + cameraHeight=header.version2.cameraHeight; } //read start locations @@ -764,6 +767,7 @@ void MapPreview::saveToFile(const string &path) { strncpy(header.version2.short_desc, desc.c_str(), MAX_DESCRIPTION_LENGTH_VERSION2); header.version2.magic= 0x01020304; header.version2.cliffLevel= cliffLevel; + header.version2.cameraHeight= cameraHeight; fwrite(&header, sizeof(MapFileHeader), 1, f1);