- diff -Naur src/game/client/components/players.cpp /home/toil/teeworlds/src/game/client/components/players.cpp
- --- src/game/client/components/players.cpp 2012-07-07 23:49:37.941683878 +1000
- +++ /home/toil/teeworlds/src/game/client/components/players.cpp 2012-06-26 16:53:53.368860821 +1000
- @@ -272,7 +272,7 @@
- }
- bool Stationary = Player.m_VelX <= 1 && Player.m_VelX >= -1;
- - bool InAir = !(Collision()->CheckPoint(Player.m_X-14, Player.m_Y+16) || Collision()->CheckPoint(Player.m_X+14, Player.m_Y+16));
- + bool InAir = !Collision()->CheckPoint(Player.m_X, Player.m_Y+16);
- bool WantOtherDir = (Player.m_Direction == -1 && Vel.x > 0) || (Player.m_Direction == 1 && Vel.x < 0);
- // evaluate animation
- diff -Naur src/game/collision.cpp /home/toil/teeworlds/src/game/collision.cpp
- --- src/game/collision.cpp 2012-07-08 00:43:40.533677337 +1000
- +++ /home/toil/teeworlds/src/game/collision.cpp 2012-06-26 16:53:53.376860790 +1000
- @@ -26,14 +26,14 @@
- m_Width = m_pLayers->GameLayer()->m_Width;
- m_Height = m_pLayers->GameLayer()->m_Height;
- m_pTiles = static_cast<CTile *>(m_pLayers->Map()->GetData(m_pLayers->GameLayer()->m_Data));
- -
- +
- for(int i = 0; i < m_Width*m_Height; i++)
- {
- int Index = m_pTiles[i].m_Index;
- -
- +
- if(Index > 128)
- continue;
- -
- +
- switch(Index)
- {
- case TILE_DEATH:
- @@ -45,64 +45,35 @@
- case TILE_NOHOOK:
- m_pTiles[i].m_Index = COLFLAG_SOLID|COLFLAG_NOHOOK;
- break;
- - case TILE_SLOPE:
- - {
- - m_pTiles[i].m_Index = COLFLAG_SLOPE;
- - m_pTiles[i].m_Flags = OrientationTile(m_pTiles[i].m_Flags, 1);
- - }
- - break;
- - case TILE_SLOPE_NH:
- - {
- - m_pTiles[i].m_Index = COLFLAG_SLOPE|COLFLAG_NOHOOK;
- - m_pTiles[i].m_Flags = OrientationTile(m_pTiles[i].m_Flags, 1);
- - }
- - break;
- default:
- m_pTiles[i].m_Index = 0;
- }
- }
- }
- -int CCollision::GetTile(int x, int y, int *pFlags, int *pDx, int *pDy)
- +int CCollision::GetTile(int x, int y)
- {
- - int Address = clamp(y/32, 0, m_Height-1)*m_Width + clamp(x/32, 0, m_Width-1);
- - int Index = m_pTiles[Address].m_Index;
- -
- - if(Index&COLFLAG_SLOPE)
- - {
- - int Flags = m_pTiles[Address].m_Flags;
- - int Dx = x < 0 ? 31-abs(x)%32 : x%32;
- - int Dy = y < 0 ? 31-abs(y)%32 : y%32;
- -
- - if((Flags == 1 && Dy >= Dx) || (Flags == 3 && Dy+Dx <= 31) || (Flags == 5 && Dy <= Dx) || (Flags == 7 && Dy+Dx >= 31))
- - Index |= COLFLAG_SOLID;
- - else if(Index&COLFLAG_NOHOOK)
- - Index ^= COLFLAG_NOHOOK;
- -
- - if(pDx) *pDx = Dx;
- - if(pDy) *pDy = Dy;
- - if(pFlags) *pFlags = Flags;
- -}
- -
- -return Index > 128 ? 0 : Index;
- + int Nx = clamp(x/32, 0, m_Width-1);
- + int Ny = clamp(y/32, 0, m_Height-1);
- + return m_pTiles[Ny*m_Width+Nx].m_Index > 128 ? 0 : m_pTiles[Ny*m_Width+Nx].m_Index;
- }
- bool CCollision::IsTileSolid(int x, int y)
- {
- - return GetTile(x,y)&COLFLAG_SOLID;
- + return GetTile(x, y)&COLFLAG_SOLID;
- }
- // TODO: rewrite this smarter!
- int CCollision::IntersectLine(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision)
- {
- - float d = distance(Pos0, Pos1);
- - int End(d+1);
- + float Distance = distance(Pos0, Pos1);
- + int End(Distance+1);
- vec2 Last = Pos0;
- -
- +
- for(int i = 0; i < End; i++)
- {
- - float a = i/d;
- + float a = i/Distance;
- vec2 Pos = mix(Pos0, Pos1, a);
- if(CheckPoint(Pos.x, Pos.y))
- {
- @@ -126,127 +97,52 @@
- {
- if(pBounces)
- *pBounces = 0;
- -
- - vec2 Pos = *pInoutPos;
- - vec2 NewPos = Pos + *pInoutVel;
- - int Flags, Index = GetTile(round(NewPos.x), round(NewPos.y), &Flags);
- - if(Index&COLFLAG_SOLID)
- + vec2 Pos = *pInoutPos;
- + vec2 Vel = *pInoutVel;
- + if(CheckPoint(Pos + Vel))
- {
- int Affected = 0;
- -
- - if(Index&COLFLAG_SLOPE)
- - {
- - if(round(NewPos.x)/32 == round(Pos.x)/32 && round(NewPos.y)/32 == round(Pos.y)/32)//not correct, only approximative
- - {
- - vec2 Reflex = vec2(pInoutVel->y, pInoutVel->x); //inverting axisses values
- - if(Flags == 3 || Flags == 7)
- - Reflex *= -1; //inverting sings
- -
- - *pInoutVel = Elasticity? Reflex*Elasticity : (*pInoutVel+Reflex)*0.5f;
- - if(pBounces)
- - (*pBounces)++;
- - Affected++;
- -
- - return;
- - }
- - }
- -
- - if(CheckPoint(NewPos.x, Pos.y))
- + if(CheckPoint(Pos.x + Vel.x, Pos.y))
- {
- pInoutVel->x *= -Elasticity;
- if(pBounces)
- - (*pBounces)++;
- + (*pBounces)++;
- Affected++;
- }
- - if(CheckPoint(Pos.x, NewPos.y))
- + if(CheckPoint(Pos.x, Pos.y + Vel.y))
- {
- pInoutVel->y *= -Elasticity;
- if(pBounces)
- - (*pBounces)++;
- + (*pBounces)++;
- Affected++;
- }
- -
- +
- if(Affected == 0)
- - *pInoutVel *= -Elasticity;
- + {
- + pInoutVel->x *= -Elasticity;
- + pInoutVel->y *= -Elasticity;
- + }
- }
- else
- {
- - *pInoutPos = NewPos;
- + *pInoutPos = Pos + Vel;
- }
- }
- -int CCollision::TestBox(vec2 Pos, vec2 Size)
- +bool CCollision::TestBox(vec2 Pos, vec2 Size)
- {
- - Pos -= Size*0.5f;
- - int Flags, Dx, Dy, Index = GetTile(round(Pos.x), round(Pos.y), &Flags, &Dx, &Dy);
- - if(Index&COLFLAG_SOLID)
- - {
- - if(Index&COLFLAG_SLOPE && Flags == 3)
- - return 3;
- - else
- - return 64;
- - }
- - else if(Index&COLFLAG_SLOPE)
- - {
- - if(Flags == 1 && Dy+Size.y > Dx)
- - return 64; //16|8
- - else if(Flags == 5 && Dy < Dx+Size.x)
- - return 64; //32|2
- - }
- -
- - Pos.x += Size.x;
- - Index = GetTile(round(Pos.x), round(Pos.y), &Flags, &Dx, &Dy);
- - if(Index&COLFLAG_SOLID)
- - {
- - if(Index&COLFLAG_SLOPE && Flags == 5)
- - return 5;
- - else
- - return 64;
- - }
- - else if(Index&COLFLAG_SLOPE)
- - {
- - if(Flags == 3 && Dy+Dx < 31+Size.x)
- - return 64; // 32|1
- - else if(Flags == 7 && Dy+Size.y+Dx > 31)
- - return 64; // 16|4
- - }
- -
- - Pos.y += Size.y;
- - Index = GetTile(round(Pos.x), round(Pos.y), &Flags, &Dx, &Dy);
- - if(Index&COLFLAG_SOLID)
- - {
- - if(Index&COLFLAG_SLOPE && Flags == 7)
- - return 7;
- - else
- - return 64;
- - }
- - else if(Index&COLFLAG_SLOPE)
- - {
- - if(Flags == 1 && Dy+Size.x > Dx)
- - return 64; // 32|8
- - else if(Flags == 5 && Dy-Size.y < Dx)
- - return 64; // 16|2
- - }
- - Pos.x -= Size.x;
- - Index = GetTile(round(Pos.x), round(Pos.y), &Flags, &Dx, &Dy);
- - if(Index&COLFLAG_SOLID)
- - {
- - if(Index&COLFLAG_SLOPE && Flags == 1)
- - return 1;
- - else
- - return 64;
- - }
- - else if(Index&COLFLAG_SLOPE)
- - {
- - if(Flags == 3 && Dy+Dx-Size.y < 31)
- - return 64; // 16|1
- - else if(Flags == 7 && Dy+Dx > 31-Size.x)
- - return 64; // 32|4
- - }
- -
- - return 0;
- + Size *= 0.5f;
- + if(CheckPoint(Pos.x-Size.x, Pos.y-Size.y))
- + return true;
- + if(CheckPoint(Pos.x+Size.x, Pos.y-Size.y))
- + return true;
- + if(CheckPoint(Pos.x-Size.x, Pos.y+Size.y))
- + return true;
- + if(CheckPoint(Pos.x+Size.x, Pos.y+Size.y))
- + return true;
- + return false;
- }
- void CCollision::MoveBox(vec2 *pInoutPos, vec2 *pInoutVel, vec2 Size, float Elasticity)
- @@ -254,10 +150,10 @@
- // do the move
- vec2 Pos = *pInoutPos;
- vec2 Vel = *pInoutVel;
- -
- +
- float Distance = length(Vel);
- int Max = (int)Distance;
- -
- +
- if(Distance > 0.00001f)
- {
- //vec2 old_pos = pos;
- @@ -267,107 +163,42 @@
- //float amount = i/(float)max;
- //if(max == 0)
- //amount = 0;
- -
- +
- vec2 NewPos = Pos + Vel*Fraction; // TODO: this row is not nice
- -
- - if(TestBox(NewPos, Size))
- +
- + if(TestBox(vec2(NewPos.x, NewPos.y), Size))
- {
- int Hits = 0;
- - int Colliding = TestBox(vec2(NewPos.x, Pos.y), Size);
- - if(Colliding)
- + if(TestBox(vec2(Pos.x, NewPos.y), Size))
- {
- - if(Colliding == 64)
- - Vel.x *= -Elasticity;
- - else if(IntersectSlope(Colliding, &Vel, Elasticity))
- - Pos = vec2(round(Pos.x), round(Pos.y));
- -
- + NewPos.y = Pos.y;
- + Vel.y *= -Elasticity;
- Hits++;
- }
- -
- - Colliding = TestBox(vec2(Pos.x, NewPos.y), Size);
- - if(Colliding)
- - {
- - if(Colliding == 64)
- - Vel.y *= -Elasticity;
- - else if(IntersectSlope(Colliding, &Vel, Elasticity))
- - Pos = vec2(round(Pos.x), round(Pos.y));
- + if(TestBox(vec2(NewPos.x, Pos.y), Size))
- + {
- + NewPos.x = Pos.x;
- + Vel.x *= -Elasticity;
- Hits++;
- }
- -
- +
- // neither of the tests got a collision.
- // this is a real _corner case_!
- if(Hits == 0)
- - Vel *= -Elasticity;
- -
- + {
- + NewPos.y = Pos.y;
- + Vel.y *= -Elasticity;
- + NewPos.x = Pos.x;
- + Vel.x *= -Elasticity;
- + }
- }
- - else
- - Pos = NewPos;
- - }
- - }
- -
- - *pInoutPos = Pos;
- - *pInoutVel = Vel;
- -}
- -int CCollision::OrientationTile(int Flags, int Dir)
- -{ //Converts tiles flags to get effective direction drawn in the map editor
- - // 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];...
- - if(Dir == 1)
- - {
- - if(Flags&TILEFLAG_ROTATE)
- - {
- - if(Flags&TILEFLAG_HFLIP)
- - Dir = Flags&TILEFLAG_VFLIP? 7 : 5;
- - else
- - Dir = Flags&TILEFLAG_VFLIP? 1 : 3;
- - }
- - else
- - {
- - if(Flags&TILEFLAG_HFLIP)
- - Dir = Flags&TILEFLAG_VFLIP? 5 : 3;
- - else
- - Dir = Flags&TILEFLAG_VFLIP? 7 : 1;
- + Pos = NewPos;
- }
- }
- - else if(Dir == 4)//this variant is useless now, but in future coulbe be used
- - {
- - if(Flags&TILEFLAG_ROTATE)
- - Dir = Flags&TILEFLAG_HFLIP? 6 : 2;
- - else
- - Dir = Flags&TILEFLAG_HFLIP? 0 : 4;
- - }
- -
- - return Dir;
- -}
- -
- -bool CCollision::IntersectSlope(int Flags, vec2 *pVel, int Elasticity)
- -{
- - vec2 Vel = *pVel;
- - 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))
- - {
- - vec2 Reaction = vec2(Vel.y, Vel.x); //inverting axisses values
- - if(Flags == 3 || Flags == 7)
- - Reaction *= -1; //inverting sings
- -
- - *pVel = Elasticity? Reaction*Elasticity : (Vel+Reaction)*0.5f;
- - return true;
- - }
- - else
- - return false;
- -//more general intersection function: maybe useful in future (not formatted)
- -/* //equation of the line(AB) in implicit form (ax+by+c=0) analytic geometry
- -float a1= Vel.y-Corner.y, b1= Corner.x-Vel.x, c1= -Corner.x*Vel.y; //1 first line: player movement
- -float a2= B.y-A.y, b2= A.x-B.x, c2= -A.x*B.y; //2 second line: slope segment
- -
- -float d = a1*b2-a2*b1;
- -
- -if(d)//lines are not parallel
- -{
- -vec2 HitPoint = vec2((b1*c2-b2*c1)/d, (a2*c1-a1*c2)/d);
- -}
- -else
- -return false*/
- + *pInoutPos = Pos;
- + *pInoutVel = Vel;
- }
- diff -Naur src/game/collision.h /home/toil/teeworlds/src/game/collision.h
- --- src/game/collision.h 2012-07-07 23:49:37.953689524 +1000
- +++ /home/toil/teeworlds/src/game/collision.h 2012-06-26 16:53:53.376860790 +1000
- @@ -13,16 +13,14 @@
- class CLayers *m_pLayers;
- bool IsTileSolid(int x, int y);
- - int GetTile(int x, int y, int *pFlags=0, int *pDx=0, int *pDy=0);
- - int OrientationTile(int Flags, int Dir);
- - bool IntersectSlope(int Flags, vec2 *pVel, int Elasticity);
- + int GetTile(int x, int y);
- +
- public:
- enum
- {
- COLFLAG_SOLID=1,
- COLFLAG_DEATH=2,
- COLFLAG_NOHOOK=4,
- - COLFLAG_SLOPE=8,
- };
- CCollision();
- @@ -35,7 +33,7 @@
- int IntersectLine(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision);
- void MovePoint(vec2 *pInoutPos, vec2 *pInoutVel, float Elasticity, int *pBounces);
- void MoveBox(vec2 *pInoutPos, vec2 *pInoutVel, vec2 Size, float Elasticity);
- - int TestBox(vec2 Pos, vec2 Size);
- + bool TestBox(vec2 Pos, vec2 Size);
- };
- #endif
- diff -Naur src/game/editor/layer_tiles.cpp /home/toil/teeworlds/src/game/editor/layer_tiles.cpp
- --- src/game/editor/layer_tiles.cpp 2012-07-08 00:55:59.013676221 +1000
- +++ /home/toil/teeworlds/src/game/editor/layer_tiles.cpp 2012-06-26 16:53:53.380861019 +1000
- @@ -219,6 +219,7 @@
- m_pTiles[y*m_Width+x] = m_pTiles[y*m_Width+m_Width-1-x];
- m_pTiles[y*m_Width+m_Width-1-x] = Tmp;
- }
- +
- if(!m_Game)
- for(int y = 0; y < m_Height; y++)
- for(int x = 0; x < m_Width; x++)
- @@ -243,13 +244,13 @@
- void CLayerTiles::BrushRotate(float Amount)
- {
- - int Rotation = (round(360.0f*Amount/(pi*2))/90)%4; // 0=0�, 1=90�, 2=180�, 3=270�
- + int Rotation = (round(360.0f*Amount/(pi*2))/90)%4; // 0=0�, 1=90�, 2=180�, 3=270�
- if(Rotation < 0)
- Rotation +=4;
- if(Rotation == 1 || Rotation == 3)
- {
- - // 90� rotation
- + // 90� rotation
- CTile *pTempData = new CTile[m_Width*m_Height];
- mem_copy(pTempData, m_pTiles, m_Width*m_Height*sizeof(CTile));
- CTile *pDst = m_pTiles;
- @@ -257,7 +258,7 @@
- for(int y = m_Height-1; y >= 0; --y, ++pDst)
- {
- *pDst = pTempData[y*m_Width+x];
- - if(!m_Game || pDst->m_Index == TILE_SLOPE || pDst->m_Index == TILE_SLOPE_NH)
- + if(!m_Game)
- {
- if(pDst->m_Flags&TILEFLAG_ROTATE)
- pDst->m_Flags ^= (TILEFLAG_HFLIP|TILEFLAG_VFLIP);
- diff -Naur src/game/generated/nethash.c /home/toil/teeworlds/src/game/generated/nethash.c
- --- src/game/generated/nethash.c 2012-07-07 23:45:54.225177199 +1000
- +++ /home/toil/teeworlds/src/game/generated/nethash.c 1970-01-01 10:00:00.000000000 +1000
- @@ -1 +0,0 @@
- -#define GAME_NETVERSION_HASH "b67d1f1a1eea234e"
- diff -Naur src/game/mapitems.h /home/toil/teeworlds/src/game/mapitems.h
- --- src/game/mapitems.h 2012-07-08 00:37:07.813676851 +1000
- +++ /home/toil/teeworlds/src/game/mapitems.h 2012-06-26 16:53:53.384860969 +1000
- @@ -46,8 +46,6 @@
- TILE_SOLID,
- TILE_DEATH,
- TILE_NOHOOK,
- - TILE_SLOPE=17,
- - TILE_SLOPE_NH,
- TILEFLAG_VFLIP=1,
- TILEFLAG_HFLIP=2,
- diff -Naur src/game/server/gamemodes/ctf.cpp /home/toil/teeworlds/src/game/server/gamemodes/ctf.cpp
- --- src/game/server/gamemodes/ctf.cpp 2012-07-07 23:49:37.969176549 +1000
- +++ /home/toil/teeworlds/src/game/server/gamemodes/ctf.cpp 2012-06-26 16:53:53.396862075 +1000
- @@ -287,9 +287,6 @@
- {
- F->m_Vel.y += GameServer()->m_World.m_Core.m_Tuning.m_Gravity;
- GameServer()->Collision()->MoveBox(&F->m_Pos, &F->m_Vel, vec2(F->ms_PhysSize, F->ms_PhysSize), 0.5f);
- -
- - if(GameServer()->Collision()->CheckPoint(F->m_Pos.x, F->m_Pos.y+F->ms_PhysSize/2+5))
- - F->m_Vel.x *= GameServer()->m_World.m_Core.m_Tuning.m_GroundFriction;
- }
- }
- }