Ejemplo n.º 1
0
//
// ACS_funcGetCVar
//
static void ACS_funcGetCVar(ACS_FUNCARG)
{
   char const *name = ACSVM::GetString(args[0]);

   command_t *command;
   variable_t *var;

   if(!(command = C_GetCmdForName(name)) || !(var = command->variable))
   {
      *retn++ = 0;
      return;
   }

   switch(var->type)
   {
   case vt_int: *retn++ = *(int *)var->variable; break;
   case vt_float: *retn++ = M_DoubleToFixed(*(double *)var->variable); break;
   case vt_string: *retn++ = 0; break;
   case vt_chararray: *retn++ = 0; break;
   case vt_toggle: *retn++ = *(bool *)var->variable; break;
   default:
      *retn++ = 0;
      break;
   }
}
Ejemplo n.º 2
0
//
// ACS_funcSqrtFixed
//
static void ACS_funcSqrtFixed(ACS_FUNCARG)
{
   *retn++ = M_DoubleToFixed(sqrt(M_FixedToDouble(args[0])));
}
Ejemplo n.º 3
0
//
// ACS_funcTrigHypot
//
static void ACS_funcTrigHypot(ACS_FUNCARG)
{
   double x = M_FixedToDouble(args[0]);
   double y = M_FixedToDouble(args[1]);
   *retn++ = M_DoubleToFixed(sqrt(x * x + y * y));
}
Ejemplo n.º 4
0
//
// R_divideSegs
//
// Split the input list of segs into left and right lists using one of the segs
// selected as a partition line for the current node.
//
static void R_divideSegs(rpolynode_t *rpn, dseglist_t *ts, 
                         dseglist_t *rs, dseglist_t *ls)
{
   dynaseg_t *best, *add_to_rs = NULL, *add_to_ls = NULL;
   
   // select best seg to use as partition line
   best = rpn->partition = R_selectPartition(*ts);

   best->bsplink.remove();

#ifdef RANGECHECK
   // Should not happen.
   if(!rpn->partition)
      I_Error("R_divideSegs: could not select partition!\n");
#endif

   // use the partition line to split any other lines in the list that intersect
   // it into left and right halves

   double pdx = best->psx - best->pex;
   double pdy = best->psy - best->pey;

   dseglink_t *cur;

   // iterate from beginning until the original list is empty
   while((cur = *ts))
   {
      dynaseg_t *seg = *cur;
      add_to_ls = add_to_rs = NULL;

      int val = R_classifyDynaSeg(best, seg, pdx, pdy);

      if(val == SPLIT_SR_EL || val == SPLIT_SL_ER)
      {
         double x, y;
         v2float_t fbackup;

         // seg is split by the partition
         R_ComputeIntersection(best, seg, x, y, &fbackup);

         // create a new vertex at the intersection point
         dynavertex_t *nv = R_GetFreeDynaVertex();
         nv->fx = static_cast<float>(x);
         nv->fy = static_cast<float>(y);
         nv->fbackup = fbackup;
         nv->x  = M_DoubleToFixed(x);
         nv->y  = M_DoubleToFixed(y);
         nv->backup.x = M_FloatToFixed(nv->fbackup.x);
         nv->backup.y = M_FloatToFixed(nv->fbackup.y);

         // create a new dynaseg from nv to v2
         dynaseg_t *nds = R_CreateDynaSeg(seg, nv, seg->seg.dyv2);
         R_setupDSForBSP(*nds);
         nds->seg.frontsector = seg->seg.frontsector;
         nds->seg.backsector  = seg->seg.backsector;
         nds->seg.len         = static_cast<float>(nds->len);

         // modify original seg to run from v1 to nv
         bool notmarked = !seg->originalv2;
         if(notmarked)   // only if not already marked!
            R_SetDynaVertexRef(&seg->originalv2, seg->seg.dyv2);
         R_SetDynaVertexRef(&seg->seg.dyv2, nv);
         R_setupDSForBSP(*seg);
         seg->seg.len = static_cast<float>(seg->len);

         // add the new seg to the current node's ownership list,
         // so it can get freed later
         nds->ownerlink.insert(nds, &rpn->owned);

         if(notmarked)
            seg->alterlink.insert(seg, &rpn->altered);

         // classify left or right
         if(val == SPLIT_SR_EL)
         {
            add_to_ls = nds;
            add_to_rs = seg;               
         }
         else
         {
            add_to_ls = seg;
            add_to_rs = nds;
         }
      }
      else
      {
         // Not split; which side?
         if(val & CLASSIFY_LEFT)   
            add_to_ls = seg; // at least one vertex is left, other is left or on
         if(val & CLASSIFY_RIGHT)
            add_to_rs = seg; // at least one vertex is right, other is right or on
         if(val == CLASSIFY_ON)
         {
            // We know the segs are parallel or nearly so; take their dot
            // product to determine their relative orientation
            if((seg->psx - seg->pex) * pdx + (seg->psy - seg->pey) * pdy < 0.0)
               add_to_ls = seg;
            else
               add_to_rs = seg;
         }
      }

      // add to right side?
      if(add_to_rs)
      {
         add_to_rs->bsplink.remove();
         add_to_rs->bsplink.insert(add_to_rs, rs);
      }

      // add to left side?
      if(add_to_ls)
      {
         add_to_ls->bsplink.remove();
         add_to_ls->bsplink.insert(add_to_ls, ls);
      }
   }
}