-
Notifications
You must be signed in to change notification settings - Fork 147
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
gcc/Linux update #95
Conversation
@@ -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## ); |
There was a problem hiding this comment.
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.
#ifdef MAPBASE_VSCRIPT | ||
template <typename T> T *HScriptToClass( HSCRIPT hObj ) | ||
{ | ||
return (hObj) ? (T*)g_pScriptVM->GetInstanceValue( hObj, GetScriptDesc( (T*)NULL ) ) : NULL; |
There was a problem hiding this comment.
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.
@@ -645,8 +631,21 @@ struct ScriptEnumDesc_t | |||
// | |||
//----------------------------------------------------------------------------- | |||
|
|||
// forwards T (and T&) if T is neither enum or an unsigned integer |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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&&
.
@@ -827,7 +829,7 @@ void PushVariant(HSQUIRRELVM vm, const ScriptVariant_t& value) | |||
sq_createinstance(vm, -1); | |||
SQUserPointer p; | |||
sq_getinstanceup(vm, -1, &p, 0); | |||
new(p) Vector(value); | |||
new(p) Vector(static_cast<const Vector&>(value)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this one interesting.
Vector()
has an overload for vec_t
(i.e. float
) and ScriptVariant_t
can be cast to both Vector&
and float
. gcc regards this as an unresolvable ambiguity. I guess MSVC doesn't, and I'm guessing a cast to Vector&
is what's desired here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya, this cast is desirable, unfortunately MSVC doesn't conform with the standard for these conversions and allows implicit conversions here. (Compiling with conforming options on MSVC will normally pick these 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() ) ); |
There was a problem hiding this comment.
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.
sp/src/vscript/vscript_squirrel.cpp
Outdated
SQUserPointer TYPETAG_VECTOR = "VectorTypeTag"; | ||
// we cast away constness here, but this looks to be an API deficit of squrrel, | ||
// since the typetag shouldn't be modified | ||
static SQUserPointer TYPETAG_VECTOR = const_cast<char*>("VectorTypeTag"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of doing this should be able to just make it a char array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that works.
I didn't know that it's fine to initialize a char*
from a string literal (while apparently for void*
it isn't).
$(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 ;\ | ||
$(MAKEFILE_LINK): $(shell which $(CXX)) $(THISFILE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dependency on CXX
seems a bit unusual here, it should probably depend on the gcc9+support.cpp
file here also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thought behind this is that this check will be rerun when the system(/compiler) is updated. So if previously it was on gcc 7 it will then switch to the gcc8+ Makefile. I can add a comment for that.
It should also depend on the gcc9+support.cpp
file, yeah.
@z33ky Would you say that this PR is ready to merge? There were a few big changes committed to |
I rebased locally and there are no conflicts or new warnings, so yeah, all good :) |
The code in this PR currently cannot be compiled with Visual Studio 2013 on Windows due to the compiler not supporting keywords like Visual Studio 2013 is the default compiler for Source SDK 2013 and Mapbase does not currently change that. I am aware that upgrading the SDK to a newer tool-set is possible, but I'm relatively hesitant to subject users to a new requirement, especially right now when we're about to release an update. Could the involved code perhaps be |
There are only two occurrences of |
bump |
I'm terribly sorry for how long it's taken me to get to this. I went through a major natural disaster in the middle of February and it took me some time to get my life back in order. Aside from what I reported, these two
However, be warned that #105 will cause a few merge conflicts with these changes and it may be merged with |
No worries, take it easy then.
Ah, that's just an incorrect include ordering I think. The two files I added must be included before memdbgon.h, not after. For the error you mentioned previously, did you try if it works if you remove the
I think I can get that done on the weekend. |
I've included these changes in an attempt to fix MSVC compilation while rebasing my changes onto the latest develop. |
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.
I tested the VScript implementation using this rather trivial script:
I invoked it via
The Z value looks suspicious. Any idea? At least it doesn't crash anymore :P If you have a better (more complex) testcase I can try let me know and I'll test. Btw the links on https://github.com/mapbase-source/source-sdk-2013/wiki/VScript-in-Mapbase#tutorials are broken due to erroneous semicolons. |
|
I finally got around to testing this and it seems to compile and function as intended. Assuming you have no objections, I will merge this later today |
Cool :) Yeah, it's ready from my side. |
gcc/Linux update
Fixes to build for Linux.
Does this PR close any issues?
No.
PR Checklist
develop
branch OR targets another branch with a specific goal in mind