Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 26 additions & 24 deletions source/OpenBVE/System/Loading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,27 @@ private static void LoadEverythingThreaded() {
Program.FileSystem.AppendToLogFile("INFO: " + Program.CurrentHost.AvailableRoutePluginCount + " Route loading plugins available.");
Program.FileSystem.AppendToLogFile("INFO: " + Program.CurrentHost.AvailableObjectPluginCount + " Object loading plugins available.");
Program.FileSystem.AppendToLogFile("INFO: " + Program.CurrentHost.AvailableRoutePluginCount + " Sound loading plugins available.");

// initialize trains
Program.TrainManager.Trains = new TrainBase[Program.CurrentRoute.PrecedingTrainTimeDeltas.Length + 1 + (Program.CurrentRoute.BogusPreTrainInstructions.Length != 0 ? 1 : 0)];
for (int k = 0; k < Program.TrainManager.Trains.Length; k++)
{
if (k == Program.TrainManager.Trains.Length - 1 & Program.CurrentRoute.BogusPreTrainInstructions.Length != 0) {
Program.TrainManager.Trains[k] = new TrainBase(TrainState.Bogus);
} else {
Program.TrainManager.Trains[k] = new TrainBase(TrainState.Pending);
}

}
TrainManager.PlayerTrain = Program.TrainManager.Trains[Program.CurrentRoute.PrecedingTrainTimeDeltas.Length];

// load player train plugin
if (!TrainManager.PlayerTrain.LoadCustomPlugin(CurrentTrainFolder, CurrentTrainEncoding))
{
TrainManager.PlayerTrain.LoadDefaultPlugin(CurrentTrainFolder);
}

// load route
for (int i = 0; i < Program.CurrentHost.Plugins.Length; i++)
{
if (Program.CurrentHost.Plugins[i].Route != null && Program.CurrentHost.Plugins[i].Route.CanLoadRoute(CurrentRouteFile))
Expand Down Expand Up @@ -262,24 +283,8 @@ private static void LoadEverythingThreaded() {
Program.FileSystem.AppendToLogFile("The processed route file only contains a single station.");
}
Program.FileSystem.AppendToLogFile("Route file loaded successfully.");
// initialize trains
System.Threading.Thread.Sleep(1); if (Cancel) return;
Program.TrainManager.Trains = new TrainBase[Program.CurrentRoute.PrecedingTrainTimeDeltas.Length + 1 + (Program.CurrentRoute.BogusPreTrainInstructions.Length != 0 ? 1 : 0)];
for (int k = 0; k < Program.TrainManager.Trains.Length; k++)
{
if (k == Program.TrainManager.Trains.Length - 1 & Program.CurrentRoute.BogusPreTrainInstructions.Length != 0)
{
Program.TrainManager.Trains[k] = new TrainBase(TrainState.Bogus);
}
else
{
Program.TrainManager.Trains[k] = new TrainBase(TrainState.Pending);
}

}
TrainManager.PlayerTrain = Program.TrainManager.Trains[Program.CurrentRoute.PrecedingTrainTimeDeltas.Length];


System.Threading.Thread.Sleep(1); if (Cancel) return;

// load trains
for (int k = 0; k < Program.TrainManager.Trains.Length; k++) {
Expand Down Expand Up @@ -312,26 +317,23 @@ private static void LoadEverythingThreaded() {
train.Specs.DoorCloseMode = DoorMode.Manual;
}
}

// finished created objects
System.Threading.Thread.Sleep(1); if (Cancel) return;
Array.Resize(ref ObjectManager.AnimatedWorldObjects, ObjectManager.AnimatedWorldObjectsUsed);
// update sections
if (Program.CurrentRoute.Sections.Length > 0) {
Program.CurrentRoute.UpdateAllSections();
}
// load plugin


// load other train plugin
CurrentTrain = 0;
for (int i = 0; i < Program.TrainManager.Trains.Length; i++) {
if ( Program.TrainManager.Trains[i].State != TrainState.Bogus) {
if ( Program.TrainManager.Trains[i].IsPlayerTrain) {
if (! Program.TrainManager.Trains[i].LoadCustomPlugin(Program.TrainManager.Trains[i].TrainFolder, CurrentTrainEncoding)) {
Program.TrainManager.Trains[i].LoadDefaultPlugin(Program.TrainManager.Trains[i].TrainFolder);
}
} else {
if (!Program.TrainManager.Trains[i].IsPlayerTrain) {
Program.TrainManager.Trains[i].LoadDefaultPlugin( Program.TrainManager.Trains[i].TrainFolder);
}
Program.TrainManager.Trains[i].InitializePlugin();
for (int j = 0; j < InputDevicePlugin.AvailablePluginInfos.Count; j++) {
if (InputDevicePlugin.AvailablePluginInfos[j].Status == InputDevicePlugin.PluginInfo.PluginStatus.Enable && InputDevicePlugin.AvailablePlugins[j] is ITrainInputDevice)
{
Expand Down
41 changes: 0 additions & 41 deletions source/OpenBveApi/System/Files.cs

This file was deleted.

11 changes: 8 additions & 3 deletions source/OpenBveApi/System/Interop.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.ServiceModel;
using System.ServiceModel;
using OpenBveApi.Runtime;

namespace OpenBveApi.Interop
Expand All @@ -14,11 +14,16 @@ public interface IAtsPluginProxy
void SetPluginFile(string fileName, int SimulationProcessID);

/// <summary>Called to load and initialize the plugin.</summary>
/// <returns>Whether loading the plugin was successful.</returns>
[OperationContract]
bool Load();

/// <summary>Called to initialize the plugin.</summary>
/// <param name="specs">The train specifications.</param>
/// <param name="mode">The initialization mode of the train.</param>
/// <returns>Whether loading the plugin was successful.</returns>
/// <returns>Whether initializing the plugin was successful.</returns>
[OperationContract]
bool Load(VehicleSpecs specs, InitializationModes mode);
bool Initialize(VehicleSpecs specs, InitializationModes mode);

/// <summary>Called to unload the plugin</summary>
[OperationContract]
Expand Down
6 changes: 1 addition & 5 deletions source/Plugins/Object.CsvB3d/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using OpenBveApi;
using OpenBveApi;
using OpenBveApi.FileSystem;
using OpenBveApi.Hosts;
using OpenBveApi.Interface;
Expand Down Expand Up @@ -30,10 +30,6 @@ public override bool CanLoadObject(string path)
path = path.ToLowerInvariant();
if (path.EndsWith(".b3d") || path.EndsWith(".csv"))
{
if (System.IO.File.Exists(path) && FileFormats.IsNautilusFile(path))
{
return false;
}
return true;
}

Expand Down
4 changes: 0 additions & 4 deletions source/Plugins/Texture.BmpGifJpegPngTiff/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ public override bool QueryTextureDimensions(string path, out int width, out int
/// <returns>Whether the plugin can load the specified texture.</returns>
public override bool CanLoadTexture(string path) {
if (File.Exists(path)) {
if (FileFormats.IsNautilusFile(path))
{
return false;
}
using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read)) {
using (BinaryReader reader = new BinaryReader(stream)) {
if (stream.Length < 8)
Expand Down
42 changes: 20 additions & 22 deletions source/Plugins/Win32PluginProxy/Win32PluginProxy.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//Simplified BSD License (BSD-2-Clause)
//Simplified BSD License (BSD-2-Clause)
//
//Copyright (c) 2020, Christopher Lees, The OpenBVE Project
//
Expand Down Expand Up @@ -75,7 +75,7 @@ public void SetPluginFile(string fileName, int simulationProcessID)
this.PluginFile = fileName;
}

public bool Load(VehicleSpecs specs, InitializationModes mode)
public bool Load()
{
int result;
try
Expand Down Expand Up @@ -133,42 +133,40 @@ public bool Load(VehicleSpecs specs, InitializationModes mode)
return false;
}

try
{
Console.WriteLine(@"Plugin loaded successfully.");
if (PanelHandle.IsAllocated) {
PanelHandle.Free();
}
if (SoundHandle.IsAllocated) {
SoundHandle.Free();
}
PanelHandle = GCHandle.Alloc(Panel, GCHandleType.Pinned);
SoundHandle = GCHandle.Alloc(Sound, GCHandleType.Pinned);
return true;
}

public bool Initialize(VehicleSpecs specs, InitializationModes mode) {
try {
Win32VehicleSpec win32Spec;
win32Spec.BrakeNotches = specs.BrakeNotches;
win32Spec.PowerNotches = specs.PowerNotches;
win32Spec.AtsNotch = specs.AtsNotch;
win32Spec.B67Notch = specs.B67Notch;
win32Spec.Cars = specs.Cars;
Win32SetVehicleSpec(ref win32Spec.BrakeNotches);
}
catch (Exception ex)
{
} catch (Exception ex) {
Callback.ReportError("Error loading Win32 plugin: " + ex);
return false;
}

try
{
try {
Console.WriteLine(@"Initializing in mode: " + mode);
Win32Initialize((int) mode);
}
catch (Exception ex)
{
Win32Initialize((int)mode);
} catch (Exception ex) {
Callback.ReportError("Error loading Win32 plugin: " + ex);
return false;
}

Console.WriteLine(@"Plugin loaded successfully.");
if (PanelHandle.IsAllocated) {
PanelHandle.Free();
}
if (SoundHandle.IsAllocated) {
SoundHandle.Free();
}
PanelHandle = GCHandle.Alloc(Panel, GCHandleType.Pinned);
SoundHandle = GCHandle.Alloc(Sound, GCHandleType.Pinned);
return true;
}

Expand Down
46 changes: 23 additions & 23 deletions source/TrainManager/SafetySystems/Plugin/LegacyPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Threading;
Expand Down Expand Up @@ -163,7 +163,7 @@ internal Win32Plugin(string pluginFile, TrainBase train)
}

// --- functions ---
public override bool Load(VehicleSpecs specs, InitializationModes mode)
public override bool Load()
{
int result;
bool retry = true;
Expand Down Expand Up @@ -235,47 +235,47 @@ public override bool Load(VehicleSpecs specs, InitializationModes mode)
return false;
}

try
if (PanelHandle.IsAllocated)
{
PanelHandle.Free();
}

if (SoundHandle.IsAllocated)
{
SoundHandle.Free();
}

PanelHandle = GCHandle.Alloc(Panel, GCHandleType.Pinned);
SoundHandle = GCHandle.Alloc(Sound, GCHandleType.Pinned);
return true;
}

public override bool Initialize(VehicleSpecs specs, InitializationModes mode) {

try {
Win32VehicleSpec win32Spec;
win32Spec.BrakeNotches = specs.BrakeNotches;
win32Spec.PowerNotches = specs.PowerNotches;
win32Spec.AtsNotch = specs.AtsNotch;
win32Spec.B67Notch = specs.B67Notch;
win32Spec.Cars = specs.Cars;
Win32SetVehicleSpec(ref win32Spec.BrakeNotches);
}
catch (Exception ex)
{
} catch (Exception ex) {
base.LastException = ex;
throw;
}

try
{
Win32Initialize((int) mode);
}
catch (Exception ex)
{
try {
Win32Initialize((int)mode);
} catch (Exception ex) {
base.LastException = ex;
throw;
}

UpdatePower();
UpdateBrake();
UpdateReverser();
if (PanelHandle.IsAllocated)
{
PanelHandle.Free();
}

if (SoundHandle.IsAllocated)
{
SoundHandle.Free();
}

PanelHandle = GCHandle.Alloc(Panel, GCHandleType.Pinned);
SoundHandle = GCHandle.Alloc(Sound, GCHandleType.Pinned);
return true;
}

Expand Down
Loading