@@ -214,15 +214,15 @@ Globe::~Globe()
214214 delete _mkCrashedUfo;
215215 delete _mkAlienSite;
216216
217- for (std::vector <Polygon*>::iterator i = _ocean.begin (); i != _ocean.end (); i++)
217+ for (std::list <Polygon*>::iterator i = _ocean.begin (); i != _ocean.end (); i++)
218218 {
219219 delete *i;
220220 }
221- for (std::vector <Polygon*>::iterator i = _cacheOcean.begin (); i != _cacheOcean.end (); i++)
221+ for (std::list <Polygon*>::iterator i = _cacheOcean.begin (); i != _cacheOcean.end (); i++)
222222 {
223223 delete *i;
224224 }
225- for (std::vector <Polygon*>::iterator i = _cacheLand.begin (); i != _cacheLand.end (); i++)
225+ for (std::list <Polygon*>::iterator i = _cacheLand.begin (); i != _cacheLand.end (); i++)
226226 {
227227 delete *i;
228228 }
@@ -327,7 +327,7 @@ bool Globe::insidePolygon(double lon, double lat, Polygon *poly) const
327327 * @param polygons Pointer to the polygon set.
328328 * @sa http://www.ufopaedia.org/index.php?title=WORLD.DAT
329329 */
330- void Globe::loadDat (const std::string &filename, std::vector <Polygon*> *polygons)
330+ void Globe::loadDat (const std::string &filename, std::list <Polygon*> *polygons)
331331{
332332 // Load file
333333 std::ifstream mapFile (filename.c_str (), std::ios::in | std::ios::binary);
@@ -513,7 +513,7 @@ void Globe::center(double lon, double lat)
513513bool Globe::insideLand (double lon, double lat) const
514514{
515515 bool inside = false ;
516- for (std::vector <Polygon*>::iterator i = _res->getPolygons ()->begin (); i < _res->getPolygons ()->end () && !inside; i++)
516+ for (std::list <Polygon*>::iterator i = _res->getPolygons ()->begin (); i != _res->getPolygons ()->end () && !inside; i++)
517517 {
518518 inside = insidePolygon (lon, lat, *i);
519519 }
@@ -610,14 +610,27 @@ std::vector<Target*> Globe::getTargets(int x, int y, bool craft) const
610610 */
611611void Globe::cachePolygons ()
612612{
613- // Cache ocean
614- for (std::vector<Polygon*>::iterator i = _cacheOcean.begin (); i != _cacheOcean.end (); i++)
613+ cache (&_ocean, &_cacheOcean);
614+ cache (_res->getPolygons (), &_cacheLand);
615+ draw ();
616+ }
617+
618+ /* *
619+ * Caches a set of polygons.
620+ * @param polygons Pointer to list of polygons.
621+ * @param cache Pointer to cache.
622+ */
623+ void Globe::cache (std::list<Polygon*> *polygons, std::list<Polygon*> *cache)
624+ {
625+ // Clear existing cache
626+ for (std::list<Polygon*>::iterator i = cache->begin (); i != cache->end (); i++)
615627 {
616628 delete *i;
617629 }
618- _cacheOcean. clear ();
630+ cache-> clear ();
619631
620- for (std::vector<Polygon*>::iterator i = _ocean.begin (); i != _ocean.end (); i++)
632+ // Pre-calculate values to cache
633+ for (std::list<Polygon*>::iterator i = polygons->begin (); i != polygons->end (); i++)
621634 {
622635 // Is quad on the back face?
623636 bool backFace = true ;
@@ -639,42 +652,8 @@ void Globe::cachePolygons()
639652 p->setY (j, y);
640653 }
641654
642- _cacheOcean.push_back (p);
643- }
644-
645- // Cache land
646- for (std::vector<Polygon*>::iterator i = _cacheLand.begin (); i != _cacheLand.end (); i++)
647- {
648- delete *i;
649- }
650- _cacheLand.clear ();
651-
652- for (std::vector<Polygon*>::iterator i = _res->getPolygons ()->begin (); i != _res->getPolygons ()->end (); i++)
653- {
654- // Don't draw if polygon is facing back
655- bool backFace = true ;
656- for (int j = 0 ; j < (*i)->getPoints (); j++)
657- {
658- backFace = backFace && pointBack ((*i)->getLongitude (j), (*i)->getLatitude (j));
659- }
660- if (backFace)
661- continue ;
662-
663- Polygon* p = new Polygon (**i);
664-
665- // Convert coordinates
666- for (int j = 0 ; j < p->getPoints (); j++)
667- {
668- Sint16 x, y;
669- polarToCart (p->getLongitude (j), p->getLatitude (j), &x, &y);
670- p->setX (j, x);
671- p->setY (j, y);
672- }
673-
674- _cacheLand.push_back (p);
655+ cache->push_back (p);
675656 }
676-
677- draw ();
678657}
679658
680659/* *
@@ -772,7 +751,7 @@ void Globe::drawOcean()
772751
773752 filledCircleColor (getSurface (), _cenX, _cenY, (Sint16)floor (_radius[_zoom]), Palette::getRGBA (this ->getPalette (), Palette::blockOffset (12 )+28 ));
774753
775- for (std::vector <Polygon*>::iterator i = _cacheOcean.begin (); i != _cacheOcean.end (); i++)
754+ for (std::list <Polygon*>::iterator i = _cacheOcean.begin (); i != _cacheOcean.end (); i++)
776755 {
777756 double tmpLon = (*i)->getLongitude (0 );
778757
@@ -806,7 +785,7 @@ void Globe::drawLand()
806785 double minLon = 0.0 , maxLon = 0.0 , curTime = _save->getTime ()->getDaylight ();
807786 Sint16 x[4 ], y[4 ];
808787
809- for (std::vector <Polygon*>::iterator i = _cacheLand.begin (); i != _cacheLand.end (); i++)
788+ for (std::list <Polygon*>::iterator i = _cacheLand.begin (); i != _cacheLand.end (); i++)
810789 {
811790 // Convert coordinates
812791 for (int j = 0 ; j < (*i)->getPoints (); j++)
@@ -847,7 +826,7 @@ void Globe::drawDetail()
847826 // Lock the surface
848827 _countries->lock ();
849828
850- for (std::vector <Polyline*>::iterator i = _res->getPolylines ()->begin (); i != _res->getPolylines ()->end (); i++)
829+ for (std::list <Polyline*>::iterator i = _res->getPolylines ()->begin (); i != _res->getPolylines ()->end (); i++)
851830 {
852831 Sint16 x[2 ], y[2 ];
853832 for (int j = 0 ; j < (*i)->getPoints () - 1 ; j++)
@@ -871,6 +850,11 @@ void Globe::drawDetail()
871850 // Draw the country names
872851 if (_zoom >= 2 )
873852 {
853+ Text *label = new Text (_res->getFont (" BIGLETS.DAT" ), _res->getFont (" SMALLSET.DAT" ), 80 , 9 , 0 , 0 );
854+ label->setPalette (getPalette ());
855+ label->setAlign (ALIGN_CENTER );
856+ label->setColor (Palette::blockOffset (15 )-1 );
857+
874858 Sint16 x, y;
875859 for (std::map<LangString, Country*>::iterator i = _save->getCountries ()->begin (); i != _save->getCountries ()->end (); i++)
876860 {
@@ -881,18 +865,23 @@ void Globe::drawDetail()
881865 // Convert coordinates
882866 polarToCart (i->second ->getLabelLongitude (), i->second ->getLabelLatitude (), &x, &y);
883867
884- Text *label = new Text (_res->getFont (" BIGLETS.DAT" ), _res->getFont (" SMALLSET.DAT" ), 80 , 9 , x - 40 , y);
885- label->setPalette (getPalette ());
886- label->setAlign (ALIGN_CENTER );
868+ label->setX (x - 40 );
869+ label->setY (y);
887870 label->setText (_res->getLanguage ()->getString (i->first ));
888- label->setColor (Palette::blockOffset (15 )-1 );
889871 label->blit (_countries);
890872 }
873+
874+ delete label;
891875 }
892876
893877 // Draw the city markers
894878 if (_zoom >= 3 )
895879 {
880+ Text *label = new Text (_res->getFont (" BIGLETS.DAT" ), _res->getFont (" SMALLSET.DAT" ), 80 , 9 , 0 , 0 );
881+ label->setPalette (getPalette ());
882+ label->setAlign (ALIGN_CENTER );
883+ label->setColor (Palette::blockOffset (8 )+10 );
884+
896885 Sint16 x, y;
897886 for (std::map<LangString, Region*>::iterator i = _save->getRegions ()->begin (); i != _save->getRegions ()->end (); i++)
898887 {
@@ -910,14 +899,14 @@ void Globe::drawDetail()
910899 _mkCity->setPalette (getPalette ());
911900 _mkCity->blit (_countries);
912901
913- Text *label = new Text (_res->getFont (" BIGLETS.DAT" ), _res->getFont (" SMALLSET.DAT" ), 80 , 9 , x - 40 , y + 2 );
914- label->setPalette (getPalette ());
915- label->setAlign (ALIGN_CENTER );
902+ label->setX (x - 40 );
903+ label->setY (y + 2 );
916904 label->setText (_res->getLanguage ()->getString ((*j)->getName ()));
917- label->setColor (Palette::blockOffset (8 )+10 );
918905 label->blit (_countries);
919906 }
920907 }
908+
909+ delete label;
921910 }
922911}
923912
0 commit comments