From da68d727e4e6eb8674c834709ea5a7f35bf7975a Mon Sep 17 00:00:00 2001 From: Halofreak1990 Date: Sun, 16 Jan 2011 00:47:37 +0000 Subject: [PATCH] Added a couple of helper classes and functions. Libraries compile, but a project based on them is flooded with undefined references. --- include/Audio.h | 32 +- include/Content.h | 16 + include/Content/ContentManager.h | 4 +- include/Game.h | 2 +- include/GameServiceContainer.h | 4 +- include/GamerServices.h | 20 + .../GamerServices/GamerServicesComponent.h | 2 +- include/Graphics.h | 2 - include/Graphics/BasicDirectionalLight.h | 8 +- include/Graphics/DepthStencilBuffer.h | 57 +-- include/Graphics/Enums.h | 20 +- include/Graphics/GraphicsAdapter.h | 14 +- include/Graphics/GraphicsDevice.h | 2 + include/Graphics/PresentationParameters.h | 24 +- include/Graphics/Sprite.h | 50 ++ include/Graphics/SpriteBatch.h | 51 ++- include/Graphics/SpriteFont.h | 55 +++ include/Graphics/StateBlock.h | 41 ++ include/Graphics/Texture2D.h | 4 +- include/GraphicsDeviceManager.h | 22 +- include/Interfaces.h | 11 +- include/Media.h | 20 + include/Net.h | 19 + include/Net/NetworkException.h | 30 +- include/Rectangle.h | 18 +- include/Storage.h | 6 +- .../StorageDeviceNotConnectedException.h | 2 +- include/System/Array.h | 6 + include/System/Collections/Generic/Comparer.h | 1 + .../System/Collections/Generic/Interfaces.h | 4 +- .../Generic/KeyNotFoundException.h | 2 +- include/System/Collections/Generic/List.h | 16 +- include/System/Exception.h | 38 +- include/System/Interfaces.h | 6 + .../InteropServices/ExternalException.h | 8 +- include/XFX.Game.h | 6 +- include/XFX.h | 19 +- src/libXFX.Game/Game.cpp | 27 +- src/libXFX.Game/GameComponentCollection.cpp | 24 + src/libXFX.Game/GameServiceContainer.cpp | 20 + src/libXFX.Game/GraphicsDeviceManager.cpp | 74 ++- src/libXFX.Game/libXFX.Game.vcproj | 20 +- src/libXFX.Game/makefile | 4 +- src/libXFX/DepthStencilBuffer.cpp | 28 +- src/libXFX/Effect.cpp | 36 ++ src/libXFX/GraphicsAdapter.cpp | 75 ++- src/libXFX/GraphicsDevice.cpp | 8 + src/libXFX/PresentationParameters.cpp | 18 +- src/libXFX/Rectangle.cpp | 2 +- src/libXFX/Sprite.cpp | 86 ++++ src/libXFX/SpriteBatch.cpp | 430 +++++++++--------- src/libXFX/SpriteFont.cpp | 162 +++++++ src/libXFX/StateBlock.cpp | 61 +++ .../StorageDeviceNotConnectedException.cpp | 3 +- src/libXFX/Texture2D.cpp | 16 + src/libXFX/libXFX.vcproj | 72 ++- src/libXFX/makefile | 2 +- src/libmscorlib/Array.cpp | 37 ++ src/libmscorlib/Comparer.cpp | 49 +- src/libmscorlib/Dictionary.cpp | 20 +- src/libmscorlib/Exception.cpp | 59 ++- src/libmscorlib/KeyNotFoundException.cpp | 2 +- src/libmscorlib/Object.cpp | 12 +- src/libmscorlib/Path.cpp | 26 +- src/libmscorlib/SystemException.cpp | 163 +++++-- src/libmscorlib/libmscorlib.vcproj | 2 +- src/libmscorlib/makefile | 2 +- 67 files changed, 1638 insertions(+), 544 deletions(-) create mode 100644 include/Content.h create mode 100644 include/GamerServices.h create mode 100644 include/Graphics/Sprite.h create mode 100644 include/Graphics/SpriteFont.h create mode 100644 include/Graphics/StateBlock.h create mode 100644 include/Media.h create mode 100644 include/Net.h create mode 100644 src/libXFX.Game/GameComponentCollection.cpp create mode 100644 src/libXFX.Game/GameServiceContainer.cpp create mode 100644 src/libXFX/Effect.cpp create mode 100644 src/libXFX/Sprite.cpp create mode 100644 src/libXFX/SpriteFont.cpp create mode 100644 src/libXFX/StateBlock.cpp diff --git a/include/Audio.h b/include/Audio.h index bb1d351..98f0df3 100644 --- a/include/Audio.h +++ b/include/Audio.h @@ -1,27 +1,15 @@ -#ifndef XFRAMEWORK_AUDIO_H -#define XFRAMEWORK_AUDIO_H +/******************************************************** + * Audio.h * + * * + * XFX::Audio namespace include file * + * Copyright © XFX Team. All Rights Reserved * + ********************************************************/ +#ifndef _XFX_AUDIO_ +#define _XFX_AUDIO_ -#ifdef XBOX -// -//Data Types -// -#include "AudioCategory.h" -#include "AudioEmitter.h" -#include "AudioEngine.h" -#include "AudioListener.h" -#include "Cue.h" -#include "RendererDetail.h" -#include "SoundBank.h" -#include "SoundState.h" -#include "WaveBank.h" // //Enums // -#include "AudioStopOptions.h" -// -//Interfaces -// +#include "Audio/Enums.h" -#endif - -#endif //XFRAMEWORK_AUDIO_H +#endif //_XFX_AUDIO_ diff --git a/include/Content.h b/include/Content.h new file mode 100644 index 0000000..78fc8c7 --- /dev/null +++ b/include/Content.h @@ -0,0 +1,16 @@ +/******************************************************** + * Content.h * + * * + * XFX::Content namespace include file * + * Copyright © XFX Team. All Rights Reserved * + ********************************************************/ +#ifndef _XFX_CONTENT_ +#define _XFX_CONTENT_ + +// +//Classes +// +#include "Content/ContentManager.h" +#include "Content/ContentReader.h" + +#endif //_XFX_CONTENT_ diff --git a/include/Content/ContentManager.h b/include/Content/ContentManager.h index 1dbe9ee..4e1dd81 100644 --- a/include/Content/ContentManager.h +++ b/include/Content/ContentManager.h @@ -29,11 +29,11 @@ namespace XFX /// It also manages the lifespan of the loaded objects, disposing the content /// manager will also dispose any assets which are themselves System.IDisposable. /// - class ContentManager : public IDisposable, public Object + class ContentManager : public IDisposable, virtual Object { private: List disposableAssets; - //Dictionary loadedAssets; + //Dictionary loadedAssets; bool disposed; IServiceProvider* _provider; diff --git a/include/Game.h b/include/Game.h index aad6943..af8c3e5 100644 --- a/include/Game.h +++ b/include/Game.h @@ -88,7 +88,7 @@ namespace XFX void Dispose(); void Exit(); void ResetElapsedTime(); - void Run(); + virtual void Run(); void SuppressDraw(); void Tick(); }; diff --git a/include/GameServiceContainer.h b/include/GameServiceContainer.h index 062a646..ef66053 100644 --- a/include/GameServiceContainer.h +++ b/include/GameServiceContainer.h @@ -10,6 +10,8 @@ #include #include +using namespace System; + namespace XFX { /// @@ -25,4 +27,4 @@ namespace XFX }; } -#endif //_XFX_GAMESERVICECONTAINER_H +#endif //_XFX_GAMESERVICECONTAINER_ diff --git a/include/GamerServices.h b/include/GamerServices.h new file mode 100644 index 0000000..0a53852 --- /dev/null +++ b/include/GamerServices.h @@ -0,0 +1,20 @@ +/******************************************************** + * GamerServices.h * + * * + * XFX::GamerServices namespace include file * + * Copyright © XFX Team. All Rights Reserved * + ********************************************************/ +#ifndef _XFX_GAMERSERVICES_ +#define _XFX_GAMERSERVICES_ + +// +//Classes +// +#include "GamerServices/Guide.h" + +// +//Enums +// +#include "GamerServices/Enums.h" + +#endif //_XFX_GAMERSERVICES_ diff --git a/include/GamerServices/GamerServicesComponent.h b/include/GamerServices/GamerServicesComponent.h index 59a30b2..a9503d2 100644 --- a/include/GamerServices/GamerServicesComponent.h +++ b/include/GamerServices/GamerServicesComponent.h @@ -16,7 +16,7 @@ namespace XFX /// /// Creates a new GamerServicesComponent. /// - class GamerServicesComponent : GameComponent + class GamerServicesComponent : public GameComponent { public: GamerServicesComponent(Game game); diff --git a/include/Graphics.h b/include/Graphics.h index c5e7fc6..688b23b 100644 --- a/include/Graphics.h +++ b/include/Graphics.h @@ -11,12 +11,10 @@ //Data Types // #include "Graphics/BasicDirectionalLight.h" -#include "Graphics/BasicEffect.h" #include "Graphics/Color.h" #include "Graphics/DepthStencilBuffer.h" #include "Graphics/DisplayMode.h" #include "Graphics/DisplayModeCollection.h" -#include "Graphics/Effect.h" #include "Graphics/Exceptions.h" #include "Graphics/GraphicsAdapter.h" #include "Graphics/GraphicsDevice.h" diff --git a/include/Graphics/BasicDirectionalLight.h b/include/Graphics/BasicDirectionalLight.h index fbeac79..68bc9d7 100644 --- a/include/Graphics/BasicDirectionalLight.h +++ b/include/Graphics/BasicDirectionalLight.h @@ -4,8 +4,8 @@ * BasicDirectionalLight definition file * * Copyright © XFX Team. All Rights Reserved * ********************************************************/ -#ifndef _BASICDIRECTIONALLIGHT_H_ -#define _BASICDIRECTIONALLICHT_H_ +#ifndef _XFX_GRAPHICS_BASICDIRECTIONALLIGHT_ +#define _XFX_GRAPHICS_BASICDIRECTIONALLICHT_ #include @@ -21,10 +21,10 @@ namespace XFX public: Vector3 DiffuseColor; Vector3 Direction; - int Enabled; + bool Enabled; Vector3 SpecularColor; }; } } -#endif //_BASICDIRECTIONALLIGHT_H_ +#endif //_XFX_GRAPHICS_BASICDIRECTIONALLIGHT_ diff --git a/include/Graphics/DepthStencilBuffer.h b/include/Graphics/DepthStencilBuffer.h index 11d095a..9630eaa 100644 --- a/include/Graphics/DepthStencilBuffer.h +++ b/include/Graphics/DepthStencilBuffer.h @@ -15,35 +15,36 @@ namespace XFX /// /// Queries and prepares depth stencil buffers. /// - class DepthStencilBuffer : IDisposable + class DepthStencilBuffer : public IDisposable { - private: - GraphicsDevice *_graphicsDevice; - int _width; - int _height; - DepthFormat_t _format; - int isDisposed; - int _multiSampleQuality; - MultiSampleType_t _multiSampleType; - - protected: - virtual void Dispose(int __p1); - - public: - DepthFormat_t Format(); - GraphicsDevice GraphicsDevice_(); - int IsDisposed(); - int MultiSampleQuality(); - MultiSampleType_t MultiSampleType_(); - int Height(); - int Width(); - - DepthStencilBuffer(GraphicsDevice &graphicsDevice, int width, int height, DepthFormat_t format); - DepthStencilBuffer(GraphicsDevice &graphicsDevice, int width, int height, DepthFormat_t format, MultiSampleType_t multiSampleType, int multiSampleQuality); - DepthStencilBuffer(); - virtual ~DepthStencilBuffer(); - - void Dispose(); + private: + GraphicsDevice *_graphicsDevice; + int _width; + int _height; + DepthFormat_t _format; + bool isDisposed; + int _multiSampleQuality; + MultiSampleType_t _multiSampleType; + + protected: + virtual void Dispose(bool __p1); + + public: + DepthFormat_t Format(); + GraphicsDevice *GraphicsDevice_(); + bool IsDisposed(); + int MultiSampleQuality(); + MultiSampleType_t MultiSampleType_(); + int Height(); + int Width(); + + DepthStencilBuffer(GraphicsDevice *graphicsDevice, int width, int height, DepthFormat_t format); + DepthStencilBuffer(GraphicsDevice *graphicsDevice, int width, int height, DepthFormat_t format, MultiSampleType_t multiSampleType, int multiSampleQuality); + DepthStencilBuffer(); + DepthStencilBuffer(const DepthStencilBuffer &obj); + virtual ~DepthStencilBuffer(); + + void Dispose(); }; } } diff --git a/include/Graphics/Enums.h b/include/Graphics/Enums.h index 9107f05..7457c86 100644 --- a/include/Graphics/Enums.h +++ b/include/Graphics/Enums.h @@ -457,10 +457,10 @@ namespace XFX { enum type { - Boolean = 0, - Float = 2, - Int4 = 1, - Sampler = 3 + Boolean = 0, //Boolean value. + Float = 2, //4D floating-point number. + Int4 = 1, //4D integer number. + Sampler = 3 //The register contains 4D sampler data. }; }; /// @@ -470,9 +470,9 @@ namespace XFX { enum type { - Additive = 2, - AlphaBlend = 1, - None = 0 + Additive = 2, //Enable Additive blending. + AlphaBlend = 1, //Enable Alpha blending. + None = 0 //No blending specified. }; }; /// @@ -482,9 +482,9 @@ namespace XFX { enum type { - FlipHorizontally = 1, - FlipVertically = 256, - None = 0 + FlipHorizontally = 1, //Rotate 180 degrees about the Y axis before rendering. + FlipVertically = 0x100, //Rotate 180 degrees about the X axis before rendering. + None = 0 //No rotations specified. }; }; /// diff --git a/include/Graphics/GraphicsAdapter.h b/include/Graphics/GraphicsAdapter.h index f3b73ad..1cf02d3 100644 --- a/include/Graphics/GraphicsAdapter.h +++ b/include/Graphics/GraphicsAdapter.h @@ -26,7 +26,7 @@ namespace XFX class GraphicsAdapter : public IDisposable { protected: - void Dispose(int __p1); + void Dispose(bool __p1); public: DisplayMode CurrentDisplayMode(); @@ -47,16 +47,16 @@ namespace XFX bool CheckDeviceFormat(DeviceType_t deviceType, SurfaceFormat_t adapterFormat, TextureUsage_t usage, QueryUsages_t queryUsages, ResourceType_t resourceType, SurfaceFormat_t checkFormat); bool CheckDeviceFormat(DeviceType_t deviceType, SurfaceFormat_t adapterFormat, TextureUsage_t usage, QueryUsages_t queryUsages, ResourceType_t resourceType, DepthFormat_t checkFormat); bool CheckDeviceFormatConversion(DeviceType_t deviceType, SurfaceFormat_t sourceFormat, SurfaceFormat_t targetFormat); - bool CheckDeviceMultiSampleType(DeviceType_t deviceType, SurfaceFormat_t surfaceFormat, int isFullScreen, MultiSampleType_t sampleType); - bool CheckDeviceMultiSampleType(DeviceType_t deviceType, SurfaceFormat_t surfaceFormat, int isFullScreen, MultiSampleType_t sampleType, out int qualityLevels); - bool CheckDeviceType(DeviceType_t deviceType, SurfaceFormat_t displayFormat, SurfaceFormat_t backBufferFormat, int isFullScreen); + bool CheckDeviceMultiSampleType(DeviceType_t deviceType, SurfaceFormat_t surfaceFormat, bool isFullScreen, MultiSampleType_t sampleType); + bool CheckDeviceMultiSampleType(DeviceType_t deviceType, SurfaceFormat_t surfaceFormat, bool isFullScreen, MultiSampleType_t sampleType, out int qualityLevels); + bool CheckDeviceType(DeviceType_t deviceType, SurfaceFormat_t displayFormat, SurfaceFormat_t backBufferFormat, bool isFullScreen); void Dispose(); - bool Equals(GraphicsAdapter &other); + bool Equals(const GraphicsAdapter obj); int GetHashCode(); bool IsDeviceTypeAvailable(DeviceType_t deviceType); - bool operator!=(GraphicsAdapter other); - bool operator==(GraphicsAdapter other); + bool operator!=(const GraphicsAdapter other); + bool operator==(const GraphicsAdapter other); }; } } diff --git a/include/Graphics/GraphicsDevice.h b/include/Graphics/GraphicsDevice.h index 673d13e..69a54a3 100644 --- a/include/Graphics/GraphicsDevice.h +++ b/include/Graphics/GraphicsDevice.h @@ -86,6 +86,8 @@ namespace XFX float* GetPixelShaderSingleConstant(int startRegister, int constantCount); Vector2* GetPixelShaderVector2ArrayConstant(int startRegister, int constantCount); Vector2 GetPixelShaderVector2Constant(int startRegister); + void SetVertexShaderConstant(int startRegister, Matrix constantData); + void SetVertexShaderConstant(int startRegister, Vector4 constantData); }; } } diff --git a/include/Graphics/PresentationParameters.h b/include/Graphics/PresentationParameters.h index 14acdd4..fb3d66a 100644 --- a/include/Graphics/PresentationParameters.h +++ b/include/Graphics/PresentationParameters.h @@ -4,10 +4,10 @@ * XFX PresentationParameters definition file * * Copyright © XFX Team. All Rights Reserved * ********************************************************/ -#ifndef _PRESENTATIONPARAMETERS_ -#define _PRESENTATIONPARAMETERS_ +#ifndef _XFX_GRAPHICS_PRESENTATIONPARAMETERS_ +#define _XFX_GRAPHICS_PRESENTATIONPARAMETERS_ -#include "../System.h" +#include #include "Enums.h" using namespace System; @@ -19,13 +19,13 @@ namespace XFX /// /// Contains presentation parameters. /// - class PresentationParameters : IDisposable + class PresentationParameters : public IDisposable { private: - int disposed; + bool disposed; protected: - virtual void Dispose(int disposing); + virtual void Dispose(bool disposing); public: DepthFormat_t AutoDepthStencilFormat; @@ -39,9 +39,9 @@ namespace XFX IntPtr DeviceWindowHandle; #endif - int EnableAutoDepthStencil; + bool EnableAutoDepthStencil; int FullScreenRefreshRateInHz; - int IsFullScreen; + bool IsFullScreen; int MultiSampleQuality; MultiSampleType_t MultiSampleType_; PresentInterval_t PresentationInterval; @@ -54,12 +54,12 @@ namespace XFX void Clear(); PresentationParameters Clone(); void Dispose(); - int Equals(PresentationParameters &other); + bool Equals(const PresentationParameters other); - int operator!=(PresentationParameters &other); - int operator==(PresentationParameters &other); + bool operator!=(const PresentationParameters other); + bool operator==(const PresentationParameters other); }; } } -#endif //_PRESENTATIONPARAMETERS_ +#endif //_XFX_GRAPHICS_PRESENTATIONPARAMETERS_ diff --git a/include/Graphics/Sprite.h b/include/Graphics/Sprite.h new file mode 100644 index 0000000..7186e6f --- /dev/null +++ b/include/Graphics/Sprite.h @@ -0,0 +1,50 @@ +/******************************************************** + * Sprite.h * + * * + * XFX Sprite definition file * + * Copyright © XFX Team. All Rights Reserved * + ********************************************************/ +#ifndef _XFX_GRAPHICS_SPRITE_ +#define _XFX_GRAPHICS_SPRITE_ + +#include "Color.h" +#include "Enums.h" +#include "Texture2D.h" +#include +#include + +namespace XFX +{ + namespace Graphics + { + /// + /// + /// + class Sprite + { + private: + Texture2D texture; + Rectangle destinationRectangle; + Rectangle sourceRectangle; + Color color; + float rotation; + Vector2 origin; + SpriteEffects_t effects; + float layerDepth; + + public: + Texture2D Texture(); + Rectangle DestinationRectangle(); + Rectangle SourceRectangle(); + Color Color_(); + float Rotation(); + Vector2 Origin(); + SpriteEffects_t Effects(); + float LayerDepth(); + + Sprite(Texture2D texture, Rectangle sourceRectangle, Rectangle destinationRectangle, Color color, float rotation, Vector2 origin, SpriteEffects_t effects, float layerDepth); + }; + } +} + +#endif //_XFX_GRAPHICS_SPRITE_ diff --git a/include/Graphics/SpriteBatch.h b/include/Graphics/SpriteBatch.h index 06c87ad..8c0e710 100644 --- a/include/Graphics/SpriteBatch.h +++ b/include/Graphics/SpriteBatch.h @@ -4,19 +4,25 @@ * XFX SpriteBatch definition file * * Copyright © XFX Team. All Rights Reserved * ********************************************************/ -#ifndef _SPRITEBATCH_ -#define _SPRITEBATCH_ +#ifndef _XFX_GRAPHICS_SPRITEBATCH_ +#define _XFX_GRAPHICS_SPRITEBATCH_ -#include #include "Enums.h" +#include "GraphicsDevice.h" +#include +#include "Sprite.h" +#include "StateBlock.h" +#include +#include +#include +#include using namespace System; +using namespace System::Collections::Generic; namespace XFX { - struct Matrix; struct Rectangle; - struct Vector2; namespace Graphics { @@ -27,15 +33,22 @@ namespace XFX /// /// Enables a group of sprites to be drawn using the same settings. /// - class SpriteBatch : public IDisposable + class SpriteBatch : public IDisposable, virtual Object { private: - GraphicsDevice* device; - bool disposed; + Texture2D* currentTexture; + GraphicsDevice device; + bool isDisposed; + bool inBeginEndPair; + SaveStateMode_t saveStateMode; + StateBlock saveState; + SpriteSortMode_t spriteSortMode; static SpriteBlendMode_t spriteBlendMode; - + int spriteQueueCount; + List SpriteList; + void applyGraphicsDeviceSettings(); - void flush(); + void Flush(); void restoreRenderState(); protected: @@ -47,8 +60,9 @@ namespace XFX EventHandler Disposing; - ~SpriteBatch(); + virtual ~SpriteBatch(); SpriteBatch(GraphicsDevice graphicsDevice); + SpriteBatch(); void Begin(); void Begin(SpriteBlendMode_t blendMode); @@ -56,18 +70,19 @@ namespace XFX void Begin(SpriteBlendMode_t blendMode, SpriteSortMode_t sortMode, SaveStateMode_t stateMode, Matrix transformMatrix); void Dispose(); void Draw(Texture2D texture, Rectangle destinationRectangle, Color color); - void Draw(Texture2D texture, Rectangle destinationRectangle, Rectangle* sourceRectangle, Color color); + void Draw(Texture2D texture, Rectangle destinationRectangle, Rectangle sourceRectangle, Color color); void Draw(Texture2D texture, Vector2 position, Color color); - void Draw(Texture2D texture, Vector2 position, Rectangle* sourceRectangle, Color color); - void Draw(Texture2D texture, Vector2 position, Rectangle* sourceRectangle, Color color, float rotation, Vector2 origin, float scale, SpriteEffects_t effects, float layerDepth); - void Draw(Texture2D texture, Vector2 position, Rectangle* sourceRectangle, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects_t effects, float layerDepth); - void Draw(Texture2D texture, Rectangle destinationRectangle, Rectangle* sourceRectangle, Color color, float rotation, Vector2 origin, SpriteEffects_t &effects, float layerDepth); + void Draw(Texture2D texture, Vector2 position, Rectangle sourceRectangle, Color color); + void Draw(Texture2D texture, Vector2 position, Rectangle sourceRectangle, Color color, float rotation, Vector2 origin, float scale, SpriteEffects_t effects, float layerDepth); + void Draw(Texture2D texture, Vector2 position, Rectangle sourceRectangle, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects_t effects, float layerDepth); + void Draw(Texture2D texture, Rectangle destinationRectangle, Rectangle sourceRectangle, Color color, float rotation, Vector2 origin, SpriteEffects_t effects, float layerDepth); void DrawString(SpriteFont spriteFont, char* text, Vector2 position, Color color); + void DrawString(SpriteFont spriteFont, char* text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects_t effects, float layerDepth); void DrawString(SpriteFont spriteFont, char* text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects_t effects, float layerDepth); - + void End(); }; } } -#endif //_SPRITEBATCH_ +#endif //_XFX_GRAPHICS_SPRITEBATCH_ diff --git a/include/Graphics/SpriteFont.h b/include/Graphics/SpriteFont.h new file mode 100644 index 0000000..dadfe10 --- /dev/null +++ b/include/Graphics/SpriteFont.h @@ -0,0 +1,55 @@ +/******************************************************** + * SpriteFont.h * + * * + * XFX SpriteFont definition file * + * Copyright © XFX Team. All Rights Reserved * + ********************************************************/ +#ifndef _XFX_GRAPHICS_SPRITEFONT_ +#define _XFX_GRAPHICS_SPRITEFONT_ + +#include +#include "Texture2D.h" +#include +#include +#include + +using namespace System; +using namespace System::Collections::Generic; + +namespace XFX +{ + struct Vector2; + + namespace Graphics + { + class SpriteBatch; + + /// + /// Represents a font texture. + /// + class SpriteFont + { + private: + List characterMap; + List croppingData; + List glyphData; + List kerning; + int lineSpacing; + float spacing; + Texture2D textureValue; + + int GetIndexForCharacter(char character); + + public: + int LineSpacing(); + float Spacing; + + SpriteFont(Texture2D texture, List glyphs, List cropping, List charMap, int lineSpacing, float spacing, List kerning); + + void Draw(char* text, SpriteBatch spriteBatch, Vector2 textblockPosition, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects_t spriteEffects, float depth); + Vector2 MeasureString(char* text); + }; + } +} + +#endif //_XFX_GRAPHICS_SPRITEFONT_ diff --git a/include/Graphics/StateBlock.h b/include/Graphics/StateBlock.h new file mode 100644 index 0000000..3028b78 --- /dev/null +++ b/include/Graphics/StateBlock.h @@ -0,0 +1,41 @@ +/******************************************************** + * StateBlock.h * + * * + * XFX StateBlock definition file * + * Copyright © XFX Team. All Rights Reserved * + ********************************************************/ +#ifndef _XFX_GRAPHICS_STATEBLOCK_ +#define _XFX_GRAPHICS_STATEBLOCK_ + +#include +#include "GraphicsDevice.h" + +namespace XFX +{ + namespace Graphics + { + class StateBlock : public IDisposable + { + protected: + void Dispose(bool disposing); + + public: + EventHandler Disposing; + + StateBlock(); + StateBlock(GraphicsDevice graphiceDevice); + StateBlock(const StateBlock &obj); + + void Apply(); + void Capture(); + void Dispose(); + bool Equals(StateBlock other); + int GetHashCode(); + + bool operator!=(const StateBlock other); + bool operator==(const StateBlock other); + }; + } +} + +#endif //_XFX_GRAPHICS_STATEBLOCK_ diff --git a/include/Graphics/Texture2D.h b/include/Graphics/Texture2D.h index 7edb274..b8bcfea 100644 --- a/include/Graphics/Texture2D.h +++ b/include/Graphics/Texture2D.h @@ -19,7 +19,7 @@ namespace XFX namespace Graphics { - class Texture2D : public Texture + class Texture2D : public Texture, virtual Object { private: GraphicsDevice device; @@ -44,8 +44,10 @@ namespace XFX TextureUsage_t TextureUsage_(); int Width(); + Texture2D(); Texture2D(GraphicsDevice graphicsDevice, int width, int height); Texture2D(GraphicsDevice graphicsDevice, int width, int height, int numberLevels, TextureUsage_t usage, SurfaceFormat_t format); + Texture2D(const Texture2D &obj); static Texture2D FromFile(GraphicsDevice graphicsDevice, Stream textureStream); static Texture2D FromFile(GraphicsDevice graphicsDevice, Stream textureStream, TextureCreationParameters creationParameters); diff --git a/include/GraphicsDeviceManager.h b/include/GraphicsDeviceManager.h index 2ea8fc3..04ab65e 100644 --- a/include/GraphicsDeviceManager.h +++ b/include/GraphicsDeviceManager.h @@ -9,10 +9,10 @@ #include "Game.h" #include "Graphics/GraphicsDevice.h" +#include "Graphics/Enums.h" +#include "Graphics/IGraphicsDeviceService.h" #include "GraphicsDeviceInformation.h" #include "Interfaces.h" -#include "Graphics/IGraphicsDeviceService.h" -#include "Graphics/Enums.h" #include "System/Interfaces.h" using namespace System; @@ -20,16 +20,25 @@ using namespace XFX::Graphics; namespace XFX { + /// + /// Handles the configuration and management of the graphics device. + /// class GraphicsDeviceManager : public IGraphicsDeviceService, public IDisposable, public IGraphicsDeviceManager, virtual Object { private: bool isFullScreen; Game _game; + SurfaceFormat_t backBufferFormat; + int backBufferHeight; + int backBufferWidth; GraphicsDevice graphicsDevice; + ShaderProfile_t minimumVertexShaderProfile; + + void CreateDevice(); protected: virtual bool CanResetDevice(GraphicsDeviceInformation newDeviceInfo); - virtual void Dispose(int disposing); + virtual void Dispose(bool disposing); virtual GraphicsDeviceInformation FindBestDevice(bool anySuitableDevice); virtual void OnDeviceCreated(Object* sender, EventArgs args); virtual void OnDeviceDisposing(Object* sender, EventArgs args); @@ -42,12 +51,12 @@ namespace XFX bool IsFullScreen(); float MinimumPixelShaderProfile; float MinimumVertexShaderProfile; - int PreferMultiSampling; + bool PreferMultiSampling; SurfaceFormat_t PreferredBackBufferFormat; int PreferredBackBufferWidth; int PreferredBackBufferHeight; DepthFormat_t PreferredDepthStencilFormat; - int SynchronizeWithVerticalRetrace; + bool SynchronizeWithVerticalRetrace; static const int DefaultBackBufferWidth; static const int DefaultBackBufferHeight; @@ -55,6 +64,7 @@ namespace XFX static SurfaceFormat_t ValidBackBufferFormats[]; static const DeviceType_t ValidDeviceTypes[]; + GraphicsDeviceManager(); GraphicsDeviceManager(Game game); EventHandler DeviceCreated; @@ -64,7 +74,9 @@ namespace XFX EventHandler Disposed; void ApplyChanges(); + bool BeginDraw(); void Dispose(); + void EndDraw(); void ToggleFullscreen(); }; } diff --git a/include/Interfaces.h b/include/Interfaces.h index b0359b7..b4aa499 100644 --- a/include/Interfaces.h +++ b/include/Interfaces.h @@ -8,6 +8,9 @@ #define _XFX_INTERFACES_ #include +#include + +using namespace System; namespace XFX { @@ -23,7 +26,7 @@ namespace XFX virtual bool Visible()=0; virtual void Draw(GameTime gameTime)=0; - virtual ~IDrawable(); + virtual ~IDrawable() {} EventHandler DrawOrderChanged; EventHandler VisibleChanged; @@ -36,7 +39,7 @@ namespace XFX { public: virtual void Initialize()=0; - virtual ~IGameComponent(); + virtual ~IGameComponent() {} }; /// @@ -49,7 +52,7 @@ namespace XFX virtual void CreateDevice()=0; virtual void EndDraw()=0; - virtual ~IGraphicsDeviceManager(); + virtual ~IGraphicsDeviceManager() {} }; /// @@ -63,7 +66,7 @@ namespace XFX virtual int UpdateOrder()=0; virtual void UpdateOrder(int value)=0; - virtual ~IUpdateable(); + virtual ~IUpdateable() {} virtual void Update(GameTime gameTime)=0; EventHandler EnabledChanged; diff --git a/include/Media.h b/include/Media.h new file mode 100644 index 0000000..b41511c --- /dev/null +++ b/include/Media.h @@ -0,0 +1,20 @@ +/******************************************************** + * Media.h * + * * + * XFX::Media namespace include file * + * Copyright © XFX Team. All Rights Reserved * + ********************************************************/ +#ifndef _XFX_MEDIA_ +#define _XFX_MEDIA_ + +// +//Classes +// +#include "Media/Video.h" +#include "Media/VideoPlayer.h" +// +//Enums +// +#include "Media/Enums.h" + +#endif //_XFX_MEDIA_ diff --git a/include/Net.h b/include/Net.h new file mode 100644 index 0000000..2698bd4 --- /dev/null +++ b/include/Net.h @@ -0,0 +1,19 @@ +/******************************************************** + * Net.h * + * * + * XFX::Net namespace include file * + * Copyright © XFX Team. All Rights Reserved * + ********************************************************/ +#ifndef _XFX_NET_ +#define _XFX_NET_ + +// +//Classes +// +#include "Net/NetworkException.h" +// +//Enums +// +#include "Net/Enums.h" + +#endif //_XFX_NET_ diff --git a/include/Net/NetworkException.h b/include/Net/NetworkException.h index 7a631b9..9276344 100644 --- a/include/Net/NetworkException.h +++ b/include/Net/NetworkException.h @@ -1,9 +1,17 @@ +/******************************************************** + * NetworkException.h * + * * + * XFX NetworkException definition file * + * Copyright © XFX Team. All Rights Reserved * + ********************************************************/ #ifndef _XFX_NET_NETWORKEXCEPTION_ #define _XFX_NET_NETWORKEXCEPTION_ #include #include "Enums.h" +using namespace System; + namespace XFX { namespace Net @@ -11,27 +19,27 @@ namespace XFX /// /// Thrown if there is a network communication failure. /// - class NetworkException : Exception + class NetworkException : public Exception { public: - public NetworkException(); - public NetworkException(char* message); - public NetworkException(char* message, Exception innerException); + NetworkException(); + NetworkException(char* message); + NetworkException(char* message, Exception innerException); }; /// /// Thrown if an error was encountered while joining a session. /// - class NetworkSessionJoinException : NetworkException + class NetworkSessionJoinException : public NetworkException { public: - public NetworkSessionJoinException(); - public NetworkSessionJoinException(char* message); - public NetworkSessionJoinException(char* message, NetworkSessionJoinError joinError); - public NetworkSessionJoinException(char* message, Exception innerException); + NetworkSessionJoinException(); + NetworkSessionJoinException(char* message); + NetworkSessionJoinException(char* message, NetworkSessionJoinError joinError); + NetworkSessionJoinException(char* message, Exception innerException); - public NetworkSessionJoinError JoinError(); //! get - public void JoinError(NetworkSessionJoinError joinError); //! set + NetworkSessionJoinError JoinError(); //! get + void JoinError(NetworkSessionJoinError joinError); //! set }; } } diff --git a/include/Rectangle.h b/include/Rectangle.h index 52c62c5..0937029 100644 --- a/include/Rectangle.h +++ b/include/Rectangle.h @@ -16,13 +16,15 @@ namespace XFX struct Rectangle { public: - int Bottom(); - int Left(); - int Right(); - int Top(); - int X, Y; - static const Rectangle Empty; - int Width, Height; + int Bottom(); //Returns the y-coordinate of the bottom of the rectangle. + static const Rectangle Empty; //Returns a Rectangle with all of its values set to zero. + int Left(); //Returns the x-coordinate of the left side of the rectangle. + int Right(); //Returns the x-coordinate of the right side of the rectangle. + int Top(); //Returns the y-coordinate of the top of the rectangle. + int Height; //Specifies the height of the rectangle. + int Width; //Specifies the width of the rectangle. + int X; //Specifies the x-coordinate of the rectangle. + int Y; //Specifies the y-coordinate of the rectangle. Rectangle(int x,int y,int width,int height); Rectangle(const Rectangle &obj); @@ -43,7 +45,7 @@ namespace XFX int operator==(const Rectangle other); int operator!=(const Rectangle other); - Rectangle &operator=(const Rectangle other); + Rectangle operator=(const Rectangle other); }; } diff --git a/include/Storage.h b/include/Storage.h index fc6e88b..3f47347 100644 --- a/include/Storage.h +++ b/include/Storage.h @@ -7,8 +7,8 @@ #ifndef _XFX_STORAGE_ #define _XFX_STORAGE_ -#include "StorageContainer.h" -#include "StorageDevice.h" -#include "StorageDeviceNotConnectedException.h" +#include "Storage/StorageContainer.h" +#include "Storage/StorageDevice.h" +#include "Storage/StorageDeviceNotConnectedException.h" #endif //_XFX_STORAGE_ diff --git a/include/Storage/StorageDeviceNotConnectedException.h b/include/Storage/StorageDeviceNotConnectedException.h index 4741d4e..4990ffa 100644 --- a/include/Storage/StorageDeviceNotConnectedException.h +++ b/include/Storage/StorageDeviceNotConnectedException.h @@ -23,7 +23,7 @@ namespace XFX public: StorageDeviceNotConnectedException(); StorageDeviceNotConnectedException(char* message); - StorageDeviceNotConnectedException(char* message, Exception innerException); + StorageDeviceNotConnectedException(char* message, Exception* innerException); }; } } diff --git a/include/System/Array.h b/include/System/Array.h index 06cacb5..88dce70 100644 --- a/include/System/Array.h +++ b/include/System/Array.h @@ -8,11 +8,17 @@ #ifndef _SYSTEM_ARRAY_ #define _SYSTEM_ARRAY_ +#include + +using namespace System::Collections::Generic; + namespace System { class Array { public: + template + static int BinarySearch(T array[], int index, int length, T value, IComparer* comparer); template static void Clear(T array[], int index, int length); template diff --git a/include/System/Collections/Generic/Comparer.h b/include/System/Collections/Generic/Comparer.h index 68b6450..8787076 100644 --- a/include/System/Collections/Generic/Comparer.h +++ b/include/System/Collections/Generic/Comparer.h @@ -13,6 +13,7 @@ namespace System /// /// Provides a base class for implementations of the System.Collections.Generic.IComparer generic interface. /// + template class Comparer : public IComparer { private: diff --git a/include/System/Collections/Generic/Interfaces.h b/include/System/Collections/Generic/Interfaces.h index 665c2ea..73eb195 100644 --- a/include/System/Collections/Generic/Interfaces.h +++ b/include/System/Collections/Generic/Interfaces.h @@ -29,7 +29,7 @@ namespace System virtual bool Remove(T item)=0; virtual int Count()=0; - virtual bool IsReadOnly(); + virtual bool IsReadOnly() { return true; } }; /// @@ -102,7 +102,7 @@ namespace System virtual T operator[](int index)=0; - virtual ~IList(); + virtual ~IList() {} }; } } diff --git a/include/System/Collections/Generic/KeyNotFoundException.h b/include/System/Collections/Generic/KeyNotFoundException.h index 77737b7..46721c1 100644 --- a/include/System/Collections/Generic/KeyNotFoundException.h +++ b/include/System/Collections/Generic/KeyNotFoundException.h @@ -24,7 +24,7 @@ namespace System public: KeyNotFoundException(); KeyNotFoundException(char* message); - KeyNotFoundException(char* message, Exception innerException); + KeyNotFoundException(char* message, Exception* innerException); }; } } diff --git a/include/System/Collections/Generic/List.h b/include/System/Collections/Generic/List.h index 9a8edeb..1582356 100644 --- a/include/System/Collections/Generic/List.h +++ b/include/System/Collections/Generic/List.h @@ -17,7 +17,8 @@ namespace System namespace Generic { /// - /// Represents a strongly typed list of objects that can be accessed by index. Provides methods to search, sort, and manipulate lists. + /// Represents a strongly typed list of objects that can be accessed by index. Provides methods to search, sort, and + /// manipulate lists. /// template class List : public IList @@ -42,24 +43,23 @@ namespace System void Add(T item); //Adds an element to the end of the list int BinarySearch(T item); - int BinarySearch(T item, IComparer comparer); - int BinarySearch(int index, int count, T item, IComparer comparer); + int BinarySearch(T item, IComparer* comparer); + int BinarySearch(int index, int count, T item, IComparer* comparer); void Clear(); //Removes all elements from the list bool Contains(T item); void CopyTo(T array[], int arrayIndex); int First(); //Goes to the first element in the list int First(out T item); //Goes to the first element returns the value - void ForEach(char* action); //Executes the specified action on each element in the list int IndexOf(T item); void Insert(int index, T item); int Next(); //Goes to next element in the list int Next(out T item); //Goes to next element and writes the element in parameter int Change(const T newElem); //changes the current element bool Remove(T item); //Removes current element - void RemoveAt(int index); - void RemoveRange(int index, int count); - void Reverse(); - void Reverse(int index, int count); + void RemoveAt(int index); //Removes the element at the specified index + void RemoveRange(int index, int count); //Removes all elements in the specified range + void Reverse(); //Reverses the items in the list + void Reverse(int index, int count); //Reverses the items in the specified range T *ToArray(); void TrimExcess(); diff --git a/include/System/Exception.h b/include/System/Exception.h index 23f4613..388716d 100644 --- a/include/System/Exception.h +++ b/include/System/Exception.h @@ -7,6 +7,8 @@ #ifndef _SYSTEM_EXCEPTION_ #define _SYSTEM_EXCEPTION_ +#include + namespace System { /// @@ -21,14 +23,15 @@ namespace System char* _message; public: - Exception InnerException(); + Exception* InnerException(); virtual char* Message(); Exception(); Exception(char* message); + Exception(char* message, Exception* innerException); virtual ~Exception(); - virtual Exception GetBaseException(); + virtual Exception* GetBaseException(); }; /// @@ -39,7 +42,7 @@ namespace System public: ApplicationException(); ApplicationException(char* message); - ~ApplicationException(); + ApplicationException(char* message, Exception* innerException); }; /// @@ -50,7 +53,7 @@ namespace System public: ArithmeticException(); ArithmeticException(char* message); - ~ArithmeticException(); + ArithmeticException(char* message, Exception* innerException); }; /// @@ -61,7 +64,7 @@ namespace System public: DivideByZeroException(); DivideByZeroException(char* message); - ~DivideByZeroException(); + DivideByZeroException(char* message, Exception* innerException); }; /// @@ -72,7 +75,7 @@ namespace System public: SystemException(); SystemException(char* message); - SystemException(char* message, Exception innerException); + SystemException(char* message, Exception* innerException); }; /// @@ -83,7 +86,7 @@ namespace System public: AccessViolationException(); AccessViolationException(char* message); - AccessViolationException(char* message, Exception innerException); + AccessViolationException(char* message, Exception* innerException); }; /// @@ -94,6 +97,7 @@ namespace System public: AppDomainUnloadedException(); AppDomainUnloadedException(char* message); + AppDomainUnloadedException(char* message, Exception* innerException); }; /// @@ -110,7 +114,9 @@ namespace System ArgumentException(); ArgumentException(char* message); + ArgumentException(char* message, Exception* innerException); ArgumentException(char* message, char* paramName); + ArgumentException(char* message, char* paramName, Exception* innerException); }; /// @@ -123,6 +129,7 @@ namespace System ArgumentNullException(); ArgumentNullException(char* paramName); ArgumentNullException(char* paramName, char* message); + ArgumentNullException(char* message, Exception* innerException); }; /// @@ -131,14 +138,19 @@ namespace System /// class ArgumentOutOfRangeException : public ArgumentException { + private: + static char* _rangeMessage; + Object* _actualValue; + static char* RangeMessage(); + public: ArgumentOutOfRangeException(); ArgumentOutOfRangeException(char* paramName); - ArgumentOutOfRangeException(char* paramName, void* object, char* message); + ArgumentOutOfRangeException(char* message, Exception* innerException); ArgumentOutOfRangeException(char* paramName, char* message); + ArgumentOutOfRangeException(char* paramName, Object* actualValue, char* message); - virtual void *ActualValue(); - char* Message(); + virtual Object* ActualValue(); }; /// @@ -160,7 +172,7 @@ namespace System public: InvalidOperationException(); InvalidOperationException(char* message); - InvalidOperationException(char* message, Exception inner); + InvalidOperationException(char* message, Exception* innerException); }; /// @@ -171,7 +183,7 @@ namespace System public: NotImplementedException(); NotImplementedException(char* message); - NotImplementedException(char* message, Exception innerException); + NotImplementedException(char* message, Exception* innerException); }; /// @@ -205,11 +217,13 @@ namespace System { private: char* _objectName; + ObjectDisposedException(); public: char* ObjectName(); ObjectDisposedException(char* objectName); + ObjectDisposedException(char* message, Exception* innerException); ObjectDisposedException(char* objectName, char* message); }; diff --git a/include/System/Interfaces.h b/include/System/Interfaces.h index 723f344..32fa8d2 100644 --- a/include/System/Interfaces.h +++ b/include/System/Interfaces.h @@ -1,3 +1,9 @@ +/******************************************************** + * Interfaces.h * + * * + * System namespace interfaces definition file * + * Copyright © XFX Team. All Rights Reserved * + ********************************************************/ #ifndef _SYSTEM_INTERFACES_ #define _SYSTEM_INTERFACES_ diff --git a/include/System/Runtime/InteropServices/ExternalException.h b/include/System/Runtime/InteropServices/ExternalException.h index 70e3af1..b32c827 100644 --- a/include/System/Runtime/InteropServices/ExternalException.h +++ b/include/System/Runtime/InteropServices/ExternalException.h @@ -4,8 +4,8 @@ * XFX ExternalException definition * * Copyright © XFX Team. All Rights Reserved * ********************************************************/ -#ifndef _SYSTEM_RUNTIME_INTEROPSERVICES_ -#define _SYSTEM_RUNTIME_INTEROPSERVICES_ +#ifndef _SYSTEM_RUNTIME_INTEROPSERVICES_ExternalException_ +#define _SYSTEM_RUNTIME_INTEROPSERVICES_ExternalException_ #include @@ -23,10 +23,10 @@ namespace System public: ExternalException(); ExternalException(char* message); - ExternalException(char* message, Exception inner); + ExternalException(char* message, Exception* inner); }; } } } -#endif //_SYSTEM_RUNTIME_INTEROPSERVICES_ +#endif //_SYSTEM_RUNTIME_INTEROPSERVICES_ExternalException_ diff --git a/include/XFX.Game.h b/include/XFX.Game.h index 8b97bc1..4e2ad46 100644 --- a/include/XFX.Game.h +++ b/include/XFX.Game.h @@ -4,14 +4,14 @@ * XFX namespace include file for libXFX.Game.a * * Copyright © XFX Team. All Rights Reserved * ********************************************************/ -#ifndef _XFX_GAME_ -#define _XFX_GAME_ +#ifndef _XFX__GAME_ +#define _XFX__GAME_ // //Data Types // #include "Game.h" -#include "GamerServicesComponent.h" +#include "GamerServices/GamerServicesComponent.h" #include "GameComponentCollection.h" #include "GameServiceContainer.h" #include "GameTime.h" diff --git a/include/XFX.h b/include/XFX.h index 974c307..50e495e 100644 --- a/include/XFX.h +++ b/include/XFX.h @@ -22,22 +22,9 @@ #include "Vector2.h" #include "Vector3.h" #include "Vector4.h" - +// +//Enums +// #include "Enums.h" -// -//Interfaces -// -#include "IDrawable.h" -#include "IGameComponent.h" -#include "IGraphicsDeviceManager.h" -#include "IUpdateable.h" - -// -//Namespaces -// -#include "Audio.h" -#include "Graphics.h" -#include "Media.h" - #endif //_XFX_ diff --git a/src/libXFX.Game/Game.cpp b/src/libXFX.Game/Game.cpp index ee1bc6b..f41d478 100644 --- a/src/libXFX.Game/Game.cpp +++ b/src/libXFX.Game/Game.cpp @@ -25,12 +25,15 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. -extern "C" { +extern "C" +{ #include #include } +#include "../libXFX/pbKit.h" #include +#include namespace XFX { @@ -78,6 +81,10 @@ namespace XFX return services; } + void Game::BeginRun() + { + } + bool Game::BeginDraw() { return graphicsManager->BeginDraw(); @@ -100,7 +107,7 @@ namespace XFX { IDisposable disposable = component as IDisposable; if (disposable != null) - disposable.Dispose(); + disposable->Dispose(); } */ } @@ -132,6 +139,10 @@ namespace XFX if(graphicsManager != null) graphicsManager->EndDraw(); } + + void Game::EndRun() + { + } void Game::Exit() { @@ -154,6 +165,10 @@ namespace XFX LoadContent(); } + void Game::LoadContent() + { + } + void Game::OnActivated(Object* sender, EventArgs args) { if (Activated != null) @@ -197,11 +212,19 @@ namespace XFX if(BeginDraw()) { + pb_reset(); + pb_erase_depth_stencil_buffer(0, 0, 640, 480); + Draw(gameTime); + EndDraw(); } } + void Game::UnloadContent() + { + } + void Game::Update(GameTime gameTime) { /*for (int i = 0; i < this.updateableComponents.Count; i++) diff --git a/src/libXFX.Game/GameComponentCollection.cpp b/src/libXFX.Game/GameComponentCollection.cpp new file mode 100644 index 0000000..29a8a0d --- /dev/null +++ b/src/libXFX.Game/GameComponentCollection.cpp @@ -0,0 +1,24 @@ +#include + +namespace XFX +{ + GameComponentCollection::GameComponentCollection() + { + } + + void GameComponentCollection::ClearItems() + { + } + + void GameComponentCollection::InsertItem(int index, IGameComponent* item) + { + } + + void GameComponentCollection::RemoveItem(int index) + { + } + + void GameComponentCollection::SetItem(int index, IGameComponent* item) + { + } +} diff --git a/src/libXFX.Game/GameServiceContainer.cpp b/src/libXFX.Game/GameServiceContainer.cpp new file mode 100644 index 0000000..a056bc6 --- /dev/null +++ b/src/libXFX.Game/GameServiceContainer.cpp @@ -0,0 +1,20 @@ +#include + +namespace XFX +{ + GameServiceContainer::GameServiceContainer() + { + } + + void GameServiceContainer::AddService(Object* provider) + { + } + + Object* GetService(Object* ServiceType) + { + } + + void RemoceService(Object* type) + { + } +} diff --git a/src/libXFX.Game/GraphicsDeviceManager.cpp b/src/libXFX.Game/GraphicsDeviceManager.cpp index 8ea470d..35a42d1 100644 --- a/src/libXFX.Game/GraphicsDeviceManager.cpp +++ b/src/libXFX.Game/GraphicsDeviceManager.cpp @@ -26,7 +26,10 @@ // POSSIBILITY OF SUCH DAMAGE. #include + +extern "C" { #include "../libXFX/pbKit.h" +} namespace XFX { @@ -35,13 +38,32 @@ namespace XFX const DeviceType_t GraphicsDeviceManager::ValidDeviceTypes[] = { DeviceType::Hardware }; SurfaceFormat_t GraphicsDeviceManager::ValidAdapterFormats[] = { SurfaceFormat::Bgr32, SurfaceFormat::Bgr555, SurfaceFormat::Bgr565, SurfaceFormat::Bgra1010102 }; SurfaceFormat_t GraphicsDeviceManager::ValidBackBufferFormats[] = { SurfaceFormat::Bgr565, SurfaceFormat::Bgr555, SurfaceFormat::Bgra5551, SurfaceFormat::Bgr32, SurfaceFormat::Color, SurfaceFormat::Bgra1010102 }; - + + GraphicsDeviceManager::GraphicsDeviceManager() + { + } + + GraphicsDeviceManager::GraphicsDeviceManager(Game game) + { + SynchronizeWithVerticalRetrace = true; + backBufferFormat = SurfaceFormat::Color; + backBufferHeight = DefaultBackBufferHeight; + backBufferWidth = DefaultBackBufferWidth; + minimumVertexShaderProfile = ShaderProfile::XVS_1_1; + _game = game; + /* + if (game.Services().GetService((Object*)IGraphicsDeviceManager) != null) + throw ArgumentException("A graphics device manager is already registered. The graphics device manager cannot be changed once it is set.");*/ + + game.Services().AddService(this); + } + GraphicsDevice GraphicsDeviceManager::GraphicsDevice_() { return graphicsDevice; } - bool IsFullScreen() + bool GraphicsDeviceManager::IsFullScreen() { return true; } @@ -51,6 +73,13 @@ namespace XFX } + bool GraphicsDeviceManager::BeginDraw() + { + pb_reset(); + + return true; + } + bool GraphicsDeviceManager::CanResetDevice(GraphicsDeviceInformation newDeviceInfo) { if (graphicsDevice.CreationParameters().DeviceType_() != newDeviceInfo.DeviceType_) @@ -60,15 +89,32 @@ namespace XFX return true; } - GraphicsDeviceManager::GraphicsDeviceManager(Game game) + void GraphicsDeviceManager::CreateDevice() { - _game = game; - /* - if (game.Services().GetService((Object*)IGraphicsDeviceManager) != null) - throw ArgumentException("A graphics device manager is already registered. The graphics device manager cannot be changed once it is set.");*/ + switch(pb_init()) + { + default: + OnDeviceCreated(this, EventArgs::Empty); + break; + } + } - game.Services().AddService((Object*)this); - game.Services().AddService((Object*)this); + void GraphicsDeviceManager::Dispose() + { + Dispose(true); + } + + void GraphicsDeviceManager::Dispose(bool disposing) + { + if (disposing) + { + } + } + + void GraphicsDeviceManager::EndDraw() + { + pb_wait_for_vbl(); + pb_finished(); } GraphicsDeviceInformation GraphicsDeviceManager::FindBestDevice(bool anySuitableDevice) @@ -125,14 +171,4 @@ namespace XFX { } - - bool IGraphicsDeviceManager::BeginDraw() - { - return true; - } - - void IGraphicsDeviceManager::EndDraw() - { - - } } diff --git a/src/libXFX.Game/libXFX.Game.vcproj b/src/libXFX.Game/libXFX.Game.vcproj index 49ef8ea..8c45e0d 100644 --- a/src/libXFX.Game/libXFX.Game.vcproj +++ b/src/libXFX.Game/libXFX.Game.vcproj @@ -128,6 +128,14 @@ RelativePath=".\GameComponent.cpp" > + + + + @@ -136,6 +144,10 @@ RelativePath=".\GraphicsDeviceManager.cpp" > + + @@ -178,6 +190,10 @@ RelativePath="..\..\include\Interfaces.h" > + + @@ -187,10 +203,6 @@ - - diff --git a/src/libXFX.Game/makefile b/src/libXFX.Game/makefile index 835f822..52a6727 100644 --- a/src/libXFX.Game/makefile +++ b/src/libXFX.Game/makefile @@ -25,9 +25,9 @@ ENTRYPOINT = -Wl,--entry,_WinMainCRTStartup STRIP = -Wl,--strip-all LD_FLAGS = $(CLINK) $(ALIGN) $(SHARED) $(ENTRYPOINT) $(STRIP) LD_DIRS = -L$(PREFIX)/i386-pc-xbox/lib -L$(PREFIX)/lib -LD_LIBS = $(LD_DIRS) -lm -lopenxdk -lhal -lc -lusb -lc -lxboxkrnl -lc -lhal -lxboxkrnl -lhal -lopenxdk -lc -lstdc++ -lgcc +LD_LIBS = $(LD_DIRS) -lmscorlib -lXFX -lm -lopenxdk -lhal -lc -lusb -lc -lxboxkrnl -lc -lhal -lxboxkrnl -lhal -lopenxdk -lc -lstdc++ -lgcc -OBJS = DrawableGameComponent.o Game.o GameComponent.o GamerServicesComponent.o GameTime.o GraphicsDeviceManager.o +OBJS = DrawableGameComponent.o Game.o GameComponent.o GameComponentCollection.o GameServiceContainer.o GamerServicesComponent.o GameTime.o GraphicsDeviceManager.o all: libXFX.Game.a diff --git a/src/libXFX/DepthStencilBuffer.cpp b/src/libXFX/DepthStencilBuffer.cpp index 8a81824..83add7a 100644 --- a/src/libXFX/DepthStencilBuffer.cpp +++ b/src/libXFX/DepthStencilBuffer.cpp @@ -6,6 +6,7 @@ namespace XFX { DepthStencilBuffer() { + _graphicsDevice = null; _width = 0; _height = 0; _format = DepthFormat::Unknown; @@ -13,8 +14,9 @@ namespace XFX isDisposed = false; } - DepthStencilBuffer::DepthStencilBuffer(GraphicsDevice &graphicsDevice, int width, int height, DepthFormat_t format) + DepthStencilBuffer::DepthStencilBuffer(GraphicsDevice* graphicsDevice, int width, int height, DepthFormat_t format) { + _graphicsDevice = graphiceDevice; _width = width; _height = height; _format = format; @@ -22,26 +24,42 @@ namespace XFX isDisposed = false; } - DepthStencilBuffer(GraphicsDevice &graphicsDevice, int width, int height, DepthFormat_t format, MultiSampleType_t multiSampleType, int multiSampleQuality) + DepthStencilBuffer::DepthStencilBuffer(GraphicsDevice* graphicsDevice, int width, int height, DepthFormat_t format, MultiSampleType_t multiSampleType, int multiSampleQuality) { + _graphicsDevice = graphiceDevice; _width = width; _height = height; _format = format; _multiSampleType = multiSampleType; isDisposed = false; } + + DepthStencilBuffer::DepthStencilBuffer(const DepthStencilBuffer &obj) + { + _graphicsDevice = obj._graphicsDevice; + _width = obj._width; + _height = obj._height; + _format = obj._format; + _multiSampleType = obj._multiSampleType; + isDisposed = obj.isDisposed; + } + + DepthStencilBuffer::~DepthStencilBuffer() + { + Dispose(false); + } DepthFormat_t DepthStencilBuffer::Format() { return _format; } - GraphicsDevice DepthStencilBuffer::GraphicsDevice_() + GraphicsDevice* DepthStencilBuffer::GraphicsDevice_() { return _graphicsDevice; } - int DepthStencilBuffer::IsDisposed() + bool DepthStencilBuffer::IsDisposed() { return isDisposed(); } @@ -61,7 +79,7 @@ namespace XFX Dispose(true); } - void DepthStencilBuffer::Dispose(int __p1) + void DepthStencilBuffer::Dispose(bool __p1) { if(__p1) { diff --git a/src/libXFX/Effect.cpp b/src/libXFX/Effect.cpp new file mode 100644 index 0000000..a05fef4 --- /dev/null +++ b/src/libXFX/Effect.cpp @@ -0,0 +1,36 @@ +// Copyright (C) 2010-2012, 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 + { + + } +} diff --git a/src/libXFX/GraphicsAdapter.cpp b/src/libXFX/GraphicsAdapter.cpp index cc4be0b..9439434 100644 --- a/src/libXFX/GraphicsAdapter.cpp +++ b/src/libXFX/GraphicsAdapter.cpp @@ -25,14 +25,22 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. -#include "pbKit.h" #include + +extern "C" { +#include "pbKit.h" #include +} namespace XFX { namespace Graphics { + GraphicsAdapter::~GraphicsAdapter() + { + Dispose(false); + } + char* GraphicsAdapter::Description() { //TODO: Come up with a device description @@ -71,8 +79,37 @@ namespace XFX bool GraphicsAdapter::IsWideScreen() { + //TODO: Get WideScreen setting from EEPROM return false; } + + bool GraphicsAdapter::CheckDepthStencilMatch(DeviceType_t deviceType, SurfaceFormat_t adapterFormat, SurfaceFormat_t renderTargetFormat, DepthFormat_t depthStencilFormat) + { + } + + bool GraphicsAdapter::CheckDeviceFormat(DeviceType_t deviceType, SurfaceFormat_t adapterFormat, TextureUsage_t usage, QueryUsages_t queryUsages, ResourceType_t resourceType, SurfaceFormat_t checkFormat) + { + } + + bool GraphicsAdapter::CheckDeviceFormat(DeviceType_t deviceType, SurfaceFormat_t adapterFormat, TextureUsage_t usage, QueryUsages_t queryUsages, ResourceType_t resourceType, DepthFormat_t checkFormat) + { + } + + bool GraphicsAdapter::CheckDeviceFormatConversion(DeviceType_t deviceType, SurfaceFormat_t sourceFormat, SurfaceFormat_t targetFormat) + { + } + + bool GraphicsAdapter::CheckDeviceMultiSampleType(DeviceType_t deviceType, SurfaceFormat_t surfaceFormat, bool isFullScreen, MultiSampleType_t sampleType) + { + } + + bool GraphicsAdapter::CheckDeviceMultiSampleType(DeviceType_t deviceType, SurfaceFormat_t surfaceFormat, bool isFullScreen, MultiSampleType_t sampleType, out int qualityLevels) + { + } + + bool GraphicsAdapter::CheckDeviceType(DeviceType_t deviceType, SurfaceFormat_t displayFormat, SurfaceFormat_t backBufferFormat, bool isFullScreen) + { + } DisplayMode GraphicsAdapter::CurrentDisplayMode() { @@ -93,15 +130,33 @@ namespace XFX } return disp; } + + void GraphicsAdapter::Dispose() + { + Dispose(true); + } + + void GraphicsAdapter::Dispose(bool __p1) + { + if (__p1) + { + } + } + + bool GraphicsAdapter::Equals(const GraphicsAdapter obj) + { + // There's for now only one GraphicsAdapter instance, so just return true; + return true; + } bool GraphicsAdapter::IsDeviceTypeAvailable(DeviceType_t deviceType) { switch(deviceType) { - case DeviceType::Hardware: return true; - case DeviceType::NullReference: return false; - case DeviceType::Reference: return false; - default: return false; + case DeviceType::Hardware: return true; + case DeviceType::NullReference: return false; + case DeviceType::Reference: return false; + default: return false; } } @@ -111,5 +166,15 @@ namespace XFX return collection; } + + bool GraphicsAdapter::operator!=(const GraphicsAdapter other) + { + return !Equals(other); + } + + bool GraphicsAdapter::operator==(const GraphicsAdapter other) + { + return Equals(other); + } } } diff --git a/src/libXFX/GraphicsDevice.cpp b/src/libXFX/GraphicsDevice.cpp index 4f42c50..8b18792 100644 --- a/src/libXFX/GraphicsDevice.cpp +++ b/src/libXFX/GraphicsDevice.cpp @@ -31,6 +31,9 @@ #include #include #include +#include +#include +#include #include "pbKit.h" @@ -143,5 +146,10 @@ namespace XFX } } + + void GraphicsDevice::SetVertexShaderConstant(int startRegister, Vector4 constantData) + { + + } } } diff --git a/src/libXFX/PresentationParameters.cpp b/src/libXFX/PresentationParameters.cpp index 6da0703..0bc1773 100644 --- a/src/libXFX/PresentationParameters.cpp +++ b/src/libXFX/PresentationParameters.cpp @@ -32,17 +32,17 @@ namespace XFX namespace Graphics { const int PresentationParameters::DefaultPresentRate = 60; - - PresentationParameters::~PresentationParameters() - { - Dispose(false); - } PresentationParameters::PresentationParameters() { disposed = false; Clear(); } + + PresentationParameters::~PresentationParameters() + { + Dispose(false); + } void PresentationParameters::Clear() { @@ -92,7 +92,7 @@ namespace XFX Dispose(true); } - void PresentationParameters::Dispose(int disposing) + void PresentationParameters::Dispose(bool disposing) { if (!disposed) { @@ -105,7 +105,7 @@ namespace XFX } } - int PresentationParameters::Equals(PresentationParameters &other) + bool PresentationParameters::Equals(const PresentationParameters other) { return ((other.AutoDepthStencilFormat == AutoDepthStencilFormat) && (other.BackBufferCount == BackBufferCount) && @@ -126,12 +126,12 @@ namespace XFX (other.SwapEffect_ == SwapEffect_)); } - int PresentationParameters::operator!=(PresentationParameters &other) + bool PresentationParameters::operator!=(const PresentationParameters other) { return !Equals(other); } - int PresentationParameters::operator==(PresentationParameters &other) + bool PresentationParameters::operator==(const PresentationParameters other) { return Equals(other); } diff --git a/src/libXFX/Rectangle.cpp b/src/libXFX/Rectangle.cpp index 28d21d8..aaddcef 100644 --- a/src/libXFX/Rectangle.cpp +++ b/src/libXFX/Rectangle.cpp @@ -149,7 +149,7 @@ namespace XFX return !Equals(other); } - Rectangle &Rectangle::operator=(const Rectangle other) + Rectangle Rectangle::operator=(const Rectangle other) { X = other.X; Y = other.Y; diff --git a/src/libXFX/Sprite.cpp b/src/libXFX/Sprite.cpp new file mode 100644 index 0000000..a46125b --- /dev/null +++ b/src/libXFX/Sprite.cpp @@ -0,0 +1,86 @@ +// Copyright (C) 2010-2012, 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 + { + Sprite::Sprite(Texture2D texture, Rectangle sourceRectangle, Rectangle destinationRectangle, Color color, float rotation, Vector2 origin, SpriteEffects_t effects, float layerDepth) + { + this->texture = texture; + this->sourceRectangle = sourceRectangle; + this->destinationRectangle = destinationRectangle; + this->color = color; + this->rotation = rotation; + this->origin = origin; + this->effects = effects; + this->layerDepth = layerDepth; + } + + Texture2D Sprite::Texture() + { + return texture; + } + + Rectangle Sprite::SourceRectangle() + { + return sourceRectangle; + } + + Rectangle Sprite::DestinationRectangle() + { + return destinationRectangle; + } + + Color Sprite::Color_() + { + return color; + } + + float Sprite::Rotation() + { + return rotation; + } + + Vector2 Sprite::Origin() + { + return origin; + } + + SpriteEffects_t Sprite::Effects() + { + return effects; + } + + float Sprite::LayerDepth() + { + return layerDepth; + } + } +} diff --git a/src/libXFX/SpriteBatch.cpp b/src/libXFX/SpriteBatch.cpp index e3dc5d3..38d8f48 100644 --- a/src/libXFX/SpriteBatch.cpp +++ b/src/libXFX/SpriteBatch.cpp @@ -25,14 +25,19 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. +extern "C" { +#include "pbkit.h" +} #include #include #include #include #include +#include #include #include #include +#include using namespace XFX; @@ -40,64 +45,72 @@ namespace XFX { namespace Graphics { - SpriteBatch::GraphicsDevice_() + SpriteBatch::SpriteBatch() { - return device; - spriteBlendMode = SpriteBlendMode::None - } - - SpriteBatch::IsDisposed() - { - return disposed; - } - - SpriteBatch::~SpriteBatch() - { - Dispose(false); } SpriteBatch::SpriteBatch(GraphicsDevice graphicsDevice) { device = graphicsDevice; } + + SpriteBatch::~SpriteBatch() + { + Dispose(false); + } + + GraphicsDevice SpriteBatch::GraphicsDevice_() + { + return device; + } + + bool SpriteBatch::IsDisposed() + { + return isDisposed; + } void SpriteBatch::Begin() { Begin(SpriteBlendMode::AlphaBlend, SpriteSortMode::Deferred, SaveStateMode::None, Matrix::Identity); } + + void SpriteBatch::Begin(SpriteBlendMode_t blendMode) + { + Begin(blendMode, SpriteSortMode::Deferred, SaveStateMode::None, Matrix::Identity); + } - void SpriteBatch::Begin(SpriteBlendMode blendMode, SpriteSortMode sortMode, SaveStateMode stateMode) + void SpriteBatch::Begin(SpriteBlendMode_t blendMode, SpriteSortMode_t sortMode, SaveStateMode_t stateMode) { Begin(blendMode, sortMode, stateMode, Matrix::Identity); } - void Begin(SpriteBlendMode blendMode, SpriteSortMode sortMode, SaveStateMode stateMode, Matrix transformMatrix) + void SpriteBatch::Begin(SpriteBlendMode_t blendMode, SpriteSortMode_t sortMode, SaveStateMode_t stateMode, Matrix transformMatrix) { - //to respect order Begin/Draw/end - if (isRunning) - return; + if (inBeginEndPair) + { + throw InvalidOperationException("Begin cannot be called again until End has been successfully called."); + } - if (stateMode == SaveStateMode::SaveState) - saveState = StateBlock(device); - - spriteBlendMode = blendMode; - this.sortMode = sortMode; - if (sortMode == SpriteSortMode::Immediate) - applyGraphicsDeviceSettings(); - isRunning = true; + if (stateMode == SaveStateMode::SaveState) + saveState = StateBlock(device); + spriteBlendMode = blendMode; + spriteSortMode = sortMode; + if (sortMode == SpriteSortMode::Immediate) + applyGraphicsDeviceSettings(); + + inBeginEndPair = true; } - void SpriteBatch::Dispose(int disposing) + void SpriteBatch::Dispose(bool disposing) { - if (!disposed) - { - if (disposing) - { - // Release any managed components - } - disposed = true; - // Release any unmanaged components - } + if (disposing && !isDisposed) + { + if (Disposing != null) + { + Disposing(this, EventArgs::Empty); + } + } + isDisposed = true; } void SpriteBatch::Dispose() @@ -105,95 +118,93 @@ namespace XFX Dispose(true); } - void SpriteBatch::Draw(Texture2D &texture, Rectangle &destinationRectangle, Color &color) + void SpriteBatch::Draw(Texture2D texture, Rectangle destinationRectangle, Color color) { - Draw(texture, destinationRectangle, Rectangle::Zero, color, 0f, Vector2::Zero, SpriteEffects::None, 0f); + Draw(texture, destinationRectangle, Rectangle::Empty, color, 0.0f, Vector2::Zero, SpriteEffects::None, 0.0f); + } + + void SpriteBatch::Draw(Texture2D texture, Vector2 position, Color color) + { + Draw(texture, position, Rectangle::Empty, color); } - void SriteBatch::Draw(Texture2D &texture, Rectangle &destinationRectangle, Rectangle &sourceRectangle, Color &color) + void SpriteBatch::Draw(Texture2D texture, Rectangle destinationRectangle, Rectangle sourceRectangle, Color color) { - Draw(texture, destinationRectangle, sourceRectangle, color, 0f, Vector2::Zero, SpriteEffects::None, 0f); - } - - void SpriteBatch::Draw(Texture2D &texture, Vector2 &position, Color &color) - { - Draw(texture, position, Rectangle::Zero, color); + Draw(texture, destinationRectangle, sourceRectangle, color, 0.0f, Vector2::Zero, SpriteEffects::None, 0.0f); } - void SpriteBatch::Draw(Texture2D &texture, Vector2 &position, Rectangle &sourceRectangle, Color &color) + void SpriteBatch::Draw(Texture2D texture, Vector2 position, Rectangle sourceRectangle, Color color) { - Rectangle destination = Rectangle((int)vector.X, (int)vector.Y, texture.Width, texture.Height); - Draw(texture, destination, sourceRectangle, color, 0f, Vector2::Zero, SpriteEffects::None, 0f); + Rectangle destination = Rectangle((int)position.X, (int)position.Y, texture.Width(), texture.Height()); + Draw(texture, destination, sourceRectangle, color, 0.0f, Vector2::Zero, SpriteEffects::None, 0.0f); } - - void SpriteBatch::Draw(Texture2D &texture, Vector2 &position, Rectangle &sourceRectangle, Color &color, float rotation, Vector2 &origin, float scale, SpriteEffects_t effects, float layerDepth) - { - int width; - int height; - if (sourceRectangle != Rectangle::Zero) - { - width = (int)(sourceRectangle.Width * scale); - height = (int)(sourceRectangle.Height * scale); - } - else - { - width = (int)(texture.Width * scale); - height = (int)(texture.Height * scale); - } - Rectangle destination = Rectangle((int)vector.X, (int)vector.Y, width, height); - Draw(texture, destination, sourceRectangle, color, rotation, origin, effects, layerDepth); - } - - void SpriteBatch::Draw(Texture2D &texture, Vector2 &position, Rectangle &sourceRectangle, Color &color, float rotation, Vector2 &origin, Vector2 &scale, SpriteEffects_t effects, float layerDepth) + + void SpriteBatch::Draw(Texture2D texture, Rectangle destinationRectangle, Rectangle sourceRectangle, Color color, float rotation, Vector2 origin, SpriteEffects_t effects, float layerDepth) { - int width; - int height; - if (sourceRectangle != Rectangle::Zero) - { - width = (int)(sourceRectangle.Width * scale.X); - height = (int)(sourceRectangle.Height * scale.Y); - } - else - { - width = (int)(texture.Width * scale.X); - height = (int)(texture.Height * scale.Y); - } - Rectangle destination = Rectangle((int)vector.X, (int)vector.Y, width, height); - Draw(texture, destination, sourceRectangle, color, rotation, origin, effects, layerDepth); + Sprite sprite = Sprite(texture, + sourceRectangle != Rectangle::Empty ? sourceRectangle : Rectangle(0, 0, texture.Width(), texture.Height()), + destinationRectangle, + color, + rotation, + origin, + effects, + layerDepth); + + SpriteList.Add(sprite); + + if (spriteSortMode == SpriteSortMode::Immediate) + Flush(); } - - void SpriteBatch::Draw(Texture2D &texture, Rectangle &destinationRectangle, Rectangle &sourceRectangle, Color &color, float rotation, Vector2 &origin, SpriteEffects_t &effects, float layerDepth) + + void SpriteBatch::Draw(Texture2D texture, Vector2 position, Rectangle sourceRectangle, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects_t effects, float layerDepth) { - if (!isRunning) - return; - - Sprite temp = Sprite(texture, (sourceRectangle != Rectangle::Zero) ? sourceRectangle : Rectangle(0, 0, texture.Width, texture.Height), - destinationRectangle, color, rotation, origin, effects, layerDepth); - - spriteList.Add(temp); - - if (sortMode == SpriteSortMode::Immediate) - flush(); + int width; + int height; + if (sourceRectangle != Rectangle::Empty) + { + width = (int)(sourceRectangle.Width * scale.X); + height = (int)(sourceRectangle.Height * scale.Y); + } + else + { + width = (int)(texture.Width() * scale.X); + height = (int)(texture.Height() * scale.Y); + } + Rectangle destination = Rectangle((int)position.X, (int)position.Y, width, height); + Draw(texture, destination, sourceRectangle, color, rotation, origin, effects, layerDepth); } - void SpriteBatch::DrawString(SpriteFont &spriteFont, char* text, Vector2 &position, Color &color) + void SpriteBatch::Draw(Texture2D texture, Vector2 position, Rectangle sourceRectangle, Color color, float rotation, Vector2 origin, float scale, SpriteEffects_t effects, float layerDepth) { - if (!spriteFont) - return; - if (!text) - return; - - spriteFont.Draw(text, *this, position, color, 0f, Vector2::Zero, Vector2::One, SpriteEffects::None, 0f); + int width; + int height; + if (sourceRectangle != Rectangle::Empty) + { + width = (int)(sourceRectangle.Width * scale); + height = (int)(sourceRectangle.Height * scale); + } + else + { + width = (int)(texture.Width() * scale); + height = (int)(texture.Height() * scale); + } + Rectangle destination = Rectangle((int)position.X, (int)position.Y, width, height); + Draw(texture, destination, sourceRectangle, color, rotation, origin, effects, layerDepth); } - void SpriteBatch::DrawString(SpriteFont &spriteFont, char* text, Vector2 &position, Color &color, float rotation, Vector2 &origin, float scale, SpriteEffects_t effects, float layerDepth) + void SpriteBatch::DrawString(SpriteFont spriteFont, char* text, Vector2 position, Color color) + { + spriteFont.Draw(text, *this, position, color, 0.0f, Vector2::Zero, Vector2::One, SpriteEffects::None, 0.0f); + } + + void SpriteBatch::DrawString(SpriteFont spriteFont, char* text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects_t effects, float layerDepth) + { + spriteFont.Draw(text, *this, position, color, rotation, origin, scale, effects, layerDepth); + } + + void SpriteBatch::DrawString(SpriteFont spriteFont, char* text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects_t effects, float layerDepth) { - Vector2 vector; - if (!spriteFont) - return; - if (!text) - return; - + Vector2 vector = Vector2::Zero; vector.X = scale; vector.Y = scale; spriteFont.Draw(text, *this, position, color, rotation, origin, vector, effects, layerDepth); @@ -201,125 +212,134 @@ namespace XFX void SpriteBatch::End() { - if (!isRunning) - return; - - if (sortMode != SpriteSortMode::Immediate) - { - applyGraphicsDeviceSettings(); - flush(); - } - - glDisable(GL_TEXTURE_2D); - - Gl::glMatrixMode(Gl::GL_PROJECTION); - Gl::glPopMatrix(); - Gl::glMatrixMode(Gl::GL_MODELVIEW); - Gl::glPopMatrix(); - - restoreRenderState(); - isRunning = false; + if (!inBeginEndPair) + throw InvalidOperationException("Begin must be called successfully before End can be called."); + + if (spriteSortMode != SpriteSortMode::Immediate) + { + applyGraphicsDeviceSettings(); + Flush(); + } + + /*glDisable(GL_TEXTURE_2D); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix();*/ + + restoreRenderState(); + + inBeginEndPair = false; } void SpriteBatch::restoreRenderState() { - if (stateMode == SaveStateMode::SaveState) + if (saveStateMode == SaveStateMode::SaveState) saveState.Apply(); } - void SpriteBatch::flush() - { - switch (sortMode) - { - case SpriteSortMode::BackToFront: - spriteList.Sort(BackToFrontSpriteComparer()); - break; - case SpriteSortMode::FrontToBack: - spriteList.Sort(FrontToBackSpriteComparer()); - break; - case SpriteSortMode::Texture: // nothing here? - break; - } - - spriteList.First(); - Sprite temp; - while(spriteList.Next(temp)) - { - // Set the color, bind the texture for drawing and prepare the texture source - if (temp.Color.A <= 0) continue; - Gl::glColor4f((float)temp.Color.R / 255f, (float)temp.Color.G / 255f, (float)temp.Color.B / 255f, (float)temp.Color.A / 255f); - Gl::glBindTexture(Gl::GL_TEXTURE_2D, temp.Texture.textureId); - - // Setup the matrix - Gl::glPushMatrix(); - if ((temp.DestinationRectangle.X != 0) || (temp.DestinationRectangle.Y != 0)) - Gl::glTranslatef(temp.DestinationRectangle.X, temp.DestinationRectangle.Y, 0f); // Position - if (temp.Rotation != 0) - Gl::glRotatef(MathHelper.ToDegrees(temp.Rotation), 0f, 0f, 1f); // Rotation - if ((temp.DestinationRectangle.Width != 0 && temp.Origin.X != 0) || (temp.DestinationRectangle.Height != 0 && temp.Origin.Y != 0)) - Gl::glTranslatef( // Orientation - -temp.Origin.X * (float)temp.DestinationRectangle.Width / (float)temp.SourceRectangle.Width, - -temp.Origin.Y * (float)temp.DestinationRectangle.Height / (float)temp.SourceRectangle.Height, 0f); - - // Calculate the points on the texture - float x = (float)temp.SourceRectangle.X / (float)temp.Texture.Width; - float y = (float)temp.SourceRectangle.Y / (float)temp.Texture.Height; - float twidth = (float)temp.SourceRectangle.Width / (float)temp.Texture.Width; - float theight = (float)temp.SourceRectangle.Height / (float)temp.Texture.Height; - - // Draw - Gl::glBegin(Gl::GL_QUADS); - { - Gl::glTexCoord2f(x,y + theight); - Gl::glVertex2f(0f, temp.DestinationRectangle.Height); - - Gl::glTexCoord2f(x + twidth, y + theight); - Gl::glVertex2f(temp.DestinationRectangle.Width, temp.DestinationRectangle.Height); - - Gl::glTexCoord2f(x + twidth,y); - Gl::glVertex2f(temp.DestinationRectangle.Width, 0f); - - Gl::glTexCoord2f(x,y); - Gl::glVertex2f(0f, 0f); - } - Gl::glEnd(); - Gl::glPopMatrix(); // Finish with the matrix - } - spriteList.Clear(); - } - void SpriteBatch::applyGraphicsDeviceSettings() - { + { + unsigned int* p; + // Set the blend mode switch (spriteBlendMode) { case SpriteBlendMode::AlphaBlend: - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + p = pb_begin(); + //Enable blending + pb_push(p, NV20_TCL_PRIMITIVE_3D_BLEND_FUNC_ENABLE, 1); p+=2; + //set blendmode + pb_push2(p, NV20_TCL_PRIMITIVE_3D_BLEND_FUNC_SRC, (0x302<<16) | 0x302, (0x303<<16) | 0x303); p+=3; + //send data to GPU + pb_end(p); break; - case SpriteBlendMode::Additive: - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE); + case SpriteBlendMode::Additive: + p = pb_begin(); + //Enable blending + pb_push(p, NV20_TCL_PRIMITIVE_3D_BLEND_FUNC_ENABLE, 1); p+=2; + //set blendmode + pb_push2(p, NV20_TCL_PRIMITIVE_3D_BLEND_FUNC_SRC, (0x302<<16) | 0x302, (1<<16) | 1); p+=3; + //send data to GPU + pb_end(p); break; case SpriteBlendMode::None: - glDisable(GL_BLEND); + p = pb_begin(); + //Disable Blending + pb_push(p, NV20_TCL_PRIMITIVE_3D_BLEND_FUNC_ENABLE, 0); p+=2; + //send data to GPU + pb_end(p); break; default: return; } - glEnable(GL_TEXTURE_2D); + //glEnable(GL_TEXTURE_2D); // Reset the projection matrix and use the orthographic matrix - int[] viewPort = new int[4]; - Gl::glGetIntegerv(Gl::GL_VIEWPORT, viewPort); - Gl::glMatrixMode(Gl::GL_PROJECTION); - Gl::glPushMatrix(); - Gl::glLoadIdentity(); - Gl::glOrtho(0, viewPort[2], viewPort[3], 0, -1, 1); // viewPort[2] = width, viewPort[3] = height - Gl::glMatrixMode(Gl::GL_MODELVIEW); - Gl::glPushMatrix(); - Gl::glLoadIdentity(); + /*int viewPort[4]; + glGetIntegerv(GL_VIEWPORT, viewPort); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glOrtho(0, device.Viewport_().Width, device.Viewport_().Height, 0, -1, 1); // viewPort[2] = width, viewPort[3] = height + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity();*/ + } + + void SpriteBatch::Flush() + { + switch (spriteSortMode) + { + case SpriteSortMode::BackToFront: + //SpriteList.Sort(BackToFrontSpriteComparer()); + break; + case SpriteSortMode::FrontToBack: + //SpriteList.Sort(FrontToBackSpriteComparer()); + break; + case SpriteSortMode::Texture: // nothing here? + break; + } + for (int i = 0; i < SpriteList.Count(); i++) + { + // Set the color, bind the texture for drawing and prepare the texture source + if (SpriteList[i].Color_().A() <= 0) continue; + //glColor4f((float)sprite.Color_().R() / 255f, (float)sprite.Color_().G() / 255f, (float)sprite.Color_().B() / 255f, (float)sprite.Color_().A() / 255f); + //glBindTexture(GL_TEXTURE_2D, sprite.Texture->textureId); + // Setup the matrix + //if ((SpriteList[i].DestinationRectangle().X != 0) || (SpriteList[i].DestinationRectangle().Y != 0)) + // glTranslatef(SpriteList[i].DestinationRectangle().X, SpriteList[i].DestinationRectangle().Y, 0.0f); // Position + + //if (SpriteList[i].Rotation() != 0) + // glRotatef(MathHelper::ToDegrees(SpriteList[i].Rotation()), 0.0f, 0.0f, 1.0f); // Rotation + + /*if ((SpriteList[i].DestinationRectangle().Width != 0 && SpriteList[i].Origin().X != 0) || (SpriteList[i].DestinationRectangle().Height != 0 && SpriteList[i].Origin().Y != 0)) + glTranslatef( + // Orientation + -SpriteList[i].Origin.X * (float)SpriteList[i].DestinationRectangle().Width / (float)SpriteList[i].SourceRectangle().Width, + -SpriteList[i].Origin.Y * (float)SpriteList[i].DestinationRectangle().Height / (float)SpriteList[i].SourceRectangle().Height, 0.0f);*/ + // Calculate the points on the texture + float x = (float)SpriteList[i].SourceRectangle().X / (float)SpriteList[i].Texture().Width(); + float y = (float)SpriteList[i].SourceRectangle().Y / (float)SpriteList[i].Texture().Height(); + float twidth = (float)SpriteList[i].SourceRectangle().Width / (float)SpriteList[i].Texture().Width(); + float theight = (float)SpriteList[i].SourceRectangle().Height / (float)SpriteList[i].Texture().Height(); + // Draw + /*glBegin(GL_QUADS); + { + glTexCoord2f(x,y + theight); + glVertex2f(0f, SpriteList[i].DestinationRectangle().Height); + glTexCoord2f(x + twidth, y + theight); + glVertex2f(SpriteList[i].DestinationRectangle().Width, SpriteList[i].DestinationRectangle().Height); + glTexCoord2f(x + twidth,y); + glVertex2f(SpriteList[i].DestinationRectangle().Width, 0f); + glTexCoord2f(x,y); + glVertex2f(0f, 0f); + } + glEnd(); + glPopMatrix(); // Finish with the matrix*/ + } + SpriteList.Clear(); } } } diff --git a/src/libXFX/SpriteFont.cpp b/src/libXFX/SpriteFont.cpp new file mode 100644 index 0000000..1740e4c --- /dev/null +++ b/src/libXFX/SpriteFont.cpp @@ -0,0 +1,162 @@ +// Copyright (C) 2010-2012, 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 +#include +#include +#include +#include + +namespace XFX +{ + namespace Graphics + { + SpriteFont::SpriteFont(Texture2D texture, List glyphs, List cropping, List charMap, int lineSpacing, float spacing, List kerning) + { + textureValue = texture; + glyphData = glyphs; + croppingData = cropping; + characterMap = charMap; + this->lineSpacing = lineSpacing; + this->spacing = spacing; + this->kerning = kerning; + } + + void SpriteFont::Draw(char* text, SpriteBatch spriteBatch, Vector2 textblockPosition, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects_t spriteEffects, float depth) + { + Vector2 vector2; + Matrix matrix; + Matrix matrix2; + + if (text == null) + throw ArgumentNullException("text"); + + Matrix::CreateRotationZ(rotation, matrix2); + Matrix::CreateTranslation(-origin.X * scale.X, -origin.Y * scale.Y, 0.0f, matrix); + Matrix::Multiply(matrix, matrix2, matrix2); + int num2 = 1; + float num4 = 0.0f; + bool flag = true; + if ((spriteEffects & SpriteEffects::FlipHorizontally) == SpriteEffects::FlipHorizontally) + { + num4 = MeasureString(text).X * scale.X; + num2 = -1; + } + if ((spriteEffects & SpriteEffects::FlipVertically) == SpriteEffects::FlipVertically) + { + vector2.Y = (MeasureString(text).Y - lineSpacing) * scale.Y; + } + else + { + vector2.Y = 0.0f; + } + vector2.X = num4; + for (int i = 0; i < Array::Length(text); i++) + { + char character = text[i]; + switch (character) + { + case '\r': + break; + + case '\n': + flag = true; + vector2.X = num4; + if ((spriteEffects & SpriteEffects::FlipVertically) == SpriteEffects::FlipVertically) + { + vector2.Y -= lineSpacing * scale.Y; + } + else + { + vector2.Y += lineSpacing * scale.Y; + } + break; + + default: + { + int indexForCharacter = GetIndexForCharacter(character); + Vector3 vector3 = kerning[indexForCharacter]; + if (flag) + { + vector3.X = Math::Max(vector3.X, 0.0f); + } + else + { + vector2.X += (spacing * scale.X) * num2; + } + vector2.X += (vector3.X * scale.X) * num2; + Rectangle rectangle = glyphData[indexForCharacter]; + Rectangle rectangle2 = croppingData[indexForCharacter]; + if ((spriteEffects & SpriteEffects::FlipVertically) == SpriteEffects::FlipVertically) + { + rectangle2.Y = (lineSpacing - rectangle.Height) - rectangle2.Y; + } + if ((spriteEffects & SpriteEffects::FlipHorizontally) == SpriteEffects::FlipHorizontally) + { + rectangle2.X -= rectangle2.Width; + } + Vector2 position = vector2; + position.X += rectangle2.X * scale.X; + position.Y += rectangle2.Y * scale.Y; + Vector2::Transform(position, matrix2, position); + position.X += textblockPosition.X; + position.Y += textblockPosition.Y; + spriteBatch.Draw(textureValue, position, rectangle, color, rotation, Vector2::Zero, scale, spriteEffects, depth); + flag = false; + vector2.X += ((vector3.Y + vector3.Z) * scale.X) * num2; + break; + } + } + } + } + + int SpriteFont::GetIndexForCharacter(char character) + { + int num2 = 0; + int num3 = characterMap.Count() - 1; + while (num2 <= num3) + { + int num = num2 + ((num3 - num2) >> 1); + char ch = characterMap[num]; + if (ch == character) + { + return num; + } + if (ch < character) + { + num2 = num + 1; + } + else + { + num3 = num - 1; + } + } + throw ArgumentException("character"); + } + } +} diff --git a/src/libXFX/StateBlock.cpp b/src/libXFX/StateBlock.cpp new file mode 100644 index 0000000..b7786c8 --- /dev/null +++ b/src/libXFX/StateBlock.cpp @@ -0,0 +1,61 @@ +// Copyright (C) 2010-2012, 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 + { + StateBlock::StateBlock() + { + } + + StateBlock::StateBlock(GraphicsDevice graphicsDevice) + { + } + + StateBlock::StateBlock(const StateBlock &obj) + { + } + + bool StateBlock::Equals(StateBlock other) + { + + } + + bool StateBlock::operator!=(const StateBlock other) + { + return !Equals(other); + } + + bool StateBlock::operator==(const StateBlock other) + { + return Equals(other); + } + } +} diff --git a/src/libXFX/StorageDeviceNotConnectedException.cpp b/src/libXFX/StorageDeviceNotConnectedException.cpp index 61c4421..0225de8 100644 --- a/src/libXFX/StorageDeviceNotConnectedException.cpp +++ b/src/libXFX/StorageDeviceNotConnectedException.cpp @@ -32,6 +32,7 @@ namespace XFX namespace Storage { StorageDeviceNotConnectedException::StorageDeviceNotConnectedException() + : ExternalException() { } @@ -40,7 +41,7 @@ namespace XFX { } - StorageDeviceNotConnectedException::StorageDeviceNotConnectedException(char* message, Exception innerException) + StorageDeviceNotConnectedException::StorageDeviceNotConnectedException(char* message, Exception* innerException) : ExternalException(message, innerException) { } diff --git a/src/libXFX/Texture2D.cpp b/src/libXFX/Texture2D.cpp index 2f83dfe..5417daf 100644 --- a/src/libXFX/Texture2D.cpp +++ b/src/libXFX/Texture2D.cpp @@ -53,6 +53,11 @@ namespace XFX { return _width; } + + Texture2D::Texture2D() + { + textureId = -1; + } Texture2D::Texture2D(GraphicsDevice graphicsDevice) { @@ -78,6 +83,17 @@ namespace XFX _textureUsage = usage; _surfaceFormat = format; } + + Texture2D::Texture2D(const Texture2D &obj) + { + textureId = obj.textureId; + device = obj.device; + _width = obj._width; + _height = obj._height; + _numberOfLevels = obj._numberOfLevels; + _textureUsage = obj._textureUsage; + _surfaceFormat = obj._surfaceFormat; + } void Texture2D::Dispose(bool disposing) { diff --git a/src/libXFX/libXFX.vcproj b/src/libXFX/libXFX.vcproj index d082fa1..3929308 100644 --- a/src/libXFX/libXFX.vcproj +++ b/src/libXFX/libXFX.vcproj @@ -187,10 +187,6 @@ - - @@ -215,10 +211,6 @@ RelativePath=".\GraphicsDeviceCapabilities.cpp" > - - @@ -227,10 +219,22 @@ RelativePath=".\PresentationParameters.cpp" > + + + + + + @@ -386,9 +390,17 @@ RelativePath="..\..\include\Vector4.h" > + + + + @@ -397,6 +409,10 @@ + + @@ -413,10 +429,6 @@ RelativePath="..\..\include\Graphics\BasicDirectionalLight.h" > - - @@ -433,10 +445,6 @@ RelativePath="..\..\include\Graphics\DisplayModeCollection.h" > - - @@ -445,6 +453,10 @@ RelativePath="..\..\include\Graphics\Exceptions.h" > + + @@ -469,10 +481,22 @@ RelativePath="..\..\include\Graphics\PresentationParameters.h" > + + + + + + @@ -541,6 +565,10 @@ RelativePath="..\..\include\Input\GamePadState.h" > + + @@ -557,6 +585,10 @@ RelativePath="..\..\include\Media\Enums.h" > + + @@ -569,6 +601,10 @@ + + @@ -589,6 +625,10 @@ RelativePath="..\..\include\GamerServices\Enums.h" > + + diff --git a/src/libXFX/makefile b/src/libXFX/makefile index a46f09a..ab9ae9d 100644 --- a/src/libXFX/makefile +++ b/src/libXFX/makefile @@ -35,7 +35,7 @@ OBJS = BoundingBox.o BoundingFrustrum.o BoundingSphere.o MathHelper.o Matrix.o P AUDIO_OBJS = CONTENT_OBJS = ContentManager.o ContentReader.o GAMERSERVICES_OBJS = Guide.o -GRAPHICS_OBJS = Color.o DisplayMode.o GraphicsAdapter.o GraphicsDevice.o pbKit.o Texture.o Texture2D.o TextureCollection.o TextureCreationParameters.o VertexElement.o VertexPositionColor.o VertexPositionNormalTexture.o VertexPositionTexture.o Viewport.o +GRAPHICS_OBJS = Color.o DisplayMode.o GraphicsAdapter.o GraphicsDevice.o pbKit.o Sprite.o SpriteBatch.o SpriteFont.o Texture.o Texture2D.o TextureCollection.o TextureCreationParameters.o VertexElement.o VertexPositionColor.o VertexPositionNormalTexture.o VertexPositionTexture.o Viewport.o INPUT_OBJS = GamePad.o Keyboard.o Mouse.o MEDIA_OBJS = VideoPlayer.o NET_OBJS = diff --git a/src/libmscorlib/Array.cpp b/src/libmscorlib/Array.cpp index 7eb38de..38f6ba5 100644 --- a/src/libmscorlib/Array.cpp +++ b/src/libmscorlib/Array.cpp @@ -26,11 +26,48 @@ // POSSIBILITY OF SUCH DAMAGE. #include +#include #include #include namespace System { + template + int Array::BinarySearch(T array[], int index, int length, T value, IComparer* comparer) + { + try + { + if (comparer == null) + { + comparer = Comparer::Default(); + } + int num = index; + int num2 = (index + length) - 1; + while (num <= num2) + { + int num3 = num + ((num2 - num) >> 1); + int num4 = comparer->Compare(array[num3], value); + if (num4 == 0) + { + return num3; + } + if (num4 < 0) + { + num = num3 + 1; + } + else + { + num2 = num3 - 1; + } + } + return ~num; + } + catch(Exception* exception) + { + throw InvalidOperationException("", exception); + } + } + template void Array::Clear(T array[], int index, int length) { diff --git a/src/libmscorlib/Comparer.cpp b/src/libmscorlib/Comparer.cpp index 6bb83af..51d0136 100644 --- a/src/libmscorlib/Comparer.cpp +++ b/src/libmscorlib/Comparer.cpp @@ -1,3 +1,30 @@ +// Copyright (C) 2010-2012, 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 System @@ -6,7 +33,27 @@ namespace System { namespace Generic { - + template + Comparer::Comparer() + { + } + + template + Comparer Comparer::Default() + { + return defaultComparer; + } + + template + int Comparer::Compare(T x, T y) + { + if (x < y) + return -1; + if (x == y) + return 0; + if (x > y) + return 1; + } } } } diff --git a/src/libmscorlib/Dictionary.cpp b/src/libmscorlib/Dictionary.cpp index 6b37abb..94b1ba3 100644 --- a/src/libmscorlib/Dictionary.cpp +++ b/src/libmscorlib/Dictionary.cpp @@ -101,7 +101,7 @@ namespace System bool Dictionary::Contains(KeyValuePair keyValuePair) { int index = FindEntry(keyValuePair.Key()); - return ((index >= 0) && EqualityComparer::Default.Equals(entries[index].value, keyValuePair.Value())); + return ((index >= 0) && EqualityComparer::Default().Equals(entries[index].value, keyValuePair.Value())); } template @@ -115,10 +115,10 @@ namespace System { if (buckets != null) { - int num = comparer.GetHashCode(key) & 0x7fffffff; + int num = comparer->GetHashCode(key) & 0x7fffffff; for (int i = buckets[num % Array::Length(buckets)]; i >= 0; i = entries[i].next) { - if ((entries[i].hashCode == num) && comparer.Equals(entries[i].key, key)) + if ((entries[i].hashCode == num) && comparer->Equals(entries[i].key, key)) { return i; } @@ -147,11 +147,11 @@ namespace System if(buckets == null) Initialize(0); - int num = comparer.GetHashCode(key) & 0x7fffffff; + int num = comparer->GetHashCode(key) & 0x7fffffff; int index = num % Array::Length(buckets); for(int i = buckets[index]; i >= 0; i = entries[i].next) { - if((entries[i].hashCode == num) && comparer.Equals(entries[i].key, key)) + if((entries[i].hashCode == num) && comparer->Equals(entries[i].key, key)) { if(add) throw ArgumentException("Adding duplicate of existing key."); @@ -190,12 +190,12 @@ namespace System { if(buckets != null) { - int num = comparer.GetHashCode(key) & 0x7fffffff; + int num = comparer->GetHashCode(key) & 0x7fffffff; int index = num % Array::Length(buckets); int num3 = -1; for(int i = buckets[index]; i >= 0; i = entries[i].next) { - if((entries[i].hashCode == num) && comparer.Equals(entries[i].key, key)) + if((entries[i].hashCode == num) && comparer->Equals(entries[i].key, key)) { if(num3 < 0) { @@ -207,8 +207,8 @@ namespace System } entries[i].hashCode = -1; entries[i].next = freeList; - //entries[i].key = default(TKey); - //entries[i].value = default(TValue); + entries[i].key = TKey(); + entries[i].value = TValue(); freeList = i; freeCount++; version++; @@ -250,7 +250,7 @@ namespace System value = entries[index].value; return true; } - //value = default(TValue); + value = TValue(); return false; } diff --git a/src/libmscorlib/Exception.cpp b/src/libmscorlib/Exception.cpp index 0c617c0..31d2d62 100644 --- a/src/libmscorlib/Exception.cpp +++ b/src/libmscorlib/Exception.cpp @@ -25,6 +25,7 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. +#include #include namespace System @@ -37,46 +38,92 @@ namespace System Exception::Exception() { _message = ""; + _innerException = null; } Exception::Exception(char* message) { _message = message; + _innerException = null; + } + + Exception::Exception(char* message, Exception* innerException) + { + _message = message; + _innerException = innerException; + } + + Exception::~Exception() + { + _innerException = null; + delete[] _message; + } + + Exception* Exception::GetBaseException() + { + Exception *innerException = _innerException; + Exception *exception2 = this; + while(innerException != null) + { + exception2 = innerException; + innerException = innerException->_innerException; + } + return innerException; + } + + Exception* Exception::InnerException() + { + return _innerException; } // // ApplicationException // ApplicationException::ApplicationException() + : Exception() { - _message = ""; } ApplicationException::ApplicationException(char* message) + : Exception(message) + { + } + + ApplicationException::ApplicationException(char* message, Exception* innerException) + : Exception(message, innerException) { - _message = message; } // // ArithmeticException // ArithmeticException::ArithmeticException() + : Exception() { - _message = ""; } ArithmeticException::ArithmeticException(char* message) + : Exception(message) + { + } + + ArithmeticException::ArithmeticException(char* message, Exception* innerException) + : Exception(message, innerException) { - _message = message; } // // DivideByZeroException // DivideByZeroException::DivideByZeroException() + : ArithmeticException() { - _message = ""; } DivideByZeroException::DivideByZeroException(char* message) + : ArithmeticException(message) + { + } + + DivideByZeroException::DivideByZeroException(char* message, Exception* innerException) + : ArithmeticException(message, innerException) { - _message = message; } } diff --git a/src/libmscorlib/KeyNotFoundException.cpp b/src/libmscorlib/KeyNotFoundException.cpp index b75abd0..c647fae 100644 --- a/src/libmscorlib/KeyNotFoundException.cpp +++ b/src/libmscorlib/KeyNotFoundException.cpp @@ -43,7 +43,7 @@ namespace System { } - KeyNotFoundException::KeyNotFoundException(char* message, Exception innerException) + KeyNotFoundException::KeyNotFoundException(char* message, Exception* innerException) : SystemException(message, innerException) { } diff --git a/src/libmscorlib/Object.cpp b/src/libmscorlib/Object.cpp index 2966351..ab7769e 100644 --- a/src/libmscorlib/Object.cpp +++ b/src/libmscorlib/Object.cpp @@ -38,6 +38,16 @@ namespace System bool Object::Equals(Object* objA, Object* objB) { - return ((&objA == &objB) || ((objA != null) && (objB != null) && objA->Equals(objB))); + return ((&objA == &objB) || ((objA != null) && (objB != null) && objA->Equals(objB)) || (objA == null) && (objB == null)); + } + + int Object::GetHashCode() + { + return 1; + } + + char* Object::ToString() + { + return "Object"; } } diff --git a/src/libmscorlib/Path.cpp b/src/libmscorlib/Path.cpp index 2fd563c..2b7c38e 100644 --- a/src/libmscorlib/Path.cpp +++ b/src/libmscorlib/Path.cpp @@ -14,7 +14,6 @@ typedef struct } stDriveMapping; -#if ENABLE_XBOX stDriveMapping driveMapping[] = { { 'C', "Harddisk0\\Partition2", 2}, @@ -28,17 +27,6 @@ char extendPartitionMapping[] = { 'F','G','R','S','V','W','A','B' }; -#else -stDriveMapping driveMapping[] = -{ - { 'C', "C:", 2}, - { 'D', "D:", -1}, - { 'E', "E:", 1}, - { 'X', "X:", 3}, - { 'Y', "Y:", 4}, - { 'Z', "Z:", 5}, -}; -#endif #define NUM_OF_DRIVES (sizeof(driveMapping) / sizeof(driveMapping[0])) @@ -58,7 +46,7 @@ namespace System char* Path::ChangeExtension(char* path, char* extension) { - + } char* Path::Combine(char* path1, char* path2) @@ -111,13 +99,11 @@ namespace System } part_num = atoi(szPartition + 19); -#ifdef _XBOX if (part_num >= 6) { *cDriveLetter = extendPartitionMapping[part_num-6]; return; } -#endif for (unsigned int i=0; i < NUM_OF_DRIVES; i++) if (strnicmp(driveMapping[i].szDevice, szPartition, strlen(driveMapping[i].szDevice)) == 0) { @@ -130,31 +116,21 @@ namespace System char *Path::GetInvalidFileNameChars() { // return a new array as we do not want anyone to be able to change the values -#if ENABLE_XBOX char invChars[41] = { '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07', '\x08', '\x09', '\x0A', '\x0B', '\x0C', '\x0D', '\x0E', '\x0F', '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\x1A', '\x1B', '\x1C', '\x1D', '\x1E', '\x1F', '\x22', '\x3C', '\x3E', '\x7C', ':', '*', '?', '\\', '/' }; return invChars; -#else - char invChars[2] = { '\x00', '/' }; - return invChars; -#endif } char *Path::GetInvalidPathChars() { // return a new array as we do not want anyone to be able to change the values -#if ENABLE_XBOX char invChars[36] = { '\x22', '\x3C', '\x3E', '\x7C', '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07', '\x08', '\x09', '\x0A', '\x0B', '\x0C', '\x0D', '\x0E', '\x0F', '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\x1A', '\x1B', '\x1C', '\x1D', '\x1E', '\x1F' }; return invChars; -#else - char invChar[1] = { '\x00' }; - return invChar; -#endif } } } diff --git a/src/libmscorlib/SystemException.cpp b/src/libmscorlib/SystemException.cpp index 158dc61..eb3bb81 100644 --- a/src/libmscorlib/SystemException.cpp +++ b/src/libmscorlib/SystemException.cpp @@ -29,168 +29,249 @@ namespace System { + // + // SystemException + // SystemException::SystemException() + Exception() { - _message = ""; } SystemException::SystemException(char* message) + : Exception(message) { - _message = message; } - SystemException::SystemException(char* message, Exception innerException) + SystemException::SystemException(char* message, Exception* innerException) + : Exception(message, innerException) { - _message = message; } - + // + // AccessViolationException + // AccessViolationException::AccessViolationException() + : SystemException() { - _message = ""; } AccessViolationException::AccessViolationException(char* message) + : SystemException(message) { - _message = message; } - AppDomainUnloadedException::AppDomainUnloadedException() + AccessViolationException::AccessViolationException(char* message, Exception* innerException) + : SystemException(message, innerException) + { + } + // + // AppDomainUnloadedException + // + AppDomainUnloadedException::AppDomainUnloadedException() + : SystemException() { - _message = ""; } AppDomainUnloadedException::AppDomainUnloadedException(char* message) + : SystemException(message) { - _message = message; } - ArgumentException::ArgumentException() + AppDomainUnloadedException::AppDomainUnloadedException(char* message, Exception* innerException) + : SystemException(message, innerException) + { + } + // + // ArgumentException + // + ArgumentException::ArgumentException() + : SystemException() { - _message = ""; _paramName = ""; } ArgumentException::ArgumentException(char* message) + : SystemException(message); { - _message = message; _paramName = ""; } ArgumentException::ArgumentException(char* message, char* paramName) + : SystemException(message) { - _message = message; _paramName = paramName; } + ArgumentException::ArgumentException(char* message, char* paramName, Exception* innerException) + : SystemException(message, innerException) + { + _paramName = paramName; + } + // + // ArgumentNullException + // ArgumentNullException::ArgumentNullException() + : ArgumentException() { - _message = ""; - _paramName = ""; } - ArgumentNullException::ArgumentNullException(char* message) + ArgumentNullException::ArgumentNullException(char* paramName) + : ArgumentException(paramName) { - _message = message; - _paramName = ""; } - ArgumentNullException::ArgumentNullException(char* message, char* paramName) + ArgumentNullException::ArgumentNullException(char* paramName, char* message) + : ArgumentException(message, paramName) { - _message = message; - _paramName = paramName; } + ArgumentNullException::ArgumentNullException(char* message, Exception* innerException) + : ArgumentException(message, innerException) + { + } + // + // ArgumentOutOfRangeException + // ArgumentOutOfRangeException::ArgumentOutOfRangeException() + : ArgumentException(RangeMessage()) + { + } + + ArgumentOutOfRangeException::ArgumentOutOfRangeException(char* paramName) + : ArgumentException(RangeMessage(), paramName) + { + } + + ArgumentOutOfRangeException::ArgumentOutOfRangeException(char* message, Exception* innerException) + : ArgumentException(message, innerException) { } ArgumentOutOfRangeException::ArgumentOutOfRangeException(char* paramName, char* message) + : ArgumentException(message, paramName) { - _message = message; - _paramName = paramName; } - ArgumentOutOfRangeException::ArgumentOutOfRangeException(char* paramName, void* object, char* message) + ArgumentOutOfRangeException::ArgumentOutOfRangeException(char* paramName, Object* actualValue, char* message) + : ArgumentException(message, paramName) { - _message = message; - _paramName = paramName; + _actualValue = actualValue; + } + + Object* ArgumentOutOfRangeException::ActualValue() + { + return _actualValue; + } + + char* ArgumentOutOfRangeException::RangeMessage() + { + if (_rangeMessage == null) + { + return ""; + } + return _rangeMessage; } IndexOutOfRangeException::IndexOutOfRangeException() + : SystemException() { } IndexOutOfRangeException::IndexOutOfRangeException(char* message) + : SystemException(message) + { + } + + IndexOutOfRangeException::IndexOutOfRangeException(char* message, Exception* innerException) + : SystemException(message, innerException) { - _message = message; } InvalidOperationException::InvalidOperationException() + : SystemException() { } InvalidOperationException::InvalidOperationException(char* message) + : SystemException(message) + { + } + + InvalidOperationException::InvalidOperationException(char* message, Exception* innerException) + : SystemException(message, innerException) { - _message = message; } NotImplementedException::NotImplementedException() + : SystemException() { } NotImplementedException::NotImplementedException(char* message) + : SystemException(message) { - _message = message; } - NotImplementedException::NotImplementedException(char* message, Exception innerException) + NotImplementedException::NotImplementedException(char* message, Exception* innerException) + : SystemException(message, innerException) { - _message = message; } NotSupportedException::NotSupportedException() + : SystemException() { - _message = ""; } NotSupportedException::NotSupportedException(char* message) + : SystemException(message) { - _message = message; } - NotSupportedException::NotSupportedException(char* message, Exception innerException) + NotSupportedException::NotSupportedException(char* message, Exception* innerException) + : SystemException(message, innerException) + { + } + + ObjectDisposedException::ObjectDisposedException() + : InvalidOperationException() { - _message = message; } ObjectDisposedException::ObjectDisposedException(char* objectName) { _objectName = objectName; + _message = ""; + } + + ObjectDisposedException::ObjectDisposedException(char* message, Exception* innerException) + : InvalidOperationException(message, innerException) + { } ObjectDisposedException::ObjectDisposedException(char* objectName, char* message) + : InvalidOperationException(message) { _objectName = objectName; - _message = message; } char* ObjectDisposedException::ObjectName() { + if (_objectName == null) + return ""; return _objectName; } UnauthorizedAccessException::UnauthorizedAccessException() + : SystemException() { - _message = ""; } UnauthorizedAccessException::UnauthorizedAccessException(char* message) + : SystemException(message) { - _message = message; } - UnauthorizedAccessException::UnauthorizedAccessException(char* message, Exception inner) + UnauthorizedAccessException::UnauthorizedAccessException(char* message, Exception* inner) + : SystemException(message, inner) { - _message = message; } } diff --git a/src/libmscorlib/libmscorlib.vcproj b/src/libmscorlib/libmscorlib.vcproj index 5c10a59..52843c4 100644 --- a/src/libmscorlib/libmscorlib.vcproj +++ b/src/libmscorlib/libmscorlib.vcproj @@ -127,7 +127,7 @@ >