Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
Unit.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018 DIVIDE-Studio
3 Copyright (c) 2009 Ionut Cava
4
5 This file is part of DIVIDE Framework.
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software
9 and associated documentation files (the "Software"), to deal in the Software
10 without restriction,
11 including without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so,
15 subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED,
22 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27 IN CONNECTION WITH THE SOFTWARE
28 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 */
31
32#pragma once
33#ifndef DVD_UNIT_H_
34#define DVD_UNIT_H_
35
37
38namespace Divide {
39
40class UnitComponent;
41namespace Attorney {
42 class UnitComponent;
43}
44
45FWD_DECLARE_MANAGED_CLASS(SceneGraphNode);
46
48enum class UnitType : U8 {
54 COUNT
55};
56namespace Names {
57 static const char* unitType[] = {
58 "CHARACTER", "VEHICLE", "UNKOWN"
59 };
60}
61
62namespace TypeUtil {
63 [[nodiscard]] const char* UnitTypeToString(UnitType unitType) noexcept;
64 [[nodiscard]] UnitType StringToUnitType(const string& name);
65}
66
68class Unit : public GUIDWrapper {
69 public:
72
73 public:
74
75 explicit Unit(UnitType type);
76
79 [[nodiscard]] virtual bool moveTo(const vec3<F32>& targetPosition, const U64 deltaTimeUS );
80 [[nodiscard]] virtual bool moveToX(F32 targetPosition, const U64 deltaTimeUS );
81 [[nodiscard]] virtual bool moveToY(F32 targetPosition, const U64 deltaTimeUS );
82 [[nodiscard]] virtual bool moveToZ(F32 targetPosition, const U64 deltaTimeUS );
84 [[nodiscard]] virtual bool teleportTo(const vec3<F32>& targetPosition);
85
88 [[nodiscard]] const vec3<F32>& getCurrentPosition() const {
89 return _currentPosition;
90 }
92 [[nodiscard]] const vec3<F32>& getTargetPosition() const {
94 }
97 virtual void setMovementSpeed(const F32 movementSpeed) {
98 _moveSpeed = movementSpeed;
99 CLAMP<F32>(_moveSpeed, 0.0f, 100.0f);
100 }
102 virtual void setAcceleration(const F32 acceleration) {
103 _acceleration = acceleration;
104 CLAMP<F32>(_moveSpeed, 0.0f, 100.0f);
105 }
107 [[nodiscard]] virtual F32 getMovementSpeed() const { return _moveSpeed; }
109 [[nodiscard]] virtual F32 getAcceleration() const { return _acceleration; }
111 void setMovementTolerance(const F32 movementTolerance) {
112 _moveTolerance = std::max(0.1f, movementTolerance);
113 }
115 [[nodiscard]] F32 getMovementTolerance() const { return _moveTolerance; }
117 [[nodiscard]] SceneGraphNode* getBoundNode() const { return _node; }
118
119 virtual void setAttribute(U32 attributeID, I32 initialValue);
120 [[nodiscard]] virtual I32 getAttribute(U32 attributeID) const;
121
123
124 protected:
125 virtual void setParentNode(SceneGraphNode* node);
126
127 protected:
141};
142
143namespace Attorney {
145 private:
146 static void setParentNode(Unit* unit, SceneGraphNode* node) {
147 unit->setParentNode(node);
148 }
150 };
151}
152} // namespace Divide
153
154#endif //DVD_UNIT_H_
#define FWD_DECLARE_MANAGED_CLASS(T)
static void setParentNode(Unit *unit, SceneGraphNode *node)
Definition: Unit.h:146
Utility class that adds basic GUID management to objects.
Definition: GUIDWrapper.h:44
Unit interface.
Definition: Unit.h:68
F32 _moveSpeed
Movement speed (meters per second)
Definition: Unit.h:129
const vec3< F32 > & getTargetPosition() const
Get the unit's target coordinates in the world.
Definition: Unit.h:92
virtual bool teleportTo(const vec3< F32 > &targetPosition)
teleportTo instantly places the unit at the desired position
Definition: Unit.cpp:170
virtual void setAttribute(U32 attributeID, I32 initialValue)
Definition: Unit.cpp:197
virtual void setMovementSpeed(const F32 movementSpeed)
Definition: Unit.h:97
vec3< F32 > _currentPosition
Unit position in world.
Definition: Unit.h:135
virtual bool moveToZ(F32 targetPosition, const U64 deltaTimeUS)
Move along the Z axis.
Definition: Unit.cpp:152
PROPERTY_RW(UnitType, type, UnitType::COUNT)
F32 getMovementTolerance() const
Get the units current movement tolerance.
Definition: Unit.h:115
virtual void setAcceleration(const F32 acceleration)
Set the unit's acceleration in metres per second squared.
Definition: Unit.h:102
SceneGraphNode * _node
Definition: Unit.h:138
SharedMutex _unitUpdateMutex
Definition: Unit.h:140
F32 _acceleration
Acceleration (meters per second squared.
Definition: Unit.h:131
virtual bool moveTo(const vec3< F32 > &targetPosition, const U64 deltaTimeUS)
Definition: Unit.cpp:42
virtual void setParentNode(SceneGraphNode *node)
Definition: Unit.cpp:35
const vec3< F32 > & getCurrentPosition() const
Definition: Unit.h:88
F32 _moveTolerance
acceptable distance from target
Definition: Unit.h:133
virtual bool moveToX(F32 targetPosition, const U64 deltaTimeUS)
Move along the X axis.
Definition: Unit.cpp:118
void setMovementTolerance(const F32 movementTolerance)
Set destination tolerance.
Definition: Unit.h:111
virtual I32 getAttribute(U32 attributeID) const
Definition: Unit.cpp:201
hashMap< U32, I32 > AttributeMap
Definition: Unit.h:70
virtual F32 getMovementSpeed() const
Get the unit's current movement speed.
Definition: Unit.h:107
SceneGraphNode * getBoundNode() const
Get bound node.
Definition: Unit.h:117
AttributeMap _attributes
Definition: Unit.h:139
virtual F32 getAcceleration() const
Get the unit's acceleration rate.
Definition: Unit.h:109
virtual bool moveToY(F32 targetPosition, const U64 deltaTimeUS)
Move along the Y axis.
Definition: Unit.cpp:135
vec3< F32 > _currentTargetPosition
Current destination point cached.
Definition: Unit.h:137
static const char * unitType[]
Definition: Unit.h:57
const char * UnitTypeToString(UnitType unitType) noexcept
Definition: Unit.cpp:11
UnitType StringToUnitType(const string &name)
Definition: Unit.cpp:15
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
int32_t I32
uint8_t U8
UnitType
Currently supported unit types.
Definition: Unit.h:48
@ COUNT
add more types above this
@ UNIT_TYPE_VEHICLE
e.g. Cars, planes, ships etc
@ UNIT_TYPE_CHARACTER
"Living beings"
std::shared_mutex SharedMutex
Definition: SharedMutex.h:43
hashAlg::unordered_map< K, V, HashFun, Predicate > hashMap
Definition: HashMap.h:55
uint32_t U32
uint64_t U64