Jump to content
  • Advertisement
Sign in to follow this  
mike25025

my game engine. comments wanted

This topic is 5066 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i have been working on a game engine for 3 months now and i have run into a problem but before i try to solve the problem i would like to know if i have a good design please tell me what u think
#ifndef MGE_H
#define MGE_H

#ifdef MGE_EXPORT
 #define MGE_API __declspec(dllexport)
#else
 #define MGE_API __declspec(dllimport)
 #ifdef _DEBUG
  #pragma comment(lib,"mge_d.lib")
 #else
  #pragma comment(lib,"mge.lib")
 #endif
#endif

namespace mge
{
	namespace core
	{
		MGE_API extern const void* null;

		typedef __int64 int64;
		typedef int64 ID;

		class Interface
		{
		private:
			int m_ref;
		protected:
			MGE_API Interface();
			MGE_API virtual ~Interface();
			MGE_API virtual void OnRelease();
			MGE_API virtual void OnAddRef();
		public:
			MGE_API void AddRef();
			MGE_API bool Release();
			MGE_API virtual Interface* QueryInterface(ID id);
		};

		enum TimerState
		{
			Running,
			Paused,
			Stopped
		};

		class ITimer : public Interface
		{
		protected:
			~ITimer(){};
		public:
			virtual void Start(float starttime=0.0f)=0;
			virtual void Pause()=0;
			virtual void Resume()=0;
			virtual void Stop()=0;
			virtual TimerState GetState()=0;
			virtual float GetTime()=0;
		};

		MGE_API ITimer* CreateTimer();
	}

	namespace fileio
	{
		class IDirectory;

		enum OpenType
		{
			Read,
			Write
		};

		enum PosType
		{
			Beginning,
			Current,
			End
		};

		class IFile : public core::Interface
		{
		protected:
			~IFile(){};
		public:
			virtual char* GetName()=0;
			virtual IDirectory* GetDirectory()=0;
			virtual bool Open(OpenType opentype)=0;
			virtual void Close()=0;
			virtual bool Delete()=0;
			virtual unsigned int GetSize()=0;
			virtual unsigned int GetPos()=0;
			virtual void SetPos(unsigned int pos,PosType postype)=0;
			virtual int Read(void* buf,unsigned int size,unsigned int count)=0;
			virtual void Write(void* buf,unsigned int size,unsigned int count)=0;
			virtual void Flush()=0;
		};

		class IDirectory : public core::Interface
		{
		protected:
			~IDirectory(){};
		public:
			virtual char* GetName()=0;
			virtual IDirectory* GetParent()=0;
			virtual char** GetDirectoryNames()=0;
			virtual char** GetFileNames()=0;
			virtual IDirectory* GetDirectory(char* name)=0;
			virtual IFile* GetFile(char* name)=0;
			virtual bool Delete()=0;
			virtual IFile* CreateNewFile(char* name)=0;
			virtual IDirectory* CreateNewDirectory(char* name)=0;
		};

		MGE_API IFile* GetProgramFile();
	}

	namespace math
	{
		MGE_API extern const float epsilon;
		MGE_API extern const float pi;
		MGE_API extern const float sqrt2;
		MGE_API extern const float e;

		MGE_API float Sqrt(float x);
		MGE_API float Sin(float x);
		MGE_API float Cos(float x);
		MGE_API float Tan(float x);
		MGE_API float ASin(float x);
		MGE_API float ACos(float x);
		MGE_API float ATan(float x);
		MGE_API float Abs(float x);
		MGE_API int Abs(int x);
		MGE_API float Pow(float x,float n);
		MGE_API int Pow(int x,int n);
		MGE_API float Pow(float x,int n);
		MGE_API float Mod(float x,float n);
		MGE_API int Mod(int x,int y);
		MGE_API float Floor(float x);
		MGE_API float Ceil(float x);
		MGE_API float Log(float x);
		MGE_API float Log10(float x);
		MGE_API float RToD(float x);
		MGE_API float DToR(float x);
		MGE_API float Rand();

		class Matrix4x4;

		class Vector3D
		{
		private:
			float m_x;
			float m_y;
			float m_z;
		public:
			MGE_API Vector3D();
			MGE_API ~Vector3D();
			MGE_API Vector3D(const Vector3D& vector);
			MGE_API Vector3D(float x,float y,float z);
			MGE_API float& operator()(unsigned char index);
			MGE_API void Normalize();
			MGE_API float GetLen();
			MGE_API Vector3D& operator=(Vector3D& vector);
			MGE_API Vector3D& operator+=(Vector3D& v);
			MGE_API Vector3D& operator-=(Vector3D& v);
			MGE_API Vector3D& operator*=(float f);
			MGE_API Vector3D& operator/=(float f);
			MGE_API Vector3D operator+();
			MGE_API Vector3D operator-();
			MGE_API Vector3D operator+(Vector3D& v);
			MGE_API Vector3D operator-(Vector3D& v);
			MGE_API Vector3D operator*(float f);
			MGE_API Vector3D operator/(float f);
			MGE_API bool operator==(Vector3D& v);
			MGE_API bool operator!=(Vector3D& v);
			MGE_API Vector3D& operator*=(Matrix4x4& m);
			MGE_API Vector3D operator*(Matrix4x4& m);
			MGE_API Vector3D& operator^=(Vector3D& v);
			MGE_API float operator*(Vector3D& v);
			MGE_API Vector3D operator^(Vector3D& v);
		};

		class Matrix4x4
		{
		private:
			float m_00;float m_01;float m_02;float m_03;
			float m_10;float m_11;float m_12;float m_13;
			float m_20;float m_21;float m_22;float m_23;
			float m_30;float m_31;float m_32;float m_33;
		public:
			MGE_API Matrix4x4();
			MGE_API ~Matrix4x4();
			MGE_API Matrix4x4(const Matrix4x4& matrix);
			MGE_API Matrix4x4(float f00,float f01,float f02,float f03,
				float f10,float f11,float f12,float f13,
				float f20,float f21,float f22,float f23,
				float f30,float f31,float f32,float f33);
			MGE_API float& operator()(unsigned char row,unsigned char col);
			MGE_API void MakeIdentity();
			MGE_API Matrix4x4& operator+=(Matrix4x4& m);
			MGE_API Matrix4x4& operator-=(Matrix4x4& m);
			MGE_API Matrix4x4& operator*=(Matrix4x4& m);
			MGE_API Matrix4x4& operator*=(float f);
			MGE_API Matrix4x4& operator/=(float f);
			MGE_API Matrix4x4 operator+();
			MGE_API Matrix4x4 operator-();
			MGE_API Matrix4x4 operator+(Matrix4x4& m);
			MGE_API Matrix4x4 operator-(Matrix4x4& m);
			MGE_API Matrix4x4 operator*(Matrix4x4& m);
			MGE_API Matrix4x4 operator*(float f);
			MGE_API Matrix4x4 operator/(float f);
			MGE_API bool operator==(Matrix4x4& m);
			MGE_API bool operator!=(Matrix4x4& m);
			MGE_API Matrix4x4 GetTranspose();
			MGE_API Matrix4x4 GetInverse();
		};

		MGE_API Matrix4x4 CreateXRotationMatrix(float r);
		MGE_API Matrix4x4 CreateYRotationMatrix(float r);
		MGE_API Matrix4x4 CreateZRotationMatrix(float r);
		MGE_API Matrix4x4 CreateScalingMatrix(float s);
		MGE_API Matrix4x4 CreateTranslationMatrix(float x,float y,float z);
		MGE_API Matrix4x4 CreateLookAtMatrix(Vector3D eye,Vector3D at,Vector3D up);
	}

	namespace video
	{
		enum TextureFormat
		{
			RGB,
			ARGB,
			A1R5G5B5,
			X1R5G5B5,
			R5G6B5,
			A4R4G4B4,
			X4R4G4B4,
			R8G8B8,
			A8R8G8B8,
			X8R8G8B8
		};

		class IVideoDevice;

		class ITexture : public core::Interface
		{
		protected:
			~ITexture(){};
		public:
			virtual unsigned int GetWidth()=0;
			virtual unsigned int GetHeight()=0;
			virtual unsigned int GetPitch()=0;
			virtual TextureFormat GetFormat()=0;
			virtual unsigned int BytesPerPixel()=0;
			virtual void* Lock()=0;
			virtual void Unlock()=0;
			virtual void CopyFromDevice(IVideoDevice* videodevice)=0;
			virtual unsigned int GetAMask()=0;
			virtual unsigned int GetRMask()=0;
			virtual unsigned int GetGMask()=0;
			virtual unsigned int GetBMask()=0;
		};

		class Color
		{
		private:
			float m_a;
			float m_r;
			float m_g;
			float m_b;
		public:
			MGE_API Color();
			MGE_API Color(float a,float r,float g,float b);
			MGE_API Color(unsigned long color);
			MGE_API operator double();
			MGE_API Color operator=(double color);
			MGE_API operator unsigned long();
			MGE_API Color operator=(unsigned long color);
			MGE_API float& operator()(unsigned char index);
			MGE_API Color& operator*=(Color& color);
			MGE_API Color& operator+=(Color& color);
			MGE_API Color& operator-=(Color& color);
			MGE_API Color operator+(Color& color);
			MGE_API Color operator-(Color& color);
			MGE_API Color operator*(Color& color);
			MGE_API void SetMax(float a,float r,float g,float b);
			MGE_API void SetMin(float a,float r,float g,float b);
		};

		struct Vertex
		{
			float x;
			float y;
			float z;
			float nx;
			float ny;
			float nz;
			unsigned long c;
			unsigned long b;
			float u;
			float v;
		};

		class ILight : public core::Interface
		{
		private:
			math::Vector3D m_pos;
			Color m_color;
			math::Vector3D m_direction;
		protected:
			~ILight(){};
			MGE_API ILight();
		public:
			virtual Color LightVertex(Vertex& vertex)=0;
			MGE_API void SetPos(math::Vector3D pos);
			MGE_API math::Vector3D GetPos();
			MGE_API void SetColor(Color color);
			MGE_API Color GetColor();
			MGE_API void SetDirection(math::Vector3D direction);
			MGE_API math::Vector3D GetDirection();
		};

		MGE_API ILight* CreatePointLight();
		MGE_API ILight* CreateOmniLight();
		MGE_API ILight* CreateDirectionalLight();

		enum VertexListType
		{
			LineList,
			LineStrip,
			TriangleList,
			TriangleStrip,
			TriangleFan
		};

		enum RenderState
		{
			Alpha,
			Filter,
			Fog,
			FogEnd,
			FogStart,
			FogColor,
			Projection,
			FOV,
			ZNear,
			ZFar,
			Lighting,
			Ambient,
			Cull,
			ZWrite
		};

		enum RenderStateValue
		{
			Enable = 1,
			Disable = 0,
			Linear = 1,
			Point = 0,
			Perspective = 1,
			Orthogonal = 0
		};

		class IVideoDevice : public core::Interface
		{
		protected:
			~IVideoDevice(){};
		public:
			virtual bool Init(int width=640,int height=480,int bits=16,
				bool fullscreen=true,char* caption="")=0;
			virtual void Uninit()=0;
			virtual bool Initalized()=0;
			virtual ITexture* LoadTexture(fileio::IFile* file,TextureFormat format=ARGB)=0;
			virtual void SetTexture(ITexture* texture)=0;
			virtual ITexture* GetTexture()=0;
			virtual void Render(Vertex* vertices,unsigned int nvertices,VertexListType vertexlisttype)=0;
			virtual void Render(Vertex* vertices,unsigned int nvertices,
				unsigned short* indices,unsigned short nindices,VertexListType vertexlisttype)=0;
			virtual void LookAt(math::Vector3D& eye,math::Vector3D& at,math::Vector3D& up)=0;
			virtual void GetLookAt(math::Vector3D* eye,math::Vector3D* at,math::Vector3D* up)=0;
			virtual void Flip()=0;
			virtual void Clear(Color color=Color(0,0,0,0),bool clearcolor=true,bool cleardepth=true)=0;
			virtual void SetRenderState(RenderState state,double value)=0;
			virtual double GetRenderState(RenderState state)=0;
			virtual void SetWorldMatrix(math::Matrix4x4& matrix)=0;
			virtual math::Matrix4x4 GetWorldMatrix()=0;
			virtual unsigned int AddLight(ILight* light)=0;
			virtual void RemoveLight(ILight* light)=0;
			virtual void RemoveLight(unsigned int light)=0;
			virtual ILight* GetLight(unsigned int light)=0;
			virtual unsigned int GetNLights()=0;
			virtual ITexture* CreateTexture(unsigned int width,unsigned int height,TextureFormat format)=0;
			virtual unsigned int GetWidth()=0;
			virtual unsigned int GetHeight()=0;
		};

		MGE_API IVideoDevice* CreateVideoDevice();
	}

	namespace audio
	{
		class ISound : public core::Interface
		{
		protected:
			~ISound(){};
		public:
			virtual ISound* Copy()=0;
			virtual void Play(bool loop=false)=0;
			virtual void Stop()=0;
			virtual void SetVolume(float volume)=0;
			virtual float GetVolume()=0;
			virtual void SetPitch(float pitch)=0;
			virtual float GetPitch()=0;
			virtual void SetPlayPos(float pos)=0;
			virtual float GetPlayPos()=0;
			virtual float GetLength()=0;
			virtual void SetPosition(math::Vector3D& v)=0;
			virtual math::Vector3D GetPosition()=0;
			virtual bool IsPlaying()=0;
			virtual void Pause()=0;
			virtual void Resume()=0;
		};

		class IMusic : public core::Interface
		{
		protected:
			~IMusic(){};
		public:
			virtual void Play(bool loop=false)=0;
			virtual void Stop()=0;
			virtual void SetVolume(float volume)=0;
			virtual float GetVolume()=0;
			virtual void SetPlayPos(float pos)=0;
			virtual float GetPlayPos()=0;
			virtual float GetLength()=0;
			virtual bool IsPlaying()=0;
			virtual void Pause()=0;
			virtual void Resume()=0;
		};

		class IAudioDevice : public core::Interface
		{
		protected:
			~IAudioDevice(){};
		public:
			virtual void LookAt(math::Vector3D& eye,math::Vector3D& at,math::Vector3D& up)=0;
			virtual void GetLookAt(math::Vector3D* eye,math::Vector3D* at,math::Vector3D* up)=0;
			virtual ISound* LoadSound(fileio::IFile* file)=0;
			virtual IMusic* LoadMusic(fileio::IFile* file)=0;
			virtual void SetUnitsPerMeter(float u)=0;
			virtual float GetUnitsPerMeter()=0;
		};

		MGE_API IAudioDevice* CreateAudioDevice();
	}

	namespace input
	{
		enum Key
		{
			Escape=1,		Key1=2,			Key2=3,			Key3=4,			Key4=5,			Key5=6,
			Key6=7,			Key7=8,			Key8=9,			Key9=10,		Key0=11,		Minus=12,
			Equals=13,		BackSpace=14,	Back=14,		Tab=15,			Q=16,			W=17,
			E=18,			R=19,			T=20,			Y=21,			U=22,			I=23,
			O=24,			P=25,			LeftBracket=26,	RightBracket=27,Enter=28,		Return=28,
			LeftControl=29,	A=30,			S=31,			D=32,			F=33,			G=34,
			H=35,			J=36,			K=37,			L=38,			Semicolon=39,	Apostrophe=40,
			Grave=41,		LeftShift=42,	BackSlash=43,	Z=44,			X=45,			C=46,
			V=47,			B=48,			N=49,			M=50,			Comma=51,		Period=52,
			Slash=53,		RightShift=54,	Multiply=55,	LeftAlt=56,		LeftMenu=56,	Space=57,
			Spacebar=57,	Caps=58,		CapsLock=58,	Capital=58,		F1=59,			F2=60,
			F3=61,			F4=62,			F5=63,			F6=64,			F7=65,			F8=66,
			F9=67,			F10=68,			NumLock=69,		ScrollLock=70,	Num7=71,		Num8=72,
			Num9=73,		Subtract=74,	Num4=75,		Num5=76,		Num6=77,		Add=78,
			Num1=79,		Num2=80,		Num3=81,		Num0=82,		Decimal=83,		OEM102=86,
			F11=87,			F12=88,			F13=100,		F14=101,		F15=102,		Kana=112,
			ABNTC1=115,		Convert=121,	NoConvert=123,	Yen=125,		ABNTC2=126,		NumEquals=141,
			PrevTrack=144,	Circumflex=144,	At=145,			Colon=146,		Underline=147,	Kanji=148,
			Stop=149,		Ax=150,			Unlabeled=151,	NextTrack=153,	NumEnter=156,	RightControl=157,
			Mute=160,		Calculator=161,	Play=162,		PlayPause=162,	MediaPause=162,	MediaPlay=162,
			MediaStop=163,	VolumeDown=174,	VolumeUp=176,	WebHome=178,	NumComma=179,	Divide=181,
			PrintScreen=183,SysRequest=183,	RightAlt=184,	RightMenu=184,	Pause=197,		Break=197,
			Home=199,		Up=200,			PageUp=201,		Prior=201,		Left=203,		Right=205,
			End=207,		Down=208,		PageDown=209,	Next=209,		Insert=210,		Delete=211,
			LeftWindows=219,RightWindows=220,Application=221,Power=222,		Sleep=223,		Wake=227,
			WebSearch=229,	WebFavorites=230,WebRefresh=231,WebStop=232,	WebForward=233,	WebBack=234,
			MyComputer=235,	Mail=236,		MediaSelect=237 
		};

		enum DeviceType
		{
			Keyboard,
			Mouse,
			Joystick
		};

		struct Effect
		{
			float attacktime;
			float attack;
			float fadetime;
			float fade;
			float time;
			float magnitude;
		};

		struct InputDeviceInfo
		{
			unsigned int nbuttons;
			unsigned int naxis;
			unsigned int npovs;
			DeviceType type;
			bool forcefeedback;
			core::ID id;
			char* name;
		};

		class IInputDevice : public core::Interface
		{
		protected:
			~IInputDevice(){};
		public:
			virtual InputDeviceInfo GetInfo()=0;
			virtual float GetAxisPos(unsigned int axis)=0;
			virtual bool ButtonDown(unsigned int button)=0;
			virtual float GetPovPos(unsigned int pov)=0;
			virtual void PlayEffect(const Effect& effect)=0;
			virtual void StopAllEffects()=0;
		};

		MGE_API unsigned int GetNDevices();
		MGE_API InputDeviceInfo GetDeviceInfo(unsigned int device);
		MGE_API IInputDevice* GetDevice(char* name,core::ID id);
	}

	namespace network
	{
		enum SysMessage
		{
			Connected=-1,
			Disconnected=-2
		};

		struct Message
		{
			int message;
			unsigned int from;
			void* data;
			unsigned int size;
		};

		class IClient : public core::Interface
		{
		protected:
			~IClient(){};
		public:
			virtual bool Connect(char* address,unsigned short port)=0;
			virtual void Disconnect()=0;
			virtual void Send(int message,void* data,unsigned int size)=0;
			virtual bool GetNextMessage(Message& message)=0;
		};

		class IServer : public core::Interface
		{
		protected:
			~IServer(){};
		public:
			virtual bool Start(unsigned short port)=0;
			virtual void Stop()=0;
			virtual void Disconnect(unsigned int id)=0;
			virtual void Broadcast(int message,void* data,unsigned int size)=0;
			virtual void SendTo(unsigned int to,int message,void* data,unsigned int size)=0;
			virtual bool GetNextMessage(Message& message)=0;
		};

		MGE_API IClient* CreateClient();
		MGE_API IServer* CreateServer();
	}

	namespace scene
	{
		class INodeData : public core::Interface
		{
		protected:
			~INodeData(){};
		public:
			virtual bool GetVector(char* name,math::Vector3D& v)=0;
			virtual void SetVector(char* name,math::Vector3D& v)=0;
		};

		MGE_API INodeData* CreateNodeData();

		class ISceneNode;

		class IScene : public core::Interface
		{
			ISceneNode** m_nodes;
			unsigned int m_nnodes;
		protected:
			MGE_API ~IScene();
			MGE_API IScene();
		public:
			MGE_API virtual void Render(video::IVideoDevice* device);
			MGE_API virtual unsigned int AddSceneNode(ISceneNode* node);
			MGE_API virtual void RemoveSceneNode(ISceneNode* node);
		};

		MGE_API IScene* CreateScene();

		enum RenderTime
		{
			DontRender,
			Pre,
			Normal,
			Post
		};

		class ISceneNode : public IScene
		{
		private:
			INodeData* m_nodedata;
			math::Vector3D m_pos;
			math::Vector3D m_direction;
			math::Vector3D m_up;
			float m_scale;
		protected:
			MGE_API ~ISceneNode();
			MGE_API ISceneNode();
		public:
			MGE_API INodeData* GetNodeData();
			MGE_API void SetNodeData(INodeData* data);
			virtual RenderTime PreRender(video::IVideoDevice* device)=0;
			virtual void Render(video::IVideoDevice* device)=0;
			virtual void PostRender(video::IVideoDevice* device)=0;
			MGE_API math::Vector3D GetPos();
			MGE_API void SetPos(math::Vector3D& pos);
			MGE_API math::Vector3D GetDirection();
			MGE_API void SetDirection(math::Vector3D& direction);
			MGE_API math::Vector3D GetUp();
			MGE_API void SetUp(math::Vector3D& up);
			MGE_API float GetScale();
			MGE_API void SetScale(float scale);
		};
	}
}

#endif

Share this post


Link to post
Share on other sites
Advertisement
Well I read quickly through the various declarations and it seems modular enough. Each class appears to be reasonably specific. But without an explanation of your system it is impossible to comment further.

Share this post


Link to post
Share on other sites
If I had one complaint I'd say that it's overly complex. For example, why do you define your own math functions? Those functions are part of the standard c library. I don't know if you're using DirectX or not, but I'm pretty sure the matrix functions are available in that API, too. In my opinion, an engine should enable the programmer to write games at a higher level than the API. Instead of giving the programmer a more organized interface to their matrix functions, try to eliminate the necessity for the programmer to worry about matrices at all.

Just a style thing:
float m_00;float m_01;float m_02;float m_03;
Is harder to read than:
float m_00, m_01, m_02, m_03;


Btw: your "SetUp" method is easily confused with the word Setup. Maybe changing it to "SetUpVector" or something would help make it less ambiguous? Just a though. Not a very important one at that.

Share this post


Link to post
Share on other sites
Quote:
Original post by smr
If I had one complaint I'd say that it's overly complex. For example, why do you define your own math functions? Those functions are part of the standard c library. I don't know if you're using directx or not, but I'm pretty sure the matrix functions are available there, too. In my opinion, an engine should enable the programmer to write games at a higher level. Instead of giving the programmer a more organized interface to their matrix functions, try to eliminate the necessity for the programmer to worry about matrices at all.


i was going to make the engine do all the collision detection but the i found a problem

i dont know why i defined the math functions (i think it was because i didnt want to type include math every where)
the matrics are there for portablity

Share this post


Link to post
Share on other sites
Quote:
Original post by mike25025
(i think it was because i didnt want to type include math every where)


Such is life. Just include math. It's better that way. It's less code for you to maintain. Less code is better.

Besides, that's what header files are there for.

And another thing, you probably typed more this way. You'd have to type #include <math.h> many, many, many times to amount to the same number of characters as all that stuff you typed.

Share this post


Link to post
Share on other sites
Quote:
Original post by mike25025
can u give me a list of things to include in my explanation
i have no idea where to begin


Well you could run through what someone would need to do to create a simple application using your engine.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kuladus
Quote:
Original post by mike25025
can u give me a list of things to include in my explanation
i have no idea where to begin


Well you could run through what someone would need to do to create a simple application using your engine.


what do u meen by simple?

and the engine isnt compleat yet because of the problem i found

so should i do?

decribe what i havent implmented yet and explane what the problem is or should i explain the engine in its current state?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!