HUDNavigation

Get help with programming issues.

Moderator: PPS-Leaders

sfluecki
Human Space Navy Sergeant
Posts: 11
Joined: Tue Mar 02, 2010 2:49 pm

HUDNavigation

Post by sfluecki » Tue May 11, 2010 8:53 pm

hi there,
after another 4 hours on the HUDNavigation.cc file in /src/modules/overlays/hud in the hudelements branch im coming here now to get some help.

target: to solve the problem caused by beeing killed in game. if the humancontroller is killed and respawns the ogre-overlays for navmarkers an distance-text are not reappearing.

idea: in the constructor-method of HUDnavigation ive created a loop over all existing radarviewables currently active. i excluded the humanship itself by testing the ->isHuman_ member of the radarviewables in each turn. if the current object is not a humanplayer it should be added to the existing activeObjectList_ (which is of type map).

apparently something doesnt work so far, because the game crashes with a sigfault after the spawn-contdown reaches '1'.

it would be nice if someone of the team had a quick look on it and would contact me here ore via skype 'sfluecki'.

thanks a lot.
sebastian

User avatar
greenman
Baron Vladimir Harkonnen
Posts: 360
Joined: Wed Oct 03, 2007 2:53 pm
Contact:

Re: HUDNavigation

Post by greenman » Wed May 12, 2010 8:25 am

as i already told you this monday you cannot do this in the constructor. (the reason is that you don't know yet which owner you have. right after the contructor of HUDNavigation "someone" calls the setOwner function and correctly sets the owner. after this the changedOwner function gets called. this is where you have to collect your radarviewables. you already have that function (changedOwner) implemented, but commented out. undo the commenting and implement the function gatherObjects (just move in the parts which you already have in you constructor).

if you still have problems you can look at HUDRadar which does exactly the same.

i hope this was understandable?!
There are only 10 types of people in the world: Those who understand binary, and those who don't.

sfluecki
Human Space Navy Sergeant
Posts: 11
Joined: Tue Mar 02, 2010 2:49 pm

Re: HUDNavigation

Post by sfluecki » Thu May 13, 2010 10:00 am

all right :beerchug:
es funktioniert - alle pfeile werden angezeigt, und aktualisiert,
und beim respawn korrekt neu initialisiert.

weiter im text:

problem: die textoverlays erscheinen nicht obwohl parallel mit den pfeiloverlays initialisiert.

vermutung: könnte es daran liegen, dass die setCaption funktion erst in der tick aufgerufen wird un nicht in addObject schon direkt? am ende von addOBject passiert background->addChild(text), text->setCaption wurde aber noch nicht ausgeführt.

versuch: ich habe mit:

Code: Select all

int dist = (int)(object->getRVWorldPosition() - HumanController::getLocalControllerEntityAsPawn()->getWorldPosition()).length();

text->setCaption(multi_cast<std::string>(dist));
versucht den text in der addObject funktion welche mit dem Radarviewable* 'object' aufgerufen wird zu berechnen. allerdings hat das nicth funktioniert (zum sigFault geführt), meiner meinung nach weil der Pawn noch nicht existiert und es somit ein pure virtual call ist (wird so auch von strace dokumentiert).

frage: wie muss ich das ding nun angehen so dass ich die distanz in der addOBject funktion berechnen und notieren kann so dass dies am ende funktioniert, ODER übersehe ich einen grund, weshalb die textoverlays nicht angezeigt werden?

lg seba
ps: hab den branch grad geSVNt, sollte also jetz bei euch sichtbar sein.

User avatar
greenman
Baron Vladimir Harkonnen
Posts: 360
Joined: Wed Oct 03, 2007 2:53 pm
Contact:

Re: HUDNavigation

Post by greenman » Thu May 13, 2010 11:22 am

if i run it, i can see something that maybe should be the font ^^ i see some strange artifacts and i guess this is because you are setting some parameters wrong (x,width, whatever)

at the time when addObject gets called from Radar the object position and orientation and so on are not yet available. this is why you have to set these things in the tick function

i saw that you are using a bool wasOutOfView_ membervariable. you cannot use a single variable if you have multiple objects. if you want to do this, then you have to create another map/vector/list or whatever OR (better) create a struct where you have 2 pointers to the overlayelement a bool for outofview and maybe other information about radarviewables and use this struct instead of the std::pair you use now in you radarobjectmap

hope this helps

btw: i cleaned up some things in your code (you need to correctly destroy the overlayelements when you remove an object)
There are only 10 types of people in the world: Those who understand binary, and those who don't.

sfluecki
Human Space Navy Sergeant
Posts: 11
Joined: Tue Mar 02, 2010 2:49 pm

Re: HUDNavigation

Post by sfluecki » Sat May 15, 2010 1:42 pm

hi there,

thanks for the cleaning part =)
with the bool outOfView i am pretty
shure to be on the right part here. if
you watch the code:

Code: Select all

Vector3 pos = transform * tempRadarViewable->first->getRVWorldPosition();

bool outOfView;
if (pos.z > 1.0)
this is all in my big for(iterating throught map) so the vector pos is
in each turn set for the new radarvieable position. which now means for
each radarViewable i use a different pos-vector. the whole position setup
is in my for-loop so this should absolutely not be the problem.

what sort of grafix did u mean? i cant see any - except for somtimes i
got the feeling that the arrows are not actually arrows :) i guess best is
if we have a closer look on monday on this.

thx so far,
sebastian

sfluecki
Human Space Navy Sergeant
Posts: 11
Joined: Tue Mar 02, 2010 2:49 pm

Re: HUDNavigation

Post by sfluecki » Sat May 15, 2010 1:49 pm

i must went throught what you wrote into the destructor:

Code: Select all

        activeObjectListType::iterator it;
        for( it = activeObjectList_.begin(); it!=activeObjectList_.end(); ++it )
        {
            removeObject(it->first);
        }
        activeObjectList_.clear();
does this make sense? in the map

key: radarvieable,
value: pair<paneloverlay, textoverlay>


the expression it->first will in my opinion point on the key itself type radarviewable, so you are going to destroy that? i guess this is redundant with activeObjectList.clear() which also erases all objects of the map?

if yo uwant to destroy the overlay i would say we have to point to

Code: Select all

it->second->first (object->value.paneloverlay)
it->second->second (object->value.textoverlay)
and afterwards clean up the objects out of the map with map.clear().

if i am wrong please correct me... but as the code is now i dont see the sensee in it.

thanks for the help
sebastian

User avatar
x3n
Baron Vladimir Harkonnen
Posts: 810
Joined: Mon Oct 30, 2006 5:40 pm
Contact:

Re: HUDNavigation

Post by x3n » Sat May 15, 2010 10:35 pm

i can't really help you there, but just a note: if you store pointers in a map and you destroy (or clear) the map, the pointers will be lost, but the "real" objects (in this case the overlays) won't be deleted. so you have to delete the objects before you clear the map.
Fabian 'x3n' Landau, Orxonox developer

sfluecki
Human Space Navy Sergeant
Posts: 11
Joined: Tue Mar 02, 2010 2:49 pm

Re: HUDNavigation

Post by sfluecki » Sun May 16, 2010 12:07 pm

x3n wrote:i can't really help you there, but just a note: if you store pointers in a map and you destroy (or clear) the map, the pointers will be lost, but the "real" objects (in this case the overlays) won't be deleted. so you have to delete the objects before you clear the map.
but i dont want to delete the objects?? i have a number of enemy ships and the pointers point
to them. there is no reason in deleting the ships themselves i just want to kill the pointers.

anyways: i just testet ingame and have a question. what exactly did you mean by cleaning up the code?
because since that new svn update i have with each respawn a ugly huge arrow-shaped overlay
pointing to the human ship itselv covering 15% of my screen.

this was not there before your commit - any chance of knowing where it came from?

cheers
sebastian

User avatar
x3n
Baron Vladimir Harkonnen
Posts: 810
Joined: Mon Oct 30, 2006 5:40 pm
Contact:

Re: HUDNavigation

Post by x3n » Mon May 17, 2010 3:27 pm

sfluecki wrote:
x3n wrote:i can't really help you there, but just a note: if you store pointers in a map and you destroy (or clear) the map, the pointers will be lost, but the "real" objects (in this case the overlays) won't be deleted. so you have to delete the objects before you clear the map.
but i dont want to delete the objects?? i have a number of enemy ships and the pointers point
to them. there is no reason in deleting the ships themselves i just want to kill the pointers.
well I guess you (and oli) worked on this today, but i still want to give you an answer on this.
your map looks like this:

Code: Select all

typedef std::map<RadarViewable*, objectStruct > activeObjectListType;
activeObjectListType activeObjectList_;
So yes, it->first is a RadarViewable, for example a SpaceShip. but it->second is a struct which contains pointers:

Code: Select all

struct objectStruct{
      Ogre::PanelOverlayElement* panel_;
      Ogre::TextAreaOverlayElement* text_;
      bool outOfView_;
      bool wasOutOfView_;
};
so you have two pointers it->second.panel_ and it->second.text_. These pointers point to objects which were created with "new", so you HAVE to remove them with "delete". you can't just "kill the pointers", that doesn't work in C++, we don't have a garbage collector here.

and now look what the function "removeObject" in your destructor does: it deletes panel_ and text_. that's exactly what i just said and therefore it works as intended. it->first (the SpaceShip) isn't deleted - it's just the key for the map.


however there's still a problem in the code, because removeObject calls "activeObjectList_.erase(viewable);" while the for-loop in the destructor iterates through the list. this is wrong and can lead to a crash. this should fix it:

Code: Select all

HUDNavigation::~HUDNavigation()
{
    if (this->isInitialized())
    {
        for (activeObjectListType::iterator it = activeObjectList_.begin(); it != activeObjectList_.end(); )
            removeObject((it++)->first);
    }
}
or

Code: Select all

HUDNavigation::~HUDNavigation()
{
    if (this->isInitialized())
    {
        while (activeObjectList_.size() > 0)
            removeObject(activeObjectList_.begin()->first);
    }
}
(note that I removed "activeObjectList_.clear();" because that was indeed unnecessary.)
Fabian 'x3n' Landau, Orxonox developer

User avatar
1337
Baron Vladimir Harkonnen
Posts: 521
Joined: Wed Oct 10, 2007 7:59 am

Re: HUDNavigation

Post by 1337 » Mon May 17, 2010 5:08 pm

I fixed that it++ issue this afternoon.
http://www.xkcd.com/
A webcomic of romance, sarcasm, math, and language.

User avatar
x3n
Baron Vladimir Harkonnen
Posts: 810
Joined: Mon Oct 30, 2006 5:40 pm
Contact:

Re: HUDNavigation

Post by x3n » Mon May 17, 2010 6:13 pm

1337 wrote:I fixed that it++ issue this afternoon.
that's interesting, because the issue is still there. looks like revision 6914 reverted this particular change.
Fabian 'x3n' Landau, Orxonox developer

User avatar
1337
Baron Vladimir Harkonnen
Posts: 521
Joined: Wed Oct 10, 2007 7:59 am

Re: HUDNavigation

Post by 1337 » Mon May 17, 2010 7:28 pm

So, somebody has overridden my changes I guess. How did that happen? It cannot be SVN, it has to be done forcefully.
http://www.xkcd.com/
A webcomic of romance, sarcasm, math, and language.

User avatar
greenman
Baron Vladimir Harkonnen
Posts: 360
Joined: Wed Oct 03, 2007 2:53 pm
Contact:

Re: HUDNavigation

Post by greenman » Tue May 18, 2010 5:40 am

maybe there was a conflict when updating to the current version which hasn't been solved thoroughly... i don't think this was deliberately
There are only 10 types of people in the world: Those who understand binary, and those who don't.

User avatar
1337
Baron Vladimir Harkonnen
Posts: 521
Joined: Wed Oct 10, 2007 7:59 am

Re: HUDNavigation

Post by 1337 » Tue May 18, 2010 7:21 am

Certainly not actually deliberate. But accidentally delibrate ^^
SVN would not just allow such an action just like that, that's all I wanted to say.
http://www.xkcd.com/
A webcomic of romance, sarcasm, math, and language.

User avatar
1337
Baron Vladimir Harkonnen
Posts: 521
Joined: Wed Oct 10, 2007 7:59 am

Re: HUDNavigation

Post by 1337 » Tue May 18, 2010 7:35 am

Fixed it again.
http://www.xkcd.com/
A webcomic of romance, sarcasm, math, and language.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest