mirror of
https://github.com/minetest/minetest.git
synced 2024-11-10 01:33:46 +01:00
refacto: protect some RenderingEngine::get_scene_manager
* protect it from Camera, Sky, ClientMap object calls * rename Game::sky to Game::m_sky
This commit is contained in:
parent
258101a910
commit
1bc855646e
@ -43,11 +43,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#define WIELDMESH_AMPLITUDE_X 7.0f
|
#define WIELDMESH_AMPLITUDE_X 7.0f
|
||||||
#define WIELDMESH_AMPLITUDE_Y 10.0f
|
#define WIELDMESH_AMPLITUDE_Y 10.0f
|
||||||
|
|
||||||
Camera::Camera(MapDrawControl &draw_control, Client *client):
|
Camera::Camera(MapDrawControl &draw_control, Client *client, RenderingEngine *rendering_engine):
|
||||||
m_draw_control(draw_control),
|
m_draw_control(draw_control),
|
||||||
m_client(client)
|
m_client(client)
|
||||||
{
|
{
|
||||||
scene::ISceneManager *smgr = RenderingEngine::get_scene_manager();
|
auto smgr = rendering_engine->get_scene_manager();
|
||||||
// note: making the camera node a child of the player node
|
// note: making the camera node a child of the player node
|
||||||
// would lead to unexpected behaviour, so we don't do that.
|
// would lead to unexpected behaviour, so we don't do that.
|
||||||
m_playernode = smgr->addEmptySceneNode(smgr->getRootSceneNode());
|
m_playernode = smgr->addEmptySceneNode(smgr->getRootSceneNode());
|
||||||
|
@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
class LocalPlayer;
|
class LocalPlayer;
|
||||||
struct MapDrawControl;
|
struct MapDrawControl;
|
||||||
class Client;
|
class Client;
|
||||||
|
class RenderingEngine;
|
||||||
class WieldMeshSceneNode;
|
class WieldMeshSceneNode;
|
||||||
|
|
||||||
struct Nametag
|
struct Nametag
|
||||||
@ -78,7 +79,7 @@ enum CameraMode {CAMERA_MODE_FIRST, CAMERA_MODE_THIRD, CAMERA_MODE_THIRD_FRONT};
|
|||||||
class Camera
|
class Camera
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Camera(MapDrawControl &draw_control, Client *client);
|
Camera(MapDrawControl &draw_control, Client *client, RenderingEngine *rendering_engine);
|
||||||
~Camera();
|
~Camera();
|
||||||
|
|
||||||
// Get camera scene node.
|
// Get camera scene node.
|
||||||
|
@ -110,7 +110,7 @@ Client::Client(
|
|||||||
m_rendering_engine(rendering_engine),
|
m_rendering_engine(rendering_engine),
|
||||||
m_mesh_update_thread(this),
|
m_mesh_update_thread(this),
|
||||||
m_env(
|
m_env(
|
||||||
new ClientMap(this, control, 666),
|
new ClientMap(this, rendering_engine, control, 666),
|
||||||
tsrc, this
|
tsrc, this
|
||||||
),
|
),
|
||||||
m_particle_manager(&m_env),
|
m_particle_manager(&m_env),
|
||||||
|
@ -64,12 +64,13 @@ void MeshBufListList::add(scene::IMeshBuffer *buf, v3s16 position, u8 layer)
|
|||||||
|
|
||||||
ClientMap::ClientMap(
|
ClientMap::ClientMap(
|
||||||
Client *client,
|
Client *client,
|
||||||
|
RenderingEngine *rendering_engine,
|
||||||
MapDrawControl &control,
|
MapDrawControl &control,
|
||||||
s32 id
|
s32 id
|
||||||
):
|
):
|
||||||
Map(client),
|
Map(client),
|
||||||
scene::ISceneNode(RenderingEngine::get_scene_manager()->getRootSceneNode(),
|
scene::ISceneNode(rendering_engine->get_scene_manager()->getRootSceneNode(),
|
||||||
RenderingEngine::get_scene_manager(), id),
|
rendering_engine->get_scene_manager(), id),
|
||||||
m_client(client),
|
m_client(client),
|
||||||
m_control(control)
|
m_control(control)
|
||||||
{
|
{
|
||||||
@ -317,7 +318,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
|
|||||||
v3f block_pos_r = intToFloat(block->getPosRelative() + MAP_BLOCKSIZE / 2, BS);
|
v3f block_pos_r = intToFloat(block->getPosRelative() + MAP_BLOCKSIZE / 2, BS);
|
||||||
float d = camera_position.getDistanceFrom(block_pos_r);
|
float d = camera_position.getDistanceFrom(block_pos_r);
|
||||||
d = MYMAX(0,d - BLOCK_MAX_RADIUS);
|
d = MYMAX(0,d - BLOCK_MAX_RADIUS);
|
||||||
|
|
||||||
// Mesh animation
|
// Mesh animation
|
||||||
if (pass == scene::ESNRP_SOLID) {
|
if (pass == scene::ESNRP_SOLID) {
|
||||||
//MutexAutoLock lock(block->mesh_mutex);
|
//MutexAutoLock lock(block->mesh_mutex);
|
||||||
|
@ -68,6 +68,7 @@ class ClientMap : public Map, public scene::ISceneNode
|
|||||||
public:
|
public:
|
||||||
ClientMap(
|
ClientMap(
|
||||||
Client *client,
|
Client *client,
|
||||||
|
RenderingEngine *rendering_engine,
|
||||||
MapDrawControl &control,
|
MapDrawControl &control,
|
||||||
s32 id
|
s32 id
|
||||||
);
|
);
|
||||||
|
@ -839,7 +839,7 @@ private:
|
|||||||
MapDrawControl *draw_control = nullptr;
|
MapDrawControl *draw_control = nullptr;
|
||||||
Camera *camera = nullptr;
|
Camera *camera = nullptr;
|
||||||
Clouds *clouds = nullptr; // Free using ->Drop()
|
Clouds *clouds = nullptr; // Free using ->Drop()
|
||||||
Sky *sky = nullptr; // Free using ->Drop()
|
Sky *m_sky = nullptr; // Free using ->Drop()
|
||||||
Hud *hud = nullptr;
|
Hud *hud = nullptr;
|
||||||
Minimap *mapper = nullptr;
|
Minimap *mapper = nullptr;
|
||||||
|
|
||||||
@ -1159,8 +1159,8 @@ void Game::shutdown()
|
|||||||
if (gui_chat_console)
|
if (gui_chat_console)
|
||||||
gui_chat_console->drop();
|
gui_chat_console->drop();
|
||||||
|
|
||||||
if (sky)
|
if (m_sky)
|
||||||
sky->drop();
|
m_sky->drop();
|
||||||
|
|
||||||
/* cleanup menus */
|
/* cleanup menus */
|
||||||
while (g_menumgr.menuCount() > 0) {
|
while (g_menumgr.menuCount() > 0) {
|
||||||
@ -1293,7 +1293,7 @@ bool Game::createClient(const GameStartData &start_data)
|
|||||||
{
|
{
|
||||||
showOverlayMessage(N_("Creating client..."), 0, 10);
|
showOverlayMessage(N_("Creating client..."), 0, 10);
|
||||||
|
|
||||||
draw_control = new MapDrawControl;
|
draw_control = new MapDrawControl();
|
||||||
if (!draw_control)
|
if (!draw_control)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -1334,7 +1334,7 @@ bool Game::createClient(const GameStartData &start_data)
|
|||||||
|
|
||||||
/* Camera
|
/* Camera
|
||||||
*/
|
*/
|
||||||
camera = new Camera(*draw_control, client);
|
camera = new Camera(*draw_control, client, m_rendering_engine);
|
||||||
if (!camera->successfullyCreated(*error_message))
|
if (!camera->successfullyCreated(*error_message))
|
||||||
return false;
|
return false;
|
||||||
client->setCamera(camera);
|
client->setCamera(camera);
|
||||||
@ -1346,8 +1346,8 @@ bool Game::createClient(const GameStartData &start_data)
|
|||||||
|
|
||||||
/* Skybox
|
/* Skybox
|
||||||
*/
|
*/
|
||||||
sky = new Sky(-1, texture_src, shader_src);
|
m_sky = new Sky(-1, m_rendering_engine, texture_src, shader_src);
|
||||||
scsf->setSky(sky);
|
scsf->setSky(m_sky);
|
||||||
skybox = NULL; // This is used/set later on in the main run loop
|
skybox = NULL; // This is used/set later on in the main run loop
|
||||||
|
|
||||||
/* Pre-calculated values
|
/* Pre-calculated values
|
||||||
@ -2754,23 +2754,23 @@ void Game::handleClientEvent_HudChange(ClientEvent *event, CameraOrientation *ca
|
|||||||
|
|
||||||
void Game::handleClientEvent_SetSky(ClientEvent *event, CameraOrientation *cam)
|
void Game::handleClientEvent_SetSky(ClientEvent *event, CameraOrientation *cam)
|
||||||
{
|
{
|
||||||
sky->setVisible(false);
|
m_sky->setVisible(false);
|
||||||
// Whether clouds are visible in front of a custom skybox.
|
// Whether clouds are visible in front of a custom skybox.
|
||||||
sky->setCloudsEnabled(event->set_sky->clouds);
|
m_sky->setCloudsEnabled(event->set_sky->clouds);
|
||||||
|
|
||||||
if (skybox) {
|
if (skybox) {
|
||||||
skybox->remove();
|
skybox->remove();
|
||||||
skybox = NULL;
|
skybox = NULL;
|
||||||
}
|
}
|
||||||
// Clear the old textures out in case we switch rendering type.
|
// Clear the old textures out in case we switch rendering type.
|
||||||
sky->clearSkyboxTextures();
|
m_sky->clearSkyboxTextures();
|
||||||
// Handle according to type
|
// Handle according to type
|
||||||
if (event->set_sky->type == "regular") {
|
if (event->set_sky->type == "regular") {
|
||||||
// Shows the mesh skybox
|
// Shows the mesh skybox
|
||||||
sky->setVisible(true);
|
m_sky->setVisible(true);
|
||||||
// Update mesh based skybox colours if applicable.
|
// Update mesh based skybox colours if applicable.
|
||||||
sky->setSkyColors(event->set_sky->sky_color);
|
m_sky->setSkyColors(event->set_sky->sky_color);
|
||||||
sky->setHorizonTint(
|
m_sky->setHorizonTint(
|
||||||
event->set_sky->fog_sun_tint,
|
event->set_sky->fog_sun_tint,
|
||||||
event->set_sky->fog_moon_tint,
|
event->set_sky->fog_moon_tint,
|
||||||
event->set_sky->fog_tint_type
|
event->set_sky->fog_tint_type
|
||||||
@ -2778,61 +2778,62 @@ void Game::handleClientEvent_SetSky(ClientEvent *event, CameraOrientation *cam)
|
|||||||
} else if (event->set_sky->type == "skybox" &&
|
} else if (event->set_sky->type == "skybox" &&
|
||||||
event->set_sky->textures.size() == 6) {
|
event->set_sky->textures.size() == 6) {
|
||||||
// Disable the dyanmic mesh skybox:
|
// Disable the dyanmic mesh skybox:
|
||||||
sky->setVisible(false);
|
m_sky->setVisible(false);
|
||||||
// Set fog colors:
|
// Set fog colors:
|
||||||
sky->setFallbackBgColor(event->set_sky->bgcolor);
|
m_sky->setFallbackBgColor(event->set_sky->bgcolor);
|
||||||
// Set sunrise and sunset fog tinting:
|
// Set sunrise and sunset fog tinting:
|
||||||
sky->setHorizonTint(
|
m_sky->setHorizonTint(
|
||||||
event->set_sky->fog_sun_tint,
|
event->set_sky->fog_sun_tint,
|
||||||
event->set_sky->fog_moon_tint,
|
event->set_sky->fog_moon_tint,
|
||||||
event->set_sky->fog_tint_type
|
event->set_sky->fog_tint_type
|
||||||
);
|
);
|
||||||
// Add textures to skybox.
|
// Add textures to skybox.
|
||||||
for (int i = 0; i < 6; i++)
|
for (int i = 0; i < 6; i++)
|
||||||
sky->addTextureToSkybox(event->set_sky->textures[i], i, texture_src);
|
m_sky->addTextureToSkybox(event->set_sky->textures[i], i, texture_src);
|
||||||
} else {
|
} else {
|
||||||
// Handle everything else as plain color.
|
// Handle everything else as plain color.
|
||||||
if (event->set_sky->type != "plain")
|
if (event->set_sky->type != "plain")
|
||||||
infostream << "Unknown sky type: "
|
infostream << "Unknown sky type: "
|
||||||
<< (event->set_sky->type) << std::endl;
|
<< (event->set_sky->type) << std::endl;
|
||||||
sky->setVisible(false);
|
m_sky->setVisible(false);
|
||||||
sky->setFallbackBgColor(event->set_sky->bgcolor);
|
m_sky->setFallbackBgColor(event->set_sky->bgcolor);
|
||||||
// Disable directional sun/moon tinting on plain or invalid skyboxes.
|
// Disable directional sun/moon tinting on plain or invalid skyboxes.
|
||||||
sky->setHorizonTint(
|
m_sky->setHorizonTint(
|
||||||
event->set_sky->bgcolor,
|
event->set_sky->bgcolor,
|
||||||
event->set_sky->bgcolor,
|
event->set_sky->bgcolor,
|
||||||
"custom"
|
"custom"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete event->set_sky;
|
delete event->set_sky;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::handleClientEvent_SetSun(ClientEvent *event, CameraOrientation *cam)
|
void Game::handleClientEvent_SetSun(ClientEvent *event, CameraOrientation *cam)
|
||||||
{
|
{
|
||||||
sky->setSunVisible(event->sun_params->visible);
|
m_sky->setSunVisible(event->sun_params->visible);
|
||||||
sky->setSunTexture(event->sun_params->texture,
|
m_sky->setSunTexture(event->sun_params->texture,
|
||||||
event->sun_params->tonemap, texture_src);
|
event->sun_params->tonemap, texture_src);
|
||||||
sky->setSunScale(event->sun_params->scale);
|
m_sky->setSunScale(event->sun_params->scale);
|
||||||
sky->setSunriseVisible(event->sun_params->sunrise_visible);
|
m_sky->setSunriseVisible(event->sun_params->sunrise_visible);
|
||||||
sky->setSunriseTexture(event->sun_params->sunrise, texture_src);
|
m_sky->setSunriseTexture(event->sun_params->sunrise, texture_src);
|
||||||
delete event->sun_params;
|
delete event->sun_params;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::handleClientEvent_SetMoon(ClientEvent *event, CameraOrientation *cam)
|
void Game::handleClientEvent_SetMoon(ClientEvent *event, CameraOrientation *cam)
|
||||||
{
|
{
|
||||||
sky->setMoonVisible(event->moon_params->visible);
|
m_sky->setMoonVisible(event->moon_params->visible);
|
||||||
sky->setMoonTexture(event->moon_params->texture,
|
m_sky->setMoonTexture(event->moon_params->texture,
|
||||||
event->moon_params->tonemap, texture_src);
|
event->moon_params->tonemap, texture_src);
|
||||||
sky->setMoonScale(event->moon_params->scale);
|
m_sky->setMoonScale(event->moon_params->scale);
|
||||||
delete event->moon_params;
|
delete event->moon_params;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::handleClientEvent_SetStars(ClientEvent *event, CameraOrientation *cam)
|
void Game::handleClientEvent_SetStars(ClientEvent *event, CameraOrientation *cam)
|
||||||
{
|
{
|
||||||
sky->setStarsVisible(event->star_params->visible);
|
m_sky->setStarsVisible(event->star_params->visible);
|
||||||
sky->setStarCount(event->star_params->count, false);
|
m_sky->setStarCount(event->star_params->count, false);
|
||||||
sky->setStarColor(event->star_params->starcolor);
|
m_sky->setStarColor(event->star_params->starcolor);
|
||||||
sky->setStarScale(event->star_params->scale);
|
m_sky->setStarScale(event->star_params->scale);
|
||||||
delete event->star_params;
|
delete event->star_params;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3709,7 +3710,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
|
|||||||
direct_brightness = time_brightness;
|
direct_brightness = time_brightness;
|
||||||
sunlight_seen = true;
|
sunlight_seen = true;
|
||||||
} else {
|
} else {
|
||||||
float old_brightness = sky->getBrightness();
|
float old_brightness = m_sky->getBrightness();
|
||||||
direct_brightness = client->getEnv().getClientMap()
|
direct_brightness = client->getEnv().getClientMap()
|
||||||
.getBackgroundBrightness(MYMIN(runData.fog_range * 1.2, 60 * BS),
|
.getBackgroundBrightness(MYMIN(runData.fog_range * 1.2, 60 * BS),
|
||||||
daynight_ratio, (int)(old_brightness * 255.5), &sunlight_seen)
|
daynight_ratio, (int)(old_brightness * 255.5), &sunlight_seen)
|
||||||
@ -3736,7 +3737,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
|
|||||||
|
|
||||||
runData.time_of_day_smooth = time_of_day_smooth;
|
runData.time_of_day_smooth = time_of_day_smooth;
|
||||||
|
|
||||||
sky->update(time_of_day_smooth, time_brightness, direct_brightness,
|
m_sky->update(time_of_day_smooth, time_brightness, direct_brightness,
|
||||||
sunlight_seen, camera->getCameraMode(), player->getYaw(),
|
sunlight_seen, camera->getCameraMode(), player->getYaw(),
|
||||||
player->getPitch());
|
player->getPitch());
|
||||||
|
|
||||||
@ -3744,7 +3745,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
|
|||||||
Update clouds
|
Update clouds
|
||||||
*/
|
*/
|
||||||
if (clouds) {
|
if (clouds) {
|
||||||
if (sky->getCloudsVisible()) {
|
if (m_sky->getCloudsVisible()) {
|
||||||
clouds->setVisible(true);
|
clouds->setVisible(true);
|
||||||
clouds->step(dtime);
|
clouds->step(dtime);
|
||||||
// camera->getPosition is not enough for 3rd person views
|
// camera->getPosition is not enough for 3rd person views
|
||||||
@ -3754,14 +3755,14 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
|
|||||||
camera_node_position.Y = camera_node_position.Y + camera_offset.Y * BS;
|
camera_node_position.Y = camera_node_position.Y + camera_offset.Y * BS;
|
||||||
camera_node_position.Z = camera_node_position.Z + camera_offset.Z * BS;
|
camera_node_position.Z = camera_node_position.Z + camera_offset.Z * BS;
|
||||||
clouds->update(camera_node_position,
|
clouds->update(camera_node_position,
|
||||||
sky->getCloudColor());
|
m_sky->getCloudColor());
|
||||||
if (clouds->isCameraInsideCloud() && m_cache_enable_fog) {
|
if (clouds->isCameraInsideCloud() && m_cache_enable_fog) {
|
||||||
// if inside clouds, and fog enabled, use that as sky
|
// if inside clouds, and fog enabled, use that as sky
|
||||||
// color(s)
|
// color(s)
|
||||||
video::SColor clouds_dark = clouds->getColor()
|
video::SColor clouds_dark = clouds->getColor()
|
||||||
.getInterpolated(video::SColor(255, 0, 0, 0), 0.9);
|
.getInterpolated(video::SColor(255, 0, 0, 0), 0.9);
|
||||||
sky->overrideColors(clouds_dark, clouds->getColor());
|
m_sky->overrideColors(clouds_dark, clouds->getColor());
|
||||||
sky->setInClouds(true);
|
m_sky->setInClouds(true);
|
||||||
runData.fog_range = std::fmin(runData.fog_range * 0.5f, 32.0f * BS);
|
runData.fog_range = std::fmin(runData.fog_range * 0.5f, 32.0f * BS);
|
||||||
// do not draw clouds after all
|
// do not draw clouds after all
|
||||||
clouds->setVisible(false);
|
clouds->setVisible(false);
|
||||||
@ -3782,7 +3783,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
|
|||||||
|
|
||||||
if (m_cache_enable_fog) {
|
if (m_cache_enable_fog) {
|
||||||
driver->setFog(
|
driver->setFog(
|
||||||
sky->getBgColor(),
|
m_sky->getBgColor(),
|
||||||
video::EFT_FOG_LINEAR,
|
video::EFT_FOG_LINEAR,
|
||||||
runData.fog_range * m_cache_fog_start,
|
runData.fog_range * m_cache_fog_start,
|
||||||
runData.fog_range * 1.0,
|
runData.fog_range * 1.0,
|
||||||
@ -3792,7 +3793,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
driver->setFog(
|
driver->setFog(
|
||||||
sky->getBgColor(),
|
m_sky->getBgColor(),
|
||||||
video::EFT_FOG_LINEAR,
|
video::EFT_FOG_LINEAR,
|
||||||
100000 * BS,
|
100000 * BS,
|
||||||
110000 * BS,
|
110000 * BS,
|
||||||
@ -3872,7 +3873,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
|
|||||||
/*
|
/*
|
||||||
Drawing begins
|
Drawing begins
|
||||||
*/
|
*/
|
||||||
const video::SColor &skycolor = sky->getSkyColor();
|
const video::SColor &skycolor = m_sky->getSkyColor();
|
||||||
|
|
||||||
TimeTaker tt_draw("Draw scene");
|
TimeTaker tt_draw("Draw scene");
|
||||||
driver->beginScene(true, true, skycolor);
|
driver->beginScene(true, true, skycolor);
|
||||||
|
@ -53,9 +53,9 @@ static video::SMaterial baseMaterial()
|
|||||||
return mat;
|
return mat;
|
||||||
};
|
};
|
||||||
|
|
||||||
Sky::Sky(s32 id, ITextureSource *tsrc, IShaderSource *ssrc) :
|
Sky::Sky(s32 id, RenderingEngine *rendering_engine, ITextureSource *tsrc, IShaderSource *ssrc) :
|
||||||
scene::ISceneNode(RenderingEngine::get_scene_manager()->getRootSceneNode(),
|
scene::ISceneNode(rendering_engine->get_scene_manager()->getRootSceneNode(),
|
||||||
RenderingEngine::get_scene_manager(), id)
|
rendering_engine->get_scene_manager(), id)
|
||||||
{
|
{
|
||||||
m_seed = (u64)myrand() << 32 | myrand();
|
m_seed = (u64)myrand() << 32 | myrand();
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ class Sky : public scene::ISceneNode
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! constructor
|
//! constructor
|
||||||
Sky(s32 id, ITextureSource *tsrc, IShaderSource *ssrc);
|
Sky(s32 id, RenderingEngine *rendering_engine, ITextureSource *tsrc, IShaderSource *ssrc);
|
||||||
|
|
||||||
virtual void OnRegisterSceneNode();
|
virtual void OnRegisterSceneNode();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user