2014-02-10 18:54:46 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2013-06-17 00:07:10 +00:00
|
|
|
|
2014-02-10 18:54:46 +00:00
|
|
|
#pragma once
|
2013-06-17 00:07:10 +00:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/Common.h"
|
2013-06-17 00:07:10 +00:00
|
|
|
|
|
|
|
// idk in case I wanted to change it to double or something, idk what's best
|
|
|
|
typedef float ControlState;
|
|
|
|
|
|
|
|
namespace ciface
|
|
|
|
{
|
|
|
|
namespace Core
|
|
|
|
{
|
|
|
|
|
|
|
|
// Forward declarations
|
|
|
|
class DeviceQualifier;
|
|
|
|
|
|
|
|
//
|
2014-01-31 00:51:21 +00:00
|
|
|
// Device
|
2013-06-17 00:07:10 +00:00
|
|
|
//
|
2014-01-31 00:51:21 +00:00
|
|
|
// A device class
|
2013-06-17 00:07:10 +00:00
|
|
|
//
|
|
|
|
class Device
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
class Input;
|
|
|
|
class Output;
|
|
|
|
|
|
|
|
//
|
2014-01-31 00:51:21 +00:00
|
|
|
// Control
|
2013-06-17 00:07:10 +00:00
|
|
|
//
|
2014-01-31 00:51:21 +00:00
|
|
|
// Control includes inputs and outputs
|
2013-06-17 00:07:10 +00:00
|
|
|
//
|
2014-01-31 00:51:21 +00:00
|
|
|
class Control // input or output
|
2013-06-17 00:07:10 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual std::string GetName() const = 0;
|
|
|
|
virtual ~Control() {}
|
|
|
|
|
2014-07-11 14:53:51 +00:00
|
|
|
bool InputGateOn();
|
|
|
|
|
2014-03-09 20:14:26 +00:00
|
|
|
virtual Input* ToInput() { return nullptr; }
|
|
|
|
virtual Output* ToOutput() { return nullptr; }
|
2013-06-17 00:07:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//
|
2014-01-31 00:51:21 +00:00
|
|
|
// Input
|
2013-06-17 00:07:10 +00:00
|
|
|
//
|
2014-01-31 00:51:21 +00:00
|
|
|
// An input on a device
|
2013-06-17 00:07:10 +00:00
|
|
|
//
|
|
|
|
class Input : public Control
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// things like absolute axes/ absolute mouse position will override this
|
|
|
|
virtual bool IsDetectable() { return true; }
|
|
|
|
|
|
|
|
virtual ControlState GetState() const = 0;
|
|
|
|
|
2014-07-11 14:53:51 +00:00
|
|
|
bool ShouldHaveInput();
|
|
|
|
|
|
|
|
ControlState GetGatedState()
|
|
|
|
{
|
|
|
|
if (InputGateOn())
|
|
|
|
return GetState();
|
|
|
|
else
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
2014-03-08 00:54:44 +00:00
|
|
|
Input* ToInput() override { return this; }
|
2013-06-17 00:07:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//
|
2014-01-31 00:51:21 +00:00
|
|
|
// Output
|
2013-06-17 00:07:10 +00:00
|
|
|
//
|
2014-01-31 00:51:21 +00:00
|
|
|
// An output on a device
|
2013-06-17 00:07:10 +00:00
|
|
|
//
|
|
|
|
class Output : public Control
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~Output() {}
|
|
|
|
|
|
|
|
virtual void SetState(ControlState state) = 0;
|
|
|
|
|
2014-07-11 14:53:51 +00:00
|
|
|
void SetGatedState(ControlState state)
|
|
|
|
{
|
|
|
|
if (InputGateOn())
|
|
|
|
SetState(state);
|
|
|
|
}
|
|
|
|
|
2014-03-08 00:54:44 +00:00
|
|
|
Output* ToOutput() override { return this; }
|
2013-06-17 00:07:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual ~Device();
|
|
|
|
|
|
|
|
virtual std::string GetName() const = 0;
|
|
|
|
virtual int GetId() const = 0;
|
|
|
|
virtual std::string GetSource() const = 0;
|
|
|
|
virtual bool UpdateInput() = 0;
|
|
|
|
virtual bool UpdateOutput() = 0;
|
|
|
|
|
|
|
|
virtual void ClearInputState();
|
|
|
|
|
|
|
|
const std::vector<Input*>& Inputs() const { return m_inputs; }
|
|
|
|
const std::vector<Output*>& Outputs() const { return m_outputs; }
|
|
|
|
|
|
|
|
Input* FindInput(const std::string& name) const;
|
|
|
|
Output* FindOutput(const std::string& name) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void AddInput(Input* const i);
|
|
|
|
void AddOutput(Output* const o);
|
|
|
|
|
|
|
|
class FullAnalogSurface : public Input
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FullAnalogSurface(Input* low, Input* high)
|
|
|
|
: m_low(*low), m_high(*high)
|
|
|
|
{}
|
|
|
|
|
2014-03-08 00:54:44 +00:00
|
|
|
ControlState GetState() const override
|
2013-06-17 00:07:10 +00:00
|
|
|
{
|
|
|
|
return (1 + m_high.GetState() - m_low.GetState()) / 2;
|
|
|
|
}
|
|
|
|
|
2014-03-08 00:54:44 +00:00
|
|
|
std::string GetName() const override
|
2013-06-17 00:07:10 +00:00
|
|
|
{
|
|
|
|
return m_low.GetName() + *m_high.GetName().rbegin();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Input& m_low;
|
|
|
|
Input& m_high;
|
|
|
|
};
|
|
|
|
|
|
|
|
void AddAnalogInputs(Input* low, Input* high)
|
|
|
|
{
|
|
|
|
AddInput(low);
|
|
|
|
AddInput(high);
|
|
|
|
AddInput(new FullAnalogSurface(low, high));
|
|
|
|
AddInput(new FullAnalogSurface(high, low));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-01-31 00:51:21 +00:00
|
|
|
std::vector<Input*> m_inputs;
|
|
|
|
std::vector<Output*> m_outputs;
|
2013-06-17 00:07:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//
|
2014-01-31 00:51:21 +00:00
|
|
|
// DeviceQualifier
|
2013-06-17 00:07:10 +00:00
|
|
|
//
|
2014-01-31 00:51:21 +00:00
|
|
|
// Device qualifier used to match devices.
|
|
|
|
// Currently has ( source, id, name ) properties which match a device
|
2013-06-17 00:07:10 +00:00
|
|
|
//
|
|
|
|
class DeviceQualifier
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DeviceQualifier() : cid(-1) {}
|
|
|
|
DeviceQualifier(const std::string& _source, const int _id, const std::string& _name)
|
|
|
|
: source(_source), cid(_id), name(_name) {}
|
|
|
|
void FromDevice(const Device* const dev);
|
|
|
|
void FromString(const std::string& str);
|
|
|
|
std::string ToString() const;
|
|
|
|
bool operator==(const DeviceQualifier& devq) const;
|
|
|
|
bool operator==(const Device* const dev) const;
|
|
|
|
|
2014-01-31 00:51:21 +00:00
|
|
|
std::string source;
|
|
|
|
int cid;
|
|
|
|
std::string name;
|
2013-06-17 00:07:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class DeviceContainer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Device::Input* FindInput(const std::string& name, const Device* def_dev) const;
|
|
|
|
Device::Output* FindOutput(const std::string& name, const Device* def_dev) const;
|
|
|
|
|
|
|
|
const std::vector<Device*>& Devices() const { return m_devices; }
|
|
|
|
Device* FindDevice(const DeviceQualifier& devq) const;
|
|
|
|
protected:
|
|
|
|
std::vector<Device*> m_devices;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|