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
|
|
|
|
|
|
|
#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"
|
2016-06-21 00:33:06 +00:00
|
|
|
#include "palette.h"
|
2019-12-29 16:04:38 +00:00
|
|
|
#include "baselayer.h"
|
2019-09-25 21:00:10 +00:00
|
|
|
#include "mmulti.h"
|
2020-01-12 13:54:43 +00:00
|
|
|
#include "glsurface.h"
|
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-12-22 19:55:47 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|