[Unsolved] Converting C# Tutorial to VB.NET [Multiplayer?]

LennardF

27-04-2006 08:14:22

Hello again,
Sorry for asking that much, but i need a little hand.

I've followed this tutorial: http://www.ogre3d.org/wiki/index.php/Og ... rld_Part_1 because it looks so nice, i already converted the full code, only my structure isnt right, so i'dd like to ask, if someone could convert this code to VB.NET For me... you dont have to do it all, just tell me what kind of file this is (module or class), what class HelloWorldApp : IDisposable means, what the heck
//Constructor
HelloWorldApp()
{
}

and
~HelloWorldApp()
{
Dispose();
}

is.
How i make a protected sub in a module/class.
How i make a boolean sub.
And if this is Sub Main
static void Main(string[] args)
{
}

this is the full code, feel free to convert, i'dd want to know the structure... is it like a module and class in one?

using System;
using System.IO;
using System.Drawing;
using Math3D;
using OgreDotNet;

namespace OgreDotNetTutorial
{
class HelloWorldApp : IDisposable
{
//Declare & pre-initialize the required elements
public Root mRoot = null;
public RenderWindow mRenderWindow = null;
public SceneManager mSceneManager = null;
public Camera mCamera = null;
public Viewport mViewport = null;
public OgreDotNet.EventHandler mEventHandler = null;
public bool mDone = false;

//Constructor
HelloWorldApp()
{
}

public void Dispose()
{
}

~HelloWorldApp()
{
Dispose();
}

protected void SetupResources(string sFileName)
{
}

public void Start()
{
}

protected bool FrameStarted(FrameEvent e)
{
return false;
}

protected bool FrameEnded(FrameEvent e)
{
return false;
}

protected void KeyClicked(KeyEvent e)
{
}

static void Main(string[] args)
{
}
}
}


Help Much appreciated.

Best Regards,
Lennard Fonteijn

EagleEye

27-04-2006 08:39:25

There are a few nifty utilities out there that convert C# to VB.NET, and the same in reverse... Do a google search for "Convert vb.net c#" and you're likely to find a few.

Let me just convert the code you have here...


Imports System
Imports System.IO
Imports System.Drawing
Imports Math3D
Imports OgreDotNet

Namespace OgreDotNetTutorial
Class HelloWorldApp
Inherits IDisposable

'Declare & pre-initialize the required elements
Public mRoot As Root = Nothing

Public mRenderWindow As RenderWindow = Nothing

Public mSceneManager As SceneManager = Nothing

Public mCamera As Camera = Nothing

Public mViewport As Viewport = Nothing

Public mEventHandler As OgreDotNet.EventHandler = Nothing

Public mDone As Boolean = false

'Constructor
Private Sub New()
MyBase.New

End Sub

Private Sub New()
MyBase.New
Dispose
End Sub

Public Sub Dispose()

End Sub

Protected Sub SetupResources(ByVal sFileName As String)

End Sub

Public Sub Start()

End Sub

Protected Function FrameStarted(ByVal e As FrameEvent) As Boolean
Return false
End Function

Protected Function FrameEnded(ByVal e As FrameEvent) As Boolean
Return false
End Function

Protected Sub KeyClicked(ByVal e As KeyEvent)

End Sub

Private Shared Sub Main(ByVal args() As String)

End Sub
End Class
End Namespace


I did that using the page at http://www.carlosag.net/Tools/CodeTrans ... fault.aspx

There are quite a few more out there.

Incidentally, I tried using the CSharpToVB converter that I have downloaded on my system, and it gave me errors.

also, you don't want to return "false" from the frame events, as that will terminate Ogre... that's Ogre's indication to quit the program. :)

LennardF

27-04-2006 10:08:18

Thanks a Million!!!

To be honest, i though it was C++, cause i alsop tried a C# to VB.NET converter, but it already gave me error's on the using defenitions (imports in VB.NET).

Thanks for that converter.
And thank you for converting it and warning me about the frame events.

Best Regards,
Lennard Fonteijn

LennardF

27-04-2006 10:10:52

Only one thing, how can it i have 2 Sub New()??? Im at school now, and as far ass i known, you cant have 2 excact named subs :S

'Constructor
Private Sub New()
MyBase.New

End Sub

Private Sub New()
MyBase.New
Dispose
End Sub


Please verify

EagleEye

27-04-2006 16:46:04

You can't have both... remove one.

LennardF

27-04-2006 20:19:50

Ok, i almost fully converted it to VB.NET, of what i got now, it loads the Options window and starts the renderingwindow (with it's Hello World title). But now, i have a problem, when i run the renderingwindow, i get the fullscreen black window, but immediatly after it, i get a Runtime Error (App requested the Runtime in to close the app in unusual way).

How do i fix this. This my converted code, the lines that are commented, aren't converted yet, and i need soem help with those, but as far as i see, those blankedout lines arent the source of this error.


This is a class file:
Imports System
Imports System.IO
Imports System.Drawing
'Imports System.Collections.Generic
Imports Math3D
Imports OgreDotNet

Namespace OgreDotNetTutorial
Class HelloWorldApp
'Inherits IDisposable

'Declare & pre-initialize the required elements
Public mRoot As Root = Nothing
Public mRenderWindow As RenderWindow = Nothing
Public mSceneManager As SceneManager = Nothing
Public mCamera As Camera = Nothing
Public mViewport As Viewport = Nothing
Public mEventHandler As OgreDotNet.EventHandler = Nothing
Public mDone As Boolean = False

'Constructor
Public Sub New()
MyBase.New()

'Create the Root object
mRoot = New Root

'Setup OGRE resources
SetupResources("resources.cfg")

'Show the config Dialog
If mRoot.ShowConfigDialog = False Then
mRoot.Dispose()
Return
End If

'Initialize the RenderWindow
mRenderWindow = mRoot.Initialise(True, "[Tutorial 1] Hello World!")

'Initialize the SceneManager
mSceneManager = mRoot.CreateSceneManager(SceneType.Generic, "HelloOgreDontNetSceneManager")
mSceneManager.SetAmbientLight(Color.White)

'Initialize the Camera
mCamera = mSceneManager.CreateCamera("HelloCamera")
mCamera.SetPosition(0, 0, -200)
mCamera.LookAt = New Vector3(0, 0, 0)
mCamera.NearClipDistance = 5

'Initialize the Viewport
mViewport = mRenderWindow.AddViewport(mCamera)
mViewport.BackgroundColor = Color.Black
mCamera.AspectRatio = mViewport.ActualWidth / mViewport.ActualHeight

'Do some "manager" setup.
ResourceGroupManager.getSingleton().initialiseAllResourceGroups()
MaterialManager.Instance.SetDefaultTextureFiltering(TextureFilterOptions.TfoBilinear)
'MaterialManager.Instance.SetDefaultAnisotropy(1)
'TextureManager.Instance.SetDefaultNumMipmaps(5)

'Create and Setup the event handler
mEventHandler = New OgreDotNet.EventHandler(mRoot, mRenderWindow)
mEventHandler.SubscribeEvents()
'mEventHandler.FrameStarted += new FrameEventDelegate(FrameStarted);
'mEventHandler.FrameEnded += new FrameEventDelegate(FrameEnded);
'mEventHandler.KeyClicked += new KeyEventDelegate(KeyClicked);

'Create the Scene
Dim ent As Entity
Dim node As SceneNode

ent = mSceneManager.CreateEntity("Robot", "robot.mesh")
node = mSceneManager.GetRootSceneNode().CreateChildSceneNode("RobotNode")
node.AttachObject(ent)
node.SetPosition(0, 0, 0)
End Sub

Public Sub Dispose()
mRoot.Dispose()
End Sub

Protected Sub SetupResources(ByVal sFileName As String)
'//Initialiser.SetupResources(sFileName);
Dim sr As StreamReader = New StreamReader(sFileName)
Dim secName As String = "", sLocType, sarchName
Dim line As String
While line = sr.ReadLine = Not Nothing
Dim x As Integer = line.IndexOf("#")
If x > -1 Then
line = line.Substring(0, x)
line = line.Trim
If line.Length > 0 Then
'if (line[0] == '[')
'{
'secName = line.Substring(1, line.Length - 2);
'}
ElseIf secName.Length > 0 Then
x = line.IndexOf("=")
If x <= 0 Then
MsgBox("Invalid line in resource file " + sFileName, MsgBoxStyle.OKOnly, "Exception!")
sLocType = line.Substring(0, x)
sarchName = line.Substring(x + 1)
ResourceGroupManager.getSingleton.addResourceLocation(sarchName, sLocType, secName)
End If
End If
End If
End While
End Sub

Public Sub Start()
mRoot.StartRendering()
End Sub

Protected Function FrameStarted(ByVal e As FrameEvent) As Boolean
If mRenderWindow.Closed = False And mDone = False Then
Return True
End If
End Function

Protected Function FrameEnded(ByVal e As FrameEvent) As Boolean
Return True
End Function

Protected Sub KeyClicked(ByVal e As KeyEvent)
Select Case e.KeyCode
Case KeyCode.Escape
mDone = True
End Select
End Sub

End Class
End Namespace


This is a module:
Module Module1
Sub Main(ByVal args() As String)
Dim app As _Tutorial_1__Hello_World.OgreDotNetTutorial.HelloWorldApp = New _Tutorial_1__Hello_World.OgreDotNetTutorial.HelloWorldApp
app.Start()
End Sub
End Module


Please help me with those couple of commented lines and with the error ofcourse. Also say it if i converted something wrong, or when i delcared something wrong (like im not sure about the defenition of app in the module)

This is the error part in my log file of Ogre, perhaps it could be helpfull to find a solution:

20:50:42: ***************************************
20:50:42: *** D3D9 : Subsystem Initialised OK ***
20:50:42: ***************************************
20:50:42: ResourceBackgroundQueue - threading disabled
20:50:42: Particle Renderer Type 'billboard' registered
20:50:42: An exception has been thrown!

-----------------------------------
Details:
-----------------------------------
Error #: 7
Function: SceneManagerEnumerator::createSceneManager
Description: No factory found for scene manager of type '1'.
File: d:\ogredev\dagon\ogremain\src\ogrescenemanagerenumerator.cpp
Line: 173
Stack unwinding: <<beginning of stack>>
20:50:51: Unregistering ResourceManager for type BspLevel
20:50:51: *-*-* OGRE Shutdown
20:50:51: Unregistering ResourceManager for type Compositor


Best Regards,
Lennard Fonteijn

Ps. By the way... This is quite strange:

File: d:\ogredev\dagon\ogremain\src\ogrescenemanagerenumerator.cpp

I dont have a ogredev\dagon\ogremain... dir on my D:\, cause that's a backup drive which i dont touch.

DigitalCyborg

27-04-2006 23:23:01

im pretty sure that you need FrameStarted and FrameEnded...

you also need to change those to return true.

rastaman

28-04-2006 00:53:51

LennardF:
I think you are getting the CreateSceneManager error because VB is choosing the wrong overloaded function.

Try this line:
mSceneManager = mRoot.CreateSceneManager(Convert.ToUInt32(SceneType.Generic), "HelloOgreDontNetSceneManager")

LennardF

28-04-2006 07:17:19

LennardF:
I think you are getting the CreateSceneManager error because VB is choosing the wrong overloaded function.

Try this line:
mSceneManager = mRoot.CreateSceneManager(Convert.ToUInt32(SceneType.Generic), "HelloOgreDontNetSceneManager")


I get this error while compiling:
C:\Documents and Settings\Eigenaar\Mijn documenten\Visual Studio Projects\[Tutorial 1] Hello World\Class1.vb(42): Overload resolution failed because no accessible 'CreateSceneManager' can be called with these arguments:
'Public Function CreateSceneManager(typeMask As System.UInt16, instanceName As String) As OgreDotNet.SceneManager': Value of type 'System.UInt32' cannot be converted to 'System.UInt16'.
'Public Function CreateSceneManager(typeName As String, instanceName As String) As OgreDotNet.SceneManager': Value of type 'System.UInt32' cannot be converted to 'String'.


EDiT of Above:
I fixed it by making it Convert.ToUInt16(SceneType.Generic), still doesnt get rid of the error!!!
End of edit

and

im pretty sure that you need FrameStarted and FrameEnded...

you also need to change those to return true.

Those already return true...

Edit 2:
Well, the error seriously lies with the scenemanager, because i changed generic to interior, and then i get this error:

Error #: 7
Function: SceneManagerEnumerator::createSceneManager
Description: No factory found for scene manager of type '16'.
File: d:\ogredev\dagon\ogremain\src\ogrescenemanagerenumerator.cpp
Line: 173
Stack unwinding: <<beginning of stack>>


Whyich means, it cannot find the 'factory' for this one, as you see, its also looking at the wrong place :S

anyone knows whats wrong?

rastaman

28-04-2006 16:42:46


Well, the error seriously lies with the scenemanager, because i changed generic to interior, and then i get this error:

Error #: 7
Function: SceneManagerEnumerator::createSceneManager
Description: No factory found for scene manager of type '16'.
File: d:\ogredev\dagon\ogremain\src\ogrescenemanagerenumerator.cpp
Line: 173
Stack unwinding: <<beginning of stack>>


Whyich means, it cannot find the 'factory' for this one, as you see, its also looking at the wrong place :S

anyone knows whats wrong?


how are you running it? from the IDE or running the exe from ogredotnet/bin/debug?
if In the IDE then you need to copy all the .dll .cfg files into your projects/bin/debug. also change resources.cfg so it can find all the media.

I cleaned the code up a bit.

Imports System
Imports System.IO
Imports System.Drawing

Imports Math3D
Imports OgreDotNet


Namespace OgreDotNetTutorial

Module Module1
Sub Main(ByVal args() As String)
Dim app As OgreDotNetTutorial.HelloWorldApp
Try
app = New OgreDotNetTutorial.HelloWorldApp
app.Start()
Catch ex As Exception
Console.WriteLine("## Exception " & ex.Message & vbCrLf & ex.Source)
Finally
Try
app.Dispose()
Catch ex As Exception
Console.WriteLine("## Exception Dispose " & ex.Message & vbCrLf & ex.Source)
End Try
End Try
End Sub
End Module

Class HelloWorldApp
Implements System.IDisposable

'Declare & pre-initialize the required elements
Public mRoot As Root = Nothing
Public mRenderWindow As RenderWindow = Nothing
Public mSceneManager As SceneManager = Nothing
Public mCamera As Camera = Nothing
Public mViewport As Viewport = Nothing
Public mEventHandler As OgreDotNet.EventHandler = Nothing
Public mDone As Boolean = False

'Constructor
Public Sub New()
MyBase.New()

'Create the Root object
mRoot = New Root

'Setup OGRE resources
SetupResources("resources.cfg")

'Show the config Dialog
If mRoot.ShowConfigDialog = False Then
mRoot.Dispose()
Return
End If
'Initialize the RenderWindow
mRenderWindow = mRoot.Initialise(True, "[Tutorial 1] Hello World!")

'Initialize the SceneManager
mSceneManager = mRoot.CreateSceneManager(Convert.ToUInt16(SceneType.Generic), "HelloOgreDontNetSceneManager")

'Initialize the Camera
mCamera = mSceneManager.CreateCamera("HelloCamera")
mCamera.SetPosition(0, 0, -200)
mCamera.LookAt = New Vector3(0, 0, 0)
mCamera.NearClipDistance = 5

'Initialize the Viewport
mViewport = mRenderWindow.AddViewport(mCamera)
mViewport.BackgroundColor = Color.Black
mCamera.AspectRatio = mViewport.ActualWidth / mViewport.ActualHeight

'Do some "manager" setup.
ResourceGroupManager.getSingleton().initialiseAllResourceGroups()
MaterialManager.Instance.SetDefaultTextureFiltering(TextureFilterOptions.TfoBilinear)
MaterialManager.Instance.SetDefaultAnisotropy(Convert.ToUInt32(1))
TextureManager.Instance.SetDefaultNumMipmaps(Convert.ToUInt32(5))

'Create and Setup the event handler
mEventHandler = New OgreDotNet.EventHandler(mRoot, mRenderWindow)
mEventHandler.SubscribeEvents()
AddHandler mEventHandler.FrameStarted, AddressOf Me.FrameStarted
AddHandler mEventHandler.FrameEnded, AddressOf Me.FrameEnded
AddHandler mEventHandler.KeyClicked, AddressOf Me.KeyClicked

'Create the Scene
Dim ent As Entity
Dim node As SceneNode

mSceneManager.SetAmbientLight(Color.White)

ent = mSceneManager.CreateEntity("Robot", "robot.mesh")
node = mSceneManager.GetRootSceneNode().CreateChildSceneNode("RobotNode")
node.AttachObject(ent)
node.SetPosition(0, 0, 0)

End Sub

Public Sub Dispose() Implements System.IDisposable.Dispose
mEventHandler = Nothing
mViewport = Nothing
mCamera = Nothing
mSceneManager = Nothing
mRenderWindow = Nothing
mRoot.Dispose()
End Sub

Protected Sub SetupResources(ByVal sFileName As String)
'//Initialiser.SetupResources(sFileName);
Dim sr As StreamReader = New StreamReader(sFileName)
Dim secName As String = "", sLocType, sarchName
Dim line As String
Do While sr.Peek() >= 0
line = sr.ReadLine
Dim x As Integer = line.IndexOf("#")
If x > -1 Then
line = line.Substring(0, x)
End If
line = line.Trim
If line.Length > 0 Then
If line.Chars(0) = "[" Then
secName = line.Substring(1, line.Length - 2)
ElseIf secName.Length > 0 Then
x = line.IndexOf("=")
If x <= 0 Then
Throw New Exception("Invalid line in resource file " + sFileName)
End If
sLocType = line.Substring(0, x)
sarchName = line.Substring(x + 1)
''Console.WriteLine("-- SetupResources {0}, {1}, {2}", sarchName, sLocType, secName)
ResourceGroupManager.getSingleton.addResourceLocation(sarchName, sLocType, secName)
End If
End If
Loop
End Sub

Public Sub Start()
mRoot.StartRendering()
End Sub

Protected Function FrameStarted(ByVal e As FrameEvent) As Boolean
If mRenderWindow.Closed = False And mDone = False Then
Return True
End If
End Function

Protected Function FrameEnded(ByVal e As FrameEvent) As Boolean
Return True
End Function

Protected Sub KeyClicked(ByVal e As KeyEvent)
Select Case e.KeyCode
Case KeyCode.Escape
mDone = True
End Select
End Sub

End Class
End Namespace

LennardF

28-04-2006 22:20:33

You're my hero :lol:

Thanks for cleaning it up, it works now...

(is it right it only shows a robot, and that i cant move around?)

(This is now the same as ExampleApplication right? Only in vb.net.)

Okay, this is like a standart class which i can use to start up the engine, but how do i load a new scene, once one is already loaded, like switching a level (for example). So how to setup a new scene while one is already loaded along with the engine.

So what do i add to RastaMans magnificant code to let it create a new scene (liek a CreateNewScene() function), shich i can call from the module.

--
I just heard i need to create a game for a school project, i find this a nice chance to learn to use Ogre engine, it's a simple Word War 1 Card game, but there willl be 3d scenes (its like yu-gi-oh).

I'dd like to know some things:

How do you start the game only with a menu (ingame ofcourse)?
After clicking the start button, how do i load a scene with interface then? Perhaps a loadingbar while waiting...

Thats all i need to know, i will create some barbwire, dead trees, army models (german and english) and a heightmap in 3dsmax. I will render that in Ogre along with an interface.

Only one question remains... how do i add things ot a scene thats allrrady loaded? Cause when loading is done and its a players turn, yuo can popup a map to place your cards, after pressign ok, everything happens in the 3d scene (like if you placd a couple of men, men models will appair in the scene).

Another thing, can i use DirectX SDK along with Ogre to extend it? like adding DirectSound and DirectPlay (cause it's a multiplayer game).

Sorry i keep pumping up those questions, i can't help it, i'm just a lonely guy on an adventure :P

Best Regards,
Lennard Fonteijn

DigitalCyborg

29-04-2006 01:47:41

(is it right it only shows a robot, and that i cant move around?)
Yes that's correct. If you don't understand why you can't move the robot or camera, you should probably work through the basic tutorials and the other intermediate tutorials too.

If you look at the main OGRE tutorials, the hello world tutorial is one of the later intermediate tutorials. I should probably move the "Hello World Part 1" to the intermediate section. I might do that later tonight.

Okay, this is like a standart class which i can use to start up the engine, but how do i load a new scene, once one is already loaded, like switching a level (for example). So how to setup a new scene while one is already loaded along with the engine.

No, its "not like a standart [sic] class which you can use to start up the engine" .. You'll want to create a custom framework that suits your application. The "Hello World Part 1" app was only intended to show what components are required to get things up and running.

You can always add and remove Entitys and Scenenodes. Just remove the ones you don't want anymore and create new ones the same way you created the initial ones. One of the intermediate tutorials lets you add entitys. You should really look at it.

How do you start the game only with a menu (ingame ofcourse)?
After clicking the start button, how do i load a scene with interface then? Perhaps a loadingbar while waiting...


There's a tutorial that can help you with this too... "Using CEGUI in OgreDotNet". Basically all the buttons use a callback interface.. you'll need to setup the callback for the "Start button" to load the scene.

I'm not sure about a loading bar though.. Maybe use a 3d line, but I'd be surprised if you really need that (at least in your early development). OGRE seems to load most scenes extremely quickly.


Only one question remains... how do i add things ot a scene thats allrrady loaded? Cause when loading is done and its a players turn, yuo can popup a map to place your cards, after pressign ok, everything happens in the 3d scene (like if you placd a couple of men, men models will appair in the scene).


Look at the intermediate tutorials. They add stuff to an existing scene. They also show how to use multiple scenemanagers, which might be useful for you to use.. maybe keep cards in one scenemanger and 3d dudes in the other.


Another thing, can i use DirectX SDK along with Ogre to extend it? like adding DirectSound and DirectPlay (cause it's a multiplayer game).


I'm looking into DirectInput (because I want a joystick). but, I don't have an answer for you right now. As far as DirectPlay goes, I don't know. I think there are a few other people who are writing custom networking instead.


Well,
I hope that helps. good luck!

DC

LennardF

29-04-2006 13:35:45

OMG!!! that's one of the best and well commented answers i ever had... I wouldnt dair asking more :roll:

But i still do, is there something i can use as a multiplayer addon? Cause, it's a 2 player card game, and if your playing ina split screen or on the same screen, you see eachothers card...

If i get that answered, ill change the title to solved, wen i got a new question, i edit it again (else i need to start up new topics everytime).

Thanks again!!!

Best Regards,
Lennard Fonteijn (really happy now :wink: )

Ps. Can i convert all tutorials to VB.NET and create new VB.NET tutorials in the wiki? That's also handy for other vb.net users (cause they are all now in C#). And may i use your text then to create an excact same tutorial?

Mwr

29-04-2006 13:56:08

I don't know what your level of programming is but from your posts, it seems like you are just starting out so networking programming might be a little bit too advanced for you at this stage. Of course I could be wrong and it could be just OgreDotNet that you are just starting out with.

However I don't know of any high level networking libraries for .net, there are some for c++ etc, but about the highest one I know of for .net is the network library that used to be part of Axiom (not sure if it is still part of it or not), but even that is really a low level one, so you would need to know about sockets etc.

You could have a look at http://www.c-sharpcorner.com/Networking.asp and some of the network programs there, even though they are in c#, you might be able to convert one and maybe adapt it to your needs, to provide basic network features. Maybe one of the chat programs and then just send text messages saying which cards each player has, then the client would decode these messages.

Sorry I can't be more help.

LennardF

29-04-2006 15:28:59

Of course I could be wrong and it could be just OgreDotNet that you are just starting out with.

Yep, you're wrong :twisted: I know VB.NET from more then 80%, but i never did something with extreme API's like Ogre(DotNet), so that's kinda new to me (and hard as you see, but when i get the hang of it, it would go way more smoother).

The 20% i dont understand is networking :P, so i need to learn a bit about that (i never needed to use it before, i create tool apps which are tools to make stuff easier).

But with socket, can i do:
- Let the others client game also place armies, when they are placed with the other player?
- Send a message to the other player, with some options to let's say block an attack.