From 9023b158753d5889af78575cb56fe731991086b1 Mon Sep 17 00:00:00 2001 From: Kevin Hake Date: Tue, 10 Aug 2021 22:55:37 -0500 Subject: [PATCH 1/3] Mass refactor 'unsigned int' ==> 'int' --- src/3do_test.cpp | 2 +- src/bridge.cpp | 2 +- src/fnt_test.cpp | 18 ++-- src/gaf_test.cpp | 2 +- src/hpi_test.cpp | 10 +-- src/main.cpp | 12 +-- src/pcx_test.cpp | 4 +- src/rwe/AudioService.cpp | 8 +- src/rwe/AudioService.h | 4 +- src/rwe/BoxTreeSplit.cpp | 2 +- src/rwe/BoxTreeSplit.h | 46 +++++----- src/rwe/ColorPalette.cpp | 2 +- src/rwe/CursorService.cpp | 4 +- src/rwe/GameHash_util.test.cpp | 2 +- src/rwe/GameNetworkService.cpp | 8 +- src/rwe/GameNetworkService.h | 4 +- src/rwe/GameScene.cpp | 10 +-- src/rwe/GameScene.h | 10 +-- src/rwe/LoadingNetworkService.cpp | 2 +- src/rwe/LoadingNetworkService.h | 2 +- src/rwe/LoadingScene.cpp | 30 +++---- src/rwe/LoadingScene.h | 12 +-- src/rwe/MainMenuModel.cpp | 2 +- src/rwe/MainMenuScene.cpp | 40 ++++----- src/rwe/MeshService.cpp | 2 +- src/rwe/MeshService.h | 2 +- src/rwe/MovementClassCollisionService.h | 2 +- src/rwe/PlayerColorIndex.cpp | 4 +- src/rwe/PlayerColorIndex.h | 4 +- src/rwe/PlayerCommandService.cpp | 4 +- src/rwe/PlayerCommandService.h | 2 +- src/rwe/RenderService.cpp | 20 ++--- src/rwe/RenderService.h | 2 +- src/rwe/SceneManager.h | 6 +- src/rwe/SceneTime.h | 2 +- src/rwe/SharedHandle.h | 8 +- src/rwe/SideData.cpp | 12 +-- src/rwe/SideData.h | 14 +-- src/rwe/TextureService.cpp | 8 +- src/rwe/TextureService.h | 6 +- src/rwe/UnitFactory.cpp | 20 ++--- src/rwe/UnitFactory.h | 6 +- src/rwe/VectorMap.h | 8 +- src/rwe/VectorMap.test.cpp | 2 +- src/rwe/Viewport.cpp | 6 +- src/rwe/Viewport.h | 10 +-- src/rwe/atlas_util.cpp | 10 +-- src/rwe/cob/CobEnvironment.cpp | 12 +-- src/rwe/cob/CobEnvironment.h | 24 ++--- src/rwe/cob/CobExecutionContext.cpp | 18 ++-- src/rwe/cob/CobExecutionContext.h | 6 +- src/rwe/cob/CobExecutionService.cpp | 2 +- src/rwe/cob/CobFunction.cpp | 4 +- src/rwe/cob/CobFunction.h | 8 +- src/rwe/cob/CobThread.cpp | 2 +- src/rwe/cob/CobThread.h | 4 +- src/rwe/dump_util.test.cpp | 2 +- src/rwe/events.cpp | 8 +- src/rwe/events.h | 10 +-- src/rwe/fixed_point.cpp | 2 +- src/rwe/grid/DiscreteRect.cpp | 44 ++++----- src/rwe/grid/DiscreteRect.h | 12 +-- src/rwe/grid/DiscreteRect.test.cpp | 2 +- src/rwe/grid/EightWayDirection.cpp | 12 +-- src/rwe/grid/EightWayDirection.h | 4 +- src/rwe/grid/Grid.h | 89 ++++++++++--------- src/rwe/io/_3do/_3do.cpp | 6 +- src/rwe/io/_3do/_3do.h | 8 +- src/rwe/io/cob/Cob.cpp | 8 +- src/rwe/io/cob/Cob.h | 4 +- src/rwe/io/fbi/UnitFbi.h | 20 ++--- src/rwe/io/fbi/io.cpp | 2 +- src/rwe/io/featuretdf/FeatureDefinition.h | 24 ++--- src/rwe/io/fnt/Fnt.cpp | 4 +- src/rwe/io/fnt/Fnt.h | 4 +- src/rwe/io/gaf/GafReaderAdapter.h | 4 +- src/rwe/io/gui/gui.h | 12 +-- src/rwe/io/pcx/pcx.h | 4 +- src/rwe/io/tnt/TntArchive.cpp | 20 ++--- src/rwe/io/tnt/TntArchive.h | 6 +- src/rwe/io/weapontdf/WeaponTdf.cpp | 10 +-- src/rwe/io/weapontdf/WeaponTdf.h | 50 +++++------ src/rwe/network_util.cpp | 2 +- src/rwe/network_util.h | 2 +- src/rwe/observable/Subject.h | 2 +- src/rwe/pathfinding/AStarPathFinder.h | 4 +- .../pathfinding/AbstractUnitPathFinder.cpp | 6 +- src/rwe/pathfinding/AbstractUnitPathFinder.h | 8 +- src/rwe/pathfinding/OctileDistance.cpp | 4 +- src/rwe/pathfinding/OctileDistance.h | 8 +- src/rwe/pathfinding/PathCost.cpp | 2 +- src/rwe/pathfinding/PathCost.h | 4 +- src/rwe/pathfinding/PathFindingService.cpp | 4 +- src/rwe/pathfinding/PathFindingService.h | 2 +- src/rwe/pathfinding/UnitPathFinder.cpp | 6 +- src/rwe/pathfinding/UnitPathFinder.h | 4 +- .../pathfinding/UnitPerimeterPathFinder.cpp | 6 +- src/rwe/pathfinding/UnitPerimeterPathFinder.h | 4 +- src/rwe/pathfinding/pathfinding_utils.cpp | 4 +- src/rwe/pathfinding/pathfinding_utils.h | 4 +- src/rwe/render/GlMesh.cpp | 2 +- src/rwe/render/GlMesh.h | 4 +- src/rwe/render/GraphicsContext.cpp | 6 +- src/rwe/render/GraphicsContext.h | 6 +- src/rwe/rwe_time.cpp | 4 +- src/rwe/rwe_time.h | 2 +- src/rwe/sim/Explosion.cpp | 2 +- src/rwe/sim/Explosion.h | 2 +- src/rwe/sim/FeatureId.h | 2 +- src/rwe/sim/GameSimulation.cpp | 8 +- src/rwe/sim/GameSimulation.h | 6 +- src/rwe/sim/GameTime.h | 2 +- src/rwe/sim/MapFeature.h | 2 +- src/rwe/sim/MovementClass.h | 12 +-- src/rwe/sim/MovementClassId.h | 2 +- src/rwe/sim/PlayerId.h | 2 +- src/rwe/sim/Projectile.cpp | 2 +- src/rwe/sim/Projectile.h | 4 +- src/rwe/sim/ProjectileId.h | 2 +- src/rwe/sim/Unit.cpp | 18 ++-- src/rwe/sim/Unit.h | 36 ++++---- src/rwe/sim/UnitBehaviorService.cpp | 30 +++---- src/rwe/sim/UnitBehaviorService.h | 26 +++--- src/rwe/sim/UnitId.h | 2 +- src/rwe/sim/WeaponDefinition.h | 2 +- src/rwe/sim/movement.cpp | 45 +++++----- src/rwe/sim/movement.h | 12 +-- src/rwe/ui/UiComponent.cpp | 4 +- src/rwe/ui/UiComponent.h | 16 ++-- src/rwe/ui/UiFactory.cpp | 18 ++-- src/rwe/ui/UiFactory.h | 6 +- src/rwe/ui/UiLabel.cpp | 2 +- src/rwe/ui/UiLabel.h | 2 +- src/rwe/ui/UiLightBar.cpp | 2 +- src/rwe/ui/UiLightBar.h | 4 +- src/rwe/ui/UiListBox.cpp | 34 +++---- src/rwe/ui/UiListBox.h | 26 +++--- src/rwe/ui/UiPanel.cpp | 6 +- src/rwe/ui/UiPanel.h | 6 +- src/rwe/ui/UiScrollBar.cpp | 4 +- src/rwe/ui/UiScrollBar.h | 4 +- src/rwe/ui/UiStagedButton.cpp | 6 +- src/rwe/ui/UiStagedButton.h | 8 +- src/rwe/ui/UiSurface.cpp | 4 +- src/rwe/ui/UiSurface.h | 4 +- src/rwe/util.cpp | 2 +- src/rwe/util.h | 2 +- src/texture_test.cpp | 20 ++--- 148 files changed, 674 insertions(+), 674 deletions(-) diff --git a/src/3do_test.cpp b/src/3do_test.cpp index 994cc1dde..d231dfdc0 100644 --- a/src/3do_test.cpp +++ b/src/3do_test.cpp @@ -8,7 +8,7 @@ #include #include -void print3doObject(unsigned int indent, const std::vector& os) +void print3doObject(int indent, const std::vector& os) { for (const auto& o : os) { diff --git a/src/bridge.cpp b/src/bridge.cpp index 2bcfd8fff..7d2d6bb47 100644 --- a/src/bridge.cpp +++ b/src/bridge.cpp @@ -115,7 +115,7 @@ namespace rwe { void loadPalette(std::istream& in, png::rgb_pixel* buffer) { - for (unsigned int i = 0; i < 256; ++i) + for (int i = 0; i < 256; ++i) { in.read(reinterpret_cast(&(buffer[i].red)), 1); in.read(reinterpret_cast(&(buffer[i].green)), 1); diff --git a/src/fnt_test.cpp b/src/fnt_test.cpp index c86d9f63d..0123f97b9 100644 --- a/src/fnt_test.cpp +++ b/src/fnt_test.cpp @@ -15,19 +15,19 @@ void renderFontFile(std::istream& in, std::ostream& out) std::vector v(512); png::image image(256, 512); - for (unsigned int i = 0; i < 256; ++i) + for (int i = 0; i < 256; ++i) { - auto charX = (i % 16) * 16; - auto charY = (i / 16) * 32; + int charX = (i % 16) * 16; + int charY = (i / 16) * 32; - auto byteLength = fnt.extract(i, v.data()); - auto width = byteLength / 2; - auto bitLength = byteLength * 8; + int byteLength = fnt.extract(i, v.data()); + int width = byteLength / 2; + int bitLength = byteLength * 8; - for (unsigned int j = 0; j < bitLength; ++j) + for (int j = 0; j < bitLength; ++j) { - auto dx = j % width; - auto dy = j / width; + int dx = j % width; + int dy = j / width; if (dy >= fnt.glyphHeight()) { break; diff --git a/src/gaf_test.cpp b/src/gaf_test.cpp index 214f0b921..6c25eb6d8 100644 --- a/src/gaf_test.cpp +++ b/src/gaf_test.cpp @@ -13,7 +13,7 @@ void loadPalette(const std::string& filename, png::rgb_pixel* buffer) { std::ifstream in(filename, std::ios::binary); - for (unsigned int i = 0; i < 256; ++i) + for (int i = 0; i < 256; ++i) { in.read(reinterpret_cast(&(buffer[i].red)), 1); in.read(reinterpret_cast(&(buffer[i].green)), 1); diff --git a/src/hpi_test.cpp b/src/hpi_test.cpp index 00cd40d08..eaf6e2f55 100644 --- a/src/hpi_test.cpp +++ b/src/hpi_test.cpp @@ -23,10 +23,10 @@ std::string schemeName(rwe::HpiArchive::File::CompressionScheme scheme) } } -void printDir(unsigned int indent, const std::string& name, const rwe::HpiArchive::Directory& d); -void printFile(unsigned int indent, const std::string& name, const rwe::HpiArchive::File& f); +void printDir(int indent, const std::string& name, const rwe::HpiArchive::Directory& d); +void printFile(int indent, const std::string& name, const rwe::HpiArchive::File& f); -void printEntry(unsigned int indent, const rwe::HpiArchive::DirectoryEntry& e) +void printEntry(int indent, const rwe::HpiArchive::DirectoryEntry& e) { match( e.data, @@ -38,7 +38,7 @@ void printEntry(unsigned int indent, const rwe::HpiArchive::DirectoryEntry& e) }); } -void printDir(unsigned int indent, const std::string& name, const rwe::HpiArchive::Directory& d) +void printDir(int indent, const std::string& name, const rwe::HpiArchive::Directory& d) { std::string dent(indent, ' '); std::cout << dent << name << " directory:" << std::endl; @@ -48,7 +48,7 @@ void printDir(unsigned int indent, const std::string& name, const rwe::HpiArchiv } } -void printFile(unsigned int indent, const std::string& name, const rwe::HpiArchive::File& f) +void printFile(int indent, const std::string& name, const rwe::HpiArchive::File& f) { std::string compression = schemeName(f.compressionScheme); diff --git a/src/main.cpp b/src/main.cpp index 868595712..bd71ba71f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -119,7 +119,7 @@ namespace rwe return Ok(std::move(glContext)); }; - int run(spdlog::logger& logger, const std::vector& searchPath, const PathMapping& pathMapping, const std::optional& gameParameters, unsigned int desiredWindowWidth, unsigned int desiredWindowHeight, bool fullscreen, const std::string& imGuiIniPath, GlobalConfig& globalConfig) + int run(spdlog::logger& logger, const std::vector& searchPath, const PathMapping& pathMapping, const std::optional& gameParameters, int desiredWindowWidth, int desiredWindowHeight, bool fullscreen, const std::string& imGuiIniPath, GlobalConfig& globalConfig) { logger.info(ProjectNameVersion); logger.info("Current directory: {0}", fs::current_path().string()); @@ -526,8 +526,8 @@ int main(int argc, char* argv[]) ("help", "produce help message") ("log", po::value(), "Sets the log output file path") ("state-log", po::value(), "Sets the output file for sim-state logs. This is a desync debugging feature.") - ("width", po::value()->default_value(800), "Sets the window width in pixels") - ("height", po::value()->default_value(600), "Sets the window height in pixels") + ("width", po::value()->default_value(800), "Sets the window width in pixels") + ("height", po::value()->default_value(600), "Sets the window height in pixels") ("fullscreen", po::bool_switch(), "Starts the application in fullscreen mode") ("interface-mode", po::value()->default_value("left-click"), "left-click or right-click") ("data-path", po::value>(), "Sets the location(s) to search for game data") @@ -591,7 +591,7 @@ int main(int argc, char* argv[]) gameParameters->stateLogFile = vm["state-log"].as(); } gameParameters->localNetworkPort = vm["port"].as(); - unsigned int playerIndex = 0; + int playerIndex = 0; if (players.size() > 10) { throw std::runtime_error("too many players"); @@ -615,8 +615,8 @@ int main(int argc, char* argv[]) gameDataPaths.emplace_back(*localDataPath) /= "Data"; } - auto screenWidth = vm["width"].as(); - auto screenHeight = vm["height"].as(); + auto screenWidth = vm["width"].as(); + auto screenHeight = vm["height"].as(); auto fullscreen = vm["fullscreen"].as(); auto pathMapping = constructDefaultPathMapping(); diff --git a/src/pcx_test.cpp b/src/pcx_test.cpp index e4cdc78a9..fd03935c5 100644 --- a/src/pcx_test.cpp +++ b/src/pcx_test.cpp @@ -25,8 +25,8 @@ int convert(const std::string& inFile, const std::string& outFile) auto decodedData = decoder.decodeImage(); auto palette = decoder.decodePalette(); - auto width = decoder.getWidth(); - auto height = decoder.getHeight(); + int width = decoder.getWidth(); + int height = decoder.getHeight(); png::image image(width, height); for (png::uint_32 y = 0; y < height; ++y) diff --git a/src/rwe/AudioService.cpp b/src/rwe/AudioService.cpp index b81f75832..567b35791 100644 --- a/src/rwe/AudioService.cpp +++ b/src/rwe/AudioService.cpp @@ -49,11 +49,11 @@ namespace rwe return sound; } - void AudioService::reserveChannels(unsigned int count) + void AudioService::reserveChannels(int count) { - auto num = sdlMixerContext->reserveChannels(count); + int num = sdlMixerContext->reserveChannels(count); assert(num >= 0); - if (static_cast(num) < count) + if (num < count) { throw std::runtime_error("Failed to reserve audio channels"); } @@ -64,7 +64,7 @@ namespace rwe sdlMixerContext->haltChannel(channel); } - void AudioService::playSoundIfFree(const AudioService::SoundHandle& sound, unsigned int channel) + void AudioService::playSoundIfFree(const AudioService::SoundHandle& sound, int channel) { if (sdlMixerContext->playing(channel)) { diff --git a/src/rwe/AudioService.h b/src/rwe/AudioService.h index 185767c03..5c4259895 100644 --- a/src/rwe/AudioService.h +++ b/src/rwe/AudioService.h @@ -54,9 +54,9 @@ namespace rwe std::optional loadSound(const std::string& soundName); - void reserveChannels(unsigned int count); + void reserveChannels(int count); - void playSoundIfFree(const SoundHandle& sound, unsigned int channel); + void playSoundIfFree(const SoundHandle& sound, int channel); void setVolume(int channel, int volume); diff --git a/src/rwe/BoxTreeSplit.cpp b/src/rwe/BoxTreeSplit.cpp index 8fdf1277d..3a9fc4665 100644 --- a/src/rwe/BoxTreeSplit.cpp +++ b/src/rwe/BoxTreeSplit.cpp @@ -2,7 +2,7 @@ namespace rwe { - Size::Size(std::size_t width, std::size_t height) : width(width), height(height) + Size::Size(int width, int height) : width(width), height(height) { } } diff --git a/src/rwe/BoxTreeSplit.h b/src/rwe/BoxTreeSplit.h index 8f0ca9853..9eaee7229 100644 --- a/src/rwe/BoxTreeSplit.h +++ b/src/rwe/BoxTreeSplit.h @@ -11,16 +11,16 @@ namespace rwe template struct BoxPackInfoEntry { - unsigned int x; - unsigned int y; + int x; + int y; T value; }; template struct BoxPackInfo { - unsigned int width; - unsigned int height; + int width; + int height; std::vector> entries; }; @@ -40,8 +40,8 @@ namespace rwe template struct BoxTreeNode { - unsigned int width; - unsigned int height; + int width; + int height; using Union = std::variant, BoxTreeLeaf>; @@ -52,13 +52,13 @@ namespace rwe std::unique_ptr&& left, std::unique_ptr&& right); - BoxTreeNode(unsigned int width, unsigned int height); + BoxTreeNode(int width, int height); - BoxTreeNode(unsigned int width, unsigned int height, const T& value); + BoxTreeNode(int width, int height, const T& value); - BoxTreeNode(unsigned int width, unsigned int height, T&& value); + BoxTreeNode(int width, int height, T&& value); - std::optional*> findNode(unsigned int itemWidth, unsigned int itemHeight); + std::optional*> findNode(int itemWidth, int itemHeight); std::vector> walk(); }; @@ -97,19 +97,19 @@ namespace rwe { std::unique_ptr> root; - BoxTree(unsigned int width, unsigned int height, const T& value) + BoxTree(int width, int height, const T& value) : root(std::make_unique>(width, height, value)) { } - BoxTree(unsigned int width, unsigned int height, T&& value) + BoxTree(int width, int height, T&& value) : root(std::make_unique>(width, height, std::move(value))) { } - BoxTreeNode* findOrCreateNode(unsigned int itemWidth, unsigned int itemHeight); + BoxTreeNode* findOrCreateNode(int itemWidth, int itemHeight); - void insert(unsigned int itemWidth, unsigned int itemHeight, const T& item); + void insert(int itemWidth, int itemHeight, const T& item); }; enum class GrowDirection @@ -119,7 +119,7 @@ namespace rwe }; template - BoxTreeNode* BoxTree::findOrCreateNode(unsigned int itemWidth, unsigned int itemHeight) + BoxTreeNode* BoxTree::findOrCreateNode(int itemWidth, int itemHeight) { // find a leaf node big enough to fit the box auto node = root->findNode(itemWidth, itemHeight); @@ -165,7 +165,7 @@ namespace rwe } template - void BoxTree::insert(unsigned int itemWidth, unsigned int itemHeight, const T& item) + void BoxTree::insert(int itemWidth, int itemHeight, const T& item) { auto node = findOrCreateNode(itemWidth, itemHeight); @@ -211,25 +211,25 @@ namespace rwe } template - BoxTreeNode::BoxTreeNode(unsigned int width, unsigned int height) + BoxTreeNode::BoxTreeNode(int width, int height) : width(width), height(height), value(BoxTreeLeaf()) { } template - BoxTreeNode::BoxTreeNode(unsigned int width, unsigned int height, const T& value) + BoxTreeNode::BoxTreeNode(int width, int height, const T& value) : width(width), height(height), value(BoxTreeLeaf(value)) { } template - BoxTreeNode::BoxTreeNode(unsigned int width, unsigned int height, T&& value) + BoxTreeNode::BoxTreeNode(int width, int height, T&& value) : width(width), height(height), value(BoxTreeLeaf(std::move(value))) { } template - std::optional*> BoxTreeNode::findNode(unsigned int itemWidth, unsigned int itemHeight) + std::optional*> BoxTreeNode::findNode(int itemWidth, int itemHeight) { if (itemWidth > width || itemHeight > height) { @@ -297,11 +297,11 @@ namespace rwe struct Size { - std::size_t width; - std::size_t height; + int width; + int height; Size() = default; - Size(std::size_t width, std::size_t height); + Size(int width, int height); }; template diff --git a/src/rwe/ColorPalette.cpp b/src/rwe/ColorPalette.cpp index 2837ac04a..a469a4dfc 100644 --- a/src/rwe/ColorPalette.cpp +++ b/src/rwe/ColorPalette.cpp @@ -16,7 +16,7 @@ namespace rwe std::vector colors(256); - for (unsigned int i = 0; i < 256; ++i) + for (int i = 0; i < 256; ++i) { colors[i].r = static_cast(vector[(4 * i)]); colors[i].g = static_cast(vector[(4 * i) + 1]); diff --git a/src/rwe/CursorService.cpp b/src/rwe/CursorService.cpp index 3d422f539..a65bb8444 100644 --- a/src/rwe/CursorService.cpp +++ b/src/rwe/CursorService.cpp @@ -37,8 +37,8 @@ namespace rwe auto timeInMillis = timeService->getTicks(); const auto& frames = currentCursor->sprites; - unsigned int frameRateInSeconds = 6; - unsigned int millisPerFrame = 1000 / frameRateInSeconds; + int frameRateInSeconds = 6; + int millisPerFrame = 1000 / frameRateInSeconds; auto frameIndex = (timeInMillis / millisPerFrame) % frames.size(); diff --git a/src/rwe/GameHash_util.test.cpp b/src/rwe/GameHash_util.test.cpp index af2b18c98..e78f7153d 100644 --- a/src/rwe/GameHash_util.test.cpp +++ b/src/rwe/GameHash_util.test.cpp @@ -5,7 +5,7 @@ namespace rwe { struct IdTag; - using Id = OpaqueId; + using Id = OpaqueId; enum class TestEnum { diff --git a/src/rwe/GameNetworkService.cpp b/src/rwe/GameNetworkService.cpp index c975f04cb..299e3b70c 100644 --- a/src/rwe/GameNetworkService.cpp +++ b/src/rwe/GameNetworkService.cpp @@ -66,7 +66,7 @@ namespace rwe SceneTime GameNetworkService::estimateAvergeSceneTime(SceneTime localSceneTime) { - std::promise result; + std::promise result; ioContext.post([this, localSceneTime, &result]() { auto time = getTimestamp(); auto otherTimes = choose(endpoints, [](const auto& e) { return e.lastKnownSceneTime; }); @@ -227,7 +227,7 @@ namespace rwe } } - void GameNetworkService::receive(const boost::system::error_code& error, std::size_t receivedBytes) + void GameNetworkService::receive(const boost::system::error_code& error, int receivedBytes) { if (error) { @@ -317,7 +317,7 @@ namespace rwe spdlog::get("rwe")->debug("Average RTT: {0}ms", endpoint.averageRoundTripTime); } - auto extraFrames = static_cast((endpoint.averageRoundTripTime / 2.0f) * SimTicksPerSecond / 1000.0f); + auto extraFrames = static_cast((endpoint.averageRoundTripTime / 2.0f) * SimTicksPerSecond / 1000.0f); endpoint.lastKnownSceneTime = std::make_pair(SceneTime(message.current_scene_time() + extraFrames), receiveTime); spdlog::get("rwe")->debug("Estimated peer scene time: {0}", endpoint.lastKnownSceneTime->first.value); @@ -333,7 +333,7 @@ namespace rwe auto firstRelevantCommandIndex = (endpoint.nextCommandToReceive - firstCommandNumber).value; // if the packet is relevant (contains new information), process it - if (firstRelevantCommandIndex < static_cast(message.command_set_size())) + if (firstRelevantCommandIndex < static_cast(message.command_set_size())) { endpoint.lastReceiveTime = receiveTime; diff --git a/src/rwe/GameNetworkService.h b/src/rwe/GameNetworkService.h index 1286afe6c..a1c81e0f6 100644 --- a/src/rwe/GameNetworkService.h +++ b/src/rwe/GameNetworkService.h @@ -19,7 +19,7 @@ namespace rwe { struct SequenceNumberTag; - using SequenceNumber = OpaqueUnit; + using SequenceNumber = OpaqueUnit; class GameNetworkService { @@ -132,6 +132,6 @@ namespace rwe void send(EndpointInfo& endpoint); - void receive(const boost::system::error_code& error, std::size_t receivedBytes); + void receive(const boost::system::error_code& error, int receivedBytes); }; } diff --git a/src/rwe/GameScene.cpp b/src/rwe/GameScene.cpp index df9ffa177..43b3d9fbb 100644 --- a/src/rwe/GameScene.cpp +++ b/src/rwe/GameScene.cpp @@ -494,8 +494,8 @@ namespace rwe if (waypointIcon) { auto timeInMillis = sceneContext.timeService->getTicks(); - unsigned int frameRateInSeconds = 2; - unsigned int millisPerFrame = 1000 / frameRateInSeconds; + int frameRateInSeconds = 2; + int millisPerFrame = 1000 / frameRateInSeconds; const auto& frames = sceneContext.cursor->getCursor(*waypointIcon)->sprites; auto frameIndex = (timeInMillis / millisPerFrame) % frames.size(); @@ -1547,7 +1547,7 @@ namespace rwe auto maxRtt = std::clamp(gameNetworkService->getMaxAverageRttMillis(), 16.0f, 2000.0f); auto highCommandLatencyMillis = maxRtt + (maxRtt / 4.0f) + 200.0f; - auto commandLatencyFrames = static_cast(highCommandLatencyMillis / 16.0f) + 1; + auto commandLatencyFrames = static_cast(highCommandLatencyMillis / 16.0f) + 1; auto targetCommandBufferSize = commandLatencyFrames; auto bufferedCommandCount = playerCommandService->bufferedCommandCount(localPlayerId); @@ -2423,7 +2423,7 @@ namespace rwe } DiscreteRect - GameScene::computeFootprintRegion(const SimVector& position, unsigned int footprintX, unsigned int footprintZ) const + GameScene::computeFootprintRegion(const SimVector& position, int footprintX, int footprintZ) const { return simulation.computeFootprintRegion(position, footprintX, footprintZ); } @@ -2629,7 +2629,7 @@ namespace rwe }); } - void GameScene::applyDamage(UnitId unitId, unsigned int damagePoints) + void GameScene::applyDamage(UnitId unitId, int damagePoints) { auto& unit = simulation.getUnit(unitId); if (unit.hitPoints <= damagePoints) diff --git a/src/rwe/GameScene.h b/src/rwe/GameScene.h index dabb77cc9..942a85a42 100644 --- a/src/rwe/GameScene.h +++ b/src/rwe/GameScene.h @@ -151,7 +151,7 @@ namespace rwe }; Section section; - unsigned int currentBuildPage; + int currentBuildPage; }; struct HoverBuildInfo @@ -171,9 +171,9 @@ namespace rwe static constexpr int GuiSizeBottom = 32; private: - static const unsigned int UnitSelectChannel = 0; + static const int UnitSelectChannel = 0; - static const unsigned int reservedChannelsCount = 1; + static const int reservedChannelsCount = 1; /** * Speed the camera pans via the arrow keys @@ -366,7 +366,7 @@ namespace rwe void spawnWeaponImpactExplosion(const Vector3f& position, const std::string& weaponType, ImpactType impactType); - DiscreteRect computeFootprintRegion(const SimVector& position, unsigned int footprintX, unsigned int footprintZ) const; + DiscreteRect computeFootprintRegion(const SimVector& position, int footprintX, int footprintZ) const; void moveUnitOccupiedArea(const DiscreteRect& oldRect, const DiscreteRect& newRect, UnitId unitId); @@ -470,7 +470,7 @@ namespace rwe void applyDamageInRadius(const SimVector& position, SimScalar radius, const Projectile& projectile); - void applyDamage(UnitId unitId, unsigned int damagePoints); + void applyDamage(UnitId unitId, int damagePoints); void deleteDeadUnits(); diff --git a/src/rwe/LoadingNetworkService.cpp b/src/rwe/LoadingNetworkService.cpp index bd9584bcf..2ff617a7e 100644 --- a/src/rwe/LoadingNetworkService.cpp +++ b/src/rwe/LoadingNetworkService.cpp @@ -75,7 +75,7 @@ namespace rwe } } - void LoadingNetworkService::onReceive(const boost::system::error_code& error, std::size_t bytesTransferred) + void LoadingNetworkService::onReceive(const boost::system::error_code& error, int bytesTransferred) { if (error) { diff --git a/src/rwe/LoadingNetworkService.h b/src/rwe/LoadingNetworkService.h index 4d78d89cc..306ace142 100644 --- a/src/rwe/LoadingNetworkService.h +++ b/src/rwe/LoadingNetworkService.h @@ -68,7 +68,7 @@ namespace rwe private: void run(const std::string& port); - void onReceive(const boost::system::error_code& error, std::size_t bytesTransferred); + void onReceive(const boost::system::error_code& error, int bytesTransferred); void notifyStatus(); diff --git a/src/rwe/LoadingScene.cpp b/src/rwe/LoadingScene.cpp index 61aca3a53..fea370204 100644 --- a/src/rwe/LoadingScene.cpp +++ b/src/rwe/LoadingScene.cpp @@ -41,7 +41,7 @@ namespace rwe return features; } - GameParameters::GameParameters(const std::string& mapName, unsigned int schemaIndex) + GameParameters::GameParameters(const std::string& mapName, int schemaIndex) : mapName(mapName), schemaIndex(schemaIndex) { @@ -133,7 +133,7 @@ namespace rwe std::seed_seq seedFromGameParameters(const GameParameters& params) { - std::vector initialVec; + std::vector initialVec; std::copy(params.mapName.begin(), params.mapName.end(), std::back_inserter(initialVec)); for (const auto& e : params.players) @@ -160,7 +160,7 @@ namespace rwe return std::seed_seq(initialVec.begin(), initialVec.end()); } - std::unique_ptr LoadingScene::createGameScene(const std::string& mapName, unsigned int schemaIndex) + std::unique_ptr LoadingScene::createGameScene(const std::string& mapName, int schemaIndex) { auto atlasInfo = createTextureAtlases(sceneContext.vfs, sceneContext.graphics, sceneContext.palette); MeshService meshService(sceneContext.vfs, sceneContext.graphics, std::move(atlasInfo.textureAtlasMap), std::move(atlasInfo.teamTextureAtlasMap), std::move(atlasInfo.colorAtlasMap)); @@ -370,7 +370,7 @@ namespace rwe return gameScene; } - LoadingScene::LoadMapResult LoadingScene::loadMap(const std::unordered_map& featuresMap, const std::string& mapName, const OtaRecord& ota, unsigned int schemaIndex) + LoadingScene::LoadMapResult LoadingScene::loadMap(const std::unordered_map& featuresMap, const std::string& mapName, const OtaRecord& ota, int schemaIndex) { auto tntBytes = sceneContext.vfs->readFile("maps/" + mapName + ".tnt"); if (!tntBytes) @@ -404,9 +404,9 @@ namespace rwe std::vector features; - for (std::size_t y = 0; y < mapAttributes.getHeight(); ++y) + for (int y = 0; y < mapAttributes.getHeight(); ++y) { - for (std::size_t x = 0; x < mapAttributes.getWidth(); ++x) + for (int x = 0; x < mapAttributes.getWidth(); ++x) { const auto& e = mapAttributes.get(x, y); switch (e.feature) @@ -438,9 +438,9 @@ namespace rwe std::vector LoadingScene::getTileTextures(TntArchive& tnt) { - static const unsigned int tileWidth = 32; - static const unsigned int tileHeight = 32; - static const unsigned int mipMapLevels = 5; + static const int tileWidth = 32; + static const int tileHeight = 32; + static const int mipMapLevels = 5; static const auto tilesPerTextureArray = 256; std::vector tileTextures; @@ -460,7 +460,7 @@ namespace rwe textureArrayBuffer.clear(); } - for (unsigned int i = 0; i < (tileWidth * tileHeight); ++i) + for (int i = 0; i < (tileWidth * tileHeight); ++i) { auto index = static_cast(tile[i]); textureArrayBuffer.push_back((*sceneContext.palette)[index]); @@ -470,7 +470,7 @@ namespace rwe textureArrayHandles.emplace_back(sceneContext.graphics->createTextureArray(tileWidth, tileHeight, mipMapLevels, textureArrayBuffer)); // populate the list of texture regions referencing the textures - for (unsigned int i = 0; i < tnt.getHeader().numberOfTiles; ++i) + for (int i = 0; i < tnt.getHeader().numberOfTiles; ++i) { assert(textureArrayHandles.size() > i / tilesPerTextureArray); auto textureIndex = i / tilesPerTextureArray; @@ -565,12 +565,12 @@ namespace rwe SimVector LoadingScene::computeFeaturePosition( const MapTerrain& terrain, const FeatureDefinition& featureDefinition, - std::size_t x, - std::size_t y) const + int x, + int y) const { const auto& heightmap = terrain.getHeightMap(); - unsigned int height = 0; + int height = 0; if (x < heightmap.getWidth() - 1 && y < heightmap.getHeight() - 1) { height = computeMidpointHeight(heightmap, x, y); @@ -585,7 +585,7 @@ namespace rwe return position; } - unsigned int LoadingScene::computeMidpointHeight(const Grid& heightmap, std::size_t x, std::size_t y) + int LoadingScene::computeMidpointHeight(const Grid& heightmap, int x, int y) { assert(x < heightmap.getWidth() - 1); assert(y < heightmap.getHeight() - 1); diff --git a/src/rwe/LoadingScene.h b/src/rwe/LoadingScene.h index 1f4d98f29..0693132d0 100644 --- a/src/rwe/LoadingScene.h +++ b/src/rwe/LoadingScene.h @@ -77,12 +77,12 @@ namespace rwe struct GameParameters { std::string mapName; - unsigned int schemaIndex; + int schemaIndex; std::array, 10> players; std::string localNetworkPort{"1337"}; std::optional stateLogFile; - GameParameters(const std::string& mapName, unsigned int schemaIndex); + GameParameters(const std::string& mapName, int schemaIndex); }; class LoadingScene : public SceneManager::Scene @@ -119,9 +119,9 @@ namespace rwe void render() override; private: - static unsigned int computeMidpointHeight(const Grid& heightmap, std::size_t x, std::size_t y); + static int computeMidpointHeight(const Grid& heightmap, int x, int y); - std::unique_ptr createGameScene(const std::string& mapName, unsigned int schemaIndex); + std::unique_ptr createGameScene(const std::string& mapName, int schemaIndex); struct LoadMapResult @@ -132,7 +132,7 @@ namespace rwe MapTerrainGraphics terrainGraphics; }; - LoadMapResult loadMap(const std::unordered_map& featuresMap, const std::string& mapName, const rwe::OtaRecord& ota, unsigned int schemaIndex); + LoadMapResult loadMap(const std::unordered_map& featuresMap, const std::string& mapName, const rwe::OtaRecord& ota, int schemaIndex); std::vector getTileTextures(TntArchive& tnt); @@ -144,7 +144,7 @@ namespace rwe MapFeature createFeature(const SimVector& pos, const FeatureDefinition& definition); - SimVector computeFeaturePosition(const MapTerrain& terrain, const FeatureDefinition& featureDefinition, std::size_t x, std::size_t y) const; + SimVector computeFeaturePosition(const MapTerrain& terrain, const FeatureDefinition& featureDefinition, int x, int y) const; const SideData& getSideData(const std::string& side) const; diff --git a/src/rwe/MainMenuModel.cpp b/src/rwe/MainMenuModel.cpp index 5ff4b6534..0c1ed1a85 100644 --- a/src/rwe/MainMenuModel.cpp +++ b/src/rwe/MainMenuModel.cpp @@ -46,7 +46,7 @@ namespace rwe std::optional MainMenuModel::getFirstFreeColor() const { - for (unsigned int i = 0; i < 10; ++i) + for (int i = 0; i < 10; ++i) { if (!isColorInUse(PlayerColorIndex(i))) { diff --git a/src/rwe/MainMenuScene.cpp b/src/rwe/MainMenuScene.cpp index 4f686fa24..07c577aa2 100644 --- a/src/rwe/MainMenuScene.cpp +++ b/src/rwe/MainMenuScene.cpp @@ -603,7 +603,7 @@ namespace rwe { auto& player = model.players[playerIndex]; auto currentColor = player.colorIndex.getValue(); - for (unsigned int i = 1; i < 10; ++i) + for (int i = 1; i < 10; ++i) { auto newColor = PlayerColorIndex((currentColor.value + i) % 10); if (!model.isColorInUse(newColor)) @@ -618,7 +618,7 @@ namespace rwe { auto& player = model.players[playerIndex]; auto currentColor = player.colorIndex.getValue(); - for (unsigned int i = 9; i >= 1; --i) + for (int i = 9; i >= 1; --i) { auto newColor = PlayerColorIndex((currentColor.value + i) % 10); if (!model.isColorInUse(newColor)) @@ -737,17 +737,17 @@ namespace rwe void MainMenuScene::attachPlayerSelectionComponents(const std::string& guiName, UiPanel& panel) { - unsigned int tableStart = 78; - unsigned int rowHeight = 20; + int tableStart = 78; + int rowHeight = 20; for (int i = 0; i < 10; ++i) { - unsigned int rowStart = tableStart + (i * rowHeight); + int rowStart = tableStart + (i * rowHeight); { // player name button - unsigned int width = 112; - unsigned int height = 20; + int width = 112; + int height = 20; auto b = uiFactory.createBasicButton(45, rowStart, width, height, guiName, "skirmname", "Player"); b->setName("PLAYER" + std::to_string(i)); @@ -781,15 +781,15 @@ namespace rwe void MainMenuScene::attachDetailedPlayerSelectionComponents(const std::string& guiName, UiPanel& panel, int i) { - unsigned int tableStart = 78; - unsigned int rowHeight = 20; + int tableStart = 78; + int rowHeight = 20; - unsigned int rowStart = tableStart + (i * rowHeight); + int rowStart = tableStart + (i * rowHeight); { // side button - unsigned int width = 44; - unsigned int height = 20; + int width = 44; + int height = 20; auto b = uiFactory.createStagedButton(163, rowStart, width, height, guiName, "SIDEx", std::vector(2), 2); b->setName("PLAYER" + std::to_string(i) + "_side"); @@ -812,8 +812,8 @@ namespace rwe { // color - unsigned int width = 19; - unsigned int height = 19; + int width = 19; + int height = 19; auto graphics = sceneContext.textureService->getGafEntry("anims/LOGOS.GAF", "32xlogos"); auto newSprites = std::make_shared(); @@ -838,8 +838,8 @@ namespace rwe { // ally - unsigned int width = 38; - unsigned int height = 20; + int width = 38; + int height = 20; auto graphics = sceneContext.textureService->getGuiTexture(guiName, "TEAMICONSx"); if (!graphics) @@ -896,8 +896,8 @@ namespace rwe { // metal - unsigned int width = 46; - unsigned int height = 20; + int width = 46; + int height = 20; auto b = uiFactory.createButton(286, rowStart, width, height, guiName, "skirmmet", ""); b->setName("PLAYER" + std::to_string(i) + "_metal"); @@ -913,8 +913,8 @@ namespace rwe { // energy - unsigned int width = 46; - unsigned int height = 20; + int width = 46; + int height = 20; auto b = uiFactory.createButton(337, rowStart, width, height, guiName, "skirmmet", ""); b->setName("PLAYER" + std::to_string(i) + "_energy"); diff --git a/src/rwe/MeshService.cpp b/src/rwe/MeshService.cpp index cfb9c5ed8..9cedee617 100644 --- a/src/rwe/MeshService.cpp +++ b/src/rwe/MeshService.cpp @@ -202,7 +202,7 @@ namespace rwe return {false, Rectangle2f(0, 0, 0, 0)}; } - Vector2f MeshService::getColorTexturePoint(unsigned int colorIndex) + Vector2f MeshService::getColorTexturePoint(int colorIndex) { assert(colorIndex < atlasColorMap.size()); return atlasColorMap[colorIndex]; diff --git a/src/rwe/MeshService.h b/src/rwe/MeshService.h index 8803c369b..7746ee84d 100644 --- a/src/rwe/MeshService.h +++ b/src/rwe/MeshService.h @@ -54,7 +54,7 @@ namespace rwe Rectangle2f region; }; TextureRegionInfo getTextureRegion(const std::string& name); - Vector2f getColorTexturePoint(unsigned int colorIndex); + Vector2f getColorTexturePoint(int colorIndex); void extractMeshes(const _3do::Object& o, std::vector>>& v); diff --git a/src/rwe/MovementClassCollisionService.h b/src/rwe/MovementClassCollisionService.h index d0ef440f7..0caec8f3f 100644 --- a/src/rwe/MovementClassCollisionService.h +++ b/src/rwe/MovementClassCollisionService.h @@ -12,7 +12,7 @@ namespace rwe class MovementClassCollisionService { private: - unsigned int nextId{0}; + int nextId{0}; std::unordered_map movementClassNameMap; std::unordered_map> walkableGrids; diff --git a/src/rwe/PlayerColorIndex.cpp b/src/rwe/PlayerColorIndex.cpp index 43154ea5c..f99a61602 100644 --- a/src/rwe/PlayerColorIndex.cpp +++ b/src/rwe/PlayerColorIndex.cpp @@ -3,9 +3,9 @@ namespace rwe { - PlayerColorIndex::PlayerColorIndex(unsigned int _value) : OpaqueId(_value) + PlayerColorIndex::PlayerColorIndex(int _value) : OpaqueId(_value) { - if (_value >= 10u) + if (_value >= 10 || _value < 0) { throw std::logic_error("Player color index out of range"); } diff --git a/src/rwe/PlayerColorIndex.h b/src/rwe/PlayerColorIndex.h index 21cc23f53..2b1d7b2dd 100644 --- a/src/rwe/PlayerColorIndex.h +++ b/src/rwe/PlayerColorIndex.h @@ -5,8 +5,8 @@ namespace rwe { struct PlayerColorIndexTag; - struct PlayerColorIndex : public OpaqueId + struct PlayerColorIndex : public OpaqueId { - explicit PlayerColorIndex(unsigned int value); + explicit PlayerColorIndex(int value); }; } diff --git a/src/rwe/PlayerCommandService.cpp b/src/rwe/PlayerCommandService.cpp index 0ef713414..5bdad504c 100644 --- a/src/rwe/PlayerCommandService.cpp +++ b/src/rwe/PlayerCommandService.cpp @@ -49,11 +49,11 @@ namespace rwe gameTimeBuffers.emplace(playerId, std::deque()); } - unsigned int PlayerCommandService::bufferedCommandCount(PlayerId player) const + int PlayerCommandService::bufferedCommandCount(PlayerId player) const { std::scoped_lock lock(mutex); - return commandBuffers.at(player).size(); + return static_cast(commandBuffers.at(player).size()); } bool PlayerCommandService::checkHashes() diff --git a/src/rwe/PlayerCommandService.h b/src/rwe/PlayerCommandService.h index 927835b4f..389ad0bf0 100644 --- a/src/rwe/PlayerCommandService.h +++ b/src/rwe/PlayerCommandService.h @@ -26,7 +26,7 @@ namespace rwe void pushHash(PlayerId player, const GameHash& gameHash); - unsigned int bufferedCommandCount(PlayerId player) const; + int bufferedCommandCount(PlayerId player) const; void registerPlayer(PlayerId playerId); diff --git a/src/rwe/RenderService.cpp b/src/rwe/RenderService.cpp index ad1806c4c..945f29586 100644 --- a/src/rwe/RenderService.cpp +++ b/src/rwe/RenderService.cpp @@ -207,13 +207,13 @@ namespace rwe return graphics->createColoredMesh(buffer, GL_STREAM_DRAW); } - void RenderService::drawMapTerrain(const MapTerrainGraphics& terrain, unsigned int x, unsigned int y, unsigned int width, unsigned int height) + void RenderService::drawMapTerrain(const MapTerrainGraphics& terrain, int x, int y, int width, int height) { - std::unordered_map>> batches; + std::unordered_map>> batches; - for (unsigned int dy = 0; dy < height; ++dy) + for (int dy = 0; dy < height; ++dy) { - for (unsigned int dx = 0; dx < width; ++dx) + for (int dx = 0; dx < width; ++dx) { auto tileIndex = terrain.getTiles().get(x + dx, y + dy); const auto& tileTexture = terrain.getTileTexture(tileIndex); @@ -262,10 +262,10 @@ namespace rwe Vector3f cameraExtents(camera.getWidth() / 2.0f, 0.0f, camera.getHeight() / 2.0f); auto topLeft = terrain.worldToTileCoordinate(floatToSimVector(camera.getPosition() - cameraExtents)); auto bottomRight = terrain.worldToTileCoordinate(floatToSimVector(camera.getPosition() + cameraExtents)); - auto x1 = static_cast(std::clamp(topLeft.x, 0, terrain.getTiles().getWidth() - 1)); - auto y1 = static_cast(std::clamp(topLeft.y, 0, terrain.getTiles().getHeight() - 1)); - auto x2 = static_cast(std::clamp(bottomRight.x, 0, terrain.getTiles().getWidth() - 1)); - auto y2 = static_cast(std::clamp(bottomRight.y, 0, terrain.getTiles().getHeight() - 1)); + auto x1 = std::clamp(topLeft.x, 0, terrain.getTiles().getWidth() - 1); + auto y1 = std::clamp(topLeft.y, 0, terrain.getTiles().getHeight() - 1); + auto x2 = std::clamp(bottomRight.x, 0, terrain.getTiles().getWidth() - 1); + auto y2 = std::clamp(bottomRight.y, 0, terrain.getTiles().getHeight() - 1); drawMapTerrain(terrain, x1, y1, (x2 + 1) - x1, (y2 + 1) - y1); } @@ -339,7 +339,7 @@ namespace rwe } } - unsigned int getFrameIndex(GameTime currentTime, unsigned int numFrames) + int getFrameIndex(GameTime currentTime, int numFrames) { return (currentTime.value / 2) % numFrames; } @@ -408,7 +408,7 @@ namespace rwe auto timeSinceSpawn = currentTime - projectile.createdAt; auto fullLifetime = projectile.dieOnFrame.value() - projectile.createdAt; auto percentComplete = static_cast(timeSinceSpawn.value) / static_cast(fullLifetime.value); - auto frameIndex = static_cast(percentComplete * spriteSeries->sprites.size()); + int frameIndex = static_cast(percentComplete * spriteSeries->sprites.size()); assert(frameIndex < spriteSeries->sprites.size()); const auto& sprite = *spriteSeries->sprites[frameIndex]; auto modelMatrix = Matrix4f::translation(snappedPosition) * conversionMatrix * sprite.getTransform(); diff --git a/src/rwe/RenderService.h b/src/rwe/RenderService.h index 4fb841f77..f15c7c256 100644 --- a/src/rwe/RenderService.h +++ b/src/rwe/RenderService.h @@ -128,7 +128,7 @@ namespace rwe drawStandingFeatureShadowsInternal(features.begin(), features.end()); } - void drawMapTerrain(const MapTerrainGraphics& terrain, unsigned int x, unsigned int y, unsigned int width, unsigned int height); + void drawMapTerrain(const MapTerrainGraphics& terrain, int x, int y, int width, int height); template void drawUnitShadows(const MapTerrain& terrain, const Range& units, float frac, SimScalar seaLevel) diff --git a/src/rwe/SceneManager.h b/src/rwe/SceneManager.h index 40ac1f6fa..efdc32b21 100644 --- a/src/rwe/SceneManager.h +++ b/src/rwe/SceneManager.h @@ -54,12 +54,12 @@ namespace rwe bool showDebugWindow{false}; bool showDemoWindow{false}; - unsigned int lastFrameStartTime{0}; - unsigned int lastFrameDurationMs{0}; + int lastFrameStartTime{0}; + int lastFrameDurationMs{0}; public: // Number of milliseconds between each game tick. - static const unsigned int TickInterval = 1000 / 60; + static const int TickInterval = 1000 / 60; explicit SceneManager(SdlContext* sdl, SDL_Window* window, GraphicsContext* graphics, TimeService* timeService, ImGuiContext* imGuiContext, CursorService* cursorService, GlobalConfig* globalConfig, UiRenderService&& uiRenderService); void setNextScene(std::shared_ptr scene); diff --git a/src/rwe/SceneTime.h b/src/rwe/SceneTime.h index 621ec0a8e..fe5f29f2c 100644 --- a/src/rwe/SceneTime.h +++ b/src/rwe/SceneTime.h @@ -5,5 +5,5 @@ namespace rwe { struct SceneTimeTag; - using SceneTime = OpaqueUnit; + using SceneTime = OpaqueUnit; } diff --git a/src/rwe/SharedHandle.h b/src/rwe/SharedHandle.h index 2459b89a7..f1811dc2c 100644 --- a/src/rwe/SharedHandle.h +++ b/src/rwe/SharedHandle.h @@ -13,12 +13,12 @@ namespace rwe private: Value handle; - unsigned int* referenceCount; + int* referenceCount; public: SharedHandle() : handle(), referenceCount(nullptr) {} - explicit SharedHandle(Value handle) : handle(handle), referenceCount(new unsigned int(1)) {} + explicit SharedHandle(Value handle) : handle(handle), referenceCount(new int(1)) {} ~SharedHandle() { @@ -102,7 +102,7 @@ namespace rwe return referenceCount != nullptr; } - unsigned int useCount() const + int useCount() const { if (referenceCount == nullptr) { @@ -117,7 +117,7 @@ namespace rwe { destroy(); handle = newValue; - referenceCount = new unsigned int(1); + referenceCount = new int(1); } /** Resets the handle to the empty state. */ diff --git a/src/rwe/SideData.cpp b/src/rwe/SideData.cpp index 20dce46e2..6c7902a6a 100644 --- a/src/rwe/SideData.cpp +++ b/src/rwe/SideData.cpp @@ -2,7 +2,7 @@ namespace rwe { - SideDataRect::SideDataRect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2) + SideDataRect::SideDataRect(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) { } @@ -19,8 +19,8 @@ namespace rwe DiscreteRect SideDataRect::toDiscreteRect() const { - unsigned int minX; - unsigned int maxX; + int minX; + int maxX; if (x1 < x2) { minX = x1; @@ -32,8 +32,8 @@ namespace rwe maxX = x1; } - unsigned int minY; - unsigned int maxY; + int minY; + int maxY; if (y1 < y2) { minY = y1; @@ -121,7 +121,7 @@ namespace rwe { std::vector list; - unsigned int i = 0; + int i = 0; for (;;) { auto block = tdf.findBlock("SIDE" + std::to_string(i)); diff --git a/src/rwe/SideData.h b/src/rwe/SideData.h index a4da8767e..1840f89eb 100644 --- a/src/rwe/SideData.h +++ b/src/rwe/SideData.h @@ -8,13 +8,13 @@ namespace rwe { struct SideDataRect { - unsigned int x1; - unsigned int y1; - unsigned int x2; - unsigned int y2; + int x1; + int y1; + int x2; + int y2; SideDataRect() = default; - SideDataRect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2); + SideDataRect(int x1, int y1, int x2, int y2); bool operator==(const SideDataRect& rhs) const; @@ -32,8 +32,8 @@ namespace rwe std::string font; std::string fontGui; - unsigned int energyColor; - unsigned int metalColor; + int energyColor; + int metalColor; SideDataRect logo; SideDataRect energyBar; diff --git a/src/rwe/TextureService.cpp b/src/rwe/TextureService.cpp index e51a34f82..bf8300ad0 100644 --- a/src/rwe/TextureService.cpp +++ b/src/rwe/TextureService.cpp @@ -279,7 +279,7 @@ namespace rwe auto series = std::make_shared(); - for (unsigned int i = 0; i < 256; ++i) + for (int i = 0; i < 256; ++i) { std::vector glyphBits(512); auto bytesRead = fnt.extract(i, glyphBits.data()); @@ -288,10 +288,10 @@ namespace rwe std::vector rgbGlyph; rgbGlyph.reserve(bytesRead * 8); - for (unsigned int j = 0; j < bytesRead; ++j) + for (int j = 0; j < bytesRead; ++j) { auto byte = static_cast(glyphBits[j]); - for (unsigned int k = 0; k < 8; ++k) + for (int k = 0; k < 8; ++k) { rgbGlyph.push_back(byte & (128u >> k) ? Color(255, 255, 255) : Color(0, 0, 0, 0)); } @@ -313,7 +313,7 @@ namespace rwe return series; } - TextureService::TextureInfo::TextureInfo(unsigned int width, unsigned int height, const SharedTextureHandle& handle) + TextureService::TextureInfo::TextureInfo(int width, int height, const SharedTextureHandle& handle) : width(width), height(height), handle(handle) { } diff --git a/src/rwe/TextureService.h b/src/rwe/TextureService.h index 8b1ef4236..624a4b1ef 100644 --- a/src/rwe/TextureService.h +++ b/src/rwe/TextureService.h @@ -16,12 +16,12 @@ namespace rwe private: struct TextureInfo { - unsigned int width; - unsigned int height; + int width; + int height; SharedTextureHandle handle; TextureInfo() = default; - TextureInfo(unsigned int width, unsigned int height, const SharedTextureHandle& handle); + TextureInfo(int width, int height, const SharedTextureHandle& handle); }; GraphicsContext* graphics; diff --git a/src/rwe/UnitFactory.cpp b/src/rwe/UnitFactory.cpp index 60e36c0df..55615eb6e 100644 --- a/src/rwe/UnitFactory.cpp +++ b/src/rwe/UnitFactory.cpp @@ -72,7 +72,7 @@ namespace rwe return cells; } - Grid parseYardMap(unsigned int width, unsigned int height, const std::string& yardMap) + Grid parseYardMap(int width, int height, const std::string& yardMap) { auto cells = parseYardMapCells(yardMap); cells.resize(width * height, YardMapCell::Ground); @@ -255,7 +255,7 @@ namespace rwe return unit; } - std::optional>> UnitFactory::getBuilderGui(const std::string& unitType, unsigned int page) const + std::optional>> UnitFactory::getBuilderGui(const std::string& unitType, int page) const { const auto& pages = unitDatabase->tryGetBuilderGui(unitType); if (!pages) @@ -273,7 +273,7 @@ namespace rwe return unwrappedPages[page]; } - unsigned int UnitFactory::getBuildPageCount(const std::string& unitType) const + int UnitFactory::getBuildPageCount(const std::string& unitType) const { const auto& pages = unitDatabase->tryGetBuilderGui(unitType); if (!pages) @@ -281,7 +281,7 @@ namespace rwe return 0; } - return pages->get().size(); + return static_cast(pages->get().size()); } Point UnitFactory::getUnitFootprint(const std::string& unitType) const @@ -309,7 +309,7 @@ namespace rwe return unitDatabase->hasUnitInfo(unitType); } - std::optional getFxName(unsigned int code) + std::optional getFxName(int code) { switch (code) { @@ -436,7 +436,7 @@ namespace rwe weapon.weaponDefinition.endSmoke = tdf.endSmoke; if (tdf.smokeTrail) { - weapon.weaponDefinition.smokeTrail = GameTime(static_cast(tdf.smokeDelay * 30.0f)); + weapon.weaponDefinition.smokeTrail = GameTime(static_cast(tdf.smokeDelay * 30.0f)); } weapon.weaponDefinition.soundTrigger = tdf.soundTrigger; @@ -450,12 +450,12 @@ namespace rwe if (tdf.weaponTimer != 0.0f) { - weapon.weaponDefinition.weaponTimer = GameTime(static_cast(tdf.weaponTimer * 30.0f)); + weapon.weaponDefinition.weaponTimer = GameTime(static_cast(tdf.weaponTimer * 30.0f)); } weapon.weaponDefinition.groundBounce = tdf.groundBounce; - weapon.weaponDefinition.randomDecay = GameTime(static_cast(tdf.randomDecay * 30.0f)); + weapon.weaponDefinition.randomDecay = GameTime(static_cast(tdf.randomDecay * 30.0f)); return weapon; } @@ -468,7 +468,7 @@ namespace rwe static_cast(color.b) / 255.0f); } - unsigned int colorDistance(const Color& a, const Color& b) + int colorDistance(const Color& a, const Color& b) { auto dr = a.r > b.r ? a.r - b.r : b.r - a.r; auto dg = a.g > b.g ? a.g - b.g : b.g - a.g; @@ -476,7 +476,7 @@ namespace rwe return dr + dg + db; } - Vector3f UnitFactory::getLaserColor(unsigned int colorIndex) + Vector3f UnitFactory::getLaserColor(int colorIndex) { // In TA, lasers use the GUIPAL colors, // but these must be mapped to a color available diff --git a/src/rwe/UnitFactory.h b/src/rwe/UnitFactory.h index 4a74886a5..a1a30bdbd 100644 --- a/src/rwe/UnitFactory.h +++ b/src/rwe/UnitFactory.h @@ -32,10 +32,10 @@ namespace rwe public: Unit createUnit(const std::string& unitType, PlayerId owner, const SimVector& position, std::optional> rotation); - std::optional>> getBuilderGui(const std::string& unitType, unsigned int page) const; + std::optional>> getBuilderGui(const std::string& unitType, int page) const; /** If the unit has no build gui, this will be zero. */ - unsigned int getBuildPageCount(const std::string& unitType) const; + int getBuildPageCount(const std::string& unitType) const; Point getUnitFootprint(const std::string& unitType) const; @@ -48,6 +48,6 @@ namespace rwe UnitWeapon createWeapon(const std::string& weaponType); UnitWeapon createWeapon(const std::string& weaponType, const WeaponTdf& tdf); - Vector3f getLaserColor(unsigned int colorIndex); + Vector3f getLaserColor(int colorIndex); }; } diff --git a/src/rwe/VectorMap.h b/src/rwe/VectorMap.h index b015c2b6f..9efe03529 100644 --- a/src/rwe/VectorMap.h +++ b/src/rwe/VectorMap.h @@ -16,11 +16,11 @@ namespace rwe class VectorMap { private: - using Id = OpaqueId; + using Id = OpaqueId; struct IndexTag; - using Index = OpaqueId; + using Index = OpaqueId; struct GenerationTag; - using Generation = OpaqueId; + using Generation = OpaqueId; struct FreeEntry { @@ -116,7 +116,7 @@ namespace rwe } else { - auto id = makeId(Index(vec.size())); + auto id = makeId(Index(static_cast(vec.size()))); vec.emplace_back(std::make_pair(id, T(std::forward(args)...))); return id; } diff --git a/src/rwe/VectorMap.test.cpp b/src/rwe/VectorMap.test.cpp index c2be0d096..49ef69a20 100644 --- a/src/rwe/VectorMap.test.cpp +++ b/src/rwe/VectorMap.test.cpp @@ -10,7 +10,7 @@ namespace rwe { struct IdTag; - using Id = OpaqueId; + using Id = OpaqueId; TEST_CASE("VectorMap") { SECTION("can store and retrieve elements") diff --git a/src/rwe/Viewport.cpp b/src/rwe/Viewport.cpp index 90ed27e47..d99865eeb 100644 --- a/src/rwe/Viewport.cpp +++ b/src/rwe/Viewport.cpp @@ -3,7 +3,7 @@ namespace rwe { - Viewport::Viewport(int x, int y, unsigned int width, unsigned int height) : _x(x), _y(y), _width(width), _height(height) + Viewport::Viewport(int x, int y, int width, int height) : _x(x), _y(y), _width(width), _height(height) { } @@ -62,12 +62,12 @@ namespace rwe return _y; } - unsigned int Viewport::width() const + int Viewport::width() const { return _width; } - unsigned int Viewport::height() const + int Viewport::height() const { return _height; } diff --git a/src/rwe/Viewport.h b/src/rwe/Viewport.h index b77479208..073bd7ca1 100644 --- a/src/rwe/Viewport.h +++ b/src/rwe/Viewport.h @@ -10,11 +10,11 @@ namespace rwe private: int _x; int _y; - unsigned int _width; - unsigned int _height; + int _width; + int _height; public: - Viewport(int x, int y, unsigned int width, unsigned int height); + Viewport(int x, int y, int width, int height); Vector2f toClipSpace(int x, int y) const; @@ -32,9 +32,9 @@ namespace rwe int y() const; - unsigned int width() const; + int width() const; - unsigned int height() const; + int height() const; int top() const { return _y; } int bottom() const { return _y + static_cast(_height); } diff --git a/src/rwe/atlas_util.cpp b/src/rwe/atlas_util.cpp index aac95f981..b8dbf725b 100644 --- a/src/rwe/atlas_util.cpp +++ b/src/rwe/atlas_util.cpp @@ -10,10 +10,10 @@ namespace rwe struct FrameInfo { std::string name; - unsigned int frameNumber; + int frameNumber; Grid data; - FrameInfo(const std::string& name, unsigned int frameNumber, unsigned int width, unsigned int height) + FrameInfo(const std::string& name, int frameNumber, int width, int height) : name(name), frameNumber(frameNumber), data(width, height) { } @@ -26,7 +26,7 @@ namespace rwe const std::string* entryName; FrameInfo* frameInfo; GafFrameData currentFrameHeader; - unsigned int frameNumber{0}; + int frameNumber{0}; public: explicit FrameListGafAdapter(std::vector* frames, const std::string* entryName) @@ -78,7 +78,7 @@ namespace rwe }; struct AtlasItemColor { - unsigned int colorIndex; + int colorIndex; }; using AtlasItem = std::variant; @@ -221,7 +221,7 @@ namespace rwe frameRefs.emplace_back(AtlasItemFrame{&f}); } - for (unsigned int i = 0; i < palette->size(); ++i) + for (int i = 0; i < palette->size(); ++i) { frameRefs.emplace_back(AtlasItemColor{i}); } diff --git a/src/rwe/cob/CobEnvironment.cpp b/src/rwe/cob/CobEnvironment.cpp index 105deddda..262f452bc 100644 --- a/src/rwe/cob/CobEnvironment.cpp +++ b/src/rwe/cob/CobEnvironment.cpp @@ -7,12 +7,12 @@ namespace rwe { } - int CobEnvironment::getStatic(unsigned int id) + int CobEnvironment::getStatic(int id) { return _statics.at(id); } - void CobEnvironment::setStatic(unsigned int id, int value) + void CobEnvironment::setStatic(int id, int value) { _statics.at(id) = value; } @@ -35,7 +35,7 @@ namespace rwe return createNonScheduledThread(index, params); } - CobThread CobEnvironment::createNonScheduledThread(unsigned int functionId, const std::vector& params) + CobThread CobEnvironment::createNonScheduledThread(int functionId, const std::vector& params) { const auto& functionInfo = _script->functions.at(functionId); CobThread thread(functionInfo.name); @@ -43,7 +43,7 @@ namespace rwe return thread; } - const CobThread* CobEnvironment::createThread(unsigned int functionId, const std::vector& params, unsigned int signalMask) + const CobThread* CobEnvironment::createThread(int functionId, const std::vector& params, int signalMask) { const auto& functionInfo = _script->functions.at(functionId); auto& thread = threads.emplace_back(std::make_unique(functionInfo.name, signalMask)); @@ -52,7 +52,7 @@ namespace rwe return thread.get(); } - const CobThread* CobEnvironment::createThread(unsigned int functionId, const std::vector& params) + const CobThread* CobEnvironment::createThread(int functionId, const std::vector& params) { return createThread(functionId, params, 0); } @@ -84,7 +84,7 @@ namespace rwe } } - void CobEnvironment::sendSignal(unsigned int signal) + void CobEnvironment::sendSignal(int signal) { for (auto it = threads.begin(); it != threads.end();) { diff --git a/src/rwe/cob/CobEnvironment.h b/src/rwe/cob/CobEnvironment.h index 24368ce3c..0d61172af 100644 --- a/src/rwe/cob/CobEnvironment.h +++ b/src/rwe/cob/CobEnvironment.h @@ -27,20 +27,20 @@ namespace rwe { struct Move { - unsigned int object; + int object; CobAxis axis; - Move(unsigned int object, CobAxis axis) : object(object), axis(axis) + Move(int object, CobAxis axis) : object(object), axis(axis) { } }; struct Turn { - unsigned int object; + int object; CobAxis axis; - Turn(unsigned int object, CobAxis axis) : object(object), axis(axis) + Turn(int object, CobAxis axis) : object(object), axis(axis) { } }; @@ -69,7 +69,7 @@ namespace rwe */ struct SignalStatus { - unsigned int signal; + int signal; }; struct PieceCommandStatus @@ -111,7 +111,7 @@ namespace rwe }; using CommandType = std::variant; - unsigned int piece; + int piece; CommandType command; }; @@ -273,19 +273,19 @@ namespace rwe CobEnvironment& operator=(CobEnvironment&& other) = delete; public: - int getStatic(unsigned int id); + int getStatic(int id); - void setStatic(unsigned int id, int value); + void setStatic(int id, int value); const CobScript* script(); std::optional createNonScheduledThread(const std::string& functionName, const std::vector& params); - CobThread createNonScheduledThread(unsigned int functionId, const std::vector& params); + CobThread createNonScheduledThread(int functionId, const std::vector& params); - const CobThread* createThread(unsigned int functionId, const std::vector& params, unsigned int signalMask); + const CobThread* createThread(int functionId, const std::vector& params, int signalMask); - const CobThread* createThread(unsigned int functionId, const std::vector& params); + const CobThread* createThread(int functionId, const std::vector& params); std::optional createThread(const std::string& functionName, const std::vector& params); @@ -298,7 +298,7 @@ namespace rwe * If the signal is non-zero after being ANDed * with the thread's signal mask, the thread is killed. */ - void sendSignal(unsigned int signal); + void sendSignal(int signal); /** * Attempts to collect the return value from a thread. diff --git a/src/rwe/cob/CobExecutionContext.cpp b/src/rwe/cob/CobExecutionContext.cpp index 8989a7afd..ac5c500b9 100644 --- a/src/rwe/cob/CobExecutionContext.cpp +++ b/src/rwe/cob/CobExecutionContext.cpp @@ -84,7 +84,7 @@ namespace rwe case CobValueId::UnitAllied: return CobEnvironment::QueryStatus::UnitAllied{UnitId(arg1)}; default: - throw std::runtime_error("Unknown unit value ID: " + std::to_string(static_cast(valueId))); + throw std::runtime_error("Unknown unit value ID: " + std::to_string(static_cast(valueId))); } } @@ -109,7 +109,7 @@ namespace rwe case CobValueId::Armored: return CobEnvironment::SetQueryStatus::Armored{value != 0}; default: - throw std::runtime_error("Cannot set unit value with ID: " + std::to_string(static_cast(valueId))); + throw std::runtime_error("Cannot set unit value with ID: " + std::to_string(static_cast(valueId))); } } @@ -587,7 +587,7 @@ namespace rwe // collect up the parameters std::vector params(paramCount); - for (unsigned int i = 0; i < paramCount; ++i) + for (int i = 0; i < paramCount; ++i) { params[i] = pop(); } @@ -602,7 +602,7 @@ namespace rwe auto paramCount = nextInstruction(); std::vector params(paramCount); - for (unsigned int i = 0; i < paramCount; ++i) + for (int i = 0; i < paramCount; ++i) { params[i] = pop(); } @@ -714,14 +714,14 @@ namespace rwe return CobAngularSpeed(pop()); } - unsigned int CobExecutionContext::popSignal() + int CobExecutionContext::popSignal() { - return static_cast(pop()); + return pop(); } - unsigned int CobExecutionContext::popSignalMask() + int CobExecutionContext::popSignalMask() { - return static_cast(pop()); + return pop(); } CobValueId CobExecutionContext::popValueId() @@ -750,7 +750,7 @@ namespace rwe } } - unsigned int CobExecutionContext::nextInstruction() + int CobExecutionContext::nextInstruction() { return env->script()->instructions.at(thread->callStack.top().instructionIndex++); } diff --git a/src/rwe/cob/CobExecutionContext.h b/src/rwe/cob/CobExecutionContext.h index d1916b33d..3c92bd5a1 100644 --- a/src/rwe/cob/CobExecutionContext.h +++ b/src/rwe/cob/CobExecutionContext.h @@ -117,12 +117,12 @@ namespace rwe CobSpeed popSpeed(); CobAngle popAngle(); CobAngularSpeed popAngularSpeed(); - unsigned int popSignal(); - unsigned int popSignalMask(); + int popSignal(); + int popSignalMask(); CobValueId popValueId(); void push(int val); - unsigned int nextInstruction(); + int nextInstruction(); CobAxis nextInstructionAsAxis(); }; } diff --git a/src/rwe/cob/CobExecutionService.cpp b/src/rwe/cob/CobExecutionService.cpp index 3aacefb8f..30b2c1307 100644 --- a/src/rwe/cob/CobExecutionService.cpp +++ b/src/rwe/cob/CobExecutionService.cpp @@ -31,7 +31,7 @@ namespace rwe } } - const std::string& getObjectName(const CobEnvironment& env, unsigned int objectId) + const std::string& getObjectName(const CobEnvironment& env, int objectId) { return env._script->pieces.at(objectId); } diff --git a/src/rwe/cob/CobFunction.cpp b/src/rwe/cob/CobFunction.cpp index 94b8cd930..d48e6b9a4 100644 --- a/src/rwe/cob/CobFunction.cpp +++ b/src/rwe/cob/CobFunction.cpp @@ -2,12 +2,12 @@ namespace rwe { - CobFunction::CobFunction(unsigned int instructionIndex, const std::vector& locals) + CobFunction::CobFunction(int instructionIndex, const std::vector& locals) : instructionIndex(instructionIndex), locals(locals) { } - CobFunction::CobFunction(unsigned int instructionIndex) : instructionIndex(instructionIndex) + CobFunction::CobFunction(int instructionIndex) : instructionIndex(instructionIndex) { } } diff --git a/src/rwe/cob/CobFunction.h b/src/rwe/cob/CobFunction.h index 8d23df58f..b8204441a 100644 --- a/src/rwe/cob/CobFunction.h +++ b/src/rwe/cob/CobFunction.h @@ -7,13 +7,13 @@ namespace rwe class CobFunction { public: - unsigned int instructionIndex; + int instructionIndex; std::vector locals; - unsigned int localCount{0}; + int localCount{0}; public: - CobFunction(unsigned int instructionIndex, const std::vector& locals); + CobFunction(int instructionIndex, const std::vector& locals); - explicit CobFunction(unsigned int instructionIndex); + explicit CobFunction(int instructionIndex); }; } diff --git a/src/rwe/cob/CobThread.cpp b/src/rwe/cob/CobThread.cpp index 664557c08..b1e3b57c8 100644 --- a/src/rwe/cob/CobThread.cpp +++ b/src/rwe/cob/CobThread.cpp @@ -2,7 +2,7 @@ namespace rwe { - CobThread::CobThread(const std::string& name, unsigned int signalMask) : name(name), signalMask(signalMask) + CobThread::CobThread(const std::string& name, int signalMask) : name(name), signalMask(signalMask) { } diff --git a/src/rwe/cob/CobThread.h b/src/rwe/cob/CobThread.h index 8e468aeb8..c2b7aec36 100644 --- a/src/rwe/cob/CobThread.h +++ b/src/rwe/cob/CobThread.h @@ -14,7 +14,7 @@ namespace rwe std::stack stack; - unsigned int signalMask{0}; + int signalMask{0}; std::stack callStack; @@ -27,7 +27,7 @@ namespace rwe std::vector returnLocals; public: - CobThread(const std::string& name, unsigned int signalMask); + CobThread(const std::string& name, int signalMask); explicit CobThread(const std::string& name); }; diff --git a/src/rwe/dump_util.test.cpp b/src/rwe/dump_util.test.cpp index af924d5f2..012eec014 100644 --- a/src/rwe/dump_util.test.cpp +++ b/src/rwe/dump_util.test.cpp @@ -4,7 +4,7 @@ namespace rwe { struct IdTag; - using Id = OpaqueId; + using Id = OpaqueId; enum class TestEnum { diff --git a/src/rwe/events.cpp b/src/rwe/events.cpp index 49b413958..100db15c7 100644 --- a/src/rwe/events.cpp +++ b/src/rwe/events.cpp @@ -20,7 +20,7 @@ namespace rwe GroupMessage::GroupMessage( const std::string& topic, - unsigned int group, + int group, const std::string& controlName, const ControlMessage& message) : topic(topic), group(group), controlName(controlName), message(message) @@ -29,7 +29,7 @@ namespace rwe GroupMessage::GroupMessage( const std::string& topic, - unsigned int group, + int group, const std::string& controlName, const ScrollPositionMessage& message) : topic(topic), group(group), controlName(controlName), message(message) @@ -37,13 +37,13 @@ namespace rwe } GroupMessage::GroupMessage( - const std::string& topic, unsigned int group, const std::string& controlName, const ScrollUpMessage& message) + const std::string& topic, int group, const std::string& controlName, const ScrollUpMessage& message) : topic(topic), group(group), controlName(controlName), message(message) { } GroupMessage::GroupMessage( - const std::string& topic, unsigned int group, const std::string& controlName, const ScrollDownMessage& message) + const std::string& topic, int group, const std::string& controlName, const ScrollDownMessage& message) : topic(topic), group(group), controlName(controlName), message(message) { } diff --git a/src/rwe/events.h b/src/rwe/events.h index 83682a6c6..61255121b 100644 --- a/src/rwe/events.h +++ b/src/rwe/events.h @@ -73,17 +73,17 @@ namespace rwe struct GroupMessage { std::string topic; - unsigned int group; + int group; std::string controlName; ControlMessage message; - GroupMessage(const std::string& topic, unsigned int group, const std::string& controlName, const ControlMessage& message); + GroupMessage(const std::string& topic, int group, const std::string& controlName, const ControlMessage& message); - GroupMessage(const std::string& topic, unsigned int group, const std::string& controlName, const ScrollPositionMessage& message); + GroupMessage(const std::string& topic, int group, const std::string& controlName, const ScrollPositionMessage& message); - GroupMessage(const std::string& topic, unsigned int group, const std::string& controlName, const ScrollUpMessage& message); + GroupMessage(const std::string& topic, int group, const std::string& controlName, const ScrollUpMessage& message); - GroupMessage(const std::string& topic, unsigned int group, const std::string& controlName, const ScrollDownMessage& message); + GroupMessage(const std::string& topic, int group, const std::string& controlName, const ScrollDownMessage& message); }; struct ButtonClickEvent diff --git a/src/rwe/fixed_point.cpp b/src/rwe/fixed_point.cpp index 010a3aec6..0f40d73b5 100644 --- a/src/rwe/fixed_point.cpp +++ b/src/rwe/fixed_point.cpp @@ -4,7 +4,7 @@ namespace rwe { int toFixedPoint(float val) { - return static_cast(val * 65536.0f); + return static_cast(val * 65536.0f); } float fromFixedPoint(int val) diff --git a/src/rwe/grid/DiscreteRect.cpp b/src/rwe/grid/DiscreteRect.cpp index a9ded2876..050759747 100644 --- a/src/rwe/grid/DiscreteRect.cpp +++ b/src/rwe/grid/DiscreteRect.cpp @@ -82,19 +82,19 @@ namespace rwe // point is left of the rectangle if (px <= minX) { - auto distanceX = static_cast(minX - px); + auto distanceX = minX - px; // top-left corner if (py <= minY) { - auto distanceY = static_cast(minY - py); + auto distanceY = minY - py; return OctileDistance::fromXAndY(distanceX, distanceY); } // bottom-left corner if (py >= maxY) { - auto distanceY = static_cast(py - maxY); + auto distanceY = py - maxY; return OctileDistance::fromXAndY(distanceX, distanceY); } @@ -105,19 +105,19 @@ namespace rwe // point is right of the rectangle if (px >= maxX) { - auto distanceX = static_cast(px - maxX); + auto distanceX = px - maxX; // top-right corner if (py <= minY) { - auto distanceY = static_cast(minY - py); + auto distanceY = minY - py; return OctileDistance::fromXAndY(distanceX, distanceY); } // bottom-right corner if (py >= maxY) { - auto distanceY = static_cast(py - maxY); + auto distanceY = py - maxY; return OctileDistance::fromXAndY(distanceX, distanceY); } @@ -128,32 +128,32 @@ namespace rwe // top edge if (py <= minY) { - auto distanceY = static_cast(minY - py); + auto distanceY = minY - py; return OctileDistance(distanceY, 0); } // bottom edge if (py >= maxY) { - auto distanceY = static_cast(py - maxY); + auto distanceY = py - maxY; return OctileDistance(distanceY, 0); } // inside - auto distance = std::min( - {static_cast(px - minX), - static_cast(maxX - px), - static_cast(py - minY), - static_cast(maxY - py)}); + auto distance = std::min( + {px - minX, + maxX - px, + py - minY, + maxY - py}); return OctileDistance(distance, 0); } - DiscreteRect DiscreteRect::expand(unsigned int amount) const + DiscreteRect DiscreteRect::expand(int amount) const { return expand(amount, amount); } - DiscreteRect DiscreteRect::expand(unsigned int dx, unsigned int dy) const + DiscreteRect DiscreteRect::expand(int dx, int dy) const { return DiscreteRect(x - dx, y - dy, width + (2 * dx), height + (2 * dy)); } @@ -163,8 +163,8 @@ namespace rwe auto left = std::max(x, rhs.x); auto top = std::max(y, rhs.y); - auto right = std::min(x + static_cast(width), rhs.x + static_cast(rhs.width)); - auto bottom = std::min(y + static_cast(height), rhs.y + static_cast(rhs.height)); + auto right = std::min(x + width, rhs.x + rhs.width); + auto bottom = std::min(y + height, rhs.y + rhs.height); auto intersectWidth = right - left; auto intersectHeight = bottom - top; @@ -174,7 +174,7 @@ namespace rwe return std::nullopt; } - return DiscreteRect(left, top, static_cast(intersectWidth), static_cast(intersectHeight)); + return DiscreteRect(left, top, intersectWidth, intersectHeight); } DiscreteRect DiscreteRect::translate(int dx, int dy) const @@ -184,14 +184,14 @@ namespace rwe bool DiscreteRect::contains(const Point& p) const { - return p.x >= x && p.y >= y && p.x < (x + static_cast(width)) && p.y < (y + static_cast(height)); + return p.x >= x && p.y >= y && p.x < (x + width) && p.y < (y + height); } - DiscreteRect DiscreteRect::expandTopLeft(unsigned int expandWidth, unsigned int expandHeight) const + DiscreteRect DiscreteRect::expandTopLeft(int expandWidth, int expandHeight) const { return DiscreteRect( - x - static_cast(expandWidth), - y - static_cast(expandHeight), + x - expandWidth, + y - expandHeight, width + expandWidth, height + expandHeight); } diff --git a/src/rwe/grid/DiscreteRect.h b/src/rwe/grid/DiscreteRect.h index 1fc2a167b..dc982b748 100644 --- a/src/rwe/grid/DiscreteRect.h +++ b/src/rwe/grid/DiscreteRect.h @@ -13,11 +13,11 @@ namespace rwe int x; int y; - unsigned int width; - unsigned int height; + int width; + int height; DiscreteRect() = default; - DiscreteRect(int x, int y, unsigned int width, unsigned int height) : x(x), y(y), width(width), height(height) + DiscreteRect(int x, int y, int width, int height) : x(x), y(y), width(width), height(height) { } @@ -64,9 +64,9 @@ namespace rwe OctileDistance octileDistanceToTopLeftTouching(int px, int py) const; - DiscreteRect expand(unsigned int amount) const; + DiscreteRect expand(int amount) const; - DiscreteRect expand(unsigned int dx, unsigned int dy) const; + DiscreteRect expand(int dx, int dy) const; DiscreteRect translate(int dx, int dy) const; @@ -78,7 +78,7 @@ namespace rwe */ std::optional intersection(const DiscreteRect& rhs) const; - DiscreteRect expandTopLeft(unsigned int expandWidth, unsigned int expandHeight) const; + DiscreteRect expandTopLeft(int expandWidth, int expandHeight) const; }; } diff --git a/src/rwe/grid/DiscreteRect.test.cpp b/src/rwe/grid/DiscreteRect.test.cpp index 59fcf53e5..132a18f3d 100644 --- a/src/rwe/grid/DiscreteRect.test.cpp +++ b/src/rwe/grid/DiscreteRect.test.cpp @@ -120,7 +120,7 @@ namespace rwe REQUIRE(!r.isAdjacentTo(DiscreteRect(2, -1, 3, 2))); } - rc::prop("a unit rectangle is adjacent if the point is", [](int x, int y, unsigned int w, unsigned int h, int x2, int y2) { + rc::prop("a unit rectangle is adjacent if the point is", [](int x, int y, int w, int h, int x2, int y2) { DiscreteRect r(x, y, w, h); RC_ASSERT(r.isAdjacentTo(DiscreteRect(x2, y2, 1, 1)) == r.isAdjacentTo(x2, y2)); }); diff --git a/src/rwe/grid/EightWayDirection.cpp b/src/rwe/grid/EightWayDirection.cpp index 006c2da5e..6fbdfbc0d 100644 --- a/src/rwe/grid/EightWayDirection.cpp +++ b/src/rwe/grid/EightWayDirection.cpp @@ -88,20 +88,20 @@ namespace rwe throw std::runtime_error("Invalid point direction"); } - unsigned int directionToIndex(Direction d) + int directionToIndex(Direction d) { - return static_cast(d); + return static_cast(d); } - Direction directionFromIndex(unsigned int i) + Direction directionFromIndex(int i) { assert(i < 8); return static_cast(i); } - unsigned int directionDistance(Direction a, Direction b) + int directionDistance(Direction a, Direction b) { - auto indexDifference = static_cast(directionToIndex(b)) - static_cast(directionToIndex(a)); - return static_cast(std::abs(wrap(-4, 4, indexDifference))); + int indexDifference = directionToIndex(b) - directionToIndex(a); + return std::abs(wrap(-4, 4, indexDifference)); } } diff --git a/src/rwe/grid/EightWayDirection.h b/src/rwe/grid/EightWayDirection.h index c74576f72..29e57df45 100644 --- a/src/rwe/grid/EightWayDirection.h +++ b/src/rwe/grid/EightWayDirection.h @@ -37,7 +37,7 @@ namespace rwe Direction pointToDirection(const Point& p); - unsigned int directionToIndex(Direction d); + int directionToIndex(Direction d); - unsigned int directionDistance(Direction a, Direction b); + int directionDistance(Direction a, Direction b); } diff --git a/src/rwe/grid/Grid.h b/src/rwe/grid/Grid.h index 7da168aa3..ca8ecae92 100644 --- a/src/rwe/grid/Grid.h +++ b/src/rwe/grid/Grid.h @@ -12,10 +12,10 @@ namespace rwe { struct GridCoordinates { - std::size_t x; - std::size_t y; + int x; + int y; GridCoordinates() = default; - GridCoordinates(size_t x, size_t y) : x(x), y(y) + GridCoordinates(int x, int y) : x(x), y(y) { } @@ -39,21 +39,22 @@ namespace rwe return GridRegion(x.first, y.first, x.second - x.first + 1, y.second - y.first + 1); } - std::size_t x; - std::size_t y; - std::size_t width; - std::size_t height; + int x; + int y; + int width; + int height; GridRegion() = default; - GridRegion(unsigned int x, unsigned int y, unsigned int width, unsigned int height) + + GridRegion(int x, int y, int width, int height) : x(x), y(y), width(width), height(height) {} template void forEach(Func f) const { - for (std::size_t dy = 0; dy < height; ++dy) + for (int dy = 0; dy < height; ++dy) { - for (std::size_t dx = 0; dx < width; ++dx) + for (int dx = 0; dx < width; ++dx) { f(GridCoordinates(x + dx, y + dy)); } @@ -63,9 +64,9 @@ namespace rwe template void forEach(Func f) { - for (std::size_t dy = 0; dy < height; ++dy) + for (int dy = 0; dy < height; ++dy) { - for (std::size_t dx = 0; dx < width; ++dx) + for (int dx = 0; dx < width; ++dx) { f(GridCoordinates(x + dx, y + dy)); } @@ -75,9 +76,9 @@ namespace rwe template bool any(Func f) const { - for (std::size_t dy = 0; dy < height; ++dy) + for (int dy = 0; dy < height; ++dy) { - for (std::size_t dx = 0; dx < width; ++dx) + for (int dx = 0; dx < width; ++dx) { if (f(GridCoordinates(x + dx, y + dy))) { @@ -101,13 +102,13 @@ namespace rwe class Grid { private: - std::size_t width; - std::size_t height; + int width; + int height; std::vector data; public: template - static Grid from(std::size_t width, std::size_t height, Func f) + static Grid from(int width, int height, Func f) { Grid g(width, height); g.fill(f); @@ -116,24 +117,24 @@ namespace rwe Grid() : width(0), height(0) {} - Grid(std::size_t width, std::size_t height) + Grid(int width, int height) : width(width), height(height), data(width * height) {} - Grid(std::size_t width, std::size_t height, const T& initialValue) + Grid(int width, int height, const T& initialValue) : width(width), height(height), data(width * height, initialValue) {} - Grid(std::size_t width, std::size_t height, std::vector&& data) + Grid(int width, int height, std::vector&& data) : width(width), height(height), data(std::move(data)) { assert(this->data.size() == width * height); } - T& get(std::size_t x, std::size_t y) + T& get(int x, int y) { return data[toIndex(x, y)]; } - const T& get(std::size_t x, std::size_t y) const + const T& get(int x, int y) const { return data[toIndex(x, y)]; } @@ -148,12 +149,12 @@ namespace rwe return data[toIndex(coords)]; } - void set(std::size_t x, std::size_t y, const T& value) + void set(int x, int y, const T& value) { data[toIndex(x, y)] = value; } - void set(std::size_t x, std::size_t y, T&& value) + void set(int x, int y, T&& value) { data[toIndex(x, y)] = std::move(value); } @@ -185,24 +186,24 @@ namespace rwe return !(rhs == *this); } - std::size_t toIndex(std::size_t x, std::size_t y) const + std::size_t toIndex(int x, int y) const { assert(x < width && y < height); - return (y * width) + x; + return (static_cast(y) * width) + x; } std::size_t toIndex(const GridCoordinates& coords) const { assert(coords.x < width && coords.y < height); - return (coords.y * width) + coords.x; + return (static_cast(coords.y) * width) + coords.x; } - std::size_t getWidth() const + int getWidth() const { return width; } - std::size_t getHeight() const + int getHeight() const { return height; } @@ -232,16 +233,16 @@ namespace rwe return GridRegion(0, 0, width, height); } - void replace(std::size_t x, std::size_t y, const Grid& replacement) + void replace(int x, int y, const Grid& replacement) { if (x + replacement.getWidth() > getWidth() || y + replacement.getHeight() > getHeight()) { throw std::logic_error("replacement goes out of bounds"); } - for (std::size_t dy = 0; dy < replacement.getHeight(); ++dy) + for (int dy = 0; dy < replacement.getHeight(); ++dy) { - for (std::size_t dx = 0; dx < replacement.getWidth(); ++dx) + for (int dx = 0; dx < replacement.getWidth(); ++dx) { set(x + dx, y + dy, replacement.get(dx, dy)); } @@ -269,7 +270,7 @@ namespace rwe } template - bool any2(unsigned int x, unsigned int y, const Grid& g, BinaryFunc f) const + bool any2(int x, int y, const Grid& g, BinaryFunc f) const { assert(x + g.getWidth() <= this->width); assert(y + g.getHeight() <= this->height); @@ -285,7 +286,7 @@ namespace rwe } template - void forEach2(unsigned int x, unsigned int y, const Grid& g, BinaryFunc f) + void forEach2(int x, int y, const Grid& g, BinaryFunc f) { assert(x + g.getWidth() <= this->width); assert(y + g.getHeight() <= this->height); @@ -327,8 +328,8 @@ namespace rwe { return rect.x >= 0 && rect.y >= 0 - && static_cast(rect.x) + rect.width <= width - && static_cast(rect.y) + rect.height <= height; + && rect.x + rect.width <= width + && rect.y + rect.height <= height; } /** @@ -357,13 +358,13 @@ namespace rwe */ GridCoordinates clampToCoords(const Point& p) const { - std::size_t x = (p.x > 0) ? static_cast(p.x) : 0; + int x = (p.x > 0) ? p.x : 0; if (x >= width) { x = width - 1; } - std::size_t y = (p.y > 0) ? static_cast(p.y) : 0; + int y = (p.y > 0) ? p.y : 0; if (y >= height) { y = height - 1; @@ -383,8 +384,8 @@ namespace rwe return std::nullopt; } - auto x1 = static_cast(p.x); - auto y1 = static_cast(p.y); + auto x1 = p.x; + auto y1 = p.y; if (x1 >= width || y1 >= height) { @@ -405,7 +406,7 @@ namespace rwe } template - void transformAndReplace(std::size_t x, std::size_t y, const Grid& replacement, Func f) + void transformAndReplace(int x, int y, const Grid& replacement, Func f) { if (x + replacement.getWidth() > getWidth() || y + replacement.getHeight() > getHeight()) { @@ -416,7 +417,7 @@ namespace rwe } template - void transformAndReplace(std::size_t x, std::size_t y, std::size_t regionWidth, std::size_t regionHeight, const Grid& replacement, Func f) + void transformAndReplace(int x, int y, int regionWidth, int regionHeight, const Grid& replacement, Func f) { if (x + regionWidth > getWidth() || y + regionHeight > getHeight()) { @@ -447,8 +448,8 @@ namespace rwe return GridRegion(0, 0, 0, 0); } return GridRegion( - static_cast(intersect->x), // guaranteed non-negative - static_cast(intersect->y), // guaranteed non-negative + intersect->x, // guaranteed non-negative + intersect->y, // guaranteed non-negative intersect->width, intersect->height); } diff --git a/src/rwe/io/_3do/_3do.cpp b/src/rwe/io/_3do/_3do.cpp index 289d63bcb..679a721da 100644 --- a/src/rwe/io/_3do/_3do.cpp +++ b/src/rwe/io/_3do/_3do.cpp @@ -33,7 +33,7 @@ namespace rwe outputObject.name = readNullTerminatedString(stream); stream.seekg(object.verticesOffset); - for (unsigned int i = 0; i < object.numberOfVertices; ++i) + for (int i = 0; i < object.numberOfVertices; ++i) { auto v = readRaw<_3doVertex>(stream); outputObject.vertices.push_back(_3do::Vertex{v.x, v.y, v.z}); @@ -42,7 +42,7 @@ namespace rwe stream.seekg(object.primitivesOffset); std::vector<_3doPrimitive> ps; ps.reserve(object.numberOfPrimitives); - for (unsigned int i = 0; i < object.numberOfPrimitives; ++i) + for (int i = 0; i < object.numberOfPrimitives; ++i) { ps.push_back(readRaw<_3doPrimitive>(stream)); } @@ -67,7 +67,7 @@ namespace rwe } stream.seekg(p.verticesOffset); - for (unsigned int j = 0; j < p.numberOfVertices; ++j) + for (int j = 0; j < p.numberOfVertices; ++j) { outP.vertices.push_back(readRaw(stream)); } diff --git a/src/rwe/io/_3do/_3do.h b/src/rwe/io/_3do/_3do.h index bd31b067c..fe770a683 100644 --- a/src/rwe/io/_3do/_3do.h +++ b/src/rwe/io/_3do/_3do.h @@ -7,7 +7,7 @@ namespace rwe { - static const unsigned int _3doMagicNumber = 1; + static const int _3doMagicNumber = 1; #pragma pack(1) struct _3doObject @@ -60,8 +60,8 @@ namespace rwe struct Primitive { - std::optional colorIndex; - std::vector vertices; + std::optional colorIndex; + std::vector vertices; std::optional textureName; }; @@ -74,7 +74,7 @@ namespace rwe std::vector primitives; std::vector children; std::string name; - std::optional selectionPrimitiveIndex; + std::optional selectionPrimitiveIndex; }; }; diff --git a/src/rwe/io/cob/Cob.cpp b/src/rwe/io/cob/Cob.cpp index e75159ba2..af15db29e 100644 --- a/src/rwe/io/cob/Cob.cpp +++ b/src/rwe/io/cob/Cob.cpp @@ -13,7 +13,7 @@ namespace rwe // read in the instructions script.instructions.resize(header.codeLength); stream.seekg(header.offsetToScriptCode); - for (unsigned int i = 0; i < header.codeLength; ++i) + for (int i = 0; i < header.codeLength; ++i) { script.instructions[i] = readRaw(stream); } @@ -22,14 +22,14 @@ namespace rwe // read in function addresses script.functions.resize(header.numberOfScripts); stream.seekg(header.offsetToScriptCodeIndexArray); - for (unsigned int i = 0; i < header.numberOfScripts; ++i) + for (int i = 0; i < header.numberOfScripts; ++i) { script.functions[i].address = readRaw(stream); } // read in function names stream.seekg(header.offsetToScriptNameOffsetArray); - for (unsigned int i = 0; i < header.numberOfScripts; ++i) + for (int i = 0; i < header.numberOfScripts; ++i) { auto nameOffset = readRaw(stream); auto loc = stream.tellg(); @@ -41,7 +41,7 @@ namespace rwe // read in piece names script.pieces.resize(header.numberOfPieces); stream.seekg(header.offsetToPieceNameOffsetArray); - for (unsigned int i = 0; i < header.numberOfPieces; ++i) + for (int i = 0; i < header.numberOfPieces; ++i) { auto nameOffset = readRaw(stream); auto loc = stream.tellg(); diff --git a/src/rwe/io/cob/Cob.h b/src/rwe/io/cob/Cob.h index 882e7ead3..69c03694c 100644 --- a/src/rwe/io/cob/Cob.h +++ b/src/rwe/io/cob/Cob.h @@ -26,7 +26,7 @@ namespace rwe struct CobFunctionInfo { std::string name; - unsigned int address; + int address; }; struct CobScript @@ -34,7 +34,7 @@ namespace rwe std::vector instructions; std::vector pieces; std::vector functions; - unsigned int staticVariableCount; + int staticVariableCount; }; CobScript parseCob(std::istream& stream); diff --git a/src/rwe/io/fbi/UnitFbi.h b/src/rwe/io/fbi/UnitFbi.h index a614e3947..412316323 100644 --- a/src/rwe/io/fbi/UnitFbi.h +++ b/src/rwe/io/fbi/UnitFbi.h @@ -23,12 +23,12 @@ namespace rwe FbiDistancePerTickSquared acceleration; FbiDistancePerTickSquared brakeRate; - unsigned int footprintX; - unsigned int footprintZ; - unsigned int maxSlope; - unsigned int maxWaterSlope; - unsigned int minWaterDepth; - unsigned int maxWaterDepth; + int footprintX; + int footprintZ; + int maxSlope; + int maxWaterSlope; + int minWaterDepth; + int maxWaterDepth; bool canAttack; bool canMove; @@ -36,7 +36,7 @@ namespace rwe bool commander; - unsigned int maxDamage; + int maxDamage; bool bmCode; @@ -50,13 +50,13 @@ namespace rwe std::string explodeAs; bool builder; - unsigned int buildTime; + int buildTime; Energy buildCostEnergy; Metal buildCostMetal; - unsigned int workerTime; + int workerTime; - unsigned int buildDistance; + int buildDistance; bool onOffable; bool activateWhenBuilt; diff --git a/src/rwe/io/fbi/io.cpp b/src/rwe/io/fbi/io.cpp index de43be58e..89d69b745 100644 --- a/src/rwe/io/fbi/io.cpp +++ b/src/rwe/io/fbi/io.cpp @@ -34,7 +34,7 @@ namespace rwe tdf.readOrDefault("FootprintX", u.footprintX); tdf.readOrDefault("FootprintZ", u.footprintZ); - tdf.readOrDefault("MaxSlope", u.maxSlope, 255u); + tdf.readOrDefault("MaxSlope", u.maxSlope, 255); tdf.readOrDefault("MaxWaterSlope", u.maxWaterSlope, u.maxSlope); tdf.readOrDefault("MinWaterDepth", u.minWaterDepth); tdf.readOrDefault("MaxWaterDepth", u.maxWaterDepth); diff --git a/src/rwe/io/featuretdf/FeatureDefinition.h b/src/rwe/io/featuretdf/FeatureDefinition.h index e21bd2ecf..474a92503 100644 --- a/src/rwe/io/featuretdf/FeatureDefinition.h +++ b/src/rwe/io/featuretdf/FeatureDefinition.h @@ -14,9 +14,9 @@ namespace rwe std::string description; std::string category; - unsigned int footprintX; - unsigned int footprintZ; - unsigned int height; + int footprintX; + int footprintZ; + int height; bool animating; std::string fileName; @@ -31,25 +31,25 @@ namespace rwe bool autoreclaimable; std::string seqNameReclamate; std::string featureReclamate; - unsigned int metal; - unsigned int energy; + int metal; + int energy; bool flamable; std::string seqNameBurn; std::string seqNameBurnShad; std::string featureBurnt; - unsigned int burnMin; - unsigned int burnMax; - unsigned int sparkTime; - unsigned int spreadChance; + int burnMin; + int burnMax; + int sparkTime; + int spreadChance; std::string burnWeapon; bool geothermal; - unsigned int hitDensity; + int hitDensity; bool reproduce; - unsigned int reproduceArea; + int reproduceArea; bool noDisplayInfo; @@ -58,7 +58,7 @@ namespace rwe bool blocking; bool indestructible; - unsigned int damage; + int damage; std::string seqNameDie; std::string featureDead; }; diff --git a/src/rwe/io/fnt/Fnt.cpp b/src/rwe/io/fnt/Fnt.cpp index 4e0490c72..d3965167d 100644 --- a/src/rwe/io/fnt/Fnt.cpp +++ b/src/rwe/io/fnt/Fnt.cpp @@ -15,7 +15,7 @@ namespace rwe _stream = stream; } - unsigned int FntArchive::extract(unsigned int index, char* buffer) + int FntArchive::extract(int index, char* buffer) { auto ptr = _entries.at(index); if (ptr == 0) @@ -29,7 +29,7 @@ namespace rwe return _stream->gcount(); } - unsigned int FntArchive::glyphHeight() const + int FntArchive::glyphHeight() const { return _header.glyphHeight; } diff --git a/src/rwe/io/fnt/Fnt.h b/src/rwe/io/fnt/Fnt.h index 11bb5c903..92a27793c 100644 --- a/src/rwe/io/fnt/Fnt.h +++ b/src/rwe/io/fnt/Fnt.h @@ -22,7 +22,7 @@ namespace rwe public: explicit FntArchive(std::istream* stream); - unsigned int glyphHeight() const; + int glyphHeight() const; /** * Writes glyph data out to the given buffer. @@ -35,6 +35,6 @@ namespace rwe * If there is no glyph for the given index (from 0 to 255), * returns 0 and writes no data to the buffer. */ - unsigned int extract(unsigned int index, char* buffer); + int extract(int index, char* buffer); }; } diff --git a/src/rwe/io/gaf/GafReaderAdapter.h b/src/rwe/io/gaf/GafReaderAdapter.h index 1fd070828..936f143a0 100644 --- a/src/rwe/io/gaf/GafReaderAdapter.h +++ b/src/rwe/io/gaf/GafReaderAdapter.h @@ -11,8 +11,8 @@ namespace rwe { int x; int y; - unsigned int width; - unsigned int height; + int width; + int height; unsigned char transparencyKey; char* data; }; diff --git a/src/rwe/io/gui/gui.h b/src/rwe/io/gui/gui.h index 63dabb3ed..325cceeea 100644 --- a/src/rwe/io/gui/gui.h +++ b/src/rwe/io/gui/gui.h @@ -27,13 +27,13 @@ namespace rwe struct GuiButtonAttrib { - static constexpr unsigned int LabelDisplayLeft = 1; - static constexpr unsigned int LabelDisplayCenter = 2; + static constexpr int LabelDisplayLeft = 1; + static constexpr int LabelDisplayCenter = 2; - static constexpr unsigned int BehaviorRadio = 16; - static constexpr unsigned int BehaviorBuildButton = 32; - static constexpr unsigned int BehaviorToggle = 64; - static constexpr unsigned int BehaviorCycle = 256; + static constexpr int BehaviorRadio = 16; + static constexpr int BehaviorBuildButton = 32; + static constexpr int BehaviorToggle = 64; + static constexpr int BehaviorCycle = 256; }; const int GuiScrollHorizontalAttrib = 1; diff --git a/src/rwe/io/pcx/pcx.h b/src/rwe/io/pcx/pcx.h index f83294f2d..054b5a3a9 100644 --- a/src/rwe/io/pcx/pcx.h +++ b/src/rwe/io/pcx/pcx.h @@ -70,12 +70,12 @@ namespace rwe header = reinterpret_cast(&*begin); } - unsigned int getWidth() + int getWidth() { return (header->window.xMax - header->window.xMin) + 1u; } - unsigned int getHeight() + int getHeight() { return (header->window.yMax - header->window.yMin) + 1u; } diff --git a/src/rwe/io/tnt/TntArchive.cpp b/src/rwe/io/tnt/TntArchive.cpp index eb26b0f46..951e91406 100644 --- a/src/rwe/io/tnt/TntArchive.cpp +++ b/src/rwe/io/tnt/TntArchive.cpp @@ -29,7 +29,7 @@ namespace rwe std::array buffer{}; - for (unsigned int i = 0; i < header.numberOfTiles; ++i) + for (int i = 0; i < header.numberOfTiles; ++i) { stream->read(buffer.data(), 32 * 32); tileCallback(buffer.data()); @@ -43,7 +43,7 @@ namespace rwe std::string str; str.reserve(128); - for (unsigned int i = 0; i < header.numberOfFeatures; ++i) + for (int i = 0; i < header.numberOfFeatures; ++i) { auto feature = readRaw(*stream); auto nullIt = std::find(feature.name, feature.name + 128, '\0'); @@ -72,14 +72,14 @@ namespace rwe struct MinimapSize { - unsigned int width; - unsigned int height; + int width; + int height; }; - MinimapSize getMinimapActualSize(const std::vector& data, unsigned int width, unsigned int height) + MinimapSize getMinimapActualSize(const std::vector& data, int width, int height) { - unsigned int realWidth = width; - unsigned int realHeight = height; + int realWidth = width; + int realHeight = height; while (realWidth > 0 && data[realWidth - 1] == TntMinimapVoidByte) { @@ -94,15 +94,15 @@ namespace rwe return MinimapSize{realWidth, realHeight}; } - std::vector trimMinimapBytes(const std::vector& data, unsigned int width, unsigned int height, unsigned int newWidth, unsigned int newHeight) + std::vector trimMinimapBytes(const std::vector& data, int width, int height, int newWidth, int newHeight) { assert(newWidth <= width); assert(newHeight <= height); std::vector newData(newWidth * newHeight); - for (unsigned int y = 0; y < newHeight; ++y) + for (int y = 0; y < newHeight; ++y) { - for (unsigned int x = 0; x < newWidth; ++x) + for (int x = 0; x < newWidth; ++x) { newData[(y * newWidth) + x] = data[(y * width) + x]; } diff --git a/src/rwe/io/tnt/TntArchive.h b/src/rwe/io/tnt/TntArchive.h index a186a22cc..86f7cdba1 100644 --- a/src/rwe/io/tnt/TntArchive.h +++ b/src/rwe/io/tnt/TntArchive.h @@ -9,7 +9,7 @@ namespace rwe { - static const unsigned int TntMagicNumber = 0x2000; + static const int TntMagicNumber = 0x2000; static const uint8_t TntMinimapVoidByte = 0x64; @@ -71,8 +71,8 @@ namespace rwe struct TntMinimapInfo { - unsigned int width; - unsigned int height; + int width; + int height; std::vector data; }; diff --git a/src/rwe/io/weapontdf/WeaponTdf.cpp b/src/rwe/io/weapontdf/WeaponTdf.cpp index efb1b4ee7..b459b028a 100644 --- a/src/rwe/io/weapontdf/WeaponTdf.cpp +++ b/src/rwe/io/weapontdf/WeaponTdf.cpp @@ -2,13 +2,13 @@ namespace rwe { - std::vector> parseWeaponDamageBlock(const TdfBlock& block) + std::vector> parseWeaponDamageBlock(const TdfBlock& block) { - std::vector> items; + std::vector> items; for (const auto& entry : block.properties) { - auto value = tdfTryParse(entry.second); + auto value = tdfTryParse(entry.second); if (!value) { throw std::runtime_error("Failed to parse damage value: " + entry.second); @@ -71,8 +71,8 @@ namespace rwe tdf.readOrDefault("burnBlow", w.burnBlow); tdf.readOrDefault("accuracy", w.accuracy); - tdf.readOrDefault("tolerance", w.tolerance, 256u); - tdf.readOrDefault("pitchTolerance", w.pitchTolerance, 256u); + tdf.readOrDefault("tolerance", w.tolerance, 256); + tdf.readOrDefault("pitchTolerance", w.pitchTolerance, 256); tdf.readOrDefault("aimRate", w.aimRate); tdf.readOrDefault("holdTime", w.holdTime); diff --git a/src/rwe/io/weapontdf/WeaponTdf.h b/src/rwe/io/weapontdf/WeaponTdf.h index 2bfb738bd..42c1823d6 100644 --- a/src/rwe/io/weapontdf/WeaponTdf.h +++ b/src/rwe/io/weapontdf/WeaponTdf.h @@ -9,10 +9,10 @@ namespace rwe class WeaponTdf { public: - unsigned int id; + int id; std::string name; - unsigned int range; + int range; bool ballistic; bool lineOfSight; @@ -22,22 +22,22 @@ namespace rwe bool noExplode; float reloadTime; - unsigned int energyPerShot; - unsigned int metalPerShot; + int energyPerShot; + int metalPerShot; float weaponTimer; bool noAutoRange; - unsigned int weaponVelocity; - unsigned int weaponAcceleration; - unsigned int areaOfEffect; + int weaponVelocity; + int weaponAcceleration; + int areaOfEffect; float edgeEffectiveness; bool turret; float fireStarter; bool unitsOnly; - unsigned int burst; + int burst; float burstRate; - unsigned int sprayAngle; + int sprayAngle; float randomDecay; bool groundBounce; @@ -46,7 +46,7 @@ namespace rwe bool twoPhase; bool guidance; - unsigned int turnRate; + int turnRate; bool cruise; @@ -55,20 +55,20 @@ namespace rwe bool waterWeapon; bool burnBlow; - unsigned int accuracy; - unsigned int tolerance; - unsigned int pitchTolerance; - unsigned int aimRate; - unsigned int holdTime; + int accuracy; + int tolerance; + int pitchTolerance; + int aimRate; + int holdTime; bool stockpile; bool interceptor; - unsigned int coverage; + int coverage; bool targetable; bool toAirWeapon; - unsigned int startVelocity; + int startVelocity; float minBarrelAngle; bool paralyzer; @@ -76,13 +76,13 @@ namespace rwe bool noRadar; std::string model; - unsigned int color; - unsigned int color2; + int color; + int color2; bool smokeTrail; float smokeDelay; bool startSmoke; bool endSmoke; - unsigned int renderType; + int renderType; bool beamWeapon; float duration; @@ -104,18 +104,18 @@ namespace rwe bool commandFire; - unsigned int shakeMagnitude; + int shakeMagnitude; float shakeDuration; - unsigned int energy; - unsigned int metal; + int energy; + int metal; - std::vector> damage; + std::vector> damage; std::string weaponType2; }; - std::vector> parseWeaponDamageBlock(const TdfBlock& block); + std::vector> parseWeaponDamageBlock(const TdfBlock& block); WeaponTdf parseWeaponBlock(const TdfBlock& tdf); diff --git a/src/rwe/network_util.cpp b/src/rwe/network_util.cpp index dbbaf76ec..3701873e2 100644 --- a/src/rwe/network_util.cpp +++ b/src/rwe/network_util.cpp @@ -21,7 +21,7 @@ namespace rwe | (static_cast(static_cast(buffer[1])) << 8u) | (static_cast(static_cast(buffer[0]))); } - unsigned int computeCrc(const char* buffer, unsigned int size) + unsigned int computeCrc(const char* buffer, int size) { // throw in a CRC to verify the message boost::crc_32_type crc; diff --git a/src/rwe/network_util.h b/src/rwe/network_util.h index 9ffc6a758..308080f00 100644 --- a/src/rwe/network_util.h +++ b/src/rwe/network_util.h @@ -28,5 +28,5 @@ namespace rwe unsigned int readInt(const char* buffer); - unsigned int computeCrc(const char* buffer, unsigned int size); + unsigned int computeCrc(const char* buffer, int size); // TODO (kwh) - can return and readInt be changed to int? } diff --git a/src/rwe/observable/Subject.h b/src/rwe/observable/Subject.h index b00e44e16..db2557ace 100644 --- a/src/rwe/observable/Subject.h +++ b/src/rwe/observable/Subject.h @@ -15,7 +15,7 @@ namespace rwe using SubscriberCallback = typename Observable::SubscriberCallback; private: - using SubscriberId = unsigned int; + using SubscriberId = int; struct Subscriber { diff --git a/src/rwe/pathfinding/AStarPathFinder.h b/src/rwe/pathfinding/AStarPathFinder.h index 8ad353579..331fd12d1 100644 --- a/src/rwe/pathfinding/AStarPathFinder.h +++ b/src/rwe/pathfinding/AStarPathFinder.h @@ -13,7 +13,7 @@ namespace rwe * The maximum number of elements in the open list to expand * before giving up on a path search. */ - const unsigned int MaxOpenListQueries = 2000; + const int MaxOpenListQueries = 2000; template struct AStarVertexInfo @@ -55,7 +55,7 @@ namespace rwe std::optional> closestVertex; - unsigned int openListPopsPerformed = 0; + int openListPopsPerformed = 0; while (!openVertices.empty() && openListPopsPerformed < MaxOpenListQueries) { diff --git a/src/rwe/pathfinding/AbstractUnitPathFinder.cpp b/src/rwe/pathfinding/AbstractUnitPathFinder.cpp index c65b4fb7b..5e3801d5f 100644 --- a/src/rwe/pathfinding/AbstractUnitPathFinder.cpp +++ b/src/rwe/pathfinding/AbstractUnitPathFinder.cpp @@ -7,8 +7,8 @@ namespace rwe MovementClassCollisionService* collisionService, UnitId self, std::optional movementClass, - unsigned int footprintX, - unsigned int footprintZ) + int footprintX, + int footprintZ) : simulation(simulation), collisionService(collisionService), self(self), @@ -40,7 +40,7 @@ namespace rwe // double the cost on rough terrain distance = distance + distance; } - unsigned int turns = (!prevDirection || direction == *prevDirection) ? 0 : 1; + int turns = (!prevDirection || direction == *prevDirection) ? 0 : 1; PathCost cost(distance, turns); vs.push_back(VertexInfo{info.costToReach + cost, neighbour, &info}); } diff --git a/src/rwe/pathfinding/AbstractUnitPathFinder.h b/src/rwe/pathfinding/AbstractUnitPathFinder.h index 5aa929b5c..1b6b71a26 100644 --- a/src/rwe/pathfinding/AbstractUnitPathFinder.h +++ b/src/rwe/pathfinding/AbstractUnitPathFinder.h @@ -21,8 +21,8 @@ namespace rwe MovementClassCollisionService* const collisionService; const UnitId self; const std::optional movementClass; - const unsigned int footprintX; - const unsigned int footprintZ; + const int footprintX; + const int footprintZ; public: AbstractUnitPathFinder( @@ -30,8 +30,8 @@ namespace rwe MovementClassCollisionService* collisionService, UnitId self, std::optional movementClass, - unsigned int footprintX, - unsigned int footprintZ); + int footprintX, + int footprintZ); protected: std::vector getSuccessors(const VertexInfo& vertex) override; diff --git a/src/rwe/pathfinding/OctileDistance.cpp b/src/rwe/pathfinding/OctileDistance.cpp index 2a2190f4b..7d9a209db 100644 --- a/src/rwe/pathfinding/OctileDistance.cpp +++ b/src/rwe/pathfinding/OctileDistance.cpp @@ -5,7 +5,7 @@ namespace rwe { static const float DiagonalDistance = std::sqrt(2.0f); - OctileDistance OctileDistance::fromXAndY(unsigned int x, unsigned int y) + OctileDistance OctileDistance::fromXAndY(int x, int y) { if (x > y) { @@ -17,7 +17,7 @@ namespace rwe } } - OctileDistance::OctileDistance(unsigned int straight, unsigned int diagonal) : straight(straight), diagonal(diagonal) + OctileDistance::OctileDistance(int straight, int diagonal) : straight(straight), diagonal(diagonal) { } diff --git a/src/rwe/pathfinding/OctileDistance.h b/src/rwe/pathfinding/OctileDistance.h index 146403706..81999b38e 100644 --- a/src/rwe/pathfinding/OctileDistance.h +++ b/src/rwe/pathfinding/OctileDistance.h @@ -5,13 +5,13 @@ namespace rwe /** A distance in grid squares separated into straight and diagonal components. */ struct OctileDistance { - unsigned int straight{0}; - unsigned int diagonal{0}; + int straight{0}; + int diagonal{0}; - static OctileDistance fromXAndY(unsigned int x, unsigned int y); + static OctileDistance fromXAndY(int x, int y); OctileDistance() = default; - OctileDistance(unsigned int straight, unsigned int diagonal); + OctileDistance(int straight, int diagonal); bool operator==(const OctileDistance& rhs) const; diff --git a/src/rwe/pathfinding/PathCost.cpp b/src/rwe/pathfinding/PathCost.cpp index 609aa081d..d272ac40b 100644 --- a/src/rwe/pathfinding/PathCost.cpp +++ b/src/rwe/pathfinding/PathCost.cpp @@ -2,7 +2,7 @@ namespace rwe { - PathCost::PathCost(const OctileDistance& distance, unsigned int turnCount) + PathCost::PathCost(const OctileDistance& distance, int turnCount) : distance(distance), turnCount(turnCount) { } diff --git a/src/rwe/pathfinding/PathCost.h b/src/rwe/pathfinding/PathCost.h index b1b1aee2c..e5f5ead8d 100644 --- a/src/rwe/pathfinding/PathCost.h +++ b/src/rwe/pathfinding/PathCost.h @@ -7,10 +7,10 @@ namespace rwe struct PathCost { OctileDistance distance; - unsigned int turnCount{0}; + int turnCount{0}; PathCost() = default; - PathCost(const OctileDistance& distance, unsigned int turnCount); + PathCost(const OctileDistance& distance, int turnCount); bool operator==(const PathCost& rhs) const; diff --git a/src/rwe/pathfinding/PathFindingService.cpp b/src/rwe/pathfinding/PathFindingService.cpp index 59113f414..358c46c7e 100644 --- a/src/rwe/pathfinding/PathFindingService.cpp +++ b/src/rwe/pathfinding/PathFindingService.cpp @@ -6,7 +6,7 @@ namespace rwe { - static const unsigned int MaxTasksPerTick = 10; + static const int MaxTasksPerTick = 10; PathFindingService::PathFindingService(GameSimulation* simulation, MovementClassCollisionService* collisionService) : simulation(simulation), collisionService(collisionService) @@ -16,7 +16,7 @@ namespace rwe void PathFindingService::update() { auto& requests = simulation->pathRequests; - unsigned int tasksDone = 0; + int tasksDone = 0; while (!requests.empty() && tasksDone < MaxTasksPerTick) { auto& request = requests.front(); diff --git a/src/rwe/pathfinding/PathFindingService.h b/src/rwe/pathfinding/PathFindingService.h index 20b672e9d..a0398dd2d 100644 --- a/src/rwe/pathfinding/PathFindingService.h +++ b/src/rwe/pathfinding/PathFindingService.h @@ -53,6 +53,6 @@ namespace rwe SimVector getWorldCenter(const DiscreteRect& discreteRect); - DiscreteRect expandTopLeft(const DiscreteRect& rect, unsigned int width, unsigned int height); + DiscreteRect expandTopLeft(const DiscreteRect& rect, int width, int height); }; } diff --git a/src/rwe/pathfinding/UnitPathFinder.cpp b/src/rwe/pathfinding/UnitPathFinder.cpp index 6a25b2a32..5508ed966 100644 --- a/src/rwe/pathfinding/UnitPathFinder.cpp +++ b/src/rwe/pathfinding/UnitPathFinder.cpp @@ -7,8 +7,8 @@ namespace rwe MovementClassCollisionService* collisionService, UnitId self, std::optional movementClass, - unsigned int footprintX, - unsigned int footprintZ, + int footprintX, + int footprintZ, const Point& goal) : AbstractUnitPathFinder( simulation, @@ -29,7 +29,7 @@ namespace rwe PathCost UnitPathFinder::estimateCostToGoal(const Point& start) { auto distance = octileDistance(start, goal); - unsigned int turns = (distance.straight > 0 && distance.diagonal > 0) ? 1 : 0; + int turns = (distance.straight > 0 && distance.diagonal > 0) ? 1 : 0; return PathCost(distance, turns); } } diff --git a/src/rwe/pathfinding/UnitPathFinder.h b/src/rwe/pathfinding/UnitPathFinder.h index 1d79baa7e..70d26b7b3 100644 --- a/src/rwe/pathfinding/UnitPathFinder.h +++ b/src/rwe/pathfinding/UnitPathFinder.h @@ -26,8 +26,8 @@ namespace rwe MovementClassCollisionService* collisionService, UnitId self, std::optional movementClass, - unsigned int footprintX, - unsigned int footprintZ, + int footprintX, + int footprintZ, const Point& goal); protected: diff --git a/src/rwe/pathfinding/UnitPerimeterPathFinder.cpp b/src/rwe/pathfinding/UnitPerimeterPathFinder.cpp index cdeb2d843..d48f07713 100644 --- a/src/rwe/pathfinding/UnitPerimeterPathFinder.cpp +++ b/src/rwe/pathfinding/UnitPerimeterPathFinder.cpp @@ -7,8 +7,8 @@ namespace rwe MovementClassCollisionService* collisionService, const UnitId& self, const std::optional& movementClass, - unsigned int footprintX, - unsigned int footprintZ, + int footprintX, + int footprintZ, const DiscreteRect& goalRect) : AbstractUnitPathFinder(simulation, collisionService, @@ -28,7 +28,7 @@ namespace rwe PathCost UnitPerimeterPathFinder::estimateCostToGoal(const Point& start) { auto distance = goalRect.octileDistanceToTopLeftTouching(start.x, start.y); - unsigned int turns = (distance.straight > 0 && distance.diagonal > 0) ? 1 : 0; + int turns = (distance.straight > 0 && distance.diagonal > 0) ? 1 : 0; return PathCost(distance, turns); } } diff --git a/src/rwe/pathfinding/UnitPerimeterPathFinder.h b/src/rwe/pathfinding/UnitPerimeterPathFinder.h index 400a613bf..cd4e58b72 100644 --- a/src/rwe/pathfinding/UnitPerimeterPathFinder.h +++ b/src/rwe/pathfinding/UnitPerimeterPathFinder.h @@ -21,8 +21,8 @@ namespace rwe MovementClassCollisionService* collisionService, const UnitId& self, const std::optional& movementClass, - unsigned int footprintX, - unsigned int footprintZ, + int footprintX, + int footprintZ, const DiscreteRect& goalRect); protected: diff --git a/src/rwe/pathfinding/pathfinding_utils.cpp b/src/rwe/pathfinding/pathfinding_utils.cpp index 6908b94dd..3a0dd3ea8 100644 --- a/src/rwe/pathfinding/pathfinding_utils.cpp +++ b/src/rwe/pathfinding/pathfinding_utils.cpp @@ -13,8 +13,8 @@ namespace rwe OctileDistance octileDistance(const Point& start, const Point& goal) { - auto deltaX = static_cast(std::abs(goal.x - start.x)); - auto deltaY = static_cast(std::abs(goal.y - start.y)); + int deltaX = std::abs(goal.x - start.x); + int deltaY = std::abs(goal.y - start.y); auto pair = std::minmax(deltaX, deltaY); auto deltaDiff = pair.second - pair.first; return OctileDistance{deltaDiff, pair.first}; diff --git a/src/rwe/pathfinding/pathfinding_utils.h b/src/rwe/pathfinding/pathfinding_utils.h index 9ec7355e2..d3b92b16e 100644 --- a/src/rwe/pathfinding/pathfinding_utils.h +++ b/src/rwe/pathfinding/pathfinding_utils.h @@ -12,12 +12,12 @@ namespace rwe * If this is not the case, the behaviour is undefined. */ template - static unsigned int simplifyPath(It it, It end, Inserter out) + static int simplifyPath(It it, It end, Inserter out) { const Point* curr = &*it; *out = *it++; - unsigned int appendedCount = 1; + int appendedCount = 1; int directionX = 0; int directionY = 0; diff --git a/src/rwe/render/GlMesh.cpp b/src/rwe/render/GlMesh.cpp index 29251354e..f739a7104 100644 --- a/src/rwe/render/GlMesh.cpp +++ b/src/rwe/render/GlMesh.cpp @@ -5,7 +5,7 @@ namespace rwe GlMesh::GlMesh( VaoHandle&& vao, VboHandle&& vbo, - unsigned int vertexCount) + int vertexCount) : vao(std::move(vao)), vbo(std::move(vbo)), vertexCount(vertexCount) diff --git a/src/rwe/render/GlMesh.h b/src/rwe/render/GlMesh.h index 1afa36c48..9d4e4a026 100644 --- a/src/rwe/render/GlMesh.h +++ b/src/rwe/render/GlMesh.h @@ -9,8 +9,8 @@ namespace rwe { VaoHandle vao; VboHandle vbo; - unsigned int vertexCount; + int vertexCount; - GlMesh(VaoHandle&& vao, VboHandle&& vbo, unsigned int vertexCount); + GlMesh(VaoHandle&& vao, VboHandle&& vbo, int vertexCount); }; } diff --git a/src/rwe/render/GraphicsContext.cpp b/src/rwe/render/GraphicsContext.cpp index 42d751c48..f6cf8b315 100644 --- a/src/rwe/render/GraphicsContext.cpp +++ b/src/rwe/render/GraphicsContext.cpp @@ -62,13 +62,13 @@ namespace rwe } TextureHandle - GraphicsContext::createTexture(unsigned int width, unsigned int height, const std::vector& image) + GraphicsContext::createTexture(int width, int height, const std::vector& image) { assert(image.size() == width * height); return createTexture(width, height, image.data()); } - TextureHandle GraphicsContext::createTexture(unsigned int width, unsigned int height, const Color* image) + TextureHandle GraphicsContext::createTexture(int width, int height, const Color* image) { GLuint texture; glGenTextures(1, &texture); @@ -122,7 +122,7 @@ namespace rwe return handle; } - TextureArrayHandle GraphicsContext::createTextureArray(unsigned int width, unsigned int height, unsigned int mipMapLevels, std::vector& images) + TextureArrayHandle GraphicsContext::createTextureArray(int width, int height, int mipMapLevels, std::vector& images) { assert(images.size() % (width * height) == 0); auto depth = images.size() / (width * height); diff --git a/src/rwe/render/GraphicsContext.h b/src/rwe/render/GraphicsContext.h index bed16b9f4..58a9dd175 100644 --- a/src/rwe/render/GraphicsContext.h +++ b/src/rwe/render/GraphicsContext.h @@ -121,13 +121,13 @@ namespace rwe TextureHandle createTexture(const Grid& image); - TextureHandle createTexture(unsigned int width, unsigned int height, const std::vector& image); + TextureHandle createTexture(int width, int height, const std::vector& image); - TextureHandle createTexture(unsigned int width, unsigned int height, const Color* image); + TextureHandle createTexture(int width, int height, const Color* image); TextureHandle createColorTexture(Color c); - TextureArrayHandle createTextureArray(unsigned int width, unsigned int height, unsigned int mipMapLevels, std::vector& images); + TextureArrayHandle createTextureArray(int width, int height, int mipMapLevels, std::vector& images); void enableDepthBuffer(); diff --git a/src/rwe/rwe_time.cpp b/src/rwe/rwe_time.cpp index f89392f25..dc5b8400e 100644 --- a/src/rwe/rwe_time.cpp +++ b/src/rwe/rwe_time.cpp @@ -7,9 +7,9 @@ namespace rwe return std::chrono::steady_clock::now(); } - unsigned int TimeService::getTicks() + int TimeService::getTicks() // TODO (kwh) - should be getElapsed_ms? Int is sufficient, won't roll over until after ~7 days { - return static_cast( + return static_cast( std::chrono::duration_cast(getTimestamp() - initTime).count()); } } diff --git a/src/rwe/rwe_time.h b/src/rwe/rwe_time.h index cdb3c4935..d5f9a2948 100644 --- a/src/rwe/rwe_time.h +++ b/src/rwe/rwe_time.h @@ -17,6 +17,6 @@ namespace rwe { } - unsigned int getTicks(); + int getTicks(); }; } diff --git a/src/rwe/sim/Explosion.cpp b/src/rwe/sim/Explosion.cpp index 6b267614d..78f8122ae 100644 --- a/src/rwe/sim/Explosion.cpp +++ b/src/rwe/sim/Explosion.cpp @@ -8,7 +8,7 @@ namespace rwe return currentTime >= startTime; } - unsigned int Explosion::getFrameIndex(GameTime currentTime, int totalFrames) const + int Explosion::getFrameIndex(GameTime currentTime, int totalFrames) const { assert(currentTime >= startTime); auto deltaTime = currentTime - startTime; diff --git a/src/rwe/sim/Explosion.h b/src/rwe/sim/Explosion.h index b6b49aace..1a382768f 100644 --- a/src/rwe/sim/Explosion.h +++ b/src/rwe/sim/Explosion.h @@ -31,7 +31,7 @@ namespace rwe bool translucent{false}; bool isStarted(GameTime currentTime) const; - unsigned int getFrameIndex(GameTime currentTime, int totalFrames) const; + int getFrameIndex(GameTime currentTime, int totalFrames) const; bool isFinished(GameTime currentTime, int numberOfFrames) const; }; } diff --git a/src/rwe/sim/FeatureId.h b/src/rwe/sim/FeatureId.h index c5cbdfcb6..cd0736b4a 100644 --- a/src/rwe/sim/FeatureId.h +++ b/src/rwe/sim/FeatureId.h @@ -5,5 +5,5 @@ namespace rwe { struct FeatureIdTag; - using FeatureId = OpaqueId; + using FeatureId = OpaqueId; } diff --git a/src/rwe/sim/GameSimulation.cpp b/src/rwe/sim/GameSimulation.cpp index 885f6ebe2..46ac15b18 100644 --- a/src/rwe/sim/GameSimulation.cpp +++ b/src/rwe/sim/GameSimulation.cpp @@ -142,7 +142,7 @@ namespace rwe return unitId; } - bool GameSimulation::canBeBuiltAt(const rwe::MovementClass& mc, unsigned int x, unsigned int y) const + bool GameSimulation::canBeBuiltAt(const rwe::MovementClass& mc, int x, int y) const { if (isCollisionAt(DiscreteRect(x, y, mc.footprintX, mc.footprintZ))) { @@ -157,7 +157,7 @@ namespace rwe return true; } - DiscreteRect GameSimulation::computeFootprintRegion(const SimVector& position, unsigned int footprintX, unsigned int footprintZ) const + DiscreteRect GameSimulation::computeFootprintRegion(const SimVector& position, int footprintX, int footprintZ) const { auto halfFootprintX = SimScalar(footprintX * MapTerrain::HeightTileWidthInWorldUnits.value / 2); auto halfFootprintZ = SimScalar(footprintZ * MapTerrain::HeightTileHeightInWorldUnits.value / 2); @@ -232,7 +232,7 @@ namespace rwe }); } - bool GameSimulation::isYardmapBlocked(unsigned int x, unsigned int y, const Grid& yardMap, bool open) const + bool GameSimulation::isYardmapBlocked(int x, int y, const Grid& yardMap, bool open) const { return occupiedGrid.any2(x, y, yardMap, [&](const auto& cell, const auto& yardMapCell) { if (isPassable(yardMapCell, open)) @@ -454,7 +454,7 @@ namespace rwe if (weapon.weaponDefinition.weaponTimer) { auto randomDecay = weapon.weaponDefinition.randomDecay.value().value; - std::uniform_int_distribution dist(0, randomDecay); + std::uniform_int_distribution dist(0, randomDecay); auto randomVal = dist(rng); projectile.dieOnFrame = gameTime + *weapon.weaponDefinition.weaponTimer - GameTime(randomDecay / 2) + GameTime(randomVal); } diff --git a/src/rwe/sim/GameSimulation.h b/src/rwe/sim/GameSimulation.h index 8a9ef9469..d4a6ca4a8 100644 --- a/src/rwe/sim/GameSimulation.h +++ b/src/rwe/sim/GameSimulation.h @@ -132,9 +132,9 @@ namespace rwe * could be built at given location on the map -- i.e. it is valid terrain * for the unit and it is not occupied by something else. */ - bool canBeBuiltAt(const MovementClass& mc, unsigned int x, unsigned int y) const; + bool canBeBuiltAt(const MovementClass& mc, int x, int y) const; - DiscreteRect computeFootprintRegion(const SimVector& position, unsigned int footprintX, unsigned int footprintZ) const; + DiscreteRect computeFootprintRegion(const SimVector& position, int footprintX, int footprintZ) const; bool isCollisionAt(const DiscreteRect& rect) const; @@ -142,7 +142,7 @@ namespace rwe bool isCollisionAt(const DiscreteRect& rect, UnitId self) const; - bool isYardmapBlocked(unsigned int x, unsigned int y, const Grid& yardMap, bool open) const; + bool isYardmapBlocked(int x, int y, const Grid& yardMap, bool open) const; bool isAdjacentToObstacle(const DiscreteRect& rect) const; diff --git a/src/rwe/sim/GameTime.h b/src/rwe/sim/GameTime.h index 6de5e4426..d425ca105 100644 --- a/src/rwe/sim/GameTime.h +++ b/src/rwe/sim/GameTime.h @@ -6,7 +6,7 @@ namespace rwe { struct GameTimeTag; - using GameTime = OpaqueUnit; + using GameTime = OpaqueUnit; GameTime deltaSecondsToTicks(float seconds); GameTime deltaSecondsToTicks(SimScalar seconds); diff --git a/src/rwe/sim/MapFeature.h b/src/rwe/sim/MapFeature.h index 6f7e33b62..b22078fb3 100644 --- a/src/rwe/sim/MapFeature.h +++ b/src/rwe/sim/MapFeature.h @@ -32,7 +32,7 @@ namespace rwe SimScalar height; bool isBlocking; bool isIndestructible; - unsigned int metal; + int metal; bool isStanding() const; }; diff --git a/src/rwe/sim/MovementClass.h b/src/rwe/sim/MovementClass.h index c185bd312..f82ee570d 100644 --- a/src/rwe/sim/MovementClass.h +++ b/src/rwe/sim/MovementClass.h @@ -8,12 +8,12 @@ namespace rwe struct MovementClass { std::string name; - unsigned int footprintX; - unsigned int footprintZ; - unsigned int minWaterDepth; - unsigned int maxWaterDepth; - unsigned int maxSlope; - unsigned int maxWaterSlope; + int footprintX; + int footprintZ; + int minWaterDepth; + int maxWaterDepth; + int maxSlope; + int maxWaterSlope; }; MovementClass parseMovementClass(const TdfBlock& block); diff --git a/src/rwe/sim/MovementClassId.h b/src/rwe/sim/MovementClassId.h index b0ead799a..571aee0e0 100644 --- a/src/rwe/sim/MovementClassId.h +++ b/src/rwe/sim/MovementClassId.h @@ -5,5 +5,5 @@ namespace rwe { struct MovementClassIdTag; - using MovementClassId = OpaqueId; + using MovementClassId = OpaqueId; } diff --git a/src/rwe/sim/PlayerId.h b/src/rwe/sim/PlayerId.h index 44f7b28d8..77cf96fec 100644 --- a/src/rwe/sim/PlayerId.h +++ b/src/rwe/sim/PlayerId.h @@ -5,5 +5,5 @@ namespace rwe { struct PlayerIdTag; - using PlayerId = OpaqueId; + using PlayerId = OpaqueId; } diff --git a/src/rwe/sim/Projectile.cpp b/src/rwe/sim/Projectile.cpp index d485b064f..2f27eb8e9 100644 --- a/src/rwe/sim/Projectile.cpp +++ b/src/rwe/sim/Projectile.cpp @@ -28,7 +28,7 @@ namespace rwe } } - unsigned int Projectile::getDamage(const std::string& unitType) const + int Projectile::getDamage(const std::string& unitType) const { auto it = damage.find(unitType); if (it != damage.end()) diff --git a/src/rwe/sim/Projectile.h b/src/rwe/sim/Projectile.h index 4efb98ab9..0015de840 100644 --- a/src/rwe/sim/Projectile.h +++ b/src/rwe/sim/Projectile.h @@ -42,7 +42,7 @@ namespace rwe /** The last time the projectile emitted smoke. */ GameTime lastSmoke; - std::unordered_map damage; + std::unordered_map damage; std::optional dieOnFrame; @@ -59,6 +59,6 @@ namespace rwe SimVector getPreviousBackPosition(SimScalar duration) const; - unsigned int getDamage(const std::string& unitType) const; + int getDamage(const std::string& unitType) const; }; } diff --git a/src/rwe/sim/ProjectileId.h b/src/rwe/sim/ProjectileId.h index 7251f7ee7..f33b9ca36 100644 --- a/src/rwe/sim/ProjectileId.h +++ b/src/rwe/sim/ProjectileId.h @@ -5,5 +5,5 @@ namespace rwe { struct ProjectileIdTag; - using ProjectileId = OpaqueId; + using ProjectileId = OpaqueId; } diff --git a/src/rwe/sim/Unit.cpp b/src/rwe/sim/Unit.cpp index 06a750049..f692f8331 100644 --- a/src/rwe/sim/Unit.cpp +++ b/src/rwe/sim/Unit.cpp @@ -80,9 +80,9 @@ namespace rwe return buildTimeCompleted < buildTime; } - unsigned int Unit::getBuildPercentLeft() const + int Unit::getBuildPercentLeft() const { - return 100u - ((buildTimeCompleted * 100u) / buildTime); + return 100 - ((buildTimeCompleted * 100) / buildTime); } float Unit::getPreciseCompletePercent() const @@ -90,7 +90,7 @@ namespace rwe return static_cast(buildTimeCompleted) / static_cast(buildTime); } - Unit::BuildCostInfo Unit::getBuildCostInfo(unsigned int buildTimeContribution) + Unit::BuildCostInfo Unit::getBuildCostInfo(int buildTimeContribution) { auto remainingBuildTime = buildTime - buildTimeCompleted; if (buildTimeContribution > remainingBuildTime) @@ -112,7 +112,7 @@ namespace rwe return BuildCostInfo{buildTimeContribution, deltaEnergy, deltaMetal}; } - bool Unit::addBuildProgress(unsigned int buildTimeContribution) + bool Unit::addBuildProgress(int buildTimeContribution) { auto remainingBuildTime = buildTime - buildTimeCompleted; if (buildTimeContribution > remainingBuildTime) @@ -440,7 +440,7 @@ namespace rwe bool operator()(const UnitWeaponStateAttacking& state) const { return std::visit(TargetIsPositionVisitor(position), state.target); } }; - void Unit::setWeaponTarget(unsigned int weaponIndex, UnitId target) + void Unit::setWeaponTarget(int weaponIndex, UnitId target) { auto& weapon = weapons[weaponIndex]; if (!weapon) @@ -455,7 +455,7 @@ namespace rwe } } - void Unit::setWeaponTarget(unsigned int weaponIndex, const SimVector& target) + void Unit::setWeaponTarget(int weaponIndex, const SimVector& target) { auto& weapon = weapons[weaponIndex]; if (!weapon) @@ -470,7 +470,7 @@ namespace rwe } } - void Unit::clearWeaponTarget(unsigned int weaponIndex) + void Unit::clearWeaponTarget(int weaponIndex) { auto& weapon = weapons[weaponIndex]; if (!weapon) @@ -479,14 +479,14 @@ namespace rwe } weapon->state = UnitWeaponStateIdle(); - cobEnvironment->createThread("TargetCleared", {static_cast(weaponIndex)}); + cobEnvironment->createThread("TargetCleared", {weaponIndex}); } void Unit::clearWeaponTargets() { for (Index i = 0; i < getSize(weapons); ++i) { - clearWeaponTarget(i); + clearWeaponTarget(static_cast(i)); } } diff --git a/src/rwe/sim/Unit.h b/src/rwe/sim/Unit.h index 07a2eec99..218f88f1c 100644 --- a/src/rwe/sim/Unit.h +++ b/src/rwe/sim/Unit.h @@ -190,18 +190,18 @@ namespace rwe std::optional movementClass; - unsigned int footprintX; - unsigned int footprintZ; - unsigned int maxSlope; - unsigned int maxWaterSlope; - unsigned int minWaterDepth; - unsigned int maxWaterDepth; + int footprintX; + int footprintZ; + int maxSlope; + int maxWaterSlope; + int minWaterDepth; + int maxWaterDepth; /** If true, the unit is considered a commander for victory conditions. */ bool commander; - unsigned int hitPoints{0}; - unsigned int maxHitPoints; + int hitPoints{0}; + int maxHitPoints; LifeState lifeState{LifeState::Alive}; @@ -238,13 +238,13 @@ namespace rwe bool builder; - unsigned int buildTime; + int buildTime; Energy energyCost; Metal metalCost; - unsigned int buildTimeCompleted{0}; + int buildTimeCompleted{0}; - unsigned int workerTimePerTick; + int workerTimePerTick; SimScalar buildDistance; @@ -291,20 +291,20 @@ namespace rwe bool isBeingBuilt() const; - unsigned int getBuildPercentLeft() const; + int getBuildPercentLeft() const; float getPreciseCompletePercent() const; struct BuildCostInfo { - unsigned int workerTime; + int workerTime; Energy energyCost; Metal metalCost; }; - BuildCostInfo getBuildCostInfo(unsigned int buildTimeContribution); + BuildCostInfo getBuildCostInfo(int buildTimeContribution); - bool addBuildProgress(unsigned int buildTimeContribution); + bool addBuildProgress(int buildTimeContribution); bool isCommander() const; @@ -338,9 +338,9 @@ namespace rwe void addOrder(const UnitOrder& order); - void setWeaponTarget(unsigned int weaponIndex, UnitId target); - void setWeaponTarget(unsigned int weaponIndex, const SimVector& target); - void clearWeaponTarget(unsigned int weaponIndex); + void setWeaponTarget(int weaponIndex, UnitId target); + void setWeaponTarget(int weaponIndex, const SimVector& target); + void clearWeaponTarget(int weaponIndex); void clearWeaponTargets(); Matrix4x getTransform() const; diff --git a/src/rwe/sim/UnitBehaviorService.cpp b/src/rwe/sim/UnitBehaviorService.cpp index 17d37a94e..5aa4dad19 100644 --- a/src/rwe/sim/UnitBehaviorService.cpp +++ b/src/rwe/sim/UnitBehaviorService.cpp @@ -118,7 +118,7 @@ namespace rwe for (Index i = 0; i < getSize(unit.weapons); ++i) { - updateWeapon(unitId, i); + updateWeapon(unitId, static_cast(i)); } } @@ -255,7 +255,7 @@ namespace rwe return false; } - void UnitBehaviorService::updateWeapon(UnitId id, unsigned int weaponIndex) + void UnitBehaviorService::updateWeapon(UnitId id, int weaponIndex) { auto& unit = scene->getSimulation().getUnit(id); auto& weapon = unit.weapons[weaponIndex]; @@ -410,7 +410,7 @@ namespace rwe return rotateDirectionXZ(direction, angle); } - void UnitBehaviorService::tryFireWeapon(UnitId id, unsigned int weaponIndex) + void UnitBehaviorService::tryFireWeapon(UnitId id, int weaponIndex) { auto& unit = scene->getSimulation().getUnit(id); auto& weapon = unit.weapons[weaponIndex]; @@ -653,7 +653,7 @@ namespace rwe return true; } - std::string UnitBehaviorService::getAimScriptName(unsigned int weaponIndex) const + std::string UnitBehaviorService::getAimScriptName(int weaponIndex) const { switch (weaponIndex) { @@ -668,7 +668,7 @@ namespace rwe } } - std::string UnitBehaviorService::getAimFromScriptName(unsigned int weaponIndex) const + std::string UnitBehaviorService::getAimFromScriptName(int weaponIndex) const { switch (weaponIndex) { @@ -683,7 +683,7 @@ namespace rwe } } - std::string UnitBehaviorService::getFireScriptName(unsigned int weaponIndex) const + std::string UnitBehaviorService::getFireScriptName(int weaponIndex) const { switch (weaponIndex) { @@ -698,7 +698,7 @@ namespace rwe } } - std::string UnitBehaviorService::getQueryScriptName(unsigned int weaponIndex) const + std::string UnitBehaviorService::getQueryScriptName(int weaponIndex) const { switch (weaponIndex) { @@ -732,13 +732,13 @@ namespace rwe return result; } - SimVector UnitBehaviorService::getAimingPoint(UnitId id, unsigned int weaponIndex) + SimVector UnitBehaviorService::getAimingPoint(UnitId id, int weaponIndex) { const auto& unit = scene->getSimulation().getUnit(id); return unit.getTransform() * getLocalAimingPoint(id, weaponIndex); } - SimVector UnitBehaviorService::getLocalAimingPoint(UnitId id, unsigned int weaponIndex) + SimVector UnitBehaviorService::getLocalAimingPoint(UnitId id, int weaponIndex) { auto scriptName = getAimFromScriptName(weaponIndex); auto pieceId = runCobQuery(id, scriptName); @@ -750,13 +750,13 @@ namespace rwe return getPieceLocalPosition(id, *pieceId); } - SimVector UnitBehaviorService::getFiringPoint(UnitId id, unsigned int weaponIndex) + SimVector UnitBehaviorService::getFiringPoint(UnitId id, int weaponIndex) { const auto& unit = scene->getSimulation().getUnit(id); return unit.getTransform() * getLocalFiringPoint(id, weaponIndex); } - SimVector UnitBehaviorService::getLocalFiringPoint(UnitId id, unsigned int weaponIndex) + SimVector UnitBehaviorService::getLocalFiringPoint(UnitId id, int weaponIndex) { auto scriptName = getQueryScriptName(weaponIndex); @@ -860,7 +860,7 @@ namespace rwe else { // we're in range, aim weapons - for (unsigned int i = 0; i < 2; ++i) + for (int i = 0; i < 2; ++i) { match( target, @@ -1099,7 +1099,7 @@ namespace rwe return getPiecePosition(id, *pieceId); } - SimVector UnitBehaviorService::getPieceLocalPosition(UnitId id, unsigned int pieceId) + SimVector UnitBehaviorService::getPieceLocalPosition(UnitId id, int pieceId) { auto& unit = scene->getSimulation().getUnit(id); @@ -1109,7 +1109,7 @@ namespace rwe return pieceTransform * SimVector(0_ss, 0_ss, 0_ss); } - SimVector UnitBehaviorService::getPiecePosition(UnitId id, unsigned int pieceId) + SimVector UnitBehaviorService::getPiecePosition(UnitId id, int pieceId) { auto& unit = scene->getSimulation().getUnit(id); @@ -1121,7 +1121,7 @@ namespace rwe return atan2(lhs.det(rhs), lhs.dot(rhs)); } - SimAngle UnitBehaviorService::getPieceXZRotation(UnitId id, unsigned int pieceId) + SimAngle UnitBehaviorService::getPieceXZRotation(UnitId id, int pieceId) { auto& unit = scene->getSimulation().getUnit(id); diff --git a/src/rwe/sim/UnitBehaviorService.h b/src/rwe/sim/UnitBehaviorService.h index e0e84b478..dd961a937 100644 --- a/src/rwe/sim/UnitBehaviorService.h +++ b/src/rwe/sim/UnitBehaviorService.h @@ -67,11 +67,11 @@ namespace rwe bool followPath(Unit& unit, PathFollowingInfo& path); - void updateWeapon(UnitId id, unsigned int weaponIndex); + void updateWeapon(UnitId id, int weaponIndex); SimVector changeDirectionByRandomAngle(const SimVector& direction, SimAngle maxAngle); - void tryFireWeapon(UnitId id, unsigned int weaponIndex); + void tryFireWeapon(UnitId id, int weaponIndex); void applyUnitSteering(UnitId id); void updateUnitRotation(UnitId id); @@ -81,25 +81,25 @@ namespace rwe bool tryApplyMovementToPosition(UnitId id, const SimVector& newPosition); - std::string getAimScriptName(unsigned int weaponIndex) const; - std::string getAimFromScriptName(unsigned int weaponIndex) const; - std::string getFireScriptName(unsigned int weaponIndex) const; - std::string getQueryScriptName(unsigned int weaponIndex) const; + std::string getAimScriptName(int weaponIndex) const; + std::string getAimFromScriptName(int weaponIndex) const; + std::string getFireScriptName(int weaponIndex) const; + std::string getQueryScriptName(int weaponIndex) const; std::optional runCobQuery(UnitId id, const std::string& name); - SimVector getAimingPoint(UnitId id, unsigned int weaponIndex); - SimVector getLocalAimingPoint(UnitId id, unsigned int weaponIndex); + SimVector getAimingPoint(UnitId id, int weaponIndex); + SimVector getLocalAimingPoint(UnitId id, int weaponIndex); - SimVector getFiringPoint(UnitId id, unsigned int weaponIndex); - SimVector getLocalFiringPoint(UnitId id, unsigned int weaponIndex); + SimVector getFiringPoint(UnitId id, int weaponIndex); + SimVector getLocalFiringPoint(UnitId id, int weaponIndex); SimVector getNanoPoint(UnitId id); - SimVector getPieceLocalPosition(UnitId id, unsigned int pieceId); - SimVector getPiecePosition(UnitId id, unsigned int pieceId); + SimVector getPieceLocalPosition(UnitId id, int pieceId); + SimVector getPiecePosition(UnitId id, int pieceId); - SimAngle getPieceXZRotation(UnitId id, unsigned int pieceId); + SimAngle getPieceXZRotation(UnitId id, int pieceId); struct BuildPieceInfo { diff --git a/src/rwe/sim/UnitId.h b/src/rwe/sim/UnitId.h index fea86a5ea..497a23a09 100644 --- a/src/rwe/sim/UnitId.h +++ b/src/rwe/sim/UnitId.h @@ -5,5 +5,5 @@ namespace rwe { struct UnitIdTag; - using UnitId = OpaqueId; + using UnitId = OpaqueId; } diff --git a/src/rwe/sim/WeaponDefinition.h b/src/rwe/sim/WeaponDefinition.h index 4284f309a..d7c7dd803 100644 --- a/src/rwe/sim/WeaponDefinition.h +++ b/src/rwe/sim/WeaponDefinition.h @@ -42,7 +42,7 @@ namespace rwe /** If true, the weapon only fires on command and does not auto-target. */ bool commandFire; - std::unordered_map damage; + std::unordered_map damage; SimScalar damageRadius; diff --git a/src/rwe/sim/movement.cpp b/src/rwe/sim/movement.cpp index 24c911c93..433308614 100644 --- a/src/rwe/sim/movement.cpp +++ b/src/rwe/sim/movement.cpp @@ -3,14 +3,14 @@ namespace rwe { bool - isGridPointWalkable(const MapTerrain& terrain, const MovementClass& movementClass, unsigned int x, unsigned int y) + isGridPointWalkable(const MapTerrain& terrain, const MovementClass& movementClass, int x, int y) { - if (isMaxSlopeGreaterThan(terrain.getHeightMap(), simScalarToUInt(terrain.getSeaLevel()), x, y, movementClass.footprintX, movementClass.footprintZ, movementClass.maxSlope, movementClass.maxWaterSlope)) + if (isMaxSlopeGreaterThan(terrain.getHeightMap(), roundToInt(terrain.getSeaLevel()), x, y, movementClass.footprintX, movementClass.footprintZ, movementClass.maxSlope, movementClass.maxWaterSlope)) { return false; } - if (!isWaterDepthWithinBounds(terrain.getHeightMap(), simScalarToUInt(terrain.getSeaLevel()), x, y, movementClass.footprintX, movementClass.footprintZ, movementClass.minWaterDepth, movementClass.maxWaterDepth)) + if (!isWaterDepthWithinBounds(terrain.getHeightMap(), roundToInt(terrain.getSeaLevel()), x, y, movementClass.footprintX, movementClass.footprintZ, movementClass.minWaterDepth, movementClass.maxWaterDepth)) { return false; } @@ -18,14 +18,14 @@ namespace rwe return true; } - bool isMaxSlopeGreaterThan(const Grid& heights, unsigned int waterLevel, unsigned int x, unsigned int y, unsigned int width, unsigned int height, unsigned int maxSlope, unsigned int maxWaterSlope) + bool isMaxSlopeGreaterThan(const Grid& heights, int waterLevel, int x, int y, int width, int height, int maxSlope, int maxWaterSlope) { auto isUnderWater = isAreaUnderWater(heights, waterLevel, x, y, width, height); auto effectiveMaxSlope = isUnderWater ? maxWaterSlope : maxSlope; - for (unsigned int dy = 0; dy < height; ++dy) + for (int dy = 0; dy < height; ++dy) { - for (unsigned int dx = 0; dx < width; ++dx) + for (int dx = 0; dx < width; ++dx) { if (getSlope(heights, x + dx, y + dy) > effectiveMaxSlope) { @@ -38,11 +38,11 @@ namespace rwe } bool - isWaterDepthWithinBounds(const Grid& heights, unsigned int waterLevel, unsigned int x, unsigned int y, unsigned int width, unsigned int height, unsigned int minWaterDepth, unsigned int maxWaterDepth) + isWaterDepthWithinBounds(const Grid& heights, int waterLevel, int x, int y, int width, int height, int minWaterDepth, int maxWaterDepth) { - for (unsigned int dy = 0; dy < height; ++dy) + for (int dy = 0; dy < height; ++dy) { - for (unsigned int dx = 0; dx < width; ++dx) + for (int dx = 0; dx < width; ++dx) { auto cellWaterDepth = getWaterDepth(heights, waterLevel, x + dx, y + dy); if (cellWaterDepth < minWaterDepth) @@ -60,21 +60,20 @@ namespace rwe return true; } - unsigned int - getWaterDepth(const Grid& heights, unsigned int waterLevel, unsigned int x, unsigned int y) + int getWaterDepth(const Grid& heights, int waterLevel, int x, int y) { auto height = heights.get(x, y); return height < waterLevel ? waterLevel - height : 0; } - unsigned int getSlope(const Grid& heights, unsigned int x, unsigned int y) + int getSlope(const Grid& heights, int x, int y) { - unsigned int minHeight = 255; - unsigned int maxHeight = 0; + int minHeight = 255; + int maxHeight = 0; - for (unsigned int dy = 0; dy < 2; ++dy) + for (int dy = 0; dy < 2; ++dy) { - for (unsigned int dx = 0; dx < 2; ++dx) + for (int dx = 0; dx < 2; ++dx) { auto cellHeight = heights.get(x + dx, y + dy); @@ -96,15 +95,15 @@ namespace rwe bool isAreaUnderWater( const Grid& heights, - unsigned int waterLevel, - unsigned int x, - unsigned int y, - unsigned int width, - unsigned int height) + int waterLevel, + int x, + int y, + int width, + int height) { - for (unsigned int dy = 0; dy < height + 1; ++dy) + for (int dy = 0; dy < height + 1; ++dy) { - for (unsigned int dx = 0; dx < width + 1; ++dx) + for (int dx = 0; dx < width + 1; ++dx) { auto cellHeight = heights.get(x + dx, y + dy); if (cellHeight < waterLevel) diff --git a/src/rwe/sim/movement.h b/src/rwe/sim/movement.h index e518414d5..87c1e23d1 100644 --- a/src/rwe/sim/movement.h +++ b/src/rwe/sim/movement.h @@ -9,15 +9,15 @@ namespace rwe { - bool isGridPointWalkable(const MapTerrain& terrain, const MovementClass& movementClass, unsigned int x, unsigned int y); + bool isGridPointWalkable(const MapTerrain& terrain, const MovementClass& movementClass, int x, int y); - bool isMaxSlopeGreaterThan(const Grid& heights, unsigned int waterLevel, unsigned int x, unsigned int y, unsigned int width, unsigned int height, unsigned int maxSlope, unsigned int maxWaterSlope); + bool isMaxSlopeGreaterThan(const Grid& heights, int waterLevel, int x, int y, int width, int height, int maxSlope, int maxWaterSlope); - bool isWaterDepthWithinBounds(const Grid& heights, unsigned int waterLevel, unsigned int x, unsigned int y, unsigned int width, unsigned int height, unsigned int minWaterDepth, unsigned int maxWaterDepth); + bool isWaterDepthWithinBounds(const Grid& heights, int waterLevel, int x, int y, int width, int height, int minWaterDepth, int maxWaterDepth); - unsigned int getWaterDepth(const Grid& heights, unsigned int waterLevel, unsigned int x, unsigned int y); + int getWaterDepth(const Grid& heights, int waterLevel, int x, int y); - unsigned int getSlope(const Grid& heights, unsigned int x, unsigned int y); + int getSlope(const Grid& heights, int x, int y); - bool isAreaUnderWater(const Grid& heights, unsigned int waterLevel, unsigned int x, unsigned int y, unsigned int width, unsigned int height); + bool isAreaUnderWater(const Grid& heights, int waterLevel, int x, int y, int width, int height); } diff --git a/src/rwe/ui/UiComponent.cpp b/src/rwe/ui/UiComponent.cpp index 53665cbbf..7c154a2ed 100644 --- a/src/rwe/ui/UiComponent.cpp +++ b/src/rwe/ui/UiComponent.cpp @@ -46,12 +46,12 @@ namespace rwe name = std::move(newName); } - unsigned int UiComponent::getGroup() const + int UiComponent::getGroup() const { return group; } - void UiComponent::setGroup(unsigned int newGroup) + void UiComponent::setGroup(int newGroup) { group = newGroup; } diff --git a/src/rwe/ui/UiComponent.h b/src/rwe/ui/UiComponent.h index 33a436ea0..082c7daa4 100644 --- a/src/rwe/ui/UiComponent.h +++ b/src/rwe/ui/UiComponent.h @@ -16,11 +16,11 @@ namespace rwe int posX; int posY; - unsigned int sizeX; - unsigned int sizeY; + int sizeX; + int sizeY; std::string name; - unsigned int group{0}; + int group{0}; Subject messagesSubject; @@ -31,7 +31,7 @@ namespace rwe std::vector> subscriptions; public: - UiComponent(int posX, int posY, unsigned int sizeX, unsigned int sizeY) + UiComponent(int posX, int posY, int sizeX, int sizeY) : posX(posX), posY(posY), sizeX(sizeX), sizeY(sizeY) { } @@ -43,9 +43,9 @@ namespace rwe virtual ~UiComponent(); - unsigned int getWidth() { return sizeX; } + int getWidth() { return sizeX; } - unsigned int getHeight() { return sizeY; } + int getHeight() { return sizeY; } int getX() { return posX; } int getY() { return posY; } @@ -91,8 +91,8 @@ namespace rwe void setName(const std::string& newName); void setName(std::string&& newName); - unsigned int getGroup() const; - void setGroup(unsigned int newGroup); + int getGroup() const; + void setGroup(int newGroup); Observable& messages(); const Observable& messages() const; diff --git a/src/rwe/ui/UiFactory.cpp b/src/rwe/ui/UiFactory.cpp index 461e825b7..25eca96de 100644 --- a/src/rwe/ui/UiFactory.cpp +++ b/src/rwe/ui/UiFactory.cpp @@ -238,7 +238,7 @@ namespace rwe } std::unique_ptr - UiFactory::createStagedButton(int x, int y, int width, int height, const std::string& guiName, const std::string& name, const std::vector& labels, unsigned int stages) + UiFactory::createStagedButton(int x, int y, int width, int height, const std::string& guiName, const std::string& name, const std::vector& labels, int stages) { auto sprites = getStagedButtonGraphics(guiName, name, stages); @@ -389,7 +389,7 @@ namespace rwe return button; } - std::shared_ptr UiFactory::getDefaultStagedButtonGraphics(const std::string& guiName, unsigned int stages) + std::shared_ptr UiFactory::getDefaultStagedButtonGraphics(const std::string& guiName, int stages) { assert(stages >= 1 && stages <= 4); std::string entryName("stagebuttn"); @@ -404,7 +404,7 @@ namespace rwe // default behaviour const auto& sprite = textureService->getDefaultSprite(); auto series = std::make_shared(); - for (unsigned int i = 0; i < stages; ++i) + for (int i = 0; i < stages; ++i) { series->sprites.push_back(sprite); } @@ -567,7 +567,7 @@ namespace rwe auto stageCount = spriteCount > 3 ? spriteCount - 2 : 1; std::vector> normalSprites; - for (unsigned int i = 0; i < stageCount; ++i) + for (int i = 0; i < stageCount; ++i) { normalSprites.push_back(sprites[i]); } @@ -602,7 +602,7 @@ namespace rwe return UiFactory::ButtonSprites{std::vector>{normalSprite}, pressedSprite, disabledSprite}; } - UiFactory::ButtonSprites UiFactory::getStagedButtonGraphics(const std::string& guiName, const std::string& name, unsigned int stages) + UiFactory::ButtonSprites UiFactory::getStagedButtonGraphics(const std::string& guiName, const std::string& name, int stages) { auto graphics = textureService->getGuiTexture(guiName, name); if (!graphics) @@ -613,17 +613,17 @@ namespace rwe auto defaultSprite = textureService->getDefaultSprite(); const auto& sprites = (*graphics)->sprites; - auto spriteCount = sprites.size(); + int spriteCount = static_cast(sprites.size()); auto stagesPresentCount = spriteCount > 2 ? spriteCount - 2 : 0; - auto stagesToCopyCount = std::min(stages, stagesPresentCount); + int stagesToCopyCount = std::min(stages, stagesPresentCount);//TODO (kwh) - do std::vector> normalSprites; - for (unsigned int i = 0; i < stagesToCopyCount; ++i) + for (int i = 0; i < stagesToCopyCount; ++i) { normalSprites.push_back(sprites[i]); } - for (unsigned int i = stagesToCopyCount; i < stages; ++i) + for (int i = stagesToCopyCount; i < stages; ++i) { normalSprites.push_back(defaultSprite); } diff --git a/src/rwe/ui/UiFactory.h b/src/rwe/ui/UiFactory.h index 26a3d3cda..e0ed54dd8 100644 --- a/src/rwe/ui/UiFactory.h +++ b/src/rwe/ui/UiFactory.h @@ -51,7 +51,7 @@ namespace rwe std::unique_ptr createBasicButton(int x, int y, int width, int height, const std::string& guiName, const std::string& name, const std::string& label); - std::unique_ptr createStagedButton(int x, int y, int width, int height, const std::string& guiName, const std::string& name, const std::vector& labels, unsigned int stages); + std::unique_ptr createStagedButton(int x, int y, int width, int height, const std::string& guiName, const std::string& name, const std::vector& labels, int stages); private: std::unique_ptr componentFromGuiEntry(const std::string& guiName, const GuiEntry& entry); @@ -74,7 +74,7 @@ namespace rwe std::optional deduceButtonSound(const std::string& guiName, const std::string& name, int width, int height); - std::shared_ptr getDefaultStagedButtonGraphics(const std::string& guiName, unsigned int stages); + std::shared_ptr getDefaultStagedButtonGraphics(const std::string& guiName, int stages); std::unique_ptr surfaceFromGuiEntry(const std::string& guiName, const GuiEntry& entry); @@ -82,6 +82,6 @@ namespace rwe ButtonSprites getBasicButtonGraphics(const std::string& guiName, const std::string& name, int width, int height); - ButtonSprites getStagedButtonGraphics(const std::string& guiName, const std::string& name, unsigned int stages); + ButtonSprites getStagedButtonGraphics(const std::string& guiName, const std::string& name, int stages); }; } diff --git a/src/rwe/ui/UiLabel.cpp b/src/rwe/ui/UiLabel.cpp index 57bcbd00f..5bd0deb1f 100644 --- a/src/rwe/ui/UiLabel.cpp +++ b/src/rwe/ui/UiLabel.cpp @@ -16,7 +16,7 @@ namespace rwe } } - UiLabel::UiLabel(int posX, int posY, unsigned int sizeX, unsigned int sizeY, const std::string& text, const std::shared_ptr& font) : UiComponent(posX, posY, sizeX, sizeY), text(text), font(font) + UiLabel::UiLabel(int posX, int posY, int sizeX, int sizeY, const std::string& text, const std::shared_ptr& font) : UiComponent(posX, posY, sizeX, sizeY), text(text), font(font) { } diff --git a/src/rwe/ui/UiLabel.h b/src/rwe/ui/UiLabel.h index d06567d8e..38f17cdca 100644 --- a/src/rwe/ui/UiLabel.h +++ b/src/rwe/ui/UiLabel.h @@ -19,7 +19,7 @@ namespace rwe Alignment alignment{Alignment::Left}; public: - UiLabel(int posX, int posY, unsigned int sizeX, unsigned int sizeY, const std::string& text, const std::shared_ptr& font); + UiLabel(int posX, int posY, int sizeX, int sizeY, const std::string& text, const std::shared_ptr& font); void render(UiRenderService& context) const override; diff --git a/src/rwe/ui/UiLightBar.cpp b/src/rwe/ui/UiLightBar.cpp index 1a2cadc40..a8f535997 100644 --- a/src/rwe/ui/UiLightBar.cpp +++ b/src/rwe/ui/UiLightBar.cpp @@ -3,7 +3,7 @@ namespace rwe { - UiLightBar::UiLightBar(int posX, int posY, unsigned int sizeX, unsigned int sizeY, std::shared_ptr lightMask) + UiLightBar::UiLightBar(int posX, int posY, int sizeX, int sizeY, std::shared_ptr lightMask) : UiComponent(posX, posY, sizeX, sizeY), lightMask(std::move(lightMask)) { } diff --git a/src/rwe/ui/UiLightBar.h b/src/rwe/ui/UiLightBar.h index 07d453770..0535a75b8 100644 --- a/src/rwe/ui/UiLightBar.h +++ b/src/rwe/ui/UiLightBar.h @@ -8,14 +8,14 @@ namespace rwe class UiLightBar : public UiComponent { private: - unsigned int numberOfSections{38}; + int numberOfSections{38}; std::shared_ptr lightMask; float percentComplete{0.0f}; public: - UiLightBar(int posX, int posY, unsigned int sizeX, unsigned int sizeY, std::shared_ptr lightMask); + UiLightBar(int posX, int posY, int sizeX, int sizeY, std::shared_ptr lightMask); void render(UiRenderService& context) const override; diff --git a/src/rwe/ui/UiListBox.cpp b/src/rwe/ui/UiListBox.cpp index 47b09b50c..2697badac 100644 --- a/src/rwe/ui/UiListBox.cpp +++ b/src/rwe/ui/UiListBox.cpp @@ -2,7 +2,7 @@ namespace rwe { - UiListBox::UiListBox(int posX, int posY, unsigned int sizeX, unsigned int sizeY, std::shared_ptr font) + UiListBox::UiListBox(int posX, int posY, int sizeX, int sizeY, std::shared_ptr font) : UiComponent(posX, posY, sizeX, sizeY), font(std::move(font)) { scrollPosition().subscribe([this](const auto& /*scrollPos*/) { @@ -17,11 +17,11 @@ namespace rwe void UiListBox::render(UiRenderService& context) const { - auto lines = std::min(numberOfLines(), items.size()); + int lines = std::min(numberOfLines(), items.size()); - for (unsigned int i = 0; i < lines; ++i) + for (int i = 0; i < lines; ++i) { - float y = 12.0f + (i * 12.0f); + int y = 12 + (i * 12); auto itemIndex = scrollPositionSubject.getValue() + i; const auto& selectedIndexValue = selectedIndexSubject.getValue(); @@ -62,7 +62,7 @@ namespace rwe auto it = std::find(items.begin(), items.end(), item); if (it != items.end()) { - auto index = static_cast(it - items.begin()); + auto index = static_cast(it - items.begin()); selectedIndexSubject.next(index); setScrollPositionCentered(index); } @@ -73,12 +73,12 @@ namespace rwe selectedIndexSubject.next(std::nullopt); } - Observable>& UiListBox::selectedIndex() + Observable>& UiListBox::selectedIndex() { return selectedIndexSubject; } - const Observable>& UiListBox::selectedIndex() const + const Observable>& UiListBox::selectedIndex() const { return selectedIndexSubject; } @@ -110,16 +110,16 @@ namespace rwe } } - unsigned int UiListBox::numberOfLines() const + int UiListBox::numberOfLines() const { - auto lines = static_cast((sizeY) / 12.0f); + auto lines = static_cast((sizeY) / 12.0f); // listboxes defined in TA guis tend to be too long, // so shorten our number of lines by 1 to compensate. return lines - 1; } - std::optional UiListBox::pixelToLine(int y) const + std::optional UiListBox::pixelToLine(int y) const { auto floatIndex = (y - posY) / 12.0f; if (floatIndex < 0.0f) @@ -127,7 +127,7 @@ namespace rwe return std::nullopt; } - auto index = static_cast(floatIndex); + auto index = static_cast(floatIndex); if (index >= numberOfLines()) { return std::nullopt; @@ -136,7 +136,7 @@ namespace rwe return index; } - void UiListBox::setScrollPositionCentered(unsigned int newPosition) + void UiListBox::setScrollPositionCentered(int newPosition) { auto halfLines = numberOfLines() / 2; if (newPosition > halfLines) @@ -149,7 +149,7 @@ namespace rwe } } - void UiListBox::setScrollPosition(unsigned int newPosition) + void UiListBox::setScrollPosition(int newPosition) { auto maxScroll = maxScrollPosition(); if (newPosition > maxScroll) @@ -162,13 +162,13 @@ namespace rwe } } - unsigned int UiListBox::maxScrollPosition() const + int UiListBox::maxScrollPosition() const { auto listSize = items.size(); auto displayLines = numberOfLines(); if (listSize > displayLines) { - return static_cast(listSize - displayLines); + return static_cast(listSize - displayLines); } else { @@ -176,12 +176,12 @@ namespace rwe } } - Observable& UiListBox::scrollPosition() + Observable& UiListBox::scrollPosition() { return scrollPositionSubject; } - const Observable& UiListBox::scrollPosition() const + const Observable& UiListBox::scrollPosition() const { return scrollPositionSubject; } diff --git a/src/rwe/ui/UiListBox.h b/src/rwe/ui/UiListBox.h index c0529fe02..b5c8b1ea9 100644 --- a/src/rwe/ui/UiListBox.h +++ b/src/rwe/ui/UiListBox.h @@ -24,7 +24,7 @@ namespace rwe void operator()(const ScrollPositionMessage& msg) const { - auto scrollPos = static_cast(msg.scrollPosition * listBox->maxScrollPosition()); + auto scrollPos = static_cast(msg.scrollPosition * listBox->maxScrollPosition()); listBox->scrollPositionSubject.next(scrollPos); } @@ -50,11 +50,11 @@ namespace rwe std::vector items; Subject itemsChangedSubject; std::shared_ptr font; - BehaviorSubject> selectedIndexSubject; - BehaviorSubject scrollPositionSubject{0}; + BehaviorSubject> selectedIndexSubject; + BehaviorSubject scrollPositionSubject{0}; public: - UiListBox(int posX, int posY, unsigned int sizeX, unsigned int sizeY, std::shared_ptr font); + UiListBox(int posX, int posY, int sizeX, int sizeY, std::shared_ptr font); void appendItem(std::string item); void setSelectedItem(const std::string& item); @@ -69,17 +69,17 @@ namespace rwe void uiMessage(const GroupMessage& message) override; - Observable>& selectedIndex(); + Observable>& selectedIndex(); - const Observable>& selectedIndex() const; + const Observable>& selectedIndex() const; Observable& itemsChanged(); const Observable& itemsChanged() const; - Observable& scrollPosition(); + Observable& scrollPosition(); - const Observable& scrollPosition() const; + const Observable& scrollPosition() const; const std::vector& getItems(); @@ -88,15 +88,15 @@ namespace rwe float getViewportPercent() const; private: - unsigned int numberOfLines() const; + int numberOfLines() const; - std::optional pixelToLine(int y) const; + std::optional pixelToLine(int y) const; - void setScrollPosition(unsigned int newPosition); + void setScrollPosition(int newPosition); - void setScrollPositionCentered(unsigned int newPosition); + void setScrollPositionCentered(int newPosition); - unsigned int maxScrollPosition() const; + int maxScrollPosition() const; void scrollUp(); diff --git a/src/rwe/ui/UiPanel.cpp b/src/rwe/ui/UiPanel.cpp index 0e211068d..3e08e8b25 100644 --- a/src/rwe/ui/UiPanel.cpp +++ b/src/rwe/ui/UiPanel.cpp @@ -3,18 +3,18 @@ namespace rwe { - UiPanel::UiPanel(int posX, int posY, unsigned int sizeX, unsigned int sizeY) + UiPanel::UiPanel(int posX, int posY, int sizeX, int sizeY) : UiComponent(posX, posY, sizeX, sizeY) { } - UiPanel::UiPanel(int posX, int posY, unsigned int sizeX, unsigned int sizeY, std::shared_ptr background) + UiPanel::UiPanel(int posX, int posY, int sizeX, int sizeY, std::shared_ptr background) : UiComponent(posX, posY, sizeX, sizeY), background(std::move(background)) { } - UiPanel::UiPanel(int posX, int posY, unsigned int sizeX, unsigned int sizeY, std::optional> background) + UiPanel::UiPanel(int posX, int posY, int sizeX, int sizeY, std::optional> background) : UiComponent(posX, posY, sizeX, sizeY), background(background) { diff --git a/src/rwe/ui/UiPanel.h b/src/rwe/ui/UiPanel.h index 2d07701ec..845d16988 100644 --- a/src/rwe/ui/UiPanel.h +++ b/src/rwe/ui/UiPanel.h @@ -15,9 +15,9 @@ namespace rwe Subject groupMessagesSubject; public: - UiPanel(int posX, int posY, unsigned int sizeX, unsigned int sizeY); - UiPanel(int posX, int posY, unsigned int sizeX, unsigned int sizeY, std::shared_ptr background); - UiPanel(int posX, int posY, unsigned int sizeX, unsigned int sizeY, std::optional> background); + UiPanel(int posX, int posY, int sizeX, int sizeY); + UiPanel(int posX, int posY, int sizeX, int sizeY, std::shared_ptr background); + UiPanel(int posX, int posY, int sizeX, int sizeY, std::optional> background); UiPanel(const UiPanel&) = delete; UiPanel& operator=(const UiPanel&) = delete; diff --git a/src/rwe/ui/UiScrollBar.cpp b/src/rwe/ui/UiScrollBar.cpp index d5bfcf3d0..bc82566e1 100644 --- a/src/rwe/ui/UiScrollBar.cpp +++ b/src/rwe/ui/UiScrollBar.cpp @@ -19,8 +19,8 @@ namespace rwe UiScrollBar::UiScrollBar( int posX, int posY, - unsigned int sizeX, - unsigned int sizeY, + int sizeX, + int sizeY, std::shared_ptr sprites) : UiComponent(posX, posY, sizeX, sizeY), sprites(std::move(sprites)) diff --git a/src/rwe/ui/UiScrollBar.h b/src/rwe/ui/UiScrollBar.h index 9ed6aa32c..5db84772a 100644 --- a/src/rwe/ui/UiScrollBar.h +++ b/src/rwe/ui/UiScrollBar.h @@ -52,8 +52,8 @@ namespace rwe UiScrollBar( int posX, int posY, - unsigned int sizeX, - unsigned int sizeY, + int sizeX, + int sizeY, std::shared_ptr sprites); void render(UiRenderService& context) const override; diff --git a/src/rwe/ui/UiStagedButton.cpp b/src/rwe/ui/UiStagedButton.cpp index a06434185..c8ceb97eb 100644 --- a/src/rwe/ui/UiStagedButton.cpp +++ b/src/rwe/ui/UiStagedButton.cpp @@ -73,8 +73,8 @@ namespace rwe UiStagedButton::UiStagedButton( int posX, int posY, - unsigned int sizeX, - unsigned int sizeY, + int sizeX, + int sizeY, std::vector stages, std::shared_ptr pressedSprite, std::shared_ptr labelFont) @@ -213,7 +213,7 @@ namespace rwe messagesSubject.next(ActivateMessage{sourceToType(event.source)}); } - void UiStagedButton::setStage(unsigned int newStage) + void UiStagedButton::setStage(int newStage) { if (newStage >= stages.size()) { diff --git a/src/rwe/ui/UiStagedButton.h b/src/rwe/ui/UiStagedButton.h index 5c513ec0c..c540186b9 100644 --- a/src/rwe/ui/UiStagedButton.h +++ b/src/rwe/ui/UiStagedButton.h @@ -59,7 +59,7 @@ namespace rwe BehaviorMode behaviorMode{BehaviorMode::Button}; - unsigned int currentStage{0}; + int currentStage{0}; Subject clickSubject; @@ -67,8 +67,8 @@ namespace rwe UiStagedButton( int posX, int posY, - unsigned int sizeX, - unsigned int sizeY, + int sizeX, + int sizeY, std::vector stages, std::shared_ptr pressedSprite, std::shared_ptr labelFont); @@ -89,7 +89,7 @@ namespace rwe Observable& onClick(); - void setStage(unsigned int newStage); + void setStage(int newStage); bool autoChangeStage{true}; diff --git a/src/rwe/ui/UiSurface.cpp b/src/rwe/ui/UiSurface.cpp index aee27573e..9d8f97750 100644 --- a/src/rwe/ui/UiSurface.cpp +++ b/src/rwe/ui/UiSurface.cpp @@ -2,12 +2,12 @@ namespace rwe { - UiSurface::UiSurface(int posX, int posY, unsigned int sizeX, unsigned int sizeY) + UiSurface::UiSurface(int posX, int posY, int sizeX, int sizeY) : UiComponent(posX, posY, sizeX, sizeY) { } - UiSurface::UiSurface(int posX, int posY, unsigned int sizeX, unsigned int sizeY, std::shared_ptr background) + UiSurface::UiSurface(int posX, int posY, int sizeX, int sizeY, std::shared_ptr background) : UiComponent(posX, posY, sizeX, sizeY), background(std::move(background)) { } diff --git a/src/rwe/ui/UiSurface.h b/src/rwe/ui/UiSurface.h index de4b83c58..081776ff4 100644 --- a/src/rwe/ui/UiSurface.h +++ b/src/rwe/ui/UiSurface.h @@ -12,8 +12,8 @@ namespace rwe std::optional> background; public: - UiSurface(int posX, int posY, unsigned int sizeX, unsigned int sizeY); - UiSurface(int posX, int posY, unsigned int sizeX, unsigned int sizeY, std::shared_ptr background); + UiSurface(int posX, int posY, int sizeX, int sizeY); + UiSurface(int posX, int posY, int sizeX, int sizeY, std::shared_ptr background); void render(UiRenderService& context) const override; diff --git a/src/rwe/util.cpp b/src/rwe/util.cpp index 990420b7d..70736fc6e 100644 --- a/src/rwe/util.cpp +++ b/src/rwe/util.cpp @@ -59,7 +59,7 @@ namespace rwe return RadiansAngle::fromUnwrappedAngle(static_cast(angle.value) * (Pif / 32768.0f)); } - float toleranceToRadians(unsigned int angle) + float toleranceToRadians(int angle) { return static_cast(angle) * (Pif / 32768.0f); } diff --git a/src/rwe/util.h b/src/rwe/util.h index 606093a0b..0dbd3ac27 100644 --- a/src/rwe/util.h +++ b/src/rwe/util.h @@ -24,7 +24,7 @@ namespace rwe RadiansAngle toRadians(CobAngle angle); - float toleranceToRadians(unsigned int angle); + float toleranceToRadians(int angle); CobAngle toCobAngle(RadiansAngle angle); diff --git a/src/texture_test.cpp b/src/texture_test.cpp index 71cf052c6..a6269aa88 100644 --- a/src/texture_test.cpp +++ b/src/texture_test.cpp @@ -16,7 +16,7 @@ namespace rwe { - using FrameId = std::pair; + using FrameId = std::pair; } namespace std @@ -36,10 +36,10 @@ namespace rwe struct FrameInfo { std::string name; - unsigned int frameNumber; + int frameNumber; Grid data; - FrameInfo(const std::string& name, unsigned int frameNumber, unsigned int width, unsigned int height) + FrameInfo(const std::string& name, int frameNumber, int width, int height) : name(name), frameNumber(frameNumber), data(width, height) { } @@ -52,7 +52,7 @@ namespace rwe const std::string* entryName; FrameInfo* frameInfo; GafFrameData currentFrameHeader; - unsigned int frameNumber{0}; + int frameNumber{0}; public: explicit FrameListGafAdapter(std::vector* frames, const std::string* entryName) @@ -69,12 +69,12 @@ namespace rwe void frameLayer(const LayerData& data) override { - for (std::size_t y = 0; y < data.height; ++y) + for (int y = 0; y < data.height; ++y) { - for (std::size_t x = 0; x < data.width; ++x) + for (int x = 0; x < data.width; ++x) { - auto outPosX = static_cast(x) - (data.x - currentFrameHeader.posX); - auto outPosY = static_cast(y) - (data.y - currentFrameHeader.posY); + auto outPosX = x - (data.x - currentFrameHeader.posX); + auto outPosY = y - (data.y - currentFrameHeader.posY); if (outPosX < 0 || outPosX >= currentFrameHeader.width || outPosY < 0 || outPosY >= currentFrameHeader.height) { @@ -163,8 +163,8 @@ namespace rwe void dumpImage(const Grid& g, const std::string& outFile) { - auto width = static_cast(g.getWidth()); - auto height = static_cast(g.getHeight()); + int width = g.getWidth(); + int height = g.getHeight(); png::image image(width, height); for (png::uint_32 y = 0; y < height; ++y) { From f495f8e2b29bc772f1e41ccd83ecd7c98f1b4cf1 Mon Sep 17 00:00:00 2001 From: Kevin Hake Date: Thu, 26 Aug 2021 18:01:41 -0500 Subject: [PATCH 2/3] Review changes refactor 'unsigned int' ==> 'int' --- src/rwe/GameNetworkService.cpp | 2 +- src/rwe/RenderService.cpp | 2 +- src/rwe/cob/CobEnvironment.cpp | 8 ++++---- src/rwe/cob/CobEnvironment.h | 12 ++++++------ src/rwe/cob/CobExecutionContext.cpp | 10 +++++----- src/rwe/cob/CobExecutionContext.h | 6 +++--- src/rwe/cob/CobThread.cpp | 2 +- src/rwe/cob/CobThread.h | 4 ++-- src/rwe/grid/DiscreteRect.h | 1 + src/rwe/grid/Grid.h | 11 ++++++++--- src/rwe/ui/UiFactory.cpp | 4 ++-- src/rwe/ui/UiListBox.cpp | 2 +- 12 files changed, 35 insertions(+), 29 deletions(-) diff --git a/src/rwe/GameNetworkService.cpp b/src/rwe/GameNetworkService.cpp index c9d0de96d..b3a7302a7 100644 --- a/src/rwe/GameNetworkService.cpp +++ b/src/rwe/GameNetworkService.cpp @@ -332,7 +332,7 @@ namespace rwe auto firstRelevantCommandIndex = (endpoint.nextCommandToReceive - firstCommandNumber).value; // if the packet is relevant (contains new information), process it - if (firstRelevantCommandIndex < static_cast(message.command_set_size())) + if (firstRelevantCommandIndex < message.command_set_size()) { endpoint.lastReceiveTime = receiveTime; diff --git a/src/rwe/RenderService.cpp b/src/rwe/RenderService.cpp index 945f29586..4e098ca56 100644 --- a/src/rwe/RenderService.cpp +++ b/src/rwe/RenderService.cpp @@ -408,7 +408,7 @@ namespace rwe auto timeSinceSpawn = currentTime - projectile.createdAt; auto fullLifetime = projectile.dieOnFrame.value() - projectile.createdAt; auto percentComplete = static_cast(timeSinceSpawn.value) / static_cast(fullLifetime.value); - int frameIndex = static_cast(percentComplete * spriteSeries->sprites.size()); + auto frameIndex = static_cast(percentComplete * spriteSeries->sprites.size()); assert(frameIndex < spriteSeries->sprites.size()); const auto& sprite = *spriteSeries->sprites[frameIndex]; auto modelMatrix = Matrix4f::translation(snappedPosition) * conversionMatrix * sprite.getTransform(); diff --git a/src/rwe/cob/CobEnvironment.cpp b/src/rwe/cob/CobEnvironment.cpp index 262f452bc..6930dc067 100644 --- a/src/rwe/cob/CobEnvironment.cpp +++ b/src/rwe/cob/CobEnvironment.cpp @@ -7,12 +7,12 @@ namespace rwe { } - int CobEnvironment::getStatic(int id) + int CobEnvironment::getStatic(uint32_t id) { return _statics.at(id); } - void CobEnvironment::setStatic(int id, int value) + void CobEnvironment::setStatic(uint32_t id, int value) { _statics.at(id) = value; } @@ -43,7 +43,7 @@ namespace rwe return thread; } - const CobThread* CobEnvironment::createThread(int functionId, const std::vector& params, int signalMask) + const CobThread* CobEnvironment::createThread(int functionId, const std::vector& params, unsigned int signalMask) { const auto& functionInfo = _script->functions.at(functionId); auto& thread = threads.emplace_back(std::make_unique(functionInfo.name, signalMask)); @@ -84,7 +84,7 @@ namespace rwe } } - void CobEnvironment::sendSignal(int signal) + void CobEnvironment::sendSignal(uint32_t signal) { for (auto it = threads.begin(); it != threads.end();) { diff --git a/src/rwe/cob/CobEnvironment.h b/src/rwe/cob/CobEnvironment.h index 0d61172af..fbebf82c5 100644 --- a/src/rwe/cob/CobEnvironment.h +++ b/src/rwe/cob/CobEnvironment.h @@ -69,7 +69,7 @@ namespace rwe */ struct SignalStatus { - int signal; + uint32_t signal; }; struct PieceCommandStatus @@ -111,7 +111,7 @@ namespace rwe }; using CommandType = std::variant; - int piece; + uint32_t piece; CommandType command; }; @@ -273,9 +273,9 @@ namespace rwe CobEnvironment& operator=(CobEnvironment&& other) = delete; public: - int getStatic(int id); + int getStatic(uint32_t id); - void setStatic(int id, int value); + void setStatic(uint32_t id, int value); const CobScript* script(); @@ -283,7 +283,7 @@ namespace rwe CobThread createNonScheduledThread(int functionId, const std::vector& params); - const CobThread* createThread(int functionId, const std::vector& params, int signalMask); + const CobThread* createThread(int functionId, const std::vector& params, uint32_t signalMask); const CobThread* createThread(int functionId, const std::vector& params); @@ -298,7 +298,7 @@ namespace rwe * If the signal is non-zero after being ANDed * with the thread's signal mask, the thread is killed. */ - void sendSignal(int signal); + void sendSignal(uint32_t signal); /** * Attempts to collect the return value from a thread. diff --git a/src/rwe/cob/CobExecutionContext.cpp b/src/rwe/cob/CobExecutionContext.cpp index ac5c500b9..ea1b7e156 100644 --- a/src/rwe/cob/CobExecutionContext.cpp +++ b/src/rwe/cob/CobExecutionContext.cpp @@ -714,14 +714,14 @@ namespace rwe return CobAngularSpeed(pop()); } - int CobExecutionContext::popSignal() + uint32_t CobExecutionContext::popSignal() { - return pop(); + return static_cast(pop()); } - int CobExecutionContext::popSignalMask() + uint32_t CobExecutionContext::popSignalMask() { - return pop(); + return static_cast(pop()); } CobValueId CobExecutionContext::popValueId() @@ -750,7 +750,7 @@ namespace rwe } } - int CobExecutionContext::nextInstruction() + uint32_t CobExecutionContext::nextInstruction() { return env->script()->instructions.at(thread->callStack.top().instructionIndex++); } diff --git a/src/rwe/cob/CobExecutionContext.h b/src/rwe/cob/CobExecutionContext.h index 3c92bd5a1..28fd7660f 100644 --- a/src/rwe/cob/CobExecutionContext.h +++ b/src/rwe/cob/CobExecutionContext.h @@ -117,12 +117,12 @@ namespace rwe CobSpeed popSpeed(); CobAngle popAngle(); CobAngularSpeed popAngularSpeed(); - int popSignal(); - int popSignalMask(); + uint32_t popSignal(); + uint32_t popSignalMask(); CobValueId popValueId(); void push(int val); - int nextInstruction(); + uint32_t nextInstruction(); CobAxis nextInstructionAsAxis(); }; } diff --git a/src/rwe/cob/CobThread.cpp b/src/rwe/cob/CobThread.cpp index b1e3b57c8..bc3041b37 100644 --- a/src/rwe/cob/CobThread.cpp +++ b/src/rwe/cob/CobThread.cpp @@ -2,7 +2,7 @@ namespace rwe { - CobThread::CobThread(const std::string& name, int signalMask) : name(name), signalMask(signalMask) + CobThread::CobThread(const std::string& name, uint32_t signalMask) : name(name), signalMask(signalMask) { } diff --git a/src/rwe/cob/CobThread.h b/src/rwe/cob/CobThread.h index c2b7aec36..3c2cbfb43 100644 --- a/src/rwe/cob/CobThread.h +++ b/src/rwe/cob/CobThread.h @@ -14,7 +14,7 @@ namespace rwe std::stack stack; - int signalMask{0}; + uint32_t signalMask{0}; std::stack callStack; @@ -27,7 +27,7 @@ namespace rwe std::vector returnLocals; public: - CobThread(const std::string& name, int signalMask); + CobThread(const std::string& name, uint32_t signalMask); explicit CobThread(const std::string& name); }; diff --git a/src/rwe/grid/DiscreteRect.h b/src/rwe/grid/DiscreteRect.h index dc982b748..6a10f10e3 100644 --- a/src/rwe/grid/DiscreteRect.h +++ b/src/rwe/grid/DiscreteRect.h @@ -19,6 +19,7 @@ namespace rwe DiscreteRect() = default; DiscreteRect(int x, int y, int width, int height) : x(x), y(y), width(width), height(height) { + assert(width >= 0 && height >= 0); } bool operator==(const DiscreteRect& rhs) const diff --git a/src/rwe/grid/Grid.h b/src/rwe/grid/Grid.h index ca8ecae92..ca7f8a660 100644 --- a/src/rwe/grid/Grid.h +++ b/src/rwe/grid/Grid.h @@ -17,6 +17,7 @@ namespace rwe GridCoordinates() = default; GridCoordinates(int x, int y) : x(x), y(y) { + assert(x >= 0 && y >= 0); } bool operator==(const GridCoordinates& rhs) const @@ -47,7 +48,10 @@ namespace rwe GridRegion() = default; GridRegion(int x, int y, int width, int height) - : x(x), y(y), width(width), height(height) {} + : x(x), y(y), width(width), height(height) + { + assert(x >= 0 && y >= 0 && width >= 0 && height >= 0); + } template void forEach(Func f) const @@ -118,14 +122,15 @@ namespace rwe Grid() : width(0), height(0) {} Grid(int width, int height) - : width(width), height(height), data(width * height) {} + : width(width), height(height), data(width * height) { assert(width >= 0 && height >= 0); } Grid(int width, int height, const T& initialValue) - : width(width), height(height), data(width * height, initialValue) {} + : width(width), height(height), data(width * height, initialValue) { assert(width >= 0 && height >= 0); } Grid(int width, int height, std::vector&& data) : width(width), height(height), data(std::move(data)) { + assert(width >= 0 && height >= 0); assert(this->data.size() == width * height); } diff --git a/src/rwe/ui/UiFactory.cpp b/src/rwe/ui/UiFactory.cpp index 25eca96de..630000821 100644 --- a/src/rwe/ui/UiFactory.cpp +++ b/src/rwe/ui/UiFactory.cpp @@ -613,10 +613,10 @@ namespace rwe auto defaultSprite = textureService->getDefaultSprite(); const auto& sprites = (*graphics)->sprites; - int spriteCount = static_cast(sprites.size()); + auto spriteCount = static_cast(sprites.size()); auto stagesPresentCount = spriteCount > 2 ? spriteCount - 2 : 0; - int stagesToCopyCount = std::min(stages, stagesPresentCount);//TODO (kwh) - do + auto stagesToCopyCount = std::min(stages, stagesPresentCount);//TODO (kwh) - do std::vector> normalSprites; for (int i = 0; i < stagesToCopyCount; ++i) diff --git a/src/rwe/ui/UiListBox.cpp b/src/rwe/ui/UiListBox.cpp index 2697badac..583aa0d1c 100644 --- a/src/rwe/ui/UiListBox.cpp +++ b/src/rwe/ui/UiListBox.cpp @@ -17,7 +17,7 @@ namespace rwe void UiListBox::render(UiRenderService& context) const { - int lines = std::min(numberOfLines(), items.size()); + auto lines = std::min(numberOfLines(), items.size()); for (int i = 0; i < lines; ++i) { From 2b5be17926c9a7124068091f0e62e09eb6865ed6 Mon Sep 17 00:00:00 2001 From: Kevin Hake Date: Fri, 27 Aug 2021 01:17:34 -0500 Subject: [PATCH 3/3] Fix DiscreteRect test after change to int --- src/rwe/grid/DiscreteRect.test.cpp | 156 +++++++++++++++-------------- 1 file changed, 82 insertions(+), 74 deletions(-) diff --git a/src/rwe/grid/DiscreteRect.test.cpp b/src/rwe/grid/DiscreteRect.test.cpp index 132a18f3d..93f0000c8 100644 --- a/src/rwe/grid/DiscreteRect.test.cpp +++ b/src/rwe/grid/DiscreteRect.test.cpp @@ -11,9 +11,10 @@ namespace rwe { SECTION("tests whether points are adjacent") { - DiscreteRect r(1, 2, 5, 6); + // x, y, w, h + DiscreteRect r(2, 2, 5, 6); - // -1 0 1 2 3 4 5 6 7 + // 0 1 2 3 4 5 6 7 8 // 0 . . . . . . . . . // 1 . . . . . . . . . // 2 . . x x x x x . . @@ -26,101 +27,108 @@ namespace rwe // 9 . . . . . . . . . // outside top-left - REQUIRE(!r.isAdjacentTo(0, 0)); - REQUIRE(!r.isAdjacentTo(-1, 1)); - REQUIRE(r.isAdjacentTo(0, 1)); + REQUIRE(!r.isAdjacentTo(1, 0)); + REQUIRE(!r.isAdjacentTo(0, 1)); REQUIRE(r.isAdjacentTo(1, 1)); - REQUIRE(r.isAdjacentTo(0, 2)); + REQUIRE(r.isAdjacentTo(2, 1)); + REQUIRE(r.isAdjacentTo(1, 2)); // inside top-left - REQUIRE(!r.isAdjacentTo(1, 2)); REQUIRE(!r.isAdjacentTo(2, 2)); - REQUIRE(!r.isAdjacentTo(1, 3)); + REQUIRE(!r.isAdjacentTo(3, 2)); + REQUIRE(!r.isAdjacentTo(2, 3)); // bottom-left - REQUIRE(r.isAdjacentTo(0, 7)); - REQUIRE(r.isAdjacentTo(0, 8)); + REQUIRE(r.isAdjacentTo(1, 7)); REQUIRE(r.isAdjacentTo(1, 8)); - REQUIRE(!r.isAdjacentTo(-1, 8)); - REQUIRE(!r.isAdjacentTo(0, 9)); + REQUIRE(r.isAdjacentTo(2, 8)); + REQUIRE(!r.isAdjacentTo(0, 8)); + REQUIRE(!r.isAdjacentTo(1, 9)); // inside bottom-left - REQUIRE(!r.isAdjacentTo(1, 6)); - REQUIRE(!r.isAdjacentTo(1, 7)); + REQUIRE(!r.isAdjacentTo(2, 6)); REQUIRE(!r.isAdjacentTo(2, 7)); + REQUIRE(!r.isAdjacentTo(3, 7)); // top-right - REQUIRE(!r.isAdjacentTo(6, 0)); - REQUIRE(!r.isAdjacentTo(7, 1)); - REQUIRE(r.isAdjacentTo(5, 1)); + REQUIRE(!r.isAdjacentTo(7, 0)); + REQUIRE(!r.isAdjacentTo(8, 1)); REQUIRE(r.isAdjacentTo(6, 1)); - REQUIRE(r.isAdjacentTo(6, 2)); + REQUIRE(r.isAdjacentTo(7, 1)); + REQUIRE(r.isAdjacentTo(7, 2)); // inside top-right - REQUIRE(!r.isAdjacentTo(4, 2)); REQUIRE(!r.isAdjacentTo(5, 2)); - REQUIRE(!r.isAdjacentTo(5, 3)); + REQUIRE(!r.isAdjacentTo(6, 2)); + REQUIRE(!r.isAdjacentTo(6, 3)); // bottom-right - REQUIRE(!r.isAdjacentTo(6, 9)); - REQUIRE(!r.isAdjacentTo(7, 8)); - REQUIRE(r.isAdjacentTo(5, 8)); + REQUIRE(!r.isAdjacentTo(7, 9)); + REQUIRE(!r.isAdjacentTo(8, 8)); REQUIRE(r.isAdjacentTo(6, 8)); - REQUIRE(r.isAdjacentTo(6, 7)); + REQUIRE(r.isAdjacentTo(7, 8)); + REQUIRE(r.isAdjacentTo(7, 7)); // inside bottom-right - REQUIRE(!r.isAdjacentTo(4, 7)); REQUIRE(!r.isAdjacentTo(5, 7)); - REQUIRE(!r.isAdjacentTo(5, 6)); + REQUIRE(!r.isAdjacentTo(6, 7)); + REQUIRE(!r.isAdjacentTo(6, 6)); } SECTION("tests whether rects are adjacent") { SECTION("manual tests") { - DiscreteRect r(1, 2, 5, 6); - - // -1 0 1 2 3 4 5 6 7 - // 0 . . . . . . . . . - // 1 . . . . . . . . . - // 2 . . x x x x x . . - // 3 . . x x x x x . . - // 4 . . x x x x x . . - // 5 . . x x x x x . . - // 6 . . x x x x x . . - // 7 . . x x x x x . . - // 8 . . . . . . . . . - // 9 . . . . . . . . . + DiscreteRect r(4, 2, 5, 6); + + // 0 1 2 3 4 5 6 7 8 9 a + // 0 . . . . . . . . . . . + // 1 . . . . . . . . . . . + // 2 . . . . x x x x x . . + // 3 . . . . x x x x x . . + // 4 . . . . x x x x x . . + // 5 . . . . x x x x x . . + // 6 . . . . x x x x x . . + // 7 . . . . x x x x x . . + // 8 . . . . . . . . . . . + // 9 . . . . . . . . . . . // shares left edge - REQUIRE(r.isAdjacentTo(DiscreteRect(-2, 3, 3, 2))); + REQUIRE(r.isAdjacentTo(DiscreteRect(1, 3, 3, 2))); // one space away from left edge - REQUIRE(!r.isAdjacentTo(DiscreteRect(-3, 3, 3, 2))); + REQUIRE(!r.isAdjacentTo(DiscreteRect(0, 3, 3, 2))); // shares top-left corner - REQUIRE(r.isAdjacentTo(DiscreteRect(-1, -1, 2, 3))); + REQUIRE(r.isAdjacentTo(DiscreteRect(2, 0, 2, 2))); // shares right edge - REQUIRE(r.isAdjacentTo(DiscreteRect(6, 4, 3, 2))); + REQUIRE(r.isAdjacentTo(DiscreteRect(9, 4, 3, 2))); // one space away from right edge - REQUIRE(!r.isAdjacentTo(DiscreteRect(7, 4, 3, 2))); + REQUIRE(!r.isAdjacentTo(DiscreteRect(10, 4, 3, 2))); // shares bottom edge - REQUIRE(r.isAdjacentTo(DiscreteRect(2, 8, 3, 2))); + REQUIRE(r.isAdjacentTo(DiscreteRect(5, 8, 3, 2))); // one space away from bottom edge - REQUIRE(!r.isAdjacentTo(DiscreteRect(2, 9, 3, 2))); + REQUIRE(!r.isAdjacentTo(DiscreteRect(5, 9, 3, 2))); // shares top edge - REQUIRE(r.isAdjacentTo(DiscreteRect(2, 0, 3, 2))); + REQUIRE(r.isAdjacentTo(DiscreteRect(5, 0, 3, 2))); // one space away from top edge - REQUIRE(!r.isAdjacentTo(DiscreteRect(2, -1, 3, 2))); + REQUIRE(!r.isAdjacentTo(DiscreteRect(5, 0, 3, 1))); } - rc::prop("a unit rectangle is adjacent if the point is", [](int x, int y, int w, int h, int x2, int y2) { + rc::prop("a unit rectangle is adjacent if the point is", []() + { + auto x = *rc::gen::positive(); + auto y = *rc::gen::positive(); + auto w = *rc::gen::positive(); + auto h = *rc::gen::positive(); + auto x2 = *rc::gen::positive(); + auto y2 = *rc::gen::positive(); DiscreteRect r(x, y, w, h); RC_ASSERT(r.isAdjacentTo(DiscreteRect(x2, y2, 1, 1)) == r.isAdjacentTo(x2, y2)); }); @@ -131,72 +139,72 @@ namespace rwe { SECTION("finds the shortest distance to the perimeter") { - DiscreteRect r(1, 2, 5, 6); - - // -1 0 1 2 3 4 5 6 7 - // 0 . . . . . . . . . - // 1 . . . . . . . . . - // 2 . . x x x x x . . - // 3 . . x x x x x . . - // 4 . . x x x x x . . - // 5 . . x x x x x . . - // 6 . . x x x x x . . - // 7 . . x x x x x . . - // 8 . . . . . . . . . - // 9 . . . . . . . . . + DiscreteRect r(5, 2, 5, 6); + + // 0 1 2 3 4 5 6 7 8 9 a b + // 0 . . . . . . . . . . . . + // 1 . . . . . . . . . . . . + // 2 . . . . . x x x x x . . + // 3 . . . . . x x x x x . . + // 4 . . . . . x x x x x . . + // 5 . . . . . x x x x x . . + // 6 . . . . . x x x x x . . + // 7 . . . . . x x x x x . . + // 8 . . . . . . . . . . . . + // 9 . . . . . . . . . . . . SECTION("top-left") { - auto actual = r.octileDistanceToPerimeter(-2, 0); + auto actual = r.octileDistanceToPerimeter(2, 0); auto expected = OctileDistance(1, 1); REQUIRE(actual == expected); } SECTION("top") { - auto actual = r.octileDistanceToPerimeter(2, -2); + auto actual = r.octileDistanceToPerimeter(6, -2); auto expected = OctileDistance(3, 0); REQUIRE(actual == expected); } SECTION("top-right") { - auto actual = r.octileDistanceToPerimeter(7, 0); + auto actual = r.octileDistanceToPerimeter(11, 0); auto expected = OctileDistance(0, 1); REQUIRE(actual == expected); } SECTION("right") { - auto actual = r.octileDistanceToPerimeter(7, 4); + auto actual = r.octileDistanceToPerimeter(11, 4); auto expected = OctileDistance(1, 0); REQUIRE(actual == expected); } SECTION("bottom-right") { - auto actual = r.octileDistanceToPerimeter(7, 9); + auto actual = r.octileDistanceToPerimeter(11, 9); auto expected = OctileDistance(0, 1); REQUIRE(actual == expected); } SECTION("bottom") { - auto actual = r.octileDistanceToPerimeter(5, 10); + auto actual = r.octileDistanceToPerimeter(9, 10); auto expected = OctileDistance(2, 0); REQUIRE(actual == expected); } SECTION("bottom-left") { - auto actual = r.octileDistanceToPerimeter(-1, 10); + auto actual = r.octileDistanceToPerimeter(3, 10); auto expected = OctileDistance(1, 1); REQUIRE(actual == expected); } SECTION("left") { - auto actual = r.octileDistanceToPerimeter(-4, 3); + auto actual = r.octileDistanceToPerimeter(0, 3); auto expected = OctileDistance(4, 0); REQUIRE(actual == expected); } @@ -204,28 +212,28 @@ namespace rwe SECTION("inside-left") { - auto actual = r.octileDistanceToPerimeter(1, 5); + auto actual = r.octileDistanceToPerimeter(5, 5); auto expected = OctileDistance(1, 0); REQUIRE(actual == expected); } SECTION("inside-top") { - auto actual = r.octileDistanceToPerimeter(3, 3); + auto actual = r.octileDistanceToPerimeter(7, 3); auto expected = OctileDistance(2, 0); REQUIRE(actual == expected); } SECTION("inside-right") { - auto actual = r.octileDistanceToPerimeter(5, 6); + auto actual = r.octileDistanceToPerimeter(9, 6); auto expected = OctileDistance(1, 0); REQUIRE(actual == expected); } SECTION("inside-bottom") { - auto actual = r.octileDistanceToPerimeter(4, 7); + auto actual = r.octileDistanceToPerimeter(8, 7); auto expected = OctileDistance(1, 0); REQUIRE(actual == expected); }