I have created a simple application that loads in an entire level, this code works (I have an EPR class that I created which is not posted as part of this code, it is very in depth and proprietary)
What I am posting is the code of the Main section of the game itself. What my continued problems are, is that I can not seem to get any good performance out of the resulting levels and I have read the threads of others having the same issues, I just wanted to point out by showing this code, that the game loop is extremely simple and forgiving, so I am still questioning why the FPS is dog.
Option Explicit On
Imports System.IO
Module modMain
Private initTown As clsEPR
Private enumINS As IDictionaryEnumerator
Private enumSRC As IDictionaryEnumerator
Private totalINS As Integer
Private iSource As DirectoryInfo
Private townObj As Integer
Private objINS As clsEPR.structINS
Private objSRC As clsEPR.structSRC
Sub Main()
' Initialize tne engine
If Not InitializeDGDK("MyBeautfulLongStuff") Then End
initTown = New clsEPR("scenes\HumanTown\HumanTown.epr")
totalINS = initTown.pINSCount
'Set the display mode
oDBDisplay.SetDisplayMode(800, 600, 16)
oDBDisplay.SetWindowPosition(0, 0)
'initialize our objects
oDBCamera.AutoCamOff()
oDBCamera.SetCameraRange(1, 400)
oDBCamera.PositionCamera(180, 35, 180)
'initialize the town
oDBCore.SyncOff()
initializeTown()
oDBCore.SyncRate(30)
oDBCore.SyncOn()
'Game loop
While oDBP.LoopGDK()
'Control the movement speed of the character
If oDBInput.ControlKey > 0 Then
oDBCamera.ControlCameraUsingArrowKeys(0, 2.0, 2.0)
Else
oDBCamera.ControlCameraUsingArrowKeys(0, 1.0, 1.0)
End If
'Determine if pageup or pagedown is being used
Select Case oDBInput.ScanCode
Case 201
'PageUp Keycode
oDBCamera.PositionCamera(oDBCamera.CameraPositionX, oDBCamera.CameraPositionY + 1.0, oDBCamera.CameraPositionZ)
Case 209
'PageDown Keycode
oDBCamera.PositionCamera(oDBCamera.CameraPositionX, oDBCamera.CameraPositionY - 1.0, oDBCamera.CameraPositionZ)
End Select
' Sync the loop
oDBDisplay.SetWindowTitle("X: " & CStr(oDBCamera.CameraPositionX) & " Y: " & CStr(oDBCamera.CameraPositionY) & " Z: " & CStr(oDBCamera.CameraPositionZ) & " Scan Code: " & oDBInput.ScanCode)
oDBCore.Sync()
End While
End Sub
Sub initializeTown()
townObj = 0
Dim i As Integer
' Deal with the EPR objects
enumINS = initTown.pHashINS.GetEnumerator
enumSRC = initTown.pHashSrc.GetEnumerator
While enumINS.MoveNext()
objINS = enumINS.Value
'Source describes the object basics
'Name, FileName and ID association
While enumSRC.MoveNext
objSRC = enumSRC.Value
If objINS.TED_Id = objSRC.TED_Id Then
iSource = Directory.GetParent(objSRC.TED_Filename)
If File.Exists(iSource.FullName & "\" & objSRC.TED_Name & ".png") Then
oDBImage.LoadImageEx(iSource.FullName & "\" & objSRC.TED_Name & ".png", townObj)
oDBSprite.Sprite(townObj, 1, 13, townObj)
oDBSprite.ShowSprite(townObj)
' throw a sync in to force a screen render of the new sprite
oDBCore.Sync()
If File.Exists(iSource.FullName & "\" & objSRC.TED_Name & "_lmap.x") Then
oDB3D.LoadObject(iSource.FullName & "\" & objSRC.TED_Name & ".x", townObj)
oDB3D.HideObject(townObj)
oDB3D.PositionObject(townObj, objINS.TED_Pos_XYZ.X, objINS.TED_Pos_XYZ.Y, objINS.TED_Pos_XYZ.Z)
oDB3D.RotateObject(townObj, objINS.TED_Rot_XYZ.X, objINS.TED_Rot_XYZ.Y, objINS.TED_Rot_XYZ.Z)
oDBSprite.HideSprite(townObj)
'Deal with loading lightmap files and attaching them to the object
Else
'Object not lightmapped, just load it in
oDB3D.LoadObject(iSource.FullName & "\" & objSRC.TED_Name & ".x", townObj)
oDB3D.HideObject(townObj)
oDB3D.PositionObject(townObj, objINS.TED_Pos_XYZ.X, objINS.TED_Pos_XYZ.Y, objINS.TED_Pos_XYZ.Z)
oDB3D.RotateObject(townObj, objINS.TED_Rot_XYZ.X, objINS.TED_Rot_XYZ.Y, objINS.TED_Rot_XYZ.Z)
oDBSprite.HideSprite(townObj)
End If
' force a sync to refresh the screens sprite clearing
oDBCore.Sync()
End If
townObj += 1
End If
End While
enumSRC.Reset()
End While
enumINS.Reset()
oDBSprite.ShowSprite(townObj - 1)
'reshow the last sprite in the sprite collection
'Finally, walk through all of the objects, deleting the sprites in the collection
'And showing all of the objects we just loaded
For i = 0 To townObj - 1
oDBSprite.DeleteSprite(i)
oDB3D.ShowObject(i)
Next
End Sub
End Module