/// <summary> /// Returns the configuration object with the specified type and name if available. /// </summary> /// <param name="type"> the type of the configuration object </param> /// <param name="name"> the name of the configuration object </param> /// @param <T> the type of the configuration object </param> /// <returns> the configuration with the specified type and name </returns> /// <exception cref="IllegalArgumentException"> if no configuration is found with the specified type and name </exception> public T get <T>(Type <T> type, string name) { SingleTypeMarketDataConfig typeConfigs = configs.get(type); // simple match if (typeConfigs != null) { object config = typeConfigs.get(name); if (config == null) { //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: throw new System.ArgumentException(Messages.format("No configuration found with type {} and name {}", type.FullName, name)); } return(type.cast(config)); } // try looking for subclasses of an interface if (!type.IsInterface) { //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: throw new System.ArgumentException("No configuration found for type " + type.FullName); } ImmutableList <SingleTypeMarketDataConfig> potentialTypes = MapStream.of(configs).filterKeys(type.isAssignableFrom).map((t, config) => config).filter(config => config.ConfigObjects.containsKey(name)).collect(toImmutableList()); if (potentialTypes.Empty) { //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: throw new System.ArgumentException("No configuration found for type " + type.FullName + " or subclasses"); } if (potentialTypes.size() > 1) { //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: throw new System.ArgumentException("Multiple configuration found for type " + type.FullName); } return(type.cast(potentialTypes.get(0).get(name))); }
private unsafe LandTile[] ReadLandBlock(int x, int y) { try { int offset = (x * BlockHeight + y) * 196 + 4; if (m_MapIndex != null) { offset = m_MapIndex.Lookup(offset); } MapStream.Seek(offset, SeekOrigin.Begin); LandTile[] tiles = new LandTile[64]; fixed(LandTile *pTiles = tiles) { NativeReader.Read(MapStream.SafeFileHandle.DangerousGetHandle(), pTiles, 192); } return(tiles); } catch { if (DateTime.UtcNow >= m_NextLandWarning) { Console.WriteLine("Warning: Land EOS for {0} ({1}, {2})", m_Owner, x, y); m_NextLandWarning = DateTime.UtcNow + TimeSpan.FromMinutes(1.0); } return(m_InvalidLandBlock); } }
/// <summary> /// Adds multiple shifts to the builder. /// </summary> /// <param name="scenarioIndex"> the index of the scenario containing the shifts </param> /// <param name="shiftMap"> the shift amounts, keyed by the identifier of the node to which they should be applied </param> /// <returns> this builder </returns> public PointShiftsBuilder addShifts <T1>(int scenarioIndex, IDictionary <T1> shiftMap) { ArgChecker.notNull(shiftMap, "shiftMap"); ArgChecker.notNegative(scenarioIndex, "scenarioIndex"); MapStream.of(shiftMap).forEach((id, shift) => shifts.put(Pair.of(scenarioIndex, id), shift)); return(this); }
public static dynamic Deserialize(this MapStream source, Type type) { var sourceReader = new BinaryReader(source); Source = source; PostProcessQueue = new List<Tuple<FieldInfo, object, MethodInvoker>>(); var constructor = (from constructors in type.GetConstructors(BindingFlags.Public | BindingFlags.Instance) where constructors.HasParameterSignature(new Type[]{typeof(BinaryReader)}) select constructors).FirstOrDefault(); if (constructor != null) { return constructor.Invoke(new[] { sourceReader }); } var returnValue = Deserialize(sourceReader, type); for (var i = 0; i < PostProcessQueue.Count; ++i) { var field = PostProcessQueue[i].Item1; var item = PostProcessQueue[i].Item2; var methodInfo = PostProcessQueue[i].Item3; methodInfo(item, sourceReader, item, field); } return returnValue; }
void ReadCatch() { Map map = MapStream.Read(Application.dataPath + "/MapCatch"); FromMap(map); FileUtil.DeleteFileOrDirectory(Application.dataPath + "/MapCatch"); }
public static dynamic Deserialize(this MapStream source, Type type) { var sourceReader = new BinaryReader(source); Source = source; PostProcessQueue = new List <Tuple <FieldInfo, object, MethodInvoker> >(); var constructor = (from constructors in type.GetConstructors(BindingFlags.Public | BindingFlags.Instance) where constructors.HasParameterSignature(new Type[] { typeof(BinaryReader) }) select constructors).FirstOrDefault(); if (constructor != null) { return(constructor.Invoke(new[] { sourceReader })); } var returnValue = Deserialize(sourceReader, type); for (var i = 0; i < PostProcessQueue.Count; ++i) { var field = PostProcessQueue[i].Item1; var item = PostProcessQueue[i].Item2; var methodInfo = PostProcessQueue[i].Item3; methodInfo(item, sourceReader, item, field); } return(returnValue); }
//------------------------------------------------------------------------- /// <summary> /// Write sensitivities to an appendable in the standard sensitivities format. /// <para> /// The output is written in standard format, with no identifier columns. /// The parameter metadata must contain tenors. /// /// </para> /// </summary> /// <param name="curveSens"> the curve sensitivities to write </param> /// <param name="output"> the appendable to write to </param> /// <exception cref="IllegalArgumentException"> if the metadata does not contain tenors </exception> /// <exception cref="UncheckedIOException"> if an IO error occurs </exception> public void write(CurveSensitivities curveSens, Appendable output) { CsvOutput csv = CsvOutput.standard(output, "\n"); IList <string> additionalHeaders = supplier.headers(curveSens); // check for dates if (curveSens.TypedSensitivities.values().stream().flatMap(allParamSens => allParamSens.Sensitivities.stream()).flatMap(paramSens => paramSens.ParameterMetadata.stream()).anyMatch(pmd => !(pmd is TenoredParameterMetadata))) { throw new System.ArgumentException("Parameter metadata must contain tenors"); } bool containsDates = curveSens.TypedSensitivities.values().stream().flatMap(allParamSens => allParamSens.Sensitivities.stream()).flatMap(paramSens => paramSens.ParameterMetadata.stream()).anyMatch(pmd => pmd is DatedParameterMetadata); // headers csv.writeCell(SensitivityCsvLoader.REFERENCE_HEADER); csv.writeCell(SensitivityCsvLoader.TYPE_HEADER); csv.writeCell(SensitivityCsvLoader.TENOR_HEADER); if (containsDates) { csv.writeCell(SensitivityCsvLoader.DATE_HEADER); } csv.writeCell(SensitivityCsvLoader.CURRENCY_HEADER); csv.writeCell(SensitivityCsvLoader.VALUE_HEADER); csv.writeLine(additionalHeaders); // content, grouped by reference, then type MapStream.of(curveSens.TypedSensitivities).flatMapValues(sens => sens.Sensitivities.stream()).mapKeys((type, sens) => Pair.of(sens.MarketDataName.Name, type)).sortedKeys().forEach((pair, paramSens) => write(pair.First, pair.Second, curveSens, paramSens, additionalHeaders, containsDates, csv)); }
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: private com.opengamma.strata.collect.result.Result<?> calculateMeasure(T target, java.util.Map<com.opengamma.strata.calc.Measure, com.opengamma.strata.collect.result.Result<?>> delegateResults, CalculationParameters parameters, com.opengamma.strata.data.scenario.ScenarioMarketData marketData, com.opengamma.strata.basics.ReferenceData refData) private Result <object> calculateMeasure <T1>(T target, IDictionary <T1> delegateResults, CalculationParameters parameters, ScenarioMarketData marketData, ReferenceData refData) { if (!requiredMeasuresSupported) { // Can't calculate the measure if the delegate can't calculate its inputs return(Result.failure(FailureReason.NOT_APPLICABLE, "The delegate function cannot calculate the required measures. Required measures: {}, " + "supported measures: {}, delegate {}", derivedFunction.requiredMeasures(), @delegate.supportedMeasures(), @delegate)); } //JAVA TO C# CONVERTER TODO TASK: There is no .NET equivalent to the java.util.Collection 'containsAll' method: if (!delegateResults.Keys.containsAll(derivedFunction.requiredMeasures())) { // There's a bug in the delegate function - it claims to support the required measures but didn't return // a result for all of them. return(Result.failure(FailureReason.CALCULATION_FAILED, "Delegate did not return the expected measures. Required {}, actual {}, delegate {}", derivedFunction.requiredMeasures(), delegateResults.Keys, @delegate)); } // Check whether all the required measures were successfully calculated //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.List<com.opengamma.strata.collect.result.Result<?>> failures = com.opengamma.strata.collect.MapStream.of(delegateResults).filterKeys(derivedFunction.requiredMeasures()::contains).map(entry -> entry.getValue()).filter(result -> result.isFailure()).collect(toList()); IList <Result <object> > failures = MapStream.of(delegateResults).filterKeys(derivedFunction.requiredMeasures().contains).map(entry => entry.Value).filter(result => result.Failure).collect(toList()); if (failures.Count > 0) { return(Result.failure(failures)); } // Unwrap the results before passing them to the function IDictionary <Measure, object> resultValues = MapStream.of(delegateResults).filterKeys(derivedFunction.requiredMeasures().contains).mapValues(result => (object)result.Value).toMap(); return(Result.of(() => derivedFunction.calculate(target, resultValues, parameters, marketData, refData))); }
private bool ValidateBlamPointer(BlamPointer blamPointer, ElementArray info, MapStream stream) { var stringWriter = new StringWriter(); if (blamPointer.Count == 0 && blamPointer.Address == 0) { return(true); } if (blamPointer.Count == 0 ^ blamPointer.Address == 0) { stringWriter.WriteLine(string.Format("-> null-value count({0}) address({1}) is invalid", blamPointer.Count, blamPointer.Address)); } if (blamPointer.Count < 0) { stringWriter.WriteLine(string.Format("-> count({0}) is invalid", blamPointer.Count)); } if (blamPointer.Count > info.MaxElementCount && info.MaxElementCount > 0) { stringWriter.WriteLine(string.Format("-> count({0}) > max-count({1})", blamPointer.Count, info.MaxElementCount)); } if (!stream.ContainsPointer(blamPointer)) { stringWriter.WriteLine(string.Format("-> address({0}) not contained in stream({1})", blamPointer.Address, stream.Name)); } var errors = stringWriter.ToString(); if (!string.IsNullOrWhiteSpace(errors)) { OnWriteMessage(string.Format("Pointer ({0})\n{1}", info.Name, errors)); return(false); } return(true); }
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: @Override public java.util.Map<com.opengamma.strata.calc.Measure, com.opengamma.strata.collect.result.Result<?>> calculate(T target, java.util.Set<com.opengamma.strata.calc.Measure> measures, CalculationParameters parameters, com.opengamma.strata.data.scenario.ScenarioMarketData marketData, com.opengamma.strata.basics.ReferenceData refData) public virtual IDictionary <Measure, Result <object> > calculate(T target, ISet <Measure> measures, CalculationParameters parameters, ScenarioMarketData marketData, ReferenceData refData) { // The caller didn't ask for the derived measure so just return the measures calculated by the delegate Measure derivedMeasure = derivedFunction.measure(); if (!measures.Contains(derivedMeasure)) { return(@delegate.calculate(target, measures, parameters, marketData, refData)); } // Add the measures required to calculate the derived measure to the measures requested by the caller ISet <Measure> allRequiredMeasures = Sets.union(measures, derivedFunction.requiredMeasures()); ISet <Measure> requiredMeasures = Sets.difference(allRequiredMeasures, ImmutableSet.of(derivedMeasure)); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.Map<com.opengamma.strata.calc.Measure, com.opengamma.strata.collect.result.Result<?>> delegateResults = delegate.calculate(target, requiredMeasures, parameters, marketData, refData); IDictionary <Measure, Result <object> > delegateResults = @delegate.calculate(target, requiredMeasures, parameters, marketData, refData); // Calculate the derived measure //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: com.opengamma.strata.collect.result.Result<?> result = calculateMeasure(target, delegateResults, parameters, marketData, refData); Result <object> result = calculateMeasure(target, delegateResults, parameters, marketData, refData); // The results containing only the requested measures and not including extra measures that were inserted above // Also filter out any results for calculationFunction.measure(). There will be failures from functions below // that don't support that measure. //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.Map<com.opengamma.strata.calc.Measure, com.opengamma.strata.collect.result.Result<?>> requestedResults = com.opengamma.strata.collect.MapStream.of(delegateResults).filterKeys(measures::contains).filterKeys(measure -> !measure.equals(derivedMeasure)).toMap(); IDictionary <Measure, Result <object> > requestedResults = MapStream.of(delegateResults).filterKeys(measures.contains).filterKeys(measure => !measure.Equals(derivedMeasure)).toMap(); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: return com.google.common.collect.ImmutableMap.builder<com.opengamma.strata.calc.Measure, com.opengamma.strata.collect.result.Result<?>>().put(derivedMeasure, result).putAll(requestedResults).build(); return(ImmutableMap.builder <Measure, Result <object> >().put(derivedMeasure, result).putAll(requestedResults).build()); }
public void TestRead() { var Stream1 = new ZeroStream(5, 0x11); var Stream2 = new ZeroStream(3, 0x22); var MapStream = new MapStream(); byte[] Readed1, Readed2, Readed3, Readed4; MapStream.Map(3, Stream1); MapStream.Map(3 + 5, Stream2); MapStream.Position = 4; Readed1 = MapStream.ReadBytesUpTo(3); Assert.Equal(new byte[] { 0x11, 0x11, 0x11 }, Readed1); Readed2 = MapStream.ReadBytesUpTo(3); Assert.Equal(new byte[] { 0x11, 0x22, 0x22 }, Readed2); Readed3 = MapStream.ReadBytesUpTo(1); Assert.Equal(new byte[] { 0x22 }, Readed3); MapStream.Position = 3; Readed4 = MapStream.ReadBytesUpTo(8); Assert.Equal(new byte[] { 0x11, 0x11, 0x11, 0x11, 0x11, 0x22, 0x22, 0x22 }, Readed4); }
public void LoadShader(MapStream map) { var bitmapTag = map[postprocessDefinition[0].bitmaps[2].bitmapGroup].Deserialize() as BitmapBlock; texture = new Texture(); texture.Load(bitmapTag, map); texture.Bind(TextureTarget.Texture2D); }
private void ValidateTagBlock(ElementArray info, BlamPointer pointer, BinaryReader reader, ref int address) { using (reader.BaseStream.Pin()) { // If owned by tag and memory has not been allocated yet* var allocated = from item in PointersList where item.Item1.Equals(pointer) select item; var partiallyAllocated = from item in PointersList where item.Item1.Intersects(pointer) select item; if (OwnedByTag(pointer)) { if (!allocated.Any()) { var alignedAddress = (address - startOffset) + Padding.GetCount(address - startOffset, info.Alignment); if (pointer.Address - startOffset != alignedAddress) { MapStream mapStream = reader.BaseStream as MapStream; if (mapStream != null) { OnWriteMessage(string.Format("{2}: Expected address \"{0}\" - actually was \"{1}\"", address - startOffset, pointer.Address - startOffset, info.Name)); } } address = pointer.Address + pointer.PointedSize; } if (allocated.Any()) { } else if (partiallyAllocated.Any()) { foreach (var overlappingItem in partiallyAllocated) { var overlap = pointer.Address - overlappingItem.Item1.Address - overlappingItem.Item1.PointedSize; OnWriteMessage(string.Format("Overlap of ({0})[{3}] with ({1}) by ({2}) bytes", overlappingItem.Item2.ToHierarchyString(), info.ToHierarchyString(), overlap, overlappingItem.Item1.Count)); } } } else if (!IsValid(pointer)) { OnWriteMessage(string.Format("INVALID POINTER")); return; } else { OnWriteMessage(string.Format("WILLLLLSOOON SHARE")); } PointersList.Add(new Tuple <BlamPointer, ElementArray>(pointer, info)); foreach (var elementAddress in pointer) { reader.BaseStream.Position = elementAddress; ValidateChildren(info, reader, ref address); } } }
/// <summary> /// /// </summary> /// <param name="Stream"></param> /// <param name="Spaces"></param> /// <returns></returns> public static MapStream ConvertSpacesToMapStream(this Stream Stream, SpaceAssigner1D.Space[] Spaces) { var MapStream = new MapStream(); foreach (var Space in Spaces) { MapStream.Map(Space.Min, Stream.SliceWithBounds(Space.Min, Space.Max)); } return(MapStream); }
/// <summary> /// /// </summary> /// <param name="stream"></param> /// <param name="spaces"></param> /// <returns></returns> public static MapStream ConvertSpacesToMapStream(this Stream stream, SpaceAssigner1D.Space[] spaces) { var mapStream = new MapStream(); foreach (var space in spaces) { mapStream.Map(space.Min, stream.SliceWithBounds(space.Min, space.Max)); } return(mapStream); }
// one valuation date, one set of market data private MarketDataBox <RatesCurveInputs> buildSingleCurveInputs <T1>(CurveDefinition filteredDefn, IDictionary <T1> marketData, LocalDate valuationDate, ReferenceData refData) where T1 : com.opengamma.strata.data.MarketDataId <T1> { // There is only a single map of values and single valuation date - create a single CurveInputs instance CurveMetadata curveMetadata = filteredDefn.metadata(valuationDate, refData); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.Map<? extends com.opengamma.strata.data.MarketDataId<?>, ?> singleMarketDataValues = com.opengamma.strata.collect.MapStream.of(marketData).mapValues(box -> box.getSingleValue()).toMap(); IDictionary <MarketDataId <object>, ?> singleMarketDataValues = MapStream.of(marketData).mapValues(box => box.SingleValue).toMap(); RatesCurveInputs curveInputs = RatesCurveInputs.of(singleMarketDataValues, curveMetadata); return(MarketDataBox.ofSingleValue(curveInputs)); }
/// <summary> /// Adds a collection of new rates for currency pairs to the builder. /// Pairs that are already in the builder are treated as updates to the /// existing rates -> !e.getKey().equals(commonCurrency) && !currencies.containsKey(e.getKey()) /// </summary> /// <param name="rates"> the currency pairs and rates to be added </param> /// <returns> the builder updated with the new rates </returns> public virtual FxMatrixBuilder addRates(IDictionary <CurrencyPair, double> rates) { ArgChecker.notNull(rates, "rates"); if (rates.Count > 0) { ensureCapacity(rates.Keys.stream().flatMap(cp => Stream.of(cp.Base, cp.Counter))); MapStream.of(rates).forEach((pair, rate) => addRate(pair, rate)); } return(this); }
public void TestReadUnmapped1() { try { var MapStream = new MapStream(); MapStream.Read(new byte[1], 0, 1); Assert.False(true); } catch (InvalidOperationException) { } }
public void ReadMap() { mapFilePath = EditorUtility.OpenFilePanel("Read map file", Application.dataPath, "txt"); if (string.IsNullOrEmpty(mapFilePath)) { return; } ClearMapCell(); MapData map = MapStream.Read(mapFilePath); FromMapData(map); }
internal virtual FxMatrixBuilder merge(FxMatrixBuilder other) { // Find the common currencies Optional <Currency> common = currencies.Keys.Where(other.currencies.containsKey).First(); Currency commonCurrency = common.orElseThrow(() => new System.ArgumentException("There are no currencies in common between " + currencies.Keys + " and " + other.currencies.Keys)); // Add in all currencies that we don't already have MapStream.of(other.currencies).filterKeys(ccy => !ccy.Equals(commonCurrency) && !currencies.containsKey(ccy)).forEach((ccy, idx) => addCurrencyPair(commonCurrency, ccy, other.getRate(commonCurrency, ccy))); return(this); }
// validates that there are no duplicate scenario names //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @ImmutableValidator private void validate() private void validate() { //JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter: IDictionary <string, IList <string> > nameMap = scenarioNames.collect(groupingBy(name => name)); IList <string> duplicateNames = MapStream.of(nameMap).filterValues(names => names.size() > 1).map((name, names) => name).collect(toImmutableList()); if (duplicateNames.Count > 0) { //JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter: string duplicates = duplicateNames.collect(joining(", ")); throw new System.ArgumentException("Scenario names must be unique but duplicates were found: " + duplicates); } }
//------------------------------------------------------------------------- public virtual void test_of_map() { ImmutableMap <ParameterMetadata, double> map = ImmutableMap.of(TenorParameterMetadata.of(Tenor.TENOR_1Y), 12d, TenorParameterMetadata.of(Tenor.TENOR_2Y), -32d, TenorParameterMetadata.of(Tenor.TENOR_5Y), 5d); CurrencyParameterSensitivity test = CurrencyParameterSensitivity.of(NAME1, USD, map); assertEquals(test.MarketDataName, NAME1); assertEquals(test.ParameterCount, 3); assertEquals(test.ParameterMetadata, map.Keys.asList()); assertEquals(test.Currency, USD); assertEquals(test.Sensitivity, DoubleArray.copyOf(map.values())); assertEquals(test.sensitivities().toMap(), map); assertEquals(test.toSensitivityMap(typeof(Tenor)), MapStream.of(map).mapKeys(pm => pm.Identifier).toMap()); }
/// <summary> /// Returns a collector which creates a multi currency amount array by combining a stream of /// currency amount arrays. /// <para> /// The arrays in the stream must all have the same length. /// /// </para> /// </summary> /// <returns> the collector </returns> //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: public static java.util.stream.Collector<CurrencyAmountArray, ?, MultiCurrencyAmountArray> toMultiCurrencyAmountArray() public static Collector <CurrencyAmountArray, ?, MultiCurrencyAmountArray> toMultiCurrencyAmountArray() { //JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter: //JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter: return(Collector.of <CurrencyAmountArray, IDictionary <Currency, CurrencyAmountArray>, MultiCurrencyAmountArray>(Hashtable::new, (map, ca) => map.merge(ca.Currency, ca, CurrencyAmountArray::plus), (map1, map2) => { map2.values().forEach((ca2) => map1.merge(ca2.Currency, ca2, CurrencyAmountArray::plus)); return map1; }, map => { IDictionary <Currency, DoubleArray> currencyArrayMap = MapStream.of(map).mapValues(caa => caa.Values).toMap(); return MultiCurrencyAmountArray.of(currencyArrayMap); }, UNORDERED)); }
public void Load(BitmapBlock bitmapCollection, MapStream map) { handle = GL.GenTexture(); var workingBitmap = bitmapCollection.bitmaps[0]; byte[] buffer = new byte[bitmapCollection.bitmaps[0].lOD1TextureDataLength]; using (map.Pin()) { map.Position = bitmapCollection.bitmaps[0].lOD1TextureDataOffset; map.Read(buffer, 0, buffer.Length); } var width = workingBitmap.widthPixels; var height = workingBitmap.heightPixels; var bytesPerPixel = ParseBitapPixelDataSize(workingBitmap.format) / 8.0f; PixelInternalFormat pixelInternalFormat = ParseBitmapPixelInternalFormat(workingBitmap.format); switch (workingBitmap.type) { case BitmapDataBlockBase.TypeDeterminesBitmapGeometry.Texture2D: { GL.BindTexture(TextureTarget.Texture2D, this.handle); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat); OpenGL.ReportError(); if (workingBitmap.flags.HasFlag(BitmapDataBlock.Flags.Compressed)) { byte[] surfaceData = new byte[(int)(bytesPerPixel * width * height)]; Array.Copy(buffer, 0, surfaceData, 0, surfaceData.Length); GL.CompressedTexImage2D( TextureTarget.Texture2D, 0, pixelInternalFormat, width, height, 0, (int)(bytesPerPixel * width * height), surfaceData); } else { var pixelFormat = ParseBitapPixelFormat(workingBitmap.format); var pixelType = ParseBitapPixelType(workingBitmap.format); GL.TexImage2D(TextureTarget.Texture2D, 0, pixelInternalFormat, width, height, 0, pixelFormat, pixelType, buffer); } } break; default: GL.DeleteTexture(this.handle); break; } OpenGL.ReportError(); }
public void Dispose() { if (m_MapIndex != null) { m_MapIndex.Close(); } else { MapStream?.Close(); } DataStream?.Close(); IndexReader?.Close(); }
public void ReadMap() { if (!string.IsNullOrEmpty(m_filePath)) { SaveMap(); } m_filePath = EditorUtility.OpenFilePanel("Read map file", Application.dataPath, "txt"); if (string.IsNullOrEmpty(m_filePath)) { return; } Map map = MapStream.Read(m_filePath); FromMap(map); }
/// <summary> /// Obtains an instance using a function to create the entries. /// <para> /// The function is passed the index and returns the {@code MultiCurrencyAmount} for that index. /// /// </para> /// </summary> /// <param name="size"> the number of elements, at least size one </param> /// <param name="valueFunction"> the function used to obtain each value </param> /// <returns> an instance initialized using the function </returns> /// <exception cref="IllegalArgumentException"> is size is zero or less </exception> public static MultiCurrencyAmountArray of(int size, System.Func <int, MultiCurrencyAmount> valueFunction) { IDictionary <Currency, double[]> map = new Dictionary <Currency, double[]>(); for (int i = 0; i < size; i++) { MultiCurrencyAmount mca = valueFunction(i); foreach (CurrencyAmount ca in mca.Amounts) { double[] array = map.computeIfAbsent(ca.Currency, c => new double[size]); array[i] = ca.Amount; } } return(new MultiCurrencyAmountArray(size, MapStream.of(map).mapValues(array => DoubleArray.ofUnsafe(array)).toMap())); }
//------------------------------------------------------------------------- // loads a single fixing series CSV file private static ImmutableMap <ObservableId, LocalDateDoubleTimeSeries> parseSingle(CharSource resource) { IDictionary <ObservableId, LocalDateDoubleTimeSeriesBuilder> builders = new Dictionary <ObservableId, LocalDateDoubleTimeSeriesBuilder>(); try { CsvFile csv = CsvFile.of(resource, true); foreach (CsvRow row in csv.rows()) { string referenceStr = row.getField(REFERENCE_FIELD); string dateStr = row.getField(DATE_FIELD); string valueStr = row.getField(VALUE_FIELD); Index index = LoaderUtils.findIndex(referenceStr); ObservableId id = IndexQuoteId.of(index); double value = double.Parse(valueStr); LocalDate date; if (index is PriceIndex) { try { YearMonth ym = LoaderUtils.parseYearMonth(dateStr); date = ym.atEndOfMonth(); } catch (Exception) { date = LoaderUtils.parseDate(dateStr); if (date.DayOfMonth != date.lengthOfMonth()) { throw new System.ArgumentException(Messages.format("Fixing Series CSV loader for price index must have date at end of month: {}", resource)); } } } else { date = LoaderUtils.parseDate(dateStr); } LocalDateDoubleTimeSeriesBuilder builder = builders.computeIfAbsent(id, k => LocalDateDoubleTimeSeries.builder()); builder.put(date, value); } } catch (Exception ex) { throw new System.ArgumentException(Messages.format("Error processing resource as CSV file: {}", resource), ex); } return(MapStream.of(builders).mapValues(builder => builder.build()).toMap()); }
public void SaveMapAs() { if (cells == null) { return; } mapFilePath = EditorUtility.SaveFilePanel("Save map file", Application.dataPath, "", "txt"); if (string.IsNullOrEmpty(mapFilePath)) { return; } MapStream.Write(ToMapData(), mapFilePath); Debug.Log("Save success."); }
public void TestLongRead() { var Position = (long)5197762560L; var Array = new byte[] { 0x11, 0x12, 0x13, 0x14, 0x15 }; var Stream1 = new MemoryStream(Array); var MapStream = new MapStream(); MapStream.Map(Position, Stream1); var SerializedData = SerializerUtils.SerializeToMemoryStream(MapStream.Serialize).ToArray(); var MapStream2 = MapStream.Unserialize(new MemoryStream(SerializedData)); MapStream2.Position = Position; Assert.Equal(Array, MapStream2.ReadBytes(5)); }
//[ReferenceArray(984)] public uint[] FreeSpace { get; set; } public override void PopulateExternalData(MapStream reader) { foreach (var reference in this.WellKnownItems) { reference.Initialize(this); } for (int i = 0; i < this.AiSquadDefinitions.Length; i++) { var squad = this.AiSquadDefinitions[i]; foreach (var loc in squad.StartingLocations) { loc.SquadIndex = i; } } }
public TagWrapper(TagBlock tag, MapStream map, Tag meta) { tag_ = tag; /* Enumerate through all the StringIDs in this tag, check to see if they exist in the Globals list, * if not we should add them locally and update the StringID value to point to the list*/ foreach (StringID string_id in tag as IEnumerable<StringID>) { if (Halo2.Strings.Contains(string_id)) continue; else { var string_value = map.Strings[string_id.Index]; var entry = new KeyValuePair<StringID, string>(string_id, string_value); local_strings_.Add(entry); var index = local_strings_.IndexOf(entry); short string_id_index = (short)(index |= 0x8000); sbyte string_length = (sbyte)Encoding.UTF8.GetByteCount(string_value); var bytes = BitConverter.GetBytes((int)new StringID(string_id_index, string_length)); //((IField)string_id).SetFieldData(bytes); throw new Exception(); } } foreach (TagIdent tag_id in tag as IEnumerable<TagIdent>) { tag_ids_.Add(tag_id); } /*Intent: to build a list of all tagblock addresses in tag */ foreach (var array in tag as IEnumerable<IFieldArray>) { var address = array.Address; if (array.Fields.Count() > 0) { var item = new { Address = address, Size = array.Fields[0].Size, Count = array.Fields.Count() }; tag_blocks.Add(item); if (meta.Contains(item.Address)) { } } } /* Intent: check every tag_block in the list for being external * if it is external build a reference list and add information about the tag_block * to that list. * address => [count, size]? * */ }
internal void LoadHierarchyModels(MapStream map) { //var tags = map.Where(x => x.Type.ToString() == "hlmt").Select(x => new { item = map[x.Identifier].Deserialize(), id = x.Identifier }); //foreach (var tag in tags) //{ // this.Add(tag.item, tag.id); //} }
public string Validate(tag_group validateTag, IEnumerable<tag_group> tagPool) { PointersList = new List<Tuple<BlamPointer, ElementArray>>(); StreamWriter stringWriter = File.CreateText(string.Format(@"C:\Users\stem\Documents\h2pc to h2xbox\analysis\{0}.txt", validateTag.Class.ToSafeString())); WriteMessage = new Log(stringWriter.WriteLine); int offset = 0; ElementArray elementArray = null; if (validateTag.ParentClass != TagClass.Null) { var parentClass = tagPool.Where(x => x.Class == validateTag.ParentClass).Single(); if (parentClass.ParentClass != TagClass.Null) { var baseClass = tagPool.Where(x => x.Class == parentClass.ParentClass).Single(); elementArray = ProcessTagBlockDefinition(baseClass.Definition, ref offset, true); elementArray.Append(ProcessTagBlockDefinition(parentClass.Definition, ref offset, true)); elementArray.Append(ProcessTagBlockDefinition(validateTag.Definition, ref offset, true)); } else { elementArray = ProcessTagBlockDefinition(parentClass.Definition, ref offset, true); elementArray.Append(ProcessTagBlockDefinition(validateTag.Definition, ref offset, true)); } } else { elementArray = ProcessTagBlockDefinition(validateTag.Definition, ref offset, true); } elementArray.Count = 1; var mapFiles = Directory.GetFiles(@"C:\Users\stem\Documents\modding\singleplayer", "*.map", SearchOption.TopDirectoryOnly) .Concat(Directory.GetFiles(@"C:\Users\stem\Documents\modding\multiplayer", "*.map", SearchOption.TopDirectoryOnly)) .Concat(Directory.GetFiles(@"C:\Users\stem\Documents\modding\resource", "*.map", SearchOption.TopDirectoryOnly)); foreach (var file in mapFiles) { using (var map = new MapStream(file)) { var binaryReader = new BinaryReader(map); OnWriteMessage(string.Format("Begin ({0})", map.MapName)); foreach (var tag in map.Tags) { if (!(tag.Type == validateTag.Class)) continue; else { VirtualMappedAddress metaTableMemory = new VirtualMappedAddress() { Address = map.Tags[0].VirtualAddress, Length = map.TagCacheLength }; isValidDelegate = new Func<BlamPointer, bool>(metaTableMemory.Contains); VirtualMappedAddress virtualTagMemory = new VirtualMappedAddress() { Address = tag.VirtualAddress, Length = tag.Length }; IsPointerOwnedByTagDelegate = new Func<BlamPointer, bool>(virtualTagMemory.Contains); OnWriteMessage(string.Format("Tag ({0})", tag.Path)); map[tag.Identifier].Seek(); offset = (int)map.Position; elementArray.VirtualAddress = map[tag.Identifier].Meta.VirtualAddress; PointersList = new List<Tuple<BlamPointer, ElementArray>>(); ValidateTagBlock(elementArray, elementArray.ToFixedArrayPointer(), binaryReader, ref offset); AnalyzePointers(PointersList); stringWriter.Flush(); } } Console.WriteLine(string.Format("Parsed ({0})", map.MapName)); //OnWriteMessage(string.Format("End ({0})", map.MapName)); } } stringWriter.Close(); return ""; }
private void LoadFile(string fileName) { this.activeObject = null; var directory = Path.GetDirectoryName(fileName); var maps = Directory.GetFiles(directory, "*.map", SearchOption.TopDirectoryOnly); var resourceMaps = maps.GroupBy( x => { return Halo2.CheckMapType(x); } ).Where(x => x.Key == MapType.MainMenu || x.Key == MapType.Shared || x.Key == MapType.SinglePlayerShared) .Select(g => g.First()).ToList(); resourceMaps.ForEach(x => Halo2.LoadResource(new MapStream(x))); StaticBenchmark.Begin(); this.map = new MapStream(fileName); StaticBenchmark.End(); this.Text = string.Format("{0} - Moonfish Marker Viewer 2014 for Remnantmods", (this.map as FileStream).Name); LoadModels(); LoadScenarioStructureBSP(); LoadScenario(); }
private bool ValidateBlamPointer(BlamPointer blamPointer, ElementArray info, MapStream stream) { var stringWriter = new StringWriter(); if (blamPointer.Count == 0 && blamPointer.Address == 0) return true; if (blamPointer.Count == 0 ^ blamPointer.Address == 0) stringWriter.WriteLine(string.Format("-> null-value count({0}) address({1}) is invalid", blamPointer.Count, blamPointer.Address)); if (blamPointer.Count < 0) stringWriter.WriteLine(string.Format("-> count({0}) is invalid", blamPointer.Count)); if (blamPointer.Count > info.MaxElementCount && info.MaxElementCount > 0) stringWriter.WriteLine(string.Format("-> count({0}) > max-count({1})", blamPointer.Count, info.MaxElementCount)); if (!stream.ContainsPointer(blamPointer)) stringWriter.WriteLine(string.Format("-> address({0}) not contained in stream({1})", blamPointer.Address, stream.Name)); var errors = stringWriter.ToString(); if (!string.IsNullOrWhiteSpace(errors)) { OnWriteMessage(string.Format("Pointer ({0})\n{1}", info.Name, errors)); return false; } return true; }
public void LoadScenario(MapStream map) { this.scenario = map["scnr", ""].Deserialize(); var scenery = scenario.sceneryPalette.Select(x => new { item = map[x.name.TagID].Deserialize(), id = x.name.TagID }); var weapons = scenario.weaponPalette.Select(x => new { item = map[x.name.TagID].Deserialize(), id = x.name.TagID }); var vehicles = scenario.vehiclePalette.Select(x => new { item = map[x.name.TagID].Deserialize(), id = x.name.TagID }); var crates = scenario.cratesPalette.Select(x => new { item = map[x.name.TagID].Deserialize(), id = x.name.TagID }); var equipment = scenario.equipmentPalette.Select(x => new { item = map[x.name.TagID].Deserialize(), id = x.name.TagID }); var items = scenery .Concat(weapons) .Concat(vehicles) .Concat(crates) .Concat(equipment); foreach (var item in items) { Add(item.item.HierarchyModel, item.id); } Log.Info(GL.GetError().ToString()); }
public static void Scan(MapStream input) { BinaryReader bin = new BinaryReader(input); input.Position = 0; var start_address = input.IndexVirtualAddress; List<object> possible_pointers = new List<object>(); for (int i = 0; i < input.Length / 8; i++) { var count = bin.ReadInt32(); var address = bin.ReadInt32(); if (count > 0 && address > start_address && address < start_address + input.Length) { possible_pointers.Add(new { Count = count, Address = address }); } } }