Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
leezer3 committed Apr 25, 2021
2 parents 7bf0fac + 96f3e46 commit 1fe1c42
Show file tree
Hide file tree
Showing 25 changed files with 646 additions and 400 deletions.
Binary file added dependencies/x64/OpenAL32.dll
Binary file not shown.
File renamed without changes.
30 changes: 30 additions & 0 deletions source/ObjectViewer/FunctionScripts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,36 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainManager
s++; break;
case Instructions.Panel2Timetable:
throw new InvalidOperationException("The instruction " + Function.InstructionSet[i].ToString() + " is for internal use only, and should not be added to objects.");
case Instructions.BrightnessOfCar:
if (Train == null) {
Function.Stack[s - 1] = 0.0;
} else {
int j = (int)Math.Round(Function.Stack[s - 1]);
if (j < 0) j += Train.Cars.Length;
if (j >= 0 & j < Train.Cars.Length) {
float b = (float) (Train.Cars[j].Brightness.NextTrackPosition - Train.Cars[j].Brightness.PreviousTrackPosition);
//1.0f represents a route brightness value of 255
//0.0f represents a route brightness value of 0
if (b != 0.0f)
{
b = (float) (Train.Cars[j].RearAxle.Follower.TrackPosition - Train.Cars[j].Brightness.PreviousTrackPosition) / b;
if (b < 0.0f) b = 0.0f;
if (b > 1.0f) b = 1.0f;
b = Train.Cars[j].Brightness.PreviousBrightness * (1.0f - b) + Train.Cars[j].Brightness.NextBrightness * b;
}
else
{
b = Train.Cars[j].Brightness.PreviousBrightness;
}
//Calculate the cab brightness
double ccb = Math.Round(255.0 * (1.0 - b));
//DNB then must equal the smaller of the cab brightness value & the dynamic brightness value
Function.Stack[s - 1] = Math.Min(Program.Renderer.Lighting.DynamicCabBrightness, ccb);
} else {
Function.Stack[s - 1] = 0.0;
}
}
break;
default:
throw new InvalidOperationException("The unknown instruction " + Function.InstructionSet[i].ToString() + " was encountered in ExecuteFunctionScript.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1403,6 +1403,36 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr
Function.Stack[s] = Train.Cars[Train.DriverCar].Windscreen.Wipers.CurrentPosition;
}
s++; break;
case Instructions.BrightnessOfCar:
if (Train == null) {
Function.Stack[s - 1] = 0.0;
} else {
int j = (int)Math.Round(Function.Stack[s - 1]);
if (j < 0) j += Train.Cars.Length;
if (j >= 0 & j < Train.Cars.Length) {
float b = (float) (Train.Cars[j].Brightness.NextTrackPosition - Train.Cars[j].Brightness.PreviousTrackPosition);
//1.0f represents a route brightness value of 255
//0.0f represents a route brightness value of 0
if (b != 0.0f)
{
b = (float) (Train.Cars[j].RearAxle.Follower.TrackPosition - Train.Cars[j].Brightness.PreviousTrackPosition) / b;
if (b < 0.0f) b = 0.0f;
if (b > 1.0f) b = 1.0f;
b = Train.Cars[j].Brightness.PreviousBrightness * (1.0f - b) + Train.Cars[j].Brightness.NextBrightness * b;
}
else
{
b = Train.Cars[j].Brightness.PreviousBrightness;
}
//Calculate the cab brightness
double ccb = Math.Round(255.0 * (1.0 - b));
//DNB then must equal the smaller of the cab brightness value & the dynamic brightness value
Function.Stack[s - 1] = Math.Min(Program.Renderer.Lighting.DynamicCabBrightness, ccb);
} else {
Function.Stack[s - 1] = 0.0;
}
}
break;
// default
default:
throw new System.InvalidOperationException("The unknown instruction " + Function.InstructionSet[i].ToString() + " was encountered in ExecuteFunctionScript.");
Expand Down
2 changes: 1 addition & 1 deletion source/OpenBVE/Game/Score/Score.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ internal void Update(double TimeElapsed)
double y = (double)this.CurrentValue / (double)Maximum;
if (y < 0.0) y = 0.0;
if (y > 1.0) y = 1.0;
int k = (int)Math.Floor(y * (double)Translations.RatingsCount);
int k = (int)Math.Floor(y * Translations.RatingsCount);
if (k >= Translations.RatingsCount) k = Translations.RatingsCount - 1;
System.Globalization.CultureInfo Culture = System.Globalization.CultureInfo.InvariantCulture;
AddScore(Translations.GetInterfaceString("score_rating"), 20.0);
Expand Down
3 changes: 1 addition & 2 deletions source/OpenBVE/Graphics/Renderers/Touch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using OpenBveApi.Objects;
using OpenBveApi.Runtime;
using OpenTK.Graphics.OpenGL;
using SoundManager;
using TrainManager.Car;
using Vector2 = OpenTK.Vector2;

Expand Down Expand Up @@ -427,7 +426,7 @@ internal void LeaveCheck(Vector2 Point)
Car.CarSections[0].CurrentAdditionalGroup = TouchElement.JumpScreenIndex;
Car.ChangeCarSection(CarSectionType.Interior);

foreach (var index in TouchElement.SoundIndices.Where(x => x >= 0 && x < Car.Sounds.Touch.Length))
foreach (var index in TouchElement.SoundIndices.Where(x => x >= 0 && Car.Sounds.Touch != null && x < Car.Sounds.Touch.Length))
{
Car.Sounds.Touch[index].Play(TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar], false);
}
Expand Down
10 changes: 8 additions & 2 deletions source/OpenBVE/Parsers/Script/TrackFollowingObjectParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,18 @@ private static void ParseTrackFollowingObjectNode(string ObjectPath, string File
AbstractTrain currentTrain = Train;
for (int i = 0; i < Program.CurrentHost.Plugins.Length; i++)
{
if (Program.CurrentHost.Plugins[i].Train != null && Program.CurrentHost.Plugins[i].Train.CanLoadTrain(TrainDirectory))
if (Program.CurrentHost.Plugins[i].Train != null && Program.CurrentHost.Plugins[i].Train.CanLoadTrain(TrainData))
{

Program.CurrentHost.Plugins[i].Train.LoadTrain(Encoding.UTF8, TrainDirectory, ref currentTrain, ref Interface.CurrentControls);
}
}

if (!Train.Cars.Any())
{
Interface.AddMessage(MessageType.Error, false, $"Failed to load the specified train in {FileName}");
return;
}

Train.AI = new TrackFollowingObjectAI(Train, Data.ToArray());
foreach (var Car in Train.Cars)
{
Expand Down
52 changes: 25 additions & 27 deletions source/OpenBVE/System/Host.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

namespace OpenBve {
/// <summary>Represents the host application.</summary>
internal class Host : OpenBveApi.Hosts.HostInterface {
internal class Host : HostInterface {

// --- functions ---

Expand Down Expand Up @@ -68,7 +68,7 @@ public override void AddMessage(string Message, object MessageDependancy, GameMo
/// <param name="height">Receives the height of the texture.</param>
/// <returns>Whether querying the dimensions was successful.</returns>
public override bool QueryTextureDimensions(string path, out int width, out int height) {
if (System.IO.File.Exists(path) || System.IO.Directory.Exists(path)) {
if (File.Exists(path) || Directory.Exists(path)) {
for (int i = 0; i < Program.CurrentHost.Plugins.Length; i++) {
if (Program.CurrentHost.Plugins[i].Texture != null) {
try {
Expand Down Expand Up @@ -103,7 +103,7 @@ public override bool QueryTextureDimensions(string path, out int width, out int
Interface.AddMessage(MessageType.Error, false, "No plugin found that is capable of loading texture " + path);
}
} else {
ReportProblem(OpenBveApi.Hosts.ProblemType.PathNotFound, path);
ReportProblem(ProblemType.PathNotFound, path);
}
width = 0;
height = 0;
Expand All @@ -116,7 +116,7 @@ public override bool QueryTextureDimensions(string path, out int width, out int
/// <param name="texture">Receives the texture.</param>
/// <returns>Whether loading the texture was successful.</returns>
public override bool LoadTexture(string path, TextureParameters parameters, out Texture texture) {
if (System.IO.File.Exists(path) || System.IO.Directory.Exists(path)) {
if (File.Exists(path) || Directory.Exists(path)) {
for (int i = 0; i < Program.CurrentHost.Plugins.Length; i++) {
if (Program.CurrentHost.Plugins[i].Texture != null) {
try {
Expand Down Expand Up @@ -147,7 +147,7 @@ public override bool LoadTexture(string path, TextureParameters parameters, out
Interface.AddMessage(MessageType.Error, false, "No plugin found that is capable of loading texture " + path);
}
} else {
ReportProblem(OpenBveApi.Hosts.ProblemType.PathNotFound, path);
ReportProblem(ProblemType.PathNotFound, path);
}
texture = null;
return false;
Expand All @@ -166,7 +166,7 @@ public override bool LoadTexture(Texture Texture, OpenGlTextureWrapMode wrapMode
/// <param name="loadTexture">Whether the texture is to be pre-loaded</param>
/// <returns>Whether loading the texture was successful.</returns>
public override bool RegisterTexture(string path, TextureParameters parameters, out Texture handle, bool loadTexture = false) {
if (System.IO.File.Exists(path) || System.IO.Directory.Exists(path)) {
if (File.Exists(path) || Directory.Exists(path)) {
Texture data;
if (Program.Renderer.TextureManager.RegisterTexture(path, parameters, out data)) {
handle = data;
Expand All @@ -181,7 +181,7 @@ public override bool RegisterTexture(string path, TextureParameters parameters,
return true;
}
} else {
ReportProblem(OpenBveApi.Hosts.ProblemType.PathNotFound, path);
ReportProblem(ProblemType.PathNotFound, path);
}
handle = null;
return false;
Expand All @@ -198,7 +198,7 @@ public override bool RegisterTexture(Texture texture, TextureParameters paramete
return true;
}

public override bool RegisterTexture(Bitmap texture, TextureParameters parameters, out OpenBveApi.Textures.Texture handle)
public override bool RegisterTexture(Bitmap texture, TextureParameters parameters, out Texture handle)
{
handle = new Texture(texture, parameters);
return true;
Expand All @@ -210,8 +210,8 @@ public override bool RegisterTexture(Bitmap texture, TextureParameters parameter
/// <param name="path">The path to the file or folder that contains the sound.</param>
/// <param name="sound">Receives the sound.</param>
/// <returns>Whether loading the sound was successful.</returns>
public override bool LoadSound(string path, out OpenBveApi.Sounds.Sound sound) {
if (System.IO.File.Exists(path) || System.IO.Directory.Exists(path)) {
public override bool LoadSound(string path, out Sound sound) {
if (File.Exists(path) || Directory.Exists(path)) {
for (int i = 0; i < Program.CurrentHost.Plugins.Length; i++) {
if (Program.CurrentHost.Plugins[i].Sound != null) {
try {
Expand All @@ -232,7 +232,7 @@ public override bool LoadSound(string path, out OpenBveApi.Sounds.Sound sound) {
}
Interface.AddMessage(MessageType.Error, false, "No plugin found that is capable of loading sound " + path);
} else {
ReportProblem(OpenBveApi.Hosts.ProblemType.PathNotFound, path);
ReportProblem(ProblemType.PathNotFound, path);
}
sound = null;
return false;
Expand All @@ -243,16 +243,14 @@ public override bool LoadSound(string path, out OpenBveApi.Sounds.Sound sound) {
/// <param name="path">The path to the file or folder that contains the sound.</param>
/// <param name="handle">Receives a handle to the sound.</param>
/// <returns>Whether loading the sound was successful.</returns>
public override bool RegisterSound(string path, out OpenBveApi.Sounds.SoundHandle handle)
public override bool RegisterSound(string path, out SoundHandle handle)
{
if (System.IO.File.Exists(path) || System.IO.Directory.Exists(path))
if (File.Exists(path) || Directory.Exists(path))
{
handle = Program.Sounds.RegisterBuffer(path, 0.0);
return true;
}
else
{
ReportProblem(OpenBveApi.Hosts.ProblemType.PathNotFound, path);
}
ReportProblem(ProblemType.PathNotFound, path);
handle = null;
return false;
}
Expand All @@ -262,14 +260,14 @@ public override bool RegisterSound(string path, out OpenBveApi.Sounds.SoundHandl
/// /// <param name="radius">The sound radius</param>
/// <param name="handle">Receives a handle to the sound.</param>
/// <returns>Whether loading the sound was successful.</returns>
public override bool RegisterSound(string path, double radius, out OpenBveApi.Sounds.SoundHandle handle)
public override bool RegisterSound(string path, double radius, out SoundHandle handle)
{
if (System.IO.File.Exists(path) || System.IO.Directory.Exists(path))
if (File.Exists(path) || Directory.Exists(path))
{
handle = Program.Sounds.RegisterBuffer(path, radius);
return true;
}
ReportProblem(OpenBveApi.Hosts.ProblemType.PathNotFound, path);
ReportProblem(ProblemType.PathNotFound, path);
handle = null;
return false;
}
Expand All @@ -278,7 +276,7 @@ public override bool RegisterSound(string path, double radius, out OpenBveApi.So
/// <param name="sound">The sound data.</param>
/// <param name="handle">Receives a handle to the sound.</param>
/// <returns>Whether loading the sound was successful.</returns>
public override bool RegisterSound(OpenBveApi.Sounds.Sound sound, out OpenBveApi.Sounds.SoundHandle handle)
public override bool RegisterSound(Sound sound, out SoundHandle handle)
{
handle = Program.Sounds.RegisterBuffer(sound, 0.0);
return true;
Expand All @@ -291,7 +289,7 @@ public override bool LoadStaticObject(string path, System.Text.Encoding Encoding
return true;
}

if (System.IO.File.Exists(path) || System.IO.Directory.Exists(path)) {
if (File.Exists(path) || Directory.Exists(path)) {
Encoding = TextEncoding.GetSystemEncodingFromFile(path, Encoding);

for (int i = 0; i < Program.CurrentHost.Plugins.Length; i++) {
Expand Down Expand Up @@ -325,7 +323,7 @@ public override bool LoadStaticObject(string path, System.Text.Encoding Encoding
}
Interface.AddMessage(MessageType.Error, false, "No plugin found that is capable of loading object " + path);
} else {
ReportProblem(OpenBveApi.Hosts.ProblemType.PathNotFound, path);
ReportProblem(ProblemType.PathNotFound, path);
}
Object = null;
return false;
Expand All @@ -338,7 +336,7 @@ public override bool LoadObject(string path, System.Text.Encoding Encoding, out
return true;
}

if (System.IO.File.Exists(path) || System.IO.Directory.Exists(path)) {
if (File.Exists(path) || Directory.Exists(path)) {
Encoding = TextEncoding.GetSystemEncodingFromFile(path, Encoding);

for (int i = 0; i < Program.CurrentHost.Plugins.Length; i++) {
Expand Down Expand Up @@ -379,7 +377,7 @@ public override bool LoadObject(string path, System.Text.Encoding Encoding, out
}
Interface.AddMessage(MessageType.Error, false, "No plugin found that is capable of loading object " + path);
} else {
ReportProblem(OpenBveApi.Hosts.ProblemType.PathNotFound, path);
ReportProblem(ProblemType.PathNotFound, path);
}
Object = null;
return false;
Expand Down Expand Up @@ -430,7 +428,7 @@ public override object PlaySound(SoundHandle buffer, double pitch, double volume
return Program.Sounds.PlaySound(buffer, pitch, volume, position, parent, looped);
}

public override void PlayMicSound(OpenBveApi.Math.Vector3 position, double backwardTolerance, double forwardTolerance)
public override void PlayMicSound(Vector3 position, double backwardTolerance, double forwardTolerance)
{
Program.Sounds.PlayMicSound(position, backwardTolerance, forwardTolerance);
}
Expand Down Expand Up @@ -591,7 +589,7 @@ public override AbstractTrain ClosestTrain(AbstractTrain Train)
{
if (Program.TrainManager.Trains[i] != baseTrain & Program.TrainManager.Trains[i].State == TrainState.Available & baseTrain.Cars.Length > 0)
{
TrainBase train = Program.TrainManager.Trains[i] as TrainBase;
TrainBase train = Program.TrainManager.Trains[i];
int c = train.Cars.Length - 1;
double z = train.Cars[c].RearAxle.Follower.TrackPosition - train.Cars[c].RearAxle.Position - 0.5 * train.Cars[c].Length;
if (z >= baseTrain.FrontCarTrackPosition() & z < bestLocation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ internal void LoadCalibration(string calibrationFile)
{
lMin = 255;
}
else if (lMin < 0)
{
lMin = 0;
}

if (lMax >= 255)
{
Expand Down Expand Up @@ -178,6 +174,11 @@ internal void SaveCalibration(string calibrationFile)
}
catch
{
/*
* Saving the calibration failed
* All this means is that it might be off next time, no real big deal
*/

}

}
Expand Down Expand Up @@ -239,7 +240,7 @@ private static int ScaleValue(int value, int value_min, int value_max)
internal static byte GetDigit(int num)
{
num = Math.Abs(num);
if (num > 9 || num < 0)
if (num > 9)
{
//Invalid data
return 0;
Expand Down Expand Up @@ -267,6 +268,7 @@ internal static byte GetDigit(int num)
return 127;
case 9:
return 103;
// ReSharper disable once UnreachableSwitchCaseDueToIntegerAnalysis
default:
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,7 @@ internal override Guid GetGuid()
{
return Guid;
}

/// <summary>Callback function from the PI Engineering DLL, raised each time the device pushes a data packet</summary>
/// <param name="data">The callback data</param>
/// <param name="sourceDevice">The source device</param>
/// <param name="error">The last error generated (if any)</param>
public void HandlePIEHidData(byte[] data, PIEDevice sourceDevice, long error)
{
if (myDevice == sourceDevice)
{
for (int r = 0; r < sourceDevice.ReadLength; r++)
{
currentState[r] = data[r];
}
}
}


/// <summary>Callback function from the PI Engineering DLL, raised if an error is encountered</summary>
/// <param name="sourceDevices">The source device</param>
/// <param name="error">The error</param>
Expand Down
2 changes: 1 addition & 1 deletion source/OpenBVE/UserInterface/formMain.Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using OpenBveApi.Interface;

namespace OpenBve {
internal partial class formMain : Form {
internal partial class formMain {


// =======
Expand Down
Loading

0 comments on commit 1fe1c42

Please sign in to comment.