205 changes: 101 additions & 104 deletions src/game.cpp

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/guiEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ bool GUIEngine::loadMainMenuScript()
}
else {
infostream
<< "GUIEngine: execution of custom menu failed!"
<< "GUIEngine: execution of custom menu: \""
<< menuscript << "\" failed!"
<< std::endl
<< "\tfalling back to builtin menu"
<< std::endl;
Expand Down Expand Up @@ -317,7 +318,7 @@ GUIEngine::~GUIEngine()
}

delete m_texture_source;

if (m_cloud.clouds)
m_cloud.clouds->drop();
}
Expand Down
245 changes: 151 additions & 94 deletions src/guiFormSpecMenu.cpp

Large diffs are not rendered by default.

19 changes: 14 additions & 5 deletions src/guiFormSpecMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class GUIFormSpecMenu : public GUIModalMenu
v2s32 geom;
bool scale;
};

struct FieldSpec
{
FieldSpec()
Expand Down Expand Up @@ -202,7 +202,7 @@ class GUIFormSpecMenu : public GUIModalMenu
m_current_inventory_location = current_inventory_location;
regenerateGui(m_screensize_old);
}

// form_src is deleted by this GUIFormSpecMenu
void setFormSource(IFormSource *form_src)
{
Expand Down Expand Up @@ -231,7 +231,7 @@ class GUIFormSpecMenu : public GUIModalMenu
Remove and re-add (or reposition) stuff
*/
void regenerateGui(v2u32 screensize);

ItemSpec getItemAtPos(v2s32 p) const;
void drawList(const ListDrawSpec &s, int phase);
void drawSelectedItem();
Expand Down Expand Up @@ -260,7 +260,7 @@ class GUIFormSpecMenu : public GUIModalMenu
v2s32 spacing;
v2s32 imgsize;
v2s32 offset;

irr::IrrlichtDevice* m_device;
InventoryManager *m_invmgr;
IGameDef *m_gamedef;
Expand All @@ -283,7 +283,7 @@ class GUIFormSpecMenu : public GUIModalMenu
ItemSpec *m_selected_item;
u32 m_selected_amount;
bool m_selected_dragging;

// WARNING: BLACK MAGIC
// Used to guess and keep up with some special things the server can do.
// If name is "", no guess exists.
Expand Down Expand Up @@ -355,6 +355,15 @@ class GUIFormSpecMenu : public GUIModalMenu
void parseBox(parserData* data,std::string element);
void parseBackgroundColor(parserData* data,std::string element);
void parseListColors(parserData* data,std::string element);


bool DoubleClickDetection(const SEvent event);

struct clickpos {
v2s32 pos;
s32 time;
};
clickpos m_doubleclickdetect[2];
};

class FormspecFormSource: public IFormSource
Expand Down
3 changes: 2 additions & 1 deletion src/httpfetch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ You should have received a copy of the GNU Lesser 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.
*/

#include "socket.h" // for select()
#include "porting.h" // for sleep_ms(), get_sysinfo()
#include "httpfetch.h"
Expand Down Expand Up @@ -566,6 +565,8 @@ class CurlFetchThread : public JThread
log_register_thread("CurlFetchThread");
DSTACK(__FUNCTION_NAME);

porting::setThreadName("CurlFetchThread");

CurlHandlePool pool;

m_multi = curl_multi_init();
Expand Down
31 changes: 16 additions & 15 deletions src/localplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void LocalPlayer::move(f32 dtime, ClientEnvironment *env, f32 pos_max_d,
/*
Collision detection
*/

/*
Check if player is in liquid (the oscillating value)
*/
Expand Down Expand Up @@ -173,7 +173,7 @@ void LocalPlayer::move(f32 dtime, ClientEnvironment *env, f32 pos_max_d,
v3f lwn_f = intToFloat(m_sneak_node, BS);
position.X = rangelim(position.X, lwn_f.X-maxd, lwn_f.X+maxd);
position.Z = rangelim(position.Z, lwn_f.Z-maxd, lwn_f.Z+maxd);

if(!is_climbing)
{
f32 min_y = lwn_f.Y + 0.5*BS;
Expand Down Expand Up @@ -203,7 +203,7 @@ void LocalPlayer::move(f32 dtime, ClientEnvironment *env, f32 pos_max_d,
*/
bool touching_ground_was = touching_ground;
touching_ground = result.touching_ground;

//bool standing_on_unloaded = result.standing_on_unloaded;

/*
Expand Down Expand Up @@ -254,7 +254,7 @@ void LocalPlayer::move(f32 dtime, ClientEnvironment *env, f32 pos_max_d,
f32 max_axis_distance_f = MYMAX(
fabs(player_p2df.X-node_p2df.X),
fabs(player_p2df.Y-node_p2df.Y));

if(distance_f > min_distance_f ||
max_axis_distance_f > 0.5*BS + sneak_max + 0.1*BS)
continue;
Expand All @@ -264,8 +264,9 @@ void LocalPlayer::move(f32 dtime, ClientEnvironment *env, f32 pos_max_d,
if(nodemgr->get(map->getNode(p)).walkable == false)
continue;
// And the node above it has to be nonwalkable
if(nodemgr->get(map->getNode(p+v3s16(0,1,0))).walkable == true)
if(nodemgr->get(map->getNode(p+v3s16(0,1,0))).walkable == true) {
continue;
}
if (!physics_override_sneak_glitch) {
if (nodemgr->get(map->getNode(p+v3s16(0,2,0))).walkable)
continue;
Expand All @@ -279,7 +280,7 @@ void LocalPlayer::move(f32 dtime, ClientEnvironment *env, f32 pos_max_d,
min_distance_f = distance_f;
new_sneak_node = p;
}

bool sneak_node_found = (min_distance_f < 100000.0*BS*0.9);

m_sneak_node = new_sneak_node;
Expand All @@ -292,12 +293,12 @@ void LocalPlayer::move(f32 dtime, ClientEnvironment *env, f32 pos_max_d,
if(sneak_node_found && control.sneak)
touching_ground = true;
}

/*
Set new position
*/
setPosition(position);

/*
Report collisions
*/
Expand Down Expand Up @@ -345,7 +346,7 @@ void LocalPlayer::move(f32 dtime, ClientEnvironment *env, f32 pos_max_d,
*/
m_old_node_below = floatToInt(position - v3f(0,BS/2,0), BS);
m_old_node_below_type = nodemgr->get(map->getNodeNoEx(m_old_node_below)).name;

/*
Check properties of the node on which the player is standing
*/
Expand Down Expand Up @@ -378,10 +379,10 @@ void LocalPlayer::applyControl(float dtime)

v3f move_direction = v3f(0,0,1);
move_direction.rotateXZBy(getYaw());

v3f speedH = v3f(0,0,0); // Horizontal (X, Z)
v3f speedV = v3f(0,0,0); // Vertical (Y)

bool fly_allowed = m_gamedef->checkLocalPrivilege("fly");
bool fast_allowed = m_gamedef->checkLocalPrivilege("fast");

Expand All @@ -393,7 +394,7 @@ void LocalPlayer::applyControl(float dtime)

// Whether superspeed mode is used or not
bool superspeed = false;

if(g_settings->getBool("always_fly_fast") && free_move && fast_move)
superspeed = true;

Expand All @@ -403,7 +404,7 @@ void LocalPlayer::applyControl(float dtime)
// If free movement and fast movement, always move fast
if(free_move && fast_move)
superspeed = true;

// Auxiliary button 1 (E)
if(control.aux1)
{
Expand Down Expand Up @@ -500,7 +501,7 @@ void LocalPlayer::applyControl(float dtime)
if(control.jump)
{
if(free_move)
{
{
if(g_settings->getBool("aux1_descends") || g_settings->getBool("always_fly_fast"))
{
if(fast_move)
Expand All @@ -526,7 +527,7 @@ void LocalPlayer::applyControl(float dtime)
{
speedJ.Y = movement_speed_jump * physics_override_jump;
setSpeed(speedJ);

MtEvent *e = new SimpleTriggerEvent("PlayerJump");
m_gamedef->event()->put(e);
}
Expand Down
7 changes: 4 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#endif

#include "irrlicht.h" // createDevice

#include "main.h"
#include "mainmenumanager.h"
#include <iostream>
Expand Down Expand Up @@ -263,6 +262,7 @@ class MyEventReceiver : public IEventReceiver
} else {
keyIsDown.unset(event.KeyInput);
}
return true;
}

if(event.EventType == irr::EET_MOUSE_INPUT_EVENT)
Expand Down Expand Up @@ -1472,10 +1472,11 @@ int main(int argc, char *argv[])
bool random_input = g_settings->getBool("random_input")
|| cmd_args.getFlag("random-input");
InputHandler *input = NULL;
if(random_input)
if(random_input) {
input = new RandomInputHandler();
else
} else {
input = new RealInputHandler(device, &receiver);
}

scene::ISceneManager* smgr = device->getSceneManager();

Expand Down
44 changes: 22 additions & 22 deletions src/porting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ bool threadBindToProcessor(threadid_t tid, int pnumber) {

#elif defined(__sun) || defined(sun)

return processor_bind(P_LWPID, MAKE_LWPID_PTHREAD(tid),
return processor_bind(P_LWPID, MAKE_LWPID_PTHREAD(tid),
pnumber, NULL) == 0;

#elif defined(_AIX)

return bindprocessor(BINDTHREAD, (tid_t)tid, pnumber) == 0;

#elif defined(__hpux) || defined(hpux)
Expand All @@ -203,11 +203,11 @@ bool threadBindToProcessor(threadid_t tid, int pnumber) {

return pthread_processor_bind_np(PTHREAD_BIND_ADVISORY_NP,
&answer, pnumber, tid) == 0;

#elif defined(__APPLE__)

struct thread_affinity_policy tapol;

thread_port_t threadport = pthread_mach_thread_np(tid);
tapol.affinity_tag = pnumber + 1;
return thread_policy_set(threadport, THREAD_AFFINITY_POLICY,
Expand All @@ -232,21 +232,21 @@ bool threadSetPriority(threadid_t tid, int prio) {

CloseHandle(hThread);
return success;

#else

struct sched_param sparam;
int policy;

if (pthread_getschedparam(tid, &policy, &sparam) != 0)
return false;

int min = sched_get_priority_min(policy);
int max = sched_get_priority_max(policy);

sparam.sched_priority = min + prio * (max - min) / THREAD_PRIORITY_HIGHEST;
return pthread_setschedparam(tid, policy, &sparam) == 0;

#endif
}

Expand Down Expand Up @@ -476,7 +476,7 @@ void initializePaths()
i != trylist.end(); i++)
{
const std::string &trypath = *i;
if(!fs::PathExists(trypath) || !fs::PathExists(trypath + "/builtin")){
if(!fs::PathExists(trypath) || !fs::PathExists(trypath + DIR_DELIM + "builtin")){
dstream<<"WARNING: system-wide share not found at \""
<<trypath<<"\""<<std::endl;
continue;
Expand All @@ -490,37 +490,37 @@ void initializePaths()
break;
}

path_user = std::string(getenv("HOME")) + "/." + PROJECT_NAME;
path_user = std::string(getenv("HOME")) + DIR_DELIM + "." + PROJECT_NAME;

/*
OS X
*/
#elif defined(__APPLE__)

// Code based on
// http://stackoverflow.com/questions/516200/relative-paths-not-working-in-xcode-c
CFBundleRef main_bundle = CFBundleGetMainBundle();
CFURLRef resources_url = CFBundleCopyResourcesDirectoryURL(main_bundle);
char path[PATH_MAX];
if(CFURLGetFileSystemRepresentation(resources_url, TRUE, (UInt8 *)path, PATH_MAX))
// Code based on
// http://stackoverflow.com/questions/516200/relative-paths-not-working-in-xcode-c
CFBundleRef main_bundle = CFBundleGetMainBundle();
CFURLRef resources_url = CFBundleCopyResourcesDirectoryURL(main_bundle);
char path[PATH_MAX];
if(CFURLGetFileSystemRepresentation(resources_url, TRUE, (UInt8 *)path, PATH_MAX))
{
dstream<<"Bundle resource path: "<<path<<std::endl;
//chdir(path);
path_share = std::string(path) + "/share";
path_share = std::string(path) + DIR_DELIM + "share";
}
else
{
// error!
{
// error!
dstream<<"WARNING: Could not determine bundle resource path"<<std::endl;
}
CFRelease(resources_url);
}
CFRelease(resources_url);

path_user = std::string(getenv("HOME")) + "/Library/Application Support/" + PROJECT_NAME;

#else // FreeBSD, and probably many other POSIX-like systems.

path_share = STATIC_SHAREDIR;
path_user = std::string(getenv("HOME")) + "/." + PROJECT_NAME;
path_user = std::string(getenv("HOME")) + DIR_DELIM + "." + PROJECT_NAME;

#endif

Expand Down
46 changes: 33 additions & 13 deletions src/porting.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define _WIN32_WINNT 0x0501
#endif
#include <windows.h>

#define sleep_ms(x) Sleep(x)
#else
#include <unistd.h>
#include <stdint.h> //for uintptr_t

#if (defined(linux) || defined(__linux)) && !defined(_GNU_SOURCE)
#define _GNU_SOURCE
#endif
Expand All @@ -72,7 +72,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#endif

#define sleep_ms(x) usleep(x*1000)

#define THREAD_PRIORITY_LOWEST 0
#define THREAD_PRIORITY_BELOW_NORMAL 1
#define THREAD_PRIORITY_NORMAL 2
Expand Down Expand Up @@ -183,65 +183,65 @@ std::string get_sysinfo();
#define _WIN32_WINNT 0x0501
#endif
#include <windows.h>

inline u32 getTimeS()
{
return GetTickCount() / 1000;
}

inline u32 getTimeMs()
{
return GetTickCount();
}

inline u32 getTimeUs()
{
LARGE_INTEGER freq, t;
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&t);
return (double)(t.QuadPart) / ((double)(freq.QuadPart) / 1000000.0);
}

inline u32 getTimeNs()
{
LARGE_INTEGER freq, t;
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&t);
return (double)(t.QuadPart) / ((double)(freq.QuadPart) / 1000000000.0);
}

#else // Posix
#include <sys/time.h>
#include <time.h>

inline u32 getTimeS()
{
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec;
}

inline u32 getTimeMs()
{
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
}

inline u32 getTimeUs()
{
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000000 + tv.tv_usec;
}

inline u32 getTimeNs()
{
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
return ts.tv_sec * 1000000000 + ts.tv_nsec;
}

/*#include <sys/timeb.h>
inline u32 getTimeMs()
{
Expand All @@ -266,6 +266,26 @@ inline u32 getTime(TimePrecision prec)
return 0;
}

inline u32 getDeltaMs(u32 old_time_ms,u32 new_time_ms) {
if (new_time_ms >= old_time_ms) {
return (new_time_ms - old_time_ms);
}
else {
return ((0xFFFFFFFF - old_time_ms) + new_time_ms);
}
}

#ifdef WIN32
// not supported on windows platform
#define setThreadName(a)
#else

#include <sys/prctl.h>

inline void setThreadName(const char* name) {
prctl(PR_SET_NAME,name);
}
#endif

} // namespace porting

Expand Down
2 changes: 2 additions & 0 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ void * ServerThread::Thread()

ThreadStarted();

porting::setThreadName("ServerThread");

while(!StopRequested())
{
try{
Expand Down
3 changes: 2 additions & 1 deletion src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <map>
#include <set>
#include "filesys.h"
#include <ctype.h>

enum ValueType
{
Expand Down Expand Up @@ -575,7 +576,7 @@ class Settings
u32 getFlagStr(std::string name, FlagDesc *flagdesc, u32 *flagmask)
{
std::string val = get(name);
return (isdigit(val[0])) ? stoi(val) :
return (std::isdigit(val[0])) ? stoi(val) :
readFlagString(val, flagdesc, flagmask);
}

Expand Down
17 changes: 14 additions & 3 deletions src/tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,9 +730,6 @@ u32 TextureSource::getTextureIdDirect(const std::string &name)
m_textureinfo_cache.push_back(ti);
m_name_to_id[name] = id;

/*infostream<<"getTextureIdDirect(): "
<<"Returning id="<<id<<" for name \""<<name<<"\""<<std::endl;*/

return id;
}

Expand Down Expand Up @@ -962,6 +959,20 @@ bool TextureSource::generateImage(std::string part_of_name, video::IImage *& bas
{
video::IImage *image = m_sourcecache.getOrLoad(part_of_name, m_device);

if (image != NULL) {
if (!driver->queryFeature(irr::video::EVDF_TEXTURE_NPOT)) {
core::dimension2d<u32> dim = image->getDimension();


if ((dim.Height %2 != 0) ||
(dim.Width %2 != 0)) {
errorstream << "TextureSource::generateImage "
<< part_of_name << " size npot2 x=" << dim.Width
<< " y=" << dim.Height << std::endl;
}
}
}

if(image == NULL)
{
if(part_of_name != ""){
Expand Down