Jump to content

FreeEntity()


Marleys Ghost
 Share

Recommended Posts

Models and textures will be freed when they are no longer in use. If they aren't being freed you have another model or material or something in use that has not been freed.

 

 

In my example, I only had one model loaded as well. There is nothing there but the model. If I move the camera to where I see one of the LOD's and then free the model, it is only releasing the current lod, the model reference, and any subsequent lods. The main mesh and any prior lod is not being removed.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

OK. So if I run free on every enitity in a scene there will be nothing left allocated then?

It is possible for the reference to remain in some special situations, like if the model were used in a vegetation layer, but generally yes, this will work.

 

This is one of the many small apps I have used to test this.

 

Download and Extract, you will have two folders LOD and Test Model Large, open LOD and run the LOD.exe, this loads a single model Box.gmf from the LOD\Test Model\ folder which is in the App dir. Hold down the RMB for camera view and move in and out. Box.gmf has 6 LOD's which are basically different colours, now with the App still running, navigate to the Test Model Large folder, in which are 7 .gmf's identically named to those in LOD\Test Model\, which are also cubes only bigger, copy and paste those into the LOD\Test Model\ folder overwriting the files it contains. going back to the App, press the F key to free the Entity, pressing the L key will load the Box again, only using the new files, or it should.

 

The models in the LOD\Test Model\ directory can be reset to the originals by extracting the contents of the Test Model.rar to that directory.

 

 

Source code?

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

 

Source code?

 

 

Nothing special ..

 

 

SuperStrict

Framework leadwerks.engine

Import "D:\Game Development\Leadwerks SDK\BMX\Framework\framework.bmx"

Include "lua-gluefunctions.bmx"

AFilter(4)
TFilter(1)

Graphics(800, 600)

RegisterAbstractPath AppDir
GCSetMode(2)

Global fw:TFramework = TFramework.Create()
If Not fw RuntimeError "Failed to initialize engine."

SetScriptObject("fw", fw)
SetBackgroundColor(Leadwerks.Engine.Vec4(0,0,0,1)) 
SetZoom(1.5)

Global camrotation:TVec3 = Vec3(0,0,0) 
Global mx:Float 
Global my:Float 
Global move:Float
Global strafe:Float

MoveEntity(fw.Main.camera, Vec3(0.0,0.5,20))
camrotation.x = fw.Main.camera.rotation.x
camrotation.y = fw.Main.camera.rotation.y

Global FirstDown:Int = 0

Global Entity:TEntity
Entity = LoadModel("abstract::Box.gmf")
PointEntity(fw.Main.camera,Entity,3,1)

camrotation.x = fw.Main.camera.rotation.x
camrotation.y = fw.Main.camera.rotation.y
'======================================================================
'                              Main Loop
'======================================================================

Repeat
       If KeyHit(KEY_ESCAPE) Exit
       If AppTerminate() Exit

	If KeyHit(KEY_F)
		FreeEntity(Entity)
	EndIf

	If KeyHit(KEY_L) Entity = LoadModel("abstract::Box.gmf")

	If MouseDown(2)
		If FirstDown = 0
		   FirstDown = 1
		   MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2)
		EndIf
		HideMouse()
		Camera()
	Else
		ShowMouse()
		FirstDown = 0
	EndIf

	move = (KeyDown(KEY_W) - KeyDown(KEY_S))
	strafe = (KeyDown(KEY_D) - KeyDown(KEY_A))
	If KeyDown(KEY_LSHIFT) | KeyDown(KEY_RSHIFT)
	move = move * 2.0
	strafe = strafe * 2.0
	EndIf

	MoveEntity(fw.Main.Camera,Leadwerks.Engine.Vec3(strafe/10,0,move/10))

	UpdateFramework() 
	RenderFramework()

	Flip()
Forever
fw.renderer.gbuffer = Null
GCCollect()
End

'======================================================================
'Functions.
'======================================================================

Function Camera()
   mx=Leadwerks.Engine.Curve(MouseX()-GraphicsWidth()/2,mx,6) 
   my=Leadwerks.Engine.Curve(MouseY()-GraphicsHeight()/2,my,6) 
   MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2)
   camrotation.x=camrotation.x+my/10 
   camrotation.y=camrotation.y-mx/10  
   RotateEntity(fw.Main.Camera,camrotation) 
End Function

Function StringToVec2:Leadwerks.Engine.TVec2(text:String, scale:Float = 1.0)
       Local t:Leadwerks.Engine.TVec2 = Leadwerks.Engine.Vec2(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
       EndIf
       Return t
EndFunction

Function StringToVec3:Leadwerks.Engine.TVec3(text:String, scale:Float = 1.0)
       Local t:Leadwerks.Engine.TVec3 = Leadwerks.Engine.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

Function StringToVec4:Leadwerks.Engine.TVec4(text:String, scale:Float = 1.0)
       Local t:Leadwerks.Engine.TVec4 = Leadwerks.Engine.Vec4(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
               If sarr.length > 3 t.w = Float(sarr[3]) * scale
       EndIf
       Return t
EndFunction

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

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Morning Josh, did you want me to add this to the tracker?

 

 

Edit: Have added this to the tracker.

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

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...