2006-04-23 06:44:19 +00:00
|
|
|
#include "compat.h"
|
|
|
|
#include "osd.h"
|
|
|
|
#include "build.h"
|
|
|
|
#include "baselayer.h"
|
|
|
|
|
2012-11-25 04:26:37 +00:00
|
|
|
#include "renderlayer.h"
|
2006-04-23 06:44:19 +00:00
|
|
|
|
2012-12-14 19:28:17 +00:00
|
|
|
#include "a.h"
|
2009-08-09 05:32:17 +00:00
|
|
|
#include "polymost.h"
|
2018-04-05 04:39:30 +00:00
|
|
|
#include "cache1d.h"
|
2019-10-28 00:12:31 +00:00
|
|
|
#include "inputstate.h"
|
2019-11-03 21:46:01 +00:00
|
|
|
#include "d_event.h"
|
2019-10-04 19:13:04 +00:00
|
|
|
#include "../../glbackend/glbackend.h"
|
2009-08-09 05:32:17 +00:00
|
|
|
|
2018-04-12 21:02:31 +00:00
|
|
|
// video
|
2018-04-12 21:02:18 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 0x00000001;
|
|
|
|
__declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
|
|
|
|
}
|
|
|
|
#endif // _WIN32
|
|
|
|
|
2019-08-29 19:00:52 +00:00
|
|
|
int32_t g_borderless=2;
|
2014-12-27 18:36:43 +00:00
|
|
|
|
2018-04-12 21:02:31 +00:00
|
|
|
// input
|
|
|
|
char inputdevices = 0;
|
2010-05-25 10:56:00 +00:00
|
|
|
|
2018-04-12 21:02:31 +00:00
|
|
|
vec2_t g_mousePos;
|
|
|
|
vec2_t g_mouseAbs;
|
|
|
|
int32_t g_mouseBits;
|
|
|
|
uint8_t g_mouseClickState;
|
|
|
|
|
|
|
|
bool g_mouseEnabled;
|
|
|
|
bool g_mouseGrabbed;
|
|
|
|
bool g_mouseInsideWindow = 1;
|
|
|
|
bool g_mouseLockedToWindow = 1;
|
|
|
|
|
|
|
|
void (*g_mouseCallback)(int32_t, int32_t);
|
|
|
|
void mouseSetCallback(void(*callback)(int32_t, int32_t)) { g_mouseCallback = callback; }
|
|
|
|
|
|
|
|
int32_t mouseAdvanceClickState(void)
|
2010-05-25 10:56:00 +00:00
|
|
|
{
|
2018-04-12 21:02:31 +00:00
|
|
|
switch (g_mouseClickState)
|
|
|
|
{
|
|
|
|
case MOUSE_PRESSED: g_mouseClickState = MOUSE_HELD; return 1;
|
|
|
|
case MOUSE_RELEASED: g_mouseClickState = MOUSE_IDLE; return 1;
|
|
|
|
case MOUSE_HELD: return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
2010-05-25 10:56:00 +00:00
|
|
|
}
|
|
|
|
|
2018-04-12 21:02:31 +00:00
|
|
|
void mouseReadPos(int32_t *x, int32_t *y)
|
2011-04-07 01:16:29 +00:00
|
|
|
{
|
2018-04-12 21:02:31 +00:00
|
|
|
if (!g_mouseEnabled || !g_mouseGrabbed || !appactive)
|
|
|
|
{
|
|
|
|
*x = *y = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
*x = g_mousePos.x;
|
|
|
|
*y = g_mousePos.y;
|
|
|
|
g_mousePos.x = g_mousePos.y = 0;
|
2011-04-07 01:16:29 +00:00
|
|
|
}
|
|
|
|
|
2018-04-12 21:02:31 +00:00
|
|
|
int32_t mouseReadAbs(vec2_t * const pResult, vec2_t const * const pInput)
|
2012-05-01 12:38:14 +00:00
|
|
|
{
|
2018-04-12 21:02:31 +00:00
|
|
|
if (!g_mouseEnabled || !appactive || !g_mouseInsideWindow || (osd && osd->flags & OSD_CAPTURE))
|
2014-11-17 07:39:12 +00:00
|
|
|
return 0;
|
|
|
|
|
2018-04-12 21:02:31 +00:00
|
|
|
int32_t const xwidth = max(scale(240<<16, xdim, ydim), 320<<16);
|
2014-11-17 07:39:12 +00:00
|
|
|
|
2018-07-14 21:36:44 +00:00
|
|
|
pResult->x = scale(pInput->x, xwidth, xres) - ((xwidth>>1) - (320<<15));
|
|
|
|
pResult->y = scale(pInput->y, 200<<16, yres);
|
2014-11-17 07:39:12 +00:00
|
|
|
|
2019-01-30 00:19:56 +00:00
|
|
|
pResult->y = divscale16(pResult->y - (200<<15), rotatesprite_yxaspect) + (200<<15) - rotatesprite_y_offset;
|
|
|
|
|
2014-11-17 07:39:12 +00:00
|
|
|
return 1;
|
2012-05-01 12:38:14 +00:00
|
|
|
}
|
|
|
|
|
2018-11-18 18:08:53 +00:00
|
|
|
int32_t mouseReadButtons(void)
|
2011-04-07 01:16:29 +00:00
|
|
|
{
|
2018-11-18 18:08:53 +00:00
|
|
|
return (!g_mouseEnabled || !appactive || !g_mouseInsideWindow || (osd && osd->flags & OSD_CAPTURE)) ? 0 : g_mouseBits;
|
2011-04-07 01:16:29 +00:00
|
|
|
}
|
|
|
|
|
2018-04-12 21:02:31 +00:00
|
|
|
controllerinput_t joystick;
|
|
|
|
|
|
|
|
void joySetCallback(void (*callback)(int32_t, int32_t)) { joystick.pCallback = callback; }
|
|
|
|
void joyReadButtons(int32_t *pResult) { *pResult = appactive ? joystick.bits : 0; }
|
2012-06-03 16:11:22 +00:00
|
|
|
|
2017-02-19 22:15:44 +00:00
|
|
|
#if defined __linux || defined EDUKE32_BSD || defined __APPLE__
|
2014-11-02 05:36:28 +00:00
|
|
|
# include <sys/mman.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-14 19:28:17 +00:00
|
|
|
// Calculate ylookup[] and call setvlinebpl()
|
|
|
|
void calc_ylookup(int32_t bpl, int32_t lastyidx)
|
|
|
|
{
|
|
|
|
int32_t i, j=0;
|
2014-11-06 23:43:47 +00:00
|
|
|
static int32_t ylookupsiz;
|
2014-11-02 05:36:28 +00:00
|
|
|
|
2012-12-14 19:28:17 +00:00
|
|
|
Bassert(lastyidx <= MAXYDIM);
|
|
|
|
|
2014-11-06 23:43:47 +00:00
|
|
|
lastyidx++;
|
|
|
|
|
2014-10-29 17:04:28 +00:00
|
|
|
if (lastyidx > ylookupsiz)
|
|
|
|
{
|
2019-06-25 11:29:08 +00:00
|
|
|
Xaligned_free(ylookup);
|
2014-10-29 17:04:28 +00:00
|
|
|
|
|
|
|
ylookup = (intptr_t *)Xaligned_alloc(16, lastyidx * sizeof(intptr_t));
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-11-06 23:43:47 +00:00
|
|
|
for (; i<lastyidx; i++)
|
2012-12-14 19:28:17 +00:00
|
|
|
{
|
|
|
|
ylookup[i] = j;
|
|
|
|
j += bpl;
|
|
|
|
}
|
|
|
|
|
|
|
|
setvlinebpl(bpl);
|
|
|
|
}
|
|
|
|
|
2014-11-02 05:36:28 +00:00
|
|
|
|
|
|
|
void makeasmwriteable(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-04-12 21:02:31 +00:00
|
|
|
int32_t g_logFlushWindow = 1;
|
2016-11-15 21:55:30 +00:00
|
|
|
|
2006-04-23 06:44:19 +00:00
|
|
|
#ifdef USE_OPENGL
|
2010-05-02 23:27:30 +00:00
|
|
|
struct glinfo_t glinfo =
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2009-09-30 01:26:13 +00:00
|
|
|
"Unknown", // vendor
|
|
|
|
"Unknown", // renderer
|
|
|
|
"0.0.0", // version
|
|
|
|
"", // extensions
|
|
|
|
|
|
|
|
1.0, // max anisotropy
|
2007-12-12 17:42:14 +00:00
|
|
|
};
|
2009-01-06 06:59:18 +00:00
|
|
|
|
2013-08-12 15:18:19 +00:00
|
|
|
// Used to register the game's / editor's osdcmd_vidmode() functions here.
|
2018-11-18 18:06:15 +00:00
|
|
|
int32_t (*baselayer_osdcmd_vidmode_func)(osdcmdptr_t parm);
|
2013-08-12 15:18:19 +00:00
|
|
|
|
2018-04-12 21:02:31 +00:00
|
|
|
|
2006-04-23 06:44:19 +00:00
|
|
|
#ifdef DEBUGGINGAIDS
|
2018-11-18 18:06:15 +00:00
|
|
|
static int osdcmd_hicsetpalettetint(osdcmdptr_t parm)
|
2006-04-23 06:44:19 +00:00
|
|
|
{
|
2017-12-12 05:13:58 +00:00
|
|
|
int32_t parms[8];
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2017-12-12 05:13:58 +00:00
|
|
|
if (parm->numparms < 1 || (int32_t)ARRAY_SIZE(parms) < parm->numparms) return OSDCMD_SHOWHELP;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2017-12-12 05:13:58 +00:00
|
|
|
size_t i;
|
|
|
|
for (i = 0; (int32_t)i < parm->numparms; ++i)
|
|
|
|
parms[i] = Batol(parm->parms[i]);
|
|
|
|
for (; i < ARRAY_SIZE(parms); ++i)
|
|
|
|
parms[i] = 0;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2017-12-12 05:13:58 +00:00
|
|
|
// order is intentional
|
|
|
|
hicsetpalettetint(parms[0],parms[1],parms[2],parms[3],parms[5],parms[6],parms[7],parms[4]);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
return OSDCMD_OK;
|
2006-04-23 06:44:19 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-11-18 18:06:15 +00:00
|
|
|
int osdcmd_glinfo(osdcmdptr_t UNUSED(parm))
|
2006-04-23 06:44:19 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
UNREFERENCED_CONST_PARAMETER(parm);
|
2008-03-22 10:23:57 +00:00
|
|
|
|
2015-02-11 05:23:04 +00:00
|
|
|
initprintf("OpenGL information\n %s %s %s\n",
|
2019-10-04 19:13:04 +00:00
|
|
|
GLInterface.glinfo.vendor, GLInterface.glinfo.renderer, GLInterface.glinfo.version);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
return OSDCMD_OK;
|
2006-04-23 06:44:19 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t baselayer_init(void)
|
2006-04-23 06:44:19 +00:00
|
|
|
{
|
2009-04-29 06:20:07 +00:00
|
|
|
|
2011-03-04 08:50:58 +00:00
|
|
|
#ifdef USE_OPENGL
|
2015-11-02 17:07:54 +00:00
|
|
|
|
2009-12-13 01:23:44 +00:00
|
|
|
# ifdef DEBUGGINGAIDS
|
|
|
|
OSD_RegisterFunction("hicsetpalettetint","hicsetpalettetint: sets palette tinting values",osdcmd_hicsetpalettetint);
|
|
|
|
# endif
|
2015-11-02 17:07:54 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
OSD_RegisterFunction("glinfo","glinfo: shows OpenGL information about the current OpenGL mode",osdcmd_glinfo);
|
2015-11-02 17:07:54 +00:00
|
|
|
|
2009-04-29 06:20:07 +00:00
|
|
|
polymost_initosdfuncs();
|
2006-04-23 06:44:19 +00:00
|
|
|
#endif
|
2009-04-29 06:20:07 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
return 0;
|
2006-04-23 06:44:19 +00:00
|
|
|
}
|
|
|
|
|