Skip to content

Commit cfb118a

Browse files
author
nitrocaster
committed
Delete DetailFormat.h duplicates, update refs.
1 parent 17425d2 commit cfb118a

12 files changed

+235
-652
lines changed

src/Layers/xrRender/DetailFormat.h

Lines changed: 214 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,252 @@
11
#pragma once
22

3-
#ifndef _DETAIL_FORMAT_H_
4-
#define _DETAIL_FORMAT_H_
53
#pragma pack(push,1)
64

7-
#define DETAIL_VERSION 3
8-
#define DETAIL_SLOT_SIZE 2.f
9-
#define DETAIL_SLOT_SIZE_2 DETAIL_SLOT_SIZE*0.5f
5+
#define DETAIL_VERSION 3
6+
#define DETAIL_SLOT_SIZE 2.f
7+
#define DETAIL_SLOT_SIZE_2 DETAIL_SLOT_SIZE*0.5f
108

11-
// int s_x = iFloor (EYE.x/slot_size+.5f)+offs_x; // [0...size_x)
12-
// int s_z = iFloor (EYE.z/slot_size+.5f)+offs_z; // [0...size_z)
13-
9+
// int s_x = iFloor(EYE.x/slot_size+.5f)+offs_x; // [0...size_x)
10+
// int s_z = iFloor(EYE.z/slot_size+.5f)+offs_z; // [0...size_z)
1411

1512
/*
1613
0 - Header(version,obj_count(max255),size_x,size_z,min_x,min_z)
1714
1 - Objects
18-
0
19-
1
20-
2
21-
..
22-
obj_count-1
15+
0
16+
1
17+
2
18+
..
19+
obj_count-1
2320
2 - slots
2421
25-
CMemoryWriter F;
22+
CMemoryWriter F;
2623
m_Header.object_count=m_Objects.size();
27-
// header
28-
F.w_chunk (DETMGR_CHUNK_HEADER,&m_Header,sizeof(DetailHeader));
24+
// header
25+
F.w_chunk (DETMGR_CHUNK_HEADER,&m_Header,sizeof(DetailHeader));
2926
// objects
30-
F.open_chunk (DETMGR_CHUNK_OBJECTS);
27+
F.open_chunk (DETMGR_CHUNK_OBJECTS);
3128
for (DOIt it=m_Objects.begin(); it!=m_Objects.end(); it++){
32-
F.open_chunk (it-m_Objects.begin());
33-
(*it)->Export (F);
34-
F.close_chunk ();
29+
F.open_chunk (it-m_Objects.begin());
30+
(*it)->Export (F);
31+
F.close_chunk ();
3532
}
36-
F.close_chunk ();
33+
F.close_chunk ();
3734
// slots
38-
F.open_chunk (DETMGR_CHUNK_SLOTS);
39-
F.write (m_Slots.begin(),m_Slots.size()*sizeof(DetailSlot));
40-
F.close_chunk ();
35+
F.open_chunk (DETMGR_CHUNK_SLOTS);
36+
F.write (m_Slots.begin(),m_Slots.size()*sizeof(DetailSlot));
37+
F.close_chunk ();
4138
42-
F.SaveTo (fn,0);
39+
F.SaveTo (fn,0);
4340
*/
4441
/*
4542
// detail object
46-
char* shader;
47-
char* texture;
43+
char* shader;
44+
char* texture;
4845
49-
u32 flag;
50-
float min_scale;
51-
float max_scale;
46+
u32 flag;
47+
float min_scale;
48+
float max_scale;
5249
53-
u32 vert_count;
54-
u32 index_count;
50+
u32 vert_count;
51+
u32 index_count;
5552
56-
fvfVertexIn* vertices;
57-
u16* indices;
53+
fvfVertexIn* vertices;
54+
u16* indices;
5855
*/
5956

60-
#define DO_NO_WAVING 0x0001
57+
#define DO_NO_WAVING 0x0001
6158

62-
struct DetailHeader
59+
class DetailHeader
6360
{
64-
u32 version;
65-
u32 object_count;
66-
int offs_x, offs_z;
67-
u32 size_x, size_z;
61+
private:
62+
u32 _version;
63+
u32 obj_count;
64+
int offs_x, offs_z;
65+
u32 size_x, size_z;
66+
67+
public:
68+
DetailHeader()
69+
{
70+
_version = u32(-1);
71+
obj_count = u32(-1);
72+
offs_x = offs_z = u32(-1);
73+
size_x = size_z = u32(-1);
74+
}
75+
76+
IC u32 version() const
77+
{ return _version; }
78+
79+
IC float fromSlotX(int x) const
80+
{ return (x-offs_x)*DETAIL_SLOT_SIZE+DETAIL_SLOT_SIZE_2; }
81+
82+
IC float fromSlotZ(int z) const
83+
{ return (z-offs_z)*DETAIL_SLOT_SIZE+DETAIL_SLOT_SIZE_2; }
84+
85+
IC void GetSlotRect(Frect& rect, int sx, int sz) const
86+
{
87+
float x = fromSlotX(sx);
88+
float z = fromSlotZ(sz);
89+
rect.x1 = x-DETAIL_SLOT_SIZE_2+EPS_L;
90+
rect.y1 = z-DETAIL_SLOT_SIZE_2+EPS_L;
91+
rect.x2 = x+DETAIL_SLOT_SIZE_2-EPS_L;
92+
rect.y2 = z+DETAIL_SLOT_SIZE_2-EPS_L;
93+
}
94+
95+
IC u32 object_count() const { return obj_count; }
96+
97+
IC u32 x_size() const { return size_x; }
98+
99+
IC u32 z_size() const { return size_z; }
100+
101+
IC u32 x_offs() const { return offs_x; }
102+
103+
IC u32 z_offs() const { return offs_z; }
104+
105+
IC u32 slot_index(int _x, int _z) const
106+
{
107+
u32 ret = _z*size_x+_x;
108+
int xx, zz;
109+
slot_x_z(ret, xx, zz);
110+
R_ASSERT(zz==_z);
111+
R_ASSERT(xx==_x);
112+
return ret;
113+
}
114+
115+
IC void slot_x_z(u32 idx, int &_x, int &_z) const
116+
{
117+
VERIFY(idx<slot_count());
118+
_z = idx/size_x;
119+
_x = idx%size_x;
120+
VERIFY(u32(_z) < z_size());
121+
VERIFY(u32(_x) < x_size());
122+
}
123+
124+
IC u32 slot_count() const
125+
{ return size_x*size_z; }
126+
127+
IC float slot_min_x(int _x) const
128+
{ return (int(_x)-int(offs_x))*DETAIL_SLOT_SIZE; }
129+
130+
IC float slot_min_z(int _z) const
131+
{ return (int(_z)-int(offs_z))*DETAIL_SLOT_SIZE; }
68132
};
133+
69134
struct DetailPalette
70135
{
71-
u16 a0:4;
72-
u16 a1:4;
73-
u16 a2:4;
74-
u16 a3:4;
136+
u16 a0 : 4;
137+
u16 a1 : 4;
138+
u16 a2 : 4;
139+
u16 a3 : 4;
75140
};
76-
struct DetailSlot // was(4+4+3*4+2 = 22b), now(8+2*4=16b)
141+
struct DetailSlot // was(4+4+3*4+2 = 22b), now(8+2*4=16b)
77142
{
78-
u32 y_base : 12; // 11 // 1 unit = 20 cm, low = -200m, high = 4096*20cm - 200 = 619.2m
79-
u32 y_height: 8; // 20 // 1 unit = 10 cm, low = 0, high = 256*10 ~= 25.6m
80-
u32 id0 : 6; // 26 // 0x3F(63) = empty
81-
u32 id1 : 6; // 32 // 0x3F(63) = empty
82-
u32 id2 : 6; // 38 // 0x3F(63) = empty
83-
u32 id3 : 6; // 42 // 0x3F(63) = empty
84-
u32 c_dir : 4; // 48 // 0..1 q
85-
u32 c_hemi : 4; // 52 // 0..1 q
86-
u32 c_r : 4; // 56 // rgb = 4.4.4
87-
u32 c_g : 4; // 60 // rgb = 4.4.4
88-
u32 c_b : 4; // 64 // rgb = 4.4.4
89-
DetailPalette palette [4];
90-
public:
91-
enum { ID_Empty = 0x3f };
92-
public:
93-
void w_y (float base, float height)
94-
{
95-
s32 _base = iFloor((base + 200)/.2f); clamp(_base, 0,4095); y_base = _base;
96-
f32 _error = base - r_ybase();
97-
s32 _height = iCeil ((height+_error) / .1f); clamp(_height, 0,255); y_height = _height;
98-
}
99-
100-
float r_ybase () { return float(y_base)*.2f - 200.f; }
101-
float r_yheight () { return float(y_height)*.1f; }
102-
u32 w_qclr (float v, u32 range) { s32 _v = iFloor(v * float(range)); clamp(_v,0,s32(range)); return _v; };
103-
float r_qclr (u32 v, u32 range) { return float(v)/float(range); }
104-
105-
// static void verify () { VERIFY(16==sizeof(DetailSlot)); }
106-
void color_editor(){c_dir=w_qclr(0.5f,15);c_hemi=w_qclr(0.5f,15);c_r=w_qclr(0.f,15);c_g=w_qclr(0.f,15);c_b=w_qclr(0.f,15);}
107-
u8 r_id (u32 idx) {
108-
switch(idx) {
109-
case 0: return (u8)id0;
110-
case 1: return (u8)id1;
111-
case 2: return (u8)id2;
112-
case 3: return (u8)id3;
113-
default: NODEFAULT;
114-
}
115-
#ifdef DEBUG
116-
return 0;
117-
#endif
143+
u32 y_base : 12; // 11 // 1 unit = 20 cm, low = -200m, high = 4096*20cm - 200 = 619.2m
144+
u32 y_height : 8; // 20 // 1 unit = 10 cm, low = 0, high = 256*10 ~= 25.6m
145+
u32 id0 : 6; // 26 // 0x3F(63) = empty
146+
u32 id1 : 6; // 32 // 0x3F(63) = empty
147+
u32 id2 : 6; // 38 // 0x3F(63) = empty
148+
u32 id3 : 6; // 42 // 0x3F(63) = empty
149+
u32 c_dir : 4; // 48 // 0..1 q
150+
u32 c_hemi : 4; // 52 // 0..1 q
151+
u32 c_r : 4; // 56 // rgb = 4.4.4
152+
u32 c_g : 4; // 60 // rgb = 4.4.4
153+
u32 c_b : 4; // 64 // rgb = 4.4.4
154+
DetailPalette palette[4];
155+
156+
public:
157+
enum {ID_Empty = 0x3f};
158+
159+
void w_y(float base, float height)
160+
{
161+
s32 _base = iFloor((base+200)/.2f);
162+
clamp(_base, 0, 4095);
163+
y_base = _base;
164+
f32 _error = base-r_ybase();
165+
s32 _height = iCeil((height+_error)/.1f);
166+
clamp( _height, 0, 255);
167+
y_height = _height;
168+
}
169+
170+
float r_ybase() const
171+
{ return float(y_base)*.2f - 200.f; }
172+
173+
float r_yheight() const
174+
{ return float(y_height)*.1f; }
175+
176+
u32 w_qclr(float v, u32 range) const
177+
{
178+
s32 _v = iFloor(v*float(range));
179+
clamp(_v, 0, s32(range));
180+
return _v;
181+
}
182+
183+
float r_qclr( u32 v, u32 range ) const
184+
{ return float(v)/float(range); }
185+
186+
void color_editor()
187+
{
188+
c_dir = w_qclr(0.5f, 15);
189+
c_hemi = w_qclr(0.5f, 15);
190+
c_r = w_qclr(0.f, 15);
191+
c_g = w_qclr(0.f, 15);
192+
c_b = w_qclr(0.f, 15);
118193
}
119-
void w_id (u32 idx, u8 val) {
120-
switch(idx){
121-
case 0: id0=val; break;
122-
case 1: id1=val; break;
123-
case 2: id2=val; break;
124-
case 3: id3=val; break;
125-
default: NODEFAULT;
194+
195+
u8 r_id(u32 idx)
196+
{
197+
switch (idx)
198+
{
199+
case 0: return (u8)id0;
200+
case 1: return (u8)id1;
201+
case 2: return (u8)id2;
202+
case 3: return (u8)id3;
203+
default: NODEFAULT;
204+
}
205+
#ifdef DEBUG
206+
return 0;
207+
#endif
208+
}
209+
210+
void w_id(u32 idx, u8 val)
211+
{
212+
switch (idx)
213+
{
214+
case 0: id0 = val; break;
215+
case 1: id1 = val; break;
216+
case 2: id2 = val; break;
217+
case 3: id3 = val; break;
218+
default: NODEFAULT;
126219
}
127220
}
128221
};
129222

223+
IC bool is_empty(const DetailPalette &pallete)
224+
{ return !pallete.a0 && !pallete.a1 && !pallete.a2 && !pallete.a3; }
225+
226+
IC bool is_empty(const DetailSlot &DS)
227+
{
228+
return DS.id0==DetailSlot::ID_Empty &&
229+
DS.id1==DetailSlot::ID_Empty &&
230+
DS.id2==DetailSlot::ID_Empty &&
231+
DS.id3==DetailSlot::ID_Empty;
232+
}
233+
234+
IC void process_pallete(DetailSlot &DS)
235+
{
236+
if (is_empty(DS.palette[0]))
237+
DS.id0 = DetailSlot::ID_Empty;
238+
if (is_empty(DS.palette[1]))
239+
DS.id1 = DetailSlot::ID_Empty;
240+
if (is_empty(DS.palette[2]))
241+
DS.id2 = DetailSlot::ID_Empty;
242+
if (is_empty(DS.palette[3]))
243+
DS.id3 = DetailSlot::ID_Empty;
244+
}
245+
246+
IC Fvector &get_slot_diameter(Fvector &diameter, const DetailSlot &DS)
247+
{
248+
diameter.set(DETAIL_SLOT_SIZE, DS.r_yheight(), DETAIL_SLOT_SIZE);
249+
return diameter;
250+
}
251+
130252
#pragma pack(pop)
131-
#endif // _DEBUG

src/Layers/xrRender/DetailManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ void CDetailManager::Load ()
121121

122122
// Header
123123
dtFS->r_chunk_safe (0,&dtH,sizeof(dtH));
124-
R_ASSERT (dtH.version == DETAIL_VERSION);
125-
u32 m_count = dtH.object_count;
124+
R_ASSERT (dtH.version() == DETAIL_VERSION);
125+
u32 m_count = dtH.object_count();
126126

127127
// Models
128128
IReader* m_fs = dtFS->open_chunk(1);

src/Layers/xrRender/DetailManager_CACHE.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,11 @@ void CDetailManager::cache_Update (int v_x, int v_z, Fvector& view, int limit)
198198

199199
DetailSlot& CDetailManager::QueryDB(int sx, int sz)
200200
{
201-
int db_x = sx+dtH.offs_x;
202-
int db_z = sz+dtH.offs_z;
203-
if ((db_x>=0) && (db_x<int(dtH.size_x)) && (db_z>=0) && (db_z<int(dtH.size_z)))
201+
int db_x = sx+dtH.x_offs();
202+
int db_z = sz+dtH.z_offs();
203+
if ((db_x>=0) && (db_x<int(dtH.x_size())) && (db_z>=0) && (db_z<int(dtH.z_size())))
204204
{
205-
u32 linear_id = db_z*dtH.size_x + db_x;
205+
u32 linear_id = db_z*dtH.x_size() + db_x;
206206
return dtSlots [linear_id];
207207
} else {
208208
// Empty slot

0 commit comments

Comments
 (0)