2019-12-17 08:03:41 -06:00
|
|
|
#include "Config.h"
|
2019-12-21 15:17:37 -06:00
|
|
|
#include "common/tpt-minmax.h"
|
2019-12-17 08:03:41 -06:00
|
|
|
|
2012-07-06 10:53:59 -05:00
|
|
|
#include <map>
|
2016-07-17 22:37:24 -05:00
|
|
|
#include <ctime>
|
2017-11-15 19:07:00 -06:00
|
|
|
#include <climits>
|
2012-07-29 11:14:14 -05:00
|
|
|
#ifdef WIN
|
2012-08-08 11:42:04 -05:00
|
|
|
#include <direct.h>
|
2012-01-29 11:54:53 -06:00
|
|
|
#endif
|
2016-10-13 21:32:52 -05:00
|
|
|
#include "SDLCompat.h"
|
2017-02-20 18:15:41 -06:00
|
|
|
|
|
|
|
#ifdef X86_SSE
|
2017-02-19 18:29:41 -06:00
|
|
|
#include <xmmintrin.h>
|
2017-02-20 18:15:41 -06:00
|
|
|
#endif
|
|
|
|
#ifdef X86_SSE3
|
2017-02-19 18:29:41 -06:00
|
|
|
#include <pmmintrin.h>
|
2017-02-20 18:15:41 -06:00
|
|
|
#endif
|
|
|
|
|
2012-01-14 12:51:24 -06:00
|
|
|
#include <iostream>
|
2012-01-08 11:39:03 -06:00
|
|
|
#include "Config.h"
|
2012-07-29 10:55:26 -05:00
|
|
|
#if defined(LIN)
|
2012-01-29 11:54:53 -06:00
|
|
|
#include "icon.h"
|
|
|
|
#endif
|
2019-01-07 00:08:52 -06:00
|
|
|
#include <csignal>
|
2016-01-25 23:24:14 -06:00
|
|
|
#include <stdexcept>
|
2012-01-08 11:39:03 -06:00
|
|
|
|
2012-08-08 11:42:04 -05:00
|
|
|
#ifndef WIN
|
2019-12-17 08:03:41 -06:00
|
|
|
# include <unistd.h>
|
2012-08-08 11:42:04 -05:00
|
|
|
#endif
|
2019-01-12 11:08:18 -06:00
|
|
|
#ifdef MACOSX
|
2019-12-17 08:03:41 -06:00
|
|
|
# ifdef DEBUG
|
|
|
|
# undef DEBUG
|
|
|
|
# define DEBUG 1
|
|
|
|
# endif
|
|
|
|
# include <CoreServices/CoreServices.h>
|
2019-01-12 11:08:18 -06:00
|
|
|
#endif
|
2020-06-06 06:40:08 -05:00
|
|
|
#include <sys/stat.h>
|
2012-08-08 11:42:04 -05:00
|
|
|
|
|
|
|
#include "Format.h"
|
2019-04-20 07:12:32 -05:00
|
|
|
#include "Misc.h"
|
|
|
|
|
|
|
|
#include "graphics/Graphics.h"
|
2012-08-12 16:32:57 -05:00
|
|
|
|
2019-04-20 07:12:32 -05:00
|
|
|
#include "client/SaveInfo.h"
|
2012-08-13 09:43:57 -05:00
|
|
|
#include "client/GameSave.h"
|
2012-08-17 10:08:03 -05:00
|
|
|
#include "client/SaveFile.h"
|
2012-06-21 19:04:55 -05:00
|
|
|
#include "client/Client.h"
|
2012-01-08 11:39:03 -06:00
|
|
|
|
2013-03-22 09:14:17 -05:00
|
|
|
#include "gui/game/GameController.h"
|
|
|
|
#include "gui/game/GameView.h"
|
|
|
|
#include "gui/dialogues/ErrorMessage.h"
|
2016-01-31 21:30:39 -06:00
|
|
|
#include "gui/dialogues/ConfirmPrompt.h"
|
2013-03-22 09:14:17 -05:00
|
|
|
#include "gui/interface/Keys.h"
|
|
|
|
#include "gui/Style.h"
|
2019-04-20 07:12:32 -05:00
|
|
|
#include "gui/interface/Engine.h"
|
2012-01-29 08:44:36 -06:00
|
|
|
|
2016-10-14 08:30:29 -05:00
|
|
|
#define INCLUDE_SYSWM
|
|
|
|
#include "SDLCompat.h"
|
2013-01-18 13:37:24 -06:00
|
|
|
|
2012-09-05 11:31:49 -05:00
|
|
|
int desktopWidth = 1280, desktopHeight = 1024;
|
|
|
|
|
upgrade to SDL 2
Still currently in process, there are some issues:
Windows version doesn't work, mac version might not work, opengl might not work
Icon doesn't work (on Linux at least)
Lua will need some changes, there are some sdl 1.2 hacks in there
When entering fullscreen, the window loses focus
When holding down mouse out of bounds, mouse move events stop being sent
When letting go of mouse out of bounds, mouseup event doesn't take into account double scale mode
Clicking on startup without moving mouse will draw at 0,0 for a frame
Renderer probably won't compile because USE_SDL doesn't entirely work
... and maybe others
Some nice things were done though:
no more blit2, sdl can do the scaling itself
3d effect removed, no reason to support this joke any longer
No need to support copy/paste ourselves, sdl does it now
text handling done much better now, separate events for key presses and text input
when a new window is shown, all events ignored until next tick (ignore textinput event if window shown from key press event like console)
2018-04-15 17:53:02 -05:00
|
|
|
SDL_Window * sdl_window;
|
|
|
|
SDL_Renderer * sdl_renderer;
|
|
|
|
SDL_Texture * sdl_texture;
|
2012-08-08 08:35:27 -05:00
|
|
|
int scale = 1;
|
|
|
|
bool fullscreen = false;
|
2018-05-19 15:50:47 -05:00
|
|
|
bool altFullscreen = false;
|
2019-02-18 21:18:29 -06:00
|
|
|
bool forceIntegerScaling = true;
|
2018-05-19 15:50:47 -05:00
|
|
|
bool resizable = false;
|
2020-10-10 14:57:29 -05:00
|
|
|
bool momentumScroll = true;
|
2012-05-30 06:32:58 -05:00
|
|
|
|
2018-04-22 21:14:06 -05:00
|
|
|
|
2018-04-30 13:13:24 -05:00
|
|
|
void ClipboardPush(ByteString text)
|
2013-01-18 13:37:24 -06:00
|
|
|
{
|
upgrade to SDL 2
Still currently in process, there are some issues:
Windows version doesn't work, mac version might not work, opengl might not work
Icon doesn't work (on Linux at least)
Lua will need some changes, there are some sdl 1.2 hacks in there
When entering fullscreen, the window loses focus
When holding down mouse out of bounds, mouse move events stop being sent
When letting go of mouse out of bounds, mouseup event doesn't take into account double scale mode
Clicking on startup without moving mouse will draw at 0,0 for a frame
Renderer probably won't compile because USE_SDL doesn't entirely work
... and maybe others
Some nice things were done though:
no more blit2, sdl can do the scaling itself
3d effect removed, no reason to support this joke any longer
No need to support copy/paste ourselves, sdl does it now
text handling done much better now, separate events for key presses and text input
when a new window is shown, all events ignored until next tick (ignore textinput event if window shown from key press event like console)
2018-04-15 17:53:02 -05:00
|
|
|
SDL_SetClipboardText(text.c_str());
|
2013-01-18 13:37:24 -06:00
|
|
|
}
|
|
|
|
|
2018-04-30 13:13:24 -05:00
|
|
|
ByteString ClipboardPull()
|
2013-01-18 13:37:24 -06:00
|
|
|
{
|
upgrade to SDL 2
Still currently in process, there are some issues:
Windows version doesn't work, mac version might not work, opengl might not work
Icon doesn't work (on Linux at least)
Lua will need some changes, there are some sdl 1.2 hacks in there
When entering fullscreen, the window loses focus
When holding down mouse out of bounds, mouse move events stop being sent
When letting go of mouse out of bounds, mouseup event doesn't take into account double scale mode
Clicking on startup without moving mouse will draw at 0,0 for a frame
Renderer probably won't compile because USE_SDL doesn't entirely work
... and maybe others
Some nice things were done though:
no more blit2, sdl can do the scaling itself
3d effect removed, no reason to support this joke any longer
No need to support copy/paste ourselves, sdl does it now
text handling done much better now, separate events for key presses and text input
when a new window is shown, all events ignored until next tick (ignore textinput event if window shown from key press event like console)
2018-04-15 17:53:02 -05:00
|
|
|
return ByteString(SDL_GetClipboardText());
|
2013-01-18 13:37:24 -06:00
|
|
|
}
|
|
|
|
|
2018-04-22 21:14:06 -05:00
|
|
|
int GetModifiers()
|
|
|
|
{
|
|
|
|
return SDL_GetModState();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoadWindowPosition()
|
|
|
|
{
|
|
|
|
int savedWindowX = Client::Ref().GetPrefInteger("WindowX", INT_MAX);
|
|
|
|
int savedWindowY = Client::Ref().GetPrefInteger("WindowY", INT_MAX);
|
2018-05-26 16:38:01 -05:00
|
|
|
|
|
|
|
int borderTop, borderLeft;
|
|
|
|
SDL_GetWindowBordersSize(sdl_window, &borderTop, &borderLeft, nullptr, nullptr);
|
2019-02-18 21:18:29 -06:00
|
|
|
// Sometimes (Windows), the border size may not be reported for 200+ frames
|
|
|
|
// So just have a default of 5 to ensure the window doesn't get stuck where it can't be moved
|
|
|
|
if (borderTop == 0)
|
|
|
|
borderTop = 5;
|
2018-05-26 16:38:01 -05:00
|
|
|
|
2019-03-24 22:17:09 -05:00
|
|
|
int numDisplays = SDL_GetNumVideoDisplays();
|
|
|
|
SDL_Rect displayBounds;
|
|
|
|
bool ok = false;
|
|
|
|
for (int i = 0; i < numDisplays; i++)
|
|
|
|
{
|
|
|
|
SDL_GetDisplayBounds(i, &displayBounds);
|
|
|
|
if (savedWindowX + borderTop > displayBounds.x && savedWindowY + borderLeft > displayBounds.y &&
|
|
|
|
savedWindowX + borderTop < displayBounds.x + displayBounds.w &&
|
|
|
|
savedWindowY + borderLeft < displayBounds.y + displayBounds.h)
|
|
|
|
{
|
|
|
|
ok = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ok)
|
2018-05-28 12:33:01 -05:00
|
|
|
SDL_SetWindowPosition(sdl_window, savedWindowX + borderLeft, savedWindowY + borderTop);
|
2018-04-22 21:14:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void SaveWindowPosition()
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
SDL_GetWindowPosition(sdl_window, &x, &y);
|
|
|
|
|
|
|
|
int borderTop, borderLeft;
|
|
|
|
SDL_GetWindowBordersSize(sdl_window, &borderTop, &borderLeft, nullptr, nullptr);
|
|
|
|
|
|
|
|
Client::Ref().SetPref("WindowX", x - borderLeft);
|
|
|
|
Client::Ref().SetPref("WindowY", y - borderTop);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CalculateMousePosition(int *x, int *y)
|
|
|
|
{
|
|
|
|
int globalMx, globalMy;
|
|
|
|
SDL_GetGlobalMouseState(&globalMx, &globalMy);
|
|
|
|
int windowX, windowY;
|
|
|
|
SDL_GetWindowPosition(sdl_window, &windowX, &windowY);
|
|
|
|
|
|
|
|
if (x)
|
|
|
|
*x = (globalMx - windowX) / scale;
|
|
|
|
if (y)
|
|
|
|
*y = (globalMy - windowY) / scale;
|
|
|
|
}
|
|
|
|
|
2012-06-23 08:59:07 -05:00
|
|
|
#ifdef OGLI
|
2012-05-30 06:32:58 -05:00
|
|
|
void blit()
|
|
|
|
{
|
|
|
|
SDL_GL_SwapBuffers();
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
void blit(pixel * vid)
|
|
|
|
{
|
upgrade to SDL 2
Still currently in process, there are some issues:
Windows version doesn't work, mac version might not work, opengl might not work
Icon doesn't work (on Linux at least)
Lua will need some changes, there are some sdl 1.2 hacks in there
When entering fullscreen, the window loses focus
When holding down mouse out of bounds, mouse move events stop being sent
When letting go of mouse out of bounds, mouseup event doesn't take into account double scale mode
Clicking on startup without moving mouse will draw at 0,0 for a frame
Renderer probably won't compile because USE_SDL doesn't entirely work
... and maybe others
Some nice things were done though:
no more blit2, sdl can do the scaling itself
3d effect removed, no reason to support this joke any longer
No need to support copy/paste ourselves, sdl does it now
text handling done much better now, separate events for key presses and text input
when a new window is shown, all events ignored until next tick (ignore textinput event if window shown from key press event like console)
2018-04-15 17:53:02 -05:00
|
|
|
SDL_UpdateTexture(sdl_texture, NULL, vid, WINDOWW * sizeof (Uint32));
|
2018-04-22 21:14:06 -05:00
|
|
|
// need to clear the renderer if there are black edges (fullscreen, or resizable window)
|
2018-05-19 15:50:47 -05:00
|
|
|
if (fullscreen || resizable)
|
2018-04-22 21:14:06 -05:00
|
|
|
SDL_RenderClear(sdl_renderer);
|
upgrade to SDL 2
Still currently in process, there are some issues:
Windows version doesn't work, mac version might not work, opengl might not work
Icon doesn't work (on Linux at least)
Lua will need some changes, there are some sdl 1.2 hacks in there
When entering fullscreen, the window loses focus
When holding down mouse out of bounds, mouse move events stop being sent
When letting go of mouse out of bounds, mouseup event doesn't take into account double scale mode
Clicking on startup without moving mouse will draw at 0,0 for a frame
Renderer probably won't compile because USE_SDL doesn't entirely work
... and maybe others
Some nice things were done though:
no more blit2, sdl can do the scaling itself
3d effect removed, no reason to support this joke any longer
No need to support copy/paste ourselves, sdl does it now
text handling done much better now, separate events for key presses and text input
when a new window is shown, all events ignored until next tick (ignore textinput event if window shown from key press event like console)
2018-04-15 17:53:02 -05:00
|
|
|
SDL_RenderCopy(sdl_renderer, sdl_texture, NULL, NULL);
|
|
|
|
SDL_RenderPresent(sdl_renderer);
|
2012-05-30 06:32:58 -05:00
|
|
|
}
|
2012-05-30 07:17:40 -05:00
|
|
|
#endif
|
2012-05-30 06:32:58 -05:00
|
|
|
|
2019-12-17 08:03:41 -06:00
|
|
|
bool RecreateWindow();
|
2020-06-06 06:40:08 -05:00
|
|
|
void SDLOpen()
|
2012-01-08 11:39:03 -06:00
|
|
|
{
|
2020-06-06 06:40:08 -05:00
|
|
|
if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
|
2012-01-08 11:39:03 -06:00
|
|
|
{
|
2020-06-06 06:40:08 -05:00
|
|
|
fprintf(stderr, "Initializing SDL (video subsystem): %s\n", SDL_GetError());
|
|
|
|
exit(-1);
|
2012-01-08 11:39:03 -06:00
|
|
|
}
|
upgrade to SDL 2
Still currently in process, there are some issues:
Windows version doesn't work, mac version might not work, opengl might not work
Icon doesn't work (on Linux at least)
Lua will need some changes, there are some sdl 1.2 hacks in there
When entering fullscreen, the window loses focus
When holding down mouse out of bounds, mouse move events stop being sent
When letting go of mouse out of bounds, mouseup event doesn't take into account double scale mode
Clicking on startup without moving mouse will draw at 0,0 for a frame
Renderer probably won't compile because USE_SDL doesn't entirely work
... and maybe others
Some nice things were done though:
no more blit2, sdl can do the scaling itself
3d effect removed, no reason to support this joke any longer
No need to support copy/paste ourselves, sdl does it now
text handling done much better now, separate events for key presses and text input
when a new window is shown, all events ignored until next tick (ignore textinput event if window shown from key press event like console)
2018-04-15 17:53:02 -05:00
|
|
|
|
2019-12-17 08:03:41 -06:00
|
|
|
if (!RecreateWindow())
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Creating SDL window: %s\n", SDL_GetError());
|
|
|
|
exit(-1);
|
|
|
|
}
|
2018-04-22 21:14:06 -05:00
|
|
|
|
2018-05-28 12:33:01 -05:00
|
|
|
int displayIndex = SDL_GetWindowDisplayIndex(sdl_window);
|
|
|
|
if (displayIndex >= 0)
|
|
|
|
{
|
2018-05-28 12:55:49 -05:00
|
|
|
SDL_Rect rect;
|
|
|
|
if (!SDL_GetDisplayUsableBounds(displayIndex, &rect))
|
|
|
|
{
|
|
|
|
desktopWidth = rect.w;
|
|
|
|
desktopHeight = rect.h;
|
|
|
|
}
|
2020-10-11 05:31:52 -05:00
|
|
|
if (Client::Ref().GetPrefBool("AutoDrawLimit", false))
|
2020-10-11 04:58:52 -05:00
|
|
|
{
|
2020-10-11 05:31:52 -05:00
|
|
|
SDL_DisplayMode displayMode;
|
|
|
|
if (!SDL_GetCurrentDisplayMode(displayIndex, &displayMode) && displayMode.refresh_rate >= 60)
|
|
|
|
{
|
|
|
|
ui::Engine::Ref().SetDrawingFrequencyLimit(displayMode.refresh_rate);
|
|
|
|
}
|
2020-10-11 04:58:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-05 22:47:31 -05:00
|
|
|
#ifdef WIN
|
|
|
|
SDL_SysWMinfo SysInfo;
|
|
|
|
SDL_VERSION(&SysInfo.version);
|
|
|
|
if(SDL_GetWindowWMInfo(sdl_window, &SysInfo) <= 0)
|
|
|
|
{
|
|
|
|
printf("%s : %p\n", SDL_GetError(), SysInfo.info.win.window);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
HWND WindowHandle = SysInfo.info.win.window;
|
|
|
|
|
|
|
|
// Use GetModuleHandle to get the Exe HMODULE/HINSTANCE
|
|
|
|
HMODULE hModExe = GetModuleHandle(NULL);
|
|
|
|
HICON hIconSmall = (HICON)LoadImage(hModExe, MAKEINTRESOURCE(101), IMAGE_ICON, 16, 16, LR_SHARED);
|
|
|
|
HICON hIconBig = (HICON)LoadImage(hModExe, MAKEINTRESOURCE(101), IMAGE_ICON, 32, 32, LR_SHARED);
|
|
|
|
SendMessage(WindowHandle, WM_SETICON, ICON_SMALL, (LPARAM)hIconSmall);
|
|
|
|
SendMessage(WindowHandle, WM_SETICON, ICON_BIG, (LPARAM)hIconBig);
|
|
|
|
#endif
|
2018-04-22 21:14:06 -05:00
|
|
|
#ifdef LIN
|
2019-01-20 11:53:39 -06:00
|
|
|
SDL_Surface *icon = SDL_CreateRGBSurfaceFrom((void*)app_icon, 128, 128, 32, 512, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
|
2018-04-22 21:14:06 -05:00
|
|
|
SDL_SetWindowIcon(sdl_window, icon);
|
|
|
|
SDL_FreeSurface(icon);
|
|
|
|
#endif
|
2012-08-08 08:35:27 -05:00
|
|
|
}
|
2012-04-22 11:13:43 -05:00
|
|
|
|
2019-02-18 21:18:29 -06:00
|
|
|
void SDLSetScreen(int scale_, bool resizable_, bool fullscreen_, bool altFullscreen_, bool forceIntegerScaling_)
|
2012-08-08 08:35:27 -05:00
|
|
|
{
|
2019-02-18 21:18:29 -06:00
|
|
|
// bool changingScale = scale != scale_;
|
2019-02-20 21:20:49 -06:00
|
|
|
bool changingFullscreen = fullscreen_ != fullscreen || (altFullscreen_ != altFullscreen && fullscreen);
|
2019-02-18 21:18:29 -06:00
|
|
|
bool changingResizable = resizable != resizable_;
|
2018-05-19 15:50:47 -05:00
|
|
|
scale = scale_;
|
|
|
|
fullscreen = fullscreen_;
|
|
|
|
altFullscreen = altFullscreen_;
|
|
|
|
resizable = resizable_;
|
2019-02-18 21:18:29 -06:00
|
|
|
forceIntegerScaling = forceIntegerScaling_;
|
|
|
|
// Recreate the window when toggling fullscreen, due to occasional issues
|
|
|
|
// Also recreate it when enabling resizable windows, to fix bugs on windows,
|
|
|
|
// see https://github.com/jacob1/The-Powder-Toy/issues/24
|
|
|
|
if (changingFullscreen || (changingResizable && resizable && !fullscreen))
|
|
|
|
{
|
|
|
|
RecreateWindow();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (changingResizable)
|
|
|
|
SDL_RestoreWindow(sdl_window);
|
|
|
|
|
2018-05-19 15:50:47 -05:00
|
|
|
SDL_SetWindowSize(sdl_window, WINDOWW * scale, WINDOWH * scale);
|
2019-02-18 21:18:29 -06:00
|
|
|
SDL_RenderSetIntegerScale(sdl_renderer, forceIntegerScaling && fullscreen ? SDL_TRUE : SDL_FALSE);
|
2018-05-19 15:50:47 -05:00
|
|
|
unsigned int flags = 0;
|
|
|
|
if (fullscreen)
|
|
|
|
flags = altFullscreen ? SDL_WINDOW_FULLSCREEN : SDL_WINDOW_FULLSCREEN_DESKTOP;
|
|
|
|
SDL_SetWindowFullscreen(sdl_window, flags);
|
|
|
|
if (fullscreen)
|
2018-04-22 19:09:44 -05:00
|
|
|
SDL_RaiseWindow(sdl_window);
|
2018-05-19 15:50:47 -05:00
|
|
|
SDL_SetWindowResizable(sdl_window, resizable ? SDL_TRUE : SDL_FALSE);
|
2016-04-01 23:10:15 -05:00
|
|
|
}
|
|
|
|
|
2019-12-17 08:03:41 -06:00
|
|
|
bool RecreateWindow()
|
2019-02-18 21:18:29 -06:00
|
|
|
{
|
|
|
|
unsigned int flags = 0;
|
|
|
|
if (fullscreen)
|
|
|
|
flags = altFullscreen ? SDL_WINDOW_FULLSCREEN : SDL_WINDOW_FULLSCREEN_DESKTOP;
|
|
|
|
if (resizable && !fullscreen)
|
|
|
|
flags |= SDL_WINDOW_RESIZABLE;
|
|
|
|
|
|
|
|
if (sdl_texture)
|
|
|
|
SDL_DestroyTexture(sdl_texture);
|
|
|
|
if (sdl_renderer)
|
|
|
|
SDL_DestroyRenderer(sdl_renderer);
|
|
|
|
if (sdl_window)
|
|
|
|
{
|
|
|
|
SaveWindowPosition();
|
|
|
|
SDL_DestroyWindow(sdl_window);
|
|
|
|
}
|
|
|
|
|
|
|
|
sdl_window = SDL_CreateWindow("The Powder Toy", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WINDOWW * scale, WINDOWH * scale,
|
|
|
|
flags);
|
|
|
|
sdl_renderer = SDL_CreateRenderer(sdl_window, -1, 0);
|
2019-12-17 08:03:41 -06:00
|
|
|
if (!sdl_renderer)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "SDL_CreateRenderer failed; available renderers:\n");
|
|
|
|
int num = SDL_GetNumRenderDrivers();
|
|
|
|
for (int i = 0; i < num; ++i)
|
|
|
|
{
|
|
|
|
SDL_RendererInfo info;
|
|
|
|
SDL_GetRenderDriverInfo(i, &info);
|
|
|
|
fprintf(stderr, " - %s\n", info.name);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2019-02-18 21:18:29 -06:00
|
|
|
SDL_RenderSetLogicalSize(sdl_renderer, WINDOWW, WINDOWH);
|
|
|
|
if (forceIntegerScaling && fullscreen)
|
|
|
|
SDL_RenderSetIntegerScale(sdl_renderer, SDL_TRUE);
|
|
|
|
sdl_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, WINDOWW, WINDOWH);
|
|
|
|
SDL_RaiseWindow(sdl_window);
|
|
|
|
//Uncomment this to enable resizing
|
|
|
|
//SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
|
|
|
|
//SDL_SetWindowResizable(sdl_window, SDL_TRUE);
|
|
|
|
|
|
|
|
if (!Client::Ref().IsFirstRun())
|
|
|
|
LoadWindowPosition();
|
2019-12-17 08:03:41 -06:00
|
|
|
|
|
|
|
return true;
|
2019-02-18 21:18:29 -06:00
|
|
|
}
|
|
|
|
|
2016-07-23 18:15:07 -05:00
|
|
|
unsigned int GetTicks()
|
|
|
|
{
|
|
|
|
return SDL_GetTicks();
|
|
|
|
}
|
|
|
|
|
2018-04-30 13:13:24 -05:00
|
|
|
std::map<ByteString, ByteString> readArguments(int argc, char * argv[])
|
2012-07-06 10:53:59 -05:00
|
|
|
{
|
2018-04-30 13:13:24 -05:00
|
|
|
std::map<ByteString, ByteString> arguments;
|
2012-07-06 10:53:59 -05:00
|
|
|
|
2012-11-16 17:20:48 -06:00
|
|
|
//Defaults
|
2012-07-06 10:53:59 -05:00
|
|
|
arguments["scale"] = "";
|
|
|
|
arguments["proxy"] = "";
|
2012-11-16 17:20:48 -06:00
|
|
|
arguments["nohud"] = "false"; //the nohud, sound, and scripts commands currently do nothing.
|
2012-07-06 10:53:59 -05:00
|
|
|
arguments["sound"] = "false";
|
|
|
|
arguments["kiosk"] = "false";
|
2019-04-05 13:48:05 -05:00
|
|
|
arguments["redirect"] = "false";
|
2012-07-06 10:53:59 -05:00
|
|
|
arguments["scripts"] = "false";
|
|
|
|
arguments["open"] = "";
|
|
|
|
arguments["ddir"] = "";
|
|
|
|
arguments["ptsave"] = "";
|
2019-12-17 08:03:41 -06:00
|
|
|
arguments["font"] = "";
|
2012-07-06 10:53:59 -05:00
|
|
|
|
|
|
|
for (int i=1; i<argc; i++)
|
|
|
|
{
|
|
|
|
if (!strncmp(argv[i], "scale:", 6) && argv[i]+6)
|
|
|
|
{
|
2018-04-30 13:13:24 -05:00
|
|
|
arguments["scale"] = argv[i]+6;
|
2012-07-06 10:53:59 -05:00
|
|
|
}
|
2019-12-17 08:03:41 -06:00
|
|
|
if (!strncmp(argv[i], "font:", 5) && argv[i]+5)
|
|
|
|
{
|
|
|
|
arguments["font"] = argv[i]+5;
|
|
|
|
}
|
2012-08-08 12:34:37 -05:00
|
|
|
else if (!strncmp(argv[i], "proxy:", 6))
|
2012-07-06 10:53:59 -05:00
|
|
|
{
|
2012-08-08 12:34:37 -05:00
|
|
|
if(argv[i]+6)
|
2018-04-30 13:13:24 -05:00
|
|
|
arguments["proxy"] = argv[i]+6;
|
2012-08-08 12:34:37 -05:00
|
|
|
else
|
|
|
|
arguments["proxy"] = "false";
|
2012-07-06 10:53:59 -05:00
|
|
|
}
|
|
|
|
else if (!strncmp(argv[i], "nohud", 5))
|
|
|
|
{
|
|
|
|
arguments["nohud"] = "true";
|
|
|
|
}
|
|
|
|
else if (!strncmp(argv[i], "kiosk", 5))
|
|
|
|
{
|
|
|
|
arguments["kiosk"] = "true";
|
|
|
|
}
|
2019-04-05 13:48:05 -05:00
|
|
|
else if (!strncmp(argv[i], "redirect", 8))
|
|
|
|
{
|
|
|
|
arguments["redirect"] = "true";
|
|
|
|
}
|
2012-07-06 10:53:59 -05:00
|
|
|
else if (!strncmp(argv[i], "sound", 5))
|
|
|
|
{
|
|
|
|
arguments["sound"] = "true";
|
|
|
|
}
|
|
|
|
else if (!strncmp(argv[i], "scripts", 8))
|
|
|
|
{
|
|
|
|
arguments["scripts"] = "true";
|
|
|
|
}
|
|
|
|
else if (!strncmp(argv[i], "open", 5) && i+1<argc)
|
|
|
|
{
|
2018-04-30 13:13:24 -05:00
|
|
|
arguments["open"] = argv[i+1];
|
2012-07-06 10:53:59 -05:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
else if (!strncmp(argv[i], "ddir", 5) && i+1<argc)
|
|
|
|
{
|
2018-04-30 13:13:24 -05:00
|
|
|
arguments["ddir"] = argv[i+1];
|
2012-07-06 10:53:59 -05:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
else if (!strncmp(argv[i], "ptsave", 7) && i+1<argc)
|
|
|
|
{
|
2018-04-30 13:13:24 -05:00
|
|
|
arguments["ptsave"] = argv[i+1];
|
2012-07-06 10:53:59 -05:00
|
|
|
i++;
|
|
|
|
break;
|
|
|
|
}
|
2019-07-22 21:46:32 -05:00
|
|
|
else if (!strncmp(argv[i], "disable-network", 16))
|
|
|
|
{
|
|
|
|
arguments["disable-network"] = "true";
|
|
|
|
}
|
2012-07-06 10:53:59 -05:00
|
|
|
}
|
|
|
|
return arguments;
|
|
|
|
}
|
|
|
|
|
2012-08-18 16:08:20 -05:00
|
|
|
int elapsedTime = 0, currentTime = 0, lastTime = 0, currentFrame = 0;
|
|
|
|
unsigned int lastTick = 0;
|
2018-06-04 22:48:40 -05:00
|
|
|
unsigned int lastFpsUpdate = 0;
|
|
|
|
float fps = 0;
|
2012-08-18 16:08:20 -05:00
|
|
|
ui::Engine * engine = NULL;
|
2019-12-21 10:39:32 -06:00
|
|
|
bool showLargeScreenDialog = false;
|
2012-11-16 15:50:02 -06:00
|
|
|
float currentWidth, currentHeight;
|
2013-10-24 15:46:41 -05:00
|
|
|
|
2018-04-22 19:09:44 -05:00
|
|
|
int mousex = 0, mousey = 0;
|
|
|
|
int mouseButton = 0;
|
|
|
|
bool mouseDown = false;
|
|
|
|
|
2018-04-22 21:14:06 -05:00
|
|
|
bool calculatedInitialMouse = false, delay = false;
|
|
|
|
bool hasMouseMoved = false;
|
|
|
|
|
2013-10-24 15:46:41 -05:00
|
|
|
void EventProcess(SDL_Event event)
|
|
|
|
{
|
|
|
|
switch (event.type)
|
|
|
|
{
|
|
|
|
case SDL_QUIT:
|
|
|
|
if (engine->GetFastQuit() || engine->CloseWindow())
|
|
|
|
engine->Exit();
|
|
|
|
break;
|
|
|
|
case SDL_KEYDOWN:
|
2021-03-08 14:09:35 -06:00
|
|
|
if (SDL_GetModState() & KMOD_GUI)
|
2021-03-08 13:42:44 -06:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
upgrade to SDL 2
Still currently in process, there are some issues:
Windows version doesn't work, mac version might not work, opengl might not work
Icon doesn't work (on Linux at least)
Lua will need some changes, there are some sdl 1.2 hacks in there
When entering fullscreen, the window loses focus
When holding down mouse out of bounds, mouse move events stop being sent
When letting go of mouse out of bounds, mouseup event doesn't take into account double scale mode
Clicking on startup without moving mouse will draw at 0,0 for a frame
Renderer probably won't compile because USE_SDL doesn't entirely work
... and maybe others
Some nice things were done though:
no more blit2, sdl can do the scaling itself
3d effect removed, no reason to support this joke any longer
No need to support copy/paste ourselves, sdl does it now
text handling done much better now, separate events for key presses and text input
when a new window is shown, all events ignored until next tick (ignore textinput event if window shown from key press event like console)
2018-04-15 17:53:02 -05:00
|
|
|
if (!event.key.repeat && event.key.keysym.sym == 'q' && (event.key.keysym.mod&KMOD_CTRL))
|
2018-03-10 15:01:14 -06:00
|
|
|
engine->ConfirmExit();
|
|
|
|
else
|
upgrade to SDL 2
Still currently in process, there are some issues:
Windows version doesn't work, mac version might not work, opengl might not work
Icon doesn't work (on Linux at least)
Lua will need some changes, there are some sdl 1.2 hacks in there
When entering fullscreen, the window loses focus
When holding down mouse out of bounds, mouse move events stop being sent
When letting go of mouse out of bounds, mouseup event doesn't take into account double scale mode
Clicking on startup without moving mouse will draw at 0,0 for a frame
Renderer probably won't compile because USE_SDL doesn't entirely work
... and maybe others
Some nice things were done though:
no more blit2, sdl can do the scaling itself
3d effect removed, no reason to support this joke any longer
No need to support copy/paste ourselves, sdl does it now
text handling done much better now, separate events for key presses and text input
when a new window is shown, all events ignored until next tick (ignore textinput event if window shown from key press event like console)
2018-04-15 17:53:02 -05:00
|
|
|
engine->onKeyPress(event.key.keysym.sym, event.key.keysym.scancode, event.key.repeat, event.key.keysym.mod&KMOD_SHIFT, event.key.keysym.mod&KMOD_CTRL, event.key.keysym.mod&KMOD_ALT);
|
2013-10-24 15:46:41 -05:00
|
|
|
break;
|
|
|
|
case SDL_KEYUP:
|
2021-03-08 14:09:35 -06:00
|
|
|
if (SDL_GetModState() & KMOD_GUI)
|
2021-03-08 13:42:44 -06:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
upgrade to SDL 2
Still currently in process, there are some issues:
Windows version doesn't work, mac version might not work, opengl might not work
Icon doesn't work (on Linux at least)
Lua will need some changes, there are some sdl 1.2 hacks in there
When entering fullscreen, the window loses focus
When holding down mouse out of bounds, mouse move events stop being sent
When letting go of mouse out of bounds, mouseup event doesn't take into account double scale mode
Clicking on startup without moving mouse will draw at 0,0 for a frame
Renderer probably won't compile because USE_SDL doesn't entirely work
... and maybe others
Some nice things were done though:
no more blit2, sdl can do the scaling itself
3d effect removed, no reason to support this joke any longer
No need to support copy/paste ourselves, sdl does it now
text handling done much better now, separate events for key presses and text input
when a new window is shown, all events ignored until next tick (ignore textinput event if window shown from key press event like console)
2018-04-15 17:53:02 -05:00
|
|
|
engine->onKeyRelease(event.key.keysym.sym, event.key.keysym.scancode, event.key.repeat, event.key.keysym.mod&KMOD_SHIFT, event.key.keysym.mod&KMOD_CTRL, event.key.keysym.mod&KMOD_ALT);
|
2013-10-24 15:46:41 -05:00
|
|
|
break;
|
upgrade to SDL 2
Still currently in process, there are some issues:
Windows version doesn't work, mac version might not work, opengl might not work
Icon doesn't work (on Linux at least)
Lua will need some changes, there are some sdl 1.2 hacks in there
When entering fullscreen, the window loses focus
When holding down mouse out of bounds, mouse move events stop being sent
When letting go of mouse out of bounds, mouseup event doesn't take into account double scale mode
Clicking on startup without moving mouse will draw at 0,0 for a frame
Renderer probably won't compile because USE_SDL doesn't entirely work
... and maybe others
Some nice things were done though:
no more blit2, sdl can do the scaling itself
3d effect removed, no reason to support this joke any longer
No need to support copy/paste ourselves, sdl does it now
text handling done much better now, separate events for key presses and text input
when a new window is shown, all events ignored until next tick (ignore textinput event if window shown from key press event like console)
2018-04-15 17:53:02 -05:00
|
|
|
case SDL_TEXTINPUT:
|
2021-03-08 14:09:35 -06:00
|
|
|
if (SDL_GetModState() & KMOD_GUI)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
upgrade to SDL 2
Still currently in process, there are some issues:
Windows version doesn't work, mac version might not work, opengl might not work
Icon doesn't work (on Linux at least)
Lua will need some changes, there are some sdl 1.2 hacks in there
When entering fullscreen, the window loses focus
When holding down mouse out of bounds, mouse move events stop being sent
When letting go of mouse out of bounds, mouseup event doesn't take into account double scale mode
Clicking on startup without moving mouse will draw at 0,0 for a frame
Renderer probably won't compile because USE_SDL doesn't entirely work
... and maybe others
Some nice things were done though:
no more blit2, sdl can do the scaling itself
3d effect removed, no reason to support this joke any longer
No need to support copy/paste ourselves, sdl does it now
text handling done much better now, separate events for key presses and text input
when a new window is shown, all events ignored until next tick (ignore textinput event if window shown from key press event like console)
2018-04-15 17:53:02 -05:00
|
|
|
engine->onTextInput(ByteString(event.text.text).FromUtf8());
|
2013-10-24 15:46:41 -05:00
|
|
|
break;
|
upgrade to SDL 2
Still currently in process, there are some issues:
Windows version doesn't work, mac version might not work, opengl might not work
Icon doesn't work (on Linux at least)
Lua will need some changes, there are some sdl 1.2 hacks in there
When entering fullscreen, the window loses focus
When holding down mouse out of bounds, mouse move events stop being sent
When letting go of mouse out of bounds, mouseup event doesn't take into account double scale mode
Clicking on startup without moving mouse will draw at 0,0 for a frame
Renderer probably won't compile because USE_SDL doesn't entirely work
... and maybe others
Some nice things were done though:
no more blit2, sdl can do the scaling itself
3d effect removed, no reason to support this joke any longer
No need to support copy/paste ourselves, sdl does it now
text handling done much better now, separate events for key presses and text input
when a new window is shown, all events ignored until next tick (ignore textinput event if window shown from key press event like console)
2018-04-15 17:53:02 -05:00
|
|
|
case SDL_MOUSEWHEEL:
|
|
|
|
{
|
|
|
|
int x = event.wheel.x;
|
|
|
|
int y = event.wheel.y;
|
|
|
|
if (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED)
|
2013-10-24 15:46:41 -05:00
|
|
|
{
|
upgrade to SDL 2
Still currently in process, there are some issues:
Windows version doesn't work, mac version might not work, opengl might not work
Icon doesn't work (on Linux at least)
Lua will need some changes, there are some sdl 1.2 hacks in there
When entering fullscreen, the window loses focus
When holding down mouse out of bounds, mouse move events stop being sent
When letting go of mouse out of bounds, mouseup event doesn't take into account double scale mode
Clicking on startup without moving mouse will draw at 0,0 for a frame
Renderer probably won't compile because USE_SDL doesn't entirely work
... and maybe others
Some nice things were done though:
no more blit2, sdl can do the scaling itself
3d effect removed, no reason to support this joke any longer
No need to support copy/paste ourselves, sdl does it now
text handling done much better now, separate events for key presses and text input
when a new window is shown, all events ignored until next tick (ignore textinput event if window shown from key press event like console)
2018-04-15 17:53:02 -05:00
|
|
|
x *= -1;
|
|
|
|
y *= -1;
|
2013-10-24 15:46:41 -05:00
|
|
|
}
|
2018-05-30 05:35:44 -05:00
|
|
|
|
|
|
|
engine->onMouseWheel(mousex, mousey, y); // TODO: pass x?
|
upgrade to SDL 2
Still currently in process, there are some issues:
Windows version doesn't work, mac version might not work, opengl might not work
Icon doesn't work (on Linux at least)
Lua will need some changes, there are some sdl 1.2 hacks in there
When entering fullscreen, the window loses focus
When holding down mouse out of bounds, mouse move events stop being sent
When letting go of mouse out of bounds, mouseup event doesn't take into account double scale mode
Clicking on startup without moving mouse will draw at 0,0 for a frame
Renderer probably won't compile because USE_SDL doesn't entirely work
... and maybe others
Some nice things were done though:
no more blit2, sdl can do the scaling itself
3d effect removed, no reason to support this joke any longer
No need to support copy/paste ourselves, sdl does it now
text handling done much better now, separate events for key presses and text input
when a new window is shown, all events ignored until next tick (ignore textinput event if window shown from key press event like console)
2018-04-15 17:53:02 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SDL_MOUSEMOTION:
|
2018-04-22 21:14:06 -05:00
|
|
|
mousex = event.motion.x;
|
|
|
|
mousey = event.motion.y;
|
2018-04-22 19:09:44 -05:00
|
|
|
engine->onMouseMove(mousex, mousey);
|
2018-04-22 21:14:06 -05:00
|
|
|
|
|
|
|
hasMouseMoved = true;
|
upgrade to SDL 2
Still currently in process, there are some issues:
Windows version doesn't work, mac version might not work, opengl might not work
Icon doesn't work (on Linux at least)
Lua will need some changes, there are some sdl 1.2 hacks in there
When entering fullscreen, the window loses focus
When holding down mouse out of bounds, mouse move events stop being sent
When letting go of mouse out of bounds, mouseup event doesn't take into account double scale mode
Clicking on startup without moving mouse will draw at 0,0 for a frame
Renderer probably won't compile because USE_SDL doesn't entirely work
... and maybe others
Some nice things were done though:
no more blit2, sdl can do the scaling itself
3d effect removed, no reason to support this joke any longer
No need to support copy/paste ourselves, sdl does it now
text handling done much better now, separate events for key presses and text input
when a new window is shown, all events ignored until next tick (ignore textinput event if window shown from key press event like console)
2018-04-15 17:53:02 -05:00
|
|
|
break;
|
2019-07-23 23:04:41 -05:00
|
|
|
case SDL_DROPFILE:
|
|
|
|
engine->onFileDrop(event.drop.file);
|
|
|
|
SDL_free(event.drop.file);
|
|
|
|
break;
|
upgrade to SDL 2
Still currently in process, there are some issues:
Windows version doesn't work, mac version might not work, opengl might not work
Icon doesn't work (on Linux at least)
Lua will need some changes, there are some sdl 1.2 hacks in there
When entering fullscreen, the window loses focus
When holding down mouse out of bounds, mouse move events stop being sent
When letting go of mouse out of bounds, mouseup event doesn't take into account double scale mode
Clicking on startup without moving mouse will draw at 0,0 for a frame
Renderer probably won't compile because USE_SDL doesn't entirely work
... and maybe others
Some nice things were done though:
no more blit2, sdl can do the scaling itself
3d effect removed, no reason to support this joke any longer
No need to support copy/paste ourselves, sdl does it now
text handling done much better now, separate events for key presses and text input
when a new window is shown, all events ignored until next tick (ignore textinput event if window shown from key press event like console)
2018-04-15 17:53:02 -05:00
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
2018-04-22 21:14:06 -05:00
|
|
|
// if mouse hasn't moved yet, sdl will send 0,0. We don't want that
|
|
|
|
if (hasMouseMoved)
|
|
|
|
{
|
2020-08-22 17:25:43 -05:00
|
|
|
mousex = event.button.x;
|
|
|
|
mousey = event.button.y;
|
2018-04-22 21:14:06 -05:00
|
|
|
}
|
2018-04-22 19:09:44 -05:00
|
|
|
mouseButton = event.button.button;
|
2020-08-22 17:25:43 -05:00
|
|
|
engine->onMouseClick(mousex, mousey, mouseButton);
|
2018-04-22 19:09:44 -05:00
|
|
|
|
|
|
|
mouseDown = true;
|
2019-02-18 21:18:29 -06:00
|
|
|
#if !defined(NDEBUG) && !defined(DEBUG)
|
2018-04-22 19:09:44 -05:00
|
|
|
SDL_CaptureMouse(SDL_TRUE);
|
2019-02-18 21:18:29 -06:00
|
|
|
#endif
|
2013-10-24 15:46:41 -05:00
|
|
|
break;
|
|
|
|
case SDL_MOUSEBUTTONUP:
|
2018-04-22 21:14:06 -05:00
|
|
|
// if mouse hasn't moved yet, sdl will send 0,0. We don't want that
|
|
|
|
if (hasMouseMoved)
|
|
|
|
{
|
2020-08-22 17:25:43 -05:00
|
|
|
mousex = event.button.x;
|
|
|
|
mousey = event.button.y;
|
2018-04-22 21:14:06 -05:00
|
|
|
}
|
2018-04-22 19:09:44 -05:00
|
|
|
mouseButton = event.button.button;
|
|
|
|
engine->onMouseUnclick(mousex, mousey, mouseButton);
|
|
|
|
|
|
|
|
mouseDown = false;
|
2019-02-18 21:18:29 -06:00
|
|
|
#if !defined(NDEBUG) && !defined(DEBUG)
|
2018-04-22 19:09:44 -05:00
|
|
|
SDL_CaptureMouse(SDL_FALSE);
|
2019-02-18 21:18:29 -06:00
|
|
|
#endif
|
2013-10-24 15:46:41 -05:00
|
|
|
break;
|
upgrade to SDL 2
Still currently in process, there are some issues:
Windows version doesn't work, mac version might not work, opengl might not work
Icon doesn't work (on Linux at least)
Lua will need some changes, there are some sdl 1.2 hacks in there
When entering fullscreen, the window loses focus
When holding down mouse out of bounds, mouse move events stop being sent
When letting go of mouse out of bounds, mouseup event doesn't take into account double scale mode
Clicking on startup without moving mouse will draw at 0,0 for a frame
Renderer probably won't compile because USE_SDL doesn't entirely work
... and maybe others
Some nice things were done though:
no more blit2, sdl can do the scaling itself
3d effect removed, no reason to support this joke any longer
No need to support copy/paste ourselves, sdl does it now
text handling done much better now, separate events for key presses and text input
when a new window is shown, all events ignored until next tick (ignore textinput event if window shown from key press event like console)
2018-04-15 17:53:02 -05:00
|
|
|
case SDL_WINDOWEVENT:
|
2013-10-24 15:46:41 -05:00
|
|
|
{
|
2018-04-22 19:09:44 -05:00
|
|
|
switch (event.window.event)
|
|
|
|
{
|
2018-04-22 21:14:06 -05:00
|
|
|
case SDL_WINDOWEVENT_SHOWN:
|
|
|
|
if (!calculatedInitialMouse)
|
|
|
|
{
|
|
|
|
//initial mouse coords, sdl won't tell us this if mouse hasn't moved
|
|
|
|
CalculateMousePosition(&mousex, &mousey);
|
2020-08-22 17:25:43 -05:00
|
|
|
engine->initialMouse(mousex, mousey);
|
2018-04-22 21:14:06 -05:00
|
|
|
engine->onMouseMove(mousex, mousey);
|
|
|
|
calculatedInitialMouse = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
// This event would be needed in certain glitchy cases of window resizing
|
|
|
|
// But for all currently tested cases, it isn't needed
|
|
|
|
/*case SDL_WINDOWEVENT_RESIZED:
|
2018-04-22 19:09:44 -05:00
|
|
|
{
|
|
|
|
float width = event.window.data1;
|
|
|
|
float height = event.window.data2;
|
|
|
|
|
|
|
|
currentWidth = width;
|
|
|
|
currentHeight = height;
|
|
|
|
// this "* scale" thing doesn't really work properly
|
|
|
|
// currently there is a bug where input doesn't scale properly after resizing, only when double scale mode is active
|
|
|
|
inputScaleH = (float)WINDOWW * scale / currentWidth;
|
|
|
|
inputScaleV = (float)WINDOWH * scale / currentHeight;
|
|
|
|
std::cout << "Changing input scale to " << inputScaleH << "x" << inputScaleV << std::endl;
|
upgrade to SDL 2
Still currently in process, there are some issues:
Windows version doesn't work, mac version might not work, opengl might not work
Icon doesn't work (on Linux at least)
Lua will need some changes, there are some sdl 1.2 hacks in there
When entering fullscreen, the window loses focus
When holding down mouse out of bounds, mouse move events stop being sent
When letting go of mouse out of bounds, mouseup event doesn't take into account double scale mode
Clicking on startup without moving mouse will draw at 0,0 for a frame
Renderer probably won't compile because USE_SDL doesn't entirely work
... and maybe others
Some nice things were done though:
no more blit2, sdl can do the scaling itself
3d effect removed, no reason to support this joke any longer
No need to support copy/paste ourselves, sdl does it now
text handling done much better now, separate events for key presses and text input
when a new window is shown, all events ignored until next tick (ignore textinput event if window shown from key press event like console)
2018-04-15 17:53:02 -05:00
|
|
|
break;
|
2018-04-22 21:14:06 -05:00
|
|
|
}*/
|
2018-04-22 19:09:44 -05:00
|
|
|
// This would send a mouse up event when focus is lost
|
|
|
|
// Not even sdl itself will know when the mouse was released if it happens in another window
|
|
|
|
// So it will ignore the next mouse down (after tpt is re-focused) and not send any events at all
|
|
|
|
// This is more unintuitive than pretending the mouse is still down when it's not, so this code is commented out
|
|
|
|
/*case SDL_WINDOWEVENT_FOCUS_LOST:
|
|
|
|
if (mouseDown)
|
|
|
|
{
|
|
|
|
mouseDown = false;
|
|
|
|
engine->onMouseUnclick(mousex, mousey, mouseButton);
|
|
|
|
}
|
|
|
|
break;*/
|
|
|
|
}
|
2013-10-24 15:46:41 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-21 10:39:32 -06:00
|
|
|
void LargeScreenDialog()
|
2016-01-31 21:30:39 -06:00
|
|
|
{
|
2018-05-02 14:08:52 -05:00
|
|
|
StringBuilder message;
|
2019-12-21 10:39:32 -06:00
|
|
|
message << "Switching to " << scale << "x size mode since your screen was determined to be large enough: ";
|
|
|
|
message << desktopWidth << "x" << desktopHeight << " detected, " << WINDOWW*scale << "x" << WINDOWH*scale << " required";
|
|
|
|
message << "\nTo undo this, hit Cancel. You can change this in settings at any time.";
|
2018-05-02 14:08:52 -05:00
|
|
|
if (!ConfirmPrompt::Blocking("Large screen detected", message.Build()))
|
2016-01-31 21:30:39 -06:00
|
|
|
{
|
|
|
|
Client::Ref().SetPref("Scale", 1);
|
|
|
|
engine->SetScale(1);
|
|
|
|
}
|
|
|
|
}
|
2016-03-31 21:08:04 -05:00
|
|
|
|
2012-08-18 16:08:20 -05:00
|
|
|
void EngineProcess()
|
|
|
|
{
|
2015-02-03 19:13:51 -06:00
|
|
|
double frameTimeAvg = 0.0f, correctedFrameTimeAvg = 0.0f;
|
2012-08-18 16:08:20 -05:00
|
|
|
SDL_Event event;
|
2020-10-11 04:58:52 -05:00
|
|
|
|
|
|
|
int drawingTimer = 0;
|
|
|
|
int frameStart = 0;
|
|
|
|
|
2012-08-18 16:08:20 -05:00
|
|
|
while(engine->Running())
|
|
|
|
{
|
2020-10-11 04:58:52 -05:00
|
|
|
int oldFrameStart = frameStart;
|
|
|
|
frameStart = SDL_GetTicks();
|
|
|
|
drawingTimer += frameStart - oldFrameStart;
|
|
|
|
|
2012-08-19 06:16:51 -05:00
|
|
|
if(engine->Broken()) { engine->UnBreak(); break; }
|
2012-08-18 16:08:20 -05:00
|
|
|
event.type = 0;
|
|
|
|
while (SDL_PollEvent(&event))
|
|
|
|
{
|
2013-10-24 15:46:41 -05:00
|
|
|
EventProcess(event);
|
2012-08-18 16:08:20 -05:00
|
|
|
event.type = 0; //Clear last event
|
|
|
|
}
|
2012-08-19 06:16:51 -05:00
|
|
|
if(engine->Broken()) { engine->UnBreak(); break; }
|
2012-08-18 16:08:20 -05:00
|
|
|
|
|
|
|
engine->Tick();
|
2017-11-15 19:07:00 -06:00
|
|
|
|
2020-10-11 04:58:52 -05:00
|
|
|
int drawcap = ui::Engine::Ref().GetDrawingFrequencyLimit();
|
|
|
|
if (!drawcap || drawingTimer > 1000.f/drawcap)
|
2013-05-21 22:05:27 -05:00
|
|
|
{
|
2020-10-11 04:58:52 -05:00
|
|
|
engine->Draw();
|
|
|
|
drawingTimer = 0;
|
|
|
|
|
|
|
|
if (scale != engine->Scale || fullscreen != engine->Fullscreen ||
|
|
|
|
altFullscreen != engine->GetAltFullscreen() ||
|
|
|
|
forceIntegerScaling != engine->GetForceIntegerScaling() || resizable != engine->GetResizable())
|
|
|
|
{
|
|
|
|
SDLSetScreen(engine->Scale, engine->GetResizable(), engine->Fullscreen, engine->GetAltFullscreen(),
|
|
|
|
engine->GetForceIntegerScaling());
|
|
|
|
}
|
2013-05-21 22:05:27 -05:00
|
|
|
|
|
|
|
#ifdef OGLI
|
2020-10-11 04:58:52 -05:00
|
|
|
blit();
|
2013-05-21 22:05:27 -05:00
|
|
|
#else
|
2020-10-11 04:58:52 -05:00
|
|
|
blit(engine->g->vid);
|
2013-05-21 22:05:27 -05:00
|
|
|
#endif
|
2020-10-11 04:58:52 -05:00
|
|
|
}
|
2013-05-21 22:05:27 -05:00
|
|
|
|
2015-02-03 19:13:51 -06:00
|
|
|
int frameTime = SDL_GetTicks() - frameStart;
|
|
|
|
frameTimeAvg = frameTimeAvg * 0.8 + frameTime * 0.2;
|
2021-02-15 14:11:10 -06:00
|
|
|
float fpsLimit = ui::Engine::Ref().FpsLimit;
|
2015-02-03 19:13:51 -06:00
|
|
|
if(fpsLimit > 2)
|
2012-10-05 08:21:38 -05:00
|
|
|
{
|
2015-02-03 19:13:51 -06:00
|
|
|
double offset = 1000.0 / fpsLimit - frameTimeAvg;
|
|
|
|
if(offset > 0)
|
2021-02-15 14:11:10 -06:00
|
|
|
SDL_Delay(Uint32(offset + 0.5));
|
2012-10-05 08:21:38 -05:00
|
|
|
}
|
2015-02-03 19:13:51 -06:00
|
|
|
int correctedFrameTime = SDL_GetTicks() - frameStart;
|
|
|
|
correctedFrameTimeAvg = correctedFrameTimeAvg * 0.95 + correctedFrameTime * 0.05;
|
2018-06-04 22:48:40 -05:00
|
|
|
if (frameStart - lastFpsUpdate > 200)
|
|
|
|
{
|
|
|
|
engine->SetFps(1000.0 / correctedFrameTimeAvg);
|
|
|
|
lastFpsUpdate = frameStart;
|
|
|
|
}
|
2019-03-03 22:47:54 -06:00
|
|
|
if (frameStart - lastTick > 100)
|
2012-08-18 16:08:20 -05:00
|
|
|
{
|
2012-10-05 08:21:38 -05:00
|
|
|
lastTick = frameStart;
|
2012-08-18 16:08:20 -05:00
|
|
|
Client::Ref().Tick();
|
|
|
|
}
|
2019-12-21 10:39:32 -06:00
|
|
|
if (showLargeScreenDialog)
|
2016-01-31 21:30:39 -06:00
|
|
|
{
|
2019-12-21 10:39:32 -06:00
|
|
|
showLargeScreenDialog = false;
|
|
|
|
LargeScreenDialog();
|
2016-01-31 21:30:39 -06:00
|
|
|
}
|
2012-08-18 16:08:20 -05:00
|
|
|
}
|
2012-08-18 18:40:20 -05:00
|
|
|
#ifdef DEBUG
|
|
|
|
std::cout << "Breaking out of EngineProcess" << std::endl;
|
|
|
|
#endif
|
2012-08-18 16:08:20 -05:00
|
|
|
}
|
|
|
|
|
upgrade to SDL 2
Still currently in process, there are some issues:
Windows version doesn't work, mac version might not work, opengl might not work
Icon doesn't work (on Linux at least)
Lua will need some changes, there are some sdl 1.2 hacks in there
When entering fullscreen, the window loses focus
When holding down mouse out of bounds, mouse move events stop being sent
When letting go of mouse out of bounds, mouseup event doesn't take into account double scale mode
Clicking on startup without moving mouse will draw at 0,0 for a frame
Renderer probably won't compile because USE_SDL doesn't entirely work
... and maybe others
Some nice things were done though:
no more blit2, sdl can do the scaling itself
3d effect removed, no reason to support this joke any longer
No need to support copy/paste ourselves, sdl does it now
text handling done much better now, separate events for key presses and text input
when a new window is shown, all events ignored until next tick (ignore textinput event if window shown from key press event like console)
2018-04-15 17:53:02 -05:00
|
|
|
void BlueScreen(String detailMessage)
|
|
|
|
{
|
2013-05-04 15:39:43 -05:00
|
|
|
ui::Engine * engine = &ui::Engine::Ref();
|
|
|
|
engine->g->fillrect(0, 0, engine->GetWidth(), engine->GetHeight(), 17, 114, 169, 210);
|
|
|
|
|
2018-04-30 13:13:24 -05:00
|
|
|
String errorTitle = "ERROR";
|
|
|
|
String errorDetails = "Details: " + detailMessage;
|
|
|
|
String errorHelp = "An unrecoverable fault has occurred, please report the error by visiting the website below\n"
|
2019-03-13 16:47:19 -05:00
|
|
|
SCHEME SERVER;
|
2013-05-04 15:39:43 -05:00
|
|
|
int currentY = 0, width, height;
|
|
|
|
int errorWidth = 0;
|
2018-04-30 13:13:24 -05:00
|
|
|
Graphics::textsize(errorHelp, errorWidth, height);
|
2017-11-15 19:07:00 -06:00
|
|
|
|
2013-05-04 15:39:43 -05:00
|
|
|
engine->g->drawtext((engine->GetWidth()/2)-(errorWidth/2), ((engine->GetHeight()/2)-100) + currentY, errorTitle.c_str(), 255, 255, 255, 255);
|
2018-04-30 13:13:24 -05:00
|
|
|
Graphics::textsize(errorTitle, width, height);
|
2013-05-04 15:39:43 -05:00
|
|
|
currentY += height + 4;
|
|
|
|
|
|
|
|
engine->g->drawtext((engine->GetWidth()/2)-(errorWidth/2), ((engine->GetHeight()/2)-100) + currentY, errorDetails.c_str(), 255, 255, 255, 255);
|
2018-04-30 13:13:24 -05:00
|
|
|
Graphics::textsize(errorTitle, width, height);
|
2013-05-04 15:39:43 -05:00
|
|
|
currentY += height + 4;
|
|
|
|
|
|
|
|
engine->g->drawtext((engine->GetWidth()/2)-(errorWidth/2), ((engine->GetHeight()/2)-100) + currentY, errorHelp.c_str(), 255, 255, 255, 255);
|
2018-04-30 13:13:24 -05:00
|
|
|
Graphics::textsize(errorTitle, width, height);
|
2013-05-04 15:39:43 -05:00
|
|
|
currentY += height + 4;
|
2017-11-15 19:07:00 -06:00
|
|
|
|
2013-05-04 15:39:43 -05:00
|
|
|
//Death loop
|
2017-11-15 19:07:00 -06:00
|
|
|
SDL_Event event;
|
2013-05-04 15:39:43 -05:00
|
|
|
while(true)
|
|
|
|
{
|
|
|
|
while (SDL_PollEvent(&event))
|
|
|
|
if(event.type == SDL_QUIT)
|
|
|
|
exit(-1);
|
|
|
|
#ifdef OGLI
|
|
|
|
blit();
|
|
|
|
#else
|
upgrade to SDL 2
Still currently in process, there are some issues:
Windows version doesn't work, mac version might not work, opengl might not work
Icon doesn't work (on Linux at least)
Lua will need some changes, there are some sdl 1.2 hacks in there
When entering fullscreen, the window loses focus
When holding down mouse out of bounds, mouse move events stop being sent
When letting go of mouse out of bounds, mouseup event doesn't take into account double scale mode
Clicking on startup without moving mouse will draw at 0,0 for a frame
Renderer probably won't compile because USE_SDL doesn't entirely work
... and maybe others
Some nice things were done though:
no more blit2, sdl can do the scaling itself
3d effect removed, no reason to support this joke any longer
No need to support copy/paste ourselves, sdl does it now
text handling done much better now, separate events for key presses and text input
when a new window is shown, all events ignored until next tick (ignore textinput event if window shown from key press event like console)
2018-04-15 17:53:02 -05:00
|
|
|
blit(engine->g->vid);
|
2013-05-04 15:39:43 -05:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SigHandler(int signal)
|
|
|
|
{
|
|
|
|
switch(signal){
|
|
|
|
case SIGSEGV:
|
|
|
|
BlueScreen("Memory read/write error");
|
|
|
|
break;
|
|
|
|
case SIGFPE:
|
|
|
|
BlueScreen("Floating point exception");
|
|
|
|
break;
|
|
|
|
case SIGILL:
|
|
|
|
BlueScreen("Program execution exception");
|
|
|
|
break;
|
|
|
|
case SIGABRT:
|
|
|
|
BlueScreen("Unexpected program abort");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-21 10:39:32 -06:00
|
|
|
constexpr int SCALE_MAXIMUM = 10;
|
|
|
|
constexpr int SCALE_MARGIN = 30;
|
|
|
|
|
|
|
|
int GuessBestScale()
|
|
|
|
{
|
|
|
|
const int widthNoMargin = desktopWidth - SCALE_MARGIN;
|
|
|
|
const int widthGuess = widthNoMargin / WINDOWW;
|
|
|
|
|
|
|
|
const int heightNoMargin = desktopHeight - SCALE_MARGIN;
|
|
|
|
const int heightGuess = heightNoMargin / WINDOWH;
|
|
|
|
|
|
|
|
int guess = std::min(widthGuess, heightGuess);
|
|
|
|
if(guess < 1 || guess > SCALE_MAXIMUM)
|
|
|
|
guess = 1;
|
|
|
|
|
|
|
|
return guess;
|
|
|
|
}
|
|
|
|
|
2021-03-12 14:02:02 -06:00
|
|
|
#ifdef main
|
|
|
|
# undef main // thank you sdl
|
|
|
|
#endif
|
|
|
|
|
2012-01-08 11:39:03 -06:00
|
|
|
int main(int argc, char * argv[])
|
|
|
|
{
|
2016-04-23 10:38:58 -05:00
|
|
|
#if defined(_DEBUG) && defined(_MSC_VER)
|
|
|
|
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);
|
|
|
|
#endif
|
2017-11-15 19:07:00 -06:00
|
|
|
currentWidth = WINDOWW;
|
2013-11-10 03:02:55 -06:00
|
|
|
currentHeight = WINDOWH;
|
2012-11-16 15:50:02 -06:00
|
|
|
|
2012-01-08 11:39:03 -06:00
|
|
|
|
2020-06-06 06:40:08 -05:00
|
|
|
// https://bugzilla.libsdl.org/show_bug.cgi?id=3796
|
|
|
|
if (SDL_Init(0) < 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Initializing SDL: %s\n", SDL_GetError());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-04-30 13:13:24 -05:00
|
|
|
std::map<ByteString, ByteString> arguments = readArguments(argc, argv);
|
2012-07-06 10:53:59 -05:00
|
|
|
|
2012-08-08 11:42:04 -05:00
|
|
|
if(arguments["ddir"].length())
|
2020-08-06 18:11:56 -05:00
|
|
|
{
|
2012-08-08 11:42:04 -05:00
|
|
|
#ifdef WIN
|
2020-08-06 18:11:56 -05:00
|
|
|
int failure = _chdir(arguments["ddir"].c_str());
|
2012-08-08 11:42:04 -05:00
|
|
|
#else
|
2020-08-06 18:11:56 -05:00
|
|
|
int failure = chdir(arguments["ddir"].c_str());
|
2012-08-08 11:42:04 -05:00
|
|
|
#endif
|
2020-08-06 18:11:56 -05:00
|
|
|
if (failure)
|
|
|
|
{
|
|
|
|
perror("failed to chdir to requested ddir");
|
|
|
|
}
|
|
|
|
}
|
2019-01-12 11:50:28 -06:00
|
|
|
else
|
2020-06-06 06:40:08 -05:00
|
|
|
{
|
|
|
|
#ifdef WIN
|
|
|
|
struct _stat s;
|
|
|
|
if(_stat("powder.pref", &s) != 0)
|
|
|
|
#else
|
|
|
|
struct stat s;
|
|
|
|
if(stat("powder.pref", &s) != 0)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
char *ddir = SDL_GetPrefPath(NULL, "The Powder Toy");
|
|
|
|
if(ddir)
|
|
|
|
{
|
|
|
|
#ifdef WIN
|
2020-08-06 18:11:56 -05:00
|
|
|
int failure = _chdir(ddir);
|
2020-06-06 06:40:08 -05:00
|
|
|
#else
|
2020-08-06 18:11:56 -05:00
|
|
|
int failure = chdir(ddir);
|
2020-06-06 06:40:08 -05:00
|
|
|
#endif
|
2020-08-06 18:11:56 -05:00
|
|
|
if (failure)
|
|
|
|
{
|
|
|
|
perror("failed to chdir to default ddir");
|
|
|
|
}
|
2020-06-06 06:40:08 -05:00
|
|
|
SDL_free(ddir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-08 11:42:04 -05:00
|
|
|
|
2018-04-22 21:14:06 -05:00
|
|
|
scale = Client::Ref().GetPrefInteger("Scale", 1);
|
2018-05-19 15:50:47 -05:00
|
|
|
resizable = Client::Ref().GetPrefBool("Resizable", false);
|
2018-04-22 21:14:06 -05:00
|
|
|
fullscreen = Client::Ref().GetPrefBool("Fullscreen", false);
|
2018-05-19 15:50:47 -05:00
|
|
|
altFullscreen = Client::Ref().GetPrefBool("AltFullscreen", false);
|
2019-02-18 21:18:29 -06:00
|
|
|
forceIntegerScaling = Client::Ref().GetPrefBool("ForceIntegerScaling", true);
|
2020-10-10 14:57:29 -05:00
|
|
|
momentumScroll = Client::Ref().GetPrefBool("MomentumScroll", true);
|
2012-08-08 11:42:04 -05:00
|
|
|
|
|
|
|
|
|
|
|
if(arguments["kiosk"] == "true")
|
|
|
|
{
|
2018-04-22 21:14:06 -05:00
|
|
|
fullscreen = true;
|
|
|
|
Client::Ref().SetPref("Fullscreen", fullscreen);
|
2012-08-08 11:42:04 -05:00
|
|
|
}
|
|
|
|
|
2019-04-05 13:48:05 -05:00
|
|
|
if(arguments["redirect"] == "true")
|
|
|
|
{
|
2020-08-06 18:11:56 -05:00
|
|
|
FILE *new_stdout = freopen("stdout.log", "w", stdout);
|
|
|
|
FILE *new_stderr = freopen("stderr.log", "w", stderr);
|
|
|
|
if (!new_stdout || !new_stderr)
|
|
|
|
{
|
2021-02-15 14:11:10 -06:00
|
|
|
exit(42);
|
2020-08-06 18:11:56 -05:00
|
|
|
}
|
2019-04-05 13:48:05 -05:00
|
|
|
}
|
|
|
|
|
2012-08-08 11:42:04 -05:00
|
|
|
if(arguments["scale"].length())
|
|
|
|
{
|
2018-04-22 21:14:06 -05:00
|
|
|
scale = arguments["scale"].ToNumber<int>();
|
|
|
|
Client::Ref().SetPref("Scale", scale);
|
2012-08-08 11:42:04 -05:00
|
|
|
}
|
|
|
|
|
2018-04-30 13:13:24 -05:00
|
|
|
ByteString proxyString = "";
|
2012-08-08 12:34:37 -05:00
|
|
|
if(arguments["proxy"].length())
|
|
|
|
{
|
|
|
|
if(arguments["proxy"] == "false")
|
|
|
|
{
|
|
|
|
proxyString = "";
|
2017-11-15 19:07:00 -06:00
|
|
|
Client::Ref().SetPref("Proxy", "");
|
2012-08-08 12:34:37 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
proxyString = (arguments["proxy"]);
|
|
|
|
Client::Ref().SetPref("Proxy", arguments["proxy"]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(Client::Ref().GetPrefString("Proxy", "").length())
|
|
|
|
{
|
2018-04-30 13:13:24 -05:00
|
|
|
proxyString = (Client::Ref().GetPrefByteString("Proxy", ""));
|
2012-08-08 12:34:37 -05:00
|
|
|
}
|
|
|
|
|
2019-07-22 21:46:32 -05:00
|
|
|
bool disableNetwork = false;
|
|
|
|
if (arguments.find("disable-network") != arguments.end())
|
|
|
|
disableNetwork = true;
|
|
|
|
|
|
|
|
Client::Ref().Initialise(proxyString, disableNetwork);
|
2012-08-08 12:34:37 -05:00
|
|
|
|
2017-11-23 07:22:40 -06:00
|
|
|
// TODO: maybe bind the maximum allowed scale to screen size somehow
|
2019-12-21 10:39:32 -06:00
|
|
|
if(scale < 1 || scale > SCALE_MAXIMUM)
|
2018-04-22 21:14:06 -05:00
|
|
|
scale = 1;
|
2012-08-08 11:42:04 -05:00
|
|
|
|
2015-01-10 21:43:33 -06:00
|
|
|
SDLOpen();
|
2019-12-21 10:39:32 -06:00
|
|
|
|
|
|
|
if (Client::Ref().IsFirstRun())
|
2015-05-14 22:22:20 -05:00
|
|
|
{
|
2019-12-21 10:39:32 -06:00
|
|
|
scale = GuessBestScale();
|
|
|
|
if (scale > 1)
|
|
|
|
{
|
|
|
|
Client::Ref().SetPref("Scale", scale);
|
|
|
|
SDL_SetWindowSize(sdl_window, WINDOWW * scale, WINDOWH * scale);
|
|
|
|
showLargeScreenDialog = true;
|
|
|
|
}
|
2015-05-14 22:22:20 -05:00
|
|
|
}
|
2013-04-22 12:04:43 -05:00
|
|
|
|
2012-06-23 08:59:07 -05:00
|
|
|
#ifdef OGLI
|
2012-05-30 06:32:58 -05:00
|
|
|
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
|
2012-06-25 10:10:40 -05:00
|
|
|
//glScaled(2.0f, 2.0f, 1.0f);
|
2012-08-12 13:29:27 -05:00
|
|
|
#endif
|
2016-07-12 15:31:29 -05:00
|
|
|
#if defined(OGLI) && !defined(MACOSX)
|
2012-08-12 13:29:27 -05:00
|
|
|
int status = glewInit();
|
|
|
|
if(status != GLEW_OK)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Initializing Glew: %d\n", status);
|
|
|
|
exit(-1);
|
|
|
|
}
|
2013-01-19 10:46:21 -06:00
|
|
|
#endif
|
2012-01-17 14:46:06 -06:00
|
|
|
ui::Engine::Ref().g = new Graphics();
|
2012-08-08 11:42:04 -05:00
|
|
|
ui::Engine::Ref().Scale = scale;
|
2018-05-19 15:50:47 -05:00
|
|
|
ui::Engine::Ref().SetResizable(resizable);
|
2012-08-08 11:42:04 -05:00
|
|
|
ui::Engine::Ref().Fullscreen = fullscreen;
|
2018-05-19 15:50:47 -05:00
|
|
|
ui::Engine::Ref().SetAltFullscreen(altFullscreen);
|
2019-02-18 21:18:29 -06:00
|
|
|
ui::Engine::Ref().SetForceIntegerScaling(forceIntegerScaling);
|
2020-10-10 14:57:29 -05:00
|
|
|
ui::Engine::Ref().SetMomentumScroll(momentumScroll);
|
2012-01-15 13:35:40 -06:00
|
|
|
|
2012-08-18 16:08:20 -05:00
|
|
|
engine = &ui::Engine::Ref();
|
2012-09-05 11:31:49 -05:00
|
|
|
engine->SetMaxSize(desktopWidth, desktopHeight);
|
2013-11-10 03:02:55 -06:00
|
|
|
engine->Begin(WINDOWW, WINDOWH);
|
2012-10-03 17:55:19 -05:00
|
|
|
engine->SetFastQuit(Client::Ref().GetPrefBool("FastQuit", true));
|
2012-01-17 14:46:06 -06:00
|
|
|
|
2013-07-10 15:59:10 -05:00
|
|
|
#if !defined(DEBUG) && !defined(_DEBUG)
|
2013-05-04 15:39:43 -05:00
|
|
|
//Get ready to catch any dodgy errors
|
|
|
|
signal(SIGSEGV, SigHandler);
|
|
|
|
signal(SIGFPE, SigHandler);
|
|
|
|
signal(SIGILL, SigHandler);
|
|
|
|
signal(SIGABRT, SigHandler);
|
2012-08-08 15:32:10 -05:00
|
|
|
#endif
|
2013-05-04 15:39:43 -05:00
|
|
|
|
2017-02-20 18:15:41 -06:00
|
|
|
#ifdef X86_SSE
|
2017-02-19 18:29:41 -06:00
|
|
|
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
|
2017-02-20 18:15:41 -06:00
|
|
|
#endif
|
|
|
|
#ifdef X86_SSE3
|
2017-02-19 18:29:41 -06:00
|
|
|
_MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
|
2017-02-20 18:15:41 -06:00
|
|
|
#endif
|
2017-02-19 18:29:41 -06:00
|
|
|
|
2013-05-04 15:39:43 -05:00
|
|
|
GameController * gameController = NULL;
|
2013-12-03 21:05:20 -06:00
|
|
|
#if !defined(DEBUG) && !defined(_DEBUG)
|
2013-05-04 15:39:43 -05:00
|
|
|
try {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
gameController = new GameController();
|
|
|
|
engine->ShowWindow(gameController->GetView());
|
|
|
|
|
|
|
|
if(arguments["open"].length())
|
2012-08-08 14:24:23 -05:00
|
|
|
{
|
2013-12-03 21:05:20 -06:00
|
|
|
#ifdef DEBUG
|
2013-05-04 15:39:43 -05:00
|
|
|
std::cout << "Loading " << arguments["open"] << std::endl;
|
2013-12-03 21:05:20 -06:00
|
|
|
#endif
|
2013-05-04 15:39:43 -05:00
|
|
|
if(Client::Ref().FileExists(arguments["open"]))
|
2012-08-08 14:24:23 -05:00
|
|
|
{
|
2013-05-04 15:39:43 -05:00
|
|
|
try
|
2012-08-08 14:24:23 -05:00
|
|
|
{
|
2013-05-04 15:39:43 -05:00
|
|
|
std::vector<unsigned char> gameSaveData = Client::Ref().ReadFile(arguments["open"]);
|
|
|
|
if(!gameSaveData.size())
|
|
|
|
{
|
|
|
|
new ErrorMessage("Error", "Could not read file");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SaveFile * newFile = new SaveFile(arguments["open"]);
|
|
|
|
GameSave * newSave = new GameSave(gameSaveData);
|
|
|
|
newFile->SetGameSave(newSave);
|
|
|
|
gameController->LoadSaveFile(newFile);
|
|
|
|
delete newFile;
|
|
|
|
}
|
|
|
|
|
2012-08-08 14:24:23 -05:00
|
|
|
}
|
2013-05-04 15:39:43 -05:00
|
|
|
catch(std::exception & e)
|
2012-08-08 14:24:23 -05:00
|
|
|
{
|
2018-04-30 13:13:24 -05:00
|
|
|
new ErrorMessage("Error", "Could not open save file:\n" + ByteString(e.what()).FromUtf8()) ;
|
2012-08-08 14:24:23 -05:00
|
|
|
}
|
|
|
|
}
|
2013-05-04 15:39:43 -05:00
|
|
|
else
|
2012-08-08 14:24:23 -05:00
|
|
|
{
|
2013-05-04 15:39:43 -05:00
|
|
|
new ErrorMessage("Error", "Could not open file");
|
2012-08-08 14:24:23 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-04 15:39:43 -05:00
|
|
|
if(arguments["ptsave"].length())
|
2012-08-08 15:32:10 -05:00
|
|
|
{
|
2013-05-04 15:39:43 -05:00
|
|
|
engine->g->fillrect((engine->GetWidth()/2)-101, (engine->GetHeight()/2)-26, 202, 52, 0, 0, 0, 210);
|
|
|
|
engine->g->drawrect((engine->GetWidth()/2)-100, (engine->GetHeight()/2)-25, 200, 50, 255, 255, 255, 180);
|
|
|
|
engine->g->drawtext((engine->GetWidth()/2)-(Graphics::textwidth("Loading save...")/2), (engine->GetHeight()/2)-5, "Loading save...", style::Colour::InformationTitle.Red, style::Colour::InformationTitle.Green, style::Colour::InformationTitle.Blue, 255);
|
|
|
|
|
2013-12-03 21:05:20 -06:00
|
|
|
#ifdef OGLI
|
2013-05-04 15:39:43 -05:00
|
|
|
blit();
|
2013-12-03 21:05:20 -06:00
|
|
|
#else
|
upgrade to SDL 2
Still currently in process, there are some issues:
Windows version doesn't work, mac version might not work, opengl might not work
Icon doesn't work (on Linux at least)
Lua will need some changes, there are some sdl 1.2 hacks in there
When entering fullscreen, the window loses focus
When holding down mouse out of bounds, mouse move events stop being sent
When letting go of mouse out of bounds, mouseup event doesn't take into account double scale mode
Clicking on startup without moving mouse will draw at 0,0 for a frame
Renderer probably won't compile because USE_SDL doesn't entirely work
... and maybe others
Some nice things were done though:
no more blit2, sdl can do the scaling itself
3d effect removed, no reason to support this joke any longer
No need to support copy/paste ourselves, sdl does it now
text handling done much better now, separate events for key presses and text input
when a new window is shown, all events ignored until next tick (ignore textinput event if window shown from key press event like console)
2018-04-15 17:53:02 -05:00
|
|
|
blit(engine->g->vid);
|
2013-12-03 21:05:20 -06:00
|
|
|
#endif
|
2018-04-30 13:13:24 -05:00
|
|
|
ByteString ptsaveArg = arguments["ptsave"];
|
2013-05-04 15:39:43 -05:00
|
|
|
try
|
2012-08-08 15:32:10 -05:00
|
|
|
{
|
2018-05-01 17:32:04 -05:00
|
|
|
ByteString saveIdPart;
|
|
|
|
if (ByteString::Split split = arguments["ptsave"].SplitBy(':'))
|
2013-05-04 15:39:43 -05:00
|
|
|
{
|
2018-05-01 17:32:04 -05:00
|
|
|
if (split.Before() != "ptsave")
|
|
|
|
throw std::runtime_error("Not a ptsave link");
|
|
|
|
saveIdPart = split.After().SplitBy('#').Before();
|
2013-05-04 15:39:43 -05:00
|
|
|
}
|
|
|
|
else
|
2018-05-01 17:32:04 -05:00
|
|
|
throw std::runtime_error("Invalid save link");
|
|
|
|
|
|
|
|
if (!saveIdPart.size())
|
2013-05-04 15:39:43 -05:00
|
|
|
throw std::runtime_error("No Save ID");
|
2015-08-29 12:14:17 -05:00
|
|
|
#ifdef DEBUG
|
2018-05-01 17:32:04 -05:00
|
|
|
std::cout << "Got Ptsave: id: " << saveIdPart << std::endl;
|
2015-08-29 12:14:17 -05:00
|
|
|
#endif
|
2018-05-04 15:10:39 -05:00
|
|
|
int saveId = saveIdPart.ToNumber<int>();
|
2015-08-29 12:14:17 -05:00
|
|
|
|
|
|
|
SaveInfo * newSave = Client::Ref().GetSave(saveId, 0);
|
|
|
|
if (!newSave)
|
|
|
|
throw std::runtime_error("Could not load save info");
|
|
|
|
std::vector<unsigned char> saveData = Client::Ref().GetSaveData(saveId, 0);
|
|
|
|
if (!saveData.size())
|
2018-04-30 13:13:24 -05:00
|
|
|
throw std::runtime_error(("Could not load save\n" + Client::Ref().GetLastError()).ToUtf8());
|
2015-08-29 12:14:17 -05:00
|
|
|
GameSave * newGameSave = new GameSave(saveData);
|
|
|
|
newSave->SetGameSave(newGameSave);
|
|
|
|
|
|
|
|
gameController->LoadSave(newSave);
|
|
|
|
delete newSave;
|
2013-05-04 15:39:43 -05:00
|
|
|
}
|
|
|
|
catch (std::exception & e)
|
2012-08-08 15:32:10 -05:00
|
|
|
{
|
2018-04-30 13:13:24 -05:00
|
|
|
new ErrorMessage("Error", ByteString(e.what()).FromUtf8());
|
2012-08-08 15:32:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-04 15:39:43 -05:00
|
|
|
EngineProcess();
|
|
|
|
SaveWindowPosition();
|
|
|
|
|
2013-12-03 21:05:20 -06:00
|
|
|
#if !defined(DEBUG) && !defined(_DEBUG)
|
2013-05-04 15:39:43 -05:00
|
|
|
}
|
2019-04-20 21:07:30 -05:00
|
|
|
catch(std::exception& e)
|
2013-05-04 15:39:43 -05:00
|
|
|
{
|
2018-05-01 17:32:04 -05:00
|
|
|
BlueScreen(ByteString(e.what()).FromUtf8());
|
2013-05-04 15:39:43 -05:00
|
|
|
}
|
2013-04-22 12:04:43 -05:00
|
|
|
#endif
|
2017-11-15 19:07:00 -06:00
|
|
|
|
2016-04-01 23:39:51 -05:00
|
|
|
Client::Ref().SetPref("Scale", ui::Engine::Ref().GetScale());
|
2012-01-21 07:19:10 -06:00
|
|
|
ui::Engine::Ref().CloseWindow();
|
|
|
|
delete gameController;
|
|
|
|
delete ui::Engine::Ref().g;
|
2012-06-21 19:04:55 -05:00
|
|
|
Client::Ref().Shutdown();
|
2021-01-06 08:46:39 -06:00
|
|
|
SDL_Quit();
|
2012-05-30 07:17:40 -05:00
|
|
|
return 0;
|
2012-01-08 11:39:03 -06:00
|
|
|
}
|