Raised This Month: $2 Target: $400
 0% 

[SP] ConfigMap: StringMap & SMCParser


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
nergal
Veteran Member
Join Date: Apr 2012
Old 11-18-2019 , 20:47   [SP] ConfigMap: StringMap & SMCParser
Reply With Quote #1

presenting ConfigMap which is a StringMap Tree very much similar to KeyValues.

Difference is that it only works with strings as values and stringmaps as sections.


API:
Code:
ConfigMap(const char[] filename);

bool GetVal(const char[] key, PackVal valbuf);

void Destroy();

int GetSize(const char[] key_path);

bool Get(const char[] key_path, char[] buffer, int buf_size);

ConfigMap GetSection(const char[] key_path);

KeyValType GetKeyValType(const char[] key_path);
Accessing values and sections is easy:

assume this config:
Code:
"root" {
    "value1"    "howdy"
    "section1" {
        "value1"    "hi"
    }
    
    "section2" {
        "subsection1" {
            "value1"    "bonjour"
        }
    }
}
to access the value "howdy", use the key path string: "root.value1"
to access the value "hi", use the key path string: "root.section1.value1"
to access the value "bonjour", use the key path string: "root.section2.subsection1.value1"

to reduce having to use these key path strings all the time on frequently used subsections, use `GetSection` to save the ConfigMap of a subsection, there is no need to free the instance to the subsection.

When you're done with the entire config map, use `Destroy` to clean it all up.
Attached Files
File Type: sp Get Plugin or Get Source (cfg.sp - 78 views - 10.3 KB)
__________________

Last edited by nergal; 11-18-2019 at 20:47.
nergal is offline
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 11-21-2019 , 10:13   Re: [SP] ConfigMap: StringMap & SMCParser
Reply With Quote #2

Is there any way to include ConfigMap to Voice Changer? I just don't want to use KeyValues loop every time NormalSoundHook is called.
__________________
MAGNAT2645 is offline
nergal
Veteran Member
Join Date: Apr 2012
Old 06-29-2020 , 13:55   Re: [SP] ConfigMap: StringMap & SMCParser
Reply With Quote #3

Quote:
Originally Posted by MAGNAT2645 View Post
Is there any way to include ConfigMap to Voice Changer? I just don't want to use KeyValues loop every time NormalSoundHook is called.
yes! you gotta compile it with Voice Changer. I also want to add that ConfigMap is loop-friendlier than KeyValues since all you need to do get a specific section and iterate that section, here's an example of what I mean from VSH2 which uses ConfigMap:

Code:
	static char download_keys[][] = {
		"downloads.sounds",
		"downloads.models",
		"downloads.materials"
	};
	
	for( int i; i<sizeof(download_keys); i++ ) {
		ConfigMap download_map = g_vsh2.m_hCfg.GetSection(download_keys[i]);
		if( download_map != null ) {
			for( int n; n<download_map.Size; n++ ) {
				char index[10];
				Format(index, sizeof(index), "%i", n);
				int value_size = download_map.GetSize(index);
				char[] filepath = new char[value_size];
				if( download_map.Get(index, filepath, value_size) ) {
					switch( i ) {
						case 0: PrepareSound(filepath);
						case 1: PrepareModel(filepath);
						case 2: PrepareMaterial(filepath);
					}
				}
			}
		}
	}
Have it iterate over an array of keys that map to a section, grab that section, and iterate over it as needed
__________________

Last edited by nergal; 06-29-2020 at 13:56.
nergal is offline
Reply


Thread Tools
Display Modes

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


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