mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 11:40:52 +01:00
Compare commits
80 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f227b3abc0 | ||
|
|
3920da2d9f | ||
|
|
bfbb31aa58 | ||
|
|
799be40018 | ||
|
|
152eb8dd19 | ||
|
|
c168c0fde1 | ||
|
|
af3c90e2a8 | ||
|
|
12e6ef88c3 | ||
|
|
28d74cec56 | ||
|
|
02efd0b41a | ||
|
|
5bf337479f | ||
|
|
3816cdb3e4 | ||
|
|
e54339bb5c | ||
|
|
98d867393c | ||
|
|
8dd9a3c097 | ||
|
|
61d30be6b3 | ||
|
|
7aa85c0b0c | ||
|
|
3574395843 | ||
|
|
13b333dcf6 | ||
|
|
bead08fc7c | ||
|
|
073fb20b66 | ||
|
|
7adca8280c | ||
|
|
61183eaba3 | ||
|
|
477b0460e8 | ||
|
|
dd18105c92 | ||
|
|
585f2467c2 | ||
|
|
0c3e4ea495 | ||
|
|
afe0c95cea | ||
|
|
e84f072278 | ||
|
|
ca0bbab8c0 | ||
|
|
6530b8806c | ||
|
|
294057e3a1 | ||
|
|
a57abb2ca7 | ||
|
|
f0d6680977 | ||
|
|
49f7b987f5 | ||
|
|
444d0847b6 | ||
|
|
005bd9e95c | ||
|
|
dfcf0349ca | ||
|
|
45a7a809db | ||
|
|
48852c5ee8 | ||
|
|
60ac4a9e26 | ||
|
|
5351f581f1 | ||
|
|
e719dd1440 | ||
|
|
1d5ca223de | ||
|
|
3170552b3d | ||
|
|
18692e21a4 | ||
|
|
ae0ccc72b4 | ||
|
|
f5eb8cd55b | ||
|
|
db1c71994b | ||
|
|
96df096303 | ||
|
|
9669221d37 | ||
|
|
480ed6d74c | ||
|
|
1d2614d75f | ||
|
|
1c5f540751 | ||
|
|
f4fe79346e | ||
|
|
cb5bfbb3da | ||
|
|
f41050583e | ||
|
|
85fa167e17 | ||
|
|
b9723b6504 | ||
|
|
2e64de57c6 | ||
|
|
feaf4160e8 | ||
|
|
93fd0014b4 | ||
|
|
22f07e3649 | ||
|
|
398a3917dc | ||
|
|
04fa16902f | ||
|
|
b0e42ef650 | ||
|
|
b0d7ee16c1 | ||
|
|
b9ece2888b | ||
|
|
d1b29a6f94 | ||
|
|
a43da12f9b | ||
|
|
4607a106d0 | ||
|
|
de9fd0cbaf | ||
|
|
2e3315cd39 | ||
|
|
f7b1b9c4b6 | ||
|
|
2572bc94c7 | ||
|
|
47f1aa6565 | ||
|
|
fdde14b93e | ||
|
|
975eea832d | ||
|
|
09ecdade70 | ||
|
|
e8b40f6091 |
@@ -15,8 +15,10 @@ install:
|
||||
- ps: if (-Not $env:APPVEYOR_PULL_REQUEST_NUMBER) { cinst msbuild-sonarqube-runner }
|
||||
|
||||
before_build:
|
||||
- cmd: py -3.5 RUN_THIS.py
|
||||
- cmd: py -3.5 Resources\buildResourcePack.py --resources-dir .\Resources --out .\Resources\ResourcePack.zip --atlas-tool .\Tools\AtlasTool.exe --no-animations --to-stderr
|
||||
- cmd: nuget restore SpaceStation14.sln
|
||||
- ps: if (-Not $env:APPVEYOR_PULL_REQUEST_NUMBER) { MSBuild.SonarQube.Runner.exe begin /k:"ss14" /d:"sonar.host.url=https://sonarqube.com" /d:"sonar.login=$env:sonarqubekey" /d:"sonar.organization=space-wizards" }
|
||||
- ps: if (-Not $env:APPVEYOR_PULL_REQUEST_NUMBER) { MSBuild.SonarQube.Runner.exe begin /k:"ss14" /d:"sonar.host.url=https://sonarqube.com" /d:"sonar.login=$env:sonarqubekey" /d:"sonar.organization=space-wizards" /d:"sonar.exclusions=SFML/**"}
|
||||
|
||||
build:
|
||||
project: SpaceStation14.sln
|
||||
@@ -25,4 +27,3 @@ build:
|
||||
|
||||
after_build:
|
||||
- ps: if (-Not $env:APPVEYOR_PULL_REQUEST_NUMBER) { MSBuild.SonarQube.Runner.exe end /d:"sonar.login=$env:sonarqubekey" }
|
||||
- cmd: py -3.5 Resources\buildResourcePack.py --resources-dir .\Resources --out .\Resources\ResourcePack.zip --atlas-tool .\Tools\AtlasTool.exe --no-animations --to-stderr
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"phabricator.uri": "http://phab.nexisonline.net",
|
||||
"project.name": "Space Station 14"
|
||||
}
|
||||
@@ -7,5 +7,5 @@ indent_size = 4
|
||||
trim_trailing_whitespace = true
|
||||
charset = utf-8-bom
|
||||
|
||||
[*.{csproj,xml,yml,dll.config}]
|
||||
[*.{csproj,xml,yml,dll.config,targets}]
|
||||
indent_size = 2
|
||||
|
||||
7
.gitignore
vendored
7
.gitignore
vendored
@@ -75,4 +75,9 @@ project.lock.json
|
||||
# Created by NUnit.
|
||||
TestResult.xml
|
||||
|
||||
NetSerializerDebug.dll
|
||||
NetSerializerDebug.dll
|
||||
|
||||
# We're not gonna ship Mac extlibs with the repo due to size. (11 MB)
|
||||
Third-Party/extlibs/Mac/
|
||||
# Or the automatically-fetched Windows natives, for that matter.
|
||||
Third-Party/extlibs/Windows/
|
||||
|
||||
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[submodule "SFML"]
|
||||
path = SFML
|
||||
url = https://github.com/space-wizards/SFML.Net.git
|
||||
@@ -11,11 +11,12 @@ before_install:
|
||||
- if [ $TRAVIS_OS_NAME = osx ]; then brew update && brew install python3; fi
|
||||
|
||||
before_script:
|
||||
- "python3 ./Resources/buildResourcePack.py --resources-dir ./Resources --out ./Resources/ResourcePack.zip --no-atlas --no-animations --to-stderr"
|
||||
- "nuget restore SpaceStation14.sln"
|
||||
- "python3 RUN_THIS.py"
|
||||
|
||||
script:
|
||||
- "msbuild /p:Configuration=Release /p:HEADLESS=1 SpaceStation14.sln"
|
||||
- "cd packages/NUnit.ConsoleRunner.3.6.1/tools"
|
||||
- "mono --debug nunit3-console.exe ../../../SS14.UnitTesting/bin/Release/SS14.UnitTesting.dll"
|
||||
- "python3 ./Resources/buildResourcePack.py --resources-dir ./Resources --out ./Resources/ResourcePack.zip --no-atlas --no-animations --to-stderr"
|
||||
- "msbuild /p:Configuration=Release /p:Platform=x86 /p:HEADLESS=1 /nologo /m /p:AllowMissingMacNatives=yes SpaceStation14.sln"
|
||||
- "cd packages/NUnit.ConsoleRunner.3.7.0/tools"
|
||||
- "mono --debug nunit3-console.exe ../../../bin/UnitTesting/SS14.UnitTesting.dll"
|
||||
|
||||
|
||||
1
BuildChecker/.gitignore
vendored
Normal file
1
BuildChecker/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
INSTALLED_HOOKS_VERSION
|
||||
30
BuildChecker/BuildChecker.csproj
Normal file
30
BuildChecker/BuildChecker.csproj
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
This is a dummy .csproj file to check things like submodules.
|
||||
Better this than other errors.
|
||||
|
||||
If you want to create this kind of file yourself, you have to create an empty .NET application,
|
||||
Then strip it of everything until you have the <Project> tags.
|
||||
VS refuses to load the project if you make a bare project file and use Add -> Existing Project... for some reason.
|
||||
|
||||
You want to handle the Build, Clean and Rebuild tasks to prevent missing task errors on build.
|
||||
|
||||
If you want to learn more about these kinds of things, check out Microsoft's official documentation about MSBuild:
|
||||
https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild
|
||||
-->
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Python>python3</Python>
|
||||
<Python Condition="'$(OS)'=='Windows_NT' Or '$(OS)'=='Windows'">py -3</Python>
|
||||
<ProjectGuid>{D0DA124B-5580-4345-A02B-9F051F78915F}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<Target Name="Build">
|
||||
<Exec Command="$(Python) git_helper.py" CustomErrorRegularExpression="^Error" />
|
||||
</Target>
|
||||
<Target Name="Rebuild" DependsOnTargets="Build" />
|
||||
<Target Name="Clean">
|
||||
<Message Importance="low" Text="Ignoring 'Clean' target." />
|
||||
</Target>
|
||||
</Project>
|
||||
101
BuildChecker/git_helper.py
Normal file
101
BuildChecker/git_helper.py
Normal file
@@ -0,0 +1,101 @@
|
||||
#!/usr/bin/env python3
|
||||
# Installs git hooks, updates them, updates submodules, that kind of thing.
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
import os
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
SOLUTION_PATH = Path("..") / "SpaceStation14Content.sln"
|
||||
CURRENT_HOOKS_VERSION = "2" # If this doesn't match the saved version we overwrite them all.
|
||||
QUIET = "--quiet" in sys.argv
|
||||
NO_HOOKS = "--nohooks" in sys.argv
|
||||
|
||||
def run_command(command: List[str], capture: bool = False) -> subprocess.CompletedProcess:
|
||||
"""
|
||||
Runs a command with pretty output.
|
||||
"""
|
||||
text = ' '.join(command)
|
||||
if not QUIET:
|
||||
print("$ {}".format(text))
|
||||
|
||||
sys.stdout.flush()
|
||||
|
||||
completed = None
|
||||
|
||||
if capture:
|
||||
completed = subprocess.run(command, cwd="..", stdout=subprocess.PIPE)
|
||||
else:
|
||||
completed = subprocess.run(command, cwd="..")
|
||||
|
||||
if completed.returncode != 0:
|
||||
print("Error: command exited with code {}!".format(completed.returncode))
|
||||
|
||||
return completed
|
||||
|
||||
|
||||
def update_submodules():
|
||||
"""
|
||||
Updates all submodules.
|
||||
"""
|
||||
|
||||
# If the status doesn't match, force VS to reload the solution.
|
||||
# status = run_command(["git", "submodule", "status"], capture=True)
|
||||
run_command(["git", "submodule", "update", "--init", "--recursive"])
|
||||
# status2 = run_command(["git", "submodule", "status"], capture=True)
|
||||
|
||||
# Something changed.
|
||||
# if status.stdout != status2.stdout:
|
||||
# print("Git submodules changed. Reloading solution.")
|
||||
# reset_solution()
|
||||
|
||||
def install_hooks():
|
||||
"""
|
||||
Installs the necessary git hooks into .git/hooks.
|
||||
"""
|
||||
|
||||
# Read version file.
|
||||
if os.path.isfile("INSTALLED_HOOKS_VERSION"):
|
||||
with open("INSTALLED_HOOKS_VERSION", "r") as f:
|
||||
if f.read() == CURRENT_HOOKS_VERSION:
|
||||
if not QUIET:
|
||||
print("No hooks change detected.")
|
||||
return
|
||||
|
||||
with open("INSTALLED_HOOKS_VERSION", "w") as f:
|
||||
f.write(CURRENT_HOOKS_VERSION)
|
||||
|
||||
print("Hooks need updating.")
|
||||
|
||||
hooks_target_dir = Path("..")/".git"/"hooks"
|
||||
hooks_source_dir = Path("hooks")
|
||||
|
||||
if not os.path.exists(str(hooks_target_dir)):
|
||||
os.makedirs(str(hooks_target_dir))
|
||||
|
||||
# Clear entire tree since we need to kill deleted files too.
|
||||
for filename in os.listdir(str(hooks_target_dir)):
|
||||
os.remove(str(hooks_target_dir/filename))
|
||||
|
||||
for filename in os.listdir(str(hooks_source_dir)):
|
||||
print("Copying hook {}".format(filename))
|
||||
shutil.copyfile(str(hooks_source_dir/filename), str(hooks_target_dir/filename))
|
||||
|
||||
|
||||
def reset_solution():
|
||||
"""
|
||||
Force VS to think the solution has been changed to prompt the user to reload it, thus fixing any load errors.
|
||||
"""
|
||||
|
||||
with SOLUTION_PATH.open("r") as f:
|
||||
content = f.read()
|
||||
|
||||
with SOLUTION_PATH.open("w") as f:
|
||||
f.write(content)
|
||||
|
||||
if __name__ == '__main__':
|
||||
if not NO_HOOKS:
|
||||
install_hooks()
|
||||
update_submodules()
|
||||
19
BuildChecker/hooks/post-checkout
Normal file
19
BuildChecker/hooks/post-checkout
Normal file
@@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
gitroot=`git rev-parse --show-toplevel`
|
||||
|
||||
cd "$gitroot/BuildChecker"
|
||||
|
||||
if [ -f "git_helper.py" ]
|
||||
then
|
||||
if [[ `uname` == MINGW* || `uname` == CYGWIN* ]]; then
|
||||
# Windows
|
||||
# Can't update hooks from here because we are a hook,
|
||||
# and the file is read only while it's used.
|
||||
# Thanks Windows.
|
||||
py -3 git_helper.py --quiet --nohooks
|
||||
else
|
||||
# Not Windows, so probably some other Unix thing.
|
||||
python3 git_helper.py --quiet
|
||||
fi
|
||||
fi
|
||||
5
BuildChecker/hooks/post-merge
Normal file
5
BuildChecker/hooks/post-merge
Normal file
@@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Just call post-checkout since it does the same thing.
|
||||
gitroot=`git rev-parse --show-toplevel`
|
||||
bash "$gitroot/.git/hooks/post-checkout"
|
||||
@@ -1,4 +0,0 @@
|
||||
call "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
|
||||
@echo on
|
||||
call prebuild-2010.cmd
|
||||
call msbuild SpaceStation14.sln /t:Build /p:Configuration=Release;Platform=x86
|
||||
@@ -1,10 +0,0 @@
|
||||
#!/bin/bash
|
||||
prebuild-nant.sh
|
||||
|
||||
nant
|
||||
|
||||
#nunit-console Bin/SS14.Test.dll -nodots -xml=NUnit.Results.xml
|
||||
echo NUnit disabled.
|
||||
|
||||
#7za a SS14.7z Bin/*
|
||||
echo Packaging disabled.
|
||||
@@ -1,2 +0,0 @@
|
||||
cd bin\client
|
||||
start SpaceStation14.exe
|
||||
@@ -1,2 +0,0 @@
|
||||
cd bin\server
|
||||
start SpaceStation14_Server.exe
|
||||
@@ -1,164 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace Lidgren.Network
|
||||
{
|
||||
/// <summary>
|
||||
/// DES encryption
|
||||
/// </summary>
|
||||
public class NetDESEncryption : INetEncryption
|
||||
{
|
||||
private readonly byte[] m_key;
|
||||
private readonly byte[] m_iv;
|
||||
private readonly int m_bitSize;
|
||||
private static readonly List<int> m_keysizes;
|
||||
private static readonly List<int> m_blocksizes;
|
||||
|
||||
static NetDESEncryption()
|
||||
{
|
||||
|
||||
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
|
||||
List<int> temp = new List<int>();
|
||||
foreach (KeySizes keysize in des.LegalKeySizes)
|
||||
{
|
||||
for (int i = keysize.MinSize; i <= keysize.MaxSize; i += keysize.SkipSize)
|
||||
{
|
||||
if (!temp.Contains(i))
|
||||
temp.Add(i);
|
||||
if (i == keysize.MaxSize)
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_keysizes = temp;
|
||||
temp = new List<int>();
|
||||
foreach (KeySizes keysize in des.LegalBlockSizes)
|
||||
{
|
||||
for (int i = keysize.MinSize; i <= keysize.MaxSize; i += keysize.SkipSize)
|
||||
{
|
||||
|
||||
if (!temp.Contains(i))
|
||||
temp.Add(i);
|
||||
if (i == keysize.MaxSize)
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_blocksizes = temp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// NetDESEncryption constructor
|
||||
/// </summary>
|
||||
public NetDESEncryption(byte[] key, byte[] iv)
|
||||
{
|
||||
if (!m_keysizes.Contains(key.Length * 8))
|
||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_keysizes)));
|
||||
|
||||
if (!m_blocksizes.Contains(iv.Length * 8))
|
||||
throw new NetException(string.Format("Not a valid iv size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_blocksizes)));
|
||||
|
||||
m_key = key;
|
||||
m_iv = iv;
|
||||
m_bitSize = m_key.Length * 8;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// NetDESEncryption constructor
|
||||
/// </summary>
|
||||
public NetDESEncryption(string key, int bitsize)
|
||||
{
|
||||
if (!m_keysizes.Contains(bitsize))
|
||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_keysizes)));
|
||||
|
||||
byte[] entropy = Encoding.UTF32.GetBytes(key);
|
||||
// I know hardcoding salts is bad, but in this case I think it is acceptable.
|
||||
HMACSHA512 hmacsha512 = new HMACSHA512(Convert.FromBase64String("i88NEiez3c50bHqr3YGasDc4p8jRrxJAaiRiqixpvp4XNAStP5YNoC2fXnWkURtkha6M8yY901Gj07IRVIRyGL=="));
|
||||
hmacsha512.Initialize();
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
entropy = hmacsha512.ComputeHash(entropy);
|
||||
}
|
||||
int keylen = bitsize / 8;
|
||||
m_key = new byte[keylen];
|
||||
Buffer.BlockCopy(entropy, 0, m_key, 0, keylen);
|
||||
m_iv = new byte[m_blocksizes[0] / 8];
|
||||
|
||||
Buffer.BlockCopy(entropy, entropy.Length - m_iv.Length - 1, m_iv, 0, m_iv.Length);
|
||||
m_bitSize = bitsize;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// NetDESEncryption constructor
|
||||
/// </summary>
|
||||
public NetDESEncryption(string key)
|
||||
: this(key, m_keysizes[0])
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encrypt outgoing message
|
||||
/// </summary>
|
||||
public bool Encrypt(NetOutgoingMessage msg)
|
||||
{
|
||||
try
|
||||
{
|
||||
// nested usings are fun!
|
||||
using (DESCryptoServiceProvider desCryptoServiceProvider = new DESCryptoServiceProvider { KeySize = m_bitSize, Mode = CipherMode.CBC })
|
||||
{
|
||||
using (ICryptoTransform cryptoTransform = desCryptoServiceProvider.CreateEncryptor(m_key, m_iv))
|
||||
{
|
||||
using (MemoryStream memoryStream = new MemoryStream())
|
||||
{
|
||||
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoTransform,
|
||||
CryptoStreamMode.Write))
|
||||
{
|
||||
cryptoStream.Write(msg.m_data, 0, msg.m_data.Length);
|
||||
}
|
||||
msg.m_data = memoryStream.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decrypt incoming message
|
||||
/// </summary>
|
||||
public bool Decrypt(NetIncomingMessage msg)
|
||||
{
|
||||
try
|
||||
{
|
||||
// nested usings are fun!
|
||||
using (DESCryptoServiceProvider desCryptoServiceProvider = new DESCryptoServiceProvider { KeySize = m_bitSize, Mode = CipherMode.CBC })
|
||||
{
|
||||
using (ICryptoTransform cryptoTransform = desCryptoServiceProvider.CreateDecryptor(m_key, m_iv))
|
||||
{
|
||||
using (MemoryStream memoryStream = new MemoryStream())
|
||||
{
|
||||
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoTransform,
|
||||
CryptoStreamMode.Write))
|
||||
{
|
||||
cryptoStream.Write(msg.m_data, 0, msg.m_data.Length);
|
||||
}
|
||||
msg.m_data = memoryStream.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,165 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace Lidgren.Network
|
||||
{
|
||||
/// <summary>
|
||||
/// RC2 encryption
|
||||
/// </summary>
|
||||
public class NetRC2Encryption : INetEncryption
|
||||
{
|
||||
private readonly byte[] m_key;
|
||||
private readonly byte[] m_iv;
|
||||
private readonly int m_bitSize;
|
||||
private static readonly List<int> m_keysizes;
|
||||
private static readonly List<int> m_blocksizes;
|
||||
|
||||
static NetRC2Encryption()
|
||||
{
|
||||
|
||||
RC2CryptoServiceProvider rc2 = new RC2CryptoServiceProvider();
|
||||
List<int> temp = new List<int>();
|
||||
foreach (KeySizes keysize in rc2.LegalKeySizes)
|
||||
{
|
||||
for (int i = keysize.MinSize; i <= keysize.MaxSize; i += keysize.SkipSize)
|
||||
{
|
||||
if (!temp.Contains(i))
|
||||
temp.Add(i);
|
||||
if (i == keysize.MaxSize)
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_keysizes = temp;
|
||||
temp = new List<int>();
|
||||
foreach (KeySizes keysize in rc2.LegalBlockSizes)
|
||||
{
|
||||
for (int i = keysize.MinSize; i <= keysize.MaxSize; i += keysize.SkipSize)
|
||||
{
|
||||
|
||||
if (!temp.Contains(i))
|
||||
temp.Add(i);
|
||||
if (i == keysize.MaxSize)
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_blocksizes = temp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// NetRC2Encryption constructor
|
||||
/// </summary>
|
||||
public NetRC2Encryption(byte[] key, byte[] iv)
|
||||
{
|
||||
if (!m_keysizes.Contains(key.Length * 8))
|
||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_keysizes)));
|
||||
|
||||
if (!m_blocksizes.Contains(iv.Length * 8))
|
||||
throw new NetException(string.Format("Not a valid iv size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_blocksizes)));
|
||||
|
||||
m_key = key;
|
||||
m_iv = iv;
|
||||
m_bitSize = m_key.Length * 8;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// NetRC2Encryption constructor
|
||||
/// </summary>
|
||||
public NetRC2Encryption(string key, int bitsize)
|
||||
{
|
||||
if (!m_keysizes.Contains(bitsize))
|
||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_keysizes)));
|
||||
|
||||
byte[] entropy = Encoding.UTF32.GetBytes(key);
|
||||
// I know hardcoding salts is bad, but in this case I think it is acceptable.
|
||||
HMACSHA512 hmacsha512 = new HMACSHA512(Convert.FromBase64String("i88NEiez3c50bHqr3YGasDc4p8jRrxJAaiRiqixpvp4XNAStP5YNoC2fXnWkURtkha6M8yY901Gj07IRVIRyGL=="));
|
||||
hmacsha512.Initialize();
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
entropy = hmacsha512.ComputeHash(entropy);
|
||||
}
|
||||
int keylen = bitsize / 8;
|
||||
m_key = new byte[keylen];
|
||||
Buffer.BlockCopy(entropy, 0, m_key, 0, keylen);
|
||||
m_iv = new byte[m_blocksizes[0] / 8];
|
||||
|
||||
Buffer.BlockCopy(entropy, entropy.Length - m_iv.Length - 1, m_iv, 0, m_iv.Length);
|
||||
m_bitSize = bitsize;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// NetRC2Encryption constructor
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
public NetRC2Encryption(string key)
|
||||
: this(key, m_keysizes[0])
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encrypt outgoing message
|
||||
/// </summary>
|
||||
public bool Encrypt(NetOutgoingMessage msg)
|
||||
{
|
||||
try
|
||||
{
|
||||
// nested usings are fun!
|
||||
using (RC2CryptoServiceProvider rc2CryptoServiceProvider = new RC2CryptoServiceProvider { KeySize = m_bitSize, Mode = CipherMode.CBC })
|
||||
{
|
||||
using (ICryptoTransform cryptoTransform = rc2CryptoServiceProvider.CreateEncryptor(m_key, m_iv))
|
||||
{
|
||||
using (MemoryStream memoryStream = new MemoryStream())
|
||||
{
|
||||
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoTransform,
|
||||
CryptoStreamMode.Write))
|
||||
{
|
||||
cryptoStream.Write(msg.m_data, 0, msg.m_data.Length);
|
||||
}
|
||||
msg.m_data = memoryStream.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decrypt incoming message
|
||||
/// </summary>
|
||||
public bool Decrypt(NetIncomingMessage msg)
|
||||
{
|
||||
try
|
||||
{
|
||||
// nested usings are fun!
|
||||
using (RC2CryptoServiceProvider rc2CryptoServiceProvider = new RC2CryptoServiceProvider { KeySize = m_bitSize, Mode = CipherMode.CBC })
|
||||
{
|
||||
using (ICryptoTransform cryptoTransform = rc2CryptoServiceProvider.CreateDecryptor(m_key, m_iv))
|
||||
{
|
||||
using (MemoryStream memoryStream = new MemoryStream())
|
||||
{
|
||||
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoTransform,
|
||||
CryptoStreamMode.Write))
|
||||
{
|
||||
cryptoStream.Write(msg.m_data, 0, msg.m_data.Length);
|
||||
}
|
||||
msg.m_data = memoryStream.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,164 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace Lidgren.Network
|
||||
{
|
||||
/// <summary>
|
||||
/// Triple DES encryption
|
||||
/// </summary>
|
||||
public class NetTripleDESEncryption : INetEncryption
|
||||
{
|
||||
private readonly byte[] m_key;
|
||||
private readonly byte[] m_iv;
|
||||
private readonly int m_bitSize;
|
||||
private static readonly List<int> m_keysizes;
|
||||
private static readonly List<int> m_blocksizes;
|
||||
|
||||
static NetTripleDESEncryption()
|
||||
{
|
||||
|
||||
TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider();
|
||||
List<int> temp = new List<int>();
|
||||
foreach (KeySizes keysize in tripleDES.LegalKeySizes)
|
||||
{
|
||||
for (int i = keysize.MinSize; i <= keysize.MaxSize; i += keysize.SkipSize)
|
||||
{
|
||||
if (!temp.Contains(i))
|
||||
temp.Add(i);
|
||||
if (i == keysize.MaxSize)
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_keysizes = temp;
|
||||
temp = new List<int>();
|
||||
foreach (KeySizes keysize in tripleDES.LegalBlockSizes)
|
||||
{
|
||||
for (int i = keysize.MinSize; i <= keysize.MaxSize; i += keysize.SkipSize)
|
||||
{
|
||||
|
||||
if (!temp.Contains(i))
|
||||
temp.Add(i);
|
||||
if (i == keysize.MaxSize)
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_blocksizes = temp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// NetTriplsDESEncryption constructor
|
||||
/// </summary>
|
||||
public NetTripleDESEncryption(byte[] key, byte[] iv)
|
||||
{
|
||||
if (!m_keysizes.Contains(key.Length * 8))
|
||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_keysizes)));
|
||||
|
||||
if (!m_blocksizes.Contains(iv.Length * 8))
|
||||
throw new NetException(string.Format("Not a valid iv size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_blocksizes)));
|
||||
|
||||
m_key = key;
|
||||
m_iv = iv;
|
||||
m_bitSize = m_key.Length * 8;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// NetTriplsDESEncryption constructor
|
||||
/// </summary>
|
||||
public NetTripleDESEncryption(string key, int bitsize)
|
||||
{
|
||||
if (!m_keysizes.Contains(bitsize))
|
||||
throw new NetException(string.Format("Not a valid key size. (Valid values are: {0})", NetUtility.MakeCommaDelimitedList(m_keysizes)));
|
||||
|
||||
byte[] entropy = Encoding.UTF32.GetBytes(key);
|
||||
// I know hardcoding salts is bad, but in this case I think it is acceptable.
|
||||
HMACSHA512 hmacsha512 = new HMACSHA512(Convert.FromBase64String("i88NEiez3c50bHqr3YGasDc4p8jRrxJAaiRiqixpvp4XNAStP5YNoC2fXnWkURtkha6M8yY901Gj07IRVIRyGL=="));
|
||||
hmacsha512.Initialize();
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
entropy = hmacsha512.ComputeHash(entropy);
|
||||
}
|
||||
int keylen = bitsize / 8;
|
||||
m_key = new byte[keylen];
|
||||
Buffer.BlockCopy(entropy, 0, m_key, 0, keylen);
|
||||
m_iv = new byte[m_blocksizes[0] / 8];
|
||||
|
||||
Buffer.BlockCopy(entropy, entropy.Length - m_iv.Length - 1, m_iv, 0, m_iv.Length);
|
||||
m_bitSize = bitsize;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// NetTriplsDESEncryption constructor
|
||||
/// </summary>
|
||||
public NetTripleDESEncryption(string key)
|
||||
: this(key, m_keysizes[0])
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encrypt outgoing message
|
||||
/// </summary>
|
||||
public bool Encrypt(NetOutgoingMessage msg)
|
||||
{
|
||||
try
|
||||
{
|
||||
// nested usings are fun!
|
||||
using (TripleDESCryptoServiceProvider tripleDESCryptoServiceProvider = new TripleDESCryptoServiceProvider { KeySize = m_bitSize, Mode = CipherMode.CBC })
|
||||
{
|
||||
using (ICryptoTransform cryptoTransform = tripleDESCryptoServiceProvider.CreateEncryptor(m_key, m_iv))
|
||||
{
|
||||
using (MemoryStream memoryStream = new MemoryStream())
|
||||
{
|
||||
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoTransform,
|
||||
CryptoStreamMode.Write))
|
||||
{
|
||||
cryptoStream.Write(msg.m_data, 0, msg.m_data.Length);
|
||||
}
|
||||
msg.m_data = memoryStream.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decrypt incoming message
|
||||
/// </summary>
|
||||
public bool Decrypt(NetIncomingMessage msg)
|
||||
{
|
||||
try
|
||||
{
|
||||
// nested usings are fun!
|
||||
using (TripleDESCryptoServiceProvider tripleDESCryptoServiceProvider = new TripleDESCryptoServiceProvider { KeySize = m_bitSize, Mode = CipherMode.CBC })
|
||||
{
|
||||
using (ICryptoTransform cryptoTransform = tripleDESCryptoServiceProvider.CreateDecryptor(m_key, m_iv))
|
||||
{
|
||||
using (MemoryStream memoryStream = new MemoryStream())
|
||||
{
|
||||
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoTransform,
|
||||
CryptoStreamMode.Write))
|
||||
{
|
||||
cryptoStream.Write(msg.m_data, 0, msg.m_data.Length);
|
||||
}
|
||||
msg.m_data = memoryStream.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Lidgren.Network
|
||||
{
|
||||
/// <summary>
|
||||
/// Example class; not very good encryption
|
||||
/// </summary>
|
||||
public class NetXorEncryption : INetEncryption
|
||||
{
|
||||
private byte[] m_key;
|
||||
|
||||
/// <summary>
|
||||
/// NetXorEncryption constructor
|
||||
/// </summary>
|
||||
public NetXorEncryption(byte[] key)
|
||||
{
|
||||
m_key = key;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// NetXorEncryption constructor
|
||||
/// </summary>
|
||||
public NetXorEncryption(string key)
|
||||
{
|
||||
m_key = Encoding.UTF8.GetBytes(key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encrypt an outgoing message
|
||||
/// </summary>
|
||||
public bool Encrypt(NetOutgoingMessage msg)
|
||||
{
|
||||
int numBytes = msg.LengthBytes;
|
||||
for (int i = 0; i < numBytes; i++)
|
||||
{
|
||||
int offset = i % m_key.Length;
|
||||
msg.m_data[i] = (byte)(msg.m_data[i] ^ m_key[offset]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decrypt an incoming message
|
||||
/// </summary>
|
||||
public bool Decrypt(NetIncomingMessage msg)
|
||||
{
|
||||
int numBytes = msg.LengthBytes;
|
||||
for (int i = 0; i < numBytes; i++)
|
||||
{
|
||||
int offset = i % m_key.Length;
|
||||
msg.m_data[i] = (byte)(msg.m_data[i] ^ m_key[offset]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@
|
||||
<DebugSymbols>True</DebugSymbols>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<Optimize>False</Optimize>
|
||||
<OutputPath>..\bin\</OutputPath>
|
||||
<OutputPath>$(SolutionDir)bin\Lidgren\</OutputPath>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
||||
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
|
||||
@@ -62,7 +62,7 @@
|
||||
<DebugSymbols>False</DebugSymbols>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<Optimize>True</Optimize>
|
||||
<OutputPath>..\bin\</OutputPath>
|
||||
<OutputPath>$(SolutionDir)bin\Lidgren\</OutputPath>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
||||
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
|
||||
@@ -107,18 +107,6 @@
|
||||
<Compile Include="Encryption\NetBlockEncryptionBase.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Encryption\NetDESEncryption.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Encryption\NetRC2Encryption.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Encryption\NetTripleDESEncryption.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Encryption\NetXorEncryption.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Encryption\NetXteaEncryption.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.Diagnostics;
|
||||
@@ -70,7 +70,6 @@ namespace Lidgren.Network
|
||||
|
||||
if (i == mag.Length)
|
||||
{
|
||||
// sign = 0;
|
||||
m_magnitude = ZeroMagnitude;
|
||||
}
|
||||
else
|
||||
@@ -241,17 +240,6 @@ namespace Lidgren.Network
|
||||
}
|
||||
}
|
||||
|
||||
// Note: This is the previous (slower) algorithm
|
||||
// while (index < value.Length)
|
||||
// {
|
||||
// char c = value[index];
|
||||
// string s = c.ToString();
|
||||
// int i = Int32.Parse(s, style);
|
||||
//
|
||||
// b = b.Multiply(r).Add(ValueOf(i));
|
||||
// index++;
|
||||
// }
|
||||
|
||||
m_magnitude = b.m_magnitude;
|
||||
}
|
||||
|
||||
@@ -390,7 +378,6 @@ namespace Lidgren.Network
|
||||
|
||||
if (sign == 0)
|
||||
{
|
||||
//sign = 0;
|
||||
m_magnitude = ZeroMagnitude;
|
||||
}
|
||||
else
|
||||
@@ -727,7 +714,6 @@ namespace Lidgren.Network
|
||||
int cBitLength = yBitLength;
|
||||
if (shift > 0)
|
||||
{
|
||||
// iCount = ShiftLeft(One.magnitude, shift);
|
||||
iCount = new int[(shift >> 5) + 1];
|
||||
iCount[0] = 1 << (shift % 32);
|
||||
|
||||
@@ -758,8 +744,7 @@ namespace Lidgren.Network
|
||||
if (++xStart == x.Length)
|
||||
return count;
|
||||
}
|
||||
|
||||
//xBitLength = calcBitLength(xStart, x);
|
||||
|
||||
xBitLength = 32 * (x.Length - xStart - 1) + BitLen(x[xStart]);
|
||||
|
||||
if (xBitLength <= yBitLength)
|
||||
@@ -797,8 +782,7 @@ namespace Lidgren.Network
|
||||
cBitLength -= shift;
|
||||
iCount = ShiftRightInPlace(iCountStart, iCount, shift);
|
||||
}
|
||||
|
||||
//cStart = c.Length - ((cBitLength + 31) / 32);
|
||||
|
||||
while (c[cStart] == 0)
|
||||
{
|
||||
++cStart;
|
||||
@@ -1000,7 +984,6 @@ namespace Lidgren.Network
|
||||
if (x.m_sign < 0)
|
||||
{
|
||||
x.m_sign = 1;
|
||||
//x = m.Subtract(x);
|
||||
x.m_magnitude = doSubBigLil(m.m_magnitude, x.m_magnitude);
|
||||
}
|
||||
|
||||
@@ -1105,7 +1088,6 @@ namespace Lidgren.Network
|
||||
{
|
||||
if (m_magnitude.Length <= m.m_magnitude.Length)
|
||||
{
|
||||
//zAccum = new int[m.magnitude.Length * 2];
|
||||
zVal = new int[m.m_magnitude.Length];
|
||||
m_magnitude.CopyTo(zVal, zVal.Length - m_magnitude.Length);
|
||||
}
|
||||
@@ -1115,8 +1097,7 @@ namespace Lidgren.Network
|
||||
// in normal practice we'll never see ..
|
||||
//
|
||||
NetBigInteger tmp = Remainder(m);
|
||||
|
||||
//zAccum = new int[m.magnitude.Length * 2];
|
||||
|
||||
zVal = new int[m.m_magnitude.Length];
|
||||
tmp.m_magnitude.CopyTo(zVal, zVal.Length - tmp.m_magnitude.Length);
|
||||
}
|
||||
@@ -1225,10 +1206,6 @@ namespace Lidgren.Network
|
||||
int[] w,
|
||||
int[] x)
|
||||
{
|
||||
// Note: this method allows w to be only (2 * x.Length - 1) words if result will fit
|
||||
// if (w.Length != 2 * x.Length)
|
||||
// throw new ArgumentException("no I don't think so...");
|
||||
|
||||
ulong u1, u2, c;
|
||||
|
||||
int wBase = w.Length - 1;
|
||||
@@ -1649,8 +1626,7 @@ namespace Lidgren.Network
|
||||
if (++xStart == x.Length)
|
||||
return x;
|
||||
}
|
||||
|
||||
//xBitLength = calcBitLength(xStart, x);
|
||||
|
||||
xBitLength = 32 * (x.Length - xStart - 1) + BitLen(x[xStart]);
|
||||
|
||||
if (xBitLength <= yBitLength)
|
||||
@@ -1686,8 +1662,7 @@ namespace Lidgren.Network
|
||||
c = ShiftRightInPlace(cStart, c, shift);
|
||||
cBitLength -= shift;
|
||||
}
|
||||
|
||||
//cStart = c.Length - ((cBitLength + 31) / 32);
|
||||
|
||||
while (c[cStart] == 0)
|
||||
{
|
||||
++cStart;
|
||||
@@ -1919,12 +1894,6 @@ namespace Lidgren.Network
|
||||
if (n >= BitLength)
|
||||
return (m_sign < 0 ? One.Negate() : Zero);
|
||||
|
||||
// int[] res = (int[]) magnitude.Clone();
|
||||
//
|
||||
// res = ShiftRightInPlace(0, res, n);
|
||||
//
|
||||
// return new BigInteger(sign, res, true);
|
||||
|
||||
int resultLength = (BitLength - n + 31) >> 5;
|
||||
int[] res = new int[resultLength];
|
||||
|
||||
@@ -1980,8 +1949,7 @@ namespace Lidgren.Network
|
||||
{
|
||||
m = (x[--iT] & IMASK) - (y[--iV] & IMASK) + borrow;
|
||||
x[iT] = (int)m;
|
||||
|
||||
// borrow = (m < 0) ? -1 : 0;
|
||||
|
||||
borrow = (int)(m >> 63);
|
||||
}
|
||||
while (iV > yStart);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//#define UNSAFE
|
||||
//#define UNSAFE
|
||||
//#define BIGENDIAN
|
||||
/* Copyright (c) 2010 Michael Lidgren
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace Lidgren.Network
|
||||
NetException.Assert(((numberOfBits > 0) && (numberOfBits < 9)), "Read() can only read between 1 and 8 bits");
|
||||
|
||||
int bytePtr = readBitOffset >> 3;
|
||||
int startReadAtIndex = readBitOffset - (bytePtr * 8); // (readBitOffset % 8);
|
||||
int startReadAtIndex = readBitOffset - (bytePtr * 8);
|
||||
|
||||
if (startReadAtIndex == 0 && numberOfBits == 8)
|
||||
return fromBuffer[bytePtr];
|
||||
@@ -70,7 +70,7 @@ namespace Lidgren.Network
|
||||
public static void ReadBytes(byte[] fromBuffer, int numberOfBytes, int readBitOffset, byte[] destination, int destinationByteOffset)
|
||||
{
|
||||
int readPtr = readBitOffset >> 3;
|
||||
int startReadAtIndex = readBitOffset - (readPtr * 8); // (readBitOffset % 8);
|
||||
int startReadAtIndex = readBitOffset - (readPtr * 8);
|
||||
|
||||
if (startReadAtIndex == 0)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2010 Michael Lidgren
|
||||
/* Copyright (c) 2010 Michael Lidgren
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
and associated documentation files (the "Software"), to deal in the Software without
|
||||
@@ -181,7 +181,6 @@ namespace Lidgren.Network
|
||||
public UInt32 PeekUInt32(int numberOfBits)
|
||||
{
|
||||
NetException.Assert((numberOfBits > 0 && numberOfBits <= 32), "ReadUInt() can only read between 1 and 32 bits");
|
||||
//NetException.Assert(m_bitLength - m_readBitPtr >= numberOfBits, "tried to read past buffer size");
|
||||
|
||||
UInt32 retval = NetBitWriter.ReadUInt32(m_data, numberOfBits, m_readPosition);
|
||||
return retval;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Reflection;
|
||||
@@ -255,7 +255,6 @@ namespace Lidgren.Network
|
||||
public UInt32 ReadUInt32(int numberOfBits)
|
||||
{
|
||||
NetException.Assert(numberOfBits > 0 && numberOfBits <= 32, "ReadUInt32(bits) can only read between 1 and 32 bits");
|
||||
//NetException.Assert(m_bitLength - m_readBitPtr >= numberOfBits, "tried to read past buffer size");
|
||||
|
||||
UInt32 retval = NetBitWriter.ReadUInt32(m_data, numberOfBits, m_readPosition);
|
||||
m_readPosition += numberOfBits;
|
||||
@@ -470,9 +469,6 @@ namespace Lidgren.Network
|
||||
int num2 = 0;
|
||||
while (true)
|
||||
{
|
||||
//if (num2 == 0x23)
|
||||
// throw new FormatException("Bad 7-bit encoded integer");
|
||||
|
||||
byte num3 = this.ReadByte();
|
||||
num1 |= ((UInt64)num3 & 0x7f) << num2;
|
||||
num2 += 7;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
@@ -94,8 +94,6 @@ namespace Lidgren.Network
|
||||
{
|
||||
m_peer.VerifyNetworkThread();
|
||||
|
||||
//m_peer.LogDebug("Executing disconnect");
|
||||
|
||||
// clear send queues
|
||||
for (int i = 0; i < m_sendChannels.Length; i++)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace Lidgren.Network
|
||||
{
|
||||
@@ -131,8 +131,6 @@ namespace Lidgren.Network
|
||||
rchan.m_resendDelay = resendDelay;
|
||||
}
|
||||
|
||||
// m_peer.LogVerbose("Timeout deadline pushed to " + m_timeoutDeadline);
|
||||
|
||||
// notify the application that average rtt changed
|
||||
if (m_peer.m_configuration.IsMessageTypeEnabled(NetIncomingMessageType.ConnectionLatencyUpdated))
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace Lidgren.Network
|
||||
{
|
||||
@@ -74,13 +74,11 @@ namespace Lidgren.Network
|
||||
{
|
||||
// we've never encountered failure; expand by 25% each time
|
||||
tryMTU = (int)((float)m_currentMTU * 1.25f);
|
||||
//m_peer.LogDebug("Trying MTU " + tryMTU);
|
||||
}
|
||||
else
|
||||
{
|
||||
// we HAVE encountered failure; so try in between
|
||||
tryMTU = (int)(((float)m_smallestFailedMTU + (float)m_largestSuccessfulMTU) / 2.0f);
|
||||
//m_peer.LogDebug("Trying MTU " + m_smallestFailedMTU + " <-> " + m_largestSuccessfulMTU + " = " + tryMTU);
|
||||
}
|
||||
|
||||
if (tryMTU > c_protocolMaxMTU)
|
||||
@@ -88,7 +86,6 @@ namespace Lidgren.Network
|
||||
|
||||
if (tryMTU == m_largestSuccessfulMTU)
|
||||
{
|
||||
//m_peer.LogDebug("Found optimal MTU - exiting");
|
||||
FinalizeMTU(m_largestSuccessfulMTU);
|
||||
return;
|
||||
}
|
||||
@@ -107,8 +104,6 @@ namespace Lidgren.Network
|
||||
bool ok = m_peer.SendMTUPacket(len, m_remoteEndPoint);
|
||||
if (ok == false)
|
||||
{
|
||||
//m_peer.LogDebug("Send MTU failed for size " + size);
|
||||
|
||||
// failure
|
||||
if (m_smallestFailedMTU == -1 || size < m_smallestFailedMTU)
|
||||
{
|
||||
@@ -149,9 +144,7 @@ namespace Lidgren.Network
|
||||
int len = om.Encode(m_peer.m_sendBuffer, 0, 0);
|
||||
bool connectionReset;
|
||||
m_peer.SendPacket(len, m_remoteEndPoint, 1, out connectionReset);
|
||||
|
||||
// m_peer.LogDebug("Received MTU expand request for " + size + " bytes");
|
||||
|
||||
|
||||
m_statistics.PacketSent(len, 1);
|
||||
}
|
||||
|
||||
@@ -162,11 +155,9 @@ namespace Lidgren.Network
|
||||
|
||||
if (size < m_currentMTU)
|
||||
{
|
||||
//m_peer.LogDebug("Received low MTU expand success (size " + size + "); current mtu is " + m_currentMTU);
|
||||
return;
|
||||
}
|
||||
|
||||
//m_peer.LogDebug("Expanding MTU to " + size);
|
||||
m_currentMTU = size;
|
||||
|
||||
ExpandMTU(now, true);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.Diagnostics;
|
||||
@@ -204,8 +204,6 @@ namespace Lidgren.Network
|
||||
NetTuple<NetMessageType, int> tuple;
|
||||
m_queuedOutgoingAcks.TryDequeue(out tuple);
|
||||
|
||||
//m_peer.LogVerbose("Sending ack for " + tuple.Item1 + "#" + tuple.Item2);
|
||||
|
||||
sendBuffer[m_sendBufferWritePtr++] = (byte)tuple.Item1;
|
||||
sendBuffer[m_sendBufferWritePtr++] = (byte)tuple.Item2;
|
||||
sendBuffer[m_sendBufferWritePtr++] = (byte)(tuple.Item2 >> 8);
|
||||
@@ -228,7 +226,6 @@ namespace Lidgren.Network
|
||||
NetTuple<NetMessageType, int> incAck;
|
||||
while (m_queuedIncomingAcks.TryDequeue(out incAck))
|
||||
{
|
||||
//m_peer.LogVerbose("Received ack for " + acktp + "#" + seqNr);
|
||||
NetSenderChannelBase chan = m_sendChannels[(int)incAck.Item1 - 1];
|
||||
if (chan == null)
|
||||
chan = CreateSenderChannel(incAck.Item1);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2010 Michael Lidgren
|
||||
/* Copyright (c) 2010 Michael Lidgren
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
and associated documentation files (the "Software"), to deal in the Software without
|
||||
@@ -91,8 +91,6 @@ namespace Lidgren.Network
|
||||
/// </summary>
|
||||
public int ResentMessages { get { return m_resentMessagesDueToHole + m_resentMessagesDueToDelay; } }
|
||||
|
||||
// public double LastSendRespondedTo { get { return m_connection.m_lastSendRespondedTo; } }
|
||||
|
||||
#if USE_RELEASE_STATISTICS
|
||||
internal void PacketSent(int numBytes, int numMessages)
|
||||
{
|
||||
@@ -156,7 +154,6 @@ namespace Lidgren.Network
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder bdr = new StringBuilder();
|
||||
//bdr.AppendLine("Average roundtrip time: " + NetTime.ToReadable(m_connection.m_averageRoundtripTime));
|
||||
bdr.AppendLine("Sent " + m_sentBytes + " bytes in " + m_sentMessages + " messages in " + m_sentPackets + " packets");
|
||||
bdr.AppendLine("Received " + m_receivedBytes + " bytes in " + m_receivedMessages + " messages in " + m_receivedPackets + " packets");
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -131,7 +131,6 @@ namespace Lidgren.Network
|
||||
Buffer.BlockCopy(im.m_data, ptr, info.Data, offset, im.LengthBytes - ptr);
|
||||
|
||||
int cnt = info.ReceivedChunks.Count();
|
||||
//LogVerbose("Found fragment #" + chunkNumber + " in group " + group + " offset " + offset + " of total bits " + totalBits + " (total chunks done " + cnt + ")");
|
||||
|
||||
LogVerbose("Received fragment " + chunkNumber + " of " + totalNumChunks + " (" + cnt + " chunks received)");
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#if !__ANDROID__ && !IOS
|
||||
#if !__ANDROID__ && !IOS
|
||||
#define IS_MAC_AVAILABLE
|
||||
#endif
|
||||
|
||||
@@ -370,9 +370,6 @@ namespace Lidgren.Network
|
||||
if (!m_socket.Poll(1000, SelectMode.SelectRead)) // wait up to 1 ms for data to arrive
|
||||
return;
|
||||
|
||||
//if (m_socket == null || m_socket.Available < 1)
|
||||
// return;
|
||||
|
||||
do
|
||||
{
|
||||
int bytesReceived = 0;
|
||||
@@ -398,8 +395,6 @@ namespace Lidgren.Network
|
||||
if (bytesReceived < NetConstants.HeaderByteSize)
|
||||
return;
|
||||
|
||||
//LogVerbose("Received " + bytesReceived + " bytes");
|
||||
|
||||
IPEndPoint ipsender = (IPEndPoint)m_senderRemote;
|
||||
|
||||
if (ipsender.Port == 1900)
|
||||
@@ -648,7 +643,6 @@ namespace Lidgren.Network
|
||||
|
||||
internal void AcceptConnection(NetConnection conn)
|
||||
{
|
||||
// LogDebug("Accepted connection " + conn);
|
||||
conn.InitExpandMTU(NetTime.Now);
|
||||
|
||||
if (m_handshakes.Remove(conn.m_remoteEndPoint) == false)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2010 Michael Lidgren
|
||||
/* Copyright (c) 2010 Michael Lidgren
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
and associated documentation files (the "Software"), to deal in the Software without
|
||||
@@ -63,7 +63,6 @@ namespace Lidgren.Network
|
||||
if (m == 0.0f && r == 0.0f)
|
||||
{
|
||||
// no latency simulation
|
||||
// LogVerbose("Sending packet " + numBytes + " bytes");
|
||||
bool wasSent = ActuallySendPacket(m_sendBuffer, numBytes, target, out connectionReset);
|
||||
// TODO: handle wasSent == false?
|
||||
return;
|
||||
@@ -87,8 +86,6 @@ namespace Lidgren.Network
|
||||
|
||||
m_delayedPackets.Add(p);
|
||||
}
|
||||
|
||||
// LogVerbose("Sending packet " + numBytes + " bytes - delayed " + NetTime.ToReadable(delay));
|
||||
}
|
||||
|
||||
private void SendDelayedPackets()
|
||||
@@ -142,8 +139,6 @@ namespace Lidgren.Network
|
||||
int bytesSent = m_socket.SendTo(data, 0, numBytes, SocketFlags.None, target);
|
||||
if (numBytes != bytesSent)
|
||||
LogWarning("Failed to send the full " + numBytes + "; only " + bytesSent + " bytes sent in packet!");
|
||||
|
||||
// LogDebug("Sent " + numBytes + " bytes");
|
||||
}
|
||||
catch (SocketException sx)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace Lidgren.Network
|
||||
{
|
||||
@@ -80,8 +80,6 @@ namespace Lidgren.Network
|
||||
// mix some semi-random properties
|
||||
int seed = (int)Environment.TickCount;
|
||||
seed ^= forObject.GetHashCode();
|
||||
//seed ^= (int)(Stopwatch.GetTimestamp());
|
||||
//seed ^= (int)(Environment.WorkingSet); // will return 0 on mono
|
||||
|
||||
int extraSeed = System.Threading.Interlocked.Increment(ref s_extraSeed);
|
||||
|
||||
@@ -265,44 +263,6 @@ namespace Lidgren.Network
|
||||
this.x = x; this.y = y; this.z = z; this.w = w;
|
||||
}
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// A version of NextBytes that uses a pointer to set 4 bytes of the byte buffer in one operation
|
||||
// /// thus providing a nice speedup. The loop is also partially unrolled to allow out-of-order-execution,
|
||||
// /// this results in about a x2 speedup on an AMD Athlon. Thus performance may vary wildly on different CPUs
|
||||
// /// depending on the number of execution units available.
|
||||
// ///
|
||||
// /// Another significant speedup is obtained by setting the 4 bytes by indexing pDWord (e.g. pDWord[i++]=w)
|
||||
// /// instead of adjusting it dereferencing it (e.g. *pDWord++=w).
|
||||
// ///
|
||||
// /// Note that this routine requires the unsafe compilation flag to be specified and so is commented out by default.
|
||||
// /// </summary>
|
||||
// /// <param name="buffer"></param>
|
||||
// public unsafe void NextBytesUnsafe(byte[] buffer)
|
||||
// {
|
||||
// if(buffer.Length % 8 != 0)
|
||||
// throw new ArgumentException("Buffer length must be divisible by 8", "buffer");
|
||||
//
|
||||
// uint x=this.x, y=this.y, z=this.z, w=this.w;
|
||||
//
|
||||
// fixed(byte* pByte0 = buffer)
|
||||
// {
|
||||
// uint* pDWord = (uint*)pByte0;
|
||||
// for(int i=0, len=buffer.Length>>2; i < len; i+=2)
|
||||
// {
|
||||
// uint t=(x^(x<<11));
|
||||
// x=y; y=z; z=w;
|
||||
// pDWord[i] = w = (w^(w>>19))^(t^(t>>8));
|
||||
//
|
||||
// t=(x^(x<<11));
|
||||
// x=y; y=z; z=w;
|
||||
// pDWord[i+1] = w = (w^(w>>19))^(t^(t>>8));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// this.x=x; this.y=y; this.z=z; this.w=w;
|
||||
// }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods [Methods not present on System.Random]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace Lidgren.Network
|
||||
{
|
||||
@@ -32,13 +32,6 @@ namespace Lidgren.Network
|
||||
|
||||
if (relate == 0)
|
||||
{
|
||||
// Log("Received message #" + message.SequenceNumber + " right on time");
|
||||
|
||||
//
|
||||
// excellent, right on time
|
||||
//
|
||||
//m_peer.LogVerbose("Received RIGHT-ON-TIME " + message);
|
||||
|
||||
AdvanceWindow();
|
||||
m_peer.ReleaseMessage(message);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace Lidgren.Network
|
||||
@@ -85,8 +85,7 @@ namespace Lidgren.Network
|
||||
startSlot = m_windowSize - 1;
|
||||
seqNr--;
|
||||
}
|
||||
|
||||
//m_connection.m_peer.LogVerbose("Resending due to delay #" + seqNr + " " + om.ToString());
|
||||
|
||||
m_connection.m_statistics.MessageResent(MessageResendReason.Delay);
|
||||
|
||||
m_connection.QueueSendMessage(om, seqNr);
|
||||
@@ -156,15 +155,10 @@ namespace Lidgren.Network
|
||||
int relate = NetUtility.RelativeSequenceNumber(seqNr, m_windowStart);
|
||||
|
||||
if (relate < 0)
|
||||
{
|
||||
//m_connection.m_peer.LogDebug("Received late/dupe ack for #" + seqNr);
|
||||
return; // late/duplicate ack
|
||||
}
|
||||
|
||||
if (relate == 0)
|
||||
{
|
||||
//m_connection.m_peer.LogDebug("Received right-on-time ack for #" + seqNr);
|
||||
|
||||
// ack arrived right on time
|
||||
NetException.Assert(seqNr == m_windowStart);
|
||||
|
||||
@@ -175,13 +169,11 @@ namespace Lidgren.Network
|
||||
// advance window if we already have early acks
|
||||
while (m_receivedAcks.Get(m_windowStart))
|
||||
{
|
||||
//m_connection.m_peer.LogDebug("Using early ack for #" + m_windowStart + "...");
|
||||
m_receivedAcks[m_windowStart] = false;
|
||||
DestoreMessage(m_windowStart % m_windowSize);
|
||||
|
||||
NetException.Assert(m_storedMessages[m_windowStart % m_windowSize].Message == null); // should already be destored
|
||||
m_windowStart = (m_windowStart + 1) % NetConstants.NumSequenceNumbers;
|
||||
//m_connection.m_peer.LogDebug("Advancing window to #" + m_windowStart);
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -194,8 +186,6 @@ namespace Lidgren.Network
|
||||
// ... or the ack for that message was lost
|
||||
//
|
||||
|
||||
//m_connection.m_peer.LogDebug("Received early ack for #" + seqNr);
|
||||
|
||||
int sendRelate = NetUtility.RelativeSequenceNumber(seqNr, m_sendStart);
|
||||
if (sendRelate <= 0)
|
||||
{
|
||||
@@ -223,12 +213,8 @@ namespace Lidgren.Network
|
||||
rnr--;
|
||||
if (rnr < 0)
|
||||
rnr = NetConstants.NumSequenceNumbers - 1;
|
||||
|
||||
if (m_receivedAcks[rnr])
|
||||
{
|
||||
// m_connection.m_peer.LogDebug("Not resending #" + rnr + " (since we got ack)");
|
||||
}
|
||||
else
|
||||
|
||||
if (!m_receivedAcks[rnr])
|
||||
{
|
||||
int slot = rnr % m_windowSize;
|
||||
NetException.Assert(m_storedMessages[slot].Message != null);
|
||||
@@ -236,7 +222,6 @@ namespace Lidgren.Network
|
||||
{
|
||||
// just sent once; resend immediately since we found gap in ack sequence
|
||||
NetOutgoingMessage rmsg = m_storedMessages[slot].Message;
|
||||
//m_connection.m_peer.LogVerbose("Resending #" + rnr + " (" + rmsg + ")");
|
||||
|
||||
if (now - m_storedMessages[slot].LastSent < (m_resendDelay * 0.35f))
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace Lidgren.Network
|
||||
{
|
||||
@@ -29,12 +29,6 @@ namespace Lidgren.Network
|
||||
|
||||
if (relate == 0)
|
||||
{
|
||||
// Log("Received message #" + message.SequenceNumber + " right on time");
|
||||
|
||||
//
|
||||
// excellent, right on time
|
||||
//
|
||||
|
||||
AdvanceWindow();
|
||||
m_peer.ReleaseMessage(message);
|
||||
return;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace Lidgren.Network
|
||||
{
|
||||
@@ -30,13 +30,6 @@ namespace Lidgren.Network
|
||||
|
||||
if (relate == 0)
|
||||
{
|
||||
// Log("Received message #" + message.SequenceNumber + " right on time");
|
||||
|
||||
//
|
||||
// excellent, right on time
|
||||
//
|
||||
//m_peer.LogVerbose("Received RIGHT-ON-TIME " + message);
|
||||
|
||||
AdvanceWindow();
|
||||
m_peer.ReleaseMessage(message);
|
||||
|
||||
@@ -45,16 +38,6 @@ namespace Lidgren.Network
|
||||
|
||||
while (m_earlyReceived[nextSeqNr % m_windowSize])
|
||||
{
|
||||
//message = m_withheldMessages[nextSeqNr % m_windowSize];
|
||||
//NetException.Assert(message != null);
|
||||
|
||||
// remove it from withheld messages
|
||||
//m_withheldMessages[nextSeqNr % m_windowSize] = null;
|
||||
|
||||
//m_peer.LogVerbose("Releasing withheld message #" + message);
|
||||
|
||||
//m_peer.ReleaseMessage(message);
|
||||
|
||||
AdvanceWindow();
|
||||
nextSeqNr++;
|
||||
}
|
||||
@@ -78,8 +61,6 @@ namespace Lidgren.Network
|
||||
}
|
||||
|
||||
m_earlyReceived.Set(message.m_sequenceNumber % m_windowSize, true);
|
||||
//m_peer.LogVerbose("Received " + message + " WITHHOLDING, waiting for " + m_windowStart);
|
||||
//m_withheldMessages[message.m_sequenceNumber % m_windowSize] = message;
|
||||
|
||||
m_peer.ReleaseMessage(message);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#define USE_SHA256
|
||||
#define USE_SHA256
|
||||
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
@@ -75,8 +75,7 @@ namespace Lidgren.Network
|
||||
byte[] total = new byte[innerHash.Length + salt.Length];
|
||||
Buffer.BlockCopy(salt, 0, total, 0, salt.Length);
|
||||
Buffer.BlockCopy(innerHash, 0, total, salt.Length, innerHash.Length);
|
||||
|
||||
// x ie. H(salt || H(username || ":" || password))
|
||||
|
||||
return new NetBigInteger(NetUtility.ToHexString(sha.ComputeHash(total)), 16).ToByteArrayUnsigned();
|
||||
}
|
||||
|
||||
@@ -139,7 +138,7 @@ namespace Lidgren.Network
|
||||
string one = NetUtility.ToHexString(clientPublicEphemeral);
|
||||
string two = NetUtility.ToHexString(serverPublicEphemeral);
|
||||
|
||||
int len = 66; // Math.Max(one.Length, two.Length);
|
||||
int len = 66;
|
||||
string ccstr = one.PadLeft(len, '0') + two.PadLeft(len, '0');
|
||||
|
||||
byte[] cc = NetUtility.ToByteArray(ccstr);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Net;
|
||||
@@ -40,9 +40,6 @@ namespace Lidgren.Network
|
||||
peer.Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true);
|
||||
peer.RawSend(arr, 0, arr.Length, new IPEndPoint(IPAddress.Broadcast, 1900));
|
||||
peer.Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, false);
|
||||
|
||||
// allow some extra time for router to respond
|
||||
// System.Threading.Thread.Sleep(50);
|
||||
}
|
||||
|
||||
internal void ExtractServiceUrl(string resp)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace Lidgren.Network
|
||||
@@ -94,15 +94,10 @@ namespace Lidgren.Network
|
||||
int relate = NetUtility.RelativeSequenceNumber(seqNr, m_windowStart);
|
||||
|
||||
if (relate < 0)
|
||||
{
|
||||
//m_connection.m_peer.LogDebug("Received late/dupe ack for #" + seqNr);
|
||||
return; // late/duplicate ack
|
||||
}
|
||||
|
||||
if (relate == 0)
|
||||
{
|
||||
//m_connection.m_peer.LogDebug("Received right-on-time ack for #" + seqNr);
|
||||
|
||||
// ack arrived right on time
|
||||
NetException.Assert(seqNr == m_windowStart);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2010 Michael Lidgren
|
||||
/* Copyright (c) 2010 Michael Lidgren
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
and associated documentation files (the "Software"), to deal in the Software without
|
||||
@@ -107,7 +107,6 @@ namespace Lidgren.Network
|
||||
{
|
||||
if (ex.SocketErrorCode == SocketError.HostNotFound)
|
||||
{
|
||||
//LogWrite(string.Format(CultureInfo.InvariantCulture, "Failed to resolve host '{0}'.", ipOrHost));
|
||||
callback(null);
|
||||
return;
|
||||
}
|
||||
@@ -140,7 +139,6 @@ namespace Lidgren.Network
|
||||
{
|
||||
if (ex.SocketErrorCode == SocketError.HostNotFound)
|
||||
{
|
||||
//LogWrite(string.Format(CultureInfo.InvariantCulture, "Failed to resolve host '{0}'.", ipOrHost));
|
||||
callback(null);
|
||||
}
|
||||
else
|
||||
@@ -189,7 +187,6 @@ namespace Lidgren.Network
|
||||
{
|
||||
if (ex.SocketErrorCode == SocketError.HostNotFound)
|
||||
{
|
||||
//LogWrite(string.Format(CultureInfo.InvariantCulture, "Failed to resolve host '{0}'.", ipOrHost));
|
||||
return null;
|
||||
}
|
||||
else
|
||||
@@ -266,7 +263,7 @@ namespace Lidgren.Network
|
||||
}
|
||||
return new string(c);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the local broadcast address
|
||||
/// </summary>
|
||||
@@ -278,7 +275,7 @@ namespace Lidgren.Network
|
||||
if (wifi.IsWifiEnabled)
|
||||
{
|
||||
var dhcp = wifi.DhcpInfo;
|
||||
|
||||
|
||||
int broadcast = (dhcp.IpAddress & dhcp.Netmask) | ~dhcp.Netmask;
|
||||
byte[] quads = new byte[4];
|
||||
for (int k = 0; k < 4; k++)
|
||||
@@ -292,7 +289,7 @@ namespace Lidgren.Network
|
||||
{
|
||||
return IPAddress.Broadcast;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#if IS_FULL_NET_AVAILABLE
|
||||
try
|
||||
{
|
||||
@@ -301,7 +298,7 @@ namespace Lidgren.Network
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
IPInterfaceProperties properties = ni.GetIPProperties();
|
||||
foreach (UnicastIPAddressInformation unicastAddress in properties.UnicastAddresses)
|
||||
{
|
||||
@@ -310,24 +307,24 @@ namespace Lidgren.Network
|
||||
var mask = unicastAddress.IPv4Mask;
|
||||
byte[] ipAdressBytes = unicastAddress.Address.GetAddressBytes();
|
||||
byte[] subnetMaskBytes = mask.GetAddressBytes();
|
||||
|
||||
|
||||
if (ipAdressBytes.Length != subnetMaskBytes.Length)
|
||||
throw new ArgumentException("Lengths of IP address and subnet mask do not match.");
|
||||
|
||||
|
||||
byte[] broadcastAddress = new byte[ipAdressBytes.Length];
|
||||
for (int i = 0; i < broadcastAddress.Length; i++)
|
||||
{
|
||||
broadcastAddress[i] = (byte)(ipAdressBytes[i] | (subnetMaskBytes[i] ^ 255));
|
||||
}
|
||||
return new IPAddress(broadcastAddress);
|
||||
return new IPAddress(broadcastAddress);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch // Catch any errors
|
||||
catch // Catch any errors
|
||||
{
|
||||
return IPAddress.Broadcast;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
return IPAddress.Broadcast;
|
||||
}
|
||||
|
||||
@@ -343,21 +340,21 @@ namespace Lidgren.Network
|
||||
Android.Net.Wifi.WifiManager wifi = (Android.Net.Wifi.WifiManager)Android.App.Application.Context.GetSystemService(Android.App.Activity.WifiService);
|
||||
if (!wifi.IsWifiEnabled) return null;
|
||||
var dhcp = wifi.DhcpInfo;
|
||||
|
||||
|
||||
int addr = dhcp.IpAddress;
|
||||
byte[] quads = new byte[4];
|
||||
for (int k = 0; k < 4; k++)
|
||||
{
|
||||
quads[k] = (byte) ((addr >> k * 8) & 0xFF);
|
||||
}
|
||||
}
|
||||
return new IPAddress(quads);
|
||||
}
|
||||
catch // Catch Access Denied errors
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#if IS_FULL_NET_AVAILABLE
|
||||
NetworkInterface ni = GetNetworkInterface();
|
||||
if (ni == null)
|
||||
@@ -486,12 +483,6 @@ namespace Lidgren.Network
|
||||
internal static int RelativeSequenceNumber(int nr, int expected)
|
||||
{
|
||||
return (nr - expected + NetConstants.NumSequenceNumbers + (NetConstants.NumSequenceNumbers / 2)) % NetConstants.NumSequenceNumbers - (NetConstants.NumSequenceNumbers / 2);
|
||||
|
||||
// old impl:
|
||||
//int retval = ((nr + NetConstants.NumSequenceNumbers) - expected) % NetConstants.NumSequenceNumbers;
|
||||
//if (retval > (NetConstants.NumSequenceNumbers / 2))
|
||||
// retval -= NetConstants.NumSequenceNumbers;
|
||||
//return retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -586,4 +577,4 @@ namespace Lidgren.Network
|
||||
return bdr.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
9
MSBuild/SS14.Engine.targets
Normal file
9
MSBuild/SS14.Engine.targets
Normal file
@@ -0,0 +1,9 @@
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0">
|
||||
<Target Name="CopyResourcesFromShared">
|
||||
<ItemGroup>
|
||||
<_ResourceFiles Include="$(SolutionDir)bin\Shared\Resources\**\*.*" />
|
||||
</ItemGroup>
|
||||
<RemoveDir Directories="$(OutputPath)Resources" />
|
||||
<Copy SourceFiles="@(_ResourceFiles)" DestinationFolder="$(OutputPath)Resources\%(RecursiveDir)" />
|
||||
</Target>
|
||||
</Project>
|
||||
29
MSBuild/SS14.Properties.targets
Normal file
29
MSBuild/SS14.Properties.targets
Normal file
@@ -0,0 +1,29 @@
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0">
|
||||
<!-- MSBuild hurts and I can't find a foolproof way to detect platform. -->
|
||||
<PropertyGroup>
|
||||
<OS Condition="'$(OS)' == ''">Windows_NT</OS>
|
||||
</PropertyGroup>
|
||||
<Choose>
|
||||
<When Condition="'$(OS)' != 'Unix'">
|
||||
<PropertyGroup>
|
||||
<ActualOS>Windows</ActualOS>
|
||||
</PropertyGroup>
|
||||
</When>
|
||||
<!-- Folders that *probably* only exist on MacOS and not Linux. -->
|
||||
<When Condition="Exists('/Volumes') And Exists('/System') And Exists('/Library')" >
|
||||
<PropertyGroup>
|
||||
<ActualOS>MacOS</ActualOS>
|
||||
</PropertyGroup>
|
||||
</When>
|
||||
<Otherwise>
|
||||
<PropertyGroup>
|
||||
<ActualOS>Linux</ActualOS>
|
||||
</PropertyGroup>
|
||||
</Otherwise>
|
||||
</Choose>
|
||||
<PropertyGroup>
|
||||
<TargetOS Condition="'$(TargetOS)' == ''">$(ActualOS)</TargetOS>
|
||||
<Python>python3</Python>
|
||||
<Python Condition="'$(ActualOS)' == 'Windows'">py -3</Python>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -1,21 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<DirectedGraph GraphDirection="LeftToRight" Layout="Sugiyama" xmlns="http://schemas.microsoft.com/vs/2009/dgml">
|
||||
<Nodes>
|
||||
<Node Id="Client" Category="Project" Label="Client" />
|
||||
</Nodes>
|
||||
<Links />
|
||||
<Categories>
|
||||
<Category Id="Project" />
|
||||
</Categories>
|
||||
<Properties>
|
||||
<Property Id="GraphDirection" DataType="Microsoft.VisualStudio.Progression.Layout.GraphDirection" />
|
||||
<Property Id="Label" Label="Label" Description="Displayable label of an Annotatable object" DataType="System.String" />
|
||||
<Property Id="Layout" DataType="System.String" />
|
||||
</Properties>
|
||||
<Styles>
|
||||
<Style TargetType="Node" GroupLabel="Project" ValueLabel="True">
|
||||
<Condition Expression="HasCategory('Project')" />
|
||||
<Setter Property="Background" Value="Blue" />
|
||||
</Style>
|
||||
</Styles>
|
||||
</DirectedGraph>
|
||||
18
RUN_THIS.py
Executable file
18
RUN_THIS.py
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Import future so people on py2 still get the clear error that they need to upgrade.
|
||||
from __future__ import print_function
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
IS_WINDOWS = sys.platform in ("win32", "cygwin")
|
||||
|
||||
version = sys.version_info
|
||||
if version.major < 3 or (version.major == 3 and version.minor < 5):
|
||||
print("ERROR: You need at least Python 3.5 to build SS14.")
|
||||
sys.exit(1)
|
||||
|
||||
if IS_WINDOWS:
|
||||
subprocess.run(["py", "-3", "git_helper.py"], cwd="BuildChecker", check=True)
|
||||
else:
|
||||
subprocess.run(["python3", "git_helper.py"], cwd="BuildChecker", check=True)
|
||||
@@ -3,8 +3,6 @@
|
||||
name: Janitor Jumpsuit
|
||||
components:
|
||||
- type: Transform
|
||||
- type: Velocity
|
||||
- type: Direction
|
||||
- type: Clickable
|
||||
- type: WearableAnimatedSprite
|
||||
sprite: player_jumpsuit_gray
|
||||
@@ -13,7 +11,7 @@
|
||||
- type: Icon
|
||||
icon: janitorsuit
|
||||
|
||||
- type: BasicMover
|
||||
- type: BoundingBox
|
||||
- type: Physics
|
||||
mass: 5
|
||||
|
||||
@@ -22,8 +20,6 @@
|
||||
name: Shoes
|
||||
components:
|
||||
- type: Transform
|
||||
- type: Velocity
|
||||
- type: Direction
|
||||
- type: Clickable
|
||||
- type: WearableAnimatedSprite
|
||||
sprite: player_toolbox
|
||||
@@ -32,6 +28,6 @@
|
||||
- type: Icon
|
||||
icon: shoes
|
||||
|
||||
- type: BasicMover
|
||||
- type: BoundingBox
|
||||
- type: Physics
|
||||
mass: 5
|
||||
@@ -3,9 +3,7 @@
|
||||
name: Toolbox
|
||||
components:
|
||||
- type: Transform
|
||||
- type: Velocity
|
||||
- type: Clickable
|
||||
- type: Direction
|
||||
- type: WearableAnimatedSprite
|
||||
sprite: player_toolbox
|
||||
notWornSprite: toolbox_r
|
||||
@@ -13,6 +11,6 @@
|
||||
- type: Icon
|
||||
icon: toolbox_r
|
||||
|
||||
- type: BasicMover
|
||||
- type: BoundingBox
|
||||
- type: Physics
|
||||
mass: 5
|
||||
@@ -3,8 +3,6 @@
|
||||
name: Door
|
||||
components:
|
||||
- type: Transform
|
||||
- type: Velocity
|
||||
- type: Direction
|
||||
- type: Clickable
|
||||
- type: Sprite
|
||||
drawdepth: FloorPlaceable
|
||||
@@ -15,5 +13,5 @@
|
||||
- type: Icon
|
||||
icon: door_ew
|
||||
|
||||
- type: BasicMover
|
||||
- type: BoundingBox
|
||||
- type: Collidable
|
||||
@@ -3,8 +3,6 @@
|
||||
name: Mop
|
||||
components:
|
||||
- type: Transform
|
||||
- type: Velocity
|
||||
- type: Direction
|
||||
- type: Clickable
|
||||
- type: WearableAnimatedSprite
|
||||
sprite: player_toolbox
|
||||
@@ -13,5 +11,6 @@
|
||||
- type: Icon
|
||||
icon: mop
|
||||
|
||||
- type: BoundingBox
|
||||
- type: Physics
|
||||
- type: Clickable
|
||||
16
Resources/Prototypes/Entities/Lights.yml
Normal file
16
Resources/Prototypes/Entities/Lights.yml
Normal file
@@ -0,0 +1,16 @@
|
||||
- type: entity
|
||||
id: WallLight
|
||||
name: Wall Light
|
||||
components:
|
||||
- type: Transform
|
||||
- type: Clickable
|
||||
- type: Sprite
|
||||
sprites:
|
||||
- wall_light
|
||||
|
||||
- type: Icon
|
||||
icon: wall_light
|
||||
|
||||
- type: PointLight
|
||||
radius: 1024
|
||||
color: "#DCDCC6"
|
||||
@@ -1,10 +1,8 @@
|
||||
- type: entity
|
||||
- type: entity
|
||||
id: HumanMob
|
||||
name: Urist McHuman
|
||||
components:
|
||||
- type: Transform
|
||||
- type: Velocity
|
||||
- type: Direction
|
||||
- type: Clickable
|
||||
- type: AnimatedSprite
|
||||
sprite: player
|
||||
@@ -12,12 +10,15 @@
|
||||
- type: Icon
|
||||
icon: player
|
||||
|
||||
- type: BasicMover
|
||||
|
||||
- type: BoundingBox
|
||||
sizeX: 0.9
|
||||
sizeY: 0.9
|
||||
offsetY: 0.6
|
||||
|
||||
- type: ParticleSystem
|
||||
- type: Physics
|
||||
mass: 5
|
||||
|
||||
- type: Hitbox
|
||||
sizeX: 25
|
||||
sizeY: 25
|
||||
- type: Collidable
|
||||
DebugColor: "#0000FF"
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
- type: entity
|
||||
- type: entity
|
||||
id: Worktop
|
||||
name: Worktop
|
||||
components:
|
||||
- type: Transform
|
||||
- type: Velocity
|
||||
- type: Direction
|
||||
- type: Clickable
|
||||
- type: Sprite
|
||||
sprites:
|
||||
@@ -14,11 +12,10 @@
|
||||
- type: Icon
|
||||
icon: worktop_single
|
||||
|
||||
- type: BasicMover
|
||||
- type: Hitbox
|
||||
sizeX: 64
|
||||
sizeY: 47
|
||||
offsetY: 8
|
||||
- type: BoundingBox
|
||||
sizeX: 2
|
||||
sizeY: 1.4
|
||||
offsetY: 0.25
|
||||
|
||||
- type: Collidable
|
||||
DebugColor: "#0000FF"
|
||||
@@ -3,15 +3,11 @@
|
||||
name: Extinguisher Cabinet
|
||||
components:
|
||||
- type: Transform
|
||||
- type: Velocity
|
||||
- type: Direction
|
||||
- type: Clickable
|
||||
- type: Sprite
|
||||
sprites:
|
||||
- fire_extinguisher
|
||||
|
||||
- type: BasicMover
|
||||
|
||||
placement:
|
||||
mode: AlignWall
|
||||
range: 200
|
||||
@@ -25,14 +21,11 @@
|
||||
name: Fire Alarm
|
||||
components:
|
||||
- type: Transform
|
||||
- type: Velocity
|
||||
- type: Direction
|
||||
- type: Clickable
|
||||
- type: Sprite
|
||||
sprites:
|
||||
- fire_alarm_off
|
||||
|
||||
- type: BasicMover
|
||||
- type: Icon
|
||||
icon: fire_alarm_off
|
||||
|
||||
@@ -49,14 +42,11 @@
|
||||
name: Medical Cabinet
|
||||
components:
|
||||
- type: Transform
|
||||
- type: Velocity
|
||||
- type: Direction
|
||||
- type: Clickable
|
||||
- type: Sprite
|
||||
sprites:
|
||||
- med_cabinet
|
||||
|
||||
- type: BasicMover
|
||||
- type: Icon
|
||||
icon: med_cabinet
|
||||
|
||||
17
Resources/Prototypes/Entities/Walls.yml
Normal file
17
Resources/Prototypes/Entities/Walls.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
- type: entity
|
||||
id: Wall
|
||||
name: Wall
|
||||
components:
|
||||
- type: Transform
|
||||
- type: Clickable
|
||||
- type: Sprite
|
||||
drawdepth: FloorPlaceable
|
||||
sprites:
|
||||
- wall_texture
|
||||
|
||||
- type: Icon
|
||||
icon: wall_texture
|
||||
|
||||
- type: BoundingBox
|
||||
|
||||
- type: Collidable
|
||||
@@ -3,75 +3,23 @@
|
||||
#define KERNEL_SIZE (RADIUS * 2 + 1)
|
||||
|
||||
uniform vec2 weights_offsets[KERNEL_SIZE];
|
||||
uniform vec2 weights_offsets0;
|
||||
uniform vec2 weights_offsets1;
|
||||
uniform vec2 weights_offsets2;
|
||||
uniform vec2 weights_offsets3;
|
||||
uniform vec2 weights_offsets4;
|
||||
uniform vec2 weights_offsets5;
|
||||
uniform vec2 weights_offsets6;
|
||||
uniform vec2 weights_offsets7;
|
||||
uniform vec2 weights_offsets8;
|
||||
uniform vec2 weights_offsets9;
|
||||
uniform vec2 weights_offsets10;
|
||||
uniform vec2 weights_offsets11;
|
||||
uniform vec2 weights_offsets12;
|
||||
uniform vec2 weights_offsets13;
|
||||
uniform vec2 weights_offsets14;
|
||||
uniform vec2 weights_offsets15;
|
||||
uniform vec2 weights_offsets16;
|
||||
uniform vec2 weights_offsets17;
|
||||
uniform vec2 weights_offsets18;
|
||||
uniform vec2 weights_offsets19;
|
||||
uniform vec2 weights_offsets20;
|
||||
uniform vec2 weights_offsets21;
|
||||
uniform vec2 weights_offsets22;
|
||||
|
||||
|
||||
uniform sampler2D colorMapTexture;
|
||||
|
||||
vec4 GaussianBlurHorizontal()
|
||||
{
|
||||
vec4 color = vec4(0,0,0,0);
|
||||
|
||||
vec2 weights_offsets[KERNEL_SIZE] = vec2[KERNEL_SIZE]
|
||||
(
|
||||
weights_offsets0,
|
||||
weights_offsets1,
|
||||
weights_offsets2,
|
||||
weights_offsets3,
|
||||
weights_offsets4,
|
||||
weights_offsets5,
|
||||
weights_offsets6,
|
||||
weights_offsets7,
|
||||
weights_offsets8,
|
||||
weights_offsets9,
|
||||
weights_offsets10,
|
||||
weights_offsets11,
|
||||
weights_offsets12,
|
||||
weights_offsets13,
|
||||
weights_offsets14,
|
||||
weights_offsets15,
|
||||
weights_offsets16,
|
||||
weights_offsets17,
|
||||
weights_offsets18,
|
||||
weights_offsets19,
|
||||
weights_offsets20,
|
||||
weights_offsets21,
|
||||
weights_offsets22
|
||||
);
|
||||
|
||||
|
||||
vec4 color = vec4(0,0,0,0);
|
||||
|
||||
for (int i = 0; i < KERNEL_SIZE; ++i)
|
||||
{
|
||||
color += texture2D(colorMapTexture, vec2(gl_TexCoord[0].x + weights_offsets[i].y, gl_TexCoord[0].y))* weights_offsets[i].x;
|
||||
{
|
||||
color += texture2D(colorMapTexture, vec2(gl_TexCoord[0].x + weights_offsets[i].y, gl_TexCoord[0].y))* weights_offsets[i].x;
|
||||
}
|
||||
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = GaussianBlurHorizontal();
|
||||
gl_FragColor = GaussianBlurHorizontal();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,73 +1,23 @@
|
||||
#version 120
|
||||
#define RADIUS 11
|
||||
#define KERNEL_SIZE (RADIUS * 2 + 1)
|
||||
|
||||
|
||||
uniform vec2 weights_offsets[KERNEL_SIZE];
|
||||
uniform vec2 weights_offsets0;
|
||||
uniform vec2 weights_offsets1;
|
||||
uniform vec2 weights_offsets2;
|
||||
uniform vec2 weights_offsets3;
|
||||
uniform vec2 weights_offsets4;
|
||||
uniform vec2 weights_offsets5;
|
||||
uniform vec2 weights_offsets6;
|
||||
uniform vec2 weights_offsets7;
|
||||
uniform vec2 weights_offsets8;
|
||||
uniform vec2 weights_offsets9;
|
||||
uniform vec2 weights_offsets10;
|
||||
uniform vec2 weights_offsets11;
|
||||
uniform vec2 weights_offsets12;
|
||||
uniform vec2 weights_offsets13;
|
||||
uniform vec2 weights_offsets14;
|
||||
uniform vec2 weights_offsets15;
|
||||
uniform vec2 weights_offsets16;
|
||||
uniform vec2 weights_offsets17;
|
||||
uniform vec2 weights_offsets18;
|
||||
uniform vec2 weights_offsets19;
|
||||
uniform vec2 weights_offsets20;
|
||||
uniform vec2 weights_offsets21;
|
||||
uniform vec2 weights_offsets22;
|
||||
|
||||
uniform sampler2D colorMapTexture;
|
||||
|
||||
vec4 GaussianBlurVertical()
|
||||
{
|
||||
vec2 weights_offsets[KERNEL_SIZE] = vec2[KERNEL_SIZE]
|
||||
(
|
||||
weights_offsets0,
|
||||
weights_offsets1,
|
||||
weights_offsets2,
|
||||
weights_offsets3,
|
||||
weights_offsets4,
|
||||
weights_offsets5,
|
||||
weights_offsets6,
|
||||
weights_offsets7,
|
||||
weights_offsets8,
|
||||
weights_offsets9,
|
||||
weights_offsets10,
|
||||
weights_offsets11,
|
||||
weights_offsets12,
|
||||
weights_offsets13,
|
||||
weights_offsets14,
|
||||
weights_offsets15,
|
||||
weights_offsets16,
|
||||
weights_offsets17,
|
||||
weights_offsets18,
|
||||
weights_offsets19,
|
||||
weights_offsets20,
|
||||
weights_offsets21,
|
||||
weights_offsets22
|
||||
);
|
||||
|
||||
vec4 color = vec4(0,0,0,0);
|
||||
|
||||
|
||||
for (int i = 0; i < KERNEL_SIZE; ++i)
|
||||
{
|
||||
color += texture2D(colorMapTexture, vec2(gl_TexCoord[0].x, gl_TexCoord[0].y + weights_offsets[i].y)) * weights_offsets[i].x; // M A G I K
|
||||
}
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = GaussianBlurVertical();
|
||||
gl_FragColor = GaussianBlurVertical();
|
||||
}
|
||||
|
||||
@@ -3,38 +3,20 @@
|
||||
#define KERNEL_SIZE (RADIUS * 2 + 1)
|
||||
|
||||
uniform vec2 weights_offsets[KERNEL_SIZE];
|
||||
uniform vec2 weights_offsets0;
|
||||
uniform vec2 weights_offsets1;
|
||||
uniform vec2 weights_offsets2;
|
||||
uniform vec2 weights_offsets3;
|
||||
uniform vec2 weights_offsets4;
|
||||
uniform vec2 weights_offsets5;
|
||||
uniform vec2 weights_offsets6;
|
||||
|
||||
uniform sampler2D colorMapTexture;
|
||||
|
||||
vec4 GaussianBlurHorizontal()
|
||||
{
|
||||
vec4 color = vec4(0,0,0,0);
|
||||
|
||||
vec2 weights_offsets[KERNEL_SIZE] = vec2[KERNEL_SIZE]
|
||||
(
|
||||
weights_offsets0,
|
||||
weights_offsets1,
|
||||
weights_offsets2,
|
||||
weights_offsets3,
|
||||
weights_offsets4,
|
||||
weights_offsets5,
|
||||
weights_offsets6
|
||||
);
|
||||
|
||||
vec4 color = vec4(0,0,0,0);
|
||||
|
||||
for (int i = 0; i < KERNEL_SIZE; ++i)
|
||||
color += texture2D(colorMapTexture, vec2(gl_TexCoord[0].x + weights_offsets[i].y, gl_TexCoord[0].y)) * weights_offsets[i].x;
|
||||
|
||||
|
||||
return color;
|
||||
}
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = GaussianBlurHorizontal();
|
||||
{
|
||||
gl_FragColor = GaussianBlurHorizontal();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,40 +1,22 @@
|
||||
#version 120
|
||||
#define RADIUS 3
|
||||
#define KERNEL_SIZE (RADIUS * 2 + 1)
|
||||
|
||||
|
||||
uniform vec2 weights_offsets[KERNEL_SIZE];
|
||||
uniform vec2 weights_offsets0;
|
||||
uniform vec2 weights_offsets1;
|
||||
uniform vec2 weights_offsets2;
|
||||
uniform vec2 weights_offsets3;
|
||||
uniform vec2 weights_offsets4;
|
||||
uniform vec2 weights_offsets5;
|
||||
uniform vec2 weights_offsets6;
|
||||
|
||||
uniform sampler2D colorMapTexture;
|
||||
|
||||
vec4 GaussianBlurVertical()
|
||||
{
|
||||
vec4 color = vec4(0,0,0,0);
|
||||
|
||||
vec2 weights_offsets[KERNEL_SIZE] = vec2[KERNEL_SIZE]
|
||||
(
|
||||
weights_offsets0,
|
||||
weights_offsets1,
|
||||
weights_offsets2,
|
||||
weights_offsets3,
|
||||
weights_offsets4,
|
||||
weights_offsets5,
|
||||
weights_offsets6
|
||||
);
|
||||
|
||||
|
||||
for (int i = 0; i < KERNEL_SIZE; ++i)
|
||||
color += texture2D(colorMapTexture, vec2(gl_TexCoord[0].x, gl_TexCoord[0].y + weights_offsets[i].y)) * weights_offsets[i].x;
|
||||
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = GaussianBlurVertical();
|
||||
{
|
||||
gl_FragColor = GaussianBlurVertical();
|
||||
}
|
||||
|
||||
@@ -3,47 +3,21 @@
|
||||
#define KERNEL_SIZE (RADIUS * 2 + 1)
|
||||
|
||||
uniform vec2 weights_offsets[KERNEL_SIZE];
|
||||
uniform vec2 weights_offsets0;
|
||||
uniform vec2 weights_offsets1;
|
||||
uniform vec2 weights_offsets2;
|
||||
uniform vec2 weights_offsets3;
|
||||
uniform vec2 weights_offsets4;
|
||||
uniform vec2 weights_offsets5;
|
||||
uniform vec2 weights_offsets6;
|
||||
uniform vec2 weights_offsets7;
|
||||
uniform vec2 weights_offsets8;
|
||||
uniform vec2 weights_offsets9;
|
||||
uniform vec2 weights_offsets10;
|
||||
|
||||
uniform sampler2D colorMapTexture;
|
||||
|
||||
vec4 GaussianBlurHorizontal()
|
||||
{
|
||||
vec4 color = vec4(0,0,0,0);
|
||||
|
||||
vec2 weights_offsets[KERNEL_SIZE] = vec2[KERNEL_SIZE]
|
||||
(
|
||||
weights_offsets0,
|
||||
weights_offsets1,
|
||||
weights_offsets2,
|
||||
weights_offsets3,
|
||||
weights_offsets4,
|
||||
weights_offsets5,
|
||||
weights_offsets6,
|
||||
weights_offsets7,
|
||||
weights_offsets8,
|
||||
weights_offsets9,
|
||||
weights_offsets10
|
||||
);
|
||||
|
||||
vec4 color = vec4(0,0,0,0);
|
||||
|
||||
for (int i = 0; i < KERNEL_SIZE; ++i)
|
||||
color += texture2D(colorMapTexture, vec2(gl_TexCoord[0].x + weights_offsets[i].y, gl_TexCoord[0].y)) * weights_offsets[i].x;
|
||||
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = GaussianBlurHorizontal();
|
||||
gl_FragColor = GaussianBlurHorizontal();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,50 +1,24 @@
|
||||
#version 120
|
||||
#define RADIUS 5
|
||||
#define KERNEL_SIZE (RADIUS * 2 + 1)
|
||||
|
||||
|
||||
uniform vec2 weights_offsets[KERNEL_SIZE];
|
||||
uniform vec2 weights_offsets0;
|
||||
uniform vec2 weights_offsets1;
|
||||
uniform vec2 weights_offsets2;
|
||||
uniform vec2 weights_offsets3;
|
||||
uniform vec2 weights_offsets4;
|
||||
uniform vec2 weights_offsets5;
|
||||
uniform vec2 weights_offsets6;
|
||||
uniform vec2 weights_offsets7;
|
||||
uniform vec2 weights_offsets8;
|
||||
uniform vec2 weights_offsets9;
|
||||
uniform vec2 weights_offsets10;
|
||||
|
||||
uniform sampler2D colorMapTexture;
|
||||
|
||||
vec4 GaussianBlurVertical()
|
||||
{
|
||||
vec4 color = vec4(0,0,0,0);
|
||||
|
||||
vec2 weights_offsets[KERNEL_SIZE] = vec2[KERNEL_SIZE]
|
||||
(
|
||||
weights_offsets0,
|
||||
weights_offsets1,
|
||||
weights_offsets2,
|
||||
weights_offsets3,
|
||||
weights_offsets4,
|
||||
weights_offsets5,
|
||||
weights_offsets6,
|
||||
weights_offsets7,
|
||||
weights_offsets8,
|
||||
weights_offsets9,
|
||||
weights_offsets10
|
||||
);
|
||||
|
||||
|
||||
for (int i = 0; i < KERNEL_SIZE; ++i)
|
||||
color += texture2D(colorMapTexture, vec2(gl_TexCoord[0].x, gl_TexCoord[0].y + weights_offsets[i].y)) * weights_offsets[i].x;
|
||||
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = GaussianBlurVertical();
|
||||
{
|
||||
gl_FragColor = GaussianBlurVertical();
|
||||
}
|
||||
|
||||
@@ -3,54 +3,21 @@
|
||||
#define KERNEL_SIZE (RADIUS * 2 + 1)
|
||||
|
||||
uniform vec2 weights_offsets[KERNEL_SIZE];
|
||||
uniform vec2 weights_offsets0;
|
||||
uniform vec2 weights_offsets1;
|
||||
uniform vec2 weights_offsets2;
|
||||
uniform vec2 weights_offsets3;
|
||||
uniform vec2 weights_offsets4;
|
||||
uniform vec2 weights_offsets5;
|
||||
uniform vec2 weights_offsets6;
|
||||
uniform vec2 weights_offsets7;
|
||||
uniform vec2 weights_offsets8;
|
||||
uniform vec2 weights_offsets9;
|
||||
uniform vec2 weights_offsets10;
|
||||
uniform vec2 weights_offsets11;
|
||||
uniform vec2 weights_offsets12;
|
||||
uniform vec2 weights_offsets13;
|
||||
uniform vec2 weights_offsets14;
|
||||
|
||||
uniform sampler2D colorMapTexture;
|
||||
|
||||
vec4 GaussianBlurHorizontal()
|
||||
{
|
||||
vec4 color = vec4(0,0,0,0);
|
||||
|
||||
vec2 weights_offsets[KERNEL_SIZE] = vec2[KERNEL_SIZE]
|
||||
(
|
||||
weights_offsets0,
|
||||
weights_offsets1,
|
||||
weights_offsets2,
|
||||
weights_offsets3,
|
||||
weights_offsets4,
|
||||
weights_offsets5,
|
||||
weights_offsets6,
|
||||
weights_offsets7,
|
||||
weights_offsets8,
|
||||
weights_offsets9,
|
||||
weights_offsets10,
|
||||
weights_offsets11,
|
||||
weights_offsets12,
|
||||
weights_offsets13,
|
||||
weights_offsets14
|
||||
);
|
||||
|
||||
vec4 color = vec4(0,0,0,0);
|
||||
|
||||
for (int i = 0; i < KERNEL_SIZE; ++i)
|
||||
color += texture2D(colorMapTexture, vec2(gl_TexCoord[0].x + weights_offsets[i].y, gl_TexCoord[0].y)) * weights_offsets[i].x;
|
||||
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
{
|
||||
gl_FragColor = GaussianBlurHorizontal();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,57 +1,22 @@
|
||||
#version 120
|
||||
#define RADIUS 7
|
||||
#define KERNEL_SIZE (RADIUS * 2 + 1)
|
||||
|
||||
uniform vec2 weights_offsets[KERNEL_SIZE];
|
||||
uniform vec2 weights_offsets0;
|
||||
uniform vec2 weights_offsets1;
|
||||
uniform vec2 weights_offsets2;
|
||||
uniform vec2 weights_offsets3;
|
||||
uniform vec2 weights_offsets4;
|
||||
uniform vec2 weights_offsets5;
|
||||
uniform vec2 weights_offsets6;
|
||||
uniform vec2 weights_offsets7;
|
||||
uniform vec2 weights_offsets8;
|
||||
uniform vec2 weights_offsets9;
|
||||
uniform vec2 weights_offsets10;
|
||||
uniform vec2 weights_offsets11;
|
||||
uniform vec2 weights_offsets12;
|
||||
uniform vec2 weights_offsets13;
|
||||
uniform vec2 weights_offsets14;
|
||||
|
||||
uniform vec2 weights_offsets[KERNEL_SIZE];
|
||||
|
||||
uniform sampler2D colorMapTexture;
|
||||
|
||||
vec4 GaussianBlurVertical()
|
||||
{
|
||||
vec4 color = vec4(0,0,0,0);
|
||||
|
||||
vec2 weights_offsets[KERNEL_SIZE] = vec2[KERNEL_SIZE]
|
||||
(
|
||||
weights_offsets0,
|
||||
weights_offsets1,
|
||||
weights_offsets2,
|
||||
weights_offsets3,
|
||||
weights_offsets4,
|
||||
weights_offsets5,
|
||||
weights_offsets6,
|
||||
weights_offsets7,
|
||||
weights_offsets8,
|
||||
weights_offsets9,
|
||||
weights_offsets10,
|
||||
weights_offsets11,
|
||||
weights_offsets12,
|
||||
weights_offsets13,
|
||||
weights_offsets14
|
||||
);
|
||||
|
||||
|
||||
for (int i = 0; i < KERNEL_SIZE; ++i)
|
||||
color += texture2D(colorMapTexture, vec2(gl_TexCoord[0].x, gl_TexCoord[0].y + weights_offsets[i].y)) * weights_offsets[i].x;
|
||||
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = GaussianBlurVertical();
|
||||
gl_FragColor = GaussianBlurVertical();
|
||||
}
|
||||
|
||||
@@ -3,63 +3,21 @@
|
||||
#define KERNEL_SIZE (RADIUS * 2 + 1)
|
||||
|
||||
uniform vec2 weights_offsets[KERNEL_SIZE];
|
||||
uniform vec2 weights_offsets0;
|
||||
uniform vec2 weights_offsets1;
|
||||
uniform vec2 weights_offsets2;
|
||||
uniform vec2 weights_offsets3;
|
||||
uniform vec2 weights_offsets4;
|
||||
uniform vec2 weights_offsets5;
|
||||
uniform vec2 weights_offsets6;
|
||||
uniform vec2 weights_offsets7;
|
||||
uniform vec2 weights_offsets8;
|
||||
uniform vec2 weights_offsets9;
|
||||
uniform vec2 weights_offsets10;
|
||||
uniform vec2 weights_offsets11;
|
||||
uniform vec2 weights_offsets12;
|
||||
uniform vec2 weights_offsets13;
|
||||
uniform vec2 weights_offsets14;
|
||||
uniform vec2 weights_offsets15;
|
||||
uniform vec2 weights_offsets16;
|
||||
uniform vec2 weights_offsets17;
|
||||
uniform vec2 weights_offsets18;
|
||||
|
||||
uniform sampler2D colorMapTexture;
|
||||
|
||||
vec4 GaussianBlurHorizontal()
|
||||
{
|
||||
vec4 color = vec4(0,0,0,0);
|
||||
|
||||
vec2 weights_offsets[KERNEL_SIZE] = vec2[KERNEL_SIZE]
|
||||
(
|
||||
weights_offsets0,
|
||||
weights_offsets1,
|
||||
weights_offsets2,
|
||||
weights_offsets3,
|
||||
weights_offsets4,
|
||||
weights_offsets5,
|
||||
weights_offsets6,
|
||||
weights_offsets7,
|
||||
weights_offsets8,
|
||||
weights_offsets9,
|
||||
weights_offsets10,
|
||||
weights_offsets11,
|
||||
weights_offsets12,
|
||||
weights_offsets13,
|
||||
weights_offsets14,
|
||||
weights_offsets15,
|
||||
weights_offsets16,
|
||||
weights_offsets17,
|
||||
weights_offsets18
|
||||
);
|
||||
|
||||
for (int i = 0; i < KERNEL_SIZE; ++i)
|
||||
vec4 color = vec4(0,0,0,0);
|
||||
|
||||
for (int i = 0; i < KERNEL_SIZE; ++i)
|
||||
color += texture2D(colorMapTexture, vec2(gl_TexCoord[0].x + weights_offsets[i].y, gl_TexCoord[0].y)) * weights_offsets[i].x;
|
||||
|
||||
return color;
|
||||
}
|
||||
void main()
|
||||
{
|
||||
|
||||
gl_FragColor = GaussianBlurHorizontal();
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = GaussianBlurHorizontal();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,66 +1,22 @@
|
||||
#version 120
|
||||
#define RADIUS 9
|
||||
#define KERNEL_SIZE (RADIUS * 2 + 1)
|
||||
|
||||
|
||||
uniform vec2 weights_offsets[KERNEL_SIZE];
|
||||
uniform vec2 weights_offsets0;
|
||||
uniform vec2 weights_offsets1;
|
||||
uniform vec2 weights_offsets2;
|
||||
uniform vec2 weights_offsets3;
|
||||
uniform vec2 weights_offsets4;
|
||||
uniform vec2 weights_offsets5;
|
||||
uniform vec2 weights_offsets6;
|
||||
uniform vec2 weights_offsets7;
|
||||
uniform vec2 weights_offsets8;
|
||||
uniform vec2 weights_offsets9;
|
||||
uniform vec2 weights_offsets10;
|
||||
uniform vec2 weights_offsets11;
|
||||
uniform vec2 weights_offsets12;
|
||||
uniform vec2 weights_offsets13;
|
||||
uniform vec2 weights_offsets14;
|
||||
uniform vec2 weights_offsets15;
|
||||
uniform vec2 weights_offsets16;
|
||||
uniform vec2 weights_offsets17;
|
||||
uniform vec2 weights_offsets18;
|
||||
|
||||
uniform sampler2D colorMapTexture;
|
||||
|
||||
vec4 GaussianBlurVertical()
|
||||
{
|
||||
vec4 color = vec4(0,0,0,0);
|
||||
|
||||
vec2 weights_offsets[KERNEL_SIZE] = vec2[KERNEL_SIZE]
|
||||
(
|
||||
weights_offsets0,
|
||||
weights_offsets1,
|
||||
weights_offsets2,
|
||||
weights_offsets3,
|
||||
weights_offsets4,
|
||||
weights_offsets5,
|
||||
weights_offsets6,
|
||||
weights_offsets7,
|
||||
weights_offsets8,
|
||||
weights_offsets9,
|
||||
weights_offsets10,
|
||||
weights_offsets11,
|
||||
weights_offsets12,
|
||||
weights_offsets13,
|
||||
weights_offsets14,
|
||||
weights_offsets15,
|
||||
weights_offsets16,
|
||||
weights_offsets17,
|
||||
weights_offsets18
|
||||
);
|
||||
|
||||
|
||||
for (int i = 0; i < KERNEL_SIZE; ++i)
|
||||
color += texture2D(colorMapTexture, vec2(gl_TexCoord[0].x, gl_TexCoord[0].y + weights_offsets[i].y)) * weights_offsets[i].x;
|
||||
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = GaussianBlurVertical();
|
||||
gl_FragColor = GaussianBlurVertical();
|
||||
}
|
||||
|
||||
@@ -1,20 +1,8 @@
|
||||
#version 120
|
||||
#define NUM_LIGHTS 6
|
||||
uniform vec4 LightPosData0;
|
||||
uniform vec4 LightPosData1;
|
||||
uniform vec4 LightPosData2;
|
||||
uniform vec4 LightPosData3;
|
||||
uniform vec4 LightPosData4;
|
||||
uniform vec4 LightPosData5;
|
||||
uniform vec4 LightPosData[NUM_LIGHTS];
|
||||
|
||||
uniform vec4 LightPosData[NUM_LIGHTS];
|
||||
uniform vec4 Colors[NUM_LIGHTS];
|
||||
uniform vec4 Colors0;
|
||||
uniform vec4 Colors1;
|
||||
uniform vec4 Colors2;
|
||||
uniform vec4 Colors3;
|
||||
uniform vec4 Colors4;
|
||||
uniform vec4 Colors5;
|
||||
|
||||
uniform sampler2D light0;
|
||||
uniform sampler2D light1;
|
||||
@@ -25,61 +13,41 @@ uniform sampler2D light5;
|
||||
|
||||
uniform sampler2D sceneTexture;
|
||||
|
||||
vec4 PreLightBlendPS()
|
||||
vec4 PreLightBlendPS()
|
||||
{
|
||||
vec4 Colors[NUM_LIGHTS] = vec4[NUM_LIGHTS]
|
||||
(
|
||||
Colors0,
|
||||
Colors1,
|
||||
Colors2,
|
||||
Colors3,
|
||||
Colors4,
|
||||
Colors5
|
||||
);
|
||||
|
||||
vec4 LightPosData[NUM_LIGHTS] = vec4[NUM_LIGHTS]
|
||||
(
|
||||
LightPosData0,
|
||||
LightPosData1,
|
||||
LightPosData2,
|
||||
LightPosData3,
|
||||
LightPosData4,
|
||||
LightPosData5
|
||||
);
|
||||
vec4 l[NUM_LIGHTS];
|
||||
vec2 ltc[NUM_LIGHTS];
|
||||
for(int i = 0;i<NUM_LIGHTS;i++)
|
||||
{
|
||||
ltc[i] = vec2((gl_TexCoord[0].x - LightPosData[i].x) * LightPosData[i].z, (gl_TexCoord[0].y - LightPosData[i].y) * LightPosData[i].w);
|
||||
}
|
||||
l[0] = texture2D(light0, ltc[0]);
|
||||
l[1] = texture2D(light1, ltc[1]);
|
||||
l[2] = texture2D(light2, ltc[2]);
|
||||
l[3] = texture2D(light3, ltc[3]);
|
||||
l[4] = texture2D(light4, ltc[4]);
|
||||
l[5] = texture2D(light5, ltc[5]);
|
||||
|
||||
vec4 l[NUM_LIGHTS];
|
||||
vec2 ltc[NUM_LIGHTS];
|
||||
for(int i = 0;i<NUM_LIGHTS;i++)
|
||||
{
|
||||
ltc[i] = vec2((gl_TexCoord[0].x - LightPosData[i].x) * LightPosData[i].z, (gl_TexCoord[0].y - LightPosData[i].y) * LightPosData[i].w);
|
||||
}
|
||||
l[0] = texture2D(light0, ltc[0]);
|
||||
l[1] = texture2D(light1, ltc[1]);
|
||||
l[2] = texture2D(light2, ltc[2]);
|
||||
l[3] = texture2D(light3, ltc[3]);
|
||||
l[4] = texture2D(light4, ltc[4]);
|
||||
l[5] = texture2D(light5, ltc[5]);
|
||||
|
||||
l[0].rgb = l[0].rgb * Colors[0].rgb;
|
||||
l[1].rgb = l[1].rgb * Colors[1].rgb;
|
||||
l[2].rgb = l[2].rgb * Colors[2].rgb;
|
||||
l[3].rgb = l[3].rgb * Colors[3].rgb;
|
||||
l[4].rgb = l[4].rgb * Colors[4].rgb;
|
||||
l[5].rgb = l[5].rgb * Colors[5].rgb;
|
||||
|
||||
vec4 s = texture2D(sceneTexture, gl_TexCoord[0].xy); // sample existing lights
|
||||
|
||||
//Add the lights together
|
||||
float r = sqrt(pow(l[0].r, 2) + pow(l[1].r, 2) + pow(l[2].r, 2) + pow(l[3].r, 2) + pow(l[4].r, 2) + pow(l[5].r, 2) + pow(s.r, 2));
|
||||
float g = sqrt(pow(l[0].g, 2) + pow(l[1].g, 2) + pow(l[2].g, 2) + pow(l[3].g, 2) + pow(l[4].g, 2) + pow(l[5].g, 2) + pow(s.g, 2));
|
||||
float b = sqrt(pow(l[0].b, 2) + pow(l[1].b, 2) + pow(l[2].b, 2) + pow(l[3].b, 2) + pow(l[4].b, 2) + pow(l[5].b, 2) + pow(s.b, 2));
|
||||
vec4 c = vec4(r,g,b, 1);
|
||||
return c;
|
||||
//Return the light color
|
||||
return vec4(c.rgb,min(1, 1/max(c.r, max(c.g,c.b))));
|
||||
l[0].rgb = l[0].rgb * Colors[0].rgb;
|
||||
l[1].rgb = l[1].rgb * Colors[1].rgb;
|
||||
l[2].rgb = l[2].rgb * Colors[2].rgb;
|
||||
l[3].rgb = l[3].rgb * Colors[3].rgb;
|
||||
l[4].rgb = l[4].rgb * Colors[4].rgb;
|
||||
l[5].rgb = l[5].rgb * Colors[5].rgb;
|
||||
|
||||
vec4 s = texture2D(sceneTexture, gl_TexCoord[0].xy); // sample existing lights
|
||||
|
||||
//Add the lights together
|
||||
float r = sqrt(pow(l[0].r, 2) + pow(l[1].r, 2) + pow(l[2].r, 2) + pow(l[3].r, 2) + pow(l[4].r, 2) + pow(l[5].r, 2) + pow(s.r, 2));
|
||||
float g = sqrt(pow(l[0].g, 2) + pow(l[1].g, 2) + pow(l[2].g, 2) + pow(l[3].g, 2) + pow(l[4].g, 2) + pow(l[5].g, 2) + pow(s.g, 2));
|
||||
float b = sqrt(pow(l[0].b, 2) + pow(l[1].b, 2) + pow(l[2].b, 2) + pow(l[3].b, 2) + pow(l[4].b, 2) + pow(l[5].b, 2) + pow(s.b, 2));
|
||||
vec4 c = vec4(r,g,b, 1);
|
||||
return c;
|
||||
//Return the light color
|
||||
return vec4(c.rgb,min(1, 1/max(c.r, max(c.g,c.b))));
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = PreLightBlendPS();
|
||||
}
|
||||
gl_FragColor = PreLightBlendPS();
|
||||
}
|
||||
|
||||
1
SFML
Submodule
1
SFML
Submodule
Submodule SFML added at 0f22866353
@@ -1,17 +1,18 @@
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using SFML.Graphics;
|
||||
using SFML.System;
|
||||
using SFML.Window;
|
||||
using SS14.Client.Graphics.Event;
|
||||
using SS14.Client.Graphics.Render;
|
||||
using SS14.Client.Graphics.Settings;
|
||||
using SS14.Client.Graphics.Shader;
|
||||
using SS14.Client.Graphics.Utility;
|
||||
using SS14.Client.Graphics.View;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using SS14.Shared.Network;
|
||||
using SS14.Shared.Maths;
|
||||
using SS14.Shared.Timing;
|
||||
|
||||
using System;
|
||||
using Vector2i = SS14.Shared.Maths.Vector2i;
|
||||
using Vector2u = SS14.Shared.Maths.Vector2u;
|
||||
|
||||
namespace SS14.Client.Graphics
|
||||
{
|
||||
@@ -20,28 +21,33 @@ namespace SS14.Client.Graphics
|
||||
private static RenderTarget[] renderTargetArray;
|
||||
|
||||
public static GameTiming Time { get; private set; }
|
||||
public static event FrameEventHandler FrameEvent;
|
||||
public static event EventHandler<FrameEventArgs> FrameEvent;
|
||||
public static Viewport CurrentClippingViewport;
|
||||
|
||||
public delegate void EventHandler();
|
||||
public static event EventHandler RefreshVideoSettings;
|
||||
|
||||
#region Accessors
|
||||
public static Vector2f WorldCenter { get; set; }
|
||||
public static Vector2 WorldCenter { get; set; }
|
||||
public static Vector2u ScreenViewportSize { get; set; }
|
||||
public static int TileSize { get; set; }
|
||||
public static FloatRect WorldViewport
|
||||
|
||||
/// <summary>
|
||||
/// Viewport scaling
|
||||
/// </summary>
|
||||
public static int TileSize { get; set; } = 32;
|
||||
|
||||
public static Box2 WorldViewport
|
||||
{
|
||||
get
|
||||
{
|
||||
return ScreenToWorld(ScreenViewport);
|
||||
}
|
||||
}
|
||||
public static IntRect ScreenViewport
|
||||
public static Box2i ScreenViewport
|
||||
{
|
||||
get
|
||||
{
|
||||
return new IntRect(0, 0, (int)ScreenViewportSize.X, (int)ScreenViewportSize.Y);
|
||||
return Box2i.FromDimensions(0, 0, (int)ScreenViewportSize.X, (int)ScreenViewportSize.Y);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +80,7 @@ namespace SS14.Client.Graphics
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion Accessors
|
||||
|
||||
static CluwneLib()
|
||||
{
|
||||
@@ -89,12 +95,11 @@ namespace SS14.Client.Graphics
|
||||
/// Shamelessly taken from Gorgon.
|
||||
public static void Go()
|
||||
{
|
||||
|
||||
if (!IsInitialized)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
|
||||
if ((Screen != null) && (renderTargetArray == null))
|
||||
throw new InvalidOperationException("Something has gone terribly wrong!");
|
||||
|
||||
@@ -110,7 +115,6 @@ namespace SS14.Client.Graphics
|
||||
renderTargetArray[0] = Screen;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
IsRunning = true;
|
||||
@@ -132,11 +136,6 @@ namespace SS14.Client.Graphics
|
||||
SplashScreen = null;
|
||||
}
|
||||
|
||||
public static void drawRectangle(int x, int y, int width, int height, object p)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
if (IsInitialized)
|
||||
@@ -147,13 +146,14 @@ namespace SS14.Client.Graphics
|
||||
Screen = new CluwneWindow(CluwneLib.Video.getVideoMode(), "Developer Station 14", CluwneLib.Video.getWindowStyle());
|
||||
Screen.SetVerticalSyncEnabled(true);
|
||||
Screen.SetFramerateLimit(300);
|
||||
|
||||
|
||||
renderTargetArray = new RenderTarget[5];
|
||||
CurrentClippingViewport = new Viewport(0, 0, Screen.Size.X, Screen.Size.Y);
|
||||
IsInitialized = true;
|
||||
|
||||
//Hook OpenTK into SFMLs Opengl
|
||||
OpenTK.Toolkit.Init(new OpenTK.ToolkitOptions{
|
||||
OpenTK.Toolkit.Init(new OpenTK.ToolkitOptions
|
||||
{
|
||||
// Non-Native backend doesn't have a default GetAddress method
|
||||
Backend = OpenTK.PlatformBackend.PreferNative
|
||||
});
|
||||
@@ -162,12 +162,12 @@ namespace SS14.Client.Graphics
|
||||
|
||||
public static void RequestGC(Action action)
|
||||
{
|
||||
action.Invoke();
|
||||
action.Invoke();
|
||||
}
|
||||
|
||||
public static void ClearCurrentRendertarget(Color color)
|
||||
public static void ClearCurrentRendertarget(Color4 color)
|
||||
{
|
||||
CurrentRenderTarget.Clear(color);
|
||||
CurrentRenderTarget.Clear(color.Convert());
|
||||
}
|
||||
|
||||
public static void Terminate()
|
||||
@@ -179,30 +179,27 @@ namespace SS14.Client.Graphics
|
||||
|
||||
public static void RunIdle(object sender, FrameEventArgs e)
|
||||
{
|
||||
FrameEvent(sender, e);
|
||||
FrameEvent?.Invoke(sender, e);
|
||||
}
|
||||
|
||||
public static void Stop()
|
||||
{
|
||||
Console.WriteLine("CluwneLib: Stop() requested");
|
||||
IsRunning=false;
|
||||
IsRunning = false;
|
||||
}
|
||||
|
||||
|
||||
public static void UpdateVideoSettings()
|
||||
{
|
||||
RefreshVideoSettings();
|
||||
RefreshVideoSettings();
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion CluwneEngine
|
||||
|
||||
#region RenderTarget Stuff
|
||||
|
||||
|
||||
|
||||
public static void setAdditionalRenderTarget(int index, RenderTarget _target)
|
||||
{
|
||||
renderTargetArray[index] = _target;
|
||||
renderTargetArray[index] = _target;
|
||||
}
|
||||
|
||||
public static RenderTarget getAdditionalRenderTarget(int index)
|
||||
@@ -210,7 +207,6 @@ namespace SS14.Client.Graphics
|
||||
return renderTargetArray[index];
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// resets the Current Render Target back to the screen
|
||||
/// </summary>
|
||||
@@ -227,9 +223,7 @@ namespace SS14.Client.Graphics
|
||||
CurrentShader = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
#endregion RenderTarget Stuff
|
||||
|
||||
#region Drawing Methods
|
||||
|
||||
@@ -243,12 +237,12 @@ namespace SS14.Client.Graphics
|
||||
/// <param name="WidthX"> Width X of rectangle </param>
|
||||
/// <param name="HeightY"> Height Y of rectangle </param>
|
||||
/// <param name="Color"> Fill Color </param>
|
||||
public static void drawRectangle(int posX, int posY, int WidthX, int HeightY, Color Color)
|
||||
public static void drawRectangle(int posX, int posY, int WidthX, int HeightY, Color4 Color)
|
||||
{
|
||||
RectangleShape rectangle = new RectangleShape();
|
||||
rectangle.Position = new SFML.System.Vector2f(posX, posY);
|
||||
rectangle.Size = new SFML.System.Vector2f(WidthX, HeightY);
|
||||
rectangle.FillColor = Color;
|
||||
rectangle.FillColor = Color.Convert();
|
||||
|
||||
CurrentRenderTarget.Draw(rectangle);
|
||||
}
|
||||
@@ -261,17 +255,16 @@ namespace SS14.Client.Graphics
|
||||
/// <param name="WidthX"> Width X of rectangle </param>
|
||||
/// <param name="HeightY"> Height Y of rectangle </param>
|
||||
/// <param name="Color"> Fill Color </param>
|
||||
public static void drawRectangle(float posX, float posY, float WidthX, float HeightY, Color Color)
|
||||
public static void drawRectangle(float posX, float posY, float WidthX, float HeightY, Color4 Color)
|
||||
{
|
||||
RectangleShape rectangle = new RectangleShape();
|
||||
rectangle.Position = new SFML.System.Vector2f(posX, posY);
|
||||
rectangle.Size = new SFML.System.Vector2f(WidthX, HeightY);
|
||||
rectangle.FillColor = Color;
|
||||
rectangle.FillColor = Color.Convert();
|
||||
|
||||
CurrentRenderTarget.Draw(rectangle);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Draws a Hollow Rectangle to the Current RenderTarget
|
||||
/// </summary>
|
||||
@@ -281,18 +274,18 @@ namespace SS14.Client.Graphics
|
||||
/// <param name="heightY"> Height Y of rectangle </param>
|
||||
/// <param name="OutlineThickness"> Outline Thickness of rectangle </param>
|
||||
/// <param name="OutlineColor"> Outline Color </param>
|
||||
public static void drawHollowRectangle(int posX, int posY, int widthX, int heightY, float OutlineThickness, Color OutlineColor)
|
||||
public static void drawHollowRectangle(int posX, int posY, int widthX, int heightY, float OutlineThickness, Color4 OutlineColor)
|
||||
{
|
||||
RectangleShape HollowRect = new RectangleShape();
|
||||
HollowRect.FillColor = Color.Transparent;
|
||||
HollowRect.Position = new SFML.System.Vector2f(posX, posY);
|
||||
HollowRect.Size = new SFML.System.Vector2f(widthX, heightY);
|
||||
HollowRect.OutlineThickness = OutlineThickness;
|
||||
HollowRect.OutlineColor = OutlineColor;
|
||||
HollowRect.OutlineColor = OutlineColor.Convert();
|
||||
|
||||
CurrentRenderTarget.Draw(HollowRect);
|
||||
}
|
||||
#endregion
|
||||
#endregion Rectangle
|
||||
|
||||
#region Circle
|
||||
/// <summary>
|
||||
@@ -302,16 +295,14 @@ namespace SS14.Client.Graphics
|
||||
/// <param name="posY"> Pos Y of Circle </param>
|
||||
/// <param name="radius"> Radius of Circle </param>
|
||||
/// <param name="color"> Fill Color </param>
|
||||
public static void drawCircle(int posX, int posY, int radius, Color color)
|
||||
public static void drawCircle(int posX, int posY, int radius, Color4 color)
|
||||
{
|
||||
CircleShape Circle = new CircleShape();
|
||||
Circle.Position = new Vector2f(posX, posY);
|
||||
Circle.Radius = radius;
|
||||
Circle.FillColor = color;
|
||||
Circle.FillColor = color.Convert();
|
||||
|
||||
CurrentRenderTarget.Draw(Circle);
|
||||
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Draws a Hollow Circle to the CurrentRenderTarget
|
||||
@@ -321,36 +312,19 @@ namespace SS14.Client.Graphics
|
||||
/// <param name="radius"> Radius of Circle </param>
|
||||
/// <param name="OutlineThickness"> Thickness of Circle Outline </param>
|
||||
/// <param name="OutlineColor"> Circle outline Color </param>
|
||||
public static void drawHollowCircle(int posX, int posY, int radius,float OutlineThickness, Color OutlineColor)
|
||||
public static void drawHollowCircle(int posX, int posY, int radius, float OutlineThickness, Color4 OutlineColor)
|
||||
{
|
||||
CircleShape Circle = new CircleShape();
|
||||
Circle.Position = new Vector2f(posX, posY);
|
||||
Circle.Position = new Vector2f(posX - radius, posY - radius);
|
||||
Circle.Radius = radius;
|
||||
Circle.FillColor = Color.Transparent;
|
||||
Circle.OutlineThickness = OutlineThickness;
|
||||
Circle.OutlineColor = OutlineColor;
|
||||
Circle.OutlineColor = OutlineColor.Convert();
|
||||
|
||||
CurrentRenderTarget.Draw(Circle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a Filled Circle to the CurrentRenderTarget
|
||||
/// </summary>
|
||||
/// <param name="posX"> Pos X of Circle </param>
|
||||
/// <param name="posY"> Pos Y of Circle </param>
|
||||
/// <param name="radius"> Radius of Cirle </param>
|
||||
/// <param name="color"> Fill Color </param>
|
||||
/// <param name="vector2"></param>
|
||||
public static void drawCircle(float posX, float posY, int radius, Color color, Vector2f vector2)
|
||||
{
|
||||
CircleShape Circle = new CircleShape();
|
||||
Circle.Position = new Vector2f(posX, posY);
|
||||
Circle.Radius = radius;
|
||||
Circle.FillColor = Color.Transparent;
|
||||
|
||||
CurrentRenderTarget.Draw(Circle);
|
||||
}
|
||||
#endregion
|
||||
#endregion Circle
|
||||
|
||||
#region Point
|
||||
/// <summary>
|
||||
@@ -359,12 +333,12 @@ namespace SS14.Client.Graphics
|
||||
/// <param name="posX"> Pos X of Point </param>
|
||||
/// <param name="posY"> Pos Y of Point </param>
|
||||
/// <param name="color"> Fill Color </param>
|
||||
public static void drawPoint(int posX, int posY, Color color)
|
||||
public static void drawPoint(int posX, int posY, Color4 color)
|
||||
{
|
||||
RectangleShape Point = new RectangleShape();
|
||||
Point.Position = new Vector2f(posX, posY);
|
||||
Point.Size = new Vector2f(1, 1);
|
||||
Point.FillColor = color;
|
||||
Point.FillColor = color.Convert();
|
||||
|
||||
CurrentRenderTarget.Draw(Point);
|
||||
}
|
||||
@@ -375,19 +349,19 @@ namespace SS14.Client.Graphics
|
||||
/// <param name="posX"> Pos X of Point </param>
|
||||
/// <param name="posY"> Pos Y of Point </param>
|
||||
/// <param name="OutlineColor"> Outline Color </param>
|
||||
public static void drawHollowPoint(int posX, int posY, Color OutlineColor)
|
||||
public static void drawHollowPoint(int posX, int posY, Color4 OutlineColor)
|
||||
{
|
||||
RectangleShape hollowPoint = new RectangleShape();
|
||||
hollowPoint.Position = new Vector2f(posX, posY);
|
||||
hollowPoint.Size = new Vector2f(1, 1);
|
||||
hollowPoint.FillColor = Color.Transparent;
|
||||
hollowPoint.OutlineThickness = .6f;
|
||||
hollowPoint.OutlineColor = OutlineColor;
|
||||
hollowPoint.OutlineColor = OutlineColor.Convert();
|
||||
|
||||
CurrentRenderTarget.Draw(hollowPoint);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion Point
|
||||
|
||||
#region Line
|
||||
/// <summary>
|
||||
@@ -398,18 +372,20 @@ namespace SS14.Client.Graphics
|
||||
/// <param name="rotate"> Line Rotation </param>
|
||||
/// <param name="thickness"> Line Thickness </param>
|
||||
/// <param name="Color"> Line Color </param>
|
||||
public static void drawLine(int posX, int posY, int rotate,float thickness, Color Color)
|
||||
public static void drawLine(float posX, float posY, float length, float rotate, float thickness, Color4 Color)
|
||||
{
|
||||
RectangleShape line = new RectangleShape();
|
||||
line.Position = new Vector2f(posX, posY);
|
||||
line.Size = new Vector2f(length, thickness);
|
||||
line.Rotation = rotate;
|
||||
line.OutlineThickness = thickness;
|
||||
line.FillColor = Color;
|
||||
line.FillColor = Color.Convert();
|
||||
line.OutlineColor = Color.Convert();
|
||||
|
||||
CurrentRenderTarget.Draw(line);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion Line
|
||||
|
||||
#region Text
|
||||
/// <summary>
|
||||
@@ -420,99 +396,88 @@ namespace SS14.Client.Graphics
|
||||
/// <param name="text"> Text to render </param>
|
||||
/// <param name="size"> Size of the font </param>
|
||||
/// <param name="textColor"> Color of the text </param>
|
||||
public static void drawText(float posX, float posY, string text, uint size, Color textColor)
|
||||
public static void drawText(float posX, float posY, string text, uint size, Color4 textColor, Font font)
|
||||
{
|
||||
Text _text = new Text(text, new Font(@"..\..\Resources\Fonts\bluehigh.ttf"));
|
||||
Text _text = new Text(text, font);
|
||||
_text.Position = new SFML.System.Vector2f(posX, posY);
|
||||
_text.Color = textColor;
|
||||
_text.FillColor = textColor.Convert();
|
||||
_text.CharacterSize = size;
|
||||
|
||||
CurrentRenderTarget.Draw(_text);
|
||||
}
|
||||
#endregion
|
||||
#endregion Text
|
||||
|
||||
#endregion
|
||||
#endregion Drawing Methods
|
||||
|
||||
#region Client Window Data
|
||||
|
||||
/// <summary>
|
||||
/// Transforms a point from the world (tile) space, to screen (pixel) space.
|
||||
/// </summary>
|
||||
public static Vector2f WorldToScreen(Vector2f point)
|
||||
public static Vector2 WorldToScreen(Vector2 point)
|
||||
{
|
||||
var center = WorldCenter;
|
||||
return new Vector2f(
|
||||
(point.X - center.X) * TileSize + ScreenViewportSize.X / 2,
|
||||
(point.Y - center.Y) * TileSize + ScreenViewportSize.Y / 2
|
||||
);
|
||||
return (point - center) * TileSize + ScreenViewportSize / 2;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transforms a rectangle from the world (tile) space, to screen (pixel) space.
|
||||
/// </summary>
|
||||
public static FloatRect WorldToScreen(FloatRect rect)
|
||||
public static Box2 WorldToScreen(Box2 rect)
|
||||
{
|
||||
var center = WorldCenter;
|
||||
return new FloatRect(
|
||||
(rect.Left - center.X) * TileSize + ScreenViewportSize.X / 2,
|
||||
(rect.Top - center.Y) * TileSize + ScreenViewportSize.Y / 2,
|
||||
rect.Width * TileSize,
|
||||
rect.Height * TileSize
|
||||
);
|
||||
var topLeft = new Vector2(rect.Left, rect.Top);
|
||||
var bottomRight = new Vector2(rect.Right, rect.Bottom);
|
||||
return new Box2(
|
||||
WorldToScreen(topLeft),
|
||||
WorldToScreen(bottomRight)
|
||||
);
|
||||
}
|
||||
|
||||
public static Vector2f WorldToTile(Vector2f point)
|
||||
public static Vector2 WorldToTile(Vector2 point)
|
||||
{
|
||||
return new Vector2f(
|
||||
return new Vector2(
|
||||
(float)Math.Floor(point.X),
|
||||
(float)Math.Floor(point.Y)
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
public static Vector2f TileToWorld(Vector2f point)
|
||||
public static Vector2 TileToWorld(Vector2 point)
|
||||
{
|
||||
return new Vector2f(
|
||||
return new Vector2(
|
||||
point.X + 0.5f,
|
||||
point.Y + 0.5f
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transforms a point from the screen (pixel) space, to world (tile) space.
|
||||
/// </summary>
|
||||
public static Vector2f ScreenToWorld(Vector2i point)
|
||||
public static Vector2 ScreenToWorld(Vector2i point)
|
||||
{
|
||||
return new Vector2f(
|
||||
((float)point.X - ScreenViewportSize.X / 2 ) / TileSize + WorldCenter.X,
|
||||
((float)point.Y - ScreenViewportSize.Y / 2 ) / TileSize + WorldCenter.Y
|
||||
);
|
||||
return ((Vector2)point - ScreenViewportSize / 2) / TileSize + WorldCenter;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transforms a rectangle from the screen (pixel) space, to world (tile) space.
|
||||
/// </summary>
|
||||
public static FloatRect ScreenToWorld(IntRect rect)
|
||||
{
|
||||
var center = WorldCenter;
|
||||
return new FloatRect(
|
||||
((float)rect.Left - ScreenViewportSize.X / 2) / TileSize + center.X,
|
||||
((float)rect.Top - ScreenViewportSize.Y / 2) / TileSize + center.Y,
|
||||
rect.Width / TileSize,
|
||||
rect.Height / TileSize
|
||||
);
|
||||
}
|
||||
public static Box2 ScreenToWorld(Box2i rect)
|
||||
{
|
||||
var center = WorldCenter;
|
||||
return new Box2(
|
||||
((Vector2)rect.TopLeft - ScreenViewportSize / 2) / TileSize + center,
|
||||
((Vector2)rect.BottomRight - ScreenViewportSize / 2) / TileSize + center
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scales a vector from pixel coordinates to tile coordinates.
|
||||
/// </summary>
|
||||
/// <param name="size"></param>
|
||||
/// <returns></returns>
|
||||
public static Vector2f PixelToTile(Vector2f vec)
|
||||
public static Vector2 PixelToTile(Vector2 vec)
|
||||
{
|
||||
return new Vector2f(
|
||||
vec.X / TileSize,
|
||||
vec.Y / TileSize
|
||||
);
|
||||
return vec / TileSize;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -520,27 +485,27 @@ namespace SS14.Client.Graphics
|
||||
/// </summary>
|
||||
/// <param name="size"></param>
|
||||
/// <returns></returns>
|
||||
public static FloatRect PixelToTile(FloatRect rect)
|
||||
{
|
||||
return new FloatRect(
|
||||
rect.Left / TileSize,
|
||||
rect.Top / TileSize,
|
||||
rect.Width / TileSize,
|
||||
rect.Height / TileSize
|
||||
);
|
||||
}
|
||||
public static Box2 PixelToTile(Box2 rect)
|
||||
{
|
||||
return new Box2(
|
||||
rect.Left / TileSize,
|
||||
rect.Top / TileSize,
|
||||
rect.Right / TileSize,
|
||||
rect.Bottom / TileSize
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Takes a point in world (tile) coordinates, and rounds it to the nearest pixel.
|
||||
/// </summary>
|
||||
public static Vector2f GetNearestPixel(Vector2f worldPoint)
|
||||
public static Vector2 GetNearestPixel(Vector2 worldPoint)
|
||||
{
|
||||
return new Vector2f(
|
||||
return new Vector2(
|
||||
(float)Math.Round(worldPoint.X * TileSize) / TileSize,
|
||||
(float)Math.Round(worldPoint.Y * TileSize) / TileSize
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion Client Window Data
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace SS14.Client.Graphics.Event
|
||||
{
|
||||
public delegate void FrameEventHandler(object sender, FrameEventArgs e);
|
||||
|
||||
|
||||
public class FrameEventArgs : EventArgs
|
||||
{
|
||||
private float _frameDeltaTime;
|
||||
|
||||
public FrameEventArgs(float frameDeltaTime)
|
||||
{
|
||||
_frameDeltaTime = frameDeltaTime;
|
||||
}
|
||||
|
||||
public float FrameDeltaTime
|
||||
{
|
||||
get { return _frameDeltaTime; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
<configuration>
|
||||
<dllmap os="linux" dll="opengl32.dll" target="libGL.so.1"/>
|
||||
<dllmap os="linux" dll="glu32.dll" target="libGLU.so.1"/>
|
||||
<dllmap os="linux" dll="openal32.dll" target="libopenal.so.1"/>
|
||||
<dllmap os="linux" dll="alut.dll" target="libalut.so.0"/>
|
||||
<dllmap os="linux" dll="opencl.dll" target="libOpenCL.so"/>
|
||||
<dllmap os="linux" dll="libX11" target="libX11.so.6"/>
|
||||
<dllmap os="linux" dll="libXi" target="libXi.so.6"/>
|
||||
<dllmap os="linux" dll="SDL2.dll" target="libSDL2-2.0.so.0"/>
|
||||
<dllmap os="osx" dll="opengl32.dll" target="/System/Library/Frameworks/OpenGL.framework/OpenGL"/>
|
||||
<dllmap os="osx" dll="openal32.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
|
||||
<dllmap os="osx" dll="alut.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
|
||||
<dllmap os="osx" dll="libGLES.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
|
||||
<dllmap os="osx" dll="libGLESv1_CM.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
|
||||
<dllmap os="osx" dll="libGLESv2.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
|
||||
<dllmap os="osx" dll="opencl.dll" target="/System/Library/Frameworks/OpenCL.framework/OpenCL"/>
|
||||
<dllmap os="osx" dll="SDL2.dll" target="libSDL2.dylib"/>
|
||||
<!-- XQuartz compatibility (X11 on Mac) -->
|
||||
<dllmap os="osx" dll="libGL.so.1" target="/usr/X11/lib/libGL.dylib"/>
|
||||
<dllmap os="osx" dll="libX11" target="/usr/X11/lib/libX11.dylib"/>
|
||||
<dllmap os="osx" dll="libXcursor.so.1" target="/usr/X11/lib/libXcursor.dylib"/>
|
||||
<dllmap os="osx" dll="libXi" target="/usr/X11/lib/libXi.dylib"/>
|
||||
<dllmap os="osx" dll="libXinerama" target="/usr/X11/lib/libXinerama.dylib"/>
|
||||
<dllmap os="osx" dll="libXrandr.so.2" target="/usr/X11/lib/libXrandr.dylib"/>
|
||||
</configuration>
|
||||
@@ -1,4 +1,4 @@
|
||||
using SFML.Graphics;
|
||||
using SFML.Graphics;
|
||||
using SFML.System;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
@@ -79,18 +79,6 @@ namespace SS14.Client.Graphics.Render
|
||||
get { return base.Texture; }
|
||||
}
|
||||
|
||||
public IntRect Crop
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public Vector2f Scale
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public bool UseDepthBuffer
|
||||
{
|
||||
get;
|
||||
@@ -233,15 +221,6 @@ namespace SS14.Client.Graphics.Render
|
||||
CluwneLib.ResetRenderTarget();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Deconstructs and disposes this instance
|
||||
/// </summary>
|
||||
protected override void Destroy(bool disposing)
|
||||
{
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Drawing Methods
|
||||
@@ -375,26 +354,7 @@ namespace SS14.Client.Graphics.Render
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scale & optionally crop
|
||||
/// </summary>
|
||||
/// <param name="destination">The exact rectangle you wish to fill - scales to this size</param>
|
||||
/// <param name="optionalcrop">To take a subset of the original texture instead of the whole texture</param>
|
||||
/// <param name="color">Color.</param>
|
||||
// public void Blit(IntRect destination, IntRect optionalcrop, Color color)
|
||||
// {
|
||||
// CluwneSprite _blit;
|
||||
// Display();
|
||||
// if (optionalcrop == null)
|
||||
// _blit = new CluwneSprite("_blit" + key, this);
|
||||
// else
|
||||
// _blit = new CluwneSprite("_blit" + key, base.Texture, optionalcrop);
|
||||
// _blit.Color = color.ToSFMLColor();
|
||||
// _blit.Draw(destination);
|
||||
// }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0">
|
||||
<Import Project="..\MSBuild\SS14.Properties.targets" />
|
||||
<PropertyGroup>
|
||||
<ProjectType>Local</ProjectType>
|
||||
<ProjectGuid>{302B877E-0000-0000-0000-000000000000}</ProjectGuid>
|
||||
@@ -21,6 +22,7 @@
|
||||
</FileUpgradeFlags>
|
||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||
<TargetFrameworkProfile />
|
||||
<AllowedReferenceRelatedFileExtensions>.pdb;.dll.config</AllowedReferenceRelatedFileExtensions>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
@@ -31,7 +33,7 @@
|
||||
<DebugSymbols>True</DebugSymbols>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\bin\Graphics\</OutputPath>
|
||||
<OutputPath>$(SolutionDir)bin\Graphics\</OutputPath>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
@@ -46,33 +48,23 @@
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<Optimize>True</Optimize>
|
||||
<OutputPath>..\bin\</OutputPath>
|
||||
<OutputPath>$(SolutionDir)bin\Graphics\</OutputPath>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>False</RemoveIntegerChecks>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
<AllowedReferenceRelatedFileExtensions>.dll.config</AllowedReferenceRelatedFileExtensions>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.CSharp">
|
||||
<Name>Microsoft.CSharp</Name>
|
||||
</Reference>
|
||||
<Reference Include="OpenTK, Version=3.0.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\OpenTK.3.0.0-pre\lib\net20\OpenTK.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="sfmlnet-graphics-2">
|
||||
<Name>sfmlnet-graphics-2</Name>
|
||||
<HintPath>..\Third-Party\sfmlnet-graphics-2.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="sfmlnet-system-2">
|
||||
<Name>sfmlnet-system-2</Name>
|
||||
<HintPath>..\Third-Party\sfmlnet-system-2.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="sfmlnet-window-2">
|
||||
<Name>sfmlnet-window-2</Name>
|
||||
<HintPath>..\Third-Party\sfmlnet-window-2.dll</HintPath>
|
||||
<HintPath>$(SolutionDir)packages\OpenTK.3.0.0-pre\lib\net20\OpenTK.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Drawing" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CluwneLib.cs">
|
||||
@@ -86,9 +78,6 @@
|
||||
<Compile Include="Enums\GraphicsEnums.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Event\FrameEvent.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Shader\TechniqueList.cs" />
|
||||
<Compile Include="Sprite\AnimationInfo.cs" />
|
||||
<Compile Include="Sprite\SpriteInfo.cs" />
|
||||
@@ -136,32 +125,32 @@
|
||||
<Compile Include="View\Viewport.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Utility\SfmlExt.cs" />
|
||||
<Compile Include="Utility\SfmlCompatibility.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SFML\src\Graphics\sfml-graphics.csproj">
|
||||
<Project>{46786269-57b9-48e7-aa4f-8f4d84609fe6}</Project>
|
||||
<Name>sfml-graphics</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\SFML\src\System\sfml-system.csproj">
|
||||
<Project>{31d24303-f6a9-4d53-bb03-a73edcb3186d}</Project>
|
||||
<Name>sfml-system</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\SFML\src\Window\sfml-window.csproj">
|
||||
<Project>{d17de83d-a592-461f-8af2-53f9e22e1d0f}</Project>
|
||||
<Name>sfml-window</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\SS14.Shared\SS14.Shared.csproj">
|
||||
<Project>{0529f740-0000-0000-0000-000000000000}</Project>
|
||||
<Name>SS14.Shared</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="csfml-graphics-2.dll">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="csfml-network-2.dll">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="csfml-system-2.dll">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="csfml-window-2.dll">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="OpenTK.dll.config">
|
||||
<Content Include="$(SolutionDir)packages\OpenTK.3.0.0-pre\content\OpenTK.dll.config">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</Content>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
using OpenTK;
|
||||
using SFML.System;
|
||||
using SFML.Graphics.Glsl;
|
||||
using SS14.Client.Graphics.Render;
|
||||
using SS14.Client.Graphics.Utility;
|
||||
using SS14.Shared.Maths;
|
||||
using SS14.Shared.Utility;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using ShaderClass = SFML.Graphics.Shader;
|
||||
|
||||
|
||||
@@ -17,13 +22,13 @@ namespace SS14.Client.Graphics.Shader
|
||||
|
||||
|
||||
public GLSLShader(string vertexShaderFilename, string fragmentShaderFilename)
|
||||
: base(vertexShaderFilename, fragmentShaderFilename)
|
||||
: base(vertexShaderFilename, null, fragmentShaderFilename)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public GLSLShader(Stream vertexShaderStream, Stream fragmentShaderStream)
|
||||
: base(vertexShaderStream, fragmentShaderStream)
|
||||
: base(vertexShaderStream, null, fragmentShaderStream)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -49,48 +54,59 @@ namespace SS14.Client.Graphics.Shader
|
||||
|
||||
}
|
||||
|
||||
public void SetParameter(string Parameter, RenderImage Image)
|
||||
public void SetUniform(string Parameter, RenderImage Image)
|
||||
{
|
||||
base.SetParameter(Parameter, Image.Texture);
|
||||
base.SetUniform(Parameter, Image.Texture);
|
||||
}
|
||||
|
||||
public void SetParameter(string Parameter, Vector3f vec3)
|
||||
public void SetUniform(string Parameter, Vector2f vec2)
|
||||
{
|
||||
base.SetParameter(Parameter, vec3.X, vec3.Y, vec3.Z);
|
||||
|
||||
base.SetUniform(Parameter, vec2);
|
||||
}
|
||||
|
||||
public void SetParameter(string Parameter, Vector4f vec4)
|
||||
public void SetUniform(string Parameter, Vector2 vec2)
|
||||
{
|
||||
base.SetParameter(Parameter, vec4.X, vec4.Y, vec4.Z, vec4.W);
|
||||
base.SetUniform(Parameter, vec2.Convert());
|
||||
}
|
||||
|
||||
|
||||
public void SetParameter(string Parameter, Vector2f[] vec2array)
|
||||
public void SetUniform(string Parameter, Vector3f vec3)
|
||||
{
|
||||
for (int i = 0; i < vec2array.Length; i++)
|
||||
{
|
||||
this.SetParameter(Parameter + i, vec2array[i]);
|
||||
}
|
||||
base.SetUniform(Parameter, vec3);
|
||||
}
|
||||
|
||||
public void SetParameter(string Parameter, Vector3f[] vec3array)
|
||||
public void SetUniform(string Parameter, Vector3 vec3)
|
||||
{
|
||||
for (int i = 0; i < vec3array.Length; i++)
|
||||
{
|
||||
this.SetParameter(Parameter + i, vec3array[i]);
|
||||
}
|
||||
base.SetUniform(Parameter, vec3.Convert());
|
||||
}
|
||||
|
||||
public void SetParameter(string Parameter, Vector4f[] vec4array)
|
||||
public void SetUniform(string Parameter, Vector4 vec4)
|
||||
{
|
||||
for (int i = 0; i < vec4array.Length; i++)
|
||||
{
|
||||
this.SetParameter(Parameter + i, vec4array[i]);
|
||||
}
|
||||
|
||||
base.SetUniform(Parameter, new Vec4(vec4.X, vec4.Y, vec4.Z, vec4.W));
|
||||
}
|
||||
|
||||
public void SetUniformArray(string Parameter, Vector2f[] vec2array)
|
||||
{
|
||||
SetUniformArray(Parameter, vec2array.Select(v => (Vec2)v).ToArray());
|
||||
}
|
||||
|
||||
public void SetUniformArray(string Parameter, Vector3f[] vec3array)
|
||||
{
|
||||
SetUniformArray(Parameter, vec3array.Select(v => (Vec3)v).ToArray());
|
||||
}
|
||||
|
||||
public void SetUniformArray(string Parameter, Vector4[] vec4array)
|
||||
{
|
||||
SetUniformArray(Parameter, vec4array.Select(v => new Vec4(v.X, v.Y, v.Z, v.W)).ToArray());
|
||||
}
|
||||
|
||||
public void SetUniformArray(string Parameter, Vector2[] vec2array)
|
||||
{
|
||||
SetUniformArray(Parameter, vec2array.Select(v => new Vec2(v.X, v.Y)).ToArray());
|
||||
}
|
||||
|
||||
public void SetUniformArray(string Parameter, Vector3[] vec3array)
|
||||
{
|
||||
SetUniformArray(Parameter, vec3array.Select(v => new Vec3(v.X, v.Y, v.Z)).ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
using SFML.Graphics;
|
||||
using SFML.System;
|
||||
using SS14.Shared.Maths;
|
||||
|
||||
namespace SS14.Client.Graphics
|
||||
{
|
||||
public static class SpriteExt
|
||||
{
|
||||
public static void SetTransformToRect(this SFML.Graphics.Sprite sprite, IntRect rect)
|
||||
public static void SetTransformToRect(this SFML.Graphics.Sprite sprite, Box2i rect)
|
||||
{
|
||||
sprite.Scale = new SFML.System.Vector2f((float)rect.Width / (float)sprite.TextureRect.Width, (float)rect.Height / (float)sprite.TextureRect.Height);
|
||||
sprite.Position = new Vector2f(rect.Left, rect.Top);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using SFML.Graphics;
|
||||
using SFML.Graphics;
|
||||
using SFML.System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -11,7 +11,7 @@ namespace SS14.Client.Graphics.Sprite
|
||||
/// </summary>
|
||||
[DebuggerDisplay("[SpriteBatch] IsDrawing: {Drawing} | ")]
|
||||
public class SpriteBatch : Drawable
|
||||
{
|
||||
{
|
||||
|
||||
private QueueItem activeItem;
|
||||
private List<QueueItem> QueuedTextures = new List<QueueItem>();
|
||||
@@ -19,15 +19,14 @@ namespace SS14.Client.Graphics.Sprite
|
||||
private readonly uint Max;
|
||||
private int count;
|
||||
private bool Drawing;
|
||||
private uint queueCount;
|
||||
|
||||
|
||||
public int Count
|
||||
{
|
||||
get { return count; }
|
||||
}
|
||||
|
||||
public BlendMode BlendingSettings;
|
||||
|
||||
|
||||
public SpriteBatch(uint maxCapacity = 100000)
|
||||
{
|
||||
Max = maxCapacity * 4;
|
||||
@@ -35,7 +34,7 @@ namespace SS14.Client.Graphics.Sprite
|
||||
}
|
||||
|
||||
public void BeginDrawing()
|
||||
{
|
||||
{
|
||||
count = 0;
|
||||
// we use these a lot, and the overall number of textures
|
||||
// remains stable, so recycle them to avoid excess calls into
|
||||
@@ -52,13 +51,13 @@ namespace SS14.Client.Graphics.Sprite
|
||||
}
|
||||
|
||||
public void EndDrawing()
|
||||
{
|
||||
{
|
||||
Drawing = false;
|
||||
}
|
||||
|
||||
private void Using(Texture texture)
|
||||
{
|
||||
if (!Drawing)
|
||||
if (!Drawing)
|
||||
throw new Exception("Call Begin first.");
|
||||
|
||||
if (activeItem == null || activeItem.Texture != texture)
|
||||
@@ -71,7 +70,7 @@ namespace SS14.Client.Graphics.Sprite
|
||||
else
|
||||
{
|
||||
activeItem = new QueueItem(texture);
|
||||
}
|
||||
}
|
||||
QueuedTextures.Add(activeItem);
|
||||
}
|
||||
}
|
||||
@@ -88,7 +87,6 @@ namespace SS14.Client.Graphics.Sprite
|
||||
Using(S.Texture);
|
||||
Vector2f Scale = new Vector2f(S.Scale.X, S.Scale.Y);
|
||||
float sin = 0, cos = 1;
|
||||
//FloatMath.SinCos(rotation, out sin, out cos);
|
||||
|
||||
S.Rotation = S.Rotation / 180 * (float)Math.PI;
|
||||
sin = (float)Math.Sin(S.Rotation);
|
||||
@@ -117,7 +115,7 @@ namespace SS14.Client.Graphics.Sprite
|
||||
activeItem.Verticies.Append
|
||||
(
|
||||
new Vertex(
|
||||
new SFML.System.Vector2f(
|
||||
new SFML.System.Vector2f(
|
||||
pX * cos - pY * sin + S.Position.X,
|
||||
pX * sin + pY * cos + S.Position.Y),
|
||||
S.Color,
|
||||
@@ -156,65 +154,6 @@ namespace SS14.Client.Graphics.Sprite
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public unsafe void Draw(Texture texture, FloatRect rec, IntRect src, Color color)
|
||||
{
|
||||
var index = Create(texture);
|
||||
|
||||
fixed (Vertex* fptr = vertices)
|
||||
{
|
||||
var ptr = fptr + index;
|
||||
|
||||
ptr->Position.X = rec.Left;
|
||||
ptr->Position.Y = rec.Top;
|
||||
ptr->TexCoords.X = src.Left;
|
||||
ptr->TexCoords.Y = src.Top;
|
||||
ptr->Color = color;
|
||||
ptr++;
|
||||
|
||||
ptr->Position.X = rec.Left + rec.Width;
|
||||
ptr->Position.Y = rec.Top;
|
||||
ptr->TexCoords.X = src.Left + src.Width;
|
||||
ptr->TexCoords.Y = src.Top;
|
||||
ptr->Color = color;
|
||||
ptr++;
|
||||
|
||||
ptr->Position.X = rec.Left + rec.Width;
|
||||
ptr->Position.Y = rec.Top + rec.Height;
|
||||
ptr->TexCoords.X = src.Left + src.Width;
|
||||
ptr->TexCoords.Y = src.Top + src.Height;
|
||||
ptr->Color = color;
|
||||
ptr++;
|
||||
|
||||
ptr->Position.X = rec.Left;
|
||||
ptr->Position.Y = rec.Top + rec.Height;
|
||||
ptr->TexCoords.X = src.Left;
|
||||
ptr->TexCoords.Y = src.Top + src.Height;
|
||||
ptr->Color = color;
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw(Texture texture, FloatRect rec, Color color)
|
||||
{
|
||||
int width = 1, height = 1;
|
||||
if (texture != null)
|
||||
{
|
||||
width = (int)texture.Size.X;
|
||||
height = (int)texture.Size.Y;
|
||||
}
|
||||
Draw(texture, rec, new IntRect(0, 0, width, height), color);
|
||||
}
|
||||
|
||||
public void Draw(Texture texture, Vector2f pos, Color color)
|
||||
{
|
||||
if (texture == null) throw new ArgumentNullException();
|
||||
var width = (int)texture.Size.X;
|
||||
var height = (int)texture.Size.Y;
|
||||
Draw(texture, new FloatRect(pos.X, pos.Y, width, height), new IntRect(0, 0, width, height), color);
|
||||
}
|
||||
|
||||
*/
|
||||
public void Draw(RenderTarget target, RenderStates Renderstates)
|
||||
{
|
||||
if (Drawing) throw new Exception("Call End first.");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using SFML.System;
|
||||
using OpenTK;
|
||||
|
||||
namespace SS14.Client.Graphics.Sprite
|
||||
{
|
||||
@@ -10,7 +10,7 @@ namespace SS14.Client.Graphics.Sprite
|
||||
public struct SpriteInfo
|
||||
{
|
||||
public string Name;
|
||||
public Vector2f Offsets;
|
||||
public Vector2f Size;
|
||||
public Vector2 Offsets;
|
||||
public Vector2 Size;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
using SFML.Graphics;
|
||||
using SFML.System;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using SS14.Client.Graphics.Interface;
|
||||
using SS14.Client.Graphics.Utility;
|
||||
using SS14.Shared.Utility;
|
||||
using Vector2i = SS14.Shared.Maths.Vector2i;
|
||||
|
||||
namespace SS14.Client.Graphics.Sprite
|
||||
{
|
||||
@@ -10,7 +15,7 @@ namespace SS14.Client.Graphics.Sprite
|
||||
public class TextSprite : ICluwneDrawable
|
||||
{
|
||||
private bool _shadowed; // Is the Text Shadowed
|
||||
private Color _shadowColor; // Shadow Color
|
||||
private Color4 _shadowColor; // Shadow Color
|
||||
private Text _textSprite;
|
||||
private string Label;
|
||||
|
||||
@@ -41,19 +46,6 @@ namespace SS14.Client.Graphics.Sprite
|
||||
_textSprite = new Text(text, font, 14);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a TextSprite
|
||||
/// </summary>
|
||||
/// <param name="Label"> ID of the TextSprite</param>
|
||||
/// <param name="x"> position X of TextSprite </param>
|
||||
/// <param name="y"> Position Y of TextSprite </param>
|
||||
/// <param name="width"> Width of TextSprite </param>
|
||||
/// <param name="height"> Height of TextSprite </param>
|
||||
// public TextSprite(string Label, int x, int y, int width, int height)
|
||||
// {
|
||||
// this.Position = new Vector2(x, y);
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Draws the TextSprite to the CurrentRenderTarget
|
||||
/// </summary>
|
||||
@@ -65,14 +57,14 @@ namespace SS14.Client.Graphics.Sprite
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
_textSprite.Position = new Vector2f(Position.X, Position.Y); // -(_textSprite.GetLocalBounds().Height/2f));
|
||||
_textSprite.Color = Color;
|
||||
_textSprite.Position = new Vector2f(Position.X, Position.Y);
|
||||
_textSprite.FillColor = Color.Convert();
|
||||
CluwneLib.CurrentRenderTarget.Draw(_textSprite);
|
||||
|
||||
if (CluwneLib.Debug.DebugTextboxes)//CluwneLib.Debug()
|
||||
if (CluwneLib.Debug.DebugTextboxes)
|
||||
{
|
||||
FloatRect fr = _textSprite.GetGlobalBounds();
|
||||
CluwneLib.drawHollowRectangle((int)fr.Left, (int)fr.Top, (int)fr.Width, (int)fr.Height, 1.0f, Color.Red);
|
||||
var fr = _textSprite.GetGlobalBounds().Convert();
|
||||
CluwneLib.drawHollowRectangle((int)fr.Left, (int)fr.Top, (int)fr.Width, (int)fr.Height, 1.0f, Color4.Red);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,9 +88,9 @@ namespace SS14.Client.Graphics.Sprite
|
||||
return MeasureLine(Text);
|
||||
}
|
||||
|
||||
public Vector2f FindCharacterPos(uint index)
|
||||
public Vector2 FindCharacterPos(uint index)
|
||||
{
|
||||
return _textSprite.FindCharacterPos(index);
|
||||
return _textSprite.FindCharacterPos(index).Convert();
|
||||
}
|
||||
|
||||
#endregion Methods
|
||||
@@ -107,9 +99,9 @@ namespace SS14.Client.Graphics.Sprite
|
||||
|
||||
public Vector2i Size;
|
||||
|
||||
public Color Color;
|
||||
public Color4 Color;
|
||||
|
||||
public Vector2f ShadowOffset { get; set; }
|
||||
public Vector2 ShadowOffset { get; set; }
|
||||
|
||||
public bool Shadowed
|
||||
{
|
||||
@@ -123,7 +115,7 @@ namespace SS14.Client.Graphics.Sprite
|
||||
set => _textSprite.CharacterSize = value;
|
||||
}
|
||||
|
||||
public Color ShadowColor
|
||||
public Color4 ShadowColor
|
||||
{
|
||||
get => _shadowColor;
|
||||
set => this._shadowColor = value;
|
||||
|
||||
117
SS14.Client.Graphics/Utility/SfmlCompatibility.cs
Normal file
117
SS14.Client.Graphics/Utility/SfmlCompatibility.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using SFML.Graphics;
|
||||
using SFML.System;
|
||||
using SS14.Shared.Maths;
|
||||
using Vector2i = SS14.Shared.Maths.Vector2i;
|
||||
using Vector2u = SS14.Shared.Maths.Vector2u;
|
||||
|
||||
namespace SS14.Client.Graphics.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides compatibility extensions to convert between SFML and OpenTK types.
|
||||
/// </summary>
|
||||
public static class SfmlCompatibility
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts a OpenTK Vector2 to a SFML Vector2.
|
||||
/// </summary>
|
||||
/// <param name="vec">OpenTK Vector2.</param>
|
||||
/// <returns>SFML Vector2.</returns>
|
||||
public static Vector2f Convert(this Vector2 vec)
|
||||
{
|
||||
return new Vector2f(vec.X, vec.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a SFML Vector2 to a OpenTK Vector2.
|
||||
/// </summary>
|
||||
/// <param name="vec">SFML Vector2.</param>
|
||||
/// <returns>OpenTK Vector2.</returns>
|
||||
public static Vector2 Convert(this Vector2f vec)
|
||||
{
|
||||
return new Vector2(vec.X, vec.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a OpenTK Vector3 to a SFML Vector3.
|
||||
/// </summary>
|
||||
/// <param name="vec">OpenTK Vector3.</param>
|
||||
/// <returns>SFML Vector3.</returns>
|
||||
public static Vector3f Convert(this Vector3 vec)
|
||||
{
|
||||
return new Vector3f(vec.X, vec.Y, vec.Z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a SFML Vector3 to a OpenTK Vector3.
|
||||
/// </summary>
|
||||
/// <param name="vec">SFML Vector3.</param>
|
||||
/// <returns>OpenTK Vector3.</returns>
|
||||
public static Vector3 Convert(this Vector3f vec)
|
||||
{
|
||||
return new Vector3(vec.X, vec.Y, vec.Z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a OpenTK Box2 to a SFML FloatRect.
|
||||
/// </summary>
|
||||
/// <param name="box">OpenTK Box2.</param>
|
||||
/// <returns>SFML FloatRect.</returns>
|
||||
public static FloatRect Convert(this Box2 box)
|
||||
{
|
||||
return new FloatRect(box.Left, box.Top, box.Width, box.Height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a SFML FloatRect to a OpenTK Box2.
|
||||
/// </summary>
|
||||
/// <param name="rect">SFML FloatRect.</param>
|
||||
/// <returns>OpenTK Box2.</returns>
|
||||
public static Box2 Convert(this FloatRect rect)
|
||||
{
|
||||
return new Box2(rect.Left, rect.Top, rect.Right(), rect.Bottom());
|
||||
}
|
||||
|
||||
public static IntRect Convert(this Box2i box)
|
||||
{
|
||||
return new IntRect(box.Left, box.Top, box.Width, box.Height);
|
||||
}
|
||||
|
||||
public static Box2i Convert(this IntRect rect)
|
||||
{
|
||||
return new Box2i(rect.Left, rect.Top, rect.Right(), rect.Bottom());
|
||||
}
|
||||
|
||||
public static Vector2i Convert(this SFML.System.Vector2i vector)
|
||||
{
|
||||
return new Vector2i(vector.X, vector.Y);
|
||||
}
|
||||
|
||||
public static SFML.System.Vector2i Convert(this Vector2i vector)
|
||||
{
|
||||
return new SFML.System.Vector2i(vector.X, vector.Y);
|
||||
}
|
||||
|
||||
public static Vector2u Convert(this SFML.System.Vector2u vector)
|
||||
{
|
||||
return new Vector2u(vector.X, vector.Y);
|
||||
}
|
||||
|
||||
public static Vector2 Convertf(this SFML.System.Vector2u vector)
|
||||
{
|
||||
return new Vector2(vector.X, vector.Y);
|
||||
}
|
||||
|
||||
public static Color Convert(this Color4 color)
|
||||
{
|
||||
var bcolor = (System.Drawing.Color)color;
|
||||
return new Color(bcolor.R, bcolor.G, bcolor.B, bcolor.A);
|
||||
}
|
||||
|
||||
public static Color4 Convert(this Color color)
|
||||
{
|
||||
return new Color4(color.R, color.G, color.B, color.A);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,21 @@
|
||||
using SFML.Graphics;
|
||||
using SFML.Graphics;
|
||||
using SFML.System;
|
||||
using System;
|
||||
|
||||
namespace SS14.Shared.Maths
|
||||
namespace SS14.Client.Graphics.Utility
|
||||
{
|
||||
public static class SfmlExt
|
||||
{
|
||||
// Vector2i
|
||||
public static int LengthSquared(this Vector2i vec) => vec.X * vec.X + vec.Y * vec.Y;
|
||||
public static float Length(this Vector2i vec) => (float)Math.Sqrt(LengthSquared(vec));
|
||||
public static Vector2f ToFloat(this Vector2i vec) => new Vector2f(vec.X, vec.Y);
|
||||
public static int LengthSquared(this SFML.System.Vector2i vec) => vec.X * vec.X + vec.Y * vec.Y;
|
||||
public static float Length(this SFML.System.Vector2i vec) => (float)Math.Sqrt(LengthSquared(vec));
|
||||
public static Vector2f ToFloat(this SFML.System.Vector2i vec) => new Vector2f(vec.X, vec.Y);
|
||||
|
||||
|
||||
// Vector2f
|
||||
// Vector2
|
||||
public static float LengthSquared(this Vector2f vec) => vec.X * vec.X + vec.Y * vec.Y;
|
||||
public static float Length(this Vector2f vec) => (float)Math.Sqrt(LengthSquared(vec));
|
||||
public static Vector2i Round(this Vector2f vec) => new Vector2i((int)Math.Round(vec.X), (int)Math.Round(vec.Y));
|
||||
public static SFML.System.Vector2i Round(this Vector2f vec) => new SFML.System.Vector2i((int)Math.Round(vec.X), (int)Math.Round(vec.Y));
|
||||
|
||||
|
||||
// IntRect
|
||||
@@ -59,58 +59,6 @@ namespace SS14.Shared.Maths
|
||||
(byte)(color >> 0),
|
||||
(byte)(color >> 24)));
|
||||
|
||||
/// <summary>
|
||||
/// Values used internally by <see cref="DirectionTo" />
|
||||
/// </summary>
|
||||
private static Direction[] AngleDirections = new Direction[]
|
||||
{
|
||||
Direction.East,
|
||||
Direction.NorthEast,
|
||||
Direction.North,
|
||||
Direction.NorthWest,
|
||||
Direction.West,
|
||||
Direction.SouthWest,
|
||||
Direction.South,
|
||||
Direction.SouthEast,
|
||||
Direction.East
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Find the direction that <paramref name="target" /> is from <paramref name="origin" />.
|
||||
/// </summary>
|
||||
/// <param name="origin">The origin vector.</param>
|
||||
/// <param name="target">The target vector.</param>
|
||||
/// <param name="fallback">The direction used if no direction could be calculated (difference between vectors too small).</param>
|
||||
public static Direction DirectionTo(this Vector2f origin, Vector2f target, Direction fallback=Direction.South)
|
||||
{
|
||||
var mag1 = origin.Magnitude();
|
||||
var mag2 = target.Magnitude();
|
||||
// Check whether the vectors are almost zero.
|
||||
// Don't use == because equality checking on floats is dangerous and unreliable.
|
||||
// If the range is too wide go ahead and make it smaller.
|
||||
if (mag1 < 0.0001 && mag1 > -0.0001 && mag2 < 0.0001 && mag2 > -0.0001)
|
||||
{
|
||||
return fallback;
|
||||
}
|
||||
|
||||
// Angle in degrees.
|
||||
// Keep in mind: Cartesian plane so 0° is to the right.
|
||||
var angle = FloatMath.ToDegrees((float)Math.Atan2(target.Y - origin.Y, target.X - origin.X));
|
||||
|
||||
// The directions are assumed to be perfect 45° surfaces.
|
||||
// So 0° is between the east one, and 22.5° is the edge between east and north east.
|
||||
|
||||
// Wrap negative angles around so we're always dealing with positives.
|
||||
if (angle < 0)
|
||||
{
|
||||
angle += 360;
|
||||
}
|
||||
|
||||
// Add 22.5° to offset the angles since 0° is inside one.
|
||||
angle += 22.5f;
|
||||
|
||||
return AngleDirections[(int)Math.Floor(angle/45f)];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the dot product of two vectors
|
||||
@@ -1,6 +1,7 @@
|
||||
using SFML.Graphics;
|
||||
using SFML.System;
|
||||
using SS14.Client.Graphics.Collection;
|
||||
using SS14.Client.Graphics.Utility;
|
||||
using SS14.Shared.Maths;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
@@ -221,4 +222,4 @@ namespace SS14.Client.Graphics.VertexData
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,337 +0,0 @@
|
||||
using SFML.Graphics;
|
||||
using SFML.System;
|
||||
using SS14.Client.GameObjects;
|
||||
using SS14.Client.Interfaces.Collision;
|
||||
using SS14.Client.Interfaces.Map;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.Maths;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace SS14.Client.Collision
|
||||
{
|
||||
//Its the bucket list!
|
||||
/// <summary>
|
||||
/// Here's what is happening here. Each collidable AABB added to this manager gets tossed into
|
||||
/// a "bucket". The buckets are subdivisions of the world space in 256-unit blocks.
|
||||
/// </summary>
|
||||
public class CollisionManager : ICollisionManager
|
||||
{
|
||||
private const int BucketSize = 256;
|
||||
private readonly Dictionary<CollidableAABB, IEntity> _aabbs;
|
||||
|
||||
private readonly Dictionary<Vector2i, int> _bucketIndex;
|
||||
//Indexed in 256-pixel blocks - 0 = 0, 1 = 256, 2 = 512 etc
|
||||
|
||||
private readonly Dictionary<int, CollidableBucket> _buckets;
|
||||
// each bucket represents a 256x256 block of pixelspace
|
||||
|
||||
private int _lastIndex;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
public CollisionManager()
|
||||
{
|
||||
_bucketIndex = new Dictionary<Vector2i, int>();
|
||||
_buckets = new Dictionary<int, CollidableBucket>();
|
||||
_aabbs = new Dictionary<CollidableAABB, IEntity>();
|
||||
}
|
||||
|
||||
#region ICollisionManager members
|
||||
|
||||
/// <summary>
|
||||
/// returns true if collider intersects a collidable under management. Does not trigger Bump.
|
||||
/// </summary>
|
||||
/// <param name="collider">Rectangle to check for collision</param>
|
||||
/// <returns></returns>
|
||||
public bool IsColliding(FloatRect collider)
|
||||
{
|
||||
Vector2f[] points =
|
||||
{
|
||||
new Vector2f(collider.Left, collider.Top),
|
||||
new Vector2f(collider.Right(), collider.Top),
|
||||
new Vector2f(collider.Right(), collider.Bottom()),
|
||||
new Vector2f(collider.Left, collider.Bottom())
|
||||
};
|
||||
|
||||
//Get the buckets that correspond to the collider's points.
|
||||
List<CollidableBucket> buckets = points.Select(GetBucket).Distinct().ToList();
|
||||
|
||||
//Get all of the points
|
||||
var cpoints = new List<CollidablePoint>();
|
||||
foreach (CollidableBucket bucket in buckets)
|
||||
{
|
||||
cpoints.AddRange(bucket.GetPoints());
|
||||
}
|
||||
|
||||
//Expand points to distinct AABBs
|
||||
List<CollidableAABB> aabBs = (cpoints.Select(cp => cp.ParentAABB)).Distinct().ToList();
|
||||
|
||||
//try all of the AABBs against the target rect.
|
||||
bool collided = false;
|
||||
foreach (CollidableAABB aabb in aabBs.Where(aabb => aabb.Collidable.AABB.Intersects(collider)))
|
||||
{
|
||||
if (aabb.IsHardCollider) //If the collider is supposed to prevent movement
|
||||
{
|
||||
collided = true;
|
||||
}
|
||||
}
|
||||
|
||||
return collided || IoCManager.Resolve<IMapManager>().GetTilesIntersecting(collider, true).Any(t => t.Tile.TileDef.IsCollidable);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// returns true if collider intersects a collidable under management and calls Bump.
|
||||
/// </summary>
|
||||
/// <param name="collider">Rectangle to check for collision</param>
|
||||
/// <returns></returns>
|
||||
public bool TryCollide(IEntity entity)
|
||||
{
|
||||
return TryCollide(entity, new Vector2f());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// returns true if collider intersects a collidable under management and calls Bump.
|
||||
/// </summary>
|
||||
/// <param name="collider">Rectangle to check for collision</param>
|
||||
/// <returns></returns>
|
||||
public bool TryCollide(IEntity entity, Vector2f offset, bool bump = true)
|
||||
{
|
||||
var collider = entity.GetComponent<ColliderComponent>();
|
||||
if (collider == null) return false;
|
||||
|
||||
var ColliderAABB = collider.WorldAABB;
|
||||
if (offset.LengthSquared() > 0)
|
||||
{
|
||||
ColliderAABB.Left += offset.X;
|
||||
ColliderAABB.Top += offset.Y;
|
||||
}
|
||||
|
||||
Vector2f[] points =
|
||||
{
|
||||
new Vector2f(ColliderAABB.Left, ColliderAABB.Top),
|
||||
new Vector2f(ColliderAABB.Right(), ColliderAABB.Top),
|
||||
new Vector2f(ColliderAABB.Right(), ColliderAABB.Bottom()),
|
||||
new Vector2f(ColliderAABB.Left, ColliderAABB.Bottom())
|
||||
};
|
||||
|
||||
var aabbs =
|
||||
points
|
||||
.Select(GetBucket) // Get the buckets that correspond to the collider's points.
|
||||
.Distinct()
|
||||
.SelectMany(b => b.GetPoints()) // Get all of the points
|
||||
.Select(p => p.ParentAABB) // Expand points to distinct AABBs
|
||||
.Distinct()
|
||||
.Where(aabb => aabb.Collidable.AABB.Intersects(ColliderAABB)); //try all of the AABBs against the target rect.
|
||||
|
||||
//try all of the AABBs against the target rect.
|
||||
bool collided = false;
|
||||
foreach (var aabb in aabbs)
|
||||
{
|
||||
if (aabb.IsHardCollider) //If the collider is supposed to prevent movement
|
||||
{
|
||||
collided = true;
|
||||
}
|
||||
|
||||
if (bump) aabb.Collidable.Bump(entity);
|
||||
}
|
||||
return collided || IoCManager.Resolve<IMapManager>().GetTilesIntersecting(ColliderAABB, true).Any(t => t.Tile.TileDef.IsCollidable);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a collidable to the manager.
|
||||
/// </summary>
|
||||
/// <param name="collidable"></param>
|
||||
public void AddCollidable(ICollidable collidable)
|
||||
{
|
||||
var c = new CollidableAABB(collidable);
|
||||
foreach (CollidablePoint p in c.Points)
|
||||
{
|
||||
AddPoint(p);
|
||||
}
|
||||
if (collidable is IComponent comp)
|
||||
{
|
||||
_aabbs.Add(c, comp.Owner);
|
||||
}
|
||||
else
|
||||
_aabbs.Add(c, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a collidable from the manager
|
||||
/// </summary>
|
||||
/// <param name="collidable"></param>
|
||||
public void RemoveCollidable(ICollidable collidable)
|
||||
{
|
||||
KeyValuePair<CollidableAABB, IEntity> ourAABB = _aabbs.FirstOrDefault(a => a.Key.Collidable == collidable);
|
||||
|
||||
if (ourAABB.Key.Collidable == null)
|
||||
return;
|
||||
|
||||
foreach (CollidablePoint p in ourAABB.Key.Points)
|
||||
{
|
||||
RemovePoint(p);
|
||||
}
|
||||
_aabbs.Remove(ourAABB.Key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the collidable in the manager.
|
||||
/// </summary>
|
||||
/// <param name="collidable"></param>
|
||||
public void UpdateCollidable(ICollidable collidable)
|
||||
{
|
||||
RemoveCollidable(collidable);
|
||||
AddCollidable(collidable);
|
||||
}
|
||||
|
||||
#endregion ICollisionManager members
|
||||
|
||||
/// <summary>
|
||||
/// Adds an AABB point to a buckets
|
||||
/// </summary>
|
||||
/// <param name="point"></param>
|
||||
private void AddPoint(CollidablePoint point)
|
||||
{
|
||||
CollidableBucket b = GetBucket(point.Coordinates);
|
||||
b.AddPoint(point);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes an AABB point from a bucket
|
||||
/// </summary>
|
||||
/// <param name="point"></param>
|
||||
private void RemovePoint(CollidablePoint point)
|
||||
{
|
||||
CollidableBucket b = GetBucket(point.Coordinates);
|
||||
b.RemovePoint(point);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a bucket given a point coordinate
|
||||
/// </summary>
|
||||
/// <param name="coordinate"></param>
|
||||
/// <returns></returns>
|
||||
private CollidableBucket GetBucket(Vector2f coordinate)
|
||||
{
|
||||
var key = GetBucketCoordinate(coordinate);
|
||||
return _bucketIndex.ContainsKey(key)
|
||||
? _buckets[_bucketIndex[key]]
|
||||
: CreateBucket(key);
|
||||
}
|
||||
|
||||
private static Vector2i GetBucketCoordinate(Vector2f coordinate)
|
||||
{
|
||||
var x = (int)Math.Floor(coordinate.X / BucketSize);
|
||||
var y = (int)Math.Floor(coordinate.Y / BucketSize);
|
||||
return new Vector2i(x, y);
|
||||
}
|
||||
|
||||
private CollidableBucket CreateBucket(Vector2i coordinate)
|
||||
{
|
||||
if (_bucketIndex.ContainsKey(coordinate))
|
||||
return _buckets[_bucketIndex[coordinate]];
|
||||
|
||||
var b = new CollidableBucket(_lastIndex, coordinate);
|
||||
_buckets.Add(_lastIndex, b);
|
||||
_bucketIndex.Add(coordinate, _lastIndex);
|
||||
_lastIndex++;
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This class holds points of collision AABBs. It represents a square in the world.
|
||||
/// </summary>
|
||||
internal class CollidableBucket
|
||||
{
|
||||
private readonly List<CollidablePoint> _points;
|
||||
private readonly Vector2i _coordinates;
|
||||
private readonly int _index;
|
||||
|
||||
public CollidableBucket(int index, Vector2i coordinates)
|
||||
{
|
||||
_index = index;
|
||||
_coordinates = coordinates;
|
||||
_points = new List<CollidablePoint>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a CollidablePoint to this bucket
|
||||
/// </summary>
|
||||
/// <param name="point"></param>
|
||||
public void AddPoint(CollidablePoint point)
|
||||
{
|
||||
_points.Add(point);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a CollidablePoint from this bucket, if it exists.
|
||||
/// </summary>
|
||||
/// <param name="point"></param>
|
||||
public void RemovePoint(CollidablePoint point)
|
||||
{
|
||||
if (_points.Contains(point))
|
||||
_points.Remove(point);
|
||||
}
|
||||
|
||||
public IEnumerable<CollidablePoint> GetPoints()
|
||||
{
|
||||
return _points;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This represents a point of a collision AABB
|
||||
/// </summary>
|
||||
internal struct CollidablePoint
|
||||
{
|
||||
public Vector2f Coordinates;
|
||||
public CollidablePointIndex Index;
|
||||
public CollidableAABB ParentAABB;
|
||||
|
||||
public CollidablePoint(CollidablePointIndex index, Vector2f coordinates, CollidableAABB parentAABB)
|
||||
{
|
||||
Index = index;
|
||||
Coordinates = coordinates;
|
||||
ParentAABB = parentAABB;
|
||||
}
|
||||
}
|
||||
|
||||
internal enum CollidablePointIndex
|
||||
{
|
||||
TopLeft,
|
||||
TopRight,
|
||||
BottomRight,
|
||||
BottomLeft
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is our representation of an AABB.
|
||||
/// </summary>
|
||||
internal struct CollidableAABB
|
||||
{
|
||||
public ICollidable Collidable;
|
||||
public bool IsHardCollider;
|
||||
public CollidablePoint[] Points;
|
||||
|
||||
public CollidableAABB(ICollidable collidable)
|
||||
{
|
||||
Collidable = collidable;
|
||||
IsHardCollider = Collidable.IsHardCollidable;
|
||||
Points = new CollidablePoint[4];
|
||||
float top = Collidable.AABB.Top;
|
||||
float bottom = Collidable.AABB.Bottom();
|
||||
float left = Collidable.AABB.Left;
|
||||
float right = Collidable.AABB.Right();
|
||||
Points[0] = new CollidablePoint(CollidablePointIndex.TopLeft, new Vector2f(left, top), this);
|
||||
Points[1] = new CollidablePoint(CollidablePointIndex.TopRight, new Vector2f(right, top), this);
|
||||
Points[2] = new CollidablePoint(CollidablePointIndex.BottomRight, new Vector2f(right, bottom), this);
|
||||
Points[3] = new CollidablePoint(CollidablePointIndex.BottomLeft, new Vector2f(left, bottom), this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
// Not some generic console command type.
|
||||
// Couldn't think of a better name sorry.
|
||||
|
||||
using OpenTK.Graphics;
|
||||
using SS14.Client.Interfaces.Console;
|
||||
using SS14.Client.Interfaces.UserInterface;
|
||||
using SS14.Shared.IoC;
|
||||
@@ -30,7 +31,7 @@ namespace SS14.Client.Console
|
||||
|
||||
public bool Execute(IDebugConsole console, params string[] args)
|
||||
{
|
||||
SFML.Graphics.Color[] colors = { SFML.Graphics.Color.Green, SFML.Graphics.Color.Blue, SFML.Graphics.Color.Red };
|
||||
Color4[] colors = { Color4.Green, Color4.Blue, Color4.Red };
|
||||
Random random = new Random();
|
||||
for (int x = 0; x < 50; x++)
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using OpenTK.Graphics;
|
||||
using SFML.Graphics;
|
||||
using SS14.Client.GameObjects;
|
||||
using SS14.Client.Interfaces.Console;
|
||||
@@ -22,9 +23,9 @@ namespace SS14.Client.Console
|
||||
{
|
||||
var entitymanager = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
foreach (IEntity e in entitymanager.GetEntities(new EntityQuery()))
|
||||
foreach (IEntity e in entitymanager.GetEntities(new ComponentEntityQuery()))
|
||||
{
|
||||
console.AddLine($"entity {e.Uid}, {e.Prototype.Name}.", Color.White);
|
||||
console.AddLine($"entity {e.Uid}, {e.Prototype.Name}.", Color4.White);
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -47,7 +48,7 @@ namespace SS14.Client.Console
|
||||
|
||||
foreach (var component in components)
|
||||
{
|
||||
console.AddLine($"{component.Owner.Uid}: {component.GetType()}", Color.White);
|
||||
console.AddLine($"{component.Owner.Uid}: {component.GetType()}", Color4.White);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -63,7 +64,7 @@ namespace SS14.Client.Console
|
||||
{
|
||||
if (args.Length < 1)
|
||||
{
|
||||
console.AddLine($"Not enough arguments.", Color.Red);
|
||||
console.AddLine($"Not enough arguments.", Color4.Red);
|
||||
return false;
|
||||
}
|
||||
var componentFactory = IoCManager.Resolve<IComponentFactory>();
|
||||
@@ -83,16 +84,16 @@ namespace SS14.Client.Console
|
||||
}
|
||||
message.Append($", NSE: {registration.NetworkSynchronizeExistence}, references:");
|
||||
|
||||
console.AddLine(message.ToString(), Color.White);
|
||||
console.AddLine(message.ToString(), Color4.White);
|
||||
|
||||
foreach (Type type in registration.References)
|
||||
{
|
||||
console.AddLine($" {type}", Color.White);
|
||||
console.AddLine($" {type}", Color4.White);
|
||||
}
|
||||
}
|
||||
catch (UnknownComponentException)
|
||||
{
|
||||
console.AddLine($"No registration found for '{args[0]}'", Color.Red);
|
||||
console.AddLine($"No registration found for '{args[0]}'", Color4.Red);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using OpenTK.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -23,7 +24,7 @@ namespace SS14.Client.Console
|
||||
switch (args.Length)
|
||||
{
|
||||
case 0:
|
||||
console.AddLine("To display help for a specific command, write 'help <command>'. To list all available commands, write 'list'.", Color.White);
|
||||
console.AddLine("To display help for a specific command, write 'help <command>'. To list all available commands, write 'list'.", Color4.White);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
@@ -33,19 +34,19 @@ namespace SS14.Client.Console
|
||||
if (!IoCManager.Resolve<IClientNetManager>().IsConnected)
|
||||
{
|
||||
// No server so nothing to respond with unknown command.
|
||||
console.AddLine("Unknown command: " + commandname, Color.Red);
|
||||
console.AddLine("Unknown command: " + commandname, Color4.Red);
|
||||
return false;
|
||||
}
|
||||
// TODO: Maybe have a server side help?
|
||||
return false; // return true;
|
||||
return false;
|
||||
}
|
||||
IConsoleCommand command = console.Commands[commandname];
|
||||
console.AddLine(string.Format("{0} - {1}", command.Command, command.Description), Color.White);
|
||||
console.AddLine(command.Help, Color.White);
|
||||
console.AddLine(string.Format("{0} - {1}", command.Command, command.Description), Color4.White);
|
||||
console.AddLine(command.Help, Color4.White);
|
||||
break;
|
||||
|
||||
default:
|
||||
console.AddLine("Invalid amount of arguments.", Color.Red);
|
||||
console.AddLine("Invalid amount of arguments.", Color4.Red);
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
@@ -62,7 +63,7 @@ namespace SS14.Client.Console
|
||||
{
|
||||
foreach (IConsoleCommand command in console.Commands.Values)
|
||||
{
|
||||
console.AddLine(command.Command + ": " + command.Description, Color.White);
|
||||
console.AddLine(command.Command + ": " + command.Description, Color4.White);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
// TODO: Re-add these.
|
||||
|
||||
/*
|
||||
switch (command)
|
||||
{
|
||||
case "addparticles": //This is only clientside.
|
||||
if (args.Count >= 3)
|
||||
{
|
||||
Entity target = null;
|
||||
if (args[1].ToLowerInvariant() == "player")
|
||||
{
|
||||
var plrMgr = IoCManager.Resolve<IPlayerManager>();
|
||||
if (plrMgr != null)
|
||||
if (plrMgr.ControlledEntity != null) target = plrMgr.ControlledEntity;
|
||||
}
|
||||
else
|
||||
{
|
||||
var entMgr = IoCManager.Resolve<IEntityManagerContainer>();
|
||||
if (entMgr != null)
|
||||
{
|
||||
int entUid = int.Parse(args[1]);
|
||||
target = entMgr.EntityManager.GetEntity(entUid);
|
||||
}
|
||||
}
|
||||
|
||||
if (target != null)
|
||||
{
|
||||
if (!target.HasComponent(ComponentFamily.Particles))
|
||||
{
|
||||
var entMgr = IoCManager.Resolve<IEntityManagerContainer>();
|
||||
var compo = (IParticleSystemComponent)entMgr.EntityManager.ComponentFactory.GetComponent("ParticleSystemComponent");
|
||||
target.AddComponent(ComponentFamily.Particles, compo);
|
||||
}
|
||||
else
|
||||
{
|
||||
var entMgr = IoCManager.Resolve<IEntityManagerContainer>();
|
||||
var compo = (IParticleSystemComponent)entMgr.EntityManager.ComponentFactory.GetComponent("ParticleSystemComponent");
|
||||
target.AddComponent(ComponentFamily.Particles, compo);
|
||||
}
|
||||
}
|
||||
}
|
||||
SendServerConsoleCommand(text); //Forward to server.
|
||||
break;
|
||||
|
||||
case "removeparticles":
|
||||
if (args.Count >= 3)
|
||||
{
|
||||
Entity target = null;
|
||||
if (args[1].ToLowerInvariant() == "player")
|
||||
{
|
||||
var plrMgr = IoCManager.Resolve<IPlayerManager>();
|
||||
if (plrMgr != null)
|
||||
if (plrMgr.ControlledEntity != null) target = plrMgr.ControlledEntity;
|
||||
}
|
||||
else
|
||||
{
|
||||
var entMgr = IoCManager.Resolve<IEntityManagerContainer>();
|
||||
if (entMgr != null)
|
||||
{
|
||||
int entUid = int.Parse(args[1]);
|
||||
target = entMgr.EntityManager.GetEntity(entUid);
|
||||
}
|
||||
}
|
||||
|
||||
if (target != null)
|
||||
{
|
||||
if (target.HasComponent(ComponentFamily.Particles))
|
||||
{
|
||||
IParticleSystemComponent compo = (IParticleSystemComponent)target.GetComponent(ComponentFamily.Particles);
|
||||
compo.RemoveParticleSystem(args[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
SendServerConsoleCommand(text); //Forward to server.
|
||||
break;
|
||||
}*/
|
||||
@@ -1,11 +1,11 @@
|
||||
using SFML.Graphics;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using SFML.Graphics;
|
||||
using SFML.Window;
|
||||
using SFML.System;
|
||||
using SS14.Client.Graphics;
|
||||
using SS14.Client.Graphics.Event;
|
||||
using SS14.Client.Graphics.Render;
|
||||
using SS14.Client.Interfaces.Input;
|
||||
using SS14.Client.Interfaces.Map;
|
||||
using SS14.Client.Interfaces.Network;
|
||||
using SS14.Client.Interfaces.Resource;
|
||||
using SS14.Client.Interfaces.State;
|
||||
@@ -13,6 +13,7 @@ using SS14.Client.Interfaces.UserInterface;
|
||||
using SS14.Client.Interfaces;
|
||||
using SS14.Client.State.States;
|
||||
using SS14.Shared.Interfaces.Configuration;
|
||||
using SS14.Shared.Interfaces.Map;
|
||||
using SS14.Shared.Interfaces.Serialization;
|
||||
using SS14.Shared.Configuration;
|
||||
using SS14.Shared.GameObjects;
|
||||
@@ -28,6 +29,9 @@ using SS14.Shared.Interfaces;
|
||||
using SS14.Shared.Interfaces.Network;
|
||||
using SS14.Shared.Interfaces.Timing;
|
||||
using KeyArgs = SFML.Window.KeyEventArgs;
|
||||
using SS14.Shared.Network.Messages;
|
||||
using SS14.Client.Interfaces.GameObjects;
|
||||
using SS14.Client.Interfaces.GameStates;
|
||||
|
||||
namespace SS14.Client
|
||||
{
|
||||
@@ -37,7 +41,6 @@ namespace SS14.Client
|
||||
|
||||
[Dependency]
|
||||
readonly private IConfigurationManager _configurationManager;
|
||||
// private Input _input;
|
||||
[Dependency]
|
||||
readonly private INetworkGrapher _netGrapher;
|
||||
[Dependency]
|
||||
@@ -49,8 +52,6 @@ namespace SS14.Client
|
||||
[Dependency]
|
||||
readonly private IResourceCache _resourceCache;
|
||||
[Dependency]
|
||||
readonly private IEntityNetworkManager _entityNetworkManager;
|
||||
[Dependency]
|
||||
readonly private ITileDefinitionManager _tileDefinitionManager;
|
||||
[Dependency]
|
||||
readonly private ISS14Serializer _serializer;
|
||||
@@ -58,12 +59,18 @@ namespace SS14.Client
|
||||
private readonly IGameTiming _time;
|
||||
[Dependency]
|
||||
private readonly IResourceManager _resourceManager;
|
||||
[Dependency]
|
||||
private readonly IMapManager _mapManager;
|
||||
|
||||
#endregion Fields
|
||||
|
||||
#region Methods
|
||||
|
||||
#region Constructors
|
||||
|
||||
private TimeSpan _lastTick;
|
||||
private TimeSpan _lastKeepUpAnnounce;
|
||||
|
||||
public void Run()
|
||||
{
|
||||
Logger.Debug("Initializing GameController.");
|
||||
@@ -71,47 +78,17 @@ namespace SS14.Client
|
||||
_configurationManager.LoadFromFile(PathHelpers.ExecutableRelativeFile("client_config.toml"));
|
||||
|
||||
_resourceCache.LoadBaseResources();
|
||||
|
||||
// Load resources used by splash screen and main menu.
|
||||
LoadSplashResources();
|
||||
ShowSplashScreen();
|
||||
|
||||
_resourceCache.LoadLocalResources();
|
||||
|
||||
LoadContentAssembly<GameShared>("Shared");
|
||||
LoadContentAssembly<GameClient>("Client");
|
||||
|
||||
// get the assembly from the file system
|
||||
if (_resourceManager.TryContentFileRead(@"Assemblies/Content.Client.dll", out MemoryStream gameDll))
|
||||
{
|
||||
Logger.Info("[ENG] Loading Client Content DLL");
|
||||
|
||||
// see if debug info is present
|
||||
if (_resourceManager.TryContentFileRead(@"Assemblies/Content.Client.pdb", out MemoryStream gamePdb))
|
||||
{
|
||||
try
|
||||
{
|
||||
// load the assembly into the process, and bootstrap the GameServer entry point.
|
||||
AssemblyLoader.LoadGameAssembly<GameServer>(gameDll.ToArray(), gamePdb.ToArray());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Info($"[ENG] Exception loading DLL Content.Client.dll, {e.Message}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
// load the assembly into the process, and bootstrap the GameServer entry point.
|
||||
AssemblyLoader.LoadGameAssembly<GameServer>(gameDll.ToArray());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Info($"[ENG] Exception loading DLL Content.Client.dll, {e.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Warning("[ENG] Could not find Client Content DLL");
|
||||
}
|
||||
// Call Init in game assemblies.
|
||||
AssemblyLoader.BroadcastRunLevel(AssemblyLoader.RunLevel.Init);
|
||||
|
||||
//Setup Cluwne first, as the rest depends on it.
|
||||
SetupCluwne();
|
||||
@@ -122,31 +99,86 @@ namespace SS14.Client
|
||||
|
||||
_serializer.Initialize();
|
||||
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
||||
prototypeManager.LoadDirectory(PathHelpers.ExecutableRelativeFile("Prototypes"));
|
||||
prototypeManager.LoadDirectory(PathHelpers.ExecutableRelativeFile("Resources/Prototypes"));
|
||||
prototypeManager.Resync();
|
||||
_networkManager.Initialize(false);
|
||||
_netGrapher.Initialize();
|
||||
_userInterfaceManager.Initialize();
|
||||
_mapManager.Initialize();
|
||||
|
||||
_networkManager.RegisterNetMessage<MsgFullState>(MsgFullState.NAME, (int)MsgFullState.ID, message => IoCManager.Resolve<IGameStateManager>().HandleFullStateMessage((MsgFullState)message));
|
||||
_networkManager.RegisterNetMessage<MsgStateUpdate>(MsgStateUpdate.NAME, (int)MsgStateUpdate.ID, message => IoCManager.Resolve<IGameStateManager>().HandleStateUpdateMessage((MsgStateUpdate)message));
|
||||
_networkManager.RegisterNetMessage<MsgEntity>(MsgEntity.NAME, (int)MsgEntity.ID, message => IoCManager.Resolve<IClientEntityManager>().HandleEntityNetworkMessage((MsgEntity)message));
|
||||
|
||||
_stateManager.RequestStateChange<MainScreen>();
|
||||
|
||||
FrameEventArgs _frameEvent;
|
||||
// EventArgs _frameEventArgs;
|
||||
var _clock = new Clock();
|
||||
#region GameLoop
|
||||
|
||||
// maximum number of ticks to queue before the loop slows down.
|
||||
const int maxTicks = 5;
|
||||
|
||||
_time.ResetRealTime();
|
||||
var maxTime = TimeSpan.FromTicks(_time.TickPeriod.Ticks * maxTicks);
|
||||
|
||||
while (CluwneLib.IsRunning)
|
||||
{
|
||||
//TODO: The client needs a real game loop...
|
||||
var accumulator = _time.RealTime - _lastTick;
|
||||
|
||||
// If the game can't keep up, limit time.
|
||||
if (accumulator > maxTime)
|
||||
{
|
||||
// limit accumulator to max time.
|
||||
accumulator = maxTime;
|
||||
|
||||
// pull lastTick up to the current realTime
|
||||
// This will slow down the simulation, but if we are behind from a
|
||||
// lag spike hopefully it will be able to catch up.
|
||||
_lastTick = _time.RealTime - maxTime;
|
||||
|
||||
// announce we are falling behind
|
||||
if ((_time.RealTime - _lastKeepUpAnnounce).TotalSeconds >= 15.0)
|
||||
{
|
||||
Logger.Warning("[SRV] MainLoop: Cannot keep up!");
|
||||
_lastKeepUpAnnounce = _time.RealTime;
|
||||
}
|
||||
}
|
||||
|
||||
_time.StartFrame();
|
||||
|
||||
var lastFrameTime = _clock.ElapsedTime.AsSeconds();
|
||||
_clock.Restart();
|
||||
_frameEvent = new FrameEventArgs(lastFrameTime);
|
||||
CluwneLib.ClearCurrentRendertarget(Color.Black);
|
||||
CluwneLib.Screen.DispatchEvents();
|
||||
CluwneLib.RunIdle(this, _frameEvent);
|
||||
CluwneLib.Screen.Display();
|
||||
var realFrameEvent = new FrameEventArgs((float)_time.RealFrameTime.TotalSeconds);
|
||||
|
||||
// process Net/KB/Mouse input
|
||||
Process(realFrameEvent);
|
||||
|
||||
_time.InSimulation = true;
|
||||
// run the simulation for every accumulated tick
|
||||
while (accumulator >= _time.TickPeriod)
|
||||
{
|
||||
accumulator -= _time.TickPeriod;
|
||||
_lastTick += _time.TickPeriod;
|
||||
|
||||
// only run the sim if unpaused, but still use up the accumulated time
|
||||
if (!_time.Paused)
|
||||
{
|
||||
// update the simulation
|
||||
var simFrameEvent = new FrameEventArgs((float) _time.FrameTime.TotalSeconds);
|
||||
Update(simFrameEvent);
|
||||
_time.CurTick++;
|
||||
}
|
||||
}
|
||||
|
||||
// if not paused, save how close to the next tick we are so interpolation works
|
||||
if (!_time.Paused)
|
||||
_time.TickRemainder = accumulator;
|
||||
|
||||
_time.InSimulation = false;
|
||||
|
||||
// render the simulation
|
||||
Render(realFrameEvent);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
_networkManager.ClientDisconnect("Client disconnected from game.");
|
||||
CluwneLib.Terminate();
|
||||
Logger.Info("GameController terminated.");
|
||||
@@ -154,6 +186,100 @@ namespace SS14.Client
|
||||
IoCManager.Resolve<IConfigurationManager>().SaveToFile();
|
||||
}
|
||||
|
||||
private void LoadContentAssembly<T>(string name) where T: GameShared
|
||||
{
|
||||
// get the assembly from the file system
|
||||
if (_resourceManager.TryContentFileRead($@"Assemblies/Content.{name}.dll", out MemoryStream gameDll))
|
||||
{
|
||||
Logger.Debug($"[SRV] Loading {name} Content DLL");
|
||||
|
||||
// see if debug info is present
|
||||
if (_resourceManager.TryContentFileRead($@"Assemblies/Content.{name}.pdb", out MemoryStream gamePdb))
|
||||
{
|
||||
try
|
||||
{
|
||||
// load the assembly into the process, and bootstrap the GameServer entry point.
|
||||
AssemblyLoader.LoadGameAssembly<T>(gameDll.ToArray(), gamePdb.ToArray());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Error($"[SRV] Exception loading DLL Content.{name}.dll: {e}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
// load the assembly into the process, and bootstrap the GameServer entry point.
|
||||
AssemblyLoader.LoadGameAssembly<T>(gameDll.ToArray());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Error($"[SRV] Exception loading DLL Content.{name}.dll: {e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Warning($"[ENG] Could not find {name} Content DLL");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processes all simulation I/O. Keyboard/Mouse/Network code gets called here.
|
||||
/// </summary>
|
||||
private void Process(FrameEventArgs e)
|
||||
{
|
||||
//TODO: Keyboard/Mouse input needs to be processed here.
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs a tick of the simulation.
|
||||
/// </summary>
|
||||
/// <param name="e">Current GameTiming.FrameTime</param>
|
||||
private void Update(FrameEventArgs e)
|
||||
{
|
||||
_networkManager.ProcessPackets();
|
||||
CluwneLib.RunIdle(this, e);
|
||||
_stateManager.Update(e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renders the view of the simulation.
|
||||
/// </summary>
|
||||
/// <param name="e">Current GameTiming.RealFrameTime</param>
|
||||
private void Render(FrameEventArgs e)
|
||||
{
|
||||
CluwneLib.ClearCurrentRendertarget(Color4.Black);
|
||||
CluwneLib.Screen.DispatchEvents();
|
||||
|
||||
// draw everything
|
||||
_stateManager.Render(e);
|
||||
|
||||
// interface runs in realtime, so it is updated here
|
||||
_userInterfaceManager.Update(e);
|
||||
|
||||
_userInterfaceManager.Render(e);
|
||||
|
||||
_netGrapher.Update();
|
||||
|
||||
// swap buffers to show the screen
|
||||
CluwneLib.Screen.Display();
|
||||
}
|
||||
|
||||
private void LoadSplashResources()
|
||||
{
|
||||
var logoTexture = _resourceCache.LoadTextureFrom("ss14_logo", _resourceManager.ContentFileRead(@"Textures/Logo/logo.png"));
|
||||
_resourceCache.LoadSpriteFromTexture("ss14_logo", logoTexture);
|
||||
|
||||
var backgroundTexture = _resourceCache.LoadTextureFrom("ss14_logo_background", _resourceManager.ContentFileRead(@"Textures/Logo/background.png"));
|
||||
_resourceCache.LoadSpriteFromTexture("ss14_logo_background", backgroundTexture);
|
||||
|
||||
var nanotrasenTexture = _resourceCache.LoadTextureFrom("ss14_logo_nt", _resourceManager.ContentFileRead(@"Textures/Logo/nanotrasen.png"));
|
||||
_resourceCache.LoadSpriteFromTexture("ss14_logo_nt", nanotrasenTexture);
|
||||
}
|
||||
|
||||
private void ShowSplashScreen()
|
||||
{
|
||||
// Do nothing when we're on DEBUG builds.
|
||||
@@ -161,25 +287,19 @@ namespace SS14.Client
|
||||
#if !DEBUG
|
||||
const uint SIZE_X = 600;
|
||||
const uint SIZE_Y = 300;
|
||||
// Size of the NT logo in the bottom left.
|
||||
// Size of the NT logo in the bottom right.
|
||||
const float NT_SIZE_X = SIZE_X / 10f;
|
||||
const float NT_SIZE_Y = SIZE_Y / 10f;
|
||||
CluwneWindow window = CluwneLib.ShowSplashScreen(new VideoMode(SIZE_X, SIZE_Y));
|
||||
|
||||
var logoTexture = new Texture(_resourceManager.ContentFileRead(@"Textures/Logo/logo.png"));
|
||||
var logo = new SFML.Graphics.Sprite(logoTexture);
|
||||
var logoSize = logoTexture.Size;
|
||||
logo.Position = new Vector2f(SIZE_X / 2 - logoSize.X / 2, SIZE_Y / 2 - logoSize.Y / 2);
|
||||
var logo = _resourceCache.GetSprite("ss14_logo");
|
||||
logo.Position = new Vector2f(SIZE_X / 2 - logo.TextureRect.Width / 2, SIZE_Y / 2 - logo.TextureRect.Height / 2);
|
||||
|
||||
var backgroundTexture = new Texture(_resourceManager.ContentFileRead(@"Textures/Logo/background.png"));
|
||||
var background = new SFML.Graphics.Sprite(backgroundTexture);
|
||||
var backgroundSize = backgroundTexture.Size;
|
||||
background.Scale = new Vector2f((float)SIZE_X / backgroundSize.X, (float)SIZE_Y / backgroundSize.Y);
|
||||
var background = _resourceCache.GetSprite("ss14_logo_background");
|
||||
background.Scale = new Vector2f((float)SIZE_X / background.TextureRect.Width, (float)SIZE_Y / background.TextureRect.Height);
|
||||
|
||||
var nanotrasenTexture = new Texture(_resourceManager.ContentFileRead(@"Textures/Logo/nanotrasen.png"));
|
||||
var nanotrasen = new SFML.Graphics.Sprite(nanotrasenTexture);
|
||||
var nanotrasenSize = nanotrasenTexture.Size;
|
||||
nanotrasen.Scale = new Vector2f(NT_SIZE_X / nanotrasenSize.X, NT_SIZE_Y / nanotrasenSize.Y);
|
||||
var nanotrasen = _resourceCache.GetSprite("ss14_logo_nt");
|
||||
nanotrasen.Scale = new Vector2f(NT_SIZE_X / nanotrasen.TextureRect.Width, NT_SIZE_Y / nanotrasen.TextureRect.Height);
|
||||
nanotrasen.Position = new Vector2f(SIZE_X - NT_SIZE_X - 5, SIZE_Y - NT_SIZE_Y - 5);
|
||||
nanotrasen.Color = new Color(255, 255, 255, 64);
|
||||
|
||||
@@ -203,17 +323,6 @@ namespace SS14.Client
|
||||
|
||||
#region EventHandlers
|
||||
|
||||
private void CluwneLibIdle(object sender, FrameEventArgs e)
|
||||
{
|
||||
_networkManager.ProcessPackets();
|
||||
_stateManager.Update(e);
|
||||
|
||||
_userInterfaceManager.Update(e);
|
||||
_userInterfaceManager.Render(e);
|
||||
|
||||
_netGrapher.Update();
|
||||
}
|
||||
|
||||
private void MainWindowLoad(object sender, EventArgs e)
|
||||
{
|
||||
_stateManager.RequestStateChange<MainScreen>();
|
||||
@@ -233,7 +342,7 @@ namespace SS14.Client
|
||||
CluwneLib.Stop();
|
||||
}
|
||||
|
||||
#region Input Handling
|
||||
#region Input Handling
|
||||
|
||||
/// <summary>
|
||||
/// Handles any keydown events.
|
||||
@@ -338,11 +447,11 @@ namespace SS14.Client
|
||||
_stateManager.TextEntered(e);
|
||||
}
|
||||
|
||||
#endregion Input Handling
|
||||
#endregion Input Handling
|
||||
|
||||
#endregion EventHandlers
|
||||
#endregion EventHandlers
|
||||
|
||||
#region Privates
|
||||
#region Privates
|
||||
|
||||
bool onetime = true;
|
||||
|
||||
@@ -367,7 +476,6 @@ namespace SS14.Client
|
||||
{
|
||||
//every time the video settings change we close the old screen and create a new one
|
||||
//SetupCluwne Gets called to reset the event handlers to the new screen
|
||||
CluwneLib.FrameEvent += CluwneLibIdle;
|
||||
CluwneLib.RefreshVideoSettings += SetupCluwne;
|
||||
onetime = false;
|
||||
}
|
||||
@@ -389,8 +497,8 @@ namespace SS14.Client
|
||||
IoCManager.Resolve<IKeyBindingManager>().Initialize();
|
||||
}
|
||||
|
||||
#endregion Privates
|
||||
#endregion Privates
|
||||
|
||||
#endregion Methods
|
||||
#endregion Methods
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
using SFML.Graphics;
|
||||
using SFML.Graphics;
|
||||
using OpenTK;
|
||||
using SS14.Client.Graphics.Collection;
|
||||
using SS14.Client.Graphics.States;
|
||||
using SS14.Client.Graphics.Utility;
|
||||
using SS14.Client.Interfaces.Resource;
|
||||
using SS14.Shared;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SS14.Shared.Maths;
|
||||
|
||||
namespace SS14.Client.Graphics.Sprite
|
||||
{
|
||||
@@ -42,25 +45,25 @@ namespace SS14.Client.Graphics.Sprite
|
||||
}
|
||||
}
|
||||
|
||||
public FloatRect AverageAABB
|
||||
public Box2 AverageAABB
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_currentSprite != null)
|
||||
return _averageAABBs[_currentAnimationState.Name][Direction];
|
||||
return new FloatRect();
|
||||
return new Box2();
|
||||
}
|
||||
}
|
||||
|
||||
#region Sprite passthrough methods
|
||||
|
||||
public IntRect AABB
|
||||
public Box2i AABB
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_currentSprite != null)
|
||||
return _currentSprite.TextureRect;
|
||||
return new IntRect();
|
||||
return _currentSprite.TextureRect.Convert();
|
||||
return new Box2i();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +80,7 @@ namespace SS14.Client.Graphics.Sprite
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, Dictionary<Direction, SFML.Graphics.Sprite[]>> _sprites = new Dictionary<string, Dictionary<Direction, SFML.Graphics.Sprite[]>>();
|
||||
|
||||
private readonly Dictionary<string, Dictionary<Direction, FloatRect>> _averageAABBs = new Dictionary<string, Dictionary<Direction, FloatRect>>();
|
||||
private readonly Dictionary<string, Dictionary<Direction, Box2>> _averageAABBs = new Dictionary<string, Dictionary<Direction, Box2>>();
|
||||
private SFML.Graphics.Sprite _currentSprite;
|
||||
|
||||
private Direction _direction = Direction.South;
|
||||
@@ -96,7 +99,7 @@ namespace SS14.Client.Graphics.Sprite
|
||||
_sprites.Add(info.Name, new Dictionary<Direction, SFML.Graphics.Sprite[]>());
|
||||
|
||||
//Because we have a shitload of frames, we're going to store the average size as the AABB for each direction and each animation
|
||||
_averageAABBs.Add(info.Name, new Dictionary<Direction, FloatRect>());
|
||||
_averageAABBs.Add(info.Name, new Dictionary<Direction, Box2>());
|
||||
|
||||
var sprites = _sprites[info.Name];
|
||||
var averageAABBs = _averageAABBs[info.Name];
|
||||
@@ -117,7 +120,7 @@ namespace SS14.Client.Graphics.Sprite
|
||||
h += bounds.Height;
|
||||
t++;
|
||||
}
|
||||
averageAABBs.Add(dir, new FloatRect(x / t, y / t, w / t, h / t));
|
||||
averageAABBs.Add(dir, Box2.FromDimensions(x / t, y / t, w / t, h / t));
|
||||
t = 0;
|
||||
x = 0;
|
||||
y = 0;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using SS14.Client.Interfaces.GameObjects.Components;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.Interfaces.GameObjects.Components;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SS14.Client.GameObjects
|
||||
{
|
||||
@@ -11,32 +10,19 @@ namespace SS14.Client.GameObjects
|
||||
public ClientComponentFactory()
|
||||
{
|
||||
Register<CollidableComponent>();
|
||||
Register<TriggerableComponent>();
|
||||
RegisterReference<CollidableComponent, ICollidableComponent>();
|
||||
Register<IconComponent>();
|
||||
Register<ContextMenuComponent>();
|
||||
Register<KeyBindingInputComponent>();
|
||||
Register<PointLightComponent>();
|
||||
Register<PhysicsComponent>();
|
||||
Register<ColliderComponent>();
|
||||
Register<TransformComponent>();
|
||||
RegisterReference<TransformComponent, ITransformComponent>();
|
||||
RegisterReference<TransformComponent, IClientTransformComponent>();
|
||||
|
||||
Register<DirectionComponent>();
|
||||
RegisterReference<DirectionComponent, IDirectionComponent>();
|
||||
|
||||
Register<BasicMoverComponent>();
|
||||
RegisterReference<BasicMoverComponent, IMoverComponent>();
|
||||
|
||||
Register<SlaveMoverComponent>();
|
||||
RegisterReference<SlaveMoverComponent, IMoverComponent>();
|
||||
|
||||
Register<PlayerInputMoverComponent>();
|
||||
RegisterReference<PlayerInputMoverComponent, IMoverComponent>();
|
||||
|
||||
Register<HitboxComponent>();
|
||||
Register<VelocityComponent>();
|
||||
RegisterReference<VelocityComponent, IVelocityComponent>();
|
||||
Register<BoundingBoxComponent>();
|
||||
|
||||
Register<AnimatedSpriteComponent>();
|
||||
RegisterReference<AnimatedSpriteComponent, IClickTargetComponent>();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using SFML.System;
|
||||
using OpenTK;
|
||||
using SFML.System;
|
||||
using SS14.Client.Interfaces.GameObjects;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
@@ -8,6 +9,7 @@ using SS14.Shared.Maths;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SS14.Shared.Utility;
|
||||
|
||||
namespace SS14.Client.GameObjects
|
||||
{
|
||||
@@ -16,26 +18,106 @@ namespace SS14.Client.GameObjects
|
||||
/// </summary>
|
||||
public class ClientEntityManager : EntityManager, IClientEntityManager
|
||||
{
|
||||
public IEnumerable<IEntity> GetEntitiesInRange(Vector2f position, float Range)
|
||||
public IEnumerable<IEntity> GetEntitiesInRange(Vector2 position, float Range)
|
||||
{
|
||||
Range *= Range; // Square it here to avoid Sqrt
|
||||
return from e in _entities.Values
|
||||
where
|
||||
(position -
|
||||
e.GetComponent<ITransformComponent>().Position).
|
||||
LengthSquared() < Range
|
||||
select e;
|
||||
|
||||
foreach (var entity in _entities.Values)
|
||||
{
|
||||
var transform = entity.GetComponent<ITransformComponent>();
|
||||
var relativePosition = position - transform.Position;
|
||||
if (relativePosition.LengthSquared <= Range)
|
||||
{
|
||||
yield return entity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void InitializeEntities()
|
||||
public IEnumerable<IEntity> GetEntitiesIntersecting(Box2 position)
|
||||
{
|
||||
foreach (var entity in _entities.Values)
|
||||
{
|
||||
if (entity.TryGetComponent<BoundingBoxComponent>(out var component))
|
||||
{
|
||||
if (position.Intersects(component.WorldAABB))
|
||||
yield return entity;
|
||||
}
|
||||
else
|
||||
{
|
||||
var transform = entity.GetComponent<ITransformComponent>();
|
||||
if (position.Contains(transform.Position))
|
||||
{
|
||||
yield return entity;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool AnyEntitiesIntersecting(Box2 position)
|
||||
{
|
||||
foreach (var entity in _entities.Values)
|
||||
{
|
||||
if (entity.TryGetComponent<BoundingBoxComponent>(out var component))
|
||||
{
|
||||
if (position.Intersects(component.WorldAABB))
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
var transform = entity.GetComponent<ITransformComponent>();
|
||||
if (position.Contains(transform.Position))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
if (Initialized)
|
||||
{
|
||||
throw new InvalidOperationException("InitializeEntities() called multiple times");
|
||||
}
|
||||
base.InitializeEntities();
|
||||
InitializeEntities();
|
||||
EntitySystemManager.Initialize();
|
||||
Initialized = true;
|
||||
}
|
||||
|
||||
public void ApplyEntityStates(IEnumerable<EntityState> entityStates, float serverTime)
|
||||
{
|
||||
var entityKeys = new HashSet<int>();
|
||||
foreach (EntityState es in entityStates)
|
||||
{
|
||||
//Todo defer component state result processing until all entities are loaded and initialized...
|
||||
es.ReceivedTime = serverTime;
|
||||
entityKeys.Add(es.StateData.Uid);
|
||||
//Known entities
|
||||
if (_entities.TryGetValue(es.StateData.Uid, out var entity))
|
||||
{
|
||||
entity.HandleEntityState(es);
|
||||
}
|
||||
else //Unknown entities
|
||||
{
|
||||
IEntity newEntity = SpawnEntity(es.StateData.TemplateName, es.StateData.Uid);
|
||||
newEntity.Name = es.StateData.Name;
|
||||
newEntity.HandleEntityState(es);
|
||||
}
|
||||
}
|
||||
|
||||
//Delete entities that exist here but don't exist in the entity states
|
||||
int[] toDelete = _entities.Keys.Where(k => !entityKeys.Contains(k)).ToArray();
|
||||
foreach (int k in toDelete)
|
||||
{
|
||||
DeleteEntity(k);
|
||||
}
|
||||
|
||||
// After the first set of states comes in we do the initialization.
|
||||
if (!Initialized)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
using Lidgren.Network;
|
||||
using NetSerializer;
|
||||
using SS14.Client.Interfaces.Network;
|
||||
using SS14.Shared;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.Interfaces.Configuration;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.Interfaces.Network;
|
||||
using SS14.Shared.Interfaces.Serialization;
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.Network.Messages;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using SS14.Shared.Interfaces.Network;
|
||||
|
||||
namespace SS14.Client.GameObjects
|
||||
{
|
||||
public class ClientEntityNetworkManager : IEntityNetworkManager
|
||||
{
|
||||
[Dependency]
|
||||
private readonly ISS14Serializer serializer;
|
||||
[Dependency]
|
||||
private readonly IClientNetManager _networkManager;
|
||||
|
||||
@@ -40,17 +41,19 @@ namespace SS14.Client.GameObjects
|
||||
NetOutgoingMessage newMsg = CreateEntityMessage();
|
||||
newMsg.Write((byte)EntityMessage.SystemMessage);
|
||||
|
||||
var stream = new MemoryStream();
|
||||
Serializer.Serialize(stream, message);
|
||||
newMsg.Write((int)stream.Length);
|
||||
newMsg.Write(stream.ToArray());
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
serializer.Serialize(stream, message);
|
||||
newMsg.Write((int)stream.Length);
|
||||
newMsg.Write(stream.ToArray());
|
||||
}
|
||||
|
||||
//Send the message
|
||||
_networkManager.ClientSendMessage(newMsg, method);
|
||||
}
|
||||
|
||||
public void SendDirectedComponentNetworkMessage(IEntity sendingEntity, uint netID,
|
||||
NetDeliveryMethod method, NetConnection recipient,
|
||||
NetDeliveryMethod method, INetChannel recipient,
|
||||
params object[] messageParams)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
@@ -185,92 +188,21 @@ namespace SS14.Client.GameObjects
|
||||
/// </summary>
|
||||
/// <param name="message">raw network message</param>
|
||||
/// <returns>An IncomingEntityMessage object</returns>
|
||||
public IncomingEntityMessage HandleEntityNetworkMessage(NetIncomingMessage message)
|
||||
public IncomingEntityMessage HandleEntityNetworkMessage(MsgEntity message)
|
||||
{
|
||||
var messageType = (EntityMessage)message.ReadByte();
|
||||
int uid;
|
||||
IncomingEntityMessage result = IncomingEntityMessage.Null;
|
||||
|
||||
switch (messageType)
|
||||
switch (message.Type)
|
||||
{
|
||||
case EntityMessage.ComponentMessage:
|
||||
uid = message.ReadInt32();
|
||||
IncomingEntityComponentMessage messageContent = HandleEntityComponentNetworkMessage(message);
|
||||
result = new IncomingEntityMessage(uid, EntityMessage.ComponentMessage, messageContent,
|
||||
message.SenderConnection);
|
||||
|
||||
break;
|
||||
return new IncomingEntityMessage(message);
|
||||
case EntityMessage.SystemMessage: //TODO: Not happy with this resolving the entmgr everytime a message comes in.
|
||||
var manager = IoCManager.Resolve<IEntitySystemManager>();
|
||||
manager.HandleSystemMessage(new EntitySystemData(message.SenderConnection, message));
|
||||
manager.HandleSystemMessage(message);
|
||||
break;
|
||||
case EntityMessage.PositionMessage:
|
||||
uid = message.ReadInt32();
|
||||
//TODO: Handle position messages!
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles an incoming entity component message
|
||||
/// </summary>
|
||||
/// <param name="message">Raw network message</param>
|
||||
/// <returns>An IncomingEntityComponentMessage object</returns>
|
||||
public IncomingEntityComponentMessage HandleEntityComponentNetworkMessage(NetIncomingMessage message)
|
||||
{
|
||||
var netID = message.ReadUInt32();
|
||||
var messageParams = new List<object>();
|
||||
while (message.Position < message.LengthBits)
|
||||
{
|
||||
switch ((NetworkDataType)message.ReadByte())
|
||||
{
|
||||
case NetworkDataType.d_enum:
|
||||
messageParams.Add(message.ReadInt32());
|
||||
break;
|
||||
case NetworkDataType.d_bool:
|
||||
messageParams.Add(message.ReadBoolean());
|
||||
break;
|
||||
case NetworkDataType.d_byte:
|
||||
messageParams.Add(message.ReadByte());
|
||||
break;
|
||||
case NetworkDataType.d_sbyte:
|
||||
messageParams.Add(message.ReadSByte());
|
||||
break;
|
||||
case NetworkDataType.d_ushort:
|
||||
messageParams.Add(message.ReadUInt16());
|
||||
break;
|
||||
case NetworkDataType.d_short:
|
||||
messageParams.Add(message.ReadInt16());
|
||||
break;
|
||||
case NetworkDataType.d_int:
|
||||
messageParams.Add(message.ReadInt32());
|
||||
break;
|
||||
case NetworkDataType.d_uint:
|
||||
messageParams.Add(message.ReadUInt32());
|
||||
break;
|
||||
case NetworkDataType.d_ulong:
|
||||
messageParams.Add(message.ReadUInt64());
|
||||
break;
|
||||
case NetworkDataType.d_long:
|
||||
messageParams.Add(message.ReadInt64());
|
||||
break;
|
||||
case NetworkDataType.d_float:
|
||||
messageParams.Add(message.ReadFloat());
|
||||
break;
|
||||
case NetworkDataType.d_double:
|
||||
messageParams.Add(message.ReadDouble());
|
||||
break;
|
||||
case NetworkDataType.d_string:
|
||||
messageParams.Add(message.ReadString());
|
||||
break;
|
||||
case NetworkDataType.d_byteArray:
|
||||
int length = message.ReadInt32();
|
||||
messageParams.Add(message.ReadBytes(length));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return new IncomingEntityComponentMessage(netID, messageParams);
|
||||
return null;
|
||||
}
|
||||
|
||||
#endregion Receiving
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
using System;
|
||||
using SS14.Shared;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.Reflection;
|
||||
|
||||
namespace SS14.Client.GameObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Sub type of <see cref="Component"/> that handles some client-specific things.
|
||||
/// </summary>
|
||||
[Reflect(false)]
|
||||
public abstract class ClientComponent : Component
|
||||
{
|
||||
public override ComponentReplyMessage ReceiveMessage(object sender, ComponentMessageType type,
|
||||
params object[] list)
|
||||
{
|
||||
ComponentReplyMessage reply = base.ReceiveMessage(sender, type, list);
|
||||
|
||||
if (sender == this) //Don't listen to our own messages!
|
||||
return reply;
|
||||
|
||||
if (type == ComponentMessageType.Initialize)
|
||||
{
|
||||
SendComponentInstantiationMessage();
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
public override void OnAdd(IEntity owner)
|
||||
{
|
||||
base.OnAdd(owner);
|
||||
if (Owner.Initialized)
|
||||
{
|
||||
SendComponentInstantiationMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Client message to server saying component has been instantiated and needs initial data
|
||||
/// </summary>
|
||||
[Obsolete("Getting rid of this messaging paradigm.")]
|
||||
public void SendComponentInstantiationMessage()
|
||||
{
|
||||
if (NetID == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var manager = IoCManager.Resolve<IEntityNetworkManager>();
|
||||
manager.SendEntityNetworkMessage(
|
||||
Owner,
|
||||
EntityMessage.ComponentInstantiationMessage,
|
||||
NetID.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,231 +0,0 @@
|
||||
using Lidgren.Network;
|
||||
using SFML.Graphics;
|
||||
using SS14.Client.Interfaces.Collision;
|
||||
using SS14.Client.Interfaces.GameObjects;
|
||||
using SS14.Client.Interfaces.Map;
|
||||
using SS14.Shared;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.GameObjects.Components;
|
||||
using SS14.Shared.GameObjects.Components.Collidable;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.Interfaces.GameObjects.Components;
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.Maths;
|
||||
using SS14.Shared.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
|
||||
namespace SS14.Client.GameObjects
|
||||
{
|
||||
public class CollidableComponent : ClientComponent, ICollidable
|
||||
{
|
||||
public override string Name => "Collidable";
|
||||
public override uint? NetID => NetIDs.COLLIDABLE;
|
||||
|
||||
public SFML.Graphics.Color DebugColor { get; set; } = Color.Red;
|
||||
|
||||
private bool collisionEnabled = true;
|
||||
private FloatRect currentAABB;
|
||||
protected bool isHardCollidable = true;
|
||||
|
||||
public override Type StateType => typeof(CollidableComponentState);
|
||||
|
||||
/// <summary>
|
||||
/// X - Top | Y - Right | Z - Bottom | W - Left
|
||||
/// </summary>
|
||||
private Vector4f TweakAABB { get; set; } = new Vector4f(0, 0, 0, 0);
|
||||
|
||||
private FloatRect OffsetAABB
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Owner.TryGetComponent<ITransformComponent>(out var ownerTransform))
|
||||
{
|
||||
return
|
||||
new FloatRect(
|
||||
currentAABB.Left +
|
||||
ownerTransform.Position.X -
|
||||
(currentAABB.Width / 2) + TweakAABB.W,
|
||||
currentAABB.Top +
|
||||
ownerTransform.Position.Y -
|
||||
(currentAABB.Height / 2) + TweakAABB.X,
|
||||
currentAABB.Width - (TweakAABB.W - TweakAABB.Y),
|
||||
currentAABB.Height - (TweakAABB.X - TweakAABB.Z));
|
||||
}
|
||||
else
|
||||
{
|
||||
return new FloatRect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region ICollidable Members
|
||||
|
||||
public FloatRect AABB
|
||||
{
|
||||
get { return OffsetAABB; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the collidable is bumped into by someone/something
|
||||
/// </summary>
|
||||
public void Bump(IEntity ent)
|
||||
{
|
||||
OnBump?.Invoke(this, new EventArgs());
|
||||
|
||||
Owner.SendMessage(this, ComponentMessageType.Bumped, ent);
|
||||
Owner.SendComponentNetworkMessage(this, NetDeliveryMethod.ReliableUnordered, ComponentMessageType.Bumped,
|
||||
ent.Uid);
|
||||
}
|
||||
|
||||
public bool IsHardCollidable
|
||||
{
|
||||
get { return isHardCollidable; }
|
||||
}
|
||||
|
||||
#endregion ICollidable Members
|
||||
|
||||
public event EventHandler OnBump;
|
||||
|
||||
/// <summary>
|
||||
/// OnAdd override -- gets the AABB from the sprite component and sends it to the collision manager.
|
||||
/// </summary>
|
||||
/// <param name="owner"></param>
|
||||
public override void OnAdd(IEntity owner)
|
||||
{
|
||||
base.OnAdd(owner);
|
||||
GetAABB();
|
||||
var cm = IoCManager.Resolve<ICollisionManager>();
|
||||
cm.AddCollidable(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnRemove override -- removes the AABB from the collisionmanager.
|
||||
/// </summary>
|
||||
public override void OnRemove()
|
||||
{
|
||||
var cm = IoCManager.Resolve<ICollisionManager>();
|
||||
cm.RemoveCollidable(this);
|
||||
|
||||
base.OnRemove();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Message handler --
|
||||
/// SpriteChanged means the spritecomponent changed the current sprite.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="reply"></param>
|
||||
/// <param name="list"></param>
|
||||
public override ComponentReplyMessage ReceiveMessage(object sender, ComponentMessageType type,
|
||||
params object[] list)
|
||||
{
|
||||
ComponentReplyMessage reply = base.ReceiveMessage(sender, type, list);
|
||||
|
||||
if (sender == this) //Don't listen to our own messages!
|
||||
return ComponentReplyMessage.Empty;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case ComponentMessageType.SpriteChanged:
|
||||
if (collisionEnabled)
|
||||
{
|
||||
GetAABB();
|
||||
var cm = IoCManager.Resolve<ICollisionManager>();
|
||||
cm.UpdateCollidable(this);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parameter Setting
|
||||
/// Settable params:
|
||||
/// TweakAABB - Vector4
|
||||
/// </summary>
|
||||
public override void LoadParameters(YamlMappingNode mapping)
|
||||
{
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
YamlNode node;
|
||||
if (mapping.TryGetNode("tweakAABB", out node))
|
||||
{
|
||||
TweakAABB = node.AsVector4f() / mapManager.TileSize;
|
||||
}
|
||||
|
||||
if (mapping.TryGetNode("TweakAABBtop", out node))
|
||||
{
|
||||
TweakAABB = new Vector4f(node.AsFloat() / mapManager.TileSize, TweakAABB.Y, TweakAABB.Z, TweakAABB.W);
|
||||
}
|
||||
|
||||
if (mapping.TryGetNode("TweakAABBright", out node))
|
||||
{
|
||||
TweakAABB = new Vector4f(TweakAABB.X, node.AsFloat() / mapManager.TileSize, TweakAABB.Z, TweakAABB.W);
|
||||
}
|
||||
|
||||
if (mapping.TryGetNode("TweakAABBbottom", out node))
|
||||
{
|
||||
TweakAABB = new Vector4f(TweakAABB.X, TweakAABB.Y, node.AsFloat() / mapManager.TileSize, TweakAABB.W);
|
||||
}
|
||||
|
||||
if (mapping.TryGetNode("TweakAABBleft", out node))
|
||||
{
|
||||
TweakAABB = new Vector4f(TweakAABB.X, TweakAABB.Y, TweakAABB.Z, node.AsFloat() / mapManager.TileSize);
|
||||
}
|
||||
|
||||
if (mapping.TryGetNode("DebugColor", out node))
|
||||
{
|
||||
DebugColor = ColorUtils.FromHex(node.AsString(), Color.Red);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enables collidable
|
||||
/// </summary>
|
||||
private void EnableCollision()
|
||||
{
|
||||
collisionEnabled = true;
|
||||
var cm = IoCManager.Resolve<ICollisionManager>();
|
||||
cm.AddCollidable(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disables Collidable
|
||||
/// </summary>
|
||||
private void DisableCollision()
|
||||
{
|
||||
collisionEnabled = false;
|
||||
var cm = IoCManager.Resolve<ICollisionManager>();
|
||||
cm.RemoveCollidable(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current AABB from the sprite component.
|
||||
/// </summary>
|
||||
private void GetAABB()
|
||||
{
|
||||
var component = Owner.GetComponent<ISpriteRenderableComponent>();
|
||||
var tileSize = IoCManager.Resolve<IMapManager>().TileSize;
|
||||
|
||||
currentAABB = new FloatRect(
|
||||
component.AABB.Left / tileSize,
|
||||
component.AABB.Top / tileSize,
|
||||
component.AABB.Width / tileSize,
|
||||
component.AABB.Height / tileSize);
|
||||
}
|
||||
|
||||
public override void HandleComponentState(dynamic state)
|
||||
{
|
||||
if (state.CollisionEnabled != collisionEnabled)
|
||||
{
|
||||
if (state.CollisionEnabled)
|
||||
EnableCollision();
|
||||
else
|
||||
DisableCollision();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using SS14.Shared.GameObjects.Components;
|
||||
|
||||
namespace SS14.Client.GameObjects
|
||||
{
|
||||
public class TriggerableComponent : CollidableComponent
|
||||
{
|
||||
public override string Name => "Triggerable";
|
||||
public override uint? NetID => NetIDs.TRIGGERABLE;
|
||||
public TriggerableComponent()
|
||||
{
|
||||
isHardCollidable = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
using SFML.Graphics;
|
||||
using SFML.System;
|
||||
using SS14.Client.Interfaces.Collision;
|
||||
using SS14.Client.Interfaces.GameObjects;
|
||||
using SS14.Shared;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.GameObjects.Components;
|
||||
using SS14.Shared.Interfaces.GameObjects.Components;
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.Utility;
|
||||
using System.Collections.Generic;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
|
||||
namespace SS14.Client.GameObjects
|
||||
{
|
||||
public class ColliderComponent : ClientComponent
|
||||
{
|
||||
public override string Name => "Collider";
|
||||
public override uint? NetID => NetIDs.COLLIDER;
|
||||
public SFML.Graphics.Color DebugColor { get; set; } = Color.Blue;
|
||||
|
||||
private FloatRect AABB
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Owner.HasComponent<HitboxComponent>())
|
||||
{
|
||||
return Owner.GetComponent<HitboxComponent>().AABB;
|
||||
}
|
||||
else if (Owner.HasComponent<IRenderableComponent>())
|
||||
{
|
||||
return Owner.GetComponent<IRenderableComponent>().AverageAABB;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new FloatRect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public FloatRect WorldAABB
|
||||
{
|
||||
get
|
||||
{
|
||||
var trans = Owner.GetComponent<ITransformComponent>();
|
||||
if (trans == null)
|
||||
{
|
||||
return AABB;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new FloatRect(
|
||||
AABB.Left + trans.X,
|
||||
AABB.Top + trans.Y,
|
||||
AABB.Width,
|
||||
AABB.Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryCollision(Vector2f offset, bool bump = false)
|
||||
{
|
||||
return IoCManager.Resolve<ICollisionManager>().TryCollide(Owner, offset, bump);
|
||||
}
|
||||
|
||||
public override void LoadParameters(YamlMappingNode mapping)
|
||||
{
|
||||
YamlNode node;
|
||||
if (mapping.TryGetNode("debugColor", out node))
|
||||
{
|
||||
DebugColor = node.AsHexColor(Color.Blue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
using SFML.System;
|
||||
using SS14.Shared;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.GameObjects.Components;
|
||||
using SS14.Shared.GameObjects.Components.Direction;
|
||||
using SS14.Shared.Maths;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.Interfaces.GameObjects.Components;
|
||||
using SS14.Shared.IoC;
|
||||
using System;
|
||||
|
||||
namespace SS14.Client.GameObjects
|
||||
{
|
||||
public class DirectionComponent : ClientComponent, IDirectionComponent
|
||||
{
|
||||
public override string Name => "Direction";
|
||||
public override uint? NetID => NetIDs.DIRECTION;
|
||||
private Direction _lastDeterminedDirection = Direction.South;
|
||||
public Direction Direction { get; set; } = Direction.South;
|
||||
|
||||
public override Type StateType => typeof(DirectionComponentState);
|
||||
|
||||
public override void OnAdd(IEntity owner)
|
||||
{
|
||||
base.OnAdd(owner);
|
||||
owner.GetComponent<ITransformComponent>().OnMove += HandleOnMove;
|
||||
}
|
||||
|
||||
public override void OnRemove()
|
||||
{
|
||||
Owner.GetComponent<ITransformComponent>().OnMove -= HandleOnMove;
|
||||
base.OnRemove();
|
||||
}
|
||||
|
||||
public void HandleOnMove(object sender, VectorEventArgs args)
|
||||
{
|
||||
if (!Owner.HasComponent<PlayerInputMoverComponent>())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.VectorFrom == args.VectorTo)
|
||||
return;
|
||||
SetMoveDir(DetermineDirection(args.VectorFrom, args.VectorTo));
|
||||
}
|
||||
|
||||
private Direction DetermineDirection(Vector2f from, Vector2f to)
|
||||
{
|
||||
Vector2f delta = to - from;
|
||||
if (delta.Length() < 0.1)
|
||||
{
|
||||
return _lastDeterminedDirection;
|
||||
}
|
||||
|
||||
_lastDeterminedDirection = from.DirectionTo(to, fallback: _lastDeterminedDirection);
|
||||
return _lastDeterminedDirection;
|
||||
}
|
||||
|
||||
private void SetMoveDir(Direction movedir)
|
||||
{
|
||||
Direction = movedir;
|
||||
Owner.SendMessage(this, ComponentMessageType.MoveDirection, movedir);
|
||||
}
|
||||
|
||||
public override void HandleComponentState(dynamic state)
|
||||
{
|
||||
var dir = (Direction)state.Direction;
|
||||
SetMoveDir(dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
using SFML.Graphics;
|
||||
using SFML.System;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.GameObjects.Components;
|
||||
using SS14.Shared.GameObjects.Components.Hitbox;
|
||||
using SS14.Shared.IoC;
|
||||
using System;
|
||||
|
||||
namespace SS14.Client.GameObjects
|
||||
{
|
||||
public class HitboxComponent : ClientComponent
|
||||
{
|
||||
public override string Name => "Hitbox";
|
||||
public override uint? NetID => NetIDs.HITBOX;
|
||||
public FloatRect AABB { get; set; }
|
||||
public Vector2f Size
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Vector2f(AABB.Width, AABB.Height);
|
||||
}
|
||||
set
|
||||
{
|
||||
AABB = new FloatRect(
|
||||
AABB.Left + (AABB.Width - value.X),
|
||||
AABB.Top + (AABB.Height - value.Y),
|
||||
value.X,
|
||||
value.Y
|
||||
);
|
||||
}
|
||||
}
|
||||
public Vector2f Offset
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Vector2f(AABB.Left + AABB.Width / 2f, AABB.Top + AABB.Height / 2f);
|
||||
}
|
||||
set
|
||||
{
|
||||
AABB = new FloatRect(
|
||||
value.X - AABB.Width / 2f,
|
||||
value.Y - AABB.Height / 2f,
|
||||
AABB.Width,
|
||||
AABB.Height
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public HitboxComponent()
|
||||
{
|
||||
Size = new Vector2f();
|
||||
Offset = new Vector2f();
|
||||
}
|
||||
|
||||
public override Type StateType
|
||||
{
|
||||
get
|
||||
{
|
||||
return typeof(HitboxComponentState);
|
||||
}
|
||||
}
|
||||
|
||||
public override void HandleComponentState(dynamic state)
|
||||
{
|
||||
AABB = state.AABB;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
using Lidgren.Network;
|
||||
using SFML.System;
|
||||
using SS14.Client.Interfaces.Lighting;
|
||||
using SS14.Shared;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.GameObjects.Components;
|
||||
using SS14.Shared.GameObjects.Components.Light;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.Interfaces.GameObjects.Components;
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
|
||||
namespace SS14.Client.GameObjects
|
||||
{
|
||||
public class PointLightComponent : ClientComponent
|
||||
{
|
||||
public override string Name => "PointLight";
|
||||
public override uint? NetID => NetIDs.POINT_LIGHT;
|
||||
//Contains a standard light
|
||||
public ILight _light;
|
||||
public Vector3f _lightColor = new Vector3f(190, 190, 190);
|
||||
public Vector2f _lightOffset = new Vector2f(0, 0);
|
||||
public int _lightRadius = 512;
|
||||
protected string _mask = "";
|
||||
public LightModeClass _mode = LightModeClass.Constant;
|
||||
|
||||
public override Type StateType => typeof(PointLightComponentState);
|
||||
|
||||
//When added, set up the light.
|
||||
public override void OnAdd(IEntity owner)
|
||||
{
|
||||
base.OnAdd(owner);
|
||||
|
||||
_light = IoCManager.Resolve<ILightManager>().CreateLight();
|
||||
IoCManager.Resolve<ILightManager>().AddLight(_light);
|
||||
|
||||
_light.SetRadius(_lightRadius);
|
||||
_light.SetColor(255, (int)_lightColor.X, (int)_lightColor.Y, (int)_lightColor.Z);
|
||||
_light.Move(Owner.GetComponent<ITransformComponent>().Position + _lightOffset);
|
||||
_light.SetMask(_mask);
|
||||
Owner.GetComponent<ITransformComponent>().OnMove += OnMove;
|
||||
}
|
||||
|
||||
public override void LoadParameters(YamlMappingNode mapping)
|
||||
{
|
||||
YamlNode node;
|
||||
if (mapping.TryGetNode("lightoffsetx", out node))
|
||||
{
|
||||
_lightOffset.X = node.AsFloat();
|
||||
}
|
||||
|
||||
if (mapping.TryGetNode("lightoffsety", out node))
|
||||
{
|
||||
_lightOffset.Y = node.AsFloat();
|
||||
}
|
||||
|
||||
if (mapping.TryGetNode("lightradius", out node))
|
||||
{
|
||||
_lightRadius = node.AsInt();
|
||||
}
|
||||
|
||||
if (mapping.TryGetNode("lightColorR", out node))
|
||||
{
|
||||
_lightColor.X = node.AsInt();
|
||||
}
|
||||
|
||||
if (mapping.TryGetNode("lightColorG", out node))
|
||||
{
|
||||
_lightColor.Y = node.AsInt();
|
||||
}
|
||||
|
||||
if (mapping.TryGetNode("lightColorB", out node))
|
||||
{
|
||||
_lightColor.Z = node.AsInt();
|
||||
}
|
||||
|
||||
if (mapping.TryGetNode("mask", out node))
|
||||
{
|
||||
_mask = node.AsString();
|
||||
}
|
||||
}
|
||||
|
||||
protected void SetState(LightState state)
|
||||
{
|
||||
_light.SetState(state);
|
||||
}
|
||||
|
||||
protected void SetMode(LightModeClass mode)
|
||||
{
|
||||
IoCManager.Resolve<ILightManager>().SetLightMode(mode, _light);
|
||||
}
|
||||
|
||||
public override void OnRemove()
|
||||
{
|
||||
Owner.GetComponent<ITransformComponent>().OnMove -= OnMove;
|
||||
IoCManager.Resolve<ILightManager>().RemoveLight(_light);
|
||||
base.OnRemove();
|
||||
}
|
||||
|
||||
private void OnMove(object sender, VectorEventArgs args)
|
||||
{
|
||||
_light.Move(Owner.GetComponent<ITransformComponent>().Position + _lightOffset);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
_light.Update(frameTime);
|
||||
}
|
||||
|
||||
protected void SetMask(string mask)
|
||||
{
|
||||
_light.SetMask(mask);
|
||||
}
|
||||
|
||||
public override void HandleComponentState(dynamic state)
|
||||
{
|
||||
if (_light.LightState != state.State)
|
||||
_light.SetState(state.State);
|
||||
if (_light.Color.R != state.ColorR || _light.Color.G != state.ColorG || _light.Color.B != state.ColorB)
|
||||
{
|
||||
SetColor(state.ColorR, state.ColorG, state.ColorB);
|
||||
}
|
||||
if (_mode != state.Mode)
|
||||
SetMode(state.Mode);
|
||||
}
|
||||
|
||||
protected void SetColor(int R, int G, int B)
|
||||
{
|
||||
_lightColor.X = R;
|
||||
_lightColor.Y = G;
|
||||
_lightColor.Z = B;
|
||||
_light.SetColor(255, R, G, B);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
using SFML.System;
|
||||
using SS14.Client.Interfaces.GameObjects;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.GameObjects.Components;
|
||||
using SS14.Shared.GameObjects.Components.Mover;
|
||||
using SS14.Shared.Interfaces.GameObjects.Components;
|
||||
using SS14.Shared.IoC;
|
||||
using System;
|
||||
|
||||
namespace SS14.Client.GameObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Receives movement data from the server and updates the entity's position accordingly.
|
||||
/// </summary>
|
||||
public class BasicMoverComponent : ClientComponent, IMoverComponent
|
||||
{
|
||||
public override string Name => "BasicMover";
|
||||
public override uint? NetID => NetIDs.BASIC_MOVER;
|
||||
public override bool NetworkSynchronizeExistence => true;
|
||||
|
||||
private bool interpolating;
|
||||
private float movedtime; // Amount of time we've been moving since the last update packet.
|
||||
private const float movetime = 0.05f; // Milliseconds it should take to move.
|
||||
private Vector2f startPosition;
|
||||
private Vector2f targetPosition;
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
if (interpolating)
|
||||
{
|
||||
movedtime = movedtime + frameTime;
|
||||
if (movedtime >= movetime)
|
||||
{
|
||||
Owner.GetComponent<ITransformComponent>().Position = targetPosition;
|
||||
startPosition = targetPosition;
|
||||
interpolating = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
float X = Ease(movedtime, startPosition.X, targetPosition.X, movetime);
|
||||
float Y = Ease(movedtime, startPosition.Y, targetPosition.Y, movetime);
|
||||
Owner.GetComponent<ITransformComponent>().Position = new Vector2f(X, Y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a float position eased from a start position to an end position.
|
||||
/// </summary>
|
||||
/// <param name="time">elapsed time since the start of the easing</param>
|
||||
/// <param name="start">start position</param>
|
||||
/// <param name="end">end position</param>
|
||||
/// <param name="duration">duration of the movement</param>
|
||||
/// <returns>current position</returns>
|
||||
private float Ease(float time, float start, float end, float duration = 1) // duration is in ms.
|
||||
{
|
||||
time = time / duration; // - 1;
|
||||
return time * (end - start) + start;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,183 +0,0 @@
|
||||
using Lidgren.Network;
|
||||
using SFML.System;
|
||||
using SS14.Client.Interfaces.GameObjects;
|
||||
using SS14.Shared;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.GameObjects.Components;
|
||||
using SS14.Shared.Interfaces.GameObjects.Components;
|
||||
using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Client.GameObjects
|
||||
{
|
||||
//Moves an entity based on key binding input
|
||||
public class PlayerInputMoverComponent : ClientComponent, IMoverComponent
|
||||
{
|
||||
public override string Name => "PlayerInputMover";
|
||||
public override uint? NetID => NetIDs.PLAYER_INPUT_MOVER;
|
||||
public override bool NetworkSynchronizeExistence => true;
|
||||
|
||||
private const float BaseMoveSpeed = Constants.HumanWalkSpeed;
|
||||
public const float FastMoveSpeed = Constants.HumanRunSpeed;
|
||||
private const float MoveRateLimit = .06666f; // 15 movements allowed to be sent to the server per second.
|
||||
|
||||
private float _currentMoveSpeed = BaseMoveSpeed;
|
||||
|
||||
private bool _moveDown;
|
||||
private bool _moveLeft;
|
||||
private bool _moveRight;
|
||||
private float _moveTimeCache;
|
||||
private bool _moveUp;
|
||||
public bool ShouldSendPositionUpdate;
|
||||
|
||||
private Vector2f Velocity
|
||||
{
|
||||
get => Owner.GetComponent<IVelocityComponent>().Velocity;
|
||||
set => Owner.GetComponent<IVelocityComponent>().Velocity = value;
|
||||
}
|
||||
|
||||
public override void HandleNetworkMessage(IncomingEntityComponentMessage message, NetConnection sender)
|
||||
{
|
||||
/*var x = (float)message.MessageParameters[0];
|
||||
var y = (float)message.MessageParameters[1];
|
||||
if((bool)message.MessageParameters[2]) //"forced" parameter -- if true forces position update
|
||||
PlainTranslate((float)x, (float)y);*/
|
||||
}
|
||||
|
||||
public override ComponentReplyMessage ReceiveMessage(object sender, ComponentMessageType type,
|
||||
params object[] list)
|
||||
{
|
||||
ComponentReplyMessage reply = base.ReceiveMessage(sender, type, list);
|
||||
|
||||
if (sender == this) //Don't listen to our own messages!
|
||||
return ComponentReplyMessage.Empty;
|
||||
switch (type)
|
||||
{
|
||||
case ComponentMessageType.BoundKeyChange:
|
||||
HandleKeyChange(list);
|
||||
break;
|
||||
}
|
||||
return reply;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles a changed keystate message
|
||||
/// </summary>
|
||||
/// <param name="list">0 - Function, 1 - Key State</param>
|
||||
private void HandleKeyChange(params object[] list)
|
||||
{
|
||||
var function = (BoundKeyFunctions)list[0];
|
||||
var state = (BoundKeyState)list[1];
|
||||
bool setting = state == BoundKeyState.Down;
|
||||
|
||||
ShouldSendPositionUpdate = true;
|
||||
/*if (state == BoundKeyState.Up)
|
||||
SendPositionUpdate(Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position);*/
|
||||
// Send a position update so that the server knows what position the client ended at.
|
||||
|
||||
if (function == BoundKeyFunctions.MoveDown)
|
||||
_moveDown = setting;
|
||||
if (function == BoundKeyFunctions.MoveUp)
|
||||
_moveUp = setting;
|
||||
if (function == BoundKeyFunctions.MoveLeft)
|
||||
_moveLeft = setting;
|
||||
if (function == BoundKeyFunctions.MoveRight)
|
||||
_moveRight = setting;
|
||||
if (function == BoundKeyFunctions.Run)
|
||||
{
|
||||
_currentMoveSpeed = setting ? FastMoveSpeed : BaseMoveSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update function. Processes currently pressed keys and does shit etc.
|
||||
/// </summary>
|
||||
/// <param name="frameTime"></param>
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
_moveTimeCache += frameTime;
|
||||
|
||||
base.Update(frameTime);
|
||||
|
||||
if (_moveUp && !_moveLeft && !_moveRight && !_moveDown) // Move Up
|
||||
{
|
||||
Velocity = new Vector2f(0, -1) * _currentMoveSpeed;
|
||||
}
|
||||
else if (_moveDown && !_moveLeft && !_moveRight && !_moveUp) // Move Down
|
||||
{
|
||||
Velocity = new Vector2f(0, 1) * _currentMoveSpeed;
|
||||
}
|
||||
else if (_moveLeft && !_moveRight && !_moveUp && !_moveDown) // Move Left
|
||||
{
|
||||
Velocity = new Vector2f(-1, 0) * _currentMoveSpeed;
|
||||
}
|
||||
else if (_moveRight && !_moveLeft && !_moveUp && !_moveDown) // Move Right
|
||||
{
|
||||
Velocity = new Vector2f(1, 0) * _currentMoveSpeed;
|
||||
}
|
||||
else if (_moveUp && _moveRight && !_moveLeft && !_moveDown) // Move Up & Right
|
||||
{
|
||||
Velocity = new Vector2f(0.7071f, -0.7071f) * _currentMoveSpeed;
|
||||
}
|
||||
else if (_moveUp && _moveLeft && !_moveRight && !_moveDown) // Move Up & Left
|
||||
{
|
||||
Velocity = new Vector2f(-0.7071f, -0.7071f) * _currentMoveSpeed;
|
||||
}
|
||||
else if (_moveDown && _moveRight && !_moveLeft && !_moveUp) // Move Down & Right
|
||||
{
|
||||
Velocity = new Vector2f(0.7071f, 0.7071f) * _currentMoveSpeed;
|
||||
}
|
||||
else if (_moveDown && _moveLeft && !_moveRight && !_moveUp) // Move Down & Left
|
||||
{
|
||||
Velocity = new Vector2f(-0.7071f, 0.7071f) * _currentMoveSpeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
Velocity = new Vector2f(0f, 0f);
|
||||
}
|
||||
|
||||
/*Vector2 translationVector = Velocity*frameTime;
|
||||
var velcomp = Owner.GetComponent<VelocityComponent>(ComponentFamily.Velocity);
|
||||
|
||||
bool translated = TryTranslate(translationVector, false); //Only bump once...
|
||||
bool translatedx = false, translatedy = false;
|
||||
if (!translated)
|
||||
translatedx = TryTranslate(new Vector2(translationVector.X, 0), true);
|
||||
if (!translated && !translatedx)
|
||||
translatedy = TryTranslate(new Vector2(0, translationVector.Y), true);
|
||||
|
||||
if (!translated)
|
||||
{
|
||||
if (!translatedx)
|
||||
{
|
||||
velcomp.Velocity = new Vector2(0, velcomp.Velocity.Y);
|
||||
}
|
||||
if (!translatedy)
|
||||
velcomp.Velocity = new Vector2(velcomp.Velocity.X, 0);
|
||||
if (!translatedx && !translatedy)
|
||||
velcomp.Velocity = Vector2.Zero;
|
||||
|
||||
translationVector = new Vector2(translatedx?translationVector.X:0, translatedy?translationVector.Y:0);
|
||||
}
|
||||
|
||||
if (_moveTimeCache >= MoveRateLimit)
|
||||
{
|
||||
var nextPosition = Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position + translationVector;
|
||||
|
||||
SendPositionUpdate(nextPosition);
|
||||
|
||||
_moveTimeCache = 0;
|
||||
}*/
|
||||
}
|
||||
|
||||
public virtual void SendPositionUpdate(Vector2f nextPosition)
|
||||
{
|
||||
var velocity = Owner.GetComponent<IVelocityComponent>();
|
||||
Owner.SendComponentNetworkMessage(this,
|
||||
NetDeliveryMethod.ReliableUnordered,
|
||||
nextPosition.X,
|
||||
nextPosition.Y,
|
||||
velocity.Velocity.X,
|
||||
velocity.Velocity.Y);
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user