GameAjaxDataSource::~GameAjaxDataSource( void ) { for( DynTableList::iterator it = tableList.begin(); it != tableList.end(); ++it ) { __delete__( it->second->table ); __delete__( it->second ); } }
void StreamCache::StreamDone( int status, const char *contentType, void *privatep ) { AsyncStream *stream; stream = ( AsyncStream * )privatep; if( stream->done_cb ) { stream->done_cb( status, contentType, stream->privatep ); __delete__( stream ); } else if( stream->cache_cb ) { std::string &tmpFile = stream->tmpFilename; std::string _contentType = "", realFile; // strip off temporary extension and optionally force extension by mime type if( contentType && *contentType ) { _contentType = std::string( contentType ); } realFile = stream->parent->RealFileForCacheFile( tmpFile.substr( 0, tmpFile.size() - strlen( WSW_UI_STREAMCACHE_EXT ) ), _contentType ); // close the temp file, that'll also flush yet unwritten data to disk trap::FS_FCloseFile( stream->tmpFilenum ); // remove the target file so that a new one can be moved in its place trap::FS_RemoveFile( realFile.c_str() ); bool moved = false; if( status == HTTP_CODE_OK ) { // verify that the move succeeds moved = ( trap::FS_MoveFile( tmpFile.c_str(), realFile.c_str() ) == qtrue ); } else { Com_Printf( S_COLOR_YELLOW "StreamCache::StreamDone: error %i fetching '%s'\n", status, stream->url.c_str() ); // remove the temp file trap::FS_RemoveFile( tmpFile.c_str() ); } // this is also going to delete the stream object stream->parent->CallCacheCbByStreamKey( stream->key, realFile, moved ); // remove the file if caching is disabled // NOTE: this breaks lazy texture loading if( stream->noCache ) { // trap::FS_RemoveFile( realFile.c_str() ); } } else { // undefined __delete__( stream ); } }
void UI_Main::preloadUI( void ) { int i; NavigationStack *navigator; for( i = 0; i < UI_NUM_CONTEXTS; i++ ) { UI_Navigation &navigation = navigations[i]; navigator = navigation.front(); while( !navigation.empty() ) { NavigationStack *stack = navigation.front(); navigation.pop_front(); // clear the navigation stack stack->popAllDocuments(); if( stack != navigator ) { __delete__( stack ); } } navigation.push_front( navigator ); navigator->setDefaultPath( ui_basepath->string ); } // load translation strings trap::L10n_ClearDomain(); // load base UI strings: l10n/ui trap::L10n_LoadLangPOFile( "l10n/ui" ); // load strings provided by the theme: e.g. ui/l10n/porkui // initialize with default document navigator = navigations[UI_CONTEXT_MAIN].front(); String l10nLocalPath( navigator->getDefaultPath().c_str() ); l10nLocalPath += "l10n"; l10nLocalPath.Erase( 0, 1 ); trap::L10n_LoadLangPOFile( l10nLocalPath.CString() ); // postpone displaying the document until the first valid refresh state navigator->pushDocument( ui_index, false, false ); showNavigationStack = navigator->hasDocuments(); // initial cursor setup if( trap::IN_SupportedDevices() & IN_DEVICE_TOUCHSCREEN ) { mouseMove( UI_CONTEXT_MAIN, 0, 0, 0, true, false ); } else { mouseMove( UI_CONTEXT_MAIN, 0, refreshState.width >> 1, refreshState.height >> 1, true, true ); } if( !quickMenuURL.Empty() ) { navigator = navigations[UI_CONTEXT_QUICK].front(); navigator->pushDocument( quickMenuURL.CString(), false ); } rocketModule->update(); }
void FunctionCallScheduler::shutdown( void ) { for( FunctionMap::iterator it = functions.begin(); it != functions.end(); ) { ScheduledFunction *func = it->second; functions.erase( it++ ); __delete__( func ); } }
void UI_Main::Destroy( void ) { if( self ) { __delete__( self ); self = NULL; } }
/// Run all currently active schedulers. /// If we're the only reference holder to a document, release the document and its scheduler void update( void ) { SchedulerMap::iterator it = schedulers.begin(); while( it != schedulers.end() ) { // grab the next pointer in case we erase the current one SchedulerMap::iterator next = it; next++; ElementDocument *doc = it->first; FunctionCallScheduler *scheduler = it->second; if( doc->GetReferenceCount() == 1 ) { scheduler->shutdown(); __delete__( scheduler ); doc->RemoveReference(); schedulers.erase( it ); } else { scheduler->update(); } // advance it = next; } }
void Shutdown( void ) { // destructor doesnt throw if( ui_main ) __delete__( ui_main ); ui_main = 0; }
void FunctionCallScheduler::removeFunction( int id ) { FunctionMap::iterator it = functions.find( id ); if( it != functions.end() ) { ScheduledFunction *func = it->second; functions.erase( it ); __delete__( func ); } }
static int UTILS_API _e_file( const char * szBaseDir, const char * szFullPath, const char * szRelativePath, const void * pvSearchContext ) { IBlk * blk; char buf[128]; IFileStream *fs; IF8Stream *s; int roffset; fs = IFileStream_from_file(szFullPath, "rb"); if(!fs){ return 1; } s = __ucast__(IFileStream, IF8Stream, (fs)); blk = IBlk_from_stream(s); if(!blk){ __delete__(fs); return 1; } roffset = __vcall__(s, tell, (s)); load_res_stream(s); probe_blk_resources(blk); fprintf(fdb, "%d=%s,%c%c,%s", count, IBlk_class_name(blk), blk->h.magic >> 8, blk->h.magic & 0xff, szRelativePath ); f8_uuid_to_string(&blk->h.uuid, buf, sizeof(buf)); fprintf(fdb, ",%s", buf); fprintf(fdb, ",%d", roffset); fprintf(fdb, "\n"); delete_blk(blk); __delete__(fs); count++; return 1; }
// runs all active functions void FunctionCallScheduler::update( void ) { for( FunctionMap::iterator it = functions.begin(); it != functions.end(); ) { ScheduledFunction *func = it->second; if( !func->run() ) { functions.erase( it++ ); __delete__( func ); } else { ++it; } } }
~ASWindow() { // detatch itself from the possibly opened modal window detachAsEventListener(); // remove schedulers for all documents we hold references to for( SchedulerMap::iterator it = schedulers.begin(); it != schedulers.end(); it++ ) { ElementDocument *doc = it->first; FunctionCallScheduler *scheduler = it->second; doc->RemoveReference(); scheduler->shutdown(); __delete__( scheduler ); } schedulers.clear(); }
void StreamCache::CallCacheCbByStreamKey( const std::string &key, const std::string &fileName, bool success ) { StreamList &list = streams[key]; // for all streams marked by the same key, fire the cache callback in case of success // then release them for( StreamList::iterator it = list.begin(); it != list.end(); ++it ) { AsyncStream *stream = *it; // only fire the callback in case of success (that means the cache file actually exists) if( success ) { stream->cache_cb( fileName.c_str(), stream->privatep ); } __delete__( stream ); } list.clear(); }
poly_t *PolyAllocator::get_temp( int numverts, int numelems ) { size_t newsize; newsize = sizeForPolyData( numverts, numelems ); if( size_temp < newsize || !base_temp ) { if( base_temp != 0 ) { __delete__( base_temp ); } base_temp = __newa__( unsigned char, newsize ); size_temp = newsize; } poly_temp.numverts = numverts; assignPointers( &poly_temp, base_temp ); return &poly_temp; }
void UI_Main::reloadUI( void ) { int i; for( i = 0; i < UI_NUM_CONTEXTS; i++ ) { UI_Navigation &navigation = navigations[i]; NavigationStack *navigator = navigation.front(); while( !navigation.empty() ) { NavigationStack *stack = navigation.front(); navigation.pop_front(); // clear the navigation stack stack->popAllDocuments(); stack->getCache()->clearCaches(); if( stack != navigator ) { __delete__( stack ); } } navigation.push_front( navigator ); } if( serverBrowser ) { serverBrowser->stopUpdate(); } if( demos ) { demos->Reset(); } destroyDataSources(); createDataSources(); preloadUI(); showUI( true ); }
/* import a resource from disk, and if the resource has already been loaded, increment its reference count. 2005/6/24 the load_from_disk branch is obsolete. */ F8RES_API __bool load_resource( const f8_uuid * id ) { RESMAP::iterator it; it = g_Resources.find(*id); if(it != g_Resources.end()){ it->second.refcount++; return __true; } return __false; #if 0 IFileStream *fs; IF8Stream * str; char buf[43]; f8_uuid_to_string(id, buf, sizeof(buf)); strcat(buf, ".res"); fs = IFileStream_from_file(buf, "rb"); if(!fs){ return __false; } str = __ucast__(IFileStream, IF8Stream, fs); h = _load_res_stream(str); if(h){ if(*id != h->id){ /* error in library */ unload_resource(&h->id); h = 0; } } __delete__(fs); return h? __true : __false; #endif }
void PolyAllocator::free( poly_t *poly ) { __delete__( poly ); }
virtual void Release() { // Com_Printf("decorator instancer destroyed\n"); __delete__( this ); }
PolyAllocator::~PolyAllocator() { // TODO Auto-generated destructor stub if( base_temp != 0 ) __delete__( base_temp ); }
void UnbindWindow( void ) { __delete__( asWindow ); asWindow = NULL; }
void StreamCache::PerformRequest( const char *url, const char *method, const char *data, ui_async_stream_read_cb_t read_cb, ui_async_stream_done_cb_t done_cb, stream_cache_cb cache_cb, void *privatep, int timeout, int cacheTTL ) { std::string cacheFilename, tmpFilename; bool noCache = cacheTTL == 0; cacheFilename = CacheFileForUrl( url, noCache ); tmpFilename = cacheFilename + WSW_UI_STREAMCACHE_EXT; // check in cache first if( cache_cb ) { // redundant check //if( trap::FS_FOpenFile( cacheFilename.c_str(), NULL, FS_READ ) >= 0 ) { time_t mTime; // examine last modified datetime for the cache file // note, that mTime is -1 for non-existing files // or 0 if mTime could not be obtained) mTime = trap::FS_FileMTime( cacheFilename.c_str() ); if( mTime + cacheTTL * 60 > time( NULL ) ) { cache_cb( cacheFilename.c_str(), privatep ); return; } else { // Com_Printf( "Cached expired for %s: %i\n", url, mTime ); } } } // allocate a new stream AsyncStream *stream; stream = __new__( AsyncStream ); stream->url = url; stream->privatep = privatep; stream->read_cb = read_cb; stream->done_cb = done_cb; stream->cache_cb = cache_cb; stream->parent = this; stream->noCache = noCache; // track cached streams by key so we don't fire multiple async requests // for the same URL. When the first request with this key completes, it'll // fire cache callbacks for other streams with the same key if( cache_cb ) { bool inProgress; std::string &cacheKey = cacheFilename; stream->key = cacheKey; // check whether there's already at least one stream with the same key inProgress = streams[cacheKey].size() > 0; if( !inProgress ) { stream->tmpFilename = tmpFilename; if( trap::FS_FOpenFile( tmpFilename.c_str(), &stream->tmpFilenum, FS_WRITE ) < 0 ) { Com_Printf( S_COLOR_YELLOW "WARNING: Failed to open %s for writing\n", tmpFilename.c_str() ); __delete__( stream ); return; } } streams[cacheKey].push_back( stream ); if( inProgress ) { return; } } // fire the async request trap::AsyncStream_PerformRequest( url, method, data, timeout, &StreamRead, &StreamDone, ( void * )stream ); }
// Dtor OptionsForm::~OptionsForm() { if( cvarListener ) __delete__( cvarListener ); }
virtual void ReleaseEvent(Event *event) { // Com_Printf("MyEventInstancer: releasing %s %s\n", event->GetType().CString(), event->GetTargetElement()->GetTagName().CString() ); __delete__( event ); }
void GameAjaxDataSource::StreamDone( int status, const char *contentType, void *privatep ) { SourceFetcherPair *fp = static_cast< SourceFetcherPair *>( privatep ); DynTableFetcher *fetcher = fp->second; GameAjaxDataSource *ds = fp->first; DynTable *table = fetcher->table; std::string tableName = table->GetName(); String rocketTableName = tableName.c_str(); DynTableList::iterator t_it = ds->tableList.find( tableName ); bool hasOldTable = t_it != ds->tableList.end(); DynTableFetcher *oldFetcher = hasOldTable ? t_it->second : NULL; DynTable *oldTable = hasOldTable ? oldFetcher->table : NULL; const char *data = fetcher->buf.c_str(); // simply exit on error or if nothing has changed in table data if( status < 0 || status >= 300 || ( hasOldTable && ( oldFetcher->buf == data ) ) ) { __delete__( table ); __delete__( fetcher ); __delete__( fp ); return; } // parse server response: // { // "key1" = "value1" // "key2" = "value2" // } char *token; std::string key, value; for(; ( token = COM_Parse( &data ) ) && token[0] == '{'; ) { Row row; while( 1 ) { token = COM_ParseExt( &data, true ); if( !token[0] ) break; // error if( token[0] == '}' ) break; // end of callvote key = Q_trim( token ); value = COM_ParseExt( &data, true ); row[key] = value; } table->AddRow( row ); } if( oldTable != NULL ) { ds->tableList[tableName] = fetcher; ds->NotifyRowChange( rocketTableName ); __delete__( oldTable ); __delete__( oldFetcher ); } else { ds->tableList[tableName] = fetcher; ds->NotifyRowAdd( rocketTableName, 0, table->GetNumRows() ); } __delete__( fp ); }
virtual void ReleaseDecorator( Decorator* decorator ) { // Com_Printf("decorator instancer decorator released\n"); __delete__( decorator ); }
virtual void Release() { __delete__( this ); }
void UI_Main::refreshScreen( unsigned int time, int clientState, int serverState, bool demoPlaying, const char *demoName, bool demoPaused, unsigned int demoTime, bool backGround, bool showCursor ) { int i; UI_Navigation::iterator it, it_next; refreshState.time = time; refreshState.clientState = clientState; refreshState.serverState = serverState; refreshState.drawBackground = backGround; if( demoPlaying && !demoInfo.getPlaying() ) { demoInfo.setName( demoName ); } demoInfo.setTime( demoTime ); demoInfo.setPaused( demoPaused ); demoInfo.setPlaying( demoPlaying ); // postponed showing of the stacked document, we need to set the refresh state first if( showNavigationStack ) { UI_Navigation &navigation = navigations[UI_CONTEXT_MAIN]; NavigationStack *navigator = navigation.front(); navigator->showStack( true ); showNavigationStack = false; } // update necessary modules if( serverBrowser ) serverBrowser->updateFrame(); if( demos ) demos->UpdateFrame(); if( ircchannels ) ircchannels->UpdateFrame(); if( clientState == CA_ACTIVE && invalidateAjaxCache ) { gameajax->FlushCache(); invalidateAjaxCache = false; } // TODO: handle the intervalled functions in AS somehow, // taking care that they are not called when menu is hidden. // i may need to make the interface public.. BindFrame( asmodule ); // run incremental garbage collection asmodule->garbageCollectOneStep(); for( i = 0; i < UI_NUM_CONTEXTS; i++ ) { UI_Navigation &navigation = navigations[i]; NavigationStack *navigator = navigation.front(); // free empty navigation stacks for( it = navigation.begin(); it != navigation.end(); it = it_next ) { it_next = it; it_next++; NavigationStack *stack = *it; if( stack != navigator && stack->empty() ) { __delete__( stack ); navigation.erase( it ); } } } // handle main menu context if( menuVisible ) { NavigationStack *navigator = navigations[UI_CONTEXT_MAIN].front(); if( !navigator->hasDocuments() ) { // no documents on stack, release the key dest showUI( false ); } else { if( showCursor ) { rocketModule->hideCursor( UI_CONTEXT_MAIN, 0, RocketModule::HIDECURSOR_REFRESH ); gamepadCursorMove(); } else { rocketModule->hideCursor( UI_CONTEXT_MAIN, RocketModule::HIDECURSOR_REFRESH, 0 ); } } } // rocket update+render rocketModule->update(); if( quickMenuVisible ) { rocketModule->render( UI_CONTEXT_QUICK ); } if( menuVisible ) { rocketModule->render( UI_CONTEXT_MAIN ); } // mark the top stack document as viwed for history tracking for( i = 0; i < UI_NUM_CONTEXTS; i++ ) { UI_Navigation &navigation = navigations[i]; for( it = navigation.begin(); it != navigation.end(); ++it ) { (*it)->markTopAsViewed(); } } // stuff we need to render without using rocket customRender(); }