Skip to content

Commit

Permalink
Merge pull request #255 from macsforme/joystick_improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
macsforme authored Sep 19, 2023
2 parents ccc653e + dcc3d87 commit 57eefc3
Show file tree
Hide file tree
Showing 20 changed files with 686 additions and 81 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
BZFlag 2.4.27
-------------

* Improved joystick support - Joshua Bodine
* Cleaned up and updated the Xcode project file - Joshua Bodine
* Fixed yet another SDL2 window management regression on macOS - Joshua Bodine
* Remove non-SDL2 platform code and add SDL2 controller rumble support
Expand Down
4 changes: 4 additions & 0 deletions MSVC/build/bzflag.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ copy "$(BZ_DEPS)\licenses\*" "..\..\bin_$(Configuration)_$(Platform)\licenses\"<
<ItemGroup>
<ClCompile Include="..\..\src\bzflag\ActionBinding.cxx" />
<ClCompile Include="..\..\src\bzflag\AutoPilot.cxx" />
<ClCompile Include="..\..\src\bzflag\HUDuiJSTestLabel.cxx" />
<ClCompile Include="..\..\src\bzflag\JoystickTestMenu.cxx" />
<ClCompile Include="..\..\src\bzflag\ServerListFilterHelpMenu.cxx" />
<ClCompile Include="..\..\src\bzflag\ServerListFilterMenu.cxx" />
<ClCompile Include="..\..\src\bzflag\bzflag.cxx">
Expand Down Expand Up @@ -939,12 +941,14 @@ copy "$(BZ_DEPS)\licenses\*" "..\..\bin_$(Configuration)_$(Platform)\licenses\"<
<ClInclude Include="..\..\src\bzflag\HUDui.h" />
<ClInclude Include="..\..\src\bzflag\HUDuiControl.h" />
<ClInclude Include="..\..\src\bzflag\HUDuiDefaultKey.h" />
<ClInclude Include="..\..\src\bzflag\HUDuiJSTestLabel.h" />
<ClInclude Include="..\..\src\bzflag\HUDuiLabel.h" />
<ClInclude Include="..\..\src\bzflag\HUDuiList.h" />
<ClInclude Include="..\..\src\bzflag\HUDuiTextureLabel.h" />
<ClInclude Include="..\..\src\bzflag\HUDuiTypeIn.h" />
<ClInclude Include="..\..\src\bzflag\InputMenu.h" />
<ClInclude Include="..\..\src\bzflag\JoinMenu.h" />
<ClInclude Include="..\..\src\bzflag\JoystickTestMenu.h" />
<ClInclude Include="..\..\src\bzflag\KeyboardMapMenu.h" />
<ClInclude Include="..\..\include\ListServer.h" />
<ClInclude Include="..\..\src\bzflag\LocalCommand.h" />
Expand Down
12 changes: 12 additions & 0 deletions MSVC/build/bzflag.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@
<ClCompile Include="..\..\src\bzflag\stars.cxx">
<Filter>Header Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\bzflag\HUDuiJSTestLabel.cxx">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\bzflag\JoystickTestMenu.cxx">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\bzflag\BackgroundRenderer.h">
Expand Down Expand Up @@ -531,6 +537,12 @@
<ClInclude Include="..\..\src\bzflag\WorldPlayer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\bzflag\HUDuiJSTestLabel.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\bzflag\JoystickTestMenu.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\bzflag.ico">
Expand Down
12 changes: 12 additions & 0 deletions Xcode/BZFlag.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@
0394E966167B2D00007F4035 /* wwzones.dylib in CopyFiles */ = {isa = PBXBuildFile; fileRef = 0394E93D167B2A9E007F4035 /* wwzones.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
0397B73B1BC1D639001C04D2 /* CustomZoneSample.bzw in Resources */ = {isa = PBXBuildFile; fileRef = C353B1E81AE2489900C5AED5 /* CustomZoneSample.bzw */; };
0397B73C1BC1E72B001C04D2 /* flagStay.bzw in Resources */ = {isa = PBXBuildFile; fileRef = C353B1E91AE2490D00C5AED5 /* flagStay.bzw */; };
03AD0A172481A06E00207E3E /* JoystickTestMenu.cxx in Sources */ = {isa = PBXBuildFile; fileRef = 03AD0A162481A06E00207E3E /* JoystickTestMenu.cxx */; };
03AD0A1A2481B2D600207E3E /* HUDuiJSTestLabel.cxx in Sources */ = {isa = PBXBuildFile; fileRef = 03AD0A192481B2D600207E3E /* HUDuiJSTestLabel.cxx */; };
03C5E82B1670A98C005A26C4 /* FontManager.cxx in Sources */ = {isa = PBXBuildFile; fileRef = 035542FD166C846F008806E9 /* FontManager.cxx */; };
03C5E82C1670A98C005A26C4 /* ImageFont.cxx in Sources */ = {isa = PBXBuildFile; fileRef = 035542FE166C846F008806E9 /* ImageFont.cxx */; };
03C5E82D1670A98C005A26C4 /* TextureFont.cxx in Sources */ = {isa = PBXBuildFile; fileRef = 03554302166C846F008806E9 /* TextureFont.cxx */; };
Expand Down Expand Up @@ -1775,6 +1777,10 @@
0394E93D167B2A9E007F4035 /* wwzones.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = wwzones.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
039708A11DD7991D00C9215C /* SDLMain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLMain.h; sourceTree = "<group>"; };
039708A21DD7991D00C9215C /* SDLMain.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLMain.m; sourceTree = "<group>"; };
03AD0A152481A06E00207E3E /* JoystickTestMenu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JoystickTestMenu.h; sourceTree = "<group>"; };
03AD0A162481A06E00207E3E /* JoystickTestMenu.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JoystickTestMenu.cxx; sourceTree = "<group>"; };
03AD0A182481B2D500207E3E /* HUDuiJSTestLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HUDuiJSTestLabel.h; sourceTree = "<group>"; };
03AD0A192481B2D600207E3E /* HUDuiJSTestLabel.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HUDuiJSTestLabel.cxx; sourceTree = "<group>"; };
03C338C71AFB5AFC00E8F655 /* SDL2Display.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SDL2Display.cxx; sourceTree = "<group>"; };
03C338C81AFB5AFC00E8F655 /* SDL2Display.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL2Display.h; sourceTree = "<group>"; };
03C338C91AFB5AFC00E8F655 /* SDL2Visual.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SDL2Visual.cxx; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2529,6 +2535,8 @@
0355435A166C846F008806E9 /* HUDuiControl.h */,
0355435B166C846F008806E9 /* HUDuiDefaultKey.cxx */,
0355435C166C846F008806E9 /* HUDuiDefaultKey.h */,
03AD0A192481B2D600207E3E /* HUDuiJSTestLabel.cxx */,
03AD0A182481B2D500207E3E /* HUDuiJSTestLabel.h */,
0355435D166C846F008806E9 /* HUDuiLabel.cxx */,
0355435E166C846F008806E9 /* HUDuiLabel.h */,
0355435F166C846F008806E9 /* HUDuiList.cxx */,
Expand All @@ -2541,6 +2549,8 @@
03554366166C846F008806E9 /* InputMenu.h */,
03554367166C846F008806E9 /* JoinMenu.cxx */,
03554368166C846F008806E9 /* JoinMenu.h */,
03AD0A162481A06E00207E3E /* JoystickTestMenu.cxx */,
03AD0A152481A06E00207E3E /* JoystickTestMenu.h */,
03554369166C846F008806E9 /* KeyboardMapMenu.cxx */,
0355436A166C846F008806E9 /* KeyboardMapMenu.h */,
0355436B166C846F008806E9 /* LocalCommand.cxx */,
Expand Down Expand Up @@ -5571,6 +5581,7 @@
03C8EE6F167AC26A00BB07A5 /* callbacks.cxx in Sources */,
03C8EE71167AC26A00BB07A5 /* clientCommands.cxx in Sources */,
03C8EE72167AC26A00BB07A5 /* clientConfig.cxx in Sources */,
03AD0A1A2481B2D600207E3E /* HUDuiJSTestLabel.cxx in Sources */,
03C8EE75167AC26A00BB07A5 /* CommandsImplementation.cxx in Sources */,
03C8EE76167AC26A00BB07A5 /* ComposeDefaultKey.cxx in Sources */,
03C8EE78167AC26A00BB07A5 /* ControlPanel.cxx in Sources */,
Expand Down Expand Up @@ -5647,6 +5658,7 @@
03C8EF01167AC26A00BB07A5 /* TrackMarks.cxx in Sources */,
03C8EF03167AC26A00BB07A5 /* Weapon.cxx in Sources */,
03C8EF05167AC26A00BB07A5 /* WeatherRenderer.cxx in Sources */,
03AD0A172481A06E00207E3E /* JoystickTestMenu.cxx in Sources */,
03C8EF07167AC26A00BB07A5 /* World.cxx in Sources */,
03C8EF09167AC26A00BB07A5 /* WorldBuilder.cxx in Sources */,
03C8EF0B167AC26A00BB07A5 /* WorldPlayer.cxx in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion include/BzfJoystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class BzfJoystick

virtual void initJoystick(const char* joystickName);
virtual bool joystick() const;
virtual void getJoy(int& x, int& y);
virtual void getJoy(float& x, float& y);
virtual int getNumHats();
virtual void getJoyHat(int hat, float &hatX, float &hatY);
virtual unsigned long getJoyButtons();
Expand Down
107 changes: 107 additions & 0 deletions src/bzflag/HUDuiJSTestLabel.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/* bzflag
* Copyright (c) 1993-2020 Tim Riker
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the license found in the file
* named COPYING that should have accompanied this file.
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/

// interface headers
#include "HUDuiJSTestLabel.h"

// system headers
#include <iostream>

// common implementation headers
#include "TextureManager.h"
#include "OpenGLTexture.h"
#include "playing.h"

//
// HUDuiJSTestLabel
//

HUDuiJSTestLabel::HUDuiJSTestLabel() : HUDuiLabel(), width(0), height(0)
{
OpenGLGStateBuilder builder(gstate);
builder.setBlending();
builder.enableTexture(false);
gstate = builder.getState();
}

void HUDuiJSTestLabel::setSize(float newWidth, float newHeight)
{
width = newWidth;
height = newHeight;
}

void HUDuiJSTestLabel::doRender()
{
gstate.setState();

// scale elements from a relative screen height of 800 pixels
#define BZ_SCALE_JS_TEST_ELEMS(x) std::ceil(float(x) * height / 800.0f)

// appearance constants
const float backgroundColor[] = { 0.0f, 0.0f, 0.0f, 0.75f };

const auto realCursorThickness = BZ_SCALE_JS_TEST_ELEMS(2);
const auto realCursorLength = BZ_SCALE_JS_TEST_ELEMS(40.0f);
const float realCursorColor[] = { 1.0f, 1.0f, 1.0f, 1.0f };

const auto modifiedCursorLength = BZ_SCALE_JS_TEST_ELEMS(20.0f);
const float modifiedCursorColor[] = { 0.5f, 0.5f, 0.5f, 1.0f };

// draw the background
const auto rangeLimit = float(BZDB.evalInt("jsRangeMax")) / 100.0f;
glColor4fv(backgroundColor);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(getX() + (1.0f - rangeLimit) / 2.0f * width, getY() + (1.0f + rangeLimit) / 2.0f * height);
glVertex2f(getX() + (1.0f - rangeLimit) / 2.0f * width, getY() + (1.0f - rangeLimit) / 2.0f * height);
glVertex2f(getX() + (1.0f + rangeLimit) / 2.0f * width, getY() + (1.0f - rangeLimit) / 2.0f * height);
glVertex2f(getX() + (1.0f + rangeLimit) / 2.0f * width, getY() + (1.0f + rangeLimit) / 2.0f * height);
glEnd();

// draw the real cursor
float jsx, jsy;
mainWindow->getJoyPosition(jsx, jsy);
jsx *= BZDB.evalInt("jsInvertAxes") % 2 == 1 ? -1.0f : 1.0f; // invert axes as required
jsy *= BZDB.evalInt("jsInvertAxes") > 1 ? -1.0f : 1.0f;
auto jsxTransformed = ((1.0f + jsx) / 2.0f) * width;
auto jsyTransformed = ((1.0f - jsy) / 2.0f) * height;
glPushAttrib(GL_LINE_BIT);
glLineWidth(realCursorThickness);
glColor4fv(realCursorColor);
glBegin(GL_LINES);
glVertex2f(getX() + jsxTransformed - realCursorLength / 2.0f, getY() + jsyTransformed);
glVertex2f(getX() + jsxTransformed + realCursorLength / 2.0f, getY() + jsyTransformed);
glVertex2f(getX() + jsxTransformed, getY() + jsyTransformed - realCursorLength / 2.0f);
glVertex2f(getX() + jsxTransformed, getY() + jsyTransformed + realCursorLength / 2.0f);
glEnd();
glPopAttrib();

// draw the modified cursor
mainWindow->getJoyPosition(jsx, jsy);
applyJSModifiers(jsx, jsy);
jsxTransformed = ((1.0f + jsx) / 2.0f) * width;
jsyTransformed = ((1.0f - jsy) / 2.0f) * height;
glColor4fv(modifiedCursorColor);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(getX() + jsxTransformed, getY() + jsyTransformed - modifiedCursorLength / 2.0f);
glVertex2f(getX() + jsxTransformed + modifiedCursorLength / 2.0f, getY() + jsyTransformed);
glVertex2f(getX() + jsxTransformed, getY() + jsyTransformed + modifiedCursorLength / 2.0f);
glVertex2f(getX() + jsxTransformed - modifiedCursorLength / 2.0f, getY() + jsyTransformed);
glEnd();
}

// Local Variables: ***
// mode: C++ ***
// tab-width: 4 ***
// c-basic-offset: 4 ***
// indent-tabs-mode: nil ***
// End: ***
// ex: shiftwidth=4 tabstop=4
48 changes: 48 additions & 0 deletions src/bzflag/HUDuiJSTestLabel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* bzflag
* Copyright (c) 1993-2020 Tim Riker
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the license found in the file
* named COPYING that should have accompanied this file.
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/

/*
* HUDuiJSTestLabel:
* User interface classes and functions for the joystick range test
*/

#ifndef __HUDUIJSTESTLABEL_H__
#define __HUDUIJSTESTLABEL_H__

#include "HUDuiLabel.h"
#include "OpenGLGState.h"

class HUDuiJSTestLabel : public HUDuiLabel
{
public:
HUDuiJSTestLabel();
~HUDuiJSTestLabel() { };

void setSize(float newWidth, float newHeight);

protected:
void doRender();

private:
float width, height;
OpenGLGState gstate;
};

#endif // __HUDUIJSTESTLABEL_H__

// Local Variables: ***
// mode: C++ ***
// tab-width: 4 ***
// c-basic-offset: 4 ***
// indent-tabs-mode: nil ***
// End: ***
// ex: shiftwidth=4 tabstop=4
Loading

0 comments on commit 57eefc3

Please sign in to comment.