Modified code to compile on Linux
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
#if WINDOWS
|
||||
using System.Windows;
|
||||
#endif
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
|
||||
@@ -42,12 +44,14 @@ namespace EventInput
|
||||
//ctrl-v
|
||||
if (e.Character == 0x16)
|
||||
{
|
||||
#if WINDOWS
|
||||
//XNA runs in Multiple Thread Apartment state, which cannot recieve clipboard
|
||||
Thread thread = new Thread(PasteThread);
|
||||
thread.SetApartmentState(ApartmentState.STA);
|
||||
thread.Start();
|
||||
thread.Join();
|
||||
_subscriber.ReceiveTextInput(_pasteResult);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -74,6 +78,7 @@ namespace EventInput
|
||||
}
|
||||
}
|
||||
|
||||
#if WINDOWS
|
||||
//Thread has to be in Single Thread Apartment state in order to receive clipboard
|
||||
string _pasteResult = "";
|
||||
[STAThread]
|
||||
@@ -81,5 +86,7 @@ namespace EventInput
|
||||
{
|
||||
_pasteResult = Clipboard.ContainsText() ? Clipboard.GetText() : "";
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,7 +274,7 @@ namespace Subsurface
|
||||
|
||||
bool clicked = false;
|
||||
|
||||
if (rect.Contains(PlayerInput.GetMouseState.Position))
|
||||
if (rect.Contains(PlayerInput.MousePosition))
|
||||
{
|
||||
clicked = (PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed);
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace Subsurface
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
if (rect.Contains(PlayerInput.GetMouseState.Position) && Enabled && (MouseOn == null || MouseOn == this || IsParentOf(MouseOn)))
|
||||
if (rect.Contains(PlayerInput.MousePosition) && Enabled && (MouseOn == null || MouseOn == this || IsParentOf(MouseOn)))
|
||||
{
|
||||
state = ComponentState.Hover;
|
||||
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed)
|
||||
|
||||
@@ -284,7 +284,7 @@ namespace Subsurface
|
||||
if (CheckSelected() != selected.UserData) selected = null;
|
||||
}
|
||||
}
|
||||
else if (enabled && (MouseOn == this || (MouseOn != null && this.IsParentOf(MouseOn))) && child.Rect.Contains(PlayerInput.GetMouseState.Position))
|
||||
else if (enabled && (MouseOn == this || (MouseOn != null && this.IsParentOf(MouseOn))) && child.Rect.Contains(PlayerInput.MousePosition))
|
||||
{
|
||||
child.State = ComponentState.Hover;
|
||||
if (PlayerInput.LeftButtonClicked())
|
||||
|
||||
@@ -155,14 +155,14 @@ namespace Subsurface
|
||||
int moveAmount;
|
||||
if (isHorizontal)
|
||||
{
|
||||
moveAmount = PlayerInput.GetMouseState.Position.X - PlayerInput.GetOldMouseState.Position.X;
|
||||
moveAmount = (int)PlayerInput.MouseSpeed.X;
|
||||
newX = Math.Min(Math.Max(newX + moveAmount, 0), frame.Rect.Width - bar.Rect.Width);
|
||||
|
||||
barScroll = (float)newX / ((float)frame.Rect.Width - (float)bar.Rect.Width);
|
||||
}
|
||||
else
|
||||
{
|
||||
moveAmount = PlayerInput.GetMouseState.Position.Y - PlayerInput.GetOldMouseState.Position.Y;
|
||||
moveAmount = (int)PlayerInput.MouseSpeed.Y;
|
||||
newY = Math.Min(Math.Max(newY+moveAmount, 0), frame.Rect.Height - bar.Rect.Height);
|
||||
|
||||
barScroll = (float)newY / ((float)frame.Rect.Height - (float)bar.Rect.Height);
|
||||
|
||||
@@ -158,7 +158,7 @@ namespace Subsurface
|
||||
caretTimer += deltaTime;
|
||||
caretVisible = ((caretTimer*1000.0f) % 1000) < 500;
|
||||
|
||||
if (rect.Contains(PlayerInput.GetMouseState.Position))
|
||||
if (rect.Contains(PlayerInput.MousePosition))
|
||||
{
|
||||
state = ComponentState.Hover;
|
||||
if (PlayerInput.LeftButtonClicked()) Select();
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace Subsurface
|
||||
|
||||
if (!Enabled) return;
|
||||
|
||||
if (box.Rect.Contains(PlayerInput.GetMouseState.Position))
|
||||
if (box.Rect.Contains(PlayerInput.MousePosition))
|
||||
{
|
||||
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ using Subsurface.Particles;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using System.Xml;
|
||||
|
||||
namespace Subsurface
|
||||
{
|
||||
@@ -119,8 +120,8 @@ namespace Subsurface
|
||||
//TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 55);
|
||||
|
||||
World = new World(new Vector2(0, -9.82f));
|
||||
Settings.VelocityIterations = 2;
|
||||
Settings.PositionIterations = 1;
|
||||
FarseerPhysics.Settings.VelocityIterations = 2;
|
||||
FarseerPhysics.Settings.PositionIterations = 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -324,4 +325,4 @@ namespace Subsurface
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -156,7 +156,7 @@ namespace Subsurface
|
||||
public int GetWaveIndex(Vector2 position)
|
||||
{
|
||||
int index = (int)(position.X - rect.X) / WaveWidth;
|
||||
index = MathHelper.Clamp(index, 0, waveY.Length-1);
|
||||
index = (int)MathHelper.Clamp(index, 0, waveY.Length-1);
|
||||
return index;
|
||||
}
|
||||
|
||||
|
||||
@@ -245,7 +245,10 @@ namespace Subsurface.Lights
|
||||
* Matrix.CreateOrthographic(Game1.GraphicsWidth, Game1.GraphicsHeight, -1, 1) * 0.5f;
|
||||
shadowEffect.CurrentTechnique.Passes[0].Apply();
|
||||
|
||||
graphicsDevice.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleList, penumbraVertices, 0, 2, VertexPositionTexture.VertexDeclaration);
|
||||
#if WINDOWS
|
||||
graphicsDevice.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleList, penumbraVertices, 0, 2, VertexPositionTexture.VertexDeclaration);
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +109,12 @@ namespace Subsurface
|
||||
{
|
||||
pass.Apply();
|
||||
|
||||
graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, verts, 0, verts.Length / 3, WaterVertex.VertexDeclaration);
|
||||
#if WINDOWS
|
||||
graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, verts, 0, verts.Length / 3, WaterVertex.VertexDeclaration);
|
||||
#endif
|
||||
#if LINUX
|
||||
//graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, verts, 0, verts.Length / 3, WaterVertex.VertexDeclaration, );
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +135,9 @@ namespace Subsurface
|
||||
{
|
||||
pass.Apply();
|
||||
|
||||
graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, vertices.Length / 3, WaterVertex.VertexDeclaration);
|
||||
#if WINDOWS
|
||||
graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, vertices.Length / 3, WaterVertex.VertexDeclaration);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -710,7 +710,6 @@ namespace Subsurface.Networking
|
||||
{
|
||||
spriteBatch.DrawString(GUI.SmallFont, c.name + ":", new Vector2(x + 10, y), Color.White);
|
||||
spriteBatch.DrawString(GUI.SmallFont, "- avg roundtrip " + c.Connection.AverageRoundtripTime+" s", new Vector2(x + 20, y + 15), Color.White);
|
||||
spriteBatch.DrawString(GUI.SmallFont, "- current MTU " + c.Connection.CurrentMTU, new Vector2(x + 20, y + 30), Color.White);
|
||||
y += 50;
|
||||
|
||||
}
|
||||
|
||||
@@ -69,7 +69,12 @@ namespace Subsurface
|
||||
|
||||
public static Vector2 MousePosition
|
||||
{
|
||||
#if WINDOWS
|
||||
get { return new Vector2(mouseState.Position.X, mouseState.Position.Y); }
|
||||
#endif
|
||||
#if LINUX
|
||||
get { return new Vector2(mouseState.Y, mouseState.X); }
|
||||
#endif
|
||||
}
|
||||
|
||||
public static MouseState GetMouseState
|
||||
@@ -85,8 +90,12 @@ namespace Subsurface
|
||||
{
|
||||
get
|
||||
{
|
||||
Point speed = mouseState.Position - oldMouseState.Position;
|
||||
return new Vector2(speed.X, speed.Y);
|
||||
#if WINDOWS
|
||||
return mouseState.Position - oldMouseState.Position;
|
||||
#endif
|
||||
#if LINUX
|
||||
return MousePosition - new Vector2(oldMouseState.X, oldMouseState.Y);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
||||
|
||||
namespace Subsurface
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
|
||||
@@ -146,7 +146,7 @@ namespace Subsurface
|
||||
graphics.Clear(new Color(11, 18, 26, 255));
|
||||
|
||||
|
||||
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.LinearWrap);
|
||||
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.LinearWrap, DepthStencilState.Default, RasterizerState.CullNone);
|
||||
|
||||
Vector2 backgroundPos = cam.Position;
|
||||
if (Level.Loaded != null) backgroundPos -= Level.Loaded.Position;
|
||||
|
||||
@@ -191,7 +191,7 @@ namespace Subsurface
|
||||
int currMaxPlayers = 10;
|
||||
|
||||
int.TryParse(maxPlayersBox.Text, out currMaxPlayers);
|
||||
currMaxPlayers = MathHelper.Clamp(currMaxPlayers+(int)button.UserData, 1, 10);
|
||||
currMaxPlayers = (int)MathHelper.Clamp(currMaxPlayers+(int)button.UserData, 1, 10);
|
||||
|
||||
maxPlayersBox.Text = currMaxPlayers.ToString();
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using OpenTK.Audio;
|
||||
#if WINDOWS
|
||||
using OpenTK.Audio.OpenAL;
|
||||
#endif
|
||||
using OpenTK.Audio;
|
||||
|
||||
using System;
|
||||
|
||||
namespace Subsurface.Sounds
|
||||
@@ -34,14 +37,14 @@ namespace Subsurface.Sounds
|
||||
|
||||
for (int i = 0 ; i < DefaultSourceCount; i++)
|
||||
{
|
||||
alSources.Add(AL.GenSource());
|
||||
alSources.Add(OpenTK.Audio.OpenAL.AL.GenSource());
|
||||
}
|
||||
|
||||
if (ALHelper.Efx.IsInitialized)
|
||||
{
|
||||
lowpassFilterId = ALHelper.Efx.GenFilter();
|
||||
//alFilters.Add(alFilterId);
|
||||
ALHelper.Efx.Filter(lowpassFilterId, EfxFilteri.FilterType, (int)EfxFilterType.Lowpass);
|
||||
ALHelper.Efx.Filter(lowpassFilterId, OpenTK.Audio.OpenAL.EfxFilteri.FilterType, (int)OpenTK.Audio.OpenAL.EfxFilterType.Lowpass);
|
||||
|
||||
//LowPassHFGain = 1;
|
||||
}
|
||||
@@ -129,29 +132,29 @@ namespace Subsurface.Sounds
|
||||
for (int i = 1; i < DefaultSourceCount; i++)
|
||||
{
|
||||
//find a source that's free to use (not playing or paused)
|
||||
if (AL.GetSourceState(alSources[i]) == ALSourceState.Playing
|
||||
|| AL.GetSourceState(alSources[i]) == ALSourceState.Paused) continue;
|
||||
if (OpenTK.Audio.OpenAL.AL.GetSourceState(alSources[i]) == OpenTK.Audio.OpenAL.ALSourceState.Playing
|
||||
|| OpenTK.Audio.OpenAL.AL.GetSourceState(alSources[i]) == OpenTK.Audio.OpenAL.ALSourceState.Paused) continue;
|
||||
|
||||
//if (position!=Vector2.Zero)
|
||||
// position /= 1000.0f;
|
||||
|
||||
alBuffers[i] = sound.AlBufferId;
|
||||
AL.Source(alSources[i], ALSourceb.Looping, false);
|
||||
OpenTK.Audio.OpenAL.AL.Source(alSources[i], OpenTK.Audio.OpenAL.ALSourceb.Looping, false);
|
||||
|
||||
position /= 1000.0f;
|
||||
|
||||
//System.Diagnostics.Debug.WriteLine("updatesoundpos: "+offset);
|
||||
AL.Source(alSources[i], ALSourcef.Gain, volume);
|
||||
AL.Source(alSources[i], ALSource3f.Position, position.X, position.Y, 0.0f);
|
||||
OpenTK.Audio.OpenAL.AL.Source(alSources[i], OpenTK.Audio.OpenAL.ALSourcef.Gain, volume);
|
||||
OpenTK.Audio.OpenAL.AL.Source(alSources[i], OpenTK.Audio.OpenAL.ALSource3f.Position, position.X, position.Y, 0.0f);
|
||||
|
||||
AL.Source(alSources[i], ALSourcei.Buffer, sound.AlBufferId);
|
||||
OpenTK.Audio.OpenAL.AL.Source(alSources[i], OpenTK.Audio.OpenAL.ALSourcei.Buffer, sound.AlBufferId);
|
||||
|
||||
ALHelper.Efx.Filter(lowpassFilterId, EfxFilterf.LowpassGainHF, lowPassHfGain = Math.Min(lowPassGain, overrideLowPassGain));
|
||||
ALHelper.Efx.Filter(lowpassFilterId, OpenTK.Audio.OpenAL.EfxFilterf.LowpassGainHF, lowPassHfGain = Math.Min(lowPassGain, overrideLowPassGain));
|
||||
ALHelper.Efx.BindFilterToSource(alSources[i], lowpassFilterId);
|
||||
ALHelper.Check();
|
||||
|
||||
//AL.Source(alSources[i], ALSource3f.Position, position.X, position.Y, 0.0f);
|
||||
AL.SourcePlay(alSources[i]);
|
||||
OpenTK.Audio.OpenAL.AL.SourcePlay(alSources[i]);
|
||||
|
||||
//sound.sourceIndex = i;
|
||||
|
||||
@@ -261,10 +264,10 @@ namespace Subsurface.Sounds
|
||||
for (int i = 0; i < DefaultSourceCount; i++)
|
||||
{
|
||||
//find a source that's free to use (not playing or paused)
|
||||
if (AL.GetSourceState(alSources[i]) != ALSourceState.Playing
|
||||
&& AL.GetSourceState(alSources[i])!= ALSourceState.Paused) continue;
|
||||
if (OpenTK.Audio.OpenAL.AL.GetSourceState(alSources[i]) != OpenTK.Audio.OpenAL.ALSourceState.Playing
|
||||
&& OpenTK.Audio.OpenAL.AL.GetSourceState(alSources[i])!= OpenTK.Audio.OpenAL.ALSourceState.Paused) continue;
|
||||
|
||||
ALHelper.Efx.Filter(lowpassFilterId, EfxFilterf.LowpassGainHF, lowPassHfGain = value);
|
||||
ALHelper.Efx.Filter(lowpassFilterId, OpenTK.Audio.OpenAL.EfxFilterf.LowpassGainHF, lowPassHfGain = value);
|
||||
ALHelper.Efx.BindFilterToSource(alSources[i], lowpassFilterId);
|
||||
ALHelper.Check();
|
||||
}
|
||||
@@ -293,10 +296,10 @@ namespace Subsurface.Sounds
|
||||
position/= 1000.0f;
|
||||
|
||||
//System.Diagnostics.Debug.WriteLine("updatesoundpos: "+offset);
|
||||
AL.Source(alSources[sourceIndex], ALSourcef.Gain, baseVolume);
|
||||
AL.Source(alSources[sourceIndex], ALSource3f.Position, position.X, position.Y, 0.0f);
|
||||
OpenTK.Audio.OpenAL.AL.Source(alSources[sourceIndex], OpenTK.Audio.OpenAL.ALSourcef.Gain, baseVolume);
|
||||
OpenTK.Audio.OpenAL.AL.Source(alSources[sourceIndex], OpenTK.Audio.OpenAL.ALSource3f.Position, position.X, position.Y, 0.0f);
|
||||
|
||||
ALHelper.Efx.Filter(lowpassFilterId, EfxFilterf.LowpassGainHF, lowPassHfGain = Math.Min(lowPassGain, overrideLowPassGain));
|
||||
ALHelper.Efx.Filter(lowpassFilterId, OpenTK.Audio.OpenAL.EfxFilterf.LowpassGainHF, lowPassHfGain = Math.Min(lowPassGain, overrideLowPassGain));
|
||||
ALHelper.Efx.BindFilterToSource(alSources[sourceIndex], lowpassFilterId);
|
||||
ALHelper.Check();
|
||||
}
|
||||
@@ -328,7 +331,7 @@ namespace Subsurface.Sounds
|
||||
{
|
||||
if (alBuffers[i] == bufferId)
|
||||
{
|
||||
AL.Source(alSources[i], ALSourcei.Buffer, 0);
|
||||
OpenTK.Audio.OpenAL.AL.Source(alSources[i], OpenTK.Audio.OpenAL.ALSourcei.Buffer, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,11 +346,11 @@ namespace Subsurface.Sounds
|
||||
|
||||
for (int i = 0; i < DefaultSourceCount; i++)
|
||||
{
|
||||
var state = AL.GetSourceState(alSources[i]);
|
||||
if (state == ALSourceState.Playing || state == ALSourceState.Paused)
|
||||
var state = OpenTK.Audio.OpenAL.AL.GetSourceState(alSources[i]);
|
||||
if (state == OpenTK.Audio.OpenAL.ALSourceState.Playing || state == OpenTK.Audio.OpenAL.ALSourceState.Paused)
|
||||
Stop(i);
|
||||
|
||||
AL.DeleteSource(alSources[i]);
|
||||
OpenTK.Audio.OpenAL.AL.DeleteSource(alSources[i]);
|
||||
|
||||
ALHelper.Check();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.IO;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Color = Microsoft.Xna.Framework.Color;
|
||||
using System;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace Subsurface
|
||||
{
|
||||
@@ -44,8 +45,15 @@ namespace Subsurface
|
||||
{
|
||||
try
|
||||
{
|
||||
#if WINDOWS
|
||||
using (Stream fileStream = File.OpenRead(path))
|
||||
return FromStream(fileStream, preMultiplyAlpha);
|
||||
#endif
|
||||
#if LINUX
|
||||
using (Stream fileStream = File.OpenRead(path))
|
||||
return Texture2D.FromFile(_graphicsDevice, fileStream);// .FromStream(fileStream, preMultiplyAlpha);
|
||||
#endif
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -55,7 +63,8 @@ namespace Subsurface
|
||||
|
||||
}
|
||||
|
||||
public Texture2D FromStream(Stream stream, bool preMultiplyAlpha = true)
|
||||
#if WINDOWS
|
||||
private Texture2D FromStream(Stream stream, bool preMultiplyAlpha = true)
|
||||
{
|
||||
Texture2D texture;
|
||||
|
||||
@@ -114,6 +123,8 @@ namespace Subsurface
|
||||
|
||||
return texture;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
private static readonly BlendState BlendColorBlendState;
|
||||
private static readonly BlendState BlendAlphaBlendState;
|
||||
|
||||
Reference in New Issue
Block a user