Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions extensions/community/GpuPreference.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{
"author": "",
"category": "Advanced",
"extensionNamespace": "",
"fullName": "GPU preference",
"gdevelopVersion": "",
"helpPath": "",
"iconUrl": "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiBpZD0ibWRpLWNoaXAiIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNNiw0SDE4VjVIMjFWN0gxOFY5SDIxVjExSDE4VjEzSDIxVjE1SDE4VjE3SDIxVjE5SDE4VjIwSDZWMTlIM1YxN0g2VjE1SDNWMTNINlYxMUgzVjlINlY3SDNWNUg2VjRNMTEsMTVWMThIMTJWMTVIMTFNMTMsMTVWMThIMTRWMTVIMTNNMTUsMTVWMThIMTZWMTVIMTVaIiAvPjwvc3ZnPg==",
"name": "GpuPreference",
"previewIconUrl": "https://asset-resources.gdevelop.io/public-resources/Icons/4c734811321280eae3cb1b80d331a0e83f51626db34f80861a13b78f8bc1f8f6_chip.svg",
"shortDescription": "Sets the active GPU to integrated or dedicated, if these are both available, ensuring the highest FPS for you application.",
"version": "1.0.0",
"description": [
"If you want to ensure that a high-power GPU is used, and you have something like an effect-heavy 3D game, you can give players the ability to choose between which of their video cards is used.",
"",
"For example, the preference \"2\" can either unlock the full power of a user's integrated graphics card, or use the dedicated one if available.",
"If you are sure your app runs on high FPS on integrated graphics, use preference \"1\"."
],
"tags": [],
"authorIds": [],
"dependencies": [],
"globalVariables": [],
"sceneVariables": [],
"eventsFunctions": [
{
"description": "Set the active GPU to either the integrated low power one, the integrated high power one, or the dedicated one.\n\n⚠️ This will relaunch GDevelop, or your app if it's exported.",
"fullName": "Set GPU preference",
"functionType": "Action",
"name": "SetGpuPreference",
"sentence": "Set the active GPU to number _PARAM1_",
"events": [
{
"type": "BuiltinCommonInstructions::JsCode",
"inlineCode": [
"// Ensure we are in a Node.js/Electron environment",
"if (typeof require === 'undefined') return;",
"",
"const runtimeGame = runtimeScene.getGame();",
"const renderer = runtimeGame.getRenderer();",
"let electron = null;",
"let remote = null;",
"",
"// Safely grab Electron and Remote (matching your SystemTrayManager approach)",
"try {",
" electron = renderer.getElectron ? renderer.getElectron() : null;",
" remote = renderer.getElectronRemote ? renderer.getElectronRemote() : null;",
" if (!electron || !remote) {",
" const e = require('electron');",
" electron = e;",
" remote = e.remote || (e.require ? e.require('@electron/remote') : null);",
" }",
"} catch (e) { ",
" return; ",
"}",
"",
"if (!electron || !remote) return;",
"",
"const { app } = remote;",
"const cp = require('child_process');",
"",
"// 1. Get the GPU preference value passed from the GDevelop action parameter",
"// Replace \"GpuPreference\" with whatever you name your parameter in the extension",
"const gpuValue = eventsFunctionContext.getArgument(\"GpuPreference\"); ",
"",
"// 2. Get the exact path to the currently running executable",
"const exePath = app.getPath('exe');",
"",
"// 3. Define the Windows Registry path and values based on your C# logic",
"const regKey = `HKCU\\\\Software\\\\Microsoft\\\\DirectX\\\\UserGpuPreferences`;",
"const regValueName = exePath;",
"const regValueData = `GpuPreference=${gpuValue};`;",
"",
"// 4. Construct the Windows command line 'reg add' instruction",
"// /v: Value Name (The executable path)",
"// /t: Type (String)",
"// /d: Data (GpuPreference=X;)",
"// /f: Force overwrite without prompting the user",
"const command = `reg add \"${regKey}\" /v \"${regValueName}\" /t REG_SZ /d \"${regValueData}\" /f`;",
"",
"// 5. Execute the command to modify the registry invisibly in the background",
"cp.exec(command, (error, stdout, stderr) => {",
" if (error) {",
" console.error(`Error setting GPU registry key: ${error.message}`);",
" return;",
" }",
" ",
" // 6. Relaunch the application and quit the current instance to apply changes",
" app.relaunch();",
" app.quit();",
"});"
],
"parameterObjects": "",
"useStrict": true,
"eventsSheetExpanded": false
}
],
"parameters": [
{
"description": "GPU preference",
"longDescription": "If you want to ensure that a high-power GPU is used, use the preference \"2\". It can either unlock the full power of a user's integrated graphics card, or use the dedicated one if available. This is recommended for 3D applications.\nIf you are sure your app runs on high FPS on integrated graphics, use preference \"1\".",
"name": "GpuPreference",
"supplementaryInformation": "[\"2\",\"1\"]",
"type": "numberWithChoices"
}
],
"objectGroups": []
}
],
"eventsBasedBehaviors": [],
"eventsBasedObjects": []
}