axmol/tests/cpp-tests/Classes/AppDelegate.cpp

151 lines
4.6 KiB
C++
Raw Normal View History

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-02-24 18:45:25 +08:00
https://adxeproject.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.
****************************************************************************/
#include <string>
2019-11-23 20:27:39 +08:00
#include "AppDelegate.h"
#include "cocos2d.h"
#include "controller.h"
// #include "extensions/cocostudio/CocoStudio.h"
2019-11-23 20:27:39 +08:00
#include "extensions/cocos-ext.h"
USING_NS_CC;
// Enable log on Debug version
#ifndef NDEBUG
# define COCOS2D_DEBUG 1
#else
# define COCOS2D_DEBUG 0
#endif
AppDelegate::AppDelegate() : _testController(nullptr) {}
2019-11-23 20:27:39 +08:00
AppDelegate::~AppDelegate()
{
// 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);
}
static Size resourceSize(960, 640);
2020-09-11 17:32:08 +08:00
static Size designSize(480, 320);
2019-11-23 20:27:39 +08:00
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();
auto glview = director->getOpenGLView();
if (!glview)
{
std::string title = "Cpp Tests";
#ifndef NDEBUG
title += " *Debug*",
#endif
glview = GLViewImpl::createWithRect(title, Rect(0, 0, resourceSize.width, resourceSize.height));
2019-11-23 20:27:39 +08:00
director->setOpenGLView(glview);
}
director->setStatsDisplay(true);
#ifdef CC_PLATFORM_PC
director->setAnimationInterval(1.0f / glfwGetVideoMode(glfwGetPrimaryMonitor())->refreshRate);
#else
2019-11-23 20:27:39 +08:00
director->setAnimationInterval(1.0f / 60);
#endif
2019-11-23 20:27:39 +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();
std::vector<std::string> searchPaths;
2019-11-23 20:27:39 +08:00
if (screenSize.height > 320)
{
searchPaths.push_back("hd");
searchPaths.push_back("ccs-res/hd");
searchPaths.push_back("ccs-res");
searchPaths.push_back("Manifests");
director->setContentScaleFactor(resourceSize.height / designSize.height);
2019-11-23 20:27:39 +08:00
searchPaths.push_back("hd/ActionTimeline");
}
else
{
searchPaths.push_back("ccs-res");
2019-11-23 20:27:39 +08:00
searchPaths.push_back("ActionTimeline");
}
2019-11-23 20:27:39 +08:00
fileUtils->setSearchPaths(searchPaths);
glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::NO_BORDER);
// Enable Remote Console
auto console = director->getConsole();
console->listenOnTCP(5678);
_testController = TestController::getInstance();
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)
{
// _testController->onEnterBackground();
2019-11-23 20:27:39 +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)
{
// _testController->onEnterForeground();
2019-11-23 20:27:39 +08:00
}
2019-11-23 20:27:39 +08:00
Director::getInstance()->startAnimation();
}