Skip to content

Commit

Permalink
Xbox controller improvements and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Memorix101 committed May 9, 2019
1 parent 7e43746 commit 7f7475f
Show file tree
Hide file tree
Showing 23 changed files with 154 additions and 118 deletions.
Binary file added Carmageddon.ico
Binary file not shown.
Binary file added Carmageddon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion Engine_XNA3/Audio/Mdx/MdxSound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Text;
using Microsoft.DirectX.DirectSound;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;

namespace OneAmEngine.Audio
{
Expand Down Expand Up @@ -82,7 +83,7 @@ public int Frequency

public void Play(bool loop)
{
_buffer.Play(0, loop ? BufferPlayFlags.Looping : BufferPlayFlags.Default);
_buffer.Play(0, loop ? BufferPlayFlags.Looping : BufferPlayFlags.Default);
if (_is3d && loop && MuteAtMaximumDistance)
{
Engine.Audio.Register3dSound(this);
Expand Down
15 changes: 7 additions & 8 deletions Engine_XNA3/InputProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public enum MouseInputMode
public class InputProvider : GameComponent
{
private GamePadState _gamePadState, _previousGamePadState;

private KeyboardState _keyboardState, _previousKeyboardState;
private MouseState _mouseState;
private Vector2 _mouseDelta;
Expand All @@ -48,11 +47,11 @@ public class InputProvider : GameComponent
private float _perFrameMultiplier;


public InputProvider(Game game)
: base(game)
public InputProvider(Game game) : base(game)
{
_mouseDelta = new Vector2();
_mouseMultiplier = 0.3f;

// Initialize the mouse smoothing cache.
_mouseSmoothingCache = new Vector2[MOUSE_SMOOTHING_CACHE_SIZE];
_mouseInputMode = MouseInputMode.FPS;
Expand Down Expand Up @@ -84,8 +83,6 @@ public override void Update(GameTime gameTime)
if (_previousKeyboardState == null)
_previousKeyboardState = _keyboardState;



if (_keyboardState.IsKeyDown(Keys.LeftAlt))
{
MouseMode = MouseInputMode.FreeMouse;
Expand Down Expand Up @@ -170,7 +167,6 @@ public float RightThumbDelta
}
}


public bool WasPressed(Keys key)
{
return _previousKeyboardState.IsKeyDown(key) && !_keyboardState.IsKeyDown(key);
Expand All @@ -185,6 +181,10 @@ public bool IsKeyDown(Keys key)
{
return _keyboardState.IsKeyDown(key);
}
public bool IsButtonDown(Buttons button)
{
return _gamePadState.IsButtonDown(button);
}

public MouseInputMode MouseMode
{
Expand All @@ -210,7 +210,6 @@ public Vector2 MousePosition
get { return new Vector2(_mouseState.X, _mouseState.Y); }
}


/// <summary>
/// Filters the mouse movement based on a weighted sum of mouse
/// movement from previous frames to ensure that the mouse movement
Expand Down Expand Up @@ -251,4 +250,4 @@ private void SmoothMouseMovement()
_mouseDelta.Y = averageY / averageTotal;
}
}
}
}
58 changes: 34 additions & 24 deletions OpenC1_XNA3/CameraViews/CockpitView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ class CockpitView : BaseHUDItem, ICameraView
public CockpitView(Vehicle vehicle, string cockpitFile)
{
_vehicle = vehicle;
if (GameVars.Emulation == EmulationMode.Demo)
if (GameVars.Emulation == EmulationMode.Demo)
cockpitFile = Path.GetDirectoryName(cockpitFile) + "\\blkeagle.txt";
else if (GameVars.Emulation == EmulationMode.SplatPackDemo)
cockpitFile = Path.GetDirectoryName(cockpitFile) + "\\neweagle.txt";
else if (!File.Exists(cockpitFile))
cockpitFile = Path.GetDirectoryName(cockpitFile) + "\\blkeagle.txt";
else if (GameVars.Emulation == EmulationMode.SplatPackDemo)
cockpitFile = Path.GetDirectoryName(cockpitFile) + "\\neweagle.txt";
else if (!File.Exists(cockpitFile))
cockpitFile = Path.GetDirectoryName(cockpitFile) + "\\blkeagle.txt";

if (File.Exists(cockpitFile))
{
_cockpitFile = new CockpitFile(cockpitFile);

ActFile actFile = new ActFile(vehicle.Config.BonnetActorFile);
if (!actFile.Exists)
actFile = new ActFile("EBONNET.ACT");
if (!actFile.Exists)
actFile = new ActFile("EBONNET.ACT");
_actors = actFile.Hierarchy;
DatFile modelsFile = new DatFile(_actors.Root.ModelName);
_actors.AttachModels(modelsFile.Models);
Expand All @@ -44,7 +44,7 @@ public CockpitView(Vehicle vehicle, string cockpitFile)
//move head back
_vehicle.Config.DriverHeadPosition.Z += 0.11f;
}

_camera = new SimpleCamera();
_camera.FieldOfView = MathHelper.ToRadians(55.55f);

Expand All @@ -53,7 +53,7 @@ public CockpitView(Vehicle vehicle, string cockpitFile)
#region ICameraView Members

public bool Selectable
{
{
get { return true; }
}

Expand All @@ -64,7 +64,7 @@ public override void Update()
_camera.Orientation = forward;

_camera.Up = m.Up;

_camera.Position = _vehicle.GetBodyBottom() + Vector3.Transform(_vehicle.Config.DriverHeadPosition, _vehicle.Chassis.Actor.GlobalOrientation) + new Vector3(0, 0.018f, 0);

Engine.Camera = _camera;
Expand All @@ -84,7 +84,7 @@ public override void Render()
Engine.SpriteBatch.Draw(_cockpitFile.Forward, rect, src, Color.White);

float steerRatio = _vehicle.Chassis.SteerRatio;

CockpitHandFrame frame = null;
if (steerRatio < -0.2)
{
Expand All @@ -97,7 +97,7 @@ public override void Render()
frame = _cockpitFile.RightHands[1];
else if (steerRatio < -0.2f)
frame = _cockpitFile.RightHands[0];

}
else if (steerRatio > 0.2f)
{
Expand All @@ -116,27 +116,37 @@ public override void Render()
frame = _cockpitFile.CenterHands;
}

if (frame.Texture1 != null)
Engine.SpriteBatch.Draw(frame.Texture1, ScaleVec2(frame.Position1), Color.White);
if (frame.Texture2 != null)
Engine.SpriteBatch.Draw(frame.Texture2, ScaleVec2(frame.Position2), Color.White);

if (_cockpitFile.IsHighRes)
{
if (frame.Texture1 != null)
Engine.SpriteBatch.Draw(frame.Texture1, ScaleVec2(frame.Position1), Color.White);
if (frame.Texture2 != null)
Engine.SpriteBatch.Draw(frame.Texture2, ScaleVec2(frame.Position2), Color.White);
}
else
{
if (frame.Texture1 != null)
Engine.SpriteBatch.Draw(frame.Texture1,
new Rectangle((int)ScaleVec2(frame.Position1).X + 5, (int)ScaleVec2(frame.Position1).Y - 20, 100, 100), Color.White);
if (frame.Texture2 != null)
Engine.SpriteBatch.Draw(frame.Texture2,
new Rectangle((int)ScaleVec2(frame.Position2).X - 50, (int)ScaleVec2(frame.Position2).Y - 20, 100, 100), Color.White);
}

_actors.Render(Matrix.CreateFromQuaternion(_vehicle.Chassis.Actor.GlobalOrientationQuat) * Matrix.CreateTranslation(_vehicle.GetBodyBottom()), null);
}

public void Activate()
{
Engine.Camera = _camera;
_camera.Position = _vehicle.GetBodyBottom() + Vector3.Transform(_vehicle.Config.DriverHeadPosition, _vehicle.Chassis.Actor.GlobalOrientation);
_camera.Update();
_camera.Update();
}

public void Deactivate()
{

}

#endregion

}
#endregion
}
}
Binary file added OpenC1_XNA3/Carmageddon.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion OpenC1_XNA3/GameModes/RaceCompletedMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public override void Update()
_camera.RotateTo(MathHelper.Pi * 2);
}

if (Engine.Input.WasPressed(Keys.Enter) || Engine.Input.WasPressed(Keys.Escape))
if (Engine.Input.WasPressed(Keys.Enter) || Engine.Input.WasPressed(Keys.Escape) || Engine.Input.WasPressed(Buttons.Start))
{
Race.Current.ExitAndReturnToMenu();
}
Expand Down
4 changes: 2 additions & 2 deletions OpenC1_XNA3/GameModes/StandardGameMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public override void Activate()

public override void Update()
{
if (Engine.Input.WasPressed(Keys.Escape))
if (Engine.Input.WasPressed(Keys.Escape) || Engine.Input.WasPressed(Buttons.Start))
{
Engine.Screen = new PauseMenuScreen((PlayGameScreen)Engine.Screen);
return;
}

if (Engine.Input.WasPressed(Keys.C)) //cockpit / external view
if (Engine.Input.WasPressed(Keys.C) || Engine.Input.WasPressed(Buttons.Y)) //cockpit / external view
{
_views[_currentView].Deactivate();
_currentView = (_currentView + 1) % _views.Count;
Expand Down
File renamed without changes.
13 changes: 8 additions & 5 deletions OpenC1_XNA3/OpenC1_XNA3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{3BA0D501-86F5-43C6-B150-7AE82E9B9CC8}</ProjectGuid>
<OutputType>Exe</OutputType>
<OutputType>WinExe</OutputType>
<RootNamespace>OpenC1</RootNamespace>
<AssemblyName>OpenC1</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
Expand Down Expand Up @@ -55,7 +55,10 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>icon.ico</ApplicationIcon>
<ApplicationIcon>Carmageddon.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="Ionic.Zip.Reduced">
Expand Down Expand Up @@ -215,10 +218,10 @@
<Compile Include="VehicleModel.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="icon.ico" />
<Content Include="OpenC1Settings.txt">
<Content Include="Carmageddon.ico" />
<None Include="OpenC1Settings.cfg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</None>
</ItemGroup>
<ItemGroup>
<Content Include="Content\BasicEffect2.xnb">
Expand Down
46 changes: 23 additions & 23 deletions OpenC1_XNA3/Parsers/CockpitFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,37 @@

namespace OpenC1.Parsers
{
class CockpitHandFrame
{
public Vector2 Position1, Position2;
public Texture2D Texture1, Texture2;
}
class CockpitHandFrame
{
public Vector2 Position1, Position2;
public Texture2D Texture1, Texture2;
}

class CockpitFile : BaseTextFile
{
public Texture2D Forward, Left, Right;
class CockpitFile : BaseTextFile
{
public Texture2D Forward, Left, Right;
public Rectangle ForwardRect, LeftRect, RightRect;
public List<CockpitHandFrame> LeftHands = new List<CockpitHandFrame>();
public List<CockpitHandFrame> RightHands = new List<CockpitHandFrame>();
public CockpitHandFrame CenterHands;
public bool IsHighRes;


public CockpitFile(string filename) : base(filename)
{

public CockpitFile(string filename) : base(filename)
{
string folderName = Path.GetDirectoryName(filename);

if (filename.Contains("64x48"))
IsHighRes = true;

Forward = GetTextureFromPixFile(folderName, ReadLine());
ForwardRect = ReadLineAsRect();
Forward = GetTextureFromPixFile(folderName, ReadLine());
ForwardRect = ReadLineAsRect();
Left = GetTextureFromPixFile(folderName, ReadLine());
LeftRect = ReadLineAsRect();
Right = GetTextureFromPixFile(folderName, ReadLine());
RightRect = ReadLineAsRect();
SkipLines(6); //internal & external speedo, tacho, gears
int nbrHandFrames = ReadLineAsInt();
SkipLines(6); //internal & external speedo, tacho, gears
int nbrHandFrames = ReadLineAsInt();

int center = nbrHandFrames / 2;
for (int i = 0; i < nbrHandFrames; i++)
Expand All @@ -55,9 +55,9 @@ public CockpitFile(string filename) : base(filename)
RightHands.Add(frame);
}

SkipLines(2); //mirror
SkipLines(2); //mirror

CloseFile();
CloseFile();

int w = 640; int h = 480;
if (!IsHighRes)
Expand All @@ -83,15 +83,15 @@ public CockpitFile(string filename) : base(filename)
CenterHands.Position2 += new Vector2(-20, 0);
CenterHands.Position1 /= new Vector2(w, h);
CenterHands.Position2 /= new Vector2(w, h);
}
}

private Texture2D GetTextureFromPixFile(string curFolder, string filename)
{
if (filename == "none") return null;
PixFile pixFile = new PixFile(filename);
if (pixFile.PixMaps.Count > 0)
return pixFile.PixMaps[0].Texture;
return null;
if (pixFile.PixMaps.Count > 0)
return pixFile.PixMaps[0].Texture;
return null;
}
}
}
}
2 changes: 1 addition & 1 deletion OpenC1_XNA3/Parsers/SettingsFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace OpenC1.Parsers
class SettingsFile : BaseTextFile
{
public SettingsFile()
: base(Path.Combine(StorageContainer.TitleLocation, "OpenC1Settings.txt"))
: base(Path.Combine(StorageContainer.TitleLocation, "OpenC1Settings.cfg"))
{
GameVars.DrawDistance = ReadLineAsInt() * 10;
GameVars.FullScreen = ReadLineAsBool();
Expand Down
4 changes: 2 additions & 2 deletions OpenC1_XNA3/PlayerDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void Update()
else
chassis.ReleaseHandbrake();

if (Engine.Input.WasPressed(Keys.R))
if (Engine.Input.WasPressed(Keys.R) || Engine.Input.WasPressed(Buttons.B))
{
if (_recoverPositions.Count > 0)
{
Expand All @@ -59,7 +59,7 @@ public void Update()
Vehicle.Chassis.Reset();
}

if (Engine.Input.WasPressed(Keys.Back))
if (Engine.Input.WasPressed(Keys.Back) || Engine.Input.WasPressed(Buttons.Back))
{
Vehicle.Repair();
}
Expand Down
Loading

0 comments on commit 7f7475f

Please sign in to comment.