Ejemplo n.º 1
0
 def maybe_remove_inst_seg(self, xyz):
     """remove any instance segmentation object where any adjacent block has changed"""
     # TODO make an archive.
     adj_xyz = util.diag_adjacent(xyz)
     deleted = {}
     for axyz in adj_xyz:
         m = self._db_read("SELECT uuid from InstSeg WHERE x=? AND y=? AND z=?", *axyz)
         for memid in m:
             if deleted.get(memid) is not None:
                 self._db_write("DELETE FROM Memories WHERE uuid=?", memid)
                 deleted[memid] = True
Ejemplo n.º 2
0
    def on_block_changed(self, xyz: XYZ, idm: IDM):
        if idm[0] == 0:
            # block removed
            tables = ["BlockObjects", "ComponentObjects"]
            for table in tables:
                memids = self.get_object_ids_by_xyz(xyz, table)
                if not memids:
                    return
                assert len(memids) == 1
                self._db_write(
                    "DELETE FROM {} WHERE x=? AND y=? AND z=?".format(table),
                    *xyz)
                if not self.check_memid_exists(memids[0], table):
                    # object is gone now
                    self.remove_memid_triple(memids[0])

        else:
            # block added
            interesting, player_placed = self._is_placed_block_interesting(
                xyz, idm[0])
            if not interesting:
                return

            adjacent_memids = set.union(*[
                set(self.get_block_object_ids_by_xyz(a))
                for a in util.diag_adjacent(xyz)
            ])

            if len(adjacent_memids) == 0:
                # new block object
                BlockObjectNode.create(self, [(xyz, idm)])
            elif len(adjacent_memids) == 1:
                # update block object
                memid = adjacent_memids.pop()
                self._upsert_block((xyz, idm), memid, "BlockObjects",
                                   player_placed)
            else:
                chosen_memid = list(adjacent_memids)[0]

                # merge tags
                where = " OR ".join(["subj=?"] * len(adjacent_memids))
                self._db_write("UPDATE Triples SET subj=? WHERE " + where,
                               chosen_memid, *adjacent_memids)

                # merge multiple block objects (will delete old ones)
                where = " OR ".join(["uuid=?"] * len(adjacent_memids))
                self._db_write("UPDATE BlockObjects SET uuid=? WHERE " + where,
                               chosen_memid, *adjacent_memids)

                # insert new block
                self._upsert_block((xyz, idm), chosen_memid, "BlockObjects",
                                   player_placed)
Ejemplo n.º 3
0
    def maybe_add_block_to_memory(self, xyz: XYZ, idm: IDM):
        interesting, player_placed, agent_placed = self._is_placed_block_interesting(
            xyz, idm[0])
        if not interesting:
            return

        adjacent = [
            self.get_object_info_by_xyz(a, "BlockObjects", just_memid=False)
            for a in util.diag_adjacent(xyz)
        ]

        if idm[0] == 0:
            # block removed / air block added
            adjacent_memids = [
                a[0][0] for a in adjacent if len(a) > 0 and a[0][1] == 0
            ]
        else:
            # normal block added
            adjacent_memids = [
                a[0][0] for a in adjacent if len(a) > 0 and a[0][1] > 0
            ]

        if len(adjacent_memids) == 0:
            # new block object
            BlockObjectNode.create(self, [(xyz, idm)])
        elif len(adjacent_memids) == 1:
            # update block object
            memid = adjacent_memids[0]
            self._upsert_block((xyz, idm), memid, "BlockObjects",
                               player_placed, agent_placed)
            self.set_memory_updated_time(memid)
        else:
            chosen_memid = adjacent_memids[0]
            self.set_memory_updated_time(chosen_memid)

            # merge tags
            where = " OR ".join(["subj=?"] * len(adjacent_memids))
            self._db_write("UPDATE Triples SET subj=? WHERE " + where,
                           chosen_memid, *adjacent_memids)

            # merge multiple block objects (will delete old ones)
            where = " OR ".join(["uuid=?"] * len(adjacent_memids))
            cmd = "UPDATE BlockObjects SET uuid=? WHERE "
            self._db_write(cmd + where, chosen_memid, *adjacent_memids)

            # insert new block
            self._upsert_block((xyz, idm), chosen_memid, "BlockObjects",
                               player_placed, agent_placed)
Ejemplo n.º 4
0
    def maybe_add_block_to_memory(self,
                                  xyz: XYZ,
                                  idm: IDM,
                                  agent_placed=False):
        if not agent_placed:
            interesting, player_placed, agent_placed = self.is_placed_block_interesting(
                xyz, idm[0])
        else:
            interesting = True
            player_placed = False
        if not interesting:
            return

        # TODO remove this, clean up
        if agent_placed:
            try:
                self.pending_agent_placed_blocks.remove(xyz)
            except:
                pass

        adjacent = [
            self.memory.get_object_info_by_xyz(a,
                                               "BlockObjects",
                                               just_memid=False)
            for a in util.diag_adjacent(xyz)
        ]

        if idm[0] == 0:
            # block removed / air block added
            adjacent_memids = [
                a[0][0] for a in adjacent if len(a) > 0 and a[0][1] == 0
            ]
        else:
            # normal block added
            adjacent_memids = [
                a[0][0] for a in adjacent if len(a) > 0 and a[0][1] > 0
            ]
        adjacent_memids = list(set(adjacent_memids))
        if len(adjacent_memids) == 0:
            # new block object
            BlockObjectNode.create(self.agent.memory, [(xyz, idm)])
        elif len(adjacent_memids) == 1:
            # update block object
            memid = adjacent_memids[0]
            self.memory.upsert_block((xyz, idm), memid, "BlockObjects",
                                     player_placed, agent_placed)
            self.memory.set_memory_updated_time(memid)
            self.memory.set_memory_attended_time(memid)
        else:
            chosen_memid = adjacent_memids[0]
            self.memory.set_memory_updated_time(chosen_memid)
            self.memory.set_memory_attended_time(chosen_memid)

            # merge tags
            where = " OR ".join(["subj=?"] * len(adjacent_memids))
            self.memory._db_write("UPDATE Triples SET subj=? WHERE " + where,
                                  chosen_memid, *adjacent_memids)

            # merge multiple block objects (will delete old ones)
            where = " OR ".join(["uuid=?"] * len(adjacent_memids))
            cmd = "UPDATE VoxelObjects SET uuid=? WHERE "
            self.memory._db_write(cmd + where, chosen_memid, *adjacent_memids)

            # insert new block
            self.memory.upsert_block((xyz, idm), chosen_memid, "BlockObjects",
                                     player_placed, agent_placed)