さっそくですが質問があるので書きたいと思います
・質問
以下のコード(一部)を実行すると
文字列を描画しなかった場合->fps60となり処理落ちしない
文字列を描画した場合->fps15~30となり処理落ちする
#include "DxLib.h"
#include <locale.h>
#define FLAME 60
int fps_count,count0t;
int f[FLAME];
double ave;
int loadcount = 0;
int graph = 0;
int white = GetColor(255,255,255);
int brack = GetColor(0,0,0);
#define FL_WINDOW_HEIGHT 600
#define FL_WINDOW_WIDTH 800
void fr_DWB()
{
DrawBox(0,0,FL_WINDOW_WIDTH,FL_WINDOW_HEIGHT,white,TRUE);
}
void fr_DBB()
{
DrawBox(0,0,FL_WINDOW_WIDTH,FL_WINDOW_HEIGHT,brack,TRUE);
}
void fps_wait(){
int term,i,gnt;
static int t=0;
if(fps_count==0){//60フレームの1回目なら
if(t==0)//完全に最初ならまたない
term=0;
else//前回記録した時間を元に計算
term=count0t+1000-GetNowCount();
}
else //待つべき時間=現在あるべき時刻-現在の時刻
term = (int)(count0t+fps_count*(1000.0/FLAME))-GetNowCount();
if(term>0)//待つべき時間だけ待つ
Sleep(term);
gnt=GetNowCount();
if(fps_count==0)//60フレームに1度基準を作る
count0t=gnt;
f[fps_count]=gnt-t;//1周した時間を記録
t=gnt;
//平均計算
if(fps_count==FLAME-1){
ave=0;
for(i=0;i<FLAME;i++)
ave+=f[i];
ave/=FLAME;
}
fps_count = (++fps_count)%FLAME ;
}
void draw_fps(int x, int y,COLORREF color)
{
if(ave!=0)
{
DrawFormatString(x, y,color,"[%.1f]",1000/ave);
}
return;
}
void DGC_FO(char* pass)
{
int x=0,y=0,xx=0;
int frame = 1;
int fr = 0;
if(loadcount == 0)
{
loadcount = 1;
graph = LoadGraph(pass);
}
GetGraphSize(graph,&x,&y);
if(timecount >= 64)
{
timecount = 0;
}
else
{
SetDrawBlendMode(DX_BLENDMODE_ALPHA,256-(timecount*4));
SetDrawBright(256-(timecount*4),256-(timecount*4),256-(timecount*4));
DrawGraph(0,0,graph,TRUE);
SetDrawBlendMode(DX_BLENDMODE_NOBLEND,255);
SetDrawBright(256,256,256);
timecount+=TIME_WAIT;
}
if(timecount >= 64)
{
timecount = 0;
}
}
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow )
{
ChangeWindowMode(TRUE);// ウィンドウモードに設定
SetGraphMode(FL_WINDOW_WIDTH,FL_WINDOW_HEIGHT,32);
if( DxLib_Init() == -1 ) // DXライブラリ初期化処理
{
return -1 ; // エラーが起きたら直ちに終了
}
SetDrawScreen( DX_SCREEN_BACK );
int MX,MY;
while( 1 )
{
if(ProcessMessage()!=0)
{ // メッセージ処理
break;//ウィンドウの×ボタンが押されたらループを抜ける
}
fps_wait();
ClearDrawScreen(); // 画面を消す
switch(main_mode)
GetMousePoint(&MX,&MY);
fr_DWB();
DGC_FO();
//ここから
DrawFormatString(10,490,brack,"Unco1Unco2unco3Unco4Unco5Unco6Unco7Unco8Unco9Unco10Unco11unco12Unco13Unco14Unco15Unco16");
DrawFormatString(10,510,brack,"Unco2");
DrawFormatString(10,530,brack,"Unco3");
DrawFormatString(10,550,brack,"Unco4");
DrawFormatString(10,570,brack,"Unco5");
//ここまで
DrawFormatString(0,20,brack,"[%d %d]",MX,MY);
draw_fps(0,0,brack);
ScreenFlip(); //裏画面を表画面に反映
}
DxLib_End() ; // DXライブラリ使用の終了処理
return 0 ; // ソフトの終了
}