]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - include/ipatch.h
Remove some dead/debug code
[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 "debugging/debugging.h"
26 #include "generic/constant.h"
27 #include "generic/vector.h"
28
29 namespace scene
30 {
31 class Node;
32 }
33
34 template<typename Element>
35 class ArrayReference
36 {
37 std::size_t m_size;
38 Element* m_data;
39 public:
40 typedef Element value_type;
41 typedef value_type* iterator;
42 typedef const value_type* const_iterator;
43
44 ArrayReference()
45         : m_size( 0 ), m_data( 0 ){
46 }
47 ArrayReference( std::size_t size, Element* data )
48         : m_size( size ), m_data( data ){
49 }
50
51 iterator begin(){
52         return m_data;
53 }
54 const_iterator begin() const {
55         return m_data;
56 }
57 iterator end(){
58         return m_data + m_size;
59 }
60 const_iterator end() const {
61         return m_data + m_size;
62 }
63
64 value_type& operator[]( std::size_t index ){
65         ASSERT_MESSAGE( index < size(), "array index out of bounds" );
66         return m_data[index];
67 }
68 const value_type& operator[]( std::size_t index ) const {
69         ASSERT_MESSAGE( index < size(), "array index out of bounds" );
70         return m_data[index];
71 }
72 value_type* data(){
73         return m_data;
74 }
75 const value_type* data() const {
76         return m_data;
77 }
78 std::size_t size() const {
79         return m_size;
80 }
81 bool empty() const {
82         return m_size == 0;
83 }
84 };
85
86 template<typename Element>
87 class Matrix
88 {
89 std::size_t m_x, m_y;
90 Element* m_data;
91 public:
92 typedef Element value_type;
93 typedef value_type* iterator;
94 typedef const value_type* const_iterator;
95
96 Matrix()
97         : m_x( 0 ), m_y( 0 ), m_data( 0 ){
98 }
99 Matrix( std::size_t x, std::size_t y, Element* data )
100         : m_x( x ), m_y( y ), m_data( data ){
101 }
102
103 iterator begin(){
104         return m_data;
105 }
106 const_iterator begin() const {
107         return m_data;
108 }
109 iterator end(){
110         return m_data + size();
111 }
112 const_iterator end() const {
113         return m_data + size();
114 }
115
116 value_type& operator[]( std::size_t index ){
117         ASSERT_MESSAGE( index < size(), "array index out of bounds" );
118         return m_data[index];
119 }
120 const value_type& operator[]( std::size_t index ) const {
121         ASSERT_MESSAGE( index < size(), "array index out of bounds" );
122         return m_data[index];
123 }
124 value_type& operator()( std::size_t x, std::size_t y ){
125         ASSERT_MESSAGE( x < m_x && y < m_y, "array index out of bounds" );
126         return m_data[x * m_y + y];
127 }
128 const value_type& operator()( std::size_t x, std::size_t y ) const {
129         ASSERT_MESSAGE( x < m_x && y < m_y, "array index out of bounds" );
130         return m_data[x * m_y + y];
131 }
132 value_type* data(){
133         return m_data;
134 }
135 const value_type* data() const {
136         return m_data;
137 }
138 std::size_t x() const {
139         return m_x;
140 }
141 std::size_t y() const {
142         return m_y;
143 }
144 std::size_t size() const {
145         return m_x * m_y;
146 }
147 bool empty() const {
148         return m_x == 0;
149 }
150 };
151
152 class PatchControl
153 {
154 public:
155 Vector3 m_vertex;
156 Vector2 m_texcoord;
157 };
158
159 typedef Matrix<PatchControl> PatchControlMatrix;
160
161
162 class PatchCreator
163 {
164 public:
165 INTEGER_CONSTANT( Version, 1 );
166 STRING_CONSTANT( Name, "patch" );
167 virtual scene::Node& createPatch() = 0;
168 virtual void Patch_undoSave( scene::Node& patch ) const = 0;
169 virtual void Patch_resize( scene::Node& patch, std::size_t width, std::size_t height ) const = 0;
170 virtual PatchControlMatrix Patch_getControlPoints( scene::Node& patch ) const = 0;
171 virtual void Patch_controlPointsChanged( scene::Node& patch ) const = 0;
172 virtual const char* Patch_getShader( scene::Node& patch ) const = 0;
173 virtual void Patch_setShader( scene::Node& patch, const char* shader ) const = 0;
174 };
175
176 #include "modulesystem.h"
177
178 template<typename Type>
179 class ModuleRef;
180 typedef ModuleRef<PatchCreator> PatchModuleRef;
181
182 template<typename Type>
183 class GlobalModule;
184 typedef GlobalModule<PatchCreator> GlobalPatchModule;
185
186 template<typename Type>
187 class GlobalModuleRef;
188 typedef GlobalModuleRef<PatchCreator> GlobalPatchModuleRef;
189
190 inline PatchCreator& GlobalPatchCreator(){
191         return GlobalPatchModule::getTable();
192 }
193
194 #endif