From c56db3537309c23f1aceadd79c30dd7fbf2395e9 Mon Sep 17 00:00:00 2001 From: Tom Lint Date: Sun, 11 Aug 2013 22:41:39 +0200 Subject: [PATCH] Added some ContentTypeReaders Added xnbbuild project skeleton Added Model and supporting classes Updated files --- .gitignore | 2 +- README.md | 6 +- XFX.sln | 6 + include/Content/ContentReader.h | 22 +- include/Enums.h | 6 +- include/Graphics/GraphicsResource.h | 2 +- include/Graphics/Model.h | 88 +++++++ include/Graphics/ModelBone.h | 59 +++++ include/Graphics/ModelBoneCollection.h | 52 ++++ include/Graphics/ModelEffectCollection.h | 32 +++ include/Graphics/ModelMesh.h | 62 +++++ include/Graphics/ModelMeshCollection.h | 52 ++++ include/Graphics/ModelMeshPart.h | 60 +++++ include/Graphics/ModelMeshPartCollection.h | 27 +++ include/Graphics/Texture.h | 2 +- include/Graphics/Texture2D.h | 47 ++-- include/System/Array.h | 10 +- include/System/Collections/Generic/List.h | 14 +- .../ObjectModel/ReadOnlyCollection.h | 224 +++++++++++++++++ include/System/Diagnostics/Debug.h | 56 +++++ include/System/FrameworkResources.h | 1 + include/System/IO/BinaryReader.h | 6 +- include/System/IO/FileStream.h | 12 +- include/System/IO/file.h | 2 +- include/System/Type.h | 6 +- include/sassert.h | 2 +- src/libSystem/Debug.cpp | 83 +++++++ src/libSystem/libSystem.vcxproj | 2 + src/libSystem/libSystem.vcxproj.filters | 28 ++- src/libSystem/makefile | 2 +- src/libXFX/Enums.h | 74 ++++++ src/libXFX/Model.cpp | 110 +++++++++ src/libXFX/ModelReader.cpp | 72 ++++++ src/libXFX/ModelReader.h | 27 +++ src/libXFX/Texture2D.cpp | 47 ++-- src/libXFX/Texture2DReader.cpp | 228 ++++++++++++++++++ src/libXFX/Texture2DReader.h | 27 +++ src/libXFX/XNBFile.h | 26 ++ src/libXFX/libXFX.vcxproj | 19 +- src/libXFX/libXFX.vcxproj.filters | 48 ++++ src/libmscorlib/BinaryReader.cpp | 25 +- src/libmscorlib/BitConverter.cpp | 8 +- src/libmscorlib/Double.cpp | 6 +- src/libmscorlib/Environment.cpp | 9 + src/libmscorlib/FileStream.cpp | 81 +++++-- src/libmscorlib/FrameworkResources.cpp | 13 +- src/libmscorlib/libmscorlib.vcxproj | 1 + src/libmscorlib/libmscorlib.vcxproj.filters | 6 + src/libmscorlib/misc.cpp | 14 +- src/xnbbuild/src/Path.c | 145 +++++++++++ src/xnbbuild/src/Path.h | 15 ++ src/xnbbuild/src/TryCatchFinally.h | 13 + src/xnbbuild/src/main.c | 62 +++++ src/xnbbuild/xnbbuild.vcxproj | 79 ++++++ src/xnbbuild/xnbbuild.vcxproj.filters | 33 +++ 55 files changed, 2037 insertions(+), 124 deletions(-) create mode 100644 include/Graphics/Model.h create mode 100644 include/Graphics/ModelBone.h create mode 100644 include/Graphics/ModelBoneCollection.h create mode 100644 include/Graphics/ModelEffectCollection.h create mode 100644 include/Graphics/ModelMesh.h create mode 100644 include/Graphics/ModelMeshCollection.h create mode 100644 include/Graphics/ModelMeshPart.h create mode 100644 include/Graphics/ModelMeshPartCollection.h create mode 100644 include/System/Collections/ObjectModel/ReadOnlyCollection.h create mode 100644 include/System/Diagnostics/Debug.h create mode 100644 src/libSystem/Debug.cpp create mode 100644 src/libXFX/Enums.h create mode 100644 src/libXFX/Model.cpp create mode 100644 src/libXFX/ModelReader.cpp create mode 100644 src/libXFX/ModelReader.h create mode 100644 src/libXFX/Texture2DReader.cpp create mode 100644 src/libXFX/Texture2DReader.h create mode 100644 src/libXFX/XNBFile.h create mode 100644 src/xnbbuild/src/Path.c create mode 100644 src/xnbbuild/src/Path.h create mode 100644 src/xnbbuild/src/TryCatchFinally.h create mode 100644 src/xnbbuild/src/main.c create mode 100644 src/xnbbuild/xnbbuild.vcxproj create mode 100644 src/xnbbuild/xnbbuild.vcxproj.filters diff --git a/.gitignore b/.gitignore index a94a90d..ff50f2d 100644 --- a/.gitignore +++ b/.gitignore @@ -46,7 +46,7 @@ local.properties [Rr]elease/ *_i.c *_p.c -[Bb]uild[Ll]og.* +[Bb]uild[Ll]og.htm *.a *.ilk diff --git a/README.md b/README.md index dfcfb08..26542af 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # XFXFramework ## C++ implementation of XNA For XBOX -XFX, or [XNA](http://en.wikipedia.org/wiki/Microsoft_XNA) for [XBOX](http://en.wikipedia.org/wiki/Xbox_(console)) is an implementation of [XNA](http://en.wikipedia.org/wiki/Microsoft_XNA), written in C++ for Microsofts [XBOX](http://en.wikipedia.org/wiki/Xbox_(console)) console. +XFX, or [XNA](http://en.wikipedia.org/wiki/Microsoft_XNA) for [XBOX](http://en.wikipedia.org/wiki/Xbox_(console)) is an implementation of [XNA](http://en.wikipedia.org/wiki/Microsoft_XNA) 4.0, written in C++ for Microsofts [XBOX](http://en.wikipedia.org/wiki/Xbox_(console)) console. It's written on top of [OpenXDK](http://sourceforge.net/projects/openxdk/), the open source, free, legal XBOX Development Kit. XFX is an attempt to bring development for the original [XBOX](http://en.wikipedia.org/wiki/Xbox_(console)) console to the masses by wrapping all low-level code in the familiar XNA classes. @@ -9,7 +9,7 @@ Being written in C++ allows XFX to be lightweight and as close to the hardware a Compiling XFX requires at least OpenXDK version 0.7 - +## Contents As of this writing, XFX Contains the following libraries: * libmscorlib - Provides the necessary classes found in mscorlib.dll to support the other libraries * libSystem - Implements any types in the System.dll required by the other libs @@ -17,3 +17,5 @@ As of this writing, XFX Contains the following libraries: * libSystem.Xml - Implements the functions found in System.Xml.dll * libXFX - Implements the functions found in Microsoft.Xna.Framework.dll * libXFX.Game - Implements the functions found in Microsoft.Xna.Framework.Game.dll + +XFX Supports loading assets both from precompiled .XNB files and most XNA-compatible formats. diff --git a/XFX.sln b/XFX.sln index 24d2002..2759cb4 100644 --- a/XFX.sln +++ b/XFX.sln @@ -18,6 +18,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libSystem", "src\libSystem\ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libSystem.Windows", "src\libSystem.Windows\libSystem.Windows.vcxproj", "{4A050C55-9479-4AE9-8B7A-62A6B89739BD}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "xnbbuild", "src\xnbbuild\xnbbuild.vcxproj", "{E5F1599D-C9FE-4EFB-97B6-13B46D4A1E35}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -48,6 +50,10 @@ Global {4A050C55-9479-4AE9-8B7A-62A6B89739BD}.Debug|Win32.Build.0 = Debug|Win32 {4A050C55-9479-4AE9-8B7A-62A6B89739BD}.Release|Win32.ActiveCfg = Release|Win32 {4A050C55-9479-4AE9-8B7A-62A6B89739BD}.Release|Win32.Build.0 = Release|Win32 + {E5F1599D-C9FE-4EFB-97B6-13B46D4A1E35}.Debug|Win32.ActiveCfg = Debug|Win32 + {E5F1599D-C9FE-4EFB-97B6-13B46D4A1E35}.Debug|Win32.Build.0 = Debug|Win32 + {E5F1599D-C9FE-4EFB-97B6-13B46D4A1E35}.Release|Win32.ActiveCfg = Release|Win32 + {E5F1599D-C9FE-4EFB-97B6-13B46D4A1E35}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/include/Content/ContentReader.h b/include/Content/ContentReader.h index f17c566..e73fdb5 100644 --- a/include/Content/ContentReader.h +++ b/include/Content/ContentReader.h @@ -1,9 +1,9 @@ -/******************************************************** - * ContentReader.h * - * * - * XFX ContentReader class definition file * - * Copyright (c) XFX Team. All Rights Reserved * - ********************************************************/ +/***************************************************************************** + * ContentReader.h * + * * + * XFX ContentReader class definition file * + * Copyright (c) XFX Team. All Rights Reserved * + *****************************************************************************/ #ifndef _XFX_CONTENT_CONTENTREADER_ #define _XFX_CONTENT_CONTENTREADER_ @@ -28,8 +28,10 @@ namespace XFX template class ContentTypeReader; - // A worker object that implements most of ContentManager.Load. A new ContentReader is constructed for each asset loaded. - class ContentReader : public BinaryReader, public Object + /** + * A worker object that implements most of ContentManager.Load. A new ContentReader is constructed for each asset loaded. + */ + class ContentReader : public BinaryReader { private: ContentManager* contentManager; @@ -40,8 +42,10 @@ namespace XFX static Stream* PrepareStream(Stream * const stream, const String& assetName); public: - String getAssetName() const; + const String getAssetName() const; ContentManager* getContentManager() const; + GraphicsDevice* getGraphicsDevice() const; + int getVersion() const; ContentReader(ContentManager * const manager, Stream * const stream, GraphicsDevice * const graphicsDevice); ContentReader(ContentManager * const manager, Stream * const input, const String& assetName); diff --git a/include/Enums.h b/include/Enums.h index aa28d04..5fcd7e8 100644 --- a/include/Enums.h +++ b/include/Enums.h @@ -90,10 +90,10 @@ namespace XFX typedef ContainmentType::type ContainmentType_t; // Describes how one bounding volume contains another. typedef CurveContinuity::type CurveContinuity_t; // Defines the continuity of CurveKeys on a Curve. - typedef CurveLoopType::type CurveLoopType_t; // Defines how the value of a Curve will be determined for positions before the first point on the Curve or after the last point on the Curve. - typedef CurveTangent::type CurveTangent_t; // Specifies different tangent types to be calculated for CurveKey points in a Curve. + typedef CurveLoopType::type CurveLoopType_t; // Defines how the value of a Curve will be determined for positions before the first point on the Curve or after the last point on the Curve. + typedef CurveTangent::type CurveTangent_t; // Specifies different tangent types to be calculated for CurveKey points in a Curve. typedef PlaneIntersectionType::type PlaneIntersectionType_t; // Describes the intersection between a plane and a bounding volume. - typedef PlayerIndex::type PlayerIndex_t; // Specifies the index of a player. + typedef PlayerIndex::type PlayerIndex_t; // Specifies the index of a player. typedef TargetPlatform::type TargetPlatform_t; // Defines the target platform to be used when compiling content. } diff --git a/include/Graphics/GraphicsResource.h b/include/Graphics/GraphicsResource.h index 43d5963..8226bf4 100644 --- a/include/Graphics/GraphicsResource.h +++ b/include/Graphics/GraphicsResource.h @@ -25,7 +25,7 @@ namespace XFX class GraphicsResource : public IDisposable, public Object { private: - bool isDisposed; + bool isDisposed; protected: GraphicsDevice* graphicsDevice; diff --git a/include/Graphics/Model.h b/include/Graphics/Model.h new file mode 100644 index 0000000..593b1c0 --- /dev/null +++ b/include/Graphics/Model.h @@ -0,0 +1,88 @@ +/***************************************************************************** + * Model.h * + * * + * XFX::Graphics::Model class definition file * + * Copyright (c) XFX Team. All Rights Reserved * + *****************************************************************************/ +#ifndef _XFX_GRAPHICS_MODEL_ +#define _XFX_GRAPHICS_MODEL_ + +#include "ModelBoneCollection.h" +#include "ModelMeshCollection.h" + +namespace XFX +{ + struct Matrix; + + namespace Graphics + { + /** + * Represents a 3D model composed of multiple ModelMesh objects which may be moved independently. + */ + class Model + { + private: + friend class XFX::Content::ModelReader; + + List bones; + List meshes; + static Matrix* sharedDrawBoneMatrices; + static int sharedDrawBoneMatrixCount; + + public: + /** + * Gets a collection of ModelBone objects which describe how each mesh in the Meshes collection for this model relates to its parent mesh. + */ + ModelBoneCollection getBones(); + /** + * Gets a collection of ModelMesh objects which compose the model. Each ModelMesh in a model may be moved independently and may be composed of multiple materials identified as ModelMeshPart objects. + */ + ModelMeshCollection getMeshes(); + /** + * Gets the root bone for this model. + */ + ModelBone getRoot(); + /** + * Gets or sets an object identifying this model. + */ + Object* Tag; + + /** + * Copies a transform of each bone in a model relative to all parent bones of the bone into a given array. + * + * @param destinationBoneTransforms + * The array to receive bone transforms. + */ + void CopyAbsoluteBoneTransformsTo(Matrix destinationBoneTransforms[]); + /** + * Copies an array of transforms into each bone in the model. + * + * @param sourceBoneTransforms + * An array containing new bone transforms. + */ + void CopyBoneTransformsFrom(Matrix sourceBoneTransforms[]); + /** + * Copies each bone transform relative only to the parent bone of the model to a given array. + * + * @param destinationBoneTransforms + * The array to receive bone transforms. + */ + void CopyBoneTransformsTo(Matrix destinationBoneTransforms[]); + /** + * Renders the model after applying the matrix transformations. + * + * @param world + * A world transformation matrix. + * + * @param view + * A view transformation matrix. + * + * @param projection + * A projection transformation matrix. + */ + void Draw(Matrix world, Matrix view, Matrix projection); + }; + } +} + +#endif //_XFX_GRAPHICS_MODEL_ diff --git a/include/Graphics/ModelBone.h b/include/Graphics/ModelBone.h new file mode 100644 index 0000000..743f7c1 --- /dev/null +++ b/include/Graphics/ModelBone.h @@ -0,0 +1,59 @@ +/***************************************************************************** + * ModelBone.h * + * * + * XFX::Graphics::ModelBone class definition file * + * Copyright (c) XFX Team. All Rights Reserved * + *****************************************************************************/ +#ifndef _XFX_GRAPHICS_MODELBONE_ +#define _XFX_GRAPHICS_MODELBONE_ + +#include +#include +#include + +using namespace System; +using namespace System::Collections::Generic; + +namespace XFX +{ + namespace Graphics + { + class ModelBoneCollection; + + /** + * Represents bone data for a model. + */ + class ModelBone + { + private: + friend class XFX::Content::ModelReader; + + List children; + String name; + + public: + /** + * Gets a collection of bones that are children of this bone. + */ + ModelBoneCollection getChildren() const; + /** + * Gets the index of this bone in the Bones collection. + */ + int getIndex() const; + /** + * Gets the name of this bone. + */ + const String getName() const; + /** + * Gets the paremt of this bone. + */ + ModelBone* getParent() const; + /** + * Gets or sets the matrix used to transform this bone relative to its parent bone. + */ + Matrix Transform; + }; + } +} + +#endif //_XFX_GRAPHICS_MODELBONE_ diff --git a/include/Graphics/ModelBoneCollection.h b/include/Graphics/ModelBoneCollection.h new file mode 100644 index 0000000..a8267ee --- /dev/null +++ b/include/Graphics/ModelBoneCollection.h @@ -0,0 +1,52 @@ +/***************************************************************************** + * ModelBoneCollection.h * + * * + * XFX::Graphics::ModelBoneCollection class definition file * + * Copyright (c) XFX Team. All Rights Reserved * + *****************************************************************************/ +#ifndef _XFX_GRAPHICS_MODELBONECOLLECTION_ +#define _XFX_GRAPHICS_MODELBONECOLLECTION_ + +#include "ModelBone.h" +#include + +using namespace System::Collections::ObjectModel; + +namespace XFX +{ + namespace Graphics + { + /** + * Represents a set of bones associated with a model. + */ + class ModelBoneCollection : public ReadOnlyCollection + { + private: + friend class Model; + + ModelBoneCollection(IList * const list); + + public: + /** + * Finds a bone with a given name if it exists in the collection. + * + * @param boneName + * The name of the bone to find. + * + * @param value + * [OutAttribute] The bone named boneName, if found. + */ + bool TryGetValue(const String& boneName, out ModelBone * value); + + /** + * Retrieves a ModelBone from the collection, given the name of the bone. + * + * @param name + * The name of the bone to retrieve. + */ + ModelBone& operator[](const String& name) const; + }; + } +} + +#endif //_XFX_GRAPHICS_MODELBONECOLLECTION_ diff --git a/include/Graphics/ModelEffectCollection.h b/include/Graphics/ModelEffectCollection.h new file mode 100644 index 0000000..d45264f --- /dev/null +++ b/include/Graphics/ModelEffectCollection.h @@ -0,0 +1,32 @@ +/***************************************************************************** + * ModelEffectCollection.h * + * * + * XFX::Graphics::ModelEffectCollection class definition file * + * Copyright (c) XFX Team. All Rights Reserved * + *****************************************************************************/ +#ifndef _XFX_GRAPHICS_MODELEFFECTCOLLECTION_ +#define _XFX_GRAPHICS_MODELEFFECTCOLLECTION_ + +#include "Effect.h" +#include + +using namespace System::Collections::ObjectModel; + +namespace XFX +{ + namespace Graphics + { + /** + * Represents a collection of effects associated with a model. + */ + class ModelEffectCollection : public ReadOnlyCollection + { + private: + friend class Model; + + ModelEffectCollection(IList* list); + }; + } +} + +#endif //_XFX_GRAPHICS_MODELEFFECTCOLLECTION_ diff --git a/include/Graphics/ModelMesh.h b/include/Graphics/ModelMesh.h new file mode 100644 index 0000000..a9c28f1 --- /dev/null +++ b/include/Graphics/ModelMesh.h @@ -0,0 +1,62 @@ +/***************************************************************************** + * ModelMesh.h * + * * + * XFX::Graphics::ModelMesh class definition file * + * Copyright (c) XFX Team. All Rights Reserved * + *****************************************************************************/ +#ifndef _XFX_GRAPHICS_MODELMESH_ +#define _XFX_GRAPHICS_MODELMESH_ + +#include "ModelBone.h" +#include "ModelEffectCollection.h" +#include "ModelMeshPartCollection.h" +#include + +using namespace System; + +namespace XFX +{ + struct BoundingSphere; + + namespace Graphics + { + /** + * Represents a mesh that is part of a model. + */ + class ModelMesh + { + public: + /** + * Gets the BoundingSphere that contains this mesh. + */ + BoundingSphere getBoundingSphere() const; + /** + * Gets a collection of effects associated with this mesh. + */ + ModelEffectCollection getEffects() const; + /** + * Gets the ModelMeshPart objects that make up this mesh. Each part of a mesh is composed of a set of primitives that share the same material. + */ + ModelMeshPartCollection getMeshParts() const; + /** + * Gets the name of this mesh. + */ + const String& getName() const; + /** + * Gets the parent bone for this mesh. The parent bone of a mesh contains a transformation matrix that describes how the mesh is located relative to any parent meshes in a model. + */ + ModelBone getParentBone() const; + /** + * Gets or sets an object identifying this mesh. + */ + Object* Tag; + + /** + * Draws all of the ModelMeshPartObjects in this mesh, using their current Effect settings. + */ + void Draw(); + }; + } +} + +#endif //_XFX_GRAPHICS_MODELMESH_ diff --git a/include/Graphics/ModelMeshCollection.h b/include/Graphics/ModelMeshCollection.h new file mode 100644 index 0000000..d36a0fa --- /dev/null +++ b/include/Graphics/ModelMeshCollection.h @@ -0,0 +1,52 @@ +/***************************************************************************** + * ModelMeshCollection.h * + * * + * XFX::Graphics::ModelMeshCollection class definition file * + * Copyright (c) XFX Team. All Rights Reserved * + *****************************************************************************/ +#ifndef _XFX_GRAPHICS_MODELMESHCOLLECTION_ +#define _XFX_GRAPHICS_MODELMESHCOLLECTION_ + +#include "ModelMesh.h" +#include + +using namespace System::Collections::ObjectModel; + +namespace XFX +{ + namespace Graphics + { + /** + * Represents a collection of ModelMesh objects. + */ + class ModelMeshCollection : public ReadOnlyCollection + { + private: + friend class Model; + + ModelMeshCollection(IList* list); + + public: + /** + * Finds a mesh with a given name if it exists in the collection. + * + * @param boneName + * The name of the mesh to find. + * + * @param value + * [OutAttribute] The bone named boneName, if found. + */ + bool TryGetValue(const String& meshName, out ModelMesh * value); + + /** + * Retrieves a ModelMesh from the collection, given the name of the mesh. + * + * @param name + * The name of the bone to retrieve. + */ + ModelMesh& operator[](const String& name) const; + }; + } +} + +#endif //_XFX_GRAPHICS_MODELMESHCOLLECTION_ diff --git a/include/Graphics/ModelMeshPart.h b/include/Graphics/ModelMeshPart.h new file mode 100644 index 0000000..77d5eb5 --- /dev/null +++ b/include/Graphics/ModelMeshPart.h @@ -0,0 +1,60 @@ +/***************************************************************************** + * ModelMeshPart.h * + * * + * XFX::Graphics::ModelMeshPart class definition file * + * Copyright (c) XFX Team. All Rights Reserved * + *****************************************************************************/ +#ifndef _XFX_GRAPHICS_MODELMESHPART_ +#define _XFX_GRAPHICS_MODELMESHPART_ + +#include "Effect.h" +#include "IndexBuffer.h" +#include "VertexBuffer.h" + +namespace XFX +{ + namespace Graphics + { + /** + * Represents a batch of geometry information to submit to the graphics device during rendering. Each ModelMeshPart is a subdivision of a ModelMesh object. The ModelMesh class is split into multiple ModelMeshPart objects, typically based on material information. + */ + class ModelMeshPart + { + public: + /** + * Gets or sets the material effect for this mesh part. + */ + XFX::Graphics::Effect* Effect; + /** + * Gets the index buffer for this mesh part. + */ + IndexBuffer getIndexBuffer(); + /** + * Gets the number of vertices used during a draw call. + */ + int getNumVertices(); + /** + * Gets the number of primitives to render. + */ + int getPrimitiveCount(); + /** + * Gets the location in the index array at which to start reading vertices. + */ + int getStartIndex(); + /** + * Gets or sets an object identifying this model mesh part. + */ + Object* Tag; + /** + * Gets the vertex buffer for this mesh part. + */ + VertexBuffer getVertexBuffer(); + /** + * Gets the offset (in vertices) from the top of vertex buffer. + */ + int getVertexOffset(); + }; + } +} + +#endif //_XFX_GRAPHICS_MODELMESHPART_ diff --git a/include/Graphics/ModelMeshPartCollection.h b/include/Graphics/ModelMeshPartCollection.h new file mode 100644 index 0000000..04be510 --- /dev/null +++ b/include/Graphics/ModelMeshPartCollection.h @@ -0,0 +1,27 @@ +#ifndef _XFX_GRAPHICS_MODELMESHPARTCOLLECTION_ +#define _XFX_GRAPHICS_MODELMESHPARTCOLLECTION_ + +#include "ModelMeshPart.h" +#include + +using namespace System::Collections::ObjectModel; + +namespace XFX +{ + namespace Graphics + { + /** + * + */ + class ModelMeshPartCollection : public ReadOnlyCollection + { + private: + ModelMeshPartCollection(IList list); + + public: + + }; + } +} + +#endif //_XFX_GRAPHICS_MODELMESHPARTCOLLECTION_ diff --git a/include/Graphics/Texture.h b/include/Graphics/Texture.h index 6d9cff7..1193f2a 100644 --- a/include/Graphics/Texture.h +++ b/include/Graphics/Texture.h @@ -25,7 +25,7 @@ namespace XFX int _levelCount; protected: - virtual void Dispose(bool disposing); + void Dispose(bool disposing); public: SurfaceFormat_t getFormat() const; diff --git a/include/Graphics/Texture2D.h b/include/Graphics/Texture2D.h index 768bec2..63db985 100644 --- a/include/Graphics/Texture2D.h +++ b/include/Graphics/Texture2D.h @@ -1,5 +1,5 @@ /***************************************************************************** - * Texture2D.h * + * Texture2D.h * * * * XFX::Graphics::Texture2D class definition file * * Copyright (c) XFX Team. All Rights Reserved * @@ -11,12 +11,17 @@ #include #include -using namespace System; +using namespace System; using namespace System::IO; namespace XFX { struct Rectangle; + + namespace Content + { + class Texture2DReader; + } namespace Graphics { @@ -27,35 +32,37 @@ namespace XFX */ class Texture2D : public Texture { + friend class XFX::Content::Texture2DReader; + private: - bool _isDisposed; // True when the texture has been disposed - int _numberOfLevels; // The number of mip levels for the texture - SurfaceFormat_t _surfaceFormat; // The colour format of the texture - int textureId; // The reference ID of the texture in OpenGL memory + bool _isDisposed; // True when the texture has been disposed + int _numberOfLevels; // The number of mip levels for the texture + SurfaceFormat_t _surfaceFormat; // The colour format of the texture + int textureId; // The reference ID of the texture in OpenGL memory uint* textureData; - - void Load(byte buffer[]); - - protected: - void Dispose(bool disposing); - - public: + + void Load(byte buffer[]); + + protected: + void Dispose(bool disposing); + + public: Rectangle getBounds() const; - SurfaceFormat_t Format() const; - const int Height; - const int Width; - - Texture2D(GraphicsDevice * const graphicsDevice, const int width, const int height); + SurfaceFormat_t Format() const; + const int Height; + const int Width; + + Texture2D(GraphicsDevice * const graphicsDevice, const int width, const int height); Texture2D(GraphicsDevice * const graphicsDevice, const int width, const int height, bool mipmap, const SurfaceFormat_t format); virtual ~Texture2D(); static Texture2D* FromStream(GraphicsDevice * const graphicsDevice, Stream * const stream); static Texture2D* FromStream(GraphicsDevice * const graphicsDevice, Stream * const stream, int width, int height, bool zoom); - void GetData(uint data[], const int startIndex, const int elementCount) const; + void GetData(uint data[], const int startIndex, const int elementCount) const; static const Type& GetType(); void SaveAsJpeg(Stream * const stream, int width, int height); void SaveAsPng(Stream * const stream, int width, int height); - void SetData(uint data[], const int startIndex, const int elementCount); + void SetData(uint data[], const int startIndex, const int elementCount); bool operator ==(const Texture2D& right) const; bool operator !=(const Texture2D& right) const; diff --git a/include/System/Array.h b/include/System/Array.h index 1d4fd7f..4a812f5 100644 --- a/include/System/Array.h +++ b/include/System/Array.h @@ -1,5 +1,5 @@ /***************************************************************************** - * Array.h * + * Array.h * * * * XFX generic Array class definition file * * Contains array helper methods * @@ -99,7 +99,7 @@ namespace System sassert((startIndex + count) < Length, ""); int num = startIndex; - int num2 = (startIndex + count) - 1; + int num2 = (startIndex + count) - 1; while (num < num2) { swap(_array[num], _array[num2]); @@ -226,7 +226,7 @@ namespace System sassert((startIndex + count) < Length, ""); int num = startIndex; - int num2 = (startIndex + count) - 1; + int num2 = (startIndex + count) - 1; while (num < num2) { swap(_array[num], _array[num2]); @@ -283,14 +283,14 @@ namespace System sassert(array != null, String::Format("array; %s", FrameworkResources::ArgumentNull_Generic)); int num = index; - int num2 = (index + length) - 1; + int num2 = (index + length) - 1; while (num < num2) { T obj2 = array[num]; array[num] = array[num2]; array[num2] = obj2; num++; - num2--; + num2--; } }*/ } diff --git a/include/System/Collections/Generic/List.h b/include/System/Collections/Generic/List.h index 07cdac5..a98d2bc 100644 --- a/include/System/Collections/Generic/List.h +++ b/include/System/Collections/Generic/List.h @@ -1,5 +1,5 @@ /***************************************************************************** - * List.h * + * List.h * * * * XFX Generic List definition file * * Copyright (c) XFX Team. All Rights Reserved * @@ -107,7 +107,7 @@ namespace System } // Initializes a new instance of the List<> class that is empty and has the default initial capacity. - List() + List() : _size(0), _actualSize(defaultCapacity), _version(0) { _items = new T[_actualSize]; @@ -137,7 +137,7 @@ namespace System /** * Adds an element to the end of the list */ - void Add(const T& item) + void Add(const T& item) { if (_size == _actualSize) { @@ -150,7 +150,7 @@ namespace System /** * Removes all elements from the list */ - void Clear() + void Clear() { if (_size > 0) { @@ -179,7 +179,7 @@ namespace System { sassert(array != null, String::Format("array; %s", FrameworkResources::ArgumentNull_Generic)); - memcpy(array, &_items[arrayIndex], _size * sizeof(T)) + memcpy(&array[arrayIndex], _items, _size * sizeof(T)) } static const Type& GetType() @@ -275,14 +275,14 @@ namespace System sassert(!((_size - index) < count), "Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection."); int num = index; - int num2 = (index + count) - 1; + int num2 = (index + count) - 1; while (num < num2) { T obj2 = _items[num]; _items[num] = _items[num2]; _items[num2] = obj2; num++; - num2--; + num2--; } _version++; } diff --git a/include/System/Collections/ObjectModel/ReadOnlyCollection.h b/include/System/Collections/ObjectModel/ReadOnlyCollection.h new file mode 100644 index 0000000..c9d628e --- /dev/null +++ b/include/System/Collections/ObjectModel/ReadOnlyCollection.h @@ -0,0 +1,224 @@ +/***************************************************************************** + * ReadOnlyCollection.h * + * * + * System::Collections::ObjectModel::ReadOnlyCollection definition file * + * Copyright (c) XFX Team. All Rights Reserved * + *****************************************************************************/ +#ifndef _SYSTEM_COLLECTIONS_OBJECTMODEL_READONLYCOLLECTION_ +#define _SYSTEM_COLLECTIONS_OBJECTMODEL_READONLYCOLLECTION_ + +#include + +using namespace System::Collections::Generic; + +namespace System +{ + namespace Collections + { + namespace ObjectModel + { + /** + * Provides the base class for a generic read-only collection. + */ + template + class ReadOnlyCollection : public IEnumerable + { + private: + IList* items; + + public: + /** + * Gets the number of elements contained in the System::Collections::ObjectModel::ReadOnlyCollection instance. + * + * @return + * The number of elements contained in the System::Collections::ObjectModel::ReadOnlyCollection instance. + */ + inline int Count() const { return items->Count(); } + /** + * Returns the System::Collections::Generic::IList that the System::Collections::ObjectModel::ReadOnlyCollection wraps. + * + * @return + * The System::Collections::Generic::IList that the System::Collections::ObjectModel::ReadOnlyCollection wraps. + */ + inline IList const * const getItems() const { return items; } + + /** + * Initializes a new instance of the System::Collections::ObjectModel::ReadOnlyCollection class that is a read-only wrapper around the specified list. + * + * @param list + * The list to wrap. + */ + ReadOnlyCollection(IList * const list) + : items(list) + { + } + + /** + * Determines whether an element is in the System::Collections::ObjectModel::ReadOnlyCollection. + * + * @param item + * The object to locate in the System::Collections::ObjectModel::ReadOnlyCollection. The value can be null for reference types. + * + * @return + * true if value is found in the System::Collections::ObjectModel::ReadOnlyCollection; otherwise, false. + */ + inline bool Contains(const T& item) const + { + return items->Contains(item); + } + + /** + * Copies the entire System::Collections::ObjectModel::ReadOnlyCollection to a compatible one-dimensional System::Array, starting at the specified index of the target array. + * + * @param array + * The one-dimensional System::Array that is the destination of the elements copied from System::Collections::ObjectModel::ReadOnlyCollection. The System::Array must have zero-based indexing. + * + * @param index + * The zero-based index in array at which copying begins. + */ + inline void CopyTo(T array[], int index) const + { + items->CopyTo(array, index); + } + + /** + * Returns an enumerator that iterates through the System::Collections::ObjectModel::ReadOnlyCollection. + * + * @return + * An System::Collections::Generic::IEnumerator for the System::Collections::ObjectModel::ReadOnlyCollection. + */ + inline IEnumerator* GetEnumerator() + { + return items->GetEnumerator(); + } + + /** + * Searches for the specified object and returns the zero-based index of the first occurrence within the entire System::Collections::ObjectModel::ReadOnlyCollection. + * + * @param item + * The object to locate in the System::Collections::Generic::List. The value can be null for reference types. + * + * @return + * The zero-based index of the first occurrence of item within the entire System::Collections::ObjectModel::ReadOnlyCollection, if found; otherwise, -1. + */ + inline int IndexOf(const T& item) const + { + return items->IndexOf(item); + } + + /** + * Gets the element at the specified index. + * + * @param index + * The zero-based index of the element to get. + * + * @return + * The element at the specified index. + */ + inline T& operator[](int index) const { return *items[index]; } + }; + + /////////////////////////////////////////////////////////////////// + + template + class ReadOnlyCollection : public IEnumerable + { + private: + IList* items; + + public: + /** + * Gets the number of elements contained in the System::Collections::ObjectModel::ReadOnlyCollection instance. + * + * @return + * The number of elements contained in the System::Collections::ObjectModel::ReadOnlyCollection instance. + */ + inline int Count() const { return items->Count(); } + /** + * Returns the System::Collections::Generic::IList that the System::Collections::ObjectModel::ReadOnlyCollection wraps. + * + * @return + * The System::Collections::Generic::IList that the System::Collections::ObjectModel::ReadOnlyCollection wraps. + */ + inline IList const * const getItems() const { return items; } + + /** + * Initializes a new instance of the System::Collections::ObjectModel::ReadOnlyCollection class that is a read-only wrapper around the specified list. + * + * @param list + * The list to wrap. + */ + ReadOnlyCollection(IList * const list) + : items(list) + { + } + + /** + * Determines whether an element is in the System::Collections::ObjectModel::ReadOnlyCollection. + * + * @param item + * The object to locate in the System::Collections::ObjectModel::ReadOnlyCollection. The value can be null for reference types. + * + * @return + * true if value is found in the System::Collections::ObjectModel::ReadOnlyCollection; otherwise, false. + */ + inline bool Contains(const T* item) const + { + return items->Contains(item); + } + + /** + * Copies the entire System::Collections::ObjectModel::ReadOnlyCollection to a compatible one-dimensional System::Array, starting at the specified index of the target array. + * + * @param array + * The one-dimensional System::Array that is the destination of the elements copied from System::Collections::ObjectModel::ReadOnlyCollection. The System::Array must have zero-based indexing. + * + * @param index + * The zero-based index in array at which copying begins. + */ + inline void CopyTo(T* array[], int index) const + { + items->CopyTo(array, index); + } + + /** + * Returns an enumerator that iterates through the System::Collections::ObjectModel::ReadOnlyCollection. + * + * @return + * An System::Collections::Generic::IEnumerator for the System::Collections::ObjectModel::ReadOnlyCollection. + */ + inline IEnumerator* GetEnumerator() + { + return items->GetEnumerator(); + } + + /** + * Searches for the specified object and returns the zero-based index of the first occurrence within the entire System::Collections::ObjectModel::ReadOnlyCollection. + * + * @param item + * The object to locate in the System::Collections::Generic::List. The value can be null for reference types. + * + * @return + * The zero-based index of the first occurrence of item within the entire System::Collections::ObjectModel::ReadOnlyCollection, if found; otherwise, -1. + */ + inline int IndexOf(const T* item) const + { + return items->IndexOf(item); + } + + /** + * Gets the element at the specified index. + * + * @param index + * The zero-based index of the element to get. + * + * @return + * The element at the specified index. + */ + inline T* operator[](int index) const { return *items[index]; } + }; + } + } +} + +#endif //_SYSTEM_COLLECTIONS_OBJECTMODEL_READONLYCOLLECTION_ diff --git a/include/System/Diagnostics/Debug.h b/include/System/Diagnostics/Debug.h new file mode 100644 index 0000000..266a7ce --- /dev/null +++ b/include/System/Diagnostics/Debug.h @@ -0,0 +1,56 @@ +#ifndef _SYSTEM_DIAGNOSTICS_DEBUG_ +#define _SYSTEM_DIAGNOSTICS_DEBUG_ + +#if _MSC_VER +#define FORMAT +#else +#define FORMAT __attribute__(format(printf, 1, 2)); +#endif + +namespace System +{ + class String; + + namespace Diagnostics + { + /** + * Provides a set of methods and properties that help debug your code. This class cannot be inherited. + */ + class Debug + { + private: + Debug(); + + public: + /** + * Checks for a condition; if the condition is false, displays a message box that shows the call stack. + * + * @param condition + * The conditional expression to evaluate. If the condition is true, a failure message is not sent and the message box is not displayed. + */ + static void Assert(bool condition); + /** + * Checks for a condition; if the condition is false, outputs a specified message and displays a message box that shows the call stack. + * + * @param condition + * The conditional expression to evaluate. If the condition is true, the message is not sent and the message box is not displayed. + * + * @param message + * Checks for a condition; if the condition is false, outputs a specified message and displays a message box that shows the call stack. + */ + static void Assert(bool condition, const String& message); + /** + * Writes a formatted message followed by a line terminator to the attached debugger. + * + * @param format + * A composite format string that contains text intermixed with zero or more format items, which correspond to objects in the args array. + * + * @param args + * An object array containing zero or more objects to format. + */ + static void WriteLine(const String& format, ...) FORMAT; + }; + } +} + +#endif //_SYSTEM_DIAGNOSTICS_DEBUG_ diff --git a/include/System/FrameworkResources.h b/include/System/FrameworkResources.h index 189a6c5..9e9d36a 100644 --- a/include/System/FrameworkResources.h +++ b/include/System/FrameworkResources.h @@ -16,6 +16,7 @@ namespace System static const char* ArgumentNull_FileName; static const char* ArgumentNull_Generic; static const char* ArgumentNull_Path; + static const char* ArgumentOutOfRange_Index; static const char* ArgumentOutOfRange_NeedNonNegNum; static const char* ArgumentOutOfRange_NeedPosNum; static const char* ArgumentOutOfRange_NegativeCapacity; diff --git a/include/System/IO/BinaryReader.h b/include/System/IO/BinaryReader.h index 122c4c8..6fbcfcf 100644 --- a/include/System/IO/BinaryReader.h +++ b/include/System/IO/BinaryReader.h @@ -4,6 +4,8 @@ #include #include "Stream.h" +#include + namespace System { class String; @@ -33,11 +35,13 @@ namespace System protected: virtual void Dispose(bool disposing); virtual void FillBuffer(int numBytes); + int Read7BitEncodedInt(); public: virtual Stream* BaseStream(); - BinaryReader(Stream* input); + BinaryReader(FILE * const file); + BinaryReader(Stream * const input); virtual ~BinaryReader(); virtual void Close(); diff --git a/include/System/IO/FileStream.h b/include/System/IO/FileStream.h index 71783fc..d36c964 100644 --- a/include/System/IO/FileStream.h +++ b/include/System/IO/FileStream.h @@ -12,6 +12,8 @@ #include "Enums.h" #include "Stream.h" +#include + namespace System { namespace IO @@ -22,6 +24,7 @@ namespace System class FileStream : public Stream { private: + FILE* _file; void* handle; //int handle; byte* _buffer; @@ -51,6 +54,7 @@ namespace System void setPosition(long long newPosition); FileStream(); + FileStream(FILE * const file); FileStream(const String& path, const FileMode_t mode); FileStream(const String& path, const FileMode_t mode, const FileAccess_t access); FileStream(const String& path, const FileMode_t mode, const FileAccess_t access, const FileShare_t share); @@ -58,10 +62,10 @@ namespace System FileStream(const String& path, const FileMode_t mode, const FileAccess_t access, const FileShare_t share, const int bufferSize, const bool useAsync); virtual ~FileStream(); - virtual IAsyncResult* BeginRead(byte buffer[], int offset, int count, AsyncCallback callback, Object* state); - virtual IAsyncResult* BeginWrite(byte buffer[], int offset, int count, AsyncCallback callback, Object* state); - virtual int EndRead(IAsyncResult* asyncResult); - virtual void EndWrite(IAsyncResult* asyncResult); + virtual IAsyncResult* BeginRead(byte buffer[], int offset, int count, AsyncCallback callback, Object * const state); + virtual IAsyncResult* BeginWrite(byte buffer[], int offset, int count, AsyncCallback callback, Object * const state); + virtual int EndRead(IAsyncResult * const asyncResult); + virtual void EndWrite(IAsyncResult * const asyncResult); void Flush(); static const Type& GetType(); int Read(byte array[], const int offset, const int count); diff --git a/include/System/IO/file.h b/include/System/IO/file.h index 826c27b..4583b17 100644 --- a/include/System/IO/file.h +++ b/include/System/IO/file.h @@ -31,7 +31,7 @@ namespace System #if ENABLE_XBOX static int FileAttributeInfo(const String& path, PXBOX_FIND_DATA data, bool tryagain, bool returnErrorOnNotFound); #else - static int FileAttributeInfo(char* path, data, bool tryagain, bool returnErrorOnNotFound); + static int FileAttributeInfo(const String& path, data, bool tryagain, bool returnErrorOnNotFound); #endif public: diff --git a/include/System/Type.h b/include/System/Type.h index 7a5bd03..6222781 100644 --- a/include/System/Type.h +++ b/include/System/Type.h @@ -1,8 +1,8 @@ /***************************************************************************** * DependencyProperty.h * * * - * System::Windows::DependencyProperty definition file * - * Copyright (c) XFX Team. All rights reserved * + * System::Windows::DependencyProperty definition file * + * Copyright (c) XFX Team. All rights reserved * *****************************************************************************/ #ifndef _SYSTEM_TYPE_ #define _SYSTEM_TYPE_ @@ -38,7 +38,7 @@ namespace System Type(const String& name, const String& fullName, const TypeCode_t typeCode, const bool hasGenericParameters = false); /** - * Determines if the underlying system type of the current System::Type is the same as the underlying system type of the specified System::Object. + * Determines if the underlying system type of the current System::Type is the same as the underlying system type of the specified System::Object. * * @param obj * The System::Object whose underlying system type is to be compared with the underlying system type of the current System::Type. diff --git a/include/sassert.h b/include/sassert.h index 5f58336..765c47b 100644 --- a/include/sassert.h +++ b/include/sassert.h @@ -12,7 +12,7 @@ extern "C" { #ifdef NDEBUG /* required by ANSI standard */ #define sassert(e,msg) ((void)0) #else -//! Causes a blue screen of death if e is not true with the msg "msg" displayed +// Causes a blue screen of death if e is not true with the msg "msg" displayed #define sassert(e,msg) ((e) ? (void)0 : __sassert(__FILE__, __LINE__, #e, msg)) #endif /* NDEBUG */ diff --git a/src/libSystem/Debug.cpp b/src/libSystem/Debug.cpp new file mode 100644 index 0000000..abd8bf2 --- /dev/null +++ b/src/libSystem/Debug.cpp @@ -0,0 +1,83 @@ +// Copyright (C) XFX Team +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +//* Redistributions of source code must retain the above copyright +//notice, this list of conditions and the following disclaimer. +//* Redistributions in binary form must reproduce the above copyright +//notice, this list of conditions and the following disclaimer in the +//documentation and/or other materials provided with the distribution. +//* Neither the name of the copyright holder nor the names of any +//contributors may be used to endorse or promote products derived from +//this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +#include +#include + +#if ENABLE_XBOX +#include +#else +// TODO: include Linux' debug header +#endif + +namespace System +{ + namespace Diagnostics + { + void Debug::Assert(bool condition) + { +#if DEBUG + if (condition) + { +#endif + return; +#if DEBUG + } + + // TODO: implement +#endif + } + + void Debug::Assert(bool condition, const String& message) + { +#if DEBUG + if (condition) + { +#endif + return; +#if DEBUG + } + + // TODO: implement +#endif + } + + void Debug::WriteLine(const String& format, ...) + { +#if !DEBUG + return; +#else + if (String::IsNullOrEmpty(format)) + { + return; + } + + // TODO: implement +#endif + } + } +} diff --git a/src/libSystem/libSystem.vcxproj b/src/libSystem/libSystem.vcxproj index ece8a9a..daa25bb 100644 --- a/src/libSystem/libSystem.vcxproj +++ b/src/libSystem/libSystem.vcxproj @@ -72,6 +72,7 @@ + @@ -79,6 +80,7 @@ + diff --git a/src/libSystem/libSystem.vcxproj.filters b/src/libSystem/libSystem.vcxproj.filters index 54a02fa..b9dab7a 100644 --- a/src/libSystem/libSystem.vcxproj.filters +++ b/src/libSystem/libSystem.vcxproj.filters @@ -25,6 +25,18 @@ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav + + {e5bf276b-a008-4dca-8230-a7bca29e8acb} + + + {7ce6f2df-e8a4-4775-a038-97daadab1d8b} + + + {56a599bf-d3a8-4e93-adb5-09b5ae4c5544} + + + {0b37cc7b-fbd5-4d60-8e8d-99f0bde53754} + @@ -39,25 +51,31 @@ Source Files\ComponentModel + + Source Files\Diagnostics + Header Files\ComponentModel + + Header Files\Diagnostics + - Source Files\Net + Header Files\Net - Source Files\Net + Header Files\Net - Source Files\Net\Sockets + Header Files\Net\Sockets - Source Files\Net\Sockets + Header Files\Net\Sockets - Source Files\Net\Sockets + Header Files\Net\Sockets diff --git a/src/libSystem/makefile b/src/libSystem/makefile index 3e2ce42..21fcd0f 100644 --- a/src/libSystem/makefile +++ b/src/libSystem/makefile @@ -26,7 +26,7 @@ LD_FLAGS = $(CLINK) $(ALIGN) $(SHARED) $(ENTRYPOINT) $(STRIP) LD_DIRS = -L$(PREFIX)/i386-pc-xbox/lib -L$(PREFIX)/lib LD_LIBS = $(LD_DIRS) -lmscorlib -lm -lopenxdk -lhal -lc -lusb -lc -lxboxkrnl -lc -lhal -lxboxkrnl -lhal -lopenxdk -lc -lgcc -lstdc++ -OBJS = CancelEventArgs.o Socket.o SocketAddress.o SocketAsyncEventArgs.o +OBJS = CancelEventArgs.o Debug.o Socket.o SocketAddress.o SocketAsyncEventArgs.o all: libSystem.a diff --git a/src/libXFX/Enums.h b/src/libXFX/Enums.h new file mode 100644 index 0000000..0a077bd --- /dev/null +++ b/src/libXFX/Enums.h @@ -0,0 +1,74 @@ +#ifndef _XFX_GRAPHICS_ENUMS_LEGACY_ +#define _XFX_GRAPHICS_ENUMS_LEGACY_ + +namespace XFX +{ + namespace Graphics + { + struct SurfaceFormat_Legacy + { + enum type + { + Unknown = -1, + Color = 1, + Bgr32 = 2, + Bgra1010102 = 3, + Rgba32 = 4, + Rgb32 = 5, + Rgba1010102 = 6, + Rg32 = 7, + Rgba64 = 8, + Bgr565 = 9, + Bgra5551 = 10, + Bgr555 = 11, + Bgra4444 = 12, + Bgr444 = 13, + Bgra2338 = 14, + Alpha8 = 15, + Bgr233 = 16, + Bgr24 = 17, + NormalizedByte2 = 18, + NormalizedByte4 = 19, + NormalizedShort2 = 20, + NormalizedShort4 = 21, + Single = 22, + Vector2 = 23, + Vector4 = 24, + HalfSingle = 25, + HalfVector2 = 26, + HalfVector4 = 27, + Dxt1 = 28, + Dxt2 = 29, + Dxt3 = 30, + Dxt4 = 31, + Dxt5 = 32, + Luminance8 = 33, + Luminance16 = 34, + LuminanceAlpha8 = 35, + LuminanceAlpha16 = 36, + Palette8 = 37, + PaletteAlpha16 = 38, + NormalizedLuminance16 = 39, + NormalizedLuminance32 = 40, + NormalizedAlpha1010102 = 41, + NormalizedByte2Computed = 42, + VideoYuYv = 43, + VideoUyVy = 44, + VideoGrGb = 45, + VideoRgBg = 46, + Multi2Bgra32 = 47, + Depth24Stencil8 = 48, + Depth24Stencil8Single = 49, + Depth24Stencil4 = 50, + Depth24 = 51, + Depth32 = 52, + Depth16 = 54, + Depth15Stencil1 = 56, + }; + }; + + typedef SurfaceFormat_Legacy::type SurfaceFormat_Legacy_t; + } +} + +#endif //_XFX_GRAPHICS_ENUMS_LEGACY_ \ No newline at end of file diff --git a/src/libXFX/Model.cpp b/src/libXFX/Model.cpp new file mode 100644 index 0000000..6756f96 --- /dev/null +++ b/src/libXFX/Model.cpp @@ -0,0 +1,110 @@ +// Copyright (C) XFX Team +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +//* Redistributions of source code must retain the above copyright +//notice, this list of conditions and the following disclaimer. +//* Redistributions in binary form must reproduce the above copyright +//notice, this list of conditions and the following disclaimer in the +//documentation and/or other materials provided with the distribution. +//* Neither the name of the copyright holder nor the names of any +//contributors may be used to endorse or promote products derived from +//this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +#include + +namespace XFX +{ + namespace Graphics + { + ModelBoneCollection Model::getBones() + { + return ModelBoneCollection(&bones); + } + + ModelMeshCollection Model::getMeshes() + { + return ModelMeshCollection(&meshes); + } + + ModelBone Model::getRoot() + { + // TODO: implement + } + + void Model::CopyAbsoluteBoneTransformsTo(Matrix destinationBoneTransforms[]) + { + sassert(destinationBoneTransforms != null, FrameworkResources::ArgumentNull_Generic); + + int count = bones.Count; + for (int index1 = 0; index1 < count; ++index1) + { + ModelBone modelBone = bones[index1]; + if (modelBone.getParent() == null) + { + destinationBoneTransforms[index1] = modelBone.Transform; + } + else + { + int index2 = modelBone.getParent()->getIndex(); + Matrix::Multiply(modelBone.Transform, destinationBoneTransforms[index2], out destinationBoneTransforms[index1]); + } + } + + } + + void Model::CopyBoneTransformsFrom(Matrix sourceBoneTransforms[]) + { + sassert(sourceBoneTransforms != null, FrameworkResources::ArgumentNull_Generic); + + // TODO: implement + } + + void Model::CopyBoneTransformsTo(Matrix destinationBoneTransforms[]) + { + sassert(destinationBoneTransforms != null, FrameworkResources::ArgumentNull_Generic); + + // TODO: implement + } + + void Model::Draw(Matrix world, Matrix view, Matrix projection) + { + int boneCount = bones.Count; + + if (sharedDrawBoneMatrices == null || sharedDrawBoneMatrixCount < boneCount) + { + if (sharedDrawBoneMatrices != null) + { + delete sharedDrawBoneMatrices; + } + + sharedDrawBoneMatrices = new Matrix[boneCount]; + sharedDrawBoneMatrixCount = boneCount; + } + + // Look up combined bone matrices for the entire model. + CopyAbsoluteBoneTransformsTo(sharedDrawBoneMatrices); + + for (int i = 0; i < meshes.Count(); i++) + { + // TODO: implement + + meshes[i].Draw(); + } + } + } +} diff --git a/src/libXFX/ModelReader.cpp b/src/libXFX/ModelReader.cpp new file mode 100644 index 0000000..30d74d8 --- /dev/null +++ b/src/libXFX/ModelReader.cpp @@ -0,0 +1,72 @@ +// Copyright (C) XFX Team +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +//* Redistributions of source code must retain the above copyright +//notice, this list of conditions and the following disclaimer. +//* Redistributions in binary form must reproduce the above copyright +//notice, this list of conditions and the following disclaimer in the +//documentation and/or other materials provided with the distribution. +//* Neither the name of the copyright holder nor the names of any +//contributors may be used to endorse or promote products derived from +//this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +#include "ModelReader.h" + +#include + +#include + +using namespace System::Diagnostics; + +namespace XFX +{ + namespace Content + { + Model* ModelReader::Read(ContentReader * const reader, Model* existingInstance) + { + Model* model = NULL; + + if (existingInstance == NULL) + { + + } + else + { + model = existingInstance; + + // TODO: clean up the old model data + } + + uint boneCount = reader->ReadUInt32(); + + for (uint i = 0; i < boneCount; i++) + { + ModelBone bone; + + bone.Transform = reader->ReadMatrix(); + + model->bones.Add(bone); + } + + for (uint i = 0; i < boneCount; i++) + { + + } + } + } +} diff --git a/src/libXFX/ModelReader.h b/src/libXFX/ModelReader.h new file mode 100644 index 0000000..8ef333d --- /dev/null +++ b/src/libXFX/ModelReader.h @@ -0,0 +1,27 @@ +/***************************************************************************** + * ModelReader.h * + * * + * XFX::Content::ModelReader class definition file * + * Copyright (c) XFX Team. All Rights Reserved * + *****************************************************************************/ +#ifndef _XFX_CONTENT_MODELREADER_ +#define _XFX_CONTENT_MODELREADER_ + +#include +#include + +using namespace XFX::Graphics; + +namespace XFX +{ + namespace Content + { + class ModelReader : public ContentTypeReader + { + public: + Model* Read(ContentReader * const input, Model* existingInstance); + }; + } +} + +#endif //_XFX_CONTENT_MODELREADER_ diff --git a/src/libXFX/Texture2D.cpp b/src/libXFX/Texture2D.cpp index b87cc63..e5fe3a0 100644 --- a/src/libXFX/Texture2D.cpp +++ b/src/libXFX/Texture2D.cpp @@ -32,6 +32,7 @@ #include #include +#include using namespace XFX; @@ -39,11 +40,13 @@ namespace XFX { namespace Graphics { + static const Type Texture2DTypeInfo("Texture2D", "XFX::Graphics::Texture2D", TypeCode::Object); + SurfaceFormat_t Texture2D::Format() const { return _surfaceFormat; } - + Texture2D::Texture2D(GraphicsDevice * const graphicsDevice, const int width, const int height) : textureData(new uint[width * height]), Height(height), Width(width) { @@ -63,7 +66,7 @@ namespace XFX this->graphicsDevice->getTextures().textures.Add(this); _surfaceFormat = format; } - + void Texture2D::Dispose(bool disposing) { if(!_isDisposed) @@ -75,9 +78,7 @@ namespace XFX catch(Exception) { - } - if(device.Textures().textures.Contains(this)) - device.Textures().textures.Remove(this);*/ + }*/ delete[] textureData; @@ -87,9 +88,9 @@ namespace XFX _isDisposed = true; } - int Texture2D::GetType() + const Type& Texture2D::GetType() { - // TODO: implement + return Texture2DTypeInfo; } void Texture2D::GetData(uint data[], const int startIndex, const int elementCount) const @@ -115,24 +116,24 @@ namespace XFX data[i] = (textureData[j] & valueMask); } } - + void Texture2D::Load(byte buffer[]) { - /*imageId = Il::ilGenImage(); - Il::ilBindImage(imageId); - Il::ilLoadL(Il::IL_JPG, buffer, buffer.Length); - - int[] texture = int[1]; - glGenTextures(1, texture); - textureId = texture[0]; - glBindTexture(GL_TEXTURE_2D, textureId); - glTexImage2D(GL_TEXTURE_2D, 0, Il::ilGetInteger(Il::IL_IMAGE_BYTES_PER_PIXEL), _width, _height, 0, GL_RGBA, GL_UNSIGNED_BYTE, Il::ilGetData()); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);*/ + /*imageId = Il::ilGenImage(); + Il::ilBindImage(imageId); + Il::ilLoadL(Il::IL_JPG, buffer, buffer.Length); + + int[] texture = int[1]; + glGenTextures(1, texture); + textureId = texture[0]; + glBindTexture(GL_TEXTURE_2D, textureId); + glTexImage2D(GL_TEXTURE_2D, 0, Il::ilGetInteger(Il::IL_IMAGE_BYTES_PER_PIXEL), _width, _height, 0, GL_RGBA, GL_UNSIGNED_BYTE, Il::ilGetData()); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);*/ } - - void Texture2D::SetData(uint data[], const int startIndex, const int elementCount) - { + + void Texture2D::SetData(uint data[], const int startIndex, const int elementCount) + { sassert(data != null, FrameworkResources::ArgumentNull_Buffer); sassert(elementCount <= Width * Height, "elementCount is larger than the texture size"); @@ -151,7 +152,7 @@ namespace XFX { textureData[i] = (data[j] | dataMask); } - } + } bool Texture2D::operator ==(const Texture2D& right) const { diff --git a/src/libXFX/Texture2DReader.cpp b/src/libXFX/Texture2DReader.cpp new file mode 100644 index 0000000..1191ac3 --- /dev/null +++ b/src/libXFX/Texture2DReader.cpp @@ -0,0 +1,228 @@ +// Copyright (C) XFX Team +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +//* Redistributions of source code must retain the above copyright +//notice, this list of conditions and the following disclaimer. +//* Redistributions in binary form must reproduce the above copyright +//notice, this list of conditions and the following disclaimer in the +//documentation and/or other materials provided with the distribution. +//* Neither the name of the copyright holder nor the names of any +//contributors may be used to endorse or promote products derived from +//this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +#include "Enums.h" +#include "Texture2DReader.h" + +#include +#include +#include + +using namespace System; + +namespace XFX +{ + namespace Content + { + Texture2D* Texture2DReader::Read(ContentReader * reader, Texture2D * existingInstance) + { + Texture2D* texture = null; + + SurfaceFormat_t surfaceFormat; + + if (reader->getVersion() < 5) + { + SurfaceFormat_Legacy_t legacyFormat = (SurfaceFormat_Legacy_t)reader->ReadInt32(); + switch(legacyFormat) + { + case SurfaceFormat_Legacy::Dxt1: + surfaceFormat = SurfaceFormat::Dxt1; + break; + case SurfaceFormat_Legacy::Dxt3: + surfaceFormat = SurfaceFormat::Dxt3; + break; + case SurfaceFormat_Legacy::Dxt5: + surfaceFormat = SurfaceFormat::Dxt5; + break; + case SurfaceFormat_Legacy::Color: + surfaceFormat = SurfaceFormat::Color; + break; + default: + //throw new NotImplementedException(); + break; + } + } + else + { + surfaceFormat = (SurfaceFormat_t)reader->ReadInt32(); + } + + int width = reader->ReadInt32(); + int height = reader->ReadInt32(); + int levelCount = reader->ReadInt32(); + int levelCountOutput = levelCount; + + // If the system does not fully support Power of Two textures, + // skip any mip maps supplied with any non PoT textures. + if (levelCount > 1 && !GraphicsCapabilities.SupportsNonPowerOfTwo && + (!MathHelper::IsPowerOfTwo(width) || !MathHelper::IsPowerOfTwo(height))) + { + levelCountOutput = 1; + System::Diagnostics::Debug::WriteLine( + "Device does not support non Power of Two textures. Skipping mipmaps."); + } + + SurfaceFormat_t convertedFormat = surfaceFormat; + switch (surfaceFormat) + { + case SurfaceFormat::Dxt1: + //case SurfaceFormat::Dxt1a: + if (!GraphicsCapabilities.SupportsDxt1) + convertedFormat = SurfaceFormat::Color; + break; + case SurfaceFormat::Dxt3: + case SurfaceFormat::Dxt5: + if (!GraphicsCapabilities.SupportsS3tc) + convertedFormat = SurfaceFormat::Color; + break; + case SurfaceFormat::NormalizedByte4: + convertedFormat = SurfaceFormat::Color; + break; + } + + if (existingInstance == null) + { + texture = new Texture2D(reader->getGraphicsDevice(), width, height, levelCountOutput > 1, convertedFormat); + } + else + { + texture = existingInstance; + + texture->Dispose(); + + texture = new Texture2D(reader->getGraphicsDevice(), width, height, levelCountOutput > 1, convertedFormat); + } + + for (int level=0; levelReadInt32(); + byte* levelData = reader->ReadBytes(levelDataSizeInBytes); + int levelWidth = width >> level; + int levelHeight = height >> level; + + if (level >= levelCountOutput) + { + continue; + } + + switch (surfaceFormat) + { + case SurfaceFormat::Dxt1: + //case SurfaceFormat::Dxt1a: + if (!GraphicsCapabilities.SupportsDxt1) + levelData = DxtUtil::DecompressDxt1(levelData, levelWidth, levelHeight); + break; + case SurfaceFormat::Dxt3: + if (!GraphicsCapabilities.SupportsS3tc) + levelData = DxtUtil::DecompressDxt3(levelData, levelWidth, levelHeight); + break; + case SurfaceFormat::Dxt5: + if (!GraphicsCapabilities.SupportsS3tc) + levelData = DxtUtil::DecompressDxt5(levelData, levelWidth, levelHeight); + break; + case SurfaceFormat::Bgr565: + { + /* + // BGR -> BGR + int offset = 0; + for (int y = 0; y < levelHeight; y++) + { + for (int x = 0; x < levelWidth; x++) + { + ushort pixel = BitConverter.ToUInt16(levelData, offset); + pixel = (ushort)(((pixel & 0x0FFF) << 4) | ((pixel & 0xF000) >> 12)); + levelData[offset] = (byte)(pixel); + levelData[offset + 1] = (byte)(pixel >> 8); + offset += 2; + } + } + */ + } + break; + case SurfaceFormat::Bgra5551: + { +#if OPENGL + // Shift the channels to suit OPENGL + int offset = 0; + for (int y = 0; y < levelHeight; y++) + { + for (int x = 0; x < levelWidth; x++) + { + ushort pixel = BitConverter::ToUInt16(levelData, offset); + pixel = (ushort)(((pixel & 0x7FFF) << 1) | ((pixel & 0x8000) >> 15)); + levelData[offset] = (byte)(pixel); + levelData[offset + 1] = (byte)(pixel >> 8); + offset += 2; + } + } +#endif + } + break; + case SurfaceFormat::Bgra4444: + { +#if OPENGL + // Shift the channels to suit OPENGL + int offset = 0; + for (int y = 0; y < levelHeight; y++) + { + for (int x = 0; x < levelWidth; x++) + { + ushort pixel = BitConverter::ToUInt16(levelData, offset); + pixel = (ushort)(((pixel & 0x0FFF) << 4) | ((pixel & 0xF000) >> 12)); + levelData[offset] = (byte)(pixel); + levelData[offset + 1] = (byte)(pixel >> 8); + offset += 2; + } + } +#endif + } + break; + case SurfaceFormat::NormalizedByte4: + { + int bytesPerPixel = surfaceFormat.Size(); + int pitch = levelWidth * bytesPerPixel; + for (int y = 0; y < levelHeight; y++) + { + for (int x = 0; x < levelWidth; x++) + { + int color = BitConverter::ToInt32(levelData, y * pitch + x * bytesPerPixel); + levelData[y * pitch + x * 4] = (byte)(((color >> 16) & 0xff)); //R:=W + levelData[y * pitch + x * 4 + 1] = (byte)(((color >> 8) & 0xff)); //G:=V + levelData[y * pitch + x * 4 + 2] = (byte)(((color) & 0xff)); //B:=U + levelData[y * pitch + x * 4 + 3] = (byte)(((color >> 24) & 0xff)); //A:=Q + } + } + } + break; + } + + //texture->SetData(levelData, 0, + } + return texture; + } + } +} diff --git a/src/libXFX/Texture2DReader.h b/src/libXFX/Texture2DReader.h new file mode 100644 index 0000000..0c43d2a --- /dev/null +++ b/src/libXFX/Texture2DReader.h @@ -0,0 +1,27 @@ +/***************************************************************************** + * Texture2DReader.h * + * * + * XFX::Content::Texture2DReader class definition file * + * Copyright (c) XFX Team. All Rights Reserved * + *****************************************************************************/ +#ifndef _XFX_CONTENT_TEXTURE2DREADER_ +#define _XFX_CONTENT_TEXTURE2DREADER_ + +#include +#include + +using namespace XFX::Graphics; + +namespace XFX +{ + namespace Content + { + class Texture2DReader : public ContentTypeReader + { + protected: + Texture2D* Read(ContentReader * const input, Texture2D* existingInstance); + }; + } +} + +#endif //_XFX_CONTENT_TEXTURE2DREADER_ diff --git a/src/libXFX/XNBFile.h b/src/libXFX/XNBFile.h new file mode 100644 index 0000000..79d293f --- /dev/null +++ b/src/libXFX/XNBFile.h @@ -0,0 +1,26 @@ +#ifndef _XNBFILE_ +#define _XNBFILE_ + +#include + +using namespace System; + +namespace XFX +{ + namespace Content + { + struct XNBFile + { + byte FormatID1; + byte FormatID2; + byte FormatID3; + byte TargetPlatform; + byte XNBVersion; + byte FlagBits; + uint CompressedSize; + uint UncompressedSize; + }; + } +} + +#endif //_XNBFILE_ diff --git a/src/libXFX/libXFX.vcxproj b/src/libXFX/libXFX.vcxproj index 88d8d84..adc2436 100644 --- a/src/libXFX/libXFX.vcxproj +++ b/src/libXFX/libXFX.vcxproj @@ -43,7 +43,7 @@ make -f makefile clean 2>&1 | sed -e %27s/\(\w\+\):\([0-9]\+\):/\1(\2):/%27 ENABLE_XBOX; DEBUG;$(NMakePreprocessorDefinitions) - C:\cygwin\usr\local\openxdk\include;C:\cygwin\usr\local\openxdk\i386-pc-xbox\include;C:\cygwin\usr\local\openxdk\include\SDL;..\..\include + C:\cygwin\usr\local\openxdk\include;C:\cygwin\usr\local\openxdk\i386-pc-xbox\include;C:\cygwin\usr\local\openxdk\include\SDL;$(SolutionDir)include $(NMakeForcedIncludes) $(NMakeAssemblySearchPath) $(NMakeForcedUsingAssemblies) @@ -53,6 +53,9 @@ + + $(SolutionDir)include + BuildLog.htm @@ -79,12 +82,15 @@ + + + @@ -148,6 +154,14 @@ + + + + + + + + @@ -226,6 +240,9 @@ + + + diff --git a/src/libXFX/libXFX.vcxproj.filters b/src/libXFX/libXFX.vcxproj.filters index 4109650..2b6a2b4 100644 --- a/src/libXFX/libXFX.vcxproj.filters +++ b/src/libXFX/libXFX.vcxproj.filters @@ -60,6 +60,12 @@ {c6888ccb-ccfe-447e-877d-1ee15a7bae48} + + {6660d5ba-e9f3-4326-8e2e-074328719d1a} + + + {dfe18763-6837-43b8-a2f6-65708ca1a24e} + @@ -221,6 +227,15 @@ Source Files\Graphics + + Source Files\Content\ContentReaders + + + Source Files\Content\ContentReaders + + + Source Files\Graphics + @@ -520,6 +535,39 @@ Header Files\Input + + Header Files\Content\ContentReaders + + + Source Files\Content + + + Header Files\Content\ContentReaders + + + Header Files\Graphics + + + Header Files\Graphics + + + Header Files\Graphics + + + Header Files\Graphics + + + Header Files\Graphics + + + Header Files\Graphics + + + Header Files\Graphics + + + Header Files\Graphics + diff --git a/src/libmscorlib/BinaryReader.cpp b/src/libmscorlib/BinaryReader.cpp index 6141015..10482dc 100644 --- a/src/libmscorlib/BinaryReader.cpp +++ b/src/libmscorlib/BinaryReader.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -43,7 +44,7 @@ namespace System return m_stream; } - BinaryReader::BinaryReader(Stream* input) + BinaryReader::BinaryReader(Stream * const input) { sassert(input->CanRead(), FrameworkResources::NotSupported_UnreadableStream); @@ -52,6 +53,11 @@ namespace System m_buffer = new byte[32]; } + BinaryReader::BinaryReader(FILE * const file) + : m_stream(new FileStream(file)) + { + } + BinaryReader::~BinaryReader() { Dispose(false); @@ -283,6 +289,23 @@ namespace System return InternalReadChars(buffer, index, count); } + int BinaryReader::Read7BitEncodedInt() + { + uint result = 0; + uint bitsRead = 0; + uint value; + + do + { + value = ReadByte(); + result |= (value & 0x7f) << bitsRead; + bitsRead += 7; + } + while (value & 0x80); + + return result; + } + bool BinaryReader::ReadBoolean() { FillBuffer(1); diff --git a/src/libmscorlib/BitConverter.cpp b/src/libmscorlib/BitConverter.cpp index 617279a..b4a974f 100644 --- a/src/libmscorlib/BitConverter.cpp +++ b/src/libmscorlib/BitConverter.cpp @@ -30,6 +30,7 @@ #include #include +#include namespace System { @@ -79,10 +80,7 @@ namespace System { byte *ret = new byte[count]; - for (int i = 0; i < count; i++) - { - ret[i] = ptr[i]; - } + memcpy(ret, ptr, count); return ret; } @@ -162,7 +160,9 @@ namespace System }*/ if (value[startIndex] != 0) + { return true; + } return false; } diff --git a/src/libmscorlib/Double.cpp b/src/libmscorlib/Double.cpp index bc3f5fe..c3049ac 100644 --- a/src/libmscorlib/Double.cpp +++ b/src/libmscorlib/Double.cpp @@ -37,9 +37,9 @@ namespace System { - unsigned long long rawNaND = 0x7ff8000000000000ULL; - unsigned long long rawPosInfD = 0x7ff0000000000000ULL; - unsigned long long rawNegInfD = 0xfff0000000000000ULL; + static unsigned long long rawNaND = 0x7ff8000000000000ULL; + static unsigned long long rawPosInfD = 0x7ff0000000000000ULL; + static unsigned long long rawNegInfD = 0xfff0000000000000ULL; const double Double::Epsilon = 4.94066e-324; const double Double::MaxValue = 1.79769e+308; diff --git a/src/libmscorlib/Environment.cpp b/src/libmscorlib/Environment.cpp index 66b0f12..e6d0e6c 100644 --- a/src/libmscorlib/Environment.cpp +++ b/src/libmscorlib/Environment.cpp @@ -60,6 +60,11 @@ namespace System return ""; } #else + switch (folder) + { + case SpecialFolder::Personal: + return "~"; + } #endif } @@ -70,7 +75,11 @@ namespace System OperatingSystem Environment::OSVersion() { +#if ENABLE_XBOX return OperatingSystem(PlatformID::Xbox, Version(XboxKrnlVersion->VersionMajor, XboxKrnlVersion->VersionMinor, XboxKrnlVersion->Build)); +#else + return OperatingSystem(PlatformID::Linux, Version()); +#endif } int Environment::ProcessorCount() diff --git a/src/libmscorlib/FileStream.cpp b/src/libmscorlib/FileStream.cpp index fd16252..7fe2a71 100644 --- a/src/libmscorlib/FileStream.cpp +++ b/src/libmscorlib/FileStream.cpp @@ -57,7 +57,7 @@ namespace System long long FileStream::Length() { - sassert(handle != NULL, FrameworkResources::ObjectDisposed_FileClosed); + sassert(handle != NULL || _file != null, FrameworkResources::ObjectDisposed_FileClosed); sassert(canSeek, FrameworkResources::NotSupported_UnseekableStream); @@ -68,8 +68,20 @@ namespace System // return -1; //} + if (_file != null) + { + size_t curPos = ftell(_file); + fseek(_file, 0, SEEK_END); + length = ftell(_file); + fseek(_file, curPos, SEEK_SET); + } + else + { + + } + if ((_writePos > 0) && ((_pos + _writePos) > length)) - { + { length = _writePos + _pos; } return length; @@ -88,7 +100,7 @@ namespace System { sassert(canSeek, FrameworkResources::NotSupported_UnseekableStream); - if(newPosition < 0) + if (newPosition < 0) { //printf("ARGUMENT_OUT_OF_RANGE in function %s, at line %i in file %s, argument \"%s\": %s\n", __FUNCTION__, __LINE__, __FILE__, "newPosition", "Attempt to set the position to a negative value."); return; @@ -98,11 +110,17 @@ namespace System } FileStream::FileStream() + : handle(NULL), _file(NULL) + { + } + + FileStream::FileStream(FILE * const file) + : handle(NULL), _file(file) { - handle = NULL; } FileStream::FileStream(const String& path, const FileMode_t mode) + : handle(NULL), _file(NULL) { sassert(!String::IsNullOrEmpty(path), FrameworkResources::ArgumentNull_Path); @@ -166,11 +184,16 @@ namespace System // Invalidate the handle handle = null; } + if (_file != null) + { + fclose(_file); + _file = null; + } } void FileStream::Flush() { - sassert(handle != null, FrameworkResources::ObjectDisposed_FileClosed); + sassert(handle != null || _file != null, FrameworkResources::ObjectDisposed_FileClosed); if (_writePos > 0) { @@ -181,7 +204,7 @@ namespace System FlushRead(); } _readPos = 0; - _readLen = 0; + _readLen = 0; } void FileStream::FlushWrite(bool calledFromFinalizer) @@ -192,7 +215,7 @@ namespace System int FileStream::Read(byte array[], const int offset, const int count) { - sassert(handle != null, FrameworkResources::ObjectDisposed_FileClosed); + sassert(handle != null || _file != null, FrameworkResources::ObjectDisposed_FileClosed); sassert(array != null, String::Format("array; %s", FrameworkResources::ArgumentNull_Generic)); @@ -209,7 +232,15 @@ namespace System sassert(!(offset > (len - count)), "Reading would overrun buffer."); uint bytesRead; - //XReadFile(handle, &array[offset], count, &bytesRead); + + if (_file != null) + { + bytesRead = fread(&array[offset], 1, count, _file); + } + else + { + //XReadFile(handle, &array[offset], count, &bytesRead); + } return bytesRead; } @@ -234,7 +265,7 @@ namespace System IO_STATUS_BLOCK ioStatusBlock; NTSTATUS status; uint filesize; - + // Calculate the target pointer switch (origin) { @@ -244,13 +275,17 @@ namespace System case SeekOrigin::Current: // From the current position status = NtQueryInformationFile(handle, &ioStatusBlock, &positionInfo, sizeof(positionInfo), FilePositionInformation); if (!NT_SUCCESS(status)) + { return RtlNtStatusToDosError(status); + } targetPointer.QuadPart = positionInfo.CurrentByteOffset.QuadPart + offset; break; case SeekOrigin::End: // From the end of the file //status = XGetFileSize(handle, &filesize); if (!NT_SUCCESS(status)) + { return RtlNtStatusToDosError(status); + } targetPointer.QuadPart -= offset; break; } @@ -262,7 +297,9 @@ namespace System // Set the new position status = NtSetInformationFile(handle, &ioStatusBlock, &positionInfo, sizeof(positionInfo), FilePositionInformation); if (!NT_SUCCESS(status)) + { return RtlNtStatusToDosError(status); + } else { return targetPointer.QuadPart; @@ -275,28 +312,44 @@ namespace System sassert(CanWrite(), FrameworkResources::NotSupported_UnwritableStream); - sassert(handle != null, FrameworkResources::ObjectDisposed_FileClosed); + sassert(handle != null || _file != null, FrameworkResources::ObjectDisposed_FileClosed); sassert(value >= 0, String::Format("value; %s", FrameworkResources::ArgumentOutOfRange_NeedNonNegNum)); Flush(); if (getPosition() > value) + { setPosition(value); + } } void FileStream::Write(byte array[], const int offset, const int count) { - sassert(handle != null, FrameworkResources::ObjectDisposed_FileClosed); + sassert(handle != null || _file != null, FrameworkResources::ObjectDisposed_FileClosed); - //XWriteFile(handle, &array[offset], count, null); + if (_file != null) + { + fwrite(&array[offset], sizeof(byte), count, _file); + } + else + { + //XWriteFile(handle, &array[offset], count, null); + } } void FileStream::WriteByte(byte value) { - sassert(handle != null, FrameworkResources::ObjectDisposed_FileClosed); + sassert(handle != null || _file != null, FrameworkResources::ObjectDisposed_FileClosed); - //XWriteFile(handle, &value, 1, null); + if (_file != null) + { + fwrite(&value, 1, 1, _file); + } + else + { + //XWriteFile(handle, &value, 1, null); + } } } } diff --git a/src/libmscorlib/FrameworkResources.cpp b/src/libmscorlib/FrameworkResources.cpp index 5e9dc73..e264fe2 100644 --- a/src/libmscorlib/FrameworkResources.cpp +++ b/src/libmscorlib/FrameworkResources.cpp @@ -3,22 +3,23 @@ namespace System { - const char* FrameworkResources::Arg_ParamName_Name = "Parameter name: %s"; - const char* FrameworkResources::Argument_InvalidOffLen = "Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection"; + const char* FrameworkResources::Arg_ParamName_Name = "Parameter name: %s"; + const char* FrameworkResources::Argument_InvalidOffLen = "Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection"; const char* FrameworkResources::Argument_InvalidSeekOrigin = "Invalid SeekOrigin."; - const char* FrameworkResources::ArgumentNull_Buffer = "Buffer cannot be null."; + const char* FrameworkResources::ArgumentNull_Buffer = "Buffer cannot be null."; const char* FrameworkResources::ArgumentNull_FileName = "File name cannot be null."; const char* FrameworkResources::ArgumentNull_Generic = "Value cannot be null."; const char* FrameworkResources::ArgumentNull_Path = "Path cannot be null."; + const char* FrameworkResources::ArgumentOutOfRange_Index = "Index was out of range. Must be non-negative and less than the size of the collection."; const char* FrameworkResources::ArgumentOutOfRange_NeedNonNegNum = "Non-negative number required."; const char* FrameworkResources::ArgumentOutOfRange_NeedPosNum = "Positive number required."; const char* FrameworkResources::ArgumentOutOfRange_NegativeCapacity = "Capacity must be positive."; const char* FrameworkResources::ArgumentOutOfRange_SmallCapacity = "capacity was less than the current size."; - const char* FrameworkResources::ArgumentOutOfRange_StreamLength = "Stream length must be non-negative and less than 2^31 - 1 - origin."; - const char* FrameworkResources::IO_SeekBeforeBegin = "Attempting to seek before the start of the Stream."; + const char* FrameworkResources::ArgumentOutOfRange_StreamLength = "Stream length must be non-negative and less than 2^31 - 1 - origin."; + const char* FrameworkResources::IO_SeekBeforeBegin = "Attempting to seek before the start of the Stream."; const char* FrameworkResources::IO_StreamTooLong = "Stream was too long."; const char* FrameworkResources::ObjectDisposed_FileClosed = "Cannot access a closed file."; - const char* FrameworkResources::ObjectDisposed_StreamClosed = "Cannot access a closed Stream."; + const char* FrameworkResources::ObjectDisposed_StreamClosed = "Cannot access a closed Stream."; const char* FrameworkResources::NotSupported_MemStreamNotExpandable = "MemoryStream is not expandable."; const char* FrameworkResources::NotSupported_UnreadableStream = "Stream does not support reading."; const char* FrameworkResources::NotSupported_UnseekableStream = "Stream does not support seeking."; diff --git a/src/libmscorlib/libmscorlib.vcxproj b/src/libmscorlib/libmscorlib.vcxproj index 9690c97..c9bb256 100644 --- a/src/libmscorlib/libmscorlib.vcxproj +++ b/src/libmscorlib/libmscorlib.vcxproj @@ -126,6 +126,7 @@ + diff --git a/src/libmscorlib/libmscorlib.vcxproj.filters b/src/libmscorlib/libmscorlib.vcxproj.filters index c424ac9..08e5eaf 100644 --- a/src/libmscorlib/libmscorlib.vcxproj.filters +++ b/src/libmscorlib/libmscorlib.vcxproj.filters @@ -49,6 +49,9 @@ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav + + {8567ce7a-ac9d-41e0-94da-66c21844aa83} + @@ -398,6 +401,9 @@ Header Files + + Header Files\Collections\ObjectModel + diff --git a/src/libmscorlib/misc.cpp b/src/libmscorlib/misc.cpp index a44deef..0625458 100644 --- a/src/libmscorlib/misc.cpp +++ b/src/libmscorlib/misc.cpp @@ -1,10 +1,10 @@ -/******************************************************************************/ -/* */ -/* File: misc.cpp */ -/* Author: bkenwright@xbdev.net */ -/* Desc: Misc functions, making our usb/gamepad code lib independent */ -/* */ -/******************************************************************************/ +/***************************************************************************** + * * + * File: misc.cpp * + * Author: bkenwright@xbdev.net * + * Desc: Misc functions, making our usb/gamepad code lib independent * + * * + *****************************************************************************/ #include #include diff --git a/src/xnbbuild/src/Path.c b/src/xnbbuild/src/Path.c new file mode 100644 index 0000000..697bbb6 --- /dev/null +++ b/src/xnbbuild/src/Path.c @@ -0,0 +1,145 @@ +#if _MSC_VER +#define _CRT_SECURE_NO_WARNINGS +#endif + +#include +#include +#include + +#include "Path.h" + +const char * Path_Combine(char const * const path1, char const * const path2) +{ + const char * strPtr = NULL; + char * pathString = NULL; + size_t newLen = 0; + + strPtr = strrchr(path1, '\\'); + + if (((size_t)strPtr - (size_t)path1) != 0) + { + newLen = strlen(path1) + 1 + strlen(path2); + + pathString = (char *)malloc(newLen + 1); + + sprintf(pathString, "%s\\%s", path1, path2); + } + else + { + newLen = strlen(path1) + strlen(path2); + + pathString = (char *)malloc(newLen + 1); + + sprintf(pathString, "%s%s", path1, path2); + } + + pathString[newLen] = '\0'; + + return pathString; +} + +const char * Path_GetDirectory(char const * const path) +{ + const char * strPtr = NULL; + size_t pathLen = 0; + char * pathString; + + strPtr = strrchr(path, '\\'); + + pathLen = (size_t)strPtr - (size_t)path; + + pathString = (char *)malloc(pathLen + 1); + + strncpy(pathString, path, pathLen); + + pathString[pathLen] = '\0'; + + return pathString; +} + +const char * Path_GetExtension(char const * const path) +{ + const char * strPtr = NULL; + size_t pathLen = 0; + size_t strLen = 0; + char * pathString = NULL; + + strPtr = strrchr(path, '.'); + + if (strPtr == NULL) + { + // no extension, return an empty string. + return ""; + } + + strLen = strlen(path); + + pathLen = (size_t)strPtr - (size_t)path; + + strLen -= pathLen; + + pathString = (char *)malloc(strLen + 1); + + strncpy(pathString, strPtr + 1, strLen); + + pathString[strLen] = '\0'; + + return pathString; +} + +const char * Path_GetFileName(char const * const path) +{ + const char * strPtr = NULL; + size_t pathLen = 0; + size_t strLen = 0; + char * pathString = NULL; + + strPtr = strrchr(path, '\\'); + + strLen = strlen(path); + + pathLen = (size_t)strPtr - (size_t)path; + + strLen -= pathLen; + + pathString = (char *)malloc(strLen + 1); + + strncpy(pathString, strPtr + 1, strLen); + + pathString[strLen] = '\0'; + + return pathString; +} + +const char * Path_GetFileNameWithoutExtension(char const * const path) +{ + const char * strPtr = NULL; + size_t pathLen = 0; + char * pathString = NULL; + const char * fileName = NULL; + + fileName = Path_GetFileName(path); + + strPtr = strchr(fileName, '.'); + + pathLen = (size_t)strPtr - (size_t)fileName; + + pathString = (char *)malloc(pathLen + 1); + + strncpy(pathString, fileName, pathLen); + + free((void *)fileName); + + pathString[pathLen] = '\0'; + + return pathString; +} + +struct _path Path = +{ + Path_Combine, + Path_GetDirectory, + Path_GetExtension, + Path_GetFileName, + Path_GetFileNameWithoutExtension +}; diff --git a/src/xnbbuild/src/Path.h b/src/xnbbuild/src/Path.h new file mode 100644 index 0000000..f82d8a2 --- /dev/null +++ b/src/xnbbuild/src/Path.h @@ -0,0 +1,15 @@ +#ifndef _PATH_H +#define _PATH_H + +struct _path +{ + const char * (*Combine)(char const * const, char const * const); + const char * (*GetDirectory)(char const * const); + const char * (*GetExtension)(char const * const); + const char * (*GetFileName)(char const * const); + const char * (*GetFileNameWithoutExtension)(char const * const); +}; + +extern struct _path Path; + +#endif //_PATH_H diff --git a/src/xnbbuild/src/TryCatchFinally.h b/src/xnbbuild/src/TryCatchFinally.h new file mode 100644 index 0000000..8e77859 --- /dev/null +++ b/src/xnbbuild/src/TryCatchFinally.h @@ -0,0 +1,13 @@ +#ifndef _TRYCATCHFINALLY_H +#define _TRYCATCHFINALLY_H + +#include +#include + +#define TRY do{ jmp_buf ex_buf__; switch(setjmp(ex_buf__) ){ case 0: while(1){ +#define CATCH(x) break; case x: +#define FINALLY break; } default: +#define ETRY } }while(0) +#define THROW(x) longjmp(ex_buf__, x) + +#endif //_TRYCATCHFINALLY_H diff --git a/src/xnbbuild/src/main.c b/src/xnbbuild/src/main.c new file mode 100644 index 0000000..fd0b89a --- /dev/null +++ b/src/xnbbuild/src/main.c @@ -0,0 +1,62 @@ +#if _MSC_VER +#define _CRT_SECURE_NO_WARNINGS +#endif + +#include +#include +#include +#include +#include + +#include "Path.h" +#include "TryCatchFinally.h" + +/** + * Application entry point + * + * @param argc + * The amount of values passed in argv. + * + * @param argv + * An array of strings that contains the command-line arguments. + * + * @return + * Application error code + */ +int main(int argc, char** argv) +{ + FILE *fpIn = NULL; + FILE *fpOut = NULL; + const char * inFile = NULL; + const char * outDir = NULL; + int i; + + if (argc == 0) + { + printf(""); + } + + for (i = 0; i < argc; i++) + { + if (strncmp(argv[i], "-outdir", 7) == 0) + { + + } + + if (argc > 0) + { + inFile = Path.GetFileName(argv[argc - 1]); + } + } + + TRY + fpIn = fopen(inFile, "rb"); + fpOut = fopen(Path.Combine(outDir, inFile), "wb"); + + + FINALLY + break; + ETRY; + + return 0; +} diff --git a/src/xnbbuild/xnbbuild.vcxproj b/src/xnbbuild/xnbbuild.vcxproj new file mode 100644 index 0000000..66b75a7 --- /dev/null +++ b/src/xnbbuild/xnbbuild.vcxproj @@ -0,0 +1,79 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {E5F1599D-C9FE-4EFB-97B6-13B46D4A1E35} + xnbbuild + + + + Application + true + v110 + MultiByte + + + Application + false + v110 + true + MultiByte + + + + + + + + + + + + + + + Level3 + Disabled + true + true + true + + + true + + + + + Level3 + MaxSpeed + true + true + true + + + true + true + true + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/xnbbuild/xnbbuild.vcxproj.filters b/src/xnbbuild/xnbbuild.vcxproj.filters new file mode 100644 index 0000000..15c4086 --- /dev/null +++ b/src/xnbbuild/xnbbuild.vcxproj.filters @@ -0,0 +1,33 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + \ No newline at end of file