Announcement

Collapse
No announcement yet.

PROJECT: ShowOnMap

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #91
    Originally posted by E
    a constructor makes a basic onject.
    This is correct.

    Originally posted by E
    a destructor "~" kills the whole object.
    That's correct, too.

    Originally posted by E
    It has an address but isn't an object. Kind of like an empty shortcut
    And that is not quite correct at least not as it stands or in the original text. Each object has an address a location in the memory. A pointer holds (contains) the address of an object. At least it should point to a valid object if the address is something else than the NULL-pointer. By the way the NULL-pointer would be the empty shortcut.

    Originally posted by E
    how are these going to apply to my showonmap?
    Here we have two things you have to understand the constructor part and the pointer object stuff. You have to understand how do you create an auto-object and what it is and how to create an object that is referenced by a pointer. (Actually you already did these but don't know that you did it.)

    We were long ago at point when I asked you to look up the constructor of MapPoint, if I remember correctly there are two. Now you should look them up and at best post them here and tell me how they initialize their data-members and whether the default constructor initialize its members so that the resulting MapPiont is valid. And of course to figure this out, you can check the MapPoint class.

    -Martin
    Civ2 military advisor: "No complaints, Sir!"

    Comment


    • #92
      These look like constructors to me...

      Code:
      MapPoint& MapPoint::operator += (const MapPoint &rhs)
      {
      	x += rhs.x;
      	y += rhs.y;
      #if !defined(_SMALL_MAPPOINTS)
      	z += rhs.z;
      #endif
      	return *this;
      }
      
      MapPoint & MapPoint::operator -= (const MapPoint &rhs)
      {
      	x -= rhs.x;
      	y -= rhs.y;
      #if !defined(_SMALL_MAPPOINTS)
      	z -= rhs.z;
      #endif
          return *this;
      }
      but it looks like they don't return a basic value.
      Formerly known as "E" on Apolyton

      See me at Civfanatics.com

      Comment


      • #93
        Originally posted by E
        These look like constructors to me...

        but it looks like they don't return a basic value.
        No, those are not constructors, they are operators, so you can use += and -= with MapPoint objects. And actually they both return something.

        Well at least you got it right that a constructor doesn't return anything, so what stuff doesn't return anything. Well that should be simple, since you have only look for the absence of the return keyword and combination with the absence of the void keyword.

        And by the way what is the proper way to figure out whether a MapPoint object is invalid?

        -Martin
        Civ2 military advisor: "No complaints, Sir!"

        Comment


        • #94
          Looking at mappoint i checked th void and the returns. Shouldn't a constructor have the same name as the class?

          but I saw this:
          MapPoint const MAP_POINT_UNKNOWN = MapPoint(-1, -1);

          isn't that the default value?

          Anyways, I took this crack at the code:

          Code:
          	// EMOD Visible wonders 4-25-2006
          	// How does the default constructor initialize MapPoint?
          	// Does the default constructor create a valid MapPoint?
          	// If not yes, how to create an invalid MapPoint?
          	MapPoint SpotFound;
          	CityInfluenceIterator it(point, GetVisionRadius());  //m_sizeIndex 
          	
          	sint32 s;
          	for(s = 0; s < rec->GetNumShowOnMap(); s++) {
          	const TerrainImprovementRecord *trec = g_theTerrainImprovementDB->Get(s);
          	
          
          		for(it.Start(); !it.End(); it.Next()) {
          //			SpotFound = it.Pos(); // Doing this means you can forget the rest
          
          			Cell *ncell = g_theWorld->GetCell(it.Pos());
          			Cell *ocell = g_theWorld->GetCell(SpotFound);
          			if(point == it.Pos())
          				continue;
          
          
          			// Amd a SpotFound valid check is missing here.
          			// See the MapPoint class for a check.
          			Assert(SpotFound.IsValid());
          
          			bool const	isAtMap	= SpotFound.IsValid();
          			if (isAtMap)
          			{
          				SpotFound = it.Pos();
          			}
          
          		
          			// These three if-statements have to be combined.			
          			if((terrainutil_CanPlayerSpecialBuildAt(trec, m_owner, it.Pos())) 
          			&& (ocell->GetNumDBImprovements() > ncell->GetNumDBImprovements())  
          			&& (ncell->GetGoldFromTerrain() > ocell->GetGoldFromTerrain()) 
          			){
          					SpotFound = it.Pos(); 
          			}
          			
          		}
          
          		g_player[m_owner]->CreateSpecialImprovement(rec->GetShowOnMapIndex(s), SpotFound, 0);
          	}
          Is my invalid code too much? I took it from MapPoint::GetNeighborPosition

          I combined the three ifs. I guess in this format we can add to it later.
          Formerly known as "E" on Apolyton

          See me at Civfanatics.com

          Comment


          • #95
            You found the valid check. However it belongs into the group of the other checks, otherwise you can forget the three combined checks.

            And please remove my comments when you have done what they tell you.

            So let's talk about the constructor:

            It is right that the constructor has the same name as the class. It shouldn't be labled with the void keyword and it shouldn't contain any return statement in its body. However you can see some examples of bad coding in source code but not in the case of MapPoint. And by the way the class is called MapPoint and mappoint.

            In the case of the MapPoint class the constructor is implemented inline, therefore you find it in the header.

            Originally posted by E
            but I saw this:
            MapPoint const MAP_POINT_UNKNOWN = MapPoint(-1, -1);

            isn't that the default value?
            That isn't the default value. Actually you see here an constructor in action, no default values at all and no default constructor at all.

            But you can tell me what this returns:

            MAP_POINT_UNKNOWN.IsValid()

            And of course you still have to post the constructors of MapPoint.

            -Martin
            Civ2 military advisor: "No complaints, Sir!"

            Comment


            • #96
              Argh! I kept looking in the cpp file not the h file. but anyways I found this:


              Code:
              class MapPoint : public MapPointData
              {
              public:
              	MapPoint()
              	:	MapPointData()
              	{ };
              My book says:

              The programmer explicitly defines a constructor with no arguments. Such a default constructor will perform the initialization specified by the programmer and willl call the default constructor for each data member that is an object of another class.
              Formerly known as "E" on Apolyton

              See me at Civfanatics.com

              Comment


              • #97
                Here you see an instance of inheritance. This syntax makes MapPoint to inherit all the data members and member functions from MapPointData:

                Code:
                class MapPoint : public MapPointData
                This constructor calles its parent constructor first:

                Code:
                	MapPoint()
                	:	MapPointData()
                	{ };
                This means for default values you have to look into the parent constructor.

                By the way if you don't provide a default constructor the compiler creates a default constructor automaticly. However the initialization maybe incorrect. So better create a default constructor.

                -Martin
                Civ2 military advisor: "No complaints, Sir!"

                Comment


                • #98
                  IN MAPPOINT.CPP I see this
                  Code:
                  MapPoint g_mp_size;
                  is that the default value for the parent constructor?


                  Where are we going with this for show on map? I don't see how this relates to SpotFound or my iterator issue.
                  Formerly known as "E" on Apolyton

                  See me at Civfanatics.com

                  Comment


                  • #99
                    Originally posted by E
                    IN MAPPOINT.CPP I see this
                    Code:
                    MapPoint g_mp_size;
                    is that the default value for the parent constructor?
                    No, g_mp_size is just another MapPoint object it doesn't has anything to do with the constructor.

                    Originally posted by E
                    Where are we going with this for show on map? I don't see how this relates to SpotFound or my iterator issue.
                    So far in the ShowOnMap code we have to figure out wheather a given MapPoint is valid. And of course at first you have to initialize SpotFound with an invalid value. So far you use the default constructor to initialize it. And here is the problem: You don't know whether the default constructor initializes SpotFound with a valid or an invalid value. And to figure that out you have to find out what the default constructor does.

                    -Martin
                    Civ2 military advisor: "No complaints, Sir!"

                    Comment


                    • So E what is so difficuilt to find the parent constructor of MapPoint and post it here? You even posted its name here.

                      -Martin
                      Civ2 military advisor: "No complaints, Sir!"

                      Comment


                      • It doesn't look like a constructor in my book thats whats making hard.

                        I'm assuming its in mappoint.h and not mappoint.cpp

                        but is this it?

                        Code:
                            MapPointData	m_pos;
                        Formerly known as "E" on Apolyton

                        See me at Civfanatics.com

                        Comment


                        • Originallz posted bz E
                          but is this it?
                          No, that's a datamember of TileUtility. Actuallz I don't understand whz zou can't find it. It is just a few lines above the line zou quoted.

                          -Martin
                          Civ2 military advisor: "No complaints, Sir!"

                          Comment


                          • the only thing above it in mappoint.h is:

                            Code:
                            uint32 MapPoint_MapPoint_GetVersion(void);
                            
                            //----------------------------------------------------------------------------
                            // Class declarations
                            //----------------------------------------------------------------------------
                            
                            struct MapPointData
                            {
                            #if defined(_SMALL_MAPPOINTS)
                            	MapPointData(sint16 const a_X = 0, sint16 const a_Y = 0)
                            	:	x(a_X),
                            		y(a_Y)
                            	{ };
                            #else
                            	MapPointData(sint16 const a_X = 0, sint16 const a_Y = 0, sint16 const a_Z = 0)
                            	:	x(a_X),
                            		y(a_Y),
                            		z(a_Z)
                            	{ };
                            
                            	sint16			z;
                            #endif
                            
                            	// Coordinates
                            	sint16			x;
                            	sint16			y;
                            
                            	bool operator == (MapPointData const & point) const
                            	{
                            		return ((x == point.x) && (y == point.y));
                            	};
                            
                            	bool operator != (MapPointData const & point) const
                            	{
                            		return (! operator ==(point));
                            	};
                            }
                            
                            [i]...tileutility...[/i]
                            
                            class MapPoint : public MapPointData
                            but I don't see anything that looks like a default value.
                            Formerly known as "E" on Apolyton

                            See me at Civfanatics.com

                            Comment


                            • Originally posted by E
                              but I don't see anything that looks like a default value.
                              Maybe you should post the constructor of the parent struct of MapPoint first. And then you should have a look on its parameter list.

                              -Martin
                              Civ2 military advisor: "No complaints, Sir!"

                              Comment


                              • Code:
                                	MapPointData(sint16 const a_X = 0, sint16 const a_Y = 0)
                                	:	x(a_X),
                                		y(a_Y)
                                	{ };
                                #else
                                	MapPointData(sint16 const a_X = 0, sint16 const a_Y = 0, sint16 const a_Z = 0)
                                	:	x(a_X),
                                		y(a_Y),
                                		z(a_Z)
                                	{ };
                                
                                	sint16			z;

                                Looking at this it looks like mapPoint's default value is 0,0 hich could be a place on the map.
                                Formerly known as "E" on Apolyton

                                See me at Civfanatics.com

                                Comment

                                Working...
                                X