Okay guys, here we go...
I have a functional ASCII sprite script interpretor thingy. It reads in the first command as a string, and converts it into a numeric code. Then, depending on command, it reads in proceding parameters.
The numeric command code and parameters are saved in an "Instruction" class. Then a list of instructions make the movie, get it?
So, a sprite will have a list of movies it can play, given triggers and such.
Problem Begin:
My sprites are polymorphed into more complicated things like bird, or bouncingthing, or whatever. Say I want to write a command specifical to invoke a function for a derived sprite function (ex. bird::batwings). My original idea was to go ahead and parse the command into a number that a bird''s overruling PlayMovie() can interpret. The problem is that for any sprite-specific command I add, I must change the base sprite''s ParseMovie function to accommodate.
Possible solution? How about preserving the command string, and interpreting that, no parsing at all? Saving 100+ string commands for a zillion sprites is pretty expensive, not to mention string-string comparison is slower.
Any good ideas?
Oddball Software
http://zap.to/oddball
Generality vs. Efficiency
The addition of commands is only done on startup, not during runtime. Thus, the overhead seems no problem to me.
DaBit.
DaBit.
You can shorten each command to reduce storage space and speed up string comparisons. You could also use a hash table to further speed up comparisons. Compared to the other operations you''re doing, I doubt this would make much of a dent in your speed.
Regards
Starfall
Regards
Starfall
January 29, 2000 01:29 PM
To try and meet things halfway, instead of creating actual instruction/function for derived classes, make a generic one like
SUBCLASS_SPECIFIC( instruction, other parameters... )
Then enumerate or define the specific functions for derived classes:
enum BAT_SPECIFIC{BAT_WING, BAT_SONAR, ...};
Then have your virtual function for SUBCLASS_SPECIFIC call private functions in the subclass using a switch() statment with a default: that does whatever you need to for invalid instructions.
The only problem with this is that you need some sort of run-time typing, whether RTTI or a returnType() function, considering you''ll have a list based on the base class. It''s not that big of a deal, just something to think about.
SUBCLASS_SPECIFIC( instruction, other parameters... )
Then enumerate or define the specific functions for derived classes:
enum BAT_SPECIFIC{BAT_WING, BAT_SONAR, ...};
Then have your virtual function for SUBCLASS_SPECIFIC call private functions in the subclass using a switch() statment with a default: that does whatever you need to for invalid instructions.
The only problem with this is that you need some sort of run-time typing, whether RTTI or a returnType() function, considering you''ll have a list based on the base class. It''s not that big of a deal, just something to think about.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement