ObjectProperties

This commit is contained in:
Perttu Ahola 2012-03-30 12:51:51 +03:00
parent b9ffb5f30d
commit 9e7ccedba4
11 changed files with 175 additions and 186 deletions

@ -165,7 +165,7 @@ set(common_SRCS
nameidmapping.cpp nameidmapping.cpp
itemdef.cpp itemdef.cpp
nodedef.cpp nodedef.cpp
luaentity_common.cpp object_properties.cpp
scriptapi.cpp scriptapi.cpp
script.cpp script.cpp
log.cpp log.cpp

@ -548,16 +548,7 @@ private:
bool m_is_player; bool m_is_player;
bool m_is_local_player; // determined locally bool m_is_local_player; // determined locally
// Property-ish things // Property-ish things
s16 m_hp_max; ObjectProperties m_prop;
bool m_physical;
float m_weight;
core::aabbox3d<f32> m_collisionbox;
std::string m_visual;
v2f m_visual_size;
core::array<std::string> m_textures;
v2s16 m_spritediv;
bool m_is_visible;
bool m_makes_footstep_sound;
// //
scene::ISceneManager *m_smgr; scene::ISceneManager *m_smgr;
IrrlichtDevice *m_irr; IrrlichtDevice *m_irr;
@ -574,6 +565,7 @@ private:
// Spritesheet/animation stuff // Spritesheet/animation stuff
v2f m_tx_size; v2f m_tx_size;
v2s16 m_tx_basepos; v2s16 m_tx_basepos;
bool m_initial_tx_basepos_set;
bool m_tx_select_horiz_by_yawpitch; bool m_tx_select_horiz_by_yawpitch;
int m_anim_frame; int m_anim_frame;
int m_anim_num_frames; int m_anim_num_frames;
@ -591,16 +583,6 @@ public:
m_is_player(false), m_is_player(false),
m_is_local_player(false), m_is_local_player(false),
// //
m_hp_max(1),
m_physical(false),
m_weight(5),
m_collisionbox(-0.5,-0.5,-0.5, 0.5,0.5,0.5),
m_visual("sprite"),
m_visual_size(1,1),
m_spritediv(1,1),
m_is_visible(true),
m_makes_footstep_sound(false),
//
m_smgr(NULL), m_smgr(NULL),
m_irr(NULL), m_irr(NULL),
m_selection_box(-BS/3.,-BS/3.,-BS/3., BS/3.,BS/3.,BS/3.), m_selection_box(-BS/3.,-BS/3.,-BS/3., BS/3.,BS/3.,BS/3.),
@ -614,6 +596,7 @@ public:
m_hp(1), m_hp(1),
m_tx_size(1,1), m_tx_size(1,1),
m_tx_basepos(0,0), m_tx_basepos(0,0),
m_initial_tx_basepos_set(false),
m_tx_select_horiz_by_yawpitch(false), m_tx_select_horiz_by_yawpitch(false),
m_anim_frame(0), m_anim_frame(0),
m_anim_num_frames(1), m_anim_num_frames(1),
@ -623,7 +606,6 @@ public:
m_visuals_expired(false), m_visuals_expired(false),
m_step_distance_counter(0) m_step_distance_counter(0)
{ {
m_textures.push_back("unknown_object.png");
if(gamedef == NULL) if(gamedef == NULL)
ClientActiveObject::registerType(getType(), create); ClientActiveObject::registerType(getType(), create);
} }
@ -678,7 +660,7 @@ public:
} }
core::aabbox3d<f32>* getSelectionBox() core::aabbox3d<f32>* getSelectionBox()
{ {
if(!m_is_visible || m_is_local_player) if(!m_prop.is_visible || m_is_local_player)
return NULL; return NULL;
return &m_selection_box; return &m_selection_box;
} }
@ -710,12 +692,12 @@ public:
m_visuals_expired = false; m_visuals_expired = false;
if(!m_is_visible || m_is_local_player) if(!m_prop.is_visible || m_is_local_player)
return; return;
//video::IVideoDriver* driver = smgr->getVideoDriver(); //video::IVideoDriver* driver = smgr->getVideoDriver();
if(m_visual == "sprite"){ if(m_prop.visual == "sprite"){
infostream<<"GenericCAO::addToScene(): single_sprite"<<std::endl; infostream<<"GenericCAO::addToScene(): single_sprite"<<std::endl;
m_spritenode = smgr->addBillboardSceneNode( m_spritenode = smgr->addBillboardSceneNode(
NULL, v2f(1, 1), v3f(0,0,0), -1); NULL, v2f(1, 1), v3f(0,0,0), -1);
@ -727,7 +709,7 @@ public:
m_spritenode->setMaterialFlag(video::EMF_FOG_ENABLE, true); m_spritenode->setMaterialFlag(video::EMF_FOG_ENABLE, true);
m_spritenode->setColor(video::SColor(255,0,0,0)); m_spritenode->setColor(video::SColor(255,0,0,0));
m_spritenode->setVisible(false); /* Set visible when brightness is known */ m_spritenode->setVisible(false); /* Set visible when brightness is known */
m_spritenode->setSize(m_visual_size*BS); m_spritenode->setSize(m_prop.visual_size*BS);
{ {
const float txs = 1.0 / 1; const float txs = 1.0 / 1;
const float tys = 1.0 / 1; const float tys = 1.0 / 1;
@ -735,11 +717,11 @@ public:
txs, tys, 0, 0); txs, tys, 0, 0);
} }
} }
else if(m_visual == "upright_sprite") else if(m_prop.visual == "upright_sprite")
{ {
scene::SMesh *mesh = new scene::SMesh(); scene::SMesh *mesh = new scene::SMesh();
double dx = BS*m_visual_size.X/2; double dx = BS*m_prop.visual_size.X/2;
double dy = BS*m_visual_size.Y/2; double dy = BS*m_prop.visual_size.Y/2;
{ // Front { // Front
scene::IMeshBuffer *buf = new scene::SMeshBuffer(); scene::IMeshBuffer *buf = new scene::SMeshBuffer();
video::SColor c(255,255,255,255); video::SColor c(255,255,255,255);
@ -788,7 +770,7 @@ public:
// This is needed for changing the texture in the future // This is needed for changing the texture in the future
m_meshnode->setReadOnlyMaterials(true); m_meshnode->setReadOnlyMaterials(true);
} }
else if(m_visual == "cube"){ else if(m_prop.visual == "cube"){
infostream<<"GenericCAO::addToScene(): cube"<<std::endl; infostream<<"GenericCAO::addToScene(): cube"<<std::endl;
scene::IMesh *mesh = createCubeMesh(v3f(BS,BS,BS)); scene::IMesh *mesh = createCubeMesh(v3f(BS,BS,BS));
m_meshnode = smgr->addMeshSceneNode(mesh, NULL); m_meshnode = smgr->addMeshSceneNode(mesh, NULL);
@ -798,7 +780,7 @@ public:
// Will be shown when we know the brightness // Will be shown when we know the brightness
m_meshnode->setVisible(false); m_meshnode->setVisible(false);
} else { } else {
infostream<<"GenericCAO::addToScene(): \""<<m_visual infostream<<"GenericCAO::addToScene(): \""<<m_prop.visual
<<"\" not supported"<<std::endl; <<"\" not supported"<<std::endl;
} }
updateTextures(""); updateTextures("");
@ -868,8 +850,8 @@ public:
addToScene(m_smgr, m_gamedef->tsrc(), m_irr); addToScene(m_smgr, m_gamedef->tsrc(), m_irr);
} }
if(m_physical){ if(m_prop.physical){
core::aabbox3d<f32> box = m_collisionbox; core::aabbox3d<f32> box = m_prop.collisionbox;
box.MinEdge *= BS; box.MinEdge *= BS;
box.MaxEdge *= BS; box.MaxEdge *= BS;
collisionMoveResult moveresult; collisionMoveResult moveresult;
@ -901,7 +883,7 @@ public:
m_step_distance_counter += moved; m_step_distance_counter += moved;
if(m_step_distance_counter > 1.5*BS){ if(m_step_distance_counter > 1.5*BS){
m_step_distance_counter = 0; m_step_distance_counter = 0;
if(!m_is_local_player && m_makes_footstep_sound){ if(!m_is_local_player && m_prop.makes_footstep_sound){
INodeDefManager *ndef = m_gamedef->ndef(); INodeDefManager *ndef = m_gamedef->ndef();
v3s16 p = floatToInt(getPosition()+v3f(0,-0.5*BS, 0), BS); v3s16 p = floatToInt(getPosition()+v3f(0,-0.5*BS, 0), BS);
MapNode n = m_env->getMap().getNodeNoEx(p); MapNode n = m_env->getMap().getNodeNoEx(p);
@ -983,11 +965,11 @@ public:
if(m_spritenode) if(m_spritenode)
{ {
if(m_visual == "sprite") if(m_prop.visual == "sprite")
{ {
std::string texturestring = "unknown_block.png"; std::string texturestring = "unknown_block.png";
if(m_textures.size() >= 1) if(m_prop.textures.size() >= 1)
texturestring = m_textures[0]; texturestring = m_prop.textures[0];
texturestring += mod; texturestring += mod;
m_spritenode->setMaterialTexture(0, m_spritenode->setMaterialTexture(0,
tsrc->getTextureRaw(texturestring)); tsrc->getTextureRaw(texturestring));
@ -995,13 +977,13 @@ public:
} }
if(m_meshnode) if(m_meshnode)
{ {
if(m_visual == "cube") if(m_prop.visual == "cube")
{ {
for (u32 i = 0; i < 6; ++i) for (u32 i = 0; i < 6; ++i)
{ {
std::string texturestring = "unknown_block.png"; std::string texturestring = "unknown_block.png";
if(m_textures.size() > i) if(m_prop.textures.size() > i)
texturestring = m_textures[i]; texturestring = m_prop.textures[i];
texturestring += mod; texturestring += mod;
AtlasPointer ap = tsrc->getTexture(texturestring); AtlasPointer ap = tsrc->getTexture(texturestring);
@ -1019,13 +1001,13 @@ public:
material.getTextureMatrix(0).setTextureScale(size.X, size.Y); material.getTextureMatrix(0).setTextureScale(size.X, size.Y);
} }
} }
else if(m_visual == "upright_sprite") else if(m_prop.visual == "upright_sprite")
{ {
scene::IMesh *mesh = m_meshnode->getMesh(); scene::IMesh *mesh = m_meshnode->getMesh();
{ {
std::string tname = "unknown_object.png"; std::string tname = "unknown_object.png";
if(m_textures.size() >= 1) if(m_prop.textures.size() >= 1)
tname = m_textures[0]; tname = m_prop.textures[0];
tname += mod; tname += mod;
scene::IMeshBuffer *buf = mesh->getMeshBuffer(0); scene::IMeshBuffer *buf = mesh->getMeshBuffer(0);
buf->getMaterial().setTexture(0, buf->getMaterial().setTexture(0,
@ -1033,10 +1015,10 @@ public:
} }
{ {
std::string tname = "unknown_object.png"; std::string tname = "unknown_object.png";
if(m_textures.size() >= 2) if(m_prop.textures.size() >= 2)
tname = m_textures[1]; tname = m_prop.textures[1];
else if(m_textures.size() >= 1) else if(m_prop.textures.size() >= 1)
tname = m_textures[0]; tname = m_prop.textures[0];
tname += mod; tname += mod;
scene::IMeshBuffer *buf = mesh->getMeshBuffer(1); scene::IMeshBuffer *buf = mesh->getMeshBuffer(1);
buf->getMaterial().setTexture(0, buf->getMaterial().setTexture(0,
@ -1054,28 +1036,19 @@ public:
u8 cmd = readU8(is); u8 cmd = readU8(is);
if(cmd == GENERIC_CMD_SET_PROPERTIES) if(cmd == GENERIC_CMD_SET_PROPERTIES)
{ {
m_hp_max = readS16(is); m_prop = gob_read_set_properties(is);
m_physical = readU8(is);
m_weight = readF1000(is);
m_collisionbox.MinEdge = readV3F1000(is);
m_collisionbox.MaxEdge = readV3F1000(is);
m_visual = deSerializeString(is);
m_visual_size = readV2F1000(is);
m_textures.clear();
u32 texture_count = readU16(is);
for(u32 i=0; i<texture_count; i++){
m_textures.push_back(deSerializeString(is));
}
m_spritediv = readV2S16(is);
m_is_visible = readU8(is);
m_makes_footstep_sound = readU8(is);
m_selection_box = m_collisionbox; m_selection_box = m_prop.collisionbox;
m_selection_box.MinEdge *= BS; m_selection_box.MinEdge *= BS;
m_selection_box.MaxEdge *= BS; m_selection_box.MaxEdge *= BS;
m_tx_size.X = 1.0 / m_spritediv.X; m_tx_size.X = 1.0 / m_prop.spritediv.X;
m_tx_size.Y = 1.0 / m_spritediv.Y; m_tx_size.Y = 1.0 / m_prop.spritediv.Y;
if(!m_initial_tx_basepos_set){
m_initial_tx_basepos_set = true;
m_tx_basepos = m_prop.initial_sprite_basepos;
}
expireVisuals(); expireVisuals();
} }
@ -1090,7 +1063,7 @@ public:
float update_interval = readF1000(is); float update_interval = readF1000(is);
if(do_interpolate){ if(do_interpolate){
if(!m_physical) if(!m_prop.physical)
pos_translator.update(m_position, is_end_position, update_interval); pos_translator.update(m_position, is_end_position, update_interval);
} else { } else {
pos_translator.init(m_position); pos_translator.init(m_position);
@ -1147,8 +1120,6 @@ public:
punchitem, punchitem,
time_from_last_punch); time_from_last_punch);
dstream<<"Directly did_punch="<<result.did_punch<<" result.damage="<<result.damage<<std::endl;
if(result.did_punch && result.damage != 0) if(result.did_punch && result.damage != 0)
{ {
if(result.damage < m_hp){ if(result.damage < m_hp){
@ -1159,7 +1130,7 @@ public:
// As there is no definition, make a smoke puff // As there is no definition, make a smoke puff
ClientSimpleObject *simple = createSmokePuff( ClientSimpleObject *simple = createSmokePuff(
m_smgr, m_env, m_position, m_smgr, m_env, m_position,
m_visual_size * BS); m_prop.visual_size * BS);
m_env->addSimpleObject(simple); m_env->addSimpleObject(simple);
} }
// TODO: Execute defined fast response // TODO: Execute defined fast response

@ -336,8 +336,6 @@ ServerActiveObject* createItemSAO(ServerEnvironment *env, v3f pos,
LuaEntitySAO LuaEntitySAO
*/ */
#include "luaentity_common.h"
// Prototype (registers item for deserialization) // Prototype (registers item for deserialization)
LuaEntitySAO proto_LuaEntitySAO(NULL, v3f(0,0,0), "_prototype", ""); LuaEntitySAO proto_LuaEntitySAO(NULL, v3f(0,0,0), "_prototype", "");
@ -347,7 +345,6 @@ LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos,
m_init_name(name), m_init_name(name),
m_init_state(state), m_init_state(state),
m_registered(false), m_registered(false),
m_prop(new LuaEntityProperties),
m_hp(-1), m_hp(-1),
m_velocity(0,0,0), m_velocity(0,0,0),
m_acceleration(0,0,0), m_acceleration(0,0,0),
@ -377,7 +374,6 @@ LuaEntitySAO::~LuaEntitySAO()
lua_State *L = m_env->getLua(); lua_State *L = m_env->getLua();
scriptapi_luaentity_rm(L, m_id); scriptapi_luaentity_rm(L, m_id);
} }
delete m_prop;
} }
void LuaEntitySAO::addedToEnvironment() void LuaEntitySAO::addedToEnvironment()
@ -390,9 +386,9 @@ void LuaEntitySAO::addedToEnvironment()
if(m_registered){ if(m_registered){
// Get properties // Get properties
scriptapi_luaentity_get_properties(L, m_id, m_prop); scriptapi_luaentity_get_properties(L, m_id, &m_prop);
// Initialize HP from properties // Initialize HP from properties
m_hp = m_prop->hp_max; m_hp = m_prop.hp_max;
} }
// Activate entity, supplying serialized state // Activate entity, supplying serialized state
@ -447,8 +443,8 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
m_last_sent_position_timer += dtime; m_last_sent_position_timer += dtime;
if(m_prop->physical){ if(m_prop.physical){
core::aabbox3d<f32> box = m_prop->collisionbox; core::aabbox3d<f32> box = m_prop.collisionbox;
box.MinEdge *= BS; box.MinEdge *= BS;
box.MaxEdge *= BS; box.MaxEdge *= BS;
collisionMoveResult moveresult; collisionMoveResult moveresult;
@ -511,13 +507,9 @@ std::string LuaEntitySAO::getClientInitializationData()
writeV3F1000(os, m_base_position); writeV3F1000(os, m_base_position);
writeF1000(os, m_yaw); writeF1000(os, m_yaw);
writeS16(os, m_hp); writeS16(os, m_hp);
writeU8(os, 3); // number of messages stuffed in here writeU8(os, 2); // number of messages stuffed in here
os<<serializeLongString(getPropertyPacket()); // message 1 os<<serializeLongString(getPropertyPacket()); // message 1
os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2 os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2
os<<serializeLongString(gob_cmd_set_sprite( // 3
m_prop->initial_sprite_basepos,
1, 1.0, false
));
// return result // return result
return os.str(); return os.str();
} }
@ -710,18 +702,7 @@ std::string LuaEntitySAO::getName()
std::string LuaEntitySAO::getPropertyPacket() std::string LuaEntitySAO::getPropertyPacket()
{ {
return gob_cmd_set_properties( return gob_cmd_set_properties(m_prop);
m_prop->hp_max,
m_prop->physical,
m_prop->weight,
m_prop->collisionbox,
m_prop->visual,
m_prop->visual_size,
m_prop->textures,
m_prop->spritediv,
true, // is_visible
false // makes_footstep_sound
);
} }
void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end) void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end)
@ -778,6 +759,19 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_):
m_inventory = &m_player->inventory; m_inventory = &m_player->inventory;
m_armor_groups["choppy"] = 2; m_armor_groups["choppy"] = 2;
m_armor_groups["fleshy"] = 3; m_armor_groups["fleshy"] = 3;
m_prop.hp_max = PLAYER_MAX_HP;
m_prop.physical = false;
m_prop.weight = 75;
m_prop.collisionbox = core::aabbox3d<f32>(-1/3.,-1.0,-1/3., 1/3.,1.0,1/3.);
m_prop.visual = "upright_sprite";
m_prop.visual_size = v2f(1, 2);
m_prop.textures.clear();
m_prop.textures.push_back("player.png");
m_prop.textures.push_back("player_back.png");
m_prop.spritediv = v2s16(1,1);
m_prop.is_visible = (getHP() != 0);
m_prop.makes_footstep_sound = true;
} }
PlayerSAO::~PlayerSAO() PlayerSAO::~PlayerSAO()
@ -1107,20 +1101,7 @@ void PlayerSAO::createCreativeInventory()
std::string PlayerSAO::getPropertyPacket() std::string PlayerSAO::getPropertyPacket()
{ {
core::array<std::string> textures; m_prop.is_visible = (getHP() != 0);
textures.push_back("player.png"); return gob_cmd_set_properties(m_prop);
textures.push_back("player_back.png");
return gob_cmd_set_properties(
PLAYER_MAX_HP,
false,
75,
core::aabbox3d<f32>(-1/3.,-1.0,-1/3., 1/3.,1.0,1/3.),
"upright_sprite",
v2f(1, 2),
textures,
v2s16(1,1),
(getHP() != 0), // is_visible
true // makes_footstep_sound
);
} }

@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "content_object.h" #include "content_object.h"
#include "itemgroup.h" #include "itemgroup.h"
#include "player.h" #include "player.h"
#include "object_properties.h"
ServerActiveObject* createItemSAO(ServerEnvironment *env, v3f pos, ServerActiveObject* createItemSAO(ServerEnvironment *env, v3f pos,
const std::string itemstring); const std::string itemstring);
@ -32,8 +33,6 @@ ServerActiveObject* createItemSAO(ServerEnvironment *env, v3f pos,
LuaEntitySAO needs some internals exposed. LuaEntitySAO needs some internals exposed.
*/ */
struct LuaEntityProperties;
class LuaEntitySAO : public ServerActiveObject class LuaEntitySAO : public ServerActiveObject
{ {
public: public:
@ -80,7 +79,7 @@ private:
std::string m_init_name; std::string m_init_name;
std::string m_init_state; std::string m_init_state;
bool m_registered; bool m_registered;
struct LuaEntityProperties *m_prop; struct ObjectProperties m_prop;
s16 m_hp; s16 m_hp;
v3f m_velocity; v3f m_velocity;
@ -193,6 +192,7 @@ private:
ItemGroupList m_armor_groups; ItemGroupList m_armor_groups;
bool m_armor_groups_sent; bool m_armor_groups_sent;
bool m_properties_sent; bool m_properties_sent;
struct ObjectProperties m_prop;
public: public:
// Some flags used by Server // Some flags used by Server

@ -21,37 +21,50 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "utility.h" #include "utility.h"
#include <sstream> #include <sstream>
std::string gob_cmd_set_properties( std::string gob_cmd_set_properties(const ObjectProperties &prop)
s16 hp_max, {
bool physical,
float weight,
core::aabbox3d<f32> collisionbox,
std::string visual,
v2f visual_size,
core::array<std::string> textures,
v2s16 spritediv,
bool is_visible,
bool makes_footstep_sound
){
std::ostringstream os(std::ios::binary); std::ostringstream os(std::ios::binary);
writeU8(os, GENERIC_CMD_SET_PROPERTIES); writeU8(os, GENERIC_CMD_SET_PROPERTIES);
writeS16(os, hp_max); writeS16(os, prop.hp_max);
writeU8(os, physical); writeU8(os, prop.physical);
writeF1000(os, weight); writeF1000(os, prop.weight);
writeV3F1000(os, collisionbox.MinEdge); writeV3F1000(os, prop.collisionbox.MinEdge);
writeV3F1000(os, collisionbox.MaxEdge); writeV3F1000(os, prop.collisionbox.MaxEdge);
os<<serializeString(visual); os<<serializeString(prop.visual);
writeV2F1000(os, visual_size); writeV2F1000(os, prop.visual_size);
writeU16(os, textures.size()); writeU16(os, prop.textures.size());
for(u32 i=0; i<textures.size(); i++){ for(u32 i=0; i<prop.textures.size(); i++){
os<<serializeString(textures[i]); os<<serializeString(prop.textures[i]);
} }
writeV2S16(os, spritediv); writeV2S16(os, prop.spritediv);
writeU8(os, is_visible); writeV2S16(os, prop.initial_sprite_basepos);
writeU8(os, makes_footstep_sound); writeU8(os, prop.is_visible);
writeU8(os, prop.makes_footstep_sound);
return os.str(); return os.str();
} }
ObjectProperties gob_read_set_properties(std::istream &is)
{
ObjectProperties prop;
prop.hp_max = readS16(is);
prop.physical = readU8(is);
prop.weight = readF1000(is);
prop.collisionbox.MinEdge = readV3F1000(is);
prop.collisionbox.MaxEdge = readV3F1000(is);
prop.visual = deSerializeString(is);
prop.visual_size = readV2F1000(is);
prop.textures.clear();
u32 texture_count = readU16(is);
for(u32 i=0; i<texture_count; i++){
prop.textures.push_back(deSerializeString(is));
}
prop.spritediv = readV2S16(is);
prop.initial_sprite_basepos = readV2S16(is);
prop.is_visible = readU8(is);
prop.makes_footstep_sound = readU8(is);
return prop;
}
std::string gob_cmd_update_position( std::string gob_cmd_update_position(
v3f position, v3f position,
v3f velocity, v3f velocity,

@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <string> #include <string>
#include "irrlichttypes.h" #include "irrlichttypes.h"
#include <iostream>
#define GENERIC_CMD_SET_PROPERTIES 0 #define GENERIC_CMD_SET_PROPERTIES 0
#define GENERIC_CMD_UPDATE_POSITION 1 #define GENERIC_CMD_UPDATE_POSITION 1
@ -30,18 +31,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define GENERIC_CMD_PUNCHED 4 #define GENERIC_CMD_PUNCHED 4
#define GENERIC_CMD_UPDATE_ARMOR_GROUPS 5 #define GENERIC_CMD_UPDATE_ARMOR_GROUPS 5
std::string gob_cmd_set_properties( #include "object_properties.h"
s16 hp_max, std::string gob_cmd_set_properties(const ObjectProperties &prop);
bool physical, ObjectProperties gob_read_set_properties(std::istream &is);
float weight,
core::aabbox3d<f32> collisionbox,
std::string visual,
v2f visual_size,
core::array<std::string> textures,
v2s16 spritediv,
bool is_visible,
bool makes_footstep_sound
);
std::string gob_cmd_update_position( std::string gob_cmd_update_position(
v3f position, v3f position,

@ -20,29 +20,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef LUAENTITY_COMMON_HEADER #ifndef LUAENTITY_COMMON_HEADER
#define LUAENTITY_COMMON_HEADER #define LUAENTITY_COMMON_HEADER
#include <string>
#include "irrlichttypes.h"
#include <iostream>
struct LuaEntityProperties
{
// Values are BS=1
s16 hp_max;
bool physical;
float weight;
core::aabbox3d<f32> collisionbox;
std::string visual;
v2f visual_size;
core::array<std::string> textures;
v2s16 spritediv;
v2s16 initial_sprite_basepos;
LuaEntityProperties();
std::string dump();
void serialize(std::ostream &os);
void deSerialize(std::istream &is);
};
#define LUAENTITY_CMD_UPDATE_POSITION 0 #define LUAENTITY_CMD_UPDATE_POSITION 0
#define LUAENTITY_CMD_SET_TEXTURE_MOD 1 #define LUAENTITY_CMD_SET_TEXTURE_MOD 1
#define LUAENTITY_CMD_SET_SPRITE 2 #define LUAENTITY_CMD_SET_SPRITE 2

@ -1,6 +1,6 @@
/* /*
Minetest-c55 Minetest-c55
Copyright (C) 2011 celeron55, Perttu Ahola <celeron55@gmail.com> Copyright (C) 2012 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -17,14 +17,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include "luaentity_common.h" #include "object_properties.h"
#include "utility.h" #include "utility.h"
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")" #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
#define PP2(x) "("<<(x).X<<","<<(x).Y<<")" #define PP2(x) "("<<(x).X<<","<<(x).Y<<")"
LuaEntityProperties::LuaEntityProperties(): ObjectProperties::ObjectProperties():
hp_max(1), hp_max(1),
physical(false), physical(false),
weight(5), weight(5),
@ -32,12 +31,14 @@ LuaEntityProperties::LuaEntityProperties():
visual("sprite"), visual("sprite"),
visual_size(1,1), visual_size(1,1),
spritediv(1,1), spritediv(1,1),
initial_sprite_basepos(0,0) initial_sprite_basepos(0,0),
is_visible(true),
makes_footstep_sound(false)
{ {
textures.push_back("unknown_object.png"); textures.push_back("unknown_object.png");
} }
std::string LuaEntityProperties::dump() std::string ObjectProperties::dump()
{ {
std::ostringstream os(std::ios::binary); std::ostringstream os(std::ios::binary);
os<<"hp_max="<<hp_max; os<<"hp_max="<<hp_max;
@ -53,10 +54,12 @@ std::string LuaEntityProperties::dump()
os<<"]"; os<<"]";
os<<", spritediv="<<PP2(spritediv); os<<", spritediv="<<PP2(spritediv);
os<<", initial_sprite_basepos="<<PP2(initial_sprite_basepos); os<<", initial_sprite_basepos="<<PP2(initial_sprite_basepos);
os<<", is_visible"<<is_visible;
os<<", makes_footstep_sound="<<makes_footstep_sound;
return os.str(); return os.str();
} }
void LuaEntityProperties::serialize(std::ostream &os) void ObjectProperties::serialize(std::ostream &os)
{ {
writeU8(os, 1); // version writeU8(os, 1); // version
writeS16(os, hp_max); writeS16(os, hp_max);
@ -72,13 +75,15 @@ void LuaEntityProperties::serialize(std::ostream &os)
} }
writeV2S16(os, spritediv); writeV2S16(os, spritediv);
writeV2S16(os, initial_sprite_basepos); writeV2S16(os, initial_sprite_basepos);
writeU8(os, is_visible);
writeU8(os, makes_footstep_sound);
} }
void LuaEntityProperties::deSerialize(std::istream &is) void ObjectProperties::deSerialize(std::istream &is)
{ {
int version = readU8(is); int version = readU8(is);
if(version != 1) throw SerializationError( if(version != 1) throw SerializationError(
"unsupported LuaEntityProperties version"); "unsupported ObjectProperties version");
hp_max = readS16(is); hp_max = readS16(is);
physical = readU8(is); physical = readU8(is);
weight = readF1000(is); weight = readF1000(is);
@ -93,6 +98,8 @@ void LuaEntityProperties::deSerialize(std::istream &is)
} }
spritediv = readV2S16(is); spritediv = readV2S16(is);
initial_sprite_basepos = readV2S16(is); initial_sprite_basepos = readV2S16(is);
is_visible = readU8(is);
makes_footstep_sound = readU8(is);
} }

49
src/object_properties.h Normal file

@ -0,0 +1,49 @@
/*
Minetest-c55
Copyright (C) 2012 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef OBJECT_PROPERTIES_HEADER
#define OBJECT_PROPERTIES_HEADER
#include <string>
#include "irrlichttypes.h"
#include <iostream>
struct ObjectProperties
{
// Values are BS=1
s16 hp_max;
bool physical;
float weight;
core::aabbox3d<f32> collisionbox;
std::string visual;
v2f visual_size;
core::array<std::string> textures;
v2s16 spritediv;
v2s16 initial_sprite_basepos;
bool is_visible;
bool makes_footstep_sound;
ObjectProperties();
std::string dump();
void serialize(std::ostream &os);
void deSerialize(std::istream &is);
};
#endif

@ -33,8 +33,7 @@ extern "C" {
#include "filesys.h" #include "filesys.h"
#include "serverobject.h" #include "serverobject.h"
#include "script.h" #include "script.h"
//#include "luna.h" #include "object_properties.h"
#include "luaentity_common.h"
#include "content_sao.h" // For LuaEntitySAO and PlayerSAO #include "content_sao.h" // For LuaEntitySAO and PlayerSAO
#include "itemdef.h" #include "itemdef.h"
#include "nodedef.h" #include "nodedef.h"
@ -4679,7 +4678,7 @@ std::string scriptapi_luaentity_get_staticdata(lua_State *L, u16 id)
} }
void scriptapi_luaentity_get_properties(lua_State *L, u16 id, void scriptapi_luaentity_get_properties(lua_State *L, u16 id,
LuaEntityProperties *prop) ObjectProperties *prop)
{ {
realitycheck(L); realitycheck(L);
assert(lua_checkstack(L, 20)); assert(lua_checkstack(L, 20));

@ -28,7 +28,7 @@ class Server;
class ServerEnvironment; class ServerEnvironment;
class ServerActiveObject; class ServerActiveObject;
typedef struct lua_State lua_State; typedef struct lua_State lua_State;
struct LuaEntityProperties; struct ObjectProperties;
struct ItemStack; struct ItemStack;
struct PointedThing; struct PointedThing;
//class IGameDef; //class IGameDef;
@ -83,7 +83,7 @@ void scriptapi_luaentity_activate(lua_State *L, u16 id,
void scriptapi_luaentity_rm(lua_State *L, u16 id); void scriptapi_luaentity_rm(lua_State *L, u16 id);
std::string scriptapi_luaentity_get_staticdata(lua_State *L, u16 id); std::string scriptapi_luaentity_get_staticdata(lua_State *L, u16 id);
void scriptapi_luaentity_get_properties(lua_State *L, u16 id, void scriptapi_luaentity_get_properties(lua_State *L, u16 id,
LuaEntityProperties *prop); ObjectProperties *prop);
void scriptapi_luaentity_step(lua_State *L, u16 id, float dtime); void scriptapi_luaentity_step(lua_State *L, u16 id, float dtime);
void scriptapi_luaentity_punch(lua_State *L, u16 id, void scriptapi_luaentity_punch(lua_State *L, u16 id,
ServerActiveObject *puncher, float time_from_last_punch, ServerActiveObject *puncher, float time_from_last_punch,