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