diff --git a/CMakeLists.txt b/CMakeLists.txt index fe22c0526..387ecf6da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -125,6 +125,7 @@ add_executable( ${OBSIDIAN_SOURCE_FILES} ) +target_include_directories(obsidian SYSTEM PRIVATE libraries/fastPRNG) if(NOT CONSOLE_ONLY) target_include_directories(obsidian SYSTEM PRIVATE libraries/fltk) target_include_directories( diff --git a/source/sys_xoshiro.cc b/source/sys_xoshiro.cc index 82ecebff2..b651bc220 100644 --- a/source/sys_xoshiro.cc +++ b/source/sys_xoshiro.cc @@ -1,15 +1,24 @@ -/* -Xoshiro256 Random Generator - -By Dashodanger, 2020 - -This is meant to be a replacement for the AJ_Random library that -uses the fastPRNG xoshiro256 implementation for random number generation. -Usage will be as similar to AJ_Random as possible in order to minimize -changes in other sections of code. -*/ - -#include "../fastPRNG/fastPRNG.h" +//------------------------------------------------------------------------ +// RANDOM NUMBER GENERATION (Xoshiro256) +//------------------------------------------------------------------------ +// +// OBSIDIAN Level Maker +// +// Copyright (C) 2020-2024 The OBSIDIAN Team +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +//------------------------------------------------------------------------ + +#include "fastPRNG.h" fastPRNG::fastXS64 xoshiro; @@ -20,12 +29,12 @@ void xoshiro_Reseed(uint64_t newseed) uint64_t xoshiro_UInt() { - int64_t rand_num = (int64_t)(xoshiro.xoshiro256p()); - if (rand_num >= 0) - { - return rand_num; - } - return -rand_num; + return xoshiro.xoshiro256p(); +} + +float xoshiro_Float() +{ + return xoshiro.xoshiro256p_UNI(); } double xoshiro_Double() @@ -33,9 +42,12 @@ double xoshiro_Double() return xoshiro.xoshiro256p_UNI(); } -// This probably isn't super efficient, but it is rarely used and shouldn't make -// a huge overall hit to performance - Dasho int xoshiro_Between(int low, int high) { - return (int)(xoshiro.xoshiro256p_Range(low, high)); + return (int)xoshiro.xoshiro256p_Range(low, high); +} + +double xoshiro_Between(double low, double high) +{ + return xoshiro.xoshiro256p_Range(low, high); } diff --git a/source/sys_xoshiro.h b/source/sys_xoshiro.h index a0408ca14..e5a612da2 100644 --- a/source/sys_xoshiro.h +++ b/source/sys_xoshiro.h @@ -1,15 +1,32 @@ -// Xoshiro256 Random Generator +//------------------------------------------------------------------------ +// RANDOM NUMBER GENERATION (Xoshiro256) +//------------------------------------------------------------------------ +// +// OBSIDIAN Level Maker +// +// Copyright (C) 2020-2024 The OBSIDIAN Team +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +//------------------------------------------------------------------------ #pragma once -#include "../../libraries/fastPRNG/fastPRNG.h" - -extern fastPRNG::fastXS64 xoshiro; - void xoshiro_Reseed(uint64_t newseed); uint64_t xoshiro_UInt(); +// These return in the range of 0.0f-1.0f/0.0-1.0 +float xoshiro_Float(); double xoshiro_Double(); int xoshiro_Between(int low, int high); +double xoshiro_Between(double low, double high); \ No newline at end of file diff --git a/source/ui_module.cc b/source/ui_module.cc index e3b6782fe..6c1513438 100644 --- a/source/ui_module.cc +++ b/source/ui_module.cc @@ -595,7 +595,7 @@ void UI_Module::randomize_Values(std::vector selected_randomize_gro M->nan_options->do_callback(); } M->mod_slider->value(M->mod_slider->round( - xoshiro.xoshiro256p_Range(M->mod_slider->minimum(), M->mod_slider->maximum()))); + xoshiro_Between(M->mod_slider->minimum(), M->mod_slider->maximum()))); M->mod_slider->do_callback(); break; } @@ -610,7 +610,7 @@ void UI_Module::randomize_Values(std::vector selected_randomize_gro { if (StringCompare(group, M->randomize_group) == 0) { - if (xoshiro.xoshiro256p_UNI() < 0.5) + if (xoshiro_Float() < 0.5) { M->mod_check->value(0); }