1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

General code refactoring/improvements in server, treegen and connection

This commit is contained in:
sfan5 2024-03-12 14:13:24 +01:00
parent 24f2c38093
commit bc4ab8b99e
34 changed files with 330 additions and 439 deletions

View file

@ -23,11 +23,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "itemgroup.h"
#include "json-forwards.h"
#include "common/c_types.h"
#include <json/json.h>
#include <SColor.h>
#include <string>
#include <iostream>
#include <map>
#include <unordered_map>
#include <optional>
struct ItemDefinition;
@ -41,15 +42,11 @@ struct ToolGroupCap
ToolGroupCap() = default;
bool getTime(int rating, float *time) const
{
std::unordered_map<int, float>::const_iterator i = times.find(rating);
if (i == times.end()) {
*time = 0;
return false;
}
*time = i->second;
return true;
std::optional<float> getTime(int rating) const {
auto i = times.find(rating);
if (i == times.end())
return std::nullopt;
return i->second;
}
void toJson(Json::Value &object) const;
@ -91,7 +88,7 @@ struct ToolCapabilities
struct WearBarParams
{
std::map<f32, video::SColor> colorStops;
enum BlendMode: u8 {
enum BlendMode : u8 {
BLEND_MODE_CONSTANT,
BLEND_MODE_LINEAR,
BlendMode_END // Dummy for validity check
@ -99,7 +96,7 @@ struct WearBarParams
constexpr const static EnumString es_BlendMode[3] = {
{WearBarParams::BLEND_MODE_CONSTANT, "constant"},
{WearBarParams::BLEND_MODE_LINEAR, "linear"},
{0, NULL}
{0, nullptr}
};
BlendMode blend;
@ -109,7 +106,7 @@ struct WearBarParams
{}
WearBarParams(const video::SColor color):
WearBarParams({{0.0, color}}, WearBarParams::BLEND_MODE_CONSTANT)
WearBarParams({{0.0f, color}}, WearBarParams::BLEND_MODE_CONSTANT)
{};
void serialize(std::ostream &os) const;