Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
- The code starting a tutorial race was duplicated in three places. Consolidate it in one place.
- When launching the tutorial from the overworld, use the last used input device instead of the keyboard
- Restore the old cmake policy. The new way to replace that code suggested by the cmake manual fails CI, and debugging MSVC fantasies without a local install is a nightmare.
- Restrict this policy setting to MSVC as that's the only compile path that needs it, avoiding the warning for non-MSVC builds.
- Add missing define guards
- Remove some extraneous includes
  • Loading branch information
Alayan-stk-2 committed May 21, 2024
1 parent e165a56 commit 2923a86
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 119 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ add_definitions( -DSUPERTUXKART_VERSION="${PROJECT_VERSION}" )
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
include(CMakeDependentOption)

if(MSVC)
cmake_policy(SET CMP0043 OLD)
endif()

include(BuildTypeSTKRelease)
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, default to STKRelease")
Expand Down
2 changes: 2 additions & 0 deletions src/config/player_profile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ class PlayerProfile : public NoCopy
/** Returns the name of this player. */
const core::stringw& getName() const
{
#ifdef DEBUG

This comment has been minimized.

Copy link
@qwertychouskie

qwertychouskie May 21, 2024

Contributor

Aren't asserts inherently not compiled unless in DEBUG?

This comment has been minimized.

Copy link
@Alayan-stk-2

Alayan-stk-2 May 22, 2024

Author Collaborator

These guards are present elsewhere in that file, and MSVC complained about it missing here at one point yesterday.

Although in theory yes, in NDEBUG the asserts should be compiled into doing nothing.

This comment has been minimized.

Copy link
@CodingJellyfish

CodingJellyfish May 22, 2024

Member

In fact there are already a lot of false warnings from GCC caused by assert(). I don't think the warning should be fixed by a #ifdef but something more general.

assert(m_magic_number == 0xABCD1234);
#endif
return m_local_name;
} // getName

Expand Down
62 changes: 62 additions & 0 deletions src/modes/tutorial_utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// SuperTuxKart - a fun racing game with go-kart
//
// Copyright (C) 2024 Alayan
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#include "modes/tutorial_utils.hpp"

#include "config/player_manager.hpp"
#include "config/user_config.hpp"
#include "karts/kart_properties_manager.hpp"
#include "input/device_manager.hpp"
#include "input/input_manager.hpp"
#include "race/race_manager.hpp"

namespace TutorialUtils
{
void startTutorial(bool from_overworld)
{
RaceManager::get()->setNumPlayers(1);
RaceManager::get()->setMajorMode (RaceManager::MAJOR_MODE_SINGLE);
RaceManager::get()->setMinorMode (RaceManager::MINOR_MODE_TUTORIAL);
RaceManager::get()->setNumKarts( 1 );
RaceManager::get()->setTrack( "tutorial" );
RaceManager::get()->setDifficulty(RaceManager::DIFFICULTY_EASY);
RaceManager::get()->setReverseTrack(false);

// Use the last used device
InputDevice* device = input_manager->getDeviceManager()->getLatestUsedDevice();

// Create player and associate player with device
StateManager::get()->createActivePlayer(PlayerManager::getCurrentPlayer(), device);

if (kart_properties_manager->getKart(UserConfigParams::m_default_kart) == NULL)
{
Log::warn("HelpScreen1", "Cannot find kart '%s', will revert to default",
UserConfigParams::m_default_kart.c_str());
UserConfigParams::m_default_kart.revertToDefaults();
}
RaceManager::get()->setPlayerKart(0, UserConfigParams::m_default_kart);

// ASSIGN should make sure that only input from assigned devices is read.
input_manager->getDeviceManager()->setAssignMode(ASSIGN);
input_manager->getDeviceManager()->setSinglePlayer( StateManager::get()->getActivePlayer(0) );

StateManager::get()->enterGameState();
RaceManager::get()->setupPlayerKartInfo();
RaceManager::get()->startNew(from_overworld);
}
}
27 changes: 27 additions & 0 deletions src/modes/tutorial_utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SuperTuxKart - a fun racing game with go-kart
//
// Copyright (C) 2024 Alayan
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#ifndef __HEADER_TUTORIAL_UTILS_HPP__
#define __HEADER_TUTORIAL_UTILS_HPP__

namespace TutorialUtils
{
void startTutorial(bool from_overworld = false);
}

#endif
44 changes: 3 additions & 41 deletions src/modes/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "karts/kart_rewinder.hpp"
#include "main_loop.hpp"
#include "modes/overworld.hpp"
#include "modes/tutorial_utils.hpp"
#include "network/child_loop.hpp"
#include "network/protocols/client_lobby.hpp"
#include "network/network_config.hpp"
Expand Down Expand Up @@ -82,12 +83,6 @@
#include "utils/translation.hpp"
#include "utils/string_utils.hpp"

#include <algorithm>
#include <assert.h>
#include <ctime>
#include <sstream>
#include <stdexcept>

#include <IrrlichtDevice.h>
#include <ISceneManager.h>

Expand Down Expand Up @@ -1016,7 +1011,6 @@ void World::updateWorld(int ticks)
assert(m_magic_number == 0xB01D6543);
#endif


if (m_schedule_pause)
{
pause(m_scheduled_pause_phase);
Expand Down Expand Up @@ -1067,41 +1061,8 @@ void World::updateWorld(int ticks)
if (m_schedule_tutorial)
{
m_schedule_tutorial = false;
RaceManager::get()->setNumPlayers(1);
RaceManager::get()->setMajorMode (RaceManager::MAJOR_MODE_SINGLE);
RaceManager::get()->setMinorMode (RaceManager::MINOR_MODE_TUTORIAL);
RaceManager::get()->setNumKarts( 1 );
RaceManager::get()->setTrack( "tutorial" );
RaceManager::get()->setDifficulty(RaceManager::DIFFICULTY_EASY);
RaceManager::get()->setReverseTrack(false);

// Use keyboard 0 by default (FIXME: let player choose?)
InputDevice* device = input_manager->getDeviceManager()->getKeyboard(0);

// Create player and associate player with keyboard
StateManager::get()->createActivePlayer(PlayerManager::getCurrentPlayer(),
device);

if (!kart_properties_manager->getKart(UserConfigParams::m_default_kart))
{
Log::warn("[World]",
"Cannot find kart '%s', will revert to default.",
UserConfigParams::m_default_kart.c_str());
UserConfigParams::m_default_kart.revertToDefaults();
}
RaceManager::get()->setPlayerKart(0, UserConfigParams::m_default_kart);

// ASSIGN should make sure that only input from assigned devices
// is read.
input_manager->getDeviceManager()->setAssignMode(ASSIGN);
input_manager->getDeviceManager()
->setSinglePlayer( StateManager::get()->getActivePlayer(0) );

delete this;

StateManager::get()->enterGameState();
RaceManager::get()->setupPlayerKartInfo();
RaceManager::get()->startNew(true);
TutorialUtils::startTutorial(true /*from overworld*/);
}
else
{
Expand All @@ -1123,6 +1084,7 @@ void World::updateWorld(int ticks)

void World::scheduleTutorial()
{
printf("Tutorial scheduled\n");

This comment has been minimized.

Copy link
@qwertychouskie

qwertychouskie May 21, 2024

Contributor

Shouldn't this use the STK logging function? (Perhaps this is a leftover from testing in development?)

This comment has been minimized.

Copy link
@Alayan-stk-2

Alayan-stk-2 May 22, 2024

Author Collaborator

Yes a leftover.

m_schedule_exit_race = true;
m_schedule_tutorial = true;
} // scheduleTutorial
Expand Down
40 changes: 2 additions & 38 deletions src/states_screens/help/help_screen_1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,8 @@
// Manages includes common to all help screens
#include "states_screens/help/help_common.hpp"

#include "config/player_manager.hpp"
#include "config/user_config.hpp"
#include "guiengine/widgets/button_widget.hpp"
#include "input/device_manager.hpp"
#include "input/input_manager.hpp"
#include "karts/kart_properties_manager.hpp"
#include "race/race_manager.hpp"
#include "modes/tutorial_utils.hpp"

using namespace GUIEngine;

Expand All @@ -46,38 +41,7 @@ void HelpScreen1::eventCallback(Widget* widget, const std::string& name, const i
{
if (name == "startTutorial")
{
RaceManager::get()->setNumPlayers(1);
RaceManager::get()->setMajorMode (RaceManager::MAJOR_MODE_SINGLE);
RaceManager::get()->setMinorMode (RaceManager::MINOR_MODE_TUTORIAL);
RaceManager::get()->setNumKarts( 1 );
RaceManager::get()->setTrack( "tutorial" );
RaceManager::get()->setDifficulty(RaceManager::DIFFICULTY_EASY);
RaceManager::get()->setReverseTrack(false);

// Use the last used device
InputDevice* device = input_manager->getDeviceManager()->getLatestUsedDevice();

// Create player and associate player with keyboard
StateManager::get()->createActivePlayer(PlayerManager::getCurrentPlayer(),
device);

if (kart_properties_manager->getKart(UserConfigParams::m_default_kart) == NULL)
{
Log::warn("HelpScreen1", "Cannot find kart '%s', will revert to default",
UserConfigParams::m_default_kart.c_str());
UserConfigParams::m_default_kart.revertToDefaults();
}
RaceManager::get()->setPlayerKart(0, UserConfigParams::m_default_kart);

// ASSIGN should make sure that only input from assigned devices
// is read.
input_manager->getDeviceManager()->setAssignMode(ASSIGN);
input_manager->getDeviceManager()
->setSinglePlayer( StateManager::get()->getActivePlayer(0) );

StateManager::get()->enterGameState();
RaceManager::get()->setupPlayerKartInfo();
RaceManager::get()->startNew(false);
TutorialUtils::startTutorial();
}
else if (name == "category")
{
Expand Down
42 changes: 4 additions & 38 deletions src/states_screens/main_menu_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@
#include "karts/kart_properties_manager.hpp"
#include "main_loop.hpp"
#include "modes/cutscene_world.hpp"
#include "modes/overworld.hpp"
#include "modes/demo_world.hpp"
#include "modes/overworld.hpp"
#include "modes/tutorial_utils.hpp"
#include "network/network_config.hpp"
#include "online/request_manager.hpp"
#include "states_screens/addons_screen.hpp"
Expand Down Expand Up @@ -258,7 +259,7 @@ void MainMenuScreen::onUpdate(float delta)
virtual void onConfirm()
{
GUIEngine::ModalDialog::dismiss();
MainMenuScreen::getInstance()->startTutorial();
TutorialUtils::startTutorial();
} // onConfirm
}; // PlayTutorial

Expand All @@ -271,41 +272,6 @@ void MainMenuScreen::onUpdate(float delta)
#endif
} // onUpdate

// ----------------------------------------------------------------------------
void MainMenuScreen::startTutorial()
{
RaceManager::get()->setNumPlayers(1);
RaceManager::get()->setMajorMode (RaceManager::MAJOR_MODE_SINGLE);
RaceManager::get()->setMinorMode (RaceManager::MINOR_MODE_TUTORIAL);
RaceManager::get()->setNumKarts( 1 );
RaceManager::get()->setTrack("tutorial");
RaceManager::get()->setDifficulty(RaceManager::DIFFICULTY_EASY);
RaceManager::get()->setReverseTrack(false);

// Use the last used device
InputDevice* device = input_manager->getDeviceManager()->getLatestUsedDevice();

// Create player and associate player with device
StateManager::get()->createActivePlayer(PlayerManager::getCurrentPlayer(), device);

if (kart_properties_manager->getKart(UserConfigParams::m_default_kart) == NULL)
{
Log::warn("MainMenuScreen", "Cannot find kart '%s', will revert to default",
UserConfigParams::m_default_kart.c_str());
UserConfigParams::m_default_kart.revertToDefaults();
}
RaceManager::get()->setPlayerKart(0, UserConfigParams::m_default_kart);

// ASSIGN should make sure that only input from assigned devices is read
input_manager->getDeviceManager()->setAssignMode(ASSIGN);
input_manager->getDeviceManager()
->setSinglePlayer( StateManager::get()->getActivePlayer(0) );

StateManager::get()->enterGameState();
RaceManager::get()->setupPlayerKartInfo();
RaceManager::get()->startNew(false);
} // startTutorial

// ----------------------------------------------------------------------------

void MainMenuScreen::eventCallback(Widget* widget, const std::string& name,
Expand Down Expand Up @@ -509,7 +475,7 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name,
}
else if (selection == "startTutorial")
{
startTutorial();
TutorialUtils::startTutorial();
}
else if (selection == "story")
{
Expand Down
2 changes: 0 additions & 2 deletions src/states_screens/main_menu_screen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class MainMenuScreen : public GUIEngine::Screen, public GUIEngine::ScreenSinglet
core::stringw m_news_text;

MainMenuScreen();

void startTutorial();
public:
virtual void onUpdate(float delta) OVERRIDE;

Expand Down

0 comments on commit 2923a86

Please sign in to comment.