diff options
23 files changed, 574 insertions, 22 deletions
diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..b7d210e --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "godot-cpp"] + path = godot-cpp + url = https://github.com/godotengine/godot-cpp + branch = 3.5 diff --git a/godot-cpp b/godot-cpp new file mode 160000 +Subproject 02333f8dae5430453dfa7abcdc8fb23338964bd diff --git a/godot/addons/blend/import_blend.gd b/godot/addons/blend/import_blend.gd new file mode 100644 index 0000000..102b1fc --- /dev/null +++ b/godot/addons/blend/import_blend.gd @@ -0,0 +1,104 @@ +# Copyright (c) 2021 K. S. Ernest (iFire) Lee and V-Sekai Contributors. +# Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. +# Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +tool +extends EditorSceneImporter + +const settings_blender_path = "filesystem/import/blend/blender_path" + +var blender_path : String + +func _init(): + if not ProjectSettings.has_setting(settings_blender_path): + ProjectSettings.set_setting(settings_blender_path, "blender") + ProjectSettings.set_initial_value(settings_blender_path, "blender") + else: + blender_path = ProjectSettings.get_setting(settings_blender_path) + var property_info = { + "name": settings_blender_path, + "type": TYPE_STRING, + "hint": PROPERTY_HINT_GLOBAL_FILE, + "hint_string": "" + } + ProjectSettings.add_property_info(property_info) + + +func _get_extensions(): + return ["blend"] + + +func _get_import_flags(): + return EditorSceneImporter.IMPORT_SCENE + + +func _import_scene(path: String, flags: int, bake_fps: int): + var import_config_file = ConfigFile.new() + import_config_file.load(path + ".import") + var compression_flags: int = import_config_file.get_value("params", "meshes/compress", 0) + # ARRAY_COMPRESS_BASE = (ARRAY_INDEX + 1) + compression_flags = compression_flags << (VisualServer.ARRAY_INDEX + 1) + if import_config_file.get_value("params", "meshes/octahedral_compression", false): + compression_flags |= VisualServer.ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION + + var path_global : String = ProjectSettings.globalize_path(path) + path_global = path_global.c_escape() + var output_path : String = "res://.import/" + path.get_file() + "-" + path.md5_text() + ".glb" + var output_path_global = ProjectSettings.globalize_path(output_path) + output_path_global = output_path_global.c_escape() + var stdout = [].duplicate() + var addon_path : String = blender_path + var addon_path_global = ProjectSettings.globalize_path(addon_path) + var params: PoolStringArray = [ + "filepath='%s'" % output_path_global, + "export_format='GLB'", + "export_colors=True", + "export_all_influences=False", + "export_extras=True", + "export_cameras=True", + "export_lights=True", + "export_apply=(len(bpy.data.shape_keys)==0)" + ] + var script : String = "import bpy; bpy.ops.export_scene.gltf(%s)" % params.join(",") + path_global = path_global.c_escape() + var args = PoolStringArray([ + path_global, + "--background", + "--python-expr", + script + ]) + var ret = OS.execute(addon_path_global, args, true, stdout, true) + if ret != OK: + push_error( + "Blender import failed with code=%d.\nCommand: %s\nOutput: %s" % [ + ret, + args.join(" "), + PoolStringArray(stdout).join("\n") + ] + ) + return null + + var root_node: Spatial = null + if Engine.get_version_info()["major"] <= 3 and Engine.get_version_info()["minor"] <= 3: + root_node = call("import_scene_from_other_importer", output_path, flags, bake_fps) + else: + root_node = call("import_scene_from_other_importer", output_path, flags, bake_fps, compression_flags) + return root_node diff --git a/godot/addons/blend/plugin.cfg b/godot/addons/blend/plugin.cfg new file mode 100644 index 0000000..3fe0961 --- /dev/null +++ b/godot/addons/blend/plugin.cfg @@ -0,0 +1,7 @@ +[plugin] + +name="Blend" +description="Blend Importer" +author="K. S. Ernest Lee and V-Sekai Contributors" +version="1.0.0" +script="plugin.gd" diff --git a/godot/addons/blend/plugin.gd b/godot/addons/blend/plugin.gd new file mode 100644 index 0000000..d399e67 --- /dev/null +++ b/godot/addons/blend/plugin.gd @@ -0,0 +1,35 @@ +# Copyright (c) 2021 K. S. Ernest (iFire) Lee and V-Sekai Contributors. +# Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. +# Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +tool +extends EditorPlugin + +var import_plugin + +func _enter_tree(): + import_plugin = preload("res://addons/blend/import_blend.gd").new() + add_scene_import_plugin(import_plugin) + + +func _exit_tree(): + remove_scene_import_plugin(import_plugin) + import_plugin = null diff --git a/godot/bin/networked_machine.gdnlib b/godot/bin/networked_machine.gdnlib new file mode 100644 index 0000000..b0d628e --- /dev/null +++ b/godot/bin/networked_machine.gdnlib @@ -0,0 +1,14 @@ +[general] + +singleton=false +load_once=false +symbol_prefix="godot_" +reloadable=true + +[entry] + +X11.64="res://bin/x11/libnetmachine.so" + +[dependencies] + +X11.64=[ ] diff --git a/godot/bin/networked_machine.gdns b/godot/bin/networked_machine.gdns new file mode 100644 index 0000000..10e3a5a --- /dev/null +++ b/godot/bin/networked_machine.gdns @@ -0,0 +1,8 @@ +[gd_resource type="NativeScript" load_steps=2 format=2] + +[ext_resource path="res://bin/networked_machine.gdnlib" type="GDNativeLibrary" id=1] + +[resource] +resource_name = "networked_machine" +class_name = "NetworkedMachine" +library = ExtResource( 1 ) diff --git a/godot/bin/x11/libnetmachine.so b/godot/bin/x11/libnetmachine.so Binary files differnew file mode 100755 index 0000000..c6fc078 --- /dev/null +++ b/godot/bin/x11/libnetmachine.so diff --git a/godot/project.godot b/godot/project.godot index e5bb440..9366827 100644 --- a/godot/project.godot +++ b/godot/project.godot @@ -20,6 +20,10 @@ config/icon="res://icon.png" window/vsync/use_vsync=false window/stretch/mode="2d" +[editor_plugins] + +enabled=PoolStringArray( "res://addons/blend/plugin.cfg" ) + [input] ui_accept={ @@ -125,7 +129,7 @@ move_jump={ "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":32,"unicode":0,"echo":false,"script":null) ] } -duck={ +move_duck={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":16777238,"unicode":0,"echo":false,"script":null) ] diff --git a/godot/scenes/characters/PlayerRigid.tscn b/godot/scenes/characters/PlayerRigid.tscn index 3834ef2..8f61532 100644 --- a/godot/scenes/characters/PlayerRigid.tscn +++ b/godot/scenes/characters/PlayerRigid.tscn @@ -49,7 +49,7 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.44, 0 ) keep_aspect = 0 cull_mask = 524287 fov = 90.0 -near = 0.3 +near = 0.2 far = 1449.4 [node name="UseRay" type="RayCast" parent="Head/Camera"] diff --git a/godot/scenes/machines/Cannon.tscn b/godot/scenes/machines/Cannon.tscn index 15f1467..e84f74a 100644 --- a/godot/scenes/machines/Cannon.tscn +++ b/godot/scenes/machines/Cannon.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=11 format=2] -[ext_resource path="res://scripts/machines/Cannon.gd" type="Script" id=1] +[ext_resource path="res://bin/networked_machine.gdns" type="Script" id=1] [ext_resource path="res://sounds/explode.wav" type="AudioStream" id=2] [sub_resource type="PhysicsMaterial" id=8] diff --git a/godot/scripts/characters/player_controller_new.gd b/godot/scripts/characters/player_controller_new.gd index 6aec2d9..6df88f0 100644 --- a/godot/scripts/characters/player_controller_new.gd +++ b/godot/scripts/characters/player_controller_new.gd @@ -19,6 +19,7 @@ var direction := Vector3() var move_axis := Vector2() var floorspeed := Vector3() var jumping = false +var can_jump = true onready var nav = $NavigationAgent # Walk @@ -26,22 +27,21 @@ const FLOOR_MAX_ANGLE: float = deg2rad(46.0) export(float) var jump_height = 400.0 var in_water : bool = false var swim_speed : float = 400.0 +var climb_speed : float = 5.0 # Control var controlling_machine = false #whether character is riding/controlling something var machine = null export var is_player = false #whether character is currently controlled by a player -var should_move = false var ladder_m = null #physics var player_state : PhysicsDirectBodyState var is_on_floor:bool -export(float) var acceleration = 80.0 -export(int) var walk_speed = 6 -export(float) var c_friction = 4.0 -export(float) var _airspeed_cap = 1.0 -export(float) var air_control = 1.0 +var acceleration = 80.0 +export(int) var walk_speed = 5 +var c_friction = 4.0 +var air_control = 0.3 # Called when the node enters the scene tree func _ready() -> void: @@ -174,10 +174,13 @@ func on_floor_test() -> bool: func _integrate_forces(state) -> void: player_state = state velocity = state.get_linear_velocity() - if should_move: - nav.set_velocity(velocity) - if nav.is_target_reached(): - should_move = false + for i in range(player_state.get_contact_count()): + var contact_angle_from_up : float = Vector3.UP.angle_to(player_state.get_contact_local_normal(i)) + if contact_angle_from_up > FLOOR_MAX_ANGLE and !is_on_floor: + friction = 0 + break + if i == player_state.get_contact_count() - 1: + friction = 1 # on input event func _input(event: InputEvent) -> void: @@ -191,16 +194,12 @@ func walk(_delta:float) -> void: direction = Vector3() var aim: Basis = head.get_global_transform().basis direction += -move_axis.x * aim.z + move_axis.y * aim.x - if !is_player and should_move: - direction = nav.get_next_location() - global_transform.origin - if nav.get_next_location().y - global_transform.origin.y > 0.05 and is_on_floor: - apply_central_impulse(Vector3.UP*jump_height) direction.y = 0 direction = direction.normalized() # Jump - if is_on_floor and is_player and jumping: - apply_central_impulse(Vector3.UP*jump_height) + if is_player and jumping and is_on_floor and can_jump: + jump() #max walk speed var _speed = walk_speed @@ -213,13 +212,20 @@ func walk(_delta:float) -> void: var projVel = Vector2(velocity.x-floorspeed.x,velocity.z-floorspeed.z).dot(Vector2(direction.x,direction.z)) if is_on_floor: + add_central_force(-mass*linear_velocity.normalized()*c_friction)#friction if _speed - _cspeed > 0: add_central_force (mass*Vector3(direction.x*_temp_accel, 0, direction.z*_temp_accel))#velocity.x += direction.x*_temp_accel else: add_central_force(mass*Vector3(direction.x*(_speed-projVel), 0, direction.z*(_speed-projVel))) - elif _airspeed_cap - projVel > 0: + elif 1.0 - projVel > 0: add_central_force (mass*Vector3(direction.x*_temp_accel, 0, direction.z*_temp_accel)) +func jump(): + can_jump = false + apply_central_impulse(Vector3.UP*jump_height) + yield(get_tree().create_timer(0.05),"timeout") + can_jump = true + func swim(_delta): #drag and buoyancy add_central_force(Vector3.UP*weight*1.0) @@ -255,7 +261,7 @@ func mount_ladder(target_ladder): #called each frame while climbing ladder func climb_ladder(delta): - var new_ladder_pos = ladder_m.global_transform.origin + ladder_m.global_transform.basis.y.normalized() * move_axis.x * delta + var new_ladder_pos = ladder_m.global_transform.origin + ladder_m.global_transform.basis.y.normalized() * move_axis.x * delta * climb_speed var prog = ladder_m.get_parent().get_climb_scalar(new_ladder_pos) if prog >= 0.0 and prog <= 1.0: ladder_m.global_transform.origin = new_ladder_pos diff --git a/godot/scripts/machines/Cannon.gd b/godot/scripts/machines/Cannon.gd index 6b636c5..15807bf 100644 --- a/godot/scripts/machines/Cannon.gd +++ b/godot/scripts/machines/Cannon.gd @@ -1,4 +1,4 @@ -extends "res://scripts/machines/NetworkedMachine.gd" +extends "res://bin/networked_machine.gdns" var world_ballistics = null diff --git a/godot/scripts/machines/NetworkedMachine.gd b/godot/scripts/machines/NetworkedMachineGDS.gd index 5ce5cbe..5ce5cbe 100644 --- a/godot/scripts/machines/NetworkedMachine.gd +++ b/godot/scripts/machines/NetworkedMachineGDS.gd 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 diff --git a/src/player_controller/SConstruct b/src/player_controller/SConstruct new file mode 100644 index 0000000..f4bb318 --- /dev/null +++ b/src/player_controller/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.', 'libgdexample', 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/player_controller/player_controller.h b/src/player_controller/player_controller.h new file mode 100644 index 0000000..2514f79 --- /dev/null +++ b/src/player_controller/player_controller.h @@ -0,0 +1,18 @@ +#ifndef PLAYER_CONTROLLER_H +#define PLAYER_CONTROLLER_H + +#include <Godot.hpp> +#include <RigidBody.hpp> + +namespace godot { + +class PlayerController : public RigidBody { + GODOT_CLASS(PlayerController, RigidBody) + +private: + String +public: + static void _register_methods(); + + PlayerController(); + ~PlayerController(); |
