Subversion Repositories spk

Rev

Rev 1 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 cycrow 1
/*
2
  defines bob_dom_cut - class that can manipulate the CUT1 format and all the 
3
  underlying objects
4
*/
5
 
6
#ifndef BOB_DOM_CUT_INCLUDED
7
#define BOB_DOM_CUT_INCLUDED
8
 
9
#include "bob_dom_base.h"
10
#include "bob_dom_bob.h"
11
#include "Settings.h"
12
#include "bob_dom_frame.h"
13
 
14
#include "../common/ext_utils.h"
15
#include "../common/strutils.h"
16
 
17
class bob_dom_cut;
18
class bob_dom_path;
19
class bob_dom_stat;
20
 
21
class bob_dom_name : public bob_dom_string
22
{
23
	public:
24
		static const int hdr_begin=BOB_SECTION_NAME_NAME_BEGIN;
25
		static const int hdr_end=BOB_SECTION_NAME_NAME_END;
26
 
27
		bool load(bob_dom_ibinaryfilestream& is) { return bob_dom_string::load(is, hdr_begin, hdr_end); }
28
		bool toFile(bob_dom_obinaryfilestream& os) { return bob_dom_string::toFile(os, hdr_begin, hdr_end); }
29
		bool toFile(bob_dom_otextfilestream& os);
30
};
31
 
32
class bob_dom_constants : public bob_dom_section
33
{
34
	public:
35
		static const int hdr_begin=BOB_SECTION_NAME_CONST_BEGIN;
36
		static const int hdr_end=BOB_SECTION_NAME_CONST_END;
37
 
38
		struct constant
39
		{
40
			int a;
41
			double b;
42
 
43
			constant() { a=0; b=0; }
44
			bool load(bob_dom_ibinaryfilestream& is);
45
 
46
			bool toFile(bob_dom_obinaryfilestream& os);
47
			bool toFile(bob_dom_otextfilestream& os);
48
		};
49
 
50
		typedef ext::list<constant>::iterator iterator;
51
 
52
		ext::list<constant> values;
53
 
54
		bool load(bob_dom_ibinaryfilestream& is);
55
 
56
		bool toFile(bob_dom_obinaryfilestream& os);
57
		bool toFile(bob_dom_otextfilestream& os);
58
};
59
 
60
struct bob_note
61
{
62
	int value;
63
	char *text;
64
	bob_error_codes errorCode;
65
 
66
	bob_note() { value=0; text=0; errorCode=e_noError; }
67
	~bob_note() { delete[] text; }
68
 
69
	bool load(bob_dom_ibinaryfilestream& is);
70
	bool toFile(bob_dom_obinaryfilestream& os);
71
	bool toFile(bob_dom_otextfilestream& os);
72
};
73
 
74
class bob_dom_notes : public bob_dom_section, public bob_dom_cantainer<bob_note>
75
{
76
	public:
77
		static const int hdr_begin=BOB_SECTION_NAME_NOTE_BEGIN;
78
		static const int hdr_end=BOB_SECTION_NAME_NOTE_END;
79
 
80
		bool load(bob_dom_ibinaryfilestream& is, int lineCount);
81
 
82
		bool toFile(bob_dom_obinaryfilestream& os);
83
		bool toFile(bob_dom_otextfilestream& os);
84
};
85
 
86
// frame
87
#ifdef X2BC_USE_INI_FORMATS
88
class bob_dom_stat : public bob_dom_section, public ext::list<int>
89
{
90
	public:
91
		typedef enum state
92
		{
93
			formatted,
94
			noFormat,
95
			cannotMatchFormat
96
		};
97
 
98
	private:
99
		const Settings::StatFormat *m_format;
100
		state m_state;
101
		void setstate(state newstate) { m_state=newstate; }
102
 
103
	public:
104
		int frameId;
105
 
106
		bob_dom_stat(const Settings *settings) { frameId=0; m_format=0; setstate(formatted); }
107
 
108
		state rdstate() const { return m_state; }
109
 
110
		bool toFile(bob_dom_obinaryfilestream& os);
111
		bool toFile(bob_dom_otextfilestream& os, const Settings *settings);
112
 
113
		bool load(bob_dom_ibinaryfilestream& is, const Settings *settings);
114
};
115
#endif // defined(X2BC_USE_INI_FORMATS)
116
 
117
#ifdef X2BC_USE_INI_FORMATS
118
	typedef bob_dom_cantainer<bob_dom_stat> FrameContainer;
119
#else
120
	typedef bob_dom_cantainer<bob_dom_frame> FrameContainer;
121
#endif
122
 
123
class bob_dom_path : public bob_dom_section, public FrameContainer
124
{
125
	private:
126
		static const int hdr_stat_begin=BOB_SECTION_NAME_STAT_BEGIN;
127
		static const int hdr_stat_end=BOB_SECTION_NAME_STAT_END;
128
		typedef ext::list<int> TempStatList;
129
 
130
		bob_dom_notes m_notes;
131
		const Settings *m_settings;
132
		char *m_bodyId;
133
 
134
		bool loadStatValues(bob_dom_ibinaryfilestream& is, int count);
135
 
136
	public:
137
		enum BodyFlags {
138
			fCamera=1,
139
			fDirLight=2,
140
			fOmniLight=10,
141
			fBody=64,
142
			fScene=128
143
		};
144
 
145
		static const int hdr_begin=BOB_SECTION_NAME_PATH_BEGIN;
146
		static const int hdr_end=BOB_SECTION_NAME_PATH_END;
147
 
148
		bob_dom_name name;
149
		bob_dom_constants constants;
150
 
151
		int partIdx;
152
		int cockpitIdx;
153
		int parentIdx;
154
		int bodyFlags; // 'c' for cameras, 'l' for lights
155
 
156
		bob_dom_bob *bob;
157
 
158
		bob_dom_path(const Settings *s) 
159
		{ 
160
			partIdx=0; m_bodyId=0; cockpitIdx=0; bodyFlags=0; parentIdx=null_value; bob=0; 
161
			m_settings=s;
162
		}
163
 
164
		~bob_dom_path() { delete m_bodyId; delete bob; }
165
 
166
		const char * bodyId() const { return m_bodyId; }
167
		void bodyId(const char *str) { strcreate(m_bodyId, str); }
168
 
169
		bob_dom_notes& notes() { return m_notes; }
170
 
171
		bool toFile(bob_dom_obinaryfilestream& os, int cutVersion);
172
		bool toFile(bob_dom_otextfilestream& os, int idx);
173
 
174
		bool load(bob_dom_ibinaryfilestream& is, int version);
175
 
176
		//bool formatStats();
177
 
178
		child_type* createChild() 
179
		{ 
180
			child_type *ch; 
181
#ifdef X2BC_USE_INI_FORMATS
182
			ch=new bob_dom_stat(m_settings);
183
#else
184
			ch=new bob_dom_frame();
185
#endif
186
			children.push_back(ch); return ch; 
187
		}
188
};
189
 
190
class bob_dom_cut : public bob_dom_section, public bob_dom_cantainer<bob_dom_path>
191
{
192
	private:
193
		int m_storedPathCount;
194
		const Settings *m_settings;
195
 
196
	public:
197
		static const int hdr_begin=BOB_SECTION_NAME_CUT_BEGIN;
198
		static const int hdr_end=BOB_SECTION_NAME_CUT_END;
199
 
200
		static const int supported_version = 6;
201
 
202
		int version;
203
		bob_dom_info info;
204
 
205
		bob_dom_cut(const Settings *s) { m_settings=s; version=0; m_storedPathCount=0; }
206
 
207
		bool toFile(bob_dom_obinaryfilestream& os);
208
		bool toFile(bob_dom_otextfilestream& os);
209
 
210
		value_type_ptr createChild() { return *(children.push_back(new bob_dom_path(m_settings))); }
211
 
212
 
213
		bool load(bob_dom_ibinaryfilestream& is);
214
 
215
		bool convert(bob_dom_ibinaryfilestream& is, bob_dom_otextfilestream& os);
216
 
217
		//bool formatStats();
218
};
219
 
220
 
221
template <class Ty>
222
inline
223
Ty& operator << (Ty& os, bob_dom_info& info)
224
{
225
	info.toFile(os);
226
	return os;
227
}
228
 
229
template <class Ty>
230
inline
231
Ty& operator << (Ty& os, bob_dom_name& right)
232
{
233
	right.toFile(os);
234
	return os;
235
}
236
 
237
template <class Ty>
238
inline
239
Ty& operator << (Ty& os, bob_dom_path& right)
240
{
241
	right.toFile(os);
242
	return os;
243
}
244
 
245
#ifdef X2BC_USE_INI_FORMATS
246
template <class Ty>
247
inline
248
Ty& operator << (Ty& os, bob_dom_stat& right)
249
{
250
	right.toFile(os);
251
	return os;
252
}
253
#endif
254
 
255
#endif // !defined(BOB_DOM_CUT_INCLUDED)