Merge pull request #5542 from IntelOrca/fix-openrct2-cli

Fix openrct2-cli build
This commit is contained in:
Ted John 2017-06-04 00:41:55 +01:00 committed by GitHub
commit 96b9d6434c
9 changed files with 140 additions and 30 deletions

View File

@ -434,6 +434,8 @@
F76C88921EC539A300FA49E2 /* libopenrct2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F76C809A1EC4D9FA00FA49E2 /* libopenrct2.a */; };
F775F5341EE35A6B001F00E7 /* DummyUiContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F775F5331EE35A6B001F00E7 /* DummyUiContext.cpp */; };
F775F5351EE35A89001F00E7 /* DummyUiContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F775F5331EE35A6B001F00E7 /* DummyUiContext.cpp */; };
F775F5371EE3724F001F00E7 /* DummyAudioContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F775F5361EE3724F001F00E7 /* DummyAudioContext.cpp */; };
F775F5381EE3725C001F00E7 /* DummyAudioContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F775F5361EE3724F001F00E7 /* DummyAudioContext.cpp */; };
F7D7747B1EC5EB6D00BE6EBC /* lay_down_roller_coaster.c in Sources */ = {isa = PBXBuildFile; fileRef = F76C84951EC4E7CC00FA49E2 /* lay_down_roller_coaster.c */; };
F7D7747F1EC61E5100BE6EBC /* UiContext.macOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = F7D7747E1EC61E5100BE6EBC /* UiContext.macOS.mm */; };
F7D7748D1EC66F8600BE6EBC /* libopenrct2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F76C809A1EC4D9FA00FA49E2 /* libopenrct2.a */; };
@ -1323,6 +1325,7 @@
F76C85AF1EC4E82600FA49E2 /* UiContext.Win32.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = UiContext.Win32.cpp; sourceTree = "<group>"; };
F775F5321EE35A48001F00E7 /* Ui.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Ui.h; sourceTree = "<group>"; };
F775F5331EE35A6B001F00E7 /* DummyUiContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DummyUiContext.cpp; sourceTree = "<group>"; };
F775F5361EE3724F001F00E7 /* DummyAudioContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DummyAudioContext.cpp; sourceTree = "<group>"; };
F7D7747E1EC61E5100BE6EBC /* UiContext.macOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UiContext.macOS.mm; sourceTree = "<group>"; usesTabs = 0; };
F7D774841EC66CD700BE6EBC /* OpenRCT2-cli */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "OpenRCT2-cli"; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
@ -1768,6 +1771,7 @@
F76C83561EC4E7CC00FA49E2 /* audio */ = {
isa = PBXGroup;
children = (
F775F5361EE3724F001F00E7 /* DummyAudioContext.cpp */,
F76C83571EC4E7CC00FA49E2 /* audio.cpp */,
F76C83581EC4E7CC00FA49E2 /* audio.h */,
F76C83591EC4E7CC00FA49E2 /* AudioChannel.h */,
@ -2924,6 +2928,7 @@
F775F5341EE35A6B001F00E7 /* DummyUiContext.cpp in Sources */,
F76C887F1EC5324E00FA49E2 /* CopyFramebufferShader.cpp in Sources */,
F76C88801EC5324E00FA49E2 /* DrawImageShader.cpp in Sources */,
F775F5371EE3724F001F00E7 /* DummyAudioContext.cpp in Sources */,
F76C88811EC5324E00FA49E2 /* DrawLineShader.cpp in Sources */,
F76C88821EC5324E00FA49E2 /* FillRectShader.cpp in Sources */,
F76C88831EC5324E00FA49E2 /* OpenGLAPI.cpp in Sources */,
@ -2945,6 +2950,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
F775F5381EE3725C001F00E7 /* DummyAudioContext.cpp in Sources */,
F775F5351EE35A89001F00E7 /* DummyUiContext.cpp in Sources */,
F7D7747B1EC5EB6D00BE6EBC /* lay_down_roller_coaster.c in Sources */,
F76C85B01EC4E88300FA49E2 /* audio.cpp in Sources */,

View File

@ -15,6 +15,7 @@
#pragma endregion
#include <openrct2/Context.h>
#include <openrct2/OpenRCT2.h>
using namespace OpenRCT2;
@ -23,8 +24,16 @@ using namespace OpenRCT2;
*/
int main(int argc, char * * argv)
{
IContext * context = CreateContext();
int exitCode = context->RunOpenRCT2(argc, argv);
delete context;
return exitCode;
core_init();
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;
}
return gExitCode;
}

View File

@ -39,16 +39,26 @@ int main(int argc, char * * argv)
int runGame = cmdline_run((const char * *)argv, argc);
if (runGame == 1)
{
// Run OpenRCT2 with a UI context
IAudioContext * audioContext = CreateAudioContext();
IUiContext * uiContext = gOpenRCT2Headless ? CreateDummyUiContext() : CreateUiContext();
IContext * context = CreateContext(audioContext, uiContext);
if (gOpenRCT2Headless)
{
// Run OpenRCT2 with a plain context
auto context = CreateContext();
context->RunOpenRCT2(argc, argv);
delete context;
}
else
{
// Run OpenRCT2 with a UI context
auto audioContext = CreateAudioContext();
auto uiContext = CreateUiContext();
auto context = CreateContext(audioContext, uiContext);
context->RunOpenRCT2(argc, argv);
context->RunOpenRCT2(argc, argv);
delete context;
delete uiContext;
delete audioContext;
delete context;
delete uiContext;
delete audioContext;
}
}
return gExitCode;
}

View File

@ -17,6 +17,7 @@
#include <exception>
#include <memory>
#include <string>
#include "audio/AudioContext.h"
#include "Context.h"
#include "ui/UiContext.h"
#include "core/Console.hpp"
@ -139,8 +140,7 @@ namespace OpenRCT2
_finished = true;
}
private:
bool Initialise()
bool Initialise() final override
{
#ifndef DISABLE_NETWORK
gHashCTX = EVP_MD_CTX_create();
@ -233,6 +233,7 @@ namespace OpenRCT2
return true;
}
private:
IPlatformEnvironment * SetupEnvironment()
{
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;
IContext * CreateContext()
{
return new Context(nullptr, nullptr);
return new PlainContext();
}
IContext * CreateContext(Audio::IAudioContext * audioContext, IUiContext * uiContext)

View File

@ -80,6 +80,8 @@ namespace OpenRCT2
virtual Ui::IUiContext * GetUiContext() abstract;
virtual sint32 RunOpenRCT2(int argc, char * * argv) abstract;
virtual bool Initialise() abstract;
virtual void Finish() abstract;
};

View File

@ -60,5 +60,7 @@ namespace OpenRCT2
virtual void StopTitleMusic() abstract;
virtual void StopVehicleSounds() abstract;
};
IAudioContext * CreateDummyAudioContext();
}
}

View File

@ -59,16 +59,19 @@ void * Mixer_Play_Effect(size_t id, sint32 loop, sint32 volume, float pan, doubl
else
{
IAudioMixer * mixer = GetMixer();
mixer->Lock();
IAudioSource * source = mixer->GetSoundSource((sint32)id);
channel = mixer->Play(source, loop, deleteondone != 0, false);
if (channel != nullptr)
if (mixer != nullptr)
{
channel->SetVolume(volume);
channel->SetPan(pan);
channel->SetRate(rate);
mixer->Lock();
IAudioSource * source = mixer->GetSoundSource((sint32)id);
channel = mixer->Play(source, loop, deleteondone != 0, false);
if (channel != nullptr)
{
channel->SetVolume(volume);
channel->SetPan(pan);
channel->SetRate(rate);
}
mixer->Unlock();
}
mixer->Unlock();
}
}
return channel;

View 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();
}
} }

View File

@ -210,13 +210,19 @@ uint8 platform_get_currency_value(const char *currCode) {
void core_init()
{
bitcount_init();
static bool initialised = false;
if (!initialised)
{
initialised = true;
bitcount_init();
#if defined(__APPLE__) && (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101200)
kern_return_t ret = mach_timebase_info(&_mach_base_info);
if (ret != 0) {
log_fatal("Unable to get mach_timebase_info.");
exit(-1);
}
kern_return_t ret = mach_timebase_info(&_mach_base_info);
if (ret != 0) {
log_fatal("Unable to get mach_timebase_info.");
exit(-1);
}
#endif
}
}