Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign upItem access overhaul. (paving the way for item processing performance improvements) #10293
Conversation
kevingranade
added
(S2 - Confirmed)
in progress
and removed
(S2 - Confirmed)
labels
Dec 1, 2014
This comment has been minimized.
This comment has been minimized.
|
Having only read your comment, your function add_item() and it's inverse i_rem() seem like they should be named add_item() and rem_item() or i_add() and i_rem(). If you require I nitpick other negligibly small items, let me know! |
This comment has been minimized.
This comment has been minimized.
|
Eh, neither of them is new, I'm just inforcing their use, don't feel like doing a find/replace everywhere to fix that as pert of this. |
This comment has been minimized.
This comment has been minimized.
|
Is this ready for testing? |
This comment has been minimized.
This comment has been minimized.
|
Yes it's ready, behavior shouldn't change, this just paves the way for |
This comment has been minimized.
This comment has been minimized.
|
OK, it was marked in-progress and has merge conflicts. |
kevingranade
added
ready for merge
and removed
in progress
labels
Dec 5, 2014
kevingranade
added some commits
Nov 30, 2014
kevingranade
force-pushed the
kevingranade:i_at-overhaul
branch
to
fda5d5a
Dec 5, 2014
This comment has been minimized.
This comment has been minimized.
|
Rebased and ready to go again. |
KA101
self-assigned this
Dec 5, 2014
This comment has been minimized.
This comment has been minimized.
|
Running over caffeine pills with a car segfaults. Stack trace and relevant line: http://pastebin.com/hYw6rtKa |
KA101
removed their assignment
Dec 5, 2014
This comment has been minimized.
This comment has been minimized.
|
Two remarks: This creates dependencies: one has to supply the map and the coordinates several times ( Handling access and removal directly via the iterator seems simple for the user and avoids the redundancy. The get_item function seems strange, it returns the object which the iterator points to. This is usually done through a function of the iterator itself, not outside of it where it requires additional parameters. That function will also scale very poorly with an item list instead of a vector. Btw. the error KA101 found is in map.cpp:871 |
This comment has been minimized.
This comment has been minimized.
|
So, I'm way more knowledgeable with C than C++, so I have to ask... Seeing as how classes can be derived, could one inherit the std::vector (list, map, etc) and override some of the operators from the base class to do read only to prevent bypassing the cache, while also implementing add_item, i_at, etc. to said derived class? |
This comment has been minimized.
This comment has been minimized.
|
The goals of this change are to prevent insertion and removal of items from |
This comment has been minimized.
This comment has been minimized.
|
Another thing I forgot to mention: I think making map functions const is quite useless. All the code accesses either the reality bubble map ( Const functions in the game class are useless for the same reason, everybody has a non-const reference to the game anyway. DavidKeaton bough up a special class for the items vector. This could be used to implement a wrapper that is returned by class item_vector {
private:
std::vector<item> *vector;
int x, y;
map *map;
public:
// Than add all the main functions that `std::vector` has to item_vector:
size_t size() const { return vector->size(); }
bool empty() const { return vector->empty(); }
iterator erase(iterator it) const { return map->i_rem(x, y, it); }
iterator begin() const { return vector->begin(); }
iterator end() const { return vector->end(); }
const item &operator[](size_t index) const { return (*vector)[index]; }
};
item_vector map::i_at(int x, int y) {
submap *sm = ...;
return item_vector{ &sm->itm[...], x, y, this };
}The wrapper would nicely store the coordinates and the map, it can be copied and given to further functions. |
KA101
added
in progress
and removed
ready for merge
labels
Dec 5, 2014
This comment has been minimized.
This comment has been minimized.
|
Not that my say means much: I like the above wrapper illustrated. It functions similar to most/all basic std containers, and can be customized in a fashion to limit access to only your get/set methods. You could also easily add aliases to methods for contiguous namings sake, while also keeping the same method names for backcompat. The retval illustrated is a stack local (to the calling function) const "splice" of a portion of the map. Thus keeping its const-ness, yet having a lifetime in the calling function's stack for use in any other function. You could then make the map class a friend, able to access the pos and map, so you don't have to iterate over and over again, you could use indices/coords inside of the map pointer provided to make any changes. e.g. where i_rem, being part of map (a friend class to item_vector) could: void i_rem(item_vector iv) { Giving your god power to those who deserve it. Hell, if the std::vector in item_vector is a copy of the actual map item vector, the indices for specific items could be used in class map for removal, and for addition a simple insertion/append. This could also be used in a journalistic manner for the cache, where you simply add each i_at returned item_vector in an array type structure, make changes to those references alone (lessening access time via contiguous stack mem), then flush and shift the journal cache constantly based on char movement. Of course storing previous journal for a bit would help with PC retracing footseps. I apologize if this sounds like nonsense fyi, tired as hell. |
This comment has been minimized.
This comment has been minimized.
Making methods const isn't intended to "protect" the object itself per se, it's intended to document which methods refrain from modifying class internal state, and as a reminder to not change that (possibly unintentionally). The wrapper is a good idea, and looks like it will clean up some of the messier parts of the refactor, thanks :) |
This comment has been minimized.
This comment has been minimized.
|
Fixed crash, will be using this as a base for the interface change BevapDin suggested, so no reason to hold off on this one if it checks out (and accumulate more merge conflicts). |
kevingranade
added
ready for merge
and removed
in progress
labels
Dec 6, 2014
KA101
self-assigned this
Dec 6, 2014
KA101
merged commit 2b4091f
into
CleverRaven:master
Dec 6, 2014
1 check passed
kevingranade
removed
the
ready for merge
label
Dec 6, 2014
narc0tiq
referenced this pull request
Dec 24, 2014
Closed
SIGABRT after set fire in the basement. #10629
narc0tiq
reviewed
Jan 1, 2015
| @@ -1538,11 +1540,12 @@ void iexamine::fvat_empty(player *p, map *m, int examx, int examy) | |||
| } | |||
| add_msg(_("Set %s in the vat."), brew.tname().c_str()); | |||
| m->i_clear(examx, examy); | |||
| m->i_at(examx, examy).push_back(brew); //This is needed to bypass NOITEM | |||
| //This is needed to bypass NOITEM | |||
| m->add_item( examx, examy, brew ); | |||
This comment has been minimized.
This comment has been minimized.
narc0tiq
Jan 1, 2015
Contributor
Except map::add_item is too stupid to be used externally. It's, in fact, leading to http://smf.cataclysmdda.com/index.php?topic=9022.0. Is there a reason you didn't use map::add_item_or_charges?
kevingranade commentedDec 1, 2014
This big scary guy is overhauling the way we access items on the map.
The heart of it is that map::i_at() now returns a const item vector, which you can't just write to.
Instead you have to call map::add_item() or one of the helper methods to add items to the map, and i_rem() if you need to remove them.
This is important because in order to address the active item processing performance issues that have caused a bit of consternation recently, we need to build a cache of active items, and we can't have code bypassing the blessed interfaces for adding and removing items from the map.