Skip to content

Commit

Permalink
Remove GameSessionRecorder (SuperTux#2755)
Browse files Browse the repository at this point in the history
Removal reasons:

* It can be coded better as a whole, utilizing features like PhysFS file reading/writing using `ReaderMapping`/`Writer` (would also prevent security issues, like SuperTux#2398).
* It is made very hidden from the regular user.
* I have personally never seen anyone use this feature, or have interest in it. I also do not see any practical use for it currently, other than for TAS-es (tool-assisted speedruns), but for that purpose, there is already special software which can do much more and is better suited for that purpose, like libTAS.

Closes SuperTux#2398.
  • Loading branch information
Vankata453 committed Feb 11, 2024
1 parent c215a35 commit 9b4eaee
Show file tree
Hide file tree
Showing 13 changed files with 5 additions and 395 deletions.
26 changes: 0 additions & 26 deletions src/scripting/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,32 +459,6 @@ void set_game_speed(float speed)
::g_debug.set_game_speed_multiplier(speed);
}

void record_demo(const std::string& filename)
{
if (GameSession::current() == nullptr)
{
log_info << "No game session." << std::endl;
return;
}
GameSession::current()->restart_level();
GameSession::current()->record_demo(filename);
}

void play_demo(const std::string& filename)
{
auto session = GameSession::current();
if (session == nullptr)
{
log_info << "No game session." << std::endl;
return;
}
// Reset random seed.
g_config->random_seed = session->get_demo_random_seed(filename);
gameRandom.seed(g_config->random_seed);
session->restart_level();
session->play_demo(filename);
}

void set_title_frame(const std::string& image)
{
auto title_screen = TitleScreen::current();
Expand Down
12 changes: 0 additions & 12 deletions src/scripting/functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,18 +289,6 @@ void set_gamma(float gamma);
*/
int rand();

/**
* Records a demo to the given file.
* @param string $filename
*/
void record_demo(const std::string& filename);

/**
* Plays back a demo from the given file.
* @param string $filename
*/
void play_demo(const std::string& filename);

/**
* Sets the frame, displayed on the title screen.
* @param string $image
Expand Down
60 changes: 0 additions & 60 deletions src/scripting/wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12973,52 +12973,6 @@ static SQInteger rand_wrapper(HSQUIRRELVM vm)

}

static SQInteger record_demo_wrapper(HSQUIRRELVM vm)
{
const SQChar* arg0;
if(SQ_FAILED(sq_getstring(vm, 2, &arg0))) {
sq_throwerror(vm, _SC("Argument 1 not a string"));
return SQ_ERROR;
}

try {
scripting::record_demo(arg0);

return 0;

} catch(std::exception& e) {
sq_throwerror(vm, e.what());
return SQ_ERROR;
} catch(...) {
sq_throwerror(vm, _SC("Unexpected exception while executing function 'record_demo'"));
return SQ_ERROR;
}

}

static SQInteger play_demo_wrapper(HSQUIRRELVM vm)
{
const SQChar* arg0;
if(SQ_FAILED(sq_getstring(vm, 2, &arg0))) {
sq_throwerror(vm, _SC("Argument 1 not a string"));
return SQ_ERROR;
}

try {
scripting::play_demo(arg0);

return 0;

} catch(std::exception& e) {
sq_throwerror(vm, e.what());
return SQ_ERROR;
} catch(...) {
sq_throwerror(vm, _SC("Unexpected exception while executing function 'play_demo'"));
return SQ_ERROR;
}

}

static SQInteger set_title_frame_wrapper(HSQUIRRELVM vm)
{
const SQChar* arg0;
Expand Down Expand Up @@ -14535,20 +14489,6 @@ void register_supertux_wrapper(HSQUIRRELVM v)
throw SquirrelError(v, "Couldn't register function 'rand'");
}

sq_pushstring(v, "record_demo", -1);
sq_newclosure(v, &record_demo_wrapper, 0);
sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, ".s");
if(SQ_FAILED(sq_createslot(v, -3))) {
throw SquirrelError(v, "Couldn't register function 'record_demo'");
}

sq_pushstring(v, "play_demo", -1);
sq_newclosure(v, &play_demo_wrapper, 0);
sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, ".s");
if(SQ_FAILED(sq_createslot(v, -3))) {
throw SquirrelError(v, "Couldn't register function 'play_demo'");
}

sq_pushstring(v, "set_title_frame", -1);
sq_newclosure(v, &set_title_frame_wrapper, 0);
sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, ".s");
Expand Down
30 changes: 0 additions & 30 deletions src/supertux/command_line_arguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ CommandLineArguments::CommandLineArguments() :
music_enabled(),
filenames(),
enable_script_debugger(),
start_demo(),
record_demo(),
tux_spawn_pos(),
sector(),
spawnpoint(),
Expand Down Expand Up @@ -125,10 +123,6 @@ CommandLineArguments::print_help(const char* arg0) const
<< _(" --sector SECTOR Spawn Tux in SECTOR\n") << "\n"
<< _(" --spawnpoint SPAWNPOINT Spawn Tux at SPAWNPOINT\n") << "\n"
<< "\n"
<< _("Demo Recording Options:") << "\n"
<< _(" --record-demo FILE LEVEL Record a demo to FILE") << "\n"
<< _(" --play-demo FILE LEVEL Play a recorded demo") << "\n"
<< "\n"
<< _("Directory Options:") << "\n"
<< _(" --datadir DIR Set the directory for the games datafiles") << "\n"
<< _(" --userdir DIR Set the directory for user data (savegames, etc.)") << "\n"
Expand Down Expand Up @@ -319,28 +313,6 @@ CommandLineArguments::parse_args(int argc, char** argv)
{
music_enabled = false;
}
else if (arg == "--play-demo")
{
if (i + 1 >= argc)
{
throw std::runtime_error("Need to specify a demo filename");
}
else
{
start_demo = argv[++i];
}
}
else if (arg == "--record-demo")
{
if (i + 1 >= argc)
{
throw std::runtime_error("Need to specify a demo filename");
}
else
{
record_demo = argv[++i];
}
}
else if (arg == "--spawn-pos")
{
Vector spawn_pos(0.0f, 0.0f);
Expand Down Expand Up @@ -427,8 +399,6 @@ CommandLineArguments::merge_into(Config& config)
merge_option(sound_enabled)
merge_option(music_enabled)
merge_option(enable_script_debugger)
merge_option(start_demo)
merge_option(record_demo)
merge_option(tux_spawn_pos)
merge_option(developer_mode)
merge_option(christmas_mode)
Expand Down
2 changes: 0 additions & 2 deletions src/supertux/command_line_arguments.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ class CommandLineArguments final

std::vector<std::string> filenames;
std::optional<bool> enable_script_debugger;
std::optional<std::string> start_demo;
std::optional<std::string> record_demo;
std::optional<Vector> tux_spawn_pos;
std::optional<std::string> sector;
std::optional<std::string> spawnpoint;
Expand Down
8 changes: 0 additions & 8 deletions src/supertux/game_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@

GameSession::GameSession(const std::string& levelfile_, Savegame& savegame, Statistics* statistics,
bool preserve_music) :
GameSessionRecorder(),
reset_button(false),
reset_checkpoint_button(false),
m_prevent_death(false),
Expand Down Expand Up @@ -234,8 +233,6 @@ GameSession::restart_level(bool after_death, bool preserve_music)
it++;
}

start_recording();

return (0);
}

Expand Down Expand Up @@ -446,8 +443,6 @@ GameSession::update(float dt_sec, const Controller& controller)
// design choice, if you prefer it not to animate when paused, add `if (!m_game_pause)`).
m_level->m_stats.update_timers(dt_sec);

process_events();

// Unpause the game if the menu has been closed.
if (m_game_pause && !MenuManager::instance().is_active()) {
ScreenManager::current()->set_speed(m_speed_before_pause);
Expand Down Expand Up @@ -480,9 +475,6 @@ GameSession::update(float dt_sec, const Controller& controller)
m_currentsector = sector;
m_currentsector->play_looping_sounds();

if (is_playing_demo())
reset_demo_controller();

m_newsector = "";
m_newspawnpoint = "";
}
Expand Down
7 changes: 3 additions & 4 deletions src/supertux/game_session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#ifndef HEADER_SUPERTUX_SUPERTUX_GAME_SESSION_HPP
#define HEADER_SUPERTUX_SUPERTUX_GAME_SESSION_HPP

#include "supertux/screen.hpp"
#include "util/currenton.hpp"

#include <memory>
#include <unordered_map>
#include <vector>
Expand All @@ -27,12 +30,9 @@
#include "squirrel/squirrel_scheduler.hpp"
#include "squirrel/squirrel_util.hpp"
#include "supertux/game_object.hpp"
#include "supertux/game_session_recorder.hpp"
#include "supertux/player_status.hpp"
#include "supertux/screen.hpp"
#include "supertux/sequence.hpp"
#include "supertux/timer.hpp"
#include "util/currenton.hpp"
#include "video/surface_ptr.hpp"

class CodeController;
Expand All @@ -46,7 +46,6 @@ class Savegame;

/** Screen that runs a Level, where Players run and jump through Sectors. */
class GameSession final : public Screen,
public GameSessionRecorder,
public Currenton<GameSession>
{
private:
Expand Down
Loading

0 comments on commit 9b4eaee

Please sign in to comment.