יום חמישי, 7 במאי 2015

Basic architecture

So , the first thing we wanted to achieve in the development process is a bear bone working game , no pretty UI elements or design , just feasibility. for that Doron and Orr set on to an almost two weeks ofcoding ,re-coding and re-factoring , architecture conceiving, article reading and fast food consuming nightmare.
The two most difficult issues they encountered were, how to design the Action and Operand Blocks and how to create and run the action sequence.
Unity3d added one more dimension to the first problem – using unity prevents the use of the "new" attribute to most of the Mono behavior successors, manning we had to re think and find new ways to implement creational  design patterns (Orr cried). At the end of the process we came out with the following design:



Running the Sequence –
 The problem:
Since Unity3D runs by refreshing frames, every frame the system starts to read its current "Update" function for all of the instantiated objects.
This made it difficult to plan an algorithm for which a sequence of operations is read and iteratively played for the user to see its result.
The following is an example for the sequence panel filled with some action blocks, thus an operation plan:

Since the Update function played by Unity happens in 1 frame for each iteration, if the whole code represented by the sequence would run in one frame, the code will never end, the frame would never finish the update and the program will crash.



The solution:
Our sequence operator script uses 1 frame to initiate the sequence built by the user, into the memory – it calls all its inner actions initiate functions, in their turn they load to the memory references of their inner children and calls their initiate functions. And so on.
Next, the sequence starts iterating, one action per update -
Each complex action, when called, runs their current frames child and returns – (True if it finished and False otherwise).
Each simple action, when called, runs its simple action, it takes place on the physics world, thus, it only makes a call to the relevant physics operator and returns that it finished.
Finally, the sequence operator holds a reference of the sequence action depth and the matching current child in depth. When the sequence starts running, all parameters are initialized to zero, and the operation runs each layer of actions, one by one, one frame per action.
This said, one more thing was desired to achieve, we wanted to be able to follow the sequence, as it runs, and see what action made which result. The solution for that is a timed delay between each sequence element, making it possible to differentiate between each action happening on screen and even make it visible to the user. 


















אין תגובות:

הוסף רשומת תגובה