@@ -17,6 +17,10 @@ namespace lol | |||
* Safe enum helpers | |||
*/ | |||
map<int64_t, String> BuildEnumMap(String const &str, char const **custom) | |||
{ | |||
return BuildEnumMap(str.C(), custom); | |||
} | |||
map<int64_t, String> BuildEnumMap(char const *str, char const **custom) | |||
{ | |||
map<int64_t, String> ret; | |||
@@ -225,7 +225,7 @@ float AxisBinding::RetrieveCurrentValue() | |||
array<Controller*> Controller::controllers; | |||
Controller::Controller(char const* name, int nb_keys, int nb_axis) | |||
Controller::Controller(String const &name, int nb_keys, int nb_axis) | |||
{ | |||
m_gamegroup = GAMEGROUP_BEFORE; | |||
m_name = name; | |||
@@ -236,7 +236,7 @@ Controller::Controller(char const* name, int nb_keys, int nb_axis) | |||
m_active = false; | |||
if (Get(name) != nullptr) | |||
{ | |||
Log::Warn("controller “%s” has already been registered", name); | |||
Log::Warn("controller “%s” has already been registered", name.C()); | |||
} | |||
controllers.Push(this); | |||
} | |||
@@ -253,7 +253,7 @@ Controller::~Controller() | |||
} | |||
} | |||
Controller* Controller::Get(char const* name) | |||
Controller* Controller::Get(String const &name) | |||
{ | |||
for (int i = 0; i < controllers.Count(); ++i) | |||
{ | |||
@@ -35,10 +35,12 @@ public: | |||
/** Unbind a previously bound physical device and key. Returns true if the binding was existing. */ | |||
bool Unbind(const String& device_name, const String& key_name); | |||
/* Small helpers */ | |||
void BindMouse(const String& key_name) { Bind(g_name_mouse, key_name); } | |||
void BindKeyboard(const String& key_name) { Bind(g_name_keyboard, key_name); } | |||
bool UnbindMouse(const String& key_name) { return Unbind(g_name_mouse, key_name); } | |||
bool UnbindKeyboard(const String& key_name) { return Unbind(g_name_mouse, key_name); } | |||
void BindMouse(const String& key_name) { Bind(g_name_mouse, key_name); } | |||
void BindKeyboard(const String& key_name) { Bind(g_name_keyboard, key_name); } | |||
void BindJoystick(const uint64_t num, const String& key_name) { Bind(g_name_joystick(num), key_name); } | |||
bool UnbindMouse(const String& key_name) { return Unbind(g_name_mouse, key_name); } | |||
bool UnbindKeyboard(const String& key_name) { return Unbind(g_name_keyboard, key_name); } | |||
bool UnbindJoystick(const uint64_t num, const String& key_name) { return Unbind(g_name_joystick(num), key_name); } | |||
/** Clear current binding */ | |||
void ClearBindings(); | |||
/** Indicate wheither a physical device and key has been bound. Returns the number of bindings set. */ | |||
@@ -98,6 +100,13 @@ public: | |||
bool UnbindMouse(const String& axis_name) { return Unbind(g_name_mouse, axis_name); } | |||
bool UnbindMouseKey(const String& key_name) { return UnbindKey(g_name_mouse, key_name); } | |||
bool UnbindMouseKeys(const String& min_key_name, const String& max_key_name){ return UnbindKeys(g_name_mouse, min_key_name, max_key_name); } | |||
/* */ | |||
void BindJoystick(const uint64_t num, const String& axis_name) { Bind(g_name_joystick(num), axis_name); } | |||
void BindJoystickKey(const uint64_t num, const String& key_name) { BindKey(g_name_joystick(num), key_name); } | |||
void BindJoystickKeys(const uint64_t num, const String& min_key_name, const String& max_key_name) { BindKeys(g_name_joystick(num), min_key_name, max_key_name); } | |||
bool UnbindJoystick(const uint64_t num, const String& axis_name) { return Unbind(g_name_joystick(num), axis_name); } | |||
bool UnbindJoystickKey(const uint64_t num, const String& key_name) { return UnbindKey(g_name_joystick(num), key_name); } | |||
bool UnbindJoystickKeys(const uint64_t num, const String& min_key_name, const String& max_key_name){ return UnbindKeys(g_name_joystick(num), min_key_name, max_key_name); } | |||
/** Clear current binding */ | |||
void ClearBindings(); | |||
/** Indicate wheither a physical device and axis has been bound. Returns the number of bindings set. */ | |||
@@ -122,7 +131,7 @@ protected: | |||
class Controller : public Entity | |||
{ | |||
public: | |||
Controller(char const* name, int nb_keys, int nb_axis); | |||
Controller(String const &name, int nb_keys, int nb_axis); | |||
~Controller(); | |||
virtual void TickGame(float seconds); | |||
@@ -137,7 +146,7 @@ public: | |||
KeyBinding& GetKey(int index) { return m_keys[index]; } | |||
AxisBinding& GetAxis(int index) { return m_axis[index]; } | |||
static Controller* Get(char const* name); | |||
static Controller* Get(String const &name); | |||
protected: | |||
array<KeyBinding> m_keys; | |||
@@ -93,19 +93,19 @@ InputDeviceInternal* InputDeviceInternal::CreateStandardKeyboard() | |||
InputDeviceInternal* InputDeviceInternal::CreateStandardMouse() | |||
{ | |||
InputDeviceInternal* mouse = new InputDeviceInternal(g_name_mouse.C()); | |||
mouse->AddKey("Left"); | |||
mouse->AddKey("Middle"); | |||
mouse->AddKey("Right"); | |||
mouse->AddKey(g_name_mouse_key_left.C()); | |||
mouse->AddKey(g_name_mouse_key_middle.C()); | |||
mouse->AddKey(g_name_mouse_key_right.C()); | |||
//Added to manage if mouse is in the screen or not. | |||
mouse->AddKey("InScreen"); | |||
mouse->AddKey(g_name_mouse_key_inScreen.C()); | |||
mouse->AddAxis("X"); | |||
mouse->AddAxis("Y"); | |||
mouse->AddAxis("XPixel"); | |||
mouse->AddAxis("YPixel"); | |||
mouse->AddAxis("Scroll"); | |||
mouse->AddAxis(g_name_mouse_axis_x.C()); | |||
mouse->AddAxis(g_name_mouse_axis_y.C()); | |||
mouse->AddAxis(g_name_mouse_axis_xpixel.C()); | |||
mouse->AddAxis(g_name_mouse_axis_ypixel.C()); | |||
mouse->AddAxis(g_name_mouse_axis_scroll.C()); | |||
mouse->AddCursor("Cursor"); | |||
mouse->AddCursor(g_name_mouse_cursor.C()); | |||
// TODO: extended button, and wheel (as axis or as buttons? or both?) | |||
return mouse; | |||
@@ -13,8 +13,47 @@ | |||
namespace lol | |||
{ | |||
const String g_name_max("MAX"); | |||
const String g_name_mouse("Mouse"); | |||
const String g_name_keyboard("Keyboard"); | |||
static String g_name_joystick(const uint64_t num) | |||
{ | |||
return String::Printf("Joystick%i", num); | |||
} | |||
//Mouse default buttons/axis | |||
const String g_name_mouse_key_left("Left"); | |||
const String g_name_mouse_key_middle("Middle"); | |||
const String g_name_mouse_key_right("Right"); | |||
const String g_name_mouse_key_inScreen("InScreen"); | |||
const String g_name_mouse_axis_x("X"); | |||
const String g_name_mouse_axis_y("Y"); | |||
const String g_name_mouse_axis_xpixel("XPixel"); | |||
const String g_name_mouse_axis_ypixel("YPixel"); | |||
const String g_name_mouse_axis_scroll("Scroll"); | |||
const String g_name_mouse_cursor("Cursor"); | |||
//Xbox default buttons/axis | |||
const String g_name_xbox_key_dpad_up("DPadUp"); | |||
const String g_name_xbox_key_dpad_down("DPadDown"); | |||
const String g_name_xbox_key_dpad_left("DPadLeft"); | |||
const String g_name_xbox_key_dpad_right("DPadRight"); | |||
const String g_name_xbox_key_left_thumb("LeftThumb"); | |||
const String g_name_xbox_key_right_thumb("RightThumb"); | |||
const String g_name_xbox_key_left_shoulder("LeftShoulder"); | |||
const String g_name_xbox_key_right_shoulder("Rightshoulder"); | |||
const String g_name_xbox_key_a("A"); | |||
const String g_name_xbox_key_b("B"); | |||
const String g_name_xbox_key_x("X"); | |||
const String g_name_xbox_key_y("Y"); | |||
const String g_name_xbox_key_start("Start"); | |||
const String g_name_xbox_key_back("Back"); | |||
const String g_name_xbox_axis_left_x("Axis1"); | |||
const String g_name_xbox_axis_left_y("Axis2"); | |||
const String g_name_xbox_axis_right_x("Axis3"); | |||
const String g_name_xbox_axis_right_y("Axis4"); | |||
const String g_name_xbox_axis_left_trigger("Axis5"); | |||
const String g_name_xbox_axis_right_trigger("Axis6"); | |||
class InputDevice | |||
{ | |||
@@ -115,6 +154,20 @@ public: | |||
return GetDevice(name); | |||
} | |||
/** Default helpers */ | |||
static InputDevice* GetKeyboard() | |||
{ | |||
return GetDevice(g_name_keyboard); | |||
} | |||
static InputDevice* GetMouse() | |||
{ | |||
return GetDevice(g_name_mouse); | |||
} | |||
static InputDevice* GetJoystick(const uint64_t num) | |||
{ | |||
return GetDevice(g_name_joystick(num)); | |||
} | |||
/** Sets whether the mouse cursor should be captured. */ | |||
static void CaptureMouse(bool activated) | |||
{ | |||
@@ -146,7 +199,7 @@ protected: | |||
InputDevice(String const &name) : m_name(name) | |||
{ | |||
devices.Push(this); | |||
devices.PushUnique(this); | |||
} | |||
~InputDevice() | |||
@@ -17,6 +17,18 @@ namespace lol | |||
extern map<int64_t, String> BuildEnumMap(char const *str, char const **custom); | |||
class Enum | |||
{ | |||
public: | |||
template<typename T> | |||
static String EnumToString(T& parameter) | |||
{ | |||
//Create your own | |||
ASSERT(0); | |||
return String(); | |||
} | |||
}; | |||
template<typename BASE, typename T = typename BASE::Type> | |||
class SafeEnum : public BASE | |||
{ | |||
@@ -54,23 +54,28 @@ D3d9Input::D3d9Input() | |||
continue; | |||
// TODO: we can put more friendly name here, such as LeftAxisX, ButtonX... | |||
InputDeviceInternal* stick = new InputDeviceInternal(String::Printf("Joystick%d", i+1).C()); | |||
for (int j = 0; j < 4; ++j) | |||
stick->AddAxis(String::Printf("Axis%d", j+1).C()); | |||
stick->AddKey("DPadUp"); | |||
stick->AddKey("DPadDown"); | |||
stick->AddKey("DPadLeft"); | |||
stick->AddKey("DPadRight"); | |||
stick->AddKey("Start"); | |||
stick->AddKey("Back"); | |||
stick->AddKey("LeftThumb"); | |||
stick->AddKey("RightThumb"); | |||
stick->AddKey("LeftShoulder"); | |||
stick->AddKey("RightShoulder"); | |||
stick->AddKey("A"); | |||
stick->AddKey("B"); | |||
stick->AddKey("X"); | |||
stick->AddKey("Y"); | |||
stick->AddAxis(g_name_xbox_axis_left_x.C()); | |||
stick->AddAxis(g_name_xbox_axis_left_y.C()); | |||
stick->AddAxis(g_name_xbox_axis_right_x.C()); | |||
stick->AddAxis(g_name_xbox_axis_right_y.C()); | |||
stick->AddAxis(g_name_xbox_axis_left_trigger.C()); | |||
stick->AddAxis(g_name_xbox_axis_right_trigger.C()); | |||
stick->AddKey(g_name_xbox_key_dpad_up.C()); | |||
stick->AddKey(g_name_xbox_key_dpad_down.C()); | |||
stick->AddKey(g_name_xbox_key_dpad_left.C()); | |||
stick->AddKey(g_name_xbox_key_dpad_right.C()); | |||
stick->AddKey(g_name_xbox_key_start.C()); | |||
stick->AddKey(g_name_xbox_key_back.C()); | |||
stick->AddKey(g_name_xbox_key_left_thumb.C()); | |||
stick->AddKey(g_name_xbox_key_right_thumb.C()); | |||
stick->AddKey(g_name_xbox_key_left_shoulder.C()); | |||
stick->AddKey(g_name_xbox_key_right_shoulder.C()); | |||
stick->AddKey(g_name_xbox_key_a.C()); | |||
stick->AddKey(g_name_xbox_key_b.C()); | |||
stick->AddKey(g_name_xbox_key_x.C()); | |||
stick->AddKey(g_name_xbox_key_y.C()); | |||
m_data->m_joysticks.Push(i, stick); | |||
} | |||
@@ -107,6 +112,8 @@ void D3d9Input::TickGame(float seconds) | |||
m_data->m_joysticks[i].m2->SetAxis(1, -(float)state.Gamepad.sThumbLY / 32768.f); | |||
m_data->m_joysticks[i].m2->SetAxis(2, (float)state.Gamepad.sThumbRX / 32768.f); | |||
m_data->m_joysticks[i].m2->SetAxis(3, -(float)state.Gamepad.sThumbRY / 32768.f); | |||
m_data->m_joysticks[i].m2->SetAxis(4, (float)state.Gamepad.bLeftTrigger / 32768.f); | |||
m_data->m_joysticks[i].m2->SetAxis(5, (float)state.Gamepad.bRightTrigger / 32768.f); | |||
for (int b = 0; b < 16; b++) | |||
{ | |||
@@ -60,7 +60,6 @@ void Text::SetPos(vec3 pos) | |||
data->pos = pos; | |||
} | |||
vec3 Text::GetPos() | |||
{ | |||
return (vec3)data->pos; | |||
@@ -71,6 +70,12 @@ void Text::SetAlign(int align) | |||
data->align = align; | |||
} | |||
ivec2 Text::GetFontSize() | |||
{ | |||
Font *font = Forge::GetFont(data->font); | |||
return font->GetSize(); | |||
} | |||
void Text::TickDraw(float seconds, Scene &scene) | |||
{ | |||
Entity::TickDraw(seconds, scene); | |||
@@ -33,6 +33,7 @@ public: | |||
void SetPos(vec3 pos); | |||
vec3 GetPos(); | |||
void SetAlign(int align); | |||
ivec2 GetFontSize(); | |||
enum | |||
{ | |||