Skip to content

Commit

Permalink
Fix tests and review problems
Browse files Browse the repository at this point in the history
  • Loading branch information
tehKaiN committed Sep 18, 2022
1 parent 94219e5 commit 0f4e4b1
Show file tree
Hide file tree
Showing 15 changed files with 122 additions and 164 deletions.
194 changes: 97 additions & 97 deletions doc/lua/functions.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion libs/s25main/BasePlayerInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct BasePlayerInfo
PlayerState ps;
AI::Info aiInfo;
std::string name;
unsigned int portraitIndex;
unsigned portraitIndex;
Nation nation;
/// Actual color (ARGB)
unsigned color;
Expand Down
3 changes: 2 additions & 1 deletion libs/s25main/SerializedGameData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@
/// 7: Use helpers::push/popContainer (uses var size)
/// 8: noFlag::Wares converted to static_vector
/// 9: Drop serialization of node BQ
static const unsigned currentGameDataVersion = 9;
/// 10: Add portrait index serialization in player state
static const unsigned currentGameDataVersion = 10;
// clang-format on

std::unique_ptr<GameObject> SerializedGameData::Create_GameObject(const GO_Type got, const unsigned obj_id)
Expand Down
2 changes: 1 addition & 1 deletion libs/s25main/controls/ctrlBaseImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ void ctrlBaseImage::DrawImage(const Rect& dstArea, unsigned color) const
dst.bottom -= halfDelta;
}

img_->DrawRect(dst, srcArea, color);
img_->Draw(dst, srcArea, color);
}
2 changes: 1 addition & 1 deletion libs/s25main/gameData/PortraitConsts.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ constexpr std::array<PortraitInfo, 13> SUPPRESS_UNUSED Portraits = {
PortraitInfo{gettext_noop("Shaka"), ResourceId("io"), 258},
PortraitInfo{gettext_noop("Todo"), ResourceId("io"), 262},
PortraitInfo{gettext_noop("Mnga Tscha "), ResourceId("io"), 257},
PortraitInfo{gettext_noop("Baby"), ResourceId("io_new"), 007},
PortraitInfo{gettext_noop("Nabonidus"), ResourceId("io_new"), 7},
};
4 changes: 1 addition & 3 deletions libs/s25main/network/GameMessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,7 @@ class GameMessage_Player_Portrait : public GameMessageWithPlayer
GameMessage_Player_Portrait() : GameMessageWithPlayer(NMS_PLAYER_PORTRAIT) {}
GameMessage_Player_Portrait(uint8_t player, unsigned int portraitIndex)
: GameMessageWithPlayer(NMS_PLAYER_PORTRAIT, player), playerPortraitIndex(portraitIndex)
{
LOG.writeToFile(">>> NMS_PLAYER_PORTRAIT(%u)\n") % portraitIndex;
}
{}

void Serialize(Serializer& ser) const override
{
Expand Down
43 changes: 1 addition & 42 deletions libs/s25main/network/GameServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,14 @@ bool GameServer::CountDown::Update()
return true;
}

///////////////////////////////////////////////////////////////////////////////
//
GameServer::GameServer() : skiptogf(0), state(ServerState::Stopped), currentGF(0), lanAnnouncer(LAN_DISCOVERY_CFG) {}

///////////////////////////////////////////////////////////////////////////////
//
GameServer::~GameServer()
{
Stop();
}

///////////////////////////////////////////////////////////////////////////////
// Spiel hosten
// Host the game.
bool GameServer::Start(const CreateServerInfo& csi, const boost::filesystem::path& map_path, MapType map_type,
const std::string& hostPw)
{
Expand Down Expand Up @@ -271,8 +266,6 @@ void GameServer::LC_Created()
AnnounceStatusChange();
}

///////////////////////////////////////////////////////////////////////////////
// Hauptschleife
void GameServer::Run()
{
if(state == ServerState::Stopped)
Expand Down Expand Up @@ -387,8 +380,6 @@ void GameServer::RunStateGame()
ExecuteGameFrame();
}

///////////////////////////////////////////////////////////////////////////////
// stoppt den server
void GameServer::Stop()
{
if(state == ServerState::Stopped)
Expand Down Expand Up @@ -524,9 +515,6 @@ bool GameServer::assignPlayersOfRandomTeams(std::vector<JoinPlayerInfo>& playerI
return playerWasAssigned;
}

/**
* startet das Spiel.
*/
bool GameServer::StartGame()
{
lanAnnouncer.Stop();
Expand Down Expand Up @@ -602,9 +590,6 @@ void GameServer::SendNWFDone(const NWFServerInfo& info)
SendToAll(GameMessage_Server_NWFDone(info.gf, info.newGFLen, info.nextNWF));
}

/**
* Nachricht an Alle
*/
void GameServer::SendToAll(const GameMessage& msg)
{
for(GameServerPlayer& player : networkPlayers)
Expand Down Expand Up @@ -643,7 +628,6 @@ void GameServer::KickPlayer(uint8_t playerId, KickReason cause, uint32_t param)
% unsigned(param);
}

///////////////////////////////////////////////////////////////////////////////
// testet, ob in der Verbindungswarteschlange Clients auf Verbindung warten
void GameServer::ClientWatchDog()
{
Expand Down Expand Up @@ -815,7 +799,6 @@ bool GameServer::CheckForLaggingPlayers()
return true;
}

///////////////////////////////////////////////////////////////////////////////
// testet, ob in der Verbindungswarteschlange Clients auf Verbindung warten
void GameServer::WaitForClients()
{
Expand Down Expand Up @@ -852,7 +835,6 @@ void GameServer::WaitForClients()
}
}

///////////////////////////////////////////////////////////////////////////////
// füllt die warteschlangen mit "paketen"
void GameServer::FillPlayerQueues()
{
Expand Down Expand Up @@ -888,8 +870,6 @@ void GameServer::FillPlayerQueues()
} while(msgReceived);
}

///////////////////////////////////////////////////////////////////////////////
// pongnachricht
bool GameServer::OnGameMessage(const GameMessage_Pong& msg)
{
GameServerPlayer* player = GetNetworkPlayer(msg.senderPlayerID);
Expand All @@ -904,8 +884,6 @@ bool GameServer::OnGameMessage(const GameMessage_Pong& msg)
return true;
}

///////////////////////////////////////////////////////////////////////////////
// servertype
bool GameServer::OnGameMessage(const GameMessage_Server_Type& msg)
{
if(state != ServerState::Config)
Expand All @@ -931,9 +909,6 @@ bool GameServer::OnGameMessage(const GameMessage_Server_Type& msg)
return true;
}

/**
* Server-Passwort-Nachricht
*/
bool GameServer::OnGameMessage(const GameMessage_Server_Password& msg)
{
if(state != ServerState::Config)
Expand Down Expand Up @@ -961,9 +936,6 @@ bool GameServer::OnGameMessage(const GameMessage_Server_Password& msg)
return true;
}

/**
* Chat-Nachricht.
*/
bool GameServer::OnGameMessage(const GameMessage_Chat& msg)
{
int playerID = GetTargetPlayer(msg);
Expand Down Expand Up @@ -1035,8 +1007,6 @@ bool GameServer::OnGameMessage(const GameMessage_Player_State& msg)
return true;
}

///////////////////////////////////////////////////////////////////////////////
// Player name
bool GameServer::OnGameMessage(const GameMessage_Player_Name& msg)
{
if(state != ServerState::Config)
Expand All @@ -1057,8 +1027,6 @@ bool GameServer::OnGameMessage(const GameMessage_Player_Name& msg)
return true;
}

///////////////////////////////////////////////////////////////////////////////
// Player portrait
bool GameServer::OnGameMessage(const GameMessage_Player_Portrait& msg)
{
if(state != ServerState::Config)
Expand All @@ -1079,8 +1047,6 @@ bool GameServer::OnGameMessage(const GameMessage_Player_Portrait& msg)
return true;
}

///////////////////////////////////////////////////////////////////////////////
// Nation weiterwechseln
bool GameServer::OnGameMessage(const GameMessage_Player_Nation& msg)
{
if(state != ServerState::Config)
Expand All @@ -1099,8 +1065,6 @@ bool GameServer::OnGameMessage(const GameMessage_Player_Nation& msg)
return true;
}

///////////////////////////////////////////////////////////////////////////////
// Team weiterwechseln
bool GameServer::OnGameMessage(const GameMessage_Player_Team& msg)
{
if(state != ServerState::Config)
Expand All @@ -1119,8 +1083,6 @@ bool GameServer::OnGameMessage(const GameMessage_Player_Team& msg)
return true;
}

///////////////////////////////////////////////////////////////////////////////
// Farbe weiterwechseln
bool GameServer::OnGameMessage(const GameMessage_Player_Color& msg)
{
if(state != ServerState::Config)
Expand All @@ -1137,9 +1099,6 @@ bool GameServer::OnGameMessage(const GameMessage_Player_Color& msg)
return true;
}

/**
* Spielerstatus wechseln
*/
bool GameServer::OnGameMessage(const GameMessage_Player_Ready& msg)
{
if(state != ServerState::Config)
Expand Down
2 changes: 1 addition & 1 deletion libs/s25main/ogl/ITexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ class ITexture
virtual Position GetOrigin() const = 0;
virtual Extent GetSize() const = 0;
virtual void DrawFull(const Position& dstPos, unsigned color = 0xFFFFFFFFu) = 0;
virtual void DrawRect(Rect dstArea, Rect srcArea, unsigned color = 0xFFFFFFFFu) = 0;
virtual void Draw(Rect dstArea, Rect srcArea, unsigned color = 0xFFFFFFFFu) = 0;
};
6 changes: 3 additions & 3 deletions libs/s25main/ogl/glArchivItem_Bitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ glArchivItem_Bitmap::glArchivItem_Bitmap(const glArchivItem_Bitmap& item)
/**
* Zeichnet die Textur.
*/
void glArchivItem_Bitmap::DrawRect(Rect dstArea, Rect srcArea, unsigned color /*= COLOR_WHITE*/)
void glArchivItem_Bitmap::Draw(Rect dstArea, Rect srcArea, unsigned color /*= COLOR_WHITE*/)
{
if(GetTexture() == 0)
return;
Expand Down Expand Up @@ -65,7 +65,7 @@ void glArchivItem_Bitmap::DrawRect(Rect dstArea, Rect srcArea, unsigned color /*

void glArchivItem_Bitmap::DrawFull(const Rect& destArea, unsigned color)
{
DrawRect(destArea, Rect(Position(0, 0), GetSize()), color);
Draw(destArea, Rect(Position(0, 0), GetSize()), color);
}

void glArchivItem_Bitmap::DrawFull(const DrawPoint& dstPos, unsigned color)
Expand All @@ -75,7 +75,7 @@ void glArchivItem_Bitmap::DrawFull(const DrawPoint& dstPos, unsigned color)

void glArchivItem_Bitmap::DrawPart(const Rect& destArea, const DrawPoint& offset, unsigned color)
{
DrawRect(destArea, Rect(offset, destArea.getSize()), color);
Draw(destArea, Rect(offset, destArea.getSize()), color);
}

void glArchivItem_Bitmap::DrawPart(const Rect& destArea, unsigned color /*= COLOR_WHITE*/)
Expand Down
2 changes: 1 addition & 1 deletion libs/s25main/ogl/glArchivItem_Bitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class glArchivItem_Bitmap : public virtual libsiedler2::baseArchivItem_Bitmap, p
/// Draw the texture.
/// src_w/h default to the full bitmap size
/// dst_w/h default the src_w/h
void DrawRect(Rect dstArea, Rect srcArea, unsigned color = COLOR_WHITE) override;
void Draw(Rect dstArea, Rect srcArea, unsigned color = COLOR_WHITE) override;

protected:
void FillTexture() override;
Expand Down
2 changes: 1 addition & 1 deletion libs/s25main/ogl/glArchivItem_Bitmap_Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void glArchivItem_Bitmap_Player::drawForPlayer(const DrawPoint& dst, unsigned pl
DrawFull(dst, COLOR_WHITE, playerColor);
}

void glArchivItem_Bitmap_Player::DrawRect(Rect dstArea, Rect srcArea, unsigned color /*= COLOR_WHITE*/)
void glArchivItem_Bitmap_Player::Draw(Rect dstArea, Rect srcArea, unsigned color /*= COLOR_WHITE*/)
{
Draw(dstArea, srcArea, color, COLOR_WHITE);
}
Expand Down
2 changes: 1 addition & 1 deletion libs/s25main/ogl/glArchivItem_Bitmap_Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class glArchivItem_Bitmap_Player : public libsiedler2::ArchivItem_Bitmap_Player,
virtual void DrawFull(const Position& dstPos, unsigned color = COLOR_WHITE) override;
/// Draw in player colors
void drawForPlayer(const DrawPoint& dst, unsigned playerColor);
void DrawRect(Rect dstArea, Rect srcArea, unsigned color = COLOR_WHITE) override;
void Draw(Rect dstArea, Rect srcArea, unsigned color = COLOR_WHITE) override;

protected:
void Draw(Rect dstArea, Rect srcArea, unsigned color = COLOR_WHITE, unsigned player_color = COLOR_WHITE);
Expand Down
18 changes: 9 additions & 9 deletions libs/s25main/ogl/glSmartBitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ void glSmartBitmap::generateTexture()
}
}

void glSmartBitmap::DrawRect(Rect dstArea, Rect srcArea, unsigned color /*= 0xFFFFFFFF*/)
void glSmartBitmap::Draw(Rect dstArea, Rect srcArea, unsigned color /*= 0xFFFFFFFF*/)
{
drawRect(dstArea, srcArea, color);
}
Expand Down Expand Up @@ -286,15 +286,15 @@ void glSmartBitmap::drawRect(Rect dstArea, Rect srcArea, unsigned color /*= 0xFF
curTexCoords[1] = texCoords[1];
curTexCoords[2] = texCoords[2];
curTexCoords[3] = texCoords[3];
curTexCoords[0].y = curTexCoords[3].y = helpers::lerp<float>(
texCoords[0].y, texCoords[1].y, helpers::inverseLerp<float>(.0f, float(size_.y), float(srcArea.getOrigin().y)));
curTexCoords[1].y = curTexCoords[2].y = helpers::lerp<float>(
texCoords[0].y, texCoords[1].y, helpers::inverseLerp<float>(.0f, float(size_.y), float(srcArea.getEndPt().y)));
curTexCoords[0].y = curTexCoords[3].y = helpers::lerp(
texCoords[0].y, texCoords[1].y, helpers::inverseLerp(.0f, float(size_.y), float(srcArea.getOrigin().y)));
curTexCoords[1].y = curTexCoords[2].y = helpers::lerp(
texCoords[0].y, texCoords[1].y, helpers::inverseLerp(.0f, float(size_.y), float(srcArea.getEndPt().y)));
// horizontal coords
curTexCoords[0].x = curTexCoords[1].x = helpers::lerp<float>(
texCoords[0].x, texCoords[3].x, helpers::inverseLerp<float>(.0f, float(size_.x), float(srcArea.getOrigin().x)));
curTexCoords[2].x = curTexCoords[3].x = helpers::lerp<float>(
texCoords[0].x, texCoords[3].x, helpers::inverseLerp<float>(.0f, float(size_.x), float(srcArea.getEndPt().x)));
curTexCoords[0].x = curTexCoords[1].x = helpers::lerp(
texCoords[0].x, texCoords[3].x, helpers::inverseLerp(.0f, float(size_.x), float(srcArea.getOrigin().x)));
curTexCoords[2].x = curTexCoords[3].x = helpers::lerp(
texCoords[0].x, texCoords[3].x, helpers::inverseLerp(.0f, float(size_.x), float(srcArea.getEndPt().x)));

int numQuads;
if(player_color && hasPlayer)
Expand Down
2 changes: 1 addition & 1 deletion libs/s25main/ogl/glSmartBitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class glSmartBitmap : public ITexture

void generateTexture();
void DrawFull(const Position& dstPos, unsigned color = 0xFFFFFFFF) override { draw(dstPos, color); }
void DrawRect(Rect dstArea, Rect srcArea, unsigned color = 0xFFFFFFFF) override;
void Draw(Rect dstArea, Rect srcArea, unsigned color = 0xFFFFFFFF) override;
void drawRect(Rect dstArea, Rect srcArea, unsigned color = 0xFFFFFFFF, unsigned player_color = 0);
void draw(DrawPoint drawPt, unsigned color = 0xFFFFFFFF, unsigned player_color = 0);
void drawForPlayer(DrawPoint drawPt, unsigned player_color) { draw(drawPt, 0xFFFFFFFF, player_color); }
Expand Down
2 changes: 1 addition & 1 deletion tests/s25Main/lua/testLuaSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ BOOST_AUTO_TEST_CASE(PlayerSettings)
BOOST_TEST(isLuaEqual("player:GetName()", "'Foo'"));

executeLua("player:SetPortrait(8)");
BOOST_TEST(players[0].portraitIndex == 8);
BOOST_TEST(players[0].portraitIndex == 8u);

executeLua("player:SetColor(2)");
BOOST_TEST_REQUIRE(players[0].color == PLAYER_COLORS[2]);
Expand Down

0 comments on commit 0f4e4b1

Please sign in to comment.