mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
attempt to run server in a separate app
partially reverts 3258f8bb40487e3731bf452dbda1add6294ff4b2
This commit is contained in:
parent
26a1cc5b73
commit
e72e5cea6f
@ -49,6 +49,10 @@
|
|||||||
<key>NSAllowsArbitraryLoads</key>
|
<key>NSAllowsArbitraryLoads</key>
|
||||||
<true/>
|
<true/>
|
||||||
</dict>
|
</dict>
|
||||||
|
<key>UIBackgroundModes</key>
|
||||||
|
<array>
|
||||||
|
<string>audio</string>
|
||||||
|
</array>
|
||||||
<key>UIDeviceFamily</key>
|
<key>UIDeviceFamily</key>
|
||||||
<array>
|
<array>
|
||||||
<integer>1</integer>
|
<integer>1</integer>
|
||||||
|
@ -177,9 +177,7 @@ if(WIN32)
|
|||||||
target_compile_definitions(vcmiclient PRIVATE WINDOWS_IGNORE_PACKING_MISMATCH)
|
target_compile_definitions(vcmiclient PRIVATE WINDOWS_IGNORE_PACKING_MISMATCH)
|
||||||
elseif(APPLE_IOS)
|
elseif(APPLE_IOS)
|
||||||
target_link_libraries(vcmiclient PRIVATE
|
target_link_libraries(vcmiclient PRIVATE
|
||||||
vcmiserver
|
"-framework Foundation -framework UIKit -framework QuartzCore -framework CoreGraphics -framework CoreServices -framework ImageIO" # SDL2_image
|
||||||
# SDL2_image:
|
|
||||||
"-framework Foundation -framework UIKit -framework QuartzCore -framework CoreGraphics -framework CoreServices -framework ImageIO"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
target_sources(vcmiclient PRIVATE ${CMAKE_SOURCE_DIR}/client/LaunchScreen.storyboard)
|
target_sources(vcmiclient PRIVATE ${CMAKE_SOURCE_DIR}/client/LaunchScreen.storyboard)
|
||||||
|
@ -24,8 +24,7 @@
|
|||||||
#ifdef VCMI_ANDROID
|
#ifdef VCMI_ANDROID
|
||||||
#include "../lib/CAndroidVMHelper.h"
|
#include "../lib/CAndroidVMHelper.h"
|
||||||
#elif defined(VCMI_IOS)
|
#elif defined(VCMI_IOS)
|
||||||
#include "../server/CVCMIServer.h"
|
//TODO
|
||||||
// todo ios
|
|
||||||
#else
|
#else
|
||||||
#include "../lib/Interprocess.h"
|
#include "../lib/Interprocess.h"
|
||||||
#endif
|
#endif
|
||||||
@ -185,18 +184,7 @@ void CServerHandler::startLocalServerAndConnect()
|
|||||||
envHelper.callStaticVoidMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "startServer", true);
|
envHelper.callStaticVoidMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "startServer", true);
|
||||||
}
|
}
|
||||||
#elif defined(VCMI_IOS)
|
#elif defined(VCMI_IOS)
|
||||||
// todo ios: hide keyboard
|
// TODO
|
||||||
logNetwork->info("[ios] create server thread");
|
|
||||||
boost::condition_variable cond;
|
|
||||||
threadRunLocalServer = std::make_shared<boost::thread>([&cond, this] {
|
|
||||||
setThreadName("CVCMIServer");
|
|
||||||
CVCMIServer::create(&cond);
|
|
||||||
// todo ios copypaste
|
|
||||||
threadRunLocalServer.reset();
|
|
||||||
CSH->campaignServerRestartLock.setn(false);
|
|
||||||
});
|
|
||||||
// threadRunLocalServer->detach();
|
|
||||||
logNetwork->info("[ios] detach server thread");
|
|
||||||
#else
|
#else
|
||||||
threadRunLocalServer = std::make_shared<boost::thread>(&CServerHandler::threadRunServer, this); //runs server executable;
|
threadRunLocalServer = std::make_shared<boost::thread>(&CServerHandler::threadRunServer, this); //runs server executable;
|
||||||
#endif
|
#endif
|
||||||
@ -214,14 +202,7 @@ void CServerHandler::startLocalServerAndConnect()
|
|||||||
logNetwork->info("waiting for server finished...");
|
logNetwork->info("waiting for server finished...");
|
||||||
androidTestServerReadyFlag = false;
|
androidTestServerReadyFlag = false;
|
||||||
#elif defined(VCMI_IOS)
|
#elif defined(VCMI_IOS)
|
||||||
// todo ios
|
//TODO
|
||||||
{
|
|
||||||
boost::mutex m;
|
|
||||||
boost::unique_lock<boost::mutex> lock{m};
|
|
||||||
logNetwork->info("[ios] wait for server");
|
|
||||||
cond.wait(lock);
|
|
||||||
logNetwork->info("[ios] server ready");
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
if(shm)
|
if(shm)
|
||||||
shm->sr->waitTillReady();
|
shm->sr->waitTillReady();
|
||||||
|
@ -391,7 +391,6 @@ class VCMIDirsIOS final : public VCMIDirsApple
|
|||||||
bfs::path libraryPath() const override;
|
bfs::path libraryPath() const override;
|
||||||
boost::filesystem::path fullLibraryPath(const std::string & desiredFolder, const std::string & baseLibName) const override;
|
boost::filesystem::path fullLibraryPath(const std::string & desiredFolder, const std::string & baseLibName) const override;
|
||||||
bfs::path binaryPath() const override;
|
bfs::path binaryPath() const override;
|
||||||
bfs::path serverPath() const override;
|
|
||||||
|
|
||||||
bool developmentMode() const override;
|
bool developmentMode() const override;
|
||||||
};
|
};
|
||||||
@ -431,7 +430,6 @@ boost::filesystem::path VCMIDirsIOS::fullLibraryPath(const std::string & desired
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
bfs::path VCMIDirsIOS::binaryPath() const { return {ios_bundlePath()}; }
|
bfs::path VCMIDirsIOS::binaryPath() const { return {ios_bundlePath()}; }
|
||||||
bfs::path VCMIDirsIOS::serverPath() const { return clientPath(); }
|
|
||||||
|
|
||||||
bool VCMIDirsIOS::developmentMode() const { return false; }
|
bool VCMIDirsIOS::developmentMode() const { return false; }
|
||||||
#elif defined(VCMI_MAC)
|
#elif defined(VCMI_MAC)
|
||||||
|
@ -2,18 +2,20 @@
|
|||||||
|
|
||||||
pushd bin/Debug
|
pushd bin/Debug
|
||||||
mkdir -p vcmiclient.app/Frameworks
|
mkdir -p vcmiclient.app/Frameworks
|
||||||
cp *.dylib AI/*.dylib vcmiclient.app
|
|
||||||
badInstallNamePrefix=$(pwd)
|
|
||||||
cd vcmiclient.app
|
|
||||||
|
|
||||||
|
productsDir=$(pwd)
|
||||||
sdl2Path=~/dev/ios/vcmi-ios-deps/SDL2-lib/lib
|
sdl2Path=~/dev/ios/vcmi-ios-deps/SDL2-lib/lib
|
||||||
cp "$sdl2Path/libSDL2.dylib" .
|
for app in vcmiclient vcmiserver; do
|
||||||
install_name_tool -rpath "$sdl2Path" '@executable_path/Frameworks' vcmiclient
|
install_name_tool -rpath "$sdl2Path" '@executable_path/Frameworks' "$productsDir/$app.app/$app"
|
||||||
|
done
|
||||||
|
|
||||||
|
cp *.dylib AI/*.dylib "$sdl2Path/libSDL2.dylib" vcmiclient.app
|
||||||
|
cd vcmiclient.app
|
||||||
|
|
||||||
for b in vcmiclient *.dylib; do
|
for b in vcmiclient *.dylib; do
|
||||||
for l in minizip vcmi; do
|
for l in minizip vcmi; do
|
||||||
libName="lib${l}.dylib"
|
libName="lib${l}.dylib"
|
||||||
install_name_tool -change "$badInstallNamePrefix/$libName" "@rpath/$libName" "$b"
|
install_name_tool -change "$productsDir/$libName" "@rpath/$libName" "$b"
|
||||||
done
|
done
|
||||||
if [ "$b" != vcmiclient ]; then
|
if [ "$b" != vcmiclient ]; then
|
||||||
install_name_tool -id "@rpath/$b" "$b"
|
install_name_tool -id "@rpath/$b" "$b"
|
||||||
@ -23,5 +25,15 @@ done
|
|||||||
mv -f *.dylib Frameworks
|
mv -f *.dylib Frameworks
|
||||||
popd
|
popd
|
||||||
|
|
||||||
cp -f ../vcmi/Info.plist "$badInstallNamePrefix/vcmiclient.app"
|
for app in vcmiclient vcmiserver; do
|
||||||
cp -R bin/Debug-iphoneos/* "$badInstallNamePrefix/vcmiclient.app"
|
cp -f ../vcmi/Info.plist "$productsDir/$app.app"
|
||||||
|
done
|
||||||
|
sed -i '' -e 's/client/server/g' -e 's/>VCMI</>VCMI server</' "$productsDir/vcmiserver.app/Info.plist"
|
||||||
|
|
||||||
|
cp -R bin/Debug-iphoneos/* "$productsDir/vcmiclient.app"
|
||||||
|
cp -fR "$productsDir/vcmiclient.app/Frameworks" "$productsDir/vcmiserver.app"
|
||||||
|
|
||||||
|
for l in minizip vcmi; do
|
||||||
|
libName="lib${l}.dylib"
|
||||||
|
install_name_tool -change "$productsDir/$libName" "@rpath/$libName" "$productsDir/vcmiserver.app/vcmiserver"
|
||||||
|
done
|
||||||
|
@ -16,21 +16,23 @@ set(server_HEADERS
|
|||||||
CVCMIServer.h
|
CVCMIServer.h
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(APPLE_IOS)
|
||||||
|
set(server_SRCS ${server_SRCS} main_ios.mm)
|
||||||
|
endif(APPLE_IOS)
|
||||||
|
|
||||||
assign_source_group(${server_SRCS} ${server_HEADERS})
|
assign_source_group(${server_SRCS} ${server_HEADERS})
|
||||||
|
|
||||||
if(ANDROID) # android needs client/server to be libraries, not executables, so we can't reuse the build part of this script
|
if(ANDROID) # android needs client/server to be libraries, not executables, so we can't reuse the build part of this script
|
||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(APPLE_IOS)
|
|
||||||
add_library(vcmiserver STATIC ${server_SRCS} ${server_HEADERS})
|
|
||||||
else()
|
|
||||||
add_executable(vcmiserver ${server_SRCS} ${server_HEADERS})
|
add_executable(vcmiserver ${server_SRCS} ${server_HEADERS})
|
||||||
endif()
|
|
||||||
|
|
||||||
set(server_LIBS vcmi)
|
set(server_LIBS vcmi)
|
||||||
if(CMAKE_SYSTEM_NAME MATCHES FreeBSD)
|
if(CMAKE_SYSTEM_NAME MATCHES FreeBSD)
|
||||||
set(server_LIBS execinfo ${server_LIBS})
|
set(server_LIBS execinfo ${server_LIBS})
|
||||||
|
elseif(APPLE_IOS)
|
||||||
|
set(server_LIBS ${server_LIBS} "-framework UIKit -framework AVFoundation")
|
||||||
endif()
|
endif()
|
||||||
target_link_libraries(vcmiserver PRIVATE ${server_LIBS} minizip::minizip)
|
target_link_libraries(vcmiserver PRIVATE ${server_LIBS} minizip::minizip)
|
||||||
|
|
||||||
@ -44,6 +46,10 @@ if(WIN32)
|
|||||||
OUTPUT_NAME "VCMI_server"
|
OUTPUT_NAME "VCMI_server"
|
||||||
PROJECT_LABEL "VCMI_server"
|
PROJECT_LABEL "VCMI_server"
|
||||||
)
|
)
|
||||||
|
elseif(APPLE_IOS)
|
||||||
|
# TODO: move to a common dir / add macro?
|
||||||
|
target_sources(vcmiclient PRIVATE ${CMAKE_SOURCE_DIR}/client/LaunchScreen.storyboard)
|
||||||
|
set_source_files_properties(${CMAKE_SOURCE_DIR}/client/LaunchScreen.storyboard PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
vcmi_set_output_dir(vcmiserver "")
|
vcmi_set_output_dir(vcmiserver "")
|
||||||
|
@ -114,8 +114,8 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string SERVER_NAME_AFFIX = "server";
|
std::string NAME_AFFIX = "server";
|
||||||
std::string SERVER_NAME = GameConstants::VCMI_VERSION + std::string(" (") + SERVER_NAME_AFFIX + ')';
|
std::string NAME = GameConstants::VCMI_VERSION + std::string(" (") + NAME_AFFIX + ')';
|
||||||
|
|
||||||
CVCMIServer::CVCMIServer(boost::program_options::variables_map & opts)
|
CVCMIServer::CVCMIServer(boost::program_options::variables_map & opts)
|
||||||
: port(3030), io(std::make_shared<boost::asio::io_service>()), state(EServerState::LOBBY), cmdLineOptions(opts), currentClientId(1), currentPlayerId(1), restartGameplay(false)
|
: port(3030), io(std::make_shared<boost::asio::io_service>()), state(EServerState::LOBBY), cmdLineOptions(opts), currentClientId(1), currentPlayerId(1), restartGameplay(false)
|
||||||
@ -293,7 +293,7 @@ void CVCMIServer::connectionAccepted(const boost::system::error_code & ec)
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
logNetwork->info("We got a new connection! :)");
|
logNetwork->info("We got a new connection! :)");
|
||||||
auto c = std::make_shared<CConnection>(upcomingConnection, SERVER_NAME, uuid);
|
auto c = std::make_shared<CConnection>(upcomingConnection, NAME, uuid);
|
||||||
upcomingConnection.reset();
|
upcomingConnection.reset();
|
||||||
connections.insert(c);
|
connections.insert(c);
|
||||||
c->handler = std::make_shared<boost::thread>(&CVCMIServer::threadHandleClient, this, c);
|
c->handler = std::make_shared<boost::thread>(&CVCMIServer::threadHandleClient, this, c);
|
||||||
@ -920,14 +920,9 @@ int main(int argc, char * argv[])
|
|||||||
console = new CConsoleHandler();
|
console = new CConsoleHandler();
|
||||||
CBasicLogConfigurator logConfig(VCMIDirs::get().userLogsPath() / "VCMI_Server_log.txt", console);
|
CBasicLogConfigurator logConfig(VCMIDirs::get().userLogsPath() / "VCMI_Server_log.txt", console);
|
||||||
logConfig.configureDefault();
|
logConfig.configureDefault();
|
||||||
logGlobal->info(SERVER_NAME);
|
logGlobal->info(NAME);
|
||||||
|
|
||||||
boost::program_options::variables_map opts;
|
boost::program_options::variables_map opts;
|
||||||
#ifdef VCMI_IOS
|
|
||||||
argc = 1;
|
|
||||||
boost::condition_variable * cond = reinterpret_cast<boost::condition_variable *>(argv[1]);
|
|
||||||
cond->notify_one();
|
|
||||||
#else
|
|
||||||
handleCommandOptions(argc, argv, opts);
|
handleCommandOptions(argc, argv, opts);
|
||||||
preinitDLL(console);
|
preinitDLL(console);
|
||||||
settings.init();
|
settings.init();
|
||||||
@ -935,7 +930,6 @@ int main(int argc, char * argv[])
|
|||||||
|
|
||||||
loadDLLClasses();
|
loadDLLClasses();
|
||||||
srand((ui32)time(nullptr));
|
srand((ui32)time(nullptr));
|
||||||
#endif
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
boost::asio::io_service io_service;
|
boost::asio::io_service io_service;
|
||||||
@ -975,17 +969,10 @@ int main(int argc, char * argv[])
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef VCMI_ANDROID
|
#if defined(VCMI_ANDROID) || defined(VCMI_IOS)
|
||||||
void CVCMIServer::create()
|
void CVCMIServer::create()
|
||||||
{
|
{
|
||||||
const char * foo[1] = {"android-server"};
|
const char * foo[1] = {"android-server"};
|
||||||
main(1, const_cast<char **>(foo));
|
main(1, const_cast<char **>(foo));
|
||||||
}
|
}
|
||||||
#elif defined(VCMI_IOS)
|
|
||||||
void CVCMIServer::create(boost::condition_variable * cond)
|
|
||||||
{
|
|
||||||
const auto executablePath = VCMIDirs::get().serverPath();
|
|
||||||
void *argv[] = {const_cast<char *>(executablePath.c_str()), cond};
|
|
||||||
main(2, reinterpret_cast<char **>(argv));
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -101,9 +101,7 @@ public:
|
|||||||
|
|
||||||
ui8 getIdOfFirstUnallocatedPlayer() const;
|
ui8 getIdOfFirstUnallocatedPlayer() const;
|
||||||
|
|
||||||
#ifdef VCMI_ANDROID
|
#if defined(VCMI_ANDROID) || defined(VCMI_IOS)
|
||||||
static void create();
|
static void create();
|
||||||
#elif defined(VCMI_IOS)
|
|
||||||
static void create(boost::condition_variable * cond);
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
63
server/main_ios.mm
Normal file
63
server/main_ios.mm
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* main_ios.mm, part of VCMI engine
|
||||||
|
*
|
||||||
|
* Authors: listed in file AUTHORS in main folder
|
||||||
|
*
|
||||||
|
* License: GNU General Public License v2.0 or later
|
||||||
|
* Full text of license available in license.txt file, in main folder
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
#import <AVFoundation/AVFoundation.h>
|
||||||
|
|
||||||
|
//#include "StdInc.h"
|
||||||
|
#include "../Global.h"
|
||||||
|
#include "CVCMIServer.h"
|
||||||
|
|
||||||
|
@interface ViewController : UIViewController
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation ViewController
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@interface AppDelegate : UIResponder <UIApplicationDelegate>
|
||||||
|
@property (nonatomic, strong) UIWindow *window;
|
||||||
|
@property (nonatomic, strong) AVPlayerLooper *looper;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation AppDelegate
|
||||||
|
|
||||||
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
||||||
|
{
|
||||||
|
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
|
||||||
|
self.window.rootViewController = [ViewController new];
|
||||||
|
[self.window makeKeyAndVisible];
|
||||||
|
|
||||||
|
[AVAudioSession.sharedInstance setCategory:AVAudioSessionCategoryPlayback mode:AVAudioSessionModeDefault options:AVAudioSessionCategoryOptionMixWithOthers error:nullptr];
|
||||||
|
|
||||||
|
auto item = [AVPlayerItem playerItemWithURL:[NSBundle.mainBundle URLForResource:@"silence" withExtension:@"wav"]];
|
||||||
|
auto player = [AVQueuePlayer new];
|
||||||
|
player.allowsExternalPlayback = NO;
|
||||||
|
[player play];
|
||||||
|
self.looper = [AVPlayerLooper playerLooperWithPlayer:player templateItem:item];
|
||||||
|
|
||||||
|
[NSThread detachNewThreadWithBlock:^
|
||||||
|
{
|
||||||
|
NSThread.currentThread.name = @"CVCMIServer";
|
||||||
|
NSLog(@"starting server from thread %@", NSThread.currentThread);
|
||||||
|
CVCMIServer::create();
|
||||||
|
}];
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char * argv[])
|
||||||
|
{
|
||||||
|
@autoreleasepool
|
||||||
|
{
|
||||||
|
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user