Project Orbiter StackEditor

Ok, after a (longish) break, I'm looking back over the code.

On the interface design end, I need to finish off "snapping" for vessel stacks. On that end, I noticed this horrendous function I wrote. I need some help refactoring it, if possible.
Code:
void VesselStack::checkForSnapping(std::vector<VesselSceneNode*>& vessels, bool dock)
{
  //loop over each node
  for (unsigned int nodeNum = 0; nodeNum < nodes.size(); nodeNum++)
  {
    //loop over empty docking ports on this node
    for (unsigned int i = 0; i < nodes[nodeNum]->dockingPorts.size(); i++)
    {
      if (nodes[nodeNum]->dockingPorts[i].docked == false)
      {
        //now, loop over the OTHER vessels (not equal to this node)
        //and see if it is close to another port's empty docking ports
        for (unsigned int j = 0; j < vessels.size(); j++)
        {
          //make sure this vessel isn't in our stack
          if (std::find(nodes.begin(), nodes.end(), vessels[j]) == nodes.end())
          {
            //check it's docking ports
            for (unsigned int k = 0; k < vessels[j]->dockingPorts.size(); k++)
            {
              //check if it is not docked, and they are within a certain distance
              if (!vessels[j]->dockingPorts[k].docked &&
                ((nodes[nodeNum]->getAbsolutePosition() + nodes[nodeNum]->returnRotatedVector(nodes[nodeNum]->dockingPorts[i].position)) -
                (vessels[j]->getAbsolutePosition() + vessels[j]->returnRotatedVector(vessels[j]->dockingPorts[k].position))
                ).getLengthSQ() < 16)
              {
                //snap it if dock=false, dock if dock=true
                if (!dock)
                  nodes[nodeNum]->snap(nodes[nodeNum]->dockingPorts[i], vessels[j]->dockingPorts[k]);
                else
                  nodes[nodeNum]->dock(nodes[nodeNum]->dockingPorts[i], vessels[j]->dockingPorts[k]);
              }

            }
          }
        }
      }
    }
  }
}

I'm no expert on algorithimic complexiety, but there are four for loops in there, which (might) mean that it runs in n^4 time. This function is called every time a stack is moved, and although it hasn't been a problem so far in my testing, it would surely crash if Dantassii got ahold if it :facepalm:

Here's what each level does, in order:
  1. For each individual vessel in the current VesselStack
  2. For each docking port on that vessel
  3. Check if the current docking port is free
  4. If so, for each vessel currently "in use" (in the scene)
  5. Check if each other vessel is not in our VesselStack (this prevents infinite docking loops)
  6. For each docking port in each vessel, not in our stack, see if it is empty, and within the "snapping" radius.
  7. Choose to dock or snap
 
Maybe you should first explain what you mean by "snapping".

Aternatively to your method, you could make collision spheres around the docking ports and let irrlicht handle the whole thing, savely shoving it off to the GPU.

I would really like to make more contributions to this, but although I would have some time every now and then, I just don't have the energy for focused work. The reason for that is screaming at me right now from its bed, and it's killing my nerves. I'm even too tired for gaming these days...

it would surely crash if Dantassii got ahold if it

To make it so Dantassii can't crash it is one of those worthy goals of legend, like the hunt for the golden fleece, the wooing of Brunhilde or the quest for the holy grail. I kind of wonder what would happen if Dantassii were ever to start playing galactic civilisations 2... :shifty:
 
Maybe you should first explain what you mean by "snapping".
Snapping is what happens when you drag one stack near another stack, and they "jump" together, as if they were actually connected. It's basically a UI aid to help construction.

Aternatively to your method, you could make collision spheres around the docking ports and let irrlicht handle the whole thing, savely shoving it off to the GPU.
That's a great idea. My system is effectively doing that, just in a completely un-optimized way. It's effectively checking if the two docking ports are within 4 Irrlicht units. That's a good idea to let Irrlicht do the hard work; it probably has a nice quad-tree implementation or something for collisions. :tiphat:



To make it so Dantassii can't crash it is one of those worthy goals of legend, like the hunt for the golden fleece, the wooing of Brunhilde or the quest for the holy grail.
We can always hope :lol:
 
Version 1.0.1 released! :)

Changelist
  • Full featured undo/redo
  • Full import and export to and from Orbiter
  • User customizable toolboxes
  • Full stack features - split, copy, move, etc
  • Session loading/saving, so you can come back to your work later
  • Many, many, many bugfixes

More information added to header post.
 
As suggested, here's my scenario with the radiator using dock 2:


BEGIN_DESC
END_DESC

BEGIN_ENVIRONMENT
System Sol
Date MJD 51982.1085842295
END_ENVIRONMENT

BEGIN_FOCUS
Ship f_a
END_FOCUS

BEGIN_CAMERA
TARGET f_a_11
MODE Extern
POS 3.37 37.57 33.09
TRACKMODE TargetRelative
FOV 50.00
END_CAMERA

BEGIN_HUD
TYPE Docking
NAV 0
END_HUD

BEGIN_SHIPS
f_a:IMS\COMMAND_MODULES\BM201_CONTROL_MODULE
STATUS Orbiting Earth
RPOS 7006581.32 0.00 146417.04
RVEL -157.565 -0.000 7540.039
AROT 0.00 -0.00 0.00
AFCMODE 7
PRPLEVEL 0:1.000000 1:1.000000 2:1.000000
DOCKINFO 0:0,f_a_1 1:0,f_a_15
NAVFREQ 0 0
COMMAND 0 1
EMPTYMASS 10000.000000
MASSCENTER 0.000000 0.000000 0.000000
PMI 8.150000 8.150000 2.300000
CONSUMABLES 0.0001 0.0001 0 0.0001 0.0001 0 0.0001 0.0001 0
TEMPERATURES -1:298.00:273.69
HEATING -1
THGROUPLEVELS 0 0 0 0
CREW 2 0
ENERGY 396000000.000000
MFC 0 0 0 -1 -1 -1 -1
MFC 0 0 0 -1 -1 -1 -1
MFC 0 0 0 -1 -1 -1 -1
MFC 0 0 0 -1 -1 -1 -1
MFC 0 0 0 -1 -1 -1 -1
MFC 0 0 0 -1 -1 -1 -1
MFC 0 0 0 -1 -1 -1 -1
MFC 0 0 0 -1 -1 -1 -1
MFC 0 0 0 -1 -1 -1 -1
MFC 0 0 0 -1 -1 -1 -1
MFC 0 0 0 -1 -1 -1 -1
MFC 0 0 0 -1 -1 -1 -1
MFC 0 0 0 -1 -1 -1 -1
MFC 0 0 0 -1 -1 -1 -1
END
f_a_1:IMS\NODES\BN301_TRUSSED_NODE
STATUS Orbiting Earth
RPOS 7006581.32 0.00 146424.32
RVEL -157.565 -0.000 7540.039
AROT -90.00 0.00 90.00
AFCMODE 7
DOCKINFO 0:0,f_a 2:4,f_a_2 5:1,f_a_14
NAVFREQ 0 0
END
f_a_2:IMS\TRUSS_PARTS\BT201_TRUSS_TO_MODULE_ADAPTER
STATUS Orbiting Earth
RPOS 7006585.76 0.00 146424.32
RVEL -157.565 -0.000 7540.039
AROT -90.00 0.00 90.00
AFCMODE 7
DOCKINFO 0:4,f_a_3 1:5,f_a_6 2:1,f_a_12 3:0,f_a_13 4:2,f_a_1
NAVFREQ 0 0
END
f_a_3:IMS\TRUSS_PARTS\BT101_TRUSS
STATUS Orbiting Earth
RPOS 7006586.82 -10.08 146424.32
RVEL -157.565 -0.000 7540.039
AROT 90.00 -0.00 -0.00
AFCMODE 7
DOCKINFO 0:0,f_a_4 1:0,f_a_5 4:0,f_a_2
NAVFREQ 0 0
END
f_a_4:IMS\PROPULSION\BRCS1_REACTIONCONTROLSYSTEM_ENGINE
STATUS Orbiting Earth
RPOS 7006588.31 -10.08 146424.32
RVEL -157.565 -0.000 7540.039
AROT -178.39 1.#R 178.39
AFCMODE 7
DOCKINFO 0:0,f_a_3
NAVFREQ 0 0
END
f_a_5:IMS\PROPULSION\BRCS1_REACTIONCONTROLSYSTEM_ENGINE
STATUS Orbiting Earth
RPOS 7006585.33 -10.08 146424.32
RVEL -157.565 -0.000 7540.039
AROT 1.61 1.#R 1.61
AFCMODE 7
DOCKINFO 0:1,f_a_3
NAVFREQ 0 0
END
f_a_6:IMS\TRUSS_PARTS\BT101_TRUSS
STATUS Orbiting Earth
RPOS 7006586.82 10.08 146424.32
RVEL -157.565 -0.000 7540.039
AROT 90.00 -0.00 -0.00
AFCMODE 7
DOCKINFO 0:0,f_a_7 1:0,f_a_8 3:0,f_a_9 4:1,f_a_10 5:1,f_a_2
NAVFREQ 0 0
END
f_a_7:IMS\PROPULSION\BRCS1_REACTIONCONTROLSYSTEM_ENGINE
STATUS Orbiting Earth
RPOS 7006588.31 10.08 146424.32
RVEL -157.565 -0.000 7540.039
AROT -178.39 1.#R 178.39
AFCMODE 7
DOCKINFO 0:0,f_a_6
NAVFREQ 0 0
END
f_a_8:IMS\PROPULSION\BRCS3_METHANE_RCS_ENGINE
STATUS Orbiting Earth
RPOS 7006585.33 10.08 146424.32
RVEL -157.565 -0.000 7540.039
AROT 1.61 1.#R 1.61
AFCMODE 7
DOCKINFO 0:1,f_a_6
NAVFREQ 0 0
END
f_a_9:IMS\COMMUNICATIONS\BCM101_ANTENNA
STATUS Orbiting Earth
RPOS 7006586.82 10.08 146426.48
RVEL -157.565 -0.000 7540.039
AROT 1.61 90.00 -88.39
AFCMODE 7
DOCKINFO 0:3,f_a_6
NAVFREQ 0 0
END
f_a_10:IMS\POWER_GENERATION\BP101_SOLAR_PANEL
STATUS Orbiting Earth
RPOS 7006586.82 17.30 146420.21
RVEL -157.565 -0.000 7540.039
AROT 0.00 -0.00 90.00
AFCMODE 7
DOCKINFO 0:1,f_a_11 1:4,f_a_6
NAVFREQ 0 0
END
f_a_11:IMS\RADIATORS\BR101_RADIATOR
STATUS Orbiting Earth
RPOS 7006586.82 19.10 146425.40
RVEL -157.565 -0.000 7540.039
AROT -90.00 0.00 -180.00
AFCMODE 7
DOCKINFO 1:0,f_a_10
NAVFREQ 0 0
END
f_a_12:IMS\BATTERIES\BG201_BATTERY_SCONTAINER
STATUS Orbiting Earth
RPOS 7006586.82 0.00 146421.93
RVEL -157.565 -0.000 7540.039
AROT -90.00 0.00 -180.00
AFCMODE 7
DOCKINFO 1:2,f_a_2
NAVFREQ 0 0
END
f_a_13:IMS\FUEL_TANKAGE\BTANK202_LOX_LH2_SFUELTANK
STATUS Orbiting Earth
RPOS 7006586.82 0.00 146426.54
RVEL -157.565 -0.000 7540.039
AROT -180.00 0.00 -90.00
AFCMODE 7
PRPLEVEL 0:1.000000
DOCKINFO 0:3,f_a_2
NAVFREQ 0 0
END
f_a_14:IMS\CONSUMABLES\BM011_CONSUMABLES
STATUS Orbiting Earth
RPOS 7006581.32 4.58 146424.32
RVEL -157.565 -0.000 7540.039
AROT 90.00 -0.00 -90.00
AFCMODE 7
DOCKINFO 1:5,f_a_1
NAVFREQ 0 0
END
f_a_15:IMS\DOCKING_PORTS\DAAPAS_DOCKING_ADAPTER
STATUS Orbiting Earth
RPOS 7006581.32 0.00 146411.96
RVEL -157.565 -0.000 7540.039
AROT -180.00 0.00 90.00
AFCMODE 7
DOCKINFO 0:1,f_a
NAVFREQ 0 0
END
END_SHIPS






And here's the Stackeditor session:


VERSION = 1
VESSEL_BEGIN
FILE = ims\power_generation\bp101_solar_panel.cfg
POS = -24.4754 7.7696 -5.1709
ROT = 360 360 1.61649e-005
UID = 0
VESSEL_END
VESSEL_BEGIN
FILE = ims\truss_parts\bt101_truss.cfg
POS = -17.2519 7.7696 -1.06378
ROT = 270 360 90
UID = 1
VESSEL_END
VESSEL_BEGIN
FILE = ims\truss_parts\bt201_truss_to_module_adapter.cfg
POS = -7.17588 6.70969 -1.06378
ROT = 0 90 6.14694e-006
UID = 3
VESSEL_END
VESSEL_BEGIN
FILE = ims\nodes\bn301_trussed_node.cfg
POS = -7.17588 2.26529 -1.06378
ROT = 0 90 4.32571e-006
UID = 4
VESSEL_END
VESSEL_BEGIN
FILE = ims\command_modules\bm201_control_module.cfg
POS = -7.17588 2.26529 -8.33982
ROT = 5.00896e-006 5.97312e-014 90
UID = 5
VESSEL_END
VESSEL_BEGIN
FILE = ims\consumables\bm011_consumables.cfg
POS = -11.7515 2.26529 -1.06378
ROT = 0 90 180
UID = 6
VESSEL_END
VESSEL_BEGIN
FILE = ims\communications\bcm101_antenna.cfg
POS = -17.2519 7.7696 1.10581
ROT = 270 360 180
UID = 8
VESSEL_END
VESSEL_BEGIN
FILE = ims\radiators\br101_radiator.cfg
POS = -26.2753 7.7696 0.0196772
ROT = 270 7.51343e-006 270
UID = 9
VESSEL_END
VESSEL_BEGIN
FILE = ims\batteries\bg201_battery_scontainer.cfg
POS = -7.17588 7.7696 -3.45217
ROT = 270 2.50448e-006 270
UID = 10
VESSEL_END
VESSEL_BEGIN
FILE = ims\docking_ports\daapas_docking_adapter.cfg
POS = -7.17588 2.26529 -13.4159
ROT = 180 360 180
UID = 11
VESSEL_END
VESSEL_BEGIN
FILE = ims\fuel_tankage\btank202_lox_lh2_sfueltank.cfg
POS = -7.17588 7.7696 1.16406
ROT = 180 360 6.83019e-006
UID = 12
VESSEL_END
VESSEL_BEGIN
FILE = ims\truss_parts\bt101_truss.cfg
POS = 2.90017 7.7696 -1.06378
ROT = 270 360 90
UID = 13
VESSEL_END
VESSEL_BEGIN
FILE = ims\propulsion\brcs3_methane_rcs_engine.cfg
POS = -17.2519 6.28086 -1.06378
ROT = 0 270 90
UID = 14
VESSEL_END
VESSEL_BEGIN
FILE = ims\propulsion\brcs1_reactioncontrolsystem_engine.cfg
POS = -17.2519 9.25834 -1.06378
ROT = 0 90 90
UID = 15
VESSEL_END
VESSEL_BEGIN
FILE = ims\propulsion\brcs1_reactioncontrolsystem_engine.cfg
POS = 2.90017 9.25834 -1.06378
ROT = 0 90 90
UID = 16
VESSEL_END
VESSEL_BEGIN
FILE = ims\propulsion\brcs1_reactioncontrolsystem_engine.cfg
POS = 2.90017 6.28086 -1.06378
ROT = 0 270 90
UID = 17
VESSEL_END
DOCKINFO = 9:1 1:4 -1:-1 15:0 14:0 -1:-1 8:0 0:1 3:1 13:4 1:5 10:1 12:0 4:2 -1:-1 5:0 -1:-1 3:4 -1:-1 -1:-1 6:1 4:0 11:0 -1:-1 4:5 1:3 -1:-1 -1:-1 0:0 -1:-1 3:2 5:1 -1:-1 3:3 -1:-1 16:0 17:0 -1:-1 -1:-1 3:0 -1:-1 1:1 1:0 13:0 13:1
 
Hasn't got anything to do with stack editor, and only peripherally with IMS: the radiators simply has no attachment point at its second dockport declared in the config file. Whether that was a concious decision or an oversight by the one who wrote the file I'm not sure. If you really need the other dockport on those radiators, you can add the following line to the attachment point block in the BR101_Radiator.cfg:

Code:
P      0 0 1.799942    0 1 0    -1 0 0     IM
 
Hi I just downloaded it and run it but it give me this error "he is dead Jim" can you help me??
 
Back
Top