| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- /*
- Copyright (c) 2013 Daniele Bartolini, Michele Rossi
- Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
- Permission is hereby granted, free of charge, to any person
- obtaining a copy of this software and associated documentation
- files (the "Software"), to deal in the Software without
- restriction, including without limitation the rights to use,
- copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the
- Software is furnished to do so, subject to the following
- conditions:
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- OTHER DEALINGS IN THE SOFTWARE.
- */
- #pragma once
- #include "Types.h"
- #include "HeapAllocator.h"
- #include "IdArray.h"
- #include "LinearAllocator.h"
- #include "Unit.h"
- #include "Camera.h"
- #include "Vector.h"
- #include "RenderWorld.h"
- #include "PhysicsWorld.h"
- #include "SoundRenderer.h"
- #include "PoolAllocator.h"
- #include "SceneGraphManager.h"
- #include "PhysicsTypes.h"
- namespace crown
- {
- #define MAX_UNITS 65000
- #define MAX_SOUNDS 64
- #define MAX_CAMERAS 16
- typedef Id UnitId;
- typedef Id CameraId;
- typedef Id MeshId;
- typedef Id SoundId;
- typedef Id SpriteId;
- typedef Id ActorId;
- struct Sound
- {
- SoundBufferId buffer;
- SoundSourceId source;
-
- Matrix4x4 world;
- float volume;
- float range;
- bool loop : 1;
- bool playing : 1;
- };
- struct UnitToSound
- {
- UnitId unit;
- SoundId sound;
- int32_t node;
- };
- class Mesh;
- class Sprite;
- class Actor;
- class Vector3;
- class Quaternion;
- class World
- {
- public:
- World();
- UnitId spawn_unit(const char* name, const Vector3& pos = Vector3::ZERO, const Quaternion& rot = Quaternion(Vector3(0, 1, 0), 0.0f));
- void destroy_unit(UnitId id);
- uint32_t num_units() const;
- void link_unit(UnitId child, UnitId parent, int32_t node);
- void unlink_unit(UnitId unit);
- Unit* lookup_unit(UnitId unit);
- Camera* lookup_camera(CameraId camera);
- Mesh* lookup_mesh(MeshId mesh);
- Sprite* lookup_sprite(SpriteId sprite);
- Actor* lookup_actor(ActorId actor);
- void update(float dt);
- void render(Camera* camera);
- CameraId create_camera(SceneGraph& sg, int32_t node);
- void destroy_camera(CameraId id);
- MeshId create_mesh(ResourceId id, SceneGraph& sg, int32_t node);
- void destroy_mesh(MeshId id);
- SpriteId create_sprite(ResourceId id, SceneGraph& sg, int32_t node);
- void destroy_sprite(SpriteId id);
- ActorId create_actor(ActorType::Enum type);
- void destroy_actor(ActorId id);
- SoundId play_sound(const char* name, const bool loop = false, const float volume = 1.0f, const Vector3& pos = Vector3::ZERO, const float range = 50.0f);
- void stop_sound(SoundId sound);
- void link_sound(SoundId sound, Unit* unit, int32_t node);
- void set_listener(const Vector3& pos, const Vector3& vel, const Vector3& or_up, const Vector3& or_at);
- void set_sound_position(SoundId sound, const Vector3& pos);
- void set_sound_range(SoundId sound, const float range);
- void set_sound_volume(SoundId sound, const float vol);
- RenderWorld& render_world();
- PhysicsWorld* physics_world();
- private:
- PoolAllocator m_unit_pool;
- PoolAllocator m_camera_pool;
- IdArray<MAX_UNITS, Unit*> m_units;
- IdArray<MAX_CAMERAS, Camera*> m_cameras;
- IdArray<MAX_SOUNDS, Sound> m_sounds;
- SceneGraphManager m_scenegraph_manager;
- // Connections
- List<UnitToSound> m_unit_to_sound;
- RenderWorld m_render_world;
- PhysicsWorld m_physics_world;
- };
- } // namespace crown
|