入力レイテンシをテストできる簡単なプログラムを作成しました。
これが意味するのは、コンピューターが画面に送信するものと、それに関連してキーを押すときとの間の遅延です。これは、オンラインの一人称シューティング ゲームのセットアップをテストするためのものです。
このプログラムは、特定のリズムでコンソール ウィンドウを白黒で点滅させ、ユーザーにそのリズムに合わせてスペースバーまたはその他のキーを押すように求めます。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
}