feat: started on scene management and player controller
parent
27e1f98695
commit
4d943a3440
|
@ -0,0 +1,3 @@
|
||||||
|
[gd_scene format=3 uid="uid://3qb27d8vkjku"]
|
||||||
|
|
||||||
|
[node name="Level" type="Level"]
|
|
@ -0,0 +1,27 @@
|
||||||
|
#include "entrance.hpp"
|
||||||
|
#include "level.hpp"
|
||||||
|
|
||||||
|
namespace godot {
|
||||||
|
void Entrance::_bind_methods() {}
|
||||||
|
void Entrance::_enter_tree() {
|
||||||
|
this->seek_parent_level();
|
||||||
|
if(parentLevel != nullptr) {
|
||||||
|
parentLevel->add_entrance(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Entrance::_exit_tree() {
|
||||||
|
if(parentLevel != nullptr)
|
||||||
|
parentLevel->remove_entrance(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
Level *Entrance::seek_parent_level() {
|
||||||
|
Node *current = this;
|
||||||
|
do {
|
||||||
|
current = current->get_parent();
|
||||||
|
if(Level *level = Object::cast_to<Level>(current))
|
||||||
|
return level;
|
||||||
|
} while(current != nullptr);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
#ifndef ENTRANCE_HPP
|
||||||
|
#define ENTRANCE_HPP
|
||||||
|
|
||||||
|
#include "godot_cpp/classes/node3d.hpp"
|
||||||
|
|
||||||
|
namespace godot {
|
||||||
|
class Level;
|
||||||
|
|
||||||
|
class Entrance : public Node3D {
|
||||||
|
GDCLASS(Entrance, Node3D)
|
||||||
|
static void _bind_methods();
|
||||||
|
protected:
|
||||||
|
Level *parentLevel;
|
||||||
|
public:
|
||||||
|
virtual void _enter_tree() override;
|
||||||
|
virtual void _exit_tree() override;
|
||||||
|
protected:
|
||||||
|
Level *seek_parent_level();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // !ENTRANCE_HPP
|
|
@ -0,0 +1,24 @@
|
||||||
|
#ifndef GAME_STATE_HPP
|
||||||
|
#define GAME_STATE_HPP
|
||||||
|
|
||||||
|
#include "godot_cpp/classes/node.hpp"
|
||||||
|
#include "godot_cpp/classes/packed_scene.hpp"
|
||||||
|
|
||||||
|
namespace godot {
|
||||||
|
class Level;
|
||||||
|
class Player;
|
||||||
|
|
||||||
|
class GameState : public Node {
|
||||||
|
GDCLASS(GameState, Node)
|
||||||
|
static void _bind_methods();
|
||||||
|
protected:
|
||||||
|
Level *currentLevel{nullptr};
|
||||||
|
Ref<PackedScene> firstLevel{};
|
||||||
|
|
||||||
|
Player *playerInstance{nullptr};
|
||||||
|
public:
|
||||||
|
void load_level(Ref<PackedScene> levelScene);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // !GAME_STATE_HPP
|
|
@ -0,0 +1,30 @@
|
||||||
|
#include "level.hpp"
|
||||||
|
#include "entrance.hpp"
|
||||||
|
#include "godot_cpp/variant/utility_functions.hpp"
|
||||||
|
|
||||||
|
namespace godot {
|
||||||
|
void Level::_bind_methods() {}
|
||||||
|
|
||||||
|
Transform3D Level::get_entrance(String entranceName) {
|
||||||
|
if(entrances.has(entranceName)) {
|
||||||
|
Node3D *entrance = Object::cast_to<Node3D>(this->entrances[entranceName]);
|
||||||
|
return entrance->get_global_transform();
|
||||||
|
} else {
|
||||||
|
return this->get_global_transform();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Level::add_entrance(Entrance *entrance) {
|
||||||
|
String key = entrance->get_name();
|
||||||
|
if(this->entrances.has(key))
|
||||||
|
UtilityFunctions::push_error("Attempt to register entrance ", key, " with duplicate key");
|
||||||
|
this->entrances[key] = entrance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Level::remove_entrance(Entrance *entrance) {
|
||||||
|
String key = entrance->get_name();
|
||||||
|
if(!this->entrances.has(key))
|
||||||
|
UtilityFunctions::push_error("Attempt to deregister entrance ", key, " without registering it");
|
||||||
|
this->entrances.erase(key);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
#ifndef LEVEL_HPP
|
||||||
|
#define LEVEL_HPP
|
||||||
|
|
||||||
|
#include "godot_cpp/classes/node3d.hpp"
|
||||||
|
#include "godot_cpp/variant/dictionary.hpp"
|
||||||
|
#include "godot_cpp/variant/string.hpp"
|
||||||
|
#include "godot_cpp/variant/transform3d.hpp"
|
||||||
|
|
||||||
|
namespace godot {
|
||||||
|
class Entrance;
|
||||||
|
|
||||||
|
class Level : public Node3D {
|
||||||
|
GDCLASS(Level, Node3D)
|
||||||
|
static void _bind_methods();
|
||||||
|
protected:
|
||||||
|
Dictionary entrances{};
|
||||||
|
public:
|
||||||
|
Transform3D get_entrance(String entranceName);
|
||||||
|
void add_entrance(Entrance *entrance);
|
||||||
|
void remove_entrance(Entrance *entrance);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // !LEVEL_HPP
|
|
@ -0,0 +1,13 @@
|
||||||
|
#include "player.hpp"
|
||||||
|
#include "godot_cpp/classes/animation_tree.hpp"
|
||||||
|
#include "godot_cpp/classes/node3d.hpp"
|
||||||
|
|
||||||
|
namespace godot {
|
||||||
|
void Player::_bind_methods() {}
|
||||||
|
void Player::_enter_tree() {
|
||||||
|
this->model = this->get_node<Node3D>("Model");
|
||||||
|
this->animTree = this->get_node<AnimationTree>("Model/AnimationTree");
|
||||||
|
}
|
||||||
|
void Player::_process(double deltaTime) {}
|
||||||
|
void Player::_physics_process(double deltaTime) {}
|
||||||
|
} // namespace godot
|
|
@ -0,0 +1,23 @@
|
||||||
|
#ifndef PLAYER_HPP
|
||||||
|
#define PLAYER_HPP
|
||||||
|
|
||||||
|
#include "godot_cpp/classes/animation_tree.hpp"
|
||||||
|
#include "godot_cpp/classes/character_body3d.hpp"
|
||||||
|
|
||||||
|
namespace godot {
|
||||||
|
class Player : public CharacterBody3D {
|
||||||
|
GDCLASS(Player, CharacterBody3D)
|
||||||
|
static void _bind_methods();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Node3D *model{nullptr};
|
||||||
|
AnimationTree *animTree{nullptr};
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual void _enter_tree() override;
|
||||||
|
virtual void _process(double deltaTime) override;
|
||||||
|
virtual void _physics_process(double deltaTime) override;
|
||||||
|
};
|
||||||
|
} // namespace godot
|
||||||
|
|
||||||
|
#endif // !PLAYER_HPP
|
|
@ -4,23 +4,32 @@
|
||||||
#include <godot_cpp/core/defs.hpp>
|
#include <godot_cpp/core/defs.hpp>
|
||||||
#include <godot_cpp/godot.hpp>
|
#include <godot_cpp/godot.hpp>
|
||||||
|
|
||||||
|
#include "player.hpp"
|
||||||
|
#include "level.hpp"
|
||||||
|
#include "entrance.hpp"
|
||||||
|
|
||||||
using namespace godot;
|
using namespace godot;
|
||||||
|
|
||||||
void initialize_gdextension_types(ModuleInitializationLevel p_level)
|
void initialize_gdextension_types(ModuleInitializationLevel p_level) {
|
||||||
{
|
|
||||||
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
|
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
ClassDB::register_class<Player>();
|
||||||
|
ClassDB::register_class<Level>();
|
||||||
|
ClassDB::register_class<Entrance>();
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C"
|
extern "C" {
|
||||||
{
|
|
||||||
// Initialization
|
// Initialization
|
||||||
GDExtensionBool GDE_EXPORT pvb_practice_init(GDExtensionInterfaceGetProcAddress p_get_proc_address, GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization)
|
GDExtensionBool GDE_EXPORT
|
||||||
{
|
pvb_practice_init(GDExtensionInterfaceGetProcAddress p_get_proc_address,
|
||||||
GDExtensionBinding::InitObject init_obj(p_get_proc_address, p_library, r_initialization);
|
GDExtensionClassLibraryPtr p_library,
|
||||||
|
GDExtensionInitialization* r_initialization) {
|
||||||
|
GDExtensionBinding::InitObject init_obj(p_get_proc_address, p_library,
|
||||||
|
r_initialization);
|
||||||
init_obj.register_initializer(initialize_gdextension_types);
|
init_obj.register_initializer(initialize_gdextension_types);
|
||||||
init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SCENE);
|
init_obj.set_minimum_library_initialization_level(
|
||||||
|
MODULE_INITIALIZATION_LEVEL_SCENE);
|
||||||
|
|
||||||
return init_obj.init();
|
return init_obj.init();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue