From f105f47e91f107a3519e9d5c8c2a3e56074c646f Mon Sep 17 00:00:00 2001 From: timoore Date: Sat, 15 Dec 2007 06:01:24 +0000 Subject: [PATCH] Added copyright to SceneryPager. Removed FGTileLoader --- projects/VC7.1/FlightGear.vcproj | 4 +- src/Scenery/FGTileLoader.cxx | 201 ------------------------------- src/Scenery/FGTileLoader.hxx | 167 ------------------------- src/Scenery/SceneryPager.cxx | 18 +++ 4 files changed, 20 insertions(+), 370 deletions(-) delete mode 100644 src/Scenery/FGTileLoader.cxx delete mode 100644 src/Scenery/FGTileLoader.hxx diff --git a/projects/VC7.1/FlightGear.vcproj b/projects/VC7.1/FlightGear.vcproj index 9b70e91c9..dad4c7e44 100755 --- a/projects/VC7.1/FlightGear.vcproj +++ b/projects/VC7.1/FlightGear.vcproj @@ -2128,10 +2128,10 @@ Name="Lib_Scenery" Filter=""> + RelativePath="..\..\src\Scenery\SceneryPager.cxx"> + RelativePath="..\..\src\Scenery\SceneryPager.hxx"> diff --git a/src/Scenery/FGTileLoader.cxx b/src/Scenery/FGTileLoader.cxx deleted file mode 100644 index 3b6d3ce93..000000000 --- a/src/Scenery/FGTileLoader.cxx +++ /dev/null @@ -1,201 +0,0 @@ -// FGTileLoader - Queue scenery tiles for loading. -// -// Written by Bernie Bright, started March 2001. -// -// Copyright (C) 2001 Bernard Bright - bbright@bigpond.net.au -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -// $Id$ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include - -#include
-#include "FGTileLoader.hxx" -#include "tileentry.hxx" -#include "tilemgr.hxx" - -/** - * - */ -FGTileLoader::FGTileLoader() -{ -#if defined(ENABLE_THREADS) - // Create and start the loader threads. - for (int i = 0; i < MAX_THREADS; ++i) - { - threads[i] = new LoaderThread(this); - threads[i]->start( 1 ); - } -#endif // ENABLE_THREADS -} - -/** - * Terminate all threads. - */ -FGTileLoader::~FGTileLoader() -{ -#if defined(ENABLE_THREADS) - // Wake up its time to die. - // queue_cond.broadcast(); - - for (int i = 0; i < MAX_THREADS; ++i) - { - threads[i]->cancel(); - threads[i]->join(); - } -#endif // ENABLE_THREADS -} - - -#if 0 // we don't ever want to do this I don't think -/** - * - */ -void FGTileLoader::reinit() { - while ( !tile_load_queue.empty() ) { - tile_load_queue.pop(); - } -} -#endif - - -/** - * - */ -void -FGTileLoader::add( FGTileEntry* tile ) -{ - /** - * Initialise tile_path here and not in ctor to avoid problems - * with the initialisation order of global objects. - */ - static bool beenhere = false; - if (!beenhere) { - tile_path = globals->get_fg_scenery(); - if (!tile_path.size()) - throw sg_throwable(string("No valid scenery path defined!")); - - beenhere = true; - } - - tile_load_queue.push( tile ); -} - -#ifdef WISH_PLIB_WAS_THREADED // but it isn't -/** - * - */ -void -FGTileLoader::remove( FGTileEntry* tile ) -{ - tile_free_queue.push( tile ); -} -#endif - -/** - * - */ -void -FGTileLoader::update() -{ - -#if defined(ENABLE_THREADS) - // send a signal to the pager thread that it is allowed to load - // another tile - mutex.lock(); - frame_cond.signal(); - mutex.unlock(); -#else - if ( !tile_load_queue.empty() ) { - // cout << "loading next tile ..." << endl; - // load the next tile in the queue - FGTileEntry* tile = tile_load_queue.front(); - tile_load_queue.pop(); - - tile->load( tile_path, true ); - - FGTileMgr::ready_to_attach( tile ); - } - -#ifdef WISH_PLIB_WAS_THREADED // but it isn't - if ( !tile_free_queue.empty() ) { - // cout << "freeing next tile ..." << endl; - // free the next tile in the queue - FGTileEntry* tile = tile_free_queue.front(); - tile_free_queue.pop(); - tile->free_tile(); - delete tile; - } -#endif - -#endif // ENABLE_THREADS - -} - - -#if defined(ENABLE_THREADS) -/** - * Ensure mutex is unlocked. - */ -void -cleanup_handler( void* arg ) -{ - FGTileLoader* loader = (FGTileLoader*) arg; - loader->mutex.unlock(); -} - -/** - * - */ -void -FGTileLoader::LoaderThread::run() -{ - pthread_cleanup_push( cleanup_handler, loader ); - while ( true ) { - // Wait for a load request to be placed in the queue. - FGTileEntry* tile = loader->tile_load_queue.pop(); - - // Wait for the next frame signal before we load a tile from the queue - loader->mutex.lock(); - loader->frame_cond.wait( loader->mutex ); - loader->mutex.unlock(); - - set_cancel( SGThread::CANCEL_DISABLE ); - tile->load( loader->tile_path, true ); - set_cancel( SGThread::CANCEL_DEFERRED ); - - FGTileMgr::ready_to_attach( tile ); - -#ifdef WISH_PLIB_WAS_THREADED // but it isn't - // Handle and pending removals - while ( !loader->tile_free_queue.empty() ) { - // cout << "freeing next tile ..." << endl; - // free the next tile in the queue - FGTileEntry* tile = loader->tile_free_queue.pop(); - tile->free_tile(); - delete tile; - } -#endif - - } - pthread_cleanup_pop(1); -} -#endif // ENABLE_THREADS diff --git a/src/Scenery/FGTileLoader.hxx b/src/Scenery/FGTileLoader.hxx deleted file mode 100644 index fcfd0d139..000000000 --- a/src/Scenery/FGTileLoader.hxx +++ /dev/null @@ -1,167 +0,0 @@ -// FGTileLoader - Queue scenery tiles for loading. -// -// Written by Bernie Bright, started March 2001. -// -// Copyright (C) 2001 Bernard Bright - bbright@bigpond.net.au -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -// $Id$ - - -#ifndef FG_TILE_LOADER_HXX -#define FG_TILE_LOADER_HXX - -#include -#include - -#if defined(ENABLE_THREADS) -# include -# include -#else -# include - SG_USING_STD( queue ); -#endif - - -// Forward reference. -class FGTileEntry; - -/** - * Queues tiles for loading, possibly by a separate thread. - */ -class FGTileLoader -{ -public: - - /** - * Constructor. - */ - FGTileLoader(); - - /** - * Destructor. - */ - ~FGTileLoader(); - -#if 0 // we don't ever want to do this I don't think - /** - * Flush anything in pending load queue without doing the work - * Leave the free queue intact since that's are only record of - * things we need to remove. - */ - void reinit(); -#endif - - /** - * Add a tile to the end of the load queue. - * @param tile The tile to be loaded from disk. - */ - void add( FGTileEntry* tile ); - -#ifdef WISH_PLIB_WAS_THREADED // but it isn't - /** - * Remove a tile from memory. - * @param tile The tile to be removed from memory. - */ - void remove( FGTileEntry* tile ); -#endif - - /** - * The tile loader thread will only load one tile per call to the - * update() method. This is a way to spread out the work of the - * tile loader and slow it down so it is less intrusive. For - * systems built without thead support this is a no-op. - */ - void update(); - - /** - * Returns whether the load queue is empty (contains no elements). - * @return true if load queue is empty otherwise returns false. - */ - // bool empty() const { return tile_load_queue.empty(); } - -private: - -private: - -#if defined(ENABLE_THREADS) - /** - * FIFO queue of tiles to load from data files. - */ - SGBlockingQueue< FGTileEntry * > tile_load_queue; - // SGBlockingQueue< FGTileEntry * > tile_free_queue; -#else - queue< FGTileEntry * > tile_load_queue; - // queue< FGTileEntry * > tile_free_queue; -#endif - - /** - * Base names of directories containing tile data files. - */ - string_list tile_path; - -#if defined(ENABLE_THREADS) - /** - * Maximum number of threads to create for loading tiles. - */ - enum { MAX_THREADS = 1 }; - - /** - * This class represents the thread of execution responsible for - * loading a tile. - */ - class LoaderThread : public SGThread - { - public: - LoaderThread( FGTileLoader* l ) : loader(l) {} - ~LoaderThread() {} - - /** - * Reads the tile from disk. - */ - void run(); - - private: - FGTileLoader* loader; - - private: - // not implemented. - LoaderThread(); - LoaderThread( const LoaderThread& ); - LoaderThread& operator=( const LoaderThread& ); - }; - - friend class LoaderThread; - - /** - * Array of loading threads. - */ - LoaderThread* threads[ MAX_THREADS ]; - - /** - * Lock and synchronize access to tile queue. - */ - SGMutex mutex; - SGPthreadCond frame_cond; - - /** - * Thread cleanup handler. - */ - friend void cleanup_handler( void* ); -#endif // ENABLE_THREADS -}; - -#endif // FG_TILE_LOADER_HXX diff --git a/src/Scenery/SceneryPager.cxx b/src/Scenery/SceneryPager.cxx index 1d411409b..5615436e4 100644 --- a/src/Scenery/SceneryPager.cxx +++ b/src/Scenery/SceneryPager.cxx @@ -1,3 +1,21 @@ +// SceneryPager.hxx -- Interface to OSG database pager +// +// Copyright (C) 2007 Tim Moore timoore@redhat.com +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + #include "SceneryPager.hxx" #include #include -- 2.39.5