EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
misc.h File Reference
#include <eve-compat.h>
Include dependency graph for misc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

 EvE
 

Functions

uint16 crc_hqx (const uint8 *data, size_t len, uint16 crc=0)
 
int64 filesize (const char *filename)
 Obtains filesize. More...
 
int64 filesize (FILE *fd)
 Obtains filesize. More...
 
int64 npowof2 (int64 num)
 Calculates next (greater or equal) power-of-two number. More...
 
int64 MakeRandomInt (int64 low=0, int64 high=RAND_MAX)
 Generates random integer from interval [low; high]. More...
 
double MakeRandomFloat (double low=0, double high=1)
 Generates random real from interval [low; high]. More...
 
bool IsEven (int64 number)
 
bool IsNaN (double x)
 
uint32 CreatePIDFile (const std::string &filename)
 create PID file More...
 
double EvE::min (double x, double y)
 
int32 EvE::min (int32 x, int32 y)
 
double EvE::min1 (double x, double y)
 
double EvE::min (double x, double y, double z)
 
int64 EvE::max (int64 x, int64 y=0)
 
double EvE::max (double x, double y=0)
 
double EvE::max (double x, double y, double z)
 
void EvE::traceStack (void)
 
bool EvE::icontains (std::string data, std::string toSearch, size_t pos=0)
 
const char * EvE::FormatTime (int64 time=-1)
 
const char * EvE::FormatTime (double time=-1)
 
double EvE::trunicate2 (double dig=0)
 

Function Documentation

uint16 crc_hqx ( const uint8 data,
size_t  len,
uint16  crc = 0 
)

This is functionally equivalent to python's binascii.crc_hqx.

Parameters
[in]dataBinary data to be checksumed.
[in]lenLength of binary data.
[in]crcCRC value to start with.
Returns
CRC-16 checksum.

Definition at line 67 of file misc.cpp.

Referenced by PyService::_BuildCachedReturn().

68 {
69  while( len-- )
70  crc = ( crc << 8 ) ^ crc16_table[ ( crc >> 8 ) ^ ( *data++ ) ];
71 
72  return crc;
73 }

Here is the caller graph for this function:

uint32 CreatePIDFile ( const std::string &  filename)

create PID file

Definition at line 131 of file misc.cpp.

132 {
133  FILE* pid_file = fopen (filename.c_str(), "w" );
134  if (pid_file == NULL)
135  return 0;
136 
137  #ifdef _WIN32
138  DWORD pid = GetCurrentProcessId();
139  #else
140  pid_t pid = getpid();
141  #endif
142 
143  fprintf(pid_file, "%u", pid );
144  fclose(pid_file);
145 
146  return (uint32)pid;
147 }
unsigned __int32 uint32
Definition: eve-compat.h:50
int64 filesize ( const char *  filename)

Obtains filesize.

Parameters
[in]filenameName of file to examine.
Returns
Size of file.

Definition at line 75 of file misc.cpp.

References filesize().

Referenced by filesize(), and CachedObjectMgr::LoadCachedFile().

76 {
77  FILE* fd = fopen( filename, "r" );
78  if( fd == NULL )
79  return 0;
80 
81  return filesize( fd );
82 }
int64 filesize(const char *filename)
Obtains filesize.
Definition: misc.cpp:75

Here is the call graph for this function:

Here is the caller graph for this function:

int64 filesize ( FILE *  fd)

Obtains filesize.

Parameters
[in]fdDescriptor of file to examine.
Returns
Size of file.

Definition at line 84 of file misc.cpp.

85 {
86 #ifdef HAVE_SYS_STAT_H
87  struct stat st;
88  ::fstat( ::fileno( fd ), &st );
89  return st.st_size;
90 #else /* !HAVE_SYS_STAT_H */
91  return ::filelength( ::fileno( fd ) );
92 #endif /* !HAVE_SYS_STAT_H */
93 }
bool IsEven ( int64  number)
inline

Definition at line 88 of file misc.h.

Referenced by DungeonMgr::AddDecoToVector(), Prospector::DropSalvage(), MapData::GetMissionDestination(), CustomsSE::Killed(), StructureSE::Killed(), and ShipSE::Killed().

88 { return ((number %2) == 0); }

Here is the caller graph for this function:

bool IsNaN ( double  x)
inline

Definition at line 89 of file misc.h.

Referenced by BeltMgr::SpawnAsteroid().

89 { return x!= x; }

Here is the caller graph for this function:

double MakeRandomFloat ( double  low = 0,
double  high = 1 
)

Generates random real from interval [low; high].

Parameters
[in]lowLow boundary of interval.
[in]highHigh boundary of interval.
Returns
The generated real.

Definition at line 114 of file misc.cpp.

Referenced by TurretModule::ApplyDamage(), AnomalyMgr::CreateAnomaly(), ShipSE::DamageRandModule(), TurretFormulas::GetDroneToHit(), StaticDataMgr::GetLoot(), TurretFormulas::GetNPCToHit(), DungeonMgr::GetRandLevel(), TurretFormulas::GetSentryToHit(), TurretFormulas::GetToHit(), Sentry::Killed(), NPC::Killed(), ShipSE::Killed(), ActiveModule::LaunchProbe(), PlanetSE::LoadExtras(), DungeonMgr::MakeDungeon(), MakeRandomInt(), GPoint::MakeRandomPointOnSphere(), Vector3D::MakeRandomPointOnSphere(), GPoint::MakeRandomPointOnSphereLayer(), Vector3D::MakeRandomPointOnSphereLayer(), NPCAIMgr::MissileLaunched(), SpawnMgr::PrepSpawn(), ConcordAI::Process(), MiningLaser::ProcessCycle(), DroneAIMgr::SetEngaged(), ConcordAI::SetEngaged(), ConcordAI::SetSignaling(), BeltMgr::SpawnBelt(), NPCAIMgr::Targeted(), and SpawnMgr::WarpOutSpawn().

115 {
116  if( low == high )
117  return low;
118 
119  static bool seeded = false;
120  if( !seeded )
121  {
122  time_t x = ::time( NULL );
123  ::srand( x * ( x % (time_t)( high - low ) ) );
124  seeded = true;
125  }
126 
127  return low + ( high - low ) * ::rand() / RAND_MAX;
128 }

Here is the caller graph for this function:

int64 MakeRandomInt ( int64  low = 0,
int64  high = RAND_MAX 
)

Generates random integer from interval [low; high].

Parameters
[in]lowLow boundary of interval.
[in]highHigh boundary of interval.
Returns
The generated integer.

Definition at line 109 of file misc.cpp.

References MakeRandomFloat().

Referenced by APIAccountManager::_GenerateAPIKey(), DungeonMgr::AddDecoToVector(), SystemEntity::ApplyDamage(), Prospector::CheckSuccess(), Command_spawn(), Command_spawnn(), PlanetSE::CreateCustomsOffice(), MissionDataMgr::CreateMissionOffer(), SystemEntity::DropLoot(), Prospector::DropSalvage(), Client::Eject(), GenerateKey(), Agent::GetAcceptRsp(), EntityList::GetAnomalyID(), SystemGPoint::GetAnomalyPoint(), Agent::GetCompleteRsp(), Agent::GetDeclineRsp(), AnomalyMgr::GetDungeonType(), StaticDataMgr::GetLoot(), MapData::GetMissionDestination(), SystemManager::GetRandBeltID(), ModuleManager::GetRandModule(), SystemGPoint::GetRandMoon(), SystemGPoint::GetRandPlanet(), SystemGPoint::GetRandPointOnMoon(), SystemGPoint::GetRandPointOnPlanet(), StaticDataMgr::GetRandRatType(), FleetService::GetRandUnitIDs(), Agent::GetStandingsRsp(), CustomsSE::Killed(), StructureSE::Killed(), ShipSE::Killed(), PlanetSE::LoadExtras(), DungeonMgr::MakeDungeon(), SpawnMgr::MakeSpawn(), SpawnMgr::PrepSpawn(), SpawnMgr::ReSpawn(), SystemBubble::SetSpawnTimer(), NPCAIMgr::SetWander(), and BeltMgr::SpawnBelt().

110 {
111  return (int64)MakeRandomFloat( (double)low, (double)high );
112 }
double MakeRandomFloat(double low, double high)
Generates random real from interval [low; high].
Definition: misc.cpp:114
signed __int64 int64
Definition: eve-compat.h:51

Here is the call graph for this function:

Here is the caller graph for this function:

int64 npowof2 ( int64  num)

Calculates next (greater or equal) power-of-two number.

Parameters
[in]numBase number.
Returns
Power-of-two number which is greater than or equal to the base number.

Definition at line 95 of file misc.cpp.

Referenced by Buffer::_CalcBufferCapacity().

96 {
97  --num;
98  num |= ( num >> 1 );
99  num |= ( num >> 2 );
100  num |= ( num >> 4 );
101  num |= ( num >> 8 );
102  num |= ( num >> 16 );
103  num |= ( num >> 32 );
104  ++num;
105 
106  return num;
107 }

Here is the caller graph for this function: