#include "porting.h"
#include "common/c_internal.h"
-/******************************************************************************/
-AsyncEngine::AsyncEngine() :
- initDone(false),
- jobIdCounter(0)
-{
-}
-
/******************************************************************************/
AsyncEngine::~AsyncEngine()
{
// Data required to queue a job
struct LuaJobInfo
{
- LuaJobInfo() :
- serializedFunction(""),
- serializedParams(""),
- serializedResult(""),
- id(0),
- valid(false)
- {}
+ LuaJobInfo() {};
// Function to be called in async environment
- std::string serializedFunction;
+ std::string serializedFunction = "";
// Parameter to be passed to function
- std::string serializedParams;
+ std::string serializedParams = "";
// Result of function call
- std::string serializedResult;
+ std::string serializedResult = "";
// JobID used to identify a job and match it to callback
- unsigned int id;
+ unsigned int id = 0;
- bool valid;
+ bool valid = false;
};
// Asynchronous working environment
void *run();
private:
- AsyncEngine *jobDispatcher;
+ AsyncEngine *jobDispatcher = nullptr;
};
// Asynchornous thread and job management
friend class AsyncWorkerThread;
typedef void (*StateInitializer)(lua_State *L, int top);
public:
- AsyncEngine();
+ AsyncEngine() {};
~AsyncEngine();
/**
private:
// Variable locking the engine against further modification
- bool initDone;
+ bool initDone = false;
// Internal store for registred state initializers
std::vector<StateInitializer> stateInitializers;
// Internal counter to create job IDs
- unsigned int jobIdCounter;
+ unsigned int jobIdCounter = 0;
// Mutex to protect job queue
std::mutex jobQueueMutex;
ScriptApiBase
*/
-ScriptApiBase::ScriptApiBase() :
- m_luastackmutex(),
- m_gamedef(NULL)
+ScriptApiBase::ScriptApiBase()
{
#ifdef SCRIPTAPI_LOCK_DEBUG
m_lock_recursion_count = 0;
lua_pushstring(m_luastack, porting::getPlatformName());
lua_setglobal(m_luastack, "PLATFORM");
-
- // m_secure gets set to true inside
- // ScriptApiSecurity::initializeSecurity(), if neccessary.
- // Default to false otherwise
- m_secure = false;
-
- m_environment = NULL;
- m_guiengine = NULL;
}
ScriptApiBase::~ScriptApiBase()
std::recursive_mutex m_luastackmutex;
std::string m_last_run_mod;
- bool m_secure;
+ bool m_secure = false;
#ifdef SCRIPTAPI_LOCK_DEBUG
int m_lock_recursion_count;
std::thread::id m_owning_thread;
private:
static int luaPanic(lua_State *L);
- lua_State* m_luastack;
+ lua_State *m_luastack = nullptr;
- IGameDef* m_gamedef;
- Environment* m_environment;
- GUIEngine* m_guiengine;
+ IGameDef *m_gamedef = nullptr;
+ Environment *m_environment = nullptr;
+ GUIEngine *m_guiengine = nullptr;
};
#endif /* S_BASE_H_ */
return deserialization_helper(L, o->as, is);
}
-LuaAreaStore::LuaAreaStore()
+LuaAreaStore::LuaAreaStore() : as(AreaStore::getOptimalImplementation())
{
- this->as = AreaStore::getOptimalImplementation();
}
LuaAreaStore::LuaAreaStore(const std::string &type)
{
#if USE_SPATIAL
if (type == "LibSpatial") {
- this->as = new SpatialAreaStore();
+ as = new SpatialAreaStore();
} else
#endif
{
- this->as = new VectorAreaStore();
+ as = new VectorAreaStore();
}
}
static int l_from_file(lua_State *L);
public:
- AreaStore *as;
+ AreaStore *as = nullptr;
LuaAreaStore();
LuaAreaStore(const std::string &type);
#include "content_cao.h"
#include "camera.h"
-LuaCamera::LuaCamera(Camera *m)
+LuaCamera::LuaCamera(Camera *m) : m_camera(m)
{
- m_camera = m;
}
void LuaCamera::create(lua_State *L, Camera *m)
static int l_get_look_horizontal(lua_State *L);
static int l_get_aspect_ratio(lua_State *L);
- Camera *m_camera;
+ Camera *m_camera = nullptr;
public:
LuaCamera(Camera *m);
class ItemStackMetaRef : public MetaDataRef
{
private:
- ItemStack *istack;
+ ItemStack *istack = nullptr;
static const char className[];
static const luaL_Reg methods[];
#include "l_internal.h"
#include "script/common/c_converter.h"
-LuaLocalPlayer::LuaLocalPlayer(LocalPlayer *m)
+LuaLocalPlayer::LuaLocalPlayer(LocalPlayer *m) : m_localplayer(m)
{
- m_localplayer = m;
}
void LuaLocalPlayer::create(lua_State *L, LocalPlayer *m)
static int l_get_movement(lua_State *L);
- LocalPlayer *m_localplayer;
+ LocalPlayer *m_localplayer = nullptr;
public:
LuaLocalPlayer(LocalPlayer *m);
#include "minimap.h"
#include "settings.h"
-LuaMinimap::LuaMinimap(Minimap *m)
+LuaMinimap::LuaMinimap(Minimap *m) : m_minimap(m)
{
- m_minimap = m;
}
void LuaMinimap::create(lua_State *L, Minimap *m)
static int l_set_shape(lua_State *L);
static int l_get_shape(lua_State *L);
- Minimap *m_minimap;
+ Minimap *m_minimap = nullptr;
public:
LuaMinimap(Minimap *m);
NodeMetaRef::NodeMetaRef(v3s16 p, ServerEnvironment *env):
m_p(p),
- m_env(env),
- m_is_local(false)
+ m_env(env)
{
}
NodeMetaRef::NodeMetaRef(Metadata *meta):
- m_meta(meta),
- m_is_local(true)
+ m_meta(meta)
{
}
class NodeMetaRef : public MetaDataRef {
private:
v3s16 m_p;
- ServerEnvironment *m_env;
- Metadata *m_meta;
- bool m_is_local;
+ ServerEnvironment *m_env = nullptr;
+ Metadata *m_meta = nullptr;
+ bool m_is_local = false;
static const char className[];
static const luaL_Reg methodsServer[];
{
private:
v3s16 m_p;
- ServerEnvironment *m_env;
+ ServerEnvironment *m_env = nullptr;
static const char className[];
static const luaL_Reg methods[];
*/
class ObjectRef : public ModApiBase {
-private:
- ServerActiveObject *m_object;
-
- static const char className[];
- static const luaL_Reg methods[];
public:
+ ObjectRef(ServerActiveObject *object);
+
+ ~ObjectRef();
+
+ // Creates an ObjectRef and leaves it on top of stack
+ // Not callable from Lua; all references are created on the C side.
+ static void create(lua_State *L, ServerActiveObject *object);
+
+ static void set_null(lua_State *L);
+
+ static void Register(lua_State *L);
+
static ObjectRef *checkobject(lua_State *L, int narg);
static ServerActiveObject* getobject(ObjectRef *ref);
private:
+ ServerActiveObject *m_object = nullptr;
+
+ static const char className[];
+ static const luaL_Reg methods[];
+
+
static LuaEntitySAO* getluaobject(ObjectRef *ref);
static PlayerSAO* getplayersao(ObjectRef *ref);
// get_nametag_attributes(self)
static int l_get_nametag_attributes(lua_State *L);
-public:
- ObjectRef(ServerActiveObject *object);
-
- ~ObjectRef();
-
- // Creates an ObjectRef and leaves it on top of stack
- // Not callable from Lua; all references are created on the C side.
- static void create(lua_State *L, ServerActiveObject *object);
-
- static void set_null(lua_State *L);
-
- static void Register(lua_State *L);
};
#endif /* L_OBJECT_H_ */
LuaSettings::LuaSettings(Settings *settings, const std::string &filename) :
m_settings(settings),
- m_filename(filename),
- m_is_own_settings(false),
- m_write_allowed(true)
+ m_filename(filename)
{
}
// to_table(self) -> {[key1]=value1,...}
static int l_to_table(lua_State *L);
- Settings *m_settings;
+ Settings *m_settings = nullptr;
std::string m_filename;
- bool m_is_own_settings;
- bool m_write_allowed;
+ bool m_is_own_settings = false;
+ bool m_write_allowed = true;
public:
LuaSettings(Settings *settings, const std::string &filename);
class StorageRef : public MetaDataRef
{
private:
- ModMetadata *m_object;
+ ModMetadata *m_object = nullptr;
static const char className[];
static const luaL_Reg methods[];
return 2;
}
-LuaVoxelManip::LuaVoxelManip(MMVManip *mmvm, bool is_mg_vm)
+LuaVoxelManip::LuaVoxelManip(MMVManip *mmvm, bool is_mg_vm) : vm(mmvm), is_mapgen_vm(is_mg_vm)
{
- this->vm = mmvm;
- this->is_mapgen_vm = is_mg_vm;
}
-LuaVoxelManip::LuaVoxelManip(Map *map)
+LuaVoxelManip::LuaVoxelManip(Map *map) : vm(new MMVManip(map))
{
- this->vm = new MMVManip(map);
- this->is_mapgen_vm = false;
}
LuaVoxelManip::LuaVoxelManip(Map *map, v3s16 p1, v3s16 p2)
{
- this->vm = new MMVManip(map);
- this->is_mapgen_vm = false;
+ vm = new MMVManip(map);
v3s16 bp1 = getNodeBlockPos(p1);
v3s16 bp2 = getNodeBlockPos(p2);
{
private:
std::map<v3s16, MapBlock *> modified_blocks;
- bool is_mapgen_vm;
+ bool is_mapgen_vm = false;
static const char className[];
static const luaL_Reg methods[];
static int l_get_emerged_area(lua_State *L);
public:
- MMVManip *vm;
+ MMVManip *vm = nullptr;
LuaVoxelManip(MMVManip *mmvm, bool is_mapgen_vm);
LuaVoxelManip(Map *map, v3s16 p1, v3s16 p2);
Thread::Thread(const std::string &name) :
m_name(name),
- m_retval(NULL),
- m_joinable(false),
m_request_stop(false),
m_running(false)
{
m_thread_obj->join();
delete m_thread_obj;
- m_thread_obj = NULL;
+ m_thread_obj = nullptr;
assert(m_running == false);
m_joinable = false;
wait();
#endif
- m_retval = NULL;
+ m_retval = nullptr;
m_joinable = false;
m_request_stop = false;
static void threadProc(Thread *thr);
- void *m_retval;
- bool m_joinable;
+ void *m_retval = nullptr;
+ bool m_joinable = false;
std::atomic<bool> m_request_stop;
std::atomic<bool> m_running;
std::mutex m_mutex;
virtual void unregisterModStorage(const std::string &name) {}
private:
- IItemDefManager *m_itemdef;
- INodeDefManager *m_nodedef;
- ICraftDefManager *m_craftdef;
- ITextureSource *m_texturesrc;
- IShaderSource *m_shadersrc;
- ISoundManager *m_soundmgr;
- MtEventManager *m_eventmgr;
- scene::ISceneManager *m_scenemgr;
- IRollbackManager *m_rollbackmgr;
- EmergeManager *m_emergemgr;
+ IItemDefManager *m_itemdef = nullptr;
+ INodeDefManager *m_nodedef = nullptr;
+ ICraftDefManager *m_craftdef = nullptr;
+ ITextureSource *m_texturesrc = nullptr;
+ IShaderSource *m_shadersrc = nullptr;
+ ISoundManager *m_soundmgr = nullptr;
+ MtEventManager *m_eventmgr = nullptr;
+ scene::ISceneManager *m_scenemgr = nullptr;
+ IRollbackManager *m_rollbackmgr = nullptr;
+ EmergeManager *m_emergemgr = nullptr;
};
struct Handler : public con::PeerHandler
{
- Handler(const char *a_name)
- {
- count = 0;
- last_id = 0;
- name = a_name;
- }
+ Handler(const char *a_name) : name(a_name) {}
void peerAdded(con::Peer *peer)
{
count--;
}
- s32 count;
- u16 last_id;
+ s32 count = 0;
+ u16 last_id = 0;
const char *name;
};
{
AreaMap::const_iterator it = areas_map.find(id);
if (it == areas_map.end())
- return NULL;
+ return nullptr;
return &it->second;
}
if (!areas_map.insert(std::make_pair(a->id, *a)).second)
// ID is not unique
return false;
- m_tree->insertData(0, NULL, get_spatial_region(a->minedge, a->maxedge), a->id);
+ m_tree->insertData(0, nullptr, get_spatial_region(a->minedge, a->maxedge), a->id);
invalidateCache();
return true;
}
struct Area {
- Area() : id(U32_MAX) {}
+ Area() {}
Area(const v3s16 &mine, const v3s16 &maxe) :
- id(U32_MAX), minedge(mine), maxedge(maxe)
+ minedge(mine), maxedge(maxe)
{
sortBoxVerticies(minedge, maxedge);
}
- u32 id;
+ u32 id = U32_MAX;
v3s16 minedge, maxedge;
std::string data;
};
class AreaStore {
public:
AreaStore() :
- m_cache_enabled(true),
- m_cacheblock_radius(64),
- m_res_cache(1000, &cacheMiss, this),
- m_next_id(0)
+ m_res_cache(1000, &cacheMiss, this)
{}
virtual ~AreaStore() {}
/// Called by the cache when a value isn't found in the cache.
static void cacheMiss(void *data, const v3s16 &mpos, std::vector<Area *> *dest);
- bool m_cache_enabled;
+ bool m_cache_enabled = true;
/// Range, in nodes, of the getAreasForPos cache.
/// If you modify this, call invalidateCache()
- u8 m_cacheblock_radius;
+ u8 m_cacheblock_radius = 64;
LRUCache<v3s16, std::vector<Area *> > m_res_cache;
- u32 m_next_id;
+ u32 m_next_id = 0;
};
virtual void getAreasForPosImpl(std::vector<Area *> *result, v3s16 pos);
private:
- SpatialIndex::ISpatialIndex *m_tree;
- SpatialIndex::IStorageManager *m_storagemanager;
+ SpatialIndex::ISpatialIndex *m_tree = nullptr;
+ SpatialIndex::IStorageManager *m_storagemanager = nullptr;
class VectorResultVisitor : public SpatialIndex::IVisitor {
public:
}
private:
- SpatialAreaStore *m_store;
- std::vector<Area *> *m_result;
+ SpatialAreaStore *m_store = nullptr;
+ std::vector<Area *> *m_result = nullptr;
};
};
// get modified if &salt_ptr isn't NULL.
char *salt_ptr = (char *)salt.c_str();
- char *bytes_v = NULL;
+ char *bytes_v = nullptr;
size_t verifier_len = 0;
gen_srp_v(name, password, &salt_ptr, &salt_len, &bytes_v, &verifier_len);
std::string verifier = std::string(bytes_v, verifier_len);
const std::string &password, std::string *verifier,
std::string *salt)
{
- char *bytes_v = NULL;
+ char *bytes_v = nullptr;
size_t verifier_len;
- char *salt_ptr = NULL;
+ char *salt_ptr = nullptr;
size_t salt_len;
gen_srp_v(name, password, &salt_ptr, &salt_len, &bytes_v, &verifier_len);
*verifier = std::string(bytes_v, verifier_len);
EnrichedString::EnrichedString(const std::wstring &string,
const std::vector<SColor> &colors):
m_string(string),
- m_colors(colors),
- m_has_background(false)
+ m_colors(colors)
{}
EnrichedString::EnrichedString(const std::wstring &s, const SColor &color)
private:
std::wstring m_string;
std::vector<irr::video::SColor> m_colors;
- bool m_has_background;
+ bool m_has_background = false;
irr::video::SColor m_background;
};
class IntervalLimiter
{
public:
- IntervalLimiter() : m_accumulator(0) {}
+ IntervalLimiter() {}
/*
dtime: time from last call to this method
wanted_interval: interval wanted
}
private:
- float m_accumulator;
+ float m_accumulator = 0.0f;
};
#include "../exceptions.h"
#include <sstream>
-PointedThing::PointedThing():
- type(POINTEDTHING_NOTHING),
- node_undersurface(0,0,0),
- node_abovesurface(0,0,0),
- node_real_undersurface(0,0,0),
- intersection_point(0,0,0),
- intersection_normal(0,0,0),
- object_id(-1)
-{}
-
std::string PointedThing::dump() const
{
std::ostringstream os(std::ios::binary);
struct PointedThing
{
//! The type of the pointed object.
- PointedThingType type;
+ PointedThingType type = POINTEDTHING_NOTHING;
/*!
* Only valid if type is POINTEDTHING_NODE.
* The coordinates of the node which owns the
* Only valid if type is POINTEDTHING_OBJECT.
* The ID of the object the ray hit.
*/
- s16 object_id;
+ s16 object_id = -1;
- PointedThing();
+ PointedThing() {};
std::string dump() const;
void serialize(std::ostream &os) const;
void deSerialize(std::istream &is);
char *fmtpos, *fmt = &format[0];
while ((f = strtok_r(fmt, ",", &fmtpos)) && s) {
- fmt = NULL;
+ fmt = nullptr;
bool is_unsigned = false;
int width = 0;
bufpos += sizeof(std::string *);
strs_alloced.push_back(str);
- s = *snext ? snext + 1 : NULL;
+ s = *snext ? snext + 1 : nullptr;
break;
case 'v':
while (*s == ' ' || *s == '\t')
char *bufpos = (char *) value;
char *fmtpos, *fmt = &format[0];
while ((f = strtok_r(fmt, ",", &fmtpos))) {
- fmt = NULL;
+ fmt = nullptr;
bool is_unsigned = false;
int width = 0;
char valtype = *f;
public:
BufReader(const u8 *data_, size_t size_) :
data(data_),
- size(size_),
- pos(0)
+ size(size_)
{
}
const u8 *data;
size_t size;
- size_t pos;
+ size_t pos = 0;
};
#undef MAKE_BUFREADER_GET_FXN
{
// make sure that the data type is the right size
assert( sizeof( Uint32 ) * 5 == 20 );
-
- // initialize
- H0 = 0x67452301;
- H1 = 0xefcdab89;
- H2 = 0x98badcfe;
- H3 = 0x10325476;
- H4 = 0xc3d2e1f0;
- unprocessedBytes = 0;
- size = 0;
}
// Destructor ********************************************************
{
private:
// fields
- Uint32 H0, H1, H2, H3, H4;
+ Uint32 H0 = 0x67452301;
+ Uint32 H1 = 0xefcdab89;
+ Uint32 H2 = 0x98badcfe;
+ Uint32 H3 = 0x10325476;
+ Uint32 H4 = 0xc3d2e1f0;
unsigned char bytes[64];
- int unprocessedBytes;
- Uint32 size;
+ int unprocessedBytes = 0;
+ Uint32 size = 0;
void process();
public:
{
m_name = name;
m_result = result;
- m_running = true;
m_precision = prec;
m_time1 = porting::getTime(prec);
}
{
if (m_running) {
u64 dtime = porting::getTime(m_precision) - m_time1;
- if (m_result != NULL) {
+ if (m_result != nullptr) {
(*m_result) += dtime;
} else {
if (!quiet) {
class TimeTaker
{
public:
- TimeTaker(const std::string &name, u64 *result=NULL,
+ TimeTaker(const std::string &name, u64 *result=nullptr,
TimePrecision prec=PRECISION_MILLI);
~TimeTaker()
private:
std::string m_name;
u64 m_time1;
- bool m_running;
+ bool m_running = true;
TimePrecision m_precision;
- u64 *m_result;
+ u64 *m_result = nullptr;
};
#endif