[TUT] Better Methodmaps tut
the sourcepawn transitional syntax wiki [ https://wiki.alliedmods.net/SourcePa...itional_Syntax ] horribly explains methodmaps.
This tutorial will aim to give a better understanding, especially to beginners... In a nutshell, Methodmaps are basically class-like functions for enums According to Bailopan, "Methodmaps are syntactic transformations only. That is, x.y() on methodmap Z is transformed into a function call that looks like Z_y(x)." - https://forums.alliedmods.net/showpo...&postcount=365 As you can see, methodmaps can help make life a bit easier. Let's begin! It should be known that methodmaps do not need to be attached to a enum to work. You can have a solo methodmap work by itself, but if you want custom types/tags, then you will be needing an enum. Because methodmaps are similar to classes, the first part of a methodmap you need is a constructor! Through messing around with the compiler and such, I've found that Constructors must always have the same name as the Methodmap they're operating from as well as having no identified return type! Constructors can also just do nothing lol! As long as you have a constructor at least. PHP Code:
PHP Code:
PHP Code:
Here's a good example. The parent methodmap has the money property while the child mtm has toys! Since the child mtm inherits from the parent mtm, that means you can use the "Money" accessor from the child mtm! PHP Code:
The most important concept of methodmaps is the "this" name. The "this" name basically refers to whatever instance of the methodmap uses the available functions inside it. look at the final code below to see what I mean. Here's the final product of what most realistic (custom) methodmaps would look like and how they are used! PHP Code:
another thing to introduce to the Methodmaps is the concept of "objectifying" them :) Here's an example! PHP Code:
with a nullable methodmap, you have to use "new" with its constructor! like so! PHP Code:
PHP Code:
.inc file PHP Code:
PHP Code:
|
Re: [TUT] Better Methodmaps tut
(int i = 0; i < 9; i++)
(int i = 0; i < 10; i++) |
Re: [TUT] Better Methodmaps tut
Quote:
|
Re: [TUT] Better Methodmaps tut
Quote:
(You can use your forum username and password to log in). |
Re: [TUT] Better Methodmaps tut
Quote:
|
Re: [TUT] Better Methodmaps tut
A huge focus of this is on properties... but none of your properties have anything backing them.
|
Re: [TUT] Better Methodmaps tut
Quote:
I'm assuming you're saying that there's no real variables? They're just examples. Plus we should talk about this more so others can understand more where I'm making a mistake |
Re: [TUT] Better Methodmaps tut
I will be watching this thread - Methodmaps is a completely foreign concept for me atm.
|
Re: [TUT] Better Methodmaps tut
Quote:
Regards, Nerus |
Re: [TUT] Better Methodmaps tut
Quote:
Quote:
|
Re: [TUT] Better Methodmaps tut
ok there, the examples have real backing fields now.
I also modified the custom example that most plugins would likely use. |
Re: [TUT] Better Methodmaps tut
Nice Tutorial.
This really helped me alot. Thanks OP |
Re: [TUT] Better Methodmaps tut
Quote:
|
Re: [TUT] Better Methodmaps tut
Quote:
PHP Code:
PHP Code:
PHP Code:
|
Re: [TUT] Better Methodmaps tut
Quote:
Basically, what happens is SP will get the return value from the get() method and increment that by one, then it will call the set() method with the new value. example: PHP Code:
|
Re: [TUT] Better Methodmaps tut
Thanks for the tut - very clear!
|
Re: [TUT] Better Methodmaps tut
Quote:
|
Re: [TUT] Better Methodmaps tut
Don't understand the tut at all honestly.
See this is why I just stay away from newdecls. |
Re: [TUT] Better Methodmaps tut
Quote:
|
Re: [TUT] Better Methodmaps tut
Quote:
|
Re: [TUT] Better Methodmaps tut
Are you breaking up with me?
|
Re: [TUT] Better Methodmaps tut
Quote:
|
Re: [TUT] Better Methodmaps tut
The only part I don't fully understand is when doing stuff like inheriting an ArrayList in a methodmap.
This one guy did upload a "Dynamic" plugin which is designed to allow developers to make the closest thing to objects. Well I figured out it would likely be simpler to just make a methodmap and have it inherit ArrayList like such: Code:
methodmap BDoor < ArrayList |
Re: [TUT] Better Methodmaps tut
Dynamic addresses a few concerns around simply inheriting ArrayList.
1. Blocksize: If you set a blocksize to accommodate for Strings your waisting memory for int/bool/float values. 2. It's nice to share methodmaps between plugins: however; if one plugin orders the indicies differently your corrupting data. You'd be best to inherit to a trie memory wise. A membername lookup via trie is really fast (dynamic does this internally). Once again Dynamic is designed to address a few issues when using a trie. 1. You might want to iterate members, this is impossible using a trie alone 2. Dynamic members are typed. Dynamic knows the type of each member and supports full type conversion for all the base pawn tags. Everything dynamic does is for a good reason. It can do 100k member reads in less than .1 seconds. So you shouldnt be concerned about performance. I have dynamic classes that have 100+ members and some members running on each frame / usercmd with no issues at all. |
Re: [TUT] Better Methodmaps tut
Quote:
You can iterate over a Trie by getting by getting a snapshot of its keys using CreateTrieSnapshot or StringMap's .Snapshot |
Re: [TUT] Better Methodmaps tut
Interesting.
Im going to have a play and do some benchmarking against dynamics current iteration support. Love your work mr lord. |
| All times are GMT -4. The time now is 22:06. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.