Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable entity/view deletion #40

Open
aaronamk opened this issue Nov 14, 2021 · 5 comments
Open

Enable entity/view deletion #40

aaronamk opened this issue Nov 14, 2021 · 5 comments
Labels

Comments

@aaronamk
Copy link
Member

use either a deleter list or more likely just add a delete flag

@aaronamk aaronamk added the code label Nov 14, 2021
@BlastWind
Copy link
Member

By delete flag, do we mean by the delete keyword or do we mean by a boolean flag to denote death like:

if (actor->isDead()) {
        this->world->DestroyBody(actor->getBody());
	actorIter = this->actorList.erase(actorIter);
	continue;
}

@BlastWind
Copy link
Member

By the way, speaking of memory management, do we need to use shared_ptr? I think the State pattern allows effectively prevents us from passing pointers around. And even in the edge case of StatePause rendering above StatePlaying, nothing should be passed between those two states. So, perhaps unique ptr can suffice so there's no reference count overhead.

Also, @aaronamk @probably-nothing do you know what happens under the hood when I do (in pseudocode):

retain_reference_to_views_ptr = StatePlaying.get_views(); 
pop StatePlaying from StateController's State Stack. 

I can probably test this out myself with a little bit more of reading. But first, does retaining a reference to a shared ptr member of a shared ptr class increase the reference count of the shared ptr class? I doubt it.

Gonna dig into deez more:

  1. https://en.cppreference.com/w/cpp/memory/unique_ptr
  2. https://en.cppreference.com/w/cpp/memory/shared_ptr
  3. https://en.cppreference.com/w/cpp/memory/weak_ptr
    and
  4. https://www.acodersjourney.com/top-10-dumb-mistakes-avoid-c-11-smart-pointers/
    The examples from cppreference are pretty cool.

@aaronamk
Copy link
Member Author

a boolean flag to denote death

@aaronamk
Copy link
Member Author

By the way, speaking of memory management, do we need to use shared_ptr? I think the State pattern allows effectively prevents us from passing pointers around. And even in the edge case of StatePause rendering above StatePlaying, nothing should be passed between those two states. So, perhaps unique ptr can suffice so there's no reference count overhead.

Do we need shared pointers at all? Yes. Actors get passed around and owned in all sorts of places. As for whether states need to be, I think probably not, we should fix that.

Also, @aaronamk @probably-nothing do you know what happens under the hood when I do (in pseudocode):

retain_reference_to_views_ptr = StatePlaying.get_views(); 
pop StatePlaying from StateController's State Stack. 

This would add one to the reference count of the view list until that code section goes out of scope, then it would remove one from the reference count of stateplaying. If that resulted in a reference count of zero, it would be deleted.

I can probably test this out myself with a little bit more of reading. But first, does retaining a reference to a shared ptr member of a shared ptr class increase the reference count of the shared ptr class? I doubt it.

Not totally sure what you mean by this, but every place that holds a shared pointer to an object will increase the reference count by one until that reference goes out of scope.

@amj0851 amj0851 assigned amj0851 and unassigned amj0851 Nov 18, 2021
@amj0851
Copy link
Member

amj0851 commented Nov 18, 2021

lol i do enemy ai

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants