Skip to content

Commit

Permalink
Merge pull request #125 from thearst3rd/autosplitter
Browse files Browse the repository at this point in the history
Add support for autosplitters
  • Loading branch information
thearst3rd authored Jun 20, 2022
2 parents 2f56c51 + 6dc385c commit 230e2e9
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 0 deletions.
72 changes: 72 additions & 0 deletions engine/source/autosplitter/autosplitter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include <cstdio>

#include "autosplitter.h"
#include "platform/platform.h"


Autosplitter *Autosplitter::smInstance = nullptr;

void Autosplitter::init()
{
if (smInstance)
return;

smInstance = new Autosplitter();
}

void Autosplitter::destroy()
{
if (!smInstance)
return;

delete smInstance;
smInstance = nullptr;
}

Autosplitter *Autosplitter::get()
{
if (!smInstance)
init();

return smInstance;
}

Autosplitter::Autosplitter()
{
mActive = false;
mFilename = Platform::getPrefsPath(AUTOSPLITTER_FILE_NAME);
mFile.open(mFilename, std::ios_base::app);
if (!mFile.is_open())
{
Con::errorf("Failed to open autosplitter file %s.", mFilename);
Con::errorf("Autosplitter is disabled.");
return;
}
Con::printf("Autosplitter Initialized to file %s", mFilename.c_str());
mActive = true;
}

Autosplitter::~Autosplitter()
{
mFile.close();
std::remove(mFilename.c_str());
}

void Autosplitter::sendData(const char *data)
{
if (!mActive)
return;

mFile << data << std::endl;
}

ConsoleFunction(sendAutosplitterData, void, 2, 2, "")
{
Autosplitter *autosplitter = Autosplitter::get();
if (!autosplitter->isActive())
return;

Con::printf("Sending autosplitter message '%s'", argv[1]);

autosplitter->sendData(argv[1]);
}
29 changes: 29 additions & 0 deletions engine/source/autosplitter/autosplitter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef _AUTOSPLITTER_H_
#define _AUTOSPLITTER_H_

#include <iostream>
#include <fstream>

#include "console/console.h"

constexpr const char *AUTOSPLITTER_FILE_NAME = "autosplitter.txt";
constexpr U32 AUTOSPLITTER_BUF_SIZE = 512;

class Autosplitter
{
public:
static void init();
static void destroy();
static Autosplitter *get();
bool isActive() { return mActive; }
void sendData(const char *data);
private:
Autosplitter();
~Autosplitter();
static Autosplitter *smInstance;
bool mActive;
std::string mFilename;
std::fstream mFile;
};

#endif // _AUTOSPLITTER_H_
5 changes: 5 additions & 0 deletions engine/source/game/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@

#include "lightingSystem/sgFormatManager.h"
#include "sfx/sfxSystem.h"
#include "autosplitter/autosplitter.h"

#ifndef BUILD_TOOLS
DemoGame GameObject;
Expand Down Expand Up @@ -188,6 +189,8 @@ static bool initLibraries()
RedBook::init();
SFXSystem::init();

Autosplitter::init();

return true;
}

Expand All @@ -200,6 +203,8 @@ static void shutdownLibraries()
if (ResourceManager)
ResourceManager->purge();

Autosplitter::destroy();

RedBook::destroy();
TSShapeInstance::destroy();
InteriorInstance::destroy();
Expand Down
2 changes: 2 additions & 0 deletions game/MBU.torsion.exports
Original file line number Diff line number Diff line change
Expand Up @@ -7895,6 +7895,8 @@ Valid inputs for xRumble/yRumble are [0 - 1].</desc>
<desc>Take a screenshot.

@param format One of JPEG or PNG.</desc>
</function>
<function> <name>sendAutosplitterData</name>
</function>
<function> <name>setClipboard</name>
<args>string text</args>
Expand Down
3 changes: 3 additions & 0 deletions game/marble/client/scripts/game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,9 @@ function clientCmdSetGameState(%state, %data)
{
$GameEndUserName = XBLiveGetUserName();
$GameEndNoAllowPause = true;

// Tell autosplitter we finished the level
sendAutosplitterData("finish" SPC GameMissionInfo.getCurrentMission().level);
}
else
$GameEndNoAllowPause = false;
Expand Down
2 changes: 2 additions & 0 deletions game/marble/client/scripts/playGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
%isFreeLevel = (%levelPlaying == $PDLC::MapPack0LevelStart);
UpsellGui.displayPDLCUpsell = %isFreeLevel ? false : !%hasLevel;
}

sendAutosplitterData("loading finished");
}

function PlayGui::show(%this)
Expand Down
4 changes: 4 additions & 0 deletions game/marble/client/ui/LevelPreviewGui.gui
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ function levelPreviewGui::onA()

// Create a new server
loadMission(GameMissionInfo.getCurrentMission().file, true);

// Tell autosplitter to start
sendAutosplitterData("start" SPC GameMissionInfo.getCurrentMission().level);
sendAutosplitterData("loading started");
}
else
{
Expand Down
2 changes: 2 additions & 0 deletions game/marble/server/scripts/easter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ function clientCmdOnEasterEggPickup( %index )
return;
}

sendAutosplitterData("egg" SPC %index);

if( hasFoundEgg( %index ) )
{
serverPlay2d(easterNotNewSfx);
Expand Down
1 change: 1 addition & 0 deletions tools/cmake/marbleblast.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ endif()
# Always enabled paths first
###############################################################################
addPath("${srcDir}/") # must come first :)
addPath("${srcDir}/autosplitter")
addPath("${srcDir}/collision")
addPath("${srcDir}/console")
addPath("${srcDir}/core")
Expand Down

0 comments on commit 230e2e9

Please sign in to comment.