Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legacy opengl renderer #420

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ed3fa2e
legacy single buffer renderer for speed freaks
assertivist Jun 21, 2024
b4bd6fc
kill some spectator frags
tra Jun 21, 2024
ee26fdd
output an estimate of CPU usage with `/dbg cpu`
tra Jun 21, 2024
f95ca3e
more frag fixes
tra Jun 22, 2024
2534cb7
local variable scope bug, oops
tra Jun 24, 2024
0bf4dbb
default Goody angle to zero
tra Jun 25, 2024
ba57a49
/dbg frag
tra Jun 25, 2024
10e900e
fixed koth field
tra Jun 26, 2024
3b002ea
try taking the hill logo out of the equation
tra Jun 26, 2024
b69e339
reverting last change for further build/testing
tra Jun 26, 2024
0cbe0bd
output dbg as BSPs are loaded
tra Jun 27, 2024
9af88b0
added attribute to Hologram
tra Jun 27, 2024
2be0190
fixed RayTest calls to use the fps ray distances
tra Jul 2, 2024
a6a45fc
backout changes to missile
tra Jul 3, 2024
75f1ede
make FramesFromNow() accept a float arg
tra Jul 3, 2024
ceca44e
consistent grenade/missile/plasma shooting rates (#417)
tra Jul 10, 2024
c54dc28
fix level-loading crashes
tra Aug 9, 2024
1f26642
fixed compiler warnings introduced by previous fix
tra Aug 9, 2024
4193ac2
Add function to allow the FrameBuffer to be updated on the fly
Ymihere03 Aug 13, 2024
d3d5fc5
Remove comment lines
Ymihere03 Aug 13, 2024
1711742
Refactored window resize handling to prevent memory leaks when updati…
Ymihere03 Aug 13, 2024
6aca440
Fix test class
Ymihere03 Aug 13, 2024
7ce62d7
Fix test class
Ymihere03 Aug 13, 2024
1a54b4a
merge with update to render api from fix for window resizing
assertivist Aug 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Avara.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
6025AE4E2C255E6A00A57EFB /* LegacyOpenGLRenderer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 60C274E22C23EBE9005B67A9 /* LegacyOpenGLRenderer.cpp */; };
940541ED2B5875B200E32241 /* OpenGLShader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 940541EC2B5875B200E32241 /* OpenGLShader.cpp */; };
940541EE2B5875B200E32241 /* OpenGLShader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 940541EC2B5875B200E32241 /* OpenGLShader.cpp */; };
9419E8472B49ECB1007C50D0 /* CTeamColorAdjuster.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9419E8462B49ECB1007C50D0 /* CTeamColorAdjuster.cpp */; };
Expand Down Expand Up @@ -387,6 +388,8 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
60C274E22C23EBE9005B67A9 /* LegacyOpenGLRenderer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = LegacyOpenGLRenderer.cpp; sourceTree = "<group>"; };
60C274E32C23EBE9005B67A9 /* LegacyOpenGLRenderer.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; path = LegacyOpenGLRenderer.h; sourceTree = "<group>"; };
940541EB2B58744500E32241 /* OpenGLShader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OpenGLShader.h; sourceTree = "<group>"; };
940541EC2B5875B200E32241 /* OpenGLShader.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = OpenGLShader.cpp; sourceTree = "<group>"; };
9419E8452B49EC89007C50D0 /* CTeamColorAdjuster.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CTeamColorAdjuster.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1083,6 +1086,8 @@
children = (
947F5C642B576B9F00F41689 /* ModernOpenGLRenderer.cpp */,
947F5C632B576ACD00F41689 /* ModernOpenGLRenderer.h */,
60C274E22C23EBE9005B67A9 /* LegacyOpenGLRenderer.cpp */,
60C274E32C23EBE9005B67A9 /* LegacyOpenGLRenderer.h */,
947F5C672B57A30100F41689 /* NullRenderer.h */,
940541EC2B5875B200E32241 /* OpenGLShader.cpp */,
940541EB2B58744500E32241 /* OpenGLShader.h */,
Expand Down Expand Up @@ -2390,6 +2395,7 @@
E5890CBF29895118007A875D /* CAbstractActor.cpp in Sources */,
E5890CAA29895118007A875D /* CAbstractPipe.cpp in Sources */,
E5890F0929895124007A875D /* stb_vorbis.c in Sources */,
6025AE4E2C255E6A00A57EFB /* LegacyOpenGLRenderer.cpp in Sources */,
E5890D0529895118007A875D /* CSoundMixer.cpp in Sources */,
E5890CF529895118007A875D /* CRamp.cpp in Sources */,
E5890C9F29895118007A875D /* Resource.cpp in Sources */,
Expand Down Expand Up @@ -2597,6 +2603,7 @@
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=macosx*]" = "";
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -2621,6 +2628,7 @@
PRODUCT_BUNDLE_IDENTIFIER = net.avaraline.Avara;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = "";
SWIFT_EMIT_LOC_STRINGS = YES;
};
name = Debug;
Expand Down Expand Up @@ -2661,6 +2669,7 @@
PRODUCT_BUNDLE_IDENTIFIER = net.avaraline.Avara;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = "";
SWIFT_EMIT_LOC_STRINGS = YES;
};
name = Release;
Expand Down
4 changes: 2 additions & 2 deletions levels/avaraline-quirks-mode/alf/heir-apparent.alf
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<set
pReqPointMultiplier="1"
pHillX="0"
pHillY="4"
pHillY="2"
pHillZ="0"
pHillW="15"
pHillD="15"
pHillH="2"
pHillH="4"
/>
<include alf="logic/koth.alf" />
</map>
8 changes: 4 additions & 4 deletions levels/avaraline-quirks-mode/alf/layout/heir-apparent.alf
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@
<Wall color="#ad6a6c" x="0" z="7.5" w="15" d="0" h="2" />
<Wall color="#ad6a6c" x="-7.5" z="0" w="0" d="15" h="2" />
<Wall color="#ad6a6c" x="7.5" z="0" w="0" d="15" h="2" />
<Solid y="2.01" shape="bspGrid7.5" scale="5" color="#3a2c2c" cx="0" cz="4.5" pitch="90" angle="0" />
<Solid y="2.01" shape="bspEnso" scale="4" color="#3a2c2c" cx="1.75" cz="3.25" angle="-20" />
<Solid y="2.01" shape="bspGroundStar" scale="0.1" color="#3a2c2c" cx="2.25" cz="3" angle="0" />
<Solid y="2.01" shape="bspGroundStar" scale="0.1" color="#3a2c2c" cx="1.75" cz="3.5" angle="0" />
<Hologram y="2.01" shape="bspGrid7.5" scale="5" color="#3a2c2c" cx="0" cz="4.5" pitch="90" angle="0" />
<Hologram y="2.01" shape="bspEnso" scale="4" color="#3a2c2c" cx="1.75" cz="3.25" angle="-20" />
<Hologram y="2.01" shape="bspGroundStar" scale="0.1" color="#3a2c2c" cx="2.25" cz="3" angle="0" />
<Hologram y="2.01" shape="bspGroundStar" scale="0.1" color="#3a2c2c" cx="1.75" cz="3.5" angle="0" />

<Teleporter y="20" shape="0" activeRange="35 * 5" deadRange="28 * 5" destGroup="@recenter" cx="0" cz="0" />
<Teleporter y="15" shape="0" group="@recenter" cx="0" cz="0" />
Expand Down
11 changes: 10 additions & 1 deletion src/bsp/CBSPPart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "AvaraDefines.h"
#include "CViewParameters.h"
#include "Memory.h"
#include "Debug.h"

#include <fstream>
#include <iostream>
Expand All @@ -38,7 +39,7 @@ CBSPPart *CBSPPart::Create(short resId) {


void CBSPPart::IBSPPart(short resId) {
//SDL_Log("Loading BSP: %s\n", bspName);
DBG_Log("bsp", "Loading BSP: %d\n", resId);
lightSeed = 0;
nextTemp = NULL;
// colorReplacements = NULL; // Use default colors.
Expand Down Expand Up @@ -101,6 +102,10 @@ void CBSPPart::IBSPPart(short resId) {
maxBounds.z = ToFixed(mxZ);
maxBounds.w = FIX1;

DBG_Log("bsp", " bounds.x = [%d, %d]\n", minBounds.x, maxBounds.x);
DBG_Log("bsp", " bounds.y = [%d, %d]\n", minBounds.y, maxBounds.y);
DBG_Log("bsp", " bounds.z = [%d, %d]\n", minBounds.z, maxBounds.z);

origColorTable = std::make_unique<ARGBColor[]>(colorCount);
currColorTable = std::make_unique<ARGBColor[]>(colorCount);
pointTable = std::make_unique<Vector[]>(pointCount);
Expand All @@ -123,12 +128,16 @@ void CBSPPart::IBSPPart(short resId) {

CheckForAlpha();

// if command is "/dbg bsp 666" then show points for resId 666
bool showPoints = (Debug::GetValue("bsp") == resId);
if (showPoints) { DBG_Log("bsp", " points:\n"); }
for (uint32_t i = 0; i < pointCount; i++) {
nlohmann::json pt = doc["points"][i];
pointTable[i][0] = ToFixed(pt[0]);
pointTable[i][1] = ToFixed(pt[1]);
pointTable[i][2] = ToFixed(pt[2]);
pointTable[i][3] = FIX1;
if (showPoints) { DBG_Log("bsp", " %s\n", FormatVector(pointTable[i]).c_str()); }
}

totalPoints = 0;
Expand Down
47 changes: 24 additions & 23 deletions src/game/CAbstractPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ void CAbstractPlayer::StartSystems() {

nextGrenadeLoad = 0;
nextMissileLoad = 0;
nextPlasmaShot = 0;

// variables in AdaptableSettings need to have "classic" counterparts in case they are changed in CWalkerActor::ReceiveConfig()
classicGeneratorPower = FIX3(30);
Expand Down Expand Up @@ -561,7 +562,7 @@ void CAbstractPlayer::LoadDashboardParts() {
dashboardSpinSpeed = ToFixed(100);
dashboardSpinHeading = 0;

int layout = itsGame->itsApp->Get(kHUDPreset);
layout = itsGame->itsApp->Get(kHUDPreset);
//float alpha = itsGame->itsApp->Get(kHUDAlpha);
//Fixed hudAlpha = FIX1 * alpha;

Expand Down Expand Up @@ -717,21 +718,22 @@ void CAbstractPlayer::RenderDashboard() {
// Lastly set relativeImpulse based on the impact location of the hit to bump the HUD
Fixed hitAngle = FOneArcTan2(dSpeed[2], dSpeed[0]);
Fixed angleDiff = hitAngle - viewYaw;
float magnitude = ToFloat(VectorLength(3, dSpeed));

if (angleDiff > 0) {
// Hit from the right side
relativeImpulse[0] = FIX(1.0);
relativeImpulse[0] = FIX(1.0*magnitude);
} else if (angleDiff < 0) {
// Hit from the left side
relativeImpulse[0] = FIX(-1.0);
relativeImpulse[0] = FIX(-1.0*magnitude);
}

if (dSpeed[1] > FIX(.5)) {
// Hit from the top
relativeImpulse[1] = FIX(1.0);
relativeImpulse[1] = FIX(1.0*magnitude);
} else if (dSpeed[1] < FIX(-.5)) {
// Hit from the bottom
relativeImpulse[1] = FIX(-1.0);
relativeImpulse[1] = FIX(-1.0*magnitude);
}

pidReset(&pMotionX);
Expand Down Expand Up @@ -923,11 +925,7 @@ void CAbstractPlayer::DashboardPosition(CScaledBSP *part, bool autoRot, float x,
// X/Y Coordinates on the screen are roughly described as a percentage of the screen away from the bottom and the left
// (-1.0, -1.0) is the bottom left of the screen
// (1.0, 1.0) is the top right of the screen


// TODO: Adjust these until it looks good, then go multiply
// all the DashboardPosition parameters by these numbers, and
// then delete these

float scale_x = 11.12;
float scale_y = 8.23;
Fixed hud_dist = (FIX3(6000) * 25)/8;
Expand Down Expand Up @@ -1144,12 +1142,12 @@ void CAbstractPlayer::ArmSmartMissile() {
}

if (!didDetach && oldKind != kweSmart && missileCount) {
if (nextMissileLoad < itsGame->frameNumber) {
if (nextMissileLoad <= itsGame->frameNumber) {
theWeapon = itsGame->itsDepot->AquireWeapon(kweSmart);
weaponIdent = theWeapon->Arm(viewPortPart);
if (weaponIdent) {
missileCount--;
nextMissileLoad = itsGame->FramesFromNow(3);
nextMissileLoad = itsGame->FramesFromNow(4);
}
} else
fireGun = false;
Expand Down Expand Up @@ -1177,12 +1175,12 @@ void CAbstractPlayer::ArmGrenade() {
}

if (!didDetach && oldKind != kweGrenade && grenadeCount) {
if (nextGrenadeLoad < itsGame->frameNumber) {
if (nextGrenadeLoad <= itsGame->frameNumber) {
theWeapon = itsGame->itsDepot->AquireWeapon(kweGrenade);
weaponIdent = theWeapon->Arm(viewPortPart);
if (weaponIdent) {
grenadeCount--;
nextGrenadeLoad = itsGame->FramesFromNow(2);
nextGrenadeLoad = itsGame->FramesFromNow(3);
}
} else
fireGun = false;
Expand Down Expand Up @@ -1294,11 +1292,11 @@ void CAbstractPlayer::KeyboardControl(FunctionTable *ft) {

FPS_DEBUG(" motors after keyb = " << FormatVector(motors, 2) << std::endl);

if (TESTFUNC(kfuBoostEnergy, ft->down) && boostsRemaining && (boostEndFrame < itsGame->frameNumber)) {
if (TESTFUNC(kfuBoostEnergy, ft->down) && boostsRemaining && (boostEndFrame <= itsGame->frameNumber)) {
CBasicSound *theSound;

boostsRemaining--;
boostEndFrame = itsGame->FramesFromNow(BOOSTLENGTH);
boostEndFrame = itsGame->FramesFromNow(BOOSTLENGTH+1);

if (!boostControlLink)
boostControlLink = gHub->GetSoundLink();
Expand Down Expand Up @@ -1384,10 +1382,12 @@ void CAbstractPlayer::KeyboardControl(FunctionTable *ft) {
}
}

// Disable scout controls while spectating
if (winFrame < 0 && !freeView && itsGame->GetSpectatePlayer() == NULL) {
// Disable local scout controls while spectating (players in the game still control their scouts)
if (winFrame < 0 && !itsManager->IsDeadOrDone()) {
Boolean doRelease = false;

// SDL_Log("keys> fn=%d: down=%08x, held=%08x, up=%08x\n",
// itsGame->frameNumber, ft->down, ft->held, ft->up);
if (TESTFUNC(kfuScoutView, ft->down)) {
if (!scoutView && !scoutIdent) {
doRelease = true;
Expand Down Expand Up @@ -1572,7 +1572,7 @@ void CAbstractPlayer::FrameAction() {
}

// if a frag frame is specified with /dbg, force a frag on that frame by messing with FRandSeed
int fragFrame = Debug::GetValue("frag");
int fragFrame = Debug::GetValue("ffrag");
if (fragFrame > 0 && itsGame->frameNumber == fragFrame) {
extern Fixed FRandSeed; // to intentionally cause frags below
FRandSeed += 1;
Expand Down Expand Up @@ -1713,7 +1713,8 @@ void CAbstractPlayer::GunActions() {
if (weapon) {
weapon->Fire();
weaponIdent = 0;
} else {
} else if (nextPlasmaShot <= itsGame->frameNumber) {
nextPlasmaShot = itsGame->FramesFromNow(1);
i = gunEnergy[0] < gunEnergy[1];
if (gunEnergy[i] >= activeGunEnergy) {
Vector missileSpeed;
Expand Down Expand Up @@ -1984,7 +1985,7 @@ bool CAbstractPlayer::ReincarnateComplete(CIncarnator* newSpot) {
LinkPartSpheres();

if (reEnergize) {
boostEndFrame = itsGame->FramesFromNow(MINIBOOSTTIME);
boostEndFrame = itsGame->FramesFromNow(MINIBOOSTTIME+1);
reEnergize = false;
if (shields < maxShields)
shields = maxShields;
Expand Down Expand Up @@ -2297,10 +2298,10 @@ void CAbstractPlayer::TakeGoody(GoodyRecord *gr) {
if (energy > maxEnergy)
energy = maxEnergy;

if (gr->boostTime > 0 && (boostEndFrame < itsGame->frameNumber)) {
if (gr->boostTime > 0 && (boostEndFrame <= itsGame->frameNumber)) {
CBasicSound *theSound;

boostEndFrame = itsGame->FramesFromNow(gr->boostTime);
boostEndFrame = itsGame->FramesFromNow(gr->boostTime+1);

if (!boostControlLink)
boostControlLink = gHub->GetSoundLink();
Expand Down
1 change: 1 addition & 0 deletions src/game/CAbstractPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class CAbstractPlayer : public CRealMovers {
short grenadeCount = 0;
FrameNumber nextGrenadeLoad = 0;
FrameNumber nextMissileLoad = 0;
FrameNumber nextPlasmaShot = 0;

short missileLimit = 0;
short grenadeLimit = 0;
Expand Down
26 changes: 24 additions & 2 deletions src/game/CAvaraApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "Tags.h"
#include "Debug.h"
#include "ModernOpenGLRenderer.h"
#include "LegacyOpenGLRenderer.h"

// included while we fake things out
#include "CPlayerManager.h"
Expand Down Expand Up @@ -79,7 +80,13 @@ CAvaraAppImpl::CAvaraAppImpl() : CApplication("Avara") {
ui->LoadImages(mNVGContext);
}

gRenderer = new ModernOpenGLRenderer(mSDLWindow);
if (Get(kUseLegacyRenderer)) {
gRenderer = new LegacyOpenGLRenderer(mSDLWindow);
}
else {
gRenderer = new ModernOpenGLRenderer(mSDLWindow);
}

gRenderer->UpdateViewRect(mSize.x, mSize.y, mPixelRatio);
gRenderer->SetFOV(Number(kFOV));
gRenderer->ResetLights();
Expand Down Expand Up @@ -152,11 +159,24 @@ void CAvaraAppImpl::Done() {
}

void CAvaraAppImpl::idle() {
static double avg = 0;
FrameNumber curFrame = itsGame->frameNumber;
uint32_t procTime = SDL_GetTicks();

CheckSockets();
TrackerUpdate();
if (itsGame->GameTick()) {
RenderContents();
}

// output a coarse estimate of cpu time & percent every second when enabled
if (curFrame > 0 && curFrame != itsGame->frameNumber && Debug::IsEnabled("cpu")) {
procTime = SDL_GetTicks() - procTime;
avg = 0.99*avg + 0.01*procTime;
if (curFrame % (1000/itsGame->frameTime) == 0) {
DBG_Log("cpu", "%.1fms (%.0f%%)\n", avg, 100.0*avg/itsGame->frameTime);
}
}
}

void CAvaraAppImpl::drawContents() {
Expand Down Expand Up @@ -187,7 +207,9 @@ void CAvaraAppImpl::RenderContents() {
}

void CAvaraAppImpl::WindowResized(int width, int height) {
gRenderer->UpdateViewRect(width, height, mPixelRatio);
// Only update if the resolution is actually changing
if (gRenderer->viewParams->viewPixelDimensions.h != width || gRenderer->viewParams->viewPixelDimensions.v != height)
gRenderer->UpdateViewRect(width, height, mPixelRatio);
//performLayout();
}

Expand Down
13 changes: 12 additions & 1 deletion src/game/CAvaraGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ void CAvaraGame::IAvaraGame(CAvaraApp *theApp) {
statusRequest = kNoVehicleStatus;

nextPingTime = 0;
nextLoadTime = 0;

showNewHUD = gApplication ? gApplication->Get<bool>(kShowNewHUD) : false;
// CalcGameRect();
Expand Down Expand Up @@ -843,6 +844,16 @@ bool CAvaraGame::GameTick() {
nextPingTime = startTime + pingInterval;
}

int randLoadPeriod = Debug::GetValue("rload"); // randomly load a level every `rload` seconds
if (randLoadPeriod > 0) {
if (startTime > nextLoadTime) {
auto p = CPlayerManagerImpl::LocalPlayer();
auto *tui = itsApp->GetTui();
tui->ExecuteMatchingCommand("/rand", p);
nextLoadTime = startTime + 1000*randLoadPeriod;
}
}

// Not playing? Nothing to do!
if (statusRequest != kPlayingStatus)
return false;
Expand Down Expand Up @@ -1135,7 +1146,7 @@ void CAvaraGame::IncrementFrame(bool firstFrame) {
isClassicFrame = (frameNumber % (CLASSICFRAMETIME / frameTime) == 0);
}

FrameNumber CAvaraGame::FramesFromNow(FrameNumber classicFrameCount) {
FrameNumber CAvaraGame::FramesFromNow(double classicFrameCount) {
return frameNumber + classicFrameCount / fpsScale;
}

Expand Down
Loading
Loading