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

@@ -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
*/
#include "StdAfx.h"
#include "DTrainDrawer.h"
#include "gtkr_list.h"
#include <list>
#include "str.h"
#include "DPoint.h"
@@ -28,31 +28,33 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "DEPair.h"
#include "DPatch.h"
#include "DEntity.h"
#include "DTrainDrawer.h"
#include "misc.h"
#include "funchandlers.h"
#include "iglrender.h"
#include "math/matrix.h"
#include "dialogs/dialogs-gtk.h"
DTrainDrawer::DTrainDrawer() {
refCount = 1;
m_bHooked = FALSE;
m_bDisplay = FALSE;
m_bDisplay = false;
BuildPaths();
constructShaders();
GlobalShaderCache().attachRenderable(*this);
}
DTrainDrawer::~DTrainDrawer(void) {
if(m_bHooked)
UnRegister();
GlobalShaderCache().detachRenderable(*this);
destroyShaders();
ClearPoints();
ClearSplines();
}
void DTrainDrawer::ClearSplines() {
for(list<splinePoint_t *>::const_iterator deadSpline = m_splineList.begin(); deadSpline != m_splineList.end(); deadSpline++) {
for(std::list<splinePoint_t *>::const_iterator deadSpline = m_splineList.begin(); deadSpline != m_splineList.end(); deadSpline++) {
(*deadSpline)->m_pointList.clear();
(*deadSpline)->m_vertexList.clear();
delete (*deadSpline);
@@ -62,25 +64,13 @@ void DTrainDrawer::ClearSplines() {
}
void DTrainDrawer::ClearPoints() {
for(list<controlPoint_t *>::const_iterator deadPoint = m_pointList.begin(); deadPoint != m_pointList.end(); deadPoint++) {
for(std::list<controlPoint_t *>::const_iterator deadPoint = m_pointList.begin(); deadPoint != m_pointList.end(); deadPoint++) {
delete *deadPoint;
}
m_pointList.clear();
}
void DTrainDrawer::Register() {
__QGLTABLENAME.m_pfnHookGL2DWindow( this );
__QGLTABLENAME.m_pfnHookGL3DWindow( this );
m_bHooked = TRUE;
}
void DTrainDrawer::UnRegister() {
__QGLTABLENAME.m_pfnUnHookGL2DWindow( this );
__QGLTABLENAME.m_pfnUnHookGL3DWindow( this );
m_bHooked = FALSE;
}
void CalculateSpline_r(vec3_t* v, int count, vec3_t out, float tension) {
vec3_t dist;
@@ -106,93 +96,70 @@ void CalculateSpline_r(vec3_t* v, int count, vec3_t out, float tension) {
delete[] v2;
}
void DTrainDrawer::Draw3D() {
if(!m_bDisplay) {
return;
}
__QGLTABLENAME.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS);
__QGLTABLENAME.m_pfn_qglDisable(GL_BLEND);
__QGLTABLENAME.m_pfn_qglDisable(GL_LINE_SMOOTH);
__QGLTABLENAME.m_pfn_qglPushMatrix();
__QGLTABLENAME.m_pfn_qglLineWidth(2.0f);
__QGLTABLENAME.m_pfn_qglColor4f(1.0f, 1.0f, 1.0f, 1.0f);
__QGLTABLENAME.m_pfn_qglEnable(GL_BLEND);
__QGLTABLENAME.m_pfn_qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
__QGLTABLENAME.m_pfn_qglDisable(GL_POLYGON_SMOOTH);
__QGLTABLENAME.m_pfn_qglDepthFunc(GL_ALWAYS);
for(list<splinePoint_t* >::const_iterator sp = m_splineList.begin(); sp != m_splineList.end(); sp++) {
void DTrainDrawer::render(RenderStateFlags state) const
{
for(std::list<splinePoint_t* >::const_iterator sp = m_splineList.begin(); sp != m_splineList.end(); sp++) {
splinePoint_t* pSP = (*sp);
__QGLTABLENAME.m_pfn_qglBegin(GL_LINE_STRIP);
for(list<DPoint >::const_iterator v = pSP->m_vertexList.begin(); v != pSP->m_vertexList.end(); v++) {
__QGLTABLENAME.m_pfn_qglVertex3fv((*v)._pnt);
glBegin(GL_LINE_STRIP);
for(std::list<DPoint >::const_iterator v = pSP->m_vertexList.begin(); v != pSP->m_vertexList.end(); v++) {
glVertex3fv((*v)._pnt);
}
__QGLTABLENAME.m_pfn_qglEnd();
glEnd();
}
__QGLTABLENAME.m_pfn_qglPopMatrix();
__QGLTABLENAME.m_pfn_qglPopAttrib();
}
void DTrainDrawer::Draw2D(VIEWTYPE vt) {
const char* DTrainDrawer_state_wireframe = "$bobtoolz/traindrawer/wireframe";
const char* DTrainDrawer_state_solid = "$bobtoolz/traindrawer/solid";
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) {
return;
}
__QGLTABLENAME.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS);
__QGLTABLENAME.m_pfn_qglDisable(GL_BLEND);
__QGLTABLENAME.m_pfn_qglDisable(GL_LINE_SMOOTH);
__QGLTABLENAME.m_pfn_qglPushMatrix();
switch(vt)
{
case XY:
break;
case XZ:
__QGLTABLENAME.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f);
break;
case YZ:
__QGLTABLENAME.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f);
__QGLTABLENAME.m_pfn_qglRotatef(270.0f, 0.0f, 0.0f, 1.0f);
break;
}
__QGLTABLENAME.m_pfn_qglLineWidth(1.0f);
__QGLTABLENAME.m_pfn_qglColor4f(1.0f, 0.0f, 0.0f, 0.5f);
__QGLTABLENAME.m_pfn_qglEnable(GL_BLEND);
__QGLTABLENAME.m_pfn_qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
__QGLTABLENAME.m_pfn_qglDisable(GL_POLYGON_SMOOTH);
__QGLTABLENAME.m_pfn_qglDepthFunc(GL_ALWAYS);
__QGLTABLENAME.m_pfn_qglColor4f(1.f, 0.f, 0.f, 1.f);
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();
renderer.SetState(m_shader_wireframe, Renderer::eWireframeOnly);
renderer.SetState(m_shader_solid, Renderer::eFullMaterials);
renderer.addRenderable(*this, g_matrix4_identity);
}
void DTrainDrawer::renderWireframe(Renderer& renderer, const VolumeTest& volume) const
{
renderSolid(renderer, volume);
}
void AddSplineControl(const char* control, splinePoint_t* pSP) {
@@ -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++) {
splinePoint_t* pSP = (*sp);
@@ -278,7 +245,7 @@ void DTrainDrawer::BuildPaths() {
pSP->pTarget = pTarget;
for(list<controlPoint_t >::iterator cp = pSP->m_pointList.begin(); cp != pSP->m_pointList.end(); cp++) {
for(std::list<controlPoint_t >::iterator cp = pSP->m_pointList.begin(); cp != pSP->m_pointList.end(); cp++) {
controlPoint_t* pControl = FindControlPoint( (*cp).strName );
if(!pControl) {
Sys_Printf( "couldn't find control %s", (*cp).strName );
@@ -306,7 +273,7 @@ void DTrainDrawer::BuildPaths() {
VectorCopy(pSP->point.vOrigin, v[0]);
int i = 1;
for(list<controlPoint_t>::reverse_iterator cp = pSP->m_pointList.rbegin(); cp != pSP->m_pointList.rend(); cp++) {
for(std::list<controlPoint_t>::reverse_iterator cp = pSP->m_pointList.rbegin(); cp != pSP->m_pointList.rend(); cp++) {
VectorCopy((*cp).vOrigin, v[i]);
i++;
}
@@ -350,13 +317,13 @@ splinePoint_t* DTrainDrawer::AddSplinePoint(const char* name, const char* target
controlPoint_t* DTrainDrawer::FindControlPoint(const char* name)
{
for(list<controlPoint_t*>::const_iterator cp = m_pointList.begin(); cp != m_pointList.end(); cp++) {
for(std::list<controlPoint_t*>::const_iterator cp = m_pointList.begin(); cp != m_pointList.end(); cp++) {
if(!strcmp(name, (*cp)->strName)) {
return (*cp);
}
}
for(list<splinePoint_t*>::const_iterator sp = m_splineList.begin(); sp != m_splineList.end(); sp++) {
for(std::list<splinePoint_t*>::const_iterator sp = m_splineList.begin(); sp != m_splineList.end(); sp++) {
if(!strcmp(name, (*sp)->point.strName)) {
return &((*sp)->point);
}