]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - include/ipatch.h
load notex textures from a builtin vfs
[xonotic/netradiant.git] / include / ipatch.h
1 /*
2    Copyright (C) 2001-2006, William Joseph.
3    All Rights Reserved.
4
5    This file is part of GtkRadiant.
6
7    GtkRadiant is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    GtkRadiant is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with GtkRadiant; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21
22 #if !defined( INCLUDED_IPATCH_H )
23 #define INCLUDED_IPATCH_H
24
25 #include "globaldefs.h"
26 #include "debugging/debugging.h"
27 #include "generic/constant.h"
28 #include "generic/vector.h"
29
30 namespace scene
31 {
32 class Node;
33 }
34
35 template<typename Element>
36 class ArrayReference
37 {
38 std::size_t m_size;
39 Element* m_data;
40 public:
41 typedef Element value_type;
42 typedef value_type* iterator;
43 typedef const value_type* const_iterator;
44
45 ArrayReference()
46         : m_size( 0 ), m_data( 0 ){
47 }
48 ArrayReference( std::size_t size, Element* data )
49         : m_size( size ), m_data( data ){
50 }
51
52 iterator begin(){
53         return m_data;
54 }
55 const_iterator begin() const {
56         return m_data;
57 }
58 iterator end(){
59         return m_data + m_size;
60 }
61 const_iterator end() const {
62         return m_data + m_size;
63 }
64
65 value_type& operator[]( std::size_t index ){
66 #if GDEF_DEBUG
67         ASSERT_MESSAGE( index < size(), "array index out of bounds" );
68 #endif
69         return m_data[index];
70 }
71 const value_type& operator[]( std::size_t index ) const {
72 #if GDEF_DEBUG
73         ASSERT_MESSAGE( index < size(), "array index out of bounds" );
74 #endif
75         return m_data[index];
76 }
77 value_type* data(){
78         return m_data;
79 }
80 const value_type* data() const {
81         return m_data;
82 }
83 std::size_t size() const {
84         return m_size;
85 }
86 bool empty() const {
87         return m_size == 0;
88 }
89 };
90
91 #if 0
92 template<typename Element>
93 class MatrixIterator
94 {
95 Element* m_position;
96
97 void increment(){
98         ++m_position;
99 }
100
101 public:
102 typedef std::bidirectional_iterator_tag iterator_category;
103 typedef std::ptrdiff_t difference_type;
104 typedef difference_type distance_type;
105 typedef KeyValue<Key, Value> value_type;
106 typedef value_type* pointer;
107 typedef value_type& reference;
108
109 MatrixIterator( Element* position ) : m_position( position ){
110 }
111
112 Element* position(){
113         return m_position;
114 }
115
116 bool operator==( const MatrixIterator& other ) const {
117         return m_position == other.m_position;
118 }
119 bool operator!=( const MatrixIterator& other ) const {
120         return !operator==( other );
121 }
122 MatrixIterator& operator++(){
123         increment();
124         return *this;
125 }
126 MatrixIterator operator++( int ){
127         MatrixIterator tmp = *this;
128         increment();
129         return tmp;
130 }
131 value_type& operator*() const {
132         return m_position->m_value;
133 }
134 value_type* operator->() const {
135         return &( operator*() );
136 }
137 };
138 #endif
139
140 template<typename Element>
141 class Matrix
142 {
143 std::size_t m_x, m_y;
144 Element* m_data;
145 public:
146 typedef Element value_type;
147 typedef value_type* iterator;
148 typedef const value_type* const_iterator;
149
150 Matrix()
151         : m_x( 0 ), m_y( 0 ), m_data( 0 ){
152 }
153 Matrix( std::size_t x, std::size_t y, Element* data )
154         : m_x( x ), m_y( y ), m_data( data ){
155 }
156
157 iterator begin(){
158         return m_data;
159 }
160 const_iterator begin() const {
161         return m_data;
162 }
163 iterator end(){
164         return m_data + size();
165 }
166 const_iterator end() const {
167         return m_data + size();
168 }
169
170 value_type& operator[]( std::size_t index ){
171 #if GDEF_DEBUG
172         ASSERT_MESSAGE( index < size(), "array index out of bounds" );
173 #endif
174         return m_data[index];
175 }
176 const value_type& operator[]( std::size_t index ) const {
177 #if GDEF_DEBUG
178         ASSERT_MESSAGE( index < size(), "array index out of bounds" );
179 #endif
180         return m_data[index];
181 }
182 value_type& operator()( std::size_t x, std::size_t y ){
183 #if GDEF_DEBUG
184         ASSERT_MESSAGE( x < m_x && y < m_y, "array index out of bounds" );
185 #endif
186         return m_data[x * m_y + y];
187 }
188 const value_type& operator()( std::size_t x, std::size_t y ) const {
189 #if GDEF_DEBUG
190         ASSERT_MESSAGE( x < m_x && y < m_y, "array index out of bounds" );
191 #endif
192         return m_data[x * m_y + y];
193 }
194 value_type* data(){
195         return m_data;
196 }
197 const value_type* data() const {
198         return m_data;
199 }
200 std::size_t x() const {
201         return m_x;
202 }
203 std::size_t y() const {
204         return m_y;
205 }
206 std::size_t size() const {
207         return m_x * m_y;
208 }
209 bool empty() const {
210         return m_x == 0;
211 }
212 };
213
214 class PatchControl
215 {
216 public:
217 Vector3 m_vertex;
218 Vector2 m_texcoord;
219 };
220
221 typedef Matrix<PatchControl> PatchControlMatrix;
222
223
224 class PatchCreator
225 {
226 public:
227 INTEGER_CONSTANT( Version, 1 );
228 STRING_CONSTANT( Name, "patch" );
229 virtual scene::Node& createPatch() = 0;
230 virtual void Patch_undoSave( scene::Node& patch ) const = 0;
231 virtual void Patch_resize( scene::Node& patch, std::size_t width, std::size_t height ) const = 0;
232 virtual PatchControlMatrix Patch_getControlPoints( scene::Node& patch ) const = 0;
233 virtual void Patch_controlPointsChanged( scene::Node& patch ) const = 0;
234 virtual const char* Patch_getShader( scene::Node& patch ) const = 0;
235 virtual void Patch_setShader( scene::Node& patch, const char* shader ) const = 0;
236 };
237
238 #include "modulesystem.h"
239
240 template<typename Type>
241 class ModuleRef;
242 typedef ModuleRef<PatchCreator> PatchModuleRef;
243
244 template<typename Type>
245 class GlobalModule;
246 typedef GlobalModule<PatchCreator> GlobalPatchModule;
247
248 template<typename Type>
249 class GlobalModuleRef;
250 typedef GlobalModuleRef<PatchCreator> GlobalPatchModuleRef;
251
252 inline PatchCreator& GlobalPatchCreator(){
253         return GlobalPatchModule::getTable();
254 }
255
256 #endif