Tiberian Technologies Scripts Reference Revision: 9000
Loading...
Searching...
No Matches
ChunkClass.h
1/* Renegade Scripts.dll
2 Copyright 2013 Tiberian Technologies
3
4 This file is part of the Renegade scripts.dll
5 The Renegade scripts.dll is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2, or (at your option) any later
8 version. See the file COPYING for more details.
9 In addition, an exemption is given to allow Run Time Dynamic Linking of this code with any closed source module that does not contain code covered by this licence.
10 Only the source code to the module(s) containing the licenced code has to be released.
11*/
12#ifndef TT_INCLUDE_CHUNKCLASS_H
13#define TT_INCLUDE_CHUNKCLASS_H
14#include "engine_string.h"
15struct ChunkHeader {
16 unsigned long ChunkType;
17 unsigned long ChunkSize;
18};
19
20struct MicroChunkHeader {
21 unsigned char ChunkType;
22 unsigned char ChunkSize;
23};
24
25struct MicroChunkHeader2 {
26 unsigned short ChunkType;
27 unsigned short ChunkSize;
28};
29
30struct IOVector2Struct {
31 float X;
32 float Y;
33};
34
35struct IOVector3Struct {
36 float X;
37 float Y;
38 float Z;
39};
40
41struct IOVector4Struct {
42 float X;
43 float Y;
44 float Z;
45 float W;
46};
47
48struct IOQuaternionStruct {
49 float Q[4];
50};
51class FileClass;
52class SCRIPTS_API ChunkLoadClass {
53private:
54 FileClass* File;
55 int StackIndex;
56 unsigned long PositionStack[256];
57 ChunkHeader HeaderStack[256];
58 bool InMicroChunk;
59 int MicroChunkPosition;
60 MicroChunkHeader MCHeader;
61public:
62 ChunkLoadClass(FileClass *file);
63 bool Open_Chunk();
64 bool Peek_Next_Chunk(unsigned int *id, unsigned int *length);
65 bool Close_Chunk();
66 unsigned long Cur_Chunk_ID();
67 unsigned long Cur_Chunk_Length();
68 int Cur_Chunk_Depth();
69 int Contains_Chunks();
70 bool Open_Micro_Chunk();
71 bool Close_Micro_Chunk();
72 unsigned long Cur_Micro_Chunk_ID();
73 unsigned long Cur_Micro_Chunk_Length();
74 long Seek(unsigned long nbytes);
75 long Read(void *buf, unsigned long nbytes);
76 long Read(IOVector2Struct *v);
77 long Read(IOVector3Struct *v);
78 long Read(IOVector4Struct *v);
79 long Read(IOQuaternionStruct *q);
80 long Read(StringClass& string);
81
82
83 template<typename T> TT_INLINE long SimpleRead(T& buf)
84 {
85 int length = Read(&buf, sizeof(T));
86 TT_ASSERT(length == sizeof(T))
87 return length;
88 }
89};
90
91class SCRIPTS_API ChunkSaveClass {
92 FileClass* File;
93 int StackIndex;
94 int PositionStack[256];
95 ChunkHeader HeaderStack[256];
96 bool InMicroChunk;
97 int MicroChunkPosition;
98 MicroChunkHeader MCHeader;
99public:
100 ChunkSaveClass(FileClass *file);
101 void Set_Contains_Chunks()
102 {
103 HeaderStack[StackIndex-1].ChunkSize |= 0x80000000;
104 }
105 bool Begin_Chunk(unsigned long id);
106 bool End_Chunk();
107 int Cur_Chunk_Depth();
108 unsigned int Cur_Chunk_Length();
109 bool Begin_Micro_Chunk(unsigned long id);
110 bool End_Micro_Chunk();
111 unsigned long Write(void* buf,unsigned long nbytes);
112 unsigned long Write(IOVector2Struct& v);
113 unsigned long Write(IOVector3Struct& v);
114 unsigned long Write(IOVector4Struct& v);
115 unsigned long Write(IOQuaternionStruct& q);
116 unsigned long Write(const StringClass& sting);
117
118
119 template<typename T> TT_INLINE long SimpleWrite(const T& buf)
120 {
121 int length = Write((void*)&buf, sizeof(T));
122 TT_ASSERT(length == sizeof(T))
123 return length;
124 }
125};
126
127#endif