Skip to content

Commit

Permalink
Merge pull request #391 from Ymihere03/spectate-freecam-mode
Browse files Browse the repository at this point in the history
New Spectator Camera mode: Free roam camera
  • Loading branch information
Ymihere03 authored Mar 13, 2024
2 parents 1243106 + 6dc6fdd commit 7133f34
Show file tree
Hide file tree
Showing 11 changed files with 361 additions and 15 deletions.
8 changes: 8 additions & 0 deletions Avara.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
948CBF152B335A1400147E80 /* BaseAssetStorage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 948CBF132B335A1400147E80 /* BaseAssetStorage.cpp */; };
94924EAF2B3A894900197378 /* OggFile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94924EAE2B3A894900197378 /* OggFile.cpp */; };
94924EB02B3A894900197378 /* OggFile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94924EAE2B3A894900197378 /* OggFile.cpp */; };
94EE531F2BA0AFCF00EE9056 /* CFreeCam.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94EE531D2BA0AFCF00EE9056 /* CFreeCam.cpp */; };
94EE53202BA0AFCF00EE9056 /* CFreeCam.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94EE531D2BA0AFCF00EE9056 /* CFreeCam.cpp */; };
94F17DDD29920D90001F5950 /* ARGBColor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94F17DDC29920D90001F5950 /* ARGBColor.cpp */; };
E20752EF2A003EC600DCC210 /* Tags.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E20752EE2A003EC600DCC210 /* Tags.cpp */; };
E20A3C562991CC72005741F7 /* KeyFuncs.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E20A3C552991CC72005741F7 /* KeyFuncs.cpp */; };
Expand Down Expand Up @@ -397,6 +399,8 @@
948CBF132B335A1400147E80 /* BaseAssetStorage.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = BaseAssetStorage.cpp; sourceTree = "<group>"; };
94924EAD2B3A893900197378 /* OggFile.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OggFile.h; sourceTree = "<group>"; };
94924EAE2B3A894900197378 /* OggFile.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = OggFile.cpp; sourceTree = "<group>"; };
94EE531D2BA0AFCF00EE9056 /* CFreeCam.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CFreeCam.cpp; sourceTree = "<group>"; };
94EE531E2BA0AFCF00EE9056 /* CFreeCam.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CFreeCam.h; sourceTree = "<group>"; };
94F17DDB2991FACE001F5950 /* ARGBColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ARGBColor.h; sourceTree = "<group>"; };
94F17DDC29920D90001F5950 /* ARGBColor.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ARGBColor.cpp; sourceTree = "<group>"; };
E20752ED29FF1EC500DCC210 /* Tags.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Tags.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1259,6 +1263,8 @@
E5890C2929895118007A875D /* CDoorActor.h */,
E5890BD829895118007A875D /* CForceField.cpp */,
E5890BDC29895118007A875D /* CForceField.h */,
94EE531D2BA0AFCF00EE9056 /* CFreeCam.cpp */,
94EE531E2BA0AFCF00EE9056 /* CFreeCam.h */,
E5890BD029895118007A875D /* CFreeSolid.cpp */,
E5890C4929895118007A875D /* CFreeSolid.h */,
E5890C2429895118007A875D /* CGlowActors.cpp */,
Expand Down Expand Up @@ -2100,6 +2106,7 @@
E517F06B299713DB0036B206 /* CAbstractYon.cpp in Sources */,
E517F06C299713DB0036B206 /* CAreaActor.cpp in Sources */,
E517F06D299713DB0036B206 /* CAvaraApp.cpp in Sources */,
94EE53202BA0AFCF00EE9056 /* CFreeCam.cpp in Sources */,
E517F06E299713DB0036B206 /* CAvaraGame.cpp in Sources */,
E517F06F299713DB0036B206 /* CBall.cpp in Sources */,
E517F070299713DB0036B206 /* CDepot.cpp in Sources */,
Expand Down Expand Up @@ -2270,6 +2277,7 @@
E5890CB229895118007A875D /* CommandManager.cpp in Sources */,
E5890CF629895118007A875D /* CGroundColorAdjuster.cpp in Sources */,
E5890CEA29895118007A875D /* CDepot.cpp in Sources */,
94EE531F2BA0AFCF00EE9056 /* CFreeCam.cpp in Sources */,
E5890EFF29895124007A875D /* theme.cpp in Sources */,
E5890F0229895124007A875D /* glutil.cpp in Sources */,
E5890F0529895124007A875D /* slider.cpp in Sources */,
Expand Down
58 changes: 58 additions & 0 deletions src/game/CAbstractPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "CPlayerManager.h"
#include "CPlayerMissile.h"
#include "CScout.h"
#include "CFreeCam.h"
#include "CSmartPart.h"
#include "CViewParameters.h"
//#include "CInfoPanel.h"
Expand Down Expand Up @@ -156,6 +157,7 @@ void CAbstractPlayer::StartSystems() {
scoutView = false;
scoutIdent = 0;
scoutBaseHeight = FIX3(2000);
freeCamIdent = 0;

sliverCounts[kSmallSliver] = 12;
sliverCounts[kMediumSliver] = 18;
Expand Down Expand Up @@ -190,6 +192,18 @@ void CAbstractPlayer::LoadScout() {
itsScout->EndScript();
}

void CAbstractPlayer::LoadFreeCam() {

itsFreeCam = new CFreeCam(this);
itsFreeCam->BeginScript();
FreshCalc();
itsFreeCam->EndScript();
}

void CAbstractPlayer::WriteDBG(int index, float val) {
freeCamDBG[index] = val;
}

void CAbstractPlayer::ReplacePartColors() {
teamMask = 1 << teamColor;
longTeamColor = GetTeamColorOr(ColorManager::getDefaultTeamColor());
Expand Down Expand Up @@ -276,6 +290,7 @@ CAbstractActor *CAbstractPlayer::EndScript() {
ReplacePartColors();
LoadHUDParts();
LoadScout();
LoadFreeCam();
PlaceParts();
LinkPartSpheres();

Expand Down Expand Up @@ -316,6 +331,15 @@ CAbstractPlayer::~CAbstractPlayer() {
scoutIdent = 0;
}

if (freeCamIdent) {
itsFreeCam = (CFreeCam *)gCurrentGame->FindIdent(freeCamIdent);
}

if (freeView) {
delete itsFreeCam;
freeCamIdent = 0;
}

gRenderer->RemoveHUDPart(dirArrow);
delete dirArrow;

Expand Down Expand Up @@ -963,6 +987,23 @@ void CAbstractPlayer::ResetDashboard() {
}
}

void CAbstractPlayer::ToggleFreeCam() {
freeView = !freeView;

itsGame->ToggleFreeCam(freeView);
itsFreeCam->ToggleState(freeView);

if (freeView) {
SDL_Log("Free cam toggled on!");
}
else
SDL_Log("Free cam toggled off!");
}

Boolean CAbstractPlayer::IsFreeCamAttached() {
return itsFreeCam->IsAttached();
}

void CAbstractPlayer::ControlSoundPoint() {
Fixed theRight[] = {FIX(-1), 0, 0};
Matrix *m;
Expand Down Expand Up @@ -991,6 +1032,11 @@ void CAbstractPlayer::ControlViewPoint() {
if (itsScout)
itsScout->ControlViewPoint();
}
} else if (freeView && freeCamIdent && itsManager->IsLocalPlayer()) {
itsFreeCam = (CFreeCam *)itsGame->FindIdent(freeCamIdent);
if (itsFreeCam) {
itsFreeCam->ControlViewPoint();
}
} else {
MATRIXCOPY(&vp->viewMatrix, viewPortPart->GetInverseTransform());
MTranslate(viewOffset[0], viewOffset[1], viewOffset[2], &vp->viewMatrix);
Expand Down Expand Up @@ -1258,9 +1304,21 @@ void CAbstractPlayer::KeyboardControl(FunctionTable *ft) {
else if(lives == 0) {
if (itsManager->IsLocalPlayer() && TESTFUNC(kfuSpectateNext, ft->down)) {
itsGame->SpectateNext();
if (freeView) {
itsFreeCam->SetAttached(true);
}
}
if (itsManager->IsLocalPlayer() && TESTFUNC(kfuSpectatePrevious, ft->down)) {
itsGame->SpectatePrevious();
if (freeView) {
itsFreeCam->SetAttached(true);
}
}
if (itsManager->IsLocalPlayer() && TESTFUNC(kfuToggleFreeCam, ft->down)) {
ToggleFreeCam();
}
if (freeView) {
itsFreeCam->ViewControl(ft);
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/game/CAbstractPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
class CBSPPart;
class CScaledBSP;
class CScout;
class CFreeCam;
class CPlayerManager;
class CIncarnator;
class CAbstractPlayer;
Expand Down Expand Up @@ -122,6 +123,7 @@ class CAbstractPlayer : public CRealMovers {
CSmartPart *viewPortPart = 0; // We look out from this one.
CScout *itsScout = 0; //
short scoutCommand = 0;
CFreeCam *itsFreeCam = 0;

// Control module (and view) orientation:
Fixed viewYaw = 0;
Expand Down Expand Up @@ -173,13 +175,17 @@ class CAbstractPlayer : public CRealMovers {

long scoutIdent = 0; // true, if scout is out.
Boolean scoutView = 0; // true = scout view, false = normal view
long freeCamIdent = 0;
Boolean freeView = 0;
Boolean isInLimbo = 0;
Boolean debugView = 0;
Boolean netDestruct = 0;

Fixed supportTraction = 0;
Fixed supportFriction = 0;

double freeCamDBG[18] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

// Hud parts:
CBSPPart *dirArrow = 0;
Fixed dirArrowHeight = 0;
Expand Down Expand Up @@ -246,6 +252,8 @@ class CAbstractPlayer : public CRealMovers {
virtual void SetSpecialColor(ARGBColor specialColor);
virtual void LoadParts();
virtual void LoadScout();
virtual void LoadFreeCam();
virtual void WriteDBG(int index, float val);
virtual void StartSystems();
virtual void LevelReset();

Expand Down Expand Up @@ -286,6 +294,8 @@ class CAbstractPlayer : public CRealMovers {
virtual void ResetDashboard();
//

virtual void ToggleFreeCam();
virtual Boolean IsFreeCamAttached();
virtual void ControlSoundPoint();
virtual void ControlViewPoint();
virtual void RecalculateViewDistance();
Expand Down
12 changes: 11 additions & 1 deletion src/game/CAvaraGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ void CAvaraGame::IAvaraGame(CAvaraApp *theApp) {
freshPlayerList = NULL;
playerList = NULL;
spectatePlayer = NULL;
freeCamState = 0;

soundSwitches = 0xFF;

Expand Down Expand Up @@ -915,9 +916,18 @@ bool CAvaraGame::GameTick() {
return true;
}

void CAvaraGame::ToggleFreeCam(Boolean state) {
freeCamState = state;
}

void CAvaraGame::ViewControl() {
if(spectatePlayer != NULL && FindPlayerManager(spectatePlayer) != NULL) {
FindPlayerManager(spectatePlayer)->ViewControl();
if (freeCamState) {
// The player has control of the camera when in free cam mode while spectating
itsNet->ViewControl();
} else {
FindPlayerManager(spectatePlayer)->ViewControl();
}
}
else {
itsNet->ViewControl();
Expand Down
3 changes: 3 additions & 0 deletions src/game/CAvaraGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class CAvaraGame {
short teamsStandingMask;
short teamsStanding;

Boolean freeCamState;

CIncarnator *incarnatorList;
CAbstractPlayer *freshPlayerList;

Expand Down Expand Up @@ -244,6 +246,7 @@ class CAvaraGame {
virtual void StopGame();
virtual void Render();
virtual void ViewControl();
virtual void ToggleFreeCam(Boolean state);

virtual void InitMixer(Boolean silentFlag);

Expand Down
Loading

0 comments on commit 7133f34

Please sign in to comment.