Jump to content
  • Advertisement
Sign in to follow this  
lucky6969b

Does this statement work the same in win32 and win64 mode?

This topic is 871 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

int index = ((BYTE *)curtile - (BYTE *)mPathTileNode) / (sizeof(PathTileNodeType) * 8);

Will it give me the same index even though the original program runs in 32bit mode,
now I am compiling it to 64bit platform?
Thanks
Jack

Share this post


Link to post
Share on other sites
Advertisement

Yes that will work the same in 32bit and 64bit builds (unless sizeof(PathTileNodeType) changes because it has pointer members).

 

That x8 looks out of place. sizeof returns the number of bytes already, so you're dividing by 8x more bytes than you need to.

ptrdiff_t offset_in_bytes = ((char*)curtile - (char*)mPathTileNode);

size_t size_of_PathTileNodeType_in_bytes = sizeof(PathTileNodeType);

int index = offset_in_bytes /  size_of_PathTileNodeType_in_bytes;

or...

int index = curtile - mPathTileNode;

Share this post


Link to post
Share on other sites

Will this also work too?

I do have a vector of pointers in place? how do I encapsulate the container in this class while having the sizeof operator returning

the same size again? Should I just derive a new class off this struct in which there are no such pointers inside?

BTW, I think what the x8 does is because I didn't write this code, he might want to skip ahead 8 nodes (It's 8 ways directional probably)

#pragma pack(push, 1)
// Define the structure to be used
struct PathTileNodeType {

    unsigned int  bOpen : 1;  // Whether this node is in the "Open" list
    unsigned int  direction : 3;  // Optional: Direction (0-7) at this node
    unsigned int  dummy : 4;
    unsigned int  costFromStart : 24; // Lowest cost (calculated so far) from origin to
    //  this tile
    unsigned int  totalCost : 24; // Sum of cost to this point + heuristic est (* 64)

    // X,Y coordinates of previous node on path
    unsigned int  parentDir : 3;
    BYTE          parentX;
    BYTE          parentY;

    // If bOpen, then this tile belongs to an implicit "Open list", &
    //  prevOpen & nextOpen are the list pointers to neighboring elements
    POINTSMALL    prevOpen, nextOpen;
    
    
    PathTileNodeType() {
        this->x = -1;
        this->z = -1;
        this->t = -1;
        this->depth = -1;
        this->transitions.clear();
    }

    PathTileNodeType(int x, int z, int t) {
        init(x, z, t);
    }

    void init(int x, int z, long t) {
        this->x = x;
        this->z = z;
        this->t = t;        
        this->depth = 0;
        this->transitions.clear();
    }

    unsigned int getDirection() {
        return direction;
    }

    std::vector<NodePoolTransition*> getTransitions(int sizeOfAgent);

    std::vector<NodePoolTransition*> transitions;

    int x;
    int z;
    int t;
    unsigned int  depth;

};
Edited by lucky6969b

Share this post


Link to post
Share on other sites

Possibly, unless you are trying to cast the bitfields to an integer via Union. The bitfields are compiler dependent, and I'm not entirely sure how the MSVC handles them. Also, it looks like you have some wasted space in that struct. In total, I see 75 bits + ?(what ever pointer small is) for the top segment of data defines. The compiler will align this for you, bringing it up to either 96 or 128 bits depending on the system. You can go ahead and add some resolution where you need it.

Edited by Tangletail

Share this post


Link to post
Share on other sites

You're doing pointer arithmetic with 32 or 64-bit pointers and putting the result into an "int", which is not good.  The size of "int" in C/C++ is platform-dependent and is only guaranteed to be at least 16-bit.  In Windows and other modern platforms it will be 32-bits, but it's best not to rely on that.  Also, in these platforms it will be 32-bit even if compiling for 64-bit, so your pointer arithmetic might work or it might not.

 

You need to make your "index" variable a size_t type, which is guaranteed to be the size of a pointer on that platform.  This also assumes, btw, that you're always expecting a positive index value.

Share this post


Link to post
Share on other sites
int index = ((BYTE *)curtile - (BYTE *)mPathTileNode) / (sizeof(PathTileNodeType) * 8);

Will it give me the same index even though the original program runs in 32bit mode,
now I am compiling it to 64bit platform?
Thanks
Jack

 

What are the types of "curtile" and "mPathTileNode"? Sure, they are being cast to (BYTE *), so their types do not directly influence this line, but their types would help with knowing whether the intention of this line is preserved in 64-bit builds. Knowing the types might also help simplify the code.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!