Running into a problem improving railtrails


#1

So I’ve been working on improving the effects of weapons in general, and I’ve made some buff to everything except LG and BFG. But I’m running into a problem with railtrails. I started with the purple spiral trail and improved it, imho, by making it a smoke trail. However, the spiral trail only displays one trail properly at once. They disappear after I fire multiple times. Anyone know what’s going on?


#2

Maybe CGame runs out of unused local entities so it frees effects still in use. Check CG_AllocLocalEntity() in code/cgame/cg_localents.c.


#3

Cool. I’ll check that. In the mean time, I made the railtrail pretty!

There’s probably an easier way to do this, but I like it this way because it’s easier for me to read.
Here’s the code:

	vec3_t axis[36], move, move2, next_move, vec, temp;
float  len;
int    i, j, skip;

float groupRand;
localEntity_t *le;
refEntity_t   *re;

float scaleRand;
float posOffs;
float posRand;
float colRand;
int randomize;
int randomizeRadius;
int randomizeDistance;
int randomizeMaxDist;
int lastRandDist;
int shift;
float lerp;
float oldScale;
float oldDist;
 
float scale;

#define RADIUS   4
#define ROTATION 1
#define SPACING  5

oldScale = 0;
shift = 0;
start[2] -4;
VectorCopy (start, move);
VectorSubtract (end, start, vec);
len = VectorNormalize (vec);
PerpendicularVector(temp, vec);


for (i = 0 ; i < 36; i++) {
	RotatePointAroundVector(axis[i], vec, temp, i * 10);//banshee 2.4 was 10
}

le = CG_AllocLocalEntity();
re = &le->refEntity;

le->leType = LE_FADE_RGB;
le->startTime = cg.time;
le->endTime = cg.time + cg_railTrailTime.value;
le->lifeRate = 1.0 / (le->endTime - le->startTime);

re->shaderTime = cg.time / 1000.0f;
re->reType = RT_RAIL_CORE;
//re->customShader = cgs.media.railCoreShader;
re->customShader = cgs.media.lightningShader;

VectorCopy(start, re->origin);
VectorCopy(end, re->oldorigin);

re->shaderRGBA[0] = ci->color1[0] * 255;
re->shaderRGBA[1] = ci->color1[1] * 255;
re->shaderRGBA[2] = ci->color1[2] * 255;
re->shaderRGBA[3] = 255;

le->color[0] = ci->color1[0] * 0.75;
le->color[1] = ci->color1[1] * 0.75;
le->color[2] = ci->color1[2] * 0.75;
le->color[3] = 1.0f;

AxisClear( re->axis );

VectorMA(move, 20, vec, move);
VectorCopy(move, next_move);
VectorScale (vec, SPACING, vec);

if (cg_oldRail.integer != 0) {
	// nudge down a bit so it isn't exactly in center
	re->origin[2] -= 8;
	re->oldorigin[2] -= 8;
	return;
}
skip = -1;

lastRandDist = 0;
randomizeMaxDist = 750;
randomizeDistance = rand() % randomizeMaxDist;

j = 18;
//Com_Printf("%f\n", len);
//Com_Printf("%i\n", ((((int)len)-(((int)len) % SPACING)) / SPACING));
//Com_Printf("%i\n\n", (((int)len) % SPACING));
for (i = 0; i < len; i += SPACING) {
	if (i != skip) {

		if(i>randomizeDistance){
			lastRandDist = i;
			randomizeDistance = (rand() % randomizeMaxDist) + lastRandDist;

			//randomizeDistance = 0;
			if(randomizeDistance > len){
				randomizeDistance = (int)len;
			}

			shift = rand() % 360;
			//Com_Printf("%i\n", randomizeDistance);
		}

		//scaleRandomizeTime
		skip = i + SPACING;
		le = CG_AllocLocalEntity();
        re = &le->refEntity;
        le->leFlags = LEF_PUFF_DONT_SCALE;
		le->leType = LE_MOVE_SCALE_FADE;
        le->startTime = cg.time;
        le->endTime = cg.time + (i>>1) + fabs((crandom() * 2000)) + 2000;
        le->lifeRate = 1.0 / (le->endTime - le->startTime);

		//posOffs = 0;
		//randomize = 0;
		posOffs = 1;
		randomize = 1;
			
		if(randomize == 1){
			scaleRand = 1;
			posRand = 1;
			colRand = 1;
		} else {
			scaleRand = 0;
			posRand = 0;
			colRand = 0;
		}

		scaleRand = 1;

		//shift = 0;

		scale = 30;
		scale = fabs(( (.1 * sinf(DEG2RAD(i+shift)) * .25) + sinf(DEG2RAD((i/10) + shift)))) * scale;


		oldScale = LerpPositionTemp(oldScale, scale, .75);
		//Com_Printf("%f\n", (oldScale/40)-.5);

        re->shaderTime = cg.time / 1000.0f;
        re->reType = RT_SPRITE;
        re->radius = ( scaleRand * (crandom() * 1.5) * oldScale) + 10;
		re->rotation = rand() % 360;

		re->customShader = cgs.media.shotgunSmokePuffShader;

        //re->shaderRGBA[0] = ci->color2[0] * 255;
        //re->shaderRGBA[1] = ci->color2[1] * 255;
        //re->shaderRGBA[2] = ci->color2[2] * 255;

		le->radius = 100;

		groupRand = crandom();
        re->shaderRGBA[0] = (colRand  * (groupRand * 50)) +155;
        re->shaderRGBA[1] = (colRand  * (groupRand * 50)) +155;
        re->shaderRGBA[2] = (colRand  * (groupRand * 50)) +155;
        re->shaderRGBA[3] = 255;

        //le->color[0] = ci->color2[0] * 0.75;
        //le->color[1] = ci->color2[1] * 0.75;
        //le->color[2] = ci->color2[2] * 0.75;


        le->color[0] = 0.75;
        le->color[1] = 0.75;
        le->color[2] = 0.75;

        //le->color[3] = (colRand * (fabs(crandom() * .5 )-.75)) + 1;
        //le->color[3] = .75;
        le->color[3] = 1;

        le->pos.trType = TR_LINEAR;
        le->pos.trTime = cg.time;

		VectorCopy( move, move2);
        VectorMA(move2, RADIUS * ((oldScale/30) -.5) , axis[j], move2);
        VectorCopy(move2, le->pos.trBase);
		
        le->pos.trDelta[0] = axis[j][0]* ((oldScale /40) * posOffs * 50) ;
        le->pos.trDelta[1] = axis[j][1]* ((oldScale /40) * posOffs * 50) ;
        le->pos.trDelta[2] = axis[j][2]* ((oldScale /40) * posOffs * 50)  + 10;

	}  

    VectorAdd (move, vec, move);

    j = j + ROTATION < 36 ? j + ROTATION : (j + ROTATION) % 36;
}