This commit is contained in:
Ben Kyd
2025-06-26 22:47:09 +01:00
parent 97df659110
commit f1e2f0b950
58 changed files with 429 additions and 683 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,143 +1,139 @@
#include "Display.hpp"
#include <Aeon/Includes.hpp>
#include <Aeon/Assert.hpp>
#include <Aeon/Rendering/RenderMaster.hpp>
#include <Aeon/Includes.hpp>
#include <Aeon/Rendering/ImGui.hpp>
using Core::Display;
Display::Display()
: mWindow( nullptr )
, mContext( NULL )
, mRenderer( Rendering::RenderMaster::GetInstance() )
, mClearColour{ 1.0f, 1.0f, 1.0f, 1.0f }
: mWindow(nullptr), mContext(NULL), mClearColour {1.0f, 1.0f, 1.0f, 1.0f}
{
PushThisAsSink( "ENGINE_DISPLAY_CORE" );
PushThisAsSink("ENGINE_DISPLAY_CORE");
}
Display::~Display()
{
}
bool Display::Create( const DisplayProperties& properties )
bool Display::Create(const DisplayProperties& properties)
{
SDL_Init( SDL_INIT_VIDEO );
SDL_Init(SDL_INIT_VIDEO);
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_BUFFER_SIZE, 32 );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 );
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, 4 );
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 4 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 5 );
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 5);
mWindow = SDL_CreateWindow( properties.Name.c_str(),
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, properties.Width, properties.Height,
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE );
mWindow = SDL_CreateWindow(properties.Name.c_str(),
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
properties.Width,
properties.Height,
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
AEON_ASSERT( mWindow, "Can't initialise window" );
AEON_ASSERT(mWindow, "Can't initialise window");
mContext = SDL_GL_CreateContext( mWindow );
mContext = SDL_GL_CreateContext(mWindow);
AEON_ASSERT( mContext, "Can't initialise context" );
AEON_ASSERT(mContext, "Can't initialise context");
SDL_GL_SetSwapInterval( static_cast<int>(!properties.VSync) );
SDL_GL_SetSwapInterval(static_cast<int>(!properties.VSync));
gladLoadGLLoader( SDL_GL_GetProcAddress );
glEnable( GL_MULTISAMPLE );
glCullFace( GL_BACK );
glEnable( GL_DEPTH_TEST );
gladLoadGLLoader(SDL_GL_GetProcAddress);
glEnable(GL_MULTISAMPLE);
glCullFace(GL_BACK);
glEnable(GL_DEPTH_TEST);
mWidth = properties.Width;
mHeight = properties.Height;
mWidth = properties.Width;
mHeight = properties.Height;
Rendering::SetupImGui( mWindow, mContext );
Rendering::SetupImGui(mWindow, mContext);
// Make sure ImGUI is ready to be used on the first frame
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame();
// Make sure ImGUI is ready to be used on the first frame
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame();
return true;
return true;
}
const unsigned int Display::GetWidth()
{
return mWidth;
return mWidth;
}
const unsigned int Display::GetHeight()
{
return mHeight;
return mHeight;
}
const SDL_Window* Display::GetWindow()
{
return mWindow;
return mWindow;
}
const SDL_GLContext& Display::GetContext()
{
return mContext;
return mContext;
}
void Display::SetClearColour( float r, float g, float b, float a )
void Display::SetClearColour(float r, float g, float b, float a)
{
mClearColour[0] = r * a;
mClearColour[1] = g * a;
mClearColour[2] = b * a;
mClearColour[3] = a;
mClearColour[0] = r * a;
mClearColour[1] = g * a;
mClearColour[2] = b * a;
mClearColour[3] = a;
}
void Display::EndFrame()
{
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData( ImGui::GetDrawData() );
SDL_GL_SwapWindow( mWindow );
glClearColor( mClearColour[0], mClearColour[1], mClearColour[2], mClearColour[3] );
glClear( GL_COLOR_BUFFER_BIT );
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame();
SDL_GL_SwapWindow(mWindow);
glClearColor(mClearColour[0], mClearColour[1], mClearColour[2], mClearColour[3]);
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame();
}
void Display::Destroy()
{
Rendering::CleanupImGui();
SDL_DestroyWindow( mWindow );
// dangly balls
mWindow = nullptr;
mWidth = 0;
mHeight = 0;
Rendering::CleanupImGui();
SDL_DestroyWindow(mWindow);
// dangly balls
mWindow = nullptr;
mWidth = 0;
mHeight = 0;
}
bool Display::EventRecieved( GenericEvent& e )
bool Display::EventRecieved(GenericEvent& e)
{
if ( e.Type == "DISPLAY_RESIZE" )
{
mWidth = e.x;
mHeight = e.y;
return true;
}
if (e.Type == "DISPLAY_RESIZE")
{
mWidth = e.x;
mHeight = e.y;
return true;
}
if ( e.Type == "DISPLAY_MOVE" )
{
mX = e.x;
mY = e.y;
return true;
}
if (e.Type == "DISPLAY_MOVE")
{
mX = e.x;
mY = e.y;
return true;
}
return false;
return false;
}

View File

@@ -37,8 +37,6 @@ private:
SDL_Window* mWindow;
SDL_GLContext mContext;
RenderMaster& mRenderer;
unsigned int mWidth, mHeight = 0;
unsigned int mX, mY = 0;
float mClearColour[4];

View File

@@ -2,262 +2,265 @@
#include <Aeon/Assert.hpp>
using Core::GenericEvent;
using Core::EventListener;
using Core::EventDispatcher;
using Core::EventListener;
using Core::EventManager;
using Core::GenericEvent;
// TODO: Events should use pre-allocated memory ALWAYS!
// TODO: Look into Bump Allocation
EventListener::EventListener()
{
}
EventListener::~EventListener()
{
}
void EventListener::PushThisAsSink( std::string system )
void EventListener::PushThisAsSink(std::string system)
{
mListenerID = EventManager::GetInstance().RegisterSinkPush( this, system );
AEON_ASSERT( mListenerID != -1, "Cannot register event sink" );
mListenerID = EventManager::GetInstance().RegisterSinkPush(this, system);
AEON_ASSERT(mListenerID != -1, "Cannot register event sink");
}
void EventListener::PushAndStickThisAsSink( std::string system )
void EventListener::PushAndStickThisAsSink(std::string system)
{
mListenerID = EventManager::GetInstance().RegisterSinkPushStick( this, system );
AEON_ASSERT( mListenerID != -1, "Cannot register event sink" );
mListenerID = EventManager::GetInstance().RegisterSinkPushStick(this, system);
AEON_ASSERT(mListenerID != -1, "Cannot register event sink");
}
void EventListener::UnshiftThisAsSink( std::string system )
void EventListener::UnshiftThisAsSink(std::string system)
{
mListenerID = EventManager::GetInstance().RegisterSinkUnshift( this, system );
AEON_ASSERT( mListenerID != -1, "Cannot register event sink" );
mListenerID = EventManager::GetInstance().RegisterSinkUnshift(this, system);
AEON_ASSERT(mListenerID != -1, "Cannot register event sink");
}
void EventListener::ShiftSinkLeft( std::string forSystem )
void EventListener::ShiftSinkLeft(std::string forSystem)
{
EventManager::GetInstance().MoveSinkLeft( this, forSystem );
EventManager::GetInstance().MoveSinkLeft(this, forSystem);
}
void EventListener::ShiftSinkRight( std::string forSystem )
void EventListener::ShiftSinkRight(std::string forSystem)
{
EventManager::GetInstance().MoveSinkRight( this, forSystem );
EventManager::GetInstance().MoveSinkRight(this, forSystem);
}
void EventListener::DeRegisterAsSink( std::string system )
void EventListener::DeRegisterAsSink(std::string system)
{
}
EventDispatcher::EventDispatcher()
{
}
EventDispatcher::EventDispatcher( std::string system )
EventDispatcher::EventDispatcher(std::string system)
{
RegisterAsSource( system );
RegisterAsSource(system);
}
EventDispatcher::~EventDispatcher()
{
}
void EventDispatcher::RegisterAsSource( std::string system )
void EventDispatcher::RegisterAsSource(std::string system)
{
mDispatcherID = EventManager::GetInstance().RegisterSource( this, system );
AEON_ASSERT( mDispatcherID != -1, "Cannot register event source" );
mSystem = system;
mDispatcherID = EventManager::GetInstance().RegisterSource(this, system);
AEON_ASSERT(mDispatcherID != -1, "Cannot register event source");
mSystem = system;
}
void EventDispatcher::DeRegisterAsSource( std::string system )
void EventDispatcher::DeRegisterAsSource(std::string system)
{
}
void EventDispatcher::Dispatch( GenericEvent e )
void EventDispatcher::Dispatch(GenericEvent e)
{
e.System = mSystem;
EventManager::GetInstance().Dispatch( mDispatcherID, e );
e.System = mSystem;
EventManager::GetInstance().Dispatch(mDispatcherID, e);
}
void EventDispatcher::Dispatch( std::string type )
void EventDispatcher::Dispatch(std::string type)
{
GenericEvent e;
e.Type = type;
e.System = mSystem;
EventManager::GetInstance().Dispatch( mDispatcherID, e );
GenericEvent e;
e.Type = type;
e.System = mSystem;
EventManager::GetInstance().Dispatch(mDispatcherID, e);
}
EventManager::EventManager()
{
}
EventManager::~EventManager()
{
}
int EventManager::RegisterSource( EventDispatcher* source, std::string system )
int EventManager::RegisterSource(EventDispatcher* source, std::string system)
{
int id = mNextHeighest;
mSources[id] = system;
mNextHeighest++;
return id;
int id = mNextHeighest;
mSources[id] = system;
mNextHeighest++;
return id;
}
int EventManager::RegisterSinkPush( EventListener* sink, std::string system )
int EventManager::RegisterSinkPush(EventListener* sink, std::string system)
{
int id = mNextHeighest;
mListeners[id] = sink;
int id = mNextHeighest;
mListeners[id] = sink;
auto& sinkVector = mSinks[system];
sinkVector.push_back( { sink, id } );
auto& sinkVector = mSinks[system];
sinkVector.push_back({sink, id});
mNextHeighest++;
return id;
mNextHeighest++;
return id;
}
int EventManager::RegisterSinkPushStick( EventListener* sink, std::string system )
int EventManager::RegisterSinkPushStick(EventListener* sink, std::string system)
{
int id = mNextHeighest;
mListeners[id] = sink;
int id = mNextHeighest;
mListeners[id] = sink;
auto& sinkVector = mStickySinks[system];
sinkVector.push_back( { sink, id } );
auto& sinkVector = mStickySinks[system];
sinkVector.push_back({sink, id});
mNextHeighest++;
return id;
mNextHeighest++;
return id;
}
int EventManager::RegisterSinkUnshift( EventListener* sink, std::string system )
int EventManager::RegisterSinkUnshift(EventListener* sink, std::string system)
{
int id = mNextHeighest;
mListeners[id] = sink;
int id = mNextHeighest;
mListeners[id] = sink;
if ( !mSinks.count( system ) )
{
return RegisterSinkPush( sink, system );
}
if (!mSinks.count(system))
{
return RegisterSinkPush(sink, system);
}
auto& sinkVector = mSinks[system];
sinkVector.insert( sinkVector.begin(), { sink, id } );
auto& sinkVector = mSinks[system];
sinkVector.insert(sinkVector.begin(), {sink, id});
mNextHeighest++;
return id;
mNextHeighest++;
return id;
}
void EventManager::MoveSinkLeft( EventListener* sink, std::string system )
void EventManager::MoveSinkLeft(EventListener* sink, std::string system)
{
}
void EventManager::MoveSinkRight( EventListener* sink, std::string system )
void EventManager::MoveSinkRight(EventListener* sink, std::string system)
{
}
void EventManager::RemoveSource( int dispatcherID, std::string system )
void EventManager::RemoveSource(int dispatcherID, std::string system)
{
}
void EventManager::RemoveSink( int listenerID, std::string system )
void EventManager::RemoveSink(int listenerID, std::string system)
{
}
// it is important to reverse the lists so that the dispatching is done correctly
// this is more efficiently done at insert... lol
template <typename C>
struct reverse_wrapper {
struct reverse_wrapper
{
C& c_;
reverse_wrapper(C& c) : c_(c) {}
C& c_;
reverse_wrapper(C& c) : c_(c)
{}
typename C::reverse_iterator begin() { return c_.rbegin(); }
typename C::reverse_iterator end() { return c_.rend(); }
typename C::reverse_iterator begin()
{
return c_.rbegin();
}
typename C::reverse_iterator end()
{
return c_.rend();
}
};
template <typename C, size_t N>
struct reverse_wrapper< C[N] > {
struct reverse_wrapper<C[N]>
{
C(&c_)[N];
reverse_wrapper(C(&c)[N]) : c_(c) {}
C (&c_)
[N];
reverse_wrapper(C (&c)[N]) : c_(c)
{}
typename std::reverse_iterator<const C*> begin() { return std::rbegin(c_); }
typename std::reverse_iterator<const C*> end() { return std::rend(c_); }
typename std::reverse_iterator<const C*> begin()
{
return std::rbegin(c_);
}
typename std::reverse_iterator<const C*> end()
{
return std::rend(c_);
}
};
template <typename C>
reverse_wrapper<C> r_wrap(C& c) {
return reverse_wrapper<C>(c);
reverse_wrapper<C> r_wrap(C& c)
{
return reverse_wrapper<C>(c);
}
void EventManager::Dispatch( int dispatcherID, GenericEvent e )
void EventManager::Dispatch(int dispatcherID, GenericEvent e)
{
std::string targetSink = mSources[dispatcherID];
auto stickySinks = mStickySinks[targetSink];
auto sinks = mSinks[targetSink];
std::string targetSink = mSources[dispatcherID];
auto stickySinks = mStickySinks[targetSink];
auto sinks = mSinks[targetSink];
if ( !stickySinks.empty() )
{
for ( auto& listenerPair : r_wrap(stickySinks))
{
EventListener* listener = std::get<0>( listenerPair );
bool handled = listener->EventRecieved( e );
if ( handled ) e.Handled = handled;
if (!stickySinks.empty())
{
for (auto& listenerPair : r_wrap(stickySinks))
{
EventListener* listener = std::get<0>(listenerPair);
bool handled = listener->EventRecieved(e);
if (handled)
e.Handled = handled;
if ( e.Handled )
{
// destroy event
return;
}
}
}
if (e.Handled)
{
// destroy event
return;
}
}
}
if (!sinks.empty())
{
for (auto& listenerPair : r_wrap(sinks))
{
EventListener* listener = std::get<0>(listenerPair);
bool handled = listener->EventRecieved(e);
if (handled) e.Handled = handled;
if (!sinks.empty())
{
for (auto& listenerPair : r_wrap(sinks))
{
EventListener* listener = std::get<0>(listenerPair);
bool handled = listener->EventRecieved(e);
if (handled)
e.Handled = handled;
if (e.Handled)
{
// destroy event
return;
}
}
}
if (e.Handled)
{
// destroy event
return;
}
}
}
}
void EventManager::DebugPrint()
{
std::cout << "----- BEGIN EVENTS DEBUG -----" << std::endl;
for (auto const& [dispatcher, targetSink] : mSources)
{
auto stickySinks = mStickySinks[targetSink];
auto sinks = mSinks[targetSink];
std::cout << "----- BEGIN EVENTS DEBUG -----" << std::endl;
for (auto const& [dispatcher, targetSink] : mSources)
{
auto stickySinks = mStickySinks[targetSink];
auto sinks = mSinks[targetSink];
int sourceCount = 0;
for (auto const& [id, source] : mSources)
if (source == targetSink) sourceCount++;
int sourceCount = 0;
for (auto const& [id, source] : mSources)
if (source == targetSink)
sourceCount++;
std::cout << targetSink << " has " << stickySinks.size() << " sticky and " << sinks.size() << " sink(s) and is being dispatched from " << sourceCount << " different source(s)" << std::endl;
}
std::cout << "----- END EVENTS DEBUG -----" << std::endl;
std::cout << targetSink << " has " << stickySinks.size() << " sticky and " << sinks.size() << " sink(s) and is being dispatched from " << sourceCount << " different source(s)" << std::endl;
}
std::cout << "----- END EVENTS DEBUG -----" << std::endl;
}

View File

@@ -2,173 +2,173 @@
#define AEON_CORE_EVENTS_H_
/*
- Events have a source and a sink, where from and where too
- Event sinks are systems that events are dispatched to from
a source of the same system
- Event listeners are layered, 0 is front, larger is back so
events propogate from the front to the back, not going
further once handled
- Event sources can only dispatch events to a single system
- Systems can request to only receive events from a certain
"system" category, or multiple
- Events are blocking for now
- Events have a source and a sink, where from and where too
- Event sinks are systems that events are dispatched to from
a source of the same system
- Event listeners are layered, 0 is front, larger is back so
events propogate from the front to the back, not going
further once handled
- Event sources can only dispatch events to a single system
- Systems can request to only receive events from a certain
"system" category, or multiple
- Events are blocking for now
*/
#include <Aeon/Includes.hpp>
#include <Aeon/Singleton.hpp>
#include <Aeon/Input/InputMap.hpp>
#include <Aeon/Singleton.hpp>
namespace Core
namespace Core
{
// THis needs some redesigning so i can do this.AttachSpecificListener(Type, Action, [&] => {...})
// More specifically to support enumerator calling AND custom defined string calling
// Maybe through a reserved enumeration map 0-100: system etc..
/*
* Engine event systems / type
* ENGINE_SYSTEM_CORE - start, stop, pause, etc
* ENGINE_START - starts game loop execution
* ENGINE_STOP
* ENGINE_PAUSE
* ENGINE_DISPLAY_CORE - window open, window close, etc
* DISPLAY_RESIZE (x, y) - rezise to x, y being new w, h
* DISPLAY_MOVE (x, y) - move to x, y
* DISPLAY_SHOW - no data
* DISPLAY_HIDE - no data
* DISPLAY_MINIMISED - no data
* DISPLAY_MAXIMISED - no data
* DISPLAY_CLOSED - no data
* DISPLAY_MOUSE_ENTER - no data
* DISPLAY_MOUSE_LEAVE - no data
* DISPLAY_FOCUS - no data
* DISPLAY_OUT_OF_FOCUS - no data
* ENGINE_INPUT_MOUSE
* MOUSE_LEFT_DOWN - no data
* MOUSE_LEFT_UP - no data
* MOUSE_RIGHT_DOWN - no data
* MOUSE_RIGHT_UP - no data
* MOUSE_MIDDLE_DOWN - no data
* MOUSE_MIDDLE_UP - no data
* MOUSE_SCROLL - y+-
* MOUSE_MOVE - move to x, y relative dx, dy
* ENGINE_INPUT_KEYBOARD
* KEYBOARD_KEYDOWN - keycode, keymod
* KEYBOARD_KEYUP - keycode, keymod
* KEYBOARD_KEYPRESS - keycode for continual pressing, keymod
*/
* Engine event systems / type
* ENGINE_SYSTEM_CORE - start, stop, pause, etc
* ENGINE_START - starts game loop execution
* ENGINE_STOP
* ENGINE_PAUSE
* ENGINE_DISPLAY_CORE - window open, window close, etc
* DISPLAY_RESIZE (x, y) - rezise to x, y being new w, h
* DISPLAY_MOVE (x, y) - move to x, y
* DISPLAY_SHOW - no data
* DISPLAY_HIDE - no data
* DISPLAY_MINIMISED - no data
* DISPLAY_MAXIMISED - no data
* DISPLAY_CLOSED - no data
* DISPLAY_MOUSE_ENTER - no data
* DISPLAY_MOUSE_LEAVE - no data
* DISPLAY_FOCUS - no data
* DISPLAY_OUT_OF_FOCUS - no data
* ENGINE_INPUT_MOUSE
* MOUSE_LEFT_DOWN - no data
* MOUSE_LEFT_UP - no data
* MOUSE_RIGHT_DOWN - no data
* MOUSE_RIGHT_UP - no data
* MOUSE_MIDDLE_DOWN - no data
* MOUSE_MIDDLE_UP - no data
* MOUSE_SCROLL - y+-
* MOUSE_MOVE - move to x, y relative dx, dy
* ENGINE_INPUT_KEYBOARD
* KEYBOARD_KEYDOWN - keycode, keymod
* KEYBOARD_KEYUP - keycode, keymod
* KEYBOARD_KEYPRESS - keycode for continual pressing, keymod
*/
struct GenericEvent
{
// always populated
std::string System;
std::string Type;
// the rest can be empty
// user defined
std::string Data;
// always populated
std::string System;
std::string Type;
// DISPLAY_RESIZE DISPLAY_MOVE MOUSE_MOVE
int x, y;
// MOUSE_MOVE
int dx, dy;
// KEYBOARD_KEYDOWN KEYBOARD_KEYUP KEYBOARD_PRESSED
Input::EKeyCode keyCode;
uint16_t keyMods;
// the rest can be empty
// user defined
std::string Data;
bool Handled = false;
// DISPLAY_RESIZE DISPLAY_MOVE MOUSE_MOVE
int x, y;
// MOUSE_MOVE
int dx, dy;
// KEYBOARD_KEYDOWN KEYBOARD_KEYUP KEYBOARD_PRESSED
Input::EKeyCode keyCode;
uint16_t keyMods;
// USER EVENTS
void* UserData = nullptr;
bool Handled = false;
};
class EventListener
{
public:
EventListener();
virtual ~EventListener();
EventListener();
virtual ~EventListener();
// Pushes sink to the top of the listener stack
// underneath the stuck listeners
void PushThisAsSink( std::string system );
// Pushes sink to the top of the listener stack
// with all of the other "stuck" listeners
void PushAndStickThisAsSink( std::string system );
// Pushes sink to the bottom of the listener stack
void UnshiftThisAsSink( std::string system );
// Pushes sink to the top of the listener stack
// underneath the stuck listeners
void PushThisAsSink(std::string system);
// Pushes sink to the top of the listener stack
// with all of the other "stuck" listeners
void PushAndStickThisAsSink(std::string system);
// Pushes sink to the bottom of the listener stack
void UnshiftThisAsSink(std::string system);
void ShiftSinkLeft( std::string forSystem );
void ShiftSinkRight( std::string forSystem );
void ShiftSinkLeft(std::string forSystem);
void ShiftSinkRight(std::string forSystem);
void DeRegisterAsSink( std::string system );
void DeRegisterAsSink(std::string system);
// return true = event handled and will not be further
// propogated
virtual bool EventRecieved( GenericEvent& e ) = 0;
// return true = event handled and will not be further
// propogated
virtual bool EventRecieved(GenericEvent& e) = 0;
private:
int mListenerID = -1;
int mListenerID = -1;
friend class EventManager;
friend class EventManager;
};
class EventDispatcher
{
public:
EventDispatcher();
EventDispatcher( std::string system );
~EventDispatcher();
EventDispatcher();
EventDispatcher(std::string system);
~EventDispatcher();
void RegisterAsSource( std::string system );
void DeRegisterAsSource( std::string system );
void RegisterAsSource(std::string system);
void DeRegisterAsSource(std::string system);
void Dispatch( GenericEvent e );
// no data needed, listeners act on the event happening
void Dispatch( std::string type );
void Dispatch(GenericEvent e);
// no data needed, listeners act on the event happening
void Dispatch(std::string type);
private:
std::string mSystem;
int mDispatcherID = -1;
std::string mSystem;
int mDispatcherID = -1;
friend class EventManager;
friend class EventManager;
};
class EventManager : public Helpers::Singleton<EventManager>
{
public:
EventManager();
~EventManager();
EventManager();
~EventManager();
int RegisterSource( EventDispatcher* source, std::string system );
int RegisterSource(EventDispatcher* source, std::string system);
int RegisterSinkPush( EventListener* sink, std::string system );
int RegisterSinkPushStick( EventListener* sink, std::string system );
int RegisterSinkUnshift( EventListener* sink, std::string system );
int RegisterSinkPush(EventListener* sink, std::string system);
int RegisterSinkPushStick(EventListener* sink, std::string system);
int RegisterSinkUnshift(EventListener* sink, std::string system);
void MoveSinkLeft( EventListener* sink, std::string system );
void MoveSinkRight( EventListener* sink, std::string system );
void MoveSinkLeft(EventListener* sink, std::string system);
void MoveSinkRight(EventListener* sink, std::string system);
void RemoveSource( int dispatcherID, std::string system );
void RemoveSink( int listenerID, std::string system );
void RemoveSource(int dispatcherID, std::string system);
void Dispatch( int dispatcherID, GenericEvent e );
void RemoveSink(int listenerID, std::string system);
void DebugPrint();
void Dispatch(int dispatcherID, GenericEvent e);
void DebugPrint();
private:
// indexed by listener ID for quick lookup
std::map<int, const EventListener*> mListeners;
// indexed by dispatcher ID for itteration
std::map<int, std::string> mSources;
// indexed by (sink) system ID (string)
// their position in the vector is their layer
std::map<std::string, std::vector<std::tuple<EventListener*, int>>> mStickySinks;
std::map<std::string, std::vector<std::tuple<EventListener*, int>>> mSinks;
// indexed by listener ID for quick lookup
std::map<int, const EventListener*> mListeners;
// indexed by dispatcher ID for itteration
std::map<int, std::string> mSources;
// indexed by (sink) system ID (string)
// their position in the vector is their layer
std::map<std::string, std::vector<std::tuple<EventListener*, int>>> mStickySinks;
std::map<std::string, std::vector<std::tuple<EventListener*, int>>> mSinks;
int mNextHeighest = 0;
int mNextHeighest = 0;
};
}
} // namespace Core
#endif

View File

@@ -2,26 +2,23 @@
using namespace EC;
EntityRegistry::EntityRegistry()
{
}
EntityRegistry::~EntityRegistry()
{
}
Entity EntityRegistry::Create()
{
uint32_t entityId;
if ( mFreedEntities.empty() )
if (mFreedEntities.empty())
{
mEntityCeiling++;
entityId = mEntityCeiling;
}
else
}
else
{
mFreedEntities.pop();
}
@@ -30,22 +27,23 @@ Entity EntityRegistry::Create()
return entityId;
}
Entity Copy( const Entity& entity )
Entity Copy(const Entity& entity)
{
// look up everything, create a new entity and populate
// with the components in the og entity
return static_cast<uint32_t>( 0 );
return static_cast<uint32_t>(0);
}
void EntityRegistry::Destroy( Entity entity )
void EntityRegistry::Destroy(Entity entity)
{
if ( !this->Valid( entity ) ) return;
if (!this->Valid(entity))
return;
mFreedEntities.push(entity);
mEntities.erase(entity);
}
bool EntityRegistry::Valid( const Entity entity )
bool EntityRegistry::Valid(const Entity entity)
{
return mEntities.find(entity) != mEntities.end();
}

View File

@@ -1,9 +1,8 @@
#ifndef AEON_ENTITY_ENTITYCONTROLLER_H_
#define AEON_ENTITY_ENTITYCONTROLLER_H_
#include <Aeon/Includes.hpp>
#include <Aeon/Entity/Entity.hpp>
#include <Aeon/Includes.hpp>
namespace EC
{
@@ -17,9 +16,9 @@ public:
~EntityRegistry();
Entity Create();
Entity Copy( const Entity entity );
void Destroy( Entity entity );
bool Valid( const Entity entity );
Entity Copy(const Entity entity);
void Destroy(Entity entity);
bool Valid(const Entity entity);
// add, replace components
template <typename TComponent>
@@ -27,7 +26,7 @@ public:
template <typename TComponent>
TComponent& Replace(const Entity entity);
// replace in-place
template <typename TComponent>
TComponent& Patch(const Entity entity);
@@ -35,7 +34,7 @@ public:
// Get component from entity based on T
template <typename TComponent>
TComponent& Get(const Entity entity);
// Get std::optional from entity based on T
template <typename TComponent>
std::optional<TComponent&> Opt(const Entity entity);
@@ -43,7 +42,7 @@ public:
// TODO: Sort by component properties, for example list of
// entities with the renderable components, sorted by Y pos
// of position component
// template <typename T>
// template <typename T>
// std::vector<T&> Sort(std::function<;
private:
@@ -58,7 +57,7 @@ private:
// optimisations coming soon TM
std::unordered_map<Entity, std::vector<std::string>> mEntities;
};
}
} // namespace EC
#endif

View File

@@ -1,76 +1,67 @@
#include "Input.hpp"
#include <Aeon/Includes.hpp>
#include <Aeon/Core/Events.hpp>
#include <Aeon/Includes.hpp>
#include <Aeon/Input/InputMap.hpp>
#include <Aeon/Rendering/ImGui.hpp>
using Input::InputController;
InputController::InputController()
: mEvent()
, mDisplayEventDispatcher()
, mKeyboardEventDispatcher()
, mMouseEventDispatcher()
: mEvent(), mDisplayEventDispatcher(), mKeyboardEventDispatcher(), mMouseEventDispatcher()
{
mDisplayEventDispatcher.RegisterAsSource( "ENGINE_DISPLAY_CORE" );
mMouseEventDispatcher.RegisterAsSource( "ENGINE_INPUT_MOUSE" );
mKeyboardEventDispatcher.RegisterAsSource( "ENGINE_INPUT_KEYBOARD" );
mDisplayEventDispatcher.RegisterAsSource("ENGINE_DISPLAY_CORE");
mMouseEventDispatcher.RegisterAsSource("ENGINE_INPUT_MOUSE");
mKeyboardEventDispatcher.RegisterAsSource("ENGINE_INPUT_KEYBOARD");
mKbdState = static_cast<const uint8_t*>(SDL_GetKeyboardState( &mNumScancodes ));
mKbdState = static_cast<const uint8_t*>(SDL_GetKeyboardState(&mNumScancodes));
}
InputController::~InputController()
{
mDisplayEventDispatcher.DeRegisterAsSource( "ENGINE_DISPLAY_CORE" );
mMouseEventDispatcher.DeRegisterAsSource( "ENGINE_INPUT_MOUSE" );
mKeyboardEventDispatcher.DeRegisterAsSource( "ENGINE_INPUT_KEYBOARD" );
mDisplayEventDispatcher.DeRegisterAsSource("ENGINE_DISPLAY_CORE");
mMouseEventDispatcher.DeRegisterAsSource("ENGINE_INPUT_MOUSE");
mKeyboardEventDispatcher.DeRegisterAsSource("ENGINE_INPUT_KEYBOARD");
// Do not free mKbdState as that is done by SDL
}
void InputController::PollInput()
{
//SDL_PumpEvents();
while ( SDL_PollEvent( &mEvent ) )
{
// SDL_PumpEvents();
while (SDL_PollEvent(&mEvent))
{
// Provide to non-event driven subsystem
ImGui_ImplSDL2_ProcessEvent( &mEvent );
ImGui_ImplSDL2_ProcessEvent(&mEvent);
switch ( mEvent.type )
{
case SDL_WINDOWEVENT:
{
switch (mEvent.type)
{
case SDL_WINDOWEVENT: {
mPollDisplay();
break;
}
case SDL_MOUSEWHEEL:
{
}
case SDL_MOUSEWHEEL: {
mPollScroll();
break;
}
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
{
case SDL_MOUSEBUTTONUP: {
mPollClick();
break;
}
case SDL_MOUSEMOTION:
{
case SDL_MOUSEMOTION: {
mPollMouse();
break;
}
case SDL_KEYDOWN:
case SDL_KEYUP:
{
case SDL_KEYUP: {
mPollKeyboard();
}
}
}
}
}
// just in case
mKbdState = static_cast<const uint8_t*>(SDL_GetKeyboardState( &mNumScancodes ));
mKbdState = static_cast<const uint8_t*>(SDL_GetKeyboardState(&mNumScancodes));
// keyboard processing
mPollScanKeyboard();
@@ -78,69 +69,58 @@ void InputController::PollInput()
void InputController::mPollDisplay()
{
switch ( mEvent.window.event )
switch (mEvent.window.event)
{
case SDL_WINDOWEVENT_SHOWN:
{
mDisplayEventDispatcher.Dispatch( "DISPLAY_SHOW" );
case SDL_WINDOWEVENT_SHOWN: {
mDisplayEventDispatcher.Dispatch("DISPLAY_SHOW");
break;
}
case SDL_WINDOWEVENT_HIDDEN:
{
mDisplayEventDispatcher.Dispatch( "DISPLAY_HIDE" );
case SDL_WINDOWEVENT_HIDDEN: {
mDisplayEventDispatcher.Dispatch("DISPLAY_HIDE");
break;
}
case SDL_WINDOWEVENT_MOVED:
{
case SDL_WINDOWEVENT_MOVED: {
Core::GenericEvent e;
e.x = mEvent.window.data1;
e.y = mEvent.window.data2;
e.Type = "DISPLAY_MOVE";
mDisplayEventDispatcher.Dispatch( e );
mDisplayEventDispatcher.Dispatch(e);
break;
}
case SDL_WINDOWEVENT_RESIZED:
{
case SDL_WINDOWEVENT_RESIZED: {
Core::GenericEvent e;
e.x = mEvent.window.data1;
e.y = mEvent.window.data2;
e.Type = "DISPLAY_RESIZE";
mDisplayEventDispatcher.Dispatch( e );
mDisplayEventDispatcher.Dispatch(e);
break;
}
case SDL_WINDOWEVENT_MINIMIZED:
{
mDisplayEventDispatcher.Dispatch( "DISPLAY_MINIMISED" );
case SDL_WINDOWEVENT_MINIMIZED: {
mDisplayEventDispatcher.Dispatch("DISPLAY_MINIMISED");
break;
}
case SDL_WINDOWEVENT_MAXIMIZED:
{
mDisplayEventDispatcher.Dispatch( "DISPLAY_MAXIMISED" );
case SDL_WINDOWEVENT_MAXIMIZED: {
mDisplayEventDispatcher.Dispatch("DISPLAY_MAXIMISED");
break;
}
case SDL_WINDOWEVENT_ENTER:
{
mDisplayEventDispatcher.Dispatch( "DISPLAY_MOUSE_ENTER" );
case SDL_WINDOWEVENT_ENTER: {
mDisplayEventDispatcher.Dispatch("DISPLAY_MOUSE_ENTER");
break;
}
case SDL_WINDOWEVENT_LEAVE:
{
mDisplayEventDispatcher.Dispatch( "DISPLAY_MOUSE_LEAVE" );
case SDL_WINDOWEVENT_LEAVE: {
mDisplayEventDispatcher.Dispatch("DISPLAY_MOUSE_LEAVE");
break;
}
case SDL_WINDOWEVENT_FOCUS_GAINED:
{
mDisplayEventDispatcher.Dispatch( "DISPLAY_FOCUS" );
case SDL_WINDOWEVENT_FOCUS_GAINED: {
mDisplayEventDispatcher.Dispatch("DISPLAY_FOCUS");
break;
}
case SDL_WINDOWEVENT_FOCUS_LOST:
{
mDisplayEventDispatcher.Dispatch( "DISPLAY_OUT_OF_FOCUS" );
case SDL_WINDOWEVENT_FOCUS_LOST: {
mDisplayEventDispatcher.Dispatch("DISPLAY_OUT_OF_FOCUS");
break;
}
case SDL_WINDOWEVENT_CLOSE:
{
mDisplayEventDispatcher.Dispatch( "DISPLAY_CLOSED" );
case SDL_WINDOWEVENT_CLOSE: {
mDisplayEventDispatcher.Dispatch("DISPLAY_CLOSED");
break;
}
}
@@ -154,7 +134,7 @@ void InputController::mPollMouse()
e.dx = mEvent.motion.xrel;
e.dy = mEvent.motion.yrel;
e.Type = "MOUSE_MOVE";
mMouseEventDispatcher.Dispatch( e );
mMouseEventDispatcher.Dispatch(e);
}
void InputController::mPollScroll()
@@ -162,49 +142,43 @@ void InputController::mPollScroll()
Core::GenericEvent e;
e.y = mEvent.wheel.y;
e.Type = "MOUSE_SCROLL";
mMouseEventDispatcher.Dispatch( e );
mMouseEventDispatcher.Dispatch(e);
}
void InputController::mPollClick()
{
if ( mEvent.button.state == SDL_PRESSED )
if (mEvent.button.state == SDL_PRESSED)
{
switch ( mEvent.button.button )
switch (mEvent.button.button)
{
case SDL_BUTTON_LEFT:
{
mDisplayEventDispatcher.Dispatch( "MOUSE_LEFT_DOWN" );
case SDL_BUTTON_LEFT: {
mDisplayEventDispatcher.Dispatch("MOUSE_LEFT_DOWN");
break;
}
case SDL_BUTTON_RIGHT:
{
mDisplayEventDispatcher.Dispatch( "MOUSE_RIGHT_DOWN" );
case SDL_BUTTON_RIGHT: {
mDisplayEventDispatcher.Dispatch("MOUSE_RIGHT_DOWN");
break;
}
case SDL_BUTTON_MIDDLE:
{
mDisplayEventDispatcher.Dispatch( "MOUSE_MIDDLE_DOWN" );
case SDL_BUTTON_MIDDLE: {
mDisplayEventDispatcher.Dispatch("MOUSE_MIDDLE_DOWN");
break;
}
}
}
else if ( mEvent.button.state == SDL_RELEASED )
else if (mEvent.button.state == SDL_RELEASED)
{
switch ( mEvent.button.button )
switch (mEvent.button.button)
{
case SDL_BUTTON_LEFT:
{
mDisplayEventDispatcher.Dispatch( "MOUSE_LEFT_UP" );
case SDL_BUTTON_LEFT: {
mDisplayEventDispatcher.Dispatch("MOUSE_LEFT_UP");
break;
}
case SDL_BUTTON_RIGHT:
{
mDisplayEventDispatcher.Dispatch( "MOUSE_RIGHT_UP" );
case SDL_BUTTON_RIGHT: {
mDisplayEventDispatcher.Dispatch("MOUSE_RIGHT_UP");
break;
}
case SDL_BUTTON_MIDDLE:
{
mDisplayEventDispatcher.Dispatch( "MOUSE_MIDDLE_UP" );
case SDL_BUTTON_MIDDLE: {
mDisplayEventDispatcher.Dispatch("MOUSE_MIDDLE_UP");
break;
}
}
@@ -213,41 +187,41 @@ void InputController::mPollClick()
void InputController::mPollKeyboard()
{
EKeyCode keycode = KeyCodeFromSDL( mEvent.key.keysym.sym );
EKeyCode keycode = KeyCodeFromSDL(mEvent.key.keysym.sym);
Core::GenericEvent e;
e.keyCode = KeyCodeFromSDL(keycode);
if ( mEvent.key.state == SDL_PRESSED )
if (mEvent.key.state == SDL_PRESSED)
{
e.Type = "KEYBOARD_KEYDOWN";
}
else if ( mEvent.key.state == SDL_RELEASED )
else if (mEvent.key.state == SDL_RELEASED)
{
e.Type = "KEYBOARD_KEYUP";
}
uint16_t mods = mEvent.key.keysym.mod;
e.keyMods = mods;
mModKeyState = mods;
mKeyboardEventDispatcher.Dispatch( e );
mKeyboardEventDispatcher.Dispatch(e);
}
void InputController::mPollScanKeyboard()
{
//this is naive, can be optimised with double buffering
for ( int i = 0; i < mNumScancodes; i++ )
// this is naive, can be optimised with double buffering
for (int i = 0; i < mNumScancodes; i++)
{
bool isKeyPressed = (bool)mKbdState[i];
if ( isKeyPressed )
if (isKeyPressed)
{
EKeyCode whatKeyPressed = KeyCodeFromScanCode( (SDL_Scancode)i );
EKeyCode whatKeyPressed = KeyCodeFromScanCode((SDL_Scancode)i);
Core::GenericEvent e;
e.keyCode = whatKeyPressed;
e.keyMods = mModKeyState;
e.Type = "KEYBOARD_KEYPRESS";
mKeyboardEventDispatcher.Dispatch( e );
mKeyboardEventDispatcher.Dispatch(e);
}
}
}

View File

View File

0
Aeon/Rendering/Mesh.cpp Normal file
View File

0
Aeon/Rendering/Mesh.hpp Normal file
View File

View File

@@ -11,12 +11,13 @@ namespace Rendering
class RenderMaster : public Helpers::Singleton<Rendering::RenderMaster>
{
public:
RenderMaster();
RenderMaster();
void QueueRenderable(Renderable* renderable);
void QueueRenderable( Renderable* renderable );
};
}
} // namespace Rendering
#endif

View File

View File

@@ -1,197 +0,0 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#.rst:
# FindSDL2
# -------
#
# Locate SDL2 library
#
# This module defines
#
# ::
#
# SDL2_LIBRARY, the name of the library to link against
# SDL2_FOUND, if false, do not try to link to SDL
# SDL2_INCLUDE_DIR, where to find SDL.h
# SDL2_VERSION_STRING, human-readable string containing the version of SDL
#
#
#
# This module responds to the flag:
#
# ::
#
# SDL2_BUILDING_LIBRARY
# If this is defined, then no SDL2_main will be linked in because
# only applications need main().
# Otherwise, it is assumed you are building an application and this
# module will attempt to locate and set the proper link flags
# as part of the returned SDL2_LIBRARY variable.
#
#
#
# Don't forget to include SDLmain.h and SDLmain.m your project for the
# OS X framework based version. (Other versions link to -lSDLmain which
# this module will try to find on your behalf.) Also for OS X, this
# module will automatically add the -framework Cocoa on your behalf.
#
#
#
# Additional Note: If you see an empty SDL2_LIBRARY_TEMP in your
# configuration and no SDL2_LIBRARY, it means CMake did not find your SDL
# library (SDL.dll, libsdl.so, SDL.framework, etc). Set
# SDL2_LIBRARY_TEMP to point to your SDL library, and configure again.
# Similarly, if you see an empty SDLMAIN_LIBRARY, you should set this
# value as appropriate. These values are used to generate the final
# SDL2_LIBRARY variable, but when these values are unset, SDL2_LIBRARY
# does not get created.
#
#
#
# $SDL2DIR is an environment variable that would correspond to the
# ./configure --prefix=$SDL2DIR used in building SDL. l.e.galup 9-20-02
#
# Modified by Eric Wing. Added code to assist with automated building
# by using environmental variables and providing a more
# controlled/consistent search behavior. Added new modifications to
# recognize OS X frameworks and additional Unix paths (FreeBSD, etc).
# Also corrected the header search path to follow "proper" SDL
# guidelines. Added a search for SDLmain which is needed by some
# platforms. Added a search for threads which is needed by some
# platforms. Added needed compile switches for MinGW.
#
# On OSX, this will prefer the Framework version (if found) over others.
# People will have to manually change the cache values of SDL2_LIBRARY to
# override this selection or set the CMake environment
# CMAKE_INCLUDE_PATH to modify the search paths.
#
# Note that the header path has changed from SDL/SDL.h to just SDL.h
# This needed to change because "proper" SDL convention is #include
# "SDL.h", not <SDL/SDL.h>. This is done for portability reasons
# because not all systems place things in SDL/ (see FreeBSD).
if(NOT SDL2_DIR)
set(SDL2_DIR "" CACHE PATH "SDL2 directory")
endif()
find_path(SDL2_INCLUDE_DIR SDL.h
HINTS
ENV SDL2DIR
${SDL2_DIR}
PATH_SUFFIXES SDL2
# path suffixes to search inside ENV{SDL2DIR}
include/SDL2 include
)
# AWLAYS 64 bit
set(VC_LIB_PATH_SUFFIX lib/x64)
find_library(SDL2_LIBRARY_TEMP
NAMES SDL2
HINTS
ENV SDL2DIR
${SDL2_DIR}
PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX}
)
# Hide this cache variable from the user, it's an internal implementation
# detail. The documented library variable for the user is SDL2_LIBRARY
# which is derived from SDL2_LIBRARY_TEMP further below.
set_property(CACHE SDL2_LIBRARY_TEMP PROPERTY TYPE INTERNAL)
if(NOT SDL2_BUILDING_LIBRARY)
if(NOT SDL2_INCLUDE_DIR MATCHES ".framework")
# Non-OS X framework versions expect you to also dynamically link to
# SDLmain. This is mainly for Windows and OS X. Other (Unix) platforms
# seem to provide SDLmain for compatibility even though they don't
# necessarily need it.
find_library(SDL2MAIN_LIBRARY
NAMES SDL2main
HINTS
ENV SDL2DIR
${SDL2_DIR}
PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX}
PATHS
/sw
/opt/local
/opt/csw
/opt
)
endif()
endif()
# SDL may require threads on your system.
# The Apple build may not need an explicit flag because one of the
# frameworks may already provide it.
# But for non-OSX systems, I will use the CMake Threads package.
if(NOT APPLE)
find_package(Threads)
endif()
# MinGW needs an additional link flag, -mwindows
# It's total link flags should look like -lmingw32 -lSDLmain -lSDL -mwindows
if(MINGW)
set(MINGW32_LIBRARY mingw32 "-mwindows" CACHE STRING "link flags for MinGW")
endif()
if(SDL2_LIBRARY_TEMP)
# For SDLmain
if(SDL2MAIN_LIBRARY AND NOT SDL2_BUILDING_LIBRARY)
list(FIND SDL2_LIBRARY_TEMP "${SDLMAIN_LIBRARY}" _SDL2_MAIN_INDEX)
if(_SDL2_MAIN_INDEX EQUAL -1)
set(SDL2_LIBRARY_TEMP "${SDLMAIN_LIBRARY}" ${SDL2_LIBRARY_TEMP})
endif()
unset(_SDL2_MAIN_INDEX)
endif()
# For OS X, SDL uses Cocoa as a backend so it must link to Cocoa.
# CMake doesn't display the -framework Cocoa string in the UI even
# though it actually is there if I modify a pre-used variable.
# I think it has something to do with the CACHE STRING.
# So I use a temporary variable until the end so I can set the
# "real" variable in one-shot.
if(APPLE)
set(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} "-framework Cocoa")
endif()
# For threads, as mentioned Apple doesn't need this.
# In fact, there seems to be a problem if I used the Threads package
# and try using this line, so I'm just skipping it entirely for OS X.
if(NOT APPLE)
set(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT})
endif()
# For MinGW library
if(MINGW)
set(SDL2_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_LIBRARY_TEMP})
endif()
# Set the final string here so the GUI reflects the final state.
set(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL Library can be found")
endif()
if(SDL2_INCLUDE_DIR AND EXISTS "${SDL2_INCLUDE_DIR}/SDL2_version.h")
file(STRINGS "${SDL2_INCLUDE_DIR}/SDL2_version.h" SDL2_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL2_MAJOR_VERSION[ \t]+[0-9]+$")
file(STRINGS "${SDL2_INCLUDE_DIR}/SDL2_version.h" SDL2_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL2_MINOR_VERSION[ \t]+[0-9]+$")
file(STRINGS "${SDL2_INCLUDE_DIR}/SDL2_version.h" SDL2_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL2_PATCHLEVEL[ \t]+[0-9]+$")
string(REGEX REPLACE "^#define[ \t]+SDL2_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_MAJOR "${SDL2_VERSION_MAJOR_LINE}")
string(REGEX REPLACE "^#define[ \t]+SDL2_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_MINOR "${SDL2_VERSION_MINOR_LINE}")
string(REGEX REPLACE "^#define[ \t]+SDL2_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_PATCH "${SDL2_VERSION_PATCH_LINE}")
set(SDL2_VERSION_STRING ${SDL2_VERSION_MAJOR}.${SDL2_VERSION_MINOR}.${SDL2_VERSION_PATCH})
unset(SDL2_VERSION_MAJOR_LINE)
unset(SDL2_VERSION_MINOR_LINE)
unset(SDL2_VERSION_PATCH_LINE)
unset(SDL2_VERSION_MAJOR)
unset(SDL2_VERSION_MINOR)
unset(SDL2_VERSION_PATCH)
endif()
set(SDL2_LIBRARIES ${SDL2_LIBRARY} ${SDL2MAIN_LIBRARY})
set(SDL2_INCLUDE_DIRS ${SDL2_INCLUDE_DIR})
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL
REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR
VERSION_VAR SDL2_VERSION_STRING)

View File

@@ -1,26 +0,0 @@
{
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "-DSDL2_PATH=\"C:/Users/benja/Programming/lib/SDL2-2.0.16/\"",
"buildCommandArgs": "-v",
"ctestCommandArgs": ""
},
{
"name": "x64-Release",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "-DSDL2_DIR=\"C:/Users/benja/Programming/lib/SDL2-2.0.16/\"",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x64_x64" ]
}
]
}