From e237c1d07d4a257329ba4db1631f40054510d445 Mon Sep 17 00:00:00 2001 From: Jürgen Doser Date: Tue, 22 Jan 2013 17:03:38 +0100 Subject: Fix crash when no world is selected and configure button is pressed. by moving return statement out of if-then-else clause... --- src/guiMainMenu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/guiMainMenu.cpp b/src/guiMainMenu.cpp index 77a5a85b8..68ee990cd 100644 --- a/src/guiMainMenu.cpp +++ b/src/guiMainMenu.cpp @@ -1048,8 +1048,8 @@ bool GUIMainMenu::OnEvent(const SEvent& event) GUIConfigureWorld *menu = new GUIConfigureWorld(env, parent, -1, menumgr, wspec); menu->drop(); - return true; } + return true; } case GUI_ID_SERVERLIST_DELETE: { gui::IGUIListBox *serverlist = (gui::IGUIListBox*)getElementFromId(GUI_ID_SERVERLIST); -- cgit v1.2.3 From 26a0efae2359334eb418f91bf85c0eae9db45646 Mon Sep 17 00:00:00 2001 From: Jürgen Doser Date: Tue, 22 Jan 2013 17:06:25 +0100 Subject: Improve behaviour for empty modpacks and when no mods at all are installed: Only show enable all / disable all buttons for all add-ons when at least one add-on is installed. When no add-on ist installed, don't show any buttons or checkboxes. Added is_modpack flag to ModSpec to distinguish empty modpacks from normal mods and check this flag in mod selection gui so that empty modpacks are not treated like mods that can be enabled or disabled. --- src/guiConfigureWorld.cpp | 62 ++++++++++++++++++++++++++++++----------------- src/mods.cpp | 5 ++-- src/mods.h | 3 +++ 3 files changed, 46 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/guiConfigureWorld.cpp b/src/guiConfigureWorld.cpp index a77697f8b..38f1a554d 100644 --- a/src/guiConfigureWorld.cpp +++ b/src/guiConfigureWorld.cpp @@ -69,15 +69,13 @@ GUIConfigureWorld::GUIConfigureWorld(gui::IGUIEnvironment* env, m_worldmods = flattenModTree(getModsInPath(worldmods_path)); // fill m_addontree with add-on mods - ModSpec addons("Add-Ons"); std::set paths = m_gspec.addon_mods_paths; for(std::set::iterator it=paths.begin(); it != paths.end(); ++it) { std::map mods = getModsInPath(*it); - addons.modpack_content.insert(mods.begin(), mods.end()); + m_addontree.insert(mods.begin(), mods.end()); } - m_addontree.insert(std::make_pair(addons.name,addons)); // expand modpacks m_addonmods = flattenModTree(m_addontree); @@ -116,7 +114,7 @@ GUIConfigureWorld::GUIConfigureWorld(gui::IGUIEnvironment* env, ModSpec mod = (*it).second; // a mod is new if it is not a modpack, and does not occur in // mod_names - if(mod.modpack_content.empty() && + if(!mod.is_modpack && mod_names.count(modname) == 0) m_new_mod_names.insert(modname); } @@ -253,7 +251,9 @@ void GUIConfigureWorld::regenerateGui(v2u32 screensize) rect += v2s32(220, 0) + topleft; m_treeview = Environment->addTreeView(rect, this, GUI_ID_MOD_TREEVIEW,true); - buildTreeView(m_addontree, m_treeview->getRoot()); + gui::IGUITreeViewNode* node + = m_treeview->getRoot()->addChildBack(L"Add-Ons"); + buildTreeView(m_addontree, node); } { core::rect rect(0, 0, 120, 30); @@ -407,8 +407,12 @@ bool GUIConfigureWorld::OnEvent(const SEvent& event) return true; } case GUI_ID_ENABLEALL: { - if(selected_node != NULL && selected_node->getText() != NULL) - { + if(selected_node != NULL && selected_node->getParent() == m_treeview->getRoot()) + { + enableAllMods(m_addonmods,true); + } + else if(selected_node != NULL && selected_node->getText() != NULL) + { std::string modname = wide_to_narrow(selected_node->getText()); ModSpec mod = m_addonmods[modname]; enableAllMods(mod.modpack_content,true); @@ -416,6 +420,10 @@ bool GUIConfigureWorld::OnEvent(const SEvent& event) return true; } case GUI_ID_DISABLEALL: { + if(selected_node != NULL && selected_node->getParent() == m_treeview->getRoot()) + { + enableAllMods(m_addonmods,false); + } if(selected_node != NULL && selected_node->getText() != NULL) { std::string modname = wide_to_narrow(selected_node->getText()); @@ -517,7 +525,7 @@ void GUIConfigureWorld::buildTreeView(std::map mods, gui::IGUITreeViewNode* new_node = node->addChildBack(narrow_to_wide(modname).c_str()); m_nodes.insert(std::make_pair(modname, new_node)); - if(!mod.modpack_content.empty()) + if(mod.is_modpack) buildTreeView(mod.modpack_content, new_node); else { @@ -552,23 +560,33 @@ void GUIConfigureWorld::adjustSidebar() modname_w = L"N/A"; std::string modname = wide_to_narrow(modname_w); - // if modpack, show enable/disable all buttons. otherwise, show - // enabled checkbox - if(node->hasChilds()) - { - m_enabled_checkbox->setVisible(false); - m_disableall->setVisible(true); - m_enableall->setVisible(true); - m_modname_text->setText((L"Modpack: "+modname_w).c_str()); - } - else + // if no mods installed, don't show buttons or checkbox on the sidebar + if(node->getParent() == m_treeview->getRoot() && !node->hasChilds()) { m_disableall->setVisible(false); m_enableall->setVisible(false); - m_enabled_checkbox->setVisible(true); - m_modname_text->setText((L"Mod: "+modname_w).c_str()); + m_enabled_checkbox->setVisible(false); + } + else + { + // if modpack, show enable/disable all buttons. otherwise, show + // enabled checkbox + if(node->getParent() == m_treeview->getRoot() || + m_addonmods[modname].is_modpack) + { + m_enabled_checkbox->setVisible(false); + m_disableall->setVisible(true); + m_enableall->setVisible(true); + m_modname_text->setText((L"Modpack: "+modname_w).c_str()); + } + else + { + m_disableall->setVisible(false); + m_enableall->setVisible(false); + m_enabled_checkbox->setVisible(true); + m_modname_text->setText((L"Mod: "+modname_w).c_str()); + } } - // the mod is enabled unless it is disabled in the world.mt settings. bool mod_enabled = true; if(m_settings.exists("load_mod_"+modname)) @@ -616,7 +634,7 @@ void GUIConfigureWorld::enableAllMods(std::map mods,bool e it != mods.end(); ++it) { ModSpec mod = (*it).second; - if(!mod.modpack_content.empty()) + if(mod.is_modpack) // a modpack, recursively enable all mods in it enableAllMods(mod.modpack_content,enable); else // not a modpack diff --git a/src/mods.cpp b/src/mods.cpp index 9e3c7d5d7..f6e3d58d7 100644 --- a/src/mods.cpp +++ b/src/mods.cpp @@ -46,6 +46,7 @@ std::map getModsInPath(std::string path) modpack_is.close(); // We don't actually need the file ModSpec spec(modname,modpath); spec.modpack_content = getModsInPath(modpath); + spec.is_modpack = true; result.insert(std::make_pair(modname,spec)); } else // not a modpack, add the modspec @@ -76,7 +77,7 @@ std::map flattenModTree(std::map mod it != mods.end(); ++it) { ModSpec mod = (*it).second; - if(!mod.modpack_content.empty()) //is a modpack + if(mod.is_modpack) { std::map content = flattenModTree(mod.modpack_content); @@ -98,7 +99,7 @@ std::vector flattenMods(std::map mods) it != mods.end(); ++it) { ModSpec mod = (*it).second; - if(!mod.modpack_content.empty()) //is a modpack + if(mod.is_modpack) { std::vector content = flattenMods(mod.modpack_content); result.reserve(result.size() + content.size()); diff --git a/src/mods.h b/src/mods.h index 37e2cd2db..59dffdade 100644 --- a/src/mods.h +++ b/src/mods.h @@ -53,6 +53,8 @@ struct ModSpec //if normal mod: std::set depends; std::set unsatisfied_depends; + + bool is_modpack; // if modpack: std::map modpack_content; ModSpec(const std::string name_="", const std::string path_="", @@ -61,6 +63,7 @@ struct ModSpec path(path_), depends(depends_), unsatisfied_depends(depends_), + is_modpack(false), modpack_content() {} }; -- cgit v1.2.3 From f214940c96d9fef72b06a65641d01115a582b098 Mon Sep 17 00:00:00 2001 From: Jürgen Doser Date: Tue, 22 Jan 2013 16:55:50 +0100 Subject: Fix crash when pressing delete button in server browser and no server is selected. A check for that was there, but was comparing an unsigned variable to -1, which doesn't work. --- src/guiMainMenu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/guiMainMenu.cpp b/src/guiMainMenu.cpp index 68ee990cd..9291bb4ec 100644 --- a/src/guiMainMenu.cpp +++ b/src/guiMainMenu.cpp @@ -1053,7 +1053,7 @@ bool GUIMainMenu::OnEvent(const SEvent& event) } case GUI_ID_SERVERLIST_DELETE: { gui::IGUIListBox *serverlist = (gui::IGUIListBox*)getElementFromId(GUI_ID_SERVERLIST); - u16 selected = ((gui::IGUIListBox*)serverlist)->getSelected(); + s32 selected = ((gui::IGUIListBox*)serverlist)->getSelected(); if (selected == -1) return true; ServerList::deleteEntry(m_data->servers[selected]); m_data->servers = ServerList::getLocal(); -- cgit v1.2.3 From f0998612457ddc3027618e7e446ed968a14385e7 Mon Sep 17 00:00:00 2001 From: Jürgen Doser Date: Tue, 22 Jan 2013 19:00:48 +0100 Subject: Make sure that settings are written to config file when settings are removed. Previously, settings where only written when a value has changed, and removal of a setting value didn't count as a change. --- src/settings.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/settings.h b/src/settings.h index 6d6db220c..2b46676c6 100644 --- a/src/settings.h +++ b/src/settings.h @@ -244,7 +244,9 @@ public: updated[name] = true; } - + else //file contains a setting which is not in m_settings + value_changed=true; + return true; } -- cgit v1.2.3 From 1163fdfa118636862997c40a32207e418c834f70 Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Wed, 23 Jan 2013 04:57:49 +0100 Subject: Treegen update. Some new symbols. Speed up code a bit. --- doc/lua_api.txt | 4 +- src/treegen.cpp | 126 +++++++++++++++++++++++++++++++++++++++++--------------- src/treegen.h | 27 +++++++----- 3 files changed, 112 insertions(+), 45 deletions(-) (limited to 'src') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index f935849ca..7ba2ed001 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1098,7 +1098,9 @@ treedef={ Key for Special L-System Symbols used in Axioms G - move forward one unit with the pen up F - move forward one unit with the pen down drawing trunks and branches - f - move forward one unit with the pen down drawing leaves + f - move forward one unit with the pen down drawing leaves (100% chance) + T - move forward one unit with the pen down drawing trunks only + R - move forward one unit with the pen down placing fruit A - replace with rules set A B - replace with rules set B C - replace with rules set C diff --git a/src/treegen.cpp b/src/treegen.cpp index 49f0666bc..7530843d3 100644 --- a/src/treegen.cpp +++ b/src/treegen.cpp @@ -1,7 +1,7 @@ /* Minetest-c55 Copyright (C) 2010-2012 celeron55, Perttu Ahola , - 2012 RealBadAngel, Maciej Kasatkin + 2012-2013 RealBadAngel, Maciej Kasatkin This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or @@ -118,7 +118,7 @@ void spawn_ltree (ServerEnvironment *env, v3s16 p0, INodeDefManager *ndef, TreeD core::map modified_blocks; ManualMapVoxelManipulator vmanip(map); v3s16 tree_blockp = getNodeBlockPos(p0); - vmanip.initialEmerge(tree_blockp - v3s16(1,1,1), tree_blockp + v3s16(1,2,1)); + vmanip.initialEmerge(tree_blockp - v3s16(1,1,1), tree_blockp + v3s16(1,3,1)); make_ltree (vmanip, p0, ndef, tree_definition); vmanip.blitBackAll(&modified_blocks); @@ -169,8 +169,11 @@ void make_ltree(ManualMapVoxelManipulator &vmanip, v3s16 p0, INodeDefManager *nd //initialize rotation matrix, position and stacks for branches core::matrix4 rotation; - rotation=setRotationAxisRadians(rotation, M_PI/2,v3f(0,0,1)); - v3f position = v3f(0,0,0); + rotation = setRotationAxisRadians(rotation, M_PI/2,v3f(0,0,1)); + v3f position; + position.X = p0.X; + position.Y = p0.Y; + position.Z = p0.Z; std::stack stack_orientation; std::stack stack_position; @@ -223,16 +226,16 @@ void make_ltree(ManualMapVoxelManipulator &vmanip, v3s16 p0, INodeDefManager *nd //make sure tree is not floating in the air if (tree_definition.trunk_type == "double") { - make_tree_node_placement(vmanip,v3f(p0.X+position.X+1,p0.Y+position.Y-1,p0.Z+position.Z),dirtnode); - make_tree_node_placement(vmanip,v3f(p0.X+position.X,p0.Y+position.Y-1,p0.Z+position.Z+1),dirtnode); - make_tree_node_placement(vmanip,v3f(p0.X+position.X+1,p0.Y+position.Y-1,p0.Z+position.Z+1),dirtnode); + tree_node_placement(vmanip,v3f(position.X+1,position.Y-1,position.Z),dirtnode); + tree_node_placement(vmanip,v3f(position.X,position.Y-1,position.Z+1),dirtnode); + tree_node_placement(vmanip,v3f(position.X+1,position.Y-1,position.Z+1),dirtnode); } if (tree_definition.trunk_type == "crossed") { - make_tree_node_placement(vmanip,v3f(p0.X+position.X+1,p0.Y+position.Y-1,p0.Z+position.Z),dirtnode); - make_tree_node_placement(vmanip,v3f(p0.X+position.X-1,p0.Y+position.Y-1,p0.Z+position.Z),dirtnode); - make_tree_node_placement(vmanip,v3f(p0.X+position.X,p0.Y+position.Y-1,p0.Z+position.Z+1),dirtnode); - make_tree_node_placement(vmanip,v3f(p0.X+position.X,p0.Y+position.Y-1,p0.Z+position.Z-1),dirtnode); + tree_node_placement(vmanip,v3f(position.X+1,position.Y-1,position.Z),dirtnode); + tree_node_placement(vmanip,v3f(position.X-1,position.Y-1,position.Z),dirtnode); + tree_node_placement(vmanip,v3f(position.X,position.Y-1,position.Z+1),dirtnode); + tree_node_placement(vmanip,v3f(position.X,position.Y-1,position.Z-1),dirtnode); } /* build tree out of generated axiom @@ -241,7 +244,9 @@ void make_ltree(ManualMapVoxelManipulator &vmanip, v3s16 p0, INodeDefManager *nd G - move forward one unit with the pen up F - move forward one unit with the pen down drawing trunks and branches - f - move forward one unit with the pen down drawing leaves + f - move forward one unit with the pen down drawing leaves (100% chance) + T - move forward one unit with the pen down drawing trunks only + R - move forward one unit with the pen down placing fruit A - replace with rules set A B - replace with rules set B C - replace with rules set C @@ -275,35 +280,54 @@ void make_ltree(ManualMapVoxelManipulator &vmanip, v3s16 p0, INodeDefManager *nd dir = transposeMatrix(rotation,dir); position+=dir; break; + case 'T': + tree_trunk_placement(vmanip,v3f(position.X,position.Y,position.Z),tree_definition); + if (tree_definition.trunk_type == "double" && !tree_definition.thin_branches) + { + tree_trunk_placement(vmanip,v3f(position.X+1,position.Y,position.Z),tree_definition); + tree_trunk_placement(vmanip,v3f(position.X,position.Y,position.Z+1),tree_definition); + tree_trunk_placement(vmanip,v3f(position.X+1,position.Y,position.Z+1),tree_definition); + } + if (tree_definition.trunk_type == "crossed" && !tree_definition.thin_branches) + { + tree_trunk_placement(vmanip,v3f(position.X+1,position.Y,position.Z),tree_definition); + tree_trunk_placement(vmanip,v3f(position.X-1,position.Y,position.Z),tree_definition); + tree_trunk_placement(vmanip,v3f(position.X,position.Y,position.Z+1),tree_definition); + tree_trunk_placement(vmanip,v3f(position.X,position.Y,position.Z-1),tree_definition); + } + dir = v3f(1,0,0); + dir = transposeMatrix(rotation,dir); + position+=dir; + break; case 'F': - make_tree_trunk_placement(vmanip,v3f(p0.X+position.X,p0.Y+position.Y,p0.Z+position.Z),tree_definition); + tree_trunk_placement(vmanip,v3f(position.X,position.Y,position.Z),tree_definition); if ((stack_orientation.empty() && tree_definition.trunk_type == "double") || (!stack_orientation.empty() && tree_definition.trunk_type == "double" && !tree_definition.thin_branches)) { - make_tree_trunk_placement(vmanip,v3f(p0.X+position.X+1,p0.Y+position.Y,p0.Z+position.Z),tree_definition); - make_tree_trunk_placement(vmanip,v3f(p0.X+position.X,p0.Y+position.Y,p0.Z+position.Z+1),tree_definition); - make_tree_trunk_placement(vmanip,v3f(p0.X+position.X+1,p0.Y+position.Y,p0.Z+position.Z+1),tree_definition); + tree_trunk_placement(vmanip,v3f(position.X+1,position.Y,position.Z),tree_definition); + tree_trunk_placement(vmanip,v3f(position.X,position.Y,position.Z+1),tree_definition); + tree_trunk_placement(vmanip,v3f(position.X+1,position.Y,position.Z+1),tree_definition); } if ((stack_orientation.empty() && tree_definition.trunk_type == "crossed") || (!stack_orientation.empty() && tree_definition.trunk_type == "crossed" && !tree_definition.thin_branches)) { - make_tree_trunk_placement(vmanip,v3f(p0.X+position.X+1,p0.Y+position.Y,p0.Z+position.Z),tree_definition); - make_tree_trunk_placement(vmanip,v3f(p0.X+position.X-1,p0.Y+position.Y,p0.Z+position.Z),tree_definition); - make_tree_trunk_placement(vmanip,v3f(p0.X+position.X,p0.Y+position.Y,p0.Z+position.Z+1),tree_definition); - make_tree_trunk_placement(vmanip,v3f(p0.X+position.X,p0.Y+position.Y,p0.Z+position.Z-1),tree_definition); + tree_trunk_placement(vmanip,v3f(position.X+1,position.Y,position.Z),tree_definition); + tree_trunk_placement(vmanip,v3f(position.X-1,position.Y,position.Z),tree_definition); + tree_trunk_placement(vmanip,v3f(position.X,position.Y,position.Z+1),tree_definition); + tree_trunk_placement(vmanip,v3f(position.X,position.Y,position.Z-1),tree_definition); } if (stack_orientation.empty() == false) { s16 size = 1; - for(x=-size; x0) { if (myrand_range(1,100) > 100-tree_definition.fruit_chance) @@ -413,6 +444,35 @@ void make_tree_leaves_placement(ManualMapVoxelManipulator &vmanip, v3f p0, vmanip.m_data[vmanip.m_area.index(p1)] = leavesnode; } +void tree_single_leaves_placement(ManualMapVoxelManipulator &vmanip, v3f p0, + TreeDef &tree_definition) +{ + MapNode leavesnode=tree_definition.leavesnode; + if (myrand_range(1,100) > 100-tree_definition.leaves2_chance) + leavesnode=tree_definition.leaves2node; + v3s16 p1 = v3s16(myround(p0.X),myround(p0.Y),myround(p0.Z)); + if(vmanip.m_area.contains(p1) == false) + return; + u32 vi = vmanip.m_area.index(p1); + if(vmanip.m_data[vi].getContent() != CONTENT_AIR + && vmanip.m_data[vi].getContent() != CONTENT_IGNORE) + return; + vmanip.m_data[vmanip.m_area.index(p1)] = leavesnode; +} + +void tree_fruit_placement(ManualMapVoxelManipulator &vmanip, v3f p0, + TreeDef &tree_definition) +{ + v3s16 p1 = v3s16(myround(p0.X),myround(p0.Y),myround(p0.Z)); + if(vmanip.m_area.contains(p1) == false) + return; + u32 vi = vmanip.m_area.index(p1); + if(vmanip.m_data[vi].getContent() != CONTENT_AIR + && vmanip.m_data[vi].getContent() != CONTENT_IGNORE) + return; + vmanip.m_data[vmanip.m_area.index(p1)] = tree_definition.fruitnode; +} + irr::core::matrix4 setRotationAxisRadians(irr::core::matrix4 M, double angle, v3f axis) { double c = cos(angle); diff --git a/src/treegen.h b/src/treegen.h index 1435d6bb2..cb365f4be 100644 --- a/src/treegen.h +++ b/src/treegen.h @@ -1,7 +1,7 @@ /* Minetest-c55 Copyright (C) 2010-2012 celeron55, Perttu Ahola , - 2012 RealBadAngel, Maciej Kasatkin + 2012-2013 RealBadAngel, Maciej Kasatkin This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or @@ -51,24 +51,29 @@ int fruit_chance; // Add default tree void make_tree(ManualMapVoxelManipulator &vmanip, v3s16 p0, - bool is_apple_tree, INodeDefManager *ndef); - + bool is_apple_tree, INodeDefManager *ndef); + // Add L-Systems tree (used by engine) void make_ltree(ManualMapVoxelManipulator &vmanip, v3s16 p0, INodeDefManager *ndef, TreeDef tree_definition); // Spawn L-systems tree from LUA - void spawn_ltree (ServerEnvironment *env, v3s16 p0, INodeDefManager *ndef, TreeDef tree_definition); - + void spawn_ltree (ServerEnvironment *env, v3s16 p0, INodeDefManager *ndef, + TreeDef tree_definition); + // L-System tree gen helper functions - void make_tree_node_placement(ManualMapVoxelManipulator &vmanip, v3f p0, + void tree_node_placement(ManualMapVoxelManipulator &vmanip, v3f p0, MapNode node); - void make_tree_trunk_placement(ManualMapVoxelManipulator &vmanip, v3f p0, + void tree_trunk_placement(ManualMapVoxelManipulator &vmanip, v3f p0, + TreeDef &tree_definition); + void tree_leaves_placement(ManualMapVoxelManipulator &vmanip, v3f p0, + TreeDef &tree_definition); + void tree_single_leaves_placement(ManualMapVoxelManipulator &vmanip, v3f p0, + TreeDef &tree_definition); + void tree_fruit_placement(ManualMapVoxelManipulator &vmanip, v3f p0, TreeDef &tree_definition); - void make_tree_leaves_placement(ManualMapVoxelManipulator &vmanip, v3f p0, - TreeDef &tree_definition); irr::core::matrix4 setRotationAxisRadians(irr::core::matrix4 M, double angle,v3f axis); - + v3f transposeMatrix(irr::core::matrix4 M ,v3f v); - + }; // namespace treegen #endif -- cgit v1.2.3