Skip to content

Commit b82884a

Browse files
authoredAug 19, 2017
ItemCAO removal (#6279)
This object is from 0.3 era and was never used since 0.4.X and GenericCAO usage
1 parent d382483 commit b82884a

File tree

1 file changed

+0
-254
lines changed

1 file changed

+0
-254
lines changed
 

Diff for: ‎src/content_cao.cpp

-254
Original file line numberDiff line numberDiff line change
@@ -249,260 +249,6 @@ void TestCAO::processMessage(const std::string &data)
249249
}
250250
}
251251

252-
/*
253-
ItemCAO
254-
*/
255-
256-
class ItemCAO : public ClientActiveObject
257-
{
258-
public:
259-
ItemCAO(Client *client, ClientEnvironment *env);
260-
virtual ~ItemCAO() = default;
261-
262-
ActiveObjectType getType() const
263-
{
264-
return ACTIVEOBJECT_TYPE_ITEM;
265-
}
266-
267-
static ClientActiveObject* create(Client *client, ClientEnvironment *env);
268-
269-
void addToScene(ITextureSource *tsrc);
270-
void removeFromScene(bool permanent);
271-
void updateLight(u8 light_at_pos);
272-
v3s16 getLightPosition();
273-
void updateNodePos();
274-
void updateInfoText();
275-
void updateTexture();
276-
277-
void step(float dtime, ClientEnvironment *env);
278-
279-
void processMessage(const std::string &data);
280-
281-
void initialize(const std::string &data);
282-
283-
284-
virtual bool getSelectionBox(aabb3f *toset) const
285-
{
286-
*toset = m_selection_box;
287-
return true;
288-
}
289-
290-
291-
v3f getPosition()
292-
{return m_position;}
293-
inline float getYaw() const
294-
{return 0;}
295-
std::string infoText()
296-
{return m_infotext;}
297-
298-
bool getCollisionBox(aabb3f *toset) const { return false; }
299-
private:
300-
aabb3f m_selection_box;
301-
scene::IMeshSceneNode *m_node;
302-
v3f m_position;
303-
std::string m_itemstring;
304-
std::string m_infotext;
305-
};
306-
307-
// Prototype
308-
ItemCAO proto_ItemCAO(NULL, NULL);
309-
310-
ItemCAO::ItemCAO(Client *client, ClientEnvironment *env):
311-
ClientActiveObject(0, client, env),
312-
m_selection_box(-BS/3.,0.0,-BS/3., BS/3.,BS*2./3.,BS/3.),
313-
m_node(NULL),
314-
m_position(v3f(0,10*BS,0))
315-
{
316-
if(!client && !env)
317-
{
318-
ClientActiveObject::registerType(getType(), create);
319-
}
320-
}
321-
322-
ClientActiveObject* ItemCAO::create(Client *client, ClientEnvironment *env)
323-
{
324-
return new ItemCAO(client, env);
325-
}
326-
327-
void ItemCAO::addToScene(ITextureSource *tsrc)
328-
{
329-
if(m_node != NULL)
330-
return;
331-
332-
//video::IVideoDriver* driver = smgr->getVideoDriver();
333-
334-
scene::SMesh *mesh = new scene::SMesh();
335-
scene::IMeshBuffer *buf = new scene::SMeshBuffer();
336-
video::SColor c(255,255,255,255);
337-
video::S3DVertex vertices[4] =
338-
{
339-
/*video::S3DVertex(-BS/2,-BS/4,0, 0,0,0, c, 0,1),
340-
video::S3DVertex(BS/2,-BS/4,0, 0,0,0, c, 1,1),
341-
video::S3DVertex(BS/2,BS/4,0, 0,0,0, c, 1,0),
342-
video::S3DVertex(-BS/2,BS/4,0, 0,0,0, c, 0,0),*/
343-
video::S3DVertex(BS/3.,0,0, 0,0,0, c, 0,1),
344-
video::S3DVertex(-BS/3.,0,0, 0,0,0, c, 1,1),
345-
video::S3DVertex(-BS/3.,0+BS*2./3.,0, 0,0,0, c, 1,0),
346-
video::S3DVertex(BS/3.,0+BS*2./3.,0, 0,0,0, c, 0,0),
347-
};
348-
u16 indices[] = {0,1,2,2,3,0};
349-
buf->append(vertices, 4, indices, 6);
350-
// Set material
351-
buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
352-
buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
353-
// Initialize with a generated placeholder texture
354-
buf->getMaterial().setTexture(0, tsrc->getTexture(""));
355-
buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
356-
buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
357-
buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
358-
// Add to mesh
359-
mesh->addMeshBuffer(buf);
360-
buf->drop();
361-
m_node = RenderingEngine::get_scene_manager()->addMeshSceneNode(mesh, NULL);
362-
mesh->drop();
363-
updateNodePos();
364-
365-
/*
366-
Update image of node
367-
*/
368-
369-
updateTexture();
370-
}
371-
372-
void ItemCAO::removeFromScene(bool permanent)
373-
{
374-
if (!m_node)
375-
return;
376-
377-
m_node->remove();
378-
m_node = nullptr;
379-
}
380-
381-
void ItemCAO::updateLight(u8 light_at_pos)
382-
{
383-
if (!m_node)
384-
return;
385-
386-
u8 li = decode_light(light_at_pos);
387-
video::SColor color(255,li,li,li);
388-
setMeshColor(m_node->getMesh(), color);
389-
}
390-
391-
v3s16 ItemCAO::getLightPosition()
392-
{
393-
return floatToInt(m_position + v3f(0,0.5*BS,0), BS);
394-
}
395-
396-
void ItemCAO::updateNodePos()
397-
{
398-
if (!m_node)
399-
return;
400-
401-
m_node->setPosition(m_position);
402-
}
403-
404-
void ItemCAO::updateInfoText()
405-
{
406-
try{
407-
IItemDefManager *idef = m_client->idef();
408-
ItemStack item;
409-
item.deSerialize(m_itemstring, idef);
410-
if(item.isKnown(idef))
411-
m_infotext = item.getDefinition(idef).description;
412-
else
413-
m_infotext = "Unknown item: '" + m_itemstring + "'";
414-
if(item.count >= 2)
415-
m_infotext += " (" + itos(item.count) + ")";
416-
}
417-
catch(SerializationError &e)
418-
{
419-
m_infotext = "Unknown item: '" + m_itemstring + "'";
420-
}
421-
}
422-
423-
void ItemCAO::updateTexture()
424-
{
425-
if (!m_node)
426-
return;
427-
428-
// Create an inventory item to see what is its image
429-
std::istringstream is(m_itemstring, std::ios_base::binary);
430-
video::ITexture *texture = NULL;
431-
try{
432-
IItemDefManager *idef = m_client->idef();
433-
ItemStack item;
434-
item.deSerialize(is, idef);
435-
texture = idef->getInventoryTexture(item.getDefinition(idef).name, m_client);
436-
}
437-
catch(SerializationError &e)
438-
{
439-
warningstream<<FUNCTION_NAME
440-
<<": error deSerializing itemstring \""
441-
<<m_itemstring<<std::endl;
442-
}
443-
444-
// Set meshbuffer texture
445-
m_node->getMaterial(0).setTexture(0, texture);
446-
}
447-
448-
449-
void ItemCAO::step(float dtime, ClientEnvironment *env)
450-
{
451-
if(m_node)
452-
{
453-
/*v3f rot = m_node->getRotation();
454-
rot.Y += dtime * 120;
455-
m_node->setRotation(rot);*/
456-
LocalPlayer *player = env->getLocalPlayer();
457-
assert(player);
458-
v3f rot = m_node->getRotation();
459-
rot.Y = 180.0 - (player->getYaw());
460-
m_node->setRotation(rot);
461-
}
462-
}
463-
464-
void ItemCAO::processMessage(const std::string &data)
465-
{
466-
//infostream<<"ItemCAO: Got message"<<std::endl;
467-
std::istringstream is(data, std::ios::binary);
468-
// command
469-
u8 cmd = readU8(is);
470-
if(cmd == 0)
471-
{
472-
// pos
473-
m_position = readV3F1000(is);
474-
updateNodePos();
475-
}
476-
if(cmd == 1)
477-
{
478-
// itemstring
479-
m_itemstring = deSerializeString(is);
480-
updateInfoText();
481-
updateTexture();
482-
}
483-
}
484-
485-
void ItemCAO::initialize(const std::string &data)
486-
{
487-
infostream<<"ItemCAO: Got init data"<<std::endl;
488-
489-
{
490-
std::istringstream is(data, std::ios::binary);
491-
// version
492-
u8 version = readU8(is);
493-
// check version
494-
if(version != 0)
495-
return;
496-
// pos
497-
m_position = readV3F1000(is);
498-
// itemstring
499-
m_itemstring = deSerializeString(is);
500-
}
501-
502-
updateNodePos();
503-
updateInfoText();
504-
}
505-
506252
/*
507253
GenericCAO
508254
*/

0 commit comments

Comments
 (0)
Please sign in to comment.