mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Some optimizations and Removed Collision and No Hook from Front Layer to avoid vanilla client prediction errors
Signed-off-by: GreYFoXGTi <GreYFoXGTi@GMaiL.CoM>
This commit is contained in:
parent
22fc13c692
commit
dd63ab26a9
|
@ -40,7 +40,7 @@ void CCollision::Init(class CLayers *pLayers)
|
|||
for(int i = 0; i < m_Width*m_Height; i++)
|
||||
{
|
||||
int Index = m_pFront[i].m_Index;
|
||||
if(Index > 191)
|
||||
if(Index > TILE_NPH)
|
||||
continue;
|
||||
|
||||
switch(Index)
|
||||
|
@ -49,10 +49,10 @@ void CCollision::Init(class CLayers *pLayers)
|
|||
m_pFront[i].m_Index = COLFLAG_DEATH;
|
||||
break;
|
||||
case TILE_SOLID:
|
||||
m_pFront[i].m_Index = COLFLAG_SOLID;
|
||||
m_pFront[i].m_Index = 0;
|
||||
break;
|
||||
case TILE_NOHOOK:
|
||||
m_pFront[i].m_Index = COLFLAG_SOLID|COLFLAG_NOHOOK;
|
||||
m_pFront[i].m_Index = 0;
|
||||
break;
|
||||
case TILE_NOLASER:
|
||||
m_pFront[i].m_Index = COLFLAG_NOLASER;
|
||||
|
@ -62,7 +62,7 @@ void CCollision::Init(class CLayers *pLayers)
|
|||
}
|
||||
|
||||
// DDRace tiles
|
||||
if(Index >= 5 && Index<=191)
|
||||
if(Index >= 6 && Index<=TILE_NPH)
|
||||
m_pFront[i].m_Index = Index;
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ void CCollision::Init(class CLayers *pLayers)
|
|||
for(int i = 0; i < m_Width*m_Height; i++)
|
||||
{
|
||||
int Index = m_pTiles[i].m_Index;
|
||||
if(Index > 191)
|
||||
if(Index > TILE_NPH)
|
||||
continue;
|
||||
|
||||
switch(Index)
|
||||
|
@ -92,7 +92,7 @@ void CCollision::Init(class CLayers *pLayers)
|
|||
}
|
||||
|
||||
// DDRace tiles
|
||||
if(Index >= 5 && Index<=191)
|
||||
if(Index >= 6 && Index<=TILE_NPH)
|
||||
m_pTiles[i].m_Index = Index;
|
||||
}
|
||||
}
|
||||
|
@ -191,9 +191,7 @@ int CCollision::GetFTile(int x, int y)
|
|||
int nx = clamp(x/32, 0, m_Width-1);
|
||||
int ny = clamp(y/32, 0, m_Height-1);
|
||||
/*dbg_msg("GetFTile","m_Index %d",m_pFront[ny*m_Width+nx].m_Index);//Remove */
|
||||
if(m_pFront[ny*m_Width+nx].m_Index == COLFLAG_SOLID
|
||||
|| m_pFront[ny*m_Width+nx].m_Index == (COLFLAG_SOLID|COLFLAG_NOHOOK)
|
||||
|| m_pFront[ny*m_Width+nx].m_Index == COLFLAG_DEATH
|
||||
if(m_pFront[ny*m_Width+nx].m_Index == COLFLAG_DEATH
|
||||
|| m_pFront[ny*m_Width+nx].m_Index == COLFLAG_NOLASER)
|
||||
return m_pFront[ny*m_Width+nx].m_Index;
|
||||
else
|
||||
|
@ -265,14 +263,13 @@ int CCollision::IntersectLine(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *p
|
|||
vec2 Pos = mix(Pos0, Pos1, a);
|
||||
ix = round(Pos.x);
|
||||
iy = round(Pos.y);
|
||||
if((CheckPoint(ix, iy) || FCheckPoint(ix, iy)) && !(AllowThrough && IsThrough(ix + dx, iy + dy)))
|
||||
if(CheckPoint(ix, iy) && !(AllowThrough && IsThrough(ix + dx, iy + dy)))
|
||||
{
|
||||
if(pOutCollision)
|
||||
*pOutCollision = Pos;
|
||||
if(pOutBeforeCollision)
|
||||
*pOutBeforeCollision = Last;
|
||||
if (CheckPoint(ix, iy)) return GetCollisionAt(ix, iy);
|
||||
else return GetFCollisionAt(ix, iy);
|
||||
return GetCollisionAt(ix, iy);
|
||||
}
|
||||
Last = Pos;
|
||||
}
|
||||
|
@ -292,14 +289,14 @@ int CCollision::IntersectNoLaser(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2
|
|||
{
|
||||
float a = f/d;
|
||||
vec2 Pos = mix(Pos0, Pos1, a);
|
||||
if(IsSolid(round(Pos.x), round(Pos.y)) || IsFSolid(round(Pos.x), round(Pos.y)) || (IsNoLaser(round(Pos.x), round(Pos.y)) || IsFNoLaser(round(Pos.x), round(Pos.y))))
|
||||
if(IsSolid(round(Pos.x), round(Pos.y)) || (IsNoLaser(round(Pos.x), round(Pos.y)) || IsFNoLaser(round(Pos.x), round(Pos.y))))
|
||||
{
|
||||
if(pOutCollision)
|
||||
*pOutCollision = Pos;
|
||||
if(pOutBeforeCollision)
|
||||
*pOutBeforeCollision = Last;
|
||||
if (IsSolid(round(Pos.x), round(Pos.y)) || IsNoLaser(round(Pos.x), round(Pos.y))) return GetCollisionAt(Pos.x, Pos.y);
|
||||
else return GetFCollisionAt(Pos.x, Pos.y);
|
||||
if (IsFNoLaser(round(Pos.x), round(Pos.y))) return GetFCollisionAt(Pos.x, Pos.y);
|
||||
else return GetCollisionAt(Pos.x, Pos.y);
|
||||
|
||||
}
|
||||
Last = Pos;
|
||||
|
@ -376,10 +373,10 @@ void CCollision::MovePoint(vec2 *pInoutPos, vec2 *pInoutVel, float Elasticity, i
|
|||
|
||||
vec2 Pos = *pInoutPos;
|
||||
vec2 Vel = *pInoutVel;
|
||||
if(CheckPoint(Pos + Vel) || FCheckPoint(Pos + Vel))
|
||||
if(CheckPoint(Pos + Vel))
|
||||
{
|
||||
int Affected = 0;
|
||||
if(CheckPoint(Pos.x + Vel.x, Pos.y) || FCheckPoint(Pos.x + Vel.x, Pos.y))
|
||||
if(CheckPoint(Pos.x + Vel.x, Pos.y))
|
||||
{
|
||||
pInoutVel->x *= -Elasticity;
|
||||
if(pBounces)
|
||||
|
@ -387,7 +384,7 @@ void CCollision::MovePoint(vec2 *pInoutPos, vec2 *pInoutVel, float Elasticity, i
|
|||
Affected++;
|
||||
}
|
||||
|
||||
if(CheckPoint(Pos.x, Pos.y + Vel.y) || FCheckPoint(Pos.x, Pos.y + Vel.y))
|
||||
if(CheckPoint(Pos.x, Pos.y + Vel.y))
|
||||
{
|
||||
pInoutVel->y *= -Elasticity;
|
||||
if(pBounces)
|
||||
|
@ -468,13 +465,13 @@ void CCollision::MoveBox(vec2 *pInoutPos, vec2 *pInoutVel, vec2 Size, float Elas
|
|||
bool CCollision::TestBox(vec2 Pos, vec2 Size)
|
||||
{
|
||||
Size *= 0.5f;
|
||||
if(CheckPoint(Pos.x-Size.x, Pos.y-Size.y) || FCheckPoint(Pos.x-Size.x, Pos.y-Size.y))
|
||||
if(CheckPoint(Pos.x-Size.x, Pos.y-Size.y))
|
||||
return true;
|
||||
if(CheckPoint(Pos.x+Size.x, Pos.y-Size.y) || FCheckPoint(Pos.x+Size.x, Pos.y-Size.y))
|
||||
if(CheckPoint(Pos.x+Size.x, Pos.y-Size.y))
|
||||
return true;
|
||||
if(CheckPoint(Pos.x-Size.x, Pos.y+Size.y) || FCheckPoint(Pos.x-Size.x, Pos.y+Size.y))
|
||||
if(CheckPoint(Pos.x-Size.x, Pos.y+Size.y))
|
||||
return true;
|
||||
if(CheckPoint(Pos.x+Size.x, Pos.y+Size.y) || FCheckPoint(Pos.x+Size.x, Pos.y+Size.y))
|
||||
if(CheckPoint(Pos.x+Size.x, Pos.y+Size.y))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
@ -484,11 +481,6 @@ int CCollision::IsSolid(int x, int y)
|
|||
return (GetTile(x,y)&COLFLAG_SOLID);
|
||||
}
|
||||
|
||||
int CCollision::IsFSolid(int x, int y)
|
||||
{
|
||||
return (GetFTile(x,y)&COLFLAG_SOLID);
|
||||
}
|
||||
|
||||
int CCollision::IsThrough(int x, int y)
|
||||
{
|
||||
int nx = clamp(x/32, 0, m_Width-1);
|
||||
|
|
|
@ -27,8 +27,6 @@ public:
|
|||
void Init(class CLayers *pLayers);
|
||||
bool CheckPoint(float x, float y) { return IsSolid(round(x), round(y)); }
|
||||
bool CheckPoint(vec2 p) { return CheckPoint(p.x, p.y); }
|
||||
bool FCheckPoint(float x, float y) { return IsFSolid(round(x), round(y)); }
|
||||
bool FCheckPoint(vec2 p) { return FCheckPoint(p.x, p.y); }
|
||||
void SetCollisionAt(float x, float y, int flag);
|
||||
int GetCollisionAt(float x, float y) { return GetTile(round(x), round(y)); }
|
||||
int GetFCollisionAt(float x, float y) { return GetFTile(round(x), round(y)); }
|
||||
|
@ -55,7 +53,6 @@ public:
|
|||
void GetSpeedup(int x, int y, vec2 *Dir, int *Force);
|
||||
|
||||
int IsSolid(int x, int y);
|
||||
int IsFSolid(int x, int y);
|
||||
int IsThrough(int x, int y);
|
||||
int IsNoLaser(int x, int y);
|
||||
int IsFNoLaser(int x, int y);
|
||||
|
|
|
@ -712,7 +712,7 @@ void CLayerFront::BrushDraw(CLayer *pBrush, float wx, float wy)
|
|||
continue;
|
||||
|
||||
// dont allow tele in and out tiles... same with speedup tile in front
|
||||
if(m_pEditor->GetSelectedLayer(0) == m_pEditor->m_Map.m_pFrontLayer && (l->m_pTiles[y*l->m_Width+x].m_Index == TILE_TELEIN || l->m_pTiles[y*l->m_Width+x].m_Index == TILE_TELEOUT || l->m_pTiles[y*l->m_Width+x].m_Index == TILE_BOOST || l->m_pTiles[y*l->m_Width+x].m_Index == (ENTITY_TRIGGER + ENTITY_OFFSET)|| l->m_pTiles[y*l->m_Width+x].m_Index == (ENTITY_DOOR + ENTITY_OFFSET)))
|
||||
if(m_pEditor->GetSelectedLayer(0) == m_pEditor->m_Map.m_pFrontLayer && (l->m_pTiles[y*l->m_Width+x].m_Index == TILE_TELEIN || l->m_pTiles[y*l->m_Width+x].m_Index == TILE_TELEOUT || l->m_pTiles[y*l->m_Width+x].m_Index == TILE_BOOST || l->m_pTiles[y*l->m_Width+x].m_Index == (ENTITY_TRIGGER + ENTITY_OFFSET) || l->m_pTiles[y*l->m_Width+x].m_Index == (ENTITY_DOOR + ENTITY_OFFSET)) || l->m_pTiles[y*l->m_Width+x].m_Index == (TILE_SOLID) || l->m_pTiles[y*l->m_Width+x].m_Index == (TILE_NOHOOK))
|
||||
continue;
|
||||
m_pTiles[fy*m_Width+fx] = l->m_pTiles[y*l->m_Width+x];
|
||||
}
|
||||
|
|
|
@ -81,9 +81,9 @@ void CCharacterCore::Tick(bool UseInput)
|
|||
|
||||
// get ground state
|
||||
bool Grounded = false;
|
||||
if(m_pCollision->CheckPoint(m_Pos.x+PhysSize/2, m_Pos.y+PhysSize/2+5) || m_pCollision->FCheckPoint(m_Pos.x+PhysSize/2, m_Pos.y+PhysSize/2+5))
|
||||
if(m_pCollision->CheckPoint(m_Pos.x+PhysSize/2, m_Pos.y+PhysSize/2+5))
|
||||
Grounded = true;
|
||||
if(m_pCollision->CheckPoint(m_Pos.x-PhysSize/2, m_Pos.y+PhysSize/2+5) || m_pCollision->FCheckPoint(m_Pos.x-PhysSize/2, m_Pos.y+PhysSize/2+5))
|
||||
if(m_pCollision->CheckPoint(m_Pos.x-PhysSize/2, m_Pos.y+PhysSize/2+5))
|
||||
Grounded = true;
|
||||
|
||||
vec2 TargetDirection = normalize(vec2(m_Input.m_TargetX, m_Input.m_TargetY));
|
||||
|
|
|
@ -128,7 +128,7 @@ enum
|
|||
TILE_NPC,
|
||||
TILE_EHOOK,
|
||||
TILE_NOHIT,
|
||||
TILE_NPH,
|
||||
TILE_NPH,//Remeber to change this in collision.cpp if you add anymore tiles
|
||||
//End of higher tiles
|
||||
//Untouchable Elements
|
||||
TILEFLAG_VFLIP=1,
|
||||
|
|
|
@ -113,9 +113,9 @@ void CCharacter::SetWeapon(int W)
|
|||
|
||||
bool CCharacter::IsGrounded()
|
||||
{
|
||||
if(GameServer()->Collision()->CheckPoint(m_Pos.x+m_ProximityRadius/2, m_Pos.y+m_ProximityRadius/2+5) || GameServer()->Collision()->FCheckPoint(m_Pos.x+m_ProximityRadius/2, m_Pos.y+m_ProximityRadius/2+5))
|
||||
if(GameServer()->Collision()->CheckPoint(m_Pos.x+m_ProximityRadius/2, m_Pos.y+m_ProximityRadius/2+5))
|
||||
return true;
|
||||
if(GameServer()->Collision()->CheckPoint(m_Pos.x-m_ProximityRadius/2, m_Pos.y+m_ProximityRadius/2+5) || GameServer()->Collision()->FCheckPoint(m_Pos.x-m_ProximityRadius/2, m_Pos.y+m_ProximityRadius/2+5))
|
||||
if(GameServer()->Collision()->CheckPoint(m_Pos.x-m_ProximityRadius/2, m_Pos.y+m_ProximityRadius/2+5))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue