### Add GET and POST Web Requests Source: https://deepwiki.com/EllanJiang/GameFramework/6-network-and-io Demonstrates how to add GET and POST requests using the WebRequestManager. It shows how to initiate a GET request to a specified URL and a POST request with data. It also covers subscribing to success and failure events for handling responses. ```csharp // Add a GET request int requestId = webRequestManager.AddWebRequest("https://example.com/api/data"); // Add a POST request with data byte[] postData = Encoding.UTF8.GetBytes("key=value"); int requestId = webRequestManager.AddWebRequest("https://example.com/api/submit", postData); // Handle response through events webRequestManager.WebRequestSuccess += OnWebRequestSuccess; webRequestManager.WebRequestFailure += OnWebRequestFailure; ``` -------------------------------- ### GameFrameworkEntry: Register and Get Modules (C#) Source: https://deepwiki.com/EllanJiang/GameFramework/2-core-framework Demonstrates how to retrieve module instances using the GameFrameworkEntry. The system uses reflection to map interface requests to concrete implementations, automatically creating modules on demand. This ensures a clean dependency resolution system. ```csharp IResourceManager resourceManager = GameFrameworkEntry.GetModule(); ``` -------------------------------- ### Monitor Download Progress Events - C# Source: https://deepwiki.com/EllanJiang/GameFramework/6 Subscribes to download events to monitor the progress and status of download tasks. This involves registering event handlers for download start, update, success, and failure. These events provide feedback on the download lifecycle, allowing for progress visualization and error handling. ```csharp downloadManager.DownloadStart += OnDownloadStart; downloadManager.DownloadUpdate += OnDownloadUpdate; downloadManager.DownloadSuccess += OnDownloadSuccess; downloadManager.DownloadFailure += OnDownloadFailure; ``` -------------------------------- ### Create a Poolable Class Implementing IReference in C# Source: https://deepwiki.com/EllanJiang/GameFramework/2 Demonstrates how to create a custom class that can be used with the Reference Pool by implementing the `IReference` interface. This involves defining a `Create` factory method and overriding the `Clear` method to reset the object's state. The example shows an `EventArgs` class that uses `ReferencePool.Acquire` internally. ```csharp public class MyCustomEventArgs : GameFrameworkEventArgs { private int m_Value; public int Value { get { return m_Value; } } public static MyCustomEventArgs Create(int value) { MyCustomEventArgs eventArgs = ReferencePool.Acquire(); eventArgs.m_Value = value; return eventArgs; } public override void Clear() { m_Value = 0; } } ``` -------------------------------- ### Organize Graphics and Audio Settings with Data Nodes Source: https://deepwiki.com/EllanJiang/GameFramework/5 Illustrates how to organize and store various game settings, such as graphics resolution and fullscreen mode, as well as audio volumes. This pattern helps in maintaining a structured configuration system. ```csharp // Setting up graphics settings dataNodeManager.SetData("Settings/Graphics/Resolution", new VarString("1920x1080")); dataNodeManager.SetData("Settings/Graphics/Fullscreen", new VarBoolean(true)); // Setting up audio settings dataNodeManager.SetData("Settings/Audio/MasterVolume", new VarFloat(0.8f)); dataNodeManager.SetData("Settings/Audio/MusicVolume", new VarFloat(0.5f)); ``` -------------------------------- ### Download Agent Helper Interface (C#) Source: https://deepwiki.com/EllanJiang/GameFramework/6 Defines the contract for platform-specific download implementations. Concrete classes implement this interface to handle network operations for data download. It includes methods for initiating downloads and resetting the helper, and defines events for update notifications, completion, and errors. ```csharp public interface IDownloadAgentHelper { event Framework_Game_Download_IDownloadAgentHelper_UpdateBytes UpdateBytesEvent; event Framework_Game_Download_IDownloadAgentHelper_UpdateLength UpdateLengthEvent; event Framework_Game_Download_IDownloadAgentHelper_Complete CompleteEvent; event Framework_Game_Download_IDownloadAgentHelper_Error ErrorEvent; void Download(string downloadPath, string downloadUri, string wwwOperation, float timeout, float priority, object userData); void Download(string downloadPath, string downloadUri, float timeout, float priority, object userData); void Reset(); } ``` -------------------------------- ### File System Manager API Source: https://deepwiki.com/EllanJiang/GameFramework/3 Operations related to managing file systems, including creation and loading. ```APIDOC ## POST /FileSystem/Create ### Description Creates a new file system with specified parameters. ### Method POST ### Endpoint /FileSystem/Create ### Parameters #### Query Parameters - **fullPath** (string) - Required - The full path to the file system. - **accessMode** (FileSystemAccessMode) - Required - The access mode for the file system (e.g., Read, ReadWrite). - **maxFileCount** (int) - Required - The maximum number of files allowed in the file system. - **maxBlockCount** (int) - Required - The maximum number of blocks allowed in the file system. ### Request Example ```json { "fullPath": "/data/my_filesystem.dat", "accessMode": "ReadWrite", "maxFileCount": 1024, "maxBlockCount": 4096 } ``` ### Response #### Success Response (200) - **success** (bool) - Indicates if the file system was created successfully. #### Response Example ```json { "success": true } ``` ## POST /FileSystem/Load ### Description Loads an existing file system from a specified path. ### Method POST ### Endpoint /FileSystem/Load ### Parameters #### Query Parameters - **fullPath** (string) - Required - The full path to the file system. - **accessMode** (FileSystemAccessMode) - Required - The access mode for loading the file system. ### Request Example ```json { "fullPath": "/data/my_filesystem.dat", "accessMode": "Read" } ``` ### Response #### Success Response (200) - **success** (bool) - Indicates if the file system was loaded successfully. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### Download Manager Methods (C#) Source: https://deepwiki.com/EllanJiang/GameFramework/6 Provides methods for managing download tasks within the Download Manager. These include retrieving download information by serial ID, tag, or all tasks, and removing tasks individually, by tag, or all at once. ```csharp public DownloadInfo GetDownloadInfo(int serialId) { return null; } public DownloadInfo[] GetDownloadInfos(string tag) { return null; } public DownloadInfo[] GetAllDownloadInfos() { return null; } public void RemoveDownload(int serialId) { } public void RemoveDownloads(string tag) { } public void RemoveAllDownloads() { } ``` -------------------------------- ### Open UI Form - C# Source: https://deepwiki.com/EllanJiang/GameFramework/4 Shows how to open a UI form using the UIManager. It covers basic usage by specifying the form name and group, as well as advanced usage with priority, pausing covered forms, and user data. ```csharp // Basic usage - open a UI form in a specific group int serialId = uiManager.OpenUIForm("MainMenu", "MainMenuGroup"); // Advanced usage - open with priority and pause covered forms int serialId = uiManager.OpenUIForm("SettingsPanel", "PopupGroup", 100, true, userData); ``` -------------------------------- ### Typical Reference Pool Usage Flow in C# Source: https://deepwiki.com/EllanJiang/GameFramework/2 Illustrates the standard lifecycle of using an object with the Reference Pool. It shows how to acquire an object using `ReferencePool.Acquire()` or a factory method, use it, and then release it back to the pool. Proper release is crucial for the pooling mechanism to function effectively and prevent memory leaks. ```csharp // Direct acquisition MyCustomEventArgs args = ReferencePool.Acquire(); // Or through factory method MyCustomEventArgs args = MyCustomEventArgs.Create(42); ``` ```csharp ReferencePool.Release(args); ``` -------------------------------- ### Object Pool Configuration Parameters Source: https://deepwiki.com/EllanJiang/GameFramework/7 Defines key parameters for configuring object pools, including identifiers, spawning behavior, auto-release intervals, capacity, expiration times, and priority. These settings influence how objects are managed, released, and prioritized within the pool. ```C# public class ObjectPool { public string Name { get; } // Identifier for the pool public bool AllowMultiSpawn { get; set; } // Whether objects can be spawned multiple times public float AutoReleaseInterval { get; set; } // Time interval for auto-release public int Capacity { get; set; } // Maximum number of objects in the pool public float ExpireTime { get; set; } // Time after which unused objects expire public int Priority { get; set; } // Pool priority for memory freeing // ... other methods and properties } ``` -------------------------------- ### Add Download Agent Helper - C# Source: https://deepwiki.com/EllanJiang/GameFramework/6 Increases concurrent download capacity by adding a download agent helper to the download manager. This requires creating a platform-specific implementation of IDownloadAgentHelper. Tuning the number of download agents is crucial for optimizing performance based on the target platform's capabilities and network conditions. ```csharp // Create platform-specific download agent helper IDownloadAgentHelper downloadAgentHelper = new MyDownloadAgentHelper(); // Add to download manager downloadManager.AddDownloadAgentHelper(downloadAgentHelper); ``` -------------------------------- ### Refocus UI Form - C# Source: https://deepwiki.com/EllanJiang/GameFramework/4 Demonstrates how to refocus a UI form using the UIManager. This action brings the specified UI form to the front of its respective group, ensuring it is rendered on top. ```csharp // Bring a UI form to the front of its group uiManager.RefocusUIForm(uiForm); ``` -------------------------------- ### Add Download Task - C# Source: https://deepwiki.com/EllanJiang/GameFramework/6 Adds a new download task to the Download Manager. This method can be called with basic parameters or with additional optional parameters for customization. The downloadUri specifies the remote file location, and downloadPath specifies the local destination. Optional parameters include a tag for identification, priority for task ordering, and custom user data. ```csharp int downloadId = downloadManager.AddDownload( downloadPath: "Assets/Downloads/example.zip", downloadUri: "https://example.com/files/example.zip" ); int downloadId = downloadManager.AddDownload( downloadPath: "Assets/Downloads/example.zip", downloadUri: "https://example.com/files/example.zip", tag: "AssetUpdates", priority: 100, userData: myCustomData ); ``` -------------------------------- ### Download Counter Class (C#) Source: https://deepwiki.com/EllanJiang/GameFramework/6 Calculates download speed by tracking data throughput over time using a sliding window approach. It maintains a recent history of download rates for accurate speed calculation. Key properties include update interval, record interval, and current speed. ```csharp internal sealed class DownloadCounter { private class DownloadCounterNode { public float m_TotalSpeed; public float m_Time; } private LinkedList m_Nodes; private float m_UpdateInterval; private float m_RecordInterval; private float m_TotalSpeed; private float m_CurrentSpeed; public DownloadCounter() { m_Nodes = new LinkedList(); m_UpdateInterval = 0.5f; m_RecordInterval = 5f; m_TotalSpeed = 0f; m_CurrentSpeed = 0f; } public void Update(int length) { float time = Time.gettime(); m_TotalSpeed += length; LinkedListNode first = m_Nodes.First; while (first != null && time - first.Value.m_Time > m_RecordInterval) { m_TotalSpeed -= first.Value.m_TotalSpeed; m_Nodes.RemoveFirst(); first = m_Nodes.First; } DownloadCounterNode value = default(DownloadCounterNode); value.m_TotalSpeed = length; value.m_Time = time; m_Nodes.AddLast(value); if (time - m_Nodes.First.Value.m_Time >= m_UpdateInterval) { m_CurrentSpeed = m_TotalSpeed / m_RecordInterval; } } public float CurrentSpeed { get { return m_CurrentSpeed; } } } ``` -------------------------------- ### Resource Management Pool Integration Source: https://deepwiki.com/EllanJiang/GameFramework/7 Highlights the use of object pools within the Resource Management system. It mentions `AssetPool` for managing loaded assets with dependencies and `ResourcePool` for shared resource objects, demonstrating how pooling improves asset and resource lifecycle management. ```C# // Conceptual representation within GameFramework's Resource Management system // ... public class AssetPool : ObjectPool // Inherits from ObjectPool { // Manages loaded assets with dependency tracking } public class ResourcePool : ObjectPool // Inherits from ObjectPool { // Manages resource objects that may be shared by multiple assets } // When a resource/asset is loaded, it's registered with the appropriate pool. // When no longer needed, it's unspawned and eventually released if not used again. // ... ``` -------------------------------- ### ReferencePool: Object Pooling and Reuse (C#) Source: https://deepwiki.com/EllanJiang/GameFramework/2-core-framework Illustrates the usage of the ReferencePool for efficient object pooling. Objects must implement IReference, which provides a Clear() method for state reset. This system reduces garbage collection pressure by reusing objects. ```csharp // Example usage pattern MyEventArgs eventArgs = ReferencePool.Acquire(); // Use the object... ReferencePool.Release(eventArgs); // Clear() is automatically called ``` -------------------------------- ### File Operations API Source: https://deepwiki.com/EllanJiang/GameFramework/3 APIs for reading, writing, and performing additional operations on files within the file system. ```APIDOC ## File Reading Operations ### Description Provides methods to read files from the file system, either completely or in segments. ### Methods - **ReadFile**(string filePath) - **ReadFile**(string filePath, byte[] buffer) - **ReadFile**(string filePath, Stream stream) - **ReadFileSegment**(string filePath, int offset, int length, byte[] buffer) - **ReadFileSegment**(string filePath, int offset, int length, Stream stream) ### Parameters - **filePath** (string) - The path to the file within the file system. - **offset** (int) - The starting offset for reading a file segment. - **length** (int) - The length of the data to read for a file segment. - **buffer** (byte[]) - The buffer to read the file content into. - **stream** (Stream) - The stream to read the file content into. ### Request Example (ReadFile into byte array) ```csharp byte[] fileContent = fileSystem.ReadFile("/path/to/my/file.txt"); ``` ### Response (for ReadFile) - **byte[]** - The content of the file as a byte array. - **void** - If reading into a buffer or stream. ## File Writing Operations ### Description Provides methods to write data to files in the file system from various sources. ### Methods - **WriteFile**(string filePath, byte[] buffer) - **WriteFile**(string filePath, Stream stream) - **WriteFile**(string filePath, string physicalPath) ### Parameters - **filePath** (string) - The path to the file within the file system. - **buffer** (byte[]) - The byte array containing the data to write. - **stream** (Stream) - The stream providing the data to write. - **physicalPath** (string) - The path to the physical file to write from. ### Request Example (WriteFile from byte array) ```csharp byte[] dataToWrite = System.Text.Encoding.UTF8.GetBytes("Hello, World!"); fileSystem.WriteFile("/path/to/new/file.txt", dataToWrite); ``` ### Response - **void** ## Additional File Operations ### Description Utility operations for managing files within the file system. ### Methods - **SaveAsFile**(string filePath, string physicalPath) - **RenameFile**(string oldPath, string newPath) - **DeleteFile**(string filePath) ### Parameters - **filePath** (string) - The path to the file within the file system. - **physicalPath** (string) - The path to the physical file. - **oldPath** (string) - The current path of the file. - **newPath** (string) - The new path for the file. ### Request Example (DeleteFile) ```csharp fileSystem.DeleteFile("/path/to/obsolete/file.txt"); ``` ### Response - **void** ``` -------------------------------- ### Store and Retrieve Player Health using Data Nodes Source: https://deepwiki.com/EllanJiang/GameFramework/5 Demonstrates how to store and retrieve player health data using the DataNodeManager. It involves setting an integer value for health and then retrieving it. This is useful for managing player-specific statistics. ```csharp // Storing player health dataNodeManager.SetData("Player/Stats/Health", new VarInt(100)); // Retrieving player health VarInt health = dataNodeManager.GetData("Player/Stats/Health"); int healthValue = health.Value; // 100 ``` -------------------------------- ### Manual Object Release Methods Source: https://deepwiki.com/EllanJiang/GameFramework/7 Provides methods for manually releasing objects from the pool. These include releasing objects to match pool capacity, releasing a specific number of objects, and releasing all currently unused objects. ```C# // Inside ObjectPoolManager.ObjectPool.cs // ... public void Release() { // Releases objects to reduce the pool to its capacity } public void Release(int count) { // Releases up to the specified number of objects } public void ReleaseAllUnused() { // Releases all objects that are not currently in use } // ... ``` -------------------------------- ### FSM System Pool Integration Source: https://deepwiki.com/EllanJiang/GameFramework/7 Explains how the Finite State Machine (FSM) system utilizes object pooling for efficient state machine management. FSM objects are acquired from and released back to the reference pool, with the `FsmManager` overseeing their creation and destruction. ```C# // Conceptual representation within GameFramework's FSM system // ... public class FsmManager { // Manages creation and destruction of state machines using object pooling public void CreateFsm(...) { // Acquire FSM object from the reference pool // ... } public void DestroyFsm(IFsm fsm) { // Release FSM object back to the reference pool // ... } } // ... ```