IEnumerator <T> IEnumerable <T> .GetEnumerator() { lock (this.Session.SyncLock) { var index = new RecordIndex <TKey>( this.Session, this.RecordManager, this.IndexName, this.Session.SerializerResolver.SerializerFor <Node <TKey> >() ); var indexEnumerator = new IndexEntryEnumerator <T, TKey>( this.Collection, this.Session, index, this.IsDescending); indexEnumerator.SetRange(this.Range); foreach (var node in indexEnumerator) { var record = RecordManager.GetRecord(node.Pointer); var obj = Serializer.Deserialize(record.Data); yield return(obj); } } }
public IEnumerable <TKey> GetKeyEnumerator() { //execute empty transaction, to apply any comitted but unapplied transactions this.Session.Transaction(() => { }); lock (this.Session.SyncLock) { foreach (var range in this.Ranges) { var index = new RecordIndex <TKey>( this.Session, this.RecordManager, this.IndexName, this.Session.SerializerResolver.SerializerFor <Node <TKey> >() ); var keyEnumerator = new KeysEnumerator <T, TKey>( this.Collection, this.Session, index, this.IsDescending); keyEnumerator.SetRange(range); foreach (var key in keyEnumerator) { yield return(key); } } } }
private LineupDataObj createTestTeamLineup(String arm, String start, String end) { LineupDataObj lineup = new LineupDataObj(RecordIndex.getNextId(RecordIndex.INDEX.TestLineupDataId)); lineup.PitcherArm = arm; // Converts 1R to the int 1 and letter 'R' if (start.Equals("E")) { lineup.BalanceItemFrom = balanceItems[hackyLookupIndex(0, start)]; } else { lineup.BalanceItemFrom = balanceItems[hackyLookupIndex(Int32.Parse(start.Substring(0, 1)), start.Substring(1, 1))]; } if (end.Equals("E")) { lineup.BalanceItemTo = balanceItems[hackyLookupIndex(0, start)]; } else { lineup.BalanceItemTo = balanceItems[hackyLookupIndex(Int32.Parse(end.Substring(0, 1)), end.Substring(1, 1))]; } return(lineup); }
public void Initialize() { _session = new Session(new TestPlatform(), ""); _mockTree = new MockBTree <object>(); _mockProvider = new MockBTreeDataProvider <object>(); _index = new RecordIndex <object>(_session, _mockTree, _mockProvider); }
private Team buildTeam(String teamAbrv, String division) { Team testTeam = new Team(RecordIndex.getNextId(RecordIndex.INDEX.TestTeamId), division, 0); testTeam.Abrv = teamAbrv; return(testTeam); }
private List <Player> lookupAssigned(int index) { List <Player> playersInLineup = new List <Player>(); for (int posIndex = index; posIndex <= index + 9; posIndex++) { if (GRID.Children[posIndex] is ComboBox) { ComboBox box = (ComboBox)GRID.Children[posIndex]; Object value = (Object)box.SelectedValue; if (value is DefenseComboBoxItem) { Player player = ((DefenseComboBoxItem)value).Value; if (player.Id == 0) { player.Id = RecordIndex.getNextId(RecordIndex.INDEX.PlayerId); } playersInLineup.Add(player); } else { playersInLineup.Add(new Player(true)); } } } return(playersInLineup); }
private void fillWithTestTeams(Dictionary <String, TeamLineup> lineups, int count) { for (int i = 1; i <= count; i++) { String teamName = "MyTeam" + i; TeamLineup lineup = new TeamLineup(); LineupData lupLeft = new LineupData(RecordIndex.getNextId(RecordIndex.INDEX.TestLineupDataId), "L", new LineupBalanceItem(0, 9, "L"), new LineupBalanceItem(18, 9, "R"), 77); lineup.Lineups.Add(lupLeft); List <Player> players = new List <Player>(); String[] names = { "CatcherL1", "FirstL1", "SecondL1", "ThirdL1", "ShortstopL1", "LeftL1", "CenterL1", "RightL1", "DesignatedL1" }; foreach (String name in names) { players.Add(createTestPlayer(name)); } LineupData lupRight = new LineupData(RecordIndex.getNextId(RecordIndex.INDEX.TestLineupDataId), "R", new LineupBalanceItem(0, 9, "L"), new LineupBalanceItem(18, 9, "R"), 888); lineup.Lineups.Add(lupRight); String[] namesR = { "CatcherR1", "FirstR1", "SecondR1", "ThirdR1", "ShortstopR1", "LeftR1", "CenterR1", "RightR1", "DesignatedR1" }; foreach (String name in namesR) { players.Add(createTestPlayer(name)); } lineup.playerByGRID = players; lineups.Add(teamName, lineup); } }
private Texture2D GetWeaponTextureAtlas( string filename, MetalTypes metalType, out Rect[] rectsOut, out RecordIndex[] indicesOut, int padding, int border, bool dilate = false) { // Load texture file cifFile.Load(Path.Combine(dfUnity.Arena2Path, filename), FileUsage.UseMemory, true); // Read every image in archive Rect rect; List <Texture2D> textures = new List <Texture2D>(); List <RecordIndex> indices = new List <RecordIndex>(); for (int record = 0; record < cifFile.RecordCount; record++) { int frames = cifFile.GetFrameCount(record); DFSize size = cifFile.GetSize(record); RecordIndex ri = new RecordIndex() { startIndex = textures.Count, frameCount = frames, width = size.Width, height = size.Height, }; indices.Add(ri); for (int frame = 0; frame < frames; frame++) { textures.Add(GetWeaponTexture2D(filename, record, frame, metalType, out rect, border, dilate)); } } // Pack textures into atlas Texture2D atlas = new Texture2D(2048, 2048, TextureFormat.RGBA32, false); rectsOut = atlas.PackTextures(textures.ToArray(), padding, 2048); indicesOut = indices.ToArray(); // Shrink UV rect to compensate for internal border float ru = 1f / atlas.width; float rv = 1f / atlas.height; for (int i = 0; i < rectsOut.Length; i++) { Rect rct = rectsOut[i]; rct.xMin += border * ru; rct.xMax -= border * ru; rct.yMin += border * rv; rct.yMax -= border * rv; rectsOut[i] = rct; } return(atlas); }
protected override void DoRun(Record record) { RecordIndex key = record.Definition.GetIndex(); if (!_numberOfRecords.ContainsKey(key)) { _numberOfRecords.Add(key, 0); } _numberOfRecords[key] = _numberOfRecords[key] + 1; }
protected internal override void UnRegister(object o, Int64 address) { var indexName = RecordIndex.GetIndexName <TObj>(this.Collection.Name, this.PropertyName, typeof(TAttribute)); var keys = this.GetKeys(o, address); foreach (var key in keys) { UnRegisterKey(key, address, this.Session, this.RecordManager, indexName); } }
public IndexEntryEnumerator( Collection collection, Session session, RecordIndex <TKey> index, bool isDescending = false ) : base(session) { this.Collection = collection; this.Index = index; this.IsDescending = isDescending; }
BuildEnumerator(IEnumerable <BTreeWalkerRange <ValueWithAddressIndexKey <TAttribute> > > ranges, bool IsDescending = false) { var indexName = RecordIndex.GetIndexName <TObj>(this.Collection.Name, this.PropertyName, typeof(TAttribute)); var enumerator = new CollectionEnumerator <TObj, ValueWithAddressIndexKey <TAttribute> >( this.Collection, Session, RecordManager, Serializer, indexName, IsDescending); enumerator.SetRanges(ranges); return(enumerator); }
protected internal override void EnsureIndex() { var indexName = RecordIndex.GetIndexName <TObj> (this.Collection.Name, this.PropertyName, typeof(TAttribute)); var index = new RecordIndex <TAttribute> ( this.Session, this.RecordManager, indexName, this.Session.SerializerResolver.SerializerFor <Node <TAttribute> > () ); //Creating a walker makes sure the index is ready index.GetWalker(); }
internal override void UnRegisterKey(object key, Int64 address, Session session, RecordManager recordManager, string indexName) { var index = new RecordIndex <TID>( this.Session, recordManager, indexName, this.Session.SerializerResolver.SerializerFor <Node <TID> >() ); index.UnRegister((TID)key); }
internal virtual void UnRegisterKey(object key, Int64 address, Session session, RecordManager recordManager, string indexName) { var index = new RecordIndex <ValueWithAddressIndexKey <TAttribute> >( this.Session, this.RecordManager, indexName, this.Session.SerializerResolver.SerializerFor <Node <ValueWithAddressIndexKey <TAttribute> > >() ); index.UnRegister((ValueWithAddressIndexKey <TAttribute>)key); }
public LineupMgrDlg(Boolean testMode) { if (!testMode) { InitializeComponent(); } WorkingLineup = new LineupDataObj(RecordIndex.getNextId(RecordIndex.INDEX.LineupDataId)); balanceItems = LineupTools.buildDefaultLineupTypes(); if (!testMode) { populateComboBoxes(CB_FROM, CB_TO, null); } }
private void BTN_SAVE_Click(object sender, EventArgs e) { if (CB_FROM.SelectedItem == null || CB_TO.SelectedItem == null || ((LineupBalanceItem)CB_FROM.SelectedItem).Value > ((LineupBalanceItem)CB_TO.SelectedItem).Value) { MessageBox.Show("FROM Selection must be less than or equal to the TO Selection"); return; } WorkingLineup = new LineupDataObj(RecordIndex.getNextId(RecordIndex.INDEX.LineupDataId)); WorkingLineup.BalanceItemFrom = (LineupBalanceItem)CB_FROM.SelectedItem; WorkingLineup.BalanceItemTo = (LineupBalanceItem)CB_TO.SelectedItem; WorkingLineup.PitcherArm = radioButtonLH.Checked ? "L" : "R"; this.Close(); }
protected override void DoEndOfFile() { foreach (KeyValuePair <RecordIndex, MinAndMax> entry in _minAndMaxRecordLength) { RecordIndex index = entry.Key; MinAndMax minAndMaxValue = entry.Value; string minLengthString = minAndMaxValue.GetMin()?.ToString() ?? "<no value>"; string maxLengthString = minAndMaxValue.GetMax()?.ToString() ?? "<no value>"; _testResults.Add(new TestResult(ResultType.Success, AddmlLocation.FromRecordIndex(index), string.Format(Messages.AnalyseFindExtremeRecordsMessage, maxLengthString, minLengthString))); } _minAndMaxRecordLength.Clear(); }
protected override void DoRun(Record record) { string recordValue = record.Value; int recordLength = recordValue.Length; RecordIndex index = record.Definition.GetIndex(); if (!_minAndMaxRecordLength.ContainsKey(index)) { _minAndMaxRecordLength.Add(index, new MinAndMax()); } MinAndMax minAndMaxValue = _minAndMaxRecordLength[index]; minAndMaxValue.NewValue(recordLength); }
protected override void DoEndOfFile() { foreach (KeyValuePair <RecordIndex, bool> entry in _recordDefinitionsInUse) { RecordIndex index = entry.Key; bool isInUse = entry.Value; if (!isInUse) { _testResults.Add(new TestResult(ResultType.Error, AddmlLocation.FromRecordIndex(entry.Key), Messages.ControlNotUsedRecordDefMessage)); } } _recordDefinitionsInUse.Clear(); }
protected override void DoRun(Record record) { List <string> primaryKeyValues = new List <string>(); foreach (Field field in record.Fields) { if (field.Definition.IsPartOfPrimaryKey()) { primaryKeyValues.Add(field.Value); } } PrimaryKeyValue primaryKeyValueForCurrentRecord = new PrimaryKeyValue(primaryKeyValues); RecordIndex recordIndex = record.Definition.GetIndex(); if (!_primaryKeyValuesPerRecord.ContainsKey(recordIndex)) { _primaryKeyValuesPerRecord.Add(recordIndex, new HashSet <PrimaryKeyValue>()); } HashSet <PrimaryKeyValue> allPrimaryKeyValuesForRecord = _primaryKeyValuesPerRecord[recordIndex]; // If null, this primary key value is already handled if (allPrimaryKeyValuesForRecord == null) { return; } // If list of primary key values already contains the value, it is not unique if (allPrimaryKeyValuesForRecord.Contains(primaryKeyValueForCurrentRecord)) { if (!_nonUniqueprimaryKeyValuesPerRecord.ContainsKey(recordIndex)) { _nonUniqueprimaryKeyValuesPerRecord.Add(recordIndex, new HashSet <PrimaryKeyValue>()); } _nonUniqueprimaryKeyValuesPerRecord[recordIndex].Add(primaryKeyValueForCurrentRecord); _primaryKeyValuesPerRecord[recordIndex].Remove(primaryKeyValueForCurrentRecord); } else { allPrimaryKeyValuesForRecord.Add(primaryKeyValueForCurrentRecord); } }
public IEnumerable <TKey> GetKeyEnumerator() { lock (this.Session.SyncLock) { var index = new RecordIndex <TKey>( this.Session, this.RecordManager, this.IndexName, this.Session.SerializerResolver.SerializerFor <Node <TKey> >() ); var keyEnumerator = new KeysEnumerator <T, TKey>( this.Collection, this.Session, index, this.IsDescending); keyEnumerator.SetRange(this.Range); return(keyEnumerator); } }
protected override void DoRun(Record record) { int?specifiedLength = record.Definition.RecordLength; if (!specifiedLength.HasValue) { return; } var actualLength = record.Value.Length; if (actualLength == specifiedLength) { return; } // actual record length is different than specified RecordIndex index = record.Definition.GetIndex(); _testResults.Add(new TestResult(ResultType.Error, AddmlLocation.FromRecordIndex(index), string.Format(Messages.ControlFixedLengthMessage, specifiedLength, actualLength))); }
private List <Player> buildListOfTestPitchers(String[,] testData) { List <Player> players = new List <Player>(); for (int i = 0; i < testData.GetLength(0); i++) { Player player = new Player(); player.Name = testData[i, 0]; player.IP = Int32.Parse(testData[i, 3]); player.Bal = testData[i, 2]; player.Hits = Int32.Parse(testData[i, 4]); player.BB = Int32.Parse(testData[i, 5]); player.GS = Int32.Parse(testData[i, 6]); player.SAVE = Int32.Parse(testData[i, 7]); player.Team = new Team(RecordIndex.getNextId(RecordIndex.INDEX.TestTeamId), "ABV", 3); player.IsHitter = false; player.Throws = testData[i, 1]; players.Add(player); } players.Sort(); return(players); }
IEnumerator <T> IEnumerable <T> .GetEnumerator() { //execute empty transaction, to apply any comitted but unapplied transactions this.Session.Transaction(() => { }); lock (this.Session.SyncLock) { foreach (var range in this.Ranges) { var index = new RecordIndex <TKey>( this.Session, this.RecordManager, this.IndexName, this.Session.SerializerResolver.SerializerFor <Node <TKey> >() ); var indexEnumerator = new IndexEntryEnumerator <T, TKey>( this.Collection, this.Session, index, this.IsDescending); indexEnumerator.SetRange(range); foreach (var node in indexEnumerator) { if (this.ShouldYieldObjectWithAddress(node.Pointer)) { var record = RecordManager.GetRecord(node.Pointer); var obj = Serializer.Deserialize(record.Data); if (this.ShouldYieldObject(obj)) { yield return(obj); } } } } } }
/// <summary> /// Gets Texture2D atlas from Daggerfall texture archive. /// Every record and frame in the archive will be added to atlas. /// An array of rects will be returned with sub-texture rect for each record index and frame. /// Currently supports one archive per atlas. Super-atlas packing (multiple archives) is in the works. /// </summary> /// <param name="settings">Get texture settings.</param> /// <param name="alphaTextureFormat">Alpha TextureFormat.</param> /// <param name="nonAlphaFormat">Non-alpha TextureFormat.</param> /// <returns>GetTextureResults.</returns> public GetTextureResults GetTexture2DAtlas( GetTextureSettings settings, SupportedAlphaTextureFormats alphaTextureFormat = SupportedAlphaTextureFormats.RGBA32, SupportedNonAlphaTextureFormats nonAlphaFormat = SupportedNonAlphaTextureFormats.RGB24) { GetTextureResults results = new GetTextureResults(); // Individual textures must remain readable to pack into atlas bool stayReadable = settings.stayReadable; settings.stayReadable = true; // Assign texture file TextureFile textureFile; if (settings.textureFile == null) { textureFile = new TextureFile(Path.Combine(Arena2Path, TextureFile.IndexToFileName(settings.archive)), FileUsage.UseMemory, true); settings.textureFile = textureFile; } else textureFile = settings.textureFile; // Create lists results.atlasSizes = new List<Vector2>(textureFile.RecordCount); results.atlasScales = new List<Vector2>(textureFile.RecordCount); results.atlasOffsets = new List<Vector2>(textureFile.RecordCount); results.atlasFrameCounts = new List<int>(textureFile.RecordCount); // Read every texture in archive bool hasNormalMaps = false; bool hasEmissionMaps = false; bool hasAnimation = false; List<Texture2D> albedoTextures = new List<Texture2D>(); List<Texture2D> normalTextures = new List<Texture2D>(); List<Texture2D> emissionTextures = new List<Texture2D>(); List<RecordIndex> indices = new List<RecordIndex>(); for (int record = 0; record < textureFile.RecordCount; record++) { // Get record index and frame count settings.record = record; int frames = textureFile.GetFrameCount(record); if (frames > 1) hasAnimation = true; // Get record information DFSize size = textureFile.GetSize(record); DFSize scale = textureFile.GetScale(record); DFPosition offset = textureFile.GetOffset(record); RecordIndex ri = new RecordIndex() { startIndex = albedoTextures.Count, frameCount = frames, width = size.Width, height = size.Height, }; indices.Add(ri); for (int frame = 0; frame < frames; frame++) { settings.frame = frame; GetTextureResults nextTextureResults = GetTexture2D(settings, alphaTextureFormat, nonAlphaFormat); albedoTextures.Add(nextTextureResults.albedoMap); if (nextTextureResults.normalMap != null) { normalTextures.Add(nextTextureResults.normalMap); hasNormalMaps = true; } if (nextTextureResults.emissionMap != null) { emissionTextures.Add(nextTextureResults.emissionMap); hasEmissionMaps = true; } } results.atlasSizes.Add(new Vector2(size.Width, size.Height)); results.atlasScales.Add(new Vector2(scale.Width, scale.Height)); results.atlasOffsets.Add(new Vector2(offset.X, offset.Y)); results.atlasFrameCounts.Add(frames); results.textureFile = textureFile; } // Pack albedo textures into atlas and get our rects Texture2D atlasAlbedoMap = new Texture2D(settings.atlasMaxSize, settings.atlasMaxSize, ParseTextureFormat(alphaTextureFormat), MipMaps); Rect[] rects = atlasAlbedoMap.PackTextures(albedoTextures.ToArray(), settings.atlasPadding, settings.atlasMaxSize, !stayReadable); // Pack normal textures into atlas Texture2D atlasNormalMap = null; if (hasNormalMaps) { // Normals must be ARGB32 atlasNormalMap = new Texture2D(settings.atlasMaxSize, settings.atlasMaxSize, TextureFormat.ARGB32, MipMaps); atlasNormalMap.PackTextures(normalTextures.ToArray(), settings.atlasPadding, settings.atlasMaxSize, !stayReadable); } // Pack emission textures into atlas // TODO: Change this as packing not consistent Texture2D atlasEmissionMap = null; if (hasEmissionMaps) { // Repacking to ensure correct mix of lit and unlit atlasEmissionMap = new Texture2D(settings.atlasMaxSize, settings.atlasMaxSize, ParseTextureFormat(alphaTextureFormat), MipMaps); atlasEmissionMap.PackTextures(emissionTextures.ToArray(), settings.atlasPadding, settings.atlasMaxSize, !stayReadable); } // Add to results if (results.atlasRects == null) results.atlasRects = new List<Rect>(rects.Length); if (results.atlasIndices == null) results.atlasIndices = new List<RecordIndex>(indices.Count); results.atlasRects.AddRange(rects); results.atlasIndices.AddRange(indices); // Shrink UV rect to compensate for internal border float ru = 1f / atlasAlbedoMap.width; float rv = 1f / atlasAlbedoMap.height; int finalBorder = settings.borderSize + settings.atlasShrinkUVs; for (int i = 0; i < results.atlasRects.Count; i++) { Rect rct = results.atlasRects[i]; rct.xMin += finalBorder * ru; rct.xMax -= finalBorder * ru; rct.yMin += finalBorder * rv; rct.yMax -= finalBorder * rv; results.atlasRects[i] = rct; } // Store results results.albedoMap = atlasAlbedoMap; results.normalMap = atlasNormalMap; results.emissionMap = atlasEmissionMap; results.isAtlasAnimated = hasAnimation; results.isEmissive = hasEmissionMaps; return results; }
protected override void DoRun(Record record) { RecordIndex recordIndex = record.Definition.GetIndex(); _recordDefinitionsInUse[recordIndex] = true; }
private Texture2D GetWeaponTextureAtlas( string filename, MetalTypes metalType, out Rect[] rectsOut, out RecordIndex[] indicesOut, int padding, int border, bool dilate = false) { // Load texture file cifFile.Load(Path.Combine(dfUnity.Arena2Path, filename), FileUsage.UseMemory, true); // Read every image in archive Rect rect; List<Texture2D> textures = new List<Texture2D>(); List<RecordIndex> indices = new List<RecordIndex>(); for (int record = 0; record < cifFile.RecordCount; record++) { int frames = cifFile.GetFrameCount(record); DFSize size = cifFile.GetSize(record); RecordIndex ri = new RecordIndex() { startIndex = textures.Count, frameCount = frames, width = size.Width, height = size.Height, }; indices.Add(ri); for (int frame = 0; frame < frames; frame++) { textures.Add(GetWeaponTexture2D(filename, record, frame, metalType, out rect, border, dilate)); } } // Pack textures into atlas Texture2D atlas = new Texture2D(2048, 2048, TextureFormat.RGBA32, false); rectsOut = atlas.PackTextures(textures.ToArray(), padding, 2048); indicesOut = indices.ToArray(); // Shrink UV rect to compensate for internal border float ru = 1f / atlas.width; float rv = 1f / atlas.height; for (int i = 0; i < rectsOut.Length; i++) { Rect rct = rectsOut[i]; rct.xMin += border * ru; rct.xMax -= border * ru; rct.yMin += border * rv; rct.yMax -= border * rv; rectsOut[i] = rct; } return atlas; }
public void collectData(string teamName, string line, int leagueNameLength) { if (line.StartsWith("--AVERAGE")) { m_bWorkingOnHitters = true; } else if (line.StartsWith("----ERA")) { m_bWorkingOnHitters = false; } else if (line.StartsWith("NAME") || line.Trim().Length == 0) { return; } else { int idx = line.IndexOf("[4]"); String playerName = line.Substring(0, idx).Trim(); if (playerName.Length > 0) { Player player = new Player(); player.IsHitter = m_bWorkingOnHitters; player.Name = playerName; String data = line.Substring(idx + 4).Trim(); Regex regex; if (data.Contains("---") && !m_bWorkingOnHitters) { regex = new Regex(REGEX_USAGE_PITCHER_NOT_USED); } else { regex = m_bWorkingOnHitters ? new Regex(REGEX_USAGE_HITTER) : new Regex(REGEX_USAGE_PITCHER); } Match teamMatch = regex.Match(line); if (teamMatch.Success) { /* * Hitters < 120 actual at bats are allowed at 150% (ie ab * 1.5) * Hitters > 120 actual at bats are actual at bats + 60 (ie ab + 60) * Hitters > 600 actual at bats are allowed at 110% (ie ab * 1.1) * * Pitchers < 60 is 150% of actual (59 * 1.5) = +29 * Pitchers > 118 innings is innings + 30 * Pitchers > 199 is 115% of actual (199 * 1.15) = +29 */ if (m_bWorkingOnHitters) { player.Actual = Convert.ToInt32(teamMatch.Groups[1].Value.Trim()); if (player.Actual < 25) { return; } player.Replay = Convert.ToInt32(teamMatch.Groups[2].Value.Trim()); player.TargetUsage = getPlayerTargetUsage(player.Actual); } else { player.Actual = Convert.ToInt32(teamMatch.Groups[1].Value.Trim()); if (player.Actual < 25) { return; } player.Replay = Convert.ToInt32(teamMatch.Groups[2].Value.Trim()); player.TargetUsage = getPitcherTargetUsage(player.Actual); } Team team = Report.DATABASE.getTeam(TeamUtils.prettyTeamName(teamName)); if (team == null) { team = new Team(RecordIndex.getNextId(RecordIndex.INDEX.TeamId), "XX", leagueNameLength); team.Abrv = teamName; } player.Team = team; } listOfPlayers.Add(player); } } }
private Texture2D GetWeaponTextureAtlas( string filename, MetalTypes metalType, out Rect[] rectsOut, out RecordIndex[] indicesOut, int padding, int border, bool dilate = false) { // Load texture file cifFile.Load(Path.Combine(dfUnity.Arena2Path, filename), FileUsage.UseMemory, true); // Read every image in archive Rect rect; List <Texture2D> textures = new List <Texture2D>(); List <RecordIndex> indices = new List <RecordIndex>(); CustomTextures = new Dictionary <string, Texture2D>(); for (int record = 0; record < cifFile.RecordCount; record++) { int frames = cifFile.GetFrameCount(record); DFSize size = cifFile.GetSize(record); RecordIndex ri = new RecordIndex() { startIndex = textures.Count, frameCount = frames, width = size.Width, height = size.Height, }; indices.Add(ri); for (int frame = 0; frame < frames; frame++) { textures.Add(GetWeaponTexture2D(filename, record, frame, metalType, out rect, border, dilate)); Texture2D tex; if (TextureReplacement.TryImportCifRci(filename, record, frame, metalType, out tex)) { tex.filterMode = (FilterMode)DaggerfallUnity.Settings.MainFilterMode; CustomTextures.Add(record + "-" + frame, tex); } //// Import custom texture //if (TextureReplacement.CustomCifExist(filename, record, frame, metalType)) //{ // Texture2D tex = TextureReplacement.LoadCustomCif(filename, record, frame, metalType); // tex.filterMode = (FilterMode)DaggerfallUnity.Settings.MainFilterMode; // CustomTextures.Add(record + "-" + frame, tex); //} } } // Pack textures into atlas Texture2D atlas = new Texture2D(2048, 2048, TextureFormat.ARGB32, false); rectsOut = atlas.PackTextures(textures.ToArray(), padding, 2048); indicesOut = indices.ToArray(); // Shrink UV rect to compensate for internal border float ru = 1f / atlas.width; float rv = 1f / atlas.height; for (int i = 0; i < rectsOut.Length; i++) { Rect rct = rectsOut[i]; rct.xMin += border * ru; rct.xMax -= border * ru; rct.yMin += border * rv; rct.yMax -= border * rv; rectsOut[i] = rct; } return(atlas); }
/// <summary> /// Gets Texture2D atlas from Daggerfall texture archive. /// Every record and frame in the archive will be added to atlas. /// An array of rects will be returned with sub-texture rect for each record index and frame. /// Currently supports one archive per atlas. Super-atlas packing (multiple archives) is in the works. /// </summary> /// <param name="settings">Get texture settings.</param> /// <param name="alphaTextureFormat">Alpha TextureFormat.</param> /// <param name="nonAlphaFormat">Non-alpha TextureFormat.</param> /// <returns>GetTextureResults.</returns> public GetTextureResults GetTexture2DAtlas( GetTextureSettings settings, SupportedAlphaTextureFormats alphaTextureFormat = SupportedAlphaTextureFormats.RGBA32, SupportedNonAlphaTextureFormats nonAlphaFormat = SupportedNonAlphaTextureFormats.RGB24) { GetTextureResults results = new GetTextureResults(); // Individual textures must remain readable to pack into atlas bool stayReadable = settings.stayReadable; settings.stayReadable = true; // Assign texture file TextureFile textureFile; if (settings.textureFile == null) { textureFile = new TextureFile(Path.Combine(Arena2Path, TextureFile.IndexToFileName(settings.archive)), FileUsage.UseMemory, true); settings.textureFile = textureFile; } else { textureFile = settings.textureFile; } // Create lists results.atlasSizes = new List <Vector2>(textureFile.RecordCount); results.atlasScales = new List <Vector2>(textureFile.RecordCount); results.atlasOffsets = new List <Vector2>(textureFile.RecordCount); results.atlasFrameCounts = new List <int>(textureFile.RecordCount); // Read every texture in archive bool hasNormalMaps = false; bool hasEmissionMaps = false; bool hasAnimation = false; bool allowImport = (settings.atlasMaxSize == 4096); List <Texture2D> albedoTextures = new List <Texture2D>(); List <Texture2D> normalTextures = new List <Texture2D>(); List <Texture2D> emissionTextures = new List <Texture2D>(); List <RecordIndex> indices = new List <RecordIndex>(); for (int record = 0; record < textureFile.RecordCount; record++) { // Get record index and frame count settings.record = record; int frames = textureFile.GetFrameCount(record); if (frames > 1) { hasAnimation = true; } // Get record information DFSize size = textureFile.GetSize(record); DFSize scale = textureFile.GetScale(record); DFPosition offset = textureFile.GetOffset(record); RecordIndex ri = new RecordIndex() { startIndex = albedoTextures.Count, frameCount = frames, width = size.Width, height = size.Height, }; indices.Add(ri); for (int frame = 0; frame < frames; frame++) { settings.frame = frame; GetTextureResults nextTextureResults = GetTexture2D(settings, alphaTextureFormat, nonAlphaFormat, allowImport); albedoTextures.Add(nextTextureResults.albedoMap); if (nextTextureResults.normalMap != null) { normalTextures.Add(nextTextureResults.normalMap); hasNormalMaps = true; } if (nextTextureResults.emissionMap != null) { emissionTextures.Add(nextTextureResults.emissionMap); hasEmissionMaps = true; } } results.atlasSizes.Add(new Vector2(size.Width, size.Height)); results.atlasScales.Add(new Vector2(scale.Width, scale.Height)); results.atlasOffsets.Add(new Vector2(offset.X, offset.Y)); results.atlasFrameCounts.Add(frames); results.textureFile = textureFile; } // Pack albedo textures into atlas and get our rects Texture2D atlasAlbedoMap = new Texture2D(settings.atlasMaxSize, settings.atlasMaxSize, ParseTextureFormat(alphaTextureFormat), MipMaps); Rect[] rects = atlasAlbedoMap.PackTextures(albedoTextures.ToArray(), settings.atlasPadding, settings.atlasMaxSize, !stayReadable); // Pack normal textures into atlas Texture2D atlasNormalMap = null; if (hasNormalMaps) { // Normals must be ARGB32 atlasNormalMap = new Texture2D(settings.atlasMaxSize, settings.atlasMaxSize, TextureFormat.ARGB32, MipMaps); atlasNormalMap.PackTextures(normalTextures.ToArray(), settings.atlasPadding, settings.atlasMaxSize, !stayReadable); } // Pack emission textures into atlas // TODO: Change this as packing not consistent Texture2D atlasEmissionMap = null; if (hasEmissionMaps) { // Repacking to ensure correct mix of lit and unlit atlasEmissionMap = new Texture2D(settings.atlasMaxSize, settings.atlasMaxSize, ParseTextureFormat(alphaTextureFormat), MipMaps); atlasEmissionMap.PackTextures(emissionTextures.ToArray(), settings.atlasPadding, settings.atlasMaxSize, !stayReadable); } // Add to results if (results.atlasRects == null) { results.atlasRects = new List <Rect>(rects.Length); } if (results.atlasIndices == null) { results.atlasIndices = new List <RecordIndex>(indices.Count); } results.atlasRects.AddRange(rects); results.atlasIndices.AddRange(indices); // Shrink UV rect to compensate for internal border float ru = 1f / atlasAlbedoMap.width; float rv = 1f / atlasAlbedoMap.height; int finalBorder = settings.borderSize + settings.atlasShrinkUVs; for (int i = 0; i < results.atlasRects.Count; i++) { Rect rct = results.atlasRects[i]; rct.xMin += finalBorder * ru; rct.xMax -= finalBorder * ru; rct.yMin += finalBorder * rv; rct.yMax -= finalBorder * rv; results.atlasRects[i] = rct; } // Store results results.albedoMap = atlasAlbedoMap; results.normalMap = atlasNormalMap; results.emissionMap = atlasEmissionMap; results.isAtlasAnimated = hasAnimation; results.isEmissive = hasEmissionMaps; return(results); }
public void Initialize() { balanceItems = LineupTools.buildDefaultLineupTypes(); RecordIndex.resetIndex(RecordIndex.INDEX.TestTeamId); RecordIndex.resetIndex(RecordIndex.INDEX.TestLineupDataId); }