Sunday, 12 December 2010

L-System - Render Method

Render Method

One of the critical algorithms to consider is the rendering function of the RuleManager class. Below is a proposed solution and justification for the method. The method will be recursive. Although this can often be more intensive on the CPU, it is important that every time we process a rule, we want to perform the same steps. We need to delve into the rules definition and perform the same process for every character. Given that the complexity of the solution depends on the users ruleset and the levels of branching they require, recursion is, I think, the most elegant and flexible solution.

Here is the function signature:
void render( const string & stringToProcess );

psuedoCode:

foreach char in stringToProcess

  if char is in CoreRules
         tell engine to draw / roll etc.
  elseif char is in UserRules AND currentRecursionLevel < branches
    ++recursionLevel
    render( UserRules[char] ) // recursive call
    --recursionLevel
  else
    cout << "Cannot find rule: " + char

No comments:

Post a Comment