• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ common::Timer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中common::Timer的典型用法代码示例。如果您正苦于以下问题:C++ Timer类的具体用法?C++ Timer怎么用?C++ Timer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Timer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: onNewImage

void CvSIFT::onNewImage() {
	LOG(LTRACE)<< "CvSIFT::onNewImage\n";
	try {
		// Input: a grayscale image.
		cv::Mat input = in_img.read();
		std::ofstream feature_calc_time;

		if(!string(prop_calc_path).empty()) {
			feature_calc_time.open((string(prop_calc_path)+string("czas_wyznaczenia_cech_sift.txt")).c_str(), ios::out|ios::app);
		}
		Common::Timer timer;

		timer.restart();
		//-- Step 1: Detect the keypoints.
		cv::SiftFeatureDetector detector(0,4);
		std::vector<cv::KeyPoint> keypoints;
		detector.detect(input, keypoints);

		//-- Step 2: Calculate descriptors (feature vectors).
		cv::SiftDescriptorExtractor extractor;
		Mat descriptors;
		extractor.compute( input, keypoints, descriptors);

		if(!string(prop_calc_path).empty()) {
			feature_calc_time << timer.elapsed() << endl;
		}
		// Write results to outputs.
		Types::Features features(keypoints);
		features.type = "SIFT";
		out_features.write(features);
		out_descriptors.write(descriptors);
	} catch (...) {
		LOG(LERROR) << "CvSIFT::onNewImage failed\n";
	}
}
开发者ID:mlepicka,项目名称:DCL_CvBasic,代码行数:35,代码来源:CvSIFT.cpp


示例2: VideoThrottle

// Apply Frame Limit and Display FPS info
// This should only be called from VI
void VideoThrottle()
{
	u32 TargetVPS = (SConfig::GetInstance().m_Framelimit > 2) ?
		(SConfig::GetInstance().m_Framelimit - 1) * 5 : VideoInterface::TargetRefreshRate;

	// Disable the frame-limiter when the throttle (Tab) key is held down. Audio throttle: m_Framelimit = 2
	if (SConfig::GetInstance().m_Framelimit && SConfig::GetInstance().m_Framelimit != 2 && !Host_GetKeyState('\t'))
	{
		u32 frametime = ((SConfig::GetInstance().b_UseFPS)? Common::AtomicLoad(DrawnFrame) : DrawnVideo) * 1000 / TargetVPS;

		u32 timeDifference = (u32)Timer.GetTimeDifference();
		if (timeDifference < frametime) {
			Common::SleepCurrentThread(frametime - timeDifference - 1);
		}

		while ((u32)Timer.GetTimeDifference() < frametime)
			Common::YieldCPU();
			//Common::SleepCurrentThread(1);
	}

	// Update info per second
	u32 ElapseTime = (u32)Timer.GetTimeDifference();
	if ((ElapseTime >= 1000 && DrawnVideo > 0) || g_requestRefreshInfo)
	{
		UpdateTitle();

		// Reset counter
		Timer.Update();
		Common::AtomicStore(DrawnFrame, 0);
		DrawnVideo = 0;
	}

	DrawnVideo++;
}
开发者ID:Everscent,项目名称:dolphin-emu,代码行数:36,代码来源:Core.cpp


示例3: BVHTest

void BVHTest()
{
    Common::Timer timer;

    Random rand = Random(1);

#define NUM_INSERTIONS 100000
    Box* pBoxes = (Box*)_aligned_malloc(NUM_INSERTIONS * sizeof(Box), 16);
    for (int i = 0; i < NUM_INSERTIONS; i++)
    {
        Vector pos = rand.GetFloat3();
        pos *= 100.0f;
        pBoxes[i] = Box(pos - Vector(0.5f, 0.5f, 0.5), pos + Vector(0.5f, 0.5f, 0.5));
    }


    Util::BVH bvh;
    timer.Start();
    for (int i = 0; i < NUM_INSERTIONS; i++)
    {
        bvh.Insert(pBoxes[i], (void*)i);
    }
    double buildTime = timer.Stop();

    Box testBox = Box(Vector(50, 50, 50), Vector(60, 60, 60));

    //__asm int 3;
}
开发者ID:nfprojects,项目名称:nfengine,代码行数:28,代码来源:test.cpp


示例4: WriteStatus

// Write to the status bar
void WriteStatus()
{
	std::string TmpStr = "Time: " + ReRecTimer.GetTimeElapsedFormatted();
	TmpStr += StringFromFormat("  Frame: %s", ThousandSeparate(g_FrameCounter).c_str());
	// The FPS is the total average since the game was booted
	TmpStr += StringFromFormat("  FPS: %i", (g_FrameCounter * 1000) / ReRecTimer.GetTimeElapsed());
	TmpStr += StringFromFormat("  FrameStep: %s", g_FrameStep ? "On" : "Off");
	Host_UpdateStatusBar(TmpStr.c_str(), 1);	
}
开发者ID:madnessw,项目名称:thesnow,代码行数:10,代码来源:CoreRerecording.cpp


示例5: onNewImage

void BlobExtractor_Processor::onNewImage() {
	LOG(LTRACE) << "BlobExtractor_Processor::onNewImage() called!\n";

	Common::Timer timer;
	timer.restart();

	cv::Mat in = in_img.read();
	in.convertTo(img_uchar, CV_8UC1);
	IplImage ipl_img = IplImage(img_uchar);
//  cv::Mat mat_img = img_uchar;
//	cv::Mat out = cv::Mat::zeros(in.size(), CV_8UC3);

	Types::Blobs::Blob_vector res;
	bool success;

	try
	{
		success = ComponentLabeling( &ipl_img, NULL, props.bkg_color, res );
	}
	catch(...)
	{
		success = false;
		LOG(LWARNING) << "blob find error\n";
	}

		try {
		if( !success ) {
			LOG(LERROR) << "Blob find error\n";
		} else {
			LOG(LTRACE) << "blobs found";
			Types::Blobs::BlobResult result(res);

			result.Filter( result, B_EXCLUDE, Types::Blobs::BlobGetArea(), B_LESS, min_size );

			out_blobs.write(result);
			LOG(LTRACE) << "blobs written";
			newBlobs->raise();
			LOG(LTRACE) << "blobs sent";
		//	result.draw(out, CV_RGB(255, 0, 0), 0, 0);
		//	out_img.write(in);
		//	newImage->raise();
		}

		LOG(LINFO) << "Blobing took " << timer.elapsed() << " seconds\n";
	}
	catch(...)
	{
		LOG(LERROR) << "BlobExtractor onNewImage failure";
	}
}
开发者ID:Sapphire1,项目名称:DCL_CvBlobs,代码行数:50,代码来源:BlobExtractor_Processor.cpp


示例6: VideoThrottle

// Apply Frame Limit and Display FPS info
// This should only be called from VI
void VideoThrottle()
{
	// Update info per second
	u32 ElapseTime = (u32)Timer.GetTimeDifference();
	if ((ElapseTime >= 1000 && DrawnVideo > 0) || g_requestRefreshInfo)
	{
		UpdateTitle();

		// Reset counter
		Timer.Update();
		Common::AtomicStore(DrawnFrame, 0);
		DrawnVideo = 0;
	}

	DrawnVideo++;
}
开发者ID:DigidragonZX,项目名称:dolphin,代码行数:18,代码来源:Core.cpp


示例7: RerecordingStart

// Start the timer when a game is booted
void RerecordingStart()
{
	g_FrameCounter = 0;
	ReRecTimer.Start();

	// Logging
	//DEBUG_LOG(CONSOLE, "RerecordingStart: %i\n", g_FrameCounter);
}
开发者ID:madnessw,项目名称:thesnow,代码行数:9,代码来源:CoreRerecording.cpp


示例8: RerecordingStop

// Reset the frame counter
void RerecordingStop()
{
	// Write the final time and Stop the timer
	ReRecTimer.Stop();

	// Update status bar
	WriteStatus();
}
开发者ID:madnessw,项目名称:thesnow,代码行数:9,代码来源:CoreRerecording.cpp


示例9: UpdateTitle

void UpdateTitle()
{
	u32 ElapseTime = (u32)s_timer.GetTimeDifference();
	s_request_refresh_info = false;
	SConfig& _CoreParameter = SConfig::GetInstance();

	if (ElapseTime == 0)
		ElapseTime = 1;

	float FPS   = (float)(s_drawn_frame.load() * 1000.0 / ElapseTime);
	float VPS   = (float)(s_drawn_video.load() * 1000.0 / ElapseTime);
	float Speed = (float)(s_drawn_video.load() * (100 * 1000.0) / (VideoInterface::GetTargetRefreshRate() * ElapseTime));

	// Settings are shown the same for both extended and summary info
	std::string SSettings = StringFromFormat("%s %s | %s | %s", cpu_core_base->GetName(), _CoreParameter.bCPUThread ? "DC" : "SC",
		g_video_backend->GetDisplayName().c_str(), _CoreParameter.bDSPHLE ? "HLE" : "LLE");

	std::string SFPS;

	if (Movie::IsPlayingInput())
		SFPS = StringFromFormat("VI: %u/%u - Input: %u/%u - FPS: %.0f - VPS: %.0f - %.0f%%", (u32)Movie::g_currentFrame, (u32)Movie::g_totalFrames, (u32)Movie::g_currentInputCount, (u32)Movie::g_totalInputCount, FPS, VPS, Speed);
	else if (Movie::IsRecordingInput())
		SFPS = StringFromFormat("VI: %u - Input: %u - FPS: %.0f - VPS: %.0f - %.0f%%", (u32)Movie::g_currentFrame, (u32)Movie::g_currentInputCount, FPS, VPS, Speed);
	else
	{
		SFPS = StringFromFormat("FPS: %.0f - VPS: %.0f - %.0f%%", FPS, VPS, Speed);
		if (SConfig::GetInstance().m_InterfaceExtendedFPSInfo)
		{
			// Use extended or summary information. The summary information does not print the ticks data,
			// that's more of a debugging interest, it can always be optional of course if someone is interested.
			static u64 ticks = 0;
			static u64 idleTicks = 0;
			u64 newTicks = CoreTiming::GetTicks();
			u64 newIdleTicks = CoreTiming::GetIdleTicks();

			u64 diff = (newTicks - ticks) / 1000000;
			u64 idleDiff = (newIdleTicks - idleTicks) / 1000000;

			ticks = newTicks;
			idleTicks = newIdleTicks;

			float TicksPercentage = (float)diff / (float)(SystemTimers::GetTicksPerSecond() / 1000000) * 100;

			SFPS += StringFromFormat(" | CPU: %s%i MHz [Real: %i + IdleSkip: %i] / %i MHz (%s%3.0f%%)",
					_CoreParameter.bSkipIdle ? "~" : "",
					(int)(diff),
					(int)(diff - idleDiff),
					(int)(idleDiff),
					SystemTimers::GetTicksPerSecond() / 1000000,
					_CoreParameter.bSkipIdle ? "~" : "",
					TicksPercentage);
		}
	}
	// This is our final "frame counter" string
	std::string SMessage = StringFromFormat("%s | %s", SSettings.c_str(), SFPS.c_str());
	Host_UpdateTitle(SMessage);
}
开发者ID:KoolWolff,项目名称:Ishiiruka,代码行数:57,代码来源:Core.cpp


示例10: WindBack

/* Wind back the frame counter when a save state is loaded. Currently we don't know what that means in
   time so we just guess that the time is proportional the the number of frames
   
   Todo: There are many assumptions here: We probably want to replace the time here by the actual time
   that we save together with the save state or the input recording for example. And have it adjusted
   for full speed playback (whether it's 30 fps or 60 fps or some other speed that the game is natively
   capped at). Also the input interrupts do not occur as often as the frame renderings, they occur more
   often. So we may want to move the input recording to fram updates, or perhaps sync the input interrupts
   to frame updates.
   */
void WindBack(int Counter)
{
	/* Counter should be smaller than g_FrameCounter, however it currently updates faster than the
	   frames so currently it may not be the same. Therefore I use the abs() function. */
	int AbsoluteFrameDifference = abs(g_FrameCounter - Counter);
	float FractionalFrameDifference = (float) AbsoluteFrameDifference / (float) g_FrameCounter;

	// Update the frame counter
	g_FrameCounter = Counter;

	// Approximate a time to wind back the clock to
	// Get the current time
	u64 CurrentTimeMs = ReRecTimer.GetTimeElapsed();
	// Save the current time in seconds in a new double
	double CurrentTimeSeconds = (double) (CurrentTimeMs / 1000);
	// Reduce it by the same proportion as the counter was wound back
	CurrentTimeSeconds = CurrentTimeSeconds * FractionalFrameDifference;
	// Update the clock
	ReRecTimer.WindBackStartingTime((u64)CurrentTimeSeconds * 1000);

	// Logging
	DEBUG_LOG(CONSOLE, "WindBack: %i %u\n", Counter, (u64)CurrentTimeSeconds);
}
开发者ID:madnessw,项目名称:thesnow,代码行数:33,代码来源:CoreRerecording.cpp


示例11: mainThread

void UDPWiimote::mainThread()
{
	std::unique_lock<std::mutex> lk(d->termLock);

	Common::Timer time;
	fd_set fds;
	struct timeval timeout;
	timeout.tv_sec=0;
	timeout.tv_usec=0;
	time.Update();
	do
	{
		int maxfd=0;
		FD_ZERO(&fds);
		for (auto& fd : d->sockfds)
		{
			FD_SET(fd,&fds);
#ifndef _WIN32
			if (fd>=maxfd)
				maxfd=(fd)+1;
#endif
		}

		u64 tleft=timeout.tv_sec*1000+timeout.tv_usec/1000;
		u64 telapsed=time.GetTimeDifference();
		time.Update();
		if (tleft<=telapsed)
		{
			timeout.tv_sec=1;
			timeout.tv_usec=500000;
			broadcastPresence();
		}
		else
		{
			tleft-=telapsed;
			timeout.tv_sec=(long)(tleft/1000);
			timeout.tv_usec=(tleft%1000)*1000;
		}

		lk.unlock(); //VERY hacky. don't like it
		if (d->exit) return;
		int rt=select(maxfd,&fds,NULL,NULL,&timeout);
		if (d->exit) return;
		lk.lock();
		if (d->exit) return;

		if (rt)
		{
			for (sock_t fd : d->sockfds)
			{
				if (FD_ISSET(fd,&fds))
				{
					u8 bf[64];
					int size=60;
					size_t addr_len;
					struct sockaddr_storage their_addr;
					addr_len = sizeof their_addr;
					if ((size = recvfrom(fd,
										 (dataz)bf,
										 size , 0,(struct sockaddr *)&their_addr, (socklen_t*)&addr_len)) == -1)
					{
						ERROR_LOG(WIIMOTE,"UDPWii Packet error");
					}
					else
					{
						std::lock_guard<std::mutex> lkm(d->mutex);
						if (pharsePacket(bf,size)==0)
						{
							//NOTICE_LOG(WIIMOTE,"UDPWII New pack");
						}
						else
						{
							//NOTICE_LOG(WIIMOTE,"UDPWII Wrong pack format... ignoring");
						}
					}
				}
			}
		}
	} while (!(d->exit));
}
开发者ID:Bigorneau,项目名称:dolphin,代码行数:80,代码来源:UDPWiimote.cpp


示例12: Callback_WiimoteInterruptChannel

namespace Core
{

bool g_want_determinism;

// Declarations and definitions
static Common::Timer s_timer;
static volatile u32 s_drawn_frame = 0;
static u32 s_drawn_video = 0;

// Function forwarding
void Callback_WiimoteInterruptChannel(int _number, u16 _channelID, const void* _pData, u32 _Size);

// Function declarations
void EmuThread();

static bool s_is_stopping = false;
static bool s_hardware_initialized = false;
static bool s_is_started = false;
static void* s_window_handle = nullptr;
static std::string s_state_filename;
static std::thread s_emu_thread;
static StoppedCallbackFunc s_on_stopped_callback = nullptr;

static std::thread s_cpu_thread;
static bool s_request_refresh_info = false;
static int s_pause_and_lock_depth = 0;
static bool s_is_framelimiter_temp_disabled = false;

bool GetIsFramelimiterTempDisabled()
{
	return s_is_framelimiter_temp_disabled;
}

void SetIsFramelimiterTempDisabled(bool disable)
{
	s_is_framelimiter_temp_disabled = disable;
}

std::string GetStateFileName() { return s_state_filename; }
void SetStateFileName(std::string val) { s_state_filename = val; }

// Display messages and return values

// Formatted stop message
std::string StopMessage(bool bMainThread, std::string Message)
{
	return StringFromFormat("Stop [%s %i]\t%s\t%s",
		bMainThread ? "Main Thread" : "Video Thread", Common::CurrentThreadId(), MemUsage().c_str(), Message.c_str());
}

void DisplayMessage(const std::string& message, int time_in_ms)
{
	// Actually displaying non-ASCII could cause things to go pear-shaped
	for (const char& c : message)
	{
		if (!std::isprint(c))
			return;
	}

	g_video_backend->Video_AddMessage(message, time_in_ms);
	Host_UpdateTitle(message);
}

bool IsRunning()
{
	return (GetState() != CORE_UNINITIALIZED) || s_hardware_initialized;
}

bool IsRunningAndStarted()
{
	return s_is_started && !s_is_stopping;
}

bool IsRunningInCurrentThread()
{
	return IsRunning() && IsCPUThread();
}

bool IsCPUThread()
{
	return (s_cpu_thread.joinable() ? (s_cpu_thread.get_id() == std::this_thread::get_id()) : !s_is_started);
}

bool IsGPUThread()
{
	const SCoreStartupParameter& _CoreParameter =
		SConfig::GetInstance().m_LocalCoreStartupParameter;
	if (_CoreParameter.bCPUThread)
	{
		return (s_emu_thread.joinable() && (s_emu_thread.get_id() == std::this_thread::get_id()));
	}
	else
	{
		return IsCPUThread();
	}
}

// This is called from the GUI thread. See the booting call schedule in
// BootManager.cpp
//.........这里部分代码省略.........
开发者ID:dragonbane0,项目名称:Dolphin-Zelda-Build-OLD-,代码行数:101,代码来源:CORE.CPP


示例13: Run

namespace Core
{



// Declarations and definitions
// ---------------
int g_FrameCounter = 0;
bool g_FrameStep = false;
Common::Timer ReRecTimer;




// Control Run, Pause, Stop and the Timer.
// ---------------

// Subtract the paused time when we run again
void Run()
{
	ReRecTimer.AddTimeDifference();
}
// Update the time
void Pause()
{
	ReRecTimer.Update();
}

// Start the timer when a game is booted
void RerecordingStart()
{
	g_FrameCounter = 0;
	ReRecTimer.Start();

	// Logging
	//DEBUG_LOG(CONSOLE, "RerecordingStart: %i\n", g_FrameCounter);
}

// Reset the frame counter
void RerecordingStop()
{
	// Write the final time and Stop the timer
	ReRecTimer.Stop();

	// Update status bar
	WriteStatus();
}

/* Wind back the frame counter when a save state is loaded. Currently we don't know what that means in
   time so we just guess that the time is proportional the the number of frames
   
   Todo: There are many assumptions here: We probably want to replace the time here by the actual time
   that we save together with the save state or the input recording for example. And have it adjusted
   for full speed playback (whether it's 30 fps or 60 fps or some other speed that the game is natively
   capped at). Also the input interrupts do not occur as often as the frame renderings, they occur more
   often. So we may want to move the input recording to fram updates, or perhaps sync the input interrupts
   to frame updates.
   */
void WindBack(int Counter)
{
	/* Counter should be smaller than g_FrameCounter, however it currently updates faster than the
	   frames so currently it may not be the same. Therefore I use the abs() function. */
	int AbsoluteFrameDifference = abs(g_FrameCounter - Counter);
	float FractionalFrameDifference = (float) AbsoluteFrameDifference / (float) g_FrameCounter;

	// Update the frame counter
	g_FrameCounter = Counter;

	// Approximate a time to wind back the clock to
	// Get the current time
	u64 CurrentTimeMs = ReRecTimer.GetTimeElapsed();
	// Save the current time in seconds in a new double
	double CurrentTimeSeconds = (double) (CurrentTimeMs / 1000);
	// Reduce it by the same proportion as the counter was wound back
	CurrentTimeSeconds = CurrentTimeSeconds * FractionalFrameDifference;
	// Update the clock
	ReRecTimer.WindBackStartingTime((u64)CurrentTimeSeconds * 1000);

	// Logging
	DEBUG_LOG(CONSOLE, "WindBack: %i %u\n", Counter, (u64)CurrentTimeSeconds);
}




// Frame advance
// ---------------
void FrameAdvance()
{
	// Update status bar
	WriteStatus();	

	// If a game is not started, return
	if (Core::GetState() == Core::CORE_UNINITIALIZED) return;

	// Play to the next frame
	if (g_FrameStep)
	{
		Run();
		Core::SetState(Core::CORE_RUN);	
//.........这里部分代码省略.........
开发者ID:madnessw,项目名称:thesnow,代码行数:101,代码来源:CoreRerecording.cpp


示例14: Callback_WiimoteInterruptChannel

namespace Core
{
// TODO: ugly, remove
bool g_aspect_wide;

bool g_want_determinism;

// Declarations and definitions
static Common::Timer s_timer;
static std::atomic<u32> s_drawn_frame;
static std::atomic<u32> s_drawn_video;

// Function forwarding
void Callback_WiimoteInterruptChannel(int _number, u16 _channelID, const void* _pData, u32 _Size);

// Function declarations
void EmuThread();

static bool s_is_stopping = false;
static bool s_hardware_initialized = false;
static bool s_is_started = false;
static std::atomic<bool> s_is_booting{false};
static void* s_window_handle = nullptr;
static std::string s_state_filename;
static std::thread s_emu_thread;
static StoppedCallbackFunc s_on_stopped_callback = nullptr;

static std::thread s_cpu_thread;
static bool s_request_refresh_info = false;
static int s_pause_and_lock_depth = 0;
static bool s_is_throttler_temp_disabled = false;

struct HostJob
{
  std::function<void()> job;
  bool run_after_stop;
};
static std::mutex s_host_jobs_lock;
static std::queue<HostJob> s_host_jobs_queue;

#ifdef ThreadLocalStorage
static ThreadLocalStorage bool tls_is_cpu_thread = false;
#else
static pthread_key_t s_tls_is_cpu_key;
static pthread_once_t s_cpu_key_is_init = PTHREAD_ONCE_INIT;
static void InitIsCPUKey()
{
  pthread_key_create(&s_tls_is_cpu_key, nullptr);
}
#endif

bool GetIsThrottlerTempDisabled()
{
  return s_is_throttler_temp_disabled;
}

void SetIsThrottlerTempDisabled(bool disable)
{
  s_is_throttler_temp_disabled = disable;
}

std::string GetStateFileName()
{
  return s_state_filename;
}
void SetStateFileName(const std::string& val)
{
  s_state_filename = val;
}

void FrameUpdateOnCPUThread()
{
  if (NetPlay::IsNetPlayRunning())
    NetPlayClient::SendTimeBase();
}

// Display messages and return values

// Formatted stop message
std::string StopMessage(bool main_thread, const std::string& message)
{
  return StringFromFormat("Stop [%s %i]\t%s\t%s", main_thread ? "Main Thread" : "Video Thread",
                          Common::CurrentThreadId(), MemUsage().c_str(), message.c_str());
}

void DisplayMessage(const std::string& message, int time_in_ms)
{
  if (!IsRunning())
    return;

  // Actually displaying non-ASCII could cause things to go pear-shaped
  for (const char& c : message)
  {
    if (!std::isprint(c))
      return;
  }

  OSD::AddMessage(message, time_in_ms);
  Host_UpdateTitle(message);
}
//.........这里部分代码省略.........
开发者ID:CarlKenner,项目名称:dolphin,代码行数:101,代码来源:Core.cpp


示例15: ZeroMemory

/*
    TODO: Font rendering MUST be redesigned.
*/
Font* GuiRendererD3D11::MakeFont(const char* pPath, int height)
{
    Common::Timer timer;
    timer.Start();

    FT_Face face;
    int texWidth = 4096;
    int texHeight = 4096;

    //create pixels array
    unsigned char* pTexData = (unsigned char*)malloc(texWidth * texHeight);
    ZeroMemory(pTexData, texWidth * texHeight);

    if (FT_New_Face(mFreeTypeLibrary, pPath, 0, &face) != 0)
    {
        free(pTexData);
        // TODO
        // LOG_ERROR("Failed to load font '%s'.", pPath);
        return 0;
    }

    //FT_Set_Pixel_Sizes(face, 2*height, 2*height);
    FT_Set_Char_Size(face, 0, height * 64, 96, 96);


    Font* pFont = new Font;

    /*
    FT_Matrix Transform;
    Transform.xx = (FT_Fixed)(1.0f * 0x10000L);
    Transform.xy = (FT_Fixed)(0.0f * 0x10000L);
    Transform.yx = (FT_Fixed)(0.0f * 0x10000L);
    Transform.yy = (FT_Fixed)(1.0f * 0x10000L);
    FT_Set_Transform(face, &Transform, 0);
    */

    int Width;
    int Height;
    int OffsetX = 0;
    int OffsetY = 0;

    pFont->height = height;
    pFont->charCount = 65536;
    pFont->characters = (CharacterInfo*)malloc(sizeof(CharacterInfo) * pFont->charCount);

    int Index = 0;
    for (int ChrId = 0; ChrId < (65536); ChrId++)
    {
        // Load The Glyph For Our Character.
        unsigned int GlyphIndex = FT_Get_Char_Index(face, ChrId);
        if (GlyphIndex == 0)
        {
            pFont->characters[ChrId].exists = false;
            continue;
        }

        FT_Load_Glyph(face, GlyphIndex, FT_LOAD_DEFAULT);


        // Move The Face's Glyph Into A Glyph Object.
        FT_Glyph glyph;
        FT_Get_Glyph(face->glyph, &glyph);


        // Convert The Glyph To A Bitmap.
        FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, 0, 1);
        FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph)glyph;

        // This Reference Will Make Accessing The Bitmap Easier.
        FT_Bitmap& bitmap = bitmap_glyph->bitmap;


        Width = bitmap.width;
        Height = bitmap.rows;

        //char won't fit to texture
        if (OffsetX + Width + 2 > texWidth)
        {
            OffsetX = 0;
            OffsetY += 2 * height;
        }

        for (int y = 0; y < Height; y++)
        {
            for (int x = 0; x < Width; x++)
            {
                unsigned char Value = bitmap.buffer[x + Width * y];

                int PxOffset = (y + OffsetY) * texWidth + x + OffsetX;
                pTexData[PxOffset] = Value;
            }
        }


        pFont->characters[ChrId].exists = true;
        pFont->characters[ChrId].top = (short)bitmap_glyph->top;
        pFont->characters[ChrId].left = (short)bitmap_glyph->left;
//.........这里部分代码省略.........
开发者ID:nfprojects,项目名称:nfengine,代码行数:101,代码来源:GuiRenderer.cpp


示例16: UpdateTitle

void UpdateTitle()
{
	u32 ElapseTime = (u32)Timer.GetTimeDifference();
	g_requestRefreshInfo = false;
	SCoreStartupParameter& _CoreParameter = SConfig::GetInstance().m_LocalCoreStartupParameter;

	if (ElapseTime == 0)
		ElapseTime = 1;

	float FPS = (float) (Common::AtomicLoad(DrawnFrame) * 1000.0 / ElapseTime);
	float VPS = (float) (DrawnVideo * 1000.0 / ElapseTime);
	float Speed = (float) (DrawnVideo * (100 * 1000.0) / (VideoInterface::TargetRefreshRate * ElapseTime));

	// Settings are shown the same for both extended and summary info
	std::string SSettings = StringFromFormat("%s %s | %s | %s", cpu_core_base->GetName(), _CoreParameter.bCPUThread ? "DC" : "SC",
		g_video_backend->GetDisplayName().c_str(), _CoreParameter.bDSPHLE ? "HLE" : "LLE");

	std::string SFPS;

	if (Movie::IsPlayingInput())
		SFPS = StringFromFormat("VI: %u/%u - Frame: %u/%u - FPS: %.0f - VPS: %.0f - %.0f%%", (u32)Movie::g_currentFrame, (u32)Movie::g_totalFrames, (u32)Movie::g_currentInputCount, (u32)Movie::g_totalInputCount, FPS, VPS, Speed);
	else if (Movie::IsRecordingInput())
		SFPS = StringFromFormat("VI: %u - Frame: %u - FPS: %.0f - VPS: %.0f - %.0f%%", (u32)Movie::g_currentFrame, (u32)Movie::g_currentInputCount, FPS, VPS, Speed);
	else
	{
		SFPS = StringFromFormat("FPS: %.0f - VPS: %.0f - %.0f%%", FPS, VPS, Speed);
		if (SConfig::GetInstance().m_InterfaceExtendedFPSInfo)
		{
			// Use extended or summary information. The summary information does not print the ticks data,
			// that's more of a debugging interest, it can always be optional of course if someone is interested.
			static u64 ticks = 0;
			static u64 idleTicks = 0;
			u64 newTicks = CoreTiming::GetTicks();
			u64 newIdleTicks = CoreTiming::GetIdleTicks();

			u64 diff = (newTicks - ticks) / 1000000;
			u64 idleDiff = (newIdleTicks - idleTicks) / 1000000;

			ticks = newTicks;
			idleTicks = newIdleTicks;

			float TicksPercentage = (float)diff / (float)(SystemTimers::GetTicksPerSecond() / 1000000) * 100;

			SFPS += StringFromFormat(" | CPU: %s%i MHz [Real: %i + IdleSkip: %i] / %i MHz (%s%3.0f%%)",
					_CoreParameter.bSkipIdle ? "~" : "",
					(int)(diff),
					(int)(diff - idleDiff),
					(int)(idleDiff),
					SystemTimers::GetTicksPerSecond() / 1000000,
					_CoreParameter.bSkipIdle ? "~" : "",
					TicksPercentage);
		}
	}
	// This is our final "frame counter" string
	std::string SMessage = StringFromFormat("%s | %s", SSettings.c_str(), SFPS.c_str());
	std::string TMessage = StringFromFormat("%s | %s", scm_rev_str, SMessage.c_str());

	// Show message
	g_video_backend->UpdateFPSDisplay(SMessage);

	// Update the audio timestretcher with the current speed
	if (soundStream)
	{
		CMixer* pMixer = soundStream->GetMixer();
		pMixer->UpdateSpeed((float)Speed / 100);
	}

	if (_CoreParameter.bRenderToMain &&
		SConfig::GetInstance().m_InterfaceStatusbar)
	{
		Host_UpdateStatusBar(SMessage);
		Host_UpdateTitle(scm_rev_str);
	}
	else
	{
		Host_UpdateTitle(TMessage);
	}
}
开发者ID:DigidragonZX,项目名称:dolphin,代码行数:78,代码来源:Core.cpp


示例17: Callback_WiimoteInterruptChannel

namespace Core
{

// Declarations and definitions
Common::Timer Timer;
volatile u32 DrawnFrame = 0;
u32 DrawnVideo = 0;

// Function forwarding
const char *Callback_ISOName(void);
void Callback_WiimoteInterruptChannel(int _number, u16 _channelID, const void* _pData, u32 _Size);

// Function declarations
void EmuThread();

void Stop();

bool g_bStopping = false;
bool g_bHwInit = false;
bool g_bStarted = false;
bool g_bRealWiimote = false;
void *g_pWindowHandle = NULL;
std::string g_stateFileName;
std::thread g_EmuThread;

static std::thread g_cpu_thread;
static bool g_requestRefreshInfo = false;
static int g_pauseAndLockDepth = 0;

SCoreStartupParameter g_CoreStartupParameter;

std::string GetStateFileName() { return g_stateFileName; }
void SetStateFileName(std::string val) { g_stateFileName = val; }

// Display messages and return values

// Formatted stop message
std::string StopMessage(bool bMainThread, std::string Message)
{
	return StringFromFormat("Stop [%s %i]\t%s\t%s",
		bMainThread ? "Main Thread" : "Video Thread", Common::CurrentThreadId(), MemUsage().c_str(), Message.c_str());
}

// 
bool PanicAlertToVideo(const char* text, bool yes_no)
{
	DisplayMessage(text, 3000);
	return true;
}

void DisplayMessage(const char *message, int time_in_ms)
{
	SCoreStartupParameter& _CoreParameter =
		SConfig::GetInstance().m_LocalCoreStartupParameter;

	// Actually displaying non-ASCII could cause things to go pear-shaped
	for (const char *c = message; *c != '\0'; ++c)
		if (*c < ' ')
			return;

	g_video_backend->Video_AddMessage(message, time_in_ms);
	
	if (_CoreParameter.bRenderToMain &&
		SConfig::GetInstance().m_InterfaceStatusbar)
	{
		Host_UpdateStatusBar(message);
	}
	else
		Host_UpdateTitle(message);
}

void Callback_DebuggerBreak()
{
	CCPU::Break();
}

void *GetWindowHandle()
{
	return g_pWindowHandle;
}

bool IsRunning()
{
	return (GetState() != CORE_UNINITIALIZED) || g_bHwInit;
}

bool IsRunningAndStarted()
{
	return g_bStarted;
}

bool IsRunningInCurrentThread()
{
	return IsRunning() && IsCPUThread();
}

bool IsCPUThread()
{
	return (g_cpu_thread.joinable() ? (g_cpu_thread.get_id() == std::this_thread::get_id()) : !g_bStarted);
}
//.........这里部分代码省略.........
开发者ID:Everscent,项目名称:dolphin-emu,代码行数:101,代码来源:Core.cpp


示例18: WinMain


//.........这里部分代码省略.........
    // Set focus
    g_pScene->SetFocusSegment(pSegments[0][0]);
#endif

    /*
    for (int i = -4; i<4; i++)
    {
        for (int j = -10; j<10; j++)
        {
            for (int k = -4; k<4; k++)
            {
                Entity* pCube = g_pScene->CreateEntity();
                pCube->SetPosition(0.75f * Vector(i,j,k));

                MeshComponent* pMesh = new MeshComponent(pCube);
                pMesh->SetMeshResource("cube.nfm");

                BodyComponent* pBody = new BodyComponent(pCube);
                pBody->SetMass(1.0f);
                pBody->EnablePhysics((CollisionShape*)Engine_GetResource(Mesh::COLLISION_SHAPE, "shape_box"));
            }
        }
    }

    //set ambient & background color
    envDesc.m_AmbientLight = Vector(0.001f, 0.001f, 0.001f, 0.0f);
    envDesc.m_BackgroundColor = Vector(0.0f, 0.0f, 0.0f, 0.0f);
    g_pScene->SetEnvironment(&envDesc);

    // SUNLIGHT
    Entity* pDirLightEnt = g_pScene->CreateEntity();
    XOrientation orient;
    orient.x = Vector(0.0f, -0.0f, -0.0f, 0.0f);
    orient.z = Vector(-0.5f, -1.1f, 1.2f, 0.0f);
    orient.y = Vector(0.0f, 1.0f, 0.0f, 0.0f);
    pDirLightEnt->SetOrientation(&orient);
    DirLightDesc dirLight;
    dirLight.m_Far = 100.0f;
    dirLight.m_Splits = 4;
    dirLight.m_LightDist = 1000.0f;

    LightComponent* pDirLight = new LightComponent(pDirLightEnt);
    pDirLight->SetDirLight(&dirLight);
    pDirLight->SetColor(Float3(2.2, 2, 1.8));
    pDirLight->SetShadowMap(1024);

    pFirstWindow->cameraEntity->SetPosition(Vector(0.0f, 1.6f, -20.0f, 0.0f));
    */

    // message loop

    DrawRequest drawRequests[2];

    Common::Timer timer;
    timer.Start();
    while (!pWindow->isClosed())
    {
        //measure delta time
        g_DeltaTime = (float)timer.Stop();
        timer.Start();

        UpdateRequest updateReq;
        updateReq.pScene = g_pScene;
        updateReq.deltaTime = g_DeltaTime;


        pWindow->processMessages();
        pWindow->UpdateCamera();

        drawRequests[0].deltaTime = g_DeltaTime;
        drawRequests[0].pView = pWindow->view;
        drawRequests[1].deltaTime = g_DeltaTime;
        drawRequests[1].pView = g_pSecondaryCameraView;
        EngineAdvance(drawRequests, 2, &updateReq, 1);

        ProcessSceneEvents();

        // print focus segment name
        wchar_t str[128];
        Segment* pFocus = g_pScene->GetFocusSegment();
        swprintf(str, L"NFEngine Demo (%S) - focus: %S", PLATFORM_STR,
                 (pFocus != 0) ? pFocus->GetName() : "NONE");
        pWindow->setTitle(str);
    }

    // for testing purposes
    Common::FileOutputStream test_stream("test.xml");
    g_pScene->Serialize(&test_stream, SerializationFormat::Xml, false);

    EngineDeleteScene(g_pScene);
    delete pWindow;
    EngineRelease();

//detect memory leaks
#ifdef _DEBUG
    _CrtDumpMemoryLeaks();
#endif

    return 0;
}
开发者ID:nfprojects,项目名称:nfengine,代码行数:101,代码来源:test.cpp


示例19: Pause

// Update the time
void Pause()
{
	ReRecTimer.Update();
}
开发者ID:madnessw,项目名称:thesnow,代码行数:5,代码来源:CoreRerecording.cpp


示例20: VideoThrottle

// Display FPS info
// This should only be called from VI
void VideoThrottle()
{
	// Update info per second
	u32 ElapseTime = (u32)s_timer.GetTimeDifference();
	if ((ElapseTime >= 1000 && s_drawn_video.load() > 0) || s_request_refresh_info)
	{
		UpdateTitle();

		// Reset counter
		s_timer.Update();
		s_drawn_frame.store(0);
		s_drawn_video.store(0);
	}

	s_drawn_video++;
	bool update_ss_speed = true;
	if (SConfig::GetInstance().bDoubleVideoRate)
	{
		update_ss_speed = s_drawn_video & 1;
	}
	// Update the audio timestretcher with the current speed
	if (g_sound_stream && update_ss_speed)
	{
		float Speed = (float)(s_drawn_video.load() * 1000.0 / (VideoInterface::GetTargetRefreshRate() * ElapseTime));
		g_sound_stream->GetMixer()->UpdateSpeed((float)Speed);
	}
}
开发者ID:KoolWolff,项目名称:Ishiiruka,代码行数:29,代码来源:Core.cpp



注:本文中的common::Timer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ common::UString类代码示例发布时间:2022-05-31
下一篇:
C++ common::StringMap类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap