Skip to content

Commit

Permalink
Merge pull request #1677 from Flamefire/replayformat
Browse files Browse the repository at this point in the history
Add version to replay and recorded game commands
  • Loading branch information
Flow86 authored Jul 16, 2024
2 parents b189b33 + e5b6522 commit 15fc611
Show file tree
Hide file tree
Showing 51 changed files with 518 additions and 490 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ jobs:
# Use (compiler) default C++ 14 standard
# Use system cmake
# Use system boost (min version)
- { compiler: gcc-9, os: ubuntu-20.04, type: Debug, cmake: 3.16.3, boost: 1.69.0 }
- { compiler: clang-10, os: ubuntu-20.04, type: Debug, cmake: 3.16.3, boost: 1.69.0, externalSanitizer: true }
- { compiler: gcc-9, os: ubuntu-20.04, type: Debug, cmake: 3.16.3, boost: 1.71.0 }
- { compiler: clang-10, os: ubuntu-20.04, type: Debug, cmake: 3.16.3, boost: 1.71.0, externalSanitizer: true }
#
# Default compiler for Ubuntu 20.04
# Use (compiler) default C++ 14 standard
Expand Down
14 changes: 3 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2005 - 2021 Settlers Freaks <sf-team at siedler25.org>
# Copyright (C) 2005 - 2024 Settlers Freaks <sf-team at siedler25.org>
#
# SPDX-License-Identifier: GPL-2.0-or-later

Expand Down Expand Up @@ -306,21 +306,13 @@ if(BUILD_TESTING)
list(APPEND BoostPackages unit_test_framework)
endif()

find_package(Boost 1.69 COMPONENTS ${BoostPackages})
find_package(Boost 1.71 COMPONENTS ${BoostPackages})
if(NOT Boost_FOUND)
message(FATAL_ERROR "You have to install boost (>=1.69) into contrib/boost or set (as CMake or environment variable) "
message(FATAL_ERROR "You have to install boost (>=1.71) into contrib/boost or set (as CMake or environment variable) "
"BOOST_ROOT (currently: '${BOOST_ROOT}', Environment: '$ENV{BOOST_ROOT}'), "
"BOOST_INCLUDEDIR (currently: '${BOOST_INCLUDEDIR}', Environment: '$ENV{BOOST_INCLUDEDIR}') "
"since cmake was unable to find boost!")
endif()
if(Boost_VERSION VERSION_EQUAL 1.70)
# Bug in Boost 1.70: https://github.com/boostorg/boost_install/issues/5
if(Boost_USE_STATIC_LIBS)
set(BUILD_SHARED_LIBS OFF)
else()
set(BUILD_SHARED_LIBS ON)
endif()
endif()

option(RTTR_USE_SYSTEM_BOOST_NOWIDE "Use system installed Boost.Nowide. Fails if not found!" "${RTTR_USE_SYSTEM_LIBS}")

Expand Down
15 changes: 10 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ branches:
- master

image:
- Visual Studio 2017
- Visual Studio 2019
- Visual Studio 2022

configuration:
- Debug
Expand All @@ -35,10 +35,16 @@ matrix:
for:
- matrix:
only:
- image: Visual Studio 2017
- image: Visual Studio 2019
environment:
BOOST_ROOT: C:\Libraries\boost_1_69_0
GENERATOR: Visual Studio 15 2017
GENERATOR: Visual Studio 16 2019
BOOST_ROOT: C:\Libraries\boost_1_83_0
- matrix:
only:
- image: Visual Studio 2022
environment:
GENERATOR: Visual Studio 17 2022
BOOST_ROOT: C:\Libraries\boost_1_84_0

install:
- dir C:\Libraries
Expand All @@ -50,7 +56,6 @@ before_build:
- if exist %INSTALL_DIR%\ (rmdir /S /Q %INSTALL_DIR%)
- mkdir build
- cd build
- if %platform% == x64 (if "%GENERATOR%" == "Visual Studio 2017" (set "GENERATOR=%GENERATOR% Win64"))
# Enable LTCG for release builds (speeds up linking as /GL compiled modules are used)
- if %configuration% == Release (set "cmakeFlags=-DCMAKE_EXE_LINKER_FLAGS=/LTCG -DCMAKE_SHARED_LINKER_FLAGS=/LTCG")
- echo "Configuring %GENERATOR% for %configuration% on %platform% with boost=%BOOST_ROOT%"
Expand Down
2 changes: 1 addition & 1 deletion external/s25edit
Submodule s25edit updated 6 files
+4 −3 CGame.cpp
+2 −3 CGame_Render.cpp
+89 −145 CIO/CFile.cpp
+22 −23 CIO/CFile.h
+2 −2 CMap.cpp
+2 −2 CMap.h
2 changes: 1 addition & 1 deletion external/s25update
Submodule s25update updated 1 files
+42 −44 src/s25update.cpp
3 changes: 1 addition & 2 deletions extras/ai-battle/HeadlessGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,10 @@ void HeadlessGame::RecordReplay(const bfs::path& path, unsigned random_init)
mapInfo.mapData.CompressFromFile(mapInfo.filepath, &mapInfo.mapChecksum);
mapInfo.type = MapType::OldMap;

replay_.random_init = random_init;
for(unsigned playerId = 0; playerId < world_.GetNumPlayers(); ++playerId)
replay_.AddPlayer(world_.GetPlayer(playerId));
replay_.ggs = game_.ggs_;
if(!replay_.StartRecording(path, mapInfo))
if(!replay_.StartRecording(path, mapInfo, random_init))
throw std::runtime_error("Replayfile could not be opened!");
}

Expand Down
4 changes: 4 additions & 0 deletions extras/videoDrivers/SDL2/VideoSDL2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

#ifdef _WIN32
# include <boost/nowide/convert.hpp>
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# include <windows.h> // Avoid "Windows headers require the default packing option" due to SDL2
# include <SDL_syswm.h>
#endif // _WIN32

Expand Down
11 changes: 11 additions & 0 deletions libs/common/include/helpers/OptionalIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#pragma once

#include "helpers/OptionalEnum.h"
#include <optional>
#include <ostream>

namespace helpers {
Expand All @@ -14,3 +15,13 @@ std::ostream& operator<<(std::ostream& os, OptionalEnum<T> const& v)
return (v) ? os << *v : os << "[empty]";
}
} // namespace helpers

namespace std {
// LCOV_EXCL_START
template<typename T>
static std::ostream& boost_test_print_type(std::ostream& os, std::optional<T> const& v)
{
return (v) ? os << *v : os << "[empty]";
}
// LCOV_EXCL_STOP
} // namespace std
28 changes: 10 additions & 18 deletions libs/common/include/variant.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
// Copyright (C) 2005 - 2024 Settlers Freaks (sf-team at siedler25.org)
//
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <boost/variant.hpp>
#include <type_traits>
#include <boost/variant2/variant.hpp>

namespace detail {
template<typename...>
struct indexOf;
template<typename T, typename... Rest>
struct indexOf<T, T, Rest...> : std::integral_constant<size_t, 0>
{};
template<typename T, typename U, typename... Rest>
struct indexOf<T, U, Rest...> : std::integral_constant<size_t, 1 + indexOf<T, Rest...>::value>
{};
/// Shortcuts to avoid typing out boost::variant2
template<typename... T>
using boost_variant2 = boost::variant2::variant<T...>;

using boost::variant2::get;
using boost::variant2::get_if;
using boost::variant2::holds_alternative;

namespace detail {
template<typename... Lambdas>
struct lambda_visitor;

Expand All @@ -36,12 +34,6 @@ struct lambda_visitor<Lambda1> : public Lambda1
};
} // namespace detail

template<class T, class... Types>
bool holds_alternative(const boost::variant<Types...>& v) noexcept
{
return v.which() == detail::indexOf<T, Types...>::value;
}

template<class... Fs>
auto composeVisitor(Fs&&... fs)
{
Expand Down
2 changes: 1 addition & 1 deletion libs/s25main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2005 - 2021 Settlers Freaks <sf-team at siedler25.org>
# Copyright (C) 2005 - 2024 Settlers Freaks <sf-team at siedler25.org>
#
# SPDX-License-Identifier: GPL-2.0-or-later

Expand Down
4 changes: 2 additions & 2 deletions libs/s25main/Debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ bool DebugInfo::SendReplay()
rpl->Close();

BinaryFile f;
if(f.Open(replayPath, OpenFileMode::OFM_READ))
if(f.Open(replayPath, OpenFileMode::Read))
{
if(!SendString("Replay"))
return false;
Expand All @@ -317,7 +317,7 @@ bool DebugInfo::SendReplay()
bool DebugInfo::SendAsyncLog(const boost::filesystem::path& asyncLogFilepath)
{
BinaryFile file;
if(!file.Open(asyncLogFilepath, OFM_READ))
if(!file.Open(asyncLogFilepath, OpenFileMode::Read))
return false;

if(!SendString("AsyncLog"))
Expand Down
10 changes: 8 additions & 2 deletions libs/s25main/GameCommand.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
// Copyright (C) 2005 - 2024 Settlers Freaks (sf-team at siedler25.org)
//
// SPDX-License-Identifier: GPL-2.0-or-later

Expand All @@ -9,7 +9,13 @@

namespace gc {

GameCommandPtr GameCommand::Deserialize(Serializer& ser)
/// Current version of the game commands, see VersionedDeserializer.
unsigned Deserializer::getCurrentVersion()
{
return 0;
}

GameCommandPtr GameCommand::Deserialize(Deserializer& ser)
{
auto gcType = helpers::popEnum<GCType>(ser);
GameCommand* gc;
Expand Down
11 changes: 9 additions & 2 deletions libs/s25main/GameCommand.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
// Copyright (C) 2005 - 2024 Settlers Freaks (sf-team at siedler25.org)
//
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include "s25util/VersionedDeserializer.h"
#include <boost/smart_ptr/intrusive_ptr.hpp>
#include <RTTR_Assert.h>
#include <cstdint>
Expand All @@ -14,6 +15,12 @@ class GameCommandFactory;

namespace gc {

struct Deserializer : s25util::VersionedDeserializer<Deserializer>
{
using s25util::VersionedDeserializer<Deserializer>::VersionedDeserializer;
static unsigned getCurrentVersion();
};

class GameCommand;
// Use this for safely using Pointers to GameCommands
using GameCommandPtr = boost::intrusive_ptr<GameCommand>;
Expand Down Expand Up @@ -82,7 +89,7 @@ class GameCommand
}

/// Builds a GameCommand depending on Type
static GameCommandPtr Deserialize(Serializer& ser);
static GameCommandPtr Deserialize(Deserializer& ser);

/// Serializes this GameCommand
virtual void Serialize(Serializer& ser) const;
Expand Down
14 changes: 7 additions & 7 deletions libs/s25main/GameCommands.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
// Copyright (C) 2005 - 2024 Settlers Freaks (sf-team at siedler25.org)
//
// SPDX-License-Identifier: GPL-2.0-or-later

Expand Down Expand Up @@ -441,11 +441,11 @@ class NotifyAlliesOfLocation : public Coords
class SetInventorySetting : public Coords
{
GC_FRIEND_DECL;
boost::variant<GoodType, Job> what;
boost_variant2<GoodType, Job> what;
InventorySetting state;

protected:
SetInventorySetting(const MapPoint pt, boost::variant<GoodType, Job> what, const InventorySetting state)
SetInventorySetting(const MapPoint pt, boost_variant2<GoodType, Job> what, const InventorySetting state)
: Coords(GCType::SetInventorySetting, pt), what(std::move(what)), state(state)
{}
SetInventorySetting(Serializer& ser) : Coords(GCType::SetInventorySetting, ser)
Expand All @@ -464,7 +464,7 @@ class SetInventorySetting : public Coords
Coords::Serialize(ser);

ser.PushBool(holds_alternative<Job>(what));
boost::apply_visitor([&ser](auto type) { helpers::pushEnum<uint8_t>(ser, type); }, what);
visit([&ser](auto type) { helpers::pushEnum<uint8_t>(ser, type); }, what);
ser.PushUnsignedChar(static_cast<uint8_t>(state));
}

Expand Down Expand Up @@ -775,13 +775,13 @@ class ExpeditionCommand : public GameCommand
class TradeOverLand : public Coords
{
GC_FRIEND_DECL;
boost::variant<GoodType, Job> what;
boost_variant2<GoodType, Job> what;
/// Number of wares/figures we want to trade
uint32_t count;

protected:
/// Note: Can only trade wares or figures!
TradeOverLand(const MapPoint pt, boost::variant<GoodType, Job> what, const uint32_t count)
TradeOverLand(const MapPoint pt, boost_variant2<GoodType, Job> what, const uint32_t count)
: Coords(GCType::Trade, pt), what(std::move(what)), count(count)
{}
TradeOverLand(Serializer& ser) : Coords(GCType::Trade, ser)
Expand All @@ -799,7 +799,7 @@ class TradeOverLand : public Coords
Coords::Serialize(ser);

ser.PushBool(holds_alternative<Job>(what));
boost::apply_visitor([&ser](auto type) { helpers::pushEnum<uint8_t>(ser, type); }, what);
visit([&ser](auto type) { helpers::pushEnum<uint8_t>(ser, type); }, what);
ser.PushUnsignedInt(count);
}

Expand Down
11 changes: 5 additions & 6 deletions libs/s25main/GamePlayer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
// Copyright (C) 2005 - 2024 Settlers Freaks (sf-team at siedler25.org)
//
// SPDX-License-Identifier: GPL-2.0-or-later

Expand Down Expand Up @@ -26,7 +26,6 @@
#include "postSystem/DiplomacyPostQuestion.h"
#include "postSystem/PostManager.h"
#include "random/Random.h"
#include "variant.h"
#include "world/GameWorld.h"
#include "world/TradeRoute.h"
#include "nodeObjs/noFlag.h"
Expand Down Expand Up @@ -2170,7 +2169,7 @@ struct WarehouseDistanceComparator
};

/// Send wares to warehouse wh
void GamePlayer::Trade(nobBaseWarehouse* goalWh, const boost::variant<GoodType, Job>& what, unsigned count) const
void GamePlayer::Trade(nobBaseWarehouse* goalWh, const boost_variant2<GoodType, Job>& what, unsigned count) const
{
if(!world.GetGGS().isEnabled(AddonId::TRADE))
return;
Expand All @@ -2195,9 +2194,9 @@ void GamePlayer::Trade(nobBaseWarehouse* goalWh, const boost::variant<GoodType,
{
// Get available wares
const unsigned available =
boost::apply_visitor(composeVisitor([wh](GoodType gt) { return wh->GetAvailableWaresForTrading(gt); },
[wh](Job job) { return wh->GetAvailableFiguresForTrading(job); }),
what);
boost::variant2::visit(composeVisitor([wh](GoodType gt) { return wh->GetAvailableWaresForTrading(gt); },
[wh](Job job) { return wh->GetAvailableFiguresForTrading(job); }),
what);
if(available == 0)
continue;

Expand Down
6 changes: 3 additions & 3 deletions libs/s25main/GamePlayer.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
// Copyright (C) 2005 - 2024 Settlers Freaks (sf-team at siedler25.org)
//
// SPDX-License-Identifier: GPL-2.0-or-later

Expand All @@ -8,14 +8,14 @@
#include "GamePlayerInfo.h"
#include "helpers/EnumArray.h"
#include "helpers/MultiArray.h"
#include "variant.h"
#include "gameTypes/BuildingType.h"
#include "gameTypes/Inventory.h"
#include "gameTypes/MapCoordinates.h"
#include "gameTypes/PactTypes.h"
#include "gameTypes/SettingsTypes.h"
#include "gameTypes/StatisticTypes.h"
#include "gameData/MaxPlayers.h"
#include <boost/variant/variant_fwd.hpp>
#include <array>
#include <list>
#include <memory>
Expand Down Expand Up @@ -281,7 +281,7 @@ class GamePlayer : public GamePlayerInfo
/// IMPORTANT: Warehouses can be destroyed. So check them first before using!
std::vector<nobBaseWarehouse*> GetWarehousesForTrading(const nobBaseWarehouse& goalWh) const;
/// Send wares to warehouse wh
void Trade(nobBaseWarehouse* goalWh, const boost::variant<GoodType, Job>& what, unsigned count) const;
void Trade(nobBaseWarehouse* goalWh, const boost_variant2<GoodType, Job>& what, unsigned count) const;

void EnableBuilding(BuildingType type) { building_enabled[type] = true; }
void DisableBuilding(BuildingType type) { building_enabled[type] = false; }
Expand Down
Loading

0 comments on commit 15fc611

Please sign in to comment.