2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 cocos2d-x.org
|
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
|
|
2022-10-01 16:24:52 +08:00
|
|
|
https://axmolengine.github.io/
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
2021-07-19 18:33:03 +08:00
|
|
|
|
|
|
|
#include <string>
|
2019-11-23 20:27:39 +08:00
|
|
|
#include "AppDelegate.h"
|
|
|
|
|
2022-10-12 00:15:09 +08:00
|
|
|
#include "axmol.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
#include "controller.h"
|
2023-02-23 09:50:36 +08:00
|
|
|
#include "BaseTest.h"
|
2023-03-14 07:56:07 +08:00
|
|
|
#include "extensions/axmol-ext.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
USING_NS_AX;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
AppDelegate::AppDelegate() : _testController(nullptr) {}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
AppDelegate::~AppDelegate()
|
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
// SimpleAudioEngine::end();
|
|
|
|
// TODO: minggo
|
|
|
|
// cocostudio::ArmatureDataManager::destroyInstance();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// if you want a different context, modify the value of glContextAttrs
|
|
|
|
// it will affect all platforms
|
|
|
|
void AppDelegate::initGLContextAttrs()
|
|
|
|
{
|
|
|
|
// set OpenGL context attributes: red,green,blue,alpha,depth,stencil
|
|
|
|
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8, 0};
|
|
|
|
|
|
|
|
GLView::setGLContextAttrs(glContextAttrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AppDelegate::applicationDidFinishLaunching()
|
|
|
|
{
|
|
|
|
// As an example, load config file
|
|
|
|
// FIXME:: This should be loaded before the Director is initialized,
|
|
|
|
// FIXME:: but at this point, the director is already initialized
|
|
|
|
Configuration::getInstance()->loadConfigFile("configs/config-example.plist");
|
2020-09-11 17:32:08 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
// initialize director
|
|
|
|
auto director = Director::getInstance();
|
2022-09-05 14:13:52 +08:00
|
|
|
auto glView = director->getOpenGLView();
|
|
|
|
if (!glView)
|
2021-12-31 12:12:40 +08:00
|
|
|
{
|
2021-07-19 18:33:03 +08:00
|
|
|
std::string title = "Cpp Tests";
|
|
|
|
#ifndef NDEBUG
|
|
|
|
title += " *Debug*",
|
|
|
|
#endif
|
2023-03-14 12:08:31 +08:00
|
|
|
#ifdef AX_PLATFORM_PC
|
|
|
|
glView = GLViewImpl::createWithRect(title, Rect(0, 0, g_resourceSize.width, g_resourceSize.height), 1.0F, true);
|
2023-01-21 14:51:14 +08:00
|
|
|
#else
|
2023-03-14 12:08:31 +08:00
|
|
|
glView = GLViewImpl::createWithRect(title, Rect(0, 0, g_resourceSize.width, g_resourceSize.height));
|
2023-01-21 14:51:14 +08:00
|
|
|
#endif
|
2022-09-05 14:13:52 +08:00
|
|
|
director->setOpenGLView(glView);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2022-07-05 00:39:20 +08:00
|
|
|
director->setStatsDisplay(true);
|
2022-07-05 14:48:46 +08:00
|
|
|
|
2023-03-14 12:08:31 +08:00
|
|
|
#ifdef AX_PLATFORM_PC
|
|
|
|
director->setAnimationInterval(1.0f / glfwGetVideoMode(glfwGetPrimaryMonitor())->refreshRate);
|
|
|
|
#else
|
2019-11-23 20:27:39 +08:00
|
|
|
director->setAnimationInterval(1.0f / 60);
|
2023-03-14 12:08:31 +08:00
|
|
|
#endif
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-09-05 14:13:52 +08:00
|
|
|
auto screenSize = glView->getFrameSize();
|
2020-09-11 17:32:08 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
auto fileUtils = FileUtils::getInstance();
|
2023-07-19 21:05:46 +08:00
|
|
|
std::vector<std::string> searchPaths;
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
if (screenSize.height > 320)
|
|
|
|
{
|
2022-08-08 13:18:33 +08:00
|
|
|
searchPaths.emplace_back("hd");
|
|
|
|
searchPaths.emplace_back("ccs-res/hd");
|
|
|
|
searchPaths.emplace_back("ccs-res");
|
|
|
|
searchPaths.emplace_back("Manifests");
|
2023-02-23 09:50:36 +08:00
|
|
|
director->setContentScaleFactor(g_resourceSize.height / g_designSize.height);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-08-08 13:18:33 +08:00
|
|
|
searchPaths.emplace_back("hd/ActionTimeline");
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-08 13:18:33 +08:00
|
|
|
searchPaths.emplace_back("ccs-res");
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2022-08-08 13:18:33 +08:00
|
|
|
searchPaths.emplace_back("ActionTimeline");
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2023-07-19 23:41:16 +08:00
|
|
|
auto&& oldSearchPaths = fileUtils->getSearchPaths();
|
|
|
|
std::copy(oldSearchPaths.begin(), oldSearchPaths.end(), std::back_inserter(searchPaths));
|
2019-11-23 20:27:39 +08:00
|
|
|
fileUtils->setSearchPaths(searchPaths);
|
|
|
|
|
2023-02-23 09:50:36 +08:00
|
|
|
glView->setDesignResolutionSize(g_designSize.width, g_designSize.height, ResolutionPolicy::SHOW_ALL);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
// Enable Remote Console
|
|
|
|
auto console = director->getConsole();
|
|
|
|
console->listenOnTCP(5678);
|
|
|
|
|
|
|
|
_testController = TestController::getInstance();
|
|
|
|
|
2023-07-09 20:10:50 +08:00
|
|
|
if (std::getenv("AXMOL_START_AUTOTEST"))
|
|
|
|
{
|
|
|
|
_testController->startAutoTest();
|
|
|
|
}
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This function will be called when the app is inactive. Note, when receiving a phone call it is invoked.
|
|
|
|
void AppDelegate::applicationDidEnterBackground()
|
|
|
|
{
|
|
|
|
if (_testController)
|
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
// _testController->onEnterBackground();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
Director::getInstance()->stopAnimation();
|
|
|
|
}
|
|
|
|
|
|
|
|
// this function will be called when the app is active again
|
|
|
|
void AppDelegate::applicationWillEnterForeground()
|
|
|
|
{
|
|
|
|
if (_testController)
|
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
// _testController->onEnterForeground();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
Director::getInstance()->startAnimation();
|
|
|
|
}
|