Am Samstag, 27. Januar 2007 schrieb Dennis Schridde:
> Am Donnerstag, 28. Dezember 2006 schrieb Dennis Schridde:
> > Hello everyone!
> >
> > I can't find the last thread on this topic anymore, so I started a new
> > one...
> >
> > I am currently into replacing the resource system with a Lua driven one.
> > Works well so far. (Am only in the very early stages.)
> >
> > The concerns some of you had, that Lua could be too slow for that task,
> > are very very probably wrong.
> > I just tried to parse 20k modules.
> > (Each mod had only 2 resources, but when I look at the current code: 20k
> > mods with only 2 resources is very probably worse than 1k mods with 20
> > resources each. And even having 1k mods is highly unrealistic.)
> >
> > It seems like the place where it needs the most time is the dependency
> > creation part, which currently only consists of some nested for loops
> > walking the whole mod and resource list to find the deps.
> > If I exchange the string compares against some hashing and use a tree
> > instead of a list, I guess it will be fast enough.
>
> Here comes some early preview of the parser.
> Just reads the testscript.lua, creates the according module/resource
> structure in memory, incl. dependencies etc. and then prints it.
> Should give an idea of the syntax and structure.
> Be aware, this is by no means polished.
>
>
> Some intro on the deps system (which this approach is all about):
>
> findResource( "foo", myModule ):
> When referencing a resource like "foo", it will search the resource of this
> name the given myModule and all of its parents. Should be a bit faster
> since not all modules have to be looked at.
>
> findResource( "foo:bar", NULL ):
> When referencing a resource as "foo:bar", it will search the resource of
> name "bar" in the module named "foo". Walks through all modules to find it,
> so it will be a bit slower than the short reference. (You don't have to
> supply NULL, of course. The supplied module will be ignored in case you
> give a full reference.)
>
> For the next time I'll work on loading of resources and their deps.
Loading of resources now works in theory.
Dependencies are automatically loaded when a resource is loaded and unloaded 
when the resource is unloaded and no one else uses it.
You will find the API in resource_manager.h and an example is to be found in 
main.c

Call WRF_load(filename) for all wrf files you need.
Then call WRF_init(), which will setup the internal depencencies. It will fail 
if called twice, so after you called it once, you cannot add additional wrf 
files...

Now you can call WRF_loadResource to explicitly request a resource to be 
loaded. This will ensure that it is not unloaded when not requested.

You can also call WRF_getData directly, which will load the resource if it was 
not before. This function will return the data associated with the resource, 
which was loaded by the loader implementation.

WRF_exit() will unload all resources and destroy them.

All functions are provided in a ByName and a ByHandle version for convenience. 
Both are equal besides that ByName does a name lookup (and thus is slower), 
which ByHandle doesn't need.
I will probably remove the ByName version and instead export the findResource 
function and require everybody to search for themselves if needed.

--Dennis

Attachment: lua_wrf.7z
Description: application/7z

Attachment: pgpAavgn26qRm.pgp
Description: PGP signature

_______________________________________________
Warzone-dev mailing list
Warzone-dev@gna.org
https://mail.gna.org/listinfo/warzone-dev

Reply via email to