Skip to content

Commit ffd16e3

Browse files
RealBadAngelest31
authored andcommittedJun 27, 2015
Add minimap feature
1 parent 3376d2e commit ffd16e3

23 files changed

+883
-30
lines changed
 

Diff for: ‎build/android/jni/Android.mk

+1
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ LOCAL_SRC_FILES := \
183183
jni/src/mg_decoration.cpp \
184184
jni/src/mg_ore.cpp \
185185
jni/src/mg_schematic.cpp \
186+
jni/src/minimap.cpp \
186187
jni/src/mods.cpp \
187188
jni/src/nameidmapping.cpp \
188189
jni/src/nodedef.cpp \

Diff for: ‎client/shaders/minimap_shader/opengl_fragment.glsl

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
uniform sampler2D baseTexture;
2+
uniform sampler2D normalTexture;
3+
uniform vec3 yawVec;
4+
5+
void main (void)
6+
{
7+
vec2 uv = gl_TexCoord[0].st;
8+
9+
//texture sampling rate
10+
const float step = 1.0 / 256.0;
11+
float tl = texture2D(normalTexture, vec2(uv.x - step, uv.y + step)).r;
12+
float t = texture2D(normalTexture, vec2(uv.x - step, uv.y - step)).r;
13+
float tr = texture2D(normalTexture, vec2(uv.x + step, uv.y + step)).r;
14+
float r = texture2D(normalTexture, vec2(uv.x + step, uv.y)).r;
15+
float br = texture2D(normalTexture, vec2(uv.x + step, uv.y - step)).r;
16+
float b = texture2D(normalTexture, vec2(uv.x, uv.y - step)).r;
17+
float bl = texture2D(normalTexture, vec2(uv.x - step, uv.y - step)).r;
18+
float l = texture2D(normalTexture, vec2(uv.x - step, uv.y)).r;
19+
float dX = (tr + 2.0 * r + br) - (tl + 2.0 * l + bl);
20+
float dY = (bl + 2.0 * b + br) - (tl + 2.0 * t + tr);
21+
vec4 bump = vec4 (normalize(vec3 (dX, dY, 0.1)),1.0);
22+
float height = 2.0 * texture2D(normalTexture, vec2(uv.x, uv.y)).r - 1.0;
23+
vec4 base = texture2D(baseTexture, uv).rgba;
24+
vec3 L = normalize(vec3(0.0, 0.75, 1.0));
25+
float specular = pow(clamp(dot(reflect(L, bump.xyz), yawVec), 0.0, 1.0), 1.0);
26+
float diffuse = dot(yawVec, bump.xyz);
27+
28+
vec3 color = (1.1 * diffuse + 0.05 * height + 0.5 * specular) * base.rgb;
29+
vec4 col = vec4(color.rgb, base.a);
30+
col *= gl_Color;
31+
gl_FragColor = vec4(col.rgb, base.a);
32+
}

Diff for: ‎client/shaders/minimap_shader/opengl_vertex.glsl

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
uniform mat4 mWorldViewProj;
2+
uniform mat4 mInvWorld;
3+
uniform mat4 mTransWorld;
4+
uniform mat4 mWorld;
5+
6+
void main(void)
7+
{
8+
gl_TexCoord[0] = gl_MultiTexCoord0;
9+
gl_Position = mWorldViewProj * gl_Vertex;
10+
gl_FrontColor = gl_BackColor = gl_Color;
11+
}

Diff for: ‎src/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ set(client_SRCS
423423
main.cpp
424424
mapblock_mesh.cpp
425425
mesh.cpp
426+
minimap.cpp
426427
particles.cpp
427428
shader.cpp
428429
sky.cpp

Diff for: ‎src/client.cpp

+21-14
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3434
#include "porting.h"
3535
#include "mapblock_mesh.h"
3636
#include "mapblock.h"
37+
#include "minimap.h"
3738
#include "settings.h"
3839
#include "profiler.h"
3940
#include "gettext.h"
@@ -185,11 +186,6 @@ void * MeshUpdateThread::Thread()
185186
ScopeProfiler sp(g_profiler, "Client: Mesh making");
186187

187188
MapBlockMesh *mesh_new = new MapBlockMesh(q->data, m_camera_offset);
188-
if(mesh_new->getMesh()->getMeshBufferCount() == 0)
189-
{
190-
delete mesh_new;
191-
mesh_new = NULL;
192-
}
193189

194190
MeshUpdateResult r;
195191
r.p = q->p;
@@ -274,6 +270,7 @@ Client::Client(
274270
// Add local player
275271
m_env.addPlayer(new LocalPlayer(this, playername));
276272

273+
m_mapper = new Mapper(device, this);
277274
m_cache_save_interval = g_settings->getU16("server_map_save_interval");
278275

279276
m_cache_smooth_lighting = g_settings->getBool("smooth_lighting");
@@ -537,27 +534,37 @@ void Client::step(float dtime)
537534
*/
538535
{
539536
int num_processed_meshes = 0;
540-
while(!m_mesh_update_thread.m_queue_out.empty())
537+
while (!m_mesh_update_thread.m_queue_out.empty())
541538
{
542539
num_processed_meshes++;
543540
MeshUpdateResult r = m_mesh_update_thread.m_queue_out.pop_frontNoEx();
544541
MapBlock *block = m_env.getMap().getBlockNoCreateNoEx(r.p);
545-
if(block) {
542+
MinimapMapblock *minimap_mapblock = NULL;
543+
if (block) {
546544
// Delete the old mesh
547-
if(block->mesh != NULL)
548-
{
549-
// TODO: Remove hardware buffers of meshbuffers of block->mesh
545+
if (block->mesh != NULL) {
550546
delete block->mesh;
551547
block->mesh = NULL;
552548
}
553549

554-
// Replace with the new mesh
555-
block->mesh = r.mesh;
550+
if (r.mesh)
551+
minimap_mapblock = r.mesh->getMinimapMapblock();
552+
553+
if (r.mesh && r.mesh->getMesh()->getMeshBufferCount() == 0) {
554+
delete r.mesh;
555+
block->mesh = NULL;
556+
} else {
557+
// Replace with the new mesh
558+
block->mesh = r.mesh;
559+
}
556560
} else {
557561
delete r.mesh;
562+
minimap_mapblock = NULL;
558563
}
559564

560-
if(r.ack_block_to_server) {
565+
m_mapper->addBlock(r.p, minimap_mapblock);
566+
567+
if (r.ack_block_to_server) {
561568
/*
562569
Acknowledge block
563570
[0] u8 count
@@ -567,7 +574,7 @@ void Client::step(float dtime)
567574
}
568575
}
569576

570-
if(num_processed_meshes > 0)
577+
if (num_processed_meshes > 0)
571578
g_profiler->graphAdd("num_processed_meshes", num_processed_meshes);
572579
}
573580

Diff for: ‎src/client.h

+6
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ struct MapDrawControl;
4848
class MtEventManager;
4949
struct PointedThing;
5050
class Database;
51+
class Mapper;
52+
struct MinimapMapblock;
5153

5254
struct QueuedMeshUpdate
5355
{
@@ -504,6 +506,9 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
504506
float getCurRate(void);
505507
float getAvgRate(void);
506508

509+
Mapper* getMapper ()
510+
{ return m_mapper; }
511+
507512
// IGameDef interface
508513
virtual IItemDefManager* getItemDefManager();
509514
virtual INodeDefManager* getNodeDefManager();
@@ -583,6 +588,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
583588
ParticleManager m_particle_manager;
584589
con::Connection m_con;
585590
IrrlichtDevice *m_device;
591+
Mapper *m_mapper;
586592
// Server serialization version
587593
u8 m_server_ser_ver;
588594
// Used version of the protocol with server

Diff for: ‎src/client/tile.cpp

+40
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,8 @@ class TextureSource : public IWritableTextureSource
382382
video::IImage* generateImage(const std::string &name);
383383

384384
video::ITexture* getNormalTexture(const std::string &name);
385+
video::SColor getTextureAverageColor(const std::string &name);
386+
385387
private:
386388

387389
// The id of the thread that is allowed to use irrlicht directly
@@ -2008,3 +2010,41 @@ video::ITexture* TextureSource::getNormalTexture(const std::string &name)
20082010
}
20092011
return NULL;
20102012
}
2013+
2014+
video::SColor TextureSource::getTextureAverageColor(const std::string &name)
2015+
{
2016+
video::IVideoDriver *driver = m_device->getVideoDriver();
2017+
video::SColor c(0, 0, 0, 0);
2018+
u32 id;
2019+
video::ITexture *texture = getTexture(name, &id);
2020+
video::IImage *image = driver->createImage(texture,
2021+
core::position2d<s32>(0, 0),
2022+
texture->getOriginalSize());
2023+
u32 total = 0;
2024+
u32 tR = 0;
2025+
u32 tG = 0;
2026+
u32 tB = 0;
2027+
core::dimension2d<u32> dim = image->getDimension();
2028+
u16 step = 1;
2029+
if (dim.Width > 16)
2030+
step = dim.Width / 16;
2031+
for (u16 x = 0; x < dim.Width; x += step) {
2032+
for (u16 y = 0; y < dim.Width; y += step) {
2033+
c = image->getPixel(x,y);
2034+
if (c.getAlpha() > 0) {
2035+
total++;
2036+
tR += c.getRed();
2037+
tG += c.getGreen();
2038+
tB += c.getBlue();
2039+
}
2040+
}
2041+
}
2042+
image->drop();
2043+
if (total > 0) {
2044+
c.setRed(tR / total);
2045+
c.setGreen(tG / total);
2046+
c.setBlue(tB / total);
2047+
}
2048+
c.setAlpha(255);
2049+
return c;
2050+
}

Diff for: ‎src/client/tile.h

+2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class ITextureSource : public ISimpleTextureSource
110110
virtual video::ITexture* generateTextureFromMesh(
111111
const TextureFromMeshParams &params)=0;
112112
virtual video::ITexture* getNormalTexture(const std::string &name)=0;
113+
virtual video::SColor getTextureAverageColor(const std::string &name)=0;
113114
};
114115

115116
class IWritableTextureSource : public ITextureSource
@@ -131,6 +132,7 @@ class IWritableTextureSource : public ITextureSource
131132
virtual void insertSourceImage(const std::string &name, video::IImage *img)=0;
132133
virtual void rebuildImagesAndTextures()=0;
133134
virtual video::ITexture* getNormalTexture(const std::string &name)=0;
135+
virtual video::SColor getTextureAverageColor(const std::string &name)=0;
134136
};
135137

136138
IWritableTextureSource* createTextureSource(IrrlichtDevice *device);

Diff for: ‎src/defaultsettings.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ void set_default_settings(Settings *settings)
4343
settings->setDefault("keymap_special1", "KEY_KEY_E");
4444
settings->setDefault("keymap_chat", "KEY_KEY_T");
4545
settings->setDefault("keymap_cmd", "/");
46+
settings->setDefault("keymap_minimap", "KEY_F9");
4647
settings->setDefault("keymap_console", "KEY_F10");
4748
settings->setDefault("keymap_rangeselect", "KEY_KEY_R");
4849
settings->setDefault("keymap_freemove", "KEY_KEY_K");
@@ -176,6 +177,9 @@ void set_default_settings(Settings *settings)
176177
settings->setDefault("enable_particles", "true");
177178
settings->setDefault("enable_mesh_cache", "true");
178179

180+
settings->setDefault("enable_minimap", "true");
181+
settings->setDefault("minimap_shape_round", "true");
182+
179183
settings->setDefault("curl_timeout", "5000");
180184
settings->setDefault("curl_parallel_limit", "8");
181185
settings->setDefault("curl_file_download_timeout", "300000");

Diff for: ‎src/drawscene.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -416,10 +416,11 @@ void draw_plain(Camera& camera, bool show_hud, Hud& hud,
416416
camera.drawWieldedTool();
417417
}
418418

419-
void draw_scene(video::IVideoDriver* driver, scene::ISceneManager* smgr,
420-
Camera& camera, Client& client, LocalPlayer* player, Hud& hud,
421-
gui::IGUIEnvironment* guienv, std::vector<aabb3f> hilightboxes,
422-
const v2u32& screensize, video::SColor skycolor, bool show_hud)
419+
void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr,
420+
Camera &camera, Client& client, LocalPlayer *player, Hud &hud,
421+
Mapper &mapper, gui::IGUIEnvironment *guienv,
422+
std::vector<aabb3f> hilightboxes, const v2u32 &screensize,
423+
video::SColor skycolor, bool show_hud, bool show_minimap)
423424
{
424425
TimeTaker timer("smgr");
425426

@@ -484,6 +485,8 @@ void draw_scene(video::IVideoDriver* driver, scene::ISceneManager* smgr,
484485
hud.drawCrosshair();
485486
hud.drawHotbar(client.getPlayerItem());
486487
hud.drawLuaElements(camera.getOffset());
488+
if (show_minimap)
489+
mapper.drawMinimap();
487490
}
488491

489492
guienv->drawAll();

Diff for: ‎src/drawscene.h

+9-7
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,18 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2222

2323
#include "camera.h"
2424
#include "hud.h"
25+
#include "minimap.h"
2526
#include "irrlichttypes_extrabloated.h"
2627

2728

28-
void draw_load_screen(const std::wstring &text, IrrlichtDevice* device,
29-
gui::IGUIEnvironment* guienv, float dtime=0, int percent=0,
30-
bool clouds=true);
29+
void draw_load_screen(const std::wstring &text, IrrlichtDevice *device,
30+
gui::IGUIEnvironment *guienv, float dtime = 0, int percent = 0,
31+
bool clouds = true);
3132

32-
void draw_scene(video::IVideoDriver* driver, scene::ISceneManager* smgr,
33-
Camera& camera, Client& client, LocalPlayer* player, Hud& hud,
34-
gui::IGUIEnvironment* guienv, std::vector<aabb3f> hilightboxes,
35-
const v2u32& screensize, video::SColor skycolor, bool show_hud);
33+
void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr,
34+
Camera &camera, Client &client, LocalPlayer *player, Hud &hud,
35+
Mapper &mapper, gui::IGUIEnvironment *guienv,
36+
std::vector<aabb3f> hilightboxes, const v2u32 &screensize,
37+
video::SColor skycolor, bool show_hud, bool show_minimap);
3638

3739
#endif /* DRAWSCENE_H_ */

0 commit comments

Comments
 (0)
Please sign in to comment.