public static HashDir CreateDir(HashDir parent, string name) { var hashDir = new HashDir(); hashDir.DirId = MathUtil.GetStringHash(name); hashDir.Name = name; hashDir.Childs = SList.Create <HashDir>(1); hashDir.ChildsDirId = SList.Create <int>(1); hashDir.Files = SList.Create <HashFile>(1); hashDir.FilesId = SList.Create <int>(1); hashDir.ParentDir = parent; if (parent != null) { hashDir.ParentDirId = parent.DirId; SList.Add(parent.Childs, hashDir); SList.Add(parent.ChildsDirId, hashDir.DirId); } else { hashDir.ParentDirId = -1; } CacheDirFullPath(hashDir); return(hashDir); }
public static void Initialize() { WindowIds = 0; CurrentlyOpenWindows = SList.Create <Window>(5); DefaultTextState = new WindowState(); DefaultTextState.CanBeClosed = true; DefaultTextState.CanBeMoved = true; DefaultTextState.CanBeResized = true; DefaultImageState = new WindowState(); DefaultImageState.CanBeClosed = true; DefaultImageState.CanBeMoved = true; DefaultImageState.CanBeResized = false; LoopUtil.CallForever(UpdateWindowsScrollBars, UpdateScrollBarsInterval); LoopUtil.CallForever(UpdateImageWindowsBlendFactor, UpdateImageWindowBlendFactor); MaxWindowSize = new Vector2(); Resolution resolution; if (Screen.resolutions.Length > 1) { resolution = Screen.resolutions[Screen.resolutions.Length - 2]; } else { resolution = Screen.resolutions[Screen.resolutions.Length - 1]; } MaxWindowSize.x = resolution.width; MaxWindowSize.y = resolution.height; }
public static HashDevice GetDeviceFromSerializedData(SerializedHashDevice serializedDevice) { var device = new HashDevice(); device.DeviceName = serializedDevice.DeviceName; device.Condition = serializedDevice.Condition; device.IpAddress = serializedDevice.IpAddress; device.AllPrograms = ProgramUtil.GetAllProgramsFromSerializedData(serializedDevice.Programs); device.AllUsers = SList.Create <HashUser>(serializedDevice.Users.Length); for (int i = 0; i < serializedDevice.Users.Length; i++) { var user = GetUserFromSerializedData(serializedDevice.Users[i]); SList.Add(device.AllUsers, user); } var defaultUser = new HashUser(); defaultUser.Username = DEFAULT_USER_NAME; defaultUser.Password = DEFAULT_PASSWORD; SList.Add(device.AllUsers, defaultUser); device.FileSystem = FileSystem.GetFileSystemFromSerializedData(serializedDevice.FileSystem); return(device); }
/// <summary> /// Creates and returns a file from the given serialized data. /// </summary> public static HashFile GetFileFromSerializedData(SerializedHashFile serializedFile) { var file = new HashFile(); file.FileId = serializedFile.FileId; file.Name = serializedFile.Name; file.ParentDirId = serializedFile.ParentDirId; file.Status = serializedFile.Status; file.Password = serializedFile.Password; file.Condition = serializedFile.Condition; file.UserPermission = SList.Create <ClassPair <string, AccessPermission> >(serializedFile.UserPermission.Length); for (int i = 0; i < serializedFile.UserPermission.Length; i++) { var permission = serializedFile.UserPermission[i]; var user = permission.Key; var pair = new ClassPair <string, AccessPermission>(); pair.Key = user.UserName; pair.Value = permission.Value; SList.Add(file.UserPermission, pair); } return(file); }
public static TextTableLine CreateLine( string nameColumnText, string typeColumnText, string statusColumnText, Color color, int textModifiers) { var nameColumnItem = CreateColumn(nameColumnText, .6f, color, textModifiers); var typeColumnItem = CreateColumn(typeColumnText, .2f, color, textModifiers); var statusColumnItem = CreateColumn(statusColumnText, .2f, color, textModifiers); var items = SList.Create <TextTableColumn>(2); SList.Add(items, nameColumnItem); SList.Add(items, typeColumnItem); SList.Add(items, statusColumnItem); var line = new TextTableLine(); line.Items = items; line.ItemsSeparator = string.Empty; line.MaxLineSize = DataHolder.TerminalData.MaxLineWidthInChars; line.MaxLineSizeIsForced = true; line.ItemsSeparator = " | "; line.SeparatorModifier.Color = color; line.SeparatorModifier.Modifiers = TextModifiers.Bold; TextUtil.FormatLineConsideringWeightsAndSize(line); return(line); }
private static Window CreateWindow(WindowState defaultState) { var references = DataHolder.GUIReferences; var windowObj = NGUITools.AddChild(DataHolder.GUIReferences.WindowsParent, references.WindowPrefab); var windowComponent = windowObj.GetComponent <WindowComponent>(); windowComponent.ControlBar.DragObject.contentRect = windowComponent.WindowWidget; windowComponent.ControlBar.DragObject.panelRegion = DataHolder.GUIReferences.MainPanel; var window = new Window(); window.WindowId = WindowIds++; window.SceneWindow = windowComponent; SetWindowState(window, defaultState); windowObj.SetActive(true); SList.Add(CurrentlyOpenWindows, window); windowComponent.Widgets = SList.Create <UIWidget>(3); windowComponent.Panels = SList.Create <UIPanel>(3); Focus(windowComponent); return(window); }
public static void Init() { DebugUtil.Assert(Instance != null, "LoopUtil.Init being called multiple times!"); Instance = new GameObject("LOOP-UTIL").AddComponent <LoopUtil>(); UpdateCallbacks = SList.Create <Action>(5); LateUpdateCallbacks = SList.Create <Action>(3); }
public void Initialize() { DebugUtil.Log("TERMINAL COMPONENT INITIALIZED!", Color.green, DebugUtil.DebugCondition.Info, DebugUtil.LogType.Info); DataHolder.TerminalData = new TerminalData(); DataHolder.TerminalData.CommandCache = SList.Create <string>(50); DataHolder.TerminalData.AvailableCommands = SList.Create <string>(20); DataHolder.TerminalData.BatchEntries = SList.Create <TextBatchEntry>(10); DataHolder.TerminalData.AllEntries = SList.Create <TerminalEntry>(100); TerminalUtil.FocusOnInput(); TerminalUtil.CalculateMaxCharLenght(); }
/// <summary> /// Returns a list of all the programs deserialized from the given serialized data. /// </summary> public static SimpleList <Program> GetAllProgramsFromSerializedData(SerializedProgram[] programs) { var result = SList.Create <Program>(programs.Length); for (int i = 0; i < programs.Length; i++) { var program = GetProgramFromSerializedData(programs[i]); SList.Add(result, program); } return(result); }
/// <summary> /// Returns a list containing all the files of the given dir that are available for use. /// See IsFileAvailable. /// </summary> public static SimpleList <HashFile> GetAvailableFilesFromDir(HashDir dir) { var result = SList.Create <HashFile>(1); for (int i = 0; i < dir.Files.Count; i++) { var file = dir.Files[i]; if (IsFileAvaibale(file)) { SList.Add(result, file); } } return(result); }
public static SimpleList <Program> GetAvailablePrograms(HashDevice device) { var programs = SList.Create <Program>(device.AllPrograms.Count); for (int i = 0; i < device.AllPrograms.Count; i++) { var program = device.AllPrograms[i]; if (IsProgramAvailable(program)) { SList.Add(programs, program); } } return(programs); }
public static SimpleList <HashDir> GetAllAvailableChild(HashDir dir) { var result = SList.Create <HashDir>(dir.Childs.Count); for (int i = 0; i < dir.Childs.Count; i++) { var child = dir.Childs[i]; if (IsDirAvaibale(child)) { SList.Add(result, child); } } return(result); }
/// <summary> /// Creates and returns a dir from the given serialized data. /// </summary> public static HashDir GetDirFromSerializedData(SerializedHashDir serializedDir) { var dir = new HashDir(); dir.DirId = serializedDir.DirId; dir.ParentDirId = serializedDir.ParentDirId; dir.Name = serializedDir.Name; dir.ChildsDirId = SList.FromArray(serializedDir.ChildsDirId); dir.FilesId = SList.FromArray(serializedDir.FilesId); dir.Childs = SList.Create <HashDir>(dir.ChildsDirId.Count); dir.Files = SList.Create <HashFile>(dir.FilesId.Count); return(dir); }
private static HashFile CreateBaseFile(HashDir parent, string name) { var hashFile = new HashFile(); hashFile.Name = GetValidFileName(parent, name); hashFile.FileId = MathUtil.GetStringHash(name); hashFile.UserPermission = SList.Create <ClassPair <string, AccessPermission> >(1); hashFile.Condition = new HashStory.Condition(); hashFile.Condition.MinimalDays = HashStory.MainState.CurrentDay; AddFileToDir(parent, hashFile); return(hashFile); }
public static DeviceData GetDeviceDataFromSerializedData(SerializedHashDevices devices) { var result = new DeviceData(); result.AllDevices = SList.Create <HashDevice>(devices.Devices.Length); for (int i = 0; i < devices.Devices.Length; i++) { var serializedDevice = devices.Devices[i]; var device = GetDeviceFromSerializedData(serializedDevice); SList.Add(result.AllDevices, device); } result.PlayerDevice = InternalFindDeviceByName(result, devices.PlayerDeviceName); result.CurrentUser = FindUserByName(result.PlayerDevice, devices.PlayerUserName); result.CurrentDevice = result.PlayerDevice; return(result); }
/// <summary> /// Calculates and return the full path of the dir. /// </summary> public static string GetDirFullPath(HashDir hashDir) { var dir = hashDir; string path; // Root folder is treated differently if (dir.ParentDirId == -1) { DebugUtil.Assert(dir.Name != PathUtil.PathSeparator, string.Format("THE DIR {0} HAS NO PARENT AND IT'S THE ROOT DIR!", dir.DirId)); path = dir.Name; } else { #if DEB if (dir.ParentDirId == dir.DirId) { DebugUtil.Log(string.Format("THE DIR {0} HAS ITSELF AS PARENT!", dir.DirId), Color.red, DebugUtil.DebugCondition.Always, DebugUtil.LogType.Info); return(null); } #endif var pathStack = SList.Create <string>(5); SList.Clear(pathStack); while (dir.ParentDirId != -1) { SList.Push(pathStack, dir.Name); dir = FindDirById(dir.ParentDirId); } var builder = new StringBuilder(pathStack.Count * 10); while (pathStack.Count > 0) { var last = SList.Pop(pathStack); builder.Append(PathUtil.AddSeparatorToStart(last)); } path = builder.ToString(); // since it's a folder, add slash to the end of it path = PathUtil.AddSeparatorToEnd(path); } return(path); }
/// <summary> /// Returns a list of all unknown arguments. /// An argument is unknown when it's present on the arguments list but not on the knownArguments list. /// </summary> public static SimpleList <Pair <string, string> > GetUnknownArguments(SimpleList <Pair <string, string> > arguments, string[] knownArguments) { var result = SList.Create <Pair <string, string> >(1); if (AreAllArgumentsKnown(arguments, knownArguments)) { return(result); } for (int i = 0; i < arguments.Count; i++) { var arg = arguments[i]; var indexOf = Array.IndexOf(knownArguments, arg.Key); if (indexOf == -1) { SList.Add(result, arg); } } return(result); }
/// <summary> /// Creates a fake hash set with the given capacity. /// This will also create an pool of SetEntry (the internal class used to store elements /// on the array) to reduce garbage generation and improve performance. /// If preWarmPool is true, this will pre-instantiate the elements on the pool. /// If preWarmPool is false, this will only create a SimpleSet of size 'size' and /// pool removed elements from the set for later reuse. /// </summary> public static SimpleSet <TKey> Create <TKey>(int size, bool preWarmPool) { var Set = new SimpleSet <TKey>(); Set.Count = 0; Set.Capacity = GetNextLength(size); Set.Entries = new SetEntry <TKey> [Set.Capacity]; Set.Comparer = EqualityComparer <TKey> .Default; Set.Enumerator = new SimpleSetEnumerator <TKey>(); Set.Enumerator.Set = Set; Set.EntryPool = SList.Create <SetEntry <TKey> >(size); if (preWarmPool) { for (int i = 0; i < size; i++) { Set.EntryPool[i] = new SetEntry <TKey>(); } } return(Set); }
/// <summary> /// Creates a fake hash table with the given capacity. /// This will also create an pool of TableEntry (the internal class used to store elements /// on the array) to reduce garbage generation and improve performance. /// If preWarmPool is true, this will pre-instantiate the elements on the pool. /// If preWarmPool is false, this will only create a SimpleSet of size 'size' and /// pool removed elements from the table for later reuse. /// </summary> public static SimpleTable <TKey, TValue> Create <TKey, TValue>(int size, bool preWarmPool) { var table = new SimpleTable <TKey, TValue>(); table.Count = 0; table.Capacity = GetNextLength(size); table.Entries = new TableEntry <TKey, TValue> [table.Capacity]; table.Comparer = EqualityComparer <TKey> .Default; table.Enumerator = new SimpleTableEnumerator <TKey, TValue>(); table.Enumerator.Table = table; table.EntryPool = SList.Create <TableEntry <TKey, TValue> >(size); if (preWarmPool) { for (int i = 0; i < size; i++) { table.EntryPool[i] = new TableEntry <TKey, TValue>(); } } return(table); }
void TestSimpleList() { var stop = new Stopwatch(); stop.Start(); var list = SList.Create <int>(10); for (int i = 0; i < 1000000; i++) { SList.Add(list, i); } //var list = new List<int>(10); //for (int i = 0; i < 1000000; i++) // list.Add(i); var sum = 0; for (int i = 0; i < 1000000; i++) { sum += list[i]; } stop.Stop(); Debug.Log(stop.ElapsedMilliseconds); }
/// <summary> /// Parses the given command line and returns the arguments form is. /// The command line is expected to be without the command name. /// </summary> public static SimpleList <Pair <string, string> > GetArgumentsFromCommandLine(string commandLineWithoutCommand) { commandLineWithoutCommand = commandLineWithoutCommand.Trim(); var result = SList.Create <Pair <string, string> >(3); var builder = new StringBuilder(commandLineWithoutCommand.Length); var argName = string.Empty; var argValue = string.Empty; const int lookForArgState = 0; const int readArgNameState = 1; const int readArgValueState = 2; int currentState = lookForArgState; // If it don't start with the argument prefix, it means that the parameter has no name, just value if (!commandLineWithoutCommand.StartsWith(ArgumentPrefix.ToString())) { currentState = readArgValueState; } var onQuote = false; var ignoreNextSpecial = false; for (int i = 0; i < commandLineWithoutCommand.Length; i++) { var letter = commandLineWithoutCommand[i]; // Specials var isEmpty = letter == ' ' && !ignoreNextSpecial; var isQuote = letter == '"' && !ignoreNextSpecial; var isBackSlash = letter == '\\' && !ignoreNextSpecial; var isArgPrefix = letter == ArgumentPrefix && !ignoreNextSpecial; ignoreNextSpecial = false; if (isQuote) { onQuote = !onQuote; continue; } else if (isBackSlash) { ignoreNextSpecial = true; continue; } if (onQuote) { ignoreNextSpecial = true; } switch (currentState) { case lookForArgState: if (isArgPrefix) { currentState = readArgNameState; } break; case readArgNameState: // if there's a space after the start of a arg, ignore the space if (isEmpty && builder.Length == 0) { continue; } if (isEmpty) { argName = builder.ToString(); TextUtil.ClearBuilder(builder); currentState = readArgValueState; argValue = string.Empty; } else { builder.Append(letter); } break; case readArgValueState: if (isArgPrefix) { argValue = builder.ToString(); TextUtil.ClearBuilder(builder); var pair = CreateArgPair(argName, argValue); SList.Add(result, pair); argName = string.Empty; argValue = string.Empty; currentState = readArgNameState; } else { builder.Append(letter); } break; } } // Process what might have been left on the command line switch (currentState) { case lookForArgState: argName = string.Empty; argValue = string.Empty; break; case readArgNameState: argName = builder.ToString(); break; case readArgValueState: argValue = builder.ToString(); break; } // We can arguments with empty names but values or with empty values but names if (!(string.IsNullOrEmpty(argName) && string.IsNullOrEmpty(argValue))) { var finalPair = CreateArgPair(argName, argValue); SList.Add(result, finalPair); } return(result); }