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.

DarkBASIC Professional Discussion / How do I reference an object limb by name?

Author
Message
GregA
15
Years of Service
User Offline
Joined: 21st Jun 2011
Location:
Posted: 12th Jul 2012 01:16
I am looking at the various Limb commands, and I am uncertain how to... rather what is the best uses policy for referencing limbs?

As I see it I could go several ways...

I could walk the whole list of limbs and pull out and make my own data table with reference index...

I could grok the bits of checklist...

Really what I want to do is something like...

Hide Limb ObjID, GetLimbID("MyLimbName")

Anyhow, what is best practices here?
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 12th Jul 2012 02:01
Foot = 1
Leg = 2
Thigh = 3

If that's what you want.

GregA
15
Years of Service
User Offline
Joined: 21st Jun 2011
Location:
Posted: 12th Jul 2012 03:17
Maybe I am coding to defensively... (I tend to code defensively, to a fault sometimes...) But the limb names are being assigned in blender, and I can't count on the index's being static over time. So ~possibly~ every time I tweak or add something to my scene file I would have to figure out all the static ID's again.

I was kinda sorta hoping someone would say something along the lines of "You need plug-in x, it has the GetLimbIDByName() Command built in, or somethin like that.
Kezzla
17
Years of Service
User Offline
Joined: 21st Aug 2008
Location: Where beer does flow and men chunder
Posted: 12th Jul 2012 05:18 Edited at: 12th Jul 2012 08:29
maybe try this out



Sometimes I like to use words out of contents
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 12th Jul 2012 13:08
If you have Matrix1Utilities you can use the "lookup" tables.
Unfortunately they're only string-to-string maps so you'll have to convert your limb ID's back and forth between strings and numbers.
Something like this (pseudocode, not sure if it'll compile but demonstrating the general idea):



"Why do programmers get Halloween and Christmas mixed up?"
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 12th Jul 2012 15:34
I am pretty certain Enhanced Animations has everything needed for this...

also I believe there is a complete example in Dark Source using native code... if required I can confirm this in advance...

GregA
15
Years of Service
User Offline
Joined: 21st Jun 2011
Location:
Posted: 12th Jul 2012 17:18
I ended up doing this with native code of the form...

Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 12th Jul 2012 18:28
That all works, however it can be considered a waste of time to constantly iterate through potentially all limbs only to find that the last one (or none!) has the sought name.
Although seeing as you probably at most have a couple of hundred limbs it might not be a very big slowdown issue.


"Why do programmers get Halloween and Christmas mixed up?"
Mage
Valued Member
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 13th Jul 2012 06:45 Edited at: 13th Jul 2012 07:24
Quote: "maybe try this out

+ Code Snippet

function GetLimbIDByName(objectno,limbname$)
perform checklist for object limbs objectno
for x = 0 to checklist quantity()
if checklist string$(x) = limbname$ then limbno = x
next x
endfunction limbno
"


Here's a better version of the same thing. It's faster and stops searching once it finds the proper limb.


Quote: " That all works, however it can be considered a waste of time to constantly iterate through potentially all limbs only to find that the last one (or none!) has the sought name.
Although seeing as you probably at most have a couple of hundred limbs it might not be a very big slowdown issue."


I agree, that's why you keep track of the limbs. This way you check once and never have to check again.

Dim Character_Limbs(50)

Make a standardized limb list for your objects. Then store the real limb numbers in the array in the proper array indexes. Basically you need to "Map Out" the limb structure of your objects.
If you decide to do this then I really recommend streamlining the process like this:


This way the processing time is O(n) instead of O(n*n) and thus faster than the previously suggested method. If you studied software development in school, this is BIG O notation for describing how long a program takes to execute.

Quote: "If you have Matrix1Utilities you can use the "lookup" tables.
Unfortunately they're only string-to-string maps so you'll have to convert your limb ID's back and forth between strings and numbers.
Something like this (pseudocode, not sure if it'll compile but demonstrating the general idea):"


I don't want to give Matrix1Utilities bad press because the plugin is great. But don't do it that way. The priority here is speed. The Example you provided, to map all the limbs is going to be O(n*n) or worse. You're in the heat of battle, JAWS and ODDJOB have you pinned down behind a crate, the golden gun only has one bullet, the cavalry is loading and there's no time for choppy frames.


Taking a step back: You should really think about the process you are using to create these objects. Most people will find ways to skip this nonsense and have their modelling program create objects with the proper limb numbers from the start. Figuring this out could save you some work.

Kezzla
17
Years of Service
User Offline
Joined: 21st Aug 2008
Location: Where beer does flow and men chunder
Posted: 13th Jul 2012 08:02
Quote: "function GetLimbIDByName(objectno,limbname$)
perform checklist for object limbs objectno
for x = 0 to checklist quantity()
if checklist string$(x) = limbname$ then ExitFunction x
next x
endfunction -1"


nice one Mage. I didn't know about exitfunction(and i did look for it), my thought would be that breaking the for loop would cause a stack error. does exitfunction close all loops?

I was thinking about making x = checklist quantity() if true but exitfunction seems better.

I will use that in future. cheers

Sometimes I like to use words out of contents
GregA
15
Years of Service
User Offline
Joined: 21st Jun 2011
Location:
Posted: 13th Jul 2012 16:25
Quote: "Most people will find ways to skip this nonsense and have their modelling program create objects with the proper limb numbers from the start."



Explain more please, I don't understand.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 13th Jul 2012 19:18 Edited at: 13th Jul 2012 19:18
Quote: "Explain more please, I don't understand. "


Agreed.

It's complicated somewhat in DBPro because the built-in limb numbering doesn't match the limb order in the file. It really should be a simple matter to build the look-up list of names when you load the object - then it really shouldn't matter much whether it's an O(n) or O(n*n) search since it would only be done once.
GregA
15
Years of Service
User Offline
Joined: 21st Jun 2011
Location:
Posted: 14th Jul 2012 00:30
Well in the game im making right now, I only walk it that one time to extract the index of the limbs.

~although~ Having given it some though...

The proper way to do it, if you had to search it in your inner loop, would be to build a hash table of all the limb names, and put them in a dictionary or a binary tree structure, that contains the reference ID.

Then just search that sorted index, and since everything is hashed you avoid the expensive strcmp function, and you are just doing an integer compare.

I havent written it yet, because I think you need to be in the hundreds or thousands (at least dozens...) of limbs before there would be a net saving over just walking the structure...
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Jul 2012 00:45
Quote: "because I think you need to be in the hundreds or thousands (at least dozens...) of limbs before there would be a net saving over just walking the structure..."


You'd certainly need an enormous number of limbs before you got a significant saving using a one-off construction of a simple look-up table using a binary tree. But food for thought though.
basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 14th Jul 2012 05:22
from IanM matrix1_util 12:

Set Limb Name objno, limbno, name$

go through matrix1_util 12 and 18. it will give a huge boost to objects and limbs creation.

Mage
Valued Member
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 14th Jul 2012 06:42
Quote: "Quote: "Most people will find ways to skip this nonsense and have their modelling program create objects with the proper limb numbers from the start."


Explain more please, I don't understand. "


In simple terms, people usually will repeat their process for making their model. With many editors, you can usually copy the same bone structure and have it export in the same order. For example instead of completely starting a new project, load the last humanoid character, delete the mesh, keep the bones, and build a new mesh using the exact same existing bones. In many cases the same limb numbers will be exported. I doubt that any editor simply randomly assigns numbers, they all have a deterministic process.


Quote: "Quote: "Explain more please, I don't understand. "

Agreed.

It's complicated somewhat in DBPro because the built-in limb numbering doesn't match the limb order in the file. It really should be a simple matter to build the look-up list of names when you load the object - then it really shouldn't matter much whether it's an O(n) or O(n*n) search since it would only be done once. "


Yes the idea is to map out the limb structure once and then you don't need to waste time searching through it again. Since DBP doesn't do this, we can do this ourselves in the code.


Quote: "
Quote: "because I think you need to be in the hundreds or thousands (at least dozens...) of limbs before there would be a net saving over just walking the structure..."

You'd certainly need an enormous number of limbs before you got a significant saving using a one-off construction of a simple look-up table using a binary tree. But food for thought though. "


I can't see that being useful unless the limb structure is going to be wildly different each time, or so enormous that the code would be huge otherwise. Such as if you were building a level out of objects attached to limbs like terrain and walls. With a character you will know how many joints there are and all their names in advance. Even small variations like some people having tails, or zombies missing heads, can be planned. Then a simple array can store the limbs numbers at known/planned array indexes.


Again this whole issue sucks, and it's best to just make the content not need this in the first place.

GregA
15
Years of Service
User Offline
Joined: 21st Jun 2011
Location:
Posted: 14th Jul 2012 07:02
Mage,

My though was to load all the content for my game in one go. Then pick out each model and get a reference to it. This way I am using Blender as my level editor. I'd rather go to the hassle of figure this out than writing my own level editor, or trying to position the items with a series of "Load Object" and "Position Object" commands.

If you look at my game at, 23 limbs, it is working excellently for the moment.

I dunno though, Im done with Tic Tac Toe and am thinking up a more complex game.

I think my next game with either be a variation of Monopoly (but Im trying to work zombies in..., or perhaps a card game, a variant on the theme of Munchkin...

Those both seem a little ambitious to me ATM, Im trying to think of something between tic tac toe and that to tackle first.
Mage
Valued Member
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 14th Jul 2012 07:28 Edited at: 14th Jul 2012 07:29
If your game world is the limb structure, rather than simply talking about a person's bone structure, then the structure can't be predicted.
In this case you would have to search the whole structure. You would likely need to always search it, so using a binary tree at least makes that painful searching faster - O(log(n)) instead of O(n*n).

For Tic Tac Toe, it probably doesn't matter what you do. For a 40man World of Warcraft Raid, it probably matters.

For a person, everyone has 2 hands 2 legs, etc. So you can put it all in an array and have processing time of O(1). After the initial mapping to an array, the search is like simply HeadLimb = LimbArray(10).

Login to post a reply

Server time is: 2026-07-07 12:26:31
Your offset time is: 2026-07-07 12:26:31