Skip to content

Commit 6e6fda1

Browse files
committed
-
1 parent c485256 commit 6e6fda1

5 files changed

Lines changed: 29 additions & 21 deletions

File tree

src/GameDefs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#define CAR_WHEEL_SIZE_W_PX 6
2828
#define CAR_WHEEL_SIZE_H_PX 12
2929

30+
#define GTA_CYCLES_PER_FRAME 24
31+
3032
// in original gta1 map height levels is counting from top to bottom -
3133
// 0 is highest and 5 is lowest level
3234
#define INVERT_MAP_LAYER(index) (MAP_LAYERS_COUNT - (index) - 1)
@@ -74,6 +76,8 @@ struct GameObjectStyle
7476
float mHeight = 0.0f;
7577
float mDepth = 0.0f;
7678

79+
int mLifeDuration = 0; // 0 for infinite, non-zero n for n animation cycles
80+
7781
SpriteAnimData mAnimationData; // optional
7882
};
7983

src/GameObjectsManager.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,16 @@ Decoration* GameObjectsManager::CreateDecoration(const glm::vec3& position, cxx:
155155
debug_assert(gGameMap.mStyleData.IsLoaded());
156156
debug_assert(desc);
157157
debug_assert(desc->mClassID == eGameObjectClass_Decoration);
158-
if (desc->mClassID == eGameObjectClass_Decoration)
159-
{
160-
GameObjectID objectID = GenerateUniqueID();
161158

162-
instance = mDecorationsPool.create(objectID, desc);
163-
debug_assert(instance);
159+
GameObjectID objectID = GenerateUniqueID();
164160

165-
mAllObjectsList.push_back(instance);
166-
// init
167-
instance->Spawn(position, heading);
168-
}
161+
instance = mDecorationsPool.create(objectID, desc);
162+
debug_assert(instance);
163+
164+
mAllObjectsList.push_back(instance);
165+
// init
166+
instance->Spawn(position, heading);
167+
instance->SetLifeDuration(desc->mLifeDuration);
169168
return instance;
170169
}
171170

src/SpriteManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ void SpriteManager::InitBlocksAnimations()
302302
{
303303
BlockAnimation animData;
304304
animData.mBlockIndex = cityStyle.GetBlockTextureLinearIndex((currAnim.mWhich == 0 ? eBlockType_Side : eBlockType_Lid), currAnim.mBlock);
305-
animData.mAnimDesc.mFramesPerSecond = (20.0f / currAnim.mSpeed);
305+
animData.mAnimDesc.mFramesPerSecond = (GTA_CYCLES_PER_FRAME * 1.0f) / currAnim.mSpeed;
306306
animData.mAnimDesc.mFramesCount = currAnim.mFrameCount + 1;
307307
animData.mAnimDesc.mFrames[0] = animData.mBlockIndex; // initial frame
308308
for (int iframe = 0; iframe < currAnim.mFrameCount; ++iframe)

src/StyleData.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,7 @@ bool StyleData::InitGameObjectsList()
10611061
{
10621062
GameObjectStyle& currObject = mGameObjects[icurr];
10631063
currObject.mGameObjectIndex = icurr;
1064+
currObject.mLifeDuration = 0;
10641065

10651066
ObjectRawData& objectRaw = mObjectsRaw[icurr];
10661067

@@ -1080,25 +1081,29 @@ bool StyleData::InitGameObjectsList()
10801081
int frameCount = 0;
10811082
cxx::json_get_attribute(currObjectNode, "frameCount", frameCount);
10821083

1083-
if (frameCount > 0)
1084-
{
1085-
int startSpriteIndex = GetSpriteIndex(eSpriteType_Object, objectRaw.mBaseSprite);
1086-
currObject.mAnimationData.Setup(startSpriteIndex, frameCount);
1087-
}
1088-
10891084
ParseObjectFlags(currObjectNode, "flags", currObject.mFlags);
10901085

1091-
// convert object dimensions pixels to meters
1092-
1093-
// todo:
1086+
int startSpriteIndex = GetSpriteIndex(eSpriteType_Object, objectRaw.mBaseSprite);
1087+
10941088
// as cds says,
10951089
// Animated objects are a special case. They cannot be involved in collisions and are there for graphical
10961090
// effect only. The same data structure is used, with the following differences :
10971091
// * height - stores the number of game cycles per frame
10981092
// * width - stores the number of frames
10991093
// * depth - stores a life descriptor ( 0 for infinite, non-zero n for n animation cycles )
1100-
if (currObject.mClassID != eGameObjectClass_Decoration)
1094+
if (objectRaw.mStatus == 5)
11011095
{
1096+
float fps = (GTA_CYCLES_PER_FRAME * 1.0f) / objectRaw.mHeight;
1097+
currObject.mAnimationData.Setup(startSpriteIndex, objectRaw.mWidth, fps);
1098+
currObject.mLifeDuration = objectRaw.mDepth;
1099+
}
1100+
else
1101+
{
1102+
if (frameCount > 0)
1103+
{
1104+
currObject.mAnimationData.Setup(startSpriteIndex, frameCount);
1105+
}
1106+
// convert object dimensions pixels to meters
11021107
currObject.mHeight = Convert::PixelsToMeters(objectRaw.mHeight);
11031108
currObject.mWidth = Convert::PixelsToMeters(objectRaw.mWidth);
11041109
currObject.mDepth = Convert::PixelsToMeters(objectRaw.mDepth);

src/TimeManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class TimeManager: public cxx::noncopyable
1515
float mUiFrameDelta = 0.0f;
1616
float mUiTimeScale = 1.0f;
1717

18-
float mMinFramerate = 25.0f; // gta1 game speed
18+
float mMinFramerate = 24.0f; // gta1 game speed
1919
float mMaxFramerate = 120.0f;
2020

2121
public:

0 commit comments

Comments
 (0)