Example #1
0
            public void IntegrateFurther(LineSet positions, float?maxTime = null)
            {
                try {
                    Debug.Assert(Field.NumVectorDimensions <= 3);

                    LineSet             result;
                    PointSet <EndPoint> ends = positions.GetAllEndPoints();
                    if (ends.Length == 0)
                    {
                        return;
                    }

                    //int validPoints = 0;
                    for (int index = 0; index < positions.Length; ++index)
                    {
                        if (positions[index].Length == 0 || ends[index] == null || (ends[index].Status != Status.BORDER && ends[index].Status != Status.TIME_BORDER && ends[index].Status != Status.OK))
                        {
                            continue;
                        }
                        StreamLine <Vector3> streamline = IntegrateLineForRendering(((Vec3)ends.Points[index].Position).ToVec(Field.NumVectorDimensions), maxTime);
                        positions[index].Positions   = positions.Lines[index].Positions.Concat(streamline.Points).ToArray();
                        positions[index].Status      = streamline.Status;
                        positions[index].LineLength += streamline.LineLength;

                        //if ((index) % (positions.Length / 10) == 0)
                        //    Console.WriteLine("Further integrated {0}/{1} lines. {2}%", index, positions.Length, ((float)index*100) / positions.Length);
                        //validPoints++;
                    }
                    //return new LineSet(lines) { Color = (Vector3)Direction };
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
Example #2
0
        private void AnalyzeLine(object SteamLine_notifier)
        {
            List <object>    param    = (List <object>)SteamLine_notifier;
            StreamLine       sl       = (StreamLine)param[0];
            ManualResetEvent notifier = (ManualResetEvent)param[1];

            double maxFTLE = double.NegativeInfinity;

            semaphore.WaitOne();
            foreach (SeedPoint sp in sl.Points)
            {
                if (sp.FTLE > maxFTLE)
                {
                    maxFTLE = sp.FTLE;
                }
            }
            foreach (SeedPoint sp in sl.Points)
            {
                SeedPoint newSp = new SeedPoint(sp, maxFTLE);
                lock (bulkListLock)
                {
                    bulkList.Add(newSp);
                }
            }
            semaphore.Release();
            notifier.Set();
        }
Example #3
0
        public List <Thread> Start(float radius, int steps, double dt, int direction, List <Point> entryPoints, int maxThreads,
                                   ManualResetEvent notifier, BackgroundWorker worker)
        {
            List <Thread> threads = new List <Thread>(maxThreads);

            semaphore = new Semaphore(maxThreads, maxThreads);

            StreamLine.ResetCount();
            worker.ReportProgress(0);
            int total = entryPoints.Count;
            int count = total;

            foreach (Point p in entryPoints)
            {
                if (p == null)
                {
                    Debug.WriteLine("[SEVERE] Advection.Start: point p is null in entrypoints!");
                    continue;
                }
                StreamLine sl = new StreamLine(new Seed(p, radius, IDS));
                SLS.AddLine(sl);
                Thread t = new Thread(sl.CalculateStreamLine);
                t.Start(new List <object> {
                    steps, dt, direction, semaphore, notifier
                });
                threads.Add(t);
                count--;
                worker.ReportProgress((total - count) * 1000 / total);
            }
            return(threads);
        }
        private void AddLineButtonPressed(object sender, System.EventArgs e)
        {
            TreeNode   node = linesTree.SelectedNode;
            StreamLine line = new StreamLine();

            line.Group = node.Text;
            line.Flags = "";

            TreeNode child = new TreeNode();

            child.Name = "GroupLoader" + node.Index;
            child.Text = line.Name;
            child.Tag  = line;
            node.Nodes.Add(child);
        }
 private void CopyLoadListAbove_Click(object sender, EventArgs e)
 {
     if (linesTree.SelectedNode != null && linesTree.SelectedNode.Tag != null)
     {
         if (linesTree.SelectedNode.Tag.GetType() == typeof(StreamLine))
         {
             TreeNode   node    = linesTree.SelectedNode;
             StreamLine newLine = new StreamLine((node.Tag as StreamLine));
             TreeNode   newNode = new TreeNode();
             newNode.Name = "GroupLoader" + node.Index;
             newNode.Text = newLine.Name;
             newNode.Tag  = newLine;
             node.Parent.Nodes.Insert(node.Index + 1, newNode);
         }
     }
 }
Example #6
0
        private void AddLineButtonPressed(object sender, System.EventArgs e)
        {
            TreeNode   node = linesTree.SelectedNode;
            StreamLine line = new StreamLine();

            line.Group = node.Text;
            line.Flags = "";

            TreeNode child = new TreeNode();

            child.Name = "GroupLoader" + node.Index;
            child.Text = line.Name;
            child.Tag  = line;
            node.Nodes.Add(child);

            Text          = Language.GetString("$STREAM_EDITOR_TITLE") + "*";
            bIsFileEdited = true;
        }
        private void Paste()
        {
            var data = clipboard;

            if (data != null)
            {
                if (linesTree.SelectedNode != null && linesTree.SelectedNode.Tag != null)
                {
                    var tag = linesTree.SelectedNode.Tag;
                    if (tag is StreamLine && data is StreamLine)
                    {
                        StreamLine newData = new StreamLine(data as StreamLine);
                        linesTree.SelectedNode.Tag  = newData;
                        linesTree.SelectedNode.Text = newData.Name;
                    }
                }
            }
            PropertyGrid_Stream.SelectedObject = linesTree?.SelectedNode.Tag;
        }
Example #8
0
        private void CopyLoadListAbove_Click(object sender, EventArgs e)
        {
            if (linesTree.SelectedNode != null && linesTree.SelectedNode.Tag != null)
            {
                if (linesTree.SelectedNode.Tag.GetType() == typeof(StreamLine))
                {
                    TreeNode   node    = linesTree.SelectedNode;
                    StreamLine newLine = new StreamLine((node.Tag as StreamLine));
                    TreeNode   newNode = new TreeNode();
                    newNode.Name = "GroupLoader" + node.Index;
                    newNode.Text = newLine.Name;
                    newNode.Tag  = newLine;
                    node.Parent.Nodes.Insert(node.Index + 1, newNode);

                    Text          = Language.GetString("$STREAM_EDITOR_TITLE") + "*";
                    bIsFileEdited = true;
                }
            }
        }
Example #9
0
            public LineSet[] Integrate <P>(PointSet <P> positions, bool forwardAndBackward = false, float?maxTime = null) where P : Point
            {
                Debug.Assert(Field.NumVectorDimensions <= 3);

                Line[] lines        = new Line[positions.Length];
                Line[] linesReverse = new Line[forwardAndBackward? positions.Length : 0];

                LineSet[] result = new LineSet[forwardAndBackward ? 2 : 1];

                for (int index = 0; index < positions.Length; ++index)
                {
                    StreamLine <Vector3> streamline = IntegrateLineForRendering(((Vec3)positions.Points[index].Position).ToVec(Field.NumVectorDimensions), maxTime);
                    lines[index]            = new Line();
                    lines[index].Positions  = streamline.Points.ToArray();
                    lines[index].Status     = streamline.Status;
                    lines[index].LineLength = streamline.LineLength;

                    //if ((index) % (positions.Length / 10) == 0)
                    //    Console.WriteLine("Integrated {0}/{1} lines. {2}%", index, positions.Length, ((float)index * 100) / positions.Length);
                }
                result[0] = new LineSet(lines)
                {
                    Color = (Vector3)Direction
                };

                if (forwardAndBackward)
                {
                    Direction = !Direction;
                    for (int index = 0; index < positions.Length; ++index)
                    {
                        StreamLine <Vector3> streamline = IntegrateLineForRendering((Vec3)positions.Points[index].Position, maxTime);
                        linesReverse[index]           = new Line();
                        linesReverse[index].Positions = streamline.Points.ToArray();
                    }
                    result[1] = new LineSet(linesReverse)
                    {
                        Color = (Vector3)Direction
                    };
                    Direction = !Direction;
                }
                return(result);
            }
Example #10
0
            public StreamLine(StreamLine other)
            {
                name     = other.name + "_duplicated";
                group    = other.group;
                loadType = other.loadType;
                flags    = other.flags;
                unk10    = other.unk10;
                unk11    = other.unk11;
                unk5     = other.unk5;
                unk12    = other.unk12;
                unk13    = other.unk13;
                unk14    = other.unk14;
                unk15    = other.unk15;

                loadList = new StreamLoader[other.loadList.Length];
                for (int i = 0; i < other.loadList.Length; i++)
                {
                    loadList[i] = new StreamLoader(other.loadList[i]);
                }
            }
        private void CopyLoadListAbove_Click(object sender, EventArgs e)
        {
            if (linesTree.SelectedNode != null && linesTree.SelectedNode.Tag != null)
            {
                if (linesTree.SelectedNode.Tag.GetType() == typeof(StreamLine))
                {
                    TreeNode parent = linesTree.SelectedNode.Parent;
                    TreeNode node   = linesTree.SelectedNode;

                    int index = parent.Nodes.IndexOf(node);
                    if (index > 0)
                    {
                        TreeNode toCopy = parent.Nodes[index];

                        StreamLine line       = (linesTree.SelectedNode.Tag as StreamLine);
                        StreamLine toCopyLine = (parent.Nodes[index - 1].Tag as StreamLine);
                        line.loadList = toCopyLine.loadList;
                        linesTree.SelectedNode.Tag = line;
                    }
                }
            }
        }
Example #12
0
        private void Paste()
        {
            var data = clipboard;

            if (data != null)
            {
                if (linesTree.SelectedNode != null && linesTree.SelectedNode.Tag != null)
                {
                    var tag = linesTree.SelectedNode.Tag;
                    if (tag is StreamLine && data is StreamLine)
                    {
                        StreamLine newData = new StreamLine(data as StreamLine);
                        linesTree.SelectedNode.Tag  = newData;
                        linesTree.SelectedNode.Text = newData.Name;
                    }

                    Text          = Language.GetString("$STREAM_EDITOR_TITLE") + "*";
                    bIsFileEdited = true;
                }
            }
            PropertyGrid_Stream.SelectedObject = linesTree?.SelectedNode.Tag;
        }
Example #13
0
        public void ReadFromFile(BinaryReader reader)
        {
            if (reader.ReadInt32() != 1299346515)
            {
                return;
            }

            if (reader.ReadInt32() != 0x6)
            {
                return;
            }

            int fileSize = reader.ReadInt32();
            int unk0     = reader.ReadInt32();

            int numGroups     = reader.ReadInt32();
            int groupOffset   = reader.ReadInt32();
            int numHeaders    = reader.ReadInt32();
            int headerOffset  = reader.ReadInt32();
            int numLines      = reader.ReadInt32();
            int lineOffset    = reader.ReadInt32();
            int numLoaders    = reader.ReadInt32();
            int loadersOffset = reader.ReadInt32();
            int numBlocks     = reader.ReadInt32();
            int blockOffset   = reader.ReadInt32();
            int numHashes     = reader.ReadInt32();
            int hashOffset    = reader.ReadInt32();
            int poolSize      = reader.ReadInt32();
            int poolOffset    = reader.ReadInt32();

            Debug.Assert(reader.BaseStream.Position == groupOffset, "Failed to reach the starting offset for group declaration!");

            groups = new StreamGroup[numGroups];
            for (int i = 0; i < numGroups; i++)
            {
                StreamGroup map = new StreamGroup();
                map.nameIDX     = reader.ReadInt32();
                map.Name        = ReadFromBuffer((long)((ulong)map.nameIDX + (ulong)poolOffset), reader.BaseStream.Position, reader);
                map.Type        = (GroupTypes)reader.ReadInt32();
                map.Unk01       = reader.ReadInt32();
                map.startOffset = reader.ReadInt32();
                map.endOffset   = reader.ReadInt32();
                map.unk5        = reader.ReadInt32();
                groups[i]       = map;
            }

            Debug.Assert(reader.BaseStream.Position == headerOffset, "Did not reach the header starting offset");

            groupHeaders = new string[numHeaders];
            ulong[] ulongHeaders = new ulong[numHeaders];

            for (int i = 0; i < numHeaders; i++)
            {
                ulongHeaders[i] = reader.ReadUInt64();
                groupHeaders[i] = ReadFromBuffer((long)(ulongHeaders[i] + (ulong)poolOffset), reader.BaseStream.Position, reader);
            }

            Debug.Assert(reader.BaseStream.Position == lineOffset, "Did not reach the line data starting offset!");

            lines = new StreamLine[numLines];

            for (int i = 0; i < numLines; i++)
            {
                StreamLine map = new StreamLine();
                map.nameIDX  = reader.ReadInt32();
                map.lineID   = reader.ReadInt32();
                map.groupID  = reader.ReadInt32();
                map.LoadType = reader.ReadInt32();
                map.flagIDX  = reader.ReadInt32();
                map.Unk5     = reader.ReadInt32();
                map.Unk10    = reader.ReadUInt64();
                map.Unk11    = reader.ReadUInt64();
                map.Unk12    = reader.ReadInt32();
                map.Unk13    = reader.ReadInt32();
                map.Unk14    = reader.ReadInt32();
                map.Unk15    = reader.ReadInt32();
                map.Group    = groupHeaders[map.groupID];
                map.Name     = ReadFromBuffer((long)((ulong)map.nameIDX + (ulong)poolOffset), reader.BaseStream.Position, reader);
                map.Flags    = ReadBufferSpecial((long)((ulong)map.flagIDX + (ulong)poolOffset), reader.BaseStream.Position, reader).TrimEnd('\0').Replace('\0', '|');
                lines[i]     = map;
            }

            Debug.Assert(reader.BaseStream.Position == loadersOffset, "Did not reach the loader data starting offset!");

            loaders = new StreamLoader[numLoaders];

            for (int i = 0; i < numLoaders; i++)
            {
                StreamLoader map = new StreamLoader();
                map.start = reader.ReadInt32();
                map.end   = reader.ReadInt32();
                map.Type  = (GroupTypes)reader.ReadInt32();

                map.LoaderSubID = reader.ReadInt32();
                map.LoaderID    = reader.ReadInt32();
                map.LoadType    = reader.ReadInt32();
                map.pathIDX     = reader.ReadInt32();
                map.entityIDX   = reader.ReadInt32();
                map.Path        = ReadFromBuffer((long)((ulong)map.pathIDX + (ulong)poolOffset), reader.BaseStream.Position, reader);
                map.Entity      = ReadBufferSpecial((long)((ulong)map.entityIDX + (ulong)poolOffset), reader.BaseStream.Position, reader).TrimEnd('\0').Replace('\0', '|');
                loaders[i]      = map;
            }

            Debug.Assert(reader.BaseStream.Position == blockOffset, "Did not reach the block declaration starting offset!");

            blocks = new StreamBlock[numBlocks];
            for (int i = 0; i < numBlocks; i++)
            {
                StreamBlock map = new StreamBlock();
                map.startOffset = reader.ReadInt32();
                map.endOffset   = reader.ReadInt32();
                map.Hashes      = new ulong[map.endOffset - map.startOffset];
                blocks[i]       = map;
            }

            Debug.Assert(reader.BaseStream.Position == hashOffset, "Did not reach the block hashes starting offset!");

            hashes = new ulong[numHashes];

            for (int i = 0; i < numHashes; i++)
            {
                hashes[i] = reader.ReadUInt64();
            }

            for (int i = 0; i < numBlocks; i++)
            {
                var block = blocks[i];
                Array.Copy(hashes, block.startOffset, block.Hashes, 0, block.Hashes.Length);
            }

            Debug.Assert(reader.BaseStream.Position == poolOffset, "Did not reach the buffer pool starting offset!");

            reader.BaseStream.Seek(poolSize, SeekOrigin.Current);

            Debug.Assert(reader.BaseStream.Position == reader.BaseStream.Length, "Did not reach the end of the file!");
        }
Example #14
0
        private void LoadGameContent()
        {
            SplashScreen.ShowSplashScreen();
            SplashScreen.SetStatus("Initializing Roslyn");
            SkillEffect.LoadAllEffects();
            SplashScreen.SetStatus("Initializing Graphics");
            BattleMap.DicGlobalVariables = new Dictionary <string, string>();
            BattleMap.DicRouteChoices    = new Dictionary <string, int>();
            GameScreen.LoadHelpers(Content);
            TextHelper.LoadHelpers(Content);

            #region Key mapping

            FileStream   FS = new FileStream("Keys.ini", FileMode.Open, FileAccess.Read);
            StreamReader SR = new StreamReader(FS);
            string       StreamLine;
            string[]     StreamData;
            string[]     StreamKeys;
            List <Keys>  ListNewKeys = new List <Keys>();
            Keys         NewKey;
            Keys[]       UsedKeys;

            while (!SR.EndOfStream)
            {
                StreamLine = SR.ReadLine();
                ListNewKeys.Clear();

                if (StreamLine.Contains('='))
                {
                    StreamData = StreamLine.Split('=');
                    StreamKeys = StreamData[1].Split(',');

                    //Read keys
                    for (int K = 0; K < StreamKeys.Length; K++)
                    {
                        NewKey = ConvertTextToKeys(StreamKeys[K].Trim());
                        if (!ListNewKeys.Contains(NewKey))
                        {
                            ListNewKeys.Add(NewKey);
                        }
                    }
                    UsedKeys = ListNewKeys.ToArray();

                    //Assign keys to the right command.
                    switch (StreamData[0].Trim())
                    {
                    case "Left":
                        KeyboardHelper.MoveLeft = UsedKeys;
                        break;

                    case "Right":
                        KeyboardHelper.MoveRight = UsedKeys;
                        break;

                    case "Up":
                        KeyboardHelper.MoveUp = UsedKeys;
                        break;

                    case "Down":
                        KeyboardHelper.MoveDown = UsedKeys;
                        break;

                    case "Confirm":
                        KeyboardHelper.ConfirmChoice = UsedKeys;
                        break;

                    case "Cancel":
                        KeyboardHelper.CancelChoice = UsedKeys;
                        break;

                    case "Command 1":
                        KeyboardHelper.Command1 = UsedKeys;
                        break;

                    case "Command 2":
                        KeyboardHelper.Command2 = UsedKeys;
                        break;

                    case "L Button":
                        KeyboardHelper.LButton = UsedKeys;
                        break;

                    case "R Button":
                        KeyboardHelper.RButton = UsedKeys;
                        break;

                    case "Skip":
                        KeyboardHelper.Skip = UsedKeys;
                        break;
                    }
                }
            }

            FS.Close();
            SR.Close();

            #endregion

            SplashScreen.SetStatus("Loading Ressources");

            SystemList.LoadSystemLists();

            #region Ressources loading

            string[] Files;
            bool     InstanceIsBaseObject;
            Type     ObjectType;

            #region Battle Maps

            Files = Directory.GetFiles("Mods", "*.dll");
            for (int F = 0; F < Files.Length; F++)
            {
                Assembly ass = Assembly.LoadFile(Path.GetFullPath(Files[F]));
                //Get every classes in it.
                Type[] types = ass.GetTypes();
                for (int t = 0; t < types.Count(); t++)
                {
                    //Look if the class inherit from Unit somewhere.
                    ObjectType           = types[t].BaseType;
                    InstanceIsBaseObject = ObjectType == typeof(BattleMap);
                    while (ObjectType != null && ObjectType != typeof(BattleMap))
                    {
                        ObjectType = ObjectType.BaseType;
                        if (ObjectType == null)
                        {
                            InstanceIsBaseObject = false;
                        }
                    }
                    //If this class is from BaseEditor, load it.
                    if (InstanceIsBaseObject)
                    {
                        BattleMap instance = Activator.CreateInstance(types[t]) as BattleMap;
                        BattleMap.DicBattmeMapType.Add(instance.GetMapType(), instance);
                    }
                }
            }

            #endregion

            #endregion

            SplashScreen.CloseForm();
        }
Example #15
0
        private void UpdateStream()
        {
            List <StreamLine>              lines          = new List <StreamLine>();
            List <StreamLoader>            loaders        = new List <StreamLoader>();
            Dictionary <int, StreamLoader> currentLoaders = new Dictionary <int, StreamLoader>();
            Dictionary <int, bool>         temp           = new Dictionary <int, bool>();

            foreach (TreeNode node in linesTree.Nodes)
            {
                foreach (TreeNode child in node.Nodes)
                {
                    StreamLine line = (child.Tag as StreamLine);
                    line.lineID = lines.Count;

                    lines.Add(line);
                    temp = new Dictionary <int, bool>();

                    for (int i = 0; i != currentLoaders.Count; i++)
                    {
                        temp.Add(currentLoaders.ElementAt(i).Key.GetHashCode(), false);
                    }

                    foreach (var loader in currentLoaders)
                    {
                        foreach (var load in line.loadList)
                        {
                            if (loader.Key == load.GetHashCode())
                            {
                                temp[loader.Key] = true;
                            }
                        }
                    }

                    for (int i = 0; i != temp.Count;)
                    {
                        if (temp.ElementAt(i).Value == false)
                        {
                            loaders.Add(currentLoaders[temp.ElementAt(i).Key]);
                            currentLoaders.Remove(temp.ElementAt(i).Key);
                            temp.Remove(temp.ElementAt(i).Key);
                        }
                        else
                        {
                            i++;
                        }
                    }

                    foreach (StreamLoader loader in line.loadList)
                    {
                        if (!currentLoaders.ContainsKey(loader.GetHashCode()))
                        {
                            loader.start = line.lineID;
                            loader.end   = line.lineID;
                            currentLoaders.Add(loader.GetHashCode(), loader);
                            temp.Add(loader.GetHashCode(), true);
                        }
                        else
                        {
                            currentLoaders[loader.GetHashCode()].end = line.lineID;
                        }
                    }
                }
            }
            foreach (var loader in currentLoaders)
            {
                loaders.Add(loader.Value);
            }

            currentLoaders = null;
            temp           = null;

            Sort(loaders);
            Dictionary <int, List <StreamLoader> > organised = new Dictionary <int, List <StreamLoader> >();
            List <StreamGroup> groups = new List <StreamGroup>();

            for (int i = 0; i < groupTree.Nodes.Count; i++)
            {
                var group = (groupTree.Nodes[i].Tag as StreamGroup);
                if (!organised.ContainsKey(i))
                {
                    organised.Add(i, new List <StreamLoader>());
                    groups.Add(group);
                }
            }

            foreach (StreamLoader pair in loaders)
            {
                if (string.IsNullOrEmpty(pair.AssignedGroup) && pair.GroupID == -1)
                {
                    if (pair.type != GroupTypes.Null)
                    {
                        for (int i = 0; i < groups.Count; i++)
                        {
                            var group = groups[i];
                            if (group.Type == pair.type)
                            {
                                pair.GroupID = i;
                                break;
                            }
                        }
                    }
                }

                if (!organised.ContainsKey(pair.GroupID))
                {
                    organised.Add(pair.GroupID, new List <StreamLoader>());
                    organised[pair.GroupID].Add(pair);
                }
                else
                {
                    organised[pair.GroupID].Add(pair);
                }
            }

            List <StreamLoader> streamLoaders = new List <StreamLoader>();
            int idx = 0;

            foreach (KeyValuePair <int, List <StreamLoader> > pair in organised)
            {
                var group = groups[idx];
                group.startOffset = streamLoaders.Count;
                streamLoaders.AddRange(pair.Value);
                group.endOffset = streamLoaders.Count - group.startOffset;
                idx++;
            }

            stream.lines   = lines.ToArray();
            stream.groups  = groups.ToArray();
            stream.loaders = streamLoaders.ToArray();
        }
Example #16
0
        private void UpdateStream()
        {
            List <StreamLine>              lines          = new List <StreamLine>();
            List <StreamLoader>            loaders        = new List <StreamLoader>();
            Dictionary <int, StreamLoader> currentLoaders = new Dictionary <int, StreamLoader>();
            Dictionary <int, bool>         temp           = new Dictionary <int, bool>();

            foreach (TreeNode node in linesTree.Nodes)
            {
                StreamHeaderGroup HeaderGroup = (StreamHeaderGroup)node.Tag;
                Debug.Assert(HeaderGroup != null, "We expect to be looking at a valid HeaderGroup.");

                foreach (TreeNode child in node.Nodes)
                {
                    StreamLine line = (child.Tag as StreamLine);
                    line.lineID = lines.Count;
                    line.Group  = HeaderGroup.HeaderName;

                    lines.Add(line);
                    temp = new Dictionary <int, bool>();

                    for (int i = 0; i != currentLoaders.Count; i++)
                    {
                        temp.Add(currentLoaders.ElementAt(i).Key.GetHashCode(), false);
                    }

                    foreach (var loader in currentLoaders)
                    {
                        foreach (var load in line.loadList)
                        {
                            if (loader.Key == load.GetHashCode())
                            {
                                temp[loader.Key] = true;
                            }
                        }
                    }

                    for (int i = 0; i != temp.Count;)
                    {
                        if (temp.ElementAt(i).Value == false)
                        {
                            loaders.Add(currentLoaders[temp.ElementAt(i).Key]);
                            currentLoaders.Remove(temp.ElementAt(i).Key);
                            temp.Remove(temp.ElementAt(i).Key);
                        }
                        else
                        {
                            i++;
                        }
                    }

                    foreach (StreamLoader loader in line.loadList)
                    {
                        if (!currentLoaders.ContainsKey(loader.GetHashCode()))
                        {
                            loader.start = line.lineID;
                            loader.end   = line.lineID;
                            currentLoaders.Add(loader.GetHashCode(), loader);
                            temp.Add(loader.GetHashCode(), true);
                        }
                        else
                        {
                            currentLoaders[loader.GetHashCode()].end = line.lineID;
                        }
                    }
                }
            }
            foreach (var loader in currentLoaders)
            {
                loaders.Add(loader.Value);
            }

            currentLoaders = null;
            temp           = null;

            Sort(loaders);
            Dictionary <int, List <StreamLoader> > organised = new Dictionary <int, List <StreamLoader> >();
            List <StreamGroup> groups = new List <StreamGroup>();

            for (int i = 0; i < groupTree.Nodes.Count; i++)
            {
                var group = (groupTree.Nodes[i].Tag as StreamGroup);
                if (!organised.ContainsKey(i))
                {
                    organised.Add(i, new List <StreamLoader>());
                    groups.Add(group);
                }
            }

            foreach (StreamLoader pair in loaders)
            {
                // The main idea of this is to find if the user has changed the group.
                // We have to iterate through the groups first and find out if this change has indeed happened.
                for (int i = 0; i < groups.Count; i++)
                {
                    var group = groups[i];

                    // If there the user has assigned a preferred group then we can look for that too.
                    // To make sure we are saving everything necessary, lets just replace everything relating to groups.
                    if (pair.PreferredGroup == group.Name)
                    {
                        pair.AssignedGroup = group.Name;
                        pair.GroupID       = i;
                        pair.Type          = group.Type;
                        break;
                    }

                    // So we check if they have modified - if yes, then we reset the group assignment so the toolkit
                    // treats this as a newly created StreamLoader.
                    if (pair.AssignedGroup == group.Name)
                    {
                        if (pair.Type != group.Type)
                        {
                            pair.AssignedGroup = string.Empty;
                            pair.GroupID       = -1;
                        }
                        break;
                    }
                }

                // This will handle any non-declared group assignments.
                if (string.IsNullOrEmpty(pair.AssignedGroup) && pair.GroupID == -1)
                {
                    if (pair.Type != GroupTypes.Null)
                    {
                        for (int i = 0; i < groups.Count; i++)
                        {
                            var group = groups[i];
                            if (group.Type == pair.Type)
                            {
                                pair.GroupID       = i;
                                pair.AssignedGroup = group.Name;
                                break;
                            }
                        }
                    }
                }

                if (!organised.ContainsKey(pair.GroupID))
                {
                    organised.Add(pair.GroupID, new List <StreamLoader>());
                    organised[pair.GroupID].Add(pair);
                }
                else
                {
                    organised[pair.GroupID].Add(pair);
                }
            }

            List <StreamLoader> streamLoaders = new List <StreamLoader>();
            int idx = 0;

            foreach (KeyValuePair <int, List <StreamLoader> > pair in organised)
            {
                var group = groups[idx];
                group.startOffset = streamLoaders.Count;
                streamLoaders.AddRange(pair.Value);
                group.endOffset = streamLoaders.Count - group.startOffset;
                idx++;
            }

            stream.Lines   = lines.ToArray();
            stream.Groups  = groups.ToArray();
            stream.Loaders = streamLoaders.ToArray();
        }
Example #17
0
            public virtual StreamLine <Vector3> IntegrateLineForRendering(Vector pos, float?maxTime = null)
            {
                StreamLine <Vector3> line = new StreamLine <Vector3>((int)(Field.Size.Max() * 1.5f / StepSize)); // Rough guess.
                //line.Points.Add((Vector3)pos);
                float timeBorder = maxTime ?? (((Field as VectorFieldUnsteady) == null) ? float.MaxValue : (Field.Grid.TimeOrigin ?? 0) + Field.Size.T);

                Vector point;
                Vector next = pos;

                if (CheckPosition(next) != Status.OK)
                {
                    return(line);
                }
                Status status;
                int    step        = -1;
                bool   attachTimeZ = Field.NumVectorDimensions == 2 && Field.TimeSlice != 0;
                float  stepLength;

                do
                {
                    step++;
                    point = next;
                    Vector3 posP = (Vector3)point;
                    if (attachTimeZ)
                    {
                        posP.Z = (float)Field.TimeSlice;
                    }
                    line.Points.Add(posP);
                    status = Step(point, out next, out stepLength);
                    if (status == Status.OK)
                    {
                        line.LineLength += stepLength;
                    }
                } while (status == Status.OK && step < MaxNumSteps && next.T <= timeBorder);

                // If the time was exceeded, take a small step at the end.
                if (next.T > timeBorder && (status == Status.OK || status == Status.BORDER))
                {
                    if (StepBorderTime(point, timeBorder, out next, out stepLength))
                    {
                        line.Points.Add((Vector3)next);
                        line.LineLength += stepLength;
                        status           = Status.TIME_BORDER;
                    }

                    if (next[1] < 0)
                    {
                        Console.WriteLine("Wut?");
                    }
                }

                // If a border was hit, take a small step at the end.
                if (status == Status.BORDER)
                {
                    if (StepBorder(point, out next, out stepLength))
                    {
                        line.Points.Add((Vector3)next);
                        line.LineLength += stepLength;
                    }
                }

                // Single points are confusing for everybody.
                if (line.Points.Count < 2)
                {
                    line.Points.Clear();
                    line.LineLength = 0;
                }
                line.Status = status;
                return(line);
            }
        public Transaction(IList <string> lines, int year, AccountType accountType)
        {
            const int MIN_LENGTH = 6;// 24;

            this.Type = accountType;

            var line = lines[0];

            this.Source = lines;

            var debug = false;

            Trace.WriteLineIf(debug, "LINE0: " + lines[0]);
            if (lines.Count > 1)
            {
                Trace.WriteLineIf(debug, "LINE1: " + lines[1]);
                if (lines.Count > 2)
                {
                    Trace.WriteLineIf(debug, "LINE2: " + lines[2]);
                }
            }

            if (line.Length > MIN_LENGTH && IsCrap(line) == false)
            {
                if (IsCrap(line))
                {
                    Trace.WriteLine(line);
                }

                Regex r = new Regex(@"^\d{1,2} [A-z]{3}", RegexOptions.IgnoreCase);
                Match m = r.Match(line.Substring(0, 6));

                if (m.Success)
                {
                    var month = m.Value.Split(' ')[1];     // had a gutful of regex now
                    var day   = m.Value.Substring(0, 2);

                    var lineDate = GetDateFromLine(line, year);

                    if (lineDate.HasValue)
                    {
                        Trace.WriteLine(string.Format("NEW TRANS: {0}", lines[0]));

                        this.Date = lineDate.Value;

                        if (StreamLine.IsBracketLine(line))
                        {
                            var line2 = line.Substring(0, line.IndexOf(')'));
                            this.Amount = LineParser.GetAmountFromLine(line2).GetValueOrDefault();
                            this.Biller = line;
                        }
                        else
                        {
                            //this.Biller = line.Substring(7, line.LastIndexOf(' ') - 7);
                            this.Biller = line.Substring(7);

                            var multiLine1 = lines.Count >= 2 && lines[1].StartsWith("##");
                            var multiLine2 = lines.Count >= 2 && lines[1].Count(f => f == ')') == 1;

                            if (multiLine2)
                            {
                                var line2 = lines[1].Substring(0, lines[1].IndexOf(')'));
                                this.Amount = LineParser.GetAmountFromLine(line2).GetValueOrDefault();
                            }
                            else
                            {
                                var amount = LineParser.GetAmountFromLine(line);
                                if (!multiLine1 && amount.HasValue)
                                {
                                    this.Amount = amount.Value;
                                }
                                else
                                {
                                    Trace.WriteLine("       " + lines[0]);
                                    Trace.WriteLine("       " + lines[1]);
                                    Trace.WriteLine("       " + lines[2]);
                                    if (lines[1].StartsWith("##"))
                                    {
                                        var line2 = LineParser.TrimEndAlpha(lines[2]);

                                        if (decimal.TryParse(line2, out decimal x))
                                        {
                                            this.Amount = decimal.Parse(line2);
                                        }
                                        else
                                        {
                                            this.Amount = amount.Value;
                                        }
                                    }
                                }
                            }
                        }

                        this.ParseSuccess = !string.IsNullOrWhiteSpace(this.Biller);

                        Trace.WriteLine(this.ToString());
                        Trace.WriteLine("----------------------------------------------------------------");
                        Trace.WriteLine("");
                    }
                }
            }
        }
        private void UpdateStream()
        {
            List <StreamLine>   lines   = new List <StreamLine>();
            List <StreamLoader> loaders = new List <StreamLoader>();
            Dictionary <string, StreamLoader> currentLoaders = new Dictionary <string, StreamLoader>();
            Dictionary <string, bool>         temp           = new Dictionary <string, bool>();

            foreach (TreeNode node in linesTree.Nodes)
            {
                foreach (TreeNode child in node.Nodes)
                {
                    StreamLine line = (child.Tag as StreamLine);
                    line.lineID = lines.Count;
                    lines.Add(line);
                    temp = new Dictionary <string, bool>();

                    for (int i = 0; i != currentLoaders.Count; i++)
                    {
                        temp.Add(currentLoaders.ElementAt(i).Key, false);
                    }

                    foreach (var loader in currentLoaders)
                    {
                        foreach (var load in line.loadList)
                        {
                            if (loader.Value.Path == load.Path)
                            {
                                temp[loader.Key] = true;
                            }
                        }
                    }

                    for (int i = 0; i != temp.Count;)
                    {
                        if (temp.ElementAt(i).Value == false)
                        {
                            loaders.Add(currentLoaders[temp.ElementAt(i).Key]);
                            currentLoaders.Remove(temp.ElementAt(i).Key);
                            temp.Remove(temp.ElementAt(i).Key);
                        }
                        else
                        {
                            i++;
                        }
                    }

                    foreach (StreamLoader loader in line.loadList)
                    {
                        if (!currentLoaders.ContainsKey(loader.Path))
                        {
                            loader.start = line.lineID;
                            loader.end   = line.lineID;
                            currentLoaders.Add(loader.Path, loader);
                            temp.Add(loader.Path, true);
                        }
                        else
                        {
                            currentLoaders[loader.Path].end = line.lineID;
                        }
                    }
                }
            }
            foreach (var loader in currentLoaders)
            {
                loaders.Add(loader.Value);
            }

            currentLoaders = null;
            temp           = null;

            Sort(loaders);
            Dictionary <string, List <StreamLoader> > organised = new Dictionary <string, List <StreamLoader> >();
            List <StreamGroup> groups = new List <StreamGroup>();

            foreach (TreeNode node in groupTree.Nodes)
            {
                if (!organised.ContainsKey(node.Text))
                {
                    organised.Add(node.Text, new List <StreamLoader>());
                    groups.Add((StreamGroup)node.Tag);
                }
            }

            foreach (StreamLoader pair in loaders)
            {
                if (!organised.ContainsKey(pair.Group))
                {
                    organised.Add(pair.Group, new List <StreamLoader>());
                    organised[pair.Group].Add(pair);
                }
                else
                {
                    organised[pair.Group].Add(pair);
                }
            }

            List <StreamLoader> streamLoaders = new List <StreamLoader>();
            int idx = 0;

            foreach (KeyValuePair <string, List <StreamLoader> > pair in organised)
            {
                groups[idx].startOffset = streamLoaders.Count;
                streamLoaders.AddRange(pair.Value);
                groups[idx].endOffset = streamLoaders.Count - groups[idx].startOffset;
                idx++;
            }

            stream.lines   = lines.ToArray();
            stream.groups  = groups.ToArray();
            stream.loaders = streamLoaders.ToArray();
        }
Example #20
0
        public void ReadFromFile(BinaryReader reader)
        {
            if (reader.ReadInt32() != 1299346515)
            {
                return;
            }

            if (reader.ReadInt32() != 0x6)
            {
                return;
            }

            int fileSize = reader.ReadInt32();
            int unk0     = reader.ReadInt32();

            int numGroups     = reader.ReadInt32();
            int groupOffset   = reader.ReadInt32();
            int numHeaders    = reader.ReadInt32();
            int headerOffset  = reader.ReadInt32();
            int numLines      = reader.ReadInt32();
            int lineOffset    = reader.ReadInt32();
            int numLoaders    = reader.ReadInt32();
            int loadersOffset = reader.ReadInt32();
            int numBlocks     = reader.ReadInt32();
            int blockOffset   = reader.ReadInt32();
            int numHashes     = reader.ReadInt32();
            int hashOffset    = reader.ReadInt32();
            int poolSize      = reader.ReadInt32();
            int poolOffset    = reader.ReadInt32();

            if (reader.BaseStream.Position != groupOffset)
            {
                throw new FormatException();
            }

            groups = new StreamGroup[numGroups];
            for (int i = 0; i < numGroups; i++)
            {
                StreamGroup map = new StreamGroup();
                map.nameIDX     = reader.ReadInt32();
                map.Name        = ReadFromBuffer((long)((ulong)map.nameIDX + (ulong)poolOffset), reader.BaseStream.Position, reader);
                map.Type        = reader.ReadInt32();
                map.Unk01       = reader.ReadInt32();
                map.startOffset = reader.ReadInt32();
                map.endOffset   = reader.ReadInt32();
                map.unk5        = reader.ReadInt32();
                groups[i]       = map;
            }

            if (reader.BaseStream.Position != headerOffset)
            {
                throw new FormatException();
            }

            groupHeaders = new string[numHeaders];
            ulong[] ulongHeaders = new ulong[numHeaders];

            for (int i = 0; i < numHeaders; i++)
            {
                ulongHeaders[i] = reader.ReadUInt64();
                groupHeaders[i] = ReadFromBuffer((long)(ulongHeaders[i] + (ulong)poolOffset), reader.BaseStream.Position, reader);
            }

            if (reader.BaseStream.Position != lineOffset)
            {
                throw new FormatException();
            }

            lines = new StreamLine[numLines];

            for (int i = 0; i < numLines; i++)
            {
                StreamLine map = new StreamLine();
                map.nameIDX  = reader.ReadInt32();
                map.lineID   = reader.ReadInt32();
                map.groupID  = reader.ReadInt32();
                map.LoadType = reader.ReadInt32();
                map.flagIDX  = reader.ReadInt32();
                map.Unk5     = reader.ReadInt32();
                map.Unk10    = reader.ReadUInt64();
                map.Unk11    = reader.ReadUInt64();
                map.Unk12    = reader.ReadInt32();
                map.Unk13    = reader.ReadInt32();
                map.Unk14    = reader.ReadInt32();
                map.Unk15    = reader.ReadInt32();
                map.Group    = groupHeaders[map.groupID];
                map.Name     = ReadFromBuffer((long)((ulong)map.nameIDX + (ulong)poolOffset), reader.BaseStream.Position, reader);
                map.Flags    = ReadBufferSpecial((long)((ulong)map.flagIDX + (ulong)poolOffset), reader.BaseStream.Position, reader).TrimEnd('\0').Replace('\0', '|');
                lines[i]     = map;
            }

            if (reader.BaseStream.Position != loadersOffset)
            {
                throw new FormatException();
            }

            loaders = new StreamLoader[numLoaders];

            for (int i = 0; i < numLoaders; i++)
            {
                StreamLoader map = new StreamLoader();
                map.start       = reader.ReadInt32();
                map.end         = reader.ReadInt32();
                map.type        = reader.ReadInt32();
                map.loaderSubID = reader.ReadInt32();
                map.loaderID    = reader.ReadInt32();
                map.LoadType    = reader.ReadInt32();
                map.pathIDX     = reader.ReadInt32();
                map.entityIDX   = reader.ReadInt32();
                map.Path        = ReadFromBuffer((long)((ulong)map.pathIDX + (ulong)poolOffset), reader.BaseStream.Position, reader);
                map.Entity      = ReadBufferSpecial((long)((ulong)map.entityIDX + (ulong)poolOffset), reader.BaseStream.Position, reader).TrimEnd('\0').Replace('\0', '|');
                loaders[i]      = map;
            }

            if (reader.BaseStream.Position != blockOffset)
            {
                throw new FormatException();
            }

            blocks = new StreamBlock[numBlocks];
            for (int i = 0; i < numBlocks; i++)
            {
                StreamBlock map = new StreamBlock();
                map.startOffset = reader.ReadInt32();
                map.endOffset   = reader.ReadInt32();
                blocks[i]       = map;
            }

            if (reader.BaseStream.Position != hashOffset)
            {
                throw new FormatException();
            }

            hashes = new ulong[numHashes];

            for (int i = 0; i < numHashes; i++)
            {
                hashes[i] = reader.ReadUInt64();
            }

            if (reader.BaseStream.Position != poolOffset)
            {
                throw new FormatException();
            }

            reader.BaseStream.Seek(poolSize, SeekOrigin.Current);

            if (reader.BaseStream.Position != reader.BaseStream.Length)
            {
                throw new FormatException("Borked this up");
            }
        }