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 update #95

Merged
merged 6 commits into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions sp/src/devtools/makefile_base_posix.mak
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ MAKEFILE_LINK:=$(THISFILE).link

-include $(MAKEFILE_LINK)

$(MAKEFILE_LINK): $(shell which $(CC)) $(THISFILE)
if [ "$(shell printf "$(shell $(CC) -dumpversion)\n8" | sort -Vr | head -1)" = 8 ]; then \
$(COMPILE.cpp) -o gcc9+support.o gcc9+support.c ;\
# depend on CXX so the correct makefile can be selected when the system is updated
$(MAKEFILE_LINK): $(shell which $(CXX)) $(THISFILE) $(SRCROOT)/devtools/gcc9+support.cpp
@ if [ "$(shell printf "$(shell $(CXX) -dumpversion)\n8" | sort -Vr | head -1)" = 8 ]; then \
ln -sf $(MAKEFILE_BASE).default $@ ;\
else \
$(COMPILE.cpp) -o $(SRCROOT)/devtools/gcc9+support.o $(SRCROOT)/devtools/gcc9+support.cpp &&\
ln -sf $(MAKEFILE_BASE).gcc8 $@ ;\
fi
2 changes: 1 addition & 1 deletion sp/src/game/client/c_baseentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ class C_BaseEntity : public IClientEntity

#ifdef MAPBASE_VSCRIPT
// "I don't know why but wrapping entindex() works, while calling it directly crashes."
inline int C_BaseEntity::GetEntityIndex() const { return entindex(); }
inline int GetEntityIndex() const { return entindex(); }
#endif

// This works for client-only entities and returns the GetEntryIndex() of the entity's handle,
Expand Down
37 changes: 19 additions & 18 deletions sp/src/game/client/c_baselesson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "ammodef.h"
#include "vprof.h"
#include "view.h"
#include "vstdlib/ikeyvaluessystem.h"
#include "vstdlib/IKeyValuesSystem.h"
#ifdef MAPBASE
#include "usermessages.h"
#endif
Expand Down Expand Up @@ -666,7 +666,8 @@ void CIconLesson::UpdateInactive()
CUtlBuffer msg_data;
msg_data.PutChar( 1 );
msg_data.PutString( m_szHudHint.String() );
usermessages->DispatchUserMessage( usermessages->LookupUserMessage( "KeyHintText" ), bf_read( msg_data.Base(), msg_data.TellPut() ) );
Copy link
Author

Choose a reason for hiding this comment

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

The issue here is that DispatchUserMessage() expects a (non-const) bf_read&. rvalues (unnamed temporaries) are normally not allowed to be used as non-const references (const would be fine). MSVC seems to allow it anyways. By using an explicit variable, it is no longer an rvalue and thus can be passed as non-const reference.

While looking into this I read the implementation of DispatchUserMessage(). For every hook it copies the bf_read, which seems unnecessary to me, considering there's a Reset() function on it. So if you wanted to you can probably optimize it to avoid making the copies and instead reset it before invoking each hook.

bf_read msg( msg_data.Base(), msg_data.TellPut() );
usermessages->DispatchUserMessage( usermessages->LookupUserMessage( "KeyHintText" ), msg );
}
#endif

Expand Down Expand Up @@ -1039,40 +1040,40 @@ Vector CIconLesson::GetIconTargetPosition( C_BaseEntity *pIconTarget )

#define LESSON_VARIABLE_INIT_SYMBOL( _varEnum, _varName, _varType ) g_n##_varEnum##Symbol = KeyValuesSystem()->GetSymbolForString( #_varEnum );

#define LESSON_SCRIPT_STRING_ADD_TO_MAP( _varEnum, _varName, _varType ) g_NameToTypeMap.Insert( #_varEnum, LESSON_VARIABLE_##_varEnum## );
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 LESSON_VARIABLE_ with _varEnum with ); will never create a valid singular token. Here three tokens are to be created: LESSON_VARIABLE_##_varEnum ) ;.
gcc is more strict than MSVC here in that it rejects the operation if pasting fails.

#define LESSON_SCRIPT_STRING_ADD_TO_MAP( _varEnum, _varName, _varType ) g_NameToTypeMap.Insert( #_varEnum, LESSON_VARIABLE_##_varEnum );

// Create enum value
#define LESSON_VARIABLE_ENUM( _varEnum, _varName, _varType ) LESSON_VARIABLE_##_varEnum##,
#define LESSON_VARIABLE_ENUM( _varEnum, _varName, _varType ) LESSON_VARIABLE_##_varEnum,

// Init info call
#define LESSON_VARIABLE_INIT_INFO_CALL( _varEnum, _varName, _varType ) g_pLessonVariableInfo[ LESSON_VARIABLE_##_varEnum## ].Init_##_varEnum##();
#define LESSON_VARIABLE_INIT_INFO_CALL( _varEnum, _varName, _varType ) g_pLessonVariableInfo[ LESSON_VARIABLE_##_varEnum ].Init_##_varEnum();

// Init info
#define LESSON_VARIABLE_INIT_INFO( _varEnum, _varName, _varType ) \
void Init_##_varEnum##() \
void Init_##_varEnum() \
{ \
iOffset = offsetof( CScriptedIconLesson, CScriptedIconLesson::##_varName## ); \
iOffset = offsetof( CScriptedIconLesson, CScriptedIconLesson::_varName ); \
varType = LessonParamTypeFromString( #_varType ); \
}

#define LESSON_VARIABLE_INIT_INFO_BOOL( _varEnum, _varName, _varType ) \
void Init_##_varEnum##() \
void Init_##_varEnum() \
{ \
iOffset = offsetof( CScriptedIconLesson, CScriptedIconLesson::##_varName## ); \
iOffset = offsetof( CScriptedIconLesson, CScriptedIconLesson::_varName ); \
varType = FIELD_BOOLEAN; \
}

#define LESSON_VARIABLE_INIT_INFO_EHANDLE( _varEnum, _varName, _varType ) \
void Init_##_varEnum##() \
void Init_##_varEnum() \
{ \
iOffset = offsetof( CScriptedIconLesson, CScriptedIconLesson::##_varName## ); \
iOffset = offsetof( CScriptedIconLesson, CScriptedIconLesson::_varName ); \
varType = FIELD_EHANDLE; \
}

#define LESSON_VARIABLE_INIT_INFO_STRING( _varEnum, _varName, _varType ) \
void Init_##_varEnum##() \
void Init_##_varEnum() \
{ \
iOffset = offsetof( CScriptedIconLesson, CScriptedIconLesson::##_varName## ); \
iOffset = offsetof( CScriptedIconLesson, CScriptedIconLesson::_varName ); \
varType = FIELD_STRING; \
}

Expand All @@ -1094,15 +1095,15 @@ Vector CIconLesson::GetIconTargetPosition( C_BaseEntity *pIconTarget )

// Process the element action on this variable
#define PROCESS_LESSON_ACTION( _varEnum, _varName, _varType ) \
case LESSON_VARIABLE_##_varEnum##:\
case LESSON_VARIABLE_##_varEnum:\
return ProcessElementAction( pLessonElement->iAction, pLessonElement->bNot, #_varName, _varName, &pLessonElement->szParam, eventParam_float );

#define PROCESS_LESSON_ACTION_EHANDLE( _varEnum, _varName, _varType ) \
case LESSON_VARIABLE_##_varEnum##:\
case LESSON_VARIABLE_##_varEnum:\
return ProcessElementAction( pLessonElement->iAction, pLessonElement->bNot, #_varName, _varName, &pLessonElement->szParam, eventParam_float, eventParam_BaseEntity, eventParam_string );

#define PROCESS_LESSON_ACTION_STRING( _varEnum, _varName, _varType ) \
case LESSON_VARIABLE_##_varEnum##:\
case LESSON_VARIABLE_##_varEnum:\
return ProcessElementAction( pLessonElement->iAction, pLessonElement->bNot, #_varName, &_varName, &pLessonElement->szParam, eventParam_string );

// Init the variable from the script (or a convar)
Expand Down Expand Up @@ -2957,7 +2958,7 @@ bool CScriptedIconLesson::ProcessElementAction( int iAction, bool bNot, const ch
{
if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
{
ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->HealthFraction() ", pchVarName, pchVarName );
ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->HealthFraction() ", pchVarName );
ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " );
ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( ">= [%s] " ) : ( "< [%s] " ), pchParamName->String() );
ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%f\n", fParam );
Expand All @@ -2969,7 +2970,7 @@ bool CScriptedIconLesson::ProcessElementAction( int iAction, bool bNot, const ch

if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
{
ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->HealthFraction() ", pchVarName, pchVarName );
ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->HealthFraction() ", pchVarName );
ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%f ", pVar->HealthFraction() );
ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( ">= [%s] " ) : ( "< [%s] " ), pchParamName->String() );
ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%f\n", fParam );
Expand Down
2 changes: 1 addition & 1 deletion sp/src/game/client/c_baselesson.h
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ class CScriptedIconLesson : public CIconLesson
LessonEvent_t * AddUpdateEvent( void );

private:
static CUtlDict< int, int > CScriptedIconLesson::LessonActionMap;
static CUtlDict< int, int > LessonActionMap;

EHANDLE m_hLocalPlayer;
float m_fOutput;
Expand Down
2 changes: 1 addition & 1 deletion sp/src/game/client/c_gameinstructor.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


#include "GameEventListener.h"
#include "vgui_controls/phandle.h"
#include "vgui_controls/PHandle.h"

class CBaseLesson;

Expand Down
2 changes: 1 addition & 1 deletion sp/src/game/client/hud_locator_target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "iclientmode.h"
#include <vgui/ILocalize.h>
#include <vgui/ISurface.h>
#include <vgui/IVGUI.h>
#include <vgui/IVGui.h>
#include <vgui_controls/EditablePanel.h>
#include <vgui_controls/Controls.h>
#include <vgui_controls/Label.h>
Expand Down
2 changes: 1 addition & 1 deletion sp/src/game/client/hud_locator_target.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#define LOCATOR_ICON_FX_FADE_OUT 0x00000800 // Set when deactivated so it can smoothly vanish
#define LOCATOR_ICON_FX_FADE_IN 0x00001000 // Set when activated so it can smoothly appear

#include "tier1/UtlSymbol.h"
#include "tier1/utlsymbol.h"

// See comments in UtlSymbol on why this is useful
DECLARE_PRIVATE_SYMBOLTYPE( CGameInstructorSymbol );
Expand Down
10 changes: 5 additions & 5 deletions sp/src/game/client/vgui_movie_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
#include "cbase.h"
#include "c_vguiscreen.h"
#include "vgui_controls/Label.h"
#include "vgui_BitmapPanel.h"
#include <vgui/IVGUI.h>
#include "vgui_bitmappanel.h"
#include <vgui/IVGui.h>
#include "c_slideshow_display.h"
#include "ienginevgui.h"
#include "fmtstr.h"
#include "vgui_controls/ImagePanel.h"
#include <vgui/ISurface.h>
#include "video/ivideoservices.h"
#include "engine/ienginesound.h"
#include "VGUIMatSurface/IMatSystemSurface.h"
#include "engine/IEngineSound.h"
#include "VGuiMatSurface/IMatSystemSurface.h"
#include "c_movie_display.h"

// NOTE: This has to be the last file included!
Expand Down Expand Up @@ -368,7 +368,7 @@ bool CMovieDisplayScreen::BeginPlayback( const char *pFilename )
Q_strncpy( szMaterialName, pFilename, sizeof(szMaterialName) );
}

const char *pszMaterialName = CFmtStrN<128>( "VideoMaterial_", m_hScreenEntity->GetEntityName() );
const char *pszMaterialName = CFmtStrN<128>( "VideoMaterial_%s", m_hScreenEntity->GetEntityName() );
m_VideoMaterial = g_pVideo->CreateVideoMaterial( pszMaterialName, pFilename, "GAME",
VideoPlaybackFlags::DEFAULT_MATERIAL_OPTIONS,
VideoSystem::DETERMINE_FROM_FILE_EXTENSION/*, m_bAllowAlternateMedia*/ );
Expand Down
2 changes: 1 addition & 1 deletion sp/src/game/server/hl2/hl2_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ class CHL2_Player : public CBasePlayer
virtual bool IsHoldingEntity( CBaseEntity *pEnt );
virtual void ForceDropOfCarriedPhysObjects( CBaseEntity *pOnlyIfHoldindThis );
virtual float GetHeldObjectMass( IPhysicsObject *pHeldObject );
virtual CBaseEntity *CHL2_Player::GetHeldObject( void );
virtual CBaseEntity *GetHeldObject( void );

virtual bool IsFollowingPhysics( void ) { return (m_afPhysicsFlags & PFLAG_ONBARNACLE) > 0; }
void InputForceDropPhysObjects( inputdata_t &data );
Expand Down
2 changes: 1 addition & 1 deletion sp/src/game/server/mapbase/logic_externaldata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void CLogicExternalData::InputWriteKeyValue( inputdata_t &inputdata )

// Separate key from value
char *delimiter = Q_strstr(szValue, " ");
if (delimiter && (delimiter + 1) != '\0')
if (delimiter && delimiter[1] != '\0')
{
Q_strncpy(key, szValue, MIN((delimiter - szValue) + 1, sizeof(key)));
Q_strncpy(value, delimiter + 1, sizeof(value));
Expand Down
3 changes: 2 additions & 1 deletion sp/src/game/shared/mapbase/vscript_consts_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,8 @@ void RegisterSharedScriptConstants()
//ScriptRegisterConstant( g_pScriptVM, AISS_AUTO_PVS_AFTER_PVS, "" );
ScriptRegisterConstant( g_pScriptVM, AI_SLEEP_FLAGS_NONE, "No sleep flags. (NPC sleep flag used in Add/Remove/HasSleepFlags())" );
ScriptRegisterConstant( g_pScriptVM, AI_SLEEP_FLAG_AUTO_PVS, "Indicates a NPC will sleep upon exiting PVS. (NPC sleep flag used in Add/Remove/HasSleepFlags())" );
ScriptRegisterConstant( g_pScriptVM, AI_SLEEP_FLAG_AUTO_PVS_AFTER_PVS, "Indicates a NPC will sleep upon exiting PVS after entering PVS for the first time(?????) (NPC sleep flag used in Add/Remove/HasSleepFlags())" );
// note: the one "?" is escaped to prevent evaluation of a trigraph
ScriptRegisterConstant( g_pScriptVM, AI_SLEEP_FLAG_AUTO_PVS_AFTER_PVS, "Indicates a NPC will sleep upon exiting PVS after entering PVS for the first time(????\?) (NPC sleep flag used in Add/Remove/HasSleepFlags())" );

ScriptRegisterConstantNamed( g_pScriptVM, CAI_BaseNPC::SCRIPT_PLAYING, "SCRIPT_PLAYING", "Playing the action animation." );
ScriptRegisterConstantNamed( g_pScriptVM, CAI_BaseNPC::SCRIPT_WAIT, "SCRIPT_WAIT", "Waiting on everyone in the script to be ready. Plays the pre idle animation if there is one." );
Expand Down
6 changes: 3 additions & 3 deletions sp/src/materialsystem/stdshaders/windowimposter_dx90.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include "BaseVSShader.h"
#include "cpp_shader_constant_register_map.h"

#include "sdk_windowimposter_vs20.inc"
#include "sdk_windowimposter_ps20.inc"
#include "sdk_windowimposter_ps20b.inc"
#include "SDK_windowimposter_vs20.inc"
#include "SDK_windowimposter_ps20.inc"
#include "SDK_windowimposter_ps20b.inc"



Expand Down
2 changes: 1 addition & 1 deletion sp/src/public/tier1/convar.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "tier1/utlvector.h"
#include "tier1/utlstring.h"
#include "icvar.h"
#include "color.h"
#include "Color.h"

#ifdef _WIN32
#define FORCEINLINE_CVAR FORCEINLINE
Expand Down
9 changes: 9 additions & 0 deletions sp/src/public/vgui/MouseCode.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
namespace vgui
{
typedef ButtonCode_t MouseCode;

static inline int MouseButtonBit(MouseCode code)
{
if (code < MOUSE_FIRST || code > MOUSE_LAST) {
Assert(false);
return 0;
}
return 1 << (code - MOUSE_FIRST);
}
}

#endif // MOUSECODE_H
46 changes: 31 additions & 15 deletions sp/src/public/vscript/ivscript.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@
#ifndef IVSCRIPT_H
#define IVSCRIPT_H

#include <type_traits>
#include <utility>

#include "platform.h"
#include "datamap.h"
#include "appframework/IAppSystem.h"
Expand Down Expand Up @@ -163,20 +166,6 @@ class IScriptManager : public IAppSystem
//
//-----------------------------------------------------------------------------

#ifdef MAPBASE_VSCRIPT
template <typename T> T *HScriptToClass( HSCRIPT hObj )
{
return (hObj) ? (T*)g_pScriptVM->GetInstanceValue( hObj, GetScriptDesc( (T*)NULL ) ) : NULL;
Copy link
Author

Choose a reason for hiding this comment

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

IScriptVM is not yet defined here. MSVC probably accepts this as long as the template is not expanded yet.
Moving it below the definition of IScriptVM seemed to cause no harm and fixes the gcc build.

}
#else
DECLARE_POINTER_HANDLE( HSCRIPT );
#define INVALID_HSCRIPT ((HSCRIPT)-1)
#endif

//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------

enum ExtendedFieldType
{
FIELD_TYPEUNKNOWN = FIELD_TYPECOUNT,
Expand Down Expand Up @@ -645,8 +634,21 @@ struct ScriptEnumDesc_t
//
//-----------------------------------------------------------------------------

// forwards T (and T&) if T is neither enum or an unsigned integer
Copy link
Author

Choose a reason for hiding this comment

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

gcc complained that it can't discern how to create a ScriptVariant_t from enums and unsigned integers.
This awkward template ensures it can deal with it properly via an implicit cast to int due to the overload below.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You'll still need std::forward<T> on this if your expecting to forward it.

Copy link
Author

Choose a reason for hiding this comment

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

Indeed, and fix the return-type from T to T&&.

// the overload for int below captures enums and unsigned integers and "bends" them to int
template<typename T>
static inline typename std::enable_if<!std::is_enum<typename std::remove_reference<T>::type>::value && !std::is_unsigned<typename std::remove_reference<T>::type>::value, T&&>::type ToConstantVariant(T &&value)
{
return std::forward<T>(value);
}

static inline int ToConstantVariant(int value)
{
return value;
}

#define ScriptRegisterConstant( pVM, constant, description ) ScriptRegisterConstantNamed( pVM, constant, #constant, description )
#define ScriptRegisterConstantNamed( pVM, constant, scriptName, description ) do { static ScriptConstantBinding_t binding; binding.m_pszScriptName = scriptName; binding.m_pszDescription = description; binding.m_data = constant; pVM->RegisterConstant( &binding ); } while (0)
#define ScriptRegisterConstantNamed( pVM, constant, scriptName, description ) do { static ScriptConstantBinding_t binding; binding.m_pszScriptName = scriptName; binding.m_pszDescription = description; binding.m_data = ToConstantVariant(constant); pVM->RegisterConstant( &binding ); } while (0)

// Could probably use a better name.
// This is used for registering variants (particularly vectors) not tied to existing variables.
Expand Down Expand Up @@ -1090,6 +1092,20 @@ class IScriptVM
#endif
};

//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------

#ifdef MAPBASE_VSCRIPT
template <typename T> T *HScriptToClass( HSCRIPT hObj )
{
extern IScriptVM *g_pScriptVM;
return (hObj) ? (T*)g_pScriptVM->GetInstanceValue( hObj, GetScriptDesc( (T*)NULL ) ) : NULL;
}
#else
DECLARE_POINTER_HANDLE( HSCRIPT );
#define INVALID_HSCRIPT ((HSCRIPT)-1)
#endif

//-----------------------------------------------------------------------------
// Script scope helper class
Expand Down
Loading