feat: changed random engine
This commit is contained in:
@@ -1,12 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <random>
|
||||
|
||||
namespace td {
|
||||
namespace utils {
|
||||
|
||||
void initRandomizer();
|
||||
std::uint64_t getRandomNumber(std::uint64_t max);
|
||||
template<typename NumberType>
|
||||
NumberType getRandomInt(NumberType min, NumberType max){
|
||||
std::random_device randomDevice;
|
||||
std::mt19937 generator(randomDevice());
|
||||
std::uniform_int_distribution<NumberType> distrib(min, max);
|
||||
return distrib(generator);
|
||||
}
|
||||
|
||||
template<typename NumberType>
|
||||
NumberType getRandomReal(NumberType min, NumberType max){
|
||||
std::random_device randomDevice;
|
||||
std::mt19937 generator(randomDevice());
|
||||
std::uniform_real_distribution<NumberType> distrib(min, max);
|
||||
return distrib(generator);
|
||||
}
|
||||
|
||||
} // namespace utils
|
||||
} // namespace td
|
||||
|
||||
@@ -7,14 +7,12 @@
|
||||
//============================================================================
|
||||
|
||||
#include "window/Display.h"
|
||||
#include "misc/Random.h"
|
||||
|
||||
#ifdef __ANDROID__
|
||||
extern "C"
|
||||
#endif
|
||||
|
||||
int main(int argc, const char* args[]) {
|
||||
td::utils::initRandomizer();
|
||||
Display::create();
|
||||
while (!Display::isCloseRequested()) {
|
||||
Display::pollEvents();
|
||||
|
||||
@@ -62,7 +62,7 @@ void ServerConnexion::checkKeepAlive() {
|
||||
}
|
||||
|
||||
void ServerConnexion::sendKeepAlive() {
|
||||
m_KeepAlive.keepAliveID = utils::getRandomNumber(RAND_MAX);
|
||||
m_KeepAlive.keepAliveID = utils::getRandomInt<std::uint64_t>(0, RAND_MAX);
|
||||
m_KeepAlive.recievedResponse = false;
|
||||
|
||||
protocol::KeepAlivePacket keepAlivePacket(m_KeepAlive.keepAliveID);
|
||||
|
||||
@@ -31,11 +31,8 @@ void ServerWorld::spawnMobs(game::MobType type, std::uint8_t level, game::Player
|
||||
std::int32_t minSpawnX = spawnCenterX - 2;
|
||||
std::int32_t maxSpawnX = spawnCenterX + 2;
|
||||
|
||||
std::uint64_t randomX = utils::getRandomNumber(std::abs(minSpawnX - maxSpawnX) * MOB_SPAWN_PRECISION);
|
||||
float mobX = (float)randomX / MOB_SPAWN_PRECISION + (float)minSpawnX;
|
||||
|
||||
std::uint64_t randomY = utils::getRandomNumber(std::abs(minSpawnY - maxSpawnY) * MOB_SPAWN_PRECISION);
|
||||
float mobY = (float)randomY / MOB_SPAWN_PRECISION + (float)minSpawnY;
|
||||
float mobX = utils::getRandomReal<float>(minSpawnX, maxSpawnX);
|
||||
float mobY = utils::getRandomReal<float>(minSpawnY, maxSpawnY);
|
||||
|
||||
spawnMobAt(m_CurrentMobID, type, level, sender, mobX, mobY, enemyMobSpawn->direction);
|
||||
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
#include "misc/Random.h"
|
||||
#include <random>
|
||||
#include <ctime>
|
||||
|
||||
namespace td {
|
||||
namespace utils {
|
||||
|
||||
void initRandomizer() {
|
||||
srand(time(0));
|
||||
}
|
||||
|
||||
std::uint64_t getRandomNumber(std::uint64_t max) {
|
||||
return rand() % max;
|
||||
}
|
||||
|
||||
} // namespace utils
|
||||
} // namespace td
|
||||
Reference in New Issue
Block a user