Example #1
0
File: gtm.cpp Project: OSGeo/gdal
vsi_l_offset GTM::findFirstWaypointOffset()
{
    /* Skip header and datum */
    if ( VSIFSeekL(pGTMFile, headerSize + DATUM_SIZE, SEEK_SET) != 0)
        return 0;

    /* Skip images */
    for (int i = 0; i < n_maps; ++i)
    {
        /* Read image name string size */
        bool bSuccess = false;
        unsigned short stringSize = readUShort(pGTMFile, &bSuccess);

        /* skip image name string */
        if ( !bSuccess ||  VSIFSeekL(pGTMFile, stringSize, SEEK_CUR) != 0)
            return 0;

        /* read image comment string size */
        stringSize = readUShort(pGTMFile, &bSuccess);

        /* skip image comment string */
        if ( !bSuccess || VSIFSeekL(pGTMFile, stringSize, SEEK_CUR) != 0)
            return 0;

        /* skip the others image parameters */
        if ( VSIFSeekL(pGTMFile, 30, SEEK_CUR) != 0)
            return 0;
    }
    return VSIFTellL(pGTMFile);
}
Example #2
0
File: gtm.cpp Project: OSGeo/gdal
vsi_l_offset GTM::findFirstTrackpointOffset()
{
    if (firstWaypointOffset == 0)
    {
        firstWaypointOffset = findFirstWaypointOffset();
        if (firstWaypointOffset == 0)
            return 0;
    }

    /*---------------------------------------------*/
    /*       We are going to skip the waypoints    */
    /*---------------------------------------------*/
    /* Seek file to the first Waypoint */
    if (VSIFSeekL(pGTMFile, firstWaypointOffset, SEEK_SET) != 0)
        return 0;

    /* Skip waypoints */
    for (int i = 0; i < nwpts; ++i)
    {
        /* Seek file to the string size comment field */
        if (VSIFSeekL(pGTMFile, 26, SEEK_CUR) != 0)
            return 0;
        /* Read string comment size */
        bool bSuccess = false;
        const unsigned short stringSize = readUShort(pGTMFile, &bSuccess);

        /* Skip to the next Waypoint */
        if( !bSuccess || VSIFSeekL(pGTMFile, stringSize + 15, SEEK_CUR) != 0 )
            return 0;
    }

    /* Skip waypoint styles */
    /* If we don't have waypoints, we don't have waypoint styles, even
       though the nwptstyles is telling the contrary. */
    if (nwpts != 0)
    {
        for (int i = 0; i < nwptstyles; ++i)
        {
            /* Seek file to the string size facename field */
            if (VSIFSeekL(pGTMFile, 4, SEEK_CUR) != 0)
                return 0;

            /* Read string facename size */
            bool bSuccess = false;
            const unsigned short stringSize = readUShort(pGTMFile, &bSuccess);

            /* Skip to the next Waypoint Style*/
            if( !bSuccess ||
                VSIFSeekL(pGTMFile, stringSize + 24, SEEK_CUR) != 0 )
                return 0;
        }
    }
    /* We've found the first track. Return the offset*/
    return VSIFTellL(pGTMFile);
}
Example #3
0
u16 NitroFile::getUshortAt(int offs)
{
    if(cached)
        return *(u16*)(cachedContents+offs);
    fseek(parent->romFile, begOffs+offs, SEEK_SET);
    return readUShort(parent->romFile);
}
Example #4
0
int main(int argc, char *argv[])
{
//    QApplication::setGraphicsSystem("opengl");
    QApplication a(argc, argv);

    qRegisterMetaType<RandomUtil*>("RandomUtil*");
    qRegisterMetaType<GameTime*>("GameTime*");
    qRegisterMetaType<Player*>("Player*");
    qRegisterMetaType<Planet*>("Planet*");
    qRegisterMetaType<Ship*>("Ship*");
    qRegisterMetaType<PlayerIntelligence*>("PlayerIntelligence*");

    RandomUtil::init();
    QStringList arguments = a.arguments();

#ifdef DEBUG
    qDebug() << "PlanetAttack started with arguments:" << arguments;
#endif

    QWidget *w;
    if (arguments.contains("-server")) {
        QHostAddress address = QHostAddress::Any;
        quint16 port = readUShort(arguments, "-port", MultiplayerServer::DEFAULT_PORT);

        MultiplayerServerWindow *server = new MultiplayerServerWindow;
        server->startListening(address, port);
        w = server;
    } else {
        if (arguments.contains("-noui")) {
            w = new Canvas;
        } else {
            w = new MainWindow;
        }
    }

    w->resize(1024, 768);
    // center window
    QDesktopWidget *desktop = QApplication::desktop();
    QRect desktopRect = desktop->availableGeometry();
    w->move(desktopRect.width() / 2 - w->width() / 2,
            desktopRect.height() / 2 - w->height() / 2);
    w->show();

    return a.exec();
}
Example #5
0
File: gtm.cpp Project: OSGeo/gdal
Track* GTM::fetchNextTrack()
{
    /* Point to the actual track offset */
    if ( VSIFSeekL(pGTMFile, actualTrackOffset, SEEK_SET) != 0)
        return nullptr;

    /* Read string length */
    const unsigned short stringSize = readUShort(pGTMFile);
    /* Read name string */
    char* pszName = (char*) VSI_MALLOC2_VERBOSE(sizeof(char), stringSize+1);
    if( pszName == nullptr )
        return nullptr;
    if ( stringSize != 0 && !readFile( pszName, 1, sizeof(char) * stringSize ) )
    {
        CPLFree(pszName);
        return nullptr;
    }
    pszName[stringSize] = '\0';

    /* Read type */
    const unsigned char type = readUChar(pGTMFile);

    /* Read color */
    const int color = readInt(pGTMFile);

    Track* poTrack = new Track(pszName, type, color);

    CPLFree(pszName);
    /* Adjust actual Track offset */
    actualTrackOffset = VSIFTellL(pGTMFile) + 7;
    ++trackFetched;

    /* Now, We read all trackpoints for this track */
    double latitude = 0.0;
    double longitude = 0.0;
    GIntBig datetime = 0;
    unsigned char start = 0;
    float altitude = 0.0f;
    /* NOTE: Parameters are passed by reference */
    if ( !readTrackPoints(latitude, longitude, datetime, start, altitude) )
    {
        delete poTrack;
        return nullptr;
    }

    /* Check if it is the start, if not we have done something wrong */
    if (start != 1)
    {
        delete poTrack;
        return nullptr;
    }
    poTrack->addPoint(longitude, latitude, datetime, altitude);

    do
    {
        /* NOTE: Parameters are passed by reference */
        if ( !readTrackPoints(latitude, longitude, datetime, start, altitude) )
        {
            delete poTrack;
            return nullptr;
        }
        if (start == 0)
            poTrack->addPoint(longitude, latitude, datetime, altitude);
    } while(start == 0 && trackpointFetched < ntcks);

    /* We have read one more than necessary, so we adjust the offset */
    if (trackpointFetched < ntcks)
    {
        actualTrackpointOffset -= 25;
        --trackpointFetched;
    }

    return poTrack;
}
Example #6
0
File: gtm.cpp Project: OSGeo/gdal
Waypoint* GTM::fetchNextWaypoint()
{
    /* Point to the actual waypoint offset */
    if ( VSIFSeekL(pGTMFile, actualWaypointOffset, SEEK_SET) != 0)
        return nullptr;

    const double latitude = readDouble(pGTMFile);
    const double longitude = readDouble(pGTMFile);

    char name[11];
    if ( !readFile( name, 1, 10 ) )
        return nullptr;

    /* Trim string name */
    {
        int i = 9;  // Used after for.
        for( ; i >= 0; --i)
        {
            if (name[i] != ' ')
            {
                name[i+1] = '\0';
                break;
            }
        }
        if (i < 0)
            name[0] = '\0';
    }

    /* Read String Length */
    const unsigned short stringSize = readUShort(pGTMFile);
    /* Read Comment String */
    char* comment = static_cast<char *>(
        VSI_MALLOC2_VERBOSE(sizeof(char), stringSize+1) );
    if( comment == nullptr )
        return nullptr;
    if ( stringSize != 0 && !readFile( comment, 1, sizeof(char)*stringSize ) )
    {
        CPLFree(comment);
        return nullptr;
    }
    comment[stringSize] = '\0';

    /* Read Icon */
    const unsigned short icon = readUShort(pGTMFile);

    /* Display number */
    readUChar(pGTMFile);

    /* Waypoint date */

    GIntBig wptdate = readInt(pGTMFile);
    if (wptdate != 0)
        wptdate += GTM_EPOCH;

    /* Rotation text angle */
    readUShort(pGTMFile);

    /* Altitude */
    const float altitude = readFloat(pGTMFile);

    Waypoint* poWaypoint = new Waypoint(latitude, longitude, altitude,
                                        name, comment, (int) icon, wptdate);

    /* Set actual waypoint offset to the next it there is one */
    ++waypointFetched;
    if (waypointFetched < nwpts)
    {
        actualWaypointOffset +=
            8 + 8 + 10 + 2 + stringSize + 2 + 1 + 4 + 2 + 4 + 2;
    }

    CPLFree(comment);
    return poWaypoint;
}
Example #7
0
File: gtm.cpp Project: OSGeo/gdal
bool GTM::readHeaderNumbers()
{
    if (pGTMFile == nullptr)
        return false;

    /* I'm supposing that the user has already checked if the file is
       valid.  */
    /* Also, I'm ignoring some header parameters that are unnecessary
       for my purpose. If you want more features, implement it. :-P */

    /* Read Number of Waypoint Styles*/
    /* Seek file */
    if (VSIFSeekL(pGTMFile, NWPTSTYLES_OFFSET, SEEK_SET) != 0)
        return false;
    /* Read nwptstyles */
    nwptstyles = readInt(pGTMFile);
    if (nwptstyles < 0)
        return false;

    /* Read Number of Waypoints */
    /* Seek file */
    if ( VSIFSeekL(pGTMFile, NWPTS_OFFSET, SEEK_SET) != 0)
        return false;
    /* Read nwpts */
    nwpts = readInt(pGTMFile);
    if (nwpts < 0)
        return false;

    /* Read Number of Trackpoints */
    ntcks = readInt(pGTMFile);
    if (ntcks < 0)
        return false;

    /* Read Number of images */
    /* Seek file */
    if ( VSIFSeekL(pGTMFile, NMAPS_OFFSET, SEEK_SET) != 0)
        return false;
    /* read n_maps */
    n_maps = readInt(pGTMFile);
    if (n_maps < 0)
        return false;

    /* Read Number of Tracks */
    n_tk = readInt(pGTMFile);
    if (n_tk < 0)
        return false;

    /* Figure out the header size */
    headerSize = 99; // Constant size plus size of strings

    /* Read gradfont string size */
    if ( VSIFSeekL(pGTMFile, 99, SEEK_SET) != 0)
        return false;
    unsigned short stringSize = readUShort(pGTMFile);
    headerSize += stringSize + 2; // String + size field

    /* Read labelfont string size */
    if ( VSIFSeekL(pGTMFile, stringSize, SEEK_CUR) != 0)
        return false;
    stringSize = readUShort(pGTMFile);
    headerSize += stringSize + 2; // String + size field

    /* Read userfont string size */
    if ( VSIFSeekL(pGTMFile, stringSize, SEEK_CUR) != 0)
        return false;
    stringSize = readUShort(pGTMFile);
    headerSize += stringSize + 2; // String + size field

    /* Read newdatum string size */
    if ( VSIFSeekL(pGTMFile, stringSize, SEEK_CUR) != 0)
        return false;
    stringSize = readUShort(pGTMFile);
    headerSize += stringSize + 2; // String + size field

/* -------------------------------------------------------------------- */
/*                 Checks if it is using WGS84 datum                    */
/* -------------------------------------------------------------------- */
    /* Read newdatum string size */
    if ( VSIFSeekL(pGTMFile, headerSize + 34, SEEK_SET) != 0)
        return false;
    if (readInt(pGTMFile) != 217)
    {
        CPLError( CE_Warning, CPLE_AppDefined,
                  "You are attempting to open a file that is not using "
                  "WGS84 datum.\n"
                  "Coordinates will be returned as if they were WGS84, "
                  "but no reprojection will be done." );
    }

    /* Look for the offsets */
    /* Waypoints */
    firstWaypointOffset = findFirstWaypointOffset();
    if (firstWaypointOffset == 0)
        return false;
    actualWaypointOffset = firstWaypointOffset;
    /* Trackpoints */
    firstTrackpointOffset = findFirstTrackpointOffset();
    if (firstTrackpointOffset == 0)
        return false;
    actualTrackpointOffset = firstTrackpointOffset;

    /* Tracks */
    firstTrackOffset = findFirstTrackOffset();
    if (firstTrackOffset == 0)
        return false;
    actualTrackOffset = firstTrackOffset;

    return true;
}
Example #8
0
char* DataInput::readUTF()
{
    unsigned short len = readUShort();
    return readBytes(len);
}
Example #9
0
Waypoint* GTM::fetchNextWaypoint()
{
    unsigned short stringSize;

    double latitude, longitude;
    char name[11];
    char* comment;
    unsigned short icon;
    int i;
    float altitude;
    GIntBig wptdate;

    /* Point to the actual waypoint offset */
    if ( VSIFSeekL(pGTMFile, actualWaypointOffset, SEEK_SET) != 0)
        return NULL;

    latitude = readDouble(pGTMFile);
    longitude = readDouble(pGTMFile);

    if ( !readFile( name, 1, 10 ) )
        return NULL;
    /* Trim string name */
    for (i = 9; i >= 0; --i)
    {
        if (name[i] != ' ')
        {
            name[i+1] = '\0';
            break;
        }
    }
    if (i < 0)
        name[0] = '\0';

    /* Read String Length */
    stringSize = readUShort(pGTMFile);
    /* Read Comment String */
    comment = (char*) VSIMalloc2(sizeof(char), stringSize+1);
    if ( stringSize != 0 && !readFile( comment, 1, sizeof(char)*stringSize ) )
    {
        CPLFree(comment);
        return NULL;
    }
    comment[stringSize] = '\0';

    /* Read Icon */
    icon = readUShort(pGTMFile);
    
    /* Display number */
    readUChar(pGTMFile);
    
    /* Waypoint date */
    
    wptdate = readInt(pGTMFile);
    if (wptdate != 0)
        wptdate += GTM_EPOCH;
    
    /* Rotation text angle */
    readUShort(pGTMFile);
    
    /* Altitude */
    altitude = readFloat(pGTMFile);
  
    Waypoint* poWaypoint = new Waypoint(latitude, longitude, altitude,
                                        name, comment, (int) icon, wptdate);


    /* Set actual waypoint offset to the next it there is one */
    ++waypointFetched;
    if (waypointFetched < nwpts)
    {
        actualWaypointOffset += 8 + 8 + 10 + 2 + stringSize + 2 + 1 + 4 + 2 + 4 + 2;
    }

    CPLFree(comment);
    return poWaypoint;
}