0

would this be right?? <:/

Python:
if (lo & 1) != 0: HasPosMatrix = (lo & 2) | 1
else: HasPosMatrix = (lo & 2) | 0

C#:
public bool HasPosMatrix {
get { return (_lo & 1) != 0; }
set { _lo = _lo & 2 | (uint)(value ? 1 : 0); }
}

No, use python's @property

@property
def HasPosMatrix(self):
    return (_lo & 1) != 0

@property
def hasPosMatrix(self, boolArg):
    _lo = .... (translate the C# set)
0

uugh...
nothing can be easy can it -_-

I need to convert this code, and the following sub codes that go with it:

[StructLayout(LayoutKind.Sequential, Pack = 1)]
    public unsafe struct MDL0Polygon
    {
        public const uint Size = 0x64;

        public bint _totalLength;
        public bint _mdl0Offset;
        public bint _nodeId; //Single-bind node

        public CPVertexFormat _vertexFormat;
        public XFVertexSpecs _vertexSpecs;

        //public bint _elemFlags, _texFlags, _dataFlags;

        public bint _defSize; //Size of def block including padding? Always 0xE0?
        public bint _defFlags; //0x80
        public bint _defOffset; //Relative to defSize field

        public bint _dataLen1;
        public bint _dataLen2; //Same as previous
        public bint _dataOffset; //Relative to dataLen1
        public XFArrayFlags _arrayFlags; //Used to enable element arrays?
        public bint _unk3; //0
        public bint _stringOffset;
        public bint _index;
        public bint _numVertices;
        public bint _numFaces;
        public bshort _vertexId;
        public bshort _normalId;
        public fixed short _colorIds[2];
        //public bshort _colorId1;
        //public bshort _colorId2;
        public fixed short _uids[8];
        public bint _nodeTableOffset; //Always 0x64?

        private VoidPtr Address { get { fixed (void* ptr = &this)return ptr; } }
        public MDL0Header* Parent { get { return (MDL0Header*)(Address + _mdl0Offset); } }

        //public MDL0VertexData* VertexData { get { return (MDL0VertexData*)Parent->VertexGroup->First[_vertexId].DataAddress; } }
        //public MDL0NormalData* NormalData { get { return (MDL0NormalData*)Parent->NormalGroup->First[_normalId].DataAddress; } }
        //public MDL0ColorData* ColorData1 { get { return (MDL0ColorData*)Parent->ColorGroup->First[_colorId1].DataAddress; } }
        //public MDL0ColorData* ColorData2 { get { return (MDL0ColorData*)Parent->ColorGroup->First[_colorId2].DataAddress; } }
        //public MDL0UVData* GetUVData(int index)
        //{
        //    fixed (short* p = _uids)
        //    {
        //        bshort* ptr = (bshort*)p;
        //        return ptr[index] == -1 ? null : (MDL0UVData*)Parent->UVGroup->First[ptr[index]].DataAddress;
        //    }
        //}

        public VoidPtr DefList { get { return Address + 0x18 + _defOffset; } }

        public bshort* ColorIds { get { return (bshort*)(Address + 0x4C); } }
        public bshort* UVIds { get { return (bshort*)(Address + 0x50); } }

        public bushort* WeightIndices { get { return (bushort*)(Address + _nodeTableOffset); } }

        public VoidPtr PrimitiveData { get { return Address + 0x24 + _dataOffset; } }

        public string ResourceString { get { return new String((sbyte*)ResourceStringAddress); } }
        public VoidPtr ResourceStringAddress
        {
            get { return (VoidPtr)Address + _stringOffset; }
            set { _stringOffset = (int)value - (int)Address; }
        }
    }

    //public struct EntrySize
    //{
    //    public int _extraLen;
    //    public int _vertexLen;
    //    public int _normalLen;
    //    public int _colorLen;
    //    public int _uvEntries;
    //    public int[] _uvLen;
    //    public int _uvTotal;
    //    public int _totalLen;

    //    public VertexFormats _format;
    //    public int _stride;

    //    public EntrySize(MDL0ElementFlags flags)
    //    {
    //        _extraLen = flags.ExtraLength;
    //        _vertexLen = flags.VertexEntryLength;
    //        _normalLen = flags.NormalEntryLength;
    //        _colorLen = flags.ColorEntryLength;

    //        _uvEntries = _uvTotal = 0;
    //        _uvLen = new int[8];
    //        for (int i = 0; i < 8; _uvTotal += _uvLen[i++])
    //            if ((_uvLen[i] = flags.UVLength(i)) != 0)
    //                _uvEntries++;

    //        _totalLen = _extraLen + _vertexLen + _normalLen + _colorLen + _uvTotal;

    //        _format = VertexFormats.None;
    //        _stride = 0;
    //        if (_vertexLen != 0) { _format |= VertexFormats.Position; _stride += 12; }
    //        if (_normalLen != 0) { _format |= VertexFormats.Normal; _stride += 12; }
    //        if (_colorLen != 0) { _format |= VertexFormats.Diffuse; _stride += 4; }
    //        //if (_uvEntries != 0) { _format |= (VertexFormats)(_uvEntries << 8); _stride += 8 * _uvEntries; }
    //    }
    //}

    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    public unsafe struct MDL0ElementFlags
    {
        private buint _data1;
        private buint _data2;


        public bool HasVertexData { get { return (_data1 & 0x400) != 0; } }
        public int VertexEntryLength { get { return (HasVertexData) ? (((_data1 & 0x200) != 0) ? 2 : 1) : 0; } }
        public bool HasNormalData { get { return (_data1 & 0x1000) != 0; } }
        public int NormalEntryLength { get { return (HasNormalData) ? (((_data1 & 0x800) != 0) ? 2 : 1) : 0; } }

        //public bool HasColorData { get { return (_data1 & 0x4000) != 0; } }
        //public int ColorEntryLength { get { return (HasColorData) ? (((_data1 & 0x2000) != 0) ? 2 : 1) : 0; } }

        public bool HasColor(int index) { return (_data1 & (0x4000 << (index * 2))) != 0; }
        public int ColorLength(int index) { return HasColor(index) ? (((_data1 & (0x2000 << (index * 2))) != 0) ? 2 : 1) : 0; }
        public int ColorTotalLength { get { int len = 0; for (int i = 0; i < 2; )len += ColorLength(i++); return len; } }

        public bool HasUV(int index) { return (_data2 & (2 << (index * 2))) != 0; }
        public int UVLength(int index) { return HasUV(index) ? (((_data2 & (1 << (index * 2))) != 0) ? 2 : 1) : 0; }
        public int UVTotalLength { get { int len = 0; for (int i = 0; i < 8; )len += UVLength(i++); return len; } }

        public bool HasExtra(int index) { return (_data1 & (1 << index)) != 0; }
        public int ExtraLength { get { int len = 0; for (int i = 0; i < 8; ) if (HasExtra(i++))len++; return len; } }

        //public bool HasWeights { get { return (_data1 & 0xFF) != 0; } }
        //public int WeightLength { get { return ExtraLength; } }
    }

first level sub codes:

//Vertex Format Lo (lower 17 bits of vtx format register)
    //0000 0000 0000 0000 0000 0000 0000 0000 0001     - Vertex/Normal matrix index
    //0000 0000 0000 0000 0000 0000 0000 0000 0010     - Texture Matrix 0
    //0000 0000 0000 0000 0000 0000 0000 0000 0100     - Texture Matrix 1
    //0000 0000 0000 0000 0000 0000 0000 0000 1000     - Texture Matrix 2
    //0000 0000 0000 0000 0000 0000 0000 0001 0000     - Texture Matrix 3
    //0000 0000 0000 0000 0000 0000 0000 0010 0000     - Texture Matrix 4
    //0000 0000 0000 0000 0000 0000 0000 0100 0000     - Texture Matrix 5
    //0000 0000 0000 0000 0000 0000 0000 1000 0000     - Texture Matrix 6
    //0000 0000 0000 0000 0000 0000 0001 0000 0000     - Texture Matrix 7
    //0000 0000 0000 0000 0000 0000 0110 0000 0000     - Vertex format
    //0000 0000 0000 0000 0000 0001 1000 0000 0000     - Normal format
    //0000 0000 0000 0000 0000 0110 0000 0000 0000     - Color0 format
    //0000 0000 0000 0000 0001 1000 0000 0000 0000     - Color1 format

    //Vertex Format Hi (shifted left 17 bits before storing)
    //0000 0000 0000 0000 0110 0000 0000 0000 0000     - Tex0 format
    //0000 0000 0000 0001 1000 0000 0000 0000 0000     - Tex1 format
    //0000 0000 0000 0110 0000 0000 0000 0000 0000     - Tex2 format
    //0000 0000 0001 1000 0000 0000 0000 0000 0000     - Tex3 format
    //0000 0000 0110 0000 0000 0000 0000 0000 0000     - Tex4 format
    //0000 0001 1000 0000 0000 0000 0000 0000 0000     - Tex5 format
    //0000 0110 0000 0000 0000 0000 0000 0000 0000     - Tex6 format
    //0001 1000 0000 0000 0000 0000 0000 0000 0000     - Tex7 format

    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    public struct CPVertexFormat
    {
        private buint _lo, _hi;

        public bool HasPosMatrix { 
        	get { return (_lo & 1) != 0; } 
        	set { _lo = _lo & 0xFFFFFFFE | (uint)(value ? 1 : 0); } 
        }
        public XFDataFormat PosFormat { 
        	get { return (XFDataFormat)(_lo >> 9 & 3); } 
        	set { _lo = _lo & 0xFFFFF9FF | (uint)value; } 
        }
        public XFDataFormat NormalFormat { 
        	get { return (XFDataFormat)(_lo >> 11 & 3); } 
        	set { _lo = _lo & 0xFFFFE7FF | (uint)value; } 
        }

        public CPVertexFormat(uint lo, uint hi)
        {
            _lo = lo;
            _hi = hi;
        }

        public XFDataFormat GetColorFormat(int index) 
        { return (XFDataFormat)(_lo >> 13 & 3); }
        public void SetColorFormat(int index, XFDataFormat format) 
        { _lo = _lo & ~((uint)3 << (index * 2 + 13)) | ((uint)format << (index * 2 + 13)); }

        public bool GetHasTexMatrix(int index) 
        { return (_lo >> (index + 1) & 1) != 0; }
        public void SetHasTexMatrix(int index, bool value) 
        { _lo = _lo & ~(uint)(1 << (index + 1)) | ((uint)(value ? 1 : 0) << (index + 1)); }

        public XFDataFormat GetUVFormat(int index) 
        { return (XFDataFormat)(_hi >> (index * 2) & 3); }
        public void SetUVFormat(int index, XFDataFormat format) 
        { _hi = (_hi & ~(uint)(3 << index * 2) | (uint)((int)format << index * 2)); }
    }
//VTXSpecs
    //0000 0000 0000 0011   - Num colors
    //0000 0000 0000 1100   - Normal type (1 = normals, 2 = normals + binormals)
    //0000 0000 1111 0000   - Num textures
    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    public struct XFVertexSpecs
    {
        internal buint _data;

        public int ColorCount { 
        	get { return (int)(_data & 3); } 
        	set { _data = _data & 0xFFFFFFFC | ((uint)value & 3); } 
        }
        public int TextureCount { 
        	get { return (int)(_data >> 4 & 0xF); } 
        	set { _data = _data & 0xFFFFFF0F | (((uint)value & 0xF) << 4); }
        }
        public XFNormalFormat NormalFormat {
        	get { return (XFNormalFormat)(_data >> 2 & 3); }
        	set { _data = _data & 0xFFFFFFF3 | (((uint)value & 3) << 2); }
        }

        public XFVertexSpecs(uint raw) { _data = raw; }
        public XFVertexSpecs(int colors, int textures, XFNormalFormat normalFormat)
        { _data = (((uint)textures & 0xF) << 4) | (((uint)normalFormat & 3) << 2) | ((uint)colors & 3); }
    }
//This is used by polygons to enable element arrays (I believe)
    //There doesn't seem to be a native spec for this
    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    public struct XFArrayFlags
    {
        internal buint _data;

        //0000 0000 0000 0000 0000 0001 Pos Matrix
        //0000 0000 0000 0000 0000 0010 TexMtx0
        //0000 0000 0000 0000 0000 0100 TexMtx1
        //0000 0000 0000 0000 0000 1000 TexMtx2
        //0000 0000 0000 0000 0001 0000 TexMtx3
        //0000 0000 0000 0000 0010 0000 TexMtx4
        //0000 0000 0000 0000 0100 0000 TexMtx5
        //0000 0000 0000 0000 1000 0000 TexMtx6
        //0000 0000 0000 0001 0000 0000 TexMtx7
        //0000 0000 0000 0010 0000 0000 Positions
        //0000 0000 0000 0100 0000 0000 Normals
        //0000 0000 0000 1000 0000 0000 Color0
        //0000 0000 0001 0000 0000 0000 Color1
        //0000 0000 0010 0000 0000 0000 Tex0
        //0000 0000 0100 0000 0000 0000 Tex1
        //0000 0000 1000 0000 0000 0000 Tex2
        //0000 0001 0000 0000 0000 0000 Tex3
        //0000 0010 0000 0000 0000 0000 Tex4
        //0000 0100 0000 0000 0000 0000 Tex5
        //0000 1000 0000 0000 0000 0000 Tex6
        //0001 0000 0000 0000 0000 0000 Tex7

        public bool HasPosMatrix { get { return (_data & 1) != 0; } set { _data = _data & 0xFFFFFFFE | (uint)(value ? 1 : 0); } }
        public bool HasPositions { get { return (_data & 0x200) != 0; } set { _data = _data & 0xFFFFFDFF | (uint)(value ? 0x200 : 0); } }
        public bool HasNormals { get { return (_data & 0x400) != 0; } set { _data = _data & 0xFFFFFBFF | (uint)(value ? 0x400 : 0); } }

        public bool GetHasTexMatrix(int index) { return (_data & 2 << index) != 0; }
        public void SetHasTexMatrix(int index, bool exists) { _data = _data & ~((uint)2 << index) | ((uint)(exists ? 2 : 0) << index); }

        public bool GetHasColor(int index) { return (_data & 0x800 << index) != 0; }
        public void SetHasColor(int index, bool exists) { _data = _data & ~((uint)0x800 << index) | ((uint)(exists ? 0x800 : 0) << index); }

        public bool GetHasUVs(int index) { return (_data & 0x2000 << index) != 0; }
        public void SetHasUVs(int index, bool exists) { _data = _data & ~((uint)0x2000 << index) | ((uint)(exists ? 0x2000 : 0) << index); }
    }

second level sub codes:

public enum XFDataFormat : byte
    {
        None = 0,
        Direct = 1,
        Index8 = 2,
        Index16 = 3
    }
public enum XFNormalFormat
    {
        Invalid = 0, //Normals are always used!
        XYZ = 1,
        NBT = 2
    }
[StructLayout(LayoutKind.Sequential)]
    public struct buint
    {
        public uint _data;
        public static implicit operator uint(buint val) { return val._data.Reverse(); }
        public static implicit operator buint(uint val) { return new buint { _data = val.Reverse() }; }
        public static explicit operator int(buint val) { return (int)val._data.Reverse(); }
        public static explicit operator buint(int val) { return new buint { _data = (uint)val.Reverse() }; }
    }

can you write a python code that does the same exact thing??
this is just way too complicated DX

what I want to do is to basically return a format list

something like: [ 3 , 3 , 3 , 2 , [ 3 , 2 ] ]
[ unk , vert , norm , col , [ uv1 , uv2 ] ]

here's what the numbers equal:

None = 0,
Direct = 1,
Index8 = 2,
Index16 = 3

0

KK

I've actually been able to figure most of it out, thanx to the notes...

here's my object code so far, if anyone's interested: :)
http://www.pasteit4me.com/2274003
(ignore Will's block (useless comparison code))

anyways...
all I need now is the middle and bottom of the first function in my last post...

0

I do not know your code base now, and also do not know C#, but looks bit operations for me. Here is my function for dealing with bits if it helps you

import random

def bits(n, number_of_bits=32):
    return {p for p in range(number_of_bits) if n & 2 ** p}

if __name__ == '__main__':
    for count in range(100):
        number = random.randint(0, 2 ** 32 - 1)
        print('{number:032b} {r}'.format(number=number, r=bits(number)))

Edited by pyTony: number_of_bits parameter

0

heh...
you know...
what I need help with:
here is prbly not the best place to ask
heh

you guys would have to look into the Wii_SDK to fully understand what I need help with... <:D

I'm stuck here without options as the the people who actually know this stuff are disreguarding everything I'm trying to ask them...

I can however post that this block of hex is what I'm trying to figure out:

00 00 00 00 00 00 00 00 00 00 08 50 00 00 5E 05
08 60 00 00 00 03 10 00 00 10 08 00 00 00 15 00
08 70 41 37 70 09 08 80 C8 24 12 09 08 90 04 82 
41 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

the values of the 08 50 and 08 60 commands can be taken care of by the first 2 functions here:
http://www.pasteit4me.com/2279002
(they're the same values every time in the object header)

the XFflags are just T/F values (in my code)

but you can see, there's more in the hex that needs figured out (in red)
the 10 00 00 10 needs to be figured out as well :/

so yea...
you see my delema...
and the experts won't even speak to me >_>

EDIT:
my code-base...
search up Brawlbox on google and look for the SVN
once there, you should find 'MDL0.cs' in brlib/.../SSBB/tyes/

I have the src on my disk thanx to tortiseSVN :P

Edited by DarkPikachu: n/a

0

hey guys...

just need the smallest bit of help around Tkinter...

how would I go about doing something like this:

imSC = ' ' #key var for selecting a single plugin to use
imbtn[0] = 'name' #name returned from a list of plugins containing an info list

Button( command=(imSC == imbtn[0], imSCWin.destroy()) ) #selects "this" plugin when pressed

I've figured out how to get the buttons to list in a window,
based on the number of plugins for a certain filetype

right now there's 2 plugins that use '.dat'
so how do I tell the button I press to set the key var to the correct name??


if you'd like to see my code, I can show it to you :/

0

edited my code a little...

did a little research on '.invoke()'

would this work:

if len(imbtns) > 0: #has open dialog been cancelled?
    if len(imbtns) > 1: #is there only a single associated plugin?
        
        def imbtn_press(key): #new
            imSCWin.destroy()
            return key

        for R, imbtn in enumerate(imbtns): #add the multiple buttons to the window
            if debug: print str(R) + ': ' + imbtn[0] + ' - name: ' + imbtn[1] #debug
            #create the button
            imbtn[1] = Button(imSCWin, width=36, height=2, text=str(imbtn[0]),
                              command=imbtn_press(imbtn[0]))# needs fixing
            imbtn[1].grid(row=(R+1), column=0)

            imSC = imbtn[1].invoke() #new
            
            #'imbtn[0]' contains a varification string (a key) that is also used as the text for the button
                #^this is what sets the 'imSC' var to decide which plugin to use
            #'imbtn[1]' contains a string to be used as a var to name the button (works perfectly)

        root.wait_window ( imSCWin )
    else: #get the key for the single plugin (works perfectly)
        for imbtn in imbtns: imSC = imbtn[0]
        imSCWin.destroy()
else: imSCWin.destroy() #file dialog has been cancelled

this is the button part of the code for the import file selection

here's the description:

#file-open/save dialogs
#____________________________________________import block_____________________________________________
    #after opening your file, creates a window to select the type of conversion method to use
    #^(if there are 2 or more plugins dedicated to that specific file type)

the buttons are created perfectly, but they do notiong atm

they're supposed to set 'imSC' to a string that's used by one of the defined plugins listed in the window
^(the string initiates the proper plugin for conversion)

____________________________________________
Self Confidence Notes: :P

you know...
I'm actually quite proud of myself for getting it this far... heh

I know almost nothing about Tk or how to use the widgets

Edited by DarkPikachu: n/a

0

KK trying something different...

the command for the button executed each time the button was created...
so I've changed the code and now I've written a list of preconfigured buttons:

[
'im_melee = Button(imSCWin, width=36, height=2, text=Melee, command=btn_press("Melee")).grid(row=1, column=0)'
,
'im_ToV = Button(imSCWin, width=36, height=2, text=Tales of Vesperia, command=btn_press("Tales of Vesperia")).grid(row=2, column=0)'
]

the text writes perfectly, but now,
how do I turn strings into usable code??

0

KK trying something different...

the command for the button executed each time the button was created...
so I've changed the code and now I've written a list of preconfigured buttons:

[
'im_melee = Button(imSCWin, width=36, height=2, text=Melee, command=btn_press("Melee")).grid(row=1, column=0)'
,
'im_ToV = Button(imSCWin, width=36, height=2, text=Tales of Vesperia, command=btn_press("Tales of Vesperia")).grid(row=2, column=0)'
]

the text writes perfectly, but now,
how do I turn strings into usable code??

found a solution...
simply use exec() for each list value

for btn in list:
exec(btn)

that should work perfectly

EDIT:
well...
fat chance of that workin out >:/

it still sets imSC to the last button name

I need some help here

I'll put my code back to the way it was...
since this is basically just a longer way of doing the same thing

Edited by DarkPikachu: n/a

0

How about simple eval, thouqh I doubt have dynamic code, why not only import the relevant plugin?

0

How about simple eval, thouqh I doubt have dynamic code, why not only import the relevant plugin?

this was discussed before I believe >_>

but I've already gotten all the plugins to import...
thanx to you actually ;)

but now...
there's really not a good safety check between the 'dat' formats of:
Melee
Tales of Vesperia
^(a seperate plugin for each game)

thus I had to implement a button window that appears after selecting your file
(if there are 2 or more plugins associated with that file type)

so yea...
everything works perfectly...
the buttons show...
but now I need to set a var, and destroy the window when clicking the button...

vars to set:
imSC = '' #import format (Safety Check)
exSC = '' #export format (Safety Check)
^(a window appears for each)

I can take a screenshot of the buttons if you like :)

EDIT:
the error:
the command for the button initiates as it's created...

how can I initialize the commands when I click the button??

Edited by DarkPikachu: n/a

0

uugh...
quick help on something here:

how do I read and apply the transparency of the IA8 format without getting this:
ValueError: chr() arg not in range(256)

I've tried using 'value = (1-alpha)*BG + alpha*color'

but from some numbers:
BG = 204 #153 as alt (tile BG)
color = 0 #black
alpha = 56

value = -11423

C = chr(value).encode('hex') #what the number is for and how it's used:
print '#' + (C*3) #B/W image


and also...
I need some help on getting my buttons to work :/
I've had to put my project on hold because of 0% feedback

0

uugh...
quick help on something here:

how do I read and apply the transparency of the IA8 format without getting this:
ValueError: chr() arg not in range(256)

I've tried using 'value = (1-alpha)*BG + alpha*color'

but from some numbers:
BG = 204 #153 as alt (tile BG)
color = 0 #black
alpha = 56

value = -11423

C = chr(value).encode('hex') #what the number is for and how it's used:
print '#' + (C*3) #B/W image


and also...
I need some help on getting my buttons to work :/
I've had to put my project on hold because of 0% feedback

I have finally found my answer
but it took more time than it should've <_<

value = chr( (alpha*(color +256- BG)) /256+ BG-alpha ).encode('hex')

it works perfectly

2

While Gribouillis's answer is correct, it could probably use more explanation, because the dot-member notation is used somewhat differently in C++ than in Python and it may be somewhat confusing.

In C++, variables have an explicit type, unlike in Python, where variables are typeless (type being a property of the objects which variables reference, not the variables which reference them). There are many different types in C++, but for our purposes there are two broad categories that matter: value variables and pointer variables.

All local named variables in C++ are stored on the stack, a system data structure which keeps track of function calls. When a function in C++ is called, all the information needed for that function - both where it needs to return to, and what variables and arguments it has - is pushed onto the stack, and access to the variables is done by offsets into the stack area. Most of the time, you have variables whose values are the actual data you are working with - for example, if you have an integer value, the integer is stored in the very location on the stack which the variable name refers to. You usually don't need to know all of this - the compiler does this part for you - but it is important to understand that the amount of local memory you have for the function is fixed when the function call is made, and that the local values only exist during the lifetime of the function call.

This works well for most needs, but if you need a value which changes size over time, or which persists beyond the scope of the current function call, you need to have memory which is dynamically allocated from somewhere else - a free memory pool called the heap. When you get memory from the heap, what you actually are getting is a pointer to a block of heap memory. This is (part of) what pointer variables are for. These are local named variables which hold the address of some other part of memory - so that the 'real' value of the pointer is what it points to, not the value in the pointer itself.

When working with pointers, you need to be able to differentiate between when you're talking about the pointer's reference or the pointer itself. In C++, to talk about a pointer's own value - that is, the address that it holds - you simply use the pointer variable's name say, foo ); but to talk about the object it points to, you need what is called the reference operator, which is the asterisk. So, if you want the object foo points to, you would write *foo etc.

This makes for a more flexible way of working with memory than doing things on the stack, but it is also a more difficult approach because it is often hard for programmers to keep proper track of memory.

Now, in Python, all of this is done for you automatically. All variables are reference variables (that is to say, pointers, more or less), and the interpreter handles the details of managing the values in memory for you.

OK, I explained all of this in order to explain the difference between dot-member notation and member-reference notation in C++ (whew!). In C++, if you have a compound value like a structure or an object, it may be either a locally store value on the stack, or it could be a dynamically allocated value in the heap. For a locally stored object, to get one of it's components you would write the name of the variable followed by a period followed by the name of the member you want to access. So, if you had a structure

struct bar {
    int baz;
    double quux;
};

bar foo;

and wanted to get the value of the member quux out of foo , you might write

double flup = foo.quux;

So far, so good; this isn't too different from getting a member from an object in Python. Where it goes astray is when you have a pointer to a structure. Remember how I said that you needed to be able to tell when you wanted the pointer, and when you wanted what it points to? The same is true with structure pointers, only this time, using the reference operator makes for a rather ugly approach:

double flup = (*foo).quux;

For this reason, there is a more explicit way of accessing a pointed-to member: the member-reference operator, -> , which looks like:

double flup = foo->quux;

It means the same thing as the other version, but is clearer as to what it means (or at least is supposed to be).

Again, all of this is done for you in Python. When you access a Python class's member, you always use the dot notation, because there is no (explicit) separation between local values and heap values - everything is on the heap, or at least everything behaves as if it were.

The practical upshot of this is that the Python dot operator would be used for everything that the dot operator is used for in C++, as well as for everything the member-reference operator is used for.

Edited by Schol-R-LEA: n/a

Votes + Comments
You put your heart in it
0

hey...
would you guys mind helping me out on another thing :/

I mainly focus on Tony, since he's helped me out the most in this area ;)

I think I finally have a proper idea for getting my window working...
but I'm not sure how to carry it out approprietly :/

what I need is for when the buttons for each plugin pop up in the window,
I need to reference a command function from the plugin,
that will set my key variable to a string in the main program,
which is then referenced by another function in the plugin...
(basically a sort of verification technique)

if I need to provide my src to help out, I will

I just need to finally get this thing working...

0

If you could isolate the relevant part of code in running form and exact specification of what you want to happen with example plugin. From your message I catch that you have the plugin available and button visible showing it's presence. Might be good idea to post that as first message of new thread with title describing what you want to accomplish.

Edited by pyTony: n/a

0

real quick...
can I get this rewritten in Python:

int main ( int argc, char * argv[] ) {

    /* initialize GLUT, using any commandline parameters passed to the 
       program */
    glutInit(&argc,argv);

    /* setup the size, position, and display mode for new windows */
    glutInitWindowSize(500,500);
    glutInitWindowPosition(0,0);
    glutInitDisplayMode(GLUT_RGB);

    /* create and set up a window */
    glutCreateWindow("hello, teapot!");
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);

    /* define the projection transformation */
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-2.0,2.0,-2.0,2.0,-2.0,2.0);

    /* define the viewing transformation */
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0);

    /* tell GLUT to wait for events */
    glutMainLoop();
}

you can leave the GL functions as they are ;)

EDIT:
NVM, I found something even better that I need :)

Edited by DarkPikachu: n/a

0

ok...
this part, I need help with...

how does this function work exactly??:

// Header information for a memory block (16 bytes)
struct MEMiExpHeapMBlockHead
{
    u16                      signature;      // Signature
    union                                // Attribute
    {
        u16                      val;
        struct
        {
            u16                  allocDir  : 1;   // Memory allocation direction
            u16                  alignment : 7;   // Alignment
            u16                  groupID   : 8;   // Group ID
        }
        fields;
    }
    attribute;
    
    u32                      blockSize;         // Block size (data area only)
    
    MEMiExpHeapMBlockHead*   pMBHeadPrev;       // Previous block
    MEMiExpHeapMBlockHead*   pMBHeadNext;       // Next block
};
0

Tcll, as you should know people are much less likely to reply to "solved" threads, we also don't like old ones bumped up, just start a new thread.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.