Jump to content
  • Advertisement
Sign in to follow this  
BugSlayer

Device in Managed DX

This topic is 4835 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

It seems to me like no matter what you want to do you need the device all the time. Like with rendering something. So how do you guys do it if you have wrapped up lets say a enemy class, and you want to render it. - Have the device as a member in the class. - Send it as a parameter every time my class needs it. - I have my device global so everyone can use it all the time. At the moment I use the first method here. Is there any big drawbacks doing this? Thanks for evey comment on this subject. - BS -

Share this post


Link to post
Share on other sites
Advertisement
Hi there BugSlayer,
How are you doing?

The Problem
Managing your device.

The Solution
What I normally do is the following , I have managers. One renderer and one entity manager. The renderer handles the rendering of the entities(objects) in my game. So the device isn't made public so that no one can interfere with it. But when I do need it I have made it public through a get method. And passed as a parameter to other classes. Look at the DirectX structure, they do the same, passing the device through a parameter list.

So having managers are a pretty good way to go and just seperating your updating and rendering.. having your renderer do the renderering and the entity manager doing the updating...

I hope this helps
Take care buddy.

Share this post


Link to post
Share on other sites
I am fine thank you..:)


Not 100% sure if I understand what you mean by manager. Are you talking about a class or properties or is this an abstract word for how you handle it?

I can see what you mean by seperating Update and Render. I do that too. But not sure if I do it in the same way. Just to lay out some psudo code here:


class Enemy{

Device m_device;

public Enemy(Device device{
m_device = device;
}

public void Update(){
//Move the guy around and stuff
}

public void Render(){
//Render the guy using the device this object has a reference to
}
}



This is probably what I would have done. Update and rendering is in the same class (but seperated into two functions) and a reference to the device.


PS: Is it your web page in your sig? Do you use your method in any of those samples? Maybe I can download one of them and check out what you mean. Can't belive I have never seen that page before. Looks good.

Thanks
- BS -

Share this post


Link to post
Share on other sites
Hi there BugSlayer :)
Thank you for the kind words about my site, I use the same technique for my samples, but my samples aren't aimed towards a complete engine but more for understanding what the topic at hand is.

The Problem
Managing the device, Revisited.

The Solution
I was talking more in the lines of the following

Class Structure
Renderer (Creates your device/Manages the device)
Methods:
RenderEntities(list of entities);

Entity Manager
Members
list<Entity> entityList; //list of entities
Methods:
UpdateEntities(list of entities);
AddEntity(Entity entity);
RemoveEntity(Entity entity);



So the basic idea I want to bring across is seperate your Rendering from your Updating completely. Your Renderer class should just handle the rendering part of your engine and have nothing to do with managing the entities. Your entitymanager might be used to batch and sort your objects and then send it to the Renderer to be drawn... or your renderer my batch them in a renderlist waiting to be rendered.

I hope this helps a bit buddy.
Take care.

Share this post


Link to post
Share on other sites
Sorry, but I think my might talk a bit over my head here.


So I guess you are kind of talking about a renderin queue or something. That will sort them after texture type, effect file and shader and so on? Or am I totaly losing you now?

But I still can't see what a rendering class is. I have always just had a rendering function inside every class. This function will change states if nessesary and then render it self. Are you saying that it should be a rendering class doing all this work. Pulling info on render states and the like and then pulling vertex and texture info from the object and then render the object (preferably batched and ordered)?

Sorry if I seems dumb to you, but I am pretty new to this.
- BS -

Share this post


Link to post
Share on other sites
Hiya BugSlayer ;)
How are you doing (once again)...

The Problem
Managed device revisited (again..)

The Solution
Buddy, I am totally just giving you my point of view and my preference, it's up to you, how you handle it :)


I was talking along the lines of the Renderer being the class that creates and manages the device. i.e.

The Renderer

class Renderer
{
public:
void CreateDevice(HWND hWnd);
void RenderEntities(list<RenderableEntity*> entityList);
private:
IDirect3DDevice9* pDevice;
}




The EntityManager

class Renderer
{
public:
void Add(Entity* entity);
void Update();
private:
list<Entity*> entityList;
}




So in a simple game you would just create your entity manager object, add some entities to it.... then send the entity manager's entityList to the Renderer which in turn either batches it or the entity manager can do that and then they will get rendered by the renderer.

You will obviously have an Entity class that will have attributes like texture, mesh, matrices... and you add them to your entity manager.

I hope this is a little more clearer.
I hope this helps a bit. Like I said, this might be ugly to some and some people might consider it ok. Take care bud.

Share this post


Link to post
Share on other sites
Ahha...ok, totaly got you know. I can see pros and cons both ways. Guess it ends up beeing taste that desides rather then right or wrong I guess.

Thanks for all your input. Appreciate it.
- BS -

Share this post


Link to post
Share on other sites
Hi BugSlayer,

What I do in my little engine is i created a class called GameEngine that I use to initialize my D3DDevice and all other things i need running before i can start doing any fun graphics stuff. In that class I made the D3DDevice static and just access it like any other static variable, it´s working very nice for me at least.

It looks a little something like this:


public class GameEngine
{
private static Direct3D.Device m_D3DDevice = null;
public static Direct3D.Device Device3D { get { return m_D3DDevice; } }
}

// Now it´s easy access in my model class like this:

public class Model
{
public void Render()
{
GameEngine.Device3D.RenderState.Lighting = false;
}
}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Ahha...yeah, that was a good idea. A cross between a global object and Armadon way of doing it. I like that one.


Thanks
- ØØ -

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!