I'll post it to the code archives when it's complete but just to give you something to look at here it is. This also backs up Michael's statement. A resource manager isn't hard to right. This is simple at the moment. I was just trying to solve the mode switch problem. I'm not sure the resource manager will help with that. What do the pro games written in Blitz do? Does anyone know? Do they destroy then reload ***everything*** on mode change?
; Resource Manager
; Kenneth "Physt" Lemieux
; kenlem@...
; 4/27/2003
; No Rights Reserved
; CONSTANTS
Const RT_MESH=1
Const RT_ANIMMESH=2
Const RT_TEXTURE=3
; TYPES
Type ResourceEntry
Field name$
Field filename$
Field resourceHandle
Field resourceType%
Field flags%
Field x#
Field y#
Field z#
Field yaw#
Field pitch#
Field roll#
End Type
;---------------------------------------------------------------------------------------------
;
; RM_FreeAllResources
;
; Free all currently loaded resources. Used at the End of a program
;
; Params
; None
;
; Returned
; None
;---------------------------------------------------------------------------------------------
Function RM_FreeAllResources()
; free the resource for each entry
RM_UnloadAllResources()
; free all the entries
Delete Each ResourceEntry
End Function
;---------------------------------------------------------------------------------------------
;
; RM_UnloadAllResources
;
; Walks the list of loaded resources and frees each one. The entry in the resourse
; table is not deleted.
;
; Params
; None
;
; Returned
; None
;---------------------------------------------------------------------------------------------
Function RM_UnloadAllResources()
For res.ResourceEntry = Each ResourceEntry
Select (res\resourceType%)
Case RT_MESH
;SavePosistion(res)
FreeEntity(res\resourceHandle)
Case RT_ANIMMESH
;SavePosistion(res)
FreeEntity(res\resourceHandle)
Case RT_TEXTURE
FreeTexture(res\resourceHandle)
End Select
Next
End Function
;---------------------------------------------------------------------------------------------
;
; RM_ReloadAllResources
;
; Walks the resourse table and loads each resource
;
; Params
; None
;
; Returned
; None
;---------------------------------------------------------------------------------------------
Function RM_ReloadAllResources()
For res.ResourceEntry = Each ResourceEntry
res\resourceHandle = RM_LoadResourceFromDisk(res\filename$, res\resourceType%, res\flags%)
;If (res\resourceType = RM_MESH) Or (res\resourceType = RM_ANIMMESH) Then
; RestorePosition(res)
;EndIf
Next
End Function
;---------------------------------------------------------------------------------------------
;
; RM_AddResourceEntry
;
; Loads resource from disk and adds an entry to the resource table
;
; Params
; argFile
;
; Returned
; None
;---------------------------------------------------------------------------------------------
Function RM_LoadResource(argName$, argFilename$, argType%, argFlags%)
resHandle = RM_LoadResourceFromDisk(argFilename$, argType%, argFlags%)
If resHandle <> 0 Then
res.ResourceEntry = New ResourceEntry
res\name$ = argName$
res\filename$ = argFilename$
res\resourceType% = argType%
res\flags% = argFlags%
res\resourceHandle = resHandle
DebugLog "Loading resource: " + argFilename$
Else
DebugLog "Can not load resource: " + argFilename$
End If
Return resHandle
End Function
;---------------------------------------------------------------------------------------------
;
; RM_LoadResourceFromDisk
;
; Loads resource
;
; Params
; argFile
;
; Returned
; handle to resource
;---------------------------------------------------------------------------------------------
Function RM_LoadResourceFromDisk(argFilename$, argType%, argFlags%)
Local resHandle
Select argType%
Case RT_MESH
resHandle = LoadMesh(argFilename$)
Case RT_ANIMMESH
resHandle = LoadAnimMesh(argFilename$)
Case RT_TEXTURE
resHandle = LoadTexture(argFilename$, argFlags%)
Default
End Select
Return resHandle
End Function
;---------------------------------------------------------------------------------------------
;
; RM_FindResourceByName
;
; Loads resource
;
; Params
; argResourceName
;
; Returned
; handle to resource
;---------------------------------------------------------------------------------------------
Function RM_FindResourceByName(argName$)
Local retVal
For res.ResourceEntry = Each ResourceEntry
If (res\name$ = argName$)
retVal = res\resourceHandle
End If
Next
Return retVal
End Function
Function SavePosistion(argRes.ResourceEntry)
entity = argRes\resourceHandle
argRes\x# = EntityX(entity)
argRes\y# = EntityX(entity)
argRes\x# = EntityX(entity)
argRes\roll# = EntityRoll(entity)
argRes\pitch# = EntityPitch(entity)
argRes\yaw# = EntityYaw(entity)
End Function
Function RestorePosition(argRes.ResourceEntry)
entity = argRes\resourceHandle
PositionEntity(entity, argRes\x#, argRes\y#, argRes\x#)
EntityRoll(entity, argRes\roll#)
EntityPitch(entity, argRes\pitch#)
EntityYaw(entity, argRes\yaw#)
End Function
|