時間在人們的生活中是多么重要的東西,如果打亂了時間,不知道這個時間會成什么樣子。在客戶端中,自然也有時間模塊,因為不同的時間可能會處理不同的事情,特別是在追求高度自由化的同時,時間也成為了一個很重要的核心。沒有時間,游戲世界將失去平衡,沒有時間的游戲,會讓人覺得乏味而單調。好了,我不用再強調時間多重要,想必大家已經明白了。比如游戲中的時辰變化,天氣變化,這個是有時間的嗎,答案是肯定的。在此次設計中,時間的接口中又提供了哪些方法呢?
CODE
模塊time 文件system.h
/** * PAP Engine ( -- ) * $Id system.h * @link -- for the canonical source repository * @copyright Copyright (c) 2013-2014 viticm( viticm@126.com ) * @license * @user viticm<viticm@126.com/viticm.ti@gmail.com> * @date 2014-3-19 09:35:51 * @uses vengine time system module */ #ifndef VENGINE_TIME_SYSTEM_H_ #define VENGINE_TIME_SYSTEM_H_ #include <time.h> #include "vengine/config.h" #include "vengine/kernel/node.h" namespace vengine_time { class VENGINE_API System : public vengine_kernel::Node { VENGINE_KERNEL_DECLARE_DYNAMIC(vengine_time_System); public: virtual void init(void*); virtual void tick(); public: //取得最近20ms以來每禎平均花費的時間 float get_looptime() const; //取得上一幀花費時間 float get_lastframe_time() const; //根據looptime_取得運行時間 float get_runtime() const; uint32_t get_nowtime() const; //獲取幀率(FPS) float getFPS() const; //算時間差,考慮時間闕(49.71天) uint32_t get_difftime(uint32_t starttime, uint32_t endtime); //獲得幀數 uint32_t get_tickcount() const; //設置服務器時間 void set_servertime(time_t _time); time_t get_servertime(); protected: float looptime_; float lastframe_time_; float runtime_; uint32_t nowtime_; float FPS_; time_t servertime_; time_t localtime_; uint32_t tickcount_; }; }; //namespace vengine_time #endif //VENGINE_TIME_SYSTEM_H_
解釋
什么是幀率?
幀率在客戶端中至關重要,因為它影響着客戶端的運行速度,即客戶端的性能。
每秒的幀數(fps)或者說幀率表示圖形處理器處理場時每秒鍾能夠更新的次數。高的幀率可以得到更流暢、更逼真的動畫。一般來說30fps就是可以接受的,但是將性能提升至60fps則可以明顯提升交互感和逼真感,但是一般來說超過75fps一般就不容易察覺到有明顯的流暢度提升了。如果幀率超過屏幕刷新率只會浪費圖形處理的能力,因為監視器不能以這么快的速度更新,這樣超過刷新率的幀率就浪費掉了。
SIMPLE
笑傲江湖OL中的各種活動
總結
時間模塊里提供的方法,大家不難看出有tick(每幀處理),獲取程序運行時間,當前客戶端時間,以及服務器時間,這些各種時間都會影響到客戶端的一些特殊的邏輯處理,我就不在這一一敘述了。下一節講的是UI模塊。