This is the changelog for developers, != changelog for the end user
that we distribute with the binaries. (see changelog)
+01/04/2006
+SPoG
+- Added key-observer interface to entity module API.
+- Rewrote callback library to add support for return-values.
+- Added minimal API to support bobtoolz plugin.
+- Refactored brush for-each functions to take Functor instead of Visitor.
+- Added signals library.
+
31/03/2006
SPoG
- Changed doom3 light creation to use size of selected brushes.
{853632F4-6420-40C5-B80B-38B678E472B8} = {853632F4-6420-40C5-B80B-38B678E472B8}\r
EndProjectSection\r
EndProject\r
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bobtoolz", "contrib\bobtoolz\bobtoolz.vcproj", "{B20364D1-4329-4D4E-B9CE-C9767618FDD6}"\r
+ ProjectSection(ProjectDependencies) = postProject\r
+ EndProjectSection\r
+EndProject\r
Global\r
GlobalSection(SolutionConfiguration) = preSolution\r
Debug = Debug\r
{B20364D1-4329-4D4E-B9CE-C9767618FDD6}.Debug.Build.0 = Debug|Win32\r
{B20364D1-4329-4D4E-B9CE-C9767618FDD6}.Release.ActiveCfg = Release|Win32\r
{B20364D1-4329-4D4E-B9CE-C9767618FDD6}.Release.Build.0 = Release|Win32\r
+ {B20364D1-4329-4D4E-B9CE-C9767618FDD6}.Debug.ActiveCfg = Debug|Win32\r
+ {B20364D1-4329-4D4E-B9CE-C9767618FDD6}.Debug.Build.0 = Debug|Win32\r
+ {B20364D1-4329-4D4E-B9CE-C9767618FDD6}.Release.ActiveCfg = Release|Win32\r
+ {B20364D1-4329-4D4E-B9CE-C9767618FDD6}.Release.Build.0 = Release|Win32\r
EndGlobalSection\r
GlobalSection(ExtensibilityGlobals) = postSolution\r
EndGlobalSection\r
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "StdAfx.h" // Added by ClassView
-
class CBspPoint {
public:
float p[3];
};
+#define NAME_MAX 255
+
class CPortals {
public:
//
//////////////////////////////////////////////////////////////////////
-#include "StdAfx.h"
#include "DBobView.h"
-#include "DListener.h"
//#include "misc.h"
#include "funchandlers.h"
-#include "gtkr_list.h"
+#include <list>
+
+#include "iglrender.h"
+#include "qerplugin.h"
#include "str.h"
+#include "math/matrix.h"
+#include "DEntity.h"
+#include "DEPair.h"
#include "misc.h"
+#include "dialogs/dialogs-gtk.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
DBobView::DBobView()
{
nPathCount = 0;
- refCount = 1;
- m_bHooked = FALSE;
-
path = NULL;
- eyes = NULL;
boundingShow = BOUNDS_APEX;
+
+ constructShaders();
+ GlobalShaderCache().attachRenderable(*this);
}
DBobView::~DBobView()
{
- if(path)
- delete[] path;
-
- // oops forgot to remove our eyes, was causing access violation when it tried
- // to talk to it's parent
- if(eyes)
- delete eyes;
+ GlobalShaderCache().detachRenderable(*this);
+ destroyShaders();
- if(m_bHooked)
- UnRegister();
+ if(path)
+ delete[] path;
g_PathView = NULL;
}
// Implementation
//////////////////////////////////////////////////////////////////////
-void DBobView::Draw2D(VIEWTYPE vt)
+void DBobView::render(RenderStateFlags state) const
{
- if(!path)
- return;
-
- __QGLTABLENAME.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS);
-
- __QGLTABLENAME.m_pfn_qglDisable(GL_BLEND);
- __QGLTABLENAME.m_pfn_qglEnable(GL_LINE_SMOOTH);
-
- __QGLTABLENAME.m_pfn_qglPushMatrix();
-
- switch(vt)
- {
- case XY:
- break;
- case XZ:
- __QGLTABLENAME.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f);
- break;
- case YZ:
- __QGLTABLENAME.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f);
- __QGLTABLENAME.m_pfn_qglRotatef(270.0f, 0.0f, 0.0f, 1.0f);
- break;
- }
-
- __QGLTABLENAME.m_pfn_qglLineWidth(1.0f);
- __QGLTABLENAME.m_pfn_qglColor4f(1.0f, 0.0f, 0.0f, 1.0f);
-
- int i;
-
- __QGLTABLENAME.m_pfn_qglBegin(GL_LINE_STRIP);
-
- for(i = 0; i < nPathCount; i++)
- __QGLTABLENAME.m_pfn_qglVertex3fv(path[i]);
-
- __QGLTABLENAME.m_pfn_qglEnd();
-
- if(m_bShowExtra)
- {
- // +mars
- // for the bounding box stuff
- __QGLTABLENAME.m_pfn_qglColor4f(0.25f, 0.75f, 0.75f, 1.0f);
+ glBegin(GL_LINE_STRIP);
- __QGLTABLENAME.m_pfn_qglTranslatef( 16.0f, 16.0f, 28.0f );
-
- __QGLTABLENAME.m_pfn_qglBegin( GL_LINE_STRIP );
-
- for ( i = 0; i < nPathCount; i++ )
- __QGLTABLENAME.m_pfn_qglVertex3fv( path[i] );
-
- __QGLTABLENAME.m_pfn_qglEnd();
-
- // ---------------
-
- __QGLTABLENAME.m_pfn_qglTranslatef( -16.0f, -16.0f, -28.0f ); // back to where we were
- __QGLTABLENAME.m_pfn_qglTranslatef( -16.0f, 16.0f, 28.0f ); // move to new postion
-
- __QGLTABLENAME.m_pfn_qglBegin( GL_LINE_STRIP );
-
- for ( i = 0; i < nPathCount; i++ )
- __QGLTABLENAME.m_pfn_qglVertex3fv( path[i] );
-
- __QGLTABLENAME.m_pfn_qglEnd();
-
- // --------------
-
- __QGLTABLENAME.m_pfn_qglTranslatef( 16.0f, -16.0f, -28.0f ); // back to where we were
- __QGLTABLENAME.m_pfn_qglTranslatef( 16.0f, -16.0f, -28.0f ); // new pos
-
- __QGLTABLENAME.m_pfn_qglBegin( GL_LINE_STRIP );
-
- for ( i = 0; i < nPathCount; i++ )
- __QGLTABLENAME.m_pfn_qglVertex3fv( path[i] );
-
- __QGLTABLENAME.m_pfn_qglEnd();
-
- // ----------------
-
- __QGLTABLENAME.m_pfn_qglTranslatef( -16.0f, 16.0f, 28.0f ); // back to where we were
-
-/* __QGLTABLENAME.m_pfn_qglTranslatef( -16.0f, -16.0f, -28.0f ); // new pos
+ for(int i = 0; i < nPathCount; i++)
+ glVertex3fv(path[i]);
- __QGLTABLENAME.m_pfn_qglBegin( GL_LINE_STRIP );
-
- if ( boundingShow == BOUNDS_ALL )
- {
- for ( i = 0; i < nPathCount; i++ )
- __QGLTABLENAME.m_pfn_qglVertex3fv( path[i] );
- }
- else if ( boundingShow == BOUNDS_APEX )
- {
- for ( i = (nPathCount/4); i < (nPathCount/4) * 3; i++ )
- __QGLTABLENAME.m_pfn_qglVertex3fv( path[i] );
- }
+ glEnd();
+}
- __QGLTABLENAME.m_pfn_qglEnd();*/ // djbob: er, um doesn't really seem to do anyhting
- }
+const char* DBobView_state_line = "$bobtoolz/bobview/line";
+const char* DBobView_state_box = "$bobtoolz/bobview/box";
- // -mars
-
- __QGLTABLENAME.m_pfn_qglPopMatrix();
+void DBobView::constructShaders()
+{
+ OpenGLState state;
+ GlobalOpenGLStateLibrary().getDefaultState(state);
+ state.m_state = RENDER_COLOURWRITE|RENDER_DEPTHWRITE|RENDER_BLEND|RENDER_LINESMOOTH;
+ state.m_sort = OpenGLState::eSortOpaque;
+ state.m_linewidth = 1;
+ state.m_colour[0] = 1;
+ state.m_colour[1] = 0;
+ state.m_colour[2] = 0;
+ state.m_colour[3] = 1;
+ GlobalOpenGLStateLibrary().insert(DBobView_state_line, state);
+
+ state.m_colour[0] = 0.25f;
+ state.m_colour[1] = 0.75f;
+ state.m_colour[2] = 0.75f;
+ state.m_colour[3] = 1;
+ GlobalOpenGLStateLibrary().insert(DBobView_state_box, state);
+
+ m_shader_line = GlobalShaderCache().capture(DBobView_state_line);
+ m_shader_box = GlobalShaderCache().capture(DBobView_state_box);
+}
- __QGLTABLENAME.m_pfn_qglPopAttrib();
+void DBobView::destroyShaders()
+{
+ GlobalOpenGLStateLibrary().erase(DBobView_state_line);
+ GlobalOpenGLStateLibrary().erase(DBobView_state_box);
+ GlobalShaderCache().release(DBobView_state_line);
+ GlobalShaderCache().release(DBobView_state_box);
}
-void DBobView::Draw3D()
+Matrix4 g_transform_box1 = matrix4_translation_for_vec3(Vector3(16.0f, 16.0f, 28.0f));
+Matrix4 g_transform_box2 = matrix4_translation_for_vec3(Vector3(-16.0f, 16.0f, 28.0f));
+Matrix4 g_transform_box3 = matrix4_translation_for_vec3(Vector3(16.0f, -16.0f, -28.0f));
+Matrix4 g_transform_box4 = matrix4_translation_for_vec3(Vector3(-16.0f, -16.0f, -28.0f));
+
+void DBobView::renderSolid(Renderer& renderer, const VolumeTest& volume) const
{
if(!path)
return;
- __QGLTABLENAME.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS);
-
- __QGLTABLENAME.m_pfn_qglDisable(GL_BLEND);
- __QGLTABLENAME.m_pfn_qglEnable(GL_LINE_SMOOTH);
-
- __QGLTABLENAME.m_pfn_qglLineWidth(1.0f);
- __QGLTABLENAME.m_pfn_qglColor4f(1.0f, 0.0f, 0.0f, 1.0f);
-
- __QGLTABLENAME.m_pfn_qglBegin(GL_LINE_STRIP);
-
- for(int i = 0; i < nPathCount; i++)
- __QGLTABLENAME.m_pfn_qglVertex3fv(path[i]);
-
- __QGLTABLENAME.m_pfn_qglEnd();
+ renderer.SetState(m_shader_line, eWireframeOnly);
+ renderer.SetState(m_shader_line, eFullMaterials);
+ renderer.addRenderable(*this, g_matrix4_identity);
if(m_bShowExtra)
{
- // +mars
- // ahhh -- a nice C&P job :)
- // for the bounding box stuff
- __QGLTABLENAME.m_pfn_qglColor4f(0.25f, 0.75f, 0.75f, 1.0f);
-
- __QGLTABLENAME.m_pfn_qglTranslatef( 16.0f, 16.0f, 28.0f );
-
- __QGLTABLENAME.m_pfn_qglBegin( GL_LINE_STRIP );
-
- int i;
- for ( i = 0; i < nPathCount; i++ )
- __QGLTABLENAME.m_pfn_qglVertex3fv( path[i] );
-
- __QGLTABLENAME.m_pfn_qglEnd();
-
- // ---------------
-
- __QGLTABLENAME.m_pfn_qglTranslatef( -16.0f, -16.0f, -28.0f ); // back to where we were
- __QGLTABLENAME.m_pfn_qglTranslatef( -16.0f, 16.0f, 28.0f ); // move to new postion
-
- __QGLTABLENAME.m_pfn_qglBegin( GL_LINE_STRIP );
-
- for ( i = 0; i < nPathCount; i++ )
- __QGLTABLENAME.m_pfn_qglVertex3fv( path[i] );
-
- __QGLTABLENAME.m_pfn_qglEnd();
-
- // --------------
-
- __QGLTABLENAME.m_pfn_qglTranslatef( 16.0f, -16.0f, -28.0f ); // back to where we were
- __QGLTABLENAME.m_pfn_qglTranslatef( 16.0f, -16.0f, -28.0f ); // new pos
-
- __QGLTABLENAME.m_pfn_qglBegin( GL_LINE_STRIP );
-
- for ( i = 0; i < nPathCount; i++ )
- __QGLTABLENAME.m_pfn_qglVertex3fv( path[i] );
-
- __QGLTABLENAME.m_pfn_qglEnd();
-
- // ----------------
-
- __QGLTABLENAME.m_pfn_qglTranslatef( -16.0f, 16.0f, 28.0f ); // back to where we were
- __QGLTABLENAME.m_pfn_qglTranslatef( -16.0f, -16.0f, -28.0f ); // new pos
-
- __QGLTABLENAME.m_pfn_qglBegin( GL_LINE_STRIP );
-
- for ( i = 0; i < nPathCount; i++ )
- __QGLTABLENAME.m_pfn_qglVertex3fv( path[i] );
-
- __QGLTABLENAME.m_pfn_qglEnd();
- }
- // -mars
-
- __QGLTABLENAME.m_pfn_qglPopAttrib();
+ renderer.SetState(m_shader_box, eWireframeOnly);
+ renderer.SetState(m_shader_box, eFullMaterials);
+ renderer.addRenderable(*this, g_transform_box1);
+ renderer.addRenderable(*this, g_transform_box2);
+ renderer.addRenderable(*this, g_transform_box3);
+ renderer.addRenderable(*this, g_transform_box4);
+ }
}
-
-void DBobView::Register()
+void DBobView::renderWireframe(Renderer& renderer, const VolumeTest& volume) const
{
- __QGLTABLENAME.m_pfnHookGL2DWindow( this );
- __QGLTABLENAME.m_pfnHookGL3DWindow( this );
- m_bHooked = TRUE;
-}
-
-void DBobView::UnRegister()
-{
- __QGLTABLENAME.m_pfnUnHookGL2DWindow( this );
- __QGLTABLENAME.m_pfnUnHookGL3DWindow( this );
- m_bHooked = FALSE;
+ renderSolid(renderer, volume);
}
void DBobView::SetPath(vec3_t *pPath)
if(apex[2] <= start[2])
{
SetPath(NULL);
- return FALSE;
+ return false;
}
// ----think q3a actually would allow these
//scrub that, coz the plugin wont :]
}
SetPath(pPath);
- return TRUE;
+ return true;
}
void DBobView::Begin(const char* trigger, const char *target, float multiplier, int points, float varGravity, bool bNoUpdate, bool bShowExtra)
nPathCount = points;
m_bShowExtra = bShowExtra;
- Register();
-
- if(UpdatePath())
- {
- if(!bNoUpdate)
- {
- eyes = new DListener;
- eyes->parent = this;
- eyes->Register();
- }
- }
- else
+ if(!UpdatePath())
{
- Sys_ERROR("Initialization Failure in DBobView::Begin");
+ globalErrorStream() << "Initialization Failure in DBobView::Begin";
delete this;
}
}
if(GetEntityCentre(entTarget, apex))
{
CalculateTrajectory(start, apex, fMultiplier, nPathCount, fVarGravity);
- return TRUE;
+ return true;
}
}
- return FALSE;
+ return false;
}
+
+void DBobView_setEntity(Entity& entity, float multiplier, int points, float varGravity, bool bNoUpdate, bool bShowExtra)
+{
+ DEntity trigger;
+ trigger.LoadEPairList(&entity);
+
+ DEPair* trigger_ep = trigger.FindEPairByKey("targetname");
+
+ if(trigger_ep)
+ {
+ if(!strcmp(trigger.m_Classname, "trigger_push"))
+ {
+ DEPair* target_ep = trigger.FindEPairByKey("target");
+ if(target_ep)
+ {
+ scene::Path* entTarget = FindEntityFromTargetname(target_ep->value, NULL);
+ if(entTarget)
+ {
+ if(g_PathView)
+ delete g_PathView;
+ g_PathView = new DBobView;
+
+ Entity* target = Node_getEntity(entTarget->top());
+ if(target != 0)
+ {
+ if(!bNoUpdate)
+ {
+ g_PathView->trigger = &entity;
+ entity.attach(*g_PathView);
+ g_PathView->target = target;
+ target->attach(*g_PathView);
+ }
+ g_PathView->Begin(trigger_ep->value, target_ep->value, multiplier, points, varGravity, bNoUpdate, bShowExtra);
+ }
+ }
+ else
+ DoMessageBox("trigger_push target could not be found.", "Error", eMB_OK);
+ }
+ else
+ DoMessageBox("trigger_push has no target.", "Error", eMB_OK);
+ }
+ else
+ DoMessageBox("You must select a 'trigger_push' entity.", "Error", eMB_OK);
+ }
+ else
+ DoMessageBox("Entity must have a targetname", "Error", eMB_OK);
+}
\ No newline at end of file
#if !defined(AFX_BOBVIEW_H__6E36062A_EF0B_11D4_ACF7_004095A18133__INCLUDED_)
#define AFX_BOBVIEW_H__6E36062A_EF0B_11D4_ACF7_004095A18133__INCLUDED_
+#include "ientity.h"
+#include "irender.h"
+#include "renderable.h"
+#include "mathlib.h"
+
class DListener;
+class Shader;
#define BOUNDS_ALL 0
#define BOUNDS_APEX 1
#pragma once
#endif // _MSC_VER > 1000
-class DBobView :
- public IGL2DWindow,
- public IGL3DWindow
+class DBobView : public Renderable, public OpenGLRenderable, public Entity::Observer
{
+ Shader* m_shader_line;
+ Shader* m_shader_box;
public:
DBobView();
virtual ~DBobView();
protected:
vec3_t* path;
- int refCount;
public:
bool m_bShowExtra;
int boundingShow;
DListener* eyes;
float fVarGravity;
+ float fMultiplier;
+ int nPathCount;
+
+ Entity* trigger;
+ Entity* target;
bool UpdatePath();
char entTarget[256];
bool CalculateTrajectory(vec3_t, vec3_t, float, int, float);
void SetPath(vec3_t* pPath);
- void UnRegister();
- void Register();
- void Draw3D();
- void Draw2D(VIEWTYPE vt);
- void IncRef() { refCount++; }
- void DecRef() { refCount--; if (refCount <= 0) delete this; }
- float fMultiplier;
- bool m_bHooked;
- int nPathCount;
+ void render(RenderStateFlags state) const;
+ void renderSolid(Renderer& renderer, const VolumeTest& volume) const;
+ void renderWireframe(Renderer& renderer, const VolumeTest& volume) const;
+
+ void constructShaders();
+ void destroyShaders();
+
+ void valueChanged(const char* value)
+ {
+ UpdatePath();
+ }
+ typedef MemberCaller1<DBobView, const char*, &DBobView::valueChanged> ValueChangedCaller;
+ void insert(const char* key, EntityKeyValue& value)
+ {
+ value.attach(ValueChangedCaller(*this));
+ }
+ void erase(const char* key, EntityKeyValue& value)
+ {
+ value.detach(ValueChangedCaller(*this));
+ }
+ void clear()
+ {
+ if(trigger != 0)
+ {
+ trigger->detach(*this);
+ target->detach(*this);
+ trigger = 0;
+ target = 0;
+ }
+ }
};
+class Entity;
+void DBobView_setEntity(Entity& entity, float multiplier, int points, float varGravity, bool bNoUpdate, bool bShowExtra);
+
#endif // !defined(AFX_BOBVIEW_H__6E36062A_EF0B_11D4_ACF7_004095A18133__INCLUDED_)
//
//////////////////////////////////////////////////////////////////////
-#include "StdAfx.h"
+#include "DBrush.h"
#ifdef WIN32
#pragma warning(disable : 4786)
#endif
-#include "StdAfx.h"
-
-#include "gtkr_list.h"
+#include <list>
#include "str.h"
#include "DPoint.h"
#include "DPlane.h"
-#include "DBrush.h"
#include "DEPair.h"
#include "DPatch.h"
#include "DEntity.h"
#include "DWinding.h"
-#include "dialogs-gtk.h"
+#include "dialogs/dialogs-gtk.h"
#include "misc.h"
#include "iundo.h"
-#include "refcounted_ptr.h"
+#include "generic/referencecounted.h"
#include "scenelib.h"
DBrush::DBrush(int ID)
{
m_nBrushID = ID;
- bBoundsBuilt = FALSE;
+ bBoundsBuilt = false;
QER_brush = NULL;
}
// Implementation
//////////////////////////////////////////////////////////////////////
-DPlane* DBrush::AddFace(vec3_t va, vec3_t vb, vec3_t vc, _QERFaceData* texData)
+DPlane* DBrush::AddFace(const vec3_t va, const vec3_t vb, const vec3_t vc, const _QERFaceData* texData)
{
#ifdef _DEBUG
// Sys_Printf("(%f %f %f) (%f %f %f) (%f %f %f)\n", va[0], va[1], va[2], vb[0], vb[1], vb[2], vc[0], vc[1], vc[2]);
#endif
- bBoundsBuilt = FALSE;
+ bBoundsBuilt = false;
DPlane* newFace = new DPlane(va, vb, vc, texData);
faceList.push_back(newFace);
if(faceList.size() <= 3) // if less than 3 faces, there can be no points
return 0; // with only 3 faces u can't have a bounded soild
- for(list<DPlane *>::const_iterator p1=faceList.begin(); p1!=faceList.end(); p1++)
+ for(std::list<DPlane *>::const_iterator p1=faceList.begin(); p1!=faceList.end(); p1++)
{
- list<DPlane *>::const_iterator p2=p1;
+ std::list<DPlane *>::const_iterator p2=p1;
for(p2++; p2!=faceList.end(); p2++)
{
- list<DPlane *>::const_iterator p3=p2;
+ std::list<DPlane *>::const_iterator p3=p2;
for(p3++; p3!=faceList.end(); p3++)
{
vec3_t pnt;
if(pos == POINT_IN_BRUSH)
{ // ???? shouldn't happen here
- Sys_Printf("ERROR:: Build Brush Points: Point IN brush!!!\n");
+ globalErrorStream() << "ERROR:: Build Brush Points: Point IN brush!!!\n";
}
else if(pos == POINT_ON_BRUSH)
{ // normal point
return pointList.size();
}
-void DBrush::LoadFromBrush(scene::Node* brush, bool textured)
+void DBrush_addFace(DBrush& brush, const _QERFaceData& faceData)
{
- ClearFaces();
- ClearPoints();
+ brush.AddFace(vector3_to_array(faceData.m_p0), vector3_to_array(faceData.m_p1), vector3_to_array(faceData.m_p2), 0);
+}
+typedef ReferenceCaller1<DBrush, const _QERFaceData&, DBrush_addFace> DBrushAddFaceCaller;
-#if 0
- for(int i = g_FuncTable.m_pfnGetFaceCount(brush)-1; i >= 0 ; i--)
- { // running backwards so i dont have to use the count function each time (OPT)
- _QERFaceData* faceData = g_FuncTable.m_pfnGetFaceData(brush, i);
+void DBrush_addFaceTextured(DBrush& brush, const _QERFaceData& faceData)
+{
+ brush.AddFace(vector3_to_array(faceData.m_p0), vector3_to_array(faceData.m_p1), vector3_to_array(faceData.m_p2), &faceData);
+}
+typedef ReferenceCaller1<DBrush, const _QERFaceData&, DBrush_addFaceTextured> DBrushAddFaceTexturedCaller;
- if(faceData == NULL)
- DoMessageBox("Null pointer returned", "WARNING!", MB_OK);
+void DBrush::LoadFromBrush(scene::Node& brush, bool textured)
+{
+ ClearFaces();
+ ClearPoints();
- if(textured)
- AddFace(faceData->m_v1, faceData->m_v2, faceData->m_v3, faceData);
- else
- AddFace(faceData->m_v1, faceData->m_v2, faceData->m_v3, NULL);
- }
-#endif
+ GlobalBrushCreator().forEachBrushFace(brush, textured ? BrushFaceDataCallback(DBrushAddFaceTexturedCaller(*this)) : BrushFaceDataCallback(DBrushAddFaceCaller(*this)));
- QER_brush = brush;
+ QER_brush = &brush;
}
int DBrush::PointPosition(vec3_t pnt)
{
int state = POINT_IN_BRUSH; // if nothing happens point is inside brush
- for(list<DPlane *>::const_iterator chkPlane=faceList.begin(); chkPlane!=faceList.end(); chkPlane++)
+ for(std::list<DPlane *>::const_iterator chkPlane=faceList.begin(); chkPlane!=faceList.end(); chkPlane++)
{
float dist = (*chkPlane)->DistanceToPoint(pnt);
void DBrush::ClearPoints()
{
- for(list<DPoint *>::const_iterator deadPoint=pointList.begin(); deadPoint!=pointList.end(); deadPoint++) {
+ for(std::list<DPoint *>::const_iterator deadPoint=pointList.begin(); deadPoint!=pointList.end(); deadPoint++) {
delete *deadPoint;
}
pointList.clear();
void DBrush::ClearFaces()
{
- bBoundsBuilt = FALSE;
- for(list<DPlane *>::const_iterator deadPlane=faceList.begin(); deadPlane!=faceList.end(); deadPlane++)
+ bBoundsBuilt = false;
+ for(std::list<DPlane *>::const_iterator deadPlane=faceList.begin(); deadPlane!=faceList.end(); deadPlane++)
{
delete *deadPlane;
}
bool DBrush::HasPoint(vec3_t pnt)
{
- for(list<DPoint *>::const_iterator chkPoint=pointList.begin(); chkPoint!=pointList.end(); chkPoint++)
+ for(std::list<DPoint *>::const_iterator chkPoint=pointList.begin(); chkPoint!=pointList.end(); chkPoint++)
{
if(**chkPoint == pnt)
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
int DBrush::RemoveRedundantPlanes()
{
int cnt = 0;
- list<DPlane *>::iterator chkPlane;
+ std::list<DPlane *>::iterator chkPlane;
// find duplicate planes
- list<DPlane *>::iterator p1=faceList.begin();
+ std::list<DPlane *>::iterator p1=faceList.begin();
while( p1!=faceList.end() )
{
- list<DPlane *>::iterator p2 = p1;
+ std::list<DPlane *>::iterator p2 = p1;
for(p2++; p2!=faceList.end(); p2++)
{
if(**p1 == **p2)
{
- if(!strcmp((*p1)->texInfo.m_texdef.GetName(), "textures/common/caulk"))
+ if(!strcmp((*p1)->m_shader.c_str(), "textures/common/caulk"))
{
delete *p1;
p1 = faceList.erase(p1); // duplicate plane
BuildBounds();
if(!bBoundsBuilt)
- return FALSE;
+ return false;
VectorCopy(bbox_min, min);
VectorCopy(bbox_max, max);
- return TRUE;
+ return true;
}
bool DBrush::BBoxCollision(DBrush* chkBrush)
chkBrush->GetBounds(min2, max2);
if(min1[0] >= max2[0])
- return FALSE;
+ return false;
if(min1[1] >= max2[1])
- return FALSE;
+ return false;
if(min1[2] >= max2[2])
- return FALSE;
+ return false;
if(max1[0] <= min2[0])
- return FALSE;
+ return false;
if(max1[1] <= min2[1])
- return FALSE;
+ return false;
if(max1[2] <= min2[2])
- return FALSE;
+ return false;
- return TRUE;
+ return true;
}
DPlane* DBrush::HasPlane(DPlane* chkPlane)
{
- for(list<DPlane *>::const_iterator brushPlane=faceList.begin(); brushPlane!=faceList.end(); brushPlane++)
+ for(std::list<DPlane *>::const_iterator brushPlane=faceList.begin(); brushPlane!=faceList.end(); brushPlane++)
{
if(**brushPlane == *chkPlane)
return *brushPlane;
if(pointList.size() == 0)
if(BuildPoints() == 0)
- return FALSE;
+ return false;
- list<DPoint *>::const_iterator chkPnt = pointList.begin();
+ std::list<DPoint *>::const_iterator chkPnt = pointList.begin();
if(chkPnt == pointList.end())
- return FALSE;
+ return false;
float dist = cuttingPlane->DistanceToPoint((*chkPnt)->_pnt);
if(dist > MAX_ROUND_ERROR)
- isInFront = FALSE;
+ isInFront = false;
else if(dist < MAX_ROUND_ERROR)
- isInFront = TRUE;
+ isInFront = true;
else
- return TRUE;
+ return true;
for(chkPnt++=pointList.begin(); chkPnt!=pointList.end(); chkPnt++)
{
if(dist > MAX_ROUND_ERROR)
{
if(isInFront)
- return TRUE;
+ return true;
}
else if(dist < MAX_ROUND_ERROR)
{
if(!isInFront)
- return TRUE;
+ return true;
}
else
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
+
scene::Node* DBrush::BuildInRadiant(bool allowDestruction, int* changeCnt, scene::Node* entity)
{
if(allowDestruction)
{
- bool kill = TRUE;
+ bool kill = true;
- for(list<DPlane *>::const_iterator chkPlane=faceList.begin(); chkPlane!=faceList.end(); chkPlane++)
+ for(std::list<DPlane *>::const_iterator chkPlane=faceList.begin(); chkPlane!=faceList.end(); chkPlane++)
{
if((*chkPlane)->m_bChkOk)
{
- kill = FALSE;
+ kill = false;
break;
}
}
//+djbob: fixed bug when brush had no faces "phantom brush" in radiant.
if(faceList.size() < 4)
{
- Sys_Printf("Possible Phantom Brush Found, will not rebuild\n");
+ globalErrorStream() << "Possible Phantom Brush Found, will not rebuild\n";
return NULL;
}
//-djbob
- NodePtr node(Brush_AllocNode());
+ scene::Node& node = GlobalBrushCreator().createBrush();
- for(list<DPlane *>::const_iterator buildPlane=faceList.begin(); buildPlane!=faceList.end(); buildPlane++) {
- if((*buildPlane)->AddToBrush(node->m_brush) && changeCnt) {
+ for(std::list<DPlane *>::const_iterator buildPlane=faceList.begin(); buildPlane!=faceList.end(); buildPlane++) {
+ if((*buildPlane)->AddToBrush(node) && changeCnt) {
(*changeCnt)++;
}
}
if(entity) {
- entity->m_traverse->insert(node);
+ Node_getTraversable(*entity)->insert(node);
} else {
- GetWorldspawn()->m_traverse->insert(node);
+ Node_getTraversable(GlobalRadiant().getMapWorldEntity())->insert(node);
}
- return node;
+ return &node;
}
void DBrush::CutByPlane(DPlane *cutPlane, DBrush **newBrush1, DBrush **newBrush2)
DBrush* b1 = new DBrush;
DBrush* b2 = new DBrush;
- for(list<DPlane *>::const_iterator parsePlane=faceList.begin(); parsePlane!=faceList.end(); parsePlane++)
+ for(std::list<DPlane *>::const_iterator parsePlane=faceList.begin(); parsePlane!=faceList.end(); parsePlane++)
{
b1->AddFace((*parsePlane)->points[0], (*parsePlane)->points[1], (*parsePlane)->points[2], NULL);
b2->AddFace((*parsePlane)->points[0], (*parsePlane)->points[1], (*parsePlane)->points[2], NULL);
{
if(pointList.size() == 0)
if(BuildPoints() == 0)
- return FALSE; // invalid brush!!!!
+ return false; // invalid brush!!!!
if(chkBrush->pointList.size() == 0)
if(chkBrush->BuildPoints() == 0)
- return FALSE; // invalid brush!!!!
+ return false; // invalid brush!!!!
if(!BBoxCollision(chkBrush))
- return FALSE;
+ return false;
- list<DPlane *>::const_iterator iplPlane;
+ std::list<DPlane *>::const_iterator iplPlane;
for( iplPlane=faceList.begin(); iplPlane!=faceList.end(); iplPlane++)
{
- bool allInFront = TRUE;
- for(list<DPoint *>::const_iterator iPoint=chkBrush->pointList.begin(); iPoint!=chkBrush->pointList.end(); iPoint++)
+ bool allInFront = true;
+ for(std::list<DPoint *>::const_iterator iPoint=chkBrush->pointList.begin(); iPoint!=chkBrush->pointList.end(); iPoint++)
{
if((*iplPlane)->DistanceToPoint((*iPoint)->_pnt) < -MAX_ROUND_ERROR)
{
- allInFront = FALSE;
+ allInFront = false;
break;
}
}
if(allInFront)
- return FALSE;
+ return false;
}
for( iplPlane=chkBrush->faceList.begin(); iplPlane!=chkBrush->faceList.end(); iplPlane++)
{
- bool allInFront = TRUE;
- for(list<DPoint *>::const_iterator iPoint=pointList.begin(); iPoint!=pointList.end(); iPoint++)
+ bool allInFront = true;
+ for(std::list<DPoint *>::const_iterator iPoint=pointList.begin(); iPoint!=pointList.end(); iPoint++)
{
if((*iplPlane)->DistanceToPoint((*iPoint)->_pnt) < -MAX_ROUND_ERROR)
{
- allInFront = FALSE;
+ allInFront = false;
break;
}
}
if(allInFront)
- return FALSE;
+ return false;
}
- return TRUE;
+ return true;
}
bool DBrush::IntersectsWith(DPlane* p1, DPlane* p2, vec3_t v) {
vec3_t vDown = { 0, 0, -1 };
- list<DPlane *>::const_iterator iplPlane;
+ std::list<DPlane *>::const_iterator iplPlane;
for( iplPlane = faceList.begin(); iplPlane != faceList.end(); iplPlane++) {
DPlane* p = (*iplPlane);
}
if(p->PlaneIntersection(p1, p2, v)) {
if(PointPosition( v ) != POINT_OUT_BRUSH) {
- return TRUE;
+ return true;
}
}
}
- return FALSE;
+ return false;
}
void DBrush::BuildBounds()
if(BuildPoints() == 0)
return;
- list<DPoint *>::const_iterator first = pointList.begin();
+ std::list<DPoint *>::const_iterator first = pointList.begin();
VectorCopy((*first)->_pnt, bbox_min);
VectorCopy((*first)->_pnt, bbox_max);
- list<DPoint *>::const_iterator point=pointList.begin();
+ std::list<DPoint *>::const_iterator point=pointList.begin();
for( point++; point!=pointList.end(); point++)
{
if((*point)->_pnt[0] > bbox_max[0])
bbox_min[2] = (*point)->_pnt[2];
}
- bBoundsBuilt = TRUE;
+ bBoundsBuilt = true;
}
}
chkBrush->GetBounds(min2, max2);
if((min1[0] - max2[0]) > MAX_ROUND_ERROR)
- return FALSE;
+ return false;
if((min1[1] - max2[1]) > MAX_ROUND_ERROR)
- return FALSE;
+ return false;
if((min1[2] - max2[2]) > MAX_ROUND_ERROR)
- return FALSE;
+ return false;
if((min2[0] - max1[0]) > MAX_ROUND_ERROR)
- return FALSE;
+ return false;
if((min2[1] - max1[1]) > MAX_ROUND_ERROR)
- return FALSE;
+ return false;
if((min2[2] - max1[2]) > MAX_ROUND_ERROR)
- return FALSE;
+ return false;
int cnt = 0;
cnt++;
if(cnt > 1)
- return FALSE;
+ return false;
- return TRUE;
+ return true;
}
-void DBrush::ResetChecks(list<Str>* exclusionList)
+void DBrush::ResetChecks(std::list<Str>* exclusionList)
{
- for(list<DPlane *>::const_iterator resetPlane=faceList.begin(); resetPlane!=faceList.end(); resetPlane++)
+ for(std::list<DPlane *>::const_iterator resetPlane=faceList.begin(); resetPlane!=faceList.end(); resetPlane++)
{
- bool set = FALSE;
+ bool set = false;
if(exclusionList)
{
- for(list<Str>::iterator eTexture = exclusionList->begin(); eTexture != exclusionList->end(); eTexture++)
+ for(std::list<Str>::iterator eTexture = exclusionList->begin(); eTexture != exclusionList->end(); eTexture++)
{
- if(strstr((*resetPlane)->texInfo.m_texdef.GetName(), eTexture->GetBuffer()))
+ if(strstr((*resetPlane)->m_shader.c_str(), eTexture->GetBuffer()))
{
- set = TRUE;
+ set = true;
break;
}
}
DPlane* DBrush::HasPlaneInverted(DPlane *chkPlane)
{
- for(list<DPlane *>::const_iterator brushPlane=faceList.begin(); brushPlane!=faceList.end(); brushPlane++)
+ for(std::list<DPlane *>::const_iterator brushPlane=faceList.begin(); brushPlane!=faceList.end(); brushPlane++)
{
if(**brushPlane != *chkPlane)
{
bool DBrush::HasTexture(const char *textureName)
{
- for(list<DPlane *>::const_iterator chkPlane=faceList.begin(); chkPlane!=faceList.end(); chkPlane++)
+ for(std::list<DPlane *>::const_iterator chkPlane=faceList.begin(); chkPlane!=faceList.end(); chkPlane++)
{
- if(strstr((*chkPlane)->texInfo.m_texdef.GetName(), textureName))
- return TRUE;
+ if(strstr((*chkPlane)->m_shader.c_str(), textureName))
+ return true;
}
- return FALSE;
+ return false;
}
bool DBrush::IsDetail()
{
- for(list<DPlane *>::const_iterator chkPlane=faceList.begin(); chkPlane!=faceList.end(); chkPlane++)
+ for(std::list<DPlane *>::const_iterator chkPlane=faceList.begin(); chkPlane!=faceList.end(); chkPlane++)
{
- if((*chkPlane)->texInfo.m_texdef.contents & FACE_DETAIL)
- return TRUE;
+ if((*chkPlane)->texInfo.contents & FACE_DETAIL)
+ return true;
}
- return FALSE;
+ return false;
}
void DBrush::BuildFromWinding(DWinding *w)
{
if(w->numpoints < 3)
{
- Sys_ERROR("Winding has invalid number of points");
+ globalErrorStream() << "Winding has invalid number of points";
return;
}
{
fprintf(pFile, "{\n");
- for(list<DPlane *>::const_iterator pp=faceList.begin(); pp!=faceList.end(); pp++)
+ for(std::list<DPlane *>::const_iterator pp=faceList.begin(); pp!=faceList.end(); pp++)
{
char buffer[512];
(*pp)->points[0][0], (*pp)->points[0][1], (*pp)->points[0][2],
(*pp)->points[1][0], (*pp)->points[1][1], (*pp)->points[1][2],
(*pp)->points[2][0], (*pp)->points[2][1], (*pp)->points[2][2],
- (*pp)->texInfo.m_texdef.GetName(),
+ (*pp)->m_shader.c_str(),
(*pp)->texInfo.m_texdef.shift[0], (*pp)->texInfo.m_texdef.shift[1],
(*pp)->texInfo.m_texdef.scale[0], (*pp)->texInfo.m_texdef.scale[0],
(*pp)->texInfo.m_texdef.rotate);
void DBrush::Rotate(vec3_t vOrigin, vec3_t vRotation)
{
- for(list<DPlane *>::const_iterator rotPlane=faceList.begin(); rotPlane!=faceList.end(); rotPlane++)
+ for(std::list<DPlane *>::const_iterator rotPlane=faceList.begin(); rotPlane!=faceList.end(); rotPlane++)
{
for(int i = 0; i < 3; i++)
VectorRotate((*rotPlane)->points[i], vRotation, vOrigin);
{
if(textureName)
{
- bool changed = FALSE;
- for(list<DPlane *>::const_iterator resetPlane=faceList.begin(); resetPlane!=faceList.end(); resetPlane++)
+ bool changed = false;
+ for(std::list<DPlane *>::const_iterator resetPlane=faceList.begin(); resetPlane!=faceList.end(); resetPlane++)
{
- if(!strcmp((*resetPlane)->texInfo.m_texdef.GetName(), textureName))
+ if(!strcmp((*resetPlane)->m_shader.c_str(), textureName))
{
if(bResetTextureName)
- (*resetPlane)->texInfo.m_texdef.SetName(newTextureName);
+ (*resetPlane)->m_shader = newTextureName;
if(bResetScale[0])
(*resetPlane)->texInfo.m_texdef.scale[0] = fScale[0];
if(bResetRotation)
(*resetPlane)->texInfo.m_texdef.rotate = (float)rotation;
- changed = TRUE;
+ changed = true;
}
}
return changed; // no point rebuilding unless we need to, only slows things down
}
else
{
- for(list<DPlane *>::const_iterator resetPlane=faceList.begin(); resetPlane!=faceList.end(); resetPlane++)
+ for(std::list<DPlane *>::const_iterator resetPlane=faceList.begin(); resetPlane!=faceList.end(); resetPlane++)
{
if(bResetTextureName)
- (*resetPlane)->texInfo.m_texdef.SetName(newTextureName);
+ (*resetPlane)->m_shader = newTextureName;
if(bResetScale[0])
(*resetPlane)->texInfo.m_texdef.scale[0] = fScale[0];
if(bResetRotation)
(*resetPlane)->texInfo.m_texdef.rotate = (float)rotation;
}
- return TRUE;
+ return true;
}
}
bool DBrush::operator ==(DBrush* other)
{
- list<DPlane *>::const_iterator chkPlane;
+ std::list<DPlane *>::const_iterator chkPlane;
for(chkPlane=faceList.begin(); chkPlane!=faceList.end(); chkPlane++)
{
if(!other->HasPlane((*chkPlane)))
- return FALSE;
+ return false;
}
for(chkPlane=faceList.begin(); chkPlane!=faceList.end(); chkPlane++)
{
if(!HasPlane((*chkPlane)))
- return FALSE;
+ return false;
}
- return TRUE;
+ return true;
}
-DPlane* DBrush::AddFace(vec3_t va, vec3_t vb, vec3_t vc, const char *textureName, bool bDetail)
+DPlane* DBrush::AddFace(const vec3_t va, const vec3_t vb, const vec3_t vc, const char *textureName, bool bDetail)
{
- bBoundsBuilt = FALSE;
+ bBoundsBuilt = false;
DPlane* newFace = new DPlane(va, vb, vc, textureName, bDetail);
faceList.push_back(newFace);
DPlane* DBrush::FindPlaneWithClosestNormal( vec_t* normal ) {
vec_t bestDot = -2;
DPlane* bestDotPlane = NULL;
- list<DPlane *>::const_iterator chkPlane;
+ std::list<DPlane *>::const_iterator chkPlane;
for( chkPlane = faceList.begin(); chkPlane != faceList.end(); chkPlane++ ) {
DPlane* pPlane = (*chkPlane);
BuildPoints();
- for( list<DPoint *>::const_iterator points = pointList.begin(); points != pointList.end(); points++ ) {
+ for( std::list<DPoint *>::const_iterator points = pointList.begin(); points != pointList.end(); points++ ) {
DPoint* point = (*points);
if( fabs(plane->DistanceToPoint( point->_pnt )) < MAX_ROUND_ERROR ) {
}
void DBrush::RemovePlane( DPlane* plane ) {
- bBoundsBuilt = FALSE;
- for( list<DPlane *>::const_iterator deadPlane = faceList.begin(); deadPlane != faceList.end(); deadPlane++ ) {
+ bBoundsBuilt = false;
+ for( std::list<DPlane *>::const_iterator deadPlane = faceList.begin(); deadPlane != faceList.end(); deadPlane++ ) {
if(*deadPlane == plane) {
delete *deadPlane;
faceList.remove( plane );
}
}
}
-
-void DBrush::RemoveFromRadiant( void ) {
- if(QER_brush) {
-#if 0
- g_FuncTable.m_pfnDeleteBrushHandle(QER_brush);
-#endif
- }
-}
#pragma once
#endif // _MSC_VER > 1000
+#include <stdio.h>
+#include <list>
+#include "mathlib.h"
+#include "str.h"
+
+class DPlane;
+class DWinding;
+class DPoint;
+class _QERFaceData;
+
+namespace scene
+{
+ class Node;
+}
+
#define POINT_IN_BRUSH 0
#define POINT_ON_BRUSH 1
#define POINT_OUT_BRUSH 2
class DBrush
{
public:
- DPlane* AddFace(vec3_t va, vec3_t vb, vec3_t vc, const char* textureName, bool bDetail);
+ DPlane* AddFace(const vec3_t va, const vec3_t vb, const vec3_t vc, const char* textureName, bool bDetail);
void SaveToFile(FILE* pFile);
void Rotate(vec3_t vOrigin, vec3_t vRotation);
DPlane* HasPlaneInverted(DPlane* chkPlane);
DPlane* HasPlane(DPlane* chkPlane);
- DPlane* AddFace(vec3_t va, vec3_t vb, vec3_t vc, _QERFaceData* texData);
+ DPlane* AddFace(const vec3_t va, const vec3_t vb, const vec3_t vc, const _QERFaceData* texData);
bool ResetTextures(const char* textureName, float fScale[2], float fShift[2], int rotation, const char* newTextureName, int bResetTextureName, int bResetScale[2], int bResetShift[2], int bResetRotation);
bool IsDetail();
void BuildFromWinding(DWinding* w);
scene::Node* BuildInRadiant(bool allowDestruction, int* changeCnt, scene::Node* entity = NULL);
- void ResetChecks(list<Str>* exclusionList);
+ void ResetChecks(std::list<Str>* exclusionList);
void ClearFaces();
void ClearPoints();
int RemoveRedundantPlanes( void );
void RemovePlane( DPlane* plane );
int PointPosition(vec3_t pnt);
- void RemoveFromRadiant( void );
void CutByPlane(DPlane* cutPlane, DBrush** newBrush1, DBrush** newBrush2);
- void LoadFromBrush(scene::Node* brush, bool textured);
+ void LoadFromBrush(scene::Node& brush, bool textured);
void AddPoint(vec3_t pnt);
DPlane* FindPlaneWithClosestNormal( vec_t* normal );
// members
scene::Node* QER_brush;
- list<DPlane*> faceList;
- list<DPoint*> pointList;
+ std::list<DPlane*> faceList;
+ std::list<DPoint*> pointList;
int m_nBrushID;
vec3_t bbox_min, bbox_max;
bool bBoundsBuilt;
//
//////////////////////////////////////////////////////////////////////
-#include "StdAfx.h"
-#include "str.h"
#include "DEPair.h"
//////////////////////////////////////////////////////////////////////
#pragma once
#endif // _MSC_VER > 1000
+#include "str.h"
+
class DEPair
{
public:
//
//////////////////////////////////////////////////////////////////////
+#include "DEntity.h"
+
#ifdef WIN32
#pragma warning(disable : 4786)
#endif
-#include "StdAfx.h"
-
-#include "gtkr_list.h"
+#include <list>
#include "str.h"
#include "DPoint.h"
#include "DBrush.h"
#include "DEPair.h"
#include "DPatch.h"
-#include "DEntity.h"
-#include "dialogs-gtk.h"
+#include "dialogs/dialogs-gtk.h"
#include "misc.h"
#include "CPortals.h"
#include "iundo.h"
+#include "ientity.h"
+#include "ieclass.h"
-#include "refcounted_ptr.h"
+#include "generic/referencecounted.h"
#include <vector>
#include <list>
void DEntity::ClearBrushes()
{
- for(list<DBrush *>::const_iterator deadBrush=brushList.begin(); deadBrush!=brushList.end(); deadBrush++)
+ for(std::list<DBrush *>::const_iterator deadBrush=brushList.begin(); deadBrush!=brushList.end(); deadBrush++)
{
delete *deadBrush;
}
void DEntity::ClearPatches()
{
- for(list<DPatch *>::const_iterator deadPatch=patchList.begin(); deadPatch!=patchList.end(); deadPatch++)
+ for(std::list<DPatch *>::const_iterator deadPatch=patchList.begin(); deadPatch!=patchList.end(); deadPatch++)
{
delete *deadPatch;
}
portals.Load();
if(portals.node_count == 0)
- return FALSE;
+ return false;
ClearBrushes();
ClearEPairs();
}
if(!build)
- brush->AddFace(portals.node[i].portal[j].point[2].p, portals.node[i].portal[j].point[1].p, portals.node[i].portal[j].point[0].p, "textures/common/caulk", FALSE);
+ brush->AddFace(portals.node[i].portal[j].point[2].p, portals.node[i].portal[j].point[1].p, portals.node[i].portal[j].point[0].p, "textures/common/caulk", false);
else
- brush->AddFace(portals.node[i].portal[j].point[0].p, portals.node[i].portal[j].point[1].p, portals.node[i].portal[j].point[2].p, "textures/common/caulk", FALSE);
+ brush->AddFace(portals.node[i].portal[j].point[0].p, portals.node[i].portal[j].point[1].p, portals.node[i].portal[j].point[2].p, "textures/common/caulk", false);
}
if(build)
- brush->BuildInRadiant(FALSE, NULL);
+ brush->BuildInRadiant(false, NULL);
}
- return TRUE;
+ return true;
}
DPlane* DEntity::AddFaceToBrush(vec3_t va, vec3_t vb, vec3_t vc, _QERFaceData* faceData, int ID)
{
DBrush* buildBrush = NULL;
- for(list<DBrush *>::const_iterator chkBrush=brushList.begin(); chkBrush!=brushList.end(); chkBrush++)
+ for(std::list<DBrush *>::const_iterator chkBrush=brushList.begin(); chkBrush!=brushList.end(); chkBrush++)
{
if((*chkBrush)->m_nBrushID == ID)
{
return buildBrush;
}
+template<typename Functor>
+class BrushSelectedVisitor : public SelectionSystem::Visitor
+{
+ const Functor& m_functor;
+public:
+ BrushSelectedVisitor(const Functor& functor) : m_functor(functor)
+ {
+ }
+ void visit(scene::Instance& instance) const
+ {
+ if(Node_isBrush(instance.path().top()))
+ {
+ m_functor(*instance.path().top());
+ }
+ }
+};
+
+template<typename Functor>
+inline const Functor& Scene_forEachSelectedBrush(const Functor& functor)
+{
+ GlobalSelectionSystem().foreachSelected(BrushSelectedVisitor<Functor>(functor));
+ return functor;
+}
+
+void DEntity_loadBrush(DEntity& entity, scene::Node& brush)
+{
+ DBrush* loadBrush = entity.NewBrush(entity.brushList.size());
+ loadBrush->LoadFromBrush(brush, true);
+}
+typedef ReferenceCaller1<DEntity, scene::Node&, DEntity_loadBrush> DEntityLoadBrushCaller;
+
void DEntity::LoadSelectedBrushes()
{
ClearBrushes();
ClearEPairs();
-#if 0
- int count = g_FuncTable.m_pfnAllocateSelectedBrushHandles();
-
- for(int i = 0; i < count; i++) {
- brush_t *brush = (brush_t*)g_FuncTable.m_pfnGetSelectedBrushHandle(i);
+ Scene_forEachSelectedBrush(DEntityLoadBrushCaller(*this));
+}
- if(brush->patchBrush)
- continue;
+template<typename Functor>
+class PatchSelectedVisitor : public SelectionSystem::Visitor
+{
+ const Functor& m_functor;
+public:
+ PatchSelectedVisitor(const Functor& functor) : m_functor(functor)
+ {
+ }
+ void visit(scene::Instance& instance) const
+ {
+ if(Node_isPatch(instance.path().top()))
+ {
+ m_functor(*instance.path().top());
+ }
+ }
+};
- DBrush* loadBrush = NewBrush(i);
- loadBrush->LoadFromBrush_t(brush, TRUE);
- }
+template<typename Functor>
+inline const Functor& Scene_forEachSelectedPatch(const Functor& functor)
+{
+ GlobalSelectionSystem().foreachSelected(PatchSelectedVisitor<Functor>(functor));
+ return functor;
+}
- g_FuncTable.m_pfnReleaseSelectedBrushHandles();
-#endif
+void DEntity_loadPatch(DEntity& entity, scene::Node& patch)
+{
+ DPatch* loadPatch = entity.NewPatch();
+ loadPatch->LoadFromBrush(patch);
}
+typedef ReferenceCaller1<DEntity, scene::Node&, DEntity_loadPatch> DEntityLoadPatchCaller;
void DEntity::LoadSelectedPatches()
{
ClearPatches();
ClearEPairs();
-#if 0
- int count = g_FuncTable.m_pfnAllocateSelectedPatchHandles();
-
- for(int i = 0; i < count; i++)
- {
- //$ FIXME: m_pfnGetPatchHandle
- patchMesh_t *pmesh = (patchMesh_t*)g_FuncTable.m_pfnGetPatchData(i);
-
- DPatch* loadPatch = NewPatch();
- loadPatch->LoadFromBrush_t(pmesh->pSymbiot);
- }
-
- g_FuncTable.m_pfnReleasePatchHandles();
-#endif
+ Scene_forEachSelectedPatch(DEntityLoadPatchCaller(*this));
}
bool* DEntity::BuildIntersectList()
bool* pbIntList = new bool[max];
memset(pbIntList, 0, sizeof(bool)*(max));
- for(list<DBrush *>::const_iterator pB1=brushList.begin(); pB1!=brushList.end(); pB1++)
+ for(std::list<DBrush *>::const_iterator pB1=brushList.begin(); pB1!=brushList.end(); pB1++)
{
- list<DBrush *>::const_iterator pB2=pB1;
+ std::list<DBrush *>::const_iterator pB2=pB1;
for(pB2++; pB2!=brushList.end(); pB2++)
{
if((*pB1)->IntersectsWith((*pB2)))
{
- pbIntList[(*pB1)->m_nBrushID] = TRUE;
- pbIntList[(*pB2)->m_nBrushID] = TRUE;
+ pbIntList[(*pB1)->m_nBrushID] = true;
+ pbIntList[(*pB2)->m_nBrushID] = true;
}
}
}
bool* pbDupList = new bool[max];
memset(pbDupList, 0, sizeof(bool)*(max));
- for(list<DBrush *>::const_iterator pB1=brushList.begin(); pB1!=brushList.end(); pB1++)
+ for(std::list<DBrush *>::const_iterator pB1=brushList.begin(); pB1!=brushList.end(); pB1++)
{
- list<DBrush *>::const_iterator pB2=pB1;
+ std::list<DBrush *>::const_iterator pB2=pB1;
for(pB2++; pB2!=brushList.end(); pB2++)
{
if(**pB1 == *pB2)
{
- pbDupList[(*pB1)->m_nBrushID] = TRUE;
- pbDupList[(*pB2)->m_nBrushID] = TRUE;
+ pbDupList[(*pB1)->m_nBrushID] = true;
+ pbDupList[(*pB2)->m_nBrushID] = true;
}
}
}
if(selectList == NULL)
return;
- GlobalSelectionSystem().Select(false);
+ GlobalSelectionSystem().setSelectedAll(false);
- scene::Path path(GlobalSceneGraph().root());
- path.push(QER_Entity);
+ scene::Path path(NodeReference(GlobalSceneGraph().root()));
+ path.push(NodeReference(*QER_Entity));
for(std::list<DBrush *>::const_iterator pBrush=brushList.begin(); pBrush!=brushList.end(); pBrush++)
{
if(selectList[(*pBrush)->m_nBrushID])
{
- path.push((*pBrush)->QER_brush);
- GlobalSceneGraph().find(path)->selectable()->select(true);
+ path.push(NodeReference(*(*pBrush)->QER_brush));
+ Instance_getSelectable(*GlobalSceneGraph().find(path))->setSelected(true);
path.pop();
}
}
}
-bool DEntity::LoadFromEntity(scene::Node* ent, bool bLoadPatches) {
+bool DEntity::LoadFromEntity(scene::Node& ent, bool bLoadPatches) {
ClearPatches();
ClearBrushes();
ClearEPairs();
- QER_Entity = ent;
+ QER_Entity = &ent;
- LoadEPairList(ent->m_entity);
+ LoadEPairList(Node_getEntity(ent));
- bool keep = FALSE;
+ bool keep = false;
int i;
for(i = 0; brushEntityList[i]; i++)
{
- if(!stricmp(brushEntityList[i], m_Classname))
+ if(string_equal_nocase(brushEntityList[i], m_Classname))
{
- keep = TRUE;
+ keep = true;
break;
}
}
if(!keep)
- return FALSE;
+ return false;
- if(ent->m_traverse)
+ if(Node_getTraversable(ent))
{
class load_brushes_t : public scene::Traversable::Walker
{
DEntity* m_entity;
- int m_count;
+ mutable int m_count;
public:
load_brushes_t(DEntity* entity)
: m_entity(entity), m_count(0)
{
}
- bool pre(scene::Node* node)
+ bool pre(scene::Node& node) const
{
- if(node->m_brush)
+ if(Node_isPatch(node))
{
DPatch* loadPatch = m_entity->NewPatch();
loadPatch->LoadFromBrush(node);
}
- else if(node->m_patch)
+ else if(Node_isBrush(node))
{
DBrush* loadBrush = m_entity->NewBrush(m_count++);
- loadBrush->LoadFromBrush(node, TRUE);
+ loadBrush->LoadFromBrush(node, true);
}
return false;
}
- void post(scene::Node* node)
- {
- }
} load_brushes(this);
- ent->m_traverse->traverse(load_brushes);
+ Node_getTraversable(ent)->traverse(load_brushes);
}
- return TRUE;
+ return true;
}
-void DEntity::RemoveNonCheckBrushes(list<Str>* exclusionList, bool useDetail)
+void DEntity::RemoveNonCheckBrushes(std::list<Str>* exclusionList, bool useDetail)
{
- list<DBrush *>::iterator chkBrush=brushList.begin();
+ std::list<DBrush *>::iterator chkBrush=brushList.begin();
while( chkBrush!=brushList.end() )
{
}
}
- list<Str>::iterator eTexture;
+ std::list<Str>::iterator eTexture;
for( eTexture=exclusionList->begin(); eTexture!=exclusionList->end(); eTexture++ )
{
}
}
-void DEntity::ResetChecks(list<Str>* exclusionList)
+void DEntity::ResetChecks(std::list<Str>* exclusionList)
{
- for(list<DBrush *>::const_iterator resetBrush=brushList.begin(); resetBrush!=brushList.end(); resetBrush++)
+ for(std::list<DBrush *>::const_iterator resetBrush=brushList.begin(); resetBrush!=brushList.end(); resetBrush++)
{
(*resetBrush)->ResetChecks(exclusionList);
}
{
int count = 0;
- for(list<DBrush *>::const_iterator fixBrush=brushList.begin(); fixBrush!=brushList.end(); fixBrush++)
+ for(std::list<DBrush *>::const_iterator fixBrush=brushList.begin(); fixBrush!=brushList.end(); fixBrush++)
{
count += (*fixBrush)->RemoveRedundantPlanes();
}
if(makeEntity)
{
- NodePtr node(GlobalEntityCreator().createEntity(m_Classname.GetBuffer()));
+ NodeReference node(GlobalEntityCreator().createEntity(GlobalEntityClassManager().findOrInsert(m_Classname.GetBuffer(), !brushList.empty() || !patchList.empty())));
- for(list<DEPair* >::const_iterator buildEPair=epairList.begin(); buildEPair!=epairList.end(); buildEPair++)
+ for(std::list<DEPair* >::const_iterator buildEPair=epairList.begin(); buildEPair!=epairList.end(); buildEPair++)
{
- node->m_entity->setkeyvalue((*buildEPair)->key, (*buildEPair)->value);
+ Node_getEntity(node)->setKeyValue((*buildEPair)->key, (*buildEPair)->value);
}
- GlobalSceneGraph().root()->m_traverse->insert(node);
+ Node_getTraversable(GlobalSceneGraph().root())->insert(node);
- for(list<DBrush *>::const_iterator buildBrush=brushList.begin(); buildBrush!=brushList.end(); buildBrush++)
- (*buildBrush)->BuildInRadiant(allowDestruction, NULL, node);
+ for(std::list<DBrush *>::const_iterator buildBrush=brushList.begin(); buildBrush!=brushList.end(); buildBrush++)
+ (*buildBrush)->BuildInRadiant(allowDestruction, NULL, node.get_pointer());
- for(list<DPatch *>::const_iterator buildPatch=patchList.begin(); buildPatch!=patchList.end(); buildPatch++)
- (*buildPatch)->BuildInRadiant(node);
+ for(std::list<DPatch *>::const_iterator buildPatch=patchList.begin(); buildPatch!=patchList.end(); buildPatch++)
+ (*buildPatch)->BuildInRadiant(node.get_pointer());
- QER_Entity = node;
+ QER_Entity = node.get_pointer();
}
else
{
- for(list<DBrush *>::const_iterator buildBrush=brushList.begin(); buildBrush!=brushList.end(); buildBrush++)
+ for(std::list<DBrush *>::const_iterator buildBrush=brushList.begin(); buildBrush!=brushList.end(); buildBrush++)
(*buildBrush)->BuildInRadiant(allowDestruction, NULL);
- for(list<DPatch *>::const_iterator buildPatch=patchList.begin(); buildPatch!=patchList.end(); buildPatch++)
+ for(std::list<DPatch *>::const_iterator buildPatch=patchList.begin(); buildPatch!=patchList.end(); buildPatch++)
(*buildPatch)->BuildInRadiant();
}
}
int DEntity::GetIDMax( void ) {
int max = -1;
- for(list<DBrush *>::const_iterator cntBrush=brushList.begin(); cntBrush!=brushList.end(); cntBrush++) {
+ for(std::list<DBrush *>::const_iterator cntBrush=brushList.begin(); cntBrush!=brushList.end(); cntBrush++) {
if((*cntBrush)->m_nBrushID > max)
max = (*cntBrush)->m_nBrushID;
}
fprintf(pFile, "\"classname\" \"%s\"\n", (const char *)m_Classname);
- for(list<DEPair *>::const_iterator ep=epairList.begin(); ep!=epairList.end(); ep++)
+ for(std::list<DEPair *>::const_iterator ep=epairList.begin(); ep!=epairList.end(); ep++)
{
fprintf(pFile, "\"%s\" \"%s\"\n", (const char *)(*ep)->key, (const char *)(*ep)->value);
}
- for(list<DBrush *>::const_iterator bp=brushList.begin(); bp!=brushList.end(); bp++)
+ for(std::list<DBrush *>::const_iterator bp=brushList.begin(); bp!=brushList.end(); bp++)
{
(*bp)->SaveToFile(pFile);
}
void DEntity::ClearEPairs()
{
- for(list<DEPair *>::const_iterator deadEPair=epairList.begin(); deadEPair!=epairList.end(); deadEPair++)
+ for(std::list<DEPair *>::const_iterator deadEPair=epairList.begin(); deadEPair!=epairList.end(); deadEPair++)
{
delete (*deadEPair);
}
} load_epairs(this);
- epl->accept(load_epairs);
+ epl->forEachKeyValue(load_epairs);
}
bool DEntity::ResetTextures(const char* textureName, float fScale[2], float fShift[2], int rotation, const char* newTextureName,
int bResetTextureName, int bResetScale[2], int bResetShift[2], int bResetRotation, bool rebuild)
{
- bool reset = FALSE;
+ bool reset = false;
- for(list<DBrush *>::const_iterator resetBrush=brushList.begin(); resetBrush!=brushList.end(); resetBrush++)
+ for(std::list<DBrush *>::const_iterator resetBrush=brushList.begin(); resetBrush!=brushList.end(); resetBrush++)
{
bool tmp = (*resetBrush)->ResetTextures(textureName, fScale, fShift, rotation, newTextureName,
bResetTextureName, bResetScale, bResetShift, bResetRotation);
if(tmp)
{
- reset = TRUE;
+ reset = true;
}
}
if(bResetTextureName)
{
- for(list<DPatch *>::const_iterator resetPatch=patchList.begin(); resetPatch!=patchList.end(); resetPatch++)
+ for(std::list<DPatch *>::const_iterator resetPatch=patchList.begin(); resetPatch!=patchList.end(); resetPatch++)
{
bool tmp = (*resetPatch)->ResetTextures(textureName, newTextureName);
if(tmp)
{
- reset = TRUE;
+ reset = true;
}
}
}
DEPair* DEntity::FindEPairByKey(const char* keyname)
{
- for(list<DEPair *>::const_iterator ep=epairList.begin(); ep!=epairList.end(); ep++)
+ for(std::list<DEPair *>::const_iterator ep=epairList.begin(); ep!=epairList.end(); ep++)
{
char* c = (*ep)->key;
if(!strcmp(c, keyname))
void DEntity::RemoveFromRadiant()
{
- GlobalSceneGraph().root()->m_traverse->erase(QER_Entity);
+ Node_getTraversable(GlobalSceneGraph().root())->erase(*QER_Entity);
QER_Entity = NULL;
}
return brushList.size();
}
-DBrush* DEntity::FindBrushByPointer( scene::Node* brush ) {
- for(list<DBrush *>::const_iterator listBrush = brushList.begin(); listBrush != brushList.end(); listBrush++) {
+DBrush* DEntity::FindBrushByPointer( scene::Node& brush ) {
+ for(std::list<DBrush *>::const_iterator listBrush = brushList.begin(); listBrush != brushList.end(); listBrush++) {
DBrush* pBrush = (*listBrush);
- if(pBrush->QER_brush == brush) {
+ if(pBrush->QER_brush == &brush) {
return pBrush;
}
}
#pragma once
#endif // _MSC_VER > 1000
+#include <list>
+#include "str.h"
+#include "mathlib.h"
+
+class DEPair;
+class DBrush;
+class DPlane;
+class DPatch;
+class Entity;
+
+namespace scene
+{
+ class Node;
+}
+class _QERFaceData;
+
class DEntity
{
public:
int GetIDMax();
void BuildInRadiant(bool allowDestruction);
- void ResetChecks(list<Str>* exclusionList);
- void RemoveNonCheckBrushes(list<Str>* exclusionList, bool useDetail);
+ void ResetChecks(std::list<Str>* exclusionList);
+ void RemoveNonCheckBrushes(std::list<Str>* exclusionList, bool useDetail);
DPlane* AddFaceToBrush(vec3_t va, vec3_t vb, vec3_t vc, _QERFaceData* faceData, int ID); // slow, try not to use much
int GetBrushCount( void );
- DBrush* FindBrushByPointer( scene::Node* brush );
+ DBrush* FindBrushByPointer( scene::Node& brush );
// ---------------------------------------------
// ---------------------------------------------
// vars
- list<DEPair*> epairList;
- list<DBrush*> brushList;
+ std::list<DEPair*> epairList;
+ std::list<DBrush*> brushList;
// new patches, wahey!!!
- list<DPatch*> patchList;
+ std::list<DPatch*> patchList;
Str m_Classname;
// ---------------------------------------------
int FixBrushes();
- bool LoadFromEntity(scene::Node* ent, bool bLoadPatches = FALSE);
+ bool LoadFromEntity(scene::Node& ent, bool bLoadPatches = false);
void LoadSelectedBrushes();
void LoadSelectedPatches();
//
//////////////////////////////////////////////////////////////////////
-#include "StdAfx.h"
#include "DListener.h"
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
-#include "StdAfx.h"
+#include "DMap.h"
#include "str.h"
-#include "gtkr_list.h"
+#include <list>
#include "DPoint.h"
#include "DPlane.h"
#include "DEPair.h"
#include "DPatch.h"
#include "DEntity.h"
-#include "DMap.h"
#include "iundo.h"
-#include "refcounted_ptr.h"
+#include "generic/referencecounted.h"
#include <vector>
#include <list>
{
m_nNextEntity = 1;
- for(list<DEntity *>::const_iterator deadEntity=entityList.begin(); deadEntity!=entityList.end(); deadEntity++)
+ for(std::list<DEntity *>::const_iterator deadEntity=entityList.begin(); deadEntity!=entityList.end(); deadEntity++)
delete *deadEntity;
entityList.clear();
{
DEntity* findEntity = NULL;
- for(list<DEntity *>::const_iterator chkEntity=entityList.begin(); chkEntity!=entityList.end(); chkEntity++)
+ for(std::list<DEntity *>::const_iterator chkEntity=entityList.begin(); chkEntity!=entityList.end(); chkEntity++)
{
if((*chkEntity)->m_nID == ID)
{
void DMap::BuildInRadiant(bool bAllowDestruction)
{
- for(list<DEntity *>::const_iterator buildEntity=entityList.begin(); buildEntity!=entityList.end(); buildEntity++)
+ for(std::list<DEntity *>::const_iterator buildEntity=entityList.begin(); buildEntity!=entityList.end(); buildEntity++)
(*buildEntity)->BuildInRadiant(bAllowDestruction);
}
{
ClearEntities();
- GlobalSelectionSystem().Select(false);
+ GlobalSelectionSystem().setSelectedAll(false);
class load_entities_t : public scene::Traversable::Walker
{
: m_map(map), m_bLoadPatches(bLoadPatches)
{
}
- bool pre(scene::Node* node)
+ bool pre(scene::Node& node) const
{
- if(node->m_entity)
+ if(Node_isEntity(node))
{
DEntity* loadEntity = m_map->AddEntity("", 0);
loadEntity->LoadFromEntity(node, m_bLoadPatches);
}
return false;
}
- void post(scene::Node* node)
- {
- }
} load_entities(this, bLoadPatches);
- GlobalSceneGraph().root()->m_traverse->traverse(load_entities);
+ Node_getTraversable(GlobalSceneGraph().root())->traverse(load_entities);
}
int DMap::FixBrushes()
{
int count = 0;
- for(list<DEntity *>::const_iterator fixEntity=entityList.begin(); fixEntity!=entityList.end(); fixEntity++)
+ for(std::list<DEntity *>::const_iterator fixEntity=entityList.begin(); fixEntity!=entityList.end(); fixEntity++)
{
count += (*fixEntity)->FixBrushes();
}
void DMap::ResetTextures( const char* textureName, float fScale[2], float fShift[2], int rotation, const char* newTextureName,
int bResetTextureName, int bResetScale[2], int bResetShift[2], int bResetRotation)
{
- for(list<DEntity *>::const_iterator texEntity=entityList.begin(); texEntity!=entityList.end(); texEntity++)
+ for(std::list<DEntity *>::const_iterator texEntity=entityList.begin(); texEntity!=entityList.end(); texEntity++)
{
- if(!stricmp("worldspawn", (*texEntity)->m_Classname))
+ if(string_equal_nocase("worldspawn", (*texEntity)->m_Classname))
(*texEntity)->ResetTextures(textureName, fScale, fShift, rotation, newTextureName,
- bResetTextureName, bResetScale, bResetShift, bResetRotation, TRUE);
+ bResetTextureName, bResetScale, bResetShift, bResetRotation, true);
else
{
if((*texEntity)->ResetTextures( textureName, fScale, fShift, rotation, newTextureName,
- bResetTextureName, bResetScale, bResetShift, bResetRotation, FALSE))
+ bResetTextureName, bResetScale, bResetShift, bResetRotation, false))
RebuildEntity(*texEntity);
}
}
void DMap::RebuildEntity(DEntity *ent)
{
ent->RemoveFromRadiant();
- ent->BuildInRadiant(FALSE);
+ ent->BuildInRadiant(false);
}
#pragma once
#endif // _MSC_VER > 1000
+#include <list>
+
+class DEntity;
+
class DMap
{
public:
static void RebuildEntity(DEntity* ent);
void ResetTextures( const char* textureName, float fScale[2], float fShift[2], int rotation, const char* newTextureName, int bResetTextureName, int bResetScale[2], int bResetShift[2], int bResetRotation);
- void LoadAll(bool bLoadPatches = FALSE);
+ void LoadAll(bool bLoadPatches = false);
void BuildInRadiant(bool bAllowDestruction);
int m_nNextEntity;
DEntity* GetWorldSpawn();
DEntity* DMap::GetEntityForID(int ID);
DEntity* AddEntity(char* classname = "worldspawn", int ID = -1);
- list<DEntity*> entityList;
+ std::list<DEntity*> entityList;
DMap();
virtual ~DMap();
//
//////////////////////////////////////////////////////////////////////
-#include "StdAfx.h"
+#include "DPatch.h"
-#include "gtkr_list.h"
+#include <list>
#include "str.h"
+#include "scenelib.h"
-//#include "DPoint.h"
-//#include "DPlane.h"
-//#include "DBrush.h"
-//#include "DEPair.h"
-#include "DPatch.h"
-//#include "DEntity.h"
+#include "ipatch.h"
#include "misc.h"
#include "./dialogs/dialogs-gtk.h"
VectorCopy(in->xyz, out->xyz);
}
-void DPatch::BuildInRadiant(void* entity)
+void DPatch::BuildInRadiant(scene::Node* entity)
{
+ NodeSmartReference node(GlobalPatchCreator().createPatch());
+
+ if(entity) {
+ Node_getTraversable(*entity)->insert(node);
+ } else {
+ Node_getTraversable(GlobalRadiant().getMapWorldEntity())->insert(node);
+ }
#if 0
int nIndex = g_FuncTable.m_pfnCreatePatchHandle();
//$ FIXME: m_pfnGetPatchHandle
// strcpy(pm->d_texture->name, texture);
brush_t* brush = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();
- brush->patchBrush = TRUE;
+ brush->patchBrush = true;
brush->pPatch = pm;
pm->pSymbiot = brush;
#endif
}
-void DPatch::LoadFromBrush(scene::Node* brush)
+void DPatch::LoadFromBrush(scene::Node& brush)
{
- QER_brush = brush;
+ QER_brush = &brush;
#if 0
SetTexture(brush->pPatch->GetShader());
#endif
}
-void DPatch::RemoveFromRadiant()
-{
- if(QER_brush)
- {
-#if 0
- g_FuncTable.m_pfnDeleteBrushHandle(QER_brush);
-#endif
- }
-}
-
bool DPatch::ResetTextures(const char *oldTextureName, const char *newTextureName)
{
if( !oldTextureName || !strcmp(texture, oldTextureName))
{
strcpy(texture, newTextureName);
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
void Build1dArray(vec3_t* array, drawVert_t points[MAX_PATCH_WIDTH][MAX_PATCH_HEIGHT],
void Print1dArray(vec3_t* array, int size)
{
for(int i = 0; i < size; i++)
- Sys_Printf("(" << array[i][0] << " " << array[i][1] << " " << array[i][2] << ")\t");
- Sys_Printf("\n");
+ globalOutputStream() << "(" << array[i][0] << " " << array[i][1] << " " << array[i][2] << ")\t";
+ globalOutputStream() << "\n";
}
bool Compare1dArrays(vec3_t* a1, vec3_t* a2, int size)
Invert();
}
-list<DPatch> DPatch::Split(bool rows, bool cols)
+std::list<DPatch> DPatch::Split(bool rows, bool cols)
{
- list<DPatch> patchList;
+ std::list<DPatch> patchList;
int i;
int x, y;
if(cols && width >= 5)
{
- list<DPatch> patchList2;
+ std::list<DPatch> patchList2;
- for(list<DPatch>::iterator patches = patchList.begin(); patches != patchList.end(); patches++)
+ for(std::list<DPatch>::iterator patches = patchList.begin(); patches != patchList.end(); patches++)
{
- list<DPatch> patchList3 = (*patches).Split(false, true);
+ std::list<DPatch> patchList3 = (*patches).Split(false, true);
- for(list<DPatch>::iterator patches2 = patchList3.begin(); patches2 != patchList3.end(); patches2++)
+ for(std::list<DPatch>::iterator patches2 = patchList3.begin(); patches2 != patchList3.end(); patches2++)
patchList2.push_front(*patches2);
}
#if !defined(AFX_DPATCH_H__26C6B083_CE5B_420B_836B_1DDA733C04CE__INCLUDED_)
#define AFX_DPATCH_H__26C6B083_CE5B_420B_836B_1DDA733C04CE__INCLUDED_
-#include "StdAfx.h" // Added by ClassView
-#if _MSC_VER > 1000
-#pragma once
-#endif // _MSC_VER > 1000
+#include <list>
typedef struct
{
float lightmap[2];
} drawVert_t;
-class Patch;
+namespace scene
+{
+ class Node;
+}
#define MAX_PATCH_WIDTH 16
#define MAX_PATCH_HEIGHT 16
class DPatch
{
public:
- list<DPatch> Split(bool rows, bool cols);
+ std::list<DPatch> Split(bool rows, bool cols);
void Transpose();
void Invert();
DPatch* MergePatches(patch_merge_t merge_info, DPatch* p1, DPatch* p2);
patch_merge_t IsMergable(DPatch* other);
bool ResetTextures(const char *oldTextureName, const char *newTextureName);
- void RemoveFromRadiant(void);
scene::Node* QER_brush;
- void LoadFromBrush(scene::Node* brush);
- void BuildInRadiant(void* entity = NULL);
+ void LoadFromBrush(scene::Node& brush);
+ void BuildInRadiant(scene::Node* entity = NULL);
void SetTexture(const char* textureName);
char texture[256];
int width, height;
//
//////////////////////////////////////////////////////////////////////
-#include "StdAfx.h"
+#include "DPlane.h"
-#include "gtkr_list.h"
+#include <list>
#include "DPoint.h"
-#include "DPlane.h"
#include "DWinding.h"
#include "str.h"
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
-DPlane::DPlane(vec3_t va, vec3_t vb, vec3_t vc, _QERFaceData* texData)
+DPlane::DPlane(const vec3_t va, const vec3_t vb, const vec3_t vc, const _QERFaceData* texData)
{
MakeNormal( va, vb, vc, normal );
if(VectorNormalize(normal, normal) == 0) // normalizes and returns length
- Sys_ERROR("DPlane::DPlane: Bad Normal.\n");
+ globalErrorStream() << "DPlane::DPlane: Bad Normal.\n";
_d = (normal[0]*va[0]) + (normal[1]*va[1]) + (normal[2]*va[2]);
VectorCopy(vb, points[1]);
VectorCopy(vc, points[2]);
- m_bChkOk = TRUE;
+ m_bChkOk = true;
if(texData)
memcpy(&texInfo, texData, sizeof(_QERFaceData));
float d = Determinant3x3(a1, a2, a3, b1, b2, b3, c1, c2, c3);
if(d == 0)
- return FALSE;
+ return false;
float v1 = _d;
float v2 = pl1->_d;
out[1] = d2/d;
out[2] = d3/d;
- return TRUE;
+ return true;
}
-bool DPlane::IsRedundant(list<DPoint*>& pointList)
+bool DPlane::IsRedundant(std::list<DPoint*>& pointList)
{
int cnt = 0;
- //list<DPoint *>::const_iterator point=pointList.begin();
- for(list<DPoint *>::const_iterator point=pointList.begin(); point!=pointList.end(); point++)
+ //std::list<DPoint *>::const_iterator point=pointList.begin();
+ for(std::list<DPoint *>::const_iterator point=pointList.begin(); point!=pointList.end(); point++)
{
if(fabs(DistanceToPoint((*point)->_pnt)) < MAX_ROUND_ERROR)
cnt++;
if(cnt == 3)
- return FALSE;
+ return false;
}
- return TRUE;
+ return true;
}
bool DPlane::operator == (DPlane& other)
vec3_t chk;
VectorSubtract(other.normal, normal, chk);
if(fabs(VectorLength(chk)) > MAX_ROUND_ERROR)
- return FALSE;
+ return false;
if(fabs(other._d - _d) > MAX_ROUND_ERROR)
- return FALSE;
+ return false;
- return TRUE;
+ return true;
}
bool DPlane::operator != (DPlane& other)
vec3_t chk;
VectorAdd(other.normal, normal, chk);
if(fabs(VectorLength(chk)) > MAX_ROUND_ERROR)
- return FALSE;
+ return false;
- return TRUE;
+ return true;
}
DWinding* DPlane::BaseWindingForPlane()
}
}
if (x==-1)
- Sys_Printf ("BaseWindingForPlane: no axis found");
+ globalOutputStream() << "BaseWindingForPlane: no axis found";
VectorCopy (vec3_origin, vup);
switch (x)
CrossProduct(v1, v2, normal);
if(VectorNormalize(normal, normal) == 0) // normalizes and returns length
- Sys_ERROR("DPlane::Rebuild: Bad Normal.\n");
+ globalErrorStream() << "DPlane::Rebuild: Bad Normal.\n";
_d = (normal[0]*points[0][0]) + (normal[1]*points[0][1]) + (normal[2]*points[0][2]);
VectorCopy(points[2], texInfo.m_p2);
}
-bool DPlane::AddToBrush(Brush *brush)
+bool DPlane::AddToBrush(scene::Node& brush)
{
-#if 0
- if(m_bChkOk || !strcmp(texInfo.m_TextureName, "textures/common/caulk"))
- {
- brush->addPlane(m_p0, m_p1, m_p2, m_texdef, false);
- return FALSE;
- }
-
- strcpy(texInfo.m_TextureName, "textures/common/caulk");
- brush->addPlane(m_p0, m_p1, m_p2, m_texdef, false);
-#endif
- return TRUE;
+ bool changed = false;
+ if(!(m_bChkOk || !strcmp(m_shader.c_str(), "textures/common/caulk")))
+ {
+ m_shader = "textures/common/caulk";
+ changed = true;
+ }
+
+ _QERFaceData faceData;
+ faceData.m_p0 = vector3_from_array(points[0]);
+ faceData.m_p1 = vector3_from_array(points[1]);
+ faceData.m_p2 = vector3_from_array(points[2]);
+ faceData.m_texdef = texInfo.m_texdef;
+ faceData.m_shader = m_shader.c_str();
+ GlobalBrushCreator().addBrushFace(brush, faceData);
+
+ return changed;
}
void DPlane::ScaleTexture()
{ }
-DPlane::DPlane(vec3_t va, vec3_t vb, vec3_t vc, const char* textureName, bool bDetail)
+DPlane::DPlane(const vec3_t va, const vec3_t vb, const vec3_t vc, const char* textureName, bool bDetail)
{
vec3_t v1, v2;
VectorSubtract(va, vb, v1);
CrossProduct(v1, v2, normal);
if(VectorNormalize(normal, normal) == 0) // normalizes and returns length
- Sys_ERROR("DPlane::DPlane: Bad Normal.\n");
+ globalErrorStream() << "DPlane::DPlane: Bad Normal.\n";
_d = (normal[0]*va[0]) + (normal[1]*va[1]) + (normal[2]*va[2]);
VectorCopy(vb, points[1]);
VectorCopy(vc, points[2]);
- m_bChkOk = TRUE;
+ m_bChkOk = true;
FillDefaultTexture(&texInfo, points[0], points[1], points[2], textureName);
if(bDetail)
- texInfo.m_texdef.contents |= FACE_DETAIL;
+ texInfo.contents |= FACE_DETAIL;
}
#if !defined(AFX_DPLANE_H__FC37C021_F0A1_11D4_ACF7_004095A18133__INCLUDED_)
#define AFX_DPLANE_H__FC37C021_F0A1_11D4_ACF7_004095A18133__INCLUDED_
+#include <list>
+#include "ibrush.h"
+#include "string/string.h"
+#include "mathlib.h"
+
class Brush;
+class DPoint;
#define FACE_DETAIL 0x8000000
class DPlane
{
public:
- DPlane(vec3_t va, vec3_t vb, vec3_t vc, const char* textureName, bool bDetail);
+ DPlane(const vec3_t va, const vec3_t vb, const vec3_t vc, const char* textureName, bool bDetail);
void ScaleTexture();
DWinding* BaseWindingForPlane();
void Rebuild();
- bool AddToBrush(Brush *brush);
+ bool AddToBrush(scene::Node& brush);
bool operator != (DPlane& other);
bool operator == (DPlane& other);
- bool IsRedundant(list<DPoint*>& pointList);
+ bool IsRedundant(std::list<DPoint*>& pointList);
bool PlaneIntersection(DPlane* pl1, DPlane* pl2, vec3_t out);;
vec_t DistanceToPoint(vec3_t pnt);
- DPlane(vec3_t va, vec3_t vb, vec3_t vc, _QERFaceData* texData);
+ DPlane(const vec3_t va, const vec3_t vb, const vec3_t vc, const _QERFaceData* texData);
DPlane() { }
virtual ~DPlane();
bool m_bChkOk;
_QERFaceData texInfo;
+ CopiedString m_shader;
vec3_t points[3]; // djbob:do we really need these any more?
vec3_t normal;
float _d;
//
//////////////////////////////////////////////////////////////////////
-#include "StdAfx.h"
#include "DPoint.h"
+#include "misc.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
vec3_t test;
VectorSubtract(other, _pnt, test);
if(fabs(VectorLength(test)) > MAX_ROUND_ERROR)
- return FALSE;
- return TRUE;
+ return false;
+ return true;
}
#pragma once
#endif // _MSC_VER > 1000
+#include "mathlib.h"
+
class DPoint
{
public:
//
//////////////////////////////////////////////////////////////////////
-#include "StdAfx.h"
+#include "DShape.h"
-#include "gtkr_list.h"
+#include <list>
+#include <time.h>
#include "str.h"
#include "DPoint.h"
#include "DEPair.h"
#include "DPatch.h"
#include "DEntity.h"
-#include "DShape.h"
//#include "dialogs-gtk.h"
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
-bool bFacesAll[6] = {TRUE, TRUE, TRUE, TRUE, TRUE, TRUE};
+bool bFacesAll[6] = {true, true, true, true, true, true};
DShape::DShape()
{
DBrush* pB = m_Container.GetWorldSpawn()->NewBrush(m_nNextBrush++);
for(i = 1; i <= nSides; i++)
- pB->AddFace(vc[i-1], vc[i], vd[i], GetCurrentTexture(), FALSE);
+ pB->AddFace(vc[i-1], vc[i], vd[i], GetCurrentTexture(), false);
- pB->AddFace(vc[2], vc[1], vc[0], "textures/common/caulk", FALSE);
- pB->AddFace(vd[0], vd[1], vd[2], "textures/common/caulk", FALSE);
+ pB->AddFace(vc[2], vc[1], vc[0], "textures/common/caulk", false);
+ pB->AddFace(vd[0], vd[1], vd[2], "textures/common/caulk", false);
}
void DShape::Commit()
{
m_Container.GetWorldSpawn()->FixBrushes();
- m_Container.BuildInRadiant(TRUE);
+ m_Container.BuildInRadiant(true);
}
void DShape::BuildInversePrism(vec3_t min, vec3_t max, int nSides, bool bAlignTop)
if(top[1] != bottom[1]) // internal line is flat already if true
{
- pB->AddFace(va[i-1], top, vb[i-1], "textures/common/caulk", FALSE);
- pB->AddFace(va[i], vb[i], bottom, "textures/common/caulk", FALSE);
+ pB->AddFace(va[i-1], top, vb[i-1], "textures/common/caulk", false);
+ pB->AddFace(va[i], vb[i], bottom, "textures/common/caulk", false);
} // add cut-off planes
- pB->AddFace(va[i-1], vb[i-1], vb[i], GetCurrentTexture(), FALSE);
+ pB->AddFace(va[i-1], vb[i-1], vb[i], GetCurrentTexture(), false);
// add internal polygon plane
}
}
{
DBrush* pB = GetBoundingCube(min, max, "textures/common/caulk");
- pB->AddFace(origin, vc[i-1], vd[i-1], "textures/common/caulk", FALSE);
- pB->AddFace(origin, vd[i], vc[i], "textures/common/caulk", FALSE);
+ pB->AddFace(origin, vc[i-1], vd[i-1], "textures/common/caulk", false);
+ pB->AddFace(origin, vd[i], vc[i], "textures/common/caulk", false);
- pB->AddFace(vc[i-1], vc[i], vd[i], GetCurrentTexture(), FALSE);
- pB->AddFace(vb[i], va[i], va[i-1], GetCurrentTexture(), FALSE);
+ pB->AddFace(vc[i-1], vc[i], vd[i], GetCurrentTexture(), false);
+ pB->AddFace(vb[i], va[i], va[i-1], GetCurrentTexture(), false);
}
}
//----- Add Six Cube Faces ---------
if(bUseFaces[0])
- pB->AddFace(v1, v2, v3, textureName, FALSE);
+ pB->AddFace(v1, v2, v3, textureName, false);
if(bUseFaces[1])
- pB->AddFace(v1, v3, v6, textureName, FALSE);
+ pB->AddFace(v1, v3, v6, textureName, false);
if(bUseFaces[2])
- pB->AddFace(v1, v7, v2, textureName, FALSE);
+ pB->AddFace(v1, v7, v2, textureName, false);
if(bUseFaces[3])
- pB->AddFace(v5, v6, v3, textureName, FALSE);
+ pB->AddFace(v5, v6, v3, textureName, false);
if(bUseFaces[4])
- pB->AddFace(v5, v2, v7, textureName, FALSE);
+ pB->AddFace(v5, v2, v7, textureName, false);
if(bUseFaces[5])
- pB->AddFace(v5, v7, v6, textureName, FALSE);
+ pB->AddFace(v5, v7, v6, textureName, false);
//----------------------------------
bool DShape::BuildPit(vec3_t min, vec3_t max)
{
if((max[2] - min[2]) < 196)
- return FALSE;
+ return false;
srand(time(NULL));
// ****** END NODROP ********
- return TRUE;
+ return true;
}
#if !defined(AFX_DSHAPE_H__0B30B302_9D21_4C2D_836A_61F3C8D4244D__INCLUDED_)
#define AFX_DSHAPE_H__0B30B302_9D21_4C2D_836A_61F3C8D4244D__INCLUDED_
-#include "DMap.h" // Added by ClassView
-#include "StdAfx.h" // Added by ClassView
-
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
+#include "mathlib.h"
+#include "DMap.h"
+class DBrush;
+class DEntity;
+
// defines for polygon stuff
#define MAX_POLYGON_FACES 128
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "StdAfx.h"
+#include "DTrainDrawer.h"
-#include "gtkr_list.h"
+#include <list>
#include "str.h"
#include "DPoint.h"
#include "DEPair.h"
#include "DPatch.h"
#include "DEntity.h"
-#include "DTrainDrawer.h"
#include "misc.h"
#include "funchandlers.h"
+#include "iglrender.h"
+#include "math/matrix.h"
+
#include "dialogs/dialogs-gtk.h"
DTrainDrawer::DTrainDrawer() {
- refCount = 1;
- m_bHooked = FALSE;
- m_bDisplay = FALSE;
+ m_bDisplay = false;
BuildPaths();
+ constructShaders();
+ GlobalShaderCache().attachRenderable(*this);
}
DTrainDrawer::~DTrainDrawer(void) {
- if(m_bHooked)
- UnRegister();
+ GlobalShaderCache().detachRenderable(*this);
+ destroyShaders();
ClearPoints();
ClearSplines();
}
void DTrainDrawer::ClearSplines() {
- for(list<splinePoint_t *>::const_iterator deadSpline = m_splineList.begin(); deadSpline != m_splineList.end(); deadSpline++) {
+ for(std::list<splinePoint_t *>::const_iterator deadSpline = m_splineList.begin(); deadSpline != m_splineList.end(); deadSpline++) {
(*deadSpline)->m_pointList.clear();
(*deadSpline)->m_vertexList.clear();
delete (*deadSpline);
}
void DTrainDrawer::ClearPoints() {
- for(list<controlPoint_t *>::const_iterator deadPoint = m_pointList.begin(); deadPoint != m_pointList.end(); deadPoint++) {
+ for(std::list<controlPoint_t *>::const_iterator deadPoint = m_pointList.begin(); deadPoint != m_pointList.end(); deadPoint++) {
delete *deadPoint;
}
m_pointList.clear();
}
-void DTrainDrawer::Register() {
- __QGLTABLENAME.m_pfnHookGL2DWindow( this );
- __QGLTABLENAME.m_pfnHookGL3DWindow( this );
- m_bHooked = TRUE;
-}
-
-void DTrainDrawer::UnRegister() {
- __QGLTABLENAME.m_pfnUnHookGL2DWindow( this );
- __QGLTABLENAME.m_pfnUnHookGL3DWindow( this );
- m_bHooked = FALSE;
-}
-
void CalculateSpline_r(vec3_t* v, int count, vec3_t out, float tension) {
vec3_t dist;
delete[] v2;
}
-void DTrainDrawer::Draw3D() {
-
- if(!m_bDisplay) {
- return;
- }
-
- __QGLTABLENAME.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS);
-
- __QGLTABLENAME.m_pfn_qglDisable(GL_BLEND);
- __QGLTABLENAME.m_pfn_qglDisable(GL_LINE_SMOOTH);
-
- __QGLTABLENAME.m_pfn_qglPushMatrix();
-
- __QGLTABLENAME.m_pfn_qglLineWidth(2.0f);
- __QGLTABLENAME.m_pfn_qglColor4f(1.0f, 1.0f, 1.0f, 1.0f);
-
- __QGLTABLENAME.m_pfn_qglEnable(GL_BLEND);
- __QGLTABLENAME.m_pfn_qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- __QGLTABLENAME.m_pfn_qglDisable(GL_POLYGON_SMOOTH);
-
- __QGLTABLENAME.m_pfn_qglDepthFunc(GL_ALWAYS);
-
- for(list<splinePoint_t* >::const_iterator sp = m_splineList.begin(); sp != m_splineList.end(); sp++) {
+void DTrainDrawer::render(RenderStateFlags state) const
+{
+ for(std::list<splinePoint_t* >::const_iterator sp = m_splineList.begin(); sp != m_splineList.end(); sp++) {
splinePoint_t* pSP = (*sp);
- __QGLTABLENAME.m_pfn_qglBegin(GL_LINE_STRIP);
- for(list<DPoint >::const_iterator v = pSP->m_vertexList.begin(); v != pSP->m_vertexList.end(); v++) {
- __QGLTABLENAME.m_pfn_qglVertex3fv((*v)._pnt);
+ glBegin(GL_LINE_STRIP);
+ for(std::list<DPoint >::const_iterator v = pSP->m_vertexList.begin(); v != pSP->m_vertexList.end(); v++) {
+ glVertex3fv((*v)._pnt);
}
- __QGLTABLENAME.m_pfn_qglEnd();
+ glEnd();
}
-
- __QGLTABLENAME.m_pfn_qglPopMatrix();
- __QGLTABLENAME.m_pfn_qglPopAttrib();
}
-void DTrainDrawer::Draw2D(VIEWTYPE vt) {
+const char* DTrainDrawer_state_wireframe = "$bobtoolz/traindrawer/wireframe";
+const char* DTrainDrawer_state_solid = "$bobtoolz/traindrawer/solid";
- if(!m_bDisplay) {
- return;
- }
-
- __QGLTABLENAME.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS);
-
- __QGLTABLENAME.m_pfn_qglDisable(GL_BLEND);
- __QGLTABLENAME.m_pfn_qglDisable(GL_LINE_SMOOTH);
-
- __QGLTABLENAME.m_pfn_qglPushMatrix();
-
- switch(vt)
- {
- case XY:
- break;
- case XZ:
- __QGLTABLENAME.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f);
- break;
- case YZ:
- __QGLTABLENAME.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f);
- __QGLTABLENAME.m_pfn_qglRotatef(270.0f, 0.0f, 0.0f, 1.0f);
- break;
- }
-
- __QGLTABLENAME.m_pfn_qglLineWidth(1.0f);
- __QGLTABLENAME.m_pfn_qglColor4f(1.0f, 0.0f, 0.0f, 0.5f);
-
- __QGLTABLENAME.m_pfn_qglEnable(GL_BLEND);
- __QGLTABLENAME.m_pfn_qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- __QGLTABLENAME.m_pfn_qglDisable(GL_POLYGON_SMOOTH);
-
- __QGLTABLENAME.m_pfn_qglDepthFunc(GL_ALWAYS);
-
- __QGLTABLENAME.m_pfn_qglColor4f(1.f, 0.f, 0.f, 1.f);
+void DTrainDrawer::constructShaders()
+{
+ OpenGLState state;
+ GlobalOpenGLStateLibrary().getDefaultState(state);
+ state.m_state = RENDER_COLOURWRITE|RENDER_DEPTHWRITE|RENDER_BLEND;
+ state.m_sort = OpenGLState::eSortOverlayFirst;
+ state.m_linewidth = 1;
+ state.m_colour[0] = 1;
+ state.m_colour[1] = 0;
+ state.m_colour[2] = 0;
+ state.m_colour[3] = 1;
+ state.m_linewidth = 1;
+ GlobalOpenGLStateLibrary().insert(DTrainDrawer_state_wireframe, state);
+
+ state.m_colour[0] = 1;
+ state.m_colour[1] = 1;
+ state.m_colour[2] = 1;
+ state.m_colour[3] = 1;
+ state.m_linewidth = 2;
+ GlobalOpenGLStateLibrary().insert(DTrainDrawer_state_solid, state);
+
+ m_shader_wireframe = GlobalShaderCache().capture(DTrainDrawer_state_wireframe);
+ m_shader_solid = GlobalShaderCache().capture(DTrainDrawer_state_solid);
+}
- for(list<splinePoint_t* >::const_iterator sp = m_splineList.begin(); sp != m_splineList.end(); sp++) {
- splinePoint_t* pSP = (*sp);
+void DTrainDrawer::destroyShaders()
+{
+ GlobalOpenGLStateLibrary().erase(DTrainDrawer_state_wireframe);
+ GlobalOpenGLStateLibrary().erase(DTrainDrawer_state_solid);
+ GlobalShaderCache().release(DTrainDrawer_state_wireframe);
+ GlobalShaderCache().release(DTrainDrawer_state_solid);
+}
- __QGLTABLENAME.m_pfn_qglBegin(GL_LINE_STRIP);
- for(list<DPoint >::const_iterator v = pSP->m_vertexList.begin(); v != pSP->m_vertexList.end(); v++) {
- __QGLTABLENAME.m_pfn_qglVertex3fv((*v)._pnt);
- }
- __QGLTABLENAME.m_pfn_qglEnd();
+void DTrainDrawer::renderSolid(Renderer& renderer, const VolumeTest& volume) const
+{
+ if(!m_bDisplay) {
+ return;
}
- __QGLTABLENAME.m_pfn_qglPopMatrix();
- __QGLTABLENAME.m_pfn_qglPopAttrib();
+ renderer.SetState(m_shader_wireframe, Renderer::eWireframeOnly);
+ renderer.SetState(m_shader_solid, Renderer::eFullMaterials);
+ renderer.addRenderable(*this, g_matrix4_identity);
+}
+void DTrainDrawer::renderWireframe(Renderer& renderer, const VolumeTest& volume) const
+{
+ renderSolid(renderer, volume);
}
void AddSplineControl(const char* control, splinePoint_t* pSP) {
}
}
- list<splinePoint_t* >::const_iterator sp;
+ std::list<splinePoint_t* >::const_iterator sp;
for(sp = m_splineList.begin(); sp != m_splineList.end(); sp++) {
splinePoint_t* pSP = (*sp);
pSP->pTarget = pTarget;
- for(list<controlPoint_t >::iterator cp = pSP->m_pointList.begin(); cp != pSP->m_pointList.end(); cp++) {
+ for(std::list<controlPoint_t >::iterator cp = pSP->m_pointList.begin(); cp != pSP->m_pointList.end(); cp++) {
controlPoint_t* pControl = FindControlPoint( (*cp).strName );
if(!pControl) {
Sys_Printf( "couldn't find control %s", (*cp).strName );
VectorCopy(pSP->point.vOrigin, v[0]);
int i = 1;
- for(list<controlPoint_t>::reverse_iterator cp = pSP->m_pointList.rbegin(); cp != pSP->m_pointList.rend(); cp++) {
+ for(std::list<controlPoint_t>::reverse_iterator cp = pSP->m_pointList.rbegin(); cp != pSP->m_pointList.rend(); cp++) {
VectorCopy((*cp).vOrigin, v[i]);
i++;
}
controlPoint_t* DTrainDrawer::FindControlPoint(const char* name)
{
- for(list<controlPoint_t*>::const_iterator cp = m_pointList.begin(); cp != m_pointList.end(); cp++) {
+ for(std::list<controlPoint_t*>::const_iterator cp = m_pointList.begin(); cp != m_pointList.end(); cp++) {
if(!strcmp(name, (*cp)->strName)) {
return (*cp);
}
}
- for(list<splinePoint_t*>::const_iterator sp = m_splineList.begin(); sp != m_splineList.end(); sp++) {
+ for(std::list<splinePoint_t*>::const_iterator sp = m_splineList.begin(); sp != m_splineList.end(); sp++) {
if(!strcmp(name, (*sp)->point.strName)) {
return &((*sp)->point);
}
#pragma once
#endif // _MSC_VER > 1000
+#include <list>
+#include "mathlib.h"
+
+#include "irender.h"
+#include "renderable.h"
+
+class DPoint;
+class Shader;
+
typedef struct {
char strName[64];
char strControl[64];
char strTarget[64];
- list<controlPoint_t> m_pointList;
- list<DPoint> m_vertexList;
+ std::list<controlPoint_t> m_pointList;
+ std::list<DPoint> m_vertexList;
controlPoint_t* pTarget;
} splinePoint_t;
-class DTrainDrawer :
- public IGL2DWindow,
- public IGL3DWindow
+class DTrainDrawer : public Renderable, public OpenGLRenderable
{
private:
- list<splinePoint_t*> m_splineList;
- list<controlPoint_t*> m_pointList;
- int refCount;
+ std::list<splinePoint_t*> m_splineList;
+ std::list<controlPoint_t*> m_pointList;
- bool m_bHooked;
bool m_bDisplay;
+ Shader* m_shader_wireframe;
+ Shader* m_shader_solid;
public:
- void UnRegister();
- void Register();
DTrainDrawer();
virtual ~DTrainDrawer(void);
- void Draw3D();
- void Draw2D(VIEWTYPE vt);
- void IncRef() { refCount++; }
- void DecRef() { refCount--; if (refCount <= 0) delete this; }
+ void render(RenderStateFlags state) const;
+ void renderSolid(Renderer& renderer, const VolumeTest& volume) const;
+ void renderWireframe(Renderer& renderer, const VolumeTest& volume) const;
+
+ void constructShaders();
+ void destroyShaders();
+
void ClearSplines();
void ClearPoints();
void BuildPaths();
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "StdAfx.h"
+#include "DTreePlanter.h"
-#include "gtkr_list.h"
+#include <list>
#include "str.h"
#include "DPoint.h"
#include "ScriptParser.h"
#include "misc.h"
-#include "DTreePlanter.h"
#include "funchandlers.h"
-bool DTreePlanter::OnMouseMove(guint32 nFlags, gdouble x, gdouble y) {
- return false;
-}
-
-bool DTreePlanter::OnLButtonDown(guint32 nFlags, gdouble x, gdouble y) {
- VIEWTYPE vt = m_XYWrapper->GetViewType();
+SignalHandlerResult DTreePlanter::mouseDown(const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers)
+{
+ if(button != c_buttonLeft)
+ {
+ return SIGNAL_CONTINUE_EMISSION;
+ }
+ VIEWTYPE vt = GlobalRadiant().XYWindow_getViewType();
switch(vt) {
case XY:
case YZ:
case XZ:
default:
- return false;
+ return SIGNAL_CONTINUE_EMISSION;
}
- vec3_t pt, vhit;
+ Vector3 pt, vhit;
- m_XYWrapper->SnapToGrid( static_cast<int>(x), static_cast<int>(y), pt );
+ pt = vector3_snapped(GlobalRadiant().XYWindow_windowToWorld(position));
- if(FindDropPoint(pt, vhit)) {
+ if(FindDropPoint(vector3_to_array(pt), vector3_to_array(vhit))) {
vhit[2] += m_offset;
char buffer[128];
e2.LoadFromEntity(lastEntNum, TRUE);
e2.AddEPair("target", buffer);
e2.RemoveFromRadiant();
- e2.BuildInRadiant(FALSE);
+ e2.BuildInRadiant(false);
}
#endif
}
e.AddEPair("modelscale", buffer);
}
- e.BuildInRadiant( FALSE );
+ e.BuildInRadiant( false );
}
if(m_autoLink) {
DoTrainPathPlot();
}
- return true;
-}
-
-bool DTreePlanter::OnLButtonUp(guint32 nFlags, gdouble x, gdouble y) {
- return false;
-}
-
-bool DTreePlanter::OnRButtonDown(guint32 nFlags, gdouble x, gdouble y) {
- return false;
-}
-
-bool DTreePlanter::OnRButtonUp(guint32 nFlags, gdouble x, gdouble y) {
- return false;
-}
-
-bool DTreePlanter::OnMButtonDown(guint32 nFlags, gdouble x, gdouble y) {
- return false;
-}
-
-bool DTreePlanter::OnMButtonUp(guint32 nFlags, gdouble x, gdouble y) {
- return false;
+ return SIGNAL_STOP_EMISSION;
}
bool DTreePlanter::FindDropPoint(vec3_t in, vec3_t out) {
sprintf( buffer, "%f %f %f", out[0], out[1], out[2] );
ent.AddEPair( "origin", buffer );
ent.RemoveFromRadiant();
- ent.BuildInRadiant(FALSE);
+ ent.BuildInRadiant(false);
}
g_FuncTable.m_pfnReleaseSelectedBrushHandles();
e.AddEPair( "control", buffer );
}
- e.BuildInRadiant( FALSE );
+ e.BuildInRadiant( false );
}
for(i = 0; i < m_linkNum-1; i++) {
sprintf( buffer, "0 %i 0", (i * 64) + 32);
e.AddEPair( "origin", buffer );
- e.BuildInRadiant( FALSE );
+ e.BuildInRadiant( false );
}
}
e.AddEPair( "control", buffer );
}
- e.BuildInRadiant( FALSE );
+ e.BuildInRadiant( false );
}
for(int i = 0; i < m_linkNum-1; i++) {
sprintf( buffer, "0 %i 0", (i * 64) + 32);
e.AddEPair( "origin", buffer );
- e.BuildInRadiant( FALSE );
+ e.BuildInRadiant( false );
}*/
}
#ifndef __DTREE_H__
#define __DTREE_H__
+#include "qerplugin.h"
+#include "signal/isignal.h"
+#include "string/string.h"
+
+#include "DEntity.h"
+#include "scriptparser.h"
+#include "mathlib.h"
+#include "misc.h"
#define MAX_QPATH 64
#define MAX_TP_MODELS 256
-class DTreePlanter : public IWindowListener {
+class DTreePlanter {
+ MouseEventHandlerId m_mouseDown;
public:
- virtual bool OnMouseMove(guint32 nFlags, gdouble x, gdouble y);
- virtual bool OnLButtonDown(guint32 nFlags, gdouble x, gdouble y);
- virtual bool OnMButtonDown(guint32 nFlags, gdouble x, gdouble y);
- virtual bool OnRButtonDown(guint32 nFlags, gdouble x, gdouble y);
- virtual bool OnLButtonUp(guint32 nFlags, gdouble x, gdouble y);
- virtual bool OnMButtonUp(guint32 nFlags, gdouble x, gdouble y);
- virtual bool OnRButtonUp(guint32 nFlags, gdouble x, gdouble y);
- virtual bool OnKeyPressed(char *s) { return false; }
- virtual bool Paint() { return true; }
- virtual void Close() { }
-
- DTreePlanter() {
- m_refCount = 1;
- m_hooked = false;
- m_XYWrapper = NULL;
+ SignalHandlerResult mouseDown(const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers);
+ typedef Member3<DTreePlanter, const WindowVector&, ButtonIdentifier, ModifierFlags, SignalHandlerResult, &DTreePlanter::mouseDown> MouseDownCaller;
+
+ DTreePlanter() {
m_numModels = 0;
m_offset = 0;
m_maxPitch = 0;
m_autoLink = false;
m_linkNum = 0;
- Register();
-
m_world.LoadSelectedBrushes();
char buffer[256];
fclose( file );
}
+
+ m_mouseDown = GlobalRadiant().XYWindowMouseDown_connect(makeSignalHandler3(MouseDownCaller(), *this));
}
-#define MT(t) !stricmp( pToken, t )
+ virtual ~DTreePlanter()
+ {
+ GlobalRadiant().XYWindowMouseDown_disconnect(m_mouseDown);
+ }
+
+#define MT(t) string_equal_nocase( pToken, t )
#define GT pToken = pScriptParser->GetToken( true )
#define CT if(!*pToken) { return; }
} while( true );
}
- virtual ~DTreePlanter() {
- UnRegister();
- }
-
- virtual void IncRef() { m_refCount++; }
- virtual void DecRef() { m_refCount--; if (m_refCount <= 0) delete this; }
-
- void Register() {
- if(!m_hooked) {
- g_MessageTable.m_pfnHookWindow( this );
- m_XYWrapper = g_MessageTable.m_pfnGetXYWndWrapper();
- m_hooked = true;
- }
- }
-
- void UnRegister() {
- if(m_hooked) {
- g_MessageTable.m_pfnUnHookWindow( this );
- m_XYWrapper = NULL;
- m_hooked = false;
- }
- }
-
bool FindDropPoint(vec3_t in, vec3_t out);
void DropEntsToGround( void );
void MakeChain( void );
void SelectChain( void );
private:
- IXYWndWrapper* m_XYWrapper;
DEntity m_world;
treeModel_t m_trees[MAX_TP_MODELS];
- int m_refCount;
int m_numModels;
int m_offset;
int m_maxPitch;
float m_minScale;
float m_maxScale;
- bool m_hooked;
bool m_useScale;
bool m_setAngles;
bool m_autoLink;
//
//////////////////////////////////////////////////////////////////////
-#include "StdAfx.h"
+#include "DVisDrawer.h"
+
+#include "iglrender.h"
+#include "math/matrix.h"
-#include "gtkr_list.h"
+#include <list>
#include "str.h"
#include "DPoint.h"
#include "DWinding.h"
-#include "DVisDrawer.h"
#include "misc.h"
#include "funchandlers.h"
DVisDrawer::DVisDrawer()
{
- refCount = 1;
- m_bHooked = FALSE;
m_list = NULL;
+
+ constructShaders();
+ GlobalShaderCache().attachRenderable(*this);
}
DVisDrawer::~DVisDrawer()
{
- if(m_bHooked)
- UnRegister();
+ GlobalShaderCache().detachRenderable(*this);
+ destroyShaders();
g_VisView = NULL;
}
//////////////////////////////////////////////////////////////////////
// Implementation
//////////////////////////////////////////////////////////////////////
+const char* g_state_solid = "$bobtoolz/visdrawer/solid";
+const char* g_state_wireframe = "$bobtoolz/visdrawer/wireframe";
-void DVisDrawer::Draw2D(VIEWTYPE vt)
+void DVisDrawer::constructShaders()
{
- if(!m_list)
- return;
-
- __QGLTABLENAME.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS);
+ OpenGLState state;
+ GlobalOpenGLStateLibrary().getDefaultState(state);
+ state.m_state = RENDER_COLOURWRITE|RENDER_DEPTHWRITE|RENDER_COLOURCHANGE;
+ state.m_linewidth = 1;
- __QGLTABLENAME.m_pfn_qglDisable(GL_BLEND);
- __QGLTABLENAME.m_pfn_qglDisable(GL_LINE_SMOOTH);
+ GlobalOpenGLStateLibrary().insert(g_state_wireframe, state);
- __QGLTABLENAME.m_pfn_qglPushMatrix();
-
- switch(vt)
- {
- case XY:
- break;
- case XZ:
- __QGLTABLENAME.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f);
- break;
- case YZ:
- __QGLTABLENAME.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f);
- __QGLTABLENAME.m_pfn_qglRotatef(270.0f, 0.0f, 0.0f, 1.0f);
- break;
- }
+ GlobalOpenGLStateLibrary().getDefaultState(state);
+ state.m_state = RENDER_FILL|RENDER_BLEND|RENDER_COLOURWRITE|RENDER_COLOURCHANGE|RENDER_SMOOTH|RENDER_DEPTHWRITE;
- __QGLTABLENAME.m_pfn_qglLineWidth(1.0f);
- __QGLTABLENAME.m_pfn_qglColor4f(1.0f, 0.0f, 0.0f, 0.5f);
+ GlobalOpenGLStateLibrary().insert(g_state_solid, state);
- __QGLTABLENAME.m_pfn_qglEnable(GL_BLEND);
- __QGLTABLENAME.m_pfn_qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- __QGLTABLENAME.m_pfn_qglDisable(GL_POLYGON_SMOOTH);
+ m_shader_solid = GlobalShaderCache().capture(g_state_solid);
+ m_shader_wireframe = GlobalShaderCache().capture(g_state_wireframe);
+}
- __QGLTABLENAME.m_pfn_qglDepthFunc(GL_ALWAYS);
+void DVisDrawer::destroyShaders()
+{
+ GlobalShaderCache().release(g_state_solid);
+ GlobalShaderCache().release(g_state_wireframe);
+ GlobalOpenGLStateLibrary().erase(g_state_solid);
+ GlobalOpenGLStateLibrary().erase(g_state_wireframe);
+}
+void DVisDrawer::render(RenderStateFlags state) const
+{
//bleh
- list<DWinding *>::const_iterator l=m_list->begin();
+ std::list<DWinding *>::const_iterator l=m_list->begin();
for(; l != m_list->end(); l++)
{
DWinding* w = *l;
- __QGLTABLENAME.m_pfn_qglColor4f(w->clr[0], w->clr[1], w->clr[2], 0.5f);
+ glColor4f(w->clr[0], w->clr[1], w->clr[2], 0.5f);
- __QGLTABLENAME.m_pfn_qglBegin(GL_POLYGON);
+ glBegin(GL_POLYGON);
for(int i = 0; i < w->numpoints; i++) {
- __QGLTABLENAME.m_pfn_qglVertex3f((w->p[i])[0], (w->p[i])[1], (w->p[i])[2]);
+ glVertex3f((w->p[i])[0], (w->p[i])[1], (w->p[i])[2]);
}
- __QGLTABLENAME.m_pfn_qglEnd();
+ glEnd();
}
-
-
- __QGLTABLENAME.m_pfn_qglPopMatrix();
-
- __QGLTABLENAME.m_pfn_qglPopAttrib();
}
-void DVisDrawer::Draw3D()
+void DVisDrawer::renderWireframe(Renderer& renderer, const VolumeTest& volume) const
{
if(!m_list)
return;
- __QGLTABLENAME.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS);
-
- __QGLTABLENAME.m_pfn_qglColor4f(1.0, 0.0, 0.0, 0.5f);
-
-// __QGLTABLENAME.m_pfn_qglHint(GL_FOG_HINT, GL_NICEST);
-
-// __QGLTABLENAME.m_pfn_qglDisable(GL_CULL_FACE);
- __QGLTABLENAME.m_pfn_qglDisable(GL_LINE_SMOOTH);
-
-// __QGLTABLENAME.m_pfn_qglPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-// __QGLTABLENAME.m_pfn_qglShadeModel(GL_SMOOTH);
+ renderer.SetState(m_shader_wireframe, Renderer::eWireframeOnly);
- __QGLTABLENAME.m_pfn_qglEnable(GL_BLEND);
- __QGLTABLENAME.m_pfn_qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- __QGLTABLENAME.m_pfn_qglDisable(GL_POLYGON_SMOOTH);
-
- __QGLTABLENAME.m_pfn_qglDepthFunc(GL_ALWAYS);
-
- //bleh
- list<DWinding *>::const_iterator l=m_list->begin();
-
- for(; l != m_list->end(); l++)
- {
- DWinding* w = *l;
-
- __QGLTABLENAME.m_pfn_qglColor4f(w->clr[0], w->clr[1], w->clr[2], 0.5f);
-
- __QGLTABLENAME.m_pfn_qglBegin(GL_POLYGON);
- for(int i = 0; i < w->numpoints; i++) {
- __QGLTABLENAME.m_pfn_qglVertex3f((w->p[i])[0], (w->p[i])[1], (w->p[i])[2]);
- }
- __QGLTABLENAME.m_pfn_qglEnd();
- }
-
- __QGLTABLENAME.m_pfn_qglPopAttrib();
+ renderer.addRenderable(*this, g_matrix4_identity);
}
-void DVisDrawer::Register()
+void DVisDrawer::renderSolid(Renderer& renderer, const VolumeTest& volume) const
{
- __QGLTABLENAME.m_pfnHookGL2DWindow( this );
- __QGLTABLENAME.m_pfnHookGL3DWindow( this );
- m_bHooked = TRUE;
-}
+ if(!m_list)
+ return;
-void DVisDrawer::UnRegister()
-{
- __QGLTABLENAME.m_pfnUnHookGL2DWindow( this );
- __QGLTABLENAME.m_pfnUnHookGL3DWindow( this );
- m_bHooked = FALSE;
+ renderer.SetState(m_shader_solid, Renderer::eWireframeOnly);
+ renderer.SetState(m_shader_solid, Renderer::eFullMaterials);
+
+ renderer.addRenderable(*this, g_matrix4_identity);
}
void DVisDrawer::SetList(std::list<DWinding*> *pointList)
void DVisDrawer::ClearPoints()
{
- list<DWinding *>::const_iterator deadPoint=m_list->begin();
+ std::list<DWinding *>::const_iterator deadPoint=m_list->begin();
for(; deadPoint!=m_list->end(); deadPoint++)
delete *deadPoint;
m_list->clear();
#pragma once
#endif // _MSC_VER > 1000
-class DVisDrawer :
- public IGL2DWindow,
- public IGL3DWindow
+#include <list>
+#include "renderable.h"
+#include "irender.h"
+
+#include "DWinding.h"
+
+class DVisDrawer : public Renderable, public OpenGLRenderable
{
+ Shader* m_shader_solid;
+ Shader* m_shader_wireframe;
public:
DVisDrawer();
virtual ~DVisDrawer();
protected:
- list<DWinding*>* m_list;
+ std::list<DWinding*>* m_list;
int refCount;
public:
void ClearPoints();
- void SetList(list<DWinding*>* pointList);
- void UnRegister();
- void Register();
- void Draw3D();
- void Draw2D(VIEWTYPE vt);
- void IncRef() { refCount++; }
- void DecRef() { refCount--; if (refCount <= 0) delete this; }
-
- bool m_bHooked;
+ void SetList(std::list<DWinding*>* pointList);
+
+ void render(RenderStateFlags state) const;
+ void renderSolid(Renderer& renderer, const VolumeTest& volume) const;
+ void renderWireframe(Renderer& renderer, const VolumeTest& volume) const;
+
+ void constructShaders();
+ void destroyShaders();
+
};
#endif // !defined(AFX_VISDRAWER_H__6E36062A_EF0B_11D4_ACF7_004095A18133__INCLUDED_)
//
//////////////////////////////////////////////////////////////////////
-#include "StdAfx.h"
+#include "DWinding.h"
-#include "gtkr_list.h"
+#include <list>
#include "DPoint.h"
-#include "DWinding.h"
#include "DPlane.h"
//////////////////////////////////////////////////////////////////////
int DWinding::WindingOnPlaneSide(vec3_t normal, vec_t dist)
{
- bool front = FALSE;
- bool back = FALSE;
+ bool front = false;
+ bool back = false;
for (int i = 0; i < numpoints; i++)
{
{
if (front)
return SIDE_CROSS;
- back = TRUE;
+ back = true;
continue;
}
if (d > ON_EPSILON)
{
if (back)
return SIDE_CROSS;
- front = TRUE;
+ front = true;
continue;
}
}
vec3_t dir, edgenormal;
if (numpoints < 3)
- Sys_Printf ("CheckWinding: %i points", numpoints);
+ globalOutputStream() << "CheckWinding: " << numpoints << " points\n";
vec_t area = WindingArea();
if (area < 1)
- Sys_Printf ("CheckWinding: %f area", area);
+ globalOutputStream() << "CheckWinding: " << area << " area\n";
DPlane* wPlane = WindingPlane ();
int i;
int j;
for (j = 0; j < 3; j++)
if (p1[j] > BOGUS_RANGE || p1[j] < -BOGUS_RANGE)
- Sys_Printf ("CheckFace: BUGUS_RANGE: %f", p1[j]);
+ globalOutputStream() << "CheckFace: BOGUS_RANGE: " << p1[j] << "\n";
j = i + 1 == numpoints ? 0 : i + 1;
// check the point is on the face plane
vec_t d = DotProduct (p1, wPlane->normal) - wPlane->_d;
if (d < -ON_EPSILON || d > ON_EPSILON)
- Sys_Printf ("CheckWinding: point off plane");
+ globalOutputStream() << "CheckWinding: point off plane\n";
// check the edge isnt degenerate
p2 = p[j];
VectorSubtract (p2, p1, dir);
if (VectorLength (dir) < ON_EPSILON)
- Sys_Printf ("CheckWinding: degenerate edge");
+ globalOutputStream() << "CheckWinding: degenerate edge\n";
CrossProduct (wPlane->normal, dir, edgenormal);
VectorNormalize (edgenormal, edgenormal);
d = DotProduct (p[j], edgenormal);
if (d > (edgedist + ON_EPSILON))
- Sys_Printf ("CheckWinding: non-convex");
+ globalOutputStream() << "CheckWinding: non-convex\n";
}
}
if (!counts[0])
{
delete this;
- return FALSE;
+ return false;
}
if (!counts[1])
- return TRUE;
+ return true;
int maxpts = numpoints+4; // cant use counts[0]+2 because
// of fp grouping errors
}
if (f->numpoints > maxpts)
- Sys_Printf ("ClipWinding: points exceeded estimate");
+ globalOutputStream() << "ClipWinding: points exceeded estimate\n";
if (f->numpoints > MAX_POINTS_ON_WINDING)
- Sys_Printf ("ClipWinding: MAX_POINTS_ON_WINDING");
+ globalOutputStream() << "ClipWinding: MAX_POINTS_ON_WINDING\n";
delete[] p;
p = f->p;
f->p = NULL;
delete f;
- return TRUE;
+ return true;
}
void DWinding::ClipWindingEpsilon(DPlane* chopPlane, vec_t epsilon, DWinding **front, DWinding **back)
}
if (f->numpoints > maxpts || b->numpoints > maxpts)
- Sys_Printf ("ClipWinding: points exceeded estimate");
+ globalOutputStream() << "ClipWinding: points exceeded estimate\n";
if (f->numpoints > MAX_POINTS_ON_WINDING || b->numpoints > MAX_POINTS_ON_WINDING)
- Sys_Printf ("ClipWinding: MAX_POINTS_ON_WINDING");
+ globalOutputStream() << "ClipWinding: MAX_POINTS_ON_WINDING\n";
}
bool DWinding::ChopWinding(DPlane* chopPlane)
if(!f)
{
delete this;
- return FALSE;
+ return false;
}
delete[] p;
numpoints = f->numpoints;
delete f;
- return TRUE;
+ return true;
}
#pragma once
#endif // _MSC_VER > 1000
+#include "mathlib.h"
+
class DPlane;
class DWinding
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "StdAfx.h"
#include "ScriptParser.h"
CScriptParser::CScriptParser(void):
#ifndef __STDAFX_BOBTOOLZ__
#define __STDAFX_BOBTOOLZ__
-#define BOBTOOLZ_MINOR "bobtoolz"
-#include <gdk/gdkkeysyms.h>
-#include <gtk/gtk.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "time.h"
-
-#define NAME_MAX 255
-
-#if defined (__linux__) || defined (__APPLE__)
-
-#include <GL/glx.h>
-
-typedef void* HMODULE;
-typedef void* LPVOID;
-typedef char* LPCSTR;
-//typedef int bool;
-
-
-#define WINAPI
-#define APIENTRY
-
-#ifndef GUID_DEFINED
-#define GUID_DEFINED
-typedef struct _GUID
-{
- unsigned long Data1;
- unsigned short Data2;
- unsigned short Data3;
- unsigned char Data4[8];
-} GUID;
-
-#define stricmp strcasecmp
-
-#endif
-
-#if defined(__cplusplus)
-#ifndef _REFGUID_DEFINED
-#define _REFGUID_DEFINED
-#define REFGUID const GUID &
-#endif // !_REFGUID_DEFINED
-#endif
-
-typedef struct tagRECT
-{
- long left;
- long top;
- long right;
- long bottom;
-} RECT, *PRECT, *LPRECT;
-
-typedef uint UINT;
-
-#endif // __linux__
-
-#include "mathlib.h"
-#include <string.h>
-#include "qertypes.h"
-#include <stdio.h>
-
-#define USE_SCENEGRAPHTABLE_DEFINE
-#include "iscenegraph.h"
-
-#define USE_QERTABLE_DEFINE
-#include "qerplugin.h"
-extern _QERFuncTable_1 __QERTABLENAME;
-
-#define USE_ENTITYTABLE_DEFINE
-#include "ientity.h"
-extern _QEREntityTable __ENTITYTABLENAME;
-
-#define USE_BRUSHTABLE_DEFINE
-#include "ibrush.h"
-extern _QERBrushTable __BRUSHTABLENAME;
-
-#define USE_PATCHTABLE_DEFINE
-#include "ipatch.h"
-extern _QERPatchTable __PATCHTABLENAME;
-
-#define USE_SHADERSTABLE_DEFINE
-#include "ishaders.h"
-extern _QERShadersTable __SHADERSTABLENAME;
-
-#define USE_QGLTABLE_DEFINE
-#include "igl.h"
-extern _QERQglTable __QGLTABLENAME;
-
-#include "ibspfrontend.h"
-extern _QERAppBSPFrontendTable g_BSPTable;
-
-#include "iui.h"
-extern _QERUITable g_MessageTable;
-
-#define USE_RENDERTABLE_DEFINE
-#include "irender.h"
-
-#define USE_SELECTIONTABLE_DEFINE
-#include "iselection.h"
-
-#include "itoolbar.h"
-
-
-#include "iplugin.h"
-
-#define MAX_ROUND_ERROR 0.05
-
-#include "itexdef.h"
-
-struct _QERFaceData
-{
- vec3_t m_p0;
- vec3_t m_p1;
- vec3_t m_p2;
- texdef_t m_texdef;
-};
#endif
#include "libxml/parser.h"
-#include "StdAfx.h"
#include "str.h"
-//#include "gtkr_list.h"
#include "funchandlers.h"
-//#include "misc.h"
#include "dialogs/dialogs-gtk.h"
#include "../../libs/cmdlib.h"
+void BobToolz_construct()
+{
+}
+
+void BobToolz_destroy()
+{
+}
+
// Radiant function table
_QERFuncTable_1 __QERTABLENAME;
_QERShadersTable __SHADERSTABLENAME; // vvvvvvvvvvvvvvvvvvvv
extern "C" void QERPlug_Dispatch (const char *p, vec3_t vMin, vec3_t vMax, bool bSingleBrush) {
LoadLists();
- if( !stricmp( p, "brush cleanup" ) ) {
+ if( string_equal_nocase( p, "brush cleanup" ) ) {
DoFixBrushes();
- } else if( !stricmp( p, "polygon builder" ) ) {
+ } else if( string_equal_nocase( p, "polygon builder" ) ) {
DoPolygonsTB();
- } else if( !stricmp( p, "caulk selection" ) ) {
+ } else if( string_equal_nocase( p, "caulk selection" ) ) {
DoCaulkSelection();
- } else if( !stricmp( p, "tree planter" ) ) {
+ } else if( string_equal_nocase( p, "tree planter" ) ) {
DoTreePlanter();
- } else if( !stricmp( p, "plot splines" ) ) {
+ } else if( string_equal_nocase( p, "plot splines" ) ) {
DoTrainPathPlot();
- } else if( !stricmp( p, "drop entity" ) ) {
+ } else if( string_equal_nocase( p, "drop entity" ) ) {
DoDropEnts();
- } else if( !stricmp( p, "merge patches" ) ) {
+ } else if( string_equal_nocase( p, "merge patches" ) ) {
DoMergePatches();
- } else if( !stricmp( p, "split patches" ) ) {
+ } else if( string_equal_nocase( p, "split patches" ) ) {
DoSplitPatch();
- } else if( !stricmp( p, "turn edge" ) ) {
+ } else if( string_equal_nocase( p, "turn edge" ) ) {
DoFlipTerrain();
- } else if( !stricmp(p, "reset textures...") ) {
+ } else if( string_equal_nocase(p, "reset textures...") ) {
DoResetTextures();
- } else if( !stricmp(p, "pitomatic") ) {
+ } else if( string_equal_nocase(p, "pitomatic") ) {
DoPitBuilder();
- } else if( !stricmp(p, "vis viewer") ) {
+ } else if( string_equal_nocase(p, "vis viewer") ) {
DoVisAnalyse();
- } else if( !stricmp(p, "about...") ) {
+ } else if( string_equal_nocase(p, "about...") ) {
DoMessageBox(PLUGIN_ABOUT, "About", eMB_OK);
}
}
virtual ~CSynapseClientBobtoolz() { }
};
+#define BOBTOOLZ_MINOR "bobtoolz"
CSynapseServer* g_pSynapseServer = NULL;
CSynapseClientBobtoolz g_SynapseClient;
return "bobToolz module built " __DATE__ " " RADIANT_VERSION;
}
-char* GetFilename(char* buffer, const char* filename) {
- strcpy(buffer, g_pSynapseServer->GetModuleFilename(&g_SynapseClient));
- StripFilename( buffer );
- strcat(buffer, "/");
- strcat(buffer, filename);
- //buffer = UnixToDosPath(buffer);
- return buffer;
-}
EXPORTS
; Explicit exports can go here
- Synapse_EnumerateInterfaces @1
+ Radiant_RegisterModules @1
-#include "StdAfx.h"
-#include "./dialogs/dialogs-gtk.h"
#include "bsploader.h"
-#include "../../libs/cmdlib.h"
+#include "dialogs/dialogs-gtk.h"
+#include "cmdlib.h"
int numnodes;
int numplanes;
return true;
}
-/*int LittleLong (int l)
+int LittleLong (int l)
{
+#if defined(__BIG_ENDIAN__)
+ std::reverse(reinterpret_cast<unsigned char*>(&l), reinterpret_cast<unsigned char*>(&l) + sizeof(int));
+#endif
return l;
}
float LittleFloat (float l)
{
+#if defined(__BIG_ENDIAN__)
+ std::reverse(reinterpret_cast<unsigned char*>(&l), reinterpret_cast<unsigned char*>(&l) + sizeof(float));
+#endif
return l;
-}*/
+}
/*
=============
+
+#include "mathlib.h"
+
#define LUMP_ENTITIES 0
#define LUMP_SHADERS 1
#define LUMP_PLANES 2
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "StdAfx.h"
#include "CPortals.h"
-//#include "misc.h"
+
+#include <string.h>
+#include <math.h>
+
+#include "misc.h"
#define LINE_BUF 1000
#define MSG_PREFIX "bobToolz plugin: "
point_count = pointCnt;
if(point_count < 3)
- return FALSE;
+ return false;
point = new CBspPoint[point_count];
for(; *c != 0 && *c != '('; c++);
if(*c == 0)
- return FALSE;
+ return false;
c++;
ClampFloat(&point[x].p[2]);
}
- return TRUE;
+ return true;
}
CPortals::CPortals()
Purge();
- Sys_Printf(MSG_PREFIX "Loading portal file %s.\n", fn);
+ globalOutputStream() << MSG_PREFIX "Loading portal file " << fn << ".\n";
FILE *in;
if(in == NULL)
{
- Sys_Printf(" ERROR - could not open file.\n");
+ globalOutputStream() << " ERROR - could not open file.\n";
return;
}
{
fclose(in);
- Sys_Printf(" ERROR - File ended prematurely.\n");
+ globalOutputStream() << " ERROR - File ended prematurely.\n";
return;
}
{
fclose(in);
- Sys_Printf(" ERROR - File header indicates wrong file type (should be \"PRT1\").\n");
+ globalOutputStream() << " ERROR - File header indicates wrong file type (should be \"PRT1\").\n";
return;
}
{
fclose(in);
- Sys_Printf(" ERROR - File ended prematurely.\n");
+ globalOutputStream() << " ERROR - File ended prematurely.\n";
return;
}
node_count = 0;
- Sys_Printf(" ERROR - Extreme number of nodes, aborting.\n");
+ globalOutputStream() << " ERROR - Extreme number of nodes, aborting.\n";
return;
}
node_count = 0;
- Sys_Printf(" ERROR - File ended prematurely.\n");
+ globalOutputStream() << " ERROR - File ended prematurely.\n";
return;
}
node_count = 0;
- Sys_Printf(" ERROR - File ended prematurely.\n");
+ globalOutputStream() << " ERROR - File ended prematurely.\n";
return;
}
node_count = 0;
- Sys_Printf(" ERROR - File ended prematurely.\n");
+ globalOutputStream() << " ERROR - File ended prematurely.\n";
return;
}
node_count = 0;
- Sys_Printf(" ERROR - File ended prematurely.\n");
+ globalOutputStream() << " ERROR - File ended prematurely.\n";
return;
}
Purge();
- Sys_Printf(" ERROR - Could not find information for portal number %d of %d.\n", n + 1, p_count);
+ globalOutputStream() << " ERROR - Could not find information for portal number " << n + 1 << " of " << p_count << ".\n";
return;
}
unsigned int pCount, node1, node2;
sscanf(buf, "%u %u %u", &pCount, &node1, &node2);
- if(!node[node1].AddPortal(buf, pCount, FALSE))
+ if(!node[node1].AddPortal(buf, pCount, false))
{
fclose(in);
Purge();
- Sys_Printf(" ERROR - Information for portal number %d of %d is not formatted correctly.\n", n + 1, p_count);
+ globalOutputStream() << " ERROR - Information for portal number " << n + 1 << " of " << p_count << " is not formatted correctly.\n";
return;
}
- if(!node[node2].AddPortal(buf, pCount, TRUE))
+ if(!node[node2].AddPortal(buf, pCount, true))
{
fclose(in);
Purge();
- Sys_Printf(" ERROR - Information for portal number %d of %d is not formatted correctly.\n", n + 1, p_count);
+ globalOutputStream() << " ERROR - Information for portal number " << n + 1 << " of " << p_count << " is not formatted correctly.\n";
return;
}
Purge();
- Sys_Printf(" ERROR - Could not find information for portal number %d of %d.\n", n + 1, p_count);
+ globalOutputStream() << " ERROR - Could not find information for portal number " << n + 1 << " of " << p_count << ".\n";
return;
}
unsigned int pCount, node1;
sscanf(buf, "%u %u", &pCount, &node1);
- if(!node[node1].AddPortal(buf, pCount, FALSE))
+ if(!node[node1].AddPortal(buf, pCount, false))
{
fclose(in);
Purge();
- Sys_Printf(" ERROR - Information for portal number %d of %d is not formatted correctly.\n", n + 1, p_count);
+ globalOutputStream() << " ERROR - Information for portal number " << n + 1 << " of " << p_count << " is not formatted correctly.\n";
return;
}
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "../StdAfx.h"
-
-
#include "dialogs-gtk.h"
#include "../funchandlers.h"
#include "str.h"
-#include "gtkr_list.h"
+#include <list>
#include "../lists.h"
#include "../misc.h"
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#if !defined(INCLUDED_DIALOGS_GTK_H)
+#define INCLUDED_DIALOGS_GTK_H
+
+#include "qerplugin.h"
+
struct BuildStairsRS{
char mainTexture[256];
char riserTexture[256];
bool bShowExtra;
};
+typedef struct _GtkWidget GtkWidget;
+
struct TwinWidget{
GtkWidget* one;
GtkWidget* two;
EMessageBoxReturn DoTrainThingBox (TrainThingRS* rs);
//GtkWidget* GetProgressWindow(char* title, GtkProgressBar* feedback);
+
+#endif
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "StdAfx.h"
+#include "funchandlers.h"
#ifdef WIN32
#pragma warning(disable : 4786)
#include "dialogs/dialogs-gtk.h"
-#include "gtkr_list.h"
+#include <list>
#include "str.h"
#include "DPoint.h"
#include "shapes.h"
#include "lists.h"
-#include "funchandlers.h"
#include "visfind.h"
#include "iundo.h"
-#include "refcounted_ptr.h"
-
#include <vector>
#include <list>
#include <map>
#include "scenelib.h"
// for autocaulk
-list<Str> exclusionList; // whole brush exclusion
-list<Str> exclusionList_Face; // single face exclusion
+std::list<Str> exclusionList; // whole brush exclusion
+std::list<Str> exclusionList_Face; // single face exclusion
bool el1Loaded = FALSE;
bool el2Loaded = FALSE;
VectorSubtract(instance.aabb_world().origin, instance.aabb_world().extents, vMin);
VectorAdd(instance.aabb_world().origin, instance.aabb_world().extents, vMax);
- instance.path().parent()->m_traverse->erase(instance.path().top());
+ Node_getTraversable(instance.path().parent())->erase(instance.path().top());
}
if(rs.bInverse)
{
{
scene::Instance& instance = GlobalSelectionSystem().ultimateSelected();
- instance.path().parent()->m_traverse->erase(instance.path().top());
+ Node_getTraversable(instance.path().parent())->erase(instance.path().top());
}
// Get Step Count
scene::Instance& instance = GlobalSelectionSystem().ultimateSelected();
VectorSubtract(instance.aabb_world().origin, instance.aabb_world().extents, vMin);
VectorAdd(instance.aabb_world().origin, instance.aabb_world().extents, vMax);
- instance.path().parent()->m_traverse->erase(instance.path().top());
+ Node_getTraversable(instance.path().parent())->erase(instance.path().top());
}
BuildDoorsX2(vMin, vMax,
return;
}
- scene::Instance& instance = GlobalSelectionSystem().ultimateSelected();
-
- DEntity world;
- world.LoadEPairList(instance.path().top()->m_entity);
-
- DEPair* trigger_ep = world.FindEPairByKey("targetname");
-
- if(trigger_ep)
- {
- if(!strcmp(world.m_Classname, "trigger_push"))
- {
- DEPair* target_ep = world.FindEPairByKey("target");
- if(target_ep)
- {
- scene::Path* entTarget = FindEntityFromTargetname(target_ep->value, NULL);
- if(entTarget)
- {
- if(g_PathView)
- delete g_PathView;
- g_PathView = new DBobView;
-
- g_PathView->Begin(trigger_ep->value, target_ep->value, rs.fMultiplier, rs.nPoints, rs.fGravity, rs.bNoUpdate, rs.bShowExtra);
- }
- else
- DoMessageBox("trigger_push target could not be found.", "Error", eMB_OK);
- }
- else
- DoMessageBox("trigger_push has no target.", "Error", eMB_OK);
- }
- else
- DoMessageBox("You must select a 'trigger_push' entity.", "Error", eMB_OK);
- }
- else
- DoMessageBox("Entity must have a targetname", "Error", eMB_OK);
+ Entity* entity = Node_getEntity(GlobalSelectionSystem().ultimateSelected().path().top());
+ if(entity != 0)
+ {
+ DBobView_setEntity(*entity, rs.fMultiplier, rs.nPoints, rs.fGravity, rs.bNoUpdate, rs.bShowExtra);
+ }
}
void DoPitBuilder()
{
pit.Commit();
- instance.path().parent()->m_traverse->erase(instance.path().top());
+ Node_getTraversable(instance.path().parent())->erase(instance.path().top());
}
else
DoMessageBox("Failed To Make Pit\nTry Making The Brush Bigger", "Error", eMB_OK);
scene::Node* patches[2];
patches[0] = GlobalSelectionSystem().ultimateSelected().path().top();
patches[1] = GlobalSelectionSystem().penultimateSelected().path().top();
+ scene::Node* ents[2];
+ ents[0] = GlobalSelectionSystem().ultimateSelected().path().parent();
+ ents[1] = GlobalSelectionSystem().penultimateSelected().path().parent();
for (i = 0; i < 2; i++)
{
{
} else
{
- mrgPatches[0].RemoveFromRadiant();
- mrgPatches[1].RemoveFromRadiant();
+ Node_getTraversable(*ents[0])->erase(*patches[0]);
+ Node_getTraversable(*ents[1])->erase(*patches[1]);
newPatch->BuildInRadiant();
delete newPatch;
patch.LoadFromBrush(node);
- list<DPatch> patchList = patch.Split( true, true );
- for(list<DPatch>::iterator patches = patchList.begin(); patches != patchList.end(); patches++) {
+ std::list<DPatch> patchList = patch.Split( true, true );
+ for(std::list<DPatch>::iterator patches = patchList.begin(); patches != patchList.end(); patches++) {
(*patches).BuildInRadiant();
}
char* ext = strrchr(filename, '.')+1;
strcpy(ext, "bsp");// rename the extension
- list<DWinding*> *pointList = BuildTrace(filename, origin);
+ std::list<DWinding*> *pointList = BuildTrace(filename, origin);
if(!g_VisView)
{
ents[1] = GlobalSelectionSystem().penultimateSelected().path().parent();
for( i = 0; i < 2; i++ ) {
- Brushes[i].RemoveFromRadiant();
+ Node_getTraversable(*ents[i])->erase(*brushes[i]);
}
#include "DShape.h"
// for autocaulk
-list<Str> exclusionList; // whole brush exclusion
-list<Str> exclusionList_Face; // single face exclusion
+std::list<Str> exclusionList; // whole brush exclusion
+std::list<Str> exclusionList_Face; // single face exclusion
BOOL el1Loaded;
BOOL el2Loaded;
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "StdAfx.h"
+#include "lists.h"
#ifdef WIN32
#pragma warning(disable : 4786)
#endif
-#include "gtkr_list.h"
-#include "str.h"
+#include <glib/glist.h>
-#include "lists.h"
#include "misc.h"
-bool LoadExclusionList(char* filename, list<Str>* exclusionList)
+bool LoadExclusionList(char* filename, std::list<Str>* exclusionList)
{
FILE* eFile = fopen(filename, "r");
if(eFile)
return TRUE;
}
- Sys_ERROR("Failed To Load Exclusion List: %s\n", filename);
+ globalErrorStream() << "Failed To Load Exclusion List: " << filename << "\n";
return FALSE;
}
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-bool LoadExclusionList(char* filename, list<Str>* exclusionList);
+#include <list>
+#include "str.h"
+typedef struct _GList GList;
+
+bool LoadExclusionList(char* filename, std::list<Str>* exclusionList);
bool LoadGList(char* filename, GList** loadlist);
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "StdAfx.h"
+#include "misc.h"
-#include "gtkr_list.h"
+#include <list>
#include "str.h"
-#include "misc.h"
-
#include "DPoint.h"
#include "DPlane.h"
#include "DBrush.h"
#endif
#include "iundo.h"
-
-#include "refcounted_ptr.h"
+#include "qerplugin.h"
#include <vector>
#include <list>
void ReadCurrentTexture()
{
- const char* textureName = g_FuncTable.m_pfnGetCurrentTexture();
+ const char* textureName = GlobalRadiant().TextureBrowser_getSelectedShader();
strcpy(g_CurrentTexture, textureName);
}
return buf2;
}
-void Sys_ERROR (char* text, ...)
-{
- va_list argptr;
- char buf[32768];
-
- va_start (argptr,text);
- vsprintf (buf, text,argptr);
- va_end (argptr);
-
- Sys_Printf("BobToolz::ERROR->%s", buf);
-}
-
-/*void Sys_Printf (char *text, ...)
-{
- va_list argptr;
- char buf[32768];
-
- va_start (argptr,text);
- vsprintf (buf, text,argptr);
- va_end (argptr);
-
- g_FuncTable.m_pfnSysMsg ( buf );
-}*/
char* UnixToDosPath(char* path)
{
Q_Exec( command, TRUE );
}
-void BuildMiniPrt(list<Str>* exclusionList)
+void BuildMiniPrt(std::list<Str>* exclusionList)
{
// yes, we could just use -fulldetail option, but, as SPOG said
// it'd be faster without all the hint, donotenter etc textures and
StartBSP();
}
+template<typename Functor>
+class EntityWalker
+{
+ const Functor& functor;
+public:
+ EntityWalker(const Functor& functor) : functor(functor)
+ {
+ }
+ bool pre(const Path& path, Instance& instance) const
+ {
+ if(Node_isEntity(path.top()))
+ {
+ functor(path.top());
+ }
+ }
+};
+
+template<typename Functor>
+const Functor& Scene_forEachEntity(const Functor& functor)
+{
+ GlobalSceneGraph().traverse(EntityWalker<Functor>(functor));
+}
+
+void
+
scene::Path* FindEntityFromTargetname(const char* targetname, int* entNum)
{
#if 0
DEPair* tn = world.FindEPairByKey("targetname");
if(tn)
{
- if(!stricmp(tn->value, targetname)) {
+ if(string_equal_nocase(tn->value, targetname)) {
if(entNum) {
*entNum = i;
}
faceData->m_texdef.flags = 0;
faceData->m_texdef.value = 0;
if(*texture)
- faceData->m_texdef.SetName(texture);
+ faceData->m_shader = texture;
else
- faceData->m_texdef.SetName("textures/common/caulk");
+ faceData->m_shader = "textures/common/caulk";
VectorCopy(va, faceData->m_p0);
VectorCopy(vb, faceData->m_p1);
VectorCopy(vc, faceData->m_p2);
return b;
}
-void MakeNormal( vec_t* va, vec_t* vb, vec_t* vc, vec_t* out ) {
+void MakeNormal( const vec_t* va, const vec_t* vb, const vec_t* vc, vec_t* out ) {
vec3_t v1, v2;
VectorSubtract(va, vb, v1);
VectorSubtract(vc, vb, v2);
CrossProduct(v1, v2, out);
}
+
+char* GetFilename(char* buffer, const char* filename) {
+ strcpy(buffer, g_pSynapseServer->GetModuleFilename(&g_SynapseClient));
+ StripFilename( buffer );
+ strcat(buffer, "/");
+ strcat(buffer, filename);
+ //buffer = UnixToDosPath(buffer);
+ return buffer;
+}
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#if !defined(INCLUDED_MISC_H)
+#define INCLUDED_MISC_H
+
+#include "mathlib.h"
+#include <list>
+#include "str.h"
+#include "iscenegraph.h"
+
+#define MAX_ROUND_ERROR 0.05
+
vec_t Min(vec_t a, vec_t b);
// reads current texture into global, returns pointer to it
const char* GetCurrentTexture();
-void FillDefaultTexture(_QERFaceData* faceData, vec3_t va, vec3_t vb, vec3_t vc, const char* texture);
+void FillDefaultTexture(void* faceData, vec3_t va, vec3_t vb, vec3_t vc, const char* texture);
-void Sys_ERROR (char* text, ...);
-
-void BuildMiniPrt(list<Str>* exclusionList);
+void BuildMiniPrt(std::list<Str>* exclusionList);
void MoveBlock(int dir, vec3_t min, vec3_t max, float dist);
void SetInitialStairPos(int dir, vec3_t min, vec3_t max, float width);
float c1, float c2, float c3);
bool GetEntityCentre(const char* entity, vec3_t centre);
-void MakeNormal( vec_t* va, vec_t* vb, vec_t* vc, vec_t* out );
+void MakeNormal( const vec_t* va, const vec_t* vb, const vec_t* vc, vec_t* out );
+
+#endif
*/
-#include "StdAfx.h"
-
#include "shapes.h"
-#include "gtkr_list.h"
+#include <list>
#include "DPoint.h"
#include "DPlane.h"
return (float)(angle*Q_PI/180);
}
-void AddFaceWithTexture(scene::Node* brush, vec3_t va, vec3_t vb, vec3_t vc, const char* texture, bool detail)
+void AddFaceWithTexture(scene::Node& brush, vec3_t va, vec3_t vb, vec3_t vc, const char* texture, bool detail)
{
_QERFaceData faceData;
FillDefaultTexture(&faceData, va, vb, vc, texture);
if(detail)
faceData.m_texdef.contents |= FACE_DETAIL;
-#if 0
- brush->m_brush->addPlane(faceData.m_p0, faceData.m_p1, faceData.m_p2, faceData.m_texdef);
-#endif
+ GlobalBrushCreator().addBrushFace(brush, faceData);
}
-void AddFaceWithTextureScaled(scene::Node* brush, vec3_t va, vec3_t vb, vec3_t vc,
+void AddFaceWithTextureScaled(scene::Node& brush, vec3_t va, vec3_t vb, vec3_t vc,
const char* texture, bool bVertScale, bool bHorScale,
float minX, float minY, float maxX, float maxY)
{
addFace.m_texdef.shift[0] = shift[0];
addFace.m_texdef.shift[1] = shift[1];
-#if 0
- brush->m_brush->addPlane(addFace.m_p0, addFace.m_p1, addFace.m_p2, addFace.m_texdef);
-#endif
+ GlobalBrushCreator().addBrushFace(brush, addFace);
}
else
{
void Build_Wedge(int dir, vec3_t min, vec3_t max, bool bUp)
{
- scene::Node* newBrush = Brush_AllocNode();
+ NodeSmartReference newBrush(GlobalBrushCreator().createBrush());
vec3_t v1, v2, v3, v5, v6, v7, v8;
VectorCopy(min, v1);
AddFaceWithTexture(newBrush, v7, v8, v3, "textures/common/caulk", FALSE);
}
- GetWorldspawn()->m_traverse->insert(newBrush);
+ Node_getTraversable(GetWorldspawn())->insert(newBrush);
}
//-----------------------------------------------------------------------------------
void Build_StairStep_Wedge(int dir, vec3_t min, vec3_t max, const char* mainTexture, const char* riserTexture, bool detail)
{
- scene::Node* newBrush = Brush_AllocNode();
+ NodeSmartReference newBrush(GlobalBrushCreator().createBrush());
//----- Build Outer Bounds ---------
if(dir == MOVE_SOUTH)
AddFaceWithTexture(newBrush, v7, v8, v3, "textures/common/caulk", detail);
- GetWorldspawn()->m_traverse->insert(newBrush);
+ Node_getTraversable(GetWorldspawn())->insert(newBrush);
}
//-----------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------
// internal use only, to get a box without finishing construction
-scene::Node* Build_Get_BoundingCube_Selective(vec3_t min, vec3_t max, char* texture, bool* useFaces)
+scene::Node& Build_Get_BoundingCube_Selective(vec3_t min, vec3_t max, char* texture, bool* useFaces)
{
- scene::Node* newBrush = Brush_AllocNode();
+ scene::Node& newBrush(GlobalBrushCreator().createBrush());
//----- Build Outer Bounds ---------
return newBrush;
}
-scene::Node* Build_Get_BoundingCube(vec3_t min, vec3_t max, char* texture)
+scene::Node& Build_Get_BoundingCube(vec3_t min, vec3_t max, char* texture)
{
return Build_Get_BoundingCube_Selective(min, max, texture, bFacesAll);
}
void Build_StairStep(vec3_t min, vec3_t max, const char* mainTexture, const char* riserTexture, int direction)
{
- scene::Node* newBrush = Brush_AllocNode();
+ scene::Node& newBrush(GlobalBrushCreator().createBrush());
//----- Build Outer Bounds ---------
AddFaceWithTexture(newBrush, v1, v2, v3, "textures/common/caulk", FALSE);
// base is caulked
- GetWorldspawn()->m_traverse->insert(newBrush);
+ Node_getTraversable(GetWorldspawn())->insert(newBrush);
// finish brush
}
//----------------------------------
- scene::Node* newBrush1 = Brush_AllocNode();
- scene::Node* newBrush2 = Brush_AllocNode();
+ NodeSmartReference newBrush1(GlobalBrushCreator().createBrush());
+ NodeSmartReference newBrush2(GlobalBrushCreator().createBrush());
AddFaceWithTexture(newBrush1, v1, v2, v3, "textures/common/caulk", FALSE);
AddFaceWithTexture(newBrush1, v5, v7, v6, "textures/common/caulk", FALSE);
//----------------------------------
- scene::Node* pEDoor1 = GlobalEntityCreator().createEntity("func_door");
- scene::Node* pEDoor2 = GlobalEntityCreator().createEntity("func_door");
+ NodeSmartReference pEDoor1 = GlobalEntityCreator().createEntity("func_door");
+ NodeSmartReference pEDoor2 = GlobalEntityCreator().createEntity("func_door");
if(direction == 0)
{
pEDoor1->m_entity->setkeyvalue("team", teamname);
pEDoor2->m_entity->setkeyvalue("team", teamname);
- pEDoor1->m_traverse->insert(newBrush1);
- pEDoor2->m_traverse->insert(newBrush2);
+ Node_getTraversable(pEDoor1)->insert(newBrush1);
+ Node_getTraversable(pEDoor2)->insert(newBrush2);
- GlobalSceneGraph().root()->m_traverse->insert(pEDoor1);
- GlobalSceneGraph().root()->m_traverse->insert(pEDoor2);
+ Node_getTraversable(GlobalSceneGraph().root())->insert(pEDoor1);
+ Node_getTraversable(GlobalSceneGraph().root())->insert(pEDoor2);
// ResetCurrentTexture();
}
void MakeBevel(vec3_t vMin, vec3_t vMax)
{
- scene::Node* patch = Patch_AllocNode();
+ NodeSmartReference patch(GlobalPatchCreator().createPatch());
aabb_t aabb;
aabb_construct_for_vec3(&aabb, vMin, vMax);
#if 0
patch->m_patch->ConstructPrefab(&aabb, eBevel, 2); // 2 == XY view
#endif
- GetWorldspawn()->m_traverse->insert(patch);
+ Node_getTraversable(GetWorldspawn())->insert(patch);
}
void BuildCornerStairs(vec3_t vMin, vec3_t vMax, int nSteps, const char* mainTexture, const char* riserTex)
for(i = 0; i < nSteps; i++)
{
- scene::Node* brush = Build_Get_BoundingCube_Selective(vBot, vTop, "textures/common/caulk", bFacesUse);
+ scene::Node& brush = Build_Get_BoundingCube_Selective(vBot, vTop, "textures/common/caulk", bFacesUse);
for(int j = 0; j < 3; j++)
tp[j][2] = vTop[2];
AddFaceWithTexture(brush, centre, botPoints[i+1], topPoints[i+1], "textures/common/caulk", FALSE);
AddFaceWithTexture(brush, centre, topPoints[i], botPoints[i], riserTex, FALSE);
- GetWorldspawn()->m_traverse->insert(brush);
+ Node_getTraversable(GetWorldspawn())->insert(brush);
vTop[2] += height;
vBot[2] += height;
#define MAX_POLYGON_FACES 128
// generic (detail added 12/01/01, for AC+)
-void AddFaceWithTexture(scene::Node* brush, vec3_t va, vec3_t vb, vec3_t vc, const char* texture, bool detail);
+void AddFaceWithTexture(scene::Node& brush, vec3_t va, vec3_t vb, vec3_t vc, const char* texture, bool detail);
// -------------
// ---caulked---
// Date: Oct 5, 2001
// Written by: Brad Whitehead (whiteheb@gamerstv.net)
-#include "StdAfx.h"
+#include "visfind.h"
#include "dialogs/dialogs-gtk.h"
#include "DWinding.h"
#include "bsploader.h"
-#include "gtkr_list.h"
+#include <list>
typedef struct {
int portalclusters;
return(c);
}
-void AddCluster(list<DWinding*> *pointlist, dleaf_t *cl, bool* repeatlist, vec3_t clr)
+void AddCluster(std::list<DWinding*> *pointlist, dleaf_t *cl, bool* repeatlist, vec3_t clr)
{
DWinding* w;
CreateTrace
=============
*/
-list<DWinding*> *CreateTrace( dleaf_t *leaf, int c, vis_header *header, byte *visdata, byte *seen )
+std::list<DWinding*> *CreateTrace( dleaf_t *leaf, int c, vis_header *header, byte *visdata, byte *seen )
{
byte *vis;
int i, j, clusterNum;
- list<DWinding*> *pointlist = new list<DWinding*>;
+ std::list<DWinding*> *pointlist = new std::list<DWinding*>;
bool* repeatlist = new bool[numDrawSurfaces];
dleaf_t *cl;
setup for CreateTrace
=============
*/
-list<DWinding*> *TraceCluster (int leafnum)
+std::list<DWinding*> *TraceCluster (int leafnum)
{
byte seen[(MAX_MAP_LEAFS/8) + 1];
vis_header *vheader;
return CreateTrace(leaf, leaf->cluster, vheader, visdata, seen);
}
-list<DWinding *>* BuildTrace(char* filename, vec3_t v_origin)
+std::list<DWinding *>* BuildTrace(char* filename, vec3_t v_origin)
{
if(!LoadBSPFile(filename))
return NULL;
int leafnum = bsp_leafnumfororigin(v_origin);
- list<DWinding*> *pointlist = TraceCluster(leafnum);
+ std::list<DWinding*> *pointlist = TraceCluster(leafnum);
FreeBSPData();
-list<DWinding*> *BuildTrace(char* filename, vec3_t v_origin);
+
+#include <list>
+#include "mathlib.h"
+
+class DWinding;
+
+std::list<DWinding*> *BuildTrace(char* filename, vec3_t v_origin);
#if 0
patch->m_patch->SetShader(Texture[Game][0]);
#endif
- h_worldspawn->m_traverse->insert(patch);
+ Node_getTraversable(h_worldspawn)->insert(patch);
return patch;
}
}
#endif
- h_func_group->m_traverse->insert(node);
+ Node_getTraversable(h_func_group)->insert(node);
}
//=============================================================
void OpenFuncGroup()
GlobalOpenGLStateLibrary().insert(g_state_wireframe, state);
GlobalOpenGLStateLibrary().getDefaultState(state);
- state.m_state = RENDER_FILL|RENDER_BLEND|RENDER_COLOURWRITE|RENDER_COLOURCHANGE|RENDER_SMOOTH|RENDER_POLYGONSMOOTH;
+ state.m_state = RENDER_FILL|RENDER_BLEND|RENDER_COLOURWRITE|RENDER_COLOURCHANGE|RENDER_SMOOTH;
if(portals.aa_3d)
{
#define INCLUDED_IBRUSH_H
#include "generic/constant.h"
+#include "generic/callback.h"
+#include "math/vector.h"
+#include "itexdef.h"
namespace scene
{
class Node;
}
+#if 0
+class IBrushFace
+{
+public:
+ virtual const char* GetShader() const = 0;
+ virtual void SetShader(const char* name) = 0;
+ virtual const TextureProjection& GetTexdef() const = 0;
+ virtual void GetTexdef(TextureProjection& projection) const = 0;
+ virtual void SetTexdef(const TextureProjection& projection) = 0;
+ virtual void GetFlags(ContentsFlagsValue& flags) const = 0;
+ virtual void SetFlags(const ContentsFlagsValue& flags) = 0;
+ virtual void ShiftTexdef(float s, float t) = 0;
+ virtual void ScaleTexdef(float s, float t) = 0;
+ virtual void RotateTexdef(float angle) = 0;
+ virtual void FitTexture(float s_repeat, float t_repeat) = 0;
+ virtual bool isDetail() const = 0;
+ virtual void setDetail(bool detail) = 0;
+};
+
+class IBrush
+{
+public:
+ STRING_CONSTANT(Name, "IBrush");
+ virtual void reserve(std::size_t count) = 0;
+ virtual void clear() = 0;
+ virtual void copy(const IBrush& other) = 0;
+ virtual IBrushFace* addPlane(const Vector3& p0, const Vector3& p1, const Vector3& p2, const char* shader, const TextureProjection& projection) = 0;
+ virtual const AABB& localAABB() const = 0;
+ virtual void removeEmptyFaces() = 0;
+};
+
+class IBrushFaceInstance
+{
+public:
+ virtual IBrushFace& getFace() = 0;
+ virtual const IBrushFace& getFace() const = 0;
+ virtual bool isSelected() const = 0;
+ virtual void setSelected(SelectionSystem::EComponentMode mode, bool select) const = 0;
+};
+
+class IBrushInstance
+{
+public:
+ STRING_CONSTANT(Name, "IBrushInstance");
+ virtual void forEachFaceInstance(const BrushInstanceVisitor& visitor) = 0;
+};
+#endif
+
+class _QERFaceData
+{
+public:
+ _QERFaceData() : contents(0), flags(0), value(0), m_shader("")
+ {
+ }
+ Vector3 m_p0;
+ Vector3 m_p1;
+ Vector3 m_p2;
+ texdef_t m_texdef;
+ const char* m_shader;
+ int contents;
+ int flags;
+ int value;
+};
+
+typedef Callback1<const _QERFaceData&> BrushFaceDataCallback;
+
class BrushCreator
{
public:
STRING_CONSTANT(Name, "brush");
virtual scene::Node& createBrush() = 0;
virtual bool useAlternativeTextureProjection() const = 0;
+ virtual void forEachBrushFace(scene::Node& brush, const BrushFaceDataCallback& callback) = 0;
+ virtual bool addBrushFace(scene::Node& brush, const _QERFaceData& faceData) = 0;
};
#include "modulesystem.h"
#define INCLUDED_ICAMERA_H
#include "generic/constant.h"
+#include "generic/callbackfwd.h"
class Matrix4;
virtual void setFieldOfView(float fieldOfView) = 0;
};
-class Callback;
-
class CameraModel
{
public:
class EntityClass;
+typedef Callback1<const char*> KeyObserver;
+
+class EntityKeyValue
+{
+public:
+ virtual const char* c_str() const = 0;
+ virtual void assign(const char* other) = 0;
+ virtual void attach(const KeyObserver& observer) = 0;
+ virtual void detach(const KeyObserver& observer) = 0;
+};
+
class Entity
{
public:
STRING_CONSTANT(Name, "Entity");
+ class Observer
+ {
+ public:
+ virtual void insert(const char* key, EntityKeyValue& value) = 0;
+ virtual void erase(const char* key, EntityKeyValue& value) = 0;
+ virtual void clear() { };
+ };
+
class Visitor
{
public:
virtual void setKeyValue(const char* key, const char* value) = 0;
virtual const char* getKeyValue(const char* key) const = 0;
virtual bool isContainer() const = 0;
+ void attach(Observer& observer);
+ void detach(Observer& observer);
};
class EntityCopyingVisitor : public Entity::Visitor
#include <cstddef>
#include "generic/constant.h"
+#include "generic/callbackfwd.h"
-template<typename FirstArgument>
-class Callback1;
typedef Callback1<const char*> ArchiveNameCallback;
typedef Callback1<const char*> FileNameCallback;
#define INCLUDED_IRENDER_H
#include "generic/constant.h"
+#include "generic/callbackfwd.h"
// Rendering states to sort by.
}
};
-template<typename FirstArgument>
-class Callback1;
-
class Renderable;
typedef Callback1<const Renderable&> RenderableCallback;
#include <cstddef>
#include "generic/constant.h"
+#include "signal/signalfwd.h"
template<typename value_type>
class Stack;
template<typename Contained>
class Reference;
-class Callback;
-
namespace scene
{
class Instance;
virtual void sceneChanged() = 0;
/// \brief Add a \p callback to be invoked when the scene changes.
/// \todo Move to a separate class.
- virtual void addSceneChangedCallback(const Callback& callback) = 0;
+ virtual void addSceneChangedCallback(const SignalHandler& handler) = 0;
/// \brief Invokes all bounds-changed callbacks. Called when the bounds of any instance in the scene change.
/// \todo Move to a separate class.
virtual void boundsChanged() = 0;
/// \brief Add a \p callback to be invoked when the bounds of any instance in the scene change.
- virtual void addBoundsChangedCallback(const Callback& callback) = 0;
+ virtual SignalHandlerId addBoundsChangedCallback(const SignalHandler& boundsChanged) = 0;
/// \brief Remove a \p callback to be invoked when the bounds of any instance in the scene change.
- virtual void removeBoundsChangedCallback(const Callback& callback) = 0;
+ virtual void removeBoundsChangedCallback(SignalHandlerId id) = 0;
virtual TypeId getNodeTypeId(const char* name) = 0;
virtual TypeId getInstanceTypeId(const char* name) = 0;
return GlobalSceneGraphModule::getTable();
}
-inline void AddSceneChangeCallback(const Callback& callback)
+inline void AddSceneChangeCallback(const SignalHandler& handler)
{
- GlobalSceneGraph().addSceneChangedCallback(callback);
+ GlobalSceneGraph().addSceneChangedCallback(handler);
}
inline void SceneChangeNotify()
{
#include <cstddef>
#include "generic/constant.h"
+#include "generic/callbackfwd.h"
+#include "signal/signalfwd.h"
class Renderer;
class View;
-class Callback;
-
-template<typename FirstArgument>
-class Callback1;
-
class Selectable
{
public:
typedef Vector4 Quaternion;
typedef Callback1<const Selectable&> SelectionChangeCallback;
+typedef SignalHandler1<const Selectable&> SelectionChangeHandler;
class SelectionSystem
{
virtual void foreachSelected(const Visitor& visitor) const = 0;
virtual void foreachSelectedComponent(const Visitor& visitor) const = 0;
- virtual void addSelectionChangeCallback(const SelectionChangeCallback& callback) = 0;
+ virtual void addSelectionChangeCallback(const SelectionChangeHandler& handler) = 0;
virtual void NudgeManipulator(const Vector3& nudge, const Vector3& view) = 0;
#define INCLUDED_ISHADERS_H
#include "generic/constant.h"
+#include "generic/callbackfwd.h"
enum
{
virtual float alphaTest() const = 0;
};
-template<typename FirstArgument>
-class Callback1;
typedef Callback1<const ShaderLayer&> ShaderLayerCallback;
virtual qtexture_t* lightFalloffImage() const = 0;
};
-class Callback;
typedef struct _GSList GSList;
typedef Callback1<const char*> ShaderNameCallback;
#include <cstddef>
#include "generic/constant.h"
+#include "generic/callbackfwd.h"
class UndoMemento
{
virtual void save(Undoable* undoable) = 0;
};
-class Callback;
-
class UndoTracker
{
public:
#include <limits>
#include "iscenegraph.h"
-
-class Callback;
+#include "generic/callbackfwd.h"
const std::size_t MAPFILE_MAX_CHANGES = std::numeric_limits<std::size_t>::max();
#define INCLUDED_MODELSKIN_H
#include "generic/constant.h"
+#include "generic/callbackfwd.h"
class SkinRemap
{
}
};
-template<typename FirstArgument>
-class Callback1;
typedef Callback1<SkinRemap> SkinRemapCallback;
class ModuleObserver;
#define INCLUDED_NAMEABLE_H
#include "generic/constant.h"
+#include "generic/callbackfwd.h"
-template<typename FirstArgument>
-class Callback1;
typedef Callback1<const char*> NameCallback;
class Nameable
#define INCLUDED_NAMESPACE_H
#include "generic/constant.h"
+#include "generic/callbackfwd.h"
-template<typename FirstArgument>
-class Callback1;
typedef Callback1<const char*> NameCallback;
typedef Callback1<const NameCallback&> NameCallbackCallback;
#define INCLUDED_PREFERENCESYSTEM_H
#include "generic/constant.h"
+#include "generic/callbackfwd.h"
-template<typename FirstArgument>
-class Callback1;
typedef Callback1<const char*> StringImportCallback;
typedef Callback1<const StringImportCallback&> StringExportCallback;
// ========================================
+namespace scene
+{
+ class Node;
+}
+
class ModuleObserver;
+#include "signal/signalfwd.h"
+#include "windowobserver.h"
+#include "math/vector.h"
+
+typedef SignalHandler3<const WindowVector&, ButtonIdentifier, ModifierFlags> MouseEventHandler;
+typedef SignalFwd<MouseEventHandler>::handler_id_type MouseEventHandlerId;
+
+enum VIEWTYPE
+{
+ YZ = 0,
+ XZ = 1,
+ XY = 2
+};
+
// the radiant core API
struct _QERFuncTable_1
{
const char* (*getGameMode)();
const char* (*getMapName)();
+ scene::Node& (*getMapWorldEntity)();
+ float (*getGridSize)();
const char* (*getGameDescriptionKeyValue)(const char* key);
const char* (*getRequiredGameDescriptionKeyValue)(const char* key);
void (*attachGameModeObserver)(ModuleObserver& observer);
void (*detachGameModeObserver)(ModuleObserver& observer);
+ MouseEventHandlerId (*XYWindowMouseDown_connect)(const MouseEventHandler& handler);
+ void (*XYWindowMouseDown_disconnect)(MouseEventHandlerId id);
+ VIEWTYPE (*XYWindow_getViewType)();
+ Vector3 (*XYWindow_windowToWorld)(const WindowVector& position);
+ const char* (*TextureBrowser_getSelectedShader)();
+
// GTK+ functions
PFN_QERAPP_MESSAGEBOX m_pfnMessageBox;
PFN_QERAPP_FILEDIALOG m_pfnFileDialog;
#include "math/vector.h"
#include "scenelib.h"
+#include "generic/callbackfwd.h"
class SelectionIntersection
{
}
-template<typename FirstArgument>
-class Callback1;
class Plane3;
typedef Callback1<const Plane3&> PlaneCallback;
: m_hash(hash), m_value(key, value)
{
}
- BucketNode* getNext()
+ BucketNode* getNext() const
{
return static_cast<BucketNode*>(next);
}
- BucketNode* getPrev()
+ BucketNode* getPrev() const
{
return static_cast<BucketNode*>(prev);
}
#define DEBUGGER_BREAKPOINT() raise(SIGTRAP);
#endif
-
-#define FILE_LINE __FILE__ ":" << __LINE__
+#define STR(x) #x
+#define STR2(x) STR(x)
+#define FILE_LINE __FILE__ ":" STR2(__LINE__)
#if defined(_DEBUG) || 1
#define DEBUG_ASSERTS
#define ASSERT_MESSAGE(condition, message)\
if(!(condition))\
{\
- globalDebugMessageHandler().getOutputStream() << FILE_LINE << "\nassertion failure: " << message << "\n";\
+ globalDebugMessageHandler().getOutputStream() << FILE_LINE "\nassertion failure: " << message << "\n";\
if(!globalDebugMessageHandler().handleMessage()) { DEBUGGER_BREAKPOINT(); }\
} else\
/// \brief Sends a \p message to the current debug-message-handler text-output-stream.
#define ERROR_MESSAGE(message)\
-globalDebugMessageHandler().getOutputStream() << FILE_LINE << "\nruntime error: " << message << "\n";\
+globalDebugMessageHandler().getOutputStream() << FILE_LINE "\nruntime error: " << message << "\n";\
if(!globalDebugMessageHandler().handleMessage()) { DEBUGGER_BREAKPOINT(); } else\
#define ASSERT_NOTNULL(ptr) ASSERT_MESSAGE(ptr != 0, "pointer \"" #ptr "\" is null")
};
-typedef Callback1<const char*> KeyObserver;
-
/// \brief A key/value pair of strings.
///
/// - Notifies observers when value changes - value changes to "" on destruction.
/// - Provides undo support through the global undo system.
-class KeyValue
+class KeyValue : public EntityKeyValue
{
typedef UnsortedSet<KeyObserver> KeyObservers;
public:
typedef KeyValue Value;
- class Observer
- {
- public:
- virtual void insert(const char* key, Value& value) = 0;
- virtual void erase(const char* key, Value& value) = 0;
- };
-
static StringPool& getPool()
{
return Static<StringPool, KeyContext>::instance();
}
~EntityKeyValues()
{
+ for(Observers::iterator i = m_observers.begin(); i != m_observers.end();)
+ {
+ // post-increment to allow current element to be removed safely
+ (*i++)->clear();
+ }
ASSERT_MESSAGE(m_observers.empty(), "EntityKeyValues::~EntityKeyValues: observers still attached");
}
}
#endif
+
+namespace
+{
+ class A1
+ {
+ };
+ class A2
+ {
+ };
+ class A3
+ {
+ };
+ class A4
+ {
+ };
+
+ class Test
+ {
+ public:
+ void test0()
+ {
+ }
+ typedef Member<Test, void, &Test::test0> Test0;
+ typedef MemberCaller<Test, &Test::test0> Test0Caller;
+ void test0const() const
+ {
+ }
+ typedef ConstMember<Test, void, &Test::test0const> Test0Const;
+ typedef ConstMemberCaller<Test, &Test::test0const> Test0ConstCaller;
+ void test1(A1)
+ {
+ }
+ typedef Member1<Test, A1, void, &Test::test1> Test1;
+ typedef MemberCaller1<Test, A1, &Test::test1> Test1Caller;
+ void test1const(A1) const
+ {
+ }
+ typedef ConstMember1<Test, A1, void, &Test::test1const> Test1Const;
+ typedef ConstMemberCaller1<Test, A1, &Test::test1const> Test1ConstCaller;
+ void test2(A1, A2)
+ {
+ }
+ typedef Member2<Test, A1, A2, void, &Test::test2> Test2;
+ void test2const(A1, A2) const
+ {
+ }
+ typedef ConstMember2<Test, A1, A2, void, &Test::test2const> Test2Const;
+ void test3(A1, A2, A3)
+ {
+ }
+ typedef Member3<Test, A1, A2, A3, void, &Test::test3> Test3;
+ void test3const(A1, A2, A3) const
+ {
+ }
+ typedef ConstMember3<Test, A1, A2, A3, void, &Test::test3const> Test3Const;
+ };
+
+ void test0free()
+ {
+ }
+ typedef FreeCaller<&test0free> Test0FreeCaller;
+ void test1free(A1)
+ {
+ }
+ typedef FreeCaller1<A1, &test1free> Test1FreeCaller;
+ void test2free(A1, A2)
+ {
+ }
+ typedef Function2<A1, A2, void, &test2free> Test2Free;
+ void test3free(A1, A2, A3)
+ {
+ }
+ typedef Function3<A1, A2, A3, void, &test3free> Test3Free;
+
+
+ void test0(Test& test)
+ {
+ }
+ typedef ReferenceCaller<Test, &test0> Test0Caller;
+
+ void test0const(const Test& test)
+ {
+ }
+ typedef ConstReferenceCaller<Test, &test0const> Test0ConstCaller;
+
+ void test0p(Test* test)
+ {
+ }
+ typedef PointerCaller<Test, &test0p> Test0PCaller;
+
+ void test0constp(const Test* test)
+ {
+ }
+ typedef ConstPointerCaller<Test, &test0constp> Test0ConstPCaller;
+
+ void test1(Test& test, A1)
+ {
+ }
+ typedef ReferenceCaller1<Test, A1, &test1> Test1Caller;
+
+ void test1const(const Test& test, A1)
+ {
+ }
+ typedef ConstReferenceCaller1<Test, A1, &test1const> Test1ConstCaller;
+
+ void test1p(Test* test, A1)
+ {
+ }
+ typedef PointerCaller1<Test, A1, &test1p> Test1PCaller;
+
+ void test1constp(const Test* test, A1)
+ {
+ }
+ typedef ConstPointerCaller1<Test, A1, &test1constp> Test1ConstPCaller;
+
+ void test2(Test& test, A1, A2)
+ {
+ }
+ typedef Function3<Test&, A1, A2, void, &test2> Test2;
+
+ void test3(Test& test, A1, A2, A3)
+ {
+ }
+ typedef Function4<Test&, A1, A2, A3, void, &test3> Test3;
+
+ void instantiate()
+ {
+ Test test;
+ const Test& testconst = test;
+ {
+ Callback a = Test0FreeCaller();
+ Callback b = Test::Test0Caller(test);
+ b = makeCallback0(Test::Test0(), test);
+ Callback c = Test::Test0ConstCaller(testconst);
+ c = makeCallback0(Test::Test0Const(), test);
+ Callback d = Test0Caller(test);
+ Callback e = Test0ConstCaller(testconst);
+ Callback f = Test0PCaller(&test);
+ Callback g = Test0ConstPCaller(&testconst);
+ a();
+ bool u = a != b;
+ }
+ {
+ typedef Callback1<A1> TestCallback1;
+ TestCallback1 a = Test1FreeCaller();
+ TestCallback1 b = Test::Test1Caller(test);
+ b = makeCallback1(Test::Test1(), test);
+ TestCallback1 c = Test::Test1ConstCaller(testconst);
+ c = makeCallback1(Test::Test1Const(), test);
+ TestCallback1 d = Test1Caller(test);
+ TestCallback1 e = Test1ConstCaller(testconst);
+ TestCallback1 f = Test1PCaller(&test);
+ TestCallback1 g = Test1ConstPCaller(&testconst);
+ a(A1());
+ bool u = a != b;
+ }
+ {
+ typedef Callback2<A1, A2> TestCallback2;
+ TestCallback2 a = makeStatelessCallback2(Test2Free());
+ TestCallback2 b = makeCallback2(Test2(), test);
+ TestCallback2 c = makeCallback2(Test::Test2(), test);
+ TestCallback2 d = makeCallback2(Test::Test2Const(), test);
+ a(A1(), A2());
+ bool u = a != b;
+ }
+ {
+ typedef Callback3<A1, A2, A3> TestCallback3;
+ TestCallback3 a = makeStatelessCallback3(Test3Free());
+ TestCallback3 b = makeCallback3(Test3(), test);
+ TestCallback3 c = makeCallback3(Test::Test3(), test);
+ TestCallback3 d = makeCallback3(Test::Test3Const(), test);
+ a(A1(), A2(), A3());
+ bool u = a != b;
+ }
+ }
+}
#define INCLUDED_GENERIC_CLOSURE_H
/// \file
-/// \brief Type-safe techniques for binding the first argument of an anonymous callback.
+/// \brief Type-safe techniques for binding the first argument of an opaque callback.
#include <cstddef>
+#include "functional.h"
+#include "callbackfwd.h"
-/// \brief Combines a void pointer with a pointer to a function which operates on a void pointer.
-///
-/// Use with the callback constructors MemberCaller, ConstMemberCaller, ReferenceCaller, ConstReferenceCaller, PointerCaller, ConstPointerCaller and FreeCaller.
-class Callback
+template<typename Type>
+inline void* convertToOpaque(Type* t)
{
- typedef void (*Thunk)(void*);
- void* m_environment;
- Thunk m_thunk;
+ return t;
+}
+template<typename Type>
+inline void* convertToOpaque(const Type* t)
+{
+ return const_cast<Type*>(t);
+}
+template<typename Type>
+inline void* convertToOpaque(Type& t)
+{
+ return &t;
+}
+template<typename Type>
+inline void* convertToOpaque(const Type& t)
+{
+ return const_cast<Type*>(&t);
+}
+
+
+template<typename Type>
+class ConvertFromOpaque
+{
+};
+
+template<typename Type>
+class ConvertFromOpaque<Type&>
+{
+public:
+ static Type& apply(void* p)
+ {
+ return *static_cast<Type*>(p);
+ }
+};
- static void nullThunk(void*)
+template<typename Type>
+class ConvertFromOpaque<const Type&>
+{
+public:
+ static const Type& apply(void* p)
{
+ return *static_cast<Type*>(p);
}
+};
+
+template<typename Type>
+class ConvertFromOpaque<Type*>
+{
+public:
+ static Type* apply(void* p)
+ {
+ return static_cast<Type*>(p);
+ }
+};
+
+template<typename Type>
+class ConvertFromOpaque<const Type*>
+{
+public:
+ static const Type* apply(void* p)
+ {
+ return static_cast<Type*>(p);
+ }
+};
+
+template<typename Caller>
+class BindFirstOpaque
+{
+ typedef typename Caller::first_argument_type FirstBound;
+ FirstBound firstBound;
public:
- Callback() : m_environment(0), m_thunk(nullThunk)
+ typedef typename Caller::result_type result_type;
+ explicit BindFirstOpaque(FirstBound firstBound) : firstBound(firstBound)
{
}
- Callback(void* environment, Thunk function) : m_environment(environment), m_thunk(function)
+ result_type operator()() const
+ {
+ return Caller::call(firstBound);
+ }
+ FirstBound getBound() const
+ {
+ return firstBound;
+ }
+ static result_type thunk(void* environment)
+ {
+ return Caller::call(ConvertFromOpaque<FirstBound>::apply(environment));
+ }
+ void* getEnvironment() const
+ {
+ return convertToOpaque(firstBound);
+ }
+};
+
+template<typename Caller>
+class BindFirstOpaque1
+{
+ typedef typename Caller::first_argument_type FirstBound;
+ FirstBound firstBound;
+public:
+ typedef typename Caller::second_argument_type first_argument_type;
+ typedef typename Caller::result_type result_type;
+ explicit BindFirstOpaque1(FirstBound firstBound) : firstBound(firstBound)
+ {
+ }
+ result_type operator()(first_argument_type a1) const
+ {
+ return Caller::call(firstBound, a1);
+ }
+ FirstBound getBound() const
+ {
+ return firstBound;
+ }
+ static result_type thunk(void* environment, first_argument_type a1)
+ {
+ return Caller::call(ConvertFromOpaque<FirstBound>::apply(environment), a1);
+ }
+ void* getEnvironment() const
+ {
+ return convertToOpaque(firstBound);
+ }
+};
+
+template<typename Caller>
+class BindFirstOpaque2
+{
+ typedef typename Caller::first_argument_type FirstBound;
+ FirstBound firstBound;
+public:
+ typedef typename Caller::second_argument_type first_argument_type;
+ typedef typename Caller::third_argument_type second_argument_type;
+ typedef typename Caller::result_type result_type;
+ explicit BindFirstOpaque2(FirstBound firstBound) : firstBound(firstBound)
+ {
+ }
+ result_type operator()(first_argument_type a1, second_argument_type a2) const
+ {
+ return Caller::call(firstBound, a1, a2);
+ }
+ FirstBound getBound() const
+ {
+ return firstBound;
+ }
+ static result_type thunk(void* environment, first_argument_type a1, second_argument_type a2)
+ {
+ return Caller::call(ConvertFromOpaque<FirstBound>::apply(environment), a1, a2);
+ }
+ void* getEnvironment() const
+ {
+ return convertToOpaque(firstBound);
+ }
+};
+
+template<typename Caller>
+class BindFirstOpaque3
+{
+ typedef typename Caller::first_argument_type FirstBound;
+ FirstBound firstBound;
+public:
+ typedef typename Caller::second_argument_type first_argument_type;
+ typedef typename Caller::third_argument_type second_argument_type;
+ typedef typename Caller::fourth_argument_type third_argument_type;
+ typedef typename Caller::result_type result_type;
+ explicit BindFirstOpaque3(FirstBound firstBound) : firstBound(firstBound)
+ {
+ }
+ result_type operator()(first_argument_type a1, second_argument_type a2, third_argument_type a3) const
+ {
+ return Caller::call(firstBound, a1, a2, a3);
+ }
+ FirstBound getBound() const
+ {
+ return firstBound;
+ }
+ static result_type thunk(void* environment, first_argument_type a1, second_argument_type a2, third_argument_type a3)
+ {
+ return Caller::call(ConvertFromOpaque<FirstBound>::apply(environment), a1, a2, a3);
+ }
+ void* getEnvironment() const
+ {
+ return convertToOpaque(firstBound);
+ }
+};
+
+template<typename typename Thunk_>
+class CallbackBase
+{
+ void* m_environment;
+ Thunk_ m_thunk;
+public:
+ typedef Thunk_ Thunk;
+ CallbackBase(void* environment, Thunk function) : m_environment(environment), m_thunk(function)
{
}
void* getEnvironment() const
{
return m_thunk;
}
- void operator()() const
- {
- m_thunk(m_environment);
- }
};
-inline bool operator==(const Callback& self, const Callback& other)
+template<typename typename Thunk>
+inline bool operator==(const CallbackBase<Thunk>& self, const CallbackBase<Thunk>& other)
{
return self.getEnvironment() == other.getEnvironment() && self.getThunk() == other.getThunk();
}
-inline bool operator<(const Callback& self, const Callback& other)
+template<typename typename Thunk>
+inline bool operator!=(const CallbackBase<Thunk>& self, const CallbackBase<Thunk>& other)
+{
+ return !(self == other);
+}
+template<typename typename Thunk>
+inline bool operator<(const CallbackBase<Thunk>& self, const CallbackBase<Thunk>& other)
{
return self.getEnvironment() < other.getEnvironment() ||
(!(other.getEnvironment() < self.getEnvironment()) && self.getThunk() < other.getThunk());
}
-/// \brief Combines a void pointer with a pointer to a function which operates on a void pointer and one other argument.
+
+/// \brief Combines a void pointer with a pointer to a function which operates on a void pointer.
///
-/// Use with the callback constructors MemberCaller1, ConstMemberCaller1, ReferenceCaller1, ConstReferenceCaller1, PointerCaller1, ConstPointerCaller1 and FreeCaller1.
-template<typename FirstArgument>
-class Callback1
+/// Use with the callback constructors MemberCaller, ConstMemberCaller, ReferenceCaller, ConstReferenceCaller, PointerCaller, ConstPointerCaller and FreeCaller.
+template<typename Result>
+class Callback0 : public CallbackBase<Result (*)(void*)>
{
- typedef void (*Thunk)(void*, FirstArgument);
- void* m_environment;
- Thunk m_thunk;
-
- static void nullThunk(void*, FirstArgument)
+ typedef CallbackBase<Result (*)(void*)> Base;
+ static Result nullThunk(void*)
{
}
public:
- typedef FirstArgument first_argument_type;
+ typedef Result result_type;
- Callback1() : m_environment(0), m_thunk(nullThunk)
- {
- }
- Callback1(void* environment, Thunk function) : m_environment(environment), m_thunk(function)
+ Callback0() : Base(0, nullThunk)
{
}
- void* getEnvironment() const
+ template<typename Caller>
+ Callback0(const BindFirstOpaque<Caller>& caller) : Base(caller.getEnvironment(), BindFirstOpaque<Caller>::thunk)
{
- return m_environment;
}
- Thunk getThunk() const
+ Callback0(void* environment, Thunk function) : Base(environment, function)
{
- return m_thunk;
}
- void operator()(FirstArgument firstArgument) const
+ result_type operator()() const
{
- m_thunk(m_environment, firstArgument);
+ return getThunk()(getEnvironment());
}
};
-template<typename FirstArgument>
-inline bool operator==(const Callback1<FirstArgument>& self, const Callback1<FirstArgument>& other)
+template<typename Caller>
+inline Callback0<typename Caller::result_type> makeCallback0(const Caller& caller, typename Caller::first_argument_type callee)
{
- return self.getEnvironment() == other.getEnvironment() && self.getThunk() == other.getThunk();
+ return Callback0<typename Caller::result_type>(BindFirstOpaque<Caller>(callee));
}
-template<typename FirstArgument>
-inline bool operator<(const Callback1<FirstArgument>& self, const Callback1<FirstArgument>& other)
+template<typename Caller>
+inline Callback0<typename Caller::result_type> makeStatelessCallback0(const Caller& caller)
{
- return self.getEnvironment() < other.getEnvironment() ||
- (!(other.getEnvironment() < self.getEnvironment()) && self.getThunk() < other.getThunk());
+ return makeCallback0(Caller0To1<Caller>(), 0);
}
-template<typename Functor>
-class FunctorInvoke
+typedef Callback0<void> Callback;
+
+
+
+/// \brief Combines a void pointer with a pointer to a function which operates on a void pointer and one other argument.
+///
+/// Use with the callback constructors MemberCaller1, ConstMemberCaller1, ReferenceCaller1, ConstReferenceCaller1, PointerCaller1, ConstPointerCaller1 and FreeCaller1.
+template<typename FirstArgument, typename Result>
+class Callback1 : public CallbackBase<Result (*)(void*, FirstArgument)>
{
+ typedef CallbackBase<Result (*)(void*, FirstArgument)> Base;
+ static Result nullThunk(void*, FirstArgument)
+ {
+ }
+
public:
- inline void operator()(Functor functor)
+ typedef FirstArgument first_argument_type;
+ typedef Result result_type;
+
+ Callback1() : Base(0, nullThunk)
{
- functor();
+ }
+ template<typename Caller>
+ Callback1(const BindFirstOpaque1<Caller>& caller) : Base(caller.getEnvironment(), BindFirstOpaque1<Caller>::thunk)
+ {
+ }
+ Callback1(void* environment, Thunk function) : Base(environment, function)
+ {
+ }
+ result_type operator()(FirstArgument firstArgument) const
+ {
+ return getThunk()(getEnvironment(), firstArgument);
}
};
-typedef FunctorInvoke<Callback> CallbackInvoke;
+template<typename Caller>
+inline Callback1<typename Caller::second_argument_type, typename Caller::result_type> makeCallback1(const Caller& caller, typename Caller::first_argument_type callee)
+{
+ return Callback1<typename Caller::second_argument_type, typename Caller::result_type>(BindFirstOpaque1<Caller>(callee));
+}
+template<typename Caller>
+inline Callback1<typename Caller::second_argument_type, typename Caller::result_type> makeStatelessCallback1(const Caller& caller)
+{
+ return makeCallback1(Caller1To2<Caller>(), 0);
+}
-template<typename Functor, typename FirstArgument>
-class Functor1Invoke
+/// \brief Combines a void pointer with a pointer to a function which operates on a void pointer and two other arguments.
+///
+template<typename FirstArgument, typename SecondArgument, typename Result>
+class Callback2 : public CallbackBase<Result (*)(void*, FirstArgument, SecondArgument)>
{
- FirstArgument m_firstArgument;
+ typedef CallbackBase<Result (*)(void*, FirstArgument, SecondArgument)> Base;
+ static Result nullThunk(void*, FirstArgument, SecondArgument)
+ {
+ }
+
public:
- Functor1Invoke(FirstArgument firstArgument) : m_firstArgument(firstArgument)
+ typedef FirstArgument first_argument_type;
+ typedef SecondArgument second_argument_type;
+ typedef Result result_type;
+
+ Callback2() : Base(0, nullThunk)
+ {
+ }
+ template<typename Caller>
+ Callback2(const BindFirstOpaque2<Caller>& caller) : Base(caller.getEnvironment(), BindFirstOpaque2<Caller>::thunk)
{
}
- inline void operator()(Functor functor)
+ Callback2(void* environment, Thunk function) : Base(environment, function)
{
- functor(m_firstArgument);
+ }
+ result_type operator()(FirstArgument firstArgument, SecondArgument secondArgument) const
+ {
+ return getThunk()(getEnvironment(), firstArgument, secondArgument);
}
};
+template<typename Caller>
+inline Callback2<
+ typename Caller::second_argument_type,
+ typename Caller::third_argument_type,
+ typename Caller::result_type
+> makeCallback2(const Caller& caller, typename Caller::first_argument_type callee)
+{
+ return Callback2<
+ typename Caller::second_argument_type,
+ typename Caller::third_argument_type,
+ typename Caller::result_type
+ >(BindFirstOpaque2<Caller>(callee));
+}
+template<typename Caller>
+inline Callback2<
+ typename Caller::first_argument_type,
+ typename Caller::second_argument_type,
+ typename Caller::result_type
+> makeStatelessCallback2(const Caller& caller)
+{
+ return makeCallback2(Caller2To3<Caller>(), 0);
+}
-typedef Callback1<bool> BoolImportCallback;
-typedef Callback1<const BoolImportCallback&> BoolExportCallback;
-typedef Callback1<int> IntImportCallback;
-typedef Callback1<const IntImportCallback&> IntExportCallback;
+/// \brief Combines a void pointer with a pointer to a function which operates on a void pointer and three other arguments.
+///
+template<typename FirstArgument, typename SecondArgument, typename ThirdArgument, typename Result>
+class Callback3 : public CallbackBase<Result (*)(void*, FirstArgument, SecondArgument, ThirdArgument)>
+{
+ typedef CallbackBase<Result (*)(void*, FirstArgument, SecondArgument, ThirdArgument)> Base;
+ static Result nullThunk(void*, FirstArgument, SecondArgument, ThirdArgument)
+ {
+ }
-typedef Callback1<float> FloatImportCallback;
-typedef Callback1<const FloatImportCallback&> FloatExportCallback;
+public:
+ typedef FirstArgument first_argument_type;
+ typedef SecondArgument second_argument_type;
+ typedef ThirdArgument third_argument_type;
+ typedef Result result_type;
-typedef Callback1<const char*> StringImportCallback;
-typedef Callback1<const StringImportCallback&> StringExportCallback;
+ Callback3() : Base(0, nullThunk)
+ {
+ }
+ template<typename Caller>
+ Callback3(const BindFirstOpaque3<Caller>& caller) : Base(caller.getEnvironment(), BindFirstOpaque3<Caller>::thunk)
+ {
+ }
+ Callback3(void* environment, Thunk function) : Base(environment, function)
+ {
+ }
+ result_type operator()(FirstArgument firstArgument, SecondArgument secondArgument, ThirdArgument thirdArgument) const
+ {
+ return getThunk()(getEnvironment(), firstArgument, secondArgument, thirdArgument);
+ }
+};
-typedef Callback1<std::size_t> SizeImportCallback;
-typedef Callback1<const SizeImportCallback&> SizeExportCallback;
+template<typename Caller>
+inline Callback3<
+ typename Caller::second_argument_type,
+ typename Caller::third_argument_type,
+ typename Caller::fourth_argument_type,
+ typename Caller::result_type
+> makeCallback3(const Caller& caller, typename Caller::first_argument_type callee)
+{
+ return Callback3<
+ typename Caller::second_argument_type,
+ typename Caller::third_argument_type,
+ typename Caller::fourth_argument_type,
+ typename Caller::result_type
+ >(BindFirstOpaque3<Caller>(callee));
+}
+template<typename Caller>
+inline Callback3<
+ typename Caller::first_argument_type,
+ typename Caller::second_argument_type,
+ typename Caller::third_argument_type,
+ typename Caller::result_type
+> makeStatelessCallback3(const Caller& caller)
+{
+ return makeCallback3(Caller3To4<Caller>(), 0);
+}
/// \brief Forms a Callback from a non-const Environment reference and a non-const Environment member-function.
/// \skipline MemberCaller example
/// \until end example
template<typename Environment, void (Environment::*member)()>
-class MemberCaller
+class MemberCaller : public BindFirstOpaque< Member<Environment, void, member> >
{
- Environment& m_environment;
public:
- MemberCaller(Environment& environment) : m_environment(environment)
- {
- }
- void* getEnvironment() const
+ MemberCaller(Environment& environment) : BindFirstOpaque< Member<Environment, void, member> >(environment)
{
- return &m_environment;
- }
- static void thunk(void* environment)
- {
- ((*reinterpret_cast<Environment*>(environment)).*member)();
- }
- operator Callback() const
- {
- return Callback(getEnvironment(), thunk);
}
};
/// \skipline MemberCaller example
/// \until end example
template<typename Environment, void (Environment::*member)() const>
-class ConstMemberCaller
+class ConstMemberCaller : public BindFirstOpaque< ConstMember<Environment, void, member> >
{
- const Environment& m_environment;
public:
- ConstMemberCaller(const Environment& environment) : m_environment(environment)
- {
- }
- void* getEnvironment() const
+ ConstMemberCaller(const Environment& environment) : BindFirstOpaque< ConstMember<Environment, void, member> >(environment)
{
- return const_cast<Environment*>(&m_environment);
- }
- static void thunk(void* environment)
- {
- ((*reinterpret_cast<const Environment*>(environment)).*member)();
- }
- operator Callback() const
- {
- return Callback(getEnvironment(), thunk);
}
};
/// \brief Forms a Callback from a non-const Environment reference and a const Environment member-function which takes one argument.
template<typename Environment, typename FirstArgument, void (Environment::*member)(FirstArgument)>
-class MemberCaller1
+class MemberCaller1 : public BindFirstOpaque1< Member1<Environment, FirstArgument, void, member> >
{
- Environment& m_environment;
public:
- MemberCaller1(Environment& environment) : m_environment(environment)
+ MemberCaller1(Environment& environment) : BindFirstOpaque1< Member1<Environment, FirstArgument, void, member> >(environment)
{
}
- void* getEnvironment() const
- {
- return &m_environment;
- }
- static void thunk(void* environment, FirstArgument firstArgument)
- {
- ((*reinterpret_cast<Environment*>(environment)).*member)(firstArgument);
- }
- operator Callback1<FirstArgument>() const
- {
- return Callback1<FirstArgument>(getEnvironment(), thunk);
- }
};
/// \brief Forms a Callback from a const Environment reference and a const Environment member-function which takes one argument.
template<typename Environment, typename FirstArgument, void (Environment::*member)(FirstArgument) const>
-class ConstMemberCaller1
+class ConstMemberCaller1 : public BindFirstOpaque1< ConstMember1<Environment, FirstArgument, void, member> >
{
- const Environment& m_environment;
public:
- ConstMemberCaller1(const Environment& environment) : m_environment(environment)
+ ConstMemberCaller1(const Environment& environment) : BindFirstOpaque1< ConstMember1<Environment, FirstArgument, void, member> >(environment)
{
}
- void* getEnvironment() const
- {
- return const_cast<Environment*>(&m_environment);
- }
- static void thunk(void* environment, FirstArgument firstArgument)
- {
- ((*reinterpret_cast<Environment*>(environment)).*member)(firstArgument);
- }
- operator Callback1<FirstArgument>() const
- {
- return Callback1<FirstArgument>(getEnvironment(), thunk);
- }
};
/// \brief Forms a Callback from a non-const Environment reference and a free function which operates on a non-const Environment reference.
/// \skipline ReferenceCaller example
/// \until end example
template<typename Environment, void (*func)(Environment&)>
-class ReferenceCaller
+class ReferenceCaller : public BindFirstOpaque< Function1<Environment&, void, func> >
{
- Environment& m_environment;
public:
- ReferenceCaller(Environment& environment) : m_environment(environment)
- {
- }
- void* getEnvironment() const
+ ReferenceCaller(Environment& environment) : BindFirstOpaque< Function1<Environment&, void, func> >(environment)
{
- return &m_environment;
- }
- static void thunk(void* environment)
- {
- (func)(*reinterpret_cast<Environment*>(environment));
- }
- operator Callback() const
- {
- return Callback(getEnvironment(), thunk);
}
};
/// \skipline ReferenceCaller example
/// \until end example
template<typename Environment, void (*func)(const Environment&)>
-class ConstReferenceCaller
+class ConstReferenceCaller : public BindFirstOpaque< Function1<const Environment&, void, func> >
{
- const Environment& m_environment;
public:
- ConstReferenceCaller(const Environment& environment) : m_environment(environment)
- {
- }
- void* getEnvironment() const
- {
- return const_cast<Environment*>(&m_environment);
- }
- static void thunk(void* environment)
+ ConstReferenceCaller(const Environment& environment) : BindFirstOpaque< Function1<const Environment&, void, func> >(environment)
{
- (func)(*reinterpret_cast<const Environment*>(environment));
- }
- operator Callback() const
- {
- return Callback(getEnvironment(), thunk);
}
};
/// \brief Forms a Callback from a non-const Environment reference and a free function which operates on a non-const Environment reference and one other argument.
template<typename Environment, typename FirstArgument, void (*func)(Environment&, FirstArgument)>
-class ReferenceCaller1
+class ReferenceCaller1 : public BindFirstOpaque1< Function2<Environment&, FirstArgument, void, func> >
{
- Environment& m_environment;
public:
- ReferenceCaller1(Environment& environment) : m_environment(environment)
- {
- }
- void* getEnvironment() const
+ ReferenceCaller1(Environment& environment) : BindFirstOpaque1< Function2<Environment&, FirstArgument, void, func> >(environment)
{
- return &m_environment;
- }
- static void thunk(void* environment, FirstArgument firstArgument)
- {
- (func)(*reinterpret_cast<Environment*>(environment), firstArgument);
- }
- operator Callback1<FirstArgument>() const
- {
- return Callback1<FirstArgument>(getEnvironment(), thunk);
}
};
/// \brief Forms a Callback from a const Environment reference and a free function which operates on a const Environment reference and one other argument.
template<typename Environment, typename FirstArgument, void (*func)(const Environment&, FirstArgument)>
-class ConstReferenceCaller1
+class ConstReferenceCaller1 : public BindFirstOpaque1< Function2<const Environment&, FirstArgument, void, func> >
{
- const Environment& m_environment;
public:
- ConstReferenceCaller1(const Environment& environment) : m_environment(environment)
+ ConstReferenceCaller1(const Environment& environment) : BindFirstOpaque1< Function2<const Environment&, FirstArgument, void, func> >(environment)
{
}
- void* getEnvironment() const
- {
- return const_cast<Environment*>(&m_environment);
- }
- static void thunk(void* environment, FirstArgument firstArgument)
- {
- (func)(*reinterpret_cast<const Environment*>(environment), firstArgument);
- }
- operator Callback1<FirstArgument>() const
- {
- return Callback1<FirstArgument>(getEnvironment(), thunk);
- }
};
/// \brief Forms a Callback from a non-const Environment pointer and a free function which operates on a non-const Environment pointer.
template<typename Environment, void (*func)(Environment*)>
-class PointerCaller
+class PointerCaller : public BindFirstOpaque< Function1<Environment*, void, func> >
{
- Environment* m_environment;
public:
- PointerCaller(Environment* environment) : m_environment(environment)
+ PointerCaller(Environment* environment) : BindFirstOpaque< Function1<Environment*, void, func> >(environment)
{
}
- void* getEnvironment() const
- {
- return m_environment;
- }
- static void thunk(void* environment)
- {
- (func)(reinterpret_cast<Environment*>(environment));
- }
- operator Callback() const
- {
- return Callback(getEnvironment(), thunk);
- }
};
/// \brief Forms a Callback from a const Environment pointer and a free function which operates on a const Environment pointer.
template<typename Environment, void (*func)(const Environment*)>
-class ConstPointerCaller
+class ConstPointerCaller : public BindFirstOpaque< Function1<const Environment*, void, func> >
{
- const Environment* m_environment;
public:
- ConstPointerCaller(const Environment* environment) : m_environment(environment)
- {
- }
- void* getEnvironment() const
- {
- return const_cast<Environment*>(m_environment);
- }
- static void thunk(void* environment)
- {
- (func)(reinterpret_cast<const Environment*>(environment));
- }
- operator Callback() const
+ ConstPointerCaller(const Environment* environment) : BindFirstOpaque< Function1<const Environment*, void, func> >(environment)
{
- return Callback(getEnvironment(), thunk);
}
};
/// \brief Forms a Callback from a non-const Environment pointer and a free function which operates on a non-const Environment pointer and one other argument.
template<typename Environment, typename FirstArgument, void (*func)(Environment*, FirstArgument)>
-class PointerCaller1
+class PointerCaller1 : public BindFirstOpaque1< Function2<Environment*, FirstArgument, void, func> >
{
- Environment* m_environment;
public:
- PointerCaller1(Environment* environment) : m_environment(environment)
- {
- }
- void* getEnvironment() const
- {
- return m_environment;
- }
- static void thunk(void* environment, FirstArgument firstArgument)
+ PointerCaller1(Environment* environment) : BindFirstOpaque1< Function2<Environment*, FirstArgument, void, func> >(environment)
{
- (func)(reinterpret_cast<Environment*>(environment), firstArgument);
- }
- operator Callback1<FirstArgument>() const
- {
- return Callback1<FirstArgument>(getEnvironment(), thunk);
}
};
/// \brief Forms a Callback from a const Environment pointer and a free function which operates on a const Environment pointer and one other argument.
template<typename Environment, typename FirstArgument, void (*func)(const Environment*, FirstArgument)>
-class ConstPointerCaller1
+class ConstPointerCaller1 : public BindFirstOpaque1< Function2<const Environment*, FirstArgument, void, func> >
{
- const Environment* m_environment;
public:
- ConstPointerCaller1(const Environment* environment) : m_environment(environment)
- {
- }
- void* getEnvironment() const
+ ConstPointerCaller1(const Environment* environment) : BindFirstOpaque1< Function2<const Environment*, FirstArgument, void, func> >(environment)
{
- return const_cast<Environment*>(m_environment);
- }
- static void thunk(void* environment, FirstArgument firstArgument)
- {
- (func)(reinterpret_cast<const Environment*>(environment), firstArgument);
- }
- operator Callback1<FirstArgument>() const
- {
- return Callback1<FirstArgument>(getEnvironment(), thunk);
}
};
-
/// \brief Forms a Callback from a free function which takes no arguments.
template<void (*func)()>
-class FreeCaller
+class FreeCaller : public BindFirstOpaque< Caller0To1< Function0<void, func> > >
{
public:
- void* getEnvironment() const
- {
- return 0;
- }
- static void thunk(void*)
- {
- (func)();
- }
- operator Callback() const
+ FreeCaller() : BindFirstOpaque< Caller0To1< Function0<void, func> > >(0)
{
- return Callback(getEnvironment(), thunk);
}
};
/// \brief Forms a Callback from a free function which takes a single argument.
template<typename FirstArgument, void (*func)(FirstArgument)>
-class FreeCaller1
+class FreeCaller1 : public BindFirstOpaque1< Caller1To2< Function1<FirstArgument, void, func> > >
{
public:
- void* getEnvironment() const
- {
- return 0;
- }
- static void thunk(void*, FirstArgument firstArgument)
+ FreeCaller1() : BindFirstOpaque1< Caller1To2< Function1<FirstArgument, void, func> > >(0)
{
- (func)(firstArgument);
- }
- operator Callback1<FirstArgument>() const
- {
- return Callback1<FirstArgument>(getEnvironment(), thunk);
}
};
return Callback1<FirstArgument>(ConstMemberCaller1<Functor, FirstArgument, &Functor::operator()>(functor));
}
+
+typedef Callback1<bool> BoolImportCallback;
+typedef Callback1<const BoolImportCallback&> BoolExportCallback;
+
+typedef Callback1<int> IntImportCallback;
+typedef Callback1<const IntImportCallback&> IntExportCallback;
+
+typedef Callback1<float> FloatImportCallback;
+typedef Callback1<const FloatImportCallback&> FloatExportCallback;
+
+typedef Callback1<const char*> StringImportCallback;
+typedef Callback1<const StringImportCallback&> StringExportCallback;
+
+typedef Callback1<std::size_t> SizeImportCallback;
+typedef Callback1<const SizeImportCallback&> SizeExportCallback;
+
+
#endif
--- /dev/null
+
+#include "callbackfwd.h"
+
--- /dev/null
+
+#if !defined(INCLUDED_CALLBACKFWD_H)
+#define INCLUDED_CALLBACKFWD_H
+
+template<typename Return>
+class Callback0;
+typedef Callback0<void> Callback;
+
+template<typename FirstArgument, typename Result = void>
+class Callback1;
+
+template<typename FirstArgument, typename SecondArgument, typename Result = void>
+class Callback2;
+
+template<typename FirstArgument, typename SecondArgument, typename ThirdArgument, typename Result = void>
+class Callback3;
+
+#endif
--- /dev/null
+
+#include "functional.h"
+
--- /dev/null
+
+#if !defined(INCLUDED_FUNCTIONAL_H)
+#define INCLUDED_FUNCTIONAL_H
+
+template<typename Object, typename R, R (Object::*member)()>
+class Member
+{
+public:
+ typedef Object& first_argument_type;
+ typedef R result_type;
+ static result_type call(first_argument_type object)
+ {
+ return (object.*member)();
+ }
+};
+
+template<typename Object, typename R, R (Object::*member)() const>
+class ConstMember
+{
+public:
+ typedef const Object& first_argument_type;
+ typedef R result_type;
+ static result_type call(first_argument_type object)
+ {
+ return (object.*member)();
+ }
+};
+
+template<typename Object, typename A1, typename R, R (Object::*member)(A1)>
+class Member1
+{
+public:
+ typedef Object& first_argument_type;
+ typedef A1 second_argument_type;
+ typedef R result_type;
+ static result_type call(first_argument_type object, second_argument_type a1)
+ {
+ return (object.*member)(a1);
+ }
+};
+
+template<typename Object, typename A1, typename R, R (Object::*member)(A1) const>
+class ConstMember1
+{
+public:
+ typedef const Object& first_argument_type;
+ typedef A1 second_argument_type;
+ typedef R result_type;
+ static result_type call(first_argument_type object, second_argument_type a1)
+ {
+ return (object.*member)(a1);
+ }
+};
+
+template<typename Object, typename A2, typename A3, typename R, R (Object::*member)(A2, A3)>
+class Member2
+{
+public:
+ typedef Object& first_argument_type;
+ typedef A2 second_argument_type;
+ typedef A3 third_argument_type;
+ typedef R result_type;
+ static result_type call(first_argument_type object, second_argument_type a2, third_argument_type a3)
+ {
+ return (object.*member)(a2, a3);
+ }
+};
+
+template<typename Object, typename A2, typename A3, typename R, R (Object::*member)(A2, A3) const>
+class ConstMember2
+{
+public:
+ typedef const Object& first_argument_type;
+ typedef A2 second_argument_type;
+ typedef A3 third_argument_type;
+ typedef R result_type;
+ static result_type call(first_argument_type object, second_argument_type a2, third_argument_type a3)
+ {
+ return (object.*member)(a2, a3);
+ }
+};
+
+template<typename Object, typename A2, typename A3, typename A4, typename R, R (Object::*member)(A2, A3, A4)>
+class Member3
+{
+public:
+ typedef Object& first_argument_type;
+ typedef A2 second_argument_type;
+ typedef A3 third_argument_type;
+ typedef A4 fourth_argument_type;
+ typedef R result_type;
+ static result_type call(first_argument_type object, second_argument_type a2, third_argument_type a3, fourth_argument_type a4)
+ {
+ return (object.*member)(a2, a3, a4);
+ }
+};
+
+template<typename Object, typename A2, typename A3, typename A4, typename R, R (Object::*member)(A2, A3, A4) const>
+class ConstMember3
+{
+public:
+ typedef const Object& first_argument_type;
+ typedef A2 second_argument_type;
+ typedef A3 third_argument_type;
+ typedef A4 fourth_argument_type;
+ typedef R result_type;
+ static result_type call(first_argument_type object, second_argument_type a2, third_argument_type a3, fourth_argument_type a4)
+ {
+ return (object.*member)(a2, a3, a4);
+ }
+};
+
+template<typename R, R (*func)()>
+class Function0
+{
+public:
+ typedef R result_type;
+ static result_type call()
+ {
+ return (func)();
+ }
+};
+
+template<typename A1, typename R, R (*func)(A1)>
+class Function1
+{
+public:
+ typedef A1 first_argument_type;
+ typedef R result_type;
+ static result_type call(first_argument_type a1)
+ {
+ return (func)(a1);
+ }
+};
+
+template<typename A1, typename A2, typename R, R (*func)(A1, A2)>
+class Function2
+{
+public:
+ typedef A1 first_argument_type;
+ typedef A2 second_argument_type;
+ typedef R result_type;
+ static result_type call(first_argument_type a1, second_argument_type a2)
+ {
+ return (func)(a1, a2);
+ }
+};
+
+template<typename A1, typename A2, typename A3, typename R, R (*func)(A1, A2, A3)>
+class Function3
+{
+public:
+ typedef A1 first_argument_type;
+ typedef A2 second_argument_type;
+ typedef A3 third_argument_type;
+ typedef R result_type;
+ static result_type call(first_argument_type a1, second_argument_type a2, third_argument_type a3)
+ {
+ return (func)(a1, a2, a3);
+ }
+};
+
+template<typename A1, typename A2, typename A3, typename A4, typename R, R (*func)(A1, A2, A3, A4)>
+class Function4
+{
+public:
+ typedef A1 first_argument_type;
+ typedef A2 second_argument_type;
+ typedef A3 third_argument_type;
+ typedef A4 fourth_argument_type;
+ typedef R result_type;
+ static result_type call(first_argument_type a1, second_argument_type a2, third_argument_type a3, fourth_argument_type a4)
+ {
+ return (func)(a1, a2, a3, a4);
+ }
+};
+
+template<typename Caller, typename FirstArgument = void*>
+class Caller0To1
+{
+public:
+ typedef FirstArgument first_argument_type;
+ typedef typename Caller::result_type result_type;
+ static result_type call(first_argument_type)
+ {
+ return Caller::call();
+ }
+};
+
+template<typename Caller, typename FirstArgument = void*>
+class Caller1To2
+{
+public:
+ typedef FirstArgument first_argument_type;
+ typedef typename Caller::first_argument_type second_argument_type;
+ typedef typename Caller::result_type result_type;
+ static result_type call(first_argument_type, second_argument_type a2)
+ {
+ return Caller::call(a2);
+ }
+};
+
+template<typename Caller, typename FirstArgument = void*>
+class Caller2To3
+{
+public:
+ typedef FirstArgument first_argument_type;
+ typedef typename Caller::first_argument_type second_argument_type;
+ typedef typename Caller::second_argument_type third_argument_type;
+ typedef typename Caller::result_type result_type;
+ static result_type call(first_argument_type, second_argument_type a2, third_argument_type a3)
+ {
+ return Caller::call(a2, a3);
+ }
+};
+
+template<typename Caller, typename FirstArgument = void*>
+class Caller3To4
+{
+public:
+ typedef FirstArgument first_argument_type;
+ typedef typename Caller::first_argument_type second_argument_type;
+ typedef typename Caller::second_argument_type third_argument_type;
+ typedef typename Caller::third_argument_type fourth_argument_type;
+ typedef typename Caller::result_type result_type;
+ static result_type call(first_argument_type, second_argument_type a2, third_argument_type a3, fourth_argument_type a4)
+ {
+ return Caller::call(a2, a3, a4);
+ }
+};
+
+template<typename Functor>
+class FunctorInvoke
+{
+public:
+ typedef typename Functor::result_type result_type;
+ inline result_type operator()(Functor functor)
+ {
+ return functor();
+ }
+};
+
+template<typename Functor>
+class Functor1Invoke
+{
+ typename Functor::first_argument_type a1;
+public:
+ typedef typename Functor::first_argument_type first_argument_type;
+ typedef typename Functor::result_type result_type;
+ Functor1Invoke(first_argument_type a1) : a1(a1)
+ {
+ }
+ inline result_type operator()(Functor functor)
+ {
+ return functor(a1);
+ }
+};
+
+template<typename Functor>
+class Functor2Invoke
+{
+ typename Functor::first_argument_type a1;
+ typename Functor::second_argument_type a2;
+public:
+ typedef typename Functor::first_argument_type first_argument_type;
+ typedef typename Functor::second_argument_type second_argument_type;
+ typedef typename Functor::result_type result_type;
+ Functor2Invoke(first_argument_type a1, second_argument_type a2)
+ : a1(a1), a2(a2)
+ {
+ }
+ inline result_type operator()(Functor functor)
+ {
+ return functor(a1, a2);
+ }
+};
+
+template<typename Functor>
+class Functor3Invoke
+{
+ typename Functor::first_argument_type a1;
+ typename Functor::second_argument_type a2;
+ typename Functor::third_argument_type a3;
+public:
+ typedef typename Functor::first_argument_type first_argument_type;
+ typedef typename Functor::second_argument_type second_argument_type;
+ typedef typename Functor::third_argument_type third_argument_type;
+ typedef typename Functor::result_type result_type;
+ Functor3Invoke(first_argument_type a1, second_argument_type a2, third_argument_type a3)
+ : a1(a1), a2(a2), a3(a3)
+ {
+ }
+ inline result_type operator()(Functor functor)
+ {
+ return functor(a1, a2, a3);
+ }
+};
+
+template<typename Type, typename Other, typename True, typename False>
+class TypeEqual
+{
+ template<typename Matched>
+ class Match
+ {
+ public:
+ typedef False type;
+ };
+ template<>
+ class Match<Other>
+ {
+ public:
+ typedef True type;
+ };
+public:
+ typedef typename Match<Type>::type type;
+};
+
+
+#endif
#if !defined(INCLUDED_GTKUTIL_BUTTON_H)
#define INCLUDED_GTKUTIL_BUTTON_H
+#include "generic/callbackfwd.h"
+
typedef struct _GtkButton GtkButton;
typedef struct _GtkToggleButton GtkToggleButton;
typedef struct _GtkRadioButton GtkRadioButton;
typedef int gint;
typedef gint gboolean;
typedef unsigned int guint;
-class Callback;
void button_connect_callback(GtkButton* button, const Callback& callback);
guint toggle_button_connect_callback(GtkToggleButton* button, const Callback& callback);
#if !defined(INCLUDED_GTKUTIL_MENU_H)
#define INCLUDED_GTKUTIL_MENU_H
-class Callback;
+#include "generic/callbackfwd.h"
+
typedef int gint;
typedef gint gboolean;
typedef struct _GSList GSList;
#if !defined(INCLUDED_GTKUTIL_TOOLBAR_H)
#define INCLUDED_GTKUTIL_TOOLBAR_H
-class Callback;
+#include "generic/callbackfwd.h"
+
typedef struct _GtkButton GtkButton;
typedef struct _GtkToggleButton GtkToggleButton;
typedef struct _GtkToolbar GtkToolbar;
<File
RelativePath=".\generic\callback.h">
</File>
+ <File
+ RelativePath=".\generic\callbackfwd.cpp">
+ </File>
+ <File
+ RelativePath=".\generic\callbackfwd.h">
+ </File>
<File
RelativePath=".\generic\constant.cpp">
</File>
<File
RelativePath=".\generic\enumeration.h">
</File>
+ <File
+ RelativePath=".\generic\functional.cpp">
+ </File>
+ <File
+ RelativePath=".\generic\functional.h">
+ </File>
<File
RelativePath=".\generic\object.cpp">
</File>
RelativePath=".\debugging\debugging.h">
</File>
</Filter>
+ <Filter
+ Name="signal"
+ Filter="">
+ <File
+ RelativePath=".\signal\isignal.cpp">
+ </File>
+ <File
+ RelativePath=".\signal\isignal.h">
+ </File>
+ <File
+ RelativePath=".\signal\signal.cpp">
+ </File>
+ <File
+ RelativePath=".\signal\signal.h">
+ </File>
+ <File
+ RelativePath=".\signal\signalfwd.cpp">
+ </File>
+ <File
+ RelativePath=".\signal\signalfwd.h">
+ </File>
+ </Filter>
<File
RelativePath=".\archivelib.cpp">
</File>
const Vector3 g_vector3_axes[3] = { g_vector3_axis_x, g_vector3_axis_y, g_vector3_axis_z };
+inline Vector3& vector3_from_array(float* array)
+{
+ return *reinterpret_cast<Vector3*>(array);
+}
+inline const Vector3& vector3_from_array(const float* array)
+{
+ return *reinterpret_cast<const Vector3*>(array);
+}
+
template<typename Element>
inline Element* vector3_to_array(BasicVector3<Element>& self)
{
--- /dev/null
+
+#include "isignal.h"
+
--- /dev/null
+
+#if !defined(INCLUDED_ISIGNAL_H)
+#define INCLUDED_ISIGNAL_H
+
+#include "generic/callback.h"
+#include "signal/signalfwd.h"
+
+class SignalHandlerResult
+{
+ bool value;
+public:
+ explicit SignalHandlerResult(bool value) : value(value)
+ {
+ }
+ bool operator==(SignalHandlerResult other) const
+ {
+ return value == other.value;
+ }
+ bool operator!=(SignalHandlerResult other) const
+ {
+ return !operator==(other);
+ }
+};
+
+const SignalHandlerResult SIGNAL_CONTINUE_EMISSION = SignalHandlerResult(false);
+const SignalHandlerResult SIGNAL_STOP_EMISSION = SignalHandlerResult(true);
+
+template<typename Caller>
+class SignalHandlerCaller1
+{
+public:
+ typedef typename Caller::first_argument_type first_argument_type;
+ typedef SignalHandlerResult result_type;
+ static result_type call(first_argument_type a1)
+ {
+ Caller::call(a1);
+ return SIGNAL_CONTINUE_EMISSION;
+ }
+};
+
+template<typename Caller>
+class SignalHandlerCaller2
+{
+public:
+ typedef typename Caller::first_argument_type first_argument_type;
+ typedef typename Caller::second_argument_type second_argument_type;
+ typedef SignalHandlerResult result_type;
+ static result_type call(first_argument_type a1, second_argument_type a2)
+ {
+ Caller::call(a1, a2);
+ return SIGNAL_CONTINUE_EMISSION;
+ }
+};
+
+template<typename Caller>
+class SignalHandlerCaller3
+{
+public:
+ typedef typename Caller::first_argument_type first_argument_type;
+ typedef typename Caller::second_argument_type second_argument_type;
+ typedef typename Caller::third_argument_type third_argument_type;
+ typedef SignalHandlerResult result_type;
+ static result_type call(first_argument_type a1, second_argument_type a2, third_argument_type a3)
+ {
+ Caller::call(a1, a2, a3);
+ return SIGNAL_CONTINUE_EMISSION;
+ }
+};
+
+template<typename Caller>
+class SignalHandlerCaller4
+{
+public:
+ typedef typename Caller::first_argument_type first_argument_type;
+ typedef typename Caller::second_argument_type second_argument_type;
+ typedef typename Caller::third_argument_type third_argument_type;
+ typedef typename Caller::fourth_argument_type fourth_argument_type;
+ typedef SignalHandlerResult result_type;
+ static result_type call(first_argument_type a1, second_argument_type a2, third_argument_type a3, fourth_argument_type a4)
+ {
+ Caller::call(a1, a2, a3, a4);
+ return SIGNAL_CONTINUE_EMISSION;
+ }
+};
+
+class SignalHandler : public Callback0<SignalHandlerResult>
+{
+public:
+ template<typename Caller>
+ SignalHandler(const BindFirstOpaque<Caller>& caller)
+ : Callback0<SignalHandlerResult>(BindFirstOpaque<typename TypeEqual<
+ typename Caller::result_type,
+ SignalHandlerResult,
+ Caller,
+ SignalHandlerCaller1<Caller>
+ >::type>(caller.getBound()))
+ {
+ }
+};
+
+template<typename Caller>
+inline SignalHandler makeSignalHandler(const BindFirstOpaque<Caller>& caller)
+{
+ return SignalHandler(caller);
+}
+template<typename Caller>
+inline SignalHandler makeSignalHandler(const Caller& caller, typename Caller::first_argument_type callee)
+{
+ return SignalHandler(BindFirstOpaque<Caller>(callee));
+}
+
+
+template<typename FirstArgument>
+class SignalHandler1 : public Callback1<FirstArgument, SignalHandlerResult>
+{
+public:
+ template<typename Caller>
+ SignalHandler1(const BindFirstOpaque1<Caller>& caller)
+ : Callback1<FirstArgument, SignalHandlerResult>(BindFirstOpaque1<typename TypeEqual<
+ typename Caller::result_type,
+ SignalHandlerResult,
+ Caller,
+ SignalHandlerCaller2<Caller>
+ >::type>(caller.getBound()))
+ {
+ }
+};
+
+template<typename Caller>
+inline SignalHandler1<typename Caller::second_argument_type> makeSignalHandler1(const BindFirstOpaque1<Caller>& caller)
+{
+ return SignalHandler1<typename Caller::second_argument_type>(caller);
+}
+template<typename Caller>
+inline SignalHandler1<typename Caller::second_argument_type> makeSignalHandler1(const Caller& caller, typename Caller::first_argument_type callee)
+{
+ return SignalHandler1<typename Caller::second_argument_type>(BindFirstOpaque1<Caller>(callee));
+}
+
+
+template<typename FirstArgument, typename SecondArgument>
+class SignalHandler2 : public Callback2<FirstArgument, SecondArgument, SignalHandlerResult>
+{
+public:
+ template<typename Caller>
+ SignalHandler2(const BindFirstOpaque2<Caller>& caller)
+ : Callback2<FirstArgument, SecondArgument, SignalHandlerResult>(BindFirstOpaque2<typename TypeEqual<
+ typename Caller::result_type,
+ SignalHandlerResult,
+ Caller,
+ SignalHandlerCaller3<Caller>
+ >::type>(caller.getBound()))
+ {
+ }
+};
+
+template<typename Caller>
+inline SignalHandler2<
+ typename Caller::second_argument_type,
+ typename Caller::third_argument_type
+> makeSignalHandler2(const BindFirstOpaque2<Caller>& caller)
+{
+ return SignalHandler2<
+ typename Caller::second_argument_type,
+ typename Caller::third_argument_type
+ >(caller);
+}
+template<typename Caller>
+inline SignalHandler2<
+ typename Caller::second_argument_type,
+ typename Caller::third_argument_type
+> makeSignalHandler2(const Caller& caller, typename Caller::first_argument_type callee)
+{
+ return SignalHandler2<
+ typename Caller::second_argument_type,
+ typename Caller::third_argument_type
+ >(BindFirstOpaque2<Caller>(callee));
+}
+
+
+template<typename FirstArgument, typename SecondArgument, typename ThirdArgument>
+class SignalHandler3 : public Callback3<FirstArgument, SecondArgument, ThirdArgument, SignalHandlerResult>
+{
+public:
+ template<typename Caller>
+ SignalHandler3(const BindFirstOpaque3<Caller>& caller)
+ : Callback3<FirstArgument, SecondArgument, ThirdArgument, SignalHandlerResult>(BindFirstOpaque3<typename TypeEqual<
+ typename Caller::result_type,
+ SignalHandlerResult,
+ Caller,
+ SignalHandlerCaller4<Caller>
+ >::type>(caller.getBound()))
+ {
+ }
+};
+
+template<typename Caller>
+inline SignalHandler3<
+ typename Caller::second_argument_type,
+ typename Caller::third_argument_type,
+ typename Caller::fourth_argument_type
+> makeSignalHandler3(const BindFirstOpaque3<Caller>& caller)
+{
+ return SignalHandler3<
+ typename Caller::second_argument_type,
+ typename Caller::third_argument_type,
+ typename Caller::fourth_argument_type
+ >(caller);
+}
+template<typename Caller>
+inline SignalHandler3<
+ typename Caller::second_argument_type,
+ typename Caller::third_argument_type,
+ typename Caller::fourth_argument_type
+> makeSignalHandler3(const Caller& caller, typename Caller::first_argument_type callee)
+{
+ return SignalHandler3<
+ typename Caller::second_argument_type,
+ typename Caller::third_argument_type,
+ typename Caller::fourth_argument_type
+ >(BindFirstOpaque3<Caller>(callee));
+}
+
+#endif
--- /dev/null
+
+#include "signal.h"
+
+
+
+namespace
+{
+ class Test
+ {
+ };
+ class A1
+ {
+ };
+ class A2
+ {
+ };
+ class A3
+ {
+ };
+
+ SignalHandlerResult handler0(Test&)
+ {
+ return SIGNAL_CONTINUE_EMISSION;
+ }
+ typedef Function1<Test&, SignalHandlerResult, handler0> TestHandler0;
+
+ int function0(Test&)
+ {
+ return 7;
+ }
+ typedef Function1<Test&, int, function0> TestFunction0;
+
+ SignalHandlerResult handler1(Test&, A1)
+ {
+ return SIGNAL_CONTINUE_EMISSION;
+ }
+ typedef Function2<Test&, A1, SignalHandlerResult, handler1> TestHandler1;
+
+ void function1(Test&, A1)
+ {
+ }
+ typedef ReferenceCaller1<Test, A1, function1> TestFunction1;
+
+ SignalHandlerResult handler2(Test&, A1, A2)
+ {
+ return SIGNAL_CONTINUE_EMISSION;
+ }
+ typedef Function3<Test&, A1, A2, SignalHandlerResult, handler2> TestHandler2;
+
+ void function2(Test&, A1, A2)
+ {
+ }
+ typedef Function3<Test&, A1, A2, void, function2> TestFunction2;
+
+ SignalHandlerResult handler3(Test&, A1, A2, A3)
+ {
+ return SIGNAL_CONTINUE_EMISSION;
+ }
+ typedef Function4<Test&, A1, A2, A3, SignalHandlerResult, handler3> TestHandler3;
+
+ void function3(Test&, A1, A2, A3)
+ {
+ }
+ typedef Function4<Test&, A1, A2, A3, void, function3> TestFunction3;
+
+ void testSignals()
+ {
+ Test test;
+ {
+ Signal0 e0;
+ Signal0::handler_id_type a = e0.connectLast(makeSignalHandler(TestHandler0(), test)); // signal handler from direct caller returning result
+ Signal0::handler_id_type b = e0.connectFirst(makeSignalHandler(TestFunction0(), test)); // signal handler from direct caller returning int
+ e0();
+ e0.disconnect(a);
+ e0.disconnect(b);
+ }
+ {
+ typedef Signal1<A1> Signal1Test;
+ Signal1Test e1;
+ Signal1Test::handler_id_type a = e1.connectLast(makeSignalHandler1(TestHandler1(), test)); // signal handler from direct caller with one argument, returning result
+ Signal1Test::handler_id_type b = e1.connectFirst(makeSignalHandler1(TestFunction1(test))); // signal handler from opaque caller with one argument, returning void
+ e1(A1());
+ e1.disconnect(a);
+ e1.disconnect(b);
+ }
+ {
+ typedef Signal2<A1, A2> Signal2Test;
+ Signal2Test e2;
+ Signal2Test::handler_id_type a = e2.connectLast(makeSignalHandler2(TestHandler2(), test)); // signal handler from direct caller with two arguments, returning result
+ Signal2Test::handler_id_type b = e2.connectLast(makeSignalHandler2(TestFunction2(), test)); // signal handler from direct caller with two arguments, returning void
+ e2(A1(), A2());
+ e2.disconnect(a);
+ e2.disconnect(b);
+ }
+ {
+ typedef Signal3<A1, A2, A3> Signal3Test;
+ Signal3Test e3;
+ Signal3Test::handler_id_type a = e3.connectLast(makeSignalHandler3(TestHandler3(), test)); // signal handler from direct caller with three arguments, returning result
+ Signal3Test::handler_id_type b = e3.connectLast(makeSignalHandler3(TestFunction3(), test)); // signal handler from direct caller with three arguments, returning void
+ e3(A1(), A2(), A3());
+ e3.disconnect(a);
+ e3.disconnect(b);
+ }
+ }
+}
--- /dev/null
+
+#if !defined(INCLUDED_SIGNAL_H)
+#define INCLUDED_SIGNAL_H
+
+#include "isignal.h"
+#include "memory/allocator.h"
+#include "debugging/debugging.h"
+#include <iterator>
+
+namespace ListDetail
+{
+ struct ListNodeBase
+ {
+ ListNodeBase* next;
+ ListNodeBase* prev;
+ };
+
+ inline void list_initialise(ListNodeBase& self)
+ {
+ self.next = self.prev = &self;
+ }
+
+ inline void list_swap(ListNodeBase& self, ListNodeBase& other)
+ {
+ ListNodeBase tmp(self);
+ if(other.next == &other)
+ {
+ list_initialise(self);
+ }
+ else
+ {
+ self = other;
+ self.next->prev = self.prev->next = &self;
+ }
+ if(tmp.next == &self)
+ {
+ list_initialise(other);
+ }
+ else
+ {
+ other = tmp;
+ other.next->prev = other.prev->next = &other;
+ }
+ }
+
+ inline void node_link(ListNodeBase* node, ListNodeBase* next)
+ {
+ node->next = next;
+ node->prev = next->prev;
+ next->prev = node;
+ node->prev->next = node;
+ }
+ inline void node_unlink(ListNodeBase* node)
+ {
+ node->prev->next = node->next;
+ node->next->prev = node->prev;
+ }
+
+ template<typename Value>
+ struct ListNode : public ListNodeBase
+ {
+ Value value;
+
+ ListNode(const Value& value) : value(value)
+ {
+ }
+ ListNode* getNext() const
+ {
+ return static_cast<ListNode*>(next);
+ }
+ ListNode* getPrev() const
+ {
+ return static_cast<ListNode*>(prev);
+ }
+ };
+
+ template<typename Type>
+ class NonConstTraits
+ {
+ public:
+ typedef Type value_type;
+ typedef value_type* pointer;
+ typedef value_type& reference;
+
+ template<typename Other>
+ struct rebind
+ {
+ typedef NonConstTraits<Other> other;
+ };
+ };
+
+ template<typename Type>
+ class ConstTraits
+ {
+ public:
+ typedef Type value_type;
+ typedef const value_type* pointer;
+ typedef const value_type& reference;
+
+ template<typename Other>
+ struct rebind
+ {
+ typedef ConstTraits<Other> other;
+ };
+ };
+
+ template<typename Traits>
+ class ListIterator
+ {
+ public:
+ typedef std::forward_iterator_tag iterator_category;
+ typedef std::ptrdiff_t difference_type;
+ typedef difference_type distance_type;
+ typedef typename Traits::value_type value_type;
+ typedef typename Traits::pointer pointer;
+ typedef typename Traits::reference reference;
+
+ private:
+ typedef ListNode<value_type> Node;
+ typedef typename Traits::template rebind<Node>::other NodeTraits;
+ typedef typename NodeTraits::pointer NodePointer;
+ typedef typename Traits::template rebind< Opaque<value_type> >::other OpaqueTraits;
+ typedef typename OpaqueTraits::pointer OpaquePointer;
+ NodePointer m_node;
+
+ void increment()
+ {
+ m_node = m_node->getNext();
+ }
+ void decrement()
+ {
+ m_node = m_node->getPrev();
+ }
+
+
+ public:
+ explicit ListIterator(NodePointer node) : m_node(node)
+ {
+ }
+ explicit ListIterator(OpaquePointer p) : m_node(reinterpret_cast<NodePointer>(p))
+ {
+ }
+
+ NodePointer node()
+ {
+ return m_node;
+ }
+ OpaquePointer opaque() const
+ {
+ return reinterpret_cast<OpaquePointer>(m_node);
+ }
+
+ bool operator==(const ListIterator& other) const
+ {
+ return m_node == other.m_node;
+ }
+ bool operator!=(const ListIterator& other) const
+ {
+ return !operator==(other);
+ }
+ ListIterator& operator++()
+ {
+ increment();
+ return *this;
+ }
+ ListIterator operator++(int)
+ {
+ ListIterator tmp = *this;
+ increment();
+ return tmp;
+ }
+ ListIterator& operator--()
+ {
+ decrement();
+ return *this;
+ }
+ ListIterator operator--(int)
+ {
+ ListIterator tmp = *this;
+ decrement();
+ return tmp;
+ }
+ reference operator*() const
+ {
+ return m_node->value;
+ }
+ pointer operator->() const
+ {
+ return &(operator*());
+ }
+ };
+}
+
+class Opaque;
+
+template<typename Value, typename Allocator = DefaultAllocator<Value> >
+class List : private Allocator
+{
+ typedef ListDetail::ListNode<Value> Node;
+ ListDetail::ListNodeBase list;
+ typedef typename Allocator::template rebind<Node>::other NodeAllocator;
+public:
+ typedef Value value_type;
+ typedef ListDetail::ListIterator< ListDetail::NonConstTraits<Value> > iterator;
+ typedef ListDetail::ListIterator< ListDetail::ConstTraits<Value> > const_iterator;
+
+ List()
+ {
+ list_initialise(list);
+ }
+ explicit List(const Allocator& allocator) : Allocator(allocator)
+ {
+ list_initialise(list);
+ }
+ iterator begin()
+ {
+ return iterator(static_cast<Node*>(list.next));
+ }
+ iterator end()
+ {
+ return iterator(static_cast<Node*>(&list));
+ }
+ const_iterator begin() const
+ {
+ return const_iterator(static_cast<const Node*>(list.next));
+ }
+ const_iterator end() const
+ {
+ return const_iterator(static_cast<const Node*>(&list));
+ }
+ void push_back(const Value& value)
+ {
+ insert(end(), value);
+ }
+ void pop_back(const Value& value)
+ {
+ erase(--end(), value);
+ }
+ void push_front(const Value& value)
+ {
+ insert(begin(), value);
+ }
+ void pop_front(const Value& value)
+ {
+ erase(begin(), value);
+ }
+ iterator insert(iterator pos, const Value& x)
+ {
+ Node* node = new (NodeAllocator(*this).allocate(1)) Node(x);
+ node_link(node, pos.node());
+ return iterator(node);
+ }
+ iterator erase(iterator pos)
+ {
+ Node* node = pos.node();
+ Node* next = node->getNext();
+ node_unlink(node);
+ node->~Node();
+ NodeAllocator(*this).deallocate(node, 1);
+ return iterator(next);
+ }
+};
+
+template<typename Functor>
+class SignalBase
+{
+ typedef List<Functor> SignalList;
+ SignalList events;
+
+public:
+
+ typedef Functor handler_type;
+ typedef Handle< Opaque<Functor> > handler_id_type;
+ typedef typename SignalList::iterator iterator;
+ typedef typename SignalList::const_iterator const_iterator;
+ iterator begin()
+ {
+ return events.begin();
+ }
+ iterator end()
+ {
+ return events.end();
+ }
+ const_iterator begin() const
+ {
+ return events.begin();
+ }
+ const_iterator end() const
+ {
+ return events.end();
+ }
+ handler_id_type connectFirst(const Functor& event)
+ {
+ events.push_front(event);
+ return handler_id_type(begin().opaque());
+ }
+ handler_id_type connectLast(const Functor& event)
+ {
+ events.push_back(event);
+ return handler_id_type((--end()).opaque());
+ }
+ bool isConnected(handler_id_type id)
+ {
+ for(iterator i = begin(); i != end(); ++i)
+ {
+ if(id.get() == i.opaque())
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+ handler_id_type connectBefore(handler_id_type id, const Functor& event)
+ {
+ ASSERT_MESSAGE(isConnected(id), "SignalBase::connectBefore: invalid id");
+ return events.insert(iterator(id.get()), event).opaque();
+ }
+ handler_id_type connectAfter(handler_id_type id, const Functor& event)
+ {
+ ASSERT_MESSAGE(isConnected(id), "SignalBase::connectAfter: invalid id");
+ return events.insert(++iterator(id.get()), event).opaque();
+ }
+ void disconnect(handler_id_type id)
+ {
+ ASSERT_MESSAGE(isConnected(id), "SignalBase::disconnect: invalid id");
+ events.erase(iterator(id.get()));
+ }
+};
+
+///\brief
+// It is safe to disconnect the signal handler currently being invoked.
+template<typename InputIterator, typename SignalHandlerInvoke>
+inline void invokeSignalHandlers(InputIterator first, InputIterator last, SignalHandlerInvoke invoke)
+{
+ while(first != last && invoke(*first++) != SIGNAL_STOP_EMISSION);
+}
+
+class Signal0 : public SignalBase<SignalHandler>
+{
+public:
+ void operator()() const
+ {
+ invokeSignalHandlers(begin(), end(), FunctorInvoke<typename handler_type>());
+ }
+};
+
+template<typename FirstArgument>
+class Signal1 : public SignalBase< SignalHandler1<FirstArgument> >
+{
+public:
+ void operator()(FirstArgument a1) const
+ {
+ invokeSignalHandlers(begin(), end(), Functor1Invoke<typename handler_type>(a1));
+ }
+};
+
+template<typename FirstArgument, typename SecondArgument>
+class Signal2 : public SignalBase< SignalHandler2<FirstArgument, SecondArgument> >
+{
+public:
+ void operator()(FirstArgument a1, SecondArgument a2) const
+ {
+ invokeSignalHandlers(begin(), end(), Functor2Invoke<typename handler_type>(a1, a2));
+ }
+};
+
+template<typename FirstArgument, typename SecondArgument, typename ThirdArgument>
+class Signal3 : public SignalBase< SignalHandler3<FirstArgument, SecondArgument, ThirdArgument> >
+{
+public:
+ void operator()(FirstArgument a1, SecondArgument a2, ThirdArgument a3) const
+ {
+ invokeSignalHandlers(begin(), end(), Functor3Invoke<typename handler_type>(a1, a2, a3));
+ }
+};
+
+#endif
--- /dev/null
+
+#include "signalfwd.h"
+
--- /dev/null
+
+#if !defined(INCLUDED_SIGNALFWD_H)
+#define INCLUDED_SIGNALFWD_H
+
+class SignalHandler;
+template<typename FirstArgument>
+class SignalHandler1;
+template<typename FirstArgument, typename SecondArgument>
+class SignalHandler2;
+template<typename FirstArgument, typename SecondArgument, typename ThirdArgument>
+class SignalHandler3;
+
+template<typename Context>
+class Opaque;
+
+///\brief A pointer that always has a well-defined value.
+/// If no value is specified, the appropriate null value is used.
+template<typename Type>
+class Handle
+{
+ Type* p;
+public:
+ Handle() : p(0)
+ {
+ }
+ explicit Handle(Type* p) : p(p)
+ {
+ }
+ Type* get() const
+ {
+ return p;
+ }
+ bool isNull() const
+ {
+ return p == 0;
+ }
+};
+
+template<typename Handler>
+class SignalFwd
+{
+public:
+ typedef Handle< Opaque<Handler> > handler_id_type;
+};
+
+typedef SignalFwd<SignalHandler>::handler_id_type SignalHandlerId;
+
+#endif
#include <map>
+///\brief All string pointers passed to an instance of this class are not
+/// copied and must stay valid for the lifetime of the instance.
class StaticElement : public XMLElement
{
- struct strless
- {
- bool operator()(const char* s1, const char* s2) const
- {
- return strcmp(s1, s2) < 0;
- }
- };
-
- typedef std::map<const char*, const char*, strless> attrs_t;
+ typedef std::map<const char*, const char*, RawStringLess> attrs_t;
public:
StaticElement(const char* name)
: m_name(name)
attrs_t m_attrs;
};
+///\brief All string pointers passed to an instance of this class are copied.
class DynamicElement : public XMLElement
{
typedef std::map<CopiedString, CopiedString> attrs_t;
public:
DynamicElement(const char* name)
: m_name(name)
- {}
+ {
+ }
void insertAttribute(const char* name, const char* value)
{
m_attrs.insert(attrs_t::value_type(name, value));
#include "math/curve.h"
#include "stream/stringstream.h"
+#include "signal/signal.h"
#include "selectionlib.h"
#include "render.h"
#include "stringio.h"
class NURBSCurve
{
- typedef std::set<Callback> Callbacks;
- Callbacks m_curveChanged;
+ Signal0 m_curveChanged;
Callback m_boundsChanged;
public:
ControlPoints m_controlPoints;
{
}
- void attach(const Callback& curveChanged)
+ SignalHandlerId connect(const SignalHandler& curveChanged)
{
- m_curveChanged.insert(curveChanged);
curveChanged();
+ return m_curveChanged.connectLast(curveChanged);
}
- void detach(const Callback& curveChanged)
+ void disconnect(SignalHandlerId id)
{
- m_curveChanged.erase(curveChanged);
+ m_curveChanged.disconnect(id);
}
void notify()
{
- std::for_each(m_curveChanged.begin(), m_curveChanged.end(), CallbackInvoke());
+ m_curveChanged();
}
void tesselate()
class CatmullRomSpline
{
- typedef std::set<Callback> Callbacks;
- Callbacks m_curveChanged;
+ Signal0 m_curveChanged;
Callback m_boundsChanged;
public:
ControlPoints m_controlPoints;
{
}
- void attach(const Callback& curveChanged)
+ SignalHandlerId connect(const SignalHandler& curveChanged)
{
- m_curveChanged.insert(curveChanged);
curveChanged();
+ return m_curveChanged.connectLast(curveChanged);
}
- void detach(const Callback& curveChanged)
+ void disconnect(SignalHandlerId id)
{
- m_curveChanged.erase(curveChanged);
+ m_curveChanged.disconnect(id);
}
void notify()
{
- std::for_each(m_curveChanged.begin(), m_curveChanged.end(), CallbackInvoke());
+ m_curveChanged();
}
void tesselate()
public:
NURBSCurve m_curveNURBS;
+ SignalHandlerId m_curveNURBSChanged;
CatmullRomSpline m_curveCatmullRom;
+ SignalHandlerId m_curveCatmullRomChanged;
private:
mutable AABB m_curveBounds;
m_curveCatmullRom(m_contained.m_curveCatmullRom.m_controlPointsTransformed, SelectionChangedComponentCaller(*this))
{
m_contained.instanceAttach(Instance::path());
- m_contained.m_curveNURBS.attach(CurveEdit::CurveChangedCaller(m_curveNURBS));
- m_contained.m_curveCatmullRom.attach(CurveEdit::CurveChangedCaller(m_curveCatmullRom));
+ m_contained.m_curveNURBSChanged = m_contained.m_curveNURBS.connect(CurveEdit::CurveChangedCaller(m_curveNURBS));
+ m_contained.m_curveCatmullRomChanged = m_contained.m_curveCatmullRom.connect(CurveEdit::CurveChangedCaller(m_curveCatmullRom));
StaticRenderableConnectionLines::instance().attach(*this);
}
{
StaticRenderableConnectionLines::instance().detach(*this);
- m_contained.m_curveCatmullRom.detach(CurveEdit::CurveChangedCaller(m_curveCatmullRom));
- m_contained.m_curveNURBS.detach(CurveEdit::CurveChangedCaller(m_curveNURBS));
+ m_contained.m_curveCatmullRom.disconnect(m_contained.m_curveCatmullRomChanged);
+ m_contained.m_curveNURBS.disconnect(m_contained.m_curveNURBSChanged);
m_contained.instanceDetach(Instance::path());
}
void renderSolid(Renderer& renderer, const VolumeTest& volume) const
#include "entitylib.h"
#include <map>
-class KeyObserverMap : public EntityKeyValues::Observer
+class KeyObserverMap : public Entity::Observer
{
typedef std::multimap<const char*, KeyObserver, RawStringLess> KeyObservers;
KeyObservers m_keyObservers;
{
m_keyObservers.insert(KeyObservers::value_type(key, observer));
}
- void insert(const char* key, EntityKeyValues::Value& value)
+ void insert(const char* key, EntityKeyValue& value)
{
for(KeyObservers::const_iterator i = m_keyObservers.find(key); i != m_keyObservers.end() && string_equal((*i).first, key); ++i)
{
value.attach((*i).second);
}
}
- void erase(const char* key, EntityKeyValues::Value& value)
+ void erase(const char* key, EntityKeyValue& value)
{
for(KeyObservers::const_iterator i = m_keyObservers.find(key); i != m_keyObservers.end() && string_equal((*i).first, key); ++i)
{
};
-typedef MemberCaller1<KeyValue, const char*, &KeyValue::assign> KeyValueAssignCaller;
-typedef MemberCaller1<KeyValue, const KeyObserver&, &KeyValue::attach> KeyValueAttachCaller;
-typedef MemberCaller1<KeyValue, const KeyObserver&, &KeyValue::detach> KeyValueDetachCaller;
+typedef MemberCaller1<EntityKeyValue, const char*, &EntityKeyValue::assign> KeyValueAssignCaller;
+typedef MemberCaller1<EntityKeyValue, const KeyObserver&, &EntityKeyValue::attach> KeyValueAttachCaller;
+typedef MemberCaller1<EntityKeyValue, const KeyObserver&, &EntityKeyValue::detach> KeyValueDetachCaller;
-class NameKeys : public EntityKeyValues::Observer, public Namespaced
+class NameKeys : public Entity::Observer, public Namespaced
{
Namespace* m_namespace;
EntityKeyValues& m_entity;
NameKeys(const NameKeys& other);
NameKeys& operator=(const NameKeys& other);
- typedef std::map<CopiedString, EntityKeyValues::Value*> KeyValues;
+ typedef std::map<CopiedString, EntityKeyValue*> KeyValues;
KeyValues m_keyValues;
- void insertName(const char* key, EntityKeyValues::Value& value)
+ void insertName(const char* key, EntityKeyValue& value)
{
if(m_namespace != 0 && m_keyIsName(key))
{
m_namespace->attach(KeyValueAssignCaller(value), KeyValueAttachCaller(value));
}
}
- void eraseName(const char* key, EntityKeyValues::Value& value)
+ void eraseName(const char* key, EntityKeyValue& value)
{
if(m_namespace != 0 && m_keyIsName(key))
{
m_keyIsName = keyIsName;
insertAll();
}
- void insert(const char* key, EntityKeyValues::Value& value)
+ void insert(const char* key, EntityKeyValue& value)
{
m_keyValues.insert(KeyValues::value_type(key, &value));
insertName(key, value);
}
- void erase(const char* key, EntityKeyValues::Value& value)
+ void erase(const char* key, EntityKeyValue& value)
{
eraseName(key, value);
m_keyValues.erase(key);
}
};
-class TargetKeys : public EntityKeyValues::Observer
+class TargetKeys : public Entity::Observer
{
TargetingEntities m_targetingEntities;
Callback m_targetsChanged;
m_targetsChanged();
}
- void insert(const char* key, EntityKeyValues::Value& value)
+ void insert(const char* key, EntityKeyValue& value)
{
std::size_t index;
if(readTargetKey(key, index))
targetsChanged();
}
}
- void erase(const char* key, EntityKeyValues::Value& value)
+ void erase(const char* key, EntityKeyValue& value)
{
std::size_t index;
if(readTargetKey(key, index))
class TargetableInstance :
public SelectableInstance,
public Targetable,
-public EntityKeyValues::Observer
+public Entity::Observer
{
mutable Vertex3f m_position;
EntityKeyValues& m_entity;
m_targeting.targetsChanged();
}
- void insert(const char* key, EntityKeyValues::Value& value)
+ void insert(const char* key, EntityKeyValue& value)
{
if(string_equal(key, g_targetable_nameKey))
{
value.attach(TargetedEntity::TargetnameChangedCaller(m_targeted));
}
}
- void erase(const char* key, EntityKeyValues::Value& value)
+ void erase(const char* key, EntityKeyValue& value)
{
if(string_equal(key, g_targetable_nameKey))
{
*/
#include "brush.h"
+#include "signal/signal.h"
-std::set<Callback> g_brushTextureChangedCallbacks;
+Signal0 g_brushTextureChangedCallbacks;
-void Brush_addTextureChangedCallback(const Callback& callback)
+void Brush_addTextureChangedCallback(const SignalHandler& handler)
{
- g_brushTextureChangedCallbacks.insert(callback);
+ g_brushTextureChangedCallbacks.connectLast(handler);
}
void Brush_textureChanged()
{
- std::for_each(g_brushTextureChangedCallbacks.begin(), g_brushTextureChangedCallbacks.end(), CallbackInvoke());
+ g_brushTextureChangedCallbacks();
}
QuantiseFunc Face::m_quantise;
#include "texturelib.h"
#include "container/container.h"
#include "generic/bitfield.h"
+#include "signal/signalfwd.h"
#include "winding.h"
#include "brush_primit.h"
};
-inline void FaceShader_getFlags(const FaceShader& faceShader, ContentsFlagsValue& flags)
-{
- flags = faceShader.getFlags();
-}
-
-
-
class FaceTexdef : public FaceShaderObserver
}
};
-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] << " ) "
}
};
+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;
bool face_filtered(Face& face);
-void Brush_addTextureChangedCallback(const Callback& callback);
+void Brush_addTextureChangedCallback(const SignalHandler& callback);
void Brush_textureChanged();
}
}
-
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)
Brush_textureChanged();
}
+ void GetTexdef(TextureProjection& projection) const
+ {
+ projection = m_texdef.normalised();
+ }
void SetTexdef(const TextureProjection& projection)
{
undoSave();
texdefChanged();
}
+ void GetFlags(ContentsFlagsValue& flags) const
+ {
+ flags = m_shader.getFlags();
+ }
void SetFlags(const ContentsFlagsValue& flags)
{
undoSave();
{
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)
void clear()
{
+ undoSave();
if(m_instanceCounter.m_count != 0)
{
forEachFace_instanceDetach(m_map);
}
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()
};
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>
};
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_getIBrush(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
#include <list>
-
void Brush_ConstructCuboid(Brush& brush, const AABB& bounds, const char* shader, const TextureProjection& projection)
{
const unsigned char box[3][2] = { { 0, 1 }, { 2, 0 }, { 1, 2 } };
Vector3 mins(vector3_subtracted(bounds.origin, bounds.extents));
Vector3 maxs(vector3_added(bounds.origin, bounds.extents));
- brush.undoSave();
brush.clear();
brush.reserve(6);
return;
}
- brush.undoSave();
brush.clear();
brush.reserve(sides+2);
return;
}
- brush.undoSave();
brush.clear();
brush.reserve(sides+1);
return;
}
- brush.undoSave();
brush.clear();
brush.reserve(sides*sides);
}
-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 Visitor>
-class FaceVisitAll : public BrushInstanceVisitor
-{
- const Visitor& m_visitor;
-public:
- FaceVisitAll(const Visitor& visitor)
- : m_visitor(visitor)
- {
- }
- void visit(FaceInstance& face) const
- {
- m_visitor.visit(face.getFace());
- }
-};
-
-template<class Visitor>
-class FaceInstanceVisitAll : public BrushInstanceVisitor
-{
- const Visitor& m_visitor;
-public:
- FaceInstanceVisitAll(const Visitor& visitor)
- : m_visitor(visitor)
- {
- }
- void visit(FaceInstance& face) const
- {
- m_visitor.visit(face);
- }
-};
-
-#if 0
-template<class Visitor>
-class FaceVisitSelected : public BrushInstanceVisitor
-{
- const Visitor& m_visitor;
-public:
- FaceVisitSelected(const Visitor& visitor)
- : m_visitor(visitor)
- {
- }
- void visit(FaceInstance& face) const
- {
- if(face.isSelected(SelectionSystem::eFace))
- {
- m_visitor.visit(face.getFace());
- }
- }
-};
-#endif
-
-template<typename Functor>
-inline void Scene_forEachBrush(scene::Graph& graph, const Functor& functor)
-{
- graph.traverse(InstanceWalker< InstanceApply<BrushInstance, Functor> >(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 void Scene_forEachVisibleBrush(scene::Graph& graph, const Functor& functor)
-{
- graph.traverse(BrushVisibleWalker<Functor>(functor));
-}
-
-template<typename Visitor>
-inline void Scene_ForEachBrush_ForEachFace(scene::Graph& graph, const Visitor& visitor)
-{
- Scene_forEachBrush(graph, BrushForEachFace(FaceVisitAll<Visitor>(visitor)));
-}
-
-template<typename Visitor>
-inline void Scene_ForEachSelectedBrush_ForEachFace(scene::Graph& graph, const Visitor& visitor)
-{
- Scene_forEachSelectedBrush(BrushForEachFace(FaceVisitAll<Visitor>(visitor)));
-}
-
-template<typename Visitor>
-inline void Scene_ForEachSelectedBrush_ForEachFaceInstance(scene::Graph& graph, const Visitor& visitor)
-{
- Scene_forEachSelectedBrush(BrushForEachFace(FaceInstanceVisitAll<Visitor>(visitor)));
-}
-
-template<typename Visitor>
-class FaceVisitorWrapper
-{
- Visitor& m_visitor;
-public:
- FaceVisitorWrapper(Visitor& visitor) : m_visitor(visitor)
- {
- }
-
- void operator()(FaceInstance& faceInstance)
- {
- m_visitor.visit(faceInstance.getFace());
- }
-};
-
-template<typename Visitor>
-inline void Scene_ForEachSelectedBrushFace(scene::Graph& graph, Visitor& faceVisitor)
-{
- g_SelectedFaceInstances.foreach(FaceVisitorWrapper<Visitor>(faceVisitor));
-}
-
-
-
-class FaceSetTexdefVisitor
+class FaceSetTexdef
{
const TextureProjection& m_projection;
public:
- FaceSetTexdefVisitor(const TextureProjection& projection) : m_projection(projection)
+ FaceSetTexdef(const TextureProjection& projection) : m_projection(projection)
{
}
- void visit(Face& face) const
+ void operator()(Face& face) const
{
face.SetTexdef(m_projection);
}
void Scene_BrushSetTexdef_Selected(scene::Graph& graph, const TextureProjection& projection)
{
- Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetTexdefVisitor(projection));
+ Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetTexdef(projection));
SceneChangeNotify();
}
void Scene_BrushSetTexdef_Component_Selected(scene::Graph& graph, const TextureProjection& projection)
{
- FaceSetTexdefVisitor visitor(projection);
- Scene_ForEachSelectedBrushFace(graph, visitor);
+ Scene_ForEachSelectedBrushFace(graph, FaceSetTexdef(projection));
SceneChangeNotify();
}
-class FaceSetFlagsVisitor
+class FaceSetFlags
{
const ContentsFlagsValue& m_projection;
public:
- FaceSetFlagsVisitor(const ContentsFlagsValue& flags) : m_projection(flags)
+ FaceSetFlags(const ContentsFlagsValue& flags) : m_projection(flags)
{
}
- void visit(Face& face) const
+ void operator()(Face& face) const
{
face.SetFlags(m_projection);
}
void Scene_BrushSetFlags_Selected(scene::Graph& graph, const ContentsFlagsValue& flags)
{
- Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetFlagsVisitor(flags));
+ Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetFlags(flags));
SceneChangeNotify();
}
void Scene_BrushSetFlags_Component_Selected(scene::Graph& graph, const ContentsFlagsValue& flags)
{
- FaceSetFlagsVisitor visitor(flags);
- Scene_ForEachSelectedBrushFace(graph, visitor);
+ Scene_ForEachSelectedBrushFace(graph, FaceSetFlags(flags));
SceneChangeNotify();
}
-class FaceShiftTexdefVisitor
+class FaceShiftTexdef
{
float m_s, m_t;
public:
- FaceShiftTexdefVisitor(float s, float t) : m_s(s), m_t(t)
+ FaceShiftTexdef(float s, float t) : m_s(s), m_t(t)
{
}
- void visit(Face& face) const
+ 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, FaceShiftTexdefVisitor(s, t));
+ Scene_ForEachSelectedBrush_ForEachFace(graph, FaceShiftTexdef(s, t));
SceneChangeNotify();
}
void Scene_BrushShiftTexdef_Component_Selected(scene::Graph& graph, float s, float t)
{
- FaceShiftTexdefVisitor visitor(s, t);
- Scene_ForEachSelectedBrushFace(graph, visitor);
+ Scene_ForEachSelectedBrushFace(graph, FaceShiftTexdef(s, t));
SceneChangeNotify();
}
-class FaceScaleTexdefVisitor
+class FaceScaleTexdef
{
float m_s, m_t;
public:
- FaceScaleTexdefVisitor(float s, float t) : m_s(s), m_t(t)
+ FaceScaleTexdef(float s, float t) : m_s(s), m_t(t)
{
}
- void visit(Face& face) const
+ 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, FaceScaleTexdefVisitor(s, t));
+ Scene_ForEachSelectedBrush_ForEachFace(graph, FaceScaleTexdef(s, t));
SceneChangeNotify();
}
void Scene_BrushScaleTexdef_Component_Selected(scene::Graph& graph, float s, float t)
{
- FaceScaleTexdefVisitor visitor(s, t);
- Scene_ForEachSelectedBrushFace(graph, visitor);
+ Scene_ForEachSelectedBrushFace(graph, FaceScaleTexdef(s, t));
SceneChangeNotify();
}
-class FaceRotateTexdefVisitor
+class FaceRotateTexdef
{
float m_angle;
public:
- FaceRotateTexdefVisitor(float angle) : m_angle(angle)
+ FaceRotateTexdef(float angle) : m_angle(angle)
{
}
- void visit(Face& face) const
+ void operator()(Face& face) const
{
face.RotateTexdef(m_angle);
}
void Scene_BrushRotateTexdef_Selected(scene::Graph& graph, float angle)
{
- Scene_ForEachSelectedBrush_ForEachFace(graph, FaceRotateTexdefVisitor(angle));
+ Scene_ForEachSelectedBrush_ForEachFace(graph, FaceRotateTexdef(angle));
SceneChangeNotify();
}
void Scene_BrushRotateTexdef_Component_Selected(scene::Graph& graph, float angle)
{
- FaceRotateTexdefVisitor visitor(angle);
- Scene_ForEachSelectedBrushFace(graph, visitor);
+ Scene_ForEachSelectedBrushFace(graph, FaceRotateTexdef(angle));
SceneChangeNotify();
}
-class FaceSetShaderVisitor
+class FaceSetShader
{
const char* m_name;
public:
- FaceSetShaderVisitor(const char* name) : m_name(name) {}
- void visit(Face& face) const
+ 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, FaceSetShaderVisitor(name));
+ Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetShader(name));
SceneChangeNotify();
}
void Scene_BrushSetShader_Component_Selected(scene::Graph& graph, const char* name)
{
- FaceSetShaderVisitor visitor(name);
- Scene_ForEachSelectedBrushFace(graph, visitor);
+ Scene_ForEachSelectedBrushFace(graph, FaceSetShader(name));
SceneChangeNotify();
}
-class FaceSetDetailVisitor
+class FaceSetDetail
{
bool m_detail;
public:
- FaceSetDetailVisitor(bool detail) : m_detail(detail)
+ FaceSetDetail(bool detail) : m_detail(detail)
{
}
- void visit(Face& face) const
+ void operator()(Face& face) const
{
face.setDetail(m_detail);
}
void Scene_BrushSetDetail_Selected(scene::Graph& graph, bool detail)
{
- Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetDetailVisitor(detail));
+ Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetDetail(detail));
SceneChangeNotify();
}
return false;
}
-class FaceFindReplaceShaderVisitor
+class FaceFindReplaceShader
{
const char* m_find;
const char* m_replace;
public:
- FaceFindReplaceShaderVisitor(const char* find, const char* replace) : m_find(find), m_replace(replace)
+ FaceFindReplaceShader(const char* find, const char* replace) : m_find(find), m_replace(replace)
{
}
- void visit(Face& face) const
+ void operator()(Face& face) const
{
Face_FindReplaceShader(face, m_find, m_replace);
}
void Scene_BrushFindReplaceShader(scene::Graph& graph, const char* find, const char* replace)
{
- Scene_ForEachBrush_ForEachFace(graph, FaceFindReplaceShaderVisitor(find, replace));
+ Scene_ForEachBrush_ForEachFace(graph, FaceFindReplaceShader(find, replace));
}
void Scene_BrushFindReplaceShader_Selected(scene::Graph& graph, const char* find, const char* replace)
{
- Scene_ForEachSelectedBrush_ForEachFace(graph, FaceFindReplaceShaderVisitor(find, replace));
+ Scene_ForEachSelectedBrush_ForEachFace(graph, FaceFindReplaceShader(find, replace));
}
void Scene_BrushFindReplaceShader_Component_Selected(scene::Graph& graph, const char* find, const char* replace)
{
- FaceFindReplaceShaderVisitor visitor(find, replace);
- Scene_ForEachSelectedBrushFace(graph, visitor);
+ Scene_ForEachSelectedBrushFace(graph, FaceFindReplaceShader(find, replace));
}
-class FaceFitTextureVisitor
+class FaceFitTexture
{
float m_s_repeat, m_t_repeat;
public:
- FaceFitTextureVisitor(float s_repeat, float t_repeat) : m_s_repeat(s_repeat), m_t_repeat(t_repeat)
+ FaceFitTexture(float s_repeat, float t_repeat) : m_s_repeat(s_repeat), m_t_repeat(t_repeat)
{
}
- void visit(Face& face) const
+ 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, FaceFitTextureVisitor(s_repeat, t_repeat));
+ Scene_ForEachSelectedBrush_ForEachFace(graph, FaceFitTexture(s_repeat, t_repeat));
SceneChangeNotify();
}
void Scene_BrushFitTexture_Component_Selected(scene::Graph& graph, float s_repeat, float t_repeat)
{
- FaceFitTextureVisitor visitor(s_repeat, t_repeat);
- Scene_ForEachSelectedBrushFace(graph, visitor);
+ Scene_ForEachSelectedBrushFace(graph, FaceFitTexture(s_repeat, t_repeat));
SceneChangeNotify();
}
+TextureProjection g_defaultTextureProjection;
+const TextureProjection& TextureTransform_getDefault()
+{
+ TexDef_Construct_Default(g_defaultTextureProjection);
+ return g_defaultTextureProjection;
+}
void Scene_BrushConstructPrefab(scene::Graph& graph, EBrushPrefab type, std::size_t sides, const char* shader)
{
Brush* brush = Node_getBrush(path.top());
if(brush != 0)
{
- AABB bounds = brush->localAABB();
- TextureProjection projection;
- TexDef_Construct_Default(projection);
- Brush_ConstructPrefab(*brush, type, bounds, sides, shader, projection);
+ AABB bounds = brush->localAABB(); // copy bounds because the brush will be modified
+ Brush_ConstructPrefab(*brush, type, bounds, sides, shader, TextureTransform_getDefault());
SceneChangeNotify();
}
}
Brush* brush = Node_getBrush(path.top());
if(brush != 0)
{
- TextureProjection projection;
- TexDef_Construct_Default(projection);
- Brush_ConstructCuboid(*brush, bounds, shader, projection);
+ Brush_ConstructCuboid(*brush, bounds, shader, TextureTransform_getDefault());
SceneChangeNotify();
}
}
graph.traverse(BrushSelectByShaderWalker(name));
}
-class FaceSelectByShaderVisitor : public BrushInstanceVisitor
+class FaceSelectByShader
{
const char* m_name;
public:
- FaceSelectByShaderVisitor(const char* name)
+ FaceSelectByShader(const char* name)
: m_name(name)
{
}
- void visit(FaceInstance& face) const
+ void operator()(FaceInstance& face) const
{
if(shader_equal(face.getFace().GetShader(), m_name))
{
void Scene_BrushSelectByShader_Component(scene::Graph& graph, const char* name)
{
- Scene_ForEachSelectedBrush_ForEachFaceInstance(graph, FaceSelectByShaderVisitor(name));
+ Scene_ForEachSelectedBrush_ForEachFaceInstance(graph, FaceSelectByShader(name));
}
-class FaceGetTexdefVisitor
+class FaceGetTexdef
{
TextureProjection& m_projection;
mutable bool m_done;
public:
- FaceGetTexdefVisitor(TextureProjection& projection)
+ FaceGetTexdef(TextureProjection& projection)
: m_projection(projection), m_done(false)
{
}
- void visit(Face& face) const
+ void operator()(Face& face) const
{
if(!m_done)
{
m_done = true;
- FaceTexdef_getTexdef(face.getTexdef(), m_projection);
+ face.GetTexdef(m_projection);
}
}
};
void Scene_BrushGetTexdef_Selected(scene::Graph& graph, TextureProjection& projection)
{
- FaceGetTexdefVisitor visitor(projection);
- Scene_ForEachSelectedBrush_ForEachFace(graph, visitor);
+ Scene_ForEachSelectedBrush_ForEachFace(graph, FaceGetTexdef(projection));
}
void Scene_BrushGetTexdef_Component_Selected(scene::Graph& graph, TextureProjection& projection)
if(!g_SelectedFaceInstances.empty())
{
FaceInstance& faceInstance = g_SelectedFaceInstances.last();
- FaceTexdef_getTexdef(faceInstance.getFace().getTexdef(), projection);
+ faceInstance.getFace().GetTexdef(projection);
}
#else
- FaceGetTexdefVisitor visitor(projection);
+ FaceGetTexdef visitor(projection);
Scene_ForEachSelectedBrushFace(graph, visitor);
#endif
}
-class FaceGetFlagsVisitor
+class FaceGetFlags
{
ContentsFlagsValue& m_flags;
mutable bool m_done;
public:
- FaceGetFlagsVisitor(ContentsFlagsValue& flags)
+ FaceGetFlags(ContentsFlagsValue& flags)
: m_flags(flags), m_done(false)
{
}
- void visit(Face& face) const
+ void operator()(Face& face) const
{
if(!m_done)
{
m_done = true;
- FaceShader_getFlags(face.getShader(), m_flags);
+ face.GetFlags(m_flags);
}
}
};
void Scene_BrushGetFlags_Selected(scene::Graph& graph, ContentsFlagsValue& flags)
{
- FaceGetFlagsVisitor visitor(flags);
- Scene_ForEachSelectedBrush_ForEachFace(graph, visitor);
+#if 1
+ if(GlobalSelectionSystem().countSelected() != 0)
+ {
+ BrushInstance* brush = Instance_getBrush(GlobalSelectionSystem().ultimateSelected());
+ if(brush != 0)
+ {
+ Brush_forEachFace(*brush, FaceGetFlags(flags));
+ }
+ }
+#else
+ Scene_ForEachSelectedBrush_ForEachFace(graph, FaceGetFlags(flags));
+#endif
}
void Scene_BrushGetFlags_Component_Selected(scene::Graph& graph, ContentsFlagsValue& flags)
if(!g_SelectedFaceInstances.empty())
{
FaceInstance& faceInstance = g_SelectedFaceInstances.last();
- FaceShader_getFlags(faceInstance.getFace().getShader(), flags);
+ faceInstance.getFace().GetFlags(flags);
}
#else
- FaceGetFlagsVisitor visitor(flags);
- Scene_ForEachSelectedBrushFace(graph, visitor);
+ Scene_ForEachSelectedBrushFace(graph, FaceGetFlags(flags));
#endif
}
-class FaceGetShaderVisitor
+class FaceGetShader
{
CopiedString& m_shader;
mutable bool m_done;
public:
- FaceGetShaderVisitor(CopiedString& shader)
+ FaceGetShader(CopiedString& shader)
: m_shader(shader), m_done(false)
{
}
- void visit(Face& face) const
+ void operator()(Face& face) const
{
if(!m_done)
{
m_done = true;
- m_shader = face.getShader().getShader();
+ m_shader = face.GetShader();
}
}
};
void Scene_BrushGetShader_Selected(scene::Graph& graph, CopiedString& shader)
{
- FaceGetShaderVisitor visitor(shader);
- Scene_ForEachSelectedBrush_ForEachFace(graph, visitor);
+#if 1
+ if(GlobalSelectionSystem().countSelected() != 0)
+ {
+ BrushInstance* brush = Instance_getBrush(GlobalSelectionSystem().ultimateSelected());
+ if(brush != 0)
+ {
+ Brush_forEachFace(*brush, FaceGetShader(shader));
+ }
+ }
+#else
+ Scene_ForEachSelectedBrush_ForEachFace(graph, FaceGetShader(shader));
+#endif
}
void Scene_BrushGetShader_Component_Selected(scene::Graph& graph, CopiedString& shader)
if(!g_SelectedFaceInstances.empty())
{
FaceInstance& faceInstance = g_SelectedFaceInstances.last();
- shader = faceInstance.getFace().getShader().getShader();
+ shader = faceInstance.getFace().GetShader();
}
#else
- FaceGetShaderVisitor visitor(shader);
+ FaceGetShader visitor(shader);
Scene_ForEachSelectedBrushFace(graph, visitor);
#endif
}
-class FaceFilterAnyVisitor : public BrushVisitor
+class FaceFilterAny
{
FaceFilter* m_filter;
bool& m_filtered;
public:
- FaceFilterAnyVisitor(FaceFilter* filter, bool& filtered) : m_filter(filter), m_filtered(filtered)
+ FaceFilterAny(FaceFilter* filter, bool& filtered) : m_filter(filter), m_filtered(filtered)
{
m_filtered = false;
}
- void visit(Face& face) const
+ void operator()(Face& face) const
{
if(m_filter->filter(face))
{
bool filter(const Brush& brush) const
{
bool filtered;
- brush.forEachFace(FaceFilterAnyVisitor(m_filter, filtered));
+ Brush_forEachFace(brush, FaceFilterAny(m_filter, filtered));
return filtered;
}
};
-class FaceFilterAllVisitor : public BrushVisitor
+class FaceFilterAll
{
FaceFilter* m_filter;
bool& m_filtered;
public:
- FaceFilterAllVisitor(FaceFilter* filter, bool& filtered) : m_filter(filter), m_filtered(filtered)
+ FaceFilterAll(FaceFilter* filter, bool& filtered) : m_filter(filter), m_filtered(filtered)
{
m_filtered = true;
}
- void visit(Face& face) const
+ void operator()(Face& face) const
{
if(!m_filter->filter(face))
{
bool filter(const Brush& brush) const
{
bool filtered;
- brush.forEachFace(FaceFilterAllVisitor(m_filter, filtered));
+ Brush_forEachFace(brush, FaceFilterAll(m_filter, filtered));
return filtered;
}
};
if(face != 0)
{
shader = face->GetShader();
- FaceTexdef_getTexdef(face->getTexdef(), projection);
+ face->GetTexdef(projection);
flags = face->getShader().m_flags;
return true;
}
if(!g_SelectedFaceInstances.empty())
{
Face& face = g_SelectedFaceInstances.last().getFace();
- FaceTexdef_getTexdef(face.getTexdef(), g_faceTextureClipboard.m_projection);
+ face.GetTexdef(g_faceTextureClipboard.m_projection);
g_faceTextureClipboard.m_flags = face.getShader().m_flags;
TextureBrowser_SetSelectedShader(g_TextureBrowser, face.getShader().getShader());
#if !defined (INCLUDED_BRUSHWRAPPER_H)
#define INCLUDED_BRUSHWRAPPER_H
-#include "string/string.h"
+#include <cstddef>
+#include "string/stringfwd.h"
+#include "generic/callbackfwd.h"
enum EBrushPrefab
{
void Scene_BrushFitTexture_Selected(scene::Graph& graph, float s_repeat, float t_repeat);
void Scene_BrushFitTexture_Component_Selected(scene::Graph& graph, float s_repeat, float t_repeat);
-class Callback;
-
typedef struct _GtkMenu GtkMenu;
void Brush_constructMenu(GtkMenu* menu);
BrushClipPlane::constructStatic();
}
+void BrushFaceData_fromFace(const BrushFaceDataCallback& callback, Face& face)
+{
+ _QERFaceData faceData;
+ faceData.m_p0 = face.getPlane().planePoints()[0];
+ faceData.m_p1 = face.getPlane().planePoints()[1];
+ faceData.m_p2 = face.getPlane().planePoints()[2];
+ faceData.m_shader = face.GetShader();
+ faceData.m_texdef = face.getTexdef().m_projection.m_texdef;
+ faceData.contents = face.getShader().m_flags.m_contentFlags;
+ faceData.flags = face.getShader().m_flags.m_surfaceFlags;
+ faceData.value = face.getShader().m_flags.m_value;
+ callback(faceData);
+}
+typedef ConstReferenceCaller1<BrushFaceDataCallback, Face&, BrushFaceData_fromFace> BrushFaceDataFromFaceCaller;
+typedef Callback1<Face&> FaceCallback;
class Quake3BrushCreator : public BrushCreator
{
{
return g_useAlternativeTextureProjection.m_value;
}
+ void forEachBrushFace(scene::Node& brush, const BrushFaceDataCallback& callback)
+ {
+ Brush_forEachFace(*Node_getBrush(brush), FaceCallback(BrushFaceDataFromFaceCaller(callback)));
+ }
+ bool addBrushFace(scene::Node& brush, const _QERFaceData& faceData)
+ {
+ return Node_getBrush(brush)->addPlane(faceData.m_p0, faceData.m_p1, faceData.m_p2, faceData.m_shader, TextureProjection(faceData.m_texdef, brushprimit_texdef_t(), Vector3(0, 0, 0), Vector3(0, 0, 0))) != 0;
+ }
};
Quake3BrushCreator g_Quake3BrushCreator;
#include "renderable.h"
#include "preferencesystem.h"
-#include "generic/callback.h"
+#include "signal/signal.h"
#include "container/array.h"
#include "scenelib.h"
#include "render.h"
#include "timer.h"
-std::vector<Callback> g_cameraMoved_callbacks;
+Signal0 g_cameraMoved_callbacks;
-void AddCameraMovedCallback(const Callback& callback)
+void AddCameraMovedCallback(const SignalHandler& handler)
{
- g_cameraMoved_callbacks.push_back(callback);
+ g_cameraMoved_callbacks.connectLast(handler);
}
void CameraMovedNotify()
{
- std::for_each(g_cameraMoved_callbacks.begin(), g_cameraMoved_callbacks.end(), CallbackInvoke());
+ g_cameraMoved_callbacks();
}
}
+
void CamWnd_Add_Handlers_Move(CamWnd& camwnd)
{
camwnd.m_selection_button_press_handler = g_signal_connect(G_OBJECT(camwnd.m_gl_widget), "button_press_event", G_CALLBACK(selection_button_press), camwnd.m_window_observer);
#define INCLUDED_CAMWINDOW_H
#include "math/vector.h"
+#include "signal/signalfwd.h"
typedef struct _GtkWidget GtkWidget;
typedef struct _GtkWindow GtkWindow;
CamWnd* NewCamWnd();
void DeleteCamWnd(CamWnd* camwnd);
-class Callback;
-void AddCameraMovedCallback(const Callback& callback);
+void AddCameraMovedCallback(const SignalHandler& handler);
void CamWnd_Update(CamWnd& camwnd);
#include "brushnode.h"
#include "grid.h"
-
-
-void Brush_makeHollow(const Brush& brush, brush_vector_t& out, float offset)
+void Face_makeBrush(Face& face, const Brush& brush, brush_vector_t& out, float offset)
{
- for(Brush::const_iterator i(brush.begin()); i != brush.end(); ++i)
+ if(face.contributes())
{
- if((*i)->contributes())
+ out.push_back(new Brush(brush));
+ Face* newFace = out.back()->addFace(face);
+ if(newFace != 0)
{
- out.push_back(new Brush(brush));
- Face* newFace = out.back()->addFace(*(*i));
- if(newFace != 0)
- {
- newFace->flipWinding();
- newFace->getPlane().offset(offset);
- newFace->planeChanged();
- }
+ newFace->flipWinding();
+ newFace->getPlane().offset(offset);
+ newFace->planeChanged();
}
}
}
+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));
+}
+
class BrushHollowSelectedWalker : public scene::Graph::Walker
{
float m_offset;
Brush_makeHollow(*brush, out, m_offset);
for(brush_vector_t::const_iterator i = out.begin(); i != out.end(); ++i)
{
- NodeSmartReference node((new BrushNode())->node());
(*i)->removeEmptyFaces();
+ NodeSmartReference node((new BrushNode())->node());
Node_getBrush(node)->copy(*(*i));
delete (*i);
Node_getTraversable(path.parent())->insert(node);
SceneChangeNotify();
}
+template<typename Functor>
+class Dereference
+{
+ const Functor& functor;
+public:
+ typedef typename Functor::first_argument_type first_argument_type;
+ typedef typename Functor::result_type result_type;
+ Dereference(const Functor& functor) : functor(functor)
+ {
+ }
+ result_type operator()(first_argument_type firstArgument) const
+ {
+ return functor(*firstArgument);
+ }
+};
+
+template<typename Functor>
+inline Dereference<Functor> makeDereference(const Functor& functor)
+{
+ return Dereference<Functor>(functor);
+}
+
+template<typename Predicate>
+Face* Brush_findIf(const Brush& brush, const Predicate& predicate)
+{
+ Brush::const_iterator i = std::find_if(brush.begin(), brush.end(), makeDereference(predicate));
+ return i == brush.end() ? 0 : *i;
+}
+
+template<typename Caller>
+class BindArguments1
+{
+ typedef typename Caller::SecondArgument FirstBound;
+ FirstBound firstBound;
+public:
+ typedef typename Caller::Return Return;
+ typedef typename Caller::FirstArgument FirstArgument;
+ BindArguments1(FirstBound firstBound)
+ : firstBound(firstBound)
+ {
+ }
+ Return operator()(FirstArgument firstArgument) const
+ {
+ return Caller::call(firstArgument, firstBound);
+ }
+};
+
+template<typename Caller>
+class BindArguments2
+{
+ typedef typename Caller::SecondArgument FirstBound;
+ typedef typename Caller::ThirdArgument SecondBound;
+ FirstBound firstBound;
+ SecondBound secondBound;
+public:
+ typedef typename Caller::Return Return;
+ typedef typename Caller::FirstArgument FirstArgument;
+ BindArguments2(FirstBound firstBound, SecondBound secondBound)
+ : firstBound(firstBound), secondBound(secondBound)
+ {
+ }
+ Return operator()(FirstArgument firstArgument) const
+ {
+ return Caller::call(firstArgument, firstBound, secondBound);
+ }
+};
+
+template<typename Caller, typename FirstBound, typename SecondBound>
+BindArguments2<Caller> bindArguments(const Caller& caller, FirstBound firstBound, SecondBound secondBound)
+{
+ return BindArguments2<Caller>(firstBound, secondBound);
+}
+
+inline bool Face_testPlane(const Face& face, const Plane3& plane, bool flipped)
+{
+ return face.contributes() && !Winding_TestPlane(face.getWinding(), plane, flipped);
+}
+typedef Function3<const Face&, const Plane3&, bool, bool, Face_testPlane> FaceTestPlane;
+
+
/// \brief Returns true if
/// \li !flipped && brush is BACK or ON
bool Brush_testPlane(const Brush& brush, const Plane3& plane, bool flipped)
{
brush.evaluateBRep();
+#if 1
for(Brush::const_iterator i(brush.begin()); i != brush.end(); ++i)
{
- if((*i)->contributes() && !Winding_TestPlane((*i)->getWinding(), plane, flipped))
+ if(Face_testPlane(*(*i), plane, flipped))
{
return false;
}
}
return true;
+#else
+ return Brush_findIf(brush, bindArguments(FaceTestPlane(), makeReference(plane), flipped)) == 0;
+#endif
}
brushsplit_t Brush_classifyPlane(const Brush& brush, const Plane3& plane)
addRadioIcons(vbox, name, icons, IntImportCaller(data), IntExportCaller(data));
}
-GtkWidget* Dialog::addEntry(GtkWidget* vbox, const char* name, const IntImportCallback& importViewer, const IntExportCallback& exportViewer)
+GtkWidget* Dialog::addIntEntry(GtkWidget* vbox, const char* name, const IntImportCallback& importViewer, const IntExportCallback& exportViewer)
{
DialogEntryRow row(DialogEntryRow_new(name));
AddIntEntryData(*row.m_entry, importViewer, exportViewer);
return row.m_row;
}
-GtkWidget* Dialog::addEntry(GtkWidget* vbox, const char* name, const SizeImportCallback& importViewer, const SizeExportCallback& exportViewer)
+GtkWidget* Dialog::addSizeEntry(GtkWidget* vbox, const char* name, const SizeImportCallback& importViewer, const SizeExportCallback& exportViewer)
{
DialogEntryRow row(DialogEntryRow_new(name));
AddSizeEntryData(*row.m_entry, importViewer, exportViewer);
return row.m_row;
}
-GtkWidget* Dialog::addEntry(GtkWidget* vbox, const char* name, const FloatImportCallback& importViewer, const FloatExportCallback& exportViewer)
+GtkWidget* Dialog::addFloatEntry(GtkWidget* vbox, const char* name, const FloatImportCallback& importViewer, const FloatExportCallback& exportViewer)
{
DialogEntryRow row(DialogEntryRow_new(name));
AddFloatEntryData(*row.m_entry, importViewer, exportViewer);
void addRadio(GtkWidget* vbox, const char* name, int& data, StringArrayRange names);
void addRadioIcons(GtkWidget* vbox, const char* name, StringArrayRange icons, const IntImportCallback& importCallback, const IntExportCallback& exportCallback);
void addRadioIcons(GtkWidget* vbox, const char* name, int& data, StringArrayRange icons);
- GtkWidget* addEntry(GtkWidget* vbox, const char* name, const IntImportCallback& importCallback, const IntExportCallback& exportCallback);
+ GtkWidget* addIntEntry(GtkWidget* vbox, const char* name, const IntImportCallback& importCallback, const IntExportCallback& exportCallback);
GtkWidget* addEntry(GtkWidget* vbox, const char* name, int& data)
{
- return addEntry(vbox, name, IntImportCaller(data), IntExportCaller(data));
+ return addIntEntry(vbox, name, IntImportCaller(data), IntExportCaller(data));
}
- GtkWidget* addEntry(GtkWidget* vbox, const char* name, const SizeImportCallback& importCallback, const SizeExportCallback& exportCallback);
+ GtkWidget* addSizeEntry(GtkWidget* vbox, const char* name, const SizeImportCallback& importCallback, const SizeExportCallback& exportCallback);
GtkWidget* addEntry(GtkWidget* vbox, const char* name, std::size_t& data)
{
- return addEntry(vbox, name, SizeImportCaller(data), SizeExportCaller(data));
+ return addSizeEntry(vbox, name, SizeImportCaller(data), SizeExportCaller(data));
}
- GtkWidget* addEntry(GtkWidget* vbox, const char* name, const FloatImportCallback& importCallback, const FloatExportCallback& exportCallback);
+ GtkWidget* addFloatEntry(GtkWidget* vbox, const char* name, const FloatImportCallback& importCallback, const FloatExportCallback& exportCallback);
GtkWidget* addEntry(GtkWidget* vbox, const char* name, float& data)
{
- return addEntry(vbox, name, FloatImportCaller(data), FloatExportCaller(data));
+ return addFloatEntry(vbox, name, FloatImportCaller(data), FloatExportCaller(data));
}
GtkWidget* addPathEntry(GtkWidget* vbox, const char* name, bool browse_directory, const StringImportCallback& importCallback, const StringExportCallback& exportCallback);
GtkWidget* addPathEntry(GtkWidget* vbox, const char* name, CopiedString& data, bool directory);
/// skin the VFS path to a skin file
///
///
-/// flag attributes define a flag in the spawnflags key:
+/// flag attributes define a flag in the "spawnflags" key:
///
/// <flag
/// key="[flag name]"
#include "preferencesystem.h"
#include "gtkutil/widget.h"
+#include "signal/signal.h"
#include "stringio.h"
#include "gtkmisc.h"
-std::vector<Callback> g_gridChange_callbacks;
+Signal0 g_gridChange_callbacks;
-void AddGridChangeCallback(const Callback& callback)
+void AddGridChangeCallback(const SignalHandler& handler)
{
- g_gridChange_callbacks.push_back(callback);
- callback();
+ g_gridChange_callbacks.connectLast(handler);
+ handler();
}
void GridChangeNotify()
{
- std::for_each(g_gridChange_callbacks.begin(), g_gridChange_callbacks.end(), CallbackInvoke());
+ g_gridChange_callbacks();
}
enum GridPower
#if !defined(INCLUDED_GRID_H)
#define INCLUDED_GRID_H
+#include "signal/signalfwd.h"
+
float GetGridSize();
int Grid_getPower();
-class Callback;
-void AddGridChangeCallback(const Callback& callback);
+void AddGridChangeCallback(const SignalHandler& handler);
void Grid_registerCommands();
typedef struct _GtkMenu GtkMenu;
#include "cmdlib.h"
#include "scenelib.h"
#include "stream/stringstream.h"
+#include "signal/isignal.h"
#include "os/path.h"
#include "os/file.h"
#include "eclasslib.h"
Radiant_detachHomePathsObserver(g_VFSModuleObserver);
}
-
// Home Paths
void HomePaths_Realise()
MainWindowActive g_MainWindowActive;
+MouseEventHandlerId XYWindowMouseDown_connect(const MouseEventHandler& handler)
+{
+ return g_pParentWnd->GetXYWnd()->onMouseDown.connectFirst(handler);
+}
+
+void XYWindowMouseDown_disconnect(MouseEventHandlerId id)
+{
+ g_pParentWnd->GetXYWnd()->onMouseDown.disconnect(id);
+}
+
// =============================================================================
// MainFrame class
#include "gtkutil/widget.h"
#include "string/string.h"
+#include "qerplugin.h"
+
class IPlugIn;
class IToolbarButton;
extern bool (*GridStatus_getTextureLockEnabled)();
void GridStatus_onTextureLockEnabledChanged();
-
+MouseEventHandlerId XYWindowMouseDown_connect(const MouseEventHandler& handler);
+void XYWindowMouseDown_disconnect(MouseEventHandlerId id);
#endif
#include "modulesystem/singletonmodule.h"
#include "modulesystem/moduleregistry.h"
#include "stream/stringstream.h"
+#include "signal/signal.h"
#include "gtkutil/filechooser.h"
#include "timer.h"
bool m_modified;
void (*m_modified_changed)(const Map&);
- typedef std::vector<Callback> MapValidCallbacks;
- MapValidCallbacks m_mapValidCallbacks;
+ Signal0 m_mapValidCallbacks;
WorldNode m_world_node; // "classname" "worldspawn" !
Map g_map;
Map* g_currentMap = 0;
-void Map_addValidCallback(Map& map, const Callback& callback)
+void Map_addValidCallback(Map& map, const SignalHandler& handler)
{
- map.m_mapValidCallbacks.push_back(callback);
+ map.m_mapValidCallbacks.connectLast(handler);
}
bool Map_Valid(const Map& map)
void Map_SetValid(Map& map, bool valid)
{
map.m_valid = valid;
- std::for_each(map.m_mapValidCallbacks.begin(), map.m_mapValidCallbacks.end(), CallbackInvoke());
+ map.m_mapValidCallbacks();
}
}
}
-void maps_directory(StringOutputStream& buffer)
+CopiedString g_mapsPath;
+
+const char* getMapsPath()
{
- ASSERT_MESSAGE(!string_empty(g_qeglobals.m_userGamePath.c_str()), "maps_directory: user-game-path is empty");
- buffer << g_qeglobals.m_userGamePath.c_str() << "maps/";
- Q_mkdir(buffer.c_str());
+ return g_mapsPath.c_str();
}
const char* map_open(const char* title)
{
- StringOutputStream buf(256);
- maps_directory(buf);
- return file_dialog(GTK_WIDGET(MainFrame_getWindow()), TRUE, title, buf.c_str(), MapFormat::Name());
+ return file_dialog(GTK_WIDGET(MainFrame_getWindow()), TRUE, title, getMapsPath(), MapFormat::Name());
}
const char* map_save(const char* title)
{
- StringOutputStream buf(256);
- maps_directory(buf);
- return file_dialog(GTK_WIDGET(MainFrame_getWindow()), FALSE, title, buf.c_str(), MapFormat::Name());
+ return file_dialog(GTK_WIDGET(MainFrame_getWindow()), FALSE, title, getMapsPath(), MapFormat::Name());
}
void OpenMap()
gtk_widget_destroy(GTK_WIDGET(window));
}
+void Map_constructPreferences(PreferencesPage& page)
+{
+ page.appendCheckBox("", "Load last map on open", g_bLoadLastMap);
+}
+
class MapEntityClasses : public ModuleObserver
{
MapEntityClasses g_MapEntityClasses;
-void Map_constructPreferences(PreferencesPage& page)
+class MapModuleObserver : public ModuleObserver
{
- page.appendCheckBox("", "Load last map on open", g_bLoadLastMap);
-}
+ std::size_t m_unrealised;
+public:
+ MapModuleObserver() : m_unrealised(1)
+ {
+ }
+ void realise()
+ {
+ if(--m_unrealised == 0)
+ {
+ ASSERT_MESSAGE(!string_empty(g_qeglobals.m_userGamePath.c_str()), "maps_directory: user-game-path is empty");
+ StringOutputStream buffer(256);
+ buffer << g_qeglobals.m_userGamePath.c_str() << "maps/";
+ Q_mkdir(buffer.c_str());
+ g_mapsPath = buffer.c_str();
+ }
+ }
+ void unrealise()
+ {
+ if(++m_unrealised == 1)
+ {
+ g_mapsPath = "";
+ }
+ }
+};
+
+MapModuleObserver g_MapModuleObserver;
#include "preferencesystem.h"
PreferencesDialog_addSettingsPreferences(FreeCaller1<PreferencesPage&, Map_constructPreferences>());
GlobalEntityClassManager().attach(g_MapEntityClasses);
+ Radiant_attachHomePathsObserver(g_MapModuleObserver);
}
void Map_Destroy()
{
+ Radiant_detachHomePathsObserver(g_MapModuleObserver);
GlobalEntityClassManager().detach(g_MapEntityClasses);
}
#include "iscenegraph.h"
#include "generic/callback.h"
+#include "signal/signalfwd.h"
#include "string/stringfwd.h"
class Map;
class MapFormat;
-void Map_addValidCallback(Map& map, const Callback& callback);
+void Map_addValidCallback(Map& map, const SignalHandler& handler);
bool Map_Valid(const Map& map);
class DeferredDraw
#include <glib/gslist.h>
#include "preferences.h"
#include "brush_primit.h"
+#include "signal/signal.h"
-std::set<Callback> g_patchTextureChangedCallbacks;
+Signal0 g_patchTextureChangedCallbacks;
-void Patch_addTextureChangedCallback(const Callback& callback)
+void Patch_addTextureChangedCallback(const SignalHandler& handler)
{
- g_patchTextureChangedCallbacks.insert(callback);
+ g_patchTextureChangedCallbacks.connectLast(handler);
}
void Patch_textureChanged()
{
- std::for_each(g_patchTextureChangedCallbacks.begin(), g_patchTextureChangedCallbacks.end(), CallbackInvoke());
+ g_patchTextureChangedCallbacks();
}
#include "stringio.h"
#include "shaderlib.h"
#include "generic/callback.h"
+#include "signal/signalfwd.h"
#include "texturelib.h"
#include "xml/ixml.h"
#include "dragplanes.h"
bool patch_filtered(Patch& patch);
void add_patch_filter(PatchFilter& filter, int mask, bool invert = false);
-void Patch_addTextureChangedCallback(const Callback& callback);
+void Patch_addTextureChangedCallback(const SignalHandler& handler);
void Patch_textureChanged();
inline void BezierCurveTreeArray_deleteAll(Array<BezierCurveTree*>& curveTrees)
#include "patch.h"
#include "commands.h"
#include "preferences.h"
+#include "signal/isignal.h"
#include <gdk/gdkkeysyms.h>
return g_pGameDescription->getRequiredKeyValue(key);
}
-const char* mapname_get()
+const char* getMapName()
{
return Map_Name(g_map);
}
+scene::Node& getMapWorldEntity()
+{
+ return Map_FindOrInsertWorldspawn(g_map);
+}
+
+VIEWTYPE XYWindow_getViewType()
+{
+ return g_pParentWnd->GetXYWnd()->GetViewType();
+}
+
+Vector3 XYWindow_windowToWorld(const WindowVector& position)
+{
+ Vector3 result(0, 0, 0);
+ g_pParentWnd->GetXYWnd()->XY_ToPoint(static_cast<int>(position.x()), static_cast<int>(position.y()), result);
+ return result;
+}
+
+const char* TextureBrowser_getSelectedShader()
+{
+ return TextureBrowser_GetSelectedShader(GlobalTextureBrowser());
+}
+
class RadiantCoreAPI
{
_QERFuncTable_1 m_radiantcore;
m_radiantcore.getGameName = &gamename_get;
m_radiantcore.getGameMode = &gamemode_get;
- m_radiantcore.getMapName = &mapname_get;
+ m_radiantcore.getMapName = &getMapName;
+ m_radiantcore.getMapWorldEntity = getMapWorldEntity;
+ m_radiantcore.getGridSize = GetGridSize;
m_radiantcore.getGameDescriptionKeyValue = &GameDescription_getKeyValue;
m_radiantcore.getRequiredGameDescriptionKeyValue = &GameDescription_getRequiredKeyValue;
m_radiantcore.attachGameModeObserver = Radiant_attachGameModeObserver;
m_radiantcore.detachGameModeObserver = Radiant_detachGameModeObserver;
+ m_radiantcore.XYWindowMouseDown_connect = XYWindowMouseDown_connect;
+ m_radiantcore.XYWindowMouseDown_disconnect = XYWindowMouseDown_disconnect;
+ m_radiantcore.XYWindow_getViewType = XYWindow_getViewType;
+ m_radiantcore.XYWindow_windowToWorld = XYWindow_windowToWorld;
+ m_radiantcore.TextureBrowser_getSelectedShader = TextureBrowser_getSelectedShader;
+
m_radiantcore.m_pfnMessageBox = >k_MessageBox;
m_radiantcore.m_pfnFileDialog = &file_dialog;
m_radiantcore.m_pfnColorDialog = &color_dialog;
}
GtkWidget* appendEntry(const char* name, const IntImportCallback& importCallback, const IntExportCallback& exportCallback)
{
- return m_dialog.addEntry(m_vbox, name, importCallback, exportCallback);
+ return m_dialog.addIntEntry(m_vbox, name, importCallback, exportCallback);
}
GtkWidget* appendEntry(const char* name, int& data)
{
}
GtkWidget* appendEntry(const char* name, const SizeImportCallback& importCallback, const SizeExportCallback& exportCallback)
{
- return m_dialog.addEntry(m_vbox, name, importCallback, exportCallback);
+ return m_dialog.addSizeEntry(m_vbox, name, importCallback, exportCallback);
}
GtkWidget* appendEntry(const char* name, std::size_t& data)
{
}
GtkWidget* appendEntry(const char* name, const FloatImportCallback& importCallback, const FloatExportCallback& exportCallback)
{
- return m_dialog.addEntry(m_vbox, name, importCallback, exportCallback);
+ return m_dialog.addFloatEntry(m_vbox, name, importCallback, exportCallback);
}
GtkWidget* appendEntry(const char* name, float& data)
{
#include <vector>
#include "string/string.h"
-#include "generic/callback.h"
+#include "signal/signal.h"
#include "scenelib.h"
#include "instancelib.h"
#include "treemodel.h"
InstanceMap m_instances;
scene::Instantiable::Observer* m_observer;
- typedef std::set<Callback> BoundsChangedCallbacks;
- BoundsChangedCallbacks m_boundsChanged;
+ Signal0 m_boundsChanged;
scene::Path m_rootpath;
- std::vector<Callback> m_sceneChangedCallbacks;
+ Signal0 m_sceneChangedCallbacks;
TypeIdMap<NODETYPEID_MAX> m_nodeTypeIds;
TypeIdMap<INSTANCETYPEID_MAX> m_instanceTypeIds;
{
}
- void addSceneChangedCallback(const Callback& callback)
+ void addSceneChangedCallback(const SignalHandler& handler)
{
- m_sceneChangedCallbacks.push_back(callback);
+ m_sceneChangedCallbacks.connectLast(handler);
}
void sceneChanged()
{
- std::for_each(m_sceneChangedCallbacks.begin(), m_sceneChangedCallbacks.end(), CallbackInvoke());
+ m_sceneChangedCallbacks();
}
scene::Node& root()
}
void boundsChanged()
{
- std::for_each(m_boundsChanged.begin(), m_boundsChanged.end(), CallbackInvoke());
+ m_boundsChanged();
}
void traverse(const Walker& walker)
m_instances.erase(PathConstReference(instance->path()));
}
- void addBoundsChangedCallback(const Callback& boundsChanged)
+ SignalHandlerId addBoundsChangedCallback(const SignalHandler& boundsChanged)
{
- ASSERT_MESSAGE(m_boundsChanged.find(boundsChanged) == m_boundsChanged.end(), "bounds-changed callback already registered");
- m_boundsChanged.insert(boundsChanged);
+ return m_boundsChanged.connectLast(boundsChanged);
}
- void removeBoundsChangedCallback(const Callback& boundsChanged)
+ void removeBoundsChangedCallback(SignalHandlerId id)
{
- ASSERT_MESSAGE(m_boundsChanged.find(boundsChanged) != m_boundsChanged.end(), "bounds-changed callback not registered");
- m_boundsChanged.erase(boundsChanged);
+ m_boundsChanged.disconnect(id);
}
TypeId getNodeTypeId(const char* name)
#include <vector>
#include "stream/stringstream.h"
+#include "signal/isignal.h"
#include "shaderlib.h"
#include "scenelib.h"
SceneChangeNotify();
}
+SignalHandlerId Selection_boundsChanged;
+
void Selection_construct()
{
GlobalSelectionSystem().addSelectionChangeCallback(FreeCaller1<const Selectable&, SceneSelectionChange>());
GlobalSelectionSystem().addSelectionChangeCallback(FreeCaller1<const Selectable&, UpdateWorkzone_ForSelection>());
- GlobalSceneGraph().addBoundsChangedCallback(FreeCaller<UpdateWorkzone_ForSelection>());
+ Selection_boundsChanged = GlobalSceneGraph().addBoundsChangedCallback(FreeCaller<UpdateWorkzone_ForSelection>());
}
void Selection_destroy()
{
- GlobalSceneGraph().removeBoundsChangedCallback(FreeCaller<UpdateWorkzone_ForSelection>());
+ GlobalSceneGraph().removeBoundsChangedCallback(Selection_boundsChanged);
}
#include "editable.h"
#include "math/frustum.h"
-#include "generic/callback.h"
+#include "signal/signal.h"
#include "generic/object.h"
#include "selectionlib.h"
#include "render.h"
selection_t m_selection;
selection_t m_component_selection;
- std::vector<SelectionChangeCallback> m_selectionChanged_callbacks;
+ Signal1<const Selectable&> m_selectionChanged_callbacks;
void ConstructPivot() const;
mutable bool m_pivotChanged;
}
}
- void addSelectionChangeCallback(const SelectionChangeCallback& callback)
+ void addSelectionChangeCallback(const SelectionChangeHandler& handler)
{
- m_selectionChanged_callbacks.push_back(callback);
+ m_selectionChanged_callbacks.connectLast(handler);
}
void selectionChanged(const Selectable& selectable)
{
- typedef Functor1Invoke<SelectionChangeCallback, const Selectable&> SelectionChangeCallbackInvoke;
- std::for_each(m_selectionChanged_callbacks.begin(), m_selectionChanged_callbacks.end(), SelectionChangeCallbackInvoke(selectable));
+ m_selectionChanged_callbacks(selectable);
}
typedef MemberCaller1<RadiantSelectionSystem, const Selectable&, &RadiantSelectionSystem::selectionChanged> SelectionChangedCaller;
inline RadiantSelectionSystem& getSelectionSystem()
{
- ASSERT_NOTNULL(g_RadiantSelectionSystem);
return *g_RadiantSelectionSystem;
}
}
}
+SignalHandlerId SelectionSystem_boundsChanged;
+
void SelectionSystem_Construct()
{
RadiantSelectionSystem::constructStatic();
g_RadiantSelectionSystem = new RadiantSelectionSystem;
- GlobalSceneGraph().addBoundsChangedCallback(FreeCaller<SelectionSystem_OnBoundsChanged>());
+ SelectionSystem_boundsChanged = GlobalSceneGraph().addBoundsChangedCallback(FreeCaller<SelectionSystem_OnBoundsChanged>());
GlobalShaderCache().attachRenderable(getSelectionSystem());
}
{
GlobalShaderCache().detachRenderable(getSelectionSystem());
- GlobalSceneGraph().removeBoundsChangedCallback(FreeCaller<SelectionSystem_OnBoundsChanged>());
+ GlobalSceneGraph().removeBoundsChangedCallback(SelectionSystem_boundsChanged);
delete g_RadiantSelectionSystem;
#define INCLUDED_SELECTION_H
#include "windowobserver.h"
+#include "generic/callbackfwd.h"
struct rect_t
{
float max[2];
};
-template<typename FirstArgument>
-class Callback1;
typedef Callback1<rect_t> RectangleCallback;
class View;
-class Callback;
class SelectionSystemWindowObserver : public WindowObserver
{
#include <gdk/gdkkeysyms.h>
#include <gtk/gtkcheckbutton.h> //Shamus: For Textool
-#include "generic/callback.h"
+#include "signal/isignal.h"
#include "generic/object.h"
#include "math/vector.h"
#include "texturelib.h"
#include "gtkutil/idledraw.h"
#include "generic/static.h"
+#include "signal/isignal.h"
#include "shaderlib.h"
#include "texwindow.h"
}
}
}
- void connect(const Callback& update) const
+ void connect(const SignalHandler& update) const
{
TextureBrowser_addActiveShadersChangedCallback(update);
}
{
GlobalShaderSystem().foreachShaderName(callback);
}
- void connect(const Callback& update) const
+ void connect(const SignalHandler& update) const
{
TextureBrowser_addShadersRealiseCallback(update);
}
#if !defined (INCLUDED_TEXTURES_H)
#define INCLUDED_TEXTURES_H
+#include "generic/callbackfwd.h"
+
void Textures_Realise();
void Textures_Unrealise();
void Textures_sharedContextDestroyed();
-class Callback;
void Textures_setModeChangedNotify(const Callback& notify);
#endif
#include <gtk/gtkvscrollbar.h>
#include <gtk/gtkmenu.h>
-#include "generic/callback.h"
+#include "signal/signal.h"
#include "math/vector.h"
#include "texturelib.h"
#include "string/string.h"
}
-std::set<Callback> g_activeShadersChangedCallbacks;
+Signal0 g_activeShadersChangedCallbacks;
-void TextureBrowser_addActiveShadersChangedCallback(const Callback& callback)
+void TextureBrowser_addActiveShadersChangedCallback(const SignalHandler& handler)
{
- g_activeShadersChangedCallbacks.insert(callback);
+ g_activeShadersChangedCallbacks.connectLast(handler);
}
class ShadersObserver : public ModuleObserver
{
- std::set<Callback> m_realiseCallbacks;
+ Signal0 m_realiseCallbacks;
public:
void realise()
{
- std::for_each(m_realiseCallbacks.begin(), m_realiseCallbacks.end(), CallbackInvoke());
+ m_realiseCallbacks();
}
void unrealise()
{
}
- void insert(const Callback& callback)
+ void insert(const SignalHandler& handler)
{
- m_realiseCallbacks.insert(callback);
+ m_realiseCallbacks.connectLast(handler);
}
};
ShadersObserver g_ShadersObserver;
}
-void TextureBrowser_addShadersRealiseCallback(const Callback& callback)
+void TextureBrowser_addShadersRealiseCallback(const SignalHandler& handler)
{
- g_ShadersObserver.insert(callback);
+ g_ShadersObserver.insert(handler);
}
void TextureBrowser_activeShadersChanged(TextureBrowser& textureBrowser)
TextureBrowser_heightChanged(textureBrowser);
textureBrowser.m_originInvalid = true;
- std::for_each(g_activeShadersChangedCallbacks.begin(), g_activeShadersChangedCallbacks.end(), CallbackInvoke());
+ g_activeShadersChangedCallbacks();
}
void TextureBrowser_importShowScrollbar(TextureBrowser& textureBrowser, bool value)
#define INCLUDED_TEXWINDOW_H
#include "math/vector.h"
+#include "generic/callbackfwd.h"
+#include "signal/signalfwd.h"
// textures menu
void TextureBrowser_Construct();
void TextureBrowser_Destroy();
-template<typename FirstArgument>
-class Callback1;
typedef Callback1<const char*> StringImportCallback;
template<typename FirstArgument, void (*func)(FirstArgument)>
class FreeCaller1;
const Vector3& TextureBrowser_getBackgroundColour(TextureBrowser& textureBrowser);
void TextureBrowser_setBackgroundColour(TextureBrowser& textureBrowser, const Vector3& colour);
-class Callback;
-void TextureBrowser_addActiveShadersChangedCallback(const Callback& callback);
-void TextureBrowser_addShadersRealiseCallback(const Callback& callback);
+void TextureBrowser_addActiveShadersChangedCallback(const SignalHandler& handler);
+void TextureBrowser_addShadersRealiseCallback(const SignalHandler& handler);
#endif
void Undo_constructPreferences(RadiantUndoSystem& undo, PreferencesPage& page)
{
- page.appendSpinner("Undo Queue Size", 64, 0, 1024, UndoLevelsImportCaller(undo), UndoLevelsExportCaller(undo));
+ page.appendSpinner("Undo Queue Size", 64, 0, 1024, IntImportCallback(UndoLevelsImportCaller(undo)), IntExportCallback(UndoLevelsExportCaller(undo)));
}
void Undo_constructPage(RadiantUndoSystem& undo, PreferenceGroup& group)
{
#include "generic/callback.h"
#include "string/string.h"
#include "stream/stringstream.h"
+
#include "scenelib.h"
#include "eclasslib.h"
#include "renderer.h"
return modifiers;
}
+inline unsigned int buttons_for_button_and_modifiers(ButtonIdentifier button, ModifierFlags flags)
+{
+ unsigned int buttons = 0;
+
+ switch (button.get())
+ {
+ case ButtonEnumeration::LEFT: buttons |= RAD_LBUTTON; break;
+ case ButtonEnumeration::MIDDLE: buttons |= RAD_MBUTTON; break;
+ case ButtonEnumeration::RIGHT: buttons |= RAD_RBUTTON; break;
+ }
+
+ if(bitfield_enabled(flags, c_modifierControl))
+ buttons |= RAD_CONTROL;
+
+ if(bitfield_enabled(flags, c_modifierShift))
+ buttons |= RAD_SHIFT;
+
+ if(bitfield_enabled(flags, c_modifierAlt))
+ buttons |= RAD_ALT;
+
+ return buttons;
+}
+
inline unsigned int buttons_for_event_button(GdkEventButton* event)
{
unsigned int flags = 0;
{
if(event->type == GDK_BUTTON_PRESS)
{
- xywnd->XY_MouseDown(static_cast<int>(event->x), static_cast<int>(event->y), buttons_for_event_button(event));
+ g_pParentWnd->SetActiveXY(xywnd);
+
+ xywnd->ButtonState_onMouseDown(buttons_for_event_button(event));
+
+ xywnd->onMouseDown(WindowVector(event->x, event->y), button_for_button(event->button), modifiers_for_state(event->state));
}
return FALSE;
}
if(event->type == GDK_BUTTON_RELEASE)
{
xywnd->XY_MouseUp(static_cast<int>(event->x), static_cast<int>(event->y), buttons_for_event_button(event));
+
+ xywnd->ButtonState_onMouseUp(buttons_for_event_button(event));
}
return FALSE;
}
AddCameraMovedCallback(ReferenceCaller<XYWnd, &XYWnd_CameraMoved>(*this));
PressedButtons_connect(g_pressedButtons, m_gl_widget);
+
+ onMouseDown.connectLast(makeSignalHandler3(MouseDownCaller(), *this));
}
XYWnd::~XYWnd()
return WindowVector(static_cast<float>(x), static_cast<float>(y));
}
+void XYWnd::mouseDown(const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers)
+{
+ XY_MouseDown(static_cast<int>(position.x()), static_cast<int>(position.y()), buttons_for_button_and_modifiers(button, modifiers));
+}
void XYWnd::XY_MouseDown (int x, int y, unsigned int buttons)
{
- g_pParentWnd->SetActiveXY(this);
-
- ButtonState_onMouseDown(buttons);
-
if(buttons == Move_buttons())
{
Move_Begin();
{
m_window_observer->onMouseUp(WindowVector_forInteger(x, y), button_for_flags(buttons), modifiers_for_flags(buttons));
}
-
- ButtonState_onMouseUp(buttons);
}
void XYWnd::XY_MouseMoved (int x, int y, unsigned int buttons)
#define INCLUDED_XYWINDOW_H
#include "math/matrix.h"
+#include "signal/signal.h"
#include "gtkutil/cursor.h"
#include "gtkutil/window.h"
#include "view.h"
#include "map.h"
+#include "qerplugin.h"
+
class Shader;
class SelectionSystemWindowObserver;
namespace scene
void OnClipMode(bool enabled);
bool ClipMode();
-enum VIEWTYPE
-{
- YZ = 0,
- XZ = 1,
- XY = 2
-};
-
inline const char* ViewType_getTitle(VIEWTYPE viewtype)
{
if(viewtype == XY)
int m_ptCursorX, m_ptCursorY;
unsigned int m_buttonstate;
- void ButtonState_onMouseDown(unsigned int buttons)
- {
- m_buttonstate |= buttons;
- }
- void ButtonState_onMouseUp(unsigned int buttons)
- {
- m_buttonstate &= ~buttons;
- }
- unsigned int getButtonState() const
- {
- return m_buttonstate;
- }
int m_nNewBrushPressx;
int m_nNewBrushPressy;
bool m_entityCreate;
public:
+ void ButtonState_onMouseDown(unsigned int buttons)
+ {
+ m_buttonstate |= buttons;
+ }
+ void ButtonState_onMouseUp(unsigned int buttons)
+ {
+ m_buttonstate &= ~buttons;
+ }
+ unsigned int getButtonState() const
+ {
+ return m_buttonstate;
+ }
void EntityCreate_MouseDown(int x, int y);
void EntityCreate_MouseMove(int x, int y);
void EntityCreate_MouseUp(int x, int y);
{
return m_nHeight;
}
+
+ Signal3<const WindowVector&, ButtonIdentifier, ModifierFlags> onMouseDown;
+ void mouseDown(const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers);
+ typedef Member3<XYWnd, const WindowVector&, ButtonIdentifier, ModifierFlags, void, &XYWnd::mouseDown> MouseDownCaller;
};
inline void XYWnd_Update(XYWnd& xywnd)