1 // FGTileLoader - Queue scenery tiles for loading.
3 // Written by Bernie Bright, started March 2001.
5 // Copyright (C) 2001 Bernard Bright - bbright@bigpond.net.au
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <Main/globals.hxx>
28 #include "FGTileLoader.hxx"
29 #include "tileentry.hxx"
30 #include "tilemgr.hxx"
35 FGTileLoader::FGTileLoader()
38 // Create and start the loader threads.
39 for (int i = 0; i < MAX_THREADS; ++i)
41 threads[i] = new LoaderThread(this);
44 #endif // ENABLE_THREADS
48 * Terminate all threads.
50 FGTileLoader::~FGTileLoader()
53 // Wake up its time to die.
54 // queue_cond.broadcast();
56 for (int i = 0; i < MAX_THREADS; ++i)
61 #endif // ENABLE_THREADS
68 FGTileLoader::add( FGTileEntry* tile )
71 * Initialise tile_path here and not in ctor to avoid problems
72 * with the initialastion order of global objects.
74 static bool beenhere = false;
77 if ( globals->get_fg_scenery() != (string)"" ) {
78 tile_path.set( globals->get_fg_scenery() );
80 tile_path.set( globals->get_fg_root() );
81 tile_path.append( "Scenery" );
87 tile_queue.push( tile );
89 tile->load( tile_path, true );
90 #endif // ENABLE_THREADS
97 FGTileLoader::update()
103 #endif // ENABLE_THREADS
107 #ifdef ENABLE_THREADS
112 FGTileLoader::LoaderThread::run()
114 pthread_cleanup_push( cleanup_handler, loader );
116 // Wait for a load request to be placed in the queue.
117 FGTileEntry* tile = loader->tile_queue.pop();
119 // Wait for the next frame signal before we load a tile from the queue
120 // loader->mutex.lock();
121 // loader->frame_cond.wait( loader->mutex );
122 // loader->mutex.unlock();
124 set_cancel( SGThread::CANCEL_DISABLE );
125 tile->load( loader->tile_path, true );
126 set_cancel( SGThread::CANCEL_DEFERRED );
128 FGTileMgr::loaded( tile );
130 pthread_cleanup_pop(1);
134 * Ensure mutex is unlocked.
137 cleanup_handler( void* arg )
139 FGTileLoader* loader = (FGTileLoader*) arg;
140 loader->mutex.unlock();
142 #endif // ENABLE_THREADS