mirror of
https://github.com/DrBeef/QuestZDoom.git
synced 2024-11-10 15:01:48 +00:00
Many fixes / performance / positional tracking / STereo
This commit is contained in:
parent
ed700f7a70
commit
7970e5fce1
13 changed files with 189 additions and 739 deletions
|
@ -46,6 +46,8 @@ bool qzdoom_initialised;
|
|||
long long global_time;
|
||||
float playerHeight;
|
||||
float playerYaw;
|
||||
bool resetDoomYaw;
|
||||
float doomYaw;
|
||||
float vrFOV;
|
||||
vec3_t worldPosition;
|
||||
vec3_t hmdPosition;
|
||||
|
@ -91,7 +93,7 @@ PFNEGLGETSYNCATTRIBKHRPROC eglGetSyncAttribKHR;
|
|||
//Let's go to the maximum!
|
||||
int CPU_LEVEL = 4;
|
||||
int GPU_LEVEL = 4;
|
||||
int NUM_MULTI_SAMPLES = 1;
|
||||
int NUM_MULTI_SAMPLES = 2;
|
||||
float SS_MULTIPLIER = 1.0f;
|
||||
|
||||
jclass clazz;
|
||||
|
@ -148,6 +150,7 @@ LAMBDA1VR Stuff
|
|||
|
||||
//This is now controlled by the engine
|
||||
static bool useVirtualScreen = true;
|
||||
bool forceVirtualScreen = false;
|
||||
|
||||
void setUseScreenLayer(bool use)
|
||||
{
|
||||
|
@ -156,7 +159,7 @@ void setUseScreenLayer(bool use)
|
|||
|
||||
bool useScreenLayer()
|
||||
{
|
||||
return useVirtualScreen;
|
||||
return useVirtualScreen || forceVirtualScreen;
|
||||
}
|
||||
|
||||
static void UnEscapeQuotes( char *arg )
|
||||
|
@ -504,17 +507,6 @@ static void ovrFramebuffer_Clear( ovrFramebuffer * frameBuffer )
|
|||
|
||||
static bool ovrFramebuffer_Create( ovrFramebuffer * frameBuffer, const GLenum colorFormat, const int width, const int height, const int multisamples )
|
||||
{
|
||||
//LOAD_GLES2(glBindTexture);
|
||||
//LOAD_GLES2(glTexParameteri);
|
||||
//LOAD_GLES2(glGenRenderbuffers);
|
||||
//LOAD_GLES2(glBindRenderbuffer);
|
||||
//LOAD_GLES2(glRenderbufferStorage);
|
||||
//LOAD_GLES2(glGenFramebuffers);
|
||||
//LOAD_GLES2(glBindFramebuffer);
|
||||
//LOAD_GLES2(glFramebufferRenderbuffer);
|
||||
//LOAD_GLES2(glFramebufferTexture2D);
|
||||
//LOAD_GLES2(glCheckFramebufferStatus);
|
||||
|
||||
frameBuffer->Width = width;
|
||||
frameBuffer->Height = height;
|
||||
frameBuffer->Multisamples = multisamples;
|
||||
|
@ -529,31 +521,31 @@ static bool ovrFramebuffer_Create( ovrFramebuffer * frameBuffer, const GLenum co
|
|||
// Create the color buffer texture.
|
||||
const GLuint colorTexture = vrapi_GetTextureSwapChainHandle( frameBuffer->ColorTextureSwapChain, i );
|
||||
GLenum colorTextureTarget = GL_TEXTURE_2D;
|
||||
GL( /*gles_*/glBindTexture( colorTextureTarget, colorTexture ) );
|
||||
GL( glBindTexture( colorTextureTarget, colorTexture ) );
|
||||
// Just clamp to edge. However, this requires manually clearing the border
|
||||
// around the layer to clear the edge texels.
|
||||
GL( /*gles_*/glTexParameteri( colorTextureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ) );
|
||||
GL( /*gles_*/glTexParameteri( colorTextureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ) );
|
||||
GL( glTexParameteri( colorTextureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ) );
|
||||
GL( glTexParameteri( colorTextureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ) );
|
||||
|
||||
GL( /*gles_*/glTexParameteri( colorTextureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR ) );
|
||||
GL( /*gles_*/glTexParameteri( colorTextureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR ) );
|
||||
GL( /*gles_*/glBindTexture( colorTextureTarget, 0 ) );
|
||||
GL( glTexParameteri( colorTextureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR ) );
|
||||
GL( glTexParameteri( colorTextureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR ) );
|
||||
GL( glBindTexture( colorTextureTarget, 0 ) );
|
||||
|
||||
{
|
||||
{
|
||||
// Create depth buffer.
|
||||
GL( /*gles_*/glGenRenderbuffers( 1, &frameBuffer->DepthBuffers[i] ) );
|
||||
GL( /*gles_*/glBindRenderbuffer( GL_RENDERBUFFER, frameBuffer->DepthBuffers[i] ) );
|
||||
GL( /*gles_*/glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, frameBuffer->Width, frameBuffer->Height ) );
|
||||
GL( /*gles_*/glBindRenderbuffer( GL_RENDERBUFFER, 0 ) );
|
||||
GL( glGenRenderbuffers( 1, &frameBuffer->DepthBuffers[i] ) );
|
||||
GL( glBindRenderbuffer( GL_RENDERBUFFER, frameBuffer->DepthBuffers[i] ) );
|
||||
GL( glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, frameBuffer->Width, frameBuffer->Height ) );
|
||||
GL( glBindRenderbuffer( GL_RENDERBUFFER, 0 ) );
|
||||
|
||||
// Create the frame buffer.
|
||||
GL( /*gles_*/glGenFramebuffers( 1, &frameBuffer->FrameBuffers[i] ) );
|
||||
GL( /*gles_*/glBindFramebuffer( GL_DRAW_FRAMEBUFFER, frameBuffer->FrameBuffers[i] ) );
|
||||
GL( /*gles_*/glFramebufferRenderbuffer( GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, frameBuffer->DepthBuffers[i] ) );
|
||||
GL( /*gles_*/glFramebufferTexture2D( GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorTexture, 0 ) );
|
||||
GL( GLenum renderFramebufferStatus = /*gles_*/glCheckFramebufferStatus( GL_DRAW_FRAMEBUFFER ) );
|
||||
GL( /*gles_*/glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 ) );
|
||||
GL( glGenFramebuffers( 1, &frameBuffer->FrameBuffers[i] ) );
|
||||
GL( glBindFramebuffer( GL_DRAW_FRAMEBUFFER, frameBuffer->FrameBuffers[i] ) );
|
||||
GL( glFramebufferRenderbuffer( GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, frameBuffer->DepthBuffers[i] ) );
|
||||
GL( glFramebufferTexture2D( GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorTexture, 0 ) );
|
||||
GL( GLenum renderFramebufferStatus = glCheckFramebufferStatus( GL_DRAW_FRAMEBUFFER ) );
|
||||
GL( glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 ) );
|
||||
if ( renderFramebufferStatus != GL_FRAMEBUFFER_COMPLETE )
|
||||
{
|
||||
ALOGE( "Incomplete frame buffer object: %s", GlFrameBufferStatusString( renderFramebufferStatus ) );
|
||||
|
@ -568,11 +560,8 @@ static bool ovrFramebuffer_Create( ovrFramebuffer * frameBuffer, const GLenum co
|
|||
|
||||
void ovrFramebuffer_Destroy( ovrFramebuffer * frameBuffer )
|
||||
{
|
||||
//LOAD_GLES2(glDeleteFramebuffers);
|
||||
//LOAD_GLES2(glDeleteRenderbuffers);
|
||||
|
||||
GL( /*gles_*/glDeleteFramebuffers( frameBuffer->TextureSwapChainLength, frameBuffer->FrameBuffers ) );
|
||||
GL( /*gles_*/glDeleteRenderbuffers( frameBuffer->TextureSwapChainLength, frameBuffer->DepthBuffers ) );
|
||||
GL( glDeleteFramebuffers( frameBuffer->TextureSwapChainLength, frameBuffer->FrameBuffers ) );
|
||||
GL( glDeleteRenderbuffers( frameBuffer->TextureSwapChainLength, frameBuffer->DepthBuffers ) );
|
||||
|
||||
vrapi_DestroyTextureSwapChain( frameBuffer->ColorTextureSwapChain );
|
||||
|
||||
|
@ -584,14 +573,17 @@ void ovrFramebuffer_Destroy( ovrFramebuffer * frameBuffer )
|
|||
|
||||
void ovrFramebuffer_SetCurrent( ovrFramebuffer * frameBuffer )
|
||||
{
|
||||
//LOAD_GLES2(glBindFramebuffer);
|
||||
GL( /*gles_*/glBindFramebuffer( GL_DRAW_FRAMEBUFFER, frameBuffer->FrameBuffers[frameBuffer->ProcessingTextureSwapChainIndex] ) );
|
||||
while (glGetError() != GL_NO_ERROR)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
GL( glBindFramebuffer( GL_FRAMEBUFFER, frameBuffer->FrameBuffers[frameBuffer->ProcessingTextureSwapChainIndex] ) );
|
||||
}
|
||||
|
||||
void ovrFramebuffer_SetNone()
|
||||
{
|
||||
//LOAD_GLES2(glBindFramebuffer);
|
||||
GL( /*gles_*/glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 ) );
|
||||
GL( glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 ) );
|
||||
}
|
||||
|
||||
void ovrFramebuffer_Resolve( ovrFramebuffer * frameBuffer )
|
||||
|
@ -614,36 +606,29 @@ void ovrFramebuffer_Advance( ovrFramebuffer * frameBuffer )
|
|||
|
||||
void ovrFramebuffer_ClearEdgeTexels( ovrFramebuffer * frameBuffer )
|
||||
{
|
||||
//LOAD_GLES2(glEnable);
|
||||
//LOAD_GLES2(glDisable);
|
||||
//LOAD_GLES2(glViewport);
|
||||
//LOAD_GLES2(glScissor);
|
||||
//LOAD_GLES2(glClearColor);
|
||||
//LOAD_GLES2(glClear);
|
||||
|
||||
GL( /*gles_*/glEnable( GL_SCISSOR_TEST ) );
|
||||
GL( /*gles_*/glViewport( 0, 0, frameBuffer->Width, frameBuffer->Height ) );
|
||||
GL( glEnable( GL_SCISSOR_TEST ) );
|
||||
GL( glViewport( 0, 0, frameBuffer->Width, frameBuffer->Height ) );
|
||||
|
||||
// Explicitly clear the border texels to black because OpenGL-ES does not support GL_CLAMP_TO_BORDER.
|
||||
// Clear to fully opaque black.
|
||||
GL( /*gles_*/glClearColor( 0.0f, 0.0f, 0.0f, 1.0f ) );
|
||||
GL( glClearColor( 0.0f, 0.0f, 0.0f, 1.0f ) );
|
||||
|
||||
// bottom
|
||||
GL( /*gles_*/glScissor( 0, 0, frameBuffer->Width, 1 ) );
|
||||
GL( /*gles_*/glClear( GL_COLOR_BUFFER_BIT ) );
|
||||
GL( glScissor( 0, 0, frameBuffer->Width, 1 ) );
|
||||
GL( glClear( GL_COLOR_BUFFER_BIT ) );
|
||||
// top
|
||||
GL( /*gles_*/glScissor( 0, frameBuffer->Height - 1, frameBuffer->Width, 1 ) );
|
||||
GL( /*gles_*/glClear( GL_COLOR_BUFFER_BIT ) );
|
||||
GL( glScissor( 0, frameBuffer->Height - 1, frameBuffer->Width, 1 ) );
|
||||
GL( glClear( GL_COLOR_BUFFER_BIT ) );
|
||||
// left
|
||||
GL( /*gles_*/glScissor( 0, 0, 1, frameBuffer->Height ) );
|
||||
GL( /*gles_*/glClear( GL_COLOR_BUFFER_BIT ) );
|
||||
GL( glScissor( 0, 0, 1, frameBuffer->Height ) );
|
||||
GL( glClear( GL_COLOR_BUFFER_BIT ) );
|
||||
// right
|
||||
GL( /*gles_*/glScissor( frameBuffer->Width - 1, 0, 1, frameBuffer->Height ) );
|
||||
GL( /*gles_*/glClear( GL_COLOR_BUFFER_BIT ) );
|
||||
GL( glScissor( frameBuffer->Width - 1, 0, 1, frameBuffer->Height ) );
|
||||
GL( glClear( GL_COLOR_BUFFER_BIT ) );
|
||||
|
||||
|
||||
GL( /*gles_*/glScissor( 0, 0, 0, 0 ) );
|
||||
GL( /*gles_*/glDisable( GL_SCISSOR_TEST ) );
|
||||
GL( glScissor( 0, 0, 0, 0 ) );
|
||||
GL( glDisable( GL_SCISSOR_TEST ) );
|
||||
}
|
||||
|
||||
|
||||
|
@ -1274,6 +1259,7 @@ void VR_Init()
|
|||
{
|
||||
//Initialise all our variables
|
||||
playerYaw = 0.0f;
|
||||
resetDoomYaw = true;
|
||||
remote_movementSideways = 0.0f;
|
||||
remote_movementForward = 0.0f;
|
||||
remote_movementUp = 0.0f;
|
||||
|
@ -1655,6 +1641,8 @@ void submitFrame(ovrTracking2 *tracking)
|
|||
// Hand over the eye images to the time warp.
|
||||
vrapi_SubmitFrame2(gAppState.Ovr, &frameDesc);
|
||||
}
|
||||
|
||||
incrementFrameIndex();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -33,6 +33,8 @@ extern long long global_time;
|
|||
|
||||
extern float playerHeight;
|
||||
extern float playerYaw;
|
||||
extern bool resetDoomYaw;
|
||||
extern float doomYaw;
|
||||
|
||||
extern float vrFOV;
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ int getGameState();
|
|||
int isMenuActive();
|
||||
void Joy_GenerateButtonEvents(int oldbuttons, int newbuttons, int numbuttons, int base);
|
||||
|
||||
extern bool forceVirtualScreen;
|
||||
|
||||
void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew, ovrInputStateTrackedRemote *pDominantTrackedRemoteOld, ovrTracking* pDominantTracking,
|
||||
ovrInputStateTrackedRemote *pOffTrackedRemoteNew, ovrInputStateTrackedRemote *pOffTrackedRemoteOld, ovrTracking* pOffTracking,
|
||||
|
@ -30,12 +31,12 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
|
|||
|
||||
static bool dominantGripPushed = false;
|
||||
|
||||
//Show screen view (if in multiplayer toggle scoreboard)
|
||||
//Show screen view - for testing
|
||||
if (((pOffTrackedRemoteNew->Buttons & offButton2) !=
|
||||
(pOffTrackedRemoteOld->Buttons & offButton2)) &&
|
||||
(pOffTrackedRemoteNew->Buttons & offButton2)) {
|
||||
|
||||
|
||||
forceVirtualScreen = !forceVirtualScreen;
|
||||
}
|
||||
|
||||
//Menu button
|
||||
|
@ -146,9 +147,9 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
|
|||
pDominantTracking->HeadPose.Pose.Position.z);
|
||||
|
||||
vec2_t v;
|
||||
rotateAboutOrigin(-positionDeltaThisFrame[0], positionDeltaThisFrame[2], -(VR_GetRawYaw() + hmdorientation[YAW]), v);
|
||||
positional_movementSideways = v[0];
|
||||
positional_movementForward = v[1];
|
||||
rotateAboutOrigin(positionDeltaThisFrame[0], positionDeltaThisFrame[2], -(doomYaw - hmdorientation[YAW]), v);
|
||||
positional_movementSideways = v[1];
|
||||
positional_movementForward = v[0];
|
||||
|
||||
ALOGV(" positional_movementSideways: %f, positional_movementForward: %f",
|
||||
positional_movementSideways,
|
||||
|
@ -197,7 +198,8 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
|
|||
{
|
||||
if (increaseSnap)
|
||||
{
|
||||
snapTurn -= vr_snapturn_angle;
|
||||
resetDoomYaw = true;
|
||||
snapTurn -= vr_snapturn_angle;
|
||||
if (vr_snapturn_angle > 10.0f) {
|
||||
increaseSnap = false;
|
||||
}
|
||||
|
@ -216,6 +218,7 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
|
|||
{
|
||||
if (decreaseSnap)
|
||||
{
|
||||
resetDoomYaw = true;
|
||||
snapTurn += vr_snapturn_angle;
|
||||
|
||||
//If snap turn configured for less than 10 degrees
|
||||
|
@ -242,35 +245,43 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
|
|||
|
||||
|
||||
//Weapon Chooser
|
||||
static bool itemSwitched = false;
|
||||
static int itemSwitched = 0;
|
||||
if (between(-0.2f, pDominantTrackedRemoteNew->Joystick.x, 0.2f) &&
|
||||
(between(0.8f, pDominantTrackedRemoteNew->Joystick.y, 1.0f) ||
|
||||
between(-1.0f, pDominantTrackedRemoteNew->Joystick.y, -0.8f)))
|
||||
{
|
||||
if (!itemSwitched) {
|
||||
if (itemSwitched == 0) {
|
||||
if (between(0.8f, pDominantTrackedRemoteNew->Joystick.y, 1.0f))
|
||||
{
|
||||
C_DoCommandC("nextweap");
|
||||
C_DoCommandC("+nextweap");
|
||||
itemSwitched = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
C_DoCommandC("prevweap");
|
||||
C_DoCommandC("+prevweap");
|
||||
itemSwitched = 2;
|
||||
}
|
||||
|
||||
itemSwitched = true;
|
||||
}
|
||||
} else {
|
||||
itemSwitched = false;
|
||||
if (itemSwitched == 1)
|
||||
{
|
||||
C_DoCommandC("-nextweap");
|
||||
}
|
||||
else if (itemSwitched == 2)
|
||||
{
|
||||
C_DoCommandC("-prevweap");
|
||||
}
|
||||
itemSwitched = 0;
|
||||
}
|
||||
|
||||
//Dominant Hand - Primary keys (no grip pushed)
|
||||
Joy_GenerateButtonEvents(((pDominantTrackedRemoteOld->Buttons & ovrButton_Trigger) != 0) && !dominantGripPushedOld ? 1 : 0,
|
||||
((pDominantTrackedRemoteNew->Buttons & ovrButton_Trigger) != 0) && !dominantGripPushedNew ? 1 : 0,
|
||||
1, KEY_PAD_RTRIGGER);
|
||||
1, KEY_RCTRL);
|
||||
|
||||
Joy_GenerateButtonEvents(((pDominantTrackedRemoteOld->Buttons & domButton1) != 0) && !dominantGripPushedOld ? 1 : 0,
|
||||
((pDominantTrackedRemoteNew->Buttons & domButton1) != 0) && !dominantGripPushedNew ? 1 : 0,
|
||||
1, KEY_PAD_A);
|
||||
1, KEY_SPACE);
|
||||
|
||||
Joy_GenerateButtonEvents(((pDominantTrackedRemoteOld->Buttons & domButton2) != 0) && !dominantGripPushedOld ? 1 : 0,
|
||||
((pDominantTrackedRemoteNew->Buttons & domButton2) != 0) && !dominantGripPushedNew ? 1 : 0,
|
||||
|
@ -305,7 +316,7 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
|
|||
//Off Hand - Primary keys (no grip pushed)
|
||||
Joy_GenerateButtonEvents(((pOffTrackedRemoteOld->Buttons & ovrButton_Trigger) != 0) && !dominantGripPushedOld ? 1 : 0,
|
||||
((pOffTrackedRemoteNew->Buttons & ovrButton_Trigger) != 0) && !dominantGripPushedNew ? 1 : 0,
|
||||
1, KEY_PAD_LTRIGGER);
|
||||
1, KEY_LSHIFT);
|
||||
|
||||
Joy_GenerateButtonEvents(((pOffTrackedRemoteOld->Buttons & offButton1) != 0) && !dominantGripPushedOld ? 1 : 0,
|
||||
((pOffTrackedRemoteNew->Buttons & offButton1) != 0) && !dominantGripPushedNew ? 1 : 0,
|
||||
|
|
|
@ -259,8 +259,8 @@ void VectorVectors( const vec3_t forward, vec3_t right, vec3_t up )
|
|||
AngleVectors
|
||||
|
||||
=================
|
||||
|
||||
void GAME_EXPORT AngleVectors( const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up )
|
||||
*/
|
||||
void AngleVectors( const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up )
|
||||
{
|
||||
static float sr, sp, sy, cr, cp, cy;
|
||||
|
||||
|
@ -296,7 +296,7 @@ void GAME_EXPORT AngleVectors( const vec3_t angles, vec3_t forward, vec3_t right
|
|||
}
|
||||
}
|
||||
|
||||
*
|
||||
/*
|
||||
=================
|
||||
VectorAngles
|
||||
|
||||
|
|
|
@ -16,6 +16,11 @@ GNU General Public License for more details.
|
|||
#ifndef MATHLIB_H
|
||||
#define MATHLIB_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
@ -158,7 +163,7 @@ void SinCosFastVector2( float r1, float r2,
|
|||
float VectorNormalizeLength2( const vec3_t v, vec3_t out );
|
||||
void VectorVectors( const vec3_t forward, vec3_t right, vec3_t up );
|
||||
void VectorAngles( const float *forward, float *angles );
|
||||
//void AngleVectors( const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up );
|
||||
void AngleVectors( const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up );
|
||||
void VectorsAngles( const vec3_t forward, const vec3_t right, const vec3_t up, vec3_t angles );
|
||||
void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, float degrees );
|
||||
|
||||
|
@ -222,4 +227,8 @@ extern vec3_t vec3_origin;
|
|||
extern const matrix3x4 matrix3x4_identity;
|
||||
extern const matrix4x4 matrix4x4_identity;
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif//MATHLIB_H
|
||||
|
|
|
@ -5,7 +5,7 @@ include $(CLEAR_VARS)
|
|||
|
||||
LOCAL_MODULE := qzdoom
|
||||
|
||||
LOCAL_CFLAGS := -D__MOBILE__ -DNO_PIX_BUFF -DOPNMIDI_DISABLE_GX_EMULATOR -DGZDOOM -DLZDOOM -DUSE_GL_HW_BUFFERS -DNO_VBO -D__STDINT_LIMITS -DENGINE_NAME=\"lzdoom\"
|
||||
LOCAL_CFLAGS := -D__MOBILE__ -DNO_PIX_BUFF -DOPNMIDI_DISABLE_GX_EMULATOR -DGZDOOM -DLZDOOM -DUSE_GL_HW_BUFFERS -DNO_CLOCK_GETTIME -DNO_VBO -D__STDINT_LIMITS -DENGINE_NAME=\"lzdoom\"
|
||||
|
||||
|
||||
LOCAL_CPPFLAGS := -DHAVE_FLUIDSYNTH -DHAVE_MPG123 -DHAVE_SNDFILE -std=c++14 -DHAVE_JWZGLES -Wno-inconsistent-missing-override -Werror=format-security -fexceptions -fpermissive -Dstricmp=strcasecmp -Dstrnicmp=strncasecmp -D__forceinline=inline -DNO_GTK -DNO_SSE -fsigned-char
|
||||
|
|
|
@ -241,7 +241,7 @@ int lookspeed[2] = {450, 512};
|
|||
|
||||
#define SLOWTURNTICS 6
|
||||
|
||||
CVAR (Bool, cl_run, true, CVAR_GLOBALCONFIG|CVAR_ARCHIVE) // Always run?
|
||||
CVAR (Bool, cl_run, false, CVAR_GLOBALCONFIG|CVAR_ARCHIVE) // Always run?
|
||||
CVAR (Bool, invertmouse, false, CVAR_GLOBALCONFIG|CVAR_ARCHIVE) // Invert mouse look down/up?
|
||||
CVAR (Bool, freelook, true, CVAR_GLOBALCONFIG|CVAR_ARCHIVE) // Always mlook?
|
||||
CVAR (Bool, lookstrafe, false, CVAR_GLOBALCONFIG|CVAR_ARCHIVE) // Always strafe with mouse?
|
||||
|
@ -738,7 +738,7 @@ void G_BuildTiccmd (ticcmd_t *cmd)
|
|||
float dummy=0;
|
||||
|
||||
VR_GetMove(&joyforward, &joyside, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy);
|
||||
side += joyint(sidemove[speed] * -joyside);
|
||||
side += joyint(joyside * sidemove[speed]);
|
||||
forward += joyint(joyforward * forwardmove[speed]);
|
||||
|
||||
cmd->ucmd.pitch = LocalViewPitch >> 16;
|
||||
|
|
|
@ -808,7 +808,7 @@ void FGLRenderer::Flush()
|
|||
glScissor(mScreenViewport.left, mScreenViewport.top, mScreenViewport.width, mScreenViewport.height);
|
||||
|
||||
//Only adjust HUD if we are 3D and not showing menu (otherwise we are rendering to a cylinder compositor layer)
|
||||
if (!is2D && !isMenuActive()) stereo3dMode.getEyePose(eye_ix)->AdjustHud();
|
||||
//if (!is2D && !isMenuActive()) stereo3dMode.getEyePose(eye_ix)->AdjustHud();
|
||||
|
||||
m2DDrawer->Draw();
|
||||
FGLDebug::PopGroup();
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <string>
|
||||
#include <map>
|
||||
#include <cmath>
|
||||
#include <VrApi_Ext.h>
|
||||
#include "gl/system/gl_system.h"
|
||||
#include "doomtype.h" // Printf
|
||||
#include "d_player.h"
|
||||
|
@ -90,13 +91,13 @@ namespace s3d
|
|||
dispose();
|
||||
}
|
||||
|
||||
/*
|
||||
static void vSMatrixFromHmdMatrix34(VSMatrix& m1, const HmdMatrix34_t& m2)
|
||||
|
||||
static void vSMatrixFromOvrMatrix(VSMatrix& m1, const ovrMatrix4f& m2)
|
||||
{
|
||||
float tmp[16];
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
tmp[4 * i + j] = m2.m[i][j];
|
||||
tmp[4 * i + j] = m2.M[i][j];
|
||||
}
|
||||
}
|
||||
int i = 3;
|
||||
|
@ -105,7 +106,7 @@ namespace s3d
|
|||
}
|
||||
tmp[15] = 1;
|
||||
m1.loadMatrix(&tmp[0]);
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
/* virtual */
|
||||
|
@ -115,27 +116,23 @@ namespace s3d
|
|||
|
||||
// Pitch and Roll are identical between OpenVR and Doom worlds.
|
||||
// But yaw can differ, depending on starting state, and controller movement.
|
||||
float doomYawDegrees = VR_GetRawYaw() + hmdorientation[YAW];
|
||||
float doomYawDegrees = r_viewpoint.Angles.Yaw.Degrees;
|
||||
while (doomYawDegrees > 180)
|
||||
doomYawDegrees -= 360;
|
||||
while (doomYawDegrees < -180)
|
||||
doomYawDegrees += 360;
|
||||
|
||||
VSMatrix shiftMat;
|
||||
shiftMat.loadIdentity();
|
||||
vec3_t angles;
|
||||
VectorSet(angles, -GLRenderer->mAngles.Pitch.Degrees, doomYawDegrees, GLRenderer->mAngles.Roll.Degrees);
|
||||
|
||||
shiftMat.rotate(GLRenderer->mAngles.Roll.Degrees, 0, 1, 0);
|
||||
shiftMat.rotate(GLRenderer->mAngles.Pitch.Degrees, 1, 0, 0);
|
||||
shiftMat.rotate(-doomYawDegrees, 0, 0, 1);
|
||||
double pixelstretch = level.info ? level.info->pixelstretch : 1.2;
|
||||
shiftMat.scale(1.0, pixelstretch, 1.0);
|
||||
vec3_t v_forward, v_right, v_up;
|
||||
AngleVectors(angles, v_forward, v_right, v_up);
|
||||
|
||||
double mult = eye == 0 ? 1.0 : -1.0;
|
||||
float stereo_separation = (vr_ipd * 0.5) * vr_vunits_per_meter * (eye == 0 ? -1.0 : 1.0);
|
||||
vec3_t tmp;
|
||||
VectorScale(v_right, stereo_separation, tmp);
|
||||
|
||||
LSVec3 vec(0, (vr_ipd * 0.5) * vr_vunits_per_meter * mult, 0);
|
||||
LSMatrix44 mat(shiftMat);
|
||||
|
||||
LSVec3 eyeOffset = mat * vec;
|
||||
LSVec3 eyeOffset(tmp[0], tmp[1], tmp[2]);
|
||||
|
||||
// In vr, the real world floor level is at y==0
|
||||
// In Doom, the virtual player foot level is viewheight below the current viewpoint (on the Z axis)
|
||||
|
@ -153,7 +150,8 @@ namespace s3d
|
|||
/* virtual */
|
||||
VSMatrix OculusQuestEyePose::GetProjection(FLOATTYPE fov, FLOATTYPE aspectRatio, FLOATTYPE fovRatio) const
|
||||
{
|
||||
return EyePose::GetProjection(fov, aspectRatio, fovRatio);
|
||||
projection = EyePose::GetProjection(fov, aspectRatio, fovRatio);
|
||||
return projection;
|
||||
}
|
||||
|
||||
void OculusQuestEyePose::initialize()
|
||||
|
@ -192,7 +190,8 @@ namespace s3d
|
|||
vr_vunits_per_meter,
|
||||
-vr_vunits_per_meter);
|
||||
double pixelstretch = level.info ? level.info->pixelstretch : 1.2;
|
||||
new_projection.scale(pixelstretch, pixelstretch, 1.0); // Doom universe is scaled by 1990s pixel aspect ratio
|
||||
new_projection.scale(1.0, pixelstretch, 1.0); // Doom universe is scaled by 1990s pixel aspect ratio
|
||||
|
||||
|
||||
const OculusQuestEyePose * activeEye = this;
|
||||
|
||||
|
@ -210,10 +209,12 @@ namespace s3d
|
|||
float vrPitchDegrees = RAD2DEG(-eulerAnglesFromMatrix(activeEye->currentPose->mDeviceToAbsoluteTracking).v[1]);
|
||||
new_projection.rotate(-vrPitchDegrees, 1, 0, 0);
|
||||
}
|
||||
if (pitchOffset != 0)
|
||||
new_projection.rotate(-pitchOffset, 1, 0, 0);
|
||||
}*/
|
||||
|
||||
|
||||
if (pitchOffset != 0)
|
||||
new_projection.rotate(-pitchOffset, 1, 0, 0);
|
||||
|
||||
// hmd coordinates (meters) from ndc coordinates
|
||||
// const float weapon_distance_meters = 0.55f;
|
||||
// const float weapon_width_meters = 0.3f;
|
||||
|
@ -228,9 +229,13 @@ namespace s3d
|
|||
new_projection.translate(-1.0, 1.0, 0);
|
||||
new_projection.scale(2.0 / SCREENWIDTH, -2.0 / SCREENHEIGHT, -1.0);
|
||||
|
||||
// VSMatrix proj(activeEye->projectionMatrix);
|
||||
// proj.multMatrix(new_projection);
|
||||
// new_projection = proj;
|
||||
ovrTracking2 tracking;
|
||||
const OculusQuestMode * mode3d = static_cast<const OculusQuestMode*>(&Stereo3DMode::getCurrentMode());
|
||||
mode3d->getTracking(&tracking);
|
||||
|
||||
VSMatrix proj = projection;
|
||||
projection.multMatrix(new_projection);
|
||||
new_projection = proj;
|
||||
|
||||
return new_projection;
|
||||
}
|
||||
|
@ -313,7 +318,7 @@ namespace s3d
|
|||
{
|
||||
GetWeaponTransform(&gl_RenderState.mModelMatrix);
|
||||
|
||||
float scale = 0.00125f * vr_weaponScale;
|
||||
float scale = 0.000625f * vr_weaponScale;
|
||||
gl_RenderState.mModelMatrix.scale(scale, -scale, scale);
|
||||
gl_RenderState.mModelMatrix.translate(-viewwidth / 2, -viewheight * 3 / 4, 0.0f);
|
||||
|
||||
|
@ -337,26 +342,27 @@ namespace s3d
|
|||
|
||||
mat->scale(vr_vunits_per_meter, vr_vunits_per_meter, -vr_vunits_per_meter);
|
||||
|
||||
mat->rotate(-deltaYawDegrees - 180, 0, 1, 0);
|
||||
float doomYawDegrees = r_viewpoint.Angles.Yaw.Degrees;
|
||||
while (doomYawDegrees > 180)
|
||||
doomYawDegrees -= 360;
|
||||
while (doomYawDegrees < -180)
|
||||
doomYawDegrees += 360;
|
||||
|
||||
if ((vr_control_scheme < 10 && hand == 1)
|
||||
|| (vr_control_scheme > 10 && hand == 0)) {
|
||||
DVector3 weap(weaponoffset[0], weaponoffset[1], weaponoffset[2]);
|
||||
weap *= vr_vunits_per_meter;
|
||||
mat->translate(weap.X - hmdPosition[0], weap.Y - vr_floor_offset,
|
||||
weap.Z - hmdPosition[2]);
|
||||
mat->translate(-weaponoffset[0], hmdPosition[1] + weaponoffset[1] - vr_floor_offset, weaponoffset[2]);
|
||||
mat->rotate(-weaponangles[ROLL], 1, 0, 0);
|
||||
mat->rotate(-weaponangles[PITCH], 0, 1, 0);
|
||||
mat->rotate(-doomYawDegrees-weaponangles[YAW], 0, 0, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
DVector3 weap(offhandoffset[0], offhandoffset[1], offhandoffset[2]);
|
||||
weap *= vr_vunits_per_meter;
|
||||
mat->translate(weap.X - hmdPosition[0], weap.Y - vr_floor_offset,
|
||||
weap.Z - hmdPosition[2]);
|
||||
//mat->rotate(-offhandangles[ROLL], 1, 0, 0);
|
||||
//mat->rotate(-offhandangles[PITCH], 0, 1, 0);
|
||||
//mat->rotate(-offhandangles[YAW], 0, 0, 1);
|
||||
mat->translate(offhandoffset[0], hmdPosition[1] + offhandoffset[1] - vr_floor_offset, -offhandoffset[2]);
|
||||
}
|
||||
|
||||
//Perform roration here?
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -400,7 +406,6 @@ namespace s3d
|
|||
// Set VR-appropriate settings
|
||||
{
|
||||
movebob = 0;
|
||||
gl_billboard_faces_camera = true;
|
||||
}
|
||||
|
||||
if (gamestate == GS_LEVEL && !isMenuActive()) {
|
||||
|
@ -424,6 +429,19 @@ namespace s3d
|
|||
vr_walkdirection = !vr_moveFollowsOffHand;
|
||||
getTrackedRemotesOrientation(vr_control_scheme);
|
||||
|
||||
//Some crazy stuff to ascertain the actual yaw that doom is using at the right times!
|
||||
if (gamestate != GS_LEVEL || isMenuActive() || (gamestate == GS_LEVEL && resetDoomYaw))
|
||||
{
|
||||
doomYaw = r_viewpoint.Angles.Yaw.Degrees;
|
||||
if (gamestate == GS_LEVEL && resetDoomYaw) {
|
||||
resetDoomYaw = false;
|
||||
}
|
||||
if (gamestate != GS_LEVEL || isMenuActive())
|
||||
{
|
||||
resetDoomYaw = true;
|
||||
}
|
||||
}
|
||||
|
||||
player_t* player = r_viewpoint.camera ? r_viewpoint.camera->player : nullptr;
|
||||
{
|
||||
if (player)
|
||||
|
@ -478,6 +496,7 @@ namespace s3d
|
|||
VR_GetMove(&dummy, &dummy, &dummy, &dummy, &dummy, &yaw, &pitch, &roll);
|
||||
|
||||
//Yaw
|
||||
double hmdYawDeltaDegrees;
|
||||
{
|
||||
static double previousHmdYaw = 0;
|
||||
static bool havePreviousYaw = false;
|
||||
|
@ -485,7 +504,7 @@ namespace s3d
|
|||
previousHmdYaw = yaw;
|
||||
havePreviousYaw = true;
|
||||
}
|
||||
double hmdYawDeltaDegrees = yaw - previousHmdYaw;
|
||||
hmdYawDeltaDegrees = yaw - previousHmdYaw;
|
||||
G_AddViewAngle(mAngleFromRadians(DEG2RAD(-hmdYawDeltaDegrees)));
|
||||
previousHmdYaw = yaw;
|
||||
}
|
||||
|
@ -499,13 +518,18 @@ namespace s3d
|
|||
G_AddViewPitch(mAngleFromRadians(dPitch));
|
||||
}
|
||||
|
||||
if (gamestate == GS_LEVEL && !isMenuActive())
|
||||
{
|
||||
doomYaw += hmdYawDeltaDegrees;
|
||||
}
|
||||
|
||||
//Set all the render angles - including roll
|
||||
{
|
||||
//Always update roll (as the game tic cmd doesn't support roll
|
||||
GLRenderer->mAngles.Roll = roll;
|
||||
GLRenderer->mAngles.Pitch = pitch;
|
||||
|
||||
double viewYaw = yaw;
|
||||
double viewYaw = doomYaw;
|
||||
while (viewYaw <= -180.0)
|
||||
viewYaw += 360.0;
|
||||
while (viewYaw > 180.0)
|
||||
|
|
|
@ -66,6 +66,8 @@ protected:
|
|||
bool doFixPitch,
|
||||
float pitchOffset
|
||||
) const;
|
||||
|
||||
mutable VSMatrix projection;
|
||||
};
|
||||
|
||||
class OculusQuestMode : public Stereo3DMode
|
||||
|
|
|
@ -4496,7 +4496,13 @@ AActor *P_LineAttack(AActor *t1, DAngle angle, double distance,
|
|||
|
||||
DVector3 tempos;
|
||||
|
||||
if (flags & LAF_ABSPOSITION)
|
||||
|
||||
if (t1->player != NULL && t1->player->mo->OverrideAttackPosDir)
|
||||
{
|
||||
tempos = t1->player->mo->AttackPos;
|
||||
direction = t1->player->mo->AttackDir;
|
||||
}
|
||||
else if (flags & LAF_ABSPOSITION)
|
||||
{
|
||||
tempos = DVector3(offsetforward, offsetside, sz);
|
||||
}
|
||||
|
|
|
@ -1,590 +0,0 @@
|
|||
/*
|
||||
** i_input.cpp
|
||||
**
|
||||
**---------------------------------------------------------------------------
|
||||
** Copyright 2005-2016 Randy Heit
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions
|
||||
** are met:
|
||||
**
|
||||
** 1. Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** 2. Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in the
|
||||
** documentation and/or other materials provided with the distribution.
|
||||
** 3. The name of the author may not be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**---------------------------------------------------------------------------
|
||||
**
|
||||
*/
|
||||
#include <SDL.h>
|
||||
#include <ctype.h>
|
||||
#include "doomtype.h"
|
||||
#include "c_dispatch.h"
|
||||
#include "doomdef.h"
|
||||
#include "doomstat.h"
|
||||
#include "m_argv.h"
|
||||
#include "i_input.h"
|
||||
#include "v_video.h"
|
||||
|
||||
#include "d_main.h"
|
||||
#include "d_event.h"
|
||||
#include "d_gui.h"
|
||||
#include "c_console.h"
|
||||
#include "c_cvars.h"
|
||||
#include "i_system.h"
|
||||
#include "c_dispatch.h"
|
||||
#include "dikeys.h"
|
||||
#include "templates.h"
|
||||
#include "s_sound.h"
|
||||
#include "events.h"
|
||||
#include "utf8.h"
|
||||
|
||||
static void I_CheckGUICapture ();
|
||||
static void I_CheckNativeMouse ();
|
||||
|
||||
bool GUICapture;
|
||||
static bool NativeMouse = true;
|
||||
|
||||
extern int paused;
|
||||
|
||||
CVAR (Bool, use_mouse, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
||||
CVAR (Bool, m_noprescale, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
||||
CVAR (Bool, m_filter, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
||||
CVAR (Bool, i_soundinbackground, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
||||
|
||||
EXTERN_CVAR (Bool, fullscreen)
|
||||
|
||||
extern int WaitingForKey, chatmodeon;
|
||||
extern constate_e ConsoleState;
|
||||
|
||||
static const SDL_Keycode DIKToKeySym[256] =
|
||||
{
|
||||
0, SDLK_ESCAPE, SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5, SDLK_6,
|
||||
SDLK_7, SDLK_8, SDLK_9, SDLK_0,SDLK_MINUS, SDLK_EQUALS, SDLK_BACKSPACE, SDLK_TAB,
|
||||
SDLK_q, SDLK_w, SDLK_e, SDLK_r, SDLK_t, SDLK_y, SDLK_u, SDLK_i,
|
||||
SDLK_o, SDLK_p, SDLK_LEFTBRACKET, SDLK_RIGHTBRACKET, SDLK_RETURN, SDLK_LCTRL, SDLK_a, SDLK_s,
|
||||
SDLK_d, SDLK_f, SDLK_g, SDLK_h, SDLK_j, SDLK_k, SDLK_l, SDLK_SEMICOLON,
|
||||
SDLK_QUOTE, SDLK_BACKQUOTE, SDLK_LSHIFT, SDLK_BACKSLASH, SDLK_z, SDLK_x, SDLK_c, SDLK_v,
|
||||
SDLK_b, SDLK_n, SDLK_m, SDLK_COMMA, SDLK_PERIOD, SDLK_SLASH, SDLK_RSHIFT, SDLK_KP_MULTIPLY,
|
||||
SDLK_LALT, SDLK_SPACE, SDLK_CAPSLOCK, SDLK_F1, SDLK_F2, SDLK_F3, SDLK_F4, SDLK_F5,
|
||||
SDLK_F6, SDLK_F7, SDLK_F8, SDLK_F9, SDLK_F10, SDLK_NUMLOCKCLEAR, SDLK_SCROLLLOCK, SDLK_KP_7,
|
||||
SDLK_KP_8, SDLK_KP_9, SDLK_KP_MINUS, SDLK_KP_4, SDLK_KP_5, SDLK_KP_6, SDLK_KP_PLUS, SDLK_KP_1,
|
||||
SDLK_KP_2, SDLK_KP_3, SDLK_KP_0, SDLK_KP_PERIOD, 0, 0, 0, SDLK_F11,
|
||||
SDLK_F12, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, SDLK_F13, SDLK_F14, SDLK_F15, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, SDLK_KP_EQUALS, 0, 0,
|
||||
0, SDLK_AT, SDLK_COLON, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, SDLK_KP_ENTER, SDLK_RCTRL, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, SDLK_KP_COMMA, 0, SDLK_KP_DIVIDE, 0, SDLK_SYSREQ,
|
||||
SDLK_RALT, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, SDLK_PAUSE, 0, SDLK_HOME,
|
||||
SDLK_UP, SDLK_PAGEUP, 0, SDLK_LEFT, 0, SDLK_RIGHT, 0, SDLK_END,
|
||||
SDLK_DOWN, SDLK_PAGEDOWN, SDLK_INSERT, SDLK_DELETE, 0, 0, 0, 0,
|
||||
0, 0, 0, SDLK_LGUI, SDLK_RGUI, SDLK_MENU, SDLK_POWER, SDLK_SLEEP,
|
||||
0, 0, 0, 0, 0, SDLK_AC_SEARCH, SDLK_AC_BOOKMARKS, SDLK_AC_REFRESH,
|
||||
SDLK_AC_STOP, SDLK_AC_FORWARD, SDLK_AC_BACK, SDLK_COMPUTER, SDLK_MAIL, SDLK_MEDIASELECT, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
static const SDL_Scancode DIKToKeyScan[256] =
|
||||
{
|
||||
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_ESCAPE, SDL_SCANCODE_1, SDL_SCANCODE_2, SDL_SCANCODE_3, SDL_SCANCODE_4, SDL_SCANCODE_5, SDL_SCANCODE_6,
|
||||
SDL_SCANCODE_7, SDL_SCANCODE_8, SDL_SCANCODE_9, SDL_SCANCODE_0 ,SDL_SCANCODE_MINUS, SDL_SCANCODE_EQUALS, SDL_SCANCODE_BACKSPACE, SDL_SCANCODE_TAB,
|
||||
SDL_SCANCODE_Q, SDL_SCANCODE_W, SDL_SCANCODE_E, SDL_SCANCODE_R, SDL_SCANCODE_T, SDL_SCANCODE_Y, SDL_SCANCODE_U, SDL_SCANCODE_I,
|
||||
SDL_SCANCODE_O, SDL_SCANCODE_P, SDL_SCANCODE_LEFTBRACKET, SDL_SCANCODE_RIGHTBRACKET, SDL_SCANCODE_RETURN, SDL_SCANCODE_LCTRL, SDL_SCANCODE_A, SDL_SCANCODE_S,
|
||||
SDL_SCANCODE_D, SDL_SCANCODE_F, SDL_SCANCODE_G, SDL_SCANCODE_H, SDL_SCANCODE_J, SDL_SCANCODE_K, SDL_SCANCODE_L, SDL_SCANCODE_SEMICOLON,
|
||||
SDL_SCANCODE_APOSTROPHE, SDL_SCANCODE_GRAVE, SDL_SCANCODE_LSHIFT, SDL_SCANCODE_BACKSLASH, SDL_SCANCODE_Z, SDL_SCANCODE_X, SDL_SCANCODE_C, SDL_SCANCODE_V,
|
||||
SDL_SCANCODE_B, SDL_SCANCODE_N, SDL_SCANCODE_M, SDL_SCANCODE_COMMA, SDL_SCANCODE_PERIOD, SDL_SCANCODE_SLASH, SDL_SCANCODE_RSHIFT, SDL_SCANCODE_KP_MULTIPLY,
|
||||
SDL_SCANCODE_LALT, SDL_SCANCODE_SPACE, SDL_SCANCODE_CAPSLOCK, SDL_SCANCODE_F1, SDL_SCANCODE_F2, SDL_SCANCODE_F3, SDL_SCANCODE_F4, SDL_SCANCODE_F5,
|
||||
SDL_SCANCODE_F6, SDL_SCANCODE_F7, SDL_SCANCODE_F8, SDL_SCANCODE_F9, SDL_SCANCODE_F10, SDL_SCANCODE_NUMLOCKCLEAR, SDL_SCANCODE_SCROLLLOCK, SDL_SCANCODE_KP_7,
|
||||
SDL_SCANCODE_KP_8, SDL_SCANCODE_KP_9, SDL_SCANCODE_KP_MINUS, SDL_SCANCODE_KP_4, SDL_SCANCODE_KP_5, SDL_SCANCODE_KP_6, SDL_SCANCODE_KP_PLUS, SDL_SCANCODE_KP_1,
|
||||
SDL_SCANCODE_KP_2, SDL_SCANCODE_KP_3, SDL_SCANCODE_KP_0, SDL_SCANCODE_KP_PERIOD, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_F11,
|
||||
SDL_SCANCODE_F12, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN,
|
||||
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_F13, SDL_SCANCODE_F14, SDL_SCANCODE_F15, SDL_SCANCODE_UNKNOWN,
|
||||
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN,
|
||||
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN,
|
||||
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN,
|
||||
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN,
|
||||
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_KP_EQUALS, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN,
|
||||
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN,
|
||||
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_KP_ENTER, SDL_SCANCODE_RCTRL, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN,
|
||||
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN,
|
||||
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN,
|
||||
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_KP_COMMA, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_KP_DIVIDE, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_SYSREQ,
|
||||
SDL_SCANCODE_RALT, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN,
|
||||
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_PAUSE, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_HOME,
|
||||
SDL_SCANCODE_UP, SDL_SCANCODE_PAGEUP, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_LEFT, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_RIGHT, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_END,
|
||||
SDL_SCANCODE_DOWN, SDL_SCANCODE_PAGEDOWN, SDL_SCANCODE_INSERT, SDL_SCANCODE_DELETE, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN,
|
||||
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_LGUI, SDL_SCANCODE_RGUI, SDL_SCANCODE_MENU, SDL_SCANCODE_POWER, SDL_SCANCODE_SLEEP,
|
||||
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_AC_SEARCH, SDL_SCANCODE_AC_BOOKMARKS, SDL_SCANCODE_AC_REFRESH,
|
||||
SDL_SCANCODE_AC_STOP, SDL_SCANCODE_AC_FORWARD, SDL_SCANCODE_AC_BACK, SDL_SCANCODE_COMPUTER, SDL_SCANCODE_MAIL, SDL_SCANCODE_MEDIASELECT, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN,
|
||||
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN,
|
||||
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN
|
||||
};
|
||||
|
||||
static TMap<SDL_Keycode, uint8_t> InitKeySymMap ()
|
||||
{
|
||||
TMap<SDL_Keycode, uint8_t> KeySymToDIK;
|
||||
|
||||
for (int i = 0; i < 256; ++i)
|
||||
{
|
||||
KeySymToDIK[DIKToKeySym[i]] = i;
|
||||
}
|
||||
KeySymToDIK[0] = 0;
|
||||
KeySymToDIK[SDLK_RSHIFT] = DIK_LSHIFT;
|
||||
KeySymToDIK[SDLK_RCTRL] = DIK_LCONTROL;
|
||||
KeySymToDIK[SDLK_RALT] = DIK_LMENU;
|
||||
// Depending on your Linux flavor, you may get SDLK_PRINT or SDLK_SYSREQ
|
||||
KeySymToDIK[SDLK_PRINTSCREEN] = DIK_SYSRQ;
|
||||
|
||||
return KeySymToDIK;
|
||||
}
|
||||
static const TMap<SDL_Keycode, uint8_t> KeySymToDIK(InitKeySymMap());
|
||||
|
||||
static TMap<SDL_Scancode, uint8_t> InitKeyScanMap ()
|
||||
{
|
||||
TMap<SDL_Scancode, uint8_t> KeyScanToDIK;
|
||||
|
||||
for (int i = 0; i < 256; ++i)
|
||||
{
|
||||
KeyScanToDIK[DIKToKeyScan[i]] = i;
|
||||
}
|
||||
|
||||
return KeyScanToDIK;
|
||||
}
|
||||
static const TMap<SDL_Scancode, uint8_t> KeyScanToDIK(InitKeyScanMap());
|
||||
|
||||
static void I_CheckGUICapture ()
|
||||
{
|
||||
bool wantCapt;
|
||||
|
||||
if (menuactive == MENU_Off)
|
||||
{
|
||||
wantCapt = ConsoleState == c_down || ConsoleState == c_falling || chatmodeon;
|
||||
}
|
||||
else
|
||||
{
|
||||
wantCapt = (menuactive == MENU_On || menuactive == MENU_OnNoPause);
|
||||
}
|
||||
|
||||
// [ZZ] check active event handlers that want the UI processing
|
||||
if (!wantCapt && E_CheckUiProcessors())
|
||||
wantCapt = true;
|
||||
|
||||
if (wantCapt != GUICapture)
|
||||
{
|
||||
GUICapture = wantCapt;
|
||||
ResetButtonStates();
|
||||
}
|
||||
}
|
||||
|
||||
void I_SetMouseCapture()
|
||||
{
|
||||
// Clear out any mouse movement.
|
||||
SDL_GetRelativeMouseState (NULL, NULL);
|
||||
SDL_SetRelativeMouseMode (SDL_TRUE);
|
||||
#ifdef __MOBILE__
|
||||
// Need to clear this again because setting mode above adds relative values
|
||||
SDL_GetRelativeMouseState (NULL, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
void I_ReleaseMouseCapture()
|
||||
{
|
||||
SDL_SetRelativeMouseMode (SDL_FALSE);
|
||||
}
|
||||
|
||||
static void PostMouseMove (int x, int y)
|
||||
{
|
||||
static int lastx = 0, lasty = 0;
|
||||
event_t ev = { 0,0,0,0,0,0,0 };
|
||||
|
||||
if (m_filter)
|
||||
{
|
||||
ev.x = (x + lastx) / 2;
|
||||
ev.y = (y + lasty) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
ev.x = x;
|
||||
ev.y = y;
|
||||
}
|
||||
lastx = x;
|
||||
lasty = y;
|
||||
if (ev.x | ev.y)
|
||||
{
|
||||
ev.type = EV_Mouse;
|
||||
D_PostEvent (&ev);
|
||||
}
|
||||
}
|
||||
|
||||
static void MouseRead ()
|
||||
{
|
||||
int x, y;
|
||||
|
||||
if (NativeMouse)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_GetRelativeMouseState (&x, &y);
|
||||
if (!m_noprescale)
|
||||
{
|
||||
x *= 3;
|
||||
y *= 2;
|
||||
}
|
||||
if (x | y)
|
||||
{
|
||||
PostMouseMove (x, -y);
|
||||
}
|
||||
}
|
||||
|
||||
CUSTOM_CVAR(Int, mouse_capturemode, 1, CVAR_GLOBALCONFIG|CVAR_ARCHIVE)
|
||||
{
|
||||
if (self < 0) self = 0;
|
||||
else if (self > 2) self = 2;
|
||||
}
|
||||
|
||||
static bool inGame()
|
||||
{
|
||||
switch (mouse_capturemode)
|
||||
{
|
||||
default:
|
||||
case 0:
|
||||
return gamestate == GS_LEVEL;
|
||||
case 1:
|
||||
return gamestate == GS_LEVEL || gamestate == GS_INTERMISSION || gamestate == GS_FINALE;
|
||||
case 2:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
static void I_CheckNativeMouse ()
|
||||
{
|
||||
bool focus = SDL_GetKeyboardFocus() != NULL;
|
||||
bool fs = screen->IsFullscreen();
|
||||
|
||||
bool wantNative = !focus || (!use_mouse || GUICapture || paused || demoplayback || !inGame());
|
||||
|
||||
if (wantNative != NativeMouse)
|
||||
{
|
||||
NativeMouse = wantNative;
|
||||
SDL_ShowCursor (wantNative);
|
||||
if (wantNative)
|
||||
I_ReleaseMouseCapture ();
|
||||
else
|
||||
I_SetMouseCapture ();
|
||||
}
|
||||
}
|
||||
|
||||
void MessagePump (const SDL_Event &sev)
|
||||
{
|
||||
static int lastx = 0, lasty = 0;
|
||||
int x, y;
|
||||
event_t event = { 0,0,0,0,0,0,0 };
|
||||
|
||||
switch (sev.type)
|
||||
{
|
||||
case SDL_QUIT:
|
||||
exit (0);
|
||||
|
||||
case SDL_WINDOWEVENT:
|
||||
switch (sev.window.event)
|
||||
{
|
||||
extern bool AppActive;
|
||||
|
||||
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
||||
S_SetSoundPaused(1);
|
||||
AppActive = true;
|
||||
break;
|
||||
|
||||
case SDL_WINDOWEVENT_FOCUS_LOST:
|
||||
S_SetSoundPaused(i_soundinbackground);
|
||||
AppActive = false;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
if (!GUICapture)
|
||||
{
|
||||
event.type = sev.type == SDL_MOUSEBUTTONDOWN ? EV_KeyDown : EV_KeyUp;
|
||||
|
||||
switch (sev.button.button)
|
||||
{
|
||||
case SDL_BUTTON_LEFT: event.data1 = KEY_MOUSE1; break;
|
||||
case SDL_BUTTON_MIDDLE: event.data1 = KEY_MOUSE3; break;
|
||||
case SDL_BUTTON_RIGHT: event.data1 = KEY_MOUSE2; break;
|
||||
case SDL_BUTTON_X1: event.data1 = KEY_MOUSE4; break;
|
||||
case SDL_BUTTON_X2: event.data1 = KEY_MOUSE5; break;
|
||||
case 6: event.data1 = KEY_MOUSE6; break;
|
||||
case 7: event.data1 = KEY_MOUSE7; break;
|
||||
case 8: event.data1 = KEY_MOUSE8; break;
|
||||
default: printf("SDL mouse button %s %d\n",
|
||||
sev.type == SDL_MOUSEBUTTONDOWN ? "down" : "up", sev.button.button); break;
|
||||
}
|
||||
|
||||
if (event.data1 != 0)
|
||||
{
|
||||
D_PostEvent(&event);
|
||||
}
|
||||
}
|
||||
else if ((sev.button.button >= SDL_BUTTON_LEFT && sev.button.button <= SDL_BUTTON_X2))
|
||||
{
|
||||
int x, y;
|
||||
SDL_GetMouseState(&x, &y);
|
||||
|
||||
event.type = EV_GUI_Event;
|
||||
event.data1 = x;
|
||||
event.data2 = y;
|
||||
|
||||
screen->ScaleCoordsFromWindow(event.data1, event.data2);
|
||||
|
||||
if (sev.type == SDL_MOUSEBUTTONDOWN)
|
||||
{
|
||||
switch(sev.button.button)
|
||||
{
|
||||
case SDL_BUTTON_LEFT: event.subtype = EV_GUI_LButtonDown; break;
|
||||
case SDL_BUTTON_MIDDLE: event.subtype = EV_GUI_MButtonDown; break;
|
||||
case SDL_BUTTON_RIGHT: event.subtype = EV_GUI_RButtonDown; break;
|
||||
case SDL_BUTTON_X1: event.subtype = EV_GUI_BackButtonDown; break;
|
||||
case SDL_BUTTON_X2: event.subtype = EV_GUI_FwdButtonDown; break;
|
||||
default: assert(false); event.subtype = EV_GUI_None; break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(sev.button.button)
|
||||
{
|
||||
case SDL_BUTTON_LEFT: event.subtype = EV_GUI_LButtonUp; break;
|
||||
case SDL_BUTTON_MIDDLE: event.subtype = EV_GUI_MButtonUp; break;
|
||||
case SDL_BUTTON_RIGHT: event.subtype = EV_GUI_RButtonUp; break;
|
||||
case SDL_BUTTON_X1: event.subtype = EV_GUI_BackButtonUp; break;
|
||||
case SDL_BUTTON_X2: event.subtype = EV_GUI_FwdButtonUp; break;
|
||||
default: assert(false); event.subtype = EV_GUI_None; break;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Keymod kmod = SDL_GetModState();
|
||||
event.data3 = ((kmod & KMOD_SHIFT) ? GKM_SHIFT : 0) |
|
||||
((kmod & KMOD_CTRL) ? GKM_CTRL : 0) |
|
||||
((kmod & KMOD_ALT) ? GKM_ALT : 0);
|
||||
|
||||
D_PostEvent(&event);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_MOUSEMOTION:
|
||||
if (GUICapture)
|
||||
{
|
||||
event.data1 = sev.motion.x;
|
||||
event.data2 = sev.motion.y;
|
||||
|
||||
screen->ScaleCoordsFromWindow(event.data1, event.data2);
|
||||
|
||||
event.type = EV_GUI_Event;
|
||||
event.subtype = EV_GUI_MouseMove;
|
||||
|
||||
SDL_Keymod kmod = SDL_GetModState();
|
||||
event.data3 = ((kmod & KMOD_SHIFT) ? GKM_SHIFT : 0) |
|
||||
((kmod & KMOD_CTRL) ? GKM_CTRL : 0) |
|
||||
((kmod & KMOD_ALT) ? GKM_ALT : 0);
|
||||
|
||||
D_PostEvent(&event);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_MOUSEWHEEL:
|
||||
if (GUICapture)
|
||||
{
|
||||
event.type = EV_GUI_Event;
|
||||
|
||||
if (sev.wheel.y == 0)
|
||||
event.subtype = sev.wheel.x > 0 ? EV_GUI_WheelRight : EV_GUI_WheelLeft;
|
||||
else
|
||||
event.subtype = sev.wheel.y > 0 ? EV_GUI_WheelUp : EV_GUI_WheelDown;
|
||||
|
||||
SDL_Keymod kmod = SDL_GetModState();
|
||||
event.data3 = ((kmod & KMOD_SHIFT) ? GKM_SHIFT : 0) |
|
||||
((kmod & KMOD_CTRL) ? GKM_CTRL : 0) |
|
||||
((kmod & KMOD_ALT) ? GKM_ALT : 0);
|
||||
|
||||
D_PostEvent (&event);
|
||||
}
|
||||
else
|
||||
{
|
||||
event.type = EV_KeyDown;
|
||||
|
||||
if (sev.wheel.y != 0)
|
||||
event.data1 = sev.wheel.y > 0 ? KEY_MWHEELUP : KEY_MWHEELDOWN;
|
||||
else
|
||||
event.data1 = sev.wheel.x > 0 ? KEY_MWHEELRIGHT : KEY_MWHEELLEFT;
|
||||
|
||||
D_PostEvent (&event);
|
||||
event.type = EV_KeyUp;
|
||||
D_PostEvent (&event);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
if (!GUICapture)
|
||||
{
|
||||
if (sev.key.repeat)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
event.type = sev.type == SDL_KEYDOWN ? EV_KeyDown : EV_KeyUp;
|
||||
|
||||
// Try to look up our key mapped key for conversion to DirectInput.
|
||||
// If that fails, then we'll do a lookup against the scan code,
|
||||
// which may not return the right key, but at least the key should
|
||||
// work in the game.
|
||||
if (const uint8_t *dik = KeySymToDIK.CheckKey (sev.key.keysym.sym))
|
||||
event.data1 = *dik;
|
||||
else if (const uint8_t *dik = KeyScanToDIK.CheckKey (sev.key.keysym.scancode))
|
||||
event.data1 = *dik;
|
||||
|
||||
if (event.data1)
|
||||
{
|
||||
if (sev.key.keysym.sym < 256)
|
||||
{
|
||||
event.data2 = sev.key.keysym.sym;
|
||||
}
|
||||
D_PostEvent (&event);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
event.type = EV_GUI_Event;
|
||||
event.subtype = sev.type == SDL_KEYDOWN ? EV_GUI_KeyDown : EV_GUI_KeyUp;
|
||||
SDL_Keymod kmod = SDL_GetModState();
|
||||
event.data3 = ((kmod & KMOD_SHIFT) ? GKM_SHIFT : 0) |
|
||||
((kmod & KMOD_CTRL) ? GKM_CTRL : 0) |
|
||||
((kmod & KMOD_ALT) ? GKM_ALT : 0);
|
||||
|
||||
if (event.subtype == EV_GUI_KeyDown && sev.key.repeat)
|
||||
{
|
||||
event.subtype = EV_GUI_KeyRepeat;
|
||||
}
|
||||
|
||||
switch (sev.key.keysym.sym)
|
||||
{
|
||||
case SDLK_KP_ENTER: event.data1 = GK_RETURN; break;
|
||||
case SDLK_PAGEUP: event.data1 = GK_PGUP; break;
|
||||
case SDLK_PAGEDOWN: event.data1 = GK_PGDN; break;
|
||||
case SDLK_END: event.data1 = GK_END; break;
|
||||
case SDLK_HOME: event.data1 = GK_HOME; break;
|
||||
case SDLK_LEFT: event.data1 = GK_LEFT; break;
|
||||
case SDLK_RIGHT: event.data1 = GK_RIGHT; break;
|
||||
case SDLK_UP: event.data1 = GK_UP; break;
|
||||
case SDLK_DOWN: event.data1 = GK_DOWN; break;
|
||||
case SDLK_DELETE: event.data1 = GK_DEL; break;
|
||||
case SDLK_ESCAPE: event.data1 = GK_ESCAPE; break;
|
||||
case SDLK_F1: event.data1 = GK_F1; break;
|
||||
case SDLK_F2: event.data1 = GK_F2; break;
|
||||
case SDLK_F3: event.data1 = GK_F3; break;
|
||||
case SDLK_F4: event.data1 = GK_F4; break;
|
||||
case SDLK_F5: event.data1 = GK_F5; break;
|
||||
case SDLK_F6: event.data1 = GK_F6; break;
|
||||
case SDLK_F7: event.data1 = GK_F7; break;
|
||||
case SDLK_F8: event.data1 = GK_F8; break;
|
||||
case SDLK_F9: event.data1 = GK_F9; break;
|
||||
case SDLK_F10: event.data1 = GK_F10; break;
|
||||
case SDLK_F11: event.data1 = GK_F11; break;
|
||||
case SDLK_F12: event.data1 = GK_F12; break;
|
||||
case SDLK_SYSREQ: event.data1 = GK_SYSRQ; break;
|
||||
default:
|
||||
if (sev.key.keysym.sym < 256)
|
||||
{
|
||||
event.data1 = sev.key.keysym.sym;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (event.data1 < 128)
|
||||
{
|
||||
event.data1 = toupper(event.data1);
|
||||
D_PostEvent (&event);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_TEXTINPUT:
|
||||
if (GUICapture)
|
||||
{
|
||||
int size;
|
||||
|
||||
int unichar = utf8_decode((const uint8_t*)sev.text.text, &size);
|
||||
if (size != 4)
|
||||
{
|
||||
event.type = EV_GUI_Event;
|
||||
event.subtype = EV_GUI_Char;
|
||||
event.data1 = (int16_t)unichar;
|
||||
event.data2 = !!(SDL_GetModState() & KMOD_ALT);
|
||||
D_PostEvent (&event);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
case SDL_JOYBUTTONUP:
|
||||
if (!GUICapture)
|
||||
{
|
||||
event.type = sev.type == SDL_JOYBUTTONDOWN ? EV_KeyDown : EV_KeyUp;
|
||||
event.data1 = KEY_FIRSTJOYBUTTON + sev.jbutton.button;
|
||||
if(event.data1 != 0)
|
||||
D_PostEvent(&event);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void I_GetEvent ()
|
||||
{
|
||||
SDL_Event sev;
|
||||
|
||||
while (SDL_PollEvent (&sev))
|
||||
{
|
||||
MessagePump (sev);
|
||||
}
|
||||
if (use_mouse)
|
||||
{
|
||||
MouseRead ();
|
||||
}
|
||||
}
|
||||
|
||||
void I_StartTic ()
|
||||
{
|
||||
I_CheckGUICapture ();
|
||||
I_CheckNativeMouse ();
|
||||
I_GetEvent ();
|
||||
}
|
||||
|
||||
void I_ProcessJoysticks ();
|
||||
void I_StartFrame ()
|
||||
{
|
||||
I_ProcessJoysticks();
|
||||
}
|
|
@ -872,35 +872,33 @@ void DFrameBuffer::DrawRateStuff ()
|
|||
if (vid_fps)
|
||||
{
|
||||
uint64_t ms = screen->FrameTime;
|
||||
uint64_t howlong = ms - LastMS;
|
||||
if ((signed)howlong >= 0)
|
||||
{
|
||||
char fpsbuff[40];
|
||||
int chars;
|
||||
int rate_x;
|
||||
int rate_y;
|
||||
uint32_t howlong = ms - LastMS;
|
||||
if ((signed)howlong >= 0)
|
||||
{
|
||||
char fpsbuff[40];
|
||||
int chars;
|
||||
int rate_x;
|
||||
|
||||
int textScale = active_con_scale();
|
||||
int textScale = active_con_scale();
|
||||
|
||||
chars = mysnprintf (fpsbuff, countof(fpsbuff), "%2" PRIu64 " ms (%3" PRIu64 " fps)", howlong, LastCount);
|
||||
rate_x = (int)(Width/2.0) - (ConFont->StringWidth(&fpsbuff[0]) * textScale / 2.0);
|
||||
rate_y = (int)((Height/2.0));
|
||||
//Clear (rate_x, rate_y, ConFont->StringWidth(&fpsbuff[0]) * textScale, ConFont->GetHeight() * textScale, GPalette.BlackIndex, 0);
|
||||
DrawText (ConFont, CR_WHITE, rate_x, rate_y, (char *)&fpsbuff[0],
|
||||
DTA_VirtualWidth, screen->GetWidth() / textScale,
|
||||
DTA_VirtualHeight, screen->GetHeight() / textScale,
|
||||
DTA_KeepRatio, true, TAG_DONE);
|
||||
chars = mysnprintf (fpsbuff, countof(fpsbuff), "%2u ms (%3u fps)", howlong, LastCount);
|
||||
rate_x = Width / textScale - ConFont->StringWidth(&fpsbuff[0]);
|
||||
Clear (rate_x * textScale, 0, Width, ConFont->GetHeight() * textScale, GPalette.BlackIndex, 0);
|
||||
DrawText (ConFont, CR_WHITE, rate_x, 0, (char *)&fpsbuff[0],
|
||||
DTA_VirtualWidth, screen->GetWidth() / textScale,
|
||||
DTA_VirtualHeight, screen->GetHeight() / textScale,
|
||||
DTA_KeepRatio, true, TAG_DONE);
|
||||
|
||||
uint32_t thisSec = (uint32_t)(ms/1000);
|
||||
if (LastSec < thisSec)
|
||||
{
|
||||
LastCount = FrameCount / (thisSec - LastSec);
|
||||
LastSec = thisSec;
|
||||
FrameCount = 0;
|
||||
}
|
||||
FrameCount++;
|
||||
}
|
||||
LastMS = ms;
|
||||
uint32_t thisSec = ms/1000;
|
||||
if (LastSec < thisSec)
|
||||
{
|
||||
LastCount = FrameCount / (thisSec - LastSec);
|
||||
LastSec = thisSec;
|
||||
FrameCount = 0;
|
||||
}
|
||||
FrameCount++;
|
||||
}
|
||||
LastMS = ms;
|
||||
}
|
||||
|
||||
// draws little dots on the bottom of the screen
|
||||
|
|
Loading…
Reference in a new issue