瀏覽代碼

Working on updated Platformer

Josh Engebretson 10 年之前
父節點
當前提交
6d0abd033d

+ 3 - 1
Script/AtomicEditor/ui/frames/inspector/CreateComponentButton.ts

@@ -12,6 +12,8 @@ var _2DCreateSource = new Atomic.UIMenuItemSource();
 _2DCreateSource.addItem(new Atomic.UIMenuItem("PhysicsWorld2D", "PhysicsWorld2D"));
 _2DCreateSource.addItem(new Atomic.UIMenuItem("PhysicsWorld2D", "PhysicsWorld2D"));
 _2DCreateSource.addItem(new Atomic.UIMenuItem("StaticSprite2D", "StaticSprite2D"));
 _2DCreateSource.addItem(new Atomic.UIMenuItem("StaticSprite2D", "StaticSprite2D"));
 _2DCreateSource.addItem(new Atomic.UIMenuItem("AnimatedSprite2D", "AnimatedSprite2D"));
 _2DCreateSource.addItem(new Atomic.UIMenuItem("AnimatedSprite2D", "AnimatedSprite2D"));
+_2DCreateSource.addItem(new Atomic.UIMenuItem("PointLight2D", "PointLight2D"));
+_2DCreateSource.addItem(new Atomic.UIMenuItem("DirectionalLight2D", "DirectionalLight2D"));
 _2DCreateSource.addItem(new Atomic.UIMenuItem("RigidBody2D", "RigidBody2D"));
 _2DCreateSource.addItem(new Atomic.UIMenuItem("RigidBody2D", "RigidBody2D"));
 _2DCreateSource.addItem(new Atomic.UIMenuItem("CollisionBox2D", "CollisionBox2D"));
 _2DCreateSource.addItem(new Atomic.UIMenuItem("CollisionBox2D", "CollisionBox2D"));
 _2DCreateSource.addItem(new Atomic.UIMenuItem("CollisionCircle2D", "CollisionCircle2D"));
 _2DCreateSource.addItem(new Atomic.UIMenuItem("CollisionCircle2D", "CollisionCircle2D"));
@@ -56,7 +58,7 @@ var sceneCreateSource = new Atomic.UIMenuItemSource();
 
 
 sceneCreateSource.addItem(new Atomic.UIMenuItem("Camera", "Camera"));
 sceneCreateSource.addItem(new Atomic.UIMenuItem("Camera", "Camera"));
 sceneCreateSource.addItem(new Atomic.UIMenuItem("Light", "Light"));
 sceneCreateSource.addItem(new Atomic.UIMenuItem("Light", "Light"));
-sceneCreateSource.addItem(new Atomic.UIMenuItem("Zone", "create component"));
+sceneCreateSource.addItem(new Atomic.UIMenuItem("Zone", "Zone"));
 
 
 var subsystemCreateSource = new Atomic.UIMenuItemSource();
 var subsystemCreateSource = new Atomic.UIMenuItemSource();
 
 

+ 6 - 1
Script/AtomicEditor/ui/frames/inspector/NodeInspector.ts

@@ -230,9 +230,14 @@ class NodeInspector extends ScriptWidget {
 
 
         for (var i in components) {
         for (var i in components) {
 
 
+            var component = components[i];
+
+            if (component.isTemporary())
+              continue;
+
             var ci = new ComponentInspector();
             var ci = new ComponentInspector();
 
 
-            ci.inspect(components[i]);
+            ci.inspect(component);
 
 
             nodeLayout.addChild(ci);
             nodeLayout.addChild(ci);
 
 

+ 2 - 0
Script/TypeScript/ToolCore.d.ts

@@ -242,6 +242,7 @@ declare module ToolCore {
       guid: string;
       guid: string;
       name: string;
       name: string;
       path: string;
       path: string;
+      extension: string;
       relativePath: string;
       relativePath: string;
       cachePath: string;
       cachePath: string;
       importerType: string;
       importerType: string;
@@ -261,6 +262,7 @@ declare module ToolCore {
       getGUID(): string;
       getGUID(): string;
       getName(): string;
       getName(): string;
       getPath(): string;
       getPath(): string;
+      getExtension(): string;
       // Get the path relative to project
       // Get the path relative to project
       getRelativePath(): string;
       getRelativePath(): string;
       getCachePath(): string;
       getCachePath(): string;

+ 80 - 31
Source/Atomic/Atomic2D/Light2D.cpp

@@ -16,6 +16,7 @@
 #include "../Graphics/RenderPath.h"
 #include "../Graphics/RenderPath.h"
 #include "../Graphics/Material.h"
 #include "../Graphics/Material.h"
 #include "../Graphics/Technique.h"
 #include "../Graphics/Technique.h"
+#include "../Graphics/Zone.h"
 
 
 #include "../Atomic2D/RigidBody2D.h"
 #include "../Atomic2D/RigidBody2D.h"
 #include "../Atomic2D/Renderer2D.h"
 #include "../Atomic2D/Renderer2D.h"
@@ -37,10 +38,12 @@ void FixMeSetLight2DGroupViewport(Viewport *viewport)
 extern const char* ATOMIC2D_CATEGORY;
 extern const char* ATOMIC2D_CATEGORY;
 
 
 Light2D::Light2D(Context* context) : Component(context),
 Light2D::Light2D(Context* context) : Component(context),
+    color_(Color::WHITE),
     castShadows_(false),
     castShadows_(false),
     softShadows_(false),
     softShadows_(false),
     softShadowLength_(2.5f),
     softShadowLength_(2.5f),
-    backtrace_(false)
+    backtrace_(false),
+    raysInitialized_(false)
 {
 {
     SetNumRays(32);
     SetNumRays(32);
 }
 }
@@ -52,9 +55,30 @@ Light2D::~Light2D()
 
 
 void Light2D::SetNumRays(int numRays)
 void Light2D::SetNumRays(int numRays)
 {
 {
+    raysInitialized_ = false;
     rays_.Resize(numRays);
     rays_.Resize(numRays);
 }
 }
 
 
+void Light2D::OnSceneSet(Scene* scene)
+{
+    if (scene)
+    {
+        // FIXME: supporting one lightgroup atm
+        PODVector<Light2DGroup*> lightgroups;
+        scene->GetComponents<Light2DGroup>(lightgroups, true);
+        lightgroup_ = lightgroups.Size() ? lightgroups.At(0) : node_->CreateComponent<Light2DGroup>();
+        lightgroup_->SetTemporary(true);
+        lightgroup_->AddLight2D(this);
+    }
+    else
+    {
+        if (lightgroup_)
+            lightgroup_->RemoveLight2D(this);
+
+    }
+}
+
+
 void Light2D::OnSetEnabled()
 void Light2D::OnSetEnabled()
 {
 {
     Component::OnSetEnabled();
     Component::OnSetEnabled();
@@ -77,10 +101,22 @@ void Light2D::RegisterObject(Context* context)
 {
 {
     context->RegisterFactory<Light2D>(ATOMIC2D_CATEGORY);
     context->RegisterFactory<Light2D>(ATOMIC2D_CATEGORY);
     COPY_BASE_ATTRIBUTES(Component);
     COPY_BASE_ATTRIBUTES(Component);
+
+    ACCESSOR_ATTRIBUTE("Color", GetColor, SetColor, Color, Color::WHITE, AM_DEFAULT);
+
+    ACCESSOR_ATTRIBUTE("Cast Shadows", GetCastShadows, SetCastShadows, bool, false, AM_DEFAULT);
+    ACCESSOR_ATTRIBUTE("Num Rays", GetNumRays, SetNumRays, int, 32, AM_DEFAULT);
+    ACCESSOR_ATTRIBUTE("Soft Shadows", GetSoftShadows, SetSoftShadows, bool, false, AM_DEFAULT);
+    ACCESSOR_ATTRIBUTE("Soft Shadows Length", GetSoftShadowLength, SetSoftShadowLength, float, 2.5f, AM_DEFAULT);
+    ACCESSOR_ATTRIBUTE("Backtrace", GetBacktrace, SetBacktrace, bool, false, AM_DEFAULT);
+
 }
 }
 
 
 void Light2D::CastRays()
 void Light2D::CastRays()
 {
 {
+    if (!raysInitialized_ || context_->GetEditorContext())
+        return;
+
     PhysicsWorld2D* physicsWorld = lightgroup_->GetPhysicsWorld();
     PhysicsWorld2D* physicsWorld = lightgroup_->GetPhysicsWorld();
 
 
     if (physicsWorld && castShadows_) {
     if (physicsWorld && castShadows_) {
@@ -155,13 +191,15 @@ void DirectionalLight2D::RegisterObject(Context* context)
 {
 {
     context->RegisterFactory<DirectionalLight2D>(ATOMIC2D_CATEGORY);
     context->RegisterFactory<DirectionalLight2D>(ATOMIC2D_CATEGORY);
     COPY_BASE_ATTRIBUTES(Light2D);
     COPY_BASE_ATTRIBUTES(Light2D);
+
+    ACCESSOR_ATTRIBUTE("Direction", GetDirection, SetDirection, float, -45.0f, AM_DEFAULT);
 }
 }
 
 
 void DirectionalLight2D::UpdateVertices()
 void DirectionalLight2D::UpdateVertices()
 {
 {
     vertices_.Clear();
     vertices_.Clear();
 
 
-    if (!lightgroup_ || !enabled_)
+    if (!lightgroup_ || !enabled_ || context_->GetEditorContext())
         return;
         return;
 
 
     const BoundingBox& frustumBox = lightgroup_->GetFrustumBox();
     const BoundingBox& frustumBox = lightgroup_->GetFrustumBox();
@@ -171,6 +209,10 @@ void DirectionalLight2D::UpdateVertices()
 
 
     float width = frustumBox.Size().x_;
     float width = frustumBox.Size().x_;
     float height = frustumBox.Size().y_;
     float height = frustumBox.Size().y_;
+
+    if (!width || !height)
+        return;
+
     float sizeOfScreen = width > height ? width : height;
     float sizeOfScreen = width > height ? width : height;
 
 
     float xAxelOffSet = sizeOfScreen * cos;
     float xAxelOffSet = sizeOfScreen * cos;
@@ -211,6 +253,7 @@ void DirectionalLight2D::UpdateVertices()
         ray.fraction_ = 0.0f;
         ray.fraction_ = 0.0f;
     }
     }
 
 
+    raysInitialized_ = true;
     CastRays();
     CastRays();
 
 
     Vertex2D vertex0;
     Vertex2D vertex0;
@@ -307,7 +350,7 @@ PositionalLight2D::~PositionalLight2D()
 void PositionalLight2D::RegisterObject(Context* context)
 void PositionalLight2D::RegisterObject(Context* context)
 {
 {
     context->RegisterFactory<PositionalLight2D>(ATOMIC2D_CATEGORY);
     context->RegisterFactory<PositionalLight2D>(ATOMIC2D_CATEGORY);
-    COPY_BASE_ATTRIBUTES(Light2D);
+    COPY_BASE_ATTRIBUTES(Light2D);    
 }
 }
 
 
 void PositionalLight2D::UpdateVertices()
 void PositionalLight2D::UpdateVertices()
@@ -389,7 +432,7 @@ void PositionalLight2D::UpdateVertices()
 }
 }
 
 
 PointLight2D::PointLight2D(Context* context) : PositionalLight2D(context),
 PointLight2D::PointLight2D(Context* context) : PositionalLight2D(context),
-    radius_(1.0f)
+    radius_(4.0f)
 {
 {
     lightType_ = LIGHT2D_POINT;
     lightType_ = LIGHT2D_POINT;
 }
 }
@@ -403,19 +446,19 @@ void PointLight2D::RegisterObject(Context* context)
 {
 {
     context->RegisterFactory<PointLight2D>(ATOMIC2D_CATEGORY);
     context->RegisterFactory<PointLight2D>(ATOMIC2D_CATEGORY);
     COPY_BASE_ATTRIBUTES(PositionalLight2D);
     COPY_BASE_ATTRIBUTES(PositionalLight2D);
+
+    ACCESSOR_ATTRIBUTE("Radius", GetRadius, SetRadius, float, 4.0f, AM_DEFAULT);
 }
 }
 
 
 void PointLight2D::UpdateVertices()
 void PointLight2D::UpdateVertices()
 {
 {
     vertices_.Clear();
     vertices_.Clear();
 
 
-    if (!lightgroup_ || !enabled_)
-        return;
-
-    const PhysicsWorld2D* physicsWorld = lightgroup_->GetPhysicsWorld();
-
     const Node* lightNode = GetNode();
     const Node* lightNode = GetNode();
 
 
+    if (!lightgroup_ || !enabled_ || !lightNode)
+        return;
+
     Vector2 start = lightNode->GetWorldPosition2D();
     Vector2 start = lightNode->GetWorldPosition2D();
 
 
     float angleNum = 360.0f / float((rays_.Size() - 1));
     float angleNum = 360.0f / float((rays_.Size() - 1));
@@ -443,31 +486,27 @@ void Light2DGroup::RegisterObject(Context* context)
 
 
 
 
 
 
-void Light2DGroup::OnNodeSet(Node* node)
+void Light2DGroup::OnSceneSet(Scene* scene)
 {
 {
-    // Do not call Drawable2D::OnNodeSet(node)
 
 
-    if (node)
+    if (scene && node_)
     {
     {
-        if (renderer_.Null())
-        {
-            renderer_ = node->GetOrCreateComponent<Renderer2D>();
-            renderer_->SetUseTris(true);
-        }
+        physicsWorld_ = scene->GetOrCreateComponent<PhysicsWorld2D>();
 
 
-        if (light2DMaterial_.Null())
-            CreateLight2DMaterial();
+        Zone* zone = scene->GetComponent<Zone>();
+        if (zone)
+            SetAmbientColor(zone->GetAmbientColor());
 
 
-        Scene* scene = GetScene();
-        if (scene)
-        {
-            if (IsEnabledEffective())
-                renderer_->AddDrawable(this);
-        }
+        renderer_ = node_->GetOrCreateComponent<Renderer2D>();
+        renderer_->SetUseTris(true);
 
 
-        node->AddListener(this);
+        if (light2DMaterial_.Null())
+            CreateLight2DMaterial();
 
 
+        if (IsEnabledEffective())
+            renderer_->AddDrawable(this);
 
 
+        node_->AddListener(this);
     }
     }
     else
     else
     {
     {
@@ -568,9 +607,10 @@ void Light2DGroup::UpdateSourceBatches()
 
 
 void Light2DGroup::AddLight2D(Light2D* light)
 void Light2DGroup::AddLight2D(Light2D* light)
 {
 {
-    for (Vector<WeakPtr<Light2D> >::ConstIterator itr = lights_.Begin(); itr != lights_.End(); itr++)
-        if (*itr == light)
-            return;
+    Vector<WeakPtr<Light2D>>::Iterator itr = lights_.Find(WeakPtr<Light2D>(light));
+
+    if (itr != lights_.End())
+        return;
 
 
     light->SetLightGroup(this);
     light->SetLightGroup(this);
 
 
@@ -578,11 +618,17 @@ void Light2DGroup::AddLight2D(Light2D* light)
 
 
 }
 }
 
 
-void Light2DGroup::SetPhysicsWorld(PhysicsWorld2D* physicsWorld)
+void Light2DGroup::RemoveLight2D(Light2D* light)
 {
 {
-    physicsWorld_ = physicsWorld;
+
+    Vector<WeakPtr<Light2D>>::Iterator itr = lights_.Find(WeakPtr<Light2D>(light));
+
+    if (itr != lights_.End())
+        lights_.Erase(itr);
+
 }
 }
 
 
+
 void Light2DGroup::SetAmbientColor(const Color& color)
 void Light2DGroup::SetAmbientColor(const Color& color)
 {
 {
     if (color == ambientColor_)
     if (color == ambientColor_)
@@ -606,6 +652,9 @@ void Light2DGroup::SetAmbientColor(const Color& color)
 
 
 void Light2DGroup::CreateLight2DMaterial()
 void Light2DGroup::CreateLight2DMaterial()
 {
 {
+    if (context_->GetEditorContext())
+        return;
+
     Renderer* renderer = GetSubsystem<Renderer>();
     Renderer* renderer = GetSubsystem<Renderer>();
     // only on main viewport atm and viewport must first be set
     // only on main viewport atm and viewport must first be set
     Viewport* viewport = __fixmeViewport ? __fixmeViewport :  renderer->GetViewport(0);
     Viewport* viewport = __fixmeViewport ? __fixmeViewport :  renderer->GetViewport(0);

+ 7 - 4
Source/Atomic/Atomic2D/Light2D.h

@@ -53,7 +53,7 @@ public:
     virtual void UpdateVertices() {}
     virtual void UpdateVertices() {}
 
 
     void SetNumRays(int numRays);
     void SetNumRays(int numRays);
-    unsigned GetNumRays() const { return rays_.Size(); }
+    int GetNumRays() const { return (int) rays_.Size(); }
 
 
     virtual void OnSetEnabled();
     virtual void OnSetEnabled();
 
 
@@ -73,6 +73,8 @@ public:
 
 
 protected:
 protected:
 
 
+    void OnSceneSet(Scene* scene);
+
     void CastRays();
     void CastRays();
 
 
     WeakPtr<Light2DGroup> lightgroup_;
     WeakPtr<Light2DGroup> lightgroup_;
@@ -82,6 +84,7 @@ protected:
     bool backtrace_;
     bool backtrace_;
     float softShadowLength_;
     float softShadowLength_;
     PODVector<Light2DRay> rays_;
     PODVector<Light2DRay> rays_;
+    bool raysInitialized_;
     Vector<Vertex2D> vertices_;
     Vector<Vertex2D> vertices_;
     LightType2D lightType_;
     LightType2D lightType_;
 };
 };
@@ -168,10 +171,11 @@ public:
     /// Register object factory. drawable2d must be registered first.
     /// Register object factory. drawable2d must be registered first.
     static void RegisterObject(Context* context);
     static void RegisterObject(Context* context);
 
 
-    void SetPhysicsWorld(PhysicsWorld2D* physicsWorld);
     PhysicsWorld2D* GetPhysicsWorld() { return physicsWorld_; }
     PhysicsWorld2D* GetPhysicsWorld() { return physicsWorld_; }
 
 
     void AddLight2D(Light2D* light);
     void AddLight2D(Light2D* light);
+    void RemoveLight2D(Light2D* light);
+
     Vector<WeakPtr<Light2D> >& GetLights() { return lights_; }
     Vector<WeakPtr<Light2D> >& GetLights() { return lights_; }
 
 
     void SetDirty() { /*verticesDirty_ = true;*/ }
     void SetDirty() { /*verticesDirty_ = true;*/ }
@@ -186,14 +190,13 @@ protected:
     /// Recalculate the world-space bounding box.
     /// Recalculate the world-space bounding box.
     void OnWorldBoundingBoxUpdate();
     void OnWorldBoundingBoxUpdate();
 
 
-    void OnNodeSet(Node* node);
+    void OnSceneSet(Scene* scene);
 
 
     /// Handle draw order changed.
     /// Handle draw order changed.
     virtual void OnDrawOrderChanged();
     virtual void OnDrawOrderChanged();
     /// Update source batches.
     /// Update source batches.
     virtual void UpdateSourceBatches();
     virtual void UpdateSourceBatches();
 
 
-
 private:
 private:
 
 
     Color ambientColor_;
     Color ambientColor_;

+ 2 - 1
Source/AtomicJS/Javascript/JSComponent.cpp

@@ -390,7 +390,8 @@ void JSComponent::OnNodeSet(Node* node)
 {
 {
     if (node)
     if (node)
     {
     {
-
+        if (!context_->GetEditorContext())
+            UpdateReferences();
     }
     }
     else
     else
     {
     {