internal void UnloadAssets() { files = files .Where(file => GetFileState(file.Key) < LoadedState.Assets) .ToDictionary(file => file.Key, file => file.Value); state = LoadedState.Code; }
public ImageProcessingProgram() { loadedState = new LoadedState(this); unloadedState = new UnloadedState(this); loadingState = new LoadingState(this); paramState = new ParameterEnteringState(this); programState = unloadedState; }
private void LoadHeaer(PipeStream stream) { if (mState == LoadedState.Method) { if (this.Header.Read(stream, mCookies)) { mState = LoadedState.Header; int.TryParse(Header[HeaderType.CONTENT_LENGTH], out mLength); KeepAlive = string.Compare(Header[HeaderType.CONNECTION], "Keep-Alive", true) == 0; } } }
private void LoadHeaer(PipeStream stream) { if (mState == LoadedState.Method) { if (this.Header.Read(stream)) { mState = LoadedState.Header; int.TryParse(Header[Header.CONTENT_LENGTH], out mLength); KeepAlive = Header[Header.CONNECTION] == "keep-alive"; } } }
private void LoadMethod(PipeStream stream) { string line; if (mState == LoadedState.None) { if (stream.TryReadLine(out line)) { string[] values = line.Split(' '); Method = values[0]; Url = values[1]; HttpVersion = values[2]; mState = LoadedState.Method; } } }
private void LoadBody(PipeStream stream) { if (mState == LoadedState.Header) { if (mLength == 0) { mState = LoadedState.Completed; } else { if (stream.Length == mLength) { mState = LoadedState.Completed; } } } }
private void LoadBody(PipeStream stream) { if (mState == LoadedState.Header) { if (mLength == 0) { mState = LoadedState.Completed; } else { object data; if (Serializer.TryDeserialize(stream, mLength, out data)) { mState = LoadedState.Completed; } } } }
/// <summary> /// removes all points from Contained point lists /// </summary> public bool ClearAllPoints() { if (pointsMutex == false) { pointsMutex = true; ContainedPointLists.Clear(); if (State == LoadedState.BUFFERED_IN_RAM) { State = LoadedState.UNLOADED; } pointsMutex = false; return(true); } return(false); }
private void LoadMethod(PipeStream stream) { if (mState == LoadedState.None) { string data; if (!stream.TryReadWith(HeaderTypeFactory.LINE_BYTES, out data)) { return; } HttpParse.AnalyzeRequestLine(data, this); HttpParse.ReadHttpVersionNumber(HttpVersion, mQueryString, this); int len = HttpParse.ReadUrlQueryString(Url, mQueryString, this); if (len > 0) { HttpParse.ReadUrlPathAndExt(Url.AsSpan().Slice(0, len), mQueryString, this, this.Server.ServerConfig); } else { HttpParse.ReadUrlPathAndExt(Url.AsSpan(), mQueryString, this, this.Server.ServerConfig); } RouteMatchResult routeMatchResult = new RouteMatchResult(); if (Server.UrlRewrite.Match(this, ref routeMatchResult, mQueryString)) { this.IsRewrite = true; this.SourceUrl = this.Url; if (Server.EnableLog(EventArgs.LogType.Info)) { Server.BaseServer.Log(EventArgs.LogType.Info, Session, "request rewrite {0} to {1}", Url, routeMatchResult.RewriteUrl); } Url = routeMatchResult.RewriteUrl; if (Server.ServerConfig.UrlIgnoreCase) { BaseUrl = routeMatchResult.RewriteUrlLower; } else { BaseUrl = routeMatchResult.RewriteUrl; } Ext = routeMatchResult.Ext; } mState = LoadedState.Method; } }
private void LoadMethod(PipeStream stream) { if (mState == LoadedState.None) { Span <char> data; if (!stream.ReadLine(out data)) { return; } HttpParse.AnalyzeRequestLine(data, this); HttpParse.ReadHttpVersionNumber(HttpVersion, mQueryString, this); int len = HttpParse.ReadUrlQueryString(Url, mQueryString, this); if (len > 0) { HttpParse.ReadUrlPathAndExt(Url.AsSpan().Slice(0, len), mQueryString, this, this.Server.Options); } else { HttpParse.ReadUrlPathAndExt(Url.AsSpan(), mQueryString, this, this.Server.Options); } //UrlCode = BaseUrl.GetHashCode() << 16 | BaseUrl.Length; RouteMatchResult routeMatchResult = new RouteMatchResult(); if (Server.UrlRewrite.Count > 0 && Server.UrlRewrite.Match(this, ref routeMatchResult, mQueryString)) { this.IsRewrite = true; this.SourceUrl = this.Url; if (Server.EnableLog(EventArgs.LogType.Info)) { Server.BaseServer.Log(EventArgs.LogType.Info, Session, $"HTTP {ID} request rewrite {Url} to {routeMatchResult.RewriteUrl}"); } Url = routeMatchResult.RewriteUrl; if (Server.Options.UrlIgnoreCase) { BaseUrl = routeMatchResult.RewriteUrlLower; } else { BaseUrl = routeMatchResult.RewriteUrl; } Ext = routeMatchResult.Ext; } mState = LoadedState.Method; } }
public LoadedState Load(PipeStream stream) { string line; if (mState == LoadedState.None) { if (stream.TryReadWith(HeaderTypeFactory.LINE_BYTES, out line)) { HttpParse.AnalyzeResponseLine(line, this); mState = LoadedState.Method; } } if (mState == LoadedState.Method) { if (Header.Read(stream, Cookies)) { mState = LoadedState.Header; } } if (mState == LoadedState.Header) { if (string.Compare(Header[HeaderTypeFactory.CONNECTION], "close", true) == 0) { this.KeepAlive = false; } if (string.Compare(Header[HeaderTypeFactory.TRANSFER_ENCODING], "chunked", true) == 0) { Chunked = true; } else { string lenstr = Header[HeaderTypeFactory.CONTENT_LENGTH]; int length = 0; if (lenstr != null) { int.TryParse(lenstr, out length); } Length = length; } mState = LoadedState.Completed; } return(mState); }
private void LoadMethod(PipeStream stream) { string line; if (mState == LoadedState.None) { if (stream.TryReadLine(out line)) { Tuple <string, string, string> result = HttpParse.AnalyzeRequestLine(line); Method = result.Item1; Url = result.Item2; BaseUrl = HttpParse.GetBaseUrl(Url); Ext = HttpParse.GetBaseUrlExt(BaseUrl); HttpVersion = result.Item3; HttpParse.AnalyzeQueryString(Url, mQueryString); mState = LoadedState.Method; } } }
private void LoadHeaer(PipeStream stream) { if (mState == LoadedState.Method) { if (this.Header.Read(stream, mCookies)) { mState = LoadedState.Header; string length = Header[HeaderTypeFactory.CONTENT_LENGTH]; if (length != null) { int.TryParse(length, out mLength); } if (VersionNumber == "1.0") { string connection = Header[HeaderTypeFactory.CONNECTION]; KeepAlive = string.Compare(connection, "keep-alive", true) == 0; } RouteMatchResult routeMatchResult; this.IsRewrite = false; if (Server.UrlRewrite.Count > 0 && Server.UrlRewrite.Match(this, out routeMatchResult, mQueryString)) { var url = routeMatchResult.RewriteUrl; if (Server.Options.AgentRewrite) { if (mQueryStringIndex > 0 && this.Url.Length > mQueryStringIndex + 1) { if (routeMatchResult.HasQueryString) { url += "&"; } else { url += "?"; } url += new string(Url.AsSpan().Slice(mQueryStringIndex + 1)); } } UrlRewriteTo(url); } } } }
private void LoadHeaer(PipeStream stream) { if (mState == LoadedState.Method) { if (this.Header.Read(stream, mCookies)) { mState = LoadedState.Header; string length = Header[HeaderTypeFactory.CONTENT_LENGTH]; if (length != null) { int.TryParse(length, out mLength); } if (VersionNumber == "1.0") { string connection = Header[HeaderTypeFactory.CONNECTION]; KeepAlive = string.Compare(connection, "keep-alive", true) == 0; } } } }
private void LoadMethod(PipeStream stream) { if (mState == LoadedState.None) { IndexOfResult index = stream.IndexOf(HeaderType.LINE_BYTES); if (index.End != null) { ReadOnlySpan <Char> line = HttpParse.ReadCharLine(index); stream.ReadFree(index.Length); Tuple <string, string, string> result = HttpParse.AnalyzeRequestLine(line); Method = result.Item1; Url = result.Item2; BaseUrl = HttpParse.GetBaseUrlToLower(Url); Ext = HttpParse.GetBaseUrlExt(BaseUrl); HttpVersion = result.Item3; HttpParse.AnalyzeQueryString(Url, mQueryString); mState = LoadedState.Method; } } }
internal void SetInvisibleAndUnbuffered() { visible = false; if (ClearAllPoints()) { numberOfLoadedPoints = 0; if (serverBufferId != null) { VBOUtils.DeleteFromGPU(serverBufferId); serverBufferId = null; if (parentVBOs.Count > 0) { ParentNode.RemoveVBO(parentVBOs); } } State = LoadedState.UNLOADED; } }
private void LoadMethod(PipeStream stream) { if (mState == LoadedState.None) { Span <char> data; if (!stream.ReadLine(out data)) { return; } PathLevel = 0; HttpParse.AnalyzeRequestLine(data, this); HttpParse.ReadHttpVersionNumber(HttpVersion, mQueryString, this); mQueryStringIndex = HttpParse.ReadUrlQueryString(Url, mQueryString, this); if (mQueryStringIndex > 0) { HttpParse.ReadUrlPathAndExt(Url.AsSpan().Slice(0, mQueryStringIndex), mQueryString, this, this.Server.Options); } else { HttpParse.ReadUrlPathAndExt(Url.AsSpan(), mQueryString, this, this.Server.Options); } mState = LoadedState.Method; } }
internal void Read(LoadedState desiredState, ReadStreamingAsset streamingHandler = null) { if (desiredState <= state) { return; } using (var fileStream = File.OpenRead(path)) using (var hReader = new BinaryReader(fileStream)) { if (Encoding.ASCII.GetString(hReader.ReadBytes(4)) != "TMOD") { throw new Exception("Magic Header != \"TMOD\""); } tModLoaderVersion = new Version(hReader.ReadString()); hash = hReader.ReadBytes(20); signature = hReader.ReadBytes(256); //currently unused, included to read the entire data-blob as a byte-array without decompressing or waiting to hit end of stream int datalen = hReader.ReadInt32(); if (state < LoadedState.Integrity) { long pos = fileStream.Position; var verifyHash = SHA1.Create().ComputeHash(fileStream); if (!verifyHash.SequenceEqual(hash)) { throw new Exception("Hash mismatch, data blob has been modified or corrupted"); } state = LoadedState.Integrity; if (desiredState == LoadedState.Integrity) { return; } fileStream.Position = pos; } bool filesAreLoadOrdered = tModLoaderVersion >= new Version(0, 10, 1, 2); using (var deflateStream = new DeflateStream(fileStream, CompressionMode.Decompress)) using (var reader = new BinaryReader(deflateStream)) { name = reader.ReadString(); version = new Version(reader.ReadString()); int count = reader.ReadInt32(); for (int i = 0; i < count; i++) { string fileName = reader.ReadString(); LoadedState fileState = GetFileState(fileName); if (filesAreLoadOrdered && fileState > desiredState) { break; } int len = reader.ReadInt32(); if (fileState == LoadedState.Streaming && desiredState >= LoadedState.Streaming) { var end = deflateStream.TotalOut + len; streamingHandler(fileName, len, reader); if (deflateStream.TotalOut < end) { reader.ReadBytes((int)(end - deflateStream.TotalOut)); } else if (deflateStream.TotalOut > end) { throw new IOException( $"Read too many bytes ({deflateStream.Position - end - len}>{len}) while loading streaming asset: {fileName}"); } } else { byte[] content = reader.ReadBytes(len); if (fileState > state && fileState <= desiredState) { AddFile(fileName, content); } } } } } if (desiredState >= LoadedState.Info && !HasFile("Info")) { throw new Exception("Missing Info file"); } if (desiredState >= LoadedState.Code && !HasFile("All.dll") && !(HasFile("Windows.dll") && HasFile("Mono.dll"))) { throw new Exception("Missing All.dll or Windows.dll and Mono.dll"); } state = desiredState; if (state > LoadedState.Assets) { state = LoadedState.Assets; } }
protected unsafe void LoadIntoVBO() { if (serverBufferId != null) { throw new ApplicationException("should not occur"); } if (parentVBOs == null) { parentVBOs = new Stack <VBOStorageInformation>(); } QTreeWrapper parentTree = LasDataManager.GetInstance().GetQtreeByGuid(ParentTreeID); #region Create vertex arrays //form three arrays to copy to server memory ColorPalette pallette = LasDataManager.ColorPallette; //code that reduces given points //how many points to skip when loading int step = (int)Math.Ceiling((1.0 / ReductionToParentCoef)); //be conservative int allLevels = parentTree.qtree.NumberOfTreeLevels; int pointsOnLevel = NumberOfPoints / allLevels; int pointsOnLastLevel = pointsOnLevel + NumberOfPoints - pointsOnLevel * allLevels; if (pointsOnLevel < 5) { //no need to overburden the system with separate arrays for very small amounts of points allLevels = 1; pointsOnLastLevel = NumberOfPoints; } float[][] interleavedArrayAtLevel = new float[allLevels][]; int interleavedDataStride = VBOUtils.PointInformationSize; int byteStride = interleavedDataStride / 4; for (int i = 0; i < allLevels; i++) { if (i == (allLevels - 1)) { //last(leaf) level also contains all remaining points interleavedArrayAtLevel[i] = new float[pointsOnLastLevel * byteStride]; //10 is for 3*V,3*N and 4*C bytes } else if (pointsOnLevel > 0) { interleavedArrayAtLevel[i] = new float[pointsOnLevel * byteStride]; } } int currentLevel = 0; //we will iterate mod allLevels so the points are distributed fairly int pointIndex = 0; //point index inside an array for a level. increased only when we return to locating points to the frst level int numAllocatedPoints = 0; //counts total number of allcoated point int lastPointsThreshold = NumberOfPoints - pointsOnLastLevel + pointsOnLevel; //threshold which determines from where on points are only on the last level //generate points for all levels in one iteration over all the points for (int j = 0; j < ContainedPointLists.Count; j++) { Point3D[] pts = ContainedPointLists[j]; int len = pts.Length; for (int k = 0; k < len; k++) { Point3D p = pts[k]; //C4 GetColorFromPalette(interleavedArrayAtLevel[currentLevel], pallette, pointIndex, p); interleavedArrayAtLevel[currentLevel][pointIndex + 3] = 1; //N3 interleavedArrayAtLevel[currentLevel][pointIndex + 4] = p.nx; interleavedArrayAtLevel[currentLevel][pointIndex + 5] = p.nz; interleavedArrayAtLevel[currentLevel][pointIndex + 6] = p.ny; //V3 interleavedArrayAtLevel[currentLevel][pointIndex + 7] = p.x + parentTree.positionOffset.x; interleavedArrayAtLevel[currentLevel][pointIndex + 8] = p.z; interleavedArrayAtLevel[currentLevel][pointIndex + 9] = p.y + parentTree.positionOffset.y; numAllocatedPoints++; //increased for every point if (numAllocatedPoints < lastPointsThreshold) { currentLevel++; if (currentLevel == allLevels) { //increase point index only when going back to the first level pointIndex += byteStride; //3 values for vertices, 3 for colors and 3 for normals currentLevel = 0; } } else { currentLevel = allLevels - 1; pointIndex += byteStride; //point index is always updated, because we only insert points to the last layer now } } } #endregion //only if points wil bedistributed between nodes propagate them up the hierarchy if (allLevels > 1) { //load all arrays into VBOStorageInformation objects and pass them along to parents Stack <VBOStorageInformation> vbosForParents = new Stack <VBOStorageInformation>(allLevels - 1); //for parents parentVBOs.Clear(); for (int i = 0; i < allLevels - 1; i++) { VBOStorageInformation vbos = VBOUtils.GenerateVBOs(pointsOnLevel); VBOUtils.CopyPointsToVBOs(interleavedArrayAtLevel[i], vbos); //insert into stack so parents can take them out vbosForParents.Push(vbos); parentVBOs.Push(vbos); } ParentNode.AddVBO(vbosForParents); } //load also into this leafs VBO serverBufferId = VBOUtils.GenerateVBOs(pointsOnLastLevel); VBOUtils.CopyPointsToVBOs(interleavedArrayAtLevel[allLevels - 1], serverBufferId); ClearAllPoints(); State = LoadedState.BUFFERED_IN_GPU; }
private void LoadMethod(PipeStream stream) { if (mState == LoadedState.None) { Span <char> data; if (!stream.ReadLine(out data)) { return; } HttpParse.AnalyzeRequestLine(data, this); HttpParse.ReadHttpVersionNumber(HttpVersion, mQueryString, this); int len = HttpParse.ReadUrlQueryString(Url, mQueryString, this); if (len > 0) { HttpParse.ReadUrlPathAndExt(Url.AsSpan().Slice(0, len), mQueryString, this, this.Server.Options); } else { HttpParse.ReadUrlPathAndExt(Url.AsSpan(), mQueryString, this, this.Server.Options); } RouteMatchResult routeMatchResult = new RouteMatchResult(); this.IsRewrite = false; if (Server.UrlRewrite.Count > 0 && Server.UrlRewrite.Match(this, ref routeMatchResult, mQueryString)) { this.IsRewrite = true; this.SourceUrl = Url; this.SourceBaseUrl = BaseUrl; this.SourcePath = Path; if (Server.Options.UrlIgnoreCase) { Url = routeMatchResult.RewriteUrlLower; } else { Url = routeMatchResult.RewriteUrl; } if (Server.Options.AgentRewrite) { if (len > 0 && this.SourceUrl.Length > len + 1) { if (Url.IndexOf('?') > 0) { Url += "&"; } else { Url += "?"; } Url += new string(SourceUrl.AsSpan().Slice(len + 1)); } } len = HttpParse.ReadUrlQueryString(Url, null, this); if (len > 0) { HttpParse.ReadUrlPathAndExt(Url.AsSpan().Slice(0, len), mQueryString, this, this.Server.Options); } else { HttpParse.ReadUrlPathAndExt(Url.AsSpan(), mQueryString, this, this.Server.Options); } if (Server.EnableLog(EventArgs.LogType.Info)) { Server.BaseServer.Log(EventArgs.LogType.Info, Session, $"HTTP {ID} {((IPEndPoint)Session.RemoteEndPoint).Address} request {SourceUrl} rewrite to {Url}"); } } mState = LoadedState.Method; } }
// 转场景 path = "map/xinkaijie.unity" private void _ChangeScene(string pathName, bool bAsync, UnityAction <string> aLoaded = null, UnityAction <string> aUnLoaded = null) { //Debug.Log("_ChangeScene: " + pathName + " | " + bAsync); if (string.IsNullOrEmpty(pathName)) { return; } string sSceneName = pathName.Substring(pathName.LastIndexOf("/") + 1); sSceneName = sSceneName.Substring(0, sSceneName.LastIndexOf(".")); if (ms_sLoadingSceneName == sSceneName || (!string.IsNullOrEmpty(ms_sLoadingSceneName))) { string sSameWarn = "_ChangeScene Load Same Scene:"; string sLoading = "_ChangeScene LastScene is Loading:"; Debug.LogWarning((ms_sLoadingSceneName == sSceneName ? sSameWarn : sLoading) + ms_sLoadingSceneName); return; } //AsyncOperation op = null; UnityAction <string, AssetBundle> aComplete = (path, ab) => { ms_aOnUnloadedScene = (oScene) => { if (aUnLoaded != null) { aUnLoaded(oScene.name); } }; /*ms_aOnActiveScene = (oSceneA, oSceneB) => * { * //SceneManager.UnloadSceneAsync(oSceneB.name); * };*/ ms_aOnLoadedScene = (oScene, eMode) => { ResourceMgr.UnLoadSceneAB(ab); if (aLoaded != null) { aLoaded(oScene.name.Equals("Empty") ? ms_sLoadingSceneName : oScene.name); } }; //LoadSceneAsync Loads the scene asynchronously in the background. //LoadScene, the loading does not happen immediately, it completes in the next frame if (bAsync) { m_eLoadSate = LoadedState.Async; //m_oLoadAsync = Application.LoadLevelAsync(ms_sLoadingSceneName); m_oLoadAsync = SceneManager.LoadSceneAsync(ms_sLoadingSceneName, LoadSceneMode.Single); GameMgr.Instance.StartCoroutine(StartLoadingAsync()); } else { m_eLoadSate = LoadedState.Sync; //Application.LoadLevel(sSceneName); SceneManager.LoadScene(sSceneName, LoadSceneMode.Single); } }; m_oLoadAsync = null; m_eLoadSate = LoadedState.None; ms_sLoadingSceneName = sSceneName; ResourceMgr.LoadSceneAB(pathName, aComplete, true); }