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.

Dark GDK / How would I go about reading limb data of DBO objects in DGDK?

Author
Message
Marth Koopa
16
Years of Service
User Offline
Joined: 23rd Apr 2008
Location:
Posted: 2nd Nov 2009 07:17
I use 3DWS to make levels for my game, and use a lot of custom entities to easily populate them with things. I'm trying to port my DBPro project to DGDK for numerous reasons (the main one being that DBPro IDEs seem to be extremely slow making it annoying to code anymore)

I copied the functions from IncaPro to my DBPro project to read limb data, it was easy and works great... but I don't know how I would incorporate this in C++ & DGDK. I've tried "translating" the DBPro code to C++ code, line by line, but strings confuse the heck out of me in C++ and I just can't get it to work.

If someone wants to walk me through how I would get this working, that would be great.
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 2nd Nov 2009 19:28
Don't really know what kind of limb data your looking for, but here is a small function that returns the limb ID for a given limb name:



( the number of max. limbs is 1000 in this, change it if you want )

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
prasoc
15
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 2nd Nov 2009 21:56
or change the loops to this:




Your signature has been erased by a mod
Marth Koopa
16
Years of Service
User Offline
Joined: 23rd Apr 2008
Location:
Posted: 2nd Nov 2009 22:18
The limb data I'm looking for is all of the stuff about my entities that I place in 3DWS... this is a bit of the code I used in my DBPro project. It looks through all of the limbs, then does things depending on what they are.



These are the functions being used by that, I have no idea what they are doing though so I have no idea how to translate it into C++

Marth Koopa
16
Years of Service
User Offline
Joined: 23rd Apr 2008
Location:
Posted: 6th Nov 2009 03:21
Well, I've ported everything from my DBPro project into DGDK, except for this one little routine I use to populate the world. I've been trying to find a way to make it work, or simply just a new way, but I can't do it...

Any ideas on how to do it, or some alternatives?
Marth Koopa
16
Years of Service
User Offline
Joined: 23rd Apr 2008
Location:
Posted: 6th Nov 2009 03:52
Well, what I mean is, I can print the limb name to the screen and see what the object type is and all of its info, but I don't know how to extract all of that from a single string so I can work with it.
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 6th Nov 2009 10:25
As far as I understand, you are saving the entity properties in the limbs name. If this is the case then I would advise you to use the standart string library to manipulate the strings (split them up, add together,...). I think it's very useful and use it a lot.
Just include <string> and use namespace std.

This page may be helpful: C++ Strings

Hope that's what you are looking for...

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
Marth Koopa
16
Years of Service
User Offline
Joined: 23rd Apr 2008
Location:
Posted: 7th Nov 2009 02:25
I've read that over, but I don't know how to extract specific data from the limb names.

I can find the names of the data I want, but I cant get the value for them.

Example... I can find if it's an "enemy" and that he has "HP", but not the value of his HP
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 7th Nov 2009 03:58
If you have the string-part that contains the HP value you could do it like this:



Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
Marth Koopa
16
Years of Service
User Offline
Joined: 23rd Apr 2008
Location:
Posted: 8th Nov 2009 01:10
I can extract "HP" from the limb name, but not with the value of it, that's my biggest problem right now.

I'm terrible with manipulating strings, it's why I just copy/pasted the functions from the IncaPro demo.
Marth Koopa
16
Years of Service
User Offline
Joined: 23rd Apr 2008
Location:
Posted: 10th Nov 2009 02:24
Well I give up, I can't figure this out

I'm just going to make a small program in DBPro that will read the data and put it in a text file that will be easily read in DGDK.

It's an extra step I'll have to do when exporting maps, and an extra step in coding, but oh well
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 10th Nov 2009 14:57 Edited at: 10th Nov 2009 18:27
Hey, don't just give up! I can't imagine this to be that hard.

Let's say you have your standard string with the data in it:



Then you could make a function to read the HP from it something like this:



Finally call it like this:



I haven't tested it, but I think it works.
If it doesn't: post, and we'll figure it out

EDIT: This assumes your health string (the value) is always 3 digits long! So the highest possible value is 999 and for example 12 HP is HP012.

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
Marth Koopa
16
Years of Service
User Offline
Joined: 23rd Apr 2008
Location:
Posted: 11th Nov 2009 05:07
I would like it to be a little less specific on what the string wants. I have very huge numbers(some times in the millions), and I don't feel like counting out lots of 0s when typing the numbers in 3DWS.

An example of the string I get form the limb name...

Classname=monster
hp=1004
damage=400
objecttype=entity

That's all in the same string. I was trying a different method... It would look for the name of the data I want, then it would count the number of characters until a "\n" appears. I was able to delete the text preceding what I want... for example... when I looked for "hp" the string would be reduced to

hp=1004
damage=400
objecttype=entity

now if I could delete everything after the 1004, I could then just delete the "hp=" and get my value, but I seem to be running into some errors.

the programs find that the length of hp=1004 is 8(I think it's counting the "\n", so I was trying to use strncpy to copy the length found into a new char, but the program keeps crashing on the strncpy line with an "unhandled expression". When I mouse over the get and get2 chars after clicking break on the error screen, it says "0x00000000 <Bad Ptr>"

Here's the function in my world class for reading limb data then making things from it(obviously not done yet). "obj" is the object number of the DBO file loaded.

_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 11th Nov 2009 12:38
Well, I can't really see what's wrong with this function at first glance, but I would really advise you to use the standard string class library!
It makes life a lot easier, you can use normal operators like + or == on your strings, and you have lots of useful functions like 'find' or 'substr'. And you don't have to worry about pointers or something.

If you're using such long strings, I think it's better to work with some kind of terminating character (like you already tried with \n).

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 11th Nov 2009 21:15
Quote: "the program keeps crashing on the strncpy line"


No wonder, as you never allocate memory for the string that get2 should point to. (Doesn't the compiler give you an "unitialized local variable" warning when you are compiling it?) That variable is just a pointer, you should allocate a memory area for the string, either by a new command:



in which case it is also good practice to delete[] it when you are done using it, or you can use a static char array:



Also, Dark GDK functions that return char pointers, like dbLimbName, create a new string in memory whenever they are called. If the returned string is never deleted, it will cause memory leak.
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 11th Nov 2009 22:49 Edited at: 11th Nov 2009 22:50
Quote: "Dark GDK functions that return char pointers, like dbLimbName, create a new string in memory whenever they are called"


Even if I create a string s = dbLimbName(...) ? What do I have to do to fix those memory leaks when using std::string?

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 11th Nov 2009 23:25
You can store the pointer into a variable and then delete it after it's copied:



In fact, now that you asked, in the case of dbLimbName I'm not quite sure how it works. Ever since I learned of this obligation to delete returned strings, I supposed that all functions with char* return type should be handled similarly. If it doesn't create a new string, then the other possibility is that it gives a pointer directly into the object data where the original string is. I don't find that very probable, but at the moment I don't have a suitable limbed object to test with. So treat this info with some reservation, but now I'm curious so I'll try to test later how it really behaves.
Marth Koopa
16
Years of Service
User Offline
Joined: 23rd Apr 2008
Location:
Posted: 12th Nov 2009 01:08
_Pauli_, I've modified the examples you gave me just a little bit, and came up with this:



The difference being I can specify what I want to look for, rather than always it looking for "HP", and after it finds "inputstr" it looks for the next "\n", then generates a substr from those two points.

for example... I could do this: int hp = get_value(limbname,"hp")
or this: int damage = get_value(limbname,"damage")

Though I'm not quite sure if this is complete...could I be missing anything? I'm going to compare the results of this method with the one I use in DBPro and see if it's generating the same results.

And to find the classname all I do is this:


Thank you very much for the help, I think I'm understanding strings a bit more.
Marth Koopa
16
Years of Service
User Offline
Joined: 23rd Apr 2008
Location:
Posted: 12th Nov 2009 01:36
HOORAY it's working! I needed to make a few more changes to locate just the number in order for it to be converted properly, though.

Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 12th Nov 2009 07:55
Marth: Good to hear that your problem is solved! It's always nice when something is finally working.

Pauli: I found a test object and made a few tests this morning. It's confirmed that dbLimbName creates a new string every time, so you need to delete it after use.
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 12th Nov 2009 14:14
Mireben:
Ok, thanks for the info!
By the way - how can I check for memory leaks in VC++ 2008 Express?

Marth:
Great! Of course I just did the function only for HP to make it easier - lots of room to optimize
But you see: String class is your friend
I find them very useful!
(If you write 'using namespace std' in your code you don't have to write 'std::' all the time...)

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 13th Nov 2009 20:32 Edited at: 13th Nov 2009 20:34
Quote: "how can I check for memory leaks in VC++ 2008 Express?"


I don't know a general solution unfortunately. I checked this string issue like this: wrote a simple program that used a lot of the command in question, let it run for a while and watched the memory usage in the Windows task manager. It was surely going up. Then I tried the same with deleting the returned string and the memory usage was steady. Also, as a final proof, I tried to modify the returned string through the pointer, then called dbLimbName again, which still returned the original string, so what I modified was a copy.

The problem is that watching the memory usage in the task manager is hardly a professional approach with a bigger application which keeps loading and deleting resources (unless the leak is really big). I usually try to avoid leaks by triple-checking that all created resources get deleted somewhere, even if there is an exception and the program is forced to quit. So far I haven't used a leak detector program, maybe I should hunt around for one, for the future. There was a thread in this forum only a few days ago, with "memory leak" in the title where a few tools were suggested.

Login to post a reply

Server time is: 2024-10-01 18:37:31
Your offset time is: 2024-10-01 18:37:31