Skip to content
This repository has been archived by the owner on Jun 26, 2019. It is now read-only.

Commit

Permalink
Remove sdl
Browse files Browse the repository at this point in the history
  • Loading branch information
ChillerDragon committed Dec 3, 2018
1 parent 26c99b4 commit b21c058
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 180 deletions.
6 changes: 0 additions & 6 deletions bam.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
CheckVersion("0.5")

Import("configure.lua")
Import("other/sdl/sdl.lua")
Import("other/freetype/freetype.lua")

--- Setup Config -------
Expand All @@ -10,7 +9,6 @@ config:Add(OptCCompiler("compiler"))
config:Add(OptTestCompileC("stackprotector", "int main(){return 0;}", "-fstack-protector -fstack-protector-all"))
config:Add(OptTestCompileC("minmacosxsdk", "int main(){return 0;}", "-mmacosx-version-min=10.7 -isysroot /Developer/SDKs/MacOSX10.7.sdk"))
config:Add(OptLibrary("zlib", "zlib.h", false))
config:Add(SDL.OptFind("sdl", true))
config:Add(FreeType.OptFind("freetype", true))
config:Finalize("config.lua")

Expand Down Expand Up @@ -158,9 +156,6 @@ function GenerateMacOSXSettings(settings, conf, arch, compiler)
-- Client
settings.link.frameworks:Add("OpenGL")
settings.link.frameworks:Add("AGL")
-- FIXME: the SDL config is applied in BuildClient too but is needed here before so the launcher will compile
config.sdl:Apply(settings)
settings.link.extrafiles:Merge(Compile(settings, "src/osxlaunch/client.m"))
BuildClient(settings)

-- Content
Expand Down Expand Up @@ -330,7 +325,6 @@ end


function BuildClient(settings, family, platform)
config.sdl:Apply(settings)
config.freetype:Apply(settings)

local client = Compile(settings, Collect("src/engine/client/*.cpp"))
Expand Down
35 changes: 0 additions & 35 deletions src/engine/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
#include <windows.h>
#endif

#include "SDL.h"
#ifdef main
#undef main
#endif
Expand Down Expand Up @@ -1660,17 +1659,6 @@ void CClient::Run()
m_LocalStartTime = time_get();
m_SnapshotParts = 0;

// init SDL
{
if(SDL_Init(0) < 0)
{
dbg_msg("client", "unable to init SDL base: %s", SDL_GetError());
return;
}

atexit(SDL_Quit); // ignore_convention
}

m_MenuStartTime = time_get();

// open socket
Expand Down Expand Up @@ -1750,11 +1738,6 @@ void CClient::Run()
m_aCmdConnect[0] = 0;
}

// update input
if(Input()->Update())
break; // SDL_QUIT


// release focus
if(!m_pGraphics->WindowActive())
{
Expand Down Expand Up @@ -1845,11 +1828,6 @@ void CClient::Run()
m_pGraphics->Shutdown();

m_ServerBrowser.SaveServerlist();

// shutdown SDL
{
SDL_Quit();
}
}

int64 CClient::TickStartTime(int Tick)
Expand Down Expand Up @@ -2069,19 +2047,6 @@ void CClient::ConchainServerBrowserUpdate(IConsole::IResult *pResult, void *pUse

void CClient::SwitchWindowScreen(int Index)
{
// Todo SDL: remove this when fixed (changing screen when in fullscreen is bugged)
if(g_Config.m_GfxFullscreen)
{
ToggleFullscreen();
if(Graphics()->SetWindowScreen(Index))
g_Config.m_GfxScreen = Index;
ToggleFullscreen();
}
else
{
if(Graphics()->SetWindowScreen(Index))
g_Config.m_GfxScreen = Index;
}
}

void CClient::ConchainWindowScreen(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
Expand Down
136 changes: 1 addition & 135 deletions src/engine/client/input.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#include "SDL.h"

#include <base/system.h>
#include <engine/shared/config.h>
#include <engine/graphics.h>
#include <engine/input.h>
#include <engine/keys.h>

Expand Down Expand Up @@ -47,45 +44,21 @@ CInput::CInput()

void CInput::Init()
{
m_pGraphics = Kernel()->RequestInterface<IEngineGraphics>();
// FIXME: unicode handling: use SDL_StartTextInput/SDL_StopTextInput on inputs

MouseModeRelative();
}

void CInput::MouseRelative(float *x, float *y)
{
if(!m_InputGrabbed)
return;

int nx = 0, ny = 0;
float Sens = g_Config.m_InpMousesens/100.0f;

SDL_GetRelativeMouseState(&nx,&ny);

*x = nx*Sens;
*y = ny*Sens;
}

void CInput::MouseModeAbsolute()
{
if(m_InputGrabbed)
{
m_InputGrabbed = 0;
SDL_ShowCursor(SDL_ENABLE);
SDL_SetRelativeMouseMode(SDL_FALSE);
}
}

void CInput::MouseModeRelative()
{
if(!m_InputGrabbed)
{
m_InputGrabbed = 1;
SDL_ShowCursor(SDL_DISABLE);
SDL_SetRelativeMouseMode(SDL_TRUE);
SDL_GetRelativeMouseState(NULL, NULL);
}
}

int CInput::MouseDoubleClick()
Expand All @@ -108,118 +81,11 @@ void CInput::Clear()

bool CInput::KeyState(int Key) const
{
return m_aInputState[Key>=KEY_MOUSE_1 ? Key : SDL_GetScancodeFromKey(KeyToKeycode(Key))];
return false;
}

int CInput::Update()
{
// keep the counter between 1..0xFFFF, 0 means not pressed
m_InputCounter = (m_InputCounter%0xFFFF)+1;

{
int i;
const Uint8 *pState = SDL_GetKeyboardState(&i);
if(i >= KEY_LAST)
i = KEY_LAST-1;
mem_copy(m_aInputState, pState, i);
}

// these states must always be updated manually because they are not in the GetKeyState from SDL
int i = SDL_GetMouseState(NULL, NULL);
if(i&SDL_BUTTON(1)) m_aInputState[KEY_MOUSE_1] = 1; // 1 is left
if(i&SDL_BUTTON(3)) m_aInputState[KEY_MOUSE_2] = 1; // 3 is right
if(i&SDL_BUTTON(2)) m_aInputState[KEY_MOUSE_3] = 1; // 2 is middle
if(i&SDL_BUTTON(4)) m_aInputState[KEY_MOUSE_4] = 1;
if(i&SDL_BUTTON(5)) m_aInputState[KEY_MOUSE_5] = 1;
if(i&SDL_BUTTON(6)) m_aInputState[KEY_MOUSE_6] = 1;
if(i&SDL_BUTTON(7)) m_aInputState[KEY_MOUSE_7] = 1;
if(i&SDL_BUTTON(8)) m_aInputState[KEY_MOUSE_8] = 1;
if(i&SDL_BUTTON(9)) m_aInputState[KEY_MOUSE_9] = 1;

{
SDL_Event Event;

while(SDL_PollEvent(&Event))
{
int Key = -1;
int Scancode = 0;
int Action = IInput::FLAG_PRESS;
switch (Event.type)
{
case SDL_TEXTINPUT:
AddEvent(Event.text.text, 0, IInput::FLAG_TEXT);
break;

// handle keys
case SDL_KEYDOWN:
Key = KeycodeToKey(Event.key.keysym.sym);
Scancode = Event.key.keysym.scancode;
break;
case SDL_KEYUP:
Action = IInput::FLAG_RELEASE;
Key = KeycodeToKey(Event.key.keysym.sym);
Scancode = Event.key.keysym.scancode;
break;

// handle mouse buttons
case SDL_MOUSEBUTTONUP:
Action = IInput::FLAG_RELEASE;

if(Event.button.button == 1) // ignore_convention
{
m_ReleaseDelta = time_get() - m_LastRelease;
m_LastRelease = time_get();
}

// fall through
case SDL_MOUSEBUTTONDOWN:
if(Event.button.button == SDL_BUTTON_LEFT) Key = KEY_MOUSE_1; // ignore_convention
if(Event.button.button == SDL_BUTTON_RIGHT) Key = KEY_MOUSE_2; // ignore_convention
if(Event.button.button == SDL_BUTTON_MIDDLE) Key = KEY_MOUSE_3; // ignore_convention
if(Event.button.button == 4) Key = KEY_MOUSE_4; // ignore_convention
if(Event.button.button == 5) Key = KEY_MOUSE_5; // ignore_convention
if(Event.button.button == 6) Key = KEY_MOUSE_6; // ignore_convention
if(Event.button.button == 7) Key = KEY_MOUSE_7; // ignore_convention
if(Event.button.button == 8) Key = KEY_MOUSE_8; // ignore_convention
if(Event.button.button == 9) Key = KEY_MOUSE_9; // ignore_convention
Scancode = Key;
break;

case SDL_MOUSEWHEEL:
if(Event.wheel.y > 0) Key = KEY_MOUSE_WHEEL_UP; // ignore_convention
if(Event.wheel.y < 0) Key = KEY_MOUSE_WHEEL_DOWN; // ignore_convention
Action |= IInput::FLAG_RELEASE;
break;

#if defined(CONF_PLATFORM_MACOSX) // Todo SDL: remove this when fixed (mouse state is faulty on start)
case SDL_WINDOWEVENT:
if(Event.window.event == SDL_WINDOWEVENT_MAXIMIZED)
{
MouseModeAbsolute();
MouseModeRelative();
}
break;
#endif

// other messages
case SDL_QUIT:
return 1;
}

//
if(Key != -1)
{
if(Action&IInput::FLAG_PRESS)
{
m_aInputState[Scancode] = 1;
m_aInputCount[Key] = m_InputCounter;
}
AddEvent(0, Key, Action);
}

}
}

return 0;
}

Expand Down
4 changes: 0 additions & 4 deletions src/engine/client/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

class CInput : public IEngineInput
{
IEngineGraphics *m_pGraphics;

int m_InputGrabbed;

int64 m_LastRelease;
Expand All @@ -24,8 +22,6 @@ class CInput : public IEngineInput
void ClearKeyStates();
bool KeyState(int Key) const;

IEngineGraphics *Graphics() { return m_pGraphics; }

public:
CInput();

Expand Down

0 comments on commit b21c058

Please sign in to comment.