Panda3D
vertexDataSaveFile.h
1 // Filename: vertexDataSaveFile.h
2 // Created by: drose (12May07)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef VERTEXDATASAVEFILE_H
16 #define VERTEXDATASAVEFILE_H
17 
18 #include "pandabase.h"
19 #include "simpleAllocator.h"
20 #include "filename.h"
21 #include "pmutex.h"
22 
23 #if defined(_WIN32)
24 #ifndef WIN32_LEAN_AND_MEAN
25 #define WIN32_LEAN_AND_MEAN 1
26 #endif
27 #include <windows.h>
28 #endif
29 
31 
32 ////////////////////////////////////////////////////////////////////
33 // Class : VertexDataSaveFile
34 // Description : A temporary file to hold the vertex data that has
35 // been evicted from memory and written to disk. All
36 // vertex data arrays are written into one large flat
37 // file.
38 ////////////////////////////////////////////////////////////////////
39 class EXPCL_PANDA_GOBJ VertexDataSaveFile : public SimpleAllocator {
40 public:
41  VertexDataSaveFile(const Filename &directory, const string &prefix,
42  size_t max_size);
44 
45 PUBLISHED:
46  INLINE bool is_valid() const;
47 
48  INLINE size_t get_total_file_size() const;
49  INLINE size_t get_used_file_size() const;
50 
51 public:
52  PT(VertexDataSaveBlock) write_data(const unsigned char *data, size_t size,
53  bool compressed);
54  bool read_data(unsigned char *data, size_t size,
55  VertexDataSaveBlock *block);
56 
57 protected:
58  virtual SimpleAllocatorBlock *make_block(size_t start, size_t size);
59 
60 private:
61  Filename _filename;
62  bool _is_valid;
63  size_t _total_file_size;
64  Mutex _lock;
65 
66 #ifdef _WIN32
67  HANDLE _handle;
68 #else
69  int _fd; // Posix file descriptor
70 #endif // _WIN32
71 };
72 
73 ////////////////////////////////////////////////////////////////////
74 // Class : VertexDataSaveBlock
75 // Description : A block of bytes on the save file.
76 ////////////////////////////////////////////////////////////////////
77 class EXPCL_PANDA_GOBJ VertexDataSaveBlock : public SimpleAllocatorBlock, public ReferenceCount {
78 protected:
80  size_t start, size_t size);
81 
82 public:
83  INLINE void set_compressed(bool compressed);
84  INLINE bool get_compressed() const;
85 
86 private:
87  bool _compressed;
88 
89 public:
90  INLINE unsigned char *get_pointer() const;
91 
92  friend class VertexDataSaveFile;
93 };
94 
95 #include "vertexDataSaveFile.I"
96 
97 #endif
A block of bytes on the save file.
A temporary file to hold the vertex data that has been evicted from memory and written to disk...
An implementation of a very simple block allocator.
A standard mutex, or mutual exclusion lock.
Definition: pmutex.h:44
A single block as returned from SimpleAllocator::alloc().
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
A base class for all things that want to be reference-counted.