diff options
Diffstat (limited to 'src/networked_entities')
| -rw-r--r-- | src/networked_entities/.sconsign.dblite | bin | 0 -> 24832 bytes | |||
| -rw-r--r-- | src/networked_entities/SConstruct | 109 | ||||
| -rw-r--r-- | src/networked_entities/gdlibrary.cpp | 15 | ||||
| -rw-r--r-- | src/networked_entities/gdlibrary.os | bin | 0 -> 178856 bytes | |||
| -rw-r--r-- | src/networked_entities/networked_machine.cpp | 77 | ||||
| -rw-r--r-- | src/networked_entities/networked_machine.h | 42 | ||||
| -rw-r--r-- | src/networked_entities/networked_machine.os | bin | 0 -> 258600 bytes |
7 files changed, 243 insertions, 0 deletions
diff --git a/src/networked_entities/.sconsign.dblite b/src/networked_entities/.sconsign.dblite Binary files differnew file mode 100644 index 0000000..e2d33d4 --- /dev/null +++ b/src/networked_entities/.sconsign.dblite diff --git a/src/networked_entities/SConstruct b/src/networked_entities/SConstruct new file mode 100644 index 0000000..3266173 --- /dev/null +++ b/src/networked_entities/SConstruct @@ -0,0 +1,109 @@ +#!python +import os + +opts = Variables([], ARGUMENTS) + +# Gets the standard flags CC, CCX, etc. +env = DefaultEnvironment() + +# Define our options +opts.Add(EnumVariable('target', "Compilation target", 'debug', ['d', 'debug', 'r', 'release'])) +opts.Add(EnumVariable('platform', "Compilation platform", '', ['', 'windows', 'x11', 'linux', 'osx'])) +opts.Add(EnumVariable('p', "Compilation target, alias for 'platform'", '', ['', 'windows', 'x11', 'linux', 'osx'])) +opts.Add(BoolVariable('use_llvm', "Use the LLVM / Clang compiler", 'no')) +opts.Add(PathVariable('target_path', 'The path where the lib is installed.', '../../godot/bin/')) +opts.Add(PathVariable('target_name', 'The library name.', 'libnetmachine', PathVariable.PathAccept)) + +# Local dependency paths, adapt them to your setup +godot_headers_path = "../../godot-cpp/godot-headers/" +cpp_bindings_path = "../../godot-cpp/" +cpp_library = "libgodot-cpp" + +# only support 64 at this time.. +bits = 64 + +# Updates the environment with the option variables. +opts.Update(env) + +# Process some arguments +if env['use_llvm']: + env['CC'] = 'clang' + env['CXX'] = 'clang++' + +if env['p'] != '': + env['platform'] = env['p'] + +if env['platform'] == '': + print("No valid target platform selected.") + quit(); + +# For the reference: +# - CCFLAGS are compilation flags shared between C and C++ +# - CFLAGS are for C-specific compilation flags +# - CXXFLAGS are for C++-specific compilation flags +# - CPPFLAGS are for pre-processor flags +# - CPPDEFINES are for pre-processor defines +# - LINKFLAGS are for linking flags + +# Check our platform specifics +if env['platform'] == "osx": + env['target_path'] += 'osx/' + cpp_library += '.osx' + env.Append(CCFLAGS=['-arch', 'x86_64']) + env.Append(CXXFLAGS=['-std=c++17']) + env.Append(LINKFLAGS=['-arch', 'x86_64']) + if env['target'] in ('debug', 'd'): + env.Append(CCFLAGS=['-g', '-O2']) + else: + env.Append(CCFLAGS=['-g', '-O3']) + +elif env['platform'] in ('x11', 'linux'): + env['target_path'] += 'x11/' + cpp_library += '.linux' + env.Append(CCFLAGS=['-fPIC']) + env.Append(CXXFLAGS=['-std=c++17']) + if env['target'] in ('debug', 'd'): + env.Append(CCFLAGS=['-g3', '-Og']) + else: + env.Append(CCFLAGS=['-g', '-O3']) + +elif env['platform'] == "windows": + env['target_path'] += 'win64/' + cpp_library += '.windows' + # This makes sure to keep the session environment variables on windows, + # that way you can run scons in a vs 2017 prompt and it will find all the required tools + env.Append(ENV=os.environ) + + env.Append(CPPDEFINES=['WIN32', '_WIN32', '_WINDOWS', '_CRT_SECURE_NO_WARNINGS']) + env.Append(CCFLAGS=['-W3', '-GR']) + env.Append(CXXFLAGS='/std:c++17') + if env['target'] in ('debug', 'd'): + env.Append(CPPDEFINES=['_DEBUG']) + env.Append(CCFLAGS=['-EHsc', '-MDd', '-ZI']) + env.Append(LINKFLAGS=['-DEBUG']) + else: + env.Append(CPPDEFINES=['NDEBUG']) + env.Append(CCFLAGS=['-O2', '-EHsc', '-MD']) + +if env['target'] in ('debug', 'd'): + cpp_library += '.debug' +else: + cpp_library += '.release' + +cpp_library += '.' + str(bits) + +# make sure our binding library is properly includes +env.Append(CPPPATH=['.', godot_headers_path, cpp_bindings_path + 'include/', cpp_bindings_path + 'include/core/', cpp_bindings_path + 'include/gen/']) +env.Append(LIBPATH=[cpp_bindings_path + 'bin/']) +env.Append(LIBS=[cpp_library]) + +# tweak this if you want to use different folders, or more folders, to store your source code in. +env.Append(CPPPATH=['./']) +sources = Glob('*.cpp') + +library = env.SharedLibrary(target=env['target_path'] + env['target_name'] , source=sources) + +Default(library) + +# Generates help for the -h scons option. +Help(opts.GenerateHelpText(env)) diff --git a/src/networked_entities/gdlibrary.cpp b/src/networked_entities/gdlibrary.cpp new file mode 100644 index 0000000..62e4a43 --- /dev/null +++ b/src/networked_entities/gdlibrary.cpp @@ -0,0 +1,15 @@ +#include "networked_machine.h" + +extern "C" void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *o) { + godot::Godot::gdnative_init(o); +} + +extern "C" void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_options *o) { + godot::Godot::gdnative_terminate(o); +} + +extern "C" void GDN_EXPORT godot_nativescript_init(void *handle) { + godot::Godot::nativescript_init(handle); + + godot::register_class<godot::NetworkedMachine>(); +} diff --git a/src/networked_entities/gdlibrary.os b/src/networked_entities/gdlibrary.os Binary files differnew file mode 100644 index 0000000..3331c13 --- /dev/null +++ b/src/networked_entities/gdlibrary.os diff --git a/src/networked_entities/networked_machine.cpp b/src/networked_entities/networked_machine.cpp new file mode 100644 index 0000000..3796f48 --- /dev/null +++ b/src/networked_entities/networked_machine.cpp @@ -0,0 +1,77 @@ +#include "networked_machine.h" + +#include <SceneTree.hpp> +#include <Viewport.hpp> +#include <PhysicsDirectBodyState.hpp> + +using namespace godot; + +void NetworkedMachine::_register_methods() { + register_method("_ready", &NetworkedMachine::_ready); + register_method("_integrate_forces", &NetworkedMachine::_integrate_forces); + register_method("relinquish_control", &NetworkedMachine::relinquish_control); + register_method("on_new_control", &NetworkedMachine::on_new_control); + register_method("on_no_control", &NetworkedMachine::on_no_control); + register_method("attack1", &NetworkedMachine::attack1); + register_method("attack2", &NetworkedMachine::attack2); + register_method("direction_input", &NetworkedMachine::direction_input); + + register_method("update_phys_transform", &NetworkedMachine::update_phys_transform, GODOT_METHOD_RPC_MODE_SYNC); + register_method("net_apply_impulse", &NetworkedMachine::net_apply_impulse, GODOT_METHOD_RPC_MODE_REMOTESYNC); + register_method("set_net_owner", &NetworkedMachine::set_net_owner, GODOT_METHOD_RPC_MODE_REMOTESYNC); +} + +NetworkedMachine::NetworkedMachine () { } + +NetworkedMachine::~NetworkedMachine () { } + +void NetworkedMachine::_init() { + in_use = false; + user = nullptr; + world = nullptr; +} + +void NetworkedMachine::_ready() { + world = (Spatial *)get_tree()->get_root()->find_node("GAMEWORLD"); +} + +void NetworkedMachine::update_phys_transform(Transform t, Vector3 lv, Vector3 av) { + set_transform(t); + set_linear_velocity(lv); + set_angular_velocity(av); +} + +void NetworkedMachine::net_apply_impulse(Vector3 impulse_v) { + apply_central_impulse(impulse_v); +} + +void NetworkedMachine::_integrate_forces(PhysicsDirectBodyState *_state) { + if(is_network_master() && get_mode() == RigidBody::MODE_RIGID) { + rpc("update_phys_transform", get_transform(), get_linear_velocity(), get_angular_velocity()); + } +} + +void NetworkedMachine::set_net_owner(int id, String char_name) { + set_network_master(id); + if (id == 1 && char_name == "NODE") { + on_no_control(); + if (user != nullptr) { + user->call("lose_machine"); + } + user = nullptr; + in_use = false; + } else { + in_use = true; + String player_path_s = String("PLAYERS/") + char_name; + NodePath player_path = NodePath(player_path_s); + user = (RigidBody *)world->get_node(player_path); + user->call("take_control_of_machine", (RigidBody *) this); + if(is_network_master()) { + on_new_control(); + } + } +} + +void NetworkedMachine::relinquish_control() { + rpc("set_net_owner", 1, "NONE"); +} diff --git a/src/networked_entities/networked_machine.h b/src/networked_entities/networked_machine.h new file mode 100644 index 0000000..573dbcc --- /dev/null +++ b/src/networked_entities/networked_machine.h @@ -0,0 +1,42 @@ +#ifndef NETWORKED_MACHINE_H +#define NETWORKED_MACHINE_H + +#include <Godot.hpp> +#include <RigidBody.hpp> + +namespace godot { + +class NetworkedMachine : public RigidBody { + GODOT_CLASS(NetworkedMachine, RigidBody) + +private: + bool in_use; + Spatial *world; + RigidBody *user; + +public: + static void _register_methods(); + + NetworkedMachine(); + ~NetworkedMachine(); + + void _ready(); + void _init(); + + void update_phys_transform(Transform t, Vector3 lv, Vector3 av); + void net_apply_impulse(Vector3 impulse_v); + void _integrate_forces(PhysicsDirectBodyState *_state); + void set_net_owner(int id, String char_name); + void relinquish_control(); + + //to be overridden + void on_new_control(); + void on_no_control(); + void attack1(); + void attack2(); + void direction_input(float _fwd, float _bwd, float _left, float _right, float _left2, float _right2); +}; + +} + +#endif diff --git a/src/networked_entities/networked_machine.os b/src/networked_entities/networked_machine.os Binary files differnew file mode 100644 index 0000000..88ba574 --- /dev/null +++ b/src/networked_entities/networked_machine.os |
