/** *是否覆盖,如果覆盖那么重绘制 */ void XWidget::findOverridingWidget(XRect& pRect,XObject *pObject) { if(!visible) { return ; } XPoint centerPoint={widget_rect.w/2+widget_rect.x,widget_rect.h/2+widget_rect.y}; XPoint srcPoint={pRect.w/2+pRect.x,pRect.h/2+pRect.y}; int wtw_w=pRect.w/2 + widget_rect.w/2; int wtw_h=pRect.h/2 + widget_rect.h/2; int w=centerPoint.x-srcPoint.x; int h=centerPoint.y-srcPoint.y; if(w <0) w=-w; if(h <0) h=-h; //找到合适的组件 if(w <=wtw_w && h <=wtw_h) { XRectF rectF={pRect.x,pRect.y,pRect.x+pRect.w,pRect.y+pRect.h}; localUpdate(rectF,pObject); if(layout) { layout->findOverridingWidget(pRect,pObject); } } }
double Rnode::FullUpdate(bool check) { double ret = 0; if (! flag) { c**t i=up.begin(); while ((i!=up.end()) && ((*i)->isValueUpdated())) i++; bool up_ok = (i == up.end()); /* bool up_ok = true; for (c**t i=up.begin(); i!=up.end(); i++) { up_ok &= (*i)->isValueUpdated(); // up_ok &= (*i)->flag; } */ if (up_ok) { ret = localUpdate(); value_updated = true; if ((fabs(ret)>MCMC::MAXDIFF) && check) { cerr << "NON ZERO CHECKSUM : " << GetName() << '\n'; cerr << "number of parents : " << up.size() << '\n'; throw CheckSumException(ret); } for (c**t i=down.begin(); i!=down.end(); i++) { ret += (*i)->FullUpdate(check); } } } return ret; }
double Rnode::NotifyUpdate() { double ret = 0; if (! flag) { c**t i=up.begin(); while ((i!=up.end()) && ((*i)->isValueUpdated())) i++; bool up_ok = (i == up.end()); /* bool up_ok = true; for (c**t i=up.begin(); i!=up.end(); i++) { up_ok &= (*i)->isValueUpdated(); // up_ok &= (*i)->flag; } if (GetName() == "BD Chrono") { cerr << "BD::NotifyUpdate : " << up_ok << '\n'; } */ if (up_ok) { ret = localUpdate(); if (! value_updated) { value_updated = true; for (c**t i=down.begin(); i!=down.end(); i++) { ret += (*i)->NotifyUpdate(); } } } } return ret; }
void XWidget::drawParent(XRectF& pRect,XObject *pObject) { if(parent && lucency) { parent->drawParent(pRect,pObject); } localUpdate(pRect,pObject); }
void XWidget::drawChild(XRectF& pRect,XObject *pObject) { localUpdate(pRect,pObject); if(layout) { layout->drawChild(pRect,pObject); } }
double Dnode::FullUpdate(bool check) { double ret = 0; if (! flag) { c**t i=up.begin(); while ((i!=up.end()) && ((*i)->isValueUpdated())) i++; bool up_ok = (i == up.end()); /* bool up_ok = true; for (c**t i=up.begin(); i!=up.end(); i++) { up_ok &= (*i)->isValueUpdated(); // up_ok &= (*i)->flag; } */ if (up_ok) { ret = localUpdate(); for (c**t i=down.begin(); i!=down.end(); i++) { ret += (*i)->FullUpdate(check); } } } return ret; }
int main( int argc, char ** argv ) { CharString iniFile = "./ProcessServer.ini"; if ( argc > 1 ) iniFile = argv[1]; Settings settings( "ProcessServer", iniFile ); // initialize the logging first thing before we do anything else.. std::string logFile( settings.get( "logFile", "ProcessServer.log" ) ); std::string logExclude( settings.get( "logExclude", "" ) ); unsigned int nMinLogLevel = settings.get( "logLevel", LL_STATUS ); new FileReactor( logFile, nMinLogLevel, logExclude ); bool bRemoteUpdate = settings.get( "remoteUpdate", 1 ) != 0; bool bLocalUpdate = settings.get( "localUpdate", (dword)0 ) != 0; CharString sPath( FileDisk::currentDirectory() ); if (! sPath.endsWith( PATH_SEPERATOR ) ) sPath += PATH_SEPERATOR; #if !defined(_DEBUG) // update the files if ( settings.get( "doUpdate", 1 ) != 0 ) { settings.put( "doUpdate", (dword)0 ); if ( bLocalUpdate ) { CharString updatePath = settings.get( "localUpdatePath", "" ); if ( updatePath.length() > 0 ) { FileDisk::normalizePath( updatePath.buffer() ); if (! updatePath.endsWith( PATH_SEPERATOR ) ) updatePath += PATH_SEPERATOR; // copy the files from a directory if ( localUpdate( sPath, updatePath ) ) return -3; // let the service/script update our files.. } } } #endif // do the update next time! settings.put( "doUpdate", 1 ); ProcessServer::Context context; context.logFile = logFile.c_str(); context.name = settings.get( "name", "ProcessServer" ); context.config = iniFile; context.gameId = settings.get( "gameId", 1 ); context.processGroup = settings.get( "processGroup", 1 ); context.networkGroup = settings.get( "networkGroup", 1 ); context.metaAddress = settings.get( "metaAddress", "meta-server.palestar.com" ); context.metaPort = settings.get( "metaPort", 9000 ); context.uid = settings.get( "uid", "DSS" ); context.pw = settings.get( "pw", "darkspace" ); context.address = settings.get( "address", "" ); context.port = settings.get( "port", 8000 ); context.maxClients = settings.get( "maxClients", 1000 ); context.processFile = iniFile; context.syncClock = settings.get ("syncClock", (dword)0 ) != 0; // start the server MyProcessServer theServer; if (! theServer.start( context ) ) return -1; // signal that we are running Event serverRunning( "ProcessServerRun" ); serverRunning.signal(); dword nNextUpdateCheck = Time::seconds() + settings.get("updateTime",300); dword nLastCRC = 0; // run the server forever, unless it crashes Event serverStop( "ProcessServerStop" ); while( theServer.running() && !theServer.shutdownCompleted() ) { if (! serverStop.wait( 10 ) ) { LOG_STATUS( "ProcessServer", "Recevied shutdown signal." ); theServer.shutdown(); serverStop.clear(); } theServer.update(); theServer.updatePerformanceMonitor(); #if !defined(_DEBUG) if ( bRemoteUpdate && nNextUpdateCheck < Time::seconds() ) { // check for new code update MirrorClient mirrorClient; if ( mirrorClient.open( settings.get( "mirrorAddress", "mirror-server.palestar.com" ), settings.get( "mirrorPort", 9200 ), sPath, NULL, true ) ) { // attempt to login, ingore if failed mirrorClient.login( settings.get( "uid", "" ), settings.get( "pw", "" ) ); // get the CRC only, only do a sync if remote files have been changed... dword nCRC = mirrorClient.getCRC(); if ( nCRC != nLastCRC ) { nLastCRC = nCRC; dword nJobID = mirrorClient.syncronize(); if ( nJobID != 0 && mirrorClient.waitJob( nJobID, 86400 * 1000 ) ) { int nWarningTime = settings.get( "warningTime", 300 ); LOG_STATUS( "ProcessServer", "Files updated -- Restarting the server in %d seconds.", nWarningTime ); CharString sWarningMessage = settings.get( "warningMessage", CharString().format("/notice /%s Updating in $T...", context.name.cstr() ) ); while( nWarningTime > 0 ) { CharString sTimeLeft; sTimeLeft.format("%d %s", nWarningTime > 60 ? nWarningTime / 60 : nWarningTime, nWarningTime > 60 ? "minute(s)" : "second(s)"); // replace the "$T" token with the time remaining... CharString sChat = sWarningMessage; sChat.replace( "$T", sTimeLeft ); theServer.sendChat( sChat ); int nSleepTime = 0; if ( nWarningTime > (60 * 10) ) nSleepTime = 60 * 5; // sleep for 5 minutes else nSleepTime = 60; // sleep for 1 minute if ( nSleepTime > nWarningTime ) nSleepTime = nWarningTime; nWarningTime -= nSleepTime; dword nEndSleep = Time::seconds() + nSleepTime; while( Time::seconds() < nEndSleep ) { if (! serverStop.wait( 10 ) ) { LOG_STATUS( "ProcessServer", "Received stop signal, stopping now." ); nSleepTime = nWarningTime = 0; // stop now... no warning break; } theServer.update(); theServer.updatePerformanceMonitor(); } } // start the shutdown, server will exit once the last process has stopped.. theServer.shutdown(); } } mirrorClient.close(); } else { LOG_ERROR( "ProcessServer", "Failed to connect to MirrorServer!" ); } nNextUpdateCheck = Time::seconds() + settings.get("updateTime",300); } #endif } theServer.stop(); return 0; }
static bool localUpdate( const char * pDest, const char * pSrc ) { bool bRestart = false; ASSERT( pDest[ strlen(pDest) - 1 ] == PATH_SEPERATORC ); ASSERT( pSrc[ strlen(pSrc) - 1 ] == PATH_SEPERATORC ); Path srcPath( pSrc ); CharString sMask( srcPath.directory() + "*" ); FindFile ff( sMask ); // make sure destination directory exists FileDisk::createDirectory( pDest ); // move files for(int i=0;i<ff.fileCount();i++) { CharString dstFile; dstFile.format( "%s%s", pDest, ff.file(i) ); CharString srcFile; srcFile.format( "%s%s", pSrc, ff.file(i) ); bool copyFile = false; bool copyUpdate = false; if ( FileDisk::fileExists( dstFile ) ) { // make sure date of src file is newer if ( FileDisk::fileDate( srcFile ) > FileDisk::fileDate( dstFile ) ) { copyFile = true; // attempt to delete the old file, if it fails then use MirrorUpdate if (! FileDisk::deleteFile( dstFile ) ) copyUpdate = true; } } else copyFile = true; bRestart |= copyFile; if ( copyFile && copyUpdate ) FileDisk::copyFile( srcFile, dstFile + ".upd" ); else if ( copyFile ) FileDisk::copyFile( srcFile, dstFile ); } // recurse into subdirectories for(int i=0;i<ff.directoryCount();i++) { if ( ff.directory(i)[0] == '.' ) continue; CharString newDst; newDst.format( "%s%s" PATH_SEPERATOR, pDest, ff.directory( i ) ); CharString newSrc; newSrc.format( "%s%s" PATH_SEPERATOR, pSrc, ff.directory( i ) ); bRestart |= localUpdate( newDst, newSrc ); } return bRestart; }