void cxJsonPrint(cxAny pjson) { CX_ASSERT_THIS(pjson, cxJson); cxStr txt = cxJsonDump(this); CX_LOGGER("%s",cxStrBody(txt)); CX_UNUSED_PARAM(txt); }
cxEngine cxEngineInstance() { if(instance == NULL) { CX_LOGGER("cxEngine Version: %d",CX_ENGINE_VERSION); instance = CX_ALLOC(cxEngine); } return instance; }
static cxInt cxStringLuaPrint(lua_State *L) { CX_LUA_DEF_THIS(cxString); if(this != NULL){ CX_LOGGER("%s",cxStringBody(this)); } return 0; }
void cxEngine::Run() { cxAutoPool::Start(); if(layout){ CX_LOGGER("window size:W=%f H=%f",winsize.w,winsize.h); cxOpenGL::Instance()->Set3DProject(winsize); if(!init){ cxOpenGL::Instance()->Init(); OnMain(); init = true; } if(!plansize.IsZero()){ planscale.x = winsize.w/plansize.w; planscale.y = winsize.h/plansize.h; } cxOpenGL::Instance()->SetViewport(bound); window->SetSize(winsize); window->Layout(); layout = false; } while(init){ cxOpenGL *gl = cxOpenGL::Instance(); cxDouble now = cxUtil::Instance()->Timestamp(); if(time == 0){ time = now; } dt = now - time; time = now; if(pause || cxFloatIsEqual(dt, 0)){ break; } if(iter != nextIter){ iter = nextIter; } for(cxInt i=0;i<iter;i++){ timevar += dt; runEvents(); OnUpdate(dt); window->Update(dt); } gl->Clear(); render->Init(); window->Render(render,gl->ModelView()); render->Draw(); break; }; cxAutoPool::Update(); if(isreset){ cxEngine::Startup(true); } }
int cxAndroid::InitDisplay() { if(display != NULL){ return 0; } display = eglGetDisplay(EGL_DEFAULT_DISPLAY); if(display == NULL){ CX_ERROR("eglGetDisplay error"); return -1; } EGLint major = 0; EGLint minor = 0; if(!eglInitialize(display, &major, &minor)){ CX_ERROR("eglInitialize error"); return -1; } CX_LOGGER("EGL Version:%d.%d",major,minor); eglChooseConfig(display, display_attribs24, &eglConfig, 1, &numConfigs); if(!numConfigs){ eglChooseConfig(display, display_attribs16, &eglConfig, 1, &numConfigs); } if(!numConfigs){ CX_ERROR("get egl config error"); return -1; } CX_LOGGER("EGL Config Number:%d",numConfigs); if(!eglGetConfigAttrib(display, eglConfig, EGL_NATIVE_VISUAL_ID, &format)){ CX_ERROR("eglGetConfigAttrib error"); return -1; } context = eglCreateContext(display, eglConfig, NULL, context_attribs); if(context == NULL){ CX_ERROR("eglCreateContext error"); return -1; } return 0; }
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 cxEventLogger(lua_State *L) { cxConstChars msg = luaL_checkstring(L, 2); CX_LOGGER("%s",msg); return 0; }
void Game::OnMain() { SetPlanSize(cxSize2F(2048, 1536)); // const cxStr *data = nullptr; { cxStr *code = cxStr::UTF8("8347834"); IndexType message = IndexType_init_zero; message.tid = 200; message.code = CX_STR_PB_ENCODE(code); data = cxStr::PBEncode(IndexType_fields, &message); cxUtil::Instance()->WriteDocument("test.dat", data, true); } { cxStr *code = cxStr::Create(); IndexType m2 = IndexType_init_zero; m2.code = CX_STR_PB_DECODE(code); cxBool ok = data->PBDecode(IndexType_fields, &m2); CX_LOGGER("%d",ok); } // LoadTexture("grid.png","grid"); // // cxSprite *sp = cxSprite::Create(); // sp->SetSize(cxSize2F(64)); // sp->SetTexture("grid"); // Window()->Append(sp); // // cxMoveTo::Create(cxPoint2F(0, 512), 6)->AttachTo(sp)->onExit+=cxAction::Remove; // // { // cxSprite *sp2 = cxSprite::Create(); // sp2->SetSize(cxSize2F(64)); // sp2->SetTexture("grid"); // sp2->SetColor(cxColor4F::RED); // Window()->Append(sp2); // // cxFollow::Create(sp, 50)->AttachTo(sp2); // } // Controller *cv = Controller::Create(6, 6); // cv->SetResizeFlags(cxView::ResizeBottom); // Window()->Append(cv); // // return; //加载纹理 LoadTexture("jl.lqt"); //加载帧序列 LoadFrames("frames.csv"); //加载动作组 LoadActions("actions.csv"); //获取法师帧序列 const cxFrames *fs = GetFrames("Mage"); //获取法师的动作列表 const cxActionGroup *ag = GetActions("Mage"); //获得move动作 //创建动画 { //获得动作组 const cxActionAttr *move = ag->Action("attack"); //创建动画 cxAnimate *animate = fs->Animate(); animate->onFrame+=[](cxAnimate *pav,cxInt frame){ CX_LOGGER("%d %d",frame,pav->IsKeyFrame()); }; animate->SetAction(move, 1); animate->SetSpeed(1.0f); //创建载体 cxAtlas *atlas = cxAtlas::Create(); atlas->SetFlipX(true); atlas->SetSize(cxSize2F(200, 200)); atlas->Append(animate);//加入动画 //载体加入绘制 Window()->Append(atlas); } { const cxActionAttr *move = ag->Action("move"); cxAnimate *animate = fs->Animate(); animate->onFrame+=[](cxAnimate *pav,cxInt frame){ CX_LOGGER("%d %d",frame,pav->IsKeyFrame()); }; animate->SetAction(move, 1); animate->SetSpeed(1.0f); // cxAtlas *atlas = cxAtlas::Create(); atlas->SetFlipX(true); atlas->SetSize(cxSize2F(200, 200)); atlas->SetPosition(cxPoint2F(0, 300)); animate->AttachTo(atlas); Window()->Append(atlas); } }
static void cxDBEnvFeedback(DB_ENV *env, int flags, int progress) { cxDBEnv this = env->app_private; CX_LOGGER("dbenv %s progress=%d",cxStringBody(this->type),progress); this->progress = progress; }