Further separation of client-specific code

Still not done here, just gonna push a commit now so I can pull this from elsewhere.
This commit is contained in:
juanjp600
2017-06-16 16:02:07 -03:00
parent e4a878113f
commit 7168a534ed
64 changed files with 3733 additions and 2954 deletions
@@ -0,0 +1,42 @@
using FarseerPhysics;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Dynamics.Joints;
using Barotrauma.Networking;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Microsoft.Xna.Framework;
namespace Barotrauma
{
partial class Character : Entity, IDamageable, IPropertyObject, IClientSerializable, IServerSerializable
{
//the Character that the player is currently controlling
private const Character controlled = null;
public static Character Controlled
{
get { return controlled; }
set
{
//do nothing
}
}
private void InitProjSpecific(XDocument doc)
{
//do nothing
}
private void UpdateControlled(float deltaTime)
{
//do nothing
}
private void ImplodeFX()
{
//do nothing
}
}
}
+23
View File
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Barotrauma.Networking;
using Barotrauma.Items.Components;
using System.Text;
using FarseerPhysics;
namespace Barotrauma
{
static partial class DebugConsole
{
private static string InputText;
private static bool ExecProjSpecific(string[] commands)
{
return false; //command not found
}
}
}
+54 -10
View File
@@ -11,25 +11,69 @@ namespace Barotrauma
{
class GameMain
{
public static readonly Version Version = Assembly.GetEntryAssembly().GetName().Version;
public static World World;
public static GameSettings Config;
public static GameServer Server;
public static GameSession GameSession;
public static GameClient Client
{
get { return null; }
}
public const GameClient Client = null;
public static NetworkMember NetworkMember
{
get { return Server as NetworkMember; }
}
public static Screen EditMapScreen
public static GameSession GameSession;
public static GameMain Instance
{
get { return null; }
get;
private set;
}
//only screens the server implements
public static GameScreen GameScreen;
public static NetLobbyScreen NetLobbyScreen;
//null screens because they are not implemented by the server,
//but they're checked for all over the place
//TODO: maybe clean up instead of having these constants
public const Screen MainMenuScreen = null;
public const Screen LobbyScreen = null;
public const Screen ServerListScreen = null;
public const Screen EditMapScreen = null;
public const Screen EditCharacterScreen = null;
//
public static ContentPackage SelectedPackage
{
get { return Config.SelectedContentPackage; }
}
public GameMain()
{
Instance = this;
Config = new GameSettings("serverconfig.xml");
if (Config.WasGameUpdated)
{
UpdaterUtil.CleanOldFiles();
Config.WasGameUpdated = false;
Config.Save("serverconfig.xml");
}
}
public void Run()
{
//TODO: implement
}
public CoroutineHandle ShowLoading(IEnumerable<object> loader, bool waitKeyHit = true)
{
return CoroutineManager.StartCoroutine(loader);
}
}
}
@@ -0,0 +1,12 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Xml.Linq;
namespace Barotrauma
{
partial class GameSession
{
public const Map Map = null;
}
}
+49
View File
@@ -0,0 +1,49 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace Barotrauma
{
public enum WindowMode
{
Windowed, Fullscreen, BorderlessWindowed
}
public partial class GameSettings
{
private void InitProjSpecific(XDocument doc)
{
//do nothing
}
public void Save(string filePath)
{
XDocument doc = new XDocument();
if (doc.Root == null)
{
doc.Add(new XElement("config"));
}
doc.Root.Add(
new XAttribute("masterserverurl", MasterServerUrl),
new XAttribute("autocheckupdates", AutoCheckUpdates),
new XAttribute("verboselogging", VerboseLogging));
if (WasGameUpdated)
{
doc.Root.Add(new XAttribute("wasgameupdated", true));
}
if (SelectedContentPackage != null)
{
doc.Root.Add(new XElement("contentpackage",
new XAttribute("path", SelectedContentPackage.Path)));
}
doc.Save(filePath);
}
}
}
@@ -0,0 +1,20 @@
using System;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Barotrauma.Networking;
using Lidgren.Network;
using System.Collections.Generic;
using Barotrauma.Items.Components;
namespace Barotrauma
{
partial class CharacterInventory : Inventory
{
void InitProjSpecific()
{
//do nothing
}
}
}
@@ -0,0 +1,39 @@
using Microsoft.Xna.Framework;
using System.Xml.Linq;
namespace Barotrauma.Items.Components
{
partial class ItemLabel : ItemComponent, IDrawableComponent
{
[HasDefaultValue("", true), Editable(100)]
public string Text
{
get;
set;
}
[Editable, HasDefaultValue("0.0,0.0,0.0,1.0", true)]
public string TextColor
{
get;
set;
}
[Editable, HasDefaultValue(1.0f, true)]
public float TextScale
{
get;
set;
}
public override void Move(Vector2 amount)
{
//do nothing
}
public ItemLabel(Item item, XElement element)
: base(item, element)
{
}
}
}
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Lidgren.Network;
using Microsoft.Xna.Framework;
using RestSharp;
using Barotrauma.Items.Components;
namespace Barotrauma.Networking
{
partial class GameServer : NetworkMember
{
void InitProjSpecific()
{
//do nothing
}
void InitUPnP()
{
server.UPnP.ForwardPort(config.Port, "barotrauma");
}
bool DiscoveringUPnP()
{
return server.UPnP.Status == UPnPStatus.Discovering;
}
void FinishUPnP()
{
//do nothing
}
}
}
@@ -0,0 +1,25 @@
using Barotrauma.Networking;
using Lidgren.Network;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Barotrauma
{
partial class Voting
{
public bool AllowSubVoting
{
get { return allowSubVoting; }
set { allowSubVoting = value; }
}
public bool AllowModeVoting
{
get { return allowModeVoting; }
set { allowModeVoting = value; }
}
}
}
+11 -96
View File
@@ -7,8 +7,6 @@ using System.Text;
#if WINDOWS
using System.Management;
using System.Windows.Forms;
using Microsoft.Xna.Framework.Graphics;
#endif
#endregion
@@ -29,109 +27,29 @@ namespace Barotrauma
[STAThread]
static void Main()
{
using (var game = new GameMain())
{
#if DEBUG
game.Run();
#else
bool attemptRestart = false;
do
{
try
{
game.Run();
attemptRestart = false;
}
catch (Exception e)
{
if (restartAttempts < 5 && CheckException(game, e))
{
attemptRestart = true;
restartAttempts++;
}
else
{
CrashDump(game, "crashreport.txt", e);
attemptRestart = false;
}
}
} while (attemptRestart);
#endif
}
}
private static bool CheckException(GameMain game, Exception e)
{
#if WINDOWS
if (e is SharpDX.SharpDXException)
GameMain game = null;
try
{
switch ((uint)((SharpDX.SharpDXException)e).ResultCode.Code)
{
case 0x887A0022: //DXGI_ERROR_NOT_CURRENTLY_AVAILABLE
switch (restartAttempts)
{
case 0:
//just wait and try again
System.Threading.Thread.Sleep(100);
return true;
case 1:
//force focus to this window
var myForm = (System.Windows.Forms.Form)System.Windows.Forms.Form.FromHandle(game.Window.Handle);
myForm.Focus();
return true;
case 2:
//try disabling hardware mode switch
if (GameMain.Config.WindowMode == WindowMode.Fullscreen)
{
DebugConsole.NewMessage("Failed to set fullscreen mode, switching configuration to borderless windowed", Microsoft.Xna.Framework.Color.Red);
GameMain.Config.WindowMode = WindowMode.BorderlessWindowed;
GameMain.Config.Save("config.xml");
}
return false;
default:
return false;
}
case 0x80070057: //E_INVALIDARG/Invalid Arguments
DebugConsole.NewMessage("Invalid graphics settings, attempting to fix", Microsoft.Xna.Framework.Color.Red);
GameMain.Config.GraphicsWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
GameMain.Config.GraphicsHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
game.ApplyGraphicsSettings();
return true;
default:
return false;
}
game = new GameMain();
game.Run();
}
catch (Exception e)
{
CrashDump(game, "servercrashreport.txt", e);
}
#endif
return false;
}
public static void CrashMessageBox(string message)
{
#if WINDOWS
MessageBox.Show(message, "Oops! Barotrauma just crashed.", MessageBoxButtons.OK, MessageBoxIcon.Error);
#endif
}
static void CrashDump(GameMain game, string filePath, Exception exception)
{
StreamWriter sw = new StreamWriter(filePath);
StringBuilder sb = new StringBuilder();
sb.AppendLine("Barotrauma crash report (generated on " + DateTime.Now + ")");
sb.AppendLine("Barotrauma Dedicated Server crash report (generated on " + DateTime.Now + ")");
sb.AppendLine("\n");
sb.AppendLine("Barotrauma seems to have crashed. Sorry for the inconvenience! ");
sb.AppendLine("If you'd like to help fix the bug that caused the crash, please send this file to the developers on the Undertow Games forums.");
sb.AppendLine("\n");
sb.AppendLine("Game version " + GameMain.Version);
sb.AppendLine("Graphics mode: " + GameMain.Config.GraphicsWidth + "x" + GameMain.Config.GraphicsHeight + " (" + GameMain.Config.WindowMode.ToString() + ")");
sb.AppendLine("Selected content package: " + GameMain.SelectedPackage.Name);
sb.AppendLine("Level seed: " + ((Level.Loaded == null) ? "no level loaded" : Level.Loaded.Seed));
sb.AppendLine("Loaded submarine: " + ((Submarine.MainSub == null) ? "None" : Submarine.MainSub.Name + " (" + Submarine.MainSub.MD5Hash + ")"));
@@ -164,10 +82,7 @@ namespace Barotrauma
sw.WriteLine(sb.ToString());
sw.Close();
CrashMessageBox( "A crash report (\"crashreport.txt\") was saved in the root folder of the game."+
" If you'd like to help fix this bug, please post the report on the Undertow Games forums.");
sw.Close();
}
}
#endif
@@ -0,0 +1,62 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Barotrauma.Networking;
using System.Linq;
using System.Collections.Generic;
using System.Reflection;
using System.ComponentModel;
namespace Barotrauma
{
partial class NetLobbyScreen : Screen
{
public Submarine SelectedSub;
public Submarine SelectedShuttle;
private GameModePreset[] GameModes;
public int SelectedModeIndex;
public GameModePreset SelectedMode
{
get { return GameModes[SelectedModeIndex]; }
}
public string ServerMessageText;
public int MissionTypeIndex;
public List<JobPrefab> JobPreferences
{
get
{
return null;
}
}
private List<Submarine> subs = new List<Submarine>();
public List<Submarine> GetSubList()
{
return subs;
}
public string LevelSeed
{
get
{
return levelSeed;
}
set
{
if (levelSeed == value) return;
levelSeed = value;
}
}
public bool StartButtonEnabled
{
get { return true; }
set { /* do nothing */ }
}
}
}