N
none
I have a "loader" class that loads 3D objects from disk. Initializing
"loader" objects is very expensive in both time and space, because there's
a lot to know about how to read a particular type of file.
Hence, I cannot create a new instance of "loader" every time I want to load
something. So I have several global loader objects that are initialized
when the program starts up -- the "character_loader," the
"monster_loader," the "weapon_loader," and so on. These are *not* classes
derived from "loader," they are simply global instances of loader that are
initialized differently so that they can load different types of objects.
These global loaders need to be used by many other objects of many
different types. This just means that the loader class itself needs to be
generic. In other words, everyone knows about loader but loader doesn't
know about anyone else.
Now, whatever object it is that uses one of these global loaders, that
object needs a way to be informed that something has happened, e.g., a
texture was loaded, a light source was loaded, loading is finished, etc.
What I *thought* that I wanted to do is have the loader use callback
functions. Each object that wants to load something could assign a
callback function to be invoked when important things happen within the
loader. The problem (as warned in the FAQ) is that doing so would require
some way for the loader to know the "this" pointer for each object. And to
make matters worse, the type of object that "this" refers to will vary.
Is this just a broken approach from the start?
Thanks.
"loader" objects is very expensive in both time and space, because there's
a lot to know about how to read a particular type of file.
Hence, I cannot create a new instance of "loader" every time I want to load
something. So I have several global loader objects that are initialized
when the program starts up -- the "character_loader," the
"monster_loader," the "weapon_loader," and so on. These are *not* classes
derived from "loader," they are simply global instances of loader that are
initialized differently so that they can load different types of objects.
These global loaders need to be used by many other objects of many
different types. This just means that the loader class itself needs to be
generic. In other words, everyone knows about loader but loader doesn't
know about anyone else.
Now, whatever object it is that uses one of these global loaders, that
object needs a way to be informed that something has happened, e.g., a
texture was loaded, a light source was loaded, loading is finished, etc.
What I *thought* that I wanted to do is have the loader use callback
functions. Each object that wants to load something could assign a
callback function to be invoked when important things happen within the
loader. The problem (as warned in the FAQ) is that doing so would require
some way for the loader to know the "this" pointer for each object. And to
make matters worse, the type of object that "this" refers to will vary.
Is this just a broken approach from the start?
Thanks.