Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix code style from recent commits and add misc. optimizations
  • Loading branch information
kwolekr committed Jul 3, 2015
1 parent 0a0378f commit 7b171ea
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 184 deletions.
71 changes: 48 additions & 23 deletions src/player.h
Expand Up @@ -130,13 +130,8 @@ class Player

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()
Expand Down Expand Up @@ -197,12 +192,13 @@ class Player
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;
}

Expand All @@ -215,62 +211,91 @@ class Player
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
Expand Down
24 changes: 11 additions & 13 deletions src/porting.cpp
Expand Up @@ -749,25 +749,23 @@ const char *getVideoDriverFriendlyName(irr::video::E_DRIVER_TYPE type)

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;
Expand Down
14 changes: 6 additions & 8 deletions src/script/common/c_content.cpp
Expand Up @@ -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());
}
Expand All @@ -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);
}
}

Expand Down
73 changes: 33 additions & 40 deletions src/script/common/c_content.h
Expand Up @@ -62,61 +62,56 @@ struct NoiseParams;
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 &params);
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);
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_);
Expand All @@ -129,8 +124,9 @@ 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);

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);
Expand All @@ -146,24 +142,21 @@ void read_soundspec (lua_State *L,
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[];

Expand Down
2 changes: 0 additions & 2 deletions src/script/common/c_converter.h
Expand Up @@ -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,
Expand Down

0 comments on commit 7b171ea

Please sign in to comment.