A Coding Dilemma: What's the Best Coding Practice?

I have a trace file that is being read and using Cinematics to run the animation on it.



Currently, I have a Reader.java that reads and stores the events from the tracefile in an array and an Animator.java that executes that array item by item using Cinematics. This works fine however the nature of the coding is not the best design since I have a lot of if else statements (e.g. if move use this else if rotate use that, etc)



Therefore, I am trying to implement the Command Design Pattern in order to solve this.



So far I have a class called Adapter.java that reads and parses the trace file and depending on what’s read it executes the related class. For example the pseudocode:



[java]read line 1 and execute it

at execution if line 1 is rotate then call rotation.java and so on[/java]



I am able to pass arguments just fine. Now the question is where do I implement the actual animation functions (SimpleApplication , rootNode, etc)? If I do so in the adapter, it defies the purpose of using the command design pattern bc in that case I will have to have several if statements. Of course I don’t want to do that in every class created as this is obviously not a good practice.



What are your thoughts?

  1. read from xml.
  2. scripting language

that was not very helpful :wink:

Well, if you create a new JME project, by default, there should be a package (mygame) and a starting class (Main.java). Also, within that class, it has SimpleApplication being extended for you and several overriding methods laid out for you as well.



Now, with one main class will do and since it extends SimpleApplication, whatever elements you need (e.g. rootNode, assetManager, cam, inputManager, etc…), if you plan out your design properly, you can create functions in this main class to feed the associated classes linked to it with the arguments from this file. Say, in your Cinematic.java, you want to do an initRunAnim() to say, run your game’s trailer.



So, over at your Cinematic.java, your initRunAnim() can work out roughly be like this:

[java]public void initRunAnim(AssetManager assetManager){…}[/java]



while at Main.java, it be this way:

[java]

public void simpleInitApp(){

Cinematic c = new Cinematic();

c.initRunAnim(assetManager);

[/java]

So, whats a better practice, read the trace file and while parsing trigger events according to whats parsed directly? or store all events in an arraylist then after we stored the whole trace file, start parsing that arraylist (as if its a buffer)?