AdmiralAlkex Posted May 18, 2009 Share Posted May 18, 2009 I realize this probably count as a AutoIt question, but I believe the advanced nature warrants posting here. Any mods that disagree are free to move it to support.Ok, so while I have been working on my SDL UDF I bumbed into a struct I have no ideo how to convert, I am just stumped. Here is the typedef:typedef struct SDL_VideoInfo { Uint32 hw_available :1; /* Flag: Can you create hardware surfaces? */ Uint32 wm_available :1; /* Flag: Can you talk to a window manager? */ Uint32 UnusedBits1 :6; Uint32 UnusedBits2 :1; Uint32 blit_hw :1; /* Flag: Accelerated blits HW --> HW */ Uint32 blit_hw_CC :1; /* Flag: Accelerated blits with Colorkey */ Uint32 blit_hw_A :1; /* Flag: Accelerated blits with Alpha */ Uint32 blit_sw :1; /* Flag: Accelerated blits SW --> HW */ Uint32 blit_sw_CC :1; /* Flag: Accelerated blits with Colorkey */ Uint32 blit_sw_A :1; /* Flag: Accelerated blits with Alpha */ Uint32 blit_fill :1; /* Flag: Accelerated color fill */ Uint32 UnusedBits3 :16; Uint32 video_mem; /* The total amount of video memory (in K) */ SDL_PixelFormat *vfmt; /* Value: The format of the video surface */ int current_w; /* Value: The current video mode width */ int current_h; /* Value: The current video mode height */ } SDL_VideoInfo;Everything I know is that according to monoceres he did a sizeof() and it returned 20 bytes, and to be only 20 bytes with all those Uint32 has to mean there are some sort of "memory sharing" (I would guess all those :1, :6 and :16 are for that) but I don't know how or what or how to convert it to AutoIt.I would be very grateful for any help on this. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Richard Robertson Posted May 18, 2009 Share Posted May 18, 2009 All of those :1 things are the widths of the fields in bytes. It's not sharing memory but actually truncating the space that the variable is allowed to occupy. Poor design if you ask me. Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted May 18, 2009 Author Share Posted May 18, 2009 Yeah I thought it could be something like that, so I tried this: #Include "SDL v5.au3" #Include <Array.au3> _SDL_Init($_SDL_INIT_EVERYTHING) $Struct = "align 1;ubyte;ubyte;ubyte;ubyte;ubyte;ubyte;ubyte;ubyte;ubyte;uint;ptr;int;int" $Surface = _SDL_SetVideoMode(640, 480, 32, $_SDL_SWSURFACE) $pTemp = DllCall($__SDL_DLL, "ptr:cdecl", "SDL_GetVideoInfo") $Created = DllStructCreate($Struct, $pTemp[0]) ConsoleWrite(@error & "/" & DllStructGetSize($Created) & "/" & @error & "/" & @CRLF) $Array = Struct2Array($Created) _ArrayDisplay($Array) _SDL_Quit() Func Struct2Array($s) Local $arr[1] For $i=1 To 100 $Tesmp = DllStructGetData($s,$i) If @error Then ReDim $arr[UBound($arr)-1] ExitLoop EndIf $arr[UBound($arr)-1] = $Tesmp ConsoleWrite($Tesmp & @CRLF) ReDim $arr[UBound($arr)+1] Next Return $arr EndFunc;==>Struct2Array But not only is it bigger than it should be (?), the text it outputs is just gibberish (if you run GetVideoInfo before SetVideoMode it should return the "best" values for your computer, otherwize it returns what is currently used). I also tried lots of variants like: $Struct = "ubyte;ubyte;uint unused1;ushort unused2;ubyte unused3;ubyte;ubyte;ubyte;ubyte;ubyte;ubyte;ubyte;uint64 unused4;uint64 unused5;uint;ptr;int;int" But it still looks like gibberish Do you have any idea how to read this from AutoIt? Or any other way? .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Valik Posted May 18, 2009 Share Posted May 18, 2009 All of those :1 things are the widths of the fields in bytes. It's not sharing memory but actually truncating the space that the variable is allowed to occupy. Poor design if you ask me.Richard, it's a good thing nobody asked you because you're completely wrong. Those are bits, not bytes. Those 12 variables take up just 32-bits of memory. It's certainly not poor design, either. I bet code that uses that is a damn good bit more readable than the alternative "if (var & 0xF0000000)" all over the place. I just don't think the code is portable (I could be wrong, however). I know there is a good reason to avoid using that notation unless absolutely necessary for optimization, however, I just can't recall what it is.At any rate, since those 12 variables take up 4-bytes and there are 4 other variables which are also 4-bytes that brings the total size of the structure up to 20 bytes (24-bytes on x64 due to the pointer). Link to comment Share on other sites More sharing options...
Wus Posted May 18, 2009 Share Posted May 18, 2009 (edited) Sooo... I don't know much about this C/C++ jazz, but I am assuming that those ":n" sections are in bits not bytes? Since if you add all of them up with that assumption (also assuming the SDL_PixelFormat pointer is 32 bits) then you end up with 20 bytes. Might be wayyy off though. Also, since they are in essence just boolean flags it seems ridiculous that they'd be more than 1 bit. EDIT: Looks like I was beat to the punch. EDIT the EDIT: Can you just pick them out as 32 bit ints and pick them apart with bitmasks like Valik showed in AutoIT? Edited May 18, 2009 by Wus Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted May 18, 2009 Author Share Posted May 18, 2009 @Valik & WusThank you both, that makes alot more sense, I run the code above with "uint;uint;ptr;int;int" and and it returns:0/20/0/200x001A5E50640480If i am getting this right I just need to BitAnd the first value to get what is enabled, right? Than means that a window manager is available, which is good I guess, but having zero hardware acceleration is a bit sad .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Wus Posted May 19, 2009 Share Posted May 19, 2009 Apparently this ":n" thing is called a bitfield, here are a few links...http://en.wikipedia.org/wiki/Bitfieldhttp://en.wikipedia.org/wiki/C_syntax#Bit_fieldshttp://msdn.microsoft.com/en-us/library/yszfawxh(VS.71).aspxGoogle Book Page with BitfieldsThere's a crapload more info out there on em, but these seem to sum it up. Link to comment Share on other sites More sharing options...
Valik Posted May 19, 2009 Share Posted May 19, 2009 Bit-field! That's it. Thank you, I couldn't remember what that syntax was called. Link to comment Share on other sites More sharing options...
Richard Robertson Posted May 19, 2009 Share Posted May 19, 2009 Ok, so I failed. I've only ever used field alignment in C# and I believe it is byte based. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now