1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-18 03:21:27 +02:00

show loading indicator when starting local server

single player or hosting a multiplayer game
This commit is contained in:
Andrey Filipenkov 2022-08-16 12:54:44 +03:00
parent 2af7c29163
commit 3ab21d8491
10 changed files with 78 additions and 15 deletions

View File

@ -441,7 +441,6 @@ int main(int argc, char * argv[])
#ifndef VCMI_NO_THREADED_LOAD #ifndef VCMI_NO_THREADED_LOAD
// todo ios
#ifdef VCMI_ANDROID // android loads the data quite slowly so we display native progressbar to prevent having only black screen for few seconds #ifdef VCMI_ANDROID // android loads the data quite slowly so we display native progressbar to prevent having only black screen for few seconds
{ {
CAndroidVMHelper vmHelper; CAndroidVMHelper vmHelper;
@ -1322,7 +1321,6 @@ static void handleEvent(SDL_Event & ev)
{ {
if((ev.type==SDL_QUIT) ||(ev.type == SDL_KEYDOWN && ev.key.keysym.sym==SDLK_F4 && (ev.key.keysym.mod & KMOD_ALT))) if((ev.type==SDL_QUIT) ||(ev.type == SDL_KEYDOWN && ev.key.keysym.sym==SDLK_F4 && (ev.key.keysym.mod & KMOD_ALT)))
{ {
// todo ios
#ifdef VCMI_ANDROID #ifdef VCMI_ANDROID
handleQuit(false); handleQuit(false);
#else #else

View File

@ -151,11 +151,13 @@ if(APPLE_IOS)
ios/GameChatKeyboardHanlder.m ios/GameChatKeyboardHanlder.m
ios/main.m ios/main.m
ios/startSDL.mm ios/startSDL.mm
ios/utils.mm
) )
set(client_HEADERS ${client_HEADERS} set(client_HEADERS ${client_HEADERS}
CFocusableHelper.h CFocusableHelper.h
ios/GameChatKeyboardHanlder.h ios/GameChatKeyboardHanlder.h
ios/startSDL.h ios/startSDL.h
ios/utils.h
) )
endif() endif()

View File

@ -364,7 +364,6 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details, bool verbose)
for(int i = 1; i < 32; i += 2 * speed) for(int i = 1; i < 32; i += 2 * speed)
{ {
movementPxStep(details, i, hp, hero); movementPxStep(details, i, hp, hero);
// todo ios
#ifndef VCMI_ANDROID #ifndef VCMI_ANDROID
// currently android doesn't seem to be able to handle all these full redraws here, so let's disable it so at least it looks less choppy; // currently android doesn't seem to be able to handle all these full redraws here, so let's disable it so at least it looks less choppy;
// most likely this is connected with the way that this manual animation+framerate handling is solved // most likely this is connected with the way that this manual animation+framerate handling is solved

View File

@ -24,8 +24,10 @@
#ifdef VCMI_ANDROID #ifdef VCMI_ANDROID
#include "../lib/CAndroidVMHelper.h" #include "../lib/CAndroidVMHelper.h"
#elif defined(VCMI_IOS) #elif defined(VCMI_IOS)
#include "ios/utils.h"
#include "../server/CVCMIServer.h" #include "../server/CVCMIServer.h"
// todo ios
#include <dispatch/dispatch.h>
#else #else
#include "../lib/Interprocess.h" #include "../lib/Interprocess.h"
#endif #endif
@ -185,8 +187,6 @@ 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
logNetwork->info("[ios] create server thread");
boost::condition_variable cond; boost::condition_variable cond;
threadRunLocalServer = std::make_shared<boost::thread>([&cond, this] { threadRunLocalServer = std::make_shared<boost::thread>([&cond, this] {
setThreadName("CVCMIServer"); setThreadName("CVCMIServer");
@ -196,7 +196,6 @@ void CServerHandler::startLocalServerAndConnect()
CSH->campaignServerRestartLock.setn(false); CSH->campaignServerRestartLock.setn(false);
}); });
threadRunLocalServer->detach(); 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,13 +213,20 @@ 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
{ {
dispatch_sync(dispatch_get_main_queue(), ^{
iOS_utils::showLoadingIndicator();
});
boost::mutex m; boost::mutex m;
boost::unique_lock<boost::mutex> lock{m}; boost::unique_lock<boost::mutex> lock{m};
logNetwork->info("waiting for server"); logNetwork->info("waiting for server");
cond.wait(lock); cond.wait(lock);
logNetwork->info("server is ready"); logNetwork->info("server is ready");
dispatch_sync(dispatch_get_main_queue(), ^{
iOS_utils::hideLoadingIndicator();
});
} }
#else #else
if(shm) if(shm)

View File

@ -21,7 +21,7 @@
#endif #endif
#ifdef VCMI_IOS #ifdef VCMI_IOS
#include "iOS_utils.h" #include "ios/utils.h"
#endif #endif
const SDL_Color Colors::YELLOW = { 229, 215, 123, 0 }; const SDL_Color Colors::YELLOW = { 229, 215, 123, 0 };

18
client/ios/utils.h Normal file
View File

@ -0,0 +1,18 @@
/*
* utils.h, 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
*
*/
#pragma once
namespace iOS_utils
{
double screenScale();
void showLoadingIndicator();
void hideLoadingIndicator();
}

46
client/ios/utils.mm Normal file
View File

@ -0,0 +1,46 @@
/*
* utils.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
*
*/
#include "utils.h"
#import <UIKit/UIKit.h>
namespace
{
UIActivityIndicatorView *indicator;
}
namespace iOS_utils
{
double screenScale()
{
return UIScreen.mainScreen.nativeScale;
}
void showLoadingIndicator()
{
NSCAssert(!indicator, @"activity indicator must be hidden before attempting to show it again");
indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[indicator startAnimating];
auto mainView = UIApplication.sharedApplication.keyWindow.rootViewController.view;
mainView.userInteractionEnabled = NO;
[mainView addSubview:indicator];
indicator.center = {CGRectGetMidX(mainView.bounds), CGRectGetMidY(mainView.bounds)};
}
void hideLoadingIndicator()
{
indicator.superview.userInteractionEnabled = YES;
[indicator stopAnimating];
[indicator removeFromSuperview];
indicator = nil;
}
}

View File

@ -4,7 +4,6 @@ add_library(iOS_utils SHARED
) )
target_link_libraries(iOS_utils PRIVATE target_link_libraries(iOS_utils PRIVATE
"-framework Foundation" "-framework Foundation"
"-framework UIKit"
) )
target_include_directories(iOS_utils PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_include_directories(iOS_utils PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

View File

@ -25,7 +25,5 @@ const char *bundlePath();
const char *frameworksPath(); const char *frameworksPath();
const char *bundleIdentifier(); const char *bundleIdentifier();
double screenScale();
} }
#pragma GCC visibility pop #pragma GCC visibility pop

View File

@ -11,7 +11,6 @@
#include "iOS_utils.h" #include "iOS_utils.h"
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
namespace namespace
{ {
@ -47,6 +46,4 @@ const char *bundlePath() { return NSBundle.mainBundle.bundlePath.fileSystemRepre
const char *frameworksPath() { return NSBundle.mainBundle.privateFrameworksPath.fileSystemRepresentation; } const char *frameworksPath() { return NSBundle.mainBundle.privateFrameworksPath.fileSystemRepresentation; }
const char *bundleIdentifier() { return NSBundle.mainBundle.bundleIdentifier.UTF8String; } const char *bundleIdentifier() { return NSBundle.mainBundle.bundleIdentifier.UTF8String; }
double screenScale() { return UIScreen.mainScreen.nativeScale; }
} }