Skip to content

Commit f6e659d

Browse files
committed
moved functions in blockContainer to cpp and bottom of file
1 parent 33515f3 commit f6e659d

File tree

2 files changed

+38
-30
lines changed

2 files changed

+38
-30
lines changed

src/backend/container/blockContainer.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,19 @@ void BlockContainer::removeBlockCells(const Block* block) {
283283
}
284284
}
285285
}
286+
287+
Difference BlockContainer::getCreationDifference() const {
288+
Difference difference;
289+
for (auto iter : blocks) {
290+
difference.addPlacedBlock(iter.second.getPosition(), iter.second.getRotation(), iter.second.type());
291+
}
292+
for (auto iter : blocks) {
293+
for (connection_end_id_t id = 0; id <= iter.second.getConnectionContainer().getMaxConnectionId(); id++) {
294+
if (iter.second.isConnectionInput(id)) continue;
295+
for (auto connectionIter : iter.second.getConnectionContainer().getConnections(id)) {
296+
difference.addCreatedConnection(iter.second.getConnectionPosition(id).first, getBlock(connectionIter.getBlockId())->getConnectionPosition(connectionIter.getConnectionId()).first);
297+
}
298+
}
299+
}
300+
return difference;
301+
}

src/backend/container/blockContainer.h

+22-30
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,12 @@ class BlockContainer {
4949
bool trySetBlockData(const Position& positionOfBlock, block_data_t data);
5050
// Sets the data value to a block at position. Returns if block found. Pass a Difference* to read the what changes were made.
5151
template<class T, unsigned int index>
52-
bool trySetBlockDataValue(const Position& positionOfBlock, T value) {
53-
Block* block = getBlock(positionOfBlock);
54-
if (!block) return false;
55-
block->setDataValue<T, index>(value);
56-
return true;
57-
}
52+
bool trySetBlockDataValue(const Position& positionOfBlock, T value);
5853
// Sets the data to a block at position. Returns if successful. Pass a Difference* to read the what changes were made.
5954
bool trySetBlockData(const Position& positionOfBlock, block_data_t data, Difference* difference);
6055
// Sets the data value to a block at position. Returns if block found. Pass a Difference* to read the what changes were made.
6156
template<class T, unsigned int index>
62-
bool trySetBlockDataValue(const Position& positionOfBlock, T value, Difference* difference) {
63-
Block* block = getBlock(positionOfBlock);
64-
if (!block) return false;
65-
block_data_t oldData = block->getRawData();
66-
block->setDataValue<T, index>(value);
67-
block_data_t newData = block->getRawData();
68-
if (oldData != newData) difference->addSetData(positionOfBlock, newData, oldData);
69-
return true;
70-
}
57+
bool trySetBlockDataValue(const Position& positionOfBlock, T value, Difference* difference);
7158

7259
/* ----------- connections ----------- */
7360
// -- getters --
@@ -97,21 +84,7 @@ class BlockContainer {
9784
const_iterator end() const { return blocks.end(); }
9885

9986
/* Difference Getter */
100-
Difference getCreationDifference() const {
101-
Difference difference;
102-
for (auto iter : blocks) {
103-
difference.addPlacedBlock(iter.second.getPosition(), iter.second.getRotation(), iter.second.type());
104-
}
105-
for (auto iter : blocks) {
106-
for (connection_end_id_t id = 0; id <= iter.second.getConnectionContainer().getMaxConnectionId(); id++) {
107-
if (iter.second.isConnectionInput(id)) continue;
108-
for (auto connectionIter : iter.second.getConnectionContainer().getConnections(id)) {
109-
difference.addCreatedConnection(iter.second.getConnectionPosition(id).first, getBlock(connectionIter.getBlockId())->getConnectionPosition(connectionIter.getConnectionId()).first);
110-
}
111-
}
112-
}
113-
return difference;
114-
}
87+
Difference getCreationDifference() const;
11588

11689
private:
11790
inline Block* getBlock(const Position& position);
@@ -149,4 +122,23 @@ inline const Block* BlockContainer::getBlock(block_id_t blockId) const {
149122
return (iter == blocks.end()) ? nullptr : &iter->second;
150123
}
151124

125+
template<class T, unsigned int index>
126+
bool BlockContainer::trySetBlockDataValue(const Position& positionOfBlock, T value) {
127+
Block* block = getBlock(positionOfBlock);
128+
if (!block) return false;
129+
block->setDataValue<T, index>(value);
130+
return true;
131+
}
132+
133+
template<class T, unsigned int index>
134+
bool BlockContainer::trySetBlockDataValue(const Position& positionOfBlock, T value, Difference* difference) {
135+
Block* block = getBlock(positionOfBlock);
136+
if (!block) return false;
137+
block_data_t oldData = block->getRawData();
138+
block->setDataValue<T, index>(value);
139+
block_data_t newData = block->getRawData();
140+
if (oldData != newData) difference->addSetData(positionOfBlock, newData, oldData);
141+
return true;
142+
}
143+
152144
#endif /* blockContainer_h */

0 commit comments

Comments
 (0)