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

📄 utility.cpp

📁 天之炼狱1服务器端源文件游戏服务端不完整
💻 CPP
字号:
//////////////////////////////////////////////////////////////////////////////// Filename    : Utility.cpp// Written by  : 辫己刮// Description : // 咯矾 镑俊辑 荤侩登绰 概农肺 棺 埃窜茄 窃荐甫 沥狼茄 颇老捞促.//////////////////////////////////////////////////////////////////////////////#include "Utility.h"#include <stdio.h>#include <stdlib.h>#include "Assert.h"#include "VSDateTime.h"//////////////////////////////////////////////////////////////////////////////// 荤阿屈 努贰胶///////////////////////////////////////////////////////////////////////////////*VSRect::VSRect(int l, int t, int r, int b){	Assert(l <= r && t <= b);	left   = l;	top    = t;	right  = r;	bottom = b;}bool VSRect::ptInRect(const POINT& pt) const{	if(left <= pt.x && pt.x <= right && top <= pt.y && pt.y <= bottom) return true;	return false;}bool VSRect::ptInRect(const int x, const int y) const{	if(left <= x && x <= right && top <= y && y <= bottom) return true;	return false;}void VSRect::set(int l, int t, int r, int b){	Assert(l <= r && t <= b);	left   = l;	top    = t;	right  = r;	bottom = b;}*///////////////////////////////////////////////////////////////////////////////// 箭磊甫 巩磊凯肺 官操扁//////////////////////////////////////////////////////////////////////////////string itos(int value){	char buf[100] = {0, };	sprintf(buf, "%d", value);	return string(buf);}//////////////////////////////////////////////////////////////////////////////// 规氢 备窍扁// origin俊辑 dest狼 规氢阑 鸥老农扁俊 嘎霸 备茄促. client俊辑 啊廉吭促.//////////////////////////////////////////////////////////////////////////////#define BASIS_DIRECTION_HIGH    2.0f#define BASIS_DIRECTION_LOW     0.5fDir_t computeDirection(int originX, int originY, int destX, int destY){	int   stepX = destX - originX;	int   stepY = destY - originY;	float k     =(stepX == 0) ? 0 :(float)(stepY) / stepX;	if(stepY == 0)	{		if(stepX == 0)     return DOWN;		else if(stepX > 0) return RIGHT;		else                return LEFT;	}	else if(stepY < 0)	{		if(stepX == 0)		{			return UP;		}		else if(stepX > 0)		{			if(k < -BASIS_DIRECTION_HIGH)     return UP;			else if(k < -BASIS_DIRECTION_LOW) return RIGHTUP;			else                               return RIGHT;		}		else		{			if(k > BASIS_DIRECTION_HIGH)     return UP;			else if(k > BASIS_DIRECTION_LOW) return LEFTUP;			else                              return LEFT;		}	}	else	{		if(stepX == 0)		{			return DOWN;		}		else if(stepX > 0)		{			if(k > BASIS_DIRECTION_HIGH)     return DOWN;			else if(k > BASIS_DIRECTION_LOW) return RIGHTDOWN;			else                              return RIGHT;		}		else		{			if(k < -BASIS_DIRECTION_HIGH)     return DOWN;			else if(k < -BASIS_DIRECTION_LOW) return LEFTDOWN;			else                               return LEFT;		}	}	return DIR_NONE;}/*Dir_t calcDirection(int originX, int originY, int destX, int destY){	return computeDirection(originX, originY, destX, destY);}Dir_t getDirection(int originX, int originY, int destX, int destY){	return computeDirection(originX, originY, destX, destY);}//////////////////////////////////////////////////////////////////////////////// 罚待 箭磊 惶酒郴扁//////////////////////////////////////////////////////////////////////////////int Random(int Min, int Max){	if(Max == 0 || Min > Max) return  0;	return ((rand() %(int)((Max) -(Min) + 1)) +(Min));}//////////////////////////////////////////////////////////////////////////////// 馆棵覆窍扁//////////////////////////////////////////////////////////////////////////////int Round(float f) { return f - 0.5 >(int)f ?(int)f + 1 :(int)f; }//////////////////////////////////////////////////////////////////////////////// 促捞胶 窃荐//////////////////////////////////////////////////////////////////////////////uint Dice(uint num , uint dice){	uint result = 0;	for(uint i = 0 ; i < num ; i ++)	result += rand() % dice + 1;	return result;}*///////////////////////////////////////////////////////////////////////////////// 变 巩磊凯俊辑 茄 扼牢 啊廉坷扁// pos 蔼篮 \n 狼 牢郸胶蔼捞 等促.//////////////////////////////////////////////////////////////////////////////string getline(const string & str , uint & pos)	throw(){	if(pos > str.size()) return "";	uint oldpos = pos;	pos = str.find_first_of('\n',oldpos);	if(pos == string::npos) pos = str.size()+1;	else                     pos = pos+1;	return str.substr(oldpos ,(pos - 1) - oldpos);	/*	uint oldpos = pos;	// 1 阑 歹秦林搁, 	pos = str.find_first_of('\n',oldpos) + 1;	return str.substr(oldpos ,(pos - 1) - oldpos);	*/}//////////////////////////////////////////////////////////////////////////////// 巩磊凯 菊 第狼 傍归 力芭窍扁//////////////////////////////////////////////////////////////////////////////string trim(const string & str)	throw(){	if(str.size() == 0) return "";	static const char * WhiteSpaces = " \t\n\r";	uint begin = str.find_first_not_of(WhiteSpaces);	uint end = str.find_last_not_of(WhiteSpaces);	if(begin == string::npos) begin = 0;	if(end   == string::npos) end   = str.size();	return str.substr(begin , end - begin + 1);}//////////////////////////////////////////////////////////////////////////////// 泅犁 矫埃 掘绢郴扁//////////////////////////////////////////////////////////////////////////////void getCurrentTimeEx(int& year, int& month, int& day, int& hour, int& minute, int& sec) 	throw(){	time_t cur_time = time(NULL);	tm     cur_tm;	localtime_r( &cur_time, &cur_tm );	//tm*    cur_tm   = localtime(&cur_time);	year   = cur_tm.tm_year + 1900;	month  = cur_tm.tm_mon  + 1;	day    = cur_tm.tm_mday;	hour   = cur_tm.tm_hour;	minute = cur_tm.tm_min;	sec    = cur_tm.tm_sec;}string getCurrentTimeStringEx(void) 	throw(){	int year, month, day, hour, minute, second;	getCurrentTimeEx(year, month, day, hour, minute, second);	string rValue;	rValue += itos(year)   + ". ";	rValue += itos(month)  + ". ";	rValue += itos(day)    + ". ";	rValue += itos(hour)   + ". ";	rValue += itos(minute) + ". ";	rValue += itos(second) + ". ";	return rValue;}//////////////////////////////////////////////////////////////////////////////// 况靛 惑困 官捞飘客 窍困 官捞飘肺 盒府矫虐扁///////////////////////////////////////////////////////////////////////////////*void splitWord(WORD value, int& high, int& low) 	throw(){	high = value >> 8;	low  = value & 0xFF;}//////////////////////////////////////////////////////////////////////////////// 0栏肺 檬扁拳矫虐扁//////////////////////////////////////////////////////////////////////////////void zerofill(void* pointer, size_t size)	throw(){	memset(pointer, 0, size);}//////////////////////////////////////////////////////////////////////////////// range 郴俊 乐绰瘤 八荤窍扁//////////////////////////////////////////////////////////////////////////////bool isInRange(int value, int min, int max)	throw(){	if(min <= value && value <= max) return true;	return false;}//////////////////////////////////////////////////////////////////////////////// 林绢柳 箭磊狼 %蔼 舅酒郴扁//////////////////////////////////////////////////////////////////////////////int getPercentValue(int value, int percent){	return(int)((float)value *(float)percent / 100.0);}*///////////////////////////////////////////////////////////////////////////////// 林绢柳 箭磊狼 %蔼 舅酒郴扁  -  家荐 霉犁磊府 焊沥//////////////////////////////////////////////////////////////////////////////int getPercentValueEx( int value, int percent ){	static int tick = 0;		int thousand = getPercentValue( value, percent * 10 );	int ret = ( thousand + tick ) / 10;	tick++;	if ( tick > 9 ) tick = 0;	return ret;}//////////////////////////////////////////////////////////////////////////////// 颇老俊促 肺弊窍扁//////////////////////////////////////////////////////////////////////////////void filelog(const char* szFilename, const char* fmt, ...)    throw(){    __BEGIN_TRY    va_list valist;    va_start(valist, fmt);    char buffer[30000];    int nchars = vsnprintf(buffer, 30000, fmt, valist);    if(nchars == -1 || nchars > 30000)	{        throw("filelog() : more buffer size needed for log");	}    va_end(valist);	VSDateTime current = VSDateTime::currentDateTime();    ofstream file(szFilename, ios::out | ios::app);    file << current.toString() << " : " << buffer << endl;    file.close();    __END_CATCH}//////////////////////////////////////////////////////////////////////////////// 2俺狼 WORD 甫 DWORD 肺 官层霖促. HIWORD, LOWORD//////////////////////////////////////////////////////////////////////////////DWORD makeDWORD( WORD hiWord, WORD loWord ){	DWORD dwResult = ( (DWORD)hiWord << 16 ) | loWord;	return dwResult;}//////////////////////////////////////////////////////////////////////////////// DWORD 狼 HIWORD, LOWORD 啊廉坷扁//////////////////////////////////////////////////////////////////////////////WORD getHIWORD( DWORD dwValue ){	WORD wResult = (WORD)( dwValue >> 16 );	return wResult;}WORD getLOWORD( DWORD dwValue ){	DWORD dwMask = 0x00FF;	WORD wResult = (WORD)( dwMask & dwValue );	return wResult;}

⌨️ 快捷键说明

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