refactored plugin api; refactored callback library; added signals library

git-svn-id: svn://svn.icculus.org/gtkradiant/GtkRadiant/trunk@44 8a3a26a2-13c4-0310-b231-cf6edde360e5
This commit is contained in:
spog 2006-04-09 17:15:13 +00:00
parent ba55f1bbf6
commit 6ee91d153e
127 changed files with 3723 additions and 2092 deletions

View file

@ -1,6 +1,14 @@
This is the changelog for developers, != changelog for the end user This is the changelog for developers, != changelog for the end user
that we distribute with the binaries. (see changelog) 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 31/03/2006
SPoG SPoG
- Changed doom3 light creation to use size of selected brushes. - Changed doom3 light creation to use size of selected brushes.

View file

@ -146,6 +146,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PrtView", "contrib\prtview\
{853632F4-6420-40C5-B80B-38B678E472B8} = {853632F4-6420-40C5-B80B-38B678E472B8} {853632F4-6420-40C5-B80B-38B678E472B8} = {853632F4-6420-40C5-B80B-38B678E472B8}
EndProjectSection EndProjectSection
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bobtoolz", "contrib\bobtoolz\bobtoolz.vcproj", "{B20364D1-4329-4D4E-B9CE-C9767618FDD6}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global Global
GlobalSection(SolutionConfiguration) = preSolution GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug Debug = Debug
@ -272,6 +276,10 @@ Global
{B20364D1-4329-4D4E-B9CE-C9767618FDD6}.Debug.Build.0 = Debug|Win32 {B20364D1-4329-4D4E-B9CE-C9767618FDD6}.Debug.Build.0 = Debug|Win32
{B20364D1-4329-4D4E-B9CE-C9767618FDD6}.Release.ActiveCfg = Release|Win32 {B20364D1-4329-4D4E-B9CE-C9767618FDD6}.Release.ActiveCfg = Release|Win32
{B20364D1-4329-4D4E-B9CE-C9767618FDD6}.Release.Build.0 = Release|Win32 {B20364D1-4329-4D4E-B9CE-C9767618FDD6}.Release.Build.0 = Release|Win32
{B20364D1-4329-4D4E-B9CE-C9767618FDD6}.Debug.ActiveCfg = Debug|Win32
{B20364D1-4329-4D4E-B9CE-C9767618FDD6}.Debug.Build.0 = Debug|Win32
{B20364D1-4329-4D4E-B9CE-C9767618FDD6}.Release.ActiveCfg = Release|Win32
{B20364D1-4329-4D4E-B9CE-C9767618FDD6}.Release.Build.0 = Release|Win32
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection EndGlobalSection

View file

@ -17,8 +17,6 @@ License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "StdAfx.h" // Added by ClassView
class CBspPoint { class CBspPoint {
public: public:
float p[3]; float p[3];
@ -47,6 +45,8 @@ public:
}; };
#define NAME_MAX 255
class CPortals { class CPortals {
public: public:

View file

@ -21,16 +21,21 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// //
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
#include "StdAfx.h"
#include "DBobView.h" #include "DBobView.h"
#include "DListener.h"
//#include "misc.h" //#include "misc.h"
#include "funchandlers.h" #include "funchandlers.h"
#include "gtkr_list.h" #include <list>
#include "str.h"
#include "iglrender.h"
#include "qerplugin.h"
#include "str.h"
#include "math/matrix.h"
#include "DEntity.h"
#include "DEPair.h"
#include "misc.h" #include "misc.h"
#include "dialogs/dialogs-gtk.h"
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Construction/Destruction // Construction/Destruction
@ -39,29 +44,23 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
DBobView::DBobView() DBobView::DBobView()
{ {
nPathCount = 0; nPathCount = 0;
refCount = 1;
m_bHooked = FALSE;
path = NULL; path = NULL;
eyes = NULL;
boundingShow = BOUNDS_APEX; boundingShow = BOUNDS_APEX;
constructShaders();
GlobalShaderCache().attachRenderable(*this);
} }
DBobView::~DBobView() DBobView::~DBobView()
{ {
if(path) GlobalShaderCache().detachRenderable(*this);
destroyShaders();
if(path)
delete[] 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;
if(m_bHooked)
UnRegister();
g_PathView = NULL; g_PathView = NULL;
} }
@ -69,201 +68,77 @@ DBobView::~DBobView()
// Implementation // Implementation
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
void DBobView::Draw2D(VIEWTYPE vt) void DBobView::render(RenderStateFlags state) const
{ {
if(!path) glBegin(GL_LINE_STRIP);
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);
__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
__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] );
}
__QGLTABLENAME.m_pfn_qglEnd();*/ // djbob: er, um doesn't really seem to do anyhting
}
// -mars
__QGLTABLENAME.m_pfn_qglPopMatrix();
__QGLTABLENAME.m_pfn_qglPopAttrib();
}
void DBobView::Draw3D()
{
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++) for(int i = 0; i < nPathCount; i++)
__QGLTABLENAME.m_pfn_qglVertex3fv(path[i]); glVertex3fv(path[i]);
__QGLTABLENAME.m_pfn_qglEnd(); glEnd();
}
const char* DBobView_state_line = "$bobtoolz/bobview/line";
const char* DBobView_state_box = "$bobtoolz/bobview/box";
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);
}
void DBobView::destroyShaders()
{
GlobalOpenGLStateLibrary().erase(DBobView_state_line);
GlobalOpenGLStateLibrary().erase(DBobView_state_box);
GlobalShaderCache().release(DBobView_state_line);
GlobalShaderCache().release(DBobView_state_box);
}
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;
renderer.SetState(m_shader_line, eWireframeOnly);
renderer.SetState(m_shader_line, eFullMaterials);
renderer.addRenderable(*this, g_matrix4_identity);
if(m_bShowExtra) if(m_bShowExtra)
{ {
// +mars renderer.SetState(m_shader_box, eWireframeOnly);
// ahhh -- a nice C&P job :) renderer.SetState(m_shader_box, eFullMaterials);
// for the bounding box stuff renderer.addRenderable(*this, g_transform_box1);
__QGLTABLENAME.m_pfn_qglColor4f(0.25f, 0.75f, 0.75f, 1.0f); renderer.addRenderable(*this, g_transform_box2);
renderer.addRenderable(*this, g_transform_box3);
__QGLTABLENAME.m_pfn_qglTranslatef( 16.0f, 16.0f, 28.0f ); renderer.addRenderable(*this, g_transform_box4);
}
__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();
} }
void DBobView::renderWireframe(Renderer& renderer, const VolumeTest& volume) const
void DBobView::Register()
{ {
__QGLTABLENAME.m_pfnHookGL2DWindow( this ); renderSolid(renderer, volume);
__QGLTABLENAME.m_pfnHookGL3DWindow( this );
m_bHooked = TRUE;
}
void DBobView::UnRegister()
{
__QGLTABLENAME.m_pfnUnHookGL2DWindow( this );
__QGLTABLENAME.m_pfnUnHookGL3DWindow( this );
m_bHooked = FALSE;
} }
void DBobView::SetPath(vec3_t *pPath) void DBobView::SetPath(vec3_t *pPath)
@ -281,7 +156,7 @@ bool DBobView::CalculateTrajectory(vec3_t start, vec3_t apex, float multiplier,
if(apex[2] <= start[2]) if(apex[2] <= start[2])
{ {
SetPath(NULL); SetPath(NULL);
return FALSE; return false;
} }
// ----think q3a actually would allow these // ----think q3a actually would allow these
//scrub that, coz the plugin wont :] //scrub that, coz the plugin wont :]
@ -319,7 +194,7 @@ bool DBobView::CalculateTrajectory(vec3_t start, vec3_t apex, float multiplier,
} }
SetPath(pPath); 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) void DBobView::Begin(const char* trigger, const char *target, float multiplier, int points, float varGravity, bool bNoUpdate, bool bShowExtra)
@ -332,20 +207,9 @@ void DBobView::Begin(const char* trigger, const char *target, float multiplier,
nPathCount = points; nPathCount = points;
m_bShowExtra = bShowExtra; m_bShowExtra = bShowExtra;
Register(); if(!UpdatePath())
if(UpdatePath())
{ {
if(!bNoUpdate) globalErrorStream() << "Initialization Failure in DBobView::Begin";
{
eyes = new DListener;
eyes->parent = this;
eyes->Register();
}
}
else
{
Sys_ERROR("Initialization Failure in DBobView::Begin");
delete this; delete this;
} }
} }
@ -359,8 +223,55 @@ bool DBobView::UpdatePath()
if(GetEntityCentre(entTarget, apex)) if(GetEntityCentre(entTarget, apex))
{ {
CalculateTrajectory(start, apex, fMultiplier, nPathCount, fVarGravity); 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);
}

View file

@ -24,7 +24,13 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#if !defined(AFX_BOBVIEW_H__6E36062A_EF0B_11D4_ACF7_004095A18133__INCLUDED_) #if !defined(AFX_BOBVIEW_H__6E36062A_EF0B_11D4_ACF7_004095A18133__INCLUDED_)
#define 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 DListener;
class Shader;
#define BOUNDS_ALL 0 #define BOUNDS_ALL 0
#define BOUNDS_APEX 1 #define BOUNDS_APEX 1
@ -33,22 +39,26 @@ class DListener;
#pragma once #pragma once
#endif // _MSC_VER > 1000 #endif // _MSC_VER > 1000
class DBobView : class DBobView : public Renderable, public OpenGLRenderable, public Entity::Observer
public IGL2DWindow,
public IGL3DWindow
{ {
Shader* m_shader_line;
Shader* m_shader_box;
public: public:
DBobView(); DBobView();
virtual ~DBobView(); virtual ~DBobView();
protected: protected:
vec3_t* path; vec3_t* path;
int refCount;
public: public:
bool m_bShowExtra; bool m_bShowExtra;
int boundingShow; int boundingShow;
DListener* eyes; DListener* eyes;
float fVarGravity; float fVarGravity;
float fMultiplier;
int nPathCount;
Entity* trigger;
Entity* target;
bool UpdatePath(); bool UpdatePath();
char entTarget[256]; char entTarget[256];
@ -57,16 +67,40 @@ public:
bool CalculateTrajectory(vec3_t, vec3_t, float, int, float); bool CalculateTrajectory(vec3_t, vec3_t, float, int, float);
void SetPath(vec3_t* pPath); 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; void render(RenderStateFlags state) const;
bool m_bHooked; void renderSolid(Renderer& renderer, const VolumeTest& volume) const;
int nPathCount; 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_) #endif // !defined(AFX_BOBVIEW_H__6E36062A_EF0B_11D4_ACF7_004095A18133__INCLUDED_)

View file

@ -21,32 +21,29 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// //
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
#include "StdAfx.h" #include "DBrush.h"
#ifdef WIN32 #ifdef WIN32
#pragma warning(disable : 4786) #pragma warning(disable : 4786)
#endif #endif
#include "StdAfx.h" #include <list>
#include "gtkr_list.h"
#include "str.h" #include "str.h"
#include "DPoint.h" #include "DPoint.h"
#include "DPlane.h" #include "DPlane.h"
#include "DBrush.h"
#include "DEPair.h" #include "DEPair.h"
#include "DPatch.h" #include "DPatch.h"
#include "DEntity.h" #include "DEntity.h"
#include "DWinding.h" #include "DWinding.h"
#include "dialogs-gtk.h" #include "dialogs/dialogs-gtk.h"
#include "misc.h" #include "misc.h"
#include "iundo.h" #include "iundo.h"
#include "refcounted_ptr.h" #include "generic/referencecounted.h"
#include "scenelib.h" #include "scenelib.h"
@ -57,7 +54,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
DBrush::DBrush(int ID) DBrush::DBrush(int ID)
{ {
m_nBrushID = ID; m_nBrushID = ID;
bBoundsBuilt = FALSE; bBoundsBuilt = false;
QER_brush = NULL; QER_brush = NULL;
} }
@ -71,12 +68,12 @@ DBrush::~DBrush()
// Implementation // 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 #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]); // 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 #endif
bBoundsBuilt = FALSE; bBoundsBuilt = false;
DPlane* newFace = new DPlane(va, vb, vc, texData); DPlane* newFace = new DPlane(va, vb, vc, texData);
faceList.push_back(newFace); faceList.push_back(newFace);
@ -90,12 +87,12 @@ int DBrush::BuildPoints()
if(faceList.size() <= 3) // if less than 3 faces, there can be no points 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 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++) 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++) for(p3++; p3!=faceList.end(); p3++)
{ {
vec3_t pnt; vec3_t pnt;
@ -105,7 +102,7 @@ int DBrush::BuildPoints()
if(pos == POINT_IN_BRUSH) if(pos == POINT_IN_BRUSH)
{ // ???? shouldn't happen here { // ???? 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) else if(pos == POINT_ON_BRUSH)
{ // normal point { // normal point
@ -131,34 +128,33 @@ int DBrush::BuildPoints()
return pointList.size(); return pointList.size();
} }
void DBrush::LoadFromBrush(scene::Node* brush, bool textured) void DBrush_addFace(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), 0);
}
typedef ReferenceCaller1<DBrush, const _QERFaceData&, DBrush_addFace> DBrushAddFaceCaller;
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;
void DBrush::LoadFromBrush(scene::Node& brush, bool textured)
{ {
ClearFaces(); ClearFaces();
ClearPoints(); ClearPoints();
#if 0 GlobalBrushCreator().forEachBrushFace(brush, textured ? BrushFaceDataCallback(DBrushAddFaceTexturedCaller(*this)) : BrushFaceDataCallback(DBrushAddFaceCaller(*this)));
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);
if(faceData == NULL) QER_brush = &brush;
DoMessageBox("Null pointer returned", "WARNING!", MB_OK);
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
QER_brush = brush;
} }
int DBrush::PointPosition(vec3_t pnt) int DBrush::PointPosition(vec3_t pnt)
{ {
int state = POINT_IN_BRUSH; // if nothing happens point is inside brush 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); float dist = (*chkPlane)->DistanceToPoint(pnt);
@ -174,7 +170,7 @@ int DBrush::PointPosition(vec3_t pnt)
void DBrush::ClearPoints() 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; delete *deadPoint;
} }
pointList.clear(); pointList.clear();
@ -182,8 +178,8 @@ void DBrush::ClearPoints()
void DBrush::ClearFaces() void DBrush::ClearFaces()
{ {
bBoundsBuilt = FALSE; bBoundsBuilt = false;
for(list<DPlane *>::const_iterator deadPlane=faceList.begin(); deadPlane!=faceList.end(); deadPlane++) for(std::list<DPlane *>::const_iterator deadPlane=faceList.begin(); deadPlane!=faceList.end(); deadPlane++)
{ {
delete *deadPlane; delete *deadPlane;
} }
@ -199,32 +195,32 @@ void DBrush::AddPoint(vec3_t pnt)
bool DBrush::HasPoint(vec3_t pnt) 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) if(**chkPoint == pnt)
return TRUE; return true;
} }
return FALSE; return false;
} }
int DBrush::RemoveRedundantPlanes() int DBrush::RemoveRedundantPlanes()
{ {
int cnt = 0; int cnt = 0;
list<DPlane *>::iterator chkPlane; std::list<DPlane *>::iterator chkPlane;
// find duplicate planes // find duplicate planes
list<DPlane *>::iterator p1=faceList.begin(); std::list<DPlane *>::iterator p1=faceList.begin();
while( p1!=faceList.end() ) while( p1!=faceList.end() )
{ {
list<DPlane *>::iterator p2 = p1; std::list<DPlane *>::iterator p2 = p1;
for(p2++; p2!=faceList.end(); p2++) for(p2++; p2!=faceList.end(); p2++)
{ {
if(**p1 == **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; delete *p1;
p1 = faceList.erase(p1); // duplicate plane p1 = faceList.erase(p1); // duplicate plane
@ -285,12 +281,12 @@ bool DBrush::GetBounds(vec3_t min, vec3_t max)
BuildBounds(); BuildBounds();
if(!bBoundsBuilt) if(!bBoundsBuilt)
return FALSE; return false;
VectorCopy(bbox_min, min); VectorCopy(bbox_min, min);
VectorCopy(bbox_max, max); VectorCopy(bbox_max, max);
return TRUE; return true;
} }
bool DBrush::BBoxCollision(DBrush* chkBrush) bool DBrush::BBoxCollision(DBrush* chkBrush)
@ -302,25 +298,25 @@ bool DBrush::BBoxCollision(DBrush* chkBrush)
chkBrush->GetBounds(min2, max2); chkBrush->GetBounds(min2, max2);
if(min1[0] >= max2[0]) if(min1[0] >= max2[0])
return FALSE; return false;
if(min1[1] >= max2[1]) if(min1[1] >= max2[1])
return FALSE; return false;
if(min1[2] >= max2[2]) if(min1[2] >= max2[2])
return FALSE; return false;
if(max1[0] <= min2[0]) if(max1[0] <= min2[0])
return FALSE; return false;
if(max1[1] <= min2[1]) if(max1[1] <= min2[1])
return FALSE; return false;
if(max1[2] <= min2[2]) if(max1[2] <= min2[2])
return FALSE; return false;
return TRUE; return true;
} }
DPlane* DBrush::HasPlane(DPlane* chkPlane) 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) if(**brushPlane == *chkPlane)
return *brushPlane; return *brushPlane;
@ -334,21 +330,21 @@ bool DBrush::IsCutByPlane(DPlane *cuttingPlane)
if(pointList.size() == 0) if(pointList.size() == 0)
if(BuildPoints() == 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()) if(chkPnt == pointList.end())
return FALSE; return false;
float dist = cuttingPlane->DistanceToPoint((*chkPnt)->_pnt); float dist = cuttingPlane->DistanceToPoint((*chkPnt)->_pnt);
if(dist > MAX_ROUND_ERROR) if(dist > MAX_ROUND_ERROR)
isInFront = FALSE; isInFront = false;
else if(dist < MAX_ROUND_ERROR) else if(dist < MAX_ROUND_ERROR)
isInFront = TRUE; isInFront = true;
else else
return TRUE; return true;
for(chkPnt++=pointList.begin(); chkPnt!=pointList.end(); chkPnt++) for(chkPnt++=pointList.begin(); chkPnt!=pointList.end(); chkPnt++)
{ {
@ -357,31 +353,32 @@ bool DBrush::IsCutByPlane(DPlane *cuttingPlane)
if(dist > MAX_ROUND_ERROR) if(dist > MAX_ROUND_ERROR)
{ {
if(isInFront) if(isInFront)
return TRUE; return true;
} }
else if(dist < MAX_ROUND_ERROR) else if(dist < MAX_ROUND_ERROR)
{ {
if(!isInFront) if(!isInFront)
return TRUE; return true;
} }
else else
return TRUE; return true;
} }
return FALSE; return false;
} }
scene::Node* DBrush::BuildInRadiant(bool allowDestruction, int* changeCnt, scene::Node* entity) scene::Node* DBrush::BuildInRadiant(bool allowDestruction, int* changeCnt, scene::Node* entity)
{ {
if(allowDestruction) 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) if((*chkPlane)->m_bChkOk)
{ {
kill = FALSE; kill = false;
break; break;
} }
} }
@ -392,26 +389,26 @@ scene::Node* DBrush::BuildInRadiant(bool allowDestruction, int* changeCnt, scene
//+djbob: fixed bug when brush had no faces "phantom brush" in radiant. //+djbob: fixed bug when brush had no faces "phantom brush" in radiant.
if(faceList.size() < 4) 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; return NULL;
} }
//-djbob //-djbob
NodePtr node(Brush_AllocNode()); scene::Node& node = GlobalBrushCreator().createBrush();
for(list<DPlane *>::const_iterator buildPlane=faceList.begin(); buildPlane!=faceList.end(); buildPlane++) { for(std::list<DPlane *>::const_iterator buildPlane=faceList.begin(); buildPlane!=faceList.end(); buildPlane++) {
if((*buildPlane)->AddToBrush(node->m_brush) && changeCnt) { if((*buildPlane)->AddToBrush(node) && changeCnt) {
(*changeCnt)++; (*changeCnt)++;
} }
} }
if(entity) { if(entity) {
entity->m_traverse->insert(node); Node_getTraversable(*entity)->insert(node);
} else { } 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) void DBrush::CutByPlane(DPlane *cutPlane, DBrush **newBrush1, DBrush **newBrush2)
@ -426,7 +423,7 @@ void DBrush::CutByPlane(DPlane *cutPlane, DBrush **newBrush1, DBrush **newBrush2
DBrush* b1 = new DBrush; DBrush* b1 = new DBrush;
DBrush* b2 = 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); b1->AddFace((*parsePlane)->points[0], (*parsePlane)->points[1], (*parsePlane)->points[2], NULL);
b2->AddFace((*parsePlane)->points[0], (*parsePlane)->points[1], (*parsePlane)->points[2], NULL); b2->AddFace((*parsePlane)->points[0], (*parsePlane)->points[1], (*parsePlane)->points[2], NULL);
@ -446,55 +443,55 @@ bool DBrush::IntersectsWith(DBrush *chkBrush)
{ {
if(pointList.size() == 0) if(pointList.size() == 0)
if(BuildPoints() == 0) if(BuildPoints() == 0)
return FALSE; // invalid brush!!!! return false; // invalid brush!!!!
if(chkBrush->pointList.size() == 0) if(chkBrush->pointList.size() == 0)
if(chkBrush->BuildPoints() == 0) if(chkBrush->BuildPoints() == 0)
return FALSE; // invalid brush!!!! return false; // invalid brush!!!!
if(!BBoxCollision(chkBrush)) 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++) for( iplPlane=faceList.begin(); iplPlane!=faceList.end(); iplPlane++)
{ {
bool allInFront = TRUE; bool allInFront = true;
for(list<DPoint *>::const_iterator iPoint=chkBrush->pointList.begin(); iPoint!=chkBrush->pointList.end(); iPoint++) for(std::list<DPoint *>::const_iterator iPoint=chkBrush->pointList.begin(); iPoint!=chkBrush->pointList.end(); iPoint++)
{ {
if((*iplPlane)->DistanceToPoint((*iPoint)->_pnt) < -MAX_ROUND_ERROR) if((*iplPlane)->DistanceToPoint((*iPoint)->_pnt) < -MAX_ROUND_ERROR)
{ {
allInFront = FALSE; allInFront = false;
break; break;
} }
} }
if(allInFront) if(allInFront)
return FALSE; return false;
} }
for( iplPlane=chkBrush->faceList.begin(); iplPlane!=chkBrush->faceList.end(); iplPlane++) for( iplPlane=chkBrush->faceList.begin(); iplPlane!=chkBrush->faceList.end(); iplPlane++)
{ {
bool allInFront = TRUE; bool allInFront = true;
for(list<DPoint *>::const_iterator iPoint=pointList.begin(); iPoint!=pointList.end(); iPoint++) for(std::list<DPoint *>::const_iterator iPoint=pointList.begin(); iPoint!=pointList.end(); iPoint++)
{ {
if((*iplPlane)->DistanceToPoint((*iPoint)->_pnt) < -MAX_ROUND_ERROR) if((*iplPlane)->DistanceToPoint((*iPoint)->_pnt) < -MAX_ROUND_ERROR)
{ {
allInFront = FALSE; allInFront = false;
break; break;
} }
} }
if(allInFront) if(allInFront)
return FALSE; return false;
} }
return TRUE; return true;
} }
bool DBrush::IntersectsWith(DPlane* p1, DPlane* p2, vec3_t v) { bool DBrush::IntersectsWith(DPlane* p1, DPlane* p2, vec3_t v) {
vec3_t vDown = { 0, 0, -1 }; 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++) { for( iplPlane = faceList.begin(); iplPlane != faceList.end(); iplPlane++) {
DPlane* p = (*iplPlane); DPlane* p = (*iplPlane);
@ -504,12 +501,12 @@ bool DBrush::IntersectsWith(DPlane* p1, DPlane* p2, vec3_t v) {
} }
if(p->PlaneIntersection(p1, p2, v)) { if(p->PlaneIntersection(p1, p2, v)) {
if(PointPosition( v ) != POINT_OUT_BRUSH) { if(PointPosition( v ) != POINT_OUT_BRUSH) {
return TRUE; return true;
} }
} }
} }
return FALSE; return false;
} }
void DBrush::BuildBounds() void DBrush::BuildBounds()
@ -520,11 +517,11 @@ void DBrush::BuildBounds()
if(BuildPoints() == 0) if(BuildPoints() == 0)
return; 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_min);
VectorCopy((*first)->_pnt, bbox_max); 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++) for( point++; point!=pointList.end(); point++)
{ {
if((*point)->_pnt[0] > bbox_max[0]) if((*point)->_pnt[0] > bbox_max[0])
@ -542,7 +539,7 @@ void DBrush::BuildBounds()
bbox_min[2] = (*point)->_pnt[2]; bbox_min[2] = (*point)->_pnt[2];
} }
bBoundsBuilt = TRUE; bBoundsBuilt = true;
} }
} }
@ -555,18 +552,18 @@ bool DBrush::BBoxTouch(DBrush *chkBrush)
chkBrush->GetBounds(min2, max2); chkBrush->GetBounds(min2, max2);
if((min1[0] - max2[0]) > MAX_ROUND_ERROR) if((min1[0] - max2[0]) > MAX_ROUND_ERROR)
return FALSE; return false;
if((min1[1] - max2[1]) > MAX_ROUND_ERROR) if((min1[1] - max2[1]) > MAX_ROUND_ERROR)
return FALSE; return false;
if((min1[2] - max2[2]) > MAX_ROUND_ERROR) if((min1[2] - max2[2]) > MAX_ROUND_ERROR)
return FALSE; return false;
if((min2[0] - max1[0]) > MAX_ROUND_ERROR) if((min2[0] - max1[0]) > MAX_ROUND_ERROR)
return FALSE; return false;
if((min2[1] - max1[1]) > MAX_ROUND_ERROR) if((min2[1] - max1[1]) > MAX_ROUND_ERROR)
return FALSE; return false;
if((min2[2] - max1[2]) > MAX_ROUND_ERROR) if((min2[2] - max1[2]) > MAX_ROUND_ERROR)
return FALSE; return false;
int cnt = 0; int cnt = 0;
@ -589,24 +586,24 @@ bool DBrush::BBoxTouch(DBrush *chkBrush)
cnt++; cnt++;
if(cnt > 1) 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) 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; break;
} }
} }
@ -618,7 +615,7 @@ void DBrush::ResetChecks(list<Str>* exclusionList)
DPlane* DBrush::HasPlaneInverted(DPlane *chkPlane) 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) if(**brushPlane != *chkPlane)
{ {
@ -631,31 +628,31 @@ DPlane* DBrush::HasPlaneInverted(DPlane *chkPlane)
bool DBrush::HasTexture(const char *textureName) 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)) if(strstr((*chkPlane)->m_shader.c_str(), textureName))
return TRUE; return true;
} }
return FALSE; return false;
} }
bool DBrush::IsDetail() 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) if((*chkPlane)->texInfo.contents & FACE_DETAIL)
return TRUE; return true;
} }
return FALSE; return false;
} }
void DBrush::BuildFromWinding(DWinding *w) void DBrush::BuildFromWinding(DWinding *w)
{ {
if(w->numpoints < 3) if(w->numpoints < 3)
{ {
Sys_ERROR("Winding has invalid number of points"); globalErrorStream() << "Winding has invalid number of points";
return; return;
} }
@ -682,7 +679,7 @@ void DBrush::SaveToFile(FILE *pFile)
{ {
fprintf(pFile, "{\n"); 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]; char buffer[512];
@ -690,7 +687,7 @@ void DBrush::SaveToFile(FILE *pFile)
(*pp)->points[0][0], (*pp)->points[0][1], (*pp)->points[0][2], (*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[1][0], (*pp)->points[1][1], (*pp)->points[1][2],
(*pp)->points[2][0], (*pp)->points[2][1], (*pp)->points[2][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.shift[0], (*pp)->texInfo.m_texdef.shift[1],
(*pp)->texInfo.m_texdef.scale[0], (*pp)->texInfo.m_texdef.scale[0], (*pp)->texInfo.m_texdef.scale[0], (*pp)->texInfo.m_texdef.scale[0],
(*pp)->texInfo.m_texdef.rotate); (*pp)->texInfo.m_texdef.rotate);
@ -703,7 +700,7 @@ void DBrush::SaveToFile(FILE *pFile)
void DBrush::Rotate(vec3_t vOrigin, vec3_t vRotation) 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++) for(int i = 0; i < 3; i++)
VectorRotate((*rotPlane)->points[i], vRotation, vOrigin); VectorRotate((*rotPlane)->points[i], vRotation, vOrigin);
@ -727,13 +724,13 @@ bool DBrush::ResetTextures(const char* textureName, float fScale[2], float fS
{ {
if(textureName) if(textureName)
{ {
bool changed = FALSE; bool changed = false;
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(!strcmp((*resetPlane)->texInfo.m_texdef.GetName(), textureName)) if(!strcmp((*resetPlane)->m_shader.c_str(), textureName))
{ {
if(bResetTextureName) if(bResetTextureName)
(*resetPlane)->texInfo.m_texdef.SetName(newTextureName); (*resetPlane)->m_shader = newTextureName;
if(bResetScale[0]) if(bResetScale[0])
(*resetPlane)->texInfo.m_texdef.scale[0] = fScale[0]; (*resetPlane)->texInfo.m_texdef.scale[0] = fScale[0];
@ -748,17 +745,17 @@ bool DBrush::ResetTextures(const char* textureName, float fScale[2], float fS
if(bResetRotation) if(bResetRotation)
(*resetPlane)->texInfo.m_texdef.rotate = (float)rotation; (*resetPlane)->texInfo.m_texdef.rotate = (float)rotation;
changed = TRUE; changed = true;
} }
} }
return changed; // no point rebuilding unless we need to, only slows things down return changed; // no point rebuilding unless we need to, only slows things down
} }
else 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) if(bResetTextureName)
(*resetPlane)->texInfo.m_texdef.SetName(newTextureName); (*resetPlane)->m_shader = newTextureName;
if(bResetScale[0]) if(bResetScale[0])
(*resetPlane)->texInfo.m_texdef.scale[0] = fScale[0]; (*resetPlane)->texInfo.m_texdef.scale[0] = fScale[0];
@ -773,32 +770,32 @@ bool DBrush::ResetTextures(const char* textureName, float fScale[2], float fS
if(bResetRotation) if(bResetRotation)
(*resetPlane)->texInfo.m_texdef.rotate = (float)rotation; (*resetPlane)->texInfo.m_texdef.rotate = (float)rotation;
} }
return TRUE; return true;
} }
} }
bool DBrush::operator ==(DBrush* other) bool DBrush::operator ==(DBrush* other)
{ {
list<DPlane *>::const_iterator chkPlane; std::list<DPlane *>::const_iterator chkPlane;
for(chkPlane=faceList.begin(); chkPlane!=faceList.end(); chkPlane++) for(chkPlane=faceList.begin(); chkPlane!=faceList.end(); chkPlane++)
{ {
if(!other->HasPlane((*chkPlane))) if(!other->HasPlane((*chkPlane)))
return FALSE; return false;
} }
for(chkPlane=faceList.begin(); chkPlane!=faceList.end(); chkPlane++) for(chkPlane=faceList.begin(); chkPlane!=faceList.end(); chkPlane++)
{ {
if(!HasPlane((*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); DPlane* newFace = new DPlane(va, vb, vc, textureName, bDetail);
faceList.push_back(newFace); faceList.push_back(newFace);
@ -808,7 +805,7 @@ DPlane* DBrush::AddFace(vec3_t va, vec3_t vb, vec3_t vc, const char *textureName
DPlane* DBrush::FindPlaneWithClosestNormal( vec_t* normal ) { DPlane* DBrush::FindPlaneWithClosestNormal( vec_t* normal ) {
vec_t bestDot = -2; vec_t bestDot = -2;
DPlane* bestDotPlane = NULL; DPlane* bestDotPlane = NULL;
list<DPlane *>::const_iterator chkPlane; std::list<DPlane *>::const_iterator chkPlane;
for( chkPlane = faceList.begin(); chkPlane != faceList.end(); chkPlane++ ) { for( chkPlane = faceList.begin(); chkPlane != faceList.end(); chkPlane++ ) {
DPlane* pPlane = (*chkPlane); DPlane* pPlane = (*chkPlane);
@ -831,7 +828,7 @@ int DBrush::FindPointsForPlane( DPlane* plane, DPoint** pnts, int maxpnts ) {
BuildPoints(); 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); DPoint* point = (*points);
if( fabs(plane->DistanceToPoint( point->_pnt )) < MAX_ROUND_ERROR ) { if( fabs(plane->DistanceToPoint( point->_pnt )) < MAX_ROUND_ERROR ) {
@ -849,19 +846,11 @@ int DBrush::FindPointsForPlane( DPlane* plane, DPoint** pnts, int maxpnts ) {
} }
void DBrush::RemovePlane( DPlane* plane ) { void DBrush::RemovePlane( DPlane* plane ) {
bBoundsBuilt = FALSE; bBoundsBuilt = false;
for( list<DPlane *>::const_iterator deadPlane = faceList.begin(); deadPlane != faceList.end(); deadPlane++ ) { for( std::list<DPlane *>::const_iterator deadPlane = faceList.begin(); deadPlane != faceList.end(); deadPlane++ ) {
if(*deadPlane == plane) { if(*deadPlane == plane) {
delete *deadPlane; delete *deadPlane;
faceList.remove( plane ); faceList.remove( plane );
} }
} }
} }
void DBrush::RemoveFromRadiant( void ) {
if(QER_brush) {
#if 0
g_FuncTable.m_pfnDeleteBrushHandle(QER_brush);
#endif
}
}

View file

@ -28,6 +28,21 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#pragma once #pragma once
#endif // _MSC_VER > 1000 #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_IN_BRUSH 0
#define POINT_ON_BRUSH 1 #define POINT_ON_BRUSH 1
#define POINT_OUT_BRUSH 2 #define POINT_OUT_BRUSH 2
@ -35,7 +50,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
class DBrush class DBrush
{ {
public: 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 SaveToFile(FILE* pFile);
void Rotate(vec3_t vOrigin, vec3_t vRotation); void Rotate(vec3_t vOrigin, vec3_t vRotation);
@ -43,7 +58,7 @@ public:
DPlane* HasPlaneInverted(DPlane* chkPlane); DPlane* HasPlaneInverted(DPlane* chkPlane);
DPlane* HasPlane(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 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(); bool IsDetail();
@ -61,7 +76,7 @@ public:
void BuildFromWinding(DWinding* w); void BuildFromWinding(DWinding* w);
scene::Node* BuildInRadiant(bool allowDestruction, int* changeCnt, scene::Node* entity = NULL); 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 ClearFaces();
void ClearPoints(); void ClearPoints();
@ -69,12 +84,11 @@ public:
int RemoveRedundantPlanes( void ); int RemoveRedundantPlanes( void );
void RemovePlane( DPlane* plane ); void RemovePlane( DPlane* plane );
int PointPosition(vec3_t pnt); int PointPosition(vec3_t pnt);
void RemoveFromRadiant( void );
void CutByPlane(DPlane* cutPlane, DBrush** newBrush1, DBrush** newBrush2); 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); void AddPoint(vec3_t pnt);
DPlane* FindPlaneWithClosestNormal( vec_t* normal ); DPlane* FindPlaneWithClosestNormal( vec_t* normal );
@ -87,8 +101,8 @@ public:
// members // members
scene::Node* QER_brush; scene::Node* QER_brush;
list<DPlane*> faceList; std::list<DPlane*> faceList;
list<DPoint*> pointList; std::list<DPoint*> pointList;
int m_nBrushID; int m_nBrushID;
vec3_t bbox_min, bbox_max; vec3_t bbox_min, bbox_max;
bool bBoundsBuilt; bool bBoundsBuilt;

View file

@ -21,8 +21,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// //
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
#include "StdAfx.h"
#include "str.h"
#include "DEPair.h" #include "DEPair.h"
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////

View file

@ -28,6 +28,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#pragma once #pragma once
#endif // _MSC_VER > 1000 #endif // _MSC_VER > 1000
#include "str.h"
class DEPair class DEPair
{ {
public: public:

View file

@ -21,13 +21,13 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// //
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
#include "DEntity.h"
#ifdef WIN32 #ifdef WIN32
#pragma warning(disable : 4786) #pragma warning(disable : 4786)
#endif #endif
#include "StdAfx.h" #include <list>
#include "gtkr_list.h"
#include "str.h" #include "str.h"
#include "DPoint.h" #include "DPoint.h"
@ -35,15 +35,16 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "DBrush.h" #include "DBrush.h"
#include "DEPair.h" #include "DEPair.h"
#include "DPatch.h" #include "DPatch.h"
#include "DEntity.h"
#include "dialogs-gtk.h" #include "dialogs/dialogs-gtk.h"
#include "misc.h" #include "misc.h"
#include "CPortals.h" #include "CPortals.h"
#include "iundo.h" #include "iundo.h"
#include "ientity.h"
#include "ieclass.h"
#include "refcounted_ptr.h" #include "generic/referencecounted.h"
#include <vector> #include <vector>
#include <list> #include <list>
@ -97,7 +98,7 @@ DEntity::~DEntity()
void DEntity::ClearBrushes() 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; delete *deadBrush;
} }
@ -106,7 +107,7 @@ void DEntity::ClearBrushes()
void DEntity::ClearPatches() 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; delete *deadPatch;
} }
@ -151,7 +152,7 @@ bool DEntity::LoadFromPrt(char *filename)
portals.Load(); portals.Load();
if(portals.node_count == 0) if(portals.node_count == 0)
return FALSE; return false;
ClearBrushes(); ClearBrushes();
ClearEPairs(); ClearEPairs();
@ -188,15 +189,15 @@ bool DEntity::LoadFromPrt(char *filename)
} }
if(!build) 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 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) 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) DPlane* DEntity::AddFaceToBrush(vec3_t va, vec3_t vb, vec3_t vc, _QERFaceData* faceData, int ID)
@ -210,7 +211,7 @@ DBrush* DEntity::GetBrushForID(int ID)
{ {
DBrush* buildBrush = NULL; 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) if((*chkBrush)->m_nBrushID == ID)
{ {
@ -225,47 +226,82 @@ DBrush* DEntity::GetBrushForID(int ID)
return buildBrush; 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() void DEntity::LoadSelectedBrushes()
{ {
ClearBrushes(); ClearBrushes();
ClearEPairs(); ClearEPairs();
#if 0 Scene_forEachSelectedBrush(DEntityLoadBrushCaller(*this));
int count = g_FuncTable.m_pfnAllocateSelectedBrushHandles();
for(int i = 0; i < count; i++) {
brush_t *brush = (brush_t*)g_FuncTable.m_pfnGetSelectedBrushHandle(i);
if(brush->patchBrush)
continue;
DBrush* loadBrush = NewBrush(i);
loadBrush->LoadFromBrush_t(brush, TRUE);
}
g_FuncTable.m_pfnReleaseSelectedBrushHandles();
#endif
} }
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());
}
}
};
template<typename Functor>
inline const Functor& Scene_forEachSelectedPatch(const Functor& functor)
{
GlobalSelectionSystem().foreachSelected(PatchSelectedVisitor<Functor>(functor));
return functor;
}
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() void DEntity::LoadSelectedPatches()
{ {
ClearPatches(); ClearPatches();
ClearEPairs(); ClearEPairs();
#if 0 Scene_forEachSelectedPatch(DEntityLoadPatchCaller(*this));
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
} }
bool* DEntity::BuildIntersectList() bool* DEntity::BuildIntersectList()
@ -277,15 +313,15 @@ bool* DEntity::BuildIntersectList()
bool* pbIntList = new bool[max]; bool* pbIntList = new bool[max];
memset(pbIntList, 0, sizeof(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++) for(pB2++; pB2!=brushList.end(); pB2++)
{ {
if((*pB1)->IntersectsWith((*pB2))) if((*pB1)->IntersectsWith((*pB2)))
{ {
pbIntList[(*pB1)->m_nBrushID] = TRUE; pbIntList[(*pB1)->m_nBrushID] = true;
pbIntList[(*pB2)->m_nBrushID] = TRUE; pbIntList[(*pB2)->m_nBrushID] = true;
} }
} }
} }
@ -302,15 +338,15 @@ bool* DEntity::BuildDuplicateList()
bool* pbDupList = new bool[max]; bool* pbDupList = new bool[max];
memset(pbDupList, 0, sizeof(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++) for(pB2++; pB2!=brushList.end(); pB2++)
{ {
if(**pB1 == *pB2) if(**pB1 == *pB2)
{ {
pbDupList[(*pB1)->m_nBrushID] = TRUE; pbDupList[(*pB1)->m_nBrushID] = true;
pbDupList[(*pB2)->m_nBrushID] = TRUE; pbDupList[(*pB2)->m_nBrushID] = true;
} }
} }
} }
@ -323,84 +359,81 @@ void DEntity::SelectBrushes(bool *selectList)
if(selectList == NULL) if(selectList == NULL)
return; return;
GlobalSelectionSystem().Select(false); GlobalSelectionSystem().setSelectedAll(false);
scene::Path path(GlobalSceneGraph().root()); scene::Path path(NodeReference(GlobalSceneGraph().root()));
path.push(QER_Entity); path.push(NodeReference(*QER_Entity));
for(std::list<DBrush *>::const_iterator pBrush=brushList.begin(); pBrush!=brushList.end(); pBrush++) for(std::list<DBrush *>::const_iterator pBrush=brushList.begin(); pBrush!=brushList.end(); pBrush++)
{ {
if(selectList[(*pBrush)->m_nBrushID]) if(selectList[(*pBrush)->m_nBrushID])
{ {
path.push((*pBrush)->QER_brush); path.push(NodeReference(*(*pBrush)->QER_brush));
GlobalSceneGraph().find(path)->selectable()->select(true); Instance_getSelectable(*GlobalSceneGraph().find(path))->setSelected(true);
path.pop(); path.pop();
} }
} }
} }
bool DEntity::LoadFromEntity(scene::Node* ent, bool bLoadPatches) { bool DEntity::LoadFromEntity(scene::Node& ent, bool bLoadPatches) {
ClearPatches(); ClearPatches();
ClearBrushes(); ClearBrushes();
ClearEPairs(); ClearEPairs();
QER_Entity = ent; QER_Entity = &ent;
LoadEPairList(ent->m_entity); LoadEPairList(Node_getEntity(ent));
bool keep = FALSE; bool keep = false;
int i; int i;
for(i = 0; brushEntityList[i]; 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; break;
} }
} }
if(!keep) if(!keep)
return FALSE; return false;
if(ent->m_traverse) if(Node_getTraversable(ent))
{ {
class load_brushes_t : public scene::Traversable::Walker class load_brushes_t : public scene::Traversable::Walker
{ {
DEntity* m_entity; DEntity* m_entity;
int m_count; mutable int m_count;
public: public:
load_brushes_t(DEntity* entity) load_brushes_t(DEntity* entity)
: m_entity(entity), m_count(0) : 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(); DPatch* loadPatch = m_entity->NewPatch();
loadPatch->LoadFromBrush(node); loadPatch->LoadFromBrush(node);
} }
else if(node->m_patch) else if(Node_isBrush(node))
{ {
DBrush* loadBrush = m_entity->NewBrush(m_count++); DBrush* loadBrush = m_entity->NewBrush(m_count++);
loadBrush->LoadFromBrush(node, TRUE); loadBrush->LoadFromBrush(node, true);
} }
return false; return false;
} }
void post(scene::Node* node)
{
}
} load_brushes(this); } 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() ) while( chkBrush!=brushList.end() )
{ {
@ -414,7 +447,7 @@ void DEntity::RemoveNonCheckBrushes(list<Str>* exclusionList, bool useDetail)
} }
} }
list<Str>::iterator eTexture; std::list<Str>::iterator eTexture;
for( eTexture=exclusionList->begin(); eTexture!=exclusionList->end(); eTexture++ ) for( eTexture=exclusionList->begin(); eTexture!=exclusionList->end(); eTexture++ )
{ {
@ -431,9 +464,9 @@ void DEntity::RemoveNonCheckBrushes(list<Str>* exclusionList, bool useDetail)
} }
} }
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); (*resetBrush)->ResetChecks(exclusionList);
} }
@ -443,7 +476,7 @@ int DEntity::FixBrushes()
{ {
int count = 0; 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(); count += (*fixBrush)->RemoveRedundantPlanes();
} }
@ -457,29 +490,29 @@ void DEntity::BuildInRadiant(bool allowDestruction)
if(makeEntity) 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++) for(std::list<DBrush *>::const_iterator buildBrush=brushList.begin(); buildBrush!=brushList.end(); buildBrush++)
(*buildBrush)->BuildInRadiant(allowDestruction, NULL, node); (*buildBrush)->BuildInRadiant(allowDestruction, NULL, node.get_pointer());
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(node); (*buildPatch)->BuildInRadiant(node.get_pointer());
QER_Entity = node; QER_Entity = node.get_pointer();
} }
else 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); (*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(); (*buildPatch)->BuildInRadiant();
} }
} }
@ -488,7 +521,7 @@ void DEntity::BuildInRadiant(bool allowDestruction)
int DEntity::GetIDMax( void ) { int DEntity::GetIDMax( void ) {
int max = -1; 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) if((*cntBrush)->m_nBrushID > max)
max = (*cntBrush)->m_nBrushID; max = (*cntBrush)->m_nBrushID;
} }
@ -505,12 +538,12 @@ void DEntity::SaveToFile(FILE *pFile)
fprintf(pFile, "\"classname\" \"%s\"\n", (const char *)m_Classname); 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); 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); (*bp)->SaveToFile(pFile);
} }
@ -520,7 +553,7 @@ void DEntity::SaveToFile(FILE *pFile)
void DEntity::ClearEPairs() 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); delete (*deadEPair);
} }
@ -559,34 +592,34 @@ void DEntity::LoadEPairList(Entity *epl)
} load_epairs(this); } 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, 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) 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, bool tmp = (*resetBrush)->ResetTextures(textureName, fScale, fShift, rotation, newTextureName,
bResetTextureName, bResetScale, bResetShift, bResetRotation); bResetTextureName, bResetScale, bResetShift, bResetRotation);
if(tmp) if(tmp)
{ {
reset = TRUE; reset = true;
} }
} }
if(bResetTextureName) 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); bool tmp = (*resetPatch)->ResetTextures(textureName, newTextureName);
if(tmp) if(tmp)
{ {
reset = TRUE; reset = true;
} }
} }
} }
@ -596,7 +629,7 @@ bool DEntity::ResetTextures(const char* textureName, float fScale[2], float
DEPair* DEntity::FindEPairByKey(const char* keyname) 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; char* c = (*ep)->key;
if(!strcmp(c, keyname)) if(!strcmp(c, keyname))
@ -607,7 +640,7 @@ DEPair* DEntity::FindEPairByKey(const char* keyname)
void DEntity::RemoveFromRadiant() void DEntity::RemoveFromRadiant()
{ {
GlobalSceneGraph().root()->m_traverse->erase(QER_Entity); Node_getTraversable(GlobalSceneGraph().root())->erase(*QER_Entity);
QER_Entity = NULL; QER_Entity = NULL;
} }
@ -656,10 +689,10 @@ int DEntity::GetBrushCount( void ) {
return brushList.size(); return brushList.size();
} }
DBrush* DEntity::FindBrushByPointer( scene::Node* brush ) { DBrush* DEntity::FindBrushByPointer( scene::Node& brush ) {
for(list<DBrush *>::const_iterator listBrush = brushList.begin(); listBrush != brushList.end(); listBrush++) { for(std::list<DBrush *>::const_iterator listBrush = brushList.begin(); listBrush != brushList.end(); listBrush++) {
DBrush* pBrush = (*listBrush); DBrush* pBrush = (*listBrush);
if(pBrush->QER_brush == brush) { if(pBrush->QER_brush == &brush) {
return pBrush; return pBrush;
} }
} }

View file

@ -28,6 +28,22 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#pragma once #pragma once
#endif // _MSC_VER > 1000 #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 class DEntity
{ {
public: public:
@ -54,12 +70,12 @@ public:
int GetIDMax(); int GetIDMax();
void BuildInRadiant(bool allowDestruction); void BuildInRadiant(bool allowDestruction);
void ResetChecks(list<Str>* exclusionList); void ResetChecks(std::list<Str>* exclusionList);
void RemoveNonCheckBrushes(list<Str>* exclusionList, bool useDetail); 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 DPlane* AddFaceToBrush(vec3_t va, vec3_t vb, vec3_t vc, _QERFaceData* faceData, int ID); // slow, try not to use much
int GetBrushCount( void ); int GetBrushCount( void );
DBrush* FindBrushByPointer( scene::Node* brush ); DBrush* FindBrushByPointer( scene::Node& brush );
// --------------------------------------------- // ---------------------------------------------
@ -84,17 +100,17 @@ public:
// --------------------------------------------- // ---------------------------------------------
// vars // vars
list<DEPair*> epairList; std::list<DEPair*> epairList;
list<DBrush*> brushList; std::list<DBrush*> brushList;
// new patches, wahey!!! // new patches, wahey!!!
list<DPatch*> patchList; std::list<DPatch*> patchList;
Str m_Classname; Str m_Classname;
// --------------------------------------------- // ---------------------------------------------
int FixBrushes(); int FixBrushes();
bool LoadFromEntity(scene::Node* ent, bool bLoadPatches = FALSE); bool LoadFromEntity(scene::Node& ent, bool bLoadPatches = false);
void LoadSelectedBrushes(); void LoadSelectedBrushes();
void LoadSelectedPatches(); void LoadSelectedPatches();

View file

@ -21,7 +21,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// //
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
#include "StdAfx.h"
#include "DListener.h" #include "DListener.h"
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////

View file

@ -21,10 +21,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// //
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
#include "StdAfx.h" #include "DMap.h"
#include "str.h" #include "str.h"
#include "gtkr_list.h" #include <list>
#include "DPoint.h" #include "DPoint.h"
#include "DPlane.h" #include "DPlane.h"
@ -32,11 +32,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "DEPair.h" #include "DEPair.h"
#include "DPatch.h" #include "DPatch.h"
#include "DEntity.h" #include "DEntity.h"
#include "DMap.h"
#include "iundo.h" #include "iundo.h"
#include "refcounted_ptr.h" #include "generic/referencecounted.h"
#include <vector> #include <vector>
#include <list> #include <list>
@ -78,7 +77,7 @@ void DMap::ClearEntities()
{ {
m_nNextEntity = 1; 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; delete *deadEntity;
entityList.clear(); entityList.clear();
@ -88,7 +87,7 @@ DEntity* DMap::GetEntityForID(int ID)
{ {
DEntity* findEntity = NULL; 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) if((*chkEntity)->m_nID == ID)
{ {
@ -111,7 +110,7 @@ DEntity* DMap::GetWorldSpawn()
void DMap::BuildInRadiant(bool bAllowDestruction) 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); (*buildEntity)->BuildInRadiant(bAllowDestruction);
} }
@ -119,7 +118,7 @@ void DMap::LoadAll(bool bLoadPatches)
{ {
ClearEntities(); ClearEntities();
GlobalSelectionSystem().Select(false); GlobalSelectionSystem().setSelectedAll(false);
class load_entities_t : public scene::Traversable::Walker class load_entities_t : public scene::Traversable::Walker
{ {
@ -130,27 +129,24 @@ void DMap::LoadAll(bool bLoadPatches)
: m_map(map), m_bLoadPatches(bLoadPatches) : 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); DEntity* loadEntity = m_map->AddEntity("", 0);
loadEntity->LoadFromEntity(node, m_bLoadPatches); loadEntity->LoadFromEntity(node, m_bLoadPatches);
} }
return false; return false;
} }
void post(scene::Node* node)
{
}
} load_entities(this, bLoadPatches); } load_entities(this, bLoadPatches);
GlobalSceneGraph().root()->m_traverse->traverse(load_entities); Node_getTraversable(GlobalSceneGraph().root())->traverse(load_entities);
} }
int DMap::FixBrushes() int DMap::FixBrushes()
{ {
int count = 0; 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(); count += (*fixEntity)->FixBrushes();
} }
@ -161,15 +157,15 @@ int DMap::FixBrushes()
void DMap::ResetTextures( const char* textureName, float fScale[2], float fShift[2], int rotation, const char* newTextureName, 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) 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, (*texEntity)->ResetTextures(textureName, fScale, fShift, rotation, newTextureName,
bResetTextureName, bResetScale, bResetShift, bResetRotation, TRUE); bResetTextureName, bResetScale, bResetShift, bResetRotation, true);
else else
{ {
if((*texEntity)->ResetTextures( textureName, fScale, fShift, rotation, newTextureName, if((*texEntity)->ResetTextures( textureName, fScale, fShift, rotation, newTextureName,
bResetTextureName, bResetScale, bResetShift, bResetRotation, FALSE)) bResetTextureName, bResetScale, bResetShift, bResetRotation, false))
RebuildEntity(*texEntity); RebuildEntity(*texEntity);
} }
} }
@ -178,5 +174,5 @@ void DMap::ResetTextures( const char* textureName, float fScale[2], float f
void DMap::RebuildEntity(DEntity *ent) void DMap::RebuildEntity(DEntity *ent)
{ {
ent->RemoveFromRadiant(); ent->RemoveFromRadiant();
ent->BuildInRadiant(FALSE); ent->BuildInRadiant(false);
} }

View file

@ -28,13 +28,17 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#pragma once #pragma once
#endif // _MSC_VER > 1000 #endif // _MSC_VER > 1000
#include <list>
class DEntity;
class DMap class DMap
{ {
public: public:
static void RebuildEntity(DEntity* ent); 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 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); void BuildInRadiant(bool bAllowDestruction);
int m_nNextEntity; int m_nNextEntity;
DEntity* GetWorldSpawn(); DEntity* GetWorldSpawn();
@ -43,7 +47,7 @@ public:
DEntity* DMap::GetEntityForID(int ID); DEntity* DMap::GetEntityForID(int ID);
DEntity* AddEntity(char* classname = "worldspawn", int ID = -1); DEntity* AddEntity(char* classname = "worldspawn", int ID = -1);
list<DEntity*> entityList; std::list<DEntity*> entityList;
DMap(); DMap();
virtual ~DMap(); virtual ~DMap();

View file

@ -21,17 +21,13 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// //
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
#include "StdAfx.h"
#include "gtkr_list.h"
#include "str.h"
//#include "DPoint.h"
//#include "DPlane.h"
//#include "DBrush.h"
//#include "DEPair.h"
#include "DPatch.h" #include "DPatch.h"
//#include "DEntity.h"
#include <list>
#include "str.h"
#include "scenelib.h"
#include "ipatch.h"
#include "misc.h" #include "misc.h"
#include "./dialogs/dialogs-gtk.h" #include "./dialogs/dialogs-gtk.h"
@ -73,8 +69,15 @@ void CopyDrawVert(const drawVert_t* in, drawVert_t* out)
VectorCopy(in->xyz, out->xyz); 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 #if 0
int nIndex = g_FuncTable.m_pfnCreatePatchHandle(); int nIndex = g_FuncTable.m_pfnCreatePatchHandle();
//$ FIXME: m_pfnGetPatchHandle //$ FIXME: m_pfnGetPatchHandle
@ -113,7 +116,7 @@ void DPatch::BuildInRadiant(void* entity)
// strcpy(pm->d_texture->name, texture); // strcpy(pm->d_texture->name, texture);
brush_t* brush = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle(); brush_t* brush = (brush_t*)g_FuncTable.m_pfnCreateBrushHandle();
brush->patchBrush = TRUE; brush->patchBrush = true;
brush->pPatch = pm; brush->pPatch = pm;
pm->pSymbiot = brush; pm->pSymbiot = brush;
@ -135,9 +138,9 @@ void DPatch::BuildInRadiant(void* entity)
#endif #endif
} }
void DPatch::LoadFromBrush(scene::Node* brush) void DPatch::LoadFromBrush(scene::Node& brush)
{ {
QER_brush = brush; QER_brush = &brush;
#if 0 #if 0
SetTexture(brush->pPatch->GetShader()); SetTexture(brush->pPatch->GetShader());
@ -160,25 +163,15 @@ void DPatch::LoadFromBrush(scene::Node* brush)
#endif #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) bool DPatch::ResetTextures(const char *oldTextureName, const char *newTextureName)
{ {
if( !oldTextureName || !strcmp(texture, oldTextureName)) if( !oldTextureName || !strcmp(texture, oldTextureName))
{ {
strcpy(texture, newTextureName); 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 Build1dArray(vec3_t* array, drawVert_t points[MAX_PATCH_WIDTH][MAX_PATCH_HEIGHT],
@ -205,8 +198,8 @@ void Build1dArray(vec3_t* array, drawVert_t points[MAX_PATCH_WIDTH][MAX_PATCH_HE
void Print1dArray(vec3_t* array, int size) void Print1dArray(vec3_t* array, int size)
{ {
for(int i = 0; i < size; i++) for(int i = 0; i < size; i++)
Sys_Printf("(" << array[i][0] << " " << array[i][1] << " " << array[i][2] << ")\t"); globalOutputStream() << "(" << array[i][0] << " " << array[i][1] << " " << array[i][2] << ")\t";
Sys_Printf("\n"); globalOutputStream() << "\n";
} }
bool Compare1dArrays(vec3_t* a1, vec3_t* a2, int size) bool Compare1dArrays(vec3_t* a1, vec3_t* a2, int size)
@ -391,9 +384,9 @@ void DPatch::Transpose()
Invert(); 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 i;
int x, y; int x, y;
@ -419,13 +412,13 @@ list<DPatch> DPatch::Split(bool rows, bool cols)
if(cols && width >= 5) 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); patchList2.push_front(*patches2);
} }

View file

@ -24,10 +24,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#if !defined(AFX_DPATCH_H__26C6B083_CE5B_420B_836B_1DDA733C04CE__INCLUDED_) #if !defined(AFX_DPATCH_H__26C6B083_CE5B_420B_836B_1DDA733C04CE__INCLUDED_)
#define 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 #include <list>
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
typedef struct typedef struct
{ {
@ -43,7 +40,10 @@ typedef struct {
float lightmap[2]; float lightmap[2];
} drawVert_t; } drawVert_t;
class Patch; namespace scene
{
class Node;
}
#define MAX_PATCH_WIDTH 16 #define MAX_PATCH_WIDTH 16
#define MAX_PATCH_HEIGHT 16 #define MAX_PATCH_HEIGHT 16
@ -53,16 +53,15 @@ class Patch;
class DPatch class DPatch
{ {
public: public:
list<DPatch> Split(bool rows, bool cols); std::list<DPatch> Split(bool rows, bool cols);
void Transpose(); void Transpose();
void Invert(); void Invert();
DPatch* MergePatches(patch_merge_t merge_info, DPatch* p1, DPatch* p2); DPatch* MergePatches(patch_merge_t merge_info, DPatch* p1, DPatch* p2);
patch_merge_t IsMergable(DPatch* other); patch_merge_t IsMergable(DPatch* other);
bool ResetTextures(const char *oldTextureName, const char *newTextureName); bool ResetTextures(const char *oldTextureName, const char *newTextureName);
void RemoveFromRadiant(void);
scene::Node* QER_brush; scene::Node* QER_brush;
void LoadFromBrush(scene::Node* brush); void LoadFromBrush(scene::Node& brush);
void BuildInRadiant(void* entity = NULL); void BuildInRadiant(scene::Node* entity = NULL);
void SetTexture(const char* textureName); void SetTexture(const char* textureName);
char texture[256]; char texture[256];
int width, height; int width, height;

View file

@ -21,12 +21,11 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// //
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
#include "StdAfx.h" #include "DPlane.h"
#include "gtkr_list.h" #include <list>
#include "DPoint.h" #include "DPoint.h"
#include "DPlane.h"
#include "DWinding.h" #include "DWinding.h"
#include "str.h" #include "str.h"
@ -36,11 +35,11 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// Construction/Destruction // 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 ); MakeNormal( va, vb, vc, normal );
if(VectorNormalize(normal, normal) == 0) // normalizes and returns length 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]); _d = (normal[0]*va[0]) + (normal[1]*va[1]) + (normal[2]*va[2]);
@ -48,7 +47,7 @@ DPlane::DPlane(vec3_t va, vec3_t vb, vec3_t vc, _QERFaceData* texData)
VectorCopy(vb, points[1]); VectorCopy(vb, points[1]);
VectorCopy(vc, points[2]); VectorCopy(vc, points[2]);
m_bChkOk = TRUE; m_bChkOk = true;
if(texData) if(texData)
memcpy(&texInfo, texData, sizeof(_QERFaceData)); memcpy(&texInfo, texData, sizeof(_QERFaceData));
@ -85,7 +84,7 @@ bool DPlane::PlaneIntersection(DPlane *pl1, DPlane *pl2, vec3_t out)
float d = Determinant3x3(a1, a2, a3, b1, b2, b3, c1, c2, c3); float d = Determinant3x3(a1, a2, a3, b1, b2, b3, c1, c2, c3);
if(d == 0) if(d == 0)
return FALSE; return false;
float v1 = _d; float v1 = _d;
float v2 = pl1->_d; float v2 = pl1->_d;
@ -99,23 +98,23 @@ bool DPlane::PlaneIntersection(DPlane *pl1, DPlane *pl2, vec3_t out)
out[1] = d2/d; out[1] = d2/d;
out[2] = d3/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; int cnt = 0;
//list<DPoint *>::const_iterator point=pointList.begin(); //std::list<DPoint *>::const_iterator point=pointList.begin();
for(list<DPoint *>::const_iterator point=pointList.begin(); point!=pointList.end(); point++) for(std::list<DPoint *>::const_iterator point=pointList.begin(); point!=pointList.end(); point++)
{ {
if(fabs(DistanceToPoint((*point)->_pnt)) < MAX_ROUND_ERROR) if(fabs(DistanceToPoint((*point)->_pnt)) < MAX_ROUND_ERROR)
cnt++; cnt++;
if(cnt == 3) if(cnt == 3)
return FALSE; return false;
} }
return TRUE; return true;
} }
bool DPlane::operator == (DPlane& other) bool DPlane::operator == (DPlane& other)
@ -123,12 +122,12 @@ bool DPlane::operator == (DPlane& other)
vec3_t chk; vec3_t chk;
VectorSubtract(other.normal, normal, chk); VectorSubtract(other.normal, normal, chk);
if(fabs(VectorLength(chk)) > MAX_ROUND_ERROR) if(fabs(VectorLength(chk)) > MAX_ROUND_ERROR)
return FALSE; return false;
if(fabs(other._d - _d) > MAX_ROUND_ERROR) if(fabs(other._d - _d) > MAX_ROUND_ERROR)
return FALSE; return false;
return TRUE; return true;
} }
bool DPlane::operator != (DPlane& other) bool DPlane::operator != (DPlane& other)
@ -136,9 +135,9 @@ bool DPlane::operator != (DPlane& other)
vec3_t chk; vec3_t chk;
VectorAdd(other.normal, normal, chk); VectorAdd(other.normal, normal, chk);
if(fabs(VectorLength(chk)) > MAX_ROUND_ERROR) if(fabs(VectorLength(chk)) > MAX_ROUND_ERROR)
return FALSE; return false;
return TRUE; return true;
} }
DWinding* DPlane::BaseWindingForPlane() DWinding* DPlane::BaseWindingForPlane()
@ -161,7 +160,7 @@ DWinding* DPlane::BaseWindingForPlane()
} }
} }
if (x==-1) if (x==-1)
Sys_Printf ("BaseWindingForPlane: no axis found"); globalOutputStream() << "BaseWindingForPlane: no axis found";
VectorCopy (vec3_origin, vup); VectorCopy (vec3_origin, vup);
switch (x) switch (x)
@ -213,7 +212,7 @@ void DPlane::Rebuild()
CrossProduct(v1, v2, normal); CrossProduct(v1, v2, normal);
if(VectorNormalize(normal, normal) == 0) // normalizes and returns length 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]); _d = (normal[0]*points[0][0]) + (normal[1]*points[0][1]) + (normal[2]*points[0][2]);
@ -222,25 +221,30 @@ void DPlane::Rebuild()
VectorCopy(points[2], texInfo.m_p2); VectorCopy(points[2], texInfo.m_p2);
} }
bool DPlane::AddToBrush(Brush *brush) bool DPlane::AddToBrush(scene::Node& brush)
{ {
#if 0 bool changed = false;
if(m_bChkOk || !strcmp(texInfo.m_TextureName, "textures/common/caulk")) if(!(m_bChkOk || !strcmp(m_shader.c_str(), "textures/common/caulk")))
{ {
brush->addPlane(m_p0, m_p1, m_p2, m_texdef, false); m_shader = "textures/common/caulk";
return FALSE; changed = true;
} }
strcpy(texInfo.m_TextureName, "textures/common/caulk"); _QERFaceData faceData;
brush->addPlane(m_p0, m_p1, m_p2, m_texdef, false); faceData.m_p0 = vector3_from_array(points[0]);
#endif faceData.m_p1 = vector3_from_array(points[1]);
return TRUE; 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() 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; vec3_t v1, v2;
VectorSubtract(va, vb, v1); VectorSubtract(va, vb, v1);
@ -248,7 +252,7 @@ DPlane::DPlane(vec3_t va, vec3_t vb, vec3_t vc, const char* textureName, bool bD
CrossProduct(v1, v2, normal); CrossProduct(v1, v2, normal);
if(VectorNormalize(normal, normal) == 0) // normalizes and returns length 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]); _d = (normal[0]*va[0]) + (normal[1]*va[1]) + (normal[2]*va[2]);
@ -256,9 +260,9 @@ DPlane::DPlane(vec3_t va, vec3_t vb, vec3_t vc, const char* textureName, bool bD
VectorCopy(vb, points[1]); VectorCopy(vb, points[1]);
VectorCopy(vc, points[2]); VectorCopy(vc, points[2]);
m_bChkOk = TRUE; m_bChkOk = true;
FillDefaultTexture(&texInfo, points[0], points[1], points[2], textureName); FillDefaultTexture(&texInfo, points[0], points[1], points[2], textureName);
if(bDetail) if(bDetail)
texInfo.m_texdef.contents |= FACE_DETAIL; texInfo.contents |= FACE_DETAIL;
} }

View file

@ -24,7 +24,13 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#if !defined(AFX_DPLANE_H__FC37C021_F0A1_11D4_ACF7_004095A18133__INCLUDED_) #if !defined(AFX_DPLANE_H__FC37C021_F0A1_11D4_ACF7_004095A18133__INCLUDED_)
#define 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 Brush;
class DPoint;
#define FACE_DETAIL 0x8000000 #define FACE_DETAIL 0x8000000
@ -37,27 +43,28 @@ class DWinding;
class DPlane class DPlane
{ {
public: 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(); void ScaleTexture();
DWinding* BaseWindingForPlane(); DWinding* BaseWindingForPlane();
void Rebuild(); void Rebuild();
bool AddToBrush(Brush *brush); bool AddToBrush(scene::Node& brush);
bool operator != (DPlane& other); bool operator != (DPlane& other);
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);; bool PlaneIntersection(DPlane* pl1, DPlane* pl2, vec3_t out);;
vec_t DistanceToPoint(vec3_t pnt); 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() { } DPlane() { }
virtual ~DPlane(); virtual ~DPlane();
bool m_bChkOk; bool m_bChkOk;
_QERFaceData texInfo; _QERFaceData texInfo;
CopiedString m_shader;
vec3_t points[3]; // djbob:do we really need these any more? vec3_t points[3]; // djbob:do we really need these any more?
vec3_t normal; vec3_t normal;
float _d; float _d;

View file

@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// //
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
#include "StdAfx.h"
#include "DPoint.h" #include "DPoint.h"
#include "misc.h"
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Construction/Destruction // Construction/Destruction
@ -47,6 +47,6 @@ bool DPoint::operator ==(vec3_t other)
vec3_t test; vec3_t test;
VectorSubtract(other, _pnt, test); VectorSubtract(other, _pnt, test);
if(fabs(VectorLength(test)) > MAX_ROUND_ERROR) if(fabs(VectorLength(test)) > MAX_ROUND_ERROR)
return FALSE; return false;
return TRUE; return true;
} }

View file

@ -28,6 +28,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#pragma once #pragma once
#endif // _MSC_VER > 1000 #endif // _MSC_VER > 1000
#include "mathlib.h"
class DPoint class DPoint
{ {
public: public:

View file

@ -21,9 +21,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// //
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
#include "StdAfx.h" #include "DShape.h"
#include "gtkr_list.h" #include <list>
#include <time.h>
#include "str.h" #include "str.h"
#include "DPoint.h" #include "DPoint.h"
@ -32,7 +33,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "DEPair.h" #include "DEPair.h"
#include "DPatch.h" #include "DPatch.h"
#include "DEntity.h" #include "DEntity.h"
#include "DShape.h"
//#include "dialogs-gtk.h" //#include "dialogs-gtk.h"
@ -43,7 +43,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// Construction/Destruction // Construction/Destruction
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
bool bFacesAll[6] = {TRUE, TRUE, TRUE, TRUE, TRUE, TRUE}; bool bFacesAll[6] = {true, true, true, true, true, true};
DShape::DShape() DShape::DShape()
{ {
@ -104,16 +104,16 @@ void DShape::BuildRegularPrism(vec3_t min, vec3_t max, int nSides, bool bAlignTo
DBrush* pB = m_Container.GetWorldSpawn()->NewBrush(m_nNextBrush++); DBrush* pB = m_Container.GetWorldSpawn()->NewBrush(m_nNextBrush++);
for(i = 1; i <= nSides; i++) 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(vc[2], vc[1], vc[0], "textures/common/caulk", false);
pB->AddFace(vd[0], vd[1], vd[2], "textures/common/caulk", FALSE); pB->AddFace(vd[0], vd[1], vd[2], "textures/common/caulk", false);
} }
void DShape::Commit() void DShape::Commit()
{ {
m_Container.GetWorldSpawn()->FixBrushes(); 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) void DShape::BuildInversePrism(vec3_t min, vec3_t max, int nSides, bool bAlignTop)
@ -180,11 +180,11 @@ void DShape::BuildInversePrism(vec3_t min, vec3_t max, int nSides, bool bAlignTo
if(top[1] != bottom[1]) // internal line is flat already if true 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-1], top, vb[i-1], "textures/common/caulk", false);
pB->AddFace(va[i], vb[i], bottom, "textures/common/caulk", FALSE); pB->AddFace(va[i], vb[i], bottom, "textures/common/caulk", false);
} // add cut-off planes } // 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 // add internal polygon plane
} }
} }
@ -264,11 +264,11 @@ void DShape::BuildBorderedPrism(vec3_t min, vec3_t max, int nSides, int nBorder,
{ {
DBrush* pB = GetBoundingCube(min, max, "textures/common/caulk"); DBrush* pB = GetBoundingCube(min, max, "textures/common/caulk");
pB->AddFace(origin, vc[i-1], vd[i-1], "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(origin, vd[i], vc[i], "textures/common/caulk", false);
pB->AddFace(vc[i-1], vc[i], vd[i], GetCurrentTexture(), 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(vb[i], va[i], va[i-1], GetCurrentTexture(), false);
} }
} }
@ -343,18 +343,18 @@ DBrush* DShape::GetBoundingCube(vec3_t min, vec3_t max, const char *textureName,
//----- Add Six Cube Faces --------- //----- Add Six Cube Faces ---------
if(bUseFaces[0]) if(bUseFaces[0])
pB->AddFace(v1, v2, v3, textureName, FALSE); pB->AddFace(v1, v2, v3, textureName, false);
if(bUseFaces[1]) if(bUseFaces[1])
pB->AddFace(v1, v3, v6, textureName, FALSE); pB->AddFace(v1, v3, v6, textureName, false);
if(bUseFaces[2]) if(bUseFaces[2])
pB->AddFace(v1, v7, v2, textureName, FALSE); pB->AddFace(v1, v7, v2, textureName, false);
if(bUseFaces[3]) if(bUseFaces[3])
pB->AddFace(v5, v6, v3, textureName, FALSE); pB->AddFace(v5, v6, v3, textureName, false);
if(bUseFaces[4]) if(bUseFaces[4])
pB->AddFace(v5, v2, v7, textureName, FALSE); pB->AddFace(v5, v2, v7, textureName, false);
if(bUseFaces[5]) if(bUseFaces[5])
pB->AddFace(v5, v7, v6, textureName, FALSE); pB->AddFace(v5, v7, v6, textureName, false);
//---------------------------------- //----------------------------------
@ -364,7 +364,7 @@ DBrush* DShape::GetBoundingCube(vec3_t min, vec3_t max, const char *textureName,
bool DShape::BuildPit(vec3_t min, vec3_t max) bool DShape::BuildPit(vec3_t min, vec3_t max)
{ {
if((max[2] - min[2]) < 196) if((max[2] - min[2]) < 196)
return FALSE; return false;
srand(time(NULL)); srand(time(NULL));
@ -465,5 +465,5 @@ bool DShape::BuildPit(vec3_t min, vec3_t max)
// ****** END NODROP ******** // ****** END NODROP ********
return TRUE; return true;
} }

View file

@ -24,13 +24,15 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#if !defined(AFX_DSHAPE_H__0B30B302_9D21_4C2D_836A_61F3C8D4244D__INCLUDED_) #if !defined(AFX_DSHAPE_H__0B30B302_9D21_4C2D_836A_61F3C8D4244D__INCLUDED_)
#define 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 #if _MSC_VER > 1000
#pragma once #pragma once
#endif // _MSC_VER > 1000 #endif // _MSC_VER > 1000
#include "mathlib.h"
#include "DMap.h"
class DBrush;
class DEntity;
// defines for polygon stuff // defines for polygon stuff
#define MAX_POLYGON_FACES 128 #define MAX_POLYGON_FACES 128

View file

@ -17,9 +17,9 @@ License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 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 "str.h"
#include "DPoint.h" #include "DPoint.h"
@ -28,31 +28,33 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "DEPair.h" #include "DEPair.h"
#include "DPatch.h" #include "DPatch.h"
#include "DEntity.h" #include "DEntity.h"
#include "DTrainDrawer.h"
#include "misc.h" #include "misc.h"
#include "funchandlers.h" #include "funchandlers.h"
#include "iglrender.h"
#include "math/matrix.h"
#include "dialogs/dialogs-gtk.h" #include "dialogs/dialogs-gtk.h"
DTrainDrawer::DTrainDrawer() { DTrainDrawer::DTrainDrawer() {
refCount = 1; m_bDisplay = false;
m_bHooked = FALSE;
m_bDisplay = FALSE;
BuildPaths(); BuildPaths();
constructShaders();
GlobalShaderCache().attachRenderable(*this);
} }
DTrainDrawer::~DTrainDrawer(void) { DTrainDrawer::~DTrainDrawer(void) {
if(m_bHooked) GlobalShaderCache().detachRenderable(*this);
UnRegister(); destroyShaders();
ClearPoints(); ClearPoints();
ClearSplines(); ClearSplines();
} }
void DTrainDrawer::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_pointList.clear();
(*deadSpline)->m_vertexList.clear(); (*deadSpline)->m_vertexList.clear();
delete (*deadSpline); delete (*deadSpline);
@ -62,25 +64,13 @@ void DTrainDrawer::ClearSplines() {
} }
void DTrainDrawer::ClearPoints() { 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; delete *deadPoint;
} }
m_pointList.clear(); 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) { void CalculateSpline_r(vec3_t* v, int count, vec3_t out, float tension) {
vec3_t dist; vec3_t dist;
@ -106,93 +96,70 @@ void CalculateSpline_r(vec3_t* v, int count, vec3_t out, float tension) {
delete[] v2; delete[] v2;
} }
void DTrainDrawer::Draw3D() { void DTrainDrawer::render(RenderStateFlags state) const
{
if(!m_bDisplay) { for(std::list<splinePoint_t* >::const_iterator sp = m_splineList.begin(); sp != m_splineList.end(); sp++) {
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++) {
splinePoint_t* pSP = (*sp); splinePoint_t* pSP = (*sp);
__QGLTABLENAME.m_pfn_qglBegin(GL_LINE_STRIP); glBegin(GL_LINE_STRIP);
for(list<DPoint >::const_iterator v = pSP->m_vertexList.begin(); v != pSP->m_vertexList.end(); v++) { for(std::list<DPoint >::const_iterator v = pSP->m_vertexList.begin(); v != pSP->m_vertexList.end(); v++) {
__QGLTABLENAME.m_pfn_qglVertex3fv((*v)._pnt); 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";
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);
}
void DTrainDrawer::destroyShaders()
{
GlobalOpenGLStateLibrary().erase(DTrainDrawer_state_wireframe);
GlobalOpenGLStateLibrary().erase(DTrainDrawer_state_solid);
GlobalShaderCache().release(DTrainDrawer_state_wireframe);
GlobalShaderCache().release(DTrainDrawer_state_solid);
}
void DTrainDrawer::renderSolid(Renderer& renderer, const VolumeTest& volume) const
{
if(!m_bDisplay) { if(!m_bDisplay) {
return; return;
} }
__QGLTABLENAME.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS); renderer.SetState(m_shader_wireframe, Renderer::eWireframeOnly);
renderer.SetState(m_shader_solid, Renderer::eFullMaterials);
__QGLTABLENAME.m_pfn_qglDisable(GL_BLEND); renderer.addRenderable(*this, g_matrix4_identity);
__QGLTABLENAME.m_pfn_qglDisable(GL_LINE_SMOOTH); }
void DTrainDrawer::renderWireframe(Renderer& renderer, const VolumeTest& volume) const
__QGLTABLENAME.m_pfn_qglPushMatrix(); {
renderSolid(renderer, volume);
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);
for(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);
}
__QGLTABLENAME.m_pfn_qglEnd();
}
__QGLTABLENAME.m_pfn_qglPopMatrix();
__QGLTABLENAME.m_pfn_qglPopAttrib();
} }
void AddSplineControl(const char* control, splinePoint_t* pSP) { void AddSplineControl(const char* control, splinePoint_t* pSP) {
@ -263,7 +230,7 @@ void DTrainDrawer::BuildPaths() {
} }
} }
list<splinePoint_t* >::const_iterator sp; std::list<splinePoint_t* >::const_iterator sp;
for(sp = m_splineList.begin(); sp != m_splineList.end(); sp++) { for(sp = m_splineList.begin(); sp != m_splineList.end(); sp++) {
splinePoint_t* pSP = (*sp); splinePoint_t* pSP = (*sp);
@ -278,7 +245,7 @@ void DTrainDrawer::BuildPaths() {
pSP->pTarget = pTarget; 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 ); controlPoint_t* pControl = FindControlPoint( (*cp).strName );
if(!pControl) { if(!pControl) {
Sys_Printf( "couldn't find control %s", (*cp).strName ); Sys_Printf( "couldn't find control %s", (*cp).strName );
@ -306,7 +273,7 @@ void DTrainDrawer::BuildPaths() {
VectorCopy(pSP->point.vOrigin, v[0]); VectorCopy(pSP->point.vOrigin, v[0]);
int i = 1; 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]); VectorCopy((*cp).vOrigin, v[i]);
i++; i++;
} }
@ -350,13 +317,13 @@ splinePoint_t* DTrainDrawer::AddSplinePoint(const char* name, const char* target
controlPoint_t* DTrainDrawer::FindControlPoint(const char* name) 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)) { if(!strcmp(name, (*cp)->strName)) {
return (*cp); 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)) { if(!strcmp(name, (*sp)->point.strName)) {
return &((*sp)->point); return &((*sp)->point);
} }

View file

@ -29,6 +29,15 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#pragma once #pragma once
#endif // _MSC_VER > 1000 #endif // _MSC_VER > 1000
#include <list>
#include "mathlib.h"
#include "irender.h"
#include "renderable.h"
class DPoint;
class Shader;
typedef struct { typedef struct {
char strName[64]; char strName[64];
@ -41,34 +50,33 @@ typedef struct {
char strControl[64]; char strControl[64];
char strTarget[64]; char strTarget[64];
list<controlPoint_t> m_pointList; std::list<controlPoint_t> m_pointList;
list<DPoint> m_vertexList; std::list<DPoint> m_vertexList;
controlPoint_t* pTarget; controlPoint_t* pTarget;
} splinePoint_t; } splinePoint_t;
class DTrainDrawer : class DTrainDrawer : public Renderable, public OpenGLRenderable
public IGL2DWindow,
public IGL3DWindow
{ {
private: private:
list<splinePoint_t*> m_splineList; std::list<splinePoint_t*> m_splineList;
list<controlPoint_t*> m_pointList; std::list<controlPoint_t*> m_pointList;
int refCount;
bool m_bHooked;
bool m_bDisplay; bool m_bDisplay;
Shader* m_shader_wireframe;
Shader* m_shader_solid;
public: public:
void UnRegister();
void Register();
DTrainDrawer(); DTrainDrawer();
virtual ~DTrainDrawer(void); virtual ~DTrainDrawer(void);
void Draw3D(); void render(RenderStateFlags state) const;
void Draw2D(VIEWTYPE vt); void renderSolid(Renderer& renderer, const VolumeTest& volume) const;
void IncRef() { refCount++; } void renderWireframe(Renderer& renderer, const VolumeTest& volume) const;
void DecRef() { refCount--; if (refCount <= 0) delete this; }
void constructShaders();
void destroyShaders();
void ClearSplines(); void ClearSplines();
void ClearPoints(); void ClearPoints();
void BuildPaths(); void BuildPaths();

View file

@ -17,9 +17,9 @@ License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 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 "str.h"
#include "DPoint.h" #include "DPoint.h"
@ -32,17 +32,17 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "ScriptParser.h" #include "ScriptParser.h"
#include "misc.h" #include "misc.h"
#include "DTreePlanter.h"
#include "funchandlers.h" #include "funchandlers.h"
bool DTreePlanter::OnMouseMove(guint32 nFlags, gdouble x, gdouble y) { SignalHandlerResult DTreePlanter::mouseDown(const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers)
return false; {
} if(button != c_buttonLeft)
{
bool DTreePlanter::OnLButtonDown(guint32 nFlags, gdouble x, gdouble y) { return SIGNAL_CONTINUE_EMISSION;
VIEWTYPE vt = m_XYWrapper->GetViewType(); }
VIEWTYPE vt = GlobalRadiant().XYWindow_getViewType();
switch(vt) { switch(vt) {
case XY: case XY:
@ -50,14 +50,14 @@ bool DTreePlanter::OnLButtonDown(guint32 nFlags, gdouble x, gdouble y) {
case YZ: case YZ:
case XZ: case XZ:
default: 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; vhit[2] += m_offset;
char buffer[128]; char buffer[128];
@ -96,7 +96,7 @@ bool DTreePlanter::OnLButtonDown(guint32 nFlags, gdouble x, gdouble y) {
e2.LoadFromEntity(lastEntNum, TRUE); e2.LoadFromEntity(lastEntNum, TRUE);
e2.AddEPair("target", buffer); e2.AddEPair("target", buffer);
e2.RemoveFromRadiant(); e2.RemoveFromRadiant();
e2.BuildInRadiant(FALSE); e2.BuildInRadiant(false);
} }
#endif #endif
} }
@ -121,34 +121,14 @@ bool DTreePlanter::OnLButtonDown(guint32 nFlags, gdouble x, gdouble y) {
e.AddEPair("modelscale", buffer); e.AddEPair("modelscale", buffer);
} }
e.BuildInRadiant( FALSE ); e.BuildInRadiant( false );
} }
if(m_autoLink) { if(m_autoLink) {
DoTrainPathPlot(); DoTrainPathPlot();
} }
return true; return SIGNAL_STOP_EMISSION;
}
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;
} }
bool DTreePlanter::FindDropPoint(vec3_t in, vec3_t out) { bool DTreePlanter::FindDropPoint(vec3_t in, vec3_t out) {
@ -226,7 +206,7 @@ void DTreePlanter::DropEntsToGround( void ) {
sprintf( buffer, "%f %f %f", out[0], out[1], out[2] ); sprintf( buffer, "%f %f %f", out[0], out[1], out[2] );
ent.AddEPair( "origin", buffer ); ent.AddEPair( "origin", buffer );
ent.RemoveFromRadiant(); ent.RemoveFromRadiant();
ent.BuildInRadiant(FALSE); ent.BuildInRadiant(false);
} }
g_FuncTable.m_pfnReleaseSelectedBrushHandles(); g_FuncTable.m_pfnReleaseSelectedBrushHandles();
@ -254,7 +234,7 @@ void DTreePlanter::MakeChain( void ) {
e.AddEPair( "control", buffer ); e.AddEPair( "control", buffer );
} }
e.BuildInRadiant( FALSE ); e.BuildInRadiant( false );
} }
for(i = 0; i < m_linkNum-1; i++) { for(i = 0; i < m_linkNum-1; i++) {
@ -266,7 +246,7 @@ void DTreePlanter::MakeChain( void ) {
sprintf( buffer, "0 %i 0", (i * 64) + 32); sprintf( buffer, "0 %i 0", (i * 64) + 32);
e.AddEPair( "origin", buffer ); e.AddEPair( "origin", buffer );
e.BuildInRadiant( FALSE ); e.BuildInRadiant( false );
} }
} }
@ -290,7 +270,7 @@ void DTreePlanter::SelectChain( void ) {
e.AddEPair( "control", buffer ); e.AddEPair( "control", buffer );
} }
e.BuildInRadiant( FALSE ); e.BuildInRadiant( false );
} }
for(int i = 0; i < m_linkNum-1; i++) { for(int i = 0; i < m_linkNum-1; i++) {
@ -302,6 +282,6 @@ void DTreePlanter::SelectChain( void ) {
sprintf( buffer, "0 %i 0", (i * 64) + 32); sprintf( buffer, "0 %i 0", (i * 64) + 32);
e.AddEPair( "origin", buffer ); e.AddEPair( "origin", buffer );
e.BuildInRadiant( FALSE ); e.BuildInRadiant( false );
}*/ }*/
} }

View file

@ -20,6 +20,14 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#ifndef __DTREE_H__ #ifndef __DTREE_H__
#define __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_QPATH 64
@ -29,23 +37,13 @@ typedef struct treeModel_s {
#define MAX_TP_MODELS 256 #define MAX_TP_MODELS 256
class DTreePlanter : public IWindowListener { class DTreePlanter {
MouseEventHandlerId m_mouseDown;
public: public:
virtual bool OnMouseMove(guint32 nFlags, gdouble x, gdouble y); SignalHandlerResult mouseDown(const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers);
virtual bool OnLButtonDown(guint32 nFlags, gdouble x, gdouble y); typedef Member3<DTreePlanter, const WindowVector&, ButtonIdentifier, ModifierFlags, SignalHandlerResult, &DTreePlanter::mouseDown> MouseDownCaller;
virtual bool OnMButtonDown(guint32 nFlags, gdouble x, gdouble y);
virtual bool OnRButtonDown(guint32 nFlags, gdouble x, gdouble y); DTreePlanter() {
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;
m_numModels = 0; m_numModels = 0;
m_offset = 0; m_offset = 0;
m_maxPitch = 0; m_maxPitch = 0;
@ -57,8 +55,6 @@ public:
m_autoLink = false; m_autoLink = false;
m_linkNum = 0; m_linkNum = 0;
Register();
m_world.LoadSelectedBrushes(); m_world.LoadSelectedBrushes();
char buffer[256]; char buffer[256];
@ -85,9 +81,16 @@ public:
fclose( file ); 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 GT pToken = pScriptParser->GetToken( true )
#define CT if(!*pToken) { return; } #define CT if(!*pToken) { return; }
@ -161,41 +164,16 @@ public:
} while( true ); } 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); bool FindDropPoint(vec3_t in, vec3_t out);
void DropEntsToGround( void ); void DropEntsToGround( void );
void MakeChain( void ); void MakeChain( void );
void SelectChain( void ); void SelectChain( void );
private: private:
IXYWndWrapper* m_XYWrapper;
DEntity m_world; DEntity m_world;
treeModel_t m_trees[MAX_TP_MODELS]; treeModel_t m_trees[MAX_TP_MODELS];
int m_refCount;
int m_numModels; int m_numModels;
int m_offset; int m_offset;
int m_maxPitch; int m_maxPitch;
@ -210,7 +188,6 @@ private:
float m_minScale; float m_minScale;
float m_maxScale; float m_maxScale;
bool m_hooked;
bool m_useScale; bool m_useScale;
bool m_setAngles; bool m_setAngles;
bool m_autoLink; bool m_autoLink;

View file

@ -21,14 +21,16 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// //
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
#include "StdAfx.h" #include "DVisDrawer.h"
#include "gtkr_list.h" #include "iglrender.h"
#include "math/matrix.h"
#include <list>
#include "str.h" #include "str.h"
#include "DPoint.h" #include "DPoint.h"
#include "DWinding.h" #include "DWinding.h"
#include "DVisDrawer.h"
#include "misc.h" #include "misc.h"
#include "funchandlers.h" #include "funchandlers.h"
@ -39,15 +41,16 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
DVisDrawer::DVisDrawer() DVisDrawer::DVisDrawer()
{ {
refCount = 1;
m_bHooked = FALSE;
m_list = NULL; m_list = NULL;
constructShaders();
GlobalShaderCache().attachRenderable(*this);
} }
DVisDrawer::~DVisDrawer() DVisDrawer::~DVisDrawer()
{ {
if(m_bHooked) GlobalShaderCache().detachRenderable(*this);
UnRegister(); destroyShaders();
g_VisView = NULL; g_VisView = NULL;
} }
@ -55,117 +58,73 @@ DVisDrawer::~DVisDrawer()
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Implementation // 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) OpenGLState state;
return; GlobalOpenGLStateLibrary().getDefaultState(state);
state.m_state = RENDER_COLOURWRITE|RENDER_DEPTHWRITE|RENDER_COLOURCHANGE;
state.m_linewidth = 1;
__QGLTABLENAME.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS); GlobalOpenGLStateLibrary().insert(g_state_wireframe, state);
__QGLTABLENAME.m_pfn_qglDisable(GL_BLEND); GlobalOpenGLStateLibrary().getDefaultState(state);
__QGLTABLENAME.m_pfn_qglDisable(GL_LINE_SMOOTH); state.m_state = RENDER_FILL|RENDER_BLEND|RENDER_COLOURWRITE|RENDER_COLOURCHANGE|RENDER_SMOOTH|RENDER_DEPTHWRITE;
__QGLTABLENAME.m_pfn_qglPushMatrix(); GlobalOpenGLStateLibrary().insert(g_state_solid, state);
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); m_shader_solid = GlobalShaderCache().capture(g_state_solid);
__QGLTABLENAME.m_pfn_qglColor4f(1.0f, 0.0f, 0.0f, 0.5f); m_shader_wireframe = GlobalShaderCache().capture(g_state_wireframe);
}
__QGLTABLENAME.m_pfn_qglEnable(GL_BLEND); void DVisDrawer::destroyShaders()
__QGLTABLENAME.m_pfn_qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); {
__QGLTABLENAME.m_pfn_qglDisable(GL_POLYGON_SMOOTH); GlobalShaderCache().release(g_state_solid);
GlobalShaderCache().release(g_state_wireframe);
__QGLTABLENAME.m_pfn_qglDepthFunc(GL_ALWAYS); GlobalOpenGLStateLibrary().erase(g_state_solid);
GlobalOpenGLStateLibrary().erase(g_state_wireframe);
}
void DVisDrawer::render(RenderStateFlags state) const
{
//bleh //bleh
list<DWinding *>::const_iterator l=m_list->begin(); std::list<DWinding *>::const_iterator l=m_list->begin();
for(; l != m_list->end(); l++) for(; l != m_list->end(); l++)
{ {
DWinding* w = *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++) { 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) if(!m_list)
return; return;
__QGLTABLENAME.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS); renderer.SetState(m_shader_wireframe, Renderer::eWireframeOnly);
__QGLTABLENAME.m_pfn_qglColor4f(1.0, 0.0, 0.0, 0.5f); renderer.addRenderable(*this, g_matrix4_identity);
// __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);
__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();
} }
void DVisDrawer::Register() void DVisDrawer::renderSolid(Renderer& renderer, const VolumeTest& volume) const
{ {
__QGLTABLENAME.m_pfnHookGL2DWindow( this ); if(!m_list)
__QGLTABLENAME.m_pfnHookGL3DWindow( this ); return;
m_bHooked = TRUE;
}
void DVisDrawer::UnRegister() renderer.SetState(m_shader_solid, Renderer::eWireframeOnly);
{ renderer.SetState(m_shader_solid, Renderer::eFullMaterials);
__QGLTABLENAME.m_pfnUnHookGL2DWindow( this );
__QGLTABLENAME.m_pfnUnHookGL3DWindow( this ); renderer.addRenderable(*this, g_matrix4_identity);
m_bHooked = FALSE;
} }
void DVisDrawer::SetList(std::list<DWinding*> *pointList) void DVisDrawer::SetList(std::list<DWinding*> *pointList)
@ -178,7 +137,7 @@ void DVisDrawer::SetList(std::list<DWinding*> *pointList)
void DVisDrawer::ClearPoints() 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++) for(; deadPoint!=m_list->end(); deadPoint++)
delete *deadPoint; delete *deadPoint;
m_list->clear(); m_list->clear();

View file

@ -29,28 +29,34 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#pragma once #pragma once
#endif // _MSC_VER > 1000 #endif // _MSC_VER > 1000
class DVisDrawer : #include <list>
public IGL2DWindow, #include "renderable.h"
public IGL3DWindow #include "irender.h"
#include "DWinding.h"
class DVisDrawer : public Renderable, public OpenGLRenderable
{ {
Shader* m_shader_solid;
Shader* m_shader_wireframe;
public: public:
DVisDrawer(); DVisDrawer();
virtual ~DVisDrawer(); virtual ~DVisDrawer();
protected: protected:
list<DWinding*>* m_list; std::list<DWinding*>* m_list;
int refCount; int refCount;
public: public:
void ClearPoints(); void ClearPoints();
void SetList(list<DWinding*>* pointList); void SetList(std::list<DWinding*>* pointList);
void UnRegister();
void Register(); void render(RenderStateFlags state) const;
void Draw3D(); void renderSolid(Renderer& renderer, const VolumeTest& volume) const;
void Draw2D(VIEWTYPE vt); void renderWireframe(Renderer& renderer, const VolumeTest& volume) const;
void IncRef() { refCount++; }
void DecRef() { refCount--; if (refCount <= 0) delete this; } void constructShaders();
void destroyShaders();
bool m_bHooked;
}; };
#endif // !defined(AFX_VISDRAWER_H__6E36062A_EF0B_11D4_ACF7_004095A18133__INCLUDED_) #endif // !defined(AFX_VISDRAWER_H__6E36062A_EF0B_11D4_ACF7_004095A18133__INCLUDED_)

View file

@ -21,12 +21,11 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// //
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
#include "StdAfx.h" #include "DWinding.h"
#include "gtkr_list.h" #include <list>
#include "DPoint.h" #include "DPoint.h"
#include "DWinding.h"
#include "DPlane.h" #include "DPlane.h"
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
@ -157,8 +156,8 @@ DWinding* DWinding::CopyWinding()
int DWinding::WindingOnPlaneSide(vec3_t normal, vec_t dist) int DWinding::WindingOnPlaneSide(vec3_t normal, vec_t dist)
{ {
bool front = FALSE; bool front = false;
bool back = FALSE; bool back = false;
for (int i = 0; i < numpoints; i++) for (int i = 0; i < numpoints; i++)
{ {
@ -167,14 +166,14 @@ int DWinding::WindingOnPlaneSide(vec3_t normal, vec_t dist)
{ {
if (front) if (front)
return SIDE_CROSS; return SIDE_CROSS;
back = TRUE; back = true;
continue; continue;
} }
if (d > ON_EPSILON) if (d > ON_EPSILON)
{ {
if (back) if (back)
return SIDE_CROSS; return SIDE_CROSS;
front = TRUE; front = true;
continue; continue;
} }
} }
@ -193,11 +192,11 @@ void DWinding::CheckWinding()
vec3_t dir, edgenormal; vec3_t dir, edgenormal;
if (numpoints < 3) if (numpoints < 3)
Sys_Printf ("CheckWinding: %i points", numpoints); globalOutputStream() << "CheckWinding: " << numpoints << " points\n";
vec_t area = WindingArea(); vec_t area = WindingArea();
if (area < 1) if (area < 1)
Sys_Printf ("CheckWinding: %f area", area); globalOutputStream() << "CheckWinding: " << area << " area\n";
DPlane* wPlane = WindingPlane (); DPlane* wPlane = WindingPlane ();
int i; int i;
@ -208,21 +207,21 @@ void DWinding::CheckWinding()
int j; int j;
for (j = 0; j < 3; j++) for (j = 0; j < 3; j++)
if (p1[j] > BOGUS_RANGE || p1[j] < -BOGUS_RANGE) 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; j = i + 1 == numpoints ? 0 : i + 1;
// check the point is on the face plane // check the point is on the face plane
vec_t d = DotProduct (p1, wPlane->normal) - wPlane->_d; vec_t d = DotProduct (p1, wPlane->normal) - wPlane->_d;
if (d < -ON_EPSILON || d > ON_EPSILON) if (d < -ON_EPSILON || d > ON_EPSILON)
Sys_Printf ("CheckWinding: point off plane"); globalOutputStream() << "CheckWinding: point off plane\n";
// check the edge isnt degenerate // check the edge isnt degenerate
p2 = p[j]; p2 = p[j];
VectorSubtract (p2, p1, dir); VectorSubtract (p2, p1, dir);
if (VectorLength (dir) < ON_EPSILON) if (VectorLength (dir) < ON_EPSILON)
Sys_Printf ("CheckWinding: degenerate edge"); globalOutputStream() << "CheckWinding: degenerate edge\n";
CrossProduct (wPlane->normal, dir, edgenormal); CrossProduct (wPlane->normal, dir, edgenormal);
VectorNormalize (edgenormal, edgenormal); VectorNormalize (edgenormal, edgenormal);
@ -236,7 +235,7 @@ void DWinding::CheckWinding()
d = DotProduct (p[j], edgenormal); d = DotProduct (p[j], edgenormal);
if (d > (edgedist + ON_EPSILON)) if (d > (edgedist + ON_EPSILON))
Sys_Printf ("CheckWinding: non-convex"); globalOutputStream() << "CheckWinding: non-convex\n";
} }
} }
@ -287,11 +286,11 @@ bool DWinding::ChopWindingInPlace(DPlane* chopPlane, vec_t epsilon)
if (!counts[0]) if (!counts[0])
{ {
delete this; delete this;
return FALSE; return false;
} }
if (!counts[1]) if (!counts[1])
return TRUE; return true;
int maxpts = numpoints+4; // cant use counts[0]+2 because int maxpts = numpoints+4; // cant use counts[0]+2 because
// of fp grouping errors // of fp grouping errors
@ -339,15 +338,15 @@ bool DWinding::ChopWindingInPlace(DPlane* chopPlane, vec_t epsilon)
} }
if (f->numpoints > maxpts) if (f->numpoints > maxpts)
Sys_Printf ("ClipWinding: points exceeded estimate"); globalOutputStream() << "ClipWinding: points exceeded estimate\n";
if (f->numpoints > MAX_POINTS_ON_WINDING) if (f->numpoints > MAX_POINTS_ON_WINDING)
Sys_Printf ("ClipWinding: MAX_POINTS_ON_WINDING"); globalOutputStream() << "ClipWinding: MAX_POINTS_ON_WINDING\n";
delete[] p; delete[] p;
p = f->p; p = f->p;
f->p = NULL; f->p = NULL;
delete f; delete f;
return TRUE; return true;
} }
void DWinding::ClipWindingEpsilon(DPlane* chopPlane, vec_t epsilon, DWinding **front, DWinding **back) void DWinding::ClipWindingEpsilon(DPlane* chopPlane, vec_t epsilon, DWinding **front, DWinding **back)
@ -455,9 +454,9 @@ void DWinding::ClipWindingEpsilon(DPlane* chopPlane, vec_t epsilon, DWinding **f
} }
if (f->numpoints > maxpts || b->numpoints > maxpts) 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) 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) bool DWinding::ChopWinding(DPlane* chopPlane)
@ -473,7 +472,7 @@ bool DWinding::ChopWinding(DPlane* chopPlane)
if(!f) if(!f)
{ {
delete this; delete this;
return FALSE; return false;
} }
delete[] p; delete[] p;
@ -482,5 +481,5 @@ bool DWinding::ChopWinding(DPlane* chopPlane)
numpoints = f->numpoints; numpoints = f->numpoints;
delete f; delete f;
return TRUE; return true;
} }

View file

@ -28,6 +28,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#pragma once #pragma once
#endif // _MSC_VER > 1000 #endif // _MSC_VER > 1000
#include "mathlib.h"
class DPlane; class DPlane;
class DWinding class DWinding

View file

@ -17,7 +17,6 @@ License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "StdAfx.h"
#include "ScriptParser.h" #include "ScriptParser.h"
CScriptParser::CScriptParser(void): CScriptParser::CScriptParser(void):

View file

@ -20,122 +20,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#ifndef __STDAFX_BOBTOOLZ__ #ifndef __STDAFX_BOBTOOLZ__
#define __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 #endif

View file

@ -19,17 +19,22 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "libxml/parser.h" #include "libxml/parser.h"
#include "StdAfx.h"
#include "str.h" #include "str.h"
//#include "gtkr_list.h"
#include "funchandlers.h" #include "funchandlers.h"
//#include "misc.h"
#include "dialogs/dialogs-gtk.h" #include "dialogs/dialogs-gtk.h"
#include "../../libs/cmdlib.h" #include "../../libs/cmdlib.h"
void BobToolz_construct()
{
}
void BobToolz_destroy()
{
}
// Radiant function table // Radiant function table
_QERFuncTable_1 __QERTABLENAME; _QERFuncTable_1 __QERTABLENAME;
_QERShadersTable __SHADERSTABLENAME; // vvvvvvvvvvvvvvvvvvvv _QERShadersTable __SHADERSTABLENAME; // vvvvvvvvvvvvvvvvvvvv
@ -71,31 +76,31 @@ extern "C" const char* QERPlug_GetCommandList() {
extern "C" void QERPlug_Dispatch (const char *p, vec3_t vMin, vec3_t vMax, bool bSingleBrush) { extern "C" void QERPlug_Dispatch (const char *p, vec3_t vMin, vec3_t vMax, bool bSingleBrush) {
LoadLists(); LoadLists();
if( !stricmp( p, "brush cleanup" ) ) { if( string_equal_nocase( p, "brush cleanup" ) ) {
DoFixBrushes(); DoFixBrushes();
} else if( !stricmp( p, "polygon builder" ) ) { } else if( string_equal_nocase( p, "polygon builder" ) ) {
DoPolygonsTB(); DoPolygonsTB();
} else if( !stricmp( p, "caulk selection" ) ) { } else if( string_equal_nocase( p, "caulk selection" ) ) {
DoCaulkSelection(); DoCaulkSelection();
} else if( !stricmp( p, "tree planter" ) ) { } else if( string_equal_nocase( p, "tree planter" ) ) {
DoTreePlanter(); DoTreePlanter();
} else if( !stricmp( p, "plot splines" ) ) { } else if( string_equal_nocase( p, "plot splines" ) ) {
DoTrainPathPlot(); DoTrainPathPlot();
} else if( !stricmp( p, "drop entity" ) ) { } else if( string_equal_nocase( p, "drop entity" ) ) {
DoDropEnts(); DoDropEnts();
} else if( !stricmp( p, "merge patches" ) ) { } else if( string_equal_nocase( p, "merge patches" ) ) {
DoMergePatches(); DoMergePatches();
} else if( !stricmp( p, "split patches" ) ) { } else if( string_equal_nocase( p, "split patches" ) ) {
DoSplitPatch(); DoSplitPatch();
} else if( !stricmp( p, "turn edge" ) ) { } else if( string_equal_nocase( p, "turn edge" ) ) {
DoFlipTerrain(); DoFlipTerrain();
} else if( !stricmp(p, "reset textures...") ) { } else if( string_equal_nocase(p, "reset textures...") ) {
DoResetTextures(); DoResetTextures();
} else if( !stricmp(p, "pitomatic") ) { } else if( string_equal_nocase(p, "pitomatic") ) {
DoPitBuilder(); DoPitBuilder();
} else if( !stricmp(p, "vis viewer") ) { } else if( string_equal_nocase(p, "vis viewer") ) {
DoVisAnalyse(); DoVisAnalyse();
} else if( !stricmp(p, "about...") ) { } else if( string_equal_nocase(p, "about...") ) {
DoMessageBox(PLUGIN_ABOUT, "About", eMB_OK); DoMessageBox(PLUGIN_ABOUT, "About", eMB_OK);
} }
} }
@ -221,6 +226,7 @@ public:
virtual ~CSynapseClientBobtoolz() { } virtual ~CSynapseClientBobtoolz() { }
}; };
#define BOBTOOLZ_MINOR "bobtoolz"
CSynapseServer* g_pSynapseServer = NULL; CSynapseServer* g_pSynapseServer = NULL;
CSynapseClientBobtoolz g_SynapseClient; CSynapseClientBobtoolz g_SynapseClient;
@ -288,11 +294,3 @@ const char* CSynapseClientBobtoolz::GetInfo()
return "bobToolz module built " __DATE__ " " RADIANT_VERSION; 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;
}

View file

@ -5,4 +5,4 @@ LIBRARY "bobToolz"
EXPORTS EXPORTS
; Explicit exports can go here ; Explicit exports can go here
Synapse_EnumerateInterfaces @1 Radiant_RegisterModules @1

View file

@ -1,7 +1,6 @@
#include "StdAfx.h"
#include "./dialogs/dialogs-gtk.h"
#include "bsploader.h" #include "bsploader.h"
#include "../../libs/cmdlib.h" #include "dialogs/dialogs-gtk.h"
#include "cmdlib.h"
int numnodes; int numnodes;
int numplanes; int numplanes;
@ -72,15 +71,21 @@ bool LoadFile( const char *filename, byte **bufferptr)
return true; 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; return l;
} }
float LittleFloat (float 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; return l;
}*/ }
/* /*
============= =============

View file

@ -1,3 +1,6 @@
#include "mathlib.h"
#define LUMP_ENTITIES 0 #define LUMP_ENTITIES 0
#define LUMP_SHADERS 1 #define LUMP_SHADERS 1
#define LUMP_PLANES 2 #define LUMP_PLANES 2

View file

@ -17,9 +17,12 @@ License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "StdAfx.h"
#include "CPortals.h" #include "CPortals.h"
//#include "misc.h"
#include <string.h>
#include <math.h>
#include "misc.h"
#define LINE_BUF 1000 #define LINE_BUF 1000
#define MSG_PREFIX "bobToolz plugin: " #define MSG_PREFIX "bobToolz plugin: "
@ -60,7 +63,7 @@ bool CBspPortal::Build(char *def, unsigned int pointCnt, bool bInverse)
point_count = pointCnt; point_count = pointCnt;
if(point_count < 3) if(point_count < 3)
return FALSE; return false;
point = new CBspPoint[point_count]; point = new CBspPoint[point_count];
@ -69,7 +72,7 @@ bool CBspPortal::Build(char *def, unsigned int pointCnt, bool bInverse)
for(; *c != 0 && *c != '('; c++); for(; *c != 0 && *c != '('; c++);
if(*c == 0) if(*c == 0)
return FALSE; return false;
c++; c++;
@ -86,7 +89,7 @@ bool CBspPortal::Build(char *def, unsigned int pointCnt, bool bInverse)
ClampFloat(&point[x].p[2]); ClampFloat(&point[x].p[2]);
} }
return TRUE; return true;
} }
CPortals::CPortals() CPortals::CPortals()
@ -115,7 +118,7 @@ void CPortals::Load()
Purge(); Purge();
Sys_Printf(MSG_PREFIX "Loading portal file %s.\n", fn); globalOutputStream() << MSG_PREFIX "Loading portal file " << fn << ".\n";
FILE *in; FILE *in;
@ -123,7 +126,7 @@ void CPortals::Load()
if(in == NULL) if(in == NULL)
{ {
Sys_Printf(" ERROR - could not open file.\n"); globalOutputStream() << " ERROR - could not open file.\n";
return; return;
} }
@ -132,7 +135,7 @@ void CPortals::Load()
{ {
fclose(in); fclose(in);
Sys_Printf(" ERROR - File ended prematurely.\n"); globalOutputStream() << " ERROR - File ended prematurely.\n";
return; return;
} }
@ -141,7 +144,7 @@ void CPortals::Load()
{ {
fclose(in); 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; return;
} }
@ -150,7 +153,7 @@ void CPortals::Load()
{ {
fclose(in); fclose(in);
Sys_Printf(" ERROR - File ended prematurely.\n"); globalOutputStream() << " ERROR - File ended prematurely.\n";
return; return;
} }
@ -163,7 +166,7 @@ void CPortals::Load()
node_count = 0; node_count = 0;
Sys_Printf(" ERROR - Extreme number of nodes, aborting.\n"); globalOutputStream() << " ERROR - Extreme number of nodes, aborting.\n";
return; return;
} }
@ -174,7 +177,7 @@ void CPortals::Load()
node_count = 0; node_count = 0;
Sys_Printf(" ERROR - File ended prematurely.\n"); globalOutputStream() << " ERROR - File ended prematurely.\n";
return; return;
} }
@ -188,7 +191,7 @@ void CPortals::Load()
node_count = 0; node_count = 0;
Sys_Printf(" ERROR - File ended prematurely.\n"); globalOutputStream() << " ERROR - File ended prematurely.\n";
return; return;
} }
@ -207,7 +210,7 @@ void CPortals::Load()
node_count = 0; node_count = 0;
Sys_Printf(" ERROR - File ended prematurely.\n"); globalOutputStream() << " ERROR - File ended prematurely.\n";
return; return;
} }
@ -227,7 +230,7 @@ void CPortals::Load()
node_count = 0; node_count = 0;
Sys_Printf(" ERROR - File ended prematurely.\n"); globalOutputStream() << " ERROR - File ended prematurely.\n";
return; return;
} }
@ -259,7 +262,7 @@ void CPortals::Load()
Purge(); 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; return;
} }
@ -267,24 +270,24 @@ void CPortals::Load()
unsigned int pCount, node1, node2; unsigned int pCount, node1, node2;
sscanf(buf, "%u %u %u", &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); fclose(in);
Purge(); 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; return;
} }
if(!node[node2].AddPortal(buf, pCount, TRUE)) if(!node[node2].AddPortal(buf, pCount, true))
{ {
fclose(in); fclose(in);
Purge(); 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; return;
} }
@ -298,7 +301,7 @@ void CPortals::Load()
Purge(); 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; return;
} }
@ -306,13 +309,13 @@ void CPortals::Load()
unsigned int pCount, node1; unsigned int pCount, node1;
sscanf(buf, "%u %u", &pCount, &node1); sscanf(buf, "%u %u", &pCount, &node1);
if(!node[node1].AddPortal(buf, pCount, FALSE)) if(!node[node1].AddPortal(buf, pCount, false))
{ {
fclose(in); fclose(in);
Purge(); 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; return;
} }

View file

@ -17,14 +17,11 @@ License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "../StdAfx.h"
#include "dialogs-gtk.h" #include "dialogs-gtk.h"
#include "../funchandlers.h" #include "../funchandlers.h"
#include "str.h" #include "str.h"
#include "gtkr_list.h" #include <list>
#include "../lists.h" #include "../lists.h"
#include "../misc.h" #include "../misc.h"

View file

@ -17,6 +17,11 @@ License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 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{ struct BuildStairsRS{
char mainTexture[256]; char mainTexture[256];
char riserTexture[256]; char riserTexture[256];
@ -80,6 +85,8 @@ struct PathPlotterRS{
bool bShowExtra; bool bShowExtra;
}; };
typedef struct _GtkWidget GtkWidget;
struct TwinWidget{ struct TwinWidget{
GtkWidget* one; GtkWidget* one;
GtkWidget* two; GtkWidget* two;
@ -96,3 +103,5 @@ EMessageBoxReturn DoCTFColourChangeBox();
EMessageBoxReturn DoTrainThingBox (TrainThingRS* rs); EMessageBoxReturn DoTrainThingBox (TrainThingRS* rs);
//GtkWidget* GetProgressWindow(char* title, GtkProgressBar* feedback); //GtkWidget* GetProgressWindow(char* title, GtkProgressBar* feedback);
#endif

View file

@ -17,7 +17,7 @@ License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "StdAfx.h" #include "funchandlers.h"
#ifdef WIN32 #ifdef WIN32
#pragma warning(disable : 4786) #pragma warning(disable : 4786)
@ -25,7 +25,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "dialogs/dialogs-gtk.h" #include "dialogs/dialogs-gtk.h"
#include "gtkr_list.h" #include <list>
#include "str.h" #include "str.h"
#include "DPoint.h" #include "DPoint.h"
@ -45,13 +45,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "shapes.h" #include "shapes.h"
#include "lists.h" #include "lists.h"
#include "funchandlers.h"
#include "visfind.h" #include "visfind.h"
#include "iundo.h" #include "iundo.h"
#include "refcounted_ptr.h"
#include <vector> #include <vector>
#include <list> #include <list>
#include <map> #include <map>
@ -60,8 +57,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "scenelib.h" #include "scenelib.h"
// for autocaulk // for autocaulk
list<Str> exclusionList; // whole brush exclusion std::list<Str> exclusionList; // whole brush exclusion
list<Str> exclusionList_Face; // single face exclusion std::list<Str> exclusionList_Face; // single face exclusion
bool el1Loaded = FALSE; bool el1Loaded = FALSE;
bool el2Loaded = FALSE; bool el2Loaded = FALSE;
@ -166,7 +163,7 @@ void DoPolygons()
VectorSubtract(instance.aabb_world().origin, instance.aabb_world().extents, vMin); VectorSubtract(instance.aabb_world().origin, instance.aabb_world().extents, vMin);
VectorAdd(instance.aabb_world().origin, instance.aabb_world().extents, vMax); 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) if(rs.bInverse)
@ -269,7 +266,7 @@ void DoBuildStairs()
{ {
{ {
scene::Instance& instance = GlobalSelectionSystem().ultimateSelected(); 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 // Get Step Count
@ -340,7 +337,7 @@ void DoBuildDoors()
scene::Instance& instance = GlobalSelectionSystem().ultimateSelected(); scene::Instance& instance = GlobalSelectionSystem().ultimateSelected();
VectorSubtract(instance.aabb_world().origin, instance.aabb_world().extents, vMin); VectorSubtract(instance.aabb_world().origin, instance.aabb_world().extents, vMin);
VectorAdd(instance.aabb_world().origin, instance.aabb_world().extents, vMax); 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, BuildDoorsX2(vMin, vMax,
@ -371,40 +368,11 @@ void DoPathPlotter()
return; return;
} }
scene::Instance& instance = GlobalSelectionSystem().ultimateSelected(); Entity* entity = Node_getEntity(GlobalSelectionSystem().ultimateSelected().path().top());
if(entity != 0)
DEntity world; {
world.LoadEPairList(instance.path().top()->m_entity); DBobView_setEntity(*entity, rs.fMultiplier, rs.nPoints, rs.fGravity, rs.bNoUpdate, rs.bShowExtra);
}
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);
} }
void DoPitBuilder() void DoPitBuilder()
@ -428,7 +396,7 @@ void DoPitBuilder()
{ {
pit.Commit(); pit.Commit();
instance.path().parent()->m_traverse->erase(instance.path().top()); Node_getTraversable(instance.path().parent())->erase(instance.path().top());
} }
else else
DoMessageBox("Failed To Make Pit\nTry Making The Brush Bigger", "Error", eMB_OK); DoMessageBox("Failed To Make Pit\nTry Making The Brush Bigger", "Error", eMB_OK);
@ -450,6 +418,9 @@ void DoMergePatches()
scene::Node* patches[2]; scene::Node* patches[2];
patches[0] = GlobalSelectionSystem().ultimateSelected().path().top(); patches[0] = GlobalSelectionSystem().ultimateSelected().path().top();
patches[1] = GlobalSelectionSystem().penultimateSelected().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++) for (i = 0; i < 2; i++)
{ {
@ -488,8 +459,8 @@ void DoMergePatches()
{ {
} else } else
{ {
mrgPatches[0].RemoveFromRadiant(); Node_getTraversable(*ents[0])->erase(*patches[0]);
mrgPatches[1].RemoveFromRadiant(); Node_getTraversable(*ents[1])->erase(*patches[1]);
newPatch->BuildInRadiant(); newPatch->BuildInRadiant();
delete newPatch; delete newPatch;
@ -516,8 +487,8 @@ void DoSplitPatch() {
patch.LoadFromBrush(node); patch.LoadFromBrush(node);
list<DPatch> patchList = patch.Split( true, true ); std::list<DPatch> patchList = patch.Split( true, true );
for(list<DPatch>::iterator patches = patchList.begin(); patches != patchList.end(); patches++) { for(std::list<DPatch>::iterator patches = patchList.begin(); patches != patchList.end(); patches++) {
(*patches).BuildInRadiant(); (*patches).BuildInRadiant();
} }
@ -568,7 +539,7 @@ void DoVisAnalyse()
char* ext = strrchr(filename, '.')+1; char* ext = strrchr(filename, '.')+1;
strcpy(ext, "bsp");// rename the extension strcpy(ext, "bsp");// rename the extension
list<DWinding*> *pointList = BuildTrace(filename, origin); std::list<DWinding*> *pointList = BuildTrace(filename, origin);
if(!g_VisView) if(!g_VisView)
{ {
@ -662,7 +633,7 @@ void DoFlipTerrain() {
ents[1] = GlobalSelectionSystem().penultimateSelected().path().parent(); ents[1] = GlobalSelectionSystem().penultimateSelected().path().parent();
for( i = 0; i < 2; i++ ) { for( i = 0; i < 2; i++ ) {
Brushes[i].RemoveFromRadiant(); Node_getTraversable(*ents[i])->erase(*brushes[i]);
} }

View file

@ -39,8 +39,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "DShape.h" #include "DShape.h"
// for autocaulk // for autocaulk
list<Str> exclusionList; // whole brush exclusion std::list<Str> exclusionList; // whole brush exclusion
list<Str> exclusionList_Face; // single face exclusion std::list<Str> exclusionList_Face; // single face exclusion
BOOL el1Loaded; BOOL el1Loaded;
BOOL el2Loaded; BOOL el2Loaded;

View file

@ -17,19 +17,17 @@ License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "StdAfx.h" #include "lists.h"
#ifdef WIN32 #ifdef WIN32
#pragma warning(disable : 4786) #pragma warning(disable : 4786)
#endif #endif
#include "gtkr_list.h" #include <glib/glist.h>
#include "str.h"
#include "lists.h"
#include "misc.h" #include "misc.h"
bool LoadExclusionList(char* filename, list<Str>* exclusionList) bool LoadExclusionList(char* filename, std::list<Str>* exclusionList)
{ {
FILE* eFile = fopen(filename, "r"); FILE* eFile = fopen(filename, "r");
if(eFile) if(eFile)
@ -52,7 +50,7 @@ bool LoadExclusionList(char* filename, list<Str>* exclusionList)
return TRUE; return TRUE;
} }
Sys_ERROR("Failed To Load Exclusion List: %s\n", filename); globalErrorStream() << "Failed To Load Exclusion List: " << filename << "\n";
return FALSE; return FALSE;
} }

View file

@ -17,5 +17,9 @@ License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 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); bool LoadGList(char* filename, GList** loadlist);

View file

@ -17,13 +17,11 @@ License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "StdAfx.h"
#include "gtkr_list.h"
#include "str.h"
#include "misc.h" #include "misc.h"
#include <list>
#include "str.h"
#include "DPoint.h" #include "DPoint.h"
#include "DPlane.h" #include "DPlane.h"
#include "DBrush.h" #include "DBrush.h"
@ -39,8 +37,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#endif #endif
#include "iundo.h" #include "iundo.h"
#include "qerplugin.h"
#include "refcounted_ptr.h"
#include <vector> #include <vector>
#include <list> #include <list>
@ -61,7 +58,7 @@ char g_CurrentTexture[256] = "";
void ReadCurrentTexture() void ReadCurrentTexture()
{ {
const char* textureName = g_FuncTable.m_pfnGetCurrentTexture(); const char* textureName = GlobalRadiant().TextureBrowser_getSelectedShader();
strcpy(g_CurrentTexture, textureName); strcpy(g_CurrentTexture, textureName);
} }
@ -152,29 +149,6 @@ char* TranslateString (char *buf)
return buf2; 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) char* UnixToDosPath(char* path)
{ {
@ -289,7 +263,7 @@ void StartBSP()
Q_Exec( command, TRUE ); 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 // yes, we could just use -fulldetail option, but, as SPOG said
// it'd be faster without all the hint, donotenter etc textures and // it'd be faster without all the hint, donotenter etc textures and
@ -347,6 +321,31 @@ void BuildMiniPrt(list<Str>* exclusionList)
StartBSP(); 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) scene::Path* FindEntityFromTargetname(const char* targetname, int* entNum)
{ {
#if 0 #if 0
@ -364,7 +363,7 @@ scene::Path* FindEntityFromTargetname(const char* targetname, int* entNum)
DEPair* tn = world.FindEPairByKey("targetname"); DEPair* tn = world.FindEPairByKey("targetname");
if(tn) if(tn)
{ {
if(!stricmp(tn->value, targetname)) { if(string_equal_nocase(tn->value, targetname)) {
if(entNum) { if(entNum) {
*entNum = i; *entNum = i;
} }
@ -388,9 +387,9 @@ void FillDefaultTexture(_QERFaceData* faceData, vec3_t va, vec3_t vb, vec3_t vc,
faceData->m_texdef.flags = 0; faceData->m_texdef.flags = 0;
faceData->m_texdef.value = 0; faceData->m_texdef.value = 0;
if(*texture) if(*texture)
faceData->m_texdef.SetName(texture); faceData->m_shader = texture;
else else
faceData->m_texdef.SetName("textures/common/caulk"); faceData->m_shader = "textures/common/caulk";
VectorCopy(va, faceData->m_p0); VectorCopy(va, faceData->m_p0);
VectorCopy(vb, faceData->m_p1); VectorCopy(vb, faceData->m_p1);
VectorCopy(vc, faceData->m_p2); VectorCopy(vc, faceData->m_p2);
@ -422,9 +421,19 @@ vec_t Min(vec_t a, vec_t b)
return b; 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; vec3_t v1, v2;
VectorSubtract(va, vb, v1); VectorSubtract(va, vb, v1);
VectorSubtract(vc, vb, v2); VectorSubtract(vc, vb, v2);
CrossProduct(v1, v2, out); 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;
}

View file

@ -17,16 +17,24 @@ License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 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); vec_t Min(vec_t a, vec_t b);
// reads current texture into global, returns pointer to it // reads current texture into global, returns pointer to it
const char* GetCurrentTexture(); 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(std::list<Str>* exclusionList);
void BuildMiniPrt(list<Str>* exclusionList);
void MoveBlock(int dir, vec3_t min, vec3_t max, float dist); void MoveBlock(int dir, vec3_t min, vec3_t max, float dist);
void SetInitialStairPos(int dir, vec3_t min, vec3_t max, float width); void SetInitialStairPos(int dir, vec3_t min, vec3_t max, float width);
@ -43,4 +51,6 @@ float Determinant3x3(float a1, float a2, float a3,
float c1, float c2, float c3); float c1, float c2, float c3);
bool GetEntityCentre(const char* entity, vec3_t centre); 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

View file

@ -18,11 +18,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "StdAfx.h"
#include "shapes.h" #include "shapes.h"
#include "gtkr_list.h" #include <list>
#include "DPoint.h" #include "DPoint.h"
#include "DPlane.h" #include "DPlane.h"
@ -80,18 +78,16 @@ float Deg2Rad(float angle)
return (float)(angle*Q_PI/180); 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; _QERFaceData faceData;
FillDefaultTexture(&faceData, va, vb, vc, texture); FillDefaultTexture(&faceData, va, vb, vc, texture);
if(detail) if(detail)
faceData.m_texdef.contents |= FACE_DETAIL; faceData.m_texdef.contents |= FACE_DETAIL;
#if 0 GlobalBrushCreator().addBrushFace(brush, faceData);
brush->m_brush->addPlane(faceData.m_p0, faceData.m_p1, faceData.m_p2, faceData.m_texdef);
#endif
} }
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, const char* texture, bool bVertScale, bool bHorScale,
float minX, float minY, float maxX, float maxY) float minX, float minY, float maxX, float maxY)
{ {
@ -135,9 +131,7 @@ void AddFaceWithTextureScaled(scene::Node* brush, vec3_t va, vec3_t vb, vec3_t v
addFace.m_texdef.shift[0] = shift[0]; addFace.m_texdef.shift[0] = shift[0];
addFace.m_texdef.shift[1] = shift[1]; addFace.m_texdef.shift[1] = shift[1];
#if 0 GlobalBrushCreator().addBrushFace(brush, addFace);
brush->m_brush->addPlane(addFace.m_p0, addFace.m_p1, addFace.m_p2, addFace.m_texdef);
#endif
} }
else else
{ {
@ -156,7 +150,7 @@ void AddFaceWithTextureScaled(scene::Node* brush, vec3_t va, vec3_t vb, vec3_t v
void Build_Wedge(int dir, vec3_t min, vec3_t max, bool bUp) 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; vec3_t v1, v2, v3, v5, v6, v7, v8;
VectorCopy(min, v1); VectorCopy(min, v1);
@ -233,7 +227,7 @@ void Build_Wedge(int dir, vec3_t min, vec3_t max, bool bUp)
AddFaceWithTexture(newBrush, v7, v8, v3, "textures/common/caulk", FALSE); AddFaceWithTexture(newBrush, v7, v8, v3, "textures/common/caulk", FALSE);
} }
GetWorldspawn()->m_traverse->insert(newBrush); Node_getTraversable(GetWorldspawn())->insert(newBrush);
} }
//----------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------
@ -241,7 +235,7 @@ void Build_Wedge(int dir, vec3_t min, vec3_t max, bool bUp)
void Build_StairStep_Wedge(int dir, vec3_t min, vec3_t max, const char* mainTexture, const char* riserTexture, bool detail) 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 --------- //----- Build Outer Bounds ---------
@ -312,16 +306,16 @@ void Build_StairStep_Wedge(int dir, vec3_t min, vec3_t max, const char* mainText
if(dir == MOVE_SOUTH) if(dir == MOVE_SOUTH)
AddFaceWithTexture(newBrush, v7, v8, v3, "textures/common/caulk", detail); 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 // 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 --------- //----- Build Outer Bounds ---------
@ -362,7 +356,7 @@ scene::Node* Build_Get_BoundingCube_Selective(vec3_t min, vec3_t max, char* text
return newBrush; 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); return Build_Get_BoundingCube_Selective(min, max, texture, bFacesAll);
} }
@ -372,7 +366,7 @@ scene::Node* Build_Get_BoundingCube(vec3_t min, vec3_t max, char* texture)
void Build_StairStep(vec3_t min, vec3_t max, const char* mainTexture, const char* riserTexture, int direction) 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 --------- //----- Build Outer Bounds ---------
@ -422,7 +416,7 @@ void Build_StairStep(vec3_t min, vec3_t max, const char* mainTexture, const char
AddFaceWithTexture(newBrush, v1, v2, v3, "textures/common/caulk", FALSE); AddFaceWithTexture(newBrush, v1, v2, v3, "textures/common/caulk", FALSE);
// base is caulked // base is caulked
GetWorldspawn()->m_traverse->insert(newBrush); Node_getTraversable(GetWorldspawn())->insert(newBrush);
// finish brush // finish brush
} }
@ -478,8 +472,8 @@ void BuildDoorsX2(vec3_t min, vec3_t max,
//---------------------------------- //----------------------------------
scene::Node* newBrush1 = Brush_AllocNode(); NodeSmartReference newBrush1(GlobalBrushCreator().createBrush());
scene::Node* newBrush2 = Brush_AllocNode(); NodeSmartReference newBrush2(GlobalBrushCreator().createBrush());
AddFaceWithTexture(newBrush1, v1, v2, v3, "textures/common/caulk", FALSE); AddFaceWithTexture(newBrush1, v1, v2, v3, "textures/common/caulk", FALSE);
AddFaceWithTexture(newBrush1, v5, v7, v6, "textures/common/caulk", FALSE); AddFaceWithTexture(newBrush1, v5, v7, v6, "textures/common/caulk", FALSE);
@ -543,8 +537,8 @@ void BuildDoorsX2(vec3_t min, vec3_t max,
//---------------------------------- //----------------------------------
scene::Node* pEDoor1 = GlobalEntityCreator().createEntity("func_door"); NodeSmartReference pEDoor1 = GlobalEntityCreator().createEntity("func_door");
scene::Node* pEDoor2 = GlobalEntityCreator().createEntity("func_door"); NodeSmartReference pEDoor2 = GlobalEntityCreator().createEntity("func_door");
if(direction == 0) if(direction == 0)
{ {
@ -564,11 +558,11 @@ void BuildDoorsX2(vec3_t min, vec3_t max,
pEDoor1->m_entity->setkeyvalue("team", teamname); pEDoor1->m_entity->setkeyvalue("team", teamname);
pEDoor2->m_entity->setkeyvalue("team", teamname); pEDoor2->m_entity->setkeyvalue("team", teamname);
pEDoor1->m_traverse->insert(newBrush1); Node_getTraversable(pEDoor1)->insert(newBrush1);
pEDoor2->m_traverse->insert(newBrush2); Node_getTraversable(pEDoor2)->insert(newBrush2);
GlobalSceneGraph().root()->m_traverse->insert(pEDoor1); Node_getTraversable(GlobalSceneGraph().root())->insert(pEDoor1);
GlobalSceneGraph().root()->m_traverse->insert(pEDoor2); Node_getTraversable(GlobalSceneGraph().root())->insert(pEDoor2);
// ResetCurrentTexture(); // ResetCurrentTexture();
} }
@ -578,14 +572,14 @@ void BuildDoorsX2(vec3_t min, vec3_t max,
void MakeBevel(vec3_t vMin, vec3_t vMax) void MakeBevel(vec3_t vMin, vec3_t vMax)
{ {
scene::Node* patch = Patch_AllocNode(); NodeSmartReference patch(GlobalPatchCreator().createPatch());
aabb_t aabb; aabb_t aabb;
aabb_construct_for_vec3(&aabb, vMin, vMax); aabb_construct_for_vec3(&aabb, vMin, vMax);
#if 0 #if 0
patch->m_patch->ConstructPrefab(&aabb, eBevel, 2); // 2 == XY view patch->m_patch->ConstructPrefab(&aabb, eBevel, 2); // 2 == XY view
#endif #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) void BuildCornerStairs(vec3_t vMin, vec3_t vMax, int nSteps, const char* mainTexture, const char* riserTex)
@ -628,7 +622,7 @@ void BuildCornerStairs(vec3_t vMin, vec3_t vMax, int nSteps, const char* mainTex
for(i = 0; i < nSteps; i++) 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++) for(int j = 0; j < 3; j++)
tp[j][2] = vTop[2]; tp[j][2] = vTop[2];
@ -638,7 +632,7 @@ void BuildCornerStairs(vec3_t vMin, vec3_t vMax, int nSteps, const char* mainTex
AddFaceWithTexture(brush, centre, botPoints[i+1], topPoints[i+1], "textures/common/caulk", FALSE); AddFaceWithTexture(brush, centre, botPoints[i+1], topPoints[i+1], "textures/common/caulk", FALSE);
AddFaceWithTexture(brush, centre, topPoints[i], botPoints[i], riserTex, FALSE); AddFaceWithTexture(brush, centre, topPoints[i], botPoints[i], riserTex, FALSE);
GetWorldspawn()->m_traverse->insert(brush); Node_getTraversable(GetWorldspawn())->insert(brush);
vTop[2] += height; vTop[2] += height;
vBot[2] += height; vBot[2] += height;

View file

@ -27,7 +27,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#define MAX_POLYGON_FACES 128 #define MAX_POLYGON_FACES 128
// generic (detail added 12/01/01, for AC+) // 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--- // ---caulked---

View file

@ -2,12 +2,12 @@
// Date: Oct 5, 2001 // Date: Oct 5, 2001
// Written by: Brad Whitehead (whiteheb@gamerstv.net) // Written by: Brad Whitehead (whiteheb@gamerstv.net)
#include "StdAfx.h" #include "visfind.h"
#include "dialogs/dialogs-gtk.h" #include "dialogs/dialogs-gtk.h"
#include "DWinding.h" #include "DWinding.h"
#include "bsploader.h" #include "bsploader.h"
#include "gtkr_list.h" #include <list>
typedef struct { typedef struct {
int portalclusters; int portalclusters;
@ -122,7 +122,7 @@ int bsp_countclusters_mask(byte *bitvector, byte *maskvector, int length)
return(c); 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; DWinding* w;
@ -164,11 +164,11 @@ void AddCluster(list<DWinding*> *pointlist, dleaf_t *cl, bool* repeatlist, vec3_
CreateTrace 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; byte *vis;
int i, j, clusterNum; int i, j, clusterNum;
list<DWinding*> *pointlist = new list<DWinding*>; std::list<DWinding*> *pointlist = new std::list<DWinding*>;
bool* repeatlist = new bool[numDrawSurfaces]; bool* repeatlist = new bool[numDrawSurfaces];
dleaf_t *cl; dleaf_t *cl;
@ -214,7 +214,7 @@ TraceCluster
setup for CreateTrace setup for CreateTrace
============= =============
*/ */
list<DWinding*> *TraceCluster (int leafnum) std::list<DWinding*> *TraceCluster (int leafnum)
{ {
byte seen[(MAX_MAP_LEAFS/8) + 1]; byte seen[(MAX_MAP_LEAFS/8) + 1];
vis_header *vheader; vis_header *vheader;
@ -232,14 +232,14 @@ list<DWinding*> *TraceCluster (int leafnum)
return CreateTrace(leaf, leaf->cluster, vheader, visdata, seen); 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)) if(!LoadBSPFile(filename))
return NULL; return NULL;
int leafnum = bsp_leafnumfororigin(v_origin); int leafnum = bsp_leafnumfororigin(v_origin);
list<DWinding*> *pointlist = TraceCluster(leafnum); std::list<DWinding*> *pointlist = TraceCluster(leafnum);
FreeBSPData(); FreeBSPData();

View file

@ -1 +1,7 @@
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);

View file

@ -1979,7 +1979,7 @@ scene::Node* MakePatch(void)
#if 0 #if 0
patch->m_patch->SetShader(Texture[Game][0]); patch->m_patch->SetShader(Texture[Game][0]);
#endif #endif
h_worldspawn->m_traverse->insert(patch); Node_getTraversable(h_worldspawn)->insert(patch);
return patch; return patch;
} }
@ -2021,7 +2021,7 @@ void MakeBrush(BRUSH *brush)
} }
#endif #endif
h_func_group->m_traverse->insert(node); Node_getTraversable(h_func_group)->insert(node);
} }
//============================================================= //=============================================================
void OpenFuncGroup() void OpenFuncGroup()

View file

@ -337,7 +337,7 @@ void Portals_constructShaders()
GlobalOpenGLStateLibrary().insert(g_state_wireframe, state); GlobalOpenGLStateLibrary().insert(g_state_wireframe, state);
GlobalOpenGLStateLibrary().getDefaultState(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) if(portals.aa_3d)
{ {

View file

@ -23,12 +23,81 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#define INCLUDED_IBRUSH_H #define INCLUDED_IBRUSH_H
#include "generic/constant.h" #include "generic/constant.h"
#include "generic/callback.h"
#include "math/vector.h"
#include "itexdef.h"
namespace scene namespace scene
{ {
class Node; 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 class BrushCreator
{ {
public: public:
@ -36,6 +105,8 @@ public:
STRING_CONSTANT(Name, "brush"); STRING_CONSTANT(Name, "brush");
virtual scene::Node& createBrush() = 0; virtual scene::Node& createBrush() = 0;
virtual bool useAlternativeTextureProjection() const = 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" #include "modulesystem.h"

View file

@ -29,6 +29,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#define INCLUDED_ICAMERA_H #define INCLUDED_ICAMERA_H
#include "generic/constant.h" #include "generic/constant.h"
#include "generic/callbackfwd.h"
class Matrix4; class Matrix4;
@ -39,8 +40,6 @@ public:
virtual void setFieldOfView(float fieldOfView) = 0; virtual void setFieldOfView(float fieldOfView) = 0;
}; };
class Callback;
class CameraModel class CameraModel
{ {
public: public:

View file

@ -29,11 +29,30 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
class EntityClass; 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 class Entity
{ {
public: public:
STRING_CONSTANT(Name, "Entity"); 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 class Visitor
{ {
public: public:
@ -45,6 +64,8 @@ public:
virtual void setKeyValue(const char* key, const char* value) = 0; virtual void setKeyValue(const char* key, const char* value) = 0;
virtual const char* getKeyValue(const char* key) const = 0; virtual const char* getKeyValue(const char* key) const = 0;
virtual bool isContainer() const = 0; virtual bool isContainer() const = 0;
void attach(Observer& observer);
void detach(Observer& observer);
}; };
class EntityCopyingVisitor : public Entity::Visitor class EntityCopyingVisitor : public Entity::Visitor

View file

@ -24,9 +24,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include <cstddef> #include <cstddef>
#include "generic/constant.h" #include "generic/constant.h"
#include "generic/callbackfwd.h"
template<typename FirstArgument>
class Callback1;
typedef Callback1<const char*> ArchiveNameCallback; typedef Callback1<const char*> ArchiveNameCallback;
typedef Callback1<const char*> FileNameCallback; typedef Callback1<const char*> FileNameCallback;

View file

@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#define INCLUDED_IRENDER_H #define INCLUDED_IRENDER_H
#include "generic/constant.h" #include "generic/constant.h"
#include "generic/callbackfwd.h"
// Rendering states to sort by. // Rendering states to sort by.
@ -88,9 +89,6 @@ public:
} }
}; };
template<typename FirstArgument>
class Callback1;
class Renderable; class Renderable;
typedef Callback1<const Renderable&> RenderableCallback; typedef Callback1<const Renderable&> RenderableCallback;

View file

@ -24,14 +24,13 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include <cstddef> #include <cstddef>
#include "generic/constant.h" #include "generic/constant.h"
#include "signal/signalfwd.h"
template<typename value_type> template<typename value_type>
class Stack; class Stack;
template<typename Contained> template<typename Contained>
class Reference; class Reference;
class Callback;
namespace scene namespace scene
{ {
class Instance; class Instance;
@ -105,15 +104,15 @@ namespace scene
virtual void sceneChanged() = 0; virtual void sceneChanged() = 0;
/// \brief Add a \p callback to be invoked when the scene changes. /// \brief Add a \p callback to be invoked when the scene changes.
/// \todo Move to a separate class. /// \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. /// \brief Invokes all bounds-changed callbacks. Called when the bounds of any instance in the scene change.
/// \todo Move to a separate class. /// \todo Move to a separate class.
virtual void boundsChanged() = 0; virtual void boundsChanged() = 0;
/// \brief Add a \p callback to be invoked when the bounds of any instance in the scene change. /// \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. /// \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 getNodeTypeId(const char* name) = 0;
virtual TypeId getInstanceTypeId(const char* name) = 0; virtual TypeId getInstanceTypeId(const char* name) = 0;
@ -208,9 +207,9 @@ inline scene::Graph& GlobalSceneGraph()
return GlobalSceneGraphModule::getTable(); return GlobalSceneGraphModule::getTable();
} }
inline void AddSceneChangeCallback(const Callback& callback) inline void AddSceneChangeCallback(const SignalHandler& handler)
{ {
GlobalSceneGraph().addSceneChangedCallback(callback); GlobalSceneGraph().addSceneChangedCallback(handler);
} }
inline void SceneChangeNotify() inline void SceneChangeNotify()
{ {

View file

@ -24,15 +24,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include <cstddef> #include <cstddef>
#include "generic/constant.h" #include "generic/constant.h"
#include "generic/callbackfwd.h"
#include "signal/signalfwd.h"
class Renderer; class Renderer;
class View; class View;
class Callback;
template<typename FirstArgument>
class Callback1;
class Selectable class Selectable
{ {
public: public:
@ -61,6 +58,7 @@ class Matrix4;
typedef Vector4 Quaternion; typedef Vector4 Quaternion;
typedef Callback1<const Selectable&> SelectionChangeCallback; typedef Callback1<const Selectable&> SelectionChangeCallback;
typedef SignalHandler1<const Selectable&> SelectionChangeHandler;
class SelectionSystem class SelectionSystem
{ {
@ -117,7 +115,7 @@ public:
virtual void foreachSelected(const Visitor& visitor) const = 0; virtual void foreachSelected(const Visitor& visitor) const = 0;
virtual void foreachSelectedComponent(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; virtual void NudgeManipulator(const Vector3& nudge, const Vector3& view) = 0;

View file

@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#define INCLUDED_ISHADERS_H #define INCLUDED_ISHADERS_H
#include "generic/constant.h" #include "generic/constant.h"
#include "generic/callbackfwd.h"
enum enum
{ {
@ -78,8 +79,6 @@ public:
virtual float alphaTest() const = 0; virtual float alphaTest() const = 0;
}; };
template<typename FirstArgument>
class Callback1;
typedef Callback1<const ShaderLayer&> ShaderLayerCallback; typedef Callback1<const ShaderLayer&> ShaderLayerCallback;
@ -133,7 +132,6 @@ public:
virtual qtexture_t* lightFalloffImage() const = 0; virtual qtexture_t* lightFalloffImage() const = 0;
}; };
class Callback;
typedef struct _GSList GSList; typedef struct _GSList GSList;
typedef Callback1<const char*> ShaderNameCallback; typedef Callback1<const char*> ShaderNameCallback;

View file

@ -27,6 +27,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include <cstddef> #include <cstddef>
#include "generic/constant.h" #include "generic/constant.h"
#include "generic/callbackfwd.h"
class UndoMemento class UndoMemento
{ {
@ -47,8 +48,6 @@ public:
virtual void save(Undoable* undoable) = 0; virtual void save(Undoable* undoable) = 0;
}; };
class Callback;
class UndoTracker class UndoTracker
{ {
public: public:

View file

@ -25,8 +25,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include <limits> #include <limits>
#include "iscenegraph.h" #include "iscenegraph.h"
#include "generic/callbackfwd.h"
class Callback;
const std::size_t MAPFILE_MAX_CHANGES = std::numeric_limits<std::size_t>::max(); const std::size_t MAPFILE_MAX_CHANGES = std::numeric_limits<std::size_t>::max();

View file

@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#define INCLUDED_MODELSKIN_H #define INCLUDED_MODELSKIN_H
#include "generic/constant.h" #include "generic/constant.h"
#include "generic/callbackfwd.h"
class SkinRemap class SkinRemap
{ {
@ -34,8 +35,6 @@ public:
} }
}; };
template<typename FirstArgument>
class Callback1;
typedef Callback1<SkinRemap> SkinRemapCallback; typedef Callback1<SkinRemap> SkinRemapCallback;
class ModuleObserver; class ModuleObserver;

View file

@ -23,9 +23,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#define INCLUDED_NAMEABLE_H #define INCLUDED_NAMEABLE_H
#include "generic/constant.h" #include "generic/constant.h"
#include "generic/callbackfwd.h"
template<typename FirstArgument>
class Callback1;
typedef Callback1<const char*> NameCallback; typedef Callback1<const char*> NameCallback;
class Nameable class Nameable

View file

@ -23,9 +23,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#define INCLUDED_NAMESPACE_H #define INCLUDED_NAMESPACE_H
#include "generic/constant.h" #include "generic/constant.h"
#include "generic/callbackfwd.h"
template<typename FirstArgument>
class Callback1;
typedef Callback1<const char*> NameCallback; typedef Callback1<const char*> NameCallback;
typedef Callback1<const NameCallback&> NameCallbackCallback; typedef Callback1<const NameCallback&> NameCallbackCallback;

View file

@ -23,9 +23,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#define INCLUDED_PREFERENCESYSTEM_H #define INCLUDED_PREFERENCESYSTEM_H
#include "generic/constant.h" #include "generic/constant.h"
#include "generic/callbackfwd.h"
template<typename FirstArgument>
class Callback1;
typedef Callback1<const char*> StringImportCallback; typedef Callback1<const char*> StringImportCallback;
typedef Callback1<const StringImportCallback&> StringExportCallback; typedef Callback1<const StringImportCallback&> StringExportCallback;

View file

@ -90,8 +90,27 @@ typedef GtkImage* (* PFN_QERAPP_NEWIMAGE) (const char* filename);
// ======================================== // ========================================
namespace scene
{
class Node;
}
class ModuleObserver; 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 // the radiant core API
struct _QERFuncTable_1 struct _QERFuncTable_1
{ {
@ -107,6 +126,8 @@ struct _QERFuncTable_1
const char* (*getGameMode)(); const char* (*getGameMode)();
const char* (*getMapName)(); const char* (*getMapName)();
scene::Node& (*getMapWorldEntity)();
float (*getGridSize)();
const char* (*getGameDescriptionKeyValue)(const char* key); const char* (*getGameDescriptionKeyValue)(const char* key);
const char* (*getRequiredGameDescriptionKeyValue)(const char* key); const char* (*getRequiredGameDescriptionKeyValue)(const char* key);
@ -120,6 +141,12 @@ struct _QERFuncTable_1
void (*attachGameModeObserver)(ModuleObserver& observer); void (*attachGameModeObserver)(ModuleObserver& observer);
void (*detachGameModeObserver)(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 // GTK+ functions
PFN_QERAPP_MESSAGEBOX m_pfnMessageBox; PFN_QERAPP_MESSAGEBOX m_pfnMessageBox;
PFN_QERAPP_FILEDIALOG m_pfnFileDialog; PFN_QERAPP_FILEDIALOG m_pfnFileDialog;

View file

@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "math/vector.h" #include "math/vector.h"
#include "scenelib.h" #include "scenelib.h"
#include "generic/callbackfwd.h"
class SelectionIntersection class SelectionIntersection
{ {
@ -281,8 +282,6 @@ inline SelectionTestable* Instance_getSelectionTestable(scene::Instance& instanc
} }
template<typename FirstArgument>
class Callback1;
class Plane3; class Plane3;
typedef Callback1<const Plane3&> PlaneCallback; typedef Callback1<const Plane3&> PlaneCallback;

View file

@ -109,11 +109,11 @@ namespace HashTableDetail
: m_hash(hash), m_value(key, value) : m_hash(hash), m_value(key, value)
{ {
} }
BucketNode* getNext() BucketNode* getNext() const
{ {
return static_cast<BucketNode*>(next); return static_cast<BucketNode*>(next);
} }
BucketNode* getPrev() BucketNode* getPrev() const
{ {
return static_cast<BucketNode*>(prev); return static_cast<BucketNode*>(prev);
} }

View file

@ -39,8 +39,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#define DEBUGGER_BREAKPOINT() raise(SIGTRAP); #define DEBUGGER_BREAKPOINT() raise(SIGTRAP);
#endif #endif
#define STR(x) #x
#define FILE_LINE __FILE__ ":" << __LINE__ #define STR2(x) STR(x)
#define FILE_LINE __FILE__ ":" STR2(__LINE__)
#if defined(_DEBUG) || 1 #if defined(_DEBUG) || 1
#define DEBUG_ASSERTS #define DEBUG_ASSERTS
@ -114,13 +115,13 @@ inline DebugMessageHandler& globalDebugMessageHandler()
#define ASSERT_MESSAGE(condition, message)\ #define ASSERT_MESSAGE(condition, message)\
if(!(condition))\ if(!(condition))\
{\ {\
globalDebugMessageHandler().getOutputStream() << FILE_LINE << "\nassertion failure: " << message << "\n";\ globalDebugMessageHandler().getOutputStream() << FILE_LINE "\nassertion failure: " << message << "\n";\
if(!globalDebugMessageHandler().handleMessage()) { DEBUGGER_BREAKPOINT(); }\ if(!globalDebugMessageHandler().handleMessage()) { DEBUGGER_BREAKPOINT(); }\
} else\ } else\
/// \brief Sends a \p message to the current debug-message-handler text-output-stream. /// \brief Sends a \p message to the current debug-message-handler text-output-stream.
#define ERROR_MESSAGE(message)\ #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\ if(!globalDebugMessageHandler().handleMessage()) { DEBUGGER_BREAKPOINT(); } else\
#define ASSERT_NOTNULL(ptr) ASSERT_MESSAGE(ptr != 0, "pointer \"" #ptr "\" is null") #define ASSERT_NOTNULL(ptr) ASSERT_MESSAGE(ptr != 0, "pointer \"" #ptr "\" is null")

View file

@ -304,13 +304,11 @@ public:
}; };
typedef Callback1<const char*> KeyObserver;
/// \brief A key/value pair of strings. /// \brief A key/value pair of strings.
/// ///
/// - Notifies observers when value changes - value changes to "" on destruction. /// - Notifies observers when value changes - value changes to "" on destruction.
/// - Provides undo support through the global undo system. /// - Provides undo support through the global undo system.
class KeyValue class KeyValue : public EntityKeyValue
{ {
typedef UnsortedSet<KeyObserver> KeyObservers; typedef UnsortedSet<KeyObserver> KeyObservers;
@ -414,13 +412,6 @@ class EntityKeyValues : public Entity
public: public:
typedef KeyValue Value; 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() static StringPool& getPool()
{ {
return Static<StringPool, KeyContext>::instance(); return Static<StringPool, KeyContext>::instance();
@ -553,6 +544,11 @@ public:
} }
~EntityKeyValues() ~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"); ASSERT_MESSAGE(m_observers.empty(), "EntityKeyValues::~EntityKeyValues: observers still attached");
} }

View file

@ -107,3 +107,179 @@ namespace ExampleReferenceCaller
} }
#endif #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;
}
}
}

View file

@ -23,28 +23,206 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#define INCLUDED_GENERIC_CLOSURE_H #define INCLUDED_GENERIC_CLOSURE_H
/// \file /// \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 <cstddef>
#include "functional.h"
#include "callbackfwd.h"
/// \brief Combines a void pointer with a pointer to a function which operates on a void pointer. template<typename Type>
/// inline void* convertToOpaque(Type* t)
/// Use with the callback constructors MemberCaller, ConstMemberCaller, ReferenceCaller, ConstReferenceCaller, PointerCaller, ConstPointerCaller and FreeCaller.
class Callback
{ {
typedef void (*Thunk)(void*); return t;
void* m_environment; }
Thunk m_thunk; 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);
}
static void nullThunk(void*)
{
}
template<typename Type>
class ConvertFromOpaque
{
};
template<typename Type>
class ConvertFromOpaque<Type&>
{
public: public:
Callback() : m_environment(0), m_thunk(nullThunk) 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 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:
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 void* getEnvironment() const
@ -55,113 +233,226 @@ public:
{ {
return m_thunk; 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(); 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() || return self.getEnvironment() < other.getEnvironment() ||
(!(other.getEnvironment() < self.getEnvironment()) && self.getThunk() < other.getThunk()); (!(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.
///
/// Use with the callback constructors MemberCaller, ConstMemberCaller, ReferenceCaller, ConstReferenceCaller, PointerCaller, ConstPointerCaller and FreeCaller.
template<typename Result>
class Callback0 : public CallbackBase<Result (*)(void*)>
{
typedef CallbackBase<Result (*)(void*)> Base;
static Result nullThunk(void*)
{
}
public:
typedef Result result_type;
Callback0() : Base(0, nullThunk)
{
}
template<typename Caller>
Callback0(const BindFirstOpaque<Caller>& caller) : Base(caller.getEnvironment(), BindFirstOpaque<Caller>::thunk)
{
}
Callback0(void* environment, Thunk function) : Base(environment, function)
{
}
result_type operator()() const
{
return getThunk()(getEnvironment());
}
};
template<typename Caller>
inline Callback0<typename Caller::result_type> makeCallback0(const Caller& caller, typename Caller::first_argument_type callee)
{
return Callback0<typename Caller::result_type>(BindFirstOpaque<Caller>(callee));
}
template<typename Caller>
inline Callback0<typename Caller::result_type> makeStatelessCallback0(const Caller& caller)
{
return makeCallback0(Caller0To1<Caller>(), 0);
}
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. /// \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. /// Use with the callback constructors MemberCaller1, ConstMemberCaller1, ReferenceCaller1, ConstReferenceCaller1, PointerCaller1, ConstPointerCaller1 and FreeCaller1.
template<typename FirstArgument> template<typename FirstArgument, typename Result>
class Callback1 class Callback1 : public CallbackBase<Result (*)(void*, FirstArgument)>
{ {
typedef void (*Thunk)(void*, FirstArgument); typedef CallbackBase<Result (*)(void*, FirstArgument)> Base;
void* m_environment; static Result nullThunk(void*, FirstArgument)
Thunk m_thunk;
static void nullThunk(void*, FirstArgument)
{ {
} }
public: public:
typedef FirstArgument first_argument_type; typedef FirstArgument first_argument_type;
typedef Result result_type;
Callback1() : m_environment(0), m_thunk(nullThunk) Callback1() : Base(0, nullThunk)
{ {
} }
Callback1(void* environment, Thunk function) : m_environment(environment), m_thunk(function) template<typename Caller>
Callback1(const BindFirstOpaque1<Caller>& caller) : Base(caller.getEnvironment(), BindFirstOpaque1<Caller>::thunk)
{ {
} }
void* getEnvironment() const Callback1(void* environment, Thunk function) : Base(environment, function)
{ {
return m_environment;
} }
Thunk getThunk() const result_type operator()(FirstArgument firstArgument) const
{ {
return m_thunk; return getThunk()(getEnvironment(), firstArgument);
}
void operator()(FirstArgument firstArgument) const
{
m_thunk(m_environment, firstArgument);
} }
}; };
template<typename FirstArgument> template<typename Caller>
inline bool operator==(const Callback1<FirstArgument>& self, const Callback1<FirstArgument>& other) inline Callback1<typename Caller::second_argument_type, typename Caller::result_type> makeCallback1(const Caller& caller, typename Caller::first_argument_type callee)
{ {
return self.getEnvironment() == other.getEnvironment() && self.getThunk() == other.getThunk(); return Callback1<typename Caller::second_argument_type, typename Caller::result_type>(BindFirstOpaque1<Caller>(callee));
} }
template<typename FirstArgument> template<typename Caller>
inline bool operator<(const Callback1<FirstArgument>& self, const Callback1<FirstArgument>& other) inline Callback1<typename Caller::second_argument_type, typename Caller::result_type> makeStatelessCallback1(const Caller& caller)
{ {
return self.getEnvironment() < other.getEnvironment() || return makeCallback1(Caller1To2<Caller>(), 0);
(!(other.getEnvironment() < self.getEnvironment()) && self.getThunk() < other.getThunk());
} }
template<typename Functor>
class FunctorInvoke /// \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)>
{ {
public: typedef CallbackBase<Result (*)(void*, FirstArgument, SecondArgument)> Base;
inline void operator()(Functor functor) static Result nullThunk(void*, FirstArgument, SecondArgument)
{ {
functor(); }
public:
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)
{
}
Callback2(void* environment, Thunk function) : Base(environment, function)
{
}
result_type operator()(FirstArgument firstArgument, SecondArgument secondArgument) const
{
return getThunk()(getEnvironment(), firstArgument, secondArgument);
} }
}; };
typedef FunctorInvoke<Callback> CallbackInvoke; template<typename Caller>
inline Callback2<
typename Caller::second_argument_type,
template<typename Functor, typename FirstArgument> typename Caller::third_argument_type,
class Functor1Invoke typename Caller::result_type
> makeCallback2(const Caller& caller, typename Caller::first_argument_type callee)
{ {
FirstArgument m_firstArgument; return Callback2<
public: typename Caller::second_argument_type,
Functor1Invoke(FirstArgument firstArgument) : m_firstArgument(firstArgument) 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);
}
/// \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)
{ {
} }
inline void operator()(Functor functor)
public:
typedef FirstArgument first_argument_type;
typedef SecondArgument second_argument_type;
typedef ThirdArgument third_argument_type;
typedef Result result_type;
Callback3() : Base(0, nullThunk)
{ {
functor(m_firstArgument); }
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);
} }
}; };
template<typename Caller>
typedef Callback1<bool> BoolImportCallback; inline Callback3<
typedef Callback1<const BoolImportCallback&> BoolExportCallback; typename Caller::second_argument_type,
typename Caller::third_argument_type,
typedef Callback1<int> IntImportCallback; typename Caller::fourth_argument_type,
typedef Callback1<const IntImportCallback&> IntExportCallback; typename Caller::result_type
> makeCallback3(const Caller& caller, typename Caller::first_argument_type callee)
typedef Callback1<float> FloatImportCallback; {
typedef Callback1<const FloatImportCallback&> FloatExportCallback; return Callback3<
typename Caller::second_argument_type,
typedef Callback1<const char*> StringImportCallback; typename Caller::third_argument_type,
typedef Callback1<const StringImportCallback&> StringExportCallback; typename Caller::fourth_argument_type,
typename Caller::result_type
typedef Callback1<std::size_t> SizeImportCallback; >(BindFirstOpaque3<Caller>(callee));
typedef Callback1<const SizeImportCallback&> SizeExportCallback; }
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. /// \brief Forms a Callback from a non-const Environment reference and a non-const Environment member-function.
@ -170,25 +461,12 @@ typedef Callback1<const SizeImportCallback&> SizeExportCallback;
/// \skipline MemberCaller example /// \skipline MemberCaller example
/// \until end example /// \until end example
template<typename Environment, void (Environment::*member)()> template<typename Environment, void (Environment::*member)()>
class MemberCaller class MemberCaller : public BindFirstOpaque< Member<Environment, void, member> >
{ {
Environment& m_environment;
public: public:
MemberCaller(Environment& environment) : m_environment(environment) MemberCaller(Environment& environment) : BindFirstOpaque< Member<Environment, void, member> >(environment)
{ {
} }
void* getEnvironment() const
{
return &m_environment;
}
static void thunk(void* environment)
{
((*reinterpret_cast<Environment*>(environment)).*member)();
}
operator Callback() const
{
return Callback(getEnvironment(), thunk);
}
}; };
/// \brief Forms a Callback from a const Environment reference and a const Environment member-function. /// \brief Forms a Callback from a const Environment reference and a const Environment member-function.
@ -197,71 +475,32 @@ public:
/// \skipline MemberCaller example /// \skipline MemberCaller example
/// \until end example /// \until end example
template<typename Environment, void (Environment::*member)() const> template<typename Environment, void (Environment::*member)() const>
class ConstMemberCaller class ConstMemberCaller : public BindFirstOpaque< ConstMember<Environment, void, member> >
{ {
const Environment& m_environment;
public: public:
ConstMemberCaller(const Environment& environment) : m_environment(environment) ConstMemberCaller(const Environment& environment) : BindFirstOpaque< ConstMember<Environment, void, member> >(environment)
{ {
} }
void* getEnvironment() const
{
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. /// \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)> template<typename Environment, typename FirstArgument, void (Environment::*member)(FirstArgument)>
class MemberCaller1 class MemberCaller1 : public BindFirstOpaque1< Member1<Environment, FirstArgument, void, member> >
{ {
Environment& m_environment;
public: 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. /// \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> 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: 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. /// \brief Forms a Callback from a non-const Environment reference and a free function which operates on a non-const Environment reference.
@ -270,25 +509,12 @@ public:
/// \skipline ReferenceCaller example /// \skipline ReferenceCaller example
/// \until end example /// \until end example
template<typename Environment, void (*func)(Environment&)> template<typename Environment, void (*func)(Environment&)>
class ReferenceCaller class ReferenceCaller : public BindFirstOpaque< Function1<Environment&, void, func> >
{ {
Environment& m_environment;
public: public:
ReferenceCaller(Environment& environment) : m_environment(environment) ReferenceCaller(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 reference and a free function which operates on a const Environment reference. /// \brief Forms a Callback from a const Environment reference and a free function which operates on a const Environment reference.
@ -297,201 +523,91 @@ public:
/// \skipline ReferenceCaller example /// \skipline ReferenceCaller example
/// \until end example /// \until end example
template<typename Environment, void (*func)(const Environment&)> template<typename Environment, void (*func)(const Environment&)>
class ConstReferenceCaller class ConstReferenceCaller : public BindFirstOpaque< Function1<const Environment&, void, func> >
{ {
const Environment& m_environment;
public: public:
ConstReferenceCaller(const Environment& environment) : m_environment(environment) ConstReferenceCaller(const Environment& environment) : BindFirstOpaque< Function1<const Environment&, void, func> >(environment)
{ {
} }
void* getEnvironment() const
{
return const_cast<Environment*>(&m_environment);
}
static void thunk(void* 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. /// \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)> template<typename Environment, typename FirstArgument, void (*func)(Environment&, FirstArgument)>
class ReferenceCaller1 class ReferenceCaller1 : public BindFirstOpaque1< Function2<Environment&, FirstArgument, void, func> >
{ {
Environment& m_environment;
public: public:
ReferenceCaller1(Environment& environment) : m_environment(environment) ReferenceCaller1(Environment& environment) : BindFirstOpaque1< Function2<Environment&, FirstArgument, void, func> >(environment)
{ {
} }
void* getEnvironment() const
{
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. /// \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)> 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: 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. /// \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*)> template<typename Environment, void (*func)(Environment*)>
class PointerCaller class PointerCaller : public BindFirstOpaque< Function1<Environment*, void, func> >
{ {
Environment* m_environment;
public: 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. /// \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*)> template<typename Environment, void (*func)(const Environment*)>
class ConstPointerCaller class ConstPointerCaller : public BindFirstOpaque< Function1<const Environment*, void, func> >
{ {
const Environment* m_environment;
public: public:
ConstPointerCaller(const Environment* environment) : m_environment(environment) ConstPointerCaller(const Environment* environment) : BindFirstOpaque< Function1<const Environment*, void, func> >(environment)
{ {
} }
void* getEnvironment() const
{
return const_cast<Environment*>(m_environment);
}
static void thunk(void* environment)
{
(func)(reinterpret_cast<const Environment*>(environment));
}
operator Callback() const
{
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. /// \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)> template<typename Environment, typename FirstArgument, void (*func)(Environment*, FirstArgument)>
class PointerCaller1 class PointerCaller1 : public BindFirstOpaque1< Function2<Environment*, FirstArgument, void, func> >
{ {
Environment* m_environment;
public: public:
PointerCaller1(Environment* environment) : m_environment(environment) PointerCaller1(Environment* environment) : BindFirstOpaque1< Function2<Environment*, FirstArgument, void, func> >(environment)
{ {
} }
void* getEnvironment() const
{
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 pointer and a free function which operates on a const Environment pointer and one other argument. /// \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)> 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: public:
ConstPointerCaller1(const Environment* environment) : m_environment(environment) ConstPointerCaller1(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 free function which takes no arguments. /// \brief Forms a Callback from a free function which takes no arguments.
template<void (*func)()> template<void (*func)()>
class FreeCaller class FreeCaller : public BindFirstOpaque< Caller0To1< Function0<void, func> > >
{ {
public: public:
void* getEnvironment() const FreeCaller() : BindFirstOpaque< Caller0To1< Function0<void, func> > >(0)
{ {
return 0;
}
static void thunk(void*)
{
(func)();
}
operator Callback() const
{
return Callback(getEnvironment(), thunk);
} }
}; };
/// \brief Forms a Callback from a free function which takes a single argument. /// \brief Forms a Callback from a free function which takes a single argument.
template<typename FirstArgument, void (*func)(FirstArgument)> template<typename FirstArgument, void (*func)(FirstArgument)>
class FreeCaller1 class FreeCaller1 : public BindFirstOpaque1< Caller1To2< Function1<FirstArgument, void, func> > >
{ {
public: public:
void* getEnvironment() const FreeCaller1() : BindFirstOpaque1< Caller1To2< Function1<FirstArgument, void, func> > >(0)
{ {
return 0;
}
static void thunk(void*, FirstArgument firstArgument)
{
(func)(firstArgument);
}
operator Callback1<FirstArgument>() const
{
return Callback1<FirstArgument>(getEnvironment(), thunk);
} }
}; };
@ -534,4 +650,21 @@ inline Callback1<typename Functor::first_argument_type> makeCallback1(const Func
return Callback1<FirstArgument>(ConstMemberCaller1<Functor, FirstArgument, &Functor::operator()>(functor)); 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 #endif

View file

@ -0,0 +1,3 @@
#include "callbackfwd.h"

View file

@ -0,0 +1,18 @@
#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

View file

@ -0,0 +1,3 @@
#include "functional.h"

319
libs/generic/functional.h Normal file
View file

@ -0,0 +1,319 @@
#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

View file

@ -22,13 +22,14 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#if !defined(INCLUDED_GTKUTIL_BUTTON_H) #if !defined(INCLUDED_GTKUTIL_BUTTON_H)
#define INCLUDED_GTKUTIL_BUTTON_H #define INCLUDED_GTKUTIL_BUTTON_H
#include "generic/callbackfwd.h"
typedef struct _GtkButton GtkButton; typedef struct _GtkButton GtkButton;
typedef struct _GtkToggleButton GtkToggleButton; typedef struct _GtkToggleButton GtkToggleButton;
typedef struct _GtkRadioButton GtkRadioButton; typedef struct _GtkRadioButton GtkRadioButton;
typedef int gint; typedef int gint;
typedef gint gboolean; typedef gint gboolean;
typedef unsigned int guint; typedef unsigned int guint;
class Callback;
void button_connect_callback(GtkButton* button, const Callback& callback); void button_connect_callback(GtkButton* button, const Callback& callback);
guint toggle_button_connect_callback(GtkToggleButton* button, const Callback& callback); guint toggle_button_connect_callback(GtkToggleButton* button, const Callback& callback);

View file

@ -22,7 +22,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#if !defined(INCLUDED_GTKUTIL_MENU_H) #if !defined(INCLUDED_GTKUTIL_MENU_H)
#define INCLUDED_GTKUTIL_MENU_H #define INCLUDED_GTKUTIL_MENU_H
class Callback; #include "generic/callbackfwd.h"
typedef int gint; typedef int gint;
typedef gint gboolean; typedef gint gboolean;
typedef struct _GSList GSList; typedef struct _GSList GSList;

View file

@ -22,7 +22,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#if !defined(INCLUDED_GTKUTIL_TOOLBAR_H) #if !defined(INCLUDED_GTKUTIL_TOOLBAR_H)
#define INCLUDED_GTKUTIL_TOOLBAR_H #define INCLUDED_GTKUTIL_TOOLBAR_H
class Callback; #include "generic/callbackfwd.h"
typedef struct _GtkButton GtkButton; typedef struct _GtkButton GtkButton;
typedef struct _GtkToggleButton GtkToggleButton; typedef struct _GtkToggleButton GtkToggleButton;
typedef struct _GtkToolbar GtkToolbar; typedef struct _GtkToolbar GtkToolbar;

View file

@ -379,6 +379,12 @@
<File <File
RelativePath=".\generic\callback.h"> RelativePath=".\generic\callback.h">
</File> </File>
<File
RelativePath=".\generic\callbackfwd.cpp">
</File>
<File
RelativePath=".\generic\callbackfwd.h">
</File>
<File <File
RelativePath=".\generic\constant.cpp"> RelativePath=".\generic\constant.cpp">
</File> </File>
@ -391,6 +397,12 @@
<File <File
RelativePath=".\generic\enumeration.h"> RelativePath=".\generic\enumeration.h">
</File> </File>
<File
RelativePath=".\generic\functional.cpp">
</File>
<File
RelativePath=".\generic\functional.h">
</File>
<File <File
RelativePath=".\generic\object.cpp"> RelativePath=".\generic\object.cpp">
</File> </File>
@ -436,6 +448,28 @@
RelativePath=".\debugging\debugging.h"> RelativePath=".\debugging\debugging.h">
</File> </File>
</Filter> </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 <File
RelativePath=".\archivelib.cpp"> RelativePath=".\archivelib.cpp">
</File> </File>

View file

@ -416,6 +416,15 @@ const Vector3 g_vector3_axis_z(0, 0, 1);
const Vector3 g_vector3_axes[3] = { g_vector3_axis_x, g_vector3_axis_y, g_vector3_axis_z }; 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> template<typename Element>
inline Element* vector3_to_array(BasicVector3<Element>& self) inline Element* vector3_to_array(BasicVector3<Element>& self)
{ {

3
libs/signal/isignal.cpp Normal file
View file

@ -0,0 +1,3 @@
#include "isignal.h"

224
libs/signal/isignal.h Normal file
View file

@ -0,0 +1,224 @@
#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

105
libs/signal/signal.cpp Normal file
View file

@ -0,0 +1,105 @@
#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);
}
}
}

377
libs/signal/signal.h Normal file
View file

@ -0,0 +1,377 @@
#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

View file

@ -0,0 +1,3 @@
#include "signalfwd.h"

48
libs/signal/signalfwd.h Normal file
View file

@ -0,0 +1,48 @@
#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

View file

@ -27,17 +27,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include <map> #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 class StaticElement : public XMLElement
{ {
struct strless typedef std::map<const char*, const char*, RawStringLess> attrs_t;
{
bool operator()(const char* s1, const char* s2) const
{
return strcmp(s1, s2) < 0;
}
};
typedef std::map<const char*, const char*, strless> attrs_t;
public: public:
StaticElement(const char* name) StaticElement(const char* name)
: m_name(name) : m_name(name)
@ -71,13 +65,15 @@ private:
attrs_t m_attrs; attrs_t m_attrs;
}; };
///\brief All string pointers passed to an instance of this class are copied.
class DynamicElement : public XMLElement class DynamicElement : public XMLElement
{ {
typedef std::map<CopiedString, CopiedString> attrs_t; typedef std::map<CopiedString, CopiedString> attrs_t;
public: public:
DynamicElement(const char* name) DynamicElement(const char* name)
: m_name(name) : m_name(name)
{} {
}
void insertAttribute(const char* name, const char* value) void insertAttribute(const char* name, const char* value)
{ {
m_attrs.insert(attrs_t::value_type(name, value)); m_attrs.insert(attrs_t::value_type(name, value));

View file

@ -30,6 +30,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "math/curve.h" #include "math/curve.h"
#include "stream/stringstream.h" #include "stream/stringstream.h"
#include "signal/signal.h"
#include "selectionlib.h" #include "selectionlib.h"
#include "render.h" #include "render.h"
#include "stringio.h" #include "stringio.h"
@ -339,8 +340,7 @@ const int NURBS_degree = 3;
class NURBSCurve class NURBSCurve
{ {
typedef std::set<Callback> Callbacks; Signal0 m_curveChanged;
Callbacks m_curveChanged;
Callback m_boundsChanged; Callback m_boundsChanged;
public: public:
ControlPoints m_controlPoints; ControlPoints m_controlPoints;
@ -354,18 +354,18 @@ public:
{ {
} }
void attach(const Callback& curveChanged) SignalHandlerId connect(const SignalHandler& curveChanged)
{ {
m_curveChanged.insert(curveChanged);
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() void notify()
{ {
std::for_each(m_curveChanged.begin(), m_curveChanged.end(), CallbackInvoke()); m_curveChanged();
} }
void tesselate() void tesselate()
@ -437,8 +437,7 @@ public:
class CatmullRomSpline class CatmullRomSpline
{ {
typedef std::set<Callback> Callbacks; Signal0 m_curveChanged;
Callbacks m_curveChanged;
Callback m_boundsChanged; Callback m_boundsChanged;
public: public:
ControlPoints m_controlPoints; ControlPoints m_controlPoints;
@ -450,18 +449,18 @@ public:
{ {
} }
void attach(const Callback& curveChanged) SignalHandlerId connect(const SignalHandler& curveChanged)
{ {
m_curveChanged.insert(curveChanged);
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() void notify()
{ {
std::for_each(m_curveChanged.begin(), m_curveChanged.end(), CallbackInvoke()); m_curveChanged();
} }
void tesselate() void tesselate()

View file

@ -96,7 +96,9 @@ class Doom3Group :
public: public:
NURBSCurve m_curveNURBS; NURBSCurve m_curveNURBS;
SignalHandlerId m_curveNURBSChanged;
CatmullRomSpline m_curveCatmullRom; CatmullRomSpline m_curveCatmullRom;
SignalHandlerId m_curveCatmullRomChanged;
private: private:
mutable AABB m_curveBounds; mutable AABB m_curveBounds;
@ -522,8 +524,8 @@ public:
m_curveCatmullRom(m_contained.m_curveCatmullRom.m_controlPointsTransformed, SelectionChangedComponentCaller(*this)) m_curveCatmullRom(m_contained.m_curveCatmullRom.m_controlPointsTransformed, SelectionChangedComponentCaller(*this))
{ {
m_contained.instanceAttach(Instance::path()); m_contained.instanceAttach(Instance::path());
m_contained.m_curveNURBS.attach(CurveEdit::CurveChangedCaller(m_curveNURBS)); m_contained.m_curveNURBSChanged = m_contained.m_curveNURBS.connect(CurveEdit::CurveChangedCaller(m_curveNURBS));
m_contained.m_curveCatmullRom.attach(CurveEdit::CurveChangedCaller(m_curveCatmullRom)); m_contained.m_curveCatmullRomChanged = m_contained.m_curveCatmullRom.connect(CurveEdit::CurveChangedCaller(m_curveCatmullRom));
StaticRenderableConnectionLines::instance().attach(*this); StaticRenderableConnectionLines::instance().attach(*this);
} }
@ -531,8 +533,8 @@ public:
{ {
StaticRenderableConnectionLines::instance().detach(*this); StaticRenderableConnectionLines::instance().detach(*this);
m_contained.m_curveCatmullRom.detach(CurveEdit::CurveChangedCaller(m_curveCatmullRom)); m_contained.m_curveCatmullRom.disconnect(m_contained.m_curveCatmullRomChanged);
m_contained.m_curveNURBS.detach(CurveEdit::CurveChangedCaller(m_curveNURBS)); m_contained.m_curveNURBS.disconnect(m_contained.m_curveNURBSChanged);
m_contained.instanceDetach(Instance::path()); m_contained.instanceDetach(Instance::path());
} }
void renderSolid(Renderer& renderer, const VolumeTest& volume) const void renderSolid(Renderer& renderer, const VolumeTest& volume) const

View file

@ -25,7 +25,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "entitylib.h" #include "entitylib.h"
#include <map> #include <map>
class KeyObserverMap : public EntityKeyValues::Observer class KeyObserverMap : public Entity::Observer
{ {
typedef std::multimap<const char*, KeyObserver, RawStringLess> KeyObservers; typedef std::multimap<const char*, KeyObserver, RawStringLess> KeyObservers;
KeyObservers m_keyObservers; KeyObservers m_keyObservers;
@ -34,14 +34,14 @@ public:
{ {
m_keyObservers.insert(KeyObservers::value_type(key, observer)); 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) for(KeyObservers::const_iterator i = m_keyObservers.find(key); i != m_keyObservers.end() && string_equal((*i).first, key); ++i)
{ {
value.attach((*i).second); 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) for(KeyObservers::const_iterator i = m_keyObservers.find(key); i != m_keyObservers.end() && string_equal((*i).first, key); ++i)
{ {

View file

@ -48,11 +48,11 @@ public:
}; };
typedef MemberCaller1<KeyValue, const char*, &KeyValue::assign> KeyValueAssignCaller; typedef MemberCaller1<EntityKeyValue, const char*, &EntityKeyValue::assign> KeyValueAssignCaller;
typedef MemberCaller1<KeyValue, const KeyObserver&, &KeyValue::attach> KeyValueAttachCaller; typedef MemberCaller1<EntityKeyValue, const KeyObserver&, &EntityKeyValue::attach> KeyValueAttachCaller;
typedef MemberCaller1<KeyValue, const KeyObserver&, &KeyValue::detach> KeyValueDetachCaller; 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; Namespace* m_namespace;
EntityKeyValues& m_entity; EntityKeyValues& m_entity;
@ -60,10 +60,10 @@ class NameKeys : public EntityKeyValues::Observer, public Namespaced
NameKeys(const NameKeys& other); NameKeys(const NameKeys& other);
NameKeys& operator=(const NameKeys& other); NameKeys& operator=(const NameKeys& other);
typedef std::map<CopiedString, EntityKeyValues::Value*> KeyValues; typedef std::map<CopiedString, EntityKeyValue*> KeyValues;
KeyValues m_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)) if(m_namespace != 0 && m_keyIsName(key))
{ {
@ -71,7 +71,7 @@ class NameKeys : public EntityKeyValues::Observer, public Namespaced
m_namespace->attach(KeyValueAssignCaller(value), KeyValueAttachCaller(value)); 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)) if(m_namespace != 0 && m_keyIsName(key))
{ {
@ -114,12 +114,12 @@ public:
m_keyIsName = keyIsName; m_keyIsName = keyIsName;
insertAll(); insertAll();
} }
void insert(const char* key, EntityKeyValues::Value& value) void insert(const char* key, EntityKeyValue& value)
{ {
m_keyValues.insert(KeyValues::value_type(key, &value)); m_keyValues.insert(KeyValues::value_type(key, &value));
insertName(key, value); insertName(key, value);
} }
void erase(const char* key, EntityKeyValues::Value& value) void erase(const char* key, EntityKeyValue& value)
{ {
eraseName(key, value); eraseName(key, value);
m_keyValues.erase(key); m_keyValues.erase(key);

View file

@ -209,7 +209,7 @@ public:
} }
}; };
class TargetKeys : public EntityKeyValues::Observer class TargetKeys : public Entity::Observer
{ {
TargetingEntities m_targetingEntities; TargetingEntities m_targetingEntities;
Callback m_targetsChanged; Callback m_targetsChanged;
@ -236,7 +236,7 @@ public:
m_targetsChanged(); m_targetsChanged();
} }
void insert(const char* key, EntityKeyValues::Value& value) void insert(const char* key, EntityKeyValue& value)
{ {
std::size_t index; std::size_t index;
if(readTargetKey(key, index)) if(readTargetKey(key, index))
@ -246,7 +246,7 @@ public:
targetsChanged(); targetsChanged();
} }
} }
void erase(const char* key, EntityKeyValues::Value& value) void erase(const char* key, EntityKeyValue& value)
{ {
std::size_t index; std::size_t index;
if(readTargetKey(key, index)) if(readTargetKey(key, index))
@ -328,7 +328,7 @@ public:
class TargetableInstance : class TargetableInstance :
public SelectableInstance, public SelectableInstance,
public Targetable, public Targetable,
public EntityKeyValues::Observer public Entity::Observer
{ {
mutable Vertex3f m_position; mutable Vertex3f m_position;
EntityKeyValues& m_entity; EntityKeyValues& m_entity;
@ -368,14 +368,14 @@ public:
m_targeting.targetsChanged(); 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)) if(string_equal(key, g_targetable_nameKey))
{ {
value.attach(TargetedEntity::TargetnameChangedCaller(m_targeted)); 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)) if(string_equal(key, g_targetable_nameKey))
{ {

View file

@ -20,17 +20,18 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "brush.h" #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() void Brush_textureChanged()
{ {
std::for_each(g_brushTextureChangedCallbacks.begin(), g_brushTextureChangedCallbacks.end(), CallbackInvoke()); g_brushTextureChangedCallbacks();
} }
QuantiseFunc Face::m_quantise; QuantiseFunc Face::m_quantise;

View file

@ -60,6 +60,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "texturelib.h" #include "texturelib.h"
#include "container/container.h" #include "container/container.h"
#include "generic/bitfield.h" #include "generic/bitfield.h"
#include "signal/signalfwd.h"
#include "winding.h" #include "winding.h"
#include "brush_primit.h" #include "brush_primit.h"
@ -560,13 +561,6 @@ public:
}; };
inline void FaceShader_getFlags(const FaceShader& faceShader, ContentsFlagsValue& flags)
{
flags = faceShader.getFlags();
}
class FaceTexdef : public FaceShaderObserver class FaceTexdef : public FaceShaderObserver
@ -703,11 +697,6 @@ public:
} }
}; };
inline void FaceTexdef_getTexdef(const FaceTexdef& faceTexdef, TextureProjection& projection)
{
projection = faceTexdef.normalised();
}
inline void planepts_print(const PlanePoints& planePoints, TextOutputStream& ostream) inline void planepts_print(const PlanePoints& planePoints, TextOutputStream& ostream)
{ {
ostream << "( " << planePoints[0][0] << " " << planePoints[0][1] << " " << planePoints[0][2] << " ) " ostream << "( " << planePoints[0][0] << " " << planePoints[0][1] << " " << planePoints[0][2] << " ) "
@ -938,6 +927,10 @@ public:
} }
}; };
inline void Winding_testSelect(Winding& winding, SelectionTest& test, SelectionIntersection& best)
{
test.TestPolygon(VertexPointer(reinterpret_cast<VertexPointer::pointer>(&winding.points.data()->vertex), sizeof(WindingVertex)), winding.numpoints, best);
}
const double GRID_MIN = 0.125; const double GRID_MIN = 0.125;
@ -963,7 +956,7 @@ public:
bool face_filtered(Face& face); bool face_filtered(Face& face);
void Brush_addTextureChangedCallback(const Callback& callback); void Brush_addTextureChangedCallback(const SignalHandler& callback);
void Brush_textureChanged(); void Brush_textureChanged();
@ -1269,10 +1262,9 @@ public:
} }
} }
void testSelect(SelectionTest& test, SelectionIntersection& best) 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) void testSelect_centroid(SelectionTest& test, SelectionIntersection& best)
@ -1311,6 +1303,10 @@ public:
Brush_textureChanged(); Brush_textureChanged();
} }
void GetTexdef(TextureProjection& projection) const
{
projection = m_texdef.normalised();
}
void SetTexdef(const TextureProjection& projection) void SetTexdef(const TextureProjection& projection)
{ {
undoSave(); undoSave();
@ -1318,6 +1314,10 @@ public:
texdefChanged(); texdefChanged();
} }
void GetFlags(ContentsFlagsValue& flags) const
{
flags = m_shader.getFlags();
}
void SetFlags(const ContentsFlagsValue& flags) void SetFlags(const ContentsFlagsValue& flags)
{ {
undoSave(); undoSave();
@ -2145,12 +2145,12 @@ public:
{ {
return m_faces.back(); 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) 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 push_back(Faces::value_type face)
@ -2203,6 +2203,7 @@ public:
void clear() void clear()
{ {
undoSave();
if(m_instanceCounter.m_count != 0) if(m_instanceCounter.m_count != 0)
{ {
forEachFace_instanceDetach(m_map); forEachFace_instanceDetach(m_map);
@ -3557,12 +3558,13 @@ public:
} }
typedef MemberCaller1<BrushInstance, const Selectable&, &BrushInstance::selectedChangedComponent> SelectedChangedComponentCaller; 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) for(FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i)
{ {
visitor.visit(*i); visitor.visit(*i);
} }
return visitor;
} }
static void constructStatic() static void constructStatic()
@ -3985,9 +3987,10 @@ public:
}; };
template<typename Functor> template<typename Functor>
inline void Scene_forEachSelectedBrush(const Functor& functor) inline const Functor& Scene_forEachSelectedBrush(const Functor& functor)
{ {
GlobalSelectionSystem().foreachSelected(BrushSelectedVisitor<Functor>(functor)); GlobalSelectionSystem().foreachSelected(BrushSelectedVisitor<Functor>(functor));
return functor;
} }
template<typename Functor> template<typename Functor>
@ -4010,9 +4013,192 @@ public:
}; };
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)); 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 #endif

View file

@ -37,14 +37,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include <list> #include <list>
void Brush_ConstructCuboid(Brush& brush, const AABB& bounds, const char* shader, const TextureProjection& projection) 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 } }; const unsigned char box[3][2] = { { 0, 1 }, { 2, 0 }, { 1, 2 } };
Vector3 mins(vector3_subtracted(bounds.origin, bounds.extents)); Vector3 mins(vector3_subtracted(bounds.origin, bounds.extents));
Vector3 maxs(vector3_added(bounds.origin, bounds.extents)); Vector3 maxs(vector3_added(bounds.origin, bounds.extents));
brush.undoSave();
brush.clear(); brush.clear();
brush.reserve(6); brush.reserve(6);
@ -107,7 +105,6 @@ void Brush_ConstructPrism(Brush& brush, const AABB& bounds, std::size_t sides, i
return; return;
} }
brush.undoSave();
brush.clear(); brush.clear();
brush.reserve(sides+2); brush.reserve(sides+2);
@ -180,7 +177,6 @@ void Brush_ConstructCone(Brush& brush, const AABB& bounds, std::size_t sides, co
return; return;
} }
brush.undoSave();
brush.clear(); brush.clear();
brush.reserve(sides+1); brush.reserve(sides+1);
@ -235,7 +231,6 @@ void Brush_ConstructSphere(Brush& brush, const AABB& bounds, std::size_t sides,
return; return;
} }
brush.undoSave();
brush.clear(); brush.clear();
brush.reserve(sides*sides); brush.reserve(sides*sides);
@ -362,168 +357,14 @@ void ConstructRegionBrushes(scene::Node* brushes[6], const Vector3& region_mins,
} }
class BrushForEachFace class FaceSetTexdef
{
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
{ {
const TextureProjection& m_projection; const TextureProjection& m_projection;
public: 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); face.SetTexdef(m_projection);
} }
@ -531,26 +372,25 @@ public:
void Scene_BrushSetTexdef_Selected(scene::Graph& graph, const TextureProjection& projection) void Scene_BrushSetTexdef_Selected(scene::Graph& graph, const TextureProjection& projection)
{ {
Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetTexdefVisitor(projection)); Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetTexdef(projection));
SceneChangeNotify(); SceneChangeNotify();
} }
void Scene_BrushSetTexdef_Component_Selected(scene::Graph& graph, const TextureProjection& projection) void Scene_BrushSetTexdef_Component_Selected(scene::Graph& graph, const TextureProjection& projection)
{ {
FaceSetTexdefVisitor visitor(projection); Scene_ForEachSelectedBrushFace(graph, FaceSetTexdef(projection));
Scene_ForEachSelectedBrushFace(graph, visitor);
SceneChangeNotify(); SceneChangeNotify();
} }
class FaceSetFlagsVisitor class FaceSetFlags
{ {
const ContentsFlagsValue& m_projection; const ContentsFlagsValue& m_projection;
public: 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); face.SetFlags(m_projection);
} }
@ -558,25 +398,24 @@ public:
void Scene_BrushSetFlags_Selected(scene::Graph& graph, const ContentsFlagsValue& flags) void Scene_BrushSetFlags_Selected(scene::Graph& graph, const ContentsFlagsValue& flags)
{ {
Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetFlagsVisitor(flags)); Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetFlags(flags));
SceneChangeNotify(); SceneChangeNotify();
} }
void Scene_BrushSetFlags_Component_Selected(scene::Graph& graph, const ContentsFlagsValue& flags) void Scene_BrushSetFlags_Component_Selected(scene::Graph& graph, const ContentsFlagsValue& flags)
{ {
FaceSetFlagsVisitor visitor(flags); Scene_ForEachSelectedBrushFace(graph, FaceSetFlags(flags));
Scene_ForEachSelectedBrushFace(graph, visitor);
SceneChangeNotify(); SceneChangeNotify();
} }
class FaceShiftTexdefVisitor class FaceShiftTexdef
{ {
float m_s, m_t; float m_s, m_t;
public: 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); face.ShiftTexdef(m_s, m_t);
} }
@ -584,25 +423,24 @@ public:
void Scene_BrushShiftTexdef_Selected(scene::Graph& graph, float s, float 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(); SceneChangeNotify();
} }
void Scene_BrushShiftTexdef_Component_Selected(scene::Graph& graph, float s, float t) void Scene_BrushShiftTexdef_Component_Selected(scene::Graph& graph, float s, float t)
{ {
FaceShiftTexdefVisitor visitor(s, t); Scene_ForEachSelectedBrushFace(graph, FaceShiftTexdef(s, t));
Scene_ForEachSelectedBrushFace(graph, visitor);
SceneChangeNotify(); SceneChangeNotify();
} }
class FaceScaleTexdefVisitor class FaceScaleTexdef
{ {
float m_s, m_t; float m_s, m_t;
public: 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); face.ScaleTexdef(m_s, m_t);
} }
@ -610,25 +448,24 @@ public:
void Scene_BrushScaleTexdef_Selected(scene::Graph& graph, float s, float 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(); SceneChangeNotify();
} }
void Scene_BrushScaleTexdef_Component_Selected(scene::Graph& graph, float s, float t) void Scene_BrushScaleTexdef_Component_Selected(scene::Graph& graph, float s, float t)
{ {
FaceScaleTexdefVisitor visitor(s, t); Scene_ForEachSelectedBrushFace(graph, FaceScaleTexdef(s, t));
Scene_ForEachSelectedBrushFace(graph, visitor);
SceneChangeNotify(); SceneChangeNotify();
} }
class FaceRotateTexdefVisitor class FaceRotateTexdef
{ {
float m_angle; float m_angle;
public: 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); face.RotateTexdef(m_angle);
} }
@ -636,24 +473,23 @@ public:
void Scene_BrushRotateTexdef_Selected(scene::Graph& graph, float angle) void Scene_BrushRotateTexdef_Selected(scene::Graph& graph, float angle)
{ {
Scene_ForEachSelectedBrush_ForEachFace(graph, FaceRotateTexdefVisitor(angle)); Scene_ForEachSelectedBrush_ForEachFace(graph, FaceRotateTexdef(angle));
SceneChangeNotify(); SceneChangeNotify();
} }
void Scene_BrushRotateTexdef_Component_Selected(scene::Graph& graph, float angle) void Scene_BrushRotateTexdef_Component_Selected(scene::Graph& graph, float angle)
{ {
FaceRotateTexdefVisitor visitor(angle); Scene_ForEachSelectedBrushFace(graph, FaceRotateTexdef(angle));
Scene_ForEachSelectedBrushFace(graph, visitor);
SceneChangeNotify(); SceneChangeNotify();
} }
class FaceSetShaderVisitor class FaceSetShader
{ {
const char* m_name; const char* m_name;
public: public:
FaceSetShaderVisitor(const char* name) : m_name(name) {} FaceSetShader(const char* name) : m_name(name) {}
void visit(Face& face) const void operator()(Face& face) const
{ {
face.SetShader(m_name); face.SetShader(m_name);
} }
@ -661,25 +497,24 @@ public:
void Scene_BrushSetShader_Selected(scene::Graph& graph, const char* name) void Scene_BrushSetShader_Selected(scene::Graph& graph, const char* name)
{ {
Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetShaderVisitor(name)); Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetShader(name));
SceneChangeNotify(); SceneChangeNotify();
} }
void Scene_BrushSetShader_Component_Selected(scene::Graph& graph, const char* name) void Scene_BrushSetShader_Component_Selected(scene::Graph& graph, const char* name)
{ {
FaceSetShaderVisitor visitor(name); Scene_ForEachSelectedBrushFace(graph, FaceSetShader(name));
Scene_ForEachSelectedBrushFace(graph, visitor);
SceneChangeNotify(); SceneChangeNotify();
} }
class FaceSetDetailVisitor class FaceSetDetail
{ {
bool m_detail; bool m_detail;
public: 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); face.setDetail(m_detail);
} }
@ -687,7 +522,7 @@ public:
void Scene_BrushSetDetail_Selected(scene::Graph& graph, bool detail) void Scene_BrushSetDetail_Selected(scene::Graph& graph, bool detail)
{ {
Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetDetailVisitor(detail)); Scene_ForEachSelectedBrush_ForEachFace(graph, FaceSetDetail(detail));
SceneChangeNotify(); SceneChangeNotify();
} }
@ -701,15 +536,15 @@ bool Face_FindReplaceShader(Face& face, const char* find, const char* replace)
return false; return false;
} }
class FaceFindReplaceShaderVisitor class FaceFindReplaceShader
{ {
const char* m_find; const char* m_find;
const char* m_replace; const char* m_replace;
public: 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); Face_FindReplaceShader(face, m_find, m_replace);
} }
@ -717,29 +552,28 @@ public:
void Scene_BrushFindReplaceShader(scene::Graph& graph, const char* find, const char* 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) 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) void Scene_BrushFindReplaceShader_Component_Selected(scene::Graph& graph, const char* find, const char* replace)
{ {
FaceFindReplaceShaderVisitor visitor(find, replace); Scene_ForEachSelectedBrushFace(graph, FaceFindReplaceShader(find, replace));
Scene_ForEachSelectedBrushFace(graph, visitor);
} }
class FaceFitTextureVisitor class FaceFitTexture
{ {
float m_s_repeat, m_t_repeat; float m_s_repeat, m_t_repeat;
public: 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); face.FitTexture(m_s_repeat, m_t_repeat);
} }
@ -747,17 +581,22 @@ public:
void Scene_BrushFitTexture_Selected(scene::Graph& graph, float s_repeat, float 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(); SceneChangeNotify();
} }
void Scene_BrushFitTexture_Component_Selected(scene::Graph& graph, float s_repeat, float t_repeat) void Scene_BrushFitTexture_Component_Selected(scene::Graph& graph, float s_repeat, float t_repeat)
{ {
FaceFitTextureVisitor visitor(s_repeat, t_repeat); Scene_ForEachSelectedBrushFace(graph, FaceFitTexture(s_repeat, t_repeat));
Scene_ForEachSelectedBrushFace(graph, visitor);
SceneChangeNotify(); 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) void Scene_BrushConstructPrefab(scene::Graph& graph, EBrushPrefab type, std::size_t sides, const char* shader)
{ {
@ -768,10 +607,8 @@ void Scene_BrushConstructPrefab(scene::Graph& graph, EBrushPrefab type, std::siz
Brush* brush = Node_getBrush(path.top()); Brush* brush = Node_getBrush(path.top());
if(brush != 0) if(brush != 0)
{ {
AABB bounds = brush->localAABB(); AABB bounds = brush->localAABB(); // copy bounds because the brush will be modified
TextureProjection projection; Brush_ConstructPrefab(*brush, type, bounds, sides, shader, TextureTransform_getDefault());
TexDef_Construct_Default(projection);
Brush_ConstructPrefab(*brush, type, bounds, sides, shader, projection);
SceneChangeNotify(); SceneChangeNotify();
} }
} }
@ -786,9 +623,7 @@ void Scene_BrushResize_Selected(scene::Graph& graph, const AABB& bounds, const c
Brush* brush = Node_getBrush(path.top()); Brush* brush = Node_getBrush(path.top());
if(brush != 0) if(brush != 0)
{ {
TextureProjection projection; Brush_ConstructCuboid(*brush, bounds, shader, TextureTransform_getDefault());
TexDef_Construct_Default(projection);
Brush_ConstructCuboid(*brush, bounds, shader, projection);
SceneChangeNotify(); SceneChangeNotify();
} }
} }
@ -833,15 +668,15 @@ void Scene_BrushSelectByShader(scene::Graph& graph, const char* name)
graph.traverse(BrushSelectByShaderWalker(name)); graph.traverse(BrushSelectByShaderWalker(name));
} }
class FaceSelectByShaderVisitor : public BrushInstanceVisitor class FaceSelectByShader
{ {
const char* m_name; const char* m_name;
public: public:
FaceSelectByShaderVisitor(const char* name) FaceSelectByShader(const char* name)
: m_name(name) : m_name(name)
{ {
} }
void visit(FaceInstance& face) const void operator()(FaceInstance& face) const
{ {
if(shader_equal(face.getFace().GetShader(), m_name)) if(shader_equal(face.getFace().GetShader(), m_name))
{ {
@ -852,24 +687,24 @@ public:
void Scene_BrushSelectByShader_Component(scene::Graph& graph, const char* 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; TextureProjection& m_projection;
mutable bool m_done; mutable bool m_done;
public: public:
FaceGetTexdefVisitor(TextureProjection& projection) FaceGetTexdef(TextureProjection& projection)
: m_projection(projection), m_done(false) : m_projection(projection), m_done(false)
{ {
} }
void visit(Face& face) const void operator()(Face& face) const
{ {
if(!m_done) if(!m_done)
{ {
m_done = true; m_done = true;
FaceTexdef_getTexdef(face.getTexdef(), m_projection); face.GetTexdef(m_projection);
} }
} }
}; };
@ -877,8 +712,7 @@ public:
void Scene_BrushGetTexdef_Selected(scene::Graph& graph, TextureProjection& projection) void Scene_BrushGetTexdef_Selected(scene::Graph& graph, TextureProjection& projection)
{ {
FaceGetTexdefVisitor visitor(projection); Scene_ForEachSelectedBrush_ForEachFace(graph, FaceGetTexdef(projection));
Scene_ForEachSelectedBrush_ForEachFace(graph, visitor);
} }
void Scene_BrushGetTexdef_Component_Selected(scene::Graph& graph, TextureProjection& projection) void Scene_BrushGetTexdef_Component_Selected(scene::Graph& graph, TextureProjection& projection)
@ -887,30 +721,30 @@ void Scene_BrushGetTexdef_Component_Selected(scene::Graph& graph, TextureProject
if(!g_SelectedFaceInstances.empty()) if(!g_SelectedFaceInstances.empty())
{ {
FaceInstance& faceInstance = g_SelectedFaceInstances.last(); FaceInstance& faceInstance = g_SelectedFaceInstances.last();
FaceTexdef_getTexdef(faceInstance.getFace().getTexdef(), projection); faceInstance.getFace().GetTexdef(projection);
} }
#else #else
FaceGetTexdefVisitor visitor(projection); FaceGetTexdef visitor(projection);
Scene_ForEachSelectedBrushFace(graph, visitor); Scene_ForEachSelectedBrushFace(graph, visitor);
#endif #endif
} }
class FaceGetFlagsVisitor class FaceGetFlags
{ {
ContentsFlagsValue& m_flags; ContentsFlagsValue& m_flags;
mutable bool m_done; mutable bool m_done;
public: public:
FaceGetFlagsVisitor(ContentsFlagsValue& flags) FaceGetFlags(ContentsFlagsValue& flags)
: m_flags(flags), m_done(false) : m_flags(flags), m_done(false)
{ {
} }
void visit(Face& face) const void operator()(Face& face) const
{ {
if(!m_done) if(!m_done)
{ {
m_done = true; m_done = true;
FaceShader_getFlags(face.getShader(), m_flags); face.GetFlags(m_flags);
} }
} }
}; };
@ -918,8 +752,18 @@ public:
void Scene_BrushGetFlags_Selected(scene::Graph& graph, ContentsFlagsValue& flags) void Scene_BrushGetFlags_Selected(scene::Graph& graph, ContentsFlagsValue& flags)
{ {
FaceGetFlagsVisitor visitor(flags); #if 1
Scene_ForEachSelectedBrush_ForEachFace(graph, visitor); 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) void Scene_BrushGetFlags_Component_Selected(scene::Graph& graph, ContentsFlagsValue& flags)
@ -928,38 +772,47 @@ void Scene_BrushGetFlags_Component_Selected(scene::Graph& graph, ContentsFlagsVa
if(!g_SelectedFaceInstances.empty()) if(!g_SelectedFaceInstances.empty())
{ {
FaceInstance& faceInstance = g_SelectedFaceInstances.last(); FaceInstance& faceInstance = g_SelectedFaceInstances.last();
FaceShader_getFlags(faceInstance.getFace().getShader(), flags); faceInstance.getFace().GetFlags(flags);
} }
#else #else
FaceGetFlagsVisitor visitor(flags); Scene_ForEachSelectedBrushFace(graph, FaceGetFlags(flags));
Scene_ForEachSelectedBrushFace(graph, visitor);
#endif #endif
} }
class FaceGetShaderVisitor class FaceGetShader
{ {
CopiedString& m_shader; CopiedString& m_shader;
mutable bool m_done; mutable bool m_done;
public: public:
FaceGetShaderVisitor(CopiedString& shader) FaceGetShader(CopiedString& shader)
: m_shader(shader), m_done(false) : m_shader(shader), m_done(false)
{ {
} }
void visit(Face& face) const void operator()(Face& face) const
{ {
if(!m_done) if(!m_done)
{ {
m_done = true; m_done = true;
m_shader = face.getShader().getShader(); m_shader = face.GetShader();
} }
} }
}; };
void Scene_BrushGetShader_Selected(scene::Graph& graph, CopiedString& shader) void Scene_BrushGetShader_Selected(scene::Graph& graph, CopiedString& shader)
{ {
FaceGetShaderVisitor visitor(shader); #if 1
Scene_ForEachSelectedBrush_ForEachFace(graph, visitor); 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) void Scene_BrushGetShader_Component_Selected(scene::Graph& graph, CopiedString& shader)
@ -968,10 +821,10 @@ void Scene_BrushGetShader_Component_Selected(scene::Graph& graph, CopiedString&
if(!g_SelectedFaceInstances.empty()) if(!g_SelectedFaceInstances.empty())
{ {
FaceInstance& faceInstance = g_SelectedFaceInstances.last(); FaceInstance& faceInstance = g_SelectedFaceInstances.last();
shader = faceInstance.getFace().getShader().getShader(); shader = faceInstance.getFace().GetShader();
} }
#else #else
FaceGetShaderVisitor visitor(shader); FaceGetShader visitor(shader);
Scene_ForEachSelectedBrushFace(graph, visitor); Scene_ForEachSelectedBrushFace(graph, visitor);
#endif #endif
} }
@ -1031,16 +884,16 @@ public:
class FaceFilterAnyVisitor : public BrushVisitor class FaceFilterAny
{ {
FaceFilter* m_filter; FaceFilter* m_filter;
bool& m_filtered; bool& m_filtered;
public: 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; m_filtered = false;
} }
void visit(Face& face) const void operator()(Face& face) const
{ {
if(m_filter->filter(face)) if(m_filter->filter(face))
{ {
@ -1059,21 +912,21 @@ public:
bool filter(const Brush& brush) const bool filter(const Brush& brush) const
{ {
bool filtered; bool filtered;
brush.forEachFace(FaceFilterAnyVisitor(m_filter, filtered)); Brush_forEachFace(brush, FaceFilterAny(m_filter, filtered));
return filtered; return filtered;
} }
}; };
class FaceFilterAllVisitor : public BrushVisitor class FaceFilterAll
{ {
FaceFilter* m_filter; FaceFilter* m_filter;
bool& m_filtered; bool& m_filtered;
public: 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; m_filtered = true;
} }
void visit(Face& face) const void operator()(Face& face) const
{ {
if(!m_filter->filter(face)) if(!m_filter->filter(face))
{ {
@ -1092,7 +945,7 @@ public:
bool filter(const Brush& brush) const bool filter(const Brush& brush) const
{ {
bool filtered; bool filtered;
brush.forEachFace(FaceFilterAllVisitor(m_filter, filtered)); Brush_forEachFace(brush, FaceFilterAll(m_filter, filtered));
return filtered; return filtered;
} }
}; };
@ -1602,7 +1455,7 @@ bool Scene_BrushGetClosestFaceTexture(scene::Graph& graph, SelectionTest& test,
if(face != 0) if(face != 0)
{ {
shader = face->GetShader(); shader = face->GetShader();
FaceTexdef_getTexdef(face->getTexdef(), projection); face->GetTexdef(projection);
flags = face->getShader().m_flags; flags = face->getShader().m_flags;
return true; return true;
} }
@ -1671,7 +1524,7 @@ void SelectedFaces_copyTexture()
if(!g_SelectedFaceInstances.empty()) if(!g_SelectedFaceInstances.empty())
{ {
Face& face = g_SelectedFaceInstances.last().getFace(); 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; g_faceTextureClipboard.m_flags = face.getShader().m_flags;
TextureBrowser_SetSelectedShader(g_TextureBrowser, face.getShader().getShader()); TextureBrowser_SetSelectedShader(g_TextureBrowser, face.getShader().getShader());

View file

@ -22,7 +22,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#if !defined (INCLUDED_BRUSHWRAPPER_H) #if !defined (INCLUDED_BRUSHWRAPPER_H)
#define INCLUDED_BRUSHWRAPPER_H #define INCLUDED_BRUSHWRAPPER_H
#include "string/string.h" #include <cstddef>
#include "string/stringfwd.h"
#include "generic/callbackfwd.h"
enum EBrushPrefab enum EBrushPrefab
{ {
@ -67,8 +69,6 @@ void Scene_BrushSelectByShader_Component(scene::Graph& graph, const char* name);
void Scene_BrushFitTexture_Selected(scene::Graph& graph, float s_repeat, float t_repeat); 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); void Scene_BrushFitTexture_Component_Selected(scene::Graph& graph, float s_repeat, float t_repeat);
class Callback;
typedef struct _GtkMenu GtkMenu; typedef struct _GtkMenu GtkMenu;
void Brush_constructMenu(GtkMenu* menu); void Brush_constructMenu(GtkMenu* menu);

View file

@ -157,6 +157,21 @@ void Brush_clipperColourChanged()
BrushClipPlane::constructStatic(); 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 class Quake3BrushCreator : public BrushCreator
{ {
@ -169,6 +184,14 @@ public:
{ {
return g_useAlternativeTextureProjection.m_value; 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; Quake3BrushCreator g_Quake3BrushCreator;

View file

@ -37,7 +37,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "renderable.h" #include "renderable.h"
#include "preferencesystem.h" #include "preferencesystem.h"
#include "generic/callback.h" #include "signal/signal.h"
#include "container/array.h" #include "container/array.h"
#include "scenelib.h" #include "scenelib.h"
#include "render.h" #include "render.h"
@ -60,16 +60,16 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "timer.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() void CameraMovedNotify()
{ {
std::for_each(g_cameraMoved_callbacks.begin(), g_cameraMoved_callbacks.end(), CallbackInvoke()); g_cameraMoved_callbacks();
} }
@ -1120,6 +1120,7 @@ void CamWnd_Move_Discrete_Import(bool value)
} }
void CamWnd_Add_Handlers_Move(CamWnd& camwnd) 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); 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);

View file

@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#define INCLUDED_CAMWINDOW_H #define INCLUDED_CAMWINDOW_H
#include "math/vector.h" #include "math/vector.h"
#include "signal/signalfwd.h"
typedef struct _GtkWidget GtkWidget; typedef struct _GtkWidget GtkWidget;
typedef struct _GtkWindow GtkWindow; typedef struct _GtkWindow GtkWindow;
@ -31,8 +32,7 @@ class CamWnd;
CamWnd* NewCamWnd(); CamWnd* NewCamWnd();
void DeleteCamWnd(CamWnd* camwnd); void DeleteCamWnd(CamWnd* camwnd);
class Callback; void AddCameraMovedCallback(const SignalHandler& handler);
void AddCameraMovedCallback(const Callback& callback);
void CamWnd_Update(CamWnd& camwnd); void CamWnd_Update(CamWnd& camwnd);

Some files were not shown because too many files have changed in this diff Show more