Ignore:
Timestamp:
2010-05-28 07:39:52 (2 years ago)
Author:
kpoole
Message:

Episode 5

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Classes/UnitTextureAtlas.cpp

    r24 r26  
    4040unsigned int gUnitTexH[NUM_UNITMAPS]; 
    4141 
    42 #define MAX_UNIT_ATLAS_TOTAL_SIZE   3*1024*1024 
     42#define MAX_UNIT_ATLAS_TOTAL_SIZE   4*1024*1024 
    4343 
    4444typedef struct 
     
    142142            filename += "map.drakes.flare.png"; 
    143143            break; 
    144         case UNITMAP_DRAKES_GLADIATOR: 
    145             filename += "map.drakes.gladiator.png"; 
     144        case UNITMAP_DRAKES_THRASHER: 
     145            filename += "map.drakes.thrasher.png"; 
    146146            break; 
    147147        case UNITMAP_DRAKES_GLIDER: 
     
    157157            filename += "map.drakes.sky.png"; 
    158158            break; 
    159         case UNITMAP_DRAKES_SLASHER: 
    160             filename += "map.drakes.slasher.png"; 
     159        case UNITMAP_DRAKES_ARBITER: 
     160            filename += "map.drakes.arbiter.png"; 
    161161            break; 
    162162        case UNITMAP_DRAKES_WARDEN: 
     
    14671467             
    14681468             
    1469              
     1469         
     1470        case UNITMAP_OOZE_GIANT_MUDCRAWLER: 
     1471            filename += "map.ooze.giant-mudcrawler.png"; 
     1472            break; 
     1473        case UNITMAP_OOZE_HUMAN_QUEEN: 
     1474            filename += "map.ooze.human-queen.png"; 
     1475            break; 
     1476        case UNITMAP_OOZE_MUDCRAWLER: 
     1477            filename += "map.ooze.mudcrawler.png"; 
     1478            break; 
     1479        case UNITMAP_OOZE_OLDELVISH_ENCHANTRESS: 
     1480            filename += "map.ooze.oldelvish-enchantress.png"; 
     1481            break; 
     1482        case UNITMAP_OOZE_OLDELVISH_SHAMAN: 
     1483            filename += "map.ooze.oldelvish-shaman.png"; 
     1484            break; 
     1485        case UNITMAP_OOZE_OLDELVISH_SORCERESS: 
     1486            filename += "map.ooze.oldelvish-sorceress.png"; 
     1487            break; 
     1488        case UNITMAP_OOZE_OLDELVISH_SYLPH: 
     1489            filename += "map.ooze.oldelvish-sylph.png"; 
     1490            break; 
     1491        case UNITMAP_OOZE_QUINTAIN: 
     1492            filename += "map.ooze.quintain.png"; 
     1493            break; 
     1494             
     1495             
     1496        case UNITMAP_SX_SAND_SCORPION: 
     1497            filename += "map.sx.sand-scorpion.png"; 
     1498            break; 
     1499             
     1500        case UNITMAP_TDH: 
     1501            filename += "map.tdh.png"; 
     1502            break; 
    14701503             
    14711504             
     
    14781511     
    14791512    glGenTextures(1, &gUnitTexIds[mapId+color]);     
    1480     glBindTexture(GL_TEXTURE_2D, gUnitTexIds[mapId+color]); 
     1513    //glBindTexture(GL_TEXTURE_2D, gUnitTexIds[mapId+color]); 
     1514    cacheBindTexture(GL_TEXTURE_2D, gUnitTexIds[mapId+color], true); 
    14811515    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 
    14821516    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
     
    15681602        gUnitAtlasLRU.push_back(uad); 
    15691603         
    1570         while(gUnitAtlasTotalSize >= MAX_UNIT_ATLAS_TOTAL_SIZE && gUnitAtlasLRU.size() > 0) 
    1571         { 
    1572             uad = gUnitAtlasLRU.front(); 
    1573             gUnitAtlasLRU.pop_front(); 
    1574             glDeleteTextures(1, &gUnitTexIds[uad.mapId]); 
    1575             gUnitTexIds[uad.mapId] = 0; 
    1576             gUnitAtlasTotalSize -= uad.size; 
    1577             std::cerr << "UnitTextureAtlas: FREED atlas ID " << uad.mapId << " size " << uad.size << " bytes, total now " << gUnitAtlasTotalSize << " bytes\n"; 
    1578         }            
    15791604         
    15801605        // note: the sdl surface is destroyed at the end of this context 
     
    15941619        fclose(fp); 
    15951620        glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, pvrtcSize, pvrtcSize, 0, dataSize, data); 
     1621         
     1622#ifndef NDEBUG       
    15961623        GLenum err = glGetError(); 
    15971624        if (err != GL_NO_ERROR) 
     
    16011628            std::cerr << buffer; 
    16021629        } 
     1630#endif 
    16031631         
    16041632        free(data); 
     
    16151643        std::cerr << "UnitTextureAtlas: creating PVRTC atlas ID " << mapId+color << " " << pvrtcSize << "x" << pvrtcSize << ", " << uad.size << " bytes, total " << gUnitAtlasTotalSize << " bytes\n"; 
    16161644        gUnitAtlasLRU.push_back(uad); 
    1617          
    1618         while(gUnitAtlasTotalSize >= MAX_UNIT_ATLAS_TOTAL_SIZE && gUnitAtlasLRU.size() > 0) 
    1619         { 
    1620             uad = gUnitAtlasLRU.front(); 
    1621             gUnitAtlasLRU.pop_front(); 
    1622             glDeleteTextures(1, &gUnitTexIds[uad.mapId]); 
    1623             gUnitTexIds[uad.mapId] = 0; 
    1624             gUnitAtlasTotalSize -= uad.size; 
    1625             std::cerr << "UnitTextureAtlas: FREED atlas ID " << uad.mapId << " size " << uad.size << " bytes, total now " << gUnitAtlasTotalSize << " bytes\n"; 
    1626         }            
     1645             
    16271646         
    16281647    } 
     
    16411660    #include "map.drakes.fighter.h" 
    16421661    #include "map.drakes.fire.h" 
    1643     #include "map.drakes.flameheart.h" 
    1644     #include "map.drakes.flare.h" 
    1645     #include "map.drakes.gladiator.h" 
     1662    //#include "map.drakes.flameheart.h" 
     1663    //#include "map.drakes.flare.h" 
     1664    #include "map.drakes.thrasher.h" 
    16461665    #include "map.drakes.glider.h" 
    16471666    #include "map.drakes.hurricane.h" 
    16481667    #include "map.drakes.inferno.h" 
    16491668    #include "map.drakes.sky.h" 
    1650     #include "map.drakes.slasher.h" 
     1669    #include "map.drakes.arbiter.h" 
    16511670    #include "map.drakes.warden.h" 
    16521671    #include "map.drakes.warrior.h" 
     
    20692088     
    20702089    // HALOS 
    2071     #include "map.elven.druid-healing.h" 
    2072     #include "map.elven.elven-shield.h" 
    2073     #include "map.elven.faerie-fire.h" 
    2074     #include "map.elven.ice-halo.h" 
    2075     #include "map.elven.nature-halo.h" 
    2076     #include "map.elven.shaman-heal.h" 
    2077     #include "map.elven.shyde.h" 
    2078     #include "map.fire-aura.h" 
    2079     #include "map.flame-burst.h" 
    2080     #include "map.holy.halo.h" 
    2081     #include "map.holy.lightbeam.h" 
    2082     #include "map.iftu.avatar.h" 
    2083     #include "map.iftu.bomb-explode.h" 
    2084     #include "map.iftu.chaos.h" 
    2085     #include "map.iftu.darkness-beam.h" 
    2086     #include "map.iftu.elynia-noillum.h" 
    2087     #include "map.iftu.elynia.h" 
    2088     #include "map.iftu.illuminates.h" 
    2089     #include "map.iftu.obscures.h" 
    2090     #include "map.iftu.wose-ranged.h" 
    2091     #include "map.iftu.wose.h" 
    2092     #include "map.illuminates-aura.h" 
    2093     #include "map.liberty.shadow-mage.h" 
    2094     #include "map.lighthouse-aura.h" 
    2095     #include "map.lightning-bolt.h" 
    2096     #include "map.mage-halo-big.h" 
    2097     #include "map.mage-halo.h" 
    2098     #include "map.mage-preparation.h" 
    2099     #include "map.merfolk.staff-flare.h" 
    2100     #include "map.merfolk.water.h" 
    2101     #include "map.saurian-magic-halo.h" 
    2102     #include "map.teleport.h" 
    2103     #include "map.thot.karrag.h" 
    2104     #include "map.undead.h" 
     2090    #include "halomap.elven.druid-healing.h" 
     2091    #include "halomap.elven.elven-shield.h" 
     2092    #include "halomap.elven.faerie-fire.h" 
     2093    #include "halomap.elven.ice-halo.h" 
     2094    #include "halomap.elven.nature-halo.h" 
     2095    #include "halomap.elven.shaman-heal.h" 
     2096    #include "halomap.elven.shyde.h" 
     2097    #include "halomap.fire-aura.h" 
     2098    #include "halomap.flame-burst.h" 
     2099    #include "halomap.holy.halo.h" 
     2100    #include "halomap.holy.lightbeam.h" 
     2101    #include "halomap.iftu.avatar.h" 
     2102    #include "halomap.iftu.bomb-explode.h" 
     2103    #include "halomap.iftu.chaos.h" 
     2104    #include "halomap.iftu.darkness-beam.h" 
     2105    #include "halomap.iftu.elynia-noillum.h" 
     2106    #include "halomap.iftu.elynia.h" 
     2107    #include "halomap.iftu.illuminates.h" 
     2108    #include "halomap.iftu.obscures.h" 
     2109    #include "halomap.iftu.wose-ranged.h" 
     2110    #include "halomap.iftu.wose.h" 
     2111    #include "halomap.illuminates-aura.h" 
     2112    #include "halomap.liberty.shadow-mage.h" 
     2113    #include "halomap.lighthouse-aura.h" 
     2114    #include "halomap.lightning-bolt.h" 
     2115    #include "halomap.mage-halo-big.h" 
     2116    #include "halomap.mage-halo.h" 
     2117    #include "halomap.mage-preparation.h" 
     2118    #include "halomap.merfolk.staff-flare.h" 
     2119    #include "halomap.merfolk.water.h" 
     2120    #include "halomap.saurian-magic-halo.h" 
     2121    #include "halomap.teleport.h" 
     2122    #include "halomap.thot.karrag.h" 
     2123    #include "halomap.undead.h" 
    21052124         
    2106      
     2125    #include "map.ooze.giant-mudcrawler.h" 
     2126    #include "map.ooze.human-queen.h" 
     2127    #include "map.ooze.mudcrawler.h" 
     2128    #include "map.ooze.oldelvish-enchantress.h" 
     2129    #include "map.ooze.oldelvish-shaman.h" 
     2130    #include "map.ooze.oldelvish-sorceress.h" 
     2131    #include "map.ooze.oldelvish-sylph.h" 
     2132    #include "map.ooze.quintain.h" 
     2133     
     2134    #include "map.sx.sand-scorpion.h" 
     2135     
     2136    #include "map.tdh.h" 
    21072137} 
    21082138 
     
    21222152} 
    21232153 
     2154void checkUnitTextureAtlas(void) 
     2155{ 
     2156    while(gUnitAtlasTotalSize >= MAX_UNIT_ATLAS_TOTAL_SIZE && gUnitAtlasLRU.size() > 0) 
     2157    { 
     2158        unitAtlasData uad; 
     2159        uad = gUnitAtlasLRU.front(); 
     2160        gUnitAtlasLRU.pop_front(); 
     2161        glDeleteTextures(1, &gUnitTexIds[uad.mapId]); 
     2162        gUnitTexIds[uad.mapId] = 0; 
     2163        gUnitAtlasTotalSize -= uad.size; 
     2164        std::cerr << "UnitTextureAtlas: FREED atlas ID " << uad.mapId << " size " << uad.size << " bytes, total now " << gUnitAtlasTotalSize << " bytes\n"; 
     2165    }            
     2166     
     2167} 
     2168 
    21242169bool getUnitTextureAtlasInfo(const std::string& filename, const std::string& modifications, textureAtlasInfo& tinfo) 
    21252170{ 
    21262171    std::string searchStr; 
     2172    std::string modStr = modifications; 
    21272173    if (filename.compare(0, 5, "halo/") == 0) 
    21282174    { 
     
    21412187        // normal unit images 
    21422188        searchStr = filename; 
    2143     } 
     2189        // check for imbedded ~ character, added for Ooze Mini-Campaign 
     2190        int pos = searchStr.find('~', 0); 
     2191        if (pos != std::string::npos) 
     2192        { 
     2193            modStr = searchStr.substr(pos, searchStr.size() - pos); 
     2194            searchStr = searchStr.substr(0, pos); 
     2195        } 
     2196    }    
    21442197     
    21452198    std::map<shared_string, textureAtlasInfo>::iterator it; 
     
    21612214    tinfo = it->second; 
    21622215 
    2163     int rcPos = modifications.find("~RC(magenta>"); 
     2216    int rcPos = modStr.find("~RC(magenta>"); 
    21642217    if (rcPos != std::string::npos) 
    21652218    { 
     
    21672220        rcPos += 12; 
    21682221        int colorInt = 0; 
    2169         if (modifications.size() > rcPos+2) 
     2222        if (modStr.size() > rcPos+2) 
    21702223        { 
    21712224            // also convert color words 
    2172             if (modifications[rcPos] == 'r') 
     2225            if (modStr[rcPos] == 'r') 
    21732226                colorInt = 1;   // red 
    2174             else if (modifications[rcPos] == 'b' && modifications[rcPos+2] == 'u') 
     2227            else if (modStr[rcPos] == 'b' && modStr[rcPos+2] == 'u') 
    21752228                colorInt = 2;   // blue 
    2176             else if (modifications[rcPos] == 'g') 
     2229            else if (modStr[rcPos] == 'g') 
    21772230                colorInt = 3;   // green 
    2178             else if (modifications[rcPos] == 'p') 
     2231            else if (modStr[rcPos] == 'p') 
    21792232                colorInt = 4;   // purple 
    2180             else if (modifications[rcPos] == 'b' && modifications[rcPos+2] == 'a') 
     2233            else if (modStr[rcPos] == 'b' && modStr[rcPos+2] == 'a') 
    21812234                colorInt = 5;   // black 
    2182             else if (modifications[rcPos] == 'b' && modifications[rcPos+2] == 'o') 
     2235            else if (modStr[rcPos] == 'b' && modStr[rcPos+2] == 'o') 
    21832236                colorInt = 6;   // brown 
    2184             else if (modifications[rcPos] == 'o') 
     2237            else if (modStr[rcPos] == 'o') 
    21852238                colorInt = 7;   // orange 
    2186             else if (modifications[rcPos] == 'w') 
     2239            else if (modStr[rcPos] == 'w') 
    21872240                colorInt = 8;   // white 
    2188             else if (modifications[rcPos] == 't') 
     2241            else if (modStr[rcPos] == 't') 
    21892242                colorInt = 9;   // teal 
    21902243             
     
    21922245        else 
    21932246        { 
    2194             char colorChar = modifications[rcPos]; 
     2247            char colorChar = modStr[rcPos]; 
    21952248            colorInt = colorChar - '0'; 
    21962249        } 
     
    22002253    } 
    22012254    // new special case for ellipse graphics 
    2202     rcPos = modifications.find("~RC(ellipse_red>"); 
     2255    rcPos = modStr.find("~RC(ellipse_red>"); 
    22032256    if (rcPos != std::string::npos) 
    22042257    { 
     
    22062259        rcPos += 16; 
    22072260        int colorInt = 0; 
    2208         if (modifications.size() > rcPos+2) 
     2261        if (modStr.size() > rcPos+2) 
    22092262        { 
    22102263            // also convert color words 
    2211             if (modifications[rcPos] == 'r') 
     2264            if (modStr[rcPos] == 'r') 
    22122265                colorInt = 1;   // red 
    2213             else if (modifications[rcPos] == 'b' && modifications[rcPos+2] == 'u') 
     2266            else if (modStr[rcPos] == 'b' && modStr[rcPos+2] == 'u') 
    22142267                colorInt = 2;   // blue 
    2215             else if (modifications[rcPos] == 'g') 
     2268            else if (modStr[rcPos] == 'g') 
    22162269                colorInt = 3;   // green 
    2217             else if (modifications[rcPos] == 'p') 
     2270            else if (modStr[rcPos] == 'p') 
    22182271                colorInt = 4;   // purple 
    2219             else if (modifications[rcPos] == 'b' && modifications[rcPos+2] == 'a') 
     2272            else if (modStr[rcPos] == 'b' && modStr[rcPos+2] == 'a') 
    22202273                colorInt = 5;   // black 
    2221             else if (modifications[rcPos] == 'b' && modifications[rcPos+2] == 'o') 
     2274            else if (modStr[rcPos] == 'b' && modStr[rcPos+2] == 'o') 
    22222275                colorInt = 6;   // brown 
    2223             else if (modifications[rcPos] == 'o') 
     2276            else if (modStr[rcPos] == 'o') 
    22242277                colorInt = 7;   // orange 
    2225             else if (modifications[rcPos] == 'w') 
     2278            else if (modStr[rcPos] == 'w') 
    22262279                colorInt = 8;   // white 
    2227             else if (modifications[rcPos] == 't') 
     2280            else if (modStr[rcPos] == 't') 
    22282281                colorInt = 9;   // teal 
    22292282             
     
    22312284        else 
    22322285        { 
    2233                 char colorChar = modifications[rcPos]; 
     2286                char colorChar = modStr[rcPos]; 
    22342287                colorInt = colorChar - '0'; 
    22352288        } 
     
    22392292    } 
    22402293    // new case for flags 
    2241     rcPos = modifications.find("~RC(flag_green>"); 
     2294    rcPos = modStr.find("~RC(flag_green>"); 
    22422295    if (rcPos != std::string::npos) 
    22432296    { 
     
    22452298        rcPos += 15; 
    22462299        int colorInt = 0; 
    2247         if (modifications.size() > rcPos+2) 
     2300        if (modStr.size() > rcPos+2) 
    22482301        { 
    22492302            // also convert color words 
    2250             if (modifications[rcPos] == 'r') 
     2303            if (modStr[rcPos] == 'r') 
    22512304                colorInt = 1;   // red 
    2252             else if (modifications[rcPos] == 'b' && modifications[rcPos+2] == 'u') 
     2305            else if (modStr[rcPos] == 'b' && modStr[rcPos+2] == 'u') 
    22532306                colorInt = 2;   // blue 
    2254             else if (modifications[rcPos] == 'g') 
     2307            else if (modStr[rcPos] == 'g') 
    22552308                colorInt = 3;   // green 
    2256             else if (modifications[rcPos] == 'p') 
     2309            else if (modStr[rcPos] == 'p') 
    22572310                colorInt = 4;   // purple 
    2258             else if (modifications[rcPos] == 'b' && modifications[rcPos+2] == 'a') 
     2311            else if (modStr[rcPos] == 'b' && modStr[rcPos+2] == 'a') 
    22592312                colorInt = 5;   // black 
    2260             else if (modifications[rcPos] == 'b' && modifications[rcPos+2] == 'o') 
     2313            else if (modStr[rcPos] == 'b' && modStr[rcPos+2] == 'o') 
    22612314                colorInt = 6;   // brown 
    2262             else if (modifications[rcPos] == 'o') 
     2315            else if (modStr[rcPos] == 'o') 
    22632316                colorInt = 7;   // orange 
    2264             else if (modifications[rcPos] == 'w') 
     2317            else if (modStr[rcPos] == 'w') 
    22652318                colorInt = 8;   // white 
    2266             else if (modifications[rcPos] == 't') 
     2319            else if (modStr[rcPos] == 't') 
    22672320                colorInt = 9;   // teal 
    22682321             
     
    22702323        else 
    22712324        { 
    2272             char colorChar = modifications[rcPos]; 
     2325            char colorChar = modStr[rcPos]; 
    22732326            colorInt = colorChar - '0'; 
    22742327        } 
     
    24252478    maxv = (GLfloat) (clippedSrc.y + clippedSrc.h) / gUnitTexH[tinfo.mapId]; 
    24262479     
    2427     GLshort vertices[8]; 
     2480    GLshort vertices[12]; 
    24282481    GLfloat texCoords[8]; 
    24292482     
    24302483    vertices[0] = minx; 
    24312484    vertices[1] = miny; 
    2432     vertices[2] = maxx; 
    2433     vertices[3] = miny; 
    2434     vertices[4] = minx; 
    2435     vertices[5] = maxy; 
    2436     vertices[6] = maxx; 
     2485    vertices[2] = 0; 
     2486    vertices[3] = maxx; 
     2487    vertices[4] = miny; 
     2488    vertices[5] = 0; 
     2489    vertices[6] = minx; 
    24372490    vertices[7] = maxy; 
     2491    vertices[8] = 0; 
     2492    vertices[9] = maxx; 
     2493    vertices[10] = maxy; 
     2494    vertices[11] = 0; 
    24382495    /*   
    24392496     B---C       ->      A B 
Note: See TracChangeset for help on using the changeset viewer.