Dynamic Objects and Properties - v.0.0.32 - [2018.05.08]
Dynamic Wiki | Download | Examples
Dynamic allows developers to use truly dynamic data structures in SourcePawn. This means you can define a Methodmap and use Dynamic to back it's member data at run-time. All dynamic members are typed which allows automatic type conversion between base types. You can then extend and inherit Dynamic Methodmaps to build complex namespaces. Namespaces simplify the sharing of complex structures which third party plugins can easily access with a minimal amount of code. Features - Fully methodmap based to try and give an Object Orientated feel - Inherit Dynamic to make your own simple methodmaps - Easily name and retrieve dynamic objects between multiple plugins (no natives required)!!!! - Supports String, int, float, bool, Handle, Vector and Dynamic types - Automatic type conversion!! - Static objects for Server and Player Settings - Hook member changes - Member iteration / looping - Member sorting - Load and Save flat configs - Load and Save KeyValue configs Dynamic Methodmaps - Extend Dynamic to create your own Dynamic methodmaps - A Class Builder to quickly generate basic Dynamic methodmaps - You dont have to muck around with Dynamic Member Offsets to improve performance - All of the same features that come with Dynamic Objects Planned Changes - Add serialisation support using mysql Download (v0.0.32) Example Use + Features Example Class Use Example Class Example Class Builder Include File |
Re: Dynamic Objects and Properties
Very cool, Will save me a lot of time instead of using natives all the time :P
|
Re: Dynamic Objects and Properties
I've done some profiling of the current version attached to the OP.
Here is the profiling code:
Spoiler
Code:
[SM] Starting Benchmark Tests... |
Re: Dynamic Objects and Properties
1 Attachment(s)
I've made a second version.
The main idea was to try and speed up Create/Update member operations. The internal data for each object is one array, rather than 3 arrays (one for each type (int, float, string)). The member name is also contained in the data, where as the first version has a lookup array that points to the members position in the data array (1 per type again). Code:
[SM] Starting Benchmark Tests... I also believe lots of the internal functions are passing around arguments that could be static. Version 002 is attached to this post. If anyone has any idea's or suggestions on how to go about making this as optimised as possible, I'm all ears! |
Re: Dynamic Objects and Properties
Cool stuff
|
Re: Dynamic Objects and Properties
Quote:
|
Re: Dynamic Objects and Properties
Quickly. Get him before he leaves lol
Edit: on topic. I done another version which is heaps faster! |
Re: Dynamic Objects and Properties
1 Attachment(s)
Version 003.
I'm using a Trie for member lookups and arrays for data storage. It's up to 10 times faster. The Trie holds the offset for where the members data is held in the internal array. Code:
[SM] Starting Benchmark Tests... |
Re: Dynamic Objects and Properties
Wow thank you for this, this is exactly what I have been needing for my plugin. I am correct in saying it works just like any other data type in that I can have an array of them like
Code:
Dynamic object[32] |
Re: Dynamic Objects and Properties
You sure can :)
Edit: remember to initialise them as per the first post |
Re: Dynamic Objects and Properties
Quote:
|
Re: Dynamic Objects and Properties
Okay, so I get that you can store integers, floats, and strings in this thing. For someone who's first "language" is SourcePawn: When and Why should I use this?
|
Re: Dynamic Objects and Properties
Hi headline :)
Great question. The main purpose of use is when you require irregular data sets to be stored and shared between plugins. An example maybe storing times for a timer plugin. You would not be required to store arrays for level / player times and could simply use a dynamic object for storage. You could also hook member data changes which will call forwards to each plugin that has hooked the dynamic object. With this your plugins can be aware of changes in real time without constantly checking for updated data via natives or global forwards. You wouldn't use dynamic objects for plain arrays that dont need to be shared via other plugins. If you've ever had a moment where you wish you could make your own netprop. This is a viable solution that would allow such functionality without the need for you to write natives. I'm personally using this to create member sets for each player. Where one plugin can store members like a playerid and others can read them easily and or hook member changes. I also hook changes and use them to update a mysql databases to synchronise changes automatically to and from plugins with no effort at all. I have some planned changes where <dynamic>(1-maxplayers) will always relate to data for the corresponding client index that auto initialises and disposes with client connect and disconnect events. |
Re: Dynamic Objects and Properties
Got something weird.
PHP Code:
|
Re: Dynamic Objects and Properties
Quote:
Code:
Dynamic someobject = Dynamic(); Code:
Dynamic someobject = view_as<Dynamic>(Native_GetDynamicObject()); Code:
return view_as<int>(someobject); |
Re: Dynamic Objects and Properties
Quote:
Can you maybe post a basic code for one plugin that sends the value and another plugin that receives the value? Maybe thats easier to understand for me & others. |
Re: Dynamic Objects and Properties
Ok. I'll do something up on the weekend hopefully.
|
Re: Dynamic Objects and Properties
Nice, i'm learning more and more from you, keep going.
I will propably use for my next mod. |
Re: Dynamic Objects and Properties
Nice to see similar objectives like in C# and Java in SM :) I head problems with methodsmaps, now I think that u solve my problem, THX !
I always create same question in any topic of plugins, but this is my first time in lib thread: will you add dynamic to github please ? :) P.S. One more thing: Quote:
I had some errors i try to create dynamic player like: Quote:
Quote:
Next I added dynamic player to array based on client id: Quote:
Quote:
Regards, Nerus |
Re: Dynamic Objects and Properties
To check if a object is valid use...
Code:
if (player.IsValid) You also need to Dispose() your object OnClientDisconnect. These objects are not managed and will cause memory leaks if not disposed of correctly. Code:
player.Dispose(); GetInt() already supports default values as the second parameter. Code:
int defaultvalue = player.GetInt ("notset", 123); |
Re: [2016.02.21] Dynamic Objects and Properties - v004
I just moved this to Github and released version 004.
The main post has been updated. A new example is included on how this is used that covers almost all features of Dynamic. |
Re: [2016.02.27] Dynamic Objects and Properties - v005
As we know, methodmaps require data backing the properties which steers people away from using them.
You can create methodmaps that inherit the Dynamic class and write properties that use the dynamic object to back the properties. dynamic-example.inc Quote:
1. All members must be set to their default values in the constructer 2. Use static offsets in each property to increase performance I'm about to make a webpage where you can define your class. It will then spit out the methodmap to make that class using Dynamic. |
Re: [2016.02.27] Dynamic Objects and Properties - v005
Dynamic Classes
- Extend Dynamic to create your own Dynamic Classes - A Class Builder to quickly generate basic Dynamic Classes - You dont have to muck around with Dynamic Member Offsets to improve performance - All of the same features that come with Dynamic Objects I just finished a basic web based class builder.
I used these settings to...
Generate this methodmap...
Which can be used like this in a plugin!
|
Re: [2016.02.27] Dynamic Objects and Properties - v005
not bad... not bad
|
Re: [2016.02.27] Dynamic Objects and Properties - v005
The latest profile stats...
I'm really curious around why the reading of members using a string membername is quicker than using integer offsets. Quote:
|
Re: [2016.02.27] Dynamic Objects and Properties - v005
Just updated Dynamic to version 0.0.6
Changes...
The technical answer as to why offsets are now faster...
The latest profile stats...
Member name lookups vs Offset lookups...
Github Changes Download Edit: I've completed a code generate tweak for the Dynamic Class Generator. - Member offsets are stored when a member is set for the first time |
Re: Dynamic Objects and Properties - v006 - [2016.03.15]
Just realised I need to add support for boolean types.
I'll do this soon by wrapping Get/SetBool around integer support. This will be similar to how Get/SetObject works if your familiar with how the Dynamic methodmap works. In the mean time booleans can be used with Get/SetInt. |
Re: Dynamic Objects and Properties - v006 - [2016.03.15]
Quote:
|
Re: Dynamic Objects and Properties - v006 - [2016.03.15]
Great question.
Handles can currently be used via Get/SetInt. You might need view_as casting to avoid type mismatch warnings. I will however add support for Handles after completing bool support. |
Re: Dynamic Objects and Properties - v006 - [2016.03.15]
This is amazing.
Thanks for this! this saved me hours of writing natives to cross communicate with plugins |
Re: Dynamic Objects and Properties - v006 - [2016.03.15]
Dynamic someobj = Dynamic();
someobj.SetBool("somebool", true); -> error 105: cannot find method or property Dynamic.SetBool |
Re: Dynamic Objects and Properties - v006 - [2016.03.15]
Quote:
Quote:
|
Re: Dynamic Objects and Properties - v006 - [2016.03.15]
My bad, did not read through pages.
Btw I want to make data persistent when a plugin reloads, is this the correct way ? Offload.smx -> getDyn & setDyn. Mainplugin.smx -> OnPluginStart -> Create Dynamic object. -> OnPluginEnd -> Use SetDyn from Offload.smx to set the reference of the dynamic. then in main plugin on a plugin start check if the getDyn is a valid dynamic? http://i.imgur.com/N6dxQis.png |
Re: Dynamic Objects and Properties - v006 - [2016.03.15]
After some head scratching this is what im thinking.
Code:
Dynamic someobj = Dynamic.GetByName("pluginname_settings"); Code:
If (!someobj.IsValid) Code:
someobj = Dynamic(); In the sanerio above. Moomoo could try find a dynamic object by name on plugin start. |
Re: Dynamic Objects and Properties - v007 - [2016.03.19]
Version 0.0.7 released
- Added support for boolean datatypes - Updated example plugin to include bool usage - Updated test plugin to verify bool usage and conversion between datatypes |
Re: Dynamic Objects and Properties - v007 - [2016.03.19]
Version 0.0.8 released
- Added support for naming dynamic objects - Updated example plugin to show usage of naming objects - Dispose now supports automatic disposing of disposable members Code:
public bool SetName(const char[] objectname, bool replace=false) Code:
// You can name a dynamic object |
Re: Dynamic Objects and Properties - v008 - [2016.03.19]
Awesome dude!
|
Re: Dynamic Objects and Properties - v008 - [2016.03.19]
I'm using this now to offload all my plugin data on PluginEnd, and recover it on PluginStart
|
Re: Dynamic Objects and Properties - v008 - [2016.03.19]
An example of the changes around .Dispose.
Code:
Dynamic someobj = Dynamic(); |
Re: Dynamic Objects and Properties - v008 - [2016.03.19]
Some ideas:
can FindByName be used to search children? .FindParent() .FindChild() .DisposeParent() .DisposeChildren() .CountChildren() Cow. |
All times are GMT -4. The time now is 09:38. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.