Skip to content

Commit 3a6eeea

Browse files
committed
refactore in progress
1 parent dacb185 commit 3a6eeea

20 files changed

Lines changed: 278 additions & 232 deletions

src/CarnageGame.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ bool CarnageGame::Initialize()
2323

2424
SetInputActionsFromConfig();
2525

26-
gGameParams.LoadDefaults();
26+
gGameParams.SetToDefaults();
2727

2828
if (gSystem.mStartupParams.mDebugMapName.empty())
2929
{
@@ -342,8 +342,8 @@ bool CarnageGame::StartScenario(const std::string& mapName)
342342
currBlock->mGroundType == eGroundType_Pawement ||
343343
currBlock->mGroundType == eGroundType_Road)
344344
{
345-
pos[currFindPosIter].x += MAP_BLOCK_LENGTH * 0.5f;
346-
pos[currFindPosIter].z += MAP_BLOCK_LENGTH * 0.5f;
345+
pos[currFindPosIter].x += 0.5f;
346+
pos[currFindPosIter].z += 0.5f;
347347
pos[currFindPosIter].y = currHeight;
348348
++currFindPosIter;
349349
}

src/Convert.h

Lines changed: 81 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,94 @@
33
#include "GameDefs.h"
44
#include "PhysicsDefs.h"
55

6-
// convert fix16 angle to degrees
7-
inline float ConvertFixAngleToDegs(unsigned short ang16)
6+
class Convert
87
{
9-
return (ang16 / 1024.0f) * 360.0f - SPRITE_ZERO_ANGLE;
10-
}
8+
public:
9+
// Convert map units to meters
10+
static float MapUnitsToMeters(float units) { return (units * METERS_PER_MAP_UNIT); }
1111

12-
// convert pixels coordinate to map coordinate
13-
inline float ConvertPixelsToMap(int pixels)
14-
{
15-
return (1.0f * pixels) / MAP_PIXELS_PER_TILE;
16-
}
12+
// Convert meters to map units
13+
static float MetersToMapUnits(float units) { return (units / METERS_PER_MAP_UNIT); }
1714

18-
// convert map coordinate to pixels
19-
inline int ConvertMapToPixels(float coord)
20-
{
21-
return static_cast<int>(coord * MAP_PIXELS_PER_TILE);
22-
}
15+
// Convert map units to meters
16+
static glm::vec2 MapUnitsToMeters(const glm::vec2& units)
17+
{
18+
return {
19+
MapUnitsToMeters(units.x),
20+
MapUnitsToMeters(units.y)
21+
};
22+
}
23+
static glm::vec3 MapUnitsToMeters(const glm::vec3& units)
24+
{
25+
return {
26+
MapUnitsToMeters(units.x),
27+
MapUnitsToMeters(units.y),
28+
MapUnitsToMeters(units.z)
29+
};
30+
}
31+
// Convert meters to map units
32+
static glm::vec2 MetersToMapUnits(const glm::vec2& units)
33+
{
34+
return {
35+
MetersToMapUnits(units.x),
36+
MetersToMapUnits(units.y)
37+
};
38+
}
39+
static glm::vec3 MetersToMapUnits(const glm::vec3& units)
40+
{
41+
return {
42+
MetersToMapUnits(units.x),
43+
MetersToMapUnits(units.y),
44+
MetersToMapUnits(units.z)
45+
};
46+
}
2347

24-
// convert map coordinate to physics world coordinate
25-
inline float ConvertMapToPhysics(float coord)
26-
{
27-
return coord * PHYSICS_SCALE;
28-
}
48+
// Convert fix16 angle
49+
static cxx::angle_t Fix16ToAngle(unsigned short ang16)
50+
{
51+
return cxx::angle_t::from_degrees((ang16 / 1024.0f) * 360.0f - SPRITE_ZERO_ANGLE);
52+
}
2953

30-
// convert physics world coordinate to map coordinate
31-
inline float ConvertPhysicsToMap(float coord)
32-
{
33-
return coord / PHYSICS_SCALE;
34-
}
54+
// Convert pixels to map units
55+
static float PixelsToMapUnits(int pixels) { return (1.0f * pixels) / PIXELS_PER_MAP_UNIT; }
3556

36-
// convert pixels coordinate to block coordinate
37-
inline int ConvertPixelsToTilePos(int pixels)
38-
{
39-
return pixels / MAP_PIXELS_PER_TILE;
40-
}
57+
// Convert map units to pixels
58+
static int MapUnitsToPixels(float units) { return (int) (units * PIXELS_PER_MAP_UNIT); }
4159

42-
// convert block coordinate to pixels coorinate
43-
inline int ConvertTilePosToPixels(int tilePos)
44-
{
45-
return tilePos * MAP_PIXELS_PER_TILE;
46-
}
60+
// Convert pixels to map units
61+
static glm::vec2 PixelsToMapUnits(const glm::ivec2& pixels)
62+
{
63+
return {
64+
PixelsToMapUnits(pixels.x),
65+
PixelsToMapUnits(pixels.y)
66+
};
67+
}
68+
static glm::vec3 PixelsToMapUnits(const glm::ivec3& pixels)
69+
{
70+
return {
71+
PixelsToMapUnits(pixels.x),
72+
PixelsToMapUnits(pixels.y),
73+
PixelsToMapUnits(pixels.z)
74+
};
75+
}
76+
77+
// Convert map units to pixels
78+
static glm::ivec2 MapUnitsToPixels(const glm::vec2& units)
79+
{
80+
return {
81+
MapUnitsToPixels(units.x),
82+
MapUnitsToPixels(units.y)
83+
};
84+
}
85+
static glm::ivec3 MapUnitsToPixels(const glm::vec3& units)
86+
{
87+
return {
88+
MapUnitsToPixels(units.x),
89+
MapUnitsToPixels(units.y),
90+
MapUnitsToPixels(units.z)
91+
};
92+
}
93+
};
4794

4895
// in original gta1 map height levels is counting from top to bottom -
4996
// 0 is highest and 5 is lowest level

src/FreeLookCameraController.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,6 @@ void FreeLookCameraController::InputEvent(MouseScrollInputEvent& inputEvent)
143143
return;
144144

145145
glm::vec3 position = mCamera->mPosition;
146-
position.y = glm::max(position.y + (MAP_BLOCK_LENGTH * 0.5f * -inputEvent.mScrollY), MAP_LAYERS_COUNT * MAP_BLOCK_LENGTH);
146+
position.y = glm::max(position.y + (0.5f * -inputEvent.mScrollY), MAP_LAYERS_COUNT * 1.0f);
147147
mCamera->SetPosition(position);
148148
}

src/GameCheatsWindow.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ void GameCheatsWindow::CreateCarNearby(CarStyle* carStyle, Pedestrian* pedestria
173173
return;
174174

175175
glm::vec3 currPosition = pedestrian->mPhysicsComponent->GetPosition();
176-
currPosition.x += MAP_BLOCK_LENGTH * 0.5f;
177-
currPosition.z += MAP_BLOCK_LENGTH * 0.5f;
176+
currPosition.x += 0.5f;
177+
currPosition.z += 0.5f;
178178

179179
gGameObjectsManager.CreateCar(currPosition, cxx::angle_t::from_degrees(25.0f), carStyle);
180180
}

src/GameDefs.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// most of game constants is mapped to GTA files format so don't change
44

55
// side length of block cube, do not change
6-
#define MAP_BLOCK_LENGTH 1.0f
76
#define MAP_BLOCK_TEXTURE_DIMS 64
87
#define MAP_BLOCK_TEXTURE_AREA (MAP_BLOCK_TEXTURE_DIMS * MAP_BLOCK_TEXTURE_DIMS)
98
#define MAX_MAP_BLOCK_ANIM_FRAMES 32
@@ -15,10 +14,12 @@
1514
// map width and height is same
1615
#define MAP_DIMENSIONS 256
1716
#define MAP_LAYERS_COUNT 6
18-
#define MAP_PIXELS_PER_TILE MAP_BLOCK_TEXTURE_DIMS
17+
18+
#define PIXELS_PER_MAP_UNIT (MAP_BLOCK_TEXTURE_DIMS)
19+
#define METERS_PER_MAP_UNIT (4.0f)
1920

2021
#define SPRITE_ZERO_ANGLE 90.0f // all sprites in game are rotated at 90 degrees
21-
#define SPRITE_SCALE (1.0f / MAP_PIXELS_PER_TILE)
22+
#define SPRITE_SCALE (1.0f / PIXELS_PER_MAP_UNIT)
2223

2324
#define PED_SPRITE_DRAW_BOX_SIZE_PX 24 // with, height
2425
#define PED_SPRITE_DRAW_BOX_SIZE ((1.0f * PED_SPRITE_DRAW_BOX_SIZE_PX) / MAP_BLOCK_TEXTURE_DIMS)

0 commit comments

Comments
 (0)