mirror of
https://github.com/minetest/minetest.git
synced 2024-12-24 23:22:24 +01:00
Add player:override_day_night_ratio() for arbitrarily controlling sunlight brightness
This commit is contained in:
parent
86a6cca3cf
commit
6a3fa9df12
@ -1820,6 +1820,9 @@ Player-only: (no-op for other objects)
|
|||||||
- "plain": Uses 0 textures, bgcolor used
|
- "plain": Uses 0 textures, bgcolor used
|
||||||
^ Note: currently does not work directly in on_joinplayer; use
|
^ Note: currently does not work directly in on_joinplayer; use
|
||||||
minetest.after(0) in there.
|
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
|
InvRef: Reference to an inventory
|
||||||
methods:
|
methods:
|
||||||
|
@ -2045,6 +2045,20 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
|||||||
event.set_sky.params = params;
|
event.set_sky.params = params;
|
||||||
m_client_event_queue.push_back(event);
|
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
|
else
|
||||||
{
|
{
|
||||||
infostream<<"Client: Ignoring unknown command "
|
infostream<<"Client: Ignoring unknown command "
|
||||||
|
@ -135,6 +135,7 @@ enum ClientEventType
|
|||||||
CE_HUDRM,
|
CE_HUDRM,
|
||||||
CE_HUDCHANGE,
|
CE_HUDCHANGE,
|
||||||
CE_SET_SKY,
|
CE_SET_SKY,
|
||||||
|
CE_OVERRIDE_DAY_NIGHT_RATIO,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ClientEvent
|
struct ClientEvent
|
||||||
@ -223,6 +224,10 @@ struct ClientEvent
|
|||||||
std::string *type;
|
std::string *type;
|
||||||
std::vector<std::string> *params;
|
std::vector<std::string> *params;
|
||||||
} set_sky;
|
} set_sky;
|
||||||
|
struct{
|
||||||
|
bool do_override;
|
||||||
|
float ratio_f;
|
||||||
|
} override_day_night_ratio;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -519,6 +519,13 @@ enum ToClientCommand
|
|||||||
u8 len
|
u8 len
|
||||||
u8[len] param
|
u8[len] param
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
TOCLIENT_OVERRIDE_DAY_NIGHT_RATIO = 0x50,
|
||||||
|
/*
|
||||||
|
u16 command
|
||||||
|
u8 do_override (boolean)
|
||||||
|
u16 day-night ratio 0...65535
|
||||||
|
*/
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ToServerCommand
|
enum ToServerCommand
|
||||||
|
@ -49,7 +49,9 @@ Environment::Environment():
|
|||||||
m_time_of_day(9000),
|
m_time_of_day(9000),
|
||||||
m_time_of_day_f(9000./24000),
|
m_time_of_day_f(9000./24000),
|
||||||
m_time_of_day_speed(0),
|
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)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,6 +192,8 @@ std::list<Player*> Environment::getPlayers(bool ignore_disconnected)
|
|||||||
|
|
||||||
u32 Environment::getDayNightRatio()
|
u32 Environment::getDayNightRatio()
|
||||||
{
|
{
|
||||||
|
if(m_enable_day_night_ratio_override)
|
||||||
|
return m_day_night_ratio_override;
|
||||||
bool smooth = g_settings->getBool("enable_shaders");
|
bool smooth = g_settings->getBool("enable_shaders");
|
||||||
return time_to_daynight_ratio(m_time_of_day_f*24000, smooth);
|
return time_to_daynight_ratio(m_time_of_day_f*24000, smooth);
|
||||||
}
|
}
|
||||||
|
@ -100,6 +100,12 @@ public:
|
|||||||
float getTimeOfDaySpeed()
|
float getTimeOfDaySpeed()
|
||||||
{ return m_time_of_day_speed; }
|
{ 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:
|
protected:
|
||||||
// peer_ids in here should be unique, except that there may be many 0s
|
// peer_ids in here should be unique, except that there may be many 0s
|
||||||
std::list<Player*> m_players;
|
std::list<Player*> m_players;
|
||||||
@ -110,6 +116,9 @@ protected:
|
|||||||
float m_time_of_day_speed;
|
float m_time_of_day_speed;
|
||||||
// Used to buffer dtime for adding to m_time_of_day
|
// Used to buffer dtime for adding to m_time_of_day
|
||||||
float m_time_counter;
|
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -2498,6 +2498,12 @@ void the_game(
|
|||||||
delete event.set_sky.type;
|
delete event.set_sky.type;
|
||||||
delete event.set_sky.params;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1129,6 +1129,28 @@ int ObjectRef::l_set_sky(lua_State *L)
|
|||||||
return 1;
|
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):
|
ObjectRef::ObjectRef(ServerActiveObject *object):
|
||||||
m_object(object)
|
m_object(object)
|
||||||
{
|
{
|
||||||
@ -1247,5 +1269,6 @@ const luaL_reg ObjectRef::methods[] = {
|
|||||||
luamethod(ObjectRef, hud_set_hotbar_image),
|
luamethod(ObjectRef, hud_set_hotbar_image),
|
||||||
luamethod(ObjectRef, hud_set_hotbar_selected_image),
|
luamethod(ObjectRef, hud_set_hotbar_selected_image),
|
||||||
luamethod(ObjectRef, set_sky),
|
luamethod(ObjectRef, set_sky),
|
||||||
|
luamethod(ObjectRef, override_day_night_ratio),
|
||||||
{0,0}
|
{0,0}
|
||||||
};
|
};
|
||||||
|
@ -228,6 +228,9 @@ private:
|
|||||||
// set_sky(self, type, list)
|
// set_sky(self, type, list)
|
||||||
static int l_set_sky(lua_State *L);
|
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:
|
public:
|
||||||
ObjectRef(ServerActiveObject *object);
|
ObjectRef(ServerActiveObject *object);
|
||||||
|
|
||||||
|
@ -3291,6 +3291,23 @@ void Server::SendSetSky(u16 peer_id, const video::SColor &bgcolor,
|
|||||||
m_clients.send(peer_id, 0, data, true);
|
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)
|
void Server::SendTimeOfDay(u16 peer_id, u16 time, f32 time_speed)
|
||||||
{
|
{
|
||||||
DSTACK(__FUNCTION_NAME);
|
DSTACK(__FUNCTION_NAME);
|
||||||
@ -4465,6 +4482,16 @@ bool Server::setSky(Player *player, const video::SColor &bgcolor,
|
|||||||
return true;
|
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)
|
void Server::notifyPlayers(const std::wstring msg)
|
||||||
{
|
{
|
||||||
SendChatMessage(PEER_ID_INEXISTENT,msg);
|
SendChatMessage(PEER_ID_INEXISTENT,msg);
|
||||||
|
@ -323,6 +323,9 @@ public:
|
|||||||
bool setSky(Player *player, const video::SColor &bgcolor,
|
bool setSky(Player *player, const video::SColor &bgcolor,
|
||||||
const std::string &type, const std::vector<std::string> ¶ms);
|
const std::string &type, const std::vector<std::string> ¶ms);
|
||||||
|
|
||||||
|
bool overrideDayNightRatio(Player *player, bool do_override,
|
||||||
|
float brightness);
|
||||||
|
|
||||||
/* con::PeerHandler implementation. */
|
/* con::PeerHandler implementation. */
|
||||||
void peerAdded(con::Peer *peer);
|
void peerAdded(con::Peer *peer);
|
||||||
void deletingPeer(con::Peer *peer, bool timeout);
|
void deletingPeer(con::Peer *peer, bool timeout);
|
||||||
@ -360,6 +363,7 @@ private:
|
|||||||
void SendHUDSetParam(u16 peer_id, u16 param, const std::string &value);
|
void SendHUDSetParam(u16 peer_id, u16 param, const std::string &value);
|
||||||
void SendSetSky(u16 peer_id, const video::SColor &bgcolor,
|
void SendSetSky(u16 peer_id, const video::SColor &bgcolor,
|
||||||
const std::string &type, const std::vector<std::string> ¶ms);
|
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.
|
Send a node removal/addition event to all clients except ignore_id.
|
||||||
|
Loading…
Reference in New Issue
Block a user