1 #include "xr_scene_wallmarks.h"
2 #include "xr_reader.h"
3 #include "xr_writer.h"
4 #include "xr_utils.h"
5
6 using namespace xray_re;
7
xr_scene_wallmarks(xr_scene & scene)8 xr_scene_wallmarks::xr_scene_wallmarks(xr_scene& scene):
9 xr_scene_part(scene, "wallmark.part", SCENE_CHUNK_WALLMARKS),
10 m_flags(WM_FLAG_DRAW_WALLMARKS),
11 m_width(1.f),
12 m_height(1.f),
13 m_rotate(0),
14 m_shader("effects\\wallmarkblend") {}
15
~xr_scene_wallmarks()16 xr_scene_wallmarks::~xr_scene_wallmarks()
17 {
18 delete_elements(m_slots);
19 }
20
operator ()read_wallmark21 struct read_wallmark { void operator()(wm_object& wm, xr_reader& r) const {
22 wm.selected = r.r_bool();
23 r.r_fvector3(wm.bbox.min);
24 r.r_fvector3(wm.bbox.max);
25 r.r_fvector3(wm.bsphere.p);
26 wm.bsphere.r = r.r_float();
27 wm.width = r.r_float();
28 wm.height = r.r_float();
29 wm.rotate = r.r_float();
30 r.r_seq(r.r_u32(), wm.vertices);
31 }};
32
operator ()read_slot_133 struct read_slot_1 { void operator()(wm_slot_le*& _slot, xr_reader& r) const {
34 wm_slot_le* slot = new wm_slot_le;
35 _slot = slot;
36 size_t n = r.r_u32();
37 r.r_sz(slot->shader);
38 r.r_sz(slot->texture);
39 r.r_seq(n, slot->wallmarks, read_wallmark());
40 }};
41
operator ()read_slot_042 struct read_slot_0 { void operator()(wm_slot_le*& slot, xr_reader& r) const {
43 xr_not_implemented();
44 }};
45
load(xr_reader & r)46 void xr_scene_wallmarks::load(xr_reader& r)
47 {
48 revision().load(r);
49
50 uint16_t version;
51 if (!r.r_chunk<uint16_t>(WM_CHUNK_VERSION, version))
52 xr_not_expected();
53 xr_assert(version == WALLMARK_VERSION);
54
55 if (!r.find_chunk(WM_CHUNK_PARAMS))
56 xr_not_expected();
57 m_width = r.r_float();
58 m_height = r.r_float();
59 m_rotate = r.r_float();
60 r.r_sz(m_shader);
61 r.r_sz(m_texture);
62 r.debug_find_chunk();
63
64 xr_reader* s;
65 if ((s = r.open_chunk(WM_CHUNK_WALLMARKS_1))) {
66 s->r_chunks(m_slots, read_slot_1());
67 r.close_chunk(s);
68 } else if ((s = r.open_chunk(WM_CHUNK_WALLMARKS_0))) {
69 s->r_chunks(m_slots, read_slot_0());
70 r.close_chunk(s);
71 }
72 }
73
operator ()write_wallmark74 struct write_wallmark { void operator()(const wm_object& wm, xr_writer& w) const {
75 w.w_bool(wm.selected);
76 w.w_fvector3(wm.bbox.min);
77 w.w_fvector3(wm.bbox.max);
78 w.w_fvector3(wm.bsphere.p);
79 w.w_float(wm.bsphere.r);
80 w.w_float(wm.width);
81 w.w_float(wm.height);
82 w.w_float(wm.rotate);
83 w.w_size_u32(wm.vertices.size());
84 w.w_seq(wm.vertices);
85 }};
86
operator ()write_slot87 struct write_slot { void operator()(const wm_slot_le* slot, xr_writer& w) const {
88 w.w_size_u32(slot->wallmarks.size());
89 w.w_sz(slot->shader);
90 w.w_sz(slot->texture);
91 w.w_seq(slot->wallmarks, write_wallmark());
92 }};
93
save(xr_writer & w) const94 void xr_scene_wallmarks::save(xr_writer& w) const
95 {
96 revision().save(w);
97
98 w.w_chunk<uint16_t>(WM_CHUNK_VERSION, WALLMARK_VERSION);
99 w.w_chunk<uint32_t>(WM_CHUNK_FLAGS, m_flags);
100
101 w.open_chunk(WM_CHUNK_PARAMS);
102 w.w_float(m_width);
103 w.w_float(m_height);
104 w.w_float(m_rotate);
105 w.w_sz(m_shader);
106 w.w_sz(m_texture);
107 w.close_chunk();
108
109 w.open_chunk(WM_CHUNK_WALLMARKS_1);
110 w.w_chunks(m_slots, write_slot());
111 w.close_chunk();
112 }
113
save_v12(xr_ini_writer * w) const114 void xr_scene_wallmarks::save_v12(xr_ini_writer* w) const
115 {
116 }
117