Anonymous avatar Anonymous committed 1a20e92

Fixed bugs

Comments (0)

Files changed (16)

PolyMain/PolyMain.vcxproj.filters

     <ClInclude Include="include\game\PolyTransformComponent.h">
       <Filter>game</Filter>
     </ClInclude>
-    <ClInclude Include="include\game\PolyCharacterControllerComponent.h">
-      <Filter>game</Filter>
-    </ClInclude>
     <ClInclude Include="include\util\PolyReflection.h">
       <Filter>util</Filter>
     </ClInclude>
     <ClInclude Include="include\game\PolyEntityTemplateTranslator.h">
       <Filter>game</Filter>
     </ClInclude>
+    <ClInclude Include="include\game\PolyCharacterControllerComponent.h">
+      <Filter>game\phyics</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="include\PolyPrerequisites.cpp" />
     <ClCompile Include="include\game\PolyEntityManager.cpp">
       <Filter>game</Filter>
     </ClCompile>
-    <ClCompile Include="include\game\PolyCharacterControllerComponent.cpp">
-      <Filter>game</Filter>
-    </ClCompile>
     <ClCompile Include="include\game\PolyTransformComponent.cpp">
       <Filter>game</Filter>
     </ClCompile>
     <ClCompile Include="include\game\PolyEntityTemplateTranslator.cpp">
       <Filter>game</Filter>
     </ClCompile>
+    <ClCompile Include="include\game\PolyCharacterControllerComponent.cpp">
+      <Filter>game\phyics</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <Filter Include="audio">

PolyMain/include/game/PolyCharacterControllerComponent.cpp

 	POLY_COMPONENT_BASE_IMPL(CharacterControllerComponent, "CharacterController", "CharacterController");
 
 	CharacterControllerComponent::CharacterControllerComponent() {
-// 		PhysicsCharacterControllerDesc desc;
-// 		desc.height = params.get<float>("CharacterController/Height", 2.0f);
-// 		desc.radius = params.get<float>("CharacterController/Radius", 0.9f);
-// 		desc.slopeLimit = params.get<float>("CharacterController/SlopeLimit", 0.707f);
-// 		desc.stepOffset = params.get<float>("CharacterController/StepOffset", 0.5f);
-// 		desc.contactOffset = params.get<float>("CharacterController/ContactOffset", 0.1f);
-// 
-// 		mOffset = params.get<Vector3>("CharacterController/Offset", Vector3::ZERO);
-// 
-// 		mController = gEnv.physics->createCharacterController(entity.getScene(), desc, entity);
-// 
-// 		TransformComponent* transformComponent = entity.getComponent<TransformComponent>();
-// 		if(transformComponent) {
-// 			Vector3 position = transformComponent->sceneNode->getPosition() + mOffset;
-// 			mController->setPosition(physx::PxExtendedVec3(position.x, position.y, position.z));
-// 		}
+		mProperties.addProperty("CharacterController/Height", (float*)POLY_NULLPTR);
+		mProperties.addProperty("CharacterController/Radius", (float*)POLY_NULLPTR);
+		mProperties.addProperty("CharacterController/SlopeLimit", (float*)POLY_NULLPTR, true);
+		mProperties.addProperty("CharacterController/StepOffset", (float*)POLY_NULLPTR, true);
+		mProperties.addProperty("CharacterController/ContactOffset", (float*)POLY_NULLPTR, true);
+		mProperties.addProperty("CharacterController/Offset", &offset, true);
 	}
 
-	void CharacterControllerComponent::move(const Vector3& offset) {
-// 		TransformComponent* transform = mEntity.getComponent<TransformComponent>();
-// 		if(!transform)
-// 			return;
-// 
-// 		ulong gameplayStepTime = gEnv.engine->getGameplayStepTime();
-// 		physx::PxVec3 disp = PhysicsUtil::convert(transform->sceneNode->getOrientation() * offset);
-// 		mController->move(disp, 0.01f, static_cast<float>(gameplayStepTime), physx::PxControllerFilters());
-// 
-// 		Vector3 position = PhysicsUtil::convert(mController->getPosition());
-// 		transform->sceneNode->translate(position - (transform->sceneNode->getPosition() + mOffset), Ogre::Node::TS_WORLD);
+	void CharacterControllerComponent::initialize(Entity entity, const StringVariantMap& values) {
+		Component::initialize(entity, values);
+
+		PhysicsCharacterControllerDesc desc;
+		desc.height = values.get<float>("CharacterController/Height", 2.0f);
+		desc.radius = values.get<float>("CharacterController/Radius", 0.9f);
+		desc.slopeLimit = values.get<float>("CharacterController/SlopeLimit", 0.707f);
+		desc.stepOffset = values.get<float>("CharacterController/StepOffset", 0.5f);
+		desc.contactOffset = values.get<float>("CharacterController/ContactOffset", 0.1f);
+
+		controller = gEnv.physics->createCharacterController(entity.getScene(), desc, entity);
+
+		TransformComponent* transformComponent = entity.getComponent<TransformComponent>();
+		if(transformComponent) {
+			Vector3 position = transformComponent->getSceneNode()->getPosition();
+			controller->setPosition(physx::PxExtendedVec3(position.x + offset.x, position.y + offset.x, position.z + offset.x));
+		}
 	}
-
-	void CharacterControllerComponent::serialize(StringVariantMap& params) const {
-	}
-
-// 	void CharacterControllerComponent::transformTeleportedEvent(const PropertyMap& params) {
-// 		Vector3 position = params.get<Vector3>("position");
-// 		position += mOffset;
-// 
-// 		mController->setPosition(physx::PxExtendedVec3(position.x, position.y, position.z));
-// 	}
 }

PolyMain/include/game/PolyCharacterControllerComponent.h

 	*/
 	class _PolyExport CharacterControllerComponent : public Component {
 	public:
+		physx::PxController*	controller;
+		Vector3					offset;
+
 								CharacterControllerComponent();
 
-		void					move(const Vector3& offset);
+		virtual void			initialize(Entity entity, const StringVariantMap& values);
 
-		// Serialization
-		virtual void			serialize(StringVariantMap& params) const;
-
-								POLY_COMPONENT_BASE;
-
-	protected:
-		physx::PxController*	mController;
-		Vector3					mOffset;
+		POLY_COMPONENT_BASE;
 	};
 }
 

PolyMain/include/game/PolyComponent.h

 
 		Entity					getEntity() const;
 
+		PropertySet&			getProperties() { return mProperties; }
+		const PropertySet&		getProperties() const { return mProperties; }
+
 		// Type/family name
 		// Don't implement them yourself, use the POLY_COMPONENT_INFO macro!
 		virtual const InternString& getTypeName() const = 0;

PolyMain/include/game/PolyComponentFactory.h

 	public:
 		virtual Component* create(Entity entity, const StringVariantMap& values) const {
 			Component* component = new T();
+
 			component->initialize(entity, values);
 
 			return component;

PolyMain/include/game/PolyComponentManager.cpp

 		mFactories.clear();
 	}
 
-	Component* ComponentManager::createComponent(Entity entity, const String& typeName, const StringVariantMap& params) {
+	Component* ComponentManager::createComponent(Entity entity, const String& typeName, const StringVariantMap& values) {
 		TypeNameFactoryMap::const_iterator itr;
 		itr = mFactories.find(typeName);
 
 		if(itr != mFactories.end()) {
 			ComponentFactoryPtr factory = (*itr).second;
 
-			Component* component = factory->create(entity, params);
+			Component* component = factory->create(entity, values);
 			POLY_ASSERT(component);
 
 			return component;

PolyMain/include/game/PolyComponentManager.h

 								ComponentManager();
 
 		void					addComponentType(	const String& typeName,
-														ComponentFactoryPtr factory);
+													ComponentFactoryPtr factory);
 
 		void					removeAllFactories();
 
 
 		Component*				createComponent(Entity entity, 
 												const String& typeName, 
-												const StringVariantMap& params);
+												const StringVariantMap& values);
 		void					destroyComponent(Component* component);
 
 	private:

PolyMain/include/game/PolyEntity.cpp

 		return emptySet;
 	}
 
-	void Entity::createComponent(const String& typeName, const StringVariantMap& params) {
+	void Entity::createComponent(const String& typeName, const StringVariantMap& values) {
 		POLY_ASSERT(mEID != UNASSIGNED_ENTITY_ID);
 		POLY_ASSERT(isValid());
 
-		Component* newComponent = gEnv.componentMgr->createComponent(*this, typeName, params);
+		Component* newComponent = gEnv.componentMgr->createComponent(*this, typeName, values);
 
 		addComponent(newComponent);
 	}

PolyMain/include/game/PolyEntity.h

 
 		static const EntitySet&		getWithComponent(const String& typeName);
 
-		void						createComponent(const String& typeName, const StringVariantMap& params=StringVariantMap());
+		void						createComponent(const String& typeName, const StringVariantMap& values=StringVariantMap());
 		void						addComponent(Component* component);
 		void						destroyComponent(Component* component);
 		void						_destroyAllComponents();

PolyMain/include/game/PolyLightComponent.cpp

 		mProperties.addProperty("Light/Type", (String*)POLY_NULLPTR);
 		mProperties.addProperty("Light/Visible", (int*)POLY_NULLPTR, true);
 		mProperties.addProperty("Light/Direction", (Vector3*)POLY_NULLPTR, true);
+		mProperties.addProperty("Light/ShadowFarClipDistance", (float*)POLY_NULLPTR, true);
 
 		gEnv.render->_registerComponent(this);
 	}
 		bool castShadows = values.get<int>("Light/CastShadows", 0) != 0;
 		light->setCastShadows(castShadows);
 
+		float shadowFarClipDistance = values.get<float>("Light/ShadowFarClipDistance", -1.0f);
+		light->setShadowFarClipDistance(shadowFarClipDistance);
+
 		ColourValue diffuseColour = values.get<ColourValue>("Light/DiffuseColour", ColourValue::White);
 		light->setDiffuseColour(diffuseColour);
 

PolyMain/include/game/PolyPhysicsComponent.cpp

 				if(tokens.size() >= 3)
 					offset = StringConverter::parseVector3(tokens[2]);
 
-				physx::PxTransform transform = PhysicsUtil::convert(offset, Quaternion::ZERO);
+				physx::PxTransform transform = PhysicsUtil::convert(offset, Quaternion::IDENTITY);
 
 				rigidBody->createShape(physx::PxPlaneGeometry(), *defaultMaterial, transform);
 			}
 				if(tokens.size() >= 3)
 					offset = StringConverter::parseVector3(tokens[2]);
 
-				rigidBody->createShape(physx::PxBoxGeometry(size.x, size.y, size.z), *defaultMaterial);
+				physx::PxTransform transform = PhysicsUtil::convert(offset, Quaternion::IDENTITY);
 
-				// TODO offset
+				rigidBody->createShape(physx::PxBoxGeometry(size.x, size.y, size.z), *defaultMaterial, transform);
 			}
 			else if(tokens[0] == "Mesh") {
 				if(tokens.size() >= 2) {
 					PhysicsCookingParams params;
 					physx::PxTriangleMesh* physicsMesh = gEnv.physics->createTriangleMesh(meshInfo, params);
 
+					Vector3 offset = Vector3::ZERO;
+					if(tokens.size() >= 3)
+						offset = StringConverter::parseVector3(tokens[2]);
 
-					physx::PxTransform transform(physx::PxVec3(0.0f, 0.0f, 0.0f), PhysicsUtil::convert(Quaternion::IDENTITY));
+					physx::PxTransform transform = PhysicsUtil::convert(offset, Quaternion::IDENTITY);
 
 					rigidBody->createShape(physx::PxTriangleMeshGeometry(physicsMesh), *defaultMaterial, transform);
 				}

PolyMain/include/game/PolyPhysicsEntityLogic.h

 
 
 namespace Poly {
+	/** Updated entities containing PhysicsDynamicComponents and PhysicsStaticComponents.
+	*/
 	class PhysicsEntityLogic : public EntityLogic {
 	public:
 						PhysicsEntityLogic();

PolyMain/include/game/PolyProperty.h

 			mProps.push_back(prop);
 		}
 
+		void addProperty(const String& name, float* ptr, bool optional=false) {
+			Property prop;
+			prop.name = name;
+			prop.ptr = ptr;
+			prop.type = PropertyType::FLOAT;
+			prop.optional = optional;
+			mProps.push_back(prop);
+		}
+
 		void addProperty(const String& name, String* ptr, bool optional=false) {
 			Property prop;
 			prop.name = name;
 			}
 		}
 
+		bool contains(const String& name) const {
+			BOOST_FOREACH(const Property& prop, mProps) {
+				if(prop.name == name)
+					return true;
+			}
+
+			return false;
+		}
+
 	protected:
 		vector<Property>::type mProps;
 	};

PolyMain/include/game/PolyTransformComponent.cpp

 	}
 
 	TransformComponent::~TransformComponent() {
-		// TODO To destroy or not to destroy, that is the question.
-// 		RenderSubScene* renderScene = mEntity.getScene().getRender();
-// 		renderScene->sceneMgr->destroySceneNode(mSceneNode);
+		// TODO
 	}
 
 	void TransformComponent::initialize(Entity entity, const StringVariantMap& values) {
 		mSceneNode->setOrientation(values.get<Quaternion>("Transform/Orientation", Quaternion::IDENTITY));
 		mSceneNode->setScale(values.get<Vector3>("Transform/Scale", Vector3::UNIT_SCALE));
 	}
+
+	void TransformComponent::setParent(TransformComponent* other) {
+		mSceneNode->getParent()->removeChild(mSceneNode);
+		other->getSceneNode()->addChild(mSceneNode);
+	}
 }

PolyMain/include/game/PolyTransformComponent.h

 
 		virtual void			initialize(Entity entity, const StringVariantMap& values);
 
+		virtual void			setParent(TransformComponent* other);
+
 		Ogre::SceneNode*		getSceneNode() { return mSceneNode; }
 
 								POLY_COMPONENT_BASE;
 - Write basic editor / implement Ogitor plugin
 - Implement saving / loading
 - Add threading library / build thread pool ontop of boost
-- Implement bucket Entity and/or EntityLogic updates
+- Implement bucket Entity and/or EntityLogic updates
+
+- More features for EntityLogics: filter by exact type, filter by multiple types
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.