so what im understanding, i would do something like
class myclass : public baseclass
string Cname ="c_myclass"
register(myclass) (or a pointer to it?)
registering it would add it to a list of all the other classes using its Cname, i would then be able to spawn shit by say
SpawnEntity(findCLassByName("c_myclass"),x,y)- and i could also register it with a "Magic number" also to facilitate smaller savefiles or, uh faster processing times (strings vs ints)
you would register an instance of the class.
you can't really have a pointer to the class itself, only to an instance of one.
typically, you would spawn something by passing the name, rather than something like a class-pointer (again, classes aren't first-class in C++, so you can't do this).
hence the whole point of having a class to describe the entity-class, so you can create an instance of it, and register this instance.
these particular classes though would be "one-off".
also, the added performance costs of using strings are not likely to really make a significant difference in this case (things like world spawning are "rarely significant"). (unless it is done very badly, it is unlikely to take long enough for anyone to be able to notice).
granted, it is possible to optimize a lot of string-handling code (if needed) via the use of hash-tables and similar (and probably store these files with any binary save-games). however, doing all this up-front would likely be a case of premature optimization.
for example, Quake 1 got along well enough dumping its savegames as text-files, and internally parsed all its entities from a textual form during map loading.
so, question time, would this register be er, pointers to the classes?, i'm still a little new to this, but i assume that if i did something like function(aclass) it would pass aclass's position in memory, and i could do something like x=aclass->x or .x or whatever.
i also found this
though it doesnt seem to have any description of how the classes are held so it's not so helpful
this also works, but does depend on some valve-specific macros and tools.
so, yeah, the goal is to understand how to do it directly.
in my case... I sort of-errm, cheat some.
namely, tools exist which parse the source-code (headers in this case), and basically mine out most of this stuff as "metadata", which is used both to allow loading/serialization and also to allow script code to make use of the entities, ... but this is all very non-trivial to implement (and many of my tools are also C only).
more likely, it will require code to load and store the contents of entities manually.
in my case, my storage is more in terms of (named) key/value pairs.
the "spawn entity" is basically just a collection of key/value pairs, which is generally the form loaded from maps or from savegames or world-regions.
when saved, the contents are converted back into a collection of key/value pairs, which are then written out.
Edited by cr88192, 19 February 2013 - 11:49 AM.