Split declaration of GenericCAO from implementation

This commit is contained in:
sapier 2014-05-03 11:14:22 +02:00
parent 87b4bce594
commit d9f6f9e7a8
2 changed files with 1343 additions and 1257 deletions

@ -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),
@ -75,10 +61,10 @@ struct SmoothTranslator
anim_time(0),
anim_time_counter(0),
aim_is_end(true)
{}
{}
void init(v3f vect)
{
void SmoothTranslator::init(v3f vect)
{
vect_old = vect;
vect_show = vect;
vect_aim = vect;
@ -86,15 +72,15 @@ struct SmoothTranslator
anim_time = 0;
anim_time_counter = 0;
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;
vect_aim = vect_new;
@ -108,10 +94,10 @@ struct SmoothTranslator
}
anim_time_counter = 0;
anim_counter = 0;
}
}
void translate(f32 dtime)
{
void SmoothTranslator::translate(f32 dtime)
{
anim_time_counter = anim_time_counter + dtime;
anim_counter = anim_counter + dtime;
v3f vect_move = vect_aim - vect_old;
@ -126,13 +112,12 @@ struct SmoothTranslator
if(moveratio > move_end)
moveratio = move_end;
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),
@ -641,12 +577,12 @@ public:
m_step_distance_counter(0),
m_last_light(255),
m_is_visible(false)
{
{
if(gamedef == NULL)
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;
@ -659,14 +595,14 @@ 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);
int num_messages = 0;
@ -714,32 +650,24 @@ public:
}
m_env->addPlayerName(m_name.c_str());
}
}
}
~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)
return m_meshnode->getAbsolutePosition();
@ -750,46 +678,36 @@ public:
return m_position;
}
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++)
{
@ -805,10 +723,10 @@ public:
if(obj)
return obj;
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)
{
// Detach this object's children
@ -845,11 +763,11 @@ public:
m_spritenode->remove();
m_spritenode = NULL;
}
}
}
void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
void GenericCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
IrrlichtDevice *irr)
{
{
m_smgr = smgr;
m_irr = irr;
@ -1026,15 +944,10 @@ public:
updateAnimation();
updateBonePosition();
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){
m_last_light = li;
@ -1046,15 +959,15 @@ public:
if(m_spritenode)
m_spritenode->setColor(color);
}
}
}
v3s16 getLightPosition()
{
v3s16 GenericCAO::getLightPosition()
{
return floatToInt(m_position, BS);
}
}
void updateNodePos()
{
void GenericCAO::updateNodePos()
{
if(getParent() != NULL)
return;
@ -1074,10 +987,10 @@ public:
if(m_spritenode){
m_spritenode->setPosition(pos_translator.vect_show-intToFloat(camera_offset, BS));
}
}
}
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) {
LocalPlayer *player = m_env->getLocalPlayer();
@ -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();
@ -1289,10 +1203,10 @@ public:
m_yaw = atan2(m_velocity.Z,m_velocity.X) * 180 / M_PI + m_prop.automatic_face_movement_dir_offset;
updateNodePos();
}
}
}
void updateTexturePos()
{
void GenericCAO::updateTexturePos()
{
if(m_spritenode){
scene::ICameraSceneNode* camera =
m_spritenode->getSceneManager()->getActiveCamera();
@ -1337,10 +1251,10 @@ public:
setBillboardTextureMatrix(m_spritenode,
txs, tys, col, row);
}
}
}
void updateTextures(const std::string &mod)
{
void GenericCAO::updateTextures(const std::string &mod)
{
ITextureSource *tsrc = m_gamedef->tsrc();
bool use_trilinear_filter = g_settings->getBool("trilinear_filter");
@ -1505,19 +1419,19 @@ public:
}
}
}
}
}
void updateAnimation()
{
void GenericCAO::updateAnimation()
{
if(m_animated_meshnode == NULL)
return;
m_animated_meshnode->setFrameLoop(m_animation_range.X, m_animation_range.Y);
m_animated_meshnode->setAnimationSpeed(m_animation_speed);
m_animated_meshnode->setTransitionTime(m_animation_blend);
}
}
void updateBonePosition()
{
void GenericCAO::updateBonePosition()
{
if(!m_bone_position.size() || m_animated_meshnode == NULL)
return;
@ -1533,10 +1447,10 @@ public:
bone->setRotation(bone_rot);
}
}
}
}
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
@ -1686,10 +1600,10 @@ public:
player->isAttached = true;
}
}
}
}
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);
// command
@ -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();
}
}
@ -1876,11 +1791,11 @@ public:
m_armor_groups[name] = rating;
}
}
}
}
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 =
&punchitem->getToolCapabilities(m_gamedef->idef());
@ -1912,10 +1827,10 @@ public:
}
return false;
}
}
std::string debugInfoText()
{
std::string GenericCAO::debugInfoText()
{
std::ostringstream os(std::ios::binary);
os<<"GenericCAO hp="<<m_hp<<"\n";
os<<"armor={";
@ -1925,10 +1840,7 @@ 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