Raised This Month: $12 Target: $400
 3% 

Dynamic Objects and Properties - v.0.0.32 - [2018.05.08]


Post New Thread Reply   
 
Thread Tools Display Modes
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 03-19-2016 , 23:02   Re: Dynamic Objects and Properties - v008 - [2016.03.19]
Reply With Quote #41

Quote:
Originally Posted by ImACow View Post
.FindParent()
That could be done...

Quote:
Originally Posted by ImACow View Post
.FindChild()
Same as get member methods (Int/Float/Bool/Object)

Quote:
Originally Posted by ImACow View Post
.DisposeParent()
Would be the same as .FindParent().Dispose()

Quote:
Originally Posted by ImACow View Post
.DisposeChildren()
Would be the same as .Dispose().

I will note, technically members cant be disposed of at all. However, if a member is of type Object then it can be disposed (When Handles are introduced as a type this would also include CloseHandle()).

Quote:
Originally Posted by ImACow View Post
.CountChildren()
.MemberCount already exists



Edit: Dynamic.FindByName will only search named objects where their name was set by SetName().
__________________

Last edited by Neuro Toxin; 03-19-2016 at 23:03.
Neuro Toxin is offline
SM9
Veteran Member
Join Date: Sep 2013
Location: United Kingdom
Old 03-24-2016 , 21:17   Re: Dynamic Objects and Properties - v008 - [2016.03.19]
Reply With Quote #42

It would be cool to have a sorting option for the objects so I can for example build a weapon menu in alphabetical order, cheers.
SM9 is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 03-24-2016 , 22:04   Re: Dynamic Objects and Properties - v008 - [2016.03.19]
Reply With Quote #43

Version 0.0.9
- Added member sorting

Say I add the following members to a fresh dynamic object
Code:
Dynamic someobj = Dynamic();
someobj.SetInt("someint", 1);
someobj.SetFloat("somefloat", 512.7);
someobj.SetBool("somebool", true);
When I iterate the members like this...
Code:
int count = someobj.MemberCount;
int memberoffset;
char membername[DYNAMIC_MEMBERNAME_MAXLEN];
char membervalue[64]

for (int i = 0; i < count; i++)
{
    memberoffset = someobj.GetMemberOffsetByIndex(i);
    someobj.GetMemberNameByIndex(i, membername, sizeof(membername));
    someobj.GetStringByOffset(offset, membervalue, sizeof(membervalue));
    PrintToServer("[SM] someobj.%s == '%s'", membername, membervalue)
}
I get an output like so (the output is in the same order I added the members)...
Code:
[SM] someobj.someint == '1'
[SM] someobj.somefloat == '512.70000000'
[SM] someobj.somebool == 'True'
Then if I sort the members with...
Code:
someobj.SortMembers(Sort_Ascending);
The output becomes (members are displayed in ascending order based on member name)...
Code:
[SM] someobj.somebool == 'True'
[SM] someobj.somefloat == '512.70000000'
[SM] someobj.someint == '1'
Note: The above example also shows how Dynamic does type conversion to strings!
__________________

Last edited by Neuro Toxin; 03-24-2016 at 22:07.
Neuro Toxin is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 03-24-2016 , 22:12   Re: Dynamic Objects and Properties - v006 - [2016.03.15]
Reply With Quote #44

Quote:
Originally Posted by kossolax View Post
What about handle types ?
FYI: This is coming next along with support for vectors...

Then I'll add support for GetParent
__________________
Neuro Toxin is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 03-25-2016 , 01:46   Re: Dynamic Objects and Properties - v.0.0.10 - [2016.03.25]
Reply With Quote #45

Version 0.0.11
- Added support for Handle data type
- Added support for Vector data type

Using handles
Code:
// You can also get and set Handles
someobj.SetHandle("somehandle", CreateArray());
Handle somehandle = someobj.GetHandle("somehandle");
PushArrayCell(somehandle, 1);

// Calling dispose on someobj will CloseHandle somehandle
someobj.Dispose();

// If you dont want the handle to close on Dispose you can
someobj.SetHandle("somehandle", null);
someobj.Dispose();

// Another way to avoid the handle closing is
someobj.Dispose(false);
Using Vectors
Code:
// Vectors are also supported like so
float somevec[3] = {1.0, 2.0, 3.0};
someobj.SetVector("somevec", somevec);
someobj.GetVector("somevec", somevec);

// Vectors support type conversion to String's only
char buffer[64]
someobj.GetString("somevec", buffer, sizeof(buffer));
// -> buffer = "{1.0, 2.0, 3.0}"
__________________
Neuro Toxin is offline
kossolax
AlliedModders Donor
Join Date: Jan 2008
Location: Belgium
Old 03-25-2016 , 03:55   Re: Dynamic Objects and Properties - v.0.0.10 - [2016.03.25]
Reply With Quote #46

By the way, with the membername caching in offset... is the performance as good as enumeration?

Most IDE understand enumeration for the auto completion but does not support stringmap.
kossolax is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 03-25-2016 , 06:13   Re: Dynamic Objects and Properties - v.0.0.10 - [2016.03.25]
Reply With Quote #47

When you lookup a member by name a Trie is used.

- When a member name is not found in the trie. If required, a new member is created at the next offset and the name is stored in the trie with the members offset as the value. The next available offset is also calculated and stored.

When you lookup a member by offset the trie isnt required so you gain a small performance boost.

Most of the work in member lookups is recalculating an offset into an index and cell position for the array that holds the data and actually fetching or storing the data in the array.
__________________
Neuro Toxin is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 04-08-2016 , 23:22   Re: Dynamic Objects and Properties - v.0.0.12 - [2016.04.09]
Reply With Quote #48

Updated to version 0.0.12
- Previous include not updated to support Vectors (thanks iNilo)
__________________
Neuro Toxin is offline
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 04-08-2016 , 23:40   Re: Dynamic Objects and Properties - v.0.0.12 - [2016.04.09]
Reply With Quote #49

Great work Neuro! I havent had the chance to use it for a replacement for natives yet, but I did finally get a chance to try it for other purposes. Great work making it more OO. Should be part of SM core if you ask me. ;)
__________________
ThatOneGuy is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 04-10-2016 , 04:11   Re: Dynamic Objects and Properties - v.0.0.13 - [2016.04.10]
Reply With Quote #50

Updated to version 0.0.13
- Updated Class Builder to support new types
- Include file bugfix for Vector type to fix Class Builder generated code
- Created Example Class Usage file
__________________
Neuro Toxin is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:05.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode