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

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


Post New Thread Reply   
 
Thread Tools Display Modes
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 09-10-2016 , 04:49   Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
Reply With Quote #131

Quote:
Originally Posted by Neuro Toxin View Post
I've just pushed an update for KeyValues.

Code:
"Styles"
{
    "0"
    {
        "name"    "Normal"
    }

    "1"
    {
        "name"    "Sideways"
    }
}
The below example would get "Normal".
Code:
dynamic.ReadKeyValues(...);
dynamic.GetDynamicByIndex(0).GetString("name", ...);
Fantastic, thanks

Edit: Now there's this error on server startup
Code:
L 09/10/2016 - 11:50:52: [SM] Exception reported: Could not read Handle 2d002d (error 1)
L 09/10/2016 - 11:50:52: [SM] Blaming: dynamic.smx()
L 09/10/2016 - 11:50:52: [SM] Call stack trace:
L 09/10/2016 - 11:50:52: [SM]   [0] GetPluginStatus
L 09/10/2016 - 11:50:52: [SM]   [1] Line 245, ..\dynamic.sp::_Dynamic_CollectGarbage()
L 09/10/2016 - 11:50:52: [SM]   [2] Line 117, ..\dynamic.sp::OnMapStart()
Except for this, I can confirm it works!

Code:
public void OnPluginStart()
{
	char[] sPath = new char[PLATFORM_MAX_PATH];
	BuildPath(Path_SM, sPath, PLATFORM_MAX_PATH, "configs/shavit-dynamic.cfg");

	Dynamic dStylesConfig = Dynamic();

	if(!dStylesConfig.ReadKeyValues(sPath))
	{
		PrintToServer("Could not read keyvalues!");
	}

	for(int i = 0; i < dStylesConfig.MemberCount; i++)
	{
		Dynamic dStyle = dStylesConfig.GetDynamicByIndex(i);

		char[] sName = new char[64];
		dStyle.GetString("name", sName, 64);

		int iAiraccelerate = dStyle.GetInt("airaccelerate");

		PrintToServer("%d - %s (%d AA)", i, sName, iAiraccelerate);

		dStyle.Dispose();
	}

	dStylesConfig.Dispose(true);
}
Code:
sm plugins reload dynamictest
0 - Normal (1000 AA)
1 - Sideways (1000 AA)
Edit 2: Nevermind, I guess my code was a problem as I don't get this error anymore
__________________
retired

Last edited by shavit; 09-10-2016 at 07:23.
shavit is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 09-10-2016 , 13:37   Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
Reply With Quote #132

A few tips based on your code:

Code:
public void OnPluginStart()
 {
     char[] sPath = new char[PLATFORM_MAX_PATH];
     BuildPath(Path_SM, sPath, PLATFORM_MAX_PATH, "configs/shavit-dynamic.cfg");
  
     Dynamic dStylesConfig = Dynamic();
  
     if(!dStylesConfig.ReadKeyValues(sPath))
     {
         PrintToServer("Could not read keyvalues!");
     }
  
     // .MemberCount currently requires a native call so
     // dont call it on every iteration in the loop
     // > important when code requires high performance
     int count = dStylesConfig.MemberCount;
  
     // Declare this outside the loop while using a static length.
     // When reading large data-sets, dynamically sized char arrays
     // will causes memory full errors, their memory seems to be 
     // only freed once the loop scope has been finished.
     char sName[DYNAMIC_MEMBERNAME_MAXLEN];
     
     for(int i = 0; i < count; i++)
     {
         Dynamic dStyle = dStylesConfig.GetDynamicByIndex(i);
         dStyle.GetString("name", sName, sizeof(sName));
         int iAiraccelerate = dStyle.GetInt("airaccelerate");
  
         PrintToServer("%d - %s (%d AA)", i, sName, iAiraccelerate);
  
         // These dynamic objects are disposed when the parent is disposed
         //dStyle.Dispose();
     }
     
     // Make sure you leave the disposemembers param set to true
     dStylesConfig.Dispose(true);
 }
__________________
Neuro Toxin is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 09-10-2016 , 13:57   Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
Reply With Quote #133

Quote:
Originally Posted by Neuro Toxin View Post
A few tips based on your code:

Code:
public void OnPluginStart()
 {
     char[] sPath = new char[PLATFORM_MAX_PATH];
     BuildPath(Path_SM, sPath, PLATFORM_MAX_PATH, "configs/shavit-dynamic.cfg");
  
     Dynamic dStylesConfig = Dynamic();
  
     if(!dStylesConfig.ReadKeyValues(sPath))
     {
         PrintToServer("Could not read keyvalues!");
     }
  
     // .MemberCount currently requires a native call so
     // dont call it on every iteration in the loop
     // > important when code requires high performance
     int count = dStylesConfig.MemberCount;
  
     // Declare this outside the loop while using a static length.
     // When reading large data-sets, dynamically sized char arrays
     // will causes memory full errors, their memory seems to be 
     // only freed once the loop scope has been finished.
     char sName[DYNAMIC_MEMBERNAME_MAXLEN];
     
     for(int i = 0; i < count; i++)
     {
         Dynamic dStyle = dStylesConfig.GetDynamicByIndex(i);
         dStyle.GetString("name", sName, sizeof(sName));
         int iAiraccelerate = dStyle.GetInt("airaccelerate");
  
         PrintToServer("%d - %s (%d AA)", i, sName, iAiraccelerate);
  
         // These dynamic objects are disposed when the parent is disposed
         //dStyle.Dispose();
     }
     
     // Make sure you leave the disposemembers param set to true
     dStylesConfig.Dispose(true);
 }
Already did all of those except commenting the dispose (did all of that for testing) - thanks
__________________
retired
shavit is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 09-11-2016 , 08:14   Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
Reply With Quote #134

I've just merged an update.

Offsets now use a special DynamicOffset type. Surprisingly this isn't a breaking change: Meaning any plugins compiled using the old int offsets will still continue to operate.

This update gives a nice boost in performance. Anyone using Static Dynamic Classes (eg: static int offsets in their methodmap properties) will see a substantial! boost in performance. Well, you probably wont lol, unless your doing 100K+ member operations on every server frame or such.

Last Triple Benchmark Output


Using this offset methodmap


I have a couple of new hacky changes planed (similar to today's offset update) for testing that will require another massive set of refactoring if they work. They should increase performance like never before (All native calls will be effectively removed and each plugin will access Dynamics data handles themselves). The trade off is, plugins not doing things right can crash dynamic, I plan to ad a compiler directive so you can compile your plugins to use this new method of accessing dynamic objects when you think your plugin is good enough to run without the safe guards in the native layer.

FYI: All the recent updates are focused towards performance as I start to build a LINQ style lookup system. This will ultimately tie into dynamic database tables that update themselves and a new database API wrapper that will be similar to PDO in PHP.
__________________
Neuro Toxin is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 09-11-2016 , 09:25   Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
Reply With Quote #135

I want to use Dynamic as a dependency with one of my plugins and apparently I need to include the file:
Code:
G:\scripting\include\dynamic.inc(168) : fatal error 183: cannot read from file: "../dynamic/system/methodmaps/dynamicoffset.sp"
Which isn't always ideal because 3rd-party APIs should be inside the include/ folder, is that intentional?
__________________
retired
shavit is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 09-11-2016 , 12:47   Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
Reply With Quote #136

technical ramble if you want to read it


All of this ramble will cause an entire namespace to be generated which will stem from the
'/sourcemod/scripting/dynamic/' folder structure. This structure generally avoids most
methodmap limitations around accessing methodmaps within property and functions
which have yet to be included based on the include order. I also have a huge portion of
my production code using this current structure to build namespaces for my plugins.

Currently I follow this construct.

Note: Any methodmap properties or functions that interact with other methodmaps within
their execution scope require the code to run from a public function. You will need to
include all of your methodmap.inc files first followed by the methodmap.sp files later.
If a public function tries to reference a methodmap that isn't yet included you receive
compilation errors. It's pretty much header and code files.

For your plugin:

1. Create a .inc file @ 'scripting/dynamic/methodmaps/<pluginname>/namespace.inc'.

For each methodmap:

2. Create a .inc file @ 'scripting/dynamic/methodmaps/<pluginname>/<methodmapname>.inc'
3. Create a .sp file @ 'scripting/dynamic/methodmaps/<pluginname>/<methodmapname>.sp'.

From your plugins main .sp file which should be stored in the /scripting/ folder:

4. include <dynamic> first
5. then include 'dynamic/methodmaps/<pluginname>/namespace'

Your namespace.inc file will:

6. FIRST include every 'dynamic/methodmaps/<pluginname>/<methodmapname>.inc'
7. SECOND include every 'dynamic/methodmaps/<pluginname>/<methodmapname>.sp'

What this does is: Gives any third party plugins that wants access to your namespace, a
simple way to include your namespace with one line, which will let them inherit
your dynamic methodmaps. Grouping your methodmaps together in '/dynamic/<pluginname>'
simplifies your workflow and helps others access your dynamic methodmaps.

I also create a `Dynamic_<PluginName>_NameSpace methodmap in my
`/dynamic/<pluginname>/namespace.inc`. You use the GetObjectByName and SetName
functions to store a global instance.

Code:
// Global stored at top of namespace.inc
Dynamic_Infested_NameSpace Infested;

// This is the methodmap public initialiser function
// To avoid methodmap limitations this would be called from your methodmaps
// initialiser. 
// Notice how I use FindObjectByName to globally name the namespace. This means
// any plugin that inherits your dynamic namespace will be accessing the same objects
public Dynamic Infested_NameSpace_Intialise()
{
   Infested = Dynamic.FindObjectByName("Dynamic_Infested_NameSpace");
   if (Infested == INVALID_DYNAMIC_OBJECT)
   {
      Infested = Dynamic_Infested_NameSpace();
      Infested.SetName("Dynamic_Infested_NameSpace");
   }
   return Infested;
}

// In your main .sp file
public void OnPluginStart()
{
   Infested = Dynamic_Infested_NameSpace()
}
__________________

Last edited by Neuro Toxin; 09-11-2016 at 13:22.
Neuro Toxin is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 09-14-2016 , 01:33   Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
Reply With Quote #137

Quote:
Originally Posted by shavit View Post
I want to use Dynamic as a dependency with one of my plugins and apparently I need to include the file:
Code:
G:\scripting\include\dynamic.inc(168) : fatal error 183: cannot read from file: "../dynamic/system/methodmaps/dynamicoffset.sp"
Which isn't always ideal because 3rd-party APIs should be inside the include/ folder, is that intentional?
I've cleaned up the include structures a bit.

You need to copy the dynamic folder in the include path.
__________________
Neuro Toxin is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 09-14-2016 , 02:02   Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
Reply With Quote #138

Quote:
Originally Posted by Neuro Toxin View Post
I've cleaned up the include structures a bit.

You need to copy the dynamic folder in the include path.
That's actually very ideal, thanks
__________________
retired
shavit is offline
mrkos9i4ok
Member
Join Date: Jul 2016
Location: Russia,Moscow
Old 09-17-2016 , 11:46   Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
Reply With Quote #139

Code:
L 09/17/2016 - 19:44:41: [SM] Exception reported: Unable to access dynamic handle -1
L 09/17/2016 - 19:44:41: [SM] Blaming: dynamic.smx()
L 09/17/2016 - 19:44:41: [SM] Call stack trace:
L 09/17/2016 - 19:44:41: [SM]   [0] ThrowNativeError
L 09/17/2016 - 19:44:41: [SM]   [1] Line 345, ..\dynamic.sp::_Dynamic_IsValid()
L 09/17/2016 - 19:44:41: [SM]   [2] Line 117, ..\dynamic/system/methodmaps/dynamicobject.sp::DynamicObject.IsValid()
L 09/17/2016 - 19:44:41: [SM]   [3] Line 501, ..\dynamic.sp::_Dynamic_GetMemberCount()
L 09/17/2016 - 19:44:41: [SM]   [4] Line 644, ..\dynamic/system/natives.sp::Native_Dynamic_GetMemberCount()
L 09/17/2016 - 19:44:41: [SM]   [6] Dynamic_GetMemberCount
L 09/17/2016 - 19:44:41: [SM]   [7] Line 218, C:\Users\Faust-PC\Desktop\Компилятор\scripting\include\dynamic.inc::Dynamic.MemberCount.get()
L 09/17/2016 - 19:44:41: [SM]   [8] Line 374, shavit-zones.sp::LoadZonesConfig()
L 09/17/2016 - 19:44:41: [SM]   [9] Line 402, shavit-zones.sp::OnMapStart()
mrkos9i4ok is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 09-17-2016 , 15:19   Re: Dynamic Objects and Properties - v.0.0.16 - [2016.07.14]
Reply With Quote #140

Quote:
Originally Posted by mrkos9i4ok View Post
Code:
L 09/17/2016 - 19:44:41: [SM] Exception reported: Unable to access dynamic handle -1
L 09/17/2016 - 19:44:41: [SM] Blaming: dynamic.smx()
L 09/17/2016 - 19:44:41: [SM] Call stack trace:
L 09/17/2016 - 19:44:41: [SM]   [0] ThrowNativeError
L 09/17/2016 - 19:44:41: [SM]   [1] Line 345, ..\dynamic.sp::_Dynamic_IsValid()
L 09/17/2016 - 19:44:41: [SM]   [2] Line 117, ..\dynamic/system/methodmaps/dynamicobject.sp::DynamicObject.IsValid()
L 09/17/2016 - 19:44:41: [SM]   [3] Line 501, ..\dynamic.sp::_Dynamic_GetMemberCount()
L 09/17/2016 - 19:44:41: [SM]   [4] Line 644, ..\dynamic/system/natives.sp::Native_Dynamic_GetMemberCount()
L 09/17/2016 - 19:44:41: [SM]   [6] Dynamic_GetMemberCount
L 09/17/2016 - 19:44:41: [SM]   [7] Line 218, C:\Users\Faust-PC\Desktop\Компилятор\scripting\include\dynamic.inc::Dynamic.MemberCount.get()
L 09/17/2016 - 19:44:41: [SM]   [8] Line 374, shavit-zones.sp::LoadZonesConfig()
L 09/17/2016 - 19:44:41: [SM]   [9] Line 402, shavit-zones.sp::OnMapStart()
that's an error with my plugin, not with dynamic..
__________________
retired

Last edited by shavit; 09-17-2016 at 15:20.
shavit is offline
Reply



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:47.


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