Merge pull request #6774 from janisozaur/fixes

Various code improvements
This commit is contained in:
Hielke Morsink authored and GitHub committed 2018-05-15 14:38:43 +02:00
commit 6c65c3d64d
32 files changed
+77 -122

No files matched your search

+2 -2
View File
@@ -45,8 +45,8 @@ enum class FILE_TYPE
struct ClassifiedFileInfo
{
FILE_TYPE Type;
uint32 Version;
FILE_TYPE Type = FILE_TYPE::UNDEFINED;
uint32 Version = 0;
};
#define FILE_TYPE_S4_CUTOFF 2
+4 -12
View File
@@ -117,22 +117,14 @@ namespace ParkImporter
bool ExtensionIsRCT1(const std::string &extension)
{
if (String::Equals(extension, ".sc4", true) ||
String::Equals(extension, ".sv4", true))
{
return true;
}
return false;
return String::Equals(extension, ".sc4", true) ||
String::Equals(extension, ".sv4", true);
}
bool ExtensionIsScenario(const std::string &extension)
{
if (String::Equals(extension, ".sc4", true) ||
String::Equals(extension, ".sc6", true))
{
return true;
}
return false;
return String::Equals(extension, ".sc4", true) ||
String::Equals(extension, ".sc6", true);
}
}
-4
View File
@@ -27,10 +27,6 @@
#include "../world/Park.h"
#include "GameAction.h"
GameActionResult::GameActionResult()
{
}
GameActionResult::GameActionResult(GA_ERROR error, rct_string_id message)
{
Error = error;
+1 -1
View File
@@ -81,7 +81,7 @@ public:
money32 Cost = 0;
uint16 ExpenditureType = 0;
GameActionResult();
GameActionResult() = default;
GameActionResult(GA_ERROR error, rct_string_id message);
GameActionResult(GA_ERROR error, rct_string_id title, rct_string_id message);
GameActionResult(GA_ERROR error, rct_string_id title, rct_string_id message, uint8 * args);
+1 -5
View File
@@ -463,11 +463,7 @@ namespace CommandLine
}
else if (shortOption[1] != '\0')
{
if (!ParseOptionValue(option, &shortOption[1]))
{
return false;
}
return true;
return ParseOptionValue(option, &shortOption[1]);
}
}
+1
View File
@@ -23,6 +23,7 @@
#include "../platform/platform.h"
#include "../localisation/Language.h"
#include "../core/Console.hpp"
#include "../core/Guard.hpp"
#include "../core/Memory.hpp"
#include "../core/Path.hpp"
#include "../core/String.hpp"
+1 -1
View File
@@ -47,7 +47,7 @@ static exitcode_t HandleUri(const std::string &uri)
{
exitcode_t result = EXITCODE_CONTINUE;
auto args = String::Split(uri, "/");
if (args.size() > 0)
if (!args.empty())
{
#ifndef DISABLE_NETWORK
std::string arg = args[0];
+1 -1
View File
@@ -135,7 +135,7 @@ namespace File
}
free(pathW);
#else
struct stat statInfo;
struct stat statInfo{};
if (stat(path.c_str(), &statInfo) == 0)
{
lastModified = statInfo.st_mtime;
+4 -4
View File
@@ -66,7 +66,7 @@ private:
{
std::string Path;
std::vector<DirectoryChild> Listing;
sint32 Index;
sint32 Index = 0;
};
// Options
@@ -75,7 +75,7 @@ private:
bool _recurse;
// State
bool _started;
bool _started = false;
std::stack<DirectoryState> _directoryStack;
// Current
@@ -132,7 +132,7 @@ public:
PushState(_rootPath);
}
while (_directoryStack.size() != 0)
while (!_directoryStack.empty())
{
DirectoryState * state = &_directoryStack.top();
state->Index++;
@@ -337,7 +337,7 @@ private:
String::Set(path, pathSize, directory);
Path::Append(path, pathSize, node->d_name);
struct stat statInfo;
struct stat statInfo{};
sint32 statRes = stat(path, &statInfo);
if (statRes != -1)
{
+2
View File
@@ -15,6 +15,8 @@
#pragma endregion
#include <cassert>
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include "../common.h"
+1 -1
View File
@@ -155,7 +155,7 @@ static void scrolling_text_format(utf8 *dst, size_t size, rct_draw_scroll_text *
extern bool TempForScrollText;
#define SCROLL_POS(x, y) ((y * 64) + x)
#define SCROLL_POS(x, y) (((y) * 64) + (x))
// clang-format off
static constexpr const sint16 _scrollpos0[] = {
+2 -2
View File
@@ -66,8 +66,8 @@ in the result FT_Bitmap after the FT_Render_Glyph() call. */
#define NUM_GRAYS 256
/* Handy routines for converting from fixed point */
#define FT_FLOOR(X) ((X & -64) / 64)
#define FT_CEIL(X) (((X + 63) & -64) / 64)
#define FT_FLOOR(X) (((X) & -64) / 64)
#define FT_CEIL(X) ((((X) + 63) & -64) / 64)
#define CACHED_METRICS 0x10
#define CACHED_BITMAP 0x01
+5 -5
View File
@@ -29,10 +29,10 @@ enum class TextAlignment
struct TextPaint
{
uint8 Colour;
sint16 SpriteBase;
bool UnderlineText;
TextAlignment Alignment;
uint8 Colour = 0;
sint16 SpriteBase = 0;
bool UnderlineText = false;
TextAlignment Alignment = TextAlignment::LEFT;
};
class StaticLayout
@@ -40,7 +40,7 @@ class StaticLayout
private:
utf8string _buffer;
TextPaint _paint;
sint32 _lineCount;
sint32 _lineCount = 0;
sint32 _lineHeight;
sint32 _maxWidth;
-5
View File
@@ -470,11 +470,6 @@ X8DrawingContext::X8DrawingContext(X8DrawingEngine * engine)
_engine = engine;
}
X8DrawingContext::~X8DrawingContext()
{
}
IDrawingEngine * X8DrawingContext::GetEngine()
{
return _engine;
-1
View File
@@ -134,7 +134,6 @@ namespace OpenRCT2
public:
explicit X8DrawingContext(X8DrawingEngine * engine);
~X8DrawingContext() override;
IDrawingEngine * GetEngine() override;
+4 -4
View File
@@ -304,7 +304,7 @@ UIThemeWindowEntry UIThemeWindowEntry::FromJson(const WindowThemeDesc * wtDesc,
uint8 numColours = (uint8)json_array_size(jsonColours);
numColours = Math::Min(numColours, wtDesc->NumColours);
UIThemeWindowEntry result;
UIThemeWindowEntry result { };
result.WindowClass = wtDesc->WindowClass;
result.Theme = wtDesc->DefaultTheme;
@@ -524,7 +524,7 @@ namespace ThemeManager
NumPredefinedThemes = 0;
for (auto predefinedTheme : PredefinedThemes)
{
AvailableTheme theme;
AvailableTheme theme {};
theme.Name = predefinedTheme.Theme->Name;
outThemes->push_back(std::move(theme));
@@ -538,7 +538,7 @@ namespace ThemeManager
auto fileInfo = scanner->GetFileInfo();
auto name = Path::GetFileNameWithoutExtension(std::string(fileInfo->Name));
AvailableTheme theme;
AvailableTheme theme {};
theme.Name = name;
theme.Path = GetThemeFileName(theme.Name);
outThemes->push_back(std::move(theme));
@@ -747,7 +747,7 @@ uint8 theme_get_colour(rct_windowclass wc, uint8 index)
void theme_set_colour(rct_windowclass wc, uint8 index, colour_t colour)
{
UIThemeWindowEntry entry;
UIThemeWindowEntry entry { };
entry.WindowClass = wc;
auto currentEntry = (UIThemeWindowEntry *)ThemeManager::CurrentTheme->GetEntry(wc);
+1 -6
View File
@@ -123,12 +123,7 @@ static bool news_item_is_current_old()
remove_time = 256;
}
if (news_item_get(0)->Ticks >= remove_time)
{
return true;
}
return false;
return news_item_get(0)->Ticks >= remove_time;
}
/**
+8 -8
View File
@@ -668,7 +668,7 @@ bool Network::CheckSRAND(uint32 tick, uint32 srand0)
server_srand0_tick = 0;
// Check that the server and client sprite hashes match
const char *client_sprite_hash = sprite_checksum();
const bool sprites_mismatch = server_sprite_hash[0] != '\0' && strcmp(client_sprite_hash, server_sprite_hash);
const bool sprites_mismatch = server_sprite_hash[0] != '\0' && strcmp(client_sprite_hash, server_sprite_hash) != 0;
// Check PRNG values and sprite hashes, if exist
if ((srand0 != server_srand0) || sprites_mismatch) {
#ifdef DEBUG_DESYNC
@@ -764,7 +764,7 @@ NetworkGroup* Network::AddGroup()
}
}
if (newid != -1) {
std::unique_ptr<NetworkGroup> group(new NetworkGroup); // change to make_unique in c++14
auto group = std::make_unique<NetworkGroup>();
group->Id = newid;
group->SetName("Group #" + std::to_string(newid));
addedgroup = group.get();
@@ -845,17 +845,17 @@ void Network::SaveGroups()
void Network::SetupDefaultGroups()
{
std::unique_ptr<NetworkGroup> admin(new NetworkGroup()); // change to make_unique in c++14
auto admin = std::make_unique<NetworkGroup>();
admin->SetName("Admin");
admin->ActionsAllowed.fill(0xFF);
admin->Id = 0;
group_list.push_back(std::move(admin));
std::unique_ptr<NetworkGroup> spectator(new NetworkGroup()); // change to make_unique in c++14
auto spectator = std::make_unique<NetworkGroup>();
spectator->SetName("Spectator");
spectator->ToggleActionPermission(0); // Chat
spectator->Id = 1;
group_list.push_back(std::move(spectator));
std::unique_ptr<NetworkGroup> user(new NetworkGroup()); // change to make_unique in c++14
auto user = std::make_unique<NetworkGroup>();
user->SetName("User");
user->ActionsAllowed.fill(0xFF);
user->ToggleActionPermission(15); // Kick Player
@@ -896,7 +896,7 @@ void Network::LoadGroups()
for (size_t i = 0; i < groupCount; i++) {
json_t * jsonGroup = json_array_get(json_groups, i);
std::unique_ptr<NetworkGroup> newgroup(new NetworkGroup(NetworkGroup::FromJson(jsonGroup))); // change to make_unique in c++14
auto newgroup = std::make_unique<NetworkGroup>(NetworkGroup::FromJson(jsonGroup));
group_list.push_back(std::move(newgroup));
}
json_t * jsonDefaultGroup = json_object_get(json, "default_group");
@@ -1956,7 +1956,7 @@ void Network::Server_Handle_AUTH(NetworkConnection& connection, NetworkPacket& p
connection.AuthStatus = NETWORK_AUTH_BADNAME;
} else
if (!passwordless) {
if ((!password || strlen(password) == 0) && _password.size() > 0) {
if ((!password || strlen(password) == 0) && !_password.empty()) {
connection.AuthStatus = NETWORK_AUTH_REQUIREPASSWORD;
} else
if (password && _password != password) {
@@ -2474,7 +2474,7 @@ void Network::Client_Handle_GROUPLIST(NetworkConnection& connection, NetworkPack
for (uint32 i = 0; i < size; i++) {
NetworkGroup group;
group.Read(packet);
std::unique_ptr<NetworkGroup> newgroup(new NetworkGroup(group)); // change to make_unique in c++14
auto newgroup = std::make_unique<NetworkGroup>(group);
group_list.push_back(std::move(newgroup));
}
}
+1 -1
View File
@@ -58,7 +58,7 @@ public:
private:
std::list<std::unique_ptr<NetworkPacket>> _outboundPackets;
uint32 _lastPacketTime;
uint32 _lastPacketTime = 0;
utf8 * _lastDisconnectReason = nullptr;
bool SendPacket(NetworkPacket &packet);
-4
View File
@@ -25,10 +25,6 @@ NetworkGroup::NetworkGroup()
ActionsAllowed = { 0 };
}
NetworkGroup::~NetworkGroup()
{
}
NetworkGroup NetworkGroup::FromJson(const json_t * json)
{
NetworkGroup group;
+1 -2
View File
@@ -25,13 +25,12 @@
class NetworkGroup final
{
public:
std::array<uint8, 8> ActionsAllowed;
std::array<uint8, 8> ActionsAllowed{};
uint8 Id = 0;
static NetworkGroup FromJson(const json_t * json);
NetworkGroup();
~NetworkGroup();
const std::string & GetName() const;
void SetName(std::string name);
+4 -2
View File
@@ -19,14 +19,16 @@
#include "NetworkTypes.h"
#include "NetworkPacket.h"
#include <memory>
std::unique_ptr<NetworkPacket> NetworkPacket::Allocate()
{
return std::unique_ptr<NetworkPacket>(new NetworkPacket); // change to make_unique in c++14
return std::make_unique<NetworkPacket>();
}
std::unique_ptr<NetworkPacket> NetworkPacket::Duplicate(NetworkPacket &packet)
{
return std::unique_ptr<NetworkPacket>(new NetworkPacket(packet)); // change to make_unique in c++14
return std::make_unique<NetworkPacket>(packet);
}
uint8 * NetworkPacket::GetData()
+8 -7
View File
@@ -24,6 +24,9 @@
#include <thread>
// clang-format off
// MSVC: include <math.h> here otherwise PI gets defined twice
#include <cmath>
#ifdef _WIN32
// winsock2 must be included before windows.h
#include <winsock2.h>
@@ -90,9 +93,7 @@ private:
std::string _error;
public:
TcpSocket()
{
}
TcpSocket() = default;
~TcpSocket() override
{
@@ -125,7 +126,7 @@ public:
throw std::runtime_error("Socket not closed.");
}
sockaddr_storage ss;
sockaddr_storage ss { };
sint32 ss_len;
if (!ResolveAddress(address, port, &ss, &ss_len))
{
@@ -185,7 +186,7 @@ public:
{
throw std::runtime_error("Socket not listening.");
}
struct sockaddr_storage client_addr;
struct sockaddr_storage client_addr { };
socklen_t client_len = sizeof(struct sockaddr_storage);
ITcpSocket * tcpSocket = nullptr;
@@ -238,7 +239,7 @@ public:
// Resolve address
_status = SOCKET_STATUS_RESOLVING;
sockaddr_storage ss;
sockaddr_storage ss { };
sint32 ss_len;
if (!ResolveAddress(address, port, &ss, &ss_len))
{
@@ -290,7 +291,7 @@ public:
#pragma warning(disable : 4548) // expression before comma has no effect; expected expression with side-effect
FD_SET(_socket, &writeFD);
#pragma warning(pop)
timeval timeout;
timeval timeout { };
timeout.tv_sec = 0;
timeout.tv_usec = 0;
if (select((sint32)(_socket + 1), nullptr, &writeFD, nullptr, &timeout) > 0)
+1 -1
View File
@@ -242,7 +242,7 @@ private:
uint32 server_tick = 0;
uint32 server_srand0 = 0;
uint32 server_srand0_tick = 0;
char server_sprite_hash[EVP_MAX_MD_SIZE + 1];
char server_sprite_hash[EVP_MAX_MD_SIZE + 1]{};
uint8 player_id = 0;
std::list<std::unique_ptr<NetworkConnection>> client_connection_list;
std::multiset<GameCommand> game_command_queue;
+1 -1
View File
@@ -139,7 +139,7 @@ class Object
{
private:
char * _identifier;
rct_object_entry _objectEntry;
rct_object_entry _objectEntry{};
StringTable _stringTable;
ImageTable _imageTable;
+1 -1
View File
@@ -64,7 +64,7 @@ void StringTable::Read(IReadObjectContext * context, IStream * stream, uint8 id)
(rct2LanguageId <= RCT2_LANGUAGE_ID_PORTUGUESE) ?
RCT2ToOpenRCT2LanguageId[rct2LanguageId] :
LANGUAGE_UNDEFINED;
StringTableEntry entry;
StringTableEntry entry { };
entry.Id = id;
entry.LanguageId = languageId;
+1 -1
View File
@@ -2057,7 +2057,7 @@ void rct_peep::UpdateAnswering()
{
return;
}
if (current_ride != rideEntranceExitElement->properties.entrance.ride_index)
return;
+11 -11
View File
@@ -122,18 +122,18 @@ private:
EntryList _waterEntry;
// Lookup tables for converting from RCT1 hard coded types to the new dynamic object entries
uint8 _rideTypeToRideEntryMap[RCT1_RIDE_TYPE_COUNT];
uint8 _vehicleTypeToRideEntryMap[RCT1_VEHICLE_TYPE_COUNT];
uint8 _smallSceneryTypeToEntryMap[256];
uint8 _largeSceneryTypeToEntryMap[256];
uint8 _wallTypeToEntryMap[256];
uint8 _pathTypeToEntryMap[24];
uint8 _pathAdditionTypeToEntryMap[16];
uint8 _sceneryThemeTypeToEntryMap[24];
uint8 _rideTypeToRideEntryMap[RCT1_RIDE_TYPE_COUNT]{};
uint8 _vehicleTypeToRideEntryMap[RCT1_VEHICLE_TYPE_COUNT]{};
uint8 _smallSceneryTypeToEntryMap[256]{};
uint8 _largeSceneryTypeToEntryMap[256]{};
uint8 _wallTypeToEntryMap[256]{};
uint8 _pathTypeToEntryMap[24]{};
uint8 _pathAdditionTypeToEntryMap[16]{};
uint8 _sceneryThemeTypeToEntryMap[24]{};
// Research
uint8 _researchRideEntryUsed[MAX_RIDE_OBJECTS];
uint8 _researchRideTypeUsed[RCT1_RIDE_TYPE_COUNT];
uint8 _researchRideEntryUsed[MAX_RIDE_OBJECTS]{};
uint8 _researchRideTypeUsed[RCT1_RIDE_TYPE_COUNT]{};
// Scenario repository - used for determining scenario name
IScenarioRepository * _scenarioRepository = GetScenarioRepository();
@@ -206,7 +206,7 @@ public:
CreateAvailableObjectMappings();
auto missingObjects = GetInvalidObjects();
if (missingObjects.size() > 0)
if (!missingObjects.empty())
{
return ParkLoadResult::CreateMissingObjects(missingObjects);
}
+1 -1
View File
@@ -44,7 +44,7 @@ public:
void ExportRide(rct2_ride * dst, const Ride * src);
private:
rct_s6_data _s6;
rct_s6_data _s6{};
void Save(IStream * stream, bool isScenario);
static uint32 GetLoanHash(money32 initialCash, money32 bankLoan, uint32 maxBankLoan);
+2 -10
View File
@@ -2279,22 +2279,14 @@ bool track_element_is_covered(sint32 trackElementType)
bool track_element_is_booster(uint8 rideType, uint8 trackType)
{
// Boosters share their ID with the Spinning Control track.
if (rideType != RIDE_TYPE_STEEL_WILD_MOUSE && trackType == TRACK_ELEM_BOOSTER)
{
return true;
}
return false;
return rideType != RIDE_TYPE_STEEL_WILD_MOUSE && trackType == TRACK_ELEM_BOOSTER;
}
bool track_element_has_speed_setting(uint8 trackType)
{
// This does not check if the element is really a Spinning Control track instead of a booster,
// but this does not cause problems.
if (trackType == TRACK_ELEM_BRAKES || trackType == TRACK_ELEM_BOOSTER)
{
return true;
}
return false;
return trackType == TRACK_ELEM_BRAKES || trackType == TRACK_ELEM_BOOSTER;
}
uint8 track_element_get_seat_rotation(const rct_tile_element * tileElement)
+1 -3
View File
@@ -55,7 +55,7 @@ std::string GetNameFromTrackPath(const std::string &path)
{
std::string name = Path::GetFileNameWithoutExtension(path);
//The track name should be the file name until the first instance of a dot
name = name.substr(0, name.find_first_of("."));
name = name.substr(0, name.find_first_of('.'));
return name;
}
@@ -150,8 +150,6 @@ public:
Guard::ArgumentNotNull(env);
}
~TrackDesignRepository() = default;
size_t GetCount() const override
{
return _items.size();
+6 -15
View File
@@ -90,7 +90,7 @@ static void vehicle_kill_all_passengers(rct_vehicle * vehicle);
static bool vehicle_can_depart_synchronised(rct_vehicle * vehicle);
#define NO_SCREAM 254
#define VEHICLE_INVALID_ID -1
#define VEHICLE_INVALID_ID (-1)
#define VEHICLE_MAX_SPIN_SPEED 1536
#define VEHICLE_MAX_SPIN_SPEED_FOR_STOPPING 700
@@ -1832,7 +1832,7 @@ static void vehicle_update_measurements(rct_vehicle * vehicle)
rct_tile_element * tile_element = map_get_surface_element_at({x, y});
// If vehicle above ground.
if (tile_element->base_height * 8 <= z)
if (tile_element->base_height * 8 <= z)
{
// Set tile_element to first element. Since elements aren't always ordered by base height,
// we must start at the first element and iterate through each tile element.
@@ -1866,7 +1866,7 @@ static void vehicle_update_measurements(rct_vehicle * vehicle)
cover_found = true;
break;
}
// Iterate through each tile_element.
// Iterate through each tile_element.
} while (!tile_element_is_last_for_tile(tile_element++));
if (cover_found == false)
@@ -3163,11 +3163,7 @@ static bool vehicle_next_tower_element_is_top(rct_vehicle * vehicle)
return true;
}
if (track_element_get_type(tileElement + 2) == TRACK_ELEM_TOWER_SECTION)
{
return false;
}
return true;
return track_element_get_type(tileElement + 2) != TRACK_ELEM_TOWER_SECTION;
}
/**
@@ -7511,12 +7507,7 @@ static bool loc_6DB38B(rct_vehicle * vehicle, rct_tile_element * tileElement)
sint32 trackType = track_element_get_type(tileElement);
sint32 vangleStart = TrackDefinitions[trackType].vangle_start;
if (vangleStart != _vehicleVAngleEndF64E36 || bankStart != _vehicleBankEndF64E37)
{
return false;
}
return true;
return vangleStart == _vehicleVAngleEndF64E36 && bankStart == _vehicleBankEndF64E37;
}
static void loc_6DB481(rct_vehicle * vehicle)
@@ -9521,7 +9512,7 @@ static void vehicle_update_track_motion_powered_ride_acceleration(rct_vehicle *
uint16 trackType = vehicle->track_direction >> 2;
if (trackType == TRACK_ELEM_LEFT_QUARTER_TURN_1_TILE)
{
{
speedModifier = (vehicle->var_CD == 5) ? HALF_SPEED : THREE_QUARTER_SPEED;
}
else if (trackType == TRACK_ELEM_RIGHT_QUARTER_TURN_1_TILE)