aboutsummaryrefslogtreecommitdiffstats
path: root/rust/src/game.rs
diff options
context:
space:
mode:
authorLibravatar David <david003@gmx.net>2022-07-15 17:33:27 +0200
committerLibravatar David <david003@gmx.net>2022-07-15 17:33:27 +0200
commita46a91e183a272e012354a6f0263299448205acb (patch)
treeb0700f933db7149c1b95afed2e04d53772f7e2dc /rust/src/game.rs
download2022-a46a91e183a272e012354a6f0263299448205acb.tar.gz
2022-a46a91e183a272e012354a6f0263299448205acb.tar.bz2
2022-a46a91e183a272e012354a6f0263299448205acb.zip
initial commit: template
Diffstat (limited to 'rust/src/game.rs')
-rw-r--r--rust/src/game.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/rust/src/game.rs b/rust/src/game.rs
new file mode 100644
index 0000000..ece5a54
--- /dev/null
+++ b/rust/src/game.rs
@@ -0,0 +1,46 @@
+use gdnative::api::*;
+use gdnative::prelude::*;
+
+/// The Game "class"
+#[derive(NativeClass)]
+#[inherit(Spatial)]
+#[register_with(Self::register_builder)]
+pub struct Game {
+ name: String,
+}
+
+// __One__ `impl` block can have the `#[methods]` attribute, which will generate
+// code to automatically bind any exported methods to Godot.
+#[methods]
+impl Game {
+ // Register the builder for methods, properties and/or signals.
+ fn register_builder(_builder: &ClassBuilder<Self>) {
+ godot_print!("Game builder is registered!");
+ }
+
+ /// The "constructor" of the class.
+ fn new(_owner: &Spatial) -> Self {
+ godot_print!("Game is created!");
+ Game {
+ name: "".to_string(),
+ }
+ }
+
+ // In order to make a method known to Godot, the #[export] attribute has to be used.
+ // In Godot script-classes do not actually inherit the parent class.
+ // Instead they are "attached" to the parent object, called the "owner".
+ // The owner is passed to every single exposed method.
+ #[export]
+ unsafe fn _ready(&mut self, _owner: &Spatial) {
+ // The `godot_print!` macro works like `println!` but prints to the Godot-editor
+ // output tab as well.
+ self.name = "Game".to_string();
+ godot_print!("{} is ready!", self.name);
+ }
+
+ // This function will be called in every frame
+ #[export]
+ unsafe fn _process(&self, _owner: &Spatial, delta: f64) {
+ godot_print!("Inside {} _process(), delta is {}", self.name, delta);
+ }
+}