2001-04-11 02:47:15 +00:00
|
|
|
// 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef FG_TILE_LOADER_HXX
|
|
|
|
#define FG_TILE_LOADER_HXX
|
|
|
|
|
|
|
|
#include <simgear/bucket/newbucket.hxx>
|
|
|
|
#include <simgear/misc/sg_path.hxx>
|
|
|
|
|
2005-11-22 17:02:31 +00:00
|
|
|
#if defined(ENABLE_THREADS)
|
2001-04-11 02:47:15 +00:00
|
|
|
# include <simgear/threads/SGThread.hxx>
|
2001-04-16 20:03:52 +00:00
|
|
|
# include <simgear/threads/SGQueue.hxx>
|
2001-05-18 20:31:23 +00:00
|
|
|
#else
|
|
|
|
# include <queue>
|
2001-07-12 17:55:44 +00:00
|
|
|
SG_USING_STD( queue );
|
2001-04-11 02:47:15 +00:00
|
|
|
#endif
|
|
|
|
|
2001-07-12 17:55:44 +00:00
|
|
|
|
2001-04-11 02:47:15 +00:00
|
|
|
// Forward reference.
|
|
|
|
class FGTileEntry;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Queues tiles for loading, possibly by a separate thread.
|
|
|
|
*/
|
|
|
|
class FGTileLoader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*/
|
|
|
|
FGTileLoader();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor.
|
|
|
|
*/
|
|
|
|
~FGTileLoader();
|
|
|
|
|
2001-05-30 18:21:03 +00:00
|
|
|
#if 0 // we don't ever want to do this I don't think
|
2001-05-21 20:44:59 +00:00
|
|
|
/**
|
|
|
|
* 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();
|
2001-05-30 18:21:03 +00:00
|
|
|
#endif
|
2001-05-21 20:44:59 +00:00
|
|
|
|
2001-04-11 02:47:15 +00:00
|
|
|
/**
|
|
|
|
* Add a tile to the end of the load queue.
|
|
|
|
* @param tile The tile to be loaded from disk.
|
|
|
|
*/
|
|
|
|
void add( FGTileEntry* tile );
|
|
|
|
|
2001-05-20 06:49:06 +00:00
|
|
|
#ifdef WISH_PLIB_WAS_THREADED // but it isn't
|
2001-05-19 16:59:43 +00:00
|
|
|
/**
|
|
|
|
* Remove a tile from memory.
|
|
|
|
* @param tile The tile to be removed from memory.
|
|
|
|
*/
|
|
|
|
void remove( FGTileEntry* tile );
|
2001-05-20 06:49:06 +00:00
|
|
|
#endif
|
2001-05-19 16:59:43 +00:00
|
|
|
|
2001-04-14 03:11:39 +00:00
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
|
2001-04-11 02:47:15 +00:00
|
|
|
/**
|
|
|
|
* Returns whether the load queue is empty (contains no elements).
|
|
|
|
* @return true if load queue is empty otherwise returns false.
|
|
|
|
*/
|
2001-05-18 20:31:23 +00:00
|
|
|
// bool empty() const { return tile_load_queue.empty(); }
|
2001-04-11 02:47:15 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2005-11-22 17:02:31 +00:00
|
|
|
#if defined(ENABLE_THREADS)
|
2001-04-11 02:47:15 +00:00
|
|
|
/**
|
|
|
|
* FIFO queue of tiles to load from data files.
|
|
|
|
*/
|
2001-05-19 16:59:43 +00:00
|
|
|
SGBlockingQueue< FGTileEntry * > tile_load_queue;
|
2001-05-20 06:49:06 +00:00
|
|
|
// SGBlockingQueue< FGTileEntry * > tile_free_queue;
|
2001-05-18 20:31:23 +00:00
|
|
|
#else
|
2001-05-19 16:59:43 +00:00
|
|
|
queue< FGTileEntry * > tile_load_queue;
|
2001-05-20 06:49:06 +00:00
|
|
|
// queue< FGTileEntry * > tile_free_queue;
|
2001-04-17 05:21:56 +00:00
|
|
|
#endif
|
|
|
|
|
2001-04-11 02:47:15 +00:00
|
|
|
/**
|
Melchior FRANZ:
Wouldn't it be better to prepare the whole list of paths (or two
separate ones for Terrain/Objects if necessary) in FGGlobals::set_fg_scenery,
and to pass the vector<string>s to FGTileEntry::load? It doesn't seem to make
a lot of sense to split the path up, modify it, mount it together to one string
again, and then let FGTileEntry::load split it up again.
Here we go:
Main/globals.cxx
================
As fg_scenery is now a string_list, we don't need initialization. Furthermore,
this list is cleared with every set_fg_scenery() call.
ctor: create default dir from fg_root if necessary. Otherwise check all paths
of --fg-scenery/FG_SCENERY: If the path doesn't exist, ignore it. If it contains
a dir Terrain and/or Objects, then only add that to the list. If it contains
neither, then use the path as is.
Scenery/tileentry.cxx
=====================
Trivial: don't split a "base path", but use the given path_list as is.
(I considered a variable name "path_list" better suited than "search".)
Scenery/FGTileLoader.cxx
========================
No more fiddling with sub-paths. This has to be delivered by get_fg_scenery
already.
2004-06-08 15:32:09 +00:00
|
|
|
* Base names of directories containing tile data files.
|
2001-04-11 02:47:15 +00:00
|
|
|
*/
|
Melchior FRANZ:
Wouldn't it be better to prepare the whole list of paths (or two
separate ones for Terrain/Objects if necessary) in FGGlobals::set_fg_scenery,
and to pass the vector<string>s to FGTileEntry::load? It doesn't seem to make
a lot of sense to split the path up, modify it, mount it together to one string
again, and then let FGTileEntry::load split it up again.
Here we go:
Main/globals.cxx
================
As fg_scenery is now a string_list, we don't need initialization. Furthermore,
this list is cleared with every set_fg_scenery() call.
ctor: create default dir from fg_root if necessary. Otherwise check all paths
of --fg-scenery/FG_SCENERY: If the path doesn't exist, ignore it. If it contains
a dir Terrain and/or Objects, then only add that to the list. If it contains
neither, then use the path as is.
Scenery/tileentry.cxx
=====================
Trivial: don't split a "base path", but use the given path_list as is.
(I considered a variable name "path_list" better suited than "search".)
Scenery/FGTileLoader.cxx
========================
No more fiddling with sub-paths. This has to be delivered by get_fg_scenery
already.
2004-06-08 15:32:09 +00:00
|
|
|
string_list tile_path;
|
2001-04-11 02:47:15 +00:00
|
|
|
|
2005-11-22 17:02:31 +00:00
|
|
|
#if defined(ENABLE_THREADS)
|
2001-04-11 02:47:15 +00:00
|
|
|
/**
|
|
|
|
* 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;
|
2003-05-13 03:18:42 +00:00
|
|
|
SGPthreadCond frame_cond;
|
2001-04-11 02:47:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Thread cleanup handler.
|
|
|
|
*/
|
|
|
|
friend void cleanup_handler( void* );
|
|
|
|
#endif // ENABLE_THREADS
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // FG_TILE_LOADER_HXX
|