2018-04-12 21:02:51 +00:00
|
|
|
// SDL interface layer for the Build Engine
|
2013-10-06 07:49:53 +00:00
|
|
|
// Use SDL 1.2 or 2.0 from http://www.libsdl.org
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2020-01-06 01:41:47 +00:00
|
|
|
#ifdef _WIN32
|
2019-09-21 21:45:57 +00:00
|
|
|
#include <Windows.h>
|
2019-09-22 21:15:46 +00:00
|
|
|
#include <CommCtrl.h>
|
2020-01-06 01:41:47 +00:00
|
|
|
#endif
|
2009-08-03 22:15:53 +00:00
|
|
|
#include <signal.h>
|
2019-10-03 22:26:13 +00:00
|
|
|
#include <string>
|
2019-10-23 23:20:58 +00:00
|
|
|
#include <stdexcept>
|
2019-12-23 14:40:17 +00:00
|
|
|
# include "gl_load.h"
|
2018-11-18 18:09:48 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
#include "a.h"
|
|
|
|
#include "build.h"
|
2019-12-17 22:25:07 +00:00
|
|
|
|
2019-09-19 21:02:57 +00:00
|
|
|
#include "common.h"
|
2018-11-18 18:09:48 +00:00
|
|
|
#include "compat.h"
|
2015-01-11 04:52:15 +00:00
|
|
|
#include "engine_priv.h"
|
2018-11-18 18:09:48 +00:00
|
|
|
#include "osd.h"
|
2016-06-21 00:33:06 +00:00
|
|
|
#include "palette.h"
|
2019-12-29 16:04:38 +00:00
|
|
|
#include "baselayer.h"
|
2019-09-23 17:29:25 +00:00
|
|
|
#include "m_argv.h"
|
2019-09-25 21:00:10 +00:00
|
|
|
#include "mmulti.h"
|
2019-10-03 22:26:13 +00:00
|
|
|
#include "scriptfile.h"
|
|
|
|
#include "zstring.h"
|
2019-10-26 11:16:32 +00:00
|
|
|
#include "gameconfigfile.h"
|
|
|
|
#include "gamecontrol.h"
|
|
|
|
#include "resourcefile.h"
|
|
|
|
#include "sc_man.h"
|
2019-10-26 11:41:42 +00:00
|
|
|
#include "i_specialpaths.h"
|
2019-10-28 00:12:31 +00:00
|
|
|
#include "inputstate.h"
|
2019-10-27 12:40:24 +00:00
|
|
|
#include "c_cvars.h"
|
2019-11-04 19:29:07 +00:00
|
|
|
#include "i_time.h"
|
2019-11-05 19:07:16 +00:00
|
|
|
#include "c_dispatch.h"
|
2019-11-07 19:31:16 +00:00
|
|
|
#include "d_gui.h"
|
2019-12-05 20:39:02 +00:00
|
|
|
#include "menu.h"
|
2019-11-07 19:31:16 +00:00
|
|
|
#include "utf8.h"
|
|
|
|
#include "imgui.h"
|
|
|
|
#include "imgui_impl_sdl.h"
|
|
|
|
#include "imgui_impl_opengl3.h"
|
2018-06-13 19:15:16 +00:00
|
|
|
# include "glsurface.h"
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2018-11-18 18:09:48 +00:00
|
|
|
|
2011-07-20 23:04:20 +00:00
|
|
|
|
2019-11-10 10:42:25 +00:00
|
|
|
double g_beforeSwapTime;
|
2019-09-21 20:53:00 +00:00
|
|
|
GameInterface* gi;
|
|
|
|
|
2019-09-25 21:00:10 +00:00
|
|
|
int myconnectindex, numplayers;
|
|
|
|
int connecthead, connectpoint2[MAXMULTIPLAYERS];
|
2014-04-12 08:45:26 +00:00
|
|
|
|
2019-11-07 19:31:16 +00:00
|
|
|
void ImGui_Init_Backend()
|
|
|
|
{
|
2019-12-23 19:03:03 +00:00
|
|
|
//ImGui_ImplSDL2_InitForOpenGL(sdl_window, sdl_context);
|
2019-11-07 19:31:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ImGui_Begin_Frame()
|
|
|
|
{
|
2019-12-23 19:03:03 +00:00
|
|
|
//ImGui_ImplOpenGL3_NewFrame();
|
|
|
|
//ImGui_ImplSDL2_NewFrame(sdl_window);
|
|
|
|
//ImGui::NewFrame();
|
2019-11-07 19:31:16 +00:00
|
|
|
}
|
|
|
|
|
2020-01-01 11:36:48 +00:00
|
|
|
int32_t xres=-1, yres=-1, bpp=0, bytesperline, refreshfreq=-1;
|
2008-02-16 22:27:08 +00:00
|
|
|
intptr_t frameplace=0;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t lockcount=0;
|
2006-04-13 20:47:06 +00:00
|
|
|
char modechange=1;
|
|
|
|
char offscreenrendering=0;
|
2010-10-21 02:20:40 +00:00
|
|
|
|
2019-10-23 23:20:58 +00:00
|
|
|
#define MAX_ERRORTEXT 4096
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// I_Error
|
|
|
|
//
|
|
|
|
// Throw an error that will send us to the console if we are far enough
|
|
|
|
// along in the startup process.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
void I_Error(const char *error, ...)
|
|
|
|
{
|
|
|
|
va_list argptr;
|
|
|
|
char errortext[MAX_ERRORTEXT];
|
|
|
|
|
|
|
|
va_start(argptr, error);
|
2019-10-27 07:14:58 +00:00
|
|
|
vsnprintf(errortext, MAX_ERRORTEXT, error, argptr);
|
2019-10-23 23:20:58 +00:00
|
|
|
va_end(argptr);
|
|
|
|
#ifdef _WIN32
|
|
|
|
OutputDebugStringA(errortext);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
throw std::runtime_error(errortext);
|
|
|
|
}
|
2019-12-22 19:55:47 +00:00
|
|
|
|
|
|
|
void I_FatalError(const char* error, ...)
|
|
|
|
{
|
|
|
|
va_list argptr;
|
|
|
|
char errortext[MAX_ERRORTEXT];
|
|
|
|
|
|
|
|
va_start(argptr, error);
|
|
|
|
vsnprintf(errortext, MAX_ERRORTEXT, error, argptr);
|
|
|
|
va_end(argptr);
|
|
|
|
#ifdef _WIN32
|
|
|
|
OutputDebugStringA(errortext);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
throw std::runtime_error(errortext);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-01 11:01:26 +00:00
|
|
|
// Calculate ylookup[] and call setvlinebpl()
|
|
|
|
void calc_ylookup(int32_t bpl, int32_t lastyidx)
|
|
|
|
{
|
|
|
|
int32_t i, j = 0;
|
|
|
|
static int32_t ylookupsiz;
|
|
|
|
|
|
|
|
Bassert(lastyidx <= MAXYDIM);
|
|
|
|
|
|
|
|
lastyidx++;
|
|
|
|
|
|
|
|
if (lastyidx > ylookupsiz)
|
|
|
|
{
|
|
|
|
ylookup.Resize(lastyidx);
|
|
|
|
ylookupsiz = lastyidx;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i <= lastyidx - 4; i += 4)
|
|
|
|
{
|
|
|
|
ylookup[i] = j;
|
|
|
|
ylookup[i + 1] = j + bpl;
|
|
|
|
ylookup[i + 2] = j + (bpl << 1);
|
|
|
|
ylookup[i + 3] = j + (bpl * 3);
|
|
|
|
j += (bpl << 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; i < lastyidx; i++)
|
|
|
|
{
|
|
|
|
ylookup[i] = j;
|
|
|
|
j += bpl;
|
|
|
|
}
|
|
|
|
|
|
|
|
setvlinebpl(bpl);
|
|
|
|
}
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
//
|
|
|
|
// begindrawing() -- locks the framebuffer for drawing
|
|
|
|
//
|
2015-07-25 17:23:21 +00:00
|
|
|
|
2018-04-12 21:02:51 +00:00
|
|
|
void videoBeginDrawing(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-11-17 05:05:16 +00:00
|
|
|
if (bpp > 8)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if (offscreenrendering) return;
|
|
|
|
frameplace = 0;
|
|
|
|
bytesperline = 0;
|
|
|
|
modechange = 0;
|
|
|
|
return;
|
|
|
|
}
|
2018-06-13 19:15:16 +00:00
|
|
|
|
2018-06-28 02:00:42 +00:00
|
|
|
// lock the frame
|
|
|
|
if (lockcount++ > 0)
|
|
|
|
return;
|
|
|
|
|
2019-08-01 00:08:02 +00:00
|
|
|
static intptr_t backupFrameplace = 0;
|
2018-06-28 02:00:42 +00:00
|
|
|
|
2019-06-25 18:35:05 +00:00
|
|
|
if (inpreparemirror)
|
|
|
|
{
|
2019-08-01 00:08:02 +00:00
|
|
|
//POGO: if we are offscreenrendering and we need to render a mirror
|
|
|
|
// or we are rendering a mirror and we start offscreenrendering,
|
|
|
|
// backup our offscreen target so we can restore it later
|
|
|
|
// (but only allow one level deep,
|
|
|
|
// i.e. no viewscreen showing a camera showing a mirror that reflects the same viewscreen and recursing)
|
|
|
|
if (offscreenrendering)
|
|
|
|
{
|
|
|
|
if (!backupFrameplace)
|
|
|
|
backupFrameplace = frameplace;
|
2019-12-24 17:53:29 +00:00
|
|
|
else if (frameplace != (intptr_t)mirrorBuffer.Data() &&
|
2019-08-01 00:08:02 +00:00
|
|
|
frameplace != backupFrameplace)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-24 17:53:29 +00:00
|
|
|
frameplace = (intptr_t)mirrorBuffer.Data();
|
2019-08-01 00:08:02 +00:00
|
|
|
|
|
|
|
if (offscreenrendering)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (offscreenrendering)
|
|
|
|
{
|
|
|
|
if (backupFrameplace)
|
|
|
|
{
|
|
|
|
frameplace = backupFrameplace;
|
|
|
|
backupFrameplace = 0;
|
|
|
|
}
|
|
|
|
return;
|
2019-06-25 18:35:05 +00:00
|
|
|
}
|
|
|
|
else
|
2018-06-13 19:15:16 +00:00
|
|
|
frameplace = (intptr_t)glsurface_getBuffer();
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2018-07-14 21:36:44 +00:00
|
|
|
if (modechange)
|
2006-11-17 05:05:16 +00:00
|
|
|
{
|
2018-07-14 21:36:44 +00:00
|
|
|
bytesperline = xdim;
|
2012-12-14 19:28:17 +00:00
|
|
|
calc_ylookup(bytesperline, ydim);
|
2006-04-24 19:04:22 +00:00
|
|
|
modechange=0;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// enddrawing() -- unlocks the framebuffer
|
|
|
|
//
|
2018-04-12 21:02:51 +00:00
|
|
|
void videoEndDrawing(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2018-06-28 02:00:42 +00:00
|
|
|
if (bpp > 8)
|
2006-11-17 05:05:16 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!offscreenrendering) frameplace = 0;
|
|
|
|
return;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!frameplace) return;
|
2007-12-12 17:42:14 +00:00
|
|
|
if (lockcount > 1) { lockcount--; return; }
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!offscreenrendering) frameplace = 0;
|
|
|
|
if (lockcount == 0) return;
|
|
|
|
lockcount = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// ---------------------------------------
|
|
|
|
//
|
|
|
|
// Miscellany
|
|
|
|
//
|
|
|
|
// ---------------------------------------
|
|
|
|
//
|
2006-04-24 19:04:22 +00:00
|
|
|
//
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2019-09-22 21:15:46 +00:00
|
|
|
auto vsnprintfptr = vsnprintf; // This is an inline in Visual Studio but we need an address for it to satisfy the MinGW compiled libraries.
|
2019-11-20 19:07:33 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// debugprintf() -- sends a debug string to the debugger
|
|
|
|
//
|
|
|
|
void debugprintf(const char* f, ...)
|
|
|
|
{
|
|
|
|
va_list va;
|
2020-01-01 11:36:48 +00:00
|
|
|
va_start(va, f);
|
2019-11-20 19:07:33 +00:00
|
|
|
|
2020-01-01 11:36:48 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
if (!IsDebuggerPresent()) return;
|
|
|
|
|
|
|
|
char buf[1024];
|
|
|
|
vsnprintf(buf, 1024, f, va);
|
|
|
|
va_end(va);
|
|
|
|
OutputDebugStringA(buf);
|
|
|
|
#else
|
|
|
|
vprintf(f, va);
|
|
|
|
#endif
|
2019-11-20 19:07:33 +00:00
|
|
|
}
|
2019-11-23 22:05:24 +00:00
|
|
|
|