ref set/get_vel_time()

This commit is contained in:
Cogi Asd
2024-07-08 12:26:01 +03:00
parent aed072d3b0
commit 42b753d485
3 changed files with 11 additions and 8 deletions
+8 -3
View File
@@ -54,12 +54,16 @@ static int l_world_set_day_time(lua::State* L) {
return 0; return 0;
} }
static int l_wolrd_set_speed_time(lua::State* L) { static int l_wolrd_set_vel_time(lua::State* L) {
auto value = lua::tonumber(L, 1); auto value = lua::tonumber(L, 1);
level->getWorld()->factorSpeedTime = std::abs(value); level->getWorld()->daytimeSpeed = std::abs(value);
return 0; return 0;
} }
static int l_wolrd_get_vel_time(lua::State* L) {
return lua::pushnumber(L, level->getWorld()->daytimeSpeed);
}
static int l_world_get_seed(lua::State* L) { static int l_world_get_seed(lua::State* L) {
return lua::pushinteger(L, level->getWorld()->getSeed()); return lua::pushinteger(L, level->getWorld()->getSeed());
} }
@@ -85,7 +89,8 @@ const luaL_Reg worldlib [] = {
{"get_total_time", lua::wrap<l_world_get_total_time>}, {"get_total_time", lua::wrap<l_world_get_total_time>},
{"get_day_time", lua::wrap<l_world_get_day_time>}, {"get_day_time", lua::wrap<l_world_get_day_time>},
{"set_day_time", lua::wrap<l_world_set_day_time>}, {"set_day_time", lua::wrap<l_world_set_day_time>},
{"set_speed_time", lua::wrap<l_wolrd_set_speed_time>}, {"set_vel_time", lua::wrap<l_wolrd_set_vel_time>},
{"get_vel_time", lua::wrap<l_wolrd_get_vel_time>},
{"get_seed", lua::wrap<l_world_get_seed>}, {"get_seed", lua::wrap<l_world_get_seed>},
{"is_day", lua::wrap<l_world_is_day>}, {"is_day", lua::wrap<l_world_is_day>},
{"is_night", lua::wrap<l_world_is_night>}, {"is_night", lua::wrap<l_world_is_night>},
+2 -1
View File
@@ -19,6 +19,7 @@
#include <utility> #include <utility>
static debug::Logger logger("world"); static debug::Logger logger("world");
const float DAYIME_SPECIFIC_SPEED = 1.0f/1440.0f; //1.0f/60.0f/24.0f;
world_load_error::world_load_error(const std::string& message) world_load_error::world_load_error(const std::string& message)
: std::runtime_error(message) { : std::runtime_error(message) {
@@ -44,7 +45,7 @@ World::~World(){
} }
void World::updateTimers(float delta) { void World::updateTimers(float delta) {
daytime += delta * daytimeSpeed * factorSpeedTime; daytime += delta * daytimeSpeed * DAYIME_SPECIFIC_SPEED;
daytime = fmod(daytime, 1.0f); daytime = fmod(daytime, 1.0f);
totalTime += delta; totalTime += delta;
} }
+1 -4
View File
@@ -42,11 +42,8 @@ public:
/// 0.5 - is noon /// 0.5 - is noon
float daytime = timeutil::time_value(10, 00, 00); float daytime = timeutil::time_value(10, 00, 00);
// factor speed time
float factorSpeedTime = 1.0f;
// looking bad // looking bad
float daytimeSpeed = 1.0f/1440.0f; //1.0f/60.0f/24.0f; float daytimeSpeed = 1.0f;
/// @brief total time passed in the world (not depending on daytimeSpeed) /// @brief total time passed in the world (not depending on daytimeSpeed)
double totalTime = 0.0; double totalTime = 0.0;