1 #ifndef __GNUC__
2 #pragma once
3 #endif
4 #ifndef __XR_SCENE_LIGHTS_H__
5 #define __XR_SCENE_LIGHTS_H__
6
7 #include "xr_scene_objects.h"
8 #include "xr_vector2.h"
9 #include "xr_vector4.h"
10 #include "xr_color.h"
11
12 namespace xray_re {
13
14 struct xr_token {
15 xr_token();
16 explicit xr_token(const char* _name, uint32_t _id);
17
18 std::string name;
19 uint32_t id;
20 };
21 TYPEDEF_STD_VECTOR(xr_token)
22
23 // CLight
24 const uint16_t LIGHT_VERSION_16 = 0x10;
25 const uint16_t LIGHT_VERSION = 0x11;
26
27 // CLight flags
28 enum {
29 LIGHT_FLAG_LIGHTMAP = 0x01,
30 LIGHT_FLAG_DYNAMIC = 0x02,
31 LIGHT_FLAG_ANIMATED = 0x04,
32 LIGHT_FLAG_FUZZY = 0x10,
33 };
34
35 enum {
36 LIGHT_CHUNK_VERSION = 0xb411,
37 LIGHT_CHUNK_FLAGS = 0xb413,
38 LIGHT_CHUNK_BRIGHTNESS = 0xb425,
39 LIGHT_CHUNK_D3D_PARAMS = 0xb435,
40 LIGHT_CHUNK_USE_IN_D3D = 0xb436,
41 LIGHT_CHUNK_ROTATION = 0xb437,
42 LIGHT_CHUNK_ANIMATION = 0xb438,
43 LIGHT_CHUNK_TEXTURE = 0xb439,
44 LIGHT_CHUNK_FUZZY_DATA = 0xb440,
45 LIGHT_CHUNK_CONTROL = 0xb441,
46 LIGHT_CHUNK_PARAMS = 0xb442,
47 };
48
49 class xr_light_object: public xr_custom_object {
50 public:
51 xr_light_object(xr_scene& scene);
52 virtual ~xr_light_object();
53 virtual void load(xr_reader& r);
54 virtual void save(xr_writer& w) const;
55
56 virtual void save_v12(xr_ini_writer* w) const;
57
58 uint32_t& type();
59 fcolor& color();
60 float& brightness();
61 float& range();
62 float& attenuation_constant();
63 float& attenuation_linear();
64 float& attenuation_quadratic();
65 float& cone_angle();
66 float& unknown();
67
68 uint32_t& use_in_d3d();
69 uint32_t& flags();
70 uint32_t& control();
71
72 enum {
73 FUZZY_SPHERE = 0,
74 FUZZY_BOX = 1,
75 };
76 struct fuzzy_shape {
77 uint8_t type;
78 fvector4 fixme;
79 };
80
81 private:
82 uint32_t m_type; // LIGHT_CHUNK_PARAMS or LIGHT_CHUNK_D3D_PARAMS+LIGHT_CHUNK_BRIGHTNESS
83 fcolor m_color;
84 float m_brightness;
85 float m_range;
86 float m_attenuation_constant;
87 float m_attenuation_linear;
88 float m_attenuation_quadratic;
89 float m_cone_angle;
90 float m_unknown;
91
92 uint32_t m_use_in_d3d; // LIGHT_CHUNK_USE_IN_D3D
93 uint32_t m_flags; // LIGHT_CHUNK_FLAGS
94 uint32_t m_control; // LIGHT_CHUNK_CONTROL
95 std::string m_animation; // LIGHT_CHUNK_ANIMATION
96 std::string m_texture; // LIGHT_CHUNK_TEXTURE
97
98 fuzzy_shape m_shape; // LIGHT_CHUNK_FUZZY_DATA
99 std::vector<fvector3> m_vertices;
100 };
101
type()102 inline uint32_t& xr_light_object::type() { return m_type; }
color()103 inline fcolor& xr_light_object::color() { return m_color; }
brightness()104 inline float& xr_light_object::brightness() { return m_brightness; }
range()105 inline float& xr_light_object::range() { return m_range; }
attenuation_constant()106 inline float& xr_light_object::attenuation_constant() { return m_attenuation_constant; }
attenuation_linear()107 inline float& xr_light_object::attenuation_linear() { return m_attenuation_linear; }
attenuation_quadratic()108 inline float& xr_light_object::attenuation_quadratic() { return m_attenuation_quadratic; }
cone_angle()109 inline float& xr_light_object::cone_angle() { return m_cone_angle; }
unknown()110 inline float& xr_light_object::unknown() { return m_unknown; }
111
use_in_d3d()112 inline uint32_t& xr_light_object::use_in_d3d() { return m_use_in_d3d; }
flags()113 inline uint32_t& xr_light_object::flags() { return m_flags; }
control()114 inline uint32_t& xr_light_object::control() { return m_control; }
115
116
117 // ESceneLightTools
118 enum {
119 LIGHTS_FLAG_DRAW_NAME = 0x40,
120 };
121
122 enum {
123 LIGHTS_CHUNK_COMMON_CONTROLS = 0x1002,
124 LIGHTS_CHUNK_COMMON_COUNT = 0x1003,
125 LIGHTS_CHUNK_COMMON_FLAGS = 0x1004,
126 LIGHTS_CHUNK_COMMON_SUN = 0x1006,
127 };
128
129 class xr_scene_lights: public xr_scene_objects {
130 public:
131 xr_scene_lights(xr_scene& scene);
132 virtual ~xr_scene_lights();
133 virtual void load(xr_reader& r);
134 virtual void save(xr_writer& w) const;
135
136 virtual void save_v12(xr_ini_writer* w) const;
137
138 uint32_t& flags();
139 xr_token_vec& controls();
140 fvector2& sun();
141
142 private:
143 uint32_t m_flags; // LIGHTS_CHUNK_COMMON_FLAGS
144 xr_token_vec m_controls; // LIGHTS_CHUNK_COMMON_COUNT + LIGHTS_CHUNK_COMMON_CONTROLS
145 fvector2 m_sun; // LIGHTS_CHUNK_COMMON_SUN (altitude then longitude)
146 };
147
flags()148 inline uint32_t& xr_scene_lights::flags() { return m_flags; }
controls()149 inline xr_token_vec& xr_scene_lights::controls() { return m_controls; }
sun()150 inline fvector2& xr_scene_lights::sun() { return m_sun; }
151
152 } // end of namespace xray_re
153
154 #endif
155