Example #1
0
void aivarLabelSet(AIVar *var, char *label)
{
    if (!var)
        return;

    memStrncpy(var->label, label, AIVAR_LABEL_MAX_LENGTH);
    /*
    if (strlen(label) < AIVAR_LABEL_MAX_LENGTH)
        var->label[strlen(label)] = 0;
    else
        var->label[AIVAR_LABEL_MAX_LENGTH] = 0;
        */
}
Example #2
0
/*-----------------------------------------------------------------------------
    Name        : gpGameNameDraw
    Description : Draw the currently selected game name in screens other
                    than the game picker.
    Inputs      :
    Outputs     :
    Return      :
----------------------------------------------------------------------------*/
void gpGameNameDraw(featom *atom, regionhandle region)
{
    fonthandle fhSave;
    char gameName[128];

    rectangle *r = &region->rect;

    fhSave = fontMakeCurrent(gpNameFont); //select the appropriate font
    memStrncpy(gameName, gpGames[gpCurrentSelected].title, 127);
    _strupr(gameName);
    fontPrintf(r->x0, r->y0, GP_SelectedColor, gameName);
    fontMakeCurrent(fhSave);
}
Example #3
0
/*-----------------------------------------------------------------------------
    Name        : spScenarioNameDraw
    Description : Draw the currently selected scenario name in screens other
                    than the scenario picker.
    Inputs      :
    Outputs     :
    Return      :
----------------------------------------------------------------------------*/
void spScenarioNameDraw(featom *atom, regionhandle region)
{
    fonthandle fhSave;
    char scenarioName[128];
    bool useDisplayName = FALSE;

    rectangle *r = &region->rect;

    fhSave = fontMakeCurrent(spNameFont); //select the appropriate font

    if (multiPlayerGame && (!GameCreator))
    {
        if (LANGame)
        {
            if (currentScreen == MGS_Basic_Options_View)
            {
                useDisplayName = TRUE;
            }
        }
        else
        {
            if (WaitingForGame)
            {
                useDisplayName = TRUE;
            }
        }
    }

    if (useDisplayName)
        memStrncpy(scenarioName, tpGameCreated.DisplayMapName, 127);
    else
        memStrncpy(scenarioName, spScenarios[spCurrentSelected].title, 127);
    _strupr(scenarioName);
    fontPrintf(r->x0, r->y0, FEC_ListItemSelected, scenarioName);
    fontMakeCurrent(fhSave);
}
Example #4
0
/*-----------------------------------------------------------------------------
    Name        : spTitleFind
    Description : Finds the title of a mission file (on first line, in brackets)
    Inputs      : directory, fileName - combine to form path to the file.
    Outputs     : Allocated memory for and duplicates a string.
    Return      : Pointer to title string.
----------------------------------------------------------------------------*/
char *spTitleFind(char *directory, char *fileName)
{
    char string[256], fullName[_MAX_PATH];
    filehandle handle;
    sdword status;

    memStrncpy(fullName, directory, _MAX_PATH - 1);
    strcat(fullName, fileName);
    strcat(fullName,"\\");
    strcat(fullName, fileName);
    strcat(fullName,".level");
    handle = fileOpen(fullName, FF_TextMode|FF_ReturnNULLOnFail);
    if (!handle)
    {
        return NULL;
    }

    for (;;)
    {
        status = fileLineRead(handle,string,256);

        if (status == FR_EndOfFile)
        {
            break;
        }

        if ((string[0] == '\n') || (string[0] == '/') || (string[0] == ';') || (string[0] == ' '))
        {
            continue;
        }

        if (strlen(string) >= 3 && *string == '[' && string[strlen(string) - 1] == ']')
        {
            fileClose(handle);
            string[strlen(string) - 1] = 0;
            return(memStringDupe(&string[1]));
        }
    }

    fileClose(handle);

    return memStringDupe(fullName);
}
Example #5
0
/*-----------------------------------------------------------------------------
    Name        : spTitleListLoad
    Description : Scans the missions directory and loads in the titles of all
                    the mission files available.
    Inputs      : void
    Outputs     : Fills in spScenarios and spNumberScenarios
    Return      : void
----------------------------------------------------------------------------*/
void spTitleListLoad(void)
{
#if !(defined(CGW) || defined (Downloadable) || defined(DLPublicBeta) || defined(OEM))
    struct _finddata_t find;
    sdword handle, startHandle;
#endif
    sdword index, numplayers;
    char fileName[_MAX_PATH], nameBuffer[_MAX_PATH];
#if MAIN_Password
    char upperNameBuffer[_MAX_PATH];
#endif
    char bitmapfileName[_MAX_PATH];
    char *pString;
    char *title;
    filehandle scriptFile;

#if defined(CGW) || defined(Downloadable) || defined(DLPublicBeta)
    scriptFile = fileOpen("DemoMissions.script", FF_TextMode);
#else
    //oem has all missions!
    scriptFile = fileOpen("multiPlayerMissions.script", FF_TextMode);
#endif
    dbgAssert(scriptFile != 0);

    while (fileLineRead(scriptFile, nameBuffer, _MAX_PATH) != FR_EndOfFile)
    {
        if (nameBuffer[0] == ';' || (nameBuffer[0] == '/' && nameBuffer[1] == '/'))
        {
            continue;
        }
        numplayers = 0;
        for (pString = nameBuffer; *pString != 0; pString++)
        {                                                   //search for a numeral character
            if (strchr("0123456789", *pString) != NULL)
            {                                               //if this is a numeral
                numplayers = atoi(pString);
                memset(fileName, 0, _MAX_PATH);
                memStrncpy(fileName, nameBuffer, pString - nameBuffer + 1);//copy the start of the string
                memStrncpy(bitmapfileName, nameBuffer, pString - nameBuffer + 1);//copy the start of the string
                strcat(fileName, "%d");                     //make something like:
                strcat(fileName, pString + 1);              //'StdGame%d.level'
            }
        }

        if (numplayers == 0)
        {
            goto alreadyLoaded;
        }

        title = spTitleFind("MultiPlayer\\", nameBuffer);
        if (title == NULL)
        {
            goto alreadyLoaded;                             //break-continue
        }
#if MAIN_Password
        if (!mainEnableSpecialMissions)
        {                                                   //if this is an "off-limits" mission
            strcpy(upperNameBuffer, title);
            _strupr(upperNameBuffer);
            if (strstr(upperNameBuffer, "ALL"))
            {
                memFree(title);
                goto alreadyLoaded;                         //break-continue
            }
        }
#endif //MAIN_Password

        for (index = 0; index < spNumberScenarios; index++)
        {
            if (!_stricmp(spScenarios[index].fileSpec, fileName))
            {                                               //if matching file specs,
                // matches, but we should update max number of player if necessary
                if (numplayers > spScenarios[index].maxplayers) spScenarios[index].maxplayers = numplayers;
                if (numplayers < spScenarios[index].minplayers) spScenarios[index].minplayers = numplayers;
                memFree(title);
                goto alreadyLoaded;                         //break-continue
            }
        }

        if (spNumberScenarios >= spScenarioListLength)
        {
            spScenarioListLength += SP_ScenarioListGrowth;
            spScenarios = memRealloc(spScenarios, spScenarioListLength * sizeof(spscenario), "spScenarios", NonVolatile);
        }
        dbgAssert(spNumberScenarios < spScenarioListLength);
        spScenarios[spNumberScenarios].fileSpec = memStringDupe(fileName);
        spScenarios[spNumberScenarios].bitmapfileSpec = memStringDupe(bitmapfileName);
        spScenarios[spNumberScenarios].title = title;
        spScenarios[spNumberScenarios].maxplayers = numplayers;
        spScenarios[spNumberScenarios].minplayers = numplayers;
        spNumberScenarios++;

alreadyLoaded:;
    }
    fileClose(scriptFile);

#if !(defined(CGW) || defined (Downloadable) || defined(DLPublicBeta) || defined(OEM))
    startHandle = handle = _findfirst(filePathPrepend("MultiPlayer\\*.", 0), &find);

    while (handle != -1)
    {
        if (find.name[0] == '.')
        {
            goto alreadyLoadedFromFileSystem;
        }
        fileName[0] = 0;
        numplayers = 0;
        for (pString = find.name; *pString != 0; pString++)
        {                                                   //search for a numeral character
            if (strchr("0123456789", *pString) != NULL)
            {                                               //if this is a numeral
                numplayers = atoi(pString);
                memset(fileName, 0, _MAX_PATH);
                strncpy(fileName, find.name, pString - find.name);//copy the start of the string
                memStrncpy(bitmapfileName, find.name, pString - find.name + 1);//copy the start of the string
                strcat(fileName, "%d");                     //make something like:
                strcat(fileName, pString + 1);              //'StdGame%d.level'
            }
        }
        if (numplayers == 0)
        {
            goto alreadyLoadedFromFileSystem;
        }

        if (fileName[0] == 0)
        {
            goto alreadyLoadedFromFileSystem;
        }

        title = spTitleFind("MultiPlayer\\", find.name);
        if (title == NULL)
        {
            goto alreadyLoadedFromFileSystem;
        }
#if MAIN_Password
        if (!mainEnableSpecialMissions)
        {                                                   //if this is an "off-limits" mission
            strcpy(upperNameBuffer, title);
            _strupr(upperNameBuffer);
            if (strstr(upperNameBuffer, "ALL"))
            {
                memFree(title);
                goto alreadyLoadedFromFileSystem;           //break-continue
            }
        }
#endif //MAIN_Password

        for (index = 0; index < spNumberScenarios; index++)
        {
            if (!_stricmp(spScenarios[index].fileSpec, fileName))
            {                                               //if matching file specs,
                // matches, but we should update max number of player if necessary
                if (numplayers > spScenarios[index].maxplayers) spScenarios[index].maxplayers = numplayers;
                if (numplayers < spScenarios[index].minplayers) spScenarios[index].minplayers = numplayers;
                memFree(title);
                goto alreadyLoadedFromFileSystem;                         //break-continue
            }
        }

        if (spNumberScenarios >= spScenarioListLength)
        {
            spScenarioListLength += SP_ScenarioListGrowth;
            spScenarios = memRealloc(spScenarios, spScenarioListLength * sizeof(spscenario), "spScenarios", NonVolatile);
        }
        dbgAssert(spNumberScenarios < spScenarioListLength);
        spScenarios[spNumberScenarios].fileSpec = memStringDupe(fileName);
        spScenarios[spNumberScenarios].bitmapfileSpec = memStringDupe(bitmapfileName);
        spScenarios[spNumberScenarios].title = title;
        spScenarios[spNumberScenarios].maxplayers = numplayers;
        spScenarios[spNumberScenarios].minplayers = numplayers;
        spNumberScenarios++;

alreadyLoadedFromFileSystem:;
        handle = _findnext(startHandle, &find);
    }
#endif //defined(CGW) || defined (Downloadable) || defined(DLPublicBeta) || defined(OEM)

    dbgAssert(spNumberScenarios > 0);
    if (spNumberScenarios > 1)
    {
        //alphabetically sort the scenario list
        qsort(&spScenarios[0],spNumberScenarios,sizeof(spscenario),compareScenariosCB);
    }

    //find the default scenario's index
    if (spCurrentSelected == 0)
    {                                                       //if it's not already selected
        spCurrentSelected = spScenarioFind(DefaultScenario);
    }
}
Example #6
0
/*-----------------------------------------------------------------------------
    Name        : btgLoad
    Description : load a btg scene into our structures
    Inputs      : filename - the name of the btg file to load
    Outputs     :
    Return      :
----------------------------------------------------------------------------*/
void btgLoad(char* filename)
{
    ubyte* btgData       = NULL;
    ubyte* btgDataOffset = NULL;
    ubyte* instarp       = NULL;
    udword headSize;
    udword vertSize;
    udword vertSizeFile;
    udword starSize, fileStarSize;
    udword polySize;
    real32 thetaSave, phiSave;
    udword i;
#if FIX_ENDIAN
    Uint64 *swap;
#endif

#if BTG_VERBOSE_LEVEL >= 2
    dbgMessagef("filename= %s", filename);
#endif


    fileLoadAlloc(filename, (void**)&btgData, 0);
    btgDataOffset=btgData;

    memStrncpy(btgLastBackground, filename, 127);

    //reset / free any previous structures
    thetaSave = btgThetaOffset;
    phiSave = btgPhiOffset;
    btgReset();
    btgThetaOffset = thetaSave;
    btgPhiOffset = phiSave;

    //header.  trivial copy
    headSize = sizeof(btgHeader);
    btgHead = (btgHeader*)memAlloc(headSize, "btg header", 0);

#if BTG_VERBOSE_LEVEL >=3
 dbgMessagef("btgData= %x", btgData);
 dbgMessagef("btgHead= %x", btgHead);
#endif


// Hard coding sizeof values. 
// This is because they may change later on in the world but static in the file.
// This allows us to align variables. It replaces 
//  memcpy(btgHead, btgData, headSize);

    memset(btgHead,0,sizeof(btgHead));

    memcpy( (ubyte*)btgHead+offsetof(btgHeader,btgFileVersion), btgDataOffset, 4 );
    btgDataOffset += 4;

    memcpy( (ubyte*)btgHead+offsetof(btgHeader,numVerts      ), btgDataOffset, 4 );
    btgDataOffset += 4;

    memcpy( (ubyte*)btgHead+offsetof(btgHeader,numStars      ), btgDataOffset, 4 );
    btgDataOffset += 4;

    memcpy( (ubyte*)btgHead+offsetof(btgHeader,numPolys      ), btgDataOffset, 4 );
    btgDataOffset += 4;

    memcpy( (ubyte*)btgHead+offsetof(btgHeader,xScroll       ), btgDataOffset, 4 );
    btgDataOffset += 4;

    memcpy( (ubyte*)btgHead+offsetof(btgHeader,yScroll       ), btgDataOffset, 4 );
    btgDataOffset += 4;

    memcpy( (ubyte*)btgHead+offsetof(btgHeader,zoomVal       ), btgDataOffset, 4 );
    btgDataOffset += 4;

    memcpy( (ubyte*)btgHead+offsetof(btgHeader,pageWidth     ), btgDataOffset, 4 );
    btgDataOffset += 4;

    memcpy( (ubyte*)btgHead+offsetof(btgHeader,pageHeight    ), btgDataOffset, 4 );
    btgDataOffset += 4;

    memcpy( (ubyte*)btgHead+offsetof(btgHeader,mRed          ), btgDataOffset, 4 );
    btgDataOffset += 4;

    memcpy( (ubyte*)btgHead+offsetof(btgHeader,mGreen        ), btgDataOffset, 4 );
    btgDataOffset += 4;

    memcpy( (ubyte*)btgHead+offsetof(btgHeader,mBlue         ), btgDataOffset, 4 );
    btgDataOffset += 4;

    memcpy( (ubyte*)btgHead+offsetof(btgHeader,mBGRed        ), btgDataOffset, 4 );
    btgDataOffset += 4;

    memcpy( (ubyte*)btgHead+offsetof(btgHeader,mBGGreen      ), btgDataOffset, 4 );
    btgDataOffset += 4;

    memcpy( (ubyte*)btgHead+offsetof(btgHeader,mBGBlue       ), btgDataOffset, 4 );
    btgDataOffset += 4;

    memcpy( (ubyte*)btgHead+offsetof(btgHeader,bVerts        ), btgDataOffset, 4 );
    btgDataOffset += 4;

    memcpy( (ubyte*)btgHead+offsetof(btgHeader,bPolys        ), btgDataOffset, 4 );
    btgDataOffset += 4;

    memcpy( (ubyte*)btgHead+offsetof(btgHeader,bStars        ), btgDataOffset, 4 );
    btgDataOffset += 4;

    memcpy( (ubyte*)btgHead+offsetof(btgHeader,bOutlines     ), btgDataOffset, 4 );
    btgDataOffset += 4;

    memcpy( (ubyte*)btgHead+offsetof(btgHeader,bBlends       ), btgDataOffset, 4 );
    btgDataOffset += 4;

    memcpy( (ubyte*)btgHead+offsetof(btgHeader,renderMode    ), btgDataOffset, 4 );
    btgDataOffset += 4;
        
//    memcpy(btgHead, btgData, headSize);  //See above.

#if FIX_ENDIAN
	btgHead->btgFileVersion = FIX_ENDIAN_INT_32( btgHead->btgFileVersion );
	btgHead->numVerts       = FIX_ENDIAN_INT_32( btgHead->numVerts );
	btgHead->numStars       = FIX_ENDIAN_INT_32( btgHead->numStars );
	btgHead->numPolys       = FIX_ENDIAN_INT_32( btgHead->numPolys );
	btgHead->xScroll        = FIX_ENDIAN_INT_32( btgHead->xScroll );
	btgHead->yScroll        = FIX_ENDIAN_INT_32( btgHead->yScroll );
	btgHead->zoomVal        = FIX_ENDIAN_INT_32( btgHead->zoomVal );
	btgHead->pageWidth      = FIX_ENDIAN_INT_32( btgHead->pageWidth );
	btgHead->pageHeight     = FIX_ENDIAN_INT_32( btgHead->pageHeight );
	btgHead->mRed           = FIX_ENDIAN_INT_32( btgHead->mRed );
	btgHead->mGreen         = FIX_ENDIAN_INT_32( btgHead->mGreen );
	btgHead->mBlue          = FIX_ENDIAN_INT_32( btgHead->mBlue );
	btgHead->mBGRed         = FIX_ENDIAN_INT_32( btgHead->mBGRed );
	btgHead->mBGGreen       = FIX_ENDIAN_INT_32( btgHead->mBGGreen );
	btgHead->mBGBlue        = FIX_ENDIAN_INT_32( btgHead->mBGBlue );
	btgHead->bVerts         = FIX_ENDIAN_INT_32( btgHead->bVerts );
	btgHead->bPolys         = FIX_ENDIAN_INT_32( btgHead->bPolys );
	btgHead->bStars         = FIX_ENDIAN_INT_32( btgHead->bStars );
	btgHead->bOutlines      = FIX_ENDIAN_INT_32( btgHead->bOutlines );
	btgHead->bBlends        = FIX_ENDIAN_INT_32( btgHead->bBlends );
	btgHead->renderMode     = FIX_ENDIAN_INT_32( btgHead->renderMode );
#endif

    //set background colour
    universe.backgroundColor = colRGB(btgHead->mBGRed, btgHead->mBGGreen, btgHead->mBGBlue);

    //version check
    dbgAssertOrIgnore(btgHead->btgFileVersion == BTG_FILE_VERSION);

    vertSize = btgHead->numVerts * sizeof(btgVertex);  //Machine Specific size

    vertSizeFile = btgHead->numVerts * (4 + (2* 8) + (5*4));  //Actual size from file. (No Alignment)

    if (vertSize)
    {

        btgVerts = (btgVertex*)memAlloc(vertSize, "btg verts", 0);

        for( i=0; i<btgHead->numVerts; i++ )
        {
            memcpy( (ubyte*)btgVerts+ ( i * sizeof(btgVertex)) +offsetof(btgVertex,flags     ), btgDataOffset, 4 );
            btgDataOffset += 4;

            memcpy( (ubyte*)btgVerts+( i * sizeof(btgVertex)) +offsetof(btgVertex,x          ), btgDataOffset, 8 );
            btgDataOffset += 8;

            memcpy( (ubyte*)btgVerts+( i * sizeof(btgVertex)) +offsetof(btgVertex,y          ), btgDataOffset, 8 );
            btgDataOffset += 8;

            memcpy( (ubyte*)btgVerts+( i * sizeof(btgVertex)) +offsetof(btgVertex,red        ), btgDataOffset, 4 );
            btgDataOffset += 4;

            memcpy( (ubyte*)btgVerts+( i * sizeof(btgVertex)) +offsetof(btgVertex,green      ), btgDataOffset, 4 );
            btgDataOffset += 4;

            memcpy( (ubyte*)btgVerts+( i * sizeof(btgVertex)) +offsetof(btgVertex,blue       ), btgDataOffset, 4 );
            btgDataOffset += 4;

            memcpy( (ubyte*)btgVerts+( i * sizeof(btgVertex)) +offsetof(btgVertex,alpha      ), btgDataOffset, 4 );
            btgDataOffset += 4;

            memcpy( (ubyte*)btgVerts+( i * sizeof(btgVertex)) +offsetof(btgVertex,brightness ), btgDataOffset, 4 );
            btgDataOffset += 4;
        }

//        memcpy(btgVerts, btgData + headSize, vertSize);  //Replaced by above.

#if FIX_ENDIAN
        for( i=0; i<btgHead->numVerts; i++ )
        {
            btgVerts[i].flags = FIX_ENDIAN_INT_32( btgVerts[i].flags );
            
            swap  = ( Uint64 *)&btgVerts[i].x;
            *swap = SDL_SwapLE64( *swap );
            
            swap  = ( Uint64 *)&btgVerts[i].y;
            *swap = SDL_SwapLE64( *swap );
            
            btgVerts[i].red        = FIX_ENDIAN_INT_32( btgVerts[i].red );
            btgVerts[i].green      = FIX_ENDIAN_INT_32( btgVerts[i].green );
            btgVerts[i].blue       = FIX_ENDIAN_INT_32( btgVerts[i].blue );
            btgVerts[i].alpha      = FIX_ENDIAN_INT_32( btgVerts[i].alpha );
            btgVerts[i].brightness = FIX_ENDIAN_INT_32( btgVerts[i].brightness );
        }
#endif
    }

#if BTG_VERBOSE_LEVEL >= 2
 dbgMessagef("numStars= %d", btgHead->numStars);
#endif

    //stars.  non-trivial munging around
    starSize = btgHead->numStars * sizeof(btgStar);
    fileStarSize = 0;
    if (starSize != 0)
    {
        btgStar* outstarp;
        btgStar* inp;
        udword*  udp;
        sdword   j, tempSize, count, length;
        char     filename[48];

        btgStars = (btgStar*)memAlloc(starSize, "btg stars", 0);
        instarp  = btgDataOffset;
#if BTG_VERBOSE_LEVEL >= 3
 dbgMessagef("instarp= %x",instarp);
 dbgMessagef("Offset= %x",instarp - btgData);
#endif
        outstarp = btgStars;
        inp = ( btgStar *)instarp;

        for (i = 0; i < btgHead->numStars; i++, outstarp++)
        {
            //extract constant-sized header
//            tempSize = sizeof(udword) + 2*sizeof(real64) + 4*sizeof(sdword);
            tempSize = 4 + 2*8 + 4*4;
            memcpy( (ubyte*)outstarp+offsetof(btgStar,flags), instarp, 4);
            instarp += 4;

            memcpy( (ubyte*)outstarp+offsetof(btgStar,x),     instarp, 8);
            instarp += 8;

            memcpy( (ubyte*)outstarp+offsetof(btgStar,y),     instarp, 8);
            instarp += 8;

            memcpy( (ubyte*)outstarp+offsetof(btgStar,red),   instarp, 4);
            instarp += 4;

            memcpy( (ubyte*)outstarp+offsetof(btgStar,green), instarp, 4);
            instarp += 4;

            memcpy( (ubyte*)outstarp+offsetof(btgStar,blue),  instarp, 4);
            instarp += 4;

            memcpy( (ubyte*)outstarp+offsetof(btgStar,alpha), instarp, 4);
            instarp += 4;

//            memcpy(outstarp, instarp, tempSize); //Replaced by Above.
#if BTG_VERBOSE_LEVEL >= 3
 dbgMessagef("tempSize= %x", tempSize);
 dbgMessagef("instarp= %x", instarp);
#endif
            fileStarSize += tempSize;

#if FIX_ENDIAN
            swap = ( Uint64 *)&outstarp->x;
            *swap = SDL_SwapLE64( *swap );
            swap = ( Uint64 *)&outstarp->y;
            *swap = SDL_SwapLE64( *swap );
            outstarp->flags = FIX_ENDIAN_INT_32( outstarp->flags );
            outstarp->red   = FIX_ENDIAN_INT_32( outstarp->red );
            outstarp->green = FIX_ENDIAN_INT_32( outstarp->green );
            outstarp->blue  = FIX_ENDIAN_INT_32( outstarp->blue );
            outstarp->alpha = FIX_ENDIAN_INT_32( outstarp->alpha );
#endif

            //extract variable-sized filename
            count = 0;
            memset(filename, 0, 48);
            udp = (udword*)instarp;

#if FIX_ENDIAN
            length = FIX_ENDIAN_INT_32( (sdword)*udp );
#else
            length = (sdword)*udp;
#endif

#if BTG_VERBOSE_LEVEL >=4
 dbgMessagef("instarp= %x", instarp);
 dbgMessagef("udp= %x", udp);
 dbgMessagef("length= %d", length);
 dbgMessagef("filename= %s", filename);
#endif

            instarp += 4;
            fileStarSize += 4;
            for (j = 0; j < length; j++)
            {
                filename[count++] = *instarp++;
                fileStarSize++;
            }
            memcpy(outstarp->filename, filename, 48);

            //create a GL texture object
            if (!btgTexInList(filename))
            {
                btgGetTexture(filename, &outstarp->glhandle, &outstarp->width, &outstarp->height);
                btgAddTexToList(filename, outstarp->glhandle, outstarp->width, outstarp->height);
            }
            else
            {
                btgFindTexture(filename, outstarp);
            }
        }
    }

    //reset the game's current texture, which now differs from the GL's
    trClearCurrent();

    btgPolygon* polyOut;

    //polys.  trivial copy
    polySize = btgHead->numPolys * sizeof(btgPolygon);
    if (polySize != 0)
    {
        btgPolys = (btgPolygon*)memAlloc(polySize, "btg polys", 0);

        polyOut= btgPolys;
// HERE FIX IT HERE
//        memcpy(btgPolys, btgData + headSize + vertSize + fileStarSize, polySize);

	for( i=0; i<btgHead->numPolys; i++, polyOut++ )
	{
            memcpy((ubyte*)polyOut+offsetof(btgPolygon,flags), instarp, 4);
            instarp += 4;

            memcpy((ubyte*)polyOut+offsetof(btgPolygon,v0), instarp, 4);
            instarp += 4;

            memcpy((ubyte*)polyOut+offsetof(btgPolygon,v1), instarp, 4);
            instarp += 4;

            memcpy((ubyte*)polyOut+offsetof(btgPolygon,v2), instarp, 4);
            instarp += 4;

	}
		
#if FIX_ENDIAN
		for( i=0; i<btgHead->numPolys; i++ )
		{
			btgPolys[i].flags = FIX_ENDIAN_INT_32( btgPolys[i].flags );
			btgPolys[i].v0    = FIX_ENDIAN_INT_32( btgPolys[i].v0 );
			btgPolys[i].v1    = FIX_ENDIAN_INT_32( btgPolys[i].v1 );
			btgPolys[i].v2    = FIX_ENDIAN_INT_32( btgPolys[i].v2 );
		}
#endif
    }

    memFree(btgData);

    btgIndices = (uword*)memAlloc(3 * btgHead->numPolys * sizeof(uword), "btg indices", NonVolatile);
    if (useVBO) glGenBuffers(1, &vboIndices);

#ifndef _WIN32_FIXME
    //spherically project things, blend colours, &c
    btgConvertVerts();
#endif
}
Example #7
0
/*-----------------------------------------------------------------------------
    Name        : lightParseHSF
    Description : parse a homeworld scene file for lighting info
    Inputs      : fileName - the name of the .hsf file, no extension or directory
    Outputs     : alters global variables
    Return      :
----------------------------------------------------------------------------*/
void lightParseHSF(char* fileName)
{
    udword numLights = 1;
    static char lastFileName[128];

    if (fileName == NULL)
    {
        fileName = lastFileName;
    }
    else
    {
        memStrncpy(lastFileName, fileName, 127);
    }

    lightDefaultLightSet();

    if (fileExists(fileName, 0))
    {
        HSFFileHeader*  hsfHeader;
        HSFLight*       hsfLight;
        ubyte* buf;
        real32 ambient[4] = {0.2f, 0.2f, 0.2f, 1.0f};
        sdword pos = sizeof(HSFFileHeader);
        sdword fileSize = fileSizeGet(fileName, 0);

        buf = memAlloc(fileSize, "lightParseHSF", 0);
        fileLoad(fileName, buf, 0);

        hsfHeader = (HSFFileHeader*)buf;

#if FIX_ENDIAN
		hsfHeader->version = FIX_ENDIAN_INT_32( hsfHeader->version );
		hsfHeader->nLights = FIX_ENDIAN_INT_32( hsfHeader->nLights );
#endif

        numLights = 0;
        while (pos <= (sdword)(fileSize - sizeof(HSFLight)))
        {
            lightinfo* linfo;

            hsfLight = (HSFLight*)(buf + pos);

#if FIX_ENDIAN
			hsfLight->type      = FIX_ENDIAN_INT_32( hsfLight->type );
			hsfLight->x         = FIX_ENDIAN_FLOAT_32( hsfLight->x );
			hsfLight->y         = FIX_ENDIAN_FLOAT_32( hsfLight->y );
			hsfLight->z         = FIX_ENDIAN_FLOAT_32( hsfLight->z );
			hsfLight->h         = FIX_ENDIAN_FLOAT_32( hsfLight->h );
			hsfLight->p         = FIX_ENDIAN_FLOAT_32( hsfLight->p );
			hsfLight->b         = FIX_ENDIAN_FLOAT_32( hsfLight->b );
			hsfLight->coneAngle = FIX_ENDIAN_FLOAT_32( hsfLight->coneAngle );
			hsfLight->edgeAngle = FIX_ENDIAN_FLOAT_32( hsfLight->edgeAngle );
			hsfLight->intensity = FIX_ENDIAN_FLOAT_32( hsfLight->intensity );
#endif

            if (hsfLight->type != L_AmbientLight)
            {
                numLights++;
                linfo = (numLights == 2) ? &currentLight1 : currentLight;

                //"L_DistantLight"
                _inplace_glify((GLfloat*)&hsfLight->x);
                linfo->position[0] = hsfLight->x;
                linfo->position[1] = hsfLight->y;
                linfo->position[2] = hsfLight->z;
                linfo->position[3] = 0.0f;

/*                if (hsfLight->intensity > 1.0f)
                {
                    hsfLight->intensity = 1.0f;
                }*/

                linfo->ambient[0] = 0.3f * hsfLight->intensity * (real32)hsfLight->red / 255.0f;
                linfo->ambient[1] = 0.3f * hsfLight->intensity * (real32)hsfLight->green / 255.0f;
                linfo->ambient[2] = 0.3f * hsfLight->intensity * (real32)hsfLight->blue / 255.0f;
                linfo->ambient[3] = 1.0f;

                linfo->diffuse[0] = hsfLight->intensity * (real32)hsfLight->red / 255.0f;
                linfo->diffuse[1] = hsfLight->intensity * (real32)hsfLight->green / 255.0f;
                linfo->diffuse[2] = hsfLight->intensity * (real32)hsfLight->blue / 255.0f;
                linfo->diffuse[3] = 1.0f;

                linfo->specular[0] = 1.0f;
                linfo->specular[1] = 1.0f;
                linfo->specular[2] = 1.0f;
                linfo->specular[3] = 1.0f;
            }
            else
            {
                sdword i;

                //L_AmbientLight
                ambient[0] = hsfLight->intensity * (real32)hsfLight->red / 255.0f;
                ambient[1] = hsfLight->intensity * (real32)hsfLight->green / 255.0f;
                ambient[2] = hsfLight->intensity * (real32)hsfLight->blue / 255.0f;
                ambient[3] = 1.0f;

                for (i = 0; i < 4; i++)
                {
                    real32 lv = 2.0f * ambient[i];
                    if (lv > 1.0f) lv = 1.0f;
                    lightAmbient[i] = lv;
                }
            }

            pos += sizeof(HSFLight);
        }

        memFree(buf);
        strcpy(lightCurrentLighting, fileName);
    }
//    else
//    {
//        lightDefaultLightSet();
//    }

    lightSetNumLights(numLights);
}