Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
SAO work: ActiveObject types & SAO cleanup * Replace u8 types with Ac…
…tiveObjectType. * Merge content_object.h into activeobject.h * Remove DummyLoadSAO, it's now unused. * Remove ItemSAO, it's also unused
  • Loading branch information
nerzhul committed Feb 17, 2015
1 parent 98d80e2 commit f8d5af7
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 315 deletions.
13 changes: 11 additions & 2 deletions src/activeobject.h
Expand Up @@ -23,7 +23,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irr_aabb3d.h"
#include <string>

#define ACTIVEOBJECT_TYPE_INVALID 0
enum ActiveObjectType {
ACTIVEOBJECT_TYPE_INVALID = 0,
ACTIVEOBJECT_TYPE_TEST = 1,
ACTIVEOBJECT_TYPE_ITEM = 2,
ACTIVEOBJECT_TYPE_LUAENTITY = 7,
// Special type, not stored as a static object
ACTIVEOBJECT_TYPE_PLAYER = 100,
// Special type, only exists as CAO
ACTIVEOBJECT_TYPE_GENERIC = 101,
};
// Other types are defined in content_object.h

struct ActiveObjectMessage
Expand Down Expand Up @@ -60,7 +69,7 @@ class ActiveObject
m_id = id;
}

virtual u8 getType() const = 0;
virtual ActiveObjectType getType() const = 0;
virtual bool getCollisionBox(aabb3f *toset) = 0;
virtual bool collideWithObjects() = 0;
protected:
Expand Down
5 changes: 2 additions & 3 deletions src/content_cao.cpp
Expand Up @@ -34,7 +34,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "serialization.h" // For decompressZlib
#include "gamedef.h"
#include "clientobject.h"
#include "content_object.h"
#include "mesh.h"
#include "itemdef.h"
#include "tool.h"
Expand Down Expand Up @@ -145,7 +144,7 @@ class TestCAO : public ClientActiveObject
TestCAO(IGameDef *gamedef, ClientEnvironment *env);
virtual ~TestCAO();

u8 getType() const
ActiveObjectType getType() const
{
return ACTIVEOBJECT_TYPE_TEST;
}
Expand Down Expand Up @@ -289,7 +288,7 @@ class ItemCAO : public ClientActiveObject
ItemCAO(IGameDef *gamedef, ClientEnvironment *env);
virtual ~ItemCAO();

u8 getType() const
ActiveObjectType getType() const
{
return ACTIVEOBJECT_TYPE_ITEM;
}
Expand Down
3 changes: 1 addition & 2 deletions src/content_cao.h
Expand Up @@ -22,7 +22,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,

#include <map>
#include "irrlichttypes_extrabloated.h"
#include "content_object.h"
#include "clientobject.h"
#include "object_properties.h"
#include "itemgroup.h"
Expand Down Expand Up @@ -115,7 +114,7 @@ class GenericCAO : public ClientActiveObject
return new GenericCAO(gamedef, env);
}

inline u8 getType() const
inline ActiveObjectType getType() const
{
return ACTIVEOBJECT_TYPE_GENERIC;
}
Expand Down
39 changes: 0 additions & 39 deletions src/content_object.h

This file was deleted.

247 changes: 1 addition & 246 deletions src/content_sao.cpp
Expand Up @@ -35,54 +35,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,

std::map<u16, ServerActiveObject::Factory> ServerActiveObject::m_types;

/*
DummyLoadSAO
*/

class DummyLoadSAO : public ServerActiveObject
{
public:
DummyLoadSAO(ServerEnvironment *env, v3f pos, u8 type):
ServerActiveObject(env, pos)
{
ServerActiveObject::registerType(type, create);
}
// Pretend to be the test object (to fool the client)
u8 getType() const
{ return ACTIVEOBJECT_TYPE_TEST; }
// And never save to disk
bool isStaticAllowed() const
{ return false; }

static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
const std::string &data)
{
return new DummyLoadSAO(env, pos, 0);
}

void step(float dtime, bool send_recommended)
{
m_removed = true;
infostream<<"DummyLoadSAO step"<<std::endl;
}

bool getCollisionBox(aabb3f *toset) {
return false;
}

bool collideWithObjects() {
return false;
}

private:
};

// Prototype (registers item for deserialization)
DummyLoadSAO proto1_DummyLoadSAO(NULL, v3f(0,0,0), ACTIVEOBJECT_TYPE_RAT);
DummyLoadSAO proto2_DummyLoadSAO(NULL, v3f(0,0,0), ACTIVEOBJECT_TYPE_OERKKI1);
DummyLoadSAO proto3_DummyLoadSAO(NULL, v3f(0,0,0), ACTIVEOBJECT_TYPE_FIREFLY);
DummyLoadSAO proto4_DummyLoadSAO(NULL, v3f(0,0,0), ACTIVEOBJECT_TYPE_MOBV2);

/*
TestSAO
*/
Expand All @@ -97,7 +49,7 @@ class TestSAO : public ServerActiveObject
{
ServerActiveObject::registerType(getType(), create);
}
u8 getType() const
ActiveObjectType getType() const
{ return ACTIVEOBJECT_TYPE_TEST; }

static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
Expand Down Expand Up @@ -158,203 +110,6 @@ class TestSAO : public ServerActiveObject
// Prototype (registers item for deserialization)
TestSAO proto_TestSAO(NULL, v3f(0,0,0));

/*
ItemSAO
DEPRECATED: New dropped items are implemented in Lua; see
builtin/item_entity.lua.
*/

class ItemSAO : public ServerActiveObject
{
public:
u8 getType() const
{ return ACTIVEOBJECT_TYPE_ITEM; }

float getMinimumSavedMovement()
{ return 0.1*BS; }

static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
const std::string &data)
{
std::istringstream is(data, std::ios::binary);
char buf[1];
// read version
is.read(buf, 1);
u8 version = buf[0];
// check if version is supported
if(version != 0)
return NULL;
std::string itemstring = deSerializeString(is);
infostream<<"create(): Creating item \""
<<itemstring<<"\""<<std::endl;
return new ItemSAO(env, pos, itemstring);
}

ItemSAO(ServerEnvironment *env, v3f pos,
const std::string &itemstring):
ServerActiveObject(env, pos),
m_itemstring(itemstring),
m_itemstring_changed(false),
m_speed_f(0,0,0),
m_last_sent_position(0,0,0)
{
ServerActiveObject::registerType(getType(), create);
}

void step(float dtime, bool send_recommended)
{
ScopeProfiler sp2(g_profiler, "step avg", SPT_AVG);

assert(m_env);

const float interval = 0.2;
if(m_move_interval.step(dtime, interval)==false)
return;
dtime = interval;

core::aabbox3d<f32> box(-BS/3.,0.0,-BS/3., BS/3.,BS*2./3.,BS/3.);
collisionMoveResult moveresult;
// Apply gravity
m_speed_f += v3f(0, -dtime*9.81*BS, 0);
// Maximum movement without glitches
f32 pos_max_d = BS*0.25;
// Limit speed
if(m_speed_f.getLength()*dtime > pos_max_d)
m_speed_f *= pos_max_d / (m_speed_f.getLength()*dtime);
v3f pos_f = getBasePosition();
v3f accel_f = v3f(0,0,0);
f32 stepheight = 0;
moveresult = collisionMoveSimple(m_env,m_env->getGameDef(),
pos_max_d, box, stepheight, dtime,
pos_f, m_speed_f, accel_f);

if(send_recommended == false)
return;

if(pos_f.getDistanceFrom(m_last_sent_position) > 0.05*BS)
{
setBasePosition(pos_f);
m_last_sent_position = pos_f;

std::ostringstream os(std::ios::binary);
// command (0 = update position)
writeU8(os, 0);
// pos
writeV3F1000(os, m_base_position);
// create message and add to list
ActiveObjectMessage aom(getId(), false, os.str());
m_messages_out.push_back(aom);
}
if(m_itemstring_changed)
{
m_itemstring_changed = false;

std::ostringstream os(std::ios::binary);
// command (1 = update itemstring)
writeU8(os, 1);
// itemstring
os<<serializeString(m_itemstring);
// create message and add to list
ActiveObjectMessage aom(getId(), false, os.str());
m_messages_out.push_back(aom);
}
}

std::string getClientInitializationData(u16 protocol_version)
{
std::ostringstream os(std::ios::binary);
// version
writeU8(os, 0);
// pos
writeV3F1000(os, m_base_position);
// itemstring
os<<serializeString(m_itemstring);
return os.str();
}

std::string getStaticData()
{
infostream<<__FUNCTION_NAME<<std::endl;
std::ostringstream os(std::ios::binary);
// version
writeU8(os, 0);
// itemstring
os<<serializeString(m_itemstring);
return os.str();
}

ItemStack createItemStack()
{
try{
IItemDefManager *idef = m_env->getGameDef()->idef();
ItemStack item;
item.deSerialize(m_itemstring, idef);
infostream<<__FUNCTION_NAME<<": m_itemstring=\""<<m_itemstring
<<"\" -> item=\""<<item.getItemString()<<"\""
<<std::endl;
return item;
}
catch(SerializationError &e)
{
infostream<<__FUNCTION_NAME<<": serialization error: "
<<"m_itemstring=\""<<m_itemstring<<"\""<<std::endl;
return ItemStack();
}
}

int punch(v3f dir,
const ToolCapabilities *toolcap,
ServerActiveObject *puncher,
float time_from_last_punch)
{
// Take item into inventory
ItemStack item = createItemStack();
Inventory *inv = puncher->getInventory();
if(inv != NULL)
{
std::string wieldlist = puncher->getWieldList();
ItemStack leftover = inv->addItem(wieldlist, item);
puncher->setInventoryModified();
if(leftover.empty())
{
m_removed = true;
}
else
{
m_itemstring = leftover.getItemString();
m_itemstring_changed = true;
}
}

return 0;
}

bool getCollisionBox(aabb3f *toset) {
return false;
}

bool collideWithObjects() {
return false;
}

private:
std::string m_itemstring;
bool m_itemstring_changed;
v3f m_speed_f;
v3f m_last_sent_position;
IntervalLimiter m_move_interval;
};

// Prototype (registers item for deserialization)
ItemSAO proto_ItemSAO(NULL, v3f(0,0,0), "");

ServerActiveObject* createItemSAO(ServerEnvironment *env, v3f pos,
const std::string &itemstring)
{
return new ItemSAO(env, pos, itemstring);
}

/*
LuaEntitySAO
*/
Expand Down

0 comments on commit f8d5af7

Please sign in to comment.