UnitCompiler.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. Copyright (c) 2013 Daniele Bartolini, Michele Rossi
  3. Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  4. Permission is hereby granted, free of charge, to any person
  5. obtaining a copy of this software and associated documentation
  6. files (the "Software"), to deal in the Software without
  7. restriction, including without limitation the rights to use,
  8. copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the
  10. Software is furnished to do so, subject to the following
  11. conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  16. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #pragma once
  24. #include "Compiler.h"
  25. #include "Resource.h"
  26. #include "UnitResource.h"
  27. #include "List.h"
  28. #include "Types.h"
  29. #include "Matrix4x4.h"
  30. #include "Quaternion.h"
  31. #include "JSONParser.h"
  32. namespace crown
  33. {
  34. struct GraphNode
  35. {
  36. StringId32 name;
  37. StringId32 parent;
  38. Vector3 position;
  39. Quaternion rotation;
  40. };
  41. struct GraphNodeDepth
  42. {
  43. StringId32 name;
  44. uint32_t index;
  45. uint32_t depth;
  46. bool operator()(const GraphNodeDepth& a, const GraphNodeDepth& b)
  47. {
  48. return a.depth < b.depth;
  49. }
  50. };
  51. class CE_EXPORT UnitCompiler : public Compiler
  52. {
  53. public:
  54. UnitCompiler();
  55. size_t compile_impl(Filesystem& fs, const char* resource_path);
  56. void write_impl(File* out_file);
  57. void parse_node(JSONElement e);
  58. void parse_camera(JSONElement e);
  59. void parse_renderable(JSONElement e);
  60. void parse_actor(JSONElement e);
  61. uint32_t compute_link_depth(GraphNode& node);
  62. uint32_t find_node_index(StringId32 name);
  63. int32_t find_node_parent_index(StringId32 name);
  64. private:
  65. List<GraphNode> m_nodes;
  66. List<GraphNodeDepth> m_node_depths;
  67. List<UnitCamera> m_cameras;
  68. List<UnitRenderable> m_renderables;
  69. List<UnitActor> m_actors;
  70. };
  71. } // namespace crown