<commit_before>// Urho3D editor scene handling

#include "Scripts/EditorSceneWindow.as"
#include "Scripts/EditorComponentWindow.as"

Scene@ editorScene;
Window@ sceneSettingsDialog;

string sceneFileName;
string sceneResourcePath;
bool sceneModified = false;
bool runPhysics = false;
bool subscribedToSceneSettingsEdits = false;
bool octreeDebug = false;
int debugGeometryMode = 0;

Component@ selectedComponent;
Entity@ selectedEntity;

void createScene()
{
    @selectedComponent = null;
    @selectedEntity = null;

    // Create a scene with default values, these will be overridden when loading scenes
    @editorScene = engine.createScene("Urho3D Editor", BoundingBox(-1000.0, 1000.0), 8, true);

    // Always pause the scene for now
    editorScene.setPaused(true);

    if (sceneWindow !is null)
    {
        updateSceneWindow(false);
        updateComponentWindow();
    }

    runPhysics = false;
    sceneFileName = "";
    updateWindowTitle();
    createCamera();

    subscribeToEvent("PostRenderUpdate", "scenePostRenderUpdate");
    subscribeToEvent("UIMouseClick", "sceneMouseClick");
    
    engine.setDefaultScene(editorScene);
    
    updateSceneSettingsDialog();
}

void createSceneSettingsDialog()
{
    if (sceneSettingsDialog !is null)
        return;
    
    @sceneSettingsDialog = ui.loadLayout(cache.getResource("XMLFile", "UI/SceneSettingsDialog.xml"), uiStyle);
    uiRoot.addChild(sceneSettingsDialog);
    centerDialog(sceneSettingsDialog);
    updateSceneSettingsDialog();
    hideSceneSettingsDialog();
}

void updateSceneSettingsDialog()
{
    if (sceneSettingsDialog is null)
        return;
        
    // Fill the current values and subscribe to changes
    LineEdit@ octreeMinEdit = sceneSettingsDialog.getChild("OctreeMinEdit", true);
    octreeMinEdit.setText(editorScene.getOctree().getWorldBoundingBox().min.toString());
    
    LineEdit@ octreeMaxEdit = sceneSettingsDialog.getChild("OctreeMaxEdit", true);
    octreeMaxEdit.setText(editorScene.getOctree().getWorldBoundingBox().max.toString());
    
    LineEdit@ octreeLevelsEdit = sceneSettingsDialog.getChild("OctreeLevelsEdit", true);
    octreeLevelsEdit.setText(toString(editorScene.getOctree().getNumLevels()));
    
    LineEdit@ gravityEdit = sceneSettingsDialog.getChild("GravityEdit", true);
    gravityEdit.setText(editorScene.getPhysicsWorld().getGravity().toString());
    
    if (!subscribedToSceneSettingsEdits)
    {
        subscribeToEvent(octreeMinEdit, "TextFinished", "editOctreeMin");
        subscribeToEvent(octreeMaxEdit, "TextFinished", "editOctreeMax");
        subscribeToEvent(octreeLevelsEdit, "TextFinished", "editOctreeLevels");
        subscribeToEvent(gravityEdit, "TextFinished", "editGravity");
        subscribeToEvent(sceneSettingsDialog.getChild("CloseButton", true), "Released", "hideSceneSettingsDialog");
        subscribedToSceneSettingsEdits = true;
    }
}

void showSceneSettingsDialog()
{
    sceneSettingsDialog.setVisible(true);
    sceneSettingsDialog.bringToFront();
}

void hideSceneSettingsDialog()
{
    sceneSettingsDialog.setVisible(false);
}

void editOctreeMin(StringHash eventType, VariantMap& eventData)
{
    Octree@ octree = editorScene.getOctree();
    LineEdit@ edit = eventData["Element"].getUIElement();
    BoundingBox box = octree.getWorldBoundingBox();
    box.min = edit.getText().toVector3();
    edit.setText(box.min.toString());
    
    octree.resize(box, octree.getNumLevels());
}

void editOctreeMax(StringHash eventType, VariantMap& eventData)
{
    Octree@ octree = editorScene.getOctree();
    LineEdit@ edit = eventData["Element"].getUIElement();
    BoundingBox box = octree.getWorldBoundingBox();
    box.max = edit.getText().toVector3();
    edit.setText(box.max.toString());
    
    octree.resize(box, octree.getNumLevels());
}

void editOctreeLevels(StringHash eventType, VariantMap& eventData)
{
    Octree@ octree = editorScene.getOctree();
    LineEdit@ edit = eventData["Element"].getUIElement();
    octree.resize(octree.getWorldBoundingBox(), edit.getText().toInt());
    edit.setText(toString(octree.getNumLevels()));
}

void editGravity(StringHash eventType, VariantMap& eventData)
{
    LineEdit@ edit = eventData["Element"].getUIElement();
    editorScene.getPhysicsWorld().setGravity(edit.getText().toVector3());
    edit.setText(editorScene.getPhysicsWorld().getGravity().toString());
}

void setResourcePath(string newPath)
{
    if (newPath == sceneResourcePath)
        return;

    cache.releaseAllResources(false);

    // Remove the old scene resource path if any. However make sure that CoreData path never gets removed
    if ((!sceneResourcePath.empty()) && (sceneResourcePath.find("CoreData") < 0))
        cache.removeResourcePath(sceneResourcePath);

    cache.addResourcePath(newPath);
    sceneResourcePath = newPath;
}

void reloadResources()
{
    array<Resource@> sceneResources = editorScene.getResourceRefs();
    uint numResources = sceneResources.size();
    for (uint i = 0; i < numResources; ++i)
    {
        // Material textures are not listed by getResourceRefs(), so have to handle them manually
        Material@ mat = cast<Material>(sceneResources[i]);
        if (mat !is null)
        {
            for (uint j = 0; j < mat.getNumTechniques(); ++j)
            {
                MaterialTechnique@ tech = mat.getTechnique(j);
                for (int k = 0; k < MAX_MATERIAL_TEXTURE_UNITS; ++k)
                {
                    Texture@ tex = tech.getTexture(TextureUnit(k));
                    if (tex !is null)
                    {
                        bool found = false;
                        for (uint l = numResources; l < sceneResources.size(); ++l)<commit_msg>Skip physics collisionshape reloading, which causes crash at the moment.<commit_after>// Urho3D editor scene handling

#include "Scripts/EditorSceneWindow.as"
#include "Scripts/EditorComponentWindow.as"

Scene@ editorScene;
Window@ sceneSettingsDialog;

string sceneFileName;
string sceneResourcePath;
bool sceneModified = false;
bool runPhysics = false;
bool subscribedToSceneSettingsEdits = false;
bool octreeDebug = false;
int debugGeometryMode = 0;

Component@ selectedComponent;
Entity@ selectedEntity;

void createScene()
{
    @selectedComponent = null;
    @selectedEntity = null;

    // Create a scene with default values, these will be overridden when loading scenes
    @editorScene = engine.createScene("Urho3D Editor", BoundingBox(-1000.0, 1000.0), 8, true);

    // Always pause the scene for now
    editorScene.setPaused(true);

    if (sceneWindow !is null)
    {
        updateSceneWindow(false);
        updateComponentWindow();
    }

    runPhysics = false;
    sceneFileName = "";
    updateWindowTitle();
    createCamera();

    subscribeToEvent("PostRenderUpdate", "scenePostRenderUpdate");
    subscribeToEvent("UIMouseClick", "sceneMouseClick");
    
    engine.setDefaultScene(editorScene);
    
    updateSceneSettingsDialog();
}

void createSceneSettingsDialog()
{
    if (sceneSettingsDialog !is null)
        return;
    
    @sceneSettingsDialog = ui.loadLayout(cache.getResource("XMLFile", "UI/SceneSettingsDialog.xml"), uiStyle);
    uiRoot.addChild(sceneSettingsDialog);
    centerDialog(sceneSettingsDialog);
    updateSceneSettingsDialog();
    hideSceneSettingsDialog();
}

void updateSceneSettingsDialog()
{
    if (sceneSettingsDialog is null)
        return;
        
    // Fill the current values and subscribe to changes
    LineEdit@ octreeMinEdit = sceneSettingsDialog.getChild("OctreeMinEdit", true);
    octreeMinEdit.setText(editorScene.getOctree().getWorldBoundingBox().min.toString());
    
    LineEdit@ octreeMaxEdit = sceneSettingsDialog.getChild("OctreeMaxEdit", true);
    octreeMaxEdit.setText(editorScene.getOctree().getWorldBoundingBox().max.toString());
    
    LineEdit@ octreeLevelsEdit = sceneSettingsDialog.getChild("OctreeLevelsEdit", true);
    octreeLevelsEdit.setText(toString(editorScene.getOctree().getNumLevels()));
    
    LineEdit@ gravityEdit = sceneSettingsDialog.getChild("GravityEdit", true);
    gravityEdit.setText(editorScene.getPhysicsWorld().getGravity().toString());
    
    if (!subscribedToSceneSettingsEdits)
    {
        subscribeToEvent(octreeMinEdit, "TextFinished", "editOctreeMin");
        subscribeToEvent(octreeMaxEdit, "TextFinished", "editOctreeMax");
        subscribeToEvent(octreeLevelsEdit, "TextFinished", "editOctreeLevels");
        subscribeToEvent(gravityEdit, "TextFinished", "editGravity");
        subscribeToEvent(sceneSettingsDialog.getChild("CloseButton", true), "Released", "hideSceneSettingsDialog");
        subscribedToSceneSettingsEdits = true;
    }
}

void showSceneSettingsDialog()
{
    sceneSettingsDialog.setVisible(true);
    sceneSettingsDialog.bringToFront();
}

void hideSceneSettingsDialog()
{
    sceneSettingsDialog.setVisible(false);
}

void editOctreeMin(StringHash eventType, VariantMap& eventData)
{
    Octree@ octree = editorScene.getOctree();
    LineEdit@ edit = eventData["Element"].getUIElement();
    BoundingBox box = octree.getWorldBoundingBox();
    box.min = edit.getText().toVector3();
    edit.setText(box.min.toString());
    
    octree.resize(box, octree.getNumLevels());
}

void editOctreeMax(StringHash eventType, VariantMap& eventData)
{
    Octree@ octree = editorScene.getOctree();
    LineEdit@ edit = eventData["Element"].getUIElement();
    BoundingBox box = octree.getWorldBoundingBox();
    box.max = edit.getText().toVector3();
    edit.setText(box.max.toString());
    
    octree.resize(box, octree.getNumLevels());
}

void editOctreeLevels(StringHash eventType, VariantMap& eventData)
{
    Octree@ octree = editorScene.getOctree();
    LineEdit@ edit = eventData["Element"].getUIElement();
    octree.resize(octree.getWorldBoundingBox(), edit.getText().toInt());
    edit.setText(toString(octree.getNumLevels()));
}

void editGravity(StringHash eventType, VariantMap& eventData)
{
    LineEdit@ edit = eventData["Element"].getUIElement();
    editorScene.getPhysicsWorld().setGravity(edit.getText().toVector3());
    edit.setText(editorScene.getPhysicsWorld().getGravity().toString());
}

void setResourcePath(string newPath)
{
    if (newPath == sceneResourcePath)
        return;

    cache.releaseAllResources(false);

    // Remove the old scene resource path if any. However make sure that CoreData path never gets removed
    if ((!sceneResourcePath.empty()) && (sceneResourcePath.find("CoreData") < 0))
        cache.removeResourcePath(sceneResourcePath);

    cache.addResourcePath(newPath);
    sceneResourcePath = newPath;
}

void reloadResources()
{
    array<Resource@> sceneResources = editorScene.getResourceRefs();
    uint numResources = sceneResources.size();
    for (uint i = 0; i < numResources; ++i)
    {
        // For now, skip physics for safety
        // (Rigidbodies would need to be informed of the ODE collisionshape being blown away from under their feet)
        if (sceneResources[i].getTypeName() == "CollisionShape")
            continue;
        
        // Material textures are not listed by getResourceRefs(), so have to handle them manually
        Material@ mat = cast<Material>(sceneResources[i]);
        if (mat !is null)
        {
            for (uint j = 0; j < mat.getNumTechniques(); ++j)
            {
                MaterialTechnique@ tech = mat.getTechnique(j);
                for (int k = 0; k < MAX_MATERIAL_TEXTURE_UNITS; ++k)
                {
                    Texture@ tex = tech.getTexture(TextureUnit(k));
                    if (tex !is null)
                    {
                        bool found = false;
                        for (uint l = numResources; l < sceneResources.size(); ++l)
{'fraction_non_alphanumeric': 0.11440497487009114, 'fraction_numerical': 0.0035778175313059034, 'mean_word_length': 3.841237113402062, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7640720', 'n_tokens_mistral': 3444, 'n_tokens_neox': 3316, 'n_words': 689}