raze-gles/source/build/src/baselayer.cpp

205 lines
4.5 KiB
C++
Raw Normal View History

#include "compat.h"
#include "osd.h"
#include "build.h"
#include "baselayer.h"
#include "renderlayer.h"
#include "a.h"
#include "polymost.h"
#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"
#include "../../glbackend/glbackend.h"
// video
#ifdef _WIN32
extern "C"
{
__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 0x00000001;
__declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
}
#endif // _WIN32
int32_t g_borderless=2;
// input
char inputdevices = 0;
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)
{
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;
}
void mouseReadPos(int32_t *x, int32_t *y)
{
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;
}
int32_t mouseReadAbs(vec2_t * const pResult, vec2_t const * const pInput)
{
if (!g_mouseEnabled || !appactive || !g_mouseInsideWindow || (osd && osd->flags & OSD_CAPTURE))
return 0;
int32_t const xwidth = max(scale(240<<16, xdim, ydim), 320<<16);
pResult->x = scale(pInput->x, xwidth, xres) - ((xwidth>>1) - (320<<15));
pResult->y = scale(pInput->y, 200<<16, yres);
pResult->y = divscale16(pResult->y - (200<<15), rotatesprite_yxaspect) + (200<<15) - rotatesprite_y_offset;
return 1;
}
int32_t mouseReadButtons(void)
{
return (!g_mouseEnabled || !appactive || !g_mouseInsideWindow || (osd && osd->flags & OSD_CAPTURE)) ? 0 : g_mouseBits;
}
controllerinput_t joystick;
void joySetCallback(void (*callback)(int32_t, int32_t)) { joystick.pCallback = callback; }
void joyReadButtons(int32_t *pResult) { *pResult = appactive ? joystick.bits : 0; }
Massive menu input control revamp/cleanup/factor. (added: input.[ch]) New Wii control defaults for the Wii Remote + Nunchuk and the Classic Controller. This includes new code added just so that the Home key brings up the menu in-game, reducing the need for a USB keyboard. On the technical side, raw joystick access (comparable to what is available for keyboard and mouse) is now present in jmact, on the game side. (added: joystick.[ch]) Using this new raw joystick access, I replaced tueidj's hack to map A and B to LMB/RMB and D-Pad Up/Down to the scrollwheel. I made the menus more friendly to mouse and joystick browsing by adding and unifying checks and clears for various buttons and gamefuncs. In fact, the majority of the time spent on this commit was tracking down problems that appeared with the factoring and trying to understand the menu system and the way input checks are precariously executed. In addition, "Press any key or button to continue" now truly means what it says. As a result of incorporating proper raw access into control.c instead of it directly accessing the implementaiton, the program *may* no longer be affected by joystick input when it is out of focus. This follows the pattern set by the mouse, and I think this is a positive change. A small bonus: In the classic/old keyboard preset, the key for Show_Console has been changed from '`' to 'C' because '`' is taken by Quick_Kick. git-svn-id: https://svn.eduke32.com/eduke32@2728 1a8010ca-5511-0410-912e-c29ae57300e0
2012-06-03 16:11:22 +00:00
#if defined __linux || defined EDUKE32_BSD || defined __APPLE__
# include <sys/mman.h>
#endif
// 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)
{
Xaligned_free(ylookup);
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);
}
for (; i<lastyidx; i++)
{
ylookup[i] = j;
j += bpl;
}
setvlinebpl(bpl);
}
void makeasmwriteable(void)
{
}
int32_t g_logFlushWindow = 1;
#ifdef USE_OPENGL
struct glinfo_t glinfo =
{
"Unknown", // vendor
"Unknown", // renderer
"0.0.0", // version
"", // extensions
1.0, // max anisotropy
};
// Used to register the game's / editor's osdcmd_vidmode() functions here.
int32_t (*baselayer_osdcmd_vidmode_func)(osdcmdptr_t parm);
#ifdef DEBUGGINGAIDS
static int osdcmd_hicsetpalettetint(osdcmdptr_t parm)
{
int32_t parms[8];
if (parm->numparms < 1 || (int32_t)ARRAY_SIZE(parms) < parm->numparms) return OSDCMD_SHOWHELP;
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;
// order is intentional
hicsetpalettetint(parms[0],parms[1],parms[2],parms[3],parms[5],parms[6],parms[7],parms[4]);
return OSDCMD_OK;
}
#endif
int osdcmd_glinfo(osdcmdptr_t UNUSED(parm))
{
UNREFERENCED_CONST_PARAMETER(parm);
initprintf("OpenGL information\n %s %s %s\n",
GLInterface.glinfo.vendor, GLInterface.glinfo.renderer, GLInterface.glinfo.version);
return OSDCMD_OK;
}
#endif
int32_t baselayer_init(void)
{
#ifdef USE_OPENGL
# ifdef DEBUGGINGAIDS
OSD_RegisterFunction("hicsetpalettetint","hicsetpalettetint: sets palette tinting values",osdcmd_hicsetpalettetint);
# endif
OSD_RegisterFunction("glinfo","glinfo: shows OpenGL information about the current OpenGL mode",osdcmd_glinfo);
polymost_initosdfuncs();
#endif
return 0;
}