gcsx_scene.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* GCSx
  2. ** SCENE.H
  3. **
  4. ** Scenes
  5. ** Doesn't include any editor-only functionality
  6. */
  7. /*****************************************************************************
  8. ** Copyright (C) 2003-2006 Janson
  9. **
  10. ** This program is free software; you can redistribute it and/or modify
  11. ** it under the terms of the GNU General Public License as published by
  12. ** the Free Software Foundation; either version 2 of the License, or
  13. ** (at your option) any later version.
  14. **
  15. ** This program is distributed in the hope that it will be useful,
  16. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ** GNU General Public License for more details.
  19. **
  20. ** You should have received a copy of the GNU General Public License
  21. ** along with this program; if not, write to the Free Software
  22. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
  23. *****************************************************************************/
  24. #ifndef __GCSx_SCENE_H_
  25. #define __GCSx_SCENE_H_
  26. class Scene : virtual public LoadOnly {
  27. protected:
  28. // Is the scene cached to our file and not in memory?
  29. int cached;
  30. FileRead* cacheFile;
  31. int lockCount;
  32. int doLock(int play) throw_File;
  33. int doUnlock(int play);
  34. // Name of scene, where it's located
  35. std::string name;
  36. std::string nameL;
  37. class World* world;
  38. // Numeric ID- computer-generated- unique to world- nonzero
  39. int id;
  40. // Layers
  41. class Layer* layers[MAX_LAYERS]; // CACHEABLE
  42. int layerCount;
  43. // NON-EDITOR, GAMEPLAY DATA (not saved by editor)
  44. // Viewpoint in pixels (not bounded)
  45. // positive scrolls left/up (view moves right/down)
  46. int vpX;
  47. int vpY;
  48. // Entity lookup by name- this scene only
  49. EntityMap entitysByName;
  50. // Entitys in processing order, for this scene only
  51. EntityOrder entitysByOrder;
  52. public:
  53. // Id must be unique; use ID of 0 if we're going to load anyways
  54. Scene(class World* myWorld, int myId = 0); // Starts with default settings
  55. virtual ~Scene();
  56. // Find one of our layers; returns < 0 for not found (expects lowercase name)
  57. // These are not designed to necessarily be efficient enough for runtime
  58. int findLayer(const std::string& fName) const;
  59. int findLayer(const class Layer* fLayer) const;
  60. // Accessors
  61. const std::string& getName() const { return name; }
  62. const std::string& getNameL() const { return nameL; }
  63. const class World* getWorld() const { return world; }
  64. class World* getWorld() { return world; }
  65. int getLayerCount() const { return layerCount; }
  66. int getId() const { return id; }
  67. int getBlockType() const { return WorldFileLoad::BLOCKTYPE_SCENE; }
  68. // (asserts pos is valid)
  69. // markLock() this scene as long as you're using the layer for nontrivial purposes
  70. const class Layer* getLayer(int pos) const;
  71. class Layer* getLayer(int pos);
  72. // File access
  73. virtual void loadHeader(FileRead* file) throw_File;
  74. void loadContent(FileRead* file);
  75. int isContentCached() const;
  76. void cacheLoad() throw_File;
  77. // (lock and unlock also recursively affect all layer resources)
  78. // 'play' versions don't retain source tileset data- only textures
  79. int markLock() throw_File;
  80. int markLockPlay() throw_File;
  81. int markUnlock();
  82. int markUnlockPlay();
  83. int isLocked() const;
  84. // GAMEPLAY
  85. // working with entities
  86. // First places in all indices including world's- call on create/delete
  87. // Also activates/deactivates if we're locked
  88. void indexEntity(Entity* addEntity);
  89. void deindexEntity(Entity* remEntity);
  90. // Second modifies priority order only- use only when just changing priority
  91. void orderEntity(Entity* addEntity);
  92. void deorderEntity(Entity* remEntity);
  93. // Third modifies name order only- use only when just changing name
  94. void nameEntity(Entity* addEntity);
  95. void denameEntity(Entity* remEntity);
  96. // Since multiple can match, use this for a range
  97. // Properly handles and optimized for "*" and "string*" wildcards
  98. // Other wildcard strings will work but you will have to compare
  99. // each match individually as well. ASSUMES fMatch IS LOWERCASED.
  100. void matchEntity(const char* fMatch, EntityMap::const_iterator& first, EntityMap::const_iterator& last) const;
  101. // do initial spawning on every layer
  102. void spawnScene();
  103. // draw current scene (layers, sprites, and all)
  104. void draw();
  105. // run all entities in order
  106. void cycle();
  107. // Viewpoint
  108. int viewX() const { return vpX; }
  109. int viewY() const { return vpY; }
  110. void viewX(int newX) { vpX = newX; }
  111. void viewY(int newY) { vpY = newY; }
  112. };
  113. #endif