Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

118 rindas
2.4 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2013 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://www.wtfpl.net/ for more details.
  9. //
  10. #include <lol/engine-internal.h>
  11. namespace lol
  12. {
  13. /*
  14. * Tiler implementation class
  15. */
  16. static class TilerData
  17. {
  18. friend class Tiler;
  19. public:
  20. TilerData()
  21. { }
  22. private:
  23. Dict tilesets;
  24. }
  25. tilerdata;
  26. static TilerData * const data = &tilerdata;
  27. /*
  28. * Public Tiler class
  29. */
  30. TileSet *Tiler::Register(String const &path, ivec2 size, ivec2 count)
  31. {
  32. return Tiler::Register(path.C(), size, count);
  33. }
  34. TileSet *Tiler::Register(char const *path, ivec2 size, ivec2 count)
  35. {
  36. int id = data->tilesets.MakeSlot(path);
  37. TileSet *tileset = (TileSet *)data->tilesets.GetEntity(id);
  38. if (!tileset)
  39. {
  40. tileset = new TileSet(path, size, count);
  41. data->tilesets.SetEntity(id, tileset);
  42. }
  43. return tileset;
  44. }
  45. TileSet *Tiler::Register(String const &path)
  46. {
  47. return Tiler::Register(path.C());
  48. }
  49. TileSet *Tiler::Register(char const *path)
  50. {
  51. int id = data->tilesets.MakeSlot(path);
  52. TileSet *tileset = (TileSet *)data->tilesets.GetEntity(id);
  53. if (!tileset)
  54. {
  55. tileset = new TileSet(path);
  56. data->tilesets.SetEntity(id, tileset);
  57. }
  58. return tileset;
  59. }
  60. TileSet *Tiler::Register(String const &path, Image* image, ivec2 size, ivec2 count)
  61. {
  62. return Tiler::Register(path.C(), image, size, count);
  63. }
  64. TileSet *Tiler::Register(char const *path, Image* image, ivec2 size, ivec2 count)
  65. {
  66. int id = data->tilesets.MakeSlot(path);
  67. TileSet *tileset = (TileSet *)data->tilesets.GetEntity(id);
  68. if (!tileset)
  69. {
  70. tileset = new TileSet(path, image, size, count);
  71. data->tilesets.SetEntity(id, tileset);
  72. }
  73. return tileset;
  74. }
  75. TileSet *Tiler::Register(String const &path, Image* image)
  76. {
  77. return Tiler::Register(path.C(), image);
  78. }
  79. TileSet *Tiler::Register(char const *path, Image* image)
  80. {
  81. int id = data->tilesets.MakeSlot(path);
  82. TileSet *tileset = (TileSet *)data->tilesets.GetEntity(id);
  83. if (!tileset)
  84. {
  85. tileset = new TileSet(path, image);
  86. data->tilesets.SetEntity(id, tileset);
  87. }
  88. return tileset;
  89. }
  90. void Tiler::Deregister(TileSet *tileset)
  91. {
  92. data->tilesets.RemoveSlot(tileset);
  93. }
  94. } /* namespace lol */