Use configured resolution for login/outgame/ingame
[ryzomcore.git] / ryzom / client / src / zone_util.cpp
blobe81ee4606892f636e0e63cb4de2b4e54547d6fec
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "stdpch.h"
23 #include "zone_util.h"
24 #include "nel/misc/path.h"
25 #include "nel/misc/vector_2f.h"
27 using namespace std;
29 #ifdef DEBUG_NEW
30 #define new DEBUG_NEW
31 #endif
33 bool getPosFromZoneName(const std::string &name,NLMISC::CVector2f &dest)
36 if (name.empty())
38 nlwarning ("getPosFromZoneName(): empty name, can't getPosFromZoneName");
39 return false;
42 static std::string zoneName;
43 static string xStr, yStr;
44 xStr.clear();
45 yStr.clear();
46 zoneName = NLMISC::CFile::getFilenameWithoutExtension(name);
47 uint32 i = 0;
48 while (zoneName[i] != '_')
50 if ((uint8)zoneName[i] >= (uint8)'\x80' || !::isdigit(zoneName[i])) return false;
51 yStr += zoneName[i]; ++i;
52 if (i == zoneName.size())
53 return false;
55 ++i;
56 while (i < zoneName.size())
58 if ((uint8)zoneName[i] >= (uint8)'\x80' || !::isalpha(zoneName[i])) return false;
59 xStr += (char) NLMISC::toUpper(zoneName[i]); ++i;
61 if (xStr.size() != 2) return false;
62 dest.x = 160.f * ((xStr[0] - 'A') * 26 + (xStr[1] - 'A'));
63 sint nY;
64 NLMISC::fromString(yStr, nY);
65 dest.y = 160.f * -nY;
66 return true;
69 bool getZonePosFromZoneName(const std::string &name, sint &x, sint &y)
72 if (name.empty())
74 nlwarning ("getPosFromZoneName(): empty name, can't getPosFromZoneName");
75 return false;
78 static std::string zoneName;
79 static string xStr, yStr;
80 xStr.clear();
81 yStr.clear();
82 zoneName = NLMISC::CFile::getFilenameWithoutExtension(name);
83 uint32 i = 0;
84 while (zoneName[i] != '_')
86 if ((uint8)zoneName[i] >= (uint8)'\x80' || !::isdigit(zoneName[i])) return false;
87 yStr += zoneName[i]; ++i;
88 if (i == zoneName.size())
89 return false;
91 ++i;
92 while (i < zoneName.size())
94 if ((uint8)zoneName[i] >= (uint8)'\x80' || !::isalpha(zoneName[i])) return false;
95 xStr += (char) NLMISC::toUpper(zoneName[i]); ++i;
97 if (xStr.size() != 2) return false;
98 x = (xStr[0] - 'A') * 26 + (xStr[1] - 'A');
99 NLMISC::fromString(yStr, y);
100 y = -y;
101 return true;