Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TextureManager.cpp 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. /*!
  2. * \file src/TextureManager.cpp
  3. * \brief Texture Registry
  4. *
  5. * \author Mongoose
  6. * \author xythobuz
  7. */
  8. #include "imgui/imgui.h"
  9. #include "stb/stb_image.h"
  10. #include "global.h"
  11. #include "Game.h"
  12. #include "Log.h"
  13. #include "RunTime.h"
  14. #include "World.h"
  15. #include "utils/Folder.h"
  16. #include "utils/pcx.h"
  17. #include "utils/pixel.h"
  18. #include "utils/random.h"
  19. #include "utils/strings.h"
  20. #include "TextureManager.h"
  21. #include <glbinding/gl/gl33.h>
  22. glm::vec2 TextureTile::getUV(unsigned int i) {
  23. glm::vec2 uv(vertices.at(i).xPixel,
  24. vertices.at(i).yPixel);
  25. /*! \fixme
  26. * This is my somewhat hacky approach to fixing
  27. * the bad texture-bleeding problems everywhere.
  28. * That's better, but makes the seams between
  29. * each sector much more visible!
  30. */
  31. if (vertices.at(i).xCoordinate == 1) {
  32. uv.x += 0.375f;
  33. }
  34. if (vertices.at(i).yCoordinate == 1) {
  35. uv.y += 0.375f;
  36. }
  37. return uv / 256.0f;
  38. }
  39. // ----------------------------------------------------------------------------
  40. #define COLOR_PALETTE_SIZE 256
  41. std::vector<unsigned int> TextureManager::mTextureIdsGame;
  42. std::vector<unsigned int> TextureManager::mTextureIdsSystem;
  43. std::vector<TextureTile*> TextureManager::tiles;
  44. std::vector<std::vector<int>> TextureManager::animations;
  45. std::vector<int> TextureManager::gameUnits;
  46. std::vector<int> TextureManager::systemUnits;
  47. unsigned int TextureManager::nextFreeTextureUnit = 0;
  48. std::vector<BufferManager> TextureManager::gameBuffers;
  49. std::vector<BufferManager> TextureManager::systemBuffers;
  50. std::array<glm::vec4, 256> TextureManager::colorPalette;
  51. std::vector<std::tuple<unsigned char*, unsigned int, unsigned int>> TextureManager::indexedTextures;
  52. int TextureManager::initialize() {
  53. orAssertEqual(mTextureIdsGame.size(), 0);
  54. orAssertEqual(mTextureIdsSystem.size(), 0);
  55. while (mTextureIdsSystem.size() < 2) {
  56. unsigned int id;
  57. gl::glGenTextures(1, &id);
  58. mTextureIdsSystem.push_back(id);
  59. }
  60. unsigned char* image = generateColorTexture(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), 32, 32, 32);
  61. int res = loadBufferSlot(image, 32, 32, ColorMode::RGBA, 32, TextureStorage::SYSTEM, TEXTURE_WHITE,
  62. false);
  63. delete [] image;
  64. if (res < 0) {
  65. return -1;
  66. }
  67. return 0;
  68. }
  69. int TextureManager::initializeSplash() {
  70. Folder f(RunTime::getPakDir());
  71. std::vector<File> files;
  72. f.findRecursiveFilesEndingWith(files, ".pcx");
  73. f.findRecursiveFilesEndingWith(files, ".bmp");
  74. f.findRecursiveFilesEndingWith(files, ".png");
  75. f.findRecursiveFilesEndingWith(files, ".tga");
  76. f.findRecursiveFilesEndingWith(files, ".jpg");
  77. if (files.size() == 0) {
  78. if (loadImage(RunTime::getDataDir() + "/splash.tga", TextureStorage::SYSTEM, TEXTURE_SPLASH) < 0) {
  79. return -2;
  80. }
  81. } else {
  82. int i = randomInteger(files.size() - 1);
  83. if (loadImage(files.at(i).getPath(), TextureStorage::SYSTEM, TEXTURE_SPLASH) < 0) {
  84. if (loadImage(RunTime::getDataDir() + "/splash.tga", TextureStorage::SYSTEM, TEXTURE_SPLASH) < 0) {
  85. return -3;
  86. }
  87. }
  88. }
  89. return 0;
  90. }
  91. void TextureManager::shutdown() {
  92. while (mTextureIdsSystem.size() > 0) {
  93. unsigned int id = mTextureIdsSystem.at(mTextureIdsSystem.size() - 1);
  94. gl::glDeleteTextures(1, &id);
  95. mTextureIdsSystem.pop_back();
  96. }
  97. gameBuffers.clear();
  98. systemBuffers.clear();
  99. clear();
  100. }
  101. void TextureManager::clear() {
  102. while (mTextureIdsGame.size() > 0) {
  103. unsigned int id = mTextureIdsGame.at(mTextureIdsGame.size() - 1);
  104. gl::glDeleteTextures(1, &id);
  105. mTextureIdsGame.pop_back();
  106. }
  107. while (!tiles.empty()) {
  108. delete tiles.at(tiles.size() - 1);
  109. tiles.pop_back();
  110. }
  111. animations.clear();
  112. gameUnits.clear();
  113. systemUnits.clear();
  114. nextFreeTextureUnit = 0;
  115. indexedTextures.clear();
  116. }
  117. int TextureManager::loadBufferSlot(unsigned char* image,
  118. unsigned int width, unsigned int height,
  119. ColorMode mode, unsigned int bpp,
  120. TextureStorage s, int slot, bool filter) {
  121. orAssertGreaterThan(width, 0);
  122. orAssertGreaterThan(height, 0);
  123. orAssert((mode == ColorMode::RGB)
  124. || (mode == ColorMode::BGR)
  125. || (mode == ColorMode::ARGB)
  126. || (mode == ColorMode::RGBA)
  127. || (mode == ColorMode::BGRA));
  128. orAssert((bpp == 8) || (bpp == 24) || (bpp == 32));
  129. if (slot < 0)
  130. slot = getIds(s).size();
  131. while (getIds(s).size() <= slot) {
  132. unsigned int id;
  133. gl::glGenTextures(1, &id);
  134. getIds(s).push_back(id);
  135. }
  136. gl::GLenum glcMode;
  137. switch (mode) {
  138. case ColorMode::BGR:
  139. glcMode = gl::GL_BGR;
  140. break;
  141. case ColorMode::RGB:
  142. glcMode = gl::GL_RGB;
  143. break;
  144. case ColorMode::ARGB:
  145. if (image != nullptr)
  146. argb2rgba32(image, width, height);
  147. glcMode = gl::GL_RGBA;
  148. break;
  149. case ColorMode::BGRA:
  150. glcMode = gl::GL_BGRA;
  151. break;
  152. case ColorMode::RGBA:
  153. glcMode = gl::GL_RGBA;
  154. break;
  155. }
  156. gl::glPixelStorei(gl::GL_UNPACK_ALIGNMENT, 1);
  157. bindTexture(slot, s);
  158. gl::glTexImage2D(gl::GL_TEXTURE_2D, 0, gl::GLint(gl::GL_RGBA), width, height, 0, glcMode, gl::GL_UNSIGNED_BYTE, image);
  159. if (filter) {
  160. // Trilinear filtering
  161. gl::glTexParameteri(gl::GL_TEXTURE_2D, gl::GL_TEXTURE_WRAP_S, gl::GLint(gl::GL_REPEAT));
  162. gl::glTexParameteri(gl::GL_TEXTURE_2D, gl::GL_TEXTURE_WRAP_T, gl::GLint(gl::GL_REPEAT));
  163. gl::glTexParameteri(gl::GL_TEXTURE_2D, gl::GL_TEXTURE_MAG_FILTER, gl::GLint(gl::GL_LINEAR));
  164. gl::glTexParameteri(gl::GL_TEXTURE_2D, gl::GL_TEXTURE_MIN_FILTER, gl::GLint(gl::GL_LINEAR_MIPMAP_LINEAR));
  165. gl::glGenerateMipmap(gl::GL_TEXTURE_2D);
  166. } else {
  167. gl::glTexParameteri(gl::GL_TEXTURE_2D, gl::GL_TEXTURE_MIN_FILTER, gl::GLint(gl::GL_NEAREST));
  168. gl::glTexParameteri(gl::GL_TEXTURE_2D, gl::GL_TEXTURE_MAG_FILTER, gl::GLint(gl::GL_NEAREST));
  169. }
  170. return slot;
  171. }
  172. int TextureManager::numTextures(TextureStorage s) {
  173. return getIds(s).size();
  174. }
  175. void TextureManager::bindTextureId(unsigned int n, TextureStorage s, unsigned int unit) {
  176. orAssertLessThan(n, getIds(s).size());
  177. orAssertLessThan(unit, 80); //! \fixme Query GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS
  178. gl::glActiveTexture(gl::GL_TEXTURE0 + unit);
  179. gl::glBindTexture(gl::GL_TEXTURE_2D, getIds(s).at(n));
  180. }
  181. int TextureManager::bindTexture(unsigned int n, TextureStorage s) {
  182. orAssertLessThan(n, getIds(s).size());
  183. if ((n < getUnits(s).size()) && (getUnits(s).at(n) >= 0)) {
  184. bindTextureId(n, s, getUnits(s).at(n));
  185. return getUnits(s).at(n);
  186. } else {
  187. while (getUnits(s).size() <= n)
  188. getUnits(s).push_back(-1);
  189. getUnits(s).at(n) = nextFreeTextureUnit;
  190. bindTextureId(n, s, nextFreeTextureUnit);
  191. nextFreeTextureUnit++;
  192. return nextFreeTextureUnit - 1;
  193. }
  194. }
  195. unsigned int TextureManager::getTextureID(int n, TextureStorage s) {
  196. orAssertLessThan(n, getIds(s).size());
  197. return getIds(s).at(n);
  198. }
  199. void TextureManager::addTile(TextureTile* t) {
  200. tiles.push_back(t);
  201. }
  202. int TextureManager::numTiles() {
  203. return tiles.size();
  204. }
  205. TextureTile& TextureManager::getTile(int index) {
  206. orAssertGreaterThanEqual(index, 0);
  207. orAssertLessThan(index, tiles.size());
  208. return *tiles.at(index);
  209. }
  210. void TextureManager::addAnimatedTile(int index, int tile) {
  211. while (index >= animations.size())
  212. animations.push_back(std::vector<int>());
  213. animations.at(index).push_back(tile);
  214. }
  215. int TextureManager::numAnimatedTiles() {
  216. return animations.size();
  217. }
  218. int TextureManager::getFirstTileAnimation(int index) {
  219. orAssertLessThan(index, animations.size());
  220. orAssertGreaterThan(animations.at(index).size(), 0);
  221. return animations.at(index).at(0);
  222. }
  223. int TextureManager::getNextTileAnimation(int index, int tile) {
  224. orAssertLessThan(index, animations.size());
  225. for (int i = 0; i < animations.at(index).size(); i++) {
  226. if (animations.at(index).at(i) == tile) {
  227. if (i < (animations.at(index).size() - 1))
  228. return animations.at(index).at(i + 1);
  229. else
  230. return animations.at(index).at(0);
  231. }
  232. }
  233. return -1;
  234. }
  235. BufferManager* TextureManager::getBufferManager(int tex, TextureStorage store) {
  236. auto& v = (store == TextureStorage::GAME) ? gameBuffers : systemBuffers;
  237. /*! \fixme Strange +2 needed, or else OpenRaider crashes hard.
  238. * Normally, this should only be (tex). I had to increase it to
  239. * (tex + 1) some time ago when OpenRaider crashed in relation to
  240. * non-existing texture IDs. Now, after removing all custom Font
  241. * support (one texture less loaded at startup), OR crashed again.
  242. * Increasing this to (tex + 2) "fixed" the problem. Why?
  243. */
  244. while (v.size() <= (tex + 2)) {
  245. v.emplace_back(v.size(), store);
  246. }
  247. return &(v.at(tex));
  248. }
  249. void TextureManager::setPalette(int index, glm::vec4 color) {
  250. orAssertGreaterThanEqual(index, 0);
  251. orAssertLessThan(index, COLOR_PALETTE_SIZE);
  252. colorPalette[index] = color;
  253. }
  254. glm::vec4 TextureManager::getPalette(int index) {
  255. orAssertGreaterThanEqual(index, 0);
  256. orAssertLessThan(index, COLOR_PALETTE_SIZE);
  257. return colorPalette[index];
  258. }
  259. void TextureManager::addIndexedTexture(unsigned char* image, unsigned int width,
  260. unsigned int height) {
  261. unsigned char* img = new unsigned char[width * height];
  262. for (unsigned int i = 0; i < (width * height); i++)
  263. img[i] = image[i];
  264. indexedTextures.emplace_back(img, width, height);
  265. }
  266. void TextureManager::prepare() {
  267. for (int i = 0; i < indexedTextures.size(); i++) {
  268. auto tex = indexedTextures.at(i);
  269. unsigned char* img = std::get<0>(tex);
  270. unsigned int width = std::get<1>(tex);
  271. unsigned int height = std::get<2>(tex);
  272. unsigned char* image = new unsigned char[width * height * 4];
  273. for (unsigned int i = 0; i < (width * height); i++) {
  274. auto col = getPalette(img[i]);
  275. image[i * 4] = col.x * 255;
  276. image[(i * 4) + 1] = col.y * 255;
  277. image[(i * 4) + 2] = col.z * 255;
  278. image[(i * 4) + 3] = col.w * 255;
  279. }
  280. delete [] img;
  281. loadBufferSlot(image, width, height, ColorMode::RGBA, 32, TextureStorage::GAME, i, true);
  282. }
  283. }
  284. int TextureManager::loadImage(std::string filename, TextureStorage s, int slot) {
  285. if (stringEndsWith(filename, ".pcx")) {
  286. return loadPCX(filename, s, slot);
  287. } else {
  288. int x, y, n;
  289. unsigned char* data = stbi_load(filename.c_str(), &x, &y, &n, 0);
  290. if (data) {
  291. if ((n < 3) || (n > 4)) {
  292. Log::get(LOG_ERROR) << "Image \"" << filename << "\" has unsupported format ("
  293. << n << ")!" << Log::endl;
  294. stbi_image_free(data);
  295. return -2;
  296. }
  297. int id = loadBufferSlot(data, x, y, (n == 3) ? ColorMode::RGB : ColorMode::RGBA,
  298. (n == 3) ? 24 : 32, s, slot);
  299. stbi_image_free(data);
  300. return id;
  301. } else {
  302. Log::get(LOG_ERROR) << "Can't load image \"" << filename << "\"!" << Log::endl;
  303. return -1;
  304. }
  305. }
  306. }
  307. int TextureManager::loadPCX(std::string filename, TextureStorage s, int slot) {
  308. int error = pcxCheck(filename.c_str());
  309. if (!error) {
  310. unsigned char* image;
  311. unsigned int w, h, bpp;
  312. ColorMode c;
  313. error = pcxLoad(filename.c_str(), &image, &w, &h, &c, &bpp);
  314. if (!error) {
  315. unsigned char* image2 = scaleBuffer(image, &w, &h, bpp);
  316. if (image2) {
  317. delete [] image;
  318. image = image2;
  319. }
  320. int id = loadBufferSlot(image, w, h, c, bpp, s, slot);
  321. delete [] image;
  322. return id;
  323. }
  324. return -5;
  325. }
  326. return -4;
  327. }
  328. std::vector<unsigned int>& TextureManager::getIds(TextureStorage s) {
  329. if (s == TextureStorage::GAME)
  330. return mTextureIdsGame;
  331. else
  332. return mTextureIdsSystem;
  333. }
  334. std::vector<int>& TextureManager::getUnits(TextureStorage s) {
  335. if (s == TextureStorage::GAME)
  336. return gameUnits;
  337. else
  338. return systemUnits;
  339. }
  340. void TextureManager::display() {
  341. if (ImGui::CollapsingHeader("Texture Viewer")) {
  342. static bool game = Game::isLoaded();
  343. static int index = 0;
  344. ImGui::SliderInt("##texslide", &index, 0, TextureManager::numTextures(
  345. game ? TextureStorage::GAME : TextureStorage::SYSTEM) - 1);
  346. ImGui::SameLine();
  347. if (ImGui::Button("+##texplus", ImVec2(0, 0), true)) {
  348. if (index < (numTextures(
  349. game ? TextureStorage::GAME : TextureStorage::SYSTEM) - 1))
  350. index++;
  351. else
  352. index = 0;
  353. }
  354. ImGui::SameLine();
  355. if (ImGui::Button("-##texminus", ImVec2(0, 0), true)) {
  356. if (index > 0)
  357. index--;
  358. else
  359. index = numTextures(
  360. game ? TextureStorage::GAME : TextureStorage::SYSTEM) - 1;
  361. }
  362. if ((numTextures(TextureStorage::GAME) > 0)) {
  363. ImGui::SameLine();
  364. ImGui::Checkbox("Game##texgame", &game);
  365. } else {
  366. game = false;
  367. }
  368. if (index >= numTextures(game ? TextureStorage::GAME : TextureStorage::SYSTEM)) {
  369. index = numTextures(game ? TextureStorage::GAME : TextureStorage::SYSTEM) - 1;
  370. if (index < 0) {
  371. game = false;
  372. index = 0;
  373. }
  374. }
  375. auto bm = getBufferManager(index, game ? TextureStorage::GAME
  376. : TextureStorage::SYSTEM);
  377. ImGui::Image(bm, ImVec2(ImGui::GetColumnWidth() * 2 / 3, ImGui::GetColumnWidth() * 2 / 3));
  378. }
  379. if (ImGui::CollapsingHeader("Textile Viewer")) {
  380. if (numTiles() > 0) {
  381. static int index = 0;
  382. ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
  383. ImGui::SliderInt("##tileslide", &index, 0, numTiles() - 1);
  384. ImGui::PopItemWidth();
  385. ImGui::SameLine();
  386. if (ImGui::Button("+##tileplus", ImVec2(0, 0), true)) {
  387. if (index < (numTiles() - 1))
  388. index++;
  389. else
  390. index = 0;
  391. }
  392. ImGui::SameLine();
  393. if (ImGui::Button("-##tileminus", ImVec2(0, 0), true)) {
  394. if (index > 0)
  395. index--;
  396. else
  397. index = numTiles() - 1;
  398. }
  399. if (index >= numTiles())
  400. index = 0;
  401. auto& tile = getTile(index);
  402. auto bm = getBufferManager(tile.getTexture(), TextureStorage::GAME);
  403. ImVec2 size(ImGui::GetColumnWidth() * 2 / 3, ImGui::GetColumnWidth() * 2 / 3);
  404. auto uvA = tile.getUV(0);
  405. auto uvB = tile.getUV(2);
  406. ImVec2 uv1(uvA.x, uvA.y);
  407. ImVec2 uv2(uvB.x, uvB.y);
  408. ImGui::Image(bm, size, uv1, uv2);
  409. } else {
  410. ImGui::Text("No textiles are currently loaded...!");
  411. }
  412. }
  413. if (ImGui::CollapsingHeader("Animated Textile Viewer")) {
  414. if (numAnimatedTiles() > 0) {
  415. static int index = 0;
  416. static int tile = getFirstTileAnimation(index);
  417. if (ImGui::SliderInt("##animslide", &index, 0, numAnimatedTiles() - 1)) {
  418. tile = getFirstTileAnimation(index);
  419. }
  420. ImGui::SameLine();
  421. if (ImGui::Button("+##animplus", ImVec2(0, 0), true)) {
  422. if (index < (numAnimatedTiles() - 1))
  423. index++;
  424. else
  425. index = 0;
  426. tile = getFirstTileAnimation(index);
  427. }
  428. ImGui::SameLine();
  429. if (ImGui::Button("-##animminus", ImVec2(0, 0), true)) {
  430. if (index > 0)
  431. index--;
  432. else
  433. index = numAnimatedTiles() - 1;
  434. tile = getFirstTileAnimation(index);
  435. }
  436. if (index >= numAnimatedTiles()) {
  437. index = 0;
  438. tile = getFirstTileAnimation(index);
  439. }
  440. int next = getNextTileAnimation(index, tile);
  441. if (next == -1) {
  442. index = 0;
  443. tile = getFirstTileAnimation(index);
  444. }
  445. ImGui::SameLine();
  446. ImGui::Text("%d", tile);
  447. auto& t = getTile(tile);
  448. auto bm = getBufferManager(t.getTexture(), TextureStorage::GAME);
  449. ImVec2 size(ImGui::GetColumnWidth() * 2 / 3, ImGui::GetColumnWidth() * 2 / 3);
  450. auto uvA = t.getUV(0);
  451. auto uvB = t.getUV(2);
  452. ImVec2 uv1(uvA.x, uvA.y);
  453. ImVec2 uv2(uvB.x, uvB.y);
  454. ImGui::Image(bm, size, uv1, uv2);
  455. static int fr = 0;
  456. if (fr > 0) {
  457. fr--;
  458. } else {
  459. fr = RunTime::getFPS() / 5;
  460. tile = next;
  461. }
  462. } else {
  463. ImGui::Text("No animated textures are currently loaded...!");
  464. }
  465. }
  466. if (ImGui::CollapsingHeader("Sprite Sequence Viewer")) {
  467. if (getWorld().sizeSprite() <= 0) {
  468. ImGui::Text("Please load a level containing sprites!");
  469. } else {
  470. static int index = 0;
  471. static int sprite = 0;
  472. if (ImGui::SliderInt("##spriteslide", &index, 0, getWorld().sizeSpriteSequence() - 1)) {
  473. sprite = 0;
  474. }
  475. ImGui::SameLine();
  476. if (ImGui::Button("+##spriteplus", ImVec2(0, 0), true)) {
  477. if (index < (getWorld().sizeSpriteSequence() - 1))
  478. index++;
  479. else
  480. index = 0;
  481. sprite = 0;
  482. }
  483. ImGui::SameLine();
  484. if (ImGui::Button("-##spriteminus", ImVec2(0, 0), true)) {
  485. if (index > 0)
  486. index--;
  487. else
  488. index = getWorld().sizeSpriteSequence() - 1;
  489. sprite = 0;
  490. }
  491. if (index >= getWorld().sizeSpriteSequence()) {
  492. index = 0;
  493. sprite = 0;
  494. }
  495. if (sprite >= getWorld().getSpriteSequence(index).size()) {
  496. sprite = 0;
  497. }
  498. ImGui::SameLine();
  499. ImGui::Text("Sprite %d/%d", sprite + 1, getWorld().getSpriteSequence(index).size());
  500. auto& s = getWorld().getSprite(getWorld().getSpriteSequence(index).getStart() + sprite);
  501. auto bm = getBufferManager(s.getTexture(), TextureStorage::GAME);
  502. ImVec2 size(ImGui::GetColumnWidth() * 2 / 3, ImGui::GetColumnWidth() * 2 / 3);
  503. auto uv = s.getUVs();
  504. ImVec2 uv1(uv.x, uv.w);
  505. ImVec2 uv2(uv.z, uv.y);
  506. ImGui::Image(bm, size, uv1, uv2);
  507. static int fr = 0;
  508. if (fr > 0) {
  509. fr--;
  510. } else {
  511. fr = RunTime::getFPS() / 10;
  512. if (sprite < (getWorld().getSpriteSequence(index).size() - 1))
  513. sprite++;
  514. else
  515. sprite = 0;
  516. }
  517. }
  518. }
  519. }