Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Offline internetfreak  
#1 Posted : Tuesday, October 8, 2013 10:12:04 PM(UTC)
internetfreak

Joined: 12/19/2011(UTC)
Posts: 529

Thanks: 10 times
Was thanked: 16 time(s) in 15 post(s)
As some of you should know, I'm working on my rpg project. For this project, I obviously need my own file formats to store all infos I want. To load/save them, I currently use a own content loading system which works fine as it is inteded. However, as I always want to simplify things, I researched a bit if I can also can use the ContentLoader of Delta to avoid having two systems for loading content (To make it better understandable: Content like maps is loaded with my system while Images, Fonts etc would be loaded with the ContentLoader from DE).
My problem is that I didn't exactly understand how I can use your content loader to extend it with own file formats. Currently, all my content is stored as xml file as I want to be able to edit it without the need of any editor or something else while the system is being built. Later, the content will not be as much editable as now as it should be protected from curios people or people who wants to cheat/mess with the content, whatever they intend with their action.

What I want to know is what I have to do to do the following:
Code:
ContentLoader.Load<MyContentType>(contentName);

Effectively, there should be then some kind of logic defined, how the content is being processed and it should not be public as I only want that content is loadable with the ContentLoader (my system does actually the same, all content from me is loaded via one single class which handles all the stuff and hides the actual loading routine)

I hope it is understandable what I want, because I had some trouble to explain it :)
Mein Blog: www.internetfreak.net

- Inoffizieller DeltaEngine-Supporter und Tutorialschreiber -

Wanna join the discussion?! Login to your forum accountregister a new account. Or Connect via Facebook Twitter Google

Offline Benjamin  
#2 Posted : Wednesday, October 9, 2013 2:06:19 AM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
If your content is just Xml, derive from XmlContent and you get all the functionality for free (there are many examples like Level, Font, InputCommands, etc. they all work like this too). If you want custom content you could use the ContentType.Custom, or let us know with a concrete example how we can improve the system and add any format easily (a simple use case is enough). Thanks.
Offline internetfreak  
#3 Posted : Wednesday, October 9, 2013 11:36:03 AM(UTC)
internetfreak

Joined: 12/19/2011(UTC)
Posts: 529

Thanks: 10 times
Was thanked: 16 time(s) in 15 post(s)
Ok so do I understaqnd it right that the ContentLoader is not really extendable yet? For now, I could easily use XmlContent but since Xml is likely not intended for public use (not sure yet, for not it's xml) in my project, I probably cannot stay forever with Xml.
Using ContentType.Custom could be maybe the solution but I don't know how to implement everything and use it. What I cannot do is to tell you my formats as they are subject to change and I don't want to bother you each time when I change my format (I have some phases where I start changing things which I had a long time simply because I want to improve them)
I think the better solution would be probably to implement a second content system for my custom content although it would be not really good from the view of a user because they have two systems and they have to remember which system does what so this is the case why I asked how I probably could extend the content system of delta
Mein Blog: www.internetfreak.net

- Inoffizieller DeltaEngine-Supporter und Tutorialschreiber -
Offline Benjamin  
#4 Posted : Thursday, October 10, 2013 8:14:40 PM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
Sure it is extensible, but I don't know what you want to do, so I don't know if it can do what you want it to do. Make an example. As I said using Custom or Xml types is the easiest way to extend it, other ways might require more work.
Offline internetfreak  
#5 Posted : Thursday, October 10, 2013 10:14:46 PM(UTC)
internetfreak

Joined: 12/19/2011(UTC)
Posts: 529

Thanks: 10 times
Was thanked: 16 time(s) in 15 post(s)
Well basically I want to load XML for now and later I'm probably switching to binary files to protect the data from curios people.
All I need is only a method where I can load my data then and the way how I can load it with the ContentLoader.
I think it's easy to just load normal files so I don't think that any extra work is required.
Mein Blog: www.internetfreak.net

- Inoffizieller DeltaEngine-Supporter und Tutorialschreiber -
Offline Benjamin  
#6 Posted : Friday, October 11, 2013 5:58:37 PM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
You upload the file by dragging and dropping it into the Editor

If it is an xml file, you load it this way:
var myData = ContentLoader.Load<XmlContent>("MyData").Data;

If it is binary data load it like this:
var myStuff = ContentLoader.Load<MyDataClass>("MyBinaryData");

With this MyDataClass (pretty much autogenerated for you if you press Alt+Enter when creating a class derived from ContentData):

public class MyDataClass : ContentData
{
protected MyDataClass(string contentName)
: base(contentName) {}

protected override void LoadData(Stream fileData)
{
// Use the binary data here somehow
}

protected override void DisposeData() {}
}


Let me know if you need additional help.
Offline internetfreak  
#7 Posted : Friday, October 11, 2013 9:22:56 PM(UTC)
internetfreak

Joined: 12/19/2011(UTC)
Posts: 529

Thanks: 10 times
Was thanked: 16 time(s) in 15 post(s)
Ok, thanks for the example. I also have to add that my xml is custom so I need to manually parse it when loading.
Can I make a derived class and then load the xml data in LoadData or how do I have to proceed then? As said, xml is used for now only during development so I can also manually use the XmlFile class as I do it now but when I'm already using the content loader then I also want to do it right :)
At the end of loading, how do I return my loaded object so the content loader can cache it and give it back to the caller? In your code, I don't see anything which is not marked as void so I cannot return anything
Mein Blog: www.internetfreak.net

- Inoffizieller DeltaEngine-Supporter und Tutorialschreiber -
Offline internetfreak  
#8 Posted : Sunday, October 13, 2013 1:33:15 AM(UTC)
internetfreak

Joined: 12/19/2011(UTC)
Posts: 529

Thanks: 10 times
Was thanked: 16 time(s) in 15 post(s)
Ok, I researched a bit more (thanks to the open source code, this is one of the things I like about delta) and I got the solution by myself.
If I really have understand it right, then I don't have to return anything, the content loader creates an instance of my class and then calls LoadData which then loads the data and populates the object itself.
The only question I now have is how to get the contentLoader to recognize my type for including it in the contentMetaData.xml, because from earlier I more or less know that I received an exception when it encountered an unknown content type. If this question is already cleared or not really mattering, then please excuse my question :D
Mein Blog: www.internetfreak.net

- Inoffizieller DeltaEngine-Supporter und Tutorialschreiber -
Offline Benjamin  
#9 Posted : Monday, October 14, 2013 2:16:47 AM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
You might get a warning in debug mode if the content type is not recognized and the class name does not match the content type. Let me know if this is annoying so I can show you how to turn this warning off (for us it is very useful as we can catch errors early).
Offline internetfreak  
#10 Posted : Monday, October 14, 2013 8:32:46 AM(UTC)
internetfreak

Joined: 12/19/2011(UTC)
Posts: 529

Thanks: 10 times
Was thanked: 16 time(s) in 15 post(s)
I will try the content loader the next time I work on my project, I already modified it so I can implement all necessary things (I got rid of my old ContentFactory since I don't need it anymore and I also simplified my project a bit more)
If I encounter any error/problem, I will let you know
Mein Blog: www.internetfreak.net

- Inoffizieller DeltaEngine-Supporter und Tutorialschreiber -
Offline internetfreak  
#11 Posted : Sunday, November 10, 2013 5:08:32 PM(UTC)
internetfreak

Joined: 12/19/2011(UTC)
Posts: 529

Thanks: 10 times
Was thanked: 16 time(s) in 15 post(s)
It's me again :)
I still cannot figure out how to use own content in the content manager and/or local content as my files always get rejected due to wrong type.
For your information: My files are using an own extension, although they are currently xml internally (as said, the xml content is subject to be changed so I cannot support it directly as I likely convert to binary data in a later step of the development process). Whenever I drag the file into the ContentManager, it says "Unknown Content Type" and when I'm using DiskContentLoader, it throws an UnsupportedContentType Exception when creating the ContentMetaData file.
How can I declare that my type is supported? Isn't it possible to say that every unsupported ContentType is meant to be loaded through the Application?
If it's not yet working that we can load own Content through the ContentLoader, I will have to stay with local content and my own ContentLoading methods.

I really appreciate your help :)
Mein Blog: www.internetfreak.net

- Inoffizieller DeltaEngine-Supporter und Tutorialschreiber -
Offline Flavio Damasco  
#12 Posted : Tuesday, November 12, 2013 2:03:56 PM(UTC)
Flavio Damasco

Joined: 5/15/2013(UTC)
Posts: 45
Location: Hannover

Was thanked: 2 time(s) in 2 post(s)
Hi Internetfreak!
I pass your support request to Steve or some other guy; justbe patient! ;)
UserPostedImage
Offline Benjamin  
#13 Posted : Friday, November 15, 2013 4:34:10 PM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
Not sure why you get this error still, in the v1.0 release the check has been removed. But if you still see it in your source code maybe just remove the check:

Code:

		internal void InternalLoad(Func<ContentData, Stream> getContentDataStream)
		{
#if DEBUG
			if (MetaData.Type != ContentType.JustStore && 
				!GetType().FullName.Contains(MetaData.Type.ToString()))
				throw new DoesNotMatchMetaDataType(this);
#endif
//...


Remove all lines between #if DEBUG and #endif (they should not be used in the release or nuget builds anyway). If this is not your problem, please explain yourself better and give us an exception stacktrace Blink
Offline internetfreak  
#14 Posted : Saturday, November 16, 2013 2:41:58 AM(UTC)
internetfreak

Joined: 12/19/2011(UTC)
Posts: 529

Thanks: 10 times
Was thanked: 16 time(s) in 15 post(s)
Here's the explanation what I'm trying to do:
My custom content files are using an own extension which is currently named .sphx
When I drag the file into the ContentFolder and force the ContentMetaData to regenerate, it throws me an exception because it does not recognize the content type but I also cannot say somewhere that I want to support that type of extension which is basically forcing me then to use some public extensions like .xml or .txt so the ContentLoader can recognize it but I don't want to use any of those extensions.
The ContentManager also rejects the file due to the same reason.
Here's an image displaying the exception:
UserPostedImage

What I'm missing is a simple way to say the ContentLoader that extension .xyz is known so it gets added to the ContentMetaData or that the ContentLoader adds every file dropped to content but unrecognized files are from type JustStore so I can load it (my application will handle the processing then)
The ContentManager should also allow files it doesn't know so such scenarios like my case here is possible.

If I'm misunderstanding things please clear them with me, maybe I only imaging problems?
Mein Blog: www.internetfreak.net

- Inoffizieller DeltaEngine-Supporter und Tutorialschreiber -
Offline Benjamin  
#15 Posted : Saturday, November 16, 2013 12:23:14 PM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
Ohh, you are using the DiskContentLoader, which is parsing the directory and trying to understand each file extension. Obviously he does not know about .sphx files and complains with the exception. There are 2 solutions with the DiskContentLoader:

- Remove the exception throwing and instead just use the JustStore content type for unknown file extensions
- Or manually add the .sphx file as JustStore content in your ContentMetaData.xml

Or use the OnlineDeveloperContentLoader where we can support such features for you on the service side.
Offline internetfreak  
#16 Posted : Saturday, November 16, 2013 12:52:57 PM(UTC)
internetfreak

Joined: 12/19/2011(UTC)
Posts: 529

Thanks: 10 times
Was thanked: 16 time(s) in 15 post(s)
Removing the exception is no solution for me as I stay natural with delta, I don't mod anything and I'm only using offical releases :)
Manually adding the file would be a solution but it's rather uncomfortable.
Is there any way to set a ContentType without editing the ContentMetaData?
Also, I cannot use only the DeveloperOnlineContentLoader (in fact I wanted to use it but because it rejected my file I tried again with the DiskContentLoader so I could maybe work until the OnlineContent works for own files) as I'm also writing an editor and because of the fact that the editor should be able to use whatever resource it got dropped into the folder, I have to use DiskContentLoader for the editor so it can load any content without requiring any online content project. And because we cannot change the ContentLoader during runtime once the app is started, I cannot switch between the different Loaders.

I hope it's somehow understandable otherwise I can explain it again but preferable on german because there I can better say what I want :)
Mein Blog: www.internetfreak.net

- Inoffizieller DeltaEngine-Supporter und Tutorialschreiber -
Offline Benjamin  
#17 Posted : Sunday, November 17, 2013 6:56:15 AM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
We will remove the exception in v1.0 (just removed the check in release mode), so you can do it in your code and remove it later once you update to 1.0.

About the ContentLoader: You can change it and even write your own (e.g. derive from DiskContentLoader and customize it to your needs), just call ContentLoader.Use<YourClass>() before you actually load any content, it will work fine (e.g. before you initialize or run your game).
Offline internetfreak  
#18 Posted : Sunday, November 17, 2013 5:44:13 PM(UTC)
internetfreak

Joined: 12/19/2011(UTC)
Posts: 529

Thanks: 10 times
Was thanked: 16 time(s) in 15 post(s)
Ok, you're right, deriving from DiskContentLoader could help for the editor issue so it can load any file I want.
What about the ContentManager? Do you plan to support specific extensions or will you provide a way to import any content file regardless of the extension? I would be fine if it will be the second one as I will take care of my own files so they can get loaded as it is supposed to get done.

Thanks for the help until now, I will check how I have to modify the ContentLoader so it fits my needs.
Mein Blog: www.internetfreak.net

- Inoffizieller DeltaEngine-Supporter und Tutorialschreiber -
Offline Benjamin  
#19 Posted : Monday, November 18, 2013 2:29:21 AM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
Currently using JustStore content types for all unknown content works just fine. In the future we will support custom content format. In fact we did that already in v0.9.5. However currently all the other content types have to be fully implemented, integrated and tested on all platforms before we continue on supporting external formats.
Offline internetfreak  
#20 Posted : Monday, November 18, 2013 7:43:09 AM(UTC)
internetfreak

Joined: 12/19/2011(UTC)
Posts: 529

Thanks: 10 times
Was thanked: 16 time(s) in 15 post(s)
I thought some more and came to the conclusion that deriving from ContentLoader could be the soultion but the problem behind that is that the user also has to use my own content loader class in order to use my project. Now I have some trouble with organization but I will look what I can do.
How much work do you think is it to just support any extension which is then automatically JustStore? I don't want to mess your plans but if it would be supported then it's very cool. I still can derive the class so you don't have to support it right now if it doesn't fit your plans :)
Mein Blog: www.internetfreak.net

- Inoffizieller DeltaEngine-Supporter und Tutorialschreiber -
Offline Benjamin  
#21 Posted : Monday, November 18, 2013 3:34:18 PM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
As I said it is already supported in the current DE nightly release. Basically you change the last line of ContentTypeIdentifier.ExtensionToType to: return ContentType.JustStore; or just modify the caller to exclude your file type and use JustStore directly there (in a derived ContentLoader). How much work it is to write your own depends on how much things you want to do, DiskContentLoader is not a very complex class anyway, it just has 100 lines.

Maybe it would help if you show concrete code instead of asking iffy questions, then it will be much quicker to help you.
Offline internetfreak  
#22 Posted : Monday, November 18, 2013 6:02:53 PM(UTC)
internetfreak

Joined: 12/19/2011(UTC)
Posts: 529

Thanks: 10 times
Was thanked: 16 time(s) in 15 post(s)
I understand your point and I have to say that my previous post was made quick as I only had a few minutes to write it before I had to go :)
I will check out what I can you and have to do, I don't think that it's too much work to support the case I want for the DiskContentLoader (the contentManager hast to be done through you)
My problem is that I have some thoughts about doing some things as I can say to the user that he has to use class X to use my project but he still can ignore that command and use other things due to the fact that delta allows it, so I have to think about things I want the user to do and not to do :)
For example this topic with the ContentLoader, who says that the user will really use my derived class? He could simply change it or don't use it so it doesn't work as expected.
Maybe I'm thinking too much about this but such questions are always with me when I'm doing something because I always think also of the user as evil person which does never do that what he should ;)
Mein Blog: www.internetfreak.net

- Inoffizieller DeltaEngine-Supporter und Tutorialschreiber -
Offline internetfreak  
#23 Posted : Thursday, December 5, 2013 1:16:12 PM(UTC)
internetfreak

Joined: 12/19/2011(UTC)
Posts: 529

Thanks: 10 times
Was thanked: 16 time(s) in 15 post(s)
Ok, now with v1.0.0.0 it seems that you support now any type of content files which is very nice.
I still have another question: How should I proceed if the content file does not match the given type?
For example: All my content files share an extension so the differences are inside of the files. Now the user wants to load a map but give me a tilesheet, what should I do now since the types does not match? Should I return from loading and return null or should I throw an exception (there's already one there but only active while debugging and also not for files which have the ContentType JustStore)?
Mein Blog: www.internetfreak.net

- Inoffizieller DeltaEngine-Supporter und Tutorialschreiber -
Offline Benjamin  
#24 Posted : Thursday, December 5, 2013 6:22:49 PM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
Actually you can use any number above JustStore the same way, then you can differentiate. Or just use different extensions.

For example:
Code:
var myCrazyExtraContentType = (ContentType)50;
Rss Feed  Atom Feed
Users browsing this topic
OceanSpiders 2.0
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2020, Yet Another Forum.NET
This page was generated in 0.200 seconds.