User
Frontpage
Release
Authors
Installation
Contents
Player
libstageplugin
Developer
libstage
Online
GitHub
Bugs/Issues
Player Project
Mailing Lists
libstage
region.hh
Go to the documentation of this file.
1
#pragma once
2
/*
3
region.hh
4
data structures supporting multi-resolution ray tracing in world class.
5
Copyright Richard Vaughan 2008
6
*/
7
8
#include "
stage.hh
"
9
10
namespace
Stg
11
{
12
13
// a bit of experimenting suggests that these values are fast. YMMV.
14
const
int32_t
RBITS
( 5 );
// regions contain (2^RBITS)^2 pixels
15
const
int32_t
SBITS
( 5 );
// superregions contain (2^SBITS)^2 regions
16
const
int32_t
SRBITS
(
RBITS
+
SBITS
);
17
18
const
int32_t
REGIONWIDTH
( 1<<
RBITS
);
19
const
int32_t
REGIONSIZE
(
REGIONWIDTH
*
REGIONWIDTH
);
20
21
const
int32_t
SUPERREGIONWIDTH
( 1<<
SBITS
);
22
const
int32_t
SUPERREGIONSIZE
(
SUPERREGIONWIDTH
*
SUPERREGIONWIDTH
);
23
24
const
int32_t
CELLMASK
( ~((~0x00)<<
RBITS
));
25
const
int32_t
REGIONMASK
( ~((~0x00)<<
SRBITS
));
26
27
inline
int32_t
GETCELL
(
const
int32_t x ) {
return
( x &
CELLMASK
); }
28
inline
int32_t
GETREG
(
const
int32_t x ) {
return
( ( x &
REGIONMASK
) >>
RBITS
); }
29
inline
int32_t
GETSREG
(
const
int32_t x ) {
return
( x >>
SRBITS
); }
30
31
// this is slightly faster than the inline method above, but not as safe
32
//#define GETREG(X) (( (static_cast<int32_t>(X)) & REGIONMASK ) >> RBITS)
33
34
class
Cell
35
{
36
friend
class
SuperRegion
;
37
friend
class
World
;
38
39
private
:
40
std::vector<Block*> blocks[2];
41
42
public
:
43
Cell
()
44
: blocks(),
45
region
(NULL)
46
{
/* nothing to do */
}
47
48
void
RemoveBlock
(
Block
* b,
unsigned
int
index );
49
void
AddBlock
(
Block
* b,
unsigned
int
index );
50
51
inline
const
std::vector<Block*>&
GetBlocks
(
unsigned
int
index )
52
{
return
blocks[index]; }
53
54
Region
*
region
;
55
};
// class Cell
56
57
class
Region
58
{
59
friend
class
SuperRegion
;
60
friend
class
World
;
// for raytracing
61
62
private
:
63
std::vector<Cell> cells;
64
unsigned
long
count;
// number of blocks rendered into this region
65
66
public
:
67
Region
();
68
~Region
();
69
70
inline
Cell
*
GetCell
( int32_t x, int32_t y )
71
{
72
if
( cells.size() == 0 )
73
{
74
assert(count == 0 );
75
76
cells.resize(
REGIONSIZE
);
77
78
for
( int32_t c=0; c<
REGIONSIZE
;++c)
79
cells[c].region =
this
;
80
}
81
82
return
( &cells[ x + y *
REGIONWIDTH
] );
83
}
84
85
inline
void
AddBlock
();
86
inline
void
RemoveBlock
();
87
88
SuperRegion
*
superregion
;
89
90
};
// class Region
91
92
class
SuperRegion
93
{
94
private
:
95
unsigned
long
count;
// number of blocks rendered into this superregion
96
point_int_t
origin;
97
Region
regions[
SUPERREGIONSIZE
];
98
World
* world;
99
100
public
:
101
SuperRegion
(
World
* world,
point_int_t
origin );
102
~SuperRegion
();
103
104
inline
Region
*
GetRegion
( int32_t x, int32_t y )
105
{
106
return
( ®ions[ x + y *
SUPERREGIONWIDTH
]);
107
}
108
109
void
DrawOccupancy
(
void
)
const
;
110
void
DrawVoxels
(
unsigned
int
layer)
const
;
111
112
inline
void
AddBlock
();
113
inline
void
RemoveBlock
();
114
115
const
point_int_t
&
GetOrigin
()
const
{
return
origin; }
116
};
// class SuperRegion;
117
118
119
};
// namespace Stg
Generated on Mon Feb 18 2013 11:39:28 for Stage by
1.8.3.1