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
Grandma
18
Years of Service
User Offline
Joined: 26th Dec 2005
Location: Norway, Guiding the New World Order
Posted: 22nd Nov 2008 15:33
Nothing major, but in plugin# 22 (strings)

Quote: "DATAFILE STRING TYPE FileId, String Type

This command is used to determine how strings are written to and read from the data file. A newly opened file is set to
string mode 1.

- 0 = String data is terminated by a newline (ascii value 10)
- 1 = String data is terminated by a CRLF combination (ascii value 10, preceded by an optional ascii calue 13)
etc..."

The two options there are mixed. When I set Datafile string type to 1, that's when it creates a new line for each string written. It seems to be at "0" on default, writing the strings on the same line. Also there's a small typo there.

Anyway, the real annoyance is the duplicate GET ARRAY TYPE error on compile. How do I murder that one?

This message was brought to you by Grandma industries.

Making yesterdays games, today!
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 22nd Nov 2008 16:00
Quote: "It seems to be at "0" on default, writing the strings on the same line"

It does seem to default to 0 - that's true, but the 'same line' bit is purely because you are opening the file with notepad, which doesn't understand linefeeds on their own. Try a different editor that does understand them, like wordpad for example.

I'll fix the default string mode and that typo ready for the next release.

Quote: "duplicate GET ARRAY TYPE error on compile"

You're running one of the 7.1beta updates - check my post for 25th Oct 2008 10:41 - there's a replacement for that DLL there.


I'll be issuing the next release of these plug-ins for 7.1 before the end of the month, whether Lee's released the official 7.1 update or not. If I beat him to it, I'll recheck everything when he does release and fix anything he breaks

Note, this won't include new plug-ins that I've agreed to do over the past few weeks.

Olby
20
Years of Service
User Offline
Joined: 21st Aug 2003
Location:
Posted: 23rd Nov 2008 00:41
Bugger.. didn't saw that post!


ACER Aspire 5920G: Core2Duo 2.2GHZ, 2GB, GeForce 8600M GT 1280MB, DirectX10, DBPro 7.1
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 27th Nov 2008 18:19 Edited at: 27th Nov 2008 19:09
Ok, here's the latest version, and this is important ... it's for the 7.1beta7 only. If you have any problems when running it with other versions then you are on your own.

Ok, big release time:

Release 20081127
General
- Recompiled all plug-ins to use latest Interface library

Matrix1Util_02 - 1.1.0.4
- Minor tweak to the resource string (not affecting functionality).
- Minor tweaking of the DLL initialisation and shutdown processes.
- Addition of functions to query timer resolutions and to set them.

Matrix1Util_05 - 1.1.0.6
- Relocated the FIND FREE VECTOR functions to Matrix1Util_32.
- Removed obsolete support code.

Matrix1Util_07 - 1.1.0.2
- Corrected error in the WRAP commands - they weren't working correctly when going below the lower range.

Matrix1Util_09 - 1.1.0.3
- Moved vector math commands to Matrix1Util_32.
- Moved object information function to Matrix1Util_18.

Matrix1Util_10 - 1.1.0.1
- Refactored the code to make expansion easier, specifically new logging targets.
- Dropped the WRITE LOG commands - they won't work for every logging target.
- Added new logging target of debugger output.

Matrix1Util_11 - 1.1.0.2
- Minor tweaking of the code for efficiency.

Matrix1Util_12 - 1.1.0.6
- Refactored the code for maintainability and extendibility.
- Corrected LIMB HAS MESH function.
- Added functions/commands to allow control over the number of primitives/vertices rendered.

Matrix1Util_18 - 1.1.0.4
- Refactored the code for maintainability and extendibility.
- Allow negative width & depth when making a plain - indexes are automatically corrected so that the top-side of the object is not culled when viewed from above.
- Changed limit of vertices from 65535 to 65536.
- Fix to allow index-less objects to be created.
- Added MAKE OBJECT PLANE commands to match the new DBPro commands.
- Implemented own routine for updating vertex fields in planes due to internal DBPro bug.
- Moved all object information functions to this plug-in from Matrix1Util_09.
- Added new commandset for creating complex multi-limbed objects.

Matrix1Util_20 - 1.1.0.4
- Rewrite of function collection sweep to get function names if available - using new DBPro core functionality.
- Added new version of GET PTR TO FUNCTION to accept a function name in a string as an argument.
- Added CALL FUNCTION NAME commands & functions that accept a function name in a string as the function to call.
- Added variables to CREATE COROUTINE commands to accept function names instead of function pointers.
- Added a few functions to get some interesting pointers from DBPro.

Matrix1Util_22 - 1.1.0.7
- Set default file open to use a string mode of 1 (optional CR, LF ending).

Matrix1Util_29 - 1.0.0.5
- GET ARRAY TYPE and GET ARRAY FORMAT rewritten to use the DBPro core functionality.
- Removed commands SET ARRAY FORMAT, SET ARRAYPTR FORMAT and function GET ARRAY TYPE as they are no longer needed.
- Updated sort routines that need to know whether the array is a single type or a UDT to look for array types that are 9 OR GREATER, not just equal to 9.

Matrix1Util_31 - 1.0.0.2
- Added LOOKUP$ that returns a default value if no value exists in the lookup.

Matrix1Util_32 - 1.0.0.1
- New plug-in for extra 3dmath functionality.
- Moved FIND FREE VECTOR to this plug-in from Matrix1Util_05.
- Moved all vector/matrix commands to this plug-in from Matrix1Util_09.
- Added command to allow matrix4 cells to be set manually.
- Added commands to automatically allocate id's for new vectors/matrix4s.
- Added MAKE VECTOR2, MAKE VECTOR3, MAKE VECTOR4, MAKE MATRIX4 as commands.
- Added DELETE VECTOR2, DELETE VECTOR3, DELETE VECTOR4, DELETE MATRIX4 as commands.
- Added commands to get object & limb matrices.

Attachments

Login to view attachments
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 27th Nov 2008 18:45
One of the additions I'm most proud of is the ability to build objects of any complexity.

You can begin creation of a new object, add limb at will (either as blanks or from existing mesh id's), set properties for those limbs, link them together by specifying their parent limb, and then when you are all done, issue the creation command.

Here's a simple example:


Limb properties that can be set are:
- Parent limb
- Limb name
- Texture
- Offset
- Rotation
- Scaling
- Transparency
- Culling
- Lighting

Note that the object is not created until the command FINISH NEW OBJECT is called, and the current settings can be dumped simply by starting a new object using BEGIN NEW OBJECT.

IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 27th Nov 2008 18:57
After manipulating an objects vertices, you sometimes have vertices left over that you don't need and don't want to display. Or perhaps you want to dynamically adjust a limbs mesh according to distance.

The solution in the past has been to either keep many meshes of various sizes available and switch between them, or to simply set the vertex positions to a single point - the problem is that either way costs you in extra memory, and either CPU power (switching between limbs) or GPU processing power (transforming vertices and rendering extra polys).

Now there's a solution - you can modify the adjusted limb so that it displays the number of polygons you specify:


Vertices are a little trickier as you need to arrange that the vertices that you require are at the front of the vertex buffer - no demo provided

IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 27th Nov 2008 19:14
There are also some additions to function pointers that makes them much easier to use now - you can get or call a function pointer by using its name!



However, if you plan on calling the function over and over, it's probably best to get the pointer, as this is far more efficient than doing a lookup by name - this can be done by using its name too:


IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 27th Nov 2008 19:18
Arrays have also been improved. In earlier versions of the array plug-in, it was the responsibility of the programmer to provide a format for typed arrays, so that sorting could take place. That step has been removed due to changes that Lee has made to the compiler - you can now sort arrays immediately without any setup at all.



Remember that negative field numbers specify that the field is to be reverse sorted.

TechLord
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 28th Nov 2008 08:50
Can someone kindly point me to the New LOOKUP Command Tuts. They look very nifty, just not sure how I can take advantage of them. Sincere Thanks in advance.

IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 28th Nov 2008 11:02
Did I never post example code for them? Oops.

This code exercises all of the basic lookup commands except for SET LOOKUP GET MODE and the INI file load/save:



Paste the following into a file named 'test-in.ini':


Then you can try the following code on it:


... one day I might work on maintaining the comments, but it's not that big a deal to me - just use self-documenting names.

IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 28th Nov 2008 11:23
Here's how you get a matrix representing the current translation/rotation of an object or one of its limbs:


IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 28th Nov 2008 11:31 Edited at: 28th Nov 2008 11:35
Complete control over the projection and view matrices - here's the basic Orthographic camera view (usable for making objects look like sprites):


Also in there, in case you didn't see it, is the auto-allocation of a matrix4 id - I'm trying it out to see how useful it can be.
Even if you don't find it useful yourselves, there are other additions that might be.

For example, all of the MAKE & DELETE functions for vectors and matrices have been duplicated to allow them to be called as commands:


TechLord
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 28th Nov 2008 12:00
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 28th Nov 2008 18:06
You're welcome.

Another example showing the timer modifications.

Run this code as-is first:


On my machine, the elapsed time switches between 15 & 16 ms (yours may differ). Now uncomment the 4th line and run it again. The elapsed time on my machine is now 1 ms.

Now something similar:


Again, on my system I get 15 or 16 ms per frame, which is 62 fps. Uncomment line 4 and run it again, and I get 9 ms per frame, which is 111 fps - the best I can do with this I'm afraid, because I believe that Lee included some other factor in calculation when using the SYNC RATE command.

RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 30th Nov 2008 00:58
IanM, first, let me say this is fantastic work. Thank you!

Now to the meat and hash browns.

I am trying the beta version, specifically Matrix 20. I keep receiving errors, like "Attempting to call unknown function name..." or "Unable to locate DBPro code Prolog at line.."

I get the same results when I try a clean Project with your examples a few posts back.

Maybe I missed something on installation?
1st try: I just extracted the files and overwrote the existing files.
2nd try: I deleted previously extracted files and then extracted the new files.


Open MMORPG: It's your game!
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th Nov 2008 01:25
My very first guess would be that you aren't using the 7.1beta release - the new compiler includes extra functionality that the plug-in now requires. The same is true of the array plug-in too (number 29).

If this is the case, you could try replacing those two plug-ins with those from the previous release (I left a link to it in the first post). I can't guarantee it will work straight off, but if it doesn't we should be able to tweak it a little. You won't get the function name functionality this way though, which I suspect is your main concern.

RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 30th Nov 2008 01:50
Thanks IanM. I upgraded and that fixed it.


Open MMORPG: It's your game!
RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 30th Nov 2008 06:44
IanM. I have a request for functionality to be added in:

Request: On Matrix 20, can a modified Call Function command be added? The current command requires hard coded parameter list. Can you add a Call Function command that can pass a string variable to be parsed as the parameter list? Example:



Reason: This would allow Functions to be completely scriptable. A simple parser code reading in script from a file could be used to execute a function and pass parameters easily. IMHO, calling functions from script files is a widely useful. After reading most of the 16 pages of this thread, it even seems that scriptability might be the intended end result of the reason for adding the Call Function FuncName$ functionality.


Open MMORPG: It's your game!
Mistrel
Retired Moderator
18
Years of Service
User Offline
Joined: 9th Nov 2005
Location:
Posted: 30th Nov 2008 07:38
Can't your script figure out the number of parameters and call the appropriate function?

RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 30th Nov 2008 08:26
Not without coding a specific call for every single function. I have done this with a pre-compiler, but IanM is so close to accomplishing all that without needing to create the specific calls.

The idea is load in a script and store the data in an array (or memory, or wherever). Then run through the array and call each function. There would be no way to store or return different variable types for the parameters (string, float, dword, integer) for the different functions. It would be possible if all functions required the same exact parameters (quantity and types), but we know this is not the case.

So, for example, how would one handle the following?:

Read String 1,FuncName$
Read String 1,Param1$
Read String 1,Param2$
Read String 1,Param3$

What would the function call look like?

Call Function FuncName$,Val(Param1$),Val(Param2$),Val(Param3$)

But what if the function FuncName$ has only 2 parameters? What if it has 4? What if Parameter 2 is a string variable and not a value (Integer or DWord)?

The only way (in concept, not specifics) to do this is to write the code like this:



That's basically what my pre-compiler did. By adding the ability to pass a string and have the dll parse the string and apply the parameters, there is no need to pre-compile. The code can look like the way I posted it in the original request.


Open MMORPG: It's your game!
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th Nov 2008 12:33
First, here's a new copy of the DLL plug-in - the existing one has problems with arguments and returned values when you call by function name. Calling by function pointer worked Ok.

I spotted the errors when putting together a piece of code for reply.

Anyway, my answer to you is 'don't'. Don't do it like that. I can't parse the string in a way that would be meaningful to everyone - would I parse '1' as a byte, integer, word, dword or double integer? If I pick one, I exclude the others.

Unfortunately, this is one you need to do yourself. Fortunately, it's quite easy due to the fact that Lee picked the CDECL calling convention, which pushed the arguments onto the stack in reverse order - that means that if you push 10 arguments onto the stack and call a function that expects 1 argument, it will get the correct argument.

My preferred way though is to pass a parameter that tells you how many arguments are present (either direct as in the following example, or indirectly as printf does it):


In the next official release of this plug-in, I'll be adding a var-args style set of functions so that you can have a variable number of arguments in your target functions.

Attachments

Login to view attachments
RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 30th Nov 2008 15:54
Thanks very much for the fix IanM.

Quote: "I can't parse the string in a way that would be meaningful to everyone - would I parse '1' as a byte, integer, word, dword or double integer? If I pick one, I exclude the others."


A few simple tests, after that, it doesn't matter.

If there is a "'" then it is a string.
If there is a "." then it is float.
If there is a "-" and no "." then it is an integer.
All others are DWords. Since DBPro stores Bytes and Words as DWords, Passing a DWord won't make a difference in these cases. Assuming the parsed value is intended as an integer, and the receiving parameter is intended as an integer - an intermediary DWord for any positive values won't alter the end results (am I correct?). For simplicity, I would exclude support for Double Integers and Double Floats, but I bet these could be done using similar logic.

Or use a parsing convention. You did do something similar for logging, right?
Strings = S%
Integer = I%
Byte = B%
Word = W%
Float = F%
and so on.

Quote: "In the next official release of this plug-in, I'll be adding a var-args style set of functions so that you can have a variable number of arguments in your target functions."




Open MMORPG: It's your game!
Mistrel
Retired Moderator
18
Years of Service
User Offline
Joined: 9th Nov 2005
Location:
Posted: 30th Nov 2008 16:12 Edited at: 30th Nov 2008 16:14
Instead of passing a string and parsing it pass one bitmask parameter for each type. It's much faster.

Todd Riggins
19
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 30th Nov 2008 20:42 Edited at: 30th Nov 2008 20:43
This is definetly awsome work your doing here, IanM... Thanks!

I am using DBPro 7.1beta7 with the Matrix1Util_20081127b:

Quote: "
Matrix1Util_29 - 1.0.0.5
- GET ARRAY TYPE and GET ARRAY FORMAT rewritten to use the DBPro core functionality.
"



I get the compiling error:
------
Duplicate GET ARRAY TYPE in Matrix1Util_29.dll and dbprocore.dll!
Command in 'Matrix1Util_29.dll' command-table unrecognised (GET ARRAY TYPE[%LH%GetArrayType%Array())
------

??

In the meantime, I just delete the Matrix1Util_29.dll to make it not error like that for me.

Inspirational Music: Descent ][ Redbook Audio CD Soundtrack
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th Nov 2008 20:51 Edited at: 30th Nov 2008 20:53
That tells me that you haven't installed the latest set of plug-ins, or haven't installed it correctly - that command doesn't exist in that plug-in any more.

Try downloading and installing it again, making sure that the directory structure is preserved when you do so.

Todd Riggins
19
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 30th Nov 2008 21:23 Edited at: 30th Nov 2008 21:28
Here's what I do:

For sanity sake, i delete all the Matrix1Util dlls from the plugin-user directory. I unzip the Matrix1Util_20081127b in it's own directory.

I copy compiler directory over to dbpro's compiler directory
I copy help directory over to dbpro's help directory
I copy editor directory over to dbpro's editor directory

Now everything from the Matrix1Util_20081127b directory is in the dbpro's directories. I see this. When moving those directories over, it asks me if I want to copy over the directories and files. I say yes to all.

Restart synergy ediotor so it can recompile the keyword list or whatever it does, run my program and bam... the same compiler error.

And yes, I made quadrouple sure that I have DBPro 7.1beta7.

Inspirational Music: Descent ][ Redbook Audio CD Soundtrack
TechLord
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 1st Dec 2008 12:40
I assume the LOOKUP lib provides superior performance for string key --> value lookup compared to a home brewed system such as iterating through a Array (which I'm currently using). I want to replace the home brewed setup which will require some significant recoding. Before I go through with it, would like to know if anyone has performed some benchmarking.

IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 1st Dec 2008 14:47
The performance increase would depend on what you had before.

I've quickly thrown together a quick test using a linear search (iterating through an Array) of 1000 items and a lookup of the same 1000 items - on average the lookup is 5 times faster on my system. A higher number of items would increase the gap, less would decrease. Replacing the linear search with a binary search would decrease the difference again, but would increase the insert time.

@Todd,
The method of unpacking you talk about is a lot more convoluted than I use. I open the zip, select extract, point it at my DBPro installation folder and then let it go.

Todd Riggins
19
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 1st Dec 2008 20:09 Edited at: 2nd Dec 2008 22:01
Edit: I have updated to DBPro v71 beta 8. Redownloaded the Matrix1Util_20081127b.zip provided from the Posted Post: 27th Nov 2008 05:19, above via it's attachment file. From the base Dark Basic Professional Directory, I extracted the Matrix1Util_20081127b.zip there so it extracts directly to the appropriate directories. Then I started synergy editor. Loaded my project. Press to Compile it and ... again.. I get the same error as above.

So I have extracted everything correctly. The GET ARRAY TYPE command does indeed conflicts between the Matrix1Util_29.dll and the dbprocore.dll. Mabie the posted zip archive accidently recieved an old Matrix1Util_29.dll?

Inspirational Music: Descent ][ Redbook Audio CD Soundtrack
kaedroho
16
Years of Service
User Offline
Joined: 21st Aug 2007
Location: Oxford,UK
Posted: 14th Dec 2008 21:51 Edited at: 14th Dec 2008 22:09
[Nevermind (all sorted)]

TechLord
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 21st Dec 2008 13:22 Edited at: 21st Dec 2008 13:25
Hi Ian,

I've been playing with the LookUp Lib. I'm definately going to employ in my Give/Take Registry System. I also need to reword a question I asked earlier in regards to performance.

I wrote home-brewed Hash Table Lib a few years back. It was really primitive and nothing to prevent key `collision`. That system basically added the ascii values of the characters in the key string together and divided by a Hash to create a Hash Table Lookup Index.

I was curious if your Lookup Lib operates similar. I'm using the Matrix1Util Lookup functions to store key/value (name$/ID combo) and simply use `LookUp` grab values (Object IDs) by keys (Object names) instantly, verses iterating through the lookup table.

IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 21st Dec 2008 14:05
It uses a balanced binary tree, not a hash. It's not got quite the performance of a hash, but it does keep things in a sorted sequence.

Maybe at some point I can add alternate storage structures, so if you don't need sorted data, you can create a hash for example.

I'm also thinking about replacing the binary tree too - there's potentially a better tree structure for strings, but it doesn't allow balancing. I'll need to experiment to see if it's worth writing a full implementation.

freight hopper
20
Years of Service
User Offline
Joined: 26th Dec 2003
Location: Just beyond the Dunsmuir yard limits
Posted: 24th Dec 2008 20:10
Wondering about the insert$() command in library 16. I am using DBP7.1 and your update 20081127b. I get a "could not understand line 2 error" for the following code:

stringg$ = "sop"
insert$(stringg$,2,"t")
print stringg$
wait key
end

Other commands in the library are working for me.

Also was the save frontbuffer command ever sorted out?

Thanks!

IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 24th Dec 2008 21:37


... and what's the problem with the save frontbuffer command? I just tried it and it worked just fine for FSEX, fullscreen windowed & plain windowed.

freight hopper
20
Years of Service
User Offline
Joined: 26th Dec 2003
Location: Just beyond the Dunsmuir yard limits
Posted: 25th Dec 2008 06:49 Edited at: 26th Dec 2008 22:04
I'm an idiot. Thanks for the post.

I had asked you about front buffer save on 9/17 and sounds like you fixed it. Can't wait to try it!

[edit] works beautifully showing other windows and I got to dump 100 lines of ugly code.

IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th Dec 2008 23:27
Quote: "works beautifully showing other windows and I got to dump 100 lines of ugly code."

Is that good or bad? I can't tell from the way you've written this.

It is a limitation that there's very little I can do about - the front-buffer IS the display, and if you have a window overlapping your game/app, then you are going to capture it. However, if you need to, you can probably use the GRAB FOCUS command in your app to force it to the front before saving the front-buffer.

RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 27th Dec 2008 16:13 Edited at: 27th Dec 2008 16:13
Hey IanM, I found a little problem with the Is Memory Readable command. A readable string pointer is not showing as readable.



Am I doing something wrong?


Open MMORPG: It's your game!
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 27th Dec 2008 17:17
I'll need to check into this a little - a quick read of some blogs regarding the API those function use has made me uncertain about whether they do the job I thought they did.

Anyhow, the way you are using it is NOT the correct usage - the functions check the memory page to see whether the page belongs to your process and has the required readable/writeable attributes, and not that the memory has been correctly allocated. Memory can belong to your process, but not currently be allocated.

RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 27th Dec 2008 17:40
Thanks IanM! I am trying to determine if it is safe to read that memory location (like in the following example). Any ideas on how to do it?




Open MMORPG: It's your game!
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 27th Dec 2008 21:54 Edited at: 27th Dec 2008 23:00
Is there some reason you are capturing the return value into a dword rather than using a string?

Perhaps you are attempting some sort of 'variant' return type?

I'm using a double integer where the lower 32 bits hold a value or pointer and the upper 32 bits hold a type. Only a little work would be required to allow this to hold any of the types < 32 bits in size.

This IMO is a better way to deal with the problem of variable return types than simply checking if the value is a valid memory location.

[EDIT]
Another variation is not to return double integers, but to return a pointer to the variant instead:


RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 28th Dec 2008 00:22
Quote: "Perhaps you are attempting some sort of 'variant' return type?"

Yes. But I figured, why bother with that? If a function is called and a value is returned, it occurred to me that one would need to know what type of value it is in the first place (at least in DBPro).

A value is pretty meaningless in the grand scheme of things. The Value of that value comes in doing something with that value, either through processing, comparison, or output (possibly input, which would likely lead to one of the former anyway). For example, if the value is numeric, it could be compared using If/Then or Select/Case logic with some form of Variant ID to prevent comparison to another value type, but it still does not tell me if that value is hit points, score, strength, or time until catastrophic destruction.

Hence the problem in calling a function via variables rather than directly hard coded. Calling function via variables is still very useful, but return values are almost always never worth bothering with. Still, I wanted some way of returning that value, just in case there is a need.

Despite all those reasons not to, I think you have presented easy enough code to implement it. Thanks!

BTW: That's some clever code you have there IanM. Is there any chance you will be adding variant values to to your matrix utilities? If I were to throw a hint; the Lookup utilities could certainly gain an advantage from this. Storing numeric values and strings would be great.


Open MMORPG: It's your game!
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 28th Dec 2008 01:02
I'll think about it. The biggest issue I see is that there's no control over memory leaks - you can create a string variant, then forget to delete it, leading to a leak. Too easy to get it wrong. Then again, the pro's may outweigh the con's.

Back to your description though - although the implementations I showed were based around variable type, there's nothing to stop you implementing a system around the usage instead. If you have a MakeVariantStrength and a MakeVariantTime etc, then you can enforce the correct interactions between them, such as throwing out an error, silently discarding the results etc.

One more thing you'll need to think about - You'll alto need to implement a copy operation (create a copy from an existing variant) and an 'equals' operation (make 'this' variant look like 'that' variant). Most copies will be simple, being a straight binary copy, but strings for example, need a new string to be allocated.

You might also want to put together a generic comparison function so that similar or identical value types can be compared (integer to integer, integer to float, string to string).

In fact, the more I think about it, the more I think I can do this. Not just having value types, but also adding other property tags such as having an integer variant but being able to label it numerically so that you know it's related to strength.

I do worry about the possibility of memory leaks though.

RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 28th Dec 2008 03:27 Edited at: 28th Dec 2008 05:19
What I don't understand is how you avoided a memory leak in this example:



It's cool, but maybe not if the same memory location is getting overwritten each time the Alloc String function is called.

Edit:

It's not overwriting the memory location as far as I can tell. Very impressive IanM!




Open MMORPG: It's your game!
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 28th Dec 2008 11:10
That's not my example, and you do have a memory leak. The chunks of memory allocated by the ALLOC STRING function are not being FREE'd before you lose track of the pointer.

I use the DeleteVariant function to free the memory when I'm done with it.

In fact, my second example also has a leak:


As I said, I do worry about memory leaks - it's too easy to leak memory with low-level stuff like this.

RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 28th Dec 2008 16:52
I see it now IanM. It was leaking too slow to observe in any short amount of time. I increased the string size and watched my memory drain away.

Thanks again.


Open MMORPG: It's your game!
RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 28th Dec 2008 22:42
Hate to be a pest IanM, and if I am, just let me know. That said, I have another request:

In the Object Groups (Matrix 19), can you add a Set Object Group Mode (or something) that allows Objects to, at the discretion of the coder, be placed in multiple groups instead of only one at a time? I see values for both of these modes. The one you have allows an object to be moved from one group to another with ease when only one group at a time is preferred. The second mode I am suggesting would allow object ID's to be in multiple groups at the same time. Moving from one group to another would be more work, but groups could be set up to perform specific tasks on objects from multiple groups.

For example: There could be a Gravity group, Momentum group, Collision group, and so on. While in most games, objects might fall into all these groups, so a single Physics group might be appropriate. In other cases, maybe there are flying creatures, so we leave those out of the gravity group. Perhaps there are ghosts, so maybe they do not belong in the collision group. These are just examples of possible groups in a physics environment. AI can expand this use significantly.

Another coder-selected-mode I would suggest for Object Groups is to report no error if object does not exist. The Object ID would still have to be valid. Right now, if an Object ID is added to a group and that object does not exist, and error is returned. This new mode would not check if the Object exists, only that ID is a valid ID for Objects (i.e. a DWord>0). Again, the advantage of the way you have now is obvious, when the object is deleted, it is removed automatically from the group it is in (or groups if you add the previously suggested mode). The advantage of the second method is to allow groups to contain "virtual objects", which are objects that are kept track of without actually having the object made/loaded/cloned/instanced. There are many reasons for having "virtual objects," but the most common would be resource optimization.

This, of course, might prompt a new command for Object Grouping; Remove Object From Group and/or Remove Object From All Groups. Right now, in order to remove an object from a group, one would need to move it to another group (probably a "null" group). Once an object is in a group, there is no way (that I can tell) to remove it from groups all-together.


Open MMORPG: It's your game!
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th Dec 2008 13:46
I'm thinking about what you've asked for - I have some ideas but I need to spend some time thinking about the implications for the existing code before I do anything, and work out how it would look from the DBPro side.

Anyway, new release time.

This release is mostly me tidying up code, tightening up on error checking, filling in a few blanks etc.

Matrix1Util_16 - 1.1.0.4
- Performance tweaks for search functions.
- Removal of duplicate code.

Matrix1Util_18 - 1.1.0.5
- Refactored 'load from dbo' code for easier maintenance.
- Enhanced error detection & reporting in all commands.
- Replace DLL calling code with interface library calls.

Matrix1Util_19 - 1.1.0.3
- Refactored code for future enhancements.

Matrix1Util_20 - 1.1.0.5
- Fixed CallFunctionName to correct the arguments and return values.
- Simplified function pointer initialisation.
- Revised assembly code for function-calling function.
- Added variable arguments commands.
- Linked variable arguments into coroutines.
- Initialise coroutine system on plug-in load rather than on the fly, to reduce startup time of first coroutine, and to reduce code size.
- Added FIND FREE COROUTINE functions.
- Removed pointer functions to reduce plug-in size.

Matrix1Util_26 - 1.0.0.6
- Add commands to allow callbacks to be set by name instead of function pointer.

Matrix1Util_29 - 1.0.0.6
- Updated CLEAR ARRAY command to correctly clear strings from UDT arrays.

The new commands in that lot are the addition of variable argument lists for functions, and the addition of setting up sync callbacks by function name and not just by address.

Attachments

Login to view attachments
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th Dec 2008 15:23
Here's a very basic example of the new arglist functions:


It's your responsibility to ensure that you read only the correct arguments of the correct type from the argument list.

There is no 'close arglist' command - the arglists are automatically garbage collected when the program returns to a higher scope, ie it is not valid to return an arglist handle created in a function from that function either directly or indirectly. It's also not valid to use handles across coroutines (that's if you use coroutines).

RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 30th Dec 2008 17:11
Very impressive IanM - and many, many thanks!

Got a question about some playing around I did. I noticed that one can now pass UDTs to the function and the values are retrievable. Was this intentional? It is very cool, but I am curious how stable it is.




Open MMORPG: It's your game!
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th Dec 2008 17:32
I can't honestly say that it was by design - it just so happens that the packing that Lee uses for UDT matches the packing of function arguments.

Basically, it's a happy coincidence and it is as stable as Lee lets it be.

Login to post a reply

Server time is: 2024-04-20 00:36:34
Your offset time is: 2024-04-20 00:36:34