Tutorial *77*

If you've followed the QSG Coloured Lighting Tutorials (and who hasn't?) you may have noticed a bug when you add a Brush Model (eg. a Health Box/Ammo Box/Exploding Box) to a map. Because the Brush Model is a different Version to the BSP, the engine will get confused.

There are a number of possible solutions to this: you could expand White Light for a version 29 BSP to RGBA in Mod_LoadLighting, or make Coloured Light versions of the Models for use in a map with coloured light in it, for example.

I offer a totally different way, that lets you get away with this with a minimum of messing around, and also lets you put Brush Models with Coloured Light in a BSP with White Light. This is a true fix, not a work-around.

(Note: If the parameters to any functions are changed, you'll also have to change the prototypes for the functions. But you already knew that.)

1. gl_model.h changes.
Look for the definition of the msurface_s/msurface_t structure and add the following right at the very end:


    // coloured lighting

    qboolean    rgb;    // true if surface is lit in colour

You're going to have to recompile the full engine after this, so you might as well do so now.
2. gl_model.c changes.
Look for the Mod_loadFaces function. Replace the declaration with this:


    void Mod_LoadFaces (lump_t *l, int is_coloured)

A little further down in the function (at the start of the first for... loop) add:


        if (is_coloured)

            out->rgb = true;

        else out->rgb = false;

Next, go to the Mod_LoadBrushModel function, and replace the following:


    if (!bspextensions)

        bspextensions = i - BSPVERSION;

with plain old...


    bspextensions = i - BSPVERSION;

Further down, replace the call to Mod_LoadFaces with:


    Mod_LoadFaces (&header->lumps[LUMP_FACES], bspextensions);

And after


    mod->numframes = 2;         // regular and alternate animation

Add:


    // MFAH - reset bspextensions for the next brush model

    bspextensions = 0;

    // MFAH - reset bspextensions for the next brush model

I'm not sure if it's necessary to reset bspextensions here (in other words I haven't tested it without doing so) but it does no harm, so what the hell...

3. gl_rsurf.c changes.
In the R_BuildLightMap function, replace the entire if (lightmap) block with:


    if (lightmap)

    {

        if (surf->rgb)

        {

            for (maps = 0 ; maps < MAXLIGHTMAPS && surf->styles[maps] != 255 ; maps++)

            {

                scale = d_lightstylevalue[surf->styles[maps]];

                surf->cached_light[maps] = scale; // 8.8 fraction



                for (i=0, j=0 ; i< MAXLIGHTMAPS && surf->styles[maps] != 255 ; maps++)

            {

                scale = d_lightstylevalue[surf->styles[maps]];

                surf->cached_light[maps] = scale; // 8.8 fraction



                for (i=0, j=0 ; i
4. sv_main.c changes.
Go to the SV_SpawnServer function, and right at the top (after the variables) add:


    // MFAH - reset bspextensions for the next server

    bspextensions = 0;

    // MFAH - reset bspextensions for the next server

Once again, I'm not sure if it's necessary to reset bspextensions here (in other words I haven't tested it without doing so) but it does no harm, so what the hell...

The usual compile and enjoy final directives apply...


 
Sign up
Login:
Passwd:
[Remember Me]