Advertisement
lucasgautheron

removed fast approximated match functions + texture clip WIP

Aug 30th, 2011
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 9.28 KB | None | 0 0
  1. Index: clientgame.cpp
  2. ===================================================================
  3. --- clientgame.cpp  (revision 6621)
  4. +++ clientgame.cpp  (working copy)
  5. @@ -1183,7 +1183,7 @@
  6.      conoutf("  The mean height is: %.2f", Mh);
  7.      if (Hhits) conoutf("  Height check is: %d", Hhits);
  8.      if (MA) conoutf("  The max area is: %d (of %d)", MA, Ma);
  9. -    if (m_flags && F2F < 1000) conoutf("  Flag-to-flag distance is: %d", (int)fSqrt(F2F));
  10. +    if (m_flags && F2F < 1000) conoutf("  Flag-to-flag distance is: %d", (int)sqrt((float)F2F));
  11.      if (item_fail) conoutf("  There are one or more items too close to each other in this map");
  12.  }
  13.  COMMAND(showmapstats, ARG_NONE);
  14. Index: editing.cpp
  15. ===================================================================
  16. --- editing.cpp (revision 6621)
  17. +++ editing.cpp (working copy)
  18. @@ -527,6 +527,17 @@
  19.      newentity(-1, sel.x, sel.y, (int)camera1->o.z, what, ATOI(a1), ATOI(a2), ATOI(a3), ATOI(a4));
  20.  }
  21.  
  22. +void newtclip(char *a1, char *a2, char *a3, char *a4, char *a5)
  23. +{
  24. +    EDITSEL;
  25. +    int xlen = atoi(a2) & 0x00000F;
  26. +    int ylen = atoi(a3) & 0x00000F;
  27. +    int attr2 = xlen | (ylen << 4);
  28. +    newentity(-1, sel.x, sel.y, (int)camera1->o.z, "tclip", ATOI(a1), attr2, ATOI(a4), ATOI(a5));
  29. +}
  30. +
  31. +COMMAND(newtclip, ARG_5STR);
  32. +
  33.  void movemap(int xo, int yo, int zo) // move whole map
  34.  {
  35.      EDITMP;
  36. Index: entities.cpp
  37. ===================================================================
  38. --- entities.cpp    (revision 6621)
  39. +++ entities.cpp    (working copy)
  40. @@ -18,18 +18,45 @@
  41.      rendermodel(mdlname, ANIM_MAPMODEL|ANIM_LOOP|ANIM_DYNALLOC, 0, 0, vec(e.x, e.y, z+S(e.x, e.y)->floor+e.attr1), yaw, 0);
  42.  }
  43.  
  44. +void getcliplen(entity &e, int &xlen, int &ylen)
  45. +{
  46. +    if(e.type == TCLIP)
  47. +    {
  48. +        xlen = e.attr2 & 0x0F;
  49. +        ylen = (e.attr2 & 0xF0) >> 4;
  50. +    }
  51. +    else
  52. +    {
  53. +        xlen = e.attr2;
  54. +        ylen = e.attr3;
  55. +    }
  56. +}
  57. +
  58.  void renderclip(entity &e)
  59.  {
  60. -    float xradius = max(float(e.attr2), 0.1f), yradius = max(float(e.attr3), 0.1f);
  61. +    int xlen, ylen;
  62. +    getcliplen(e, xlen, ylen);
  63. +
  64. +    float xradius = max(float(xlen), 0.1f), yradius = max(float(ylen), 0.1f);
  65.      vec bbmin(e.x - xradius, e.y - yradius, float(S(e.x, e.y)->floor+e.attr1)),
  66.          bbmax(e.x + xradius, e.y + yradius, bbmin.z + max(float(e.attr4), 0.1f));
  67.  
  68. +    if(e.type==TCLIP)
  69. +    {
  70. +        // draw textured clip
  71. +        // TODO!
  72. +        Texture *t = lookuptexture(e.attr3);
  73. +    }
  74. +
  75. +    if(!editmode) return;
  76. +
  77.      glDisable(GL_TEXTURE_2D);
  78.      switch(e.type)
  79.      {
  80.          case CLIP:     linestyle(1, 0xFF, 0xFF, 0); break;  // yellow
  81.          case MAPMODEL: linestyle(1, 0, 0xFF, 0);    break;  // green
  82.          case PLCLIP:   linestyle(1, 0xFF, 0, 0xFF); break;  // magenta
  83. +        case TCLIP:    linestyle(1, 0, 0, 0xFF);    break;
  84.      }
  85.      glBegin(GL_LINES);
  86.  
  87. @@ -208,6 +235,10 @@
  88.                  renderent(e);
  89.              }
  90.          }
  91. +        else if(e.type == TCLIP)
  92. +        {
  93. +            renderclip(e);
  94. +        }
  95.          else if(editmode)
  96.          {
  97.              if(e.type==CTF_FLAG)
  98. Index: entity.h
  99. ===================================================================
  100. --- entity.h    (revision 6621)
  101. +++ entity.h    (working copy)
  102. @@ -13,6 +13,7 @@
  103.      SOUND,
  104.      CLIP,
  105.      PLCLIP,
  106. +    TCLIP,
  107.      MAXENTTYPES
  108.  };
  109.  
  110. Index: geom.h
  111. ===================================================================
  112. --- geom.h  (revision 6621)
  113. +++ geom.h  (working copy)
  114. @@ -3,7 +3,7 @@
  115.  // http://www.lomont.org/Math/Papers/2003/InvSqrt.pdf
  116.  // http://www.mceniry.net/papers/Fast%20Inverse%20Square%20Root.pdf
  117.  // http://en.wikipedia.org/wiki/Fast_inverse_square_root
  118. -#define UFINVSQRT(x)  union { int d; float f; } u; u.f = x; u.d = 0x5f3759df - (u.d >> 1)
  119. +/*#define UFINVSQRT(x)  union { int d; float f; } u; u.f = x; u.d = 0x5f3759df - (u.d >> 1)
  120.  inline float ufInvSqrt (float x) { UFINVSQRT(x); return u.f; } // about 3.5% of error
  121.  inline float fInvSqrt (float x) { UFINVSQRT(x); return 0.5f * u.f * ( 3.00175f - x * u.f * u.f ); } // about 0.1% of error
  122.  inline float fSqrt (float x) { return x * fInvSqrt(x); }
  123. @@ -24,13 +24,14 @@
  124.      u.f = y * 0.5f * u.f * ( 3.0f - y * u.f * u.f );
  125.      return 1.57079632f * ( r + s * u.f * ( 0.9003163f + y * ( 0.07782684f + y * ( 0.006777598f + y * 0.015079262f ) ) ) );
  126.  }
  127. -#undef UFINVSQRT
  128. +#undef UFINVSQRT*/
  129.  
  130.  template <typename T> inline T pow2(T x) { return x*x; }
  131. +inline float uSqrt(float x) { return sqrt(fabs(x)); }
  132.  
  133.  // Fast Cosine
  134.  // inspired after http://www.devmaster.net/forums/showthread.php?t=5784
  135. -#define FCOS \
  136. +/*#define FCOS \
  137.      x = fabs(x); \
  138.      int s = 1; \
  139.      if ( x > 1.0f ) \
  140. @@ -45,7 +46,7 @@
  141.  inline float fSin(float x) { x *= 0.636619772f; x -= 1.0f; FCOS; }
  142.  #undef FCOS
  143.  
  144. -inline float ufS2C(float x) { x *= x; return x < 1.0f ? ufSqrt(1.0f - x) : 0.0f; }
  145. +inline float ufS2C(float x) { x *= x; return x < 1.0f ? ufSqrt(1.0f - x) : 0.0f; }*/
  146.  
  147.  struct vec
  148.  {
  149. @@ -86,8 +87,8 @@
  150.      float magnitude() const { return sqrtf(squaredlen()); }
  151.      vec &normalize() { div(magnitude()); return *this; }
  152.  
  153. -    float fmag() const { return fSqrt(squaredlen()); }
  154. -    float ufmag() const { return ufSqrt(squaredlen()); }
  155. +    //float fmag() const { return fSqrt(squaredlen()); }
  156. +    //float ufmag() const { return ufSqrt(squaredlen()); }
  157.  
  158.      float dist(const vec &e) const { vec t; return dist(e, t); }
  159.      float dist(const vec &e, vec &t) const { t = *this; t.sub(e); return t.magnitude(); }
  160. @@ -95,8 +96,8 @@
  161.      float distxy(const vec &e) const { float dx = e.x - x, dy = e.y - y; return sqrtf(dx*dx + dy*dy); }
  162.      float magnitudexy() const { return sqrtf(x*x + y*y); }
  163.  
  164. -    float fmagxy() const { return fSqrt(x*x + y*y); }
  165. -    float ufmagxy() const { return ufSqrt(x*x + y*y); }
  166. +    //float fmagxy() const { return fSqrt(x*x + y*y); }
  167. +    //float ufmagxy() const { return ufSqrt(x*x + y*y); }
  168.  
  169.      bool reject(const vec &o, float max) const { return x>o.x+max || x<o.x-max || y>o.y+max || y<o.y-max; }
  170.  
  171. Index: physics.cpp
  172. ===================================================================
  173. --- physics.cpp (revision 6621)
  174. +++ physics.cpp (working copy)
  175. @@ -117,9 +117,11 @@
  176.      {
  177.          entity &e = ents[i];
  178.          // if(e.type==CLIP || (e.type == PLCLIP && d->type == ENT_PLAYER))
  179. -        if (e.type==CLIP || (e.type == PLCLIP && (d->type == ENT_BOT || d->type == ENT_PLAYER))) // don't allow bots to hack themselves into plclips - Bukz 2011/04/14
  180. +        if (e.type==CLIP || e.type == TCLIP || (e.type == PLCLIP && (d->type == ENT_BOT || d->type == ENT_PLAYER))) // don't allow bots to hack themselves into plclips - Bukz 2011/04/14
  181.          {
  182. -            if(fabs(e.x-d->o.x) < e.attr2 + d->radius && fabs(e.y-d->o.y) < e.attr3 + d->radius)
  183. +            int xlen, ylen;
  184. +            getcliplen(e, xlen, ylen);
  185. +            if(fabs(e.x-d->o.x) < xlen + d->radius && fabs(e.y-d->o.y) < ylen + d->radius)
  186.              {
  187.                  const float cz = float(S(e.x, e.y)->floor+e.attr1), ch = float(e.attr4);
  188.                  const float dz = d->o.z-d->eyeheight;
  189. @@ -535,7 +537,7 @@
  190.          if(pl->type!=ENT_BOUNCE && hitplayer)
  191.          {
  192.              vec dr(hitplayer->o.x-pl->o.x,hitplayer->o.y-pl->o.y,0);
  193. -            float invdist = ufInvSqrt(dr.sqrxy()),
  194. +            float invdist = 1.0f/dr.magnitudexy(),
  195.                    push = (invdist < 10.0f ? dr.dotxy(d)*1.1f*invdist : dr.dotxy(d) * 11.0f);
  196.  
  197.              pl->o.x -= f*d.x*push;
  198. @@ -548,7 +550,7 @@
  199.          if (cornersurface)
  200.          {
  201.              float ct2f = (cornersurface == 2 ? -1.0 : 1.0);
  202. -            float diag = f*d.ufmagxy()*2;
  203. +            float diag = f*d.magnitudexy()*2;
  204.              vec vd = vec((d.y*ct2f+d.x >= 0.0f ? diag : -diag), (d.x*ct2f+d.y >= 0.0f ? diag : -diag), 0);
  205.              pl->o.x -= f*d.x;
  206.              pl->o.y -= f*d.y;
  207. Index: protos.h
  208. ===================================================================
  209. --- protos.h    (revision 6621)
  210. +++ protos.h    (working copy)
  211. @@ -702,6 +702,7 @@
  212.  extern void checkitems(playerent *d);
  213.  extern vector<int> changedents;
  214.  extern void syncentchanges(bool force = false);
  215. +extern void getcliplen(entity &e, int &xlen, int &ylen);
  216.  
  217.  // rndmap
  218.  extern void perlinarea(block &b, int scale, int seed, int psize);
  219. Index: server.cpp
  220. ===================================================================
  221. --- server.cpp  (revision 6621)
  222. +++ server.cpp  (working copy)
  223. @@ -1628,7 +1628,7 @@
  224.      loopv(clients) if(clients[i]->type!=ST_EMPTY)
  225.      {
  226.          clientstate &cs = clients[i]->state;
  227. -        sum += clients[i]->at3_score = cs.points > 0 ? ufSqrt((float)cs.points) : -ufSqrt((float)-cs.points);
  228. +        sum += clients[i]->at3_score = cs.points > 0 ? uSqrt((float)cs.points) : -uSqrt((float)-cs.points);
  229.      }
  230.      return sum;
  231.  }
  232. Index: server.h
  233. ===================================================================
  234. --- server.h    (revision 6621)
  235. +++ server.h    (working copy)
  236. @@ -446,7 +446,7 @@
  237.      "none?",
  238.      "light", "playerstart", "pistol", "ammobox","grenades",
  239.      "health", "helmet", "armour", "akimbo",
  240. -    "mapmodel", "trigger", "ladder", "ctf-flag", "sound", "clip", "plclip"
  241. +    "mapmodel", "trigger", "ladder", "ctf-flag", "sound", "clip", "plclip", "tclip"
  242.  };
  243.  
  244.  // see entity.h:61: struct itemstat { int add, start, max, sound; };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement