Пример #1
0
wyDirector::wyDirector() :
		m_projection(PROJECTION_DEFAULT),
		m_delta(0.f),
		m_frameDelta(0.f),
		m_frameRate(0.f),
		m_tickFactor(1),
		m_frames(0),
		m_lastUpdateTime(0),
		m_needCheckTexture(false),
		m_paused(false),
		m_UIPaused(false),
		m_displayFPS(false),
		m_calculateFPS(false),
		m_surfaceCreated(false),
		m_enableDepthTest(false),
		m_makeScreenshot(false),
		m_focusEnabled(true),
		m_screenshotPath(NULL),
		m_maxFrameRate(0),
		m_lastFrameTime(0),
		m_minFrameInterval(0),
		m_savedDelta(0),
		m_nextScene(NULL),
		m_runningScene(NULL),
		m_fpsLabel(NULL),
		m_scenesStack(NULL),
		m_lifecycleListeners(wyArrayNew(3)),
		m_clipStack((wyRect*)wyMalloc(10 * sizeof(wyRect))),
		m_clipStackCount(0),
		m_clipStackCapacity(10),
		m_glView(NULL),
		m_context(NULL),
		m_lifecycleData(NULL) {
	// reset global variable
	g_Director_isEnding = false;

	// init math library
#ifdef WY_CFLAG_OPTIMIZE_MATH
	wyMath::init();
#endif

	// create mutex
	pthread_mutexattr_t attr;
	pthread_mutexattr_init(&attr);
	pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
	pthread_mutex_init(&gMutex, &attr);
	pthread_mutex_init(&gCondMutex, &attr);
	pthread_mutexattr_destroy(&attr);

	// ensure other singleton class existence
	wyInitAutoReleasePool();
	wyEventDispatcher::getInstance();
	wyScheduler::getInstance();
	wyActionManager::getInstance();
	wyTextureManager::getInstance();
	wyZwoptexManager::getInstance();

	// create stack
	m_scenesStack = wyArrayNew(10);
}
Пример #2
0
wyBladeRibbon::wyBladeRibbon(wyTexture2D* tex, wyColor4B color, float fade) :
		wyRibbon(fade),
		m_blade(NULL),
		m_color(color),
		m_maxPointCount(50),
		m_dyingBlades(wyArrayNew(5)),
		m_reusableBlades(wyArrayNew(5)),
		m_texture(NULL) {
	tex->setAntiAlias(false);
	setTexture(tex);
}
Пример #3
0
wyHexagonAStarMap::wyHexagonAStarMap(int width, int height) :
	wyAStarMap(), m_width(width), m_height(height) {

	m_tiles = wyArrayNew(m_width * m_height);
	for (int x = 0; x < m_width; x++) {
		for (int y = 0; y < m_height; y++) {
			wyArrayPush(m_tiles, WYNEW wyAStarTile(TILE_FREE, x, y));
		}
	}

	// auto clilds
	for (int i = 0; i < m_tiles->num; i++) {
		wyAStarTile* tile = (wyAStarTile*) wyArrayGet(m_tiles, i);
		int y_max = (tile->getX() % 2) ? 2 : 1;
		int y_min = (tile->getX() % 2) ? 0 : -1;
		int child_y = (tile->getX() % 2) ? -1 : 1;

		wyAStarTile* neighbor = getTileAt(tile->getX(), tile->getY() + child_y);
		if (neighbor != tile && neighbor != NULL) {
			tile->pushChild(neighbor);
		}

		for (int x = -1; x < 2; x++) {
			for (int y = y_min; y < y_max; y++) {
				neighbor = getTileAt(tile->getX() + x, tile->getY() + y);
				if (neighbor != tile && neighbor != NULL) {
					tile->pushChild(neighbor);
				}
			}
		}
	}
}
Пример #4
0
wyTMXTileMap* wyTMXTileMap::make(const char* path, bool isFile, wyTexture2D* tex1, ...) {
	wyTMXTileMap* tmx = WYNEW wyTMXTileMap();

	// load tmx file
	wyMapInfo* map = wyTMXLoader::load(path, isFile);

	// collect first texture
	wyArray* textures = wyArrayNew(map->tilesets->num);
	wyArrayPush(textures, tex1);

	// collect other textures
    va_list texList;
    va_start(texList, tex1);
    for(wyTexture2D* now = va_arg(texList, wyTexture2D*); now != NULL; now = va_arg(texList, wyTexture2D*)) {
    	wyArrayPush(textures, now);
    }
    va_end(texList);

    // init
    tmx->init(map, textures);

    // destroy temp list
    wyArrayDestroy(textures);

	return (wyTMXTileMap*)tmx->autoRelease();
}
Пример #5
0
wyResultSet::wyResultSet(wyDatabase* db, wyStatement* statement) :
		m_db(db),
		m_statement(statement),
		m_sql(wyUtils::copy(statement->getQuery())),
		m_columnNames(NULL) {
	// setup column names
    int columnCount = sqlite3_column_count(statement->getStatement());
    m_columnNames = wyArrayNew(columnCount);
    for(int i = 0; i < columnCount; i++) {
    	char* name = (char*)wyUtils::copy(sqlite3_column_name(statement->getStatement(), i));
    	wyUtils::toLowercase(name);
    	wyArrayPush(m_columnNames, name);
    }
}
Пример #6
0
wyBitmapFontLabel::wyBitmapFontLabel(wyBitmapFont* font, const char* text) :
        m_font(font),
        m_color(wyc4bWhite),
        m_text(NULL),
        m_spaceWidth(DP(6)),
        m_tabSize(4),
        m_alignment(LEFT),
        m_lineSpacing(0),
        m_lineHeight(font->getLineHeight()),
        m_lineWidth(MAX_FLOAT) {
	// create atlas for every page
    m_atlasList = wyArrayNew(m_font->m_textures->num);
    for(int i = 0; i < m_font->m_textures->num; i++) {
    	wyArrayPush(m_atlasList, WYNEW wyTextureAtlas(m_font->getTexture(i)));
    }

    // set text and it will trigger updateContentSize
    setText(text);
}
Пример #7
0
wyTMXTileMap* wyTMXTileMap::make(int resId, wyTexture2D** tex, int texCount) {
	wyTMXTileMap* tmx = WYNEW wyTMXTileMap();

	// load tmx file
	wyMapInfo* map = wyTMXLoader::load(resId);

	// collect textures
	wyArray* textures = wyArrayNew(texCount);
    for(int i = 0; i < texCount; i++) {
    	wyArrayPush(textures, *(tex + i));
    }

    // init
    tmx->init(map, textures);

    // destroy temp list
    wyArrayDestroy(textures);

	return (wyTMXTileMap*)tmx->autoRelease();
}
Пример #8
0
wyPageControl::wyPageControl() :
		m_pages(wyArrayNew(5)),
		m_container(NULL),
		m_lastX(0),
		m_lastY(0),
		m_scroller(WYNEW wyScroller()),
		m_flinging(false),
		m_scrolling(false),
		m_vertical(false),
		m_initialPageIndex(-1),
		m_indicator(NULL),
		m_data(NULL),
#if ANDROID
		m_jCallback(NULL),
#endif
		m_centerY(-1),
		m_centerX(-1) {
	// set page control properties
	setRelativeAnchorPoint(false);
	setContentSize(wyDevice::winWidth, wyDevice::winHeight);
	memset(&m_callback, 0, sizeof(wyPageControlCallback));

	// create container
	m_container = WYNEW wyLayer();
	m_container->setPosition(0, 0);
	addChildLocked(m_container);
	m_container->release();

	// enable events
	setTouchEnabled(true);
			
	// schedule fling timer
	wyTargetSelector* ts = wyTargetSelector::make(this, SEL(wyPageControl::updateFling));
	wyTimer* timer = wyTimer::make(ts);
	scheduleLocked(timer);
}
Пример #9
0
void wyNode::scheduleLocked(wyTimer* t) {
    if(t == NULL) {
        LOGW("node schedule: timer must be non-null");
        return;
    }

    // check array
    if(m_timers == NULL)
        m_timers = wyArrayNew(3);

    // if already contains, return
    if(wyArrayIndexOf(m_timers, t, wyTimerEquals, NULL) >= 0) {
        if(t->isOneShot() && t->isDone()) {
            t->reset();

            // if node is running, schedule it now because onEnter won't be called later
            if(m_running) {
                gScheduler->scheduleLocked(t);
            }
        } else {
            LOGW("this timer is already scheduled");
        }

        return;
    }

    // if node is running, schedule it now because onEnter won't be called later
    if(m_running) {
        gScheduler->scheduleLocked(t);
    }

    pthread_mutex_lock(&gMutex);
    wyArrayPush(m_timers, t);
    wyObjectRetain(t);
    pthread_mutex_unlock(&gMutex);
}
Пример #10
0
wyB2BodyMeta::wyB2BodyMeta(const char* name) :
    m_arrayFixturedef(wyArrayNew(4)){
    setName(name);
}
Пример #11
0
wyDirector_android::wyDirector_android() :
    m_allowBackgroundRunning(false),
    m_backgroundRunning(false),
    m_originalMaxFrameRate(0),
    m_jLifecycleListeners(wyArrayNew(3)) {
}
Пример #12
0
wyAStarTile::wyAStarTile(int type, int x, int y) :
    m_type(type), m_x(x), m_y(y), m_childs(wyArrayNew(8)) {
    m_gRate = 1.0f;
}
Пример #13
0
wyCombineColorFilter::wyCombineColorFilter() :
		m_filters(wyArrayNew(5)) {
}
Пример #14
0
wyNode::wyNode() :
    m_transformMatrix(wyaZero),
    m_inverseMatrix(wyaZero),
    m_transformDirty(true),
    m_inverseDirty(true),
    m_enabled(true),
    m_selected(false),
    m_focused(false),
    m_visible(true),
    m_noDraw(false),
    m_relativeAnchorPoint(true),
    m_running(false),
    m_touchEnabled(false),
    m_keyEnabled(false),
    m_accelerometerEnabled(false),
    m_gestureEnabled(false),
    m_doubleTabEnabled(false),
    m_multiTouchClickable(false),
    m_interceptTouch(true),
    m_childrenChanging(false),
    m_touchPriority(0),
    m_keyPriority(0),
    m_gesturePriority(0),
    m_doubleTapPriority(0),
    m_accelerometerPriority(0),
    m_zOrder(0),
    m_tag(INVALID_TAG),
    m_anchorPointX(0.f),
    m_anchorPointY(0.f),
    m_anchorX(0.f),
    m_anchorY(0.f),
    m_positionX(0.f),
    m_positionY(0.f),
    m_velocityX(0.f),
    m_velocityY(0.f),
    m_accelerationX(0.f),
    m_accelerationY(0.f),
    m_width(0.f),
    m_height(0.f),
    m_rotation(0.f),
    m_scaleX(1.f),
    m_scaleY(1.f),
    m_skewX(0),
    m_skewY(0),
    m_vertexZ(0.f),
    m_parent(NULL),
    m_hasClip(false),
    m_clipRect(wyrZero),
    m_clipRelativeToSelf(false),
    m_children(wyArrayNew(3)),
    m_grid(NULL),
    m_camera(NULL),
    m_timers(NULL),
    m_touchCoffin(NULL),
#if ANDROID
    m_jTouchHandler(NULL),
    m_jKeyHandler(NULL),
    m_jAccelHandler(NULL),
    m_jDoubleTapHandler(NULL),
    m_jGestureHandler(NULL),
    m_jVirtualMethods(NULL),
    m_jPositionListener(NULL),
    m_dataIsJavaObject(false),
#endif
    m_downSelector(NULL),
    m_upSelector(NULL),
    m_moveOutSelector(NULL),
    m_positionListener(NULL),
    m_plData(NULL) {
    memset(&m_data, 0, sizeof(wyUserData));
    memset(&m_state, 0, sizeof(wyTouchState));
    setAnchor(0.5f, 0.5f);
}