Voxellancer  0.3
A game about voxels in space
 All Classes Functions Pages
worldobject.h
1 #pragma once
2 
3 #include <list>
4 #include <memory>
5 
6 #include "scripting/scriptable.h"
7 
8 #include "utils/handle/handle.h"
9 
10 #include "voxel/voxelcluster.h"
11 
12 class CollisionDetector;
13 class EngineVoxel;
14 class HardpointVoxel;
15 class CockpitVoxel;
16 class FuelVoxel;
17 class CollisionFilter;
18 class Physics;
19 class ObjectInfo;
20 class VoxelCollision;
22 
23 enum class SpawnState {
24  None,
25  SpawnScheduled,
26  Spawned,
27  Rejected,
28  RemovalScheduled,
29 };
30 
31 enum class WorldObjectType {
32  Ship = 1 << 0,
33  Bullet = 1 << 1,
34  Rocket = 1 << 2,
35  Other = 1 << 3
36 };
37 
43 class WorldObject : public VoxelCluster, public Scriptable {
44 public:
45  WorldObject();
46  WorldObject(const Transform& transform);
47  virtual ~WorldObject();
48 
49  virtual WorldObjectType objectType() const;
50 
51  SpawnState spawnState() const;
52  void setSpawnState(SpawnState spawnState);
53 
54  CollisionFilter& collisionFilter();
55  void setCollisionFilter(CollisionFilter* collisionFilter);
56 
57  CollisionDetector& collisionDetector();
58 
59  Physics& physics();
60  const Physics& physics() const;
61 
62  ObjectInfo& objectInfo();
63 
64  WorldObjectComponents& components();
65  const WorldObjectComponents& components() const;
66 
67  virtual void update(float deltaSec);
68 
69  virtual void addVoxel(Voxel* voxel) override;
70  virtual void removeVoxel(Voxel* voxel) override;
71 
72  Voxel* crucialVoxel();
73  void setCrucialVoxel(const glm::ivec3& cell);
74  bool isCrucialVoxelDestroyed();
75 
76  void updateTransformAndGeode(const glm::vec3& position, const glm::quat& orientation);
77 
78  virtual void onCollision();
79  virtual void onSpawnFail();
80  //virtual void onWrecked();
81 
82  Handle<WorldObject>& handle();
83 
84  float collisionFieldOfDamage() const;
85  void setCollisionFieldOfDamage(float collisionFieldOfDamage);
86 
87  virtual bool passiveForCollisionDetection();
88 
89 
90 protected:
91  std::unique_ptr<CollisionFilter> m_collisionFilter;
92  std::unique_ptr<CollisionDetector> m_collisionDetector;
93  std::unique_ptr<Physics> m_physics;
94  std::unique_ptr<ObjectInfo> m_objectInfo;
95  std::unique_ptr<WorldObjectComponents> m_components;
96 
97  Handle<WorldObject> m_handle;
98  Voxel* m_crucialVoxel;
99  bool m_crucialVoxelDestroyed;
100  float m_collisionFieldOfDamage;
101  SpawnState m_spawnState;
102 };
103 
Definition: collisionfilter.h:9
Definition: worldobject.h:43
Definition: voxelcluster.h:21
Definition: collisiondetector.h:19
Definition: transform.h:9
Definition: rocket.h:22
Definition: fuelvoxel.h:6
Definition: objectinfo.h:8
Definition: voxel.h:15
Definition: physics.h:19
Definition: voxelcollision.h:22
Definition: worldobjectcomponents.h:22
Definition: bullet.h:12
Definition: hardpointvoxel.h:10
Definition: cockpitvoxel.h:6
Definition: scriptable.h:4
Definition: ship.h:23