tSx development in Visual Basic?

About Truespace Archives

These pages are a copy of the official truespace forums prior to their removal somewhere around 2011.

They are retained here for archive purposes only.

tSx development in Visual Basic? // Archive: Tech Forum

1  |  

Post by frank // Jan 18, 2007, 9:54am

frank
Total Posts: 709
pic
I know C++ and Delphi are the standard languages to code plugins for trueSpace, but I remember a few years back when Scott Miles wrote a tool for VB programmers to write tS-compatible plugins (of course, it's no longer available, as with most of his site).


Just did some searching around on my computer here and found some old sample framework code. However, all I really have is this one file and no other libraries or anything. I also have the compiled DLL but it doesn't work. tS6.6 reports "Not a valid trueSpace eXtension"


Plugin developers will recognize the tS-required export functions here, although in VB format:



Public Type tsxData

m_Title As String

m_Author As String

m_ResidBtnBmp As Long

m_ResidBtnHelp As Long

End Type


Public Function tsxOnRightClick()

MsgBox "You right clicked on the plugin icon!"

End Function


Public Function tsxOnLeftClick() As Integer

tsxOnLeftClick = tsxPLUG_DONE

End Function


Public Function tsxDeactivate()

MsgBox "tsxDeactivate was just called!"

End Function


Public Function tsxGetVersion(tsxid As Integer) As Integer

tsxGetVersion = 510

End Function


Public Function tsxGetData(ByRef tsx_Data As String, ByVal tsxid As Integer) As Integer


tsxData.m_Author = "Author Name Here"

tsxData.m_Title = "Plugin Name Here"

tsxData.m_ResidBtnBmp = 1

tsxData.m_ResidBtnHelp = 2


tsxGetData = 1




End Function



Anyway, Scott figured out how to get VB DLLs to work in trueSpace, so do any of you other brilliant-minded folks have ideas on how to do this?


P.S. I'm using Visual Basic 6

Post by frank // Jan 18, 2007, 11:05am

frank
Total Posts: 709
pic
I may be making some headway.


There are some things you have to change about the way VB complies, so that the DLL exports are handled correctly.


We'll see...

Post by frank // Jan 18, 2007, 11:43am

frank
Total Posts: 709
pic
Closer...


It is no longer telling me "Not a valid trueSpace extension", but is giving me an error message which lets me know trueSpace is talking to my DLL.


The issue will be figuring out how to pass the GetData info from VB to trueSpace in a way that makes trueSpace happy.

Post by jamesmc // Jan 18, 2007, 12:03pm

jamesmc
Total Posts: 2566
I know there are VB to C# converters, saw them somewhere, maybe on Delphi.


Have you tried these?


It might be a plethora of error statements, but perhaps a path to completion of your project.

Post by chamaeleon // Jan 18, 2007, 2:30pm

chamaeleon
Total Posts: 74
I'm pretty sure the problem for VB pre-.NET is that it does not expose functions in dll's in the same manner as C/C++ (ie, cdecl, which is what trueSpace expects the plugin to do), and most solutions tend to be implement it as an ActiveX control. In this particular case, it would mean it would be necessary to write two components (the second would be a thin wrapper that activates the ActiveX control and translates the C calls from trueSpace to COM invocations on the control).


http://groups.google.com/group/microsoft.public.vb.winapi/browse_thread/thread/d4f97b41c6618ef7/b09e85490c20f8c3?lnk=st&q=vb6+export+function&rnum=27#b09e85490c20f8c3


I cannot say what kind of approach Scott Miles took at the time as I never looked at it.

Post by frank // Jan 18, 2007, 3:15pm

frank
Total Posts: 709
pic
I'm pretty sure the problem for VB pre-.NET is that it does not expose functions in dll's in the same manner as C/C++


You are correct about that. I did some research and found out a way to "trick" the linker. What you do is build your own link.exe that takes the command-line arguments and modifies them (primarily, to make it recognize the .DEF file, which contains the 6 main tS export functions), and then passes the info along to the real link executable, which has been renamed.


Pretty strange workflow but it does allow you to make DLLs with exposed functions.


More info: http://www.windowsdevcenter.com/pub/a/windows/2005/04/26/create_dll.html


UPDATE: This is interesting: http://awc.al-williams.com/tips/tip30.htm Digesting now...

Post by frank // Jan 19, 2007, 6:40am

frank
Total Posts: 709
pic
Doing CDECL function calls w/ callbacks and such looks to be quite tricky in Visual Basic.


Did some further research and PowerBASIC offers the ability to create true DLLs. Maybe that's something I should try, as making the move to that vs. jumping into Visual C++ would be easier.


Not sure yet - still reading and searching a bunch...

Post by TomG // Jan 19, 2007, 7:48am

TomG
Total Posts: 3397
Make the jump to C++, or C# (I wonder how XNA works for making this sort of thing, if at all?). Those are nice languages, they seem "weird" at first but I prefer them now to VB now that I am used to them and wouldn't want to write code in anything else these days :) It wasn't that hard to learn either (though I am but a beginner in such things and only do simple stuffs, all my real programming was actually for IBM Mainframes).


Anyway, good luck in whatever language you choose!


HTH!

Tom

Post by chamaeleon // Jan 19, 2007, 8:21am

chamaeleon
Total Posts: 74
C#, etc, wouldn't be particularly suitable, unless you feel like messing with COM/.NET interoperability (a C++ based tsx would create a bridge for the .NET component that would do the real work). VC++ generating Win32 dlls is still the best way to go when using Microsoft tools, in my opinion.


As I've mentioned to Frank in private, would Caligari extend trueSpace to allow for .NET components to be loaded, I would happily switch to F# though. :)

Post by frank // Jan 19, 2007, 10:36am

frank
Total Posts: 709
pic
Tom: :) Yeah, I kinda feel like I "need" to learn C. Thing is, I have books on it, and can look at C/C++ code and comprehend what's going on, but...


I've been doing BASIC stuff since the QBasic days. I know it to the point I can just about speak it. ...if that makes sense. LOL!


I went ahead and purchased PowerBASIC. Builds really small and fast TRUE EXEs - no interpreters and no dependencies (unless you want them).


Can compile real Win-32 CDECL DLLs w/ exports, etc.


Will be doing some experiments shortly.

Post by frank // Jan 19, 2007, 11:12am

frank
Total Posts: 709
pic
UPDATE: Weeehaaa! Got my DLL to load into trueSpace. I have it set to do message boxes for the various events (right-click, left-click).


The tSx icon is just a grey box, though. Have to figure out how to load bitmap and string resources now.


Also I'm learning how to convert the data types. For instance:


C++

struct tsxData

{

char m_Title[32];

char m_Author[64];

short m_ResidBtnBmp;

short m_ResidBtnHelp;

};


PowerBASIC

TYPE tsxData

m_Title(0 TO 31) AS BYTE

m_Author(0 TO 63) AS BYTE

m_ResidBtnBmp AS INTEGER

m_ResidBtnHelp AS INTEGER

END TYPE


Exciting so far!

Post by frank // Jan 19, 2007, 3:09pm

frank
Total Posts: 709
pic
Making calls to the tsxapi.dll ... BUT...




DECLARE FUNCTION tsxAnimGetBaseFramerate CDECL LIB "c:\truespace66\tsxapi.dll" ALIAS "tsxAnimGetBaseFramerate" () AS SINGLE


...


FUNCTION tsxOnLeftClick CDECL ALIAS "tsxOnLeftClick" () EXPORT AS INTEGER

MSGBOX "tsxOnLeftClick()"


DIM x AS SINGLE

x = tsxAnimGetBaseFramerate

MSGBOX STR$(x)

tsxOnLeftClick = 0


END FUNCTION






The above returns "29.97", no matter what the framerate is on (and I always leave mine on 24).


So that lets me know it's apparently not pulling from the "live" running DLL, which leads me to think that somehow I have to incorporate "tsxapi.lib" into the mix. I know it's done in VC++ 6 through the configuration/settings menu.


Approximately how would this be done in PowerBASIC? Am I even correct in my assumption?


As added confirmation, I made a call to "tsxAnimGetActiveTime" and it returns "0", no matter what frame it's on.

Post by Chester Desmond // Jan 19, 2007, 4:01pm

Chester Desmond
Total Posts: 323
Not sure what you're trying for but I want caustics and fur. :banana:


this thread is all greek to me, but I did download everything to do with making plugs in VB (all the stuff from PI) when I thought I could learn greek. If you can't find something related to that, I may have it here.

Post by frank // Jan 19, 2007, 6:35pm

frank
Total Posts: 709
pic
WEHAAAA!!!!!


DECLARE FUNCTION tsxAnimGetBaseFramerate CDECL LIB "tsxapi.dll" ALIAS "tsxAnimGetBaseFramerate" () AS SINGLE


I took out the reference to tsxapi w/ the full path ("c:\truespace66\tsxapi.dll") and it's now working. I can change the framerate in tS and when I click my plugin, it gives me the correct number.


Now it's time to work on my "ShapeSwapper" plugin.


and then... the Computational Fluid Dynamics plugin. ;) (after I learn me some maths)

Post by GraySho // Jan 20, 2007, 4:38am

GraySho
Total Posts: 695
pic
Das hast du gut gemacht ;)


I get you are realizing your own plugin suggestion for lip sync, very cool.


:banana:

Post by chamaeleon // Jan 20, 2007, 6:54am

chamaeleon
Total Posts: 74
Congratulations, Frank. :)

Post by frank // Jan 20, 2007, 8:18pm

frank
Total Posts: 709
pic
Thanks, GraySho and Chamaeleon!


I recently learned how to reference the resource ID for the bitmap, and pass it along to trueSpace.


Working on converting trueSpace data types from C to PowerBASIC. Lots of fun!

Post by ProfessorKhaos // Jan 22, 2007, 7:58pm

ProfessorKhaos
Total Posts: 622
pic
You guys are starting to scare me with all this tech talk :)


Nice to know you've got this plugin thing down Frank! Can't claim I did as well (even with VC++) when I was trying to compile my own shaders though I did ultimately get some help along the way (thanks Gord!)


Now, let's see some cool stuff!!!!

Post by frank // Jan 23, 2007, 3:51am

frank
Total Posts: 709
pic
Howdy, Professor!


Thanks! Still got a lot to figure out, though. Chamaeleon and the nice folks at PowerBASIC have been very helpful.


You should maybe get back into it. The plugin development community has dwindled down quite a bit.

Post by ProfessorKhaos // Jan 23, 2007, 5:05am

ProfessorKhaos
Total Posts: 622
pic
I guess that's true. Hasn't been quite as much activity since tS4 in terms of plugins. In some ways I think scripts and widgets will take over much of the functionality down the road but that's not to say that tSx won't still be useful. Plugins like UVCow required an interface beyond the capabilities of the current 2D rosetta panels and that's where the flexibility of making your own tSx really shines!


I loved shaderlab for it's ability to provide a good prototyping environment for shaders but turned to C++ when I needed more input parameters than shaderlab was capable of using.


Chamaeleon has always been an awesome resource for us script writers and coders. What mesher did for python was incredibly huge. Actually, the lessons I learned there have helped me immensely in my current LED project because it taught me how to assemble meshes from scripted instructions. If only python was a bit friendlier to use back then I think it would have really taken off.


Hmmm... that reminds me. Maybe I can port my roller coaster making script over to tS7 from python. Ought to be pretty easy to do at this point.

Post by Alien // Feb 26, 2007, 2:37pm

Alien
Total Posts: 1231
pic
As I've mentioned to Frank in private, would Caligari extend trueSpace to allow for .NET components to be loaded, I would happily switch to F# though. :)

Sadly a lot of this programming talk is over my head, but the 1 thing I will say is that I am not exactly thrilled at the concept of Caligari letting .Net anywhere near trueSpace. Why? In my experience [using, not programming] stuff made with .Net tends to be slow, & very CPU hungry. Best example I can give off the top of my head is the ATI Catalyst Control Centre, which is seriously slow compared to the old ATI Control Panel [or whatever they called it] that they made before they switched to making stuff with .Net.
Awportals.com is a privately held community resource website dedicated to Active Worlds.
Copyright (c) Mark Randall 2006 - 2021. All Rights Reserved.
Awportals.com   ·   ProLibraries Live   ·   Twitter   ·   LinkedIn