The Runtime module manages the application’s execution lifecycle, thread management, and real-time operation control.
| English Version | 中文版本 |
The Runtime module provides:
The runtime system coordinates all engine components:
Main runtime management and coordination system.
Manages the complete application lifecycle from startup to shutdown.
RuntimeState := {
IsInitialized: false,
IsRunning: false,
IsPaused: false,
IsStopping: false,
StartTime: 0,
UptimeMs: 0,
ThreadCount: 0,
ActiveEngines: []
}
Manages multiple execution threads for parallel processing.
Thread := {
Id: 1,
Name: "MainRotation",
Priority: "Normal",
IntervalMs: 100,
IsRunning: false,
LastRunTime: 0,
ErrorCount: 0,
EngineDependencies: ["RotationEngine", "CastEngine"]
}
Tracks runtime performance metrics.
PerformanceMetrics := {
FPS: 60,
CPUUsage: 15.5,
MemoryUsage: 102.4,
ThreadLatency: [5, 8, 12],
EnginePerformance: {
RotationEngine: 2.1,
CastEngine: 1.8,
BuffEngine: 0.9
}
}
Initializes the runtime system.
Parameters: None
Returns: Boolean indicating success
Starts the main runtime execution.
Parameters: None
Returns: Boolean indicating success
Stops the runtime execution.
Parameters: None
Returns: Boolean indicating success
Pauses the runtime execution.
Parameters: None
Returns: Boolean indicating success
Resumes the runtime execution.
Parameters: None
Returns: Boolean indicating success
Creates a new execution thread.
Parameters:
threadConfig (Map): Thread configurationReturns: Thread ID
Starts a specific thread.
Parameters:
threadId (Integer): Thread identifierReturns: Boolean indicating success
Stops a specific thread.
Parameters:
threadId (Integer): Thread identifierReturns: Boolean indicating success
Gets the state of a specific thread.
Parameters:
threadId (Integer): Thread identifierReturns: Thread state map
Gets current performance metrics.
Parameters: None
Returns: Performance metrics map
Gets performance metrics for a specific engine.
Parameters:
engineName (String): Engine nameReturns: Engine performance metrics
Resets performance metrics.
Parameters: None
Returns: Boolean indicating success
; Initialize runtime system
if (!Runtime_Init()) {
Logger_Error("Runtime", "Failed to initialize runtime system")
ExitApp(1)
}
; Start runtime execution
if (!Runtime_Start()) {
Logger_Error("Runtime", "Failed to start runtime")
ExitApp(1)
}
; Create a rotation thread
rotationThread := {
Id: 1,
Name: "MainRotation",
Priority: "Normal",
IntervalMs: 100,
EngineDependencies: ["RotationEngine", "CastEngine", "BuffEngine"]
}
threadId := Runtime_CreateThread(rotationThread)
; Start the thread
if (Runtime_StartThread(threadId)) {
Logger_Info("Runtime", "Rotation thread started", Map("threadId", threadId))
}
; Handle UI control events
UI_RegisterControl("startButton", "Runtime_Start")
UI_RegisterControl("stopButton", "Runtime_Stop")
UI_RegisterControl("pauseButton", "Runtime_Pause")
UI_RegisterControl("resumeButton", "Runtime_Resume")
; Update UI with runtime status
UI_UpdateStatus("runtimeStatus", Runtime_GetState())
; Performance monitoring thread
monitoringThread := {
Id: 2,
Name: "PerformanceMonitor",
Priority: "Low",
IntervalMs: 1000,
EngineDependencies: []
}
monitorId := Runtime_CreateThread(monitoringThread)
; Monitoring function
Runtime_RegisterThreadFunction(monitorId, Func("MonitorPerformance"))
MonitorPerformance() {
metrics := Runtime_GetPerformanceMetrics()
; Log performance metrics
Logger_Debug("Runtime", "Performance metrics", metrics)
; Update UI with performance data
UI_UpdatePerformance(metrics)
; Check for performance issues
if (metrics["CPUUsage"] > 80) {
Logger_Warning("Runtime", "High CPU usage detected", metrics)
}
}
; Error handling in thread execution
Runtime_RegisterErrorHandler(Func("HandleRuntimeError"))
HandleRuntimeError(errorInfo) {
Logger_Error("Runtime", "Runtime error occurred", errorInfo)
; Attempt recovery based on error type
switch errorInfo["Type"] {
case "ThreadCrash":
; Restart crashed thread
Runtime_RestartThread(errorInfo["ThreadId"])
case "EngineFailure":
; Reinitialize failed engine
Engine_Reinitialize(errorInfo["EngineName"])
case "PerformanceDegradation":
; Adjust thread priorities
Runtime_AdjustThreadPriorities()
}
}
Runtime settings are stored in the main configuration:
App["RuntimeConfig"] := {
ThreadCount: 3,
DefaultInterval: 100,
PerformanceMonitoring: true,
AutoRecovery: true,
MaxErrorCount: 10
}
Thread configurations are part of profile data:
profile["Threads"] := [
{
Name: "RotationThread",
Interval: 100,
Engines: ["Rotation", "Cast", "Buff"]
},
{
Name: "DetectionThread",
Interval: 50,
Engines: ["Pixel", "Timer"]
}
]
The runtime module includes comprehensive error handling:
The module provides a debugging interface for real-time monitoring:
; Enable runtime debugging
Runtime_EnableDebug()
; Get debug information
debugInfo := Runtime_GetDebugInfo()
All runtime activities are logged for troubleshooting: