Skip to content

Commit

Permalink
Timecycle Randomizer: Make less random because people no like
Browse files Browse the repository at this point in the history
* The Timecycle Randomizer now uses all available presets to randomize
  the timecycle instead of only the one mentioned in the config file.

  Currently, the option in the config does nothing, eventually it will
  be made a list of presets to choose from.

* There's now an option to have randomisation of the time sample a
  certain percent of the time when the timecycle is not supposed to be
  random.

* Extensively document the timecycle randomizer config options for
  timecycle randomizer haters. 👍
  • Loading branch information
Parik27 committed Oct 30, 2021
1 parent 2b758e6 commit 05bab1f
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build-count.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
485
491
18 changes: 16 additions & 2 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,23 @@ LogSpawnedVehicles = false # Logs all the spawned script vehicles
[WeatherRandomizer]

RandomizeWeather = true # Randomize the weather (properties like sun, rain, etc.)

RandomizeTimecycle = true # Randomize the appearance of the sky/ground.
RandomizeTimecycleOdds = 40

#######################################################
# """"FILTER/LIGHTING""""" HATERS LOOK HERE (Spoiler Alert: There's no """FILTER""")
#######################################################
# These control how random the timecycles are gonna be.

# The first setting is how many times out of 100 the sky is gonna be randomised through presets.
# So this includes everything from just the skies having random moons all the way to crazy wacky super-dark pink sky
RandomizeTimecycleOdds = 25

# This second setting is how many times out of 100 (WHEN THE TIMECYCLE IS NOT RANDOM),
# the non-randomized timecycle uses a timesample from a different NORMAL timecycle.
# So if it's supposed to be clear and night time, it may be cloudy and day time.
RandomizeTimeOdds = 75

#######################################################

TunableFile = "Timecyc/Default.txt"

Expand Down
1 change: 1 addition & 0 deletions lib/Random.hh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <iterator>
#include <random>
#include <ctime>

template <typename Engine = std::mt19937> class RandomUtils
{
Expand Down
18 changes: 16 additions & 2 deletions src/common/configDefault.hh
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,23 @@ LogSpawnedVehicles = false # Logs all the spawned script vehicles
[WeatherRandomizer]
RandomizeWeather = true # Randomize the weather (properties like sun, rain, etc.)
RandomizeTimecycle = true # Randomize the appearance of the sky/ground.
RandomizeTimecycleOdds = 40
#######################################################
# """"FILTER/LIGHTING""""" HATERS LOOK HERE (Spoiler Alert: There's no """FILTER""")
#######################################################
# These control how random the timecycles are gonna be.
# The first setting is how many times out of 100 the sky is gonna be randomised through presets.
# So this includes everything from just the skies having random moons all the way to crazy wacky super-dark pink sky
RandomizeTimecycleOdds = 25
# This second setting is how many times out of 100 (WHEN THE TIMECYCLE IS NOT RANDOM),
# the non-randomized timecycle uses a timesample from a different NORMAL timecycle.
# So if it's supposed to be clear and night time, it may be cloudy and day time.
RandomizeTimeOdds = 75
#######################################################
TunableFile = "Timecyc/Default.txt"
Expand Down
15 changes: 13 additions & 2 deletions src/misc/weather.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class WeatherRandomizer
bool RandomizeTimecycle = true;
bool CrazyMode = false;
bool RandomizeEveryFade = true;
double RandomizeTimeOdds = 80.0;
double RandomizeTimecycleOdds = 80.0;
std::string TunableFile = "Timecyc/Default.txt";
} sm_Config;
Expand Down Expand Up @@ -108,15 +109,24 @@ class WeatherRandomizer
if (future.valid ())
future.wait ();

static std::array TimecyclePresets = {
"Timecyc/Default.txt",
"Timecyc/Alternative.txt",
"Timecyc/SkyAndColours.txt",
"Timecyc/SkyOnly.txt",
};

future = std::async (std::launch::async, [restoreTimecycles] {
if (restoreTimecycles)
WeatherRandomizer_TunableManager::RestoreOriginalTimecycles ();

WeatherRandomizer_TunableManager::Initialise (
Config ().TunableFile);
GetRandomElement (TimecyclePresets));

if (RandomFloat (1000) < Config ().RandomizeTimecycleOdds * 10.0f)
WeatherRandomizer_TunableManager::Randomize ();
WeatherRandomizer_TunableManager::Randomize ();
else if (RandomFloat (1000) < Config ().RandomizeTimeOdds * 10.0f)
WeatherRandomizer_TunableManager::RandomizeTimesamples ();
});
}

Expand All @@ -131,6 +141,7 @@ class WeatherRandomizer
std::pair ("TunableFile", &Config ().TunableFile),
std::pair ("RandomizeTimecycleOdds",
&Config ().RandomizeTimecycleOdds),
std::pair ("RandomizeTimeOdds", &Config ().RandomizeTimeOdds),
std::pair ("RandomizeEveryFade",
&Config ().RandomizeEveryFade)))
return;
Expand Down
26 changes: 26 additions & 0 deletions src/misc/weather_Timecycle.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <time.h>
#include <vector>
#include <array>
#include <numeric>

struct WeatherRandomizer_Tunables
{
Expand Down Expand Up @@ -361,6 +362,31 @@ public:
RestoreTimecycle (tcManager::g_timeCycle->pTimecycles[i], i);
}

static void
RandomizeTimesamples ()
{
int NUM_TIMESAMPLES = tcConfig::ms_cycleInfo->Size * 2 * 13;

std::vector<int> v (NUM_TIMESAMPLES);
std::iota (std::begin (v), std::end (v), 0);
std::shuffle (std::begin (v), std::end (v),
WeatherRandomizer_Tunables::sm_Random.GetEngine ());

auto convertTimesamplesToPtr = [] (int idx) {
int timecycle = idx / 26;
int offset = idx % 26;
return (&tcManager::g_timeCycle->pTimecycles[timecycle]
.Regions[0]
.TimeSamples[0])
+ offset;
};

for (int i = 0; i < NUM_TIMESAMPLES; i++)
{
*convertTimesamplesToPtr (i) = *convertTimesamplesToPtr (v[i]);
}
}

static WeatherRandomizer_Tunables &
GetTunable ()
{
Expand Down

0 comments on commit 05bab1f

Please sign in to comment.