Skip to content

Commit

Permalink
Fix mouse trapped inside a rectangle (#2)
Browse files Browse the repository at this point in the history
* Make project compile on Linux

- Updated CMake files to support build on Linux
- Deleted original Linux makefiles as they are not needed since CMake is introduced
- Fixed minor problems in the code which prevented the project from compiling

It likely breaks the Windows build, but hopefully it only causes minor problems
those are easy to fix in a way that allows the project to compile on both platforms.

The Linux CMake files don't try to deploy the built libraries to the game mod
directory (people likely build in a separate environment, not where they have the
game installed).

* Explicitly link SDL2 to client library

- Added SDL2 to the list of linked libraries to client.so
Not sure if it helps anything, the library loaded without it successfully,
but it doesn't hurt either.

- Fixed symlinks to Linux and MacOS builds of SDL2
They were supposed to be symlinks and they are in Valve's repo, but in
Solokiller's fork they lost their symlink flag with this commit:
twhl-community/halflife-updated@6509102

* Port fix for getting mouse stuck in box

Apparently, the problem is caused by this issue:
ValveSoftware/halflife#1377

Which Solokiller has a fix for:
twhl-community/halflife-updated@92ffa23

But seems to be originated from L453rh4wk:
ValveSoftware/halflife#1546 (comment)

Co-authored-by: MegaBrutal <megabrutal@devcentre>
  • Loading branch information
MegaBrutal and MegaBrutal authored Mar 12, 2022
1 parent 8059652 commit 445e326
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cl_dll/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,13 @@ if(UNIX)
dl
pthread
stdc++
SDL2
:vgui.so
)

set_target_properties(${CLIENT_DLL_NAME} PROPERTIES
PREFIX ""
COMPILE_FLAGS "-m32" LINK_FLAGS "-m32 -L ../../linux/release"
COMPILE_FLAGS "-m32" LINK_FLAGS "-m32 -L ../../linux/release -L ../../linux"
)

elseif(MSVC)
Expand Down
38 changes: 38 additions & 0 deletions cl_dll/inputw32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ DWORD s_hMouseThreadId = 0;
HANDLE s_hMouseThread = 0;
HANDLE s_hMouseQuitEvent = 0;
HANDLE s_hMouseDoneQuitEvent = 0;
SDL_bool mouseRelative = SDL_TRUE;
#endif

/*
Expand Down Expand Up @@ -235,6 +236,21 @@ void DLLEXPORT IN_ActivateMouse (void)
#endif
mouseactive = 1;
}

#ifdef _WIN32
if (!m_bRawInput)
{
SDL_SetRelativeMouseMode(SDL_FALSE);
mouseRelative = SDL_FALSE;
}
else
{
mouseRelative = SDL_TRUE;
SDL_SetRelativeMouseMode(SDL_TRUE);
}
#else
SDL_SetRelativeMouseMode(SDL_TRUE);
#endif
}


Expand All @@ -255,6 +271,15 @@ void DLLEXPORT IN_DeactivateMouse (void)

mouseactive = 0;
}

#ifdef _WIN32
if (m_bRawInput)
{
mouseRelative = SDL_FALSE;
}

#endif
SDL_SetRelativeMouseMode(SDL_FALSE);
}

/*
Expand Down Expand Up @@ -572,6 +597,19 @@ void IN_MouseMove ( float frametime, usercmd_t *cmd)

gEngfuncs.SetViewAngles( (float *)viewangles );

#ifdef _WIN32
if (!m_bRawInput && mouseRelative)
{
SDL_SetRelativeMouseMode(SDL_FALSE);
mouseRelative = SDL_FALSE;
}
else if (m_bRawInput && !mouseRelative)
{
SDL_SetRelativeMouseMode(SDL_TRUE);
mouseRelative = SDL_TRUE;
}
#endif

/*
//#define TRACE_TEST
#if defined( TRACE_TEST )
Expand Down
1 change: 0 additions & 1 deletion linux/libSDL2.dylib

This file was deleted.

1 change: 1 addition & 0 deletions linux/libSDL2.dylib
1 change: 0 additions & 1 deletion linux/libSDL2.so

This file was deleted.

1 change: 1 addition & 0 deletions linux/libSDL2.so

0 comments on commit 445e326

Please sign in to comment.