World.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 "Camera.h"
  25. #include "IdArray.h"
  26. #include "LinearAllocator.h"
  27. #include "PhysicsTypes.h"
  28. #include "PhysicsWorld.h"
  29. #include "PoolAllocator.h"
  30. #include "RenderWorld.h"
  31. #include "RenderWorldTypes.h"
  32. #include "SceneGraphManager.h"
  33. #include "Types.h"
  34. #include "Unit.h"
  35. #include "Vector.h"
  36. #include "WorldTypes.h"
  37. #include "SoundWorld.h"
  38. #include "EventStream.h"
  39. namespace crown
  40. {
  41. #define MAX_UNITS 65000
  42. #define MAX_CAMERAS 16
  43. struct Mesh;
  44. struct Sprite;
  45. struct Actor;
  46. struct Vector3;
  47. struct Quaternion;
  48. struct PhysicsResource;
  49. class World
  50. {
  51. public:
  52. World();
  53. ~World();
  54. WorldId id() const;
  55. void set_id(WorldId id);
  56. UnitId spawn_unit(const char* name, const Vector3& pos = Vector3::ZERO, const Quaternion& rot = Quaternion::IDENTITY);
  57. UnitId spawn_unit(UnitResource* ur, const Vector3& pos, const Quaternion& rot);
  58. void destroy_unit(UnitId id);
  59. void reload_units(UnitResource* old_ur, UnitResource* new_ur);
  60. uint32_t num_units() const;
  61. void link_unit(UnitId child, UnitId parent, int32_t node);
  62. void unlink_unit(UnitId unit);
  63. Unit* lookup_unit(UnitId unit);
  64. Camera* lookup_camera(CameraId camera);
  65. void update(float dt);
  66. void render(Camera* camera);
  67. CameraId create_camera(SceneGraph& sg, int32_t node);
  68. void destroy_camera(CameraId id);
  69. SoundInstanceId play_sound(const char* name, bool loop = false, float volume = 1.0f, const Vector3& pos = Vector3::ZERO, float range = 50.0f);
  70. void stop_sound(SoundInstanceId sound);
  71. void link_sound(SoundInstanceId sound, Unit* unit, int32_t node);
  72. void set_listener_pose(const Matrix4x4& pose);
  73. void set_sound_position(SoundInstanceId sound, const Vector3& pos);
  74. void set_sound_range(SoundInstanceId sound, float range);
  75. void set_sound_volume(SoundInstanceId sound, float vol);
  76. GuiId create_window_gui(const char* name);
  77. GuiId create_world_gui(const Matrix4x4 pose, const uint32_t width, const uint32_t height);
  78. void destroy_gui(GuiId id);
  79. Gui* lookup_gui(GuiId id);
  80. SceneGraphManager* scene_graph_manager();
  81. RenderWorld* render_world();
  82. PhysicsWorld* physics_world();
  83. SoundWorld* sound_world();
  84. private:
  85. PoolAllocator m_unit_pool;
  86. PoolAllocator m_camera_pool;
  87. IdArray<MAX_UNITS, Unit*> m_units;
  88. IdArray<MAX_CAMERAS, Camera*> m_cameras;
  89. SceneGraphManager m_scenegraph_manager;
  90. RenderWorld m_render_world;
  91. PhysicsWorld m_physics_world;
  92. SoundWorld* m_sound_world;
  93. WorldId m_id;
  94. EventStream m_events;
  95. };
  96. } // namespace crown