1 #include "xr_level_ps_static.h"
2 #include "xr_file_system.h"
3 #include "xr_utils.h"
4
5 using namespace xray_re;
6
~xr_level_ps_static()7 xr_level_ps_static::~xr_level_ps_static()
8 {
9 delete_elements(m_particles);
10 }
11
load(xr_reader & r)12 void xr_level_ps_static::load(xr_reader& r)
13 {
14 if (r.find_chunk(PS_CHUNK_VERSION) == sizeof(uint32_t)) {
15 m_version = r.r_u32();
16 xr_assert(m_version == PS_VERSION_1);
17 } else {
18 m_version = PS_VERSION_0;
19 }
20 // compiler will optimize this, so no explicit (id = version) trick.
21 uint32_t id = (m_version == PS_VERSION_0) ? 0 : 1;
22 for (xr_reader* s; (s = r.open_chunk(id)); ++id) {
23 particle_data* particle = new particle_data;
24 m_particles.push_back(particle);
25 particle->extra = (m_version == PS_VERSION_0) ? 0xffff : r.r_u16();
26 r.r_sz(particle->reference);
27 r.r(particle->xform);
28 r.close_chunk(s);
29 }
30 }
31
save(xr_writer & w) const32 void xr_level_ps_static::save(xr_writer& w) const
33 {
34 uint32_t id;
35 if (m_version == PS_VERSION_0) {
36 id = 0;
37 } else {
38 id = 1;
39 w.w_chunk(PS_CHUNK_VERSION, m_version);
40 }
41 for (particle_data_vec_cit it = m_particles.begin(), end = m_particles.end();
42 it != end; ++it, ++id) {
43 const particle_data* particle = *it;
44 w.open_chunk(id);
45 if (m_version != PS_VERSION_0)
46 w.w_u16(particle->extra);
47 w.w_sz(particle->reference);
48 w.w(particle->xform);
49 w.close_chunk();
50 }
51 }
52
load(const char * path,const char * name)53 bool xr_level_ps_static::load(const char* path, const char* name)
54 {
55 xr_file_system& fs = xr_file_system::instance();
56 xr_reader* r = fs.r_open(path, name);
57 if (r == 0)
58 return false;
59 load(*r);
60 fs.r_close(r);
61 return true;
62 }
63
save(const char * path,const char * name)64 bool xr_level_ps_static::save(const char* path, const char* name)
65 {
66 xr_file_system& fs = xr_file_system::instance();
67 xr_writer* w = fs.w_open(path, name);
68 if (w == 0)
69 return false;
70 save(*w);
71 fs.w_close(w);
72 return true;
73 }
74