Skip to main content
gamedev.net
🔒 Locked

My code structure

Started by Vendayan 3 replies 300+ views
Original Post
Vendayan
Vendayan
I was wondering how I sould go about making an ''application'' class like the kind in the DX common framework that encupsulates the device interface. The encapsulation part would be straightforward enough but how do I make it so that the CMesh objects in there somewhere could access the device that belongs to the class that owns the mesh? In other words how would I make this work...
  

class App
{
  public:
    bool init();
    bool run();

  private:
    IDirect3Device8 myDevice;
    Mesh myMesh;
}

class Mesh
{
  public:
    bool Draw{};
    
  private:
    sVertex Verts[10];
}

bool Mesh::Draw()
{
  // How do I get access to the device here to do my drawing?


  return false; // :(

}

  
thanks ~Vendayan
"Never have a battle of wits with an unarmed man. He will surely attempt to disarm you as well"~Vendayan
Vendayan
Vendayan
Would it be sufficient just to give every mesh object another pointer to the device? But that gets tricky when making it also have a link to its AI for example (although I doubt it would be needed) things like that lead to access violations very easily dont they?

~Vendayan
"Never have a battle of wits with an unarmed man. He will surely attempt to disarm you as well"~Vendayan
spackwad
spackwad
You could set up your mesh object''s draw function
to accept a device object as a parameter. Then
pass the device in from the app as you draw all
of the meshes.

Spack
Vendayan
Vendayan
Isn''t there a more intuitive way of doing it though? I know passing one variable isn''t much of a speed hit but I like to do a little extra work in the beginning to minimize the amount of typing I''ll have to do later once I''m debugging.

Sounds like whinning I know. Perhaps that is the best way, but If there are any other ideas on how this should be done let me know though.

~Vendayan
"Never have a battle of wits with an unarmed man. He will surely attempt to disarm you as well"~Vendayan
intransigent-seal
intransigent-seal
Add a one line function to your App class that returns the Device interface.
Or you could use the friend class thing.

John B
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.