Untitled

From Anonymous, 3 Years ago, written in Plain Text, viewed 50 times.
URL https://paste.bugabuse.net/view/83856715 Embed
Download Paste or View Raw
  1. diff -Naur /home/toil/teeworlds/src/engine/client/backend_sdl.cpp src/engine/client/backend_sdl.cpp
  2. --- /home/toil/teeworlds/src/engine/client/backend_sdl.cpp      2012-06-26 16:53:53.284860687 +1000
  3. +++ src/engine/client/backend_sdl.cpp   2012-07-07 23:49:37.485176348 +1000
  4. @@ -427,6 +427,13 @@
  5.         if(pInfo->blit_hw) // ignore_convention
  6.                 SdlFlags |= SDL_HWACCEL;
  7.  
  8. +       dbg_assert(!(Flags&IGraphicsBackend::INITFLAG_BORDERLESS)
  9. +               || !(Flags&IGraphicsBackend::INITFLAG_FULLSCREEN),
  10. +               "only one of borderless and fullscreen may be activated at the same time");
  11. +
  12. +       if(Flags&IGraphicsBackend::INITFLAG_BORDERLESS)
  13. +               SdlFlags |= SDL_NOFRAME;
  14. +
  15.         if(Flags&IGraphicsBackend::INITFLAG_FULLSCREEN)
  16.                 SdlFlags |= SDL_FULLSCREEN;
  17.  
  18. @@ -443,7 +450,7 @@
  19.         }
  20.  
  21.         SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
  22. -       SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, Flags&CCommandBuffer::INITFLAG_VSYNC ? 1 : 0);
  23. +       SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, Flags&IGraphicsBackend::INITFLAG_VSYNC ? 1 : 0);
  24.  
  25.         // set caption
  26.         SDL_WM_SetCaption(pName, pName);
  27. diff -Naur /home/toil/teeworlds/src/engine/client/graphics.cpp src/engine/client/graphics.cpp
  28. --- /home/toil/teeworlds/src/engine/client/graphics.cpp 2012-06-26 16:53:53.292861564 +1000
  29. +++ src/engine/client/graphics.cpp      2012-07-07 23:49:37.861176855 +1000
  30. @@ -801,7 +801,15 @@
  31.         if(pInfo->blit_hw) // ignore_convention
  32.                 Flags |= SDL_HWACCEL;
  33.  
  34. -       if(g_Config.m_GfxFullscreen)
  35. +       if(g_Config.m_GfxBorderless && g_Config.m_GfxFullscreen)
  36. +       {
  37. +               dbg_msg("gfx", "both borderless and fullscreen activated, disabling borderless");
  38. +               g_Config.m_GfxBorderless = 0;
  39. +       }
  40. +
  41. +       if(g_Config.m_GfxBorderless)
  42. +               Flags |= SDL_NOFRAME;
  43. +       else if(g_Config.m_GfxFullscreen)
  44.                 Flags |= SDL_FULLSCREEN;
  45.  
  46.         // set gl attributes
  47. diff -Naur /home/toil/teeworlds/src/engine/client/graphics_threaded.cpp src/engine/client/graphics_threaded.cpp
  48. --- /home/toil/teeworlds/src/engine/client/graphics_threaded.cpp        2012-06-26 16:53:53.292861564 +1000
  49. +++ src/engine/client/graphics_threaded.cpp     2012-07-07 23:49:37.489176297 +1000
  50. @@ -712,7 +712,14 @@
  51.  int CGraphics_Threaded::IssueInit()
  52.  {
  53.         int Flags = 0;
  54. -       if(g_Config.m_GfxFullscreen) Flags |= IGraphicsBackend::INITFLAG_FULLSCREEN;
  55. +       if(g_Config.m_GfxBorderless && g_Config.m_GfxFullscreen)
  56. +       {
  57. +               dbg_msg("gfx", "both borderless and fullscreen activated, disabling borderless");
  58. +               g_Config.m_GfxBorderless = 0;
  59. +       }
  60. +
  61. +       if(g_Config.m_GfxBorderless) Flags |= IGraphicsBackend::INITFLAG_BORDERLESS;
  62. +       else if(g_Config.m_GfxFullscreen) Flags |= IGraphicsBackend::INITFLAG_FULLSCREEN;
  63.         if(g_Config.m_GfxVsync) Flags |= IGraphicsBackend::INITFLAG_VSYNC;
  64.         if(g_Config.m_DbgResizable) Flags |= IGraphicsBackend::INITFLAG_RESIZABLE;
  65.  
  66. diff -Naur /home/toil/teeworlds/src/engine/client/graphics_threaded.h src/engine/client/graphics_threaded.h
  67. --- /home/toil/teeworlds/src/engine/client/graphics_threaded.h  2012-06-26 16:53:53.292861564 +1000
  68. +++ src/engine/client/graphics_threaded.h       2012-07-07 23:49:37.489176297 +1000
  69. @@ -98,13 +98,6 @@
  70.  
  71.         enum
  72.         {
  73. -               INITFLAG_FULLSCREEN = 1,
  74. -               INITFLAG_VSYNC = 2,
  75. -               INITFLAG_RESIZABLE = 4,
  76. -       };
  77. -
  78. -       enum
  79. -       {
  80.                 //
  81.                 PRIMTYPE_INVALID = 0,
  82.                 PRIMTYPE_LINES,
  83. @@ -300,6 +293,7 @@
  84.                 INITFLAG_FULLSCREEN = 1,
  85.                 INITFLAG_VSYNC = 2,
  86.                 INITFLAG_RESIZABLE = 4,
  87. +               INITFLAG_BORDERLESS = 8,
  88.         };
  89.  
  90.         virtual int Init(const char *pName, int *Width, int *Height, int FsaaSamples, int Flags) = 0;
  91. diff -Naur /home/toil/teeworlds/src/engine/client/input.cpp src/engine/client/input.cpp
  92. --- /home/toil/teeworlds/src/engine/client/input.cpp    2012-06-26 16:53:53.292861564 +1000
  93. +++ src/engine/client/input.cpp 2012-07-07 23:49:37.865176246 +1000
  94. @@ -35,6 +35,7 @@
  95.  
  96.         m_InputCurrent = 0;
  97.         m_InputGrabbed = 0;
  98. +       m_InputDispatched = false;
  99.  
  100.         m_LastRelease = 0;
  101.         m_ReleaseDelta = -1;
  102. @@ -116,10 +117,14 @@
  103.         /*if(!input_grabbed && Graphics()->WindowActive())
  104.                 Input()->MouseModeRelative();*/
  105.  
  106. -       // clear and begin count on the other one
  107. -       m_InputCurrent^=1;
  108. -       mem_zero(&m_aInputCount[m_InputCurrent], sizeof(m_aInputCount[m_InputCurrent]));
  109. -       mem_zero(&m_aInputState[m_InputCurrent], sizeof(m_aInputState[m_InputCurrent]));
  110. +       if(m_InputDispatched)
  111. +       {
  112. +               // clear and begin count on the other one
  113. +               m_InputCurrent^=1;
  114. +               mem_zero(&m_aInputCount[m_InputCurrent], sizeof(m_aInputCount[m_InputCurrent]));
  115. +               mem_zero(&m_aInputState[m_InputCurrent], sizeof(m_aInputState[m_InputCurrent]));
  116. +               m_InputDispatched = false;
  117. +       }
  118.  
  119.         {
  120.                 int i;
  121. diff -Naur /home/toil/teeworlds/src/engine/client/serverbrowser.cpp src/engine/client/serverbrowser.cpp
  122. --- /home/toil/teeworlds/src/engine/client/serverbrowser.cpp    2012-06-26 16:53:53.292861564 +1000
  123. +++ src/engine/client/serverbrowser.cpp 2012-07-07 23:49:37.653176620 +1000
  124. @@ -86,7 +86,7 @@
  125.         CServerEntry *a = m_ppServerlist[Index1];
  126.         CServerEntry *b = m_ppServerlist[Index2];
  127.         //      make sure empty entries are listed last
  128. -       return (a->m_GotInfo && b->m_GotInfo) || (!a->m_GotInfo && !b->m_GotInfo) ? str_comp(a->m_Info.m_aName, b->m_Info.m_aName) < 0 :
  129. +       return (a->m_GotInfo && b->m_GotInfo) || (!a->m_GotInfo && !b->m_GotInfo) ? str_comp_nocase(a->m_Info.m_aName, b->m_Info.m_aName) < 0 :
  130.                         a->m_GotInfo ? true : false;
  131.  }
  132.  
  133. @@ -94,7 +94,7 @@
  134.  {
  135.         CServerEntry *a = m_ppServerlist[Index1];
  136.         CServerEntry *b = m_ppServerlist[Index2];
  137. -       return str_comp(a->m_Info.m_aMap, b->m_Info.m_aMap) < 0;
  138. +       return str_comp_nocase(a->m_Info.m_aMap, b->m_Info.m_aMap) < 0;
  139.  }
  140.  
  141.  bool CServerBrowser::SortComparePing(int Index1, int Index2) const
  142. @@ -108,7 +108,7 @@
  143.  {
  144.         CServerEntry *a = m_ppServerlist[Index1];
  145.         CServerEntry *b = m_ppServerlist[Index2];
  146. -       return str_comp(a->m_Info.m_aGameType, b->m_Info.m_aGameType) < 0;
  147. +       return str_comp_nocase(a->m_Info.m_aGameType, b->m_Info.m_aGameType) < 0;
  148.  }
  149.  
  150.  bool CServerBrowser::SortCompareNumPlayers(int Index1, int Index2) const
  151. diff -Naur /home/toil/teeworlds/src/engine/input.h src/engine/input.h
  152. --- /home/toil/teeworlds/src/engine/input.h     2012-06-26 16:53:53.328861462 +1000
  153. +++ src/engine/input.h  2012-07-07 23:49:37.893182739 +1000
  154. @@ -38,6 +38,7 @@
  155.  
  156.         unsigned char m_aInputState[2][1024];
  157.         int m_InputCurrent;
  158. +       bool m_InputDispatched;
  159.  
  160.         int KeyWasPressed(int Key) { return m_aInputState[m_InputCurrent^1][Key]; }
  161.  
  162. @@ -51,7 +52,11 @@
  163.  
  164.         // events
  165.         int NumEvents() const { return m_NumEvents; }
  166. -       void ClearEvents() { m_NumEvents = 0; }
  167. +       void ClearEvents()
  168. +       {
  169. +               m_NumEvents = 0;
  170. +               m_InputDispatched = true;
  171. +       }
  172.         CEvent GetEvent(int Index) const
  173.         {
  174.                 if(Index < 0 || Index >= m_NumEvents)
  175. diff -Naur /home/toil/teeworlds/src/engine/shared/config_variables.h src/engine/shared/config_variables.h
  176. --- /home/toil/teeworlds/src/engine/shared/config_variables.h   2012-06-26 16:53:53.332860923 +1000
  177. +++ src/engine/shared/config_variables.h        2012-07-07 23:49:37.901191509 +1000
  178. @@ -59,6 +59,7 @@
  179.  
  180.  MACRO_CONFIG_INT(GfxScreenWidth, gfx_screen_width, 0, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Screen resolution width")
  181.  MACRO_CONFIG_INT(GfxScreenHeight, gfx_screen_height, 0, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Screen resolution height")
  182. +MACRO_CONFIG_INT(GfxBorderless, gfx_borderless, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Borderless window (not to be used with fullscreen)")
  183.  MACRO_CONFIG_INT(GfxFullscreen, gfx_fullscreen, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Fullscreen")
  184.  MACRO_CONFIG_INT(GfxAlphabits, gfx_alphabits, 0, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Alpha bits for framebuffer (fullscreen only)")
  185.  MACRO_CONFIG_INT(GfxColorDepth, gfx_color_depth, 24, 16, 24, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Colors bits for framebuffer (fullscreen only)")
  186. diff -Naur /home/toil/teeworlds/src/engine/shared/memheap.cpp src/engine/shared/memheap.cpp
  187. --- /home/toil/teeworlds/src/engine/shared/memheap.cpp  2012-06-26 16:53:53.340861242 +1000
  188. +++ src/engine/shared/memheap.cpp       2012-07-07 23:49:37.909190850 +1000
  189. @@ -3,7 +3,6 @@
  190.  #include <base/system.h>
  191.  #include "memheap.h"
  192.  
  193. -static const int CHUNK_SIZE = 1024*64;
  194.  
  195.  // allocates a new chunk to be used
  196.  void CHeap::NewChunk()
  197. diff -Naur /home/toil/teeworlds/src/engine/shared/memheap.h src/engine/shared/memheap.h
  198. --- /home/toil/teeworlds/src/engine/shared/memheap.h    2012-06-26 16:53:53.340861242 +1000
  199. +++ src/engine/shared/memheap.h 2012-07-07 23:49:37.909190850 +1000
  200. @@ -15,7 +15,7 @@
  201.         enum
  202.         {
  203.                 // how large each chunk should be
  204. -               CHUNK_SIZE = 1025*64,
  205. +               CHUNK_SIZE = 1024*64,
  206.         };
  207.  
  208.         CChunk *m_pCurrent;
  209. diff -Naur /home/toil/teeworlds/src/game/client/components/menus.h src/game/client/components/menus.h
  210. --- /home/toil/teeworlds/src/game/client/components/menus.h     2012-06-26 16:53:53.360863645 +1000
  211. +++ src/game/client/components/menus.h  2012-07-07 23:49:37.929676066 +1000
  212. @@ -218,11 +218,11 @@
  213.                                 return false;
  214.                         else
  215.                         {
  216. -                               int Result = str_comp(m_pFriendInfo->m_aName, Other.m_pFriendInfo->m_aName);
  217. +                               int Result = str_comp_nocase(m_pFriendInfo->m_aName, Other.m_pFriendInfo->m_aName);
  218.                                 if(Result)
  219.                                         return Result < 0;
  220.                                 else
  221. -                                       return str_comp(m_pFriendInfo->m_aClan, Other.m_pFriendInfo->m_aClan) < 0;
  222. +                                       return str_comp_nocase(m_pFriendInfo->m_aClan, Other.m_pFriendInfo->m_aClan) < 0;
  223.                         }
  224.                 }
  225.         };
  226. diff -Naur /home/toil/teeworlds/src/game/client/components/menus_settings.cpp src/game/client/components/menus_settings.cpp
  227. --- /home/toil/teeworlds/src/game/client/components/menus_settings.cpp  2012-06-26 16:53:53.364862128 +1000
  228. +++ src/game/client/components/menus_settings.cpp       2012-07-07 23:49:37.937676315 +1000
  229. @@ -615,6 +615,7 @@
  230.         static int s_GfxScreenWidth = g_Config.m_GfxScreenWidth;
  231.         static int s_GfxScreenHeight = g_Config.m_GfxScreenHeight;
  232.         static int s_GfxColorDepth = g_Config.m_GfxColorDepth;
  233. +       static int s_GfxBorderless = g_Config.m_GfxBorderless;
  234.         static int s_GfxFullscreen = g_Config.m_GfxFullscreen;
  235.         static int s_GfxVsync = g_Config.m_GfxVsync;
  236.         static int s_GfxFsaaSamples = g_Config.m_GfxFsaaSamples;
  237. @@ -670,9 +671,20 @@
  238.  
  239.         // switches
  240.         MainView.HSplitTop(20.0f, &Button, &MainView);
  241. +       if(DoButton_CheckBox(&g_Config.m_GfxBorderless, Localize("Borderless window"), g_Config.m_GfxBorderless, &Button))
  242. +       {
  243. +               g_Config.m_GfxBorderless ^= 1;
  244. +               if(g_Config.m_GfxBorderless && g_Config.m_GfxFullscreen)
  245. +                       g_Config.m_GfxFullscreen = 0;
  246. +               CheckSettings = true;
  247. +       }
  248. +
  249. +       MainView.HSplitTop(20.0f, &Button, &MainView);
  250.         if(DoButton_CheckBox(&g_Config.m_GfxFullscreen, Localize("Fullscreen"), g_Config.m_GfxFullscreen, &Button))
  251.         {
  252.                 g_Config.m_GfxFullscreen ^= 1;
  253. +               if(g_Config.m_GfxFullscreen && g_Config.m_GfxBorderless)
  254. +                       g_Config.m_GfxBorderless = 0;
  255.                 CheckSettings = true;
  256.         }
  257.  
  258. @@ -715,6 +727,7 @@
  259.                 if(s_GfxScreenWidth == g_Config.m_GfxScreenWidth &&
  260.                         s_GfxScreenHeight == g_Config.m_GfxScreenHeight &&
  261.                         s_GfxColorDepth == g_Config.m_GfxColorDepth &&
  262. +                       s_GfxBorderless == g_Config.m_GfxBorderless &&
  263.                         s_GfxFullscreen == g_Config.m_GfxFullscreen &&
  264.                         s_GfxVsync == g_Config.m_GfxVsync &&
  265.                         s_GfxFsaaSamples == g_Config.m_GfxFsaaSamples &&
  266. diff -Naur /home/toil/teeworlds/src/game/client/components/players.cpp src/game/client/components/players.cpp
  267. --- /home/toil/teeworlds/src/game/client/components/players.cpp 2012-06-26 16:53:53.368860821 +1000
  268. +++ src/game/client/components/players.cpp      2012-07-07 23:49:37.941683878 +1000
  269. @@ -272,7 +272,7 @@
  270.         }
  271.  
  272.         bool Stationary = Player.m_VelX <= 1 && Player.m_VelX >= -1;
  273. -       bool InAir = !Collision()->CheckPoint(Player.m_X, Player.m_Y+16);
  274. +       bool InAir = !(Collision()->CheckPoint(Player.m_X-14, Player.m_Y+16) || Collision()->CheckPoint(Player.m_X+14, Player.m_Y+16));
  275.         bool WantOtherDir = (Player.m_Direction == -1 && Vel.x > 0) || (Player.m_Direction == 1 && Vel.x < 0);
  276.  
  277.         // evaluate animation
  278. diff -Naur /home/toil/teeworlds/src/game/client/components/skins.h src/game/client/components/skins.h
  279. --- /home/toil/teeworlds/src/game/client/components/skins.h     2012-06-26 16:53:53.368860821 +1000
  280. +++ src/game/client/components/skins.h  2012-07-07 23:49:37.945691580 +1000
  281. @@ -17,7 +17,7 @@
  282.                 char m_aName[24];
  283.                 vec3 m_BloodColor;
  284.  
  285. -               bool operator<(const CSkin &Other) { return str_comp(m_aName, Other.m_aName) < 0; }
  286. +               bool operator<(const CSkin &Other) { return str_comp_nocase(m_aName, Other.m_aName) < 0; }
  287.         };
  288.  
  289.         void OnInit();
  290. diff -Naur /home/toil/teeworlds/src/game/collision.cpp src/game/collision.cpp
  291. --- /home/toil/teeworlds/src/game/collision.cpp 2012-06-26 16:53:53.376860790 +1000
  292. +++ src/game/collision.cpp      2012-07-08 00:01:43.141676413 +1000
  293. @@ -26,14 +26,14 @@
  294.         m_Width = m_pLayers->GameLayer()->m_Width;
  295.         m_Height = m_pLayers->GameLayer()->m_Height;
  296.         m_pTiles = static_cast<CTile *>(m_pLayers->Map()->GetData(m_pLayers->GameLayer()->m_Data));
  297. -
  298. +      
  299.         for(int i = 0; i < m_Width*m_Height; i++)
  300.         {
  301.                 int Index = m_pTiles[i].m_Index;
  302. -
  303. +              
  304.                 if(Index > 128)
  305.                         continue;
  306. -
  307. +              
  308.                 switch(Index)
  309.                 {
  310.                 case TILE_DEATH:
  311. @@ -45,35 +45,64 @@
  312.                 case TILE_NOHOOK:
  313.                         m_pTiles[i].m_Index = COLFLAG_SOLID|COLFLAG_NOHOOK;
  314.                         break;
  315. +               case TILE_SLOPE:
  316. +               {
  317. +                       m_pTiles[i].m_Index = COLFLAG_SLOPE;
  318. +                       m_pTiles[i].m_Flags = OrientationTile(m_pTiles[i].m_Flags, 1);
  319. +               }
  320. +                       break;
  321. +               case TILE_SLOPE_NH:
  322. +               {
  323. +                       m_pTiles[i].m_Index = COLFLAG_SLOPE|COLFLAG_NOHOOK;
  324. +                       m_pTiles[i].m_Flags = OrientationTile(m_pTiles[i].m_Flags, 1);
  325. +               }
  326. +                       break;
  327.                 default:
  328.                         m_pTiles[i].m_Index = 0;
  329.                 }
  330.         }
  331.  }
  332.  
  333. -int CCollision::GetTile(int x, int y)
  334. +int CCollision::GetTile(int x, int y, int *pFlags, int *pDx, int *pDy)
  335.  {
  336. -       int Nx = clamp(x/32, 0, m_Width-1);
  337. -       int Ny = clamp(y/32, 0, m_Height-1);
  338. +       int Address = clamp(y/32, 0, m_Height-1)*m_Width + clamp(x/32, 0, m_Width-1);
  339. +       int Index = m_pTiles[Address].m_Index;
  340. +      
  341. +       if(Index&COLFLAG_SLOPE)
  342. +       {
  343. +               int Flags = m_pTiles[Address].m_Flags;
  344. +               int Dx = x < 0 ? 31-abs(x)%32 : x%32;
  345. +               int Dy = y < 0 ? 31-abs(y)%32 : y%32;
  346. +
  347. +               if((Flags == 1 && Dy >= Dx) || (Flags == 3 && Dy+Dx <= 31) || (Flags == 5 && Dy <= Dx) || (Flags == 7 && Dy+Dx >= 31))
  348. +                       Index |= COLFLAG_SOLID;
  349. +               else if(Index&COLFLAG_NOHOOK)
  350. +                       Index ^= COLFLAG_NOHOOK;
  351. +
  352. +               if(pDx) *pDx = Dx;
  353. +               if(pDy) *pDy = Dy;
  354. +               if(pFlags) *pFlags = Flags;
  355. +}
  356. +
  357. +return Index > 128 ? 0 : Index;
  358.  
  359. -       return m_pTiles[Ny*m_Width+Nx].m_Index > 128 ? 0 : m_pTiles[Ny*m_Width+Nx].m_Index;
  360.  }
  361.  
  362.  bool CCollision::IsTileSolid(int x, int y)
  363.  {
  364. -       return GetTile(x, y)&COLFLAG_SOLID;
  365. +       return GetTile(x,y)&COLFLAG_SOLID;
  366.  }
  367.  
  368.  // TODO: rewrite this smarter!
  369.  int CCollision::IntersectLine(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision)
  370.  {
  371. -       float Distance = distance(Pos0, Pos1);
  372. -       int End(Distance+1);
  373. +       float d = distance(Pos0, Pos1);
  374. +       int End(d+1);
  375.         vec2 Last = Pos0;
  376. -
  377. +      
  378.         for(int i = 0; i < End; i++)
  379.         {
  380. -               float a = i/Distance;
  381. +               float a = i/d;
  382.                 vec2 Pos = mix(Pos0, Pos1, a);
  383.                 if(CheckPoint(Pos.x, Pos.y))
  384.                 {
  385. @@ -97,52 +126,112 @@
  386.  {
  387.         if(pBounces)
  388.                 *pBounces = 0;
  389. -
  390. +      
  391.         vec2 Pos = *pInoutPos;
  392. -       vec2 Vel = *pInoutVel;
  393. -       if(CheckPoint(Pos + Vel))
  394. +       vec2 NewPos = Pos + *pInoutVel;
  395. +       int Flags, Index = GetTile(round(NewPos.x), round(NewPos.y), &Flags);
  396. +
  397. +       if(Index&COLFLAG_SOLID)
  398.         {
  399.                 int Affected = 0;
  400. -               if(CheckPoint(Pos.x + Vel.x, Pos.y))
  401. +
  402. +               if(Index&COLFLAG_SLOPE)
  403. +               {
  404. +                       if(round(NewPos.x)/32 == round(Pos.x)/32 && round(NewPos.y)/32 == round(Pos.y)/32)//not correct, only approximative
  405. +                       {
  406. +                               vec2 Reflex = vec2(pInoutVel->y, pInoutVel->x); //inverting axisses values
  407. +                               if(Flags == 3 || Flags == 7)
  408. +                                       Reflex *= -1; //inverting sings
  409. +  
  410. +                               *pInoutVel = Elasticity? Reflex*Elasticity : (*pInoutVel+Reflex)*0.5f;
  411. +                               if(pBounces)
  412. +                                       (*pBounces)++;
  413. +                               Affected++;
  414. +
  415. +                               return;
  416. +                       }
  417. +               }
  418. +
  419. +               if(CheckPoint(NewPos.x, Pos.y))
  420.                 {
  421.                         pInoutVel->x *= -Elasticity;
  422.                         if(pBounces)
  423. -                               (*pBounces)++;
  424. +                               (*pBounces)++;                 
  425.                         Affected++;
  426.                 }
  427.  
  428. -               if(CheckPoint(Pos.x, Pos.y + Vel.y))
  429. +               if(CheckPoint(Pos.x, NewPos.y))
  430.                 {
  431.                         pInoutVel->y *= -Elasticity;
  432.                         if(pBounces)
  433. -                               (*pBounces)++;
  434. +                               (*pBounces)++;                 
  435.                         Affected++;
  436.                 }
  437. -
  438. +              
  439.                 if(Affected == 0)
  440. -               {
  441. -                       pInoutVel->x *= -Elasticity;
  442. -                       pInoutVel->y *= -Elasticity;
  443. -               }
  444. +                       *pInoutVel *= -Elasticity;
  445.         }
  446.         else
  447.         {
  448. -               *pInoutPos = Pos + Vel;
  449. +               *pInoutPos = NewPos;
  450.         }
  451.  }
  452.  
  453. -bool CCollision::TestBox(vec2 Pos, vec2 Size)
  454. +int CCollision::TestBox(vec2 Pos, vec2 Size)
  455. +{// not formatted, sorry :)
  456. +Pos -= Size*0.5f;
  457. +int Flags, Dx, Dy, Index = GetTile(round(Pos.x), round(Pos.y), &Flags, &Dx, &Dy);
  458. +if(Index&COLFLAG_SOLID)
  459.  {
  460. -       Size *= 0.5f;
  461. -       if(CheckPoint(Pos.x-Size.x, Pos.y-Size.y))
  462. -               return true;
  463. -       if(CheckPoint(Pos.x+Size.x, Pos.y-Size.y))
  464. -               return true;
  465. -       if(CheckPoint(Pos.x-Size.x, Pos.y+Size.y))
  466. -               return true;
  467. -       if(CheckPoint(Pos.x+Size.x, Pos.y+Size.y))
  468. -               return true;
  469. -       return false;
  470. +if(Index&COLFLAG_SLOPE && Flags == 3) return 3;
  471. +else return 64;
  472. +}
  473. +else if(Index&COLFLAG_SLOPE)
  474. +{
  475. +if(Flags == 1 && Dy+Size.y > Dx) return 64; //16|8
  476. +else if(Flags == 5 && Dy < Dx+Size.x) return 64; //32|2
  477. +}
  478. +  
  479. +Pos.x += Size.x;
  480. +Index = GetTile(round(Pos.x), round(Pos.y), &Flags, &Dx, &Dy);
  481. +if(Index&COLFLAG_SOLID)
  482. +{
  483. +if(Index&COLFLAG_SLOPE && Flags == 5) return 5;
  484. +else return 64;
  485. +}
  486. +else if(Index&COLFLAG_SLOPE)
  487. +{
  488. +if(Flags == 3 && Dy+Dx < 31+Size.x) return 64; // 32|1
  489. +else if(Flags == 7 && Dy+Size.y+Dx > 31) return 64; // 16|4
  490. +}
  491. +  
  492. +Pos.y += Size.y;
  493. +Index = GetTile(round(Pos.x), round(Pos.y), &Flags, &Dx, &Dy);
  494. +if(Index&COLFLAG_SOLID)
  495. +{
  496. +if(Index&COLFLAG_SLOPE && Flags == 7) return 7;
  497. +else return 64;
  498. +}
  499. +else if(Index&COLFLAG_SLOPE)
  500. +{    
  501. +if(Flags == 1 && Dy+Size.x > Dx) return 64; // 32|8
  502. +else if(Flags == 5 && Dy-Size.y < Dx) return 64; // 16|2
  503. +}
  504. +
  505. +Pos.x -= Size.x;    
  506. +Index = GetTile(round(Pos.x), round(Pos.y), &Flags, &Dx, &Dy);
  507. +if(Index&COLFLAG_SOLID)
  508. +{
  509. +if(Index&COLFLAG_SLOPE && Flags == 1) return 1;
  510. +else return 64;
  511. +}
  512. +else if(Index&COLFLAG_SLOPE)
  513. +{
  514. +if(Flags == 3 && Dy+Dx-Size.y < 31) return 64; // 16|1
  515. +else if(Flags == 7 && Dy+Dx > 31-Size.x) return 64; // 32|4
  516. +}
  517. +
  518. +return 0;
  519.  }
  520.  
  521.  void CCollision::MoveBox(vec2 *pInoutPos, vec2 *pInoutVel, vec2 Size, float Elasticity)
  522. @@ -150,10 +239,10 @@
  523.         // do the move
  524.         vec2 Pos = *pInoutPos;
  525.         vec2 Vel = *pInoutVel;
  526. -
  527. +      
  528.         float Distance = length(Vel);
  529.         int Max = (int)Distance;
  530. -
  531. +      
  532.         if(Distance > 0.00001f)
  533.         {
  534.                 //vec2 old_pos = pos;
  535. @@ -163,42 +252,107 @@
  536.                         //float amount = i/(float)max;
  537.                         //if(max == 0)
  538.                                 //amount = 0;
  539. -
  540. +                      
  541.                         vec2 NewPos = Pos + Vel*Fraction; // TODO: this row is not nice
  542. -
  543. -                       if(TestBox(vec2(NewPos.x, NewPos.y), Size))
  544. +                      
  545. +                       if(TestBox(NewPos, Size))
  546.                         {
  547.                                 int Hits = 0;
  548.  
  549. -                               if(TestBox(vec2(Pos.x, NewPos.y), Size))
  550. +                               int Colliding = TestBox(vec2(NewPos.x, Pos.y), Size);                          
  551. +                               if(Colliding)
  552.                                 {
  553. -                                       NewPos.y = Pos.y;
  554. -                                       Vel.y *= -Elasticity;
  555. +                                       if(Colliding == 64)
  556. +                                               Vel.x *= -Elasticity;
  557. +                                       else if(IntersectSlope(Colliding, &Vel, Elasticity))
  558. +                                               Pos = vec2(round(Pos.x), round(Pos.y));
  559. +
  560.                                         Hits++;
  561.                                 }
  562. -
  563. -                               if(TestBox(vec2(NewPos.x, Pos.y), Size))
  564. +                              
  565. +                               Colliding = TestBox(vec2(Pos.x, NewPos.y), Size);
  566. +                               if(Colliding)
  567.                                 {
  568. -                                       NewPos.x = Pos.x;
  569. -                                       Vel.x *= -Elasticity;
  570. +                                       if(Colliding == 64)
  571. +                                               Vel.y *= -Elasticity;
  572. +                                       else if(IntersectSlope(Colliding, &Vel, Elasticity))
  573. +                                               Pos = vec2(round(Pos.x), round(Pos.y));
  574. +
  575.                                         Hits++;
  576.                                 }
  577. -
  578. +                              
  579.                                 // neither of the tests got a collision.
  580.                                 // this is a real _corner case_!
  581.                                 if(Hits == 0)
  582. -                               {
  583. -                                       NewPos.y = Pos.y;
  584. -                                       Vel.y *= -Elasticity;
  585. -                                       NewPos.x = Pos.x;
  586. -                                       Vel.x *= -Elasticity;
  587. -                               }
  588. -                       }
  589. +                                       Vel *= -Elasticity;
  590.  
  591. -                       Pos = NewPos;
  592. +                       }
  593. +                       else
  594. +                               Pos = NewPos;
  595.                 }
  596.         }
  597. -
  598. +      
  599.         *pInoutPos = Pos;
  600.         *pInoutVel = Vel;
  601.  }
  602. +
  603. +int CCollision::OrientationTile(int Flags, int Dir)
  604. +{  //Converts tiles flags to get effective direction drawn in the map editor
  605. +  // 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];...
  606. +       if(Dir == 1)
  607. +       {
  608. +               if(Flags&TILEFLAG_ROTATE)
  609. +               {
  610. +                       if(Flags&TILEFLAG_HFLIP)
  611. +                               Dir = Flags&TILEFLAG_VFLIP? 7 : 5;
  612. +                       else
  613. +                               Dir = Flags&TILEFLAG_VFLIP? 1 : 3;
  614. +               }
  615. +               else
  616. +               {
  617. +                       if(Flags&TILEFLAG_HFLIP)
  618. +                               Dir = Flags&TILEFLAG_VFLIP? 5 : 3;
  619. +                       else
  620. +                               Dir = Flags&TILEFLAG_VFLIP? 7 : 1;
  621. +               }
  622. +       }
  623. +       else if(Dir == 4)//this variant is useless now, but in future coulbe be used
  624. +       {
  625. +               if(Flags&TILEFLAG_ROTATE)
  626. +                       Dir = Flags&TILEFLAG_HFLIP? 6 : 2;
  627. +               else
  628. +                       Dir = Flags&TILEFLAG_HFLIP? 0 : 4;
  629. +       }
  630. +
  631. +       return Dir;
  632. +}
  633. +
  634. +bool CCollision::IntersectSlope(int Flags, vec2 *pVel, int Elasticity)
  635. +{
  636. +       vec2 Vel = *pVel;
  637. +       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))
  638. +       {
  639. +               vec2 Reaction = vec2(Vel.y, Vel.x); //inverting axisses values
  640. +               if(Flags == 3 || Flags == 7)
  641. +                       Reaction *= -1; //inverting sings
  642. +
  643. +               *pVel = Elasticity? Reaction*Elasticity : (Vel+Reaction)*0.5f;
  644. +               return true;
  645. +       }
  646. +       else
  647. +               return false;
  648. +
  649. +//more general intersection function: maybe useful in future (not formatted)
  650. +/* //equation of the line(AB) in implicit form (ax+by+c=0) analytic geometry
  651. +float a1= Vel.y-Corner.y, b1= Corner.x-Vel.x, c1= -Corner.x*Vel.y; //1 first line: player movement
  652. +float a2= B.y-A.y, b2= A.x-B.x, c2= -A.x*B.y; //2 second line: slope segment
  653. +  
  654. +float d = a1*b2-a2*b1;
  655. +
  656. +if(d)//lines are not parallel
  657. +{
  658. +vec2 HitPoint = vec2((b1*c2-b2*c1)/d, (a2*c1-a1*c2)/d);
  659. +}
  660. +else
  661. +return false*/
  662. +}
  663. \ No newline at end of file
  664. diff -Naur /home/toil/teeworlds/src/game/collision.h src/game/collision.h
  665. --- /home/toil/teeworlds/src/game/collision.h   2012-06-26 16:53:53.376860790 +1000
  666. +++ src/game/collision.h        2012-07-07 23:49:37.953689524 +1000
  667. @@ -13,14 +13,16 @@
  668.         class CLayers *m_pLayers;
  669.  
  670.         bool IsTileSolid(int x, int y);
  671. -       int GetTile(int x, int y);
  672. -
  673. +       int GetTile(int x, int y, int *pFlags=0, int *pDx=0, int *pDy=0);
  674. +       int OrientationTile(int Flags, int Dir);
  675. +       bool IntersectSlope(int Flags, vec2 *pVel, int Elasticity);
  676.  public:
  677.         enum
  678.         {
  679.                 COLFLAG_SOLID=1,
  680.                 COLFLAG_DEATH=2,
  681.                 COLFLAG_NOHOOK=4,
  682. +               COLFLAG_SLOPE=8,
  683.         };
  684.  
  685.         CCollision();
  686. @@ -33,7 +35,7 @@
  687.         int IntersectLine(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision);
  688.         void MovePoint(vec2 *pInoutPos, vec2 *pInoutVel, float Elasticity, int *pBounces);
  689.         void MoveBox(vec2 *pInoutPos, vec2 *pInoutVel, vec2 Size, float Elasticity);
  690. -       bool TestBox(vec2 Pos, vec2 Size);
  691. +       int TestBox(vec2 Pos, vec2 Size);
  692.  };
  693.  
  694.  #endif
  695. diff -Naur /home/toil/teeworlds/src/game/editor/layer_tiles.cpp src/game/editor/layer_tiles.cpp
  696. --- /home/toil/teeworlds/src/game/editor/layer_tiles.cpp        2012-06-26 16:53:53.380861019 +1000
  697. +++ src/game/editor/layer_tiles.cpp     2012-07-07 23:49:37.665176329 +1000
  698. @@ -220,10 +220,13 @@
  699.                         m_pTiles[y*m_Width+m_Width-1-x] = Tmp;
  700.                 }
  701.  
  702. -       if(!m_Game)
  703. -               for(int y = 0; y < m_Height; y++)
  704. -                       for(int x = 0; x < m_Width; x++)
  705. -                               m_pTiles[y*m_Width+x].m_Flags ^= m_pTiles[y*m_Width+x].m_Flags&TILEFLAG_ROTATE ? TILEFLAG_HFLIP : TILEFLAG_VFLIP;
  706. +       for(int y = 0; y < m_Height; y++)
  707. +               for(int x = 0; x < m_Width; x++)
  708. +               {
  709. +                       int N = y*m_Width+x;
  710. +                       if(!m_Game || m_pTiles[N].m_Index == TILE_SLOPE || m_pTiles[N].m_Index == TILE_SLOPE_NH)
  711. +                               m_pTiles[N].m_Flags ^= m_pTiles[N].m_Flags&TILEFLAG_ROTATE ? TILEFLAG_HFLIP : TILEFLAG_VFLIP;
  712. +               }
  713.  }
  714.  
  715.  void CLayerTiles::BrushFlipY()
  716. @@ -236,21 +239,24 @@
  717.                         m_pTiles[(m_Height-1-y)*m_Width+x] = Tmp;
  718.                 }
  719.  
  720. -       if(!m_Game)
  721. -               for(int y = 0; y < m_Height; y++)
  722. -                       for(int x = 0; x < m_Width; x++)
  723. -                               m_pTiles[y*m_Width+x].m_Flags ^= m_pTiles[y*m_Width+x].m_Flags&TILEFLAG_ROTATE ? TILEFLAG_VFLIP : TILEFLAG_HFLIP;
  724. +       for(int y = 0; y < m_Height; y++)
  725. +               for(int x = 0; x < m_Width; x++)
  726. +               {
  727. +                       int N = y*m_Width+x;
  728. +                       if(!m_Game || m_pTiles[N].m_Index == TILE_SLOPE || m_pTiles[N].m_Index == TILE_SLOPE_NH)
  729. +                               m_pTiles[N].m_Flags ^= m_pTiles[N].m_Flags&TILEFLAG_ROTATE ? TILEFLAG_VFLIP : TILEFLAG_HFLIP;
  730. +               }
  731.  }
  732.  
  733.  void CLayerTiles::BrushRotate(float Amount)
  734.  {
  735. -       int Rotation = (round(360.0f*Amount/(pi*2))/90)%4;      // 0=0�, 1=90�, 2=180�, 3=270�
  736. +       int Rotation = (round(360.0f*Amount/(pi*2))/90)%4;      // 0=0�, 1=90�, 2=180�, 3=270�
  737.         if(Rotation < 0)
  738.                 Rotation +=4;
  739.  
  740.         if(Rotation == 1 || Rotation == 3)
  741.         {
  742. -               // 90� rotation
  743. +               // 90� rotation
  744.                 CTile *pTempData = new CTile[m_Width*m_Height];
  745.                 mem_copy(pTempData, m_pTiles, m_Width*m_Height*sizeof(CTile));
  746.                 CTile *pDst = m_pTiles;
  747. @@ -258,7 +264,7 @@
  748.                         for(int y = m_Height-1; y >= 0; --y, ++pDst)
  749.                         {
  750.                                 *pDst = pTempData[y*m_Width+x];
  751. -                               if(!m_Game)
  752. +                               if(!m_Game || pDst->m_Index == TILE_SLOPE || pDst->m_Index == TILE_SLOPE_NH)
  753.                                 {
  754.                                         if(pDst->m_Flags&TILEFLAG_ROTATE)
  755.                                                 pDst->m_Flags ^= (TILEFLAG_HFLIP|TILEFLAG_VFLIP);
  756. diff -Naur /home/toil/teeworlds/src/game/generated/nethash.c src/game/generated/nethash.c
  757. --- /home/toil/teeworlds/src/game/generated/nethash.c   1970-01-01 10:00:00.000000000 +1000
  758. +++ src/game/generated/nethash.c        2012-07-07 23:45:54.225177199 +1000
  759. @@ -0,0 +1 @@
  760. +#define GAME_NETVERSION_HASH "b67d1f1a1eea234e"
  761. diff -Naur /home/toil/teeworlds/src/game/mapitems.h src/game/mapitems.h
  762. --- /home/toil/teeworlds/src/game/mapitems.h    2012-06-26 16:53:53.384860969 +1000
  763. +++ src/game/mapitems.h 2012-07-07 23:53:46.241689194 +1000
  764. @@ -46,7 +46,8 @@
  765.         TILE_SOLID,
  766.         TILE_DEATH,
  767.         TILE_NOHOOK,
  768. -
  769. +       TILE_SLOPE=17,
  770. +       TILE_SLOPE_NH,
  771.         TILEFLAG_VFLIP=1,
  772.         TILEFLAG_HFLIP=2,
  773.         TILEFLAG_OPAQUE=4,
  774. diff -Naur /home/toil/teeworlds/src/game/server/gamecontext.cpp src/game/server/gamecontext.cpp
  775. --- /home/toil/teeworlds/src/game/server/gamecontext.cpp        2012-06-26 16:53:53.392865827 +1000
  776. +++ src/game/server/gamecontext.cpp     2012-07-07 23:49:37.965178275 +1000
  777. @@ -1120,39 +1120,29 @@
  778.         if(!pSelf->m_pController->IsTeamplay())
  779.                 return;
  780.  
  781. -       int CounterRed = 0;
  782. -       int CounterBlue = 0;
  783. +       int rnd = 0;
  784.         int PlayerTeam = 0;
  785. -       for(int i = 0; i < MAX_CLIENTS; ++i)
  786. +       int aPlayer[MAX_CLIENTS];
  787. +
  788. +       for(int i = 0; i < MAX_CLIENTS; i++)
  789.                 if(pSelf->m_apPlayers[i] && pSelf->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS)
  790. -                       ++PlayerTeam;
  791. -       PlayerTeam = (PlayerTeam+1)/2;
  792. -      
  793. +                       aPlayer[PlayerTeam++]=i;
  794. +
  795.         pSelf->SendChat(-1, CGameContext::CHAT_ALL, "Teams were shuffled");
  796.  
  797. -       for(int i = 0; i < MAX_CLIENTS; ++i)
  798. +       //creating random permutation
  799. +       for(int i = PlayerTeam; i > 1; i--)
  800.         {
  801. -               if(pSelf->m_apPlayers[i] && pSelf->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS)
  802. -               {
  803. -                       if(CounterRed == PlayerTeam)
  804. -                               pSelf->m_pController->DoTeamChange(pSelf->m_apPlayers[i], TEAM_BLUE, false);
  805. -                       else if(CounterBlue == PlayerTeam)
  806. -                               pSelf->m_pController->DoTeamChange(pSelf->m_apPlayers[i], TEAM_RED, false);
  807. -                       else
  808. -                       {      
  809. -                               if(rand() % 2)
  810. -                               {
  811. -                                       pSelf->m_pController->DoTeamChange(pSelf->m_apPlayers[i], TEAM_BLUE, false);
  812. -                                       ++CounterBlue;
  813. -                               }
  814. -                               else
  815. -                               {
  816. -                                       pSelf->m_pController->DoTeamChange(pSelf->m_apPlayers[i], TEAM_RED, false);
  817. -                                       ++CounterRed;
  818. -                               }
  819. -                       }
  820. -               }
  821. +               rnd = rand() % i;
  822. +               int tmp = aPlayer[rnd];
  823. +               aPlayer[rnd] = aPlayer[i-1];
  824. +               aPlayer[i-1] = tmp;
  825.         }
  826. +       //uneven Number of Players?
  827. +       rnd = PlayerTeam % 2 ? rand() % 2 : 0;
  828. +
  829. +       for(int i = 0; i < PlayerTeam; i++)
  830. +               pSelf->m_pController->DoTeamChange(pSelf->m_apPlayers[aPlayer[i]], i < (PlayerTeam+rnd)/2 ? TEAM_RED : TEAM_BLUE, false);
  831.  }
  832.  
  833.  void CGameContext::ConLockTeams(IConsole::IResult *pResult, void *pUserData)
  834. @@ -1458,15 +1448,15 @@
  835.         m_Collision.Init(&m_Layers);
  836.  
  837.         // select gametype
  838. -       if(str_comp(g_Config.m_SvGametype, "mod") == 0)
  839. +       if(str_comp_nocase(g_Config.m_SvGametype, "mod") == 0)
  840.                 m_pController = new CGameControllerMOD(this);
  841. -       else if(str_comp(g_Config.m_SvGametype, "ctf") == 0)
  842. +       else if(str_comp_nocase(g_Config.m_SvGametype, "ctf") == 0)
  843.                 m_pController = new CGameControllerCTF(this);
  844. -       else if(str_comp(g_Config.m_SvGametype, "lms") == 0)
  845. +       else if(str_comp_nocase(g_Config.m_SvGametype, "lms") == 0)
  846.                 m_pController = new CGameControllerLMS(this);
  847. -       else if(str_comp(g_Config.m_SvGametype, "sur") == 0)
  848. +       else if(str_comp_nocase(g_Config.m_SvGametype, "sur") == 0)
  849.                 m_pController = new CGameControllerSUR(this);
  850. -       else if(str_comp(g_Config.m_SvGametype, "tdm") == 0)
  851. +       else if(str_comp_nocase(g_Config.m_SvGametype, "tdm") == 0)
  852.                 m_pController = new CGameControllerTDM(this);
  853.         else
  854.                 m_pController = new CGameControllerDM(this);
  855. diff -Naur /home/toil/teeworlds/src/game/server/gamemodes/ctf.cpp src/game/server/gamemodes/ctf.cpp
  856. --- /home/toil/teeworlds/src/game/server/gamemodes/ctf.cpp      2012-06-26 16:53:53.396862075 +1000
  857. +++ src/game/server/gamemodes/ctf.cpp   2012-07-07 23:49:37.969176549 +1000
  858. @@ -287,6 +287,9 @@
  859.                                 {
  860.                                         F->m_Vel.y += GameServer()->m_World.m_Core.m_Tuning.m_Gravity;
  861.                                         GameServer()->Collision()->MoveBox(&F->m_Pos, &F->m_Vel, vec2(F->ms_PhysSize, F->ms_PhysSize), 0.5f);
  862. +
  863. +                                       if(GameServer()->Collision()->CheckPoint(F->m_Pos.x, F->m_Pos.y+F->ms_PhysSize/2+5))
  864. +                                               F->m_Vel.x *= GameServer()->m_World.m_Core.m_Tuning.m_GroundFriction;
  865.                                 }
  866.                         }
  867.                 }
  868.  

Reply to "Untitled"

Here you can reply to the paste above