From 7c37b1891adcddc0e7d11e5faafddaa554443318 Mon Sep 17 00:00:00 2001 From: Diego Martínez Date: Mon, 22 Apr 2013 06:53:55 -0300 Subject: Added support for alignment in HUD items --- doc/lua_api.txt | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'doc') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index aa4503879..774448778 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -409,6 +409,9 @@ ranging in value from 0 to 1. The name field is not yet used, but should contain a description of what the HUD element represents. The direction field is the direction in which something is drawn. 0 draws from left to right, 1 draws from right to left, 2 draws from top to bottom, and 3 draws from bottom to top. +The alignment field specifies how the item will be aligned. It ranges from -1 to 1, +with 0 being the center, -1 is moved to the left/up, and 1 is to the right/down. Fractional +values can be used. Below are the specific uses for fields in each type; fields not listed for that type are ignored. Note: Future revisions to the HUD API may be incompatible; the HUD API is still in the experimental stages. @@ -418,6 +421,7 @@ Note: Future revisions to the HUD API may be incompatible; the HUD API is still - scale: The scale of the image, with 1 being the original texture size. Only the X coordinate scale is used. - text: The name of the texture that is displayed. + - alignment: The alignment of the image. - text Displays text on the HUD. - scale: Defines the bounding rectangle of the text. @@ -425,6 +429,7 @@ Note: Future revisions to the HUD API may be incompatible; the HUD API is still - text: The text to be displayed in the HUD element. - number: An integer containing the RGB value of the color used to draw the text. Specify 0xFFFFFF for white text, 0xFF0000 for red, and so on. + - alignment: The alignment of the text. - statbar Displays a horizontal bar made up of half-images. - text: The name of the texture that is used. @@ -1857,4 +1862,6 @@ HUD Definition (hud_add, hud_get) ^ Selected item in inventory. 0 for no item selected. direction = 0, ^ Direction: 0: left-right, 1: right-left, 2: top-bottom, 3: bottom-top + alignment = {x=0, y=0}, + ^ See "HUD Element Types" } -- cgit v1.2.3 From 9894167bbf516c40bf2b8577179ff8f13b8b54e2 Mon Sep 17 00:00:00 2001 From: Diego Martínez Date: Mon, 22 Apr 2013 20:47:59 -0300 Subject: Added offset support for HUD items --- doc/lua_api.txt | 8 ++++++++ src/client.cpp | 2 ++ src/client.h | 1 + src/clientserver.h | 1 + src/game.cpp | 6 ++++++ src/hud.cpp | 17 +++++++++++------ src/hud.h | 6 ++++-- src/scriptapi_object.cpp | 8 ++++++++ src/server.cpp | 2 ++ 9 files changed, 43 insertions(+), 8 deletions(-) (limited to 'doc') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 774448778..76f687f8e 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -412,6 +412,9 @@ The direction field is the direction in which something is drawn. The alignment field specifies how the item will be aligned. It ranges from -1 to 1, with 0 being the center, -1 is moved to the left/up, and 1 is to the right/down. Fractional values can be used. +The offset field specifies a pixel offset from the position. Contrary to position, +the offset is not scaled to screen size. This allows for some precisely-positioned +items in the HUD. Below are the specific uses for fields in each type; fields not listed for that type are ignored. Note: Future revisions to the HUD API may be incompatible; the HUD API is still in the experimental stages. @@ -422,6 +425,7 @@ Note: Future revisions to the HUD API may be incompatible; the HUD API is still Only the X coordinate scale is used. - text: The name of the texture that is displayed. - alignment: The alignment of the image. + - offset: offset in pixels from position. - text Displays text on the HUD. - scale: Defines the bounding rectangle of the text. @@ -430,12 +434,14 @@ Note: Future revisions to the HUD API may be incompatible; the HUD API is still - number: An integer containing the RGB value of the color used to draw the text. Specify 0xFFFFFF for white text, 0xFF0000 for red, and so on. - alignment: The alignment of the text. + - offset: offset in pixels from position. - statbar Displays a horizontal bar made up of half-images. - text: The name of the texture that is used. - number: The number of half-textures that are displayed. If odd, will end with a vertically center-split texture. - direction + - offset: offset in pixels from position. - inventory - text: The name of the inventory list to be displayed. - number: Number of items in the inventory to be displayed. @@ -1864,4 +1870,6 @@ HUD Definition (hud_add, hud_get) ^ Direction: 0: left-right, 1: right-left, 2: top-bottom, 3: bottom-top alignment = {x=0, y=0}, ^ See "HUD Element Types" + offset = {x=0, y=0}, + ^ See "HUD Element Types" } diff --git a/src/client.cpp b/src/client.cpp index 8db6f2f40..15fb6932a 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -2055,6 +2055,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id) u32 item = readU32(is); u32 dir = readU32(is); v2f align = readV2F1000(is); + v2f offset = readV2F1000(is); ClientEvent event; event.type = CE_HUDADD; @@ -2068,6 +2069,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id) event.hudadd.item = item; event.hudadd.dir = dir; event.hudadd.align = new v2f(align); + event.hudadd.offset = new v2f(offset); m_client_event_queue.push_back(event); } else if(command == TOCLIENT_HUDRM) diff --git a/src/client.h b/src/client.h index ff42f3e05..67ba6c565 100644 --- a/src/client.h +++ b/src/client.h @@ -231,6 +231,7 @@ struct ClientEvent u32 item; u32 dir; v2f *align; + v2f *offset; } hudadd; struct{ u32 id; diff --git a/src/clientserver.h b/src/clientserver.h index 0418d10b3..5e981c202 100644 --- a/src/clientserver.h +++ b/src/clientserver.h @@ -453,6 +453,7 @@ enum ToClientCommand u32 item u32 dir v2f1000 align + v2f1000 offset */ TOCLIENT_HUDRM = 0x50, diff --git a/src/game.cpp b/src/game.cpp index 2c73dfa6f..cbd9eab4d 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2107,6 +2107,7 @@ void the_game( delete event.hudadd.scale; delete event.hudadd.text; delete event.hudadd.align; + delete event.hudadd.offset; continue; } @@ -2120,6 +2121,7 @@ void the_game( e->item = event.hudadd.item; e->dir = event.hudadd.dir; e->align = *event.hudadd.align; + e->offset = *event.hudadd.offset; if (id == nhudelem) player->hud.push_back(e); @@ -2131,6 +2133,7 @@ void the_game( delete event.hudadd.scale; delete event.hudadd.text; delete event.hudadd.align; + delete event.hudadd.offset; } else if (event.type == CE_HUDRM) { @@ -2175,6 +2178,9 @@ void the_game( case HUD_STAT_ALIGN: e->align = *event.hudchange.v2fdata; break; + case HUD_STAT_OFFSET: + e->offset = *event.hudchange.v2fdata; + break; } delete event.hudchange.v2fdata; diff --git a/src/hud.cpp b/src/hud.cpp index 0f3ab40d2..9db92db52 100644 --- a/src/hud.cpp +++ b/src/hud.cpp @@ -189,6 +189,7 @@ void Hud::drawLuaElements() { v2s32 offset((e->align.X - 1.0) * ((imgsize.Width * e->scale.X) / 2), (e->align.Y - 1.0) * ((imgsize.Height * e->scale.X) / 2)); rect += offset; + rect += v2s32(e->offset.X, e->offset.Y); driver->draw2DImage(texture, rect, core::rect(core::position2d(0,0), imgsize), NULL, colors, true); @@ -202,11 +203,13 @@ void Hud::drawLuaElements() { core::dimension2d textsize = font->getDimension(text.c_str()); v2s32 offset((e->align.X - 1.0) * (textsize.Width / 2), (e->align.Y - 1.0) * (textsize.Height / 2)); - font->draw(text.c_str(), size + pos + offset, color); + v2s32 offs(e->offset.X, e->offset.Y); + font->draw(text.c_str(), size + pos + offset + offs, color); + break; } + case HUD_ELEM_STATBAR: { + v2s32 offs(e->offset.X, e->offset.Y); + drawStatbar(pos, HUD_CORNER_UPPER, e->dir, e->text, e->number, offs); break; } - case HUD_ELEM_STATBAR: - drawStatbar(pos, HUD_CORNER_UPPER, e->dir, e->text, e->number); - break; case HUD_ELEM_INVENTORY: { InventoryList *inv = inventory->getList(e->text); drawItem(pos, hotbar_imagesize, e->number, inv, e->item, e->dir); @@ -219,7 +222,7 @@ void Hud::drawLuaElements() { } -void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s32 count) { +void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s32 count, v2s32 offset) { const video::SColor color(255, 255, 255, 255); const video::SColor colors[] = {color, color, color, color}; @@ -234,6 +237,8 @@ void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s if (corner & HUD_CORNER_LOWER) p -= srcd.Height; + p += offset; + v2s32 steppos; switch (drawdir) { case HUD_DIR_RIGHT_LEFT: @@ -285,7 +290,7 @@ void Hud::drawHotbar(v2s32 centerlowerpos, s32 halfheartcount, u16 playeritem) { drawItem(pos, hotbar_imagesize, hotbar_itemcount, mainlist, playeritem + 1, 0); drawStatbar(pos - v2s32(0, 4), HUD_CORNER_LOWER, HUD_DIR_LEFT_RIGHT, - "heart.png", halfheartcount); + "heart.png", halfheartcount, v2s32(0, 0)); } diff --git a/src/hud.h b/src/hud.h index 7a1dff3d8..104a2f00d 100644 --- a/src/hud.h +++ b/src/hud.h @@ -48,7 +48,8 @@ enum HudElementStat { HUD_STAT_NUMBER, HUD_STAT_ITEM, HUD_STAT_DIR, - HUD_STAT_ALIGN + HUD_STAT_ALIGN, + HUD_STAT_OFFSET }; struct HudElement { @@ -61,6 +62,7 @@ struct HudElement { u32 item; u32 dir; v2f align; + v2f offset; }; @@ -108,7 +110,7 @@ public: void drawItem(v2s32 upperleftpos, s32 imgsize, s32 itemcount, InventoryList *mainlist, u16 selectitem, u16 direction); void drawLuaElements(); - void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s32 count); + void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s32 count, v2s32 offset); void drawHotbar(v2s32 centerlowerpos, s32 halfheartcount, u16 playeritem); void resizeHotbar(); diff --git a/src/scriptapi_object.cpp b/src/scriptapi_object.cpp index c07f6565d..6669ad871 100644 --- a/src/scriptapi_object.cpp +++ b/src/scriptapi_object.cpp @@ -48,6 +48,7 @@ struct EnumString es_HudElementStat[] = {HUD_STAT_ITEM, "item"}, {HUD_STAT_DIR, "direction"}, {HUD_STAT_ALIGN, "alignment"}, + {HUD_STAT_OFFSET, "offset"}, {0, NULL}, }; @@ -756,6 +757,10 @@ int ObjectRef::l_hud_add(lua_State *L) elem->align = lua_istable(L, -1) ? read_v2f(L, -1) : v2f(); lua_pop(L, 1); + lua_getfield(L, 2, "offset"); + elem->offset = lua_istable(L, -1) ? read_v2f(L, -1) : v2f(); + lua_pop(L, 1); + u32 id = get_server(L)->hudAdd(player, elem); if (id == (u32)-1) { delete elem; @@ -841,6 +846,9 @@ int ObjectRef::l_hud_change(lua_State *L) case HUD_STAT_ALIGN: e->align = read_v2f(L, 4); value = &e->align; + case HUD_STAT_OFFSET: + e->offset = read_v2f(L, 4); + value = &e->offset; } get_server(L)->hudChange(player, id, stat, value); diff --git a/src/server.cpp b/src/server.cpp index b8f3e4da8..dda2165c8 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -3617,6 +3617,7 @@ void Server::SendHUDAdd(u16 peer_id, u32 id, HudElement *form) writeU32(os, form->item); writeU32(os, form->dir); writeV2F1000(os, form->align); + writeV2F1000(os, form->offset); // Make data buffer std::string s = os.str(); @@ -3652,6 +3653,7 @@ void Server::SendHUDChange(u16 peer_id, u32 id, HudElementStat stat, void *value case HUD_STAT_POS: case HUD_STAT_SCALE: case HUD_STAT_ALIGN: + case HUD_STAT_OFFSET: writeV2F1000(os, *(v2f *)value); break; case HUD_STAT_NAME: -- cgit v1.2.3 From 3d4d0cb5749a68436cccd08b7a135f9bb7527038 Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Fri, 29 Mar 2013 23:28:13 -0400 Subject: Add option to not prepend "Server -!- " to messages sent with minetest.chat_send_player() --- builtin/chatcommands.lua | 2 +- doc/lua_api.txt | 3 ++- src/scriptapi.cpp | 7 +++++-- src/server.cpp | 7 +++++-- src/server.h | 2 +- 5 files changed, 14 insertions(+), 7 deletions(-) (limited to 'doc') diff --git a/builtin/chatcommands.lua b/builtin/chatcommands.lua index 9f14749f4..f548fb01d 100644 --- a/builtin/chatcommands.lua +++ b/builtin/chatcommands.lua @@ -675,7 +675,7 @@ minetest.register_chatcommand("msg", { if found then if minetest.env:get_player_by_name(sendto) then minetest.log("action", "PM from "..name.." to "..sendto..": "..message) - minetest.chat_send_player(sendto, "PM from "..name..": "..message) + minetest.chat_send_player(sendto, "PM from "..name..": "..message, false) minetest.chat_send_player(name, "Message sent") else minetest.chat_send_player(name, "The player "..sendto.." is not online") diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 76f687f8e..38e12882d 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1005,7 +1005,8 @@ minetest.check_player_privs(name, {priv1=true,...}) -> bool, missing_privs Chat: minetest.chat_send_all(text) -minetest.chat_send_player(name, text) +minetest.chat_send_player(name, text, prepend) +^ prepend: optional, if it is set to false "Server -!- " will not be prepended to the message Inventory: minetest.get_inventory(location) -> InvRef diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index 8d472e6b8..3b0c15f8a 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -754,15 +754,18 @@ static int l_chat_send_all(lua_State *L) return 0; } -// chat_send_player(name, text) +// chat_send_player(name, text, prepend) static int l_chat_send_player(lua_State *L) { const char *name = luaL_checkstring(L, 1); const char *text = luaL_checkstring(L, 2); + bool prepend = true; + if (lua_isboolean(L, 3)) + prepend = lua_toboolean(L, 3); // Get server from registry Server *server = get_server(L); // Send - server->notifyPlayer(name, narrow_to_wide(text)); + server->notifyPlayer(name, narrow_to_wide(text), prepend); return 0; } diff --git a/src/server.cpp b/src/server.cpp index dda2165c8..62c190036 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -4606,12 +4606,15 @@ void Server::saveConfig() g_settings->updateConfigFile(m_path_config.c_str()); } -void Server::notifyPlayer(const char *name, const std::wstring msg) +void Server::notifyPlayer(const char *name, const std::wstring msg, const bool prepend = true) { Player *player = m_env->getPlayer(name); if(!player) return; - SendChatMessage(player->peer_id, std::wstring(L"Server: -!- ")+msg); + if (prepend) + SendChatMessage(player->peer_id, std::wstring(L"Server -!- ")+msg); + else + SendChatMessage(player->peer_id, msg); } bool Server::showFormspec(const char *playername, const std::string &formspec, const std::string &formname) diff --git a/src/server.h b/src/server.h index 52606b0cb..b668ecae4 100644 --- a/src/server.h +++ b/src/server.h @@ -456,7 +456,7 @@ public: } // Envlock and conlock should be locked when calling this - void notifyPlayer(const char *name, const std::wstring msg); + void notifyPlayer(const char *name, const std::wstring msg, const bool prepend); void notifyPlayers(const std::wstring msg); void spawnParticle(const char *playername, v3f pos, v3f velocity, v3f acceleration, -- cgit v1.2.3 From 4a9b8aae5e54e4cb6395771868a83bfd0f72c11a Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Thu, 4 Apr 2013 04:28:21 -0400 Subject: Add minetest.get_player_ip() --- doc/lua_api.txt | 1 + src/scriptapi.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) (limited to 'doc') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 38e12882d..531a40b29 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1002,6 +1002,7 @@ minetest.auth_reload() ^ These call the authentication handler minetest.check_player_privs(name, {priv1=true,...}) -> bool, missing_privs ^ A quickhand for checking privileges +minetest.get_player_ip(name) -> IP address string Chat: minetest.chat_send_all(text) diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index 3b0c15f8a..f0fe1950e 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -788,6 +788,31 @@ static int l_get_player_privs(lua_State *L) return 1; } +// get_player_ip() +static int l_get_player_ip(lua_State *L) +{ + const char * name = luaL_checkstring(L, 1); + Player *player = get_env(L)->getPlayer(name); + if(player == NULL) + { + lua_pushnil(L); // no such player + return 1; + } + try + { + Address addr = get_server(L)->getPeerAddress(get_env(L)->getPlayer(name)->peer_id); + std::string ip_str = addr.serializeString(); + lua_pushstring(L, ip_str.c_str()); + return 1; + } + catch(con::PeerNotFoundException) // unlikely + { + dstream << __FUNCTION_NAME << ": peer was not found" << std::endl; + lua_pushnil(L); // error + return 1; + } +} + // get_ban_list() static int l_get_ban_list(lua_State *L) { @@ -1084,6 +1109,7 @@ static const struct luaL_Reg minetest_f [] = { {"chat_send_all", l_chat_send_all}, {"chat_send_player", l_chat_send_player}, {"get_player_privs", l_get_player_privs}, + {"get_player_ip", l_get_player_ip}, {"get_ban_list", l_get_ban_list}, {"get_ban_description", l_get_ban_description}, {"ban_player", l_ban_player}, -- cgit v1.2.3 From 770305e28dc0ed9aea0eefe041477a46d64eee58 Mon Sep 17 00:00:00 2001 From: kwolekr Date: Tue, 23 Apr 2013 18:39:10 -0400 Subject: Add option to use texture alpha channel --- client/shaders/test_shader_3/base.txt | 1 + client/shaders/test_shader_3/opengl_fragment.glsl | 23 ++++++++++ client/shaders/test_shader_3/opengl_vertex.glsl | 51 +++++++++++++++++++++++ doc/lua_api.txt | 1 + src/mapblock_mesh.cpp | 4 +- src/nodedef.cpp | 14 +++---- src/scriptapi_content.cpp | 5 +++ src/tile.h | 10 ++++- 8 files changed, 98 insertions(+), 11 deletions(-) create mode 100644 client/shaders/test_shader_3/base.txt create mode 100644 client/shaders/test_shader_3/opengl_fragment.glsl create mode 100644 client/shaders/test_shader_3/opengl_vertex.glsl (limited to 'doc') diff --git a/client/shaders/test_shader_3/base.txt b/client/shaders/test_shader_3/base.txt new file mode 100644 index 000000000..1c2647118 --- /dev/null +++ b/client/shaders/test_shader_3/base.txt @@ -0,0 +1 @@ +trans_alphach diff --git a/client/shaders/test_shader_3/opengl_fragment.glsl b/client/shaders/test_shader_3/opengl_fragment.glsl new file mode 100644 index 000000000..78abadcaf --- /dev/null +++ b/client/shaders/test_shader_3/opengl_fragment.glsl @@ -0,0 +1,23 @@ + +uniform sampler2D myTexture; +uniform float fogDistance; + +varying vec3 vPosition; + +void main (void) +{ + vec4 col = texture2D(myTexture, vec2(gl_TexCoord[0])); + col *= gl_Color; + col = col * col; // SRGB -> Linear + col *= 1.8; + col.r = 1.0 - exp(1.0 - col.r) / exp(1.0); + col.g = 1.0 - exp(1.0 - col.g) / exp(1.0); + col.b = 1.0 - exp(1.0 - col.b) / exp(1.0); + col = sqrt(col); // Linear -> SRGB + float a = col.a; + if(fogDistance != 0.0){ + float d = max(0.0, min(vPosition.z / fogDistance * 1.5 - 0.6, 1.0)); + a = mix(a, 0.0, d); + } + gl_FragColor = vec4(col.r, col.g, col.b, a); +} diff --git a/client/shaders/test_shader_3/opengl_vertex.glsl b/client/shaders/test_shader_3/opengl_vertex.glsl new file mode 100644 index 000000000..2881bad21 --- /dev/null +++ b/client/shaders/test_shader_3/opengl_vertex.glsl @@ -0,0 +1,51 @@ + +uniform mat4 mWorldViewProj; +uniform mat4 mInvWorld; +uniform mat4 mTransWorld; +uniform float dayNightRatio; + +varying vec3 vPosition; + +void main(void) +{ + gl_Position = mWorldViewProj * gl_Vertex; + + vPosition = (mWorldViewProj * gl_Vertex).xyz; + + vec4 color; + //color = vec4(1.0, 1.0, 1.0, 1.0); + + float day = gl_Color.r; + float night = gl_Color.g; + float light_source = gl_Color.b; + + /*color.r = mix(night, day, dayNightRatio); + color.g = color.r; + color.b = color.r;*/ + + float rg = mix(night, day, dayNightRatio); + rg += light_source * 1.0; // Make light sources brighter + float b = rg; + + // Moonlight is blue + b += (day - night) / 13.0; + rg -= (day - night) / 13.0; + + // Emphase blue a bit in darker places + // See C++ implementation in mapblock_mesh.cpp finalColorBlend() + b += max(0.0, (1.0 - abs(b - 0.13)/0.17) * 0.025); + + // Artificial light is yellow-ish + // See C++ implementation in mapblock_mesh.cpp finalColorBlend() + rg += max(0.0, (1.0 - abs(rg - 0.85)/0.15) * 0.065); + + color.r = rg; + color.g = rg; + color.b = b; + + color.a = gl_Color.a; + + gl_FrontColor = gl_BackColor = color; + + gl_TexCoord[0] = gl_MultiTexCoord0; +} diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 531a40b29..42579fda3 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1649,6 +1649,7 @@ Node definition (register_node) ^ Special textures of node; used rarely (old field name: special_materials) ^ List can be shortened to needed length alpha = 255, + use_texture_alpha = false, -- Use texture's alpha channel post_effect_color = {a=0, r=0, g=0, b=0}, -- If player is inside node paramtype = "none", -- See "Nodes" paramtype2 = "none", -- See "Nodes" diff --git a/src/mapblock_mesh.cpp b/src/mapblock_mesh.cpp index f68a79e41..f8a0b5f06 100644 --- a/src/mapblock_mesh.cpp +++ b/src/mapblock_mesh.cpp @@ -1099,6 +1099,8 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data): getShader("test_shader_1").material; video::E_MATERIAL_TYPE shadermat2 = m_gamedef->getShaderSource()-> getShader("test_shader_2").material; + video::E_MATERIAL_TYPE shadermat3 = m_gamedef->getShaderSource()-> + getShader("test_shader_3").material; for(u32 i = 0; i < collector.prebuffers.size(); i++) { PreMeshBuffer &p = collector.prebuffers[i]; @@ -1174,7 +1176,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data): = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; material.setTexture(0, p.tile.texture.atlas); if(enable_shaders) - p.tile.applyMaterialOptionsWithShaders(material, shadermat1, shadermat2); + p.tile.applyMaterialOptionsWithShaders(material, shadermat1, shadermat2, shadermat3); else p.tile.applyMaterialOptions(material); diff --git a/src/nodedef.cpp b/src/nodedef.cpp index e2b72333f..e09c1910d 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -658,15 +658,11 @@ public: break; } - u8 material_type = 0; - if(is_liquid){ - if(f->alpha == 255) - material_type = TILE_MATERIAL_LIQUID_OPAQUE; - else - material_type = TILE_MATERIAL_LIQUID_TRANSPARENT; - } else{ - material_type = TILE_MATERIAL_BASIC; - } + u8 material_type; + if (is_liquid) + material_type = (f->alpha == 255) ? TILE_MATERIAL_LIQUID_OPAQUE : TILE_MATERIAL_LIQUID_TRANSPARENT; + else + material_type = (f->alpha == 255) ? TILE_MATERIAL_BASIC : TILE_MATERIAL_ALPHA; // Tiles (fill in f->tiles[]) for(u16 j=0; j<6; j++){ diff --git a/src/scriptapi_content.cpp b/src/scriptapi_content.cpp index 3b7ed5179..30fd70349 100644 --- a/src/scriptapi_content.cpp +++ b/src/scriptapi_content.cpp @@ -225,6 +225,11 @@ ContentFeatures read_content_features(lua_State *L, int index) lua_pop(L, 1); f.alpha = getintfield_default(L, index, "alpha", 255); + + bool usealpha = getboolfield_default(L, index, + "use_texture_alpha", false); + if (usealpha) + f.alpha = 0; /* Other stuff */ diff --git a/src/tile.h b/src/tile.h index c5c7f9303..ea5c4be54 100644 --- a/src/tile.h +++ b/src/tile.h @@ -162,6 +162,7 @@ IWritableTextureSource* createTextureSource(IrrlichtDevice *device); enum MaterialType{ TILE_MATERIAL_BASIC, + TILE_MATERIAL_ALPHA, TILE_MATERIAL_LIQUID_TRANSPARENT, TILE_MATERIAL_LIQUID_OPAQUE, }; @@ -222,6 +223,9 @@ struct TileSpec case TILE_MATERIAL_BASIC: material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; break; + case TILE_MATERIAL_ALPHA: + material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; + break; case TILE_MATERIAL_LIQUID_TRANSPARENT: material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA; break; @@ -233,12 +237,16 @@ struct TileSpec } void applyMaterialOptionsWithShaders(video::SMaterial &material, const video::E_MATERIAL_TYPE &basic, - const video::E_MATERIAL_TYPE &liquid) const + const video::E_MATERIAL_TYPE &liquid, + const video::E_MATERIAL_TYPE &alpha) const { switch(material_type){ case TILE_MATERIAL_BASIC: material.MaterialType = basic; break; + case TILE_MATERIAL_ALPHA: + material.MaterialType = alpha; + break; case TILE_MATERIAL_LIQUID_TRANSPARENT: material.MaterialType = liquid; break; -- cgit v1.2.3 From e703c5b81f87550e636ebb1ebb1eb64027a44687 Mon Sep 17 00:00:00 2001 From: Diego Martínez Date: Wed, 24 Apr 2013 07:52:46 -0300 Subject: Added support to disable built-in HUD elements --- doc/lua_api.txt | 3 +++ src/client.cpp | 14 ++++++++++++++ src/client.h | 7 ++++++- src/clientserver.h | 12 ++++++++++-- src/game.cpp | 15 ++++++++++++--- src/hud.cpp | 8 +++++--- src/hud.h | 17 +++++++++++++++-- src/player.cpp | 6 ++++++ src/player.h | 1 + src/scriptapi_object.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/scriptapi_object.h | 3 +++ src/server.cpp | 24 ++++++++++++++++++++++++ src/server.h | 2 ++ 13 files changed, 138 insertions(+), 11 deletions(-) (limited to 'doc') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 42579fda3..b2106b64c 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1433,6 +1433,9 @@ Player-only: (no-op for other objects) - hud_change(id, stat, value): change a value of a previously added HUD element ^ element stat values: position, name, scale, text, number, item, dir - hud_get(id): gets the HUD element definition structure of the specified ID +- hud_builtin_enable(what, flag): enable or disable built-in HUD items + ^ what: "hotbar", "healthbar", "crosshair", "wielditem" + ^ flag: true/false InvRef: Reference to an inventory methods: diff --git a/src/client.cpp b/src/client.cpp index 12ced17fe..941e9e882 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -2114,6 +2114,20 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id) event.hudchange.data = intdata; m_client_event_queue.push_back(event); } + else if(command == TOCLIENT_HUD_BUILTIN_ENABLE) + { + std::string datastring((char *)&data[2], datasize - 2); + std::istringstream is(datastring, std::ios_base::binary); + + u32 id = readU8(is); + bool flag = (readU8(is) ? true : false); + + ClientEvent event; + event.type = CE_HUD_BUILTIN_ENABLE; + event.hudbuiltin.id = (HudBuiltinElement)id; + event.hudbuiltin.flag = flag; + m_client_event_queue.push_back(event); + } else { infostream<<"Client: Ignoring unknown command " diff --git a/src/client.h b/src/client.h index 67ba6c565..33872864e 100644 --- a/src/client.h +++ b/src/client.h @@ -163,7 +163,8 @@ enum ClientEventType CE_DELETE_PARTICLESPAWNER, CE_HUDADD, CE_HUDRM, - CE_HUDCHANGE + CE_HUDCHANGE, + CE_HUD_BUILTIN_ENABLE }; struct ClientEvent @@ -243,6 +244,10 @@ struct ClientEvent std::string *sdata; u32 data; } hudchange; + struct{ + u32 id; + u32 flag; + } hudbuiltin; }; }; diff --git a/src/clientserver.h b/src/clientserver.h index 5e981c202..114b04d13 100644 --- a/src/clientserver.h +++ b/src/clientserver.h @@ -94,6 +94,7 @@ SharedBuffer makePacket_TOCLIENT_TIME_OF_DAY(u16 time, float time_speed); TOCLIENT_HUD_ADD TOCLIENT_HUD_RM TOCLIENT_HUD_CHANGE + TOCLIENT_HUD_BUILTIN_ENABLE */ #define LATEST_PROTOCOL_VERSION 20 @@ -456,13 +457,13 @@ enum ToClientCommand v2f1000 offset */ - TOCLIENT_HUDRM = 0x50, + TOCLIENT_HUDRM = 0x4a, /* u16 command u32 id */ - TOCLIENT_HUDCHANGE = 0x51, + TOCLIENT_HUDCHANGE = 0x4b, /* u16 command u32 id @@ -472,6 +473,13 @@ enum ToClientCommand u8[len] data | u32 data] */ + + TOCLIENT_HUD_BUILTIN_ENABLE = 0x4c, + /* + u16 command + u8 id + u8 flag + */ }; enum ToServerCommand diff --git a/src/game.cpp b/src/game.cpp index cbd9eab4d..e3251bf65 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2186,6 +2186,14 @@ void the_game( delete event.hudchange.v2fdata; delete event.hudchange.sdata; } + else if (event.type == CE_HUD_BUILTIN_ENABLE) { + u32 bit = (u32)event.hudbuiltin.id; + u32 mask = 1 << bit; + if (event.hudbuiltin.flag) + player->hud_flags |= mask; + else + player->hud_flags &= ~mask; + } } } @@ -3070,7 +3078,7 @@ void the_game( /* Wielded tool */ - if(show_hud) + if(show_hud && (player->hud_flags & HUD_DRAW_WIELDITEM)) { // Warning: This clears the Z buffer. camera.drawWieldedTool(); @@ -3094,7 +3102,7 @@ void the_game( /* Draw crosshair */ - if (show_hud) + if (show_hud && (player->hud_flags & HUD_DRAW_CROSSHAIR)) hud.drawCrosshair(); } // timer @@ -3109,7 +3117,8 @@ void the_game( if (show_hud) { hud.drawHotbar(v2s32(displaycenter.X, screensize.Y), - client.getHP(), client.getPlayerItem()); + client.getHP(), client.getPlayerItem(), + player->hud_flags); } /* diff --git a/src/hud.cpp b/src/hud.cpp index 9db92db52..8daadad37 100644 --- a/src/hud.cpp +++ b/src/hud.cpp @@ -277,7 +277,7 @@ void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s } -void Hud::drawHotbar(v2s32 centerlowerpos, s32 halfheartcount, u16 playeritem) { +void Hud::drawHotbar(v2s32 centerlowerpos, s32 halfheartcount, u16 playeritem, u32 flags) { InventoryList *mainlist = inventory->getList("main"); if (mainlist == NULL) { errorstream << "draw_hotbar(): mainlist == NULL" << std::endl; @@ -288,8 +288,10 @@ void Hud::drawHotbar(v2s32 centerlowerpos, s32 halfheartcount, u16 playeritem) { s32 width = hotbar_itemcount * (hotbar_imagesize + padding * 2); v2s32 pos = centerlowerpos - v2s32(width / 2, hotbar_imagesize + padding * 2); - drawItem(pos, hotbar_imagesize, hotbar_itemcount, mainlist, playeritem + 1, 0); - drawStatbar(pos - v2s32(0, 4), HUD_CORNER_LOWER, HUD_DIR_LEFT_RIGHT, + if (flags & HUD_DRAW_HOTBAR) + drawItem(pos, hotbar_imagesize, hotbar_itemcount, mainlist, playeritem + 1, 0); + if (flags & HUD_DRAW_HEALTHBAR) + drawStatbar(pos - v2s32(0, 4), HUD_CORNER_LOWER, HUD_DIR_LEFT_RIGHT, "heart.png", halfheartcount, v2s32(0, 0)); } diff --git a/src/hud.h b/src/hud.h index 104a2f00d..e0d7ccd6f 100644 --- a/src/hud.h +++ b/src/hud.h @@ -31,6 +31,11 @@ with this program; if not, write to the Free Software Foundation, Inc., #define HUD_CORNER_LOWER 1 #define HUD_CORNER_CENTER 2 +#define HUD_DRAW_HOTBAR (1 << 0) +#define HUD_DRAW_HEALTHBAR (1 << 1) +#define HUD_DRAW_CROSSHAIR (1 << 2) +#define HUD_DRAW_WIELDITEM (1 << 3) + class Player; enum HudElementType { @@ -66,6 +71,14 @@ struct HudElement { }; +enum HudBuiltinElement { + HUD_BUILTIN_HOTBAR = 0, + HUD_BUILTIN_HEALTHBAR, + HUD_BUILTIN_CROSSHAIR, + HUD_BUILTIN_WIELDITEM +}; + + inline u32 hud_get_free_id(Player *player) { size_t size = player->hud.size(); for (size_t i = 0; i != size; i++) { @@ -94,7 +107,7 @@ public: IGameDef *gamedef; LocalPlayer *player; Inventory *inventory; - + v2u32 screensize; v2s32 displaycenter; s32 hotbar_imagesize; @@ -112,7 +125,7 @@ public: void drawLuaElements(); void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s32 count, v2s32 offset); - void drawHotbar(v2s32 centerlowerpos, s32 halfheartcount, u16 playeritem); + void drawHotbar(v2s32 centerlowerpos, s32 halfheartcount, u16 playeritem, u32 flags); void resizeHotbar(); void drawCrosshair(); diff --git a/src/player.cpp b/src/player.cpp index 1ca9423b0..e86b64206 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -18,6 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include "player.h" +#include "hud.h" #include "constants.h" #include "gamedef.h" #include "connection.h" // PEER_ID_INEXISTENT @@ -76,6 +77,11 @@ Player::Player(IGameDef *gamedef): physics_override_speed = 1; physics_override_jump = 1; physics_override_gravity = 1; + + hud_flags = HUD_DRAW_HOTBAR + | HUD_DRAW_HEALTHBAR + | HUD_DRAW_CROSSHAIR + | HUD_DRAW_WIELDITEM; } Player::~Player() diff --git a/src/player.h b/src/player.h index d0e50d2c3..4e5b3af97 100644 --- a/src/player.h +++ b/src/player.h @@ -245,6 +245,7 @@ public: u32 keyPressed; std::vector hud; + u32 hud_flags; protected: IGameDef *m_gamedef; diff --git a/src/scriptapi_object.cpp b/src/scriptapi_object.cpp index 6669ad871..e2eec5104 100644 --- a/src/scriptapi_object.cpp +++ b/src/scriptapi_object.cpp @@ -52,6 +52,15 @@ struct EnumString es_HudElementStat[] = {0, NULL}, }; +struct EnumString es_HudBuiltinElement[] = +{ + {HUD_BUILTIN_HOTBAR, "hotbar"}, + {HUD_BUILTIN_HEALTHBAR, "healthbar"}, + {HUD_BUILTIN_CROSSHAIR, "crosshair"}, + {HUD_BUILTIN_WIELDITEM, "wielditem"}, + {0, NULL}, +}; + /* ObjectRef @@ -902,6 +911,33 @@ int ObjectRef::l_hud_get(lua_State *L) return 1; } +// hud_builtin_enable(self, id, flag) +int ObjectRef::l_hud_builtin_enable(lua_State *L) +{ + ObjectRef *ref = checkobject(L, 1); + Player *player = getplayer(ref); + if (player == NULL) + return 0; + + HudBuiltinElement id; + int id_i; + + std::string s(lua_tostring(L, 2)); + + // Return nil if component is not in enum + if (!string_to_enum(es_HudBuiltinElement, id_i, s)) + return 0; + + id = (HudBuiltinElement)id_i; + + bool flag = (bool)lua_toboolean(L, 3); + + bool ok = get_server(L)->hudBuiltinEnable(player, id, flag); + + lua_pushboolean(L, (int)ok); + return 1; +} + ObjectRef::ObjectRef(ServerActiveObject *object): m_object(object) { @@ -1012,6 +1048,7 @@ const luaL_reg ObjectRef::methods[] = { luamethod(ObjectRef, hud_remove), luamethod(ObjectRef, hud_change), luamethod(ObjectRef, hud_get), + luamethod(ObjectRef, hud_builtin_enable), //luamethod(ObjectRef, hud_lock_next_bar), //luamethod(ObjectRef, hud_unlock_bar), {0,0} diff --git a/src/scriptapi_object.h b/src/scriptapi_object.h index fd46f2cf6..81e8cda33 100644 --- a/src/scriptapi_object.h +++ b/src/scriptapi_object.h @@ -202,6 +202,9 @@ private: // hud_get(self, id) static int l_hud_get(lua_State *L); + // hud_builtin_enable(self, id, flag) + static int l_hud_builtin_enable(lua_State *L); + public: ObjectRef(ServerActiveObject *object); diff --git a/src/server.cpp b/src/server.cpp index 62c190036..a93d887e2 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -3675,6 +3675,22 @@ void Server::SendHUDChange(u16 peer_id, u32 id, HudElementStat stat, void *value m_con.Send(peer_id, 0, data, true); } +void Server::SendHUDBuiltinEnable(u16 peer_id, u32 id, bool flag) +{ + std::ostringstream os(std::ios_base::binary); + + // Write command + writeU16(os, TOCLIENT_HUD_BUILTIN_ENABLE); + writeU8(os, id); + writeU8(os, (flag ? 1 : 0)); + + // Make data buffer + std::string s = os.str(); + SharedBuffer data((u8*)s.c_str(), s.size()); + // Send as reliable + m_con.Send(peer_id, 0, data, true); +} + void Server::BroadcastChatMessage(const std::wstring &message) { for(std::map::iterator @@ -4664,6 +4680,14 @@ bool Server::hudChange(Player *player, u32 id, HudElementStat stat, void *data) return true; } +bool Server::hudBuiltinEnable(Player *player, u32 id, bool flag) { + if (!player) + return false; + + SendHUDBuiltinEnable(player->peer_id, id, flag); + return true; +} + void Server::notifyPlayers(const std::wstring msg) { BroadcastChatMessage(msg); diff --git a/src/server.h b/src/server.h index b668ecae4..b951ae53f 100644 --- a/src/server.h +++ b/src/server.h @@ -540,6 +540,7 @@ public: u32 hudAdd(Player *player, HudElement *element); bool hudRemove(Player *player, u32 id); bool hudChange(Player *player, u32 id, HudElementStat stat, void *value); + bool hudBuiltinEnable(Player *player, u32 id, bool flag); private: @@ -583,6 +584,7 @@ private: void SendHUDAdd(u16 peer_id, u32 id, HudElement *form); void SendHUDRemove(u16 peer_id, u32 id); void SendHUDChange(u16 peer_id, u32 id, HudElementStat stat, void *value); + void SendHUDBuiltinEnable(u16 peer_id, u32 id, bool flag); /* Send a node removal/addition event to all clients except ignore_id. Additionally, if far_players!=NULL, players further away than -- cgit v1.2.3 From 625a4c2e662f6b69b73a2a828d1b08d72e53ff73 Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Thu, 25 Apr 2013 02:39:21 +0200 Subject: Add new drawtype GLASSLIKE_FRAMED --- doc/lua_api.txt | 1 + src/content_mapblock.cpp | 129 ++++++++++++++++++++++++++++++++++++++++++++++- src/nodedef.cpp | 4 ++ src/nodedef.h | 2 + src/scriptapi_node.cpp | 1 + 5 files changed, 135 insertions(+), 2 deletions(-) (limited to 'doc') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index b2106b64c..5b1942aef 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -329,6 +329,7 @@ Look for examples in games/minimal or games/minetest_game. - liquid - flowingliquid - glasslike +- glasslike_framed - allfaces - allfaces_optional - torchlike diff --git a/src/content_mapblock.cpp b/src/content_mapblock.cpp index 84d5f067c..155b39ab6 100644 --- a/src/content_mapblock.cpp +++ b/src/content_mapblock.cpp @@ -740,8 +740,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data, continue; // The face at Z+ - video::S3DVertex vertices[4] = - { + video::S3DVertex vertices[4] = { video::S3DVertex(-BS/2,-BS/2,BS/2, 0,0,0, c, ap.x0(), ap.y1()), video::S3DVertex(BS/2,-BS/2,BS/2, 0,0,0, c, @@ -781,6 +780,132 @@ void mapblock_mesh_generate_special(MeshMakeData *data, collector.append(tile, vertices, 4, indices, 6); } break;} + case NDT_GLASSLIKE_FRAMED: + { + static const v3s16 dirs[6] = { + v3s16( 0, 1, 0), + v3s16( 0,-1, 0), + v3s16( 1, 0, 0), + v3s16(-1, 0, 0), + v3s16( 0, 0, 1), + v3s16( 0, 0,-1) + }; + TileSpec tiles[2]; + tiles[0] = getNodeTile(n, p, dirs[0], data); + tiles[1] = getNodeTile(n, p, dirs[1], data); + u16 l = getInteriorLight(n, 1, data); + video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source)); + v3f pos = intToFloat(p, BS); + static const float a=BS/2; + static const float b=.876*(BS/2); + static const aabb3f frame_edges[12] = { + aabb3f( b, b,-a, a, a, a), // y+ + aabb3f(-a, b,-a,-b, a, a), // y+ + aabb3f( b,-a,-a, a,-b, a), // y- + aabb3f(-a,-a,-a,-b,-b, a), // y- + aabb3f( b,-a, b, a, a, a), // x+ + aabb3f( b,-a,-a, a, a,-b), // x+ + aabb3f(-a,-a, b,-b, a, a), // x- + aabb3f(-a,-a,-a,-b, a,-b), // x- + aabb3f(-a, b, b, a, a, a), // z+ + aabb3f(-a,-a, b, a,-b, a), // z+ + aabb3f(-a,-a,-a, a,-b,-b), // z- + aabb3f(-a, b,-a, a, a,-b) // z- + }; + aabb3f glass_faces[6] = { + aabb3f(-a, a,-a, a, a, a), // y+ + aabb3f(-a,-a,-a, a,-a, a), // y- + aabb3f( a,-a,-a, a, a, a), // x+ + aabb3f(-a,-a,-a,-a, a, a), // x- + aabb3f(-a,-a, a, a, a, a), // z+ + aabb3f(-a,-a,-a, a, a,-a) // z- + }; + + int visible_faces[6] = {0,0,0,0,0,0}; + int nb[18] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; + u8 i; + content_t current = n.getContent(); + content_t content; + MapNode n2; + v3s16 n2p; + for(i=0; i<18; i++) + { + n2p = blockpos_nodes + p + g_26dirs[i]; + n2 = data->m_vmanip.getNodeNoEx(n2p); + content_t n2c = n2.getContent(); + //TODO: remove CONTENT_IGNORE check when getNodeNoEx is fixed + if (n2c == current || n2c == CONTENT_IGNORE) + nb[i]=1; + } + for(i=0; i<6; i++) + { + n2p = blockpos_nodes + p + dirs[i]; + n2 = data->m_vmanip.getNodeNoEx(n2p); + content = n2.getContent(); + const ContentFeatures &f2 = nodedef->get(content); + if (content == CONTENT_AIR || f2.isLiquid()) + visible_faces[i]=1; + } + static const u8 nb_triplet[12*3] = { + 1,2, 7, 1,5, 6, 4,2,15, 4,5,14, + 2,0,11, 2,3,13, 5,0,10, 5,3,12, + 0,1, 8, 0,4,16, 3,4,17, 3,1, 9 + }; + + f32 tx1,ty1,tz1,tx2,ty2,tz2; + aabb3f box; + for(i=0; i<12; i++) + { + int edge_invisible; + if (nb[nb_triplet[i*3+2]]==1) + edge_invisible=nb[nb_triplet[i*3]] & nb[nb_triplet[i*3+1]]; + else + edge_invisible=nb[nb_triplet[i*3]] ^ nb[nb_triplet[i*3+1]]; + if (edge_invisible) + continue; + box=frame_edges[i]; + box.MinEdge += pos; + box.MaxEdge += pos; + tx1 = (box.MinEdge.X/BS)+0.5; + ty1 = (box.MinEdge.Y/BS)+0.5; + tz1 = (box.MinEdge.Z/BS)+0.5; + tx2 = (box.MaxEdge.X/BS)+0.5; + ty2 = (box.MaxEdge.Y/BS)+0.5; + tz2 = (box.MaxEdge.Z/BS)+0.5; + f32 txc1[24] = { + tx1, 1-tz2, tx2, 1-tz1, + tx1, tz1, tx2, tz2, + tz1, 1-ty2, tz2, 1-ty1, + 1-tz2, 1-ty2, 1-tz1, 1-ty1, + 1-tx2, 1-ty2, 1-tx1, 1-ty1, + tx1, 1-ty2, tx2, 1-ty1, + }; + makeCuboid(&collector, box, &tiles[0], 1, c, txc1); + } + for(i=0; i<6; i++) + { + if (visible_faces[i]==0) + continue; + box=glass_faces[i]; + box.MinEdge += pos; + box.MaxEdge += pos; + tx1 = (box.MinEdge.X/BS)+0.5; + ty1 = (box.MinEdge.Y/BS)+0.5; + tz1 = (box.MinEdge.Z/BS)+0.5; + tx2 = (box.MaxEdge.X/BS)+0.5; + ty2 = (box.MaxEdge.Y/BS)+0.5; + tz2 = (box.MaxEdge.Z/BS)+0.5; + f32 txc2[24] = { + tx1, 1-tz2, tx2, 1-tz1, + tx1, tz1, tx2, tz2, + tz1, 1-ty2, tz2, 1-ty1, + 1-tz2, 1-ty2, 1-tz1, 1-ty1, + 1-tx2, 1-ty2, 1-tx1, 1-ty1, + tx1, 1-ty2, tx2, 1-ty1, + }; + makeCuboid(&collector, box, &tiles[1], 1, c, txc2); + } + break;} case NDT_ALLFACES: { TileSpec tile_leaves = getNodeTile(n, p, diff --git a/src/nodedef.cpp b/src/nodedef.cpp index e09c1910d..ba3e42e98 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -628,6 +628,10 @@ public: f->solidness = 0; f->visual_solidness = 1; break; + case NDT_GLASSLIKE_FRAMED: + f->solidness = 0; + f->visual_solidness = 1; + break; case NDT_ALLFACES: f->solidness = 0; f->visual_solidness = 1; diff --git a/src/nodedef.h b/src/nodedef.h index d846489ae..8be18f9cb 100644 --- a/src/nodedef.h +++ b/src/nodedef.h @@ -133,6 +133,8 @@ enum NodeDrawType NDT_LIQUID, // Do not draw face towards same kind of flowing/source liquid NDT_FLOWINGLIQUID, // A very special kind of thing NDT_GLASSLIKE, // Glass-like, don't draw faces towards other glass + NDT_GLASSLIKE_FRAMED, // Glass-like, draw connected frames and all all visible faces + // uses 2 textures, one for frames, second for faces NDT_ALLFACES, // Leaves-like, draw all faces no matter what NDT_ALLFACES_OPTIONAL, // Fancy -> allfaces, fast -> normal NDT_TORCHLIKE, diff --git a/src/scriptapi_node.cpp b/src/scriptapi_node.cpp index 5ffcaeb9d..2fea50fa1 100644 --- a/src/scriptapi_node.cpp +++ b/src/scriptapi_node.cpp @@ -34,6 +34,7 @@ struct EnumString es_DrawType[] = {NDT_LIQUID, "liquid"}, {NDT_FLOWINGLIQUID, "flowingliquid"}, {NDT_GLASSLIKE, "glasslike"}, + {NDT_GLASSLIKE_FRAMED, "glasslike_framed"}, {NDT_ALLFACES, "allfaces"}, {NDT_ALLFACES_OPTIONAL, "allfaces_optional"}, {NDT_TORCHLIKE, "torchlike"}, -- cgit v1.2.3 From d3f0ce62240b7598eded13153eacb410bf2420a1 Mon Sep 17 00:00:00 2001 From: kwolekr Date: Thu, 25 Apr 2013 19:27:22 -0400 Subject: Generalize hud_builtin_enable into hud_set_flags --- doc/lua_api.txt | 7 ++++--- src/client.cpp | 20 ++++++++++---------- src/client.h | 7 +------ src/clientserver.h | 6 +++--- src/game.cpp | 15 +++------------ src/hud.cpp | 16 +++++++++------- src/hud.h | 21 +++++++-------------- src/player.cpp | 36 +++++++++++++++++------------------- src/scriptapi_object.cpp | 41 +++++++++++++++++++---------------------- src/scriptapi_object.h | 4 ++-- src/server.cpp | 14 +++++++------- src/server.h | 5 +++-- 12 files changed, 85 insertions(+), 107 deletions(-) (limited to 'doc') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 5b1942aef..07fb1ccd6 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1434,9 +1434,10 @@ Player-only: (no-op for other objects) - hud_change(id, stat, value): change a value of a previously added HUD element ^ element stat values: position, name, scale, text, number, item, dir - hud_get(id): gets the HUD element definition structure of the specified ID -- hud_builtin_enable(what, flag): enable or disable built-in HUD items - ^ what: "hotbar", "healthbar", "crosshair", "wielditem" - ^ flag: true/false +- hud_set_flags(flags): sets specified HUD flags to true/false + ^ flags: (is visible) hotbar, healthbar, crosshair, wielditem + ^ pass a table containing a true/false value of each flag to be set or unset + ^ if a flag is nil, the flag is not modified InvRef: Reference to an inventory methods: diff --git a/src/client.cpp b/src/client.cpp index 941e9e882..56505c66c 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -2097,8 +2097,8 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id) u32 id = readU32(is); u8 stat = (HudElementStat)readU8(is); - if (stat == HUD_STAT_POS || stat == HUD_STAT_SCALE - || stat == HUD_STAT_ALIGN || stat == HUD_STAT_OFFSET) + if (stat == HUD_STAT_POS || stat == HUD_STAT_SCALE || + stat == HUD_STAT_ALIGN || stat == HUD_STAT_OFFSET) v2fdata = readV2F1000(is); else if (stat == HUD_STAT_NAME || stat == HUD_STAT_TEXT) sdata = deSerializeString(is); @@ -2114,19 +2114,19 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id) event.hudchange.data = intdata; m_client_event_queue.push_back(event); } - else if(command == TOCLIENT_HUD_BUILTIN_ENABLE) + else if(command == TOCLIENT_HUD_SET_FLAGS) { std::string datastring((char *)&data[2], datasize - 2); std::istringstream is(datastring, std::ios_base::binary); - u32 id = readU8(is); - bool flag = (readU8(is) ? true : false); + Player *player = m_env.getLocalPlayer(); + assert(player != NULL); - ClientEvent event; - event.type = CE_HUD_BUILTIN_ENABLE; - event.hudbuiltin.id = (HudBuiltinElement)id; - event.hudbuiltin.flag = flag; - m_client_event_queue.push_back(event); + u32 flags = readU32(is); + u32 mask = readU32(is); + + player->hud_flags &= ~mask; + player->hud_flags |= flags; } else { diff --git a/src/client.h b/src/client.h index 33872864e..67ba6c565 100644 --- a/src/client.h +++ b/src/client.h @@ -163,8 +163,7 @@ enum ClientEventType CE_DELETE_PARTICLESPAWNER, CE_HUDADD, CE_HUDRM, - CE_HUDCHANGE, - CE_HUD_BUILTIN_ENABLE + CE_HUDCHANGE }; struct ClientEvent @@ -244,10 +243,6 @@ struct ClientEvent std::string *sdata; u32 data; } hudchange; - struct{ - u32 id; - u32 flag; - } hudbuiltin; }; }; diff --git a/src/clientserver.h b/src/clientserver.h index 114b04d13..cfa87ada7 100644 --- a/src/clientserver.h +++ b/src/clientserver.h @@ -474,11 +474,11 @@ enum ToClientCommand u32 data] */ - TOCLIENT_HUD_BUILTIN_ENABLE = 0x4c, + TOCLIENT_HUD_SET_FLAGS = 0x4c, /* u16 command - u8 id - u8 flag + u32 flags + u32 mask */ }; diff --git a/src/game.cpp b/src/game.cpp index e3251bf65..189003e4c 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2186,14 +2186,6 @@ void the_game( delete event.hudchange.v2fdata; delete event.hudchange.sdata; } - else if (event.type == CE_HUD_BUILTIN_ENABLE) { - u32 bit = (u32)event.hudbuiltin.id; - u32 mask = 1 << bit; - if (event.hudbuiltin.flag) - player->hud_flags |= mask; - else - player->hud_flags &= ~mask; - } } } @@ -3078,7 +3070,7 @@ void the_game( /* Wielded tool */ - if(show_hud && (player->hud_flags & HUD_DRAW_WIELDITEM)) + if(show_hud && (player->hud_flags & HUD_FLAG_WIELDITEM_VISIBLE)) { // Warning: This clears the Z buffer. camera.drawWieldedTool(); @@ -3102,7 +3094,7 @@ void the_game( /* Draw crosshair */ - if (show_hud && (player->hud_flags & HUD_DRAW_CROSSHAIR)) + if (show_hud) hud.drawCrosshair(); } // timer @@ -3117,8 +3109,7 @@ void the_game( if (show_hud) { hud.drawHotbar(v2s32(displaycenter.X, screensize.Y), - client.getHP(), client.getPlayerItem(), - player->hud_flags); + client.getHP(), client.getPlayerItem()); } /* diff --git a/src/hud.cpp b/src/hud.cpp index 8daadad37..cf53354b2 100644 --- a/src/hud.cpp +++ b/src/hud.cpp @@ -277,7 +277,7 @@ void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s } -void Hud::drawHotbar(v2s32 centerlowerpos, s32 halfheartcount, u16 playeritem, u32 flags) { +void Hud::drawHotbar(v2s32 centerlowerpos, s32 halfheartcount, u16 playeritem) { InventoryList *mainlist = inventory->getList("main"); if (mainlist == NULL) { errorstream << "draw_hotbar(): mainlist == NULL" << std::endl; @@ -288,19 +288,21 @@ void Hud::drawHotbar(v2s32 centerlowerpos, s32 halfheartcount, u16 playeritem, u s32 width = hotbar_itemcount * (hotbar_imagesize + padding * 2); v2s32 pos = centerlowerpos - v2s32(width / 2, hotbar_imagesize + padding * 2); - if (flags & HUD_DRAW_HOTBAR) + if (player->hud_flags & HUD_FLAG_HOTBAR_VISIBLE) drawItem(pos, hotbar_imagesize, hotbar_itemcount, mainlist, playeritem + 1, 0); - if (flags & HUD_DRAW_HEALTHBAR) + if (player->hud_flags & HUD_FLAG_HEALTHBAR_VISIBLE) drawStatbar(pos - v2s32(0, 4), HUD_CORNER_LOWER, HUD_DIR_LEFT_RIGHT, "heart.png", halfheartcount, v2s32(0, 0)); } void Hud::drawCrosshair() { - driver->draw2DLine(displaycenter - v2s32(10, 0), - displaycenter + v2s32(10, 0), crosshair_argb); - driver->draw2DLine(displaycenter - v2s32(0, 10), - displaycenter + v2s32(0, 10), crosshair_argb); + if (player->hud_flags & HUD_FLAG_CROSSHAIR_VISIBLE) { + driver->draw2DLine(displaycenter - v2s32(10, 0), + displaycenter + v2s32(10, 0), crosshair_argb); + driver->draw2DLine(displaycenter - v2s32(0, 10), + displaycenter + v2s32(0, 10), crosshair_argb); + } } diff --git a/src/hud.h b/src/hud.h index e0d7ccd6f..405e91176 100644 --- a/src/hud.h +++ b/src/hud.h @@ -31,10 +31,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #define HUD_CORNER_LOWER 1 #define HUD_CORNER_CENTER 2 -#define HUD_DRAW_HOTBAR (1 << 0) -#define HUD_DRAW_HEALTHBAR (1 << 1) -#define HUD_DRAW_CROSSHAIR (1 << 2) -#define HUD_DRAW_WIELDITEM (1 << 3) +#define HUD_FLAG_HOTBAR_VISIBLE (1 << 0) +#define HUD_FLAG_HEALTHBAR_VISIBLE (1 << 1) +#define HUD_FLAG_CROSSHAIR_VISIBLE (1 << 2) +#define HUD_FLAG_WIELDITEM_VISIBLE (1 << 3) class Player; @@ -71,14 +71,6 @@ struct HudElement { }; -enum HudBuiltinElement { - HUD_BUILTIN_HOTBAR = 0, - HUD_BUILTIN_HEALTHBAR, - HUD_BUILTIN_CROSSHAIR, - HUD_BUILTIN_WIELDITEM -}; - - inline u32 hud_get_free_id(Player *player) { size_t size = player->hud.size(); for (size_t i = 0; i != size; i++) { @@ -123,9 +115,10 @@ public: void drawItem(v2s32 upperleftpos, s32 imgsize, s32 itemcount, InventoryList *mainlist, u16 selectitem, u16 direction); void drawLuaElements(); - void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s32 count, v2s32 offset); + void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, + std::string texture, s32 count, v2s32 offset); - void drawHotbar(v2s32 centerlowerpos, s32 halfheartcount, u16 playeritem, u32 flags); + void drawHotbar(v2s32 centerlowerpos, s32 halfheartcount, u16 playeritem); void resizeHotbar(); void drawCrosshair(); diff --git a/src/player.cpp b/src/player.cpp index d3e16810f..34f0fda08 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -54,35 +54,33 @@ Player::Player(IGameDef *gamedef): inventory.addList("craftresult", 1); // Can be redefined via Lua - inventory_formspec = "size[8,7.5]" + inventory_formspec = "size[8,7.5]" //"image[1,0.6;1,2;player.png]" "list[current_player;main;0,3.5;8,4;]" "list[current_player;craft;3,0;3,3;]" "list[current_player;craftpreview;7,1;1,1;]"; // Initialize movement settings at default values, so movement can work if the server fails to send them - movement_acceleration_default = 3 * BS; - movement_acceleration_air = 2 * BS; - movement_acceleration_fast = 10 * BS; - movement_speed_walk = 4 * BS; - movement_speed_crouch = 1.35 * BS; - movement_speed_fast = 20 * BS; - movement_speed_climb = 2 * BS; - movement_speed_jump = 6.5 * BS; - movement_liquid_fluidity = 1 * BS; - movement_liquid_fluidity_smooth = 0.5 * BS; - movement_liquid_sink = 10 * BS; - movement_gravity = 9.81 * BS; + movement_acceleration_default = 3 * BS; + movement_acceleration_air = 2 * BS; + movement_acceleration_fast = 10 * BS; + movement_speed_walk = 4 * BS; + movement_speed_crouch = 1.35 * BS; + movement_speed_fast = 20 * BS; + movement_speed_climb = 2 * BS; + movement_speed_jump = 6.5 * BS; + movement_liquid_fluidity = 1 * BS; + movement_liquid_fluidity_smooth = 0.5 * BS; + movement_liquid_sink = 10 * BS; + movement_gravity = 9.81 * BS; // Movement overrides are multipliers and must be 1 by default - physics_override_speed = 1; - physics_override_jump = 1; + physics_override_speed = 1; + physics_override_jump = 1; physics_override_gravity = 1; - hud_flags = HUD_DRAW_HOTBAR - | HUD_DRAW_HEALTHBAR - | HUD_DRAW_CROSSHAIR - | HUD_DRAW_WIELDITEM; + hud_flags = HUD_FLAG_HOTBAR_VISIBLE | HUD_FLAG_HEALTHBAR_VISIBLE | + HUD_FLAG_CROSSHAIR_VISIBLE | HUD_FLAG_WIELDITEM_VISIBLE; } Player::~Player() diff --git a/src/scriptapi_object.cpp b/src/scriptapi_object.cpp index e2eec5104..4dfdeb8c8 100644 --- a/src/scriptapi_object.cpp +++ b/src/scriptapi_object.cpp @@ -54,10 +54,10 @@ struct EnumString es_HudElementStat[] = struct EnumString es_HudBuiltinElement[] = { - {HUD_BUILTIN_HOTBAR, "hotbar"}, - {HUD_BUILTIN_HEALTHBAR, "healthbar"}, - {HUD_BUILTIN_CROSSHAIR, "crosshair"}, - {HUD_BUILTIN_WIELDITEM, "wielditem"}, + {HUD_FLAG_HOTBAR_VISIBLE, "hotbar"}, + {HUD_FLAG_HEALTHBAR_VISIBLE, "healthbar"}, + {HUD_FLAG_CROSSHAIR_VISIBLE, "crosshair"}, + {HUD_FLAG_WIELDITEM_VISIBLE, "wielditem"}, {0, NULL}, }; @@ -911,30 +911,29 @@ int ObjectRef::l_hud_get(lua_State *L) return 1; } -// hud_builtin_enable(self, id, flag) -int ObjectRef::l_hud_builtin_enable(lua_State *L) +// hud_set_flags(self, flags) +int ObjectRef::l_hud_set_flags(lua_State *L) { ObjectRef *ref = checkobject(L, 1); Player *player = getplayer(ref); if (player == NULL) return 0; - HudBuiltinElement id; - int id_i; + u32 flags = 0; + u32 mask = 0; + bool flag; - std::string s(lua_tostring(L, 2)); - - // Return nil if component is not in enum - if (!string_to_enum(es_HudBuiltinElement, id_i, s)) + const EnumString *esp = es_HudBuiltinElement; + for (int i = 0; esp[i].str; i++) { + if (getboolfield(L, 2, esp[i].str, flag)) { + flags |= esp[i].num * flag; + mask |= esp[i].num; + } + } + if (!get_server(L)->hudSetFlags(player, flags, mask)) return 0; - - id = (HudBuiltinElement)id_i; - bool flag = (bool)lua_toboolean(L, 3); - - bool ok = get_server(L)->hudBuiltinEnable(player, id, flag); - - lua_pushboolean(L, (int)ok); + lua_pushboolean(L, true); return 1; } @@ -1048,9 +1047,7 @@ const luaL_reg ObjectRef::methods[] = { luamethod(ObjectRef, hud_remove), luamethod(ObjectRef, hud_change), luamethod(ObjectRef, hud_get), - luamethod(ObjectRef, hud_builtin_enable), - //luamethod(ObjectRef, hud_lock_next_bar), - //luamethod(ObjectRef, hud_unlock_bar), + luamethod(ObjectRef, hud_set_flags), {0,0} }; diff --git a/src/scriptapi_object.h b/src/scriptapi_object.h index 81e8cda33..82535ee94 100644 --- a/src/scriptapi_object.h +++ b/src/scriptapi_object.h @@ -202,8 +202,8 @@ private: // hud_get(self, id) static int l_hud_get(lua_State *L); - // hud_builtin_enable(self, id, flag) - static int l_hud_builtin_enable(lua_State *L); + // hud_set_flags(self, flags) + static int l_hud_set_flags(lua_State *L); public: ObjectRef(ServerActiveObject *object); diff --git a/src/server.cpp b/src/server.cpp index a93d887e2..d5e505190 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -3675,18 +3675,18 @@ void Server::SendHUDChange(u16 peer_id, u32 id, HudElementStat stat, void *value m_con.Send(peer_id, 0, data, true); } -void Server::SendHUDBuiltinEnable(u16 peer_id, u32 id, bool flag) +void Server::SendHUDSetFlags(u16 peer_id, u32 flags, u32 mask) { std::ostringstream os(std::ios_base::binary); // Write command - writeU16(os, TOCLIENT_HUD_BUILTIN_ENABLE); - writeU8(os, id); - writeU8(os, (flag ? 1 : 0)); + writeU16(os, TOCLIENT_HUD_SET_FLAGS); + writeU32(os, flags); + writeU32(os, mask); // Make data buffer std::string s = os.str(); - SharedBuffer data((u8*)s.c_str(), s.size()); + SharedBuffer data((u8 *)s.c_str(), s.size()); // Send as reliable m_con.Send(peer_id, 0, data, true); } @@ -4680,11 +4680,11 @@ bool Server::hudChange(Player *player, u32 id, HudElementStat stat, void *data) return true; } -bool Server::hudBuiltinEnable(Player *player, u32 id, bool flag) { +bool Server::hudSetFlags(Player *player, u32 flags, u32 mask) { if (!player) return false; - SendHUDBuiltinEnable(player->peer_id, id, flag); + SendHUDSetFlags(player->peer_id, flags, mask); return true; } diff --git a/src/server.h b/src/server.h index b951ae53f..dcd007d23 100644 --- a/src/server.h +++ b/src/server.h @@ -540,7 +540,7 @@ public: u32 hudAdd(Player *player, HudElement *element); bool hudRemove(Player *player, u32 id); bool hudChange(Player *player, u32 id, HudElementStat stat, void *value); - bool hudBuiltinEnable(Player *player, u32 id, bool flag); + bool hudSetFlags(Player *player, u32 flags, u32 mask); private: @@ -584,7 +584,8 @@ private: void SendHUDAdd(u16 peer_id, u32 id, HudElement *form); void SendHUDRemove(u16 peer_id, u32 id); void SendHUDChange(u16 peer_id, u32 id, HudElementStat stat, void *value); - void SendHUDBuiltinEnable(u16 peer_id, u32 id, bool flag); + void SendHUDSetFlags(u16 peer_id, u32 flags, u32 mask); + /* Send a node removal/addition event to all clients except ignore_id. Additionally, if far_players!=NULL, players further away than -- cgit v1.2.3 From a4183994a446a065e3151745b4167270ebae6194 Mon Sep 17 00:00:00 2001 From: Sfan5 Date: Wed, 1 May 2013 12:31:21 +0200 Subject: Add a Way of checking for specific Feature with Lua Adds minetest.get_feature() and minetest.has_feature() --- builtin/builtin.lua | 1 + builtin/features.lua | 28 ++++++++++++++++++++++++++++ doc/lua_api.txt | 5 +++++ 3 files changed, 34 insertions(+) create mode 100644 builtin/features.lua (limited to 'doc') diff --git a/builtin/builtin.lua b/builtin/builtin.lua index bf33cbe6b..f10c6c7cf 100644 --- a/builtin/builtin.lua +++ b/builtin/builtin.lua @@ -24,4 +24,5 @@ dofile(minetest.get_modpath("__builtin").."/chatcommands.lua") dofile(minetest.get_modpath("__builtin").."/static_spawn.lua") dofile(minetest.get_modpath("__builtin").."/detached_inventory.lua") dofile(minetest.get_modpath("__builtin").."/falling.lua") +dofile(minetest.get_modpath("__builtin").."/features.lua") diff --git a/builtin/features.lua b/builtin/features.lua new file mode 100644 index 000000000..0eef2519d --- /dev/null +++ b/builtin/features.lua @@ -0,0 +1,28 @@ +-- Minetest: builtin/features.lua + +minetest.features = { + "glasslike_framed" = true, + "nodebox_as_selectionbox" = true, + "chat_send_player_param3" = true, + "get_all_craft_recipes_works" = true, + "use_texture_alpha" = true, +} + +function minetest.has_feature(arg) + if type(arg) == "table" then + missing_features = {} + result = true + for ft, _ in pairs(arg) do + if not minetest.features[ftr] then + missing_features[ftr] = true + result = false + end + end + return result, missing_features + elseif type(arg) == "string" then + if not minetest.features[arg] then + return false, {[arg]=true} + end + return true, {} + end +end diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 07fb1ccd6..597f98c2c 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -912,6 +912,11 @@ minetest.get_modnames() -> list of installed mods minetest.get_worldpath() -> eg. "/home/user/.minetest/world" ^ Useful for storing custom data minetest.is_singleplayer() +minetest.features +^ table containing API feature flags: {foo=true, bar=true} +minetest.has_feature(arg) -> bool, missing_features +^ arg: string or table in format {foo=true, bar=true} +^ missing_features: {foo=true, bar=true} minetest.debug(line) ^ Always printed to stderr and logfile (print() is redirected here) -- cgit v1.2.3