Browse Source

ObjectProperties

nephele-craftmethods
Perttu Ahola 10 years ago
parent
commit
9e7ccedba4
  1. 2
      src/CMakeLists.txt
  2. 107
      src/content_cao.cpp
  3. 61
      src/content_sao.cpp
  4. 6
      src/content_sao.h
  5. 63
      src/genericobject.cpp
  6. 16
      src/genericobject.h
  7. 23
      src/luaentity_common.h
  8. 25
      src/object_properties.cpp
  9. 49
      src/object_properties.h
  10. 5
      src/scriptapi.cpp
  11. 4
      src/scriptapi.h

2
src/CMakeLists.txt

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

107
src/content_cao.cpp

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

61
src/content_sao.cpp

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

6
src/content_sao.h

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

63
src/genericobject.cpp

@ -21,37 +21,50 @@ with this program; if not, write to the Free Software Foundation, Inc., @@ -21,37 +21,50 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "utility.h"
#include <sstream>
std::string gob_cmd_set_properties(
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::string gob_cmd_set_properties(const ObjectProperties &prop)
{
std::ostringstream os(std::ios::binary);
writeU8(os, GENERIC_CMD_SET_PROPERTIES);
writeS16(os, hp_max);
writeU8(os, physical);
writeF1000(os, weight);
writeV3F1000(os, collisionbox.MinEdge);
writeV3F1000(os, collisionbox.MaxEdge);
os<<serializeString(visual);
writeV2F1000(os, visual_size);
writeU16(os, textures.size());
for(u32 i=0; i<textures.size(); i++){
os<<serializeString(textures[i]);
writeS16(os, prop.hp_max);
writeU8(os, prop.physical);
writeF1000(os, prop.weight);
writeV3F1000(os, prop.collisionbox.MinEdge);
writeV3F1000(os, prop.collisionbox.MaxEdge);
os<<serializeString(prop.visual);
writeV2F1000(os, prop.visual_size);
writeU16(os, prop.textures.size());
for(u32 i=0; i<prop.textures.size(); i++){
os<<serializeString(prop.textures[i]);
}
writeV2S16(os, spritediv);
writeU8(os, is_visible);
writeU8(os, makes_footstep_sound);
writeV2S16(os, prop.spritediv);
writeV2S16(os, prop.initial_sprite_basepos);
writeU8(os, prop.is_visible);
writeU8(os, prop.makes_footstep_sound);
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(
v3f position,
v3f velocity,

16
src/genericobject.h

@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., @@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <string>
#include "irrlichttypes.h"
#include <iostream>
#define GENERIC_CMD_SET_PROPERTIES 0
#define GENERIC_CMD_UPDATE_POSITION 1
@ -30,18 +31,9 @@ with this program; if not, write to the Free Software Foundation, Inc., @@ -30,18 +31,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define GENERIC_CMD_PUNCHED 4
#define GENERIC_CMD_UPDATE_ARMOR_GROUPS 5
std::string gob_cmd_set_properties(
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
);
#include "object_properties.h"
std::string gob_cmd_set_properties(const ObjectProperties &prop);
ObjectProperties gob_read_set_properties(std::istream &is);
std::string gob_cmd_update_position(
v3f position,

23
src/luaentity_common.h

@ -20,29 +20,6 @@ with this program; if not, write to the Free Software Foundation, Inc., @@ -20,29 +20,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef 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_SET_TEXTURE_MOD 1
#define LUAENTITY_CMD_SET_SPRITE 2

25
src/luaentity_common.cpp → src/object_properties.cpp

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
/*
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
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., @@ -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.
*/
#include "luaentity_common.h"
#include "object_properties.h"
#include "utility.h"
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
#define PP2(x) "("<<(x).X<<","<<(x).Y<<")"
LuaEntityProperties::LuaEntityProperties():
ObjectProperties::ObjectProperties():
hp_max(1),
physical(false),
weight(5),
@ -32,12 +31,14 @@ LuaEntityProperties::LuaEntityProperties(): @@ -32,12 +31,14 @@ LuaEntityProperties::LuaEntityProperties():
visual("sprite"),
visual_size(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");
}
std::string LuaEntityProperties::dump()
std::string ObjectProperties::dump()
{
std::ostringstream os(std::ios::binary);
os<<"hp_max="<<hp_max;
@ -53,10 +54,12 @@ std::string LuaEntityProperties::dump() @@ -53,10 +54,12 @@ std::string LuaEntityProperties::dump()
os<<"]";
os<<", spritediv="<<PP2(spritediv);
os<<", initial_sprite_basepos="<<PP2(initial_sprite_basepos);
os<<", is_visible"<<is_visible;
os<<", makes_footstep_sound="<<makes_footstep_sound;
return os.str();
}
void LuaEntityProperties::serialize(std::ostream &os)
void ObjectProperties::serialize(std::ostream &os)
{
writeU8(os, 1); // version
writeS16(os, hp_max);
@ -72,13 +75,15 @@ void LuaEntityProperties::serialize(std::ostream &os) @@ -72,13 +75,15 @@ void LuaEntityProperties::serialize(std::ostream &os)
}
writeV2S16(os, spritediv);
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);
if(version != 1) throw SerializationError(
"unsupported LuaEntityProperties version");
"unsupported ObjectProperties version");
hp_max = readS16(is);
physical = readU8(is);
weight = readF1000(is);
@ -93,6 +98,8 @@ void LuaEntityProperties::deSerialize(std::istream &is) @@ -93,6 +98,8 @@ void LuaEntityProperties::deSerialize(std::istream &is)
}
spritediv = readV2S16(is);
initial_sprite_basepos = readV2S16(is);
is_visible = readU8(is);
makes_footstep_sound = readU8(is);
}

49
src/object_properties.h

@ -0,0 +1,49 @@ @@ -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

5
src/scriptapi.cpp

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

4
src/scriptapi.h

@ -28,7 +28,7 @@ class Server; @@ -28,7 +28,7 @@ class Server;
class ServerEnvironment;
class ServerActiveObject;
typedef struct lua_State lua_State;
struct LuaEntityProperties;
struct ObjectProperties;
struct ItemStack;
struct PointedThing;
//class IGameDef;
@ -83,7 +83,7 @@ void scriptapi_luaentity_activate(lua_State *L, u16 id, @@ -83,7 +83,7 @@ void scriptapi_luaentity_activate(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);
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_punch(lua_State *L, u16 id,
ServerActiveObject *puncher, float time_from_last_punch,

Loading…
Cancel
Save