Skip to content

Commit

Permalink
Wires are now logical groups (internally) #62
Browse files Browse the repository at this point in the history
  • Loading branch information
tatjam committed Aug 26, 2023
1 parent 1bf4647 commit ce28611
Show file tree
Hide file tree
Showing 13 changed files with 257 additions and 201 deletions.
2 changes: 1 addition & 1 deletion res/core/shaders/light/part_icon.fs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void main()

// Env mapping
vec3 specular; //< set by get_ambient
vec3 ambient = get_ambient(FragPos, Normal, Albedo, Roughness, Metallic, irradiance_map, specular_map, brdf_map, specular);
vec3 ambient = get_ambient(FragPos, Normal, Albedo, Roughness, Metallic, Emissive, irradiance_map, specular_map, brdf_map, specular);

vec3 fcolor = lo * color + emit + (specular + ambient) * Occlussion;

Expand Down
14 changes: 7 additions & 7 deletions src/game/scenes/editor/interfaces/WireInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ bool WireInterface::do_machine(NVGcontext* vg, GUIInput* gui_input, Machine* m,
if((gui_input->mouse_down(GUI_LEFT_BUTTON) && is_hovered) || selected == m)
{
selected = m;
selected_wired = m->get_all_wired_machines(false);
selected_wired = editing->get_all_connected(m, false);
nvgFillColor(vg, nvgRGB(255, 255, 255));
}
else
Expand All @@ -335,21 +335,21 @@ bool WireInterface::do_machine(NVGcontext* vg, GUIInput* gui_input, Machine* m,
if(gui_input->mouse_down(GUI_RIGHT_BUTTON))
{
// We have to do two iterations
auto sel_to_m = edveh->veh->wires.equal_range(selected);
auto m_to_sel = edveh->veh->wires.equal_range(m);
auto sel_to_m = editing->connections.equal_range(selected);
auto m_to_sel = editing->connections.equal_range(m);
for(auto i = sel_to_m.first; i != sel_to_m.second; i++)
{
if(i->second == m)
{
edveh->veh->wires.erase(i);
editing->connections.erase(i);
break;
}
}
for(auto i = m_to_sel.first; i != m_to_sel.second; i++)
{
if(i->second == selected)
{
edveh->veh->wires.erase(i);
editing->connections.erase(i);
break;
}
}
Expand All @@ -362,8 +362,8 @@ bool WireInterface::do_machine(NVGcontext* vg, GUIInput* gui_input, Machine* m,
nvgStrokeColor(vg, nvgRGB(0, 255, 0));
if(gui_input->mouse_down(GUI_RIGHT_BUTTON))
{
edveh->veh->wires.insert(std::make_pair(selected, m));
edveh->veh->wires.insert(std::make_pair(m, selected));
editing->connections.insert(std::make_pair(selected, m));
editing->connections.insert(std::make_pair(m, selected));
}
else
{
Expand Down
3 changes: 3 additions & 0 deletions src/game/scenes/editor/interfaces/WireInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class EditorVehicleInterface;
class WireInterface : public BaseInterface
{
private:

LogicalGroup* editing;

EditorVehicle* edveh;
EditorScene* scene;
EditorVehicleInterface* edveh_int;
Expand Down
83 changes: 43 additions & 40 deletions src/lua/libs/LuaVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,50 +211,53 @@ void LuaVehicle::load_to(sol::table& table)
self->load_interface(sane_name, n_table);
return n_table;
},
"get_all_wired_machines", sol::overload([](Machine& self)
{
return self.get_all_wired_machines();
},
[](Machine& self, bool include_this)
{
return self.get_all_wired_machines(include_this);
}),
"get_wired_machines_with", [](Machine& self, sol::variadic_args args)
{
// We build the vector, something which sol cannot do automatically
// and also find any 'false' value which sets include_this to false
std::vector<std::string> vec;
bool include_this = true;
for(auto arg : args)
{
if(arg.get_type() == sol::type::boolean)
{
if(arg.get<bool>() == false)
{
include_this = false;
}
}
else if(arg.get_type() == sol::type::string)
{
vec.push_back(arg.get<std::string>());
}
}

return self.get_wired_machines_with(vec, include_this);
},
"get_wired_interfaces",
sol::overload([](Machine& self, const std::string& int_type, bool include_this)
{
return self.get_wired_interfaces(int_type, include_this);
},
[](Machine& self, const std::string& int_type)
{
return self.get_wired_interfaces(int_type);
}),
"get_interface", &Machine::get_interface

);

table.new_usertype<LogicalGroup>("logical_group", sol::no_constructor,
"get_connected_with", [](const LogicalGroup& self, Machine* to, sol::variadic_args args)
{
// We build the vector, something which sol cannot do automatically
// and also find any 'false' value which sets include_this to false
std::vector<std::string> vec;
bool include_this = true;
for(auto arg : args)
{
if(arg.get_type() == sol::type::boolean)
{
if(arg.get<bool>() == false)
{
include_this = false;
}
}
else if(arg.get_type() == sol::type::string)
{
vec.push_back(arg.get<std::string>());
}
}

return self.get_connected_with(to, vec, include_this);
},
"get_connected_interfaces",
sol::overload([](const LogicalGroup& self, Machine* to, const std::string& int_type, bool include_to)
{
return self.get_connected_interfaces(to, int_type, include_to);
},
[](const LogicalGroup& self, Machine* to, const std::string& int_type)
{
return self.get_connected_interfaces(to, int_type);
}),
"get_all_connected", sol::overload([](const LogicalGroup& self, Machine* to)
{
return self.get_all_connected(to);
},
[](const LogicalGroup& self, Machine* to, bool include_this)
{
return self.get_all_connected(to, include_this);
})
);

table.new_usertype<PartPrototype>("part_prototype", sol::no_constructor,
"name", &PartPrototype::name);

Expand Down
20 changes: 12 additions & 8 deletions src/universe/vehicle/Vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,20 @@ void Vehicle::remove_outdated()
}
}

// Some machines may have gone missing
for(auto it = wires.begin(); it != wires.end();)
// Some logical connections my have been cut
for(auto& pair : logical_groups)
{
if(!find_machine(it->first, this) || !find_machine(it->second, this))
LogicalGroup* g = pair.second;
for (auto it = g->connections.begin(); it != g->connections.end();)
{
it = wires.erase(it);
}
else
{
it++;
if (!find_machine(it->first, this) || !find_machine(it->second, this))
{
it = g->connections.erase(it);
}
else
{
it++;
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/universe/vehicle/Vehicle.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include "part/Part.h"
#include "part/Piece.h"
#include "connections/LogicalGroup.h"

#pragma warning(push, 0)
#include <btBulletDynamicsCommon.h>
Expand Down Expand Up @@ -118,8 +119,8 @@ class Vehicle : public EventEmitter
// Parts whose root piece is contained in this vehicle
std::vector<Part*> parts;

// Bidirectional wires, so if A is connected to B then B is connected to A
std::unordered_multimap<Machine*, Machine*> wires;
std::unordered_map<std::string, LogicalGroup*> logical_groups;


// These return nullptr if the part / piece is no longer present in this vehicle
Part* get_part_by_id(int64_t id);
Expand Down
Loading

0 comments on commit ce28611

Please sign in to comment.