PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Updates to [code] [/code]

Chris Edwards · 16 Jan 2002, 00:35 UTC
I have made a few improvements to the code function today..

1. ( and ) are replaced with their valid html code ONLY in the code box, so that smiley's won't be in your code.

2. Look at that nifty scroll bar at the bottom... Isn't it nice?.. it happens when lines are really long so that you don't lose track of lines in the code, and it doesn't screw the width of the page up.

3. There isn't a three... but Dan said he wants to work on building a colour coding scheme thing into the [ code ] blocks. We'll see how that turns out... that would be really cool..

Anyways.. here's an example of our scroll bar things:

Code:
This is a great example, it is only one line, so everything is cool, isn't it?... yep, it all is pretty cool.
this is another line... exciting, eh?

:) :) :) -- see, no smiles!!!

:) :) :) -- see... smiles!!
Part of that smily is covered by the scroll bar, but maybe I'm just too picky.
wow thats relatively neat
Code:
Woo, i am in a box, look at me boxy woooooooooooo
Chris Edwards · 16 Jan 2002, 00:51 UTC
Yeah.. I'll fix that tomorrow... I've got huge amounts of homework to do now.
Code:
yeah, awesome
It's a very good feature. I like the bigger font, and the scrollbar is simply awesome.

Here's the sourcecode for the Nutcracker:

Code:

/*
THE NUTCRACKER
*/
#define _UL_GENERATE_CODE_

#include "ssgLocal.h"

#ifndef WIN32
# ifndef macintosh
# include <GL/glx.h>
# else
# include <agl.h>
# endif
#endif

static bool glIsValidContext ()
{
#if defined(CONSOLE)
return true ;
#elif defined(WIN32)
return ( wglGetCurrentContext () != NULL ) ;
#elif defined(macintosh)
return ( aglGetCurrentContext() != NULL ) ;
#else
return ( glXGetCurrentContext() != NULL ) ;
#endif
}

sgMat4 _ssgOpenGLAxisSwapMatrix =
{
{ 1.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, -1.0f, 0.0f },
{ 0.0f, 1.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 0.0f, 1.0f }
} ;

sgVec3 _ssgVertex000 = { 0.0f, 0.0f, 0.0f } ;
sgVec4 _ssgColourWhite = { 1.0f, 1.0f, 1.0f, 1.0f } ;
sgVec3 _ssgNormalUp = { 0.0f, 0.0f, 1.0f } ;
sgVec2 _ssgTexCoord00 = { 0.0f, 0.0f } ;
short _ssgIndex0 = 0;

ssgLight _ssgLights [ 8 ] ;
int _ssgFrameCounter = 0 ;

int ssgGetFrameCounter () { return _ssgFrameCounter ; }
void ssgSetFrameCounter ( int fc ) { _ssgFrameCounter = fc ; }

char *ssgGetVersion ()
{
#ifdef VERSION
return VERSION ;
#else
return "Unknown" ;
#endif
}

void ssgDeRefDelete ( ssgBase *s )
{
if ( s == NULL ) return ;

s -> deRef () ;

if ( s -> getRef () <= 0 )
delete s ;
}

void ssgDelete ( ssgBranch *br )
{
if ( br == NULL )
return ;

br -> removeAllKids () ;
delete br ;
}

ssgLight *ssgGetLight ( int i )
{
return &_ssgLights [ i ] ;
}

void ssgInit ()
{
if ( ! glIsValidContext () )
{
ulSetError ( UL_FATAL, "ssgInit called without a valid OpenGL context.");
}

ssgTexturePath ( "." ) ;
ssgModelPath ( "." ) ;

_ssgLights [ 0 ] . setID ( 0 ) ;
_ssgLights [ 0 ] . on () ;

for ( int i = 1 ; i < 8 ; i++ )
{
_ssgLights [ i ] . setID ( i ) ;
_ssgLights [ i ] . off () ;
}

new ssgContext ; /* Sets the current context with defaults */

ssgAddModelFormat ( ".ssg", ssgLoadSSG , ssgSaveSSG ) ;

ssgAddModelFormat ( ".3ds", ssgLoad3ds , ssgSave3ds ) ;
ssgAddModelFormat ( ".ac" , ssgLoadAC3D , ssgSaveAC ) ;
ssgAddModelFormat ( ".ase", ssgLoadASE , ssgSaveASE ) ;
ssgAddModelFormat ( ".dxf", ssgLoadDXF , ssgSaveDXF ) ;
ssgAddModelFormat ( ".obj", ssgLoadOBJ , ssgSaveOBJ ) ;
ssgAddModelFormat ( ".tri", ssgLoadTRI , ssgSaveTRI ) ;
ssgAddModelFormat ( ".md2", ssgLoadMD2 , NULL ) ;
ssgAddModelFormat ( ".x" , ssgLoadX , ssgSaveX ) ;
ssgAddModelFormat ( ".flt", ssgLoadFLT , NULL ) ;
ssgAddModelFormat ( ".strip", ssgLoadStrip, NULL ) ;
ssgAddModelFormat ( ".m" , ssgLoadM , ssgSaveM ) ;
ssgAddModelFormat ( ".off" , ssgLoadOFF , ssgSaveOFF ) ;
ssgAddModelFormat ( ".atg" , ssgLoadATG , ssgSaveATG ) ;
ssgAddModelFormat ( ".qhi" , NULL , ssgSaveQHI ) ;


#ifdef SSG_LOAD_MDL_SUPPORTED
ssgAddModelFormat ( ".mdl", ssgLoadMDL , NULL ) ;
#endif

#ifdef SSG_LOAD_TGA_SUPPORTED
ssgAddTextureFormat ( ".tga" , ssgLoadTGA ) ;
#endif

#ifdef SSG_LOAD_BMP_SUPPORTED
ssgAddTextureFormat ( ".bmp" , ssgLoadBMP ) ;
#endif

#ifdef SSG_LOAD_PNG_SUPPORTED
ssgAddTextureFormat ( ".png" , ssgLoadPNG ) ;
#endif

#ifdef SSG_LOAD_SGI_SUPPORTED
ssgAddTextureFormat ( ".rgb" , ssgLoadSGI ) ;
ssgAddTextureFormat ( ".rgba" , ssgLoadSGI ) ;
ssgAddTextureFormat ( ".int" , ssgLoadSGI ) ;
ssgAddTextureFormat ( ".inta" , ssgLoadSGI ) ;
ssgAddTextureFormat ( ".bw" , ssgLoadSGI ) ;
#endif

#ifdef SSG_LOAD_MDL_SUPPORTED
ssgAddTextureFormat ( ".0af" , ssgLoadMDLTexture ) ;
ssgAddTextureFormat ( ".1af" , ssgLoadMDLTexture ) ;
ssgAddTextureFormat ( ".2af" , ssgLoadMDLTexture ) ;
ssgAddTextureFormat ( ".3af" , ssgLoadMDLTexture ) ;
ssgAddTextureFormat ( ".4af" , ssgLoadMDLTexture ) ;
ssgAddTextureFormat ( ".5af" , ssgLoadMDLTexture ) ;
ssgAddTextureFormat ( ".6af" , ssgLoadMDLTexture ) ;
ssgAddTextureFormat ( ".7af" , ssgLoadMDLTexture ) ;
ssgAddTextureFormat ( ".8af" , ssgLoadMDLTexture ) ;
ssgAddTextureFormat ( ".9af" , ssgLoadMDLTexture ) ;
ssgAddTextureFormat ( ".aaf" , ssgLoadMDLTexture ) ;
ssgAddTextureFormat ( ".baf" , ssgLoadMDLTexture ) ;
ssgAddTextureFormat ( ".caf" , ssgLoadMDLTexture ) ;
ssgAddTextureFormat ( ".daf" , ssgLoadMDLTexture ) ;
ssgAddTextureFormat ( ".eaf" , ssgLoadMDLTexture ) ;
ssgAddTextureFormat ( ".faf" , ssgLoadMDLTexture ) ;
ssgAddTextureFormat ( ".gaf" , ssgLoadMDLTexture ) ;
ssgAddTextureFormat ( ".haf" , ssgLoadMDLTexture ) ;
ssgAddTextureFormat ( ".iaf" , ssgLoadMDLTexture ) ;
ssgAddTextureFormat ( ".jaf" , ssgLoadMDLTexture ) ;
ssgAddTextureFormat ( ".kaf" , ssgLoadMDLTexture ) ;
#endif

}



void ssgCullAndPick ( ssgRoot *r, sgVec2 botleft, sgVec2 topright )
{
if ( _ssgCurrentContext == NULL )
{
ulSetError ( UL_FATAL, "ssg: No Current Context: Did you forgot to call ssgInit()?" ) ;
}

ssgForceBasicState () ;

int vp [ 4 ] ;
sgVec4 viewport ;
sgMat4 mat ;

float w = (topright[0] - botleft[0]) ;
float h = (topright[1] - botleft[1]) ;

float x = (botleft[0] + topright[0]) / 2.0f ;
float y = (botleft[1] + topright[1]) / 2.0f ;

glGetIntegerv ( GL_VIEWPORT, vp ) ;

sgSetVec4 ( viewport, (float)vp[0], (float)vp[1],
(float)vp[2], (float)vp[3] ) ;
sgMakePickMatrix ( mat, x, y, w, h, viewport ) ;

glMatrixMode ( GL_PROJECTION ) ;
glLoadIdentity () ;
glMultMatrixf ( (float *) mat ) ;

_ssgCurrentContext->pushProjectionMatrix () ;

glMatrixMode ( GL_MODELVIEW ) ;
glLoadIdentity () ;

int i ;

for ( i = 0 ; i < 8 ; i++ )
if ( _ssgLights [ i ] . isHeadlight () )
_ssgLights [ i ] . setup () ;

_ssgCurrentContext->loadModelviewMatrix () ;

for ( i = 0 ; i < 8 ; i++ )
if ( ! _ssgLights [ i ] . isHeadlight () )
_ssgLights [ i ] . setup () ;

_ssgCurrentContext->cull(r) ;
_ssgDrawDList () ;

glMatrixMode ( GL_MODELVIEW ) ;
glLoadIdentity () ;
}


void ssgCullAndDraw ( ssgRoot *r )
{
if ( _ssgCurrentContext == NULL )
{
ulSetError ( UL_FATAL, "ssg: No Current Context: Did you forgot to call ssgInit()?" ) ;
}

ssgForceBasicState () ;

glMatrixMode ( GL_PROJECTION ) ;
_ssgCurrentContext->loadProjectionMatrix () ;

glMatrixMode ( GL_MODELVIEW ) ;
glLoadIdentity () ;

int i ;

for ( i = 0 ; i < 8 ; i++ )
if ( _ssgLights [ i ] . isHeadlight () )
_ssgLights [ i ] . setup () ;

_ssgCurrentContext->loadModelviewMatrix () ;
_ssgCurrentContext->applyClipPlanes () ;

for ( i = 0 ; i < 8 ; i++ )
if ( ! _ssgLights [ i ] . isHeadlight () )
_ssgLights [ i ] . setup () ;

_ssgCurrentContext->cull(r) ;
_ssgDrawDList () ;

_ssgCurrentContext->removeClipPlanes () ;

glMatrixMode ( GL_MODELVIEW ) ;
glLoadIdentity () ;

_ssgFrameCounter++ ;
}


char *ssgAxisTransform::getTypeName (void) { return "ssgAxisTransform" ; }
char *ssgBase ::getTypeName (void) { return "ssgBase" ; }
char *ssgTexture ::getTypeName (void) { return "ssgTexture" ; }
char *ssgState ::getTypeName (void) { return "ssgState" ; }
char *ssgSimpleState ::getTypeName (void) { return "ssgSimpleState" ; }
char *ssgStateSelector::getTypeName (void) { return "ssgStateSelector" ; }
char *ssgEntity ::getTypeName (void) { return "ssgEntity" ; }
char *ssgLeaf ::getTypeName (void) { return "ssgLeaf" ; }
char *ssgVTable ::getTypeName (void) { return "ssgVTable" ; }
char *ssgVtxTable ::getTypeName (void) { return "ssgVtxTable" ; }
char *ssgVtxArray ::getTypeName (void) { return "ssgVtxArray" ; }
char *ssgBranch ::getTypeName (void) { return "ssgBranch" ; }
char *ssgSelector ::getTypeName (void) { return "ssgSelector" ; }
char *ssgRangeSelector::getTypeName (void) { return "ssgRangeSelector" ; }
char *ssgTimedSelector::getTypeName (void) { return "ssgTimedSelector" ; }
char *ssgBaseTransform::getTypeName (void) { return "ssgBaseTransform" ; }
char *ssgTransform ::getTypeName (void) { return "ssgTransform" ; }
char *ssgTexTrans ::getTypeName (void) { return "ssgTexTrans" ; }
char *ssgCutout ::getTypeName (void) { return "ssgCutout" ; }
char *ssgRoot ::getTypeName (void) { return "ssgRoot" ; }

char *ssgSimpleList ::getTypeName (void) { return "ssgSimpleList" ; }
char *ssgColourArray ::getTypeName (void) { return "ssgColourArray" ; }
char *ssgIndexArray ::getTypeName (void) { return "ssgIndexArray" ; }
char *ssgTransformArray::getTypeName (void) { return "ssgTransformArray" ; }
char *ssgTexCoordArray::getTypeName (void) { return "ssgTexCoordArray" ; }
char *ssgVertexArray ::getTypeName (void) { return "ssgVertexArray" ; }
char *ssgNormalArray ::getTypeName (void) { return "ssgNormalArray" ; }
char *ssgInterleavedArray::getTypeName (void) { return "ssgInterleavedArray"; }



static ssgBase *createBase () { return new ssgBase ; }

//static ssgBase *createEntity () { return new ssgEntity ; }
//static ssgBase *createLeaf () { return new ssgLeaf ; }
static ssgBase *createVTable () { return new ssgVTable ; }
static ssgBase *createVtxTable () { return new ssgVtxTable ; }
static ssgBase *createVtxArray () { return new ssgVtxArray ; }
static ssgBase *createBranch () { return new ssgBranch ; }
//static ssgBase *createBaseTransform () { return new ssgBaseTransform ; }
static ssgBase *createTransform () { return new ssgTransform ; }
static ssgBase *createTexTrans () { return new ssgTexTrans ; }
static ssgBase *createSelector () { return new ssgSelector ; }
static ssgBase *createRangeSelector () { return new ssgRangeSelector ; }
static ssgBase *createTimedSelector () { return new ssgTimedSelector ; }
static ssgBase *createRoot () { return new ssgRoot ; }
static ssgBase *createCutout () { return new ssgCutout ; }
static ssgBase *createInvisible () { return new ssgInvisible ; }

//static ssgBase *createState () { return new ssgState ; }
static ssgBase *createSimpleState () { return new ssgSimpleState ; }
static ssgBase *createStateSelector () { return new ssgStateSelector ; }

static ssgBase *createSimpleList () { return new ssgSimpleList ; }
static ssgBase *createVertexArray () { return new ssgVertexArray ; }
static ssgBase *createNormalArray () { return new ssgNormalArray ; }
static ssgBase *createTexCoordArray () { return new ssgTexCoordArray ; }
static ssgBase *createColourArray () { return new ssgColourArray ; }
static ssgBase *createIndexArray () { return new ssgIndexArray ; }
static ssgBase *createTransformArray () { return new ssgTransformArray ; }
static ssgBase *createInterleavedArray () { return new ssgInterleavedArray ; }

static ssgBase *createTexture () { return new ssgTexture ; }


static struct {

int type ;
ssgBase * ( *func ) () ;

} table[256] = {

{ ssgTypeBase () , createBase },

//{ ssgTypeEntity () , createEntity },
//{ ssgTypeLeaf () , createLeaf },
{ ssgTypeVTable () , createVTable },
{ ssgTypeVtxTable () , createVtxTable },
{ ssgTypeVtxArray () , createVtxArray },
{ ssgTypeBranch () , createBranch },
//{ ssgTypeBaseTransform () , createBaseTransform },
{ ssgTypeTransform () , createTransform },
{ ssgTypeTexTrans () , createTexTrans },
{ ssgTypeSelector () , createSelector },
{ ssgTypeRangeSelector () , createRangeSelector },
{ ssgTypeTimedSelector () , createTimedSelector },
{ ssgTypeRoot () , createRoot },
{ ssgTypeCutout () , createCutout },
{ ssgTypeInvisible () , createInvisible },

//{ ssgTypeState () , createState },
{ ssgTypeSimpleState () , createSimpleState },
{ ssgTypeStateSelector () , createStateSelector },

{ ssgTypeSimpleList () , createSimpleList },
{ ssgTypeVertexArray () , createVertexArray },
{ ssgTypeNormalArray () , createNormalArray },
{ ssgTypeTexCoordArray () , createTexCoordArray },
{ ssgTypeColourArray () , createColourArray },
{ ssgTypeIndexArray () , createIndexArray },
{ ssgTypeTransformArray () , createTransformArray },
{ ssgTypeInterleavedArray () , createInterleavedArray },

{ ssgTypeTexture () , createTexture },

{ 0, NULL }

};

void ssgRegisterType ( int type, ssgBase * ( *func ) () )
{
if ( type == 0 || func == NULL )
{
ulSetError ( UL_WARNING, "ssgRegisterType: Bad arguments (type %#x, func %p).",
type, func ) ;
return ;
}

int i ;
for ( i = 0 ; table[i].type != 0 && table[i].type != type ; i++ )
;

if ( table[i].type == type && table[i].func != func )
ulSetError ( UL_WARNING, "ssgRegisterType: Type %#x redefined differently.", type ) ;

table[i].type = type ;
table[i].func = func ;
}

ssgBase *ssgCreateOfType ( int type )
{
// XXX linear search
int i ;
for ( i = 0 ; table[i].type != 0 && table[i].type != type ; i++ )
;

if ( table[i].type == 0 )
{
ulSetError ( UL_WARNING, "ssgCreateOfType: Unrecognized type %#x.", type ) ;
return NULL ;
}

ssgBase *obj = (*table[i].func) () ;

if ( obj == NULL )
ulSetError ( UL_WARNING, "ssgCreateOfType: Got null object for type %#x.", type ) ;
else if ( obj -> getType () != type )
ulSetError ( UL_WARNING,
"ssgCreateOfType: Created object has wrong type %#x (%s), expected %#x.",
obj -> getType (), obj -> getTypeName (), type ) ;

return obj ;
}
Oops, wrong source. :)
yes, that is indeed very cool. But shouldn't there be a scrollbar on the right as well. I noticed I had to scroll all the way to the bottom, in order to get to the horizontal scrollbar. If the box had a maxheight, you could have all the scrollbars on a single page.

I know, snippets usually aren't that big. Can't wait to see the color-coded stuff.
Getting more and more like the Flipcode for PPCs everyday.

-Hosed
I'm pretty sure Chris could set a max height and use a vert scrollbar if it is exceeded. Chris, I would set it for at least 50 lines or so.

The syntactic keyword coloring php script is done, and works very well (if I do say so myself :) ). It would be online already, but the actual integration into the phpBB code isn't very straightforward. Hopefully it will be online later today.
The only thing that is not working to my knowledge is coloring #include strings:
#include <stdio.h>
In that example the stdio.h is not colored like a string.

If we can figure out a way to pass parameters via the [ code ] tags, then I will allow additional formatting options, like line numbers, and how many spaces a tab should be translated into (I'm currently using 4, which is what eVC uses). I can perhaps add support for additional languages besides C / C++, which could also be specified as a parameter in the code tag.

Dan East
Well, 50 lines would be too many. Perhaps 35 or 40.

I've added a summary to the syntactic coloring that shows various stats about the source (number of lines, operators, keywords, comments, etc).

BTW, the topic review window when you post is very cool. It does not hold up the loading of the page, sorts the posts so the most recent is on top, and doesn't make the page 5000 lines tall for big threads. This BB is such a massive improvement over what we had before that it's hard to even realize how much better off we are.

Dan East
Dan East · 16 Jan 2002, 15:29 UTC — test
testing:
Code:

code
code
[code]
more code
code
[code]
more code
[/code]
[/code]
some code


Dan East
Chris Edwards · 16 Jan 2002, 15:47 UTC
yeah... the embedded code is a bit screwed up... I guess I could fix it, but there isn't much point... how often would that be used?
Never.

Dan East
Anyone wishing to help test the syntactic keyword coloring script can do so here: http://dex-plor.com/test/c_format.php

Please report any inconsistencies you may find. As I've already said, it is currently not properly coloring the filename after #include directives as a string.

Thanks!

Dan East
Chris Edwards · 16 Jan 2002, 16:50 UTC
Ok, just a tip... to scroll in the code blocks when you can't see the scrollbar:

click anywhere in the code block... use arrow keys to scroll.