From 4dbd7f53b85fdd37ec47cd1877fa6c32ae770314 Mon Sep 17 00:00:00 2001 From: Daveo Date: Tue, 14 Aug 2001 19:19:13 +0000 Subject: [PATCH] --- source/level/layercollision.cpp | 64 ++++++++++++++++----------------- source/level/layercollision.h | 14 +++++--- 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/source/level/layercollision.cpp b/source/level/layercollision.cpp index f23225ea4..10b6b568b 100644 --- a/source/level/layercollision.cpp +++ b/source/level/layercollision.cpp @@ -76,32 +76,33 @@ void CLayerCollision::shutdown() /*****************************************************************************/ int CLayerCollision::getHeightFromGround(int _x,int _y,int _maxHeight) { - int mapX,mapY,xFraction,yFraction; - int distanceFromGround; - int colHeight; - int maxHeightToCheck; +int xFraction,yFraction; +int distanceFromGround; +int colHeight; +int maxHeightToCheck; +u8 *MapPtr,T; - mapX=_x>>4; -// mapY=(_y>>4)*MapWidth; - mapY=GetYPos(_y>>4); xFraction=_x&0x0f; yFraction=16-(_y&0x0f); + MapPtr=getMapPtr(_x,_y); distanceFromGround=0; - colHeight=s_collisionTable[((Map[mapX+mapY]&COLLISION_TILE_MASK)*16)+xFraction]; + T=*MapPtr; + colHeight=s_collisionTable[((T&COLLISION_TILE_MASK)*16)+xFraction]; if(colHeight) { // Inside a collision block.. find the nearest ground above this point maxHeightToCheck=-_maxHeight-16; // Need to check one block more incase we cross onto a new block while(colHeight==16) { - mapY-=MapWidth; + MapPtr-=MapWidth; distanceFromGround-=16; if(distanceFromGround<=maxHeightToCheck) { return -_maxHeight; } - colHeight=s_collisionTable[((Map[mapX+mapY]&COLLISION_TILE_MASK)*16)+xFraction]; + T=*MapPtr; + colHeight=s_collisionTable[((T&COLLISION_TILE_MASK)*16)+xFraction]; } distanceFromGround+=yFraction-colHeight; if(distanceFromGround<-_maxHeight)distanceFromGround=-_maxHeight; @@ -113,13 +114,14 @@ int CLayerCollision::getHeightFromGround(int _x,int _y,int _maxHeight) maxHeightToCheck=_maxHeight+16; // Need to check one block more incase we cross onto a new block while(colHeight==0) { - mapY+=MapWidth; + MapPtr+=MapWidth; distanceFromGround+=16; if(distanceFromGround>=maxHeightToCheck) { return _maxHeight; } - colHeight=s_collisionTable[((Map[mapX+mapY]&COLLISION_TILE_MASK)*16)+xFraction]; + T=*MapPtr; + colHeight=s_collisionTable[((T&COLLISION_TILE_MASK)*16)+xFraction]; } distanceFromGround+=yFraction-colHeight; if(distanceFromGround>_maxHeight)distanceFromGround=_maxHeight; @@ -131,20 +133,20 @@ int CLayerCollision::getHeightFromGround(int _x,int _y,int _maxHeight) /*****************************************************************************/ int CLayerCollision::getHeightFromGroundExcluding(int _x,int _y,int _exclusion,int _maxHeight=32) { - int mapX,mapY,xFraction,yFraction; - int distanceFromGround; - int colHeight; - int maxHeightToCheck; +int xFraction,yFraction; +int distanceFromGround; +int colHeight; +int maxHeightToCheck; +u8 *MapPtr,T; - mapX=_x>>4; -// mapY=(_y>>4)*MapWidth; - mapY=GetYPos(_y>>4); xFraction=_x&0x0f; yFraction=16-(_y&0x0f); + MapPtr=getMapPtr(_x,_y); distanceFromGround=0; - colHeight=s_collisionTable[((Map[mapX+mapY]&COLLISION_TILE_MASK)*16)+xFraction]; - if ( (Map[mapX+mapY] & COLLISION_TYPE_MASK) == _exclusion ) + T=*MapPtr; + colHeight=s_collisionTable[((T&COLLISION_TILE_MASK)*16)+xFraction]; + if ( (T & COLLISION_TYPE_MASK) == _exclusion ) { colHeight = 0; } @@ -154,14 +156,15 @@ int CLayerCollision::getHeightFromGroundExcluding(int _x,int _y,int _exclusion maxHeightToCheck=-_maxHeight-16; // Need to check one block more incase we cross onto a new block while(colHeight==16) { - mapY-=MapWidth; + MapPtr-=MapWidth; distanceFromGround-=16; if(distanceFromGround<=maxHeightToCheck) { return -_maxHeight; } - colHeight=s_collisionTable[((Map[mapX+mapY]&COLLISION_TILE_MASK)*16)+xFraction]; - if ( (Map[mapX+mapY] & COLLISION_TYPE_MASK) == _exclusion ) + T=*MapPtr; + colHeight=s_collisionTable[((T&COLLISION_TILE_MASK)*16)+xFraction]; + if ( (T & COLLISION_TYPE_MASK) == _exclusion ) { colHeight = 0; } @@ -176,14 +179,15 @@ int CLayerCollision::getHeightFromGroundExcluding(int _x,int _y,int _exclusion maxHeightToCheck=_maxHeight+16; // Need to check one block more incase we cross onto a new block while(colHeight==0) { - mapY+=MapWidth; + MapPtr+=MapWidth; distanceFromGround+=16; if(distanceFromGround>=maxHeightToCheck) { return _maxHeight; } - colHeight=s_collisionTable[((Map[mapX+mapY]&COLLISION_TILE_MASK)*16)+xFraction]; - if ( (Map[mapX+mapY] & COLLISION_TYPE_MASK) == _exclusion ) + T=*MapPtr; + colHeight=s_collisionTable[((T&COLLISION_TILE_MASK)*16)+xFraction]; + if ( (T & COLLISION_TYPE_MASK) == _exclusion ) { colHeight = 0; } @@ -265,12 +269,6 @@ int CLayerCollision::getHeightFromGroundCart(int _x,int _y,int _maxHeight) return distanceFromGround; } -/*****************************************************************************/ -int CLayerCollision::getHeightFromGroundAmmo(int _x,int _y,int _maxHeight) -{ - return( CLayerCollision::getHeightFromGroundExcluding( _x, _y, COLLISION_TYPE_FLAG_NORMAL, _maxHeight ) ); -} - /*****************************************************************************/ #ifdef __SHOW_COLLISION__ #include "gfx\prim.h" diff --git a/source/level/layercollision.h b/source/level/layercollision.h index 819583007..dd1348bae 100644 --- a/source/level/layercollision.h +++ b/source/level/layercollision.h @@ -33,24 +33,28 @@ virtual void shutdown(); int getHeightFromGroundExcluding(int _x,int _y,int _exclusion,int _maxHeight=32); int getHeightFromGroundNonSB(int _x,int _y,int _maxHeight=32) {return( CLayerCollision::getHeightFromGroundExcluding( _x, _y, COLLISION_TYPE_FLAG_SB_NOMOVE, _maxHeight ) );} int getHeightFromGroundCart(int _x,int _y,int _maxHeight=32); - int getHeightFromGroundAmmo(int _x,int _y,int _maxHeight=32); + int getHeightFromGroundAmmo(int _x,int _y,int _maxHeight=32) {return(CLayerCollision::getHeightFromGroundExcluding( _x, _y, COLLISION_TYPE_FLAG_NORMAL, _maxHeight ));} -inline u8 *getMapPtr(int _x,int _y) +inline u8 *getMapPtr(int X,int Y) { - int Ofs=(_x>>4)+GetYPos(_y>>4); + X>>=4; + Y>>=4; + ASSERT((Y>=0-COL_Y_OFS) && (Y>4)+((_y>>4)*MapWidth)]); } -inline int getCollisionBlock(int _x,int _y) +inline int getCollisionBlock(int X,int Y) { - u8 Col=*getMapPtr(_x,_y); + u8 Col=*getMapPtr(X,Y); return (Col); // return Map[(_x>>4)+((_y>>4)*MapWidth)]; } inline u8 Get(int X,int Y) { + ASSERT((Y>=0-COL_Y_OFS) && (Y