~ubuntu-branches/ubuntu/quantal/flightgear/quantal

« back to all changes in this revision

Viewing changes to src/Scenery/newcache.hxx

  • Committer: Bazaar Package Importer
  • Author(s): Ove Kaaven
  • Date: 2002-03-27 21:50:15 UTC
  • Revision ID: james.westby@ubuntu.com-20020327215015-0rvi3o8iml0a8s93
Tags: upstream-0.7.9
ImportĀ upstreamĀ versionĀ 0.7.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// newcache.hxx -- routines to handle scenery tile caching
 
2
//
 
3
// Written by Curtis Olson, started December 2000.
 
4
//
 
5
// Copyright (C) 2000  Curtis L. Olson  - curt@flightgear.org
 
6
//
 
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.
 
11
//
 
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.
 
16
//
 
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.
 
20
//
 
21
// $Id: newcache.hxx,v 1.9 2001/07/20 20:25:12 curt Exp $
 
22
 
 
23
 
 
24
#ifndef _NEWCACHE_HXX
 
25
#define _NEWCACHE_HXX
 
26
 
 
27
 
 
28
#ifndef __cplusplus                                                          
 
29
# error This library requires C++
 
30
#endif                                   
 
31
 
 
32
 
 
33
#ifdef HAVE_CONFIG_H
 
34
#  include <config.h>
 
35
#endif
 
36
 
 
37
#ifdef HAVE_WINDOWS_H
 
38
#  include <windows.h>
 
39
#endif
 
40
 
 
41
#include <GL/glut.h>
 
42
 
 
43
#include <map>
 
44
 
 
45
#include <simgear/bucket/newbucket.hxx>
 
46
#include <simgear/math/point3d.hxx>
 
47
 
 
48
#include "tileentry.hxx"
 
49
 
 
50
SG_USING_STD(map);
 
51
 
 
52
// A class to store and manage a pile of tiles
 
53
class FGNewCache {
 
54
 
 
55
    typedef map < long, FGTileEntry * > tile_map;
 
56
    typedef tile_map::iterator tile_map_iterator;
 
57
    typedef tile_map::const_iterator const_tile_map_iterator;
 
58
 
 
59
    // cache storage space
 
60
    tile_map tile_cache;
 
61
 
 
62
    // maximum cache size
 
63
    int max_cache_size;
 
64
 
 
65
    // pointers to allow an external linear traversal of cache entries
 
66
    tile_map_iterator current;
 
67
 
 
68
    // Free a tile cache entry
 
69
    void entry_free( long cache_index );
 
70
 
 
71
public:
 
72
 
 
73
    // Constructor
 
74
    FGNewCache();
 
75
 
 
76
    // Destructor
 
77
    ~FGNewCache();
 
78
 
 
79
    // Initialize the tile cache subsystem 
 
80
    void init( void );
 
81
 
 
82
    // Check if the specified "bucket" exists in the cache
 
83
    bool exists( const SGBucket& b ) const;
 
84
 
 
85
    // Ensure at least one entry is free in the cache
 
86
    bool make_space();
 
87
 
 
88
    // Clear all completely loaded tiles (ignores partially loaded tiles)
 
89
    void clear_cache();
 
90
 
 
91
    // Fill in a tile cache entry with real data for the specified bucket 
 
92
    // void fill_in( const SGBucket& b );
 
93
 
 
94
    // Return a pointer to the specified tile cache entry 
 
95
    inline FGTileEntry *get_tile( const long tile_index ) {
 
96
        tile_map_iterator it = tile_cache.find( tile_index );
 
97
        if ( it != tile_cache.end() ) {
 
98
            return it->second;
 
99
        } else {
 
100
            return NULL;
 
101
        }
 
102
    }
 
103
 
 
104
    // Return a pointer to the specified tile cache entry 
 
105
    inline FGTileEntry *get_tile( const SGBucket& b ) {
 
106
        return get_tile( b.gen_index() );
 
107
    }
 
108
 
 
109
    // Return the cache size
 
110
    inline size_t get_size() const { return tile_cache.size(); }
 
111
 
 
112
    // External linear traversal of cache
 
113
    inline void reset_traversal() { current = tile_cache.begin(); }
 
114
    inline bool at_end() { return current == tile_cache.end(); }
 
115
    inline FGTileEntry *get_current() {
 
116
        // cout << "index = " << current->first << endl;
 
117
        return current->second;
 
118
    }
 
119
    inline void next() { ++current; }
 
120
 
 
121
    inline int get_max_cache_size() const { return max_cache_size; }
 
122
    inline void set_max_cache_size( int m ) { max_cache_size = m; }
 
123
 
 
124
    /**
 
125
     * Create a new tile and enqueue it for loading.
 
126
     * @param b 
 
127
     * @return success/failure
 
128
     */
 
129
    bool insert_tile( FGTileEntry* e );
 
130
};
 
131
 
 
132
 
 
133
#endif // _NEWCACHE_HXX