Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/etternagame/etterna into…
Browse files Browse the repository at this point in the history
… develop
  • Loading branch information
TheROPFather committed Jun 24, 2018
2 parents 9baf024 + 72f2c74 commit d60f79e
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 43 deletions.
2 changes: 1 addition & 1 deletion extern/json
Submodule json updated from fdecbf to f7a446
2 changes: 2 additions & 0 deletions src/GameState.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ class GameState
bool m_bDemonstrationOrJukebox;
bool m_bJukeboxUsesModifiers;
int m_iNumStagesOfThisSong;
//Used by GameplayScreen to know if it needs to call NSMAN
bool m_bInNetGameplay = false;
/**
* @brief Increase this every stage while not resetting on a continue.
*
Expand Down
19 changes: 19 additions & 0 deletions src/InputFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,21 @@ void InputFilter::UpdateMouseWheel(float _fZ)
m_MouseCoords.fZ = _fZ;
}

bool InputFilter::IsKBKeyPressed(DeviceButton k) const
{
return INPUTFILTER->IsBeingPressed(DeviceInput(DEVICE_KEYBOARD, k));
}

bool InputFilter::IsControlPressed() const
{
return IsKBKeyPressed(KEY_LCTRL) || IsKBKeyPressed(KEY_RCTRL);
}

bool InputFilter::IsShiftPressed() const
{
return IsKBKeyPressed(KEY_LSHIFT) || IsKBKeyPressed(KEY_RSHIFT);
}

// lua start
#include "LuaBinding.h"

Expand Down Expand Up @@ -506,12 +521,16 @@ class LunaInputFilter: public Luna<InputFilter>
lua_pushboolean(L, INPUTFILTER->IsBeingPressed(DeviceInput(device, button)));
return 1;
}
DEFINE_METHOD(IsShiftPressed, IsShiftPressed());
DEFINE_METHOD(IsControlPressed, IsControlPressed());
LunaInputFilter()
{
ADD_METHOD(GetMouseX);
ADD_METHOD(GetMouseY);
ADD_METHOD(GetMouseWheel);
ADD_METHOD(IsBeingPressed);
ADD_METHOD(IsShiftPressed);
ADD_METHOD(IsControlPressed);
}
};

Expand Down
3 changes: 3 additions & 0 deletions src/InputFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class InputFilter

// If aButtonState is NULL, use the last reported state.
bool IsBeingPressed( const DeviceInput &di, const DeviceInputList *pButtonState = nullptr ) const;
bool IsKBKeyPressed(DeviceButton k) const;
bool IsControlPressed() const;
bool IsShiftPressed() const;
float GetSecsHeld( const DeviceInput &di, const DeviceInputList *pButtonState = nullptr ) const;
float GetLevel( const DeviceInput &di, const DeviceInputList *pButtonState = nullptr ) const;
RString GetButtonComment( const DeviceInput &di ) const;
Expand Down
7 changes: 4 additions & 3 deletions src/NetworkSyncManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ AutoScreenMessage(ETTP_NewScore);

extern Preference<RString> g_sLastServer;
Preference<unsigned int> autoConnectMultiplayer("AutoConnectMultiplayer", 1);
static LocalizedString CONNECTION_SUCCESSFUL( "NetworkSyncManager", "Connection to '%s' successful." );
static LocalizedString CONNECTION_FAILED ( "NetworkSyncManager", "Connection failed." );

SMOProtocol::SMOProtocol() {
NetPlayerClient = new EzSockets;
Expand Down Expand Up @@ -905,7 +907,8 @@ bool SMOProtocol::Connect(NetworkSyncManager * n, unsigned short port, RString a
n->isSMOnline = true;
serverName = m_packet.ReadNT();
m_iSalt = m_packet.Read4();
n->DisplayStartupStatus();
RString sMessage = ssprintf(CONNECTION_SUCCESSFUL.GetValue(), serverName.c_str());
SCREENMAN->SystemMessage(sMessage);
return true;
}

Expand Down Expand Up @@ -1486,8 +1489,6 @@ void SMOProtocol::StartRequest(NetworkSyncManager* n, short position)

}

static LocalizedString CONNECTION_SUCCESSFUL( "NetworkSyncManager", "Connection to '%s' successful." );
static LocalizedString CONNECTION_FAILED ( "NetworkSyncManager", "Connection failed." );
void NetworkSyncManager::DisplayStartupStatus()
{
RString sMessage("");
Expand Down
2 changes: 1 addition & 1 deletion src/ScreenGameplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ ScreenGameplay::ScreenGameplay()
{
m_pSongBackground = NULL;
m_pSongForeground = NULL;
m_bForceNoNetwork = false;
m_bForceNoNetwork = !GAMESTATE->m_bInNetGameplay;
m_delaying_ready_announce= false;
GAMESTATE->m_AdjustTokensBySongCostForFinalStageCheck= false;
#if !defined(WITHOUT_NETWORKING)
Expand Down
1 change: 1 addition & 0 deletions src/ScreenNetSelectMusic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ void ScreenNetSelectMusic::HandleScreenMessage( const ScreenMessage SM )
}
else if( SM == SM_GoToNextScreen )
{
GAMESTATE->m_bInNetGameplay = true;
SOUND->StopMusic();
SCREENMAN->SetNewScreen( THEME->GetMetric (m_sName, "NextScreen") );
}
Expand Down
2 changes: 1 addition & 1 deletion src/ScreenSelectMusic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ void ScreenSelectMusic::HandleScreenMessage(const ScreenMessage SM)
m_bAllowOptionsMenu = false;
if (OPTIONS_MENU_AVAILABLE && !m_bGoToOptions)
this->PlayCommand("HidePressStartForOptions");

GAMESTATE->m_bInNetGameplay = false;
this->PostScreenMessage(SM_GoToNextScreen, this->GetTweenTimeLeft());
}
else if (SM == SM_GoToNextScreen)
Expand Down
41 changes: 6 additions & 35 deletions src/ScreenTextEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "ScreenPrompt.h"
#include "ScreenTextEntry.h"
#include "ThemeManager.h"
#include "InputFilter.h"
#include "arch/ArchHooks/ArchHooks.h" // HOOKS->GetClipboard()

static const char* g_szKeys[NUM_KeyboardRow][KEYS_PER_ROW] =
Expand Down Expand Up @@ -413,41 +414,8 @@ void ScreenTextEntry::Update( float fDelta )

bool ScreenTextEntry::Input( const InputEventPlus &input )
{
static bool bLCtrl = false, bRCtrl = false;
if( IsTransitioning() )
return false;

// bLCtrl and bRCtl are whether their respective Ctrl keys are held
// We update them here.
if( input.DeviceI == DeviceInput(DEVICE_KEYBOARD, KEY_LCTRL) )
{
switch( input.type )
{
case IET_FIRST_PRESS:
bLCtrl = true;
break;
case IET_RELEASE:
bLCtrl = false;
break;
default:
break;
}
}

if( input.DeviceI == DeviceInput(DEVICE_KEYBOARD, KEY_RCTRL) )
{
switch( input.type )
{
case IET_FIRST_PRESS:
bRCtrl = true;
break;
case IET_RELEASE:
bRCtrl = false;
break;
default:
break;
}
}

bool bHandled = false;
if( input.DeviceI == DeviceInput(DEVICE_KEYBOARD, KEY_BACK) )
Expand All @@ -466,7 +434,9 @@ bool ScreenTextEntry::Input( const InputEventPlus &input )
{
wchar_t c = INPUTMAN->DeviceInputToChar(input.DeviceI,true);
// Detect Ctrl+V
if( ( c == L'v' || c == L'V' ) && ( bLCtrl || bRCtrl ) )
auto ctrlPressed = INPUTFILTER->IsControlPressed();
auto vPressed = input.DeviceI.button == KEY_CV || input.DeviceI.button == KEY_Cv;
if(vPressed && ctrlPressed)
{
TryAppendToAnswer( HOOKS->GetClipboard() );

Expand All @@ -476,7 +446,8 @@ bool ScreenTextEntry::Input( const InputEventPlus &input )
else if( c >= L' ' )
{
// todo: handle caps lock -aj
TryAppendToAnswer( WStringToRString(wstring()+c) );
auto str = WStringToRString(wstring() + c);
TryAppendToAnswer( str );

TextEnteredDirectly();
bHandled = true;
Expand Down
1 change: 1 addition & 0 deletions src/Song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ bool Song::ReloadFromSongDir( const RString &sDir )
// Remove the cache file to force the song to reload from its dir instead
// of loading from the cache. -Kyz
FILEMAN->Remove(GetCacheFilePath());
SONGINDEX->DeleteSongFromDBByDir(sDir.c_str());

vector<Steps*> vOldSteps = m_vpSteps;

Expand Down
13 changes: 11 additions & 2 deletions src/ezsockets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "global.h"

#include "ezsockets.h"
#include "Preference.h"
#include <iostream>

#if defined(_MSC_VER) // We need the WinSock32 Library on Windows
Expand Down Expand Up @@ -36,6 +37,8 @@
#define INVALID_SOCKET (-1)
#endif

static Preference<unsigned int> timeoutSeconds("ConnectionSecondsTimeout", 5);

// Returns a timeval set to the given number of milliseconds.
inline timeval timevalFromMs(unsigned int ms)
{
Expand Down Expand Up @@ -100,8 +103,14 @@ bool EzSockets::create(int Protocol, int Type)
state = skDISCONNECTED;
sock = socket(AF_INET, Type, Protocol);
if (sock > SOCKET_NONE) {
struct timeval tv = { 2, 0 };
setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (const char *)&tv, sizeof(struct timeval));
#if defined(WIN32)
int tv = timeoutSeconds*1000;
#else
struct timeval tv;
tv.tv_sec = timeoutSeconds;
tv.tv_usec = 0;
#endif
setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (const char *)&tv, sizeof(tv));
}
lastCode = sock;
return sock > SOCKET_NONE; // Socket must be Greater than 0
Expand Down

0 comments on commit d60f79e

Please sign in to comment.