summaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
Diffstat (limited to 'engine')
-rw-r--r--engine/src/windowing.rs19
1 files changed, 16 insertions, 3 deletions
diff --git a/engine/src/windowing.rs b/engine/src/windowing.rs
index fac1c62..5cb34f7 100644
--- a/engine/src/windowing.rs
+++ b/engine/src/windowing.rs
@@ -54,6 +54,8 @@ const MESSAGE_FROM_APP_QUEUE_SIZE: usize = 512;
const MESSAGE_TO_APP_QUEUE_SIZE: usize = 16; // Increase if more messages are added
+static CONTEXT_CREATED: AtomicBool = AtomicBool::new(false);
+
declare_entity!(
pub PHASE,
(
@@ -73,7 +75,10 @@ impl crate::ecs::extension::Extension for Extension
{
fn collect(self, mut collector: crate::ecs::extension::Collector<'_>)
{
- collector.add_sole(Context::default()).ok();
+ if !CONTEXT_CREATED.load(Ordering::Relaxed) {
+ collector.add_sole(Context::new()).ok();
+ }
+
collector.add_sole(Keyboard::default()).ok();
collector.add_sole(Mouse::default()).ok();
collector.add_sole(MouseButtons::default()).ok();
@@ -352,10 +357,18 @@ impl Context
}
}
-impl Default for Context
+impl Context
{
- fn default() -> Self
+ /// Returns a new windowing context.
+ ///
+ /// # Panics
+ /// Will panic if a windowing context have already been created.
+ pub fn new() -> Self
{
+ if CONTEXT_CREATED.swap(true, Ordering::Relaxed) {
+ panic!("A windowing context have already been created");
+ }
+
let message_from_app_queue = Arc::new(ArrayQueue::<MessageFromApp>::new(
MESSAGE_FROM_APP_QUEUE_SIZE,
));