主题
降低目标进程CPU占用 - DownCpu
函数简介
绑定窗口后调用。开启后窗口刷新会变慢,这是功能本身而不是故障。
display="dx"。type=1 必须已绑定 DX 图色且没有 dx.public.down.cpu。
接口名称
DownCpuDLL调用
c
int32_t DownCpu(int64_t instance, int32_t type, int32_t rate);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| type | 整数型 | 降 CPU 方式,详见下表。 |
| rate | 整数型 | type=0 时为每次延迟毫秒;type=1 时为目标 FPS;0 关闭。 |
type 降 CPU 方式
| 值 | 说明 |
|---|---|
0 | 图色路径额外延迟(rate 为毫秒)。若绑定带 dx.public.down.cpu,则改为消息循环无消息时 Sleep,此时图色降 CPU 失效。 |
1 | 把窗口 Present 锁到目标帧率(rate 为 FPS)。只卡住画面刷新;点击/滚轮/键盘会结束等待,纯移动不打断限帧。不可与 dx.public.down.cpu 同时使用。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
// 须先 BindWindow / BindWindowEx,且 display="dx"
int ret = ola.DownCpu(1, 30); // 限帧 30 FPS
if (ret == 1) {
// 操作成功;窗口刷新变慢是功能本身
}csharp
using OLAPlug;
var ola = new OLAPlugServer();
// 须先 BindWindow / BindWindowEx,且 display="dx"
int ret = ola.DownCpu(1, 30); // 限帧 30 FPS
if (ret == 1)
{
// 操作成功;窗口刷新变慢是功能本身
}python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
# 须先 BindWindow / BindWindowEx,且 display="dx"
ret = ola.DownCpu(1, 30) # 限帧 30 FPS
if ret == 1:
pass # 操作成功;窗口刷新变慢是功能本身java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
// 须先 BindWindow / BindWindowEx,且 display="dx"
int ret = ola.DownCpu(1, 30); // 限帧 30 FPS
if (ret == 1) {
// 操作成功;窗口刷新变慢是功能本身
}go
import "github.com/ola/olaplug/olaplug"
ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
// 须先 BindWindow / BindWindowEx,且 display="dx"
ret := ola.DownCpu(1, 30) // 限帧 30 FPS
if ret == 1 {
// 操作成功;窗口刷新变慢是功能本身
}rust
use olaplug::OLAPlugServer;
let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
// 须先 BindWindow / BindWindowEx,且 display="dx"
let ret = ola.down_cpu(1, 30); // 限帧 30 FPS
if ret == 1 {
// 操作成功;窗口刷新变慢是功能本身
}cpp
var ola = com("OlaPlug.OlaSoft")
// 须先 BindWindow / BindWindowEx,且 display="dx"
var ret = ola.DownCpu(1, 30) // 限帧 30 FPS
if(ret == 1) {
// 操作成功;窗口刷新变慢是功能本身
}vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
' 须先 BindWindow / BindWindowEx,且 display="dx"
ret = ola.DownCpu(1, 30)
If ret = 1 Then
' 操作成功;窗口刷新变慢是功能本身
End Iftext
.局部变量 ola, OLAPlug
ola.创建 ()
' 须先 BindWindow / BindWindowEx,且 display="dx"
ret = ola.DownCpu(1, 30)
.如果真 (ret = 1)
' 操作成功;窗口刷新变慢是功能本身
.如果真结束aardio
import OLAPlugServer;
var ola = OLAPlugServer();
// 须先 BindWindow / BindWindowEx,且 display="dx"
var ret = ola.DownCpu(1, 30); // 限帧 30 FPS
if(ret == 1){
// 操作成功;窗口刷新变慢是功能本身
}text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
' 须先 BindWindow / BindWindowEx,且 display="dx"
整数 ret = ola.DownCpu(1, 30)
如果真 (ret = 1)
{
// 操作成功;窗口刷新变慢是功能本身
}cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
// 须先 BindWindow / BindWindowEx,且 display="dx"
int32_t ret = ola.DownCpu(1, 30); // 限帧 30 FPS
if (ret == 1) {
// 操作成功;窗口刷新变慢是功能本身
}原生 DLL 调用
cpp
DownCpu(instance, 1, 30);csharp
using System.Runtime.InteropServices;
using System.Text;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int DownCpu(long ola, int type, int rate);
DownCpu(instance, 1, 30);python
from ctypes import CDLL, c_int, c_int64, create_string_buffer
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
ola.DownCpu(instance, 1, 30)返回值
| 返回值 | 说明 |
|---|---|
1 | 成功。 |
0 | 失败:未绑定、type 非法、rate < 0、type=1 带了 dx.public.down.cpu、或当前不是 DX 图色。 |
注意事项
| 项目 | 说明 |
|---|---|
| 调用时机 | 绑定窗口后调用。 |
| 刷新变慢 | 开启后窗口刷新会变慢,这是功能本身而不是故障。 |
| display | 须为 "dx"。type=1 必须已绑定 DX 图色且没有 dx.public.down.cpu。 |
| type=0 与 dx.public.down.cpu | 绑定带 dx.public.down.cpu 时,type=0 改为消息循环无消息时 Sleep,图色路径降 CPU 失效。 |
| type=1 限帧行为 | 只卡住画面刷新;点击/滚轮/键盘会结束等待,纯移动不打断限帧。 |
| 关闭 | rate=0 关闭降 CPU。 |
| 绑定参数 | dx.public.down.cpu 见 BindWindowEx 的 public 参数。 |
