cxBool cxEngineFireKey(cxKeyType type,cxInt code) { cxEngine this = cxEngineInstance(); this->key.type = type; this->key.code = code; return cxViewOnKey(this->window, &this->key); }
static cxInt cxFixScaleH(lua_State *L) { cxEngine engine = cxEngineInstance(); cxNumber num = cxNumberVec2f(cxVec2fv(engine->scale.y, engine->scale.y)); CX_LUA_PUSH_OBJECT(num); return 1; }
cxBool cxEngineFireTouch(cxTouchType type,cxVec2f pos) { cxEngine this = cxEngineInstance(); if(!this->isTouch){ return false; } cxDouble time = cxTimestamp(); cxVec2f cpos = cxEngineTouchToWindow(pos); if(type == cxTouchTypeDown){ this->touch.movement = cxVec2fv(0, 0); this->touch.delta = cxVec2fv(0, 0); this->touch.previous = cpos; this->touch.dtime = time; this->touch.start = cpos; }else if(type == cxTouchTypeMove){ this->touch.delta = cxVec2fv(cpos.x - this->touch.previous.x, cpos.y - this->touch.previous.y); this->touch.previous = cpos; this->touch.movement.x += this->touch.delta.x; this->touch.movement.y += this->touch.delta.y; }else{ this->touch.utime = time; } this->touch.current = cpos; this->touch.type = type; cxBool ret = false; CX_SIGNAL_FIRE(this->onTouch, CX_FUNC_TYPE(cxAny, cxTouch *, cxBool *),CX_SLOT_OBJECT, &this->touch, &ret); return (ret || cxViewTouch(this->window, &this->touch)); }
cxVec2f cxWindowPointToGLPoint(cxVec2f wPoint) { cxEngine engine = cxEngineInstance(); cxFloat x = wPoint.x + engine->winsize.w/2.0f; cxFloat y = wPoint.y + engine->winsize.h/2.0f; return cxVec2fv(x, y); }
cxBool cxViewContainsGLBox(cxAny pview) { cxEngine engine = cxEngineInstance(); cxRect4f vr = cxViewGLRect(pview); cxRect4f gr = cxRect4fv(0, 0, engine->winsize.w, engine->winsize.h); return cxRect4fContainsRect4f(gr,vr); }
cxVec2f cxGLPointToWindowPoint(cxVec2f glPoint) { cxEngine engine = cxEngineInstance(); cxFloat x = glPoint.x - engine->winsize.w/2.0f; cxFloat y = glPoint.y - engine->winsize.h/2.0f; return cxVec2fv(x, y); }
void cxActionStop(cxAny pav) { cxEngine engine = cxEngineInstance(); cxAction this = pav; this->isExit = true; cxActionUpdate(this, engine->frameDelta); }
cxAny cxActionRootMakeElement(cxConstChars temp,xmlTextReaderPtr reader) { cxEngine engine = cxEngineInstance(); cxAny action = NULL; if(ELEMENT_IS_TYPE(cxMove)){ action = CX_CREATE(cxMove); }else if(ELEMENT_IS_TYPE(cxScale)){ action = CX_CREATE(cxScale); }else if(ELEMENT_IS_TYPE(cxRotate)){ action = CX_CREATE(cxRotate); }else if(ELEMENT_IS_TYPE(cxJump)){ action = CX_CREATE(cxJump); }else if(ELEMENT_IS_TYPE(cxFade)){ action = CX_CREATE(cxFade); }else if(ELEMENT_IS_TYPE(cxTint)){ action = CX_CREATE(cxTint); }else if(ELEMENT_IS_TYPE(cxTimer)){ action = CX_CREATE(cxTimer); }else if(ELEMENT_IS_TYPE(cxActionSet)){ action = CX_CREATE(cxActionSet); }else if(ELEMENT_IS_TYPE(cxAnimate)){ action = CX_CREATE(cxAnimate); }else if(ELEMENT_IS_TYPE(cxSpline)){ action = CX_CREATE(cxSpline); }else if(ELEMENT_IS_TYPE(cxRunParticle)){ action = CX_CREATE(cxRunParticle); }else if(ELEMENT_IS_TYPE(cxParabola)){ action = CX_CREATE(cxParabola); }else{ action = CX_METHOD_FIRE(NULL, engine->MakeAction, temp, reader); } return action; }
cxAny cxActionRootCreate(cxConstChars xml) { cxEngine engine = cxEngineInstance(); cxActionRoot this = cxHashGet(engine->actions, cxHashStrKey(xml)); if(this != NULL){ return this; } cxXMLScript script = cxEngineGetXMLScript(xml); if(script == NULL || script->bytes == NULL){ CX_ERROR("%s script not register",xml); return NULL; } this = CX_CREATE(cxActionRoot); xmlTextReaderPtr reader = cxXMLReaderForScript(script,cxActionRootReaderError, this); if(reader == NULL){ CX_ERROR("create xml reader failed"); return NULL; } CX_EVENT_FIRE(this, onBegin); cxActionRootLoadCodesWithReader(this, reader); cxHashKey key = cxHashStrKey(xml); cxHashSet(this->codes, key, script->bytes); cxHashSet(engine->actions, key, this); CX_EVENT_FIRE(this, onEnd); return this; }
CX_OBJECT_INIT(cxEventBase, cxObject) { cxEngine engine = cxEngineInstance(); CX_SLOT_CONNECT(engine->onUpdate, this, onUpdate, cxEventUpdate); this->base = event_base_new(); this->conns = CX_ALLOC(cxHash); }
CX_OBJECT_INIT(cxTextureFactory, cxObject) { cxEngine engine = cxEngineInstance(); this->caches = CX_ALLOC(cxHash); CX_SLOT_CONNECT(engine->onMemory, this, onMemory, cxTextureFactoryMemory); CX_EVENT_QUICK(engine->onFree, cxTextureFactoryDestroy); }
cxVec2f cxEngineTouchToWindow(cxVec2f pos) { cxEngine this = cxEngineInstance(); cxVec2f rv; rv.x = pos.x - this->winsize.w / 2.0f; rv.y = this->winsize.h / 2.0f - pos.y; return rv; }
static cxInt cxRelativeH(lua_State *L) { cxEngine engine = cxEngineInstance(); cxFloat v = luaL_checknumber(L, 2); cxNumber num = cxNumberFloat(v * engine->winsize.h); CX_LUA_PUSH_OBJECT(num); return 1; }
cxVec2f cxEngineWindowToTouch(cxVec2f pos) { cxEngine this = cxEngineInstance(); cxVec2f rv; rv.x = this->winsize.w / 2.0f - pos.x; rv.y = pos.y - this->winsize.h / 2.0f; return rv; }
void cxEngineResume() { CX_RETURN(isExit); cxEngine engine = cxEngineInstance(); engine->isPause = false; CX_SIGNAL_FIRE(engine->onResume, CX_FUNC_TYPE(cxAny),CX_SLOT_OBJECT); if(engine->isInit){ cxResumeMusic(); } }
void cxEnginePause() { CX_RETURN(isExit); cxEngine engine = cxEngineInstance(); engine->isPause = true; CX_SIGNAL_FIRE(engine->onPause, CX_FUNC_TYPE(cxAny),CX_SLOT_OBJECT); if(engine->isInit){ cxPauseMusic(); } }
void cxEngineBegin() { cxEngine engine = cxEngineInstance(); //set locate lang cxEngineSetLocalized(cxLocalizedLang()); //init event list and att method cxEngineSystemInit(engine); // cxPlayerOpen(0, 0); cxEngineInit(engine); }
void cxEngineExit() { CX_RETURN(isExit); cxEngine engine = cxEngineInstance(); CX_EVENT_FIRE(engine, onExit); cxEnginePause(); cxEngineDestroy(); cxAllocatorFree(); cxEngineTerminate(); isExit = true; }
static void cxEngineLookAt(cxMatrix4f *matrix,const cxVec2f point) { cxEngine engine = cxEngineInstance(); cxFloat zeye = engine->winsize.h / 1.1566f; cxVec3f eye; cxVec3f center; cxVec3f up; kmVec3Fill(&eye, point.x, point.y, zeye); kmVec3Fill(¢er, point.x, point.y, 0.0f); kmVec3Fill(&up, 0.0f, 1.0f, 0.0f); kmMat4Identity(matrix); kmMat4LookAt(matrix, &eye, ¢er, &up); }
cxBMPFont cxEngineLoadBMPFont(cxConstChars file) { cxEngine this = cxEngineInstance(); cxBMPFont font = cxHashGet(this->bmpfonts, cxHashStrKey(file)); if(font != NULL){ return font; } font = cxBMPFontCreate(file); if(font == NULL){ return NULL; } cxHashSet(this->bmpfonts, cxHashStrKey(file), font); return font; }
void cxEngineDraw() { CX_RETURN(isExit); cxEngine engine = cxEngineInstance(); CX_RETURN(!engine->isInit || engine->isPause); cxOpenGLClear(); cxAutoPoolBegin(); cxDouble now = cxTimestamp(); engine->frameDelta = now - engine->lastTime; CX_SIGNAL_FIRE(engine->onUpdate, CX_FUNC_TYPE(cxAny,cxFloat),CX_SLOT_OBJECT,engine->frameDelta); kmGLPushMatrix(); cxViewDraw(engine->window); kmGLPopMatrix(); engine->lastTime = now; cxAutoPoolClean(); }
cxAny cxEngineTypes(cxConstChars url) { CX_RETURN(url == NULL, NULL); cxEngine this = cxEngineInstance(); cxUrlPath path = cxUrlPathParse(url); CX_RETURN(path == NULL, NULL); cxHashRoot sets = cxHashGet(this->datasets, cxHashStrKey(path->path)); if(sets == NULL){ sets = cxHashRootCreate(path->path); CX_RETURN(sets == NULL, NULL); cxHashSet(this->datasets, cxHashStrKey(path->path), sets); } cxAny ret = NULL; if(path->count >= 2){ ret = cxHashGet(sets->items, cxHashStrKey(path->key)); } return ret; }
cxString cxEngineLocalizedText(cxConstChars url) { cxEngine this = cxEngineInstance(); cxUrlPath path = cxUrlPathParse(url); cxTypes langTypes= cxEngineTypes("appConfig.xml?lang"); CX_ASSERT(langTypes != NULL, "appConfig.xml must set lang filed"); cxString dir = cxHashGet(langTypes->any, cxHashStrKey(cxStringBody(this->lang))); if(dir == NULL){ dir = cxHashFirst(langTypes->any); } CX_ASSERT(dir != NULL, "get lang dir error"); cxConstChars file = CX_CONST_STRING("%s/%s",cxStringBody(dir),path->path); cxTypes types = cxEngineTypes(CX_CONST_STRING("%s?%s",file,path->key)); CX_RETURN(types == NULL || !cxTypesIsType(types, cxTypesString), NULL); return types->any; }
cxXMLScript cxEngineGetXMLScript(cxConstChars file) { cxEngine this = cxEngineInstance(); CX_RETURN(file == NULL,NULL); cxXMLScript script = cxHashGet(this->scripts, cxHashStrKey(file)); if(script != NULL){ return script; } script = CX_CREATE(cxXMLScript); cxStream stream = cxAssetsStreamCreate(file); CX_RETURN(stream == NULL, NULL); CX_RETAIN_SWAP(script->bytes, cxStreamAllBytes(stream)); CX_RETURN(script->bytes == NULL, NULL); cxHashSet(this->scripts, cxHashStrKey(file), script); return script; }
void cxEngineLayout(cxInt width,cxInt height) { CX_LOGGER("openGL layout width=%d height=%d",width,height); cxEngine engine = cxEngineInstance(); engine->winsize = cxSize2fv(width, height); cxViewSetSize(engine->window, engine->winsize); if(!cxSize2Zero(engine->dessize)){ engine->scale = cxVec2fv(engine->winsize.w/engine->dessize.w, engine->winsize.h/engine->dessize.h); } // if(!engine->isInit){ cxOpenGLCheckFeature(); cxEngineMain(engine); } // cxFloat zeye = engine->winsize.h / 1.1566f; kmMat4 perspective={0}; kmGLMatrixMode(KM_GL_PROJECTION); kmGLLoadIdentity(); // kmMat4PerspectiveProjection(&perspective, 60.0f, engine->winsize.w / engine->winsize.h, 0.0f, zeye * 2); kmGLMultMatrix(&perspective); kmGLMatrixMode(KM_GL_MODELVIEW); kmGLLoadIdentity(); // cxOpenGLViewport(cxBox4fv(0, engine->winsize.w, 0, engine->winsize.h)); // cxMatrix4f matrix; cxEngineLookAt(&matrix,cxVec2fv(0, 0)); kmGLMultMatrix(&matrix); // engine->lastTime = cxTimestamp(); if(!engine->isInit){ cxViewEnter(engine->window); } cxViewLayout(engine->window); engine->isInit = true; }
static cxInt cxEngineLuaGetShowBorder(lua_State *L) { cxEngine this = cxEngineInstance(); lua_pushboolean(L, this->isShowBorder); return 1; }
void cxLoaingFinished(cxAny pview) { cxLoading this = pview; this->isLoading = true; } CX_OBJECT_INIT(cxLoading, cxView) { this->isLoading = false; CX_EVENT_QUICK(this->super.onUpdate, cxLoadingOnUpdate); CX_METHOD_OVERRIDE(this->super.Touch, cxLoadingTouch); } CX_OBJECT_FREE(cxLoading, cxView) { CX_EVENT_RELEASE(this->onStart); CX_EVENT_RELEASE(this->onFinished); CX_EVENT_RELEASE(this->onLoading); } CX_OBJECT_TERM(cxLoading, cxView) void cxLoadingStart(cxLoading this) { cxEngine engine = cxEngineInstance(); CX_EVENT_FIRE(this, onStart); cxTimer timer = cxViewAppendTimer(this, 1.0f, 1); CX_EVENT_QUICK(timer->onArrive, cxLoadingArrive); cxViewAppend(engine->window, this); }
void cxEngineEnableTouch(cxBool enable) { cxEngine this = cxEngineInstance(); this->isTouch = enable; }
void cxEngineRemoveScript(cxConstChars file) { cxEngine this = cxEngineInstance(); CX_RETURN(file == NULL); cxHashDel(this->scripts, cxHashStrKey(file)); }
static cxInt cxEngineLuaGetScreenSize(lua_State *L) { cxEngine this = cxEngineInstance(); cxLuaPushSize2fv(L, this->winsize); return 1; }