misc optimization & refactoring
This commit is contained in:
@@ -0,0 +1,108 @@
|
|||||||
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace Hyper.ComponentModel {
|
||||||
|
public abstract class ChainingPropertyDescriptor : PropertyDescriptor {
|
||||||
|
private readonly PropertyDescriptor _root;
|
||||||
|
protected PropertyDescriptor Root { get { return _root; } }
|
||||||
|
protected ChainingPropertyDescriptor(PropertyDescriptor root)
|
||||||
|
: base(root) {
|
||||||
|
_root = root;
|
||||||
|
}
|
||||||
|
public override void AddValueChanged(object component, EventHandler handler) {
|
||||||
|
Root.AddValueChanged(component, handler);
|
||||||
|
}
|
||||||
|
public override AttributeCollection Attributes {
|
||||||
|
get {
|
||||||
|
return Root.Attributes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override bool CanResetValue(object component) {
|
||||||
|
return Root.CanResetValue(component);
|
||||||
|
}
|
||||||
|
public override string Category {
|
||||||
|
get {
|
||||||
|
return Root.Category;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override Type ComponentType {
|
||||||
|
get { return Root.ComponentType; }
|
||||||
|
}
|
||||||
|
public override TypeConverter Converter {
|
||||||
|
get {
|
||||||
|
return Root.Converter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override string Description {
|
||||||
|
get {
|
||||||
|
return Root.Description;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override bool DesignTimeOnly {
|
||||||
|
get {
|
||||||
|
return Root.DesignTimeOnly;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override string DisplayName {
|
||||||
|
get {
|
||||||
|
return Root.DisplayName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override bool Equals(object obj) {
|
||||||
|
return Root.Equals(obj);
|
||||||
|
}
|
||||||
|
public override PropertyDescriptorCollection GetChildProperties(object instance, Attribute[] filter) {
|
||||||
|
return Root.GetChildProperties(instance, filter);
|
||||||
|
}
|
||||||
|
public override object GetEditor(Type editorBaseType) {
|
||||||
|
return Root.GetEditor(editorBaseType);
|
||||||
|
}
|
||||||
|
public override int GetHashCode() {
|
||||||
|
return Root.GetHashCode();
|
||||||
|
}
|
||||||
|
public override object GetValue(object component) {
|
||||||
|
return Root.GetValue(component);
|
||||||
|
}
|
||||||
|
public override bool IsBrowsable {
|
||||||
|
get {
|
||||||
|
return Root.IsBrowsable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override bool IsLocalizable {
|
||||||
|
get {
|
||||||
|
return Root.IsLocalizable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override bool IsReadOnly {
|
||||||
|
get { return Root.IsReadOnly; }
|
||||||
|
}
|
||||||
|
public override string Name {
|
||||||
|
get {
|
||||||
|
return Root.Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override Type PropertyType {
|
||||||
|
get { return Root.PropertyType; }
|
||||||
|
}
|
||||||
|
public override void RemoveValueChanged(object component, EventHandler handler) {
|
||||||
|
Root.RemoveValueChanged(component, handler);
|
||||||
|
}
|
||||||
|
public override void ResetValue(object component) {
|
||||||
|
Root.ResetValue(component);
|
||||||
|
}
|
||||||
|
public override void SetValue(object component, object value) {
|
||||||
|
Root.SetValue(component, value);
|
||||||
|
}
|
||||||
|
public override bool ShouldSerializeValue(object component) {
|
||||||
|
return Root.ShouldSerializeValue(component);
|
||||||
|
}
|
||||||
|
public override bool SupportsChangeEvents {
|
||||||
|
get {
|
||||||
|
return Root.SupportsChangeEvents;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override string ToString() {
|
||||||
|
return Root.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProductVersion>8.0.50727</ProductVersion>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
<ProjectGuid>{954502B1-7282-417D-9310-3332962A1CA1}</ProjectGuid>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>HyperPropertyDescriptor</RootNamespace>
|
||||||
|
<AssemblyName>HyperPropertyDescriptor</AssemblyName>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="ChainingPropertyDescriptor.cs" />
|
||||||
|
<Compile Include="HyperTypeDescriptionProvider.cs" />
|
||||||
|
<Compile Include="HyperTypeDescriptor.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
<Target Name="BeforeBuild">
|
||||||
|
</Target>
|
||||||
|
<Target Name="AfterBuild">
|
||||||
|
</Target>
|
||||||
|
-->
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<ProjectView>ShowAllFiles</ProjectView>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Security.Permissions;
|
||||||
|
|
||||||
|
/* Change history:
|
||||||
|
* 20 Apr 2007 Marc Gravell Rollback dictionary on error;
|
||||||
|
* Assert ReflectionPermission for main creation
|
||||||
|
* (thanks/credit to Josh Smith for feedback/hints)
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Hyper.ComponentModel {
|
||||||
|
public sealed class HyperTypeDescriptionProvider : TypeDescriptionProvider {
|
||||||
|
public static void Add(Type type) {
|
||||||
|
TypeDescriptionProvider parent = TypeDescriptor.GetProvider(type);
|
||||||
|
TypeDescriptor.AddProvider(new HyperTypeDescriptionProvider(parent), type);
|
||||||
|
}
|
||||||
|
public HyperTypeDescriptionProvider() : this(typeof(object)) { }
|
||||||
|
public HyperTypeDescriptionProvider(Type type) : this(TypeDescriptor.GetProvider(type)) { }
|
||||||
|
public HyperTypeDescriptionProvider(TypeDescriptionProvider parent) : base(parent) { }
|
||||||
|
public static void Clear(Type type) {
|
||||||
|
lock (descriptors) {
|
||||||
|
descriptors.Remove(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void Clear() {
|
||||||
|
lock (descriptors) {
|
||||||
|
descriptors.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static readonly Dictionary<Type, ICustomTypeDescriptor> descriptors = new Dictionary<Type, ICustomTypeDescriptor>();
|
||||||
|
public sealed override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance) {
|
||||||
|
ICustomTypeDescriptor descriptor;
|
||||||
|
lock (descriptors) {
|
||||||
|
if (!descriptors.TryGetValue(objectType, out descriptor)) {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
descriptor = BuildDescriptor(objectType);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return base.GetTypeDescriptor(objectType, instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return descriptor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[ReflectionPermission( SecurityAction.Assert, Flags = ReflectionPermissionFlag.AllFlags)]
|
||||||
|
private ICustomTypeDescriptor BuildDescriptor(Type objectType)
|
||||||
|
{
|
||||||
|
// NOTE: "descriptors" already locked here
|
||||||
|
|
||||||
|
// get the parent descriptor and add to the dictionary so that
|
||||||
|
// building the new descriptor will use the base rather than recursing
|
||||||
|
ICustomTypeDescriptor descriptor = base.GetTypeDescriptor(objectType, null);
|
||||||
|
descriptors.Add(objectType, descriptor);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// build a new descriptor from this, and replace the lookup
|
||||||
|
descriptor = new HyperTypeDescriptor(descriptor);
|
||||||
|
descriptors[objectType] = descriptor;
|
||||||
|
return descriptor;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{ // rollback and throw
|
||||||
|
// (perhaps because the specific caller lacked permissions;
|
||||||
|
// another caller may be successful)
|
||||||
|
descriptors.Remove(objectType);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,218 @@
|
|||||||
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Reflection.Emit;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
/* Change history:
|
||||||
|
* 20 Apr 2007 Marc Gravell Renamed
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Hyper.ComponentModel {
|
||||||
|
sealed class HyperTypeDescriptor : CustomTypeDescriptor {
|
||||||
|
private readonly PropertyDescriptorCollection propertyCollections;
|
||||||
|
static readonly Dictionary<PropertyInfo, PropertyDescriptor> properties = new Dictionary<PropertyInfo, PropertyDescriptor>();
|
||||||
|
internal HyperTypeDescriptor(ICustomTypeDescriptor parent)
|
||||||
|
: base(parent) {
|
||||||
|
propertyCollections = WrapProperties(parent.GetProperties());
|
||||||
|
}
|
||||||
|
public sealed override PropertyDescriptorCollection GetProperties(Attribute[] attributes) {
|
||||||
|
return propertyCollections;
|
||||||
|
}
|
||||||
|
public sealed override PropertyDescriptorCollection GetProperties() {
|
||||||
|
return propertyCollections;
|
||||||
|
}
|
||||||
|
private static PropertyDescriptorCollection WrapProperties(PropertyDescriptorCollection oldProps) {
|
||||||
|
PropertyDescriptor[] newProps = new PropertyDescriptor[oldProps.Count];
|
||||||
|
int index = 0;
|
||||||
|
bool changed = false;
|
||||||
|
// HACK: how to identify reflection, given that the class is internal...
|
||||||
|
Type wrapMe = Assembly.GetAssembly(typeof(PropertyDescriptor)).GetType("System.ComponentModel.ReflectPropertyDescriptor");
|
||||||
|
foreach (PropertyDescriptor oldProp in oldProps) {
|
||||||
|
PropertyDescriptor pd = oldProp;
|
||||||
|
// if it looks like reflection, try to create a bespoke descriptor
|
||||||
|
if (ReferenceEquals(wrapMe, pd.GetType()) && TryCreatePropertyDescriptor(ref pd)) {
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
newProps[index++] = pd;
|
||||||
|
}
|
||||||
|
|
||||||
|
return changed ? new PropertyDescriptorCollection(newProps, true) : oldProps;
|
||||||
|
}
|
||||||
|
|
||||||
|
static readonly ModuleBuilder moduleBuilder;
|
||||||
|
static int counter;
|
||||||
|
static HyperTypeDescriptor() {
|
||||||
|
AssemblyName an = new AssemblyName("Hyper.ComponentModel.dynamic");
|
||||||
|
AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly(an, AssemblyBuilderAccess.Run);
|
||||||
|
moduleBuilder = ab.DefineDynamicModule("Hyper.ComponentModel.dynamic.dll");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool TryCreatePropertyDescriptor(ref PropertyDescriptor descriptor) {
|
||||||
|
try {
|
||||||
|
PropertyInfo property = descriptor.ComponentType.GetProperty(descriptor.Name);
|
||||||
|
if (property == null) return false;
|
||||||
|
|
||||||
|
lock (properties) {
|
||||||
|
PropertyDescriptor foundBuiltAlready;
|
||||||
|
if (properties.TryGetValue(property, out foundBuiltAlready)) {
|
||||||
|
descriptor = foundBuiltAlready;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
string name = "_c" + Interlocked.Increment(ref counter).ToString();
|
||||||
|
TypeBuilder tb = moduleBuilder.DefineType(name, TypeAttributes.Sealed | TypeAttributes.NotPublic | TypeAttributes.Class | TypeAttributes.BeforeFieldInit | TypeAttributes.AutoClass | TypeAttributes.Public, typeof(ChainingPropertyDescriptor));
|
||||||
|
|
||||||
|
// ctor calls base
|
||||||
|
ConstructorBuilder cb = tb.DefineConstructor(MethodAttributes.HideBySig | MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName, CallingConventions.Standard, new Type[] { typeof(PropertyDescriptor) });
|
||||||
|
ILGenerator il = cb.GetILGenerator();
|
||||||
|
il.Emit(OpCodes.Ldarg_0);
|
||||||
|
il.Emit(OpCodes.Ldarg_1);
|
||||||
|
il.Emit(OpCodes.Call, typeof(ChainingPropertyDescriptor).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(PropertyDescriptor) }, null));
|
||||||
|
il.Emit(OpCodes.Ret);
|
||||||
|
|
||||||
|
MethodBuilder mb;
|
||||||
|
MethodInfo baseMethod;
|
||||||
|
if (property.CanRead) {
|
||||||
|
// obtain the implementation that we want to override
|
||||||
|
baseMethod = typeof(ChainingPropertyDescriptor).GetMethod("GetValue");
|
||||||
|
// create a new method that accepts an object and returns an object (as per the base)
|
||||||
|
mb = tb.DefineMethod(baseMethod.Name,
|
||||||
|
MethodAttributes.HideBySig | MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.Final,
|
||||||
|
baseMethod.CallingConvention, baseMethod.ReturnType, new Type[] { typeof(object) });
|
||||||
|
// start writing IL into the method
|
||||||
|
il = mb.GetILGenerator();
|
||||||
|
if (property.DeclaringType.IsValueType) {
|
||||||
|
// upbox the object argument into our known (instance) struct type
|
||||||
|
LocalBuilder lb = il.DeclareLocal(property.DeclaringType);
|
||||||
|
il.Emit(OpCodes.Ldarg_1);
|
||||||
|
il.Emit(OpCodes.Unbox_Any, property.DeclaringType);
|
||||||
|
il.Emit(OpCodes.Stloc_0);
|
||||||
|
il.Emit(OpCodes.Ldloca_S, lb);
|
||||||
|
} else {
|
||||||
|
// cast the object argument into our known class type
|
||||||
|
il.Emit(OpCodes.Ldarg_1);
|
||||||
|
il.Emit(OpCodes.Castclass, property.DeclaringType);
|
||||||
|
}
|
||||||
|
// call the "get" method
|
||||||
|
il.Emit(OpCodes.Callvirt, property.GetGetMethod());
|
||||||
|
|
||||||
|
if (property.PropertyType.IsValueType) {
|
||||||
|
// box it from the known (value) struct type
|
||||||
|
il.Emit(OpCodes.Box, property.PropertyType);
|
||||||
|
}
|
||||||
|
// return the value
|
||||||
|
il.Emit(OpCodes.Ret);
|
||||||
|
// signal that this method should override the base
|
||||||
|
tb.DefineMethodOverride(mb, baseMethod);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool supportsChangeEvents = descriptor.SupportsChangeEvents, isReadOnly = descriptor.IsReadOnly;
|
||||||
|
|
||||||
|
// override SupportsChangeEvents
|
||||||
|
baseMethod = typeof(ChainingPropertyDescriptor).GetProperty("SupportsChangeEvents").GetGetMethod();
|
||||||
|
mb = tb.DefineMethod(baseMethod.Name, MethodAttributes.HideBySig | MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.Final | MethodAttributes.SpecialName, baseMethod.CallingConvention, baseMethod.ReturnType, Type.EmptyTypes);
|
||||||
|
il = mb.GetILGenerator();
|
||||||
|
if (supportsChangeEvents) {
|
||||||
|
il.Emit(OpCodes.Ldc_I4_1);
|
||||||
|
} else {
|
||||||
|
il.Emit(OpCodes.Ldc_I4_0);
|
||||||
|
}
|
||||||
|
il.Emit(OpCodes.Ret);
|
||||||
|
tb.DefineMethodOverride(mb, baseMethod);
|
||||||
|
|
||||||
|
// override IsReadOnly
|
||||||
|
baseMethod = typeof(ChainingPropertyDescriptor).GetProperty("IsReadOnly").GetGetMethod();
|
||||||
|
mb = tb.DefineMethod(baseMethod.Name, MethodAttributes.HideBySig | MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.Final | MethodAttributes.SpecialName, baseMethod.CallingConvention, baseMethod.ReturnType, Type.EmptyTypes);
|
||||||
|
il = mb.GetILGenerator();
|
||||||
|
if (isReadOnly) {
|
||||||
|
il.Emit(OpCodes.Ldc_I4_1);
|
||||||
|
} else {
|
||||||
|
il.Emit(OpCodes.Ldc_I4_0);
|
||||||
|
}
|
||||||
|
il.Emit(OpCodes.Ret);
|
||||||
|
tb.DefineMethodOverride(mb, baseMethod);
|
||||||
|
|
||||||
|
/* REMOVED: PropertyType, ComponentType; actually *adds* time overriding these
|
||||||
|
// override PropertyType
|
||||||
|
baseMethod = typeof(ChainingPropertyDescriptor).GetProperty("PropertyType").GetGetMethod();
|
||||||
|
mb = tb.DefineMethod(baseMethod.Name, MethodAttributes.HideBySig | MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.Final | MethodAttributes.SpecialName, baseMethod.CallingConvention, baseMethod.ReturnType, Type.EmptyTypes);
|
||||||
|
il = mb.GetILGenerator();
|
||||||
|
il.Emit(OpCodes.Ldtoken, descriptor.PropertyType);
|
||||||
|
il.Emit(OpCodes.Call, typeof(Type).GetMethod("GetTypeFromHandle"));
|
||||||
|
il.Emit(OpCodes.Ret);
|
||||||
|
tb.DefineMethodOverride(mb, baseMethod);
|
||||||
|
|
||||||
|
// override ComponentType
|
||||||
|
baseMethod = typeof(ChainingPropertyDescriptor).GetProperty("ComponentType").GetGetMethod();
|
||||||
|
mb = tb.DefineMethod(baseMethod.Name, MethodAttributes.HideBySig | MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.Final | MethodAttributes.SpecialName, baseMethod.CallingConvention, baseMethod.ReturnType, Type.EmptyTypes);
|
||||||
|
il = mb.GetILGenerator();
|
||||||
|
il.Emit(OpCodes.Ldtoken, descriptor.ComponentType);
|
||||||
|
il.Emit(OpCodes.Call, typeof(Type).GetMethod("GetTypeFromHandle"));
|
||||||
|
il.Emit(OpCodes.Ret);
|
||||||
|
tb.DefineMethodOverride(mb, baseMethod);
|
||||||
|
*/
|
||||||
|
|
||||||
|
// for classes, implement write (would be lost in unbox for structs)
|
||||||
|
if (!property.DeclaringType.IsValueType) {
|
||||||
|
if (!isReadOnly && property.CanWrite) {
|
||||||
|
// override set method
|
||||||
|
baseMethod = typeof(ChainingPropertyDescriptor).GetMethod("SetValue");
|
||||||
|
mb = tb.DefineMethod(baseMethod.Name, MethodAttributes.HideBySig | MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.Final, baseMethod.CallingConvention, baseMethod.ReturnType, new Type[] { typeof(object), typeof(object) });
|
||||||
|
il = mb.GetILGenerator();
|
||||||
|
il.Emit(OpCodes.Ldarg_1);
|
||||||
|
il.Emit(OpCodes.Castclass, property.DeclaringType);
|
||||||
|
il.Emit(OpCodes.Ldarg_2);
|
||||||
|
if (property.PropertyType.IsValueType) {
|
||||||
|
il.Emit(OpCodes.Unbox_Any, property.PropertyType);
|
||||||
|
} else {
|
||||||
|
il.Emit(OpCodes.Castclass, property.PropertyType);
|
||||||
|
}
|
||||||
|
il.Emit(OpCodes.Callvirt, property.GetSetMethod());
|
||||||
|
il.Emit(OpCodes.Ret);
|
||||||
|
tb.DefineMethodOverride(mb, baseMethod);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (supportsChangeEvents) {
|
||||||
|
EventInfo ei = property.DeclaringType.GetEvent(property.Name + "Changed");
|
||||||
|
if (ei != null) {
|
||||||
|
baseMethod = typeof(ChainingPropertyDescriptor).GetMethod("AddValueChanged");
|
||||||
|
mb = tb.DefineMethod(baseMethod.Name, MethodAttributes.HideBySig | MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.Final | MethodAttributes.SpecialName, baseMethod.CallingConvention, baseMethod.ReturnType, new Type[] { typeof(object), typeof(EventHandler) });
|
||||||
|
il = mb.GetILGenerator();
|
||||||
|
il.Emit(OpCodes.Ldarg_1);
|
||||||
|
il.Emit(OpCodes.Castclass, property.DeclaringType);
|
||||||
|
il.Emit(OpCodes.Ldarg_2);
|
||||||
|
il.Emit(OpCodes.Callvirt, ei.GetAddMethod());
|
||||||
|
il.Emit(OpCodes.Ret);
|
||||||
|
tb.DefineMethodOverride(mb, baseMethod);
|
||||||
|
|
||||||
|
baseMethod = typeof(ChainingPropertyDescriptor).GetMethod("RemoveValueChanged");
|
||||||
|
mb = tb.DefineMethod(baseMethod.Name, MethodAttributes.HideBySig | MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.Final | MethodAttributes.SpecialName, baseMethod.CallingConvention, baseMethod.ReturnType, new Type[] { typeof(object), typeof(EventHandler) });
|
||||||
|
il = mb.GetILGenerator();
|
||||||
|
il.Emit(OpCodes.Ldarg_1);
|
||||||
|
il.Emit(OpCodes.Castclass, property.DeclaringType);
|
||||||
|
il.Emit(OpCodes.Ldarg_2);
|
||||||
|
il.Emit(OpCodes.Callvirt, ei.GetRemoveMethod());
|
||||||
|
il.Emit(OpCodes.Ret);
|
||||||
|
tb.DefineMethodOverride(mb, baseMethod);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
PropertyDescriptor newDesc = tb.CreateType().GetConstructor(new Type[] { typeof(PropertyDescriptor) }).Invoke(new object[] { descriptor }) as PropertyDescriptor;
|
||||||
|
if (newDesc == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
descriptor = newDesc;
|
||||||
|
properties.Add(property, descriptor);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Security;
|
||||||
|
|
||||||
|
[assembly: AllowPartiallyTrustedCallers]
|
||||||
|
|
||||||
|
// General Information about an assembly is controlled through the following
|
||||||
|
// set of attributes. Change these attribute values to modify the information
|
||||||
|
// associated with an assembly.
|
||||||
|
[assembly: AssemblyTitle("HyperTypeDescriptor")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("HyperTypeDescriptor")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © Marc Gravell 2007")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// Setting ComVisible to false makes the types in this assembly not visible
|
||||||
|
// to COM components. If you need to access a type in this assembly from
|
||||||
|
// COM, set the ComVisible attribute to true on that type.
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||||
|
[assembly: Guid("f22bc56b-501e-438a-967e-8f0b48827869")]
|
||||||
|
|
||||||
|
// Version information for an assembly consists of the following four values:
|
||||||
|
//
|
||||||
|
// Major Version
|
||||||
|
// Minor Version
|
||||||
|
// Build Number
|
||||||
|
// Revision
|
||||||
|
//
|
||||||
|
// You can specify all the values or you can default the Revision and Build Numbers
|
||||||
|
// by using the '*' as shown below:
|
||||||
|
[assembly: AssemblyVersion("1.0.0.0")]
|
||||||
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||||
@@ -15,6 +15,8 @@ namespace Subsurface
|
|||||||
|
|
||||||
const float CheckWallsInterval = 5.0f;
|
const float CheckWallsInterval = 5.0f;
|
||||||
|
|
||||||
|
public bool Enabled;
|
||||||
|
|
||||||
private BackgroundSpritePrefab prefab;
|
private BackgroundSpritePrefab prefab;
|
||||||
|
|
||||||
private Vector2 position;
|
private Vector2 position;
|
||||||
@@ -29,6 +31,12 @@ namespace Subsurface
|
|||||||
|
|
||||||
public Swarm Swarm;
|
public Swarm Swarm;
|
||||||
|
|
||||||
|
Vector2 drawPosition;
|
||||||
|
public Vector2 TransformedPosition
|
||||||
|
{
|
||||||
|
get { return drawPosition; }
|
||||||
|
}
|
||||||
|
|
||||||
public Vector2 Position
|
public Vector2 Position
|
||||||
{
|
{
|
||||||
get { return position; }
|
get { return position; }
|
||||||
@@ -51,6 +59,8 @@ namespace Subsurface
|
|||||||
|
|
||||||
this.position = position;
|
this.position = position;
|
||||||
|
|
||||||
|
drawPosition = position + Level.Loaded.Position;
|
||||||
|
|
||||||
steeringManager = new SteeringManager(this);
|
steeringManager = new SteeringManager(this);
|
||||||
|
|
||||||
velocity = new Vector3(
|
velocity = new Vector3(
|
||||||
@@ -141,18 +151,16 @@ namespace Subsurface
|
|||||||
if (velocity.X < 0.0f) rotation -= MathHelper.Pi;
|
if (velocity.X < 0.0f) rotation -= MathHelper.Pi;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 drawPos = position;
|
if (Level.Loaded != null) drawPosition = position + Level.Loaded.Position;
|
||||||
|
|
||||||
if (Level.Loaded != null) drawPos += Level.Loaded.Position;
|
|
||||||
|
|
||||||
if (depth > 0.0f)
|
if (depth > 0.0f)
|
||||||
{
|
{
|
||||||
Vector2 camOffset = drawPos - GameMain.GameScreen.Cam.WorldViewCenter;
|
Vector2 camOffset = drawPosition - GameMain.GameScreen.Cam.WorldViewCenter;
|
||||||
|
|
||||||
drawPos = drawPos - camOffset * (depth / MaxDepth) * 0.05f;
|
drawPosition = drawPosition - camOffset * (depth / MaxDepth) * 0.05f;
|
||||||
}
|
}
|
||||||
|
|
||||||
prefab.Sprite.Draw(spriteBatch, new Vector2(drawPos.X, -drawPos.Y), Color.Lerp(Color.White, Color.DarkBlue, (depth/MaxDepth)*0.3f),
|
prefab.Sprite.Draw(spriteBatch, new Vector2(drawPosition.X, -drawPosition.Y), Color.Lerp(Color.White, Color.DarkBlue, (depth/MaxDepth)*0.3f),
|
||||||
rotation, 1.0f - (depth / MaxDepth) * 0.2f, velocity.X > 0.0f ? SpriteEffects.None : SpriteEffects.FlipHorizontally, (depth / MaxDepth));
|
rotation, 1.0f - (depth / MaxDepth) * 0.2f, velocity.X > 0.0f ? SpriteEffects.None : SpriteEffects.FlipHorizontally, (depth / MaxDepth));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ namespace Subsurface
|
|||||||
{
|
{
|
||||||
const int MaxSprites = 100;
|
const int MaxSprites = 100;
|
||||||
|
|
||||||
|
const float checkActiveInterval = 1.0f;
|
||||||
|
|
||||||
|
float checkActiveTimer;
|
||||||
|
|
||||||
private List<BackgroundSpritePrefab> prefabs;
|
private List<BackgroundSpritePrefab> prefabs;
|
||||||
private List<BackgroundSprite> activeSprites;
|
private List<BackgroundSprite> activeSprites;
|
||||||
|
|
||||||
@@ -31,7 +35,6 @@ namespace Subsurface
|
|||||||
|
|
||||||
public void SpawnSprites(int count)
|
public void SpawnSprites(int count)
|
||||||
{
|
{
|
||||||
|
|
||||||
activeSprites.Clear();
|
activeSprites.Clear();
|
||||||
|
|
||||||
if (prefabs.Count == 0) return;
|
if (prefabs.Count == 0) return;
|
||||||
@@ -77,10 +80,26 @@ namespace Subsurface
|
|||||||
activeSprites.Clear();
|
activeSprites.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update(float deltaTime)
|
public void Update(Camera cam, float deltaTime)
|
||||||
{
|
{
|
||||||
|
if (checkActiveTimer<0.0f)
|
||||||
|
{
|
||||||
|
foreach (BackgroundSprite sprite in activeSprites)
|
||||||
|
{
|
||||||
|
sprite.Enabled = (Math.Abs(sprite.TransformedPosition.X - cam.WorldViewCenter.X) < 4000.0f &&
|
||||||
|
Math.Abs(sprite.TransformedPosition.Y - cam.WorldViewCenter.Y) < 4000.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
checkActiveTimer = checkActiveInterval;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
checkActiveTimer -= deltaTime;
|
||||||
|
}
|
||||||
|
|
||||||
foreach (BackgroundSprite sprite in activeSprites)
|
foreach (BackgroundSprite sprite in activeSprites)
|
||||||
{
|
{
|
||||||
|
if (!sprite.Enabled) continue;
|
||||||
sprite.Update(deltaTime);
|
sprite.Update(deltaTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,6 +108,7 @@ namespace Subsurface
|
|||||||
{
|
{
|
||||||
foreach (BackgroundSprite sprite in activeSprites)
|
foreach (BackgroundSprite sprite in activeSprites)
|
||||||
{
|
{
|
||||||
|
if (!sprite.Enabled) continue;
|
||||||
sprite.Draw(spriteBatch);
|
sprite.Draw(spriteBatch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -307,16 +307,22 @@ namespace Subsurface
|
|||||||
if (GameMain.DebugDraw)
|
if (GameMain.DebugDraw)
|
||||||
{
|
{
|
||||||
spriteBatch.DrawString(Font,
|
spriteBatch.DrawString(Font,
|
||||||
"Physics: " + GameMain.World.UpdateTime
|
"Physics: " + GameMain.World.UpdateTime,
|
||||||
+ " - bodies: " + GameMain.World.BodyList.Count
|
|
||||||
+ " Camera pos: " + GameMain.GameScreen.Cam.Position,
|
|
||||||
new Vector2(10, 30), Color.White);
|
new Vector2(10, 30), Color.White);
|
||||||
|
|
||||||
|
spriteBatch.DrawString(Font,
|
||||||
|
"Bodies: " + GameMain.World.BodyList.Count + " (" + GameMain.World.BodyList.FindAll(b => b.Awake && b.Enabled).Count + " awake)",
|
||||||
|
new Vector2(10, 50), Color.White);
|
||||||
|
|
||||||
|
spriteBatch.DrawString(Font,
|
||||||
|
"Camera pos: " + GameMain.GameScreen.Cam.Position,
|
||||||
|
new Vector2(10, 70), Color.White);
|
||||||
|
|
||||||
if (Submarine.Loaded!=null)
|
if (Submarine.Loaded!=null)
|
||||||
{
|
{
|
||||||
spriteBatch.DrawString(Font,
|
spriteBatch.DrawString(Font,
|
||||||
"Sub pos: " + Submarine.Loaded.Position,
|
"Sub pos: " + Submarine.Loaded.Position,
|
||||||
new Vector2(10, 50), Color.White);
|
new Vector2(10, 90), Color.White);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -120,6 +120,8 @@ namespace Subsurface
|
|||||||
//TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 55);
|
//TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 55);
|
||||||
|
|
||||||
World = new World(new Vector2(0, -9.82f));
|
World = new World(new Vector2(0, -9.82f));
|
||||||
|
FarseerPhysics.Settings.AllowSleep = true;
|
||||||
|
FarseerPhysics.Settings.ContinuousPhysics = false;
|
||||||
FarseerPhysics.Settings.VelocityIterations = 2;
|
FarseerPhysics.Settings.VelocityIterations = 2;
|
||||||
FarseerPhysics.Settings.PositionIterations = 1;
|
FarseerPhysics.Settings.PositionIterations = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ namespace Subsurface.Items.Components
|
|||||||
{
|
{
|
||||||
if (containedItem == null) continue;
|
if (containedItem == null) continue;
|
||||||
|
|
||||||
containedItem.sprite.Draw(
|
containedItem.Sprite.Draw(
|
||||||
spriteBatch,
|
spriteBatch,
|
||||||
new Vector2(transformedItemPos.X, -transformedItemPos.Y),
|
new Vector2(transformedItemPos.X, -transformedItemPos.Y),
|
||||||
-currentRotation,
|
-currentRotation,
|
||||||
|
|||||||
@@ -82,7 +82,16 @@ namespace Subsurface.Items.Components
|
|||||||
public virtual bool IsActive
|
public virtual bool IsActive
|
||||||
{
|
{
|
||||||
get { return isActive; }
|
get { return isActive; }
|
||||||
set { isActive = value; }
|
set
|
||||||
|
{
|
||||||
|
if (!value && isActive)
|
||||||
|
{
|
||||||
|
StopSounds(ActionType.OnActive);
|
||||||
|
StopSounds(ActionType.OnUse);
|
||||||
|
}
|
||||||
|
|
||||||
|
isActive = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HasDefaultValue(false, false)]
|
[HasDefaultValue(false, false)]
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ namespace Subsurface.Items.Components
|
|||||||
stickJoint.MaxMotorForce = 30.0f;
|
stickJoint.MaxMotorForce = 30.0f;
|
||||||
|
|
||||||
stickJoint.LimitEnabled = true;
|
stickJoint.LimitEnabled = true;
|
||||||
stickJoint.UpperLimit = ConvertUnits.ToSimUnits(item.sprite.size.X*0.7f);
|
stickJoint.UpperLimit = ConvertUnits.ToSimUnits(item.Sprite.size.X*0.7f);
|
||||||
|
|
||||||
item.body.FarseerBody.IgnoreCollisionWith(targetBody);
|
item.body.FarseerBody.IgnoreCollisionWith(targetBody);
|
||||||
stickTarget = targetBody;
|
stickTarget = targetBody;
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ namespace Subsurface
|
|||||||
|
|
||||||
if (item == null) return;
|
if (item == null) return;
|
||||||
|
|
||||||
item.sprite.Draw(spriteBatch, new Vector2(rect.X + rect.Width / 2, rect.Y + rect.Height / 2), item.Color);
|
item.Sprite.Draw(spriteBatch, new Vector2(rect.X + rect.Width / 2, rect.Y + rect.Height / 2), item.Color);
|
||||||
|
|
||||||
if (isHighLighted)
|
if (isHighLighted)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ namespace Subsurface
|
|||||||
get { return prefab.Name; }
|
get { return prefab.Name; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Sprite sprite
|
public override Sprite Sprite
|
||||||
{
|
{
|
||||||
get { return prefab.sprite; }
|
get { return prefab.sprite; }
|
||||||
}
|
}
|
||||||
@@ -299,9 +299,8 @@ namespace Subsurface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InsertToList();
|
||||||
itemList.Add(this);
|
itemList.Add(this);
|
||||||
mapEntityList.Add(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public T GetComponent<T>()
|
public T GetComponent<T>()
|
||||||
@@ -475,23 +474,8 @@ namespace Subsurface
|
|||||||
{
|
{
|
||||||
if (ic.Parent != null) ic.IsActive = ic.Parent.IsActive;
|
if (ic.Parent != null) ic.IsActive = ic.Parent.IsActive;
|
||||||
|
|
||||||
//if (!ic.WasUsed)
|
if (!ic.IsActive) continue;
|
||||||
//{
|
|
||||||
// if (ic.Name == "RepairTool" && ic.IsActive)
|
|
||||||
// {
|
|
||||||
// System.Diagnostics.Debug.WriteLine("stop sounds");
|
|
||||||
// }
|
|
||||||
// ic.StopSounds(ActionType.OnUse);
|
|
||||||
//}
|
|
||||||
//ic.WasUsed = false;
|
|
||||||
|
|
||||||
|
|
||||||
if (!ic.IsActive)
|
|
||||||
{
|
|
||||||
ic.StopSounds(ActionType.OnActive);
|
|
||||||
ic.StopSounds(ActionType.OnUse);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (condition > 0.0f)
|
if (condition > 0.0f)
|
||||||
{
|
{
|
||||||
ic.Update(deltaTime, cam);
|
ic.Update(deltaTime, cam);
|
||||||
@@ -503,17 +487,19 @@ namespace Subsurface
|
|||||||
{
|
{
|
||||||
ic.UpdateBroken(deltaTime, cam);
|
ic.UpdateBroken(deltaTime, cam);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (body == null || !body.Enabled) return;
|
||||||
|
|
||||||
|
if (body.LinearVelocity.Length() > 0.001f)
|
||||||
|
{
|
||||||
|
FindHull();
|
||||||
|
|
||||||
|
Vector2 displayPos = ConvertUnits.ToDisplayUnits(body.SimPosition);
|
||||||
|
|
||||||
|
rect.X = (int)(displayPos.X - rect.Width / 2.0f);
|
||||||
|
rect.Y = (int)(displayPos.Y + rect.Height / 2.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (body == null) return;
|
|
||||||
|
|
||||||
if (body.LinearVelocity.Length()>0.001f) FindHull();
|
|
||||||
|
|
||||||
Vector2 displayPos = ConvertUnits.ToDisplayUnits(body.SimPosition);
|
|
||||||
|
|
||||||
rect.X = (int)(displayPos.X - rect.Width / 2.0f);
|
|
||||||
rect.Y = (int)(displayPos.Y + rect.Height / 2.0f);
|
|
||||||
|
|
||||||
body.SetToTargetPosition();
|
body.SetToTargetPosition();
|
||||||
|
|
||||||
@@ -527,7 +513,7 @@ namespace Subsurface
|
|||||||
{
|
{
|
||||||
Vector2 impulse = -body.LinearVelocity * (body.Mass / body.Density);
|
Vector2 impulse = -body.LinearVelocity * (body.Mass / body.Density);
|
||||||
body.ApplyLinearImpulse(impulse);
|
body.ApplyLinearImpulse(impulse);
|
||||||
int n = (int)((displayPos.X - CurrentHull.Rect.X) / Hull.WaveWidth);
|
int n = (int)((ConvertUnits.ToDisplayUnits(body.SimPosition.X) - CurrentHull.Rect.X) / Hull.WaveWidth);
|
||||||
CurrentHull.WaveVel[n] = impulse.Y * 10.0f;
|
CurrentHull.WaveVel[n] = impulse.Y * 10.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -537,28 +523,21 @@ namespace Subsurface
|
|||||||
Vector2 buoyancy = new Vector2(0, volume * 20.0f);
|
Vector2 buoyancy = new Vector2(0, volume * 20.0f);
|
||||||
|
|
||||||
//apply buoyancy and drag
|
//apply buoyancy and drag
|
||||||
try
|
|
||||||
{
|
|
||||||
//if ((buoyancy - body.LinearVelocity * volume) == Vector2.Zero) DebugConsole.ThrowError("v.zero ");
|
|
||||||
if (body.LinearVelocity != Vector2.Zero && body.LinearVelocity.Length() > 1000.0f)
|
|
||||||
{
|
|
||||||
body.ResetDynamics();
|
|
||||||
if (body.SimPosition.Length() > 1000.0f)
|
|
||||||
{
|
|
||||||
Remove();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
body.ApplyForce(buoyancy - body.LinearVelocity * volume);
|
|
||||||
|
|
||||||
//apply simple angular drag
|
|
||||||
body.ApplyTorque(body.AngularVelocity * volume * -0.05f);
|
|
||||||
}
|
|
||||||
|
|
||||||
catch
|
//if ((buoyancy - body.LinearVelocity * volume) == Vector2.Zero) DebugConsole.ThrowError("v.zero ");
|
||||||
|
if (body.LinearVelocity != Vector2.Zero && body.LinearVelocity.Length() > 1000.0f)
|
||||||
{
|
{
|
||||||
DebugConsole.ThrowError("something bad happened with the physics");
|
body.ResetDynamics();
|
||||||
|
if (body.SimPosition.Length() > 1000.0f)
|
||||||
|
{
|
||||||
|
Remove();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
body.ApplyForce(buoyancy - body.LinearVelocity * volume);
|
||||||
|
|
||||||
|
//apply simple angular drag
|
||||||
|
body.ApplyTorque(body.AngularVelocity * volume * -0.05f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Draw(SpriteBatch spriteBatch, bool editing)
|
public override void Draw(SpriteBatch spriteBatch, bool editing)
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ namespace Subsurface
|
|||||||
|
|
||||||
name = ToolBox.GetAttributeString(element, "name", "");
|
name = ToolBox.GetAttributeString(element, "name", "");
|
||||||
if (name == "") DebugConsole.ThrowError("Unnamed item in "+filePath+"!");
|
if (name == "") DebugConsole.ThrowError("Unnamed item in "+filePath+"!");
|
||||||
|
|
||||||
pickDistance = ConvertUnits.ToSimUnits(ToolBox.GetAttributeFloat(element, "pickdistance", 0.0f));
|
pickDistance = ConvertUnits.ToSimUnits(ToolBox.GetAttributeFloat(element, "pickdistance", 0.0f));
|
||||||
|
|
||||||
isLinkable = ToolBox.GetAttributeBool(element, "linkable", false);
|
isLinkable = ToolBox.GetAttributeBool(element, "linkable", false);
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ namespace Subsurface
|
|||||||
FindHulls();
|
FindHulls();
|
||||||
|
|
||||||
GapList.Add(this);
|
GapList.Add(this);
|
||||||
mapEntityList.Add(this);
|
InsertToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void UpdateHulls()
|
public static void UpdateHulls()
|
||||||
|
|||||||
@@ -146,8 +146,7 @@ namespace Subsurface
|
|||||||
|
|
||||||
Volume = 0.0f;
|
Volume = 0.0f;
|
||||||
|
|
||||||
//add to list of entities as well
|
InsertToList();
|
||||||
mapEntityList.Add(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Contains(Vector2 position)
|
public override bool Contains(Vector2 position)
|
||||||
|
|||||||
@@ -10,18 +10,17 @@ namespace Subsurface.Lights
|
|||||||
public static List<ConvexHull> list = new List<ConvexHull>();
|
public static List<ConvexHull> list = new List<ConvexHull>();
|
||||||
static BasicEffect shadowEffect;
|
static BasicEffect shadowEffect;
|
||||||
static BasicEffect penumbraEffect;
|
static BasicEffect penumbraEffect;
|
||||||
|
|
||||||
private static VertexPositionTexture[] penumbraVertices;
|
private Vector2[] vertices;
|
||||||
|
private int primitiveCount;
|
||||||
private VertexPositionColor[] vertices;
|
|
||||||
private short[] indices;
|
|
||||||
int primitiveCount;
|
|
||||||
|
|
||||||
bool[] backFacing;
|
private bool[] backFacing;
|
||||||
VertexPositionColor[] shadowVertices;
|
|
||||||
|
private VertexPositionColor[] shadowVertices;
|
||||||
|
private VertexPositionTexture[] penumbraVertices;
|
||||||
|
|
||||||
private Rectangle boundingBox;
|
private Rectangle boundingBox;
|
||||||
|
|
||||||
public bool Enabled
|
public bool Enabled
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
@@ -48,86 +47,77 @@ namespace Subsurface.Lights
|
|||||||
penumbraEffect.LightingEnabled = false;
|
penumbraEffect.LightingEnabled = false;
|
||||||
penumbraEffect.Texture = TextureLoader.FromFile("Content/Lights/penumbra.png");
|
penumbraEffect.Texture = TextureLoader.FromFile("Content/Lights/penumbra.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vertices = points;
|
||||||
|
primitiveCount = vertices.Length;
|
||||||
|
|
||||||
if (penumbraVertices==null)
|
CalculateDimensions();
|
||||||
{
|
//indices = new short[primitiveCount * 3];
|
||||||
penumbraVertices = new VertexPositionTexture[6];
|
|
||||||
}
|
|
||||||
|
|
||||||
int vertexCount = points.Length;
|
//for (int i = 0; i < primitiveCount; i++)
|
||||||
vertices = new VertexPositionColor[vertexCount + 1];
|
//{
|
||||||
Vector2 center = Vector2.Zero;
|
// indices[3 * i] = (short)i;
|
||||||
|
// indices[3 * i + 1] = (short)((i + 1) % vertexCount);
|
||||||
float? minX = null, minY = null, maxX = null, maxY = null;
|
// indices[3 * i + 2] = (short)vertexCount;
|
||||||
|
//}
|
||||||
for (int i = 0; i < vertexCount; i++)
|
backFacing = new bool[primitiveCount];
|
||||||
{
|
|
||||||
vertices[i] = new VertexPositionColor(new Vector3(points[i], 0), color);
|
|
||||||
center += points[i];
|
|
||||||
|
|
||||||
if (minX == null || points[i].X < minX) minX = points[i].X;
|
|
||||||
if (minY == null || points[i].Y < minY) minY = points[i].Y;
|
|
||||||
|
|
||||||
if (maxX == null || points[i].X > maxX) maxX = points[i].X;
|
|
||||||
if (maxY == null || points[i].Y > minY) maxY = points[i].Y;
|
|
||||||
}
|
|
||||||
center /= points.Length;
|
|
||||||
vertices[vertexCount] = new VertexPositionColor(new Vector3(center, 0), color);
|
|
||||||
|
|
||||||
boundingBox = new Rectangle((int)minX, (int)minY, (int)(maxX-minX), (int)(maxY-minY));
|
|
||||||
|
|
||||||
primitiveCount = points.Length;
|
|
||||||
indices = new short[primitiveCount * 3];
|
|
||||||
|
|
||||||
for (int i = 0; i < primitiveCount; i++)
|
|
||||||
{
|
|
||||||
indices[3 * i] = (short)i;
|
|
||||||
indices[3 * i + 1] = (short)((i + 1) % vertexCount);
|
|
||||||
indices[3 * i + 2] = (short)vertexCount;
|
|
||||||
}
|
|
||||||
backFacing = new bool[vertexCount];
|
|
||||||
|
|
||||||
Enabled = true;
|
Enabled = true;
|
||||||
|
|
||||||
list.Add(this);
|
list.Add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void CalculateDimensions()
|
||||||
|
{
|
||||||
|
Vector2 center = Vector2.Zero;
|
||||||
|
|
||||||
|
float? minX = null, minY = null, maxX = null, maxY = null;
|
||||||
|
|
||||||
|
for (int i = 0; i < vertices.Length; i++)
|
||||||
|
{
|
||||||
|
center += vertices[i];
|
||||||
|
|
||||||
|
if (minX == null || vertices[i].X < minX) minX = vertices[i].X;
|
||||||
|
if (minY == null || vertices[i].Y < minY) minY = vertices[i].Y;
|
||||||
|
|
||||||
|
if (maxX == null || vertices[i].X > maxX) maxX = vertices[i].X;
|
||||||
|
if (maxY == null || vertices[i].Y > minY) maxY = vertices[i].Y;
|
||||||
|
}
|
||||||
|
center /= vertices.Length;
|
||||||
|
|
||||||
|
boundingBox = new Rectangle((int)minX, (int)minY, (int)(maxX - minX), (int)(maxY - minY));
|
||||||
|
}
|
||||||
|
|
||||||
public void Move(Vector2 amount)
|
public void Move(Vector2 amount)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < vertices.Count(); i++)
|
for (int i = 0; i < vertices.Count(); i++)
|
||||||
{
|
{
|
||||||
vertices[i].Position = new Vector3(vertices[i].Position.X + amount.X, vertices[i].Position.Y + amount.Y, vertices[i].Position.Z);
|
vertices[i] += amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CalculateDimensions();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetVertices(Vector2[] points)
|
public void SetVertices(Vector2[] points)
|
||||||
{
|
{
|
||||||
int vertexCount = points.Length;
|
vertices = points;
|
||||||
vertices = new VertexPositionColor[vertexCount + 1];
|
|
||||||
|
|
||||||
for (int i = 0; i < vertexCount; i++)
|
|
||||||
{
|
|
||||||
vertices[i] = new VertexPositionColor(new Vector3(points[i], 0), Color.Black);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawShadows(GraphicsDevice graphicsDevice, Camera cam, Vector2 lightSourcePos, Matrix transform, bool los = true)
|
private void CalculateShadowVertices(Vector2 lightSourcePos, bool los = true)
|
||||||
{
|
{
|
||||||
if (!Enabled) return;
|
|
||||||
|
|
||||||
//compute facing of each edge, using N*L
|
//compute facing of each edge, using N*L
|
||||||
for (int i = 0; i < primitiveCount; i++)
|
for (int i = 0; i < primitiveCount; i++)
|
||||||
{
|
{
|
||||||
Vector2 firstVertex = new Vector2(vertices[i].Position.X, vertices[i].Position.Y);
|
Vector2 firstVertex = new Vector2(vertices[i].X, vertices[i].Y);
|
||||||
int secondIndex = (i + 1) % primitiveCount;
|
int secondIndex = (i + 1) % primitiveCount;
|
||||||
Vector2 secondVertex = new Vector2(vertices[secondIndex].Position.X, vertices[secondIndex].Position.Y);
|
Vector2 secondVertex = new Vector2(vertices[secondIndex].X, vertices[secondIndex].Y);
|
||||||
Vector2 middle = (firstVertex + secondVertex) / 2;
|
Vector2 middle = (firstVertex + secondVertex) / 2;
|
||||||
|
|
||||||
Vector2 L = lightSourcePos - middle;
|
Vector2 L = lightSourcePos - middle;
|
||||||
|
|
||||||
Vector2 N = new Vector2();
|
Vector2 N = new Vector2(
|
||||||
N.X = -(secondVertex.Y - firstVertex.Y);
|
-(secondVertex.Y - firstVertex.Y),
|
||||||
N.Y = secondVertex.X - firstVertex.X;
|
secondVertex.X - firstVertex.X);
|
||||||
|
|
||||||
backFacing[i] = (Vector2.Dot(N, L) < 0);
|
backFacing[i] = (Vector2.Dot(N, L) < 0);
|
||||||
}
|
}
|
||||||
@@ -148,49 +138,6 @@ namespace Subsurface.Lights
|
|||||||
startingIndex = nextEdge;
|
startingIndex = nextEdge;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (los)
|
|
||||||
{
|
|
||||||
for (int n = 0; n < 4; n+=3)
|
|
||||||
{
|
|
||||||
Vector3 penumbraStart = (n == 0) ? vertices[startingIndex].Position : vertices[endingIndex].Position;
|
|
||||||
|
|
||||||
penumbraVertices[n] = new VertexPositionTexture();
|
|
||||||
penumbraVertices[n].Position = penumbraStart;
|
|
||||||
penumbraVertices[n].TextureCoordinate = new Vector2(0.0f, 1.0f);
|
|
||||||
//penumbraVertices[0].te = fow ? Color.Black : Color.Transparent;
|
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++ )
|
|
||||||
{
|
|
||||||
penumbraVertices[n + i + 1] = new VertexPositionTexture();
|
|
||||||
Vector3 vertexDir = penumbraStart - new Vector3(lightSourcePos, 0);
|
|
||||||
vertexDir.Normalize();
|
|
||||||
|
|
||||||
Vector3 normal = (i == 0) ? new Vector3(-vertexDir.Y, vertexDir.X, 0.0f) : new Vector3(vertexDir.Y, -vertexDir.X, 0.0f)*0.05f;
|
|
||||||
if (n > 0) normal = -normal;
|
|
||||||
vertexDir = penumbraStart - (new Vector3(lightSourcePos, 0) - normal * 20.0f);
|
|
||||||
vertexDir.Normalize();
|
|
||||||
penumbraVertices[n + i + 1].Position = new Vector3(lightSourcePos, 0) + vertexDir * 9000;
|
|
||||||
|
|
||||||
if (los)
|
|
||||||
{
|
|
||||||
penumbraVertices[n + i + 1].TextureCoordinate = (i == 0) ? new Vector2(0.05f, 0.0f) : new Vector2(1.0f, 0.0f);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
penumbraVertices[n + i + 1].TextureCoordinate = (i == 0) ? new Vector2(1.0f, 0.0f) : Vector2.Zero;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (n > 0)
|
|
||||||
{
|
|
||||||
var temp = penumbraVertices[4];
|
|
||||||
penumbraVertices[4] = penumbraVertices[5];
|
|
||||||
penumbraVertices[5] = temp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int shadowVertexCount;
|
int shadowVertexCount;
|
||||||
|
|
||||||
//nr of vertices that are in the shadow
|
//nr of vertices that are in the shadow
|
||||||
@@ -206,7 +153,7 @@ namespace Subsurface.Lights
|
|||||||
int svCount = 0;
|
int svCount = 0;
|
||||||
while (svCount != shadowVertexCount * 2)
|
while (svCount != shadowVertexCount * 2)
|
||||||
{
|
{
|
||||||
Vector3 vertexPos = vertices[currentIndex].Position;
|
Vector3 vertexPos = new Vector3(vertices[currentIndex], 0.0f);
|
||||||
|
|
||||||
//one vertex on the hull
|
//one vertex on the hull
|
||||||
shadowVertices[svCount] = new VertexPositionColor();
|
shadowVertices[svCount] = new VertexPositionColor();
|
||||||
@@ -224,10 +171,68 @@ namespace Subsurface.Lights
|
|||||||
currentIndex = (currentIndex + 1) % primitiveCount;
|
currentIndex = (currentIndex + 1) % primitiveCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (los)
|
||||||
|
{
|
||||||
|
CalculatePenumbraVertices(startingIndex, endingIndex, lightSourcePos, los);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CalculatePenumbraVertices(int startingIndex, int endingIndex, Vector2 lightSourcePos, bool los)
|
||||||
|
{
|
||||||
|
penumbraVertices = new VertexPositionTexture[6];
|
||||||
|
|
||||||
|
for (int n = 0; n < 4; n += 3)
|
||||||
|
{
|
||||||
|
Vector3 penumbraStart = new Vector3((n == 0) ? vertices[startingIndex] : vertices[endingIndex], 0.0f);
|
||||||
|
|
||||||
|
penumbraVertices[n] = new VertexPositionTexture();
|
||||||
|
penumbraVertices[n].Position = penumbraStart;
|
||||||
|
penumbraVertices[n].TextureCoordinate = new Vector2(0.0f, 1.0f);
|
||||||
|
//penumbraVertices[0].te = fow ? Color.Black : Color.Transparent;
|
||||||
|
|
||||||
|
for (int i = 0; i < 2; i++)
|
||||||
|
{
|
||||||
|
penumbraVertices[n + i + 1] = new VertexPositionTexture();
|
||||||
|
Vector3 vertexDir = penumbraStart - new Vector3(lightSourcePos, 0);
|
||||||
|
vertexDir.Normalize();
|
||||||
|
|
||||||
|
Vector3 normal = (i == 0) ? new Vector3(-vertexDir.Y, vertexDir.X, 0.0f) : new Vector3(vertexDir.Y, -vertexDir.X, 0.0f) * 0.05f;
|
||||||
|
if (n > 0) normal = -normal;
|
||||||
|
|
||||||
|
vertexDir = penumbraStart - (new Vector3(lightSourcePos, 0) - normal * 20.0f);
|
||||||
|
vertexDir.Normalize();
|
||||||
|
penumbraVertices[n + i + 1].Position = new Vector3(lightSourcePos, 0) + vertexDir * 9000;
|
||||||
|
|
||||||
|
if (los)
|
||||||
|
{
|
||||||
|
penumbraVertices[n + i + 1].TextureCoordinate = (i == 0) ? new Vector2(0.05f, 0.0f) : new Vector2(1.0f, 0.0f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
penumbraVertices[n + i + 1].TextureCoordinate = (i == 0) ? new Vector2(1.0f, 0.0f) : Vector2.Zero;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n > 0)
|
||||||
|
{
|
||||||
|
var temp = penumbraVertices[4];
|
||||||
|
penumbraVertices[4] = penumbraVertices[5];
|
||||||
|
penumbraVertices[5] = temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawShadows(GraphicsDevice graphicsDevice, Camera cam, Vector2 lightSourcePos, Matrix transform, bool los = true)
|
||||||
|
{
|
||||||
|
if (!Enabled) return;
|
||||||
|
|
||||||
|
CalculateShadowVertices(lightSourcePos, los);
|
||||||
|
|
||||||
|
|
||||||
shadowEffect.World = transform;
|
shadowEffect.World = transform;
|
||||||
shadowEffect.CurrentTechnique.Passes[0].Apply();
|
shadowEffect.CurrentTechnique.Passes[0].Apply();
|
||||||
|
|
||||||
graphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleStrip, shadowVertices, 0, shadowVertexCount * 2 - 2);
|
graphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleStrip, shadowVertices, 0, shadowVertices.Length - 2);
|
||||||
|
|
||||||
if (los)
|
if (los)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ namespace Subsurface
|
|||||||
set { rect = value; }
|
set { rect = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual Sprite sprite
|
public virtual Sprite Sprite
|
||||||
{
|
{
|
||||||
get { return null; }
|
get { return null; }
|
||||||
}
|
}
|
||||||
@@ -150,6 +150,28 @@ namespace Subsurface
|
|||||||
return (Submarine.RectContains(rect, position));
|
return (Submarine.RectContains(rect, position));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void InsertToList()
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
if (Sprite==null)
|
||||||
|
{
|
||||||
|
mapEntityList.Add(this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (i<mapEntityList.Count)
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
|
||||||
|
Sprite existingSprite = mapEntityList[i-1].Sprite;
|
||||||
|
if (existingSprite == null) continue;
|
||||||
|
if (existingSprite.Texture == this.Sprite.Texture) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
mapEntityList.Insert(i, this);
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void Draw(SpriteBatch spriteBatch, bool editing) {}
|
public virtual void Draw(SpriteBatch spriteBatch, bool editing) {}
|
||||||
|
|
||||||
public override void Remove()
|
public override void Remove()
|
||||||
@@ -227,8 +249,8 @@ namespace Subsurface
|
|||||||
|
|
||||||
foreach (MapEntity e in mapEntityList)
|
foreach (MapEntity e in mapEntityList)
|
||||||
{
|
{
|
||||||
if (highLightedEntity == null || e.sprite == null ||
|
if (highLightedEntity == null || e.Sprite == null ||
|
||||||
(highLightedEntity.sprite!=null && e.sprite.Depth < highLightedEntity.sprite.Depth))
|
(highLightedEntity.Sprite!=null && e.Sprite.Depth < highLightedEntity.Sprite.Depth))
|
||||||
{
|
{
|
||||||
if (e.Contains(position)) highLightedEntity = e;
|
if (e.Contains(position)) highLightedEntity = e;
|
||||||
}
|
}
|
||||||
@@ -448,7 +470,7 @@ namespace Subsurface
|
|||||||
/// Has to be done after all the entities have been loaded (an entity can't
|
/// Has to be done after all the entities have been loaded (an entity can't
|
||||||
/// be linked to some other entity that hasn't been loaded yet)
|
/// be linked to some other entity that hasn't been loaded yet)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void LinkAll()
|
public static void OnMapLoaded()
|
||||||
{
|
{
|
||||||
foreach (MapEntity e in mapEntityList)
|
foreach (MapEntity e in mapEntityList)
|
||||||
{
|
{
|
||||||
@@ -465,7 +487,15 @@ namespace Subsurface
|
|||||||
e.linkedTo.Add(linked);
|
e.linkedTo.Add(linked);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//mapEntityList.Sort((x, y) =>
|
||||||
|
//{
|
||||||
|
// return x.Name.CompareTo(y.Name);
|
||||||
|
//});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void RemoveLinked(MapEntity e)
|
public void RemoveLinked(MapEntity e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ namespace Subsurface
|
|||||||
|
|
||||||
bool isHorizontal;
|
bool isHorizontal;
|
||||||
|
|
||||||
public override Sprite sprite
|
public override Sprite Sprite
|
||||||
{
|
{
|
||||||
get { return prefab.sprite; }
|
get { return prefab.sprite; }
|
||||||
}
|
}
|
||||||
@@ -265,7 +265,7 @@ namespace Subsurface
|
|||||||
convexHull = new ConvexHull(corners, Color.Black);
|
convexHull = new ConvexHull(corners, Color.Black);
|
||||||
}
|
}
|
||||||
|
|
||||||
mapEntityList.Add(this);
|
InsertToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Remove()
|
public override void Remove()
|
||||||
@@ -290,19 +290,22 @@ namespace Subsurface
|
|||||||
|
|
||||||
Color color = (isHighlighted) ? Color.Green : Color.White;
|
Color color = (isHighlighted) ? Color.Green : Color.White;
|
||||||
if (isSelected && editing) color = Color.Red;
|
if (isSelected && editing) color = Color.Red;
|
||||||
|
|
||||||
|
prefab.sprite.DrawTiled(spriteBatch, new Vector2(rect.X, -rect.Y), new Vector2(rect.Width, rect.Height), Vector2.Zero, color);
|
||||||
|
|
||||||
prefab.sprite.DrawTiled(spriteBatch, new Vector2(rect.X, -rect.Y), new Vector2(rect.Width, rect.Height), Vector2.Zero, color);
|
|
||||||
|
|
||||||
foreach (WallSection s in sections)
|
foreach (WallSection s in sections)
|
||||||
{
|
{
|
||||||
if (s.isHighLighted)
|
if (s.isHighLighted)
|
||||||
|
{
|
||||||
GUI.DrawRectangle(spriteBatch,
|
GUI.DrawRectangle(spriteBatch,
|
||||||
new Rectangle((int)s.rect.X, (int)-s.rect.Y, (int)s.rect.Width, (int)s.rect.Height),
|
new Rectangle((int)s.rect.X, (int)-s.rect.Y, (int)s.rect.Width, (int)s.rect.Height),
|
||||||
new Color((s.damage / prefab.MaxHealth), 1.0f - (s.damage / prefab.MaxHealth), 0.0f, 1.0f), true);
|
new Color((s.damage / prefab.MaxHealth), 1.0f - (s.damage / prefab.MaxHealth), 0.0f, 1.0f), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
s.isHighLighted = false;
|
s.isHighLighted = false;
|
||||||
|
|
||||||
if (s.damage == 0.0f) continue;
|
if (s.damage < 0.01f) continue;
|
||||||
|
|
||||||
GUI.DrawRectangle(spriteBatch,
|
GUI.DrawRectangle(spriteBatch,
|
||||||
new Rectangle((int)s.rect.X, (int)-s.rect.Y, (int)s.rect.Width, (int)s.rect.Height),
|
new Rectangle((int)s.rect.X, (int)-s.rect.Y, (int)s.rect.Width, (int)s.rect.Height),
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ namespace Subsurface
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < MapEntity.mapEntityList.Count(); i++)
|
for (int i = 0; i < MapEntity.mapEntityList.Count(); i++)
|
||||||
{
|
{
|
||||||
if (MapEntity.mapEntityList[i].sprite == null || MapEntity.mapEntityList[i].sprite.Depth < 0.5f)
|
if (MapEntity.mapEntityList[i].Sprite == null || MapEntity.mapEntityList[i].Sprite.Depth < 0.5f)
|
||||||
MapEntity.mapEntityList[i].Draw(spriteBatch, editing);
|
MapEntity.mapEntityList[i].Draw(spriteBatch, editing);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,7 +181,7 @@ namespace Subsurface
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < MapEntity.mapEntityList.Count(); i++)
|
for (int i = 0; i < MapEntity.mapEntityList.Count(); i++)
|
||||||
{
|
{
|
||||||
if (MapEntity.mapEntityList[i].sprite == null || MapEntity.mapEntityList[i].sprite.Depth >= 0.5f)
|
if (MapEntity.mapEntityList[i].Sprite == null || MapEntity.mapEntityList[i].Sprite.Depth >= 0.5f)
|
||||||
MapEntity.mapEntityList[i].Draw(spriteBatch, editing);
|
MapEntity.mapEntityList[i].Draw(spriteBatch, editing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -603,7 +603,7 @@ namespace Subsurface
|
|||||||
|
|
||||||
subBody = new SubmarineBody(this);
|
subBody = new SubmarineBody(this);
|
||||||
|
|
||||||
MapEntity.LinkAll();
|
MapEntity.OnMapLoaded();
|
||||||
|
|
||||||
foreach (Item item in Item.itemList)
|
foreach (Item item in Item.itemList)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ namespace Subsurface
|
|||||||
linkedTo = new ObservableCollection<MapEntity>();
|
linkedTo = new ObservableCollection<MapEntity>();
|
||||||
idCardTags = new string[0];
|
idCardTags = new string[0];
|
||||||
|
|
||||||
mapEntityList.Add(this);
|
InsertToList();
|
||||||
WayPointList.Add(this);
|
WayPointList.Add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -436,9 +436,6 @@ namespace Subsurface.Networking
|
|||||||
userID = inc.ReadInt32();
|
userID = inc.ReadInt32();
|
||||||
userPassword = inc.ReadString();
|
userPassword = inc.ReadString();
|
||||||
version = inc.ReadString();
|
version = inc.ReadString();
|
||||||
#if DEBUG
|
|
||||||
version = GameMain.Version.ToString();
|
|
||||||
#endif
|
|
||||||
packageName = inc.ReadString();
|
packageName = inc.ReadString();
|
||||||
packageHash = inc.ReadString();
|
packageHash = inc.ReadString();
|
||||||
name = inc.ReadString();
|
name = inc.ReadString();
|
||||||
@@ -450,6 +447,8 @@ namespace Subsurface.Networking
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !DEBUG
|
||||||
|
|
||||||
if (userPassword != password)
|
if (userPassword != password)
|
||||||
{
|
{
|
||||||
inc.SenderConnection.Deny("Wrong password!");
|
inc.SenderConnection.Deny("Wrong password!");
|
||||||
@@ -481,6 +480,8 @@ namespace Subsurface.Networking
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
//existing user re-joining
|
//existing user re-joining
|
||||||
if (userID > 0)
|
if (userID > 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -226,6 +226,8 @@ namespace Subsurface
|
|||||||
body.CollidesWith = Physics.CollisionWall;
|
body.CollidesWith = Physics.CollisionWall;
|
||||||
|
|
||||||
body.Friction = ToolBox.GetAttributeFloat(element, "friction", 0.3f);
|
body.Friction = ToolBox.GetAttributeFloat(element, "friction", 0.3f);
|
||||||
|
body.Restitution = 0.05f;
|
||||||
|
|
||||||
|
|
||||||
body.BodyType = BodyType.Dynamic;
|
body.BodyType = BodyType.Dynamic;
|
||||||
//body.AngularDamping = Limb.LimbAngularDamping;
|
//body.AngularDamping = Limb.LimbAngularDamping;
|
||||||
@@ -307,9 +309,14 @@ namespace Subsurface
|
|||||||
UpdateDrawPosition();
|
UpdateDrawPosition();
|
||||||
|
|
||||||
SpriteEffects spriteEffect = (dir == 1.0f) ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
|
SpriteEffects spriteEffect = (dir == 1.0f) ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
|
||||||
|
|
||||||
|
if (GameMain.DebugDraw && !body.Awake)
|
||||||
|
{
|
||||||
|
color = Color.Blue;
|
||||||
|
}
|
||||||
|
|
||||||
sprite.Draw(spriteBatch, new Vector2(drawPosition.X, -drawPosition.Y), color, -drawRotation, 1.0f, spriteEffect, depth);
|
sprite.Draw(spriteBatch, new Vector2(drawPosition.X, -drawPosition.Y), color, -drawRotation, 1.0f, spriteEffect, depth);
|
||||||
|
|
||||||
//prevPosition = body.Position;
|
//prevPosition = body.Position;
|
||||||
//prevRotation = body.Rotation;
|
//prevRotation = body.Rotation;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using Microsoft.Xna.Framework;
|
|||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
using Subsurface.Lights;
|
using Subsurface.Lights;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace Subsurface
|
namespace Subsurface
|
||||||
{
|
{
|
||||||
@@ -57,8 +58,15 @@ namespace Subsurface
|
|||||||
//http://gafferongames.com/game-physics/fix-your-timestep/
|
//http://gafferongames.com/game-physics/fix-your-timestep/
|
||||||
Physics.accumulator += deltaTime;
|
Physics.accumulator += deltaTime;
|
||||||
|
|
||||||
|
Stopwatch sw = new Stopwatch();
|
||||||
|
sw.Start();
|
||||||
|
|
||||||
AmbientSoundManager.Update();
|
AmbientSoundManager.Update();
|
||||||
|
|
||||||
|
sw.Stop();
|
||||||
|
Debug.WriteLine("************** abupdate: "+sw.ElapsedTicks);
|
||||||
|
sw.Restart();
|
||||||
|
|
||||||
//if (Game1.GameSession != null && Game1.GameSession.Level != null)
|
//if (Game1.GameSession != null && Game1.GameSession.Level != null)
|
||||||
//{
|
//{
|
||||||
// Vector2 targetMovement = Vector2.Zero;
|
// Vector2 targetMovement = Vector2.Zero;
|
||||||
@@ -73,17 +81,38 @@ namespace Subsurface
|
|||||||
if (GameMain.GameSession!=null) GameMain.GameSession.Update((float)deltaTime);
|
if (GameMain.GameSession!=null) GameMain.GameSession.Update((float)deltaTime);
|
||||||
//EventManager.Update(gameTime);
|
//EventManager.Update(gameTime);
|
||||||
|
|
||||||
|
sw.Stop();
|
||||||
|
Debug.WriteLine("gamesession update: " + sw.ElapsedTicks);
|
||||||
|
sw.Restart();
|
||||||
|
|
||||||
Character.UpdateAll(cam, (float)deltaTime);
|
Character.UpdateAll(cam, (float)deltaTime);
|
||||||
|
|
||||||
BackgroundSpriteManager.Update((float)deltaTime);
|
sw.Stop();
|
||||||
|
Debug.WriteLine("characterupdate: " + sw.ElapsedTicks);
|
||||||
|
sw.Restart();
|
||||||
|
|
||||||
|
BackgroundSpriteManager.Update(cam, (float)deltaTime);
|
||||||
|
|
||||||
|
sw.Stop();
|
||||||
|
Debug.WriteLine("bgsprite: " + sw.ElapsedTicks);
|
||||||
|
sw.Restart();
|
||||||
|
|
||||||
GameMain.ParticleManager.Update((float)deltaTime);
|
GameMain.ParticleManager.Update((float)deltaTime);
|
||||||
|
|
||||||
|
sw.Stop();
|
||||||
|
Debug.WriteLine("particlemanager: " + sw.ElapsedTicks);
|
||||||
|
sw.Restart();
|
||||||
|
|
||||||
StatusEffect.UpdateAll((float)deltaTime);
|
StatusEffect.UpdateAll((float)deltaTime);
|
||||||
|
|
||||||
|
sw.Stop();
|
||||||
|
Debug.WriteLine("statuseff: " + sw.ElapsedTicks);
|
||||||
|
|
||||||
|
|
||||||
Physics.accumulator = Math.Min(Physics.accumulator, Physics.step * 4);
|
Physics.accumulator = Math.Min(Physics.accumulator, Physics.step * 4);
|
||||||
while (Physics.accumulator >= Physics.step)
|
while (Physics.accumulator >= Physics.step)
|
||||||
{
|
{
|
||||||
|
sw.Restart();
|
||||||
cam.MoveCamera((float)Physics.step);
|
cam.MoveCamera((float)Physics.step);
|
||||||
|
|
||||||
foreach (PhysicsBody pb in PhysicsBody.list)
|
foreach (PhysicsBody pb in PhysicsBody.list)
|
||||||
@@ -93,8 +122,16 @@ namespace Subsurface
|
|||||||
|
|
||||||
MapEntity.UpdateAll(cam, (float)Physics.step);
|
MapEntity.UpdateAll(cam, (float)Physics.step);
|
||||||
|
|
||||||
|
sw.Stop();
|
||||||
|
Debug.WriteLine(" mapentity: " + sw.ElapsedTicks);
|
||||||
|
sw.Restart();
|
||||||
|
|
||||||
Character.UpdateAnimAll((float)Physics.step);
|
Character.UpdateAnimAll((float)Physics.step);
|
||||||
|
|
||||||
|
sw.Stop();
|
||||||
|
Debug.WriteLine(" char: " + sw.ElapsedTicks);
|
||||||
|
sw.Restart();
|
||||||
|
|
||||||
Ragdoll.UpdateAll((float)Physics.step);
|
Ragdoll.UpdateAll((float)Physics.step);
|
||||||
|
|
||||||
if (GameMain.GameSession != null && GameMain.GameSession.Level != null)
|
if (GameMain.GameSession != null && GameMain.GameSession.Level != null)
|
||||||
@@ -102,8 +139,16 @@ namespace Subsurface
|
|||||||
GameMain.GameSession.Submarine.Update((float)Physics.step);
|
GameMain.GameSession.Submarine.Update((float)Physics.step);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sw.Stop();
|
||||||
|
Debug.WriteLine(" sub: " + sw.ElapsedTicks);
|
||||||
|
sw.Restart();
|
||||||
|
|
||||||
GameMain.World.Step((float)Physics.step);
|
GameMain.World.Step((float)Physics.step);
|
||||||
|
|
||||||
|
sw.Stop();
|
||||||
|
Debug.WriteLine(" worldstep: " + sw.ElapsedTicks);
|
||||||
|
sw.Restart();
|
||||||
|
|
||||||
Level.AfterWorldStep();
|
Level.AfterWorldStep();
|
||||||
|
|
||||||
Physics.accumulator -= Physics.step;
|
Physics.accumulator -= Physics.step;
|
||||||
@@ -146,7 +191,7 @@ namespace Subsurface
|
|||||||
public void DrawMap(GraphicsDevice graphics, SpriteBatch spriteBatch)
|
public void DrawMap(GraphicsDevice graphics, SpriteBatch spriteBatch)
|
||||||
{
|
{
|
||||||
GameMain.LightManager.DrawLightmap(graphics, spriteBatch, cam);
|
GameMain.LightManager.DrawLightmap(graphics, spriteBatch, cam);
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------
|
||||||
//1. draw the background, characters and the parts of the submarine that are behind them
|
//1. draw the background, characters and the parts of the submarine that are behind them
|
||||||
//----------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------
|
||||||
@@ -200,7 +245,7 @@ namespace Subsurface
|
|||||||
Submarine.DrawBack(spriteBatch);
|
Submarine.DrawBack(spriteBatch);
|
||||||
|
|
||||||
foreach (Character c in Character.CharacterList) c.Draw(spriteBatch);
|
foreach (Character c in Character.CharacterList) c.Draw(spriteBatch);
|
||||||
|
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------
|
||||||
@@ -213,10 +258,6 @@ namespace Subsurface
|
|||||||
spriteBatch.Draw(renderTarget, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), new Color(0.75f, 0.8f, 0.9f, 1.0f));
|
spriteBatch.Draw(renderTarget, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), new Color(0.75f, 0.8f, 0.9f, 1.0f));
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
|
|
||||||
BlendState blend = new BlendState();
|
|
||||||
blend.AlphaSourceBlend = Blend.One;
|
|
||||||
blend.AlphaDestinationBlend = Blend.InverseSourceAlpha;
|
|
||||||
|
|
||||||
spriteBatch.Begin(SpriteSortMode.Immediate,
|
spriteBatch.Begin(SpriteSortMode.Immediate,
|
||||||
BlendState.AlphaBlend,
|
BlendState.AlphaBlend,
|
||||||
null, DepthStencilState.DepthRead, null, null,
|
null, DepthStencilState.DepthRead, null, null,
|
||||||
@@ -258,7 +299,7 @@ namespace Subsurface
|
|||||||
}
|
}
|
||||||
|
|
||||||
Hull.renderer.Render(graphics, cam, renderTargetAir, Cam.ShaderTransform);
|
Hull.renderer.Render(graphics, cam, renderTargetAir, Cam.ShaderTransform);
|
||||||
|
|
||||||
if (GameMain.GameSession != null && GameMain.GameSession.Level != null)
|
if (GameMain.GameSession != null && GameMain.GameSession.Level != null)
|
||||||
{
|
{
|
||||||
GameMain.GameSession.Level.Render(graphics, cam);
|
GameMain.GameSession.Level.Render(graphics, cam);
|
||||||
@@ -285,17 +326,16 @@ namespace Subsurface
|
|||||||
Submarine.DrawFront(spriteBatch);
|
Submarine.DrawFront(spriteBatch);
|
||||||
|
|
||||||
foreach (Character c in Character.CharacterList) c.DrawFront(spriteBatch);
|
foreach (Character c in Character.CharacterList) c.DrawFront(spriteBatch);
|
||||||
|
|
||||||
if (GameMain.GameSession != null && GameMain.GameSession.Level != null)
|
//if (GameMain.GameSession != null && GameMain.GameSession.Level != null)
|
||||||
{
|
//{
|
||||||
GameMain.GameSession.Level.Draw(spriteBatch);
|
// GameMain.GameSession.Level.Draw(spriteBatch);
|
||||||
//Game1.GameSession.Level.SetObserverPosition(cam.WorldViewCenter);
|
// //Game1.GameSession.Level.SetObserverPosition(cam.WorldViewCenter);
|
||||||
}
|
//}
|
||||||
|
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
|
|
||||||
GameMain.LightManager.DrawLOS(graphics, cam, LightManager.ViewPos);
|
GameMain.LightManager.DrawLOS(graphics, cam, LightManager.ViewPos);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,9 +80,9 @@ namespace Subsurface
|
|||||||
if (!path.EndsWith("/")) path += "/";
|
if (!path.EndsWith("/")) path += "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
file = path + file;
|
this.file = path + file;
|
||||||
|
|
||||||
texture = LoadTexture(file);
|
texture = LoadTexture(this.file);
|
||||||
|
|
||||||
if (texture == null) return;
|
if (texture == null) return;
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Launcher2", "Launcher2\Laun
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CrashReporter", "CrashReporter\CrashReporter.csproj", "{6BE950CD-9A34-49C9-939A-786AC89C287E}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CrashReporter", "CrashReporter\CrashReporter.csproj", "{6BE950CD-9A34-49C9-939A-786AC89C287E}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D32A29D8-AC7B-4189-B734-8ED9EB4120D0}"
|
||||||
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
Performance1.psess = Performance1.psess
|
||||||
|
EndProjectSection
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Android|Any CPU = Android|Any CPU
|
Android|Any CPU = Android|Any CPU
|
||||||
@@ -396,4 +401,7 @@ Global
|
|||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
|
GlobalSection(Performance) = preSolution
|
||||||
|
HasPerformanceSessions = true
|
||||||
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user