forked from Mirrorlandia_minetest/minetest
Modernize src/c* src/d* and src/e* files (#6263)
* Modernize src/c* src/d* and src/e* files * default operator * redundant init * delete default constructors on CraftDefinition childs (never used) * fix some missing init values * const ref fix reported by clang-tidy * ranged-based for loops * simple conditions & returns * empty stl function instead of size * emplace_back stl function instead of push_back + construct temp obj * auto for some iterators * code style fixes * c++ stl headers instead of C stl headers (stdio.h -> cstdio)
This commit is contained in:
parent
921151d97a
commit
13e995b811
@ -119,7 +119,7 @@ class TestCAO : public ClientActiveObject
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TestCAO(Client *client, ClientEnvironment *env);
|
TestCAO(Client *client, ClientEnvironment *env);
|
||||||
virtual ~TestCAO();
|
virtual ~TestCAO() = default;
|
||||||
|
|
||||||
ActiveObjectType getType() const
|
ActiveObjectType getType() const
|
||||||
{
|
{
|
||||||
@ -155,10 +155,6 @@ TestCAO::TestCAO(Client *client, ClientEnvironment *env):
|
|||||||
ClientActiveObject::registerType(getType(), create);
|
ClientActiveObject::registerType(getType(), create);
|
||||||
}
|
}
|
||||||
|
|
||||||
TestCAO::~TestCAO()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ClientActiveObject* TestCAO::create(Client *client, ClientEnvironment *env)
|
ClientActiveObject* TestCAO::create(Client *client, ClientEnvironment *env)
|
||||||
{
|
{
|
||||||
return new TestCAO(client, env);
|
return new TestCAO(client, env);
|
||||||
@ -261,7 +257,7 @@ class ItemCAO : public ClientActiveObject
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ItemCAO(Client *client, ClientEnvironment *env);
|
ItemCAO(Client *client, ClientEnvironment *env);
|
||||||
virtual ~ItemCAO();
|
virtual ~ItemCAO() = default;
|
||||||
|
|
||||||
ActiveObjectType getType() const
|
ActiveObjectType getType() const
|
||||||
{
|
{
|
||||||
@ -323,10 +319,6 @@ ItemCAO::ItemCAO(Client *client, ClientEnvironment *env):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemCAO::~ItemCAO()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ClientActiveObject* ItemCAO::create(Client *client, ClientEnvironment *env)
|
ClientActiveObject* ItemCAO::create(Client *client, ClientEnvironment *env)
|
||||||
{
|
{
|
||||||
return new ItemCAO(client, env);
|
return new ItemCAO(client, env);
|
||||||
@ -563,7 +555,7 @@ void GenericCAO::initialize(const std::string &data)
|
|||||||
player->setCAO(this);
|
player->setCAO(this);
|
||||||
}
|
}
|
||||||
if (m_client->getProtoVersion() < 33)
|
if (m_client->getProtoVersion() < 33)
|
||||||
m_env->addPlayerName(m_name.c_str());
|
m_env->addPlayerName(m_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -607,7 +599,7 @@ void GenericCAO::processInitData(const std::string &data)
|
|||||||
GenericCAO::~GenericCAO()
|
GenericCAO::~GenericCAO()
|
||||||
{
|
{
|
||||||
if (m_is_player && m_client->getProtoVersion() < 33) {
|
if (m_is_player && m_client->getProtoVersion() < 33) {
|
||||||
m_env->removePlayerName(m_name.c_str());
|
m_env->removePlayerName(m_name);
|
||||||
}
|
}
|
||||||
removeFromScene(true);
|
removeFromScene(true);
|
||||||
}
|
}
|
||||||
@ -628,8 +620,8 @@ v3f GenericCAO::getPosition()
|
|||||||
scene::ISceneNode *node = getSceneNode();
|
scene::ISceneNode *node = getSceneNode();
|
||||||
if (node)
|
if (node)
|
||||||
return node->getAbsolutePosition();
|
return node->getAbsolutePosition();
|
||||||
else
|
|
||||||
return m_position;
|
return m_position;
|
||||||
}
|
}
|
||||||
return pos_translator.vect_show;
|
return pos_translator.vect_show;
|
||||||
}
|
}
|
||||||
@ -638,11 +630,17 @@ scene::ISceneNode* GenericCAO::getSceneNode()
|
|||||||
{
|
{
|
||||||
if (m_meshnode) {
|
if (m_meshnode) {
|
||||||
return m_meshnode;
|
return m_meshnode;
|
||||||
} else if (m_animated_meshnode) {
|
}
|
||||||
|
|
||||||
|
if (m_animated_meshnode) {
|
||||||
return m_animated_meshnode;
|
return m_animated_meshnode;
|
||||||
} else if (m_wield_meshnode) {
|
}
|
||||||
|
|
||||||
|
if (m_wield_meshnode) {
|
||||||
return m_wield_meshnode;
|
return m_wield_meshnode;
|
||||||
} else if (m_spritenode) {
|
}
|
||||||
|
|
||||||
|
if (m_spritenode) {
|
||||||
return m_spritenode;
|
return m_spritenode;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -655,8 +653,8 @@ scene::IAnimatedMeshSceneNode* GenericCAO::getAnimatedMeshSceneNode()
|
|||||||
|
|
||||||
void GenericCAO::setChildrenVisible(bool toset)
|
void GenericCAO::setChildrenVisible(bool toset)
|
||||||
{
|
{
|
||||||
for (std::vector<u16>::size_type i = 0; i < m_children.size(); i++) {
|
for (u16 cao_id : m_children) {
|
||||||
GenericCAO *obj = m_env->getGenericCAO(m_children[i]);
|
GenericCAO *obj = m_env->getGenericCAO(cao_id);
|
||||||
if (obj) {
|
if (obj) {
|
||||||
obj->setVisible(toset);
|
obj->setVisible(toset);
|
||||||
}
|
}
|
||||||
@ -686,8 +684,7 @@ void GenericCAO::removeFromScene(bool permanent)
|
|||||||
// Should be true when removing the object permanently and false when refreshing (eg: updating visuals)
|
// Should be true when removing the object permanently and false when refreshing (eg: updating visuals)
|
||||||
if((m_env != NULL) && (permanent))
|
if((m_env != NULL) && (permanent))
|
||||||
{
|
{
|
||||||
for (std::vector<u16>::size_type i = 0; i < m_children.size(); i++) {
|
for (u16 ci : m_children) {
|
||||||
u16 ci = m_children[i];
|
|
||||||
if (m_env->attachement_parent_ids[ci] == getId()) {
|
if (m_env->attachement_parent_ids[ci] == getId()) {
|
||||||
m_env->attachement_parent_ids[ci] = 0;
|
m_env->attachement_parent_ids[ci] = 0;
|
||||||
}
|
}
|
||||||
@ -858,14 +855,13 @@ void GenericCAO::addToScene(ITextureSource *tsrc)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
errorstream<<"GenericCAO::addToScene(): Could not load mesh "<<m_prop.mesh<<std::endl;
|
errorstream<<"GenericCAO::addToScene(): Could not load mesh "<<m_prop.mesh<<std::endl;
|
||||||
}
|
} else if (m_prop.visual == "wielditem") {
|
||||||
else if(m_prop.visual == "wielditem") {
|
|
||||||
ItemStack item;
|
ItemStack item;
|
||||||
infostream << "GenericCAO::addToScene(): wielditem" << std::endl;
|
infostream << "GenericCAO::addToScene(): wielditem" << std::endl;
|
||||||
if (m_prop.wield_item == "") {
|
if (m_prop.wield_item.empty()) {
|
||||||
// Old format, only textures are specified.
|
// Old format, only textures are specified.
|
||||||
infostream << "textures: " << m_prop.textures.size() << std::endl;
|
infostream << "textures: " << m_prop.textures.size() << std::endl;
|
||||||
if (m_prop.textures.size() >= 1) {
|
if (!m_prop.textures.empty()) {
|
||||||
infostream << "textures[0]: " << m_prop.textures[0]
|
infostream << "textures[0]: " << m_prop.textures[0]
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
IItemDefManager *idef = m_client->idef();
|
IItemDefManager *idef = m_client->idef();
|
||||||
@ -894,7 +890,7 @@ void GenericCAO::addToScene(ITextureSource *tsrc)
|
|||||||
updateTextures(m_current_texture_modifier);
|
updateTextures(m_current_texture_modifier);
|
||||||
|
|
||||||
scene::ISceneNode *node = getSceneNode();
|
scene::ISceneNode *node = getSceneNode();
|
||||||
if (node && m_prop.nametag != "" && !m_is_local_player) {
|
if (node && !m_prop.nametag.empty() && !m_is_local_player) {
|
||||||
// Add nametag
|
// Add nametag
|
||||||
v3f pos;
|
v3f pos;
|
||||||
pos.Y = m_prop.collisionbox.MaxEdge.Y + 0.3f;
|
pos.Y = m_prop.collisionbox.MaxEdge.Y + 0.3f;
|
||||||
@ -919,8 +915,8 @@ void GenericCAO::updateLight(u8 light_at_pos)
|
|||||||
updateLightNoCheck(light_at_pos);
|
updateLightNoCheck(light_at_pos);
|
||||||
|
|
||||||
// Update light of all children
|
// Update light of all children
|
||||||
for (std::vector<u16>::size_type i = 0; i < m_children.size(); i++) {
|
for (u16 i : m_children) {
|
||||||
ClientActiveObject *obj = m_env->getActiveObject(m_children[i]);
|
ClientActiveObject *obj = m_env->getActiveObject(i);
|
||||||
if (obj) {
|
if (obj) {
|
||||||
obj->updateLightNoCheck(light_at_pos);
|
obj->updateLightNoCheck(light_at_pos);
|
||||||
}
|
}
|
||||||
@ -1046,9 +1042,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
|
|||||||
|
|
||||||
// Attachments, part 1: All attached objects must be unparented first,
|
// Attachments, part 1: All attached objects must be unparented first,
|
||||||
// or Irrlicht causes a segmentation fault
|
// or Irrlicht causes a segmentation fault
|
||||||
for(std::vector<u16>::iterator ci = m_children.begin();
|
for (auto ci = m_children.begin(); ci != m_children.end();) {
|
||||||
ci != m_children.end();)
|
|
||||||
{
|
|
||||||
if (m_env->attachement_parent_ids[*ci] != getId()) {
|
if (m_env->attachement_parent_ids[*ci] != getId()) {
|
||||||
ci = m_children.erase(ci);
|
ci = m_children.erase(ci);
|
||||||
continue;
|
continue;
|
||||||
@ -1066,9 +1060,9 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
|
|||||||
addToScene(m_client->tsrc());
|
addToScene(m_client->tsrc());
|
||||||
|
|
||||||
// Attachments, part 2: Now that the parent has been refreshed, put its attachments back
|
// Attachments, part 2: Now that the parent has been refreshed, put its attachments back
|
||||||
for (std::vector<u16>::size_type i = 0; i < m_children.size(); i++) {
|
for (u16 cao_id : m_children) {
|
||||||
// Get the object of the child
|
// Get the object of the child
|
||||||
ClientActiveObject *obj = m_env->getActiveObject(m_children[i]);
|
ClientActiveObject *obj = m_env->getActiveObject(cao_id);
|
||||||
if (obj)
|
if (obj)
|
||||||
obj->setAttachments();
|
obj->setAttachments();
|
||||||
}
|
}
|
||||||
@ -1248,12 +1242,10 @@ void GenericCAO::updateTextures(std::string mod)
|
|||||||
m_previous_texture_modifier = m_current_texture_modifier;
|
m_previous_texture_modifier = m_current_texture_modifier;
|
||||||
m_current_texture_modifier = mod;
|
m_current_texture_modifier = mod;
|
||||||
|
|
||||||
if(m_spritenode)
|
if (m_spritenode) {
|
||||||
{
|
if (m_prop.visual == "sprite") {
|
||||||
if(m_prop.visual == "sprite")
|
|
||||||
{
|
|
||||||
std::string texturestring = "unknown_node.png";
|
std::string texturestring = "unknown_node.png";
|
||||||
if(m_prop.textures.size() >= 1)
|
if (!m_prop.textures.empty())
|
||||||
texturestring = m_prop.textures[0];
|
texturestring = m_prop.textures[0];
|
||||||
texturestring += mod;
|
texturestring += mod;
|
||||||
m_spritenode->setMaterialTexture(0,
|
m_spritenode->setMaterialTexture(0,
|
||||||
@ -1262,8 +1254,7 @@ void GenericCAO::updateTextures(std::string mod)
|
|||||||
// This allows setting per-material colors. However, until a real lighting
|
// This allows setting per-material colors. However, until a real lighting
|
||||||
// system is added, the code below will have no effect. Once MineTest
|
// system is added, the code below will have no effect. Once MineTest
|
||||||
// has directional lighting, it should work automatically.
|
// has directional lighting, it should work automatically.
|
||||||
if(m_prop.colors.size() >= 1)
|
if (!m_prop.colors.empty()) {
|
||||||
{
|
|
||||||
m_spritenode->getMaterial(0).AmbientColor = m_prop.colors[0];
|
m_spritenode->getMaterial(0).AmbientColor = m_prop.colors[0];
|
||||||
m_spritenode->getMaterial(0).DiffuseColor = m_prop.colors[0];
|
m_spritenode->getMaterial(0).DiffuseColor = m_prop.colors[0];
|
||||||
m_spritenode->getMaterial(0).SpecularColor = m_prop.colors[0];
|
m_spritenode->getMaterial(0).SpecularColor = m_prop.colors[0];
|
||||||
@ -1274,20 +1265,17 @@ void GenericCAO::updateTextures(std::string mod)
|
|||||||
m_spritenode->getMaterial(0).setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
|
m_spritenode->getMaterial(0).setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(m_animated_meshnode)
|
|
||||||
{
|
if (m_animated_meshnode) {
|
||||||
if(m_prop.visual == "mesh")
|
if (m_prop.visual == "mesh") {
|
||||||
{
|
|
||||||
for (u32 i = 0; i < m_prop.textures.size() &&
|
for (u32 i = 0; i < m_prop.textures.size() &&
|
||||||
i < m_animated_meshnode->getMaterialCount(); ++i)
|
i < m_animated_meshnode->getMaterialCount(); ++i) {
|
||||||
{
|
|
||||||
std::string texturestring = m_prop.textures[i];
|
std::string texturestring = m_prop.textures[i];
|
||||||
if(texturestring == "")
|
if (texturestring.empty())
|
||||||
continue; // Empty texture string means don't modify that material
|
continue; // Empty texture string means don't modify that material
|
||||||
texturestring += mod;
|
texturestring += mod;
|
||||||
video::ITexture* texture = tsrc->getTextureForMesh(texturestring);
|
video::ITexture* texture = tsrc->getTextureForMesh(texturestring);
|
||||||
if(!texture)
|
if (!texture) {
|
||||||
{
|
|
||||||
errorstream<<"GenericCAO::updateTextures(): Could not load texture "<<texturestring<<std::endl;
|
errorstream<<"GenericCAO::updateTextures(): Could not load texture "<<texturestring<<std::endl;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1351,13 +1339,11 @@ void GenericCAO::updateTextures(std::string mod)
|
|||||||
m_meshnode->getMaterial(i).setFlag(video::EMF_BILINEAR_FILTER, use_bilinear_filter);
|
m_meshnode->getMaterial(i).setFlag(video::EMF_BILINEAR_FILTER, use_bilinear_filter);
|
||||||
m_meshnode->getMaterial(i).setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
|
m_meshnode->getMaterial(i).setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
|
||||||
}
|
}
|
||||||
}
|
} else if (m_prop.visual == "upright_sprite") {
|
||||||
else if(m_prop.visual == "upright_sprite")
|
|
||||||
{
|
|
||||||
scene::IMesh *mesh = m_meshnode->getMesh();
|
scene::IMesh *mesh = m_meshnode->getMesh();
|
||||||
{
|
{
|
||||||
std::string tname = "unknown_object.png";
|
std::string tname = "unknown_object.png";
|
||||||
if(m_prop.textures.size() >= 1)
|
if (!m_prop.textures.empty())
|
||||||
tname = m_prop.textures[0];
|
tname = m_prop.textures[0];
|
||||||
tname += mod;
|
tname += mod;
|
||||||
scene::IMeshBuffer *buf = mesh->getMeshBuffer(0);
|
scene::IMeshBuffer *buf = mesh->getMeshBuffer(0);
|
||||||
@ -1367,8 +1353,7 @@ void GenericCAO::updateTextures(std::string mod)
|
|||||||
// This allows setting per-material colors. However, until a real lighting
|
// This allows setting per-material colors. However, until a real lighting
|
||||||
// system is added, the code below will have no effect. Once MineTest
|
// system is added, the code below will have no effect. Once MineTest
|
||||||
// has directional lighting, it should work automatically.
|
// has directional lighting, it should work automatically.
|
||||||
if(m_prop.colors.size() >= 1)
|
if(!m_prop.colors.empty()) {
|
||||||
{
|
|
||||||
buf->getMaterial().AmbientColor = m_prop.colors[0];
|
buf->getMaterial().AmbientColor = m_prop.colors[0];
|
||||||
buf->getMaterial().DiffuseColor = m_prop.colors[0];
|
buf->getMaterial().DiffuseColor = m_prop.colors[0];
|
||||||
buf->getMaterial().SpecularColor = m_prop.colors[0];
|
buf->getMaterial().SpecularColor = m_prop.colors[0];
|
||||||
@ -1380,9 +1365,9 @@ void GenericCAO::updateTextures(std::string mod)
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
std::string tname = "unknown_object.png";
|
std::string tname = "unknown_object.png";
|
||||||
if(m_prop.textures.size() >= 2)
|
if (m_prop.textures.size() >= 2)
|
||||||
tname = m_prop.textures[1];
|
tname = m_prop.textures[1];
|
||||||
else if(m_prop.textures.size() >= 1)
|
else if (!m_prop.textures.empty())
|
||||||
tname = m_prop.textures[0];
|
tname = m_prop.textures[0];
|
||||||
tname += mod;
|
tname += mod;
|
||||||
scene::IMeshBuffer *buf = mesh->getMeshBuffer(1);
|
scene::IMeshBuffer *buf = mesh->getMeshBuffer(1);
|
||||||
@ -1392,14 +1377,11 @@ void GenericCAO::updateTextures(std::string mod)
|
|||||||
// This allows setting per-material colors. However, until a real lighting
|
// This allows setting per-material colors. However, until a real lighting
|
||||||
// system is added, the code below will have no effect. Once MineTest
|
// system is added, the code below will have no effect. Once MineTest
|
||||||
// has directional lighting, it should work automatically.
|
// has directional lighting, it should work automatically.
|
||||||
if(m_prop.colors.size() >= 2)
|
if (m_prop.colors.size() >= 2) {
|
||||||
{
|
|
||||||
buf->getMaterial().AmbientColor = m_prop.colors[1];
|
buf->getMaterial().AmbientColor = m_prop.colors[1];
|
||||||
buf->getMaterial().DiffuseColor = m_prop.colors[1];
|
buf->getMaterial().DiffuseColor = m_prop.colors[1];
|
||||||
buf->getMaterial().SpecularColor = m_prop.colors[1];
|
buf->getMaterial().SpecularColor = m_prop.colors[1];
|
||||||
}
|
} else if (!m_prop.colors.empty()) {
|
||||||
else if(m_prop.colors.size() >= 1)
|
|
||||||
{
|
|
||||||
buf->getMaterial().AmbientColor = m_prop.colors[0];
|
buf->getMaterial().AmbientColor = m_prop.colors[0];
|
||||||
buf->getMaterial().DiffuseColor = m_prop.colors[0];
|
buf->getMaterial().DiffuseColor = m_prop.colors[0];
|
||||||
buf->getMaterial().SpecularColor = m_prop.colors[0];
|
buf->getMaterial().SpecularColor = m_prop.colors[0];
|
||||||
@ -1476,7 +1458,7 @@ void GenericCAO::updateAttachments()
|
|||||||
scene::ISceneNode *parent_node = getParent()->getSceneNode();
|
scene::ISceneNode *parent_node = getParent()->getSceneNode();
|
||||||
scene::IAnimatedMeshSceneNode *parent_animated_mesh_node =
|
scene::IAnimatedMeshSceneNode *parent_animated_mesh_node =
|
||||||
getParent()->getAnimatedMeshSceneNode();
|
getParent()->getAnimatedMeshSceneNode();
|
||||||
if (parent_animated_mesh_node && m_attachment_bone != "") {
|
if (parent_animated_mesh_node && !m_attachment_bone.empty()) {
|
||||||
parent_node = parent_animated_mesh_node->getJointNode(m_attachment_bone.c_str());
|
parent_node = parent_animated_mesh_node->getJointNode(m_attachment_bone.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1519,7 +1501,7 @@ void GenericCAO::processMessage(const std::string &data)
|
|||||||
player->setCollisionbox(m_selection_box);
|
player->setCollisionbox(m_selection_box);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((m_is_player && !m_is_local_player) && m_prop.nametag == "")
|
if ((m_is_player && !m_is_local_player) && m_prop.nametag.empty())
|
||||||
m_prop.nametag = m_name;
|
m_prop.nametag = m_name;
|
||||||
|
|
||||||
expireVisuals();
|
expireVisuals();
|
||||||
|
@ -40,11 +40,11 @@ struct SmoothTranslator
|
|||||||
v3f vect_show;
|
v3f vect_show;
|
||||||
v3f vect_aim;
|
v3f vect_aim;
|
||||||
f32 anim_counter = 0;
|
f32 anim_counter = 0;
|
||||||
f32 anim_time;
|
f32 anim_time = 0;
|
||||||
f32 anim_time_counter = 0;
|
f32 anim_time_counter = 0;
|
||||||
bool aim_is_end = true;
|
bool aim_is_end = true;
|
||||||
|
|
||||||
SmoothTranslator() {};
|
SmoothTranslator() = default;
|
||||||
|
|
||||||
void init(v3f vect);
|
void init(v3f vect);
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ class SmokePuffCSO: public ClientSimpleObject
|
|||||||
scene::IBillboardSceneNode *m_spritenode = nullptr;
|
scene::IBillboardSceneNode *m_spritenode = nullptr;
|
||||||
public:
|
public:
|
||||||
SmokePuffCSO(scene::ISceneManager *smgr,
|
SmokePuffCSO(scene::ISceneManager *smgr,
|
||||||
ClientEnvironment *env, v3f pos, v2f size)
|
ClientEnvironment *env, const v3f &pos, const v2f &size)
|
||||||
{
|
{
|
||||||
infostream<<"SmokePuffCSO: constructing"<<std::endl;
|
infostream<<"SmokePuffCSO: constructing"<<std::endl;
|
||||||
m_spritenode = smgr->addBillboardSceneNode(
|
m_spritenode = smgr->addBillboardSceneNode(
|
||||||
|
@ -28,7 +28,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include <IMeshManipulator.h>
|
#include <IMeshManipulator.h>
|
||||||
#include "client/renderingengine.h"
|
#include "client/renderingengine.h"
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
#include "log.h"
|
|
||||||
#include "noise.h"
|
#include "noise.h"
|
||||||
|
|
||||||
// Distance of light extrapolation (for oversized nodes)
|
// Distance of light extrapolation (for oversized nodes)
|
||||||
@ -81,9 +80,10 @@ void MapblockMeshGenerator::useTile(int index, u8 set_flags, u8 reset_flags, boo
|
|||||||
getNodeTileN(n, p, index, data, tile);
|
getNodeTileN(n, p, index, data, tile);
|
||||||
if (!data->m_smooth_lighting)
|
if (!data->m_smooth_lighting)
|
||||||
color = encode_light(light, f->light_source);
|
color = encode_light(light, f->light_source);
|
||||||
for (int layer = 0; layer < MAX_TILE_LAYERS; layer++) {
|
|
||||||
tile.layers[layer].material_flags |= set_flags;
|
for (auto &layer : tile.layers) {
|
||||||
tile.layers[layer].material_flags &= ~reset_flags;
|
layer.material_flags |= set_flags;
|
||||||
|
layer.material_flags &= ~reset_flags;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,14 +99,16 @@ void MapblockMeshGenerator::getSpecialTile(int index, TileSpec *tile, bool apply
|
|||||||
{
|
{
|
||||||
*tile = f->special_tiles[index];
|
*tile = f->special_tiles[index];
|
||||||
TileLayer *top_layer = NULL;
|
TileLayer *top_layer = NULL;
|
||||||
for (int layernum = 0; layernum < MAX_TILE_LAYERS; layernum++) {
|
|
||||||
TileLayer *layer = &tile->layers[layernum];
|
for (auto &layernum : tile->layers) {
|
||||||
|
TileLayer *layer = &layernum;
|
||||||
if (layer->texture_id == 0)
|
if (layer->texture_id == 0)
|
||||||
continue;
|
continue;
|
||||||
top_layer = layer;
|
top_layer = layer;
|
||||||
if (!layer->has_color)
|
if (!layer->has_color)
|
||||||
n.getColor(*f, &layer->color);
|
n.getColor(*f, &layer->color);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (apply_crack)
|
if (apply_crack)
|
||||||
top_layer->material_flags |= MATERIAL_FLAG_CRACK;
|
top_layer->material_flags |= MATERIAL_FLAG_CRACK;
|
||||||
}
|
}
|
||||||
@ -502,8 +504,8 @@ void MapblockMeshGenerator::drawLiquidSides()
|
|||||||
{1, 0},
|
{1, 0},
|
||||||
{0, 0}
|
{0, 0}
|
||||||
};
|
};
|
||||||
for (int i = 0; i < 4; i++) {
|
|
||||||
const LiquidFaceDesc &face = base_faces[i];
|
for (const auto &face : base_faces) {
|
||||||
const NeighborData &neighbor = liquid_neighbors[face.dir.Z + 1][face.dir.X + 1];
|
const NeighborData &neighbor = liquid_neighbors[face.dir.Z + 1][face.dir.X + 1];
|
||||||
|
|
||||||
// No face between nodes of the same liquid, unless there is node
|
// No face between nodes of the same liquid, unless there is node
|
||||||
@ -580,9 +582,9 @@ void MapblockMeshGenerator::drawLiquidTop()
|
|||||||
tcoord_translate.X -= floor(tcoord_translate.X);
|
tcoord_translate.X -= floor(tcoord_translate.X);
|
||||||
tcoord_translate.Y -= floor(tcoord_translate.Y);
|
tcoord_translate.Y -= floor(tcoord_translate.Y);
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++) {
|
for (auto &vertice : vertices) {
|
||||||
vertices[i].TCoords.rotateBy(tcoord_angle, tcoord_center);
|
vertice.TCoords.rotateBy(tcoord_angle, tcoord_center);
|
||||||
vertices[i].TCoords += tcoord_translate;
|
vertice.TCoords += tcoord_translate;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::swap(vertices[0].TCoords, vertices[2].TCoords);
|
std::swap(vertices[0].TCoords, vertices[2].TCoords);
|
||||||
@ -619,14 +621,21 @@ void MapblockMeshGenerator::drawGlasslikeNode()
|
|||||||
v3f( BS / 2, -BS / 2, -BS / 2),
|
v3f( BS / 2, -BS / 2, -BS / 2),
|
||||||
v3f(-BS / 2, -BS / 2, -BS / 2),
|
v3f(-BS / 2, -BS / 2, -BS / 2),
|
||||||
};
|
};
|
||||||
for (int i = 0; i < 4; i++) {
|
|
||||||
|
for (auto &vertice : vertices) {
|
||||||
switch (face) {
|
switch (face) {
|
||||||
case D6D_ZP: vertices[i].rotateXZBy(180); break;
|
case D6D_ZP:
|
||||||
case D6D_YP: vertices[i].rotateYZBy( 90); break;
|
vertice.rotateXZBy(180); break;
|
||||||
case D6D_XP: vertices[i].rotateXZBy( 90); break;
|
case D6D_YP:
|
||||||
case D6D_ZN: vertices[i].rotateXZBy( 0); break;
|
vertice.rotateYZBy( 90); break;
|
||||||
case D6D_YN: vertices[i].rotateYZBy(-90); break;
|
case D6D_XP:
|
||||||
case D6D_XN: vertices[i].rotateXZBy(-90); break;
|
vertice.rotateXZBy( 90); break;
|
||||||
|
case D6D_ZN:
|
||||||
|
vertice.rotateXZBy( 0); break;
|
||||||
|
case D6D_YN:
|
||||||
|
vertice.rotateYZBy(-90); break;
|
||||||
|
case D6D_XN:
|
||||||
|
vertice.rotateXZBy(-90); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
drawQuad(vertices, dir);
|
drawQuad(vertices, dir);
|
||||||
@ -650,8 +659,8 @@ void MapblockMeshGenerator::drawGlasslikeFramedNode()
|
|||||||
glass_tiles[4] = tiles[3];
|
glass_tiles[4] = tiles[3];
|
||||||
glass_tiles[5] = tiles[4];
|
glass_tiles[5] = tiles[4];
|
||||||
} else {
|
} else {
|
||||||
for (int face = 0; face < 6; face++)
|
for (auto &glass_tile : glass_tiles)
|
||||||
glass_tiles[face] = tiles[4];
|
glass_tile = tiles[4];
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 param2 = n.getParam2();
|
u8 param2 = n.getParam2();
|
||||||
@ -785,14 +794,21 @@ void MapblockMeshGenerator::drawTorchlikeNode()
|
|||||||
v3f( size, -size, 0),
|
v3f( size, -size, 0),
|
||||||
v3f(-size, -size, 0),
|
v3f(-size, -size, 0),
|
||||||
};
|
};
|
||||||
for (int i = 0; i < 4; i++) {
|
|
||||||
|
for (auto &vertice : vertices) {
|
||||||
switch (wall) {
|
switch (wall) {
|
||||||
case DWM_YP: vertices[i].rotateXZBy(-45); break;
|
case DWM_YP:
|
||||||
case DWM_YN: vertices[i].rotateXZBy( 45); break;
|
vertice.rotateXZBy(-45); break;
|
||||||
case DWM_XP: vertices[i].rotateXZBy( 0); break;
|
case DWM_YN:
|
||||||
case DWM_XN: vertices[i].rotateXZBy(180); break;
|
vertice.rotateXZBy( 45); break;
|
||||||
case DWM_ZP: vertices[i].rotateXZBy( 90); break;
|
case DWM_XP:
|
||||||
case DWM_ZN: vertices[i].rotateXZBy(-90); break;
|
vertice.rotateXZBy( 0); break;
|
||||||
|
case DWM_XN:
|
||||||
|
vertice.rotateXZBy(180); break;
|
||||||
|
case DWM_ZP:
|
||||||
|
vertice.rotateXZBy( 90); break;
|
||||||
|
case DWM_ZN:
|
||||||
|
vertice.rotateXZBy(-90); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
drawQuad(vertices);
|
drawQuad(vertices);
|
||||||
@ -811,14 +827,21 @@ void MapblockMeshGenerator::drawSignlikeNode()
|
|||||||
v3f(BS / 2 - offset, -size, -size),
|
v3f(BS / 2 - offset, -size, -size),
|
||||||
v3f(BS / 2 - offset, -size, size),
|
v3f(BS / 2 - offset, -size, size),
|
||||||
};
|
};
|
||||||
for (int i = 0; i < 4; i++) {
|
|
||||||
|
for (auto &vertice : vertices) {
|
||||||
switch (wall) {
|
switch (wall) {
|
||||||
case DWM_YP: vertices[i].rotateXYBy( 90); break;
|
case DWM_YP:
|
||||||
case DWM_YN: vertices[i].rotateXYBy(-90); break;
|
vertice.rotateXYBy( 90); break;
|
||||||
case DWM_XP: vertices[i].rotateXZBy( 0); break;
|
case DWM_YN:
|
||||||
case DWM_XN: vertices[i].rotateXZBy(180); break;
|
vertice.rotateXYBy(-90); break;
|
||||||
case DWM_ZP: vertices[i].rotateXZBy( 90); break;
|
case DWM_XP:
|
||||||
case DWM_ZN: vertices[i].rotateXZBy(-90); break;
|
vertice.rotateXZBy( 0); break;
|
||||||
|
case DWM_XN:
|
||||||
|
vertice.rotateXZBy(180); break;
|
||||||
|
case DWM_ZP:
|
||||||
|
vertice.rotateXZBy( 90); break;
|
||||||
|
case DWM_ZN:
|
||||||
|
vertice.rotateXZBy(-90); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
drawQuad(vertices);
|
drawQuad(vertices);
|
||||||
@ -840,9 +863,10 @@ void MapblockMeshGenerator::drawPlantlikeQuad(float rotation, float quad_offset,
|
|||||||
int offset_count = offset_top_only ? 2 : 4;
|
int offset_count = offset_top_only ? 2 : 4;
|
||||||
for (int i = 0; i < offset_count; i++)
|
for (int i = 0; i < offset_count; i++)
|
||||||
vertices[i].Z += quad_offset;
|
vertices[i].Z += quad_offset;
|
||||||
for (int i = 0; i < 4; i++) {
|
|
||||||
vertices[i].rotateXZBy(rotation + rotate_degree);
|
for (auto &vertice : vertices) {
|
||||||
vertices[i] += offset;
|
vertice.rotateXZBy(rotation + rotate_degree);
|
||||||
|
vertice += offset;
|
||||||
}
|
}
|
||||||
drawQuad(vertices, v3s16(0, 0, 0), plant_height);
|
drawQuad(vertices, v3s16(0, 0, 0), plant_height);
|
||||||
}
|
}
|
||||||
@ -946,11 +970,12 @@ void MapblockMeshGenerator::drawFirelikeQuad(float rotation, float opening_angle
|
|||||||
v3f( scale, -BS / 2, 0),
|
v3f( scale, -BS / 2, 0),
|
||||||
v3f(-scale, -BS / 2, 0),
|
v3f(-scale, -BS / 2, 0),
|
||||||
};
|
};
|
||||||
for (int i = 0; i < 4; i++) {
|
|
||||||
vertices[i].rotateYZBy(opening_angle);
|
for (auto &vertice : vertices) {
|
||||||
vertices[i].Z += offset_h;
|
vertice.rotateYZBy(opening_angle);
|
||||||
vertices[i].rotateXZBy(rotation);
|
vertice.Z += offset_h;
|
||||||
vertices[i].Y += offset_v;
|
vertice.rotateXZBy(rotation);
|
||||||
|
vertice.Y += offset_v;
|
||||||
}
|
}
|
||||||
drawQuad(vertices);
|
drawQuad(vertices);
|
||||||
}
|
}
|
||||||
@ -1006,8 +1031,9 @@ void MapblockMeshGenerator::drawFencelikeNode()
|
|||||||
{
|
{
|
||||||
useTile(0, 0, 0);
|
useTile(0, 0, 0);
|
||||||
TileSpec tile_nocrack = tile;
|
TileSpec tile_nocrack = tile;
|
||||||
for (int layer = 0; layer < MAX_TILE_LAYERS; layer++)
|
|
||||||
tile_nocrack.layers[layer].material_flags &= ~MATERIAL_FLAG_CRACK;
|
for (auto &layer : tile_nocrack.layers)
|
||||||
|
layer.material_flags &= ~MATERIAL_FLAG_CRACK;
|
||||||
|
|
||||||
// Put wood the right way around in the posts
|
// Put wood the right way around in the posts
|
||||||
TileSpec tile_rot = tile;
|
TileSpec tile_rot = tile;
|
||||||
@ -1166,8 +1192,8 @@ void MapblockMeshGenerator::drawRaillikeNode()
|
|||||||
v3f(-size, -size + offset, -size),
|
v3f(-size, -size + offset, -size),
|
||||||
};
|
};
|
||||||
if (angle)
|
if (angle)
|
||||||
for (int i = 0; i < 4; i++)
|
for (auto &vertice : vertices)
|
||||||
vertices[i].rotateXZBy(angle);
|
vertice.rotateXZBy(angle);
|
||||||
drawQuad(vertices);
|
drawQuad(vertices);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1212,8 +1238,8 @@ void MapblockMeshGenerator::drawNodeboxNode()
|
|||||||
|
|
||||||
std::vector<aabb3f> boxes;
|
std::vector<aabb3f> boxes;
|
||||||
n.getNodeBoxes(nodedef, &boxes, neighbors_set);
|
n.getNodeBoxes(nodedef, &boxes, neighbors_set);
|
||||||
for (std::vector<aabb3f>::iterator i = boxes.begin(); i != boxes.end(); ++i)
|
for (const auto &box : boxes)
|
||||||
drawAutoLightedCuboid(*i, NULL, tiles, 6);
|
drawAutoLightedCuboid(box, NULL, tiles, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapblockMeshGenerator::drawMeshNode()
|
void MapblockMeshGenerator::drawMeshNode()
|
||||||
|
@ -108,11 +108,9 @@ MapNode mapnode_translate_to_internal(MapNode n_from, u8 version)
|
|||||||
if(version <= 19)
|
if(version <= 19)
|
||||||
{
|
{
|
||||||
content_t c_from = n_from.getContent();
|
content_t c_from = n_from.getContent();
|
||||||
for(u32 i=0; i<sizeof(trans_table_19)/sizeof(trans_table_19[0]); i++)
|
for (const auto &tt_i : trans_table_19) {
|
||||||
{
|
if (tt_i[1] == c_from) {
|
||||||
if(trans_table_19[i][1] == c_from)
|
result.setContent(tt_i[0]);
|
||||||
{
|
|
||||||
result.setContent(trans_table_19[i][0]);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ public:
|
|||||||
if(m_base_position.Y > 8*BS)
|
if(m_base_position.Y > 8*BS)
|
||||||
m_base_position.Y = 2*BS;
|
m_base_position.Y = 2*BS;
|
||||||
|
|
||||||
if(send_recommended == false)
|
if (!send_recommended)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_timer1 -= dtime;
|
m_timer1 -= dtime;
|
||||||
@ -402,7 +402,7 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(send_recommended == false)
|
if (!send_recommended)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(!isAttached())
|
if(!isAttached())
|
||||||
@ -423,7 +423,7 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_armor_groups_sent == false){
|
if (!m_armor_groups_sent) {
|
||||||
m_armor_groups_sent = true;
|
m_armor_groups_sent = true;
|
||||||
std::string str = gob_cmd_update_armor_groups(
|
std::string str = gob_cmd_update_armor_groups(
|
||||||
m_armor_groups);
|
m_armor_groups);
|
||||||
@ -432,7 +432,7 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
|
|||||||
m_messages_out.push(aom);
|
m_messages_out.push(aom);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_animation_sent == false){
|
if (!m_animation_sent) {
|
||||||
m_animation_sent = true;
|
m_animation_sent = true;
|
||||||
std::string str = gob_cmd_update_animation(
|
std::string str = gob_cmd_update_animation(
|
||||||
m_animation_range, m_animation_speed, m_animation_blend, m_animation_loop);
|
m_animation_range, m_animation_speed, m_animation_blend, m_animation_loop);
|
||||||
@ -441,7 +441,7 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
|
|||||||
m_messages_out.push(aom);
|
m_messages_out.push(aom);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_bone_position_sent == false){
|
if (!m_bone_position_sent) {
|
||||||
m_bone_position_sent = true;
|
m_bone_position_sent = true;
|
||||||
for (std::unordered_map<std::string, core::vector2d<v3f>>::const_iterator
|
for (std::unordered_map<std::string, core::vector2d<v3f>>::const_iterator
|
||||||
ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){
|
ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){
|
||||||
@ -453,7 +453,7 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_attachment_sent == false){
|
if (!m_attachment_sent) {
|
||||||
m_attachment_sent = true;
|
m_attachment_sent = true;
|
||||||
std::string str = gob_cmd_update_attachment(m_attachment_parent_id, m_attachment_bone, m_attachment_position, m_attachment_rotation);
|
std::string str = gob_cmd_update_attachment(m_attachment_parent_id, m_attachment_bone, m_attachment_position, m_attachment_rotation);
|
||||||
// create message and add to list
|
// create message and add to list
|
||||||
@ -897,7 +897,7 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
|
|||||||
return os.str();
|
return os.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerSAO::getStaticData(std::string *result) const
|
void PlayerSAO::getStaticData(std::string *) const
|
||||||
{
|
{
|
||||||
FATAL_ERROR("Deprecated function");
|
FATAL_ERROR("Deprecated function");
|
||||||
}
|
}
|
||||||
@ -1171,7 +1171,7 @@ int PlayerSAO::punch(v3f dir,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// No effect if PvP disabled
|
// No effect if PvP disabled
|
||||||
if (g_settings->getBool("enable_pvp") == false) {
|
if (!g_settings->getBool("enable_pvp")) {
|
||||||
if (puncher->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
|
if (puncher->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
|
||||||
std::string str = gob_cmd_punched(0, getHP());
|
std::string str = gob_cmd_punched(0, getHP());
|
||||||
// create message and add to list
|
// create message and add to list
|
||||||
|
@ -29,7 +29,7 @@ class UnitSAO: public ServerActiveObject
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UnitSAO(ServerEnvironment *env, v3f pos);
|
UnitSAO(ServerEnvironment *env, v3f pos);
|
||||||
virtual ~UnitSAO() {}
|
virtual ~UnitSAO() = default;
|
||||||
|
|
||||||
virtual void setYaw(const float yaw) { m_yaw = yaw; }
|
virtual void setYaw(const float yaw) { m_yaw = yaw; }
|
||||||
float getYaw() const { return m_yaw; };
|
float getYaw() const { return m_yaw; };
|
||||||
@ -156,7 +156,7 @@ class LagPool
|
|||||||
float m_pool = 15.0f;
|
float m_pool = 15.0f;
|
||||||
float m_max = 15.0f;
|
float m_max = 15.0f;
|
||||||
public:
|
public:
|
||||||
LagPool() {}
|
LagPool() = default;
|
||||||
|
|
||||||
void setMax(float new_max)
|
void setMax(float new_max)
|
||||||
{
|
{
|
||||||
@ -323,7 +323,7 @@ public:
|
|||||||
m_time_from_last_punch = 0.0;
|
m_time_from_last_punch = 0.0;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
void noCheatDigStart(v3s16 p)
|
void noCheatDigStart(const v3s16 &p)
|
||||||
{
|
{
|
||||||
m_nocheat_dig_pos = p;
|
m_nocheat_dig_pos = p;
|
||||||
m_nocheat_dig_time = 0;
|
m_nocheat_dig_time = 0;
|
||||||
|
183
src/craftdef.cpp
183
src/craftdef.cpp
@ -50,7 +50,7 @@ static u64 getHashForGrid(CraftHashType type, const std::vector<std::string> &gr
|
|||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
bool is_first = true;
|
bool is_first = true;
|
||||||
for (size_t i = 0; i < grid_names.size(); i++) {
|
for (size_t i = 0; i < grid_names.size(); i++) {
|
||||||
if (grid_names[i] != "") {
|
if (!grid_names[i].empty()) {
|
||||||
os << (is_first ? "" : "\n") << grid_names[i];
|
os << (is_first ? "" : "\n") << grid_names[i];
|
||||||
is_first = false;
|
is_first = false;
|
||||||
}
|
}
|
||||||
@ -59,7 +59,7 @@ static u64 getHashForGrid(CraftHashType type, const std::vector<std::string> &gr
|
|||||||
} case CRAFT_HASH_TYPE_COUNT: {
|
} case CRAFT_HASH_TYPE_COUNT: {
|
||||||
u64 cnt = 0;
|
u64 cnt = 0;
|
||||||
for (size_t i = 0; i < grid_names.size(); i++)
|
for (size_t i = 0; i < grid_names.size(); i++)
|
||||||
if (grid_names[i] != "")
|
if (!grid_names[i].empty())
|
||||||
cnt++;
|
cnt++;
|
||||||
return cnt;
|
return cnt;
|
||||||
} case CRAFT_HASH_TYPE_UNHASHED:
|
} case CRAFT_HASH_TYPE_UNHASHED:
|
||||||
@ -112,9 +112,8 @@ static std::vector<std::string> craftGetItemNames(
|
|||||||
const std::vector<std::string> &itemstrings, IGameDef *gamedef)
|
const std::vector<std::string> &itemstrings, IGameDef *gamedef)
|
||||||
{
|
{
|
||||||
std::vector<std::string> result;
|
std::vector<std::string> result;
|
||||||
for (std::vector<std::string>::size_type i = 0;
|
for (const auto &itemstring : itemstrings) {
|
||||||
i < itemstrings.size(); i++) {
|
result.push_back(craftGetItemName(itemstring, gamedef));
|
||||||
result.push_back(craftGetItemName(itemstrings[i], gamedef));
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -124,9 +123,8 @@ static std::vector<std::string> craftGetItemNames(
|
|||||||
const std::vector<ItemStack> &items, IGameDef *gamedef)
|
const std::vector<ItemStack> &items, IGameDef *gamedef)
|
||||||
{
|
{
|
||||||
std::vector<std::string> result;
|
std::vector<std::string> result;
|
||||||
for (std::vector<ItemStack>::size_type i = 0;
|
for (const auto &item : items) {
|
||||||
i < items.size(); i++) {
|
result.push_back(item.name);
|
||||||
result.push_back(items[i].name);
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -136,10 +134,9 @@ static std::vector<ItemStack> craftGetItems(
|
|||||||
const std::vector<std::string> &items, IGameDef *gamedef)
|
const std::vector<std::string> &items, IGameDef *gamedef)
|
||||||
{
|
{
|
||||||
std::vector<ItemStack> result;
|
std::vector<ItemStack> result;
|
||||||
for (std::vector<std::string>::size_type i = 0;
|
for (const auto &item : items) {
|
||||||
i < items.size(); i++) {
|
result.emplace_back(std::string(item), (u16)1,
|
||||||
result.push_back(ItemStack(std::string(items[i]), (u16)1,
|
(u16)0, gamedef->getItemDefManager());
|
||||||
(u16)0, gamedef->getItemDefManager()));
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -156,7 +153,7 @@ static bool craftGetBounds(const std::vector<std::string> &items, unsigned int w
|
|||||||
for (std::vector<std::string>::size_type i = 0;
|
for (std::vector<std::string>::size_type i = 0;
|
||||||
i < items.size(); i++) {
|
i < items.size(); i++) {
|
||||||
// Is this an actual item?
|
// Is this an actual item?
|
||||||
if (items[i] != "") {
|
if (!items[i].empty()) {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
// This is the first nonempty item
|
// This is the first nonempty item
|
||||||
min_x = max_x = x;
|
min_x = max_x = x;
|
||||||
@ -183,10 +180,9 @@ static bool craftGetBounds(const std::vector<std::string> &items, unsigned int w
|
|||||||
// Removes 1 from each item stack
|
// Removes 1 from each item stack
|
||||||
static void craftDecrementInput(CraftInput &input, IGameDef *gamedef)
|
static void craftDecrementInput(CraftInput &input, IGameDef *gamedef)
|
||||||
{
|
{
|
||||||
for (std::vector<ItemStack>::size_type i = 0;
|
for (auto &item : input.items) {
|
||||||
i < input.items.size(); i++) {
|
if (item.count != 0)
|
||||||
if (input.items[i].count != 0)
|
item.remove(1);
|
||||||
input.items[i].remove(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,28 +202,25 @@ static void craftDecrementOrReplaceInput(CraftInput &input,
|
|||||||
// Make a copy of the replacements pair list
|
// Make a copy of the replacements pair list
|
||||||
std::vector<std::pair<std::string, std::string> > pairs = replacements.pairs;
|
std::vector<std::pair<std::string, std::string> > pairs = replacements.pairs;
|
||||||
|
|
||||||
for (std::vector<ItemStack>::size_type i = 0;
|
for (auto &item : input.items) {
|
||||||
i < input.items.size(); i++) {
|
|
||||||
ItemStack &item = input.items[i];
|
|
||||||
// Find an appropriate replacement
|
// Find an appropriate replacement
|
||||||
bool found_replacement = false;
|
bool found_replacement = false;
|
||||||
for (std::vector<std::pair<std::string, std::string> >::iterator
|
for (auto j = pairs.begin(); j != pairs.end(); ++j) {
|
||||||
j = pairs.begin();
|
|
||||||
j != pairs.end(); ++j) {
|
|
||||||
if (inputItemMatchesRecipe(item.name, j->first, gamedef->idef())) {
|
if (inputItemMatchesRecipe(item.name, j->first, gamedef->idef())) {
|
||||||
if (item.count == 1) {
|
if (item.count == 1) {
|
||||||
item.deSerialize(j->second, gamedef->idef());
|
item.deSerialize(j->second, gamedef->idef());
|
||||||
found_replacement = true;
|
found_replacement = true;
|
||||||
pairs.erase(j);
|
pairs.erase(j);
|
||||||
break;
|
break;
|
||||||
} else {
|
|
||||||
ItemStack rep;
|
|
||||||
rep.deSerialize(j->second, gamedef->idef());
|
|
||||||
item.remove(1);
|
|
||||||
found_replacement = true;
|
|
||||||
output_replacements.push_back(rep);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ItemStack rep;
|
||||||
|
rep.deSerialize(j->second, gamedef->idef());
|
||||||
|
item.remove(1);
|
||||||
|
found_replacement = true;
|
||||||
|
output_replacements.push_back(rep);
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// No replacement was found, simply decrement count by one
|
// No replacement was found, simply decrement count by one
|
||||||
@ -311,9 +304,7 @@ std::string CraftReplacements::dump() const
|
|||||||
std::ostringstream os(std::ios::binary);
|
std::ostringstream os(std::ios::binary);
|
||||||
os<<"{";
|
os<<"{";
|
||||||
const char *sep = "";
|
const char *sep = "";
|
||||||
for (std::vector<std::pair<std::string, std::string> >::size_type i = 0;
|
for (const auto &repl_p : pairs) {
|
||||||
i < pairs.size(); i++) {
|
|
||||||
const std::pair<std::string, std::string> &repl_p = pairs[i];
|
|
||||||
os << sep
|
os << sep
|
||||||
<< '"' << (repl_p.first)
|
<< '"' << (repl_p.first)
|
||||||
<< "\"=>\"" << (repl_p.second) << '"';
|
<< "\"=>\"" << (repl_p.second) << '"';
|
||||||
@ -343,7 +334,7 @@ bool CraftDefinitionShaped::check(const CraftInput &input, IGameDef *gamedef) co
|
|||||||
if (inp_width == 0)
|
if (inp_width == 0)
|
||||||
return false;
|
return false;
|
||||||
while (inp_names.size() % inp_width != 0)
|
while (inp_names.size() % inp_width != 0)
|
||||||
inp_names.push_back("");
|
inp_names.emplace_back("");
|
||||||
|
|
||||||
// Get input bounds
|
// Get input bounds
|
||||||
unsigned int inp_min_x = 0, inp_max_x = 0, inp_min_y = 0, inp_max_y = 0;
|
unsigned int inp_min_x = 0, inp_max_x = 0, inp_min_y = 0, inp_max_y = 0;
|
||||||
@ -362,7 +353,7 @@ bool CraftDefinitionShaped::check(const CraftInput &input, IGameDef *gamedef) co
|
|||||||
if (rec_width == 0)
|
if (rec_width == 0)
|
||||||
return false;
|
return false;
|
||||||
while (rec_names.size() % rec_width != 0)
|
while (rec_names.size() % rec_width != 0)
|
||||||
rec_names.push_back("");
|
rec_names.emplace_back("");
|
||||||
|
|
||||||
// Get recipe bounds
|
// Get recipe bounds
|
||||||
unsigned int rec_min_x=0, rec_max_x=0, rec_min_y=0, rec_max_y=0;
|
unsigned int rec_min_x=0, rec_max_x=0, rec_min_y=0, rec_max_y=0;
|
||||||
@ -418,16 +409,16 @@ CraftHashType CraftDefinitionShaped::getHashType() const
|
|||||||
{
|
{
|
||||||
assert(hash_inited); // Pre-condition
|
assert(hash_inited); // Pre-condition
|
||||||
bool has_group = false;
|
bool has_group = false;
|
||||||
for (size_t i = 0; i < recipe_names.size(); i++) {
|
for (const auto &recipe_name : recipe_names) {
|
||||||
if (isGroupRecipeStr(recipe_names[i])) {
|
if (isGroupRecipeStr(recipe_name)) {
|
||||||
has_group = true;
|
has_group = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (has_group)
|
if (has_group)
|
||||||
return CRAFT_HASH_TYPE_COUNT;
|
return CRAFT_HASH_TYPE_COUNT;
|
||||||
else
|
|
||||||
return CRAFT_HASH_TYPE_ITEM_NAMES;
|
return CRAFT_HASH_TYPE_ITEM_NAMES;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 CraftDefinitionShaped::getHash(CraftHashType type) const
|
u64 CraftDefinitionShaped::getHash(CraftHashType type) const
|
||||||
@ -474,10 +465,8 @@ bool CraftDefinitionShapeless::check(const CraftInput &input, IGameDef *gamedef)
|
|||||||
|
|
||||||
// Filter empty items out of input
|
// Filter empty items out of input
|
||||||
std::vector<std::string> input_filtered;
|
std::vector<std::string> input_filtered;
|
||||||
for (std::vector<ItemStack>::size_type i = 0;
|
for (const auto &item : input.items) {
|
||||||
i < input.items.size(); i++) {
|
if (!item.name.empty())
|
||||||
const ItemStack &item = input.items[i];
|
|
||||||
if (item.name != "")
|
|
||||||
input_filtered.push_back(item.name);
|
input_filtered.push_back(item.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -540,16 +529,16 @@ CraftHashType CraftDefinitionShapeless::getHashType() const
|
|||||||
{
|
{
|
||||||
assert(hash_inited); // Pre-condition
|
assert(hash_inited); // Pre-condition
|
||||||
bool has_group = false;
|
bool has_group = false;
|
||||||
for (size_t i = 0; i < recipe_names.size(); i++) {
|
for (const auto &recipe_name : recipe_names) {
|
||||||
if (isGroupRecipeStr(recipe_names[i])) {
|
if (isGroupRecipeStr(recipe_name)) {
|
||||||
has_group = true;
|
has_group = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (has_group)
|
if (has_group)
|
||||||
return CRAFT_HASH_TYPE_COUNT;
|
return CRAFT_HASH_TYPE_COUNT;
|
||||||
else
|
|
||||||
return CRAFT_HASH_TYPE_ITEM_NAMES;
|
return CRAFT_HASH_TYPE_ITEM_NAMES;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 CraftDefinitionShapeless::getHash(CraftHashType type) const
|
u64 CraftDefinitionShapeless::getHash(CraftHashType type) const
|
||||||
@ -622,9 +611,7 @@ bool CraftDefinitionToolRepair::check(const CraftInput &input, IGameDef *gamedef
|
|||||||
|
|
||||||
ItemStack item1;
|
ItemStack item1;
|
||||||
ItemStack item2;
|
ItemStack item2;
|
||||||
for (std::vector<ItemStack>::size_type i = 0;
|
for (const auto &item : input.items) {
|
||||||
i < input.items.size(); i++) {
|
|
||||||
const ItemStack &item = input.items[i];
|
|
||||||
if (!item.empty()) {
|
if (!item.empty()) {
|
||||||
if (item1.empty())
|
if (item1.empty())
|
||||||
item1 = item;
|
item1 = item;
|
||||||
@ -642,9 +629,7 @@ CraftOutput CraftDefinitionToolRepair::getOutput(const CraftInput &input, IGameD
|
|||||||
{
|
{
|
||||||
ItemStack item1;
|
ItemStack item1;
|
||||||
ItemStack item2;
|
ItemStack item2;
|
||||||
for (std::vector<ItemStack>::size_type i = 0;
|
for (const auto &item : input.items) {
|
||||||
i < input.items.size(); i++) {
|
|
||||||
const ItemStack &item = input.items[i];
|
|
||||||
if (!item.empty()) {
|
if (!item.empty()) {
|
||||||
if (item1.empty())
|
if (item1.empty())
|
||||||
item1 = item;
|
item1 = item;
|
||||||
@ -659,7 +644,7 @@ CraftOutput CraftDefinitionToolRepair::getOutput(const CraftInput &input, IGameD
|
|||||||
CraftInput CraftDefinitionToolRepair::getInput(const CraftOutput &output, IGameDef *gamedef) const
|
CraftInput CraftDefinitionToolRepair::getInput(const CraftOutput &output, IGameDef *gamedef) const
|
||||||
{
|
{
|
||||||
std::vector<ItemStack> stack;
|
std::vector<ItemStack> stack;
|
||||||
stack.push_back(ItemStack());
|
stack.emplace_back();
|
||||||
return CraftInput(CRAFT_METHOD_COOKING, additional_wear, stack);
|
return CraftInput(CRAFT_METHOD_COOKING, additional_wear, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -692,10 +677,9 @@ bool CraftDefinitionCooking::check(const CraftInput &input, IGameDef *gamedef) c
|
|||||||
|
|
||||||
// Filter empty items out of input
|
// Filter empty items out of input
|
||||||
std::vector<std::string> input_filtered;
|
std::vector<std::string> input_filtered;
|
||||||
for (std::vector<ItemStack>::size_type i = 0;
|
for (const auto &item : input.items) {
|
||||||
i < input.items.size(); i++) {
|
const std::string &name = item.name;
|
||||||
const std::string &name = input.items[i].name;
|
if (!name.empty())
|
||||||
if (name != "")
|
|
||||||
input_filtered.push_back(name);
|
input_filtered.push_back(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -733,15 +717,16 @@ CraftHashType CraftDefinitionCooking::getHashType() const
|
|||||||
{
|
{
|
||||||
if (isGroupRecipeStr(recipe_name))
|
if (isGroupRecipeStr(recipe_name))
|
||||||
return CRAFT_HASH_TYPE_COUNT;
|
return CRAFT_HASH_TYPE_COUNT;
|
||||||
else
|
|
||||||
return CRAFT_HASH_TYPE_ITEM_NAMES;
|
return CRAFT_HASH_TYPE_ITEM_NAMES;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 CraftDefinitionCooking::getHash(CraftHashType type) const
|
u64 CraftDefinitionCooking::getHash(CraftHashType type) const
|
||||||
{
|
{
|
||||||
if (type == CRAFT_HASH_TYPE_ITEM_NAMES) {
|
if (type == CRAFT_HASH_TYPE_ITEM_NAMES) {
|
||||||
return getHashForString(recipe_name);
|
return getHashForString(recipe_name);
|
||||||
} else if (type == CRAFT_HASH_TYPE_COUNT) {
|
}
|
||||||
|
if (type == CRAFT_HASH_TYPE_COUNT) {
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
//illegal hash type for this CraftDefinition (pre-condition)
|
//illegal hash type for this CraftDefinition (pre-condition)
|
||||||
@ -784,10 +769,9 @@ bool CraftDefinitionFuel::check(const CraftInput &input, IGameDef *gamedef) cons
|
|||||||
|
|
||||||
// Filter empty items out of input
|
// Filter empty items out of input
|
||||||
std::vector<std::string> input_filtered;
|
std::vector<std::string> input_filtered;
|
||||||
for (std::vector<ItemStack>::size_type i = 0;
|
for (const auto &item : input.items) {
|
||||||
i < input.items.size(); i++) {
|
const std::string &name = item.name;
|
||||||
const std::string &name = input.items[i].name;
|
if (!name.empty())
|
||||||
if (name != "")
|
|
||||||
input_filtered.push_back(name);
|
input_filtered.push_back(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -825,15 +809,17 @@ CraftHashType CraftDefinitionFuel::getHashType() const
|
|||||||
{
|
{
|
||||||
if (isGroupRecipeStr(recipe_name))
|
if (isGroupRecipeStr(recipe_name))
|
||||||
return CRAFT_HASH_TYPE_COUNT;
|
return CRAFT_HASH_TYPE_COUNT;
|
||||||
else
|
|
||||||
return CRAFT_HASH_TYPE_ITEM_NAMES;
|
return CRAFT_HASH_TYPE_ITEM_NAMES;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 CraftDefinitionFuel::getHash(CraftHashType type) const
|
u64 CraftDefinitionFuel::getHash(CraftHashType type) const
|
||||||
{
|
{
|
||||||
if (type == CRAFT_HASH_TYPE_ITEM_NAMES) {
|
if (type == CRAFT_HASH_TYPE_ITEM_NAMES) {
|
||||||
return getHashForString(recipe_name);
|
return getHashForString(recipe_name);
|
||||||
} else if (type == CRAFT_HASH_TYPE_COUNT) {
|
}
|
||||||
|
|
||||||
|
if (type == CRAFT_HASH_TYPE_COUNT) {
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
//illegal hash type for this CraftDefinition (pre-condition)
|
//illegal hash type for this CraftDefinition (pre-condition)
|
||||||
@ -884,9 +870,8 @@ public:
|
|||||||
|
|
||||||
// If all input items are empty, abort.
|
// If all input items are empty, abort.
|
||||||
bool all_empty = true;
|
bool all_empty = true;
|
||||||
for (std::vector<ItemStack>::size_type i = 0;
|
for (const auto &item : input.items) {
|
||||||
i < input.items.size(); i++) {
|
if (!item.empty()) {
|
||||||
if (!input.items[i].empty()) {
|
|
||||||
all_empty = false;
|
all_empty = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -906,8 +891,7 @@ public:
|
|||||||
|
|
||||||
// We'd like to do "const [...] hash_collisions = m_craft_defs[type][hash];"
|
// We'd like to do "const [...] hash_collisions = m_craft_defs[type][hash];"
|
||||||
// but that doesn't compile for some reason. This does.
|
// but that doesn't compile for some reason. This does.
|
||||||
std::map<u64, std::vector<CraftDefinition*> >::const_iterator
|
auto col_iter = (m_craft_defs[type]).find(hash);
|
||||||
col_iter = (m_craft_defs[type]).find(hash);
|
|
||||||
|
|
||||||
if (col_iter == (m_craft_defs[type]).end())
|
if (col_iter == (m_craft_defs[type]).end())
|
||||||
continue;
|
continue;
|
||||||
@ -940,8 +924,7 @@ public:
|
|||||||
{
|
{
|
||||||
std::vector<CraftDefinition*> recipes;
|
std::vector<CraftDefinition*> recipes;
|
||||||
|
|
||||||
std::map<std::string, std::vector<CraftDefinition*> >::const_iterator
|
auto vec_iter = m_output_craft_definitions.find(output.item);
|
||||||
vec_iter = m_output_craft_definitions.find(output.item);
|
|
||||||
|
|
||||||
if (vec_iter == m_output_craft_definitions.end())
|
if (vec_iter == m_output_craft_definitions.end())
|
||||||
return recipes;
|
return recipes;
|
||||||
@ -963,26 +946,22 @@ public:
|
|||||||
|
|
||||||
virtual bool clearCraftRecipesByOutput(const CraftOutput &output, IGameDef *gamedef)
|
virtual bool clearCraftRecipesByOutput(const CraftOutput &output, IGameDef *gamedef)
|
||||||
{
|
{
|
||||||
std::map<std::string, std::vector<CraftDefinition*> >::iterator vec_iter =
|
auto vec_iter = m_output_craft_definitions.find(output.item);
|
||||||
m_output_craft_definitions.find(output.item);
|
|
||||||
|
|
||||||
if (vec_iter == m_output_craft_definitions.end())
|
if (vec_iter == m_output_craft_definitions.end())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
std::vector<CraftDefinition*> &vec = vec_iter->second;
|
std::vector<CraftDefinition*> &vec = vec_iter->second;
|
||||||
for (std::vector<CraftDefinition*>::iterator i = vec.begin();
|
for (auto def : vec) {
|
||||||
i != vec.end(); ++i) {
|
|
||||||
CraftDefinition *def = *i;
|
|
||||||
// Recipes are not yet hashed at this point
|
// Recipes are not yet hashed at this point
|
||||||
std::vector<CraftDefinition*> &unhashed_inputs_vec = m_craft_defs[(int) CRAFT_HASH_TYPE_UNHASHED][0];
|
std::vector<CraftDefinition*> &unhashed_inputs_vec = m_craft_defs[(int) CRAFT_HASH_TYPE_UNHASHED][0];
|
||||||
std::vector<CraftDefinition*> new_vec_by_input;
|
std::vector<CraftDefinition*> new_vec_by_input;
|
||||||
/* We will preallocate necessary memory addresses, so we don't need to reallocate them later.
|
/* We will preallocate necessary memory addresses, so we don't need to reallocate them later.
|
||||||
This would save us some performance. */
|
This would save us some performance. */
|
||||||
new_vec_by_input.reserve(unhashed_inputs_vec.size());
|
new_vec_by_input.reserve(unhashed_inputs_vec.size());
|
||||||
for (std::vector<CraftDefinition*>::iterator i2 = unhashed_inputs_vec.begin();
|
for (auto &i2 : unhashed_inputs_vec) {
|
||||||
i2 != unhashed_inputs_vec.end(); ++i2) {
|
if (def != i2) {
|
||||||
if (def != *i2) {
|
new_vec_by_input.push_back(i2);
|
||||||
new_vec_by_input.push_back(*i2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_craft_defs[(int) CRAFT_HASH_TYPE_UNHASHED][0].swap(new_vec_by_input);
|
m_craft_defs[(int) CRAFT_HASH_TYPE_UNHASHED][0].swap(new_vec_by_input);
|
||||||
@ -995,9 +974,8 @@ public:
|
|||||||
const std::vector<std::string> &recipe, IGameDef *gamedef)
|
const std::vector<std::string> &recipe, IGameDef *gamedef)
|
||||||
{
|
{
|
||||||
bool all_empty = true;
|
bool all_empty = true;
|
||||||
for (std::vector<std::string>::size_type i = 0;
|
for (const auto &i : recipe) {
|
||||||
i < recipe.size(); i++) {
|
if (!i.empty()) {
|
||||||
if (!recipe[i].empty()) {
|
|
||||||
all_empty = false;
|
all_empty = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1021,8 +999,7 @@ public:
|
|||||||
}
|
}
|
||||||
CraftOutput output = def->getOutput(input, gamedef);
|
CraftOutput output = def->getOutput(input, gamedef);
|
||||||
got_hit = true;
|
got_hit = true;
|
||||||
std::map<std::string, std::vector<CraftDefinition*> >::iterator
|
auto vec_iter = m_output_craft_definitions.find(output.item);
|
||||||
vec_iter = m_output_craft_definitions.find(output.item);
|
|
||||||
if (vec_iter == m_output_craft_definitions.end())
|
if (vec_iter == m_output_craft_definitions.end())
|
||||||
continue;
|
continue;
|
||||||
std::vector<CraftDefinition*> &vec = vec_iter->second;
|
std::vector<CraftDefinition*> &vec = vec_iter->second;
|
||||||
@ -1030,14 +1007,13 @@ public:
|
|||||||
/* We will preallocate necessary memory addresses, so we don't need
|
/* We will preallocate necessary memory addresses, so we don't need
|
||||||
to reallocate them later. This would save us some performance. */
|
to reallocate them later. This would save us some performance. */
|
||||||
new_vec_by_output.reserve(vec.size());
|
new_vec_by_output.reserve(vec.size());
|
||||||
for (std::vector<CraftDefinition*>::iterator i = vec.begin();
|
for (auto &vec_i : vec) {
|
||||||
i != vec.end(); ++i) {
|
|
||||||
/* If pointers from map by input and output are not same,
|
/* If pointers from map by input and output are not same,
|
||||||
we will add 'CraftDefinition*' to a new vector. */
|
we will add 'CraftDefinition*' to a new vector. */
|
||||||
if (def != *i) {
|
if (def != vec_i) {
|
||||||
/* Adding dereferenced iterator value (which are
|
/* Adding dereferenced iterator value (which are
|
||||||
'CraftDefinition' reference) to a new vector. */
|
'CraftDefinition' reference) to a new vector. */
|
||||||
new_vec_by_output.push_back(*i);
|
new_vec_by_output.push_back(vec_i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Swaps assigned to current key value with new vector for output map.
|
// Swaps assigned to current key value with new vector for output map.
|
||||||
@ -1055,9 +1031,8 @@ public:
|
|||||||
std::ostringstream os(std::ios::binary);
|
std::ostringstream os(std::ios::binary);
|
||||||
os << "Crafting definitions:\n";
|
os << "Crafting definitions:\n";
|
||||||
for (int type = 0; type <= craft_hash_type_max; ++type) {
|
for (int type = 0; type <= craft_hash_type_max; ++type) {
|
||||||
for (std::map<u64, std::vector<CraftDefinition*> >::const_iterator
|
for (auto it = m_craft_defs[type].begin();
|
||||||
it = (m_craft_defs[type]).begin();
|
it != m_craft_defs[type].end(); ++it) {
|
||||||
it != (m_craft_defs[type]).end(); ++it) {
|
|
||||||
for (std::vector<CraftDefinition*>::size_type i = 0;
|
for (std::vector<CraftDefinition*>::size_type i = 0;
|
||||||
i < it->second.size(); i++) {
|
i < it->second.size(); i++) {
|
||||||
os << "type " << type
|
os << "type " << type
|
||||||
@ -1083,15 +1058,12 @@ public:
|
|||||||
virtual void clear()
|
virtual void clear()
|
||||||
{
|
{
|
||||||
for (int type = 0; type <= craft_hash_type_max; ++type) {
|
for (int type = 0; type <= craft_hash_type_max; ++type) {
|
||||||
for (std::map<u64, std::vector<CraftDefinition*> >::iterator
|
for (auto &it : m_craft_defs[type]) {
|
||||||
it = m_craft_defs[type].begin();
|
for (auto iit = it.second.begin();
|
||||||
it != m_craft_defs[type].end(); ++it) {
|
iit != it.second.end(); ++iit) {
|
||||||
for (std::vector<CraftDefinition*>::iterator
|
|
||||||
iit = it->second.begin();
|
|
||||||
iit != it->second.end(); ++iit) {
|
|
||||||
delete *iit;
|
delete *iit;
|
||||||
}
|
}
|
||||||
it->second.clear();
|
it.second.clear();
|
||||||
}
|
}
|
||||||
m_craft_defs[type].clear();
|
m_craft_defs[type].clear();
|
||||||
}
|
}
|
||||||
@ -1102,10 +1074,7 @@ public:
|
|||||||
// Move the CraftDefs from the unhashed layer into layers higher up.
|
// Move the CraftDefs from the unhashed layer into layers higher up.
|
||||||
std::vector<CraftDefinition *> &unhashed =
|
std::vector<CraftDefinition *> &unhashed =
|
||||||
m_craft_defs[(int) CRAFT_HASH_TYPE_UNHASHED][0];
|
m_craft_defs[(int) CRAFT_HASH_TYPE_UNHASHED][0];
|
||||||
for (std::vector<CraftDefinition*>::size_type i = 0;
|
for (auto def : unhashed) {
|
||||||
i < unhashed.size(); i++) {
|
|
||||||
CraftDefinition *def = unhashed[i];
|
|
||||||
|
|
||||||
// Initialize and get the definition's hash
|
// Initialize and get the definition's hash
|
||||||
def->initHash(gamedef);
|
def->initHash(gamedef);
|
||||||
CraftHashType type = def->getHashType();
|
CraftHashType type = def->getHashType();
|
||||||
|
@ -73,7 +73,7 @@ struct CraftInput
|
|||||||
unsigned int width = 0;
|
unsigned int width = 0;
|
||||||
std::vector<ItemStack> items;
|
std::vector<ItemStack> items;
|
||||||
|
|
||||||
CraftInput() {}
|
CraftInput() = default;
|
||||||
|
|
||||||
CraftInput(CraftMethod method_, unsigned int width_,
|
CraftInput(CraftMethod method_, unsigned int width_,
|
||||||
const std::vector<ItemStack> &items_):
|
const std::vector<ItemStack> &items_):
|
||||||
@ -93,7 +93,7 @@ struct CraftOutput
|
|||||||
// Used for cooking (cook time) and fuel (burn time), seconds
|
// Used for cooking (cook time) and fuel (burn time), seconds
|
||||||
float time = 0.0f;
|
float time = 0.0f;
|
||||||
|
|
||||||
CraftOutput() {}
|
CraftOutput() = default;
|
||||||
|
|
||||||
CraftOutput(const std::string &item_, float time_):
|
CraftOutput(const std::string &item_, float time_):
|
||||||
item(item_), time(time_)
|
item(item_), time(time_)
|
||||||
@ -119,9 +119,7 @@ struct CraftReplacements
|
|||||||
// List of replacements
|
// List of replacements
|
||||||
std::vector<std::pair<std::string, std::string> > pairs;
|
std::vector<std::pair<std::string, std::string> > pairs;
|
||||||
|
|
||||||
CraftReplacements():
|
CraftReplacements() = default;
|
||||||
pairs()
|
|
||||||
{}
|
|
||||||
CraftReplacements(const std::vector<std::pair<std::string, std::string> > &pairs_):
|
CraftReplacements(const std::vector<std::pair<std::string, std::string> > &pairs_):
|
||||||
pairs(pairs_)
|
pairs(pairs_)
|
||||||
{}
|
{}
|
||||||
@ -134,8 +132,8 @@ struct CraftReplacements
|
|||||||
class CraftDefinition
|
class CraftDefinition
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CraftDefinition(){}
|
CraftDefinition() = default;
|
||||||
virtual ~CraftDefinition(){}
|
virtual ~CraftDefinition() = default;
|
||||||
|
|
||||||
// Returns type of crafting definition
|
// Returns type of crafting definition
|
||||||
virtual std::string getName() const=0;
|
virtual std::string getName() const=0;
|
||||||
@ -169,7 +167,7 @@ public:
|
|||||||
class CraftDefinitionShaped: public CraftDefinition
|
class CraftDefinitionShaped: public CraftDefinition
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CraftDefinitionShaped() {}
|
CraftDefinitionShaped() = delete;
|
||||||
|
|
||||||
CraftDefinitionShaped(
|
CraftDefinitionShaped(
|
||||||
const std::string &output_,
|
const std::string &output_,
|
||||||
@ -179,7 +177,7 @@ public:
|
|||||||
output(output_), width(width_), recipe(recipe_),
|
output(output_), width(width_), recipe(recipe_),
|
||||||
replacements(replacements_)
|
replacements(replacements_)
|
||||||
{}
|
{}
|
||||||
virtual ~CraftDefinitionShaped(){}
|
virtual ~CraftDefinitionShaped() = default;
|
||||||
|
|
||||||
virtual std::string getName() const;
|
virtual std::string getName() const;
|
||||||
virtual bool check(const CraftInput &input, IGameDef *gamedef) const;
|
virtual bool check(const CraftInput &input, IGameDef *gamedef) const;
|
||||||
@ -218,17 +216,14 @@ private:
|
|||||||
class CraftDefinitionShapeless: public CraftDefinition
|
class CraftDefinitionShapeless: public CraftDefinition
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CraftDefinitionShapeless():
|
CraftDefinitionShapeless() = delete;
|
||||||
output(""), recipe(), hash_inited(false), replacements()
|
|
||||||
{}
|
|
||||||
CraftDefinitionShapeless(
|
CraftDefinitionShapeless(
|
||||||
const std::string &output_,
|
const std::string &output_,
|
||||||
const std::vector<std::string> &recipe_,
|
const std::vector<std::string> &recipe_,
|
||||||
const CraftReplacements &replacements_):
|
const CraftReplacements &replacements_):
|
||||||
output(output_), recipe(recipe_),
|
output(output_), recipe(recipe_), replacements(replacements_)
|
||||||
hash_inited(false), replacements(replacements_)
|
|
||||||
{}
|
{}
|
||||||
virtual ~CraftDefinitionShapeless(){}
|
virtual ~CraftDefinitionShapeless() = default;
|
||||||
|
|
||||||
virtual std::string getName() const;
|
virtual std::string getName() const;
|
||||||
virtual bool check(const CraftInput &input, IGameDef *gamedef) const;
|
virtual bool check(const CraftInput &input, IGameDef *gamedef) const;
|
||||||
@ -252,7 +247,7 @@ private:
|
|||||||
// Recipe list (item names)
|
// Recipe list (item names)
|
||||||
std::vector<std::string> recipe_names;
|
std::vector<std::string> recipe_names;
|
||||||
// bool indicating if initHash has been called already
|
// bool indicating if initHash has been called already
|
||||||
bool hash_inited;
|
bool hash_inited = false;
|
||||||
// Replacement items for decrementInput()
|
// Replacement items for decrementInput()
|
||||||
CraftReplacements replacements;
|
CraftReplacements replacements;
|
||||||
};
|
};
|
||||||
@ -266,13 +261,11 @@ private:
|
|||||||
class CraftDefinitionToolRepair: public CraftDefinition
|
class CraftDefinitionToolRepair: public CraftDefinition
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CraftDefinitionToolRepair():
|
CraftDefinitionToolRepair() = delete;
|
||||||
additional_wear(0)
|
|
||||||
{}
|
|
||||||
CraftDefinitionToolRepair(float additional_wear_):
|
CraftDefinitionToolRepair(float additional_wear_):
|
||||||
additional_wear(additional_wear_)
|
additional_wear(additional_wear_)
|
||||||
{}
|
{}
|
||||||
virtual ~CraftDefinitionToolRepair(){}
|
virtual ~CraftDefinitionToolRepair() = default;
|
||||||
|
|
||||||
virtual std::string getName() const;
|
virtual std::string getName() const;
|
||||||
virtual bool check(const CraftInput &input, IGameDef *gamedef) const;
|
virtual bool check(const CraftInput &input, IGameDef *gamedef) const;
|
||||||
@ -294,7 +287,7 @@ private:
|
|||||||
// 1 = new tool is completely broken
|
// 1 = new tool is completely broken
|
||||||
// 0 = simply add remaining uses of both input tools
|
// 0 = simply add remaining uses of both input tools
|
||||||
// -1 = new tool is completely pristine
|
// -1 = new tool is completely pristine
|
||||||
float additional_wear;
|
float additional_wear = 0.0f;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -304,18 +297,15 @@ private:
|
|||||||
class CraftDefinitionCooking: public CraftDefinition
|
class CraftDefinitionCooking: public CraftDefinition
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CraftDefinitionCooking():
|
CraftDefinitionCooking() = delete;
|
||||||
output(""), recipe(""), hash_inited(false), cooktime()
|
|
||||||
{}
|
|
||||||
CraftDefinitionCooking(
|
CraftDefinitionCooking(
|
||||||
const std::string &output_,
|
const std::string &output_,
|
||||||
const std::string &recipe_,
|
const std::string &recipe_,
|
||||||
float cooktime_,
|
float cooktime_,
|
||||||
const CraftReplacements &replacements_):
|
const CraftReplacements &replacements_):
|
||||||
output(output_), recipe(recipe_), hash_inited(false),
|
output(output_), recipe(recipe_), cooktime(cooktime_), replacements(replacements_)
|
||||||
cooktime(cooktime_), replacements(replacements_)
|
|
||||||
{}
|
{}
|
||||||
virtual ~CraftDefinitionCooking(){}
|
virtual ~CraftDefinitionCooking() = default;
|
||||||
|
|
||||||
virtual std::string getName() const;
|
virtual std::string getName() const;
|
||||||
virtual bool check(const CraftInput &input, IGameDef *gamedef) const;
|
virtual bool check(const CraftInput &input, IGameDef *gamedef) const;
|
||||||
@ -339,7 +329,7 @@ private:
|
|||||||
// Recipe item name
|
// Recipe item name
|
||||||
std::string recipe_name;
|
std::string recipe_name;
|
||||||
// bool indicating if initHash has been called already
|
// bool indicating if initHash has been called already
|
||||||
bool hash_inited;
|
bool hash_inited = false;
|
||||||
// Time in seconds
|
// Time in seconds
|
||||||
float cooktime;
|
float cooktime;
|
||||||
// Replacement items for decrementInput()
|
// Replacement items for decrementInput()
|
||||||
@ -353,18 +343,13 @@ private:
|
|||||||
class CraftDefinitionFuel: public CraftDefinition
|
class CraftDefinitionFuel: public CraftDefinition
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CraftDefinitionFuel():
|
CraftDefinitionFuel() = delete;
|
||||||
recipe(""), hash_inited(false), burntime()
|
|
||||||
{}
|
|
||||||
CraftDefinitionFuel(const std::string &recipe_,
|
CraftDefinitionFuel(const std::string &recipe_,
|
||||||
float burntime_,
|
float burntime_,
|
||||||
const CraftReplacements &replacements_):
|
const CraftReplacements &replacements_):
|
||||||
recipe(recipe_),
|
recipe(recipe_), burntime(burntime_), replacements(replacements_)
|
||||||
hash_inited(false),
|
|
||||||
burntime(burntime_),
|
|
||||||
replacements(replacements_)
|
|
||||||
{}
|
{}
|
||||||
virtual ~CraftDefinitionFuel(){}
|
virtual ~CraftDefinitionFuel() = default;
|
||||||
|
|
||||||
virtual std::string getName() const;
|
virtual std::string getName() const;
|
||||||
virtual bool check(const CraftInput &input, IGameDef *gamedef) const;
|
virtual bool check(const CraftInput &input, IGameDef *gamedef) const;
|
||||||
@ -386,7 +371,7 @@ private:
|
|||||||
// Recipe item name
|
// Recipe item name
|
||||||
std::string recipe_name;
|
std::string recipe_name;
|
||||||
// bool indicating if initHash has been called already
|
// bool indicating if initHash has been called already
|
||||||
bool hash_inited;
|
bool hash_inited = false;
|
||||||
// Time in seconds
|
// Time in seconds
|
||||||
float burntime;
|
float burntime;
|
||||||
// Replacement items for decrementInput()
|
// Replacement items for decrementInput()
|
||||||
@ -399,8 +384,8 @@ private:
|
|||||||
class ICraftDefManager
|
class ICraftDefManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ICraftDefManager(){}
|
ICraftDefManager() = default;
|
||||||
virtual ~ICraftDefManager(){}
|
virtual ~ICraftDefManager() = default;
|
||||||
|
|
||||||
// The main crafting function
|
// The main crafting function
|
||||||
virtual bool getCraftResult(CraftInput &input, CraftOutput &output,
|
virtual bool getCraftResult(CraftInput &input, CraftOutput &output,
|
||||||
@ -416,8 +401,8 @@ public:
|
|||||||
class IWritableCraftDefManager : public ICraftDefManager
|
class IWritableCraftDefManager : public ICraftDefManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
IWritableCraftDefManager(){}
|
IWritableCraftDefManager() = default;
|
||||||
virtual ~IWritableCraftDefManager(){}
|
virtual ~IWritableCraftDefManager() = default;
|
||||||
|
|
||||||
// The main crafting function
|
// The main crafting function
|
||||||
virtual bool getCraftResult(CraftInput &input, CraftOutput &output,
|
virtual bool getCraftResult(CraftInput &input, CraftOutput &output,
|
||||||
|
@ -33,7 +33,7 @@ bool Database_Dummy::saveBlock(const v3s16 &pos, const std::string &data)
|
|||||||
void Database_Dummy::loadBlock(const v3s16 &pos, std::string *block)
|
void Database_Dummy::loadBlock(const v3s16 &pos, std::string *block)
|
||||||
{
|
{
|
||||||
s64 i = getBlockAsInteger(pos);
|
s64 i = getBlockAsInteger(pos);
|
||||||
std::map<s64, std::string>::iterator it = m_database.find(i);
|
auto it = m_database.find(i);
|
||||||
if (it == m_database.end()) {
|
if (it == m_database.end()) {
|
||||||
*block = "";
|
*block = "";
|
||||||
return;
|
return;
|
||||||
|
@ -44,7 +44,7 @@ void PlayerDatabaseFiles::serialize(std::ostringstream &os, RemotePlayer *player
|
|||||||
args.setFloat("yaw", player->getPlayerSAO()->getYaw());
|
args.setFloat("yaw", player->getPlayerSAO()->getYaw());
|
||||||
args.setS32("breath", player->getPlayerSAO()->getBreath());
|
args.setS32("breath", player->getPlayerSAO()->getBreath());
|
||||||
|
|
||||||
std::string extended_attrs = "";
|
std::string extended_attrs;
|
||||||
player->serializeExtraAttributes(extended_attrs);
|
player->serializeExtraAttributes(extended_attrs);
|
||||||
args.set("extended_attributes", extended_attrs);
|
args.set("extended_attributes", extended_attrs);
|
||||||
|
|
||||||
@ -174,6 +174,6 @@ void PlayerDatabaseFiles::listPlayers(std::vector<std::string> &res)
|
|||||||
player.deSerialize(is, "", &playerSAO);
|
player.deSerialize(is, "", &playerSAO);
|
||||||
is.close();
|
is.close();
|
||||||
|
|
||||||
res.push_back(player.getName());
|
res.emplace_back(player.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ class PlayerDatabaseFiles : public PlayerDatabase
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PlayerDatabaseFiles(const std::string &savedir) : m_savedir(savedir) {}
|
PlayerDatabaseFiles(const std::string &savedir) : m_savedir(savedir) {}
|
||||||
virtual ~PlayerDatabaseFiles() {}
|
virtual ~PlayerDatabaseFiles() = default;
|
||||||
|
|
||||||
void savePlayer(RemotePlayer *player);
|
void savePlayer(RemotePlayer *player);
|
||||||
bool loadPlayer(RemotePlayer *player, PlayerSAO *sao);
|
bool loadPlayer(RemotePlayer *player, PlayerSAO *sao);
|
||||||
|
@ -489,7 +489,8 @@ void PlayerDatabasePostgreSQL::savePlayer(RemotePlayer *player)
|
|||||||
std::vector<const InventoryList*> inventory_lists = sao->getInventory()->getLists();
|
std::vector<const InventoryList*> inventory_lists = sao->getInventory()->getLists();
|
||||||
for (u16 i = 0; i < inventory_lists.size(); i++) {
|
for (u16 i = 0; i < inventory_lists.size(); i++) {
|
||||||
const InventoryList* list = inventory_lists[i];
|
const InventoryList* list = inventory_lists[i];
|
||||||
std::string name = list->getName(), width = itos(list->getWidth()),
|
const std::string &name = list->getName();
|
||||||
|
std::string width = itos(list->getWidth()),
|
||||||
inv_id = itos(i), lsize = itos(list->getSize());
|
inv_id = itos(i), lsize = itos(list->getSize());
|
||||||
|
|
||||||
const char* inv_values[] = {
|
const char* inv_values[] = {
|
||||||
@ -518,11 +519,11 @@ void PlayerDatabasePostgreSQL::savePlayer(RemotePlayer *player)
|
|||||||
|
|
||||||
execPrepared("remove_player_metadata", 1, rmvalues);
|
execPrepared("remove_player_metadata", 1, rmvalues);
|
||||||
const PlayerAttributes &attrs = sao->getExtendedAttributes();
|
const PlayerAttributes &attrs = sao->getExtendedAttributes();
|
||||||
for (PlayerAttributes::const_iterator it = attrs.begin(); it != attrs.end(); ++it) {
|
for (const auto &attr : attrs) {
|
||||||
const char *meta_values[] = {
|
const char *meta_values[] = {
|
||||||
player->getName(),
|
player->getName(),
|
||||||
it->first.c_str(),
|
attr.first.c_str(),
|
||||||
it->second.c_str()
|
attr.second.c_str()
|
||||||
};
|
};
|
||||||
execPrepared("save_player_metadata", 3, meta_values);
|
execPrepared("save_player_metadata", 3, meta_values);
|
||||||
}
|
}
|
||||||
@ -622,7 +623,7 @@ void PlayerDatabasePostgreSQL::listPlayers(std::vector<std::string> &res)
|
|||||||
|
|
||||||
int numrows = PQntuples(results);
|
int numrows = PQntuples(results);
|
||||||
for (int row = 0; row < numrows; row++)
|
for (int row = 0; row < numrows; row++)
|
||||||
res.push_back(PQgetvalue(results, row, 0));
|
res.emplace_back(PQgetvalue(results, row, 0));
|
||||||
|
|
||||||
PQclear(results);
|
PQclear(results);
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ class MapDatabasePostgreSQL : private Database_PostgreSQL, public MapDatabase
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MapDatabasePostgreSQL(const std::string &connect_string);
|
MapDatabasePostgreSQL(const std::string &connect_string);
|
||||||
virtual ~MapDatabasePostgreSQL() {}
|
virtual ~MapDatabasePostgreSQL() = default;
|
||||||
|
|
||||||
bool saveBlock(const v3s16 &pos, const std::string &data);
|
bool saveBlock(const v3s16 &pos, const std::string &data);
|
||||||
void loadBlock(const v3s16 &pos, std::string *block);
|
void loadBlock(const v3s16 &pos, std::string *block);
|
||||||
@ -130,7 +130,7 @@ class PlayerDatabasePostgreSQL : private Database_PostgreSQL, public PlayerDatab
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PlayerDatabasePostgreSQL(const std::string &connect_string);
|
PlayerDatabasePostgreSQL(const std::string &connect_string);
|
||||||
virtual ~PlayerDatabasePostgreSQL() {}
|
virtual ~PlayerDatabasePostgreSQL() = default;
|
||||||
|
|
||||||
void savePlayer(RemotePlayer *player);
|
void savePlayer(RemotePlayer *player);
|
||||||
bool loadPlayer(RemotePlayer *player, PlayerSAO *sao);
|
bool loadPlayer(RemotePlayer *player, PlayerSAO *sao);
|
||||||
|
@ -38,7 +38,7 @@ Database_Redis::Database_Redis(Settings &conf)
|
|||||||
try {
|
try {
|
||||||
tmp = conf.get("redis_address");
|
tmp = conf.get("redis_address");
|
||||||
hash = conf.get("redis_hash");
|
hash = conf.get("redis_hash");
|
||||||
} catch (SettingNotFoundException) {
|
} catch (SettingNotFoundException &) {
|
||||||
throw SettingNotFoundException("Set redis_address and "
|
throw SettingNotFoundException("Set redis_address and "
|
||||||
"redis_hash in world.mt to use the redis backend");
|
"redis_hash in world.mt to use the redis backend");
|
||||||
}
|
}
|
||||||
|
@ -521,10 +521,10 @@ void PlayerDatabaseSQLite3::savePlayer(RemotePlayer *player)
|
|||||||
sqlite3_reset(m_stmt_player_metadata_remove);
|
sqlite3_reset(m_stmt_player_metadata_remove);
|
||||||
|
|
||||||
const PlayerAttributes &attrs = sao->getExtendedAttributes();
|
const PlayerAttributes &attrs = sao->getExtendedAttributes();
|
||||||
for (PlayerAttributes::const_iterator it = attrs.begin(); it != attrs.end(); ++it) {
|
for (const auto &attr : attrs) {
|
||||||
str_to_sqlite(m_stmt_player_metadata_add, 1, player->getName());
|
str_to_sqlite(m_stmt_player_metadata_add, 1, player->getName());
|
||||||
str_to_sqlite(m_stmt_player_metadata_add, 2, it->first);
|
str_to_sqlite(m_stmt_player_metadata_add, 2, attr.first);
|
||||||
str_to_sqlite(m_stmt_player_metadata_add, 3, it->second);
|
str_to_sqlite(m_stmt_player_metadata_add, 3, attr.second);
|
||||||
sqlite3_vrfy(sqlite3_step(m_stmt_player_metadata_add), SQLITE_DONE);
|
sqlite3_vrfy(sqlite3_step(m_stmt_player_metadata_add), SQLITE_DONE);
|
||||||
sqlite3_reset(m_stmt_player_metadata_add);
|
sqlite3_reset(m_stmt_player_metadata_add);
|
||||||
}
|
}
|
||||||
|
@ -32,9 +32,9 @@ static inline s16 unsigned_to_signed(u16 i, u16 max_positive)
|
|||||||
{
|
{
|
||||||
if (i < max_positive) {
|
if (i < max_positive) {
|
||||||
return i;
|
return i;
|
||||||
} else {
|
|
||||||
return i - (max_positive * 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return i - (max_positive * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ public:
|
|||||||
class MapDatabase : public Database
|
class MapDatabase : public Database
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~MapDatabase() {}
|
virtual ~MapDatabase() = default;
|
||||||
|
|
||||||
virtual bool saveBlock(const v3s16 &pos, const std::string &data) = 0;
|
virtual bool saveBlock(const v3s16 &pos, const std::string &data) = 0;
|
||||||
virtual void loadBlock(const v3s16 &pos, std::string *block) = 0;
|
virtual void loadBlock(const v3s16 &pos, std::string *block) = 0;
|
||||||
@ -54,7 +54,8 @@ class RemotePlayer;
|
|||||||
class PlayerDatabase
|
class PlayerDatabase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~PlayerDatabase() {}
|
virtual ~PlayerDatabase() = default;
|
||||||
|
|
||||||
virtual void savePlayer(RemotePlayer *player) = 0;
|
virtual void savePlayer(RemotePlayer *player) = 0;
|
||||||
virtual bool loadPlayer(RemotePlayer *player, PlayerSAO *sao) = 0;
|
virtual bool loadPlayer(RemotePlayer *player, PlayerSAO *sao) = 0;
|
||||||
virtual bool removePlayer(const std::string &name) = 0;
|
virtual bool removePlayer(const std::string &name) = 0;
|
||||||
|
@ -50,16 +50,17 @@ inline u32 time_to_daynight_ratio(float time_of_day, bool smooth)
|
|||||||
return values[i][1];
|
return values[i][1];
|
||||||
}
|
}
|
||||||
return 1000;
|
return 1000;
|
||||||
} else {
|
}
|
||||||
for(u32 i=0; i<sizeof(values)/sizeof(*values); i++){
|
|
||||||
if(values[i][0] <= t)
|
for (u32 i=0; i < sizeof(values) / sizeof(*values); i++) {
|
||||||
|
if (values[i][0] <= t)
|
||||||
continue;
|
continue;
|
||||||
if(i == 0)
|
if (i == 0)
|
||||||
return values[i][1];
|
return values[i][1];
|
||||||
float td0 = values[i][0] - values[i-1][0];
|
float td0 = values[i][0] - values[i-1][0];
|
||||||
float f = (t - values[i-1][0]) / td0;
|
float f = (t - values[i-1][0]) / td0;
|
||||||
return f * values[i][1] + (1.0 - f) * values[i-1][1];
|
return f * values[i][1] + (1.0 - f) * values[i-1][1];
|
||||||
}
|
}
|
||||||
return 1000;
|
return 1000;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "porting.h"
|
#include "porting.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "exceptions.h"
|
#include "exceptions.h"
|
||||||
#include <stdio.h>
|
#include <cstdio>
|
||||||
#include <stdlib.h>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@ -110,7 +110,7 @@ void DebugStack::print(FILE *file, bool everything)
|
|||||||
os.str().c_str());
|
os.str().c_str());
|
||||||
|
|
||||||
for (int i = 0; i < stack_max_i; i++) {
|
for (int i = 0; i < stack_max_i; i++) {
|
||||||
if (i == stack_i && everything == false)
|
if (i == stack_i && !everything)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (i < stack_i)
|
if (i < stack_i)
|
||||||
@ -128,7 +128,7 @@ void DebugStack::print(std::ostream &os, bool everything)
|
|||||||
os<<"DEBUG STACK FOR THREAD "<<thread_id<<": "<<std::endl;
|
os<<"DEBUG STACK FOR THREAD "<<thread_id<<": "<<std::endl;
|
||||||
|
|
||||||
for(int i = 0; i < stack_max_i; i++) {
|
for(int i = 0; i < stack_max_i; i++) {
|
||||||
if(i == stack_i && everything == false)
|
if(i == stack_i && !everything)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (i < stack_i)
|
if (i < stack_i)
|
||||||
@ -193,7 +193,7 @@ DebugStacker::~DebugStacker()
|
|||||||
{
|
{
|
||||||
MutexAutoLock lock(g_debug_stacks_mutex);
|
MutexAutoLock lock(g_debug_stacks_mutex);
|
||||||
|
|
||||||
if (m_overflowed == true)
|
if (m_overflowed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_stack->stack_i--;
|
m_stack->stack_i--;
|
||||||
|
@ -21,7 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <assert.h>
|
#include <cassert>
|
||||||
#include "gettime.h"
|
#include "gettime.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
@ -440,8 +440,7 @@ void set_default_settings(Settings *settings)
|
|||||||
void override_default_settings(Settings *settings, Settings *from)
|
void override_default_settings(Settings *settings, Settings *from)
|
||||||
{
|
{
|
||||||
std::vector<std::string> names = from->getNames();
|
std::vector<std::string> names = from->getNames();
|
||||||
for (size_t i = 0; i < names.size(); i++) {
|
for (const auto &name : names) {
|
||||||
const std::string &name = names[i];
|
|
||||||
settings->setDefault(name, from->get(name));
|
settings->setDefault(name, from->get(name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,7 +201,7 @@ void DungeonGen::makeDungeon(v3s16 start_padding)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// No place found
|
// No place found
|
||||||
if (fits == false)
|
if (!fits)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -564,7 +564,7 @@ bool DungeonGen::findPlaceForRoomDoor(v3s16 roomsize, v3s16 &result_doorplace,
|
|||||||
v3s16 doorplace;
|
v3s16 doorplace;
|
||||||
v3s16 doordir;
|
v3s16 doordir;
|
||||||
bool r = findPlaceForDoor(doorplace, doordir);
|
bool r = findPlaceForDoor(doorplace, doordir);
|
||||||
if (r == false)
|
if (!r)
|
||||||
continue;
|
continue;
|
||||||
v3s16 roomplace;
|
v3s16 roomplace;
|
||||||
// X east, Z north, Y up
|
// X east, Z north, Y up
|
||||||
@ -596,7 +596,7 @@ bool DungeonGen::findPlaceForRoomDoor(v3s16 roomsize, v3s16 &result_doorplace,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fits == false) {
|
if (!fits) {
|
||||||
// Find new place
|
// Find new place
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -625,12 +625,12 @@ v3s16 rand_ortho_dir(PseudoRandom &random, bool diagonal_dirs)
|
|||||||
} while ((dir.X == 0 || dir.Z == 0) && trycount < 10);
|
} while ((dir.X == 0 || dir.Z == 0) && trycount < 10);
|
||||||
|
|
||||||
return dir;
|
return dir;
|
||||||
} else {
|
|
||||||
if (random.next() % 2 == 0)
|
|
||||||
return random.next() % 2 ? v3s16(-1, 0, 0) : v3s16(1, 0, 0);
|
|
||||||
else
|
|
||||||
return random.next() % 2 ? v3s16(0, 0, -1) : v3s16(0, 0, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (random.next() % 2 == 0)
|
||||||
|
return random.next() % 2 ? v3s16(-1, 0, 0) : v3s16(1, 0, 0);
|
||||||
|
|
||||||
|
return random.next() % 2 ? v3s16(0, 0, -1) : v3s16(0, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -673,6 +673,6 @@ int dir_to_facedir(v3s16 d)
|
|||||||
{
|
{
|
||||||
if (abs(d.X) > abs(d.Z))
|
if (abs(d.X) > abs(d.Z))
|
||||||
return d.X < 0 ? 3 : 1;
|
return d.X < 0 ? 3 : 1;
|
||||||
else
|
|
||||||
return d.Z < 0 ? 2 : 0;
|
return d.Z < 0 ? 2 : 0;
|
||||||
}
|
}
|
||||||
|
@ -52,18 +52,18 @@ public:
|
|||||||
int id;
|
int id;
|
||||||
|
|
||||||
EmergeThread(Server *server, int ethreadid);
|
EmergeThread(Server *server, int ethreadid);
|
||||||
~EmergeThread();
|
~EmergeThread() = default;
|
||||||
|
|
||||||
void *run();
|
void *run();
|
||||||
void signal();
|
void signal();
|
||||||
|
|
||||||
// Requires queue mutex held
|
// Requires queue mutex held
|
||||||
bool pushBlock(v3s16 pos);
|
bool pushBlock(const v3s16 &pos);
|
||||||
|
|
||||||
void cancelPendingItems();
|
void cancelPendingItems();
|
||||||
|
|
||||||
static void runCompletionCallbacks(
|
static void runCompletionCallbacks(
|
||||||
v3s16 pos, EmergeAction action,
|
const v3s16 &pos, EmergeAction action,
|
||||||
const EmergeCallbackList &callbacks);
|
const EmergeCallbackList &callbacks);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -78,7 +78,7 @@ private:
|
|||||||
bool popBlockEmerge(v3s16 *pos, BlockEmergeData *bedata);
|
bool popBlockEmerge(v3s16 *pos, BlockEmergeData *bedata);
|
||||||
|
|
||||||
EmergeAction getBlockOrStartGen(
|
EmergeAction getBlockOrStartGen(
|
||||||
v3s16 pos, bool allow_gen, MapBlock **block, BlockMakeData *data);
|
const v3s16 &pos, bool allow_gen, MapBlock **block, BlockMakeData *data);
|
||||||
MapBlock *finishGen(v3s16 pos, BlockMakeData *bmdata,
|
MapBlock *finishGen(v3s16 pos, BlockMakeData *bmdata,
|
||||||
std::map<v3s16, MapBlock *> *modified_blocks);
|
std::map<v3s16, MapBlock *> *modified_blocks);
|
||||||
|
|
||||||
@ -181,7 +181,7 @@ EmergeManager::~EmergeManager()
|
|||||||
|
|
||||||
bool EmergeManager::initMapgens(MapgenParams *params)
|
bool EmergeManager::initMapgens(MapgenParams *params)
|
||||||
{
|
{
|
||||||
if (m_mapgens.size())
|
if (!m_mapgens.empty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
this->mgparams = params;
|
this->mgparams = params;
|
||||||
@ -316,7 +316,7 @@ v3s16 EmergeManager::getContainingChunk(v3s16 blockpos, s16 chunksize)
|
|||||||
|
|
||||||
int EmergeManager::getSpawnLevelAtPoint(v2s16 p)
|
int EmergeManager::getSpawnLevelAtPoint(v2s16 p)
|
||||||
{
|
{
|
||||||
if (m_mapgens.size() == 0 || !m_mapgens[0]) {
|
if (m_mapgens.empty() || !m_mapgens[0]) {
|
||||||
errorstream << "EmergeManager: getSpawnLevelAtPoint() called"
|
errorstream << "EmergeManager: getSpawnLevelAtPoint() called"
|
||||||
" before mapgen init" << std::endl;
|
" before mapgen init" << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
@ -328,7 +328,7 @@ int EmergeManager::getSpawnLevelAtPoint(v2s16 p)
|
|||||||
|
|
||||||
int EmergeManager::getGroundLevelAtPoint(v2s16 p)
|
int EmergeManager::getGroundLevelAtPoint(v2s16 p)
|
||||||
{
|
{
|
||||||
if (m_mapgens.size() == 0 || !m_mapgens[0]) {
|
if (m_mapgens.empty() || !m_mapgens[0]) {
|
||||||
errorstream << "EmergeManager: getGroundLevelAtPoint() called"
|
errorstream << "EmergeManager: getGroundLevelAtPoint() called"
|
||||||
" before mapgen init" << std::endl;
|
" before mapgen init" << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
@ -380,7 +380,7 @@ bool EmergeManager::pushBlockEmergeData(
|
|||||||
*entry_already_exists = !findres.second;
|
*entry_already_exists = !findres.second;
|
||||||
|
|
||||||
if (callback)
|
if (callback)
|
||||||
bedata.callbacks.push_back(std::make_pair(callback, callback_param));
|
bedata.callbacks.emplace_back(callback, callback_param);
|
||||||
|
|
||||||
if (*entry_already_exists) {
|
if (*entry_already_exists) {
|
||||||
bedata.flags |= flags;
|
bedata.flags |= flags;
|
||||||
@ -457,19 +457,13 @@ EmergeThread::EmergeThread(Server *server, int ethreadid) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
EmergeThread::~EmergeThread()
|
|
||||||
{
|
|
||||||
//cancelPendingItems();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void EmergeThread::signal()
|
void EmergeThread::signal()
|
||||||
{
|
{
|
||||||
m_queue_event.signal();
|
m_queue_event.signal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool EmergeThread::pushBlock(v3s16 pos)
|
bool EmergeThread::pushBlock(const v3s16 &pos)
|
||||||
{
|
{
|
||||||
m_block_queue.push(pos);
|
m_block_queue.push(pos);
|
||||||
return true;
|
return true;
|
||||||
@ -494,9 +488,7 @@ void EmergeThread::cancelPendingItems()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void EmergeThread::runCompletionCallbacks(
|
void EmergeThread::runCompletionCallbacks(const v3s16 &pos, EmergeAction action,
|
||||||
v3s16 pos,
|
|
||||||
EmergeAction action,
|
|
||||||
const EmergeCallbackList &callbacks)
|
const EmergeCallbackList &callbacks)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i != callbacks.size(); i++) {
|
for (size_t i = 0; i != callbacks.size(); i++) {
|
||||||
@ -528,7 +520,7 @@ bool EmergeThread::popBlockEmerge(v3s16 *pos, BlockEmergeData *bedata)
|
|||||||
|
|
||||||
|
|
||||||
EmergeAction EmergeThread::getBlockOrStartGen(
|
EmergeAction EmergeThread::getBlockOrStartGen(
|
||||||
v3s16 pos, bool allow_gen, MapBlock **block, BlockMakeData *bmdata)
|
const v3s16 &pos, bool allow_gen, MapBlock **block, BlockMakeData *bmdata)
|
||||||
{
|
{
|
||||||
MutexAutoLock envlock(m_server->m_env_mutex);
|
MutexAutoLock envlock(m_server->m_env_mutex);
|
||||||
|
|
||||||
@ -644,7 +636,7 @@ void *EmergeThread::run()
|
|||||||
|
|
||||||
m_mapgen->makeChunk(&bmdata);
|
m_mapgen->makeChunk(&bmdata);
|
||||||
|
|
||||||
if (enable_mapgen_debug_info == false)
|
if (!enable_mapgen_debug_info)
|
||||||
t.stop(true); // Hide output
|
t.stop(true); // Hide output
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -656,7 +648,7 @@ void *EmergeThread::run()
|
|||||||
if (block)
|
if (block)
|
||||||
modified_blocks[pos] = block;
|
modified_blocks[pos] = block;
|
||||||
|
|
||||||
if (modified_blocks.size() > 0)
|
if (!modified_blocks.empty())
|
||||||
m_server->SetBlocksNotSent(modified_blocks);
|
m_server->SetBlocksNotSent(modified_blocks);
|
||||||
}
|
}
|
||||||
} catch (VersionMismatchException &e) {
|
} catch (VersionMismatchException &e) {
|
||||||
|
@ -54,7 +54,8 @@ struct BlockMakeData {
|
|||||||
UniqueQueue<v3s16> transforming_liquid;
|
UniqueQueue<v3s16> transforming_liquid;
|
||||||
INodeDefManager *nodedef = nullptr;
|
INodeDefManager *nodedef = nullptr;
|
||||||
|
|
||||||
BlockMakeData() {}
|
BlockMakeData() = default;
|
||||||
|
|
||||||
~BlockMakeData() { delete vmanip; }
|
~BlockMakeData() { delete vmanip; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user