Fix code style from recent commits and add misc. optimizations
parent
0a0378fece
commit
7b171ea2be
71
src/player.h
71
src/player.h
|
@ -130,13 +130,8 @@ public:
|
||||||
|
|
||||||
v3f getEyeOffset()
|
v3f getEyeOffset()
|
||||||
{
|
{
|
||||||
// This is at the height of the eyes of the current figure
|
float eye_height = camera_barely_in_ceiling ? 1.5f : 1.625f;
|
||||||
// return v3f(0, BS*1.5, 0);
|
return v3f(0, BS * eye_height, 0);
|
||||||
// This is more like in minecraft
|
|
||||||
if(camera_barely_in_ceiling)
|
|
||||||
return v3f(0,BS*1.5,0);
|
|
||||||
else
|
|
||||||
return v3f(0,BS*1.625,0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
v3f getEyePosition()
|
v3f getEyePosition()
|
||||||
|
@ -197,12 +192,13 @@ public:
|
||||||
return (m_yaw + 90.) * core::DEGTORAD;
|
return (m_yaw + 90.) * core::DEGTORAD;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * getName() const
|
const char *getName() const
|
||||||
{
|
{
|
||||||
return m_name;
|
return m_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
core::aabbox3d<f32> getCollisionbox() {
|
core::aabbox3d<f32> getCollisionbox()
|
||||||
|
{
|
||||||
return m_collisionbox;
|
return m_collisionbox;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,62 +211,91 @@ public:
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setHotbarItemcount(s32 hotbar_itemcount) {
|
void setHotbarItemcount(s32 hotbar_itemcount)
|
||||||
|
{
|
||||||
hud_hotbar_itemcount = hotbar_itemcount;
|
hud_hotbar_itemcount = hotbar_itemcount;
|
||||||
}
|
}
|
||||||
s32 getHotbarItemcount() {
|
|
||||||
|
s32 getHotbarItemcount()
|
||||||
|
{
|
||||||
return hud_hotbar_itemcount;
|
return hud_hotbar_itemcount;
|
||||||
}
|
}
|
||||||
void setHotbarImage(std::string name) {
|
|
||||||
|
void setHotbarImage(const std::string &name)
|
||||||
|
{
|
||||||
hud_hotbar_image = name;
|
hud_hotbar_image = name;
|
||||||
}
|
}
|
||||||
std::string getHotbarImage() {
|
|
||||||
|
std::string getHotbarImage()
|
||||||
|
{
|
||||||
return hud_hotbar_image;
|
return hud_hotbar_image;
|
||||||
}
|
}
|
||||||
void setHotbarSelectedImage(std::string name) {
|
|
||||||
|
void setHotbarSelectedImage(const std::string &name)
|
||||||
|
{
|
||||||
hud_hotbar_selected_image = name;
|
hud_hotbar_selected_image = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getHotbarSelectedImage() {
|
std::string getHotbarSelectedImage() {
|
||||||
return hud_hotbar_selected_image;
|
return hud_hotbar_selected_image;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setSky(const video::SColor &bgcolor, const std::string &type,
|
void setSky(const video::SColor &bgcolor, const std::string &type,
|
||||||
const std::vector<std::string> ¶ms) {
|
const std::vector<std::string> ¶ms)
|
||||||
|
{
|
||||||
m_sky_bgcolor = bgcolor;
|
m_sky_bgcolor = bgcolor;
|
||||||
m_sky_type = type;
|
m_sky_type = type;
|
||||||
m_sky_params = params;
|
m_sky_params = params;
|
||||||
}
|
}
|
||||||
|
|
||||||
void getSky(video::SColor *bgcolor, std::string *type,
|
void getSky(video::SColor *bgcolor, std::string *type,
|
||||||
std::vector<std::string> *params) {
|
std::vector<std::string> *params)
|
||||||
|
{
|
||||||
*bgcolor = m_sky_bgcolor;
|
*bgcolor = m_sky_bgcolor;
|
||||||
*type = m_sky_type;
|
*type = m_sky_type;
|
||||||
*params = m_sky_params;
|
*params = m_sky_params;
|
||||||
}
|
}
|
||||||
void overrideDayNightRatio(bool do_override, float ratio) {
|
|
||||||
|
void overrideDayNightRatio(bool do_override, float ratio)
|
||||||
|
{
|
||||||
m_day_night_ratio_do_override = do_override;
|
m_day_night_ratio_do_override = do_override;
|
||||||
m_day_night_ratio = ratio;
|
m_day_night_ratio = ratio;
|
||||||
}
|
}
|
||||||
void getDayNightRatio(bool *do_override, float *ratio) {
|
|
||||||
|
void getDayNightRatio(bool *do_override, float *ratio)
|
||||||
|
{
|
||||||
*do_override = m_day_night_ratio_do_override;
|
*do_override = m_day_night_ratio_do_override;
|
||||||
*ratio = m_day_night_ratio;
|
*ratio = m_day_night_ratio;
|
||||||
}
|
}
|
||||||
void setLocalAnimations(v2s32 frames[4], float frame_speed) {
|
|
||||||
|
void setLocalAnimations(v2s32 frames[4], float frame_speed)
|
||||||
|
{
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
local_animations[i] = frames[i];
|
local_animations[i] = frames[i];
|
||||||
local_animation_speed = frame_speed;
|
local_animation_speed = frame_speed;
|
||||||
}
|
}
|
||||||
void getLocalAnimations(v2s32 *frames, float *frame_speed) {
|
|
||||||
|
void getLocalAnimations(v2s32 *frames, float *frame_speed)
|
||||||
|
{
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
frames[i] = local_animations[i];
|
frames[i] = local_animations[i];
|
||||||
*frame_speed = local_animation_speed;
|
*frame_speed = local_animation_speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool isLocal() const
|
virtual bool isLocal() const
|
||||||
{ return false; }
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
virtual PlayerSAO *getPlayerSAO()
|
virtual PlayerSAO *getPlayerSAO()
|
||||||
{ return NULL; }
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
virtual void setPlayerSAO(PlayerSAO *sao)
|
virtual void setPlayerSAO(PlayerSAO *sao)
|
||||||
{ FATAL_ERROR("FIXME"); }
|
{
|
||||||
|
FATAL_ERROR("FIXME");
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
serialize() writes a bunch of text that can contain
|
serialize() writes a bunch of text that can contain
|
||||||
|
|
|
@ -749,25 +749,23 @@ const char *getVideoDriverFriendlyName(irr::video::E_DRIVER_TYPE type)
|
||||||
|
|
||||||
static float calcDisplayDensity()
|
static float calcDisplayDensity()
|
||||||
{
|
{
|
||||||
const char* current_display = getenv("DISPLAY");
|
const char *current_display = getenv("DISPLAY");
|
||||||
|
|
||||||
if (current_display != NULL) {
|
if (current_display != NULL) {
|
||||||
Display * x11display = XOpenDisplay(current_display);
|
Display *x11display = XOpenDisplay(current_display);
|
||||||
|
|
||||||
if (x11display != NULL) {
|
if (x11display != NULL) {
|
||||||
/* try x direct */
|
/* try x direct */
|
||||||
float dpi_height =
|
float dpi_height = floor(DisplayHeight(x11display, 0) /
|
||||||
floor(DisplayHeight(x11display, 0) /
|
(DisplayHeightMM(x11display, 0) * 0.039370) + 0.5);
|
||||||
(DisplayHeightMM(x11display, 0) * 0.039370) + 0.5);
|
float dpi_width = floor(DisplayWidth(x11display, 0) /
|
||||||
float dpi_width =
|
(DisplayWidthMM(x11display, 0) * 0.039370) + 0.5);
|
||||||
floor(DisplayWidth(x11display, 0) /
|
|
||||||
(DisplayWidthMM(x11display, 0) * 0.039370) +0.5);
|
|
||||||
|
|
||||||
XCloseDisplay(x11display);
|
XCloseDisplay(x11display);
|
||||||
|
|
||||||
return std::max(dpi_height,dpi_width) / 96.0;
|
return std::max(dpi_height,dpi_width) / 96.0;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* return manually specified dpi */
|
/* return manually specified dpi */
|
||||||
return g_settings->getFloat("screen_dpi")/96.0;
|
return g_settings->getFloat("screen_dpi")/96.0;
|
||||||
|
|
|
@ -985,11 +985,11 @@ void read_groups(lua_State *L, int index,
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
void push_groups(lua_State *L, std::map<std::string, int> groups)
|
void push_groups(lua_State *L, const std::map<std::string, int> &groups)
|
||||||
{
|
{
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
for (std::map<std::string, int>::iterator it = groups.begin();
|
std::map<std::string, int>::const_iterator it;
|
||||||
it != groups.end(); ++it) {
|
for (it = groups.begin(); it != groups.end(); ++it) {
|
||||||
lua_pushnumber(L, it->second);
|
lua_pushnumber(L, it->second);
|
||||||
lua_setfield(L, -2, it->first.c_str());
|
lua_setfield(L, -2, it->first.c_str());
|
||||||
}
|
}
|
||||||
|
@ -998,12 +998,10 @@ void push_groups(lua_State *L, std::map<std::string, int> groups)
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
void push_items(lua_State *L, const std::vector<ItemStack> &items)
|
void push_items(lua_State *L, const std::vector<ItemStack> &items)
|
||||||
{
|
{
|
||||||
// Create and fill table
|
|
||||||
lua_createtable(L, items.size(), 0);
|
lua_createtable(L, items.size(), 0);
|
||||||
std::vector<ItemStack>::const_iterator iter = items.begin();
|
for (u32 i = 0; i != items.size(); i++) {
|
||||||
for (u32 i = 0; iter != items.end(); iter++) {
|
LuaItemStack::create(L, items[i]);
|
||||||
LuaItemStack::create(L, *iter);
|
lua_rawseti(L, -2, i + 1);
|
||||||
lua_rawseti(L, -2, ++i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,61 +62,56 @@ struct NoiseParams;
|
||||||
class Schematic;
|
class Schematic;
|
||||||
|
|
||||||
|
|
||||||
ContentFeatures read_content_features (lua_State *L, int index);
|
ContentFeatures read_content_features (lua_State *L, int index);
|
||||||
TileDef read_tiledef (lua_State *L, int index);
|
TileDef read_tiledef (lua_State *L, int index);
|
||||||
void read_soundspec (lua_State *L, int index,
|
void read_soundspec (lua_State *L, int index,
|
||||||
SimpleSoundSpec &spec);
|
SimpleSoundSpec &spec);
|
||||||
NodeBox read_nodebox (lua_State *L, int index);
|
NodeBox read_nodebox (lua_State *L, int index);
|
||||||
|
|
||||||
void read_server_sound_params (lua_State *L, int index,
|
void read_server_sound_params (lua_State *L, int index,
|
||||||
ServerSoundParams ¶ms);
|
ServerSoundParams ¶ms);
|
||||||
|
|
||||||
void push_dig_params (lua_State *L,const DigParams ¶ms);
|
void push_dig_params (lua_State *L,
|
||||||
void push_hit_params (lua_State *L,const HitParams ¶ms);
|
const DigParams ¶ms);
|
||||||
|
void push_hit_params (lua_State *L,
|
||||||
|
const HitParams ¶ms);
|
||||||
|
|
||||||
ItemStack read_item (lua_State *L, int index, Server* srv);
|
ItemStack read_item (lua_State *L, int index, Server *srv);
|
||||||
|
|
||||||
|
|
||||||
ToolCapabilities read_tool_capabilities (lua_State *L,
|
ToolCapabilities read_tool_capabilities (lua_State *L, int table);
|
||||||
int table);
|
|
||||||
void push_tool_capabilities (lua_State *L,
|
void push_tool_capabilities (lua_State *L,
|
||||||
const ToolCapabilities &prop);
|
const ToolCapabilities &prop);
|
||||||
|
|
||||||
ItemDefinition read_item_definition (lua_State *L,
|
ItemDefinition read_item_definition (lua_State *L, int index,
|
||||||
int index,
|
|
||||||
ItemDefinition default_def);
|
ItemDefinition default_def);
|
||||||
void read_object_properties (lua_State *L,
|
void read_object_properties (lua_State *L, int index,
|
||||||
int index,
|
ObjectProperties *prop);
|
||||||
|
void push_object_properties (lua_State *L,
|
||||||
ObjectProperties *prop);
|
ObjectProperties *prop);
|
||||||
void push_object_properties (lua_State *L,
|
|
||||||
ObjectProperties *prop);
|
|
||||||
|
|
||||||
void push_inventory_list (lua_State *L,
|
void push_inventory_list (lua_State *L,
|
||||||
Inventory *inv,
|
Inventory *inv,
|
||||||
const char *name);
|
const char *name);
|
||||||
void read_inventory_list (lua_State *L,
|
void read_inventory_list (lua_State *L, int tableindex,
|
||||||
int tableindex,
|
Inventory *inv, const char *name,
|
||||||
Inventory *inv,
|
Server *srv, int forcesize=-1);
|
||||||
const char *name,
|
|
||||||
Server* srv,
|
|
||||||
int forcesize=-1);
|
|
||||||
|
|
||||||
MapNode readnode (lua_State *L,
|
MapNode readnode (lua_State *L, int index,
|
||||||
int index,
|
|
||||||
INodeDefManager *ndef);
|
INodeDefManager *ndef);
|
||||||
void pushnode (lua_State *L,
|
void pushnode (lua_State *L, const MapNode &n,
|
||||||
const MapNode &n,
|
|
||||||
INodeDefManager *ndef);
|
INodeDefManager *ndef);
|
||||||
|
|
||||||
NodeBox read_nodebox (lua_State *L, int index);
|
NodeBox read_nodebox (lua_State *L, int index);
|
||||||
|
|
||||||
void read_groups (lua_State *L,
|
void read_groups (lua_State *L, int index,
|
||||||
int index,
|
|
||||||
std::map<std::string, int> &result);
|
std::map<std::string, int> &result);
|
||||||
|
|
||||||
|
void push_groups (lua_State *L,
|
||||||
|
const std::map<std::string, int> &groups);
|
||||||
|
|
||||||
//TODO rename to "read_enum_field"
|
//TODO rename to "read_enum_field"
|
||||||
int getenumfield (lua_State *L,
|
int getenumfield (lua_State *L, int table,
|
||||||
int table,
|
|
||||||
const char *fieldname,
|
const char *fieldname,
|
||||||
const EnumString *spec,
|
const EnumString *spec,
|
||||||
int default_);
|
int default_);
|
||||||
|
@ -129,8 +124,9 @@ bool getflagsfield (lua_State *L, int table,
|
||||||
bool read_flags (lua_State *L, int index,
|
bool read_flags (lua_State *L, int index,
|
||||||
FlagDesc *flagdesc,
|
FlagDesc *flagdesc,
|
||||||
u32 *flags, u32 *flagmask);
|
u32 *flags, u32 *flagmask);
|
||||||
void push_flags_string (lua_State *L, FlagDesc *flagdesc,
|
|
||||||
u32 flags, u32 flagmask);
|
void push_flags_string (lua_State *L, FlagDesc *flagdesc,
|
||||||
|
u32 flags, u32 flagmask);
|
||||||
|
|
||||||
u32 read_flags_table (lua_State *L, int table,
|
u32 read_flags_table (lua_State *L, int table,
|
||||||
FlagDesc *flagdesc, u32 *flagmask);
|
FlagDesc *flagdesc, u32 *flagmask);
|
||||||
|
@ -146,24 +142,21 @@ void read_soundspec (lua_State *L,
|
||||||
int index,
|
int index,
|
||||||
SimpleSoundSpec &spec);
|
SimpleSoundSpec &spec);
|
||||||
|
|
||||||
|
|
||||||
bool string_to_enum (const EnumString *spec,
|
bool string_to_enum (const EnumString *spec,
|
||||||
int &result,
|
int &result,
|
||||||
const std::string &str);
|
const std::string &str);
|
||||||
|
|
||||||
bool read_noiseparams (lua_State *L, int index,
|
bool read_noiseparams (lua_State *L, int index,
|
||||||
NoiseParams *np);
|
NoiseParams *np);
|
||||||
void push_noiseparams (lua_State *L, NoiseParams *np);
|
void push_noiseparams (lua_State *L, NoiseParams *np);
|
||||||
|
|
||||||
void luaentity_get (lua_State *L,u16 id);
|
void luaentity_get (lua_State *L,u16 id);
|
||||||
|
|
||||||
bool push_json_value (lua_State *L,
|
bool push_json_value (lua_State *L,
|
||||||
const Json::Value &value,
|
const Json::Value &value,
|
||||||
int nullindex);
|
int nullindex);
|
||||||
void read_json_value (lua_State *L,
|
void read_json_value (lua_State *L, Json::Value &root,
|
||||||
Json::Value &root,
|
int index, u8 recursion = 0);
|
||||||
int index,
|
|
||||||
u8 recursion = 0);
|
|
||||||
|
|
||||||
extern struct EnumString es_TileAnimationType[];
|
extern struct EnumString es_TileAnimationType[];
|
||||||
|
|
||||||
|
|
|
@ -104,8 +104,6 @@ void push_ARGB8 (lua_State *L, video::SColor color);
|
||||||
void pushFloatPos (lua_State *L, v3f p);
|
void pushFloatPos (lua_State *L, v3f p);
|
||||||
void push_v3f (lua_State *L, v3f p);
|
void push_v3f (lua_State *L, v3f p);
|
||||||
void push_v2f (lua_State *L, v2f p);
|
void push_v2f (lua_State *L, v2f p);
|
||||||
void push_groups (lua_State *L,
|
|
||||||
std::map<std::string, int> groups);
|
|
||||||
|
|
||||||
void warn_if_field_exists(lua_State *L, int table,
|
void warn_if_field_exists(lua_State *L, int table,
|
||||||
const char *fieldname,
|
const char *fieldname,
|
||||||
|
|
|
@ -142,7 +142,7 @@ bool ScriptApiBase::loadScript(const std::string &script_path, std::string *erro
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
std::string error_msg = lua_tostring(L, -1);
|
std::string error_msg = lua_tostring(L, -1);
|
||||||
if (error)
|
if (error)
|
||||||
(*error) = error_msg;
|
*error = error_msg;
|
||||||
errorstream << "========== ERROR FROM LUA ===========" << std::endl
|
errorstream << "========== ERROR FROM LUA ===========" << std::endl
|
||||||
<< "Failed to load and run script from " << std::endl
|
<< "Failed to load and run script from " << std::endl
|
||||||
<< script_path << ":" << std::endl << std::endl
|
<< script_path << ":" << std::endl << std::endl
|
||||||
|
@ -157,8 +157,8 @@ bool ScriptApiBase::loadScript(const std::string &script_path, std::string *erro
|
||||||
void ScriptApiBase::realityCheck()
|
void ScriptApiBase::realityCheck()
|
||||||
{
|
{
|
||||||
int top = lua_gettop(m_luastack);
|
int top = lua_gettop(m_luastack);
|
||||||
if(top >= 30){
|
if (top >= 30) {
|
||||||
dstream<<"Stack is over 30:"<<std::endl;
|
dstream << "Stack is over 30:" << std::endl;
|
||||||
stackDump(dstream);
|
stackDump(dstream);
|
||||||
std::string traceback = script_get_backtrace(m_luastack);
|
std::string traceback = script_get_backtrace(m_luastack);
|
||||||
throw LuaError("Stack is over 30 (reality check)\n" + traceback);
|
throw LuaError("Stack is over 30 (reality check)\n" + traceback);
|
||||||
|
@ -172,34 +172,29 @@ void ScriptApiBase::scriptError()
|
||||||
|
|
||||||
void ScriptApiBase::stackDump(std::ostream &o)
|
void ScriptApiBase::stackDump(std::ostream &o)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
int top = lua_gettop(m_luastack);
|
int top = lua_gettop(m_luastack);
|
||||||
for (i = 1; i <= top; i++) { /* repeat for each level */
|
for (int i = 1; i <= top; i++) { /* repeat for each level */
|
||||||
int t = lua_type(m_luastack, i);
|
int t = lua_type(m_luastack, i);
|
||||||
switch (t) {
|
switch (t) {
|
||||||
|
|
||||||
case LUA_TSTRING: /* strings */
|
case LUA_TSTRING: /* strings */
|
||||||
o<<"\""<<lua_tostring(m_luastack, i)<<"\"";
|
o << "\"" << lua_tostring(m_luastack, i) << "\"";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LUA_TBOOLEAN: /* booleans */
|
case LUA_TBOOLEAN: /* booleans */
|
||||||
o<<(lua_toboolean(m_luastack, i) ? "true" : "false");
|
o << (lua_toboolean(m_luastack, i) ? "true" : "false");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LUA_TNUMBER: /* numbers */ {
|
case LUA_TNUMBER: /* numbers */ {
|
||||||
char buf[10];
|
char buf[10];
|
||||||
snprintf(buf, 10, "%g", lua_tonumber(m_luastack, i));
|
snprintf(buf, 10, "%g", lua_tonumber(m_luastack, i));
|
||||||
o<<buf;
|
o << buf;
|
||||||
break; }
|
break;
|
||||||
|
}
|
||||||
default: /* other values */
|
default: /* other values */
|
||||||
o<<lua_typename(m_luastack, t);
|
o << lua_typename(m_luastack, t);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
o<<" ";
|
o << " ";
|
||||||
}
|
}
|
||||||
o<<std::endl;
|
o << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptApiBase::addObjectReference(ServerActiveObject *cobj)
|
void ScriptApiBase::addObjectReference(ServerActiveObject *cobj)
|
||||||
|
@ -251,7 +246,7 @@ void ScriptApiBase::removeObjectReference(ServerActiveObject *cobj)
|
||||||
void ScriptApiBase::objectrefGetOrCreate(lua_State *L,
|
void ScriptApiBase::objectrefGetOrCreate(lua_State *L,
|
||||||
ServerActiveObject *cobj)
|
ServerActiveObject *cobj)
|
||||||
{
|
{
|
||||||
if(cobj == NULL || cobj->getId() == 0){
|
if (cobj == NULL || cobj->getId() == 0) {
|
||||||
ObjectRef::create(L, cobj);
|
ObjectRef::create(L, cobj);
|
||||||
} else {
|
} else {
|
||||||
objectrefGet(L, cobj->getId());
|
objectrefGet(L, cobj->getId());
|
||||||
|
|
|
@ -51,7 +51,8 @@ public:
|
||||||
ScriptApiBase();
|
ScriptApiBase();
|
||||||
virtual ~ScriptApiBase();
|
virtual ~ScriptApiBase();
|
||||||
|
|
||||||
bool loadMod(const std::string &script_path, const std::string &mod_name, std::string *error=NULL);
|
bool loadMod(const std::string &script_path, const std::string &mod_name,
|
||||||
|
std::string *error=NULL);
|
||||||
bool loadScript(const std::string &script_path, std::string *error=NULL);
|
bool loadScript(const std::string &script_path, std::string *error=NULL);
|
||||||
|
|
||||||
/* object */
|
/* object */
|
||||||
|
|
143
src/server.cpp
143
src/server.cpp
|
@ -2838,7 +2838,7 @@ std::string Server::getBanDescription(const std::string &ip_or_name)
|
||||||
void Server::notifyPlayer(const char *name, const std::wstring &msg)
|
void Server::notifyPlayer(const char *name, const std::wstring &msg)
|
||||||
{
|
{
|
||||||
Player *player = m_env->getPlayer(name);
|
Player *player = m_env->getPlayer(name);
|
||||||
if(!player)
|
if (!player)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (player->peer_id == PEER_ID_INEXISTENT)
|
if (player->peer_id == PEER_ID_INEXISTENT)
|
||||||
|
@ -2847,21 +2847,19 @@ void Server::notifyPlayer(const char *name, const std::wstring &msg)
|
||||||
SendChatMessage(player->peer_id, msg);
|
SendChatMessage(player->peer_id, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Server::showFormspec(const char *playername, const std::string &formspec, const std::string &formname)
|
bool Server::showFormspec(const char *playername, const std::string &formspec,
|
||||||
|
const std::string &formname)
|
||||||
{
|
{
|
||||||
Player *player = m_env->getPlayer(playername);
|
Player *player = m_env->getPlayer(playername);
|
||||||
|
if (!player)
|
||||||
if(!player)
|
|
||||||
{
|
|
||||||
infostream<<"showFormspec: couldn't find player:"<<playername<<std::endl;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
SendShowFormspecMessage(player->peer_id, formspec, formname);
|
SendShowFormspecMessage(player->peer_id, formspec, formname);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 Server::hudAdd(Player *player, HudElement *form) {
|
u32 Server::hudAdd(Player *player, HudElement *form)
|
||||||
|
{
|
||||||
if (!player)
|
if (!player)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -2887,7 +2885,8 @@ bool Server::hudRemove(Player *player, u32 id) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Server::hudChange(Player *player, u32 id, HudElementStat stat, void *data) {
|
bool Server::hudChange(Player *player, u32 id, HudElementStat stat, void *data)
|
||||||
|
{
|
||||||
if (!player)
|
if (!player)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -2895,7 +2894,8 @@ bool Server::hudChange(Player *player, u32 id, HudElementStat stat, void *data)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Server::hudSetFlags(Player *player, u32 flags, u32 mask) {
|
bool Server::hudSetFlags(Player *player, u32 flags, u32 mask)
|
||||||
|
{
|
||||||
if (!player)
|
if (!player)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -2911,7 +2911,8 @@ bool Server::hudSetFlags(Player *player, u32 flags, u32 mask) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Server::hudSetHotbarItemcount(Player *player, s32 hotbar_itemcount) {
|
bool Server::hudSetHotbarItemcount(Player *player, s32 hotbar_itemcount)
|
||||||
|
{
|
||||||
if (!player)
|
if (!player)
|
||||||
return false;
|
return false;
|
||||||
if (hotbar_itemcount <= 0 || hotbar_itemcount > HUD_HOTBAR_ITEMCOUNT_MAX)
|
if (hotbar_itemcount <= 0 || hotbar_itemcount > HUD_HOTBAR_ITEMCOUNT_MAX)
|
||||||
|
@ -2924,13 +2925,15 @@ bool Server::hudSetHotbarItemcount(Player *player, s32 hotbar_itemcount) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 Server::hudGetHotbarItemcount(Player *player) {
|
s32 Server::hudGetHotbarItemcount(Player *player)
|
||||||
|
{
|
||||||
if (!player)
|
if (!player)
|
||||||
return 0;
|
return 0;
|
||||||
return player->getHotbarItemcount();
|
return player->getHotbarItemcount();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::hudSetHotbarImage(Player *player, std::string name) {
|
void Server::hudSetHotbarImage(Player *player, std::string name)
|
||||||
|
{
|
||||||
if (!player)
|
if (!player)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -2938,13 +2941,15 @@ void Server::hudSetHotbarImage(Player *player, std::string name) {
|
||||||
SendHUDSetParam(player->peer_id, HUD_PARAM_HOTBAR_IMAGE, name);
|
SendHUDSetParam(player->peer_id, HUD_PARAM_HOTBAR_IMAGE, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Server::hudGetHotbarImage(Player *player) {
|
std::string Server::hudGetHotbarImage(Player *player)
|
||||||
|
{
|
||||||
if (!player)
|
if (!player)
|
||||||
return "";
|
return "";
|
||||||
return player->getHotbarImage();
|
return player->getHotbarImage();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::hudSetHotbarSelectedImage(Player *player, std::string name) {
|
void Server::hudSetHotbarSelectedImage(Player *player, std::string name)
|
||||||
|
{
|
||||||
if (!player)
|
if (!player)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -2952,14 +2957,16 @@ void Server::hudSetHotbarSelectedImage(Player *player, std::string name) {
|
||||||
SendHUDSetParam(player->peer_id, HUD_PARAM_HOTBAR_SELECTED_IMAGE, name);
|
SendHUDSetParam(player->peer_id, HUD_PARAM_HOTBAR_SELECTED_IMAGE, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Server::hudGetHotbarSelectedImage(Player *player) {
|
std::string Server::hudGetHotbarSelectedImage(Player *player)
|
||||||
|
{
|
||||||
if (!player)
|
if (!player)
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
return player->getHotbarSelectedImage();
|
return player->getHotbarSelectedImage();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Server::setLocalPlayerAnimations(Player *player, v2s32 animation_frames[4], f32 frame_speed)
|
bool Server::setLocalPlayerAnimations(Player *player,
|
||||||
|
v2s32 animation_frames[4], f32 frame_speed)
|
||||||
{
|
{
|
||||||
if (!player)
|
if (!player)
|
||||||
return false;
|
return false;
|
||||||
|
@ -2981,7 +2988,7 @@ bool Server::setPlayerEyeOffset(Player *player, v3f first, v3f third)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Server::setSky(Player *player, const video::SColor &bgcolor,
|
bool Server::setSky(Player *player, const video::SColor &bgcolor,
|
||||||
const std::string &type, const std::vector<std::string> ¶ms)
|
const std::string &type, const std::vector<std::string> ¶ms)
|
||||||
{
|
{
|
||||||
if (!player)
|
if (!player)
|
||||||
return false;
|
return false;
|
||||||
|
@ -2992,7 +2999,7 @@ bool Server::setSky(Player *player, const video::SColor &bgcolor,
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Server::overrideDayNightRatio(Player *player, bool do_override,
|
bool Server::overrideDayNightRatio(Player *player, bool do_override,
|
||||||
float ratio)
|
float ratio)
|
||||||
{
|
{
|
||||||
if (!player)
|
if (!player)
|
||||||
return false;
|
return false;
|
||||||
|
@ -3008,9 +3015,9 @@ void Server::notifyPlayers(const std::wstring &msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::spawnParticle(const char *playername, v3f pos,
|
void Server::spawnParticle(const char *playername, v3f pos,
|
||||||
v3f velocity, v3f acceleration,
|
v3f velocity, v3f acceleration,
|
||||||
float expirationtime, float size, bool
|
float expirationtime, float size, bool
|
||||||
collisiondetection, bool vertical, std::string texture)
|
collisiondetection, bool vertical, const std::string &texture)
|
||||||
{
|
{
|
||||||
Player *player = m_env->getPlayer(playername);
|
Player *player = m_env->getPlayer(playername);
|
||||||
if(!player)
|
if(!player)
|
||||||
|
@ -3020,21 +3027,17 @@ void Server::spawnParticle(const char *playername, v3f pos,
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::spawnParticleAll(v3f pos, v3f velocity, v3f acceleration,
|
void Server::spawnParticleAll(v3f pos, v3f velocity, v3f acceleration,
|
||||||
float expirationtime, float size,
|
float expirationtime, float size,
|
||||||
bool collisiondetection, bool vertical, std::string texture)
|
bool collisiondetection, bool vertical, const std::string &texture)
|
||||||
{
|
{
|
||||||
SendSpawnParticle(PEER_ID_INEXISTENT,pos, velocity, acceleration,
|
SendSpawnParticle(PEER_ID_INEXISTENT,pos, velocity, acceleration,
|
||||||
expirationtime, size, collisiondetection, vertical, texture);
|
expirationtime, size, collisiondetection, vertical, texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 Server::addParticleSpawner(const char *playername,
|
u32 Server::addParticleSpawner(const char *playername, u16 amount, float spawntime,
|
||||||
u16 amount, float spawntime,
|
v3f minpos, v3f maxpos, v3f minvel, v3f maxvel, v3f minacc, v3f maxacc,
|
||||||
v3f minpos, v3f maxpos,
|
float minexptime, float maxexptime, float minsize, float maxsize,
|
||||||
v3f minvel, v3f maxvel,
|
bool collisiondetection, bool vertical, const std::string &texture)
|
||||||
v3f minacc, v3f maxacc,
|
|
||||||
float minexptime, float maxexptime,
|
|
||||||
float minsize, float maxsize,
|
|
||||||
bool collisiondetection, bool vertical, std::string texture)
|
|
||||||
{
|
{
|
||||||
Player *player = m_env->getPlayer(playername);
|
Player *player = m_env->getPlayer(playername);
|
||||||
if(!player)
|
if(!player)
|
||||||
|
@ -3062,12 +3065,12 @@ u32 Server::addParticleSpawner(const char *playername,
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 Server::addParticleSpawnerAll(u16 amount, float spawntime,
|
u32 Server::addParticleSpawnerAll(u16 amount, float spawntime,
|
||||||
v3f minpos, v3f maxpos,
|
v3f minpos, v3f maxpos,
|
||||||
v3f minvel, v3f maxvel,
|
v3f minvel, v3f maxvel,
|
||||||
v3f minacc, v3f maxacc,
|
v3f minacc, v3f maxacc,
|
||||||
float minexptime, float maxexptime,
|
float minexptime, float maxexptime,
|
||||||
float minsize, float maxsize,
|
float minsize, float maxsize,
|
||||||
bool collisiondetection, bool vertical, std::string texture)
|
bool collisiondetection, bool vertical, const std::string &texture)
|
||||||
{
|
{
|
||||||
u32 id = 0;
|
u32 id = 0;
|
||||||
for(;;) // look for unused particlespawner id
|
for(;;) // look for unused particlespawner id
|
||||||
|
@ -3128,24 +3131,6 @@ Inventory* Server::createDetachedInventory(const std::string &name)
|
||||||
return inv;
|
return inv;
|
||||||
}
|
}
|
||||||
|
|
||||||
class BoolScopeSet
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
BoolScopeSet(bool *dst, bool val):
|
|
||||||
m_dst(dst)
|
|
||||||
{
|
|
||||||
m_orig_state = *m_dst;
|
|
||||||
*m_dst = val;
|
|
||||||
}
|
|
||||||
~BoolScopeSet()
|
|
||||||
{
|
|
||||||
*m_dst = m_orig_state;
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
bool *m_dst;
|
|
||||||
bool m_orig_state;
|
|
||||||
};
|
|
||||||
|
|
||||||
// actions: time-reversed list
|
// actions: time-reversed list
|
||||||
// Return value: success/failure
|
// Return value: success/failure
|
||||||
bool Server::rollbackRevertActions(const std::list<RollbackAction> &actions,
|
bool Server::rollbackRevertActions(const std::list<RollbackAction> &actions,
|
||||||
|
@ -3195,27 +3180,29 @@ bool Server::rollbackRevertActions(const std::list<RollbackAction> &actions,
|
||||||
|
|
||||||
// IGameDef interface
|
// IGameDef interface
|
||||||
// Under envlock
|
// Under envlock
|
||||||
IItemDefManager* Server::getItemDefManager()
|
IItemDefManager *Server::getItemDefManager()
|
||||||
{
|
{
|
||||||
return m_itemdef;
|
return m_itemdef;
|
||||||
}
|
}
|
||||||
INodeDefManager* Server::getNodeDefManager()
|
|
||||||
|
INodeDefManager *Server::getNodeDefManager()
|
||||||
{
|
{
|
||||||
return m_nodedef;
|
return m_nodedef;
|
||||||
}
|
}
|
||||||
ICraftDefManager* Server::getCraftDefManager()
|
|
||||||
|
ICraftDefManager *Server::getCraftDefManager()
|
||||||
{
|
{
|
||||||
return m_craftdef;
|
return m_craftdef;
|
||||||
}
|
}
|
||||||
ITextureSource* Server::getTextureSource()
|
ITextureSource *Server::getTextureSource()
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
IShaderSource* Server::getShaderSource()
|
IShaderSource *Server::getShaderSource()
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
scene::ISceneManager* Server::getSceneManager()
|
scene::ISceneManager *Server::getSceneManager()
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -3224,44 +3211,50 @@ u16 Server::allocateUnknownNodeId(const std::string &name)
|
||||||
{
|
{
|
||||||
return m_nodedef->allocateDummy(name);
|
return m_nodedef->allocateDummy(name);
|
||||||
}
|
}
|
||||||
ISoundManager* Server::getSoundManager()
|
|
||||||
|
ISoundManager *Server::getSoundManager()
|
||||||
{
|
{
|
||||||
return &dummySoundManager;
|
return &dummySoundManager;
|
||||||
}
|
}
|
||||||
MtEventManager* Server::getEventManager()
|
|
||||||
|
MtEventManager *Server::getEventManager()
|
||||||
{
|
{
|
||||||
return m_event;
|
return m_event;
|
||||||
}
|
}
|
||||||
|
|
||||||
IWritableItemDefManager* Server::getWritableItemDefManager()
|
IWritableItemDefManager *Server::getWritableItemDefManager()
|
||||||
{
|
{
|
||||||
return m_itemdef;
|
return m_itemdef;
|
||||||
}
|
}
|
||||||
IWritableNodeDefManager* Server::getWritableNodeDefManager()
|
|
||||||
|
IWritableNodeDefManager *Server::getWritableNodeDefManager()
|
||||||
{
|
{
|
||||||
return m_nodedef;
|
return m_nodedef;
|
||||||
}
|
}
|
||||||
IWritableCraftDefManager* Server::getWritableCraftDefManager()
|
|
||||||
|
IWritableCraftDefManager *Server::getWritableCraftDefManager()
|
||||||
{
|
{
|
||||||
return m_craftdef;
|
return m_craftdef;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ModSpec* Server::getModSpec(const std::string &modname) const
|
const ModSpec *Server::getModSpec(const std::string &modname) const
|
||||||
{
|
{
|
||||||
for(std::vector<ModSpec>::const_iterator i = m_mods.begin();
|
std::vector<ModSpec>::const_iterator it;
|
||||||
i != m_mods.end(); i++){
|
for (it = m_mods.begin(); it != m_mods.end(); ++it) {
|
||||||
const ModSpec &mod = *i;
|
const ModSpec &mod = *it;
|
||||||
if(mod.name == modname)
|
if (mod.name == modname)
|
||||||
return &mod;
|
return &mod;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::getModNames(std::vector<std::string> &modlist)
|
void Server::getModNames(std::vector<std::string> &modlist)
|
||||||
{
|
{
|
||||||
for(std::vector<ModSpec>::iterator i = m_mods.begin(); i != m_mods.end(); i++) {
|
std::vector<ModSpec>::iterator it;
|
||||||
modlist.push_back(i->name);
|
for (it = m_mods.begin(); it != m_mods.end(); ++it)
|
||||||
}
|
modlist.push_back(it->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Server::getBuiltinLuaPath()
|
std::string Server::getBuiltinLuaPath()
|
||||||
{
|
{
|
||||||
return porting::path_share + DIR_DELIM + "builtin";
|
return porting::path_share + DIR_DELIM + "builtin";
|
||||||
|
|
|
@ -267,11 +267,11 @@ public:
|
||||||
void spawnParticle(const char *playername,
|
void spawnParticle(const char *playername,
|
||||||
v3f pos, v3f velocity, v3f acceleration,
|
v3f pos, v3f velocity, v3f acceleration,
|
||||||
float expirationtime, float size,
|
float expirationtime, float size,
|
||||||
bool collisiondetection, bool vertical, std::string texture);
|
bool collisiondetection, bool vertical, const std::string &texture);
|
||||||
|
|
||||||
void spawnParticleAll(v3f pos, v3f velocity, v3f acceleration,
|
void spawnParticleAll(v3f pos, v3f velocity, v3f acceleration,
|
||||||
float expirationtime, float size,
|
float expirationtime, float size,
|
||||||
bool collisiondetection, bool vertical, std::string texture);
|
bool collisiondetection, bool vertical, const std::string &texture);
|
||||||
|
|
||||||
u32 addParticleSpawner(const char *playername,
|
u32 addParticleSpawner(const char *playername,
|
||||||
u16 amount, float spawntime,
|
u16 amount, float spawntime,
|
||||||
|
@ -280,7 +280,7 @@ public:
|
||||||
v3f minacc, v3f maxacc,
|
v3f minacc, v3f maxacc,
|
||||||
float minexptime, float maxexptime,
|
float minexptime, float maxexptime,
|
||||||
float minsize, float maxsize,
|
float minsize, float maxsize,
|
||||||
bool collisiondetection, bool vertical, std::string texture);
|
bool collisiondetection, bool vertical, const std::string &texture);
|
||||||
|
|
||||||
u32 addParticleSpawnerAll(u16 amount, float spawntime,
|
u32 addParticleSpawnerAll(u16 amount, float spawntime,
|
||||||
v3f minpos, v3f maxpos,
|
v3f minpos, v3f maxpos,
|
||||||
|
@ -288,7 +288,7 @@ public:
|
||||||
v3f minacc, v3f maxacc,
|
v3f minacc, v3f maxacc,
|
||||||
float minexptime, float maxexptime,
|
float minexptime, float maxexptime,
|
||||||
float minsize, float maxsize,
|
float minsize, float maxsize,
|
||||||
bool collisiondetection, bool vertical, std::string texture);
|
bool collisiondetection, bool vertical, const std::string &texture);
|
||||||
|
|
||||||
void deleteParticleSpawner(const char *playername, u32 id);
|
void deleteParticleSpawner(const char *playername, u32 id);
|
||||||
void deleteParticleSpawnerAll(u32 id);
|
void deleteParticleSpawnerAll(u32 id);
|
||||||
|
|
Loading…
Reference in New Issue