Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DLL Talk / The Matrix1Utils plugins collection

Author
Message
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th Dec 2011 12:05
I should have added some detail to the help for that - it's simple enough though.

Locate the following directory in your DBPro installation directory: Compiler\lang\english (for english language, obviously - amend for other languages).

In that directory you'll find a file called Errors.txt. Within that text file, you'll file a section labelled [RUNTIME], followed by a list of all the possible standard DBPro error messages.

Example selection from the file:


GIDustin
16
Years of Service
User Offline
Joined: 30th May 2008
Location:
Posted: 30th Dec 2011 03:29
Hey Ian,

This code crashes when you CTRL ALT DEL, or at least it does for me. Any ideas?

Lawrence Shen
15
Years of Service
User Offline
Joined: 13th Feb 2009
Location:
Posted: 31st Dec 2011 07:58
Do you have a plan for AppGameKit?
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 31st Dec 2011 13:04
No, I haven't touched the AppGameKit for a few months now - I don't have an AppGameKit compatible phone yet. When I do, and when Lee provides the ability to us to create plug-ins, then I may put together plug-in sets for each platform in AppGameKit too.

BTW, I haven't gotten to the bottom of the crash just yet.

In addition, you may either want to switch to the log commands for logging, or enable flushing when writing to your log file so that complete lines are written.

Alaror
13
Years of Service
User Offline
Joined: 9th May 2011
Location:
Posted: 1st Jan 2012 19:03 Edited at: 1st Jan 2012 19:04
Hey IanM!

I was wondering if there was any more information available somewhere about how to work with your MAKE OBJECT PLANE command. I'm looking for an alternative to the default MATRIX commands using objects instead (having issues getting the display priority to work correctly between objects and matrices; changing the terrain to objects would solve it). Would it be possible to texture individual tiles of the plane using a tilemap of some sort? The terrain needs to be updated at every step so speed is a huge consideration (tried working with memblocks but they appear to be too slow).

Thanks for your time as always


EDIT: If you'd rather me create a separate topic for the question to not spam this one please let me know.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 1st Jan 2012 23:23
The planes created by my commands aren't really suitable for tile-maps.

Where each corner of a square on a matrix has it's own vertex and therefore texture coordinates which can be adjusted independently, the squares on plane share each vertex with the surrounding squares.

That makes for great and fast terrain height adjustment when using a single big texture as you only need to amend a single vertex to raise a corner, but it's death on tile-mapping.

Alaror
13
Years of Service
User Offline
Joined: 9th May 2011
Location:
Posted: 2nd Jan 2012 22:48
Ah alright I see, thanks for clearing it up. Guess I'll have to keep looking!
Manson_NS
20
Years of Service
User Offline
Joined: 4th May 2004
Location: Denmark
Posted: 5th Jan 2012 19:57
Hi guys,
I am having a very weird crash, which I have no idea where is originating. The only thing I can think of would be the Matrix1 plugin, seeing as that is the only thing I keep updating (I think there's a compliment in there Ian, only it's not that apparent)

If somebody'd please see if this code results in a crash:
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 5th Jan 2012 20:17
Hi Mamspm_NS, the problem with that code lies between [suspend for key] and your function declaration. There must be an [end] command before the function declaration. The program should never alow a function declaration to be run. The end command will close the program and prevent it from running the into the function.

sladeiw
15
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 5th Jan 2012 20:36
I'm guessing you're using Vista or Win 7, in which case returning a string literal will crash your app. This fixes it:

Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 5th Jan 2012 20:47
Hmm, never knew that.

Manson_NS
20
Years of Service
User Offline
Joined: 4th May 2004
Location: Denmark
Posted: 5th Jan 2012 21:57 Edited at: 5th Jan 2012 22:02
[double post]
Manson_NS
20
Years of Service
User Offline
Joined: 4th May 2004
Location: Denmark
Posted: 5th Jan 2012 22:00
Chris, the crash I'm seeing is before hitting any key.

You're right sladeiw - that fixes it.
What baffals me is that the code only crashes when I have more than one instance of
Quote: "print "Hello: "+hello(0)"
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 8th Jan 2012 20:06
When you assign a string to a variable, the old value in that variable is freed. String literals should never be freed. The bug in DBPro is that when you return a string literal it puts it straight into your variable instead of putting a copy in the variable. When you give the variable a new value it tries to free the old value (the string literal) and fails, usually crashing the program.

[b]
Manson_NS
20
Years of Service
User Offline
Joined: 4th May 2004
Location: Denmark
Posted: 9th Jan 2012 14:26
Thanks for your thorough explanation Diggsey, I hope to avoid any more mistakes of that sort
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 11th Jan 2012 01:39 Edited at: 11th Jan 2012 01:41
Not sure if anyone else agrees; but a 'Repeat String' function wouldn't be a bad addition to the Generate String function set. Useful for text based interface decoration, particularly when the length of the text is dynamic; defined at runtime.

Something like: Make String$( Text$, Count )

Code: For I = 1 to Count : ReturnString$ = ReturnString$ + Text$ : Next I : Return ReturnString$

I am really lazy, I know.

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 11th Jan 2012 14:59
Lots faster:


Before I add anything to my plug-ins though, I'd like an idea of what you plan on using it for - I can't think of many occasions that you'd need something like this.

Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 11th Jan 2012 17:49
Yeah; thanks for the snippet Ian.

About your question. It would not be the most useful function in the world; and it could easily be created in DBPRO directly. I am thinking more about others who wouldn't think to fill a string for illustration, text tables and text interface decoration. It makes no difference to me if you add the command or not.

Seeing it next to the Generate String command in the documentation could inspire them to use it for what I use it for; or where ever you feel it should go in the documentation; which is a help library I often browse for ideas myself. I only know about it because I saw it used somewhere (I can't remember where). I personally would use it if it was in your utility, even though it only took 1 minute to write my own.

As a real life example of its use; yesterday I wanted to store a global string to be used as a section seperator in the documentation outputted to your console.

The string is something like "============================================"
for sections

And "--------------------------------------------"
for subsections.

But I may use the ASCII extension codes, used for old fashion user interfaces (EG: QBasic ), except this is in scrolling document form.

Obviously I could just write it out in a variable with the literal. But I want the length to be based on whatever width the user specifies for the console window in their settings. People with smaller monitors might want to use up less space without horizontal scrolling, or vise-versa. So I needed the length of the seperators to match the length of the console; to avoid wrapping the seperator on the next line, as you would have guessed. Who knows, if I get far enough, I may even alow them to specify what the line seperator looks like.

I use line seperators everywhere where I want to seperate unrelated text articles; this for me is the simplest most decorated form of low level text seperation without font changing that could be used in the console. A bit like the thread post seperation on this web page.


Another use I see my self using this for is text based progress bars in the console; So, for 50% progress; draw 5 dots or 5 special characters, or 50 or what ever. I might use percentage digits instead, or I might use both; who knows. In some cases I feel I might prefer to see the progress of the current process in the console without looking directly at it; I'd be able to see the progress bar text more easily than a percentage figure, whilst focusing on what I am doing in the DBPRO window. (The console is a great companion; for me, this is the case because I no longer need to disrupt my display with debugging text.)

Finally, there is a very low chance I might use the function for formatted string input: For example; the underscore could be used to illustrate the maximum length of a text field as I type into it. So I might decide to fill the remaining characters with an underscore as text is inputted. Or, I might not bother with this.

Other uses:
Make X amount of line feeds, make x amount of tab spaces, make x amount of identical formatted document elements (.direcx, .fx, xml, .html elements etc) without a for loop, then do a search and replace on data placeholders.

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 11th Jan 2012 23:39
It's also useful for formatting numbers to a fixed number of digits (ie. add n minus length of string 0s in front).

[b]
GIDustin
16
Years of Service
User Offline
Joined: 30th May 2008
Location:
Posted: 11th Jan 2012 23:41
Why don't you just use padleft and padright?

text$ = padleft$(intval(someValue),"0",10)

dividerText$ = padleft$("","=",100)
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 12th Jan 2012 02:38
Hmm, that looks good; to be honest padleft is one of those commands in the library I have yet to read up on. I didn't realize it had a optional character parameter. It is better for tables and string formatting than my function since I could use the current field value as its string parameter.

Although

Text$ = Make$( "=", 100 )

Is still more concise and readable for creating a new string.

GIDustin
16
Years of Service
User Offline
Joined: 30th May 2008
Location:
Posted: 17th Jan 2012 04:05
Ian,

make bank from file throws an error if that file is in use, such as an exe or a DLL in use by an exe. Is it possible to get a version that can read files that are in use? I am really only using it for MD5 checking:
Jeff Miller
19
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: New Jersey, USA
Posted: 3rd Feb 2012 14:21
I reported a species of that error in my April 24, 2011 post, regarding music files. It is apparently a more general error.
The Weeping Corpse
13
Years of Service
User Offline
Joined: 19th Sep 2011
Location: United Kingdom
Posted: 7th Feb 2012 21:10
Dear IanM

I'm new to dark basic and DirectX but not new to programming in general. I've studied the help files and your DLL help files and I can't find a function to suit my needs so maybe you can point me in the right direction, maybe I've overlooked something.

Ok, I want to modify the vertex data of an object from a DLL but I can't find anyway to obtain the base address of the vertex data. For example my code would go something like this.

`******************************************************************
Vertices = whatever
Indices = whatever

MAKE OBJECT NEW 1, Vertices, Indices, FVF_XYZ || FVF_NORMAL || FVF_DIFFUSE

LOCK VERTEXDATA FOR LIMB 1, 0

my_ptr = BASE ADDR OF VERTEXTDATA
MY_DLL_FUNCTION my_ptr

UNLOCK VERTEXDATA

do whatever with object 1
`******************************************************************

I know I can modify the vertex data with the SET VERTEXDATA commands but from what I understand the data is laid out linearly in memory, so I just need the base address, this would allow me to read and write to the memory much faster.
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 8th Feb 2012 00:05
You can see how it's done by DBPro by looking here: http://code.google.com/p/darkbasicpro/source/browse/trunk/%20darkbasicpro%20--username%20LeeBamberTGC/Dark%20Basic%20Pro%20SDK/Shared/Objects/CObjectsC.cpp

First, you need to get the sObject structure for the object you want to modify. There is a function to do this which you can import:
DARKSDK_DLL sObject* GetObject ( int iID )

Once you have the sObject* structure you can get at a particular limb by accessing the ppFrameList array, and from there you can get at the limb's mesh, and from there the vertex data. See the function "LockVertexDataForLimbCore" in the above link for an example.

[b]
The Weeping Corpse
13
Years of Service
User Offline
Joined: 19th Sep 2011
Location: United Kingdom
Posted: 8th Feb 2012 02:04
@Diggsey

WOW, I had no idea the source code had been released. Thanks for the help.
Jeff Miller
19
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: New Jersey, USA
Posted: 8th Feb 2012 15:00
If you are using the Make Object New command, you do not need the base address. You set the data with the object number that you assigned and you use vertex numbers that you order starting with 0. Conceive of the procedure as setting data for a blank object rather than modifying certain data on a pre-existing object. IanM has examples in a few older posts, one in September 2007 as I recall.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 8th Feb 2012 18:48
There is some code I worked on some years back that 'welded' matching vertices in the index buffer - I can't find the original thread, but I found another where the code was posted: http://forum.thegamecreators.com/?m=forum_view&t=162646&b=1

Take a look at the code from the LoadDLL_Basic3D function onwards, and see where I query the object mesh to see it it has an index buffer and allocate one if it doesn't. The important function as far as you are concerned is GetMeshAddress near the end of the code.

The Weeping Corpse
13
Years of Service
User Offline
Joined: 19th Sep 2011
Location: United Kingdom
Posted: 8th Feb 2012 23:57
@IanM

Thank you, thats exactly what I was looking for. I can now get a pointer directly into the vertex data and manipulate the memory directly with lightning fast access, rather than using SET VERTEXDATA POSITION, NORMAL etc. I'm using your POKE FLOAT command at the moment to alter the model data at run time and it works fine.

Your DLLs are an amazing piece of work.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 9th Feb 2012 00:15
All fine and dandy, but is it provably faster?

- You still need to lock/unload the vertex data to take into account changes.
- You now have to calculate address+offsets to write the data, which the vertex data commands did for you.

The Weeping Corpse
13
Years of Service
User Offline
Joined: 19th Sep 2011
Location: United Kingdom
Posted: 9th Feb 2012 01:06 Edited at: 9th Feb 2012 14:15
@IanM

True, but if you look at the source code for SetPositionData in the SDK it performs a lot of repeated calculations based on the FVF and it performs those calculations again and again for each call and also for SetNormalsData, SetDiffuseData etc.

Having a base address means I can write multiple vertex records at once.

Maybe it would be a good idea for a new command to be created (wink, wink) such as SET VERTEXRECORD i, x, y, z, nx, ny, nz, diffuse, u, v
Manson_NS
20
Years of Service
User Offline
Joined: 4th May 2004
Location: Denmark
Posted: 9th Feb 2012 22:46
I am having an issue with decoding images from a webcam, seeing as most newer cams encode in either YUY2 or MJPG.

YUY2 seems to be the lesser of the evils, and seeing as your plugin has quite some functionality with regards to colors, I was hoping that you'd put some conversion functionality on your todo list.

For inspiration here's a rough copy of how it'd be used (look for function peek_YUY2) I apologise for the crudity of the code:

Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 10th Feb 2012 13:52
I have not yet attempted sharing membanks. Just a quick question; when running two DBPRO programs that need to share information, should shared memory banks be used within mutex conditions? Do I need to check if a mutex is not reserved before creating and modifying a shared memory bank?

MAKE SYSOBJ MUTEX SysObj, SysObjName$
MAKE BANK BankId
MAP SHARED MEM TO BANK SysObjName$, BankId, PreferedSize

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 10th Feb 2012 14:47
Mapping shared memory to a bank creates the bank for you - you don't need the MAKE BANK command.

You don't need to use a mutex to create a shared memory bank - about the only odd thing to watch out for is that if you have two programs creating a shared bank with different sizes, the first program to execute the command will create the bank to the size it has specified, and the second program will simply re-open that memory (the size is ignored).

You may want to use a mutex when reading/writing to the bank, depending on how you organise things in the bank.

@Manson_NS,
Sure, I'll take a look at that - it shouldn't be too difficult to add another few colour conversion functions.

Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 10th Feb 2012 17:06
Thanks

Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 10th Feb 2012 19:12 Edited at: 10th Feb 2012 19:15
Excuse the double post, because I forgot to ask something. I wrongly assumed that after linking an array in a local function to another array outside of the function, the local function array and the pointer are lost after exiting the function so I need not unlink it, but this is not the case, because I cannot relink succesfully the local array the second time as this snippet shows:



If I do not unlink the local array T$(), the value of T$(1) will be nothing the second time the function is called.

Am I wrongly linking the global array to itself? Or is the global array being discarded by the function because of my error?


The above code runs without a crash, but in my project it crashes. I made the mistake thinking that T$() was local as far as the function is concerned and would be discarded from memory on function exit.

Nevermind:

Quote: "If this is not done then the linked array data will be released when the array goes out of scope."


IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 11th Feb 2012 18:02
@Manson_MS,
My initial investigations reveal that the YUY2 format is awful - luminescence is per-pixel, while colour is averaged per pair of pixels. If this is the actual case, then each colour will actually hold 2 pixels-worth of low-grade information, and I'm not sure how to handle that just yet.

To confirm this, can you write a small program that saves the raw untranslated image from your data feed into a file and send me that file?

Manson_NS
20
Years of Service
User Offline
Joined: 4th May 2004
Location: Denmark
Posted: 12th Feb 2012 22:40
Thank you very much for looking into it Ian, switching bits back and forth in DBPro is very much my least favoured option - while I do appreciate the possibilies to do so

Yea, there's some tricks to it - the luminance is the easier one to make out - that's what my sample is based on.

I've made a rough dump of the image data into a file "image.YUY2" The image captured at 640x480, 16bit

The code to generate the file included again, in case you'd want to hold up a piece of colored paper in front of your webcam:

Attachments

Login to view attachments
Sparkytus
18
Years of Service
User Offline
Joined: 22nd Sep 2006
Location:
Posted: 17th Feb 2012 10:44
Hello IanM.

May I say thanks to you for your fine work on your plug-in(s), very very much appreciated.

After being away from computers for many a year (it would seen longer) I returned with that buzzing idea in my head (you've probably experienced it yourself, where you must do something about it, even if it's just to write it on paper) and after searching the forum I found you & your plug-ins.

I hadn't been on much after I first joined (before I vanished for a long time) and hadn't been searching much back then on here, in truth I didn't have a clear idea of what I wanted to do with dbpro, till now and thanks to your plug-ins I hopefully will proceed and get this buzzing idea out my head and on screen finally.

I'm rambling, sorry.

Many many thanks to you Ian.

Ciao.

Sparkytus (Russ)
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 18th Feb 2012 23:05
Is there any way to read in commands from the console without pausing the program?

TheComet

nruser
16
Years of Service
User Offline
Joined: 22nd Dec 2007
Location: Serbia
Posted: 22nd Feb 2012 18:38
i need some more info on coroutines, if i want to use more then one cpu core, are coroutines way to go? i know there is not much that can be muli-threaded but still this seems as a good start apart from multithreading plugin i found here on forum
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 22nd Feb 2012 20:49 Edited at: 22nd Feb 2012 20:51
Coroutines are not multi-threaded so they can't run on different cores. They act more like a kind of state system in that can only be in one state at a time, but you can change state at any point. There is no way to safely write multithreaded code in DBPro, and trying to do so will not give you any benefit, since any command you want to use will require locking out other threads which kindof defeats the point of multithreading.

[b]
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 22nd Feb 2012 21:31
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 23rd Feb 2012 20:04
Sorry, no. The console input is implemented using a simple ReadConsole function call, which is a blocking function with no timeout.

TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 23rd Feb 2012 20:25
Would it be possible for a future update? Or would it be possible to do it with a bat file like bukkit does it?

TheComet

ShaunRW
DBPro Developer
16
Years of Service
User Offline
Joined: 7th Jan 2008
Location: Brisbane, Australia
Posted: 29th Mar 2012 14:56 Edited at: 29th Mar 2012 15:02
Hey Ian,

With the Call Function Ptr function, you said you wouldn't make it possible to use a string arglist such as Call Function Ptr ptrToFunction,Arglist$. This was because your plug-in wouldn't know what datatype to parse the parameters with. Well what if you use a format string that decides the datatypes for you?

For Example:

Would this be possible or am i missing something?
Also sorry for the bump.

- ShaunRW

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th Mar 2012 19:26
I'm not sure what the point of that is.

If you know enough about what you are calling that you can specify the format string in the first place, then why not just cut out the middle man and ensure that your argument types are correct when calling?


If you don't want to work that hard, then write yourself a single function that calls the function pointer for you with the correct argument types:


ShaunRW
DBPro Developer
16
Years of Service
User Offline
Joined: 7th Jan 2008
Location: Brisbane, Australia
Posted: 31st Mar 2012 05:48 Edited at: 31st Mar 2012 08:30
I was doing it the same way as your second snippet, with every function having it's own DespatchCall function.
As I was looking at your first snippet, it gave me a kick in the right direction. I came up with a way to have any combination of types:



The number of arguments has to be the same, but a workaround for that is easy.
I didn't think this would even compile, with not knowing the argument types at compile time.

Edit: Also would IntPtr = Get ptr To Function("as_integer") be better as a global variable or constant(if they can be constant)?

Thank you, and if you see any problem with the code, please let me know.

- ShaunRW

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 31st Mar 2012 16:02
I'm still not seeing why you don't just do this:

... or even just pass the strings into the function and let the function carry out the conversion.

Perhaps you should tell me what problem you are trying to solve here so that I can understand and offer suggestions.

Login to post a reply

Server time is: 2024-11-23 08:03:22
Your offset time is: 2024-11-23 08:03:22