libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
Context.h
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <memory>
5#include <mutex>
6#include <unordered_set>
7#include <vector>
8#include <unordered_map>
9#include <chrono>
10#include <stdint.h>
11#include <functional>
12#include "ship/audio/Audio.h"
13#include "ship/core/Component.h"
15
38namespace Ship {
39
63class Context : public Component {
64 public:
87 static std::shared_ptr<Context>
88 CreateDefaultInstance(const std::string& name, const std::string& shortName, const std::string& configFilePath,
89 const std::vector<std::string>& archivePaths = {},
90 const std::unordered_set<uint32_t>& validHashes = {}, uint32_t reservedThreadCount = 1,
91 AudioSettings audioSettings = {}, std::shared_ptr<Component> window = nullptr,
92 std::shared_ptr<Component> controlDeck = nullptr);
93
99 static std::shared_ptr<Context> CreateInstance(const std::string& name, const std::string& shortName);
100
114 static std::shared_ptr<Context> CreateInstance(const std::string& name, const std::string& shortName,
115 std::vector<std::shared_ptr<Component>> components);
116
121 static std::string GetAppBundlePath();
127 static std::string GetAppDirectoryPath(const std::string& appName = "");
134 static std::string GetPathRelativeToAppDirectory(const std::string& path, const std::string& appName = "");
140 static std::string GetPathRelativeToAppBundle(const std::string& path);
147 static std::string LocateFileAcrossAppDirs(const std::string& path, const std::string& appName = "");
148
154 Context(std::string name, std::string shortName);
156
158 const std::string& GetShortName() const;
159
160 // ---- TickableComponent list ----
161
164
166 double GetElapsedTimeSeconds() const;
167
170
176 void Tick(EventID eventId);
177
184 void Tick();
185
186 protected:
187 Context() = default;
188
189 private:
190 std::string mShortName;
191 std::chrono::steady_clock::time_point mInitTime{};
192 double mElapsedTimeSeconds = 0.0;
193
194 TickableList mTickableComponents;
195#ifdef COMPONENT_THREAD_SAFE
196 mutable std::mutex mTickableMutex;
197#endif
198};
199
200} // namespace Ship
int32_t EventID
Numeric identifier for an event. -1 is uninitialized, IDs < -1 are internally registered,...
Definition EventTypes.h:8
A named Part with a parent/child hierarchy and optional thread safety.
Definition Component.h:34
Central singleton context for the libultraship engine.
Definition Context.h:63
static std::shared_ptr< Context > CreateDefaultInstance(const std::string &name, const std::string &shortName, const std::string &configFilePath, const std::vector< std::string > &archivePaths={}, const std::unordered_set< uint32_t > &validHashes={}, uint32_t reservedThreadCount=1, AudioSettings audioSettings={}, std::shared_ptr< Component > window=nullptr, std::shared_ptr< Component > controlDeck=nullptr)
Creates and stores the global Context instance with the default set of components.
static std::shared_ptr< Context > CreateInstance(const std::string &name, const std::string &shortName, std::vector< std::shared_ptr< Component > > components)
Creates and stores the global Context instance with the given set of components.
static std::string GetPathRelativeToAppBundle(const std::string &path)
Resolves a path relative to the application bundle directory.
void Tick()
Runs the default frame sequence: Update, LateUpdate, then Draw.
static std::shared_ptr< Context > CreateInstance(const std::string &name, const std::string &shortName)
Creates and stores the global Context instance without adding any default components.
Context(std::string name, std::string shortName)
Constructs a Context with the given identifiers but does not initialize subsystems.
const TickableList & GetTickableComponents() const
const std::string & GetShortName() const
Returns the short application identifier.
Context()=default
double GetElapsedTimeSeconds() const
Returns elapsed time in seconds since this Context was initialized.
static std::string LocateFileAcrossAppDirs(const std::string &path, const std::string &appName="")
Searches common application directories for a file and returns its absolute path.
static std::string GetAppBundlePath()
Returns the platform-specific application bundle directory (e.g. the .app bundle on macOS).
static std::string GetAppDirectoryPath(const std::string &appName="")
Returns the platform-specific directory where the application stores its data.
static std::string GetPathRelativeToAppDirectory(const std::string &path, const std::string &appName="")
Resolves a path relative to the application data directory.
void UpdateElapsedTimeSeconds()
Recomputes elapsed time in seconds since this Context was initialized.
TickableList & GetTickableComponents()
void Tick(EventID eventId)
Drives one frame of all registered TickableComponents for a specific EventID.
Extends PartList<TickableComponent> with order-aware sorting.
Definition TickableList.h:18
Core namespace for the libultraship engine framework.
Definition gfx_direct3d_common.h:14