Commit 58c60799 authored by Libretro-Admin's avatar Libretro-Admin
Browse files

Remove non-libretro code

parent 1417a168
/***************************************************************************
Microsoft DirectX 8 Force Feedback (aka Haptic) Support
- Currently, SDL does not support haptic devices. So this is Win32 only.
- DirectX 8 still works on Windows XP, so I'm not attempting to support
a higher version for now.
Ref: http://msdn.microsoft.com/en-us/library/windows/desktop/ee417563%28v=vs.85%29.aspx
Copyright Chris White.
See license.txt for more details.
***************************************************************************/
#include "ffeedback.hpp"
//-----------------------------------------------------------------------------
// Dummy Functions For Non-Windows Builds
//-----------------------------------------------------------------------------
#ifndef WIN32
namespace forcefeedback
{
bool init(int a, int b, int c) { return false; } // Did not initialize
......@@ -25,288 +10,3 @@ namespace forcefeedback
int set(int x, int f) { return 0; }
bool is_supported() { return false; } // Not supported
};
//-----------------------------------------------------------------------------
// DirectX 8 Code Below
//-----------------------------------------------------------------------------
#else
// DirectX 8 Needed (Windows XP and up)
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>
#include <SDL_syswm.h> // Used to get window handle for DirectX
namespace forcefeedback
{
//-----------------------------------------------------------------------------
// Function prototypes
//-----------------------------------------------------------------------------
HRESULT InitDirectInput( HWND hDlg );
BOOL CALLBACK EnumFFDevicesCallback( const DIDEVICEINSTANCE* pInst, VOID* pContext );
BOOL CALLBACK EnumAxesCallback( const DIDEVICEOBJECTINSTANCE* pdidoi, VOID* pContext );
HRESULT InitForceEffects();
//-----------------------------------------------------------------------------
// Defines, constants, and global variables
//-----------------------------------------------------------------------------
#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
LPDIRECTINPUT8 g_pDI = NULL;
LPDIRECTINPUTDEVICE8 g_pDevice = NULL;
LPDIRECTINPUTEFFECT g_pEffect = NULL; // Force Feedback Effect
DWORD g_dwNumForceFeedbackAxis = 0;
bool g_supported = false; // Is Haptic Device Supported?
//-----------------------------------------------------------------------------
// User Configurable Values
//-----------------------------------------------------------------------------
int g_max_force; // Maximum Force To Apply (0 to DI_FFNOMINALMAX)
int g_min_force; // Minimum Force To Apply (0 to g_max_force)
int g_force_duration; // Length of each effect. (1/x seconds)
bool init(int max_force, int min_force, int force_duration)
{
g_max_force = max_force;
g_min_force = min_force;
g_force_duration = force_duration;
if (!g_supported)
{
// Platform Specific SDL code to get a window handle
SDL_SysWMinfo i;
SDL_VERSION(&i.version);
if (SDL_GetWMInfo(&i))
{
HWND hwnd = i.window;
InitDirectInput(hwnd);
}
}
return g_supported;
}
void close()
{
// Unacquire the device one last time just in case
// the app tried to exit while the device is still acquired.
if( g_pDevice )
g_pDevice->Unacquire();
// Release any DirectInput objects.
SAFE_RELEASE( g_pEffect );
SAFE_RELEASE( g_pDevice );
SAFE_RELEASE( g_pDI );
g_supported = false;
}
HRESULT InitDirectInput( HWND hDlg )
{
HRESULT hr;
// Register with the DirectInput subsystem and get a pointer
// to a IDirectInput interface we can use.
if( FAILED( hr = DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION,
IID_IDirectInput8, (VOID**)&g_pDI, NULL ) ) )
{
return hr;
}
// Look for a force feedback device we can use
if( FAILED( hr = g_pDI->EnumDevices(DI8DEVCLASS_GAMECTRL,
EnumFFDevicesCallback, NULL,
DIEDFL_ATTACHEDONLY | DIEDFL_FORCEFEEDBACK )))
{
return hr;
}
if( NULL == g_pDevice )
{
// Force Feedback Device Not Found
return S_OK;
}
// Set the data format to "simple joystick" - a predefined data format. A
// data format specifies which controls on a device we are interested in,
// and how they should be reported.
//
// This tells DirectInput that we will be passing a DIJOYSTATE structure to
// IDirectInputDevice8::GetDeviceState(). Even though we won't actually do
// it in this sample. But setting the data format is important so that the
// DIJOFS_* values work properly.
if( FAILED( hr = g_pDevice->SetDataFormat( &c_dfDIJoystick ) ) )
return hr;
// Set the cooperative level to let DInput know how this device should
// interact with the system and with other DInput applications.
// Exclusive access is required in order to perform force feedback.
if( FAILED( hr = g_pDevice->SetCooperativeLevel( hDlg,
DISCL_EXCLUSIVE |
DISCL_BACKGROUND ) ) )
{
return hr;
}
// Since we will be playing force feedback effects, we should disable the
// auto-centering spring.
DIPROPDWORD dipdw;
dipdw.diph.dwSize = sizeof(DIPROPDWORD);
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dipdw.diph.dwObj = 0;
dipdw.diph.dwHow = DIPH_DEVICE;
dipdw.dwData = FALSE;
if( FAILED( hr = g_pDevice->SetProperty( DIPROP_AUTOCENTER, &dipdw.diph ) ) )
return hr;
// Enumerate and count the axes of the joystick
if ( FAILED( hr = g_pDevice->EnumObjects( EnumAxesCallback,
(VOID*)&g_dwNumForceFeedbackAxis, DIDFT_AXIS ) ) )
return hr;
// We only support one/two axis joysticks
if( g_dwNumForceFeedbackAxis > 2 )
g_dwNumForceFeedbackAxis = 2;
g_pDevice->Acquire();
return InitForceEffects();
}
//-----------------------------------------------------------------------------
// Name: EnumAxesCallback()
// Desc: Callback function for enumerating the axes on a joystick and counting
// each force feedback enabled axis
//-----------------------------------------------------------------------------
BOOL CALLBACK EnumAxesCallback( const DIDEVICEOBJECTINSTANCE* pdidoi,
VOID* pContext )
{
DWORD* pdwNumForceFeedbackAxis = (DWORD*) pContext;
if( (pdidoi->dwFlags & DIDOI_FFACTUATOR) != 0 )
(*pdwNumForceFeedbackAxis)++;
return DIENUM_CONTINUE;
}
//-----------------------------------------------------------------------------
// Name: EnumFFDevicesCallback()
// Desc: Called once for each enumerated force feedback device. If we find
// one, create a device interface on it so we can play with it.
//-----------------------------------------------------------------------------
BOOL CALLBACK EnumFFDevicesCallback( const DIDEVICEINSTANCE* pInst,
VOID* pContext )
{
LPDIRECTINPUTDEVICE8 pDevice;
HRESULT hr;
// Obtain an interface to the enumerated force feedback device.
hr = g_pDI->CreateDevice( pInst->guidInstance, &pDevice, NULL );
// If it failed, then we can't use this device for some
// bizarre reason. (Maybe the user unplugged it while we
// were in the middle of enumerating it.) So continue enumerating
if( FAILED(hr) )
return DIENUM_CONTINUE;
// We successfully created an IDirectInputDevice8. So stop looking
// for another one.
g_pDevice = pDevice;
return DIENUM_STOP;
}
HRESULT InitForceEffects()
{
HRESULT hr;
// Cap Default Values
if (g_force_duration <= 0)
g_force_duration = 20;
DWORD dwAxes[2] = { DIJOFS_X, DIJOFS_Y };
LONG lDirection[2] = { 0, 0 };
DICONSTANTFORCE cf = { 0 };
DIEFFECT eff;
ZeroMemory( &eff, sizeof(eff) );
eff.dwSize = sizeof(DIEFFECT) ;
eff.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS; // Using X/Y style coords
eff.dwDuration = DI_SECONDS/g_force_duration; // Duration: 20th of a second (use INFINITE for never ending)
eff.dwSamplePeriod = 0;
eff.dwGain = DI_FFNOMINALMAX;
eff.dwTriggerButton = DIEB_NOTRIGGER;
eff.dwTriggerRepeatInterval = 0;
eff.cAxes = g_dwNumForceFeedbackAxis;
eff.rgdwAxes = dwAxes;
eff.rglDirection = lDirection;
eff.lpEnvelope = 0;
eff.cbTypeSpecificParams = sizeof(DICONSTANTFORCE);
eff.lpvTypeSpecificParams = &cf;
eff.dwStartDelay = 0;
if (FAILED(hr = g_pDevice->CreateEffect(GUID_ConstantForce, &eff, &g_pEffect, NULL)))
return hr;
if (g_pEffect == NULL)
return E_FAIL;
// Denote Force Feedback Device Found & Supported
g_supported = true;
return S_OK;
}
// xdirection = Direction to turn wheel in
// < 8: Left
// 8: Centre
// > 8: Right
// Higher force = Less aggressive steer
int set(int xdirection, int force)
{
if (!g_supported || g_pEffect == NULL || force < 0)
return -1;
LONG lDirection[2] = { 0, 0 }; // centred by default
if (xdirection > 0x08) // push right
lDirection[0] = 1;
else if (xdirection < 0x08) // push left
lDirection[0] = -1;
// 7 possible force positions, so divide maximum amount to subtract by 7.
LONG magnitude = g_max_force - (((g_max_force-g_min_force) / 7) * force);
// Cap within range
if (magnitude > DI_FFNOMINALMAX)
magnitude = DI_FFNOMINALMAX;
else if (magnitude < -DI_FFNOMINALMAX)
magnitude = -DI_FFNOMINALMAX;
DICONSTANTFORCE cf; // Type-specific parameters
cf.lMagnitude = magnitude;
DIEFFECT eff;
ZeroMemory( &eff, sizeof(eff) );
eff.dwSize = sizeof(DIEFFECT);
eff.cbTypeSpecificParams = sizeof(DICONSTANTFORCE);
eff.lpvTypeSpecificParams = &cf;
eff.cAxes = g_dwNumForceFeedbackAxis;
eff.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS; // Using X/Y style coords
eff.rglDirection = lDirection;
return g_pEffect->SetParameters(&eff, DIEP_DIRECTION | DIEP_TYPESPECIFICPARAMS | DIEP_START);
}
// Is Haptic Device Supported?
bool is_supported()
{
return g_supported;
}
};
#endif
\ No newline at end of file
/***************************************************************************
Microsoft DirectX 8 Force Feedback (aka Haptic) Support
- Currently, SDL does not support haptic devices. So this is Win32 only.
- DirectX 8 still works on Windows XP, so I'm not attempting to support
a higher version for now.
Ref: http://msdn.microsoft.com/en-us/library/windows/desktop/ee417563%28v=vs.85%29.aspx
Copyright Chris White.
See license.txt for more details.
***************************************************************************/
......@@ -23,4 +14,4 @@ namespace forcefeedback
extern void close();
extern int set(int xdirection, int force);
extern bool is_supported();
};
\ No newline at end of file
};
......@@ -10,13 +10,7 @@
#pragma once
#ifdef SDL2
#include "sdl2/input.hpp"
#elif defined __LIBRETRO__
#include "libretro/input.hpp"
#else
#include "sdl/input.hpp"
#endif
#include "outrun.hpp"
......
......@@ -16,13 +16,7 @@
#include "cabdiag.hpp"
#ifdef SDL2
#include "sdl2/input.hpp"
#elif defined __LIBRETRO__
#include "libretro/input.hpp"
#else
#include "sdl/input.hpp"
#endif
#include "utils.hpp"
#include "../video.hpp"
......
......@@ -421,8 +421,6 @@ void Config::set_fps(int fps)
else
tick_fps = 60;
cannonball::frame_ms = 1000.0 / this->fps;
#ifdef COMPILE_SOUND_CODE
if (config.sound.enabled)
cannonball::audio.stop_audio();
......
......@@ -174,15 +174,8 @@ void Menu::populate()
menu_cannonboard.push_back(ENTRY_BACK);
menu_video.push_back(ENTRY_FPS);
#ifndef __LIBRETRO__
menu_video.push_back(ENTRY_FULLSCREEN);
#endif
menu_video.push_back(ENTRY_WIDESCREEN);
menu_video.push_back(ENTRY_HIRES);
#ifndef __LIBRETRO__
menu_video.push_back(ENTRY_SCALE);
menu_video.push_back(ENTRY_SCANLINES);
#endif
menu_video.push_back(ENTRY_BACK);
menu_sound.push_back(ENTRY_MUTE);
......@@ -196,10 +189,6 @@ void Menu::populate()
menu_controls.push_back(ENTRY_GEAR);
if (input.gamepad) menu_controls.push_back(ENTRY_ANALOG);
#ifndef __LIBRETRO__
menu_controls.push_back(ENTRY_REDEFKEY);
if (input.gamepad) menu_controls.push_back(ENTRY_REDEFJOY);
#endif
menu_controls.push_back(ENTRY_DSTEER);
menu_controls.push_back(ENTRY_DPEDAL);
menu_controls.push_back(ENTRY_BACK);
......@@ -649,11 +638,7 @@ void Menu::tick_menu()
{
if (++config.video.fps > 3)
{
#ifdef __LIBRETRO__
config.video.fps = 1;
#else
config.video.fps = 0;
#endif
}
config.set_fps(config.video.fps);
}
......@@ -862,12 +847,7 @@ void Menu::refresh_menu()
set_menu_text(ENTRY_HIRES, config.video.hires ? "ON" : "OFF");
else if (SELECTED(ENTRY_FPS))
{
#ifdef __LIBRETRO__
if (config.video.fps == 1) s = "ORIGINAL";
#else
if (config.video.fps == 0) s = "30 FPS";
else if (config.video.fps == 1) s = "ORIGINAL";
#endif
else if (config.video.fps == 2) s = "60 FPS";
else if (config.video.fps == 3) s = "120 FPS";
set_menu_text(ENTRY_FPS, s);
......
......@@ -6,13 +6,7 @@
See license.txt for more details.
***************************************************************************/
#ifdef SDL2
#include "sdl2/input.hpp"
#elif defined __LIBRETRO__
#include "libretro/input.hpp"
#else
#include "sdl/input.hpp"
#endif
#include "frontend/ttrial.hpp"
......
......@@ -119,7 +119,6 @@ void Audio::tick()
static unsigned SND_RATE = 44100;
int bytes_written = 0;
int newpos;
double bytes_per_ms;
if (!sound_enabled)
return;
......@@ -157,7 +156,6 @@ void Audio::tick()
uint8_t* mbuf8 = (uint8_t*) mix_buffer;
// produce samples from the sound emulation
bytes_per_ms = (bytes_per_sample) * (FREQ/1000.0);
bytes_written = (BITS == 8 ? samples_written : samples_written*2);
// now we copy the data into the buffer and adjust the positions
......
......@@ -36,7 +36,6 @@
using namespace cannonball;
int cannonball::state = STATE_BOOT;
double cannonball::frame_ms = 0;
int cannonball::frame = 0;
bool cannonball::tick_frame = true;
int cannonball::fps_counter = 0;
......
/***************************************************************************
Cannonball Main Entry Point.
Copyright Chris White.
See license.txt for more details.
***************************************************************************/
// Error reporting
#include <iostream>
// SDL Library
#include <SDL.h>
#ifndef SDL2
#pragma comment(lib, "SDLmain.lib") // Replace main with SDL_main
#endif
#pragma comment(lib, "SDL.lib")
#pragma comment(lib, "glu32.lib")
// SDL Specific Code
#if defined SDL2
#include "sdl2/timer.hpp"
#include "sdl2/input.hpp"
#else
#include "sdl/timer.hpp"
#include "sdl/input.hpp"
#endif
#include "video.hpp"
#include "romloader.hpp"
#include "trackloader.hpp"
#include "stdint.hpp"
#include "main.hpp"
#include "setup.hpp"
#include "engine/outrun.hpp"
#include "frontend/config.hpp"
#include "frontend/menu.hpp"
#include "cannonboard/interface.hpp"
#include "engine/oinputs.hpp"
#include "engine/ooutputs.hpp"
#include "engine/omusic.hpp"
// Direct X Haptic Support.
// Fine to include on non-windows builds as dummy functions used.
#include "directx/ffeedback.hpp"
// Initialize Shared Variables
using namespace cannonball;
int cannonball::state = STATE_BOOT;
double cannonball::frame_ms = 0;
int cannonball::frame = 0;
bool cannonball::tick_frame = true;
int cannonball::fps_counter = 0;
#ifdef COMPILE_SOUND_CODE
Audio cannonball::audio;
#endif
Menu* menu;
Interface cannonboard;
static void quit_func(int code)
{
#ifdef COMPILE_SOUND_CODE
audio.stop_audio();
#endif
input.close();
forcefeedback::close();
delete menu;
SDL_Quit();
exit(code);
}
static void process_events(void)
{
SDL_Event event;
// Grab all events from the queue.
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_KEYDOWN:
// Handle key presses.
if (event.key.keysym.sym == SDLK_ESCAPE)
state = STATE_QUIT;
else
input.handle_key_down(&event.key.keysym);
break;
case SDL_KEYUP:
input.handle_key_up(&event.key.keysym);
break;
case SDL_JOYAXISMOTION:
input.handle_joy_axis(&event.jaxis);
break;
case SDL_JOYBUTTONDOWN:
input.handle_joy_down(&event.jbutton);
break;
case SDL_JOYBUTTONUP:
input.handle_joy_up(&event.jbutton);
break;
case SDL_QUIT:
// Handle quit requests (like Ctrl-c).
state = STATE_QUIT;
break;
}
}
}
// Pause Engine
bool pause_engine;
static void tick()
{
frame++;
// Get CannonBoard Packet Data
Packet* packet = config.cannonboard.enabled ? cannonboard.get_packet() : NULL;
// Non standard FPS.
// Determine whether to tick the current frame.
if (config.fps != 30)
{
if (config.fps == 60)
tick_frame = frame & 1;
else if (config.fps == 120)
tick_frame = (frame & 3) == 1;
}
process_events();
if (tick_frame)
oinputs.tick(packet); // Do Controls
oinputs.do_gear(); // Digital Gear
switch (state)
{
case STATE_GAME:
{
if (input.has_pressed(Input::TIMER))
outrun.freeze_timer = !outrun.freeze_timer;
if (input.has_pressed(Input::PAUSE))
pause_engine = !pause_engine;
if (input.has_pressed(Input::MENU))
state = STATE_INIT_MENU;
if (!pause_engine || input.has_pressed(Input::STEP))
{
outrun.tick(packet, tick_frame);
input.frame_done(); // Denote keys read
#ifdef COMPILE_SOUND_CODE
// Tick audio program code
osoundint.tick();