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

gcc/Linux fixes #71

Merged
merged 11 commits into from
Feb 17, 2021
Merged

gcc/Linux fixes #71

merged 11 commits into from
Feb 17, 2021

Conversation

z33ky
Copy link

@z33ky z33ky commented Jan 30, 2021

Hi,

I got this thing to compile and run on Linux. Mostly it's just fixing file paths, since in Linux that's usually case-sensitive.
There were a couple of compiler errors, mostly easy to fix, and I squashed a few warnings as well.

z33ky added 6 commits January 27, 2021 23:07
This crashes on Linux as pKeyValuesData is NULL when deleteThis() is
invoked. This likely is caused by another issue, but fixing this here
seems good regardless.
This is important for case-sensitive filesystems/operating systems (i.e.
Linux).
Print them using "%s" instead, so their contents are not accidentally
interpreted as format specifiers.
Copy link
Author

@z33ky z33ky left a comment

Choose a reason for hiding this comment

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

Left a couple of notes about changes that may look funny.
Feel free to ask if there are further changes that look questionable or something is still unclear.

@hogsy
Copy link

hogsy commented Jan 30, 2021

Thanks, I did a quick glance through the changes and everything looks pretty reasonable. I appreciate you took the time to clean up some other bits in there too from the looks of it.

I'll try to test this as soon as I can and will look to get it merged soon 👍

@@ -23,13 +23,13 @@ namespace vgui
}

#define DECLARE_HINTITEMFACTORY( className ) \
CHintItemBase *Create_##className##( vgui::Panel *parent, const char *panelName ) \
Copy link
Author

Choose a reason for hiding this comment

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

A note to the changes here: The ## operator is for creating a singular token. In this instance, for example, pasting Create_ with className with ( will never create a valid singular token. Here two tokens are to be created: Create_##className (.
gcc is more strict than MSVC here in that it rejects the operation if pasting fails.

@@ -472,7 +472,8 @@ void CBaseTFFourWheelVehicle::PlayerControlInit( CBasePlayer *pPlayer )
pPlayer->SetViewOffset( vec3_origin );

m_playerOn.FireOutput( pPlayer, this, 0 );
InputTurnOn( inputdata_t() );
inputdata_t inputdata;
Copy link
Author

Choose a reason for hiding this comment

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

Passing a temporary via reference is only allowed for const&. gcc disallows doing that if the reference is not specified as const.
In most cases I simply changed the function parameters to include const, however since InputTurn{On,Off}() is used in multiple places I was a bit lazy to check if that's a reasonable change and opted to put the temporary in a variable instead.

@@ -1611,6 +1618,7 @@ void CBreakableProp::Break( CBaseEntity *pBreaker, const CTakeDamageInfo &info )
{
bSmashed = true;
}
#ifndef TF_DLL
else if ( pBreaker && dynamic_cast< CPropVehicleDriveable * >( pBreaker ) )
Copy link
Author

Choose a reason for hiding this comment

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

CPropVehicleDriveable is not defined for this project, hence there is no type-info available to do the dynamic_cast with. I don't know what MSVC compiles this to, with gcc this results in a linker error due to missing symbol.
My best guess to implement this using CBaseTFVehicle is just below.

@@ -40,7 +40,13 @@
#include "doors.h"
#include "physics_collisionevent.h"
#include "gamestats.h"
#define TF_DLL //FIXME
Copy link
Author

Choose a reason for hiding this comment

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

There is no macro specific to this project. I assume that other code has been changed with the assumption, that no other variant(/game) is compiled from this fork.
To cleanly separate mod-specific changes it may be a good idea to add such a macro though. TF_DLL is already taken, MOD_INVASION perhaps?
If you don't think this approach I can just #if 0 [old code] #else [new code] #endif, or flat out remove the irrelevant code.

Copy link

Choose a reason for hiding this comment

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

Personally I've not been concerned about seperating the mod-specific changes as I'm not expecting Valve to ever update the SDK at this stage - I'd prefer just to remove the irrelevant code.

Copy link
Author

Choose a reason for hiding this comment

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

It may be interesting to merge other forks, like Mapbase (if it gets an MP port, mapbase-source#77).

@@ -374,8 +374,9 @@ class TableVector
class ALIGN16 VectorAligned : public Vector
{
public:
inline VectorAligned(void) {};
inline VectorAligned(void):w(0) {};
Copy link
Author

Choose a reason for hiding this comment

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

Leaving w uninitialized is problematic when the VectorAligned is copied, since uninitialized data would be read, which means undefined behavior occurs.
Perhaps w could just be removed, it seems totally unused. Maybe it's required for ALIGN16 to work right? It seemed safest to just initialize it with some dummy value.

@@ -109,6 +109,95 @@ template<class T> class CStridedConstPtr
}
};

class CFltx4StridedPtr
Copy link
Author

Choose a reason for hiding this comment

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

The manual instantiation is unfortunate, but according to a gcc warning the __vector-specifier would get lost in the templated-code, meaning that (slow) unaligned access to the floats was used. By manually expanding CStridedPtr the compiler can emit the proper vectorized access instructions.
I don't know if MSVC actually just does carry over the specifiers or like the old gcc silently throws it away.

@z33ky z33ky force-pushed the Invasion/gcc-linux branch from 6cf5449 to eddfeaa Compare January 30, 2021 17:20
@z33ky
Copy link
Author

z33ky commented Jan 30, 2021

I have a minor issue with font loading. For some reason the engine is unable to find the fonts ("Couldn't find custom font file") if they're three directories deep (e.g. "resource/fonts/Squada_One/").
It does work if I just copy the fonts in e.g. "resource/fonts". Would that be an acceptable change?

The class-selection menu is bugged for me; clicking the buttons does not work. Pressing "enter" will close it, without selecting a class. Afterwards I managed to change classes using the "changeclass" console command. I'm wondering, is this also broken on Windows? I'll probably take a look at what's going on there.

@hogsy
Copy link

hogsy commented Jan 30, 2021

I have a minor issue with font loading. For some reason the engine is unable to find the fonts ("Couldn't find custom font file") if they're three directories deep (e.g. "resource/fonts/Squada_One/").
It does work if I just copy the fonts in e.g. "resource/fonts". Would that be an acceptable change?

If you do, can you rename the OFL in the same directory to use the same name as the font? Basically squadaone-regular.txt rather than OFL.txt - just to keep it clear what license that particular font is under.

The class-selection menu is bugged for me; clicking the buttons does not work. Pressing "enter" will close it, without selecting a class. Afterwards I managed to change classes using the "changeclass" console command. I'm wondering, is this also broken on Windows? I'll probably take a look at what's going on there.

Both the team selection and class menus should work, so I'm not sure what's going on there.

@z33ky
Copy link
Author

z33ky commented Jan 31, 2021

If you do, can you rename the OFL in the same directory to use the same name as the font? Basically squadaone-regular.txt rather than OFL.txt - just to keep it clear what license that particular font is under.

Yeah sure.

Both the team selection and class menus should work, so I'm not sure what's going on there.

I figured out it's some undefined behavior in the VGUI code - also present in the upstream Source SDK. That bug just became apparent by using a newer compiler, probably some optimization which killed the intent.
I'm writing up a fix.

z33ky added 5 commits January 31, 2021 15:55
We don't use CPropVehicleDriveable. Instead we've got CBaseTFVehicle, so
check for that.
The HL2(MP) assets weren't being loaded correctly on Linux. I copied the
settings from the original Source SDK 2013 file, which fixed it.
This works around an engine bug that seems to exist for Linux, where
fonts are not found if three directories deep:
	Couldn't find custom font file 'resource/fonts/Squada_One/SquadaOne-Regular.ttf'
The button mask is created by shifting a bit according to the
MouseCode, which is just a renamed ButtonCode_t.
Mouse buttons start at 107, which is way out of range for our ints.

To fix this, introduce MouseButtonBit(), which checks if a button code
corresponds to a mouse button at all and returns a usable bitmask
for the corresponding mouse button code.
This is then used for the button mask.
@z33ky z33ky force-pushed the Invasion/gcc-linux branch from eddfeaa to c860df4 Compare January 31, 2021 14:56
@@ -695,12 +695,12 @@ void Button::SetMouseClickEnabled(MouseCode code,bool state)
if(state)
{
//set bit to 1
_mouseClickMask|=1<<((int)(code+1));
Copy link
Author

Choose a reason for hiding this comment

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

I don't know why they did that +1 here. In MouseButtonBit() I use bit #0, which they may have wanted to avoid for some reason.

Copy link

Choose a reason for hiding this comment

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

Who knows, VGUI is a horrible poorly documented mess. If that resolves it I'm happy but should probably double check for regressions elsewhere before merge.

@hogsy hogsy merged commit c860df4 into TalonBraveInfo:master Feb 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants