CEGUI - As object

BlitzMax Forums/Brucey's Modules/CEGUI - As object

Retimer(Posted 2008) [#1]
Any chance of having the wrapper allow the loading of fonts, layouts, etc as objects/pointers as supported by tcetexture instead of limited support via path strings for everything else?
This is probobly more of a task for crazyeddy but perhaps it might be a fairly simple task to add support for within your wrapper?

I can't say enough how awesome this wrapper is for blitzmax, but having all the files in the open, rather then having support for pointers seems both messy and inefficient for distribution.


Brucey(Posted 2008) [#2]
Well, I hadn't managed to get around to looking at better BlitzMax integration yet.

I think I know what you mean. You'd like to be able to use incbin:: and similar ?

I've certainly thought it important with other modules to have that kind of support - like for example, incbin:: support for wxBitmap etc.

Since CEGUI supports the use of "custom" loaders, it's quite possible that one might be able to implement new loaders for this task.


Retimer(Posted 2008) [#3]
Not incbin, but yes similar with the tstreams and tbank objects. I use a custom compressed archive packer/loader for all my apps, so I can include all the media in a single packed 'data' file and use a simple 'loadfilebyname' scheme and the option to protect it, rather then having hundreds of media files all over the place, all I need is my app, and a single package file.

I'm sure others who will end up using cegui with their app will want to do something similar if they are using a large set of fonts and layouts.

Unfortunately I haven't a clue on how to use custom loaders with blitzmax pointers, or objects.


Brucey(Posted 2008) [#4]
Okay... I get it... you want some kind of TStream override on all file access...

Well, it looks possible... I appear to have already created an extendable ResourceProvider... so I guess now I need to see how/where to implement it ;-)

fun... fun...


Retimer(Posted 2008) [#5]
Yeah, like the same object system of 'LoadImage(url:OBJECT)'

I'm still behind on the technical terms =( sorry for being so confusing.


Brucey(Posted 2008) [#6]
Well, that was cool... turns out I've actually implemented all the necessary bits already :-)
(I vaguely remember having thought about this at some previous point...)


Anyhoo... if you update, you'll see a new little example : custom_provider.bmx

When you initialize CEGUI, you can optionally pass in a Resource Provider object. This controls how resources are processed.
The example loads all resources using a TStream. (xml, images, fonts)

Note in unloadRawDataContainer() the call to dataContainer.SetData(Null). Turns out that is very important, as it seems that when CEGUI removes the instance of the container it will attempt to clean any allocated memory, and it assumes it was created with malloc - which isn't always the case. So you need to Nullify it. Not a big deal.


Anyways... I hope that's of some use to you.


Retimer(Posted 2008) [#7]
Anyways... I hope that's of some use to you.


It will be. Thanks a lot Brucey.

Threw a small donation your way. I'm a bit slow on generosity in big portions but it comes in stages. You have continued to help me beyond belief.


Brucey(Posted 2008) [#8]
Thanks very much :-)

You have continued to help me beyond belief.

Nah... I just don't like to see anyone getting stuck with issues while using my modules.
Although, usually I need to work it all out myself first to be able to provide an answer - Language-bindings are just that... doesn't necessarily mean I have any idea what is going on myself ;-)

But we seem to get there in the end.

The thing I like with BlitzMax (still, and I've mentioned it before), is how nice it is to be able to call back and forth between it and c/c++... so that you can do this :
Type CustomResourceProvider Extends TCEResourceProvider

	Method loadRawDataContainer(filename:String, dataContainer:TCERawDataContainer, resourceGroup:String)
		
		DebugLog "Loading file : " + filename
		
		Local stream:TStream = ReadStream(filename)
		
		Local size:Int = stream.Size()
		
		' create some memory - we will free this later
		Local data:Byte Ptr = MemAlloc(size)
		
		stream.ReadBytes(data, size)
		stream.Close()
		
		' Set size and data within container
		dataContainer.SetSize(size)
		dataContainer.SetData(data)
	End Method

	Method unloadRawDataContainer(dataContainer:TCERawDataContainer)
	
		Local data:Byte Ptr = dataContainer.GetDataPtr()
		
		If data Then
			' free our data
			MemFree(data)
			' we also need to Null out the pointer within the container
			dataContainer.SetData(Null)
		End If
	End Method

End Type

and be happy in the knowledge that the framework will look after calling these methods for you. BlitzMax rocks :-)


Retimer(Posted 2008) [#9]
Perfect! That did the trick plenty. Tiny bit of editing and I am able to load the files directly from my media archive by returning the bank buffer from my package type. Everything seems to be working without issue.



BlitzMax rocks :-)


Yes...yes it does. Thanks again brucey


Retimer(Posted 2008) [#10]
Apparently when I load an imageset file...it loads correctly, but unloading it causes some issues, both with destroying the window, or cegui_cleanup()

Upon closing the application, and using cegui_cleanup() I recieve an unhandled exception error in base.bmx:

in Function cegui_cleanup()
bmx_cegui_delete_renderer(cegui_rendererPtr)



Retimer(Posted 2008) [#11]
Ok, more information...

It seems all the files located in the .scheme file wont load correctly through the customresourceprovider. It seems like even though it is passed through it, it loads/unloads in a different way.

Commonwealth-10.font
TaharezLook.imageset
TaharezLook.looknfeel

all located in the TaharezLook.scheme file, and are the only files not working correctly when loaded through my package. All the other fonts, backgrounds, etc files are loading fine.

Edit:

I managed to stop my layouts from using the commonwealth-10.font, so that is no longer an issue, however I still have a problem loading any TaharezLook files properly. Mostly causing errors on shutdown, or not even loading period.


Brucey(Posted 2008) [#12]
Perhaps this line in base.bmx is the problem?

OnEnd cegui_cleanup


If I don't call cegui_cleanup myself at the end of the program, it throws an exception (on my Mac) when the app quits. I'm guessing that some of the internals have already cleaned themselves up at this point - perhaps OnEnd is called too late.

Otherwise, my converted custom_provider example (to use TaharezLook instead), looks to be working fine here.

The big hole is an obvious lack of exception handling on my part - something which I have been going through and applying, but it ain't finished yet. The aim is to have it raise proper bmx exceptions everywhere CEGUI ones are thrown.


Brucey(Posted 2008) [#13]
I've added some more exception handling, as well as a new custom_provider_tz example which uses TaharezLook. Runs fine here. Can you confirm it doesn't work for you?


Retimer(Posted 2009) [#14]
Sorry for late response, been busy transferring a bazillion files, servers, libraries, databased, etc to new dev pc to be able to test this.

I discovered the problem was that I was setting the data from a bank buffer rather than a streams. I suppose that is because you placed support for streams, not banks. I was under the assumption that there wasn't a difference in allocated data from either, but I learn new things every day.

This was the broken code:
Method loadRawDataContainer(filename:String, dataContainer:TCERawDataContainer, resourceGroup:String)
	Local StrippedName:String = StripDir(filename)
	If FileSize(StrippedName) <> - 1 Then
		DebugLog(StrippedName + " found in main directory. Loading file from path")
		Local stream:TStream = ReadStream(StrippedName)
		Local size:Int = stream.Size()
		Local data:Byte Ptr = MemAlloc(size)
	
		stream.ReadBytes(data, size)
		stream.Close()

		dataContainer.SetSize(size)
		dataContainer.SetData(data)
	ElseIf Package.FileExists(StrippedName) <> - 1 Then
		DebugLog (StrippedName + " found in archive...loading from archive...")
		Local Bank:TBank = Package.LoadFileByName(StrippedName)
		dataContainer.setSize(Bank.Size())
		dataContainer.setData(Bank.Buf())
	Else
		RuntimeError(StrippedName + " data file was not found")
	End If
End Method


Changing:
ElseIf Package.FileExists(StrippedName) <> - 1 Then
	DebugLog (StrippedName + " found in archive...loading from archive...")
	Local Bank:TBank = Package.LoadFileByName(StrippedName)
	dataContainer.setSize(Bank.Size())
	dataContainer.setData(Bank.Buf())


to

ElseIf Package.FileExists(StrippedName) <> - 1 Then
	DebugLog (StrippedName + " found in archive...loading from archive...")
	Local Bank:TBank = Package.LoadFileByName(StrippedName)
	Local Stream:TStream = OpenStream(Bank)
	Local Data:Byte Ptr = MemAlloc(Bank.Size())
	Stream.ReadBytes(Data, Bank.Size())
	dataContainer.setSize(Bank.Size())
	dataContainer.setData(Data)


Fixed the problem.

So basically loading the bank through a stream works. A little sloppy but it works and works well.

Thanks for supporting this brucey!

Now, with this I can allow users to override default files to use their own custom layouts and backgrounds :)


Brucey(Posted 2009) [#15]
Local Data:Byte Ptr = MemAlloc(Bank.Size())

And don't forget to free + null this in unloadRawDataContainer()

:-)


Retimer(Posted 2009) [#16]
Yeah that's still there ;) I haven't altered anything with the code you provided on the unload part.