Exemplo n.º 1
0
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
        glview = GLViewImpl::createWithRect("Takigyo", Rect(0, 0, 640, 960));
        director->setOpenGLView(glview);
    }
    
    cocos2d::Size targetSize = glview->getFrameSize();
    
//    CCLOG("w:%f", targetSize.width);
//    CCLOG("h:%f", targetSize.height);
    
    if (targetSize.width/targetSize.height >= 0.74){
        glview->setDesignResolutionSize(640, 960, ResolutionPolicy::EXACT_FIT);
    } else {
        glview->setDesignResolutionSize(640, 960, ResolutionPolicy::FIXED_WIDTH);
    }

    // turn on display FPS
    director->setDisplayStats(false);

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);

    FileUtils::getInstance()->addSearchPath("res");
    
    // create a scene. it's an autorelease object
    auto scene = MainScene::createScene();

    // run
    director->runWithScene(scene);

    return true;
}
Exemplo n.º 2
0
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    Size designResolution = Size(2048, 1536);
    auto glview = director->getOpenGLView();
    if(!glview) {
        glview = GLViewImpl::create("My Game");
        glview->setDesignResolutionSize(designResolution.width, designResolution.height, ResolutionPolicy::SHOW_ALL);
        director->setOpenGLView(glview);
    }

    director->setContentScaleFactor(designResolution.height / glview->getFrameSize().height);

    // turn on display FPS
    director->setDisplayStats(true);

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);

    // run by customer GameController
    GameController::getInstance()->enterStartScene();

    return true;
}
Exemplo n.º 3
0
sf::FloatRect Animation::getLocalBounds() const
{
	return sf::FloatRect(getOrigin(), static_cast<sf::Vector2f>(getFrameSize()));
}
Exemplo n.º 4
0
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
        glview = GLViewImpl::createWithRect("WackyBirds", Rect(0, 0, designResolutionSize.width, designResolutionSize.height));
#else
        glview = GLViewImpl::create("WackyBirds");
#endif
        director->setOpenGLView(glview);
    }

    // turn on display FPS
    director->setDisplayStats(true);

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);

    // Set the design resolution
    glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
    Size frameSize = glview->getFrameSize();
    // if the frame's height is larger than the height of medium size.
    if (frameSize.height > mediumResolutionSize.height)
    {        
        director->setContentScaleFactor(MIN(largeResolutionSize.height/designResolutionSize.height, largeResolutionSize.width/designResolutionSize.width));
    }
    // if the frame's height is larger than the height of small size.
    else if (frameSize.height > smallResolutionSize.height)
    {        
        director->setContentScaleFactor(MIN(mediumResolutionSize.height/designResolutionSize.height, mediumResolutionSize.width/designResolutionSize.width));
    }
    // if the frame's height is smaller than the height of medium size.
    else
    {        
        director->setContentScaleFactor(MIN(smallResolutionSize.height/designResolutionSize.height, smallResolutionSize.width/designResolutionSize.width));
    }


// multi platform resolution
        auto fileUtils = FileUtils::getInstance();
        auto screenSize = glview->getFrameSize();
        std::vector<std::string> resDirOrders;
    
    // check which assets the devices requires
    if ( 2048 == screenSize.width || 2048 == screenSize.height ) // retina iPad
    {
        resDirOrders.push_back("ipadhd");
        resDirOrders.push_back("ipad");
        resDirOrders.push_back("iphonehd5");
        resDirOrders.push_back("iphonehd");
        resDirOrders.push_back("iphone");
        
        glview->setDesignResolutionSize(1536, 2048, ResolutionPolicy::NO_BORDER);
    }
    else if ( 1024 == screenSize.width || 1024 == screenSize.height ) // non retina iPad
    {
        resDirOrders.push_back("ipad");
        resDirOrders.push_back("iphonehd5");
        resDirOrders.push_back("iphonehd");
        resDirOrders.push_back("iphone");
        
        glview->setDesignResolutionSize(768, 1024, ResolutionPolicy::NO_BORDER);
    }
    else if ( 1136 == screenSize.width || 1136 == screenSize.height ) // retina iPhone (5 and 5S)
    {
        resDirOrders.push_back("iphonehd5");
        resDirOrders.push_back("iphonehd");
        resDirOrders.push_back("iphone");
        
        glview->setDesignResolutionSize(640, 1136, ResolutionPolicy::NO_BORDER);
    }
    else if ( 960 == screenSize.width || 960 == screenSize.height ) // retina iPhone (4 and 4S)
    {
        resDirOrders.push_back("iphonehd");
        resDirOrders.push_back("iphone");
        
        glview->setDesignResolutionSize(640, 960, ResolutionPolicy::NO_BORDER);
    }
    else // non retina iPhone and Android devices
    {
        if ( 1080 < screenSize.width ) // android devices that have a high resolution
        {
            resDirOrders.push_back("iphonehd");
            resDirOrders.push_back("iphone");
            
            glview->setDesignResolutionSize(640, 960, ResolutionPolicy::NO_BORDER);
        }
        else // non retina iPhone and Android devices with lower resolutions
        {
            resDirOrders.push_back("iphone");
            
            glview->setDesignResolutionSize(320, 480, ResolutionPolicy::NO_BORDER);
        }
    }
    
    fileUtils->setSearchPaths(resDirOrders);
// end multi platform resolution




    register_all_packages();

    // create a scene. it's an autorelease object
    auto scene = SplashScene::createScene();

    // run
    director->runWithScene(scene);

    return true;
}
Exemplo n.º 5
0
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
        glview = GLViewImpl::create("Get To The Lander");
        director->setOpenGLView(glview);
    }
    
    // turn on display FPS
    director->setDisplayStats(false);
    
    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);
    
    auto fileUtils = FileUtils::getInstance( );
    auto screenSize = glview->getFrameSize( );
    std::vector<std::string> resDirOrders;
    
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
	// check which assets the devices requires
	if (2048 == screenSize.width || 2048 == screenSize.height) // retina iPad
	{
		resDirOrders.push_back("ipadhd");
		resDirOrders.push_back("ipad");
		resDirOrders.push_back("iphonehd5");
		resDirOrders.push_back("iphonehd");
		resDirOrders.push_back("iphone");

		if (true == IS_LANDSCAPE)
		{
			glview->setDesignResolutionSize(2048, 1536, ResolutionPolicy::NO_BORDER);
		}
		else
		{
			glview->setDesignResolutionSize(1536, 2048, ResolutionPolicy::NO_BORDER);
		}
	}
	else if (1024 == screenSize.width || 1024 == screenSize.height) // non retina iPad
	{
		resDirOrders.push_back("ipad");
		resDirOrders.push_back("iphonehd5");
		resDirOrders.push_back("iphonehd");
		resDirOrders.push_back("iphone");

		if (true == IS_LANDSCAPE)
		{
			glview->setDesignResolutionSize(1024, 768, ResolutionPolicy::NO_BORDER);
		}
		else
		{
			glview->setDesignResolutionSize(768, 1024, ResolutionPolicy::NO_BORDER);
		}
	}
	else if (1136 == screenSize.width || 1136 == screenSize.height) // retina iPhone (5 and 5S)
	{
		resDirOrders.push_back("iphonehd5");
		resDirOrders.push_back("iphonehd");
		resDirOrders.push_back("iphone");

		if (true == IS_LANDSCAPE)
		{
			glview->setDesignResolutionSize(1136, 640, ResolutionPolicy::NO_BORDER);
		}
		else
		{
			glview->setDesignResolutionSize(640, 1136, ResolutionPolicy::NO_BORDER);
		}
	}
	else if (960 == screenSize.width || 960 == screenSize.height) // retina iPhone (4 and 4S)
	{
		resDirOrders.push_back("iphonehd");
		resDirOrders.push_back("iphone");

		if (true == IS_LANDSCAPE)
		{
			glview->setDesignResolutionSize(960, 640, ResolutionPolicy::NO_BORDER);
		}
		else
		{
			glview->setDesignResolutionSize(640, 960, ResolutionPolicy::NO_BORDER);
		}
	}
	else // non retina iPhone and Android devices
	{
		if (1080 < screenSize.width && 1080 < screenSize.height) // android devices that have a high resolution
		{
			resDirOrders.push_back("iphonehd");
			resDirOrders.push_back("iphone");

			if (true == IS_LANDSCAPE)
			{
				glview->setDesignResolutionSize(960, 640, ResolutionPolicy::NO_BORDER);
			}
			else
			{
				glview->setDesignResolutionSize(640, 960, ResolutionPolicy::NO_BORDER);
			}
		}
		else // non retina iPhone and Android devices with lower resolutions
		{
			resDirOrders.push_back("iphone");

			if (true == IS_LANDSCAPE)
			{
				glview->setDesignResolutionSize(480, 320, ResolutionPolicy::NO_BORDER);
			}
			else
			{
				glview->setDesignResolutionSize(320, 480, ResolutionPolicy::NO_BORDER);
			}
		}
	}

#elif (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
	resDirOrders.push_back("ipad");
	resDirOrders.push_back("iphonehd5");
	resDirOrders.push_back("iphonehd");
	resDirOrders.push_back("iphone");

	if (true == IS_LANDSCAPE)
	{
		glview->setFrameSize(1024, 768);
		glview->setDesignResolutionSize(1024, 768, ResolutionPolicy::NO_BORDER);
	}
	else
	{
		glview->setFrameSize(768, 1024);
		glview->setDesignResolutionSize(768, 1024, ResolutionPolicy::NO_BORDER);
	}
#endif
    
    fileUtils->setSearchPaths(resDirOrders);
    
    // create a scene. it's an autorelease object
    auto scene = SplashScene::createScene();
    
    // run
    director->runWithScene(scene);
    
    return true;
}
Exemplo n.º 6
0
bool AppDelegate::applicationDidFinishLaunching() {

	guanKa =1;
	// background music
	BACKMUSIC = JNIUtil::getBool("backMusic",true,classPath.c_str());
	
	CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic("sound/background.mp3");
	if (BACKMUSIC){
		CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("sound/background.mp3",true);
	}
	CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic("sound/fire.mp3");
	CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic("sound/failure.mp3");
	CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic("sound/mainback.mp3");
	CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic("sound/victory.mp3");	
	
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
        glview = GLView::create("My Game");
        director->setOpenGLView(glview);
    }
	// Set the design resolution
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
    glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionShowAll);
#else
    /*glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionNoBorder);*/
	glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionShowAll);	
#endif

    Size frameSize = glview->getFrameSize();
	
	std::vector<std::string,std::allocator<std::string>> searchPath;	

    // In this demo, we select resource according to the frame's height.
    // If the resource size is different from design resolution size, you need to set contentScaleFactor.
    // We use the ratio of resource's height to the height of design resolution,
    // this can make sure that the resource's height could fit for the height of design resolution.

    // if the frame's height is larger than the height of medium resource size, select large resource.
	if (frameSize.height > mediumResource.size.height)
	{
        searchPath.push_back(largeResource.directory);

        director->setContentScaleFactor(MIN(largeResource.size.height/designResolutionSize.height, largeResource.size.width/designResolutionSize.width));
	}
    // if the frame's height is larger than the height of small resource size, select medium resource.
    else if (frameSize.height > smallResource.size.height)
    {
        searchPath.push_back(mediumResource.directory);
        
        director->setContentScaleFactor(MIN(mediumResource.size.height/designResolutionSize.height, mediumResource.size.width/designResolutionSize.width));
    }
    // if the frame's height is smaller than the height of medium resource size, select small resource.
	else
    {
        searchPath.push_back(smallResource.directory);

        director->setContentScaleFactor(MIN(smallResource.size.height/designResolutionSize.height, smallResource.size.width/designResolutionSize.width));
    }

	// manual add for show all
	director->setContentScaleFactor(1.0);	
    // set searching path
    FileUtils::sharedFileUtils()->setSearchPaths(searchPath);	
    // turn on display FPS
    director->setDisplayStats(true);

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);

    // create a scene. it's an autorelease object
    auto scene = BanQiuSceneManager::createScene();
    // run
    director->runWithScene(scene);

    return true;
}
Exemplo n.º 7
0
status_t AMRSource::read(
        MediaBuffer **out, const ReadOptions *options) {
    *out = NULL;

    int64_t seekTimeUs;
    ReadOptions::SeekMode mode;
    if (options && options->getSeekTo(&seekTimeUs, &mode)) {
        int64_t seekFrame = seekTimeUs / 20000ll;  // 20ms per frame.
        mCurrentTimeUs = seekFrame * 20000ll;
        mOffset = seekFrame * mFrameSize + (mIsWide ? 9 : 6);
    }

    uint8_t header;
    ssize_t n = mDataSource->readAt(mOffset, &header, 1);

    if (n < 1) {
        return ERROR_END_OF_STREAM;
    }

    if (header & 0x83) {
        // Padding bits must be 0.

        LOGE("padding bits must be 0, header is 0x%02x", header);

        return ERROR_MALFORMED;
    }

    unsigned FT = (header >> 3) & 0x0f;

    if (FT > 8 || (!mIsWide && FT > 7)) {

        LOGE("illegal AMR frame type %d", FT);

        return ERROR_MALFORMED;
    }

    size_t frameSize = getFrameSize(mIsWide, FT);
    CHECK_EQ(frameSize, mFrameSize);

    MediaBuffer *buffer;
    status_t err = mGroup->acquire_buffer(&buffer);
    if (err != OK) {
        return err;
    }

    n = mDataSource->readAt(mOffset, buffer->data(), frameSize);

    if (n != (ssize_t)frameSize) {
        buffer->release();
        buffer = NULL;

        return ERROR_IO;
    }

    buffer->set_range(0, frameSize);
    buffer->meta_data()->setInt64(kKeyTime, mCurrentTimeUs);
    buffer->meta_data()->setInt32(kKeyIsSyncFrame, 1);

    mOffset += frameSize;
    mCurrentTimeUs += 20000;  // Each frame is 20ms

    *out = buffer;

    return OK;
}
Exemplo n.º 8
0
bool AppDelegate::applicationDidFinishLaunching()
{
    #if COCOS2D_DEBUG

#endif    
	cocos2d::log("Hello world! CCLog! = %d", std::this_thread::get_id());
	CCLOG("Hello world! CCLOG");

    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
        glview = GLViewImpl::createWithRect("u2", cocos2d::Rect(0, 0, winResolutionSize.width, winResolutionSize.height));
#else
        glview = GLViewImpl::create("u2");
#endif
        director->setOpenGLView(glview);
    }

    // turn on display FPS
    director->setDisplayStats(true);

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);

    // Set the design resolution
    //glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
    cocos2d::Size frameSize = glview->getFrameSize();
	//director->setContentScaleFactor(2.0f);
	/*
    // if the frame's height is larger than the height of medium size.
    if (frameSize.height > mediumResolutionSize.height)
    {        
        director->setContentScaleFactor(MIN(largeResolutionSize.height/designResolutionSize.height, largeResolutionSize.width/designResolutionSize.width));
    }
    // if the frame's height is larger than the height of small size.
    else if (frameSize.height > smallResolutionSize.height)
    {        
        director->setContentScaleFactor(MIN(mediumResolutionSize.height/designResolutionSize.height, mediumResolutionSize.width/designResolutionSize.width));
    }
    // if the frame's height is smaller than the height of medium size.
    else
    {        
        director->setContentScaleFactor(MIN(smallResolutionSize.height/designResolutionSize.height, smallResolutionSize.width/designResolutionSize.width));
    }
	*/

    register_all_packages();


	FileUtils::getInstance()->addSearchPath(FileUtils::getInstance()->getWritablePath());
	cocos2d::FileUtils::getInstance()->addSearchPath("res");
    cocos2d::FileUtils::getInstance()->addSearchPath("res/entities");
	cocos2d::FileUtils::getInstance()->addSearchPath("res/ui/plist");
	cocos2d::FileUtils::getInstance()->addSearchPath("res/ui/application");
    cocos2d::FileUtils::getInstance()->addSearchPath("res/ui/joystick");
	cocos2d::FileUtils::getInstance()->addSearchPath("res/ui/cg");
    cocos2d::FileUtils::getInstance()->addSearchPath("res/ui/ui_info");


    


    {
        //------------------------------- init u2 ----------------------------------------
        m_pRoot = U2_NEW GameRoot;
        m_pRoot->enter();
    }
	


	{
		//------------------------------- Test Thread ----------------------------------------
		/*
		// Create a thread pool
		TaskGroup group(1);

		// Run a function in the thread pool
		for (int i = 0; i < 1; ++i)
		{
			group.run([=] {
				//cocos2d::log("Hello world! run = %d, %d", i, std::this_thread::get_id());
				//CCLOG("Hello world! run = %d, %d", i, std::this_thread::get_id());
				u2::LogManager::getSingleton().stream(u2::LML_NORMAL) 
					<< "Hello world! run = " << i << ", " << std::this_thread::get_id() 
					<< "\n";
 				});
			//pool.run([i] { std::cout << "Hello world! = " << i << std::endl; });
		}

		// Wait for all queued functions to finish and the pool to become empty
		group.wait();
		u2::LogManager::getSingleton().stream(u2::LML_NORMAL)
			<< "Hello world! main = " << std::this_thread::get_id()
			<< "\n";
		cocos2d::log("Hello world! Thread over!");
		*/
	}
	

	{
		//------------------------------- Test ObjectCollection ----------------------------------------
		/*
		ObjectCollection<u2::Context> collect;
		collect.createObject(OT_Context, "aaa");
		collect.createObject(OT_Context, "ddd");
		collect.createObject(OT_Context, "eee");
		collect.createObject(OT_Context, "www");
		collect.createObject(OT_Context, "ccc");
		collect.createObject(OT_Context, "www");

		ObjectCollection<u2::Context>::ObjectMapIterator objIt = collect.retrieveAllObjectsByName("www");
		while (objIt.hasMoreElements())
		{
			u2::Context* pContext = dynamic_cast<u2::Context*>(objIt.getNext());
			CCLOG("=========Name, %s, %s", pContext->getName().c_str(), pContext->getGuid().c_str());
		}

		ObjectCollection<u2::Context>::ObjectMapIterator objIt2 = collect.retrieveAllObjectsByTN(OT_Context, "www");
		while (objIt2.hasMoreElements())
		{
			u2::Context* pContext = dynamic_cast<u2::Context*>(objIt2.getNext());
			CCLOG("=========TN, %s, %s", pContext->getName().c_str(), pContext->getGuid().c_str());
		}

		ObjectCollection<u2::Context>::ObjectMapIterator objIt3 = collect.retrieveAllObjectsByType(OT_Context);
		while (objIt3.hasMoreElements())
		{
			u2::Context* pContext = dynamic_cast<u2::Context*>(objIt3.getNext());
			CCLOG("=========Type, %s, %s", pContext->getName().c_str(), pContext->getGuid().c_str());
		}

		u2::Context* pContext = collect.retrieveObjectByGuid("class u2::Context6");
		CCLOG("=========Guid, %s, %s", pContext->getName().c_str(), pContext->getGuid().c_str());
		*/
	}
	
	{
		//------------------------------- Test Stream ----------------------------------------
		/*
		FilterOutQueue<DataFilterOutStream> out;
		out.push<FileOutStream>("aaa", "D://aaa.txt", std::ios_base::out);
		out.push<DataFilterOutStream>("bbb");
		out->writeInt32(100);
		out->close();

		FilterInQueue<DataFilterInStream> in;
		in.push<FileInStream>("aaa", "D://aaa.txt", std::ios_base::in);
		in.push<DataFilterInStream>("bbb");
		u2int32 n = in->readInt32();

		OutStreamQueue<DataFilterOutStream> out;
		out.push<FileHandleOutStream>("aaa", "D://aaa.txt", "wb");
		out.push<DataFilterOutStream>("bbb");
		out->writeInt64(150);
		out->close();

		InStreamQueue<DataFilterInStream> in;
		in.push<FileHandleInStream>("aaa", "D://aaa.txt", "rb");
		in.push<DataFilterInStream>("bbb");
		u2int64 n = in->readInt64();

		PipedInStream* pPipeIn = new PipedInStream;
		PipedOutStream* pPipeOut = new PipedOutStream;
		pPipeIn->connect(pPipeOut);

		TestInThread* pInTread = new TestInThread(pPipeIn);
		TestOutThread* pOutTread = new TestOutThread(pPipeOut);
		TaskGroup group(2);
		group.run(pInTread);
		group.run(pOutTread);
		group.wait();

		int bbb = 0;
		*/
	}


    

    
    return true;
}
Exemplo n.º 9
0
status_t AMRSource::read(
        MediaBuffer **out, const ReadOptions *options) {
    *out = NULL;

    int64_t seekTimeUs;
    ReadOptions::SeekMode mode;
    if (options && options->getSeekTo(&seekTimeUs, &mode)) {
#ifdef MTK_AOSP_ENHANCEMENT

        // Maybe risk (int)index >= (uint)mOffsetTableLength warning: comparison between signed and unsigned integer expressions
        // should check seekTimeUs < 0 case
	if (seekTimeUs < 0) {
	    ALOGW("seekTimeUs:%lld < 0", seekTimeUs);
	    seekTimeUs = 0;
	}
#endif
        size_t size;
        int64_t seekFrame = seekTimeUs / 20000ll;  // 20ms per frame.
        mCurrentTimeUs = seekFrame * 20000ll;

        size_t index = seekFrame < 0 ? 0 : seekFrame / 50;
        if (index >= mOffsetTableLength) {
            index = mOffsetTableLength - 1;
        }

        mOffset = mOffsetTable[index] + (mIsWide ? 9 : 6);

        for (size_t i = 0; i< seekFrame - index * 50; i++) {
            status_t err;
            if ((err = getFrameSizeByOffset(mDataSource, mOffset,
                            mIsWide, &size)) != OK) {
                return err;
            }
            mOffset += size;
        }
    }

    uint8_t header;
    ssize_t n = mDataSource->readAt(mOffset, &header, 1);

    if (n < 1) {
        return ERROR_END_OF_STREAM;
    }
#ifdef MTK_AOSP_ENHANCEMENT

    int count = 0;
	while(header & 0x83)
	{  
        if ((count % 10) == 0)
            SXLOGW("AMRSource::read--Frame head error,skip until to find an valid one count %d",count);
	    mOffset++;
	    count++;
	    if (count>320) {
	    	SXLOGW("getFrameSizeByOffset--can not find the correct frame header in 64 byte");
	        return ERROR_END_OF_STREAM;
	    }
		n = mDataSource->readAt(mOffset, &header, 1);
	    if (n < 1) {
            return ERROR_END_OF_STREAM;
		}
	}
#else
    if (header & 0x83) {
        // Padding bits must be 0.

        ALOGE("padding bits must be 0, header is 0x%02x", header);

        return ERROR_MALFORMED;
    }
#endif

    unsigned FT = (header >> 3) & 0x0f;

    size_t frameSize = getFrameSize(mIsWide, FT);
    if (frameSize == 0) {
        return ERROR_MALFORMED;
    }

    MediaBuffer *buffer;
    status_t err = mGroup->acquire_buffer(&buffer);
    if (err != OK) {
        return err;
    }

    n = mDataSource->readAt(mOffset, buffer->data(), frameSize);

    if (n != (ssize_t)frameSize) {
        buffer->release();
        buffer = NULL;

        return ERROR_IO;
    }

    buffer->set_range(0, frameSize);
    buffer->meta_data()->setInt64(kKeyTime, mCurrentTimeUs);
    buffer->meta_data()->setInt32(kKeyIsSyncFrame, 1);

    mOffset += frameSize;
    mCurrentTimeUs += 20000;  // Each frame is 20ms

    *out = buffer;

    return OK;
}
Exemplo n.º 10
0
bool Tutorial::init()
{
	if (!Layer::init())
	{
		return false;
	}
	//LevelLoader::getInstance()->load("data/Level2.json");
	CocosDenshion::SimpleAudioEngine::getInstance()->setEffectsVolume(1.0f);
	m_gameState = GameStates::PlaceGunTower;
	move = true;
	CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect("audio/scoreSound.mp3");
	CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect("audio/crashSound.mp3");

	Size visibleSize = Director::getInstance()->getVisibleSize();
	Point origin = Director::getInstance()->getVisibleOrigin();

	powerUpBool = false;

	pauseItem =
		MenuItemImage::create("GameScreen/Pause_Button.png",
			"GameScreen/Pause_Button(Click).png",
			CC_CALLBACK_1(Tutorial::activatePauseScene, this));

	pauseItem->setPosition(22, 520);

	auto menu = Menu::create(pauseItem, NULL);
	menu->setPosition(Point::ZERO);
	this->addChild(menu, 100);

	player = Player::create();
	player->setPosition(195, 125);
	player->setAnchorPoint(Point(0.5f, 0.55f));
	this->addChild(player,5);

	powerUp = PowerUp::create(2);
	powerUp->setPosition(195,5775);
	this->addChild(powerUp);

	addBackGroundSprite(visibleSize, origin);
	createTowerBases();
	createCoins();
	createPolice();
	createAmbulances();
	//createMTrucks();
	//createTrucks();
	//createBikes();

	auto director = Director::getInstance();
	auto glview = director->getOpenGLView();
	auto screenSize = glview->getFrameSize();

	//checks for movement on the device that will be use to move the car
	Device::setAccelerometerEnabled(true);
	auto listener = EventListenerAcceleration::create(CC_CALLBACK_2(Tutorial::OnAcceleration, this));
	
	_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);

	//checks for collisions between two objects with physics bodies
	auto contactListener = EventListenerPhysicsContact::create();
	contactListener->onContactBegin = CC_CALLBACK_1(Tutorial::onContactBegin, this);
	Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(contactListener, this);

	//sets up the camera that will follow the player as it moves up the screen
	cameraTarget = Sprite::create();
	cameraTarget->setPositionX(visibleSize.width / 2);
	cameraTarget->setPositionY(player->getPosition().y - 115);
	this->scheduleUpdate();
	this->addChild(cameraTarget);
	camera = Follow::create(cameraTarget, Rect::ZERO);
	camera->retain();
	this->runAction(camera);
	return true;
}
Exemplo n.º 11
0
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");

    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
        glview = GLViewImpl::create("Cpp Tests");
        director->setOpenGLView(glview);
    }

    director->setDisplayStats(true);
    director->setAnimationInterval(1.0 / 60);

    auto screenSize = glview->getFrameSize();
    auto designSize = Size(480, 320);

    auto fileUtils = FileUtils::getInstance();
    std::vector<std::string> searchPaths;
    
    if (screenSize.height > 320)
    {
        auto resourceSize = Size(960, 640);
        searchPaths.push_back("hd");
        searchPaths.push_back("ccs-res/hd");
        searchPaths.push_back("ccs-res/hd/scenetest");
        searchPaths.push_back("ccs-res/hd/scenetest/ArmatureComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/AttributeComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/BackgroundComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/EffectComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/LoadSceneEdtiorFileTest");
        searchPaths.push_back("ccs-res/hd/scenetest/ParticleComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/SpriteComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/TmxMapComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/UIComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/TriggerTest");
        searchPaths.push_back("ccs-res");
        searchPaths.push_back("Manifests");
        director->setContentScaleFactor(resourceSize.height/designSize.height);
        
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UIButton");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UICheckBox");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UIImageView");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILabel");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILabelBMFont");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILayout/BackgroundImage");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILayout/Color");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILayout/Layout");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILayout/Gradient_Color");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILayout/Scale9_BackgroundImage");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILayout/LayoutComponent");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILoadingBar");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UIPageView");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UIScrollView/Both");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UIScrollView/Horizontal");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UIScrollView/Vertical");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UISlider");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UITextField");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UIWidgetAddNode");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UIListView/New");
        
        searchPaths.push_back("ccs-res/hd/cocosui/CustomTest/CustomWidgetCallbackBindTest");
        searchPaths.push_back("hd/ActionTimeline");
        searchPaths.push_back("ccs-res/hd/armature");
    }
    else
    {
        searchPaths.push_back("ccs-res");
        searchPaths.push_back("ccs-res/scenetest/ArmatureComponentTest");
        searchPaths.push_back("ccs-res/scenetest/AttributeComponentTest");
        searchPaths.push_back("ccs-res/scenetest/BackgroundComponentTest");
        searchPaths.push_back("ccs-res/scenetest/EffectComponentTest");
        searchPaths.push_back("ccs-res/scenetest/LoadSceneEdtiorFileTest");
        searchPaths.push_back("ccs-res/scenetest/ParticleComponentTest");
        searchPaths.push_back("ccs-res/scenetest/SpriteComponentTest");
        searchPaths.push_back("ccs-res/scenetest/TmxMapComponentTest");
        searchPaths.push_back("ccs-res/scenetest/UIComponentTest");
        searchPaths.push_back("ccs-res/scenetest/TriggerTest");
        
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UIButton");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UICheckBox");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UIImageView");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILabel");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILabelBMFont");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILayout/BackgroundImage");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILayout/Color");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILayout/Layout");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILayout/Gradient_Color");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILayout/Scale9_BackgroundImage");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILayout/LayoutComponent");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILoadingBar");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UIPageView");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UIScrollView/Both");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UIScrollView/Horizontal");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UIScrollView/Vertical");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UISlider");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UITextField");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UIWidgetAddNode");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UIListView/New");
        
        searchPaths.push_back("ccs-res/cocosui/CustomTest/CustomWidgetCallbackBindTest");
        searchPaths.push_back("ActionTimeline");
        searchPaths.push_back("ccs-res/armature");
    }
    
    fileUtils->setSearchPaths(searchPaths);

    glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::SHOW_ALL);
    
    // Enable Remote Console
    auto console = director->getConsole();
    console->listenOnTCP(5678);

    _testController = TestController::getInstance();
    
    return true;
}
Exemplo n.º 12
0
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
        glview = GLViewImpl::createWithRect("MadCraftWar", Rect(0, 0, designResolutionSize.width, designResolutionSize.height));
#else
        glview = GLViewImpl::create("MadCraftWar");
#endif
        director->setOpenGLView(glview);
    }

    // turn on display FPS
    director->setDisplayStats(true);

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0f / 60);

    // Set the design resolution
    glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
    Size frameSize = glview->getFrameSize();
    if (frameSize.height > mediumResolutionSize.height) {
    // if the frame's height is larger than the height of medium size. 
        director->setContentScaleFactor(MIN(largeResolutionSize.height/designResolutionSize.height, largeResolutionSize.width/designResolutionSize.width));
    } else if (frameSize.height > smallResolutionSize.height) {   
		// if the frame's height is larger than the height of small size.     
        director->setContentScaleFactor(MIN(mediumResolutionSize.height/designResolutionSize.height, mediumResolutionSize.width/designResolutionSize.width));
    } else {
		// if the frame's height is smaller than the height of medium size.
        director->setContentScaleFactor(MIN(smallResolutionSize.height/designResolutionSize.height, smallResolutionSize.width/designResolutionSize.width));
    }

    register_all_packages();

	// Load game resource
	//SpriteFrameCache::getInstance()->addSpriteFrame(SpriteFrame::create("monster.png", Rect(0, 0, 48, 72)), "monster.png");
	SpriteFrameCache::getInstance()->addSpriteFramesWithFile("game-sheet.plist");
	// Explosion animation
	char frameName[64];
	Animation * animation = Animation::create();
	for (int i = 0; i < 15; ++i) {
		sprintf(frameName, "explosion-%d.png", i);
		animation->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(frameName));
	}
	animation->setDelayPerUnit(0.1f);
	AnimationCache::getInstance()->addAnimation(animation, "ExplosionAnimation");

	CocosDenshion::SimpleAudioEngine::getInstance()->preloadBackgroundMusic("background.mp3");
	CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect("fire.wav");
	CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect("explosion.wav");
	CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect("hurt.wav");

    // create a scene. it's an autorelease object
    auto scene = GameScene::createScene();

    // run
    director->runWithScene(scene);

    return true;
}
Exemplo n.º 13
0
cocos2d::Sprite* GfxUtils::PrintScreen(cocos2d::Texture2D** pTexture)
{
	auto glview = Director::getInstance()->getOpenGLView();

	const cocos2d::Size& visibleSzie = glview->getFrameSize();
	int nWidth = (int)visibleSzie.width;
	int nHeight = (int)visibleSzie.height;
	int bytePerPixel = 4;

	GLubyte *pTempData = NULL;
	Image* pShotImage = new Image();
	do
	{
		pTempData = new GLubyte[nWidth * nHeight * bytePerPixel];

		HDC hDCScreen = GetDC(GetDesktopWindow());
		HBITMAP hBitmap = ::CreateCompatibleBitmap(hDCScreen, nWidth, nHeight);
		HDC hDCMem = CreateCompatibleDC(hDCScreen);
		HBITMAP hOldBitmap = (HBITMAP)::SelectObject(hDCMem, hBitmap);
		::BitBlt(hDCMem, 0, 0, nWidth, nHeight, hDCScreen, 0, 0, SRCCOPY);
		::SelectObject(hDCMem, hOldBitmap);

		BITMAP  bm;
		::GetObject(hBitmap, sizeof(BITMAP), &bm);// 获取位图信息
		DWORD   dwImageSize = bm.bmWidthBytes * bm.bmHeight;
		BITMAPINFOHEADER bih;// 设置位图信息头
		bih.biSize = sizeof(BITMAPINFOHEADER); // 位图信息头尺寸
		bih.biWidth = bm.bmWidth;     // 位图宽度
		bih.biHeight = bm.bmHeight;    // 位图高度
		bih.biBitCount = bm.bmBitsPixel; // 设置每像素所用字节数
		bih.biCompression = BI_RGB;
		bih.biPlanes = 1;
		bih.biSizeImage = dwImageSize;
		bih.biXPelsPerMeter = 0;
		bih.biYPelsPerMeter = 0;
		bih.biClrImportant = 0;
		bih.biClrUsed = 0;
		int ret = GetDIBits(hDCMem, hBitmap, 0, bih.biHeight, pTempData, (BITMAPINFO*)&bih, DIB_RGB_COLORS);
		
		/*glPixelStorei(GL_PACK_ALIGNMENT, 1);
		glReadPixels(0, 0, nSavedBufferWidth, nSavedBufferHeight, GL_RGBA, GL_UNSIGNED_BYTE, pTempData);*/

		pShotImage->initWithRawData(pTempData, nWidth * nHeight * bytePerPixel, nWidth, nHeight, 8);

		// 删除创建的资源
		::DeleteDC(hDCMem);
		::DeleteObject(hBitmap);
		::DeleteDC(hDCScreen);

	} while (0);
	//pShotImage->saveToFile("abc.png");
	CC_SAFE_DELETE_ARRAY(pTempData);

	(*pTexture)->initWithImage(pShotImage);
	CC_SAFE_DELETE(pShotImage);

	Sprite* pScreenShotSprite = Sprite::createWithTexture(*pTexture);
	pScreenShotSprite->setAnchorPoint(Vec2(0.5f, 0.5f));
	cocos2d::Size resolution = glview->getDesignResolutionSize();
	// 缩放至适合屏幕大小
	cocos2d::Size spriteSize = pScreenShotSprite->getContentSize();
	float scale = resolution.width / spriteSize.width;
	pScreenShotSprite->setScaleX(scale);
	pScreenShotSprite->setScaleY(-scale);
	//
	return pScreenShotSprite;
}
Exemplo n.º 14
0
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
        glview = GLView::create("aplicacion X");
		glview->setFrameSize(480, 800);
        director->setOpenGLView(glview);
    }

    // turn on display FPS
    director->setDisplayStats(false);

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);


	auto fileUtils = FileUtils::getInstance();
	auto screenSize = glview->getFrameSize();
	std::vector<std::string> resDirOrder;


	// vrificamos los deistintos dispositivos.

	if( 2048 == screenSize.width || 2048 ==screenSize.height )
	{
		resDirOrder.push_back("default");

		glview->setDesignResolutionSize(2048,1536, ResolutionPolicy::NO_BORDER);

	}


	else if(1024 == screenSize.width || 1024 == screenSize.height)
	{
	
		resDirOrder.push_back("default2");

		glview->setDesignResolutionSize(1024, 768, ResolutionPolicy::NO_BORDER);
	}


	else if(1136 == screenSize.width || 1136 == screenSize.height)
	{
	
		resDirOrder.push_back("default");

		glview->setDesignResolutionSize(1136, 640, ResolutionPolicy::NO_BORDER);
	}



		else if(960 == screenSize.width || 960 == screenSize.height)
	{
	
		resDirOrder.push_back("default");

		glview->setDesignResolutionSize(960, 640, ResolutionPolicy::NO_BORDER);
	}


		else
		{
		   
			resDirOrder.push_back("default");

			glview->setDesignResolutionSize(380, 650, ResolutionPolicy::NO_BORDER);
		   
		}

		fileUtils->setSearchPaths(resDirOrder);


    // create a scene. it's an autorelease object
    auto scene = HelloWorld::createScene();

    // run
    director->runWithScene(scene);

    return true;
}
Exemplo n.º 15
0
int modTM_FSH_Extract::svc() {
	svcStart_();

	TM_Transfer_Frame* frame = 0;

	while ( continueService() ) {
		ndSafeRelease(frame);

		std::pair<NetworkData*, int> queueTop = getData_();

		if ( msg_queue()->deactivated() ) break;

		if ( queueTop.second < 0 ) {
			MOD_ERROR("getData_() call failed.");
			continue;
		}
		else if ( ! queueTop.first ) {
			MOD_ERROR("getData_() returned with null data.");
			continue;
		}

		frame = dynamic_cast<TM_Transfer_Frame*>(queueTop.first);

		if ( !frame ) {
			MOD_ERROR("Received %d-octet buffer in %s wrapper (not TM_Transfer_Frame)! Must discard.",
				queueTop.first->getUnitLength(), queueTop.first->typeStr().c_str());
			ndSafeRelease(queueTop.first);
			continue;
		}

		queueTop.first = 0;

		MOD_DEBUG("Received %d-octet frame.", frame->getUnitLength());
		frame->setSecondaryHeaderLen(getFSHSize());

		// Test expected values.
		if (frame->getUnitLength() != getFrameSizeU()) {
			MOD_WARNING("TM Transfer Frame bad length: received %d octets, needed %d.", frame->getUnitLength(), getFrameSize());
			incBadLengthCount();
			if ( getDropBadFrames() ) continue;
		}
		else { incValidFrameCount(); }

		_extractAndSendFSH(frame);

		if ( links_[PrimaryOutputLink] ) {
			MOD_DEBUG("Sending a %d-octet TM Transfer Frame.", frame->getUnitLength());
			links_[PrimaryOutputLink]->send(frame);
			frame = 0; // important
		}
		else {
			MOD_ERROR("No output target defined, dropping frame.");
		}

		MOD_DEBUG("Finished processing incoming frame.");
	}

	return svcEnd_();
}
Exemplo n.º 16
0
int modAOS_OCF_Extract::svc() {
	svcStart_();

	AOS_Transfer_Frame* frame = 0;

	while ( continueService() ) {
		ndSafeRelease(frame);
		std::pair<NetworkData*, int> queueTop = getData_();

		if ( msg_queue()->deactivated() ) break;

		if ( queueTop.second < 0 ) {
			MOD_ERROR("getData_() call failed.");
			continue;
		}
		else if ( ! queueTop.first ) {
			MOD_ERROR("getData_() returned with null data.");
			continue;
		}

		frame = dynamic_cast<AOS_Transfer_Frame*>(queueTop.first);

		if ( ! frame ) {
			MOD_INFO("Received %d octets of non-AOS data! Dropping.", queueTop.first->getUnitLength());
			ndSafeRelease(queueTop.first);
			continue;
		}

		queueTop.first = 0;

		MOD_DEBUG("Received %d-octet frame.", frame->getUnitLength());
		frame->useOperationalControl(true);

		// Test expected values.
		if (frame->getUnitLength() != getFrameSizeU()) {
			MOD_WARNING("AOS Transfer Frame bad length: received %d octets, needed %d.", frame->getUnitLength(), getFrameSize());
			incBadLengthCount();
			if ( getDropBadFrames() ) continue;
		}
		else incValidFrameCount();

		_extractAndSendOCF(frame);

		if ( links_[PrimaryOutputLink] ) {
			MOD_DEBUG("Sending a %d-octet AOS Transfer Frame.", frame->getUnitLength());
			links_[PrimaryOutputLink]->send(frame);
			frame = 0; // important
		}
		else {
			MOD_ERROR("No output target defined, dropping frame.");
		}

		MOD_DEBUG("Finished processing incoming frame.");
	}

	return svcEnd_();
}
Exemplo n.º 17
0
status_t AMRSource::read(
        MediaBuffer **out, const ReadOptions *options) {
    *out = NULL;

    int64_t seekTimeUs;
    ReadOptions::SeekMode mode;
    if (mOffsetTableLength > 0 && options && options->getSeekTo(&seekTimeUs, &mode)) {
        size_t size;
        int64_t seekFrame = seekTimeUs / 20000ll;  // 20ms per frame.
        mCurrentTimeUs = seekFrame * 20000ll;

        size_t index = seekFrame < 0 ? 0 : seekFrame / 50;
        if (index >= mOffsetTableLength) {
            index = mOffsetTableLength - 1;
        }

        mOffset = mOffsetTable[index] + (mIsWide ? 9 : 6);

        for (size_t i = 0; i< seekFrame - index * 50; i++) {
            status_t err;
            if ((err = getFrameSizeByOffset(mDataSource, mOffset,
                            mIsWide, &size)) != OK) {
                return err;
            }
            mOffset += size;
        }
    }

    uint8_t header;
    ssize_t n = mDataSource->readAt(mOffset, &header, 1);

    if (n < 1) {
        return ERROR_END_OF_STREAM;
    }

    if (header & 0x83) {
        // Padding bits must be 0.

        ALOGE("padding bits must be 0, header is 0x%02x", header);

        return ERROR_MALFORMED;
    }

    unsigned FT = (header >> 3) & 0x0f;

    size_t frameSize = getFrameSize(mIsWide, FT);
    if (frameSize == 0) {
        return ERROR_MALFORMED;
    }

    MediaBuffer *buffer;
    status_t err = mGroup->acquire_buffer(&buffer);
    if (err != OK) {
        return err;
    }

    n = mDataSource->readAt(mOffset, buffer->data(), frameSize);

    if (n != (ssize_t)frameSize) {
        buffer->release();
        buffer = NULL;

        if (n < 0) {
            return ERROR_IO;
        } else {
            // only partial frame is available, treat it as EOS.
            mOffset += n;
            return ERROR_END_OF_STREAM;
        }
    }

    buffer->set_range(0, frameSize);
    buffer->meta_data()->setInt64(kKeyTime, mCurrentTimeUs);
    buffer->meta_data()->setInt32(kKeyIsSyncFrame, 1);

    mOffset += frameSize;
    mCurrentTimeUs += 20000;  // Each frame is 20ms

    *out = buffer;

    return OK;
}
Exemplo n.º 18
0
void KMagSelWin::setSelRect (const QRect &_selRect)
{
  QRect selRect = _selRect.normalized();

  if (selRect.left() < 0)
    selRect.setLeft (0);
  if (selRect.top() < 0)
    selRect.setTop (0);
  if (selRect.right() > QApplication::desktop()->width())
    selRect.setRight (QApplication::desktop()->width());
  if (selRect.bottom() > QApplication::desktop()->height())
    selRect.setBottom (QApplication::desktop()->height());

  setGeometry (
      selRect.left() - getFrameSize(),
      selRect.top() - getTitleSize() - 2,
      selRect.width() + getFrameSize() + getFrameSize(),
      selRect.height() + getFrameSize() + getTitleSize()+2);

  int w = getFrameSize();
  if (selRect.width() < w+w)
    w = static_cast<int>(selRect.width()/2);

  int h = getFrameSize();
  if (selRect.height() < h+h)
    h = static_cast<int>(selRect.height()/2);

  setMask (QRegion (QRect (0, 0, width(), height ()))
           - QRegion (QRect (getFrameSize(), getTitleSize()+2, selRect.width(), selRect.height()))
           - QRegion (QRect (0, 0, getFrameSize()+w, getTitleSize()+2-getFrameSize()))
           - QRegion (QRect (width()-getFrameSize()-w, 0, getFrameSize()+w, getTitleSize()+2-getFrameSize()))
           - QRegion (QRect (0, getTitleSize()+2+h, getFrameSize()-2, selRect.height()-h-h))
           - QRegion (QRect (width()-getFrameSize()+2, getTitleSize()+2+h, getFrameSize()-2, selRect.height()-h-h))
           - QRegion (QRect (getFrameSize()+w, height()-getFrameSize()+2, selRect.width()-w-w, getFrameSize()-2)));

  titleBar->setGeometry (getFrameSize()+w, 0, selRect.width()-h-h, getTitleSize());
  topLeftCorner->setGeometry (0, getTitleSize()+2-getFrameSize(), getFrameSize()+w, getFrameSize()+h);
  topRightCorner->setGeometry (width()-getFrameSize()-w, getTitleSize()+2-getFrameSize(), getFrameSize()+w, getFrameSize()+h);
  bottomLeftCorner->setGeometry (0, height()-getFrameSize()-h, getFrameSize()+w, getFrameSize()+h);
  bottomRightCorner->setGeometry (width()-getFrameSize()-w, height()-getFrameSize()-h, getFrameSize()+w, getFrameSize()+h);
}
Exemplo n.º 19
0
void EvilFish::advance() {
	if (_state == kStateNone)
		return;

	bool wasLastFrame = lastFrame();

	int16 oldX, oldY;
	getPosition(oldX, oldY);

	ANIObject::advance();

	int16 x, y, width, height;
	getFramePosition(x, y);
	getFrameSize(width, height);

	switch (_state) {
	case kStateNone:
		break;

	case kStateSwimLeft:
		if (!_shouldLeave && (x >= _screenWidth - width)) {
			setAnimation(_animTurnRight);
			setPosition(x, oldY);
			_state = kStateTurnRight;
		}

		if (_shouldLeave && (x >= _screenWidth)) {
			setVisible(false);

			_shouldLeave = false;
			_state       = kStateNone;
		}
		break;

	case kStateSwimRight:
		if (!_shouldLeave && (x <= 0)) {
			setAnimation(_animTurnLeft);
			setPosition(x, oldY);
			_state = kStateTurnLeft;
		}

		if (_shouldLeave && (x < -width)) {
			setVisible(false);

			_shouldLeave = false;
			_state       = kStateNone;
		}
		break;

	case kStateTurnLeft:
		if (wasLastFrame) {
			setAnimation(_animSwimLeft);
			_state = kStateSwimLeft;
		}
		break;

	case kStateTurnRight:
		if (wasLastFrame) {
			setAnimation(_animSwimRight);
			_state = kStateSwimRight;
		}
		break;

	case kStateDie:
		if (wasLastFrame) {
			setVisible(false);

			_state = kStateNone;
		}
		break;
	}
}
Exemplo n.º 20
0
bool AppDelegate::applicationDidFinishLaunching()
{
    // As an example, load config file
    // XXX: This should be loaded before the Director is initialized,
    // XXX: but at this point, the director is already initialized
    Configuration::getInstance()->loadConfigFile("configs/config-example.plist");

    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
        glview = GLView::create("Cpp Tests");
        director->setOpenGLView(glview);
    }

    director->setDisplayStats(true);
    director->setAnimationInterval(1.0 / 60);

    auto screenSize = glview->getFrameSize();

    auto designSize = Size(480, 320);

    auto fileUtils = FileUtils::getInstance();
    std::vector<std::string> searchPaths;
    
    if (screenSize.height > 320)
    {
        auto resourceSize = Size(960, 640);
        searchPaths.push_back("hd");
        searchPaths.push_back("ccs-res/hd");
        searchPaths.push_back("ccs-res/hd/scenetest");
        searchPaths.push_back("ccs-res/hd/scenetest/ArmatureComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/AttributeComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/BackgroundComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/EffectComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/LoadSceneEdtiorFileTest");
        searchPaths.push_back("ccs-res/hd/scenetest/ParticleComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/SpriteComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/TmxMapComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/UIComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/TriggerTest");
        searchPaths.push_back("ccs-res");
        director->setContentScaleFactor(resourceSize.height/designSize.height);
    }
    else
    {
        searchPaths.push_back("ccs-res");
        searchPaths.push_back("ccs-res/scenetest/ArmatureComponentTest");
        searchPaths.push_back("ccs-res/scenetest/AttributeComponentTest");
        searchPaths.push_back("ccs-res/scenetest/BackgroundComponentTest");
        searchPaths.push_back("ccs-res/scenetest/EffectComponentTest");
        searchPaths.push_back("ccs-res/scenetest/LoadSceneEdtiorFileTest");
        searchPaths.push_back("ccs-res/scenetest/ParticleComponentTest");
        searchPaths.push_back("ccs-res/scenetest/SpriteComponentTest");
        searchPaths.push_back("ccs-res/scenetest/TmxMapComponentTest");
        searchPaths.push_back("ccs-res/scenetest/UIComponentTest");
        searchPaths.push_back("ccs-res/scenetest/TriggerTest");
    }
    
    fileUtils->setSearchPaths(searchPaths);

#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
    // a bug in DirectX 11 level9-x on the device prevents ResolutionPolicy::NO_BORDER from working correctly
    glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::SHOW_ALL);
#else
    glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::NO_BORDER);
#endif

    auto scene = Scene::create();
    auto layer = new TestController();
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WP8) && (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
    layer->addConsoleAutoTest();
#endif
    layer->autorelease();
    layer->addConsoleAutoTest();
    scene->addChild(layer);
    director->runWithScene(scene);

    // Enable Remote Console
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
    auto console = director->getConsole();
    console->listenOnTCP(5678);
    Configuration *conf = Configuration::getInstance();
    bool isAutoRun = conf->getValue("cocos2d.x.testcpp.autorun", Value(false)).asBool();
    if(isAutoRun)
    {
        layer->startAutoRun();
    }
#endif
    
    return true;
}
                return;
            }

            ++numBytesRead;  // Include the frame type header byte.

            if (static_cast<size_t>(numBytesRead) > inHeader->nFilledLen) {
                // This is bad, should never have happened, but did. Abort now.

                notify(OMX_EventError, OMX_ErrorUndefined, 0, NULL);
                mSignalledError = true;

                return;
            }
        } else {
            int16 mode = ((inputPtr[0] >> 3) & 0x0f);
            size_t frameSize = getFrameSize(mode);
            CHECK_GE(inHeader->nFilledLen, frameSize);

            int16 frameType;
            RX_State_wb rx_state;
            mime_unsorting(
                    const_cast<uint8_t *>(&inputPtr[1]),
                    mInputSampleBuffer,
                    &frameType, &mode, 1, &rx_state);

            int16_t *outPtr = (int16_t *)outHeader->pBuffer;

            int16_t numSamplesOutput;
            pvDecoder_AmrWb(
                    mode, mInputSampleBuffer,
                    outPtr,
Exemplo n.º 22
0
    void GameManager::initDisplay() {
		// initialize director
		auto director = Director::getInstance();
		auto glview = director->getOpenGLView();
        
        
        if(!glview){
            glview = GLView::create("MyGame");
            director->setOpenGLView(glview);
        }
        
        // Set the design resolution
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
        // a bug in DirectX 11 level9-x on the device prevents ResolutionPolicy::NO_BORDER from working correctly
        glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::SHOW_ALL);
#else
        glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
#endif
        
        Size frameSize = glview->getFrameSize();
        
        vector<string> searchPath;
        
        searchPath.push_back("images/common");
        searchPath.push_back("fonts");
        searchPath.push_back("sounds");
        searchPath.push_back("sounds/altp");
         searchPath.push_back("sounds/altp/play");
        searchPath.push_back("configs");
        // In this demo, we select resource according to the frame's height.
        // If the resource size is different from design resolution size, you need to set contentScaleFactor.
        // We use the ratio of resource's height to the height of design resolution,
        // this can make sure that the resource's height could fit for the height of design resolution.
        
        // if the frame's height is larger than the height of medium resource size, select large resource.
        if (frameSize.height > mediumResource.size.height)
        {
            searchPath.push_back(largeResource.directory);
            
            director->setContentScaleFactor(MIN(largeResource.size.height/designResolutionSize.height, largeResource.size.width/designResolutionSize.width))
            ;
                   }
        // if the frame's height is larger than the height of small resource size, select medium resource.
        else if (frameSize.height > smallResource.size.height)
        {
            searchPath.push_back(mediumResource.directory);
            
            director->setContentScaleFactor(MIN(mediumResource.size.height/designResolutionSize.height, mediumResource.size.width/designResolutionSize.width));
            
                  }
        // if the frame's height is smaller than the height of medium resource size, select small resource.
        else
        {
            searchPath.push_back(smallResource.directory);
            
            director->setContentScaleFactor(MIN(smallResource.size.height/designResolutionSize.height, smallResource.size.width/designResolutionSize.width));
            
           

        }
        
        // set searching path
        FileUtils::getInstance()->setSearchPaths(searchPath);
      
    
   
        
        // turn on display FPS
		//director->setDisplayStats(true);
		
		// set FPS. the default value is 1.0/60 if you don't call this
		//director->setAnimationInterval(1.0 / 60);

	}
Exemplo n.º 23
0
void TimeLineCells::mouseMoveEvent( QMouseEvent* event )
{
    if ( m_eType == TIMELINE_CELL_TYPE::Layers )
    {
        endY = event->pos().y();
        emit mouseMovedY( endY - startY );
    }
    int frameNumber = getFrameNumber( event->pos().x() );
    //int layerNumber = getLayerNumber( event->pos().y() );

    if ( m_eType == TIMELINE_CELL_TYPE::Tracks )
    {
        if ( primaryButton == Qt::MidButton )
        {
            // qMin( max_frame_offset, qMax ( min_frame_offset, draw_frame_offset ) )
            frameOffset = qMin( qMax( 0, frameLength - width() / getFrameSize() ), qMax( 0, frameOffset + lastFrameNumber - frameNumber ) );
            update();
            emit offsetChanged( frameOffset );
        }
        else
        {
            if ( timeLine->scrubbing )
            {
                mEditor->scrubTo( frameNumber );
            }
            else
            {
                if ( startLayerNumber != -1 && startLayerNumber < mEditor->object()->getLayerCount() )
                {
                    Layer *currentLayer = mEditor->object()->getLayer(startLayerNumber);

                    // Did we move to another frame ?
                    //
                    if ( frameNumber != lastFrameNumber ) {

                        // Check if the frame we clicked was selected
                        //
                        if ( canMoveFrame ) {

                            // If it is the case, we move the selected frames in the layer
                            //
                            movingFrames        = true;

                            int offset = frameNumber - lastFrameNumber;
                            currentLayer->moveSelectedFrames(offset);

                            mEditor->updateCurrentFrame();

                        }
                        else if ( canBoxSelect ){

                            // Otherwise, we do a box select
                            //
                            boxSelecting        = true;

                            currentLayer->deselectAll();
                            currentLayer->setFrameSelected(startFrameNumber, true);
                            currentLayer->extendSelectionTo(frameNumber);
                        }

                        lastFrameNumber = frameNumber;
                    }

                    currentLayer->mouseMove( event, frameNumber );
                }
            }
        }
    }
    timeLine->update();
}
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
        glview = GLViewImpl::create("My Game");
        director->setOpenGLView(glview);
    }
    
    // turn on display FPS
    director->setDisplayStats(false);
    
    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);
    
    // MULTI RESOLUTION SUPPORT FOR V3
    // Credits: http://becomingindiedev.blogspot.com/2014/05/multi-resolution-support-in-ios-with.html
    auto screenSize = glview->getFrameSize();
    
    auto fileUtils = FileUtils::getInstance();
    std::vector<std::string> searchPaths;
    
    if (screenSize.width == 2048 || screenSize.height == 2048)
    {
        glview -> setDesignResolutionSize(1536, 2048, ResolutionPolicy::NO_BORDER);
        searchPaths.push_back("ipadhd");
        searchPaths.push_back("ipadsd");
        searchPaths.push_back("iphone5");
        searchPaths.push_back("iphonehd");
        searchPaths.push_back("iphonesd");
    }
    else if (screenSize.width == 1024 || screenSize.height == 1024)
    {
        glview -> setDesignResolutionSize(768, 1024, ResolutionPolicy::NO_BORDER);
        searchPaths.push_back("ipadsd");
        searchPaths.push_back("iphone5");
        searchPaths.push_back("iphonehd");
        searchPaths.push_back("iphonesd");
        
    }
    else if (screenSize.width == 1136 || screenSize.height == 1136)
    {
        glview -> setDesignResolutionSize(640, 1136, ResolutionPolicy::NO_BORDER);
        searchPaths.push_back("iphone5");
        searchPaths.push_back("iphonehd");
        searchPaths.push_back("iphonesd");
        
    }
    else if (screenSize.width == 960 || screenSize.height == 960)
    {
        glview -> setDesignResolutionSize(640, 960, ResolutionPolicy::NO_BORDER);
        searchPaths.push_back("iphonehd");
        searchPaths.push_back("iphonesd");
    }
    else
    {
        searchPaths.push_back("iphonesd");
        glview -> setDesignResolutionSize(320, 480, ResolutionPolicy::NO_BORDER);
    }
    
    fileUtils->setSearchPaths(searchPaths);
    
    // create a scene. it's an autorelease object
    
    // run
    auto scene = WelcomeScene::createScene();
    director->runWithScene(scene);
    
    return true;
}
Exemplo n.º 25
0
vector<string> ProjectConfig::makeCommandLineVector(unsigned int mask /* = kProjectConfigAll */) const
{
    vector<string> ret;

    stringstream buff;

    if (mask & kProjectConfigProjectDir)
    {
        auto path = getProjectDir();
        if (path.length())
        {
            ret.push_back("-workdir");
            ret.push_back(dealWithSpaceWithPath(path));
        }
    }

    if (mask & kProjectConfigScriptFile)
    {
        auto path = getScriptFileRealPath();
        if (path.length())
        {
            ret.push_back("-entry");
            ret.push_back(dealWithSpaceWithPath(path));
        }
    }

    if (mask & kProjectConfigWritablePath)
    {
        auto path = getWritableRealPath();
        if (path.length())
        {
            ret.push_back("-writable-path");
            ret.push_back(dealWithSpaceWithPath(path));
        }
    }

    if (mask & kProjectConfigFrameSize)
    {
        buff.str("");
        buff << (int)getFrameSize().width;
        buff << "x";
        buff << (int)getFrameSize().height;

        ret.push_back("-resolution");
        ret.push_back(buff.str());
    }

    if (mask & kProjectConfigFrameScale)
    {
        if (getFrameScale() < 1.0f)
        {
            buff.str("");
            buff.precision(2);
            buff << getFrameScale();

            ret.push_back("-scale");
            ret.push_back(buff.str());
        }
    }

    if (mask & kProjectConfigWriteDebugLogToFile)
    {
        if (isWriteDebugLogToFile())
        {
            ret.push_back("-write-debug-log");
            ret.push_back(getDebugLogFilePath());
        }
    }

    if (mask & kProjectConfigShowConsole)
    {
        if (isShowConsole())
        {
            ret.push_back("-console");
            ret.push_back("enable");
        }
        else
        {
            ret.push_back("-console");
            ret.push_back("disable");
        }
    }

    if (mask & kProjectConfigWindowOffset)
    {
        if (_windowOffset.x != 0 && _windowOffset.y != 0)
        {
            buff.str("");
            buff << (int)_windowOffset.x;
            buff << ",";
            buff << (int)_windowOffset.y;
            buff << "";

            ret.push_back("-position");
            ret.push_back(buff.str());
        }
    }

    if (mask & kProjectConfigDebugger)
    {
        switch (getDebuggerType())
        {
            case kCCRuntimeDebuggerCodeIDE:
                ret.push_back("-debugger");
                ret.push_back("codeide");
                break;
            case kCCRuntimeDebuggerStudio:
                ret.push_back("-debugger");
                ret.push_back("studio");
                break;
        }
    }

    if (mask & kProjectConfigListen)
    {
        if (!_bindAddress.empty())
        {
            ret.push_back("-listen");
            ret.push_back(_bindAddress);
        }
    }

    if (mask & kProjectConfigSearchPath)
    {
        if (_searchPath.size() > 0)
        {
            stringstream pathbuff;
            for (auto &path : _searchPath)
            {
                pathbuff << dealWithSpaceWithPath(path) << ";";
            }
            string pathArgs = pathbuff.str();
            pathArgs[pathArgs.length()-1] = '\0';

            ret.push_back("-search-path");
            ret.push_back(pathArgs);
        }
    }

    if (mask & kProjectConfigFirstSearchPath)
    {
        if (_searchPath.size() > 0)
        {
            stringstream pathbuff;
            for (auto &path : _searchPath)
            {
                pathbuff << dealWithSpaceWithPath(path) << ";";
            }
            string pathArgs = pathbuff.str();
            pathArgs[pathArgs.length() - 1] = '\0';

            ret.push_back("-first-search-path");
            ret.push_back(pathArgs);
        }
    }
    return ret;
}
Exemplo n.º 26
0
bool AppDelegate::applicationDidFinishLaunching()
{
	// initialize director
	auto director = Director::getInstance();
	auto glview = director->getOpenGLView();
	if (!glview)
	{
		glview = GLView::createWithRect("Flappy Ponta", cocos2d::Rect(0, 0, 480, 640), 1);
		director->setOpenGLView(glview);
	}
	
	glview->setDesignResolutionSize(AppDelegate::BASE_WIDTH, AppDelegate::BASE_HEIGHT, ResolutionPolicy::NO_BORDER);
	cocos2d::Size frameSize = glview->getFrameSize();
	
	cocos2d::log("frame size %f, %f", frameSize.width, frameSize.height);
	
	std::vector<std::string> searchPath;
	if (frameSize.height >= 1920) {
		this->resolutionScale = AppDelegate::SCALE_XXH_RES;
		searchPath.push_back("gfx/xxh_res");
	} else if (frameSize.height >= 1280) {
		this->resolutionScale = AppDelegate::SCALE_XH_RES;
		searchPath.push_back("gfx/xh_res");
	} else if (frameSize.height >= 960) {
		this->resolutionScale = AppDelegate::SCALE_H_RES;
		searchPath.push_back("gfx/h_res");
	} else if (frameSize.height >= 640) {
		this->resolutionScale = AppDelegate::SCALE_M_RES;
		searchPath.push_back("gfx/m_res");
	} else {
		this->resolutionScale = AppDelegate::SCALE_L_RES;
		searchPath.push_back("gfx/l_res");
	}
	searchPath.push_back("gfx/all_res");
	searchPath.push_back("sfx");
	
	FileUtils::getInstance()->setSearchPaths(searchPath);
	
	cocos2d::log("resolution scale %f, %f", resolutionScale, (AppDelegate::BASE_WIDTH * this->resolutionScale) / AppDelegate::BASE_WIDTH);
	
	director->setContentScaleFactor(this->resolutionScale);
	
	// turn on display FPS
	director->setDisplayStats(false);
	
	// set FPS. the default value is 1.0/60 if you don't call this
	director->setAnimationInterval(1.0 / 60);
	
	pluginAnalytics = dynamic_cast<cocos2d::plugin::ProtocolAnalytics*>
			(cocos2d::plugin::PluginManager::getInstance()->loadPlugin("GoogleAnalytics"));
	pluginAnalytics->setDebugMode(false);
	pluginAnalytics->startSession("UA-55456421-4");
	pluginAnalytics->setCaptureUncaughtException(true);
	pluginAnalytics->setSessionContinueMillis(300);
	
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
	const char *pluginName = "AppleGameCenter";
#else
	const char *pluginName = "GpsGames";
#endif
	pluginGameServices = dynamic_cast<cocos2d::plugin::ProtocolGameServices*>
			(cocos2d::plugin::PluginManager::getInstance()->loadPlugin(pluginName));
	pluginGameServices->setDebugMode(false);
	pluginGameServices->startSession();
	
	auto scene = LoadingScene::create();
	director->runWithScene(scene);
	
	return true;
}
Exemplo n.º 27
0
	/// Override BaseTrafficHandler::getMTU() to return frameSize_ instead of MTU_.
	size_t getMTU() const { return getFrameSize(); }
Exemplo n.º 28
0
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
		glview = GLViewImpl::createWithRect( "Framework", Rect( 0, 0, designResolutionSize.width, designResolutionSize.height ) );
#else
        glview = GLViewImpl::create("My Game");
#endif
        director->setOpenGLView(glview);
    }

#ifdef FORCE_DEBUG
    // turn on display FPS
    director->setDisplayStats(true);
#endif

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);

    // Set the design resolution
    glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
    Size frameSize = glview->getFrameSize();
    // if the frame's height is larger than the height of medium size.
    if (frameSize.height > mediumResolutionSize.height)
    {        
        director->setContentScaleFactor(MIN(largeResolutionSize.height/designResolutionSize.height, largeResolutionSize.width/designResolutionSize.width));
    }
    // if the frame's height is larger than the height of small size.
    else if (frameSize.height > smallResolutionSize.height)
    {        
        director->setContentScaleFactor(MIN(mediumResolutionSize.height/designResolutionSize.height, mediumResolutionSize.width/designResolutionSize.width));
    }
    // if the frame's height is smaller than the height of medium size.
    else
    {        
        director->setContentScaleFactor(MIN(smallResolutionSize.height/designResolutionSize.height, smallResolutionSize.width/designResolutionSize.width));
    }

    register_all_packages();

    // create a scene. it's an autorelease object
    auto scene = TitleScene::create();

    // run
	SceneManager::getInstance()->replaceScene( scene );
    //director->runWithScene(scene);

	//data init
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)

	sql_manager::set_db("");

#elif (CC_TARGET_PLATFORM ==CC_PLATFORM_WIN32)
	sql_manager::set_db((const char*)"./db/rayjack");
	accessor::init();
	//	CCLOG("");

#endif


    return true;
}
const string ProjectConfig::makeCommandLine(unsigned int mask /* = kProjectConfigAll */)
{
    stringstream buff;

    if (mask & kProjectConfigQuickRootPath)
    {
        const string path = SimulatorConfig::sharedDefaults()->getQuickCocos2dxRootPath();
        if (path.length())
        {
            buff << " -quick ";
            buff << path;
        }
    }

    if (mask & kProjectConfigProjectDir)
    {
		const string path = getProjectDir();
		if (path.length())
		{
			buff << " -workdir ";
			buff << path;
		}
    }

    if (mask & kProjectConfigScriptFile)
    {
		const string path = getScriptFileRealPath();
		if (path.length())
		{
			buff << " -file ";
			buff << path;
		}
    }

    if (mask & kProjectConfigWritablePath)
    {
		const string path = getWritableRealPath();
		if (path.length())
		{
			buff << " -writable ";
			buff << path;
		}
    }

    if (mask & kProjectConfigPackagePath)
    {
        const string packagePath = getPackagePath();
        if (packagePath.length())
        {
            buff << " -package.path ";
            buff << packagePath;
        }
    }

    if (mask & kProjectConfigFrameSize)
    {
        buff << " -size ";
        buff << (int)getFrameSize().width;
        buff << "x";
        buff << (int)getFrameSize().height;
    }

    if (mask & kProjectConfigFrameScale)
    {
        if (getFrameScale() < 1.0f)
        {
            buff << " -scale ";
            buff.precision(2);
            buff << getFrameScale();
        }
    }

    if (mask & kProjectConfigWriteDebugLogToFile)
    {
        if (isWriteDebugLogToFile())
        {
            buff << " -write-debug-log";
        }
        else
        {
            buff << " -disable-write-debug-log";
        }
    }

    if (mask & kProjectConfigShowConsole)
    {
        if (isShowConsole())
        {
            buff << " -console";
        }
        else
        {
            buff << " -disable-console";
        }
    }

    if (mask & kProjectConfigLoadPrecompiledFramework)
    {
        if (isLoadPrecompiledFramework())
        {
            buff << " -load-framework";
        }
        else
        {
            buff << " -disable-load-framework";
        }
    }

    if (mask & kProjectConfigWindowOffset)
    {
        if (m_windowOffset.x != 0 && m_windowOffset.y != 0)
        {
            buff << " -offset {";
            buff << (int)m_windowOffset.x;
            buff << ",";
            buff << (int)m_windowOffset.y;
            buff << "}";
        }
    }

    if (mask & kProjectConfigDebugger)
    {
        switch (getDebuggerType())
        {
            case kCCLuaDebuggerLDT:
                buff << " -debugger-ldt";
                break;
            case kCCLuaDebuggerNone:
            default:
                buff << " -disable-debugger";
        }
    }

    return buff.str();
}
Exemplo n.º 30
0
bool AppDelegate::applicationDidFinishLaunching() {
	// initialize director
	auto director = Director::getInstance();
	auto glview = director->getOpenGLView();
	if (!glview) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
		glview = GLViewImpl::createWithRect("hw9", Rect(0, 0, designResolutionSize.width, designResolutionSize.height));
#else
		glview = GLViewImpl::create("hw9");
#endif
		director->setOpenGLView(glview);
	}

	// turn on display FPS
	director->setDisplayStats(false);

	// set FPS. the default value is 1.0/60 if you don't call this
	director->setAnimationInterval(1.0 / 60);

	// Set the design resolution
	glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::EXACT_FIT);
	Size frameSize = glview->getFrameSize();
	// if the frame's height is larger than the height of medium size.
	if (frameSize.height > mediumResolutionSize.height)
	{
		director->setContentScaleFactor(MIN(largeResolutionSize.height / designResolutionSize.height, largeResolutionSize.width / designResolutionSize.width));
	}
	// if the frame's height is larger than the height of small size.
	else if (frameSize.height > smallResolutionSize.height)
	{
		director->setContentScaleFactor(MIN(mediumResolutionSize.height / designResolutionSize.height, mediumResolutionSize.width / designResolutionSize.width));
	}
	// if the frame's height is smaller than the height of medium size.
	else
	{
		director->setContentScaleFactor(MIN(smallResolutionSize.height / designResolutionSize.height, smallResolutionSize.width / designResolutionSize.width));
	}

	register_all_packages();



	// load game resource
	SpriteFrameCache::getInstance()->addSpriteFramesWithFile("general-sheet.plist");
	char totalFrames = 3;
	char frameName[20];
	Animation* legAnimation = Animation::create();

	for (int i = 0; i < totalFrames; i++) {
		sprintf(frameName, "miner-leg-%d.png", i);
		legAnimation->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(frameName));
	}

	legAnimation->setDelayPerUnit(0.1);
	AnimationCache::getInstance()->addAnimation(legAnimation, "legAnimation");

	Animation* caveAnimation = Animation::create();

	for (int i = 0; i < totalFrames; i++) {
		sprintf(frameName, "cave-%d.png", i);
		caveAnimation->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(frameName));
	}

	caveAnimation->setDelayPerUnit(0.1);
	AnimationCache::getInstance()->addAnimation(caveAnimation, "caveAnimation");

	auto scene = MenuSence::createScene();
	// run
	director->runWithScene(scene);

	return true;
}