mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-23 15:52:55 +01:00
Fix openrct2-cli build
By using a dummy audio context, we can now make openrct2-cli start a headless instance without any SDL2 calls. SDL2 is still a dependency until we remove out the input code to openrct2-ui.
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
#include <openrct2/Context.h>
|
#include <openrct2/Context.h>
|
||||||
|
#include <openrct2/OpenRCT2.h>
|
||||||
|
|
||||||
using namespace OpenRCT2;
|
using namespace OpenRCT2;
|
||||||
|
|
||||||
@@ -23,8 +24,16 @@ using namespace OpenRCT2;
|
|||||||
*/
|
*/
|
||||||
int main(int argc, char * * argv)
|
int main(int argc, char * * argv)
|
||||||
{
|
{
|
||||||
IContext * context = CreateContext();
|
core_init();
|
||||||
int exitCode = context->RunOpenRCT2(argc, argv);
|
int runGame = cmdline_run((const char * *)argv, argc);
|
||||||
|
if (runGame == 1)
|
||||||
|
{
|
||||||
|
gOpenRCT2Headless = true;
|
||||||
|
|
||||||
|
// Run OpenRCT2 with a plain context
|
||||||
|
auto context = CreateContext();
|
||||||
|
context->RunOpenRCT2(argc, argv);
|
||||||
delete context;
|
delete context;
|
||||||
return exitCode;
|
}
|
||||||
|
return gExitCode;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,11 +38,20 @@ int main(int argc, char * * argv)
|
|||||||
core_init();
|
core_init();
|
||||||
int runGame = cmdline_run((const char * *)argv, argc);
|
int runGame = cmdline_run((const char * *)argv, argc);
|
||||||
if (runGame == 1)
|
if (runGame == 1)
|
||||||
|
{
|
||||||
|
if (gOpenRCT2Headless)
|
||||||
|
{
|
||||||
|
// Run OpenRCT2 with a plain context
|
||||||
|
auto context = CreateContext();
|
||||||
|
context->RunOpenRCT2(argc, argv);
|
||||||
|
delete context;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
// Run OpenRCT2 with a UI context
|
// Run OpenRCT2 with a UI context
|
||||||
IAudioContext * audioContext = CreateAudioContext();
|
auto audioContext = CreateAudioContext();
|
||||||
IUiContext * uiContext = gOpenRCT2Headless ? CreateDummyUiContext() : CreateUiContext();
|
auto uiContext = CreateUiContext();
|
||||||
IContext * context = CreateContext(audioContext, uiContext);
|
auto context = CreateContext(audioContext, uiContext);
|
||||||
|
|
||||||
context->RunOpenRCT2(argc, argv);
|
context->RunOpenRCT2(argc, argv);
|
||||||
|
|
||||||
@@ -50,5 +59,6 @@ int main(int argc, char * * argv)
|
|||||||
delete uiContext;
|
delete uiContext;
|
||||||
delete audioContext;
|
delete audioContext;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return gExitCode;
|
return gExitCode;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include <exception>
|
#include <exception>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "audio/AudioContext.h"
|
||||||
#include "Context.h"
|
#include "Context.h"
|
||||||
#include "ui/UiContext.h"
|
#include "ui/UiContext.h"
|
||||||
#include "core/Console.hpp"
|
#include "core/Console.hpp"
|
||||||
@@ -139,8 +140,7 @@ namespace OpenRCT2
|
|||||||
_finished = true;
|
_finished = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
bool Initialise() final override
|
||||||
bool Initialise()
|
|
||||||
{
|
{
|
||||||
#ifndef DISABLE_NETWORK
|
#ifndef DISABLE_NETWORK
|
||||||
gHashCTX = EVP_MD_CTX_create();
|
gHashCTX = EVP_MD_CTX_create();
|
||||||
@@ -233,6 +233,7 @@ namespace OpenRCT2
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
IPlatformEnvironment * SetupEnvironment()
|
IPlatformEnvironment * SetupEnvironment()
|
||||||
{
|
{
|
||||||
utf8 userPath[MAX_PATH];
|
utf8 userPath[MAX_PATH];
|
||||||
@@ -544,11 +545,30 @@ namespace OpenRCT2
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class PlainContext final : public Context
|
||||||
|
{
|
||||||
|
std::unique_ptr<IAudioContext> _audioContext;
|
||||||
|
std::unique_ptr<IUiContext> _uiContext;
|
||||||
|
|
||||||
|
public:
|
||||||
|
PlainContext()
|
||||||
|
: PlainContext(CreateDummyAudioContext(), CreateDummyUiContext())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PlainContext(IAudioContext * audioContext, IUiContext * uiContext)
|
||||||
|
: Context(audioContext, uiContext)
|
||||||
|
{
|
||||||
|
_audioContext = std::unique_ptr<IAudioContext>(audioContext);
|
||||||
|
_uiContext = std::unique_ptr<IUiContext>(uiContext);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Context * Context::Instance = nullptr;
|
Context * Context::Instance = nullptr;
|
||||||
|
|
||||||
IContext * CreateContext()
|
IContext * CreateContext()
|
||||||
{
|
{
|
||||||
return new Context(nullptr, nullptr);
|
return new PlainContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
IContext * CreateContext(Audio::IAudioContext * audioContext, IUiContext * uiContext)
|
IContext * CreateContext(Audio::IAudioContext * audioContext, IUiContext * uiContext)
|
||||||
|
|||||||
@@ -80,6 +80,8 @@ namespace OpenRCT2
|
|||||||
virtual Ui::IUiContext * GetUiContext() abstract;
|
virtual Ui::IUiContext * GetUiContext() abstract;
|
||||||
|
|
||||||
virtual sint32 RunOpenRCT2(int argc, char * * argv) abstract;
|
virtual sint32 RunOpenRCT2(int argc, char * * argv) abstract;
|
||||||
|
|
||||||
|
virtual bool Initialise() abstract;
|
||||||
virtual void Finish() abstract;
|
virtual void Finish() abstract;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -60,5 +60,7 @@ namespace OpenRCT2
|
|||||||
virtual void StopTitleMusic() abstract;
|
virtual void StopTitleMusic() abstract;
|
||||||
virtual void StopVehicleSounds() abstract;
|
virtual void StopVehicleSounds() abstract;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
IAudioContext * CreateDummyAudioContext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,6 +59,8 @@ void * Mixer_Play_Effect(size_t id, sint32 loop, sint32 volume, float pan, doubl
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
IAudioMixer * mixer = GetMixer();
|
IAudioMixer * mixer = GetMixer();
|
||||||
|
if (mixer != nullptr)
|
||||||
|
{
|
||||||
mixer->Lock();
|
mixer->Lock();
|
||||||
IAudioSource * source = mixer->GetSoundSource((sint32)id);
|
IAudioSource * source = mixer->GetSoundSource((sint32)id);
|
||||||
channel = mixer->Play(source, loop, deleteondone != 0, false);
|
channel = mixer->Play(source, loop, deleteondone != 0, false);
|
||||||
@@ -71,6 +73,7 @@ void * Mixer_Play_Effect(size_t id, sint32 loop, sint32 volume, float pan, doubl
|
|||||||
mixer->Unlock();
|
mixer->Unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return channel;
|
return channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
52
src/openrct2/audio/DummyAudioContext.cpp
Normal file
52
src/openrct2/audio/DummyAudioContext.cpp
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#pragma region Copyright (c) 2014-2017 OpenRCT2 Developers
|
||||||
|
/*****************************************************************************
|
||||||
|
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
|
||||||
|
*
|
||||||
|
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
|
||||||
|
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
|
||||||
|
*
|
||||||
|
* OpenRCT2 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.
|
||||||
|
*
|
||||||
|
* A full copy of the GNU General Public License can be found in licence.txt
|
||||||
|
*****************************************************************************/
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
|
#include "AudioContext.h"
|
||||||
|
|
||||||
|
namespace OpenRCT2 { namespace Audio
|
||||||
|
{
|
||||||
|
class DummyAudioContext final : public IAudioContext
|
||||||
|
{
|
||||||
|
IAudioMixer * GetMixer() override { return nullptr; }
|
||||||
|
|
||||||
|
std::vector<std::string> GetOutputDevices() override { return std::vector<std::string>(); }
|
||||||
|
void SetOutputDevice(const std::string &deviceName) override { }
|
||||||
|
|
||||||
|
IAudioSource * CreateStreamFromWAV(const std::string &path) override { return nullptr; }
|
||||||
|
|
||||||
|
void StartTitleMusic() override { }
|
||||||
|
|
||||||
|
IAudioChannel * PlaySound(sint32 soundId, sint32 volume, sint32 pan) override { return nullptr; }
|
||||||
|
IAudioChannel * PlaySoundAtLocation(sint32 soundId, sint16 x, sint16 y, sint16 z) override { return nullptr; }
|
||||||
|
IAudioChannel * PlaySoundPanned(sint32 soundId, sint32 pan, sint16 x, sint16 y, sint16 z) override { return nullptr; }
|
||||||
|
|
||||||
|
void ToggleAllSounds() override { }
|
||||||
|
void PauseSounds() override { }
|
||||||
|
void UnpauseSounds() override { }
|
||||||
|
|
||||||
|
void StopAll() override { }
|
||||||
|
void StopCrowdSound() override { }
|
||||||
|
void StopRainSound() override { }
|
||||||
|
void StopRideMusic() override { }
|
||||||
|
void StopTitleMusic() override { }
|
||||||
|
void StopVehicleSounds() override { }
|
||||||
|
};
|
||||||
|
|
||||||
|
IAudioContext * CreateDummyAudioContext()
|
||||||
|
{
|
||||||
|
return new DummyAudioContext();
|
||||||
|
}
|
||||||
|
} }
|
||||||
@@ -210,6 +210,11 @@ uint8 platform_get_currency_value(const char *currCode) {
|
|||||||
|
|
||||||
void core_init()
|
void core_init()
|
||||||
{
|
{
|
||||||
|
static bool initialised = false;
|
||||||
|
if (!initialised)
|
||||||
|
{
|
||||||
|
initialised = true;
|
||||||
|
|
||||||
bitcount_init();
|
bitcount_init();
|
||||||
|
|
||||||
#if defined(__APPLE__) && (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101200)
|
#if defined(__APPLE__) && (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101200)
|
||||||
@@ -220,3 +225,4 @@ void core_init()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user