Skip to content

Commit

Permalink
[quality] Sonar fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gbaudic committed Apr 11, 2020
1 parent 186b9b6 commit d5f3393
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
12 changes: 11 additions & 1 deletion src/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,20 @@ void Context::receive() {
}
}

/**
* \brief Send a message to the server
* We assume that the correct IP has been set beforehand
* \param code message type
* \param message message, formatted as a string
*/
void Context::send(const Uint8 code, const std::string & message) {
network.send(code, message);
}

/**
* \brief Store the server IP for further use
* \param ip address to use
*/
void Context::setServerIP(const Uint32 ip) {
network.setServerInfo(ip);
}
Expand Down Expand Up @@ -167,7 +177,7 @@ Context * Context::getNextContext(ContextName nextName) {
currentContext->leave();
if (currentName == ContextName::ROOM) {
// Restore the previous lobby
Context* previousContext = currentContext;
const Context* previousContext = currentContext;
currentContext = dynamic_cast<RoomView*>(currentContext)->getLobby();
delete previousContext;
} else {
Expand Down
6 changes: 6 additions & 0 deletions src/views/lobbyview.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@

class LobbyView : public Context, public gcn::ActionListener {
public:
enum class InteractionMode {
WAITING,
LOADING, //! room full, coordinates and map are loading
EXITING //! loading complete, about to move to RoomView
};

explicit LobbyView(ContextName name);
void action(const gcn::ActionEvent& actionEvent) override;

Expand Down
6 changes: 3 additions & 3 deletions src/views/roomview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ const Uint16 RoomView::MAX_POWER;
* Constructor
* @param view the LobbyView, which already has players and all parameters set
*/
RoomView::RoomView(LobbyView *view) : Context(ContextName::ROOM),
gameMode(view->getMode()) {
RoomView::RoomView(const LobbyView *view) : Context(ContextName::ROOM),
gameMode(view->getMode()), currentMap(new GameMap(view->getMap())) {

currentMap = new GameMap(view->getMap());

fg_rect.w = getWidth();
fg_rect.h = getHeight();
Expand Down Expand Up @@ -73,6 +72,7 @@ gameMode(view->getMode()) {
}

RoomView::~RoomView() {
delete currentMap; // because of new in constructor -- improve this
}

void RoomView::action(const gcn::ActionEvent &actionEvent) {
Expand Down
2 changes: 1 addition & 1 deletion src/views/roomview.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class RoomView: public Context, public gcn::ActionListener {
RESULTS //! match is over
};

explicit RoomView(LobbyView *view);
explicit RoomView(const LobbyView *view);
virtual ~RoomView();

void action(const gcn::ActionEvent &actionEvent) override;
Expand Down

0 comments on commit d5f3393

Please sign in to comment.