Untitled

From Anonymous, 3 Years ago, written in Plain Text, viewed 58 times.
URL https://paste.bugabuse.net/view/42503834 Embed
Download Paste or View Raw
  1. diff -Naur src/game/client/components/players.cpp /home/toil/teeworlds/src/game/client/components/players.cpp
  2. --- src/game/client/components/players.cpp      2012-07-07 23:49:37.941683878 +1000
  3. +++ /home/toil/teeworlds/src/game/client/components/players.cpp 2012-06-26 16:53:53.368860821 +1000
  4. @@ -272,7 +272,7 @@
  5.         }
  6.  
  7.         bool Stationary = Player.m_VelX <= 1 && Player.m_VelX >= -1;
  8. -       bool InAir = !(Collision()->CheckPoint(Player.m_X-14, Player.m_Y+16) || Collision()->CheckPoint(Player.m_X+14, Player.m_Y+16));
  9. +       bool InAir = !Collision()->CheckPoint(Player.m_X, Player.m_Y+16);
  10.         bool WantOtherDir = (Player.m_Direction == -1 && Vel.x > 0) || (Player.m_Direction == 1 && Vel.x < 0);
  11.  
  12.         // evaluate animation
  13. diff -Naur src/game/collision.cpp /home/toil/teeworlds/src/game/collision.cpp
  14. --- src/game/collision.cpp      2012-07-08 00:43:40.533677337 +1000
  15. +++ /home/toil/teeworlds/src/game/collision.cpp 2012-06-26 16:53:53.376860790 +1000
  16. @@ -26,14 +26,14 @@
  17.         m_Width = m_pLayers->GameLayer()->m_Width;
  18.         m_Height = m_pLayers->GameLayer()->m_Height;
  19.         m_pTiles = static_cast<CTile *>(m_pLayers->Map()->GetData(m_pLayers->GameLayer()->m_Data));
  20. -      
  21. +
  22.         for(int i = 0; i < m_Width*m_Height; i++)
  23.         {
  24.                 int Index = m_pTiles[i].m_Index;
  25. -              
  26. +
  27.                 if(Index > 128)
  28.                         continue;
  29. -              
  30. +
  31.                 switch(Index)
  32.                 {
  33.                 case TILE_DEATH:
  34. @@ -45,64 +45,35 @@
  35.                 case TILE_NOHOOK:
  36.                         m_pTiles[i].m_Index = COLFLAG_SOLID|COLFLAG_NOHOOK;
  37.                         break;
  38. -               case TILE_SLOPE:
  39. -               {
  40. -                       m_pTiles[i].m_Index = COLFLAG_SLOPE;
  41. -                       m_pTiles[i].m_Flags = OrientationTile(m_pTiles[i].m_Flags, 1);
  42. -               }
  43. -                       break;
  44. -               case TILE_SLOPE_NH:
  45. -               {
  46. -                       m_pTiles[i].m_Index = COLFLAG_SLOPE|COLFLAG_NOHOOK;
  47. -                       m_pTiles[i].m_Flags = OrientationTile(m_pTiles[i].m_Flags, 1);
  48. -               }
  49. -                       break;
  50.                 default:
  51.                         m_pTiles[i].m_Index = 0;
  52.                 }
  53.         }
  54.  }
  55.  
  56. -int CCollision::GetTile(int x, int y, int *pFlags, int *pDx, int *pDy)
  57. +int CCollision::GetTile(int x, int y)
  58.  {
  59. -       int Address = clamp(y/32, 0, m_Height-1)*m_Width + clamp(x/32, 0, m_Width-1);
  60. -       int Index = m_pTiles[Address].m_Index;
  61. -      
  62. -       if(Index&COLFLAG_SLOPE)
  63. -       {
  64. -               int Flags = m_pTiles[Address].m_Flags;
  65. -               int Dx = x < 0 ? 31-abs(x)%32 : x%32;
  66. -               int Dy = y < 0 ? 31-abs(y)%32 : y%32;
  67. -
  68. -               if((Flags == 1 && Dy >= Dx) || (Flags == 3 && Dy+Dx <= 31) || (Flags == 5 && Dy <= Dx) || (Flags == 7 && Dy+Dx >= 31))
  69. -                       Index |= COLFLAG_SOLID;
  70. -               else if(Index&COLFLAG_NOHOOK)
  71. -                       Index ^= COLFLAG_NOHOOK;
  72. -
  73. -               if(pDx) *pDx = Dx;
  74. -               if(pDy) *pDy = Dy;
  75. -               if(pFlags) *pFlags = Flags;
  76. -}
  77. -
  78. -return Index > 128 ? 0 : Index;
  79. +       int Nx = clamp(x/32, 0, m_Width-1);
  80. +       int Ny = clamp(y/32, 0, m_Height-1);
  81.  
  82. +       return m_pTiles[Ny*m_Width+Nx].m_Index > 128 ? 0 : m_pTiles[Ny*m_Width+Nx].m_Index;
  83.  }
  84.  
  85.  bool CCollision::IsTileSolid(int x, int y)
  86.  {
  87. -       return GetTile(x,y)&COLFLAG_SOLID;
  88. +       return GetTile(x, y)&COLFLAG_SOLID;
  89.  }
  90.  
  91.  // TODO: rewrite this smarter!
  92.  int CCollision::IntersectLine(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision)
  93.  {
  94. -       float d = distance(Pos0, Pos1);
  95. -       int End(d+1);
  96. +       float Distance = distance(Pos0, Pos1);
  97. +       int End(Distance+1);
  98.         vec2 Last = Pos0;
  99. -      
  100. +
  101.         for(int i = 0; i < End; i++)
  102.         {
  103. -               float a = i/d;
  104. +               float a = i/Distance;
  105.                 vec2 Pos = mix(Pos0, Pos1, a);
  106.                 if(CheckPoint(Pos.x, Pos.y))
  107.                 {
  108. @@ -126,127 +97,52 @@
  109.  {
  110.         if(pBounces)
  111.                 *pBounces = 0;
  112. -      
  113. -       vec2 Pos = *pInoutPos;
  114. -       vec2 NewPos = Pos + *pInoutVel;
  115. -       int Flags, Index = GetTile(round(NewPos.x), round(NewPos.y), &Flags);
  116.  
  117. -       if(Index&COLFLAG_SOLID)
  118. +       vec2 Pos = *pInoutPos;
  119. +       vec2 Vel = *pInoutVel;
  120. +       if(CheckPoint(Pos + Vel))
  121.         {
  122.                 int Affected = 0;
  123. -
  124. -               if(Index&COLFLAG_SLOPE)
  125. -               {
  126. -                       if(round(NewPos.x)/32 == round(Pos.x)/32 && round(NewPos.y)/32 == round(Pos.y)/32)//not correct, only approximative
  127. -                       {
  128. -                               vec2 Reflex = vec2(pInoutVel->y, pInoutVel->x); //inverting axisses values
  129. -                               if(Flags == 3 || Flags == 7)
  130. -                                       Reflex *= -1; //inverting sings
  131. -  
  132. -                               *pInoutVel = Elasticity? Reflex*Elasticity : (*pInoutVel+Reflex)*0.5f;
  133. -                               if(pBounces)
  134. -                                       (*pBounces)++;
  135. -                               Affected++;
  136. -
  137. -                               return;
  138. -                       }
  139. -               }
  140. -
  141. -               if(CheckPoint(NewPos.x, Pos.y))
  142. +               if(CheckPoint(Pos.x + Vel.x, Pos.y))
  143.                 {
  144.                         pInoutVel->x *= -Elasticity;
  145.                         if(pBounces)
  146. -                               (*pBounces)++;                 
  147. +                               (*pBounces)++;
  148.                         Affected++;
  149.                 }
  150.  
  151. -               if(CheckPoint(Pos.x, NewPos.y))
  152. +               if(CheckPoint(Pos.x, Pos.y + Vel.y))
  153.                 {
  154.                         pInoutVel->y *= -Elasticity;
  155.                         if(pBounces)
  156. -                               (*pBounces)++;                 
  157. +                               (*pBounces)++;
  158.                         Affected++;
  159.                 }
  160. -              
  161. +
  162.                 if(Affected == 0)
  163. -                       *pInoutVel *= -Elasticity;
  164. +               {
  165. +                       pInoutVel->x *= -Elasticity;
  166. +                       pInoutVel->y *= -Elasticity;
  167. +               }
  168.         }
  169.         else
  170.         {
  171. -               *pInoutPos = NewPos;
  172. +               *pInoutPos = Pos + Vel;
  173.         }
  174.  }
  175.  
  176. -int CCollision::TestBox(vec2 Pos, vec2 Size)
  177. +bool CCollision::TestBox(vec2 Pos, vec2 Size)
  178.  {
  179. -       Pos -= Size*0.5f;
  180. -       int Flags, Dx, Dy, Index = GetTile(round(Pos.x), round(Pos.y), &Flags, &Dx, &Dy);
  181. -       if(Index&COLFLAG_SOLID)
  182. -       {
  183. -               if(Index&COLFLAG_SLOPE && Flags == 3)
  184. -                       return 3;
  185. -               else
  186. -                       return 64;
  187. -       }
  188. -       else if(Index&COLFLAG_SLOPE)
  189. -       {
  190. -               if(Flags == 1 && Dy+Size.y > Dx)
  191. -                       return 64; //16|8
  192. -               else if(Flags == 5 && Dy < Dx+Size.x)
  193. -                       return 64; //32|2
  194. -       }
  195. -  
  196. -       Pos.x += Size.x;
  197. -       Index = GetTile(round(Pos.x), round(Pos.y), &Flags, &Dx, &Dy);
  198. -       if(Index&COLFLAG_SOLID)
  199. -       {
  200. -               if(Index&COLFLAG_SLOPE && Flags == 5)
  201. -                       return 5;
  202. -               else
  203. -                       return 64;
  204. -       }
  205. -       else if(Index&COLFLAG_SLOPE)
  206. -       {
  207. -               if(Flags == 3 && Dy+Dx < 31+Size.x)
  208. -                       return 64; // 32|1
  209. -               else if(Flags == 7 && Dy+Size.y+Dx > 31)
  210. -                       return 64; // 16|4
  211. -       }
  212. -  
  213. -       Pos.y += Size.y;
  214. -       Index = GetTile(round(Pos.x), round(Pos.y), &Flags, &Dx, &Dy);
  215. -       if(Index&COLFLAG_SOLID)
  216. -       {
  217. -               if(Index&COLFLAG_SLOPE && Flags == 7)
  218. -                       return 7;
  219. -               else
  220. -                       return 64;
  221. -       }
  222. -       else if(Index&COLFLAG_SLOPE)
  223. -       {    
  224. -               if(Flags == 1 && Dy+Size.x > Dx)
  225. -                       return 64; // 32|8
  226. -               else if(Flags == 5 && Dy-Size.y < Dx)
  227. -                       return 64; // 16|2
  228. -       }
  229. -       Pos.x -= Size.x;    
  230. -       Index = GetTile(round(Pos.x), round(Pos.y), &Flags, &Dx, &Dy);
  231. -       if(Index&COLFLAG_SOLID)
  232. -       {
  233. -               if(Index&COLFLAG_SLOPE && Flags == 1)
  234. -                       return 1;
  235. -               else
  236. -                       return 64;
  237. -       }
  238. -       else if(Index&COLFLAG_SLOPE)
  239. -       {
  240. -               if(Flags == 3 && Dy+Dx-Size.y < 31)
  241. -                       return 64; // 16|1
  242. -               else if(Flags == 7 && Dy+Dx > 31-Size.x)
  243. -                       return 64; // 32|4
  244. -       }
  245. -
  246. -       return 0;
  247. +       Size *= 0.5f;
  248. +       if(CheckPoint(Pos.x-Size.x, Pos.y-Size.y))
  249. +               return true;
  250. +       if(CheckPoint(Pos.x+Size.x, Pos.y-Size.y))
  251. +               return true;
  252. +       if(CheckPoint(Pos.x-Size.x, Pos.y+Size.y))
  253. +               return true;
  254. +       if(CheckPoint(Pos.x+Size.x, Pos.y+Size.y))
  255. +               return true;
  256. +       return false;
  257.  }
  258.  
  259.  void CCollision::MoveBox(vec2 *pInoutPos, vec2 *pInoutVel, vec2 Size, float Elasticity)
  260. @@ -254,10 +150,10 @@
  261.         // do the move
  262.         vec2 Pos = *pInoutPos;
  263.         vec2 Vel = *pInoutVel;
  264. -      
  265. +
  266.         float Distance = length(Vel);
  267.         int Max = (int)Distance;
  268. -      
  269. +
  270.         if(Distance > 0.00001f)
  271.         {
  272.                 //vec2 old_pos = pos;
  273. @@ -267,107 +163,42 @@
  274.                         //float amount = i/(float)max;
  275.                         //if(max == 0)
  276.                                 //amount = 0;
  277. -                      
  278. +
  279.                         vec2 NewPos = Pos + Vel*Fraction; // TODO: this row is not nice
  280. -                      
  281. -                       if(TestBox(NewPos, Size))
  282. +
  283. +                       if(TestBox(vec2(NewPos.x, NewPos.y), Size))
  284.                         {
  285.                                 int Hits = 0;
  286.  
  287. -                               int Colliding = TestBox(vec2(NewPos.x, Pos.y), Size);                          
  288. -                               if(Colliding)
  289. +                               if(TestBox(vec2(Pos.x, NewPos.y), Size))
  290.                                 {
  291. -                                       if(Colliding == 64)
  292. -                                               Vel.x *= -Elasticity;
  293. -                                       else if(IntersectSlope(Colliding, &Vel, Elasticity))
  294. -                                               Pos = vec2(round(Pos.x), round(Pos.y));
  295. -
  296. +                                       NewPos.y = Pos.y;
  297. +                                       Vel.y *= -Elasticity;
  298.                                         Hits++;
  299.                                 }
  300. -                              
  301. -                               Colliding = TestBox(vec2(Pos.x, NewPos.y), Size);
  302. -                               if(Colliding)
  303. -                               {
  304. -                                       if(Colliding == 64)
  305. -                                               Vel.y *= -Elasticity;
  306. -                                       else if(IntersectSlope(Colliding, &Vel, Elasticity))
  307. -                                               Pos = vec2(round(Pos.x), round(Pos.y));
  308.  
  309. +                               if(TestBox(vec2(NewPos.x, Pos.y), Size))
  310. +                               {
  311. +                                       NewPos.x = Pos.x;
  312. +                                       Vel.x *= -Elasticity;
  313.                                         Hits++;
  314.                                 }
  315. -                              
  316. +
  317.                                 // neither of the tests got a collision.
  318.                                 // this is a real _corner case_!
  319.                                 if(Hits == 0)
  320. -                                       Vel *= -Elasticity;
  321. -
  322. +                               {
  323. +                                       NewPos.y = Pos.y;
  324. +                                       Vel.y *= -Elasticity;
  325. +                                       NewPos.x = Pos.x;
  326. +                                       Vel.x *= -Elasticity;
  327. +                               }
  328.                         }
  329. -                       else
  330. -                               Pos = NewPos;
  331. -               }
  332. -       }
  333. -      
  334. -       *pInoutPos = Pos;
  335. -       *pInoutVel = Vel;
  336. -}
  337.  
  338. -int CCollision::OrientationTile(int Flags, int Dir)
  339. -{  //Converts tiles flags to get effective direction drawn in the map editor
  340. -  // Examples Dir(values)[axisses reference]: (0)=to down[x=0:y=1]; (1)=to bottom-right[x=1:y=1]; (2)=to right[x=1:y=0];...
  341. -       if(Dir == 1)
  342. -       {
  343. -               if(Flags&TILEFLAG_ROTATE)
  344. -               {
  345. -                       if(Flags&TILEFLAG_HFLIP)
  346. -                               Dir = Flags&TILEFLAG_VFLIP? 7 : 5;
  347. -                       else
  348. -                               Dir = Flags&TILEFLAG_VFLIP? 1 : 3;
  349. -               }
  350. -               else
  351. -               {
  352. -                       if(Flags&TILEFLAG_HFLIP)
  353. -                               Dir = Flags&TILEFLAG_VFLIP? 5 : 3;
  354. -                       else
  355. -                               Dir = Flags&TILEFLAG_VFLIP? 7 : 1;
  356. +                       Pos = NewPos;
  357.                 }
  358.         }
  359. -       else if(Dir == 4)//this variant is useless now, but in future coulbe be used
  360. -       {
  361. -               if(Flags&TILEFLAG_ROTATE)
  362. -                       Dir = Flags&TILEFLAG_HFLIP? 6 : 2;
  363. -               else
  364. -                       Dir = Flags&TILEFLAG_HFLIP? 0 : 4;
  365. -       }
  366. -
  367. -       return Dir;
  368. -}
  369. -
  370. -bool CCollision::IntersectSlope(int Flags, vec2 *pVel, int Elasticity)
  371. -{
  372. -       vec2 Vel = *pVel;
  373. -       if((Flags==1 && Vel.y > Vel.x) || (Flags==3 && Vel.y+Vel.x < 0) || (Flags==5 && Vel.y < Vel.x) || (Flags==7 && Vel.y+Vel.x > 0))
  374. -       {
  375. -               vec2 Reaction = vec2(Vel.y, Vel.x); //inverting axisses values
  376. -               if(Flags == 3 || Flags == 7)
  377. -                       Reaction *= -1; //inverting sings
  378. -
  379. -               *pVel = Elasticity? Reaction*Elasticity : (Vel+Reaction)*0.5f;
  380. -               return true;
  381. -       }
  382. -       else
  383. -               return false;
  384.  
  385. -//more general intersection function: maybe useful in future (not formatted)
  386. -/* //equation of the line(AB) in implicit form (ax+by+c=0) analytic geometry
  387. -float a1= Vel.y-Corner.y, b1= Corner.x-Vel.x, c1= -Corner.x*Vel.y; //1 first line: player movement
  388. -float a2= B.y-A.y, b2= A.x-B.x, c2= -A.x*B.y; //2 second line: slope segment
  389. -  
  390. -float d = a1*b2-a2*b1;
  391. -
  392. -if(d)//lines are not parallel
  393. -{
  394. -vec2 HitPoint = vec2((b1*c2-b2*c1)/d, (a2*c1-a1*c2)/d);
  395. -}
  396. -else
  397. -return false*/
  398. +       *pInoutPos = Pos;
  399. +       *pInoutVel = Vel;
  400.  }
  401. diff -Naur src/game/collision.h /home/toil/teeworlds/src/game/collision.h
  402. --- src/game/collision.h        2012-07-07 23:49:37.953689524 +1000
  403. +++ /home/toil/teeworlds/src/game/collision.h   2012-06-26 16:53:53.376860790 +1000
  404. @@ -13,16 +13,14 @@
  405.         class CLayers *m_pLayers;
  406.  
  407.         bool IsTileSolid(int x, int y);
  408. -       int GetTile(int x, int y, int *pFlags=0, int *pDx=0, int *pDy=0);
  409. -       int OrientationTile(int Flags, int Dir);
  410. -       bool IntersectSlope(int Flags, vec2 *pVel, int Elasticity);
  411. +       int GetTile(int x, int y);
  412. +
  413.  public:
  414.         enum
  415.         {
  416.                 COLFLAG_SOLID=1,
  417.                 COLFLAG_DEATH=2,
  418.                 COLFLAG_NOHOOK=4,
  419. -               COLFLAG_SLOPE=8,
  420.         };
  421.  
  422.         CCollision();
  423. @@ -35,7 +33,7 @@
  424.         int IntersectLine(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision);
  425.         void MovePoint(vec2 *pInoutPos, vec2 *pInoutVel, float Elasticity, int *pBounces);
  426.         void MoveBox(vec2 *pInoutPos, vec2 *pInoutVel, vec2 Size, float Elasticity);
  427. -       int TestBox(vec2 Pos, vec2 Size);
  428. +       bool TestBox(vec2 Pos, vec2 Size);
  429.  };
  430.  
  431.  #endif
  432. diff -Naur src/game/editor/layer_tiles.cpp /home/toil/teeworlds/src/game/editor/layer_tiles.cpp
  433. --- src/game/editor/layer_tiles.cpp     2012-07-08 00:55:59.013676221 +1000
  434. +++ /home/toil/teeworlds/src/game/editor/layer_tiles.cpp        2012-06-26 16:53:53.380861019 +1000
  435. @@ -219,6 +219,7 @@
  436.                         m_pTiles[y*m_Width+x] = m_pTiles[y*m_Width+m_Width-1-x];
  437.                         m_pTiles[y*m_Width+m_Width-1-x] = Tmp;
  438.                 }
  439. +
  440.         if(!m_Game)
  441.                 for(int y = 0; y < m_Height; y++)
  442.                         for(int x = 0; x < m_Width; x++)
  443. @@ -243,13 +244,13 @@
  444.  
  445.  void CLayerTiles::BrushRotate(float Amount)
  446.  {
  447. -       int Rotation = (round(360.0f*Amount/(pi*2))/90)%4;      // 0=0�, 1=90�, 2=180�, 3=270�
  448. +       int Rotation = (round(360.0f*Amount/(pi*2))/90)%4;      // 0=0�, 1=90�, 2=180�, 3=270�
  449.         if(Rotation < 0)
  450.                 Rotation +=4;
  451.  
  452.         if(Rotation == 1 || Rotation == 3)
  453.         {
  454. -               // 90� rotation
  455. +               // 90� rotation
  456.                 CTile *pTempData = new CTile[m_Width*m_Height];
  457.                 mem_copy(pTempData, m_pTiles, m_Width*m_Height*sizeof(CTile));
  458.                 CTile *pDst = m_pTiles;
  459. @@ -257,7 +258,7 @@
  460.                         for(int y = m_Height-1; y >= 0; --y, ++pDst)
  461.                         {
  462.                                 *pDst = pTempData[y*m_Width+x];
  463. -                               if(!m_Game || pDst->m_Index == TILE_SLOPE || pDst->m_Index == TILE_SLOPE_NH)
  464. +                               if(!m_Game)
  465.                                 {
  466.                                         if(pDst->m_Flags&TILEFLAG_ROTATE)
  467.                                                 pDst->m_Flags ^= (TILEFLAG_HFLIP|TILEFLAG_VFLIP);
  468. diff -Naur src/game/generated/nethash.c /home/toil/teeworlds/src/game/generated/nethash.c
  469. --- src/game/generated/nethash.c        2012-07-07 23:45:54.225177199 +1000
  470. +++ /home/toil/teeworlds/src/game/generated/nethash.c   1970-01-01 10:00:00.000000000 +1000
  471. @@ -1 +0,0 @@
  472. -#define GAME_NETVERSION_HASH "b67d1f1a1eea234e"
  473. diff -Naur src/game/mapitems.h /home/toil/teeworlds/src/game/mapitems.h
  474. --- src/game/mapitems.h 2012-07-08 00:37:07.813676851 +1000
  475. +++ /home/toil/teeworlds/src/game/mapitems.h    2012-06-26 16:53:53.384860969 +1000
  476. @@ -46,8 +46,6 @@
  477.         TILE_SOLID,
  478.         TILE_DEATH,
  479.         TILE_NOHOOK,
  480. -       TILE_SLOPE=17,
  481. -       TILE_SLOPE_NH,
  482.  
  483.         TILEFLAG_VFLIP=1,
  484.         TILEFLAG_HFLIP=2,
  485. diff -Naur src/game/server/gamemodes/ctf.cpp /home/toil/teeworlds/src/game/server/gamemodes/ctf.cpp
  486. --- src/game/server/gamemodes/ctf.cpp   2012-07-07 23:49:37.969176549 +1000
  487. +++ /home/toil/teeworlds/src/game/server/gamemodes/ctf.cpp      2012-06-26 16:53:53.396862075 +1000
  488. @@ -287,9 +287,6 @@
  489.                                 {
  490.                                         F->m_Vel.y += GameServer()->m_World.m_Core.m_Tuning.m_Gravity;
  491.                                         GameServer()->Collision()->MoveBox(&F->m_Pos, &F->m_Vel, vec2(F->ms_PhysSize, F->ms_PhysSize), 0.5f);
  492. -
  493. -                                       if(GameServer()->Collision()->CheckPoint(F->m_Pos.x, F->m_Pos.y+F->ms_PhysSize/2+5))
  494. -                                               F->m_Vel.x *= GameServer()->m_World.m_Core.m_Tuning.m_GroundFriction;
  495.                                 }
  496.                         }
  497.                 }
  498.  

Reply to "Untitled"

Here you can reply to the paste above