I'm having second thoughts about the cleanest way to design all my types/classes in my game engine. For the sake of keeping it short and simple for people to see what I'm up to, I'll pick a basic example.
[code]
Type GameEngine
' DETAILS OF THE 3D ENGINE GO IN HERE
' AMONG MANY OTHER THINGS, OF COURSE...
End Type
Type GameCamera
' THIS NEEDS TO ACCESS THE CAMERA CLASS OF THE 3D ENGINE.
End Type
[code]
Ok, simple enough, I think. Keep everything neat and tidy in it's own class, but the Engine class has the inner workings of the 3d engine within. Perhaps a class for cameras.
Now my game camera class needs to use that class to position it's camera, and perhaps check for collisions with meshes. So hmm.. yeah. it'll need the mesh class instance too.
Would it be cleaner design to give the camera class ( and every other class ) copies of the handles it might need ( as globals / statics obviously, since they will be the same for every instance of the camera class ) or would ie be cleaner to ( as I currently do ) give the camera class ( and all similar classes ) a handle back to the engine, which it can then use to work with the camera and mesh classes.
Of course, if the Engine is a singleton ( well, a fake-singleton really, with all globals and functions, no fields or methods ) then it need not have the instance, it can just call the class itself to access the camera and mesh classes. But either way, it's kinda the same effect. Should the camera and other game object classes have duplicates for everything or should they ( as I currently have it ) go back to the "root" or "hub" Engine class?
[code]
Type GameEngine
' DETAILS OF THE 3D ENGINE GO IN HERE
' AMONG MANY OTHER THINGS, OF COURSE...
End Type
Type GameCamera
' THIS NEEDS TO ACCESS THE CAMERA CLASS OF THE 3D ENGINE.
End Type
[code]
Ok, simple enough, I think. Keep everything neat and tidy in it's own class, but the Engine class has the inner workings of the 3d engine within. Perhaps a class for cameras.
Now my game camera class needs to use that class to position it's camera, and perhaps check for collisions with meshes. So hmm.. yeah. it'll need the mesh class instance too.
Would it be cleaner design to give the camera class ( and every other class ) copies of the handles it might need ( as globals / statics obviously, since they will be the same for every instance of the camera class ) or would ie be cleaner to ( as I currently do ) give the camera class ( and all similar classes ) a handle back to the engine, which it can then use to work with the camera and mesh classes.
Of course, if the Engine is a singleton ( well, a fake-singleton really, with all globals and functions, no fields or methods ) then it need not have the instance, it can just call the class itself to access the camera and mesh classes. But either way, it's kinda the same effect. Should the camera and other game object classes have duplicates for everything or should they ( as I currently have it ) go back to the "root" or "hub" Engine class?