| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- // Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos.
- // All rights reserved.
- // Code licensed under the BSD License.
- // http://www.anki3d.org/LICENSE
- #pragma once
- #include <anki/util/Allocator.h>
- #include <anki/util/String.h>
- #include <anki/util/Ptr.h>
- #include <anki/core/Timestamp.h>
- #if ANKI_OS == ANKI_OS_ANDROID
- #include <android_native_app_glue.h>
- #endif
- namespace anki
- {
- #if ANKI_OS == ANKI_OS_ANDROID
- extern android_app* gAndroidApp;
- #endif
- // Forward
- class ConfigSet;
- class ThreadPool;
- class NativeWindow;
- class Input;
- class GrManager;
- class MainRenderer;
- class PhysicsWorld;
- class SceneGraph;
- class ScriptManager;
- class ResourceManager;
- class ResourceFilesystem;
- class GrManagerInterfaceImpl;
- /// The core class of the engine.
- class App
- {
- friend class GrManagerInterfaceImpl;
- public:
- /// User callback of main loop
- using UserMainLoopCallback = Error (*)(
- App& app, void* userData, Bool& quit);
- App();
- ~App();
- ANKI_USE_RESULT Error create(const ConfigSet& config,
- AllocAlignedCallback allocCb,
- void* allocCbUserData);
- F32 getTimerTick() const
- {
- return m_timerTick;
- }
- void setTimerTick(const F32 x)
- {
- m_timerTick = x;
- }
- const String& getSettingsDirectory() const
- {
- return m_settingsDir;
- }
- const String& getCacheDirectory() const
- {
- return m_cacheDir;
- }
- AllocAlignedCallback getAllocationCallback() const
- {
- return m_allocCb;
- }
- void* getAllocationCallbackData() const
- {
- return m_allocCbData;
- }
- ThreadPool& getThreadPool()
- {
- return *m_threadpool;
- }
- HeapAllocator<U8>& getAllocator()
- {
- return m_heapAlloc;
- }
- Timestamp getGlobalTimestamp() const
- {
- return m_globalTimestamp;
- }
- /// Run the main loop.
- /// @param callback The user callback to run along with the other main loop
- /// code.
- /// @param userData The data to pass to the user callback.
- ANKI_USE_RESULT Error mainLoop(
- UserMainLoopCallback callback, void* userData);
- Input& getInput()
- {
- return *m_input;
- }
- SceneGraph& getSceneGraph()
- {
- return *m_scene;
- }
- MainRenderer& getMainRenderer()
- {
- return *m_renderer;
- }
- ResourceManager& getResourceManager()
- {
- return *m_resources;
- }
- ScriptManager& getScriptManager()
- {
- return *m_script;
- }
- PhysicsWorld& getPhysicsWorld()
- {
- return *m_physics;
- }
- HeapAllocator<U8> getAllocator() const
- {
- return m_heapAlloc;
- }
- private:
- // Allocation
- AllocAlignedCallback m_allocCb;
- void* m_allocCbData;
- HeapAllocator<U8> m_heapAlloc;
- // Sybsystems
- NativeWindow* m_window = nullptr;
- Input* m_input = nullptr;
- WeakPtr<GrManagerInterfaceImpl> m_grInterface;
- GrManager* m_gr = nullptr;
- PhysicsWorld* m_physics = nullptr;
- ResourceFilesystem* m_resourceFs = nullptr;
- ResourceManager* m_resources = nullptr;
- MainRenderer* m_renderer = nullptr;
- SceneGraph* m_scene = nullptr;
- ScriptManager* m_script = nullptr;
- // Misc
- Timestamp m_globalTimestamp = 0;
- ThreadPool* m_threadpool = nullptr;
- String m_settingsDir; ///< The path that holds the configuration
- String m_cacheDir; ///< This is used as a cache
- F32 m_timerTick;
- ANKI_USE_RESULT Error createInternal(const ConfigSet& config,
- AllocAlignedCallback allocCb,
- void* allocCbUserData);
- ANKI_USE_RESULT Error initDirs();
- void cleanup();
- static void makeCurrent(void* app, void* ctx);
- static void swapWindow(void* window);
- };
- } // end namespace anki
|