예제 #1
0
파일: wyNode.cpp 프로젝트: nbolabs/WiEngine
void wyNode::cleanup() {
    // stop all actions
    stopAllActions(false);

    // clear selectors
    if(m_timers != NULL) {
        wyArrayEach(m_timers, releaseTimer, NULL);
        wyArrayClear(m_timers);
    }

    // cleanup children
    wyArrayEach(m_children, sCleanup, NULL);
}
예제 #2
0
wyBladeRibbon::~wyBladeRibbon() {
	wyObjectRelease(m_texture);

	wyArrayEach(m_dyingBlades, releaseBlade, NULL);
	wyArrayDestroy(m_dyingBlades);

	wyArrayEach(m_reusableBlades, releaseBlade, NULL);
	wyArrayDestroy(m_reusableBlades);

	if(m_blade) {
		WYDELETE(m_blade);
		m_blade = NULL;
	}
}
예제 #3
0
파일: wyNode.cpp 프로젝트: nbolabs/WiEngine
void wyNode::onExit() {
    if(m_running) {
        if(m_touchEnabled)
            gEventDispatcher->removeTouchHandlerLocked(this);

        if(m_keyEnabled)
            gEventDispatcher->removeKeyHandlerLocked(this);

        if(m_accelerometerEnabled)
            gEventDispatcher->removeAccelHandlerLocked(this);

        if(m_gestureEnabled)
            gEventDispatcher->removeGestureHandlerLocked(this);

        if(m_doubleTabEnabled)
            gEventDispatcher->removeDoubleTapHandlerLocked(this);

        deactivateTimers();
        m_running = false;

        // make children exit
        wyArrayEach(m_children, sOnExit, NULL);

#if ANDROID
        // if java layer implemention is set, callback
        if(m_jVirtualMethods != NULL && g_mid_INodeVirtualMethods_jOnExit != 0) {
            JNIEnv* env = getEnv();
            env->CallVoidMethod(m_jVirtualMethods, g_mid_INodeVirtualMethods_jOnExit);
        }
#endif
    }
}
예제 #4
0
파일: wyNode.cpp 프로젝트: nbolabs/WiEngine
void wyNode::onEnter() {
    if(!m_running) {
        if(m_touchEnabled)
            gEventDispatcher->addTouchHandlerLocked(this, m_touchPriority);

        if(m_keyEnabled)
            gEventDispatcher->addKeyHandlerLocked(this, m_keyPriority);

        if(m_gestureEnabled)
            gEventDispatcher->addGestureHandlerLocked(this, m_gesturePriority);

        if(m_doubleTabEnabled)
            gEventDispatcher->addDoubleTapHandlerLocked(this, m_doubleTapPriority);

        if(m_accelerometerEnabled)
            gEventDispatcher->addAccelHandlerLocked(this, m_accelerometerPriority);

        wyArrayEach(m_children, sOnEnter, NULL);
        activateTimers();
        m_running = true;

#if ANDROID
        // if java layer implemention is set, callback
        if(m_jVirtualMethods != NULL && g_mid_INodeVirtualMethods_jOnEnter != 0) {
            JNIEnv* env = getEnv();
            env->CallVoidMethod(m_jVirtualMethods, g_mid_INodeVirtualMethods_jOnEnter);
        }
#endif
    }
}
예제 #5
0
wyBitmapFontLabel::~wyBitmapFontLabel() {
    if(m_text) {
    	wyFree((void*)m_text);
    }

    wyArrayEach(m_atlasList, releaseAtlas, NULL);
    wyArrayDestroy(m_atlasList);
}
예제 #6
0
파일: wyNode.cpp 프로젝트: nbolabs/WiEngine
void wyNode::onEnterTransitionDidFinish() {
    wyArrayEach(m_children, sOnEnterTransitionDidFinish, NULL);

#if ANDROID
    // if java layer implemention is set, callback
    if(m_jVirtualMethods != NULL && g_mid_INodeVirtualMethods_jOnEnterTransitionDidFinish != 0) {
        JNIEnv* env = getEnv();
        env->CallVoidMethod(m_jVirtualMethods, g_mid_INodeVirtualMethods_jOnEnterTransitionDidFinish);
    }
#endif
}
예제 #7
0
wyResultSet::~wyResultSet() {
	// close
	close();

	// free sql
	wyFree((void*)m_sql);

	// free column names
	wyArrayEach(m_columnNames, releaseColumn, NULL);
	wyArrayDestroy(m_columnNames);
}
예제 #8
0
void wyPageControl::removeAllPages() {
	for(int i = 0; i < m_pages->num; i++) {
		wyNode* page = (wyNode*)wyArrayGet(m_pages, i);
		m_container->removeChildLocked(page, true);
	}
	wyArrayEach(m_pages, releasePage, NULL);
	wyArrayClear(m_pages);

	// notify indicator
	if(m_indicator)
		m_indicator->onPageAllRemoved();
}
예제 #9
0
wyPageControl::~wyPageControl() {
#if ANDROID
	if(m_jCallback != NULL) {
		JNIEnv* env = wyUtils::getJNIEnv();
		env->DeleteGlobalRef(m_jCallback);
		m_jCallback = NULL;
	}
#endif

	m_scroller->release();
	wyArrayEach(m_pages, releasePage, NULL);
	wyArrayDestroy(m_pages);
}
예제 #10
0
파일: wyNode.cpp 프로젝트: nbolabs/WiEngine
wyNode::~wyNode() {
    // nullify parent
    m_parent = NULL;

#if ANDROID
    // clear handers
    setJavaVirtualMethods(NULL);
    setJavaTouchHandler(NULL);
    setJavaKeyHandler(NULL);
    setJavaAccelHandler(NULL);
    setJavaDoubleTapHandler(NULL);
    setJavaGestureHandler(NULL);
#endif

    // remove from physics node queue
    if(m_velocityX != 0 || m_velocityY != 0 || m_accelerationX != 0 || m_accelerationY != 0) {
        if(gActionManager != NULL)
            gActionManager->removePhysicsNode(this);
    }

    // release members
    wyObjectRelease(m_camera);
    wyObjectRelease(m_grid);
    wyObjectRelease(m_downSelector);
    wyObjectRelease(m_upSelector);
    wyObjectRelease(m_moveOutSelector);
    removeAllChildrenLocked(true);
    wyArrayDestroy(m_children);
    m_children = NULL;
    if(m_timers != NULL) {
        wyArrayEach(m_timers, releaseTimer, NULL);
        wyArrayDestroy(m_timers);
        m_timers = NULL;
    }
    if(m_positionListener != NULL) {
        wyFree(m_positionListener);
        m_positionListener = NULL;
    }
#if ANDROID
    if(m_dataIsJavaObject) {
        JNIEnv* env = getEnv();
        env->DeleteGlobalRef(m_data.jo);
        m_dataIsJavaObject = false;
    }
    if(m_jPositionListener != NULL) {
        JNIEnv* env = getEnv();
        env->DeleteGlobalRef(m_jPositionListener);
        m_jPositionListener = NULL;
    }
#endif
}
예제 #11
0
void wyDirector_android::notifyDirectorResumed() {
    wyDirector::notifyDirectorResumed();
    wyArrayEach(m_jLifecycleListeners, j_notifyDirectorResumed, NULL);
}
예제 #12
0
void wyDirector_android::notifyDirectorScreenCaptured() {
    wyDirector::notifyDirectorScreenCaptured();
    wyArrayEach(m_jLifecycleListeners, j_notifyDirectorScreenCaptured, NULL);
}
예제 #13
0
void wyDirector_android::notifySurfaceDestroyed() {
    wyDirector::notifySurfaceDestroyed();
    wyArrayEach(m_jLifecycleListeners, j_notifySurfaceDestroyed, NULL);
}
예제 #14
0
wyDirector_android::~wyDirector_android() {
    // if background running is enabled
    if(m_allowBackgroundRunning) {
        pthread_mutex_lock(&gCondMutex);
        if(m_backgroundRunning) {
            if(pthread_cond_init(&sBackgroundLooperCond, NULL) == 0) {
                m_backgroundRunning = false;
                pthread_cond_wait(&sBackgroundLooperCond, &gCondMutex);
                pthread_cond_destroy(&sBackgroundLooperCond);
            }
        }
        pthread_mutex_unlock(&gCondMutex);
    }

    // call gl view
    JNIEnv* env = wyUtils::getJNIEnv();
    if(env != NULL) {
        if(m_glView != NULL) {
            if(!m_paused)
                env->CallVoidMethod(m_glView, g_mid_WYGLSurfaceView_onPause);
            env->DeleteGlobalRef(m_glView);
            m_glView = NULL;
        }
    }

    // if resource decoder is set, check whether it is wyJavaResourceDecoder
    if(gResDecoder) {
        wyJavaResourceDecoder* jrd = dynamic_cast<wyJavaResourceDecoder*>(gResDecoder);
        if(jrd)
            delete jrd;
    }

    // common destroy
    commonDestroy();

    // release listener
    wyArrayEach(m_jLifecycleListeners, j_releaseListener, NULL);
    wyArrayDestroy(m_jLifecycleListeners);

    // deinit aal
    if(gAAL.deinit)
        gAAL.deinit();

    // delete context ref
    if(env != NULL) {
        if(m_context != NULL) {
            env->DeleteGlobalRef(m_context);
            m_context = NULL;
        }
    }

    // global deinit
    globalDeInit(env);

    // unload sal lib
    if(sAALHandler != NULL) {
        /*
         * 不要close这个东西, 可能是因为android底层有什么bug, 导致重复载入卸载45
         * 次之后就会出现问题. 而android上的dlopen又不支持RTLD_NODELETE这个flag,
         * 所以只能不close它, 就没事了
         */
//		dlclose(sAALHandler);
        sAALHandler = NULL;
    }

    // nullify gVM
    gVM = NULL;

    // free my self
    gDirector = NULL;
}
예제 #15
0
파일: wyNode.cpp 프로젝트: nbolabs/WiEngine
void wyNode::deactivateTimers() {
    if(m_timers != NULL)
        wyArrayEach(m_timers, deactivateTimer, NULL);

    gActionManager->pauseActions(this, false);
}
예제 #16
0
void wyDirector::notifySurfaceDestroyed() {
	wyArrayEach(m_lifecycleListeners, notifySurfaceDestroyed, m_lifecycleData);
}
예제 #17
0
void wyDirector::notifyDirectorScreenCaptured() {
	wyArrayEach(m_lifecycleListeners, notifyDirectorScreenCaptured, m_lifecycleData);
}
예제 #18
0
void wyDirector::notifyDirectorEnded() {
	wyArrayEach(m_lifecycleListeners, notifyDirectorEnded, m_lifecycleData);
}
예제 #19
0
wyCombineColorFilter::~wyCombineColorFilter() {
	wyArrayEach(m_filters, releaseFilter, NULL);
	wyArrayDestroy(m_filters);
}
예제 #20
0
void wyDirector::commonDestroy() {
	g_Director_isEnding = true;

	// notify listener
	notifyDirectorEnded();
	
	// stop dispatch events and remove all handlers
	gEventDispatcher->setDispatchEvent(false);

	// remove all textures
	gTextureManager->removeAllTextures();

	// remove all actions
	gActionManager->removeAllActionsLocked();

	// release auto release pool
	wyDestroyAutoReleasePool();

	// free members
	wyObjectRelease(m_fpsLabel);
	if(m_runningScene != NULL) {
		m_runningScene->onExit();
		m_runningScene->cleanup();
	}
	if(m_screenshotPath != NULL) {
		wyFree((void*)m_screenshotPath);
		m_screenshotPath = NULL;
	}
	setRunningScene(NULL);
	setNextScene(NULL);
	wyArrayEach(m_scenesStack, releaseScene, NULL);
	wyArrayDestroy(m_scenesStack);
	wyArrayDestroy(m_lifecycleListeners);
	wyFree(m_clipStack);

	// clear singleton instance
	wyObjectRelease(gTextureManager);
	wyObjectRelease(gScheduler);
	wyObjectRelease(gEventDispatcher);
	wyObjectRelease(gActionManager);
	wyObjectRelease(gZwoptexManager);
	wyObjectRelease(gMWManager);
	wyObjectRelease(gSPXManager);
	wyObjectRelease(gSPX3Manager);
	wyObjectRelease(gArcticManager);
	wyObjectRelease(gAuroraManager);
	wyBitmapFont::unloadAll();
    wyToast::clear();

    // clear resource decoder
	gResDecoder = NULL;

	// now flush all existing auto release pool
	wyAutoReleasePool::flush();

	// free mutex
	pthread_mutex_destroy(&gMutex);
	pthread_mutex_destroy(&gCondMutex);
	
	// check leak
#ifdef WY_CFLAG_MEMORY_TRACKING
	wyOutputLeakPool();
	wyClearLeakPool();

	printUnreleasedMemory(true);
#endif
}
예제 #21
0
void wyBitmapFontLabel::updateContentSize() {
	// remove all quads in all atlas
	wyArrayEach(m_atlasList, clearAtlas, NULL);

	// if null, do nothing
	if(!m_text)
		return;

	// break line into a vector
	vector<const char*>* lines = wyUtils::breakLines(m_text, m_font, m_lineWidth, m_spaceWidth, m_tabSize);

	// get width first because we need support text alignment
	vector<float>* widthList = measureWidth(lines);
	
	// get max width
	float maxWidth = 0;
	for(vector<float>::iterator iter = widthList->begin(); iter != widthList->end(); iter++) {
		maxWidth = MAX(maxWidth, *iter);
	}
	
	// line number
	int line = 0;
	
	// real width of final render
	float width = 0;

	// final render y position
	float y = 0;

	// prev line height
	float prevLineHeight = 0;

	// render line one by one
	for(vector<const char*>::iterator iter = lines->begin(); iter != lines->end(); iter++, line++) {
		char* p = (char*)(*iter);
		float x = 0;
		float lineOffset = 0;
		float charWidth, charHeight;
		bool firstLineChar = true;
		float currentLineHeight = 0;

		// line offset
		switch(m_alignment) {
			case LEFT:
				lineOffset = 0;
				break;
			case CENTER:
				lineOffset = (maxWidth - widthList->at(line)) / 2;
				break;
			case RIGHT:
				lineOffset = maxWidth - widthList->at(line);
				break;
		}

		// if first char of this line, add line spacing
		if(line > 0) {
			y += m_lineSpacing;
			if(prevLineHeight == 0)
				y += m_font->getEmptyLineHeight();
			else
				y += prevLineHeight;
		}

	    while(*p != 0) {
	    	// get char integer
	    	int c = 0;
	    	int b = wyUtils::getUTF8Bytes(*p);
	    	while(b-- > 0) {
	    		c <<= 8;
	    		c |= *p & 0xff;
	    		p++;
	    	}

	        wyCharInfo* pCi = m_font->getCharInfo(c);
	        if(pCi) {
	        	// get char size
	        	charWidth = pCi->texRect.width;
	        	charHeight = pCi->texRect.height;

				// if not first char of line, add left padding
				if(!firstLineChar) {
					x += pCi->left;
				}

				// choose max height as line height
				currentLineHeight = m_lineHeight > 0 ? m_lineHeight : MAX(currentLineHeight, charHeight + pCi->top);

	            // get atlas
	            wyTextureAtlas* atlas = (wyTextureAtlas*)wyArrayGet(m_atlasList, pCi->page);

	            // get vertex corner
	            float left = x + lineOffset;
	            float right = left + charWidth;
	            float top = -y - pCi->top;
	            float bottom = top - charHeight;

	            // build vertex
	            wyQuad3D v;
	    		v.bl_x = left;
	    		v.bl_y = bottom;
	    		v.bl_z = 0.0f;
	    		v.br_x = right;
	    		v.br_y = bottom;
	    		v.br_z = 0.0f;
	    		v.tl_x = left;
	    		v.tl_y = top;
	    		v.tl_z = 0.0f;
	    		v.tr_x = right;
	    		v.tr_y = top;
	    		v.tr_z = 0.0f;

	    		// build texture coordinates
	    		wyQuad2D t;
	    		wyTexture2D* tex = m_font->getTexture(pCi->page);
	    	    left = pCi->texRect.x / tex->getPixelWidth();
	    	    right = (pCi->texRect.x + charWidth) / tex->getPixelWidth();
	    	    top = pCi->texRect.y / tex->getPixelHeight();
	    	    bottom = (pCi->texRect.y + charHeight) / tex->getPixelHeight();
	    	    t.bl_x = left;
	    	    t.bl_y = bottom;
	    	    t.br_x = right;
	    	    t.br_y = bottom;
	    	    t.tl_x = left;
	    	    t.tl_y = top;
	    	    t.tr_x = right;
	    	    t.tr_y = top;

	    	    // add quad
	    	    atlas->appendQuad(t, v);

				// adjust x and y
				x += charWidth + pCi->right;
	        } else {
	        	// special check for space or tab
	        	if(c == ' ') {
	        		x += m_spaceWidth;
				} else if(c == '\t') {
	        		x += m_spaceWidth * m_tabSize;
				}
	        }

			// we can clear line first char flag here
			firstLineChar = false;
	    }

		// save line height
		prevLineHeight = currentLineHeight;

		// save max width
		width = MAX(width, x);
	}

	// add last line
	if(prevLineHeight != 0) {
		y += prevLineHeight;
	}

	// set label content size
	setContentSize(width, y);

	// adjust quad
	for(int i = 0; i < m_atlasList->num; i++) {
		wyTextureAtlas* atlas = (wyTextureAtlas*)wyArrayGet(m_atlasList, i);
		atlas->iterateQuad3D(adjustAtlasPosition, this);
	}
	
	// release
	for(vector<const char*>::iterator iter = lines->begin(); iter != lines->end(); iter++) {
		releaseLine(*iter);
	}
	WYDELETE(lines);
	WYDELETE(widthList);
}