public ISrvBindable[] GetSrvs(MyPart part)
        {
            using (m_lock.AcquireExclusiveUsing())
            {
                PrepareFileTextures();

                Vector2I texResolution = new Vector2I(0, 0);

                if (part.StandardMaterial.Srvs != null && part.StandardMaterial.Srvs.Length >= 1)
                {
                    texResolution = part.StandardMaterial.Srvs[0].Size;
                }

                ISrvBindable gbuffer0Tex;
                // if the texture does not have size, resolving of mipmaping cannot be used
                if (texResolution == new Vector2I(0, 0))
                {
                    gbuffer0Tex = m_blackTexture;
                }
                else if (!m_textures.TryGetValue(texResolution, out gbuffer0Tex))
                {
                    gbuffer0Tex = CreateNewTexture(texResolution);
                    m_textures.Add(texResolution, gbuffer0Tex);
                }

                m_tmpSrvs[0] = gbuffer0Tex;
                m_tmpSrvs[1] = MyGeneratedTextureManager.ReleaseMissingNormalGlossTex;
                m_tmpSrvs[2] = MyGeneratedTextureManager.ReleaseMissingExtensionTex;

                return(m_tmpSrvs);
            }
        }
Exemple #2
0
        static void DrawHighlightedPart(MyRenderContext RC, MyPart part, MyInstanceLodState state)
        {
            // settings per part (using MyPart.cs):

            MyShaderBundle shaderBundle = part.GetShaderBundle(state);

            RC.SetInputLayout(shaderBundle.InputLayout);
            RC.VertexShader.Set(shaderBundle.VertexShader);
            RC.PixelShader.Set(shaderBundle.PixelShader);

            // (using MyHighlightPass.cs):
            RC.SetRasterizerState(null);

            RC.DrawIndexed(part.IndicesCount, part.StartIndex, part.StartVertex);
        }
Exemple #3
0
        private object GetClass(MyPart part)
        {
            ComposablePart composablePart = part.part.CreatePart();

            if (part.is_singleInstance)
            {
                string str = part.contractName + "|" + part.name + "|" + part.ver;
                if (!singleInstance.ContainsKey(str))
                {
                    singleInstance.Add(str, composablePart.GetExportedValue(part.exportDef));
                }
                return(singleInstance[str]);
            }
            return(composablePart.GetExportedValue(part.exportDef));
        }
Exemple #4
0
 private void UpdatePluginList()
 {
     partsDic.Clear();
     foreach (var T in catelog)
     {
         foreach (var def in T.ExportDefinitions)
         {
             MyPart myPart = new MyPart();
             myPart.contractName = def.ContractName;
             myPart.part         = T;
             myPart.exportDef    = def;
             if (def.Metadata.ContainsKey("Name"))
             {
                 myPart.name = def.Metadata["Name"].ToString();
             }
             if (def.Metadata.ContainsKey("Ver"))
             {
                 myPart.ver = def.Metadata["Ver"].ToString();
             }
             if (def.Metadata.ContainsKey("System.ComponentModel.Composition.CreationPolicy"))
             {
                 if (def.Metadata["System.ComponentModel.Composition.CreationPolicy"].ToString() == "Shared")
                 {
                     myPart.is_singleInstance = true;
                 }
             }
             if (!partsDic.ContainsKey(myPart.contractName))
             {
                 partsDic[myPart.contractName] = new Dictionary <string, Dictionary <string, MyPart> >();
             }
             if (!partsDic[myPart.contractName].ContainsKey(myPart.name))
             {
                 partsDic[myPart.contractName][myPart.name] = new Dictionary <string, MyPart>();
             }
             partsDic[myPart.contractName][myPart.name].Add(myPart.ver, myPart);
         }
     }
 }
        public ISrvBindable[] GetSrvs(MyPart part)
        {
            using (m_lock.AcquireExclusiveUsing())
            {
                PrepareFileTextures();

                ISrvBindable[] srvs = part.StandardMaterial.Srvs;
                for (int i = 0; i < srvs.Length; i++)
                {
                    m_tmpSrvs[i] = srvs[i];
                }
                for (int i = srvs.Length; i < m_tmpSrvs.Length; i++)
                {
                    m_tmpSrvs[i] = null;
                }

                int lodNum = part.Parent.LodNum;
                m_tmpSrvs[0] = m_fileTextures[lodNum % m_fileTextures.Length];
                m_tmpSrvs[1] = MyGeneratedTextureManager.ReleaseMissingNormalGlossTex;
                m_tmpSrvs[2] = MyGeneratedTextureManager.ReleaseMissingExtensionTex;

                return(m_tmpSrvs);
            }
        }
Exemple #6
0
 public void AddChild([NotNull] MyPart child)
 {
     Children.Add(child); child.Parent = this;
 }
 public ISrvBindable[] GetSrvs(MyPart part)
 {
     return(part.StandardMaterial.Srvs);
 }
 /// <summary>
 /// called by the Aircraft owning the part owning this WeaponAbility each frame
 /// </summary>
 /// <param name="dt">time since the previous frame</param>
 internal void ExecuteOrders(float dt)
 {
     // cool down
     CooldownUntilNextShot -= dt;
     CooldownUntilNextTargetUpdate -= dt;
     if (CooldownUntilNextShot < 0) CooldownUntilNextShot = 0;
     // if you have a target check if it is still in range
     if (TargetPart != null)
     {
             CCPoint vectorMyPartTarget = TargetPart.PositionWorldspace - MyPart.PositionWorldspace;
             if (TargetPart.MyState == Part.State.DESTROYED || (TargetAircraft != null && TargetAircraft.MyState == Aircraft.State.SHOT_DOWN)
                 || CooldownUntilNextTargetUpdate <= 0
                 || CCPoint.Distance(MyPart.PositionWorldspace, TargetPart.PositionWorldspace) > AttentionRange
                 || Constants.AbsAngleDifferenceDeg(MyPart.TotalRotation - MyPart.RotationFromNull, Constants.DxDyToCCDegrees(vectorMyPartTarget.X, vectorMyPartTarget.Y)) > AttentionAngle)
                 TargetPart = null;
     }
     if (TargetPart == null && CooldownUntilNextTargetUpdate <= 0)     // if you currently do not aim at anything search for a target
     {
         CooldownUntilNextTargetUpdate = UpdateTargetDelay;
         // collect aircrafts that are near enough to have parts which could be targets
         // go through the parts of all of these planes and collect those that are in the attention angle
         PartsInRange(out List<Part> partsInRange, out List<float> anglesFromTo, out List<float> distances);
         // try to choose a part that is in reach
         // choose the part that is closest anglewise
         // but prioritize aircraft bodies:
         //  this means that you should only change target from a body to another part if the part you would choose instead (because it's closer)
         //  belongs to another plane
         float minAngle = float.PositiveInfinity;
         for (int i=0; i<partsInRange.Count(); i++)
         {
             if (distances[i] <= ShootingRange)  // first only try parts that are already in reach
             {
                 float absAngle = (float)Math.Abs(anglesFromTo[i]);
                 var part = partsInRange[i];
                 if (absAngle < minAngle) //&&
                     //(TargetPart == null || !(part.Parent == TargetPart.Parent && TargetPart == TargetAircraft.Body)))  // don't switch from a body to a different part of the same aircraft
                 {
                     TargetPart = part;
                     minAngle = absAngle;
                 }
             }
         }
         if (TargetPart == null) // if you found no target this way check the rest
         {
             minAngle = float.PositiveInfinity;
             for (int i = 0; i < partsInRange.Count(); i++)
             {
                 float absAngle = (float)Math.Abs(anglesFromTo[i]);
                 var part = partsInRange[i];
                 // now also try parts that are not already in reach
                 if (absAngle < minAngle) //&&
                     //(TargetPart == null || !(part.Parent == TargetPart.Parent && TargetPart == TargetAircraft.Body)))  // don't switch from a body to a different part of the same aircraft
                 {
                     TargetPart = part;
                     minAngle = absAngle;
                 }
             }
         }
     }
     // calculate the perfect point to aim for in order to hit the target
     if (TargetPart != null)
     {
         float angleToAimFor = AngleToAimFor();
         if (!(MyPart is WingJet))   // a dirty fix to make sure jet wings don't rotate since rotation screws up the flip state; for other weapons this effect can be neglected since it is only visual
         {
             float angleToTurnTo = angleToAimFor;
             float angleTurn = Constants.AngleFromToDeg(MyPart.NullRotation, angleToTurnTo);
             // make sure you don't rotate further than your MountPoint allows
             if (angleTurn > MyPart.MountPoint.MaxTurningAngle)
                 angleToTurnTo = MyPart.NullRotation + MyPart.MountPoint.MaxTurningAngle;
             else if (angleTurn < -MyPart.MountPoint.MaxTurningAngle)
                 angleToTurnTo = MyPart.NullRotation - MyPart.MountPoint.MaxTurningAngle;
             // make sure you don't rotate further than this weapons MaxTurningAngle allows
             if (MaxTurningAngle < MyPart.MountPoint.MaxTurningAngle)
             {
                 if (angleTurn > MaxTurningAngle)
                     angleToTurnTo = MyPart.NullRotation + MaxTurningAngle;
                 else if (angleTurn < -MaxTurningAngle)
                     angleToTurnTo = MyPart.NullRotation - MaxTurningAngle;
             }
             MyPart.RotateTowards(angleToTurnTo, TurningAnglePerSecond * dt);
         }
         // if you're now close enough to the perfect angle (and in range) start shooting
         if (CanShoot()
             && CCPoint.Distance(MyPart.PositionWorldspace, TargetPart.PositionWorldspace) <= ShootingRange
             && (Constants.AbsAngleDifferenceDeg(angleToAimFor, MyPart.MyRotation) <= ToleratedError || WouldHit()))
         {
             TryShoot();
         }
             
     }
     // and if you have no target try to get back to NullRotation
     else if (!(MyPart is WingJet))
     {
         MyPart.RotateTowards(MyPart.NullRotation, TurningAnglePerSecond * dt);
     }
 }