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

[TF2] Optimizing: SDKCall VS Datamaps/Netprops


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Tylerst
Veteran Member
Join Date: Oct 2010
Old 05-13-2012 , 13:02   [TF2] Optimizing: SDKCall VS Datamaps/Netprops
Reply With Quote #1

I've been working on updating my Infinite Ammo Plugin, and have been working with sdktools a bit.

I was wondering which of these would be better as far as optimization.

Example 1(SDKCall):
Code:
new Handle:hGiveAmmo = INVALID_HANDLE;

public OnPluginStart()
{
	new Handle:hFile = LoadGameConfigFile("gamedatafile");
	if(hFile == INVALID_HANDLE) SetFailState("Gamedata file not found: gamedatafile");
	StartPrepSDKCall(SDKCall_Player);
	PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
	PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
	PrepSDKCall_AddParameter(SDKType_Bool, SDKPass_Plain);
	PrepSDKCall_SetFromConf(hFile, SDKConf_Virtual, "GiveAmmo");
	hGiveAmmo = EndPrepSDKCall();
	CloseHandle(hFile);
}

SDKGiveAmmo(client, iAmmo, iWeaponSlot, bool:bDisableSound)
{
	SDKCall(hGiveAmmo, client, iAmmo, iWeaponSlot+1, bDisableSound);
}
Example 2(Datamaps/Netprops):
Code:
new iOffset_Ammo;

public OnPluginStart()
{
	iOffset_Ammo = FindSendPropInfo("CTFPlayer", "m_iAmmo");
}

SetAmmo(client, iWeapon, iAmmo)
{
	new iAmmoType = GetEntProp(iWeapon, Prop_Send, "m_iPrimaryAmmoType")*4;
	SetEntData(client, iAmmoType+iOffset_Ammo, iAmmo, 4, true);	
}
I'm guessing the prop version would be slower due to getting ammotype every time, however I don't know how computationally expensive sdkcalls are.
Also, what if I specified ammotype myself, leaving only the SetEntData?

Last edited by Tylerst; 05-13-2012 at 13:16.
Tylerst is offline
Zephyrus
Cool Pig B)
Join Date: Jun 2010
Location: Hungary
Old 05-13-2012 , 13:42   Re: [TF2] Optimizing: SDKCall VS Datamaps/Netprops
Reply With Quote #2

Quote:
Originally Posted by Tylerst View Post
I've been working on updating my Infinite Ammo Plugin, and have been working with sdktools a bit.

I was wondering which of these would be better as far as optimization.

Example 1(SDKCall):
Code:
new Handle:hGiveAmmo = INVALID_HANDLE;

public OnPluginStart()
{
    new Handle:hFile = LoadGameConfigFile("gamedatafile");
    if(hFile == INVALID_HANDLE) SetFailState("Gamedata file not found: gamedatafile");
    StartPrepSDKCall(SDKCall_Player);
    PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
    PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
    PrepSDKCall_AddParameter(SDKType_Bool, SDKPass_Plain);
    PrepSDKCall_SetFromConf(hFile, SDKConf_Virtual, "GiveAmmo");
    hGiveAmmo = EndPrepSDKCall();
    CloseHandle(hFile);
}

SDKGiveAmmo(client, iAmmo, iWeaponSlot, bool:bDisableSound)
{
    SDKCall(hGiveAmmo, client, iAmmo, iWeaponSlot+1, bDisableSound);
}
Example 2(Datamaps/Netprops):
Code:
new iOffset_Ammo;

public OnPluginStart()
{
    iOffset_Ammo = FindSendPropInfo("CTFPlayer", "m_iAmmo");
}

SetAmmo(client, iWeapon, iAmmo)
{
    new iAmmoType = GetEntProp(iWeapon, Prop_Send, "m_iPrimaryAmmoType")*4;
    SetEntData(client, iAmmoType+iOffset_Ammo, iAmmo, 4, true);    
}
I'm guessing the prop version would be slower due to getting ammotype every time, however I don't know how computationally expensive sdkcalls are.
Also, what if I specified ammotype myself, leaving only the SetEntData?
imho giveammo just sets the netprop as well
__________________
Taking private C++/PHP/SourcePawn requests, PM me.
Zephyrus is offline
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 05-13-2012 , 14:07   Re: [TF2] Optimizing: SDKCall VS Datamaps/Netprops
Reply With Quote #3

giveammo obeys the max amount of ammo for that ammotype, which isn't possible easily with just the netprops.
You shouldn't worry about optimization here. I'd expect sdkcalls to be slightly "slower" than setting netprops, but you wouldn't really notice the difference.
__________________
Peace-Maker is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 05-13-2012 , 14:07   Re: [TF2] Optimizing: SDKCall VS Datamaps/Netprops
Reply With Quote #4

Try compiling two versions and use the Profiler to test the speed of each.
__________________
11530 is offline
Tylerst
Veteran Member
Join Date: Oct 2010
Old 05-13-2012 , 14:15   Re: [TF2] Optimizing: SDKCall VS Datamaps/Netprops
Reply With Quote #5

Quote:
Originally Posted by 11530 View Post
Try compiling two versions and use the Profiler to test the speed of each.
Wasn't aware of that tool, thanks.
That'll save me a lot of time, not having to ask.

Last edited by Tylerst; 05-13-2012 at 14:18.
Tylerst is offline
psychonic

BAFFLED
Join Date: May 2008
Old 05-13-2012 , 16:13   Re: [TF2] Optimizing: SDKCall VS Datamaps/Netprops
Reply With Quote #6

Use whatever is most readable and works. Don't prematurely optimize unless you know or suspect that you have a slowdown.
psychonic 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 20:37.


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