mirror of
https://github.com/minetest/minetest.git
synced 2024-12-28 00:47:29 +01:00
Player-is-SAO WIP
This commit is contained in:
parent
9dcfa882b1
commit
ee0d3bacbc
@ -205,7 +205,7 @@ Client::Client(
|
||||
device->getSceneManager()->getRootSceneNode(),
|
||||
device->getSceneManager(), 666),
|
||||
device->getSceneManager(),
|
||||
tsrc, this
|
||||
tsrc, this, device
|
||||
),
|
||||
m_con(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, this),
|
||||
m_device(device),
|
||||
@ -1010,6 +1010,8 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
||||
}
|
||||
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
|
||||
@ -1111,6 +1113,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
||||
m_env.removePlayer((*ip)->peer_id);
|
||||
}
|
||||
} //envlock
|
||||
#endif
|
||||
}
|
||||
else if(command == TOCLIENT_SECTORMETA)
|
||||
{
|
||||
|
@ -26,9 +26,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
@ -37,7 +39,8 @@ ClientActiveObject::~ClientActiveObject()
|
||||
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;
|
||||
@ -51,7 +54,7 @@ ClientActiveObject* ClientActiveObject::create(u8 type, IGameDef *gamedef)
|
||||
}
|
||||
|
||||
Factory f = n->getValue();
|
||||
ClientActiveObject *object = (*f)(gamedef);
|
||||
ClientActiveObject *object = (*f)(gamedef, env);
|
||||
return object;
|
||||
}
|
||||
|
||||
|
@ -42,10 +42,11 @@ class IGameDef;
|
||||
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){}
|
||||
@ -70,7 +71,8 @@ public:
|
||||
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)
|
||||
@ -78,9 +80,10 @@ public:
|
||||
|
||||
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;
|
||||
|
@ -22,20 +22,393 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#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))
|
||||
{
|
||||
@ -46,12 +419,13 @@ TestCAO::~TestCAO()
|
||||
{
|
||||
}
|
||||
|
||||
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;
|
||||
@ -147,10 +521,10 @@ void TestCAO::processMessage(const std::string &data)
|
||||
#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))
|
||||
@ -162,12 +536,13 @@ ItemCAO::~ItemCAO()
|
||||
{
|
||||
}
|
||||
|
||||
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;
|
||||
@ -288,7 +663,7 @@ void ItemCAO::step(float dtime, ClientEnvironment *env)
|
||||
|
||||
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);
|
||||
@ -327,10 +702,10 @@ void ItemCAO::initialize(const std::string &data)
|
||||
#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)),
|
||||
@ -343,12 +718,13 @@ RatCAO::~RatCAO()
|
||||
{
|
||||
}
|
||||
|
||||
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;
|
||||
@ -472,10 +848,10 @@ void RatCAO::initialize(const std::string &data)
|
||||
#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)),
|
||||
@ -490,12 +866,13 @@ Oerkki1CAO::~Oerkki1CAO()
|
||||
{
|
||||
}
|
||||
|
||||
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;
|
||||
@ -712,10 +1089,10 @@ bool Oerkki1CAO::directReportPunch(const std::string &toolname, v3f dir)
|
||||
*/
|
||||
|
||||
// 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)),
|
||||
@ -728,12 +1105,13 @@ FireflyCAO::~FireflyCAO()
|
||||
{
|
||||
}
|
||||
|
||||
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;
|
||||
@ -855,10 +1233,10 @@ void FireflyCAO::initialize(const std::string &data)
|
||||
*/
|
||||
|
||||
// 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)),
|
||||
@ -887,12 +1265,13 @@ MobV2CAO::~MobV2CAO()
|
||||
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;
|
||||
@ -1269,7 +1648,7 @@ void MobV2CAO::setLooks(const std::string &looks)
|
||||
|
||||
#include "luaentity_common.h"
|
||||
|
||||
class CLuaEntityCAO : public LuaEntityCAO
|
||||
class LuaEntityCAO : public ClientActiveObject
|
||||
{
|
||||
private:
|
||||
core::aabbox3d<f32> m_selection_box;
|
||||
@ -1291,8 +1670,8 @@ private:
|
||||
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),
|
||||
@ -1309,12 +1688,13 @@ public:
|
||||
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
|
||||
@ -1346,14 +1726,14 @@ public:
|
||||
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
|
||||
@ -1369,7 +1749,8 @@ public:
|
||||
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;
|
||||
@ -1377,7 +1758,7 @@ public:
|
||||
//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,
|
||||
@ -1398,7 +1779,7 @@ public:
|
||||
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] =
|
||||
{
|
||||
@ -1461,7 +1842,7 @@ public:
|
||||
// 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("");
|
||||
@ -1640,7 +2021,7 @@ public:
|
||||
|
||||
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);
|
||||
@ -1692,6 +2073,230 @@ public:
|
||||
};
|
||||
|
||||
// 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);
|
||||
|
||||
|
||||
|
@ -20,398 +20,5 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#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
|
||||
|
||||
|
@ -29,7 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
|
||||
#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
|
||||
|
@ -1799,4 +1799,96 @@ void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end)
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -240,5 +240,30 @@ private:
|
||||
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
|
||||
|
||||
|
@ -491,7 +491,9 @@ void ServerEnvironment::deSerializePlayers(const std::string &savedir)
|
||||
}
|
||||
|
||||
if(newplayer)
|
||||
{
|
||||
addPlayer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1320,34 +1322,38 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
|
||||
<<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();
|
||||
}
|
||||
|
||||
@ -1547,18 +1553,14 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
|
||||
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();
|
||||
@ -1568,7 +1570,7 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
|
||||
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(): "
|
||||
@ -1582,97 +1584,102 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
|
||||
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->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;
|
||||
}
|
||||
}
|
||||
|
||||
bool shall_be_written = (!stays_in_same_block || data_changed);
|
||||
|
||||
// Delete old static object
|
||||
if(obj->m_static_exists)
|
||||
if(obj->isStaticAllowed())
|
||||
{
|
||||
MapBlock *block = m_map->emergeBlock(obj->m_static_block, false);
|
||||
// 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;
|
||||
|
||||
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)
|
||||
{
|
||||
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);
|
||||
|
||||
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");
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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();
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
If known by some client, set pending deactivation.
|
||||
Otherwise delete it immediately.
|
||||
*/
|
||||
|
||||
if(pending_delete)
|
||||
if(pending_delete && !force_delete)
|
||||
{
|
||||
verbosestream<<"ServerEnvironment::deactivateFarObjects(): "
|
||||
<<"object id="<<id<<" is known by clients"
|
||||
@ -1713,14 +1720,14 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
|
||||
*/
|
||||
|
||||
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()
|
||||
@ -2096,7 +2103,7 @@ u16 ClientEnvironment::addActiveObject(ClientActiveObject *object)
|
||||
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{
|
||||
@ -2114,7 +2121,8 @@ u16 ClientEnvironment::addActiveObject(ClientActiveObject *object)
|
||||
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(): "
|
||||
|
@ -376,7 +376,8 @@ class ClientEnvironment : public Environment
|
||||
{
|
||||
public:
|
||||
ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr,
|
||||
ITextureSource *texturesource, IGameDef *gamedef);
|
||||
ITextureSource *texturesource, IGameDef *gamedef,
|
||||
IrrlichtDevice *device);
|
||||
~ClientEnvironment();
|
||||
|
||||
Map & getMap()
|
||||
@ -454,6 +455,7 @@ private:
|
||||
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;
|
||||
|
@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "nodedef.h"
|
||||
#include "environment.h"
|
||||
#include "gamedef.h"
|
||||
#include "content_sao.h"
|
||||
|
||||
Player::Player(IGameDef *gamedef):
|
||||
touching_ground(false),
|
||||
@ -186,7 +187,8 @@ ServerRemotePlayer::ServerRemotePlayer(ServerEnvironment *env):
|
||||
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_,
|
||||
@ -194,7 +196,8 @@ ServerRemotePlayer::ServerRemotePlayer(ServerEnvironment *env, v3f pos_, u16 pee
|
||||
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_;
|
||||
@ -203,6 +206,28 @@ ServerRemotePlayer::ServerRemotePlayer(ServerEnvironment *env, v3f pos_, u16 pee
|
||||
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 */
|
||||
@ -329,6 +354,7 @@ s16 ServerRemotePlayer::getHP()
|
||||
|
||||
#ifndef SERVER
|
||||
|
||||
#if 0
|
||||
RemotePlayer::RemotePlayer(
|
||||
IGameDef *gamedef,
|
||||
scene::ISceneNode* parent,
|
||||
@ -441,6 +467,7 @@ void RemotePlayer::move(f32 dtime, Map &map, f32 pos_max_d)
|
||||
|
||||
ISceneNode::setPosition(m_showpos);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
15
src/player.h
15
src/player.h
@ -181,6 +181,8 @@ public:
|
||||
#include "serverobject.h"
|
||||
#include "content_object.h" // Object type IDs
|
||||
|
||||
class PlayerSAO;
|
||||
|
||||
class ServerRemotePlayer : public Player, public ServerActiveObject
|
||||
{
|
||||
public:
|
||||
@ -197,12 +199,11 @@ 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
|
||||
@ -242,10 +243,13 @@ public:
|
||||
bool m_hp_not_sent;
|
||||
|
||||
private:
|
||||
|
||||
PlayerSAO *m_sao;
|
||||
};
|
||||
|
||||
#ifndef SERVER
|
||||
|
||||
#if 0
|
||||
/*
|
||||
All the other players on the client are these
|
||||
*/
|
||||
@ -337,6 +341,7 @@ private:
|
||||
f32 m_pos_animation_time_counter;
|
||||
v3f m_showpos;
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif // !SERVER
|
||||
|
||||
|
@ -1588,7 +1588,9 @@ private:
|
||||
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
|
||||
|
@ -48,6 +48,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#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<<")"
|
||||
|
||||
@ -2218,7 +2219,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
||||
}
|
||||
|
||||
// Get player
|
||||
Player *player = emergePlayer(playername, peer_id);
|
||||
ServerRemotePlayer *player = emergePlayer(playername, peer_id);
|
||||
|
||||
// If failed, cancel
|
||||
if(player == NULL)
|
||||
@ -2228,6 +2229,10 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
||||
return;
|
||||
}
|
||||
|
||||
// Add PlayerSAO
|
||||
PlayerSAO *sao = new PlayerSAO(m_env, player->getPosition(), player);
|
||||
m_env->addActiveObject(sao);
|
||||
|
||||
/*
|
||||
Answer with a TOCLIENT_INIT
|
||||
*/
|
||||
@ -4830,12 +4835,13 @@ v3f findSpawnPos(ServerMap &map)
|
||||
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
|
||||
@ -4960,10 +4966,12 @@ void Server::handlePeerChange(PeerChange &c)
|
||||
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());
|
||||
@ -4974,21 +4982,26 @@ void Server::handlePeerChange(PeerChange &c)
|
||||
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);
|
||||
|
@ -599,7 +599,7 @@ private:
|
||||
|
||||
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;
|
||||
|
@ -58,6 +58,10 @@ public:
|
||||
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,
|
||||
@ -112,12 +116,17 @@ public:
|
||||
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){}
|
||||
@ -156,12 +165,13 @@ public:
|
||||
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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user