Skip to content

Commit

Permalink
- Pulled remaining references to SDL library from OGL_Renderer.h to f…
Browse files Browse the repository at this point in the history
…urther encapsulate implementation details.

- Moved extern declaration of _WINDOW to EventHandler. It's a hack but it's necessary to get mouse grabbing working with SDL.
- Added some precision warning ignore pragma's to MersenneTwister -- don't care about precision in these cases.
- Pulled debug code out of Trig -- see no reason to keep it there.
- Pulled debug code from Renderer's d'tor.
  • Loading branch information
ldicker83 committed Mar 2, 2017
1 parent 9b7bffc commit 55776a1
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 52 deletions.
16 changes: 0 additions & 16 deletions include/NAS2D/Renderer/OGL_Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,11 @@

#pragma once

#ifdef WINDOWS
#define NO_SDL_GLEXT
#include "GL/glew.h"
#endif

#ifdef __APPLE__
#include <SDL2/SDL.h>
#elif __linux__
#include "SDL2/SDL.h"
#include "SDL2/SDL_opengl.h"
#else
#include "SDL.h"
#endif

#include "Renderer.h"
#include "ShaderManager.h"

#include <map>

extern SDL_Window* _window;

namespace NAS2D {

/**
Expand Down
16 changes: 10 additions & 6 deletions src/EventHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@

#include <iostream>

// UGLY ASS HACK!
// This is required for mouse grabbing in the EventHandler class.
extern SDL_Window* _WINDOW;


using namespace std;
using namespace NAS2D;
Expand Down Expand Up @@ -439,8 +443,8 @@ EventHandler::QuitEventCallback& EventHandler::quit()
*/
void EventHandler::grabMouse()
{
if(_window)
SDL_SetWindowGrab(_window, SDL_TRUE);
if(_WINDOW)
SDL_SetWindowGrab(_WINDOW, SDL_TRUE);
}


Expand All @@ -452,8 +456,8 @@ void EventHandler::grabMouse()
*/
void EventHandler::releaseMouse()
{
if(_window)
SDL_SetWindowGrab(_window, SDL_FALSE);
if(_WINDOW)
SDL_SetWindowGrab(_WINDOW, SDL_FALSE);
}


Expand All @@ -465,8 +469,8 @@ void EventHandler::releaseMouse()
*/
void EventHandler::warpMouse(int x, int y)
{
if(_window)
SDL_WarpMouseInWindow(_window, x, y);
if(_WINDOW)
SDL_WarpMouseInWindow(_WINDOW, x, y);
}


Expand Down
6 changes: 6 additions & 0 deletions src/MersenneTwister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@

#include "NAS2D/MersenneTwister.h"

#ifdef _MSC_VER
#pragma warning( push )
#pragma warning( disable : 4838 )
#pragma warning( disable : 4244 )
#endif

/**
* C'tor
*/
Expand Down
20 changes: 12 additions & 8 deletions src/Renderer/OGL_Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@
#include "NAS2D/Trig.h"
#include "NAS2D/Renderer/OGL_Renderer.h"

#if defined(__APPLE__)
#include <OpenGL/OpenGL.h>
#elif defined(WIN32)
#include "SDL/SDL_opengl.h"
#elif defined (__linux__)
#include "SDL2/SDL_opengl.h"
#ifdef WINDOWS
#define NO_SDL_GLEXT
#include "GL/glew.h"
#elif __APPLE__
#include <SDL2/SDL.h>
#elif __linux__
#include "SDL2/SDL.h"
#include "SDL2/SDL_opengl.h"
#else
#include "SDL2.h"
#endif


#include <iostream>
#include <math.h>

Expand Down Expand Up @@ -56,8 +61,7 @@ GraphicsQuality TEXTURE_FILTER = GRAPHICS_GOOD;


// UGLY ASS HACK!
// Until I do this properly, for now I'm leaving this as a global
// so that we can handle mouse input grabbing.
// This is required for mouse grabbing in the EventHandler class.
SDL_Window* _WINDOW = nullptr;

SDL_GLContext CONTEXT; /**< Primary OpenGL render context. */
Expand Down
10 changes: 0 additions & 10 deletions src/Renderer/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,6 @@ Renderer::Renderer(const std::string& rendererName, const std::string& appTitle)
*/
Renderer::~Renderer()
{
// This is purely a debugging aid.
#if defined(_DEBUG)
if(!mMessages.empty())
{
cout << "Renderer contains the following " << mMessages.size() << " messages:" << endl;
for(size_t i = 0; i < mMessages.size(); i++)
cout << i << " Description: " << mMessages[i] << endl;
}
#endif

cout << "Renderer Terminated." << endl;
}

Expand Down
13 changes: 1 addition & 12 deletions src/Trig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,7 @@ float NAS2D::radToDeg(float rad)
*/
float NAS2D::angleFromPoints(float x, float y, float x2, float y2)
{
#if defined(_DEBUG)
float angle = 90 - NAS2D::radToDeg(atan2(y2 - y, x2 - x));

// Corrects for an odd anomaly whenever the angle
// is between 270.0f and 260.0f.
if(angle < 0.0f)
angle = 360.0f + angle;

return angle;
#else
return 90 - radToDeg(atan2(y2 - y, x2 - x));
#endif
return 90.0f - radToDeg(atan2(y2 - y, x2 - x));
}


Expand Down

0 comments on commit 55776a1

Please sign in to comment.