- "plain": Uses 0 textures, bgcolor used
^ Note: currently does not work directly in on_joinplayer; use
minetest.after(0) in there.
+- override_day_night_ratio(ratio or nil)
+ ^ 0...1: Overrides day-night ratio, controlling sunlight to a specific amount
+ ^ nil: Disables override, defaulting to sunlight based on day-night cycle
InvRef: Reference to an inventory
methods:
event.set_sky.params = params;
m_client_event_queue.push_back(event);
}
+ else if(command == TOCLIENT_OVERRIDE_DAY_NIGHT_RATIO)
+ {
+ std::string datastring((char *)&data[2], datasize - 2);
+ std::istringstream is(datastring, std::ios_base::binary);
+
+ bool do_override = readU8(is);
+ float day_night_ratio_f = (float)readU16(is) / 65536;
+
+ ClientEvent event;
+ event.type = CE_OVERRIDE_DAY_NIGHT_RATIO;
+ event.override_day_night_ratio.do_override = do_override;
+ event.override_day_night_ratio.ratio_f = day_night_ratio_f;
+ m_client_event_queue.push_back(event);
+ }
else
{
infostream<<"Client: Ignoring unknown command "
CE_HUDRM,
CE_HUDCHANGE,
CE_SET_SKY,
+ CE_OVERRIDE_DAY_NIGHT_RATIO,
};
struct ClientEvent
std::string *type;
std::vector<std::string> *params;
} set_sky;
+ struct{
+ bool do_override;
+ float ratio_f;
+ } override_day_night_ratio;
};
};
u8 len
u8[len] param
*/
+
+ TOCLIENT_OVERRIDE_DAY_NIGHT_RATIO = 0x50,
+ /*
+ u16 command
+ u8 do_override (boolean)
+ u16 day-night ratio 0...65535
+ */
};
enum ToServerCommand
m_time_of_day(9000),
m_time_of_day_f(9000./24000),
m_time_of_day_speed(0),
- m_time_counter(0)
+ m_time_counter(0),
+ m_enable_day_night_ratio_override(false),
+ m_day_night_ratio_override(0.0f)
{
}
u32 Environment::getDayNightRatio()
{
+ if(m_enable_day_night_ratio_override)
+ return m_day_night_ratio_override;
bool smooth = g_settings->getBool("enable_shaders");
return time_to_daynight_ratio(m_time_of_day_f*24000, smooth);
}
std::list<Player*> getPlayers(bool ignore_disconnected);
u32 getDayNightRatio();
-
+
// 0-23999
virtual void setTimeOfDay(u32 time)
{
float getTimeOfDaySpeed()
{ return m_time_of_day_speed; }
+ void setDayNightRatioOverride(bool enable, u32 value)
+ {
+ m_enable_day_night_ratio_override = enable;
+ m_day_night_ratio_override = value;
+ }
+
protected:
// peer_ids in here should be unique, except that there may be many 0s
std::list<Player*> m_players;
float m_time_of_day_speed;
// Used to buffer dtime for adding to m_time_of_day
float m_time_counter;
+ // Overriding the day-night ratio is useful for custom sky visuals
+ bool m_enable_day_night_ratio_override;
+ u32 m_day_night_ratio_override;
};
/*
delete event.set_sky.type;
delete event.set_sky.params;
}
+ else if (event.type == CE_OVERRIDE_DAY_NIGHT_RATIO)
+ {
+ bool enable = event.override_day_night_ratio.do_override;
+ u32 value = event.override_day_night_ratio.ratio_f * 1000;
+ client.getEnv().setDayNightRatioOverride(enable, value);
+ }
}
}
return 1;
}
+// override_day_night_ratio(self, brightness=0...1)
+int ObjectRef::l_override_day_night_ratio(lua_State *L)
+{
+ ObjectRef *ref = checkobject(L, 1);
+ Player *player = getplayer(ref);
+ if (player == NULL)
+ return 0;
+
+ bool do_override = false;
+ float ratio = 0.0f;
+ if (!lua_isnil(L, 2)){
+ do_override = true;
+ ratio = luaL_checknumber(L, 2);
+ }
+
+ if (!getServer(L)->overrideDayNightRatio(player, do_override, ratio))
+ return 0;
+
+ lua_pushboolean(L, true);
+ return 1;
+}
+
ObjectRef::ObjectRef(ServerActiveObject *object):
m_object(object)
{
luamethod(ObjectRef, hud_set_hotbar_image),
luamethod(ObjectRef, hud_set_hotbar_selected_image),
luamethod(ObjectRef, set_sky),
+ luamethod(ObjectRef, override_day_night_ratio),
{0,0}
};
// set_sky(self, type, list)
static int l_set_sky(lua_State *L);
+ // override_day_night_ratio(self, type, list)
+ static int l_override_day_night_ratio(lua_State *L);
+
public:
ObjectRef(ServerActiveObject *object);
m_clients.send(peer_id, 0, data, true);
}
+void Server::SendOverrideDayNightRatio(u16 peer_id, bool do_override,
+ float ratio)
+{
+ std::ostringstream os(std::ios_base::binary);
+
+ // Write command
+ writeU16(os, TOCLIENT_OVERRIDE_DAY_NIGHT_RATIO);
+ writeU8(os, do_override);
+ writeU16(os, ratio*65535);
+
+ // Make data buffer
+ std::string s = os.str();
+ SharedBuffer<u8> data((u8 *)s.c_str(), s.size());
+ // Send as reliable
+ m_clients.send(peer_id, 0, data, true);
+}
+
void Server::SendTimeOfDay(u16 peer_id, u16 time, f32 time_speed)
{
DSTACK(__FUNCTION_NAME);
return true;
}
+bool Server::overrideDayNightRatio(Player *player, bool do_override,
+ float ratio)
+{
+ if (!player)
+ return false;
+
+ SendOverrideDayNightRatio(player->peer_id, do_override, ratio);
+ return true;
+}
+
void Server::notifyPlayers(const std::wstring msg)
{
SendChatMessage(PEER_ID_INEXISTENT,msg);
bool setSky(Player *player, const video::SColor &bgcolor,
const std::string &type, const std::vector<std::string> ¶ms);
+
+ bool overrideDayNightRatio(Player *player, bool do_override,
+ float brightness);
/* con::PeerHandler implementation. */
void peerAdded(con::Peer *peer);
void SendHUDSetParam(u16 peer_id, u16 param, const std::string &value);
void SendSetSky(u16 peer_id, const video::SColor &bgcolor,
const std::string &type, const std::vector<std::string> ¶ms);
+ void SendOverrideDayNightRatio(u16 peer_id, bool do_override, float ratio);
/*
Send a node removal/addition event to all clients except ignore_id.