Skip to main content
gamedev.net
🔒 Locked

Creating Classes dynamicly...

Started by TheSyan Oct 11, 2002 at 5:15 AM 0 replies 200+ views
Original Post
TheSyan
TheSyan
I want to know, how to create classes dynamically, from, for exmaple a .MAP file. The file can store the class type of an entity, and then my program will load the relavent class. The thing is I dont want to hard code the classes into the code. Think half-life, in the may a modder, doesn''t have to add the code to create the class for a new weapon, they just code the class, and it looks for it, giving an error if its not found. I know a function name can be stored as a string and cast as a function using the (PROC) type cast, so I thought a method like this may exist... any help?
Red Ghost
Red Ghost
I would propose to check the factory pattern: let's have an example with a FPS weapon.
I think your DLL will hold the factory (returns a weapon class), the base virtual weapon class (weapon interface) and all the derived weapon classes.
Your initiation program flow becomes:
1- load up DLL - get the factory class
2- open scenario file read weapon ID
3- transfer the weapon ID to the factory - get a weapon object
4- close the scenario file
Thus your game will not hard code all weapon function and the weapon loading, it will just use the base weapon virtual class for all the game interactions. All weapon specific code will be in your DLL. The Game Programming Gems series have good articles regarding DLL and classes.
Hope that helps.
Ghostly yours,
Red.


[edited by - Red Ghost on October 11, 2002 6:39:53 AM]
Ghostly yours,Red.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.