private static PartSet findParts( DirectoryInfo saveFolder, PartSet library ) { var saveFile = new FileInfo( Strut.String.combinePath( saveFolder.FullName, "persistent.sfs" ) ); if ( !saveFile.Exists ) throw new Strut.MissingFileException( saveFile ); return Part.parseFromSfs( saveFile, library ); }
public StageValues(SharedObjects shared) { this.shared = shared; partSet = new PartSet(partHash); InitializeSuffixes(); }
public static SaveGame create( DirectoryInfo location, PartSet library ) { if ( !location.Exists ) throw new Strut.MissingFolderException( location ); var game = new SaveGame( location ); game.parts_.UnionWith( findParts( game.location_, library ) ); return game; }
/// <summary> /// Do not call! VesselTarget.StageValues uses this, would use `friend VesselTarget` if this was C++! /// </summary> internal StageValues(SharedObjects shared) { // Do not try to construct VesselTarget here, it is called from VesselTarget's constructor! // Would need special logic if VesselTarget is needed here this.shared = shared; partSet = new PartSet(partHash); RegisterInitializer(InitializeSuffixes); }
/// <summary> /// コンストラクタ /// </summary> public ResultSet(PartSet src) { this.Wepon = src.Wepon; this.Head = src.Head; this.Body = src.Body; this.Arm = src.Arm; this.Waist = src.Waist; this.Leg = src.Leg; this.Amulet = src.Amulet; this.Accessory = src.Accessory; }
protected void StartSimulation() { Profiler.BeginSample("StartSimulation"); try { simulationRunning = true; resultReady = false; stopwatch.Start(); //starts a timer that times how long the simulation takes //Create two FuelFlowSimulations, one for vacuum and one for atmosphere List <Part> parts = (HighLogic.LoadedSceneIsEditor ? EditorLogic.fetch.ship.parts : vessel.parts); if (HighLogic.LoadedSceneIsEditor) { if (needRebuild > 0) { PartSet.BuildPartSets(parts, null); needRebuild--; } } else { vessel.UpdateResourceSetsIfDirty(); } Profiler.BeginSample("StartSimulation_Init"); sims[0].Init(parts, dVLinearThrust); sims[1].Init(parts, dVLinearThrust); Profiler.EndSample(); //Run the simulation in a separate thread ThreadPool.QueueUserWorkItem(RunSimulation, sims); //Profiler.BeginSample("StartSimulation_Run"); //RunSimulation(sims); //Profiler.EndSample(); } catch (Exception e) { print("Exception in MechJebModuleStageStats.StartSimulation(): " + e + "\n" + e.StackTrace); // Stop timing the simulation stopwatch.Stop(); millisecondsBetweenSimulations = 500; stopwatch.Reset(); // Start counting down the time to the next simulation stopwatch.Start(); simulationRunning = false; } Profiler.EndSample(); }
protected void UpdateMesh(PartSet partSet, int index, MeshCache.MeshDetails meshDetails) { if (meshDetails != null && meshDetails.Finalised) { partSet.Meshes[index] = meshDetails; // Select a material override if required. } else { partSet.Meshes[index] = null; partSet.MaterialOverrides[index] = null; } }
void initFlight() { Log.Info("Initializing flight"); zAwake(); if (crossfeedToggleModule != null) { Log.Info("initFlight, CrossfeedType: " + CrossfeedType + " crossfeedToggleModule.crossfeedStatus: " + crossfeedToggleModule.crossfeedStatus); } this.GetAvailableResourceIDs(this.part, true); partSet = new PartSet(hashPartSet); flightInitialized = true; }
/// <summary> /// Creates a mesh set shape for serialising the mesh and its resource references. /// </summary> /// <param name="shapeComponent">The component to create a shape for.</param> /// <returns>A shape instance suitable for configuring to generate serialisation messages.</returns> protected override Shapes.Shape CreateSerialisationShape(ShapeCache cache, int shapeIndex, CreateMessage shapeData) { // Start by building the resource list. PartSet partSet = cache.GetShapeDataByIndex <PartSet>(shapeIndex); Shapes.MeshSet meshSet = new Shapes.MeshSet(shapeData.ObjectID, shapeData.Category); meshSet.SetAttributes(shapeData.Attributes); for (int i = 0; i < partSet.MeshIDs.Length; ++i) { MeshResourcePlaceholder part = new MeshResourcePlaceholder(partSet.MeshIDs[i]); meshSet.AddPart(part, Tes.Maths.Matrix4Ext.FromUnity(partSet.Transforms[i])); } return(meshSet); }
void checkStageParts() { if (stagePartsChanged) { if (partSet == null) { partSet = new PartSet(activeStageParts); } else { partSet.RebuildParts(activeStageParts); } stagePartsChanged = false; } }
/// <summary> /// This should be called when staging, and wil lthen rebuild the partSet used to check for resources /// </summary> /// <param name="v"></param> void onVesselWasModified(Vessel v) { Log.Info("onVesselWasModified"); if (v == this.vessel) { if (hashPartSet != null) { hashPartSet.Clear(); } if (partSet != null) { partSet = null; } initFlight(); } }
public void EndLoop(double time) { float invDeltaT = (float)(1.0 / (time - lastcheck)); for (int i = 0; i < rs.Length; ++i) { rs[i].delta = (rs[i].previous - rs[i].current) * invDeltaT; rs[i].previous = rs[i].current; } lastcheck = time; if (stagePartsChanged) { if (partSet == null) { partSet = new PartSet(activeStageParts); } else { partSet.RebuildParts(activeStageParts); } stagePartsChanged = false; } numValidResourceNames = 0; for (int i = 0; i < rs.Length; ++i) { if (rs[i].max > 0.0) { sortedResourceNames[numValidResourceNames] = rs[i].name; ++numValidResourceNames; // If the resource can flow anywhere, we already have the stage // values listed here. if (rs[i].stagemax == 0.0) { double amount, maxAmount; partSet.GetConnectedResourceTotals(rs[i].resourceId, out amount, out maxAmount, true); rs[i].stagemax = (float)maxAmount; rs[i].stage = (float)amount; } } } }
protected virtual void BindMaterial(PartSet partSet, int partIndex) { Material material = null; if ((partSet.ObjectFlags & ObjectFlag.Wireframe) == ObjectFlag.Wireframe) { material = Materials[MaterialLibrary.WireframeMesh]; } else if ((partSet.ObjectFlags & ObjectFlag.Transparent) == ObjectFlag.Transparent) { material = Materials[MaterialLibrary.TransparentMesh]; } else if ((partSet.ObjectFlags & ObjectFlag.TwoSided) == ObjectFlag.TwoSided) { material = Materials[MaterialLibrary.OpaqueTwoSidedMesh]; } // else no override. if (material != null && partSet.Meshes[partIndex] != null) { // Have an override material. Validate the topology. Only supported for triangles and quads. RenderMesh mesh = partSet.Meshes[partIndex].Mesh; if (mesh.Topology == MeshTopology.Triangles || mesh.Topology == MeshTopology.Quads) { // Instance the material and setup streams. material = new Material(material); if (mesh.HasColours) { material.EnableKeyword("WITH_COLOURS_UINT"); } if (mesh.HasNormals) { material.EnableKeyword("WITH_NORMALS"); } partSet.MaterialOverrides[partIndex] = material; } } }
public void EndLoop(double time) { float invDeltaT = (float)(1.0 / (time - lastcheck)); for (int i = 0; i < rs.Length; ++i) { rs[i].delta = (rs[i].previous - rs[i].current) * invDeltaT; rs[i].previous = rs[i].current; } lastcheck = time; if (partSet == null) { partSet = new PartSet(activeResources); } else { partSet.RebuildParts(activeResources); } numValidResourceNames = 0; for (int i = 0; i < rs.Length; ++i) { if (rs[i].max > 0.0) { sortedResourceNames[numValidResourceNames] = rs[i].name; ++numValidResourceNames; if (rs[i].ispropellant) { double amount, maxAmount; partSet.GetConnectedResourceTotals(rs[i].resourceId, out amount, out maxAmount, true); rs[i].stagemax = (float)maxAmount; rs[i].stage = (float)amount; } } } }
private void RenderMeshes(CameraContext cameraContext, ShapeCache cache, int shapeIndex) { CreateMessage shape = cache.GetShapeByIndex(shapeIndex); if (CategoriesState != null && !CategoriesState.IsActive(shape.Category)) { return; } Matrix4x4 shapeWorldTransform = cameraContext.TesSceneToWorldTransform * cache.GetShapeTransformByIndex(shapeIndex); PartSet parts = cache.GetShapeDataByIndex <PartSet>(shapeIndex); for (int i = 0; i < parts.Meshes.Length; ++i) { RenderMesh mesh = (parts.Meshes[i] != null) ? parts.Meshes[i].Mesh : null; if (mesh == null) { continue; } if (mesh.MaterialDirty) { mesh.UpdateMaterial(); } Material material = (parts.MaterialOverrides != null && parts.MaterialOverrides.Length > 0 && parts.MaterialOverrides[i]) ? parts.MaterialOverrides[i] : mesh.Material; if (material == null) { continue; } // TODO: (KS) use transparent queue for parts with transparency. CommandBuffer renderQueue = cameraContext.OpaqueBuffer; // Push the part transform. Matrix4x4 partWorldTransform = shapeWorldTransform * parts.Transforms[i] * mesh.LocalTransform; if (mesh.HasColours) { material.SetBuffer("_Colours", mesh.ColoursBuffer); } if (mesh.HasNormals) { material.SetBuffer("_Normals", mesh.NormalsBuffer); } // if (mesh.HasUVs) // { // material.SetBuffer("uvs", mesh.UvsBuffer); // } if (material.HasProperty("_Color")) { material.SetColor("_Color", new Maths.Colour(shape.Attributes.Colour).ToUnity32()); } if (material.HasProperty("_Tint")) { material.SetColor("_Tint", mesh.Tint.ToUnity32()); } if (material.HasProperty("_BackColour")) { material.SetColor("_BackColour", new Maths.Colour(shape.Attributes.Colour).ToUnity32()); } // Bind vertices and draw. material.SetBuffer("_Vertices", mesh.VertexBuffer); if (mesh.IndexBuffer != null) { renderQueue.DrawProcedural(mesh.IndexBuffer, partWorldTransform, material, 0, mesh.Topology, mesh.IndexCount); } else { renderQueue.DrawProcedural(partWorldTransform, material, 0, mesh.Topology, mesh.VertexCount); } } }
//public void DumpData() //{ // JUtil.LogMessage(this, "Resource data update:"); // for (int i = 0; i < rs.Length; ++i) // { // JUtil.LogMessage(this, "{0}: C {1:0.0} / {2:0.0}; T {3:0.0} / {4:0.0}; R {5:0.00}", // rs[i].name, rs[i].stage, rs[i].current, rs[i].stagemax, rs[i].max, rs[i].delta); // } //} public void MarkPropellant(PartSet ps) { var parts = ps.GetParts(); activeResources.UnionWith(parts); }
// Note: expensive call private static PartSet findPartsIn( params DirectoryInfo[] folders ) { var result = new PartSet(); foreach ( var folder in folders ) foreach ( var partFile in folder.EnumerateFiles( partFileNameGlob_, SearchOption.AllDirectories ) ) result.UnionWith( Part.parseFromCfg( partFile ) ); return result; }
private void UpdateCrossfeedSets(ShipConstruct ship) { PartSet.BuildPartSets(ship.parts, null); }
public ActiveResourceValue(PartResourceDefinition definition, SharedObjects shared, StageValues stageValues, PartSet partSet) : base(definition, shared) { stageValRef = new WeakReference(stageValues); resourceId = definition.id; this.partSet = partSet; }