GPBFile.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * GPBFile.h
  3. */
  4. #ifndef GPBFILE_H_
  5. #define GPBFILE_H_
  6. #include <iostream>
  7. #include <list>
  8. #include "FileIO.h"
  9. #include "Object.h"
  10. #include "Scene.h"
  11. #include "Node.h"
  12. #include "Camera.h"
  13. #include "Light.h"
  14. #include "Mesh.h"
  15. #include "Reference.h"
  16. #include "ReferenceTable.h"
  17. #include "Animations.h"
  18. #include "Animation.h"
  19. #include "AnimationChannel.h"
  20. namespace gameplay
  21. {
  22. /**
  23. * Increment the version number when making a change that break binary compatibility.
  24. * [0] is major, [1] is minor.
  25. */
  26. const unsigned char VERSION[2] = {1, 0};
  27. /**
  28. * The GamePlay Binary file class handles writing the GamePlay Binary file.
  29. */
  30. class GPBFile
  31. {
  32. public:
  33. /**
  34. * Constructor.
  35. */
  36. GPBFile(void);
  37. /**
  38. * Destructor.
  39. */
  40. ~GPBFile(void);
  41. /**
  42. * Saves the GPBFile as a binary file at filepath.
  43. *
  44. * @param filepath The file name and path to save to.
  45. */
  46. void saveBinary(const std::string& filepath);
  47. /**
  48. * Saves the GPBFile as a text file at filepath. Useful for debugging.
  49. *
  50. * @param filepath The file name and path to save to.
  51. */
  52. void saveText(const std::string& filepath);
  53. void add(Object* obj);
  54. void addScene(Scene* scene);
  55. void addCamera(Camera* camera);
  56. void addLight(Light* light);
  57. void addMesh(Mesh* mesh);
  58. void addNode(Node* node);
  59. void addAnimation(Animation* animation);
  60. /**
  61. * Adds the given object to the ref table.
  62. */
  63. void addToRefTable(Object* obj);
  64. /**
  65. * Returns the object with the given id. Returns NULL if not found.
  66. */
  67. Object* getFromRefTable(const std::string& id);
  68. /**
  69. * Returns true if the id was found in the ref table.
  70. */
  71. bool idExists(const std::string& id);
  72. Camera* getCamera(const char* id);
  73. Light* getLight(const char* id);
  74. Mesh* getMesh(const char* id);
  75. Node* getNode(const char* id);
  76. /**
  77. * Adjusts the game play binary file before it is written.
  78. */
  79. void adjust();
  80. private:
  81. FILE* _file;
  82. std::list<Object*> _objects;
  83. std::list<Camera*> _cameras;
  84. std::list<Light*> _lights;
  85. std::list<Mesh*> _geometry;
  86. std::list<Node*> _nodes;
  87. Animations _animations;
  88. bool _animationsAdded;
  89. ReferenceTable _refTable;
  90. };
  91. }
  92. #endif