Stendhal code design: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
imported>Chad3f |
imported>Hendrik Brummermann No edit summary |
||
| (207 intermediate revisions by 6 users not shown) | |||
| Line 1: | Line 1: | ||
{{Stendhal code design}}{{Navigation for Stendhal Top|Developing}}__NOTOC__ |
|||
This page gives a little overview about the Stendhal code. |
|||
== Development Environment == |
|||
Stendhal is completely open source. So you can [http://arianne.sourceforge.net/download/stendhal-src.tar.gz download the source code] and have a look. If you plan to modify it and contribute to the project, we suggest that you use the Eclipse IDE and checkout the latest development state from our version control system. |
|||
== Client == |
|||
There are good [[Configure a development environment (IDE)|tutorials]] to get you started with Eclipse. |
|||
=== Entities === |
|||
== Finding your way around the Code == |
|||
Entity's are created using '''EntityFactory.createEntity()'''. In this method, the appropriete implementation class is created, and the '''initialize()''' method is called. When the entity is to be removed, the '''release()''' method should be called on it. |
|||
The next step is to find your way around the code. The Stendhal code base is roughly divided into the server, client and a little code that is used by both: |
|||
The design is being transitioned to a Model-View-Controller (MVC) like framework. This will allow different visual implementations (like 2D, 3D) to be plugged in with minimal (or no) changes of the model class. |
|||
* [[Finding your way around the Stendhal Server Code]] |
|||
'''Example:''' |
|||
* [[Finding your way around the Stendhal Client Code]] |
|||
* [[Finding your way around the Stendhal Web Client Code]] (early development) |
|||
RPObject object = ... |
|||
| ⚫ | |||
Entity entity = EntityFactory.createEntity(object); |
|||
// Force the view to be created |
|||
entity.getView(); |
|||
| ⚫ | |||
// Done with entity - free up resources |
|||
entity.release(); |
|||
== Coding Standards == |
|||
'''Model/Controller''' |
|||
We try to follow [http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html SUN Java code convention], in order to create code that feels familiar to many developers. |
|||
This contains all logical entity data, and is responsible for tracking all entity specific attribute changes in the RPObject that it wraps. Currently this also handles some of the UI controller functions. |
|||
Despite this: |
|||
The initialize() method is called with the RPObject that it will represent. This method is called after the constructor returns, but before anything else is [externally] called. |
|||
When the client no longer needs the entity, it should call release(), which should handling any cleanup that garbage collection only is insufficient. |
|||
* We use tab for all indentation. (One tab is equivalent to 4 spaces for display purpose.) |
|||
The class gets notified of object changes via the RPObjectChangeListener interface that it implements. This will be called for all changes to it's object (and immediate slot objects). |
|||
* We do not stick too closely to line length. |
|||
* We always use blocks in if-statements and loops, even if the block only consists of one single statement: |
|||
<code> |
|||
if (condition) { |
|||
method(); |
|||
| ⚫ | |||
</code> |
|||
Avoid evaluation and assignment in the same line like: |
|||
* ternary operators, for example in: |
|||
'''View''' |
|||
<code>String y = x==null ? "NULL": x.toString();</code> |
|||
* post-increment/decrement operators as in: |
|||
The current view implementation is Entity2DView. This is responsible for rendering an entity in a 2D view. |
|||
if (idx++ == 10) { |
|||
| ⚫ | |||
=== Sound System === |
|||
} |
|||
== Server == |
|||
Latest revision as of 20:38, 7 September 2015
Stendhal code design
This page gives a little overview about the Stendhal code.
Development Environment
Stendhal is completely open source. So you can download the source code and have a look. If you plan to modify it and contribute to the project, we suggest that you use the Eclipse IDE and checkout the latest development state from our version control system.
There are good tutorials to get you started with Eclipse.
Finding your way around the Code
The next step is to find your way around the code. The Stendhal code base is roughly divided into the server, client and a little code that is used by both:
- Finding your way around the Stendhal Server Code
- Finding your way around the Stendhal Client Code
- Finding your way around the Stendhal Web Client Code (early development)
Coding Standards
We try to follow SUN Java code convention, in order to create code that feels familiar to many developers.
Despite this:
- We use tab for all indentation. (One tab is equivalent to 4 spaces for display purpose.)
- We do not stick too closely to line length.
- We always use blocks in if-statements and loops, even if the block only consists of one single statement:
if (condition) {
method();
}
Avoid evaluation and assignment in the same line like:
- ternary operators, for example in:
String y = x==null ? "NULL": x.toString();
- post-increment/decrement operators as in:
if (idx++ == 10) {
...
}