gcsx_world.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* GCSx
  2. ** WORLD.H
  3. **
  4. ** World storage
  5. ** Non-editor 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_WORLD_H_
  25. #define __GCSx_WORLD_H_
  26. class World : virtual public LoadOnly {
  27. public:
  28. typedef std::map<int, class Scene*> SceneIndex;
  29. typedef hash_map<const char*, class Scene*, hash<const char*>, hash_eqstr> SceneMap;
  30. typedef std::map<int, class TileSet*> TileSetIndex;
  31. typedef hash_map<const char*, class TileSet*, hash<const char*>, hash_eqstr> TileSetMap;
  32. typedef std::map<int, class AnimGroup*> AnimGroupIndex;
  33. typedef hash_map<const char*, class AnimGroup*, hash<const char*>, hash_eqstr> AnimGroupMap;
  34. typedef std::map<int, class Script*> ScriptIndex;
  35. typedef hash_map<const char*, class Script*, hash<const char*>, hash_eqstr> ScriptMap;
  36. typedef hash_map<const char*, std::pair<int,const char*>, hash<const char*>, hash_eqstr> GlobalMap;
  37. protected:
  38. // World title
  39. std::string title;
  40. // Our file
  41. std::string* filename;
  42. class WorldFileLoad* file;
  43. // Our resources, indexed by lowercase name and by id
  44. SceneIndex scenesById;
  45. SceneMap scenesByName;
  46. TileSetIndex tilesetsById;
  47. TileSetMap tilesetsByName;
  48. AnimGroupIndex animgroupsById;
  49. AnimGroupMap animgroupsByName;
  50. ScriptIndex scriptsById;
  51. ScriptMap scriptsByNameCode;
  52. ScriptMap scriptsByNameLib;
  53. ScriptMap scriptsByNameNote;
  54. // Used for linking during gameplay, and for verifying global variable
  55. // consistency across scripts; should not be cleared during gameplay.
  56. // (char pointers are allocated specifically to place in this map)
  57. GlobalMap globalLinks;
  58. int globalLinksDone;
  59. int globalLinksCount;
  60. void clearGlobalLinks();
  61. // Returns # of errors; assumes all scripts are compiled
  62. int prepGlobalLinks();
  63. // World properties
  64. int startingScene; // (id number)
  65. // Used by WorldEdit
  66. World();
  67. // Deletes all objects in our resources; used in destructor or failed construct
  68. // Safe to call multiple times, but leaves World object in a state unusable except
  69. // for further destruction/cleanup
  70. void deleteCollections();
  71. public:
  72. World(const char* wFilename) throw_File; // Opens an existing world
  73. virtual ~World();
  74. // Accessors
  75. const std::string& getTitle() const { return title; }
  76. int getStartScene() const { return startingScene; }
  77. int getId() const { return 0; }
  78. int getBlockType() const { return WorldFileLoad::BLOCKTYPE_WORLDINFO; }
  79. // Add and remove from byId and byName indices
  80. // DO NOT CHANGE RESOURCE NAME WITHOUT REMOVING FIRST
  81. // (to change name, remove and readd)
  82. virtual void indexScene(Scene* addScene);
  83. virtual void deindexScene(Scene* remScene);
  84. void indexTileSet(TileSet* addTileSet);
  85. void deindexTileSet(TileSet* remTileSet);
  86. void indexAnimGroup(AnimGroup* addAnimGroup);
  87. void deindexAnimGroup(AnimGroup* remAnimGroup);
  88. void indexScript(Script* addScript);
  89. void deindexScript(Script* remScript);
  90. // Find items based on name/id or iterate sequence
  91. // Designed for runtime efficiency
  92. class Scene* findScene(const std::string& fName) const;
  93. class Scene* findScene(int fId) const;
  94. SceneIndex::const_iterator beginScene() const { return scenesById.begin(); }
  95. SceneIndex::const_iterator endScene() const { return scenesById.end(); }
  96. class TileSet* findTileSet(const std::string& fName) const;
  97. class TileSet* findTileSet(int fId) const;
  98. TileSetIndex::const_iterator beginTileSet() const { return tilesetsById.begin(); }
  99. TileSetIndex::const_iterator endTileSet() const { return tilesetsById.end(); }
  100. class AnimGroup* findAnimGroup(const std::string& fName) const;
  101. class AnimGroup* findAnimGroup(int fId) const;
  102. AnimGroupIndex::const_iterator beginAnimGroup() const { return animgroupsById.begin(); }
  103. AnimGroupIndex::const_iterator endAnimGroup() const { return animgroupsById.end(); }
  104. class Script* findScriptCode(const std::string& fName) const;
  105. class Script* findScriptLib(const std::string& fName) const;
  106. class Script* findScriptNote(const std::string& fName) const;
  107. class Script* findScript(int fId) const;
  108. ScriptIndex::const_iterator beginScript() const { return scriptsById.begin(); }
  109. ScriptIndex::const_iterator endScript() const { return scriptsById.end(); }
  110. // Used both during editing and gameplay
  111. // Returns # of errors
  112. int buildScripts();
  113. // File access
  114. void loadHeader(class FileRead* file) throw_File;
  115. virtual void loadContent(class FileRead* file);
  116. int isContentCached() const;
  117. void cacheLoad();
  118. int markLock();
  119. int markUnlock();
  120. int isLocked() const;
  121. };
  122. #endif