⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stopwatch.h

📁 robocup源代码2001年清华机器人源代码
💻 H
字号:
/*
    Copyright (C) 2001  Tsinghuaeolus

    Authors : ChenJiang, YaoJinyi, CaiYunpeng, Lishi

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

	If you make any changes or have any comments we would appreciate a 
	message to yjy01@mails.tsinghua.edu.cn.
*/

#ifndef _STOPWATCH
#define _STOPWATCH
#include "types.h"
#include "stdafx.h"
#include "stdio.h"

#define NUMSTOPWATCHS 4

/*For Time Control*/
class Stopwatch{
private:
	_int64 frequency;
	bool newcycle;
	int current_cycle;
	
	LARGE_INTEGER Newmsg_t;
	void QueryTime(TimedDataArray<LARGE_INTEGER, NUMSTOPWATCHS>& t, int cycle);
public:
	TimedDataArray<LARGE_INTEGER, NUMSTOPWATCHS> Cycle_s, PreCycle_s, AI_s, AI_e, 
		Update_s, Notification_t, RecvNotification_t, See_t, Wake_t;
	LARGE_INTEGER Changeview_t;

	Stopwatch();

	void SetCurrentCycle(int cycle){ current_cycle = cycle;}
	void SetNewmsgTime(){ QueryPerformanceCounter(&Newmsg_t);};
	void SetCycleStartTime(int cycle){ Cycle_s.Setdata(Newmsg_t, cycle);}
	void SetNotificationTime(int cycle){ QueryTime(Notification_t, cycle);}
	void RecvNotification(int cycle){ QueryTime(RecvNotification_t, cycle);}
	void RecvNotification(){ RecvNotification(current_cycle);}
	void UpdateStart(int cycle){ QueryTime(Update_s, cycle);}
	void UpdateStart(){ UpdateStart(current_cycle);}
	void AIstart(int cycle){ QueryTime(AI_s, cycle);}
	void AIstart(){ AIstart(current_cycle);}
	void AIexit(int cycle){ QueryTime(AI_e, cycle);}
	void AIexit(){ AIexit(current_cycle);}
	void SetSeeTime(int cycle){ See_t.Setdata(Newmsg_t, cycle);}
	void Wake(int cycle){ QueryTime(Wake_t, cycle);}
	void Wake(){ Wake(current_cycle);}
	void Changeview(){ QueryPerformanceCounter(&Changeview_t);}
	
	float MsBetween(LARGE_INTEGER& t1, LARGE_INTEGER& t2){return float(t2.QuadPart - t1.QuadPart)/frequency * 1000.0f;}

	float GetAIUseTime(int cycle){ return MsBetween(AI_s.Data(cycle), AI_e.Data(cycle));}
	float GetAIUseTime(){ return GetAIUseTime(current_cycle);}
	float GetAIStartTime(int cycle){ return MsBetween(Cycle_s.Data(cycle), AI_s.Data(cycle));}
	float GetAIStartTime(){ return GetAIStartTime(current_cycle);}
	float GetAIEndTime(int cycle){ return MsBetween(Cycle_s.Data(cycle), AI_e.Data(cycle));}
	float GetAIEndTime(){ return GetAIEndTime(current_cycle);}
	float GetUpdateStartTime(int cycle){ return MsBetween(Cycle_s.Data(cycle), Update_s.Data(cycle));}
	float GetUpdateStartTime(){ return GetUpdateStartTime(current_cycle);}
	float LastCycleLength(int cycle){ return MsBetween(Cycle_s.Data(cycle-1), Cycle_s.Data(cycle));}
	float GetNotificationTime(int cycle){ return MsBetween(Cycle_s.Data(cycle), Notification_t.Data(cycle));}
	float GetNotificationTime(){ return GetNotificationTime(current_cycle);}
	float GetSeeTime(int cycle){ return See_t.IsDataKnown(cycle) ? MsBetween(Cycle_s.Data(cycle), See_t.Data(cycle)) : -1;}
	float GetSeeTime(){ return GetSeeTime(current_cycle);}
	float GetWakeTime(int cycle){ return MsBetween(Cycle_s.Data(cycle), Wake_t.Data(cycle));}
	float GetWakeTime(){ return GetWakeTime(current_cycle);}
	float GetWakeTime_AfterNotification(int cycle){return MsBetween(Notification_t.Data(cycle), Wake_t.Data(cycle));}
	float GetWakeTime_AfterNotification(){ return GetWakeTime_AfterNotification(current_cycle);}
	float GetSightWakeTime(int cycle){return MsBetween(RecvNotification_t.Data(cycle), Wake_t.Data(cycle));}
	float GetSightWakeTime(){ return GetSightWakeTime(current_cycle);}
	float GetRecvWakeTime(int cycle){ return MsBetween(Notification_t.Data(cycle), RecvNotification_t.Data(cycle));}
	float GetRecvWakeTime(){ return GetRecvWakeTime(current_cycle);}
	float GetRecvTime(){ return GetRecvTime(current_cycle);}
	float GetRecvTime(int cycle){ return MsBetween(Cycle_s.Data(cycle), RecvNotification_t.Data(cycle));}

	float TimeElapsedThisCycle();
	float TimeElapsedAfterAIStart();

	float SightIntervalBetween(int prevcycle, int nextcycle);
	float Sincechangeview(int sightime){ return MsBetween(Changeview_t, See_t.Data(sightime));}
	float TimeElapsedSight();
	float PredictNextSight();
};
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -