Raised This Month: $7 Target: $400
 1% 

Module: Vdf (key/value trees) - 1.07


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
commonbullet
Veteran Member
Join Date: Oct 2005
Old 02-22-2007 , 00:19   Module: Vdf (key/value trees) - 1.07
Reply With Quote #1

This is a simple module to handle vdf (valve data files) trees. It makes very easy to read, create and write node structures.

A vdf tree is composed by nodes of key/value string pairs in quotation marks hierarchically disposed in braces.

Example:
Code:

"UserConfigData"
{
	"Steam"
	{
		"Cached"
		{
			"SteamGamesDialog.res"
			{
				"xpos"		"700"
				"ypos"		"112"
				"wide"		"204"
				"tall"		"332"
			}
                }
         }
}
Big thanks to sawce for helping with linux.
Attached Files
File Type: inc vdf.inc (10.5 KB, 1649 views)
File Type: zip vdf_amxx_1.07_release.zip (73.3 KB, 1718 views)
File Type: zip vdf_amxx_1.07_src.zip (60.6 KB, 1190 views)
File Type: zip examples.zip (21.3 KB, 1340 views)
File Type: zip everything-1.07.zip (152.4 KB, 1504 views)

Last edited by commonbullet; 11-27-2010 at 16:54.
commonbullet is offline
Send a message via ICQ to commonbullet Send a message via MSN to commonbullet
Zenith77
Veteran Member
Join Date: Aug 2005
Old 02-22-2007 , 09:58   Re: Module: Vdf trees
Reply With Quote #2

So basically now instead of creating are own file formats, we can just use this for plugins that require loading things? In other words, we could create are own .vdf files then read from them (I'm guessing 90% yes)? If so, you've saved my life.
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
Twilight Suzuka
bad
Join Date: Jul 2004
Location: CS lab
Old 02-22-2007 , 15:24   Re: Module: Vdf trees
Reply With Quote #3

That is actually reasonably cool.

A little ineffecient though, as you could use casts to hand the user a direct pointer, thus improving speed by a large margin (due to cache misses).

But cool none the less.
__________________
Twilight Suzuka is offline
Send a message via AIM to Twilight Suzuka Send a message via MSN to Twilight Suzuka
commonbullet
Veteran Member
Join Date: Oct 2005
Old 02-22-2007 , 16:18   Re: Module: Vdf trees
Reply With Quote #4

Yep, Zenith that's what it's supposed to be ;).

Thanks Rukia.

EDIT: I am working on that.

Last edited by commonbullet; 06-06-2007 at 20:25.
commonbullet is offline
Send a message via ICQ to commonbullet Send a message via MSN to commonbullet
sawce
The null pointer exception error and virtual machine bug
Join Date: Oct 2004
Old 02-23-2007 , 00:49   Re: Module: Vdf trees
Reply With Quote #5

Here's a Linux build (if you update and don't have a way to build Linux on your own PM me and I'll rebuild). I haven't tested this build's functionality beyond it loading properly.

I'd suggest 2 things:

1. Look at other module include files (.inc and the moduleconfig.h) (like fakemeta, engine) and see how they do module auto loading.

2. Update your amxxmodule.cpp/amxxmodule.h to whatever is in SVN, it doesn't export the amxx query functions properly in GCC4 with the version you have.
Attached Files
File Type: so vdf_amxx_i386.so (18.6 KB, 1194 views)
sawce is offline
BAILOPAN
Join Date: Jan 2004
Old 02-23-2007 , 01:07   Re: Module: Vdf trees
Reply With Quote #6

Shameless plug: If you're interested, I wrote an article on this file format using a different parsing technique: http://www.sourcemod.net/devlog/?p=96 (source code included)

Tree-based parsers are better for coders who like simplicity and don't like maintaining state, so I can certainly see this module being useful ;) good job.
__________________
egg
BAILOPAN is offline
commonbullet
Veteran Member
Join Date: Oct 2005
Old 02-23-2007 , 11:51   Re: Module: Vdf trees
Reply With Quote #7

Thank you sawce for that linux build, I'll check how to do the auto load thing and update my source files (I was using sdk from amxx 1.75).

Very cool reading - thanks Bail, maybe in future it could support both parsing methods (in separate modules or not), just like i.e. xml's sax & dom libraries.

I'm trying to work out Rukia's point (if I understand what she meant).
The way it works right now, nodes are exposed in pawn as indexes of a pointer 'list'. When a function is called it checks if node is in pointer array index bounds before picking up the pointer.

If these 'nodes' in script were directly nodes objects addresses, how could I safely cast them? (it could happen that a coder would pass a wrong argument or accidentally change the variable and hl would crash; I guess this would be hard to debug)

Last edited by commonbullet; 03-04-2007 at 20:26.
commonbullet is offline
Send a message via ICQ to commonbullet Send a message via MSN to commonbullet
Old 02-23-2007, 12:01
commonbullet
This message has been deleted by commonbullet.
Old 02-23-2007, 12:02
commonbullet
This message has been deleted by commonbullet. Reason: double post
BAILOPAN
Join Date: Jan 2004
Old 02-23-2007 , 13:29   Re: Module: Vdf trees
Reply With Quote #8

Using pointers directly is possible if you explicitly tell users not to pass wrong ones. For example, pcvars in AMX Mod X use direct pointers. Just tell users to be careful and not to assume that the return values are mutable or consistent in any way.
__________________
egg
BAILOPAN is offline
Zenith77
Veteran Member
Join Date: Aug 2005
Old 02-24-2007 , 12:46   Re: Module: Vdf trees
Reply With Quote #9

Already have some requests, as I plan on using this module in two of my major projects.
I would like these two natives:

Code:
vdf_is_first_node(); vdf_is_last_node();

or perhaps collapse them into one native:

Code:
vdf_is_node_number(myNode, 1); vdf_is_node_number(myNode, vdf_num_nodes(myParentNode));

The latter one would require an additional native though, 'vdf_num_nodes()', which as you can tell returns the number of nodes in the current node.

Also, you should put everything in one big .zip file ^^..
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred

Last edited by Zenith77; 02-24-2007 at 13:51.
Zenith77 is offline
commonbullet
Veteran Member
Join Date: Oct 2005
Old 02-24-2007 , 15:17   Re: Module: Vdf trees
Reply With Quote #10

Cool ideas.

You could check if it's the last or first node with "vdf_get_first_node" or vdf_get_last_node", but I see the advantages of using your model in a loop.

The new version is going to change functions arguments a bit, since nodes and trees will be pointers, functions like vdf_get_next_node won't need to pass the tree i.e.

And although this means performance enhancement you'll have to be very careful - I crashed hl a couple of times when I was writing the new example script carelessly...

For the same reason it's better to detach nodes concept from numbers. I'll include a function to count nodes in a branch though.

Finally I'm including important stuff I had forgotten like destroying trees and setting keys/values functions.

Last edited by commonbullet; 02-24-2007 at 15:21.
commonbullet is offline
Send a message via ICQ to commonbullet Send a message via MSN to commonbullet
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 22:49.


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