Jelly Donut Man Posted February 5, 2003 Posted February 5, 2003 (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 February 6, 2003 by Jelly Donut Man Quote
shouzama Posted February 5, 2003 Posted February 5, 2003 (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 February 5, 2003 by shouzama Quote
Jelly Donut Man Posted February 5, 2003 Author Posted February 5, 2003 (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 February 6, 2003 by Jelly Donut Man Quote
*Experts* Nerseus Posted February 5, 2003 *Experts* Posted February 5, 2003 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 Quote "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
Jelly Donut Man Posted February 6, 2003 Author Posted February 6, 2003 (edited) // Create class 2, passing in the device Class2 c = new Class2(dev); How exactly is that in VB.NET, doesn't seem to work quite the same. Edited February 6, 2003 by Jelly Donut Man Quote
*Experts* Nerseus Posted February 6, 2003 *Experts* Posted February 6, 2003 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 Quote "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
Jelly Donut Man Posted February 6, 2003 Author Posted February 6, 2003 (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 February 6, 2003 by Jelly Donut Man Quote
*Experts* Nerseus Posted February 6, 2003 *Experts* Posted February 6, 2003 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 Quote "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
Jelly Donut Man Posted February 6, 2003 Author Posted February 6, 2003 Hehe, not bad for a C# guy. I put it in a sample DLL to test it out 100% on the money it seems :) Thanks man. Quote
*Experts* Nerseus Posted February 7, 2003 *Experts* Posted February 7, 2003 *whew* again :) -nerseus Quote "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
Jelly Donut Man Posted February 8, 2003 Author Posted February 8, 2003 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. Quote
shouzama Posted February 18, 2003 Posted February 18, 2003 Sorry, I can't understand your problem. The correct syntax is: Dim c2 as New Class2(mDev) or Dim c2 as Class2 = New Class2(mDev) So, what's wrong? Quote
Jelly Donut Man Posted February 20, 2003 Author Posted February 20, 2003 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.