mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Moved remaining render-related code from CMT
This commit is contained in:
parent
c688411bab
commit
28f41bb472
@ -36,13 +36,17 @@
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
#include <vstd/StringUtils.h>
|
||||
#include <SDL.h>
|
||||
#include <SDL_events.h>
|
||||
#include <SDL_hints.h>
|
||||
#include <SDL_main.h>
|
||||
|
||||
#ifdef VCMI_WINDOWS
|
||||
#include <SDL_syswm.h>
|
||||
#endif
|
||||
|
||||
#ifdef VCMI_ANDROID
|
||||
#include "../lib/CAndroidVMHelper.h"
|
||||
#include <SDL_system.h>
|
||||
#endif
|
||||
|
||||
#if __MINGW32__
|
||||
@ -53,25 +57,13 @@ namespace po = boost::program_options;
|
||||
namespace po_style = boost::program_options::command_line_style;
|
||||
namespace bfs = boost::filesystem;
|
||||
|
||||
CGuiHandler GH;
|
||||
|
||||
SDL_Window * mainWindow = nullptr;
|
||||
SDL_Renderer * mainRenderer = nullptr;
|
||||
SDL_Texture * screenTexture = nullptr;
|
||||
|
||||
extern boost::thread_specific_ptr<bool> inGuiThread;
|
||||
|
||||
SDL_Surface *screen = nullptr, //main screen surface
|
||||
*screen2 = nullptr, //and hlp surface (used to store not-active interfaces layer)
|
||||
*screenBuf = screen; //points to screen (if only advmapint is present) or screen2 (else) - should be used when updating controls which are not regularly redrawed
|
||||
|
||||
std::queue<SDL_Event> SDLEventsQueue;
|
||||
boost::mutex eventsM;
|
||||
|
||||
static po::variables_map vm;
|
||||
|
||||
//static bool setResolution = false; //set by event handling thread after resolution is adjusted
|
||||
|
||||
#ifndef VCMI_IOS
|
||||
void processCommand(const std::string &message);
|
||||
#endif
|
||||
@ -356,9 +348,7 @@ int main(int argc, char * argv[])
|
||||
{
|
||||
if(!vm.count("battle") && !vm.count("nointro") && settings["video"]["showIntro"].Bool())
|
||||
playIntro();
|
||||
SDL_SetRenderDrawColor(mainRenderer, 0, 0, 0, 255);
|
||||
SDL_RenderClear(mainRenderer);
|
||||
SDL_RenderPresent(mainRenderer);
|
||||
GH.windowHandler().clearScreen();
|
||||
}
|
||||
|
||||
|
||||
|
@ -39,6 +39,8 @@
|
||||
#include "ios/utils.h"
|
||||
#endif
|
||||
|
||||
CGuiHandler GH;
|
||||
|
||||
extern std::queue<SDL_Event> SDLEventsQueue;
|
||||
extern boost::mutex eventsM;
|
||||
|
||||
|
@ -17,8 +17,19 @@
|
||||
#include "CMT.h"
|
||||
#include "SDL_Extensions.h"
|
||||
|
||||
#ifdef VCMI_ANDROID
|
||||
#include "../lib/CAndroidVMHelper.h"
|
||||
#endif
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
SDL_Window * mainWindow = nullptr;
|
||||
SDL_Renderer * mainRenderer = nullptr;
|
||||
SDL_Texture * screenTexture = nullptr;
|
||||
SDL_Surface * screen = nullptr; //main screen surface
|
||||
SDL_Surface * screen2 = nullptr; //and hlp surface (used to store not-active interfaces layer)
|
||||
SDL_Surface * screenBuf = screen; //points to screen (if only advmapint is present) or screen2 (else) - should be used when updating controls which are not regularly redrawed
|
||||
|
||||
static const std::string NAME_AFFIX = "client";
|
||||
static const std::string NAME = GameConstants::VCMI_VERSION + std::string(" (") + NAME_AFFIX + ')'; //application name
|
||||
|
||||
@ -229,14 +240,12 @@ void WindowHandler::initializeScreen()
|
||||
}
|
||||
|
||||
screenBuf = screen;
|
||||
|
||||
SDL_SetRenderDrawColor(mainRenderer, 0, 0, 0, 0);
|
||||
SDL_RenderClear(mainRenderer);
|
||||
SDL_RenderPresent(mainRenderer);
|
||||
clearScreen();
|
||||
}
|
||||
|
||||
SDL_Window * WindowHandler::createWindowImpl(Point dimensions, int displayIndex, int flags, bool center)
|
||||
SDL_Window * WindowHandler::createWindowImpl(Point dimensions, int flags, bool center)
|
||||
{
|
||||
int displayIndex = getPreferredDisplayIndex();
|
||||
int positionFlags = center ? SDL_WINDOWPOS_CENTERED_DISPLAY(displayIndex) : SDL_WINDOWPOS_UNDEFINED_DISPLAY(displayIndex);
|
||||
|
||||
return SDL_CreateWindow(NAME.c_str(), positionFlags, positionFlags, dimensions.x, dimensions.y, flags);
|
||||
@ -245,19 +254,22 @@ SDL_Window * WindowHandler::createWindowImpl(Point dimensions, int displayIndex,
|
||||
SDL_Window * WindowHandler::createWindow()
|
||||
{
|
||||
#ifndef VCMI_MOBILE
|
||||
const JsonNode & video = settings["video"];
|
||||
int displayIndex = video["displayIndex"].Float();
|
||||
bool fullscreen = video["fullscreen"].Bool();
|
||||
bool realFullscreen = video["realFullscreen"].Bool();
|
||||
Point dimensions = getPreferredRenderingResolution();
|
||||
|
||||
if(!fullscreen)
|
||||
return createWindowImpl(dimensions, displayIndex, 0, true);
|
||||
switch(getPreferredWindowMode())
|
||||
{
|
||||
case EWindowMode::FULLSCREEN_TRUE:
|
||||
return createWindowImpl(dimensions, SDL_WINDOW_FULLSCREEN, false);
|
||||
|
||||
if(realFullscreen)
|
||||
return createWindowImpl(dimensions, displayIndex, SDL_WINDOW_FULLSCREEN, false);
|
||||
else
|
||||
return createWindowImpl(Point(), displayIndex, SDL_WINDOW_FULLSCREEN_DESKTOP, false);
|
||||
case EWindowMode::FULLSCREEN_WINDOWED:
|
||||
return createWindowImpl(Point(), SDL_WINDOW_FULLSCREEN_DESKTOP, false);
|
||||
|
||||
case EWindowMode::WINDOWED:
|
||||
return createWindowImpl(dimensions, 0, true);
|
||||
|
||||
default:
|
||||
return nullptr;
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef VCMI_IOS
|
||||
@ -266,17 +278,17 @@ SDL_Window * WindowHandler::createWindow()
|
||||
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "best");
|
||||
|
||||
uint32_t windowFlags = SDL_WINDOW_BORDERLESS | SDL_WINDOW_ALLOW_HIGHDPI;
|
||||
SDL_Window * result = createWindowImpl(Point(), displayIndex, windowFlags | SDL_WINDOW_METAL, false);
|
||||
SDL_Window * result = createWindowImpl(Point(), windowFlags | SDL_WINDOW_METAL, false);
|
||||
|
||||
if(result != nullptr)
|
||||
return result;
|
||||
|
||||
logGlobal->warn("Metal unavailable, using OpenGLES");
|
||||
return createWindowImpl(Point(), displayIndex, windowFlags, false);
|
||||
return createWindowImpl(Point(), windowFlags, false);
|
||||
#endif
|
||||
|
||||
#ifdef VCMI_ANDROID
|
||||
return createWindowImpl(Point(), displayIndex, SDL_WINDOW_FULLSCREEN, false);
|
||||
return createWindowImpl(Point(), SDL_WINDOW_FULLSCREEN, false);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -405,3 +417,10 @@ void WindowHandler::close()
|
||||
destroyWindow();
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
void WindowHandler::clearScreen()
|
||||
{
|
||||
SDL_SetRenderDrawColor(mainRenderer, 0, 0, 0, 255);
|
||||
SDL_RenderClear(mainRenderer);
|
||||
SDL_RenderPresent(mainRenderer);
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ class WindowHandler
|
||||
int getPreferredRenderingDriver() const;
|
||||
|
||||
/// Creates SDL window with specified parameters
|
||||
SDL_Window * createWindowImpl(Point dimensions, int displayIndex, int flags, bool center);
|
||||
SDL_Window * createWindowImpl(Point dimensions, int flags, bool center);
|
||||
|
||||
/// Creates SDL window using OS-specific settings & user-specific config
|
||||
SDL_Window * createWindow();
|
||||
@ -71,4 +71,7 @@ public:
|
||||
|
||||
/// De-initializes and destroys screen, window and SDL state
|
||||
void close();
|
||||
|
||||
/// Fills screen with black color, erasing any existing content
|
||||
void clearScreen();
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user