add crosshair effect (Harry Tuttle)

This commit is contained in:
Ian Curtis 2018-07-04 22:15:44 +00:00
parent 73ff32a10d
commit 80cf1f9b52

View file

@ -693,69 +693,91 @@ static void PrintGLError(GLenum error)
case GL_NO_ERROR: break; case GL_NO_ERROR: break;
default: printf("unknown error\n"); break; default: printf("unknown error\n"); break;
} }
} }
*/ */
static void UpdateCrosshairs(CInputs *Inputs, unsigned crosshairs) static void UpdateCrosshairs(uint32_t currentInputs, CInputs *Inputs, unsigned crosshairs)
{
float x[2], y[2]; {
bool offscreenTrigger[2];
crosshairs &= 3; float x[2], y[2];
if (!crosshairs)
return; crosshairs &= 3;
if (!crosshairs)
// Set up the viewport and orthogonal projection return;
glUseProgram(0); // no shaders
glViewport(xOffset, yOffset, xRes, yRes); // Set up the viewport and orthogonal projection
glUseProgram(0); // no shaders
glViewport(xOffset, yOffset, xRes, yRes);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
gluOrtho2D(0.0, 1.0, 1.0, 0.0); gluOrtho2D(0.0, 1.0, 1.0, 0.0);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
glDisable(GL_TEXTURE_2D); // no texture mapping glDisable(GL_TEXTURE_2D); // no texture mapping
glDisable(GL_BLEND); // no blending glDisable(GL_BLEND); // no blending
glDisable(GL_DEPTH_TEST); // no Z-buffering needed glDisable(GL_DEPTH_TEST); // no Z-buffering needed
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
// Convert gun coordinates to viewspace coordinates // Convert gun coordinates to viewspace coordinates
x[0] = (float) Inputs->gunX[0]->value; if (currentInputs & Game::INPUT_ANALOG_GUN1)
y[0] = (float) Inputs->gunY[0]->value; {
x[1] = (float) Inputs->gunX[1]->value; x[0] = ((float)Inputs->analogGunX[0]->value / 255.0f);
y[1] = (float) Inputs->gunY[1]->value; y[0] = ((255.0f - (float)Inputs->analogGunY[0]->value) / 255.0f);
GunToViewCoords(&x[0], &y[0]); offscreenTrigger[0] = Inputs->analogTriggerLeft[0]->value || Inputs->analogTriggerRight[0]->value;
GunToViewCoords(&x[1], &y[1]); }
else if (currentInputs & Game::INPUT_GUN1)
// Draw visible crosshairs {
glBegin(GL_TRIANGLES); x[0] = (float)Inputs->gunX[0]->value;
if ((crosshairs & 1) && !Inputs->trigger[0]->offscreenValue) // Player 1 y[0] = (float)Inputs->gunY[0]->value;
DrawCrosshair(x[0], y[0], 1.0f, 0.0f, 0.0f); GunToViewCoords(&x[0], &y[0]);
if ((crosshairs & 2) && !Inputs->trigger[1]->offscreenValue) // Player 2 offscreenTrigger[0] = (Inputs->trigger[0]->offscreenValue) > 0;
DrawCrosshair(x[1], y[1], 0.0f, 1.0f, 0.0f); }
glEnd(); if (currentInputs & Game::INPUT_ANALOG_GUN2)
{
//PrintGLError(glGetError()); x[1] = ((float)Inputs->analogGunX[1]->value / 255.0f);
} y[1] = ((255.0f - (float)Inputs->analogGunY[1]->value) / 255.0f);
offscreenTrigger[1] = Inputs->analogTriggerLeft[1]->value || Inputs->analogTriggerRight[1]->value;
}
else if (currentInputs & Game::INPUT_GUN2)
{
x[1] = (float)Inputs->gunX[1]->value;
y[1] = (float)Inputs->gunY[1]->value;
GunToViewCoords(&x[1], &y[1]);
offscreenTrigger[1] = (Inputs->trigger[1]->offscreenValue) > 0;
}
// Draw visible crosshairs
glBegin(GL_TRIANGLES);
if ((crosshairs & 1) && !offscreenTrigger[0]) // Player 1
DrawCrosshair(x[0], y[0], 1.0f, 0.0f, 0.0f);
if ((crosshairs & 2) && !offscreenTrigger[1]) // Player 2
DrawCrosshair(x[1], y[1], 0.0f, 1.0f, 0.0f);
glEnd();
//PrintGLError(glGetError());
}
/****************************************************************************** /******************************************************************************
Video Callbacks Video Callbacks
******************************************************************************/ ******************************************************************************/
static CInputs *videoInputs = NULL; static CInputs *videoInputs = NULL;
static uint32_t currentInputs = 0;
bool BeginFrameVideo()
{ bool BeginFrameVideo()
{
return true; return true;
} }
void EndFrameVideo() void EndFrameVideo()
{ {
// Show crosshairs for light gun games // Show crosshairs for light gun games
if (videoInputs) if (videoInputs)
UpdateCrosshairs(videoInputs, s_runtime_config["Crosshairs"].ValueAs<unsigned>()); UpdateCrosshairs(currentInputs, videoInputs, s_runtime_config["Crosshairs"].ValueAs<unsigned>());
// Swap the buffers // Swap the buffers
SDL_GL_SwapBuffers(); SDL_GL_SwapBuffers();
} }
static void SuperSleep(UINT32 time) static void SuperSleep(UINT32 time)
@ -816,12 +838,14 @@ int Supermodel(const Game &game, ROMSet *rom_set, IEmulator *Model3, CInputs *In
if (OKAY != OpenAudio()) if (OKAY != OpenAudio())
return 1; return 1;
// Hide mouse if fullscreen, enable crosshairs for gun games // Hide mouse if fullscreen, enable crosshairs for gun games
Inputs->GetInputSystem()->SetMouseVisibility(!s_runtime_config["FullScreen"].ValueAs<bool>()); Inputs->GetInputSystem()->SetMouseVisibility(!s_runtime_config["FullScreen"].ValueAs<bool>());
gameHasLightguns = !!(game.inputs & (Game::INPUT_GUN1|Game::INPUT_GUN2)); gameHasLightguns = !!(game.inputs & (Game::INPUT_GUN1|Game::INPUT_GUN2));
if (gameHasLightguns) gameHasLightguns |= game.name == "lostwsga";
videoInputs = Inputs; currentInputs = game.inputs;
else if (gameHasLightguns)
videoInputs = Inputs;
else
videoInputs = NULL; videoInputs = NULL;
// Attach the inputs to the emulator // Attach the inputs to the emulator