From: TimePath Date: Sun, 31 Dec 2017 11:06:17 +0000 (+1100) Subject: Embrace lambdas X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fnetradiant.git;a=commitdiff_plain;h=074614f03092ddf3ddaae4d945f4570a4435130d Embrace lambdas --- diff --git a/libs/instancelib.h b/libs/instancelib.h index 913288b6..eeb95e23 100644 --- a/libs/instancelib.h +++ b/libs/instancelib.h @@ -153,21 +153,14 @@ inline void InstanceSet_forEach( InstanceSet& instances, const Functor& functor } } -template -class InstanceEvaluateTransform -{ -public: -inline void operator()( scene::Instance& instance ) const { - InstanceTypeCast::cast( instance )->evaluateTransform(); -} -}; - template class InstanceSetEvaluateTransform { public: static void apply( InstanceSet& instances ){ - InstanceSet_forEach( instances, InstanceEvaluateTransform() ); + InstanceSet_forEach(instances, [&](scene::Instance &instance) { + InstanceTypeCast::cast(instance)->evaluateTransform(); + }); } typedef ReferenceCaller::apply> Caller; }; diff --git a/libs/math/aabb.h b/libs/math/aabb.h index 29e3a38e..917850f5 100644 --- a/libs/math/aabb.h +++ b/libs/math/aabb.h @@ -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 ); diff --git a/plugins/entity/curve.h b/plugins/entity/curve.h index de610de3..cefad32a 100644 --- a/plugins/entity/curve.h +++ b/plugins/entity/curve.h @@ -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() ); } diff --git a/plugins/entity/doom3group.cpp b/plugins/entity/doom3group.cpp index b53017c5..bab1bbe8 100644 --- a/plugins/entity/doom3group.cpp +++ b/plugins/entity/doom3group.cpp @@ -423,17 +423,6 @@ void transformChanged(){ typedef MemberCaller 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; } diff --git a/radiant/brush.h b/radiant/brush.h index 0fb6ffe2..4508591c 100644 --- a/radiant/brush.h +++ b/radiant/brush.h @@ -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 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 { diff --git a/radiant/brushmanip.cpp b/radiant/brushmanip.cpp index 43dc0e73..dd22446a 100644 --- a/radiant/brushmanip.cpp +++ b/radiant/brushmanip.cpp @@ -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; } }; diff --git a/radiant/build.cpp b/radiant/build.cpp index 5207d676..722d46fb 100644 --- a/radiant/build.cpp +++ b/radiant/build.cpp @@ -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 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 ){ diff --git a/radiant/csg.cpp b/radiant/csg.cpp index 2538359f..cc5de460 100644 --- a/radiant/csg.cpp +++ b/radiant/csg.cpp @@ -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 diff --git a/radiant/eclass.cpp b/radiant/eclass.cpp index ea9828e5..90c8a11b 100644 --- a/radiant/eclass.cpp +++ b/radiant/eclass.cpp @@ -175,22 +175,11 @@ struct PathLess typedef std::map 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)); + })); } diff --git a/radiant/mainframe.cpp b/radiant/mainframe.cpp index 05fdc2b7..433767d5 100644 --- a/radiant/mainframe.cpp +++ b/radiant/mainframe.cpp @@ -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( 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 ){ diff --git a/radiant/patchdialog.cpp b/radiant/patchdialog.cpp index 4a358a5e..0b85ea2d 100644 --- a/radiant/patchdialog.cpp +++ b/radiant/patchdialog.cpp @@ -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 ){ diff --git a/radiant/patchmanip.cpp b/radiant/patchmanip.cpp index 38c68e51..4c1336b8 100644 --- a/radiant/patchmanip.cpp +++ b/radiant/patchmanip.cpp @@ -147,17 +147,6 @@ void Patch_makeCaps( Patch& patch, scene::Instance& instance, EPatchCap type, co typedef std::vector 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); + } + }); } diff --git a/radiant/preferences.cpp b/radiant/preferences.cpp index e2886d2d..0fee7ef9 100644 --- a/radiant/preferences.cpp +++ b/radiant/preferences.cpp @@ -334,33 +334,6 @@ ui::Window CGameDialog::BuildDialog(){ return create_simple_modal_dialog_window( "Global Preferences", m_modal, frame ); } -class LoadGameFile -{ -std::list& mGames; -const char* mPath; -public: -LoadGameFile( std::list& 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(){ diff --git a/radiant/scenegraph.cpp b/radiant/scenegraph.cpp index 1f885cff..c1730c33 100644 --- a/radiant/scenegraph.cpp +++ b/radiant/scenegraph.cpp @@ -33,17 +33,6 @@ #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 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;