]> de.git.xonotic.org Git - xonotic/netradiant.git/commitdiff
Embrace lambdas
authorTimePath <andrew.hardaker1995@gmail.com>
Sun, 31 Dec 2017 11:06:17 +0000 (22:06 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Sun, 31 Dec 2017 11:06:17 +0000 (22:06 +1100)
14 files changed:
libs/instancelib.h
libs/math/aabb.h
plugins/entity/curve.h
plugins/entity/doom3group.cpp
radiant/brush.h
radiant/brushmanip.cpp
radiant/build.cpp
radiant/csg.cpp
radiant/eclass.cpp
radiant/mainframe.cpp
radiant/patchdialog.cpp
radiant/patchmanip.cpp
radiant/preferences.cpp
radiant/scenegraph.cpp

index 913288b6a9b127b90566412d78f96f3f13ad5c70..eeb95e23579860c11f73088ff9e2bcde3b40c610 100644 (file)
@@ -153,21 +153,14 @@ inline void InstanceSet_forEach( InstanceSet& instances, const Functor& functor
        }
 }
 
-template<typename Type>
-class InstanceEvaluateTransform
-{
-public:
-inline void operator()( scene::Instance& instance ) const {
-       InstanceTypeCast<Type>::cast( instance )->evaluateTransform();
-}
-};
-
 template<typename Type>
 class InstanceSetEvaluateTransform
 {
 public:
 static void apply( InstanceSet& instances ){
-       InstanceSet_forEach( instances, InstanceEvaluateTransform<Type>() );
+       InstanceSet_forEach(instances, [&](scene::Instance &instance) {
+               InstanceTypeCast<Type>::cast(instance)->evaluateTransform();
+       });
 }
 typedef ReferenceCaller<InstanceSet, &InstanceSetEvaluateTransform<Type>::apply> Caller;
 };
index 29e3a38ebd13545565d9ba5dae4cc9913147379c..917850f5b5b3d6e2d326e3b5e1b1e114aced4d7c 100644 (file)
@@ -112,17 +112,6 @@ inline void aabb_extend_by_point_safe( AABB& aabb, const Vector3& point ){
        }
 }
 
-class AABBExtendByPoint
-{
-AABB& m_aabb;
-public:
-AABBExtendByPoint( AABB& aabb ) : m_aabb( aabb ){
-}
-void operator()( const Vector3& point ) const {
-       aabb_extend_by_point_safe( m_aabb, point );
-}
-};
-
 inline void aabb_extend_by_aabb( AABB& aabb, const AABB& other ){
        AABBExtend< IntegralConstant<0> >::apply( aabb, other );
        AABBExtend< IntegralConstant<1> >::apply( aabb, other );
index de610de35f05d6409b78b09d2278d9256c1141af..cefad32a2c5d1ce90d67f0a65722b472814e1367 100644 (file)
@@ -111,50 +111,6 @@ inline void ControlPoint_testSelect( const Vector3& point, ObservedSelectable& s
        }
 }
 
-class ControlPointTransform
-{
-const Matrix4& m_matrix;
-public:
-ControlPointTransform( const Matrix4& matrix ) : m_matrix( matrix ){
-}
-void operator()( Vector3& point ) const {
-       matrix4_transform_point( m_matrix, point );
-}
-};
-
-class ControlPointSnap
-{
-float m_snap;
-public:
-ControlPointSnap( float snap ) : m_snap( snap ){
-}
-void operator()( Vector3& point ) const {
-       vector3_snap( point, m_snap );
-}
-};
-
-class ControlPointAdd
-{
-RenderablePointVector& m_points;
-public:
-ControlPointAdd( RenderablePointVector& points ) : m_points( points ){
-}
-void operator()( const Vector3& point ) const {
-       m_points.push_back( PointVertex( vertex3f_for_vector3( point ), colour_vertex ) );
-}
-};
-
-class ControlPointAddSelected
-{
-RenderablePointVector& m_points;
-public:
-ControlPointAddSelected( RenderablePointVector& points ) : m_points( points ){
-}
-void operator()( const Vector3& point ) const {
-       m_points.push_back( PointVertex( vertex3f_for_vector3( point ), colour_selected ) );
-}
-};
-
 class CurveEditType
 {
 public:
@@ -253,15 +209,21 @@ void write( const char* key, Entity& entity ){
 }
 
 void transform( const Matrix4& matrix ){
-       forEachSelected( ControlPointTransform( matrix ) );
+       forEachSelected([&](Vector3 &point) {
+               matrix4_transform_point(matrix, point);
+       });
 }
 void snapto( float snap ){
-       forEachSelected( ControlPointSnap( snap ) );
+       forEachSelected([&](Vector3 &point) {
+               vector3_snap(point, snap);
+       });
 }
 
 void updateSelected() const {
        m_selectedRender.clear();
-       forEachSelected( ControlPointAddSelected( m_selectedRender ) );
+       forEachSelected([&](const Vector3 &point) {
+               m_selectedRender.push_back(PointVertex(vertex3f_for_vector3(point), colour_selected));
+       });
 }
 
 void renderComponents( Renderer& renderer, const VolumeTest& volume, const Matrix4& localToWorld ) const {
@@ -285,7 +247,9 @@ void curveChanged(){
 
        m_controlsRender.clear();
        m_controlsRender.reserve( m_controlPoints.size() );
-       forEach( ControlPointAdd( m_controlsRender ) );
+       forEach([&](const Vector3 &point) {
+               m_controlsRender.push_back(PointVertex(vertex3f_for_vector3(point), colour_vertex));
+       });
 
        m_selectedRender.reserve( m_controlPoints.size() );
 }
index b53017c55d59b05c734714305da1d11b113ab9a1..bab1bbe813010bee85dc0910b613653bb749773e 100644 (file)
@@ -423,17 +423,6 @@ void transformChanged(){
 typedef MemberCaller<Doom3Group, &Doom3Group::transformChanged> TransformChangedCaller;
 };
 
-class ControlPointAddBounds
-{
-AABB& m_bounds;
-public:
-ControlPointAddBounds( AABB& bounds ) : m_bounds( bounds ){
-}
-void operator()( const Vector3& point ) const {
-       aabb_extend_by_point_safe( m_bounds, point );
-}
-};
-
 class Doom3GroupInstance :
        public TargetableInstance,
        public TransformModifier,
@@ -555,8 +544,12 @@ void transformComponents( const Matrix4& matrix ){
 
 const AABB& getSelectedComponentsBounds() const {
        m_aabb_component = AABB();
-       m_curveNURBS.forEachSelected( ControlPointAddBounds( m_aabb_component ) );
-       m_curveCatmullRom.forEachSelected( ControlPointAddBounds( m_aabb_component ) );
+       m_curveNURBS.forEachSelected([&](const Vector3 &point) {
+               aabb_extend_by_point_safe(m_aabb_component, point);
+       });
+       m_curveCatmullRom.forEachSelected([&](const Vector3 &point) {
+               aabb_extend_by_point_safe(m_aabb_component, point);
+       });
        return m_aabb_component;
 }
 
index 0fb6ffe225c2b0d3dbe45d0a8b3d5fb08a07079f..4508591c73926700f56b5643a298f8198264c82e 100644 (file)
@@ -311,22 +311,6 @@ virtual void realiseShader() = 0;
 virtual void unrealiseShader() = 0;
 };
 
-class FaceShaderObserverRealise
-{
-public:
-void operator()( FaceShaderObserver& observer ) const {
-       observer.realiseShader();
-}
-};
-
-class FaceShaderObserverUnrealise
-{
-public:
-void operator()( FaceShaderObserver& observer ) const {
-       observer.unrealiseShader();
-}
-};
-
 typedef ReferencePair<FaceShaderObserver> FaceShaderObserverPair;
 
 
@@ -426,11 +410,15 @@ void releaseShader(){
 void realise(){
        ASSERT_MESSAGE( !m_realised, "FaceTexdef::realise: already realised" );
        m_realised = true;
-       m_observers.forEach( FaceShaderObserverRealise() );
+       m_observers.forEach([](FaceShaderObserver &observer) {
+               observer.realiseShader();
+       });
 }
 void unrealise(){
        ASSERT_MESSAGE( m_realised, "FaceTexdef::unrealise: already unrealised" );
-       m_observers.forEach( FaceShaderObserverUnrealise() );
+       m_observers.forEach([](FaceShaderObserver &observer) {
+               observer.unrealiseShader();
+       });
        m_realised = false;
 }
 
@@ -2560,23 +2548,16 @@ void SelectedComponents_foreach( Functor functor ) const {
 }
 
 void iterate_selected( AABB& aabb ) const {
-       SelectedComponents_foreach( AABBExtendByPoint( aabb ) );
+       SelectedComponents_foreach([&](const Vector3 &point) {
+               aabb_extend_by_point_safe(aabb, point);
+       });
 }
 
-class RenderablePointVectorPushBack
-{
-RenderablePointVector& m_points;
-public:
-RenderablePointVectorPushBack( RenderablePointVector& points ) : m_points( points ){
-}
-void operator()( const Vector3& point ) const {
-       const Colour4b colour_selected( 0, 0, 255, 255 );
-       m_points.push_back( pointvertex_for_windingpoint( point, colour_selected ) );
-}
-};
-
 void iterate_selected( RenderablePointVector& points ) const {
-       SelectedComponents_foreach( RenderablePointVectorPushBack( points ) );
+       SelectedComponents_foreach([&](const Vector3 &point) {
+               const Colour4b colour_selected(0, 0, 255, 255);
+               points.push_back(pointvertex_for_windingpoint(point, colour_selected));
+       });
 }
 
 bool intersectVolume( const VolumeTest& volume, const Matrix4& localToWorld ) const {
index 43dc0e7315220582cdac831311a84fedced43075..dd22446afa5788035c882e8a91c14a3f728f88d0 100644 (file)
@@ -405,146 +405,96 @@ void ConstructRegionBrushes( scene::Node* brushes[6], const Vector3& region_mins
 }
 
 
-class FaceSetTexdef
-{
-const TextureProjection& m_projection;
-public:
-FaceSetTexdef( const TextureProjection& projection ) : m_projection( projection ){
-}
-void operator()( Face& face ) const {
-       face.SetTexdef( m_projection );
-}
-};
-
 void Scene_BrushSetTexdef_Selected( scene::Graph& graph, const TextureProjection& projection ){
-       Scene_ForEachSelectedBrush_ForEachFace( graph, FaceSetTexdef( projection ) );
+       Scene_ForEachSelectedBrush_ForEachFace(graph, [&](Face &face) {
+               face.SetTexdef(projection);
+       });
        SceneChangeNotify();
 }
 
 void Scene_BrushSetTexdef_Component_Selected( scene::Graph& graph, const TextureProjection& projection ){
-       Scene_ForEachSelectedBrushFace( graph, FaceSetTexdef( projection ) );
+       Scene_ForEachSelectedBrushFace(graph, [&](Face &face) {
+               face.SetTexdef(projection);
+       });
        SceneChangeNotify();
 }
 
 
-class FaceSetFlags
-{
-const ContentsFlagsValue& m_projection;
-public:
-FaceSetFlags( const ContentsFlagsValue& flags ) : m_projection( flags ){
-}
-void operator()( Face& face ) const {
-       face.SetFlags( m_projection );
-}
-};
-
 void Scene_BrushSetFlags_Selected( scene::Graph& graph, const ContentsFlagsValue& flags ){
-       Scene_ForEachSelectedBrush_ForEachFace( graph, FaceSetFlags( flags ) );
+       Scene_ForEachSelectedBrush_ForEachFace(graph, [&](Face &face) {
+               face.SetFlags(flags);
+       });
        SceneChangeNotify();
 }
 
 void Scene_BrushSetFlags_Component_Selected( scene::Graph& graph, const ContentsFlagsValue& flags ){
-       Scene_ForEachSelectedBrushFace( graph, FaceSetFlags( flags ) );
+       Scene_ForEachSelectedBrushFace(graph, [&](Face &face) {
+               face.SetFlags(flags);
+       });
        SceneChangeNotify();
 }
 
-class FaceShiftTexdef
-{
-float m_s, m_t;
-public:
-FaceShiftTexdef( float s, float t ) : m_s( s ), m_t( t ){
-}
-void operator()( Face& face ) const {
-       face.ShiftTexdef( m_s, m_t );
-}
-};
-
 void Scene_BrushShiftTexdef_Selected( scene::Graph& graph, float s, float t ){
-       Scene_ForEachSelectedBrush_ForEachFace( graph, FaceShiftTexdef( s, t ) );
+       Scene_ForEachSelectedBrush_ForEachFace(graph, [&](Face &face) {
+               face.ShiftTexdef(s, t);
+       });
        SceneChangeNotify();
 }
 
 void Scene_BrushShiftTexdef_Component_Selected( scene::Graph& graph, float s, float t ){
-       Scene_ForEachSelectedBrushFace( graph, FaceShiftTexdef( s, t ) );
+       Scene_ForEachSelectedBrushFace(graph, [&](Face &face) {
+               face.ShiftTexdef(s, t);
+       });
        SceneChangeNotify();
 }
 
-class FaceScaleTexdef
-{
-float m_s, m_t;
-public:
-FaceScaleTexdef( float s, float t ) : m_s( s ), m_t( t ){
-}
-void operator()( Face& face ) const {
-       face.ScaleTexdef( m_s, m_t );
-}
-};
-
 void Scene_BrushScaleTexdef_Selected( scene::Graph& graph, float s, float t ){
-       Scene_ForEachSelectedBrush_ForEachFace( graph, FaceScaleTexdef( s, t ) );
+       Scene_ForEachSelectedBrush_ForEachFace(graph, [&](Face &face) {
+               face.ScaleTexdef(s, t);
+       });
        SceneChangeNotify();
 }
 
 void Scene_BrushScaleTexdef_Component_Selected( scene::Graph& graph, float s, float t ){
-       Scene_ForEachSelectedBrushFace( graph, FaceScaleTexdef( s, t ) );
+       Scene_ForEachSelectedBrushFace(graph, [&](Face &face) {
+               face.ScaleTexdef(s, t);
+       });
        SceneChangeNotify();
 }
 
-class FaceRotateTexdef
-{
-float m_angle;
-public:
-FaceRotateTexdef( float angle ) : m_angle( angle ){
-}
-void operator()( Face& face ) const {
-       face.RotateTexdef( m_angle );
-}
-};
-
 void Scene_BrushRotateTexdef_Selected( scene::Graph& graph, float angle ){
-       Scene_ForEachSelectedBrush_ForEachFace( graph, FaceRotateTexdef( angle ) );
+       Scene_ForEachSelectedBrush_ForEachFace(graph, [&](Face &face) {
+               face.RotateTexdef(angle);
+       });
        SceneChangeNotify();
 }
 
 void Scene_BrushRotateTexdef_Component_Selected( scene::Graph& graph, float angle ){
-       Scene_ForEachSelectedBrushFace( graph, FaceRotateTexdef( angle ) );
+       Scene_ForEachSelectedBrushFace(graph, [&](Face &face) {
+               face.RotateTexdef(angle);
+       });
        SceneChangeNotify();
 }
 
 
-class FaceSetShader
-{
-const char* m_name;
-public:
-FaceSetShader( const char* name ) : m_name( name ) {}
-void operator()( Face& face ) const {
-       face.SetShader( m_name );
-}
-};
-
 void Scene_BrushSetShader_Selected( scene::Graph& graph, const char* name ){
-       Scene_ForEachSelectedBrush_ForEachFace( graph, FaceSetShader( name ) );
+       Scene_ForEachSelectedBrush_ForEachFace(graph, [&](Face &face) {
+               face.SetShader(name);
+       });
        SceneChangeNotify();
 }
 
 void Scene_BrushSetShader_Component_Selected( scene::Graph& graph, const char* name ){
-       Scene_ForEachSelectedBrushFace( graph, FaceSetShader( name ) );
+       Scene_ForEachSelectedBrushFace(graph, [&](Face &face) {
+               face.SetShader(name);
+       });
        SceneChangeNotify();
 }
 
-class FaceSetDetail
-{
-bool m_detail;
-public:
-FaceSetDetail( bool detail ) : m_detail( detail ){
-}
-void operator()( Face& face ) const {
-       face.setDetail( m_detail );
-}
-};
-
 void Scene_BrushSetDetail_Selected( scene::Graph& graph, bool detail ){
-       Scene_ForEachSelectedBrush_ForEachFace( graph, FaceSetDetail( detail ) );
+       Scene_ForEachSelectedBrush_ForEachFace(graph, [&](Face &face) {
+               face.setDetail(detail);
+       });
        SceneChangeNotify();
 }
 
@@ -556,55 +506,37 @@ bool Face_FindReplaceShader( Face& face, const char* find, const char* replace )
        return false;
 }
 
-class FaceFindReplaceShader
-{
-const char* m_find;
-const char* m_replace;
-public:
-FaceFindReplaceShader( const char* find, const char* replace ) : m_find( find ), m_replace( replace ){
-}
-void operator()( Face& face ) const {
-       Face_FindReplaceShader( face, m_find, m_replace );
-}
-};
-
-class FaceFindShader
-{
-const char* m_find;
-const char* m_replace;
-public:
-FaceFindShader( const char* find ) : m_find( find ){
-}
-void operator()( FaceInstance& faceinst ) const {
-       if ( shader_equal( faceinst.getFace().GetShader(), m_find ) ) {
-               faceinst.setSelected( SelectionSystem::eFace, true );
-       }
-}
-};
-
 bool DoingSearch( const char *repl ){
        return ( repl == NULL || ( strcmp( "textures/", repl ) == 0 ) );
 }
 
 void Scene_BrushFindReplaceShader( scene::Graph& graph, const char* find, const char* replace ){
        if ( DoingSearch( replace ) ) {
-               Scene_ForEachBrush_ForEachFaceInstance( graph, FaceFindShader( find ) );
+               Scene_ForEachBrush_ForEachFaceInstance(graph, [&](FaceInstance &faceinst) {
+                       if (shader_equal(faceinst.getFace().GetShader(), find)) {
+                               faceinst.setSelected(SelectionSystem::eFace, true);
+                       }
+               });
        }
        else
        {
-               Scene_ForEachBrush_ForEachFace( graph, FaceFindReplaceShader( find, replace ) );
+               Scene_ForEachBrush_ForEachFace(graph, [&](Face &face) { Face_FindReplaceShader(face, find, replace); });
        }
 }
 
 void Scene_BrushFindReplaceShader_Selected( scene::Graph& graph, const char* find, const char* replace ){
        if ( DoingSearch( replace ) ) {
-               Scene_ForEachSelectedBrush_ForEachFaceInstance( graph,
-                                                                                                               FaceFindShader( find ) );
+               Scene_ForEachSelectedBrush_ForEachFaceInstance(graph, [&](FaceInstance &faceinst) {
+                       if (shader_equal(faceinst.getFace().GetShader(), find)) {
+                               faceinst.setSelected(SelectionSystem::eFace, true);
+                       }
+               });
        }
        else
        {
-               Scene_ForEachSelectedBrush_ForEachFace( graph,
-                                                                                               FaceFindReplaceShader( find, replace ) );
+               Scene_ForEachSelectedBrush_ForEachFace(graph, [&](Face &face) {
+                       Face_FindReplaceShader(face, find, replace);
+               });
        }
 }
 
@@ -616,29 +548,24 @@ void Scene_BrushFindReplaceShader_Component_Selected( scene::Graph& graph, const
        }
        else
        {
-               Scene_ForEachSelectedBrushFace( graph, FaceFindReplaceShader( find, replace ) );
+               Scene_ForEachSelectedBrushFace(graph, [&](Face &face) {
+                       Face_FindReplaceShader(face, find, replace);
+               });
        }
 }
 
 
-class FaceFitTexture
-{
-float m_s_repeat, m_t_repeat;
-public:
-FaceFitTexture( float s_repeat, float t_repeat ) : m_s_repeat( s_repeat ), m_t_repeat( t_repeat ){
-}
-void operator()( Face& face ) const {
-       face.FitTexture( m_s_repeat, m_t_repeat );
-}
-};
-
 void Scene_BrushFitTexture_Selected( scene::Graph& graph, float s_repeat, float t_repeat ){
-       Scene_ForEachSelectedBrush_ForEachFace( graph, FaceFitTexture( s_repeat, t_repeat ) );
+       Scene_ForEachSelectedBrush_ForEachFace(graph, [&](Face &face) {
+               face.FitTexture(s_repeat, t_repeat);
+       });
        SceneChangeNotify();
 }
 
 void Scene_BrushFitTexture_Component_Selected( scene::Graph& graph, float s_repeat, float t_repeat ){
-       Scene_ForEachSelectedBrushFace( graph, FaceFitTexture( s_repeat, t_repeat ) );
+       Scene_ForEachSelectedBrushFace(graph, [&](Face &face) {
+               face.FitTexture(s_repeat, t_repeat);
+       });
        SceneChangeNotify();
 }
 
@@ -705,44 +632,23 @@ void Scene_BrushSelectByShader( scene::Graph& graph, const char* name ){
        graph.traverse( BrushSelectByShaderWalker( name ) );
 }
 
-class FaceSelectByShader
-{
-const char* m_name;
-public:
-FaceSelectByShader( const char* name )
-       : m_name( name ){
-}
-void operator()( FaceInstance& face ) const {
-       printf( "checking %s = %s\n", face.getFace().GetShader(), m_name );
-       if ( shader_equal( face.getFace().GetShader(), m_name ) ) {
-               face.setSelected( SelectionSystem::eFace, true );
-       }
-}
-};
-
 void Scene_BrushSelectByShader_Component( scene::Graph& graph, const char* name ){
-       Scene_ForEachSelectedBrush_ForEachFaceInstance( graph, FaceSelectByShader( name ) );
-}
-
-class FaceGetTexdef
-{
-TextureProjection& m_projection;
-mutable bool m_done;
-public:
-FaceGetTexdef( TextureProjection& projection )
-       : m_projection( projection ), m_done( false ){
-}
-void operator()( Face& face ) const {
-       if ( !m_done ) {
-               m_done = true;
-               face.GetTexdef( m_projection );
-       }
+       Scene_ForEachSelectedBrush_ForEachFaceInstance(graph, [&](FaceInstance &face) {
+               printf("checking %s = %s\n", face.getFace().GetShader(), name);
+               if (shader_equal(face.getFace().GetShader(), name)) {
+                       face.setSelected(SelectionSystem::eFace, true);
+               }
+       });
 }
-};
-
 
 void Scene_BrushGetTexdef_Selected( scene::Graph& graph, TextureProjection& projection ){
-       Scene_ForEachSelectedBrush_ForEachFace( graph, FaceGetTexdef( projection ) );
+       bool done = false;
+       Scene_ForEachSelectedBrush_ForEachFace(graph, [&](Face &face) {
+               if (!done) {
+                       done = true;
+                       face.GetTexdef(projection);
+               }
+       });
 }
 
 void Scene_BrushGetTexdef_Component_Selected( scene::Graph& graph, TextureProjection& projection ){
@@ -766,29 +672,18 @@ void Scene_BrushGetShaderSize_Component_Selected( scene::Graph& graph, size_t& w
 }
 
 
-class FaceGetFlags
-{
-ContentsFlagsValue& m_flags;
-mutable bool m_done;
-public:
-FaceGetFlags( ContentsFlagsValue& flags )
-       : m_flags( flags ), m_done( false ){
-}
-void operator()( Face& face ) const {
-       if ( !m_done ) {
-               m_done = true;
-               face.GetFlags( m_flags );
-       }
-}
-};
-
-
 void Scene_BrushGetFlags_Selected( scene::Graph& graph, ContentsFlagsValue& flags ){
 #if 1
        if ( GlobalSelectionSystem().countSelected() != 0 ) {
                BrushInstance* brush = Instance_getBrush( GlobalSelectionSystem().ultimateSelected() );
                if ( brush != 0 ) {
-                       Brush_forEachFace( *brush, FaceGetFlags( flags ) );
+                       bool done = false;
+                       Brush_forEachFace(*brush, [&](Face &face) {
+                               if (!done) {
+                                       done = true;
+                                       face.GetFlags(flags);
+                               }
+                       });
                }
        }
 #else
@@ -808,28 +703,18 @@ void Scene_BrushGetFlags_Component_Selected( scene::Graph& graph, ContentsFlagsV
 }
 
 
-class FaceGetShader
-{
-CopiedString& m_shader;
-mutable bool m_done;
-public:
-FaceGetShader( CopiedString& shader )
-       : m_shader( shader ), m_done( false ){
-}
-void operator()( Face& face ) const {
-       if ( !m_done ) {
-               m_done = true;
-               m_shader = face.GetShader();
-       }
-}
-};
-
 void Scene_BrushGetShader_Selected( scene::Graph& graph, CopiedString& shader ){
 #if 1
        if ( GlobalSelectionSystem().countSelected() != 0 ) {
                BrushInstance* brush = Instance_getBrush( GlobalSelectionSystem().ultimateSelected() );
                if ( brush != 0 ) {
-                       Brush_forEachFace( *brush, FaceGetShader( shader ) );
+                       bool done = false;
+                       Brush_forEachFace(*brush, [&](Face &face) {
+                               if (!done) {
+                                       done = true;
+                                       shader = face.GetShader();
+                               }
+                       });
                }
        }
 #else
@@ -896,21 +781,6 @@ bool filter( const Face& face ) const {
 
 
 
-class FaceFilterAny
-{
-FaceFilter* m_filter;
-bool& m_filtered;
-public:
-FaceFilterAny( FaceFilter* filter, bool& filtered ) : m_filter( filter ), m_filtered( filtered ){
-       m_filtered = false;
-}
-void operator()( Face& face ) const {
-       if ( m_filter->filter( face ) ) {
-               m_filtered = true;
-       }
-}
-};
-
 class filter_brush_any_face : public BrushFilter
 {
 FaceFilter* m_filter;
@@ -918,27 +788,16 @@ public:
 filter_brush_any_face( FaceFilter* filter ) : m_filter( filter ){
 }
 bool filter( const Brush& brush ) const {
-       bool filtered;
-       Brush_forEachFace( brush, FaceFilterAny( m_filter, filtered ) );
+       bool filtered = false;
+       Brush_forEachFace(brush, [&](Face &face) {
+               if (m_filter->filter(face)) {
+                       filtered = true;
+               }
+       });
        return filtered;
 }
 };
 
-class FaceFilterAll
-{
-FaceFilter* m_filter;
-bool& m_filtered;
-public:
-FaceFilterAll( FaceFilter* filter, bool& filtered ) : m_filter( filter ), m_filtered( filtered ){
-       m_filtered = true;
-}
-void operator()( Face& face ) const {
-       if ( !m_filter->filter( face ) ) {
-               m_filtered = false;
-       }
-}
-};
-
 class filter_brush_all_faces : public BrushFilter
 {
 FaceFilter* m_filter;
@@ -946,8 +805,12 @@ public:
 filter_brush_all_faces( FaceFilter* filter ) : m_filter( filter ){
 }
 bool filter( const Brush& brush ) const {
-       bool filtered;
-       Brush_forEachFace( brush, FaceFilterAll( m_filter, filtered ) );
+       bool filtered = true;
+       Brush_forEachFace(brush, [&](Face &face) {
+               if (!m_filter->filter(face)) {
+                       filtered = false;
+               }
+       });
        return filtered;
 }
 };
index 5207d67678e275d2b7dcbc45645017b493005896..722d46fba30f512c235734a50c2e6343654d34ca 100644 (file)
@@ -311,21 +311,12 @@ static bool is_separator( const BuildPair &p ){
 }
 
 
-class BuildPairEqual
-{
-const char* m_name;
-public:
-BuildPairEqual( const char* name ) : m_name( name ){
-}
-bool operator()( const BuildPair& self ) const {
-       return string_equal( self.first.c_str(), m_name );
-}
-};
-
 typedef std::list<BuildPair> Project;
 
 Project::iterator Project_find( Project& project, const char* name ){
-       return std::find_if( project.begin(), project.end(), BuildPairEqual( name ) );
+       return std::find_if(project.begin(), project.end(), [&](const BuildPair &self) {
+               return string_equal(self.first.c_str(), name);
+       });
 }
 
 Project::iterator Project_find( Project& project, std::size_t index ){
index 2538359fc96a8ac5d8e9b7285c22058368d940db..cc5de460285bf609eb4a832c6ddc3b07c54a085e 100644 (file)
@@ -42,22 +42,10 @@ void Face_makeBrush( Face& face, const Brush& brush, brush_vector_t& out, float
        }
 }
 
-class FaceMakeBrush
-{
-const Brush& brush;
-brush_vector_t& out;
-float offset;
-public:
-FaceMakeBrush( const Brush& brush, brush_vector_t& out, float offset )
-       : brush( brush ), out( out ), offset( offset ){
-}
-void operator()( Face& face ) const {
-       Face_makeBrush( face, brush, out, offset );
-}
-};
-
 void Brush_makeHollow( const Brush& brush, brush_vector_t& out, float offset ){
-       Brush_forEachFace( brush, FaceMakeBrush( brush, out, offset ) );
+       Brush_forEachFace(brush, [&](Face &face) {
+               Face_makeBrush(face, brush, out, offset);
+       });
 }
 
 class BrushHollowSelectedWalker : public scene::Graph::Walker
index ea9828e510857749ebe09e3a0eacee48f19f1c2a..90c8a11b2f2eda7d2d6f487398a536dd150779c5 100644 (file)
@@ -175,22 +175,11 @@ struct PathLess
 
 typedef std::map<CopiedString, const char*, PathLess> Paths;
 
-class PathsInsert
-{
-Paths& m_paths;
-const char* m_directory;
-public:
-PathsInsert( Paths& paths, const char* directory ) : m_paths( paths ), m_directory( directory ){
-}
-void operator()( const char* name ) const {
-       m_paths.insert( Paths::value_type( name, m_directory ) );
-}
-};
-
-
 void EntityClassQuake3_constructDirectory( const char* directory, const char* extension, Paths& paths ){
        globalOutputStream() << "EntityClass: searching " << makeQuoted( directory ) << " for *." << extension << '\n';
-       Directory_forEach( directory, matchFileExtension( extension, PathsInsert( paths, directory ) ) );
+       Directory_forEach(directory, matchFileExtension(extension, [&](const char *name) {
+               paths.insert(Paths::value_type(name, directory));
+       }));
 }
 
 
index 05fdc2b78eae7221499f8d0e5844b84478ce167b..433767d547c705bb2a04d0b521a9a4db820aa493 100644 (file)
@@ -521,22 +521,6 @@ void gamemode_set( const char* gamemode ){
 
 #include "os/dir.h"
 
-class CLoadModule
-{
-const char* m_path;
-public:
-CLoadModule( const char* path ) : m_path( path ){
-}
-void operator()( const char* name ) const {
-       char fullname[1024];
-       ASSERT_MESSAGE( strlen( m_path ) + strlen( name ) < 1024, "" );
-       strcpy( fullname, m_path );
-       strcat( fullname, name );
-       globalOutputStream() << "Found '" << fullname << "'\n";
-       GlobalModuleServer_loadModule( fullname );
-}
-};
-
 const char* const c_library_extension =
 #if defined( CMAKE_SHARED_MODULE_SUFFIX )
     CMAKE_SHARED_MODULE_SUFFIX
@@ -550,7 +534,14 @@ const char* const c_library_extension =
 ;
 
 void Radiant_loadModules( const char* path ){
-       Directory_forEach( path, MatchFileExtension<CLoadModule>( c_library_extension, CLoadModule( path ) ) );
+       Directory_forEach(path, matchFileExtension(c_library_extension, [&](const char *name) {
+               char fullname[1024];
+               ASSERT_MESSAGE(strlen(path) + strlen(name) < 1024, "");
+               strcpy(fullname, path);
+               strcat(fullname, name);
+               globalOutputStream() << "Found '" << fullname << "'\n";
+               GlobalModuleServer_loadModule(fullname);
+       }));
 }
 
 void Radiant_loadModulesFromRoot( const char* directory ){
index 4a358a5ed2f9dce2884f94c3b362d9402aaee487..0b85ea2d1f0a1c6ae46328dd1b0db91f1a18c9df 100644 (file)
@@ -137,20 +137,11 @@ void Scene_PatchGetFixedSubdivisions( PatchFixedSubdivisions& subdivisions ){
 #endif
 }
 
-class PatchSetFixedSubdivisions
-{
-const PatchFixedSubdivisions& m_subdivisions;
-public:
-PatchSetFixedSubdivisions( const PatchFixedSubdivisions& subdivisions ) : m_subdivisions( subdivisions ){
-}
-void operator()( Patch& patch ) const {
-       Patch_setFixedSubdivisions( patch, m_subdivisions );
-}
-};
-
 void Scene_PatchSetFixedSubdivisions( const PatchFixedSubdivisions& subdivisions ){
        UndoableCommand command( "patchSetFixedSubdivisions" );
-       Scene_forEachVisibleSelectedPatch( PatchSetFixedSubdivisions( subdivisions ) );
+       Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
+               Patch_setFixedSubdivisions(patch, subdivisions);
+       });
 }
 
 
@@ -350,19 +341,10 @@ static void OnSelchangeComboColRow( ui::Widget widget, gpointer data ){
        g_PatchInspector.importData();
 }
 
-class PatchSetTextureRepeat
-{
-float m_s, m_t;
-public:
-PatchSetTextureRepeat( float s, float t ) : m_s( s ), m_t( t ){
-}
-void operator()( Patch& patch ) const {
-       patch.SetTextureRepeat( m_s, m_t );
-}
-};
-
 void Scene_PatchTileTexture_Selected( scene::Graph& graph, float s, float t ){
-       Scene_forEachVisibleSelectedPatch( PatchSetTextureRepeat( s, t ) );
+       Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
+               patch.SetTextureRepeat(s, t);
+       });
        SceneChangeNotify();
 }
 
@@ -390,32 +372,12 @@ static void OnBtnPatchFlipY( ui::Widget widget, gpointer data ){
        Patch_FlipTextureY();
 }
 
-struct PatchRotateTexture
-{
-       float m_angle;
-public:
-       PatchRotateTexture( float angle ) : m_angle( angle ){
-       }
-       void operator()( Patch& patch ) const {
-               patch.RotateTexture( m_angle );
-       }
-};
-
 void Scene_PatchRotateTexture_Selected( scene::Graph& graph, float angle ){
-       Scene_forEachVisibleSelectedPatch( PatchRotateTexture( angle ) );
+       Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
+               patch.RotateTexture(angle);
+       });
 }
 
-class PatchScaleTexture
-{
-float m_s, m_t;
-public:
-PatchScaleTexture( float s, float t ) : m_s( s ), m_t( t ){
-}
-void operator()( Patch& patch ) const {
-       patch.ScaleTexture( m_s, m_t );
-}
-};
-
 float Patch_convertScale( float scale ){
        if ( scale > 0 ) {
                return scale;
@@ -427,23 +389,17 @@ float Patch_convertScale( float scale ){
 }
 
 void Scene_PatchScaleTexture_Selected( scene::Graph& graph, float s, float t ){
-       Scene_forEachVisibleSelectedPatch( PatchScaleTexture( Patch_convertScale( s ), Patch_convertScale( t ) ) );
+       s = Patch_convertScale(s);
+       t = Patch_convertScale(t);
+       Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
+               patch.ScaleTexture(s, t);
+       });
 }
 
-class PatchTranslateTexture
-{
-float m_s, m_t;
-public:
-PatchTranslateTexture( float s, float t )
-       : m_s( s ), m_t( t ){
-}
-void operator()( Patch& patch ) const {
-       patch.TranslateTexture( m_s, m_t );
-}
-};
-
 void Scene_PatchTranslateTexture_Selected( scene::Graph& graph, float s, float t ){
-       Scene_forEachVisibleSelectedPatch( PatchTranslateTexture( s, t ) );
+       Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
+               patch.TranslateTexture(s, t);
+       });
 }
 
 static void OnBtnPatchAutoCap( ui::Widget widget, gpointer data ){
index 38c68e51e23d5b90b067e71cddaebece7dd45bdb..4c1336b8fc313d05107b4bc2638d969d1cee2def 100644 (file)
@@ -147,17 +147,6 @@ void Patch_makeCaps( Patch& patch, scene::Instance& instance, EPatchCap type, co
 
 typedef std::vector<scene::Instance*> InstanceVector;
 
-class PatchStoreInstance
-{
-InstanceVector& m_instances;
-public:
-PatchStoreInstance( InstanceVector& instances ) : m_instances( instances ){
-}
-void operator()( PatchInstance& patch ) const {
-       m_instances.push_back( &patch );
-}
-};
-
 enum ECapDialog {
        PATCHCAP_BEVEL = 0,
        PATCHCAP_ENDCAP,
@@ -196,7 +185,9 @@ void Scene_PatchDoCap_Selected( scene::Graph& graph, const char* shader ){
                }
 
                InstanceVector instances;
-               Scene_forEachVisibleSelectedPatchInstance( PatchStoreInstance( instances ) );
+               Scene_forEachVisibleSelectedPatchInstance([&](PatchInstance &patch) {
+                       instances.push_back(&patch);
+               });
                for ( InstanceVector::const_iterator i = instances.begin(); i != instances.end(); ++i )
                {
                        Patch_makeCaps( *Node_getPatch( ( *i )->path().top() ), *( *i ), eType, shader );
@@ -215,132 +206,62 @@ Patch* Scene_GetUltimateSelectedVisiblePatch(){
 }
 
 
-class PatchCapTexture
-{
-public:
-void operator()( Patch& patch ) const {
-       patch.ProjectTexture( Patch::m_CycleCapIndex );
-}
-};
-
 void Scene_PatchCapTexture_Selected( scene::Graph& graph ){
-       Scene_forEachVisibleSelectedPatch( PatchCapTexture() );
+       Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
+               patch.ProjectTexture(Patch::m_CycleCapIndex);
+       });
        Patch::m_CycleCapIndex = ( Patch::m_CycleCapIndex == 0 ) ? 1 : ( Patch::m_CycleCapIndex == 1 ) ? 2 : 0;
        SceneChangeNotify();
 }
 
-class PatchFlipTexture
-{
-int m_axis;
-public:
-PatchFlipTexture( int axis ) : m_axis( axis ){
-}
-void operator()( Patch& patch ) const {
-       patch.FlipTexture( m_axis );
-}
-};
-
 void Scene_PatchFlipTexture_Selected( scene::Graph& graph, int axis ){
-       Scene_forEachVisibleSelectedPatch( PatchFlipTexture( axis ) );
+       Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
+               patch.FlipTexture(axis);
+       });
 }
 
-class PatchNaturalTexture
-{
-public:
-void operator()( Patch& patch ) const {
-       patch.NaturalTexture();
-}
-};
-
 void Scene_PatchNaturalTexture_Selected( scene::Graph& graph ){
-       Scene_forEachVisibleSelectedPatch( PatchNaturalTexture() );
+       Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
+               patch.NaturalTexture();
+       });
        SceneChangeNotify();
 }
 
 
-class PatchInsertRemove
-{
-bool m_insert, m_column, m_first;
-public:
-PatchInsertRemove( bool insert, bool column, bool first ) : m_insert( insert ), m_column( column ), m_first( first ){
-}
-void operator()( Patch& patch ) const {
-       patch.InsertRemove( m_insert, m_column, m_first );
-}
-};
-
 void Scene_PatchInsertRemove_Selected( scene::Graph& graph, bool bInsert, bool bColumn, bool bFirst ){
-       Scene_forEachVisibleSelectedPatch( PatchInsertRemove( bInsert, bColumn, bFirst ) );
+       Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
+               patch.InsertRemove(bInsert, bColumn, bFirst);
+       });
 }
 
-class PatchInvertMatrix
-{
-public:
-void operator()( Patch& patch ) const {
-       patch.InvertMatrix();
-}
-};
-
 void Scene_PatchInvert_Selected( scene::Graph& graph ){
-       Scene_forEachVisibleSelectedPatch( PatchInvertMatrix() );
-}
-
-class PatchRedisperse
-{
-EMatrixMajor m_major;
-public:
-PatchRedisperse( EMatrixMajor major ) : m_major( major ){
-}
-void operator()( Patch& patch ) const {
-       patch.Redisperse( m_major );
+       Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
+               patch.InvertMatrix();
+       });
 }
-};
 
 void Scene_PatchRedisperse_Selected( scene::Graph& graph, EMatrixMajor major ){
-       Scene_forEachVisibleSelectedPatch( PatchRedisperse( major ) );
-}
-
-class PatchSmooth
-{
-EMatrixMajor m_major;
-public:
-PatchSmooth( EMatrixMajor major ) : m_major( major ){
-}
-void operator()( Patch& patch ) const {
-       patch.Smooth( m_major );
+       Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
+               patch.Redisperse(major);
+       });
 }
-};
 
 void Scene_PatchSmooth_Selected( scene::Graph& graph, EMatrixMajor major ){
-       Scene_forEachVisibleSelectedPatch( PatchSmooth( major ) );
+       Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
+               patch.Smooth(major);
+       });
 }
 
-class PatchTransposeMatrix
-{
-public:
-void operator()( Patch& patch ) const {
-       patch.TransposeMatrix();
-}
-};
-
 void Scene_PatchTranspose_Selected( scene::Graph& graph ){
-       Scene_forEachVisibleSelectedPatch( PatchTransposeMatrix() );
+       Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
+               patch.TransposeMatrix();
+       });
 }
 
-class PatchSetShader
-{
-const char* m_name;
-public:
-PatchSetShader( const char* name )
-       : m_name( name ){
-}
-void operator()( Patch& patch ) const {
-       patch.SetShader( m_name );
-}
-};
-
 void Scene_PatchSetShader_Selected( scene::Graph& graph, const char* name ){
-       Scene_forEachVisibleSelectedPatch( PatchSetShader( name ) );
+       Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
+               patch.SetShader(name);
+       });
        SceneChangeNotify();
 }
 
@@ -351,45 +272,29 @@ void Scene_PatchGetShader_Selected( scene::Graph& graph, CopiedString& name ){
        }
 }
 
-class PatchSelectByShader
-{
-const char* m_name;
-public:
-inline PatchSelectByShader( const char* name )
-       : m_name( name ){
-}
-void operator()( PatchInstance& patch ) const {
-       if ( shader_equal( patch.getPatch().GetShader(), m_name ) ) {
-               patch.setSelected( true );
-       }
-}
-};
-
 void Scene_PatchSelectByShader( scene::Graph& graph, const char* name ){
-       Scene_forEachVisiblePatchInstance( PatchSelectByShader( name ) );
+       Scene_forEachVisiblePatchInstance([&](PatchInstance &patch) {
+               if (shader_equal(patch.getPatch().GetShader(), name)) {
+                       patch.setSelected(true);
+               }
+       });
 }
 
 
-class PatchFindReplaceShader
-{
-const char* m_find;
-const char* m_replace;
-public:
-PatchFindReplaceShader( const char* find, const char* replace ) : m_find( find ), m_replace( replace ){
-}
-void operator()( Patch& patch ) const {
-       if ( shader_equal( patch.GetShader(), m_find ) ) {
-               patch.SetShader( m_replace );
-       }
-}
-};
-
 void Scene_PatchFindReplaceShader( scene::Graph& graph, const char* find, const char* replace ){
-       Scene_forEachVisiblePatch( PatchFindReplaceShader( find, replace ) );
+       Scene_forEachVisiblePatch([&](Patch &patch) {
+               if (shader_equal(patch.GetShader(), find)) {
+                       patch.SetShader(replace);
+               }
+       });
 }
 
 void Scene_PatchFindReplaceShader_Selected( scene::Graph& graph, const char* find, const char* replace ){
-       Scene_forEachVisibleSelectedPatch( PatchFindReplaceShader( find, replace ) );
+       Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
+               if (shader_equal(patch.GetShader(), find)) {
+                       patch.SetShader(replace);
+               }
+       });
 }
 
 
index e2886d2d18962e0c7eae3cef9c6b5c6499b3535f..0fee7ef9377e3ef9c83dd36857429de7dcc20bb1 100644 (file)
@@ -334,33 +334,6 @@ ui::Window CGameDialog::BuildDialog(){
        return create_simple_modal_dialog_window( "Global Preferences", m_modal, frame );
 }
 
-class LoadGameFile
-{
-std::list<CGameDescription*>& mGames;
-const char* mPath;
-public:
-LoadGameFile( std::list<CGameDescription*>& games, const char* path ) : mGames( games ), mPath( path ){
-}
-void operator()( const char* name ) const {
-       if ( !extension_equal( path_get_extension( name ), "game" ) ) {
-               return;
-       }
-       StringOutputStream strPath( 256 );
-       strPath << mPath << name;
-       globalOutputStream() << strPath.c_str() << '\n';
-
-       xmlDocPtr pDoc = xmlParseFile( strPath.c_str() );
-       if ( pDoc ) {
-               mGames.push_front( new CGameDescription( pDoc, name ) );
-               xmlFreeDoc( pDoc );
-       }
-       else
-       {
-               globalErrorStream() << "XML parser failed on '" << strPath.c_str() << "'\n";
-       }
-}
-};
-
 void CGameDialog::ScanForGames(){
        StringOutputStream strGamesPath( 256 );
        strGamesPath << AppPath_get() << "games/";
@@ -377,7 +350,22 @@ void CGameDialog::ScanForGames(){
           (if that's really needed)
         */
 
-       Directory_forEach( path, LoadGameFile( mGames, path ) );
+       Directory_forEach(path, [&](const char *name) {
+               if (!extension_equal(path_get_extension(name), "game")) {
+                       return;
+               }
+               StringOutputStream strPath(256);
+               strPath << path << name;
+               globalOutputStream() << strPath.c_str() << '\n';
+
+               xmlDocPtr pDoc = xmlParseFile(strPath.c_str());
+               if (pDoc) {
+                       mGames.push_front(new CGameDescription(pDoc, name));
+                       xmlFreeDoc(pDoc);
+               } else {
+                       globalErrorStream() << "XML parser failed on '" << strPath.c_str() << "'\n";
+               }
+       });
 }
 
 CGameDescription* CGameDialog::GameDescriptionForComboItem(){
index 1f885cff9e16d73c7dd6b7945abb53a2e5be87a1..c1730c333ed31b7134c26733202bbc38b990a5c6 100644 (file)
 #include "instancelib.h"
 #include "treemodel.h"
 
-class StringEqualPredicate
-{
-const char* m_string;
-public:
-StringEqualPredicate( const char* string ) : m_string( string ){
-}
-bool operator()( const char* other ) const {
-       return string_equal( m_string, other );
-}
-};
-
 template<std::size_t SIZE>
 class TypeIdMap
 {
@@ -56,7 +45,9 @@ public:
 TypeIdMap() : m_typeNamesEnd( m_typeNames ){
 }
 TypeId getTypeId( const char* name ){
-       TypeName* i = std::find_if( m_typeNames, m_typeNamesEnd, StringEqualPredicate( name ) );
+       TypeName *i = std::find_if(m_typeNames, m_typeNamesEnd, [&](const char *other) {
+               return string_equal(name, other);
+       });
        if ( i == m_typeNamesEnd ) {
                ASSERT_MESSAGE( m_typeNamesEnd != m_typeNames + SIZE, "reached maximum number of type names supported (" << Unsigned( SIZE ) << ")" );
                *m_typeNamesEnd++ = name;