Fix code style from recent commits and add misc. optimizations

This commit is contained in:
kwolekr 2015-07-02 23:14:30 -04:00
parent 0a0378fece
commit 7b171ea2be
9 changed files with 186 additions and 185 deletions

@ -130,13 +130,8 @@ public:
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()
@ -202,7 +197,8 @@ public:
return m_name;
}
core::aabbox3d<f32> getCollisionbox() {
core::aabbox3d<f32> getCollisionbox()
{
return m_collisionbox;
}
@ -215,62 +211,91 @@ public:
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> &params) {
const std::vector<std::string> &params)
{
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

@ -756,11 +756,9 @@ static float calcDisplayDensity()
if (x11display != NULL) {
/* try x direct */
float dpi_height =
floor(DisplayHeight(x11display, 0) /
float dpi_height = floor(DisplayHeight(x11display, 0) /
(DisplayHeightMM(x11display, 0) * 0.039370) + 0.5);
float dpi_width =
floor(DisplayWidth(x11display, 0) /
float dpi_width = floor(DisplayWidth(x11display, 0) /
(DisplayWidthMM(x11display, 0) * 0.039370) + 0.5);
XCloseDisplay(x11display);

@ -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);
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());
}
@ -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)
{
// 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);
}
}

@ -71,22 +71,21 @@ NodeBox read_nodebox (lua_State *L, int index);
void read_server_sound_params (lua_State *L, int index,
ServerSoundParams &params);
void push_dig_params (lua_State *L,const DigParams &params);
void push_hit_params (lua_State *L,const HitParams &params);
void push_dig_params (lua_State *L,
const DigParams &params);
void push_hit_params (lua_State *L,
const HitParams &params);
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);
@ -94,29 +93,25 @@ void push_object_properties (lua_State *L,
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_);
@ -129,6 +124,7 @@ bool getflagsfield (lua_State *L, int table,
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);
@ -146,7 +142,6 @@ void read_soundspec (lua_State *L,
int index,
SimpleSoundSpec &spec);
bool string_to_enum (const EnumString *spec,
int &result,
const std::string &str);
@ -160,10 +155,8 @@ 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[];

@ -104,8 +104,6 @@ void push_ARGB8 (lua_State *L, video::SColor color);
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,

@ -142,7 +142,7 @@ bool ScriptApiBase::loadScript(const std::string &script_path, std::string *erro
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
@ -172,30 +172,25 @@ void ScriptApiBase::scriptError()
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) << "\"";
break;
case LUA_TBOOLEAN: /* booleans */
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; }
break;
}
default: /* other values */
o << lua_typename(m_luastack, t);
break;
}
o << " ";
}

@ -51,7 +51,8 @@ public:
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 */

@ -2847,21 +2847,19 @@ void Server::notifyPlayer(const char *name, const std::wstring &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);
if (!player)
{
infostream<<"showFormspec: couldn't find player:"<<playername<<std::endl;
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;
@ -2887,7 +2885,8 @@ bool Server::hudRemove(Player *player, u32 id) {
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;
@ -2895,7 +2894,8 @@ bool Server::hudChange(Player *player, u32 id, HudElementStat stat, void *data)
return true;
}
bool Server::hudSetFlags(Player *player, u32 flags, u32 mask) {
bool Server::hudSetFlags(Player *player, u32 flags, u32 mask)
{
if (!player)
return false;
@ -2911,7 +2911,8 @@ bool Server::hudSetFlags(Player *player, u32 flags, u32 mask) {
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)
@ -2924,13 +2925,15 @@ bool Server::hudSetHotbarItemcount(Player *player, s32 hotbar_itemcount) {
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;
@ -2938,13 +2941,15 @@ void Server::hudSetHotbarImage(Player *player, std::string name) {
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;
@ -2952,14 +2957,16 @@ void Server::hudSetHotbarSelectedImage(Player *player, std::string 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)
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;
@ -3010,7 +3017,7 @@ void Server::notifyPlayers(const std::wstring &msg)
void Server::spawnParticle(const char *playername, v3f pos,
v3f velocity, v3f acceleration,
float expirationtime, float size, bool
collisiondetection, bool vertical, std::string texture)
collisiondetection, bool vertical, const std::string &texture)
{
Player *player = m_env->getPlayer(playername);
if(!player)
@ -3021,20 +3028,16 @@ void Server::spawnParticle(const char *playername, v3f pos,
void Server::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)
{
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)
@ -3067,7 +3070,7 @@ u32 Server::addParticleSpawnerAll(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 id = 0;
for(;;) // look for unused particlespawner id
@ -3128,24 +3131,6 @@ Inventory* Server::createDetachedInventory(const std::string &name)
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,
@ -3199,10 +3184,12 @@ IItemDefManager* Server::getItemDefManager()
{
return m_itemdef;
}
INodeDefManager *Server::getNodeDefManager()
{
return m_nodedef;
}
ICraftDefManager *Server::getCraftDefManager()
{
return m_craftdef;
@ -3224,10 +3211,12 @@ u16 Server::allocateUnknownNodeId(const std::string &name)
{
return m_nodedef->allocateDummy(name);
}
ISoundManager *Server::getSoundManager()
{
return &dummySoundManager;
}
MtEventManager *Server::getEventManager()
{
return m_event;
@ -3237,10 +3226,12 @@ IWritableItemDefManager* Server::getWritableItemDefManager()
{
return m_itemdef;
}
IWritableNodeDefManager *Server::getWritableNodeDefManager()
{
return m_nodedef;
}
IWritableCraftDefManager *Server::getWritableCraftDefManager()
{
return m_craftdef;
@ -3248,20 +3239,22 @@ IWritableCraftDefManager* Server::getWritableCraftDefManager()
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;
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";

@ -267,11 +267,11 @@ public:
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,
@ -280,7 +280,7 @@ public:
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,
@ -288,7 +288,7 @@ public:
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);