Panda3D
Loading...
Searching...
No Matches
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 */
36class EXPCL_PANDA_GOBJ VertexDataSaveFile : public SimpleAllocator {
37public:
38 VertexDataSaveFile(const Filename &directory, const std::string &prefix,
39 size_t max_size);
40 ~VertexDataSaveFile();
41
42PUBLISHED:
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
48public:
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
54protected:
55 virtual SimpleAllocatorBlock *make_block(size_t start, size_t size);
56
57private:
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 */
73class EXPCL_PANDA_GOBJ VertexDataSaveBlock : public SimpleAllocatorBlock, public ReferenceCount {
74protected:
75 INLINE VertexDataSaveBlock(VertexDataSaveFile *file,
76 size_t start, size_t size);
77
78public:
79 INLINE void set_compressed(bool compressed);
80 INLINE bool get_compressed() const;
81
82private:
83 bool _compressed;
84
85public:
86 INLINE unsigned char *get_pointer() const;
87
88 friend class VertexDataSaveFile;
89};
90
91#include "vertexDataSaveFile.I"
92
93#endif
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
A standard mutex, or mutual exclusion lock.
Definition pmutex.h:40
A block of bytes on the save file.
void set_compressed(bool compressed)
Sets the compressed flag.
bool get_compressed() const
Returns the compressed flag.
bool is_valid() const
Returns true if the save file was successfully created and is ready for use, false if there was an er...
size_t get_total_file_size() const
Returns the amount of space consumed by the save file, including unused portions.
bool read_data(unsigned char *data, size_t size, VertexDataSaveBlock *block)
Reads a block of data from the file, and returns true on success, false on failure.
size_t get_used_file_size() const
Returns the amount of space within the save file that is currently in use.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.