1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| #include<string.h> #include<time.h> #include<stdio.h> #include<stdlib.h> #include<windows.h> #include <mmsystem.h> #pragma comment(lib, "WINMM.LIB") #include <iostream> using namespace std;
int main() { void recursur(); //函数声明 int i = 0, caf = 33; char p = 0; FILE *fp; clock_t stime = 0, ftime = 0; char buf[1921] = {}, seat[] = "output\\test(0).txt", ai[10]; //buf是输出的字符串,seat是打开的文件名 printf("-----test art player-----\nPress Enter to play.\nSource:av706from bilibili\n"); getchar(); system("cls"); PlaySound("test.wav", NULL, SND_FILENAME SND_ASYNC); //输入声音 stime = clock(); while (i <= 6568)// { //6568是输出的总帧数,视情况而定 if (i % 30 == 0) { caf = 43; } else { caf = 33; } //设定刷新时间 strcpy(seat, "output\\test("); sprintf(ai, "%d", i); strcat(seat, ai); strcat(seat, ").txt"); //把seat设定成要打开的文件的形式 ftime = clock(); if ((ftime - stime) >= caf) { //简单而言,就是该程序从启动到函数调用占用CPU的时间。这个函数返回从“开启这个程序进程”到“程序中调用clock()函数”时之间的CPU时钟计时单元(clock tick) //如果系统运行的时间还没到下一次运行时要清屏的时间,那if不进入,也就不会清屏,继续while循环 i++; //播放下一帧 fp = fopen(seat, "r"); fread(buf, sizeof(buf), 1, fp); buf[1920] = '\0'; fclose(fp); fprintf(stdout, "%s", buf); fprintf(stdout, "Frame:%d", i); stime += caf; //加一下当前循环的时候运行的时间 recursur(); } } system("cls"); printf("----- art player-----\nThanks for watching!\nMade by Sukuna.\n\n"); printf("Press Enter to Exit.\n"); getchar(); return 0; } void recursur() { HANDLE hout; COORD coord; coord.X = 0; coord.Y = 0; hout = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition(hout, coord); }
|