Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [help] map.erase();  (Read 1736 times)

0 Members and 1 Guest are viewing this topic.

Elekhyr

  • Guest
[help] map.erase();
« on: May 17, 2014, 02:05:41 am »
Hi ! I've a std::map<std::string,Obj*> which contains an ObjA, an ObjB and many ObjC.
I made a function which manages collision between ObjB and ObjC (it works) !
but my function which is used for delete my ObjC when they collide with my ObjB didn't :

 //ManagerObj.cpp

void ManagerObj::deleteObj(std::map<std::string, Blocks*>::iterator i)
{
                m_VecMap.erase(i);
}

void ManagerObj::updateAll()
{
        for (std::map<std::string, Obj*>::iterator i = m_VecMap.begin(); i != m_VecMap.end(); ++i)
        {
                if ((i->first == "ObjC") && (i->second->checkCollision() == true)) delete(i);
                i->second->update(); // used for ObjB and ObjC collide and they do
        }
}
 

//main.cpp

        ManagerObj mapManager;
        mapManager.addObj("ObjA", p_ObjA);
        mapManager.addObj("ObjB", p_ObjB);
        mapManager.addObj("ObjC", p_ObjC);

//...

        mapManager.updateAll();

//...

 

Can you help me to erase my ObjC from mapManager when it collides with ObjB ? Thanks you !

Elekhyr

  • Guest
Re: [help] map.erase();
« Reply #1 on: May 17, 2014, 02:18:11 am »
In fact my function collision() doesn't work  ;D

bool Blocks::checkCollision()
{

        double circle = sqrt((m_Rectangle.getPosition().x - m_Circle.getPosition().x)*(m_Rectangle.getPosition().x - m_Circle.getPosition().x) + (m_Rectangle.getPosition().y - m_Circle.getPosition().y)*(m_Rectangle.getPosition().y - m_Circle.getPosition().y));
       
        if (circle <= m_Circle.getRadius()) return true;
}
 

(I just realize that my function is truly bad, help me please)
« Last Edit: May 17, 2014, 02:22:07 am by Elekhyr »

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: [help] map.erase();
« Reply #2 on: May 17, 2014, 02:32:37 am »
So... what exactly has this problem got to do with something specific to SFML? You could have asked this question on any other forum on the internet. The fact that this sub-forum is called "General" doesn't mean you can post anything you want. It is for problems that have to do with SFML and don't fit in any of the other forums. And no... just because your objects happen to be/contain SFML classes doesn't mean you can ask about any other part of your code on this forum. These random posts have been becoming quite frequent recently. Maybe an additional amendment to the rules is necessary... Or even a separate sub-forum for programming issues in general.

I'm sure there will be someone friendly who comes along and tries to help you with your problem, but I say the line has to be drawn somewhere. If we allowed everybody to post any little problem they had, the forum would get flooded with these kinds of threads and stackoverflow or gamedev.net would run out of business.

Besides... even if I did feel like helping you, I have no idea what you are trying to achieve and what kind of an answer you are expecting from us.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

Elekhyr

  • Guest
Re: [help] map.erase();
« Reply #3 on: May 17, 2014, 03:28:24 am »
But in fact collision between Object is a collision between sf::RectangleShape and sf::CircleShape, I forgot to mention, sorry

Voroz

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Re: [help] map.erase();
« Reply #4 on: May 17, 2014, 03:14:19 pm »
So... what exactly has this problem got to do with something specific to SFML? You could have asked this question on any other forum on the internet. The fact that this sub-forum is called "General" doesn't mean you can post anything you want. It is for problems that have to do with SFML and don't fit in any of the other forums. And no... just because your objects happen to be/contain SFML classes doesn't mean you can ask about any other part of your code on this forum. These random posts have been becoming quite frequent recently. Maybe an additional amendment to the rules is necessary... Or even a separate sub-forum for programming issues in general.

I'm sure there will be someone friendly who comes along and tries to help you with your problem, but I say the line has to be drawn somewhere. If we allowed everybody to post any little problem they had, the forum would get flooded with these kinds of threads and stackoverflow or gamedev.net would run out of business.

Besides... even if I did feel like helping you, I have no idea what you are trying to achieve and what kind of an answer you are expecting from us.

Maybe he wanted help from you guys because you are such a friendly community  ;D.
I don't think you have to worry about becoming more popular than stackoverlow or gamedev, and i also think there should be a subforum for general programming questions on this site.

There aren't that many questions for SFML specific things that you can't just point to the tutorial about, so if you want more activity on the forum (it's quite dead), then i guess a subforum for general programming questions would be good.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: [help] map.erase();
« Reply #5 on: May 17, 2014, 03:28:52 pm »
There aren't that many questions for SFML specific things that you can't just point to the tutorial about
There are tons. Just dig through the forums, you'll see many interesting discussions that don't concern basic things. A lot of them have contributed to an improvement of the library during the last years.

There are of course many beginner questions, and I personally think we should be slightly more strict if it's obvious that people have not read the tutorials or documentation. See also here.

so if you want more activity on the forum (it's quite dead)
Which forum is dead? Anyway, the idea is not to have as much traffic as possible, but to have a nice community where people get quality answers concerning SFML.

so if you want more activity on the forum (it's quite dead), then i guess a subforum for general programming questions would be good.
I don't think that's a good idea, there are really enough forums focused on C++, where you typically get better help. In my opinion, this forum should focus on SFML and related game development questions.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: [help] map.erase();
« Reply #6 on: May 17, 2014, 03:53:02 pm »
We should really try to make the official SFML FAQ more obvious.  It answers a lot of these newbie questions but even I keep forgetting it exists because there's no mention of it anywhere on the main site.  I think there's a rule thread on this forum that mentions it but that's also really easy to miss unless you check every subforum before posting.


Incidentally, I think there might actually be some value in a general programming section, because there are parts of C++ that aren't specific to SFML but never really come up until you start doing something like multimedia programming.  For instance, premature destruction issues like "the white square problem" simply never happened to me until I started using SFML.  Still, there's also a pretty big risk that it would just attract a lot more people who can't be bothered to learn C++ properly, so I can't say I'm strongly for or against it.

StormWingDelta

  • Sr. Member
  • ****
  • Posts: 365
    • View Profile
Re: [help] map.erase();
« Reply #7 on: May 17, 2014, 10:40:33 pm »
Yep we really need a section for non SFML things.  To at very least give a place to drop people into and collect the things. :)  It's funny how you never run into some things until you start programming in new areas so don't take it too personally if someone pops up more confused than you are. :)
I have many ideas but need the help of others to find way to make use of them.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: [help] map.erase();
« Reply #8 on: August 27, 2014, 09:31:34 pm »
I'll side with Nexus on this one.
There are many good C++ forums elsewhere. This does not need to be yet another. Let's focus on SFML specific issues (as much as reasonably possible; of course exceptions should be allowed).

 

anything