Path: blob/master/modules/multiplayer/multiplayer_spawner.h
10277 views
/**************************************************************************/1/* multiplayer_spawner.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "core/templates/local_vector.h"33#include "scene/main/node.h"34#include "scene/resources/packed_scene.h"3536class MultiplayerSpawner : public Node {37GDCLASS(MultiplayerSpawner, Node);3839public:40enum {41INVALID_ID = 0xFF,42};4344private:45struct SpawnableScene {46String path;47Ref<PackedScene> cache;48};4950LocalVector<SpawnableScene> spawnable_scenes;5152HashSet<ResourceUID::ID> spawnable_ids;53NodePath spawn_path;5455struct SpawnInfo {56Variant args;57int id = INVALID_ID;58SpawnInfo(Variant p_args, int p_id) {59id = p_id;60args = p_args;61}62SpawnInfo() {}63};6465ObjectID spawn_node;66HashMap<ObjectID, SpawnInfo> tracked_nodes;67uint32_t spawn_limit = 0;68Callable spawn_function;6970void _update_spawn_node();71void _track(Node *p_node, const Variant &p_argument, int p_scene_id = INVALID_ID);72void _node_added(Node *p_node);73void _node_exit(ObjectID p_id);74void _spawn_notify(ObjectID p_id);7576Vector<String> _get_spawnable_scenes() const;77void _set_spawnable_scenes(const Vector<String> &p_scenes);7879protected:80static void _bind_methods();81void _notification(int p_what);8283#ifdef TOOLS_ENABLED84bool _set(const StringName &p_name, const Variant &p_value);85bool _get(const StringName &p_name, Variant &r_ret) const;86void _get_property_list(List<PropertyInfo> *p_list) const;87#endif88public:89PackedStringArray get_configuration_warnings() const override;9091Node *get_spawn_node() const {92return spawn_node.is_valid() ? ObjectDB::get_instance<Node>(spawn_node) : nullptr;93}9495void add_spawnable_scene(const String &p_path);96int get_spawnable_scene_count() const;97String get_spawnable_scene(int p_idx) const;98void clear_spawnable_scenes();99100NodePath get_spawn_path() const;101void set_spawn_path(const NodePath &p_path);102uint32_t get_spawn_limit() const { return spawn_limit; }103void set_spawn_limit(uint32_t p_limit) { spawn_limit = p_limit; }104void set_spawn_function(Callable p_spawn_function) { spawn_function = p_spawn_function; }105Callable get_spawn_function() const { return spawn_function; }106107const Variant get_spawn_argument(const ObjectID &p_id) const;108int find_spawnable_scene_index_from_object(const ObjectID &p_id) const;109int find_spawnable_scene_index_from_path(const String &p_path) const;110Node *spawn(const Variant &p_data = Variant());111Node *instantiate_custom(const Variant &p_data);112Node *instantiate_scene(int p_idx);113114MultiplayerSpawner() {}115};116117118