mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-02 16:38:41 +00:00
set_sky improvements, set_sun, set_moon and set_stars
This commit is contained in:
parent
580e7e8eb9
commit
946c03c69b
19 changed files with 1525 additions and 400 deletions
|
@ -40,6 +40,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "util/srp.h"
|
||||
#include "tileanimation.h"
|
||||
#include "gettext.h"
|
||||
#include "skyparams.h"
|
||||
|
||||
void Client::handleCommand_Deprecated(NetworkPacket* pkt)
|
||||
{
|
||||
|
@ -1233,28 +1234,132 @@ void Client::handleCommand_HudSetParam(NetworkPacket* pkt)
|
|||
|
||||
void Client::handleCommand_HudSetSky(NetworkPacket* pkt)
|
||||
{
|
||||
std::string datastring(pkt->getString(0), pkt->getSize());
|
||||
std::istringstream is(datastring, std::ios_base::binary);
|
||||
if (m_proto_ver < 39) {
|
||||
// Handle Protocol 38 and below servers with old set_sky,
|
||||
// ensuring the classic look is kept.
|
||||
std::string datastring(pkt->getString(0), pkt->getSize());
|
||||
std::istringstream is(datastring, std::ios_base::binary);
|
||||
|
||||
video::SColor *bgcolor = new video::SColor(readARGB8(is));
|
||||
std::string *type = new std::string(deSerializeString(is));
|
||||
u16 count = readU16(is);
|
||||
std::vector<std::string> *params = new std::vector<std::string>;
|
||||
SkyboxParams skybox;
|
||||
skybox.bgcolor = video::SColor(readARGB8(is));
|
||||
skybox.type = std::string(deSerializeString(is));
|
||||
u16 count = readU16(is);
|
||||
std::vector<std::string>* params = new std::vector<std::string>;
|
||||
|
||||
for (size_t i = 0; i < count; i++)
|
||||
params->push_back(deSerializeString(is));
|
||||
for (size_t i = 0; i < count; i++)
|
||||
skybox.textures.emplace_back(deSerializeString(is));
|
||||
|
||||
bool clouds = true;
|
||||
try {
|
||||
clouds = readU8(is);
|
||||
} catch (...) {}
|
||||
bool clouds = true;
|
||||
try {
|
||||
skybox.clouds = readU8(is);
|
||||
} catch (...) {}
|
||||
|
||||
// Use default skybox settings:
|
||||
SkyboxDefaults sky_defaults;
|
||||
SunParams sun = sky_defaults.getSunDefaults();
|
||||
MoonParams moon = sky_defaults.getMoonDefaults();
|
||||
StarParams stars = sky_defaults.getStarDefaults();
|
||||
|
||||
// Fix for "regular" skies, as color isn't kept:
|
||||
if (skybox.type == "regular") {
|
||||
skybox.sky_color = sky_defaults.getSkyColorDefaults();
|
||||
skybox.tint_type = "default";
|
||||
skybox.moon_tint = video::SColor(255, 255, 255, 255);
|
||||
skybox.sun_tint = video::SColor(255, 255, 255, 255);
|
||||
}
|
||||
else {
|
||||
sun.visible = false;
|
||||
sun.sunrise_visible = false;
|
||||
moon.visible = false;
|
||||
stars.visible = false;
|
||||
}
|
||||
|
||||
// Skybox, sun, moon and stars ClientEvents:
|
||||
ClientEvent *sky_event = new ClientEvent();
|
||||
sky_event->type = CE_SET_SKY;
|
||||
sky_event->set_sky = new SkyboxParams(skybox);
|
||||
m_client_event_queue.push(sky_event);
|
||||
|
||||
ClientEvent *sun_event = new ClientEvent();
|
||||
sun_event->type = CE_SET_SUN;
|
||||
sun_event->sun_params = new SunParams(sun);
|
||||
m_client_event_queue.push(sun_event);
|
||||
|
||||
ClientEvent *moon_event = new ClientEvent();
|
||||
moon_event->type = CE_SET_MOON;
|
||||
moon_event->moon_params = new MoonParams(moon);
|
||||
m_client_event_queue.push(moon_event);
|
||||
|
||||
ClientEvent *star_event = new ClientEvent();
|
||||
star_event->type = CE_SET_STARS;
|
||||
star_event->star_params = new StarParams(stars);
|
||||
m_client_event_queue.push(star_event);
|
||||
} else {
|
||||
SkyboxParams skybox;
|
||||
u16 texture_count;
|
||||
std::string texture;
|
||||
|
||||
*pkt >> skybox.bgcolor >> skybox.type >> skybox.clouds >>
|
||||
skybox.sun_tint >> skybox.moon_tint >> skybox.tint_type;
|
||||
|
||||
if (skybox.type == "skybox") {
|
||||
*pkt >> texture_count;
|
||||
for (int i = 0; i < texture_count; i++) {
|
||||
*pkt >> texture;
|
||||
skybox.textures.emplace_back(texture);
|
||||
}
|
||||
}
|
||||
else if (skybox.type == "regular") {
|
||||
*pkt >> skybox.sky_color.day_sky >> skybox.sky_color.day_horizon
|
||||
>> skybox.sky_color.dawn_sky >> skybox.sky_color.dawn_horizon
|
||||
>> skybox.sky_color.night_sky >> skybox.sky_color.night_horizon
|
||||
>> skybox.sky_color.indoors;
|
||||
}
|
||||
|
||||
ClientEvent *event = new ClientEvent();
|
||||
event->type = CE_SET_SKY;
|
||||
event->set_sky = new SkyboxParams(skybox);
|
||||
m_client_event_queue.push(event);
|
||||
}
|
||||
}
|
||||
|
||||
void Client::handleCommand_HudSetSun(NetworkPacket *pkt)
|
||||
{
|
||||
SunParams sun;
|
||||
|
||||
*pkt >> sun.visible >> sun.texture>> sun.tonemap
|
||||
>> sun.sunrise >> sun.sunrise_visible >> sun.scale;
|
||||
|
||||
ClientEvent *event = new ClientEvent();
|
||||
event->type = CE_SET_SKY;
|
||||
event->set_sky.bgcolor = bgcolor;
|
||||
event->set_sky.type = type;
|
||||
event->set_sky.params = params;
|
||||
event->set_sky.clouds = clouds;
|
||||
event->type = CE_SET_SUN;
|
||||
event->sun_params = new SunParams(sun);
|
||||
m_client_event_queue.push(event);
|
||||
}
|
||||
|
||||
void Client::handleCommand_HudSetMoon(NetworkPacket *pkt)
|
||||
{
|
||||
MoonParams moon;
|
||||
|
||||
*pkt >> moon.visible >> moon.texture
|
||||
>> moon.tonemap >> moon.scale;
|
||||
|
||||
ClientEvent *event = new ClientEvent();
|
||||
event->type = CE_SET_MOON;
|
||||
event->moon_params = new MoonParams(moon);
|
||||
m_client_event_queue.push(event);
|
||||
}
|
||||
|
||||
void Client::handleCommand_HudSetStars(NetworkPacket *pkt)
|
||||
{
|
||||
StarParams stars;
|
||||
|
||||
*pkt >> stars.visible >> stars.count
|
||||
>> stars.starcolor >> stars.scale;
|
||||
|
||||
ClientEvent *event = new ClientEvent();
|
||||
event->type = CE_SET_STARS;
|
||||
event->star_params = new StarParams(stars);
|
||||
|
||||
m_client_event_queue.push(event);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue