|
| 1 | +# Development |
| 2 | +--- |
| 3 | +### Recommended Code Editor |
| 4 | +Before proceeding, make sure the build preset you are using is `*-debug`. We recommend [Visual Studio Code](https://code.visualstudio.com/Download) as a code editor with the following extensions: |
| 5 | + |
| 6 | +- CMake Tools ([Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools) | [Open VSX](https://open-vsx.org/extension/ms-vscode/cmake-tools)) |
| 7 | +- clangd ([Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd) | [Open VSX](https://open-vsx.org/extension/llvm-vs-code-extensions/vscode-clangd)) |
| 8 | +- rust-analyzer ([Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer) | [Open VSX](https://open-vsx.org/extension/rust-lang/rust-analyzer)) |
| 9 | +- CodeLLDB ([Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb) | [Open VSX](https://open-vsx.org/extension/vadimcn/vscode-lldb)) |
| 10 | + |
| 11 | +Then open this folder with VS Code. It will ask which CMake preset to use and you need to choose the same one that you were using when building. Everything should work out of the box (e.g. code completion, debugging, etc). |
| 12 | + |
| 13 | +### macOS debugging issues |
| 14 | + |
| 15 | +If you can't launch or debug Obliteration from VS Code, try [this](https://github.com/vadimcn/codelldb/discussions/456#discussioncomment-874122) solution. |
| 16 | + |
| 17 | +### Get a homebrew application for testing |
| 18 | + |
| 19 | +If you don't have a PS4 application for testing you can download PS Scene Quiz for free [here](https://pkg-zone.com/details/LAPY10010). |
| 20 | + |
| 21 | +### Rules for Rust sources |
| 22 | + |
| 23 | +- Use unsafe code only when you know what you are doing. When you do try to wrap it in a safe function so other people who are not familiar with unsafe code can have a safe life. |
| 24 | +- Don't chain method calls without an intermediate variable if the result code is hard to follow. We encourage code readability as a pleasure when writing so try to make it easy to read and understand for other people. |
| 25 | +- Do not blindly cast an integer. Make sure the value can fit in a destination type. We don't have any plans to support non-64-bit systems so the pointer size and its related types like `usize` are always 64-bits. |
| 26 | +- Beware of deadlock and memory leak. Rust can protect us from most mistakes, except those two. Deadlock can be happen easily in Rust because Rust requires us to wrap the data we want to protect with a mutex and get a mutable reference through it. The problem with this is it become natural for you to lock the mutex to operate on the inner data, which can easily cause a deadlock if you are not aware when there are another locks being active. The only cases for memory leak you need to aware is when working with `Arc`. Just make sure you don't create a reference cycle that will never be dropped. |
| 27 | + |
| 28 | +### Rules for C++ sources |
| 29 | + |
| 30 | +Just follow how Qt is written (e.g. coding style, etc.). Always prefers Qt classes over `std` when possible so you don't need to handle exceptions. Do not use the Qt `ui` file to design the UI because it will break on a high-DPI screen. |
| 31 | + |
| 32 | +### Starting point |
| 33 | + |
| 34 | +The application consists of 2 binaries: |
| 35 | + |
| 36 | +#### Frontend |
| 37 | + |
| 38 | +This is what users will see when they launch Obliteration. Its entry point is inside `src/main.cpp`. |
| 39 | + |
| 40 | +#### Kernel |
| 41 | + |
| 42 | +This is where emulation takes place. Its entry point is inside `src/kernel/src/main.rs`. |
| 43 | + |
| 44 | +### Debugging the kernel |
| 45 | + |
| 46 | +Create `.kernel-debug` in the root of the repository. The contents of this file is YAML and the kernel will deserialize it to the `Args` struct in `src/kernel/src/main.rs` when passing the `--debug` flag to the kernel. See `Args` struct for available options. |
| 47 | + |
| 48 | +We already provide a launch configuration for VS Code so all you need to do is choose `Debug - Kernel` as the configuration and start debugging. |
| 49 | + |
| 50 | +### Code contribution |
| 51 | + |
| 52 | +If you want to make some contributions but don't know what to work on you can look for `TODO` comment or `todo!` macro invocation in the source code. You can also take a look at unassigned issues. |
| 53 | + |
| 54 | +### Additional informations |
| 55 | + |
| 56 | +[PS4 Developer Wiki](https://www.psdevwiki.com/ps4) has a lot of useful information about the PS4 internal. We also have a PS4 reverse engineering [project](https://github.com/obhq/reverse-engineering). |
0 commit comments