MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / loadDat

Method loadDat

src/Geoscape/Globe.cpp:548–599  ·  view source on GitHub ↗

* Loads a series of map polar coordinates in X-Com format, * converts them and stores them in a set of polygons. * @param filename Filename of the DAT file. * @param polygons Pointer to the polygon set. * @sa http://www.ufopaedia.org/index.php?title=WORLD.DAT */

Source from the content-addressed store, hash-verified

546 * @sa http://www.ufopaedia.org/index.php?title=WORLD.DAT
547 */
548void Globe::loadDat(const std::string &filename, std::list<Polygon*> *polygons)
549{
550 // Load file
551 std::ifstream mapFile (filename.c_str(), std::ios::in | std::ios::binary);
552 if (!mapFile)
553 {
554 throw Exception(filename + " not found");
555 }
556
557 short value[10];
558
559 while (mapFile.read((char*)&value, sizeof(value)))
560 {
561 Polygon* poly;
562 int points;
563
564 for (int i = 0; i < 10; ++i)
565 {
566 value[i] = SDL_SwapLE16(value[i]);
567 }
568
569 if (value[6] != -1)
570 {
571 points = 4;
572 }
573 else
574 {
575 points = 3;
576 }
577 poly = new Polygon(points);
578
579 for (int i = 0, j = 0; i < points; ++i)
580 {
581 // Correct X-Com degrees and convert to radians
582 double lonRad = value[j++] * 0.125f * M_PI / 180;
583 double latRad = value[j++] * 0.125f * M_PI / 180;
584
585 poly->setLongitude(i, lonRad);
586 poly->setLatitude(i, latRad);
587 }
588 poly->setTexture(value[8]);
589
590 polygons->push_back(poly);
591 }
592
593 if (!mapFile.eof())
594 {
595 throw Exception("Invalid globe map");
596 }
597
598 mapFile.close();
599}
600
601/**
602 * Sets a leftwards rotation speed and starts the timer.

Callers

nothing calls this directly

Calls 5

ExceptionClass · 0.85
setLongitudeMethod · 0.45
setLatitudeMethod · 0.45
setTextureMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected