v3f getEyeOffset()
{
- // This is at the height of the eyes of the current figure
- // return v3f(0, BS*1.5, 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);
+ float eye_height = camera_barely_in_ceiling ? 1.5f : 1.625f;
+ return v3f(0, BS * eye_height, 0);
}
v3f getEyePosition()
return (m_yaw + 90.) * core::DEGTORAD;
}
- const char * getName() const
+ const char *getName() const
{
return m_name;
}
- core::aabbox3d<f32> getCollisionbox() {
+ core::aabbox3d<f32> getCollisionbox()
+ {
return m_collisionbox;
}
return size;
}
- void setHotbarItemcount(s32 hotbar_itemcount) {
+ void setHotbarItemcount(s32 hotbar_itemcount)
+ {
hud_hotbar_itemcount = hotbar_itemcount;
}
- s32 getHotbarItemcount() {
+
+ s32 getHotbarItemcount()
+ {
return hud_hotbar_itemcount;
}
- void setHotbarImage(std::string name) {
+
+ void setHotbarImage(const std::string &name)
+ {
hud_hotbar_image = name;
}
- std::string getHotbarImage() {
+
+ std::string getHotbarImage()
+ {
return hud_hotbar_image;
}
- void setHotbarSelectedImage(std::string name) {
+
+ void setHotbarSelectedImage(const std::string &name)
+ {
hud_hotbar_selected_image = name;
}
+
std::string getHotbarSelectedImage() {
return hud_hotbar_selected_image;
}
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_type = type;
m_sky_params = params;
}
+
void getSky(video::SColor *bgcolor, std::string *type,
- std::vector<std::string> *params) {
+ std::vector<std::string> *params)
+ {
*bgcolor = m_sky_bgcolor;
*type = m_sky_type;
*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 = ratio;
}
- void getDayNightRatio(bool *do_override, float *ratio) {
+
+ void getDayNightRatio(bool *do_override, float *ratio)
+ {
*do_override = m_day_night_ratio_do_override;
*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++)
local_animations[i] = frames[i];
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++)
frames[i] = local_animations[i];
*frame_speed = local_animation_speed;
}
virtual bool isLocal() const
- { return false; }
+ {
+ return false;
+ }
+
virtual PlayerSAO *getPlayerSAO()
- { return NULL; }
+ {
+ return NULL;
+ }
+
virtual void setPlayerSAO(PlayerSAO *sao)
- { FATAL_ERROR("FIXME"); }
+ {
+ FATAL_ERROR("FIXME");
+ }
/*
serialize() writes a bunch of text that can contain
static float calcDisplayDensity()
{
- const char* current_display = getenv("DISPLAY");
+ const char *current_display = getenv("DISPLAY");
if (current_display != NULL) {
- Display * x11display = XOpenDisplay(current_display);
+ Display *x11display = XOpenDisplay(current_display);
- if (x11display != NULL) {
- /* try x direct */
- float dpi_height =
- floor(DisplayHeight(x11display, 0) /
- (DisplayHeightMM(x11display, 0) * 0.039370) + 0.5);
- float dpi_width =
- floor(DisplayWidth(x11display, 0) /
- (DisplayWidthMM(x11display, 0) * 0.039370) +0.5);
+ if (x11display != NULL) {
+ /* try x direct */
+ float dpi_height = floor(DisplayHeight(x11display, 0) /
+ (DisplayHeightMM(x11display, 0) * 0.039370) + 0.5);
+ float dpi_width = 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 g_settings->getFloat("screen_dpi")/96.0;
}
/******************************************************************************/
-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);
- for (std::map<std::string, int>::iterator it = groups.begin();
- it != groups.end(); ++it) {
+ std::map<std::string, int>::const_iterator it;
+ for (it = groups.begin(); it != groups.end(); ++it) {
lua_pushnumber(L, it->second);
lua_setfield(L, -2, it->first.c_str());
}
/******************************************************************************/
void push_items(lua_State *L, const std::vector<ItemStack> &items)
{
- // Create and fill table
lua_createtable(L, items.size(), 0);
- std::vector<ItemStack>::const_iterator iter = items.begin();
- for (u32 i = 0; iter != items.end(); iter++) {
- LuaItemStack::create(L, *iter);
- lua_rawseti(L, -2, ++i);
+ for (u32 i = 0; i != items.size(); i++) {
+ LuaItemStack::create(L, items[i]);
+ lua_rawseti(L, -2, i + 1);
}
}
class Schematic;
-ContentFeatures read_content_features (lua_State *L, int index);
-TileDef read_tiledef (lua_State *L, int index);
-void read_soundspec (lua_State *L, int index,
- SimpleSoundSpec &spec);
-NodeBox read_nodebox (lua_State *L, int index);
+ContentFeatures read_content_features (lua_State *L, int index);
+TileDef read_tiledef (lua_State *L, int index);
+void read_soundspec (lua_State *L, int index,
+ SimpleSoundSpec &spec);
+NodeBox read_nodebox (lua_State *L, int index);
-void read_server_sound_params (lua_State *L, int index,
- ServerSoundParams ¶ms);
+void read_server_sound_params (lua_State *L, int index,
+ ServerSoundParams ¶ms);
-void push_dig_params (lua_State *L,const DigParams ¶ms);
-void push_hit_params (lua_State *L,const HitParams ¶ms);
+void push_dig_params (lua_State *L,
+ 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,
- int table);
+ToolCapabilities read_tool_capabilities (lua_State *L, int table);
void push_tool_capabilities (lua_State *L,
const ToolCapabilities &prop);
-ItemDefinition read_item_definition (lua_State *L,
- int index,
+ItemDefinition read_item_definition (lua_State *L, int index,
ItemDefinition default_def);
-void read_object_properties (lua_State *L,
- int index,
+void read_object_properties (lua_State *L, int index,
+ ObjectProperties *prop);
+void push_object_properties (lua_State *L,
ObjectProperties *prop);
-void push_object_properties (lua_State *L,
- ObjectProperties *prop);
void push_inventory_list (lua_State *L,
Inventory *inv,
const char *name);
-void read_inventory_list (lua_State *L,
- int tableindex,
- Inventory *inv,
- const char *name,
- Server* srv,
- int forcesize=-1);
+void read_inventory_list (lua_State *L, int tableindex,
+ Inventory *inv, const char *name,
+ Server *srv, int forcesize=-1);
-MapNode readnode (lua_State *L,
- int index,
+MapNode readnode (lua_State *L, int index,
INodeDefManager *ndef);
-void pushnode (lua_State *L,
- const MapNode &n,
+void pushnode (lua_State *L, const MapNode &n,
INodeDefManager *ndef);
NodeBox read_nodebox (lua_State *L, int index);
-void read_groups (lua_State *L,
- int index,
+void read_groups (lua_State *L, int index,
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"
-int getenumfield (lua_State *L,
- int table,
+int getenumfield (lua_State *L, int table,
const char *fieldname,
const EnumString *spec,
int default_);
bool read_flags (lua_State *L, int index,
FlagDesc *flagdesc,
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,
FlagDesc *flagdesc, u32 *flagmask);
int index,
SimpleSoundSpec &spec);
-
bool string_to_enum (const EnumString *spec,
int &result,
const std::string &str);
bool read_noiseparams (lua_State *L, int index,
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);
bool push_json_value (lua_State *L,
const Json::Value &value,
int nullindex);
-void read_json_value (lua_State *L,
- Json::Value &root,
- int index,
- u8 recursion = 0);
+void read_json_value (lua_State *L, Json::Value &root,
+ int index, u8 recursion = 0);
extern struct EnumString es_TileAnimationType[];
void pushFloatPos (lua_State *L, v3f p);
void push_v3f (lua_State *L, v3f 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,
const char *fieldname,
if (!ok) {
std::string error_msg = lua_tostring(L, -1);
if (error)
- (*error) = error_msg;
+ *error = error_msg;
errorstream << "========== ERROR FROM LUA ===========" << std::endl
<< "Failed to load and run script from " << std::endl
<< script_path << ":" << std::endl << std::endl
void ScriptApiBase::realityCheck()
{
int top = lua_gettop(m_luastack);
- if(top >= 30){
- dstream<<"Stack is over 30:"<<std::endl;
+ if (top >= 30) {
+ dstream << "Stack is over 30:" << std::endl;
stackDump(dstream);
std::string traceback = script_get_backtrace(m_luastack);
throw LuaError("Stack is over 30 (reality check)\n" + traceback);
void ScriptApiBase::stackDump(std::ostream &o)
{
- int i;
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);
switch (t) {
-
case LUA_TSTRING: /* strings */
- o<<"\""<<lua_tostring(m_luastack, i)<<"\"";
+ o << "\"" << lua_tostring(m_luastack, i) << "\"";
break;
-
case LUA_TBOOLEAN: /* booleans */
- o<<(lua_toboolean(m_luastack, i) ? "true" : "false");
+ o << (lua_toboolean(m_luastack, i) ? "true" : "false");
break;
-
case LUA_TNUMBER: /* numbers */ {
char buf[10];
snprintf(buf, 10, "%g", lua_tonumber(m_luastack, i));
- o<<buf;
- break; }
-
+ o << buf;
+ break;
+ }
default: /* other values */
- o<<lua_typename(m_luastack, t);
+ o << lua_typename(m_luastack, t);
break;
-
}
- o<<" ";
+ o << " ";
}
- o<<std::endl;
+ o << std::endl;
}
void ScriptApiBase::addObjectReference(ServerActiveObject *cobj)
void ScriptApiBase::objectrefGetOrCreate(lua_State *L,
ServerActiveObject *cobj)
{
- if(cobj == NULL || cobj->getId() == 0){
+ if (cobj == NULL || cobj->getId() == 0) {
ObjectRef::create(L, cobj);
} else {
objectrefGet(L, cobj->getId());
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);
/* object */
void Server::notifyPlayer(const char *name, const std::wstring &msg)
{
Player *player = m_env->getPlayer(name);
- if(!player)
+ if (!player)
return;
if (player->peer_id == PEER_ID_INEXISTENT)
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);
-
- if(!player)
- {
- infostream<<"showFormspec: couldn't find player:"<<playername<<std::endl;
+ if (!player)
return false;
- }
SendShowFormspecMessage(player->peer_id, formspec, formname);
return true;
}
-u32 Server::hudAdd(Player *player, HudElement *form) {
+u32 Server::hudAdd(Player *player, HudElement *form)
+{
if (!player)
return -1;
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)
return false;
return true;
}
-bool Server::hudSetFlags(Player *player, u32 flags, u32 mask) {
+bool Server::hudSetFlags(Player *player, u32 flags, u32 mask)
+{
if (!player)
return false;
return true;
}
-bool Server::hudSetHotbarItemcount(Player *player, s32 hotbar_itemcount) {
+bool Server::hudSetHotbarItemcount(Player *player, s32 hotbar_itemcount)
+{
if (!player)
return false;
if (hotbar_itemcount <= 0 || hotbar_itemcount > HUD_HOTBAR_ITEMCOUNT_MAX)
return true;
}
-s32 Server::hudGetHotbarItemcount(Player *player) {
+s32 Server::hudGetHotbarItemcount(Player *player)
+{
if (!player)
return 0;
return player->getHotbarItemcount();
}
-void Server::hudSetHotbarImage(Player *player, std::string name) {
+void Server::hudSetHotbarImage(Player *player, std::string name)
+{
if (!player)
return;
SendHUDSetParam(player->peer_id, HUD_PARAM_HOTBAR_IMAGE, name);
}
-std::string Server::hudGetHotbarImage(Player *player) {
+std::string Server::hudGetHotbarImage(Player *player)
+{
if (!player)
return "";
return player->getHotbarImage();
}
-void Server::hudSetHotbarSelectedImage(Player *player, std::string name) {
+void Server::hudSetHotbarSelectedImage(Player *player, std::string name)
+{
if (!player)
return;
SendHUDSetParam(player->peer_id, HUD_PARAM_HOTBAR_SELECTED_IMAGE, name);
}
-std::string Server::hudGetHotbarSelectedImage(Player *player) {
+std::string Server::hudGetHotbarSelectedImage(Player *player)
+{
if (!player)
return "";
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)
return false;
}
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)
return false;
}
bool Server::overrideDayNightRatio(Player *player, bool do_override,
- float ratio)
+ float ratio)
{
if (!player)
return false;
}
void Server::spawnParticle(const char *playername, v3f pos,
- v3f velocity, v3f acceleration,
- float expirationtime, float size, bool
- collisiondetection, bool vertical, std::string texture)
+ v3f velocity, v3f acceleration,
+ float expirationtime, float size, bool
+ collisiondetection, bool vertical, const std::string &texture)
{
Player *player = m_env->getPlayer(playername);
if(!player)
}
void Server::spawnParticleAll(v3f pos, v3f velocity, v3f acceleration,
- float expirationtime, float size,
- bool collisiondetection, bool vertical, std::string texture)
+ float expirationtime, float size,
+ bool collisiondetection, bool vertical, const std::string &texture)
{
SendSpawnParticle(PEER_ID_INEXISTENT,pos, velocity, acceleration,
expirationtime, size, collisiondetection, vertical, texture);
}
-u32 Server::addParticleSpawner(const char *playername,
- u16 amount, float spawntime,
- v3f minpos, v3f maxpos,
- v3f minvel, v3f maxvel,
- v3f minacc, v3f maxacc,
- float minexptime, float maxexptime,
- float minsize, float maxsize,
- bool collisiondetection, bool vertical, std::string texture)
+u32 Server::addParticleSpawner(const char *playername, u16 amount, float spawntime,
+ v3f minpos, v3f maxpos, v3f minvel, v3f maxvel, v3f minacc, v3f maxacc,
+ float minexptime, float maxexptime, float minsize, float maxsize,
+ bool collisiondetection, bool vertical, const std::string &texture)
{
Player *player = m_env->getPlayer(playername);
if(!player)
}
u32 Server::addParticleSpawnerAll(u16 amount, float spawntime,
- v3f minpos, v3f maxpos,
- v3f minvel, v3f maxvel,
- v3f minacc, v3f maxacc,
- float minexptime, float maxexptime,
- float minsize, float maxsize,
- bool collisiondetection, bool vertical, std::string texture)
+ v3f minpos, v3f maxpos,
+ v3f minvel, v3f maxvel,
+ v3f minacc, v3f maxacc,
+ float minexptime, float maxexptime,
+ float minsize, float maxsize,
+ bool collisiondetection, bool vertical, const std::string &texture)
{
u32 id = 0;
for(;;) // look for unused particlespawner id
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
// Return value: success/failure
bool Server::rollbackRevertActions(const std::list<RollbackAction> &actions,
// IGameDef interface
// Under envlock
-IItemDefManager* Server::getItemDefManager()
+IItemDefManager *Server::getItemDefManager()
{
return m_itemdef;
}
-INodeDefManager* Server::getNodeDefManager()
+
+INodeDefManager *Server::getNodeDefManager()
{
return m_nodedef;
}
-ICraftDefManager* Server::getCraftDefManager()
+
+ICraftDefManager *Server::getCraftDefManager()
{
return m_craftdef;
}
-ITextureSource* Server::getTextureSource()
+ITextureSource *Server::getTextureSource()
{
return NULL;
}
-IShaderSource* Server::getShaderSource()
+IShaderSource *Server::getShaderSource()
{
return NULL;
}
-scene::ISceneManager* Server::getSceneManager()
+scene::ISceneManager *Server::getSceneManager()
{
return NULL;
}
{
return m_nodedef->allocateDummy(name);
}
-ISoundManager* Server::getSoundManager()
+
+ISoundManager *Server::getSoundManager()
{
return &dummySoundManager;
}
-MtEventManager* Server::getEventManager()
+
+MtEventManager *Server::getEventManager()
{
return m_event;
}
-IWritableItemDefManager* Server::getWritableItemDefManager()
+IWritableItemDefManager *Server::getWritableItemDefManager()
{
return m_itemdef;
}
-IWritableNodeDefManager* Server::getWritableNodeDefManager()
+
+IWritableNodeDefManager *Server::getWritableNodeDefManager()
{
return m_nodedef;
}
-IWritableCraftDefManager* Server::getWritableCraftDefManager()
+
+IWritableCraftDefManager *Server::getWritableCraftDefManager()
{
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();
- i != m_mods.end(); i++){
- const ModSpec &mod = *i;
- if(mod.name == modname)
+ std::vector<ModSpec>::const_iterator it;
+ for (it = m_mods.begin(); it != m_mods.end(); ++it) {
+ const ModSpec &mod = *it;
+ if (mod.name == modname)
return &mod;
}
return NULL;
}
+
void Server::getModNames(std::vector<std::string> &modlist)
{
- for(std::vector<ModSpec>::iterator i = m_mods.begin(); i != m_mods.end(); i++) {
- modlist.push_back(i->name);
- }
+ std::vector<ModSpec>::iterator it;
+ for (it = m_mods.begin(); it != m_mods.end(); ++it)
+ modlist.push_back(it->name);
}
+
std::string Server::getBuiltinLuaPath()
{
return porting::path_share + DIR_DELIM + "builtin";
void spawnParticle(const char *playername,
v3f pos, v3f velocity, v3f acceleration,
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,
float expirationtime, float size,
- bool collisiondetection, bool vertical, std::string texture);
+ bool collisiondetection, bool vertical, const std::string &texture);
u32 addParticleSpawner(const char *playername,
u16 amount, float spawntime,
v3f minacc, v3f maxacc,
float minexptime, float maxexptime,
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,
v3f minpos, v3f maxpos,
v3f minacc, v3f maxacc,
float minexptime, float maxexptime,
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 deleteParticleSpawnerAll(u32 id);