Skip to content

Latest commit

 

History

History
118 lines (93 loc) · 4.26 KB

contrib.md

File metadata and controls

118 lines (93 loc) · 4.26 KB

Reporting Issues

If you believe you have a valid issue report, please post text or a screenshot from the log (the console window that opens alongside monsters) and build version (string visible in the filename of the produced binary), as well as your hardware and software information if applicable.

Contributing

monsters is a brand new project, so we have a great opportunity to keep things clean and well organized early on. As such, coding style is very important when making commits. Please use it to format your code when contributing. However, it doesn't cover all the rules below. Some of them aren't very strict rules since we want to be flexible and we understand that under certain circumstances some of them can be counterproductive. Just try to follow as many of them as possible:

General Rules

  • Don't ever introduce new external dependencies without openning an issue for discussion
  • Don't use any platform specific code
  • Avoid the use of C-style casts and instead prefer C++-style static_cast and reinterpret_cast. Try to avoid using dynamic_cast. Never use const_cast. The only exception to this rule is for casting between two numeric types, where C-style casts are encouraged for brevity and readability.

Naming Rules

  • Functions: camelCase
  • Variables: lower_case_underscored. Prefix with G_ if global.
  • Classes: PascalCase
  • Files and Directories: lower_case_underscored
  • Namespaces: PascalCase, _ may also be used for clarity (e.g. ARM_InitCore)

Indentation/Whitespace Style

Follow the indentation/whitespace style shown below. Do not use tabs, use 4-spaces instead.

Comments

  • For regular comments, use C++ style (//) comments, even for multi-line ones.
  • For doc-comments (Doxygen comments), use /// if it's a single line, else use the /** */ style featured in the example. Start the text on the second line, not the first containing /**.
  • For items that are both defined and declared in two separate files, put the doc-comment only next to the associated declaration. (In a header file, usually.) Otherwise, put it next to the implementation. Never duplicate doc-comments in both places.
// STD includes first
#include <map>
#include <memory>

// then, library includes
#include <SDL2/SDL.h>

// finally, monsters includes
#include "include/battle.h"
#include "include/monster.h"

// each major module is separated
#include "include/game.h"

    namespace Example {

  // Namespace contents are not indented

  // Declare globals at the top
  int g_foo{}; // {} can be used to initialize types as 0, false, or nullptr
  char *g_some_pointer{}; // Pointer * and reference & stick to the type name,
                          // and make sure to initialize as nullptr!

  /// A colorful enum.
  enum SomeEnum {
    ColorRed,   ///< The color of fire.
    ColorGreen, ///< The color of grass.
    ColorBlue,  ///< Not actually the color of water.
  };

  /**
   * Very important struct that does a lot of stuff.
   * Note that the asterisks are indented by one space to align to the first
   * line.
   */
  struct Position {
    int x{}, y{}; // Intitialize member variables!
  };

  // Use "typename" rather than "class" here
  template <typename T> void FooBar() {
    const std::string some_string{"prefer uniform initialization"};

    int some_array[]{
        5,
        25,
        7,
        42,
    };

    if (note == the_space_after_the_if) {
      CallAfunction();
    } else {
      // Use a space after the // when commenting
    }

    // Place a single space after the for loop semicolons, prefer pre-increment
    for (int i{}; i != 25; ++i) {
      // This is how we write loops
    }

    DoStuff(this, function, call, takes, up, multiple, lines, like, this);

    if (this || condition_takes_up_multiple && lines && like && this ||
        everything || alright || then) {

      // Leave a blank space before the if block body if the condition was
      // continued across several lines.
    }

    switch (var) {
    // No indentation for case label
    case 1: {
      int case_var{var + 3};
      DoSomething(case_var);
      break;
    }
    case 3:
      DoSomething(var);
      return;

    default:
      // Yes, even break for the last case
      break;
    }

    std::vector<T> you_can_declare, a_few, variables, like_this;
  }
}