aboutsummaryrefslogtreecommitdiff
path: root/src/content_cao.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/content_cao.cpp')
-rw-r--r--src/content_cao.cpp83
1 files changed, 33 insertions, 50 deletions
diff --git a/src/content_cao.cpp b/src/content_cao.cpp
index e7c7a0be5..d701e4f72 100644
--- a/src/content_cao.cpp
+++ b/src/content_cao.cpp
@@ -546,12 +546,14 @@ GenericCAO::GenericCAO(IGameDef *gamedef, ClientEnvironment *env):
//
m_smgr(NULL),
m_irr(NULL),
+ m_camera(NULL),
+ m_gamedef(NULL),
m_selection_box(-BS/3.,-BS/3.,-BS/3., BS/3.,BS/3.,BS/3.),
m_meshnode(NULL),
m_animated_meshnode(NULL),
m_wield_meshnode(NULL),
m_spritenode(NULL),
- m_textnode(NULL),
+ m_nametag(NULL),
m_position(v3f(0,10*BS,0)),
m_velocity(v3f(0,0,0)),
m_acceleration(v3f(0,0,0)),
@@ -580,8 +582,11 @@ GenericCAO::GenericCAO(IGameDef *gamedef, ClientEnvironment *env):
m_last_light(255),
m_is_visible(false)
{
- if(gamedef == NULL)
+ if (gamedef == NULL) {
ClientActiveObject::registerType(getType(), create);
+ } else {
+ m_gamedef = gamedef;
+ }
}
bool GenericCAO::getCollisionBox(aabb3f *toset)
@@ -667,8 +672,7 @@ void GenericCAO::initialize(const std::string &data)
GenericCAO::~GenericCAO()
{
- if(m_is_player)
- {
+ if (m_is_player) {
m_env->removePlayerName(m_name.c_str());
}
removeFromScene(true);
@@ -695,14 +699,15 @@ v3f GenericCAO::getPosition()
scene::ISceneNode* GenericCAO::getSceneNode()
{
- if (m_meshnode)
+ if (m_meshnode) {
return m_meshnode;
- if (m_animated_meshnode)
+ } else if (m_animated_meshnode) {
return m_animated_meshnode;
- if (m_wield_meshnode)
+ } else if (m_wield_meshnode) {
return m_wield_meshnode;
- if (m_spritenode)
+ } else if (m_spritenode) {
return m_spritenode;
+ }
return NULL;
}
@@ -775,56 +780,47 @@ void GenericCAO::removeFromScene(bool permanent)
}
}
- if(m_meshnode)
- {
+ if (m_meshnode) {
m_meshnode->remove();
m_meshnode->drop();
m_meshnode = NULL;
- }
- if(m_animated_meshnode)
- {
+ } else if (m_animated_meshnode) {
m_animated_meshnode->remove();
m_animated_meshnode->drop();
m_animated_meshnode = NULL;
- }
- if(m_wield_meshnode)
- {
+ } else if (m_wield_meshnode) {
m_wield_meshnode->remove();
m_wield_meshnode->drop();
m_wield_meshnode = NULL;
- }
- if(m_spritenode)
- {
+ } else if (m_spritenode) {
m_spritenode->remove();
m_spritenode->drop();
m_spritenode = NULL;
}
- if (m_textnode)
- {
- m_textnode->remove();
- m_textnode->drop();
- m_textnode = NULL;
+
+ if (m_nametag) {
+ m_gamedef->getCamera()->removeNametag(m_nametag);
+ m_nametag = NULL;
}
}
-void GenericCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
- IrrlichtDevice *irr)
+void GenericCAO::addToScene(scene::ISceneManager *smgr,
+ ITextureSource *tsrc, IrrlichtDevice *irr)
{
m_smgr = smgr;
m_irr = irr;
- if (getSceneNode() != NULL)
+ if (getSceneNode() != NULL) {
return;
+ }
m_visuals_expired = false;
- if(!m_prop.is_visible)
+ if (!m_prop.is_visible) {
return;
+ }
- //video::IVideoDriver* driver = smgr->getVideoDriver();
-
- if(m_prop.visual == "sprite")
- {
+ if (m_prop.visual == "sprite") {
infostream<<"GenericCAO::addToScene(): single_sprite"<<std::endl;
m_spritenode = smgr->addBillboardSceneNode(
NULL, v2f(1, 1), v3f(0,0,0), -1);
@@ -972,18 +968,9 @@ void GenericCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
scene::ISceneNode *node = getSceneNode();
if (node && m_prop.nametag != "" && !m_is_local_player) {
- // Add a text node for showing the name
- gui::IGUIEnvironment* gui = irr->getGUIEnvironment();
- std::wstring nametag_text = utf8_to_wide(m_prop.nametag);
- m_textnode = smgr->addTextSceneNode(gui->getSkin()->getFont(),
- nametag_text.c_str(), m_prop.nametag_color, node);
- m_textnode->grab();
- m_textnode->setPosition(v3f(0, BS*1.1, 0));
-
- // Enforce hiding nametag,
- // because if freetype is enabled, a grey
- // shadow can remain.
- m_textnode->setVisible(m_prop.nametag_color.getAlpha() > 0);
+ // Add nametag
+ m_nametag = m_gamedef->getCamera()->addNametag(node,
+ m_prop.nametag, m_prop.nametag_color);
}
updateNodePos();
@@ -1785,12 +1772,8 @@ void GenericCAO::processMessage(const std::string &data)
// Deprecated, for backwards compatibility only.
readU8(is); // version
m_prop.nametag_color = readARGB8(is);
- if (m_textnode != NULL) {
- m_textnode->setTextColor(m_prop.nametag_color);
-
- // Enforce hiding nametag,
- // because if freetype is enabled, a grey shadow can remain.
- m_textnode->setVisible(m_prop.nametag_color.getAlpha() > 0);
+ if (m_nametag != NULL) {
+ m_nametag->nametag_color = m_prop.nametag_color;
}
}
}