Jump to content

Can someone please take a look at my code


Cole Chapman
 Share

Recommended Posts

The Problem: When the window is 800,600 using the Scene I want to load, I get about 13 Ave FPS (Not suprised, the Day and Night Settings are way up) What surprises me though is when I maximize the parent window to my full resolution (1920x1080), the FPS stays the same. When I scale it even lower than 800x600, the FPS still does not break 13. I always thought the more space a program/game had to render, the slower the performance (made sense logically)

 

On another note, when I open the scene up in the Leadwerks Editor, I get a solid 30 FPS. Is this due to problems in my code, or does BlitzMax generally operate that slow (assuming Leadwerks Editor was written in C++ or something)

 

Heres the code:

 

SuperStrict


Framework Leadwerks.Engine
Import "Framework.BMX"
Import MaxGUI.MaxGUI
Import MaxGUI.Drivers
Import BRL.EventQueue
Include "lua-gluefunctions.bmx"
RegisterAbstractPath("C:\Leadwerks Engine SDK")
GCSetMode(2)


Global FW:TFramework
Local GEWindow:TGadget
Local GEWindowX:Int 'Null (WINDOW_CENTER)
Local GEWindowY:Int 'Null (WINDOW_CENTER)
Local GEWindowW:Int = 800
Local GEWindowH:Int = 600
Local GEWindowStyle:Int = WINDOW_TITLEBAR|WINDOW_RESIZABLE|WINDOW_MENU|WINDOW_STATUS|WINDOW_CENTER
Local Canvas1:TGadget

Global Scene:TEntity
Global Move:Float
Global Strafe:Float
Global CamRotation:TVec3 = Vec3(0)
Global mx:Float
Global my:Float
Global MouseXInt:Int
Global MouseYInt:Int


GEWindow:TGadget = CreateWindow("GE", GEWindowX, GEWindowY, GEWindowW, GEWindowH, Null, GEWindowStyle)
Canvas1:TGadget = CreateCanvas(0, 0, ClientWidth(GEWindow), ClientHeight(GEWindow), GEWindow)

SetGadgetLayout(Canvas1, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED)
SetGraphics(CanvasGraphics(Canvas1))
ActivateGadget(Canvas1)
EnablePolledInput()


FW:TFramework = CreateFramework()
If Not FW RuntimeError "Failed to Initialize Engine"
SetScriptObject("fw", fw)
Scene:TEntity = LoadScene("abstract::DayNightCycle.sbx")
PositionEntity(fw.Main.camera, StringToVec3(GetEntityKey(scene, "cameraposition")))


Repeat

While PeekEvent()
	WaitEvent()
	Select EventID()
		Case EVENT_WINDOWCLOSE
			End
		Case EVENT_WINDOWSIZE
			SetGraphics CanvasGraphics(Canvas1)
	EndSelect
Wend

CameraUpdate()

If KeyDown(KEY_ESCAPE) Then End

FW.Update()
FW.Render()

SetBlend(1)
DrawText(MouseX(), 0, 10)	
SetBlend(0)	

Flip(0)
Forever

GCCollect()
End


Function CameraUpdate()
If KeyDown(KEY_SPACE)
	mx = MouseX() - GraphicsWidth()/2
	my = MouseY() - GraphicsHeight()/2
	MoveMouse(GraphicsWidth()/2, GraphicsHeight()/2)
	CamRotation.X = CamRotation.X + my
	CamRotation.Y = CamRotation.Y - mx
	RotateEntity(FW.Main.Camera, CamRotation)

	move = KeyDown(KEY_W) - KeyDown(KEY_S)
	strafe = KeyDown(KEY_D) - KeyDown(KEY_A)
	MoveEntity(fw.Main.camera, Vec3(strafe / 10.0, 0, move / 10.0))
EndIf
EndFunction



Function StringToVec3:TVec3(text:String, scale:Float = 1.0)
Local t:TVec3 = Vec3(1)
Local sarr:String[]
sarr = text.split(",")
If sarr
	If sarr.length > 0 t.x = Float(sarr[0]) * scale
	If sarr.length > 1 t.y = Float(sarr[1]) * scale
	If sarr.length > 2 t.z = Float(sarr[2]) * scale
EndIf
Return t
EndFunction

'These functions allow you to pass framework to the lua state'
Function SetScriptObject(name:String, o:Object)
       Local size:Int=GetStackSize()
       lua_pushbmaxobject(luastate.L,o)
       lua_setglobal(luastate.L,name)
       SetStackSize(size)
EndFunction

Function GetStackSize:Int()
       Return lua_gettop(luastate.L)
EndFunction

Function SetStackSize(size:Int)
       Local currentsize:Int=GetStackSize()
       If size<currentsize
       lua_pop(luastate.L, currentsize - size)
       EndIf
EndFunction



Link to comment
Share on other sites

Oh wow, I forgot all about build options. I thought that the exe that BMax built just said .debug and it was the final executable :P Thank you for helping, the FPS cleared right up when I unchecked Debug. and I had no idea the editor was made in Bmax, thats pretty sweet :( Thanks again!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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.

 Share

×
×
  • Create New...