Minor fixes

- 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
This commit is contained in:
Alayan 2024-05-21 21:35:41 +02:00
parent e165a5680b
commit 2923a86cd6
No known key found for this signature in database
8 changed files with 104 additions and 119 deletions

View File

@ -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")

View File

@ -160,7 +160,9 @@ public:
/** Returns the name of this player. */
const core::stringw& getName() const
{
#ifdef DEBUG
assert(m_magic_number == 0xABCD1234);
#endif
return m_local_name;
} // getName

View File

@ -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);
}
}

View File

@ -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

View File

@ -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"
@ -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>
@ -1016,7 +1011,6 @@ void World::updateWorld(int ticks)
assert(m_magic_number == 0xB01D6543);
#endif
if (m_schedule_pause)
{
pause(m_scheduled_pause_phase);
@ -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
{
@ -1123,6 +1084,7 @@ void World::updateWorld(int ticks)
void World::scheduleTutorial()
{
printf("Tutorial scheduled\n");
m_schedule_exit_race = true;
m_schedule_tutorial = true;
} // scheduleTutorial

View File

@ -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;
@ -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")
{

View File

@ -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"
@ -258,7 +259,7 @@ void MainMenuScreen::onUpdate(float delta)
virtual void onConfirm()
{
GUIEngine::ModalDialog::dismiss();
MainMenuScreen::getInstance()->startTutorial();
TutorialUtils::startTutorial();
} // onConfirm
}; // PlayTutorial
@ -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,
@ -509,7 +475,7 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name,
}
else if (selection == "startTutorial")
{
startTutorial();
TutorialUtils::startTutorial();
}
else if (selection == "story")
{

View File

@ -38,8 +38,6 @@ private:
core::stringw m_news_text;
MainMenuScreen();
void startTutorial();
public:
virtual void onUpdate(float delta) OVERRIDE;