Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

87 строки
1.7 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://sam.zoy.org/projects/COPYING.WTFPL for more details.
  9. //
  10. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include <cstdio>
  14. #include "core.h"
  15. /*
  16. * Tiler implementation class
  17. */
  18. static class TilerData
  19. {
  20. friend class Tiler;
  21. public:
  22. TilerData()
  23. #if !FINAL_RELEASE
  24. : lasterror(-1)
  25. #endif
  26. { }
  27. private:
  28. Dict tilesets;
  29. #if !FINAL_RELEASE
  30. int lasterror;
  31. #endif
  32. }
  33. tilerdata;
  34. static TilerData * const data = &tilerdata;
  35. /*
  36. * Public Tiler class
  37. */
  38. int Tiler::Register(char const *path, int w, int h, float dilate)
  39. {
  40. int id = data->tilesets.MakeSlot(path);
  41. if (!data->tilesets.GetEntity(id))
  42. {
  43. TileSet *tileset = new TileSet(path, w, h, dilate);
  44. data->tilesets.SetEntity(id, tileset);
  45. #if !FINAL_RELEASE
  46. if (id == data->lasterror)
  47. data->lasterror = -1;
  48. #endif
  49. }
  50. return id + 1; /* ID 0 is for the empty tileset */
  51. }
  52. void Tiler::Deregister(int id)
  53. {
  54. data->tilesets.RemoveSlot(id - 1); /* ID 0 is for the empty tileset */
  55. }
  56. void Tiler::BlitTile(uint32_t code, int x, int y, int z, int o)
  57. {
  58. int id = (code >> 16) - 1; /* ID 0 is for the empty tileset */
  59. TileSet *tileset = (TileSet *)data->tilesets.GetEntity(id);
  60. #if !FINAL_RELEASE
  61. if (!tileset)
  62. {
  63. if (id != data->lasterror)
  64. fprintf(stderr, "ERROR: blitting to null tiler #%i\n", id);
  65. data->lasterror = id;
  66. return;
  67. }
  68. #endif
  69. tileset->BlitTile(code & 0xffff, x, y, z, o);
  70. }