Skip to content

Commit

Permalink
Merge branch 'develop' into feature-35
Browse files Browse the repository at this point in the history
  • Loading branch information
Vio1625 committed Jan 27, 2023
2 parents af99a26 + 1f55b54 commit c75a563
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 39 deletions.
4 changes: 4 additions & 0 deletions src/client/ClientGameEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ ClientGameEngine::ClientGameEngine()
clientMap = std::make_shared<shared::Map>();
playerTurn.store(false);
clientConnectedAndReady.store(false);
areTextureLoaded.store(false);
}

/*!
Expand Down Expand Up @@ -449,10 +450,13 @@ void ClientGameEngine::renderGame()
*/
void ClientGameEngine::playGame()
{

std::thread t(&ClientGameEngine::startGameWindow, this);

long lastUpdateTimer = clientGame->getCurrentTime();

while (areTextureLoaded.load() == false);

while (runningWindow.load() == GAME)
{
if (clientGame->getCurrentTime() - lastUpdateTimer > REFRESH_ELEMENT)
Expand Down
1 change: 1 addition & 0 deletions src/client/GameWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ void GameWindow::startGame()
loadElementTexture();
updateElementTexture();
loadHudTexture();
gameEnginePtr->areTextureLoaded.store(true);
addPlayer(gameEnginePtr->myself->getName());

std::shared_ptr<bool> moveMode = std::make_shared<bool>(false);
Expand Down
1 change: 1 addition & 0 deletions src/shared/City.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ City::City()
this->isCapital = false;
this->isStateCity = false;
this->position = {0, 0};
this->stateCityType = CityStateEnum::bruxelles;
}

City::City(std::array<unsigned, 2> position)
Expand Down
1 change: 1 addition & 0 deletions src/shared/Resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ ResourceEnum Resource::getType()
Resource::Resource(ResourceEnum resource)
{
type = resource;
isAlive = true;
}
150 changes: 111 additions & 39 deletions src/shared/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,122 @@ template <class Archive>
void Hexagon::save(Archive &ar, const unsigned int version) const
{
ar << level;
ar << elementsList.size();
ar << elementsList;

std::vector<Caravan> caravans;
std::vector<Barbarian> barbarians;
std::vector<BarbarianVillage> barbarianVillages;
std::vector<ControlPawn> controlPawns;
std::vector<City> cities;

for (const auto &element : elementsList)
{
switch (element->index())
{
case 0:
caravans.push_back(std::get<Caravan>(*element));
break;
case 1:
barbarians.push_back(std::get<Barbarian>(*element));
break;
case 2:
barbarianVillages.push_back(std::get<BarbarianVillage>(*element));
break;
case 3:
controlPawns.push_back(std::get<ControlPawn>(*element));
break;
case 4:
cities.push_back(std::get<City>(*element));
break;
}
}
ar << caravans.size();
ar << barbarians.size();
ar << barbarianVillages.size();
ar << controlPawns.size();
ar << cities.size();
ar << caravans;
ar << barbarians;
ar << barbarianVillages;
ar << controlPawns;
ar << cities;

bool haveResource = (hexResource != nullptr);
ar << haveResource;
if (haveResource)
{
bool alive = hexResource->isAlive;
int type = (int) hexResource->type;
ar << alive;
ar << type;
}
}

template <class Archive>
void Hexagon::load(Archive &ar, const unsigned int version)
{
ar >> level;
size_t size = 0;

std::vector<Caravan> caravans;
std::vector<Barbarian> barbarians;
std::vector<BarbarianVillage> barbarianVillages;
std::vector<ControlPawn> controlPawns;
std::vector<City> cities;

ar >> size;
std::generate_n(std::back_inserter(caravans), size, []()
{ return Caravan(); });
ar >> size;
std::generate_n(std::back_inserter(elementsList), size, []()
{ return std::make_shared<elementVariant>(); });
ar >> elementsList;
std::generate_n(std::back_inserter(barbarians), size, []()
{ return Barbarian(); });
ar >> size;
std::generate_n(std::back_inserter(barbarianVillages), size, []()
{ return BarbarianVillage(); });
ar >> size;
std::generate_n(std::back_inserter(controlPawns), size, []()
{ return ControlPawn(); });
ar >> size;
std::generate_n(std::back_inserter(cities), size, []()
{ return City(); });

ar >> caravans;
ar >> barbarians;
ar >> barbarianVillages;
ar >> controlPawns;
ar >> cities;

for (auto &caravan : caravans)
{
elementsList.push_back(std::make_shared<elementVariant>(caravan));
}
for (auto &barbarian : barbarians)
{
elementsList.push_back(std::make_shared<elementVariant>(barbarian));
}
for (auto &barbarianVillage : barbarianVillages)
{
elementsList.push_back(std::make_shared<elementVariant>(barbarianVillage));
}
for (auto &controlPawn : controlPawns)
{
elementsList.push_back(std::make_shared<elementVariant>(controlPawn));
}
for (auto &city : cities)
{
elementsList.push_back(std::make_shared<elementVariant>(city));
}

bool haveResource = false;
ar >> haveResource;
if (haveResource)
{
bool alive = false;
int type = 0;
ar >> alive;
ar >> type;
hexResource = std::make_shared<Resource>((shared::ResourceEnum) type);
hexResource->isAlive = alive;
}
}

template <class Archive>
Expand Down Expand Up @@ -84,6 +187,9 @@ void City::serialize(Archive &ar, const unsigned int version)
ar &isMature;
ar &position;
ar &player;
int type = (int) stateCityType;
ar &type;
stateCityType = (shared::CityStateEnum) type;
}

template <class Archive>
Expand Down Expand Up @@ -113,37 +219,3 @@ void Caravan::serialize(Archive &ar, const unsigned int version)
ar &used;
ar &player;
}

namespace boost
{
namespace serialization
{
template <class Archive, typename... Ts>
void save(Archive &ar, const std::variant<Ts...> &obj, const unsigned int version)
{
boost::variant<Ts...> v;
std::visit([&](const auto &arg)
{ v = arg; },
obj);

ar &v;
}

template <class Archive, typename... Ts>
void load(Archive &ar, std::variant<Ts...> &obj, const unsigned int version)
{
boost::variant<Ts...> v;
ar &v;

boost::apply_visitor([&](auto &arg)
{ obj = arg; },
v);
}

template <class Archive, typename... Ts>
void serialize(Archive &ar, std::variant<Ts...> &t, const unsigned int file_version)
{
split_free(ar, t, file_version);
}
}
}

0 comments on commit c75a563

Please sign in to comment.