Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions Generals/Code/GameEngine/Include/Common/GlobalData.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class GlobalData : public SubsystemInterface
void update() { }

Bool setTimeOfDay( TimeOfDay tod ); ///< Use this function to set the Time of day;
void setResolution(Int xres, Int yres);

static void parseGameDataDefinition( INI* ini );

Expand Down Expand Up @@ -159,6 +160,7 @@ class GlobalData : public SubsystemInterface
Real m_cameraHeight;
Real m_maxCameraHeight;
Real m_minCameraHeight;
Real m_cameraHeightAspectRatioMultiplier;
Real m_terrainHeightAtEdgeOfMap;
Real m_unitDamagedThresh;
Real m_unitReallyDamagedThresh;
Expand Down
4 changes: 2 additions & 2 deletions Generals/Code/GameEngine/Source/Common/CommandLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ Int parseXRes(char *args[], int num)
{
if (TheWritableGlobalData && num > 1)
{
TheWritableGlobalData->m_xResolution = atoi(args[1]);
TheWritableGlobalData->setResolution(atoi(args[1]), TheWritableGlobalData->m_yResolution);
return 2;
}
return 1;
Expand All @@ -399,7 +399,7 @@ Int parseYRes(char *args[], int num)
{
if (TheWritableGlobalData && num > 1)
{
TheWritableGlobalData->m_yResolution = atoi(args[1]);
TheWritableGlobalData->setResolution(TheWritableGlobalData->m_xResolution, atoi(args[1]));
return 2;
}
return 1;
Expand Down
34 changes: 31 additions & 3 deletions Generals/Code/GameEngine/Source/Common/GlobalData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@

#include "GameClient/Color.h"
#include "GameClient/TerrainVisual.h"
#include "GameClient/View.h"

#include "GameNetwork/FirewallHelper.h"

Expand Down Expand Up @@ -1076,6 +1077,35 @@ Bool GlobalData::setTimeOfDay( TimeOfDay tod )

}

// TheSuperHackers @tweak valeronm 21/03/2025 Increase camera height for wide resolutions
void GlobalData::setResolution(Int xres, Int yres) {
static const Real aspect_4_3 = 4.f / 3.f;
static const Real aspect_16_9 = 16.f / 9.f;

m_xResolution = xres;
m_yResolution = yres;

// Change camera height based on xezon code from https://github.com/TheSuperHackers/GeneralsGameCode/issues/78
Real aspect = static_cast<Real>(xres) / static_cast<Real>(yres);

if (aspect > aspect_4_3 && xres >= 640 && yres >= 480) {
if (aspect > aspect_16_9)
aspect = aspect_16_9;
const Real multi = aspect - aspect_4_3 + 1.0f;
const Real nerf = 1.0f - (aspect - aspect_4_3) / 12.0f;
m_cameraHeightAspectRatioMultiplier = multi * nerf;
m_drawEntireTerrain = TRUE;
}
else
{
m_cameraHeightAspectRatioMultiplier = 1.0f;
m_drawEntireTerrain = FALSE;
}
if (TheTacticalView) {
TheTacticalView->setDefaultView(0.0f, 0.0f, 1.0f);
}
}

//-------------------------------------------------------------------------------------------------
/** Create a new global data instance to override the existing data set. The
* initial values of the newly created instance will be a copy of the current
Expand Down Expand Up @@ -1213,8 +1243,6 @@ void GlobalData::parseGameDataDefinition( INI* ini )

Int xres,yres;
optionPref.getResolution(&xres, &yres);

TheWritableGlobalData->m_xResolution = xres;
TheWritableGlobalData->m_yResolution = yres;
TheWritableGlobalData->setResolution(xres,yres);
}

Original file line number Diff line number Diff line change
Expand Up @@ -737,8 +737,7 @@ void DeclineResolution()
dispChanged = FALSE;
newDispSettings = oldDispSettings;

TheWritableGlobalData->m_xResolution = newDispSettings.xRes;
TheWritableGlobalData->m_yResolution = newDispSettings.yRes;
TheWritableGlobalData->setResolution(newDispSettings.xRes, newDispSettings.yRes);

TheHeaderTemplateManager->headerNotifyResolutionChange();
TheMouse->mouseNotifyResolutionChange();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1031,8 +1031,7 @@ static void saveOptions( void )
if (TheDisplay->setDisplayMode(xres,yres,bitDepth,TheDisplay->getWindowed()))
{
dispChanged = TRUE;
TheWritableGlobalData->m_xResolution = xres;
TheWritableGlobalData->m_yResolution = yres;
TheWritableGlobalData->setResolution(xres, yres);

TheHeaderTemplateManager->headerNotifyResolutionChange();
TheMouse->mouseNotifyResolutionChange();
Expand Down
2 changes: 1 addition & 1 deletion Generals/Code/GameEngine/Source/GameClient/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void View::init( void )
m_maxZoom = 1.3f;
m_minZoom = 0.2f;
m_zoom = m_maxZoom;
m_maxHeightAboveGround = TheGlobalData->m_maxCameraHeight;
m_maxHeightAboveGround = TheGlobalData->m_maxCameraHeight * TheGlobalData->m_cameraHeightAspectRatioMultiplier;
m_minHeightAboveGround = TheGlobalData->m_minCameraHeight;
m_okToAdjustHeight = FALSE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1617,7 +1617,7 @@ void W3DView::setDefaultView(Real pitch, Real angle, Real maxHeight)
// MDC - we no longer want to rotate maps (design made all of them right to begin with)
// m_defaultAngle = angle * M_PI/180.0f;
m_defaultPitchAngle = pitch;
m_maxHeightAboveGround = TheGlobalData->m_maxCameraHeight*maxHeight;
m_maxHeightAboveGround = TheGlobalData->m_maxCameraHeight * TheGlobalData->m_cameraHeightAspectRatioMultiplier * maxHeight;
if (m_minHeightAboveGround > m_maxHeightAboveGround)
m_maxHeightAboveGround = m_minHeightAboveGround;
}
Expand Down
2 changes: 2 additions & 0 deletions GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class GlobalData : public SubsystemInterface
void update() { }

Bool setTimeOfDay( TimeOfDay tod ); ///< Use this function to set the Time of day;
void setResolution(Int xRes, Int yRes);

static void parseGameDataDefinition( INI* ini );

Expand Down Expand Up @@ -166,6 +167,7 @@ class GlobalData : public SubsystemInterface
Real m_cameraHeight;
Real m_maxCameraHeight;
Real m_minCameraHeight;
Real m_cameraHeightAspectRatioMultiplier;
Real m_terrainHeightAtEdgeOfMap;
Real m_unitDamagedThresh;
Real m_unitReallyDamagedThresh;
Expand Down
4 changes: 2 additions & 2 deletions GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ Int parseXRes(char *args[], int num)
{
if (TheWritableGlobalData && num > 1)
{
TheWritableGlobalData->m_xResolution = atoi(args[1]);
TheWritableGlobalData->setResolution(atoi(args[1]), TheWritableGlobalData->m_yResolution);
return 2;
}
return 1;
Expand All @@ -407,7 +407,7 @@ Int parseYRes(char *args[], int num)
{
if (TheWritableGlobalData && num > 1)
{
TheWritableGlobalData->m_yResolution = atoi(args[1]);
TheWritableGlobalData->setResolution(TheWritableGlobalData->m_xResolution, atoi(args[1]));
return 2;
}
return 1;
Expand Down
35 changes: 32 additions & 3 deletions GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

#include "GameClient/Color.h"
#include "GameClient/TerrainVisual.h"
#include "GameClient/View.h"

#include "GameNetwork/FirewallHelper.h"

Expand Down Expand Up @@ -825,6 +826,7 @@ GlobalData::GlobalData()
m_cameraHeight = 0.0f;
m_minCameraHeight = 100.0f;
m_maxCameraHeight = 300.0f;
m_cameraHeightAspectRatioMultiplier = 1.0f;
m_terrainHeightAtEdgeOfMap = 0.0f;

m_unitDamagedThresh = 0.5f;
Expand Down Expand Up @@ -1122,6 +1124,35 @@ Bool GlobalData::setTimeOfDay( TimeOfDay tod )

}

// TheSuperHackers @tweak valeronm 21/03/2025 Increase camera height for wide resolutions
void GlobalData::setResolution(Int xres, Int yres) {
static const Real aspect_4_3 = 4.f / 3.f;
static const Real aspect_16_9 = 16.f / 9.f;

m_xResolution = xres;
m_yResolution = yres;

// Change camera height based on xezon code from https://github.com/TheSuperHackers/GeneralsGameCode/issues/78
Real aspect = static_cast<Real>(xres) / static_cast<Real>(yres);

if (aspect > aspect_4_3 && xres >= 640 && yres >= 480) {
if (aspect > aspect_16_9)
aspect = aspect_16_9;
const Real multi = aspect - aspect_4_3 + 1.0f;
const Real nerf = 1.0f - (aspect - aspect_4_3) / 12.0f;
m_cameraHeightAspectRatioMultiplier = multi * nerf;
m_drawEntireTerrain = TRUE;
}
else
{
m_cameraHeightAspectRatioMultiplier = 1.0f;
m_drawEntireTerrain = FALSE;
}
if (TheTacticalView) {
TheTacticalView->setDefaultView(0.0f, 0.0f, 1.0f);
}
}

//-------------------------------------------------------------------------------------------------
/** Create a new global data instance to override the existing data set. The
* initial values of the newly created instance will be a copy of the current
Expand Down Expand Up @@ -1249,8 +1280,6 @@ void GlobalData::parseGameDataDefinition( INI* ini )

Int xres,yres;
optionPref.getResolution(&xres, &yres);

TheWritableGlobalData->m_xResolution = xres;
TheWritableGlobalData->m_yResolution = yres;
TheWritableGlobalData->setResolution(xres, yres);
}

Original file line number Diff line number Diff line change
Expand Up @@ -747,8 +747,7 @@ void DeclineResolution()
dispChanged = FALSE;
newDispSettings = oldDispSettings;

TheWritableGlobalData->m_xResolution = newDispSettings.xRes;
TheWritableGlobalData->m_yResolution = newDispSettings.yRes;
TheWritableGlobalData->setResolution(newDispSettings.xRes, newDispSettings.yRes);

TheHeaderTemplateManager->headerNotifyResolutionChange();
TheMouse->mouseNotifyResolutionChange();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1086,8 +1086,7 @@ static void saveOptions( void )
if (TheDisplay->setDisplayMode(xres,yres,bitDepth,TheDisplay->getWindowed()))
{
dispChanged = TRUE;
TheWritableGlobalData->m_xResolution = xres;
TheWritableGlobalData->m_yResolution = yres;
TheWritableGlobalData->setResolution(xres, yres);

TheHeaderTemplateManager->headerNotifyResolutionChange();
TheMouse->mouseNotifyResolutionChange();
Expand Down
2 changes: 1 addition & 1 deletion GeneralsMD/Code/GameEngine/Source/GameClient/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void View::init( void )
m_maxZoom = 1.3f;
m_minZoom = 0.2f;
m_zoom = m_maxZoom;
m_maxHeightAboveGround = TheGlobalData->m_maxCameraHeight;
m_maxHeightAboveGround = TheGlobalData->m_maxCameraHeight * TheGlobalData->m_cameraHeightAspectRatioMultiplier;
m_minHeightAboveGround = TheGlobalData->m_minCameraHeight;
m_okToAdjustHeight = FALSE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1916,7 +1916,7 @@ void W3DView::setDefaultView(Real pitch, Real angle, Real maxHeight)
// MDC - we no longer want to rotate maps (design made all of them right to begin with)
// m_defaultAngle = angle * M_PI/180.0f;
m_defaultPitchAngle = pitch;
m_maxHeightAboveGround = TheGlobalData->m_maxCameraHeight*maxHeight;
m_maxHeightAboveGround = TheGlobalData->m_maxCameraHeight * TheGlobalData->m_cameraHeightAspectRatioMultiplier * maxHeight;
if (m_minHeightAboveGround > m_maxHeightAboveGround)
m_maxHeightAboveGround = m_minHeightAboveGround;
}
Expand Down