2020-06-15 15:45:53 +00:00
Coding Style
============
2020-06-14 10:55:31 +00:00
2020-06-15 15:45:53 +00:00
The coding style for EmulationStation-DE is mostly a combination of the Linux Kernel and Google C++ coding guidelines. \
Please refer to these documents here: \
https://www.kernel.org/doc/html/v4.10/process/coding-style.html \
https://google.github.io/styleguide/cppguide.html \
2020-06-14 10:55:31 +00:00
There are some deviations though, mostly due to historical reasons as the original code did not use this coding style.
2020-06-15 15:45:53 +00:00
Some key points:
2020-06-14 10:55:31 +00:00
* Column width (line length) is 100 characters
* Indentation is 4 spaces, don't use tabs as they can be interpreted differently!
2020-06-15 15:45:53 +00:00
* Line break is Unix-style (line feed only, no carriage return)
2020-06-15 20:14:41 +00:00
* Do not leave trailing whitespaces at the end of the lines (a good source code editor should have a setting to automatically trim these for you)
2020-06-21 12:25:28 +00:00
* When breaking up long lines into multiple lines, consider what could be useful data to grep for so you don't break in the middle of such a string
2020-06-14 10:55:31 +00:00
* Comments always in C++ style, i.e. // instead of /* */
* Comments should be proper sentences, starting with a capital letter and ending with a dot
2020-06-15 15:45:53 +00:00
* Use K& R placements of braces, read the Linux Kernel coding style document for clarifications
* Always use spaces between keywords and opening brackets, i.e. `if ()` , `for ()` , `while ()` etc.
2020-06-23 18:07:00 +00:00
* Use `std::string` instead of `char *` or `char []` unless there is a specific reason requiring the latter
2020-06-15 15:45:53 +00:00
* If the arguments (and initializer list) for a function or class exceeds 4 items, arrange them vertically to make the code easier to read
* Always declare one variable per line, never combine multiple declarations of the same type
* Name local variables with the first word in small letters and the proceeding words starting with capital letters, e.g. myExampleVariable
* Name member variables starting with a small 'm', e.g. mMyMemberVariable
* Use the same naming convention for functions as for local variables, e.g. someFunction()
2020-06-23 18:07:00 +00:00
* Inline functions makes perfect sense to use, but don't overdo it by using them for functions that won't be called very frequently
2020-06-28 16:39:18 +00:00
* Never put more than one statement on a single line (there are some exceptions though like lambda expressions and some switch statements)
2020-06-15 15:45:53 +00:00
* Avoid overoptimizations, especially if it sacrifices readability, makes the code hard to expand on or is error prone
* For the rest, check the code and have fun! :)
2013-11-12 23:28:15 +00:00
Development Environment
=======================
2020-06-23 18:07:00 +00:00
EmulationStation-DE is developed and compiled using GCC and GDB. Any code editor can be used of course, I use [VSCodium ](https://vscodium.com ). \
2020-06-14 10:55:31 +00:00
For debugging purposes, starting the application like this could make sense:
2013-11-12 23:28:15 +00:00
2014-03-14 03:14:49 +00:00
`emulationstation --windowed --debug --resolution 1280 720`
2013-11-12 23:28:15 +00:00
Creating a new GuiComponent
===========================
You probably want to override:
`bool input(InputConfig* config, Input input);`
Check if some input is mapped to some action with `config->isMappedTo("a", input);` .
Check if an input is "pressed" with `input.value != 0` (input.value *can* be negative in the case of axes).
`void update(int deltaTime);`
`deltaTime` is in milliseconds.
2018-01-17 14:14:21 +00:00
`void render(const Transform4x4f& parentTrans);`
You probably want to do `Transform4x4f trans = parentTrans * getTransform();` to get your final "modelview" matrix.
Apply the modelview matrix with `Renderer::setMatrix(const Transform4x4f&)` .
2013-11-12 23:28:15 +00:00
Render any children the component may have with `renderChildren(parentTrans);` .
Creating a new GameListView Class
=================================
1. Don't allow the user to navigate to the root node's parent. If you use a stack of some sort to keep track of past cursor states this will be a natural side effect.
2014-03-19 20:03:23 +00:00
Creating a new Component
========================
If your component is not made up of other components, and you draw something to the screen with OpenGL, make sure:
* Your vertex positions are rounded before you render (you can use round(float) in Util.h to do this).
2020-06-14 10:55:31 +00:00
* Your transform matrix's translation is rounded (you can use roundMatrix(affine3f) in Util.h to do this).