1 #ifndef _miscchunk_hpp 2 #define _miscchunk_hpp 1 3 4 #include <time.h> 5 #include "chunk.hpp" 6 7 #include "chnktype.hpp" 8 9 #define UseLocalAssert No 10 #include "ourasert.h" 11 #define assert(x) GLOBALASSERT(x) 12 13 #define twprintf printf 14 15 extern char * users_name; 16 17 class File_Chunk; 18 19 class Lockable_Chunk_With_Children : public Chunk_With_Children 20 { 21 22 public: 23 Lockable_Chunk_With_Children(Chunk_With_Children * parent,const char * identifier)24 Lockable_Chunk_With_Children (Chunk_With_Children * parent, const char * identifier) 25 : Chunk_With_Children (parent, identifier), 26 output_chunk_for_process(FALSE), 27 updated(FALSE), updated_outside(FALSE), local_lock(FALSE), 28 external_lock(FALSE), deleted(FALSE) 29 {} 30 31 32 // derived classes from this class must have the 33 // following functions (or it won't compile)!! 34 35 virtual BOOL file_equals(HANDLE &) = 0; 36 // the file equals function knows to look in 37 // the file from the start of the current chunk 38 // to see if the current chunk is the same one 39 40 virtual const char * get_head_id() = 0; 41 virtual void set_lock_user(char *) = 0; 42 43 // this function will lock the chunk if it can - 44 // will return true on success or if the chunk has 45 // already been locked locally. 46 47 BOOL lock_chunk(File_Chunk &); 48 49 // The unlock_chunk will unlock the chunk 50 // if the updateyn flag is set, the updated flag will be set 51 // internally and the chunk may be updated on the next file update 52 // If there is no update, the chunk will be unlocked in the file 53 54 BOOL unlock_chunk (File_Chunk &, BOOL updateyn); 55 56 BOOL update_chunk_in_file(HANDLE &rif_file); 57 58 // Selective output functions, 59 // These will output on condition of the flag, the flag will be set 60 // to FALSE 61 62 BOOL output_chunk_for_process; 63 64 virtual size_t size_chunk_for_process(); 65 66 virtual void fill_data_block_for_process(char * data_start); 67 68 69 BOOL updated; 70 BOOL updated_outside; 71 BOOL local_lock; 72 BOOL external_lock; 73 74 BOOL deleted; 75 76 }; 77 78 79 /////////////////////////////////////////////// 80 81 class Object_Chunk; 82 class Shape_Chunk; 83 class Dummy_Object_Chunk; 84 class Environment_Data_Chunk; 85 86 class File_Chunk : public Chunk_With_Children 87 { 88 public: 89 90 //constructor 91 File_Chunk (const char * filename); 92 File_Chunk (); 93 94 //destructor 95 ~File_Chunk (); 96 97 // file handling 98 BOOL update_file (); 99 BOOL write_file (const char *); 100 101 BOOL check_file(); 102 103 BOOL update_chunks_from_file(); 104 105 // the file_chunk must link all of its shapes & objects together 106 // in post_input_processing 107 108 virtual void post_input_processing(); 109 110 // copy string when constructed 111 // to this variable 112 char * filename; 113 114 115 // some easy access functions 116 117 void list_objects(List<Object_Chunk *> * pList); 118 void list_shapes(List<Shape_Chunk *> * pList); 119 void list_dummy_objects(List<Dummy_Object_Chunk *> * pList); 120 121 Environment_Data_Chunk * get_env_data(); 122 123 Object_Chunk* get_object_by_index(int index); 124 void assign_index_to_object(Object_Chunk* object); 125 126 private: 127 128 friend class Shape_Chunk; 129 friend class Object_Chunk; 130 friend class Lockable_Chunk_With_Children; 131 132 int flags; 133 134 int object_array_size; 135 Object_Chunk** object_array; 136 137 void build_object_array(); 138 }; 139 140 /////////////////////////////////////////////// 141 142 143 class RIF_Version_Num_Chunk : public Chunk 144 { 145 public: RIF_Version_Num_Chunk(Chunk_With_Children * parent,const char * data,size_t)146 RIF_Version_Num_Chunk (Chunk_With_Children * parent, const char *data, size_t /*size*/) 147 : Chunk (parent,"RIFVERIN"), file_version_no (*((int *) data)) 148 {} 149 150 int file_version_no; 151 152 // output_chunk updates the above 153 154 virtual void fill_data_block (char * data_start); 155 size_chunk()156 virtual size_t size_chunk () 157 { 158 chunk_size = 16; 159 return 16; 160 } 161 162 private: 163 164 friend class File_Chunk; 165 friend class GodFather_Chunk; 166 friend class RIF_File_Chunk; 167 168 169 RIF_Version_Num_Chunk(Chunk_With_Children * parent)170 RIF_Version_Num_Chunk (Chunk_With_Children * parent) 171 : Chunk (parent,"RIFVERIN"), file_version_no (0) 172 {} 173 }; 174 175 /////////////////////////////////////////////// 176 177 class RIF_File_Chunk : public Chunk_With_Children 178 { 179 public: 180 181 // This is a special chunk which does not output itself 182 183 RIF_File_Chunk (Chunk_With_Children * parent, const char * fname); 184 size_chunk()185 size_t size_chunk() 186 { 187 return chunk_size = 0; 188 } 189 190 virtual void post_input_processing(); 191 output_chunk(HANDLE &)192 BOOL output_chunk (HANDLE & /*h*/){return TRUE;}; fill_data_block(char *)193 void fill_data_block (char * /*c*/){}; 194 195 void list_objects(List<Object_Chunk *> * pList); 196 void list_shapes(List<Shape_Chunk *> * pList); 197 Environment_Data_Chunk * get_env_data(); 198 199 }; 200 201 /////////////////////////////////////////////// 202 203 class RIF_Name_Chunk : public Chunk 204 { 205 public: 206 207 RIF_Name_Chunk (Chunk_With_Children * parent, const char * rname); 208 ~RIF_Name_Chunk(); 209 // constructor from buffer 210 RIF_Name_Chunk (Chunk_With_Children * parent, const char * sdata, size_t ssize); 211 char * rif_name; 212 size_chunk()213 virtual size_t size_chunk () 214 { 215 return (chunk_size = 12 + strlen (rif_name) + 4 - strlen (rif_name)%4); 216 } 217 218 virtual void fill_data_block (char * data_start); 219 220 private: 221 222 friend class Environment_Data_Chunk; 223 friend class Environment_Game_Mode_Chunk; 224 friend class Shape_External_File_Chunk; 225 friend class Sprite_Header_Chunk; 226 227 228 229 }; 230 231 #endif 232