Jump to content

SDL UDF


Recommended Posts

If you need webspace I can host you now through Oct 2014. Let me know if you are interested, I'll setup an FTP account for you on my site.

I love SDL and AutoIt I am in the process of converting my previous SDL C++ programs to your SDL_UDF, and I'm picking up ?do=embed' frameborder='0' data-embedContent> aswell..

It's going very well, I want to learn AutoIt structs better.

Quick project drawing animated tank objects on the desktop. (It will become a action multiplayer, joystick desktop fighter)

http://www.youtube.com/watch?v=t_n6INq_Yzw&feature=youtu.be

(source zip)

Please note that the source still contains the NOT CLOSING properly bug. I use CTRL+BREAK, wait 3-5seconds and press CTRL+BREAK again to close it. My prog is just an example of how SDL_UDF and ?do=embed' frameborder='0' data-embedContent> are totally awesome.

{ Player controls, keyboard

Tank_1:up, down, left, right, DRILL: pgdown, NITRO: end, JUMP: spacebar

Tank_2:w, s, a, d, DRILL: pgup, NITRO: home, JUMP: b

} use a Nitro to pickup speed fast

In C++ SDL It can say surface->w, surface->h.

and rect.x, rect.y, rect.w, rect.h (good, clean)

In AutoIt I say

$struct= DllStructCreate($tagSDL_SURFACE, $surface)
$surfw= DllStructGetData($Struct, "w")
$surfh= DllStructGetData($Struct, "h")
$struct= 0
(bad, clutter and I'm not going to function call each time)

If the struct method I used above is the only way to access members in AutoIt, then I will make an updater function to update script variables to reflect the width and height of surfaces. Just looking for a clean way to access the members and a clean way to set the rect without a _SDL_Rect_Create()

I'm asking if you know a better way to access and change members of a struct in AutoIt. I feel like I must not know what I'm doing.

edit: within 6 hours I solved my issue; I almost died. DllStructGetData() to access members.

Thank you AdmiralAlkex for bringing SDL to AutoIt and for Joe Zimmerman I only tested the function on the linked case. It returned happyness.

Edited by Xandy
Link to comment
Share on other sites

If you need webspace I can host you now through Oct 2014. Let me know if you are interested, I'll setup an FTP account for you on my site.

Thank you for your offer, but MVPs has a whopping 8MB attachment space, so I'm cool for the time being ;)

I love SDL and AutoIt I am in the process of converting my previous SDL C++ programs to your SDL_UDF, and I'm picking up aswell..

Good choices :P

Quick project drawing animated tank objects on the desktop. (It will become a action multiplayer, joystick desktop fighter)

---

Please note that the source still contains the NOT CLOSING properly bug. I use CTRL+BREAK, wait 3-5seconds and press CTRL+BREAK again to close it.

That's a great beginning! Looks like it will be a cool game. It will be very interesting to see when it's finished.

As for the crash, i guess you could say it's two-part.

To find it, I put a bunch of ConsoleWrite()s to find where the trouble was (I guess I'm old-school that way?) and found this:

for $i= 0 to $tank_drillframemax-1;loop thru all the drill movement frames
_SDL_FreeSurface($tank_drillframemax[$a][$i])
next

$tank_drillframemax is not an array so AutoIt crashes/locks up. I think that may be a copy paste error, looks like the array is $tank_drill.

Normally AutoIt would crash with the "Subscript used with non-Array variable.", pointing you to the exact location and all that which would make it easy to discover and fix, but something in the UDF causes crashes to lock up AutoIt instead of failing nicely. I don't know why. I have also fallen for this many times, I find in extremely frustrating.

But you know what you could also do? Skip it. While it's considered nice to clean up, it's technically a waste of time. The memory used by the process will be returned by Windows anyway when it closes.

I'm asking if you know a better way to access and change members of a struct in AutoIt. I feel like I must not know what I'm doing.

edit: within 6 hours I solved my issue; I almost died. DllStructGetData() to access members.

Yeah exactly, you use DllStruct* functions. It's kind of a bother, I hope AutoIt can do it the c++ way in the future.

Thank you AdmiralAlkex for bringing SDL to AutoIt and for Joe Zimmerman I only tested the function on the linked case. It returned happyness.

Hehe, thank you back. Will you believe me if I tell you that Joe Zimmerman was an accident? I'm a huge fan of Star Trek, and one of the best characters in Voyager is The Doctor. He didn't have a name until the last episode when he became known as Joe. And his creators last name was Zimmerman, so I put those together for some kind of obscure easter-egg. I only discovered the comedian later :lol:

Sorry for taking so much time to answer.

Link to comment
Share on other sites

  • 2 months later...

Hey guys, I have a little problem. I downloaded SDL UDF v14½ from first post, and when I running example scripts then I got this:

Loaded SDL_image version: 1.2.7.*

Loaded SDL version: 1.2.8.*

This script was built for SDL 1.2.13.* Using a dll of another version is not supported

in output conosle. Help! How to repair this? ;(
Link to comment
Share on other sites

  • 4 weeks later...

Hey guys, I have a little problem. I downloaded SDL UDF v14½ from first post, and when I running example scripts then I got this:

in output conosle. Help! How to repair this? ;(

Oops, I had forgotten about you. Well, either use the file in the download as that is 1.2.13, or remove the version check from _SDL_Init() and use your own file. SDL like their compatibility more than us so it is likely to work anyway.

Link to comment
Share on other sites

  • 1 year later...

Welcome back to the wonderful and slightly messy world of structs!

    • If you got the SDL_Rect from _SDL_Rect_Create(), that function is slightly silly/stupid. Change

      $pRect = DllStructCreate("short;short;ushort;ushort")
       

      to

      $pRect = DllStructCreate($tagSDL_Rect)
       

      so structure elements can be referred by names and not just numbers

    • If you got a pointer from somewhere else, then use DllStructCreate($tagSDL_Rect, $pointer)
    • Now, like in your post earlier (>#81) use DllStructGetData() to read a element of the structure. For example, to read y, you would use DllStructGetData($var, "y") or DllStructGetData($var, 2)
    • Dot notation for structures have been available for a while now, (which means you can read and write y with $structure.y instead of DllStructGetData() & DllStructSetData()). I can't remember if that feature actually ever was publicly announced, but it's still working in the latest stable so I guess you can go ahead and use it if you want.
You still working on that tank-desktop-fighter-game? Must be a giant after all this time! ;)
Link to comment
Share on other sites

You still working on that tank-desktop-fighter-game? Must be a giant after all this time! ;)

Haha, Well sort of.

I haven't directly worked on that project in a long time. One of the things the project requires is a control system for players.

I'm making a >configure controls UDF using Mat's GUIHotkey.au3 so that I can share the script here.

It's taking a while because now I need two types of controls and interfacing.  Where before I only needed input fields, but then the key event loop would look all keylogger like.

So once I make configurecontrols pretty and get it approved to post here, I'll post it with the game above as a test example for the configurecontrols UDF.

Of course the game will still be unfinished, but people could add to it.

Everything you mentioned will be useful to me.  I tried many times before to DllStructCreate($tagSDL_Rect, $rect) and it just wasn't working out for me.  I kept wondering if I could use the dot syntax too.  I made the changes and it works fine.

Awesome!  Thank you!

Edited by Xandy
Link to comment
Share on other sites

  • 2 weeks later...

You still working on that tank-desktop-fighter-game? Must be a giant after all this time! ;)

It's right here. >SDL Configure Controls UDF

The Tank files are included in the source zip.

I'll (probably) work on it more now that I have configure control reasonably finished.

Edited by Xandy
Link to comment
Share on other sites

  • 3 years later...

I have an array of Surfaces loaded from a sprite_sheet file.

I try to list them in a comboboxEx but I do not know how to convert the Surfaces to hImage.

I ask if anyone knows how to do this without saving each array index to pic file.

Local $hImage = _GUIImageList_Create($gTile_w, $gTile_h, 6); Image List for ComboboxEx
For $i = 0 To 1
    ; This works but only from file:
    ;_GUIImageList_AddBitmap($hImage, $gFolder_graphics & $gaWorld_info[$player.iWorld_cur][$eWi_filename] & "Tiles\" & $i & ".bmp")
    ; This doesn't display the image in the combobox
    _GUIImageList_Add($hImage, $aNPC_surf[1][1][1][$i])

    _GUICtrlComboBoxEx_AddString($aControl[$eNPC_iPic_type][$eControl_data], $i, $i, $i)
Next
; Set Image list
_GUICtrlComboBoxEx_SetImageList($aControl[$eNPC_iPic_type][$eControl_data], $hImage)

The exact array index surface does display with SDL functions.  Just image doesn't get added to comboboxEx list.

 

In video I show comboxbox showing images (from files).  Then I show my problem, different images not loading into combobox image list from memory.  Woman at top left is the array index surface.

Spoiler

 

 

I have a method to go from hBitmap to SDL_Surface.  But I don't know how to go from SDL_Surface to hBitmap or hImage.

Edited by Xandy
Link to comment
Share on other sites

  • 1 month later...
On ‎2017‎-‎12‎-‎31 at 10:02 PM, Xandy said:

I have a method to go from hBitmap to SDL_Surface.  But I don't know how to go from SDL_Surface to hBitmap or hImage.

Sorry I have no idea. I haven't worked on anything SDL-related in a really long time.

Link to comment
Share on other sites

  • 11 months later...
On 04/02/2018 at 5:56 PM, AdmiralAlkex said:

Sorry I have no idea. I haven't worked on anything SDL-related in a really long time.

Hello, I need a quick 2D graphic interface, I'm looking into the SDL functions and I find no option to write texts. I tried with irrlich and the way of drawing texts is pretty basic. Can you give me an idea? (Google Translator)

Link to comment
Share on other sites

@PedroWarlock

My SDL Print function: SDL_Print.zip

The example: "Print Test.au3"

; Print Test
#include "Include/Print.au3"
#include <GUIConstants.au3>
OnAutoItExitRegister("_Exit")

; Unmarked Globals: screen, font

Main()

Func Main()
    Local $iSCR_W = 320, $iSCR_H = 200

    $hGUI = GUICreate("", $iSCR_W, $iSCR_H)
    EnvSet("SDL_WINDOWID", $hGUI) ; Remark this to create AutoIt window and recieve error messages from AutoIt
    GUISetState()

    ; Font to load.  This font is 9x9 pixels.
    $Font_Image_Path = @ScriptDir & "\Graphics\Fonts\qbasic_screen13.txt"
    ; Startup some SDL
    $winTitle = StringTrimRight(@ScriptName, 4)
    $SDL_STARTUP_FLAGS = BitOR($SDL_INIT_IMAGE, $SDL_INIT_SGE, $SDL_INIT_GFX, $SDL_INIT_SPRIG)
    SDL_Template_Init($iSCR_W, $iSCR_H, 32, $winTitle, $SDL_STARTUP_FLAGS, "", $Font_Image_Path)

    ; Print to screen
    ; Line 1
    Local $x = 10, $y = 10
    Local $r = 255, $g = 255, $b = 255
    Local $scale_x = 2, $scale_y = 2
    print("SDL_Print", $screen, $x, $y, $r, $g, $b, $scale_x, $scale_y)
    ; Line 2
    $y += $font.iH * $scale_y + 5
    Local $b = 0, $g = 0
    print("Hello", $screen, $x, $y, $r, $g, $b)
    _SDL_Flip($screen)

    Do
        $msg = GUIGetMsg()
    Until $msg = $GUI_EVENT_CLOSE

EndFunc; Main

; Registered to be called at exit
Func _Exit()
    ; If you don't do this script may hang in Scite after being stopped and not re-run until CTRL+BREAK
    If $__SDL_DLL <> -1 Then _SDL_Quit()
    If $__SDL_DLL_image <> -1 Then _SDL_Shutdown_image()
    If $__SDL_DLL_sge <> -1 Then _SDL_Shutdown_sge()
    If $__SDL_DLL_sprig <> -1 Then _SDL_Shutdown_sprig() ;)
    If $__SDL_DLL_GFX <> -1 Then _SDL_Shutdown_gfx()
EndFunc   ;==>_Exit

Output:

SDL-Print.png

The font can be scaled in the print function, but it is always faster to have a default size. 

The file: Font/qbasic_screen13.png is 9x9.

The file: Font/qbasic_screen_Scaled.png is 18x18.

Load the better default for the current project and you can still scale on the fly from the default.

PS: Freetype font and TTF are probably better.  I wouldn't know.

Edited by Xandy
Link to comment
Share on other sites

@PedroWarlock

We will have to wait for some body with more knowledge.  I provided the only way I have used a font in SDL.  Another trick I use with the system I gave you is, only draw text on text change.  In all other cases, simply re-blit the surface text was rendered to.  Even the re-blit doesn't need to be every cycle.  Very fast.

Edited by Xandy
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...