Split declaration of GenericCAO from implementation
parent
87b4bce594
commit
d9f6f9e7a8
|
@ -53,21 +53,7 @@ struct ToolCapabilities;
|
|||
|
||||
std::map<u16, ClientActiveObject::Factory> ClientActiveObject::m_types;
|
||||
|
||||
/*
|
||||
SmoothTranslator
|
||||
*/
|
||||
|
||||
struct SmoothTranslator
|
||||
{
|
||||
v3f vect_old;
|
||||
v3f vect_show;
|
||||
v3f vect_aim;
|
||||
f32 anim_counter;
|
||||
f32 anim_time;
|
||||
f32 anim_time_counter;
|
||||
bool aim_is_end;
|
||||
|
||||
SmoothTranslator():
|
||||
SmoothTranslator::SmoothTranslator():
|
||||
vect_old(0,0,0),
|
||||
vect_show(0,0,0),
|
||||
vect_aim(0,0,0),
|
||||
|
@ -77,7 +63,7 @@ struct SmoothTranslator
|
|||
aim_is_end(true)
|
||||
{}
|
||||
|
||||
void init(v3f vect)
|
||||
void SmoothTranslator::init(v3f vect)
|
||||
{
|
||||
vect_old = vect;
|
||||
vect_show = vect;
|
||||
|
@ -88,12 +74,12 @@ struct SmoothTranslator
|
|||
aim_is_end = true;
|
||||
}
|
||||
|
||||
void sharpen()
|
||||
void SmoothTranslator::sharpen()
|
||||
{
|
||||
init(vect_show);
|
||||
}
|
||||
|
||||
void update(v3f vect_new, bool is_end_position=false, float update_interval=-1)
|
||||
void SmoothTranslator::update(v3f vect_new, bool is_end_position, float update_interval)
|
||||
{
|
||||
aim_is_end = is_end_position;
|
||||
vect_old = vect_show;
|
||||
|
@ -110,7 +96,7 @@ struct SmoothTranslator
|
|||
anim_counter = 0;
|
||||
}
|
||||
|
||||
void translate(f32 dtime)
|
||||
void SmoothTranslator::translate(f32 dtime)
|
||||
{
|
||||
anim_time_counter = anim_time_counter + dtime;
|
||||
anim_counter = anim_counter + dtime;
|
||||
|
@ -128,11 +114,10 @@ struct SmoothTranslator
|
|||
vect_show = vect_old + vect_move * moveratio;
|
||||
}
|
||||
|
||||
bool is_moving()
|
||||
bool SmoothTranslator::is_moving()
|
||||
{
|
||||
return ((anim_time_counter / anim_time) < 1.4);
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Other stuff
|
||||
|
@ -552,56 +537,7 @@ void ItemCAO::initialize(const std::string &data)
|
|||
|
||||
#include "genericobject.h"
|
||||
|
||||
class GenericCAO : public ClientActiveObject
|
||||
{
|
||||
private:
|
||||
// Only set at initialization
|
||||
std::string m_name;
|
||||
bool m_is_player;
|
||||
bool m_is_local_player;
|
||||
int m_id;
|
||||
// Property-ish things
|
||||
ObjectProperties m_prop;
|
||||
//
|
||||
scene::ISceneManager *m_smgr;
|
||||
IrrlichtDevice *m_irr;
|
||||
core::aabbox3d<f32> m_selection_box;
|
||||
scene::IMeshSceneNode *m_meshnode;
|
||||
scene::IAnimatedMeshSceneNode *m_animated_meshnode;
|
||||
scene::IBillboardSceneNode *m_spritenode;
|
||||
scene::ITextSceneNode* m_textnode;
|
||||
v3f m_position;
|
||||
v3f m_velocity;
|
||||
v3f m_acceleration;
|
||||
float m_yaw;
|
||||
s16 m_hp;
|
||||
SmoothTranslator pos_translator;
|
||||
// Spritesheet/animation stuff
|
||||
v2f m_tx_size;
|
||||
v2s16 m_tx_basepos;
|
||||
bool m_initial_tx_basepos_set;
|
||||
bool m_tx_select_horiz_by_yawpitch;
|
||||
v2s32 m_animation_range;
|
||||
int m_animation_speed;
|
||||
int m_animation_blend;
|
||||
std::map<std::string, core::vector2d<v3f> > m_bone_position; // stores position and rotation for each bone name
|
||||
std::string m_attachment_bone;
|
||||
v3f m_attachment_position;
|
||||
v3f m_attachment_rotation;
|
||||
bool m_attached_to_local;
|
||||
int m_anim_frame;
|
||||
int m_anim_num_frames;
|
||||
float m_anim_framelength;
|
||||
float m_anim_timer;
|
||||
ItemGroupList m_armor_groups;
|
||||
float m_reset_textures_timer;
|
||||
bool m_visuals_expired;
|
||||
float m_step_distance_counter;
|
||||
u8 m_last_light;
|
||||
bool m_is_visible;
|
||||
|
||||
public:
|
||||
GenericCAO(IGameDef *gamedef, ClientEnvironment *env):
|
||||
GenericCAO::GenericCAO(IGameDef *gamedef, ClientEnvironment *env):
|
||||
ClientActiveObject(0, gamedef, env),
|
||||
//
|
||||
m_is_player(false),
|
||||
|
@ -646,7 +582,7 @@ public:
|
|||
ClientActiveObject::registerType(getType(), create);
|
||||
}
|
||||
|
||||
bool getCollisionBox(aabb3f *toset) {
|
||||
bool GenericCAO::getCollisionBox(aabb3f *toset) {
|
||||
if (m_prop.physical) {
|
||||
//update collision box
|
||||
toset->MinEdge = m_prop.collisionbox.MinEdge * BS;
|
||||
|
@ -661,11 +597,11 @@ public:
|
|||
return false;
|
||||
}
|
||||
|
||||
bool collideWithObjects() {
|
||||
bool GenericCAO::collideWithObjects() {
|
||||
return m_prop.collideWithObjects;
|
||||
}
|
||||
|
||||
void initialize(const std::string &data)
|
||||
void GenericCAO::initialize(const std::string &data)
|
||||
{
|
||||
infostream<<"GenericCAO: Got init data"<<std::endl;
|
||||
std::istringstream is(data, std::ios::binary);
|
||||
|
@ -716,29 +652,21 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
~GenericCAO()
|
||||
GenericCAO::~GenericCAO()
|
||||
{
|
||||
if(m_is_player){
|
||||
m_env->removePlayerName(m_name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
static ClientActiveObject* create(IGameDef *gamedef, ClientEnvironment *env)
|
||||
{
|
||||
return new GenericCAO(gamedef, env);
|
||||
}
|
||||
|
||||
u8 getType() const
|
||||
{
|
||||
return ACTIVEOBJECT_TYPE_GENERIC;
|
||||
}
|
||||
core::aabbox3d<f32>* getSelectionBox()
|
||||
core::aabbox3d<f32>* GenericCAO::getSelectionBox()
|
||||
{
|
||||
if(!m_prop.is_visible || !m_is_visible || m_is_local_player || getParent() != NULL)
|
||||
return NULL;
|
||||
return &m_selection_box;
|
||||
}
|
||||
v3f getPosition()
|
||||
|
||||
v3f GenericCAO::getPosition()
|
||||
{
|
||||
if(getParent() != NULL){
|
||||
if(m_meshnode)
|
||||
|
@ -752,43 +680,33 @@ public:
|
|||
return pos_translator.vect_show;
|
||||
}
|
||||
|
||||
scene::IMeshSceneNode *getMeshSceneNode()
|
||||
scene::IMeshSceneNode* GenericCAO::getMeshSceneNode()
|
||||
{
|
||||
if(m_meshnode)
|
||||
return m_meshnode;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode()
|
||||
scene::IAnimatedMeshSceneNode* GenericCAO::getAnimatedMeshSceneNode()
|
||||
{
|
||||
if(m_animated_meshnode)
|
||||
return m_animated_meshnode;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
scene::IBillboardSceneNode *getSpriteSceneNode()
|
||||
scene::IBillboardSceneNode* GenericCAO::getSpriteSceneNode()
|
||||
{
|
||||
if(m_spritenode)
|
||||
return m_spritenode;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool isPlayer()
|
||||
{
|
||||
return m_is_player;
|
||||
}
|
||||
|
||||
bool isLocalPlayer()
|
||||
{
|
||||
return m_is_local_player;
|
||||
}
|
||||
|
||||
void setAttachments()
|
||||
void GenericCAO::setAttachments()
|
||||
{
|
||||
updateAttachments();
|
||||
}
|
||||
|
||||
ClientActiveObject *getParent()
|
||||
ClientActiveObject* GenericCAO::getParent()
|
||||
{
|
||||
ClientActiveObject *obj = NULL;
|
||||
for(std::vector<core::vector2d<int> >::const_iterator cii = m_env->attachment_list.begin(); cii != m_env->attachment_list.end(); cii++)
|
||||
|
@ -807,7 +725,7 @@ public:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void removeFromScene(bool permanent)
|
||||
void GenericCAO::removeFromScene(bool permanent)
|
||||
{
|
||||
if(permanent) // Should be true when removing the object permanently and false when refreshing (eg: updating visuals)
|
||||
{
|
||||
|
@ -847,7 +765,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
|
||||
void GenericCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
|
||||
IrrlichtDevice *irr)
|
||||
{
|
||||
m_smgr = smgr;
|
||||
|
@ -1028,12 +946,7 @@ public:
|
|||
updateAttachments();
|
||||
}
|
||||
|
||||
void expireVisuals()
|
||||
{
|
||||
m_visuals_expired = true;
|
||||
}
|
||||
|
||||
void updateLight(u8 light_at_pos)
|
||||
void GenericCAO::updateLight(u8 light_at_pos)
|
||||
{
|
||||
u8 li = decode_light(light_at_pos);
|
||||
if(li != m_last_light){
|
||||
|
@ -1048,12 +961,12 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
v3s16 getLightPosition()
|
||||
v3s16 GenericCAO::getLightPosition()
|
||||
{
|
||||
return floatToInt(m_position, BS);
|
||||
}
|
||||
|
||||
void updateNodePos()
|
||||
void GenericCAO::updateNodePos()
|
||||
{
|
||||
if(getParent() != NULL)
|
||||
return;
|
||||
|
@ -1076,7 +989,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void step(float dtime, ClientEnvironment *env)
|
||||
void GenericCAO::step(float dtime, ClientEnvironment *env)
|
||||
{
|
||||
// Handel model of local player instantly to prevent lags
|
||||
if(m_is_local_player) {
|
||||
|
@ -1133,6 +1046,7 @@ public:
|
|||
player->last_animation_speed = m_animation_speed;
|
||||
} else {
|
||||
player->last_animation = NO_ANIM;
|
||||
|
||||
if (old_anim != NO_ANIM) {
|
||||
m_animation_range = player->local_animations[0];
|
||||
updateAnimation();
|
||||
|
@ -1291,7 +1205,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void updateTexturePos()
|
||||
void GenericCAO::updateTexturePos()
|
||||
{
|
||||
if(m_spritenode){
|
||||
scene::ICameraSceneNode* camera =
|
||||
|
@ -1339,7 +1253,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void updateTextures(const std::string &mod)
|
||||
void GenericCAO::updateTextures(const std::string &mod)
|
||||
{
|
||||
ITextureSource *tsrc = m_gamedef->tsrc();
|
||||
|
||||
|
@ -1507,7 +1421,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void updateAnimation()
|
||||
void GenericCAO::updateAnimation()
|
||||
{
|
||||
if(m_animated_meshnode == NULL)
|
||||
return;
|
||||
|
@ -1516,7 +1430,7 @@ public:
|
|||
m_animated_meshnode->setTransitionTime(m_animation_blend);
|
||||
}
|
||||
|
||||
void updateBonePosition()
|
||||
void GenericCAO::updateBonePosition()
|
||||
{
|
||||
if(!m_bone_position.size() || m_animated_meshnode == NULL)
|
||||
return;
|
||||
|
@ -1535,7 +1449,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void updateAttachments()
|
||||
void GenericCAO::updateAttachments()
|
||||
{
|
||||
m_attached_to_local = getParent() != NULL && getParent()->isLocalPlayer();
|
||||
m_is_visible = !m_attached_to_local; // Objects attached to the local player should always be hidden
|
||||
|
@ -1688,7 +1602,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void processMessage(const std::string &data)
|
||||
void GenericCAO::processMessage(const std::string &data)
|
||||
{
|
||||
//infostream<<"GenericCAO: Got message"<<std::endl;
|
||||
std::istringstream is(data, std::ios::binary);
|
||||
|
@ -1806,7 +1720,8 @@ public:
|
|||
is_known = true;
|
||||
}
|
||||
if(!is_known ||
|
||||
(player->local_animations[1].Y + player->local_animations[2].Y < 1)) {
|
||||
(player->local_animations[1].Y + player->local_animations[2].Y < 1))
|
||||
{
|
||||
updateAnimation();
|
||||
}
|
||||
}
|
||||
|
@ -1878,8 +1793,8 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
bool directReportPunch(v3f dir, const ItemStack *punchitem=NULL,
|
||||
float time_from_last_punch=1000000)
|
||||
bool GenericCAO::directReportPunch(v3f dir, const ItemStack *punchitem,
|
||||
float time_from_last_punch)
|
||||
{
|
||||
assert(punchitem);
|
||||
const ToolCapabilities *toolcap =
|
||||
|
@ -1914,7 +1829,7 @@ public:
|
|||
return false;
|
||||
}
|
||||
|
||||
std::string debugInfoText()
|
||||
std::string GenericCAO::debugInfoText()
|
||||
{
|
||||
std::ostringstream os(std::ios::binary);
|
||||
os<<"GenericCAO hp="<<m_hp<<"\n";
|
||||
|
@ -1926,9 +1841,6 @@ public:
|
|||
os<<"}";
|
||||
return os.str();
|
||||
}
|
||||
};
|
||||
|
||||
// Prototype
|
||||
GenericCAO proto_GenericCAO(NULL, NULL);
|
||||
|
||||
|
||||
|
|
|
@ -20,5 +20,179 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#ifndef CONTENT_CAO_HEADER
|
||||
#define CONTENT_CAO_HEADER
|
||||
|
||||
#include <map>
|
||||
#include "irrlichttypes_extrabloated.h"
|
||||
#include "content_object.h"
|
||||
#include "clientobject.h"
|
||||
#include "object_properties.h"
|
||||
#include "itemgroup.h"
|
||||
|
||||
/*
|
||||
SmoothTranslator
|
||||
*/
|
||||
|
||||
struct SmoothTranslator
|
||||
{
|
||||
v3f vect_old;
|
||||
v3f vect_show;
|
||||
v3f vect_aim;
|
||||
f32 anim_counter;
|
||||
f32 anim_time;
|
||||
f32 anim_time_counter;
|
||||
bool aim_is_end;
|
||||
|
||||
SmoothTranslator();
|
||||
|
||||
void init(v3f vect);
|
||||
|
||||
void sharpen();
|
||||
|
||||
void update(v3f vect_new, bool is_end_position=false, float update_interval=-1);
|
||||
|
||||
void translate(f32 dtime);
|
||||
|
||||
bool is_moving();
|
||||
};
|
||||
|
||||
class GenericCAO : public ClientActiveObject
|
||||
{
|
||||
private:
|
||||
// Only set at initialization
|
||||
std::string m_name;
|
||||
bool m_is_player;
|
||||
bool m_is_local_player;
|
||||
int m_id;
|
||||
// Property-ish things
|
||||
ObjectProperties m_prop;
|
||||
//
|
||||
scene::ISceneManager *m_smgr;
|
||||
IrrlichtDevice *m_irr;
|
||||
core::aabbox3d<f32> m_selection_box;
|
||||
scene::IMeshSceneNode *m_meshnode;
|
||||
scene::IAnimatedMeshSceneNode *m_animated_meshnode;
|
||||
scene::IBillboardSceneNode *m_spritenode;
|
||||
scene::ITextSceneNode* m_textnode;
|
||||
v3f m_position;
|
||||
v3f m_velocity;
|
||||
v3f m_acceleration;
|
||||
float m_yaw;
|
||||
s16 m_hp;
|
||||
SmoothTranslator pos_translator;
|
||||
// Spritesheet/animation stuff
|
||||
v2f m_tx_size;
|
||||
v2s16 m_tx_basepos;
|
||||
bool m_initial_tx_basepos_set;
|
||||
bool m_tx_select_horiz_by_yawpitch;
|
||||
v2s32 m_animation_range;
|
||||
int m_animation_speed;
|
||||
int m_animation_blend;
|
||||
std::map<std::string, core::vector2d<v3f> > m_bone_position; // stores position and rotation for each bone name
|
||||
std::string m_attachment_bone;
|
||||
v3f m_attachment_position;
|
||||
v3f m_attachment_rotation;
|
||||
bool m_attached_to_local;
|
||||
int m_anim_frame;
|
||||
int m_anim_num_frames;
|
||||
float m_anim_framelength;
|
||||
float m_anim_timer;
|
||||
ItemGroupList m_armor_groups;
|
||||
float m_reset_textures_timer;
|
||||
bool m_visuals_expired;
|
||||
float m_step_distance_counter;
|
||||
u8 m_last_light;
|
||||
bool m_is_visible;
|
||||
|
||||
public:
|
||||
GenericCAO(IGameDef *gamedef, ClientEnvironment *env);
|
||||
|
||||
~GenericCAO();
|
||||
|
||||
static ClientActiveObject* create(IGameDef *gamedef, ClientEnvironment *env)
|
||||
{
|
||||
return new GenericCAO(gamedef, env);
|
||||
}
|
||||
|
||||
inline u8 getType() const
|
||||
{
|
||||
return ACTIVEOBJECT_TYPE_GENERIC;
|
||||
}
|
||||
|
||||
void initialize(const std::string &data);
|
||||
|
||||
ClientActiveObject *getParent();
|
||||
|
||||
bool getCollisionBox(aabb3f *toset);
|
||||
|
||||
bool collideWithObjects();
|
||||
|
||||
core::aabbox3d<f32>* getSelectionBox();
|
||||
|
||||
v3f getPosition();
|
||||
|
||||
scene::IMeshSceneNode *getMeshSceneNode();
|
||||
|
||||
scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode();
|
||||
|
||||
scene::IBillboardSceneNode *getSpriteSceneNode();
|
||||
|
||||
inline bool isPlayer() const
|
||||
{
|
||||
return m_is_player;
|
||||
}
|
||||
|
||||
inline bool isLocalPlayer() const
|
||||
{
|
||||
return m_is_local_player;
|
||||
}
|
||||
|
||||
inline bool isVisible() const
|
||||
{
|
||||
return m_is_visible;
|
||||
}
|
||||
|
||||
inline void setVisible(bool toset)
|
||||
{
|
||||
m_is_visible = toset;
|
||||
}
|
||||
|
||||
void setAttachments();
|
||||
|
||||
void removeFromScene(bool permanent);
|
||||
|
||||
void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
|
||||
IrrlichtDevice *irr);
|
||||
|
||||
inline void expireVisuals()
|
||||
{
|
||||
m_visuals_expired = true;
|
||||
}
|
||||
|
||||
void updateLight(u8 light_at_pos);
|
||||
|
||||
v3s16 getLightPosition();
|
||||
|
||||
void updateNodePos();
|
||||
|
||||
void step(float dtime, ClientEnvironment *env);
|
||||
|
||||
void updateTexturePos();
|
||||
|
||||
void updateTextures(const std::string &mod);
|
||||
|
||||
void updateAnimation();
|
||||
|
||||
void updateBonePosition();
|
||||
|
||||
void updateAttachments();
|
||||
|
||||
void processMessage(const std::string &data);
|
||||
|
||||
bool directReportPunch(v3f dir, const ItemStack *punchitem=NULL,
|
||||
float time_from_last_punch=1000000);
|
||||
|
||||
std::string debugInfoText();
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue