Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

this is a set of modifications to modernize parts of the code #1515

Closed
wants to merge 17 commits into from

Conversation

jfmherokiller
Copy link
Contributor

@jfmherokiller jfmherokiller commented Oct 23, 2023

feel free to poke around here. this draft is more an experiment then an actual draft atm.

@jfmherokiller
Copy link
Contributor Author

using static constexpr seems to incrase compile time but atleast under my tests also provides some marginal speedups

@jfmherokiller jfmherokiller marked this pull request as ready for review October 25, 2023 03:58
return {p0.fY * p1.fZ - p0.fZ * p1.fY,
p0.fZ * p1.fX - p0.fX * p1.fZ,
p0.fX * p1.fY - p0.fY * p1.fX
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably remain an hsVector3 for type safety and clarity. I don't think there's any performance impact here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair enough i just found it as duplicating the type since the function already returns it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always better to use the defined constructor for an object instead of pushing in memory directly. Even if it's a bit duplicative with the type name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dgelessus - I see your emoji. I'm poking at this and I see C++ is policing the number of elements in the struct. However - this struct does have a defined constructor and it does seem weird to go around it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I wanted to explain later and forgot, sorry. As I understand it, the brace syntax in this case will use the constructor defined in the class, despite the brace syntax. According to cppreference, the C-style field by field initialization is called aggregate initialization, which never applies to classes with user-defined constructors. Instead, the brace syntax does list initialization here, which in this case calls the normal constructor, exactly like the previous code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dgelessus Thanks! I'll review the docs.

| D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE3(0);

static D3DMATRIX d3dIdentityMatrix{ 1.0f, 0.0f, 0.0f, 0.0f,
static constexpr D3DMATRIX d3dIdentityMatrix{ 1.0f, 0.0f, 0.0f, 0.0f,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if the identity matrix should be constexpr. Something being both static and constexpr may already be a bit of a paradox. But the identity matrix is loaded as a buffer from a pointer, which means it can't actually be constexpr easily by a compiler. And it might be more optimal just to have one copy of the buffer in memory anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static constexpr is perfectly valid. Sometimes you have things that can be used at both compile-time and runtime. In this case, we aren't doing any compile-time matrix math, so it probably makes more sense to just leave this one alone. I doubt that the generated machine code is any different since we're just going to be pushing a pointer onto the stack.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i can revert this if desired

@Hoikas
Copy link
Member

Hoikas commented Oct 26, 2023

You may revert or remove 843c93b

@jfmherokiller
Copy link
Contributor Author

jfmherokiller commented Oct 31, 2023

dropped the commit

Copy link
Member

@Hoikas Hoikas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR covers an odd set of topics. I think we would prefer to see changesets grouped by topic where possible.

Sources/Plasma/Apps/plPythonPack/main.cpp Outdated Show resolved Hide resolved
Sources/Plasma/Apps/plPythonPack/main.cpp Outdated Show resolved Hide resolved
Sources/Plasma/PubUtilLib/plMath/plTriUtils.cpp Outdated Show resolved Hide resolved
@@ -55,7 +55,7 @@ You can contact Cyan Worlds, Inc. by email [email protected]
#if HS_BUILD_FOR_WIN32
# include "hsWindows.h"
# include <io.h>
# define isatty _isatty
# define ttycheck(fileinfo) (GetFileType(fileinfo) == FILE_TYPE_CHAR)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We prefer to use standards compliant mechanisms. AFAIK, isatty is part of the POSIX standard. The Windows SDK just emits an erroneous deprecation warning with isatty and wants _isatty (which is just the Microsoft way of making life more difficult for cross-platform development). Is there a particular bug that is fixed by using (GetFileType(fileinfo) == FILE_TYPE_CHAR) instead of _isatty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it does if the user attempts compile and run the game using msys2 or cygwin the value of _isatty can be invalid.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, you should probably fix the preprocessor checks to detect that situation to use isatty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldnt HS_BUILD_FOR_WIN32 handle that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HS_BUILD_FOR_WIN32 will be defined for MSVC, clang-cl, and mingw

In this case, you'll need an extra check for mingw to avoid aliasing isatty

Copy link
Member

@Hoikas Hoikas Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still seems to be using non-standards complaint naming, unfortunately. We prefer the POSIX standard isatty.

@Hoikas
Copy link
Member

Hoikas commented Nov 10, 2023

Due to the changes to pfDXPipeline, this will be deferred until after #1326 is merged.

@jfmherokiller
Copy link
Contributor Author

fine by me I just hope the mac port lands successfully

@Hoikas Hoikas closed this Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants