]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/brush.h
changed ASSERT_MESSAGE and ERROR_MESSAGE macros to use proper
[xonotic/netradiant.git] / radiant / brush.h
index 8645063f5039860623f96f3a5d38483ea7ffab13..04d3d1ff4d4ac5193995c1be38820f70e8fbfbc7 100644 (file)
@@ -60,12 +60,13 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include "texturelib.h"
 #include "container/container.h"
 #include "generic/bitfield.h"
+#include "signal/signalfwd.h"
 
 #include "winding.h"
 #include "brush_primit.h"
 
-#define CONTENTS_DETAIL 0x8000000
-
+const unsigned int BRUSH_DETAIL_FLAG = 27;
+const unsigned int BRUSH_DETAIL_MASK = (1 << BRUSH_DETAIL_FLAG);
 
 enum EBrushType
 {
@@ -200,8 +201,6 @@ inline void Winding_Draw(const Winding& winding, const Vector3& normal, RenderSt
 #endif
 }
 
-const Colour4b colour_vertex(0, 255, 0, 255);
-
 
 #include "shaderlib.h"
 
@@ -377,14 +376,18 @@ public:
   bool m_specified;
 };
 
-inline unsigned int ContentFlags_assignable(unsigned int contentFlags)
-{
-  return contentFlags & ~CONTENTS_DETAIL;
-}
-
-inline ContentsFlagsValue ContentsFlagsValue_maskDetail(const ContentsFlagsValue& other)
+inline void ContentsFlagsValue_assignMasked(ContentsFlagsValue& flags, const ContentsFlagsValue& other)
 {
-  return ContentsFlagsValue(other.m_surfaceFlags, ContentFlags_assignable(other.m_contentFlags), other.m_value, other.m_specified);
+  bool detail = bitfield_enabled(flags.m_contentFlags, BRUSH_DETAIL_MASK);
+  flags = other;
+  if(detail)
+  {
+    flags.m_contentFlags = bitfield_enable(flags.m_contentFlags, BRUSH_DETAIL_MASK);
+  }
+  else
+  {
+    flags.m_contentFlags = bitfield_disable(flags.m_contentFlags, BRUSH_DETAIL_MASK);
+  }
 }
 
 
@@ -525,7 +528,7 @@ public:
   void setFlags(const ContentsFlagsValue& flags)
   {
     ASSERT_MESSAGE(m_realised, "FaceShader::setFlags: flags not valid when unrealised");
-    m_flags = ContentsFlagsValue_maskDetail(flags);
+    ContentsFlagsValue_assignMasked(m_flags, flags);
   }
 
   Shader* state() const
@@ -560,13 +563,6 @@ public:
 };
 
 
-inline void FaceShader_getFlags(const FaceShader& faceShader, ContentsFlagsValue& flags)
-{
-  flags = faceShader.getFlags();
-}
-
-
-
 
 
 class FaceTexdef : public FaceShaderObserver
@@ -703,11 +699,6 @@ public:
   }
 };
 
-inline void FaceTexdef_getTexdef(const FaceTexdef& faceTexdef, TextureProjection& projection)
-{
-  projection = faceTexdef.normalised();
-}
-
 inline void planepts_print(const PlanePoints& planePoints, TextOutputStream& ostream)
 {
   ostream << "( " << planePoints[0][0] << " " << planePoints[0][1] << " " << planePoints[0][2] << " ) "
@@ -938,6 +929,10 @@ public:
   }
 };
 
+inline void Winding_testSelect(Winding& winding, SelectionTest& test, SelectionIntersection& best)
+{
+  test.TestPolygon(VertexPointer(reinterpret_cast<VertexPointer::pointer>(&winding.points.data()->vertex), sizeof(WindingVertex)), winding.numpoints, best);
+}
 
 const double GRID_MIN = 0.125;
 
@@ -962,8 +957,9 @@ public:
 };
 
 bool face_filtered(Face& face);
+void add_face_filter(FaceFilter& filter, int mask, bool invert = false);
 
-void Brush_addTextureChangedCallback(const Callback& callback);
+void Brush_addTextureChangedCallback(const SignalHandler& callback);
 void Brush_textureChanged();
 
 
@@ -1269,10 +1265,9 @@ public:
     }
   }
 
-
   void testSelect(SelectionTest& test, SelectionIntersection& best)
   {
-    test.TestPolygon(VertexPointer(reinterpret_cast<VertexPointer::pointer>(&m_winding.points.data()->vertex), sizeof(WindingVertex)), m_winding.numpoints, best);
+    Winding_testSelect(m_winding, test, best);
   }
 
   void testSelect_centroid(SelectionTest& test, SelectionIntersection& best)
@@ -1286,6 +1281,7 @@ public:
     Brush_textureChanged();
     m_observer->shaderChanged();
     updateFiltered();
+       planeChanged();
     SceneChangeNotify();
   }
 
@@ -1311,6 +1307,10 @@ public:
     Brush_textureChanged();
   }
 
+  void GetTexdef(TextureProjection& projection) const
+  {
+    projection = m_texdef.normalised();
+  }
   void SetTexdef(const TextureProjection& projection)
   {
     undoSave();
@@ -1318,6 +1318,10 @@ public:
     texdefChanged();
   }
 
+  void GetFlags(ContentsFlagsValue& flags) const
+  {
+    flags = m_shader.getFlags();
+  }
   void SetFlags(const ContentsFlagsValue& flags)
   {
     undoSave();
@@ -1411,18 +1415,18 @@ public:
 
   bool isDetail() const
   {
-    return (m_shader.m_flags.m_contentFlags & CONTENTS_DETAIL) != 0;
+    return (m_shader.m_flags.m_contentFlags & BRUSH_DETAIL_MASK) != 0;
   }
   void setDetail(bool detail)
   {
     undoSave();
     if(detail && !isDetail())
     {
-      m_shader.m_flags.m_contentFlags |= CONTENTS_DETAIL;
+      m_shader.m_flags.m_contentFlags |= BRUSH_DETAIL_MASK;
     }
     else if(!detail && isDetail())
     {
-      m_shader.m_flags.m_contentFlags &= ~CONTENTS_DETAIL;
+      m_shader.m_flags.m_contentFlags &= ~BRUSH_DETAIL_MASK;
     }
     m_observer->shaderChanged();
   }
@@ -1729,10 +1733,10 @@ public:
     m_render_faces(m_faceCentroidPoints, GL_POINTS),
     m_render_vertices(m_uniqueVertexPoints, GL_POINTS),
     m_render_edges(m_uniqueEdgePoints, GL_POINTS),
-    m_planeChanged(false),
-    m_transformChanged(false),
     m_evaluateTransform(evaluateTransform),
-    m_boundsChanged(boundsChanged)
+    m_boundsChanged(boundsChanged),
+    m_planeChanged(false),
+    m_transformChanged(false)
   {
     planeChanged();
   }
@@ -1743,10 +1747,10 @@ public:
     m_render_faces(m_faceCentroidPoints, GL_POINTS),
     m_render_vertices(m_uniqueVertexPoints, GL_POINTS),
     m_render_edges(m_uniqueEdgePoints, GL_POINTS),
-    m_planeChanged(false),
-    m_transformChanged(false),
     m_evaluateTransform(evaluateTransform),
-    m_boundsChanged(boundsChanged)
+    m_boundsChanged(boundsChanged),
+    m_planeChanged(false),
+    m_transformChanged(false)
   {
     copy(other);
   }
@@ -1754,6 +1758,7 @@ public:
     TransformNode(other),
     Bounded(other),
     Cullable(other),
+    Snappable(),
     Undoable(other),
     FaceObserver(other),
     Filterable(other),
@@ -1902,6 +1907,7 @@ public:
   void shaderChanged()
   {
     updateFiltered();
+       planeChanged();
   }
 
   void evaluateBRep() const
@@ -2145,12 +2151,12 @@ public:
   {
     return m_faces.back();
   }
-  void reserve(std::size_t size)
+  void reserve(std::size_t count)
   {
-    m_faces.reserve(size);
+    m_faces.reserve(count);
     for(Observers::iterator i = m_observers.begin(); i != m_observers.end(); ++i)
     {
-      (*i)->reserve(size);
+      (*i)->reserve(count);
     }
   }
   void push_back(Faces::value_type face)
@@ -2203,6 +2209,7 @@ public:
 
   void clear()
   {
+    undoSave();
     if(m_instanceCounter.m_count != 0)
     {
       forEachFace_instanceDetach(m_map);
@@ -3092,7 +3099,7 @@ public:
         m_face->getWinding()[2].vertex
       ),
       "update_move_planepts_vertex2: error"
-    )
+    );
 
     m_face->m_move_planepts[0] = m_face->getWinding()[opposite].vertex;
     m_face->m_move_planepts[1] = m_face->getWinding()[index].vertex;
@@ -3557,12 +3564,13 @@ public:
   }
   typedef MemberCaller1<BrushInstance, const Selectable&, &BrushInstance::selectedChangedComponent> SelectedChangedComponentCaller;
 
-  void forEachFaceInstance(const BrushInstanceVisitor& visitor)
+  const BrushInstanceVisitor& forEachFaceInstance(const BrushInstanceVisitor& visitor)
   {
     for(FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i)
     {
       visitor.visit(*i);
     }
+    return visitor;
   }
 
   static void constructStatic()
@@ -3985,9 +3993,10 @@ public:
 };
 
 template<typename Functor>
-inline void Scene_forEachSelectedBrush(const Functor& functor)
+inline const Functor& Scene_forEachSelectedBrush(const Functor& functor)
 {
   GlobalSelectionSystem().foreachSelected(BrushSelectedVisitor<Functor>(functor));
+  return functor;
 }
 
 template<typename Functor>
@@ -4010,9 +4019,192 @@ public:
 };
 
 template<typename Functor>
-inline void Scene_forEachVisibleSelectedBrush(const Functor& functor)
+inline const Functor& Scene_forEachVisibleSelectedBrush(const Functor& functor)
 {
   GlobalSelectionSystem().foreachSelected(BrushVisibleSelectedVisitor<Functor>(functor));
+  return functor;
 }
 
+class BrushForEachFace
+{
+  const BrushInstanceVisitor& m_visitor;
+public:
+  BrushForEachFace(const BrushInstanceVisitor& visitor) : m_visitor(visitor)
+  {
+  }
+  void operator()(BrushInstance& brush) const
+  {
+    brush.forEachFaceInstance(m_visitor);
+  }
+};
+
+template<class Functor>
+class FaceInstanceVisitFace : public BrushInstanceVisitor
+{
+  const Functor& functor;
+public:
+  FaceInstanceVisitFace(const Functor& functor)
+    : functor(functor)
+  {
+  }
+  void visit(FaceInstance& face) const
+  {
+    functor(face.getFace());
+  }
+};
+
+template<typename Functor>
+inline const Functor& Brush_forEachFace(BrushInstance& brush, const Functor& functor)
+{
+  brush.forEachFaceInstance(FaceInstanceVisitFace<Functor>(functor));
+  return functor;
+}
+
+template<class Functor>
+class FaceVisitAll : public BrushVisitor
+{
+  const Functor& functor;
+public:
+  FaceVisitAll(const Functor& functor)
+    : functor(functor)
+  {
+  }
+  void visit(Face& face) const
+  {
+    functor(face);
+  }
+};
+
+template<typename Functor>
+inline const Functor& Brush_forEachFace(const Brush& brush, const Functor& functor)
+{
+  brush.forEachFace(FaceVisitAll<Functor>(functor));
+  return functor;
+}
+
+template<typename Functor>
+inline const Functor& Brush_forEachFace(Brush& brush, const Functor& functor)
+{
+  brush.forEachFace(FaceVisitAll<Functor>(functor));
+  return functor;
+}
+
+template<class Functor>
+class FaceInstanceVisitAll : public BrushInstanceVisitor
+{
+  const Functor& functor;
+public:
+  FaceInstanceVisitAll(const Functor& functor)
+    : functor(functor)
+  {
+  }
+  void visit(FaceInstance& face) const
+  {
+    functor(face);
+  }
+};
+
+template<typename Functor>
+inline const Functor& Brush_ForEachFaceInstance(BrushInstance& brush, const Functor& functor)
+{
+  brush.forEachFaceInstance(FaceInstanceVisitAll<Functor>(functor));
+  return functor;
+}
+
+template<typename Functor>
+inline const Functor& Scene_forEachBrush(scene::Graph& graph, const Functor& functor)
+{
+  graph.traverse(InstanceWalker< InstanceApply<BrushInstance, Functor> >(functor));
+  return functor;
+}
+
+template<typename Type, typename Functor>
+class InstanceIfVisible : public Functor
+{
+public:
+  InstanceIfVisible(const Functor& functor) : Functor(functor)
+  {
+  }
+  void operator()(scene::Instance& instance)
+  {
+    if(instance.path().top().get().visible())
+    {
+      Functor::operator()(instance);
+    }
+  }
+};
+
+template<typename Functor>
+class BrushVisibleWalker : public scene::Graph::Walker
+{
+  const Functor& m_functor;
+public:
+  BrushVisibleWalker(const Functor& functor) : m_functor(functor)
+  {
+  }
+  bool pre(const scene::Path& path, scene::Instance& instance) const
+  {
+    if(path.top().get().visible())
+    {
+      BrushInstance* brush = Instance_getBrush(instance);
+      if(brush != 0)
+      {
+        m_functor(*brush);
+      }
+    }
+    return true;
+  }
+};
+
+template<typename Functor>
+inline const Functor& Scene_forEachVisibleBrush(scene::Graph& graph, const Functor& functor)
+{
+  graph.traverse(BrushVisibleWalker<Functor>(functor));
+  return functor;
+}
+
+template<typename Functor>
+inline const Functor& Scene_ForEachBrush_ForEachFace(scene::Graph& graph, const Functor& functor)
+{
+  Scene_forEachBrush(graph, BrushForEachFace(FaceInstanceVisitFace<Functor>(functor)));
+  return functor;
+}
+
+template<typename Functor>
+inline const Functor& Scene_ForEachSelectedBrush_ForEachFace(scene::Graph& graph, const Functor& functor)
+{
+  Scene_forEachSelectedBrush(BrushForEachFace(FaceInstanceVisitFace<Functor>(functor)));
+  return functor;
+}
+
+template<typename Functor>
+inline const Functor& Scene_ForEachSelectedBrush_ForEachFaceInstance(scene::Graph& graph, const Functor& functor)
+{
+  Scene_forEachSelectedBrush(BrushForEachFace(FaceInstanceVisitAll<Functor>(functor)));
+  return functor;
+}
+
+template<typename Functor>
+class FaceVisitorWrapper
+{
+  const Functor& functor;
+public:
+  FaceVisitorWrapper(const Functor& functor) : functor(functor)
+  {
+  }
+
+  void operator()(FaceInstance& faceInstance) const
+  {
+    functor(faceInstance.getFace());
+  }
+};
+
+template<typename Functor>
+inline const Functor& Scene_ForEachSelectedBrushFace(scene::Graph& graph, const Functor& functor)
+{
+  g_SelectedFaceInstances.foreach(FaceVisitorWrapper<Functor>(functor));
+  return functor;
+}
+
+
 #endif