Move git root from Client/ to src/ to track all source code: - Client: Game client source (moved to Client/Client/) - Server: Game server source - GameTools: Development tools - CryptoSource: Encryption utilities - database: Database scripts - Script: Game scripts - rylCoder_16.02.2008_src: Legacy coder tools - GMFont, Game: Additional resources 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
93 lines
2.6 KiB
C++
93 lines
2.6 KiB
C++
// FastMath.h: interface for the CFastMath class.
|
|
//
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#ifndef _CUSTOM_MATH_FUNCTIONS_H_
|
|
#define _CUSTOM_MATH_FUNCTIONS_H_
|
|
|
|
#include <winsock2.h>
|
|
#include <windows.h>
|
|
#include <cmath>
|
|
|
|
|
|
namespace Math
|
|
{
|
|
namespace Convert
|
|
{
|
|
extern const unsigned short m_FastHeToBi[0x100];
|
|
|
|
// SPX, IPX 주소 계산을 위해 사용하는 함수
|
|
inline unsigned char BiToHe(char cBin);
|
|
inline void AcToHe(char *szDst, char *szSrc, int iCount);
|
|
|
|
// String을 값으로 바꿈(String은 0x가 붙은 Hex string이다.)
|
|
inline BYTE StrToHex08(const char *szSrc);
|
|
inline WORD StrToHex16(const char *szSrc);
|
|
inline DWORD StrToHex32(const char *szSrc);
|
|
inline DWORD64 StrToHex64(const char *szSrc);
|
|
|
|
// String을 값으로 바꿈(0x가 붙던지, 붙지 않던지간에 전부 바꿀 수 있다)
|
|
inline BYTE Atoc(char *szSrc);
|
|
inline WORD Atos(char *szSrc);
|
|
inline DWORD Atoi(char *szSrc);
|
|
inline DWORD64 Atol64(char *szSrc);
|
|
|
|
// 값을 Hex String으로 바꿈
|
|
inline void Hex08ToStr(char *szDest, BYTE hex);
|
|
inline void Hex16ToStr(char *szDest, WORD hex);
|
|
inline void Hex32ToStr(char *szDest, DWORD hex);
|
|
inline void Hex64ToStr(char *szDest, DWORD64 hex);
|
|
};
|
|
|
|
namespace Random
|
|
{
|
|
// 리턴값은 0 ~ nExtent - 1의 범위를 갖는다.
|
|
unsigned long ComplexRandom(int nExtent); // 비교적 분포가 좋다.
|
|
};
|
|
|
|
namespace HashFunc
|
|
{
|
|
// -------------------------------------------------------------------------------------------------
|
|
// String-to-Hash 함수들 : http://www.cs.yorku.ca/~oz/hash.html 에서 참고
|
|
|
|
inline unsigned long djb2Hash(const unsigned char *str); // first reported by dan bernstein
|
|
inline unsigned long sdbmHash(const unsigned char *str); // this is one of the algorithms used in berkeley db
|
|
inline unsigned long looseHash(const unsigned char *str); // 가장 간단한 해쉬. 그냥 모두 더함.
|
|
};
|
|
};
|
|
|
|
#include "Convert.inl"
|
|
|
|
|
|
|
|
inline unsigned long Math::HashFunc::djb2Hash(const unsigned char *str)
|
|
{
|
|
unsigned long hash = 5381;
|
|
int c;
|
|
|
|
while (c = *str++) { hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ }
|
|
return hash;
|
|
}
|
|
|
|
|
|
inline unsigned long Math::HashFunc::sdbmHash(const unsigned char *str)
|
|
{
|
|
unsigned long hash = 0;
|
|
int c;
|
|
|
|
while (c = *str++) { hash = c + (hash << 6) + (hash << 16) - hash; }
|
|
return hash;
|
|
}
|
|
|
|
inline unsigned long Math::HashFunc::looseHash(const unsigned char *str)
|
|
{
|
|
unsigned int hash = 0;
|
|
int c;
|
|
|
|
while (c = *str++) { hash += c; }
|
|
return hash;
|
|
}
|
|
|
|
|
|
#endif // !defined(AFX_FASTMATH_H__ED69578B_18C1_42EA_9C5E_888DC38101C2__INCLUDED_)
|