From 59bff34bb107c8779d4621a126b36bddd3b2214f Mon Sep 17 00:00:00 2001 From: Regalis Date: Tue, 29 Sep 2015 20:06:15 +0300 Subject: [PATCH] Simpler anim logic for off-screen characters (all limbs except refLimb are hidden) --- Backup/ChainingPropertyDescriptor.cs | 108 --------- Backup/HyperPropertyDescriptor.csproj | 50 ---- Backup/HyperPropertyDescriptor.csproj.user | 5 - Backup/HyperTypeDescriptionProvider.cs | 74 ------ Backup/HyperTypeDescriptor.cs | 218 ------------------ Backup/Properties/AssemblyInfo.cs | 38 --- Subsurface/Source/Characters/Character.cs | 11 +- .../Source/Characters/FishAnimController.cs | 36 ++- .../Characters/HumanoidAnimController.cs | 37 ++- Subsurface/Source/Characters/Ragdoll.cs | 38 ++- .../Source/Events/Quests/MonsterQuest.cs | 7 +- .../Items/Components/Machines/Reactor.cs | 2 +- Subsurface/Source/Map/Levels/Level.cs | 17 +- .../Source/Screens/EditCharacterScreen.cs | 2 +- Subsurface/Source/Screens/GameScreen.cs | 2 +- Subsurface_Solution.v12.suo | Bin 746496 -> 746496 bytes 16 files changed, 116 insertions(+), 529 deletions(-) delete mode 100644 Backup/ChainingPropertyDescriptor.cs delete mode 100644 Backup/HyperPropertyDescriptor.csproj delete mode 100644 Backup/HyperPropertyDescriptor.csproj.user delete mode 100644 Backup/HyperTypeDescriptionProvider.cs delete mode 100644 Backup/HyperTypeDescriptor.cs delete mode 100644 Backup/Properties/AssemblyInfo.cs diff --git a/Backup/ChainingPropertyDescriptor.cs b/Backup/ChainingPropertyDescriptor.cs deleted file mode 100644 index 997cfb27c..000000000 --- a/Backup/ChainingPropertyDescriptor.cs +++ /dev/null @@ -1,108 +0,0 @@ -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(); - } - } -} diff --git a/Backup/HyperPropertyDescriptor.csproj b/Backup/HyperPropertyDescriptor.csproj deleted file mode 100644 index cf60a1d62..000000000 --- a/Backup/HyperPropertyDescriptor.csproj +++ /dev/null @@ -1,50 +0,0 @@ - - - Debug - AnyCPU - 8.0.50727 - 2.0 - {954502B1-7282-417D-9310-3332962A1CA1} - Library - Properties - HyperPropertyDescriptor - HyperPropertyDescriptor - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - false - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Backup/HyperPropertyDescriptor.csproj.user b/Backup/HyperPropertyDescriptor.csproj.user deleted file mode 100644 index 6a34e7dcd..000000000 --- a/Backup/HyperPropertyDescriptor.csproj.user +++ /dev/null @@ -1,5 +0,0 @@ - - - ShowAllFiles - - \ No newline at end of file diff --git a/Backup/HyperTypeDescriptionProvider.cs b/Backup/HyperTypeDescriptionProvider.cs deleted file mode 100644 index f21c47d85..000000000 --- a/Backup/HyperTypeDescriptionProvider.cs +++ /dev/null @@ -1,74 +0,0 @@ -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 descriptors = new Dictionary(); - 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; - } - } - } -} diff --git a/Backup/HyperTypeDescriptor.cs b/Backup/HyperTypeDescriptor.cs deleted file mode 100644 index d47858bca..000000000 --- a/Backup/HyperTypeDescriptor.cs +++ /dev/null @@ -1,218 +0,0 @@ -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 properties = new Dictionary(); - 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; - } - } - } -} diff --git a/Backup/Properties/AssemblyInfo.cs b/Backup/Properties/AssemblyInfo.cs deleted file mode 100644 index 89228e1b0..000000000 --- a/Backup/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,38 +0,0 @@ -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")] diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index f5a58ec55..1962bc932 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -601,11 +601,10 @@ namespace Subsurface /// public void ControlLocalPlayer(float deltaTime, Camera cam, bool moveCam = true) { - //if (isDead) - //{ - - // return; - //} + if (PlayerInput.KeyHit(Keys.U)) + { + AnimController.SimplePhysicsEnabled = !AnimController.SimplePhysicsEnabled; + } Limb head = AnimController.GetLimb(LimbType.Head); @@ -747,6 +746,8 @@ namespace Subsurface public virtual void Update(Camera cam, float deltaTime) { + AnimController.SimplePhysicsEnabled = (Character.controlled!=this && Vector2.Distance(cam.WorldViewCenter, Position)>2000.0f); + if (isDead) return; if (PressureProtection==0.0f && diff --git a/Subsurface/Source/Characters/FishAnimController.cs b/Subsurface/Source/Characters/FishAnimController.cs index 491c34364..9ef14ac76 100644 --- a/Subsurface/Source/Characters/FishAnimController.cs +++ b/Subsurface/Source/Characters/FishAnimController.cs @@ -4,6 +4,7 @@ using System.Xml.Linq; using FarseerPhysics; using FarseerPhysics.Dynamics.Joints; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input; namespace Subsurface { @@ -48,6 +49,11 @@ namespace Subsurface public override void UpdateAnim(float deltaTime) { + if (PlayerInput.KeyHit(Keys.I)) + { + SimplePhysicsEnabled = !SimplePhysicsEnabled; + } + if (character.IsDead) { UpdateDying(deltaTime); @@ -68,6 +74,10 @@ namespace Subsurface stunTimer -= deltaTime; return; } + else if (SimplePhysicsEnabled) + { + UpdateSimpleAnim(); + } else { if (inWater) @@ -80,7 +90,6 @@ namespace Subsurface } } - if (flip) { //targetDir = (movement.X > 0.0f) ? Direction.Right : Direction.Left; @@ -208,6 +217,31 @@ namespace Subsurface floorY = Limbs[0].SimPosition.Y; } } + + void UpdateSimpleAnim() + { + movement = MathUtils.SmoothStep(movement, TargetMovement*swimSpeed, 1.0f); + if (movement == Vector2.Zero) return; + + float movementAngle = MathUtils.VectorToAngle(movement) - MathHelper.PiOver2; + + RefLimb.body.SmoothRotate( + (rotateTowardsMovement) ? + RefLimb.body.Rotation + MathUtils.GetShortestAngle(RefLimb.body.Rotation, movementAngle) : + HeadAngle*Dir); + + RefLimb.pullJoint.Enabled = true; + RefLimb.pullJoint.WorldAnchorB = + RefLimb.SimPosition + movement * 0.1f; + + RefLimb.body.SmoothRotate(0.0f); + + foreach (Limb l in Limbs) + { + if (l == RefLimb) continue; + l.body.SetTransform(RefLimb.SimPosition, RefLimb.Rotation); + } + } void UpdateWalkAnim(float deltaTime) { diff --git a/Subsurface/Source/Characters/HumanoidAnimController.cs b/Subsurface/Source/Characters/HumanoidAnimController.cs index cc79e911a..0f19a120e 100644 --- a/Subsurface/Source/Characters/HumanoidAnimController.cs +++ b/Subsurface/Source/Characters/HumanoidAnimController.cs @@ -30,8 +30,8 @@ namespace Subsurface public override void UpdateAnim(float deltaTime) { - if (character.IsDead) return; - + if (character.IsDead) return; + Vector2 colliderPos = GetLimb(LimbType.Torso).SimPosition; //if (inWater) stairs = null; @@ -136,6 +136,15 @@ namespace Subsurface return; } + if (TargetDir != dir) Flip(); + + if (SimplePhysicsEnabled) + { + UpdateStandingSimple(); + return; + } + + switch (Anim) { case Animation.Climbing: @@ -152,7 +161,6 @@ namespace Subsurface break; } - if (TargetDir != dir) Flip(); foreach (Limb limb in Limbs) { @@ -389,6 +397,29 @@ namespace Subsurface } + void UpdateStandingSimple() + { + movement = MathUtils.SmoothStep(movement, TargetMovement, movementLerp); + + if (inWater && movement != Vector2.Zero) + { + movement = Vector2.Normalize(movement); + } + + RefLimb.pullJoint.Enabled = true; + RefLimb.pullJoint.WorldAnchorB = + RefLimb.SimPosition + movement*0.15f; + + RefLimb.body.SmoothRotate(0.0f); + + foreach (Limb l in Limbs) + { + if (l==RefLimb) continue; + l.body.SetTransform(RefLimb.SimPosition, RefLimb.Rotation); + } + //new Vector2(movement.X, floorY + HeadPosition), 0.5f); + } + void UpdateSwimming() { IgnorePlatforms = true; diff --git a/Subsurface/Source/Characters/Ragdoll.cs b/Subsurface/Source/Characters/Ragdoll.cs index bff201eea..849d84a57 100644 --- a/Subsurface/Source/Characters/Ragdoll.cs +++ b/Subsurface/Source/Characters/Ragdoll.cs @@ -22,7 +22,9 @@ namespace Subsurface private Dictionary limbDictionary; public RevoluteJoint[] limbJoints; - Character character; + private bool simplePhysicsEnabled; + + private Character character; private Limb lowestLimb; @@ -76,6 +78,29 @@ namespace Subsurface private set; } + public bool SimplePhysicsEnabled + { + get { return simplePhysicsEnabled; } + set + { + if (value == simplePhysicsEnabled) return; + + simplePhysicsEnabled = value; + + foreach (Limb limb in Limbs) + { + limb.body.Enabled = !simplePhysicsEnabled; + } + + foreach (RevoluteJoint joint in limbJoints) + { + joint.Enabled = !simplePhysicsEnabled; + } + + refLimb.body.Enabled = true; + } + } + public Vector2 TargetMovement { get @@ -473,11 +498,11 @@ namespace Subsurface } } - public static void UpdateAll(float deltaTime) + public static void UpdateAll(Camera cam, float deltaTime) { foreach (Ragdoll r in list) { - r.Update(deltaTime); + r.Update(cam, deltaTime); } } @@ -491,10 +516,12 @@ namespace Subsurface currentHull); } - public void Update(float deltaTime) + public void Update(Camera cam, float deltaTime) { UpdateNetplayerPosition(); + + Vector2 flowForce = Vector2.Zero; FindLowestLimb(); @@ -537,8 +564,7 @@ namespace Subsurface limb.inWater = true; } else if (limbHull.Volume > 0.0f && Submarine.RectContains(limbHull.Rect, limbPosition)) - { - + { if (limbPosition.Y < limbHull.Surface) { limb.inWater = true; diff --git a/Subsurface/Source/Events/Quests/MonsterQuest.cs b/Subsurface/Source/Events/Quests/MonsterQuest.cs index f88110803..686ae94ac 100644 --- a/Subsurface/Source/Events/Quests/MonsterQuest.cs +++ b/Subsurface/Source/Events/Quests/MonsterQuest.cs @@ -18,10 +18,7 @@ namespace Subsurface public override Vector2 RadarPosition { - get - { - return monster.Position; - } + get { return monster.Position; } } public MonsterQuest(XElement element) @@ -34,7 +31,7 @@ namespace Subsurface { Vector2 position = level.PositionsOfInterest[Rand.Int(level.PositionsOfInterest.Count, false)]; - monster = new Character(monsterFile, ConvertUnits.ToSimUnits(position+level.Position)); + monster = new AICharacter(monsterFile, ConvertUnits.ToSimUnits(position+level.Position)); } public override void End() diff --git a/Subsurface/Source/Items/Components/Machines/Reactor.cs b/Subsurface/Source/Items/Components/Machines/Reactor.cs index 7420c9342..8cfc099b9 100644 --- a/Subsurface/Source/Items/Components/Machines/Reactor.cs +++ b/Subsurface/Source/Items/Components/Machines/Reactor.cs @@ -206,7 +206,7 @@ namespace Subsurface.Items.Components if (item.CurrentHull != null) { //the sound can be heard from 20 000 display units away when everything running at 100% - item.CurrentHull.SoundRange += (coolingRate + fissionRate) * 100; + item.CurrentHull.SoundRange = (coolingRate + fissionRate) * 100; } UpdateGraph(deltaTime); diff --git a/Subsurface/Source/Map/Levels/Level.cs b/Subsurface/Source/Map/Levels/Level.cs index ef8664c0e..2ccacad2f 100644 --- a/Subsurface/Source/Map/Levels/Level.cs +++ b/Subsurface/Source/Map/Levels/Level.cs @@ -728,19 +728,10 @@ int currentTargetIndex = 1; } } - foreach (MapEntity mapEntity in MapEntity.mapEntityList) - { - Item item = mapEntity as Item; - if (item == null) - { - //if (!mapEntity.MoveWithLevel) continue; - //mapEntity.Move(velocity); - } - else if (item.body!=null) - { - if (item.CurrentHull != null) continue; - item.body.LinearVelocity += simVelocity; - } + foreach (Item item in Item.itemList) + { + if (item.body==null || item.CurrentHull != null) continue; + item.body.LinearVelocity += simVelocity; } AtStartPosition = Vector2.Distance(startPosition, -Position) < ExitDistance; diff --git a/Subsurface/Source/Screens/EditCharacterScreen.cs b/Subsurface/Source/Screens/EditCharacterScreen.cs index adcc4fda8..dec16e249 100644 --- a/Subsurface/Source/Screens/EditCharacterScreen.cs +++ b/Subsurface/Source/Screens/EditCharacterScreen.cs @@ -110,7 +110,7 @@ namespace Subsurface { Character.UpdateAnimAll((float)Physics.step * 1000.0f); - Ragdoll.UpdateAll((float)Physics.step); + Ragdoll.UpdateAll(cam, (float)Physics.step); GameMain.World.Step((float)Physics.step); diff --git a/Subsurface/Source/Screens/GameScreen.cs b/Subsurface/Source/Screens/GameScreen.cs index 9d88a2f84..891779d48 100644 --- a/Subsurface/Source/Screens/GameScreen.cs +++ b/Subsurface/Source/Screens/GameScreen.cs @@ -132,7 +132,7 @@ namespace Subsurface Debug.WriteLine(" char: " + sw.ElapsedTicks); sw.Restart(); - Ragdoll.UpdateAll((float)Physics.step); + Ragdoll.UpdateAll(cam, (float)Physics.step); if (GameMain.GameSession != null && GameMain.GameSession.Level != null) { diff --git a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