Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Maxim: Use of SDK for wrapping the Irrlicht

  1. #1

    Maxim: Use of SDK for wrapping the Irrlicht

    Quote Originally Posted by Petr Schreiber View Post
    Hi Largo_Winch, if include file works, the module would be redundant I guess. Some time ago, the DECLAREd functions in includes had slower execution than module based keywords, but I think the difference is no more so big. That is the reason why for example OpenGL is provided via header and not module. The general rule I follow is:
    • if it is just a wrapper of existing DLL -> make include
    • if it is something more, computionaly expensive and so on, then module is the way to go
    Petr
    Thanks Petr, now i better understand Largo's question. I use includes becouse not want use compiler and yes, it is enough fast (develop and launch). My question about new functional with classes: can use this dynamically?
     %thinBasic_ReturnNone             =  &h0
    %thinBasic_ReturnCodeByte         =  &h1
    %thinBasic_ReturnCodeInteger      =  &h2
    %thinBasic_ReturnCodeWord         =  &h3
    %thinBasic_ReturnCodeDWord        =  &h4
    %thinBasic_ReturnCodeLong         =  &h5
    %thinBasic_ReturnCodeQuad         =  &h6
    %thinBasic_ReturnCodeSingle       =  &h7
    %thinBasic_ReturnCodeDouble       =  &h8
    %thinBasic_ReturnCodeCurrency     =  &h9
    %thinBasic_ReturnCodeExt          = &h10
    %thinBasic_ReturnNumber           = &h20
    %thinBasic_ReturnString           = &h30
    
    Declare Function FunctionGetPtr Lib "thinCore.dll" Alias "thinBasic_FunctionGetPtr" (ByVal fName As String) As Long
    Declare Function thinBasic_LoadSymbol Lib "thinCore.dll" Alias "thinBasic_LoadSymbol" (ByVal SymbolName As String, ByVal ReturnCode As Long, ByVal FunctionOrSubPointer As Dword, Optional ByVal ForceOverWrite As Long) As Long
    Declare Function thinBasic_Class_Add Lib "thinCore.dll" Alias "thinBasic_Class_Add" (ByVal sClassName As String, ByVal pClassFunc As Long) As Long
    Declare Function thinBasic_Class_AddMethod Lib "thinCore.dll" Alias "thinBasic_Class_AddMethod" (ByVal pClass As Long, ByVal sMethodName As String, ByVal MethodReturnType As Long, ByVal pMethodFunc As Long) As Long
    Local RetCode As Long
    TYPE IrrlichtDevice DWORD
         getVersion As ASCIIZ
    END TYPE
    Local IrrlichtDevicePtr As Long = thinBasic_Class_Add("IrrlichtDevice", Function_GetPtr(IrrlichtDevice_run))
    If IrrlichtDevicePtr Then
         RetCode = thinBasic_Class_AddMethod(IrrlichtDevicePtr, "run", %thinBasic_ReturnNumber, Function_GetPtr(IrrlichtDevice_run))
         RetCode = thinBasic_Class_AddMethod(IrrlichtDevicePtr, "getVersion", %thinBasic_ReturnString, Function_GetPtr(IrrlichtDevice_getVersion))
    Else
         Uses "console"
         PrintL "ERROR thinBasic_Class_Add IrrlichtDevice"
    End If
    
    Function_GetPtr is not valid for this target, what is correct function for get code pointer?

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi Maxim,

    the code in one line is a bit hard on the eyes, do you think you could break it to lines?

    thinBasic_FunctionGetPtr is function, which serves to retrieve something like code pointer to function defined in ThinBASIC code, but it is not synonym of classic CODEPTR in compiled code. The value returned by thinBasic_FunctionGetPtr is designed to be used with thinBasic_FunctionSimpleCall_ByPtr or thinBasic_FunctionCall_ByPtr.

    Please have a look to your ThinBASIC/SDK directory, unzip the ZIP file, and check out for example the sample module in thinBasic\SDK\thinBasic BASIC SDK\PB\.

    You will see the function referenced by function pointer must perform the parsing of parameters on its own, via stuff calls to things like thinBasic_ParseNumber and so on, you cannot directly wrap functions from DLL this way.

    It also seems you are trying to use SDK functions in ThinBASIC code. It is possible, but you won't create module this way. You need some compiler, such as PowerBASIC, to produce the module DLL.
    If you want to create Module Class, you currently need to create the class internally as COM class, and then wrap it.

    I hope this text helped you a bit. If not please do not hesitate to ask, but please do it in the dedicated thread in ThinBASIC SDK forum, to not interfere with effort of Largo_Winch.


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    Quote Originally Posted by Petr Schreiber View Post
    Hi Maxim,the code in one line is a bit hard on the eyes, do you think you could break it to lines?thinBasic_FunctionGetPtr is function, which serves to retrieve something like code pointer to function defined in ThinBASIC code, but it is not synonym of classic CODEPTR in compiled code. The value returned by thinBasic_FunctionGetPtr is designed to be used with thinBasic_FunctionSimpleCall_ByPtr or thinBasic_FunctionCall_ByPtr.Please have a look to your ThinBASIC/SDK directory, unzip the ZIP file, and check out for example the sample module in thinBasic\SDK\thinBasic BASIC SDK\PB\.You will see the function referenced by function pointer must perform the parsing of parameters on its own, via stuff calls to things like thinBasic_ParseNumber and so on, you cannot directly wrap functions from DLL this way.It also seems you are trying to use SDK functions in ThinBASIC code. It is possible, but you won't create module this way. You need some compiler, such as PowerBASIC, to produce the module DLL.If you want to create Module Class, you currently need to create the class internally as COM class, and then wrap it.I hope this text helped you a bit. If not please do not hesitate to ask, but please do it in the dedicated thread in ThinBASIC SDK forum, to not interfere with effort of Largo_Winch.Petr
    Again thanks Petr.I do code with many lines, but when I press "Submit Reply" button, I have result as you see (my browser was Firefox).Sorry for my question here, I do this question before with class article topic, but not get answer and repeated here.I promise not to do so more.

  4. #4
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    No problem,

    I just split the thread.
    Regarding posting - I use Firefox 5.0, and if I paste from ThinAIR, the code aligns properly. Do you have the same FF version?


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  5. #5
    Quote Originally Posted by Petr Schreiber View Post
    No problem,I just split the thread.Regarding posting - I use Firefox 5.0, and if I paste from ThinAIR, the code aligns properly. Do you have the same FF version?Petr
    FF was 4.0.1 now I do update to 5.0 (thank you) and I paste code from Notepad

  6. #6
    I do as you say and press "Preview Post" button - same result. My post also edited as one line, but I write many lines. I try ie browser - same result. I do attached file to better understand my question.
    Attached Files Attached Files

  7. #7
    %thinBasic_ReturnNone             =  &h0
    %thinBasic_ReturnCodeByte         =  &h1
    %thinBasic_ReturnCodeInteger      =  &h2
    %thinBasic_ReturnCodeWord         =  &h3
    %thinBasic_ReturnCodeDWord        =  &h4
    %thinBasic_ReturnCodeLong         =  &h5
    %thinBasic_ReturnCodeQuad         =  &h6
    %thinBasic_ReturnCodeSingle       =  &h7
    %thinBasic_ReturnCodeDouble       =  &h8
    %thinBasic_ReturnCodeCurrency     =  &h9
    %thinBasic_ReturnCodeExt          = &h10
    %thinBasic_ReturnNumber           = &h20
    %thinBasic_ReturnString           = &h30
    
    Declare Function FunctionGetPtr Lib "thinCore.dll" Alias "thinBasic_FunctionGetPtr" (ByVal fName As String) As Long
    Declare Function thinBasic_LoadSymbol Lib "thinCore.dll" Alias "thinBasic_LoadSymbol" (ByVal SymbolName As String, ByVal ReturnCode As Long, ByVal FunctionOrSubPointer As Dword, Optional ByVal ForceOverWrite As Long) As Long
    Declare Function thinBasic_Class_Add Lib "thinCore.dll" Alias "thinBasic_Class_Add" (ByVal sClassName As String, ByVal pClassFunc As Long) As Long
    Declare Function thinBasic_Class_AddMethod Lib "thinCore.dll" Alias "thinBasic_Class_AddMethod" (ByVal pClass As Long, ByVal sMethodName As String, ByVal MethodReturnType As Long, ByVal pMethodFunc As Long) As Long
    
    Local RetCode As Long
    
    TYPE IrrlichtDevice DWORD
    	getVersion As ASCIIZ
    END TYPE
    
    Local IrrlichtDevicePtr As Long = thinBasic_Class_Add("IrrlichtDevice", Function_GetPtr(IrrlichtDevice_run))
    If IrrlichtDevicePtr Then
    	RetCode = thinBasic_Class_AddMethod(IrrlichtDevicePtr, "run", %thinBasic_ReturnNumber, Function_GetPtr(IrrlichtDevice_run))
    	RetCode = thinBasic_Class_AddMethod(IrrlichtDevicePtr, "getVersion", %thinBasic_ReturnString, Function_GetPtr(IrrlichtDevice_getVersion))
    Else
    	Uses "console"
    	PrintL "ERROR thinBasic_Class_Add IrrlichtDevice"
    End If
    
    I change with "My Profile" "General Settings" editor from "Enhanced Interface - Full WYSIWYG Editing" (default) to "Standard Editor - Extra formatting controls" and now BB code tag and break lines is worked.

  8. #8
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi Maxim,

    I think for what you need, you would need to create compiled module first, where:
    • you would create internal COM wrapper for each of the Irrlicht classes with all functions (phew, lot of them!)

    So for example for IrrlichtDevice, you would need to do (in PowerBasic):
    CLASS CIrrlichtDevice
      INSTANCE pDevice AS DWORD
     
      INTERFACE IIrrlichtDevice
        INHERIT IUnknown
    
        METHOD CreateDevice(BYVAL deviceType AS LONG, BYVAL windowSize AS DWORD, BYVAL BITS AS WORD, BYVAL fullscreen AS BYTE, BYVAL stencilbuffer AS BYTE, BYVAL vsync AS BYTE, BYVAL receiver AS DWORD)
          pDevice = IrrlichtDevice_createDevice(deviceType, windowSize, bits, fullscreen, stencilbuffer, vsync, receiver)
        END METHOD
    
        METHOD Run()
          IrrlichtDevice_run(pDevice) ' -- This we have stored thanks to previous CreateDevice method call
        END METHOD
    
        ' .. and so on, wrapper for everything
    
      END INTERFACE
    END CLASS
    
    Then you would need to create the ThinBASIC wrappers for methods:
        ' -- pClass identifies the class as such in later code (when adding methods)
        LOCAL pClass AS LONG
        pClass = thinBasic_Class_Add("IrrlichtDevice", 0)
    
        ' -- If the creation of class succeeded, we can proceed adding methods
        IF pClass THEN
          ' -- _Create method is used for constructor
          thinBasic_Class_AddMethod(pClass, "_Create" , %thinBasic_ReturnNone , CODEPTR(keyword_IrrlichtDevice_Create))
    
          ' -- _Destroy method is used for destructor
          thinBasic_Class_AddMethod(pClass, "_Destroy" , %thinBasic_ReturnNone , CODEPTR(keyword_IrrlichtDevice_Destroy))
    
          ' -- CreateDevice method
          thinBasic_Class_AddMethod(pClass, "CreateDevice" , %thinBasic_ReturnNone , CODEPTR(keyword_IrrlichtDevice_CreateDevice))
    
          ' -- Run method
          thinBasic_Class_AddMethod(pClass, "Run" , %thinBasic_ReturnNone , CODEPTR(keyword_IrrlichtDevice_Run))
    
          ' -- and so on for others
        END IF
    
    • and of course create the wrapper functions which interact with parser

    SUB keyword_IrrlichtDevice_Create(BYVAL pInstance AS LONG)
    
      ' -- Instantiate object
      REDIM obj(1 to 1) AS IIrrlichtDevice AT pInstance
      obj(1) = CLASS "CIrrlichtDevice"
    
    END SUB
    
    SUB keyword_IrrlichtDevice_CreateDevice(BYVAL pInstance AS LONG)
      LOCAL deviceType, windowSize, bits, fullscreen, stencilbuffer, vsync, receiver AS EXT
    
      ' -- Get reference to object
      REDIM obj(1 to 1) AS IIrrlichtDevice AT pInstance
    
      ' -- Get params for it from parser
      thinBasic_Parse7Numbers(deviceType, windowSize, bits, fullscreen, stencilbuffer, vsync, receiver)
    
      ' -- Call the method
      obj(1).CreateDevice(deviceType, windowSize, bits, fullscreen, stencilbuffer, vsync, receiver)
    
    END SUB
    
    ... and so on


    Petr
    Last edited by Petr Schreiber; 03-07-2011 at 14:47.
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  9. #9
    Thanks Petr.
    If I understand all this code is PowerBasic and PowerBasic is not free?

  10. #10
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi Maxim,

    modules with classes can currently be created using PowerBASIC for Windows 9. This commercial compiler is currently superceded by (also suitable) version 10 ($199), but if we are lucky, they might once provide "Classic" edition of the v9 compiler, which could be at nicer $49.

    Modules with keywords, constants and user defined TYPEs can be still easily created using FreeBASIC, C, PowerBASIC and maybe even others - example is in SDK folder.

    As the CLASSes development for modules is in initial stage, I am sure Eros can be open to other compilers as well - we would "just" need to find a way which is cross-compiler.
    The problem is mostly one - procedures are quite standardised thing, they might differ in calling convention, but that is easy to cover, and that is why SDK for procedural interface is basically no problem in any language which can create DLLs.
    But with objects, the situation is different. COM is at least partially something, which you can see implemented in multiple languages (but I have no experience with it in them).

    I think I am now reaching the boundaries of my knowledge, I think Eros can tell you more. Maybe if you create COM object in C++ it will work as well?


    Petr
    Last edited by Petr Schreiber; 07-07-2011 at 11:04.
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

Page 1 of 2 12 LastLast

Similar Threads

  1. Wrapping DLL functions bug
    By Bagamut in forum Xors3D Graphics Engine
    Replies: 7
    Last Post: 09-01-2011, 22:37
  2. a 3D web browers using Irrlicht
    By ErosOlmi in forum Software discussion
    Replies: 0
    Last Post: 05-05-2007, 18:25

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •