Просмотр исходного кода

Cache the selected graphic resolution instead of looking it up many times.

Frank Zago 14 лет назад
Родитель
Сommit
4cad2f4587
3 измененных файлов с 10 добавлено и 8 удалено
  1. 2 5
      client/CConfigHandler.cpp
  2. 7 1
      client/CConfigHandler.h
  3. 1 2
      client/CMT.cpp

+ 2 - 5
client/CConfigHandler.cpp

@@ -137,7 +137,7 @@ static void setGem(AdventureMapConfig &ac, const int gem, const JsonNode &g)
 	ac.gemG.push_back(g["graphic"].String());
 }
 
-CConfigHandler::CConfigHandler(void)
+CConfigHandler::CConfigHandler(void): current(NULL)
 {
 }
 
@@ -250,9 +250,6 @@ void config::CConfigHandler::init()
 		cc.screenx = cc.resx;
 		cc.screeny = cc.resy;
 	}
-}
 
-GUIOptions * config::CConfigHandler::go()
-{
-	return &guiOptions[std::pair<int,int>(cc.resx,cc.resy)];
+	SetResolution(cc.resx, cc.resy);
 }

+ 7 - 1
client/CConfigHandler.h

@@ -79,13 +79,19 @@ namespace config
 	/// Handles adventure map screen settings
 	class CConfigHandler
 	{
+		GUIOptions *current; // pointer to current gui options
+
 	public:
 		ClientConfig cc;
 		std::map<std::pair<int,int>, GUIOptions > guiOptions;
-		GUIOptions *go(); //return pointer to gui options appropriate for used screen resolution
 		void init();
 		CConfigHandler(void); //c-tor
 		~CConfigHandler(void); //d-tor
+
+		GUIOptions *go() { return current; };
+		void SetResolution(int x, int y) {
+			current = &guiOptions[std::pair<int,int>(x, y)];
+		}
 	};
 }
 extern config::CConfigHandler conf;

+ 1 - 2
client/CMT.cpp

@@ -430,8 +430,7 @@ void processCommand(const std::string &message)
 		else
 		{
 			for(j=conf.guiOptions.begin(); j!=conf.guiOptions.end() && hlp++<i; j++); //move j to the i-th resolution info
-			conf.cc.resx = j->first.first;
-			conf.cc.resy = j->first.second;
+			conf.SetResolution(j->first.first, j->first.second);
 			conf.cc.screenx = j->first.first;
 			conf.cc.screeny = j->first.second;
 			tlog0 << "Screen resolution set to " << conf.cc.resx << " x " << conf.cc.resy <<". It will be aplied when the game starts.\n";