Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)
I'm trying to set up separate classes to handle different parts of the engine, but I'm having a problem trying to initialize the things with out the Device that I'm using with the rest of Direct3D. I don't want to set the device as public so that it shows up in the application using the engine. I've seen other engines achieve this not sure of how they did but they have multiple classes and everything runs smooth. Edited by Jelly Donut Man
Posted (edited)

I think you should do the main initialization method only in one class (the CMain class, for example).

Passing the Device to other classes can be achieved by using "creation" method inside this CMain class:

Let's suppose you have these 4 classes -

1. CMain

2. COne

3. CTwo

4. CThree

 

2,3,4 all have a creator method that requires passing of the Device by reference.

 

So, in CMain, you define

createOne() as COne

createTwo() as CTwo

createThree() as CThree

and in these methods you create an object of desided class by passing the Device by ref.

Edited by shouzama
Posted (edited)
and in these methods you create an object of desided class by passing the Device by ref.

 

How do I go about this .. It's probably easy but I'm not seeing how to do it.

Edited by Jelly Donut Man
  • *Experts*
Posted

In the constructor of your secondary classes you'll want to add the device as an argument. Each class can then keep a reference to the main class's device.

 

For example, this would be your main class that defines the device. It assumes there's a class called Class2 that needs access to the device.

public class mainClass
{
   private Device dev;
   
   public mainClass()
   {
       // This class's constructor, create the device
       dev = new Device(...);

       // Create class 2, passing in the device
       Class2 c = new Class2(dev);
   }
}

 

Here's what Class2 might look like:

public class Class2
{
   private Device myDev;

   public Class2(Device dev)
   {
       this.myDev = dev;
   }
}

 

Now Class2 can use the device wherever it needs it.

 

-nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • *Experts*
Posted

Ah, I think you have to use the New() function in VB.NET. The default constructor takes no params, so you end up with New(). You can change that to New(ByRef dev As Device) I think - not 100% about VB.NET :)

 

-nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted (edited)
Umm.. but wouldn't I call something like that in the Class 2? How am I getting it to the class 2 so I can ref it? Just give me a simple code again in your best VB syntax for each part :) .. Not sure if I get it in the C# way :-\ Edited by Jelly Donut Man
  • *Experts*
Posted

Ok, here goes (may not work exactly right):

Public Class mainClass
  Private device As Device
   
   public Sub New()
       ' This class's constructor, create the device
       device = New Device(...)

       ' Create class 2, passing in the device
       Dim c As Class2 = New Class2(device)
   End Sub
End Class

 

And the second class...

Public Class Class2
   Private myDev As Device
   Public Sub New(ByRef dev As Device)
       Me.myDev = dev
   End Sub

   Private Sub UseDevice()
       'You can use myDev here...
   End Sub
End Class

 

 

-nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • *Experts*
Posted

*whew* again :)

 

-nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

As the syntax of the code is correct. The usage of it within the application that I use the DLL is not working as expected. Say if I were to declare my Class 2 in the application as follows.

Dim Class2 as New Class2

It is telling me that I need to pass it the device right there when I declare it as New. This is what it is asking me for.

Dim Class2 as New Class2(Device)

I thought that making the MainClass do

Dim c As Class2 = New Class2(device)

Would pass it the device ..... :-\ I'm not sure whats going on here.

  • 2 weeks later...
Posted
Well, I'm trying to pass my device and create it with in the .dll, and when I try to make the engine, and something else using the device from the engine, it wants me to pass it the device from the application that is using the engine. At least the way Nerseus is showing me.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...