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:
@@ -21,16 +21,21 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "DBobView.h"
|
||||
#include "DListener.h"
|
||||
//#include "misc.h"
|
||||
#include "funchandlers.h"
|
||||
|
||||
#include "gtkr_list.h"
|
||||
#include "str.h"
|
||||
#include <list>
|
||||
|
||||
#include "iglrender.h"
|
||||
#include "qerplugin.h"
|
||||
#include "str.h"
|
||||
#include "math/matrix.h"
|
||||
|
||||
#include "DEntity.h"
|
||||
#include "DEPair.h"
|
||||
#include "misc.h"
|
||||
#include "dialogs/dialogs-gtk.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
@@ -39,29 +44,23 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
DBobView::DBobView()
|
||||
{
|
||||
nPathCount = 0;
|
||||
refCount = 1;
|
||||
|
||||
m_bHooked = FALSE;
|
||||
|
||||
path = NULL;
|
||||
eyes = NULL;
|
||||
|
||||
boundingShow = BOUNDS_APEX;
|
||||
|
||||
constructShaders();
|
||||
GlobalShaderCache().attachRenderable(*this);
|
||||
}
|
||||
|
||||
DBobView::~DBobView()
|
||||
{
|
||||
if(path)
|
||||
GlobalShaderCache().detachRenderable(*this);
|
||||
destroyShaders();
|
||||
|
||||
if(path)
|
||||
delete[] path;
|
||||
|
||||
// oops forgot to remove our eyes, was causing access violation when it tried
|
||||
// to talk to it's parent
|
||||
if(eyes)
|
||||
delete eyes;
|
||||
|
||||
if(m_bHooked)
|
||||
UnRegister();
|
||||
|
||||
g_PathView = NULL;
|
||||
}
|
||||
|
||||
@@ -69,201 +68,77 @@ DBobView::~DBobView()
|
||||
// Implementation
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
void DBobView::Draw2D(VIEWTYPE vt)
|
||||
void DBobView::render(RenderStateFlags state) const
|
||||
{
|
||||
if(!path)
|
||||
return;
|
||||
|
||||
__QGLTABLENAME.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS);
|
||||
|
||||
__QGLTABLENAME.m_pfn_qglDisable(GL_BLEND);
|
||||
__QGLTABLENAME.m_pfn_qglEnable(GL_LINE_SMOOTH);
|
||||
|
||||
__QGLTABLENAME.m_pfn_qglPushMatrix();
|
||||
|
||||
switch(vt)
|
||||
{
|
||||
case XY:
|
||||
break;
|
||||
case XZ:
|
||||
__QGLTABLENAME.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f);
|
||||
break;
|
||||
case YZ:
|
||||
__QGLTABLENAME.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f);
|
||||
__QGLTABLENAME.m_pfn_qglRotatef(270.0f, 0.0f, 0.0f, 1.0f);
|
||||
break;
|
||||
}
|
||||
|
||||
__QGLTABLENAME.m_pfn_qglLineWidth(1.0f);
|
||||
__QGLTABLENAME.m_pfn_qglColor4f(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
int i;
|
||||
|
||||
__QGLTABLENAME.m_pfn_qglBegin(GL_LINE_STRIP);
|
||||
|
||||
for(i = 0; i < nPathCount; i++)
|
||||
__QGLTABLENAME.m_pfn_qglVertex3fv(path[i]);
|
||||
|
||||
__QGLTABLENAME.m_pfn_qglEnd();
|
||||
|
||||
if(m_bShowExtra)
|
||||
{
|
||||
// +mars
|
||||
// for the bounding box stuff
|
||||
__QGLTABLENAME.m_pfn_qglColor4f(0.25f, 0.75f, 0.75f, 1.0f);
|
||||
|
||||
__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);
|
||||
glBegin(GL_LINE_STRIP);
|
||||
|
||||
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)
|
||||
{
|
||||
// +mars
|
||||
// ahhh -- a nice C&P job :)
|
||||
// for the bounding box stuff
|
||||
__QGLTABLENAME.m_pfn_qglColor4f(0.25f, 0.75f, 0.75f, 1.0f);
|
||||
|
||||
__QGLTABLENAME.m_pfn_qglTranslatef( 16.0f, 16.0f, 28.0f );
|
||||
|
||||
__QGLTABLENAME.m_pfn_qglBegin( GL_LINE_STRIP );
|
||||
|
||||
int i;
|
||||
for ( i = 0; i < nPathCount; i++ )
|
||||
__QGLTABLENAME.m_pfn_qglVertex3fv( path[i] );
|
||||
|
||||
__QGLTABLENAME.m_pfn_qglEnd();
|
||||
|
||||
// ---------------
|
||||
|
||||
__QGLTABLENAME.m_pfn_qglTranslatef( -16.0f, -16.0f, -28.0f ); // back to where we were
|
||||
__QGLTABLENAME.m_pfn_qglTranslatef( -16.0f, 16.0f, 28.0f ); // move to new postion
|
||||
|
||||
__QGLTABLENAME.m_pfn_qglBegin( GL_LINE_STRIP );
|
||||
|
||||
for ( i = 0; i < nPathCount; i++ )
|
||||
__QGLTABLENAME.m_pfn_qglVertex3fv( path[i] );
|
||||
|
||||
__QGLTABLENAME.m_pfn_qglEnd();
|
||||
|
||||
// --------------
|
||||
|
||||
__QGLTABLENAME.m_pfn_qglTranslatef( 16.0f, -16.0f, -28.0f ); // back to where we were
|
||||
__QGLTABLENAME.m_pfn_qglTranslatef( 16.0f, -16.0f, -28.0f ); // new pos
|
||||
|
||||
__QGLTABLENAME.m_pfn_qglBegin( GL_LINE_STRIP );
|
||||
|
||||
for ( i = 0; i < nPathCount; i++ )
|
||||
__QGLTABLENAME.m_pfn_qglVertex3fv( path[i] );
|
||||
|
||||
__QGLTABLENAME.m_pfn_qglEnd();
|
||||
|
||||
// ----------------
|
||||
|
||||
__QGLTABLENAME.m_pfn_qglTranslatef( -16.0f, 16.0f, 28.0f ); // back to where we were
|
||||
__QGLTABLENAME.m_pfn_qglTranslatef( -16.0f, -16.0f, -28.0f ); // new pos
|
||||
|
||||
__QGLTABLENAME.m_pfn_qglBegin( GL_LINE_STRIP );
|
||||
|
||||
for ( i = 0; i < nPathCount; i++ )
|
||||
__QGLTABLENAME.m_pfn_qglVertex3fv( path[i] );
|
||||
|
||||
__QGLTABLENAME.m_pfn_qglEnd();
|
||||
}
|
||||
// -mars
|
||||
|
||||
__QGLTABLENAME.m_pfn_qglPopAttrib();
|
||||
renderer.SetState(m_shader_box, eWireframeOnly);
|
||||
renderer.SetState(m_shader_box, eFullMaterials);
|
||||
renderer.addRenderable(*this, g_transform_box1);
|
||||
renderer.addRenderable(*this, g_transform_box2);
|
||||
renderer.addRenderable(*this, g_transform_box3);
|
||||
renderer.addRenderable(*this, g_transform_box4);
|
||||
}
|
||||
}
|
||||
|
||||
void DBobView::Register()
|
||||
void DBobView::renderWireframe(Renderer& renderer, const VolumeTest& volume) const
|
||||
{
|
||||
__QGLTABLENAME.m_pfnHookGL2DWindow( this );
|
||||
__QGLTABLENAME.m_pfnHookGL3DWindow( this );
|
||||
m_bHooked = TRUE;
|
||||
}
|
||||
|
||||
void DBobView::UnRegister()
|
||||
{
|
||||
__QGLTABLENAME.m_pfnUnHookGL2DWindow( this );
|
||||
__QGLTABLENAME.m_pfnUnHookGL3DWindow( this );
|
||||
m_bHooked = FALSE;
|
||||
renderSolid(renderer, volume);
|
||||
}
|
||||
|
||||
void DBobView::SetPath(vec3_t *pPath)
|
||||
@@ -281,7 +156,7 @@ bool DBobView::CalculateTrajectory(vec3_t start, vec3_t apex, float multiplier,
|
||||
if(apex[2] <= start[2])
|
||||
{
|
||||
SetPath(NULL);
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
// ----think q3a actually would allow these
|
||||
//scrub that, coz the plugin wont :]
|
||||
@@ -319,7 +194,7 @@ bool DBobView::CalculateTrajectory(vec3_t start, vec3_t apex, float multiplier,
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -332,20 +207,9 @@ void DBobView::Begin(const char* trigger, const char *target, float multiplier,
|
||||
nPathCount = points;
|
||||
m_bShowExtra = bShowExtra;
|
||||
|
||||
Register();
|
||||
|
||||
if(UpdatePath())
|
||||
if(!UpdatePath())
|
||||
{
|
||||
if(!bNoUpdate)
|
||||
{
|
||||
eyes = new DListener;
|
||||
eyes->parent = this;
|
||||
eyes->Register();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Sys_ERROR("Initialization Failure in DBobView::Begin");
|
||||
globalErrorStream() << "Initialization Failure in DBobView::Begin";
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
@@ -359,8 +223,55 @@ bool DBobView::UpdatePath()
|
||||
if(GetEntityCentre(entTarget, apex))
|
||||
{
|
||||
CalculateTrajectory(start, apex, fMultiplier, nPathCount, fVarGravity);
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
void DBobView_setEntity(Entity& entity, float multiplier, int points, float varGravity, bool bNoUpdate, bool bShowExtra)
|
||||
{
|
||||
DEntity trigger;
|
||||
trigger.LoadEPairList(&entity);
|
||||
|
||||
DEPair* trigger_ep = trigger.FindEPairByKey("targetname");
|
||||
|
||||
if(trigger_ep)
|
||||
{
|
||||
if(!strcmp(trigger.m_Classname, "trigger_push"))
|
||||
{
|
||||
DEPair* target_ep = trigger.FindEPairByKey("target");
|
||||
if(target_ep)
|
||||
{
|
||||
scene::Path* entTarget = FindEntityFromTargetname(target_ep->value, NULL);
|
||||
if(entTarget)
|
||||
{
|
||||
if(g_PathView)
|
||||
delete g_PathView;
|
||||
g_PathView = new DBobView;
|
||||
|
||||
Entity* target = Node_getEntity(entTarget->top());
|
||||
if(target != 0)
|
||||
{
|
||||
if(!bNoUpdate)
|
||||
{
|
||||
g_PathView->trigger = &entity;
|
||||
entity.attach(*g_PathView);
|
||||
g_PathView->target = target;
|
||||
target->attach(*g_PathView);
|
||||
}
|
||||
g_PathView->Begin(trigger_ep->value, target_ep->value, multiplier, points, varGravity, bNoUpdate, bShowExtra);
|
||||
}
|
||||
}
|
||||
else
|
||||
DoMessageBox("trigger_push target could not be found.", "Error", eMB_OK);
|
||||
}
|
||||
else
|
||||
DoMessageBox("trigger_push has no target.", "Error", eMB_OK);
|
||||
}
|
||||
else
|
||||
DoMessageBox("You must select a 'trigger_push' entity.", "Error", eMB_OK);
|
||||
}
|
||||
else
|
||||
DoMessageBox("Entity must have a targetname", "Error", eMB_OK);
|
||||
}
|
||||
Reference in New Issue
Block a user