the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 1522 lines 37 kB view raw
1#include "stdafx.h" 2#include "Textures.h" 3#include "TexturePackRepository.h" 4#include "HttpTexture.h" 5#include "MemTexture.h" 6#include "..\Minecraft.World\InputStream.h" 7#include "..\Minecraft.World\IntBuffer.h" 8#include "..\Minecraft.World\ByteBuffer.h" 9#include "TexturePack.h" 10#include "Options.h" 11#include "..\Minecraft.Client\MemTextureProcessor.h" 12#include "MobSkinMemTextureProcessor.h" 13#include "PreStitchedTextureMap.h" 14#include "StitchedTexture.h" 15#include "Texture.h" 16#include "..\Minecraft.World\net.minecraft.world.h" 17#include "..\Minecraft.World\net.minecraft.world.level.h" 18#include "..\Minecraft.World\StringHelpers.h" 19#include "ResourceLocation.h" 20#include "..\Minecraft.World\ItemEntity.h" 21#include "TextureAtlas.h" 22 23bool Textures::MIPMAP = true; 24C4JRender::eTextureFormat Textures::TEXTURE_FORMAT = C4JRender::TEXTURE_FORMAT_RxGyBzAw; 25 26int Textures::preLoadedIdx[TN_COUNT]; 27wchar_t *Textures::preLoaded[TN_COUNT] = 28{ 29 L"%blur%misc/pumpkinblur", 30// L"%blur%/misc/vignette", // Not currently used 31 L"%clamp%misc/shadow", 32// L"/achievement/bg", // Not currently used 33 L"art/kz", 34 L"environment/clouds", 35 L"environment/rain", 36 L"environment/snow", 37 L"gui/gui", 38 L"gui/icons", 39 L"item/arrows", 40 L"item/boat", 41 L"item/cart", 42 L"item/sign", 43 L"misc/mapbg", 44 L"misc/mapicons", 45 L"misc/water", 46 L"misc/footprint", 47 L"mob/saddle", 48 L"mob/sheep_fur", 49 L"mob/spider_eyes", 50 L"particles", 51 L"mob/chicken", 52 L"mob/cow", 53 L"mob/pig", 54 L"mob/sheep", 55 L"mob/squid", 56 L"mob/wolf", 57 L"mob/wolf_tame", 58 L"mob/wolf_angry", 59 L"mob/creeper", 60 L"mob/ghast", 61 L"mob/ghast_fire", 62 L"mob/zombie", 63 L"mob/pigzombie", 64 L"mob/skeleton", 65 L"mob/slime", 66 L"mob/spider", 67 L"mob/char", 68 L"mob/char1", 69 L"mob/char2", 70 L"mob/char3", 71 L"mob/char4", 72 L"mob/char5", 73 L"mob/char6", 74 L"mob/char7", 75 L"terrain/moon", 76 L"terrain/sun", 77 L"armor/power", 78 79 // 1.8.2 80 L"mob/cavespider", 81 L"mob/enderman", 82 L"mob/silverfish", 83 L"mob/enderman_eyes", 84 L"misc/explosion", 85 L"item/xporb", 86 L"item/chest", 87 L"item/largechest", 88 89 // 1.3.2 90 L"item/enderchest", 91 92 // 1.0.1 93 L"mob/redcow", 94 L"mob/snowman", 95 L"mob/enderdragon/ender", 96 L"mob/fire", 97 L"mob/lava", 98 L"mob/villager/villager", 99 L"mob/villager/farmer", 100 L"mob/villager/librarian", 101 L"mob/villager/priest", 102 L"mob/villager/smith", 103 L"mob/villager/butcher", 104 L"mob/enderdragon/crystal", 105 L"mob/enderdragon/shuffle", 106 L"mob/enderdragon/beam", 107 L"mob/enderdragon/ender_eyes", 108 L"%blur%misc/glint", 109 L"item/book", 110 L"misc/tunnel", 111 L"misc/particlefield", 112 L"terrain/moon_phases", 113 114 // 1.2.3 115 L"mob/ozelot", 116 L"mob/cat_black", 117 L"mob/cat_red", 118 L"mob/cat_siamese", 119 L"mob/villager_golem", 120 L"mob/skeleton_wither", 121 122 // TU 14 123 L"mob/wolf_collar", 124 L"mob/zombie_villager", 125 126 // 1.6.4 127 L"item/lead_knot", 128 129 L"misc/beacon_beam", 130 131 L"mob/bat", 132 133 L"mob/horse/donkey", 134 L"mob/horse/horse_black", 135 L"mob/horse/horse_brown", 136 L"mob/horse/horse_chestnut", 137 L"mob/horse/horse_creamy", 138 L"mob/horse/horse_darkbrown", 139 L"mob/horse/horse_gray", 140 L"mob/horse/horse_markings_blackdots", 141 L"mob/horse/horse_markings_white", 142 L"mob/horse/horse_markings_whitedots", 143 L"mob/horse/horse_markings_whitefield", 144 L"mob/horse/horse_skeleton", 145 L"mob/horse/horse_white", 146 L"mob/horse/horse_zombie", 147 L"mob/horse/mule", 148 149 L"mob/horse/armor/horse_armor_diamond", 150 L"mob/horse/armor/horse_armor_gold", 151 L"mob/horse/armor/horse_armor_iron", 152 153 L"mob/witch", 154 155 L"mob/wither/wither", 156 L"mob/wither/wither_armor", 157 L"mob/wither/wither_invulnerable", 158 159 L"item/trapped", 160 L"item/trapped_double", 161 //L"item/christmas", 162 //L"item/christmas_double", 163 164#ifdef _LARGE_WORLDS 165 L"misc/additionalmapicons", 166#endif 167 168 L"font/Default", 169 L"font/alternate", 170 171 // skin packs 172/* L"/SP1", 173 L"/SP2", 174 L"/SP3", 175 L"/SPF", 176 177 // themes 178 L"/ThSt", 179 L"/ThIr", 180 L"/ThGo", 181 L"/ThDi", 182 183 // gamerpics 184 L"/GPAn", 185 L"/GPCo", 186 L"/GPEn", 187 L"/GPFo", 188 L"/GPTo", 189 L"/GPBA", 190 L"/GPFa", 191 L"/GPME", 192 L"/GPMF", 193 L"/GPMM", 194 L"/GPSE", 195 196 // avatar items 197 198 L"/AH_0006", 199 L"/AH_0003", 200 L"/AH_0007", 201 L"/AH_0005", 202 L"/AH_0004", 203 L"/AH_0001", 204 L"/AH_0002", 205 L"/AT_0001", 206 L"/AT_0002", 207 L"/AT_0003", 208 L"/AT_0004", 209 L"/AT_0005", 210 L"/AT_0006", 211 L"/AT_0007", 212 L"/AT_0008", 213 L"/AT_0009", 214 L"/AT_0010", 215 L"/AT_0011", 216 L"/AT_0012", 217 L"/AP_0001", 218 L"/AP_0002", 219 L"/AP_0003", 220 L"/AP_0004", 221 L"/AP_0005", 222 L"/AP_0006", 223 L"/AP_0007", 224 L"/AP_0009", 225 L"/AP_0010", 226 L"/AP_0011", 227 L"/AP_0012", 228 L"/AP_0013", 229 L"/AP_0014", 230 L"/AP_0015", 231 L"/AP_0016", 232 L"/AP_0017", 233 L"/AP_0018", 234 L"/AA_0001", 235 L"/AT_0013", 236 L"/AT_0014", 237 L"/AT_0015", 238 L"/AT_0016", 239 L"/AT_0017", 240 L"/AT_0018", 241 L"/AP_0019", 242 L"/AP_0020", 243 L"/AP_0021", 244 L"/AP_0022", 245 L"/AP_0023", 246 L"/AH_0008", 247 L"/AH_0009",*/ 248 249 L"gui/items", 250 L"terrain", 251}; 252 253Textures::Textures(TexturePackRepository *skins, Options *options) 254{ 255// pixels = MemoryTracker::createIntBuffer(2048 * 2048); // 4J removed - now just creating this buffer when we need it 256 missingNo = new BufferedImage(16, 16, BufferedImage::TYPE_INT_ARGB); 257 258 this->skins = skins; 259 this->options = options; 260 261 /* 4J - TODO, maybe... 262 Graphics g = missingNo.getGraphics(); 263 g.setColor(Color.WHITE); 264 g.fillRect(0, 0, 64, 64); 265 g.setColor(Color.BLACK); 266 int y = 10; 267 int i = 0; 268 while (y < 64) { 269 String text = (i++ % 2 == 0) ? "missing" : "texture"; 270 g.drawString(text, 1, y); 271 y += g.getFont().getSize(); 272 if (i % 2 == 0) y += 5; 273 } 274 275 g.dispose(); 276 */ 277 278 // 4J Stu - Changed these to our PreStitchedTextureMap from TextureMap 279 terrain = new PreStitchedTextureMap(Icon::TYPE_TERRAIN, L"terrain", L"textures/blocks/", missingNo, true); 280 items = new PreStitchedTextureMap(Icon::TYPE_ITEM, L"items", L"textures/items/", missingNo, true); 281 282 // 4J - added - preload a set of commonly used textures that can then be referenced directly be an enumerated type rather by string 283 loadIndexedTextures(); 284} 285 286void Textures::loadIndexedTextures() 287{ 288 // 4J - added - preload a set of commonly used textures that can then be referenced directly be an enumerated type rather by string 289 for( int i = 0; i < TN_COUNT - 2; i++ ) 290 { 291 preLoadedIdx[i] = loadTexture((TEXTURE_NAME)i, wstring(preLoaded[i]) + L".png"); 292 } 293} 294 295intArray Textures::loadTexturePixels(TEXTURE_NAME texId, const wstring& resourceName) 296{ 297 TexturePack *skin = skins->getSelected(); 298 299 { 300 intArray id = pixelsMap[resourceName]; 301 // 4J - if resourceName isn't in the map, it should add an element and as that will use the default constructor, its 302 // internal data pointer will be NULL 303 if (id.data != NULL) return id; 304 } 305 306 // 4J - removed try/catch 307// try { 308 intArray res; 309 //wstring in = skin->getResource(resourceName); 310 if (false)// 4J - removed - was ( in == NULL) 311 { 312 res = loadTexturePixels(missingNo); 313 } 314 else 315 { 316 BufferedImage *bufImage = readImage(texId, resourceName); //in); 317 res = loadTexturePixels(bufImage); 318 delete bufImage; 319 } 320 321 pixelsMap[resourceName] = res; 322 return res; 323/* 324} 325 catch (IOException e) { 326 e.printStackTrace(); 327 int[] res = loadTexturePixels(missingNo); 328 pixelsMap.put(resourceName, res); 329 return res; 330 } 331 */ 332} 333 334intArray Textures::loadTexturePixels(BufferedImage *img) 335{ 336 int w = img->getWidth(); 337 int h = img->getHeight(); 338 intArray pixels(w*h); 339 return loadTexturePixels(img, pixels); 340} 341 342intArray Textures::loadTexturePixels(BufferedImage *img, intArray pixels) 343{ 344 int w = img->getWidth(); 345 int h = img->getHeight(); 346 img->getRGB(0, 0, w, h, pixels, 0, w); 347 return pixels; 348} 349 350int Textures::loadTexture(int idx) 351{ 352 if( idx == -1 ) 353 { 354 return 0; 355 } 356 else 357 { 358 if ( idx == TN_TERRAIN ) 359 { 360 terrain->getStitchedTexture()->bind(0); 361 return terrain->getStitchedTexture()->getGlId(); 362 } 363 if ( idx == TN_GUI_ITEMS) 364 { 365 items->getStitchedTexture()->bind(0); 366 return items->getStitchedTexture()->getGlId(); 367 } 368 return preLoadedIdx[idx]; 369 } 370} 371 372// 4J added - textures default to standard 32-bit RGBA format, but where we can, use an 8-bit format. There's 3 different varieties of these currently 373// in the renderer that map the single 8-bit channel to RGBA differently. 374void Textures::setTextureFormat(const wstring& resourceName) 375{ 376 // 4J Stu - These texture formats are not currently in the render header 377#ifdef _XBOX 378 if(resourceName == L"/environment/clouds.png") 379 { 380 TEXTURE_FORMAT = C4JRender::TEXTURE_FORMAT_R1G1B1Ax; 381 } 382 else if(resourceName == L"%blur%/misc/pumpkinblur.png") 383 { 384 TEXTURE_FORMAT = C4JRender::TEXTURE_FORMAT_R0G0B0Ax; 385 } 386 else if(resourceName == L"%clamp%/misc/shadow.png") 387 { 388 TEXTURE_FORMAT = C4JRender::TEXTURE_FORMAT_R0G0B0Ax; 389 } 390 else if(resourceName == L"/environment/snow.png") 391 { 392 TEXTURE_FORMAT = C4JRender::TEXTURE_FORMAT_RxGxBxAx; 393 } 394 else if(resourceName == L"/1_2_2/misc/explosion.png") 395 { 396 TEXTURE_FORMAT = C4JRender::TEXTURE_FORMAT_RxGxBxAx; 397 } 398 else 399#endif 400 { 401 TEXTURE_FORMAT = C4JRender::TEXTURE_FORMAT_RxGyBzAw; 402 } 403} 404 405void Textures::bindTexture(const wstring &resourceName) 406{ 407 bind(loadTexture(TN_COUNT,resourceName)); 408} 409 410// 4J Added 411void Textures::bindTexture(ResourceLocation *resource) 412{ 413 if(resource->isPreloaded()) 414 { 415 bind(loadTexture(resource->getTexture())); 416 } 417 else 418 { 419 bind(loadTexture(TN_COUNT, resource->getPath())); 420 } 421} 422 423void Textures::bindTextureLayers(ResourceLocation *resource) 424{ 425 assert(resource->isPreloaded()); 426 427 int layers = resource->getTextureCount(); 428 429 for( int i = 0; i < layers; i++ ) 430 { 431 RenderManager.TextureBind(loadTexture(resource->getTexture(i))); 432 } 433} 434 435void Textures::bind(int id) 436{ 437 //if (id != lastBoundId) 438 { 439 if(id < 0) return; 440 glBindTexture(GL_TEXTURE_2D, id); 441 // lastBoundId = id; 442 } 443} 444 445ResourceLocation *Textures::getTextureLocation(shared_ptr<Entity> entity) 446{ 447 shared_ptr<ItemEntity> item = dynamic_pointer_cast<ItemEntity>(entity); 448 int iconType = item->getItem()->getIconType(); 449 return getTextureLocation(iconType); 450} 451 452ResourceLocation *Textures::getTextureLocation(int iconType) 453{ 454 switch(iconType) 455 { 456 case Icon::TYPE_TERRAIN: 457 return &TextureAtlas::LOCATION_BLOCKS; 458 break; 459 case Icon::TYPE_ITEM: 460 return &TextureAtlas::LOCATION_ITEMS; 461 break; 462 } 463} 464 465void Textures::clearLastBoundId() 466{ 467 lastBoundId = -1; 468} 469 470int Textures::loadTexture(TEXTURE_NAME texId, const wstring& resourceName) 471{ 472// char buf[256]; 473// wcstombs(buf, resourceName.c_str(), 256); 474// printf("Textures::loadTexture name - %s\n",buf); 475 476 //if (resourceName.compare(L"/terrain.png") == 0) 477 //{ 478 // terrain->getStitchedTexture()->bind(0); 479 // return terrain->getStitchedTexture()->getGlId(); 480 //} 481 //if (resourceName.compare(L"/gui/items.png") == 0) 482 //{ 483 // items->getStitchedTexture()->bind(0); 484 // return items->getStitchedTexture()->getGlId(); 485 //} 486 487 // If the texture is not present in the idMap, load it, otherwise return its id 488 489 { 490 bool inMap = ( idMap.find(resourceName) != idMap.end() ); 491 int id = idMap[resourceName]; 492 if (inMap) return id; 493 } 494 495 wstring pathName = resourceName; 496 497 // 4J - added special cases to avoid mipmapping on clouds & shadows 498 if( (resourceName == L"environment/clouds.png") || 499 (resourceName == L"%clamp%misc/shadow.png") || 500 (resourceName == L"%blur%misc/pumpkinblur.png") || 501 (resourceName == L"%clamp%misc/shadow.png") || 502 (resourceName == L"gui/icons.png" ) || 503 (resourceName == L"gui/gui.png" ) || 504 (resourceName == L"misc/footprint.png") ) 505 { 506 MIPMAP = false; 507 } 508 setTextureFormat(resourceName); 509 510 // 4J - removed try/catch 511// try { 512 int id = MemoryTracker::genTextures(); 513 514 515 wstring prefix = L"%blur%"; 516 bool blur = resourceName.substr(0, prefix.size()).compare(prefix) == 0; //resourceName.startsWith("%blur%"); 517 if (blur) pathName = resourceName.substr(6); 518 519 prefix = L"%clamp%"; 520 bool clamp = resourceName.substr(0, prefix.size()).compare(prefix) == 0; //resourceName.startsWith("%clamp%"); 521 if (clamp) pathName = resourceName.substr(7); 522 523 //wstring in = skins->getSelected()->getResource(pathName); 524 if (false ) // 4J - removed was ( in == NULL) 525 { 526 loadTexture(missingNo, id, blur, clamp); 527 } 528 else 529 { 530 // 4J Stu - Get resource above just returns the name for texture packs 531 BufferedImage *bufImage = readImage(texId, pathName); //in); 532 loadTexture(bufImage, id, blur, clamp); 533 delete bufImage; 534 } 535 536 idMap[resourceName] = id; 537 MIPMAP = true; // 4J added 538 TEXTURE_FORMAT = C4JRender::TEXTURE_FORMAT_RxGyBzAw; 539 return id; 540 /* 541 } catch (IOException e) { 542 e.printStackTrace(); 543 MemoryTracker.genTextures(ib); 544 int id = ib.get(0); 545 loadTexture(missingNo, id); 546 idMap.put(resourceName, id); 547 return id; 548 } 549 */ 550} 551 552int Textures::getTexture(BufferedImage *img, C4JRender::eTextureFormat format, bool mipmap) 553{ 554 int id = MemoryTracker::genTextures(); 555 TEXTURE_FORMAT = format; 556 MIPMAP = mipmap; 557 loadTexture(img, id); 558 TEXTURE_FORMAT = C4JRender::TEXTURE_FORMAT_RxGyBzAw; 559 MIPMAP = true; 560 loadedImages[id] = img; 561 return id; 562} 563 564void Textures::loadTexture(BufferedImage *img, int id) 565{ 566// printf("Textures::loadTexture BufferedImage %d\n",id); 567 568 loadTexture(img, id, false, false); 569} 570 571void Textures::loadTexture(BufferedImage *img, int id, bool blur, bool clamp) 572{ 573// printf("Textures::loadTexture BufferedImage with blur and clamp %d\n",id); 574 int iMipLevels=1; 575 MemSect(33); 576 glBindTexture(GL_TEXTURE_2D, id); 577 578 if (MIPMAP) 579 { 580 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); 581 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 582 /* 583 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); 584 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 4); 585 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); 586 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 4); 587 */ 588 } 589 else 590 { 591 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 592 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 593 } 594 if (blur) 595 { 596 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 597 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 598 } 599 600 if (clamp) 601 { 602 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); 603 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); 604 } 605 else 606 { 607 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 608 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 609 } 610 611 int w = img->getWidth(); 612 int h = img->getHeight(); 613 614 intArray rawPixels(w*h); 615 img->getRGB(0, 0, w, h, rawPixels, 0, w); 616 617 if (options != NULL && options->anaglyph3d) 618 { 619 rawPixels = anaglyph(rawPixels); 620 } 621 622 byteArray newPixels(w * h * 4); 623 for (unsigned int i = 0; i < rawPixels.length; i++) 624 { 625 int a = (rawPixels[i] >> 24) & 0xff; 626 int r = (rawPixels[i] >> 16) & 0xff; 627 int g = (rawPixels[i] >> 8) & 0xff; 628 int b = (rawPixels[i]) & 0xff; 629 630#ifdef _XBOX 631 newPixels[i * 4 + 0] = (byte) a; 632 newPixels[i * 4 + 1] = (byte) r; 633 newPixels[i * 4 + 2] = (byte) g; 634 newPixels[i * 4 + 3] = (byte) b; 635#else 636 newPixels[i * 4 + 0] = (byte) r; 637 newPixels[i * 4 + 1] = (byte) g; 638 newPixels[i * 4 + 2] = (byte) b; 639 newPixels[i * 4 + 3] = (byte) a; 640#endif 641 } 642 // 4J - now creating a buffer of the size we require dynamically 643 ByteBuffer *pixels = MemoryTracker::createByteBuffer(w * h * 4); 644 pixels->clear(); 645 pixels->put(newPixels); 646 pixels->position(0)->limit(newPixels.length); 647 648 delete[] rawPixels.data; 649 delete[] newPixels.data; 650 651 if (MIPMAP) 652 { 653 // 4J-PB - In the new XDK, the CreateTexture will fail if the number of mipmaps is higher than the width & height passed in will allow! 654 int iWidthMips=1; 655 int iHeightMips=1; 656 while((8<<iWidthMips)<w) iWidthMips++; 657 while((8<<iHeightMips)<h) iHeightMips++; 658 659 iMipLevels=(iWidthMips<iHeightMips)?iWidthMips:iHeightMips; 660 //RenderManager.TextureSetTextureLevels(5); // 4J added 661 if(iMipLevels>5)iMipLevels = 5; 662 RenderManager.TextureSetTextureLevels(iMipLevels); // 4J added 663 } 664 RenderManager.TextureData(w,h,pixels->getBuffer(),0,TEXTURE_FORMAT); 665 //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, pixels); 666 667 if (MIPMAP) 668 { 669 for (int level = 1; level < iMipLevels; level++) 670 { 671 int ow = w >> (level - 1); 672 // int oh = h >> (level - 1); 673 674 int ww = w >> level; 675 int hh = h >> level; 676 677 // 4J - added tempData so we aren't overwriting source data 678 unsigned int *tempData = new unsigned int[ww * hh]; 679 // 4J - added - have we loaded mipmap data for this level? Use that rather than generating if possible 680 if( img->getData( level ) ) 681 { 682 memcpy( tempData, img->getData( level ), ww * hh * 4); 683#ifndef _XBOX 684 // Swap ARGB to RGBA 685 for( int i = 0; i < ww * hh ; i++ ) 686 { 687 tempData[i] = ( tempData[i] >> 24 ) | (tempData[i] << 8 ); 688 } 689#endif 690 } 691 else 692 { 693 for (int x = 0; x < ww; x++) 694 for (int y = 0; y < hh; y++) 695 { 696 int c0 = pixels->getInt(((x * 2 + 0) + (y * 2 + 0) * ow) * 4); 697 int c1 = pixels->getInt(((x * 2 + 1) + (y * 2 + 0) * ow) * 4); 698 int c2 = pixels->getInt(((x * 2 + 1) + (y * 2 + 1) * ow) * 4); 699 int c3 = pixels->getInt(((x * 2 + 0) + (y * 2 + 1) * ow) * 4); 700#ifndef _XBOX 701 // 4J - convert our RGBA texels to ARGB that crispBlend is expecting 702 c0 = ( ( c0 >> 8 ) & 0x00ffffff ) | ( c0 << 24 ); 703 c1 = ( ( c1 >> 8 ) & 0x00ffffff ) | ( c1 << 24 ); 704 c2 = ( ( c2 >> 8 ) & 0x00ffffff ) | ( c2 << 24 ); 705 c3 = ( ( c3 >> 8 ) & 0x00ffffff ) | ( c3 << 24 ); 706#endif 707 int col = Texture::crispBlend(Texture::crispBlend(c0, c1), Texture::crispBlend(c2, c3)); 708#ifndef _XBOX 709 // 4J - and back from ARGB -> RGBA 710 col = ( col << 8 ) | (( col >> 24 ) & 0xff); 711#endif 712 tempData[x + y * ww] = col; 713 } 714 } 715 for (int x = 0; x < ww; x++ ) 716 for (int y = 0; y < hh; y++) 717 { 718 pixels->putInt((x + y * ww) * 4, tempData[x + y * ww]); 719 } 720 delete [] tempData; 721 RenderManager.TextureData(ww,hh,pixels->getBuffer(),level,TEXTURE_FORMAT); 722 } 723 } 724 725 /* 726 * if (MIPMAP) { GLU.gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, w, h, 727 * GL_RGBA, GL_UNSIGNED_BYTE, pixels); } else { } 728 */ 729 delete pixels; // 4J - now creating this dynamically 730 MemSect(0); 731} 732 733intArray Textures::anaglyph(intArray rawPixels) 734{ 735 intArray result(rawPixels.length); 736 for (unsigned int i = 0; i < rawPixels.length; i++) 737 { 738 int a = (rawPixels[i] >> 24) & 0xff; 739 int r = (rawPixels[i] >> 16) & 0xff; 740 int g = (rawPixels[i] >> 8) & 0xff; 741 int b = (rawPixels[i]) & 0xff; 742 743 int rr = (r * 30 + g * 59 + b * 11) / 100; 744 int gg = (r * 30 + g * 70) / (100); 745 int bb = (r * 30 + b * 70) / (100); 746 747 748 result[i] = a << 24 | rr << 16 | gg << 8 | bb; 749 } 750 751 delete[] rawPixels.data; 752 753 return result; 754} 755 756void Textures::replaceTexture(intArray rawPixels, int w, int h, int id) 757{ 758 bind(id); 759 760 // Removed in Java 761#if 0 762 if (MIPMAP) 763 { 764 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); 765 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 766 /* 767 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); 768 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 4); 769 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); 770 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 4); 771 */ 772 } 773 else 774#endif 775 { 776 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 777 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 778 } 779 780 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 781 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 782 783 if (options != NULL && options->anaglyph3d) 784 { 785 rawPixels = anaglyph(rawPixels); 786 } 787 788 byteArray newPixels(w * h * 4); 789 for (unsigned int i = 0; i < rawPixels.length; i++) 790 { 791 int a = (rawPixels[i] >> 24) & 0xff; 792 int r = (rawPixels[i] >> 16) & 0xff; 793 int g = (rawPixels[i] >> 8) & 0xff; 794 int b = (rawPixels[i]) & 0xff; 795 796 if (options != NULL && options->anaglyph3d) 797 { 798 int rr = (r * 30 + g * 59 + b * 11) / 100; 799 int gg = (r * 30 + g * 70) / (100); 800 int bb = (r * 30 + b * 70) / (100); 801 802 r = rr; 803 g = gg; 804 b = bb; 805 } 806 807 newPixels[i * 4 + 0] = (byte) r; 808 newPixels[i * 4 + 1] = (byte) g; 809 newPixels[i * 4 + 2] = (byte) b; 810 newPixels[i * 4 + 3] = (byte) a; 811 } 812 ByteBuffer *pixels = MemoryTracker::createByteBuffer(w * h * 4); // 4J - now creating dynamically 813 pixels->put(newPixels); 814 pixels->position(0)->limit(newPixels.length); 815 delete [] newPixels.data; 816 817 // New 818 // glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, pixels); 819#ifdef _XBOX 820 RenderManager.TextureDataUpdate(pixels->getBuffer(),0); 821#else 822 RenderManager.TextureDataUpdate(0, 0,w,h,pixels->getBuffer(),0); 823#endif 824 // Old 825 //glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels); 826 delete pixels; 827} 828 829// 4J - added. This is a more minimal version of replaceTexture that assumes the texture bytes are already in order, and so doesn't do any of the extra copying round 830// that the original java version does 831void Textures::replaceTextureDirect(intArray rawPixels, int w, int h, int id) 832{ 833 glBindTexture(GL_TEXTURE_2D, id); 834 835 // Remove in Java 836#if 0 837 if (MIPMAP) 838 { 839 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); 840 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 841 /* 842 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); 843 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 4); 844 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); 845 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 4); 846 */ 847 } 848 else 849#endif 850 { 851 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 852 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 853 } 854 855 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 856 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 857 858#ifdef _XBOX 859 RenderManager.TextureDataUpdate(rawPixels.data, 0); 860#else 861 RenderManager.TextureDataUpdate(0, 0, w, h, rawPixels.data, 0); 862#endif 863} 864 865// 4J - added. This is a more minimal version of replaceTexture that assumes the texture bytes are already in order, and so doesn't do any of the extra copying round 866// that the original java version does 867void Textures::replaceTextureDirect(shortArray rawPixels, int w, int h, int id) 868{ 869 glBindTexture(GL_TEXTURE_2D, id); 870 871 // Remove in Java 872#if 0 873 if (MIPMAP) 874 { 875 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); 876 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 877 /* 878 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); 879 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 4); 880 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); 881 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 4); 882 */ 883 } 884 else 885#endif 886 { 887 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 888 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 889 } 890 891 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 892 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 893 894#ifdef _XBOX 895 RenderManager.TextureDataUpdate(rawPixels.data, 0); 896#else 897 RenderManager.TextureDataUpdate(0, 0, w, h, rawPixels.data, 0); 898#endif 899} 900 901void Textures::releaseTexture(int id) 902{ 903 loadedImages.erase(id); 904 glDeleteTextures(id); 905} 906 907int Textures::loadHttpTexture(const wstring& url, const wstring& backup) 908{ 909 HttpTexture *texture = httpTextures[url]; 910 if (texture != NULL) 911 { 912 if (texture->loadedImage != NULL && !texture->isLoaded) 913 { 914 if (texture->id < 0) 915 { 916 texture->id = getTexture(texture->loadedImage); 917 } 918 else 919 { 920 loadTexture(texture->loadedImage, texture->id); 921 } 922 texture->isLoaded = true; 923 } 924 } 925 if (texture == NULL || texture->id < 0) 926 { 927 if (backup.empty() ) return -1; 928 return loadTexture(TN_COUNT, backup); 929 } 930 return texture->id; 931} 932 933int Textures::loadHttpTexture(const wstring& url, int backup) 934{ 935 HttpTexture *texture = httpTextures[url]; 936 if (texture != NULL) 937 { 938 if (texture->loadedImage != NULL && !texture->isLoaded) 939 { 940 if (texture->id < 0) 941 { 942 texture->id = getTexture(texture->loadedImage); 943 } 944 else 945 { 946 loadTexture(texture->loadedImage, texture->id); 947 } 948 texture->isLoaded = true; 949 } 950 } 951 if (texture == NULL || texture->id < 0) 952 { 953 return loadTexture(backup); 954 } 955 return texture->id; 956} 957 958bool Textures::hasHttpTexture(const wstring &url) 959{ 960 return httpTextures.find(url) != httpTextures.end(); 961} 962 963HttpTexture *Textures::addHttpTexture(const wstring& url, HttpTextureProcessor *processor) 964{ 965 HttpTexture *texture = httpTextures[url]; 966 if (texture == NULL) 967 { 968 httpTextures[url] = new HttpTexture(url, processor); 969 } 970 else 971 { 972 texture->count++; 973 } 974 return texture; 975} 976 977void Textures::removeHttpTexture(const wstring& url) 978{ 979 HttpTexture *texture = httpTextures[url]; 980 if (texture != NULL) 981 { 982 texture->count--; 983 if (texture->count == 0) 984 { 985 if (texture->id >= 0) releaseTexture(texture->id); 986 httpTextures.erase(url); 987 } 988 } 989} 990 991// 4J-PB - adding for texture in memory (from global title storage) 992int Textures::loadMemTexture(const wstring& url, const wstring& backup) 993{ 994 MemTexture *texture = NULL; 995 AUTO_VAR(it, memTextures.find(url) ); 996 if (it != memTextures.end()) 997 { 998 texture = (*it).second; 999 } 1000 if(texture == NULL && app.IsFileInMemoryTextures(url)) 1001 { 1002 // If we haven't loaded it yet, but we have the data for it then add it 1003 texture = addMemTexture(url, new MobSkinMemTextureProcessor() ); 1004 } 1005 if(texture != NULL) 1006 { 1007 if (texture->loadedImage != NULL && !texture->isLoaded) 1008 { 1009 // 4J - Disable mipmapping in general for skins & capes. Have seen problems with edge-on polys for some eg mumbo jumbo 1010 if( ( url.substr(0,7) == L"dlcskin" ) || 1011 ( url.substr(0,7) == L"dlccape" ) ) 1012 { 1013 MIPMAP = false; 1014 } 1015 1016 if (texture->id < 0) 1017 { 1018 texture->id = getTexture(texture->loadedImage, C4JRender::TEXTURE_FORMAT_RxGyBzAw, MIPMAP); 1019 } 1020 else 1021 { 1022 loadTexture(texture->loadedImage, texture->id); 1023 } 1024 texture->isLoaded = true; 1025 MIPMAP = true; 1026 } 1027 } 1028 if (texture == NULL || texture->id < 0) 1029 { 1030 if (backup.empty() ) return -1; 1031 return loadTexture(TN_COUNT,backup); 1032 } 1033 return texture->id; 1034} 1035 1036int Textures::loadMemTexture(const wstring& url, int backup) 1037{ 1038 MemTexture *texture = NULL; 1039 AUTO_VAR(it, memTextures.find(url) ); 1040 if (it != memTextures.end()) 1041 { 1042 texture = (*it).second; 1043 } 1044 if(texture == NULL && app.IsFileInMemoryTextures(url)) 1045 { 1046 // If we haven't loaded it yet, but we have the data for it then add it 1047 texture = addMemTexture(url, new MobSkinMemTextureProcessor() ); 1048 } 1049 if(texture != NULL) 1050 { 1051 texture->ticksSinceLastUse = 0; 1052 if (texture->loadedImage != NULL && !texture->isLoaded) 1053 { 1054 // 4J - Disable mipmapping in general for skins & capes. Have seen problems with edge-on polys for some eg mumbo jumbo 1055 if( ( url.substr(0,7) == L"dlcskin" ) || 1056 ( url.substr(0,7) == L"dlccape" ) ) 1057 { 1058 MIPMAP = false; 1059 } 1060 if (texture->id < 0) 1061 { 1062 texture->id = getTexture(texture->loadedImage, C4JRender::TEXTURE_FORMAT_RxGyBzAw, MIPMAP); 1063 } 1064 else 1065 { 1066 loadTexture(texture->loadedImage, texture->id); 1067 } 1068 texture->isLoaded = true; 1069 MIPMAP = true; 1070 } 1071 } 1072 if (texture == NULL || texture->id < 0) 1073 { 1074 return loadTexture(backup); 1075 } 1076 return texture->id; 1077} 1078 1079MemTexture *Textures::addMemTexture(const wstring& name,MemTextureProcessor *processor) 1080{ 1081 MemTexture *texture = NULL; 1082 AUTO_VAR(it, memTextures.find(name) ); 1083 if (it != memTextures.end()) 1084 { 1085 texture = (*it).second; 1086 } 1087 if(texture == NULL) 1088 { 1089 // can we find it in the app mem files? 1090 PBYTE pbData=NULL; 1091 DWORD dwBytes=0; 1092 app.GetMemFileDetails(name,&pbData,&dwBytes); 1093 1094 if(dwBytes!=0) 1095 { 1096 texture = new MemTexture(name, pbData, dwBytes, processor); 1097 memTextures[name] = texture; 1098 } 1099 else 1100 { 1101 // 4J Stu - Make an entry for this anyway and we can populate it later 1102 memTextures[name] = NULL; 1103 } 1104 } 1105 else 1106 { 1107 texture->count++; 1108 } 1109 1110 delete processor; 1111 1112 return texture; 1113} 1114 1115// MemTexture *Textures::getMemTexture(const wstring& url, MemTextureProcessor *processor) 1116// { 1117// MemTexture *texture = memTextures[url]; 1118// if (texture != NULL) 1119// { 1120// texture->count++; 1121// } 1122// return texture; 1123// } 1124 1125void Textures::removeMemTexture(const wstring& url) 1126{ 1127 MemTexture *texture = NULL; 1128 AUTO_VAR(it, memTextures.find(url) ); 1129 if (it != memTextures.end()) 1130 { 1131 texture = (*it).second; 1132 1133 // If it's NULL then we should just remove the entry 1134 if( texture == NULL ) memTextures.erase(url); 1135 } 1136 if(texture != NULL) 1137 { 1138 texture->count--; 1139 if (texture->count == 0) 1140 { 1141 if (texture->id >= 0) releaseTexture(texture->id); 1142 memTextures.erase(url); 1143 delete texture; 1144 } 1145 } 1146} 1147 1148void Textures::tick(bool updateTextures, bool tickDynamics) // 4J added updateTextures parameter & tickDynamics 1149{ 1150 MemSect(22); 1151 if(tickDynamics) 1152 { 1153 // 4J - added - if we aren't updating the final renderer textures, just tick each of the dynamic textures instead. This is used so that in frames were we have multiple 1154 // ticks due to framerate compensation, that we don't lock the renderer textures twice needlessly and force the CPU to sync with the GPU. 1155 if( !updateTextures ) 1156 { 1157 MemSect(0); 1158 return; 1159 } 1160 1161 // 4J - added - tell renderer that we're about to do a block of dynamic texture updates, so we can unlock the resources after they are done rather than a series of locks/unlocks 1162 //RenderManager.TextureDynamicUpdateStart(); 1163 terrain->cycleAnimationFrames(); 1164 items->cycleAnimationFrames(); 1165 //RenderManager.TextureDynamicUpdateEnd(); // 4J added - see comment above 1166 } 1167 1168 // 4J - go over all the memory textures once per frame, and free any that haven't been used for a while. Ones that are being used will 1169 // have their ticksSinceLastUse reset in Textures::loadMemTexture. 1170 for( AUTO_VAR(it, memTextures.begin() ); it != memTextures.end(); ) 1171 { 1172 MemTexture *tex = it->second; 1173 1174 if( tex && ( ++tex->ticksSinceLastUse > MemTexture::UNUSED_TICKS_TO_FREE ) ) 1175 { 1176 if (tex->id >= 0) releaseTexture(tex->id); 1177 delete tex; 1178 it = memTextures.erase(it); 1179 } 1180 else 1181 { 1182 it++; 1183 } 1184 1185 } 1186 MemSect(0); 1187} 1188 1189void Textures::reloadAll() 1190{ 1191 TexturePack *skin = skins->getSelected(); 1192 1193 for( int i = 0; i < TN_COUNT - 2; i++ ) 1194 { 1195 releaseTexture(preLoadedIdx[i]); 1196 } 1197 1198 idMap.clear(); 1199 loadedImages.clear(); 1200 1201 loadIndexedTextures(); 1202 1203 pixelsMap.clear(); 1204 // 4J Stu - These are not used any more 1205 //WaterColor::init(loadTexturePixels(L"misc/watercolor.png")); 1206 //GrassColor::init(loadTexturePixels(L"misc/grasscolor.png")); 1207 //FoliageColor::init(loadTexturePixels(L"misc/foliagecolor.png")); 1208 1209 stitch(); 1210 1211 skins->clearInvalidTexturePacks(); 1212 1213#if 0 1214 AUTO_VAR(itEndLI, loadedImages.end() ); 1215 for(unordered_map<int, BufferedImage *>::iterator it = loadedImages.begin(); it != itEndLI; it++ ) 1216 { 1217 BufferedImage *image = it->second; 1218 loadTexture(image, it->first); 1219 } 1220 1221 AUTO_VAR(itEndHT, httpTextures.end()); 1222 for(unordered_map<wstring, HttpTexture *>::iterator it = httpTextures.begin(); it != itEndHT; it++ ) 1223 { 1224 it->second->isLoaded = false; 1225 } 1226 1227 AUTO_VAR(itEndMT, memTextures.end()); 1228 for(unordered_map<wstring, MemTexture *>::iterator it = memTextures.begin(); it != itEndMT; it++ ) 1229 { 1230 it->second->isLoaded = false; 1231 } 1232 1233 1234 AUTO_VAR(itEndIM, idMap.end()); 1235 for( unordered_map<wstring, int>::iterator it = idMap.begin(); it != itEndIM; it++ ) 1236 { 1237 wstring name = it->first; 1238 1239 int id = idMap[name]; 1240 BufferedImage *image; 1241 1242 wstring prefix = L"%blur%"; 1243 bool blur = name.substr(0, prefix.size()).compare(prefix) == 0; //name.startsWith("%blur%"); 1244 if (blur) name = name.substr(6); 1245 1246 prefix = L"%clamp%"; 1247 bool clamp = name.substr(0, prefix.size()).compare(prefix) == 0; //name.startsWith("%clamp%"); 1248 if (clamp) name = name.substr(7); 1249 1250 image = readImage(skin->getResource(name)); 1251 1252 loadTexture(image, id, blur, clamp); 1253 delete image; 1254 } 1255 AUTO_VAR(itEndPM, pixelsMap.end()); 1256 for( unordered_map<wstring, intArray>::iterator it = pixelsMap.begin(); it != itEndPM; it++ ) 1257 { 1258 wstring name = it->first; 1259 BufferedImage *image = readImage(skin->getResource(name)); 1260 1261 loadTexturePixels(image, pixelsMap[name]); 1262 delete image; 1263 } 1264#endif 1265 1266 // Recalculate fonts 1267 //Minecraft::GetInstance()->font->loadCharacterWidths(); 1268 //Minecraft::GetInstance()->altFont->loadCharacterWidths(); 1269} 1270 1271void Textures::stitch() 1272{ 1273 terrain->stitch(); 1274 items->stitch(); 1275} 1276 1277Icon *Textures::getMissingIcon(int type) 1278{ 1279 switch (type) 1280 { 1281 case Icon::TYPE_ITEM: 1282 default: 1283 return items->getMissingIcon(); 1284 case Icon::TYPE_TERRAIN: 1285 return terrain->getMissingIcon(); 1286 } 1287} 1288 1289BufferedImage *Textures::readImage(TEXTURE_NAME texId, const wstring& name) // 4J was InputStream *in 1290{ 1291 BufferedImage *img=NULL; 1292 MemSect(32); 1293 // is this image one of the Title Update ones? 1294 bool isTu = IsTUImage(texId, name); 1295 wstring drive = L""; 1296 1297 if(!skins->isUsingDefaultSkin() && skins->getSelected()->hasFile(L"res/" + name,false)) 1298 { 1299 drive = skins->getSelected()->getPath(isTu); 1300 img = skins->getSelected()->getImageResource(name, false, isTu, drive); //new BufferedImage(name,false,isTu,drive); 1301 } 1302 else 1303 { 1304 const char *pchName=wstringtofilename(name); 1305#ifdef __PS3__ 1306 if(app.GetBootedFromDiscPatch() && app.IsFileInPatchList(pchName)) 1307 { 1308 char *pchUsrDir = app.GetBDUsrDirPath(pchName); 1309 wstring wstr (pchUsrDir, pchUsrDir+strlen(pchUsrDir)); 1310 1311 if(isTu) 1312 { 1313 drive= wstr + L"\\Common\\res\\TitleUpdate\\"; 1314 1315 } 1316 else 1317 { 1318 drive= wstr + L"\\Common\\"; 1319 } 1320 } 1321 else 1322#endif 1323 { 1324 drive = skins->getDefault()->getPath(isTu); 1325 } 1326 1327 const char *pchDrive=wstringtofilename(drive); 1328 1329 if(IsOriginalImage(texId, name) || isTu) 1330 { 1331 img = skins->getDefault()->getImageResource(name,false,isTu,drive); //new BufferedImage(name,false,isTu,drive); 1332 } 1333 else 1334 { 1335 img = skins->getDefault()->getImageResource(L"1_2_2/" + name, false, isTu, drive); //new BufferedImage(L"/1_2_2" + name,false,isTu,drive); 1336 } 1337 } 1338 1339 MemSect(0); 1340 return img; 1341} 1342 1343// Match the preload images from their enum to avoid a ton of string comparisons 1344TEXTURE_NAME TUImages[] = 1345{ 1346 TN_POWERED_CREEPER, 1347 TN_MOB_ENDERMAN_EYES, 1348 TN_MISC_EXPLOSION, 1349 TN_MOB_ZOMBIE, 1350 TN_MISC_FOOTSTEP, 1351 TN_MOB_RED_COW, 1352 TN_MOB_SNOWMAN, 1353 TN_MOB_ENDERDRAGON, 1354 TN_MOB_VILLAGER_VILLAGER, 1355 TN_MOB_VILLAGER_FARMER, 1356 TN_MOB_VILLAGER_LIBRARIAN, 1357 TN_MOB_VILLAGER_PRIEST, 1358 TN_MOB_VILLAGER_SMITH, 1359 TN_MOB_VILLAGER_BUTCHER, 1360 TN_MOB_ENDERDRAGON_ENDEREYES, 1361 TN__BLUR__MISC_GLINT, 1362 TN_ITEM_BOOK, 1363 TN_MISC_PARTICLEFIELD, 1364 1365 // TU9 1366 TN_MISC_TUNNEL, 1367 TN_MOB_ENDERDRAGON_BEAM, 1368 TN_GUI_ITEMS, 1369 TN_TERRAIN, 1370 TN_MISC_MAPICONS, 1371 1372 // TU12 1373 TN_MOB_WITHER_SKELETON, 1374 1375 // TU14 1376 TN_TILE_ENDER_CHEST, 1377 TN_ART_KZ, 1378 TN_MOB_WOLF_TAME, 1379 TN_MOB_WOLF_COLLAR, 1380 TN_PARTICLES, 1381 TN_MOB_ZOMBIE_VILLAGER, 1382 1383 TN_ITEM_LEASHKNOT, 1384 1385 TN_MISC_BEACON_BEAM, 1386 1387 TN_MOB_BAT, 1388 1389 TN_MOB_DONKEY, 1390 TN_MOB_HORSE_BLACK, 1391 TN_MOB_HORSE_BROWN, 1392 TN_MOB_HORSE_CHESTNUT, 1393 TN_MOB_HORSE_CREAMY, 1394 TN_MOB_HORSE_DARKBROWN, 1395 TN_MOB_HORSE_GRAY, 1396 TN_MOB_HORSE_MARKINGS_BLACKDOTS, 1397 TN_MOB_HORSE_MARKINGS_WHITE, 1398 TN_MOB_HORSE_MARKINGS_WHITEDOTS, 1399 TN_MOB_HORSE_MARKINGS_WHITEFIELD, 1400 TN_MOB_HORSE_SKELETON, 1401 TN_MOB_HORSE_WHITE, 1402 TN_MOB_HORSE_ZOMBIE, 1403 TN_MOB_MULE, 1404 TN_MOB_HORSE_ARMOR_DIAMOND, 1405 TN_MOB_HORSE_ARMOR_GOLD, 1406 TN_MOB_HORSE_ARMOR_IRON, 1407 1408 TN_MOB_WITCH, 1409 1410 TN_MOB_WITHER, 1411 TN_MOB_WITHER_ARMOR, 1412 TN_MOB_WITHER_INVULNERABLE, 1413 1414 TN_TILE_TRAP_CHEST, 1415 TN_TILE_LARGE_TRAP_CHEST, 1416 //TN_TILE_XMAS_CHEST, 1417 //TN_TILE_LARGE_XMAS_CHEST, 1418 1419#ifdef _LARGE_WORLDS 1420 TN_MISC_ADDITIONALMAPICONS, 1421#endif 1422 1423 // TU17 1424 TN_DEFAULT_FONT, 1425 // TN_ALT_FONT, // Not in TU yet 1426 1427 TN_COUNT // Why is this here? 1428}; 1429 1430// This is for any TU textures that aren't part of our enum indexed preload set 1431wchar_t *TUImagePaths[] = 1432{ 1433 L"font/Default", 1434 L"font/Mojangles_7", 1435 L"font/Mojangles_11", 1436 1437 // TU12 1438 L"armor/cloth_1.png", 1439 L"armor/cloth_1_b.png", 1440 L"armor/cloth_2.png", 1441 L"armor/cloth_2_b.png", 1442 1443 // 1444 1445 NULL 1446}; 1447 1448bool Textures::IsTUImage(TEXTURE_NAME texId, const wstring& name) 1449{ 1450 int i = 0; 1451 if(texId < TN_COUNT) 1452 { 1453 while(TUImages[i] < TN_COUNT) 1454 { 1455 if(texId == TUImages[i]) 1456 { 1457 return true; 1458 } 1459 i++; 1460 } 1461 } 1462 i = 0; 1463 while(TUImagePaths[i]) 1464 { 1465 if(name.compare(TUImagePaths[i])==0) 1466 { 1467 return true; 1468 } 1469 i++; 1470 } 1471 return false; 1472} 1473 1474TEXTURE_NAME OriginalImages[] = 1475{ 1476 TN_MOB_CHAR, 1477 TN_MOB_CHAR1, 1478 TN_MOB_CHAR2, 1479 TN_MOB_CHAR3, 1480 TN_MOB_CHAR4, 1481 TN_MOB_CHAR5, 1482 TN_MOB_CHAR6, 1483 TN_MOB_CHAR7, 1484 1485 TN_MISC_MAPBG, 1486 1487 TN_COUNT 1488}; 1489 1490wchar_t *OriginalImagesPaths[] = 1491{ 1492 L"misc/watercolor.png", 1493 1494 NULL 1495}; 1496 1497bool Textures::IsOriginalImage(TEXTURE_NAME texId, const wstring& name) 1498{ 1499 int i = 0; 1500 if(texId < TN_COUNT) 1501 { 1502 while(OriginalImages[i] < TN_COUNT) 1503 { 1504 if(texId == OriginalImages[i]) 1505 { 1506 return true; 1507 } 1508 i++; 1509 } 1510 } 1511 i = 0; 1512 while(OriginalImagesPaths[i]) 1513 { 1514 if(name.compare(OriginalImagesPaths[i])==0) 1515 { 1516 return true; 1517 } 1518 i++; 1519 } 1520 return false; 1521} 1522