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

Virtual Display Mode Support #1244

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
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
8 changes: 6 additions & 2 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 @@ -1541,6 +1543,7 @@ def InitVideoControlsGUI(self):
if not vidRes in vidResList:
vidRes = vidResList[numRes-1]

gMaxVideoWidth = int(vidResList[numRes-1].split("x")[0])
for res in range(numRes):
if vidRes == vidResList[res]:
if numRes > 1:
Expand Down Expand Up @@ -1644,8 +1647,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
165 changes: 165 additions & 0 deletions Sources/Plasma/CoreLib/hsIniHelper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/*==LICENSE==*

CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

Additional permissions under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.

You can contact Cyan Worlds, Inc. by email [email protected]
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021

*==LICENSE==*/

#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);
}
Loading