Friday, November 29, 2013

Unity, Localization and oh so much anger...

T.StartPost();

Unity.

So powerful, pretty easy to use and so annoying when something breaks.

For the game we're making in our Integration Projects 3 class, we are making our game in Unity.  The class states that the game has to be localized for English, Dutch, French and German, as well as Win 8  Store ready.

We thought everything was A-OK till this last week when we went to do a Win 8 build (cause the school finally got the tablets for us to test on...) and that's when we found out something that hinges our whole localization code and throws it in the the garbage...

Since our game is going to be using quite a bit of text we decided to spend some time making sure our localization would work flawlessly from the start instead of going back and doing it after (since that seems like a dumb idea anyway...)

So we came up with a system that is basically as follows:

One class - GlobalData -> basically keeps track of what language the game should be in.

Holds an Enum,

 LanguageEnum {English, Nederlands, French, German}  

and an int that is CurrentLanguage which of course keeps track of our language by casting the LanguageEnum to an int and storing it.

Then for each class that will have text in it, we have an xml file with a pretty basic structure that is like this:

 <?xml version="1.0" encoding="utf-8"?>  
 <MainMenu>  
  <Title>  
   <Eng Text="Main Menu"/>  
   <Nl Text="Hoofdmenu"/>  
   <Fr Text="Menu Principal"/>  
   <Ger Text="Hauptmen├╝"/>  
  </Title>  
  <NewGame>  
   <Eng Text="New Game"/>  
   <Nl Text="Nieuw Spel"/>  
   <Fr Text="Nouveaux Jeu"/>  
   <Ger Text="Neues Spiel"/>  
  </NewGame>  
 </MainMenu>  

Then in our class with text we have two things, another Enum that corresponds with the Elements in our xml such as:
 public enum MenuStringKey  
 { Title, NewGame, Controls, Options, Credits, Exit }  

And a public void  LoadStrings(); method which is as follows:

 // Open Xml Document with tranlations.  
     XmlDocument xmlDoc = new XmlDocument();  
     xmlDoc.Load(@"Assets\Localization\MenuText.xml");  
     // Loop over all needed option strings. (By looping over OptionStringKey enums.)  
     foreach (MenuStringKey neededStr in Enum.GetValues(typeof(MenuStringKey)))  
     {  
       // Get all possible translations for the needed string.  
       XmlNodeList languageList = xmlDoc.GetElementsByTagName(neededStr.ToString());  
       // Get needed translation.  
       foreach (XmlNode translations in languageList)  
       {  
         //Get the attribute that goes with the localization.  
         MenuStrings.Add(neededStr, translations.ChildNodes.Item((int)GlobalData.CurrentLanguage).Attributes["Text"].Value);  
       }  
     }  

We store our localized strings in a Dictionary of
 Dictionary<MenuStringKey, string>   

 Or whichever Enum it is.

And whenever we wanted to get the localized string it is just
 MenuStrings[MenuStringKey.Title]  //Gets the corresponding string in whichever language

We had to do our loading with relative paths as for some reason, Resources didn't want to work us before (it does in our new code but it didn't back then...)

This also made another problem we didn't at first notice, because we're referring to the assets/localization folder, we also have to copy that folder structure over to the build else, no text, no working game.

But hey, not a big deal right?

Well, this was working fine for us up till this week, as I said before.  When we went to build for Win 8 app store, we found that XmlDocument and friends are not supported...Great...
 Just GREAT...

So now we have to figure out how to get our xml reading to work again with XDocument which is actually what I wanted to use in the first place but at the time (only a few weeks ago) Unity didn't support which is why we had to use the xmlDocument instead of XDocument and LINQ (which is sooo much nicer)

So after messing around and trying to get used to XDocument and LINQ again, I have finally come up with an actually, even more elegant solution which solves 2 problems for us.

It solves the having to copy over the folder structure as well as our xml loading problems.


So we still have the same setup with the enums and such, the only change I have made is in the GlobalData one by changing it from the original (see above) to
 LanguageEnum {Eng, Nl, Fre, Ger}  
 This makes it so when we use it for LINQ it auto finds the same tag in our XML.

So I changed our LoadStrings to

 var textAsset = (TextAsset)Resources.Load("Localization/MenuText");  
     var doc = new XDocument(XDocument.Parse(textAsset.text));  
     var root = doc.Root;  
     foreach (MenuStringKey neededStr in Enum.GetValues(typeof(MenuStringKey)))  
     {  
       MenuStrings.Add(neededStr,  
         root.Element(neededStr.ToString()).Element(GlobalData.CurrentLanguage.ToString()).FirstAttribute.Value);  
     }  
Now there is a few things I can say about this chunk of code besides it being one foreach instead of 2 and actually one line :P

 var textAsset = (TextAsset)Resources.Load("Localization/MenuText");  

This is using the Resources of Unity.  What is Resources?  It's a folder called Resources inside your Assets folder. It apparently is quite handy for a lot of things not only limited to loading text files and such.

So I moved our localization folder from the Assets into our Resources folder. I kept it in our Localization folder just cause you never know what else we're gonna throw in there (order and stuff...)

So for resource loading of xmls, you don't put the .xml, just the file name and Unity will actually look where you tell it and find the file that matches what you want. I tested because some documentation says you can just say the file name and it will search ALL folders in your resources folder but this seems to not be completely true, so be warned that if you have a sub folder, make sure you are including that folder name in your path as well like above.

The second thing is
 var doc = new XDocument(XDocument.Parse(textAsset.text));</code></pre>  
 Which was actually a pretty annoying thing to get figured out. &nbsp;A lot of online sources say use XDocument.load which doesn't seem to work. I did finally stumble across someone saying doing this current line which made it work correctly.  

Now for our XML structure, we only have the one attribute in our Element which is the text for that language.
 MenuStrings.Add(neededStr,   
      root.Element(neededStr.ToString()).Element(GlobalData.CurrentLanguage.ToString()).FirstAttribute.Value);   
 .  
Since this is inside our ForEach, we check for each Enum that is in MenuStringKey and try to find the element that corresponds with it and then finding the element in that one that corresponds to our CurrentLanguage and then finally the attribute which is the Text="" part
This works quite nicely and actually makes it so we can keep all the other code (so far, I do have to check to make sure it will Build for Win 8 after I get this all re done in the other classes...)for the actual using of our text and such, which is great.

I'll do an edit when I've found out if this will completely fix our build problem.
Thanks for reading and hopefully this has helped someone :D
EDIT:
This code has made it so I was able to make a Win 8 App store build with no problems. Cheers, hope it helps.

 T.Out();


Friday, October 25, 2013

Still got them, problems

T.StartPost();

So it's been awhile yet again since my last post.

Been working on a shader to replicate an old CRT for HLSL shader model 3 for XNA 4.0. There's of course some strange stuff that I didn't know about XNA 4.0, such as if you make a shader that only implements the pixel shader, the spritebatch (which I am using for this shader as it's all post processing) will make a ShaderModel 2.0 vertex shader to pass things through. This wouldn't be a problem if there wasn't s 64 instruction limit on pixel shaders math calculations. A shader I found to base myself on for the start of the scan lines goes over that limit and of course the poster even said, "Fixed it by putting it on shaderModel 3."

Now the problem with that is if you just put your pixel shader on 3.0 and still don't define a vertexShader of 3.0 as well, XNA will give you a compilation error which basically says "Fool, you're trying to mix a VertexShader of ShaderModel 2 with a PixelShader of ShadeModel 3...You duuuumb."

I had to search for a couple different things to finally come across a way of just passing everything through the VertexShader to not affect the outcome of the post processing (if you try to just do something like pass the input position to the output in the vertexShader, it will give you a one color screen instead of what you want.).  Thankfully someone has already done a great service by figuring out a way to make a pass through without affecting the actual image (much, he claims it might make it a bit blurry but I don't really see it)

http://gamedev.sleptlate.org/blog/165-implementing-a-pass-through-3vertex-shader-for-games-without-vertices/

A few lines of code later and you've got a model 3 vertex shader that passes through and doesn't mess with your pixel shader.  So I got that working...And then I found out I needed to actually be working on this for GLSL so here goes nothing (with learning GLSL/OpenGl) and trying to paste some shaders together and check their performance

UNITY PROBLEMS

Something else that has popped up is Unity and XML reading. Now I figured since we're using the C# scripting it would be just regular C# that I could use to read it all in and work with it. I figured hey, I like LINQ and I've gotten quite a bit of experience working with it and XML together in my P90X WoT  project so we'll just use that for our localization and be done with it.

Oh How Wrong Was I. Unity doesn't use a high enough C# version to access XDocument which is what I had done all my previous work with so I had to scour the internet to find a new way to do it and after researching...and, you guess it, PROBLEMS GALORE, I finally have it working.

One of the pages about XML loading and Unity I found was this,
http://unitynoobs.blogspot.be/2011/02/xml-loading-data-from-xml-file.html

Which almost worked for me. Some of the code was needed for me to get it working again but one of the lines that did give me errors no matter what is this one

 Line 29 xmlDoc.LoadXml(GameAsset.text); // load the file.

I found a bunch of things about how when you save XML as UTF-8 it sometimes adds a BOM (Byte Order Mark) which Unity reads as white space. It's supposed to be in there to let things know what the endianess of the code is but Unity just reads it as white space and will actually just say, "NO".  So after probably a literal hour or two searching and trying different solutions all to no avail, I tried something else which I originally didn't know was there....

If you do xmlDoc.Load(GameAsset.text);

It will go without a hitch and load it. Strange but it works and I curse it every time I look at it.

LOCALIZATION PROBLEMS

I'm just starting with localization for the first time and we're going to be developing a text heavy game (dialogues for characters and their actions and progress reports etc. etc.) which has to be localized from English to Dutch, French and German as well...Now that the XML is loading finally we can start on things because we felt that we had to get this in place before we even started developing the game. I feel it's a good thing because if I would have to go back and change all this stuff to load different things based on languages I'd probably rip my hair out and throw myself through a wall..

But anyways, that's all my problems for now.

T.Out();





Sunday, September 1, 2013

Oh long and busy summer...

T.StartPost();

Oh long time no write.

So it's been quite a while since I posted...sorry, but I have been pretty busy as of late.
Since it summer, it is my time to work..as much as possible. This summer I'm being a pipeliner in the oil and gas industry (yeah, makes sense right and isn't a complete and polar opposite of what I go to school for right?) which is a definite go go go job most of the time, 12 hour shifts for 21 days straight...so you can see why I've been busy.

But anyways I have been doing some Youtube videos here and there throughout the summer as well as semi-"apprenticing" a few people on 3D techniques and the work flow for making game ready models (sometimes it's pretty hard getting ideas through haha)

I figured I would make a small update about myself to make sure that anyone that does happen across this doesn't think I'm dead to the world, because "I'm Not Dead Yet!" (Quest for the Holy Grail - anyone?)

Some stress outside of the work is looking for the internship I'll need in my second semester this year so I can end up graduating from ma, edu-mi-cation ;)...I've been finding it's next to impossible finding an internship as a Technical Artist, which is somewhat disheartening. Might have to go for 3D or gameplay...or even just tools dev I guess, we'll see what ole fate gives me.

If for some reason you can't find my youtube channel, you can find it at
http://www.youtube.com/user/TJE3
 where I uploaded some stuff I did this year as well and some videos that I've been uploading about some 3D tips/Tricks (and a forth coming series on the quick and dirty workflow )


Well I guess that it's for now,

T.Out();

Monday, April 1, 2013

Some updates

T.StartPost();

So I wanted to do another blog post a little while ago but just couldn't get what I wanted to say, down in text. This time it's a bit different haha, this is some updates about life in general I guess and some other things as well.

One thing I wanted to talk about is the new program I put out, P90X Workout Tracker Program.
You can find it here P90X Workout Tracker Program

PWT is a program to be used with P90X the crazy home workout program.  With P90X it's pretty much drilled into you that you need to record your results so you can see what you did last time to improve the next time.  In my Tools Development class I had to make a program that fit with a lot of C#/WPF principles (MVVM patterns and LINQ and such like that) so I decided to make a program that I would end up using later, the PWT.

Having just started up P90X again today, I came across one thing I need to update in this version (as a minor tweak) and that's make it so the program will accept text and not just numbers in the reps area so you can say how many kg's/lbs or what color of band you did etc, so that will be in a update pretty soon I hope.

Other than that, it's been some updates to my portfolio site as well as making a spot to host the program.
I've been kind of educating some people on The Dead Linger forums on how to model and texture things better than they currently have been which is kinda fun cause I get to see some results already as they progress.

I'll post when I make updates to the program as well as other stuff I remember I wanted to post about, later on.

T.Out();


Thursday, February 14, 2013

Finally Catching Up: Pt 2

T.StartPost();

So, in the last post, I covered the 3D stuff I've been up to, as well as shared the game that I helped make with other members of my team.

Now it's onto some other stuff where it's been more organizing and talking...and talking...... .... and talking that I've been doing.

RADIO SHOW:
I actually just realized that I never did write the post that I thought I had about the radio show so...this is a little awkward since I thought I had posted about it. But here it goes, a little selfish self promoting is in order!

Last year I was approached about being the host for a radio show here in Belgium to which I obviously said, "You want to put my silly ass on the radio?" and even after that they still wanted to.  Although the radio show we do is completely different from the original show that was mentioned to me (interviewing other foreign people like myself about their time in Belgium and travels etc) it's been fun just getting people to come around and talk about games and trying to make people actually think about the games they are playing (or even not playing).

So the Radio Show goes by the name of LEVEL UP. You can find our facebook page here


https://www.facebook.com/QuindoLevelUp

This is where we post our teasers, photos and other stuff that pertains to Level Up. Since we are about to air our 9th Episode (Yea I'm that far behind on actually documenting it here that I even had a show...that we're now about to air the 9th....) that means you've missed out on the last 8, which you can never hear unfortun...JUST KIDIIIIING, you can still hear them because we put them online on MixCloud as well

http://www.mixcloud.com/search/?mixcloud_query=quindo%20level%20up

This is the link to find any of the previous and upcoming shows. I hope that people enjoy the shows because it has been fun making them.  Really, I never thought I would enjoy talking for so long on something that people could actually hear me on...It's one of those things I've always been kind of weirded out about haha, but anyways it seems to have passed.

The fun part for me (and also the hardest and most stressful part) is trying to get a hold of industry people for Industry Talk. It's fun talking to the professionals about our topics for the show and seeing what they think cause sometimes you receive even more thought provoking things such as on the Game Addiction Episode when I got to interview +James Portnow , a game designer and writer for Extra Credits over at Penny Arcade.

But anyways, I guess it's time to do the brief part of the post about the last little project that I was doing for the last year and a half now which has also grown to be bigger than I initially planned.

STUDY NIGHT:
So Study Nights...It's exactly what it sounds like but since DAE didn't have a formal study night for people to kind of come together and give opinions on projects, work and socialize together (which we ALL benefit from) which I still don't know if it's because of DAE's kind of "recluse" nature that the students end up with because of the amount of work and projects that are due or what, but, I decided to try and bring people together.

Study Night actually started out last year (in my second year, 2011/2012 year). I decided that since, now that we were the second year of the international classes of DAE we should help out the new first years to hopefully help them pass with a higher ratio than we had. Since we (And I) still think that one of the reasons we didn't have a good ratio is because we had no one above to help us really as we were kind of  like the smelly kid in school, the Dutch classes didn't really want anything to do with us because they thought we were doing the English side for special treatment (Even the teachers thought it too, whether or not they will admit it though...) which we never received.

Anyways, As I said, I was trying to just make the Internationals look a little less bad cause our pass ratio sucked ...real bad in the first year of it running.  At the time, I did have the odd Dutch side person that wanted to come but I decided that if they wanted to treat us like we were different in the first year, we could do the same with our new Study Night  as well. They never made the effort (for the most part, as there of course is some of the Dutch side that were and still remain to be really cool about us being in the other class) to include us in stuff so I wasn't about to do the same for them AND MAINLY because I didn't want to plan something for a ton of people, we had about 45 people with the first and second years.

I saw that this had actually improved the pass rate (whether that year just had better and more studious people, I'll never really know cause I can't run the same people through it twice ...and I lack a Time Machine (although I do have a book on it now.. <.< >.>)) of the people that attended because we could help the people that needed the help.

This year (2012/2013) I decided to take the plunge (mainly cause I'm kind of an idiot and in the intro day of the year, I was giving a speech with our program coordinator, Rik Leenknegt and I meant to actually just say that the internationals in the room (as the plan originally was that the Intl and the Dutch would be two talks and I was to talk to the Intl's...but they put them together...), I was going to run the study night for them again...but I didn't have the heart so I said I would try to run it for everyone this year...I cursed myself later for saying it and not checking into anything before hand...) and try and run it for everyone. I tried a few times just doing it where we had always had it prior, The Studios. This proved to be pretty ok for about 2 sessions then it started to grow..and we ran out of plugs and chairs.

So at this point I didn't have much choice but to ask Rik if we could hold it at the school and he pointed me to the head of infrastructure at Howest and we arranged to have it in the school cafeteria since it has lots of space and we can take the plugs from the art room to make it accessible for more.  I was approached by a few people that said they wanted to help with Study Night so I said ok and now the team consists of two teachers and two students.

Stijn Grooten and myself were interviewed by one of Belgiums Newspapers about Study Night and why it seems that it had to be started by a Canuck and someone hadn't already started it.
(http://www.nieuwsblad.be/article/detail.aspx?articleid=DMF20130107_00424985  Here's the link but it's in Dutch just saying)

Now we run Study Night every week and try to also get more and more teachers to drop by when there are big projects coming up for due dates to give last minute feedback and it seems to be pretty appreciated (which is all I can ask for I guess)

I must say that I'm just happy people like it and find it useful.

Well now that that is all rambled out. You're pretty much caught up with my last semester and year of stuff I guess.

Thanks for reading/skimming.

T.Out();

Finally Catching Up: Pt 1

T.StartPost()

Soooooo...I was going to update this a bit ago...then I got into school work, the radio show (having to not only do the show but try and coordinate with industry professionals to do the Industry Talk portion of it...not the easiest thing..) organizing Study Nights for the whole of Digital Arts and Entertainment...Yea it's been busy.  Now that I have some time with the new semester start (and a bout of a throat infection, bronchitis and only 2 days of school) I can catch up with what I've been doing since the last one...Buckle up. It's going to be a long one. Think I might split the updates into 2 posts (at least)


3D 

3D wise, here's what I've been up to. I finished this vehicle for my exam.




Before the Vehicle project, we had to make a gun, originally we were going to have to make a gun based on designs from the art side of our program and right before we had to pick it was opened up that we could do either (as some of the art designs were ...*cough*unrealistic and stupid *uncough*).  Anyways, I chose to go with the artist design and it was fun to do. I had to make some modifications to the original design due to how the gun itself is actually put together but overall it was good.

The tri count might be a bit high on it but it was also modeled to be snapped open and reloaded (instead of just shoving the harpoons down the barrel with the charges attached  (which doesn't make much sense to me but hey, never know I guess)




And unfortunately I didn't make this little cutie, this was made by my buddy and team
Fluffy
Animal
Projects  Artist - Brent Rombouts and I just couldn't help but share her with you guys. This is ChiChi, our intelligent guinea pig with.......a JETPACK!!!1!11one!
We had to make a level for a game and we chose this as our heroine. We got the level done and you can actually download and play it if you'd like. I have the installer on my dropbox, so feel free to just download, do the small install and give it a shot. Just make sure you check out the help section for controls and such.

https://dl.dropbox.com/u/31340003/UDKInstall-AMothersFury.7z

And onto the Next Part!

T.Out();