Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 180 lines (161 sloc) 4.129 kb
ccc5fee0 »
2010-11-15 Added a fast integer vector class, and integrated it.
1 /*
8a472bf3 »
2011-01-16 tiny changes..
2 Copyright (c) 2011, The Mineserver Project
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
3 All rights reserved.
ccc5fee0 »
2010-11-15 Added a fast integer vector class, and integrated it.
4
080bd08b »
2011-01-10 fixed formatting of license, it was annoying me to no end
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of the The Mineserver Project nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
ccc5fee0 »
2010-11-15 Added a fast integer vector class, and integrated it.
15
080bd08b »
2011-01-10 fixed formatting of license, it was annoying me to no end
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
26 */
ccc5fee0 »
2010-11-15 Added a fast integer vector class, and integrated it.
27
28 #ifndef _VEC_H
29 #define _VEC_H
30
31 #if defined(__clang__) || defined(__gcc__)
32 #define VEC_VECTORISED
33 #endif
34
35 class vec
36 {
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
37 private:
ccc5fee0 »
2010-11-15 Added a fast integer vector class, and integrated it.
38 #ifdef VEC_VECTORISED
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
39 typedef int ivec __attribute__((vector_size(16)));
40 union
41 {
42 int arrayValue[4];
43 ivec vectorValue;
44 } data;
45 vec(ivec vector)
46 {
47 data.vectorValue = vector;
48 }
ccc5fee0 »
2010-11-15 Added a fast integer vector class, and integrated it.
49 #else
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
50 union
51 {
52 int arrayValue[3];
53 } data;
ccc5fee0 »
2010-11-15 Added a fast integer vector class, and integrated it.
54 #endif
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
55 public:
56 vec(int x, int y, int z)
57 {
58 data.arrayValue[0] = x;
59 data.arrayValue[1] = y;
60 data.arrayValue[2] = z;
61 }
62 vec(const int values[3])
63 {
64 data.arrayValue[0] = values[0];
65 data.arrayValue[1] = values[1];
66 data.arrayValue[2] = values[2];
67 }
68 vec()
69 {
70 data.arrayValue[0] = 0;
71 data.arrayValue[1] = 0;
72 data.arrayValue[2] = 0;
73 }
5d47fd57 »
2011-03-01 Testing AStyle
74 vec(const vec& ov)
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
75 {
ccc5fee0 »
2010-11-15 Added a fast integer vector class, and integrated it.
76 #ifdef VEC_VECTORISED
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
77 data.vectorValue = ov.data.vectorValue;
ccc5fee0 »
2010-11-15 Added a fast integer vector class, and integrated it.
78 #else
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
79 data.arrayValue[0] = ov.data.arrayValue[0];
80 data.arrayValue[1] = ov.data.arrayValue[1];
81 data.arrayValue[2] = ov.data.arrayValue[2];
ccc5fee0 »
2010-11-15 Added a fast integer vector class, and integrated it.
82 #endif
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
83 }
ccc5fee0 »
2010-11-15 Added a fast integer vector class, and integrated it.
84
5d47fd57 »
2011-03-01 Testing AStyle
85 vec& operator=(const vec& ov)
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
86 {
ccc5fee0 »
2010-11-15 Added a fast integer vector class, and integrated it.
87 #ifdef VEC_VECTORISED
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
88 data.vectorValue = ov.data.vectorValue;
ccc5fee0 »
2010-11-15 Added a fast integer vector class, and integrated it.
89 #else
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
90 data.arrayValue[0] = ov.data.arrayValue[0];
91 data.arrayValue[1] = ov.data.arrayValue[1];
92 data.arrayValue[2] = ov.data.arrayValue[2];
ccc5fee0 »
2010-11-15 Added a fast integer vector class, and integrated it.
93 #endif
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
94 return *this;
95 }
96
5d47fd57 »
2011-03-01 Testing AStyle
97 int& x()
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
98 {
99 return data.arrayValue[0];
100 }
5d47fd57 »
2011-03-01 Testing AStyle
101 int& y()
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
102 {
103 return data.arrayValue[1];
104 }
5d47fd57 »
2011-03-01 Testing AStyle
105 int& z()
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
106 {
107 return data.arrayValue[2];
108 }
5d47fd57 »
2011-03-01 Testing AStyle
109 const int& x() const
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
110 {
111 return data.arrayValue[0];
112 }
5d47fd57 »
2011-03-01 Testing AStyle
113 const int& y() const
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
114 {
115 return data.arrayValue[1];
116 }
5d47fd57 »
2011-03-01 Testing AStyle
117 const int& z() const
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
118 {
119 return data.arrayValue[2];
120 }
121
5d47fd57 »
2011-03-01 Testing AStyle
122 vec operator+(const vec& ov) const
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
123 {
ccc5fee0 »
2010-11-15 Added a fast integer vector class, and integrated it.
124 #ifdef VEC_VECTORISED
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
125 return vec(data.vectorValue + ov.data.vectorValue);
126
ccc5fee0 »
2010-11-15 Added a fast integer vector class, and integrated it.
127 #else
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
128 return vec(x() + ov.x(),
129 y() + ov.y(),
130 z() + ov.z());
131
ccc5fee0 »
2010-11-15 Added a fast integer vector class, and integrated it.
132 #endif
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
133 }
5d47fd57 »
2011-03-01 Testing AStyle
134 vec operator-(const vec& ov) const
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
135 {
ccc5fee0 »
2010-11-15 Added a fast integer vector class, and integrated it.
136 #ifdef VEC_VECTORISED
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
137 return vec(data.vectorValue - ov.data.vectorValue);
138
ccc5fee0 »
2010-11-15 Added a fast integer vector class, and integrated it.
139 #else
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
140 return vec(x() - ov.x(),
141 y() - ov.y(),
142 z() - ov.z());
143
ccc5fee0 »
2010-11-15 Added a fast integer vector class, and integrated it.
144 #endif
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
145 }
146 vec operator-() const
147 {
ccc5fee0 »
2010-11-15 Added a fast integer vector class, and integrated it.
148 #ifdef VEC_VECTORISED
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
149 return vec(-data.vectorValue);
150
ccc5fee0 »
2010-11-15 Added a fast integer vector class, and integrated it.
151 #else
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
152 return vec(-x(),
153 -y(),
154 -z());
155
ccc5fee0 »
2010-11-15 Added a fast integer vector class, and integrated it.
156 #endif
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
157 }
158
5d47fd57 »
2011-03-01 Testing AStyle
159 vec& operator+=(const vec& ov)
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
160 {
161 return *this = *this + ov;
162 }
5d47fd57 »
2011-03-01 Testing AStyle
163 vec& operator-=(const vec& ov)
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
164 {
165 return *this = *this - ov;
166 }
167
168 int squareLength() const
169 {
5d47fd57 »
2011-03-01 Testing AStyle
170 return x() * x() + y() * y() + z() * z();
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
171 }
172
5d47fd57 »
2011-03-01 Testing AStyle
173 static int squareDistance(const vec& x, const vec& y)
de8e38c9 »
2010-11-16 Heavily cleaned up the source formatting.
174 {
175 return (x - y).squareLength();
176 }
ccc5fee0 »
2010-11-15 Added a fast integer vector class, and integrated it.
177 };
178
179 #endif
Something went wrong with that request. Please try again.