Add Application base classes (WIP)
This commit is contained in:
parent
67320e02e9
commit
04bfa97579
|
|
@ -32,6 +32,7 @@
|
|||
#include <Nazara/Core/AbstractHash.hpp>
|
||||
#include <Nazara/Core/AbstractLogger.hpp>
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/Application.hpp>
|
||||
#include <Nazara/Core/ByteArray.hpp>
|
||||
#include <Nazara/Core/ByteArrayPool.hpp>
|
||||
#include <Nazara/Core/ByteStream.hpp>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_APPLICATION_HPP
|
||||
#define NAZARA_CORE_APPLICATION_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/ApplicationComponent.hpp>
|
||||
#include <Nazara/Core/Clock.hpp>
|
||||
#include <atomic>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CORE_API Application
|
||||
{
|
||||
public:
|
||||
inline Application();
|
||||
inline Application(int argc, char** argv);
|
||||
Application(int argc, const char** argv);
|
||||
Application(const Application&) = delete;
|
||||
Application(Application&&) = delete;
|
||||
~Application() = default;
|
||||
|
||||
template<typename T, typename... Args> T& AddComponent(Args&&... args);
|
||||
inline void AddComponent(std::unique_ptr<ApplicationComponent>&& component);
|
||||
|
||||
int Run();
|
||||
|
||||
inline void Quit();
|
||||
|
||||
void Update(Time elapsedTime);
|
||||
|
||||
Application& operator=(const Application&) = delete;
|
||||
Application& operator=(Application&&) = delete;
|
||||
|
||||
private:
|
||||
std::atomic_bool m_running;
|
||||
std::vector<ApplicationComponent> m_components;
|
||||
HighPrecisionClock m_clock;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/Application.inl>
|
||||
|
||||
#endif // NAZARA_CORE_APPLICATION_HPP
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Application.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template<typename T, typename ...Args>
|
||||
T& Nz::Application::AddComponent(Args&& ...args)
|
||||
{
|
||||
std::unique_ptr<T> component = std::make_unique<T>(std::forward<Args>(args)...);
|
||||
T& componentRef = *component;
|
||||
AddComponent(std::move(component));
|
||||
|
||||
return componentRef;
|
||||
}
|
||||
|
||||
inline Application::Application() :
|
||||
Application(0, static_cast<const char**>(nullptr))
|
||||
{
|
||||
}
|
||||
|
||||
inline Application::Application(int argc, char** argv) :
|
||||
Application(argc, static_cast<const char**>(argv))
|
||||
{
|
||||
}
|
||||
|
||||
void Application::AddComponent(std::unique_ptr<ApplicationComponent>&& component)
|
||||
{
|
||||
m_components.emplace_back(std::move(component));
|
||||
}
|
||||
|
||||
inline void Application::Quit()
|
||||
{
|
||||
m_running = false;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_APPLICATIONCOMPONENT_HPP
|
||||
#define NAZARA_CORE_APPLICATIONCOMPONENT_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/Time.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CORE_API ApplicationComponent
|
||||
{
|
||||
public:
|
||||
ApplicationComponent() = default;
|
||||
ApplicationComponent(const ApplicationComponent&) = delete;
|
||||
ApplicationComponent(ApplicationComponent&&) = delete;
|
||||
virtual ~ApplicationComponent();
|
||||
|
||||
virtual void Update(Time elapsedTime);
|
||||
|
||||
ApplicationComponent& operator=(const ApplicationComponent&) = delete;
|
||||
ApplicationComponent& operator=(ApplicationComponent&&) = delete;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/ApplicationComponent.inl>
|
||||
|
||||
#endif // NAZARA_CORE_APPLICATIONCOMPONENT_HPP
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/ApplicationComponent.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Platform module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PLATFORM_APPWINDOWINGCOMPONENT_HPP
|
||||
#define NAZARA_PLATFORM_APPWINDOWINGCOMPONENT_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/ApplicationComponent.hpp>
|
||||
#include <Nazara/Platform/Config.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_PLATFORM_API AppWindowingComponent : public ApplicationComponent
|
||||
{
|
||||
public:
|
||||
AppWindowingComponent() = default;
|
||||
AppWindowingComponent(const AppWindowingComponent&) = delete;
|
||||
AppWindowingComponent(AppWindowingComponent&&) = delete;
|
||||
~AppWindowingComponent() = default;
|
||||
|
||||
void Update(Time elapsedTime) override;
|
||||
|
||||
AppWindowingComponent& operator=(const AppWindowingComponent&) = delete;
|
||||
AppWindowingComponent& operator=(AppWindowingComponent&&) = delete;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Platform/AppWindowingComponent.inl>
|
||||
|
||||
#endif // NAZARA_PLATFORM_APPWINDOWINGCOMPONENT_HPP
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Platform module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Platform/AppWindowingComponent.hpp>
|
||||
#include <Nazara/Platform/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/Platform/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Application.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
Application::Application(int argc, const char** argv) :
|
||||
m_running(true)
|
||||
{
|
||||
}
|
||||
|
||||
int Application::Run()
|
||||
{
|
||||
// Ignore time between creation and Run() call
|
||||
m_clock.Restart();
|
||||
|
||||
while (m_running)
|
||||
{
|
||||
Time elapsedTime = m_clock.Restart();
|
||||
Update(elapsedTime);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Application::Update(Time elapsedTime)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/ApplicationComponent.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
ApplicationComponent::~ApplicationComponent() = default;
|
||||
|
||||
void ApplicationComponent::Update(Time elapsedTime)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Platform module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Platform/AppWindowingComponent.hpp>
|
||||
#include <Nazara/Platform/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
void AppWindowingComponent::Update(Time elapsedTime)
|
||||
{
|
||||
// SDL_PollEvent
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue