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.
24 #ifndef FG_TILE_LOADER_HXX
25 #define FG_TILE_LOADER_HXX
27 #include <simgear/bucket/newbucket.hxx>
28 #include <simgear/misc/sg_path.hxx>
31 # include <simgear/threads/SGThread.hxx>
32 # include <simgear/threads/SGQueue.hxx>
41 * Queues tiles for loading, possibly by a separate thread.
58 * Add a tile to the end of the load queue.
59 * @param tile The tile to be loaded from disk.
61 void add( FGTileEntry* tile );
63 #ifdef WISH_PLIB_WAS_THREADED // but it isn't
65 * Remove a tile from memory.
66 * @param tile The tile to be removed from memory.
68 void remove( FGTileEntry* tile );
72 * The tile loader thread will only load one tile per call to the
73 * update() method. This is a way to spread out the work of the
74 * tile loader and slow it down so it is less intrusive. For
75 * systems built without thead support this is a no-op.
80 * Returns whether the load queue is empty (contains no elements).
81 * @return true if load queue is empty otherwise returns false.
83 // bool empty() const { return tile_load_queue.empty(); }
91 * FIFO queue of tiles to load from data files.
93 SGBlockingQueue< FGTileEntry * > tile_load_queue;
94 // SGBlockingQueue< FGTileEntry * > tile_free_queue;
96 queue< FGTileEntry * > tile_load_queue;
97 // queue< FGTileEntry * > tile_free_queue;
101 * Base name of directory containing tile data file.
105 #ifdef ENABLE_THREADS
107 * Maximum number of threads to create for loading tiles.
109 enum { MAX_THREADS = 1 };
112 * This class represents the thread of execution responsible for
115 class LoaderThread : public SGThread
118 LoaderThread( FGTileLoader* l ) : loader(l) {}
122 * Reads the tile from disk.
127 FGTileLoader* loader;
132 LoaderThread( const LoaderThread& );
133 LoaderThread& operator=( const LoaderThread& );
136 friend class LoaderThread;
139 * Array of loading threads.
141 LoaderThread* threads[ MAX_THREADS ];
144 * Lock and synchronize access to tile queue.
147 SGCondition frame_cond;
150 * Thread cleanup handler.
152 friend void cleanup_handler( void* );
153 #endif // ENABLE_THREADS
156 #endif // FG_TILE_LOADER_HXX