forked from Mirrorlandia_minetest/minetest
Modernize various files (src/k*, src/l*)
* range-based for loops * code style * C++ headers instead of C headers * Default operators
This commit is contained in:
parent
1d086aee7c
commit
951f1201c4
@ -246,9 +246,9 @@ static const struct table_key table[] = {
|
|||||||
|
|
||||||
struct table_key lookup_keyname(const char *name)
|
struct table_key lookup_keyname(const char *name)
|
||||||
{
|
{
|
||||||
for (u16 i = 0; i < ARRLEN(table); i++) {
|
for (const auto &table_key : table) {
|
||||||
if (strcmp(table[i].Name, name) == 0)
|
if (strcmp(table_key.Name, name) == 0)
|
||||||
return table[i];
|
return table_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw UnknownKeycode(name);
|
throw UnknownKeycode(name);
|
||||||
@ -256,9 +256,9 @@ struct table_key lookup_keyname(const char *name)
|
|||||||
|
|
||||||
struct table_key lookup_keykey(irr::EKEY_CODE key)
|
struct table_key lookup_keykey(irr::EKEY_CODE key)
|
||||||
{
|
{
|
||||||
for (u16 i = 0; i < ARRLEN(table); i++) {
|
for (const auto &table_key : table) {
|
||||||
if (table[i].Key == key)
|
if (table_key.Key == key)
|
||||||
return table[i];
|
return table_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
@ -268,9 +268,9 @@ struct table_key lookup_keykey(irr::EKEY_CODE key)
|
|||||||
|
|
||||||
struct table_key lookup_keychar(wchar_t Char)
|
struct table_key lookup_keychar(wchar_t Char)
|
||||||
{
|
{
|
||||||
for (u16 i = 0; i < ARRLEN(table); i++) {
|
for (const auto &table_key : table) {
|
||||||
if (table[i].Char == Char)
|
if (table_key.Char == Char)
|
||||||
return table[i];
|
return table_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
@ -285,7 +285,9 @@ KeyPress::KeyPress(const char *name)
|
|||||||
Char = L'\0';
|
Char = L'\0';
|
||||||
m_name = "";
|
m_name = "";
|
||||||
return;
|
return;
|
||||||
} else if (strlen(name) <= 4) {
|
}
|
||||||
|
|
||||||
|
if (strlen(name) <= 4) {
|
||||||
// Lookup by resulting character
|
// Lookup by resulting character
|
||||||
int chars_read = mbtowc(&Char, name, 1);
|
int chars_read = mbtowc(&Char, name, 1);
|
||||||
FATAL_ERROR_IF(chars_read != 1, "Unexpected multibyte character");
|
FATAL_ERROR_IF(chars_read != 1, "Unexpected multibyte character");
|
||||||
@ -339,7 +341,7 @@ const char *KeyPress::sym() const
|
|||||||
|
|
||||||
const char *KeyPress::name() const
|
const char *KeyPress::name() const
|
||||||
{
|
{
|
||||||
if (m_name == "")
|
if (m_name.empty())
|
||||||
return "";
|
return "";
|
||||||
const char *ret;
|
const char *ret;
|
||||||
if (valid_kcode(Key))
|
if (valid_kcode(Key))
|
||||||
|
@ -30,7 +30,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
class KeyPress
|
class KeyPress
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
KeyPress() {}
|
KeyPress() = default;
|
||||||
|
|
||||||
KeyPress(const char *name);
|
KeyPress(const char *name);
|
||||||
|
|
||||||
KeyPress(const irr::SEvent::SKeyInput &in, bool prefer_character = false);
|
KeyPress(const irr::SEvent::SKeyInput &in, bool prefer_character = false);
|
||||||
|
@ -18,7 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "light.h"
|
#include "light.h"
|
||||||
#include <math.h>
|
#include <cmath>
|
||||||
#include "util/numeric.h"
|
#include "util/numeric.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
|
@ -38,13 +38,9 @@ LocalPlayer::LocalPlayer(Client *client, const char *name):
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalPlayer::~LocalPlayer()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static aabb3f getNodeBoundingBox(const std::vector<aabb3f> &nodeboxes)
|
static aabb3f getNodeBoundingBox(const std::vector<aabb3f> &nodeboxes)
|
||||||
{
|
{
|
||||||
if (nodeboxes.size() == 0)
|
if (nodeboxes.empty())
|
||||||
return aabb3f(0, 0, 0, 0, 0, 0);
|
return aabb3f(0, 0, 0, 0, 0, 0);
|
||||||
|
|
||||||
aabb3f b_max;
|
aabb3f b_max;
|
||||||
@ -103,8 +99,8 @@ bool LocalPlayer::updateSneakNode(Map *map, const v3f &position,
|
|||||||
m_sneak_ladder_detected = false;
|
m_sneak_ladder_detected = false;
|
||||||
f32 min_distance_f = 100000.0 * BS;
|
f32 min_distance_f = 100000.0 * BS;
|
||||||
|
|
||||||
for (s16 d = 0; d < 9; d++) {
|
for (const auto &d : dir9_center) {
|
||||||
const v3s16 p = current_node + dir9_center[d];
|
const v3s16 p = current_node + d;
|
||||||
const v3f pf = intToFloat(p, BS);
|
const v3f pf = intToFloat(p, BS);
|
||||||
const v2f diff(position.X - pf.X, position.Z - pf.Z);
|
const v2f diff(position.X - pf.X, position.Z - pf.Z);
|
||||||
f32 distance_f = diff.getLength();
|
f32 distance_f = diff.getLength();
|
||||||
@ -389,9 +385,8 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
|
|||||||
|
|
||||||
// Dont report if flying
|
// Dont report if flying
|
||||||
if(collision_info && !(g_settings->getBool("free_move") && fly_allowed)) {
|
if(collision_info && !(g_settings->getBool("free_move") && fly_allowed)) {
|
||||||
for(size_t i=0; i<result.collisions.size(); i++) {
|
for (const auto &colinfo : result.collisions) {
|
||||||
const CollisionInfo &info = result.collisions[i];
|
collision_info->push_back(colinfo);
|
||||||
collision_info->push_back(info);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -938,7 +933,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d,
|
|||||||
|
|
||||||
// The node to be sneaked on has to be walkable
|
// The node to be sneaked on has to be walkable
|
||||||
node = map->getNodeNoEx(p, &is_valid_position);
|
node = map->getNodeNoEx(p, &is_valid_position);
|
||||||
if (!is_valid_position || nodemgr->get(node).walkable == false)
|
if (!is_valid_position || !nodemgr->get(node).walkable)
|
||||||
continue;
|
continue;
|
||||||
// And the node above it has to be nonwalkable
|
// And the node above it has to be nonwalkable
|
||||||
node = map->getNodeNoEx(p + v3s16(0, 1, 0), &is_valid_position);
|
node = map->getNodeNoEx(p + v3s16(0, 1, 0), &is_valid_position);
|
||||||
@ -965,9 +960,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d,
|
|||||||
MapNode n = map->getNodeNoEx(m_sneak_node);
|
MapNode n = map->getNodeNoEx(m_sneak_node);
|
||||||
std::vector<aabb3f> nodeboxes;
|
std::vector<aabb3f> nodeboxes;
|
||||||
n.getCollisionBoxes(nodemgr, &nodeboxes);
|
n.getCollisionBoxes(nodemgr, &nodeboxes);
|
||||||
for (std::vector<aabb3f>::iterator it = nodeboxes.begin();
|
for (const auto &box : nodeboxes) {
|
||||||
it != nodeboxes.end(); ++it) {
|
|
||||||
aabb3f box = *it;
|
|
||||||
if (box.MaxEdge.Y > cb_max)
|
if (box.MaxEdge.Y > cb_max)
|
||||||
cb_max = box.MaxEdge.Y;
|
cb_max = box.MaxEdge.Y;
|
||||||
}
|
}
|
||||||
@ -994,8 +987,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d,
|
|||||||
*/
|
*/
|
||||||
// Dont report if flying
|
// Dont report if flying
|
||||||
if (collision_info && !(g_settings->getBool("free_move") && fly_allowed)) {
|
if (collision_info && !(g_settings->getBool("free_move") && fly_allowed)) {
|
||||||
for (size_t i = 0; i < result.collisions.size(); i++) {
|
for (const auto &info : result.collisions) {
|
||||||
const CollisionInfo &info = result.collisions[i];
|
|
||||||
collision_info->push_back(info);
|
collision_info->push_back(info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ class LocalPlayer : public Player
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LocalPlayer(Client *client, const char *name);
|
LocalPlayer(Client *client, const char *name);
|
||||||
virtual ~LocalPlayer();
|
virtual ~LocalPlayer() = default;
|
||||||
|
|
||||||
ClientActiveObject *parent = nullptr;
|
ClientActiveObject *parent = nullptr;
|
||||||
|
|
||||||
|
@ -205,9 +205,7 @@ extern std::ostream dstream;
|
|||||||
#define dout_con (*dout_con_ptr)
|
#define dout_con (*dout_con_ptr)
|
||||||
#define derr_con (*derr_con_ptr)
|
#define derr_con (*derr_con_ptr)
|
||||||
#define dout_server (*dout_server_ptr)
|
#define dout_server (*dout_server_ptr)
|
||||||
#define derr_server (*derr_server_ptr)
|
|
||||||
|
|
||||||
#ifndef SERVER
|
#ifndef SERVER
|
||||||
#define dout_client (*dout_client_ptr)
|
#define dout_client (*dout_client_ptr)
|
||||||
#define derr_client (*derr_client_ptr)
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user