aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2020-11-28 13:48:33 +0100
committerElias Fleckenstein <eliasfleckenstein@web.de>2020-11-28 13:48:33 +0100
commiteb6aca8b4a67ef55108231e71ff29a18a29bf5ae (patch)
treef891914d25cae2cdaa24392381436a287340651e /src/client
parent8de51dae97aa2fe6ea02e4cf437bfe2b2a38eb06 (diff)
parentf1d72d212a0661588be27003069abf4bd8092e55 (diff)
downloaddragonfireclient-eb6aca8b4a67ef55108231e71ff29a18a29bf5ae.tar.xz
Merged Minetest
Diffstat (limited to 'src/client')
-rw-r--r--src/client/camera.cpp2
-rw-r--r--src/client/camera.h2
-rw-r--r--src/client/client.cpp33
-rw-r--r--src/client/client.h2
-rw-r--r--src/client/clientenvironment.cpp130
-rw-r--r--src/client/clientlauncher.cpp6
-rw-r--r--src/client/clientmap.cpp39
-rw-r--r--src/client/clientmedia.cpp3
-rw-r--r--src/client/clouds.cpp60
-rw-r--r--src/client/content_cao.cpp165
-rw-r--r--src/client/content_cao.h12
-rw-r--r--src/client/content_mapblock.cpp7
-rw-r--r--src/client/content_mapblock.h2
-rw-r--r--src/client/event_manager.h2
-rw-r--r--src/client/fontengine.h2
-rw-r--r--src/client/game.cpp264
-rw-r--r--src/client/game.h36
-rw-r--r--src/client/gameui.cpp33
-rw-r--r--src/client/guiscalingfilter.cpp5
-rw-r--r--src/client/guiscalingfilter.h3
-rw-r--r--src/client/hud.cpp168
-rw-r--r--src/client/hud.h10
-rw-r--r--src/client/inputhandler.cpp166
-rw-r--r--src/client/inputhandler.h154
-rw-r--r--src/client/joystick_controller.cpp22
-rw-r--r--src/client/keys.h8
-rw-r--r--src/client/localplayer.cpp2
-rw-r--r--src/client/mapblock_mesh.cpp79
-rw-r--r--src/client/mapblock_mesh.h10
-rw-r--r--src/client/mesh.cpp9
-rw-r--r--src/client/mesh.h7
-rw-r--r--src/client/mesh_generator_thread.cpp6
-rw-r--r--src/client/mesh_generator_thread.h1
-rw-r--r--src/client/minimap.cpp270
-rw-r--r--src/client/minimap.h52
-rw-r--r--src/client/render/core.cpp46
-rw-r--r--src/client/shader.cpp248
-rw-r--r--src/client/sky.cpp225
-rw-r--r--src/client/sky.h15
-rw-r--r--src/client/sound_openal.cpp56
-rw-r--r--src/client/wieldmesh.cpp211
41 files changed, 1469 insertions, 1104 deletions
diff --git a/src/client/camera.cpp b/src/client/camera.cpp
index c9e8fab6a..398bc8377 100644
--- a/src/client/camera.cpp
+++ b/src/client/camera.cpp
@@ -30,7 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "wieldmesh.h"
#include "noise.h" // easeCurve
#include "sound.h"
-#include "event.h"
+#include "mtevent.h"
#include "nodedef.h"
#include "util/numeric.h"
#include "constants.h"
diff --git a/src/client/camera.h b/src/client/camera.h
index 3a59637bc..16a1961be 100644
--- a/src/client/camera.h
+++ b/src/client/camera.h
@@ -169,8 +169,6 @@ public:
void removeNametag(Nametag *nametag);
- const std::list<Nametag *> &getNametags() { return m_nametags; }
-
void drawNametags();
inline void addArmInertia(f32 player_yaw);
diff --git a/src/client/client.cpp b/src/client/client.cpp
index aa3e257ac..9bbb57668 100644
--- a/src/client/client.cpp
+++ b/src/client/client.cpp
@@ -130,6 +130,7 @@ Client::Client(
if (g_settings->getBool("enable_minimap")) {
m_minimap = new Minimap(this);
}
+
m_cache_save_interval = g_settings->getU16("server_map_save_interval");
}
@@ -241,18 +242,13 @@ void Client::scanModSubfolder(const std::string &mod_name, const std::string &mo
infostream << "Client::scanModSubfolder(): Loading \"" << real_path
<< "\" as \"" << vfs_path << "\"." << std::endl;
- std::ifstream is(real_path, std::ios::binary | std::ios::ate);
- if(!is.good()) {
+ std::string contents;
+ if (!fs::ReadFile(real_path, contents)) {
errorstream << "Client::scanModSubfolder(): Can't read file \""
<< real_path << "\"." << std::endl;
continue;
}
- auto size = is.tellg();
- std::string contents(size, '\0');
- is.seekg(0);
- is.read(&contents[0], size);
- infostream << " size: " << size << " bytes" << std::endl;
m_mod_vfs.emplace(vfs_path, contents);
}
}
@@ -333,6 +329,8 @@ Client::~Client()
}
delete m_minimap;
+ m_minimap = nullptr;
+
delete m_media_downloader;
}
@@ -1310,7 +1308,7 @@ void Client::sendPlayerPos(v3f pos)
player->last_pitch == player->getPitch() &&
player->last_yaw == player->getYaw() &&
player->last_keyPressed == player->keyPressed &&
- player->last_camera_fov == camera_fov &&
+ player->last_camera_fov == camera_fov &&
player->last_wanted_range == wanted_range)
return;
@@ -1671,15 +1669,13 @@ void Client::updateAllMapBlocks()
for (s16 Z = currentBlock.Z - 2; Z <= currentBlock.Z + 2; Z++)
addUpdateMeshTask(v3s16(X, Y, Z), false, true);
- std::map<v2s16, MapSector*> *sectors = m_env.getMap().getSectorsPtr();
+ Map &map = m_env.getMap();
- for (auto &sector_it : *sectors) {
- MapSector *sector = sector_it.second;
- MapBlockVect blocks;
- sector->getBlocks(blocks);
- for (MapBlock *block : blocks) {
- addUpdateMeshTask(block->getPos(), false, false);
- }
+ std::vector<v3s16> positions;
+ map.listAllLoadedBlocks(positions);
+
+ for (v3s16 p : positions) {
+ addUpdateMeshTask(p, false, false);
}
}
@@ -1693,11 +1689,6 @@ ClientEvent *Client::getClientEvent()
return event;
}
-bool Client::connectedToServer()
-{
- return m_con->Connected();
-}
-
const Address Client::getServerAddress()
{
return m_con->GetPeerAddress(PEER_ID_SERVER);
diff --git a/src/client/client.h b/src/client/client.h
index 7455d78dc..979636eba 100644
--- a/src/client/client.h
+++ b/src/client/client.h
@@ -222,6 +222,7 @@ public:
void handleCommand_CSMRestrictionFlags(NetworkPacket *pkt);
void handleCommand_PlayerSpeed(NetworkPacket *pkt);
void handleCommand_MediaPush(NetworkPacket *pkt);
+ void handleCommand_MinimapModes(NetworkPacket *pkt);
void ProcessData(NetworkPacket *pkt);
@@ -338,7 +339,6 @@ public:
u16 getProtoVersion()
{ return m_proto_ver; }
- bool connectedToServer();
void confirmRegistration();
bool m_is_registration_confirmation_state = false;
bool m_simple_singleplayer_mode;
diff --git a/src/client/clientenvironment.cpp b/src/client/clientenvironment.cpp
index 3f82bd316..2b50fbf64 100644
--- a/src/client/clientenvironment.cpp
+++ b/src/client/clientenvironment.cpp
@@ -25,7 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "clientmap.h"
#include "scripting_client.h"
#include "mapblock_mesh.h"
-#include "event.h"
+#include "mtevent.h"
#include "collision.h"
#include "nodedef.h"
#include "profiler.h"
@@ -183,84 +183,61 @@ void ClientEnvironment::step(float dtime)
if(dtime > 0.5)
dtime = 0.5;
- f32 dtime_downcount = dtime;
-
/*
Stuff that has a maximum time increment
*/
- u32 loopcount = 0;
- do
- {
- loopcount++;
-
- f32 dtime_part;
- if(dtime_downcount > dtime_max_increment)
- {
- dtime_part = dtime_max_increment;
- dtime_downcount -= dtime_part;
- }
- else
- {
- dtime_part = dtime_downcount;
- /*
- Setting this to 0 (no -=dtime_part) disables an infinite loop
- when dtime_part is so small that dtime_downcount -= dtime_part
- does nothing
- */
- dtime_downcount = 0;
- }
-
+ u32 steps = ceil(dtime / dtime_max_increment);
+ f32 dtime_part = dtime / steps;
+ for (; steps > 0; --steps) {
/*
- Handle local player
+ Local player handling
*/
- {
- // Control local player
- lplayer->applyControl(dtime_part, this);
-
- // Apply physics
- if (!free_move && !is_climbing && ! g_settings->getBool("freecam")) {
- // Gravity
- v3f speed = lplayer->getSpeed();
- if (!lplayer->in_liquid)
- speed.Y -= lplayer->movement_gravity *
- lplayer->physics_override_gravity * dtime_part * 2.0f;
-
- // Liquid floating / sinking
- if (lplayer->in_liquid && !lplayer->swimming_vertical &&
- !lplayer->swimming_pitch)
- speed.Y -= lplayer->movement_liquid_sink * dtime_part * 2.0f;
-
- // Liquid resistance
- if (lplayer->in_liquid_stable || lplayer->in_liquid) {
- // How much the node's viscosity blocks movement, ranges
- // between 0 and 1. Should match the scale at which viscosity
- // increase affects other liquid attributes.
- static const f32 viscosity_factor = 0.3f;
-
- v3f d_wanted = -speed / lplayer->movement_liquid_fluidity;
- f32 dl = d_wanted.getLength();
- if (dl > lplayer->movement_liquid_fluidity_smooth)
- dl = lplayer->movement_liquid_fluidity_smooth;
-
- dl *= (lplayer->liquid_viscosity * viscosity_factor) +
- (1 - viscosity_factor);
- v3f d = d_wanted.normalize() * (dl * dtime_part * 100.0f);
- speed += d;
- }
-
- lplayer->setSpeed(speed);
+ // Control local player
+ lplayer->applyControl(dtime_part, this);
+
+ // Apply physics
+ if (!free_move && !is_climbing && !g_settings->getBool("freecam")) {
+ // Gravity
+ v3f speed = lplayer->getSpeed();
+ if (!lplayer->in_liquid)
+ speed.Y -= lplayer->movement_gravity *
+ lplayer->physics_override_gravity * dtime_part * 2.0f;
+
+ // Liquid floating / sinking
+ if (lplayer->in_liquid && !lplayer->swimming_vertical &&
+ !lplayer->swimming_pitch)
+ speed.Y -= lplayer->movement_liquid_sink * dtime_part * 2.0f;
+
+ // Liquid resistance
+ if (lplayer->in_liquid_stable || lplayer->in_liquid) {
+ // How much the node's viscosity blocks movement, ranges
+ // between 0 and 1. Should match the scale at which viscosity
+ // increase affects other liquid attributes.
+ static const f32 viscosity_factor = 0.3f;
+
+ v3f d_wanted = -speed / lplayer->movement_liquid_fluidity;
+ f32 dl = d_wanted.getLength();
+ if (dl > lplayer->movement_liquid_fluidity_smooth)
+ dl = lplayer->movement_liquid_fluidity_smooth;
+
+ dl *= (lplayer->liquid_viscosity * viscosity_factor) +
+ (1 - viscosity_factor);
+ v3f d = d_wanted.normalize() * (dl * dtime_part * 100.0f);
+ speed += d;
}
- /*
- Move the lplayer.
- This also does collision detection.
- */
- lplayer->move(dtime_part, this, position_max_increment,
- &player_collisions);
+ lplayer->setSpeed(speed);
}
- } while (dtime_downcount > 0.001);
+
+ /*
+ Move the lplayer.
+ This also does collision detection.
+ */
+ lplayer->move(dtime_part, this, position_max_increment,
+ &player_collisions);
+ }
bool player_immortal = lplayer->getCAO() && lplayer->getCAO()->isImmortal();
@@ -368,21 +345,6 @@ bool isFreeClientActiveObjectId(const u16 id,
}
-u16 getFreeClientActiveObjectId(ClientActiveObjectMap &objects)
-{
- // try to reuse id's as late as possible
- static u16 last_used_id = 0;
- u16 startid = last_used_id;
- for(;;) {
- last_used_id ++;
- if (isFreeClientActiveObjectId(last_used_id, objects))
- return last_used_id;
-
- if (last_used_id == startid)
- return 0;
- }
-}
-
u16 ClientEnvironment::addActiveObject(ClientActiveObject *object)
{
// Register object. If failed return zero id
diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp
index ce16797e6..29427f609 100644
--- a/src/client/clientlauncher.cpp
+++ b/src/client/clientlauncher.cpp
@@ -327,13 +327,13 @@ void ClientLauncher::init_args(GameStartData &start_data, const Settings &cmd_ar
// Join a remote server
start_data.address = cmd_args.get("address");
start_data.world_path.clear();
+ start_data.name = g_settings->get("name");
}
if (!start_data.world_path.empty()) {
// Start a singleplayer instance
start_data.address = "";
}
- start_data.name = g_settings->get("name");
if (cmd_args.exists("name"))
start_data.name = cmd_args.get("name");
@@ -419,7 +419,6 @@ bool ClientLauncher::launch_game(std::string &error_message,
/* Show the GUI menu
*/
std::string server_name, server_description;
- start_data.local_server = false;
if (!skip_main_menu) {
// Initialize menu data
// TODO: Re-use existing structs (GameStartData)
@@ -467,6 +466,9 @@ bool ClientLauncher::launch_game(std::string &error_message,
start_data.local_server = !menudata.simple_singleplayer_mode &&
start_data.address.empty();
+ } else {
+ start_data.local_server = !start_data.world_path.empty() &&
+ start_data.address.empty() && !start_data.name.empty();
}
if (!RenderingEngine::run())
diff --git a/src/client/clientmap.cpp b/src/client/clientmap.cpp
index d41b66741..294687ff8 100644
--- a/src/client/clientmap.cpp
+++ b/src/client/clientmap.cpp
@@ -36,7 +36,7 @@ ClientMap::ClientMap(
MapDrawControl &control,
s32 id
):
- Map(dout_client, client),
+ Map(client),
scene::ISceneNode(RenderingEngine::get_scene_manager()->getRootSceneNode(),
RenderingEngine::get_scene_manager(), id),
m_client(client),
@@ -122,20 +122,20 @@ void ClientMap::updateDrawList()
}
m_drawlist.clear();
- v3f camera_position = m_camera_position;
- v3f camera_direction = m_camera_direction;
- f32 camera_fov = m_camera_fov;
+ const v3f camera_position = m_camera_position;
+ const v3f camera_direction = m_camera_direction;
// Use a higher fov to accomodate faster camera movements.
// Blocks are cropped better when they are drawn.
- // Or maybe they aren't? Well whatever.
- camera_fov *= 1.2;
+ const f32 camera_fov = m_camera_fov * 1.1f;
v3s16 cam_pos_nodes = floatToInt(camera_position, BS);
v3s16 p_blocks_min;
v3s16 p_blocks_max;
getBlocksInViewRange(cam_pos_nodes, &p_blocks_min, &p_blocks_max);
+ // Number of blocks currently loaded by the client
+ u32 blocks_loaded = 0;
// Number of blocks with mesh in rendering range
u32 blocks_in_range_with_mesh = 0;
// Number of blocks occlusion culled
@@ -160,6 +160,7 @@ void ClientMap::updateDrawList()
MapSector *sector = sector_it.second;
v2s16 sp = sector->getPos();
+ blocks_loaded += sector->size();
if (!m_control.range_all) {
if (sp.X < p_blocks_min.X || sp.X > p_blocks_max.X ||
sp.Y < p_blocks_min.Z || sp.Y > p_blocks_max.Z)
@@ -181,8 +182,12 @@ void ClientMap::updateDrawList()
if not seen on display
*/
- if (block->mesh)
+ if (block->mesh) {
block->mesh->updateCameraOffset(m_camera_offset);
+ } else {
+ // Ignore if mesh doesn't exist
+ continue;
+ }
float range = 100000 * BS;
if (!m_control.range_all)
@@ -193,13 +198,6 @@ void ClientMap::updateDrawList()
camera_direction, camera_fov, range, &d))
continue;
-
- /*
- Ignore if mesh doesn't exist
- */
- if (!block->mesh)
- continue;
-
blocks_in_range_with_mesh++;
/*
@@ -228,6 +226,7 @@ void ClientMap::updateDrawList()
g_profiler->avg("MapBlock meshes in range [#]", blocks_in_range_with_mesh);
g_profiler->avg("MapBlocks occlusion culled [#]", blocks_occlusion_culled);
g_profiler->avg("MapBlocks drawn [#]", m_drawlist.size());
+ g_profiler->avg("MapBlocks loaded [#]", blocks_loaded);
}
struct MeshBufList
@@ -293,13 +292,13 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
/*
Get animation parameters
*/
- float animation_time = m_client->getAnimationTime();
- int crack = m_client->getCrackLevel();
- u32 daynight_ratio = m_client->getEnv().getDayNightRatio();
+ const float animation_time = m_client->getAnimationTime();
+ const int crack = m_client->getCrackLevel();
+ const u32 daynight_ratio = m_client->getEnv().getDayNightRatio();
- v3f camera_position = m_camera_position;
- v3f camera_direction = m_camera_direction;
- f32 camera_fov = m_camera_fov;
+ const v3f camera_position = m_camera_position;
+ const v3f camera_direction = m_camera_direction;
+ const f32 camera_fov = m_camera_fov;
/*
Get all blocks and draw all visible ones
diff --git a/src/client/clientmedia.cpp b/src/client/clientmedia.cpp
index 8cd3b6bcc..c4c08c05d 100644
--- a/src/client/clientmedia.cpp
+++ b/src/client/clientmedia.cpp
@@ -260,7 +260,8 @@ void ClientMediaDownloader::initialStep(Client *client)
fetch_request.request_id = m_httpfetch_next_id; // == i
fetch_request.timeout = m_httpfetch_timeout;
fetch_request.connect_timeout = m_httpfetch_timeout;
- fetch_request.post_data = required_hash_set;
+ fetch_request.method = HTTP_POST;
+ fetch_request.raw_data = required_hash_set;
fetch_request.extra_headers.emplace_back(
"Content-Type: application/octet-stream");
diff --git a/src/client/clouds.cpp b/src/client/clouds.cpp
index 887a62f25..253dee8b9 100644
--- a/src/client/clouds.cpp
+++ b/src/client/clouds.cpp
@@ -170,8 +170,9 @@ void Clouds::render()
// Read noise
- bool *grid = new bool[m_cloud_radius_i * 2 * m_cloud_radius_i * 2];
-
+ std::vector<char> grid(m_cloud_radius_i * 2 * m_cloud_radius_i * 2); // vector<bool> is broken
+ std::vector<video::S3DVertex> vertices;
+ vertices.reserve(16 * m_cloud_radius_i * m_cloud_radius_i);
for(s16 zi = -m_cloud_radius_i; zi < m_cloud_radius_i; zi++) {
u32 si = (zi + m_cloud_radius_i) * m_cloud_radius_i * 2 + m_cloud_radius_i;
@@ -195,12 +196,7 @@ void Clouds::render()
{
s16 zi = zi0;
s16 xi = xi0;
- // Draw from front to back (needed for transparency)
- /*if(zi <= 0)
- zi = -m_cloud_radius_i - zi;
- if(xi <= 0)
- xi = -m_cloud_radius_i - xi;*/
- // Draw from back to front
+ // Draw from back to front for proper transparency
if(zi >= 0)
zi = m_cloud_radius_i - zi - 1;
if(xi >= 0)
@@ -220,17 +216,10 @@ void Clouds::render()
video::S3DVertex(0,0,0, 0,0,0, c_top, 0, 0)
};
- /*if(zi <= 0 && xi <= 0){
- v[0].Color.setBlue(255);
- v[1].Color.setBlue(255);
- v[2].Color.setBlue(255);
- v[3].Color.setBlue(255);
- }*/
-
- f32 rx = cloud_size / 2.0f;
+ const f32 rx = cloud_size / 2.0f;
// if clouds are flat, the top layer should be at the given height
- f32 ry = m_enable_3d ? m_params.thickness * BS : 0.0f;
- f32 rz = cloud_size / 2;
+ const f32 ry = m_enable_3d ? m_params.thickness * BS : 0.0f;
+ const f32 rz = cloud_size / 2;
for(int i=0; i<num_faces_to_draw; i++)
{
@@ -320,15 +309,25 @@ void Clouds::render()
v3f pos(p0.X, m_params.height * BS, p0.Y);
pos -= intToFloat(m_camera_offset, BS);
- for (video::S3DVertex &vertex : v)
+ for (video::S3DVertex &vertex : v) {
vertex.Pos += pos;
- u16 indices[] = {0,1,2,2,3,0};
- driver->drawVertexPrimitiveList(v, 4, indices, 2,
- video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT);
+ vertices.push_back(vertex);
+ }
}
}
-
- delete[] grid;
+ int quad_count = vertices.size() / 4;
+ std::vector<u16> indices;
+ indices.reserve(quad_count * 6);
+ for (int k = 0; k < quad_count; k++) {
+ indices.push_back(4 * k + 0);
+ indices.push_back(4 * k + 1);
+ indices.push_back(4 * k + 2);
+ indices.push_back(4 * k + 2);
+ indices.push_back(4 * k + 3);
+ indices.push_back(4 * k + 0);
+ }
+ driver->drawVertexPrimitiveList(vertices.data(), vertices.size(), indices.data(), 2 * quad_count,
+ video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT);
// Restore fog settings
driver->setFog(fog_color, fog_type, fog_start, fog_end, fog_density,
@@ -342,14 +341,13 @@ void Clouds::step(float dtime)
void Clouds::update(const v3f &camera_p, const video::SColorf &color_diffuse)
{
+ video::SColorf ambient(m_params.color_ambient);
+ video::SColorf bright(m_params.color_bright);
m_camera_pos = camera_p;
- m_color.r = MYMIN(MYMAX(color_diffuse.r * m_params.color_bright.getRed(),
- m_params.color_ambient.getRed()), 255) / 255.0f;
- m_color.g = MYMIN(MYMAX(color_diffuse.g * m_params.color_bright.getGreen(),
- m_params.color_ambient.getGreen()), 255) / 255.0f;
- m_color.b = MYMIN(MYMAX(color_diffuse.b * m_params.color_bright.getBlue(),
- m_params.color_ambient.getBlue()), 255) / 255.0f;
- m_color.a = m_params.color_bright.getAlpha() / 255.0f;
+ m_color.r = core::clamp(color_diffuse.r * bright.r, ambient.r, 1.0f);
+ m_color.g = core::clamp(color_diffuse.g * bright.g, ambient.g, 1.0f);
+ m_color.b = core::clamp(color_diffuse.b * bright.b, ambient.b, 1.0f);
+ m_color.a = bright.a;
// is the camera inside the cloud mesh?
m_camera_inside_cloud = false; // default
diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp
index e1cebf461..7208212d4 100644
--- a/src/client/content_cao.cpp
+++ b/src/client/content_cao.cpp
@@ -48,6 +48,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <cmath>
#include "client/shader.h"
#include "script/scripting_client.h"
+#include "client/minimap.h"
class Settings;
struct ToolCapabilities;
@@ -354,6 +355,8 @@ void GenericCAO::initialize(const std::string &data)
m_is_local_player = true;
m_is_visible = false;
player->setCAO(this);
+
+ m_prop.show_on_minimap = false;
}
}
@@ -372,7 +375,7 @@ void GenericCAO::processInitData(const std::string &data)
}
// PROTOCOL_VERSION >= 37
- m_name = deSerializeString(is);
+ m_name = deSerializeString16(is);
m_is_player = readU8(is);
m_id = readU16(is);
m_position = readV3F32(is);
@@ -382,7 +385,7 @@ void GenericCAO::processInitData(const std::string &data)
const u8 num_messages = readU8(is);
for (int i = 0; i < num_messages; i++) {
- std::string message = deSerializeLongString(is);
+ std::string message = deSerializeString32(is);
processMessage(message);
}
@@ -457,18 +460,21 @@ void GenericCAO::setChildrenVisible(bool toset)
for (u16 cao_id : m_attachment_child_ids) {
GenericCAO *obj = m_env->getGenericCAO(cao_id);
if (obj) {
- obj->setVisible(toset);
+ // Check if the entity is forced to appear in first person.
+ obj->setVisible(obj->m_force_visible ? true : toset);
}
}
}
-void GenericCAO::setAttachment(int parent_id, const std::string &bone, v3f position, v3f rotation)
+void GenericCAO::setAttachment(int parent_id, const std::string &bone,
+ v3f position, v3f rotation, bool force_visible)
{
int old_parent = m_attachment_parent_id;
m_attachment_parent_id = parent_id;
m_attachment_bone = bone;
m_attachment_position = position;
m_attachment_rotation = rotation;
+ m_force_visible = force_visible;
ClientActiveObject *parent = m_env->getActiveObject(parent_id);
@@ -480,17 +486,32 @@ void GenericCAO::setAttachment(int parent_id, const std::string &bone, v3f posit
if (parent)
parent->addAttachmentChild(m_id);
}
-
+
updateAttachments();
+
+ // Forcibly show attachments if required by set_attach
+ if (m_force_visible) {
+ m_is_visible = true;
+ } else if (!m_is_local_player) {
+ // Objects attached to the local player should be hidden in first person
+ m_is_visible = !m_attached_to_local ||
+ m_client->getCamera()->getCameraMode() != CAMERA_MODE_FIRST;
+ m_force_visible = false;
+ } else {
+ // Local players need to have this set,
+ // otherwise first person attachments fail.
+ m_is_visible = true;
+ }
}
void GenericCAO::getAttachment(int *parent_id, std::string *bone, v3f *position,
- v3f *rotation) const
+ v3f *rotation, bool *force_visible) const
{
*parent_id = m_attachment_parent_id;
*bone = m_attachment_bone;
*position = m_attachment_position;
*rotation = m_attachment_rotation;
+ *force_visible = m_force_visible;
}
void GenericCAO::clearChildAttachments()
@@ -500,7 +521,7 @@ void GenericCAO::clearChildAttachments()
int child_id = *m_attachment_child_ids.begin();
if (ClientActiveObject *child = m_env->getActiveObject(child_id))
- child->setAttachment(0, "", v3f(), v3f());
+ child->setAttachment(0, "", v3f(), v3f(), false);
removeAttachmentChild(child_id);
}
@@ -509,9 +530,9 @@ void GenericCAO::clearChildAttachments()
void GenericCAO::clearParentAttachment()
{
if (m_attachment_parent_id)
- setAttachment(0, "", m_attachment_position, m_attachment_rotation);
+ setAttachment(0, "", m_attachment_position, m_attachment_rotation, false);
else
- setAttachment(0, "", v3f(), v3f());
+ setAttachment(0, "", v3f(), v3f(), false);
}
void GenericCAO::addAttachmentChild(int child_id)
@@ -569,6 +590,9 @@ void GenericCAO::removeFromScene(bool permanent)
m_client->getCamera()->removeNametag(m_nametag);
m_nametag = nullptr;
}
+
+ if (m_marker && m_client->getMinimap())
+ m_client->getMinimap()->removeMarker(&m_marker);
}
void GenericCAO::addToScene(ITextureSource *tsrc)
@@ -797,11 +821,13 @@ void GenericCAO::addToScene(ITextureSource *tsrc)
node->setParent(m_matrixnode);
updateNametag();
+ updateMarker();
updateNodePos();
updateAnimation();
updateBonePosition();
updateAttachments();
setNodeLight(m_last_light);
+ updateMeshCulling();
}
void GenericCAO::updateLight(u32 day_night_ratio)
@@ -889,6 +915,26 @@ u16 GenericCAO::getLightPosition(v3s16 *pos)
return 3;
}
+void GenericCAO::updateMarker()
+{
+ if (!m_client->getMinimap())
+ return;
+
+ if (!m_prop.show_on_minimap) {
+ if (m_marker)
+ m_client->getMinimap()->removeMarker(&m_marker);
+ return;
+ }
+
+ if (m_marker)
+ return;
+
+ scene::ISceneNode *node = getSceneNode();
+ if (!node)
+ return;
+ m_marker = m_client->getMinimap()->addMarker(node);
+}
+
void GenericCAO::updateNametag()
{
if (m_is_local_player && ! g_settings->getBool("freecam")) // No nametag for local player
@@ -981,13 +1027,13 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
if (controls.sneak && walking && ! g_settings->getBool("no_slow"))
new_speed /= 2;
- if (walking && (controls.LMB || controls.RMB)) {
+ if (walking && (controls.dig || controls.place)) {
new_anim = player->local_animations[3];
player->last_animation = WD_ANIM;
- } else if(walking) {
+ } else if (walking) {
new_anim = player->local_animations[1];
player->last_animation = WALK_ANIM;
- } else if(controls.LMB || controls.RMB) {
+ } else if (controls.dig || controls.place) {
new_anim = player->local_animations[2];
player->last_animation = DIG_ANIM;
}
@@ -1010,9 +1056,9 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
// Update local player animations
if ((player->last_animation != old_anim ||
- m_animation_speed != old_anim_speed) &&
- player->last_animation != NO_ANIM && allow_update)
- updateAnimation();
+ m_animation_speed != old_anim_speed) &&
+ player->last_animation != NO_ANIM && allow_update)
+ updateAnimation();
}
}
@@ -1182,6 +1228,7 @@ void GenericCAO::updateTexturePos()
int row = m_tx_basepos.Y;
int col = m_tx_basepos.X;
+ // Yawpitch goes rightwards
if (m_tx_select_horiz_by_yawpitch) {
if (cam_to_entity.Y > 0.75)
col += 5;
@@ -1212,6 +1259,27 @@ void GenericCAO::updateTexturePos()
float tys = m_tx_size.Y;
setBillboardTextureMatrix(m_spritenode, txs, tys, col, row);
}
+
+ else if (m_meshnode) {
+ if (m_prop.visual == "upright_sprite") {
+ int row = m_tx_basepos.Y;
+ int col = m_tx_basepos.X;
+
+ // Animation goes downwards
+ row += m_anim_frame;
+
+ const auto &tx = m_tx_size;
+ v2f t[4] = { // cf. vertices in GenericCAO::addToScene()
+ tx * v2f(col+1, row+1),
+ tx * v2f(col, row+1),
+ tx * v2f(col, row),
+ tx * v2f(col+1, row),
+ };
+ auto mesh = m_meshnode->getMesh();
+ setMeshBufferTextureCoords(mesh->getMeshBuffer(0), t, 4);
+ setMeshBufferTextureCoords(mesh->getMeshBuffer(1), t, 4);
+ }
+ }
}
// Do not pass by reference, see header.
@@ -1253,7 +1321,7 @@ void GenericCAO::updateTextures(std::string mod)
}
}
- if (m_animated_meshnode) {
+ else if (m_animated_meshnode) {
if (m_prop.visual == "mesh") {
for (u32 i = 0; i < m_prop.textures.size() &&
i < m_animated_meshnode->getMaterialCount(); ++i) {
@@ -1302,8 +1370,8 @@ void GenericCAO::updateTextures(std::string mod)
}
}
}
- if(m_meshnode)
- {
+
+ else if (m_meshnode) {
if(m_prop.visual == "cube")
{
for (u32 i = 0; i < 6; ++i)
@@ -1395,6 +1463,9 @@ void GenericCAO::updateTextures(std::string mod)
setMeshColor(mesh, m_prop.colors[0]);
}
}
+ // Prevent showing the player after changing texture
+ if (m_is_local_player)
+ updateMeshCulling();
}
void GenericCAO::updateAnimation()
@@ -1564,6 +1635,8 @@ void GenericCAO::processMessage(const std::string &data)
u8 cmd = readU8(is);
if (cmd == AO_CMD_SET_PROPERTIES) {
ObjectProperties newprops;
+ newprops.show_on_minimap = m_is_player; // default
+
newprops.deSerialize(is);
// Check what exactly changed
@@ -1597,6 +1670,8 @@ void GenericCAO::processMessage(const std::string &data)
if ((m_is_player && !m_is_local_player) && m_prop.nametag.empty())
m_prop.nametag = m_name;
+ if (m_is_local_player)
+ m_prop.show_on_minimap = false;
if (expire_visuals) {
expireVisuals();
@@ -1609,6 +1684,7 @@ void GenericCAO::processMessage(const std::string &data)
updateTextures(m_current_texture_modifier);
}
updateNametag();
+ updateMarker();
}
} else if (cmd == AO_CMD_UPDATE_POSITION) {
// Not sent by the server if this object is an attachment.
@@ -1641,7 +1717,7 @@ void GenericCAO::processMessage(const std::string &data)
rot_translator.update(m_rotation, false, update_interval);
updateNodePos();
} else if (cmd == AO_CMD_SET_TEXTURE_MOD) {
- std::string mod = deSerializeString(is);
+ std::string mod = deSerializeString16(is);
// immediately reset a engine issued texture modifier if a mod sends a different one
if (m_reset_textures_timer > 0) {
@@ -1724,7 +1800,7 @@ void GenericCAO::processMessage(const std::string &data)
m_animation_speed = readF32(is);
updateAnimationSpeed();
} else if (cmd == AO_CMD_SET_BONE_POSITION) {
- std::string bone = deSerializeString(is);
+ std::string bone = deSerializeString16(is);
v3f position = readV3F32(is);
v3f rotation = readV3F32(is);
m_bone_position[bone] = core::vector2d<v3f>(position, rotation);
@@ -1732,15 +1808,12 @@ void GenericCAO::processMessage(const std::string &data)
// updateBonePosition(); now called every step
} else if (cmd == AO_CMD_ATTACH_TO) {
u16 parent_id = readS16(is);
- std::string bone = deSerializeString(is);
+ std::string bone = deSerializeString16(is);
v3f position = readV3F32(is);
v3f rotation = readV3F32(is);
+ bool force_visible = readU8(is); // Returns false for EOF
- setAttachment(parent_id, bone, position, rotation);
-
- // localplayer itself can't be attached to localplayer
- if (!m_is_local_player)
- m_is_visible = !m_attached_to_local;
+ setAttachment(parent_id, bone, position, rotation, force_visible);
} else if (cmd == AO_CMD_PUNCHED) {
u16 result_hp = readU16(is);
@@ -1782,7 +1855,7 @@ void GenericCAO::processMessage(const std::string &data)
int armor_groups_size = readU16(is);
for(int i=0; i<armor_groups_size; i++)
{
- std::string name = deSerializeString(is);
+ std::string name = deSerializeString16(is);
int rating = readS16(is);
m_armor_groups[name] = rating;
}
@@ -1854,5 +1927,43 @@ std::string GenericCAO::debugInfoText()
return os.str();
}
+void GenericCAO::updateMeshCulling()
+{
+ if (!m_is_local_player)
+ return;
+
+ const bool hidden = m_client->getCamera()->getCameraMode() == CAMERA_MODE_FIRST;
+
+ if (m_meshnode && m_prop.visual == "upright_sprite") {
+ u32 buffers = m_meshnode->getMesh()->getMeshBufferCount();
+ for (u32 i = 0; i < buffers; i++) {
+ video::SMaterial &mat = m_meshnode->getMesh()->getMeshBuffer(i)->getMaterial();
+ // upright sprite has no backface culling
+ mat.setFlag(video::EMF_FRONT_FACE_CULLING, hidden);
+ }
+ return;
+ }
+
+ irr::scene::ISceneNode *node = getSceneNode();
+ if (!node)
+ return;
+
+ if (hidden) {
+ // Hide the mesh by culling both front and
+ // back faces. Serious hackyness but it works for our
+ // purposes. This also preserves the skeletal armature.
+ node->setMaterialFlag(video::EMF_BACK_FACE_CULLING,
+ true);
+ node->setMaterialFlag(video::EMF_FRONT_FACE_CULLING,
+ true);
+ } else {
+ // Restore mesh visibility.
+ node->setMaterialFlag(video::EMF_BACK_FACE_CULLING,
+ m_prop.backface_culling);
+ node->setMaterialFlag(video::EMF_FRONT_FACE_CULLING,
+ false);
+ }
+}
+
// Prototype
GenericCAO proto_GenericCAO(NULL, NULL);
diff --git a/src/client/content_cao.h b/src/client/content_cao.h
index 75882a074..09c26bd9c 100644
--- a/src/client/content_cao.h
+++ b/src/client/content_cao.h
@@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
class Camera;
class Client;
struct Nametag;
+struct MinimapMarker;
/*
SmoothTranslator
@@ -84,6 +85,7 @@ private:
scene::IBillboardSceneNode *m_spritenode = nullptr;
scene::IDummyTransformationSceneNode *m_matrixnode = nullptr;
Nametag *m_nametag = nullptr;
+ MinimapMarker *m_marker = nullptr;
v3f m_position = v3f(0.0f, 10.0f * BS, 0);
v3f m_velocity;
v3f m_acceleration;
@@ -109,6 +111,7 @@ private:
v3f m_attachment_position;
v3f m_attachment_rotation;
bool m_attached_to_local = false;
+ bool m_force_visible = false;
int m_anim_frame = 0;
int m_anim_num_frames = 1;
@@ -241,9 +244,10 @@ public:
}
void setChildrenVisible(bool toset);
- void setAttachment(int parent_id, const std::string &bone, v3f position, v3f rotation);
+ void setAttachment(int parent_id, const std::string &bone, v3f position,
+ v3f rotation, bool force_visible);
void getAttachment(int *parent_id, std::string *bone, v3f *position,
- v3f *rotation) const;
+ v3f *rotation, bool *force_visible) const;
void clearChildAttachments();
void clearParentAttachment();
void addAttachmentChild(int child_id);
@@ -274,6 +278,8 @@ public:
void updateNametag();
+ void updateMarker();
+
void updateNodePos();
void step(float dtime, ClientEnvironment *env);
@@ -308,4 +314,6 @@ public:
{
return &m_prop;
}
+
+ void updateMeshCulling();
};
diff --git a/src/client/content_mapblock.cpp b/src/client/content_mapblock.cpp
index 3d06584c4..df2748212 100644
--- a/src/client/content_mapblock.cpp
+++ b/src/client/content_mapblock.cpp
@@ -723,7 +723,8 @@ void MapblockMeshGenerator::drawGlasslikeFramedNode()
for (auto &glass_tile : glass_tiles)
glass_tile = tiles[4];
- u8 param2 = n.getParam2();
+ // Only respect H/V merge bits when paramtype2 = "glasslikeliquidlevel" (liquid tank)
+ u8 param2 = (f->param_type_2 == CPT2_GLASSLIKE_LIQUID_LEVEL) ? n.getParam2() : 0;
bool H_merge = !(param2 & 128);
bool V_merge = !(param2 & 64);
param2 &= 63;
@@ -1454,10 +1455,10 @@ void MapblockMeshGenerator::generate()
}
}
-void MapblockMeshGenerator::renderSingle(content_t node)
+void MapblockMeshGenerator::renderSingle(content_t node, u8 param2)
{
p = {0, 0, 0};
- n = MapNode(node, 0xff, 0x00);
+ n = MapNode(node, 0xff, param2);
f = &nodedef->get(n);
drawNode();
}
diff --git a/src/client/content_mapblock.h b/src/client/content_mapblock.h
index 97947cdbe..487d84a07 100644
--- a/src/client/content_mapblock.h
+++ b/src/client/content_mapblock.h
@@ -174,5 +174,5 @@ public:
public:
MapblockMeshGenerator(MeshMakeData *input, MeshCollector *output);
void generate();
- void renderSingle(content_t node);
+ void renderSingle(content_t node, u8 param2 = 0x00);
};
diff --git a/src/client/event_manager.h b/src/client/event_manager.h
index 3762e89bf..16f7bcf07 100644
--- a/src/client/event_manager.h
+++ b/src/client/event_manager.h
@@ -19,7 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#pragma once
-#include "event.h"
+#include "mtevent.h"
#include <list>
#include <map>
diff --git a/src/client/fontengine.h b/src/client/fontengine.h
index 865b2d3ff..c6efa0df4 100644
--- a/src/client/fontengine.h
+++ b/src/client/fontengine.h
@@ -48,7 +48,7 @@ struct FontSpec {
u16 getHash()
{
- return (mode << 2) | (bold << 1) | italic;
+ return (mode << 2) | (static_cast<u8>(bold) << 1) | static_cast<u8>(italic);
}
unsigned int size;
diff --git a/src/client/game.cpp b/src/client/game.cpp
index 88607d1d8..cc2a1bc43 100644
--- a/src/client/game.cpp
+++ b/src/client/game.cpp
@@ -96,7 +96,7 @@ Game::Game() :
&settingChangedCallback, this);
g_settings->registerChangedCallback("joystick_frustum_sensitivity",
&settingChangedCallback, this);
- g_settings->registerChangedCallback("repeat_rightclick_time",
+ g_settings->registerChangedCallback("repeat_place_time",
&settingChangedCallback, this);
g_settings->registerChangedCallback("noclip",
&settingChangedCallback, this);
@@ -164,7 +164,7 @@ Game::~Game()
&settingChangedCallback, this);
g_settings->deregisterChangedCallback("mouse_sensitivity",
&settingChangedCallback, this);
- g_settings->deregisterChangedCallback("repeat_rightclick_time",
+ g_settings->deregisterChangedCallback("repeat_place_time",
&settingChangedCallback, this);
g_settings->deregisterChangedCallback("noclip",
&settingChangedCallback, this);
@@ -476,7 +476,8 @@ bool Game::createSingleplayerServer(const std::string &map_dir,
return false;
}
- server = new Server(map_dir, gamespec, simple_singleplayer_mode, bind_addr, false);
+ server = new Server(map_dir, gamespec, simple_singleplayer_mode, bind_addr,
+ false, nullptr, error_message);
server->start();
return true;
@@ -545,7 +546,7 @@ bool Game::createClient(const GameStartData &start_data)
/* Skybox
*/
- sky = new Sky(-1, texture_src);
+ sky = new Sky(-1, texture_src, shader_src);
scsf->setSky(sky);
skybox = NULL; // This is used/set later on in the main run loop
@@ -591,11 +592,9 @@ bool Game::createClient(const GameStartData &start_data)
}
mapper = client->getMinimap();
- if (mapper) {
- mapper->setMinimapMode(MINIMAP_MODE_OFF);
- if (client->modsLoaded())
- client->getScript()->on_minimap_ready(mapper);
- }
+
+ if (mapper && client->modsLoaded())
+ client->getScript()->on_minimap_ready(mapper);
return true;
}
@@ -834,7 +833,10 @@ bool Game::getServerContent(bool *aborted)
std::stringstream message;
std::fixed(message);
message.precision(0);
- message << gettext("Media...") << " " << (client->mediaReceiveProgress()*100) << "%";
+ float receive = client->mediaReceiveProgress() * 100;
+ message << gettext("Media...");
+ if (receive > 0)
+ message << " " << receive << "%";
message.precision(2);
if ((USE_CURL == 0) ||
@@ -1228,15 +1230,11 @@ void Game::processItemSelection(u16 *new_playeritem)
s32 dir = wheel;
- if (input->joystick.wasKeyDown(KeyType::SCROLL_DOWN) ||
- wasKeyDown(KeyType::HOTBAR_NEXT)) {
+ if (wasKeyDown(KeyType::HOTBAR_NEXT))
dir = -1;
- }
- if (input->joystick.wasKeyDown(KeyType::SCROLL_UP) ||
- wasKeyDown(KeyType::HOTBAR_PREV)) {
+ if (wasKeyDown(KeyType::HOTBAR_PREV))
dir = 1;
- }
if (dir < 0)
*new_playeritem = *new_playeritem < max_item ? *new_playeritem + 1 : 0;
@@ -1289,7 +1287,7 @@ void Game::openInventory()
TextDest *txt_dst = new TextDestPlayerInventory(client);
auto *&formspec = m_game_ui->updateFormspec("");
GUIFormSpecMenu::create(formspec, client, &input->joystick, fs_src,
- txt_dst, client->getFormspecPrepend());
+ txt_dst, client->getFormspecPrepend(), sound);
formspec->setFormSpec(fs_src->getForm(), inventoryloc);
}
@@ -1490,52 +1488,37 @@ void Game::toggleMinimap(bool shift_pressed)
if (!mapper || !m_game_ui->m_flags.show_hud || !g_settings->getBool("enable_minimap"))
return;
- if (shift_pressed) {
+ if (shift_pressed)
mapper->toggleMinimapShape();
- return;
- }
+ else
+ mapper->nextMode();
+ // TODO: When legacy minimap is deprecated, keep only HUD minimap stuff here
+
+ // Not so satisying code to keep compatibility with old fixed mode system
+ // -->
u32 hud_flags = client->getEnv().getLocalPlayer()->hud_flags;
- MinimapMode mode = MINIMAP_MODE_OFF;
- if (hud_flags & HUD_FLAG_MINIMAP_VISIBLE) {
- mode = mapper->getMinimapMode();
- mode = (MinimapMode)((int)mode + 1);
- // If radar is disabled and in, or switching to, radar mode
- if (!(hud_flags & HUD_FLAG_MINIMAP_RADAR_VISIBLE) && mode > 3)
- mode = MINIMAP_MODE_OFF;
- }
+ if (!(hud_flags & HUD_FLAG_MINIMAP_VISIBLE)) {
+ m_game_ui->m_flags.show_minimap = false;
+ } else {
- m_game_ui->m_flags.show_minimap = true;
- switch (mode) {
- case MINIMAP_MODE_SURFACEx1:
- m_game_ui->showTranslatedStatusText("Minimap in surface mode, Zoom x1");
- break;
- case MINIMAP_MODE_SURFACEx2:
- m_game_ui->showTranslatedStatusText("Minimap in surface mode, Zoom x2");
- break;
- case MINIMAP_MODE_SURFACEx4:
- m_game_ui->showTranslatedStatusText("Minimap in surface mode, Zoom x4");
- break;
- case MINIMAP_MODE_RADARx1:
- m_game_ui->showTranslatedStatusText("Minimap in radar mode, Zoom x1");
- break;
- case MINIMAP_MODE_RADARx2:
- m_game_ui->showTranslatedStatusText("Minimap in radar mode, Zoom x2");
- break;
- case MINIMAP_MODE_RADARx4:
- m_game_ui->showTranslatedStatusText("Minimap in radar mode, Zoom x4");
- break;
- default:
- mode = MINIMAP_MODE_OFF;
- m_game_ui->m_flags.show_minimap = false;
- if (hud_flags & HUD_FLAG_MINIMAP_VISIBLE)
- m_game_ui->showTranslatedStatusText("Minimap hidden");
- else
- m_game_ui->showTranslatedStatusText("Minimap currently disabled by game or mod");
- }
+ // If radar is disabled, try to find a non radar mode or fall back to 0
+ if (!(hud_flags & HUD_FLAG_MINIMAP_RADAR_VISIBLE))
+ while (mapper->getModeIndex() &&
+ mapper->getModeDef().type == MINIMAP_TYPE_RADAR)
+ mapper->nextMode();
- mapper->setMinimapMode(mode);
+ m_game_ui->m_flags.show_minimap = mapper->getModeDef().type !=
+ MINIMAP_TYPE_OFF;
+ }
+ // <--
+ // End of 'not so satifying code'
+ if ((hud_flags & HUD_FLAG_MINIMAP_VISIBLE) ||
+ (hud && hud->hasElementOfType(HUD_ELEM_MINIMAP)))
+ m_game_ui->showStatusText(utf8_to_wide(mapper->getModeDef().label));
+ else
+ m_game_ui->showTranslatedStatusText("Minimap currently disabled by game or mod");
}
void Game::toggleFog()
@@ -1743,8 +1726,8 @@ void Game::updatePlayerControl(const CameraOrientation &cam)
isKeyDown(KeyType::SPECIAL1),
isKeyDown(KeyType::SNEAK),
isKeyDown(KeyType::ZOOM),
- input->getLeftState(),
- input->getRightState(),
+ isKeyDown(KeyType::DIG),
+ isKeyDown(KeyType::PLACE),
cam.camera_pitch,
cam.camera_yaw,
input->joystick.getAxisWithoutDead(JA_SIDEWARD_MOVE),
@@ -1759,8 +1742,8 @@ void Game::updatePlayerControl(const CameraOrientation &cam)
( (u32)(isKeyDown(KeyType::JUMP) & 0x1) << 4) |
( (u32)(isKeyDown(KeyType::SPECIAL1) & 0x1) << 5) |
( (u32)(isKeyDown(KeyType::SNEAK) & 0x1) << 6) |
- ( (u32)(input->getLeftState() & 0x1) << 7) |
- ( (u32)(input->getRightState() & 0x1) << 8) |
+ ( (u32)(isKeyDown(KeyType::DIG) & 0x1) << 7) |
+ ( (u32)(isKeyDown(KeyType::PLACE) & 0x1) << 8) |
( (u32)(isKeyDown(KeyType::ZOOM) & 0x1) << 9)
);
@@ -1898,7 +1881,7 @@ void Game::handleClientEvent_ShowFormSpec(ClientEvent *event, CameraOrientation
auto *&formspec = m_game_ui->updateFormspec(*(event->show_formspec.formname));
GUIFormSpecMenu::create(formspec, client, &input->joystick,
- fs_src, txt_dst, client->getFormspecPrepend());
+ fs_src, txt_dst, client->getFormspecPrepend(), sound);
}
delete event->show_formspec.formspec;
@@ -1911,7 +1894,7 @@ void Game::handleClientEvent_ShowLocalFormSpec(ClientEvent *event, CameraOrienta
LocalFormspecHandler *txt_dst =
new LocalFormspecHandler(*event->show_formspec.formname, client);
GUIFormSpecMenu::create(m_game_ui->getFormspecGUI(), client, &input->joystick,
- fs_src, txt_dst, client->getFormspecPrepend());
+ fs_src, txt_dst, client->getFormspecPrepend(), sound);
delete event->show_formspec.formspec;
delete event->show_formspec.formname;
@@ -2246,12 +2229,13 @@ void Game::updateCamera(u32 busy_time, f32 dtime)
void Game::updatePlayerCAOVisibility()
{
+ // Make the player visible depending on camera mode.
LocalPlayer *player = client->getEnv().getLocalPlayer();
GenericCAO *playercao = player->getCAO();
if (!playercao)
return;
- playercao->setVisible(camera->getCameraMode() > CAMERA_MODE_FIRST || g_settings->getBool("freecam"));
- playercao->setChildrenVisible(camera->getCameraMode() > CAMERA_MODE_FIRST || g_settings->getBool("freecam"));
+ playercao->updateMeshCulling();
+ playercao->setChildrenVisible(camera->getCameraMode() > CAMERA_MODE_FIRST || g_settings->getBool("freecam"));
}
void Game::updateSound(f32 dtime)
@@ -2348,7 +2332,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug)
PointedThing pointed = updatePointedThing(shootline,
selected_def.liquids_pointable,
- !runData.ldown_for_dig,
+ !runData.btn_down_for_dig,
camera_offset);
if (pointed != runData.pointed_old) {
@@ -2356,20 +2340,18 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug)
hud->updateSelectionMesh(camera_offset);
}
- if (runData.digging_blocked && !input->getLeftState()) {
- // allow digging again if button is not pressed
+ // Allow digging again if button is not pressed
+ if (runData.digging_blocked && !isKeyDown(KeyType::DIG))
runData.digging_blocked = false;
- }
/*
Stop digging when
- - releasing left mouse button
+ - releasing dig button
- pointing away from node
*/
if (runData.digging) {
- if (input->getLeftReleased()) {
- infostream << "Left button released"
- << " (stopped digging)" << std::endl;
+ if (wasKeyReleased(KeyType::DIG)) {
+ infostream << "Dig button released (stopped digging)" << std::endl;
runData.digging = false;
} else if (pointed != runData.pointed_old) {
if (pointed.type == POINTEDTHING_NODE
@@ -2379,8 +2361,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug)
// Still pointing to the same node, but a different face.
// Don't reset.
} else {
- infostream << "Pointing away from node"
- << " (stopped digging)" << std::endl;
+ infostream << "Pointing away from node (stopped digging)" << std::endl;
runData.digging = false;
hud->updateSelectionMesh(camera_offset);
}
@@ -2391,55 +2372,57 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug)
client->setCrack(-1, v3s16(0, 0, 0));
runData.dig_time = 0.0;
}
- } else if (runData.dig_instantly && input->getLeftReleased()) {
- // Remove e.g. torches faster when clicking instead of holding LMB
+ } else if (runData.dig_instantly && wasKeyReleased(KeyType::DIG)) {
+ // Remove e.g. torches faster when clicking instead of holding dig button
runData.nodig_delay_timer = 0;
runData.dig_instantly = false;
}
- if (!runData.digging && runData.ldown_for_dig && !input->getLeftState()) {
- runData.ldown_for_dig = false;
- }
+ if (!runData.digging && runData.btn_down_for_dig && !isKeyDown(KeyType::DIG))
+ runData.btn_down_for_dig = false;
- runData.left_punch = false;
+ runData.punching = false;
soundmaker->m_player_leftpunch_sound.name = "";
// Prepare for repeating, unless we're not supposed to
- if ((input->getRightState() || g_settings->getBool("autoplace")) && !g_settings->getBool("safe_dig_and_place"))
- runData.repeat_rightclick_timer += dtime;
+ if ((isKeyDown(KeyType::PLACE) || g_settings->getBool("autoplace")) && !g_settings->getBool("safe_dig_and_place"))
+ runData.repeat_place_timer += dtime;
else
- runData.repeat_rightclick_timer = 0;
+ runData.repeat_place_timer = 0;
- if (selected_def.usable && input->getLeftState()) {
- if (input->getLeftClicked() && (!client->modsLoaded()
- || !client->getScript()->on_item_use(selected_item, pointed)))
+ if (selected_def.usable && isKeyDown(KeyType::DIG)) {
+ if (wasKeyPressed(KeyType::DIG) && (!client->modsLoaded() ||
+ !client->getScript()->on_item_use(selected_item, pointed)))
client->interact(INTERACT_USE, pointed);
} else if (pointed.type == POINTEDTHING_NODE) {
handlePointingAtNode(pointed, selected_item, hand_item, dtime);
} else if (pointed.type == POINTEDTHING_OBJECT) {
v3f player_position = player->getPosition();
handlePointingAtObject(pointed, tool_item, player_position, show_debug);
- } else if (input->getLeftState()) {
+ } else if (isKeyDown(KeyType::DIG)) {
// When button is held down in air, show continuous animation
- runData.left_punch = true;
+ runData.punching = true;
// Run callback even though item is not usable
- if (input->getLeftClicked() && client->modsLoaded())
+ if (wasKeyPressed(KeyType::DIG) && client->modsLoaded())
client->getScript()->on_item_use(selected_item, pointed);
- } else if (input->getRightClicked()) {
+ } else if (wasKeyPressed(KeyType::PLACE)) {
handlePointingAtNothing(selected_item);
}
runData.pointed_old = pointed;
- if (runData.left_punch || input->getLeftClicked())
- camera->setDigging(0); // left click animation
+ if (runData.punching || wasKeyPressed(KeyType::DIG))
+ camera->setDigging(0); // dig animation
+
+ input->clearWasKeyPressed();
+ input->clearWasKeyReleased();
- input->resetLeftClicked();
- input->resetRightClicked();
+ input->joystick.clearWasKeyDown(KeyType::DIG);
+ input->joystick.clearWasKeyDown(KeyType::PLACE);
- input->resetLeftReleased();
- input->resetRightReleased();
+ input->joystick.clearWasKeyReleased(KeyType::DIG);
+ input->joystick.clearWasKeyReleased(KeyType::PLACE);
}
@@ -2537,7 +2520,7 @@ PointedThing Game::updatePointedThing(
void Game::handlePointingAtNothing(const ItemStack &playerItem)
{
- infostream << "Right Clicked in Air" << std::endl;
+ infostream << "Attempted to place item while pointing at nothing" << std::endl;
PointedThing fauxPointed;
fauxPointed.type = POINTEDTHING_NOTHING;
client->interact(INTERACT_ACTIVATE, fauxPointed);
@@ -2556,7 +2539,7 @@ void Game::handlePointingAtNode(const PointedThing &pointed,
ClientMap &map = client->getEnv().getClientMap();
- if (((runData.nodig_delay_timer <= 0.0 || g_settings->getBool("fastdig")) && (input->getLeftState() || g_settings->getBool("autodig"))
+ if (((runData.nodig_delay_timer <= 0.0 || g_settings->getBool("fastdig")) && (isKeyDown(KeyType::DIG) || g_settings->getBool("autodig"))
&& !runData.digging_blocked
&& client->checkPrivilege("interact"))
) {
@@ -2578,14 +2561,14 @@ void Game::handlePointingAtNode(const PointedThing &pointed,
}
}
- if ((input->getRightState() || g_settings->getBool("autoplace")) &&
- (input->getRightClicked() ||
- (runData.repeat_rightclick_timer >= (g_settings->getBool("fastplace") ? 0 : m_repeat_right_click_time))) &&
+ if (((wasKeyPressed(KeyType::PLACE) || g_settings->getBool("autoplace")) ||
+ (runData.repeat_place_timer >= (g_settings->getBool("fastplace") ? 0 : m_repeat_place_time))) &&
client->checkPrivilege("interact")) {
- runData.repeat_rightclick_timer = 0;
- infostream << "Ground right-clicked" << std::endl;
+ runData.repeat_place_timer = 0;
+ infostream << "Place button pressed while looking at ground" << std::endl;
- camera->setDigging(1); // right click animation (always shown for feedback)
+ // Placing animation (always shown for feedback)
+ camera->setDigging(1);
soundmaker->m_player_rightpunch_sound = SimpleSoundSpec();
@@ -2636,7 +2619,7 @@ bool Game::nodePlacement(const ItemDefinition &selected_def,
auto *&formspec = m_game_ui->updateFormspec("");
GUIFormSpecMenu::create(formspec, client, &input->joystick, fs_src,
- txt_dst, client->getFormspecPrepend());
+ txt_dst, client->getFormspecPrepend(), sound);
formspec->setFormSpec(meta->getString("formspec"), inventoryloc);
return false;
@@ -2651,8 +2634,7 @@ bool Game::nodePlacement(const ItemDefinition &selected_def,
}
verbosestream << "Node placement prediction for "
- << selected_def.name << " is "
- << prediction << std::endl;
+ << selected_def.name << " is " << prediction << std::endl;
v3s16 p = neighbourpos;
// Place inside node itself if buildable_to
@@ -2663,6 +2645,7 @@ bool Game::nodePlacement(const ItemDefinition &selected_def,
} else {
node = map.getNode(p, &is_valid_position);
if (is_valid_position && !nodedef->get(node).buildable_to) {
+ soundmaker->m_player_rightpunch_sound = selected_def.sound_place_failed;
// Report to server
client->interact(INTERACT_PLACE, pointed);
return false;
@@ -2735,6 +2718,7 @@ bool Game::nodePlacement(const ItemDefinition &selected_def,
pp = p + v3s16(0, -1, 0);
if (!nodedef->get(map.getNode(pp)).walkable) {
+ soundmaker->m_player_rightpunch_sound = selected_def.sound_place_failed;
// Report to server
client->interact(INTERACT_PLACE, pointed);
return false;
@@ -2811,7 +2795,7 @@ void Game::handlePointingAtObject(const PointedThing &pointed,
m_game_ui->setInfoText(infotext);
- if (input->getLeftState() || g_settings->getBool("autohit")) {
+ if (isKeyDown(KeyType::DIG) || g_settings->getBool("autohit")) {
bool do_punch = false;
bool do_punch_damage = false;
@@ -2821,12 +2805,12 @@ void Game::handlePointingAtObject(const PointedThing &pointed,
runData.object_hit_delay_timer = object_hit_delay;
}
- if (input->getLeftClicked())
+ if (wasKeyPressed(KeyType::DIG))
do_punch = true;
if (do_punch) {
- infostream << "Left-clicked object" << std::endl;
- runData.left_punch = true;
+ infostream << "Punched object" << std::endl;
+ runData.punching = true;
}
if (do_punch_damage) {
@@ -2842,8 +2826,8 @@ void Game::handlePointingAtObject(const PointedThing &pointed,
client->interact(INTERACT_START_DIGGING, pointed);
}
}
- } else if (input->getRightClicked()) {
- infostream << "Right-clicked object" << std::endl;
+ } else if (wasKeyDown(KeyType::PLACE)) {
+ infostream << "Pressed place button while pointing at object" << std::endl;
client->interact(INTERACT_PLACE, pointed); // place
}
}
@@ -2893,7 +2877,7 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos,
return;
client->interact(INTERACT_START_DIGGING, pointed);
runData.digging = true;
- runData.ldown_for_dig = true;
+ runData.btn_down_for_dig = true;
}
if (!runData.dig_instantly) {
@@ -2987,10 +2971,9 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos,
client->setCrack(-1, nodepos);
}
- camera->setDigging(0); // left click animation
+ camera->setDigging(0); // Dig animation
}
-
void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
const CameraOrientation &cam)
{
@@ -3242,7 +3225,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
/*
Update minimap pos and rotation
*/
- if (mapper && m_game_ui->m_flags.show_minimap && m_game_ui->m_flags.show_hud) {
+ if (mapper && m_game_ui->m_flags.show_hud) {
mapper->setPos(floatToInt(player->getPosition(), BS));
mapper->setAngle(player->getYaw());
}
@@ -3250,7 +3233,27 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
/*
End scene
*/
-
+ if (++m_reset_HW_buffer_counter > 500) {
+ /*
+ Periodically remove all mesh HW buffers.
+
+ Work around for a quirk in Irrlicht where a HW buffer is only
+ released after 20000 iterations (triggered from endScene()).
+
+ Without this, all loaded but unused meshes will retain their HW
+ buffers for at least 5 minutes, at which point looking up the HW buffers
+ becomes a bottleneck and the framerate drops (as much as 30%).
+
+ Tests showed that numbers between 50 and 1000 are good, so picked 500.
+ There are no other public Irrlicht APIs that allow interacting with the
+ HW buffers without tracking the status of every individual mesh.
+
+ The HW buffers for _visible_ meshes will be reinitialized in the next frame.
+ */
+ infostream << "Game::updateFrame(): Removing all HW buffers." << std::endl;
+ driver->removeAllHardwareBuffers();
+ m_reset_HW_buffer_counter = 0;
+ }
driver->endScene();
stats->drawtime = tt_draw.stop(true);
@@ -3286,9 +3289,10 @@ inline void Game::limitFps(FpsControl *fps_timings, f32 *dtime)
else
fps_timings->busy_time = 0;
- u32 frametime_min = 1000 / (g_menumgr.pausesGame()
- ? g_settings->getFloat("pause_fps_max")
- : g_settings->getFloat("fps_max"));
+ u32 frametime_min = 1000 / (
+ device->isWindowFocused() && !g_menumgr.pausesGame()
+ ? g_settings->getFloat("fps_max")
+ : g_settings->getFloat("fps_max_unfocused"));
if (fps_timings->busy_time < frametime_min) {
fps_timings->sleep_time = frametime_min - fps_timings->busy_time;
@@ -3354,7 +3358,7 @@ void Game::readSettings()
m_cache_enable_fog = g_settings->getBool("enable_fog");
m_cache_mouse_sensitivity = g_settings->getFloat("mouse_sensitivity");
m_cache_joystick_frustum_sensitivity = g_settings->getFloat("joystick_frustum_sensitivity");
- m_repeat_right_click_time = g_settings->getFloat("repeat_rightclick_time");
+ m_repeat_place_time = g_settings->getFloat("repeat_place_time");
m_cache_enable_noclip = g_settings->getBool("noclip");
m_cache_enable_free_move = g_settings->getBool("free_move");
@@ -3419,7 +3423,7 @@ void Game::showDeathFormspec()
auto *&formspec = m_game_ui->getFormspecGUI();
GUIFormSpecMenu::create(formspec, client, &input->joystick,
- fs_src, txt_dst, client->getFormspecPrepend());
+ fs_src, txt_dst, client->getFormspecPrepend(), sound);
formspec->setFocus("btn_respawn");
}
@@ -3446,14 +3450,14 @@ void Game::showPauseMenu()
"- %s: move backwards\n"
"- %s: move left\n"
"- %s: move right\n"
- "- %s: jump/climb\n"
- "- %s: sneak/go down\n"
+ "- %s: jump/climb up\n"
+ "- %s: dig/punch\n"
+ "- %s: place/use\n"
+ "- %s: sneak/climb down\n"
"- %s: drop item\n"
"- %s: inventory\n"
"- %s: enderchest\n"
"- Mouse: turn/look\n"
- "- Mouse left: dig/punch\n"
- "- Mouse right: place/use\n"
"- Mouse wheel: select item\n"
"- %s: chat\n"
"- %s: Killaura\n"
@@ -3470,6 +3474,8 @@ void Game::showPauseMenu()
GET_KEY_NAME(keymap_left),
GET_KEY_NAME(keymap_right),
GET_KEY_NAME(keymap_jump),
+ GET_KEY_NAME(keymap_dig),
+ GET_KEY_NAME(keymap_place),
GET_KEY_NAME(keymap_sneak),
GET_KEY_NAME(keymap_drop),
GET_KEY_NAME(keymap_inventory),
@@ -3561,7 +3567,7 @@ void Game::showPauseMenu()
auto *&formspec = m_game_ui->getFormspecGUI();
GUIFormSpecMenu::create(formspec, client, &input->joystick,
- fs_src, txt_dst, client->getFormspecPrepend());
+ fs_src, txt_dst, client->getFormspecPrepend(), sound);
formspec->setFocus("btn_continue");
formspec->doPause = true;
}
diff --git a/src/client/game.h b/src/client/game.h
index 51accc679..26117ab86 100644
--- a/src/client/game.h
+++ b/src/client/game.h
@@ -295,7 +295,7 @@ public:
m_sound(sound),
m_ndef(ndef),
makes_footstep_sound(true),
- m_player_step_timer(0),
+ m_player_step_timer(0.0f),
m_player_jump_timer(0.0f)
{
}
@@ -441,14 +441,13 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
CachedVertexShaderSetting<float> m_animation_timer_vertex;
CachedPixelShaderSetting<float> m_animation_timer_pixel;
CachedPixelShaderSetting<float, 3> m_day_light;
+ CachedPixelShaderSetting<float, 4> m_star_color;
CachedPixelShaderSetting<float, 3> m_eye_position_pixel;
CachedVertexShaderSetting<float, 3> m_eye_position_vertex;
CachedPixelShaderSetting<float, 3> m_minimap_yaw;
CachedPixelShaderSetting<float, 3> m_camera_offset_pixel;
CachedPixelShaderSetting<float, 3> m_camera_offset_vertex;
CachedPixelShaderSetting<SamplerLayer_t> m_base_texture;
- CachedPixelShaderSetting<SamplerLayer_t> m_normal_texture;
- CachedPixelShaderSetting<SamplerLayer_t> m_texture_flags;
Client *m_client;
public:
@@ -475,14 +474,13 @@ public:
m_animation_timer_vertex("animationTimer"),
m_animation_timer_pixel("animationTimer"),
m_day_light("dayLight"),
+ m_star_color("starColor"),
m_eye_position_pixel("eyePosition"),
m_eye_position_vertex("eyePosition"),
m_minimap_yaw("yawVec"),
m_camera_offset_pixel("cameraOffset"),
m_camera_offset_vertex("cameraOffset"),
m_base_texture("baseTexture"),
- m_normal_texture("normalTexture"),
- m_texture_flags("textureFlags"),
m_client(client)
{
g_settings->registerChangedCallback("enable_fog", settingsCallback, this);
@@ -528,6 +526,10 @@ public:
sunlight.b };
m_day_light.set(dnc, services);
+ video::SColorf star_color = m_sky->getCurrentStarColor();
+ float clr[4] = {star_color.r, star_color.g, star_color.b, star_color.a};
+ m_star_color.set(clr, services);
+
u32 animation_timer = porting::getTimeMs() % 1000000;
float animation_timer_f = (float)animation_timer / 100000.f;
m_animation_timer_vertex.set(&animation_timer_f, services);
@@ -570,12 +572,8 @@ public:
m_camera_offset_pixel.set(camera_offset_array, services);
m_camera_offset_vertex.set(camera_offset_array, services);
- SamplerLayer_t base_tex = 0,
- normal_tex = 1,
- flags_tex = 2;
+ SamplerLayer_t base_tex = 0;
m_base_texture.set(&base_tex, services);
- m_normal_texture.set(&normal_tex, services);
- m_texture_flags.set(&flags_tex, services);
}
};
@@ -621,7 +619,6 @@ public:
#endif
/****************************************************************************
-
****************************************************************************/
const float object_hit_delay = 0.2;
@@ -642,7 +639,8 @@ struct GameRunData {
u16 new_playeritem;
PointedThing pointed_old;
bool digging;
- bool ldown_for_dig;
+ bool punching;
+ bool btn_down_for_dig;
bool dig_instantly;
bool digging_blocked;
bool left_punch;
@@ -650,7 +648,7 @@ struct GameRunData {
float nodig_delay_timer;
float dig_time;
float dig_time_complete;
- float repeat_rightclick_timer;
+ float repeat_place_timer;
float object_hit_delay_timer;
float time_from_last_punch;
ClientActiveObject *selected_object;
@@ -802,6 +800,14 @@ public:
{
return input->wasKeyDown(k);
}
+ inline bool wasKeyPressed(GameKeyType k)
+ {
+ return input->wasKeyPressed(k);
+ }
+ inline bool wasKeyReleased(GameKeyType k)
+ {
+ return input->wasKeyReleased(k);
+ }
#ifdef __ANDROID__
void handleAndroidChatInput();
@@ -891,7 +897,6 @@ public:
bool *reconnect_requested;
scene::ISceneNode *skybox;
- bool random_input;
bool simple_singleplayer_mode;
/* End 'cache' */
@@ -916,7 +921,7 @@ public:
bool m_cache_enable_free_move;
f32 m_cache_mouse_sensitivity;
f32 m_cache_joystick_frustum_sensitivity;
- f32 m_repeat_right_click_time;
+ f32 m_repeat_place_time;
f32 m_cache_cam_smoothing;
f32 m_cache_fog_start;
@@ -929,6 +934,7 @@ public:
CameraOrientation cam_view_target = { 0 };
CameraOrientation cam_view = { 0 };
+ int m_reset_HW_buffer_counter = 0;
#ifdef __ANDROID__
bool m_cache_hold_aux1;
bool m_android_chat_open;
diff --git a/src/client/gameui.cpp b/src/client/gameui.cpp
index a9057052e..0c1da3915 100644
--- a/src/client/gameui.cpp
+++ b/src/client/gameui.cpp
@@ -64,17 +64,6 @@ void GameUI::init()
m_guitext2 = gui::StaticText::add(guienv, L"", core::rect<s32>(0, 0, 0, 0), false,
false, guiroot);
- // At the middle of the screen
- // Object infos are shown in this
- m_guitext_info = gui::StaticText::add(guienv, L"",
- core::rect<s32>(0, 0, 400, g_fontengine->getTextHeight() * 5 + 5)
- + v2s32(100, 200), false, true, guiroot);
-
- // Status text (displays info when showing and hiding GUI stuff, etc.)
- m_guitext_status = gui::StaticText::add(guienv, L"<Status>",
- core::rect<s32>(0, 0, 0, 0), false, false, guiroot);
- m_guitext_status->setVisible(false);
-
// Chat text
m_guitext_chat = gui::StaticText::add(guienv, L"", core::rect<s32>(0, 0, 0, 0),
//false, false); // Disable word wrap as of now
@@ -85,6 +74,20 @@ void GameUI::init()
chat_font_size, FM_Unspecified));
}
+ // At the middle of the screen
+ // Object infos are shown in this
+ u32 chat_font_height = m_guitext_chat->getActiveFont()->getDimension(L"Ay").Height;
+ m_guitext_info = gui::StaticText::add(guienv, L"",
+ core::rect<s32>(0, 0, 400, g_fontengine->getTextHeight() * 5 + 5) +
+ v2s32(100, chat_font_height *
+ (g_settings->getU16("recent_chat_messages") + 3)),
+ false, true, guiroot);
+
+ // Status text (displays info when showing and hiding GUI stuff, etc.)
+ m_guitext_status = gui::StaticText::add(guienv, L"<Status>",
+ core::rect<s32>(0, 0, 0, 0), false, false, guiroot);
+ m_guitext_status->setVisible(false);
+
// Profiler text (size is updated when text is updated)
m_guitext_profiler = gui::StaticText::add(guienv, L"<Profiler>",
core::rect<s32>(0, 0, 0, 0), false, false, guiroot);
@@ -132,8 +135,8 @@ void GameUI::update(const RunStats &stats, Client *client, MapDrawControl *draw_
<< std::setprecision(1)
<< " | view range: "
<< (draw_control->range_all ? "All" : itos(draw_control->wanted_range))
- << std::setprecision(3)
- << " | RTT: " << client->getRTT() << "s";
+ << std::setprecision(2)
+ << " | RTT: " << (client->getRTT() * 1000.0f) << "ms";
setStaticText(m_guitext, utf8_to_wide(os.str()).c_str());
m_guitext->setRelativePosition(core::rect<s32>(5, 5, screensize.X,
@@ -149,9 +152,9 @@ void GameUI::update(const RunStats &stats, Client *client, MapDrawControl *draw_
<< "pos: (" << (player_position.X / BS)
<< ", " << (player_position.Y / BS)
<< ", " << (player_position.Z / BS)
- << ") | yaw: " << (wrapDegrees_0_360(cam.camera_yaw)) << "\xC2\xB0 "
+ << ") | yaw: " << (wrapDegrees_0_360(cam.camera_yaw)) << "° "
<< yawToDirectionString(cam.camera_yaw)
- << " | pitch: " << (-wrapDegrees_180(cam.camera_pitch)) << "\xC2\xB0"
+ << " | pitch: " << (-wrapDegrees_180(cam.camera_pitch)) << "°"
<< " | seed: " << ((u64)client->getMapSeed());
if (pointed_old.type == POINTEDTHING_NODE) {
diff --git a/src/client/guiscalingfilter.cpp b/src/client/guiscalingfilter.cpp
index 4262331bd..406c096e6 100644
--- a/src/client/guiscalingfilter.cpp
+++ b/src/client/guiscalingfilter.cpp
@@ -172,11 +172,8 @@ void draw2DImageFilterScaled(video::IVideoDriver *driver, video::ITexture *txr,
void draw2DImage9Slice(video::IVideoDriver *driver, video::ITexture *texture,
const core::rect<s32> &rect, const core::rect<s32> &middle,
- const core::rect<s32> *cliprect)
+ const core::rect<s32> *cliprect, const video::SColor *const colors)
{
- const video::SColor color(255,255,255,255);
- const video::SColor colors[] = {color,color,color,color};
-
auto originalSize = texture->getOriginalSize();
core::vector2di lowerRightOffset = core::vector2di(originalSize.Width, originalSize.Height) - middle.LowerRightCorner;
diff --git a/src/client/guiscalingfilter.h b/src/client/guiscalingfilter.h
index b703d91f0..379a4bdb0 100644
--- a/src/client/guiscalingfilter.h
+++ b/src/client/guiscalingfilter.h
@@ -54,4 +54,5 @@ void draw2DImageFilterScaled(video::IVideoDriver *driver, video::ITexture *txr,
*/
void draw2DImage9Slice(video::IVideoDriver *driver, video::ITexture *texture,
const core::rect<s32> &rect, const core::rect<s32> &middle,
- const core::rect<s32> *cliprect = nullptr);
+ const core::rect<s32> *cliprect = nullptr,
+ const video::SColor *const colors = nullptr);
diff --git a/src/client/hud.cpp b/src/client/hud.cpp
index 2b347c1e0..f6497fe25 100644
--- a/src/client/hud.cpp
+++ b/src/client/hud.cpp
@@ -36,6 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mesh.h"
#include "wieldmesh.h"
#include "client/renderingengine.h"
+#include "client/minimap.h"
#ifdef HAVE_TOUCHSCREENGUI
#include "gui/touchscreengui.h"
@@ -114,6 +115,28 @@ Hud::Hud(gui::IGUIEnvironment *guienv, Client *client, LocalPlayer *player,
} else {
m_selection_material.MaterialType = video::EMT_SOLID;
}
+
+ // Prepare mesh for compass drawing
+ m_rotation_mesh_buffer.Vertices.set_used(4);
+ m_rotation_mesh_buffer.Indices.set_used(6);
+
+ video::SColor white(255, 255, 255, 255);
+ v3f normal(0.f, 0.f, 1.f);
+
+ m_rotation_mesh_buffer.Vertices[0] = video::S3DVertex(v3f(-1.f, -1.f, 0.f), normal, white, v2f(0.f, 1.f));
+ m_rotation_mesh_buffer.Vertices[1] = video::S3DVertex(v3f(-1.f, 1.f, 0.f), normal, white, v2f(0.f, 0.f));
+ m_rotation_mesh_buffer.Vertices[2] = video::S3DVertex(v3f( 1.f, 1.f, 0.f), normal, white, v2f(1.f, 0.f));
+ m_rotation_mesh_buffer.Vertices[3] = video::S3DVertex(v3f( 1.f, -1.f, 0.f), normal, white, v2f(1.f, 1.f));
+
+ m_rotation_mesh_buffer.Indices[0] = 0;
+ m_rotation_mesh_buffer.Indices[1] = 1;
+ m_rotation_mesh_buffer.Indices[2] = 2;
+ m_rotation_mesh_buffer.Indices[3] = 2;
+ m_rotation_mesh_buffer.Indices[4] = 3;
+ m_rotation_mesh_buffer.Indices[5] = 0;
+
+ m_rotation_mesh_buffer.getMaterial().Lighting = false;
+ m_rotation_mesh_buffer.getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
}
Hud::~Hud()
@@ -275,6 +298,18 @@ void Hud::drawItems(v2s32 upperleftpos, v2s32 screen_offset, s32 itemcount,
}
}
+bool Hud::hasElementOfType(HudElementType type)
+{
+ for (size_t i = 0; i != player->maxHudId(); i++) {
+ HudElement *e = player->getHud(i);
+ if (!e)
+ continue;
+ if (e->type == type)
+ return true;
+ }
+ return false;
+}
+
// Calculates screen position of waypoint. Returns true if waypoint is visible (in front of the player), else false.
bool Hud::calculateScreenPos(const v3s16 &camera_offset, HudElement *e, v2s32 *pos)
{
@@ -423,6 +458,69 @@ void Hud::drawLuaElements(const v3s16 &camera_offset)
core::rect<s32>(core::position2d<s32>(0,0), imgsize),
NULL, colors, true);
break; }
+ case HUD_ELEM_COMPASS: {
+ video::ITexture *texture = tsrc->getTexture(e->text);
+ if (!texture)
+ continue;
+
+ // Positionning :
+ v2s32 dstsize(e->size.X, e->size.Y);
+ if (e->size.X < 0)
+ dstsize.X = m_screensize.X * (e->size.X * -0.01);
+ if (e->size.Y < 0)
+ dstsize.Y = m_screensize.Y * (e->size.Y * -0.01);
+
+ if (dstsize.X <= 0 || dstsize.Y <= 0)
+ return; // Avoid zero divides
+
+ // Angle according to camera view
+ v3f fore(0.f, 0.f, 1.f);
+ scene::ICameraSceneNode *cam = RenderingEngine::get_scene_manager()->getActiveCamera();
+ cam->getAbsoluteTransformation().rotateVect(fore);
+ int angle = - fore.getHorizontalAngle().Y;
+
+ // Limit angle and ajust with given offset
+ angle = (angle + (int)e->number) % 360;
+
+ core::rect<s32> dstrect(0, 0, dstsize.X, dstsize.Y);
+ dstrect += pos + v2s32(
+ (e->align.X - 1.0) * dstsize.X / 2,
+ (e->align.Y - 1.0) * dstsize.Y / 2) +
+ v2s32(e->offset.X * m_hud_scaling, e->offset.Y * m_hud_scaling);
+
+ switch (e->dir) {
+ case HUD_COMPASS_ROTATE:
+ drawCompassRotate(e, texture, dstrect, angle);
+ break;
+ case HUD_COMPASS_ROTATE_REVERSE:
+ drawCompassRotate(e, texture, dstrect, -angle);
+ break;
+ case HUD_COMPASS_TRANSLATE:
+ drawCompassTranslate(e, texture, dstrect, angle);
+ break;
+ case HUD_COMPASS_TRANSLATE_REVERSE:
+ drawCompassTranslate(e, texture, dstrect, -angle);
+ break;
+ default:
+ break;
+ }
+ break; }
+ case HUD_ELEM_MINIMAP: {
+ if (e->size.X <= 0 || e->size.Y <= 0)
+ break;
+ if (!client->getMinimap())
+ break;
+ // Draw a minimap of size "size"
+ v2s32 dstsize(e->size.X * m_scale_factor,
+ e->size.Y * m_scale_factor);
+ // (no percent size as minimap would likely be anamorphosed)
+ v2s32 offset((e->align.X - 1.0) * dstsize.X / 2,
+ (e->align.Y - 1.0) * dstsize.Y / 2);
+ core::rect<s32> rect(0, 0, dstsize.X, dstsize.Y);
+ rect += pos + offset + v2s32(e->offset.X * m_scale_factor,
+ e->offset.Y * m_scale_factor);
+ client->getMinimap()->drawMinimap(rect);
+ break; }
default:
infostream << "Hud::drawLuaElements: ignoring drawform " << e->type <<
" of hud element ID " << i << " due to unrecognized type" << std::endl;
@@ -430,6 +528,76 @@ void Hud::drawLuaElements(const v3s16 &camera_offset)
}
}
+void Hud::drawCompassTranslate(HudElement *e, video::ITexture *texture,
+ const core::rect<s32> &rect, int angle)
+{
+ const video::SColor color(255, 255, 255, 255);
+ const video::SColor colors[] = {color, color, color, color};
+
+ // Compute source image scaling
+ core::dimension2di imgsize(texture->getOriginalSize());
+ core::rect<s32> srcrect(0, 0, imgsize.Width, imgsize.Height);
+
+ v2s32 dstsize(rect.getHeight() * e->scale.X * imgsize.Width / imgsize.Height,
+ rect.getHeight() * e->scale.Y);
+
+ // Avoid infinite loop
+ if (dstsize.X <= 0 || dstsize.Y <= 0)
+ return;
+
+ core::rect<s32> tgtrect(0, 0, dstsize.X, dstsize.Y);
+ tgtrect += v2s32(
+ (rect.getWidth() - dstsize.X) / 2,
+ (rect.getHeight() - dstsize.Y) / 2) +
+ rect.UpperLeftCorner;
+
+ int offset = angle * dstsize.X / 360;
+
+ tgtrect += v2s32(offset, 0);
+
+ // Repeat image as much as needed
+ while (tgtrect.UpperLeftCorner.X > rect.UpperLeftCorner.X)
+ tgtrect -= v2s32(dstsize.X, 0);
+
+ draw2DImageFilterScaled(driver, texture, tgtrect, srcrect, &rect, colors, true);
+ tgtrect += v2s32(dstsize.X, 0);
+
+ while (tgtrect.UpperLeftCorner.X < rect.LowerRightCorner.X) {
+ draw2DImageFilterScaled(driver, texture, tgtrect, srcrect, &rect, colors, true);
+ tgtrect += v2s32(dstsize.X, 0);
+ }
+}
+
+void Hud::drawCompassRotate(HudElement *e, video::ITexture *texture,
+ const core::rect<s32> &rect, int angle)
+{
+ core::dimension2di imgsize(texture->getOriginalSize());
+
+ core::rect<s32> oldViewPort = driver->getViewPort();
+ core::matrix4 oldProjMat = driver->getTransform(video::ETS_PROJECTION);
+ core::matrix4 oldViewMat = driver->getTransform(video::ETS_VIEW);
+
+ core::matrix4 Matrix;
+ Matrix.makeIdentity();
+ Matrix.setRotationDegrees(v3f(0.f, 0.f, angle));
+
+ driver->setViewPort(rect);
+ driver->setTransform(video::ETS_PROJECTION, core::matrix4());
+ driver->setTransform(video::ETS_VIEW, core::matrix4());
+ driver->setTransform(video::ETS_WORLD, Matrix);
+
+ video::SMaterial &material = m_rotation_mesh_buffer.getMaterial();
+ material.TextureLayer[0].Texture = texture;
+ driver->setMaterial(material);
+ driver->drawMeshBuffer(&m_rotation_mesh_buffer);
+
+ driver->setTransform(video::ETS_WORLD, core::matrix4());
+ driver->setTransform(video::ETS_VIEW, oldViewMat);
+ driver->setTransform(video::ETS_PROJECTION, oldProjMat);
+
+ // restore the view area
+ driver->setViewPort(oldViewPort);
+}
void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir,
const std::string &texture, const std::string &bgtexture,
diff --git a/src/client/hud.h b/src/client/hud.h
index ba34d479d..d46545d71 100644
--- a/src/client/hud.h
+++ b/src/client/hud.h
@@ -81,6 +81,8 @@ public:
m_selected_face_normal = face_normal;
}
+ bool hasElementOfType(HudElementType type);
+
void drawLuaElements(const v3s16 &camera_offset);
private:
@@ -95,6 +97,12 @@ private:
void drawItem(const ItemStack &item, const core::rect<s32> &rect, bool selected);
+ void drawCompassTranslate(HudElement *e, video::ITexture *texture,
+ const core::rect<s32> &rect, int way);
+
+ void drawCompassRotate(HudElement *e, video::ITexture *texture,
+ const core::rect<s32> &rect, int way);
+
float m_hud_scaling; // cached minetest setting
float m_scale_factor;
v3s16 m_camera_offset;
@@ -115,6 +123,8 @@ private:
video::SMaterial m_selection_material;
+ scene::SMeshBuffer m_rotation_mesh_buffer;
+
enum
{
HIGHLIGHT_BOX,
diff --git a/src/client/inputhandler.cpp b/src/client/inputhandler.cpp
index 418e41931..37ab838c0 100644
--- a/src/client/inputhandler.cpp
+++ b/src/client/inputhandler.cpp
@@ -37,6 +37,8 @@ void KeyCache::populate()
key[KeyType::JUMP] = getKeySetting("keymap_jump");
key[KeyType::SPECIAL1] = getKeySetting("keymap_special1");
key[KeyType::SNEAK] = getKeySetting("keymap_sneak");
+ key[KeyType::DIG] = getKeySetting("keymap_dig");
+ key[KeyType::PLACE] = getKeySetting("keymap_place");
key[KeyType::AUTOFORWARD] = getKeySetting("keymap_autoforward");
@@ -122,57 +124,81 @@ bool MyEventReceiver::OnEvent(const SEvent &event)
if (event.EventType == irr::EET_KEY_INPUT_EVENT) {
const KeyPress &keyCode = event.KeyInput;
if (keysListenedFor[keyCode]) {
+ // If the key is being held down then the OS may
+ // send a continuous stream of keydown events.
+ // In this case, we don't want to let this
+ // stream reach the application as it will cause
+ // certain actions to repeat constantly.
if (event.KeyInput.PressedDown) {
+ if (!IsKeyDown(keyCode)) {
+ keyWasDown.set(keyCode);
+ keyWasPressed.set(keyCode);
+ }
keyIsDown.set(keyCode);
- keyWasDown.set(keyCode);
} else {
+ if (IsKeyDown(keyCode))
+ keyWasReleased.set(keyCode);
+
keyIsDown.unset(keyCode);
}
+
return true;
}
- }
#ifdef HAVE_TOUCHSCREENGUI
- // case of touchscreengui we have to handle different events
- if (m_touchscreengui && event.EventType == irr::EET_TOUCH_INPUT_EVENT) {
+ } else if (m_touchscreengui && event.EventType == irr::EET_TOUCH_INPUT_EVENT) {
+ // In case of touchscreengui, we have to handle different events
m_touchscreengui->translateEvent(event);
return true;
- }
#endif
- if (event.EventType == irr::EET_JOYSTICK_INPUT_EVENT) {
+ } else if (event.EventType == irr::EET_JOYSTICK_INPUT_EVENT) {
/* TODO add a check like:
if (event.JoystickEvent != joystick_we_listen_for)
return false;
*/
return joystick->handleEvent(event.JoystickEvent);
- }
- // handle mouse events
- if (event.EventType == irr::EET_MOUSE_INPUT_EVENT) {
- if (isMenuActive()) {
- left_active = false;
- middle_active = false;
- right_active = false;
- } else {
- left_active = event.MouseInput.isLeftPressed();
- middle_active = event.MouseInput.isMiddlePressed();
- right_active = event.MouseInput.isRightPressed();
-
- if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) {
- leftclicked = true;
- }
- if (event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN) {
- rightclicked = true;
- }
- if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) {
- leftreleased = true;
- }
- if (event.MouseInput.Event == EMIE_RMOUSE_LEFT_UP) {
- rightreleased = true;
- }
- if (event.MouseInput.Event == EMIE_MOUSE_WHEEL) {
- mouse_wheel += event.MouseInput.Wheel;
- }
+ } else if (event.EventType == irr::EET_MOUSE_INPUT_EVENT) {
+ // Handle mouse events
+ KeyPress key;
+ switch (event.MouseInput.Event) {
+ case EMIE_LMOUSE_PRESSED_DOWN:
+ key = "KEY_LBUTTON";
+ keyIsDown.set(key);
+ keyWasDown.set(key);
+ keyWasPressed.set(key);
+ break;
+ case EMIE_MMOUSE_PRESSED_DOWN:
+ key = "KEY_MBUTTON";
+ keyIsDown.set(key);
+ keyWasDown.set(key);
+ keyWasPressed.set(key);
+ break;
+ case EMIE_RMOUSE_PRESSED_DOWN:
+ key = "KEY_RBUTTON";
+ keyIsDown.set(key);
+ keyWasDown.set(key);
+ keyWasPressed.set(key);
+ break;
+ case EMIE_LMOUSE_LEFT_UP:
+ key = "KEY_LBUTTON";
+ keyIsDown.unset(key);
+ keyWasReleased.set(key);
+ break;
+ case EMIE_MMOUSE_LEFT_UP:
+ key = "KEY_MBUTTON";
+ keyIsDown.unset(key);
+ keyWasReleased.set(key);
+ break;
+ case EMIE_RMOUSE_LEFT_UP:
+ key = "KEY_RBUTTON";
+ keyIsDown.unset(key);
+ keyWasReleased.set(key);
+ break;
+ case EMIE_MOUSE_WHEEL:
+ mouse_wheel += event.MouseInput.Wheel;
+ break;
+ default: break;
}
} else if (event.EventType == irr::EET_LOG_TEXT_EVENT) {
static const LogLevel irr_loglev_conv[] = {
@@ -199,38 +225,28 @@ s32 RandomInputHandler::Rand(s32 min, s32 max)
return (myrand() % (max - min + 1)) + min;
}
+struct RandomInputHandlerSimData {
+ std::string key;
+ float counter;
+ int time_max;
+};
+
void RandomInputHandler::step(float dtime)
{
- {
- static float counter1 = 0;
- counter1 -= dtime;
- if (counter1 < 0.0) {
- counter1 = 0.1 * Rand(1, 40);
- keydown.toggle(getKeySetting("keymap_jump"));
- }
- }
- {
- static float counter1 = 0;
- counter1 -= dtime;
- if (counter1 < 0.0) {
- counter1 = 0.1 * Rand(1, 40);
- keydown.toggle(getKeySetting("keymap_special1"));
- }
- }
- {
- static float counter1 = 0;
- counter1 -= dtime;
- if (counter1 < 0.0) {
- counter1 = 0.1 * Rand(1, 40);
- keydown.toggle(getKeySetting("keymap_forward"));
- }
- }
- {
- static float counter1 = 0;
- counter1 -= dtime;
- if (counter1 < 0.0) {
- counter1 = 0.1 * Rand(1, 40);
- keydown.toggle(getKeySetting("keymap_left"));
+ static RandomInputHandlerSimData rnd_data[] = {
+ { "keymap_jump", 0.0f, 40 },
+ { "keymap_special1", 0.0f, 40 },
+ { "keymap_forward", 0.0f, 40 },
+ { "keymap_left", 0.0f, 40 },
+ { "keymap_dig", 0.0f, 30 },
+ { "keymap_place", 0.0f, 15 }
+ };
+
+ for (auto &i : rnd_data) {
+ i.counter -= dtime;
+ if (i.counter < 0.0) {
+ i.counter = 0.1 * Rand(1, i.time_max);
+ keydown.toggle(getKeySetting(i.key.c_str()));
}
}
{
@@ -241,29 +257,5 @@ void RandomInputHandler::step(float dtime)
mousespeed = v2s32(Rand(-20, 20), Rand(-15, 20));
}
}
- {
- static float counter1 = 0;
- counter1 -= dtime;
- if (counter1 < 0.0) {
- counter1 = 0.1 * Rand(1, 30);
- leftdown = !leftdown;
- if (leftdown)
- leftclicked = true;
- if (!leftdown)
- leftreleased = true;
- }
- }
- {
- static float counter1 = 0;
- counter1 -= dtime;
- if (counter1 < 0.0) {
- counter1 = 0.1 * Rand(1, 15);
- rightdown = !rightdown;
- if (rightdown)
- rightclicked = true;
- if (!rightdown)
- rightreleased = true;
- }
- }
mousepos += mousespeed;
}
diff --git a/src/client/inputhandler.h b/src/client/inputhandler.h
index e006affb2..b3a7d4ba3 100644
--- a/src/client/inputhandler.h
+++ b/src/client/inputhandler.h
@@ -144,6 +144,14 @@ public:
return b;
}
+ // Checks whether a key was just pressed. State will be cleared
+ // in the subsequent iteration of Game::processPlayerInteraction
+ bool WasKeyPressed(const KeyPress &keycode) const { return keyWasPressed[keycode]; }
+
+ // Checks whether a key was just released. State will be cleared
+ // in the subsequent iteration of Game::processPlayerInteraction
+ bool WasKeyReleased(const KeyPress &keycode) const { return keyWasReleased[keycode]; }
+
void listenForKey(const KeyPress &keyCode) { keysListenedFor.set(keyCode); }
void dontListenForKeys() { keysListenedFor.clear(); }
@@ -158,17 +166,20 @@ public:
{
keyIsDown.clear();
keyWasDown.clear();
+ keyWasPressed.clear();
+ keyWasReleased.clear();
- leftclicked = false;
- rightclicked = false;
- leftreleased = false;
- rightreleased = false;
+ mouse_wheel = 0;
+ }
- left_active = false;
- middle_active = false;
- right_active = false;
+ void clearWasKeyPressed()
+ {
+ keyWasPressed.clear();
+ }
- mouse_wheel = 0;
+ void clearWasKeyReleased()
+ {
+ keyWasReleased.clear();
}
MyEventReceiver()
@@ -178,15 +189,6 @@ public:
#endif
}
- bool leftclicked = false;
- bool rightclicked = false;
- bool leftreleased = false;
- bool rightreleased = false;
-
- bool left_active = false;
- bool middle_active = false;
- bool right_active = false;
-
s32 mouse_wheel = 0;
JoystickController *joystick = nullptr;
@@ -197,8 +199,16 @@ public:
// The current state of keys
KeyList keyIsDown;
- // Whether a key has been pressed or not
+
+ // Whether a key was down
KeyList keyWasDown;
+
+ // Whether a key has just been pressed
+ KeyList keyWasPressed;
+
+ // Whether a key has just been released
+ KeyList keyWasReleased;
+
// List of keys we listen for
// TODO perhaps the type of this is not really
// performant as KeyList is designed for few but
@@ -227,27 +237,19 @@ public:
virtual void setKeypress(const KeyPress &keyCode) = 0;
virtual void unsetKeypress(const KeyPress &keyCode) = 0;
virtual bool wasKeyDown(GameKeyType k) = 0;
+ virtual bool wasKeyPressed(GameKeyType k) = 0;
+ virtual bool wasKeyReleased(GameKeyType k) = 0;
virtual bool cancelPressed() = 0;
+ virtual void clearWasKeyPressed() {}
+ virtual void clearWasKeyReleased() {}
+
virtual void listenForKey(const KeyPress &keyCode) {}
virtual void dontListenForKeys() {}
virtual v2s32 getMousePos() = 0;
virtual void setMousePos(s32 x, s32 y) = 0;
- virtual bool getLeftState() = 0;
- virtual bool getRightState() = 0;
-
- virtual bool getLeftClicked() = 0;
- virtual bool getRightClicked() = 0;
- virtual void resetLeftClicked() = 0;
- virtual void resetRightClicked() = 0;
-
- virtual bool getLeftReleased() = 0;
- virtual bool getRightReleased() = 0;
- virtual void resetLeftReleased() = 0;
- virtual void resetRightReleased() = 0;
-
virtual s32 getMouseWheel() = 0;
virtual void step(float dtime) {}
@@ -285,10 +287,26 @@ public:
{
return m_receiver->WasKeyDown(keycache.key[k]) || joystick.wasKeyDown(k);
}
+ virtual bool wasKeyPressed(GameKeyType k)
+ {
+ return m_receiver->WasKeyPressed(keycache.key[k]) || joystick.wasKeyReleased(k);
+ }
+ virtual bool wasKeyReleased(GameKeyType k)
+ {
+ return m_receiver->WasKeyReleased(keycache.key[k]) || joystick.wasKeyReleased(k);
+ }
virtual bool cancelPressed()
{
return wasKeyDown(KeyType::ESC) || m_receiver->WasKeyDown(CancelKey);
}
+ virtual void clearWasKeyPressed()
+ {
+ m_receiver->clearWasKeyPressed();
+ }
+ virtual void clearWasKeyReleased()
+ {
+ m_receiver->clearWasKeyReleased();
+ }
virtual void listenForKey(const KeyPress &keyCode)
{
m_receiver->listenForKey(keyCode);
@@ -316,59 +334,6 @@ public:
}
}
- virtual bool getLeftState()
- {
- return m_receiver->left_active || joystick.isKeyDown(KeyType::MOUSE_L);
- }
- virtual bool getRightState()
- {
- return m_receiver->right_active || joystick.isKeyDown(KeyType::MOUSE_R);
- }
-
- virtual bool getLeftClicked()
- {
- return m_receiver->leftclicked ||
- joystick.getWasKeyDown(KeyType::MOUSE_L);
- }
- virtual bool getRightClicked()
- {
- return m_receiver->rightclicked ||
- joystick.getWasKeyDown(KeyType::MOUSE_R);
- }
-
- virtual void resetLeftClicked()
- {
- m_receiver->leftclicked = false;
- joystick.clearWasKeyDown(KeyType::MOUSE_L);
- }
- virtual void resetRightClicked()
- {
- m_receiver->rightclicked = false;
- joystick.clearWasKeyDown(KeyType::MOUSE_R);
- }
-
- virtual bool getLeftReleased()
- {
- return m_receiver->leftreleased ||
- joystick.wasKeyReleased(KeyType::MOUSE_L);
- }
- virtual bool getRightReleased()
- {
- return m_receiver->rightreleased ||
- joystick.wasKeyReleased(KeyType::MOUSE_R);
- }
-
- virtual void resetLeftReleased()
- {
- m_receiver->leftreleased = false;
- joystick.clearWasKeyReleased(KeyType::MOUSE_L);
- }
- virtual void resetRightReleased()
- {
- m_receiver->rightreleased = false;
- joystick.clearWasKeyReleased(KeyType::MOUSE_R);
- }
-
virtual s32 getMouseWheel() { return m_receiver->getMouseWheel(); }
void clear()
@@ -402,23 +367,12 @@ public:
keydown.unset(keyCode);
}
virtual bool wasKeyDown(GameKeyType k) { return false; }
+ virtual bool wasKeyPressed(GameKeyType k) { return false; }
+ virtual bool wasKeyReleased(GameKeyType k) { return false; }
virtual bool cancelPressed() { return false; }
virtual v2s32 getMousePos() { return mousepos; }
virtual void setMousePos(s32 x, s32 y) { mousepos = v2s32(x, y); }
- virtual bool getLeftState() { return leftdown; }
- virtual bool getRightState() { return rightdown; }
-
- virtual bool getLeftClicked() { return leftclicked; }
- virtual bool getRightClicked() { return rightclicked; }
- virtual void resetLeftClicked() { leftclicked = false; }
- virtual void resetRightClicked() { rightclicked = false; }
-
- virtual bool getLeftReleased() { return leftreleased; }
- virtual bool getRightReleased() { return rightreleased; }
- virtual void resetLeftReleased() { leftreleased = false; }
- virtual void resetRightReleased() { rightreleased = false; }
-
virtual s32 getMouseWheel() { return 0; }
virtual void step(float dtime);
@@ -429,10 +383,4 @@ private:
KeyList keydown;
v2s32 mousepos;
v2s32 mousespeed;
- bool leftdown = false;
- bool rightdown = false;
- bool leftclicked = false;
- bool rightclicked = false;
- bool leftreleased = false;
- bool rightreleased = false;
};
diff --git a/src/client/joystick_controller.cpp b/src/client/joystick_controller.cpp
index c29e8b639..742115046 100644
--- a/src/client/joystick_controller.cpp
+++ b/src/client/joystick_controller.cpp
@@ -74,8 +74,8 @@ JoystickLayout create_default_layout()
// Accessible without four modifier button pressed
// regardless whether start is pressed or not
- JLO_B_PB(KeyType::MOUSE_L, fb | 1 << 4, 1 << 4);
- JLO_B_PB(KeyType::MOUSE_R, fb | 1 << 5, 1 << 5);
+ JLO_B_PB(KeyType::DIG, fb | 1 << 4, 1 << 4);
+ JLO_B_PB(KeyType::PLACE, fb | 1 << 5, 1 << 5);
// Accessible without any modifier pressed
JLO_B_PB(KeyType::JUMP, bm | 1 << 0, 1 << 0);
@@ -83,9 +83,9 @@ JoystickLayout create_default_layout()
// Accessible with start button not pressed, but four pressed
// TODO find usage for button 0
- JLO_B_PB(KeyType::DROP, bm | 1 << 1, fb | 1 << 1);
- JLO_B_PB(KeyType::SCROLL_UP, bm | 1 << 4, fb | 1 << 4);
- JLO_B_PB(KeyType::SCROLL_DOWN,bm | 1 << 5, fb | 1 << 5);
+ JLO_B_PB(KeyType::DROP, bm | 1 << 1, fb | 1 << 1);
+ JLO_B_PB(KeyType::HOTBAR_PREV, bm | 1 << 4, fb | 1 << 4);
+ JLO_B_PB(KeyType::HOTBAR_NEXT, bm | 1 << 5, fb | 1 << 5);
// Accessible with start button and four pressed
// TODO find usage for buttons 0, 1 and 4, 5
@@ -99,8 +99,8 @@ JoystickLayout create_default_layout()
JLO_A_PB(KeyType::RIGHT, 0, -1, 1024);
// Scroll buttons
- JLO_A_PB(KeyType::SCROLL_UP, 2, -1, 1024);
- JLO_A_PB(KeyType::SCROLL_DOWN, 5, -1, 1024);
+ JLO_A_PB(KeyType::HOTBAR_PREV, 2, -1, 1024);
+ JLO_A_PB(KeyType::HOTBAR_NEXT, 5, -1, 1024);
return jlo;
}
@@ -134,10 +134,10 @@ JoystickLayout create_xbox_layout()
JLO_B_PB(KeyType::SNEAK, 1 << 12, 1 << 12); // right
// Triggers
- JLO_B_PB(KeyType::MOUSE_L, 1 << 6, 1 << 6); // lt
- JLO_B_PB(KeyType::MOUSE_R, 1 << 7, 1 << 7); // rt
- JLO_B_PB(KeyType::SCROLL_UP, 1 << 4, 1 << 4); // lb
- JLO_B_PB(KeyType::SCROLL_DOWN, 1 << 5, 1 << 5); // rb
+ JLO_B_PB(KeyType::DIG, 1 << 6, 1 << 6); // lt
+ JLO_B_PB(KeyType::PLACE, 1 << 7, 1 << 7); // rt
+ JLO_B_PB(KeyType::HOTBAR_PREV, 1 << 4, 1 << 4); // lb
+ JLO_B_PB(KeyType::HOTBAR_NEXT, 1 << 5, 1 << 5); // rb
// D-PAD
JLO_B_PB(KeyType::ZOOM, 1 << 15, 1 << 15); // up
diff --git a/src/client/keys.h b/src/client/keys.h
index 43a032a7b..828ea3ec4 100644
--- a/src/client/keys.h
+++ b/src/client/keys.h
@@ -35,6 +35,8 @@ public:
SPECIAL1,
SNEAK,
AUTOFORWARD,
+ DIG,
+ PLACE,
ESC,
@@ -119,12 +121,6 @@ public:
SLOT_31,
SLOT_32,
- // joystick specific keys
- MOUSE_L,
- MOUSE_R,
- SCROLL_UP,
- SCROLL_DOWN,
-
// Fake keycode for array size and internal checks
INTERNAL_ENUM_COUNT
diff --git a/src/client/localplayer.cpp b/src/client/localplayer.cpp
index 3b52b18e1..7d532c602 100644
--- a/src/client/localplayer.cpp
+++ b/src/client/localplayer.cpp
@@ -19,7 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "localplayer.h"
#include <cmath>
-#include "event.h"
+#include "mtevent.h"
#include "collision.h"
#include "nodedef.h"
#include "settings.h"
diff --git a/src/client/mapblock_mesh.cpp b/src/client/mapblock_mesh.cpp
index f65864599..7b342fc33 100644
--- a/src/client/mapblock_mesh.cpp
+++ b/src/client/mapblock_mesh.cpp
@@ -35,11 +35,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
MeshMakeData
*/
-MeshMakeData::MeshMakeData(Client *client, bool use_shaders,
- bool use_tangent_vertices):
+MeshMakeData::MeshMakeData(Client *client, bool use_shaders):
m_client(client),
- m_use_shaders(use_shaders),
- m_use_tangent_vertices(use_tangent_vertices)
+ m_use_shaders(use_shaders)
{}
void MeshMakeData::fillBlockDataBegin(const v3s16 &blockpos)
@@ -81,33 +79,6 @@ void MeshMakeData::fill(MapBlock *block)
}
}
-void MeshMakeData::fillSingleNode(MapNode *node)
-{
- m_blockpos = v3s16(0,0,0);
-
- v3s16 blockpos_nodes = v3s16(0,0,0);
- VoxelArea area(blockpos_nodes-v3s16(1,1,1)*MAP_BLOCKSIZE,
- blockpos_nodes+v3s16(1,1,1)*MAP_BLOCKSIZE*2-v3s16(1,1,1));
- s32 volume = area.getVolume();
- s32 our_node_index = area.index(1,1,1);
-
- // Allocate this block + neighbors
- m_vmanip.clear();
- m_vmanip.addArea(area);
-
- // Fill in data
- MapNode *data = new MapNode[volume];
- for(s32 i = 0; i < volume; i++)
- {
- if (i == our_node_index)
- data[i] = *node;
- else
- data[i] = MapNode(CONTENT_AIR, LIGHT_MAX, 0);
- }
- m_vmanip.copyFrom(data, area, area.MinEdge, area.MinEdge, area.getExtent());
- delete[] data;
-}
-
void MeshMakeData::setCrack(int crack_level, v3s16 crack_pos)
{
if (crack_level >= 0)
@@ -422,7 +393,16 @@ static void getNodeVertexDirs(const v3s16 &dir, v3s16 *vertex_dirs)
u8 idx = (dir.X + 2 * dir.Y + 3 * dir.Z) & 7;
idx = (idx - 1) * 4;
+#if defined(__GNUC__) && !defined(__clang__)
+#pragma GCC diagnostic push
+#if __GNUC__ > 7
+#pragma GCC diagnostic ignored "-Wclass-memaccess"
+#endif
+#endif
memcpy(vertex_dirs, &vertex_dirs_table[idx], 4 * sizeof(v3s16));
+#if defined(__GNUC__) && !defined(__clang__)
+#pragma GCC diagnostic pop
+#endif
}
static void getNodeTextureCoords(v3f base, const v3f &scale, const v3s16 &dir, float *u, float *v)
@@ -1076,10 +1056,9 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
for (auto &m : m_mesh)
m = new scene::SMesh();
m_enable_shaders = data->m_use_shaders;
- m_use_tangent_vertices = data->m_use_tangent_vertices;
m_enable_vbo = g_settings->getBool("enable_vbo");
- if (g_settings->getBool("enable_minimap")) {
+ if (data->m_client->getMinimap()) {
m_minimap_mapblock = new MinimapMapblock;
m_minimap_mapblock->getMinimapNodes(
&data->m_vmanip, data->m_blockpos * MAP_BLOCKSIZE);
@@ -1256,28 +1235,12 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
scene::SMesh *mesh = (scene::SMesh *)m_mesh[layer];
- // Create meshbuffer, add to mesh
- if (m_use_tangent_vertices) {
- scene::SMeshBufferTangents *buf =
- new scene::SMeshBufferTangents();
- buf->Material = material;
- buf->Vertices.reallocate(p.vertices.size());
- buf->Indices.reallocate(p.indices.size());
- for (const video::S3DVertex &v: p.vertices)
- buf->Vertices.push_back(video::S3DVertexTangents(v.Pos, v.Color, v.TCoords));
- for (u16 i: p.indices)
- buf->Indices.push_back(i);
- buf->recalculateBoundingBox();
- mesh->addMeshBuffer(buf);
- buf->drop();
- } else {
- scene::SMeshBuffer *buf = new scene::SMeshBuffer();
- buf->Material = material;
- buf->append(&p.vertices[0], p.vertices.size(),
- &p.indices[0], p.indices.size());
- mesh->addMeshBuffer(buf);
- buf->drop();
- }
+ scene::SMeshBuffer *buf = new scene::SMeshBuffer();
+ buf->Material = material;
+ buf->append(&p.vertices[0], p.vertices.size(),
+ &p.indices[0], p.indices.size());
+ mesh->addMeshBuffer(buf);
+ buf->drop();
}
/*
@@ -1287,12 +1250,6 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
translateMesh(m_mesh[layer],
intToFloat(data->m_blockpos * MAP_BLOCKSIZE - camera_offset, BS));
- if (m_use_tangent_vertices) {
- scene::IMeshManipulator* meshmanip =
- RenderingEngine::get_scene_manager()->getMeshManipulator();
- meshmanip->recalculateTangents(m_mesh[layer], true, false, false);
- }
-
if (m_mesh[layer]) {
#if 0
// Usually 1-700 faces and 1-7 materials
diff --git a/src/client/mapblock_mesh.h b/src/client/mapblock_mesh.h
index 95fda83e5..ec1faea32 100644
--- a/src/client/mapblock_mesh.h
+++ b/src/client/mapblock_mesh.h
@@ -45,10 +45,8 @@ struct MeshMakeData
Client *m_client;
bool m_use_shaders;
- bool m_use_tangent_vertices;
- MeshMakeData(Client *client, bool use_shaders,
- bool use_tangent_vertices = false);
+ MeshMakeData(Client *client, bool use_shaders);
/*
Copy block data manually (to allow optimizations by the caller)
@@ -63,11 +61,6 @@ struct MeshMakeData
void fill(MapBlock *block);
/*
- Set up with only a single node at (1,1,1)
- */
- void fillSingleNode(MapNode *node);
-
- /*
Set the (node) position of a crack
*/
void setCrack(int crack_level, v3s16 crack_pos);
@@ -143,7 +136,6 @@ private:
IShaderSource *m_shdrsrc;
bool m_enable_shaders;
- bool m_use_tangent_vertices;
bool m_enable_vbo;
// Must animate() be called before rendering?
diff --git a/src/client/mesh.cpp b/src/client/mesh.cpp
index e1ec22068..2400a374c 100644
--- a/src/client/mesh.cpp
+++ b/src/client/mesh.cpp
@@ -203,6 +203,15 @@ void setMeshColor(scene::IMesh *mesh, const video::SColor &color)
setMeshBufferColor(mesh->getMeshBuffer(j), color);
}
+void setMeshBufferTextureCoords(scene::IMeshBuffer *buf, const v2f *uv, u32 count)
+{
+ const u32 stride = getVertexPitchFromType(buf->getVertexType());
+ assert(buf->getVertexCount() >= count);
+ u8 *vertices = (u8 *) buf->getVertices();
+ for (u32 i = 0; i < count; i++)
+ ((video::S3DVertex*) (vertices + i * stride))->TCoords = uv[i];
+}
+
template <typename F>
static void applyToMesh(scene::IMesh *mesh, const F &fn)
{
diff --git a/src/client/mesh.h b/src/client/mesh.h
index 103c61e45..dbc091a06 100644
--- a/src/client/mesh.h
+++ b/src/client/mesh.h
@@ -58,6 +58,13 @@ void setMeshBufferColor(scene::IMeshBuffer *buf, const video::SColor &color);
*/
void setMeshColor(scene::IMesh *mesh, const video::SColor &color);
+
+/*
+ Sets texture coords for vertices in the mesh buffer.
+ `uv[]` must have `count` elements
+*/
+void setMeshBufferTextureCoords(scene::IMeshBuffer *buf, const v2f *uv, u32 count);
+
/*
Set a constant color for an animated mesh
*/
diff --git a/src/client/mesh_generator_thread.cpp b/src/client/mesh_generator_thread.cpp
index 53b980eeb..c8d1cba26 100644
--- a/src/client/mesh_generator_thread.cpp
+++ b/src/client/mesh_generator_thread.cpp
@@ -52,9 +52,6 @@ MeshUpdateQueue::MeshUpdateQueue(Client *client):
m_client(client)
{
m_cache_enable_shaders = g_settings->getBool("enable_shaders");
- m_cache_use_tangent_vertices = m_cache_enable_shaders && (
- g_settings->getBool("enable_bumpmapping") ||
- g_settings->getBool("enable_parallax_occlusion"));
m_cache_smooth_lighting = g_settings->getBool("smooth_lighting");
m_meshgen_block_cache_size = g_settings->getS32("meshgen_block_cache_size");
}
@@ -207,8 +204,7 @@ CachedMapBlockData* MeshUpdateQueue::getCachedBlock(const v3s16 &p)
void MeshUpdateQueue::fillDataFromMapBlockCache(QueuedMeshUpdate *q)
{
- MeshMakeData *data = new MeshMakeData(m_client, m_cache_enable_shaders,
- m_cache_use_tangent_vertices);
+ MeshMakeData *data = new MeshMakeData(m_client, m_cache_enable_shaders);
q->data = data;
data->fillBlockDataBegin(q->p);
diff --git a/src/client/mesh_generator_thread.h b/src/client/mesh_generator_thread.h
index 2bb74589e..8e13dec3e 100644
--- a/src/client/mesh_generator_thread.h
+++ b/src/client/mesh_generator_thread.h
@@ -88,7 +88,6 @@ private:
// TODO: Add callback to update these when g_settings changes
bool m_cache_enable_shaders;
- bool m_cache_use_tangent_vertices;
bool m_cache_smooth_lighting;
int m_meshgen_block_cache_size;
diff --git a/src/client/minimap.cpp b/src/client/minimap.cpp
index 8ea1a0283..60b095712 100644
--- a/src/client/minimap.cpp
+++ b/src/client/minimap.cpp
@@ -25,7 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "shader.h"
#include "mapblock.h"
#include "client/renderingengine.h"
-
+#include "gettext.h"
////
//// MinimapUpdateThread
@@ -108,8 +108,11 @@ void MinimapUpdateThread::doUpdate()
}
}
- if (data->map_invalidated && data->mode != MINIMAP_MODE_OFF) {
- getMap(data->pos, data->map_size, data->scan_height);
+
+ if (data->map_invalidated && (
+ data->mode.type == MINIMAP_TYPE_RADAR ||
+ data->mode.type == MINIMAP_TYPE_SURFACE)) {
+ getMap(data->pos, data->mode.map_size, data->mode.scan_height);
data->map_invalidated = false;
}
}
@@ -181,19 +184,26 @@ Minimap::Minimap(Client *client)
this->m_ndef = client->getNodeDefManager();
m_angle = 0.f;
+ m_current_mode_index = 0;
// Initialize static settings
m_enable_shaders = g_settings->getBool("enable_shaders");
m_surface_mode_scan_height =
g_settings->getBool("minimap_double_scan_height") ? 256 : 128;
+ // Initialize minimap modes
+ addMode(MINIMAP_TYPE_OFF);
+ addMode(MINIMAP_TYPE_SURFACE, 256);
+ addMode(MINIMAP_TYPE_SURFACE, 128);
+ addMode(MINIMAP_TYPE_SURFACE, 64);
+ addMode(MINIMAP_TYPE_RADAR, 512);
+ addMode(MINIMAP_TYPE_RADAR, 256);
+ addMode(MINIMAP_TYPE_RADAR, 128);
+
// Initialize minimap data
data = new MinimapData;
- data->mode = MINIMAP_MODE_OFF;
- data->is_radar = false;
- data->map_invalidated = true;
- data->texture = NULL;
- data->heightmap_texture = NULL;
+ data->map_invalidated = true;
+
data->minimap_shape_round = g_settings->getBool("minimap_shape_round");
// Get round minimap textures
@@ -215,6 +225,8 @@ Minimap::Minimap(Client *client)
// Create object marker texture
data->object_marker_red = m_tsrc->getTexture("object_marker_red.png");
+ setModeIndex(0);
+
// Create mesh buffer for minimap
m_meshbuffer = getMinimapMeshBuffer();
@@ -240,6 +252,10 @@ Minimap::~Minimap()
driver->removeTexture(data->minimap_overlay_square);
driver->removeTexture(data->object_marker_red);
+ for (MinimapMarker *m : m_markers)
+ delete m;
+ m_markers.clear();
+
delete data;
delete m_minimap_update_thread;
}
@@ -280,29 +296,101 @@ MinimapShape Minimap::getMinimapShape()
return MINIMAP_SHAPE_SQUARE;
}
-void Minimap::setMinimapMode(MinimapMode mode)
+void Minimap::setModeIndex(size_t index)
{
- static const MinimapModeDef modedefs[MINIMAP_MODE_COUNT] = {
- {false, 0, 0},
- {false, m_surface_mode_scan_height, 256},
- {false, m_surface_mode_scan_height, 128},
- {false, m_surface_mode_scan_height, 64},
- {true, 32, 128},
- {true, 32, 64},
- {true, 32, 32}
- };
-
- if (mode >= MINIMAP_MODE_COUNT)
- return;
-
MutexAutoLock lock(m_mutex);
- data->is_radar = modedefs[mode].is_radar;
- data->scan_height = modedefs[mode].scan_height;
- data->map_size = modedefs[mode].map_size;
- data->mode = mode;
+ if (index < m_modes.size()) {
+ data->mode = m_modes[index];
+ m_current_mode_index = index;
+ } else {
+ data->mode = MinimapModeDef{MINIMAP_TYPE_OFF, N_("Minimap hidden"), 0, 0, ""};
+ m_current_mode_index = 0;
+ }
- m_minimap_update_thread->deferUpdate();
+ data->map_invalidated = true;
+
+ if (m_minimap_update_thread)
+ m_minimap_update_thread->deferUpdate();
+}
+
+void Minimap::addMode(MinimapModeDef mode)
+{
+ // Check validity
+ if (mode.type == MINIMAP_TYPE_TEXTURE) {
+ if (mode.texture.empty())
+ return;
+ if (mode.scale < 1)
+ mode.scale = 1;
+ }
+
+ int zoom = -1;
+
+ // Build a default standard label
+ if (mode.label == "") {
+ switch (mode.type) {
+ case MINIMAP_TYPE_OFF:
+ mode.label = N_("Minimap hidden");
+ break;
+ case MINIMAP_TYPE_SURFACE:
+ mode.label = N_("Minimap in surface mode, Zoom x%d");
+ if (mode.map_size > 0)
+ zoom = 256 / mode.map_size;
+ break;
+ case MINIMAP_TYPE_RADAR:
+ mode.label = N_("Minimap in radar mode, Zoom x%d");
+ if (mode.map_size > 0)
+ zoom = 512 / mode.map_size;
+ break;
+ case MINIMAP_TYPE_TEXTURE:
+ mode.label = N_("Minimap in texture mode");
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (zoom >= 0) {
+ char label_buf[1024];
+ porting::mt_snprintf(label_buf, sizeof(label_buf),
+ mode.label.c_str(), zoom);
+ mode.label = label_buf;
+ }
+
+ m_modes.push_back(mode);
+}
+
+void Minimap::addMode(MinimapType type, u16 size, std::string label,
+ std::string texture, u16 scale)
+{
+ MinimapModeDef mode;
+ mode.type = type;
+ mode.label = label;
+ mode.map_size = size;
+ mode.texture = texture;
+ mode.scale = scale;
+ switch (type) {
+ case MINIMAP_TYPE_SURFACE:
+ mode.scan_height = m_surface_mode_scan_height;
+ break;
+ case MINIMAP_TYPE_RADAR:
+ mode.scan_height = 32;
+ break;
+ default:
+ mode.scan_height = 0;
+ }
+ addMode(mode);
+}
+
+void Minimap::nextMode()
+{
+ if (m_modes.empty())
+ return;
+ m_current_mode_index++;
+ if (m_current_mode_index >= m_modes.size())
+ m_current_mode_index = 0;
+
+ setModeIndex(m_current_mode_index);
}
void Minimap::setPos(v3s16 pos)
@@ -331,16 +419,16 @@ void Minimap::setAngle(f32 angle)
void Minimap::blitMinimapPixelsToImageRadar(video::IImage *map_image)
{
video::SColor c(240, 0, 0, 0);
- for (s16 x = 0; x < data->map_size; x++)
- for (s16 z = 0; z < data->map_size; z++) {
- MinimapPixel *mmpixel = &data->minimap_scan[x + z * data->map_size];
+ for (s16 x = 0; x < data->mode.map_size; x++)
+ for (s16 z = 0; z < data->mode.map_size; z++) {
+ MinimapPixel *mmpixel = &data->minimap_scan[x + z * data->mode.map_size];
if (mmpixel->air_count > 0)
c.setGreen(core::clamp(core::round32(32 + mmpixel->air_count * 8), 0, 255));
else
c.setGreen(0);
- map_image->setPixel(x, data->map_size - z - 1, c);
+ map_image->setPixel(x, data->mode.map_size - z - 1, c);
}
}
@@ -349,9 +437,9 @@ void Minimap::blitMinimapPixelsToImageSurface(
{
// This variable creation/destruction has a 1% cost on rendering minimap
video::SColor tilecolor;
- for (s16 x = 0; x < data->map_size; x++)
- for (s16 z = 0; z < data->map_size; z++) {
- MinimapPixel *mmpixel = &data->minimap_scan[x + z * data->map_size];
+ for (s16 x = 0; x < data->mode.map_size; x++)
+ for (s16 z = 0; z < data->mode.map_size; z++) {
+ MinimapPixel *mmpixel = &data->minimap_scan[x + z * data->mode.map_size];
const ContentFeatures &f = m_ndef->get(mmpixel->n);
const TileDef *tile = &f.tiledef[0];
@@ -367,10 +455,10 @@ void Minimap::blitMinimapPixelsToImageSurface(
tilecolor.setBlue(tilecolor.getBlue() * f.minimap_color.getBlue() / 255);
tilecolor.setAlpha(240);
- map_image->setPixel(x, data->map_size - z - 1, tilecolor);
+ map_image->setPixel(x, data->mode.map_size - z - 1, tilecolor);
u32 h = mmpixel->height;
- heightmap_image->setPixel(x,data->map_size - z - 1,
+ heightmap_image->setPixel(x,data->mode.map_size - z - 1,
video::SColor(255, h, h, h));
}
}
@@ -378,21 +466,46 @@ void Minimap::blitMinimapPixelsToImageSurface(
video::ITexture *Minimap::getMinimapTexture()
{
// update minimap textures when new scan is ready
- if (data->map_invalidated)
+ if (data->map_invalidated && data->mode.type != MINIMAP_TYPE_TEXTURE)
return data->texture;
// create minimap and heightmap images in memory
- core::dimension2d<u32> dim(data->map_size, data->map_size);
+ core::dimension2d<u32> dim(data->mode.map_size, data->mode.map_size);
video::IImage *map_image = driver->createImage(video::ECF_A8R8G8B8, dim);
video::IImage *heightmap_image = driver->createImage(video::ECF_A8R8G8B8, dim);
video::IImage *minimap_image = driver->createImage(video::ECF_A8R8G8B8,
core::dimension2d<u32>(MINIMAP_MAX_SX, MINIMAP_MAX_SY));
// Blit MinimapPixels to images
- if (data->is_radar)
- blitMinimapPixelsToImageRadar(map_image);
- else
+ switch(data->mode.type) {
+ case MINIMAP_TYPE_OFF:
+ break;
+ case MINIMAP_TYPE_SURFACE:
blitMinimapPixelsToImageSurface(map_image, heightmap_image);
+ break;
+ case MINIMAP_TYPE_RADAR:
+ blitMinimapPixelsToImageRadar(map_image);
+ break;
+ case MINIMAP_TYPE_TEXTURE:
+ // Want to use texture source, to : 1 find texture, 2 cache it
+ video::ITexture* texture = m_tsrc->getTexture(data->mode.texture);
+ video::IImage* image = driver->createImageFromData(
+ texture->getColorFormat(), texture->getSize(), texture->lock(), true, false);
+ texture->unlock();
+
+ auto dim = image->getDimension();
+
+ map_image->fill(video::SColor(255, 0, 0, 0));
+
+ image->copyTo(map_image,
+ irr::core::vector2d<int> {
+ ((data->mode.map_size - (static_cast<int>(dim.Width))) >> 1)
+ - data->pos.X / data->mode.scale,
+ ((data->mode.map_size - (static_cast<int>(dim.Height))) >> 1)
+ + data->pos.Z / data->mode.scale
+ });
+ image->drop();
+ }
map_image->copyToScaling(minimap_image);
map_image->drop();
@@ -461,21 +574,34 @@ scene::SMeshBuffer *Minimap::getMinimapMeshBuffer()
void Minimap::drawMinimap()
{
+ // Non hud managed minimap drawing (legacy minimap)
+ v2u32 screensize = RenderingEngine::get_instance()->getWindowSize();
+ const u32 size = 0.25 * screensize.Y;
+
+ drawMinimap(core::rect<s32>(
+ screensize.X - size - 10, 10,
+ screensize.X - 10, size + 10));
+}
+
+void Minimap::drawMinimap(core::rect<s32> rect) {
+
video::ITexture *minimap_texture = getMinimapTexture();
if (!minimap_texture)
return;
+ if (data->mode.type == MINIMAP_TYPE_OFF)
+ return;
+
updateActiveMarkers();
- v2u32 screensize = RenderingEngine::get_instance()->getWindowSize();
- const u32 size = 0.25 * screensize.Y;
core::rect<s32> oldViewPort = driver->getViewPort();
core::matrix4 oldProjMat = driver->getTransform(video::ETS_PROJECTION);
core::matrix4 oldViewMat = driver->getTransform(video::ETS_VIEW);
- driver->setViewPort(core::rect<s32>(
- screensize.X - size * 2 - 10, 10,
- screensize.X - size - 10, size + 10));
+// driver->setViewPort(core::rect<s32>(
+// screensize.X - size * 2 - 10, 10,
+// screensize.X - size - 10, size + 10));
+ driver->setViewPort(rect);
driver->setTransform(video::ETS_PROJECTION, core::matrix4());
driver->setTransform(video::ETS_VIEW, core::matrix4());
@@ -488,7 +614,7 @@ void Minimap::drawMinimap()
material.TextureLayer[0].Texture = minimap_texture;
material.TextureLayer[1].Texture = data->heightmap_texture;
- if (m_enable_shaders && !data->is_radar) {
+ if (m_enable_shaders && data->mode.type == MINIMAP_TYPE_SURFACE) {
u16 sid = m_shdrsrc->getShader("minimap_shader", 1, 1);
material.MaterialType = m_shdrsrc->getShaderInfo(sid).material;
} else {
@@ -529,14 +655,15 @@ void Minimap::drawMinimap()
driver->setViewPort(oldViewPort);
// Draw player markers
- v2s32 s_pos(screensize.X - size * 2 - 10, 10);
+// v2s32 s_pos(screensize.X - size * 2 - 10, 10);
+ v2s32 s_pos(rect.UpperLeftCorner.X, rect.UpperLeftCorner.Y);
core::dimension2di imgsize(data->object_marker_red->getOriginalSize());
core::rect<s32> img_rect(0, 0, imgsize.Width, imgsize.Height);
static const video::SColor col(255, 255, 255, 255);
static const video::SColor c[4] = {col, col, col, col};
f32 sin_angle = std::sin(m_angle * core::DEGTORAD);
f32 cos_angle = std::cos(m_angle * core::DEGTORAD);
- s32 marker_size2 = 0.025 * (float)size;
+ s32 marker_size2 = 0.025 * (float)rect.getWidth();;
for (std::list<v2f>::const_iterator
i = m_active_markers.begin();
i != m_active_markers.end(); ++i) {
@@ -547,8 +674,8 @@ void Minimap::drawMinimap()
posf.X = t1;
posf.Y = t2;
}
- posf.X = (posf.X + 0.5) * (float)size;
- posf.Y = (posf.Y + 0.5) * (float)size;
+ posf.X = (posf.X + 0.5) * (float)rect.getWidth();
+ posf.Y = (posf.Y + 0.5) * (float)rect.getHeight();
core::rect<s32> dest_rect(
s_pos.X + posf.X - marker_size2,
s_pos.Y + posf.Y - marker_size2,
@@ -559,28 +686,41 @@ void Minimap::drawMinimap()
}
}
+MinimapMarker* Minimap::addMarker(scene::ISceneNode *parent_node)
+{
+ MinimapMarker *m = new MinimapMarker(parent_node);
+ m_markers.push_back(m);
+ return m;
+}
+
+void Minimap::removeMarker(MinimapMarker **m)
+{
+ m_markers.remove(*m);
+ delete *m;
+ *m = nullptr;
+}
+
void Minimap::updateActiveMarkers()
{
video::IImage *minimap_mask = data->minimap_shape_round ?
data->minimap_mask_round : data->minimap_mask_square;
- const std::list<Nametag *> &nametags = client->getCamera()->getNametags();
-
m_active_markers.clear();
-
- for (Nametag *nametag : nametags) {
- v3s16 pos = floatToInt(nametag->parent_node->getAbsolutePosition() +
- intToFloat(client->getCamera()->getOffset(), BS), BS);
- pos -= data->pos - v3s16(data->map_size / 2,
- data->scan_height / 2,
- data->map_size / 2);
- if (pos.X < 0 || pos.X > data->map_size ||
- pos.Y < 0 || pos.Y > data->scan_height ||
- pos.Z < 0 || pos.Z > data->map_size) {
+ v3f cam_offset = intToFloat(client->getCamera()->getOffset(), BS);
+ v3s16 pos_offset = data->pos - v3s16(data->mode.map_size / 2,
+ data->mode.scan_height / 2,
+ data->mode.map_size / 2);
+
+ for (MinimapMarker *marker : m_markers) {
+ v3s16 pos = floatToInt(marker->parent_node->getAbsolutePosition() +
+ cam_offset, BS) - pos_offset;
+ if (pos.X < 0 || pos.X > data->mode.map_size ||
+ pos.Y < 0 || pos.Y > data->mode.scan_height ||
+ pos.Z < 0 || pos.Z > data->mode.map_size) {
continue;
}
- pos.X = ((float)pos.X / data->map_size) * MINIMAP_MAX_SX;
- pos.Z = ((float)pos.Z / data->map_size) * MINIMAP_MAX_SY;
+ pos.X = ((float)pos.X / data->mode.map_size) * MINIMAP_MAX_SX;
+ pos.Z = ((float)pos.Z / data->mode.map_size) * MINIMAP_MAX_SY;
const video::SColor &mask_col = minimap_mask->getPixel(pos.X, pos.Z);
if (!mask_col.getAlpha()) {
continue;
diff --git a/src/client/minimap.h b/src/client/minimap.h
index 258d5330d..4a2c462f8 100644
--- a/src/client/minimap.h
+++ b/src/client/minimap.h
@@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#pragma once
+#include "../hud.h"
#include "irrlichttypes_extrabloated.h"
#include "util/thread.h"
#include "voxel.h"
@@ -33,28 +34,27 @@ class IShaderSource;
#define MINIMAP_MAX_SX 512
#define MINIMAP_MAX_SY 512
-enum MinimapMode {
- MINIMAP_MODE_OFF,
- MINIMAP_MODE_SURFACEx1,
- MINIMAP_MODE_SURFACEx2,
- MINIMAP_MODE_SURFACEx4,
- MINIMAP_MODE_RADARx1,
- MINIMAP_MODE_RADARx2,
- MINIMAP_MODE_RADARx4,
- MINIMAP_MODE_COUNT,
-};
-
enum MinimapShape {
MINIMAP_SHAPE_SQUARE,
MINIMAP_SHAPE_ROUND,
};
struct MinimapModeDef {
- bool is_radar;
+ MinimapType type;
+ std::string label;
u16 scan_height;
u16 map_size;
+ std::string texture;
+ u16 scale;
};
+struct MinimapMarker {
+ MinimapMarker(scene::ISceneNode *parent_node):
+ parent_node(parent_node)
+ {
+ }
+ scene::ISceneNode *parent_node;
+};
struct MinimapPixel {
//! The topmost node that the minimap displays.
MapNode n;
@@ -69,12 +69,9 @@ struct MinimapMapblock {
};
struct MinimapData {
- bool is_radar;
- MinimapMode mode;
+ MinimapModeDef mode;
v3s16 pos;
v3s16 old_pos;
- u16 scan_height;
- u16 map_size;
MinimapPixel minimap_scan[MINIMAP_MAX_SX * MINIMAP_MAX_SY];
bool map_invalidated;
bool minimap_shape_round;
@@ -127,12 +124,22 @@ public:
v3s16 getPos() const { return data->pos; }
void setAngle(f32 angle);
f32 getAngle() const { return m_angle; }
- void setMinimapMode(MinimapMode mode);
- MinimapMode getMinimapMode() const { return data->mode; }
void toggleMinimapShape();
void setMinimapShape(MinimapShape shape);
MinimapShape getMinimapShape();
+ void clearModes() { m_modes.clear(); };
+ void addMode(MinimapModeDef mode);
+ void addMode(MinimapType type, u16 size = 0, std::string label = "",
+ std::string texture = "", u16 scale = 1);
+
+ void setModeIndex(size_t index);
+ size_t getModeIndex() const { return m_current_mode_index; };
+ size_t getMaxModeIndex() const { return m_modes.size() - 1; };
+ void nextMode();
+
+ void setModesFromString(std::string modes_string);
+ MinimapModeDef getModeDef() const { return data->mode; }
video::ITexture *getMinimapTexture();
@@ -142,8 +149,12 @@ public:
scene::SMeshBuffer *getMinimapMeshBuffer();
+ MinimapMarker* addMarker(scene::ISceneNode *parent_node);
+ void removeMarker(MinimapMarker **marker);
+
void updateActiveMarkers();
void drawMinimap();
+ void drawMinimap(core::rect<s32> rect);
video::IVideoDriver *driver;
Client* client;
@@ -153,11 +164,14 @@ private:
ITextureSource *m_tsrc;
IShaderSource *m_shdrsrc;
const NodeDefManager *m_ndef;
- MinimapUpdateThread *m_minimap_update_thread;
+ MinimapUpdateThread *m_minimap_update_thread = nullptr;
scene::SMeshBuffer *m_meshbuffer;
bool m_enable_shaders;
+ std::vector<MinimapModeDef> m_modes;
+ size_t m_current_mode_index;
u16 m_surface_mode_scan_height;
f32 m_angle;
std::mutex m_mutex;
+ std::list<MinimapMarker*> m_markers;
std::list<v2f> m_active_markers;
};
diff --git a/src/client/render/core.cpp b/src/client/render/core.cpp
index 1fad4af52..44e3ed744 100644
--- a/src/client/render/core.cpp
+++ b/src/client/render/core.cpp
@@ -123,34 +123,30 @@ void RenderingCore::drawTracersAndESP()
}
if (draw_node_esp || draw_node_tracers) {
Map &map = env.getMap();
- std::map<v2s16, MapSector*> *sectors = map.getSectorsPtr();
-
- for (auto &sector_it : *sectors) {
- MapSector *sector = sector_it.second;
- MapBlockVect blocks;
- sector->getBlocks(blocks);
- for (MapBlock *block : blocks) {
- if (! block->mesh)
- continue;
- for (v3s16 p : block->mesh->esp_nodes) {
- v3f pos = intToFloat(p, BS) - camera_offset;
- MapNode node = map.getNode(p);
- std::vector<aabb3f> boxes;
- node.getSelectionBoxes(client->getNodeDefManager(), &boxes, node.getNeighbors(p, &map));
- video::SColor color = client->getNodeDefManager()->get(node).minimap_color;
-
- for (aabb3f box : boxes) {
- box.MinEdge += pos;
- box.MaxEdge += pos;
- if (draw_node_esp)
- driver->draw3DBox(box, color);
- if (draw_node_tracers)
- driver->draw3DLine(eye_pos, box.getCenter(), color);
- }
+
+ std::vector<v3s16> positions;
+ map.listAllLoadedBlocks(positions);
+
+ for (v3s16 blockp : positions) {
+ MapBlock *block = map.getBlockNoCreate(blockp);
+ if (! block->mesh)
+ continue;
+ for (v3s16 p : block->mesh->esp_nodes) {
+ v3f pos = intToFloat(p, BS) - camera_offset;
+ MapNode node = map.getNode(p);
+ std::vector<aabb3f> boxes;
+ node.getSelectionBoxes(client->getNodeDefManager(), &boxes, node.getNeighbors(p, &map));
+ video::SColor color = client->getNodeDefManager()->get(node).minimap_color;
+ for (aabb3f box : boxes) {
+ box.MinEdge += pos;
+ box.MaxEdge += pos;
+ if (draw_node_esp)
+ driver->draw3DBox(box, color);
+ if (draw_node_tracers)
+ driver->draw3DLine(eye_pos, box.getCenter(), color);
}
}
}
-
}
driver->setMaterial(oldmaterial);
diff --git a/src/client/shader.cpp b/src/client/shader.cpp
index ee6079f7a..1cec20d2c 100644
--- a/src/client/shader.cpp
+++ b/src/client/shader.cpp
@@ -37,6 +37,22 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "log.h"
#include "gamedef.h"
#include "client/tile.h"
+#include "config.h"
+
+#if ENABLE_GLES
+#ifdef _IRR_COMPILE_WITH_OGLES1_
+#include <GLES/gl.h>
+#else
+#include <GLES2/gl2.h>
+#endif
+#else
+#ifndef __APPLE__
+#include <GL/gl.h>
+#else
+#define GL_SILENCE_DEPRECATION
+#include <OpenGL/gl.h>
+#endif
+#endif
/*
A cache from shader name to shader path
@@ -215,11 +231,24 @@ class MainShaderConstantSetter : public IShaderConstantSetter
{
CachedVertexShaderSetting<float, 16> m_world_view_proj;
CachedVertexShaderSetting<float, 16> m_world;
+#if ENABLE_GLES
+ // Modelview matrix
+ CachedVertexShaderSetting<float, 16> m_world_view;
+ // Texture matrix
+ CachedVertexShaderSetting<float, 16> m_texture;
+ // Normal matrix
+ CachedVertexShaderSetting<float, 9> m_normal;
+#endif
public:
MainShaderConstantSetter() :
- m_world_view_proj("mWorldViewProj"),
- m_world("mWorld")
+ m_world_view_proj("mWorldViewProj")
+ , m_world("mWorld")
+#if ENABLE_GLES
+ , m_world_view("mWorldView")
+ , m_texture("mTexture")
+ , m_normal("mNormal")
+#endif
{}
~MainShaderConstantSetter() = default;
@@ -229,23 +258,42 @@ public:
video::IVideoDriver *driver = services->getVideoDriver();
sanity_check(driver);
+ // Set world matrix
+ core::matrix4 world = driver->getTransform(video::ETS_WORLD);
+ if (is_highlevel)
+ m_world.set(*reinterpret_cast<float(*)[16]>(world.pointer()), services);
+ else
+ services->setVertexShaderConstant(world.pointer(), 4, 4);
+
// Set clip matrix
+ core::matrix4 worldView;
+ worldView = driver->getTransform(video::ETS_VIEW);
+ worldView *= world;
core::matrix4 worldViewProj;
worldViewProj = driver->getTransform(video::ETS_PROJECTION);
- worldViewProj *= driver->getTransform(video::ETS_VIEW);
- worldViewProj *= driver->getTransform(video::ETS_WORLD);
+ worldViewProj *= worldView;
if (is_highlevel)
m_world_view_proj.set(*reinterpret_cast<float(*)[16]>(worldViewProj.pointer()), services);
else
services->setVertexShaderConstant(worldViewProj.pointer(), 0, 4);
- // Set world matrix
- core::matrix4 world = driver->getTransform(video::ETS_WORLD);
- if (is_highlevel)
- m_world.set(*reinterpret_cast<float(*)[16]>(world.pointer()), services);
- else
- services->setVertexShaderConstant(world.pointer(), 4, 4);
-
+#if ENABLE_GLES
+ if (is_highlevel) {
+ core::matrix4 texture = driver->getTransform(video::ETS_TEXTURE_0);
+ m_world_view.set(*reinterpret_cast<float(*)[16]>(worldView.pointer()), services);
+ m_texture.set(*reinterpret_cast<float(*)[16]>(texture.pointer()), services);
+
+ core::matrix4 normal;
+ worldView.getTransposed(normal);
+ sanity_check(normal.makeInverse());
+ float m[9] = {
+ normal[0], normal[1], normal[2],
+ normal[4], normal[5], normal[6],
+ normal[8], normal[9], normal[10],
+ };
+ m_normal.set(m, services);
+ }
+#endif
}
};
@@ -529,7 +577,6 @@ ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtyp
shaderinfo.name = name;
shaderinfo.material_type = material_type;
shaderinfo.drawtype = drawtype;
- shaderinfo.material = video::EMT_SOLID;
switch (material_type) {
case TILE_MATERIAL_OPAQUE:
case TILE_MATERIAL_LIQUID_OPAQUE:
@@ -550,6 +597,7 @@ ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtyp
shaderinfo.base_material = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
break;
}
+ shaderinfo.material = shaderinfo.base_material;
bool enable_shaders = g_settings->getBool("enable_shaders");
if (!enable_shaders)
@@ -605,7 +653,62 @@ ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtyp
return shaderinfo;
// Create shaders header
- std::string shaders_header = "#version 120\n";
+ bool use_gles = false;
+#if ENABLE_GLES
+ use_gles = driver->getDriverType() == video::EDT_OGLES2;
+#endif
+ std::string shaders_header, vertex_header, pixel_header; // geometry shaders aren’t supported in GLES<3
+ if (use_gles) {
+ shaders_header =
+ "#version 100\n"
+ ;
+ vertex_header = R"(
+ uniform highp mat4 mWorldView;
+ uniform highp mat4 mWorldViewProj;
+ uniform mediump mat4 mTexture;
+ uniform mediump mat3 mNormal;
+
+ attribute highp vec4 inVertexPosition;
+ attribute lowp vec4 inVertexColor;
+ attribute mediump vec4 inTexCoord0;
+ attribute mediump vec3 inVertexNormal;
+ attribute mediump vec4 inVertexTangent;
+ attribute mediump vec4 inVertexBinormal;
+ )";
+ pixel_header = R"(
+ precision mediump float;
+ )";
+ } else {
+ shaders_header = R"(
+ #version 120
+ #define lowp
+ #define mediump
+ #define highp
+ )";
+ vertex_header = R"(
+ #define mWorldView gl_ModelViewMatrix
+ #define mWorldViewProj gl_ModelViewProjectionMatrix
+ #define mTexture (gl_TextureMatrix[0])
+ #define mNormal gl_NormalMatrix
+
+ #define inVertexPosition gl_Vertex
+ #define inVertexColor gl_Color
+ #define inTexCoord0 gl_MultiTexCoord0
+ #define inVertexNormal gl_Normal
+ #define inVertexTangent gl_MultiTexCoord1
+ #define inVertexBinormal gl_MultiTexCoord2
+ )";
+ }
+
+ bool use_discard = use_gles;
+#ifdef __unix__
+ // For renderers that should use discard instead of GL_ALPHA_TEST
+ const char* gl_renderer = (const char*)glGetString(GL_RENDERER);
+ if (strstr(gl_renderer, "GC7000"))
+ use_discard = true;
+#endif
+ if (use_discard && shaderinfo.base_material != video::EMT_SOLID)
+ shaders_header += "#define USE_DISCARD\n";
static const char* drawTypes[] = {
"NDT_NORMAL",
@@ -665,73 +768,16 @@ ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtyp
shaders_header += itos(drawtype);
shaders_header += "\n";
- if (g_settings->getBool("generate_normalmaps")) {
- shaders_header += "#define GENERATE_NORMALMAPS 1\n";
- } else {
- shaders_header += "#define GENERATE_NORMALMAPS 0\n";
- }
- shaders_header += "#define NORMALMAPS_STRENGTH ";
- shaders_header += ftos(g_settings->getFloat("normalmaps_strength"));
- shaders_header += "\n";
- float sample_step;
- int smooth = (int)g_settings->getFloat("normalmaps_smooth");
- switch (smooth){
- case 0:
- sample_step = 0.0078125; // 1.0 / 128.0
- break;
- case 1:
- sample_step = 0.00390625; // 1.0 / 256.0
- break;
- case 2:
- sample_step = 0.001953125; // 1.0 / 512.0
- break;
- default:
- sample_step = 0.0078125;
- break;
- }
- shaders_header += "#define SAMPLE_STEP ";
- shaders_header += ftos(sample_step);
- shaders_header += "\n";
-
- if (g_settings->getBool("enable_bumpmapping"))
- shaders_header += "#define ENABLE_BUMPMAPPING\n";
-
- if (g_settings->getBool("enable_parallax_occlusion")){
- int mode = g_settings->getFloat("parallax_occlusion_mode");
- float scale = g_settings->getFloat("parallax_occlusion_scale");
- float bias = g_settings->getFloat("parallax_occlusion_bias");
- int iterations = g_settings->getFloat("parallax_occlusion_iterations");
- shaders_header += "#define ENABLE_PARALLAX_OCCLUSION\n";
- shaders_header += "#define PARALLAX_OCCLUSION_MODE ";
- shaders_header += itos(mode);
- shaders_header += "\n";
- shaders_header += "#define PARALLAX_OCCLUSION_SCALE ";
- shaders_header += ftos(scale);
- shaders_header += "\n";
- shaders_header += "#define PARALLAX_OCCLUSION_BIAS ";
- shaders_header += ftos(bias);
- shaders_header += "\n";
- shaders_header += "#define PARALLAX_OCCLUSION_ITERATIONS ";
- shaders_header += itos(iterations);
- shaders_header += "\n";
- }
-
- shaders_header += "#define USE_NORMALMAPS ";
- if (g_settings->getBool("enable_bumpmapping") || g_settings->getBool("enable_parallax_occlusion"))
- shaders_header += "1\n";
- else
- shaders_header += "0\n";
-
if (g_settings->getBool("enable_waving_water")){
shaders_header += "#define ENABLE_WAVING_WATER 1\n";
shaders_header += "#define WATER_WAVE_HEIGHT ";
- shaders_header += ftos(g_settings->getFloat("water_wave_height"));
+ shaders_header += std::to_string(g_settings->getFloat("water_wave_height"));
shaders_header += "\n";
shaders_header += "#define WATER_WAVE_LENGTH ";
- shaders_header += ftos(g_settings->getFloat("water_wave_length"));
+ shaders_header += std::to_string(g_settings->getFloat("water_wave_length"));
shaders_header += "\n";
shaders_header += "#define WATER_WAVE_SPEED ";
- shaders_header += ftos(g_settings->getFloat("water_wave_speed"));
+ shaders_header += std::to_string(g_settings->getFloat("water_wave_speed"));
shaders_header += "\n";
} else{
shaders_header += "#define ENABLE_WAVING_WATER 0\n";
@@ -753,7 +799,7 @@ ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtyp
shaders_header += "#define ENABLE_TONE_MAPPING\n";
shaders_header += "#define FOG_START ";
- shaders_header += ftos(rangelim(g_settings->getFloat("fog_start"), 0.0f, 0.99f));
+ shaders_header += std::to_string(rangelim(g_settings->getFloat("fog_start"), 0.0f, 0.99f));
shaders_header += "\n";
// Call addHighLevelShaderMaterial() or addShaderMaterial()
@@ -761,11 +807,11 @@ ShaderInfo generate_shader(const std::string &name, u8 material_type, u8 drawtyp
const c8* pixel_program_ptr = 0;
const c8* geometry_program_ptr = 0;
if (!vertex_program.empty()) {
- vertex_program = shaders_header + vertex_program;
+ vertex_program = shaders_header + vertex_header + vertex_program;
vertex_program_ptr = vertex_program.c_str();
}
if (!pixel_program.empty()) {
- pixel_program = shaders_header + pixel_program;
+ pixel_program = shaders_header + pixel_header + pixel_program;
pixel_program_ptr = pixel_program.c_str();
}
if (!geometry_program.empty()) {
@@ -847,27 +893,37 @@ void load_shaders(const std::string &name, SourceShaderCache *sourcecache,
geometry_program = "";
is_highlevel = false;
- if(enable_shaders){
- // Look for high level shaders
- if(drivertype == video::EDT_DIRECT3D9){
- // Direct3D 9: HLSL
- // (All shaders in one file)
- vertex_program = sourcecache->getOrLoad(name, "d3d9.hlsl");
- pixel_program = vertex_program;
- geometry_program = vertex_program;
- }
- else if(drivertype == video::EDT_OPENGL){
- // OpenGL: GLSL
- vertex_program = sourcecache->getOrLoad(name, "opengl_vertex.glsl");
- pixel_program = sourcecache->getOrLoad(name, "opengl_fragment.glsl");
- geometry_program = sourcecache->getOrLoad(name, "opengl_geometry.glsl");
- }
- if (!vertex_program.empty() || !pixel_program.empty() || !geometry_program.empty()){
- is_highlevel = true;
- return;
- }
- }
+ if (!enable_shaders)
+ return;
+
+ // Look for high level shaders
+ switch (drivertype) {
+ case video::EDT_DIRECT3D9:
+ // Direct3D 9: HLSL
+ // (All shaders in one file)
+ vertex_program = sourcecache->getOrLoad(name, "d3d9.hlsl");
+ pixel_program = vertex_program;
+ geometry_program = vertex_program;
+ break;
+ case video::EDT_OPENGL:
+#if ENABLE_GLES
+ case video::EDT_OGLES2:
+#endif
+ // OpenGL: GLSL
+ vertex_program = sourcecache->getOrLoad(name, "opengl_vertex.glsl");
+ pixel_program = sourcecache->getOrLoad(name, "opengl_fragment.glsl");
+ geometry_program = sourcecache->getOrLoad(name, "opengl_geometry.glsl");
+ break;
+
+ default:
+ // e.g. OpenGL ES 1 (with no shader support)
+ break;
+ }
+ if (!vertex_program.empty() || !pixel_program.empty() || !geometry_program.empty()){
+ is_highlevel = true;
+ return;
+ }
}
void dumpShaderProgram(std::ostream &output_stream,
diff --git a/src/client/sky.cpp b/src/client/sky.cpp
index 2e0cbca86..9a2614eda 100644
--- a/src/client/sky.cpp
+++ b/src/client/sky.cpp
@@ -1,6 +1,7 @@
/*
Minetest
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
+Copyright (C) 2020 numzero, Lobachevskiy Vitaliy <numzer0@yandex.ru>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
@@ -34,16 +35,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "config.h"
using namespace irr::core;
-Sky::Sky(s32 id, ITextureSource *tsrc) :
- scene::ISceneNode(RenderingEngine::get_scene_manager()->getRootSceneNode(),
- RenderingEngine::get_scene_manager(), id)
+static video::SMaterial baseMaterial()
{
- setAutomaticCulling(scene::EAC_OFF);
- m_box.MaxEdge.set(0, 0, 0);
- m_box.MinEdge.set(0, 0, 0);
-
- // Create material
-
video::SMaterial mat;
mat.Lighting = false;
#if ENABLE_GLES
@@ -56,14 +49,31 @@ Sky::Sky(s32 id, ITextureSource *tsrc) :
mat.TextureLayer[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
mat.TextureLayer[0].TextureWrapV = video::ETC_CLAMP_TO_EDGE;
mat.BackfaceCulling = false;
+ return mat;
+};
+
+Sky::Sky(s32 id, ITextureSource *tsrc, IShaderSource *ssrc) :
+ scene::ISceneNode(RenderingEngine::get_scene_manager()->getRootSceneNode(),
+ RenderingEngine::get_scene_manager(), id)
+{
+ setAutomaticCulling(scene::EAC_OFF);
+ m_box.MaxEdge.set(0, 0, 0);
+ m_box.MinEdge.set(0, 0, 0);
+
+ m_enable_shaders = g_settings->getBool("enable_shaders");
- m_materials[0] = mat;
+ // Create materials
- m_materials[1] = mat;
+ m_materials[0] = baseMaterial();
+ m_materials[0].MaterialType = ssrc->getShaderInfo(ssrc->getShader("stars_shader", TILE_MATERIAL_ALPHA, 0)).material;
+ m_materials[0].Lighting = true;
+ m_materials[0].ColorMaterial = video::ECM_NONE;
+
+ m_materials[1] = baseMaterial();
//m_materials[1].MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
m_materials[1].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
- m_materials[2] = mat;
+ m_materials[2] = baseMaterial();
m_materials[2].setTexture(0, tsrc->getTextureForMesh("sunrisebg.png"));
m_materials[2].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
//m_materials[2].MaterialType = video::EMT_TRANSPARENT_ADD_COLOR;
@@ -80,7 +90,7 @@ Sky::Sky(s32 id, ITextureSource *tsrc) :
tsrc->getTexture(m_moon_params.tonemap) : NULL;
if (m_sun_texture) {
- m_materials[3] = mat;
+ m_materials[3] = baseMaterial();
m_materials[3].setTexture(0, m_sun_texture);
m_materials[3].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
// Disables texture filtering
@@ -92,7 +102,7 @@ Sky::Sky(s32 id, ITextureSource *tsrc) :
m_materials[3].Lighting = true;
}
if (m_moon_texture) {
- m_materials[4] = mat;
+ m_materials[4] = baseMaterial();
m_materials[4].setTexture(0, m_moon_texture);
m_materials[4].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
// Disables texture filtering
@@ -105,7 +115,7 @@ Sky::Sky(s32 id, ITextureSource *tsrc) :
}
for (int i = 5; i < 11; i++) {
- m_materials[i] = mat;
+ m_materials[i] = baseMaterial();
m_materials[i].Lighting = true;
m_materials[i].MaterialType = video::EMT_SOLID;
}
@@ -202,7 +212,7 @@ void Sky::render()
const f32 t = 1.0f;
const f32 o = 0.0f;
- static const u16 indices[4] = {0, 1, 2, 3};
+ static const u16 indices[6] = {0, 1, 2, 0, 2, 3};
video::S3DVertex vertices[4];
driver->setMaterial(m_materials[1]);
@@ -244,7 +254,7 @@ void Sky::render()
vertex.Pos.rotateXZBy(180);
}
}
- driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
+ driver->drawIndexedTriangleList(&vertices[0], 4, indices, 2);
}
}
@@ -270,7 +280,7 @@ void Sky::render()
// Switch from -Z (south) to +Z (north)
vertex.Pos.rotateXZBy(-180);
}
- driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
+ driver->drawIndexedTriangleList(&vertices[0], 4, indices, 2);
}
}
@@ -301,7 +311,7 @@ void Sky::render()
// Switch from -Z (south) to -X (west)
vertex.Pos.rotateXZBy(-90);
}
- driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
+ driver->drawIndexedTriangleList(&vertices[0], 4, indices, 2);
}
// Draw sun
@@ -337,7 +347,7 @@ void Sky::render()
// Switch from -Z (south) to +Z (north)
vertex.Pos.rotateXZBy(-180);
}
- driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
+ driver->drawIndexedTriangleList(&vertices[0], 4, indices, 2);
}
// Draw bottom far cloudy fog thing in front of sun, moon and stars
@@ -346,7 +356,7 @@ void Sky::render()
vertices[1] = video::S3DVertex( 1, -1.0, -1, 0, 1, 0, c, o, t);
vertices[2] = video::S3DVertex( 1, -1.0, 1, 0, 1, 0, c, o, o);
vertices[3] = video::S3DVertex(-1, -1.0, 1, 0, 1, 0, c, t, o);
- driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
+ driver->drawIndexedTriangleList(&vertices[0], 4, indices, 2);
}
}
}
@@ -590,7 +600,7 @@ void Sky::draw_sun(video::IVideoDriver *driver, float sunsize, const video::SCol
* wicked_time_of_day: current time of day, to know where should be the sun in the sky
*/
{
- static const u16 indices[4] = {0, 1, 2, 3};
+ static const u16 indices[] = {0, 1, 2, 0, 2, 3};
std::array<video::S3DVertex, 4> vertices;
if (!m_sun_texture) {
driver->setMaterial(m_materials[1]);
@@ -608,7 +618,7 @@ void Sky::draw_sun(video::IVideoDriver *driver, float sunsize, const video::SCol
for (int i = 0; i < 4; i++) {
draw_sky_body(vertices, -sunsizes[i], sunsizes[i], colors[i]);
place_sky_body(vertices, 90, wicked_time_of_day * 360 - 90);
- driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
+ driver->drawIndexedTriangleList(&vertices[0], 4, indices, 2);
}
} else {
driver->setMaterial(m_materials[3]);
@@ -620,7 +630,7 @@ void Sky::draw_sun(video::IVideoDriver *driver, float sunsize, const video::SCol
c = video::SColor(255, 255, 255, 255);
draw_sky_body(vertices, -d, d, c);
place_sky_body(vertices, 90, wicked_time_of_day * 360 - 90);
- driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
+ driver->drawIndexedTriangleList(&vertices[0], 4, indices, 2);
}
}
@@ -637,7 +647,7 @@ void Sky::draw_moon(video::IVideoDriver *driver, float moonsize, const video::SC
* the sky
*/
{
- static const u16 indices[4] = {0, 1, 2, 3};
+ static const u16 indices[] = {0, 1, 2, 0, 2, 3};
std::array<video::S3DVertex, 4> vertices;
if (!m_moon_texture) {
driver->setMaterial(m_materials[1]);
@@ -661,7 +671,7 @@ void Sky::draw_moon(video::IVideoDriver *driver, float moonsize, const video::SC
for (int i = 0; i < 4; i++) {
draw_sky_body(vertices, moonsizes_1[i], moonsizes_2[i], colors[i]);
place_sky_body(vertices, -90, wicked_time_of_day * 360 - 90);
- driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
+ driver->drawIndexedTriangleList(&vertices[0], 4, indices, 2);
}
} else {
driver->setMaterial(m_materials[4]);
@@ -673,13 +683,12 @@ void Sky::draw_moon(video::IVideoDriver *driver, float moonsize, const video::SC
c = video::SColor(255, 255, 255, 255);
draw_sky_body(vertices, -d, d, c);
place_sky_body(vertices, -90, wicked_time_of_day * 360 - 90);
- driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
+ driver->drawIndexedTriangleList(&vertices[0], 4, indices, 2);
}
}
void Sky::draw_stars(video::IVideoDriver * driver, float wicked_time_of_day)
{
- driver->setMaterial(m_materials[1]);
// Tune values so that stars first appear just after the sun
// disappears over the horizon, and disappear just before the sun
// appears over the horizon.
@@ -687,87 +696,18 @@ void Sky::draw_stars(video::IVideoDriver * driver, float wicked_time_of_day)
// to time 4000.
float tod = wicked_time_of_day < 0.5f ? wicked_time_of_day : (1.0f - wicked_time_of_day);
- float starbrightness = clamp((0.25f - fabsf(tod)) * 20.0f, 0.0f, 1.0f);
-
- float f = starbrightness;
- float d = (0.006 / 2) * m_star_params.scale;
-
- video::SColor starcolor = m_star_params.starcolor;
- starcolor.setAlpha(f * m_star_params.starcolor.getAlpha());
-
- // Stars are only drawn when not fully transparent
- if (m_star_params.starcolor.getAlpha() < 1)
+ float starbrightness = (0.25f - fabsf(tod)) * 20.0f;
+ m_star_color = m_star_params.starcolor;
+ m_star_color.a *= clamp(starbrightness, 0.0f, 1.0f);
+ if (m_star_color.a <= 0.0f) // Stars are only drawn when not fully transparent
return;
-#if ENABLE_GLES
- u16 *indices = new u16[m_star_params.count * 3];
- video::S3DVertex *vertices =
- new video::S3DVertex[m_star_params.count * 3];
- for (u32 i = 0; i < m_star_params.count; i++) {
- indices[i * 3 + 0] = i * 3 + 0;
- indices[i * 3 + 1] = i * 3 + 1;
- indices[i * 3 + 2] = i * 3 + 2;
- v3f r = m_stars[i];
- core::CMatrix4<f32> a;
- a.buildRotateFromTo(v3f(0, 1, 0), r);
- v3f p = v3f(-d, 1, -d);
- v3f p1 = v3f(d, 1, 0);
- v3f p2 = v3f(-d, 1, d);
- a.rotateVect(p);
- a.rotateVect(p1);
- a.rotateVect(p2);
- p.rotateXYBy(wicked_time_of_day * 360 - 90);
- p1.rotateXYBy(wicked_time_of_day * 360 - 90);
- p2.rotateXYBy(wicked_time_of_day * 360 - 90);
- vertices[i * 3 + 0].Pos = p;
- vertices[i * 3 + 0].Color = starcolor;
- vertices[i * 3 + 1].Pos = p1;
- vertices[i * 3 + 1].Color = starcolor;
- vertices[i * 3 + 2].Pos = p2;
- vertices[i * 3 + 2].Color = starcolor;
- }
- driver->drawIndexedTriangleList(vertices, m_star_params.count * 3,
- indices, m_star_params.count);
- delete[] indices;
- delete[] vertices;
-#else
- u16 *indices = new u16[m_star_params.count * 4];
- video::S3DVertex *vertices =
- new video::S3DVertex[m_star_params.count * 4];
- for (u32 i = 0; i < m_star_params.count; i++) {
- indices[i * 4 + 0] = i * 4 + 0;
- indices[i * 4 + 1] = i * 4 + 1;
- indices[i * 4 + 2] = i * 4 + 2;
- indices[i * 4 + 3] = i * 4 + 3;
- v3f r = m_stars[i];
- core::CMatrix4<f32> a;
- a.buildRotateFromTo(v3f(0, 1, 0), r);
- v3f p = v3f(-d, 1, -d);
- v3f p1 = v3f(d, 1, -d);
- v3f p2 = v3f(d, 1, d);
- v3f p3 = v3f(-d, 1, d);
- a.rotateVect(p);
- a.rotateVect(p1);
- a.rotateVect(p2);
- a.rotateVect(p3);
- p.rotateXYBy(wicked_time_of_day * 360 - 90);
- p1.rotateXYBy(wicked_time_of_day * 360 - 90);
- p2.rotateXYBy(wicked_time_of_day * 360 - 90);
- p3.rotateXYBy(wicked_time_of_day * 360 - 90);
- vertices[i * 4 + 0].Pos = p;
- vertices[i * 4 + 0].Color = starcolor;
- vertices[i * 4 + 1].Pos = p1;
- vertices[i * 4 + 1].Color = starcolor;
- vertices[i * 4 + 2].Pos = p2;
- vertices[i * 4 + 2].Color = starcolor;
- vertices[i * 4 + 3].Pos = p3;
- vertices[i * 4 + 3].Color = starcolor;
- }
- driver->drawVertexPrimitiveList(vertices, m_star_params.count * 4,
- indices, m_star_params.count, video::EVT_STANDARD,
- scene::EPT_QUADS, video::EIT_16BIT);
- delete[] indices;
- delete[] vertices;
-#endif
+ m_materials[0].DiffuseColor = m_materials[0].EmissiveColor = m_star_color.toSColor();
+ auto sky_rotation = core::matrix4().setRotationAxisRadians(2.0f * M_PI * (wicked_time_of_day - 0.25f), v3f(0.0f, 0.0f, 1.0f));
+ auto world_matrix = driver->getTransform(video::ETS_WORLD);
+ driver->setTransform(video::ETS_WORLD, world_matrix * sky_rotation);
+ driver->setMaterial(m_materials[0]);
+ driver->drawMeshBuffer(m_stars.get());
+ driver->setTransform(video::ETS_WORLD, world_matrix);
}
void Sky::draw_sky_body(std::array<video::S3DVertex, 4> &vertices, float pos_1, float pos_2, const video::SColor &c)
@@ -822,7 +762,7 @@ void Sky::setSunTexture(std::string sun_texture,
m_sun_texture = tsrc->getTextureForMesh(m_sun_params.texture);
if (m_sun_texture) {
- m_materials[3] = m_materials[0];
+ m_materials[3] = baseMaterial();
m_materials[3].setTexture(0, m_sun_texture);
m_materials[3].MaterialType = video::
EMT_TRANSPARENT_ALPHA_CHANNEL;
@@ -870,7 +810,7 @@ void Sky::setMoonTexture(std::string moon_texture,
m_moon_texture = tsrc->getTextureForMesh(m_moon_params.texture);
if (m_moon_texture) {
- m_materials[4] = m_materials[0];
+ m_materials[4] = baseMaterial();
m_materials[4].setTexture(0, m_moon_texture);
m_materials[4].MaterialType = video::
EMT_TRANSPARENT_ALPHA_CHANNEL;
@@ -892,19 +832,58 @@ void Sky::setStarCount(u16 star_count, bool force_update)
// Allow force updating star count at game init.
if (m_star_params.count != star_count || force_update) {
m_star_params.count = star_count;
- m_stars.clear();
- // Rebuild the stars surrounding the camera
- for (u16 i = 0; i < star_count; i++) {
- v3f star = v3f(
- myrand_range(-10000, 10000),
- myrand_range(-10000, 10000),
- myrand_range(-10000, 10000)
- );
-
- star.normalize();
- m_stars.emplace_back(star);
- }
+ m_seed = (u64)myrand() << 32 | myrand();
+ updateStars();
+ }
+}
+
+void Sky::updateStars()
+{
+ m_stars.reset(new scene::SMeshBuffer());
+ // Stupid IrrLicht doesn’t allow non-indexed rendering, and indexed quad
+ // rendering is slow due to lack of hardware support. So as indices are
+ // 16-bit and there are 4 vertices per star... the limit is 2^16/4 = 0x4000.
+ // That should be well enough actually.
+ if (m_star_params.count > 0x4000) {
+ warningstream << "Requested " << m_star_params.count << " stars but " << 0x4000 << " is the max\n";
+ m_star_params.count = 0x4000;
+ }
+ m_stars->Vertices.reallocate(4 * m_star_params.count);
+ m_stars->Indices.reallocate(6 * m_star_params.count);
+
+ video::SColor fallback_color = m_star_params.starcolor; // used on GLES 2 “without shaders”
+ PcgRandom rgen(m_seed);
+ float d = (0.006 / 2) * m_star_params.scale;
+ for (u16 i = 0; i < m_star_params.count; i++) {
+ v3f r = v3f(
+ rgen.range(-10000, 10000),
+ rgen.range(-10000, 10000),
+ rgen.range(-10000, 10000)
+ );
+ core::CMatrix4<f32> a;
+ a.buildRotateFromTo(v3f(0, 1, 0), r);
+ v3f p = v3f(-d, 1, -d);
+ v3f p1 = v3f(d, 1, -d);
+ v3f p2 = v3f(d, 1, d);
+ v3f p3 = v3f(-d, 1, d);
+ a.rotateVect(p);
+ a.rotateVect(p1);
+ a.rotateVect(p2);
+ a.rotateVect(p3);
+ m_stars->Vertices.push_back(video::S3DVertex(p, {}, fallback_color, {}));
+ m_stars->Vertices.push_back(video::S3DVertex(p1, {}, fallback_color, {}));
+ m_stars->Vertices.push_back(video::S3DVertex(p2, {}, fallback_color, {}));
+ m_stars->Vertices.push_back(video::S3DVertex(p3, {}, fallback_color, {}));
+ }
+ for (u16 i = 0; i < m_star_params.count; i++) {
+ m_stars->Indices.push_back(i * 4 + 0);
+ m_stars->Indices.push_back(i * 4 + 1);
+ m_stars->Indices.push_back(i * 4 + 2);
+ m_stars->Indices.push_back(i * 4 + 2);
+ m_stars->Indices.push_back(i * 4 + 3);
+ m_stars->Indices.push_back(i * 4 + 0);
}
+ m_stars->setHardwareMappingHint(scene::EHM_STATIC);
}
void Sky::setSkyColors(const SkyColor &sky_color)
@@ -936,7 +915,7 @@ void Sky::addTextureToSkybox(std::string texture, int material_id,
// Keep a list of texture names handy.
m_sky_params.textures.emplace_back(texture);
video::ITexture *result = tsrc->getTextureForMesh(texture);
- m_materials[material_id+5] = m_materials[0];
+ m_materials[material_id+5] = baseMaterial();
m_materials[material_id+5].setTexture(0, result);
m_materials[material_id+5].MaterialType = video::EMT_SOLID;
}
diff --git a/src/client/sky.h b/src/client/sky.h
index 3227e8f59..10e1cd976 100644
--- a/src/client/sky.h
+++ b/src/client/sky.h
@@ -21,6 +21,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <array>
#include "camera.h"
#include "irrlichttypes_extrabloated.h"
+#include "irr_ptr.h"
+#include "shader.h"
#include "skyparams.h"
#pragma once
@@ -34,7 +36,7 @@ class Sky : public scene::ISceneNode
{
public:
//! constructor
- Sky(s32 id, ITextureSource *tsrc);
+ Sky(s32 id, ITextureSource *tsrc, IShaderSource *ssrc);
virtual void OnRegisterSceneNode();
@@ -77,7 +79,7 @@ public:
void setStarsVisible(bool stars_visible) { m_star_params.visible = stars_visible; }
void setStarCount(u16 star_count, bool force_update);
void setStarColor(video::SColor star_color) { m_star_params.starcolor = star_color; }
- void setStarScale(f32 star_scale) { m_star_params.scale = star_scale; }
+ void setStarScale(f32 star_scale) { m_star_params.scale = star_scale; updateStars(); }
bool getCloudsVisible() const { return m_clouds_visible && m_clouds_enabled; }
const video::SColorf &getCloudColor() const { return m_cloudcolor_f; }
@@ -101,6 +103,8 @@ public:
void clearSkyboxTextures() { m_sky_params.textures.clear(); }
void addTextureToSkybox(std::string texture, int material_id,
ITextureSource *tsrc);
+ const video::SColorf &getCurrentStarColor() const { return m_star_color; }
+
private:
aabb3f m_box;
video::SMaterial m_materials[SKY_MATERIAL_COUNT];
@@ -154,6 +158,7 @@ private:
bool m_clouds_enabled = true; // Initialised to true, reset only by set_sky API
bool m_directional_colored_fog;
bool m_in_clouds = true; // Prevent duplicating bools to remember old values
+ bool m_enable_shaders = false;
video::SColorf m_bgcolor_bright_f = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f);
video::SColorf m_skycolor_bright_f = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f);
@@ -178,13 +183,17 @@ private:
bool m_default_tint = true;
- std::vector<v3f> m_stars;
+ u64 m_seed = 0;
+ irr_ptr<scene::SMeshBuffer> m_stars;
+ video::SColorf m_star_color;
video::ITexture *m_sun_texture;
video::ITexture *m_moon_texture;
video::ITexture *m_sun_tonemap;
video::ITexture *m_moon_tonemap;
+ void updateStars();
+
void draw_sun(video::IVideoDriver *driver, float sunsize, const video::SColor &suncolor,
const video::SColor &suncolor2, float wicked_time_of_day);
void draw_moon(video::IVideoDriver *driver, float moonsize, const video::SColor &mooncolor,
diff --git a/src/client/sound_openal.cpp b/src/client/sound_openal.cpp
index 20a651c1d..f4e61f93e 100644
--- a/src/client/sound_openal.cpp
+++ b/src/client/sound_openal.cpp
@@ -28,6 +28,7 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
#include <alc.h>
//#include <alext.h>
#elif defined(__APPLE__)
+ #define OPENAL_DEPRECATED
#include <OpenAL/al.h>
#include <OpenAL/alc.h>
//#include <OpenAL/alext.h>
@@ -337,14 +338,12 @@ private:
};
std::unordered_map<int, FadeState> m_sounds_fading;
- float m_fade_delay;
public:
OpenALSoundManager(SoundManagerSingleton *smg, OnDemandSoundFetcher *fetcher):
m_fetcher(fetcher),
m_device(smg->m_device.get()),
m_context(smg->m_context.get()),
- m_next_id(1),
- m_fade_delay(0)
+ m_next_id(1)
{
infostream << "Audio: Initialized: OpenAL " << std::endl;
}
@@ -616,38 +615,45 @@ public:
void fadeSound(int soundid, float step, float gain)
{
- m_sounds_fading[soundid] = FadeState(step, getSoundGain(soundid), gain);
+ // Ignore the command if step isn't valid.
+ if (step == 0)
+ return;
+ float current_gain = getSoundGain(soundid);
+ step = gain - current_gain > 0 ? abs(step) : -abs(step);
+ if (m_sounds_fading.find(soundid) != m_sounds_fading.end()) {
+ auto current_fade = m_sounds_fading[soundid];
+ // Do not replace the fade if it's equivalent.
+ if (current_fade.target_gain == gain && current_fade.step == step)
+ return;
+ m_sounds_fading.erase(soundid);
+ }
+ gain = rangelim(gain, 0, 1);
+ m_sounds_fading[soundid] = FadeState(step, current_gain, gain);
}
void doFades(float dtime)
{
- m_fade_delay += dtime;
-
- if (m_fade_delay < 0.1f)
- return;
+ for (auto i = m_sounds_fading.begin(); i != m_sounds_fading.end();) {
+ FadeState& fade = i->second;
+ assert(fade.step != 0);
+ fade.current_gain += (fade.step * dtime);
- float chkGain = 0;
- for (auto i = m_sounds_fading.begin();
- i != m_sounds_fading.end();) {
- if (i->second.step < 0.f)
- chkGain = -(i->second.current_gain);
+ if (fade.step < 0.f)
+ fade.current_gain = std::max(fade.current_gain, fade.target_gain);
else
- chkGain = i->second.current_gain;
+ fade.current_gain = std::min(fade.current_gain, fade.target_gain);
- if (chkGain < i->second.target_gain) {
- i->second.current_gain += (i->second.step * m_fade_delay);
- i->second.current_gain = rangelim(i->second.current_gain, 0, 1);
-
- updateSoundGain(i->first, i->second.current_gain);
- ++i;
- } else {
- if (i->second.target_gain <= 0.f)
- stopSound(i->first);
+ if (fade.current_gain <= 0.f)
+ stopSound(i->first);
+ else
+ updateSoundGain(i->first, fade.current_gain);
+ // The increment must happen during the erase call, or else it'll segfault.
+ if (fade.current_gain == fade.target_gain)
m_sounds_fading.erase(i++);
- }
+ else
+ i++;
}
- m_fade_delay = 0;
}
bool soundExists(int sound)
diff --git a/src/client/wieldmesh.cpp b/src/client/wieldmesh.cpp
index 8cd3e29a9..ad583210a 100644
--- a/src/client/wieldmesh.cpp
+++ b/src/client/wieldmesh.cpp
@@ -303,13 +303,24 @@ void WieldMeshSceneNode::setExtruded(const std::string &imagename,
}
}
-scene::SMesh *createSpecialNodeMesh(Client *client, content_t id, std::vector<ItemPartColor> *colors)
+scene::SMesh *createSpecialNodeMesh(Client *client, content_t id, std::vector<ItemPartColor> *colors, const ContentFeatures &f)
{
- MeshMakeData mesh_make_data(client, false, false);
+ MeshMakeData mesh_make_data(client, false);
MeshCollector collector;
mesh_make_data.setSmoothLighting(false);
MapblockMeshGenerator gen(&mesh_make_data, &collector);
- gen.renderSingle(id);
+ u8 param2 = 0;
+ if (f.param_type_2 == CPT2_WALLMOUNTED ||
+ f.param_type_2 == CPT2_COLORED_WALLMOUNTED) {
+ if (f.drawtype == NDT_TORCHLIKE)
+ param2 = 1;
+ else if (f.drawtype == NDT_SIGNLIKE ||
+ f.drawtype == NDT_NODEBOX ||
+ f.drawtype == NDT_MESH)
+ param2 = 4;
+ }
+ gen.renderSingle(id, param2);
+
colors->clear();
scene::SMesh *mesh = new scene::SMesh();
for (auto &prebuffers : collector.prebuffers)
@@ -319,8 +330,9 @@ scene::SMesh *createSpecialNodeMesh(Client *client, content_t id, std::vector<It
p.layer.texture = frame.texture;
p.layer.normal_texture = frame.normal_texture;
}
- for (video::S3DVertex &v : p.vertices)
+ for (video::S3DVertex &v : p.vertices) {
v.Color.setAlpha(255);
+ }
scene::SMeshBuffer *buf = new scene::SMeshBuffer();
buf->Material.setTexture(0, p.layer.texture);
p.layer.applyMaterialOptions(buf->Material);
@@ -368,73 +380,61 @@ void WieldMeshSceneNode::setItem(const ItemStack &item, Client *client, bool che
// Handle nodes
// See also CItemDefManager::createClientCached()
if (def.type == ITEM_NODE) {
- if (f.mesh_ptr[0]) {
- // e.g. mesh nodes and nodeboxes
- mesh = cloneMesh(f.mesh_ptr[0]);
- postProcessNodeMesh(mesh, f, m_enable_shaders, true,
- &m_material_type, &m_colors);
+ bool cull_backface = f.needsBackfaceCulling();
+
+ // Select rendering method
+ switch (f.drawtype) {
+ case NDT_AIRLIKE:
+ setExtruded("no_texture_airlike.png", "",
+ v3f(1.0, 1.0, 1.0), tsrc, 1);
+ break;
+ case NDT_SIGNLIKE:
+ case NDT_TORCHLIKE:
+ case NDT_RAILLIKE:
+ case NDT_PLANTLIKE:
+ case NDT_PLANTLIKE_ROOTED:
+ case NDT_FLOWINGLIQUID: {
+ v3f wscale = def.wield_scale;
+ if (f.drawtype == NDT_FLOWINGLIQUID)
+ wscale.Z *= 0.1f;
+ setExtruded(tsrc->getTextureName(f.tiles[0].layers[0].texture_id),
+ tsrc->getTextureName(f.tiles[0].layers[1].texture_id),
+ wscale, tsrc,
+ f.tiles[0].layers[0].animation_frame_count);
+ // Add color
+ const TileLayer &l0 = f.tiles[0].layers[0];
+ m_colors.emplace_back(l0.has_color, l0.color);
+ const TileLayer &l1 = f.tiles[0].layers[1];
+ m_colors.emplace_back(l1.has_color, l1.color);
+ break;
+ }
+ case NDT_NORMAL:
+ case NDT_ALLFACES:
+ case NDT_LIQUID:
+ setCube(f, def.wield_scale);
+ break;
+ default:
+ // Render non-trivial drawtypes like the actual node
+ mesh = createSpecialNodeMesh(client, id, &m_colors, f);
changeToMesh(mesh);
mesh->drop();
- // mesh is pre-scaled by BS * f->visual_scale
m_meshnode->setScale(
- def.wield_scale * WIELD_SCALE_FACTOR
- / (BS * f.visual_scale));
- } else {
- switch (f.drawtype) {
- case NDT_AIRLIKE: {
- changeToMesh(nullptr);
- break;
- }
- case NDT_PLANTLIKE: {
- setExtruded(tsrc->getTextureName(f.tiles[0].layers[0].texture_id),
- tsrc->getTextureName(f.tiles[0].layers[1].texture_id),
- def.wield_scale, tsrc,
- f.tiles[0].layers[0].animation_frame_count);
- // Add color
- const TileLayer &l0 = f.tiles[0].layers[0];
- m_colors.emplace_back(l0.has_color, l0.color);
- const TileLayer &l1 = f.tiles[0].layers[1];
- m_colors.emplace_back(l1.has_color, l1.color);
- break;
- }
- case NDT_PLANTLIKE_ROOTED: {
- setExtruded(tsrc->getTextureName(f.special_tiles[0].layers[0].texture_id),
- "", def.wield_scale, tsrc,
- f.special_tiles[0].layers[0].animation_frame_count);
- // Add color
- const TileLayer &l0 = f.special_tiles[0].layers[0];
- m_colors.emplace_back(l0.has_color, l0.color);
- break;
- }
- case NDT_NORMAL:
- case NDT_ALLFACES:
- case NDT_LIQUID:
- case NDT_FLOWINGLIQUID: {
- setCube(f, def.wield_scale);
- break;
- }
- default: {
- mesh = createSpecialNodeMesh(client, id, &m_colors);
- changeToMesh(mesh);
- mesh->drop();
- m_meshnode->setScale(
- def.wield_scale * WIELD_SCALE_FACTOR
- / (BS * f.visual_scale));
- }
- }
+ def.wield_scale * WIELD_SCALE_FACTOR
+ / (BS * f.visual_scale));
+ break;
}
+
u32 material_count = m_meshnode->getMaterialCount();
for (u32 i = 0; i < material_count; ++i) {
video::SMaterial &material = m_meshnode->getMaterial(i);
material.MaterialType = m_material_type;
material.MaterialTypeParam = 0.5f;
- material.setFlag(video::EMF_BACK_FACE_CULLING, true);
+ material.setFlag(video::EMF_BACK_FACE_CULLING, cull_backface);
material.setFlag(video::EMF_BILINEAR_FILTER, m_bilinear_filter);
material.setFlag(video::EMF_TRILINEAR_FILTER, m_trilinear_filter);
}
return;
- }
- else if (!def.inventory_image.empty()) {
+ } else if (!def.inventory_image.empty()) {
setExtruded(def.inventory_image, def.inventory_overlay, def.wield_scale,
tsrc, 1);
m_colors.emplace_back();
@@ -529,6 +529,8 @@ void getItemMesh(Client *client, const ItemStack &item, ItemMesh *result)
// Shading is on by default
result->needs_shading = true;
+ bool cull_backface = f.needsBackfaceCulling();
+
// If inventory_image is defined, it overrides everything else
if (!def.inventory_image.empty()) {
mesh = getExtrudedMesh(tsrc, def.inventory_image,
@@ -538,51 +540,56 @@ void getItemMesh(Client *client, const ItemStack &item, ItemMesh *result)
result->buffer_colors.emplace_back(true, video::SColor(0xFFFFFFFF));
// Items with inventory images do not need shading
result->needs_shading = false;
+ } else if (def.type == ITEM_NODE && f.drawtype == NDT_AIRLIKE) {
+ // Fallback image for airlike node
+ mesh = getExtrudedMesh(tsrc, "no_texture_airlike.png",
+ def.inventory_overlay);
+ result->needs_shading = false;
} else if (def.type == ITEM_NODE) {
- if (f.mesh_ptr[0]) {
- mesh = cloneMesh(f.mesh_ptr[0]);
- scaleMesh(mesh, v3f(0.12, 0.12, 0.12));
+ switch (f.drawtype) {
+ case NDT_NORMAL:
+ case NDT_ALLFACES:
+ case NDT_LIQUID:
+ case NDT_FLOWINGLIQUID: {
+ scene::IMesh *cube = g_extrusion_mesh_cache->createCube();
+ mesh = cloneMesh(cube);
+ cube->drop();
+ if (f.drawtype == NDT_FLOWINGLIQUID) {
+ scaleMesh(mesh, v3f(1.2, 0.03, 1.2));
+ translateMesh(mesh, v3f(0, -0.57, 0));
+ } else
+ scaleMesh(mesh, v3f(1.2, 1.2, 1.2));
+ // add overlays
postProcessNodeMesh(mesh, f, false, false, nullptr,
- &result->buffer_colors);
- } else {
- switch (f.drawtype) {
- case NDT_PLANTLIKE: {
- mesh = getExtrudedMesh(tsrc,
- tsrc->getTextureName(f.tiles[0].layers[0].texture_id),
- tsrc->getTextureName(f.tiles[0].layers[1].texture_id));
- // Add color
- const TileLayer &l0 = f.tiles[0].layers[0];
- result->buffer_colors.emplace_back(l0.has_color, l0.color);
- const TileLayer &l1 = f.tiles[0].layers[1];
- result->buffer_colors.emplace_back(l1.has_color, l1.color);
- break;
- }
- case NDT_PLANTLIKE_ROOTED: {
- mesh = getExtrudedMesh(tsrc,
- tsrc->getTextureName(f.special_tiles[0].layers[0].texture_id), "");
- // Add color
- const TileLayer &l0 = f.special_tiles[0].layers[0];
- result->buffer_colors.emplace_back(l0.has_color, l0.color);
- break;
- }
- case NDT_NORMAL:
- case NDT_ALLFACES:
- case NDT_LIQUID:
- case NDT_FLOWINGLIQUID: {
- scene::IMesh *cube = g_extrusion_mesh_cache->createCube();
- mesh = cloneMesh(cube);
- cube->drop();
- scaleMesh(mesh, v3f(1.2, 1.2, 1.2));
- // add overlays
- postProcessNodeMesh(mesh, f, false, false, nullptr,
- &result->buffer_colors);
- break;
- }
- default: {
- mesh = createSpecialNodeMesh(client, id, &result->buffer_colors);
- scaleMesh(mesh, v3f(0.12, 0.12, 0.12));
- }
- }
+ &result->buffer_colors, true);
+ if (f.drawtype == NDT_ALLFACES)
+ scaleMesh(mesh, v3f(f.visual_scale));
+ break;
+ }
+ case NDT_PLANTLIKE: {
+ mesh = getExtrudedMesh(tsrc,
+ tsrc->getTextureName(f.tiles[0].layers[0].texture_id),
+ tsrc->getTextureName(f.tiles[0].layers[1].texture_id));
+ // Add color
+ const TileLayer &l0 = f.tiles[0].layers[0];
+ result->buffer_colors.emplace_back(l0.has_color, l0.color);
+ const TileLayer &l1 = f.tiles[0].layers[1];
+ result->buffer_colors.emplace_back(l1.has_color, l1.color);
+ break;
+ }
+ case NDT_PLANTLIKE_ROOTED: {
+ mesh = getExtrudedMesh(tsrc,
+ tsrc->getTextureName(f.special_tiles[0].layers[0].texture_id), "");
+ // Add color
+ const TileLayer &l0 = f.special_tiles[0].layers[0];
+ result->buffer_colors.emplace_back(l0.has_color, l0.color);
+ break;
+ }
+ default:
+ // Render non-trivial drawtypes like the actual node
+ mesh = createSpecialNodeMesh(client, id, &result->buffer_colors, f);
+ scaleMesh(mesh, v3f(0.12, 0.12, 0.12));
+ break;
}
u32 mc = mesh->getMeshBufferCount();
@@ -593,7 +600,7 @@ void getItemMesh(Client *client, const ItemStack &item, ItemMesh *result)
material.MaterialTypeParam = 0.5f;
material.setFlag(video::EMF_BILINEAR_FILTER, false);
material.setFlag(video::EMF_TRILINEAR_FILTER, false);
- material.setFlag(video::EMF_BACK_FACE_CULLING, true);
+ material.setFlag(video::EMF_BACK_FACE_CULLING, cull_backface);
material.setFlag(video::EMF_LIGHTING, false);
}