Merge lp:~stellarium/stellarium/gz_landscapePreload into lp:stellarium
- gz_landscapePreload
- Merge into trunk
Proposed by
gzotti
Status: | Merged |
---|---|
Merged at revision: | 9107 |
Proposed branch: | lp:~stellarium/stellarium/gz_landscapePreload |
Merge into: | lp:stellarium |
Diff against target: |
724 lines (+230/-61) 6 files modified
src/core/StelTexture.hpp (+4/-1) src/core/StelTextureMgr.hpp (+1/-1) src/core/modules/Landscape.cpp (+66/-36) src/core/modules/Landscape.hpp (+17/-0) src/core/modules/LandscapeMgr.cpp (+100/-16) src/core/modules/LandscapeMgr.hpp (+42/-7) |
To merge this branch: | bzr merge lp:~stellarium/stellarium/gz_landscapePreload |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alexander Wolf | Approve | ||
Review via email: mp+315181@code.launchpad.net |
Commit message
Allow caching for landscapes, including preloading and some other manipulation via scripting.
Description of the change
This branch adds caching for the landscapes, mostly useful for the multi-gigabyte GPUs of today, but (hopefully) not disturbing for older systems. Big landscapes take several seconds to load. Switching rapidly between several landscapes becomes much easier with this. It is also possible to pre-load or delete from the cache via scripting.
Cache size can be configured in config.ini.
To post a comment you must log in.
Revision history for this message
Alexander Wolf (alexwolf) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/core/StelTexture.hpp' | |||
2 | --- src/core/StelTexture.hpp 2016-11-28 16:01:23 +0000 | |||
3 | +++ src/core/StelTexture.hpp 2017-01-19 22:30:07 +0000 | |||
4 | @@ -91,6 +91,9 @@ | |||
5 | 91 | //! Return whether the image is currently being loaded | 91 | //! Return whether the image is currently being loaded |
6 | 92 | bool isLoading() const {return (loader || networkReply) && !canBind();} | 92 | bool isLoading() const {return (loader || networkReply) && !canBind();} |
7 | 93 | 93 | ||
8 | 94 | //! Return texture memory size | ||
9 | 95 | unsigned int getGlSize() const {return glSize;} | ||
10 | 96 | |||
11 | 94 | signals: | 97 | signals: |
12 | 95 | //! Emitted when the texture is ready to be bind(), i.e. when downloaded, imageLoading and glLoading is over | 98 | //! Emitted when the texture is ready to be bind(), i.e. when downloaded, imageLoading and glLoading is over |
13 | 96 | //! or when an error occured and the texture will never be available | 99 | //! or when an error occured and the texture will never be available |
14 | @@ -171,7 +174,7 @@ | |||
15 | 171 | GLsizei height; //! Texture image height | 174 | GLsizei height; //! Texture image height |
16 | 172 | 175 | ||
17 | 173 | //! Size in GL memory | 176 | //! Size in GL memory |
19 | 174 | int glSize; | 177 | unsigned int glSize; |
20 | 175 | }; | 178 | }; |
21 | 176 | 179 | ||
22 | 177 | 180 | ||
23 | 178 | 181 | ||
24 | === modified file 'src/core/StelTextureMgr.hpp' | |||
25 | --- src/core/StelTextureMgr.hpp 2016-11-21 21:04:36 +0000 | |||
26 | +++ src/core/StelTextureMgr.hpp 2017-01-19 22:30:07 +0000 | |||
27 | @@ -61,7 +61,7 @@ | |||
28 | 61 | //! Must be called after the creation of the GLContext. | 61 | //! Must be called after the creation of the GLContext. |
29 | 62 | void init(); | 62 | void init(); |
30 | 63 | 63 | ||
32 | 64 | int glMemoryUsage; | 64 | unsigned int glMemoryUsage; |
33 | 65 | }; | 65 | }; |
34 | 66 | 66 | ||
35 | 67 | 67 | ||
36 | 68 | 68 | ||
37 | === modified file 'src/core/modules/Landscape.cpp' | |||
38 | --- src/core/modules/Landscape.cpp 2017-01-08 16:39:11 +0000 | |||
39 | +++ src/core/modules/Landscape.cpp 2017-01-19 22:30:07 +0000 | |||
40 | @@ -2,6 +2,7 @@ | |||
41 | 2 | * Stellarium | 2 | * Stellarium |
42 | 3 | * Copyright (C) 2003 Fabien Chereau | 3 | * Copyright (C) 2003 Fabien Chereau |
43 | 4 | * Copyright (C) 2011 Bogdan Marinov | 4 | * Copyright (C) 2011 Bogdan Marinov |
44 | 5 | * Copyright (C) 2014-17 Georg Zotti | ||
45 | 5 | * | 6 | * |
46 | 6 | * This program is free software; you can redistribute it and/or | 7 | * This program is free software; you can redistribute it and/or |
47 | 7 | * modify it under the terms of the GNU General Public License | 8 | * modify it under the terms of the GNU General Public License |
48 | @@ -37,6 +38,7 @@ | |||
49 | 37 | 38 | ||
50 | 38 | Landscape::Landscape(float _radius) | 39 | Landscape::Landscape(float _radius) |
51 | 39 | : radius(_radius) | 40 | : radius(_radius) |
52 | 41 | , id("uninitialized") | ||
53 | 40 | , minBrightness(-1.) | 42 | , minBrightness(-1.) |
54 | 41 | , landscapeBrightness(1.) | 43 | , landscapeBrightness(1.) |
55 | 42 | , lightScapeBrightness(0.) | 44 | , lightScapeBrightness(0.) |
56 | @@ -63,6 +65,7 @@ | |||
57 | 63 | // Load attributes common to all landscapes | 65 | // Load attributes common to all landscapes |
58 | 64 | void Landscape::loadCommon(const QSettings& landscapeIni, const QString& landscapeId) | 66 | void Landscape::loadCommon(const QSettings& landscapeIni, const QString& landscapeId) |
59 | 65 | { | 67 | { |
60 | 68 | id = landscapeId; | ||
61 | 66 | name = landscapeIni.value("landscape/name").toString(); | 69 | name = landscapeIni.value("landscape/name").toString(); |
62 | 67 | author = landscapeIni.value("landscape/author").toString(); | 70 | author = landscapeIni.value("landscape/author").toString(); |
63 | 68 | description = landscapeIni.value("landscape/description").toString(); | 71 | description = landscapeIni.value("landscape/description").toString(); |
64 | @@ -284,13 +287,14 @@ | |||
65 | 284 | { | 287 | { |
66 | 285 | QString line=in.readLine(); | 288 | QString line=in.readLine(); |
67 | 286 | 289 | ||
70 | 287 | // TODO: Read entries, construct vectors, put in list. | 290 | // Skip comments and all-empty lines (space allowed and ignored) |
71 | 288 | if (line.startsWith('#')) | 291 | if (line.startsWith('#') || line.trimmed().isEmpty() ) |
72 | 289 | continue; | 292 | continue; |
73 | 293 | // Read entries, construct vectors, put in list. | ||
74 | 290 | QStringList parts=line.split('|'); | 294 | QStringList parts=line.split('|'); |
75 | 291 | if (parts.count() != 5) | 295 | if (parts.count() != 5) |
76 | 292 | { | 296 | { |
78 | 293 | qWarning() << "Invalid line in landscape" << descFileName << ":" << line; | 297 | qWarning() << "Invalid line in landscape gazetteer" << descFileName << ":" << line; |
79 | 294 | continue; | 298 | continue; |
80 | 295 | } | 299 | } |
81 | 296 | LandscapeLabel newLabel; | 300 | LandscapeLabel newLabel; |
82 | @@ -359,6 +363,7 @@ | |||
83 | 359 | , drawGroundFirst(0) | 363 | , drawGroundFirst(0) |
84 | 360 | , tanMode(false) | 364 | , tanMode(false) |
85 | 361 | , calibrated(false) | 365 | , calibrated(false) |
86 | 366 | , memorySize(sizeof(LandscapeOldStyle)) // start with just the known entries. | ||
87 | 362 | {} | 367 | {} |
88 | 363 | 368 | ||
89 | 364 | LandscapeOldStyle::~LandscapeOldStyle() | 369 | LandscapeOldStyle::~LandscapeOldStyle() |
90 | @@ -391,7 +396,7 @@ | |||
91 | 391 | { | 396 | { |
92 | 392 | qWarning() << "Landscape type mismatch for landscape " << landscapeId | 397 | qWarning() << "Landscape type mismatch for landscape " << landscapeId |
93 | 393 | << ", expected old_style, found " << type << ". No landscape in use."; | 398 | << ", expected old_style, found " << type << ". No landscape in use."; |
95 | 394 | validLandscape = 0; | 399 | validLandscape = false; |
96 | 395 | return; | 400 | return; |
97 | 396 | } | 401 | } |
98 | 397 | 402 | ||
99 | @@ -421,6 +426,7 @@ | |||
100 | 421 | if ( (!horizonPolygon) && calibrated ) { // for uncalibrated landscapes the texture is currently never queried, so no need to store. | 426 | if ( (!horizonPolygon) && calibrated ) { // for uncalibrated landscapes the texture is currently never queried, so no need to store. |
101 | 422 | QImage *image = new QImage(texturePath); | 427 | QImage *image = new QImage(texturePath); |
102 | 423 | sidesImages.append(image); // indices identical to those in sideTexs | 428 | sidesImages.append(image); // indices identical to those in sideTexs |
103 | 429 | memorySize+=image->byteCount(); | ||
104 | 424 | } | 430 | } |
105 | 425 | // Also allow light textures. The light textures must cover the same geometry as the sides. It is allowed that not all or even any light textures are present! | 431 | // Also allow light textures. The light textures must cover the same geometry as the sides. It is allowed that not all or even any light textures are present! |
106 | 426 | textureKey = QString("landscape/light%1").arg(i); | 432 | textureKey = QString("landscape/light%1").arg(i); |
107 | @@ -429,6 +435,8 @@ | |||
108 | 429 | { | 435 | { |
109 | 430 | const QString lightTexturePath = getTexturePath(textureName, landscapeId); | 436 | const QString lightTexturePath = getTexturePath(textureName, landscapeId); |
110 | 431 | sideTexs[nbSideTexs+i] = StelApp::getInstance().getTextureManager().createTexture(lightTexturePath); | 437 | sideTexs[nbSideTexs+i] = StelApp::getInstance().getTextureManager().createTexture(lightTexturePath); |
111 | 438 | if(sideTexs[nbSideTexs+i]) | ||
112 | 439 | memorySize+=sideTexs[nbSideTexs+i].data()->getGlSize(); | ||
113 | 432 | } | 440 | } |
114 | 433 | else | 441 | else |
115 | 434 | sideTexs[nbSideTexs+i].clear(); | 442 | sideTexs[nbSideTexs+i].clear(); |
116 | @@ -471,28 +479,14 @@ | |||
117 | 471 | QString groundTexName = landscapeIni.value("landscape/groundtex").toString(); | 479 | QString groundTexName = landscapeIni.value("landscape/groundtex").toString(); |
118 | 472 | QString groundTexPath = getTexturePath(groundTexName, landscapeId); | 480 | QString groundTexPath = getTexturePath(groundTexName, landscapeId); |
119 | 473 | groundTex = StelApp::getInstance().getTextureManager().createTexture(groundTexPath, StelTexture::StelTextureParams(true)); | 481 | groundTex = StelApp::getInstance().getTextureManager().createTexture(groundTexPath, StelTexture::StelTextureParams(true)); |
129 | 474 | // GZ 2013/11: I don't see any use of this: | 482 | if (groundTex) |
130 | 475 | // QString description = landscapeIni.value("landscape/ground").toString(); | 483 | memorySize+=groundTex.data()->getGlSize(); |
122 | 476 | // //sscanf(description.toLocal8Bit(),"groundtex:%f:%f:%f:%f",&a,&b,&c,&d); | ||
123 | 477 | // QStringList parameters = description.split(':'); | ||
124 | 478 | // groundTexCoord.tex = groundTex; | ||
125 | 479 | // groundTexCoord.texCoords[0] = parameters.at(1).toFloat(); | ||
126 | 480 | // groundTexCoord.texCoords[1] = parameters.at(2).toFloat(); | ||
127 | 481 | // groundTexCoord.texCoords[2] = parameters.at(3).toFloat(); | ||
128 | 482 | // groundTexCoord.texCoords[3] = parameters.at(4).toFloat(); | ||
131 | 483 | 484 | ||
132 | 484 | QString fogTexName = landscapeIni.value("landscape/fogtex").toString(); | 485 | QString fogTexName = landscapeIni.value("landscape/fogtex").toString(); |
133 | 485 | QString fogTexPath = getTexturePath(fogTexName, landscapeId); | 486 | QString fogTexPath = getTexturePath(fogTexName, landscapeId); |
134 | 486 | fogTex = StelApp::getInstance().getTextureManager().createTexture(fogTexPath, StelTexture::StelTextureParams(true, GL_LINEAR, GL_REPEAT)); | 487 | fogTex = StelApp::getInstance().getTextureManager().createTexture(fogTexPath, StelTexture::StelTextureParams(true, GL_LINEAR, GL_REPEAT)); |
144 | 487 | // GZ 2013/11: I don't see any use of this: | 488 | if (fogTex) |
145 | 488 | // QString description = landscapeIni.value("landscape/fog").toString(); | 489 | memorySize+=fogTex.data()->getGlSize(); |
137 | 489 | // //sscanf(description.toLocal8Bit(),"fogtex:%f:%f:%f:%f",&a,&b,&c,&d); | ||
138 | 490 | // QStringList parameters = description.split(':'); | ||
139 | 491 | // fogTexCoord.tex = fogTex; | ||
140 | 492 | // fogTexCoord.texCoords[0] = parameters.at(1).toFloat(); | ||
141 | 493 | // fogTexCoord.texCoords[1] = parameters.at(2).toFloat(); | ||
142 | 494 | // fogTexCoord.texCoords[2] = parameters.at(3).toFloat(); | ||
143 | 495 | // fogTexCoord.texCoords[3] = parameters.at(4).toFloat(); | ||
146 | 496 | 490 | ||
147 | 497 | // Precompute the vertex arrays for ground display | 491 | // Precompute the vertex arrays for ground display |
148 | 498 | // Make slices_per_side=(3<<K) so that the innermost polygon of the fandisk becomes a triangle: | 492 | // Make slices_per_side=(3<<K) so that the innermost polygon of the fandisk becomes a triangle: |
149 | @@ -520,9 +514,9 @@ | |||
150 | 520 | // GZ: the original code for vertical placement makes unfortunately no sense. There are many approximately-fitted landscapes, though. | 514 | // GZ: the original code for vertical placement makes unfortunately no sense. There are many approximately-fitted landscapes, though. |
151 | 521 | // I added a switch "calibrated" for the ini file. If true, it works as this landscape apparently was originally intended, | 515 | // I added a switch "calibrated" for the ini file. If true, it works as this landscape apparently was originally intended, |
152 | 522 | // if false (or missing) it uses the original code. | 516 | // if false (or missing) it uses the original code. |
154 | 523 | // So I corrected the texture coordinates so that decorAltAngle is the total vertical angle, decorAngleShift the lower angle, | 517 | // I corrected the texture coordinates so that decorAltAngle is the total vertical angle, decorAngleShift the lower angle, |
155 | 524 | // and the texture in between is correctly stretched. | 518 | // and the texture in between is correctly stretched. |
157 | 525 | // I located an undocumented switch tan_mode, maybe tan_mode=true means cylindrical panorama projection. | 519 | // I located an undocumented switch tan_mode, maybe tan_mode=true means cylindrical panorama projection instead of equirectangular. |
158 | 526 | // Since V0.13, calibrated&&tanMode also works! | 520 | // Since V0.13, calibrated&&tanMode also works! |
159 | 527 | // In calibrated && !tan_mode, the vertical position is computed correctly, so that quads off the horizon are larger. | 521 | // In calibrated && !tan_mode, the vertical position is computed correctly, so that quads off the horizon are larger. |
160 | 528 | // in calibrated && tan_mode, d_z can become a constant because the texture is already predistorted in cylindrical projection. | 522 | // in calibrated && tan_mode, d_z can become a constant because the texture is already predistorted in cylindrical projection. |
161 | @@ -619,6 +613,7 @@ | |||
162 | 619 | } | 613 | } |
163 | 620 | } | 614 | } |
164 | 621 | } | 615 | } |
165 | 616 | //qDebug() << "OldStyleLandscape" << landscapeId << "loaded, mem size:" << memorySize; | ||
166 | 622 | } | 617 | } |
167 | 623 | 618 | ||
168 | 624 | void LandscapeOldStyle::draw(StelCore* core) | 619 | void LandscapeOldStyle::draw(StelCore* core) |
169 | @@ -836,17 +831,18 @@ | |||
170 | 836 | if(type != "polygonal") | 831 | if(type != "polygonal") |
171 | 837 | { | 832 | { |
172 | 838 | qWarning() << "Landscape type mismatch for landscape "<< landscapeId << ", expected polygonal, found " << type << ". No landscape in use.\n"; | 833 | qWarning() << "Landscape type mismatch for landscape "<< landscapeId << ", expected polygonal, found " << type << ". No landscape in use.\n"; |
174 | 839 | validLandscape = 0; | 834 | validLandscape = false; |
175 | 840 | return; | 835 | return; |
176 | 841 | } | 836 | } |
177 | 842 | if (horizonPolygon.isNull()) | 837 | if (horizonPolygon.isNull()) |
178 | 843 | { | 838 | { |
179 | 844 | qWarning() << "Landscape " << landscapeId << " does not declare a valid polygonal_horizon_list. No landscape in use.\n"; | 839 | qWarning() << "Landscape " << landscapeId << " does not declare a valid polygonal_horizon_list. No landscape in use.\n"; |
181 | 845 | validLandscape = 0; | 840 | validLandscape = false; |
182 | 846 | return; | 841 | return; |
183 | 847 | } | 842 | } |
184 | 848 | groundColor=StelUtils::strToVec3f( landscapeIni.value("landscape/ground_color", "0,0,0" ).toString() ); | 843 | groundColor=StelUtils::strToVec3f( landscapeIni.value("landscape/ground_color", "0,0,0" ).toString() ); |
186 | 849 | validLandscape = 1; // assume ok... | 844 | validLandscape = true; // assume ok... |
187 | 845 | //qDebug() << "PolygonalLandscape" << landscapeId << "loaded, mem size:" << getMemorySize(); | ||
188 | 850 | } | 846 | } |
189 | 851 | 847 | ||
190 | 852 | void LandscapePolygonal::draw(StelCore* core) | 848 | void LandscapePolygonal::draw(StelCore* core) |
191 | @@ -891,8 +887,12 @@ | |||
192 | 891 | 887 | ||
193 | 892 | LandscapeFisheye::LandscapeFisheye(float _radius) | 888 | LandscapeFisheye::LandscapeFisheye(float _radius) |
194 | 893 | : Landscape(_radius) | 889 | : Landscape(_radius) |
195 | 890 | , mapTex(StelTextureSP()) | ||
196 | 891 | , mapTexFog(StelTextureSP()) | ||
197 | 892 | , mapTexIllum(StelTextureSP()) | ||
198 | 894 | , mapImage(NULL) | 893 | , mapImage(NULL) |
199 | 895 | , texFov(360.) | 894 | , texFov(360.) |
200 | 895 | , memorySize(0) | ||
201 | 896 | {} | 896 | {} |
202 | 897 | 897 | ||
203 | 898 | LandscapeFisheye::~LandscapeFisheye() | 898 | LandscapeFisheye::~LandscapeFisheye() |
204 | @@ -909,7 +909,7 @@ | |||
205 | 909 | if(type != "fisheye") | 909 | if(type != "fisheye") |
206 | 910 | { | 910 | { |
207 | 911 | qWarning() << "Landscape type mismatch for landscape "<< landscapeId << ", expected fisheye, found " << type << ". No landscape in use.\n"; | 911 | qWarning() << "Landscape type mismatch for landscape "<< landscapeId << ", expected fisheye, found " << type << ". No landscape in use.\n"; |
209 | 912 | validLandscape = 0; | 912 | validLandscape = false; |
210 | 913 | return; | 913 | return; |
211 | 914 | } | 914 | } |
212 | 915 | create(name, | 915 | create(name, |
213 | @@ -918,25 +918,38 @@ | |||
214 | 918 | getTexturePath(landscapeIni.value("landscape/maptex_fog").toString(), landscapeId), | 918 | getTexturePath(landscapeIni.value("landscape/maptex_fog").toString(), landscapeId), |
215 | 919 | getTexturePath(landscapeIni.value("landscape/maptex_illum").toString(), landscapeId), | 919 | getTexturePath(landscapeIni.value("landscape/maptex_illum").toString(), landscapeId), |
216 | 920 | landscapeIni.value("landscape/angle_rotatez", 0.f).toFloat()); | 920 | landscapeIni.value("landscape/angle_rotatez", 0.f).toFloat()); |
217 | 921 | //qDebug() << "FisheyeLandscape" << landscapeId << "loaded, mem size:" << memorySize; | ||
218 | 921 | } | 922 | } |
219 | 922 | 923 | ||
220 | 923 | 924 | ||
221 | 924 | void LandscapeFisheye::create(const QString _name, float _texturefov, const QString& _maptex, const QString &_maptexFog, const QString& _maptexIllum, const float _angleRotateZ) | 925 | void LandscapeFisheye::create(const QString _name, float _texturefov, const QString& _maptex, const QString &_maptexFog, const QString& _maptexIllum, const float _angleRotateZ) |
222 | 925 | { | 926 | { |
223 | 926 | // qDebug() << _name << " " << _fullpath << " " << _maptex << " " << _texturefov; | 927 | // qDebug() << _name << " " << _fullpath << " " << _maptex << " " << _texturefov; |
225 | 927 | validLandscape = 1; // assume ok... | 928 | validLandscape = true; // assume ok... |
226 | 928 | name = _name; | 929 | name = _name; |
227 | 929 | texFov = _texturefov*M_PI/180.f; | 930 | texFov = _texturefov*M_PI/180.f; |
228 | 930 | angleRotateZ = _angleRotateZ*M_PI/180.f; | 931 | angleRotateZ = _angleRotateZ*M_PI/180.f; |
229 | 932 | |||
230 | 931 | if (!horizonPolygon) | 933 | if (!horizonPolygon) |
231 | 934 | { | ||
232 | 932 | mapImage = new QImage(_maptex); | 935 | mapImage = new QImage(_maptex); |
233 | 936 | memorySize+=mapImage->byteCount(); | ||
234 | 937 | } | ||
235 | 933 | mapTex = StelApp::getInstance().getTextureManager().createTexture(_maptex, StelTexture::StelTextureParams(true)); | 938 | mapTex = StelApp::getInstance().getTextureManager().createTexture(_maptex, StelTexture::StelTextureParams(true)); |
236 | 939 | memorySize+=mapTex.data()->getGlSize(); | ||
237 | 934 | 940 | ||
239 | 935 | if (_maptexIllum.length()) | 941 | if (_maptexIllum.length() && (!_maptexIllum.endsWith("/"))) |
240 | 942 | { | ||
241 | 936 | mapTexIllum = StelApp::getInstance().getTextureManager().createTexture(_maptexIllum, StelTexture::StelTextureParams(true)); | 943 | mapTexIllum = StelApp::getInstance().getTextureManager().createTexture(_maptexIllum, StelTexture::StelTextureParams(true)); |
243 | 937 | if (_maptexFog.length()) | 944 | if (mapTexIllum) |
244 | 945 | memorySize+=mapTexIllum.data()->getGlSize(); | ||
245 | 946 | } | ||
246 | 947 | if (_maptexFog.length() && (!_maptexFog.endsWith("/"))) | ||
247 | 948 | { | ||
248 | 938 | mapTexFog = StelApp::getInstance().getTextureManager().createTexture(_maptexFog, StelTexture::StelTextureParams(true)); | 949 | mapTexFog = StelApp::getInstance().getTextureManager().createTexture(_maptexFog, StelTexture::StelTextureParams(true)); |
250 | 939 | 950 | if (mapTexFog) | |
251 | 951 | memorySize+=mapTexFog.data()->getGlSize(); | ||
252 | 952 | } | ||
253 | 940 | } | 953 | } |
254 | 941 | 954 | ||
255 | 942 | 955 | ||
256 | @@ -1025,6 +1038,9 @@ | |||
257 | 1025 | 1038 | ||
258 | 1026 | LandscapeSpherical::LandscapeSpherical(float _radius) | 1039 | LandscapeSpherical::LandscapeSpherical(float _radius) |
259 | 1027 | : Landscape(_radius) | 1040 | : Landscape(_radius) |
260 | 1041 | , mapTex(StelTextureSP()) | ||
261 | 1042 | , mapTexFog(StelTextureSP()) | ||
262 | 1043 | , mapTexIllum(StelTextureSP()) | ||
263 | 1028 | , mapTexTop(0.) | 1044 | , mapTexTop(0.) |
264 | 1029 | , mapTexBottom(0.) | 1045 | , mapTexBottom(0.) |
265 | 1030 | , fogTexTop(0.) | 1046 | , fogTexTop(0.) |
266 | @@ -1032,6 +1048,7 @@ | |||
267 | 1032 | , illumTexTop(0.) | 1048 | , illumTexTop(0.) |
268 | 1033 | , illumTexBottom(0.) | 1049 | , illumTexBottom(0.) |
269 | 1034 | , mapImage(NULL) | 1050 | , mapImage(NULL) |
270 | 1051 | , memorySize(sizeof(LandscapeSpherical)) | ||
271 | 1035 | {} | 1052 | {} |
272 | 1036 | 1053 | ||
273 | 1037 | LandscapeSpherical::~LandscapeSpherical() | 1054 | LandscapeSpherical::~LandscapeSpherical() |
274 | @@ -1054,7 +1071,7 @@ | |||
275 | 1054 | qWarning() << "Landscape type mismatch for landscape "<< landscapeId | 1071 | qWarning() << "Landscape type mismatch for landscape "<< landscapeId |
276 | 1055 | << ", expected spherical, found " << type | 1072 | << ", expected spherical, found " << type |
277 | 1056 | << ". No landscape in use.\n"; | 1073 | << ". No landscape in use.\n"; |
279 | 1057 | validLandscape = 0; | 1074 | validLandscape = false; |
280 | 1058 | return; | 1075 | return; |
281 | 1059 | } | 1076 | } |
282 | 1060 | 1077 | ||
283 | @@ -1069,6 +1086,7 @@ | |||
284 | 1069 | landscapeIni.value("landscape/maptex_fog_bottom" , -90.f).toFloat(), | 1086 | landscapeIni.value("landscape/maptex_fog_bottom" , -90.f).toFloat(), |
285 | 1070 | landscapeIni.value("landscape/maptex_illum_top" , 90.f).toFloat(), | 1087 | landscapeIni.value("landscape/maptex_illum_top" , 90.f).toFloat(), |
286 | 1071 | landscapeIni.value("landscape/maptex_illum_bottom", -90.f).toFloat()); | 1088 | landscapeIni.value("landscape/maptex_illum_bottom", -90.f).toFloat()); |
287 | 1089 | //qDebug() << "SphericalLandscape" << landscapeId << "loaded, mem size:" << memorySize; | ||
288 | 1072 | } | 1090 | } |
289 | 1073 | 1091 | ||
290 | 1074 | 1092 | ||
291 | @@ -1079,7 +1097,7 @@ | |||
292 | 1079 | const float _illumTexTop, const float _illumTexBottom) | 1097 | const float _illumTexTop, const float _illumTexBottom) |
293 | 1080 | { | 1098 | { |
294 | 1081 | //qDebug() << "LandscapeSpherical::create():"<< _name << " : " << _maptex << " : " << _maptexFog << " : " << _maptexIllum << " : " << _angleRotateZ; | 1099 | //qDebug() << "LandscapeSpherical::create():"<< _name << " : " << _maptex << " : " << _maptexFog << " : " << _maptexIllum << " : " << _angleRotateZ; |
296 | 1082 | validLandscape = 1; // assume ok... | 1100 | validLandscape = true; // assume ok... |
297 | 1083 | name = _name; | 1101 | name = _name; |
298 | 1084 | angleRotateZ = _angleRotateZ *M_PI/180.f; // Defined in ini --> internal prg value | 1102 | angleRotateZ = _angleRotateZ *M_PI/180.f; // Defined in ini --> internal prg value |
299 | 1085 | mapTexTop = (90.f-_mapTexTop) *M_PI/180.f; // top 90 --> 0 | 1103 | mapTexTop = (90.f-_mapTexTop) *M_PI/180.f; // top 90 --> 0 |
300 | @@ -1089,13 +1107,25 @@ | |||
301 | 1089 | illumTexTop = (90.f-_illumTexTop) *M_PI/180.f; | 1107 | illumTexTop = (90.f-_illumTexTop) *M_PI/180.f; |
302 | 1090 | illumTexBottom= (90.f-_illumTexBottom)*M_PI/180.f; | 1108 | illumTexBottom= (90.f-_illumTexBottom)*M_PI/180.f; |
303 | 1091 | if (!horizonPolygon) | 1109 | if (!horizonPolygon) |
304 | 1110 | { | ||
305 | 1092 | mapImage = new QImage(_maptex); | 1111 | mapImage = new QImage(_maptex); |
306 | 1112 | memorySize+=mapImage->byteCount(); | ||
307 | 1113 | } | ||
308 | 1093 | mapTex = StelApp::getInstance().getTextureManager().createTexture(_maptex, StelTexture::StelTextureParams(true)); | 1114 | mapTex = StelApp::getInstance().getTextureManager().createTexture(_maptex, StelTexture::StelTextureParams(true)); |
309 | 1115 | memorySize+=mapTex.data()->getGlSize(); | ||
310 | 1094 | 1116 | ||
312 | 1095 | if (_maptexIllum.length()) | 1117 | if (_maptexIllum.length() && (!_maptexIllum.endsWith("/"))) |
313 | 1118 | { | ||
314 | 1096 | mapTexIllum = StelApp::getInstance().getTextureManager().createTexture(_maptexIllum, StelTexture::StelTextureParams(true)); | 1119 | mapTexIllum = StelApp::getInstance().getTextureManager().createTexture(_maptexIllum, StelTexture::StelTextureParams(true)); |
316 | 1097 | if (_maptexFog.length()) | 1120 | if (mapTexIllum) |
317 | 1121 | memorySize+=mapTexIllum.data()->getGlSize(); | ||
318 | 1122 | } | ||
319 | 1123 | if (_maptexFog.length() && (!_maptexFog.endsWith("/"))) | ||
320 | 1124 | { | ||
321 | 1098 | mapTexFog = StelApp::getInstance().getTextureManager().createTexture(_maptexFog, StelTexture::StelTextureParams(true)); | 1125 | mapTexFog = StelApp::getInstance().getTextureManager().createTexture(_maptexFog, StelTexture::StelTextureParams(true)); |
322 | 1126 | if (mapTexFog) | ||
323 | 1127 | memorySize+=mapTexFog.data()->getGlSize(); | ||
324 | 1128 | } | ||
325 | 1099 | } | 1129 | } |
326 | 1100 | 1130 | ||
327 | 1101 | void LandscapeSpherical::draw(StelCore* core) | 1131 | void LandscapeSpherical::draw(StelCore* core) |
328 | 1102 | 1132 | ||
329 | === modified file 'src/core/modules/Landscape.hpp' | |||
330 | --- src/core/modules/Landscape.hpp 2016-05-22 21:14:58 +0000 | |||
331 | +++ src/core/modules/Landscape.hpp 2017-01-19 22:30:07 +0000 | |||
332 | @@ -75,6 +75,13 @@ | |||
333 | 75 | //! @param landscapeIni A reference to an existing QSettings object which describes the landscape | 75 | //! @param landscapeIni A reference to an existing QSettings object which describes the landscape |
334 | 76 | //! @param landscapeId The name of the directory for the landscape files (e.g. "ocean") | 76 | //! @param landscapeId The name of the directory for the landscape files (e.g. "ocean") |
335 | 77 | virtual void load(const QSettings& landscapeIni, const QString& landscapeId) = 0; | 77 | virtual void load(const QSettings& landscapeIni, const QString& landscapeId) = 0; |
336 | 78 | |||
337 | 79 | //! Return approximate memory footprint in bytes (required for cache cost estimate in LandscapeMgr) | ||
338 | 80 | //! The returned value is only approximate, content of QStrings and other small containers like the horizon polygon are not put in in detail. | ||
339 | 81 | //! However, texture image sizes must be computed in subclasses. | ||
340 | 82 | //! The value returned is a sum of RAM and texture memory requirements. | ||
341 | 83 | virtual unsigned int getMemorySize() const {return sizeof(Landscape);} | ||
342 | 84 | |||
343 | 78 | virtual void draw(StelCore* core) = 0; | 85 | virtual void draw(StelCore* core) = 0; |
344 | 79 | void update(double deltaTime) | 86 | void update(double deltaTime) |
345 | 80 | { | 87 | { |
346 | @@ -124,6 +131,8 @@ | |||
347 | 124 | QString getAuthorName() const {return author;} | 131 | QString getAuthorName() const {return author;} |
348 | 125 | //! Get landscape description | 132 | //! Get landscape description |
349 | 126 | QString getDescription() const {return description;} | 133 | QString getDescription() const {return description;} |
350 | 134 | //! Get landscape id. This is the landscape directory name, used for cache handling. | ||
351 | 135 | QString getId() const {return id;} | ||
352 | 127 | 136 | ||
353 | 128 | //! Return the associated location (may be empty!) | 137 | //! Return the associated location (may be empty!) |
354 | 129 | const StelLocation& getLocation() const {return location;} | 138 | const StelLocation& getLocation() const {return location;} |
355 | @@ -202,6 +211,7 @@ | |||
356 | 202 | QString name; //! Read from landscape.ini:[landscape]name | 211 | QString name; //! Read from landscape.ini:[landscape]name |
357 | 203 | QString author; //! Read from landscape.ini:[landscape]author | 212 | QString author; //! Read from landscape.ini:[landscape]author |
358 | 204 | QString description; //! Read from landscape.ini:[landscape]description | 213 | QString description; //! Read from landscape.ini:[landscape]description |
359 | 214 | QString id; //! Set during load. Required for consistent caching. | ||
360 | 205 | 215 | ||
361 | 206 | float minBrightness; //! Read from landscape.ini:[landscape]minimal_brightness. Allows minimum visibility that cannot be underpowered. | 216 | float minBrightness; //! Read from landscape.ini:[landscape]minimal_brightness. Allows minimum visibility that cannot be underpowered. |
362 | 207 | float landscapeBrightness; //! brightness [0..1] to draw the landscape. Computed by the LandscapeMgr. | 217 | float landscapeBrightness; //! brightness [0..1] to draw the landscape. Computed by the LandscapeMgr. |
363 | @@ -259,6 +269,7 @@ | |||
364 | 259 | LandscapeOldStyle(float radius = 2.f); | 269 | LandscapeOldStyle(float radius = 2.f); |
365 | 260 | virtual ~LandscapeOldStyle(); | 270 | virtual ~LandscapeOldStyle(); |
366 | 261 | virtual void load(const QSettings& landscapeIni, const QString& landscapeId); | 271 | virtual void load(const QSettings& landscapeIni, const QString& landscapeId); |
367 | 272 | virtual unsigned int getMemorySize() const {return memorySize;} | ||
368 | 262 | virtual void draw(StelCore* core); | 273 | virtual void draw(StelCore* core); |
369 | 263 | //void create(bool _fullpath, QMap<QString, QString> param); // still not implemented | 274 | //void create(bool _fullpath, QMap<QString, QString> param); // still not implemented |
370 | 264 | virtual float getOpacity(Vec3d azalt) const; | 275 | virtual float getOpacity(Vec3d azalt) const; |
371 | @@ -302,6 +313,7 @@ | |||
372 | 302 | }; | 313 | }; |
373 | 303 | 314 | ||
374 | 304 | QList<LOSSide> precomputedSides; | 315 | QList<LOSSide> precomputedSides; |
375 | 316 | unsigned int memorySize; | ||
376 | 305 | }; | 317 | }; |
377 | 306 | 318 | ||
378 | 307 | ///////////////////////////////////////////////////////// | 319 | ///////////////////////////////////////////////////////// |
379 | @@ -319,6 +331,7 @@ | |||
380 | 319 | LandscapePolygonal(float radius = 1.f); | 331 | LandscapePolygonal(float radius = 1.f); |
381 | 320 | virtual ~LandscapePolygonal(); | 332 | virtual ~LandscapePolygonal(); |
382 | 321 | virtual void load(const QSettings& landscapeIni, const QString& landscapeId); | 333 | virtual void load(const QSettings& landscapeIni, const QString& landscapeId); |
383 | 334 | virtual unsigned int getMemorySize() const {return sizeof(LandscapePolygonal);} | ||
384 | 322 | virtual void draw(StelCore* core); | 335 | virtual void draw(StelCore* core); |
385 | 323 | virtual float getOpacity(Vec3d azalt) const; | 336 | virtual float getOpacity(Vec3d azalt) const; |
386 | 324 | private: | 337 | private: |
387 | @@ -338,6 +351,7 @@ | |||
388 | 338 | LandscapeFisheye(float radius = 1.f); | 351 | LandscapeFisheye(float radius = 1.f); |
389 | 339 | virtual ~LandscapeFisheye(); | 352 | virtual ~LandscapeFisheye(); |
390 | 340 | virtual void load(const QSettings& landscapeIni, const QString& landscapeId); | 353 | virtual void load(const QSettings& landscapeIni, const QString& landscapeId); |
391 | 354 | virtual unsigned int getMemorySize() const {return memorySize;} | ||
392 | 341 | virtual void draw(StelCore* core); | 355 | virtual void draw(StelCore* core); |
393 | 342 | //! Sample landscape texture for transparency/opacity. May be used for visibility, sunrise etc. | 356 | //! Sample landscape texture for transparency/opacity. May be used for visibility, sunrise etc. |
394 | 343 | //! @param azalt normalized direction in alt-az frame | 357 | //! @param azalt normalized direction in alt-az frame |
395 | @@ -360,6 +374,7 @@ | |||
396 | 360 | QImage *mapImage; //!< The same image as mapTex, but stored in-mem for sampling. | 374 | QImage *mapImage; //!< The same image as mapTex, but stored in-mem for sampling. |
397 | 361 | 375 | ||
398 | 362 | float texFov; | 376 | float texFov; |
399 | 377 | unsigned int memorySize; | ||
400 | 363 | }; | 378 | }; |
401 | 364 | 379 | ||
402 | 365 | ////////////////////////////////////////////////////////////////////////// | 380 | ////////////////////////////////////////////////////////////////////////// |
403 | @@ -378,6 +393,7 @@ | |||
404 | 378 | LandscapeSpherical(float radius = 1.f); | 393 | LandscapeSpherical(float radius = 1.f); |
405 | 379 | virtual ~LandscapeSpherical(); | 394 | virtual ~LandscapeSpherical(); |
406 | 380 | virtual void load(const QSettings& landscapeIni, const QString& landscapeId); | 395 | virtual void load(const QSettings& landscapeIni, const QString& landscapeId); |
407 | 396 | virtual unsigned int getMemorySize() const {return memorySize;} | ||
408 | 381 | virtual void draw(StelCore* core); | 397 | virtual void draw(StelCore* core); |
409 | 382 | //! Sample landscape texture for transparency/opacity. May be used for visibility, sunrise etc. | 398 | //! Sample landscape texture for transparency/opacity. May be used for visibility, sunrise etc. |
410 | 383 | //! @param azalt normalized direction in alt-az frame | 399 | //! @param azalt normalized direction in alt-az frame |
411 | @@ -414,6 +430,7 @@ | |||
412 | 414 | float illumTexTop; //!< zenithal top angle of the illumination texture, radians | 430 | float illumTexTop; //!< zenithal top angle of the illumination texture, radians |
413 | 415 | float illumTexBottom; //!< zenithal bottom angle of the illumination texture, radians | 431 | float illumTexBottom; //!< zenithal bottom angle of the illumination texture, radians |
414 | 416 | QImage *mapImage; //!< The same image as mapTex, but stored in-mem for opacity sampling. | 432 | QImage *mapImage; //!< The same image as mapTex, but stored in-mem for opacity sampling. |
415 | 433 | unsigned int memorySize; //!< holds an approximate value of memory consumption (for cache cost estimate) | ||
416 | 417 | }; | 434 | }; |
417 | 418 | 435 | ||
418 | 419 | #endif // _LANDSCAPE_HPP_ | 436 | #endif // _LANDSCAPE_HPP_ |
419 | 420 | 437 | ||
420 | === modified file 'src/core/modules/LandscapeMgr.cpp' | |||
421 | --- src/core/modules/LandscapeMgr.cpp 2017-01-08 16:39:11 +0000 | |||
422 | +++ src/core/modules/LandscapeMgr.cpp 2017-01-19 22:30:07 +0000 | |||
423 | @@ -142,7 +142,8 @@ | |||
424 | 142 | 142 | ||
425 | 143 | 143 | ||
426 | 144 | LandscapeMgr::LandscapeMgr() | 144 | LandscapeMgr::LandscapeMgr() |
428 | 145 | : atmosphere(NULL) | 145 | : StelModule() |
429 | 146 | , atmosphere(NULL) | ||
430 | 146 | , cardinalsPoints(NULL) | 147 | , cardinalsPoints(NULL) |
431 | 147 | , landscape(NULL) | 148 | , landscape(NULL) |
432 | 148 | , oldLandscape(NULL) | 149 | , oldLandscape(NULL) |
433 | @@ -154,7 +155,7 @@ | |||
434 | 154 | , flagLandscapeSetsMinimalBrightness(false) | 155 | , flagLandscapeSetsMinimalBrightness(false) |
435 | 155 | , flagAtmosphereAutoEnabling(false) | 156 | , flagAtmosphereAutoEnabling(false) |
436 | 156 | { | 157 | { |
438 | 157 | setObjectName("LandscapeMgr"); | 158 | setObjectName("LandscapeMgr"); // should be done by StelModule's constructor. |
439 | 158 | 159 | ||
440 | 159 | //Note: The first entry in the list is used as the default 'default landscape' in removeLandscape(). | 160 | //Note: The first entry in the list is used as the default 'default landscape' in removeLandscape(). |
441 | 160 | packagedLandscapeIDs = (QStringList() << "guereins"); | 161 | packagedLandscapeIDs = (QStringList() << "guereins"); |
442 | @@ -165,6 +166,7 @@ | |||
443 | 165 | packagedLandscapeIDs << directories.fileName(); | 166 | packagedLandscapeIDs << directories.fileName(); |
444 | 166 | } | 167 | } |
445 | 167 | packagedLandscapeIDs.removeDuplicates(); | 168 | packagedLandscapeIDs.removeDuplicates(); |
446 | 169 | landscapeCache.clear(); | ||
447 | 168 | } | 170 | } |
448 | 169 | 171 | ||
449 | 170 | LandscapeMgr::~LandscapeMgr() | 172 | LandscapeMgr::~LandscapeMgr() |
450 | @@ -178,6 +180,8 @@ | |||
451 | 178 | } | 180 | } |
452 | 179 | delete landscape; | 181 | delete landscape; |
453 | 180 | landscape = NULL; | 182 | landscape = NULL; |
454 | 183 | qDebug() << "LandscapeMgr: Clearing cache of" << landscapeCache.size() << "landscapes totalling about " << landscapeCache.totalCost() << "MB."; | ||
455 | 184 | landscapeCache.clear(); // deletes all objects within. | ||
456 | 181 | } | 185 | } |
457 | 182 | 186 | ||
458 | 183 | /************************************************************************* | 187 | /************************************************************************* |
459 | @@ -198,6 +202,7 @@ | |||
460 | 198 | void LandscapeMgr::update(double deltaTime) | 202 | void LandscapeMgr::update(double deltaTime) |
461 | 199 | { | 203 | { |
462 | 200 | atmosphere->update(deltaTime); | 204 | atmosphere->update(deltaTime); |
463 | 205 | |||
464 | 201 | if (oldLandscape) | 206 | if (oldLandscape) |
465 | 202 | { | 207 | { |
466 | 203 | // This is only when transitioning to newly loaded landscape. We must draw the old one until the new one is faded in completely. | 208 | // This is only when transitioning to newly loaded landscape. We must draw the old one until the new one is faded in completely. |
467 | @@ -208,7 +213,10 @@ | |||
468 | 208 | 213 | ||
469 | 209 | if (oldLandscape->getEffectiveLandFadeValue()< 0.01f) | 214 | if (oldLandscape->getEffectiveLandFadeValue()< 0.01f) |
470 | 210 | { | 215 | { |
472 | 211 | delete oldLandscape; | 216 | // new logic: try to put old landscape to cache. |
473 | 217 | //qDebug() << "LandscapeMgr::update: moving oldLandscape " << oldLandscape->getId() << "to Cache. Cost:" << oldLandscape->getMemorySize()/(1024*1024)+1; | ||
474 | 218 | landscapeCache.insert(oldLandscape->getId(), oldLandscape, oldLandscape->getMemorySize()/(1024*1024)+1); | ||
475 | 219 | //qDebug() << "--> LandscapeMgr::update(): cache now contains " << landscapeCache.size() << "landscapes totalling about " << landscapeCache.totalCost() << "MB."; | ||
476 | 212 | oldLandscape=NULL; | 220 | oldLandscape=NULL; |
477 | 213 | } | 221 | } |
478 | 214 | } | 222 | } |
479 | @@ -368,8 +376,10 @@ | |||
480 | 368 | QSettings* conf = StelApp::getInstance().getSettings(); | 376 | QSettings* conf = StelApp::getInstance().getSettings(); |
481 | 369 | Q_ASSERT(conf); | 377 | Q_ASSERT(conf); |
482 | 370 | 378 | ||
483 | 379 | landscapeCache.setMaxCost(conf->value("landscape/cache_size_mb", 100).toInt()); | ||
484 | 380 | qDebug() << "LandscapeMgr: initialized Cache for" << landscapeCache.maxCost() << "MB."; | ||
485 | 381 | |||
486 | 371 | atmosphere = new Atmosphere(); | 382 | atmosphere = new Atmosphere(); |
487 | 372 | landscape = new LandscapeOldStyle(); | ||
488 | 373 | defaultLandscapeID = conf->value("init_location/landscape_name").toString(); | 383 | defaultLandscapeID = conf->value("init_location/landscape_name").toString(); |
489 | 374 | setCurrentLandscapeID(defaultLandscapeID); | 384 | setCurrentLandscapeID(defaultLandscapeID); |
490 | 375 | setFlagLandscape(conf->value("landscape/flag_landscape", conf->value("landscape/flag_ground", true).toBool()).toBool()); | 385 | setFlagLandscape(conf->value("landscape/flag_landscape", conf->value("landscape/flag_ground", true).toBool()).toBool()); |
491 | @@ -421,13 +431,39 @@ | |||
492 | 421 | if(id==currentLandscapeID) | 431 | if(id==currentLandscapeID) |
493 | 422 | return false; | 432 | return false; |
494 | 423 | 433 | ||
502 | 424 | // We want to lookup the landscape ID (dir) from the name. | 434 | Landscape* newLandscape; |
503 | 425 | Landscape* newLandscape = createFromFile(StelFileMgr::findFile("landscapes/" + id + "/landscape.ini"), id); | 435 | |
504 | 426 | 436 | // There is a slight chance that we switch back to oldLandscape while oldLandscape is still fading away. | |
505 | 427 | if (!newLandscape) | 437 | // in this case it is not yet stored in cache, but obviously available. So we just swap places. |
506 | 428 | { | 438 | if (oldLandscape && oldLandscape->getId()==id) |
507 | 429 | qWarning() << "ERROR while loading landscape " << "landscapes/" + id + "/landscape.ini"; | 439 | { |
508 | 430 | return false; | 440 | newLandscape=oldLandscape; |
509 | 441 | } | ||
510 | 442 | else | ||
511 | 443 | { | ||
512 | 444 | // We want to lookup the landscape ID (dir) from the name. | ||
513 | 445 | newLandscape= landscapeCache.take(id); | ||
514 | 446 | |||
515 | 447 | if (newLandscape) | ||
516 | 448 | { | ||
517 | 449 | #ifndef NDEBUG | ||
518 | 450 | qDebug() << "LandscapeMgr::setCurrentLandscapeID():: taken " << id << "from cache..."; | ||
519 | 451 | qDebug() << ".-->LandscapeMgr::setCurrentLandscapeID(): cache contains " << landscapeCache.size() << "landscapes totalling about " << landscapeCache.totalCost() << "MB."; | ||
520 | 452 | #endif | ||
521 | 453 | } | ||
522 | 454 | else | ||
523 | 455 | { | ||
524 | 456 | #ifndef NDEBUG | ||
525 | 457 | qDebug() << "LandscapeMgr::setCurrentLandscapeID: Loading from file:" << id ; | ||
526 | 458 | #endif | ||
527 | 459 | newLandscape = createFromFile(StelFileMgr::findFile("landscapes/" + id + "/landscape.ini"), id); | ||
528 | 460 | } | ||
529 | 461 | |||
530 | 462 | if (!newLandscape) | ||
531 | 463 | { | ||
532 | 464 | qWarning() << "ERROR while loading landscape " << "landscapes/" + id + "/landscape.ini"; | ||
533 | 465 | return false; | ||
534 | 466 | } | ||
535 | 431 | } | 467 | } |
536 | 432 | 468 | ||
537 | 433 | // Keep current landscape for a while, while new landscape fades in! | 469 | // Keep current landscape for a while, while new landscape fades in! |
538 | @@ -439,15 +475,23 @@ | |||
539 | 439 | newLandscape->setFlagShowFog(landscape->getFlagShowFog()); | 475 | newLandscape->setFlagShowFog(landscape->getFlagShowFog()); |
540 | 440 | newLandscape->setFlagShowIllumination(landscape->getFlagShowIllumination()); | 476 | newLandscape->setFlagShowIllumination(landscape->getFlagShowIllumination()); |
541 | 441 | newLandscape->setFlagShowLabels(landscape->getFlagShowLabels()); | 477 | newLandscape->setFlagShowLabels(landscape->getFlagShowLabels()); |
545 | 442 | //in case we already fade out one old landscape (if switching too rapidly): the old one has to go immediately. | 478 | |
546 | 443 | if (oldLandscape) | 479 | // If we have an oldLandscape that is not just swapped back, put that into cache. |
547 | 444 | delete oldLandscape; | 480 | if (oldLandscape && oldLandscape!=newLandscape) |
548 | 481 | { | ||
549 | 482 | #ifndef NDEBUG | ||
550 | 483 | qDebug() << "LandscapeMgr::setCurrent: moving oldLandscape " << oldLandscape->getId() << "to Cache. Cost:" << oldLandscape->getMemorySize()/(1024*1024)+1; | ||
551 | 484 | #endif | ||
552 | 485 | landscapeCache.insert(oldLandscape->getId(), oldLandscape, oldLandscape->getMemorySize()/(1024*1024)+1); | ||
553 | 486 | #ifndef NDEBUG | ||
554 | 487 | qDebug() << "-->LandscapeMgr::setCurrentLandscapeId(): cache contains " << landscapeCache.size() << "landscapes totalling about " << landscapeCache.totalCost() << "MB."; | ||
555 | 488 | #endif | ||
556 | 489 | } | ||
557 | 445 | oldLandscape = landscape; // keep old while transitioning! | 490 | oldLandscape = landscape; // keep old while transitioning! |
558 | 446 | } | 491 | } |
559 | 447 | landscape=newLandscape; | 492 | landscape=newLandscape; |
560 | 448 | currentLandscapeID = id; | 493 | currentLandscapeID = id; |
561 | 449 | 494 | ||
562 | 450 | |||
563 | 451 | if (getFlagLandscapeSetsLocation() && landscape->hasLocation()) | 495 | if (getFlagLandscapeSetsLocation() && landscape->hasLocation()) |
564 | 452 | { | 496 | { |
565 | 453 | StelCore *core = StelApp::getInstance().getCore(); | 497 | StelCore *core = StelApp::getInstance().getCore(); |
566 | @@ -508,6 +552,46 @@ | |||
567 | 508 | } | 552 | } |
568 | 509 | } | 553 | } |
569 | 510 | 554 | ||
570 | 555 | // Load a landscape into cache. | ||
571 | 556 | // @param id the ID of a landscape | ||
572 | 557 | // @param replace true if existing landscape entry should be replaced (useful during development to reload after edit) | ||
573 | 558 | // @return false if landscape could not be found, or existed already and replace was false. | ||
574 | 559 | bool LandscapeMgr::precacheLandscape(const QString& id, const bool replace) | ||
575 | 560 | { | ||
576 | 561 | if (landscapeCache.contains(id) && (!replace)) | ||
577 | 562 | return false; | ||
578 | 563 | |||
579 | 564 | Landscape* newLandscape = createFromFile(StelFileMgr::findFile("landscapes/" + id + "/landscape.ini"), id); | ||
580 | 565 | if (!newLandscape) | ||
581 | 566 | { | ||
582 | 567 | qWarning() << "ERROR while preloading landscape " << "landscapes/" + id + "/landscape.ini"; | ||
583 | 568 | return false; | ||
584 | 569 | } | ||
585 | 570 | |||
586 | 571 | bool res=landscapeCache.insert(id, newLandscape, newLandscape->getMemorySize()/(1024*1024)+1); | ||
587 | 572 | #ifndef NDEBUG | ||
588 | 573 | if (res) | ||
589 | 574 | { | ||
590 | 575 | qDebug() << "LandscapeMgr::precacheLandscape(): Successfully added landscape with ID " << id << "to cache"; | ||
591 | 576 | } | ||
592 | 577 | qDebug() << "LandscapeMgr::precacheLandscape(): cache contains " << landscapeCache.size() << "landscapes totalling about " << landscapeCache.totalCost() << "MB."; | ||
593 | 578 | #endif | ||
594 | 579 | return res; | ||
595 | 580 | } | ||
596 | 581 | |||
597 | 582 | // Remove a landscape from the cache of loaded landscapes. | ||
598 | 583 | // @param id the ID of a landscape | ||
599 | 584 | // @return false if landscape could not be found | ||
600 | 585 | bool LandscapeMgr::removeCachedLandscape(const QString& id) | ||
601 | 586 | { | ||
602 | 587 | bool res= landscapeCache.remove(id); | ||
603 | 588 | #ifndef NDEBUG | ||
604 | 589 | qDebug() << "LandscapeMgr::removeCachedLandscape(): cache contains " << landscapeCache.size() << "landscapes totalling about " << landscapeCache.totalCost() << "MB."; | ||
605 | 590 | #endif | ||
606 | 591 | return res; | ||
607 | 592 | } | ||
608 | 593 | |||
609 | 594 | |||
610 | 511 | // Change the default landscape to the landscape with the ID specified. | 595 | // Change the default landscape to the landscape with the ID specified. |
611 | 512 | bool LandscapeMgr::setDefaultLandscapeID(const QString& id) | 596 | bool LandscapeMgr::setDefaultLandscapeID(const QString& id) |
612 | 513 | { | 597 | { |
613 | @@ -878,7 +962,7 @@ | |||
614 | 878 | } | 962 | } |
615 | 879 | 963 | ||
616 | 880 | /**************************************************************************** | 964 | /**************************************************************************** |
618 | 881 | get a map of landscape name (from landscape.ini name field) to ID (dir name) | 965 | get a map of landscape names (from landscape.ini name field) to ID (dir name) |
619 | 882 | ****************************************************************************/ | 966 | ****************************************************************************/ |
620 | 883 | QMap<QString,QString> LandscapeMgr::getNameToDirMap() const | 967 | QMap<QString,QString> LandscapeMgr::getNameToDirMap() const |
621 | 884 | { | 968 | { |
622 | 885 | 969 | ||
623 | === modified file 'src/core/modules/LandscapeMgr.hpp' | |||
624 | --- src/core/modules/LandscapeMgr.hpp 2016-12-18 06:38:55 +0000 | |||
625 | +++ src/core/modules/LandscapeMgr.hpp 2017-01-19 22:30:07 +0000 | |||
626 | @@ -28,6 +28,7 @@ | |||
627 | 28 | 28 | ||
628 | 29 | #include <QMap> | 29 | #include <QMap> |
629 | 30 | #include <QStringList> | 30 | #include <QStringList> |
630 | 31 | #include <QCache> | ||
631 | 31 | 32 | ||
632 | 32 | class Atmosphere; | 33 | class Atmosphere; |
633 | 33 | class Cardinals; | 34 | class Cardinals; |
634 | @@ -41,7 +42,7 @@ | |||
635 | 41 | //! \note | 42 | //! \note |
636 | 42 | //! The Bortle scale index setting was removed from this class, because it was duplicated | 43 | //! The Bortle scale index setting was removed from this class, because it was duplicated |
637 | 43 | //! from StelSkyDrawer, complicating code that changes it. | 44 | //! from StelSkyDrawer, complicating code that changes it. |
639 | 44 | //! It is now only in StelSkyDrawer and can be accessed with | 45 | //! It is now only in StelSkyDrawer and can be accessed |
640 | 45 | //! with \link StelSkyDrawer::getBortleScaleIndex getBortleScaleIndex \endlink | 46 | //! with \link StelSkyDrawer::getBortleScaleIndex getBortleScaleIndex \endlink |
641 | 46 | //! and \link StelSkyDrawer::setBortleScaleIndex setBortleScaleIndex \endlink. | 47 | //! and \link StelSkyDrawer::setBortleScaleIndex setBortleScaleIndex \endlink. |
642 | 47 | //! Slots setAtmosphereBortleLightPollution and getAtmosphereBortleLightPollution | 48 | //! Slots setAtmosphereBortleLightPollution and getAtmosphereBortleLightPollution |
643 | @@ -141,9 +142,10 @@ | |||
644 | 141 | /////////////////////////////////////////////////////////////////////////// | 142 | /////////////////////////////////////////////////////////////////////////// |
645 | 142 | // Methods specific to the landscape manager | 143 | // Methods specific to the landscape manager |
646 | 143 | 144 | ||
650 | 144 | //! Load a landscape based on a hash of parameters mirroring the landscape.ini | 145 | // Load a landscape based on a hash of parameters mirroring the landscape.ini |
651 | 145 | //! file and make it the current landscape. | 146 | // file and make it the current landscape. |
652 | 146 | bool loadLandscape(QMap<QString, QString>& param); | 147 | // GZ: This was declared, but not implemented(?) |
653 | 148 | //bool loadLandscape(QMap<QString, QString>& param); | ||
654 | 147 | 149 | ||
655 | 148 | //! Create a new landscape from the files which describe it. | 150 | //! Create a new landscape from the files which describe it. |
656 | 149 | //! Reads a landscape.ini file which is passed as the first parameter, determines | 151 | //! Reads a landscape.ini file which is passed as the first parameter, determines |
657 | @@ -177,7 +179,7 @@ | |||
658 | 177 | //! this value explicitly to freeze it during image export. To unfreeze, call this again with any negative value. | 179 | //! this value explicitly to freeze it during image export. To unfreeze, call this again with any negative value. |
659 | 178 | void setAtmosphereAverageLuminance(const float overrideLuminance); | 180 | void setAtmosphereAverageLuminance(const float overrideLuminance); |
660 | 179 | 181 | ||
662 | 180 | //! Return a map of landscape name to landscape ID (directory name). | 182 | //! Return a map of landscape names to landscape IDs (directory names). |
663 | 181 | QMap<QString,QString> getNameToDirMap() const; | 183 | QMap<QString,QString> getNameToDirMap() const; |
664 | 182 | 184 | ||
665 | 183 | //! Retrieve a list of the names of all the available landscapes in | 185 | //! Retrieve a list of the names of all the available landscapes in |
666 | @@ -212,6 +214,31 @@ | |||
667 | 212 | //! @param changeLocationDuration the duration of the transition animation | 214 | //! @param changeLocationDuration the duration of the transition animation |
668 | 213 | bool setCurrentLandscapeName(const QString& name, const double changeLocationDuration = 1.0); | 215 | bool setCurrentLandscapeName(const QString& name, const double changeLocationDuration = 1.0); |
669 | 214 | 216 | ||
670 | 217 | //! Preload a landscape into cache. | ||
671 | 218 | //! @param id the ID of a landscape | ||
672 | 219 | //! @param replace true if existing landscape entry should be replaced (useful during development to reload after edit) | ||
673 | 220 | //! @return false if landscape could not be found, or if it already existed in cache and replace was false. | ||
674 | 221 | bool precacheLandscape(const QString& id, const bool replace=true); | ||
675 | 222 | //! Remove a landscape from the cache of landscapes. | ||
676 | 223 | //! @param id the ID of a landscape | ||
677 | 224 | //! @return false if landscape could not be found | ||
678 | 225 | bool removeCachedLandscape(const QString& id); | ||
679 | 226 | //! Set size of the landscape cache, in MB. | ||
680 | 227 | //! Default size is 100MB, or configured as [landscape/cache_size_mb] from config.ini. | ||
681 | 228 | //! The landscape sizes returned in Landscape::getMemorySize() are only approximate, but include image and texture sizes. | ||
682 | 229 | //! A big landscape may well take 150MB or more. | ||
683 | 230 | //! On a 32bit system, keep this rather small. On 64bit with 16GB RAM and no other tasks, 4GB is no problem. | ||
684 | 231 | //! Modern GPUs may have 4 or even 8GB of dedicated texture memory. Most of this may be filled with landscape textures. | ||
685 | 232 | //! Example: a museum installation with 20 large (16384x2048) old_stype landscapes can require up to 3.5GB. Allow 4GB cache, | ||
686 | 233 | //! and the system will never have to load a landscape during the show when all have been preloaded. | ||
687 | 234 | void setCacheSize(int mb) { landscapeCache.setMaxCost(mb);} | ||
688 | 235 | //! Retrieve total size of cache (MB). | ||
689 | 236 | int getCacheSize() const {return landscapeCache.maxCost();} | ||
690 | 237 | //! Retrieve sum of currently used memory in cache (MB, approximate) | ||
691 | 238 | int getCacheFilledSize() const {return landscapeCache.totalCost();} | ||
692 | 239 | //! Return number of landscapes already in the cache. | ||
693 | 240 | int getCacheCount() const {return landscapeCache.count();} | ||
694 | 241 | |||
695 | 215 | //! Get the current landscape object. | 242 | //! Get the current landscape object. |
696 | 216 | Landscape* getCurrentLandscape() const { return landscape; } | 243 | Landscape* getCurrentLandscape() const { return landscape; } |
697 | 217 | 244 | ||
698 | @@ -505,16 +532,24 @@ | |||
699 | 505 | //! Indicate auto-enable atmosphere for planets with atmospheres in location window | 532 | //! Indicate auto-enable atmosphere for planets with atmospheres in location window |
700 | 506 | bool flagAtmosphereAutoEnabling; | 533 | bool flagAtmosphereAutoEnabling; |
701 | 507 | 534 | ||
703 | 508 | // The ID of the currently loaded landscape | 535 | //! The ID of the currently loaded landscape |
704 | 509 | QString currentLandscapeID; | 536 | QString currentLandscapeID; |
705 | 510 | 537 | ||
707 | 511 | // The ID of the default landscape | 538 | //! The ID of the default landscape |
708 | 512 | QString defaultLandscapeID; | 539 | QString defaultLandscapeID; |
709 | 513 | 540 | ||
710 | 514 | //! List of the IDs of the landscapes packaged by default with Stellarium. | 541 | //! List of the IDs of the landscapes packaged by default with Stellarium. |
711 | 515 | //! (So that they can't be removed.) | 542 | //! (So that they can't be removed.) |
712 | 516 | QStringList packagedLandscapeIDs; | 543 | QStringList packagedLandscapeIDs; |
713 | 517 | 544 | ||
714 | 545 | //! QCache of landscapes kept in memory for faster access, esp. when frequently switching between several big landscapes. | ||
715 | 546 | //! Example: a 16384-size old_style landscape takes about 10 seconds to load. Kept in cache, it is back instantly. | ||
716 | 547 | //! Of course, this requires lots of RAM and GPU texture memory, but in the age of 64bit CPUs and 4GB and more GPU | ||
717 | 548 | //! texture memory, it is no problem to keep even 20 or more landscapes. | ||
718 | 549 | //! This is esp. useful in a context of automated setup (museum show or such) where a list of landscapes is preloaded | ||
719 | 550 | //! at system start (e.g. in the startup.ssc script) and then retrieved while script is running. | ||
720 | 551 | //! The key is just the LandscapeID. | ||
721 | 552 | QCache<QString,Landscape> landscapeCache; | ||
722 | 518 | }; | 553 | }; |
723 | 519 | 554 | ||
724 | 520 | #endif // _LANDSCAPEMGR_HPP_ | 555 | #endif // _LANDSCAPEMGR_HPP_ |