Skip to content

Commit

Permalink
Merge branch 'master' of github.com:gta-reversed/gta-reversed-modern …
Browse files Browse the repository at this point in the history
…into reverse/CCoronas
  • Loading branch information
Pirulax committed Jul 16, 2023
2 parents f44c2c6 + 950f181 commit b90f927
Show file tree
Hide file tree
Showing 160 changed files with 2,933 additions and 1,356 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
[submodule "libs/imgui"]
path = libs/imgui
url = ../../ocornut/imgui.git
branch = docking
[submodule "libs/tracy"]
path = libs/tracy
url = git@github.com:wolfpld/tracy.git
61 changes: 48 additions & 13 deletions docs/CodingGuidelines.MD
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
* Please check and try to eliminate warnings from your code.

### Code style
* 4 space indentation, LF line endings.
* If some rule about something is not specified here, refer to how it's done in the code.
* Some classes may have *helper* functions to make code more readable. (usually denoted by *NOTSA* or *Helpers*) Try looking for and use them.
* 4 space indentation, LF line endings
* No hungarian notation [It's useless]
* If some rule about something is not specified here, refer to how it's done in the code
* Some classes may have *helper* functions to make code more readable. (Denoted by *NOTSA*) - Try adding new ones, or looking for and using them.
* Prefer `get`-ters/`set`-ters over raw member access
* Use range-based for loops as much as possible.
* We encourage you to write modern C++, but if that's not your style, please keep the following in mind:
```cpp
for (auto& element : array); // <-- GOOD

Expand All @@ -17,23 +20,55 @@ for (int i = 0; i < std::size(array); i++); // <-- BAD
```cpp
for (auto&& [i, e] : notsa::enumerate(array));
```
* If there's a dynamic `count` variable associated with a fixed size array, use `std::span` or `rng::views::take`. E.g.:
```cpp
// Bad
for (auto i = 0u; i < m_numThings; i++);

// Good
for (auto& thing : std::span{ m_things, m_numThings });
// Also good
for (auto& thing : m_things | rng::views::take(m_numThings));

* Use `f` in float literals, omitting it makes them double. (e.g. `1.0f`)
* Use `std` library for generic functions like `min`, `max`, `lerp` etc.
* Function prototypes must look like it's from Android symbols. Except for output parameters like `T*` can be changed to `T&` to make the code prettier.
* Use lambdas for repetitive procedures in functions.
* Use `constexpr` variables instead of macros.
// ^ If these funcs are called more than once, make a helper function in the header. Like below:
auto GetActiveThings() {
return std::span{ m_things, m_numThings }
}
* Use `f` in float literals [As omitting it would make them a `double`] (e.g. `1.0f`)
* Use `std` library for generic functions like `min`, `max`, `lerp`, etc...
* `CVector` is interchangible with 3 floats [As is `CVector2D` with 2 floats] for function args
* Use lambdas for repetitive procedures in functions
* Use `constexpr` variables instead of macros
* Use `static inline` instead of `extern` and `static` in headers:
```cpp
class Foo {
static uint32& m_FooCount; // Bad

static inline auto& m_FooCount = StaticRef<uint32, 0xDEADBEEF>(); // Good
}
```
#### Types
* Use `auto` in function bodies if the variables' type is guessable.
* Guess for enum values, at least leave a TODO comment for it.
* Take care of const correctness. (e.g. `const char*` over `char*`)
* Guess for enum values [Or at least leave a `TODO` comment]
* Take care of const correctness [Especially of class methods] (e.g. `const char*` over `char*`)
* Try to use SA types over RW as much as possible, **except** `RwMatrix`. (e.g. `CVector` for `RwV3d`, `CRGBA` for `RwRGBA`)
* Use fixed width integer types (e.g. `uint8`, `int32`).
* Use `std::array` for arrays most of the time. Do not use it if the variable is just a pair of values or something basic like that.
* Do not use Win32 types. (e.g. `DWORD` -> `uint32`)
* Do not use Win32 integer types. [Except for Win32 exclusive code] (e.g. `DWORD` -> `uint32`)
* For array sizes, etc.. prefer using `unsigned` types over `signed` ones
* Whenever possible use `std::array` over `C-Style` array [as the former has bounds checking in debug mode, and can help us discover many bugs]
#### Fixing bugs
Whenever you find a bug, we encourage you to fix it [and/or at least] leave a comment explaining what the bug is.
Bug fixes should only be active if `notsa::IsFixBugs()` returns `true`.
If that's not possible [due to code complexity], then wrap into an `#ifdef`:
```c
#ifdef FIX_BUGS
// Bug fixing code here
#endif
```

### Contributing
Please make sure to test your contribution before opening a PR. Guess what places/missions are affected by your code and test them. Use debug menu (F7) for quick access to stuff.
Please make sure to test your code before opening a PR. Guess what places/missions are affected by your code and test them. Use debug menu (F7) for quick access to stuff.

If you don't know how to test the code or think you have not tested enough specify it in the PR message.
7 changes: 7 additions & 0 deletions libs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,10 @@ target_include_directories(imgui PUBLIC
)
target_link_libraries(imgui PRIVATE d3d9 ${CMAKE_DL_LIBS})
target_compile_definitions(imgui PRIVATE _CRT_SECURE_NO_WARNINGS)

# set options before add_subdirectory
# available options: TRACY_ENABLE , TRACY_ON_DEMAND , TRACY_NO_BROADCAST , TRACY_NO_CODE_TRANSFER , ...
option(TRACY_ENABLE "" ON)
option(TRACY_ON_DEMAND "" ON)
option(TRACY_CALLSTACK "" ON)
add_subdirectory(tracy) # target: TracyClient or alias Tracy :: TracyClient
2 changes: 1 addition & 1 deletion libs/imgui
Submodule imgui updated 189 files
79 changes: 79 additions & 0 deletions libs/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,82 @@ project "imgui"
"imgui/backends",
"imgui/misc/cpp"
}

project "tracy"
language "C++"
kind "StaticLib"
targetname "tracy"
warnings "Off"

vpaths {
["Headers/*"] = {"tracy/**.h*",},
["Sources/*"] = {"tracy/**.cpp",},
["*"] = {"premake5.lua", "CMakeLists.txt"}
}

includedirs {
"tracy/public/",
}

files {
"tracy/public/TracyClient.cpp",

-- tracy_includes
"tracy/public/tracy/TracyC.h",
"tracy/public/tracy/Tracy.hpp",
"tracy/public/tracy/TracyD3D11.hpp",
"tracy/public/tracy/TracyD3D12.hpp",
"tracy/public/tracy/TracyLua.hpp",
"tracy/public/tracy/TracyOpenCL.hpp",
"tracy/public/tracy/TracyOpenGL.hpp",
"tracy/public/tracy/TracyVulkan.hpp",

-- client_includes
"tracy/public/client/tracy_concurrentqueue.h",
"tracy/public/client/tracy_rpmalloc.hpp",
"tracy/public/client/tracy_SPSCQueue.h",
"tracy/public/client/TracyArmCpuTable.hpp",
"tracy/public/client/TracyCallstack.h",
"tracy/public/client/TracyCallstack.hpp",
"tracy/public/client/TracyCpuid.hpp",
"tracy/public/client/TracyDebug.hpp",
"tracy/public/client/TracyDxt1.hpp",
"tracy/public/client/TracyFastVector.hpp",
"tracy/public/client/TracyLock.hpp",
"tracy/public/client/TracyProfiler.hpp",
"tracy/public/client/TracyRingBuffer.hpp",
"tracy/public/client/TracyScoped.hpp",
"tracy/public/client/TracyStringHelpers.hpp",
"tracy/public/client/TracySysPower.hpp",
"tracy/public/client/TracySysTime.hpp",
"tracy/public/client/TracySysTrace.hpp",
"tracy/public/client/TracyThread.hpp",

-- common_includes
"tracy/public/common/tracy_lz4.hpp",
"tracy/public/common/tracy_lz4hc.hpp",
"tracy/public/common/TracyAlign.hpp",
"tracy/public/common/TracyAlloc.hpp",
"tracy/public/common/TracyApi.h",
"tracy/public/common/TracyColor.hpp",
"tracy/public/common/TracyForceInline.hpp",
"tracy/public/common/TracyMutex.hpp",
"tracy/public/common/TracyProtocol.hpp",
"tracy/public/common/TracyQueue.hpp",
"tracy/public/common/TracySocket.hpp",
"tracy/public/common/TracyStackFrames.hpp",
"tracy/public/common/TracySystem.hpp",
"tracy/public/common/TracyUwp.hpp",
"tracy/public/common/TracyYield.hpp",
}

defines {
"TRACY_ENABLE",
"TRACY_CALLSTACK",
"TRACY_ON_DEMAND",
--"TRACY_NO_CODE_TRANSFER" -- Uncomment if you want callstacks to be working
}

--removefiles {
-- "tracy/public/server/**.*"
--}
1 change: 1 addition & 0 deletions libs/tracy
Submodule tracy added at 897aec
8 changes: 8 additions & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,15 @@ target_link_libraries(${RE_PROJECT_LIB_NAME} PRIVATE
ogg
vorbisfile
imgui
Tracy::TracyClient
ddraw
Winmm
dxguid
strmiids
dsound
d3d9
)

target_include_directories(${RE_PROJECT_LIB_NAME} PRIVATE
/
toolsmenu/
Expand Down
3 changes: 1 addition & 2 deletions source/InjectHooksMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,7 @@

#include "platform/win/VideoPlayer/VideoPlayer.h"
#include "platform/win/VideoMode.h"
#include "platform/win/win.h"
#include "platform/platform.h"
#include "platform/win/Platform.h"

#include "app/app.h"
#include <RealTimeShadowManager.h>
Expand Down
2 changes: 2 additions & 0 deletions source/StdInc.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ namespace rngv = std::views;
#include "HookSystem.h"
#include "reversiblehooks\ReversibleHooks.h"

#include <tracy/Tracy.hpp>

// DirectX
#include <d3d9.h>
#define DIRECTINPUT_VERSION 0x0800
Expand Down
4 changes: 3 additions & 1 deletion source/app/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "Plugins/BreakablePlugin/BreakablePlugin.h"
#include "Pipelines/CustomBuilding/CustomBuildingRenderer.h"

#include "win/win.h"
#include "platform/win/Platform.h"

void AppInjectHooks() {
RH_ScopedCategory("App");
Expand Down Expand Up @@ -54,6 +54,8 @@ bool DoRWStuffStartOfFrame(int16 TopRed, int16 TopGreen, int16 TopBlue, int16 Bo

// 0x53D7A0
bool DoRWStuffStartOfFrame_Horizon(int16 TopRed, int16 TopGreen, int16 TopBlue, int16 BottomRed, int16 BottomGreen, int16 BottomBlue, int16 Alpha) {
ZoneScoped;

CDraw::CalculateAspectRatio();
CameraSize(Scene.m_pRwCamera, nullptr, SCREEN_VIEW_WINDOW, SCREEN_ASPECT_RATIO);
CVisibilityPlugins::SetRenderWareCamera(Scene.m_pRwCamera);
Expand Down
3 changes: 1 addition & 2 deletions source/app/app_camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ void CameraSize(RwCamera* camera, RwRect* rect, RwReal viewWindow, RwReal aspect
rect->x = rect->y = 0;
}

RwVideoMode videoMode;
RwEngineGetVideoModeInfo(&videoMode, RwEngineGetCurrentVideoMode());
const auto videoMode = RwEngineGetVideoModeInfo(RwEngineGetCurrentVideoMode());

if (videoMode.flags & rwVIDEOMODEEXCLUSIVE) {
rect->x = rect->y = 0;
Expand Down
29 changes: 24 additions & 5 deletions source/app/app_game.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "StdInc.h"
#include "app_game.h"

#include <tracy/Tracy.hpp>

#include "app_game.h"
#include "LoadingScreen.h"
#include "PlantMgr.h"
#include "Shadows.h"
Expand Down Expand Up @@ -38,11 +40,11 @@ void AppGameInjectHooks() {
RH_ScopedGlobalInstall(RenderEffects, 0x53E170);
RH_ScopedGlobalInstall(RenderScene, 0x53DF40);
RH_ScopedGlobalInstall(RenderMenus, 0x53E530);
RH_ScopedGlobalInstall(Render2dStuff, 0x53E230, {.locked = true});
RH_ScopedGlobalInstall(Render2dStuff, 0x53E230);
RH_ScopedGlobalInstall(RenderDebugShit, 0x53E160);

RH_ScopedGlobalInstall(Idle, 0x53E920);
RH_ScopedGlobalInstall(FrontendIdle, 0x53E770);
RH_ScopedGlobalInstall(FrontendIdle, 0x53E770, { .locked = true }); // Must be hooked at all times otherwise imgui stops working!
}

// 0x5BF3B0
Expand All @@ -53,6 +55,8 @@ void GameInit() {

// 0x53E580
void InitialiseGame() {
ZoneScoped;

static int16& version_number = *(int16*)(0xB72C68);
version_number = 78;

Expand Down Expand Up @@ -87,6 +91,8 @@ void RwTerminate() {

// 0x53E170
void RenderEffects() {
ZoneScoped;

CBirds::Render();
CSkidmarks::Render();
CRopes::Render();
Expand Down Expand Up @@ -120,6 +126,8 @@ void RenderEffects() {

// 0x53DF40
void RenderScene() {
ZoneScoped;

const auto underWater = CWeather::UnderWaterness <= 0.0f;

RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RWRSTATE(NULL));
Expand Down Expand Up @@ -204,13 +212,17 @@ void RenderScene() {

// 0x53E530
void RenderMenus() {
ZoneScoped;

if (FrontEndMenuManager.m_bMenuActive) {
FrontEndMenuManager.DrawFrontEnd();
}
}

// 0x53E230
void Render2dStuff() {
ZoneScoped;

RenderDebugShit(); // NOTSA, temp

const auto DrawOuterZoomBox = []() {
Expand Down Expand Up @@ -277,6 +289,8 @@ void RenderDebugShit() {

// 0x53E920
void Idle(void* param) {
ZoneScoped;

/* FPS lock. Limits to 26 frames per second.
CTimer::GetCurrentTimeInCycles();
CTimer::GetCyclesPerMillisecond();
Expand Down Expand Up @@ -310,8 +324,10 @@ void Idle(void* param) {
}

if (!FrontEndMenuManager.m_bMenuActive && TheCamera.GetScreenFadeStatus() != eNameState::NAME_FADE_IN) {
CVector2D mousePos{SCREEN_WIDTH / 2.0f, SCREEN_HEIGHT / 2.0f};
RsMouseSetPos(&mousePos);
if (!notsa::ui::UIRenderer::GetSingleton().GetImIO()->NavActive) { // If imgui nav is active don't center the cursor
FrontEndMenuManager.CentreMousePointer();
}

CRenderer::ConstructRenderList();
CRenderer::PreRender();
CWorld::ProcessPedsAfterPreRender();
Expand Down Expand Up @@ -348,6 +364,7 @@ void Idle(void* param) {
}

RenderMenus();
notsa::ui::UIRenderer::GetSingleton().DrawLoop(); // NOTSA: ImGui menu draw loop
RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RWRSTATE(NULL));
DoFade();
CHud::DrawAfterFade();
Expand All @@ -366,6 +383,8 @@ void Idle(void* param) {

// 0x53E770
void FrontendIdle() {
ZoneScoped;

CDraw::CalculateAspectRatio();
CTimer::Update();
CSprite2d::SetRecipNearClip();
Expand Down
Loading

0 comments on commit b90f927

Please sign in to comment.