Luanti 5.17.0-dev
Loading...
Searching...
No Matches
activeobject.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
7#include "irr_aabb3d.h"
8#include "irr_v3d.h"
9#include <quaternion.h>
10#include <string>
11#include <string_view>
12#include <unordered_map>
13
14
18// Obsolete stuff
19// ACTIVEOBJECT_TYPE_ITEM = 2,
20// ACTIVEOBJECT_TYPE_RAT = 3,
21// ACTIVEOBJECT_TYPE_OERKKI1 = 4,
22// ACTIVEOBJECT_TYPE_FIREFLY = 5,
23// ACTIVEOBJECT_TYPE_MOBV2 = 6,
24// End obsolete stuff
26// Special type, not stored as a static object
28// Special type, only exists as CAO
30};
31// Other types are defined in content_object.h
32
34{
35 ActiveObjectMessage(u16 id_, bool reliable_=true, std::string_view data_ = "") :
36 id(id_),
37 reliable(reliable_),
38 datastring(data_)
39 {}
40
41 void appendTo(std::string &data) const;
42
43 u16 id;
45 std::string datastring;
46};
47
60 // ^ UPDATE_NAMETAG_ATTRIBUTES deprecated since 0.4.14, removed in 5.3.0
63 // >= 5.17.0-dev
65 // When adding new commands, update Server::AsyncRunStep()
66 // to drop newer commands for older clients
67};
68
70{
78
79 v3f getPosition(v3f anim_pos) const {
80 f32 progress = dtime_passed / position.interp_duration;
81 if (progress > 1.0f || position.interp_duration == 0.0f)
82 progress = 1.0f;
83 return position.vector.getInterpolated(position.previous, progress)
84 + (position.absolute ? v3f() : anim_pos);
85 }
86
88 {
89 core::quaternion previous;
90 core::quaternion next;
91 // Redundantly store the euler angles serverside
92 // so that we can return them in the appropriate getters
94 bool absolute = false;
95 f32 interp_duration = 0.0f;
97
98 v3f getRotationEulerDeg(v3f anim_rot_euler) const {
99 core::quaternion rot;
100
101 f32 progress = dtime_passed / rotation.interp_duration;
102 if (progress > 1.0f || rotation.interp_duration == 0.0f)
103 progress = 1.0f;
104 rot.slerp(rotation.previous, rotation.next, progress);
105 if (!rotation.absolute) {
106 core::quaternion anim_rot(anim_rot_euler * core::DEGTORAD);
107 rot = rot * anim_rot; // first rotate by anim. bone rot., then rot.
108 }
109
110 v3f rot_euler;
111 rot.toEuler(rot_euler);
112 return rot_euler * core::RADTODEG;
113 }
114
116 {
117 v3f previous = v3f(1.0f);
118 v3f vector = v3f(1.0f);
119 bool absolute = false;
120 f32 interp_duration = 0.0f;
122
123 v3f getScale(v3f anim_scale) const {
124 f32 progress = dtime_passed / scale.interp_duration;
125 if (progress > 1.0f || scale.interp_duration == 0.0f)
126 progress = 1.0f;
127 return scale.vector.getInterpolated(scale.previous, progress)
128 * (scale.absolute ? v3f(1.0f) : anim_scale);
129 }
130
131 f32 dtime_passed = 0.0f;
132
134 {
135 return dtime_passed >= std::max(std::max(
136 position.interp_duration, rotation.interp_duration),
137 scale.interp_duration);
138 }
139
140 bool isIdentity() const
141 {
142 return finishedInterpolation()
143 && !position.absolute && position.vector == v3f()
144 && !rotation.absolute && rotation.next == core::quaternion()
145 && !scale.absolute && scale.vector == v3f(1.0f);
146 }
147};
148
149typedef std::unordered_map<std::string, BoneOverride> BoneOverrideMap;
150
151
152/*
153 Parent class for ServerActiveObject and ClientActiveObject
154*/
156{
157public:
158 typedef u16 object_t;
159
161 m_id(id)
162 {
163 }
164
166 {
167 return m_id;
168 }
169
171 {
172 m_id = id;
173 }
174
175 virtual ActiveObjectType getType() const = 0;
176
177
185 virtual bool getCollisionBox(aabb3f *toset) const = 0;
186
187
195 virtual bool getSelectionBox(aabb3f *toset) const = 0;
196
197
198 virtual bool collideWithObjects() const = 0;
199
200
201 virtual void setAttachment(object_t parent_id, const std::string &bone, v3f position,
202 v3f rotation, bool force_visible) {}
203 virtual void getAttachment(object_t *parent_id, std::string *bone, v3f *position,
204 v3f *rotation, bool *force_visible) const {}
205 // Detach all children
206 virtual void clearChildAttachments() {}
207 // Detach from parent
209 {
210 setAttachment(0, "", v3f(), v3f(), false);
211 }
212
213 // To be called from setAttachment() and descendants, but not manually!
214 virtual void addAttachmentChild(object_t child_id) {}
215 virtual void removeAttachmentChild(object_t child_id) {}
216
217protected:
218 object_t m_id; // 0 is invalid, "no id"
219};
std::unordered_map< std::string, BoneOverride > BoneOverrideMap
Definition activeobject.h:149
ActiveObjectCommand
Definition activeobject.h:48
@ AO_CMD_SET_TEXTURE_MOD
Definition activeobject.h:51
@ AO_CMD_OBSOLETE1
Definition activeobject.h:59
@ AO_CMD_SPAWN_INFANT
Definition activeobject.h:61
@ AO_CMD_SET_PROPERTIES
Definition activeobject.h:49
@ AO_CMD_PUNCHED
Definition activeobject.h:53
@ AO_CMD_UPDATE_POSITION
Definition activeobject.h:50
@ AO_CMD_SET_PHYSICS_OVERRIDE
Definition activeobject.h:58
@ AO_CMD_SET_ANIMATION
Definition activeobject.h:55
@ AO_CMD_SET_ANIMATION_SPEED
Definition activeobject.h:62
@ AO_CMD_ATTACH_TO
Definition activeobject.h:57
@ AO_CMD_UPDATE_ARMOR_GROUPS
Definition activeobject.h:54
@ AO_CMD_SET_BONE_POSITION
Definition activeobject.h:56
@ AO_CMD_STOP_ANIMATION
Definition activeobject.h:64
@ AO_CMD_SET_SPRITE
Definition activeobject.h:52
ActiveObjectType
Definition activeobject.h:15
@ ACTIVEOBJECT_TYPE_TEST
Definition activeobject.h:17
@ ACTIVEOBJECT_TYPE_PLAYER
Definition activeobject.h:27
@ ACTIVEOBJECT_TYPE_INVALID
Definition activeobject.h:16
@ ACTIVEOBJECT_TYPE_GENERIC
Definition activeobject.h:29
@ ACTIVEOBJECT_TYPE_LUAENTITY
Definition activeobject.h:25
virtual void clearParentAttachment()
Definition activeobject.h:208
object_t getId() const
Definition activeobject.h:165
virtual void setAttachment(object_t parent_id, const std::string &bone, v3f position, v3f rotation, bool force_visible)
Definition activeobject.h:201
virtual bool getCollisionBox(aabb3f *toset) const =0
ActiveObject(object_t id)
Definition activeobject.h:160
virtual void clearChildAttachments()
Definition activeobject.h:206
virtual void removeAttachmentChild(object_t child_id)
Definition activeobject.h:215
virtual void addAttachmentChild(object_t child_id)
Definition activeobject.h:214
virtual bool collideWithObjects() const =0
object_t m_id
Definition activeobject.h:218
void setId(object_t id)
Definition activeobject.h:170
virtual ActiveObjectType getType() const =0
virtual bool getSelectionBox(aabb3f *toset) const =0
u16 object_t
Definition activeobject.h:158
virtual void getAttachment(object_t *parent_id, std::string *bone, v3f *position, v3f *rotation, bool *force_visible) const
Definition activeobject.h:203
core::aabbox3d< f32 > aabb3f
Definition irr_aabb3d.h:11
core::vector3df v3f
Definition irr_v3d.h:11
ActiveObjectMessage(u16 id_, bool reliable_=true, std::string_view data_="")
Definition activeobject.h:35
std::string datastring
Definition activeobject.h:45
void appendTo(std::string &data) const
Definition activeobject.cpp:8
u16 id
Definition activeobject.h:43
bool reliable
Definition activeobject.h:44
Definition activeobject.h:72
f32 interp_duration
Definition activeobject.h:76
bool absolute
Definition activeobject.h:75
v3f vector
Definition activeobject.h:74
v3f previous
Definition activeobject.h:73
Definition activeobject.h:88
f32 interp_duration
Definition activeobject.h:95
core::quaternion next
Definition activeobject.h:90
core::quaternion previous
Definition activeobject.h:89
bool absolute
Definition activeobject.h:94
v3f next_radians
Definition activeobject.h:93
Definition activeobject.h:116
v3f previous
Definition activeobject.h:117
v3f vector
Definition activeobject.h:118
bool absolute
Definition activeobject.h:119
f32 interp_duration
Definition activeobject.h:120
Definition activeobject.h:70
v3f getRotationEulerDeg(v3f anim_rot_euler) const
Definition activeobject.h:98
v3f getPosition(v3f anim_pos) const
Definition activeobject.h:79
bool isIdentity() const
Definition activeobject.h:140
v3f getScale(v3f anim_scale) const
Definition activeobject.h:123
bool finishedInterpolation() const
Definition activeobject.h:133
struct BoneOverride::ScaleProperty scale
f32 dtime_passed
Definition activeobject.h:131
struct BoneOverride::PositionProperty position
struct BoneOverride::RotationProperty rotation