Skip to content

Commit f490a11

Browse files
committed
Merge branch 'refactoring_gameobjects'
2 parents 30febc3 + 8d38eb8 commit f490a11

72 files changed

Lines changed: 3939 additions & 2709 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

gamedata/entities/weapons.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
"projectile_hit_object_sfx": 43, // sound index
2020
"projectile_offset":
2121
[
22-
{ "anim": "shoot_pistol_while_standing", "px": [8, 2] },
23-
{ "anim": "shoot_pistol_while_walking", "px": [11, 0] },
24-
{ "anim": "shoot_pistol_while_running", "px": [11, 5] }
22+
{ "anim": "shoot_pistol_while_standing", "px": [8, -1] },
23+
{ "anim": "shoot_pistol_while_walking", "px": [11, -2] },
24+
{ "anim": "shoot_pistol_while_running", "px": [11, 2] }
2525
],
2626
// base params
2727
"base_hit_range": 4.5,
@@ -44,9 +44,9 @@
4444
"projectile_hit_object_sfx": 43, // sound index
4545
"projectile_offset":
4646
[
47-
{ "anim": "shoot_machinegun_while_standing", "px": [6, 3] },
48-
{ "anim": "shoot_machinegun_while_walking", "px": [10, 3] },
49-
{ "anim": "shoot_machinegun_while_running", "px": [11, 7] }
47+
{ "anim": "shoot_machinegun_while_standing", "px": [6, 0] },
48+
{ "anim": "shoot_machinegun_while_walking", "px": [8, 0] },
49+
{ "anim": "shoot_machinegun_while_running", "px": [12, 4] }
5050
],
5151
// base params
5252
"base_hit_range": 4.5,
@@ -68,9 +68,9 @@
6868
"projectile_object": 75,
6969
"projectile_offset":
7070
[
71-
{ "anim": "shoot_flamethrower_while_standing", "px": [16, 3] },
72-
{ "anim": "shoot_flamethrower_while_walking", "px": [16, 3] },
73-
{ "anim": "shoot_flamethrower_while_running", "px": [18, 6] }
71+
{ "anim": "shoot_flamethrower_while_standing", "px": [18, 2] },
72+
{ "anim": "shoot_flamethrower_while_walking", "px": [18, 2] },
73+
{ "anim": "shoot_flamethrower_while_running", "px": [20, 5] }
7474
],
7575
// base params
7676
"base_hit_range": 1.1,

src/AiCharacterController.cpp

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "stdafx.h"
22
#include "AiCharacterController.h"
33
#include "Pedestrian.h"
4-
#include "PhysicsComponents.h"
4+
#include "PhysicsBody.h"
55
#include "CarnageGame.h"
66
#include "DebugRenderer.h"
77
#include "BroadcastEventsManager.h"
@@ -115,7 +115,7 @@ void AiCharacterController::DebugDraw(DebugRenderer& debugRender)
115115
if (mAiMode == ePedestrianAiMode_None || mAiMode == ePedestrianAiMode_Disabled)
116116
return;
117117

118-
glm::vec3 currpos = mCharacter->mPhysicsBody->GetPosition();
118+
glm::vec3 currpos = mCharacter->mTransform.mPosition;
119119
glm::vec3 destpos (mDestinationPoint.x, currpos.y, mDestinationPoint.y);
120120

121121
debugRender.DrawLine(currpos, destpos, Color32_Red, false);
@@ -137,9 +137,10 @@ bool AiCharacterController::ScanForExplosions()
137137
float reactionDistance2 = glm::pow(gGameParams.mAiReactOnExplosionsDistance, 2.0f);
138138

139139
BroadcastEvent eventData;
140-
if (gBroadcastEvents.PeekClosestEvent(eBroadcastEvent_Explosion, mCharacter->GetPosition2(), eventData))
140+
glm::vec2 position2 = mCharacter->mTransform.GetPosition2();
141+
if (gBroadcastEvents.PeekClosestEvent(eBroadcastEvent_Explosion, position2, eventData))
141142
{
142-
if (glm::distance2(eventData.mPosition, mCharacter->GetPosition2()) > reactionDistance2) // too far away
143+
if (glm::distance2(eventData.mPosition, position2) > reactionDistance2) // too far away
143144
return false;
144145

145146
return true;
@@ -152,12 +153,13 @@ bool AiCharacterController::ScanForGunshots()
152153
float reactionDistance2 = glm::pow(gGameParams.mAiReactOnGunshotsDistance, 2.0f);
153154

154155
BroadcastEvent eventData;
155-
if (gBroadcastEvents.PeekClosestEvent(eBroadcastEvent_GunShot, mCharacter->GetPosition2(), eventData))
156+
glm::vec2 position2 = mCharacter->mTransform.GetPosition2();
157+
if (gBroadcastEvents.PeekClosestEvent(eBroadcastEvent_GunShot, position2, eventData))
156158
{
157159
if (eventData.mCharacter == mCharacter) // hear own gunshots
158160
return false;
159161

160-
if (glm::distance2(eventData.mPosition, mCharacter->GetPosition2()) > reactionDistance2) // too far away
162+
if (glm::distance2(eventData.mPosition, position2) > reactionDistance2) // too far away
161163
return false;
162164

163165
return true;
@@ -249,7 +251,7 @@ void AiCharacterController::UpdateWandering()
249251
if (ContinueWalkToWaypoint(mDefaultNearDistance))
250252
return;
251253

252-
bool canFollowHuman = HasAiFlags(ePedestrianAiFlags_FollowHumanCharacter);
254+
bool canFollowHuman = HasAiFlags(PedestrianAiFlags_FollowHumanCharacter);
253255
if (canFollowHuman)
254256
{
255257
if (TryFollowHumanCharacterNearby())
@@ -290,7 +292,7 @@ void AiCharacterController::StartWandering()
290292

291293
bool AiCharacterController::ChooseWalkWaypoint(bool isPanic)
292294
{
293-
cxx::angle_t currHeading = mCharacter->mPhysicsBody->GetRotationAngle();
295+
cxx::angle_t currHeading = mCharacter->mTransform.mOrientation;
294296

295297
// choose new block ir next order: forward, left, right, backward
296298
eMapDirection currentMapDirection = GetMapDirectionFromHeading(currHeading.mDegrees);
@@ -302,7 +304,7 @@ bool AiCharacterController::ChooseWalkWaypoint(bool isPanic)
302304
GetMapDirectionOpposite(currentMapDirection)
303305
};
304306

305-
glm::ivec3 currentLogPos = Convert::MetersToMapUnits(mCharacter->GetPosition());
307+
glm::ivec3 currentLogPos = Convert::MetersToMapUnits(mCharacter->mTransform.mPosition);
306308
glm::ivec3 newWayPoint (0, 0, 0);
307309
for (eMapDirection curr: moveDirs)
308310
{
@@ -325,7 +327,7 @@ bool AiCharacterController::ChooseWalkWaypoint(bool isPanic)
325327
break;
326328
}
327329

328-
bool canSuicide = HasAiFlags(ePedestrianAiFlags_LemmingBehavior);
330+
bool canSuicide = HasAiFlags(PedestrianAiFlags_LemmingBehavior);
329331
if (canSuicide && (groundType == eGroundType_Air))
330332
{
331333
newWayPoint = moveBlockPos;
@@ -352,17 +354,16 @@ bool AiCharacterController::ContinueWalkToWaypoint(float distance)
352354
{
353355
float tolerance2 = pow(gGameParams.mPedestrianBoundsSphereRadius, 2.0f);
354356

355-
glm::vec2 currentPosition = mCharacter->mPhysicsBody->GetPosition2();
356-
if (glm::distance2(currentPosition, mDestinationPoint) <= tolerance2)
357+
glm::vec2 currentPos2 = mCharacter->mTransform.GetPosition2();
358+
if (glm::distance2(currentPos2, mDestinationPoint) <= tolerance2)
357359
{
358360
mCharacter->mCtlState.Clear();
359361
return false;
360362
}
361363

362364
// setup sign direction
363-
glm::vec2 currentPos2 = mCharacter->mPhysicsBody->GetPosition2();
364365
glm::vec2 toTarget = glm::normalize(mDestinationPoint - currentPos2);
365-
mCharacter->mPhysicsBody->SetOrientation2(toTarget);
366+
mCharacter->SetOrientation(toTarget);
366367

367368
// set control
368369
mCharacter->mCtlState.mWalkForward = true;
@@ -389,7 +390,7 @@ void AiCharacterController::StopDriving()
389390

390391
mCharacter->mCtlState.Clear();
391392

392-
float currentSpeed = mCharacter->mCurrentCar->mPhysicsBody->GetCurrentSpeed();
393+
float currentSpeed = mCharacter->mCurrentCar->GetCurrentSpeed();
393394
if (currentSpeed > gGameParams.mCarSpeedPassengerCanEnter)
394395
{
395396
mCharacter->mCtlState.mAcceleration = -1.0f;
@@ -460,7 +461,7 @@ void AiCharacterController::StartFollowTarget()
460461
mCharacter->mCtlState.Clear();
461462
mAiMode = ePedestrianAiMode_FollowTarget;
462463

463-
mDestinationPoint = mFollowPedestrian->mPhysicsBody->GetPosition2();
464+
mDestinationPoint = mFollowPedestrian->mTransform.GetPosition2();
464465
}
465466

466467
void AiCharacterController::UpdateFollowTarget()
@@ -480,8 +481,8 @@ void AiCharacterController::UpdateFollowTarget()
480481
if (ContinueWalkToWaypoint(mFollowNearDistance))
481482
return;
482483

483-
glm::vec2 characterPosition2 = mCharacter->mPhysicsBody->GetPosition2();
484-
glm::vec2 targetPosition2 = mFollowPedestrian->mPhysicsBody->GetPosition2();
484+
glm::vec2 characterPosition2 = mCharacter->mTransform.GetPosition2();
485+
glm::vec2 targetPosition2 = mFollowPedestrian->mTransform.GetPosition2();
485486

486487
float distanceToTarget2 = glm::distance2(characterPosition2, targetPosition2);
487488
if (distanceToTarget2 < glm::pow(mFollowNearDistance, 2.0f))
@@ -495,17 +496,17 @@ void AiCharacterController::UpdateFollowTarget()
495496
ContinueWalkToWaypoint(mFollowNearDistance);
496497
}
497498

498-
void AiCharacterController::EnableAiFlags(ePedestrianAiFlags aiFlags)
499+
void AiCharacterController::EnableAiFlags(PedestrianAiFlags aiFlags)
499500
{
500501
mAiFlags = (mAiFlags | aiFlags);
501502
}
502503

503-
void AiCharacterController::DisableAiFlags(ePedestrianAiFlags aiFlags)
504+
void AiCharacterController::DisableAiFlags(PedestrianAiFlags aiFlags)
504505
{
505506
mAiFlags = (mAiFlags & ~aiFlags);
506507
}
507508

508-
bool AiCharacterController::HasAiFlags(ePedestrianAiFlags aiFlags) const
509+
bool AiCharacterController::HasAiFlags(PedestrianAiFlags aiFlags) const
509510
{
510511
return (mAiFlags & aiFlags) == aiFlags;
511512
}
@@ -524,7 +525,7 @@ bool AiCharacterController::TryFollowHumanCharacterNearby()
524525
if (!currentPlayer->mCharacter->IsStanding())
525526
continue;
526527

527-
float currDistance2 = glm::distance2(currentPlayer->mCharacter->GetPosition2(), mCharacter->GetPosition2());
528+
float currDistance2 = glm::distance2(currentPlayer->mCharacter->mTransform.GetPosition2(), mCharacter->mTransform.GetPosition2());
528529
if (currDistance2 > bestDistance2)
529530
continue;
530531

src/AiCharacterController.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ enum ePedestrianAiState
2020
ePedestrianAiState_WalkToLocation,
2121
};
2222

23-
enum ePedestrianAiFlags
23+
enum PedestrianAiFlags
2424
{
25-
ePedestrianAiFlags_None = 0,
25+
PedestrianAiFlags_None = 0,
2626

27-
ePedestrianAiFlags_LemmingBehavior = BIT(0), // can suicide
28-
ePedestrianAiFlags_FollowHumanCharacter = BIT(1),
27+
PedestrianAiFlags_LemmingBehavior = BIT(0), // can suicide
28+
PedestrianAiFlags_FollowHumanCharacter = BIT(1),
2929
};
30-
decl_enum_as_flags(ePedestrianAiFlags);
30+
decl_enum_as_flags(PedestrianAiFlags);
3131

3232
// defines ai character controller
3333
class AiCharacterController final: public CharacterController
@@ -39,9 +39,9 @@ class AiCharacterController final: public CharacterController
3939
void UpdateFrame() override;
4040
void DebugDraw(DebugRenderer& debugRender) override;
4141

42-
void EnableAiFlags(ePedestrianAiFlags aiFlags);
43-
void DisableAiFlags(ePedestrianAiFlags aiFlags);
44-
bool HasAiFlags(ePedestrianAiFlags aiFlags) const;
42+
void EnableAiFlags(PedestrianAiFlags aiFlags);
43+
void DisableAiFlags(PedestrianAiFlags aiFlags);
44+
bool HasAiFlags(PedestrianAiFlags aiFlags) const;
4545

4646
// objectives
4747
void FollowPedestrian(Pedestrian* pedestrian);
@@ -80,7 +80,7 @@ class AiCharacterController final: public CharacterController
8080
glm::vec2 mDestinationPoint;
8181
float mDefaultNearDistance;
8282

83-
ePedestrianAiFlags mAiFlags = ePedestrianAiFlags_None;
83+
PedestrianAiFlags mAiFlags = PedestrianAiFlags_None;
8484

8585
PedestrianHandle mFollowPedestrian;
8686
float mFollowNearDistance;

src/AudioManager.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,16 +191,16 @@ void AudioManager::ResumeAllSounds()
191191
}
192192
}
193193

194-
SfxSample* AudioManager::GetSound(eSfxType sfxType, SfxIndex sfxIndex)
194+
SfxSample* AudioManager::GetSound(eSfxSampleType sfxType, SfxSampleIndex sfxIndex)
195195
{
196-
AudioSampleArchive& sampleArchive = (sfxType == eSfxType_Level) ? mLevelSounds : mVoiceSounds;
196+
AudioSampleArchive& sampleArchive = (sfxType == eSfxSampleType_Level) ? mLevelSounds : mVoiceSounds;
197197
if ((int) sfxIndex >= sampleArchive.GetEntriesCount())
198198
{
199199
debug_assert(false);
200200
return nullptr;
201201
}
202202

203-
std::vector<SfxSample*>& samples = (sfxType == eSfxType_Level) ?
203+
std::vector<SfxSample*>& samples = (sfxType == eSfxSampleType_Level) ?
204204
mLevelSfxSamples :
205205
mVoiceSfxSamples;
206206

@@ -286,7 +286,7 @@ void AudioManager::UpdateActiveEmitters()
286286
{
287287
if (currEmitter->mGameObject) // sync audio params
288288
{
289-
glm::vec3 gameObjectPosition = currEmitter->mGameObject->GetPosition();
289+
glm::vec3 gameObjectPosition = currEmitter->mGameObject->mTransform.mPosition;
290290
currEmitter->UpdateEmitterParams(gameObjectPosition);
291291
}
292292

@@ -307,7 +307,7 @@ void AudioManager::UpdateActiveEmitters()
307307
}
308308
}
309309

310-
bool AudioManager::StartSound(eSfxType sfxType, SfxIndex sfxIndex, SfxFlags sfxFlags, const glm::vec3& emitterPosition)
310+
bool AudioManager::StartSound(eSfxSampleType sfxType, SfxSampleIndex sfxIndex, SfxFlags sfxFlags, const glm::vec3& emitterPosition)
311311
{
312312
SfxSample* audioSample = GetSound(sfxType, sfxIndex);
313313
if (audioSample == nullptr)

src/AudioManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ class AudioManager final: public cxx::noncopyable
2323
// Simple play one shot sound within world
2424
// @param sfxType, sfxIndex: Sound identifier
2525
// @param emitterPosition: Sound position
26-
bool StartSound(eSfxType sfxType, SfxIndex sfxIndex, SfxFlags sfxFlags, const glm::vec3& emitterPosition);
26+
bool StartSound(eSfxSampleType sfxType, SfxSampleIndex sfxIndex, SfxFlags sfxFlags, const glm::vec3& emitterPosition);
2727

2828
// Get game sound by its identifier, will load audio data if it is not loaded yet
2929
// @param sfxType: Sound type
3030
// @param sfxIndex: Sound index
31-
SfxSample* GetSound(eSfxType sfxType, SfxIndex sfxIndex);
31+
SfxSample* GetSound(eSfxSampleType sfxType, SfxSampleIndex sfxIndex);
3232

3333
// Allocate new sound emitter instance
3434
// @param gameObject: Game object which emitting sounds, optional

src/Box2D_Helpers.h

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,52 @@
11
#pragma once
22

3-
namespace box2d
3+
#include "GameObject.h"
4+
#include "PhysicsBody.h"
5+
#include "Collider.h"
6+
7+
// b2Vec <- -> glm::vec2 conversion
8+
9+
//////////////////////////////////////////////////////////////////////////
10+
11+
inline glm::vec2 convert_vec2(const b2Vec2& vector_value)
12+
{
13+
return { vector_value.x, vector_value.y };
14+
}
15+
16+
inline b2Vec2 convert_vec2(const glm::vec2& vector_value)
17+
{
18+
return { vector_value.x, vector_value.y };
19+
}
20+
21+
//////////////////////////////////////////////////////////////////////////
22+
23+
inline Collider* b2Fixture_get_collider(b2Fixture* fixture)
424
{
5-
// simple wrapper for seamlessly cast between math libraries
6-
struct vec2: public b2Vec2
25+
debug_assert(fixture);
26+
Collider* collisionShape = (Collider*) fixture->GetUserData();
27+
28+
return collisionShape;
29+
}
30+
31+
inline PhysicsBody* b2Fixture_get_physics_body(b2Fixture* fixture)
32+
{
33+
debug_assert(fixture);
34+
35+
PhysicsBody* physicsBoxy = (PhysicsBody*) fixture->GetBody()->GetUserData();
36+
return physicsBoxy;
37+
}
38+
39+
inline GameObject* b2Fixture_get_game_object(b2Fixture* fixture)
40+
{
41+
debug_assert(fixture);
42+
43+
PhysicsBody* physicsBoxy = (PhysicsBody*) fixture->GetBody()->GetUserData();
44+
GameObject* gameObject = nullptr;
45+
if (physicsBoxy)
746
{
8-
public:
9-
vec2() = default;
10-
vec2(float xIn, float yIn): b2Vec2(xIn, yIn)
11-
{
12-
}
13-
template<typename TVec2>
14-
vec2(const TVec2& in_vec2): b2Vec2(in_vec2.x, in_vec2.y)
15-
{
16-
}
17-
template<typename TVec2>
18-
inline vec2& operator = (const TVec2& in_vec2)
19-
{
20-
x = in_vec2.x;
21-
y = in_vec2.y;
22-
return *this;
23-
}
24-
inline operator glm::vec2 () const
25-
{
26-
return {x, y};
27-
}
28-
inline vec2 operator * (float scalar) const
29-
{
30-
return {x * scalar, y * scalar};
31-
}
32-
};
33-
34-
// vectors
35-
static const vec2 NullVector { 0.0f, 0.0f };
36-
static const vec2 ForwardVector (1.0f, 0.0f);
37-
static const vec2 LateralVector (0.0f, 1.0f);
38-
39-
} // namespace box2d
47+
gameObject = physicsBoxy->mGameObject;
48+
}
49+
return gameObject;
50+
}
51+
52+
//////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)