Skip to content

Commit f8d5af7

Browse files
committedFeb 17, 2015
SAO work: ActiveObject types & SAO cleanup * Replace u8 types with ActiveObjectType. * Merge content_object.h into activeobject.h * Remove DummyLoadSAO, it's now unused. * Remove ItemSAO, it's also unused
1 parent 98d80e2 commit f8d5af7

9 files changed

+20
-315
lines changed
 

Diff for: ‎src/activeobject.h

+11-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2323
#include "irr_aabb3d.h"
2424
#include <string>
2525

26-
#define ACTIVEOBJECT_TYPE_INVALID 0
26+
enum ActiveObjectType {
27+
ACTIVEOBJECT_TYPE_INVALID = 0,
28+
ACTIVEOBJECT_TYPE_TEST = 1,
29+
ACTIVEOBJECT_TYPE_ITEM = 2,
30+
ACTIVEOBJECT_TYPE_LUAENTITY = 7,
31+
// Special type, not stored as a static object
32+
ACTIVEOBJECT_TYPE_PLAYER = 100,
33+
// Special type, only exists as CAO
34+
ACTIVEOBJECT_TYPE_GENERIC = 101,
35+
};
2736
// Other types are defined in content_object.h
2837

2938
struct ActiveObjectMessage
@@ -60,7 +69,7 @@ class ActiveObject
6069
m_id = id;
6170
}
6271

63-
virtual u8 getType() const = 0;
72+
virtual ActiveObjectType getType() const = 0;
6473
virtual bool getCollisionBox(aabb3f *toset) = 0;
6574
virtual bool collideWithObjects() = 0;
6675
protected:

Diff for: ‎src/content_cao.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3434
#include "serialization.h" // For decompressZlib
3535
#include "gamedef.h"
3636
#include "clientobject.h"
37-
#include "content_object.h"
3837
#include "mesh.h"
3938
#include "itemdef.h"
4039
#include "tool.h"
@@ -145,7 +144,7 @@ class TestCAO : public ClientActiveObject
145144
TestCAO(IGameDef *gamedef, ClientEnvironment *env);
146145
virtual ~TestCAO();
147146

148-
u8 getType() const
147+
ActiveObjectType getType() const
149148
{
150149
return ACTIVEOBJECT_TYPE_TEST;
151150
}
@@ -289,7 +288,7 @@ class ItemCAO : public ClientActiveObject
289288
ItemCAO(IGameDef *gamedef, ClientEnvironment *env);
290289
virtual ~ItemCAO();
291290

292-
u8 getType() const
291+
ActiveObjectType getType() const
293292
{
294293
return ACTIVEOBJECT_TYPE_ITEM;
295294
}

Diff for: ‎src/content_cao.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2222

2323
#include <map>
2424
#include "irrlichttypes_extrabloated.h"
25-
#include "content_object.h"
2625
#include "clientobject.h"
2726
#include "object_properties.h"
2827
#include "itemgroup.h"
@@ -115,7 +114,7 @@ class GenericCAO : public ClientActiveObject
115114
return new GenericCAO(gamedef, env);
116115
}
117116

118-
inline u8 getType() const
117+
inline ActiveObjectType getType() const
119118
{
120119
return ACTIVEOBJECT_TYPE_GENERIC;
121120
}

Diff for: ‎src/content_object.h

-39
This file was deleted.

Diff for: ‎src/content_sao.cpp

+1-246
Original file line numberDiff line numberDiff line change
@@ -35,54 +35,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3535

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

38-
/*
39-
DummyLoadSAO
40-
*/
41-
42-
class DummyLoadSAO : public ServerActiveObject
43-
{
44-
public:
45-
DummyLoadSAO(ServerEnvironment *env, v3f pos, u8 type):
46-
ServerActiveObject(env, pos)
47-
{
48-
ServerActiveObject::registerType(type, create);
49-
}
50-
// Pretend to be the test object (to fool the client)
51-
u8 getType() const
52-
{ return ACTIVEOBJECT_TYPE_TEST; }
53-
// And never save to disk
54-
bool isStaticAllowed() const
55-
{ return false; }
56-
57-
static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
58-
const std::string &data)
59-
{
60-
return new DummyLoadSAO(env, pos, 0);
61-
}
62-
63-
void step(float dtime, bool send_recommended)
64-
{
65-
m_removed = true;
66-
infostream<<"DummyLoadSAO step"<<std::endl;
67-
}
68-
69-
bool getCollisionBox(aabb3f *toset) {
70-
return false;
71-
}
72-
73-
bool collideWithObjects() {
74-
return false;
75-
}
76-
77-
private:
78-
};
79-
80-
// Prototype (registers item for deserialization)
81-
DummyLoadSAO proto1_DummyLoadSAO(NULL, v3f(0,0,0), ACTIVEOBJECT_TYPE_RAT);
82-
DummyLoadSAO proto2_DummyLoadSAO(NULL, v3f(0,0,0), ACTIVEOBJECT_TYPE_OERKKI1);
83-
DummyLoadSAO proto3_DummyLoadSAO(NULL, v3f(0,0,0), ACTIVEOBJECT_TYPE_FIREFLY);
84-
DummyLoadSAO proto4_DummyLoadSAO(NULL, v3f(0,0,0), ACTIVEOBJECT_TYPE_MOBV2);
85-
8638
/*
8739
TestSAO
8840
*/
@@ -97,7 +49,7 @@ class TestSAO : public ServerActiveObject
9749
{
9850
ServerActiveObject::registerType(getType(), create);
9951
}
100-
u8 getType() const
52+
ActiveObjectType getType() const
10153
{ return ACTIVEOBJECT_TYPE_TEST; }
10254

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

161-
/*
162-
ItemSAO
163-
164-
DEPRECATED: New dropped items are implemented in Lua; see
165-
builtin/item_entity.lua.
166-
*/
167-
168-
class ItemSAO : public ServerActiveObject
169-
{
170-
public:
171-
u8 getType() const
172-
{ return ACTIVEOBJECT_TYPE_ITEM; }
173-
174-
float getMinimumSavedMovement()
175-
{ return 0.1*BS; }
176-
177-
static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
178-
const std::string &data)
179-
{
180-
std::istringstream is(data, std::ios::binary);
181-
char buf[1];
182-
// read version
183-
is.read(buf, 1);
184-
u8 version = buf[0];
185-
// check if version is supported
186-
if(version != 0)
187-
return NULL;
188-
std::string itemstring = deSerializeString(is);
189-
infostream<<"create(): Creating item \""
190-
<<itemstring<<"\""<<std::endl;
191-
return new ItemSAO(env, pos, itemstring);
192-
}
193-
194-
ItemSAO(ServerEnvironment *env, v3f pos,
195-
const std::string &itemstring):
196-
ServerActiveObject(env, pos),
197-
m_itemstring(itemstring),
198-
m_itemstring_changed(false),
199-
m_speed_f(0,0,0),
200-
m_last_sent_position(0,0,0)
201-
{
202-
ServerActiveObject::registerType(getType(), create);
203-
}
204-
205-
void step(float dtime, bool send_recommended)
206-
{
207-
ScopeProfiler sp2(g_profiler, "step avg", SPT_AVG);
208-
209-
assert(m_env);
210-
211-
const float interval = 0.2;
212-
if(m_move_interval.step(dtime, interval)==false)
213-
return;
214-
dtime = interval;
215-
216-
core::aabbox3d<f32> box(-BS/3.,0.0,-BS/3., BS/3.,BS*2./3.,BS/3.);
217-
collisionMoveResult moveresult;
218-
// Apply gravity
219-
m_speed_f += v3f(0, -dtime*9.81*BS, 0);
220-
// Maximum movement without glitches
221-
f32 pos_max_d = BS*0.25;
222-
// Limit speed
223-
if(m_speed_f.getLength()*dtime > pos_max_d)
224-
m_speed_f *= pos_max_d / (m_speed_f.getLength()*dtime);
225-
v3f pos_f = getBasePosition();
226-
v3f accel_f = v3f(0,0,0);
227-
f32 stepheight = 0;
228-
moveresult = collisionMoveSimple(m_env,m_env->getGameDef(),
229-
pos_max_d, box, stepheight, dtime,
230-
pos_f, m_speed_f, accel_f);
231-
232-
if(send_recommended == false)
233-
return;
234-
235-
if(pos_f.getDistanceFrom(m_last_sent_position) > 0.05*BS)
236-
{
237-
setBasePosition(pos_f);
238-
m_last_sent_position = pos_f;
239-
240-
std::ostringstream os(std::ios::binary);
241-
// command (0 = update position)
242-
writeU8(os, 0);
243-
// pos
244-
writeV3F1000(os, m_base_position);
245-
// create message and add to list
246-
ActiveObjectMessage aom(getId(), false, os.str());
247-
m_messages_out.push_back(aom);
248-
}
249-
if(m_itemstring_changed)
250-
{
251-
m_itemstring_changed = false;
252-
253-
std::ostringstream os(std::ios::binary);
254-
// command (1 = update itemstring)
255-
writeU8(os, 1);
256-
// itemstring
257-
os<<serializeString(m_itemstring);
258-
// create message and add to list
259-
ActiveObjectMessage aom(getId(), false, os.str());
260-
m_messages_out.push_back(aom);
261-
}
262-
}
263-
264-
std::string getClientInitializationData(u16 protocol_version)
265-
{
266-
std::ostringstream os(std::ios::binary);
267-
// version
268-
writeU8(os, 0);
269-
// pos
270-
writeV3F1000(os, m_base_position);
271-
// itemstring
272-
os<<serializeString(m_itemstring);
273-
return os.str();
274-
}
275-
276-
std::string getStaticData()
277-
{
278-
infostream<<__FUNCTION_NAME<<std::endl;
279-
std::ostringstream os(std::ios::binary);
280-
// version
281-
writeU8(os, 0);
282-
// itemstring
283-
os<<serializeString(m_itemstring);
284-
return os.str();
285-
}
286-
287-
ItemStack createItemStack()
288-
{
289-
try{
290-
IItemDefManager *idef = m_env->getGameDef()->idef();
291-
ItemStack item;
292-
item.deSerialize(m_itemstring, idef);
293-
infostream<<__FUNCTION_NAME<<": m_itemstring=\""<<m_itemstring
294-
<<"\" -> item=\""<<item.getItemString()<<"\""
295-
<<std::endl;
296-
return item;
297-
}
298-
catch(SerializationError &e)
299-
{
300-
infostream<<__FUNCTION_NAME<<": serialization error: "
301-
<<"m_itemstring=\""<<m_itemstring<<"\""<<std::endl;
302-
return ItemStack();
303-
}
304-
}
305-
306-
int punch(v3f dir,
307-
const ToolCapabilities *toolcap,
308-
ServerActiveObject *puncher,
309-
float time_from_last_punch)
310-
{
311-
// Take item into inventory
312-
ItemStack item = createItemStack();
313-
Inventory *inv = puncher->getInventory();
314-
if(inv != NULL)
315-
{
316-
std::string wieldlist = puncher->getWieldList();
317-
ItemStack leftover = inv->addItem(wieldlist, item);
318-
puncher->setInventoryModified();
319-
if(leftover.empty())
320-
{
321-
m_removed = true;
322-
}
323-
else
324-
{
325-
m_itemstring = leftover.getItemString();
326-
m_itemstring_changed = true;
327-
}
328-
}
329-
330-
return 0;
331-
}
332-
333-
bool getCollisionBox(aabb3f *toset) {
334-
return false;
335-
}
336-
337-
bool collideWithObjects() {
338-
return false;
339-
}
340-
341-
private:
342-
std::string m_itemstring;
343-
bool m_itemstring_changed;
344-
v3f m_speed_f;
345-
v3f m_last_sent_position;
346-
IntervalLimiter m_move_interval;
347-
};
348-
349-
// Prototype (registers item for deserialization)
350-
ItemSAO proto_ItemSAO(NULL, v3f(0,0,0), "");
351-
352-
ServerActiveObject* createItemSAO(ServerEnvironment *env, v3f pos,
353-
const std::string &itemstring)
354-
{
355-
return new ItemSAO(env, pos, itemstring);
356-
}
357-
358113
/*
359114
LuaEntitySAO
360115
*/

0 commit comments

Comments
 (0)
Please sign in to comment.