Panda3D
|
00001 // Filename: vertexDataSaveFile.h 00002 // Created by: drose (12May07) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef VERTEXDATASAVEFILE_H 00016 #define VERTEXDATASAVEFILE_H 00017 00018 #include "pandabase.h" 00019 #include "simpleAllocator.h" 00020 #include "filename.h" 00021 #include "pmutex.h" 00022 00023 #if defined(_WIN32) 00024 #define WIN32_LEAN_AND_MEAN 00025 #include <windows.h> 00026 #endif 00027 00028 class VertexDataSaveBlock; 00029 00030 //////////////////////////////////////////////////////////////////// 00031 // Class : VertexDataSaveFile 00032 // Description : A temporary file to hold the vertex data that has 00033 // been evicted from memory and written to disk. All 00034 // vertex data arrays are written into one large flat 00035 // file. 00036 //////////////////////////////////////////////////////////////////// 00037 class EXPCL_PANDA_GOBJ VertexDataSaveFile : public SimpleAllocator { 00038 public: 00039 VertexDataSaveFile(const Filename &directory, const string &prefix, 00040 size_t max_size); 00041 ~VertexDataSaveFile(); 00042 00043 PUBLISHED: 00044 INLINE bool is_valid() const; 00045 00046 INLINE size_t get_total_file_size() const; 00047 INLINE size_t get_used_file_size() const; 00048 00049 public: 00050 PT(VertexDataSaveBlock) write_data(const unsigned char *data, size_t size, 00051 bool compressed); 00052 bool read_data(unsigned char *data, size_t size, 00053 VertexDataSaveBlock *block); 00054 00055 protected: 00056 virtual SimpleAllocatorBlock *make_block(size_t start, size_t size); 00057 00058 private: 00059 Filename _filename; 00060 bool _is_valid; 00061 size_t _total_file_size; 00062 Mutex _lock; 00063 00064 #ifdef _WIN32 00065 HANDLE _handle; 00066 #else 00067 int _fd; // Posix file descriptor 00068 #endif // _WIN32 00069 }; 00070 00071 //////////////////////////////////////////////////////////////////// 00072 // Class : VertexDataSaveBlock 00073 // Description : A block of bytes on the save file. 00074 //////////////////////////////////////////////////////////////////// 00075 class EXPCL_PANDA_GOBJ VertexDataSaveBlock : public SimpleAllocatorBlock, public ReferenceCount { 00076 protected: 00077 INLINE VertexDataSaveBlock(VertexDataSaveFile *file, 00078 size_t start, size_t size); 00079 00080 public: 00081 INLINE void set_compressed(bool compressed); 00082 INLINE bool get_compressed() const; 00083 00084 private: 00085 bool _compressed; 00086 00087 public: 00088 INLINE unsigned char *get_pointer() const; 00089 00090 friend class VertexDataSaveFile; 00091 }; 00092 00093 #include "vertexDataSaveFile.I" 00094 00095 #endif