Skip to content

Commit

Permalink
Initial work on virtual display mode support
Browse files Browse the repository at this point in the history
Saving out display mode ratio of max res, and adding support for client to set resolution in response to window events
  • Loading branch information
colincornaby committed Sep 20, 2022
1 parent 2a059e0 commit 9df8d56
Show file tree
Hide file tree
Showing 11 changed files with 372 additions and 14 deletions.
9 changes: 5 additions & 4 deletions Scripts/Python/xIniDisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@
kGraphicsShadows = "Graphics.Shadow.Enable"
kGraphicsVerticalSync = "Graphics.EnableVSync"
kGraphicsShadowQuality = "Graphics.Shadow.VisibleDistance"
kGraphicsOutputScale = "Graphics.OutputScale"

CmdList = [kGraphicsWidth, kGraphicsHeight, kGraphicsColorDepth, kGraphicsWindowed, kGraphicsTextureQuality, kGraphicsAntiAliasLevel, kGraphicsAnisotropicLevel, kGraphicsQualityLevel, kGraphicsShadows, kGraphicsVerticalSync, kGraphicsShadowQuality]
DefaultsList = ["800", "600", "32", "false", "2", "0", "0", "2", "true", "false", "0"]
CmdList = [kGraphicsWidth, kGraphicsHeight, kGraphicsColorDepth, kGraphicsWindowed, kGraphicsTextureQuality, kGraphicsAntiAliasLevel, kGraphicsAnisotropicLevel, kGraphicsQualityLevel, kGraphicsShadows, kGraphicsVerticalSync, kGraphicsShadowQuality, kGraphicsOutputScale]
DefaultsList = ["800", "600", "32", "false", "2", "0", "0", "2", "true", "false", "0", "100"]

def ConstructFilenameAndPath():
global gFilenameAndPath
Expand Down Expand Up @@ -120,9 +121,9 @@ def ReadIni():
ConstructFilenameAndPath()
gIniFile.writeFile(gFilenameAndPath)

def SetGraphicsOptions(width, heigth, colordepth, windowed, texquality, aaLevel, anisoLevel, qualityLevel, useShadows, vsync, shadowqual):
def SetGraphicsOptions(width, heigth, colordepth, windowed, texquality, aaLevel, anisoLevel, qualityLevel, useShadows, vsync, shadowqual, outputScale):
if gIniFile:
paramList = [width, heigth, colordepth, windowed, texquality, aaLevel, anisoLevel, qualityLevel, useShadows, vsync, shadowqual]
paramList = [width, heigth, colordepth, windowed, texquality, aaLevel, anisoLevel, qualityLevel, useShadows, vsync, shadowqual, outputScale]
for idx in range(len(CmdList)):
entry,junk = gIniFile.findByCommand(CmdList[idx])
val = str(paramList[idx])
Expand Down
12 changes: 9 additions & 3 deletions Scripts/Python/xOptionsMenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@
gClickToTurn = "0"
gAudioHack = 0
gCurrentReleaseNotes = "Welcome to Myst Online: Uru Live!"
gMaxVideoWidth = 0

class xOptionsMenu(ptModifier):
"The Options dialog modifier"
Expand Down Expand Up @@ -1488,6 +1489,7 @@ def ResetVideoToDefault(self):
self.SetVidResField(vidRes)

def InitVideoControlsGUI(self):
global gMaxVideoWidth
xIniDisplay.ReadIni()
opts = xIniDisplay.GetGraphicsOptions()

Expand Down Expand Up @@ -1540,7 +1542,10 @@ def InitVideoControlsGUI(self):

if not vidRes in vidResList:
vidRes = vidResList[numRes-1]


gMaxVideoWidth = int(vidResList[numRes-1].split("x")[0])
print("Largest video width is " + str(gMaxVideoWidth))

for res in range(numRes):
if vidRes == vidResList[res]:
if numRes > 1:
Expand Down Expand Up @@ -1644,8 +1649,9 @@ def WriteVideoControls(self, setMode = 0):

gammaField = ptGUIControlKnob(GraphicsSettingsDlg.dialog.getControlFromTag(kGSDisplayGammaSlider))
gamma = gammaField.getValue()

xIniDisplay.SetGraphicsOptions(width, height, colordepth, windowed, tex_quality, antialias, aniso, quality, shadows, vsyncstr, shadow_quality)
resolutionScale = int(round((width / gMaxVideoWidth) * 100))

xIniDisplay.SetGraphicsOptions(width, height, colordepth, windowed, tex_quality, antialias, aniso, quality, shadows, vsyncstr, shadow_quality, resolutionScale)
xIniDisplay.WriteIni()
self.setNewChronicleVar("gamma", gamma)

Expand Down
47 changes: 46 additions & 1 deletion Sources/Plasma/Apps/plClient/plClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ You can contact Cyan Worlds, Inc. by email [email protected]
#include "pfPython/cyMisc.h"
#include "pfPython/cyPythonInterface.h"


#define MSG_LOADING_BAR

// static hsVector3 gAbsDown(0,0,-1.f);
Expand Down Expand Up @@ -221,6 +220,7 @@ plClient::~plClient()
plClient::SetInstance(nullptr);

delete fPageMgr;
delete fGraphicsIni;
}

template<typename T>
Expand Down Expand Up @@ -443,6 +443,7 @@ bool plClient::InitPipeline(hsWindowHndl display, uint32_t devType)

hsG3DDeviceRecord *rec = (hsG3DDeviceRecord *)dmr.GetDevice();

#if !PLASMA_DISPLAY_INDEPENDENT_VIDEO_MODES
if(!plPipeline::fInitialPipeParams.Windowed)
{
// find our resolution if we're not in windowed mode
Expand All @@ -467,6 +468,7 @@ bool plClient::InitPipeline(hsWindowHndl display, uint32_t devType)
ISetGraphicsDefaults();
}
}
#endif

if(plPipeline::fInitialPipeParams.TextureQuality == -1)
{
Expand Down Expand Up @@ -1900,6 +1902,47 @@ void plClient::ResizeDisplayDevice(int Width, int Height, bool Windowed)
IResizeNativeDisplayDevice(Width, Height, Windowed);
}

void plClient::SetDisplayOptions(int Width, int Height, bool Windowed)
{
fGraphicsIni->readFile();
std::shared_ptr<hsIniEntry> entry = fGraphicsIni->findByCommand("Graphics.Windowed");
if (entry) {
entry->setValue(0, Windowed ? "true" : "false");
}

entry = fGraphicsIni->findByCommand("Graphics.OutputScale");
if (entry) {
double scale = entry->getValue(0)->to_uint() / 100.0;
Width *= scale;
Height *= scale;
}

entry = fGraphicsIni->findByCommand("Graphics.Width");
if (entry) {
entry->setValue(0, std::to_string(Width));
}
entry = fGraphicsIni->findByCommand("Graphics.Height");
if (entry) {
entry->setValue(0, std::to_string(Height));
}
fGraphicsIni->writeFile();

FlushGraphicsOptions();
}

void plClient::FlushGraphicsOptions()
{
int Width = fGraphicsIni->findByCommand("Graphics.Width")->getValue(0)->to_int();
int Height = fGraphicsIni->findByCommand("Graphics.Height")->getValue(0)->to_int();
int ColorDepth = fGraphicsIni->findByCommand("Graphics.ColorDepth")->getValue(0)->to_int();
int NumAASamples = fGraphicsIni->findByCommand("Graphics.AntiAliasAmount")->getValue(0)->to_int();
int MaxAnisotropicSamples = fGraphicsIni->findByCommand("Graphics.AnisotropicLevel")->getValue(0)->to_int();
bool VSync = (fGraphicsIni->findByCommand("Graphics.EnableVSync")->getValue(0) == "true");
bool Windowed = (fGraphicsIni->findByCommand("Graphics.Windowed")->getValue(0) == "true");

ResetDisplayDevice(Width, Height, ColorDepth, Windowed, NumAASamples, MaxAnisotropicSamples);
}

void WriteBool(hsStream *stream, const char *name, bool on )
{
char command[256];
Expand Down Expand Up @@ -1998,6 +2041,8 @@ void plClient::IDetectAudioVideoSettings()
s.Close();
else
IWriteDefaultGraphicsSettings(graphicsIniFile);

fGraphicsIni = new hsIniFile(graphicsIniFile);
}

void plClient::IWriteDefaultAudioSettings(const plFileName& destFile)
Expand Down
5 changes: 5 additions & 0 deletions Sources/Plasma/Apps/plClient/plClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ You can contact Cyan Worlds, Inc. by email [email protected]

#include "HeadSpin.h"
#include "hsBitVector.h"
#include "hsIniHelper.h"
#include "plFileSystem.h"

#include <list>
Expand Down Expand Up @@ -157,6 +158,8 @@ class plClient : public hsKeyedObject

plMessagePumpProc fMessagePumpProc;

hsIniFile *fGraphicsIni;

#ifndef PLASMA_EXTERNAL_RELEASE
bool bPythonDebugConnected;
#endif
Expand Down Expand Up @@ -223,6 +226,7 @@ class plClient : public hsKeyedObject
void IResizeNativeDisplayDevice(int width, int height, bool windowed);
void IChangeResolution(int width, int height);
void IUpdateProgressIndicator(plOperationProgress* progress);
void FlushGraphicsOptions();

public:

Expand Down Expand Up @@ -310,6 +314,7 @@ class plClient : public hsKeyedObject
void SetMessagePumpProc(plMessagePumpProc proc) { fMessagePumpProc = proc; }
void ResetDisplayDevice(int Width, int Height, int ColorDepth, bool Windowed, int NumAASamples, int MaxAnisotropicSamples, bool VSync = false);
void ResizeDisplayDevice(int Width, int Height, bool Windowed);
void SetDisplayOptions(int Width, int Height, bool Windowed);

plAnimDebugList *fAnimDebugList;
};
Expand Down
2 changes: 2 additions & 0 deletions Sources/Plasma/CoreLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(CoreLib_SOURCES
hsExceptionStack.cpp
hsFastMath.cpp
hsGeometry3.cpp
hsIniHelper.cpp
hsMatrix33.cpp
hsMatrix44.cpp
hsMemory.cpp
Expand Down Expand Up @@ -48,6 +49,7 @@ set(CoreLib_HEADERS
hsExceptionStack.h
hsFastMath.h
hsGeometry3.h
hsIniHelper.h
hsLockGuard.h
hsMatrix44.h
hsMemory.h
Expand Down
130 changes: 130 additions & 0 deletions Sources/Plasma/CoreLib/hsIniHelper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
//
// hsIniHelper.cpp
// CoreLib
//
// Created by Colin Cornaby on 8/29/22.
//

#include "hsIniHelper.h"
#include "hsStringTokenizer.h"

hsIniEntry::hsIniEntry(ST::string line):
fCommand(), fComment() {
if(line.size() == 0) {
fType = kBlankLine;
} else if(line[0] == '#') {
fType = kComment;
fComment = line.after_first('#');
} else if(line == "\n") {
fType = kBlankLine;
} else {
fType = kCommandValue;
hsStringTokenizer tokenizer = hsStringTokenizer(line.c_str(), " ");
char *str;
int i = 0;
while((str = tokenizer.next())) {
if (i==0) {
fCommand = str;
} else {
fValues.push_back(str);
}
i++;
}
}
}

void hsIniEntry::setValue(size_t idx, ST::string value) {
if (fValues.size() >= idx) {
fValues[idx] = value;
} else {
for (int i=fValues.size(); i<idx; i++) {
fValues.push_back("");
}
fValues.push_back(value);
}
}

std::optional<ST::string> hsIniEntry::getValue(size_t idx) {
if (fValues.size() < idx) {
return std::optional<ST::string>();
} else {
return fValues[idx];
}
}


hsIniFile::hsIniFile(plFileName filename) {

this->filename = filename;
readFile();
}


hsIniFile::hsIniFile(hsStream& stream) {
readStream(stream);
}

void hsIniFile::readStream(hsStream& stream) {
ST::string line;
while(stream.ReadLn(line)) {
std::shared_ptr<hsIniEntry> entry = std::make_shared<hsIniEntry>(line);
fEntries.push_back(entry);
}
}

void hsIniFile::writeFile() {
hsAssert(filename.GetSize() > 0, "writeFile requires contructor with filename");

hsBufferedStream s;
s.Open(filename, "w");
writeStream(s);
s.Close();
}

void hsIniFile::readFile() {
hsAssert(filename.GetSize() > 0, "writeFile requires contructor with filename");

fEntries.clear();

hsBufferedStream s;
s.Open(filename);
readStream(s);
s.Close();
}

void hsIniFile::writeFile(plFileName filename) {
hsBufferedStream s;
s.Open(filename, "w");
writeStream(s);
s.Close();
}

void hsIniFile::writeStream(hsStream& stream) {
for (std::shared_ptr<hsIniEntry> entry: fEntries) {
switch (entry->fType) {
case hsIniEntry::kBlankLine:
stream.WriteSafeString("\n");
break;
case hsIniEntry::kComment:
stream.WriteSafeString("#" + entry.get()->fComment + "\n");
break;
case hsIniEntry::kCommandValue:
ST::string line = entry->fCommand;
for (ST::string value: entry->fValues) {
line += " " + value;
}
line += "\n";
stream.WriteString(line);
break;
}
}
}

std::shared_ptr<hsIniEntry> hsIniFile::findByCommand(ST::string command) {
for (std::shared_ptr<hsIniEntry> entry: fEntries) {
if(entry->fCommand == command) {
return entry;
}
}
return std::shared_ptr<hsIniEntry>(nullptr);
}
55 changes: 55 additions & 0 deletions Sources/Plasma/CoreLib/hsIniHelper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// hsIniHelper.hpp
// CoreLib
//
// Created by Colin Cornaby on 8/29/22.
//

#ifndef hsIniHelper_hpp
#define hsIniHelper_hpp

#include <stdio.h>
#include <string_theory/string>
#include <vector>
#include <optional>
#include "plFileSystem.h"
#include "hsStream.h"

#endif /* hsIniHelper_hpp */

class hsIniFile;

class hsIniEntry {
friend hsIniFile;
public:

enum Type {
kBlankLine = 0,
kComment,
kCommandValue
};

Type fType;
ST::string fCommand;
ST::string fComment;
std::vector<ST::string> fValues;
void setValue(size_t idx, ST::string value);
std::optional<ST::string> getValue(size_t idx);
hsIniEntry(ST::string line);
};

class hsIniFile {
public:
std::vector<std::shared_ptr<hsIniEntry>> fEntries;

hsIniFile(plFileName filename);
hsIniFile(hsStream& stream);
void writeFile(plFileName filename);
void writeFile();
void writeStream(hsStream& stream);
std::shared_ptr<hsIniEntry> findByCommand(ST::string command);
void readFile();
private:
void readStream(hsStream& stream);
plFileName filename;
};
Loading

0 comments on commit 9df8d56

Please sign in to comment.