device->getSceneManager()->getRootSceneNode(),
device->getSceneManager(), 666),
device->getSceneManager(),
- tsrc, this
+ tsrc, this, device
),
m_con(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, this),
m_device(device),
}
else if(command == TOCLIENT_PLAYERINFO)
{
+ infostream<<"Client received DEPRECATED TOCLIENT_PLAYERINFO"<<std::endl;
+#if 0
u16 our_peer_id;
{
//JMutexAutoLock lock(m_con_mutex); //bulk comment-out
m_env.removePlayer((*ip)->peer_id);
}
} //envlock
+#endif
}
else if(command == TOCLIENT_SECTORMETA)
{
ClientActiveObject
*/
-ClientActiveObject::ClientActiveObject(u16 id, IGameDef *gamedef):
+ClientActiveObject::ClientActiveObject(u16 id, IGameDef *gamedef,
+ ClientEnvironment *env):
ActiveObject(id),
- m_gamedef(gamedef)
+ m_gamedef(gamedef),
+ m_env(env)
{
}
removeFromScene();
}
-ClientActiveObject* ClientActiveObject::create(u8 type, IGameDef *gamedef)
+ClientActiveObject* ClientActiveObject::create(u8 type, IGameDef *gamedef,
+ ClientEnvironment *env)
{
// Find factory function
core::map<u16, Factory>::Node *n;
}
Factory f = n->getValue();
- ClientActiveObject *object = (*f)(gamedef);
+ ClientActiveObject *object = (*f)(gamedef, env);
return object;
}
class ClientActiveObject : public ActiveObject
{
public:
- ClientActiveObject(u16 id, IGameDef *gamedef);
+ ClientActiveObject(u16 id, IGameDef *gamedef, ClientEnvironment *env);
virtual ~ClientActiveObject();
- virtual void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc){}
+ virtual void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
+ IrrlichtDevice *irr){}
virtual void removeFromScene(){}
// 0 <= light_at_pos <= LIGHT_SUN
virtual void updateLight(u8 light_at_pos){}
virtual void initialize(const std::string &data){}
// Create a certain type of ClientActiveObject
- static ClientActiveObject* create(u8 type, IGameDef *gamedef);
+ static ClientActiveObject* create(u8 type, IGameDef *gamedef,
+ ClientEnvironment *env);
// If returns true, punch will not be sent to the server
virtual bool directReportPunch(const std::string &toolname, v3f dir)
protected:
// Used for creating objects based on type
- typedef ClientActiveObject* (*Factory)(IGameDef *gamedef);
+ typedef ClientActiveObject* (*Factory)(IGameDef *gamedef, ClientEnvironment *env);
static void registerType(u16 type, Factory f);
IGameDef *m_gamedef;
+ ClientEnvironment *m_env;
private:
// Used for creating objects based on type
static core::map<u16, Factory> m_types;
#include "environment.h"
#include "settings.h"
#include <ICameraSceneNode.h>
+#include <ITextSceneNode.h>
#include "serialization.h" // For decompressZlib
#include "gamedef.h"
+#include "clientobject.h"
+#include "content_object.h"
+#include "utility.h" // For IntervalLimiter
+class Settings;
+#include "MyBillboardSceneNode.h"
core::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():
+ vect_old(0,0,0),
+ vect_show(0,0,0),
+ vect_aim(0,0,0),
+ anim_counter(0),
+ anim_time(0),
+ anim_time_counter(0),
+ aim_is_end(true)
+ {}
+
+ void init(v3f vect)
+ {
+ vect_old = vect;
+ vect_show = vect;
+ vect_aim = vect;
+ anim_counter = 0;
+ anim_time = 0;
+ anim_time_counter = 0;
+ aim_is_end = true;
+ }
+
+ void sharpen()
+ {
+ init(vect_show);
+ }
+
+ void update(v3f vect_new, bool is_end_position=false, float update_interval=-1)
+ {
+ aim_is_end = is_end_position;
+ vect_old = vect_show;
+ vect_aim = vect_new;
+ if(update_interval > 0){
+ anim_time = update_interval;
+ } else {
+ if(anim_time < 0.001 || anim_time > 1.0)
+ anim_time = anim_time_counter;
+ else
+ anim_time = anim_time * 0.9 + anim_time_counter * 0.1;
+ }
+ anim_time_counter = 0;
+ anim_counter = 0;
+ }
+
+ void translate(f32 dtime)
+ {
+ anim_time_counter = anim_time_counter + dtime;
+ anim_counter = anim_counter + dtime;
+ v3f vect_move = vect_aim - vect_old;
+ f32 moveratio = 1.0;
+ if(anim_time > 0.001)
+ moveratio = anim_time_counter / anim_time;
+ // Move a bit less than should, to avoid oscillation
+ moveratio = moveratio * 0.8;
+ float move_end = 1.5;
+ if(aim_is_end)
+ move_end = 1.0;
+ if(moveratio > move_end)
+ moveratio = move_end;
+ vect_show = vect_old + vect_move * moveratio;
+ }
+
+ bool is_moving()
+ {
+ return ((anim_time_counter / anim_time) < 1.4);
+ }
+};
+
+
+/*
+ TestCAO
+*/
+
+class TestCAO : public ClientActiveObject
+{
+public:
+ TestCAO(IGameDef *gamedef, ClientEnvironment *env);
+ virtual ~TestCAO();
+
+ u8 getType() const
+ {
+ return ACTIVEOBJECT_TYPE_TEST;
+ }
+
+ static ClientActiveObject* create(IGameDef *gamedef, ClientEnvironment *env);
+
+ void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
+ IrrlichtDevice *irr);
+ void removeFromScene();
+ void updateLight(u8 light_at_pos);
+ v3s16 getLightPosition();
+ void updateNodePos();
+
+ void step(float dtime, ClientEnvironment *env);
+
+ void processMessage(const std::string &data);
+
+private:
+ scene::IMeshSceneNode *m_node;
+ v3f m_position;
+};
+
+/*
+ ItemCAO
+*/
+
+class ItemCAO : public ClientActiveObject
+{
+public:
+ ItemCAO(IGameDef *gamedef, ClientEnvironment *env);
+ virtual ~ItemCAO();
+
+ u8 getType() const
+ {
+ return ACTIVEOBJECT_TYPE_ITEM;
+ }
+
+ static ClientActiveObject* create(IGameDef *gamedef, ClientEnvironment *env);
+
+ void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
+ IrrlichtDevice *irr);
+ void removeFromScene();
+ void updateLight(u8 light_at_pos);
+ v3s16 getLightPosition();
+ void updateNodePos();
+
+ void step(float dtime, ClientEnvironment *env);
+
+ void processMessage(const std::string &data);
+
+ void initialize(const std::string &data);
+
+ core::aabbox3d<f32>* getSelectionBox()
+ {return &m_selection_box;}
+ v3f getPosition()
+ {return m_position;}
+
+private:
+ core::aabbox3d<f32> m_selection_box;
+ scene::IMeshSceneNode *m_node;
+ v3f m_position;
+ std::string m_inventorystring;
+};
+
+/*
+ RatCAO
+*/
+
+class RatCAO : public ClientActiveObject
+{
+public:
+ RatCAO(IGameDef *gamedef, ClientEnvironment *env);
+ virtual ~RatCAO();
+
+ u8 getType() const
+ {
+ return ACTIVEOBJECT_TYPE_RAT;
+ }
+
+ static ClientActiveObject* create(IGameDef *gamedef, ClientEnvironment *env);
+
+ void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
+ IrrlichtDevice *irr);
+ void removeFromScene();
+ void updateLight(u8 light_at_pos);
+ v3s16 getLightPosition();
+ void updateNodePos();
+
+ void step(float dtime, ClientEnvironment *env);
+
+ void processMessage(const std::string &data);
+
+ void initialize(const std::string &data);
+
+ core::aabbox3d<f32>* getSelectionBox()
+ {return &m_selection_box;}
+ v3f getPosition()
+ {return pos_translator.vect_show;}
+ //{return m_position;}
+
+private:
+ core::aabbox3d<f32> m_selection_box;
+ scene::IMeshSceneNode *m_node;
+ v3f m_position;
+ float m_yaw;
+ SmoothTranslator pos_translator;
+};
+
+/*
+ Oerkki1CAO
+*/
+
+class Oerkki1CAO : public ClientActiveObject
+{
+public:
+ Oerkki1CAO(IGameDef *gamedef, ClientEnvironment *env);
+ virtual ~Oerkki1CAO();
+
+ u8 getType() const
+ {
+ return ACTIVEOBJECT_TYPE_OERKKI1;
+ }
+
+ static ClientActiveObject* create(IGameDef *gamedef, ClientEnvironment *env);
+
+ void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
+ IrrlichtDevice *irr);
+ void removeFromScene();
+ void updateLight(u8 light_at_pos);
+ v3s16 getLightPosition();
+ void updateNodePos();
+
+ void step(float dtime, ClientEnvironment *env);
+
+ void processMessage(const std::string &data);
+
+ void initialize(const std::string &data);
+
+ core::aabbox3d<f32>* getSelectionBox()
+ {return &m_selection_box;}
+ v3f getPosition()
+ {return pos_translator.vect_show;}
+ //{return m_position;}
+
+ // If returns true, punch will not be sent to the server
+ bool directReportPunch(const std::string &toolname, v3f dir);
+
+private:
+ IntervalLimiter m_attack_interval;
+ core::aabbox3d<f32> m_selection_box;
+ scene::IMeshSceneNode *m_node;
+ v3f m_position;
+ float m_yaw;
+ SmoothTranslator pos_translator;
+ float m_damage_visual_timer;
+ bool m_damage_texture_enabled;
+};
+
+/*
+ FireflyCAO
+*/
+
+class FireflyCAO : public ClientActiveObject
+{
+public:
+ FireflyCAO(IGameDef *gamedef, ClientEnvironment *env);
+ virtual ~FireflyCAO();
+
+ u8 getType() const
+ {
+ return ACTIVEOBJECT_TYPE_FIREFLY;
+ }
+
+ static ClientActiveObject* create(IGameDef *gamedef, ClientEnvironment *env);
+
+ void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
+ IrrlichtDevice *irr);
+ void removeFromScene();
+ void updateLight(u8 light_at_pos);
+ v3s16 getLightPosition();
+ void updateNodePos();
+
+ void step(float dtime, ClientEnvironment *env);
+
+ void processMessage(const std::string &data);
+
+ void initialize(const std::string &data);
+
+ core::aabbox3d<f32>* getSelectionBox()
+ {return &m_selection_box;}
+ v3f getPosition()
+ {return m_position;}
+
+private:
+ core::aabbox3d<f32> m_selection_box;
+ scene::IMeshSceneNode *m_node;
+ v3f m_position;
+ float m_yaw;
+ SmoothTranslator pos_translator;
+};
+
+/*
+ MobV2CAO
+*/
+
+class MobV2CAO : public ClientActiveObject
+{
+public:
+ MobV2CAO(IGameDef *gamedef, ClientEnvironment *env);
+ virtual ~MobV2CAO();
+
+ u8 getType() const
+ {
+ return ACTIVEOBJECT_TYPE_MOBV2;
+ }
+
+ static ClientActiveObject* create(IGameDef *gamedef, ClientEnvironment *env);
+
+ void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
+ IrrlichtDevice *irr);
+ void removeFromScene();
+ void updateLight(u8 light_at_pos);
+ v3s16 getLightPosition();
+ void updateNodePos();
+
+ void step(float dtime, ClientEnvironment *env);
+
+ void processMessage(const std::string &data);
+
+ void initialize(const std::string &data);
+
+ core::aabbox3d<f32>* getSelectionBox()
+ {return &m_selection_box;}
+ v3f getPosition()
+ {return pos_translator.vect_show;}
+ //{return m_position;}
+ bool doShowSelectionBox(){return false;}
+
+ // If returns true, punch will not be sent to the server
+ bool directReportPunch(const std::string &toolname, v3f dir);
+
+private:
+ void setLooks(const std::string &looks);
+
+ IntervalLimiter m_attack_interval;
+ core::aabbox3d<f32> m_selection_box;
+ scene::MyBillboardSceneNode *m_node;
+ v3f m_position;
+ std::string m_texture_name;
+ float m_yaw;
+ SmoothTranslator pos_translator;
+ bool m_walking;
+ float m_walking_unset_timer;
+ float m_walk_timer;
+ int m_walk_frame;
+ float m_damage_visual_timer;
+ u8 m_last_light;
+ bool m_shooting;
+ float m_shooting_unset_timer;
+ v2f m_sprite_size;
+ float m_sprite_y;
+ bool m_bright_shooting;
+ std::string m_sprite_type;
+ int m_simple_anim_frames;
+ float m_simple_anim_frametime;
+ bool m_lock_full_brightness;
+ int m_player_hit_damage;
+ float m_player_hit_distance;
+ float m_player_hit_interval;
+ float m_player_hit_timer;
+
+ Settings *m_properties;
+};
+
/*
TestCAO
*/
// Prototype
-TestCAO proto_TestCAO(NULL);
+TestCAO proto_TestCAO(NULL, NULL);
-TestCAO::TestCAO(IGameDef *gamedef):
- ClientActiveObject(0, gamedef),
+TestCAO::TestCAO(IGameDef *gamedef, ClientEnvironment *env):
+ ClientActiveObject(0, gamedef, env),
m_node(NULL),
m_position(v3f(0,10*BS,0))
{
{
}
-ClientActiveObject* TestCAO::create(IGameDef *gamedef)
+ClientActiveObject* TestCAO::create(IGameDef *gamedef, ClientEnvironment *env)
{
- return new TestCAO(gamedef);
+ return new TestCAO(gamedef, env);
}
-void TestCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc)
+void TestCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
+ IrrlichtDevice *irr)
{
if(m_node != NULL)
return;
#include "inventory.h"
// Prototype
-ItemCAO proto_ItemCAO(NULL);
+ItemCAO proto_ItemCAO(NULL, NULL);
-ItemCAO::ItemCAO(IGameDef *gamedef):
- ClientActiveObject(0, gamedef),
+ItemCAO::ItemCAO(IGameDef *gamedef, ClientEnvironment *env):
+ ClientActiveObject(0, gamedef, env),
m_selection_box(-BS/3.,0.0,-BS/3., BS/3.,BS*2./3.,BS/3.),
m_node(NULL),
m_position(v3f(0,10*BS,0))
{
}
-ClientActiveObject* ItemCAO::create(IGameDef *gamedef)
+ClientActiveObject* ItemCAO::create(IGameDef *gamedef, ClientEnvironment *env)
{
- return new ItemCAO(gamedef);
+ return new ItemCAO(gamedef, env);
}
-void ItemCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc)
+void ItemCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
+ IrrlichtDevice *irr)
{
if(m_node != NULL)
return;
void ItemCAO::processMessage(const std::string &data)
{
- infostream<<"ItemCAO: Got message"<<std::endl;
+ //infostream<<"ItemCAO: Got message"<<std::endl;
std::istringstream is(data, std::ios::binary);
// command
u8 cmd = readU8(is);
#include "inventory.h"
// Prototype
-RatCAO proto_RatCAO(NULL);
+RatCAO proto_RatCAO(NULL, NULL);
-RatCAO::RatCAO(IGameDef *gamedef):
- ClientActiveObject(0, gamedef),
+RatCAO::RatCAO(IGameDef *gamedef, ClientEnvironment *env):
+ ClientActiveObject(0, gamedef, env),
m_selection_box(-BS/3.,0.0,-BS/3., BS/3.,BS/2.,BS/3.),
m_node(NULL),
m_position(v3f(0,10*BS,0)),
{
}
-ClientActiveObject* RatCAO::create(IGameDef *gamedef)
+ClientActiveObject* RatCAO::create(IGameDef *gamedef, ClientEnvironment *env)
{
- return new RatCAO(gamedef);
+ return new RatCAO(gamedef, env);
}
-void RatCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc)
+void RatCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
+ IrrlichtDevice *irr)
{
if(m_node != NULL)
return;
#include "inventory.h"
// Prototype
-Oerkki1CAO proto_Oerkki1CAO(NULL);
+Oerkki1CAO proto_Oerkki1CAO(NULL, NULL);
-Oerkki1CAO::Oerkki1CAO(IGameDef *gamedef):
- ClientActiveObject(0, gamedef),
+Oerkki1CAO::Oerkki1CAO(IGameDef *gamedef, ClientEnvironment *env):
+ ClientActiveObject(0, gamedef, env),
m_selection_box(-BS/3.,0.0,-BS/3., BS/3.,BS*2.,BS/3.),
m_node(NULL),
m_position(v3f(0,10*BS,0)),
{
}
-ClientActiveObject* Oerkki1CAO::create(IGameDef *gamedef)
+ClientActiveObject* Oerkki1CAO::create(IGameDef *gamedef, ClientEnvironment *env)
{
- return new Oerkki1CAO(gamedef);
+ return new Oerkki1CAO(gamedef, env);
}
-void Oerkki1CAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc)
+void Oerkki1CAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
+ IrrlichtDevice *irr)
{
if(m_node != NULL)
return;
*/
// Prototype
-FireflyCAO proto_FireflyCAO(NULL);
+FireflyCAO proto_FireflyCAO(NULL, NULL);
-FireflyCAO::FireflyCAO(IGameDef *gamedef):
- ClientActiveObject(0, gamedef),
+FireflyCAO::FireflyCAO(IGameDef *gamedef, ClientEnvironment *env):
+ ClientActiveObject(0, gamedef, env),
m_selection_box(-BS/3.,0.0,-BS/3., BS/3.,BS/2.,BS/3.),
m_node(NULL),
m_position(v3f(0,10*BS,0)),
{
}
-ClientActiveObject* FireflyCAO::create(IGameDef *gamedef)
+ClientActiveObject* FireflyCAO::create(IGameDef *gamedef, ClientEnvironment *env)
{
- return new FireflyCAO(gamedef);
+ return new FireflyCAO(gamedef, env);
}
-void FireflyCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc)
+void FireflyCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
+ IrrlichtDevice *irr)
{
if(m_node != NULL)
return;
*/
// Prototype
-MobV2CAO proto_MobV2CAO(NULL);
+MobV2CAO proto_MobV2CAO(NULL, NULL);
-MobV2CAO::MobV2CAO(IGameDef *gamedef):
- ClientActiveObject(0, gamedef),
+MobV2CAO::MobV2CAO(IGameDef *gamedef, ClientEnvironment *env):
+ ClientActiveObject(0, gamedef, env),
m_selection_box(-0.4*BS,-0.4*BS,-0.4*BS, 0.4*BS,0.8*BS,0.4*BS),
m_node(NULL),
m_position(v3f(0,10*BS,0)),
delete m_properties;
}
-ClientActiveObject* MobV2CAO::create(IGameDef *gamedef)
+ClientActiveObject* MobV2CAO::create(IGameDef *gamedef, ClientEnvironment *env)
{
- return new MobV2CAO(gamedef);
+ return new MobV2CAO(gamedef, env);
}
-void MobV2CAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc)
+void MobV2CAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
+ IrrlichtDevice *irr)
{
if(m_node != NULL)
return;
#include "luaentity_common.h"
-class CLuaEntityCAO : public LuaEntityCAO
+class LuaEntityCAO : public ClientActiveObject
{
private:
core::aabbox3d<f32> m_selection_box;
float m_anim_timer;
public:
- CLuaEntityCAO(IGameDef *gamedef):
- LuaEntityCAO(gamedef),
+ LuaEntityCAO(IGameDef *gamedef, ClientEnvironment *env):
+ ClientActiveObject(0, gamedef, env),
m_selection_box(-BS/3.,-BS/3.,-BS/3., BS/3.,BS/3.,BS/3.),
m_meshnode(NULL),
m_spritenode(NULL),
m_anim_framelength(0.2),
m_anim_timer(0)
{
- ClientActiveObject::registerType(getType(), create);
+ if(gamedef == NULL)
+ ClientActiveObject::registerType(getType(), create);
}
void initialize(const std::string &data)
{
- infostream<<"CLuaEntityCAO: Got init data"<<std::endl;
+ infostream<<"LuaEntityCAO: Got init data"<<std::endl;
std::istringstream is(data, std::ios::binary);
// version
updateNodePos();
}
- ~CLuaEntityCAO()
+ ~LuaEntityCAO()
{
delete m_prop;
}
- static ClientActiveObject* create(IGameDef *gamedef)
+ static ClientActiveObject* create(IGameDef *gamedef, ClientEnvironment *env)
{
- return new CLuaEntityCAO(gamedef);
+ return new LuaEntityCAO(gamedef, env);
}
u8 getType() const
return pos_translator.vect_show;
}
- void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc)
+ void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
+ IrrlichtDevice *irr)
{
if(m_meshnode != NULL || m_spritenode != NULL)
return;
//video::IVideoDriver* driver = smgr->getVideoDriver();
if(m_prop->visual == "sprite"){
- infostream<<"CLuaEntityCAO::addToScene(): single_sprite"<<std::endl;
+ infostream<<"LuaEntityCAO::addToScene(): single_sprite"<<std::endl;
m_spritenode = new scene::MyBillboardSceneNode(
smgr->getRootSceneNode(), smgr, -1, v3f(0,0,0), v2f(1,1));
m_spritenode->setMaterialTexture(0,
m_spritenode->setTCoords(3, v2f(txs*0, tys*1));
}
} else if(m_prop->visual == "cube"){
- infostream<<"CLuaEntityCAO::addToScene(): cube"<<std::endl;
+ infostream<<"LuaEntityCAO::addToScene(): cube"<<std::endl;
video::SColor c(255,255,255,255);
video::S3DVertex vertices[24] =
{
// Will be shown when we know the brightness
m_meshnode->setVisible(false);
} else {
- infostream<<"CLuaEntityCAO::addToScene(): \""<<m_prop->visual
+ infostream<<"LuaEntityCAO::addToScene(): \""<<m_prop->visual
<<"\" not supported"<<std::endl;
}
updateTextures("");
void processMessage(const std::string &data)
{
- infostream<<"CLuaEntityCAO: Got message"<<std::endl;
+ //infostream<<"LuaEntityCAO: Got message"<<std::endl;
std::istringstream is(data, std::ios::binary);
// command
u8 cmd = readU8(is);
};
// Prototype
-CLuaEntityCAO proto_CLuaEntityCAO(NULL);
+LuaEntityCAO proto_LuaEntityCAO(NULL, NULL);
+
+/*
+ PlayerCAO
+*/
+
+class PlayerCAO : public ClientActiveObject
+{
+private:
+ core::aabbox3d<f32> m_selection_box;
+ scene::IMeshSceneNode *m_node;
+ scene::ITextSceneNode* m_text;
+ std::string m_name;
+ v3f m_position;
+ float m_yaw;
+ SmoothTranslator pos_translator;
+ bool m_is_local_player;
+
+public:
+ PlayerCAO(IGameDef *gamedef, ClientEnvironment *env):
+ ClientActiveObject(0, gamedef, env),
+ m_selection_box(-BS/3.,0.0,-BS/3., BS/3.,BS*2.0,BS/3.),
+ m_node(NULL),
+ m_text(NULL),
+ m_position(v3f(0,10*BS,0)),
+ m_yaw(0),
+ m_is_local_player(false)
+ {
+ if(gamedef == NULL)
+ ClientActiveObject::registerType(getType(), create);
+ }
+
+ void initialize(const std::string &data)
+ {
+ infostream<<"PlayerCAO: Got init data"<<std::endl;
+
+ std::istringstream is(data, std::ios::binary);
+ // version
+ u8 version = readU8(is);
+ // check version
+ if(version != 0)
+ return;
+ // name
+ m_name = deSerializeString(is);
+ // pos
+ m_position = readV3F1000(is);
+ // yaw
+ m_yaw = readF1000(is);
+
+ Player *player = m_env->getPlayer(m_name.c_str());
+ if(player && player->isLocal())
+ m_is_local_player = true;
+
+ updateNodePos();
+ }
+
+ ~PlayerCAO()
+ {
+ if(m_node)
+ m_node->remove();
+ }
+
+ static ClientActiveObject* create(IGameDef *gamedef, ClientEnvironment *env)
+ {
+ return new PlayerCAO(gamedef, env);
+ }
+
+ u8 getType() const
+ {
+ return ACTIVEOBJECT_TYPE_PLAYER;
+ }
+ core::aabbox3d<f32>* getSelectionBox()
+ {
+ if(m_is_local_player)
+ return NULL;
+ return &m_selection_box;
+ }
+ v3f getPosition()
+ {
+ return pos_translator.vect_show;
+ }
+
+ void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
+ IrrlichtDevice *irr)
+ {
+ if(m_node != NULL)
+ return;
+ if(m_is_local_player)
+ return;
+
+ //video::IVideoDriver* driver = smgr->getVideoDriver();
+ gui::IGUIEnvironment* gui = irr->getGUIEnvironment();
+
+ scene::SMesh *mesh = new scene::SMesh();
+ { // Front
+ scene::IMeshBuffer *buf = new scene::SMeshBuffer();
+ video::SColor c(255,255,255,255);
+ video::S3DVertex vertices[4] =
+ {
+ video::S3DVertex(-BS/2,0,0, 0,0,0, c, 0,1),
+ video::S3DVertex(BS/2,0,0, 0,0,0, c, 1,1),
+ video::S3DVertex(BS/2,BS*2,0, 0,0,0, c, 1,0),
+ video::S3DVertex(-BS/2,BS*2,0, 0,0,0, c, 0,0),
+ };
+ u16 indices[] = {0,1,2,2,3,0};
+ buf->append(vertices, 4, indices, 6);
+ // Set material
+ buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
+ buf->getMaterial().setTexture(0, tsrc->getTextureRaw("player.png"));
+ buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
+ buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
+ buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
+ // Add to mesh
+ mesh->addMeshBuffer(buf);
+ buf->drop();
+ }
+ { // Back
+ scene::IMeshBuffer *buf = new scene::SMeshBuffer();
+ video::SColor c(255,255,255,255);
+ video::S3DVertex vertices[4] =
+ {
+ video::S3DVertex(BS/2,0,0, 0,0,0, c, 1,1),
+ video::S3DVertex(-BS/2,0,0, 0,0,0, c, 0,1),
+ video::S3DVertex(-BS/2,BS*2,0, 0,0,0, c, 0,0),
+ video::S3DVertex(BS/2,BS*2,0, 0,0,0, c, 1,0),
+ };
+ u16 indices[] = {0,1,2,2,3,0};
+ buf->append(vertices, 4, indices, 6);
+ // Set material
+ buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
+ buf->getMaterial().setTexture(0, tsrc->getTextureRaw("player_back.png"));
+ buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
+ buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
+ buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
+ // Add to mesh
+ mesh->addMeshBuffer(buf);
+ buf->drop();
+ }
+ m_node = smgr->addMeshSceneNode(mesh, NULL);
+ mesh->drop();
+ // Set it to use the materials of the meshbuffers directly.
+ // This is needed for changing the texture in the future
+ m_node->setReadOnlyMaterials(true);
+ updateNodePos();
+
+ // Add a text node for showing the name
+ std::wstring wname = narrow_to_wide(m_name);
+ m_text = smgr->addTextSceneNode(gui->getBuiltInFont(),
+ wname.c_str(), video::SColor(255,255,255,255), m_node);
+ m_text->setPosition(v3f(0, (f32)BS*2.1, 0));
+
+ }
+
+ void removeFromScene()
+ {
+ if(m_node == NULL)
+ return;
+
+ m_node->remove();
+ m_node = NULL;
+ }
+
+ void updateLight(u8 light_at_pos)
+ {
+ if(m_node == NULL)
+ return;
+
+ if(light_at_pos <= 2)
+ {
+ m_node->setVisible(false);
+ return;
+ }
+
+ m_node->setVisible(true);
+
+ u8 li = decode_light(light_at_pos);
+ video::SColor color(255,li,li,li);
+ setMeshVerticesColor(m_node->getMesh(), color);
+ }
+
+ v3s16 getLightPosition()
+ {
+ return floatToInt(m_position+v3f(0,BS*1.5,0), BS);
+ }
+
+ void updateNodePos()
+ {
+ if(m_node == NULL)
+ return;
+
+ m_node->setPosition(pos_translator.vect_show);
+
+ v3f rot = m_node->getRotation();
+ rot.Y = -m_yaw;
+ m_node->setRotation(rot);
+ }
+
+ void step(float dtime, ClientEnvironment *env)
+ {
+ pos_translator.translate(dtime);
+ updateNodePos();
+ }
+
+ void processMessage(const std::string &data)
+ {
+ //infostream<<"PlayerCAO: Got message"<<std::endl;
+ std::istringstream is(data, std::ios::binary);
+ // command
+ u8 cmd = readU8(is);
+ if(cmd == 0) // update position
+ {
+ // pos
+ m_position = readV3F1000(is);
+ // yaw
+ m_yaw = readF1000(is);
+
+ pos_translator.update(m_position, false);
+
+ updateNodePos();
+ }
+ }
+};
+
+// Prototype
+PlayerCAO proto_PlayerCAO(NULL, NULL);
#ifndef CONTENT_CAO_HEADER
#define CONTENT_CAO_HEADER
-#include "clientobject.h"
-#include "content_object.h"
-#include "utility.h" // For IntervalLimiter
-class Settings;
-#include "MyBillboardSceneNode.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():
- vect_old(0,0,0),
- vect_show(0,0,0),
- vect_aim(0,0,0),
- anim_counter(0),
- anim_time(0),
- anim_time_counter(0),
- aim_is_end(true)
- {}
-
- void init(v3f vect)
- {
- vect_old = vect;
- vect_show = vect;
- vect_aim = vect;
- anim_counter = 0;
- anim_time = 0;
- anim_time_counter = 0;
- aim_is_end = true;
- }
-
- void sharpen()
- {
- init(vect_show);
- }
-
- void update(v3f vect_new, bool is_end_position=false, float update_interval=-1)
- {
- aim_is_end = is_end_position;
- vect_old = vect_show;
- vect_aim = vect_new;
- if(update_interval > 0){
- anim_time = update_interval;
- } else {
- if(anim_time < 0.001 || anim_time > 1.0)
- anim_time = anim_time_counter;
- else
- anim_time = anim_time * 0.9 + anim_time_counter * 0.1;
- }
- anim_time_counter = 0;
- anim_counter = 0;
- }
-
- void translate(f32 dtime)
- {
- anim_time_counter = anim_time_counter + dtime;
- anim_counter = anim_counter + dtime;
- v3f vect_move = vect_aim - vect_old;
- f32 moveratio = 1.0;
- if(anim_time > 0.001)
- moveratio = anim_time_counter / anim_time;
- // Move a bit less than should, to avoid oscillation
- moveratio = moveratio * 0.8;
- float move_end = 1.5;
- if(aim_is_end)
- move_end = 1.0;
- if(moveratio > move_end)
- moveratio = move_end;
- vect_show = vect_old + vect_move * moveratio;
- }
-
- bool is_moving()
- {
- return ((anim_time_counter / anim_time) < 1.4);
- }
-};
-
-
-/*
- TestCAO
-*/
-
-class TestCAO : public ClientActiveObject
-{
-public:
- TestCAO(IGameDef *gamedef);
- virtual ~TestCAO();
-
- u8 getType() const
- {
- return ACTIVEOBJECT_TYPE_TEST;
- }
-
- static ClientActiveObject* create(IGameDef *gamedef);
-
- void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
- void removeFromScene();
- void updateLight(u8 light_at_pos);
- v3s16 getLightPosition();
- void updateNodePos();
-
- void step(float dtime, ClientEnvironment *env);
-
- void processMessage(const std::string &data);
-
-private:
- scene::IMeshSceneNode *m_node;
- v3f m_position;
-};
-
-/*
- ItemCAO
-*/
-
-class ItemCAO : public ClientActiveObject
-{
-public:
- ItemCAO(IGameDef *gamedef);
- virtual ~ItemCAO();
-
- u8 getType() const
- {
- return ACTIVEOBJECT_TYPE_ITEM;
- }
-
- static ClientActiveObject* create(IGameDef *gamedef);
-
- void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
- void removeFromScene();
- void updateLight(u8 light_at_pos);
- v3s16 getLightPosition();
- void updateNodePos();
-
- void step(float dtime, ClientEnvironment *env);
-
- void processMessage(const std::string &data);
-
- void initialize(const std::string &data);
-
- core::aabbox3d<f32>* getSelectionBox()
- {return &m_selection_box;}
- v3f getPosition()
- {return m_position;}
-
-private:
- core::aabbox3d<f32> m_selection_box;
- scene::IMeshSceneNode *m_node;
- v3f m_position;
- std::string m_inventorystring;
-};
-
-/*
- RatCAO
-*/
-
-class RatCAO : public ClientActiveObject
-{
-public:
- RatCAO(IGameDef *gamedef);
- virtual ~RatCAO();
-
- u8 getType() const
- {
- return ACTIVEOBJECT_TYPE_RAT;
- }
-
- static ClientActiveObject* create(IGameDef *gamedef);
-
- void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
- void removeFromScene();
- void updateLight(u8 light_at_pos);
- v3s16 getLightPosition();
- void updateNodePos();
-
- void step(float dtime, ClientEnvironment *env);
-
- void processMessage(const std::string &data);
-
- void initialize(const std::string &data);
-
- core::aabbox3d<f32>* getSelectionBox()
- {return &m_selection_box;}
- v3f getPosition()
- {return pos_translator.vect_show;}
- //{return m_position;}
-
-private:
- core::aabbox3d<f32> m_selection_box;
- scene::IMeshSceneNode *m_node;
- v3f m_position;
- float m_yaw;
- SmoothTranslator pos_translator;
-};
-
-/*
- Oerkki1CAO
-*/
-
-class Oerkki1CAO : public ClientActiveObject
-{
-public:
- Oerkki1CAO(IGameDef *gamedef);
- virtual ~Oerkki1CAO();
-
- u8 getType() const
- {
- return ACTIVEOBJECT_TYPE_OERKKI1;
- }
-
- static ClientActiveObject* create(IGameDef *gamedef);
-
- void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
- void removeFromScene();
- void updateLight(u8 light_at_pos);
- v3s16 getLightPosition();
- void updateNodePos();
-
- void step(float dtime, ClientEnvironment *env);
-
- void processMessage(const std::string &data);
-
- void initialize(const std::string &data);
-
- core::aabbox3d<f32>* getSelectionBox()
- {return &m_selection_box;}
- v3f getPosition()
- {return pos_translator.vect_show;}
- //{return m_position;}
-
- // If returns true, punch will not be sent to the server
- bool directReportPunch(const std::string &toolname, v3f dir);
-
-private:
- IntervalLimiter m_attack_interval;
- core::aabbox3d<f32> m_selection_box;
- scene::IMeshSceneNode *m_node;
- v3f m_position;
- float m_yaw;
- SmoothTranslator pos_translator;
- float m_damage_visual_timer;
- bool m_damage_texture_enabled;
-};
-
-/*
- FireflyCAO
-*/
-
-class FireflyCAO : public ClientActiveObject
-{
-public:
- FireflyCAO(IGameDef *gamedef);
- virtual ~FireflyCAO();
-
- u8 getType() const
- {
- return ACTIVEOBJECT_TYPE_FIREFLY;
- }
-
- static ClientActiveObject* create(IGameDef *gamedef);
-
- void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
- void removeFromScene();
- void updateLight(u8 light_at_pos);
- v3s16 getLightPosition();
- void updateNodePos();
-
- void step(float dtime, ClientEnvironment *env);
-
- void processMessage(const std::string &data);
-
- void initialize(const std::string &data);
-
- core::aabbox3d<f32>* getSelectionBox()
- {return &m_selection_box;}
- v3f getPosition()
- {return m_position;}
-
-private:
- core::aabbox3d<f32> m_selection_box;
- scene::IMeshSceneNode *m_node;
- v3f m_position;
- float m_yaw;
- SmoothTranslator pos_translator;
-};
-
-/*
- MobV2CAO
-*/
-
-class MobV2CAO : public ClientActiveObject
-{
-public:
- MobV2CAO(IGameDef *gamedef);
- virtual ~MobV2CAO();
-
- u8 getType() const
- {
- return ACTIVEOBJECT_TYPE_MOBV2;
- }
-
- static ClientActiveObject* create(IGameDef *gamedef);
-
- void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
- void removeFromScene();
- void updateLight(u8 light_at_pos);
- v3s16 getLightPosition();
- void updateNodePos();
-
- void step(float dtime, ClientEnvironment *env);
-
- void processMessage(const std::string &data);
-
- void initialize(const std::string &data);
-
- core::aabbox3d<f32>* getSelectionBox()
- {return &m_selection_box;}
- v3f getPosition()
- {return pos_translator.vect_show;}
- //{return m_position;}
- bool doShowSelectionBox(){return false;}
-
- // If returns true, punch will not be sent to the server
- bool directReportPunch(const std::string &toolname, v3f dir);
-
-private:
- void setLooks(const std::string &looks);
-
- IntervalLimiter m_attack_interval;
- core::aabbox3d<f32> m_selection_box;
- scene::MyBillboardSceneNode *m_node;
- v3f m_position;
- std::string m_texture_name;
- float m_yaw;
- SmoothTranslator pos_translator;
- bool m_walking;
- float m_walking_unset_timer;
- float m_walk_timer;
- int m_walk_frame;
- float m_damage_visual_timer;
- u8 m_last_light;
- bool m_shooting;
- float m_shooting_unset_timer;
- v2f m_sprite_size;
- float m_sprite_y;
- bool m_bright_shooting;
- std::string m_sprite_type;
- int m_simple_anim_frames;
- float m_simple_anim_frametime;
- bool m_lock_full_brightness;
- int m_player_hit_damage;
- float m_player_hit_distance;
- float m_player_hit_interval;
- float m_player_hit_timer;
-
- Settings *m_properties;
-};
-
-/*
- LuaEntityCAO
-*/
-
-class LuaEntityCAO : public ClientActiveObject
-{
-public:
- LuaEntityCAO(IGameDef *gamedef):
- ClientActiveObject(0, gamedef)
- {}
- virtual ~LuaEntityCAO(){}
- virtual u8 getType() const=0;
- virtual void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc)=0;
- virtual void removeFromScene()=0;
- virtual void updateLight(u8 light_at_pos)=0;
- virtual v3s16 getLightPosition()=0;
- virtual void updateNodePos()=0;
- virtual void step(float dtime, ClientEnvironment *env)=0;
- virtual void processMessage(const std::string &data)=0;
- virtual void initialize(const std::string &data)=0;
- virtual core::aabbox3d<f32>* getSelectionBox()=0;
- virtual v3f getPosition()=0;
-private:
-};
-
-
#endif
#define ACTIVEOBJECT_TYPE_LUAENTITY 7
-// Special type, not stored in active object lists
+// Special type, not stored as a static object
#define ACTIVEOBJECT_TYPE_PLAYER 100
#endif
m_messages_out.push_back(aom);
}
+/*
+ PlayerSAO
+*/
+
+// Prototype
+PlayerSAO proto_PlayerSAO(NULL, v3f(0,0,0), NULL);
+
+PlayerSAO::PlayerSAO(ServerEnvironment *env, v3f pos,
+ ServerRemotePlayer *player):
+ ServerActiveObject(env, pos),
+ m_player(player),
+ m_position_updated(true)
+{
+ if(m_player)
+ m_player->setSAO(this);
+}
+
+PlayerSAO::~PlayerSAO()
+{
+ if(m_player)
+ m_player->setSAO(NULL);
+}
+
+void PlayerSAO::step(float dtime, bool send_recommended)
+{
+ if(!m_player)
+ return;
+
+ if(send_recommended == false)
+ return;
+
+ if(m_position_updated)
+ {
+ m_position_updated = false;
+
+ std::ostringstream os(std::ios::binary);
+ // command (0 = update position)
+ writeU8(os, 0);
+ // pos
+ writeV3F1000(os, m_player->getPosition());
+ // yaw
+ writeF1000(os, m_player->getYaw());
+ // create message and add to list
+ ActiveObjectMessage aom(getId(), false, os.str());
+ m_messages_out.push_back(aom);
+ }
+}
+
+std::string PlayerSAO::getClientInitializationData()
+{
+ if(!m_player)
+ return "";
+
+ std::ostringstream os(std::ios::binary);
+ // version
+ writeU8(os, 0);
+ // name
+ os<<serializeString(m_player->getName());
+ // pos
+ writeV3F1000(os, m_player->getPosition());
+ // yaw
+ writeF1000(os, m_player->getYaw());
+ return os.str();
+}
+
+std::string PlayerSAO::getStaticData()
+{
+ assert(0);
+ return "";
+}
+
+void PlayerSAO::punch(ServerActiveObject *puncher)
+{
+ infostream<<"TODO: PlayerSAO::punch()"<<std::endl;
+}
+
+void PlayerSAO::setPlayer(ServerRemotePlayer *player)
+{
+ infostream<<"PlayerSAO id="<<getId()<<" got player \""
+ <<(player?player->getName():"(NULL)")<<"\""<<std::endl;
+ m_player = player;
+}
+
+ServerRemotePlayer* PlayerSAO::getPlayer()
+{
+ return m_player;
+}
+
+void PlayerSAO::positionUpdated()
+{
+ m_position_updated = true;
+}
float m_last_sent_move_precision;
};
+class ServerRemotePlayer;
+
+class PlayerSAO : public ServerActiveObject
+{
+public:
+ PlayerSAO(ServerEnvironment *env, v3f pos,
+ ServerRemotePlayer *player);
+ ~PlayerSAO();
+ u8 getType() const
+ {return ACTIVEOBJECT_TYPE_PLAYER;}
+ void step(float dtime, bool send_recommended);
+ std::string getClientInitializationData();
+ std::string getStaticData();
+ bool isStaticAllowed() const
+ { return false; }
+ void punch(ServerActiveObject *puncher);
+ /* PlayerSAO-specific */
+ void setPlayer(ServerRemotePlayer *player);
+ ServerRemotePlayer* getPlayer();
+ void positionUpdated();
+private:
+ ServerRemotePlayer *m_player;
+ bool m_position_updated;
+};
+
#endif
}
if(newplayer)
+ {
addPlayer(player);
+ }
}
}
<<m_active_objects.size()<<" active objects."
<<std::endl;
- // Add static object to active static list of the block
- v3f objectpos = object->getBasePosition();
- std::string staticdata = object->getStaticData();
- StaticObject s_obj(object->getType(), objectpos, staticdata);
- // Add to the block where the object is located in
- v3s16 blockpos = getNodeBlockPos(floatToInt(objectpos, BS));
- MapBlock *block = m_map->getBlockNoCreateNoEx(blockpos);
- if(block)
- {
- block->m_static_objects.m_active.insert(object->getId(), s_obj);
- object->m_static_exists = true;
- object->m_static_block = blockpos;
-
- if(set_changed)
- block->raiseModified(MOD_STATE_WRITE_NEEDED,
- "addActiveObjectRaw");
- }
- else{
- errorstream<<"ServerEnvironment::addActiveObjectRaw(): "
- <<"could not find block for storing id="<<object->getId()
- <<" statically"<<std::endl;
- }
-
// Register reference in scripting api (must be done before post-init)
scriptapi_add_object_reference(m_lua, object);
// Post-initialize object
object->addedToEnvironment();
+
+ // Add static data to block
+ if(object->isStaticAllowed())
+ {
+ // Add static object to active static list of the block
+ v3f objectpos = object->getBasePosition();
+ std::string staticdata = object->getStaticData();
+ StaticObject s_obj(object->getType(), objectpos, staticdata);
+ // Add to the block where the object is located in
+ v3s16 blockpos = getNodeBlockPos(floatToInt(objectpos, BS));
+ MapBlock *block = m_map->getBlockNoCreateNoEx(blockpos);
+ if(block)
+ {
+ block->m_static_objects.m_active.insert(object->getId(), s_obj);
+ object->m_static_exists = true;
+ object->m_static_block = blockpos;
+ if(set_changed)
+ block->raiseModified(MOD_STATE_WRITE_NEEDED,
+ "addActiveObjectRaw");
+ }
+ else{
+ errorstream<<"ServerEnvironment::addActiveObjectRaw(): "
+ <<"could not find block for storing id="<<object->getId()
+ <<" statically"<<std::endl;
+ }
+ }
+
return object->getId();
}
i.atEnd()==false; i++)
{
ServerActiveObject* obj = i.getNode()->getValue();
-
- // This shouldn't happen but check it
- if(obj == NULL)
- {
- errorstream<<"NULL object found in ServerEnvironment"
- <<std::endl;
- assert(0);
+ assert(obj);
+
+ // Do not deactivate if static data creation not allowed
+ if(!force_delete && !obj->isStaticAllowed())
continue;
- }
// If pending deactivation, let removeRemovedObjects() do it
- if(obj->m_pending_deactivation)
+ if(!force_delete && obj->m_pending_deactivation)
continue;
u16 id = i.getNode()->getKey();
v3s16 blockpos_o = getNodeBlockPos(floatToInt(objectpos, BS));
// If block is active, don't remove
- if(m_active_blocks.contains(blockpos_o))
+ if(!force_delete && m_active_blocks.contains(blockpos_o))
continue;
verbosestream<<"ServerEnvironment::deactivateFarObjects(): "
Update the static data
*/
- // Create new static object
- std::string staticdata_new = obj->getStaticData();
- StaticObject s_obj(obj->getType(), objectpos, staticdata_new);
-
- bool stays_in_same_block = false;
- bool data_changed = true;
+ if(obj->isStaticAllowed())
+ {
+ // Create new static object
+ std::string staticdata_new = obj->getStaticData();
+ StaticObject s_obj(obj->getType(), objectpos, staticdata_new);
+
+ bool stays_in_same_block = false;
+ bool data_changed = true;
- if(obj->m_static_exists){
- if(obj->m_static_block == blockpos_o)
- stays_in_same_block = true;
+ if(obj->m_static_exists){
+ if(obj->m_static_block == blockpos_o)
+ stays_in_same_block = true;
- MapBlock *block = m_map->emergeBlock(obj->m_static_block, false);
-
- core::map<u16, StaticObject>::Node *n =
- block->m_static_objects.m_active.find(id);
- if(n){
- StaticObject static_old = n->getValue();
-
- float save_movem = obj->getMinimumSavedMovement();
-
- if(static_old.data == staticdata_new &&
- (static_old.pos - objectpos).getLength() < save_movem)
- data_changed = false;
- } else {
- errorstream<<"ServerEnvironment::deactivateFarObjects(): "
- <<"id="<<id<<" m_static_exists=true but "
- <<"static data doesn't actually exist in "
- <<PP(obj->m_static_block)<<std::endl;
+ MapBlock *block = m_map->emergeBlock(obj->m_static_block, false);
+
+ core::map<u16, StaticObject>::Node *n =
+ block->m_static_objects.m_active.find(id);
+ if(n){
+ StaticObject static_old = n->getValue();
+
+ float save_movem = obj->getMinimumSavedMovement();
+
+ if(static_old.data == staticdata_new &&
+ (static_old.pos - objectpos).getLength() < save_movem)
+ data_changed = false;
+ } else {
+ errorstream<<"ServerEnvironment::deactivateFarObjects(): "
+ <<"id="<<id<<" m_static_exists=true but "
+ <<"static data doesn't actually exist in "
+ <<PP(obj->m_static_block)<<std::endl;
+ }
}
- }
- bool shall_be_written = (!stays_in_same_block || data_changed);
-
- // Delete old static object
- if(obj->m_static_exists)
- {
- MapBlock *block = m_map->emergeBlock(obj->m_static_block, false);
- if(block)
+ bool shall_be_written = (!stays_in_same_block || data_changed);
+
+ // Delete old static object
+ if(obj->m_static_exists)
{
- block->m_static_objects.remove(id);
- obj->m_static_exists = false;
- // Only mark block as modified if data changed considerably
- if(shall_be_written)
- block->raiseModified(MOD_STATE_WRITE_NEEDED,
- "deactivateFarObjects: Static data "
- "changed considerably");
+ MapBlock *block = m_map->emergeBlock(obj->m_static_block, false);
+ if(block)
+ {
+ block->m_static_objects.remove(id);
+ obj->m_static_exists = false;
+ // Only mark block as modified if data changed considerably
+ if(shall_be_written)
+ block->raiseModified(MOD_STATE_WRITE_NEEDED,
+ "deactivateFarObjects: Static data "
+ "changed considerably");
+ }
}
- }
- // Add to the block where the object is located in
- v3s16 blockpos = getNodeBlockPos(floatToInt(objectpos, BS));
- // Get or generate the block
- MapBlock *block = m_map->emergeBlock(blockpos);
+ // Add to the block where the object is located in
+ v3s16 blockpos = getNodeBlockPos(floatToInt(objectpos, BS));
+ // Get or generate the block
+ MapBlock *block = m_map->emergeBlock(blockpos);
- if(block)
- {
- if(block->m_static_objects.m_stored.size() >= 49){
- errorstream<<"ServerEnv: Trying to store id="<<obj->getId()
- <<" statically but block "<<PP(blockpos)
- <<" already contains "
- <<block->m_static_objects.m_stored.size()
- <<" (over 49) objects."
- <<" Forcing delete."<<std::endl;
- force_delete = true;
- } else {
- u16 new_id = pending_delete ? id : 0;
- block->m_static_objects.insert(new_id, s_obj);
-
- // Only mark block as modified if data changed considerably
- if(shall_be_written)
- block->raiseModified(MOD_STATE_WRITE_NEEDED,
- "deactivateFarObjects: Static data "
- "changed considerably");
-
- obj->m_static_exists = true;
- obj->m_static_block = block->getPos();
+ if(block)
+ {
+ if(block->m_static_objects.m_stored.size() >= 49){
+ errorstream<<"ServerEnv: Trying to store id="<<obj->getId()
+ <<" statically but block "<<PP(blockpos)
+ <<" already contains "
+ <<block->m_static_objects.m_stored.size()
+ <<" (over 49) objects."
+ <<" Forcing delete."<<std::endl;
+ force_delete = true;
+ } else {
+ u16 new_id = pending_delete ? id : 0;
+ block->m_static_objects.insert(new_id, s_obj);
+
+ // Only mark block as modified if data changed considerably
+ if(shall_be_written)
+ block->raiseModified(MOD_STATE_WRITE_NEEDED,
+ "deactivateFarObjects: Static data "
+ "changed considerably");
+
+ obj->m_static_exists = true;
+ obj->m_static_block = block->getPos();
+ }
+ }
+ else{
+ if(!force_delete){
+ errorstream<<"ServerEnv: Could not find or generate "
+ <<"a block for storing id="<<obj->getId()
+ <<" statically"<<std::endl;
+ continue;
+ }
}
- }
- else{
- errorstream<<"ServerEnv: Could not find or generate "
- <<"a block for storing id="<<obj->getId()
- <<" statically"<<std::endl;
- continue;
}
/*
Otherwise delete it immediately.
*/
- if(pending_delete)
+ if(pending_delete && !force_delete)
{
verbosestream<<"ServerEnvironment::deactivateFarObjects(): "
<<"object id="<<id<<" is known by clients"
*/
ClientEnvironment::ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr,
- ITextureSource *texturesource, IGameDef *gamedef):
+ ITextureSource *texturesource, IGameDef *gamedef,
+ IrrlichtDevice *irr):
m_map(map),
m_smgr(smgr),
m_texturesource(texturesource),
- m_gamedef(gamedef)
+ m_gamedef(gamedef),
+ m_irr(irr)
{
- assert(m_map);
- assert(m_smgr);
}
ClientEnvironment::~ClientEnvironment()
infostream<<"ClientEnvironment::addActiveObject(): "
<<"added (id="<<object->getId()<<")"<<std::endl;
m_active_objects.insert(object->getId(), object);
- object->addToScene(m_smgr, m_texturesource);
+ object->addToScene(m_smgr, m_texturesource, m_irr);
{ // Update lighting immediately
u8 light = 0;
try{
void ClientEnvironment::addActiveObject(u16 id, u8 type,
const std::string &init_data)
{
- ClientActiveObject* obj = ClientActiveObject::create(type, m_gamedef);
+ ClientActiveObject* obj =
+ ClientActiveObject::create(type, m_gamedef, this);
if(obj == NULL)
{
infostream<<"ClientEnvironment::addActiveObject(): "
{
public:
ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr,
- ITextureSource *texturesource, IGameDef *gamedef);
+ ITextureSource *texturesource, IGameDef *gamedef,
+ IrrlichtDevice *device);
~ClientEnvironment();
Map & getMap()
scene::ISceneManager *m_smgr;
ITextureSource *m_texturesource;
IGameDef *m_gamedef;
+ IrrlichtDevice *m_irr;
core::map<u16, ClientActiveObject*> m_active_objects;
Queue<ClientEnvEvent> m_client_event_queue;
IntervalLimiter m_active_object_light_update_interval;
#include "nodedef.h"
#include "environment.h"
#include "gamedef.h"
+#include "content_sao.h"
Player::Player(IGameDef *gamedef):
touching_ground(false),
m_last_good_position_age(0),
m_additional_items(),
m_inventory_not_sent(false),
- m_hp_not_sent(false)
+ m_hp_not_sent(false),
+ m_sao(NULL)
{
}
ServerRemotePlayer::ServerRemotePlayer(ServerEnvironment *env, v3f pos_, u16 peer_id_,
Player(env->getGameDef()),
ServerActiveObject(env, pos_),
m_inventory_not_sent(false),
- m_hp_not_sent(false)
+ m_hp_not_sent(false),
+ m_sao(NULL)
{
setPosition(pos_);
peer_id = peer_id_;
ServerRemotePlayer::~ServerRemotePlayer()
{
clearAddToInventoryLater();
+ if(m_sao)
+ m_sao->setPlayer(NULL);
+}
+
+void ServerRemotePlayer::setPosition(const v3f &position)
+{
+ Player::setPosition(position);
+ ServerActiveObject::setBasePosition(position);
+ if(m_sao)
+ m_sao->positionUpdated();
+}
+
+void ServerRemotePlayer::setSAO(PlayerSAO *sao)
+{
+ infostream<<"ServerRemotePlayer \""<<getName()
+ <<"\" got sao="<<sao<<std::endl;
+ m_sao = sao;
+}
+
+PlayerSAO* ServerRemotePlayer::getSAO()
+{
+ return m_sao;
}
/* ServerActiveObject interface */
#ifndef SERVER
+#if 0
RemotePlayer::RemotePlayer(
IGameDef *gamedef,
scene::ISceneNode* parent,
ISceneNode::setPosition(m_showpos);
}
+#endif
#endif
#include "serverobject.h"
#include "content_object.h" // Object type IDs
+class PlayerSAO;
+
class ServerRemotePlayer : public Player, public ServerActiveObject
{
public:
{
}
- virtual void setPosition(const v3f &position)
- {
- Player::setPosition(position);
- ServerActiveObject::setBasePosition(position);
- }
+ virtual void setPosition(const v3f &position);
+ void setSAO(PlayerSAO *sao);
+ PlayerSAO* getSAO();
+
/* ServerActiveObject interface */
u8 getType() const
bool m_hp_not_sent;
private:
+
+ PlayerSAO *m_sao;
};
#ifndef SERVER
+#if 0
/*
All the other players on the client are these
*/
f32 m_pos_animation_time_counter;
v3f m_showpos;
};
+#endif
#endif // !SERVER
return NULL;
if(obj->getType() != ACTIVEOBJECT_TYPE_PLAYER)
return NULL;
- return static_cast<ServerRemotePlayer*>(obj);
+ PlayerSAO *player_sao = static_cast<PlayerSAO*>(obj);
+ return player_sao->getPlayer();
+ //return static_cast<ServerRemotePlayer*>(obj);
}
// Exported functions
#include "craftitemdef.h"
#include "mapgen.h"
#include "content_abm.h"
+#include "content_sao.h" // For PlayerSAO
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
}
// Get player
- Player *player = emergePlayer(playername, peer_id);
+ ServerRemotePlayer *player = emergePlayer(playername, peer_id);
// If failed, cancel
if(player == NULL)
return;
}
+ // Add PlayerSAO
+ PlayerSAO *sao = new PlayerSAO(m_env, player->getPosition(), player);
+ m_env->addActiveObject(sao);
+
/*
Answer with a TOCLIENT_INIT
*/
return intToFloat(nodepos, BS);
}
-Player *Server::emergePlayer(const char *name, u16 peer_id)
+ServerRemotePlayer *Server::emergePlayer(const char *name, u16 peer_id)
{
/*
Try to get an existing player
*/
- Player *player = m_env->getPlayer(name);
+ ServerRemotePlayer *player =
+ static_cast<ServerRemotePlayer*>(m_env->getPlayer(name));
if(player != NULL)
{
// If player is already connected, cancel
obj->m_known_by_count--;
}
+ ServerRemotePlayer* player =
+ static_cast<ServerRemotePlayer*>(m_env->getPlayer(c.peer_id));
+
// Collect information about leaving in chat
std::wstring message;
{
- Player *player = m_env->getPlayer(c.peer_id);
if(player != NULL)
{
std::wstring name = narrow_to_wide(player->getName());
message += L" (timed out)";
}
}
-
- /*// Delete player
+
+ // Remove PlayerSAO
+ if(player != NULL)
{
- m_env->removePlayer(c.peer_id);
- }*/
-
+ PlayerSAO *sao = player->getSAO();
+ if(sao){
+ sao->setPlayer(NULL);
+ sao->m_removed = true;
+ }
+ player->setSAO(NULL);
+ }
+
// Set player client disconnected
+ if(player != NULL)
+ player->peer_id = 0;
+
+ /*
+ Print out action
+ */
{
- Player *player = m_env->getPlayer(c.peer_id);
- if(player != NULL)
- player->peer_id = 0;
-
- /*
- Print out action
- */
if(player != NULL)
{
std::ostringstream os(std::ios_base::binary);
Call with env and con locked.
*/
- Player *emergePlayer(const char *name, u16 peer_id);
+ ServerRemotePlayer *emergePlayer(const char *name, u16 peer_id);
// Locks environment and connection by its own
struct PeerChange;
virtual void addedToEnvironment(){};
// Called before removing from environment
virtual void removingFromEnvironment(){};
+ // Returns true if object's deletion is the job of the
+ // environment
+ virtual bool environmentDeletes() const
+ { return true; }
// Create a certain type of ServerActiveObject
static ServerActiveObject* create(u8 type,
when it is created (converted from static to active - actually
the data is the static form)
*/
- virtual std::string getStaticData(){return "";}
+ virtual std::string getStaticData()
+ {
+ assert(isStaticAllowed());
+ return "";
+ }
/*
Return false in here to never save and instead remove object
on unload. getStaticData() will not be called in that case.
*/
- virtual bool isStaticAllowed(){return true;}
+ virtual bool isStaticAllowed() const
+ {return true;}
virtual void punch(ServerActiveObject *puncher){}
virtual void rightClick(ServerActiveObject *clicker){}
bool m_removed;
/*
- This is set to true when a block should be removed from the active
+ This is set to true when an object should be removed from the active
object list but couldn't be removed because the id has to be
reserved for some client.
The environment checks this periodically. If this is true and also
- m_known_by_count is true,
+ m_known_by_count is true, object is deleted from the active object
+ list.
*/
bool m_pending_deactivation;