Changeset 26 for trunk/Classes/UnitTextureAtlas.cpp
- Timestamp:
- 2010-05-28 07:39:52 (2 years ago)
- File:
-
- 1 edited
-
trunk/Classes/UnitTextureAtlas.cpp (modified) (23 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Classes/UnitTextureAtlas.cpp
r24 r26 40 40 unsigned int gUnitTexH[NUM_UNITMAPS]; 41 41 42 #define MAX_UNIT_ATLAS_TOTAL_SIZE 3*1024*102442 #define MAX_UNIT_ATLAS_TOTAL_SIZE 4*1024*1024 43 43 44 44 typedef struct … … 142 142 filename += "map.drakes.flare.png"; 143 143 break; 144 case UNITMAP_DRAKES_ GLADIATOR:145 filename += "map.drakes. gladiator.png";144 case UNITMAP_DRAKES_THRASHER: 145 filename += "map.drakes.thrasher.png"; 146 146 break; 147 147 case UNITMAP_DRAKES_GLIDER: … … 157 157 filename += "map.drakes.sky.png"; 158 158 break; 159 case UNITMAP_DRAKES_ SLASHER:160 filename += "map.drakes. slasher.png";159 case UNITMAP_DRAKES_ARBITER: 160 filename += "map.drakes.arbiter.png"; 161 161 break; 162 162 case UNITMAP_DRAKES_WARDEN: … … 1467 1467 1468 1468 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; 1470 1503 1471 1504 … … 1478 1511 1479 1512 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); 1481 1515 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 1482 1516 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); … … 1568 1602 gUnitAtlasLRU.push_back(uad); 1569 1603 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 }1579 1604 1580 1605 // note: the sdl surface is destroyed at the end of this context … … 1594 1619 fclose(fp); 1595 1620 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, pvrtcSize, pvrtcSize, 0, dataSize, data); 1621 1622 #ifndef NDEBUG 1596 1623 GLenum err = glGetError(); 1597 1624 if (err != GL_NO_ERROR) … … 1601 1628 std::cerr << buffer; 1602 1629 } 1630 #endif 1603 1631 1604 1632 free(data); … … 1615 1643 std::cerr << "UnitTextureAtlas: creating PVRTC atlas ID " << mapId+color << " " << pvrtcSize << "x" << pvrtcSize << ", " << uad.size << " bytes, total " << gUnitAtlasTotalSize << " bytes\n"; 1616 1644 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 1627 1646 1628 1647 } … … 1641 1660 #include "map.drakes.fighter.h" 1642 1661 #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" 1646 1665 #include "map.drakes.glider.h" 1647 1666 #include "map.drakes.hurricane.h" 1648 1667 #include "map.drakes.inferno.h" 1649 1668 #include "map.drakes.sky.h" 1650 #include "map.drakes. slasher.h"1669 #include "map.drakes.arbiter.h" 1651 1670 #include "map.drakes.warden.h" 1652 1671 #include "map.drakes.warrior.h" … … 2069 2088 2070 2089 // 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" 2105 2124 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" 2107 2137 } 2108 2138 … … 2122 2152 } 2123 2153 2154 void 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 2124 2169 bool getUnitTextureAtlasInfo(const std::string& filename, const std::string& modifications, textureAtlasInfo& tinfo) 2125 2170 { 2126 2171 std::string searchStr; 2172 std::string modStr = modifications; 2127 2173 if (filename.compare(0, 5, "halo/") == 0) 2128 2174 { … … 2141 2187 // normal unit images 2142 2188 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 } 2144 2197 2145 2198 std::map<shared_string, textureAtlasInfo>::iterator it; … … 2161 2214 tinfo = it->second; 2162 2215 2163 int rcPos = mod ifications.find("~RC(magenta>");2216 int rcPos = modStr.find("~RC(magenta>"); 2164 2217 if (rcPos != std::string::npos) 2165 2218 { … … 2167 2220 rcPos += 12; 2168 2221 int colorInt = 0; 2169 if (mod ifications.size() > rcPos+2)2222 if (modStr.size() > rcPos+2) 2170 2223 { 2171 2224 // also convert color words 2172 if (mod ifications[rcPos] == 'r')2225 if (modStr[rcPos] == 'r') 2173 2226 colorInt = 1; // red 2174 else if (mod ifications[rcPos] == 'b' && modifications[rcPos+2] == 'u')2227 else if (modStr[rcPos] == 'b' && modStr[rcPos+2] == 'u') 2175 2228 colorInt = 2; // blue 2176 else if (mod ifications[rcPos] == 'g')2229 else if (modStr[rcPos] == 'g') 2177 2230 colorInt = 3; // green 2178 else if (mod ifications[rcPos] == 'p')2231 else if (modStr[rcPos] == 'p') 2179 2232 colorInt = 4; // purple 2180 else if (mod ifications[rcPos] == 'b' && modifications[rcPos+2] == 'a')2233 else if (modStr[rcPos] == 'b' && modStr[rcPos+2] == 'a') 2181 2234 colorInt = 5; // black 2182 else if (mod ifications[rcPos] == 'b' && modifications[rcPos+2] == 'o')2235 else if (modStr[rcPos] == 'b' && modStr[rcPos+2] == 'o') 2183 2236 colorInt = 6; // brown 2184 else if (mod ifications[rcPos] == 'o')2237 else if (modStr[rcPos] == 'o') 2185 2238 colorInt = 7; // orange 2186 else if (mod ifications[rcPos] == 'w')2239 else if (modStr[rcPos] == 'w') 2187 2240 colorInt = 8; // white 2188 else if (mod ifications[rcPos] == 't')2241 else if (modStr[rcPos] == 't') 2189 2242 colorInt = 9; // teal 2190 2243 … … 2192 2245 else 2193 2246 { 2194 char colorChar = mod ifications[rcPos];2247 char colorChar = modStr[rcPos]; 2195 2248 colorInt = colorChar - '0'; 2196 2249 } … … 2200 2253 } 2201 2254 // new special case for ellipse graphics 2202 rcPos = mod ifications.find("~RC(ellipse_red>");2255 rcPos = modStr.find("~RC(ellipse_red>"); 2203 2256 if (rcPos != std::string::npos) 2204 2257 { … … 2206 2259 rcPos += 16; 2207 2260 int colorInt = 0; 2208 if (mod ifications.size() > rcPos+2)2261 if (modStr.size() > rcPos+2) 2209 2262 { 2210 2263 // also convert color words 2211 if (mod ifications[rcPos] == 'r')2264 if (modStr[rcPos] == 'r') 2212 2265 colorInt = 1; // red 2213 else if (mod ifications[rcPos] == 'b' && modifications[rcPos+2] == 'u')2266 else if (modStr[rcPos] == 'b' && modStr[rcPos+2] == 'u') 2214 2267 colorInt = 2; // blue 2215 else if (mod ifications[rcPos] == 'g')2268 else if (modStr[rcPos] == 'g') 2216 2269 colorInt = 3; // green 2217 else if (mod ifications[rcPos] == 'p')2270 else if (modStr[rcPos] == 'p') 2218 2271 colorInt = 4; // purple 2219 else if (mod ifications[rcPos] == 'b' && modifications[rcPos+2] == 'a')2272 else if (modStr[rcPos] == 'b' && modStr[rcPos+2] == 'a') 2220 2273 colorInt = 5; // black 2221 else if (mod ifications[rcPos] == 'b' && modifications[rcPos+2] == 'o')2274 else if (modStr[rcPos] == 'b' && modStr[rcPos+2] == 'o') 2222 2275 colorInt = 6; // brown 2223 else if (mod ifications[rcPos] == 'o')2276 else if (modStr[rcPos] == 'o') 2224 2277 colorInt = 7; // orange 2225 else if (mod ifications[rcPos] == 'w')2278 else if (modStr[rcPos] == 'w') 2226 2279 colorInt = 8; // white 2227 else if (mod ifications[rcPos] == 't')2280 else if (modStr[rcPos] == 't') 2228 2281 colorInt = 9; // teal 2229 2282 … … 2231 2284 else 2232 2285 { 2233 char colorChar = mod ifications[rcPos];2286 char colorChar = modStr[rcPos]; 2234 2287 colorInt = colorChar - '0'; 2235 2288 } … … 2239 2292 } 2240 2293 // new case for flags 2241 rcPos = mod ifications.find("~RC(flag_green>");2294 rcPos = modStr.find("~RC(flag_green>"); 2242 2295 if (rcPos != std::string::npos) 2243 2296 { … … 2245 2298 rcPos += 15; 2246 2299 int colorInt = 0; 2247 if (mod ifications.size() > rcPos+2)2300 if (modStr.size() > rcPos+2) 2248 2301 { 2249 2302 // also convert color words 2250 if (mod ifications[rcPos] == 'r')2303 if (modStr[rcPos] == 'r') 2251 2304 colorInt = 1; // red 2252 else if (mod ifications[rcPos] == 'b' && modifications[rcPos+2] == 'u')2305 else if (modStr[rcPos] == 'b' && modStr[rcPos+2] == 'u') 2253 2306 colorInt = 2; // blue 2254 else if (mod ifications[rcPos] == 'g')2307 else if (modStr[rcPos] == 'g') 2255 2308 colorInt = 3; // green 2256 else if (mod ifications[rcPos] == 'p')2309 else if (modStr[rcPos] == 'p') 2257 2310 colorInt = 4; // purple 2258 else if (mod ifications[rcPos] == 'b' && modifications[rcPos+2] == 'a')2311 else if (modStr[rcPos] == 'b' && modStr[rcPos+2] == 'a') 2259 2312 colorInt = 5; // black 2260 else if (mod ifications[rcPos] == 'b' && modifications[rcPos+2] == 'o')2313 else if (modStr[rcPos] == 'b' && modStr[rcPos+2] == 'o') 2261 2314 colorInt = 6; // brown 2262 else if (mod ifications[rcPos] == 'o')2315 else if (modStr[rcPos] == 'o') 2263 2316 colorInt = 7; // orange 2264 else if (mod ifications[rcPos] == 'w')2317 else if (modStr[rcPos] == 'w') 2265 2318 colorInt = 8; // white 2266 else if (mod ifications[rcPos] == 't')2319 else if (modStr[rcPos] == 't') 2267 2320 colorInt = 9; // teal 2268 2321 … … 2270 2323 else 2271 2324 { 2272 char colorChar = mod ifications[rcPos];2325 char colorChar = modStr[rcPos]; 2273 2326 colorInt = colorChar - '0'; 2274 2327 } … … 2425 2478 maxv = (GLfloat) (clippedSrc.y + clippedSrc.h) / gUnitTexH[tinfo.mapId]; 2426 2479 2427 GLshort vertices[ 8];2480 GLshort vertices[12]; 2428 2481 GLfloat texCoords[8]; 2429 2482 2430 2483 vertices[0] = minx; 2431 2484 vertices[1] = miny; 2432 vertices[2] = maxx;2433 vertices[3] = m iny;2434 vertices[4] = min x;2435 vertices[5] = maxy;2436 vertices[6] = m axx;2485 vertices[2] = 0; 2486 vertices[3] = maxx; 2487 vertices[4] = miny; 2488 vertices[5] = 0; 2489 vertices[6] = minx; 2437 2490 vertices[7] = maxy; 2491 vertices[8] = 0; 2492 vertices[9] = maxx; 2493 vertices[10] = maxy; 2494 vertices[11] = 0; 2438 2495 /* 2439 2496 B---C -> A B
Note: See TracChangeset
for help on using the changeset viewer.