Advertisement
voivodpl

muzzleflash wip

Mar 3rd, 2024 (edited)
846
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.66 KB | None | 0 0
  1. void CL_MuzzleFlash( cl_entity_t *entity, vec3_t pos, int type, int attachmentnum )
  2. {
  3.     const char *muzzleflash;
  4.  
  5.     TEMPENTITY  *pTemp;
  6.     int     index, frameCount;
  7.     float       scale;
  8.  
  9.     extern int g_weaponselect_frames;
  10.     if( g_weaponselect_frames )
  11.         return;
  12.  
  13.     index = bound( 0, type % 5, MAX_MUZZLEFLASH - 1 );
  14.     scale = (type / 10) * 0.1f;
  15.     if( scale == 0.0f ) scale = 0.5f;
  16.  
  17.     switch( index )
  18.     {
  19.     case 0:
  20.         muzzleflash = "sprites/muzzleflash1.spr";
  21.         break;
  22.     case 1:
  23.         muzzleflash = "sprites/muzzleflash2.spr";
  24.         break;
  25.     case 2:
  26.         muzzleflash = "sprites/muzzleflash3.spr";
  27.         break;
  28.     case 3:
  29.         muzzleflash = "sprites/muzzleflash.spr";
  30.         break;
  31.     }
  32.     int modelIndex = gEngfuncs.pEventAPI->EV_FindModelIndex(muzzleflash);
  33.     model_t* modelchar = gEngfuncs.hudGetModelByIndex(modelIndex);
  34.     //gEngfuncs.Con_DPrintf("DEBUG: SHOULD DO A MUZZLEFLASH!, model = %i, char = %s\n", modelIndex, modelchar);
  35.     model_t* model = gEngfuncs.CL_LoadModel(muzzleflash, &modelIndex);
  36.     if( !model ) return;
  37.  
  38.  
  39.     frameCount = model->numframes;
  40.  
  41.     // must set position for right culling on render
  42.     pTemp = gEngfuncs.pEfxAPI->CL_TempEntAllocHigh( pos, model);
  43.     if( !pTemp ) return;
  44.  
  45.     pTemp->clientIndex = entity->curstate.owner;
  46.     pTemp->entity.curstate.rendermode = kRenderTransAdd;
  47.     pTemp->entity.curstate.renderamt = 32;
  48.     pTemp->entity.curstate.framerate = 100;
  49.     pTemp->entity.curstate.renderfx = 0;
  50.     pTemp->die = gEngfuncs.GetClientTime() + 2.0f; // gHUD.m_flTimeDelta * 1000.5f; // die at next frame
  51.     pTemp->entity.curstate.frame = Com_RandomLong( 0, frameCount - 1 );
  52.     //pTemp->flags |= FTENT_SPRANIMATE|FTENT_SPRANIMATELOOP;
  53.     pTemp->flags = FTENT_CLIENTCUSTOM;
  54.     pTemp->frameMax = frameCount - 1;
  55.     //VectorCopy(entity->curstate.velocity, pTemp->entity.curstate.velocity);
  56.     pTemp->entity.curstate.effects = EF_MUZZLEFLASH;
  57.     //cl_entity_s* player = gEngfuncs.GetLocalPlayer();
  58.     //gEngfuncs.Con_DPrintf("DEBUG: MUZZLEFLASH  FUNC!!!, vel = %f %f %f\n", player->curstate.velocity.x, player->curstate.velocity.y, player->curstate.velocity.z);
  59.     pTemp->entity.curstate.iuser4 = attachmentnum;
  60.     entity->curstate.eflags |= EF_UPDATE_ATTACHMENTS;
  61.     gEngfuncs.Con_DPrintf("DEBUG: MUZZLEFLASH start, index = %i attachment num = %i, pos = %f %f %f\n", entity->index, attachmentnum, pos.x, pos.y, pos.z);
  62.     pTemp->entity.curstate.owner = entity->index;
  63.     pTemp->callback = [](struct tempent_s* te, float frametime, float currenttime) -> void
  64.     {
  65.  
  66.         cl_entity_t *owner = gEngfuncs.GetEntityByIndex(te->entity.curstate.owner);
  67.         Vector dir;
  68.         gEngfuncs.Con_DPrintf("DEBUG: MUZZLEFLASH  callback, owner index = %i, attachmentnum = %i pos = %f %f %f\n", te->entity.curstate.owner, te->entity.curstate.iuser4, owner->attachment[te->entity.curstate.iuser4].x, owner->attachment[te->entity.curstate.iuser4].y, owner->attachment[te->entity.curstate.iuser4].z);
  69.  
  70.  
  71.         VectorSubtract(owner->attachment[te->entity.curstate.iuser4], te->entity.origin, dir);
  72.         VectorCopy(owner->attachment[te->entity.curstate.iuser4], te->entity.origin);
  73.         VectorNormalize(dir);
  74.         //VectorMA(te->entity.origin, frametime * 0.0f, dir, te->entity.origin);
  75.         //
  76.         //gEngfuncs.Con_DPrintf("DEBUG: MUZZLEFLASH  FUNC!!! gun att origin = %f %f %f mf origin = %f %f %f\n", gun->attachment[te->entity.curstate.iuser4].x, gun->attachment[te->entity.curstate.iuser4].y, gun->attachment[te->entity.curstate.iuser4].z, te->entity.curstate.origin.x, te->entity.curstate.origin.y, te->entity.curstate.origin.z);
  77.         //VectorCopy(gun->curstate.velocity, te->entity.curstate.velocity);
  78.         if (te->entity.curstate.team == 0)
  79.         {
  80.             te->entity.curstate.renderamt += frametime * 7649.0 * 0.75f;
  81.             if (te->entity.curstate.renderamt > 255)
  82.             {
  83.                 te->entity.curstate.renderamt = 255;
  84.                 te->entity.curstate.team = 1;
  85.                 //gEngfuncs.Con_DPrintf("DEBUG: MUZZLEFLASH CALLBACK MORE VISIBLE!\n");
  86.             }
  87.  
  88.         }
  89.         else if (te->entity.curstate.team == 1)
  90.         {
  91.             te->entity.curstate.renderamt -= frametime * 7649.0f * 0.75f;
  92.             //gEngfuncs.Con_DPrintf("DEBUG: MUZZLEFLASH CALLBACK LESS VISIBLE!\n");
  93.  
  94.         }
  95.         te->entity.curstate.scale += frametime * 10.0f * 0.0625f * 0.5f;
  96.  
  97.         //Con_DPrintf("debug: frametime = %f \n", cl_clientframetime());
  98.         if (te->entity.curstate.renderamt <= 0.0f)
  99.             te->die = gEngfuncs.GetClientTime() + 0.0001f;
  100.  
  101.         //if(!te->entity.curstate.iuser1)
  102.         //gEngfuncs.Con_DPrintf("DEBUG: MUZZLEFLASH CALLBACK FUNC!!!, attachment vec = %f %f %f, number = %i, origin = %f %f %f\n", gun->attachment[te->entity.curstate.iuser4].x, gun->attachment[te->entity.curstate.iuser4].y, gun->attachment[te->entity.curstate.iuser4].z,
  103.         //  te->entity.curstate.iuser4, gun->origin.x, gun->origin.y, gun->origin.z);
  104.         //te->entity.curstate.iuser1 = 1; // what is this for??? FIXME
  105.     };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement