forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbamCache.h
More file actions
137 lines (107 loc) · 4.18 KB
/
bamCache.h
File metadata and controls
137 lines (107 loc) · 4.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Filename: bamCache.h
// Created by: drose (09Jun06)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) Carnegie Mellon University. All rights reserved.
//
// All use of this software is subject to the terms of the revised BSD
// license. You should have received a copy of this license along
// with this source code in a file named "LICENSE."
//
////////////////////////////////////////////////////////////////////
#ifndef BAMCACHE_H
#define BAMCACHE_H
#include "pandabase.h"
#include "bamCacheRecord.h"
#include "pointerTo.h"
#include "filename.h"
#include "pmap.h"
#include "pvector.h"
#include "reMutex.h"
#include "reMutexHolder.h"
#include <time.h>
class BamCacheIndex;
////////////////////////////////////////////////////////////////////
// Class : BamCache
// Description : This class maintains a cache of Bam and/or Txo
// objects generated from model files and texture images
// (as well as possibly other kinds of loadable objects
// that can be stored in bam file format).
//
// This class also maintains a persistent index that
// lists all of the cached objects (see BamCacheIndex).
// We go through some considerable effort to make sure
// this index gets saved correctly to disk, even in the
// presence of multiple different processes writing to
// the same index, and without relying too heavily on
// low-level os-provided file locks (which work poorly
// with C++ iostreams).
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA_PUTIL BamCache {
PUBLISHED:
BamCache();
~BamCache();
INLINE void set_active(bool flag);
INLINE bool get_active() const;
INLINE void set_cache_models(bool flag);
INLINE bool get_cache_models() const;
INLINE void set_cache_textures(bool flag);
INLINE bool get_cache_textures() const;
INLINE void set_cache_compressed_textures(bool flag);
INLINE bool get_cache_compressed_textures() const;
void set_root(const Filename &root);
INLINE Filename get_root() const;
INLINE void set_flush_time(int flush_time);
INLINE int get_flush_time() const;
INLINE void set_cache_max_kbytes(int max_kbytes);
INLINE int get_cache_max_kbytes() const;
INLINE void set_read_only(bool ro);
INLINE bool get_read_only() const;
PT(BamCacheRecord) lookup(const Filename &source_filename,
const string &cache_extension);
bool store(BamCacheRecord *record);
void consider_flush_index();
void flush_index();
void list_index(ostream &out, int indent_level = 0) const;
INLINE static BamCache *get_global_ptr();
private:
void read_index();
bool read_index_pathname(Filename &index_pathname,
string &index_ref_contents) const;
void merge_index(BamCacheIndex *new_index);
void rebuild_index();
INLINE void mark_index_stale();
void add_to_index(const BamCacheRecord *record);
void remove_from_index(const Filename &source_filename);
void check_cache_size();
void emergency_read_only();
static BamCacheIndex *do_read_index(const Filename &index_pathname);
static bool do_write_index(const Filename &index_pathname, const BamCacheIndex *index);
PT(BamCacheRecord) find_and_read_record(const Filename &source_pathname,
const Filename &cache_filename);
PT(BamCacheRecord) read_record(const Filename &source_pathname,
const Filename &cache_filename,
int pass);
static PT(BamCacheRecord) do_read_record(const Filename &cache_pathname,
bool read_data);
static string hash_filename(const string &filename);
static void make_global();
bool _active;
bool _cache_models;
bool _cache_textures;
bool _cache_compressed_textures;
bool _read_only;
Filename _root;
int _flush_time;
int _max_kbytes;
static BamCache *_global_ptr;
BamCacheIndex *_index;
time_t _index_stale_since;
Filename _index_pathname;
string _index_ref_contents;
ReMutex _lock;
};
#include "bamCache.I"
#endif