Merge pull request #356 from Wargus/topic/build-fixes

Build and runtime fixes
This commit is contained in:
Tim Felgentreff 2021-07-17 07:12:49 +02:00 committed by GitHub
commit fba2e8e440
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 57 additions and 37 deletions

View file

@ -41,6 +41,7 @@ set(STRATAGUS_PATCH_LEVEL2 0)
project(stratagus) project(stratagus)
cmake_minimum_required(VERSION 2.6) cmake_minimum_required(VERSION 2.6)
cmake_policy(VERSION 3.10..3.20.2)
# useful for clangd LSP server # useful for clangd LSP server
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

View file

@ -579,7 +579,7 @@ int main(int argc, char * argv[]) {
// Use extractor from PATH // Use extractor from PATH
strcpy(extractor_path, EXTRACTOR_TOOL); strcpy(extractor_path, EXTRACTOR_TOOL);
if (!detectPresence(extractor_path)) { if (!detectPresence(extractor_path)) {
char msg[BUFF_SIZE * 2]; char msg[BUFF_SIZE * 2] = {'\0'};;
strcpy(msg, EXTRACTOR_NOT_FOUND); strcpy(msg, EXTRACTOR_NOT_FOUND);
strcat(msg, " (expected at "); strcat(msg, " (expected at ");
strcat(msg, extractor_path); strcat(msg, extractor_path);
@ -623,7 +623,7 @@ int main(int argc, char * argv[]) {
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, REGKEY, 0, KEY_QUERY_VALUE, &key) == ERROR_SUCCESS) { if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, REGKEY, 0, KEY_QUERY_VALUE, &key) == ERROR_SUCCESS) {
if (RegQueryValueEx(key, "InstallLocation", NULL, NULL, (LPBYTE)stratagus_path, &stratagus_path_size) == ERROR_SUCCESS) { if (RegQueryValueEx(key, "InstallLocation", NULL, NULL, (LPBYTE)stratagus_path, &stratagus_path_size) == ERROR_SUCCESS) {
if (stratagus_path_size == 0 || strlen(stratagus_path) == 0) { if (stratagus_path_size == 0 || strlen(stratagus_path) == 0) {
char msg[BUFF_SIZE * 2]; char msg[BUFF_SIZE * 2] = {'\0'};
strcat(msg, STRATAGUS_NOT_FOUND); strcat(msg, STRATAGUS_NOT_FOUND);
strcat(msg, " (expected globally installed or in "); strcat(msg, " (expected globally installed or in ");
strcat(msg, stratagus_bin); strcat(msg, stratagus_bin);
@ -635,7 +635,7 @@ int main(int argc, char * argv[]) {
} }
if (_chdir(stratagus_path) != 0) { if (_chdir(stratagus_path) != 0) {
char msg[BUFF_SIZE * 2]; char msg[BUFF_SIZE * 2] = {'\0'};
strcat(msg, STRATAGUS_NOT_FOUND); strcat(msg, STRATAGUS_NOT_FOUND);
strcat(msg, " (registry key found, but directory "); strcat(msg, " (registry key found, but directory ");
strcat(msg, stratagus_path); strcat(msg, stratagus_path);
@ -680,7 +680,7 @@ int main(int argc, char * argv[]) {
PathRemoveFileSpec(stratagus_bin); PathRemoveFileSpec(stratagus_bin);
strcat(extractor_path, "\\stratagus.exe"); strcat(extractor_path, "\\stratagus.exe");
if (stat(stratagus_bin, &st) != 0) { if (stat(stratagus_bin, &st) != 0) {
char msg[BUFF_SIZE * 2]; char msg[BUFF_SIZE * 2] = {'\0'};
strcat(msg, STRATAGUS_NOT_FOUND); strcat(msg, STRATAGUS_NOT_FOUND);
strcat(msg, " (expected in "); strcat(msg, " (expected in ");
strcat(msg, stratagus_bin); strcat(msg, stratagus_bin);
@ -697,7 +697,7 @@ int main(int argc, char * argv[]) {
strcat(stratagus_bin, "./stratagus"); strcat(stratagus_bin, "./stratagus");
} }
if ( stat(stratagus_bin, &st) != 0 ) { if ( stat(stratagus_bin, &st) != 0 ) {
char msg[BUFF_SIZE * 2]; char msg[BUFF_SIZE * 2] = {'\0'};
strcat(msg, STRATAGUS_NOT_FOUND); strcat(msg, STRATAGUS_NOT_FOUND);
strcat(msg, " (expected in "); strcat(msg, " (expected in ");
strcat(msg, stratagus_bin); strcat(msg, stratagus_bin);

View file

@ -243,11 +243,9 @@ void ArgvQuote(const std::wstring& Argument, std::wstring& CommandLine, bool For
int runCommand(std::wstring& file, std::vector<std::wstring> argv, bool echo = false, std::wstring *outputCommandline = NULL) { int runCommand(std::wstring& file, std::vector<std::wstring> argv, bool echo = false, std::wstring *outputCommandline = NULL) {
std::wstring cmdline; std::wstring cmdline;
std::wstring executable;
ArgvQuote(file, cmdline, false); ArgvQuote(file, executable, false);
if (argv.size() > 0) {
cmdline.push_back(L' ');
}
for (size_t i = 0; i < argv.size(); i++) { for (size_t i = 0; i < argv.size(); i++) {
std::wstring arg = argv[i]; std::wstring arg = argv[i];
@ -263,11 +261,19 @@ int runCommand(std::wstring& file, std::vector<std::wstring> argv, bool echo = f
} }
cmdcmdline.push_back(c); cmdcmdline.push_back(c);
} }
if (argv.size() > 0) {
cmdcmdline = std::wstring(L"@") + executable + std::wstring(L" ") + cmdcmdline;
} else {
cmdcmdline = std::wstring(L"@") + executable;
}
if (outputCommandline != NULL) { if (outputCommandline != NULL) {
outputCommandline->append(cmdline); outputCommandline->append(cmdcmdline);
} }
if (echo) { if (echo) {
std::wcout << cmdline << L'\n'; std::wcout << executable << L' ' << cmdline << L'\n';
std::wcout << cmdcmdline << L'\n';
} }
_flushall(); _flushall();
int code = _wsystem(cmdcmdline.c_str()); int code = _wsystem(cmdcmdline.c_str());

View file

@ -711,9 +711,9 @@ private:
}; };
class Context; class Context;
class NetworkState { class OnlineState {
public: public:
virtual ~NetworkState() {}; virtual ~OnlineState() {};
virtual void doOneStep(Context *ctx) = 0; virtual void doOneStep(Context *ctx) = 0;
protected: protected:
@ -1311,7 +1311,7 @@ public:
return true; return true;
} }
void setState(NetworkState* newState) { void setState(OnlineState* newState) {
assert (newState != this->state); assert (newState != this->state);
if (this->state != NULL) { if (this->state != NULL) {
delete this->state; delete this->state;
@ -1339,7 +1339,7 @@ private:
return username + "'s game"; return username + "'s game";
} }
NetworkState *state; OnlineState *state;
CHost *host; CHost *host;
int8_t canDoUdp = -1; // -1,0,1 --- not tried, doesn't work, I created it int8_t canDoUdp = -1; // -1,0,1 --- not tried, doesn't work, I created it
CTCPSocket *tcpSocket; CTCPSocket *tcpSocket;
@ -1365,11 +1365,11 @@ private:
std::vector<std::string> defaultUserKeys; std::vector<std::string> defaultUserKeys;
}; };
int NetworkState::send(Context *ctx, BNCSOutputStream *buf) { int OnlineState::send(Context *ctx, BNCSOutputStream *buf) {
return buf->flush(ctx->getTCPSocket()); return buf->flush(ctx->getTCPSocket());
} }
class DisconnectedState : public NetworkState { class DisconnectedState : public OnlineState {
public: public:
DisconnectedState(std::string message) { DisconnectedState(std::string message) {
this->message = message; this->message = message;
@ -1386,7 +1386,7 @@ private:
std::string message; std::string message;
}; };
class S2C_CHATEVENT : public NetworkState { class S2C_CHATEVENT : public OnlineState {
public: public:
S2C_CHATEVENT() { S2C_CHATEVENT() {
this->ticks = 0; this->ticks = 0;
@ -1620,7 +1620,7 @@ private:
uint64_t ticks; uint64_t ticks;
}; };
class S2C_ENTERCHAT : public NetworkState { class S2C_ENTERCHAT : public OnlineState {
virtual void doOneStep(Context *ctx) { virtual void doOneStep(Context *ctx) {
if (ctx->getTCPSocket()->HasDataToRead(0)) { if (ctx->getTCPSocket()->HasDataToRead(0)) {
uint8_t msg = ctx->getMsgIStream()->readMessageId(); uint8_t msg = ctx->getMsgIStream()->readMessageId();
@ -1662,7 +1662,7 @@ class S2C_ENTERCHAT : public NetworkState {
} }
}; };
class C2S_ENTERCHAT : public NetworkState { class C2S_ENTERCHAT : public OnlineState {
virtual void doOneStep(Context *ctx) { virtual void doOneStep(Context *ctx) {
// does all of enterchar, getchannellist, and first-join joinchannel // does all of enterchar, getchannellist, and first-join joinchannel
BNCSOutputStream enterchat(0x0a); BNCSOutputStream enterchat(0x0a);
@ -1686,11 +1686,11 @@ class C2S_ENTERCHAT : public NetworkState {
} }
}; };
class C2S_LOGONRESPONSE2_OR_C2S_CREATEACCOUNT : public NetworkState { class C2S_LOGONRESPONSE2_OR_C2S_CREATEACCOUNT : public OnlineState {
virtual void doOneStep(Context *ctx); virtual void doOneStep(Context *ctx);
}; };
class S2C_CREATEACCOUNT2 : public NetworkState { class S2C_CREATEACCOUNT2 : public OnlineState {
virtual void doOneStep(Context *ctx) { virtual void doOneStep(Context *ctx) {
if (ctx->getTCPSocket()->HasDataToRead(0)) { if (ctx->getTCPSocket()->HasDataToRead(0)) {
uint8_t msg = ctx->getMsgIStream()->readMessageId(); uint8_t msg = ctx->getMsgIStream()->readMessageId();
@ -1754,7 +1754,7 @@ class S2C_CREATEACCOUNT2 : public NetworkState {
} }
}; };
class S2C_LOGONRESPONSE2 : public NetworkState { class S2C_LOGONRESPONSE2 : public OnlineState {
virtual void doOneStep(Context *ctx) { virtual void doOneStep(Context *ctx) {
if (ctx->getTCPSocket()->HasDataToRead(0)) { if (ctx->getTCPSocket()->HasDataToRead(0)) {
uint8_t msg = ctx->getMsgIStream()->readMessageId(); uint8_t msg = ctx->getMsgIStream()->readMessageId();
@ -1859,7 +1859,7 @@ void C2S_LOGONRESPONSE2_OR_C2S_CREATEACCOUNT::doOneStep(Context *ctx) {
} }
}; };
class S2C_SID_AUTH_CHECK : public NetworkState { class S2C_SID_AUTH_CHECK : public OnlineState {
virtual void doOneStep(Context *ctx) { virtual void doOneStep(Context *ctx) {
if (ctx->getTCPSocket()->HasDataToRead(0)) { if (ctx->getTCPSocket()->HasDataToRead(0)) {
uint8_t msg = ctx->getMsgIStream()->readMessageId(); uint8_t msg = ctx->getMsgIStream()->readMessageId();
@ -1921,7 +1921,7 @@ class S2C_SID_AUTH_CHECK : public NetworkState {
} }
}; };
class S2C_SID_AUTH_INFO : public NetworkState { class S2C_SID_AUTH_INFO : public OnlineState {
virtual void doOneStep(Context *ctx) { virtual void doOneStep(Context *ctx) {
if (ctx->getTCPSocket()->HasDataToRead(0)) { if (ctx->getTCPSocket()->HasDataToRead(0)) {
uint8_t msg = ctx->getMsgIStream()->readMessageId(); uint8_t msg = ctx->getMsgIStream()->readMessageId();
@ -1985,7 +1985,7 @@ class S2C_SID_AUTH_INFO : public NetworkState {
} }
}; };
class S2C_SID_PING : public NetworkState { class S2C_SID_PING : public OnlineState {
virtual void doOneStep(Context *ctx) { virtual void doOneStep(Context *ctx) {
if (ctx->getTCPSocket()->HasDataToRead(0)) { if (ctx->getTCPSocket()->HasDataToRead(0)) {
uint8_t msg = ctx->getMsgIStream()->readMessageId(); uint8_t msg = ctx->getMsgIStream()->readMessageId();
@ -2015,7 +2015,7 @@ class S2C_SID_PING : public NetworkState {
} }
}; };
class ConnectState : public NetworkState { class ConnectState : public OnlineState {
virtual void doOneStep(Context *ctx) { virtual void doOneStep(Context *ctx) {
// Connect // Connect

View file

@ -274,25 +274,38 @@ static void setDpiAware() {
userDLL = SDL_LoadObject("USER32.DLL"); userDLL = SDL_LoadObject("USER32.DLL");
if (userDLL) { if (userDLL) {
SetProcessDPIAware = (BOOL(WINAPI *)(void)) SDL_LoadFunction(userDLL, "SetProcessDPIAware"); SetProcessDPIAware = (BOOL(WINAPI *)(void)) SDL_LoadFunction(userDLL, "SetProcessDPIAware");
} else {
SetProcessDPIAware = NULL;
} }
shcoreDLL = SDL_LoadObject("SHCORE.DLL"); shcoreDLL = SDL_LoadObject("SHCORE.DLL");
if (shcoreDLL) { if (shcoreDLL) {
SetProcessDpiAwareness = (HRESULT(WINAPI *)(PROCESS_DPI_AWARENESS)) SDL_LoadFunction(shcoreDLL, "SetProcessDpiAwareness"); SetProcessDpiAwareness = (HRESULT(WINAPI *)(PROCESS_DPI_AWARENESS)) SDL_LoadFunction(shcoreDLL, "SetProcessDpiAwareness");
} else {
SetProcessDpiAwareness = NULL;
} }
if (SetProcessDpiAwareness) { if (SetProcessDpiAwareness) {
/* Try Windows 8.1+ version */ /* Try Windows 8.1+ version */
HRESULT result = SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE); HRESULT result = SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
DebugPrint("called SetProcessDpiAwareness: %d" _C_ (result == S_OK) ? 1 : 0); DebugPrint("called SetProcessDpiAwareness: %d" _C_ (result == S_OK) ? 1 : 0);
} else {
if (SetProcessDPIAware) {
/* Try Vista - Windows 8 version.
This has a constant scale factor for all monitors.
*/
BOOL success = SetProcessDPIAware();
DebugPrint("called SetProcessDPIAware: %d" _C_ (int)success);
}
// In any case, on these old Windows versions we have to do a bit of
// compatibility hacking. Windows 7 and below don't play well with
// opengl rendering and (for some odd reason) fullscreen.
fprintf(stdout, "\n!!! Detected old Windows version - forcing software renderer and windowed mode !!!\n\n");
SDL_SetHintWithPriority(SDL_HINT_RENDER_DRIVER, "software", SDL_HINT_OVERRIDE);
VideoForceFullScreen = 1;
Video.FullScreen = 0;
} }
else if (SetProcessDPIAware) {
/* Try Vista - Windows 8 version.
This has a constant scale factor for all monitors.
*/
BOOL success = SetProcessDPIAware();
DebugPrint("called SetProcessDPIAware: %d" _C_ (int)success);
}
} }
#else #else
static void setDpiAware() { static void setDpiAware() {
@ -333,6 +346,8 @@ void InitVideoSdl()
// Initialize the display // Initialize the display
setDpiAware();
// Sam said: better for windows. // Sam said: better for windows.
/* SDL_HWSURFACE|SDL_HWPALETTE | */ /* SDL_HWSURFACE|SDL_HWPALETTE | */
if (Video.FullScreen) { if (Video.FullScreen) {
@ -363,8 +378,6 @@ void InitVideoSdl()
win_title = Parameters::Instance.applicationName.c_str(); win_title = Parameters::Instance.applicationName.c_str();
} }
setDpiAware();
TheWindow = SDL_CreateWindow(win_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, TheWindow = SDL_CreateWindow(win_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
Video.WindowWidth, Video.WindowHeight, flags); Video.WindowWidth, Video.WindowHeight, flags);
if (TheWindow == NULL) { if (TheWindow == NULL) {
@ -375,7 +388,7 @@ void InitVideoSdl()
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"); SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl");
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0"); SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0");
if (!TheRenderer) { if (!TheRenderer) {
TheRenderer = SDL_CreateRenderer(TheWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE); TheRenderer = SDL_CreateRenderer(TheWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE | SDL_RENDERER_PRESENTVSYNC);
} }
SDL_RendererInfo rendererInfo; SDL_RendererInfo rendererInfo;
SDL_GetRendererInfo(TheRenderer, &rendererInfo); SDL_GetRendererInfo(TheRenderer, &rendererInfo);