)
set(common_SRCS
+ collision.cpp
nodemetadata.cpp
serverobject.cpp
noise.cpp
#define ACTIVEOBJECT_TYPE_INVALID 0
#define ACTIVEOBJECT_TYPE_TEST 1
#define ACTIVEOBJECT_TYPE_ITEM 2
+#define ACTIVEOBJECT_TYPE_RAT 3
/*
Parent class for ServerActiveObject and ClientActiveObject
void ItemCAO::updateLight(u8 light_at_pos)
{
+ if(m_node == NULL)
+ return;
+
+ u8 li = decode_light(light_at_pos);
+ video::SColor color(255,li,li,li);
+
+ scene::IMesh *mesh = m_node->getMesh();
+ if(mesh == NULL)
+ return;
+
+ u16 mc = mesh->getMeshBufferCount();
+ for(u16 j=0; j<mc; j++)
+ {
+ scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
+ video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices();
+ u16 vc = buf->getVertexCount();
+ for(u16 i=0; i<vc; i++)
+ {
+ vertices[i].Color = color;
+ }
+ }
}
v3s16 ItemCAO::getLightPosition()
void ItemCAO::processMessage(const std::string &data)
{
- dstream<<"ItemCAO: Got data: "<<data<<std::endl;
+ dstream<<"ItemCAO: Got message"<<std::endl;
std::istringstream is(data, std::ios::binary);
- u16 cmd;
- is>>cmd;
+ char buf[4];
+ // command
+ is.read(buf, 1);
+ u8 cmd = buf[0];
if(cmd == 0)
{
- v3f newpos;
- is>>newpos.X;
- is>>newpos.Y;
- is>>newpos.Z;
- m_position = newpos;
+ // pos
+ is.read(buf, 4);
+ m_position.X = (float)readS32((u8*)buf)/1000.0;
+ is.read(buf, 4);
+ m_position.Y = (float)readS32((u8*)buf)/1000.0;
+ is.read(buf, 4);
+ m_position.Z = (float)readS32((u8*)buf)/1000.0;
updateNodePos();
}
}
void ItemCAO::initialize(const std::string &data)
{
- dstream<<"ItemCAO: Got init data: "<<data<<std::endl;
+ dstream<<"ItemCAO: Got init data"<<std::endl;
+
+ {
+ std::istringstream is(data, std::ios::binary);
+ char buf[4];
+ // version
+ is.read(buf, 1);
+ u8 version = buf[0];
+ // check version
+ if(version != 0)
+ return;
+ // pos
+ is.read(buf, 4);
+ m_position.X = (float)readS32((u8*)buf)/1000.0;
+ is.read(buf, 4);
+ m_position.Y = (float)readS32((u8*)buf)/1000.0;
+ is.read(buf, 4);
+ m_position.Z = (float)readS32((u8*)buf)/1000.0;
+ // inventorystring
+ m_inventorystring = deSerializeString(is);
+ }
- Strfnd fn(data);
-
- v3f newpos;
- newpos.X = stoi(fn.next(","));
- newpos.Y = stoi(fn.next(","));
- newpos.Z = stoi(fn.next(":"));
- m_position = newpos;
updateNodePos();
- m_inventorystring = fn.next("");
+ /*
+ Update image of node
+ */
if(m_node == NULL)
return;
if(buf == NULL)
return;
- /*
- Create an inventory item to see what is its image
- */
+ // Create an inventory item to see what is its image
std::istringstream is(m_inventorystring, std::ios_base::binary);
video::ITexture *texture = NULL;
try{
them to clients\r
- Not applicable. MapBlockObjects will be removed in the future.\r
\r
-SUGG: MovingObject::move and Player::move are basically the same.\r
- combine them.\r
- - NOTE: Player::move is more up-to-date.\r
-\r
SUGG: Precalculate lighting translation table at runtime (at startup)\r
- This is not doable because it is currently hand-made and not\r
based on some mathematical function.\r
\r
TODO: Get rid of MapBlockObjects and use ActiveObjects\r
\r
+SUGG: MovingObject::move and Player::move are basically the same.\r
+ combine them.\r
+ - NOTE: Player::move is more up-to-date.\r
+\r
Map:\r
----\r
\r
\r
core::aabbox3d<f32> *selection_box\r
= selected_active_object->getSelectionBox();\r
- // Box should exist because it was returned in the first place\r
+ // Box should exist because object was returned in the\r
+ // first place\r
assert(selection_box);\r
\r
v3f pos = selected_active_object->getPosition();\r
\r
hilightboxes.push_back(box_on_map);\r
\r
- infotext = narrow_to_wide("A ClientActiveObject");\r
- //infotext = narrow_to_wide(selected_object->infoText());\r
+ //infotext = narrow_to_wide("A ClientActiveObject");\r
+ infotext = narrow_to_wide(selected_active_object->infoText());\r
\r
if(g_input->getLeftClicked())\r
{\r
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+// This file contains the DEPRECATED MapBlockObject system
+
#include "mapblockobject.h"
#include "mapblock.h"
// For object wrapping
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+// This file contains the DEPRECATED MapBlockObject system
+
#ifndef MAPBLOCKOBJECT_HEADER
#define MAPBLOCKOBJECT_HEADER
return;
}
- v3f pos = intToFloat(p_over, BS);
- pos.Y -= BS*0.45;
-
dout_server<<"Placing a miscellaneous item on map"
<<std::endl;
-
+
+ // Calculate a position for it
+ v3f pos = intToFloat(p_over, BS);
+ //pos.Y -= BS*0.45;
+ pos.Y -= BS*0.25; // let it drop a bit
+ // Randomize a bit
+ pos.X += BS*0.2*(float)myrand_range(-1000,1000)/1000.0;
+ pos.Z += BS*0.2*(float)myrand_range(-1000,1000)/1000.0;
+
/*
Create an ItemSAO
*/
#include <fstream>
#include "environment.h"
#include "inventory.h"
+#include "collision.h"
core::map<u16, ServerActiveObject::Factory> ServerActiveObject::m_types;
ItemSAO::ItemSAO(ServerEnvironment *env, u16 id, v3f pos,
const std::string inventorystring):
ServerActiveObject(env, id, pos),
- m_inventorystring(inventorystring)
+ m_inventorystring(inventorystring),
+ m_speed_f(0,0,0)
{
dstream<<"Server: ItemSAO created with inventorystring=\""
<<m_inventorystring<<"\""<<std::endl;
{
std::istringstream is(data, std::ios::binary);
char buf[1];
- is.read(buf, 1); // read version
+ // read version
+ is.read(buf, 1);
+ u8 version = buf[0];
+ // check if version is supported
+ if(version != 0)
+ return NULL;
std::string inventorystring = deSerializeString(is);
dstream<<"ItemSAO::create(): Creating item \""
<<inventorystring<<"\""<<std::endl;
void ItemSAO::step(float dtime, Queue<ActiveObjectMessage> &messages)
{
+ 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 pos_f_old = pos_f;
+ moveresult = collisionMoveSimple(&m_env->getMap(), pos_max_d,
+ box, dtime, pos_f, m_speed_f);
+
+ if(pos_f.getDistanceFrom(pos_f_old) > 0.01*BS)
+ {
+ setBasePosition(pos_f);
+
+ std::ostringstream os(std::ios::binary);
+ char buf[6];
+ // command (0 = update position)
+ buf[0] = 0;
+ os.write(buf, 1);
+ // pos
+ writeS32((u8*)buf, m_base_position.X*1000);
+ os.write(buf, 4);
+ writeS32((u8*)buf, m_base_position.Y*1000);
+ os.write(buf, 4);
+ writeS32((u8*)buf, m_base_position.Z*1000);
+ os.write(buf, 4);
+ // create message and add to list
+ ActiveObjectMessage aom(getId(), false, os.str());
+ messages.push_back(aom);
+ }
}
std::string ItemSAO::getClientInitializationData()
{
- dstream<<__FUNCTION_NAME<<std::endl;
- std::string data;
- data += itos(m_base_position.X);
- data += ",";
- data += itos(m_base_position.Y);
- data += ",";
- data += itos(m_base_position.Z);
- data += ":";
- data += m_inventorystring;
- return data;
+ std::ostringstream os(std::ios::binary);
+ char buf[6];
+ // version
+ buf[0] = 0;
+ os.write(buf, 1);
+ // pos
+ writeS32((u8*)buf, m_base_position.X*1000);
+ os.write(buf, 4);
+ writeS32((u8*)buf, m_base_position.Y*1000);
+ os.write(buf, 4);
+ writeS32((u8*)buf, m_base_position.Z*1000);
+ os.write(buf, 4);
+ // inventorystring
+ os<<serializeString(m_inventorystring);
+ return os.str();
}
std::string ItemSAO::getStaticData()
dstream<<__FUNCTION_NAME<<std::endl;
std::ostringstream os(std::ios::binary);
char buf[1];
- buf[0] = 0; //version
+ // version
+ buf[0] = 0;
os.write(buf, 1);
+ // inventorystring
os<<serializeString(m_inventorystring);
return os.str();
}
* Server environment adds an active object, which gets the id 1
* The active object list is scanned for each client once in a while,
and it finds out what objects have been added that are not known
- by the client yet. This scan is initiated by the server and the
- result ends up directly to the server.
+ by the client yet. This scan is initiated by the Server class and
+ the result ends up directly to the server.
* A network packet is created with the info and sent to the client.
+* Environment converts objects to static data and static data to
+ objects, based on how close players are to them.
*/
InventoryItem* createInventoryItem();
private:
std::string m_inventorystring;
+ v3f m_speed_f;
};
#endif