IceShard 1
A personal game engine project, with development focused on 2D/2.5D games.
Loading...
Searching...
No Matches
module_negotiator.hxx
Go to the documentation of this file.
1
3
4#pragma once
6#include <ice/module_info.hxx>
8
9namespace ice
10{
11
12 using ice::concepts::ModuleNegotiator;
13
17 {
20 using FnModuleInAppContext = bool(*)(
21 ice::ModuleNegotiatorAPIContext*
22 ) noexcept;
23
27 using FnModuleSelectAPIs = bool (*)(
28 ice::ModuleNegotiatorAPIContext*,
29 ice::StringID_Hash api_name,
30 ice::u32 api_version,
31 ice::ModuleAPI* out_array,
32 ice::u32* inout_array_size
33 ) noexcept;
34
37 using FnModuleRegisterAPI = bool (*)(
38 ice::ModuleNegotiatorAPIContext*,
39 ice::StringID_Hash api_name,
40 ice::FnModuleSelectAPI* fn_api_selector
41 ) noexcept;
42
46 };
47
51 {
52 public:
55 ice::ModuleNegotiatorAPIContext* negotiator_context
56 ) noexcept;
57
59 bool from_app() const noexcept;
60
63 ice::StringID_Arg api_name,
64 ice::u32 api_version,
65 ice::ModuleAPI* out_array,
66 ice::u32* inout_array_size
67 ) const noexcept override;
68
71 ice::StringID_Arg api_name,
72 ice::FnModuleSelectAPI* fn_api_selector
73 ) const noexcept;
74
75 public:
77 ice::ModuleNegotiatorAPIContext* negotiator_context;
78 };
79
80 template<typename Tag>
82 {
83 public:
87
91 template<typename T> requires(ice::concepts::APIType<T>)
92 bool register_api(ice::ProcAPIQuickRegisterFunc<T> register_func) const noexcept;
93 };
94
102
103 template<typename Tag>
104 template<typename T> requires(ice::concepts::APIType<T>)
106 {
107 static T api_struct = [](ice::ProcAPIQuickRegisterFunc<T> func) noexcept
108 {
109 T result_struct;
110 func(result_struct);
111 return result_struct;
112 }(register_func);
113
114 return register_api(
115 T::Constant_APIName,
116 [](ice::StringID_Hash name, ice::u32 version, ice::ModuleAPI* api_ptr) noexcept -> bool
117 {
118 if (name == T::Constant_APIName && version == T::Constant_APIVersion)
119 {
120 api_ptr->api_ptr = &api_struct;
121 api_ptr->version = T::Constant_APIVersion;
123 {
124 api_ptr->priority = T::Constant_APIPriority;
125 }
126 else
127 {
128 api_ptr->priority = 100;
129 }
130 return true;
131 }
132 return false;
133 }
134 );
135 }
136
137} // namespace ice
ice::ModuleNegotiatorAPIContext * negotiator_context
Definition module_negotiator.hxx:77
bool query_apis(ice::StringID_Arg api_name, ice::u32 api_version, ice::ModuleAPI *out_array, ice::u32 *inout_array_size) const noexcept override
\copy ice::ModuleQuery::query_apis
ice::ModuleNegotiatorAPI * negotiator_api
Definition module_negotiator.hxx:76
ModuleNegotiatorBase(ice::ModuleNegotiatorAPI *negotiator_api, ice::ModuleNegotiatorAPIContext *negotiator_context) noexcept
Definition module_negotiator.hxx:95
bool from_app() const noexcept
bool register_api(ice::StringID_Arg api_name, ice::FnModuleSelectAPI *fn_api_selector) const noexcept
Registers an API selector function with the given API name.
Definition module_negotiator.hxx:82
bool register_api(ice::ProcAPIQuickRegisterFunc< T > register_func) const noexcept
Registers an API selector function.
Definition module_negotiator.hxx:105
ModuleNegotiatorBase(ice::ModuleNegotiatorAPI *negotiator_api, ice::ModuleNegotiatorAPIContext *negotiator_context) noexcept
Definition module_negotiator.hxx:95
Definition module_concepts.hxx:19
Definition module_concepts.hxx:12
SPDX-License-Identifier: MIT.
Definition array.hxx:12
void(*)(T &out_api) noexcept ProcAPIQuickRegisterFunc
Definition module_types.hxx:28
std::conditional_t< ice::build::Constant_StringID_DebugInfoEnabled, StringID const &, StringID > StringID_Arg
Argument type used to pass ice::StringID values to functions.
Definition stringid.hxx:23
std::uint32_t u32
Definition types.hxx:26
bool(ice::StringID_Hash, ice::u32, ice::ModuleAPI *) FnModuleSelectAPI
Definition module_types.hxx:25
Stores information about a single API entry.
Definition module_info.hxx:33
void * api_ptr
Pointer to an API structure holding functions to be called.
Definition module_info.hxx:35
ice::u32 priority
Arbitrary priority of the API. Can be used to wrap existing APIs with additional functionality.
Definition module_info.hxx:41
ice::u32 version
Version of the API.
Definition module_info.hxx:38
Negotiation API used to register and query modules for their APIs.
Definition module_negotiator.hxx:17
bool(*)( ice::ModuleNegotiatorAPIContext *) noexcept FnModuleInAppContext
Definition module_negotiator.hxx:20
FnModuleRegisterAPI fn_register_api
Definition module_negotiator.hxx:45
FnModuleSelectAPIs fn_select_apis
Definition module_negotiator.hxx:44
bool(*)( ice::ModuleNegotiatorAPIContext *, ice::StringID_Hash api_name, ice::u32 api_version, ice::ModuleAPI *out_array, ice::u32 *inout_array_size) noexcept FnModuleSelectAPIs
Used to return API pointers into the given array.
Definition module_negotiator.hxx:27
FnModuleInAppContext fn_is_app_context
Definition module_negotiator.hxx:43
bool(*)( ice::ModuleNegotiatorAPIContext *, ice::StringID_Hash api_name, ice::FnModuleSelectAPI *fn_api_selector) noexcept FnModuleRegisterAPI
Registers an API selector function for the given API name.
Definition module_negotiator.hxx:37
Definition module_query.hxx:14
Internal hash type representing the hashed string value.
Definition stringid.hxx:34