From 7c37b1891adcddc0e7d11e5faafddaa554443318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Mart=C3=ADnez?= Date: Mon, 22 Apr 2013 06:53:55 -0300 Subject: [PATCH 01/26] Added support for alignment in HUD items --- doc/lua_api.txt | 7 +++++++ src/client.cpp | 2 ++ src/client.h | 1 + src/clientserver.h | 1 + src/game.cpp | 6 ++++++ src/hud.cpp | 9 ++++++++- src/hud.h | 4 +++- src/scriptapi_object.cpp | 8 ++++++++ src/server.cpp | 2 ++ 9 files changed, 38 insertions(+), 2 deletions(-) diff --git a/doc/lua_api.txt b/doc/lua_api.txt index aa450387..77444877 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" } diff --git a/src/client.cpp b/src/client.cpp index 03a71059..8db6f2f4 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -2054,6 +2054,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id) u32 number = readU32(is); u32 item = readU32(is); u32 dir = readU32(is); + v2f align = readV2F1000(is); ClientEvent event; event.type = CE_HUDADD; @@ -2066,6 +2067,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id) event.hudadd.number = number; event.hudadd.item = item; event.hudadd.dir = dir; + event.hudadd.align = new v2f(align); m_client_event_queue.push_back(event); } else if(command == TOCLIENT_HUDRM) diff --git a/src/client.h b/src/client.h index f5958868..ff42f3e0 100644 --- a/src/client.h +++ b/src/client.h @@ -230,6 +230,7 @@ struct ClientEvent u32 number; u32 item; u32 dir; + v2f *align; } hudadd; struct{ u32 id; diff --git a/src/clientserver.h b/src/clientserver.h index 6f7bb440..0418d10b 100644 --- a/src/clientserver.h +++ b/src/clientserver.h @@ -452,6 +452,7 @@ enum ToClientCommand u32 number u32 item u32 dir + v2f1000 align */ TOCLIENT_HUDRM = 0x50, diff --git a/src/game.cpp b/src/game.cpp index a2d94ac0..2c73dfa6 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2106,6 +2106,7 @@ void the_game( delete event.hudadd.name; delete event.hudadd.scale; delete event.hudadd.text; + delete event.hudadd.align; continue; } @@ -2118,6 +2119,7 @@ void the_game( e->number = event.hudadd.number; e->item = event.hudadd.item; e->dir = event.hudadd.dir; + e->align = *event.hudadd.align; if (id == nhudelem) player->hud.push_back(e); @@ -2128,6 +2130,7 @@ void the_game( delete event.hudadd.name; delete event.hudadd.scale; delete event.hudadd.text; + delete event.hudadd.align; } else if (event.type == CE_HUDRM) { @@ -2169,6 +2172,9 @@ void the_game( case HUD_STAT_DIR: e->dir = event.hudchange.data; break; + case HUD_STAT_ALIGN: + e->align = *event.hudchange.v2fdata; + break; } delete event.hudchange.v2fdata; diff --git a/src/hud.cpp b/src/hud.cpp index 77cf2317..0f3ab40d 100644 --- a/src/hud.cpp +++ b/src/hud.cpp @@ -186,6 +186,9 @@ void Hud::drawLuaElements() { core::rect rect(0, 0, imgsize.Width * e->scale.X, imgsize.Height * e->scale.X); rect += pos; + 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; driver->draw2DImage(texture, rect, core::rect(core::position2d(0,0), imgsize), NULL, colors, true); @@ -195,7 +198,11 @@ void Hud::drawLuaElements() { (e->number >> 8) & 0xFF, (e->number >> 0) & 0xFF); core::rect size(0, 0, e->scale.X, text_height * e->scale.Y); - font->draw(narrow_to_wide(e->text).c_str(), size + pos, color); + std::wstring text = narrow_to_wide(e->text); + 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); break; } case HUD_ELEM_STATBAR: drawStatbar(pos, HUD_CORNER_UPPER, e->dir, e->text, e->number); diff --git a/src/hud.h b/src/hud.h index 274a669c..7a1dff3d 100644 --- a/src/hud.h +++ b/src/hud.h @@ -47,7 +47,8 @@ enum HudElementStat { HUD_STAT_TEXT, HUD_STAT_NUMBER, HUD_STAT_ITEM, - HUD_STAT_DIR + HUD_STAT_DIR, + HUD_STAT_ALIGN }; struct HudElement { @@ -59,6 +60,7 @@ struct HudElement { u32 number; u32 item; u32 dir; + v2f align; }; diff --git a/src/scriptapi_object.cpp b/src/scriptapi_object.cpp index 9152c9eb..c07f6565 100644 --- a/src/scriptapi_object.cpp +++ b/src/scriptapi_object.cpp @@ -47,6 +47,7 @@ struct EnumString es_HudElementStat[] = {HUD_STAT_NUMBER, "number"}, {HUD_STAT_ITEM, "item"}, {HUD_STAT_DIR, "direction"}, + {HUD_STAT_ALIGN, "alignment"}, {0, NULL}, }; @@ -751,6 +752,10 @@ int ObjectRef::l_hud_add(lua_State *L) elem->item = getintfield_default(L, 2, "item", 0); elem->dir = getintfield_default(L, 2, "direction", 0); + lua_getfield(L, 2, "alignment"); + elem->align = 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; @@ -833,6 +838,9 @@ int ObjectRef::l_hud_change(lua_State *L) case HUD_STAT_DIR: e->dir = lua_tonumber(L, 4); value = &e->dir; + case HUD_STAT_ALIGN: + e->align = read_v2f(L, 4); + value = &e->align; } get_server(L)->hudChange(player, id, stat, value); diff --git a/src/server.cpp b/src/server.cpp index 7fad623c..b8f3e4da 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -3616,6 +3616,7 @@ void Server::SendHUDAdd(u16 peer_id, u32 id, HudElement *form) writeU32(os, form->number); writeU32(os, form->item); writeU32(os, form->dir); + writeV2F1000(os, form->align); // Make data buffer std::string s = os.str(); @@ -3650,6 +3651,7 @@ void Server::SendHUDChange(u16 peer_id, u32 id, HudElementStat stat, void *value switch (stat) { case HUD_STAT_POS: case HUD_STAT_SCALE: + case HUD_STAT_ALIGN: writeV2F1000(os, *(v2f *)value); break; case HUD_STAT_NAME: From 9894167bbf516c40bf2b8577179ff8f13b8b54e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Mart=C3=ADnez?= Date: Mon, 22 Apr 2013 20:47:59 -0300 Subject: [PATCH 02/26] 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(-) diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 77444877..76f687f8 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 8db6f2f4..15fb6932 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 ff42f3e0..67ba6c56 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 0418d10b..5e981c20 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 2c73dfa6..cbd9eab4 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 0f3ab40d..9db92db5 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 7a1dff3d..104a2f00 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 c07f6565..6669ad87 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 b8f3e4da..dda2165c 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: From 3d4d0cb5749a68436cccd08b7a135f9bb7527038 Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Fri, 29 Mar 2013 23:28:13 -0400 Subject: [PATCH 03/26] 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(-) diff --git a/builtin/chatcommands.lua b/builtin/chatcommands.lua index 9f14749f..f548fb01 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 76f687f8..38e12882 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 8d472e6b..3b0c15f8 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 dda2165c..62c19003 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 52606b0c..b668ecae 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, From 4a9b8aae5e54e4cb6395771868a83bfd0f72c11a Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Thu, 4 Apr 2013 04:28:21 -0400 Subject: [PATCH 04/26] Add minetest.get_player_ip() --- doc/lua_api.txt | 1 + src/scriptapi.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 38e12882..531a40b2 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 3b0c15f8..f0fe1950 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}, From c03c296dc7afe0e4ded65484221072ad6715e2be Mon Sep 17 00:00:00 2001 From: PilzAdam Date: Tue, 23 Apr 2013 19:02:41 +0200 Subject: [PATCH 05/26] Grow dirt_with_snow instead of dirt_with_grass if snow is above it --- src/content_abm.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/content_abm.cpp b/src/content_abm.cpp index ccd9ca19..e20201dc 100644 --- a/src/content_abm.cpp +++ b/src/content_abm.cpp @@ -51,11 +51,15 @@ public: ServerMap *map = &env->getServerMap(); MapNode n_top = map->getNodeNoEx(p+v3s16(0,1,0)); + content_t c_snow = ndef->getId("snow"); if(ndef->get(n_top).light_propagates && !ndef->get(n_top).isLiquid() && n_top.getLightBlend(env->getDayNightRatio(), ndef) >= 13) { - n.setContent(ndef->getId("mapgen_dirt_with_grass")); + if(c_snow != CONTENT_IGNORE && n_top.getContent() == c_snow) + n.setContent(ndef->getId("dirt_with_snow")); + else + n.setContent(ndef->getId("mapgen_dirt_with_grass")); map->addNodeWithEvent(p, n); } } From 36747794ab981e5d1cc085075979ef981e783b55 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Tue, 23 Apr 2013 23:19:36 +0300 Subject: [PATCH 06/26] Disable fall bobbing by default; enable using fall_bobbing_amount = 1.0 --- minetest.conf.example | 2 ++ src/camera.cpp | 2 ++ src/defaultsettings.cpp | 1 + 3 files changed, 5 insertions(+) diff --git a/minetest.conf.example b/minetest.conf.example index 838987c3..36ef3145 100644 --- a/minetest.conf.example +++ b/minetest.conf.example @@ -136,6 +136,8 @@ #screenshot_path = . # Amount of view bobbing (0 = no view bobbing, 1.0 = normal, 2.0 = double) #view_bobbing_amount = 1.0 +# Amount of fall bobbing (0 = no fall bobbing, 1.0 = normal, 2.0 = double) +#fall_bobbing_amount = 0.0 # Anaglyph stereo #anaglyph = false #anaglyph_strength = 0.1 diff --git a/src/camera.cpp b/src/camera.cpp index 211ecfd7..6224a2b8 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -263,6 +263,8 @@ void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize, fall_bobbing = sin(fall_bobbing * 0.5 * M_PI) * -1; // Amplify according to the intensity of the impact fall_bobbing *= (1 - rangelim(50 / player->camera_impact, 0, 1)) * 5; + + fall_bobbing *= g_settings->getFloat("fall_bobbing_amount"); } // Set head node transformation diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 9875c6ec..09ec4569 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -107,6 +107,7 @@ void set_default_settings(Settings *settings) settings->setDefault("enable_clouds", "true"); settings->setDefault("screenshot_path", "."); settings->setDefault("view_bobbing_amount", "1.0"); + settings->setDefault("fall_bobbing_amount", "0.0"); settings->setDefault("enable_3d_clouds", "true"); settings->setDefault("cloud_height", "120"); settings->setDefault("menu_clouds", "true"); From 770305e28dc0ed9aea0eefe041477a46d64eee58 Mon Sep 17 00:00:00 2001 From: kwolekr Date: Tue, 23 Apr 2013 18:39:10 -0400 Subject: [PATCH 07/26] Add option to use texture alpha channel --- client/shaders/test_shader_3/base.txt | 1 + .../test_shader_3/opengl_fragment.glsl | 23 +++++++++ .../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 diff --git a/client/shaders/test_shader_3/base.txt b/client/shaders/test_shader_3/base.txt new file mode 100644 index 00000000..1c264711 --- /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 00000000..78abadca --- /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 00000000..2881bad2 --- /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 531a40b2..42579fda 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 f68a79e4..f8a0b5f0 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 e2b72333..e09c1910 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 3b7ed517..30fd7034 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 c5c7f930..ea5c4be5 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; From a699bdb7a11661778da0b45abd6a74c26b9e2237 Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Wed, 24 Apr 2013 04:12:24 +0200 Subject: [PATCH 08/26] Fix to: addUpdateMeshTaskWithEdge Check in all 6 directions instead of just 3. --- src/client.cpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/client.cpp b/src/client.cpp index 15fb6932..bd72737f 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -45,6 +45,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "IMeshCache.h" #include "util/serialize.h" #include "config.h" +#include "util/directiontables.h" #if USE_CURL #include @@ -2723,21 +2724,14 @@ void Client::addUpdateMeshTaskWithEdge(v3s16 blockpos, bool ack_to_server, bool } catch(InvalidPositionException &e){} // Leading edge - try{ - v3s16 p = blockpos + v3s16(-1,0,0); - addUpdateMeshTask(p, false, urgent); + for (int i=0;i<6;i++) + { + try{ + v3s16 p = blockpos + g_6dirs[i]; + addUpdateMeshTask(p, false, urgent); + } + catch(InvalidPositionException &e){} } - catch(InvalidPositionException &e){} - try{ - v3s16 p = blockpos + v3s16(0,-1,0); - addUpdateMeshTask(p, false, urgent); - } - catch(InvalidPositionException &e){} - try{ - v3s16 p = blockpos + v3s16(0,0,-1); - addUpdateMeshTask(p, false, urgent); - } - catch(InvalidPositionException &e){} } void Client::addUpdateMeshTaskForNode(v3s16 nodepos, bool ack_to_server, bool urgent) From 33dd267fd9da1a89b44cd6eab590aadab0f4e335 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Mart=C3=ADnez?= Date: Tue, 23 Apr 2013 05:06:24 -0300 Subject: [PATCH 09/26] Fixes possible crash when using hud_change with "align" or "offset" --- src/client.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/client.cpp b/src/client.cpp index bd72737f..12ced17f 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -2097,7 +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) + 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); From e703c5b81f87550e636ebb1ebb1eb64027a44687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Mart=C3=ADnez?= Date: Wed, 24 Apr 2013 07:52:46 -0300 Subject: [PATCH 10/26] 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(-) diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 42579fda..b2106b64 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 12ced17f..941e9e88 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 67ba6c56..33872864 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 5e981c20..114b04d1 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 cbd9eab4..e3251bf6 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 9db92db5..8daadad3 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 104a2f00..e0d7ccd6 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 1ca9423b..e86b6420 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 d0e50d2c..4e5b3af9 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 6669ad87..e2eec510 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 fd46f2cf..81e8cda3 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 62c19003..a93d887e 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 b668ecae..b951ae53 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 From 625a4c2e662f6b69b73a2a828d1b08d72e53ff73 Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Thu, 25 Apr 2013 02:39:21 +0200 Subject: [PATCH 11/26] 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(-) diff --git a/doc/lua_api.txt b/doc/lua_api.txt index b2106b64..5b1942ae 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 84d5f067..155b39ab 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 e09c1910..ba3e42e9 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 d846489a..8be18f9c 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 5ffcaeb9..2fea50fa 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"}, From e9a4e98cb9608e26e7dafc575856aad9da5c27da Mon Sep 17 00:00:00 2001 From: sapier Date: Sun, 21 Apr 2013 15:54:29 +0200 Subject: [PATCH 12/26] Improve getFree*ActiveObjectId to reduce common case cpu usage drasticaly --- src/environment.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/environment.cpp b/src/environment.cpp index fc7972b2..438c9ef4 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -1295,16 +1295,17 @@ bool isFreeServerActiveObjectId(u16 id, u16 getFreeServerActiveObjectId( std::map &objects) { - u16 new_id = 1; + //try to reuse id's as late as possible + static u16 last_used_id = 0; + u16 startid = last_used_id; for(;;) { - if(isFreeServerActiveObjectId(new_id, objects)) - return new_id; + last_used_id ++; + if(isFreeServerActiveObjectId(last_used_id, objects)) + return last_used_id; - if(new_id == 65535) + if(last_used_id == startid) return 0; - - new_id++; } } @@ -2296,16 +2297,17 @@ bool isFreeClientActiveObjectId(u16 id, u16 getFreeClientActiveObjectId( std::map &objects) { - u16 new_id = 1; + //try to reuse id's as late as possible + static u16 last_used_id = 0; + u16 startid = last_used_id; for(;;) { - if(isFreeClientActiveObjectId(new_id, objects)) - return new_id; + last_used_id ++; + if(isFreeClientActiveObjectId(last_used_id, objects)) + return last_used_id; - if(new_id == 65535) + if(last_used_id == startid) return 0; - - new_id++; } } From bc3072b35e6a60cc77ee5275eb9e7cd5c537385c Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Thu, 25 Apr 2013 11:51:28 +0300 Subject: [PATCH 13/26] Fix compatibility of RBA's NDT_GLASSLIKE_FRAMED --- src/nodedef.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/nodedef.h b/src/nodedef.h index 8be18f9c..2691aca3 100644 --- a/src/nodedef.h +++ b/src/nodedef.h @@ -133,8 +133,6 @@ 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, @@ -143,6 +141,9 @@ enum NodeDrawType NDT_FENCELIKE, NDT_RAILLIKE, NDT_NODEBOX, + NDT_GLASSLIKE_FRAMED, // Glass-like, draw connected frames and all all + // visible faces + // uses 2 textures, one for frames, second for faces }; #define CF_SPECIAL_COUNT 2 From ddd2b18321a6dad82c4618bfb8f797579d4d6666 Mon Sep 17 00:00:00 2001 From: kwolekr Date: Thu, 25 Apr 2013 12:29:27 -0400 Subject: [PATCH 14/26] Transform alpha channel as well in shader --- client/shaders/test_shader_3/opengl_fragment.glsl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/shaders/test_shader_3/opengl_fragment.glsl b/client/shaders/test_shader_3/opengl_fragment.glsl index 78abadca..e42fef6e 100644 --- a/client/shaders/test_shader_3/opengl_fragment.glsl +++ b/client/shaders/test_shader_3/opengl_fragment.glsl @@ -9,7 +9,8 @@ void main (void) vec4 col = texture2D(myTexture, vec2(gl_TexCoord[0])); col *= gl_Color; col = col * col; // SRGB -> Linear - col *= 1.8; + col *= 1.8; + col.a = 1.0 - exp(1.0 - col.a) / exp(1.0); 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); From 386108f982e3d0819f6a153d750f967c0b25268c Mon Sep 17 00:00:00 2001 From: PilzAdam Date: Thu, 25 Apr 2013 18:32:49 +0200 Subject: [PATCH 15/26] kahrl is back --- src/guiMainMenu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/guiMainMenu.cpp b/src/guiMainMenu.cpp index 431b40e6..06e7cdff 100644 --- a/src/guiMainMenu.cpp +++ b/src/guiMainMenu.cpp @@ -57,6 +57,7 @@ const wchar_t *contrib_core_strs[] = { }; const wchar_t *contrib_active_strs[] = { + L"kahrl ", L"sfan5 ", L"sapier ", L"Vanessa Ezekowitz (VanessaE) ", @@ -69,7 +70,6 @@ const wchar_t *contrib_active_strs[] = { }; const wchar_t *contrib_previous_strs[] = { - L"kahrl ", L"Giuseppe Bilotta (Oblomov) ", L"Jonathan Neuschafer ", L"Nils Dagsson Moskopp (erlehmann) ", From 88ffb3f73bb16c6680ee10a8e804a699e366edd8 Mon Sep 17 00:00:00 2001 From: sapier Date: Wed, 17 Apr 2013 00:15:53 +0200 Subject: [PATCH 16/26] Move player collisionbox to player class --- src/content_sao.cpp | 9 +++++++-- src/localplayer.cpp | 17 +---------------- src/player.cpp | 3 ++- src/player.h | 5 +++++ 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/content_sao.cpp b/src/content_sao.cpp index 3526ecbd..24a9186f 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -1472,6 +1472,11 @@ std::string PlayerSAO::getPropertyPacket() } bool PlayerSAO::getCollisionBox(aabb3f *toset) { - //player collision handling is already done clientside no need to do it twice - return false; + //update collision box + *toset = m_player->getCollisionbox(); + + toset->MinEdge += m_base_position; + toset->MaxEdge += m_base_position; + + return true; } diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 6b7b0943..13117d88 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -154,9 +154,6 @@ void LocalPlayer::move(f32 dtime, ClientEnvironment *env, f32 pos_max_d, // This should always apply, otherwise there are glitches assert(d > pos_max_d); - float player_radius = BS*0.30; - float player_height = BS*1.55; - // Maximum distance over border for sneaking f32 sneak_max = BS*0.4; @@ -184,24 +181,12 @@ void LocalPlayer::move(f32 dtime, ClientEnvironment *env, f32 pos_max_d, } } - /* - Calculate player collision box (new and old) - */ - core::aabbox3d playerbox( - -player_radius, - 0.0, - -player_radius, - player_radius, - player_height, - player_radius - ); - float player_stepheight = touching_ground ? (BS*0.6) : (BS*0.2); v3f accel_f = v3f(0,0,0); collisionMoveResult result = collisionMoveSimple(env, m_gamedef, - pos_max_d, playerbox, player_stepheight, dtime, + pos_max_d, m_collisionbox, player_stepheight, dtime, position, m_speed, accel_f); /* diff --git a/src/player.cpp b/src/player.cpp index e86b6420..d3e16810 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -42,7 +42,8 @@ Player::Player(IGameDef *gamedef): m_pitch(0), m_yaw(0), m_speed(0,0,0), - m_position(0,0,0) + m_position(0,0,0), + m_collisionbox(-BS*0.30,0.0,-BS*0.30,BS*0.30,BS*1.55,BS*0.30) { updateName(""); inventory.clear(); diff --git a/src/player.h b/src/player.h index 4e5b3af9..fade6de0 100644 --- a/src/player.h +++ b/src/player.h @@ -180,6 +180,10 @@ public: return m_name; } + core::aabbox3d getCollisionbox() { + return m_collisionbox; + } + virtual bool isLocal() const { return false; } virtual PlayerSAO *getPlayerSAO() @@ -255,6 +259,7 @@ protected: f32 m_yaw; v3f m_speed; v3f m_position; + core::aabbox3d m_collisionbox; }; From c33b99339788995a31cb3f652a9ffe8f7270b061 Mon Sep 17 00:00:00 2001 From: Zeg9 Date: Fri, 12 Apr 2013 12:58:04 +0200 Subject: [PATCH 17/26] Fix serverlist on -DRUN_IN_PLACE=0 (use path_user instead of path_share) --- src/serverlist.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/serverlist.cpp b/src/serverlist.cpp index 93f9d243..7053436d 100644 --- a/src/serverlist.cpp +++ b/src/serverlist.cpp @@ -38,10 +38,12 @@ std::string getFilePath() { std::string serverlist_file = g_settings->get("serverlist_file"); - std::string rel_path = std::string("client") + DIR_DELIM - + "serverlist" + DIR_DELIM - + serverlist_file; - std::string path = porting::path_share + DIR_DELIM + rel_path; + std::string dir_path = std::string("client") + DIR_DELIM + + "serverlist" + DIR_DELIM; + fs::CreateDir(porting::path_user + DIR_DELIM + "client"); + fs::CreateDir(porting::path_user + DIR_DELIM + dir_path); + std::string rel_path = dir_path + serverlist_file; + std::string path = porting::path_user + DIR_DELIM + rel_path; return path; } From d83602d98ed9df6a8b9bc0d68a14b824777e2032 Mon Sep 17 00:00:00 2001 From: proller Date: Thu, 25 Apr 2013 22:52:23 +0400 Subject: [PATCH 18/26] Tune finite liquids, indev huge caves --- src/map.cpp | 2 +- src/mapgen_indev.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/map.cpp b/src/map.cpp index c4884a45..821805d4 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -1764,7 +1764,7 @@ void Map::transformLiquidsFinite(std::map & modified_blocks) } // prevent lakes in air above unloaded blocks - if (p0.Y > water_level && neighbors[D_BOTTOM].n.getContent() == CONTENT_IGNORE) { + if (liquid_levels[D_TOP] == 0 && (p0.Y > water_level || !fast_flood) && neighbors[D_BOTTOM].n.getContent() == CONTENT_IGNORE) { --total_level; } diff --git a/src/mapgen_indev.cpp b/src/mapgen_indev.cpp index 7f0faf16..ce5cfbfe 100644 --- a/src/mapgen_indev.cpp +++ b/src/mapgen_indev.cpp @@ -303,7 +303,7 @@ CaveIndev::CaveIndev(Mapgen *mg, PseudoRandom *ps, PseudoRandom *ps2, flooded = !ps->range(0, 3); tunnel_routepoints = ps->range(5, 30); min_tunnel_diameter = 30; - max_tunnel_diameter = ps->range(40, ps->range(80, 200)); + max_tunnel_diameter = ps->range(40, ps->range(80, 150)); } else { tunnel_routepoints = ps->range(5, ps->range(15,30)); min_tunnel_diameter = 5; From d3f0ce62240b7598eded13153eacb410bf2420a1 Mon Sep 17 00:00:00 2001 From: kwolekr Date: Thu, 25 Apr 2013 19:27:22 -0400 Subject: [PATCH 19/26] 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(-) diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 5b1942ae..07fb1ccd 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 941e9e88..56505c66 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 33872864..67ba6c56 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 114b04d1..cfa87ada 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 e3251bf6..189003e4 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 8daadad3..cf53354b 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 e0d7ccd6..405e9117 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 d3e16810..34f0fda0 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 e2eec510..4dfdeb8c 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 81e8cda3..82535ee9 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 a93d887e..d5e50519 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 b951ae53..dcd007d2 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 From 43a388ec533220fcdb84fb3680bcb87a38fd010d Mon Sep 17 00:00:00 2001 From: "Esteban I. Ruiz Moreno" Date: Sat, 20 Apr 2013 22:39:31 -0300 Subject: [PATCH 20/26] Ability to change the crosshair using textures --- src/hud.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/hud.cpp b/src/hud.cpp index cf53354b..375d6587 100644 --- a/src/hud.cpp +++ b/src/hud.cpp @@ -297,7 +297,19 @@ void Hud::drawHotbar(v2s32 centerlowerpos, s32 halfheartcount, u16 playeritem) { void Hud::drawCrosshair() { - if (player->hud_flags & HUD_FLAG_CROSSHAIR_VISIBLE) { + if (!(player->hud_flags & HUD_FLAG_CROSSHAIR_VISIBLE)) + return; + + ITextureSource *tsrc = gamedef->getTextureSource(); + if (tsrc->isKnownSourceImage("crosshair.png")) { + video::ITexture *crosshair = tsrc->getTextureRaw("crosshair.png"); + v2u32 size = crosshair->getOriginalSize(); + v2s32 lsize = v2s32(displaycenter.X - (size.X / 2), + displaycenter.Y - (size.Y / 2)); + driver->draw2DImage(crosshair, lsize, + core::rect(0, 0, size.X, size.Y), + 0, crosshair_argb, true); + } else { driver->draw2DLine(displaycenter - v2s32(10, 0), displaycenter + v2s32(10, 0), crosshair_argb); driver->draw2DLine(displaycenter - v2s32(0, 10), From 0fb9567f1394646a71d42aa9bd7e6da8343c9784 Mon Sep 17 00:00:00 2001 From: kwolekr Date: Thu, 25 Apr 2013 20:56:12 -0400 Subject: [PATCH 21/26] Minor hud.cpp cleanup --- src/hud.cpp | 15 ++++++++------- src/hud.h | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/hud.cpp b/src/hud.cpp index 375d6587..65c78ca5 100644 --- a/src/hud.cpp +++ b/src/hud.cpp @@ -45,6 +45,8 @@ Hud::Hud(video::IVideoDriver *driver, gui::IGUIEnvironment* guienv, hotbar_imagesize = 48; hotbar_itemcount = 8; + tsrc = gamedef->getTextureSource(); + v3f crosshair_color = g_settings->getV3F("crosshair_color"); u32 cross_r = rangelim(myround(crosshair_color.X), 0, 255); u32 cross_g = rangelim(myround(crosshair_color.Y), 0, 255); @@ -57,6 +59,8 @@ Hud::Hud(video::IVideoDriver *driver, gui::IGUIEnvironment* guienv, u32 sbox_g = rangelim(myround(selectionbox_color.Y), 0, 255); u32 sbox_b = rangelim(myround(selectionbox_color.Z), 0, 255); selectionbox_argb = video::SColor(255, sbox_r, sbox_g, sbox_b); + + use_crosshair_image = tsrc->isKnownSourceImage("crosshair.png"); } @@ -175,8 +179,7 @@ void Hud::drawLuaElements() { v2s32 pos(e->pos.X * screensize.X, e->pos.Y * screensize.Y); switch (e->type) { case HUD_ELEM_IMAGE: { - video::ITexture *texture = - gamedef->getTextureSource()->getTextureRaw(e->text); + video::ITexture *texture = tsrc->getTextureRaw(e->text); if (!texture) continue; @@ -226,8 +229,7 @@ void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s const video::SColor color(255, 255, 255, 255); const video::SColor colors[] = {color, color, color, color}; - video::ITexture *stat_texture = - gamedef->getTextureSource()->getTextureRaw(texture); + video::ITexture *stat_texture = tsrc->getTextureRaw(texture); if (!stat_texture) return; @@ -299,9 +301,8 @@ void Hud::drawHotbar(v2s32 centerlowerpos, s32 halfheartcount, u16 playeritem) { void Hud::drawCrosshair() { if (!(player->hud_flags & HUD_FLAG_CROSSHAIR_VISIBLE)) return; - - ITextureSource *tsrc = gamedef->getTextureSource(); - if (tsrc->isKnownSourceImage("crosshair.png")) { + + if (use_crosshair_image) { video::ITexture *crosshair = tsrc->getTextureRaw("crosshair.png"); v2u32 size = crosshair->getOriginalSize(); v2s32 lsize = v2s32(displaycenter.X - (size.X / 2), diff --git a/src/hud.h b/src/hud.h index 405e9117..00e44dd8 100644 --- a/src/hud.h +++ b/src/hud.h @@ -82,8 +82,6 @@ inline u32 hud_get_free_id(Player *player) { #ifndef SERVER -#include - #include #include "gamedef.h" @@ -99,6 +97,7 @@ public: IGameDef *gamedef; LocalPlayer *player; Inventory *inventory; + ITextureSource *tsrc; v2u32 screensize; v2s32 displaycenter; @@ -107,6 +106,7 @@ public: video::SColor crosshair_argb; video::SColor selectionbox_argb; + bool use_crosshair_image; Hud(video::IVideoDriver *driver, gui::IGUIEnvironment* guienv, gui::IGUIFont *font, u32 text_height, IGameDef *gamedef, From 8767c781699a43e27185181979340f9712b3c236 Mon Sep 17 00:00:00 2001 From: kwolekr Date: Sat, 27 Apr 2013 22:40:52 -0400 Subject: [PATCH 22/26] Enhance caves for mgv7, add ravines --- src/cavegen.cpp | 305 ++++++++++++++++++++++++++++++++++++++++--- src/cavegen.h | 57 +++++++- src/mapgen_indev.cpp | 12 +- src/mapgen_indev.h | 4 +- src/mapgen_v6.cpp | 2 +- src/mapgen_v7.cpp | 25 ++-- 6 files changed, 359 insertions(+), 46 deletions(-) diff --git a/src/cavegen.cpp b/src/cavegen.cpp index bef50c7a..01543252 100644 --- a/src/cavegen.cpp +++ b/src/cavegen.cpp @@ -20,18 +20,21 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/numeric.h" #include "map.h" #include "mapgen.h" +#include "mapgen_v6.h" +#include "mapgen_v7.h" #include "cavegen.h" -CaveV6::CaveV6(Mapgen *mg, PseudoRandom *ps, PseudoRandom *ps2, - bool is_large_cave, content_t c_water, content_t c_lava) { - this->vm = mg->vm; +CaveV6::CaveV6(MapgenV6 *mg, PseudoRandom *ps, PseudoRandom *ps2, bool is_large_cave) { + this->mg = mg; + this->vm = mg->vm; + this->ndef = mg->ndef; this->water_level = mg->water_level; this->large_cave = is_large_cave; this->ps = ps; this->ps2 = ps2; - this->c_water_source = c_water; - this->c_lava_source = c_lava; + this->c_water_source = mg->c_water_source; + this->c_lava_source = mg->c_lava_source; min_tunnel_diameter = 2; max_tunnel_diameter = ps->range(2, 6); @@ -152,13 +155,6 @@ void CaveV6::makeTunnel(bool dirswitch) { ); } - /*if(large_cave){ - v3f p = orp + vec; - s16 h = find_ground_level_clever(vmanip, v2s16(p.X, p.Z), ndef); - route_y_min = h - rs/3; - route_y_max = h + rs; - }*/ - vec += main_direction; v3f rp = orp + vec; @@ -181,7 +177,7 @@ void CaveV6::makeTunnel(bool dirswitch) { float veclen = vec.getLength(); // As odd as it sounds, veclen is *exactly* 0.0 sometimes, causing a FPE - if (veclen == 0.0) + if (veclen < 0.05) veclen = 1.0; // Every second section is rough @@ -220,11 +216,7 @@ void CaveV6::carveRoute(v3f vec, float f, bool randomize_xz) { for (s16 x0 = -si - ps->range(0,1); x0 <= si - 1 + ps->range(0,1); x0++) { s16 maxabsxz = MYMAX(abs(x0), abs(z0)); s16 si2 = rs / 2 - MYMAX(0, maxabsxz - rs / 7 - 1); - for (s16 y0 = -si2; y0 <= si2; y0++) { - // Make better floors in small caves - //if(y0 <= -rs/2 && rs<=7) - // continue; - + for (s16 y0 = -si2; y0 <= si2; y0++) { if (large_cave_is_flat) { // Make large caves not so tall if (rs > 7 && abs(y0) >= rs / 3) @@ -242,7 +234,7 @@ void CaveV6::carveRoute(v3f vec, float f, bool randomize_xz) { if (large_cave) { int full_ymin = node_min.Y - MAP_BLOCKSIZE; int full_ymax = node_max.Y + MAP_BLOCKSIZE; - + if (flooded && full_ymin < water_level && full_ymax > water_level) { vm->m_data[i] = (p.Y <= water_level) ? waternode : airnode; } else if (flooded && full_ymax < water_level) { @@ -264,3 +256,278 @@ void CaveV6::carveRoute(v3f vec, float f, bool randomize_xz) { } } } + + +///////////////////////////////////////// Caves V7 + +CaveV7::CaveV7(MapgenV7 *mg, PseudoRandom *ps, bool is_large_cave) { + this->mg = mg; + this->vm = mg->vm; + this->ndef = mg->ndef; + this->water_level = mg->water_level; + this->large_cave = is_large_cave; + this->ps = ps; + this->c_water_source = mg->c_water_source; + this->c_lava_source = mg->c_lava_source; + + dswitchint = ps->range(1, 14); + flooded = ps->range(1, 2) == 2; + + if (large_cave) { + part_max_length_rs = ps->range(2, 4); + tunnel_routepoints = ps->range(5, ps->range(15, 30)); + min_tunnel_diameter = 5; + max_tunnel_diameter = ps->range(7, ps->range(8, 24)); + } else { + part_max_length_rs = ps->range(2, 9); + tunnel_routepoints = ps->range(10, ps->range(15, 30)); + min_tunnel_diameter = 2; + max_tunnel_diameter = ps->range(2, 6); + } + + large_cave_is_flat = (ps->range(0, 1) == 0); +} + + +void CaveV7::makeCave(v3s16 nmin, v3s16 nmax, int max_stone_height) { + node_min = nmin; + node_max = nmax; + max_stone_y = max_stone_height; + main_direction = v3f(0, 0, 0); + + // Allowed route area size in nodes + ar = node_max - node_min + v3s16(1, 1, 1); + // Area starting point in nodes + of = node_min; + + // Allow a bit more + //(this should be more than the maximum radius of the tunnel) + s16 insure = 10; + s16 more = MAP_BLOCKSIZE - max_tunnel_diameter / 2 - insure; + ar += v3s16(1,0,1) * more * 2; + of -= v3s16(1,0,1) * more; + + route_y_min = 0; + // Allow half a diameter + 7 over stone surface + route_y_max = -of.Y + max_stone_y + max_tunnel_diameter / 2 + 7; + + // Limit maximum to area + route_y_max = rangelim(route_y_max, 0, ar.Y - 1); + + if (large_cave) { + s16 min = 0; + if (node_min.Y < water_level && node_max.Y > water_level) { + min = water_level - max_tunnel_diameter/3 - of.Y; + route_y_max = water_level + max_tunnel_diameter/3 - of.Y; + } + route_y_min = ps->range(min, min + max_tunnel_diameter); + route_y_min = rangelim(route_y_min, 0, route_y_max); + } + + s16 route_start_y_min = route_y_min; + s16 route_start_y_max = route_y_max; + + route_start_y_min = rangelim(route_start_y_min, 0, ar.Y - 1); + route_start_y_max = rangelim(route_start_y_max, route_start_y_min, ar.Y - 1); + + // Randomize starting position + orp = v3f( + (float)(ps->next() % ar.X) + 0.5, + (float)(ps->range(route_start_y_min, route_start_y_max)) + 0.5, + (float)(ps->next() % ar.Z) + 0.5 + ); + + // Generate some tunnel starting from orp + for (u16 j = 0; j < tunnel_routepoints; j++) + makeTunnel(j % dswitchint == 0); +} + + +void CaveV7::makeTunnel(bool dirswitch) { + if (dirswitch && !large_cave) { + main_direction = v3f( + ((float)(ps->next() % 20) - (float)10) / 10, + ((float)(ps->next() % 20) - (float)10) / 30, + ((float)(ps->next() % 20) - (float)10) / 10 + ); + main_direction *= (float)ps->range(0, 10) / 10; + } + + // Randomize size + s16 min_d = min_tunnel_diameter; + s16 max_d = max_tunnel_diameter; + rs = ps->range(min_d, max_d); + + v3s16 maxlen; + if (large_cave) { + maxlen = v3s16( + rs * part_max_length_rs, + rs * part_max_length_rs / 2, + rs * part_max_length_rs + ); + } else { + maxlen = v3s16( + rs * part_max_length_rs, + ps->range(1, rs * part_max_length_rs), + rs * part_max_length_rs + ); + } + + v3f vec; + // Jump downward sometimes + if (!large_cave && ps->range(0, 12) == 0) { + vec = v3f( + (float)(ps->next() % (maxlen.X * 1)) - (float)maxlen.X / 2, + (float)(ps->next() % (maxlen.Y * 2)) - (float)maxlen.Y, + (float)(ps->next() % (maxlen.Z * 1)) - (float)maxlen.Z / 2 + ); + } else { + vec = v3f( + (float)(ps->next() % (maxlen.X * 1)) - (float)maxlen.X / 2, + (float)(ps->next() % (maxlen.Y * 1)) - (float)maxlen.Y / 2, + (float)(ps->next() % (maxlen.Z * 1)) - (float)maxlen.Z / 2 + ); + } + + // Do not make large caves that are above ground. + // It is only necessary to check the startpoint and endpoint. + if (large_cave) { + v3s16 orpi(orp.X, orp.Y, orp.Z); + v3s16 veci(vec.X, vec.Y, vec.Z); + v3s16 p; + + p = orpi + veci + of + rs / 2; + if (p.Z >= node_min.Z && p.Z <= node_max.Z && + p.X >= node_min.X && p.X <= node_max.X) { + u32 index = (p.Z - node_min.Z) * mg->ystride + (p.X - node_min.X); + s16 h = mg->ridge_heightmap[index]; + if (h < p.Y) + return; + } else if (p.Y > water_level) { + return; // If it's not in our heightmap, use a simple heuristic + } + + p = orpi + of + rs / 2; + if (p.Z >= node_min.Z && p.Z <= node_max.Z && + p.X >= node_min.X && p.X <= node_max.X) { + u32 index = (p.Z - node_min.Z) * mg->ystride + (p.X - node_min.X); + s16 h = mg->ridge_heightmap[index]; + if (h < p.Y) + return; + } else if (p.Y > water_level) { + return; + } + } + + vec += main_direction; + + v3f rp = orp + vec; + if (rp.X < 0) + rp.X = 0; + else if (rp.X >= ar.X) + rp.X = ar.X - 1; + + if (rp.Y < route_y_min) + rp.Y = route_y_min; + else if (rp.Y >= route_y_max) + rp.Y = route_y_max - 1; + + if (rp.Z < 0) + rp.Z = 0; + else if (rp.Z >= ar.Z) + rp.Z = ar.Z - 1; + + vec = rp - orp; + + float veclen = vec.getLength(); + if (veclen < 0.05) + veclen = 1.0; + + // Every second section is rough + bool randomize_xz = (ps->range(1, 2) == 1); + + // Make a ravine every once in a while if it's long enough + float xylen = vec.X * vec.X + vec.Z * vec.Z; + bool is_ravine = (xylen > 500.0) && !large_cave && (ps->range(1, 8) == 1); + + // Carve routes + for (float f = 0; f < 1.0; f += 1.0 / veclen) + carveRoute(vec, f, randomize_xz, is_ravine); + + orp = rp; +} + + +void CaveV7::carveRoute(v3f vec, float f, bool randomize_xz, bool is_ravine) { + MapNode airnode(CONTENT_AIR); + MapNode waternode(c_water_source); + MapNode lavanode(c_lava_source); + MapNode liquidnode = ps->range(0, 4) ? lavanode : waternode; + + v3s16 startp(orp.X, orp.Y, orp.Z); + startp += of; + + v3f fp = orp + vec * f; + fp.X += 0.1 * ps->range(-10, 10); + fp.Z += 0.1 * ps->range(-10, 10); + v3s16 cp(fp.X, fp.Y, fp.Z); + + s16 d0 = -rs/2; + s16 d1 = d0 + rs; + if (randomize_xz) { + d0 += ps->range(-1, 1); + d1 += ps->range(-1, 1); + } + + bool flat_cave_floor = !large_cave && ps->range(0, 2) == 2; + + for (s16 z0 = d0; z0 <= d1; z0++) { + s16 si = rs / 2 - MYMAX(0, abs(z0) - rs / 7 - 1); + for (s16 x0 = -si - ps->range(0,1); x0 <= si - 1 + ps->range(0,1); x0++) { + s16 maxabsxz = MYMAX(abs(x0), abs(z0)); + + s16 si2 = is_ravine ? MYMIN(ps->range(25, 26), ar.Y) : + rs / 2 - MYMAX(0, maxabsxz - rs / 7 - 1); + + for (s16 y0 = -si2; y0 <= si2; y0++) { + // Make better floors in small caves + if(flat_cave_floor && y0 <= -rs/2 && rs<=7) + continue; + + if (large_cave_is_flat) { + // Make large caves not so tall + if (rs > 7 && abs(y0) >= rs / 3) + continue; + } + + v3s16 p(cp.X + x0, cp.Y + y0, cp.Z + z0); + p += of; + + if (vm->m_area.contains(p) == false) + continue; + + u32 i = vm->m_area.index(p); + + // Don't replace air or water or lava + content_t c = vm->m_data[i].getContent(); + if (c == CONTENT_AIR || c == c_water_source || c == c_lava_source) + continue; + + if (large_cave) { + int full_ymin = node_min.Y - MAP_BLOCKSIZE; + int full_ymax = node_max.Y + MAP_BLOCKSIZE; + + if (flooded && full_ymin < water_level && full_ymax > water_level) + vm->m_data[i] = (p.Y <= water_level) ? waternode : airnode; + else if (flooded && full_ymax < water_level) + vm->m_data[i] = (p.Y < startp.Y - 4) ? liquidnode : airnode; + else + vm->m_data[i] = airnode; + } else { + vm->m_data[i] = airnode; + vm->m_flags[i] |= VMANIP_FLAG_CAVE; + } + } + } + } +} diff --git a/src/cavegen.h b/src/cavegen.h index 979226b3..7822816d 100644 --- a/src/cavegen.h +++ b/src/cavegen.h @@ -22,9 +22,14 @@ with this program; if not, write to the Free Software Foundation, Inc., #define VMANIP_FLAG_CAVE VOXELFLAG_CHECKED1 +class MapgenV6; +class MapgenV7; + class CaveV6 { public: + MapgenV6 *mg; ManualMapVoxelManipulator *vm; + INodeDefManager *ndef; s16 min_tunnel_diameter; s16 max_tunnel_diameter; @@ -40,10 +45,10 @@ public: v3s16 node_min; v3s16 node_max; - v3f orp; //original point - v3s16 of; + v3f orp; // starting point, relative to caved space + v3s16 of; // absolute coordinates of caved space v3s16 ar; // allowed route area - s16 rs; // radius size + s16 rs; // tunnel radius size v3f main_direction; s16 route_y_min; @@ -58,11 +63,53 @@ public: int water_level; CaveV6() {} - CaveV6(Mapgen *mg, PseudoRandom *ps, PseudoRandom *ps2, bool large_cave, - content_t c_water, content_t c_lava); + CaveV6(MapgenV6 *mg, PseudoRandom *ps, PseudoRandom *ps2, bool large_cave); void makeCave(v3s16 nmin, v3s16 nmax, int max_stone_height); void makeTunnel(bool dirswitch); void carveRoute(v3f vec, float f, bool randomize_xz); }; +class CaveV7 { +public: + MapgenV7 *mg; + ManualMapVoxelManipulator *vm; + INodeDefManager *ndef; + + s16 min_tunnel_diameter; + s16 max_tunnel_diameter; + u16 tunnel_routepoints; + int dswitchint; + int part_max_length_rs; + + bool large_cave; + bool large_cave_is_flat; + bool flooded; + + s16 max_stone_y; + v3s16 node_min; + v3s16 node_max; + + v3f orp; // starting point, relative to caved space + v3s16 of; // absolute coordinates of caved space + v3s16 ar; // allowed route area + s16 rs; // tunnel radius size + v3f main_direction; + + s16 route_y_min; + s16 route_y_max; + + PseudoRandom *ps; + + content_t c_water_source; + content_t c_lava_source; + + int water_level; + + CaveV7() {} + CaveV7(MapgenV7 *mg, PseudoRandom *ps, bool large_cave); + void makeCave(v3s16 nmin, v3s16 nmax, int max_stone_height); + void makeTunnel(bool dirswitch); + void carveRoute(v3f vec, float f, bool randomize_xz, bool is_ravine); +}; + #endif diff --git a/src/mapgen_indev.cpp b/src/mapgen_indev.cpp index ce5cfbfe..2eeaf13e 100644 --- a/src/mapgen_indev.cpp +++ b/src/mapgen_indev.cpp @@ -274,23 +274,21 @@ void MapgenIndev::generateCaves(int max_stone_y) { for (u32 i = 0; i < caves_count + bruises_count; i++) { bool large_cave = (i >= caves_count); - CaveIndev cave(this, &ps, &ps2, node_min, large_cave, - c_water_source, c_lava_source); + CaveIndev cave(this, &ps, &ps2, node_min, large_cave); cave.makeCave(node_min, node_max, max_stone_y); } } -CaveIndev::CaveIndev(Mapgen *mg, PseudoRandom *ps, PseudoRandom *ps2, - v3s16 node_min, bool is_large_cave, - content_t c_water, content_t c_lava) { +CaveIndev::CaveIndev(MapgenIndev *mg, PseudoRandom *ps, PseudoRandom *ps2, + v3s16 node_min, bool is_large_cave) { this->vm = mg->vm; this->water_level = mg->water_level; this->large_cave = is_large_cave; this->ps = ps; this->ps2 = ps2; - this->c_water_source = c_water; - this->c_lava_source = c_lava; + this->c_water_source = mg->c_water_source; + this->c_lava_source = mg->c_lava_source; min_tunnel_diameter = 2; max_tunnel_diameter = ps->range(2,6); diff --git a/src/mapgen_indev.h b/src/mapgen_indev.h index bd6faa21..87ae39d0 100644 --- a/src/mapgen_indev.h +++ b/src/mapgen_indev.h @@ -153,8 +153,8 @@ struct MapgenFactoryIndev : public MapgenFactoryV6 { class CaveIndev : public CaveV6 { public: - CaveIndev(Mapgen *mg, PseudoRandom *ps, PseudoRandom *ps2, v3s16 node_min, - bool is_large_cave, content_t c_water, content_t c_lava); + CaveIndev(MapgenIndev *mg, PseudoRandom *ps, PseudoRandom *ps2, + v3s16 node_min, bool is_large_cave); }; #endif diff --git a/src/mapgen_v6.cpp b/src/mapgen_v6.cpp index 352afd2f..d90d142d 100644 --- a/src/mapgen_v6.cpp +++ b/src/mapgen_v6.cpp @@ -948,7 +948,7 @@ void MapgenV6::generateCaves(int max_stone_y) { for (u32 i = 0; i < caves_count + bruises_count; i++) { bool large_cave = (i >= caves_count); - CaveV6 cave(this, &ps, &ps2, large_cave, c_water_source, c_lava_source); + CaveV6 cave(this, &ps, &ps2, large_cave); cave.makeCave(node_min, node_max, max_stone_y); } diff --git a/src/mapgen_v7.cpp b/src/mapgen_v7.cpp index efcf7867..4bfc866e 100644 --- a/src/mapgen_v7.cpp +++ b/src/mapgen_v7.cpp @@ -78,7 +78,7 @@ MapgenV7::MapgenV7(int mapgenid, MapgenV7Params *params, EmergeManager *emerge) this->water_level = params->water_level; this->flags = params->flags; this->csize = v3s16(1, 1, 1) * params->chunksize * MAP_BLOCKSIZE; -// this->ystride = csize.X; //////fix this + this->ystride = csize.X; //////fix this this->biomemap = new u8[csize.X * csize.Z]; this->heightmap = new s16[csize.X * csize.Z]; @@ -187,7 +187,6 @@ void MapgenV7::makeChunk(BlockMakeData *data) { generateCaves(stone_surface_max_y); addTopNodes(); - //v3s16 central_area_size = node_max - node_min + v3s16(1,1,1); if (flags & MG_DUNGEONS) { DungeonGen dgen(ndef, data->seed, water_level); @@ -452,7 +451,8 @@ void MapgenV7::addTopNodes() { vm->m_area.add_y(em, i, 1); } // If dirt, grow grass on it. - if (vm->m_data[i].getContent() == CONTENT_AIR) { + if (y > water_level - 10 && + vm->m_data[i].getContent() == CONTENT_AIR) { vm->m_area.add_y(em, i, -1); if (vm->m_data[i].getContent() == c_dirt) vm->m_data[i] = MapNode(c_dirt_with_grass); @@ -489,7 +489,8 @@ void MapgenV7::addTopNodes() { vm->m_area.add_y(em, i, 1); } // If dirt, grow grass on it. - if (vm->m_data[i].getContent() == CONTENT_AIR) { + if (y > water_level - 10 && + vm->m_data[i].getContent() == CONTENT_AIR) { vm->m_area.add_y(em, i, -1); if (vm->m_data[i].getContent() == c_dirt) vm->m_data[i] = MapNode(c_dirt_with_grass); @@ -502,22 +503,22 @@ void MapgenV7::addTopNodes() { #include "mapgen_v6.h" void MapgenV7::generateCaves(int max_stone_y) { PseudoRandom ps(blockseed + 21343); - PseudoRandom ps2(blockseed + 1032); int volume_nodes = (node_max.X - node_min.X + 1) * - (node_max.Y - node_min.Y + 1) * MAP_BLOCKSIZE; + (node_max.Y - node_min.Y + 1) * + (node_max.Z - node_min.Z + 1); float cave_amount = NoisePerlin2D(&nparams_v6_def_cave, node_min.X, node_min.Y, seed); - - u32 caves_count = MYMAX(0.0, cave_amount) * volume_nodes / 50000; + + u32 caves_count = MYMAX(0.0, cave_amount) * volume_nodes / 250000; for (u32 i = 0; i < caves_count; i++) { - CaveV6 cave(this, &ps, &ps2, false, c_water_source, c_lava_source); + CaveV7 cave(this, &ps, false); cave.makeCave(node_min, node_max, max_stone_y); } - - u32 bruises_count = (ps.range(1, 6) == 1) ? ps.range(0, ps.range(0, 2)) : 1; + + u32 bruises_count = (ps.range(1, 8) == 1) ? ps.range(0, ps.range(0, 2)) : 1; for (u32 i = 0; i < bruises_count; i++) { - CaveV6 cave(this, &ps, &ps2, true, c_water_source, c_lava_source); + CaveV7 cave(this, &ps, true); cave.makeCave(node_min, node_max, max_stone_y); } } From d7395cd2aba86f5b15cdce3be2ec141f88f95ab6 Mon Sep 17 00:00:00 2001 From: kwolekr Date: Sat, 27 Apr 2013 23:04:52 -0400 Subject: [PATCH 23/26] Actually fix shader3 alpha this time --- client/shaders/test_shader_3/opengl_fragment.glsl | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/client/shaders/test_shader_3/opengl_fragment.glsl b/client/shaders/test_shader_3/opengl_fragment.glsl index e42fef6e..535774c1 100644 --- a/client/shaders/test_shader_3/opengl_fragment.glsl +++ b/client/shaders/test_shader_3/opengl_fragment.glsl @@ -8,17 +8,18 @@ void main (void) { vec4 col = texture2D(myTexture, vec2(gl_TexCoord[0])); col *= gl_Color; + float a = col.a; col = col * col; // SRGB -> Linear - col *= 1.8; - col.a = 1.0 - exp(1.0 - col.a) / exp(1.0); + 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; + col.b = 1.0 - exp(1.0 - col.b) / exp(1.0); + col = sqrt(col); // Linear -> SRGB + 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); } From c824abd7b2e199d9c7e3dcc2839a28275f4120f2 Mon Sep 17 00:00:00 2001 From: kwolekr Date: Sun, 28 Apr 2013 21:07:09 -0400 Subject: [PATCH 24/26] Fix itemdef drop on NULL texture --- src/itemdef.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/itemdef.cpp b/src/itemdef.cpp index 784919ae..05328ea4 100644 --- a/src/itemdef.cpp +++ b/src/itemdef.cpp @@ -247,7 +247,8 @@ public: i = values.begin(); i != values.end(); ++i) { ClientCached *cc = *i; - cc->wield_mesh->drop(); + if (cc->wield_mesh) + cc->wield_mesh->drop(); delete cc; } From a4183994a446a065e3151745b4167270ebae6194 Mon Sep 17 00:00:00 2001 From: Sfan5 Date: Wed, 1 May 2013 12:31:21 +0200 Subject: [PATCH 25/26] 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 diff --git a/builtin/builtin.lua b/builtin/builtin.lua index bf33cbe6..f10c6c7c 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 00000000..0eef2519 --- /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 07fb1ccd..597f98c2 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) From 898a4e441fc0245aaf4821ff5e3dad0daccda3b5 Mon Sep 17 00:00:00 2001 From: Ilya Zhuravlev Date: Wed, 1 May 2013 17:32:29 +0400 Subject: [PATCH 26/26] Add Norwegian language. --- po/no/minetest.po | 757 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 757 insertions(+) create mode 100644 po/no/minetest.po diff --git a/po/no/minetest.po b/po/no/minetest.po new file mode 100644 index 00000000..58d0d95c --- /dev/null +++ b/po/no/minetest.po @@ -0,0 +1,757 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: minetest\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-03-30 19:56+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: src/guiConfigureWorld.cpp:125 +msgid "" +"Warning: Some mods are not configured yet.\n" +"They will be enabled by default when you save the configuration. " +msgstr "" + +#: src/guiConfigureWorld.cpp:144 +msgid "" +"Warning: Some configured mods are missing.\n" +"Their setting will be removed when you save the configuration. " +msgstr "" + +#: src/guiConfigureWorld.cpp:208 +msgid "enabled" +msgstr "" + +#: src/guiConfigureWorld.cpp:215 +msgid "Enable All" +msgstr "" + +#: src/guiConfigureWorld.cpp:222 +msgid "Disable All" +msgstr "" + +#: src/guiConfigureWorld.cpp:228 +msgid "depends on:" +msgstr "" + +#: src/guiConfigureWorld.cpp:240 +msgid "is required by:" +msgstr "" + +#: src/guiConfigureWorld.cpp:262 src/guiCreateWorld.cpp:165 +#: src/guiKeyChangeMenu.cpp:179 src/keycode.cpp:223 +msgid "Cancel" +msgstr "" + +#: src/guiConfigureWorld.cpp:268 src/guiKeyChangeMenu.cpp:173 +msgid "Save" +msgstr "" + +#: src/guiConfigureWorld.cpp:394 +msgid "Configuration saved. " +msgstr "" + +#: src/guiConfigureWorld.cpp:402 +msgid "Warning: Configuration not consistent. " +msgstr "" + +#: src/guiConfirmMenu.cpp:120 +msgid "Yes" +msgstr "" + +#: src/guiConfirmMenu.cpp:126 +msgid "No" +msgstr "" + +#: src/guiCreateWorld.cpp:116 +msgid "World name" +msgstr "" + +#: src/guiCreateWorld.cpp:135 +msgid "Game" +msgstr "" + +#: src/guiCreateWorld.cpp:159 +msgid "Create" +msgstr "" + +#: src/guiDeathScreen.cpp:96 +msgid "You died." +msgstr "" + +#: src/guiDeathScreen.cpp:104 +msgid "Respawn" +msgstr "" + +#: src/guiFormSpecMenu.cpp:582 +msgid "Left click: Move all items, Right click: Move single item" +msgstr "" + +#: src/guiFormSpecMenu.cpp:607 src/guiMessageMenu.cpp:109 +#: src/guiTextInputMenu.cpp:131 +msgid "Proceed" +msgstr "" + +#: src/guiKeyChangeMenu.cpp:114 +msgid "Keybindings. (If this menu screws up, remove stuff from minetest.conf)" +msgstr "" + +#: src/guiKeyChangeMenu.cpp:151 +msgid "\"Use\" = climb down" +msgstr "" + +#: src/guiKeyChangeMenu.cpp:164 +msgid "Double tap \"jump\" to toggle fly" +msgstr "" + +#: src/guiKeyChangeMenu.cpp:269 +msgid "Key already in use" +msgstr "" + +#: src/guiKeyChangeMenu.cpp:347 +msgid "press key" +msgstr "" + +#: src/guiKeyChangeMenu.cpp:372 +msgid "Forward" +msgstr "" + +#: src/guiKeyChangeMenu.cpp:373 +msgid "Backward" +msgstr "" + +#: src/guiKeyChangeMenu.cpp:374 src/keycode.cpp:228 +msgid "Left" +msgstr "" + +#: src/guiKeyChangeMenu.cpp:375 src/keycode.cpp:228 +msgid "Right" +msgstr "" + +#: src/guiKeyChangeMenu.cpp:376 +msgid "Use" +msgstr "" + +#: src/guiKeyChangeMenu.cpp:377 +msgid "Jump" +msgstr "" + +#: src/guiKeyChangeMenu.cpp:378 +msgid "Sneak" +msgstr "" + +#: src/guiKeyChangeMenu.cpp:379 +msgid "Drop" +msgstr "" + +#: src/guiKeyChangeMenu.cpp:380 +msgid "Inventory" +msgstr "" + +#: src/guiKeyChangeMenu.cpp:381 +msgid "Chat" +msgstr "" + +#: src/guiKeyChangeMenu.cpp:382 +msgid "Command" +msgstr "" + +#: src/guiKeyChangeMenu.cpp:383 +msgid "Console" +msgstr "" + +#: src/guiKeyChangeMenu.cpp:384 +msgid "Toggle fly" +msgstr "" + +#: src/guiKeyChangeMenu.cpp:385 +msgid "Toggle fast" +msgstr "" + +#: src/guiKeyChangeMenu.cpp:386 +msgid "Toggle noclip" +msgstr "" + +#: src/guiKeyChangeMenu.cpp:387 +msgid "Range select" +msgstr "" + +#: src/guiKeyChangeMenu.cpp:388 +msgid "Print stacks" +msgstr "" + +#: src/guiMainMenu.cpp:92 +msgid "Cannot create world: Name contains invalid characters" +msgstr "" + +#: src/guiMainMenu.cpp:101 +msgid "Cannot create world: A world by this name already exists" +msgstr "" + +#: src/guiMainMenu.cpp:283 +msgid "Singleplayer" +msgstr "" + +#: src/guiMainMenu.cpp:284 +msgid "Multiplayer" +msgstr "" + +#: src/guiMainMenu.cpp:285 +msgid "Advanced" +msgstr "" + +#: src/guiMainMenu.cpp:286 +msgid "Settings" +msgstr "" + +#: src/guiMainMenu.cpp:287 +msgid "Credits" +msgstr "" + +#: src/guiMainMenu.cpp:317 +msgid "Select World:" +msgstr "" + +#: src/guiMainMenu.cpp:339 src/guiMainMenu.cpp:511 src/keycode.cpp:229 +msgid "Delete" +msgstr "" + +#: src/guiMainMenu.cpp:346 +msgid "New" +msgstr "" + +#: src/guiMainMenu.cpp:354 +msgid "Configure" +msgstr "" + +#: src/guiMainMenu.cpp:369 src/keycode.cpp:248 +msgid "Play" +msgstr "" + +#: src/guiMainMenu.cpp:380 src/guiMainMenu.cpp:619 +msgid "Creative Mode" +msgstr "" + +#: src/guiMainMenu.cpp:386 src/guiMainMenu.cpp:625 +msgid "Enable Damage" +msgstr "" + +#: src/guiMainMenu.cpp:406 src/guiMainMenu.cpp:541 +msgid "Name/Password" +msgstr "" + +#: src/guiMainMenu.cpp:442 src/guiMainMenu.cpp:459 src/guiMainMenu.cpp:1184 +msgid "Favorites:" +msgstr "" + +#: src/guiMainMenu.cpp:450 src/guiMainMenu.cpp:1194 +msgid "Public Server List:" +msgstr "" + +#: src/guiMainMenu.cpp:470 src/guiMainMenu.cpp:568 +msgid "Address/Port" +msgstr "" + +#: src/guiMainMenu.cpp:497 src/guiMainMenu.cpp:1183 +msgid "Show Public" +msgstr "" + +#: src/guiMainMenu.cpp:501 src/guiMainMenu.cpp:1193 +msgid "Show Favorites" +msgstr "" + +#: src/guiMainMenu.cpp:521 +msgid "Connect" +msgstr "" + +#: src/guiMainMenu.cpp:591 +msgid "Leave address blank to start a local server." +msgstr "" + +#: src/guiMainMenu.cpp:600 +msgid "Start Game / Connect" +msgstr "" + +#: src/guiMainMenu.cpp:632 +msgid "Public" +msgstr "" + +#: src/guiMainMenu.cpp:640 src/guiMainMenu.cpp:1113 +msgid "Delete world" +msgstr "" + +#: src/guiMainMenu.cpp:647 +msgid "Create world" +msgstr "" + +#: src/guiMainMenu.cpp:681 +msgid "Fancy trees" +msgstr "" + +#: src/guiMainMenu.cpp:687 +msgid "Smooth Lighting" +msgstr "" + +#: src/guiMainMenu.cpp:693 +msgid "3D Clouds" +msgstr "" + +#: src/guiMainMenu.cpp:699 +msgid "Opaque water" +msgstr "" + +#: src/guiMainMenu.cpp:709 +msgid "Mip-Mapping" +msgstr "" + +#: src/guiMainMenu.cpp:716 +msgid "Anisotropic Filtering" +msgstr "" + +#: src/guiMainMenu.cpp:723 +msgid "Bi-Linear Filtering" +msgstr "" + +#: src/guiMainMenu.cpp:730 +msgid "Tri-Linear Filtering" +msgstr "" + +#: src/guiMainMenu.cpp:738 +msgid "Shaders" +msgstr "" + +#: src/guiMainMenu.cpp:745 +msgid "Preload item visuals" +msgstr "" + +#: src/guiMainMenu.cpp:752 +msgid "Enable Particles" +msgstr "" + +#: src/guiMainMenu.cpp:759 +msgid "Finite liquid" +msgstr "" + +#: src/guiMainMenu.cpp:769 +msgid "Change keys" +msgstr "" + +#: src/guiMainMenu.cpp:1084 +msgid "Address required." +msgstr "" + +#: src/guiMainMenu.cpp:1102 +msgid "Cannot delete world: Nothing selected" +msgstr "" + +#: src/guiMainMenu.cpp:1117 +msgid "Files to be deleted" +msgstr "" + +#: src/guiMainMenu.cpp:1133 +msgid "Cannot create world: No games found" +msgstr "" + +#: src/guiMainMenu.cpp:1149 +msgid "Cannot configure world: Nothing selected" +msgstr "" + +#: src/guiMainMenu.cpp:1256 +msgid "Failed to delete all world files" +msgstr "" + +#: src/guiPasswordChange.cpp:108 +msgid "Old Password" +msgstr "" + +#: src/guiPasswordChange.cpp:125 +msgid "New Password" +msgstr "" + +#: src/guiPasswordChange.cpp:141 +msgid "Confirm Password" +msgstr "" + +#: src/guiPasswordChange.cpp:158 +msgid "Change" +msgstr "" + +#: src/guiPasswordChange.cpp:167 +msgid "Passwords do not match!" +msgstr "" + +#: src/guiPauseMenu.cpp:123 +msgid "Continue" +msgstr "" + +#: src/guiPauseMenu.cpp:132 +msgid "Change Password" +msgstr "" + +#: src/guiPauseMenu.cpp:140 +msgid "Sound Volume" +msgstr "" + +#: src/guiPauseMenu.cpp:147 +msgid "Exit to Menu" +msgstr "" + +#: src/guiPauseMenu.cpp:154 +msgid "Exit to OS" +msgstr "" + +#: src/guiPauseMenu.cpp:161 +msgid "" +"Default Controls:\n" +"- WASD: Walk\n" +"- Mouse left: dig/hit\n" +"- Mouse right: place/use\n" +"- Mouse wheel: select item\n" +"- 0...9: select item\n" +"- Shift: sneak\n" +"- R: Toggle viewing all loaded chunks\n" +"- I: Inventory menu\n" +"- ESC: This menu\n" +"- T: Chat\n" +msgstr "" + +#: src/guiVolumeChange.cpp:108 +msgid "Sound Volume: " +msgstr "" + +#: src/guiVolumeChange.cpp:121 +msgid "Exit" +msgstr "" + +#: src/keycode.cpp:223 +msgid "Left Button" +msgstr "" + +#: src/keycode.cpp:223 +msgid "Middle Button" +msgstr "" + +#: src/keycode.cpp:223 +msgid "Right Button" +msgstr "" + +#: src/keycode.cpp:223 +msgid "X Button 1" +msgstr "" + +#: src/keycode.cpp:224 +msgid "Back" +msgstr "" + +#: src/keycode.cpp:224 +msgid "Clear" +msgstr "" + +#: src/keycode.cpp:224 +msgid "Return" +msgstr "" + +#: src/keycode.cpp:224 +msgid "Tab" +msgstr "" + +#: src/keycode.cpp:224 +msgid "X Button 2" +msgstr "" + +#: src/keycode.cpp:225 +msgid "Capital" +msgstr "" + +#: src/keycode.cpp:225 +msgid "Control" +msgstr "" + +#: src/keycode.cpp:225 +msgid "Kana" +msgstr "" + +#: src/keycode.cpp:225 +msgid "Menu" +msgstr "" + +#: src/keycode.cpp:225 +msgid "Pause" +msgstr "" + +#: src/keycode.cpp:225 +msgid "Shift" +msgstr "" + +#: src/keycode.cpp:226 +msgid "Convert" +msgstr "" + +#: src/keycode.cpp:226 +msgid "Escape" +msgstr "" + +#: src/keycode.cpp:226 +msgid "Final" +msgstr "" + +#: src/keycode.cpp:226 +msgid "Junja" +msgstr "" + +#: src/keycode.cpp:226 +msgid "Kanji" +msgstr "" + +#: src/keycode.cpp:226 +msgid "Nonconvert" +msgstr "" + +#: src/keycode.cpp:227 +msgid "Accept" +msgstr "" + +#: src/keycode.cpp:227 +msgid "End" +msgstr "" + +#: src/keycode.cpp:227 +msgid "Home" +msgstr "" + +#: src/keycode.cpp:227 +msgid "Mode Change" +msgstr "" + +#: src/keycode.cpp:227 +msgid "Next" +msgstr "" + +#: src/keycode.cpp:227 +msgid "Prior" +msgstr "" + +#: src/keycode.cpp:227 +msgid "Space" +msgstr "" + +#: src/keycode.cpp:228 +msgid "Down" +msgstr "" + +#: src/keycode.cpp:228 +msgid "Execute" +msgstr "" + +#: src/keycode.cpp:228 +msgid "Print" +msgstr "" + +#: src/keycode.cpp:228 +msgid "Select" +msgstr "" + +#: src/keycode.cpp:228 +msgid "Up" +msgstr "" + +#: src/keycode.cpp:229 +msgid "Help" +msgstr "" + +#: src/keycode.cpp:229 +msgid "Insert" +msgstr "" + +#: src/keycode.cpp:229 +msgid "Snapshot" +msgstr "" + +#: src/keycode.cpp:232 +msgid "Left Windows" +msgstr "" + +#: src/keycode.cpp:233 +msgid "Apps" +msgstr "" + +#: src/keycode.cpp:233 +msgid "Numpad 0" +msgstr "" + +#: src/keycode.cpp:233 +msgid "Numpad 1" +msgstr "" + +#: src/keycode.cpp:233 +msgid "Right Windows" +msgstr "" + +#: src/keycode.cpp:233 +msgid "Sleep" +msgstr "" + +#: src/keycode.cpp:234 +msgid "Numpad 2" +msgstr "" + +#: src/keycode.cpp:234 +msgid "Numpad 3" +msgstr "" + +#: src/keycode.cpp:234 +msgid "Numpad 4" +msgstr "" + +#: src/keycode.cpp:234 +msgid "Numpad 5" +msgstr "" + +#: src/keycode.cpp:234 +msgid "Numpad 6" +msgstr "" + +#: src/keycode.cpp:234 +msgid "Numpad 7" +msgstr "" + +#: src/keycode.cpp:235 +msgid "Numpad *" +msgstr "" + +#: src/keycode.cpp:235 +msgid "Numpad +" +msgstr "" + +#: src/keycode.cpp:235 +msgid "Numpad -" +msgstr "" + +#: src/keycode.cpp:235 +msgid "Numpad /" +msgstr "" + +#: src/keycode.cpp:235 +msgid "Numpad 8" +msgstr "" + +#: src/keycode.cpp:235 +msgid "Numpad 9" +msgstr "" + +#: src/keycode.cpp:239 +msgid "Num Lock" +msgstr "" + +#: src/keycode.cpp:239 +msgid "Scroll Lock" +msgstr "" + +#: src/keycode.cpp:240 +msgid "Left Shift" +msgstr "" + +#: src/keycode.cpp:240 +msgid "Right Shift" +msgstr "" + +#: src/keycode.cpp:241 +msgid "Left Control" +msgstr "" + +#: src/keycode.cpp:241 +msgid "Left Menu" +msgstr "" + +#: src/keycode.cpp:241 +msgid "Right Control" +msgstr "" + +#: src/keycode.cpp:241 +msgid "Right Menu" +msgstr "" + +#: src/keycode.cpp:243 +msgid "Comma" +msgstr "" + +#: src/keycode.cpp:243 +msgid "Minus" +msgstr "" + +#: src/keycode.cpp:243 +msgid "Period" +msgstr "" + +#: src/keycode.cpp:243 +msgid "Plus" +msgstr "" + +#: src/keycode.cpp:247 +msgid "Attn" +msgstr "" + +#: src/keycode.cpp:247 +msgid "CrSel" +msgstr "" + +#: src/keycode.cpp:248 +msgid "Erase OEF" +msgstr "" + +#: src/keycode.cpp:248 +msgid "ExSel" +msgstr "" + +#: src/keycode.cpp:248 +msgid "OEM Clear" +msgstr "" + +#: src/keycode.cpp:248 +msgid "PA1" +msgstr "" + +#: src/keycode.cpp:248 +msgid "Zoom" +msgstr "" + +#: src/main.cpp:1506 +msgid "Main Menu" +msgstr "" + +#: src/main.cpp:1830 +msgid "Failed to initialize world" +msgstr "" + +#: src/main.cpp:1842 +msgid "No world selected and no address provided. Nothing to do." +msgstr "" + +#: src/main.cpp:1850 +msgid "Could not find or load game \"" +msgstr "" + +#: src/main.cpp:1864 +msgid "Invalid gamespec." +msgstr "" + +#: src/main.cpp:1904 +msgid "Connection error (timed out?)" +msgstr "" + +#: src/main.cpp:1915 +msgid "" +"\n" +"Check debug.txt for details." +msgstr ""