Skip to content

Commit bf99c0d

Browse files
committed
[update] kernel -> runtime for clarity.
1 parent 2dac3ae commit bf99c0d

5 files changed

Lines changed: 57 additions & 62 deletions

File tree

lambda/src/core/events.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub enum WindowEvent {
1818

1919
/// Kernel events are generated by the kernel itself
2020
#[derive(Debug)]
21-
pub enum KernelEvent {
21+
pub enum RuntimeEvent {
2222
Initialized,
2323
Shutdown,
2424
}
@@ -35,8 +35,8 @@ pub enum Events {
3535
event: WindowEvent,
3636
issued_at: Instant,
3737
},
38-
Kernel {
39-
event: KernelEvent,
38+
Runtime {
39+
event: RuntimeEvent,
4040
issued_at: Instant,
4141
},
4242
}

lambda/src/core/kernel.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub trait Kernel {
1+
pub trait Runtime {
22
fn on_start(&mut self);
33
fn on_stop(&mut self);
44
fn run(self);
@@ -7,13 +7,13 @@ pub trait Kernel {
77
/// Builds & executes a Runnable all in one good. This is useful for when you
88
/// don't need to execute any code in between the building & execution stage of
99
/// the runnable
10-
pub fn build_and_start_kernel<T: Default + Kernel>() {
10+
pub fn build_and_start_kernel<T: Default + Runtime>() {
1111
let app = T::default();
12-
start_kernel(app);
12+
start_runtime(app);
1313
}
1414

1515
/// Simple function for starting any prebuilt Runnable.
16-
pub fn start_kernel<T: Kernel>(mut kernel: T) {
16+
pub fn start_runtime<T: Runtime>(mut kernel: T) {
1717
kernel.on_start();
1818
kernel.run();
1919
}

lambda/src/kernels/mod.rs

Lines changed: 46 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ use lambda_platform::winit::{
1313
use crate::core::{
1414
component::RenderableComponent,
1515
events::{
16+
ComponentEvent,
1617
Events,
17-
KernelEvent,
18+
RuntimeEvent,
1819
WindowEvent,
1920
},
20-
kernel::Kernel,
21+
kernel::Runtime,
2122
render::{
2223
window::{
2324
Window,
@@ -28,14 +29,14 @@ use crate::core::{
2829
},
2930
};
3031

31-
pub struct LambdaKernelBuilder {
32+
pub struct GenericRuntimeBuilder {
3233
app_name: String,
3334
render_api: RenderContextBuilder,
3435
window_size: (u32, u32),
3536
components: Vec<Box<dyn RenderableComponent<Events>>>,
3637
}
3738

38-
impl LambdaKernelBuilder {
39+
impl GenericRuntimeBuilder {
3940
pub fn new(app_name: &str) -> Self {
4041
return Self {
4142
app_name: app_name.to_string(),
@@ -79,7 +80,7 @@ impl LambdaKernelBuilder {
7980
/// Builds a LambdaKernel equipped with Windowing, an event loop, and a
8081
/// component stack that allows components to be dynamically pushed into the
8182
/// Kernel to receive events & render access.
82-
pub fn build(self) -> LambdaKernel {
83+
pub fn build(self) -> GenericRuntime {
8384
let name = self.app_name;
8485
let mut event_loop = create_event_loop::<Events>();
8586
let (width, height) = self.window_size;
@@ -91,7 +92,7 @@ impl LambdaKernelBuilder {
9192
let component_stack = self.components;
9293
let render_api = self.render_api.build(&window);
9394

94-
return LambdaKernel {
95+
return GenericRuntime {
9596
name,
9697
event_loop,
9798
window,
@@ -104,24 +105,24 @@ impl LambdaKernelBuilder {
104105
/// A windowed and event-driven kernel that can be used to render a
105106
/// scene on the primary GPU across Windows, MacOS, and Linux at this point in
106107
/// time.
107-
pub struct LambdaKernel {
108+
pub struct GenericRuntime {
108109
name: String,
109110
event_loop: Loop<Events>,
110111
window: Window,
111112
component_stack: Vec<Box<dyn RenderableComponent<Events>>>,
112113
render_api: RenderContext,
113114
}
114115

115-
impl LambdaKernel {}
116+
impl GenericRuntime {}
116117

117-
impl Kernel for LambdaKernel {
118+
impl Runtime for GenericRuntime {
118119
/// Initiates an event loop that captures the context of the LambdaKernel
119120
/// and generates events from the windows event loop until the end of the event loops
120121
/// lifetime (Whether that be initiated intentionally or via error).
121122
fn run(self) {
122123
// Decompose Kernel components for transferring ownership to the
123124
// closure.
124-
let LambdaKernel {
125+
let GenericRuntime {
125126
mut window,
126127
mut event_loop,
127128
mut component_stack,
@@ -132,8 +133,8 @@ impl Kernel for LambdaKernel {
132133
let mut active_render_api = Some(render_api);
133134

134135
let publisher = event_loop.create_publisher();
135-
publisher.publish_event(Events::Kernel {
136-
event: KernelEvent::Initialized,
136+
publisher.publish_event(Events::Runtime {
137+
event: RuntimeEvent::Initialized,
137138
issued_at: Instant::now(),
138139
});
139140

@@ -144,8 +145,8 @@ impl Kernel for LambdaKernel {
144145
WinitEvent::WindowEvent { event, .. } => match event {
145146
WinitWindowEvent::CloseRequested => {
146147
// Issue a Shutdown event to deallocate resources and clean up.
147-
publisher.publish_event(Events::Kernel {
148-
event: KernelEvent::Shutdown,
148+
publisher.publish_event(Events::Runtime {
149+
event: RuntimeEvent::Shutdown,
149150
issued_at: Instant::now(),
150151
});
151152
}
@@ -175,39 +176,39 @@ impl Kernel for LambdaKernel {
175176
WinitWindowEvent::ReceivedCharacter(_) => {}
176177
WinitWindowEvent::Focused(_) => {}
177178
WinitWindowEvent::KeyboardInput {
178-
device_id: _,
179-
input: _,
180-
is_synthetic: _,
179+
device_id,
180+
input,
181+
is_synthetic,
181182
} => {}
182183
WinitWindowEvent::ModifiersChanged(_) => {}
183184
WinitWindowEvent::CursorMoved {
184-
device_id: _,
185-
position: _,
186-
modifiers: _,
185+
device_id,
186+
position,
187+
modifiers,
187188
} => {}
188-
WinitWindowEvent::CursorEntered { device_id: _ } => {}
189-
WinitWindowEvent::CursorLeft { device_id: _ } => {}
189+
WinitWindowEvent::CursorEntered { device_id } => {}
190+
WinitWindowEvent::CursorLeft { device_id } => {}
190191
WinitWindowEvent::MouseWheel {
191-
device_id: _,
192-
delta: _,
193-
phase: _,
194-
modifiers: _,
192+
device_id,
193+
delta,
194+
phase,
195+
modifiers,
195196
} => {}
196197
WinitWindowEvent::MouseInput {
197-
device_id: _,
198-
state: _,
199-
button: _,
200-
modifiers: _,
198+
device_id,
199+
state,
200+
button,
201+
modifiers,
201202
} => {}
202203
WinitWindowEvent::TouchpadPressure {
203-
device_id: _,
204-
pressure: _,
205-
stage: _,
204+
device_id,
205+
pressure,
206+
stage,
206207
} => {}
207208
WinitWindowEvent::AxisMotion {
208-
device_id: _,
209-
axis: _,
210-
value: _,
209+
device_id,
210+
axis,
211+
value,
211212
} => {}
212213
WinitWindowEvent::Touch(_) => {}
213214
WinitWindowEvent::ThemeChanged(_) => {}
@@ -229,24 +230,18 @@ impl Kernel for LambdaKernel {
229230
}
230231
WinitEvent::RedrawRequested(_) => {}
231232
WinitEvent::NewEvents(_) => {}
232-
WinitEvent::DeviceEvent {
233-
device_id: _,
234-
event: _,
235-
} => {}
233+
WinitEvent::DeviceEvent { device_id, event } => {}
236234
WinitEvent::UserEvent(lambda_event) => match lambda_event {
237-
Events::Kernel {
238-
event,
239-
issued_at: _,
240-
} => match event {
241-
KernelEvent::Initialized => {
235+
Events::Runtime { event, issued_at } => match event {
236+
RuntimeEvent::Initialized => {
242237
println!("Starting the kernel {}", name);
243238
for component in &mut component_stack {
244239
component.on_attach();
245240
component
246241
.on_renderer_attached(active_render_api.as_mut().unwrap());
247242
}
248243
}
249-
KernelEvent::Shutdown => {
244+
RuntimeEvent::Shutdown => {
250245
for component in &mut component_stack {
251246
component.on_detach();
252247
component
@@ -273,9 +268,11 @@ impl Kernel for LambdaKernel {
273268
});
274269
}
275270

276-
/// When the lambda kernel starts, it will attach all of the components that
277-
/// have been added to the kernel during the construction phase.
278-
fn on_start(&mut self) {}
271+
/// When the generic runtime starts, it will attach all of the components that
272+
/// have been added during the construction phase in the users code.
273+
fn on_start(&mut self) {
274+
println!("Starting the runtime {}", self.name);
275+
}
279276

280277
fn on_stop(&mut self) {
281278
println!("Stopping {}", self.name)

lambda/tests/runnables.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
use lambda;
2-
31
#[test]
42
fn lambda_runnable() {}

tools/lambda_rs_demo/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use lambda::{
77
RenderableComponent,
88
},
99
events::Events,
10-
kernel::start_kernel,
10+
kernel::start_runtime,
1111
render::{
1212
command::RenderCommand,
1313
pipeline::{
@@ -27,7 +27,7 @@ use lambda::{
2727
viewport,
2828
},
2929
},
30-
kernels::LambdaKernelBuilder,
30+
kernels::GenericRuntimeBuilder,
3131
};
3232

3333
pub struct DemoComponent {
@@ -160,7 +160,7 @@ impl Default for DemoComponent {
160160
}
161161

162162
fn main() {
163-
let kernel = LambdaKernelBuilder::new("Lambda 2D Demo")
163+
let runtime = GenericRuntimeBuilder::new("2D Triangle Demo")
164164
.with_renderer(move |render_context_builder| {
165165
return render_context_builder;
166166
})
@@ -169,5 +169,5 @@ fn main() {
169169
})
170170
.build();
171171

172-
start_kernel(kernel);
172+
start_runtime(runtime);
173173
}

0 commit comments

Comments
 (0)