Skip to content

Commit

Permalink
Merge pull request #30282 from neikeq/editor_in_cs_equals_win
Browse files Browse the repository at this point in the history
 Re-write mono module editor code in C#
  • Loading branch information
akien-mga authored Jul 5, 2019
2 parents a149e41 + 0639946 commit 6e9cb44
Show file tree
Hide file tree
Showing 97 changed files with 5,703 additions and 4,120 deletions.
4 changes: 4 additions & 0 deletions core/project_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ String ProjectSettings::localize_path(const String &p_path) const {
// `plus_file("")` is an easy way to ensure we have a trailing '/'.
const String res_path = resource_path.plus_file("");

// DirAccess::get_current_dir() is not guaranteed to return a path that with a trailing '/',
// so we must make sure we have it as well in order to compare with 'res_path'.
cwd = cwd.plus_file("");

if (!cwd.begins_with(res_path)) {
return p_path;
};
Expand Down
4 changes: 2 additions & 2 deletions core/reference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ bool Reference::reference() {
if (get_script_instance()) {
get_script_instance()->refcount_incremented();
}
if (instance_binding_count > 0) {
if (instance_binding_count > 0 && !ScriptServer::are_languages_finished()) {
for (int i = 0; i < MAX_SCRIPT_INSTANCE_BINDINGS; i++) {
if (_script_instance_bindings[i]) {
ScriptServer::get_language(i)->refcount_incremented_instance_binding(this);
Expand All @@ -91,7 +91,7 @@ bool Reference::unreference() {
bool script_ret = get_script_instance()->refcount_decremented();
die = die && script_ret;
}
if (instance_binding_count > 0) {
if (instance_binding_count > 0 && !ScriptServer::are_languages_finished()) {
for (int i = 0; i < MAX_SCRIPT_INSTANCE_BINDINGS; i++) {
if (_script_instance_bindings[i]) {
bool script_ret = ScriptServer::get_language(i)->refcount_decremented_instance_binding(this);
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ EditorSelection *EditorInterface::get_selection() {
return EditorNode::get_singleton()->get_editor_selection();
}

EditorSettings *EditorInterface::get_editor_settings() {
Ref<EditorSettings> EditorInterface::get_editor_settings() {
return EditorSettings::get_singleton();
}

Expand Down
2 changes: 1 addition & 1 deletion editor/editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class EditorInterface : public Node {

EditorSelection *get_selection();
//EditorImportExport *get_import_export();
EditorSettings *get_editor_settings();
Ref<EditorSettings> get_editor_settings();
EditorResourcePreview *get_resource_previewer();
EditorFileSystem *get_resource_file_system();

Expand Down
2 changes: 2 additions & 0 deletions editor/editor_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1579,6 +1579,8 @@ void EditorSettings::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_recent_dirs"), &EditorSettings::get_recent_dirs);

ADD_SIGNAL(MethodInfo("settings_changed"));

BIND_CONSTANT(NOTIFICATION_EDITOR_SETTINGS_CHANGED);
}

EditorSettings::EditorSettings() {
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/spatial_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class EditorSpatialGizmo : public SpatialGizmo {

void set_spatial_node(Spatial *p_node);
Spatial *get_spatial_node() const { return spatial_node; }
EditorSpatialGizmoPlugin *get_plugin() const { return gizmo_plugin; }
Ref<EditorSpatialGizmoPlugin> get_plugin() const { return gizmo_plugin; }
Vector3 get_handle_pos(int p_idx) const;
bool intersect_frustum(const Camera *p_camera, const Vector<Plane> &p_frustum);
bool intersect_ray(Camera *p_camera, const Point2 &p_point, Vector3 &r_pos, Vector3 &r_normal, int *r_gizmo_handle = NULL, bool p_sec_first = false);
Expand Down
28 changes: 20 additions & 8 deletions modules/mono/SCsub
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env python

import build_scripts.tls_configure as tls_configure
import build_scripts.mono_configure as mono_configure

Import('env')
Import('env_modules')

Expand All @@ -26,27 +29,36 @@ if env_mono['mono_glue']:

import os.path
if not os.path.isfile('glue/mono_glue.gen.cpp'):
raise RuntimeError('Missing mono glue sources. Did you forget to generate them?')
raise RuntimeError("Mono glue sources not found. Did you forget to run '--generate-mono-glue'?")

if env_mono['tools'] or env_mono['target'] != 'release':
env_mono.Append(CPPDEFINES=['GD_MONO_HOT_RELOAD'])

# Configure Thread Local Storage

import build_scripts.tls_configure as tls_configure

conf = Configure(env_mono)
tls_configure.configure(conf)
env_mono = conf.Finish()

# Configure Mono

import build_scripts.mono_configure as mono_configure

mono_configure.configure(env, env_mono)

# Build GodotSharpTools
# Build Godot API solution

if env_mono['tools'] and env_mono['mono_glue']:
import build_scripts.api_solution_build as api_solution_build
api_solution_build.build(env_mono)

import build_scripts.godotsharptools_build as godotsharptools_build
# Build GodotTools

godotsharptools_build.build(env_mono)
if env_mono['tools']:
import build_scripts.godot_tools_build as godot_tools_build
if env_mono['mono_glue']:
godot_tools_build.build(env_mono)
else:
# Building without the glue sources so the Godot API solution may be missing.
# GodotTools depends on the Godot API solution. As such, we will only build
# GodotTools.ProjectEditor which doesn't depend on the Godot API solution and
# is required by the bindings generator in order to be able to generated it.
godot_tools_build.build_project_editor_only(env_mono)
Empty file added modules/mono/__init__.py
Empty file.
66 changes: 66 additions & 0 deletions modules/mono/build_scripts/api_solution_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Build the Godot API solution

import os

from SCons.Script import Dir


def build_api_solution(source, target, env):
# source and target elements are of type SCons.Node.FS.File, hence why we convert them to str

module_dir = env['module_dir']

solution_path = os.path.join(module_dir, 'glue/Managed/Generated/GodotSharp.sln')

if not os.path.isfile(solution_path):
raise RuntimeError("Godot API solution not found. Did you forget to run '--generate-mono-glue'?")

build_config = env['solution_build_config']

extra_msbuild_args = ['/p:NoWarn=1591'] # Ignore missing documentation warnings

from .solution_builder import build_solution
build_solution(env, solution_path, build_config, extra_msbuild_args=extra_msbuild_args)

# Copy targets

core_src_dir = os.path.abspath(os.path.join(solution_path, os.pardir, 'GodotSharp', 'bin', build_config))
editor_src_dir = os.path.abspath(os.path.join(solution_path, os.pardir, 'GodotSharpEditor', 'bin', build_config))

dst_dir = os.path.abspath(os.path.join(str(target[0]), os.pardir))

if not os.path.isdir(dst_dir):
assert not os.path.isfile(dst_dir)
os.makedirs(dst_dir)

def copy_target(target_path):
from shutil import copy
filename = os.path.basename(target_path)

src_path = os.path.join(core_src_dir, filename)
if not os.path.isfile(src_path):
src_path = os.path.join(editor_src_dir, filename)

copy(src_path, target_path)

for scons_target in target:
copy_target(str(scons_target))


def build(env_mono):
assert env_mono['tools']

target_filenames = [
'GodotSharp.dll', 'GodotSharp.pdb', 'GodotSharp.xml',
'GodotSharpEditor.dll', 'GodotSharpEditor.pdb', 'GodotSharpEditor.xml'
]

for build_config in ['Debug', 'Release']:
output_dir = Dir('#bin').abspath
editor_api_dir = os.path.join(output_dir, 'GodotSharp', 'Api', build_config)

targets = [os.path.join(editor_api_dir, filename) for filename in target_filenames]

cmd = env_mono.CommandNoCache(targets, [], build_api_solution,
module_dir=os.getcwd(), solution_build_config=build_config)
env_mono.AlwaysBuild(cmd)
108 changes: 108 additions & 0 deletions modules/mono/build_scripts/godot_tools_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Build GodotTools solution

import os

from SCons.Script import Dir


def build_godot_tools(source, target, env):
# source and target elements are of type SCons.Node.FS.File, hence why we convert them to str

module_dir = env['module_dir']

solution_path = os.path.join(module_dir, 'editor/GodotTools/GodotTools.sln')
build_config = 'Debug' if env['target'] == 'debug' else 'Release'

from . solution_builder import build_solution, nuget_restore
nuget_restore(env, solution_path)
build_solution(env, solution_path, build_config)

# Copy targets

solution_dir = os.path.abspath(os.path.join(solution_path, os.pardir))

src_dir = os.path.join(solution_dir, 'GodotTools', 'bin', build_config)
dst_dir = os.path.abspath(os.path.join(str(target[0]), os.pardir))

if not os.path.isdir(dst_dir):
assert not os.path.isfile(dst_dir)
os.makedirs(dst_dir)

def copy_target(target_path):
from shutil import copy
filename = os.path.basename(target_path)
copy(os.path.join(src_dir, filename), target_path)

for scons_target in target:
copy_target(str(scons_target))


def build_godot_tools_project_editor(source, target, env):
# source and target elements are of type SCons.Node.FS.File, hence why we convert them to str

module_dir = env['module_dir']

project_name = 'GodotTools.ProjectEditor'

csproj_dir = os.path.join(module_dir, 'editor/GodotTools', project_name)
csproj_path = os.path.join(csproj_dir, project_name + '.csproj')
build_config = 'Debug' if env['target'] == 'debug' else 'Release'

from . solution_builder import build_solution, nuget_restore

# Make sure to restore NuGet packages in the project directory for the project to find it
nuget_restore(env, os.path.join(csproj_dir, 'packages.config'), '-PackagesDirectory',
os.path.join(csproj_dir, 'packages'))

build_solution(env, csproj_path, build_config)

# Copy targets

src_dir = os.path.join(csproj_dir, 'bin', build_config)
dst_dir = os.path.abspath(os.path.join(str(target[0]), os.pardir))

if not os.path.isdir(dst_dir):
assert not os.path.isfile(dst_dir)
os.makedirs(dst_dir)

def copy_target(target_path):
from shutil import copy
filename = os.path.basename(target_path)
copy(os.path.join(src_dir, filename), target_path)

for scons_target in target:
copy_target(str(scons_target))


def build(env_mono):
assert env_mono['tools']

output_dir = Dir('#bin').abspath
editor_tools_dir = os.path.join(output_dir, 'GodotSharp', 'Tools')
editor_api_dir = os.path.join(output_dir, 'GodotSharp', 'Api', 'Debug')

source_filenames = ['GodotSharp.dll', 'GodotSharpEditor.dll']
sources = [os.path.join(editor_api_dir, filename) for filename in source_filenames]

target_filenames = ['GodotTools.dll', 'GodotTools.BuildLogger.dll', 'GodotTools.ProjectEditor.dll', 'DotNet.Glob.dll', 'GodotTools.Core.dll']

if env_mono['target'] == 'debug':
target_filenames += ['GodotTools.pdb', 'GodotTools.BuildLogger.dll', 'GodotTools.ProjectEditor.dll', 'GodotTools.Core.dll']

targets = [os.path.join(editor_tools_dir, filename) for filename in target_filenames]

cmd = env_mono.CommandNoCache(targets, sources, build_godot_tools, module_dir=os.getcwd())
env_mono.AlwaysBuild(cmd)


def build_project_editor_only(env_mono):
assert env_mono['tools']

output_dir = Dir('#bin').abspath
editor_tools_dir = os.path.join(output_dir, 'GodotSharp', 'Tools')

target_filenames = ['GodotTools.ProjectEditor.dll', 'DotNet.Glob.dll', 'GodotTools.Core.dll']
targets = [os.path.join(editor_tools_dir, filename) for filename in target_filenames]

cmd = env_mono.CommandNoCache(targets, [], build_godot_tools_project_editor, module_dir=os.getcwd())
env_mono.AlwaysBuild(cmd)
Loading

0 comments on commit 6e9cb44

Please sign in to comment.