diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/3d/SCsub | 1 | ||||
-rw-r--r-- | scene/3d/car_body.cpp | 741 | ||||
-rw-r--r-- | scene/3d/car_body.h | 170 | ||||
-rw-r--r-- | scene/3d/editable_shape.cpp | 85 | ||||
-rw-r--r-- | scene/3d/editable_shape.h | 73 | ||||
-rw-r--r-- | scene/SCsub | 2 | ||||
-rw-r--r-- | scene/io/scene_format_object.cpp | 851 | ||||
-rw-r--r-- | scene/io/scene_format_object.h | 128 | ||||
-rw-r--r-- | scene/io/scene_format_script.cpp | 65 | ||||
-rw-r--r-- | scene/io/scene_format_script.h | 45 | ||||
-rw-r--r-- | scene/io/scene_loader.cpp | 161 | ||||
-rw-r--r-- | scene/io/scene_loader.h | 90 | ||||
-rw-r--r-- | scene/io/scene_saver.cpp | 94 | ||||
-rw-r--r-- | scene/io/scene_saver.h | 80 | ||||
-rw-r--r-- | scene/main/node.cpp | 1 | ||||
-rw-r--r-- | scene/register_scene_types.cpp | 56 | ||||
-rw-r--r-- | scene/resources/image_path_finder.cpp | 427 | ||||
-rw-r--r-- | scene/resources/image_path_finder.h | 84 | ||||
-rw-r--r-- | scene/resources/packed_scene.cpp | 26 | ||||
-rw-r--r-- | scene/resources/scene_preloader.cpp | 853 | ||||
-rw-r--r-- | scene/scene_binds.cpp | 55 | ||||
-rw-r--r-- | scene/scene_binds.h | 62 |
22 files changed, 459 insertions, 3691 deletions
diff --git a/scene/3d/SCsub b/scene/3d/SCsub index 6789851aab..3c2144bedc 100644 --- a/scene/3d/SCsub +++ b/scene/3d/SCsub @@ -1,7 +1,6 @@ Import('env') -print("V: "+env["disable_3d"]) if (env["disable_3d"]=="yes"): env.scene_sources.append("3d/spatial.cpp") diff --git a/scene/3d/car_body.cpp b/scene/3d/car_body.cpp deleted file mode 100644 index a21598b07c..0000000000 --- a/scene/3d/car_body.cpp +++ /dev/null @@ -1,741 +0,0 @@ -/*************************************************************************/ -/* car_body.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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. */ -/*************************************************************************/ -#include "car_body.h" - -#define DEG2RADMUL (Math_PI/180.0) -#define RAD2DEGMUL (180.0/Math_PI) - -void CarWheel::_notification(int p_what) { - - - if (p_what==NOTIFICATION_ENTER_SCENE) { - - if (!get_parent()) - return; - CarBody *cb = get_parent()->cast_to<CarBody>(); - if (!cb) - return; - body=cb; - local_xform=get_transform(); - cb->wheels.push_back(this); - } - if (p_what==NOTIFICATION_EXIT_SCENE) { - - if (!get_parent()) - return; - CarBody *cb = get_parent()->cast_to<CarBody>(); - if (!cb) - return; - cb->wheels.erase(this); - body=NULL; - } -} - -void CarWheel::set_side_friction(real_t p_friction) { - - side_friction=p_friction; -} -void CarWheel::set_forward_friction(real_t p_friction) { - - forward_friction=p_friction; -} -void CarWheel::set_travel(real_t p_travel) { - - travel=p_travel; - update_gizmo(); - -} -void CarWheel::set_radius(real_t p_radius) { - - radius=p_radius; - update_gizmo(); - -} -void CarWheel::set_resting_frac(real_t p_frac) { - - resting_frac=p_frac; -} -void CarWheel::set_damping_frac(real_t p_frac) { - - damping_frac=p_frac; -} -void CarWheel::set_num_rays(real_t p_rays) { - - num_rays=p_rays; -} - -real_t CarWheel::get_side_friction() const{ - - return side_friction; -} -real_t CarWheel::get_forward_friction() const{ - - return forward_friction; -} -real_t CarWheel::get_travel() const{ - - return travel; -} -real_t CarWheel::get_radius() const{ - - return radius; -} -real_t CarWheel::get_resting_frac() const{ - - return resting_frac; -} -real_t CarWheel::get_damping_frac() const{ - - return damping_frac; -} - -int CarWheel::get_num_rays() const{ - - return num_rays; -} - - -void CarWheel::update(real_t dt) { - - - if (dt <= 0.0f) - return; - - float origAngVel = angVel; - - if (locked) - { - angVel = 0; - torque = 0; - } - else - { - - float wheelMass = 0.03f * body->mass; - float inertia = 0.5f * (radius * radius) * wheelMass; - - angVel += torque * dt / inertia; - torque = 0; - - // prevent friction from reversing dir - todo do this better - // by limiting the torque - if (((origAngVel > angVelForGrip) && (angVel < angVelForGrip)) || - ((origAngVel < angVelForGrip) && (angVel > angVelForGrip))) - angVel = angVelForGrip; - - angVel += driveTorque * dt / inertia; - driveTorque = 0; - - float maxAngVel = 200; - print_line("angvel: "+rtos(angVel)); - angVel = CLAMP(angVel, -maxAngVel, maxAngVel); - - axisAngle += Math::rad2deg(dt * angVel); - } -} - -bool CarWheel::add_forces(PhysicsDirectBodyState *s) { - - - Vector3 force; - - PhysicsDirectSpaceState *space = s->get_space_state(); - - Transform world = s->get_transform() * local_xform; - - // OpenGl has differnet row/column order for matrixes than XNA has .. - //Vector3 wheelFwd = world.get_basis().get_axis(Vector3::AXIS_Z); - //Vector3 wheelFwd = RotationMatrix(mSteerAngle, worldAxis) * carBody.GetOrientation().GetCol(0); - Vector3 wheelUp = world.get_basis().get_axis(Vector3::AXIS_Y); - Vector3 wheelFwd = Matrix3(wheelUp,Math::deg2rad(steerAngle)).xform( world.get_basis().get_axis(Vector3::AXIS_Z) ); - Vector3 wheelLeft = -wheelUp.cross(wheelFwd).normalized(); - Vector3 worldPos = world.origin; - Vector3 worldAxis = wheelUp; - - // start of ray - float rayLen = 2.0f * radius + travel; - Vector3 wheelRayEnd = worldPos - radius * worldAxis; - Vector3 wheelRayBegin = wheelRayEnd + rayLen * worldAxis; - //wheelRayEnd = -rayLen * worldAxis; - - //Assert(PhysicsSystem.CurrentPhysicsSystem); - - - ///Assert(collSystem); - /// - const int maxNumRays = 32; - - int numRaysUse = MIN(num_rays, maxNumRays); - - // adjust the start position of the ray - divide the wheel into numRays+2 - // rays, but don't use the first/last. - float deltaFwd = (2.0f * radius) / (numRaysUse + 1); - float deltaFwdStart = deltaFwd; - - float fracs[maxNumRays]; - Vector3 segmentEnds[maxNumRays]; - Vector3 groundPositions[maxNumRays]; - Vector3 groundNormals[maxNumRays]; - - - lastOnFloor = false; - int bestIRay = 0; - int iRay; - - - for (iRay = 0; iRay < numRaysUse; ++iRay) - { - fracs[iRay] = 1e20; - // work out the offset relative to the middle ray - float distFwd = (deltaFwdStart + iRay * deltaFwd) - radius; - float zOffset = radius * (1.0f - (float)Math::cos( Math::deg2rad( 90.0f * (distFwd / radius)))); - - segmentEnds[iRay] = wheelRayEnd + distFwd * wheelFwd + zOffset * wheelUp; - - - PhysicsDirectSpaceState::RayResult rr; - - bool collided = space->intersect_ray(wheelRayBegin,segmentEnds[iRay],rr,body->exclude); - - - if (collided){ - lastOnFloor = true; - groundPositions[iRay]=rr.position; - groundNormals[iRay]=rr.normal; - fracs[iRay] = ((wheelRayBegin-rr.position).length() / (wheelRayBegin-wheelRayEnd).length()); - if (fracs[iRay] < fracs[bestIRay]) - bestIRay = iRay; - } - } - - - if (!lastOnFloor) - return false; - - //Assert(bestIRay < numRays); - - // use the best one - Vector3 groundPos = groundPositions[bestIRay]; - float frac = fracs[bestIRay]; - - // const Vector3 groundNormal = (worldPos - segments[bestIRay].GetEnd()).NormaliseSafe(); - // const Vector3 groundNormal = groundNormals[bestIRay]; - - - Vector3 groundNormal = worldAxis; - - if (numRaysUse > 1) - { - for (iRay = 0; iRay < numRaysUse; ++iRay) - { - if (fracs[iRay] <= 1.0f) - { - groundNormal += (1.0f - fracs[iRay]) * (worldPos - segmentEnds[iRay]); - } - } - - groundNormal.normalize(); - - } - else - { - groundNormal = groundNormals[bestIRay]; - } - - - - float spring = (body->mass/body->wheels.size()) * s->get_total_gravity().length() / (resting_frac * travel); - - float displacement = rayLen * (1.0f - frac); - displacement = CLAMP(displacement, 0, travel); - - - - float displacementForceMag = displacement * spring; - - // reduce force when suspension is par to ground - displacementForceMag *= groundNormals[bestIRay].dot(worldAxis); - - // apply damping - float damping = 2.0f * (float)Math::sqrt(spring * body->mass); - damping /= body->wheels.size(); // assume wheels act together - damping *= damping_frac; // a bit bouncy - - float upSpeed = (displacement - lastDisplacement) / s->get_step(); - - float dampingForceMag = upSpeed * damping; - - float totalForceMag = displacementForceMag + dampingForceMag; - - if (totalForceMag < 0.0f) totalForceMag = 0.0f; - - Vector3 extraForce = totalForceMag * worldAxis; - - - force += extraForce; - // side-slip friction and drive force. Work out wheel- and floor-relative coordinate frame - Vector3 groundUp = groundNormal; - Vector3 groundLeft = groundNormal.cross(wheelFwd).normalized(); - - Vector3 groundFwd = groundLeft.cross(groundUp); - - Vector3 wheelPointVel = s->get_linear_velocity() + - (s->get_angular_velocity()).cross(s->get_transform().basis.xform(local_xform.origin));// * mPos); - - Vector3 rimVel = -angVel * wheelLeft.cross(groundPos - worldPos); - wheelPointVel += rimVel; - - // if sitting on another body then adjust for its velocity. - /*if (worldBody != null) - { - Vector3 worldVel = worldBody.Velocity + - Vector3.Cross(worldBody.AngularVelocity, groundPos - worldBody.Position); - - wheelPointVel -= worldVel; - }*/ - - // sideways forces - float noslipVel = 0.2f; - float slipVel = 0.4f; - float slipFactor = 0.7f; - - float smallVel = 3; - float friction = side_friction; - - float sideVel = wheelPointVel.dot(groundLeft); - - if ((sideVel > slipVel) || (sideVel < -slipVel)) - friction *= slipFactor; - else - if ((sideVel > noslipVel) || (sideVel < -noslipVel)) - friction *= 1.0f - (1.0f - slipFactor) * (Math::absf(sideVel) - noslipVel) / (slipVel - noslipVel); - - if (sideVel < 0.0f) - friction *= -1.0f; - - if (Math::absf(sideVel) < smallVel) - friction *= Math::absf(sideVel) / smallVel; - - float sideForce = -friction * totalForceMag; - - extraForce = sideForce * groundLeft; - force += extraForce; - // fwd/back forces - friction = forward_friction; - float fwdVel = wheelPointVel.dot(groundFwd); - - if ((fwdVel > slipVel) || (fwdVel < -slipVel)) - friction *= slipFactor; - else - if ((fwdVel > noslipVel) || (fwdVel < -noslipVel)) - friction *= 1.0f - (1.0f - slipFactor) * (Math::absf(fwdVel) - noslipVel) / (slipVel - noslipVel); - - if (fwdVel < 0.0f) - friction *= -1.0f; - - if (Math::absf(fwdVel) < smallVel) - friction *= Math::absf(fwdVel) / smallVel; - - float fwdForce = -friction * totalForceMag; - - extraForce = fwdForce * groundFwd; - force += extraForce; - - - //if (!force.IsSensible()) - //{ - // TRACE_FILE_IF(ONCE_1) - // TRACE("Bad force in car wheel\n"); - // return true; - //} - - // fwd force also spins the wheel - Vector3 wheelCentreVel = s->get_linear_velocity() + - (s->get_angular_velocity()).cross(s->get_transform().basis.xform(local_xform.origin)); - - angVelForGrip = wheelCentreVel.dot(groundFwd) / radius; - torque += -fwdForce * radius; - - // add force to car -// carBody.AddWorldForce(force, groundPos); - - s->add_force(force,(groundPos-s->get_transform().origin)); - - // add force to the world - /* - if (worldBody != null && !worldBody.Immovable) - { - // todo get the position in the right place... - // also limit the velocity that this force can produce by looking at the - // mass/inertia of the other object - float maxOtherBodyAcc = 500.0f; - float maxOtherBodyForce = maxOtherBodyAcc * worldBody.Mass; - - if (force.LengthSquared() > (maxOtherBodyForce * maxOtherBodyForce)) - force *= maxOtherBodyForce / force.Length(); - - worldBody.AddWorldForce(-force, groundPos); - }*/ - - Transform wheel_xf = local_xform; - wheel_xf.origin += wheelUp * displacement; - wheel_xf.basis = wheel_xf.basis * Matrix3(Vector3(0,1,0),Math::deg2rad(steerAngle)); - //wheel_xf.basis = wheel_xf.basis * Matrix3(wheel_xf.basis[0],-Math::deg2rad(axisAngle)); - - set_transform(wheel_xf); - lastDisplacement=displacement; - return true; - -} - -void CarWheel::set_type_drive(bool p_enable) { - - type_drive=p_enable; -} - -bool CarWheel::is_type_drive() const { - - return type_drive; -} - -void CarWheel::set_type_steer(bool p_enable) { - - type_steer=p_enable; -} - -bool CarWheel::is_type_steer() const { - - return type_steer; -} - - -void CarWheel::_bind_methods() { - - ObjectTypeDB::bind_method(_MD("set_side_friction","friction"),&CarWheel::set_side_friction); - ObjectTypeDB::bind_method(_MD("set_forward_friction","friction"),&CarWheel::set_forward_friction); - ObjectTypeDB::bind_method(_MD("set_travel","distance"),&CarWheel::set_travel); - ObjectTypeDB::bind_method(_MD("set_radius","radius"),&CarWheel::set_radius); - ObjectTypeDB::bind_method(_MD("set_resting_frac","frac"),&CarWheel::set_resting_frac); - ObjectTypeDB::bind_method(_MD("set_damping_frac","frac"),&CarWheel::set_damping_frac); - ObjectTypeDB::bind_method(_MD("set_num_rays","amount"),&CarWheel::set_num_rays); - - ObjectTypeDB::bind_method(_MD("get_side_friction"),&CarWheel::get_side_friction); - ObjectTypeDB::bind_method(_MD("get_forward_friction"),&CarWheel::get_forward_friction); - ObjectTypeDB::bind_method(_MD("get_travel"),&CarWheel::get_travel); - ObjectTypeDB::bind_method(_MD("get_radius"),&CarWheel::get_radius); - ObjectTypeDB::bind_method(_MD("get_resting_frac"),&CarWheel::get_resting_frac); - ObjectTypeDB::bind_method(_MD("get_damping_frac"),&CarWheel::get_damping_frac); - ObjectTypeDB::bind_method(_MD("get_num_rays"),&CarWheel::get_num_rays); - - ObjectTypeDB::bind_method(_MD("set_type_drive","enable"),&CarWheel::set_type_drive); - ObjectTypeDB::bind_method(_MD("is_type_drive"),&CarWheel::is_type_drive); - - ObjectTypeDB::bind_method(_MD("set_type_steer","enable"),&CarWheel::set_type_steer); - ObjectTypeDB::bind_method(_MD("is_type_steer"),&CarWheel::is_type_steer); - - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"type/drive"),_SCS("set_type_drive"),_SCS("is_type_drive")); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"type/steer"),_SCS("set_type_steer"),_SCS("is_type_steer")); - ADD_PROPERTY( PropertyInfo(Variant::REAL,"config/side_friction",PROPERTY_HINT_RANGE,"0.01,64,0.01"),_SCS("set_side_friction"),_SCS("get_side_friction")); - ADD_PROPERTY( PropertyInfo(Variant::REAL,"config/forward_friction",PROPERTY_HINT_RANGE,"0.01,64,0.01"),_SCS("set_forward_friction"),_SCS("get_forward_friction")); - ADD_PROPERTY( PropertyInfo(Variant::REAL,"config/travel",PROPERTY_HINT_RANGE,"0.01,1024,0.01"),_SCS("set_travel"),_SCS("get_travel")); - ADD_PROPERTY( PropertyInfo(Variant::REAL,"config/radius",PROPERTY_HINT_RANGE,"0.01,1024,0.01"),_SCS("set_radius"),_SCS("get_radius")); - ADD_PROPERTY( PropertyInfo(Variant::REAL,"config/resting_frac",PROPERTY_HINT_RANGE,"0.01,64,0.01"),_SCS("set_resting_frac"),_SCS("get_resting_frac")); - ADD_PROPERTY( PropertyInfo(Variant::REAL,"config/damping_frac",PROPERTY_HINT_RANGE,"0.01,64,0.01"),_SCS("set_damping_frac"),_SCS("get_damping_frac")); - ADD_PROPERTY( PropertyInfo(Variant::REAL,"config/num_rays",PROPERTY_HINT_RANGE,"1,32,1"),_SCS("set_num_rays"),_SCS("get_num_rays")); - -} - -CarWheel::CarWheel() { - - side_friction=4.7; - forward_friction=5.0; - travel=0.2; - radius=0.4; - resting_frac=0.45; - damping_frac=0.3; - num_rays=1; - - angVel = 0.0f; - steerAngle = 0.0f; - torque = 0.0f; - driveTorque = 0.0f; - axisAngle = 0.0f; - upSpeed = 0.0f; - locked = false; - lastDisplacement = 0.0f; - lastOnFloor = false; - angVelForGrip = 0.0f; - angVelForGrip=0; - - type_drive=false; - type_steer=false; - -} - -/// - - -void CarBody::set_max_steer_angle(real_t p_angle) { - - max_steer_angle=p_angle; -} -void CarBody::set_steer_rate(real_t p_rate) { - - steer_rate=p_rate; -} -void CarBody::set_drive_torque(real_t p_torque) { - - drive_torque=p_torque; -} - -real_t CarBody::get_max_steer_angle() const{ - - return max_steer_angle; -} -real_t CarBody::get_steer_rate() const{ - - return steer_rate; -} -real_t CarBody::get_drive_torque() const{ - - return drive_torque; -} - - -void CarBody::set_target_steering(float p_steering) { - - target_steering=p_steering; -} - -void CarBody::set_target_accelerate(float p_accelerate) { - target_accelerate=p_accelerate; -} - -void CarBody::set_hand_brake(float p_amont) { - - hand_brake=p_amont; -} - -real_t CarBody::get_target_steering() const { - - return target_steering; -} -real_t CarBody::get_target_accelerate() const { - - return target_accelerate; -} -real_t CarBody::get_hand_brake() const { - - return hand_brake; -} - - -void CarBody::_direct_state_changed(Object *p_state) { - - PhysicsDirectBodyState *state=p_state->cast_to<PhysicsDirectBodyState>(); - - float dt = state->get_step(); - AABB aabb; - int drive_total=0; - for(int i=0;i<wheels.size();i++) { - CarWheel *w=wheels[i]; - if (i==0) { - aabb.pos=w->local_xform.origin; - } else { - aabb.expand_to(w->local_xform.origin); - } - if (w->type_drive) - drive_total++; - - } - // control inputs - float deltaAccelerate = dt * 4.0f; - - float dAccelerate = target_accelerate - accelerate; - dAccelerate = CLAMP(dAccelerate, -deltaAccelerate, deltaAccelerate); - accelerate += dAccelerate; - - float deltaSteering = dt * steer_rate; - float dSteering = target_steering - steering; - dSteering = CLAMP(dSteering, -deltaSteering, deltaSteering); - steering += dSteering; - - // apply these inputs - float maxTorque = drive_torque; - - float torque_div = drive_total/2; - if (torque_div>0) - maxTorque/=torque_div; - - - float alpha = ABS(max_steer_angle * steering); - float angleSgn = steering > 0.0f ? 1.0f : -1.0f; - - int wheels_on_floor=0; - - for(int i=0;i<wheels.size();i++) { - - CarWheel *w=wheels[i]; - if (w->type_drive) - w->driveTorque+=maxTorque * accelerate; - w->locked = !w->type_steer && (hand_brake > 0.5f); - - if (w->type_steer) { - //steering - - bool inner = (steering > 0 && w->local_xform.origin.x > 0) || (steering < 0 && w->local_xform.origin.x < 0); - - if (inner || alpha==0.0) { - - w->steerAngle = (angleSgn * alpha); - } else { - float dx = aabb.size.z; - float dy = aabb.size.x; - - float beta = Math::atan2(dy, dx + (dy / (float)Math::tan(Math::deg2rad(alpha)))); - beta = Math::rad2deg(beta); - w->steerAngle = (angleSgn * beta); - - } - } - - if (w->add_forces(state)) - wheels_on_floor++; - w->update(dt); - - - } - - print_line("onfloor: "+itos(wheels_on_floor)); - - - set_ignore_transform_notification(true); - set_global_transform(state->get_transform()); - linear_velocity=state->get_linear_velocity(); - angular_velocity=state->get_angular_velocity(); - //active=!state->is_sleeping(); - //if (get_script_instance()) - // get_script_instance()->call("_integrate_forces",state); - set_ignore_transform_notification(false); - - -} - -void CarBody::set_mass(real_t p_mass) { - - mass=p_mass; - PhysicsServer::get_singleton()->body_set_param(get_rid(),PhysicsServer::BODY_PARAM_MASS,mass); -} - -real_t CarBody::get_mass() const{ - - return mass; -} - - -void CarBody::set_friction(real_t p_friction) { - - friction=p_friction; - PhysicsServer::get_singleton()->body_set_param(get_rid(),PhysicsServer::BODY_PARAM_FRICTION,friction); -} - -real_t CarBody::get_friction() const{ - - return friction; -} - - -void CarBody::_bind_methods() { - - ObjectTypeDB::bind_method(_MD("set_max_steer_angle","value"),&CarBody::set_max_steer_angle); - ObjectTypeDB::bind_method(_MD("set_steer_rate","rate"),&CarBody::set_steer_rate); - ObjectTypeDB::bind_method(_MD("set_drive_torque","value"),&CarBody::set_drive_torque); - - ObjectTypeDB::bind_method(_MD("get_max_steer_angle"),&CarBody::get_max_steer_angle); - ObjectTypeDB::bind_method(_MD("get_steer_rate"),&CarBody::get_steer_rate); - ObjectTypeDB::bind_method(_MD("get_drive_torque"),&CarBody::get_drive_torque); - - ObjectTypeDB::bind_method(_MD("set_target_steering","amount"),&CarBody::set_target_steering); - ObjectTypeDB::bind_method(_MD("set_target_accelerate","amount"),&CarBody::set_target_accelerate); - ObjectTypeDB::bind_method(_MD("set_hand_brake","amount"),&CarBody::set_hand_brake); - - ObjectTypeDB::bind_method(_MD("get_target_steering"),&CarBody::get_target_steering); - ObjectTypeDB::bind_method(_MD("get_target_accelerate"),&CarBody::get_target_accelerate); - ObjectTypeDB::bind_method(_MD("get_hand_brake"),&CarBody::get_hand_brake); - - ObjectTypeDB::bind_method(_MD("set_mass","mass"),&CarBody::set_mass); - ObjectTypeDB::bind_method(_MD("get_mass"),&CarBody::get_mass); - - ObjectTypeDB::bind_method(_MD("set_friction","friction"),&CarBody::set_friction); - ObjectTypeDB::bind_method(_MD("get_friction"),&CarBody::get_friction); - - ObjectTypeDB::bind_method(_MD("_direct_state_changed"),&CarBody::_direct_state_changed); - - ADD_PROPERTY( PropertyInfo(Variant::REAL,"body/mass",PROPERTY_HINT_RANGE,"0.01,65536,0.01"),_SCS("set_mass"),_SCS("get_mass")); - ADD_PROPERTY( PropertyInfo(Variant::REAL,"body/friction",PROPERTY_HINT_RANGE,"0.01,1,0.01"),_SCS("set_friction"),_SCS("get_friction")); - - ADD_PROPERTY( PropertyInfo(Variant::REAL,"config/max_steer_angle",PROPERTY_HINT_RANGE,"1,90,1"),_SCS("set_max_steer_angle"),_SCS("get_max_steer_angle")); - ADD_PROPERTY( PropertyInfo(Variant::REAL,"config/drive_torque",PROPERTY_HINT_RANGE,"0.01,64,0.01"),_SCS("set_drive_torque"),_SCS("get_drive_torque")); - ADD_PROPERTY( PropertyInfo(Variant::REAL,"config/steer_rate",PROPERTY_HINT_RANGE,"0.01,64,0.01"),_SCS("set_steer_rate"),_SCS("get_steer_rate")); - - ADD_PROPERTY( PropertyInfo(Variant::REAL,"drive/target_steering",PROPERTY_HINT_RANGE,"-1,1,0.01"),_SCS("set_target_steering"),_SCS("get_target_steering")); - ADD_PROPERTY( PropertyInfo(Variant::REAL,"drive/target_accelerate",PROPERTY_HINT_RANGE,"-1,1,0.01"),_SCS("set_target_accelerate"),_SCS("get_target_accelerate")); - ADD_PROPERTY( PropertyInfo(Variant::REAL,"drive/hand_brake",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_hand_brake"),_SCS("get_hand_brake")); - -} - -CarBody::CarBody() : PhysicsBody(PhysicsServer::BODY_MODE_RIGID) { - - forward_drive=true; - backward_drive=true; - max_steer_angle=30; - steer_rate=1; - drive_torque=520; - - target_steering=0; - target_accelerate=0; - hand_brake=0; - - steering=0; - accelerate=0; - - mass=1; - friction=1; - - ccd=false; -// can_sleep=true; - - - - - exclude.insert(get_rid()); - PhysicsServer::get_singleton()->body_set_force_integration_callback(get_rid(),this,"_direct_state_changed"); - - -} diff --git a/scene/3d/car_body.h b/scene/3d/car_body.h deleted file mode 100644 index 87eb047bcf..0000000000 --- a/scene/3d/car_body.h +++ /dev/null @@ -1,170 +0,0 @@ -/*************************************************************************/ -/* car_body.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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. */ -/*************************************************************************/ -#ifndef CAR_BODY_H -#define CAR_BODY_H - -#include "scene/3d/physics_body.h" - - -class CarBody; - -class CarWheel : public Spatial { - - OBJ_TYPE(CarWheel,Spatial); - -friend class CarBody; - real_t side_friction; - real_t forward_friction; - real_t travel; - real_t radius; - real_t resting_frac; - real_t damping_frac; - int num_rays; - Transform local_xform; - - CarBody *body; - - float angVel; - float steerAngle; - float torque; - float driveTorque; - float axisAngle; - float upSpeed; // speed relative to the car - bool locked; - // last frame stuff - float lastDisplacement; - float angVelForGrip; - bool lastOnFloor; - - bool type_drive; - bool type_steer; - - -protected: - void update(real_t dt); - bool add_forces(PhysicsDirectBodyState *s); - void _notification(int p_what); - static void _bind_methods(); - -public: - - void set_side_friction(real_t p_friction); - void set_forward_friction(real_t p_friction); - void set_travel(real_t p_travel); - void set_radius(real_t p_radius); - void set_resting_frac(real_t p_frac); - void set_damping_frac(real_t p_frac); - void set_num_rays(real_t p_rays); - - real_t get_side_friction() const; - real_t get_forward_friction() const; - real_t get_travel() const; - real_t get_radius() const; - real_t get_resting_frac() const; - real_t get_damping_frac() const; - int get_num_rays() const; - - void set_type_drive(bool p_enable); - bool is_type_drive() const; - - void set_type_steer(bool p_enable); - bool is_type_steer() const; - - CarWheel(); - -}; - - - -class CarBody : public PhysicsBody { - - OBJ_TYPE(CarBody,PhysicsBody); - - real_t mass; - real_t friction; - - Vector3 linear_velocity; - Vector3 angular_velocity; - bool ccd; - - real_t max_steer_angle; - real_t steer_rate; - int wheel_num_rays; - real_t drive_torque; - -// control stuff - real_t target_steering; - real_t target_accelerate; - - bool forward_drive; - bool backward_drive; - - real_t steering; - real_t accelerate; - real_t hand_brake; - Set<RID> exclude; - - -friend class CarWheel; - Vector<CarWheel*> wheels; - - static void _bind_methods(); - - void _direct_state_changed(Object *p_state); -public: - - - void set_mass(real_t p_mass); - real_t get_mass() const; - - void set_friction(real_t p_friction); - real_t get_friction() const; - - void set_max_steer_angle(real_t p_angle); - void set_steer_rate(real_t p_rate); - void set_drive_torque(real_t p_torque); - - real_t get_max_steer_angle() const; - real_t get_steer_rate() const; - real_t get_drive_torque() const; - - - void set_target_steering(float p_steering); - void set_target_accelerate(float p_accelerate); - void set_hand_brake(float p_amont); - - real_t get_target_steering() const; - real_t get_target_accelerate() const; - real_t get_hand_brake() const; - - - CarBody(); -}; - -#endif // CAR_BODY_H diff --git a/scene/3d/editable_shape.cpp b/scene/3d/editable_shape.cpp deleted file mode 100644 index ab3f832028..0000000000 --- a/scene/3d/editable_shape.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/*************************************************************************/ -/* editable_shape.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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. */ -/*************************************************************************/ -#include "editable_shape.h" - - -void EditableShape::_notification(int p_what) { - - - -} - - -void EditableShape::set_bsp_tree(const BSP_Tree& p_bsp) { - - bsp=p_bsp; -} - -void EditableShape::set_shape(const Ref<Shape>& p_shape) { - - shape=p_shape; -} - - - -EditableShape::EditableShape() -{ -} - - - -///////////////////////// - - -void EditableSphere::set_radius(float p_radius) { - - radius=p_radius; - update_gizmo(); - _change_notify("params/radius"); -} - - -float EditableSphere::get_radius() const{ - - return radius; -} - - -void EditableSphere::_bind_methods() { - - ObjectTypeDB::bind_method(_MD("set_radius","radius"),&EditableSphere::set_radius); - ObjectTypeDB::bind_method(_MD("get_radius"),&EditableSphere::get_radius); - - ADD_PROPERTY( PropertyInfo(Variant::REAL,"params/radius",PROPERTY_HINT_EXP_RANGE,"0.001,16384,0.001"),_SCS("set_radius"),_SCS("get_radius")); -} - -EditableSphere::EditableSphere() { - - radius=1.0; -} diff --git a/scene/3d/editable_shape.h b/scene/3d/editable_shape.h deleted file mode 100644 index 9accea575c..0000000000 --- a/scene/3d/editable_shape.h +++ /dev/null @@ -1,73 +0,0 @@ -/*************************************************************************/ -/* editable_shape.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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. */ -/*************************************************************************/ -#ifndef EDITABLE_SHAPE_H -#define EDITABLE_SHAPE_H - -#include "scene/3d/spatial.h" -#include "scene/resources/shape.h" - -class EditableShape : public Spatial { - - OBJ_TYPE(EditableShape,Spatial); - - //can hold either of those - BSP_Tree bsp; - Ref<Shape> shape; - - void _update_parent(); -protected: - - void _notification(int p_what); - - void set_bsp_tree(const BSP_Tree& p_bsp); - void set_shape(const Ref<Shape>& p_shape); -public: - EditableShape(); -}; - - -class EditableSphere : public EditableShape { - - OBJ_TYPE( EditableSphere, EditableShape ); - - - float radius; -protected: - - static void _bind_methods(); -public: - - void set_radius(float p_radius); - float get_radius() const; - - EditableSphere(); -}; - - -#endif // EDITABLE_SHAPE_H diff --git a/scene/SCsub b/scene/SCsub index 28fb358106..8c4f0499c4 100644 --- a/scene/SCsub +++ b/scene/SCsub @@ -15,7 +15,7 @@ SConscript('resources/SCsub'); SConscript('io/SCsub'); -lib = env.Library("scene",env.scene_sources, LIBSUFFIX=env['platform_libsuffix']) +lib = env.Library("scene",env.scene_sources) env.Prepend(LIBS=[lib]) diff --git a/scene/io/scene_format_object.cpp b/scene/io/scene_format_object.cpp deleted file mode 100644 index 6ffae30282..0000000000 --- a/scene/io/scene_format_object.cpp +++ /dev/null @@ -1,851 +0,0 @@ -/*************************************************************************/ -/* scene_format_object.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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. */ -/*************************************************************************/ -#include "scene_format_object.h" -#include "print_string.h" -#include "globals.h" -#include "scene/resources/packed_scene.h" -#include "io/resource_loader.h" - -#ifdef OLD_SCENE_FORMAT_ENABLED - -void SceneFormatSaverObject::save_node(const Node* p_root,const Node* p_node,const Node* p_owner,ObjectFormatSaver *p_saver,String p_base_path,uint32_t p_flags,Map<const Node*,uint32_t>& owner_id) const { - - if (p_node!=p_root && p_node->get_owner()==NULL) - return; - - - if (p_flags&SceneSaver::FLAG_BUNDLE_INSTANCED_SCENES || p_node->get_owner() == p_owner || p_node == p_owner ) { - - Dictionary d; - if (p_root!=p_node) { - d["path"]=p_root->get_path_to(p_node->get_parent()); - } - - d["name"]=p_node->get_name(); - - /* Connections */ - - List<MethodInfo> signal_list; - - p_node->get_signal_list(&signal_list); - - int conn_count=0; - - Set<Node::Connection> exclude_connections; - - if (!(p_flags&SceneSaver::FLAG_BUNDLE_INSTANCED_SCENES)) { - - Vector<Node::Connection> ex = p_node->get_instance_connections(); - for(int i=0;i<ex.size();i++) { - exclude_connections.insert(ex[i]); - } - } - - for (List<MethodInfo>::Element *S=signal_list.front();S;S=S->next()) { - - List<Node::Connection> connections; - p_node->get_signal_connection_list(S->get().name,&connections); - for(List<Node::Connection>::Element *E=connections.front();E;E=E->next()) { - - Node::Connection &c=E->get(); - if (!(c.flags&Object::CONNECT_PERSIST)) - continue; - if (exclude_connections.has(c)) - continue; - - Node *target = c.target->cast_to<Node>(); - if (!target) - continue; //connected to something not a node, ignoring - - Dictionary cd; - cd["signal"]=c.signal; - cd["target"]=p_node->get_path_to(target); - cd["method"]=c.method; - cd["realtime"]=!(c.flags&Object::CONNECT_DEFERRED); - if (c.binds.size()) - cd["binds"]=c.binds; - d["connection/"+itos(conn_count+1)]=cd; - - conn_count++; - } - } - - d["connection_count"]=conn_count; - if (owner_id.has(p_node->get_owner())) { - - d["owner"]=owner_id[p_node->get_owner()]; - } - - /* Groups */ - - DVector<String> group_array; - List<Node::GroupInfo> groups; - p_node->get_groups(&groups); - Set<StringName> exclude_groups; - - if (!(p_flags&SceneSaver::FLAG_BUNDLE_INSTANCED_SCENES)) { - //generate groups to exclude (came from instance) - Vector<StringName> eg; - eg=p_node->get_instance_groups(); - for(int i=0;i<eg.size();i++) - exclude_groups.insert(eg[i]); - } - - for(List<Node::GroupInfo>::Element*E=groups.front();E;E=E->next()) { - - if (E->get().persistent && !exclude_groups.has(E->get().name)) - group_array.push_back(E->get().name); - } - - if (group_array.size()) - d["groups"]=group_array; - - /* Save */ - - if (p_owner!=p_node && p_node->get_filename()!="") { - - String instance_path; - if (p_flags&SceneSaver::FLAG_RELATIVE_PATHS) - instance_path=p_base_path.path_to_file(Globals::get_singleton()->localize_path(p_node->get_filename())); - else - instance_path=p_node->get_filename(); - d["instance"]=instance_path; - - if (p_flags&SceneSaver::FLAG_BUNDLE_INSTANCED_SCENES) { - - int id = owner_id.size(); - d["owner_id"]=id; - owner_id[p_node]=id; - - p_saver->save(p_node,d); - - //owner change! - for (int i=0;i<p_node->get_child_count();i++) { - - save_node(p_root,p_node->get_child(i),p_node,p_saver,p_base_path,p_flags,owner_id); - } - return; - - } else { - DVector<String> prop_names; - Array prop_values; - - List<PropertyInfo> properties; - p_node->get_property_list(&properties); - - //instance state makes sure that only changes to instance are saved - Dictionary instance_state=p_node->get_instance_state(); - - for(List<PropertyInfo>::Element *E=properties.front();E;E=E->next()) { - - if (!(E->get().usage&PROPERTY_USAGE_STORAGE)) - continue; - - String name=E->get().name; - Variant value=p_node->get(E->get().name); - - if (!instance_state.has(name)) - continue; // did not change since it was loaded, not save - if (value==instance_state[name]) - continue; - prop_names.push_back( name ); - prop_values.push_back( value ); - - } - - d["override_names"]=prop_names; - d["override_values"]=prop_values; - - p_saver->save(NULL,d); - } - } else { - - p_saver->save(p_node,d); - } - } - - for (int i=0;i<p_node->get_child_count();i++) { - - save_node(p_root,p_node->get_child(i),p_owner,p_saver,p_base_path,p_flags,owner_id); - } -} - - -Error SceneFormatSaverObject::save(const String &p_path,const Node* p_scene,uint32_t p_flags,const Ref<OptimizedSaver> &p_optimizer) { - - String extension=p_path.extension(); - if (extension=="scn") - extension="bin"; - if (extension=="xscn") - extension="xml"; - - String local_path=Globals::get_singleton()->localize_path(p_path); - uint32_t saver_flags=0; - if (p_flags&SceneSaver::FLAG_RELATIVE_PATHS) - saver_flags|=ObjectSaver::FLAG_RELATIVE_PATHS; - if (p_flags&SceneSaver::FLAG_BUNDLE_RESOURCES) - saver_flags|=ObjectSaver::FLAG_BUNDLE_RESOURCES; - if (p_flags&SceneSaver::FLAG_OMIT_EDITOR_PROPERTIES) - saver_flags|=ObjectSaver::FLAG_OMIT_EDITOR_PROPERTIES; - if (p_flags&SceneSaver::FLAG_SAVE_BIG_ENDIAN) - saver_flags|=ObjectSaver::FLAG_SAVE_BIG_ENDIAN; - - ObjectFormatSaver *saver = ObjectSaver::instance_format_saver(local_path,"SCENE",extension,saver_flags,p_optimizer); - - ERR_FAIL_COND_V(!saver,ERR_FILE_UNRECOGNIZED); - - /* SAVE SCENE */ - - Map<const Node*,uint32_t> node_id_map; - save_node(p_scene,p_scene,p_scene,saver,local_path,p_flags,node_id_map); - - memdelete(saver); - - return OK; -} - -void SceneFormatSaverObject::get_recognized_extensions(List<String> *p_extensions) const { - - p_extensions->push_back("xml"); - p_extensions->push_back("scn"); - p_extensions->push_back("xscn"); - -// ObjectSaver::get_recognized_extensions(p_extensions); -} - - -///////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////// - -void SceneFormatLoaderObject::_apply_meta(Node *node, const Variant&meta, ObjectFormatLoader *p_loader,List<ConnectionItem>& connections,Error& r_err,Map<uint32_t,Node*>& owner_map) { - - r_err = OK; - - - Dictionary d=meta; - - if (!d.has("name")) { - - r_err=ERR_WTF; - memdelete(node); - ERR_FAIL_COND(!d.has("name")); - } - - - node->set_name(d["name"]); - int connection_count=d.has("connection_count")?d["connection_count"].operator int():0; - - - for (int i=0;i<connection_count;i++) { - - Dictionary cd=d["connection/"+itos(i+1)]; - - ERR_CONTINUE(!cd.has("target")); - ERR_CONTINUE(!cd.has("method")); - ERR_CONTINUE(!cd.has("realtime")); - ERR_CONTINUE(!cd.has("signal")); - - ConnectionItem ci; - - ci.node=node; - ci.target=cd["target"]; - ci.method=cd["method"]; - ci.signal=cd["signal"]; - ci.realtime=cd["realtime"]; - if (cd.has("binds")) - ci.binds=cd["binds"]; - - connections.push_back(ci); - - } - - DVector<String> groups=d.has("groups")?d["groups"].operator DVector<String>():DVector<String>(); - for (int i=0;i<groups.size();i++) { - - node->add_to_group(groups[i],true); - } - -} - - - -Ref<SceneInteractiveLoader> SceneFormatLoaderObject::load_interactive(const String &p_path,bool p_save_root_state) { - - SceneInteractiveLoaderObject *sil = memnew( SceneInteractiveLoaderObject(p_path,p_save_root_state) ); - - if (sil->error!=OK) { - - memdelete( sil ); - return Ref<SceneInteractiveLoader>(); - } - - return Ref<SceneInteractiveLoader>( sil ); - -} - - -Node* SceneFormatLoaderObject::load_node(Object *obj, const Variant& meta, Node *p_root, ObjectFormatLoader *p_loader,List<ConnectionItem>& connections,Error& r_err,bool p_save_instance_state,Map<uint32_t,Node*>& owner_map) { - - r_err = OK; - - Node *node=obj->cast_to<Node>(); - - _apply_meta(node,meta,p_loader,connections,r_err,owner_map); - if (r_err!=OK) - return NULL; - - Dictionary d=meta; - - if (p_root) { - NodePath path=d.has("path")?d["path"].operator NodePath():NodePath("."); - - Node *parent=p_root->get_node(path); - if (!parent) { - memdelete(node); - r_err=ERR_FILE_CORRUPT; - ERR_FAIL_COND_V(!parent,NULL); - } - - parent->add_child(node); - - if (d.has("owner_id")) { - //is owner - owner_map[d["owner_id"]]=node; - if (d.has("instance")) - node->set_filename(d["instance"]); - - } - - if (d.has("owner")) { - - uint32_t owner = d["owner"]; - ERR_FAIL_COND_V(!owner_map.has(owner),NULL); - node->set_owner(owner_map[owner]); - } else { - - node->set_owner(p_root); - } - } - - return node; -} - -void SceneFormatLoaderObject::_apply_connections(List<ConnectionItem>& connections) { - - int idx=0; - for (List<ConnectionItem>::Element *E=connections.front();E;E=E->next()) { - - ConnectionItem &ci=E->get(); - Node *target = ci.node->get_node(ci.target); - ERR_CONTINUE(!target); - ci.node->connect(ci.signal,target,ci.method,ci.binds,(ci.realtime?0:Object::CONNECT_DEFERRED)|Object::CONNECT_PERSIST); - idx++; - } - -} - -Node* SceneFormatLoaderObject::load(const String &p_path,bool p_save_instance_state) { - - List<ConnectionItem> connections; - - String extension=p_path.extension(); - if (extension=="scn") - extension="bin"; - if (extension=="xscn") - extension="xml"; - - String local_path = Globals::get_singleton()->localize_path(p_path); - - ObjectFormatLoader *loader = ObjectLoader::instance_format_loader(local_path,"SCENE",extension); - - ERR_EXPLAIN("Couldn't load scene: "+p_path); - ERR_FAIL_COND_V(!loader,NULL); - - Node *root=NULL; - Map<uint32_t,Node*> owner_map; - - while(true) { - - Object *obj=NULL; - Variant metav; - Error r_err=loader->load(&obj,metav); - - if (r_err == ERR_SKIP) { - continue; - }; - - if (r_err==ERR_FILE_EOF) { - memdelete(loader); - ERR_FAIL_COND_V(!root,NULL); - _apply_connections(connections); - return root; - } - - if (r_err || (!obj && metav.get_type()==Variant::NIL)) { - memdelete(loader); - ERR_EXPLAIN("Object Loader Failed for Scene: "+p_path) ; - ERR_FAIL_COND_V( r_err, NULL); - ERR_EXPLAIN("Object Loader Failed for Scene: "+p_path) ; - ERR_FAIL_COND_V( !obj && metav.get_type()==Variant::NIL,NULL); - } - - if (obj) { - if (obj->cast_to<Node>()) { - - Error err; - Node* node = load_node(obj, metav, root, loader,connections,err,p_save_instance_state,owner_map); - if (err) - memdelete(loader); - - ERR_FAIL_COND_V( err, NULL ); - if (!root) - root=node; - } else { - - memdelete(loader); - ERR_FAIL_V( NULL ); - - } - } else { - - // check for instance - Dictionary meta=metav; - if (meta.has("instance")) { - if (!root) { - - memdelete(loader); - ERR_FAIL_COND_V(!root,NULL); - } - - String path = meta["instance"]; - - if (path.find("://")==-1 && path.is_rel_path()) { - // path is relative to file being loaded, so convert to a resource path - path=Globals::get_singleton()->localize_path( - local_path.get_base_dir()+"/"+path); - } - - - Node *scene = SceneLoader::load(path); - - if (!scene) { - - Ref<PackedScene> sd = ResourceLoader::load(path); - if (sd.is_valid()) { - - scene=sd->instance(); - } - } - - - if (!scene) { - - memdelete(loader); - ERR_FAIL_COND_V(!scene,NULL); - } - - if (p_save_instance_state) - scene->generate_instance_state(); - - - Error err; - _apply_meta(scene,metav,loader,connections,err,owner_map); - if (err!=OK) { - memdelete(loader); - ERR_FAIL_COND_V(err!=OK,NULL); - } - - Node *parent=root; - - if (meta.has("path")) - parent=root->get_node(meta["path"]); - - - if (!parent) { - - memdelete(loader); - ERR_FAIL_COND_V(!parent,NULL); - } - - - if (meta.has("override_names") && meta.has("override_values")) { - - DVector<String> override_names=meta["override_names"]; - Array override_values=meta["override_values"]; - - int len = override_names.size(); - if ( len > 0 && len == override_values.size() ) { - - DVector<String>::Read names = override_names.read(); - - for(int i=0;i<len;i++) { - - scene->set(names[i],override_values[i]); - } - - } - - } - - scene->set_filename(path); - - parent->add_child(scene); - scene->set_owner(root); - } - } - } - - return NULL; -} - -void SceneFormatLoaderObject::get_recognized_extensions(List<String> *p_extensions) const { - - p_extensions->push_back("xml"); - p_extensions->push_back("scn"); - p_extensions->push_back("xscn"); - -// ObjectLoader::get_recognized_extensions(p_extensions); - -} - - - -/////////////////////////////////////////////////// - - -void SceneInteractiveLoaderObject::_apply_meta(Node *node, const Variant&meta, ObjectFormatLoader *p_loader,List<ConnectionItem>& connections,Error& r_err,Map<uint32_t,Node*>& owner_map) { - - r_err = OK; - - - Dictionary d=meta; - - if (!d.has("name")) { - - r_err=ERR_WTF; - memdelete(node); - ERR_FAIL_COND(!d.has("name")); - } - - - node->set_name(d["name"]); - int connection_count=d.has("connection_count")?d["connection_count"].operator int():0; - - - for (int i=0;i<connection_count;i++) { - - Dictionary cd=d["connection/"+itos(i+1)]; - - ERR_CONTINUE(!cd.has("target")); - ERR_CONTINUE(!cd.has("method")); - ERR_CONTINUE(!cd.has("realtime")); - ERR_CONTINUE(!cd.has("signal")); - - ConnectionItem ci; - - ci.node=node; - ci.target=cd["target"]; - ci.method=cd["method"]; - ci.signal=cd["signal"]; - ci.realtime=cd["realtime"]; - if (cd.has("binds")) - ci.binds=cd["binds"]; - - connections.push_back(ci); - - } - - DVector<String> groups=d.has("groups")?d["groups"].operator DVector<String>():DVector<String>(); - for (int i=0;i<groups.size();i++) { - - node->add_to_group(groups[i],true); - } - -} - - - -Node* SceneInteractiveLoaderObject::load_node(Object *obj, const Variant& meta, Node *p_root, ObjectFormatLoader *p_loader,List<ConnectionItem>& connections,Error& r_err,bool p_save_instance_state,Map<uint32_t,Node*>& owner_map) { - - r_err = OK; - - Node *node=obj->cast_to<Node>(); - - _apply_meta(node,meta,p_loader,connections,r_err,owner_map); - if (r_err!=OK) - return NULL; - - Dictionary d=meta; - - if (p_root) { - NodePath path=d.has("path")?d["path"].operator NodePath():NodePath("."); - - Node *parent=p_root->get_node(path); - if (!parent) { - memdelete(node); - r_err=ERR_FILE_CORRUPT; - ERR_FAIL_COND_V(!parent,NULL); - } - - parent->add_child(node); - - if (d.has("owner_id")) { - //is owner - owner_map[d["owner_id"]]=node; - if (d.has("instance")) - node->set_filename(d["instance"]); - - } - - if (d.has("owner")) { - - uint32_t owner = d["owner"]; - ERR_FAIL_COND_V(!owner_map.has(owner),NULL); - node->set_owner(owner_map[owner]); - } else { - - node->set_owner(p_root); - } - } - - return node; -} - -void SceneInteractiveLoaderObject::_apply_connections(List<ConnectionItem>& connections) { - - int idx=0; - for (List<ConnectionItem>::Element *E=connections.front();E;E=E->next()) { - - ConnectionItem &ci=E->get(); - Node *target = ci.node->get_node(ci.target); - ERR_CONTINUE(!target); - ci.node->connect(ci.signal,target,ci.method,ci.binds,(ci.realtime?0:Object::CONNECT_DEFERRED)|Object::CONNECT_PERSIST); - idx++; - } - -} - -SceneInteractiveLoaderObject::SceneInteractiveLoaderObject(const String &p_path,bool p_save_root_state) { - - error=OK; - path=p_path; - save_instance_state=p_save_root_state; - node_path=p_path; - root=NULL; - stage_max=1; - stage=0; - - - String extension=p_path.extension(); - if (extension=="scn") - extension="bin"; - if (extension=="xscn") - extension="xml"; - - local_path = Globals::get_singleton()->localize_path(p_path); - - loader = ObjectLoader::instance_format_loader(local_path,"SCENE",extension); - - if (!loader) { - - error=ERR_CANT_OPEN; - } - ERR_EXPLAIN("Couldn't load scene: "+p_path); - ERR_FAIL_COND(!loader); - -} - - - -void SceneInteractiveLoaderObject::set_local_path(const String& p_local_path) { - - node_path=p_local_path; -} - -Node *SceneInteractiveLoaderObject::get_scene() { - - if (error==ERR_FILE_EOF) - return root; - return NULL; -} -Error SceneInteractiveLoaderObject::poll() { - - if (error!=OK) - return error; - - Object *obj=NULL; - Variant metav; - Error r_err=loader->load(&obj,metav); - - - if (r_err == ERR_SKIP) { - stage++; - return OK; - }; - - if (r_err==ERR_FILE_EOF) { - memdelete(loader); - error=ERR_FILE_CORRUPT; - ERR_FAIL_COND_V(!root,ERR_FILE_CORRUPT); - _apply_connections(connections); - error=ERR_FILE_EOF; - if (root) - root->set_filename(node_path); - return error; - } - - if (r_err || (!obj && metav.get_type()==Variant::NIL)) { - memdelete(loader); - error=ERR_FILE_CORRUPT; - ERR_EXPLAIN("Object Loader Failed for Scene: "+path); - ERR_FAIL_COND_V( r_err, ERR_FILE_CORRUPT); - ERR_EXPLAIN("Object Loader Failed for Scene: "+path); - ERR_FAIL_COND_V( !obj && metav.get_type()==Variant::NIL,ERR_FILE_CORRUPT); - } - - if (obj) { - if (obj->cast_to<Node>()) { - - Error err; - Node* node = load_node(obj, metav, root, loader,connections,err,save_instance_state,owner_map); - if (err) { - error=ERR_FILE_CORRUPT; - memdelete(loader); - } - - ERR_FAIL_COND_V( err, ERR_FILE_CORRUPT ); - if (!root) - root=node; - } else { - - error=ERR_FILE_CORRUPT; - memdelete(loader); - ERR_EXPLAIN("Loaded something not a node.. (?)"); - ERR_FAIL_V( ERR_FILE_CORRUPT ); - - } - } else { - - // check for instance - Dictionary meta=metav; - if (meta.has("instance")) { - - if (!root) { - - error=ERR_FILE_CORRUPT; - memdelete(loader); - ERR_FAIL_COND_V(!root,ERR_FILE_CORRUPT); - } - - String path = meta["instance"]; - - if (path.find("://")==-1 && path.is_rel_path()) { - // path is relative to file being loaded, so convert to a resource path - path=Globals::get_singleton()->localize_path( - local_path.get_base_dir()+"/"+path); - } - - Node *scene = SceneLoader::load(path); - - if (!scene) { - - error=ERR_FILE_CORRUPT; - memdelete(loader); - ERR_FAIL_COND_V(!scene,ERR_FILE_CORRUPT); - } - - if (save_instance_state) - scene->generate_instance_state(); - - - Error err; - _apply_meta(scene,metav,loader,connections,err,owner_map); - if (err!=OK) { - error=ERR_FILE_CORRUPT; - memdelete(loader); - ERR_FAIL_COND_V(err!=OK,ERR_FILE_CORRUPT); - } - - Node *parent=root; - - if (meta.has("path")) - parent=root->get_node(meta["path"]); - - - if (!parent) { - - error=ERR_FILE_CORRUPT; - memdelete(loader); - ERR_FAIL_COND_V(!parent,ERR_FILE_CORRUPT); - } - - - if (meta.has("override_names") && meta.has("override_values")) { - - DVector<String> override_names=meta["override_names"]; - Array override_values=meta["override_values"]; - - int len = override_names.size(); - if ( len > 0 && len == override_values.size() ) { - - DVector<String>::Read names = override_names.read(); - - for(int i=0;i<len;i++) { - - scene->set(names[i],override_values[i]); - } - - } - - } - - scene->set_filename(path); - - parent->add_child(scene); - scene->set_owner(root); - } - } - - stage++; - error=OK; - return error; - -} -int SceneInteractiveLoaderObject::get_stage() const { - - return stage; -} -int SceneInteractiveLoaderObject::get_stage_count() const { - - return stage_max; -} - - -#endif diff --git a/scene/io/scene_format_object.h b/scene/io/scene_format_object.h deleted file mode 100644 index 3f0bbd4627..0000000000 --- a/scene/io/scene_format_object.h +++ /dev/null @@ -1,128 +0,0 @@ -/*************************************************************************/ -/* scene_format_object.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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. */ -/*************************************************************************/ -#ifndef SCENE_FORMAT_OBJECT_H -#define SCENE_FORMAT_OBJECT_H - - -#include "scene/main/node.h" -#include "scene/io/scene_saver.h" -#include "scene/io/scene_loader.h" -#include "io/object_saver.h" -#include "io/object_loader.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - - -#ifdef OLD_SCENE_FORMAT_ENABLED - -class SceneFormatSaverObject : public SceneFormatSaver { - - void save_node(const Node* p_root,const Node* p_node,const Node* p_owner,ObjectFormatSaver *p_saver,String p_base_path,uint32_t p_flags,Map<const Node*,uint32_t>& owner_id) const; - -public: - - virtual Error save(const String &p_path,const Node* p_scenezz,uint32_t p_flags=0,const Ref<OptimizedSaver> &p_optimizer=Ref<OptimizedSaver>()); - virtual void get_recognized_extensions(List<String> *p_extensions) const; - virtual ~SceneFormatSaverObject() {} -}; - - - -class SceneFormatLoaderObject : public SceneFormatLoader { - - - struct ConnectionItem { - Node *node; - NodePath target; - StringName method; - StringName signal; - Vector<Variant> binds; - bool realtime; - }; - - Node* load_node(Object *obj, const Variant& meta, Node *p_root, ObjectFormatLoader *p_loader,List<ConnectionItem>& connections,Error& r_err,bool p_root_scene_hint,Map<uint32_t,Node*>& owner_map); - void _apply_connections(List<ConnectionItem>& connections); - void _apply_meta(Node *node, const Variant& meta, ObjectFormatLoader *p_loader,List<ConnectionItem>& connections,Error& r_err,Map<uint32_t,Node*>& owner_map); - -public: - - virtual Ref<SceneInteractiveLoader> load_interactive(const String &p_path,bool p_root_scene_hint=false); - virtual Node* load(const String &p_path,bool p_save_root_state=false); - virtual void get_recognized_extensions(List<String> *p_extensions) const; - -}; - - -class SceneInteractiveLoaderObject : public SceneInteractiveLoader { - - OBJ_TYPE(SceneInteractiveLoaderObject,SceneInteractiveLoader); - - struct ConnectionItem { - Node *node; - NodePath target; - StringName method; - StringName signal; - Vector<Variant> binds; - bool realtime; - }; - ObjectFormatLoader *loader; - String path; - String node_path; - String local_path; - Error error; - bool save_instance_state; - List<ConnectionItem> connections; - Map<uint32_t,Node*> owner_map; - Node *root; - int stage_max; - int stage; - - - Node* load_node(Object *obj, const Variant& meta, Node *p_root, ObjectFormatLoader *p_loader,List<ConnectionItem>& connections,Error& r_err,bool p_root_scene_hint,Map<uint32_t,Node*>& owner_map); - void _apply_connections(List<ConnectionItem>& connections); - void _apply_meta(Node *node, const Variant& meta, ObjectFormatLoader *p_loader,List<ConnectionItem>& connections,Error& r_err,Map<uint32_t,Node*>& owner_map); - -friend class SceneFormatLoaderObject; -public: - - virtual void set_local_path(const String& p_local_path); - virtual Node *get_scene(); - virtual Error poll(); - virtual int get_stage() const; - virtual int get_stage_count() const; - - - SceneInteractiveLoaderObject(const String &p_path,bool p_save_root_state=false); -}; - - - -#endif -#endif diff --git a/scene/io/scene_format_script.cpp b/scene/io/scene_format_script.cpp deleted file mode 100644 index a6f1596d2b..0000000000 --- a/scene/io/scene_format_script.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/*************************************************************************/ -/* scene_format_script.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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. */ -/*************************************************************************/ -#include "scene_format_script.h" -#if 0 -Node* SceneFormatLoaderScript::load(const String &p_path,bool p_save_instance_state) { - - Ref<Script> script = ResourceLoader::load(p_path); - ERR_EXPLAIN("Can't load script-based scene: "+p_path); - ERR_FAIL_COND_V(script.is_null(),NULL); - ERR_EXPLAIN("Script does not instance in a node: "+p_path); - ERR_FAIL_COND_V(script->get_node_type()=="",NULL); - String node_type=script->get_node_type(); - Object *obj = ObjectTypeDB::instance(node_type); - ERR_EXPLAIN("Unknown node type for instancing '"+node_type+"' in script: "+p_path); - ERR_FAIL_COND_V(!obj,NULL); - Node *node = obj->cast_to<Node>(); - if (!node) - memdelete(obj); - ERR_EXPLAIN("Node type '"+node_type+"' not of type 'Node'' in script: "+p_path); - ERR_FAIL_COND_V(!node,NULL); - - node->set_script(script.get_ref_ptr()); - - return node; -} - -void SceneFormatLoaderScript::get_recognized_extensions(List<String> *p_extensions) const { - - for (int i=0;i<ScriptServer::get_language_count();i++) { - - ScriptServer::get_language(i)->get_recognized_extensions(p_extensions); - } -} - - -SceneFormatLoaderScript::SceneFormatLoaderScript() -{ -} -#endif diff --git a/scene/io/scene_format_script.h b/scene/io/scene_format_script.h deleted file mode 100644 index 9bfcc0b1e3..0000000000 --- a/scene/io/scene_format_script.h +++ /dev/null @@ -1,45 +0,0 @@ -/*************************************************************************/ -/* scene_format_script.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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. */ -/*************************************************************************/ -#ifndef SCENE_FORMAT_SCRIPT_H -#define SCENE_FORMAT_SCRIPT_H - -#include "scene/io/scene_loader.h" -#include "io/resource_loader.h" -#if 0 - -class SceneFormatLoaderScript : public SceneFormatLoader { -public: - - virtual Node* load(const String &p_path,bool p_save_instance_state=false); - virtual void get_recognized_extensions(List<String> *p_extensions) const; - - SceneFormatLoaderScript(); -}; -#endif -#endif // SCENE_FORMAT_SCRIPT_H diff --git a/scene/io/scene_loader.cpp b/scene/io/scene_loader.cpp deleted file mode 100644 index 8615e64ae9..0000000000 --- a/scene/io/scene_loader.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/*************************************************************************/ -/* scene_loader.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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. */ -/*************************************************************************/ -#include "scene_loader.h" -#include "globals.h" -#include "path_remap.h" - -#ifdef OLD_SCENE_FORMAT_ENABLED - -SceneFormatLoader *SceneLoader::loader[MAX_LOADERS]; - -int SceneLoader::loader_count=0; - - -void SceneInteractiveLoader::_bind_methods() { - - ObjectTypeDB::bind_method(_MD("get_scene"),&SceneInteractiveLoader::get_scene); - ObjectTypeDB::bind_method(_MD("poll"),&SceneInteractiveLoader::poll); - ObjectTypeDB::bind_method(_MD("get_stage"),&SceneInteractiveLoader::get_stage); - ObjectTypeDB::bind_method(_MD("get_stage_count"),&SceneInteractiveLoader::get_stage_count); -} - -class SceneInteractiveLoaderDefault : public SceneInteractiveLoader { - - OBJ_TYPE( SceneInteractiveLoaderDefault, SceneInteractiveLoader ); -public: - Node *scene; - - virtual void set_local_path(const String& p_local_path) { scene->set_filename(p_local_path); } - virtual Node *get_scene() { return scene; } - virtual Error poll() { return ERR_FILE_EOF; } - virtual int get_stage() const { return 1; } - virtual int get_stage_count() const { return 1; } - - SceneInteractiveLoaderDefault() {} -}; - - -Ref<SceneInteractiveLoader> SceneFormatLoader::load_interactive(const String &p_path,bool p_root_scene_hint) { - - Node *scene = load(p_path,p_root_scene_hint); - if (!scene) - return Ref<SceneInteractiveLoader>(); - Ref<SceneInteractiveLoaderDefault> sil = Ref<SceneInteractiveLoaderDefault>( memnew( SceneInteractiveLoaderDefault )); - sil->scene=scene; - return sil; -} - - - -bool SceneFormatLoader::recognize(const String& p_extension) const { - - - List<String> extensions; - get_recognized_extensions(&extensions); - for (List<String>::Element *E=extensions.front();E;E=E->next()) { - - if (E->get().nocasecmp_to(p_extension.extension())==0) - return true; - } - - return false; -} - -Ref<SceneInteractiveLoader> SceneLoader::load_interactive(const String &p_path,bool p_save_root_state) { - - String local_path=Globals::get_singleton()->localize_path(p_path); - - String remapped_path = PathRemap::get_singleton()->get_remap(local_path); - String extension=remapped_path.extension(); - - for (int i=0;i<loader_count;i++) { - - if (!loader[i]->recognize(extension)) - continue; - Ref<SceneInteractiveLoader> il = loader[i]->load_interactive(remapped_path,p_save_root_state); - - if (il.is_null() && remapped_path!=local_path) - il = loader[i]->load_interactive(local_path,p_save_root_state); - - ERR_EXPLAIN("Error loading scene: "+local_path); - ERR_FAIL_COND_V(il.is_null(),Ref<SceneInteractiveLoader>()); - il->set_local_path(local_path); - - return il; - } - - ERR_EXPLAIN("No loader found for scene: "+p_path); - ERR_FAIL_V(Ref<SceneInteractiveLoader>()); - return Ref<SceneInteractiveLoader>(); -} - -Node* SceneLoader::load(const String &p_path,bool p_root_scene_hint) { - - String local_path=Globals::get_singleton()->localize_path(p_path); - - String remapped_path = PathRemap::get_singleton()->get_remap(local_path); - String extension=remapped_path.extension(); - - for (int i=0;i<loader_count;i++) { - - if (!loader[i]->recognize(extension)) - continue; - Node*node = loader[i]->load(remapped_path,p_root_scene_hint); - - if (!node && remapped_path!=local_path) - node = loader[i]->load(local_path,p_root_scene_hint); - - ERR_EXPLAIN("Error loading scene: "+local_path); - ERR_FAIL_COND_V(!node,NULL); - node->set_filename(local_path); - - return node; - } - - ERR_EXPLAIN("No loader found for scene: "+p_path); - ERR_FAIL_V(NULL); -} - -void SceneLoader::get_recognized_extensions(List<String> *p_extensions) { - - for (int i=0;i<loader_count;i++) { - - loader[i]->get_recognized_extensions(p_extensions); - } - -} - -void SceneLoader::add_scene_format_loader(SceneFormatLoader *p_format_loader) { - - ERR_FAIL_COND( loader_count >= MAX_LOADERS ); - loader[loader_count++]=p_format_loader; -} - - -#endif diff --git a/scene/io/scene_loader.h b/scene/io/scene_loader.h deleted file mode 100644 index 2562fc0520..0000000000 --- a/scene/io/scene_loader.h +++ /dev/null @@ -1,90 +0,0 @@ -/*************************************************************************/ -/* scene_loader.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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. */ -/*************************************************************************/ -#ifndef SCENE_LOADER_H -#define SCENE_LOADER_H - -#include "scene/main/node.h" - -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - -#ifdef OLD_SCENE_FORMAT_ENABLED - -class SceneInteractiveLoader : public Reference { - - OBJ_TYPE(SceneInteractiveLoader,Reference); -protected: - - static void _bind_methods(); -public: - - virtual void set_local_path(const String& p_local_path)=0; - virtual Node *get_scene()=0; - virtual Error poll()=0; - virtual int get_stage() const=0; - virtual int get_stage_count() const=0; - - - SceneInteractiveLoader() {} -}; - -class SceneFormatLoader { -public: - - virtual Ref<SceneInteractiveLoader> load_interactive(const String &p_path,bool p_root_scene_hint=false); - virtual Node* load(const String &p_path,bool p_root_scene_hint=false)=0; - virtual void get_recognized_extensions(List<String> *p_extensions) const=0; - bool recognize(const String& p_extension) const; - - virtual ~SceneFormatLoader() {} -}; - -class SceneLoader { - - enum { - MAX_LOADERS=64 - }; - - static SceneFormatLoader *loader[MAX_LOADERS]; - static int loader_count; - -public: - - static Ref<SceneInteractiveLoader> load_interactive(const String &p_path,bool p_save_root_state=false); - static Node* load(const String &p_path,bool p_save_root_state=false); - static void add_scene_format_loader(SceneFormatLoader *p_format_loader); - static void get_recognized_extensions(List<String> *p_extensions); - - -}; - -#endif - -#endif diff --git a/scene/io/scene_saver.cpp b/scene/io/scene_saver.cpp deleted file mode 100644 index f1b503ef27..0000000000 --- a/scene/io/scene_saver.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/*************************************************************************/ -/* scene_saver.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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. */ -/*************************************************************************/ -#include "scene_saver.h" -#include "print_string.h" - -#ifdef OLD_SCENE_FORMAT_ENABLED -SceneFormatSaver *SceneSaver::saver[MAX_SAVERS]; - -int SceneSaver::saver_count=0; - -bool SceneFormatSaver::recognize(const String& p_extension) const { - - - List<String> extensions; - get_recognized_extensions(&extensions); - for (List<String>::Element *E=extensions.front();E;E=E->next()) { - - - if (E->get().nocasecmp_to(p_extension.extension())==0) - return true; - } - - return false; -} - -Error SceneSaver::save(const String &p_path,const Node* p_scene,uint32_t p_flags,const Ref<OptimizedSaver> &p_optimizer) { - - String extension=p_path.extension(); - Error err=ERR_FILE_UNRECOGNIZED; - bool recognized=false; - - for (int i=0;i<saver_count;i++) { - - if (!saver[i]->recognize(extension)) - continue; - recognized=true; - err = saver[i]->save(p_path,p_scene,p_flags,p_optimizer); - if (err == OK ) - return OK; - } - - if (err) { - if (!recognized) { - ERR_EXPLAIN("No saver format found for scene: "+p_path); - } else { - ERR_EXPLAIN("Couldn't save scene: "+p_path); - } - ERR_FAIL_V(err); - } - - return err; -} - -void SceneSaver::get_recognized_extensions(List<String> *p_extensions) { - - for (int i=0;i<saver_count;i++) { - - saver[i]->get_recognized_extensions(p_extensions); - } -} - -void SceneSaver::add_scene_format_saver(SceneFormatSaver *p_format_saver) { - - ERR_FAIL_COND( saver_count >= MAX_SAVERS ); - saver[saver_count++]=p_format_saver; -} - -#endif diff --git a/scene/io/scene_saver.h b/scene/io/scene_saver.h deleted file mode 100644 index 3028dce133..0000000000 --- a/scene/io/scene_saver.h +++ /dev/null @@ -1,80 +0,0 @@ -/*************************************************************************/ -/* scene_saver.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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. */ -/*************************************************************************/ -#ifndef SCENE_SAVER_H -#define SCENE_SAVER_H - -#include "scene/main/node.h" -#include "io/object_saver.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - - -#ifdef OLD_SCENE_FORMAT_ENABLED - -class SceneFormatSaver { -public: - - virtual Error save(const String &p_path,const Node* p_scen,uint32_t p_flags=0,const Ref<OptimizedSaver> &p_optimizer=Ref<OptimizedSaver>())=0; - virtual void get_recognized_extensions(List<String> *p_extensions) const=0; - bool recognize(const String& p_extension) const; - virtual ~SceneFormatSaver() {} -}; - - - - -class SceneSaver { - - enum { - MAX_SAVERS=64 - }; - - static SceneFormatSaver *saver[MAX_SAVERS]; - static int saver_count; - -public: - enum SaverFlags { - - FLAG_RELATIVE_PATHS=1, - FLAG_BUNDLE_RESOURCES=2, - FLAG_BUNDLE_INSTANCED_SCENES=4, - FLAG_OMIT_EDITOR_PROPERTIES=8, - FLAG_SAVE_BIG_ENDIAN=16 - }; - - static Error save(const String &p_path,const Node* p_scenezz,uint32_t p_flags=0,const Ref<OptimizedSaver> &p_optimizer=Ref<OptimizedSaver>()); - static void add_scene_format_saver(SceneFormatSaver *p_format_saver); - static void get_recognized_extensions(List<String> *p_extensions); -}; - - - -#endif -#endif diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 5d89ee80f1..e511a057c5 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -28,7 +28,6 @@ /*************************************************************************/ #include "node.h" #include "print_string.h" -#include "scene/io/scene_loader.h" #include "message_queue.h" #include "scene/scene_string_names.h" #include "scene/resources/packed_scene.h" diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index 1902ff686b..a5ad38e79c 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -32,7 +32,7 @@ #include "scene/io/resource_format_image.h" #include "scene/io/resource_format_wav.h" -#include "scene/io/scene_format_script.h" +//#include "scene/io/scene_format_script.h" #include "resources/default_theme/default_theme.h" #include "object_type_db.h" #include "scene/main/canvas_layer.h" @@ -120,7 +120,7 @@ #include "scene/resources/scene_preloader.h" #include "scene/main/timer.h" -#include "scene/io/scene_format_object.h" + #include "scene/audio/stream_player.h" #include "scene/audio/event_player.h" #include "scene/audio/sound_room_params.h" @@ -142,7 +142,7 @@ #include "scene/resources/mesh_library.h" -#include "scene/resources/image_path_finder.h" + #include "scene/resources/polygon_path_finder.h" #include "scene/resources/sample.h" @@ -174,7 +174,7 @@ #ifndef _3D_DISABLED #include "scene/3d/camera.h" -#include "scene/3d/editable_shape.h" + #include "scene/3d/interpolated_camera.h" #include "scene/3d/follow_camera.h" #include "scene/3d/position_3d.h" @@ -186,7 +186,7 @@ #include "scene/3d/portal.h" #include "scene/resources/environment.h" #include "scene/3d/physics_body.h" -#include "scene/3d/car_body.h" + #include "scene/3d/vehicle_body.h" #include "scene/3d/body_shape.h" #include "scene/3d/area.h" @@ -204,7 +204,7 @@ #include "scene/3d/collision_polygon.h" #endif -#include "scene/scene_binds.h" + static ResourceFormatLoaderImage *resource_loader_image=NULL; static ResourceFormatLoaderWAV *resource_loader_wav=NULL; @@ -216,15 +216,6 @@ static ResourceFormatLoaderBitMap *resource_loader_bitmap=NULL; #endif static ResourceFormatLoaderTheme *resource_loader_theme=NULL; static ResourceFormatLoaderShader *resource_loader_shader=NULL; -#ifdef OLD_SCENE_FORMAT_ENABLED -static SceneFormatSaverObject *scene_saver_object=NULL; -static SceneFormatLoaderObject *scene_loader_object=NULL; -//static SceneFormatLoaderScript *scene_loader_script=NULL; -#endif - -#ifdef OLD_SCENE_FORMAT_ENABLED -SceneIO *scene_io=NULL; -#endif //static SceneStringNames *string_names; @@ -236,13 +227,6 @@ void register_scene_types() { Node::init_node_hrcr(); -#ifdef OLD_SCENE_FORMAT_ENABLED - ObjectTypeDB::register_type<SceneIO>(); - ObjectTypeDB::register_virtual_type<SceneInteractiveLoader>(); - scene_io = memnew( SceneIO ); - Globals::get_singleton()->add_singleton(Globals::Singleton("SceneIO",scene_io)); -#endif - resource_loader_image = memnew( ResourceFormatLoaderImage ); ResourceLoader::add_resource_format_loader( resource_loader_image ); @@ -263,16 +247,6 @@ void register_scene_types() { resource_loader_shader = memnew( ResourceFormatLoaderShader ); ResourceLoader::add_resource_format_loader( resource_loader_shader ); -#ifdef OLD_SCENE_FORMAT_ENABLED - scene_saver_object=memnew( SceneFormatSaverObject ); - SceneSaver::add_scene_format_saver(scene_saver_object); - - scene_loader_object=memnew( SceneFormatLoaderObject ); - SceneLoader::add_scene_format_loader(scene_loader_object); - -// scene_loader_script=memnew( SceneFormatLoaderScript ); -// SceneLoader::add_scene_format_loader(scene_loader_script); -#endif make_default_theme(); @@ -405,8 +379,8 @@ void register_scene_types() { ObjectTypeDB::register_type<StaticBody>(); ObjectTypeDB::register_type<RigidBody>(); ObjectTypeDB::register_type<KinematicBody>(); - ObjectTypeDB::register_type<CarBody>(); - ObjectTypeDB::register_type<CarWheel>(); + + ObjectTypeDB::register_type<VehicleBody>(); ObjectTypeDB::register_type<VehicleWheel>(); ObjectTypeDB::register_type<Area>(); @@ -414,8 +388,6 @@ void register_scene_types() { ObjectTypeDB::register_type<CollisionShape>(); ObjectTypeDB::register_type<CollisionPolygon>(); ObjectTypeDB::register_type<RayCast>(); - ObjectTypeDB::register_virtual_type<EditableShape>(); - ObjectTypeDB::register_type<EditableSphere>(); ObjectTypeDB::register_type<MultiMeshInstance>(); ObjectTypeDB::register_type<Room>(); ObjectTypeDB::register_type<Curve3D>(); @@ -561,7 +533,7 @@ void register_scene_types() { ObjectTypeDB::register_type<StyleBoxFlat>(); ObjectTypeDB::register_type<StyleBoxImageMask>(); ObjectTypeDB::register_type<Theme>(); - ObjectTypeDB::register_type<ImagePathFinder>(); + ObjectTypeDB::register_type<PolygonPathFinder>(); ObjectTypeDB::register_type<BitMap>(); @@ -592,10 +564,6 @@ void register_scene_types() { OS::get_singleton()->yield(); //may take time to init ObjectTypeDB::register_type<PackedScene>(); -#ifdef OLD_SCENE_FORMAT_ENABLED - ObjectTypeDB::register_type<ScenePreloader>(); -#endif - ObjectTypeDB::register_type<SceneMainLoop>(); @@ -619,11 +587,5 @@ void unregister_scene_types() { memdelete( resource_loader_theme ); memdelete( resource_loader_shader ); -#ifdef OLD_SCENE_FORMAT_ENABLED - memdelete( scene_saver_object ); - memdelete( scene_loader_object ); -// memdelete( scene_loader_script ); - memdelete( scene_io ); -#endif SceneStringNames::free(); } diff --git a/scene/resources/image_path_finder.cpp b/scene/resources/image_path_finder.cpp deleted file mode 100644 index 1a7758789c..0000000000 --- a/scene/resources/image_path_finder.cpp +++ /dev/null @@ -1,427 +0,0 @@ -/*************************************************************************/ -/* image_path_finder.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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. */ -/*************************************************************************/ -#include "image_path_finder.h"
-
-
-void ImagePathFinder::_unlock() {
-
- lock=DVector<Cell>::Write();
- cells=NULL;
-
-}
-
-void ImagePathFinder::_lock() {
-
- lock = cell_data.write();
- cells=lock.ptr();
-
-}
-
-
-bool ImagePathFinder::_can_go_straigth(const Point2& p_from, const Point2& p_to) const {
-
- int x1=p_from.x;
- int y1=p_from.y;
- int x2=p_to.x;
- int y2=p_to.y;
-
-#define _TEST_VALID \
- {\
- uint32_t ofs=drawy*width+drawx;\
- if (cells[ofs].solid) {\
- if (!((drawx>0 && cells[ofs-1].visited) ||\
- (drawx<width-1 && cells[ofs+1].visited) ||\
- (drawy>0 && cells[ofs-width].visited) ||\
- (drawy<height-1 && cells[ofs+width].visited))) {\
- return false;\
- }\
- }\
- }\
-
-
- int n, deltax, deltay, sgndeltax, sgndeltay, deltaxabs, deltayabs, x, y, drawx, drawy;
- deltax = x2 - x1;
- deltay = y2 - y1;
- deltaxabs = ABS(deltax);
- deltayabs = ABS(deltay);
- sgndeltax = SGN(deltax);
- sgndeltay = SGN(deltay);
- x = deltayabs >> 1;
- y = deltaxabs >> 1;
- drawx = x1;
- drawy = y1;
- int pc=0;
-
- _TEST_VALID
-
- if(deltaxabs >= deltayabs) {
- for(n = 0; n < deltaxabs; n++) {
- y += deltayabs;
- if(y >= deltaxabs){
- y -= deltaxabs;
- drawy += sgndeltay;
- }
- drawx += sgndeltax;
- _TEST_VALID
- }
- } else {
- for(n = 0; n < deltayabs; n++) {
- x += deltaxabs;
- if(x >= deltayabs) {
- x -= deltayabs;
- drawx += sgndeltax;
- }
- drawy += sgndeltay;
- _TEST_VALID
- }
- }
- return true;
-
-
-}
-
-bool ImagePathFinder::_is_linear_path(const Point2& p_from, const Point2& p_to) {
-
- int x1=p_from.x;
- int y1=p_from.y;
- int x2=p_to.x;
- int y2=p_to.y;
-
-#define _TEST_CELL \
- if (cells[drawy*width+drawx].solid)\
- return false;
-
-
- int n, deltax, deltay, sgndeltax, sgndeltay, deltaxabs, deltayabs, x, y, drawx, drawy;
- deltax = x2 - x1;
- deltay = y2 - y1;
- deltaxabs = ABS(deltax);
- deltayabs = ABS(deltay);
- sgndeltax = SGN(deltax);
- sgndeltay = SGN(deltay);
- x = deltayabs >> 1;
- y = deltaxabs >> 1;
- drawx = x1;
- drawy = y1;
- int pc=0;
-
- _TEST_CELL
-
- if(deltaxabs >= deltayabs) {
- for(n = 0; n < deltaxabs; n++) {
- y += deltayabs;
- if(y >= deltaxabs){
- y -= deltaxabs;
- drawy += sgndeltay;
- }
- drawx += sgndeltax;
- _TEST_CELL
- }
- } else {
- for(n = 0; n < deltayabs; n++) {
- x += deltaxabs;
- if(x >= deltayabs) {
- x -= deltayabs;
- drawx += sgndeltax;
- }
- drawy += sgndeltay;
- _TEST_CELL
- }
- }
- return true;
-}
-
-
-DVector<Point2> ImagePathFinder::find_path(const Point2& p_from, const Point2& p_to,bool p_optimize) {
-
-
- Point2i from=p_from;
- Point2i to=p_to;
-
- ERR_FAIL_COND_V(from.x < 0,DVector<Point2>());
- ERR_FAIL_COND_V(from.y < 0,DVector<Point2>());
- ERR_FAIL_COND_V(from.x >=width,DVector<Point2>());
- ERR_FAIL_COND_V(from.y >=height,DVector<Point2>());
- ERR_FAIL_COND_V(to.x < 0,DVector<Point2>());
- ERR_FAIL_COND_V(to.y < 0,DVector<Point2>());
- ERR_FAIL_COND_V(to.x >=width,DVector<Point2>());
- ERR_FAIL_COND_V(to.y >=height,DVector<Point2>());
-
- if (from==to) {
- DVector<Point2> p;
- p.push_back(from);
- return p;
- }
-
- _lock();
-
-
- if (p_optimize) { //try a line first
-
- if (_is_linear_path(p_from,p_to)) {
- _unlock();
- DVector<Point2> p;
- p.push_back(from);
- p.push_back(to);
- return p;
- }
- }
-
-
- //clear all
- for(int i=0;i<width*height;i++) {
-
- bool s = cells[i].solid;
- cells[i].data=0;
- cells[i].solid=s;
- }
-
-#define CELL_INDEX(m_p) (m_p.y*width+m_p.x)
-#define CELL_COST(m_p) (cells[CELL_INDEX(m_p)].cost+( ABS(m_p.x-to.x)+ABS(m_p.y-to.y))*10)
-
-
- Set<Point2i> pending;
- pending.insert(from);
-
- //helper constants
- static const Point2i neighbour_rel[8]={
- Point2i(-1,-1), //0
- Point2i(-1, 0), //1
- Point2i(-1,+1), //2
- Point2i( 0,-1), //3
- Point2i( 0,+1), //4
- Point2i(+1,-1), //5
- Point2i(+1, 0), //6
- Point2i(+1,+1) }; //7
-
- static const int neighbour_cost[8]={
- 14,
- 10,
- 14,
- 10,
- 10,
- 14,
- 10,
- 14
- };
-
- static const int neighbour_parent[8]={
- 7,
- 6,
- 5,
- 4,
- 3,
- 2,
- 1,
- 0,
- };
-
- while(true) {
-
- if (pending.size() == 0) {
- _unlock();
- return DVector<Point2>(); // points don't connect
- }
- Point2i current;
- int lc=0x7FFFFFFF;
- { //find the one with the least cost
-
- Set<Point2i>::Element *Efound=NULL;
- for (Set<Point2i>::Element *E=pending.front();E;E=E->next()) {
-
- int cc =CELL_COST(E->get());
- if (cc<lc) {
- lc=cc;
- current=E->get();
- Efound=E;
-
- }
-
- }
- pending.erase(Efound);
- }
-
- Cell &c = cells[CELL_INDEX(current)];
-
- //search around other cells
-
-
- int accum_cost = (from==current) ? 0 : cells[CELL_INDEX((current + neighbour_rel[c.parent]))].cost;
-
- bool done=false;
-
- for(int i=0;i<8;i++) {
-
- Point2i neighbour=current+neighbour_rel[i];
- if (neighbour.x<0 || neighbour.y<0 || neighbour.x>=width || neighbour.y>=height)
- continue;
-
- Cell &n = cells[CELL_INDEX(neighbour)];
- if (n.solid)
- continue; //no good
-
- int cost = neighbour_cost[i]+accum_cost;
-
- if (n.visited && n.cost < cost)
- continue;
-
- n.cost=cost;
- n.parent=neighbour_parent[i];
- n.visited=true;
- pending.insert(neighbour);
- if (neighbour==to)
- done=true;
-
- }
-
- if (done)
- break;
- }
-
-
- // go througuh poins twice, first compute amount, then add them
-
- Point2i current=to;
- int pcount=0;
-
- while(true) {
-
- Cell &c = cells[CELL_INDEX(current)];
- c.visited=true;
- pcount++;
- if (current==from)
- break;
- current+=neighbour_rel[ c.parent ];
- }
-
- //now place them in an array
- DVector<Vector2> result;
- result.resize(pcount);
-
- DVector<Vector2>::Write res=result.write();
-
- current=to;
- int pidx=pcount-1;
-
- while(true) {
-
- Cell &c = cells[CELL_INDEX(current)];
- res[pidx]=current;
- pidx--;
- if (current==from)
- break;
- current+=neighbour_rel[ c.parent ];
- }
-
-
- //simplify..
-
-
- if (p_optimize) {
-
- int p=pcount-1;
- while(p>0) {
-
-
- int limit=p;
- while(limit>0) {
-
- limit--;
- if (!_can_go_straigth(res[p],res[limit]))
- break;
- }
-
-
- if (limit<p-1) {
- int diff = p-limit-1;
- pcount-=diff;
- for(int i=limit+1;i<pcount;i++) {
-
- res[i]=res[i+diff];
- }
- }
- p=limit;
- }
- }
-
- res=DVector<Vector2>::Write();
- result.resize(pcount);
- return result;
-}
-
-Size2 ImagePathFinder::get_size() const {
-
- return Size2(width,height);
-}
-bool ImagePathFinder::is_solid(const Point2& p_pos) {
-
-
- Point2i pos = p_pos;
-
- ERR_FAIL_COND_V(pos.x<0,true);
- ERR_FAIL_COND_V(pos.y<0,true);
- ERR_FAIL_COND_V(pos.x>=width,true);
- ERR_FAIL_COND_V(pos.y>=height,true);
-
- return cell_data[pos.y*width+pos.x].solid;
-}
-
-void ImagePathFinder::create_from_image_alpha(const Image& p_image) {
-
- ERR_FAIL_COND(p_image.get_format() != Image::FORMAT_RGBA);
- width = p_image.get_width();
- height = p_image.get_height();
- DVector<uint8_t> data = p_image.get_data();
- cell_data.resize(width * height);
- DVector<uint8_t>::Read read = data.read();
- DVector<Cell>::Write write = cell_data.write();
- for (int i=0; i<width * height; i++) {
- Cell cell;
- cell.data = 0;
- cell.solid = read[i*4+3] < 128;
- write[i] = cell;
- };
-};
-
-
-void ImagePathFinder::_bind_methods() {
-
- ObjectTypeDB::bind_method(_MD("find_path","from","to","optimize"),&ImagePathFinder::find_path,DEFVAL(false));
- ObjectTypeDB::bind_method(_MD("get_size"),&ImagePathFinder::get_size);
- ObjectTypeDB::bind_method(_MD("is_solid","pos"),&ImagePathFinder::is_solid);
- ObjectTypeDB::bind_method(_MD("create_from_image_alpha"),&ImagePathFinder::create_from_image_alpha);
-}
-
-ImagePathFinder::ImagePathFinder()
-{
-
- cells=NULL;
- width=0;
- height=0;
-}
diff --git a/scene/resources/image_path_finder.h b/scene/resources/image_path_finder.h deleted file mode 100644 index e975ea5ed9..0000000000 --- a/scene/resources/image_path_finder.h +++ /dev/null @@ -1,84 +0,0 @@ -/*************************************************************************/ -/* image_path_finder.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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. */ -/*************************************************************************/ -#ifndef IMAGE_PATH_FINDER_H
-#define IMAGE_PATH_FINDER_H
-
-#include "resource.h"
-
-class ImagePathFinder : public Resource{
-
-
- OBJ_TYPE(ImagePathFinder,Resource);
- union Cell {
-
- struct {
- bool solid:1;
- bool visited:1;
- bool final:1;
- uint8_t parent:3;
- uint32_t cost:26;
- };
-
- uint32_t data;
- };
-
-
-
-
-
- DVector<Cell>::Write lock;
- DVector<Cell> cell_data;
-
- uint32_t width;
- uint32_t height;
- Cell* cells; //when unlocked
-
- void _unlock();
- void _lock();
-
-
- _FORCE_INLINE_ bool _can_go_straigth(const Point2& p_from, const Point2& p_to) const;
- _FORCE_INLINE_ bool _is_linear_path(const Point2& p_from, const Point2& p_to);
-
-protected:
-
- static void _bind_methods();
-public:
-
- DVector<Point2> find_path(const Point2& p_from, const Point2& p_to,bool p_optimize=false);
- Size2 get_size() const;
- bool is_solid(const Point2& p_pos);
- void create_from_image_alpha(const Image& p_image);
-
-
-
- ImagePathFinder();
-};
-
-#endif // IMAGE_PATH_FINDER_H
diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index 3109556922..76e4aad81e 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -29,6 +29,9 @@ #include "packed_scene.h" #include "globals.h" #include "io/resource_loader.h" +#include "scene/3d/spatial.h" +#include "scene/gui/control.h" +#include "scene/2d/node_2d.h" bool PackedScene::can_instance() const { @@ -80,9 +83,26 @@ Node *PackedScene::instance(bool p_gen_edit_state) const { } else { //create anew Object * obj = ObjectTypeDB::instance(snames[ n.type ]); - ERR_FAIL_COND_V(!obj,NULL); - node = obj->cast_to<Node>(); - ERR_FAIL_COND_V(!node,NULL); + if (!obj || !obj->cast_to<Node>()) { + if (obj) { + memdelete(obj); + obj=NULL; + } + WARN_PRINT(String("Warning node of type "+snames[n.type].operator String()+" does not exist.").ascii().get_data()); + if (n.parent>=0 && n.parent<nc && ret_nodes[n.parent]) { + if (ret_nodes[n.parent]->cast_to<Spatial>()) { + obj = memnew( Spatial ); + } else if (ret_nodes[n.parent]->cast_to<Control>()) { + obj = memnew( Control ); + } else if (ret_nodes[n.parent]->cast_to<Node2D>()) { + obj = memnew( Node2D ); + } + + } + if (!obj) { + obj = memnew( Node ); + } + } } diff --git a/scene/resources/scene_preloader.cpp b/scene/resources/scene_preloader.cpp index 59d8cae970..e37a2c4967 100644 --- a/scene/resources/scene_preloader.cpp +++ b/scene/resources/scene_preloader.cpp @@ -26,430 +26,429 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "scene_preloader.h"
-#include "scene/io/scene_loader.h"
-#include "globals.h"
-
-bool ScenePreloader::can_instance() const {
-
- return nodes.size()>0;
-}
-
-Node *ScenePreloader::instance() const {
-
- int nc = nodes.size();
- ERR_FAIL_COND_V(nc==0,NULL);
-
- const StringName*snames=NULL;
- int sname_count=names.size();
- if (sname_count)
- snames=&names[0];
-
- const Variant*props=NULL;
- int prop_count=variants.size();
- if (prop_count)
- props=&variants[0];
-
- Vector<Variant> properties;
-
- const NodeData *nd = &nodes[0];
-
- Node **ret_nodes=(Node**)alloca( sizeof(Node*)*nc );
-
- for(int i=0;i<nc;i++) {
-
- const NodeData &n=nd[i];
-
-
- if (!ObjectTypeDB::is_type_enabled(snames[n.type])) {
- ret_nodes[i]=NULL;
- continue;
- }
-
- Object * obj = ObjectTypeDB::instance(snames[ n.type ]);
- ERR_FAIL_COND_V(!obj,NULL);
- Node *node = obj->cast_to<Node>();
- ERR_FAIL_COND_V(!node,NULL);
-
- int nprop_count=n.properties.size();
- if (nprop_count) {
-
- const NodeData::Property* nprops=&n.properties[0];
-
- for(int j=0;j<nprop_count;j++) {
-
- bool valid;
- node->set(snames[ nprops[j].name ],props[ nprops[j].value ],&valid);
- }
-
-
- }
-
- node->set_name( snames[ n.name ] );
- ret_nodes[i]=node;
- if (i>0) {
- ERR_FAIL_INDEX_V(n.parent,i,NULL);
- ERR_FAIL_COND_V(!ret_nodes[n.parent],NULL);
- ret_nodes[n.parent]->add_child(node);
- }
- }
-
-
- //do connections
-
- int cc = connections.size();
- const ConnectionData *cdata = connections.ptr();
-
- for(int i=0;i<cc;i++) {
-
- const ConnectionData &c=cdata[i];
- ERR_FAIL_INDEX_V( c.from, nc, NULL );
- ERR_FAIL_INDEX_V( c.to, nc, NULL );
-
- Vector<Variant> binds;
- if (c.binds.size()) {
- binds.resize(c.binds.size());
- for(int j=0;j<c.binds.size();j++)
- binds[j]=props[ c.binds[j] ];
- }
-
- if (!ret_nodes[c.from] || !ret_nodes[c.to])
- continue;
- ret_nodes[c.from]->connect( snames[ c.signal], ret_nodes[ c.to ], snames[ c.method], binds,CONNECT_PERSIST );
- }
-
- return ret_nodes[0];
-
-}
-
-
-static int _nm_get_string(const String& p_string, Map<StringName,int> &name_map) {
-
- if (name_map.has(p_string))
- return name_map[p_string];
-
- int idx = name_map.size();
- name_map[p_string]=idx;
- return idx;
-}
-
-static int _vm_get_variant(const Variant& p_variant, HashMap<Variant,int,VariantHasher> &variant_map) {
-
- if (variant_map.has(p_variant))
- return variant_map[p_variant];
-
- int idx = variant_map.size();
- variant_map[p_variant]=idx;
- return idx;
-}
-
-void ScenePreloader::_parse_node(Node *p_owner,Node *p_node,int p_parent_idx, Map<StringName,int> &name_map,HashMap<Variant,int,VariantHasher> &variant_map,Map<Node*,int> &node_map) {
-
- if (p_node!=p_owner && !p_node->get_owner())
- return;
-
- NodeData nd;
- nd.name=_nm_get_string(p_node->get_name(),name_map);
- nd.type=_nm_get_string(p_node->get_type(),name_map);
- nd.parent=p_parent_idx;
-
- List<PropertyInfo> plist;
- p_node->get_property_list(&plist);
- for (List<PropertyInfo>::Element *E=plist.front();E;E=E->next()) {
-
- if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
- continue;
-
- NodeData::Property prop;
- prop.name=_nm_get_string(E->get().name,name_map);
- prop.value=_vm_get_variant( p_node->get( E->get().name ), variant_map);
- nd.properties.push_back(prop);
- }
-
- int idx = nodes.size();
- node_map[p_node]=idx;
- nodes.push_back(nd);
-
- for(int i=0;i<p_node->get_child_count();i++) {
-
- Node *c=p_node->get_child(i);
- _parse_node(p_owner,c,idx,name_map,variant_map,node_map);
- }
-
-
-
-}
-
-void ScenePreloader::_parse_connections(Node *p_node, Map<StringName,int> &name_map,HashMap<Variant,int,VariantHasher> &variant_map,Map<Node*,int> &node_map,bool p_instance) {
-
-
- List<MethodInfo> signals;
- p_node->get_signal_list(&signals);
-
- for(List<MethodInfo>::Element *E=signals.front();E;E=E->next()) {
-
- List<Node::Connection> conns;
- p_node->get_signal_connection_list(E->get().name,&conns);
- for(List<Node::Connection>::Element *F=conns.front();F;F=F->next()) {
-
- const Node::Connection &c = F->get();
- if (!(c.flags&CONNECT_PERSIST))
- continue;
- Node *n=c.target->cast_to<Node>();
- if (!n)
- continue;
-
- if (!node_map.has(n))
- continue;
-
- ConnectionData cd;
- cd.from=node_map[p_node];
- cd.to=node_map[n];
- cd.method=_nm_get_string(c.method,name_map);
- cd.signal=_nm_get_string(c.signal,name_map);
- for(int i=0;i<c.binds.size();i++) {
-
- cd.binds.push_back( _vm_get_variant(c.binds[i],variant_map));
- }
- connections.push_back(cd);
- }
- }
-
-}
-
-
-Error ScenePreloader::load_scene(const String& p_path) {
-
- return ERR_CANT_OPEN;
-#if 0
- if (path==p_path)
- return OK;
-
- String p=Globals::get_singleton()->localize_path(p_path);
- clear();
-
- Node *scene = SceneLoader::load(p);
-
- ERR_FAIL_COND_V(!scene,ERR_CANT_OPEN);
-
- path=p;
-
- Map<StringName,int> name_map;
- HashMap<Variant,int,VariantHasher> variant_map;
- Map<Node*,int> node_map;
-
- _parse_node(scene,scene,-1,name_map,variant_map,node_map);
-
-
- names.resize(name_map.size());
-
- for(Map<StringName,int>::Element *E=name_map.front();E;E=E->next()) {
-
- names[E->get()]=E->key();
- }
-
- variants.resize(variant_map.size());
- const Variant *K=NULL;
- while((K=variant_map.next(K))) {
-
- int idx = variant_map[*K];
- variants[idx]=*K;
- }
-
-
- memdelete(scene); // <- me falto esto :(
- return OK;
-#endif
-}
-
-String ScenePreloader::get_scene_path() const {
-
- return path;
-}
-
-void ScenePreloader::clear() {
-
- names.clear();
- variants.clear();
- nodes.clear();
- connections.clear();
-
-}
-
-void ScenePreloader::_set_bundled_scene(const Dictionary& d) {
-
-
- ERR_FAIL_COND( !d.has("names"));
- ERR_FAIL_COND( !d.has("variants"));
- ERR_FAIL_COND( !d.has("node_count"));
- ERR_FAIL_COND( !d.has("nodes"));
- ERR_FAIL_COND( !d.has("conn_count"));
- ERR_FAIL_COND( !d.has("conns"));
- ERR_FAIL_COND( !d.has("path"));
-
- DVector<String> snames = d["names"];
- if (snames.size()) {
-
- int namecount = snames.size();
- names.resize(namecount);
- DVector<String>::Read r =snames.read();
- for(int i=0;i<names.size();i++)
- names[i]=r[i];
- }
-
- Array svariants = d["variants"];
-
- if (svariants.size()) {
- int varcount=svariants.size();
- variants.resize(varcount);
- for(int i=0;i<varcount;i++) {
-
- variants[i]=svariants[i];
- }
-
- } else {
- variants.clear();
- }
-
- nodes.resize(d["node_count"]);
- int nc=nodes.size();
- if (nc) {
- DVector<int> snodes = d["nodes"];
- DVector<int>::Read r = snodes.read();
- int idx=0;
- for(int i=0;i<nc;i++) {
- NodeData &nd = nodes[i];
- nd.parent=r[idx++];
- nd.type=r[idx++];
- nd.name=r[idx++];
- nd.properties.resize(r[idx++]);
- for(int j=0;j<nd.properties.size();j++) {
-
- nd.properties[j].name=r[idx++];
- nd.properties[j].value=r[idx++];
- }
- }
-
- }
-
- connections.resize(d["conn_count"]);
- int cc=connections.size();
-
- if (cc) {
-
- DVector<int> sconns = d["conns"];
- DVector<int>::Read r = sconns.read();
- int idx=0;
- for(int i=0;i<nc;i++) {
- ConnectionData &cd = connections[nc];
- cd.from=r[idx++];
- cd.to=r[idx++];
- cd.signal=r[idx++];
- cd.method=r[idx++];
- cd.binds.resize(r[idx++]);
- for(int j=0;j<cd.binds.size();j++) {
-
- cd.binds[j]=r[idx++];
- }
- }
-
- }
-
-
-
- path=d["path"];
-
-}
-
-Dictionary ScenePreloader::_get_bundled_scene() const {
-
- DVector<String> rnames;
- rnames.resize(names.size());
-
- if (names.size()) {
-
- DVector<String>::Write r=rnames.write();
-
- for(int i=0;i<names.size();i++)
- r[i]=names[i];
- }
-
- Dictionary d;
- d["names"]=rnames;
- d["variants"]=variants;
-
- Vector<int> rnodes;
- d["node_count"]=nodes.size();
-
- for(int i=0;i<nodes.size();i++) {
-
- const NodeData &nd=nodes[i];
- rnodes.push_back(nd.parent);
- rnodes.push_back(nd.type);
- rnodes.push_back(nd.name);
- rnodes.push_back(nd.properties.size());
- for(int j=0;j<nd.properties.size();j++) {
-
- rnodes.push_back(nd.properties[j].name);
- rnodes.push_back(nd.properties[j].value);
- }
- }
-
- d["nodes"]=rnodes;
-
- Vector<int> rconns;
- d["conn_count"]=connections.size();
-
- for(int i=0;i<connections.size();i++) {
-
- const ConnectionData &cd=connections[i];
- rconns.push_back(cd.from);
- rconns.push_back(cd.to);
- rconns.push_back(cd.signal);
- rconns.push_back(cd.method);
- rconns.push_back(cd.binds.size());
- for(int j=0;j<cd.binds.size();i++)
- rconns.push_back(cd.binds[j]);
-
- }
-
- d["conns"]=rconns;
-
- d["path"]=path;
-
- return d;
-
-
-}
-
-void ScenePreloader::_bind_methods() {
-
- ObjectTypeDB::bind_method(_MD("load_scene","path"),&ScenePreloader::load_scene);
- ObjectTypeDB::bind_method(_MD("get_scene_path"),&ScenePreloader::get_scene_path);
- ObjectTypeDB::bind_method(_MD("instance:Node"),&ScenePreloader::instance);
- ObjectTypeDB::bind_method(_MD("can_instance"),&ScenePreloader::can_instance);
- ObjectTypeDB::bind_method(_MD("_set_bundled_scene"),&ScenePreloader::_set_bundled_scene);
- ObjectTypeDB::bind_method(_MD("_get_bundled_scene"),&ScenePreloader::_get_bundled_scene);
-
- ADD_PROPERTY( PropertyInfo(Variant::DICTIONARY,"_bundled",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_BUNDLE),_SCS("_set_bundled_scene"),_SCS("_get_bundled_scene"));
-#if 0
- List<String> extensions;
- SceneLoader::get_recognized_extensions(&extensions);
- String exthint;
- for (List<String>::Element*E=extensions.front();E;E=E->next()) {
-
- if (exthint!="")
- exthint+=",";
- exthint+="*."+E->get();
- }
-
- exthint+="; Scenes";
-
- ADD_PROPERTY( PropertyInfo(Variant::STRING,"scene",PROPERTY_HINT_FILE,exthint),_SCS("load_scene"),_SCS("get_scene_path"));
-#endif
-}
-
-ScenePreloader::ScenePreloader() {
-
-
-}
+#include "scene_preloader.h" +#include "globals.h" + +bool ScenePreloader::can_instance() const { + + return nodes.size()>0; +} + +Node *ScenePreloader::instance() const { + + int nc = nodes.size(); + ERR_FAIL_COND_V(nc==0,NULL); + + const StringName*snames=NULL; + int sname_count=names.size(); + if (sname_count) + snames=&names[0]; + + const Variant*props=NULL; + int prop_count=variants.size(); + if (prop_count) + props=&variants[0]; + + Vector<Variant> properties; + + const NodeData *nd = &nodes[0]; + + Node **ret_nodes=(Node**)alloca( sizeof(Node*)*nc ); + + for(int i=0;i<nc;i++) { + + const NodeData &n=nd[i]; + + + if (!ObjectTypeDB::is_type_enabled(snames[n.type])) { + ret_nodes[i]=NULL; + continue; + } + + Object * obj = ObjectTypeDB::instance(snames[ n.type ]); + ERR_FAIL_COND_V(!obj,NULL); + Node *node = obj->cast_to<Node>(); + ERR_FAIL_COND_V(!node,NULL); + + int nprop_count=n.properties.size(); + if (nprop_count) { + + const NodeData::Property* nprops=&n.properties[0]; + + for(int j=0;j<nprop_count;j++) { + + bool valid; + node->set(snames[ nprops[j].name ],props[ nprops[j].value ],&valid); + } + + + } + + node->set_name( snames[ n.name ] ); + ret_nodes[i]=node; + if (i>0) { + ERR_FAIL_INDEX_V(n.parent,i,NULL); + ERR_FAIL_COND_V(!ret_nodes[n.parent],NULL); + ret_nodes[n.parent]->add_child(node); + } + } + + + //do connections + + int cc = connections.size(); + const ConnectionData *cdata = connections.ptr(); + + for(int i=0;i<cc;i++) { + + const ConnectionData &c=cdata[i]; + ERR_FAIL_INDEX_V( c.from, nc, NULL ); + ERR_FAIL_INDEX_V( c.to, nc, NULL ); + + Vector<Variant> binds; + if (c.binds.size()) { + binds.resize(c.binds.size()); + for(int j=0;j<c.binds.size();j++) + binds[j]=props[ c.binds[j] ]; + } + + if (!ret_nodes[c.from] || !ret_nodes[c.to]) + continue; + ret_nodes[c.from]->connect( snames[ c.signal], ret_nodes[ c.to ], snames[ c.method], binds,CONNECT_PERSIST ); + } + + return ret_nodes[0]; + +} + + +static int _nm_get_string(const String& p_string, Map<StringName,int> &name_map) { + + if (name_map.has(p_string)) + return name_map[p_string]; + + int idx = name_map.size(); + name_map[p_string]=idx; + return idx; +} + +static int _vm_get_variant(const Variant& p_variant, HashMap<Variant,int,VariantHasher> &variant_map) { + + if (variant_map.has(p_variant)) + return variant_map[p_variant]; + + int idx = variant_map.size(); + variant_map[p_variant]=idx; + return idx; +} + +void ScenePreloader::_parse_node(Node *p_owner,Node *p_node,int p_parent_idx, Map<StringName,int> &name_map,HashMap<Variant,int,VariantHasher> &variant_map,Map<Node*,int> &node_map) { + + if (p_node!=p_owner && !p_node->get_owner()) + return; + + NodeData nd; + nd.name=_nm_get_string(p_node->get_name(),name_map); + nd.type=_nm_get_string(p_node->get_type(),name_map); + nd.parent=p_parent_idx; + + List<PropertyInfo> plist; + p_node->get_property_list(&plist); + for (List<PropertyInfo>::Element *E=plist.front();E;E=E->next()) { + + if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) + continue; + + NodeData::Property prop; + prop.name=_nm_get_string(E->get().name,name_map); + prop.value=_vm_get_variant( p_node->get( E->get().name ), variant_map); + nd.properties.push_back(prop); + } + + int idx = nodes.size(); + node_map[p_node]=idx; + nodes.push_back(nd); + + for(int i=0;i<p_node->get_child_count();i++) { + + Node *c=p_node->get_child(i); + _parse_node(p_owner,c,idx,name_map,variant_map,node_map); + } + + + +} + +void ScenePreloader::_parse_connections(Node *p_node, Map<StringName,int> &name_map,HashMap<Variant,int,VariantHasher> &variant_map,Map<Node*,int> &node_map,bool p_instance) { + + + List<MethodInfo> signals; + p_node->get_signal_list(&signals); + + for(List<MethodInfo>::Element *E=signals.front();E;E=E->next()) { + + List<Node::Connection> conns; + p_node->get_signal_connection_list(E->get().name,&conns); + for(List<Node::Connection>::Element *F=conns.front();F;F=F->next()) { + + const Node::Connection &c = F->get(); + if (!(c.flags&CONNECT_PERSIST)) + continue; + Node *n=c.target->cast_to<Node>(); + if (!n) + continue; + + if (!node_map.has(n)) + continue; + + ConnectionData cd; + cd.from=node_map[p_node]; + cd.to=node_map[n]; + cd.method=_nm_get_string(c.method,name_map); + cd.signal=_nm_get_string(c.signal,name_map); + for(int i=0;i<c.binds.size();i++) { + + cd.binds.push_back( _vm_get_variant(c.binds[i],variant_map)); + } + connections.push_back(cd); + } + } + +} + + +Error ScenePreloader::load_scene(const String& p_path) { + + return ERR_CANT_OPEN; +#if 0 + if (path==p_path) + return OK; + + String p=Globals::get_singleton()->localize_path(p_path); + clear(); + + Node *scene = SceneLoader::load(p); + + ERR_FAIL_COND_V(!scene,ERR_CANT_OPEN); + + path=p; + + Map<StringName,int> name_map; + HashMap<Variant,int,VariantHasher> variant_map; + Map<Node*,int> node_map; + + _parse_node(scene,scene,-1,name_map,variant_map,node_map); + + + names.resize(name_map.size()); + + for(Map<StringName,int>::Element *E=name_map.front();E;E=E->next()) { + + names[E->get()]=E->key(); + } + + variants.resize(variant_map.size()); + const Variant *K=NULL; + while((K=variant_map.next(K))) { + + int idx = variant_map[*K]; + variants[idx]=*K; + } + + + memdelete(scene); // <- me falto esto :( + return OK; +#endif +} + +String ScenePreloader::get_scene_path() const { + + return path; +} + +void ScenePreloader::clear() { + + names.clear(); + variants.clear(); + nodes.clear(); + connections.clear(); + +} + +void ScenePreloader::_set_bundled_scene(const Dictionary& d) { + + + ERR_FAIL_COND( !d.has("names")); + ERR_FAIL_COND( !d.has("variants")); + ERR_FAIL_COND( !d.has("node_count")); + ERR_FAIL_COND( !d.has("nodes")); + ERR_FAIL_COND( !d.has("conn_count")); + ERR_FAIL_COND( !d.has("conns")); + ERR_FAIL_COND( !d.has("path")); + + DVector<String> snames = d["names"]; + if (snames.size()) { + + int namecount = snames.size(); + names.resize(namecount); + DVector<String>::Read r =snames.read(); + for(int i=0;i<names.size();i++) + names[i]=r[i]; + } + + Array svariants = d["variants"]; + + if (svariants.size()) { + int varcount=svariants.size(); + variants.resize(varcount); + for(int i=0;i<varcount;i++) { + + variants[i]=svariants[i]; + } + + } else { + variants.clear(); + } + + nodes.resize(d["node_count"]); + int nc=nodes.size(); + if (nc) { + DVector<int> snodes = d["nodes"]; + DVector<int>::Read r = snodes.read(); + int idx=0; + for(int i=0;i<nc;i++) { + NodeData &nd = nodes[i]; + nd.parent=r[idx++]; + nd.type=r[idx++]; + nd.name=r[idx++]; + nd.properties.resize(r[idx++]); + for(int j=0;j<nd.properties.size();j++) { + + nd.properties[j].name=r[idx++]; + nd.properties[j].value=r[idx++]; + } + } + + } + + connections.resize(d["conn_count"]); + int cc=connections.size(); + + if (cc) { + + DVector<int> sconns = d["conns"]; + DVector<int>::Read r = sconns.read(); + int idx=0; + for(int i=0;i<nc;i++) { + ConnectionData &cd = connections[nc]; + cd.from=r[idx++]; + cd.to=r[idx++]; + cd.signal=r[idx++]; + cd.method=r[idx++]; + cd.binds.resize(r[idx++]); + for(int j=0;j<cd.binds.size();j++) { + + cd.binds[j]=r[idx++]; + } + } + + } + + + + path=d["path"]; + +} + +Dictionary ScenePreloader::_get_bundled_scene() const { + + DVector<String> rnames; + rnames.resize(names.size()); + + if (names.size()) { + + DVector<String>::Write r=rnames.write(); + + for(int i=0;i<names.size();i++) + r[i]=names[i]; + } + + Dictionary d; + d["names"]=rnames; + d["variants"]=variants; + + Vector<int> rnodes; + d["node_count"]=nodes.size(); + + for(int i=0;i<nodes.size();i++) { + + const NodeData &nd=nodes[i]; + rnodes.push_back(nd.parent); + rnodes.push_back(nd.type); + rnodes.push_back(nd.name); + rnodes.push_back(nd.properties.size()); + for(int j=0;j<nd.properties.size();j++) { + + rnodes.push_back(nd.properties[j].name); + rnodes.push_back(nd.properties[j].value); + } + } + + d["nodes"]=rnodes; + + Vector<int> rconns; + d["conn_count"]=connections.size(); + + for(int i=0;i<connections.size();i++) { + + const ConnectionData &cd=connections[i]; + rconns.push_back(cd.from); + rconns.push_back(cd.to); + rconns.push_back(cd.signal); + rconns.push_back(cd.method); + rconns.push_back(cd.binds.size()); + for(int j=0;j<cd.binds.size();i++) + rconns.push_back(cd.binds[j]); + + } + + d["conns"]=rconns; + + d["path"]=path; + + return d; + + +} + +void ScenePreloader::_bind_methods() { + + ObjectTypeDB::bind_method(_MD("load_scene","path"),&ScenePreloader::load_scene); + ObjectTypeDB::bind_method(_MD("get_scene_path"),&ScenePreloader::get_scene_path); + ObjectTypeDB::bind_method(_MD("instance:Node"),&ScenePreloader::instance); + ObjectTypeDB::bind_method(_MD("can_instance"),&ScenePreloader::can_instance); + ObjectTypeDB::bind_method(_MD("_set_bundled_scene"),&ScenePreloader::_set_bundled_scene); + ObjectTypeDB::bind_method(_MD("_get_bundled_scene"),&ScenePreloader::_get_bundled_scene); + + ADD_PROPERTY( PropertyInfo(Variant::DICTIONARY,"_bundled",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_BUNDLE),_SCS("_set_bundled_scene"),_SCS("_get_bundled_scene")); +#if 0 + List<String> extensions; + SceneLoader::get_recognized_extensions(&extensions); + String exthint; + for (List<String>::Element*E=extensions.front();E;E=E->next()) { + + if (exthint!="") + exthint+=","; + exthint+="*."+E->get(); + } + + exthint+="; Scenes"; + + ADD_PROPERTY( PropertyInfo(Variant::STRING,"scene",PROPERTY_HINT_FILE,exthint),_SCS("load_scene"),_SCS("get_scene_path")); +#endif +} + +ScenePreloader::ScenePreloader() { + + +} diff --git a/scene/scene_binds.cpp b/scene/scene_binds.cpp deleted file mode 100644 index 5c6a02611f..0000000000 --- a/scene/scene_binds.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/*************************************************************************/ -/* scene_binds.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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. */ -/*************************************************************************/ -#include "scene_binds.h" - - -#ifdef OLD_SCENE_FORMAT_ENABLED -void SceneIO::_bind_methods() { - - ObjectTypeDB::bind_method(_MD("load:Node","path"),&SceneIO::load); - ObjectTypeDB::bind_method(_MD("save","path","scene:Node","flags","optimizer:OptimizedSaver","scene"),&SceneIO::save,DEFVAL(0),DEFVAL(Ref<OptimizedSaver>())); - ObjectTypeDB::bind_method(_MD("load_interactive:SceneInteractiveLoader","path"),&SceneIO::load_interactive); -} - -Node* SceneIO::load(const String& p_scene) { - - return SceneLoader::load(p_scene); -} - -Error SceneIO::save(const String& p_path, Node *p_scene,int p_flags,const Ref<OptimizedSaver> &p_optimizer) { - - return SceneSaver::save(p_path,p_scene,p_flags,p_optimizer); -} - -Ref<SceneInteractiveLoader> SceneIO::load_interactive(const String& p_scene) { - - return SceneLoader::load_interactive(p_scene); -} - -#endif diff --git a/scene/scene_binds.h b/scene/scene_binds.h deleted file mode 100644 index 29e4b9ab60..0000000000 --- a/scene/scene_binds.h +++ /dev/null @@ -1,62 +0,0 @@ -/*************************************************************************/ -/* scene_binds.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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. */ -/*************************************************************************/ -#ifndef SCENE_BINDS_H -#define SCENE_BINDS_H - -#include "scene/io/scene_loader.h" -#include "scene/io/scene_saver.h" - -#ifdef OLD_SCENE_FORMAT_ENABLED - -class SceneIO : public Object { - - OBJ_TYPE( SceneIO, Object ); -protected: - - static void _bind_methods(); -public: - - enum SaveFlags { - - SAVE_FLAG_RELATIVE_PATHS=SceneSaver::FLAG_RELATIVE_PATHS, - SAVE_FLAG_BUNDLE_RESOURCES=SceneSaver::FLAG_BUNDLE_RESOURCES, - SAVE_FLAG_BUNDLE_INSTANCED_SCENES=SceneSaver::FLAG_BUNDLE_INSTANCED_SCENES, - SAVE_FLAG_OMIT_EDITOR_PROPERTIES=SceneSaver::FLAG_OMIT_EDITOR_PROPERTIES, - SAVE_FLAG_SAVE_BIG_ENDIAN=SceneSaver::FLAG_SAVE_BIG_ENDIAN - }; - - Node* load(const String& p_scene); - Error save(const String& p_path, Node *p_scene,int p_flags=0,const Ref<OptimizedSaver> &p_optimizer=Ref<OptimizedSaver>()); - Ref<SceneInteractiveLoader> load_interactive(const String& p_scene); - - SceneIO() {} -}; - -#endif -#endif // SCENE_BINDS_H |