Пример #1
0
        public static bool TryGetRopeData(long ropeEntityId, out MyRopeData ropeData)
        {
            ropeData = default(MyRopeData);
            InternalRopeData internalRopeData;
            if (m_ropeIdToRope.TryGetValue(ropeEntityId, out internalRopeData))
            {
                ropeData = internalRopeData.Public;
                return true;
            }

            return false;
        }
Пример #2
0
        public static long AddRopeData(MyRopeData publicData, long ropeId)
        {
            if (ropeId == 0)
                ropeId = MyEntityIdentifier.AllocateId();

            // Avoid referencing external objects during addition. They might not have been created yet.
            var ropeData = new InternalRopeData
            {
                Public = publicData,
                RopeId = ropeId,
            };

            Debug.Assert(!m_hookIdToRopeId.ContainsKey(ropeData.Public.HookEntityIdA), "Hook already has rope attached!");
            Debug.Assert(!m_hookIdToRopeId.ContainsKey(ropeData.Public.HookEntityIdB), "Hook already has rope attached!");
            Debug.Assert(!m_ropeIdToRope.ContainsKey(ropeData.RopeId), "Rope with given ID already exists!");
            m_ropeIdToRope[ropeData.RopeId] = ropeData;
            m_hookIdToRopeId[ropeData.Public.HookEntityIdA] = ropeId;
            m_hookIdToRopeId[ropeData.Public.HookEntityIdB] = ropeId;

            if (ropeData.Public.Definition.EnableRayCastRelease && Sync.IsServer)
            {
                m_ropeIdToRayCastRelease.Add(ropeId, ropeData);
            }

            m_ropeIdToInit.Add(ropeId);

            return ropeId;
        }
Пример #3
0
 public static void GetRopeData(long ropeEntityId, out MyRopeData ropeData)
 {
     ropeData = m_ropeIdToRope[ropeEntityId].Public;
 }
Пример #4
0
        public static long AddRopeData(long hookEntityIdA, long hookEntityIdB, MyRopeDefinition ropeDefinition, long ropeId)
        {
            MyEntity entityA, entityB;
            if (!MyEntities.TryGetEntityById(hookEntityIdA, out entityA))
                return 0;

            if (!MyEntities.TryGetEntityById(hookEntityIdB, out entityB))
                return 0;

            var hookA = m_hookIdToHook[hookEntityIdA];
            var hookB = m_hookIdToHook[hookEntityIdB];
            var posA = Vector3D.Transform(hookA.LocalPivot, entityA.WorldMatrix);
            var posB = Vector3D.Transform(hookB.LocalPivot, entityB.WorldMatrix);
            var maxRopeLength = (float)(posA - posB).Length();
            var ropeData = new MyRopeData
            {
                HookEntityIdA = hookEntityIdA,
                HookEntityIdB = hookEntityIdB,
                MaxRopeLength = maxRopeLength,
                CurrentRopeLength = maxRopeLength,
                Definition = ropeDefinition,
            };
            return AddRopeData(ropeData, ropeId);
        }