我创建了一个简单的程序,应该能够测试输入延迟。
我的意思是您的计算机发送到屏幕的内容与您按下与其相关的键之间的延迟。这是用于测试在线第一人称射击游戏的设置。
该程序通过以特定节奏黑白闪烁控制台窗口来工作,并要求用户按空格键或该节奏的任何其他键。它使用 getch 来确定何时按下键,并运行使用 OpenMP 与闪烁控制台并行处理 getch 的函数。
这是否可用作基本的免费输入滞后测试,或者如果不是,我应该怎么做才能做到这一点?
//Fdisk's input lag tester
#include <omp.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
#include <conio.h>
using namespace std;
//My global variables. My functions run in parallel so it's easier to use global variables here.
int i=0;
long int outp[11];
long int inpu[11];
//This function takes the input
int inputfunc() {
while(i<11) {
getch(); //Takes the key input
inpu[i]=clock(); //Marks the time the key was pressed
if(inpu[i]-outp[i]>=0 && inpu[i]-outp[i]<5000) //Checks if result is valid
i++; //Moves the program along so it doesn't blink for eternity
}
return 0;
}
//This function causes the screen to change color
int outputfunc() {
while(i<11) {
system("color F0"); //Changes screen to white
outp[i]=clock(); //Marks the time when screen became white
usleep(400000); //Pause a bit here
system("color 0F"); //Make the screen black again
usleep(400000); //Pause again
}
return 0;
}
int main() {
printf("Fdisk's Input Lag Tester\n\nPress any key when the screen flashes WHITE. Let it flash a few times before pressing anything, so you can get used to the rhythm. Using the spacebar is recommended. Be as precise as possible with what you see on screen. A multicore or multithreading processor is required.\n");
system("pause"); //Sorry my coding is bad
system("cls"); //Again
#pragma omp parallel sections //Parallel sections, these run in parallel on a dual core or dual threading machine
{
#pragma omp section
{
outputfunc(); //The output function, changes the screen's color
}
#pragma omp section
{
inputfunc(); //The input functions, waits for keypresses
}
}
long int x;
for(i=0;i<11;i++) {
x=x+(inpu[i]-outp[i]); //Difference between input and output=latency. This adds them up so we can take a mean value.
}
x=x/11; //This takes the mean value
x=x*(1000/CLOCKS_PER_SEC); //I think clock is always set to milliseconds but in case it's not
printf("Your input latency: %ims\n",x); //Gives the input latency to the user
system("pause"); //Pauses the program so it doesn't exit in case not running it from a command line
usleep(10000000); //Prevents someone from mindlessly pressing space to exit
system("pause"); //Another redundancy to prevent accidental quitting
}