2014-01-31 07:11:54 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 cocos2d-x.org
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2014-01-31 07:11:54 +08:00
|
|
|
|
2022-07-09 22:23:34 +08:00
|
|
|
https://axis-project.github.io/
|
2014-01-31 07:11:54 +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>
|
2012-04-19 14:35:52 +08:00
|
|
|
#include "AppDelegate.h"
|
|
|
|
|
|
|
|
#include "cocos2d.h"
|
2012-07-19 17:22:36 +08:00
|
|
|
#include "controller.h"
|
2020-11-01 20:18:50 +08:00
|
|
|
// #include "extensions/cocostudio/CocoStudio.h"
|
2013-10-16 16:48:39 +08:00
|
|
|
#include "extensions/cocos-ext.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
USING_NS_AX;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2021-12-01 22:03:57 +08:00
|
|
|
// Enable log on Debug version
|
|
|
|
#ifndef NDEBUG
|
2021-12-28 16:06:23 +08:00
|
|
|
# define COCOS2D_DEBUG 1
|
2021-12-01 22:03:57 +08:00
|
|
|
#else
|
2021-12-28 16:06:23 +08:00
|
|
|
# define COCOS2D_DEBUG 0
|
2021-12-01 22:03:57 +08:00
|
|
|
#endif
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
AppDelegate::AppDelegate() : _testController(nullptr) {}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
AppDelegate::~AppDelegate()
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
// SimpleAudioEngine::end();
|
|
|
|
// TODO: minggo
|
|
|
|
// cocostudio::ArmatureDataManager::destroyInstance();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2016-05-25 22:18:57 +08:00
|
|
|
// if you want a different context, modify the value of glContextAttrs
|
|
|
|
// it will affect all platforms
|
2014-08-22 16:22:16 +08:00
|
|
|
void AppDelegate::initGLContextAttrs()
|
2014-08-21 09:35:32 +08:00
|
|
|
{
|
2016-05-25 22:18:57 +08:00
|
|
|
// set OpenGL context attributes: red,green,blue,alpha,depth,stencil
|
2018-01-19 09:28:22 +08:00
|
|
|
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8, 0};
|
2014-08-21 09:35:32 +08:00
|
|
|
|
2014-08-22 16:22:16 +08:00
|
|
|
GLView::setGLContextAttrs(glContextAttrs);
|
2014-08-21 09:35:32 +08:00
|
|
|
}
|
|
|
|
|
2020-10-20 16:38:50 +08:00
|
|
|
static Size resourceSize(960, 640);
|
2020-09-11 17:32:08 +08:00
|
|
|
static Size designSize(480, 320);
|
|
|
|
|
2022-06-30 18:13:55 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
bool AppDelegate::applicationDidFinishLaunching()
|
|
|
|
{
|
2014-01-25 05:43:46 +08:00
|
|
|
// As an example, load config file
|
2014-08-30 03:54:24 +08:00
|
|
|
// FIXME:: This should be loaded before the Director is initialized,
|
|
|
|
// FIXME:: but at this point, the director is already initialized
|
2014-01-25 05:43:46 +08:00
|
|
|
Configuration::getInstance()->loadConfigFile("configs/config-example.plist");
|
2020-09-11 17:32:08 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// initialize director
|
2013-08-16 16:05:27 +08:00
|
|
|
auto director = Director::getInstance();
|
2021-12-28 16:06:23 +08:00
|
|
|
auto glview = director->getOpenGLView();
|
|
|
|
if (!glview)
|
|
|
|
{
|
2021-07-19 18:33:03 +08:00
|
|
|
std::string title = "Cpp Tests";
|
|
|
|
#ifndef NDEBUG
|
|
|
|
title += " *Debug*",
|
|
|
|
#endif
|
2021-12-28 16:06:23 +08:00
|
|
|
glview = GLViewImpl::createWithRect(title, Rect(0, 0, resourceSize.width, resourceSize.height));
|
2014-01-25 05:43:46 +08:00
|
|
|
director->setOpenGLView(glview);
|
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-04 22:45:23 +08:00
|
|
|
director->setStatsDisplay(true);
|
2022-07-05 14:48:46 +08:00
|
|
|
|
|
|
|
#ifdef CC_PLATFORM_PC
|
|
|
|
director->setAnimationInterval(1.0f / glfwGetVideoMode(glfwGetPrimaryMonitor())->refreshRate);
|
|
|
|
#else
|
2016-04-20 03:01:06 +08:00
|
|
|
director->setAnimationInterval(1.0f / 60);
|
2022-07-05 14:48:46 +08:00
|
|
|
#endif
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-01-24 07:36:55 +08:00
|
|
|
auto screenSize = glview->getFrameSize();
|
2020-09-11 17:32:08 +08:00
|
|
|
|
2014-01-28 11:16:09 +08:00
|
|
|
auto fileUtils = FileUtils::getInstance();
|
2014-01-25 05:43:46 +08:00
|
|
|
std::vector<std::string> searchPaths;
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2012-10-23 17:48:50 +08:00
|
|
|
if (screenSize.height > 320)
|
2012-10-12 17:37:26 +08:00
|
|
|
{
|
2013-01-28 17:44:53 +08:00
|
|
|
searchPaths.push_back("hd");
|
2014-05-05 15:24:33 +08:00
|
|
|
searchPaths.push_back("ccs-res/hd");
|
|
|
|
searchPaths.push_back("ccs-res");
|
2014-10-09 18:30:39 +08:00
|
|
|
searchPaths.push_back("Manifests");
|
2021-12-28 16:06:23 +08:00
|
|
|
director->setContentScaleFactor(resourceSize.height / designSize.height);
|
2015-07-09 10:19:07 +08:00
|
|
|
|
2016-05-06 15:37:10 +08:00
|
|
|
searchPaths.push_back("hd/ActionTimeline");
|
2012-10-12 17:37:26 +08:00
|
|
|
}
|
2014-01-25 05:43:46 +08:00
|
|
|
else
|
|
|
|
{
|
2014-05-05 15:24:33 +08:00
|
|
|
searchPaths.push_back("ccs-res");
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-12-02 16:00:30 +08:00
|
|
|
searchPaths.push_back("ActionTimeline");
|
2014-01-25 05:43:46 +08:00
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-01-28 11:16:09 +08:00
|
|
|
fileUtils->setSearchPaths(searchPaths);
|
2012-10-12 17:37:26 +08:00
|
|
|
|
2016-12-13 11:42:12 +08:00
|
|
|
glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::NO_BORDER);
|
|
|
|
|
2015-04-22 10:20:21 +08:00
|
|
|
// Enable Remote Console
|
|
|
|
auto console = director->getConsole();
|
|
|
|
console->listenOnTCP(5678);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2015-04-03 11:54:39 +08:00
|
|
|
_testController = TestController::getInstance();
|
2016-06-16 02:33:25 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-25 22:18:57 +08:00
|
|
|
// This function will be called when the app is inactive. Note, when receiving a phone call it is invoked.
|
2012-04-19 14:35:52 +08:00
|
|
|
void AppDelegate::applicationDidEnterBackground()
|
|
|
|
{
|
2015-04-07 16:14:27 +08:00
|
|
|
if (_testController)
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
// _testController->onEnterBackground();
|
2015-04-07 16:14:27 +08:00
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->stopAnimation();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// this function will be called when the app is active again
|
|
|
|
void AppDelegate::applicationWillEnterForeground()
|
|
|
|
{
|
2015-04-07 16:14:27 +08:00
|
|
|
if (_testController)
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
// _testController->onEnterForeground();
|
2015-04-07 16:14:27 +08:00
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->startAnimation();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|