[okadu] 計測コード
@@ -2,6 +2,7 @@ | ||
2 | 2 | #include "md5.h" |
3 | 3 | #include "RailMap.h" |
4 | 4 | #include "Network.h" |
5 | +#include "CJobTimer.h" | |
5 | 6 | #include "CListView.h" |
6 | 7 | #include "CSimpleDialog.h" |
7 | 8 | #include "CRailWay.h" |
@@ -451,6 +452,7 @@ | ||
451 | 452 | void CSaveFile::RenderScene( |
452 | 453 | int option // 1: renderwarp |
453 | 454 | ){ |
455 | + TIMER_RAII("CSaveFile::RenderScene()"); | |
454 | 456 | InitShadow(); |
455 | 457 | InitRailMap(); |
456 | 458 | CNamedObject::InitAfterRenderList(); |
@@ -459,10 +461,13 @@ | ||
459 | 461 | g_Scene->RenderScene(); |
460 | 462 | devSetState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL); |
461 | 463 | devSetState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL); |
462 | - CTrainGroup *group = m_GroupList; | |
463 | - while(group){ | |
464 | - group->Render(); | |
465 | - group = group->Next(); | |
464 | + { | |
465 | + TIMER_RAII("train group"); | |
466 | + CTrainGroup *group = m_GroupList; | |
467 | + while(group){ | |
468 | + group->Render(); | |
469 | + group = group->Next(); | |
470 | + } | |
466 | 471 | } |
467 | 472 | devSetState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_COLOR1); |
468 | 473 | devSetState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_COLOR1); |
@@ -472,8 +477,11 @@ | ||
472 | 477 | CNamedObject::AfterRenderAll(); |
473 | 478 | devSetState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_COLOR1); |
474 | 479 | devSetState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_COLOR1); |
475 | - CParticle::RenderAll(); | |
476 | - CHeadlight::RenderAll(); | |
480 | + { | |
481 | + TIMER_RAII("effect"); | |
482 | + CParticle::RenderAll(); | |
483 | + CHeadlight::RenderAll(); | |
484 | + } | |
477 | 485 | g_Scene->RenderAfter(); |
478 | 486 | devResetMatrix(); |
479 | 487 | devSetTexture(0, NULL); |
@@ -501,6 +509,7 @@ | ||
501 | 509 | void CSaveFile::Simulate( |
502 | 510 | int num // 回数 |
503 | 511 | ){ |
512 | + TIMER_RAII("CSaveFile::Simulate()"); | |
504 | 513 | int scale = g_SimulationMode->GetTimeScale(); |
505 | 514 | int speed = num<0 ? g_SimulationMode->GetSimSpeed() : num; |
506 | 515 | int i; |
@@ -514,6 +523,7 @@ | ||
514 | 523 | speed = g_SimulationMode->GetOldSpeed(); |
515 | 524 | } |
516 | 525 | for(i = 0; i<speed; i++){ |
526 | + TIMER_RAII("single simulation"); | |
517 | 527 | if(g_NetworkInitialized){ |
518 | 528 | if(exceed) ExceedNetworkSyncLimit(m_NetworkSyncCount); |
519 | 529 | if(m_NetworkSyncCount){ |
@@ -1,7 +1,8 @@ | ||
1 | 1 | #include <time.h> |
2 | 2 | #include <windows.h> |
3 | 3 | |
4 | -LONGLONG g_Freq = 0; | |
4 | +LONGLONG g_HighTimerFreq = 0; | |
5 | +double g_HighTimer_FromCountToMilliseconds = 0.0; | |
5 | 6 | |
6 | 7 | /* |
7 | 8 | * 高分解能タイマの初期化 |
@@ -9,10 +10,12 @@ | ||
9 | 10 | * 戻り値: CPU が対応していれば true を返す |
10 | 11 | */ |
11 | 12 | bool InitHighTimer(){ |
12 | - if(QueryPerformanceFrequency((LARGE_INTEGER *)(&g_Freq))){ | |
13 | + if(QueryPerformanceFrequency((LARGE_INTEGER *)(&g_HighTimerFreq))){ | |
14 | + g_HighTimer_FromCountToMilliseconds = 1000.0/g_HighTimerFreq; | |
13 | 15 | return true; |
14 | 16 | }else{ |
15 | - g_Freq = 0; | |
17 | + g_HighTimerFreq = 0; | |
18 | + g_HighTimer_FromCountToMilliseconds = 1.0; | |
16 | 19 | return false; |
17 | 20 | } |
18 | 21 | } |
@@ -20,14 +23,23 @@ | ||
20 | 23 | /* |
21 | 24 | * 現在時刻の取得 |
22 | 25 | * |
23 | - * 戻り値: ミリ秒 | |
26 | + * 戻り値: 内部カウント値 | |
24 | 27 | */ |
25 | -double HighTimer(){ | |
26 | - if(g_Freq){ | |
28 | +LONGLONG HighTimer(){ | |
29 | + if(g_HighTimerFreq){ | |
27 | 30 | LONGLONG cnt; |
28 | 31 | QueryPerformanceCounter((LARGE_INTEGER *)(&cnt)); |
29 | - return (double)cnt/g_Freq*1000.0; | |
32 | + return cnt; | |
30 | 33 | }else{ |
31 | - return (double)clock(); // 非対応 orz | |
34 | + return clock(); | |
32 | 35 | } |
33 | 36 | } |
37 | + | |
38 | +/* | |
39 | + * ミリ秒に変換 | |
40 | + * | |
41 | + * 戻り値: ミリ秒 | |
42 | + */ | |
43 | +double FromHighTimerCountToMs(LONGLONG t){ | |
44 | + return t*g_HighTimer_FromCountToMilliseconds; | |
45 | +} |
@@ -0,0 +1,87 @@ | ||
1 | +#ifndef CJOBTIMER_H_INCLUDED | |
2 | +#define CJOBTIMER_H_INCLUDED | |
3 | + | |
4 | +#define ENABLE_JOB_TIMER (0) | |
5 | + | |
6 | +class CTimerObj{ | |
7 | +public: | |
8 | + struct CTimerData{ | |
9 | + public: | |
10 | + LONGLONG m_Start; | |
11 | + LONGLONG m_End; | |
12 | + public: | |
13 | + LONGLONG GetDelta() const{ return m_End-m_Start; } | |
14 | + }; | |
15 | + | |
16 | + struct CFrameData{ | |
17 | + public: | |
18 | + vector<CTimerData> m_Data; | |
19 | + LONGLONG m_Total; | |
20 | + public: | |
21 | + CFrameData(): m_Total(0) {} | |
22 | + }; | |
23 | + | |
24 | +private: | |
25 | + CFrameData m_FrameData[2]; | |
26 | + int m_OddFrame; | |
27 | + | |
28 | + string m_Name; | |
29 | + int m_FrameCount; | |
30 | + bool m_IsStarted; | |
31 | + int m_InactiveFrames; | |
32 | +public: | |
33 | + CTimerObj(const char* name); | |
34 | + void InitFrame(); | |
35 | + void Start(); | |
36 | + void Stop(); | |
37 | + void Update(); | |
38 | + | |
39 | + const char* GetName() const{ return m_Name.c_str(); } | |
40 | + void SetName(const char* name){ m_Name = name; } | |
41 | + bool IsStarted() const{ return m_IsStarted; } | |
42 | + int GetInactiveFrames() const{ return m_InactiveFrames; } | |
43 | + const CFrameData& GetFrameData(int flip) const{ return m_FrameData[(m_OddFrame+flip)&1]; } | |
44 | +}; | |
45 | + | |
46 | +class CTimerRAII{ | |
47 | +private: | |
48 | + CTimerObj* m_Obj; | |
49 | +public: | |
50 | + CTimerRAII(CTimerObj* obj): m_Obj(obj) { m_Obj->Start(); } | |
51 | + ~CTimerRAII() { m_Obj->Stop(); } | |
52 | +}; | |
53 | +#if ENABLE_JOB_TIMER | |
54 | +#define TIMER_RAII(name) \ | |
55 | + static CTimerObj _timer_obj_##__LINE__(name); \ | |
56 | + CTimerRAII _timer_raii_##__LINE__(&_timer_obj_##__LINE__) | |
57 | +#else | |
58 | +#define TIMER_RAII(name) | |
59 | +#endif | |
60 | + | |
61 | +class CJobTimer{ | |
62 | +private: | |
63 | + struct CFrameData{ | |
64 | + public: | |
65 | + vector<CTimerObj*> m_ObjList; | |
66 | + LONGLONG m_Start; | |
67 | + LONGLONG m_End; | |
68 | + }; | |
69 | + CFrameData m_FrameData[2]; | |
70 | + int m_OddFrame; | |
71 | + int m_FrameCount; | |
72 | + int m_SpanFrames; | |
73 | + int m_SpanFrameCount; | |
74 | + | |
75 | +public: | |
76 | + CJobTimer(); | |
77 | + int GetFrameCount() const{ return m_FrameCount; } | |
78 | + void Clear(); | |
79 | + void AddObj(CTimerObj*); | |
80 | + void Start(); | |
81 | + void Stop(); | |
82 | + void DrawResult(); | |
83 | +}; | |
84 | + | |
85 | +extern CJobTimer g_JobTimer; | |
86 | + | |
87 | +#endif |
@@ -2,6 +2,7 @@ | ||
2 | 2 | #include "HighTimer.h" |
3 | 3 | #include "Capture.h" |
4 | 4 | #include "RSPV.h" |
5 | +#include "CJobTimer.h" | |
5 | 6 | #include "CScene.h" |
6 | 7 | #include "CSaveFile.h" |
7 | 8 | #include "CToggleIcon.h" |
@@ -64,7 +65,7 @@ | ||
64 | 65 | int g_BlinkCounter = 0; // 汎用点滅カウンタ (0..MAXFPS-1) |
65 | 66 | float g_BlinkAlpha = 0.0f; // 汎用点滅アルファ (0.0..1.0) |
66 | 67 | bool g_RenderBlink = false; // レンダリング点滅フラグ |
67 | -double g_SoundSync = 0.0; // サウンド同期用タイマ | |
68 | +LONGLONG g_SoundSync = 0; // サウンド同期用タイマ | |
68 | 69 | float g_FrameDelta = 0.0f; // フレーム時間 [ms] |
69 | 70 | |
70 | 71 | CNeutralMode *g_NeutralMode; // ニュートラルモード |
@@ -522,6 +523,7 @@ | ||
522 | 523 | void CGameMode::RenderFrame( |
523 | 524 | int option // 1: speedinfo, 2: photomode |
524 | 525 | ){ |
526 | + TIMER_RAII("CGameMode::RenderFrame"); | |
525 | 527 | int i, j, top1, top2, right1, right2; |
526 | 528 | if(g_RSPV && g_RSPV!=RSPV_SKIN) option = 2; |
527 | 529 | if(option&2){ |
@@ -713,29 +715,37 @@ | ||
713 | 715 | * モードループ |
714 | 716 | */ |
715 | 717 | void CGameMode::Spin(){ |
718 | + | |
716 | 719 | SetMasterVolume(); |
717 | 720 | while(PeekAllMessage()){ |
718 | 721 | if(IsActive()){ |
719 | - POINT wp = {0, 0}; | |
720 | - ClientToScreen(svw.hWnd, &wp); | |
721 | - RECT crc = {wp.x, wp.y, wp.x+g_DispWidth, wp.y+g_DispHeight}; | |
722 | - ClipCursor(&crc); | |
723 | - //カーソル描画直前に | |
724 | - //ScanInputDevice(); | |
725 | - //g_Cursor.FixCursor(); | |
726 | - g_BlinkCounter = (g_BlinkCounter+1)%MAXFPS; | |
727 | - g_BlinkAlpha = 0.5f*(sinf(2.0f*D3DX_PI*g_BlinkCounter/MAXFPS)+1.0f); | |
728 | - g_ConfigMode->SetSpecularLight(); | |
729 | - g_ManualControl = !!g_SimulationMode->GetManualControl() || g_NetworkInitialized; | |
730 | - g_IgnoreAcceleration = !!g_SimulationMode->GetIgnoreAcceleration(); | |
731 | - void CheckNetworkState(); | |
732 | - CheckNetworkState(); | |
733 | - SpinGame(); | |
734 | - if(CheckAlt() && GetKey(DIK_F4)==S_PUSH){ | |
735 | - Exit(); | |
736 | - break; | |
722 | + g_JobTimer.Start(); | |
723 | + { | |
724 | + TIMER_RAII("All"); | |
725 | + POINT wp = {0, 0}; | |
726 | + ClientToScreen(svw.hWnd, &wp); | |
727 | + RECT crc = {wp.x, wp.y, wp.x+g_DispWidth, wp.y+g_DispHeight}; | |
728 | + ClipCursor(&crc); | |
729 | + //カーソル描画直前に | |
730 | + //ScanInputDevice(); | |
731 | + //g_Cursor.FixCursor(); | |
732 | + g_BlinkCounter = (g_BlinkCounter+1)%MAXFPS; | |
733 | + g_BlinkAlpha = 0.5f*(sinf(2.0f*D3DX_PI*g_BlinkCounter/MAXFPS)+1.0f); | |
734 | + g_ConfigMode->SetSpecularLight(); | |
735 | + g_ManualControl = !!g_SimulationMode->GetManualControl() || g_NetworkInitialized; | |
736 | + g_IgnoreAcceleration = !!g_SimulationMode->GetIgnoreAcceleration(); | |
737 | + void CheckNetworkState(); | |
738 | + CheckNetworkState(); | |
739 | + SpinGame(); | |
740 | + if(CheckAlt() && GetKey(DIK_F4)==S_PUSH){ | |
741 | + Exit(); | |
742 | + break; | |
743 | + } | |
744 | + if(GetButton(DIM_LEFT)<=S_PULL){ | |
745 | + CDragContainer::EndDrag(); | |
746 | + } | |
737 | 747 | } |
738 | - if(GetButton(DIM_LEFT)<=S_PULL) CDragContainer::EndDrag(); | |
748 | + g_JobTimer.Stop(); | |
739 | 749 | SyncFrame(); |
740 | 750 | }else{ |
741 | 751 | SetMasterVolume(); |
@@ -756,7 +766,7 @@ | ||
756 | 766 | * サウンド定常処理 |
757 | 767 | */ |
758 | 768 | void CGameMode::SpinSound(){ |
759 | - double t = HighTimer(); | |
769 | + LONGLONG t = HighTimer(); | |
760 | 770 | g_FrameDelta = (float)(t-g_SoundSync); |
761 | 771 | g_SoundSync = t; |
762 | 772 | SetListenerPos(GetVPos()); |
@@ -2,6 +2,7 @@ | ||
2 | 2 | #define HIGHTIMER_H_INCLUDED |
3 | 3 | |
4 | 4 | bool InitHighTimer(); |
5 | -double HighTimer(); | |
5 | +LONGLONG HighTimer(); | |
6 | +double FromHighTimerCountToMs(LONGLONG t); | |
6 | 7 | |
7 | 8 | #endif |
@@ -1,4 +1,5 @@ | ||
1 | 1 | #include "stdafx.h" |
2 | +#include "CJobTimer.h" | |
2 | 3 | #include "CRailDetectCurve.h" |
3 | 4 | #include "CRailConnector.h" |
4 | 5 | #include "CPier.h" |
@@ -652,6 +653,7 @@ | ||
652 | 653 | * レンダリング |
653 | 654 | */ |
654 | 655 | void CScene::RenderScene(){ |
656 | + TIMER_RAII("CScene::RenderScene()"); | |
655 | 657 | SetSeason(); |
656 | 658 | SetGlobalAxis(); |
657 | 659 | g_SystemSwitch[SYS_SW_SERIAL].SetValue(m_Serial); |
@@ -668,43 +670,64 @@ | ||
668 | 670 | Render(); |
669 | 671 | devSetState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_COLOR1); |
670 | 672 | devSetState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_COLOR1); |
671 | - g_RailPluginList->RenderAll(); | |
672 | - g_TiePluginList->RenderAll(); | |
673 | - g_GirderPluginList->RenderAll(); | |
674 | - g_PierPluginList->RenderAll(); | |
675 | - g_LinePluginList->RenderAll(); | |
673 | + { | |
674 | + TIMER_RAII("profile RenderAll()"); | |
675 | + g_RailPluginList->RenderAll(); | |
676 | + g_TiePluginList->RenderAll(); | |
677 | + g_GirderPluginList->RenderAll(); | |
678 | + g_PierPluginList->RenderAll(); | |
679 | + g_LinePluginList->RenderAll(); | |
680 | + } | |
676 | 681 | devSetState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL); |
677 | 682 | devSetState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL); |
678 | 683 | devSetLighting(TRUE); |
679 | - CRailWay *way = m_RailWay; | |
680 | - while(way){ | |
681 | - way->Render(); | |
682 | - way = way->Next(); | |
684 | + { | |
685 | + TIMER_RAII("railway"); | |
686 | + CRailWay *way = m_RailWay; | |
687 | + while(way){ | |
688 | + way->Render(); | |
689 | + way = way->Next(); | |
690 | + } | |
683 | 691 | } |
684 | - CPier *pier = m_Pier; | |
685 | - while(pier){ | |
686 | - pier->Render(); | |
687 | - pier = pier->Next(); | |
692 | + { | |
693 | + TIMER_RAII("pier"); | |
694 | + CPier *pier = m_Pier; | |
695 | + while(pier){ | |
696 | + pier->Render(); | |
697 | + pier = pier->Next(); | |
698 | + } | |
688 | 699 | } |
689 | - CLine *line = m_Line; | |
690 | - while(line){ | |
691 | - line->Render(); | |
692 | - line = line->Next(); | |
700 | + { | |
701 | + TIMER_RAII("line"); | |
702 | + CLine *line = m_Line; | |
703 | + while(line){ | |
704 | + line->Render(); | |
705 | + line = line->Next(); | |
706 | + } | |
693 | 707 | } |
694 | - CPole *pole = m_Pole; | |
695 | - while(pole){ | |
696 | - pole->Render(); | |
697 | - pole = pole->Next(); | |
708 | + { | |
709 | + TIMER_RAII("pole"); | |
710 | + CPole *pole = m_Pole; | |
711 | + while(pole){ | |
712 | + pole->Render(); | |
713 | + pole = pole->Next(); | |
714 | + } | |
698 | 715 | } |
699 | - CStation *station = m_Station; | |
700 | - while(station){ | |
701 | - station->Render(); | |
702 | - station = station->Next(); | |
716 | + { | |
717 | + TIMER_RAII("station"); | |
718 | + CStation *station = m_Station; | |
719 | + while(station){ | |
720 | + station->Render(); | |
721 | + station = station->Next(); | |
722 | + } | |
703 | 723 | } |
704 | - CStruct *strct = m_Struct; | |
705 | - while(strct){ | |
706 | - strct->Render(); | |
707 | - strct = strct->Next(); | |
724 | + { | |
725 | + TIMER_RAII("struct"); | |
726 | + CStruct *strct = m_Struct; | |
727 | + while(strct){ | |
728 | + strct->Render(); | |
729 | + strct = strct->Next(); | |
730 | + } | |
708 | 731 | } |
709 | 732 | devSetState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_COLOR1); |
710 | 733 | devSetState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_COLOR1); |
@@ -3,6 +3,7 @@ | ||
3 | 3 | #include "CPixelbit.h" |
4 | 4 | #include "Capture.h" |
5 | 5 | #include "RailMap.h" |
6 | +#include "CJobTimer.h" | |
6 | 7 | #include "CScene.h" |
7 | 8 | #include "CSaveFile.h" |
8 | 9 | #include "CSurfacePlugin.h" |
@@ -105,6 +106,8 @@ | ||
105 | 106 | break; |
106 | 107 | } |
107 | 108 | |
109 | + g_JobTimer.DrawResult(); | |
110 | + | |
108 | 111 | EndScene(); |
109 | 112 | |
110 | 113 | VideoCapture(1|(ms_PhotoMode==2 ? 4 : 0) |
@@ -0,0 +1,157 @@ | ||
1 | +#include "stdafx.h" | |
2 | +#include "HighTimer.h" | |
3 | +#include "CJobTimer.h" | |
4 | + | |
5 | +CJobTimer g_JobTimer; | |
6 | + | |
7 | +//////////////////////////////////////////////////////////////////////////////// | |
8 | +//////////////////////////////////////////////////////////////////////////////// | |
9 | + | |
10 | +CTimerObj::CTimerObj(const char* name) | |
11 | + : m_FrameCount(-1) | |
12 | + , m_IsStarted(false) | |
13 | + , m_InactiveFrames(0) | |
14 | + , m_OddFrame(0) | |
15 | +{ | |
16 | + SetName(name); | |
17 | +} | |
18 | + | |
19 | +void CTimerObj::InitFrame(){ | |
20 | + CFrameData &frame_data = m_FrameData[m_OddFrame]; | |
21 | + if(frame_data.m_Data.size()){ | |
22 | + frame_data.m_Data.clear(); | |
23 | + m_InactiveFrames = 0; | |
24 | + }else{ | |
25 | + ++m_InactiveFrames; | |
26 | + } | |
27 | + frame_data.m_Total = 0; | |
28 | +} | |
29 | + | |
30 | +void CTimerObj::Start(){ | |
31 | + if(m_FrameCount!=g_JobTimer.GetFrameCount()){ | |
32 | + m_FrameCount = g_JobTimer.GetFrameCount(); | |
33 | + InitFrame(); | |
34 | + g_JobTimer.AddObj(this); | |
35 | + } | |
36 | + CFrameData &frame_data = m_FrameData[m_OddFrame]; | |
37 | + if(m_IsStarted) ErrorDialog("CTimerObj::Start() [%s] Already started!", GetName()); | |
38 | + m_IsStarted = true; | |
39 | + frame_data.m_Data.push_back(CTimerData()); | |
40 | + CTimerData &data = frame_data.m_Data.back(); | |
41 | + data.m_Start = data.m_End = HighTimer(); | |
42 | +} | |
43 | + | |
44 | +void CTimerObj::Stop(){ | |
45 | + CFrameData &frame_data = m_FrameData[m_OddFrame]; | |
46 | + if(!m_IsStarted) ErrorDialog("CTimerObj::Stop() [%s] Not started!", GetName()); | |
47 | + CTimerData &data = frame_data.m_Data.back(); | |
48 | + data.m_End = HighTimer(); | |
49 | + frame_data.m_Total += data.GetDelta(); | |
50 | + m_IsStarted = false; | |
51 | +} | |
52 | + | |
53 | +void CTimerObj::Update(){ | |
54 | + if(m_IsStarted) ErrorDialog("CTimerObj::Update() [%s] Already started!", GetName()); | |
55 | + m_OddFrame = !m_OddFrame; | |
56 | +} | |
57 | + | |
58 | +//////////////////////////////////////////////////////////////////////////////// | |
59 | +//////////////////////////////////////////////////////////////////////////////// | |
60 | + | |
61 | +CJobTimer::CJobTimer() | |
62 | + : m_OddFrame(0) | |
63 | + , m_FrameCount(0) | |
64 | + , m_SpanFrames(1) | |
65 | + , m_SpanFrameCount(0) | |
66 | +{ | |
67 | +} | |
68 | + | |
69 | +void CJobTimer::Clear(){ | |
70 | + CFrameData &frame_data = m_FrameData[m_OddFrame]; | |
71 | + frame_data.m_ObjList.clear(); | |
72 | +} | |
73 | + | |
74 | +void CJobTimer::AddObj( | |
75 | + CTimerObj *obj // object | |
76 | +){ | |
77 | + CFrameData &frame_data = m_FrameData[m_OddFrame]; | |
78 | + frame_data.m_ObjList.push_back(obj); | |
79 | +} | |
80 | + | |
81 | +void CJobTimer::Start(){ | |
82 | +#if ENABLE_JOB_TIMER | |
83 | + ++m_FrameCount; | |
84 | + Clear(); | |
85 | + CFrameData &frame_data = m_FrameData[m_OddFrame]; | |
86 | + frame_data.m_Start = frame_data.m_End = HighTimer(); | |
87 | +#endif | |
88 | +} | |
89 | + | |
90 | +void CJobTimer::Stop(){ | |
91 | +#if ENABLE_JOB_TIMER | |
92 | + CFrameData &frame_data = m_FrameData[m_OddFrame]; | |
93 | + frame_data.m_End = HighTimer(); | |
94 | + unsigned int i; | |
95 | + for(i = 0; i<frame_data.m_ObjList.size(); ++i){ | |
96 | + frame_data.m_ObjList[i]->Update(); | |
97 | + } | |
98 | + m_OddFrame = !m_OddFrame; | |
99 | +#endif | |
100 | +} | |
101 | + | |
102 | +void CJobTimer::DrawResult(){ | |
103 | +#if ENABLE_JOB_TIMER | |
104 | + TIMER_RAII("CJobTimer::DrawResult()"); | |
105 | + CFrameData &frame_data = m_FrameData[!m_OddFrame]; | |
106 | + unsigned int i, j; | |
107 | + static const double FRAME_UNIT = 1000.0/MAXFPS; // milliseconds | |
108 | + const double delta = FromHighTimerCountToMs(frame_data.m_End-frame_data.m_Start); | |
109 | + const int span_frames = (int)ceil(delta/FRAME_UNIT); | |
110 | + if(span_frames<m_SpanFrames){ | |
111 | + ++m_SpanFrameCount; | |
112 | + if(m_SpanFrameCount>MAXFPS) m_SpanFrames = span_frames; | |
113 | + }else{ | |
114 | + m_SpanFrames = span_frames; | |
115 | + m_SpanFrameCount = 0; | |
116 | + } | |
117 | + const double rcp_span = 1.0/(FRAME_UNIT*m_SpanFrames); | |
118 | + const int bar_height = FONT_HEIGHT; | |
119 | + const int bar_hilite = 4; | |
120 | + const int area_x = 50; | |
121 | + const int area_y = g_DispHeight-50; | |
122 | + const int area_width = g_DispWidth-200; | |
123 | + const int area_height = bar_height*frame_data.m_ObjList.size(); | |
124 | + int pos_y = area_y; | |
125 | + devResetMatrix(); | |
126 | + devSetLighting(false); | |
127 | + devSetTexture(0, 0); | |
128 | + devBLEND_ALPHA(); | |
129 | + Fill2DRect(area_x, area_y-area_height, area_x+area_width, area_y, 0x80000000); | |
130 | + for(i = 0; i<frame_data.m_ObjList.size(); ++i){ | |
131 | + CTimerObj* obj = frame_data.m_ObjList[i]; | |
132 | + const CTimerObj::CFrameData &obj_frame = obj->GetFrameData(1); | |
133 | + for(j = 0; j<obj_frame.m_Data.size(); ++j){ | |
134 | + const CTimerObj::CTimerData &timer_data = obj_frame.m_Data[j]; | |
135 | + const int bar_start = (int)(FromHighTimerCountToMs(timer_data.m_Start-frame_data.m_Start)*area_width*rcp_span); | |
136 | + int bar_end = (int)(FromHighTimerCountToMs(timer_data.m_End-frame_data.m_Start)*area_width*rcp_span); | |
137 | + if(bar_end==bar_start) bar_end=bar_start+1; | |
138 | + Fill2DRect(area_x+bar_start, pos_y-bar_height, area_x+bar_end, pos_y, MultiplyColor(0xc0ff0000, j&1 ? 0xffc0c0c0 : 0xffffffff)); | |
139 | + Fill2DRect(area_x+bar_start, pos_y-bar_hilite, area_x+bar_end, pos_y, j&1 ? 0x80c0c0c0 : 0x80ffffff); | |
140 | + } | |
141 | + pos_y -= bar_height; | |
142 | + } | |
143 | + Draw2DRect(area_x, area_y-area_height, area_x+area_width, area_y, 0xffffffff); | |
144 | + for(i = 1; i<m_SpanFrames; ++i){ | |
145 | + const int line_x = area_width*i/m_SpanFrames; | |
146 | + Draw2DLine(area_x+line_x, area_y-area_height, area_x+line_x, area_y, 0xffffffff); | |
147 | + } | |
148 | + pos_y = area_y; | |
149 | + for(i = 0; i<frame_data.m_ObjList.size(); ++i){ | |
150 | + CTimerObj* obj = frame_data.m_ObjList[i]; | |
151 | + const CTimerObj::CFrameData &obj_frame = obj->GetFrameData(1); | |
152 | + const double frame_percent = FromHighTimerCountToMs(obj_frame.m_Total)*100.0/FRAME_UNIT; | |
153 | + g_StrTex->RenderLeft(area_x, pos_y-bar_height, 0xffffffff, 0, FlashIn("%7.2lf x%d: %s", frame_percent, obj_frame.m_Data.size(), obj->GetName())); | |
154 | + pos_y -= bar_height; | |
155 | + } | |
156 | +#endif | |
157 | +} |
@@ -1,4 +1,5 @@ | ||
1 | 1 | #include "stdafx.h" |
2 | +#include "CJobTimer.h" | |
2 | 3 | #include "CShadowVolume.h" |
3 | 4 | #include "CScene.h" |
4 | 5 | #include "CEnvPlugin.h" |
@@ -137,6 +138,8 @@ | ||
137 | 138 | CObject *obj, // オブジェクト |
138 | 139 | VEC3 vLight // ライト方向 |
139 | 140 | ){ |
141 | + TIMER_RAII("CShadowVolume::BuildFromMesh()"); | |
142 | + | |
140 | 143 | CMesh *udxMesh = obj->GetMesh(); |
141 | 144 | if(!udxMesh) return; |
142 | 145 | udxMesh->MaskMatFlag(1); |