Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
TileRing.cpp
Go to the documentation of this file.
1// Copyright (c) 2011 NVIDIA Corporation. All rights reserved.
2//
3// TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED
4// *AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS
5// OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT,IMPLIED WARRANTIES OF
6// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA
7// OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, SPECIAL, INCIDENTAL, INDIRECT, OR
8// CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS
9// OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY
10// OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
11// EVEN IF NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
12//
13// Please direct any bugs or questions to SDKFeedback@nvidia.com
14
15
16#include "Headers/TileRing.h"
17
20
21namespace Divide {
22
23TileRing::TileRing(const I32 holeWidth, const I32 outerWidth, const F32 tileSize) noexcept :
24 _tileCount(outerWidth*outerWidth - holeWidth*holeWidth),
25 _tileSize(tileSize),
26 _holeWidth(holeWidth), // No remainder - see assert below.
27 _outerWidth(outerWidth),
28 _ringWidth((outerWidth - holeWidth) / 2)
29{
30 assert((outerWidth - holeWidth) % 2 == 0);
31}
32
33bool TileRing::InRing(const I32 x, const I32 y) const noexcept
34{
35 assert(x >= 0 && x < _outerWidth);
36 assert(y >= 0 && y < _outerWidth);
37 return x < _ringWidth || y < _ringWidth || x >= _outerWidth - _ringWidth || y >= _outerWidth - _ringWidth;
38}
39
40void TileRing::AssignNeighbourSizes(const I32 x, const I32 y, Adjacency* pAdj) const noexcept
41{
42 pAdj->neighbourPlusX = 1.0f;
43 pAdj->neighbourPlusY = 1.0f;
44 pAdj->neighbourMinusX = 1.0f;
45 pAdj->neighbourMinusY = 1.0f;
46
47 // TBD: these aren't necessarily 2x different. Depends on the relative tiles sizes supplied to ring ctors.
48 constexpr F32 innerNeighbourSize = 0.5f;
49 constexpr F32 outerNeighbourSize = 2.0f;
50
51 // Inner edges abut tiles that are smaller. (But not on the inner-most.)
52 if (_holeWidth > 0)
53 {
54 if (y >= _ringWidth && y < _outerWidth-_ringWidth)
55 {
56 if (x == _ringWidth-1)
57 {
58 pAdj->neighbourPlusX = innerNeighbourSize;
59 }
60 if (x == _outerWidth - _ringWidth)
61 {
62 pAdj->neighbourMinusX = innerNeighbourSize;
63 }
64 }
65 if (x >= _ringWidth && x < _outerWidth - _ringWidth)
66 {
67 if (y == _ringWidth-1)
68 {
69 pAdj->neighbourPlusY = innerNeighbourSize;
70 }
71 if (y == _outerWidth - _ringWidth)
72 {
73 pAdj->neighbourMinusY = innerNeighbourSize;
74 }
75 }
76 }
77
78 // Outer edges abut tiles that are larger. We could skip this on the outer-most ring. But it will
79 // make almost zero visual or perf difference.
80 if (x == 0)
81 {
82 pAdj->neighbourMinusX = outerNeighbourSize;
83 }
84 if (y == 0)
85 {
86 pAdj->neighbourMinusY = outerNeighbourSize;
87 }
88 if (x == _outerWidth - 1)
89 {
90 pAdj->neighbourPlusX = outerNeighbourSize;
91 }
92 if (y == _outerWidth - 1)
93 {
94 pAdj->neighbourPlusY = outerNeighbourSize;
95 }
96}
97
99{
100 vector<InstanceData> ret(tileCount());
101
102 I32 index = 0;
103 const F32 halfWidth = 0.5f * to_F32(_outerWidth);
104 for (I32 y = 0; y < _outerWidth; ++y)
105 {
106 for (I32 x = 0; x < _outerWidth; ++x)
107 {
108 if (InRing(x,y))
109 {
110 ret[index].data.positionX = tileSize() * (to_F32(x) - halfWidth);
111 ret[index].data.positionZ = tileSize() * (to_F32(y) - halfWidth);
112 ret[index].data.tileScale = tileSize();
113 ret[index].data.ringID = to_F32(ringID);
114 AssignNeighbourSizes(x, y, &ret[index].adjacency);
115 index++;
116 }
117 }
118 }
119 assert(index == tileCount());
120 return ret;
121}
122
123} //namespace Divide
TileRing(I32 holeWidth, I32 outerWidth, F32 tileSize) noexcept
Definition: TileRing.cpp:23
void AssignNeighbourSizes(I32 x, I32 y, Adjacency *) const noexcept
Definition: TileRing.cpp:40
const I32 _outerWidth
Definition: TileRing.h:118
vector< InstanceData > createInstanceDataVB(I32 ringID)
Definition: TileRing.cpp:98
bool InRing(I32 x, I32 y) const noexcept
Definition: TileRing.cpp:33
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
int32_t I32
constexpr F32 to_F32(const T value)
eastl::vector< Type > vector
Definition: Vector.h:42