Archived

This topic is now archived and is closed to further replies.

elis-cool

Engine organization...

Recommended Posts

elis-cool    271
I am not really too sure as to what to put in my engine, what not to, how it should go etc... heres what I have so far, for the interface, keep in mind I only started learning D3D about 2 days ago, and am in the process of putting together a 2D in D3D engine to port my current DDraw game over too... (this is going to be a generic engine BTW):
    
class CMust_Find_Engine_Name
{
public:
	CMust_Find_Engine_Name();

	bool InitD3D(HWND hwnd, int width, int height, bool fullscreen);
	void Shutdown();

	void BeginFrame();
	void EndFrame();

	void LogInit();
	void Log(const char *Text, int SetFlag = 1);
	void Log(int Number, int SetFlag = 1);


private:
	struct CVertex
	{
		FLOAT x, y, z;
		DWORD color;
		FLOAT u, v;
	};

	IDirect3D8 *pd3d;
	IDirect3DDevice8 *pd3dDevice;
	IDirect3DVertexBuffer8 *pVertexB;
	CVertex* pVertices;
};
    
As you can see, I am still to find a name for it But I havent got to handling sprites etc yet... I have some idea how this will work... and im not sure as to the log functions and stuff, any help/thoery etc would be helpful... (BTW, im thinking of converting the log functions over to a VA list... as thats a bit messy up there ) [EDIT] Probly sounds like I put a little too much emphisis on the logging part, its not really that, just like overall, what functions should I have, what does each do etc, so how should it all be split up etc... [/EDIT] CEO Plunder Studios [edited by - elis-cool on June 10, 2002 7:22:23 AM]

Share this post


Link to post
Share on other sites
VisualB4BigD    122
Well what I do in my 2D engine, is I have these functions:

Init : Sets up engine
CreateTexture : Excepts Filename, Returns Texture Number
CreateSprite : Fills in sprite structure, then adds it to collection
DrawSprite : Excepts Texture Number and Sprite Structure
SetBackground : Excepts Filename to Background
DrawBackground : Draws background set by "SetBackground"
Clear : Clears backbuffer
FPS : Returns Frames Per Second
GetKey : Excepts Key from list, Returns Boolean of key state (Down or Up)
GetMouseX : Returns Mouse X Position
GetMouseY : Returns Mouse Y Position
SetFont : Sets the font for the plot text function
PlotText : Excepts String of text, and Color
Present : Swaps buffer and screen. Displays everything in buffer
Done : Releases engine and shuts it down

I hope this helped you. Send me a demo once your finished if you can. Good Luck.

Horny Farmer (Jolly Rancher)

Share this post


Link to post
Share on other sites
elis-cool    271
Well at the moment my DDraw "engine" is pretty good, it has an excellent font engine I made, I dont want to use the inbuilt one(in d3d) as mine is probly faster, and allows you to have picture text etc, it has a console etc, but these are sort of just added into the game and is not really made super generic enough for an engine, so in this new d3d one, im just not sure wheter to add my console, font engine etc into this interface or create their own etc...

a little info:
so far beginFrame() clears the buffer and calls BegineScene() and EndFrame() calls EndScene() and present() etc...

An FPS counter is a good idea, hadn''t really thought about it...

For sprites im thinking of something like:
CreateSprite(char* filename) // loads texture and adds sprite to a linked list...
DrawSprite(RECT source, RECT dest, char* filename) // similer to blt(), searchs list and draws sprite... maybe VisualB4BigD''s way is a little better... hmmn... but I dont think the background deserves its own function...

CEO Plunder Studios

Share this post


Link to post
Share on other sites
VisualB4BigD    122
Using the background functions keeps things clearer. I don''t like to use a sprite as a background. I use packages in my engine and game. I open my level editor and insert or delete sprites and backgrounds from my package. Then I can save it all into one large file to be used in making my levels. So then my engine opens both the package file and the map file. Then loads sprites from the package and puts them where they need to be in the level.

Horny Farmer (Jolly Rancher)

Share this post


Link to post
Share on other sites