AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [TUT] Better Methodmaps tut (https://forums.alliedmods.net/showthread.php?t=260680)

Neuro Toxin 05-28-2016 03:41

Re: [TUT] Better Methodmaps tut
 
Are you breaking up with me?

nergal 05-28-2016 19:38

Re: [TUT] Better Methodmaps tut
 
Quote:

Originally Posted by EasSidezz (Post 2422647)
It's not you, it's me.

ok, what part are you not understanding? ° ͜ʖ °

Chief149 06-09-2016 01:37

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
{
    public BDoor(int doorid)
    {
        ArrayList bdoor = new ArrayList();
        bdoor.Push(doorid); //index 0 is doorid
        bdoor.Push(0); //index 1 holds the locked state
        return view_as<BDoor>(bdoor);
    }
   
    property int doorid
    {
        public get()
        {
            return this.Get(0); //where the door id is stored
        }
    }

    property bool locked
    {
        public get()
        {
            return this.Get(1); //where the lock state is stored
        }
   
        public set(bool isLocked)
        {
            this.Set(1, isLocked);
            if(isLocked)
                AcceptEntityInput(this.doorid, "Lock");
            else
                AcceptEntityInput(this.doorid, "Unlock");
        }
    }
}

I mean, sure it means that basically every custom methodmap is technically an arraylist where someone could just add in code to modify any of the elements, but that's kind of the case with the Dynamic class that one guy made on here. It's just really simple I guess.

Neuro Toxin 06-09-2016 05:24

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.

Powerlord 06-09-2016 22:59

Re: [TUT] Better Methodmaps tut
 
Quote:

Originally Posted by Neuro Toxin (Post 2426041)
1. You might want to iterate members, this is impossible using a trie alone

That hasn't been true since SM 1.7 came out.

You can iterate over a Trie by getting by getting a snapshot of its keys using CreateTrieSnapshot or StringMap's .Snapshot

Neuro Toxin 06-10-2016 00:22

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.