#include "master.hpp" #include #include int cmp(const void* a,const void* b){return ((pn*)b)->p-((pn*)a)->p;} extern sceneManager *sceneMgr; SMELT* sceneManager::sm=NULL; std::thread* sceneManager::uth=NULL; sceneManager::sceneManager(){sm=smGetInterface(SMELT_APILEVEL);utime=scnt=0;thactive=false;dlps=64;} sceneManager::~sceneManager(){sm->smRelease();} int sceneManager::registerScene(scenePrototype *sp,const char* scenename,int priority) { for(int i=0;ijoin();delete uth;} bool sceneManager::isThreadActive(){return thactive;} int sceneManager::getSceneID(const char* scene) {for(int i=0;isceneUpdate())return true; sm->smRenderBegin2D(true); for(int i=0;isceneRender(); sm->smRenderEnd(); if(sm->smGetKeyState(SMK_S)==SMKST_HIT)sm->smScreenShot("ss0.bmp"); return false; } void sceneManager::threadUpdate() { long ddlay; while(thactive) { ddlay=1000000000/dlps; using namespace std::chrono; high_resolution_clock::time_point b=high_resolution_clock::now(); for(int i=0;ithreadUpdate(); high_resolution_clock::time_point a=high_resolution_clock::now(); auto updateTime=a-b;utime=updateTime.count(); ++lp;lpsud+=updateTime.count()>ddlay?updateTime.count():ddlay; if(lpsud>=1000000000){lps=(float)lp/(lpsud/1000000000.);lp=0;lpsud=0;} if(updateTime<(duration>)ddlay) std::this_thread::sleep_for((duration>)ddlay-updateTime); } }