-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor!: give items identity (#2250)
* Temp commit, now with compiling * More refactoring * vehicles fix * More bugfixes and the start of the test suite * More bugfixes * More bugfixes * Beginning of better types * More new stuff, no compiling * More moving to smart pointers * Bit more * More more more * MOAR * More * even more * style: typo `item_spawn` -> `item::spawn` * style: remove unnecessary `std::move`, use `->` for activity applied clang-tidy to fix `-Wpessimizing-move`, and activiy being changed to pointer Co-authored-by: jove <[email protected]> * fix: legacy null item reference Co-authored-by: jove <[email protected]> * docs: return type of reduce_charges * style: astyle * Now with compiling * More fixes * More fixes * Pre-merge commit, fairly stable now * Round out interfaces * Better vehicles and cleanup * Remove traces and better destruction * Attempt to appease gcc with vectors * Pretty sure this wasn't me but ok * ty clang tidy * Oh yeah sounds exist * bug fix * Remove unused overmap constructors as they fail on some compilers * Backwards compat * Test suite compiles now * MOAR * More more more * Test suite passes * Bad move * Fix missing super character constructors * Update init.cpp * Update src/init.cpp Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/init.cpp Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update init.cpp * Remove unused stuff * And the missed use * Remove execinfo.h * Bugs * Fix map rotation * Fix failed wrecks * More bugfixes * Various bugs * More bugfixes * Fix disassembly * Fix dead removals * Back to late delete for now * Missing property in constructor * Activity fix * More safety * style: format with code blocks * ups * Update crafting.cpp * More fixes * More fixes * Forgot to add a file * Fix rotation offsets * Appease gcc * Fixup android * minor fixes * weapon charges fix * Fix monsters * Remove old rotation offsets * Fixes * minor safety, needs investigating * Fixes * cleanup * pch fix and more cleanup * merge * Fix msvc * Fix spacing, remove unused includes * Remove npc.h include from locations.h * Remove leftovers from item_location * Remove old commented code * Remove player_activity.h from json.h * Split off activity_ptr into its own header * Fix typos * Remove commented out or dead code * Fix tidy warnings * Remove colony from update-pch.sh * Hopefully this fixes the compile * build fixes * Wrap long comments * Fix typo * Delete submodule * Alternative build fix * Fix dereferencing nullptr * Remove extra space * Remove dead code * Update src/detached_ptr.cpp Co-authored-by: Olanti <[email protected]> * Update src/activity_actor.cpp Co-authored-by: Olanti <[email protected]> * Update src/active_tile_data.cpp Co-authored-by: Olanti <[email protected]> * Update src/handle_liquid.h Co-authored-by: Olanti <[email protected]> * Update src/active_tile_data.cpp Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Fix takeoff deleting items * Fixes * Liquid fix * Fix book crash * fix holsters * missed a spot * fix: make it compile * Mess with lua iterators * Fixes * fix: iexamine_elevator * fix: `vehicle_part.h` headers * fix: salvage by weight PR * docs: game objects * fix: salvage test * style(autofix.ci): automated formatting * submap rotate fixes * Shouldn't use uint * And the rest * Fix destroyed things being processed * Fix armor relayering * fix gcc * style(autofix.ci): automated formatting * Fix filthy clothes * Fix butchering * Random iterator safety fixes * refactor: trailing return goes brrrrr * refactor: apply clang-tidy suggestions * perf: remove obsoleted colony tests * perf: apply all clang-tidy performance fixes * perf: use `emplace_back` * fix: position loopback segfaulting * fix: keep location info on `attempt_detach` * perf: remove flag usage for temperature display * feat: give morale bonus for items `EATEN_COLD` * Better position through attempt_detach * Update game_object.cpp * Update rot.cpp * style(autofix.ci): automated formatting * Fix things rotting away * Fix null cache references being moved badly * style(autofix.ci): automated formatting * Fix ub when active item list is empty * Prevents possible use after free in sounds * Appease windows compilers noexcept * Bunch of cleanup * Proper move for lambda arg/return * style(autofix.ci): automated formatting * tidy * style(autofix.ci): automated formatting * Fix or silence misc lints * Fix accidental copy * Use somewhat safer deallocation on return * Fix readability-inconsistent-declaration-parameter-name * Delete doc/GAME_OBJECT.md It's been moved to doc/src/content/docs/en/dev/explanation/game_objects.md * Use id as debug name to avoid it being translated * Fix nullptr access * Add blocks in switch cases * Silence false positive use-after-move * Reorder some code to avoid use-after-move * Reorder some code to avoid bugprone-if-assignment * Fix moving of references * Remove noop detached_ptr<item>::release() calls * Fix legit (?) cases of use-after-move * Fix crash in inventory dumping * Fix bug in spells --------- Co-authored-by: scarf <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Olanti <[email protected]> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
daddaec
commit 7ed3776
Showing
362 changed files
with
17,569 additions
and
20,573 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
--- | ||
title: Game Objects | ||
--- | ||
|
||
Many of the things that physically exist within the game world are **game objects(GO)**. Currently | ||
this only covers items, but creatures and vehicles are coming soon and then probably furniture at | ||
some point. GOs have a small common interface with methods like name and position that you can find | ||
in `game_object.h`. GOs use private constructors, this means **your variables must always be | ||
references or pointers**. Trying to assign a variable without a layer of indirection like that will | ||
cause a compile error. Likewise trying to copy one object over another will cause a similar error. | ||
|
||
```cpp | ||
item& it_ref = ...; // Good | ||
item* it_pointer; // Good | ||
|
||
item it = ...; // Compile error | ||
it_ref = other; // Compile error | ||
*it_pointer = other; // Compile error | ||
``` | ||
|
||
New GOs can be created via `::spawn` static methods that return a `detached_ptr` to the newly | ||
created game object. A `detached_ptr` represents an object that does not currently exist in the game | ||
world. There can only be one `detached_ptr` to an object at a time (those who know | ||
[`std::unique_ptr`](https://en.cppreference.com/w/cpp/memory/unique_ptr) will be familiar with this | ||
behavior). Functions that add an object to the world will require that you `std::move` in a | ||
`detached_ptr`. In general `detached_ptr`s must be `std::move`'d when they're passed into a | ||
function. Note that you should never use any variable after it has been moved. Likewise functions | ||
that remove an object from the world will return a `detached_ptr`. This ensures that you can't add | ||
the same thing to the world twice. | ||
|
||
Functions that don't add things to the world just accept normal pointers. You can turn a | ||
`detached_ptr` into a normal pointer by doing this. Note that you can use this to keep a valid | ||
pointer to something even after you `std::move` it, but you must do this before the `std::move` | ||
happens. | ||
|
||
```cpp | ||
&*detached | ||
``` | ||
|
||
And you can go the other way using this. Though note that it removes the object from the game world | ||
in the process and will cause errors if called on an object that isn't in the game world. | ||
|
||
```cpp | ||
detached_ptr<item> as_detached = normal_ptr->detach(); | ||
``` | ||
|
||
Trying to access an invalid `detached_ptr` (for instance one that has been `std::move`'d from) will | ||
cause a debugmsg and give you the null version of that object. | ||
|
||
## Safe References | ||
|
||
Game objects support safe references. `safe_reference<item>` will refuse access to an object that | ||
has been destroyed or is outside of the reality bubble without losing track of it, and they can be | ||
saved and loaded. You must check them as a boolean (e.g. `if( ref )`) to see if they're valid. | ||
Trying to access them when they're not will cause debugmsgs and give you a null object instead. They | ||
have a small interface that lets you check if they're destroyed or unloaded etc. If they were | ||
destroyed or unloaded this turn, they have a method that will allow you to access the object in a | ||
const fashion, for instance to display an error message. | ||
|
||
If you're moving objects around you need to use `detached_ptr`s, but otherwise when choosing which | ||
reference to use the most important thing to consider is how long you want to hold onto it. If | ||
you're just using something temporarily, for instance most arguments and variables, you should use a | ||
normal reference or pointer. If you need to store it for longer you should use a safe reference and | ||
this means it can be easily stored in the save file. In the rare case that you do want to save it | ||
across turns but don't want to store it in the save file, which means caches, there's also a fast | ||
`cache_reference<item>`, which does last across turns but can't be saved. | ||
|
||
Game objects can sometimes be split into pieces or merged together. Item stacks are the main example | ||
of this but there are others like vehicles being split or dissoluted devourers merging. When a stack | ||
of items is split, the stack that stays in place is the one that safe references will follow. When | ||
they are merged safe references to either half of the merge will now point to the merge result. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
title: Items Cookbook | ||
--- | ||
|
||
Here are some common tasks that you might want to do with items. | ||
[For more on item(game objects), check here.](../explanation/game_objects.md) | ||
|
||
## Moving items from one tripoint to another | ||
|
||
```cpp | ||
auto move_item( map &here, const tripoint &src, const tripoint &dest ) -> void | ||
{ | ||
map_stack items_src = here.i_at( src ); | ||
map_stack items_dest = here.i_at( dest ); | ||
|
||
items_src.move_all_to( &items_dest ); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,4 +55,3 @@ | |
#include <unordered_set> | ||
#include <utility> | ||
#include <vector> | ||
#include "../src/colony.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.