Skip to content

Commit 995c96a

Browse files
committed
-
1 parent 105a2b5 commit 995c96a

6 files changed

Lines changed: 22 additions & 25 deletions

File tree

src/Convert.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,3 @@ class Convert
137137
};
138138
}
139139
};
140-
141-
// in original gta1 map height levels is counting from top to bottom -
142-
// 0 is highest and 5 is lowest level
143-
inline int ConvertMapLevel(int tileLayer)
144-
{
145-
tileLayer = MAP_LAYERS_COUNT - tileLayer - 1;
146-
debug_assert(tileLayer > -1 && tileLayer < MAP_LAYERS_COUNT);
147-
148-
return tileLayer;
149-
}

src/GameDefs.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121

2222
#define SPRITE_ZERO_ANGLE 90.0f // all sprites in game are rotated at 90 degrees
2323
#define SPRITE_SCALE (METERS_PER_MAP_UNIT / PIXELS_PER_MAP_UNIT)
24-
2524
#define PED_SPRITE_DRAW_BOX_SIZE_PX 24 // with, height
26-
#define PED_SPRITE_DRAW_BOX_SIZE ((1.0f * PED_SPRITE_DRAW_BOX_SIZE_PX) / MAP_BLOCK_TEXTURE_DIMS)
25+
26+
// in original gta1 map height levels is counting from top to bottom -
27+
// 0 is highest and 5 is lowest level
28+
#define INVERT_MAP_LAYER(index) (MAP_LAYERS_COUNT - (index) - 1)
2729

2830
#define GAME_MAX_PLAYERS 4
2931

src/GameMapManager.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,11 @@ void GameMapManager::FixShiftedBits()
225225
float GameMapManager::GetHeightAtPosition(const glm::vec3& position, bool excludeWater) const
226226
{
227227
// get map block position in which we are located
228-
glm::ivec3 mapBlock = Convert::MetersToMapUnits(position);
229-
228+
glm::ivec3 mapBlock {
229+
Convert::MetersToMapUnits(position.x),
230+
Convert::MetersToMapUnits(position.y) + 0.5f,
231+
Convert::MetersToMapUnits(position.z)
232+
};
230233
float currentHeight = (float) mapBlock.y; // set current height to ground, map units
231234
for (; currentHeight > 0.0f;)
232235
{

src/GameObjectsManager.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,13 @@ bool GameObjectsManager::CreateStartupObjects()
248248
debug_assert(false);
249249
continue;
250250
}
251-
int mapBlock = (int) Convert::PixelsToMapUnits(currObject.mZ);
252-
int mapLevel = ConvertMapLevel(mapBlock);
251+
int mapLevel = (int) Convert::PixelsToMapUnits(currObject.mZ);
252+
mapLevel = INVERT_MAP_LAYER(mapLevel);
253253
glm::vec3 carPosition
254254
{
255-
Convert::PixelsToMapUnits(currObject.mX),
256-
mapLevel * 1.0f,
257-
Convert::PixelsToMapUnits(currObject.mY)
255+
Convert::PixelsToMeters(currObject.mX),
256+
Convert::MapUnitsToMeters(mapLevel * 1.0f),
257+
Convert::PixelsToMeters(currObject.mY)
258258
};
259259

260260
cxx::angle_t rotationDegrees = Convert::Fix16ToAngle(currObject.mRotation);

src/Pedestrian.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void Pedestrian::ComputeDrawHeight(const glm::vec3& position)
144144
float maxHeight = position.y;
145145
if (!mPhysicsComponent->mFalling)
146146
{
147-
float halfBox = PED_SPRITE_DRAW_BOX_SIZE * 0.5f;
147+
float halfBox = Convert::PixelsToMeters(PED_SPRITE_DRAW_BOX_SIZE_PX) * 0.5f;
148148
//glm::vec3 points[4] = {
149149
// { 0.0f, position.y + 0.01f, -halfBox },
150150
// { halfBox, position.y + 0.01f, 0.0f },

src/PhysicsManager.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ void PhysicsManager::PreSolve(b2Contact* contact, const b2Manifold* oldManifold)
325325
b2FixtureData_map fxdata = fixtureMapSolidBlock->GetUserData();
326326
PhysicsComponent* physicsObject = (PhysicsComponent*) fixturePed->GetBody()->GetUserData();
327327
debug_assert(physicsObject);
328+
328329
// detect height
329330
float height = gGameMap.GetHeightAtPosition(physicsObject->GetPosition());
330331
hasCollision = HasCollisionPedestrianVsMap(fxdata.mX, fxdata.mZ, height);
@@ -406,7 +407,7 @@ void PhysicsManager::FixedStepGravity()
406407
// process fall
407408
float newHeight = gGameMap.GetHeightAtPosition(position, false);
408409

409-
bool onTheGround = newHeight > (position.y - 0.01f);
410+
bool onTheGround = newHeight > (position.y - 0.00f);
410411
if (physicsComponent->mFalling)
411412
{
412413
if (onTheGround)
@@ -452,23 +453,24 @@ bool PhysicsManager::CollidePedVsPed(b2Contact* contact, PedPhysicsComponent* pe
452453

453454
bool PhysicsManager::HasCollisionPedestrianVsMap(int mapx, int mapz, float height) const
454455
{
455-
int map_layer = (int) (height + 0.5f);
456+
int mapLayer = (int) (Convert::MetersToMapUnits(height) + 0.5f);
456457

457458
// todo: temporary implementation
458459

459-
BlockStyle* blockData = gGameMap.GetBlockClamp(mapx, mapz, map_layer);
460+
BlockStyle* blockData = gGameMap.GetBlockClamp(mapx, mapz, mapLayer);
460461
return (blockData->mGroundType == eGroundType_Building);
461462
}
462463

463464
bool PhysicsManager::HasCollisionCarVsMap(b2Contact* contact, b2Fixture* fixtureCar, int mapx, int mapz) const
464465
{
465466
CarPhysicsComponent* carPhysicsComponent = (CarPhysicsComponent*) fixtureCar->GetBody()->GetUserData();
466467
debug_assert(carPhysicsComponent);
467-
int map_layer = (int) (carPhysicsComponent->mHeight + 0.5f);
468+
469+
int mapLayer = (int) (Convert::MetersToMapUnits(carPhysicsComponent->mHeight) + 0.5f);
468470

469471
// todo: temporary implementation
470472

471-
BlockStyle* blockData = gGameMap.GetBlockClamp(mapx, mapz, map_layer);
473+
BlockStyle* blockData = gGameMap.GetBlockClamp(mapx, mapz, mapLayer);
472474
return (blockData->mGroundType == eGroundType_Building);
473475
}
474476

0 commit comments

Comments
 (0)