Friday, April 20, 2012

Designing RuneEngine V2

This is something I’ve been meaning to discuss wider scale, but haven’t taken the time to do so. This post is going to be all about the ideas and design theories I am using as features are added to RuneEngine V2. I am also going to do my best to explain why these theories are proving to work well and how they will improve experience for use of the engine later when it is more completed.


Interfaces and Polymorphism

One of the biggest concepts that have stuck hard in the new structure of the engine is strong use of Polymorphing topics and interfaces. This is extremely important for users who would plan to extend the engine and add objects without having to write crazy wrappers around my rendering and content systems. Almost every object in the engine implements an interface, and almost all of the internal systems use the interfaces and NOT the objects directly to handle core features. For example, all content reference objects are interface driven and apply specific rules that the rendering pipeline requires. So, the rendering pipeline only requires the interface and proper implementation. Therefore, this can be extended very easily so long as the interfaces are implemented correctly. The most recent IO systems are nearly 100% interface driven, and probably show the extensibility of RuneEngine at it’s peak. The physics system exposes no objects, only interfaces and attaches to physics engine wrappers, so to add a new custom engine is trivial(well as far as making it work with RuneEngine goes).

As you can see those are some major area’s and they are very simple to plug into the existing API. This makes my life especially easier, but other’s using the engine could gain the same benefit as these interfaces are not internal and can be used by anyone.

Key reasons for the high focus here are obviously for extensibility and generic behaviors. This benefits mostly programmers, but that high benefit could allow a team to do much more with RuneEngine than what I allow them to.


Internal Code Cleanup/Optimization

This is a huge reason I started restructuring the engine. My goals for what I wanted it to be changed a few times during the first structure so the internals were getting haggard and the calling conventions were inconsistent.

So what are the new guidelines and why? First a little history of what it kept shaping around originally. When I first started the engine it was designed to be built like C++, well I took that a little too seriously. So, I backed off that and went way the other direction for a while. The object oriented model has always been very important through development of this, but some pieces were being written poorly, and as the ideas changed the legacy code was not getting removed. This made the code base fairly hard to work in as there was a mix of all sorts of styles. Before I started the restructure I gained an even better handle over C++ development and stay well practiced with it building many prototypes first in C++. The C++ iteration was started for RuneEngine. This is when I saw how poorly they were going to correlate. Some parts would work fine while others would need full rewrites. Therefore, the engine began restructuring. I use the term restructuring because I have not rewritten much of the internal code, just optimized and sorted it better. Much of it has not changed aside from areas where the objects used were changed greatly.

Ok, so let’s focus more on what has happened internally now. Originally there were a lot of methods calling methods and deeper callstacks, well now unless completely necessary every method is completely self maintained and does not internally call upon another. I’ve made my method argument lists more appropriate for C++ porting. However, I have also added higher level overloads which do not look as much like C++. Naming conventions have been held true, and many fields are marked internal now. Using statements have been cleaned up(this can actually be a huge optimization). All of this has made the performance better and the cleanliness much greater.


Exposure of High Level and Low Level methods

Before I only really exposed high level methods to access features. Although, I did have internal methods to do much of the low level portion as well. The biggest change here is that the low-level methods are now public and cleaned up. This also gets back into extensibility of the engine. If I don’t expose these methods then users of the engine will still have to handle things the XNA way. My methods just make that process a little simpler, even the low level ones.


IO vs Content Pipeline

This is a big change more so than original design at all. Originally there was a high focus on the IO system to load files which were unique to RuneEngine. Well, to adhere better to XNA and what XNA developers are used to, I am extending the ContentPipeline for many proprietary formats. Of course the C++ iteration will need some major differences here, but it should be manageable. So, pretty much all Rune specific content types are extended in the pipeline. And therefore could be used without any feature in RuneEngine at all.


Compartmentalized Design

This has been the plan since day one. Each DLL has been designed to be completely self maintained and features are being better designed in this new structure to hold true that they can work without the rest of the engine. I do this by writing majority of the objects completely independent from the rest of the engine. I had made some mistakes in the original structure, primarily the content systems. The content was reliant on every other part there, and the Graphics wrappers I had built as well. Now they’re self maintained and as stated above can be loaded through the content pipeline and be used with normal XNA projects.


Platform Target considerations

This part is simple, I’ve focused towards XBOX360, because it has more restrictions than PC and it’s not a mobile device. Not to hark on mobile, but just because market studies show it as the better revenue stream doesn’t mean it’s my primary focus. I prefer to focus on maximum quality I’m capable for. I’m not going to downgrade the output by adhering to mobile. This is a personal stubbornness of mine and I admit that, but I am NOT ignoring mobile. Just I will build the engine focused against everything else and make a mobile build later. Adhering to 360 and REACH profiles are going to keep me closer to what mobile will expect, so I am genuinely not concerned.


Development Tools

There is a fairly large concern here as well, but none of this matters if the engine itself behind it is not backing it. So, I’ve rebuilt a lot of the editor and have a lot of plans for working new features into this side of the engine. There is also a strong feel for extensibility here.




That about wraps it all up, there is not much more to point out at this time. Of course there has been a lot of time spent some days determining what a method should be called, and where it should be located. I didn’t think any of that detail was that important ;-D. Anyways, until next time…

Friday, April 6, 2012

Project Organization and File Structure

I was just thinking on this and realized that I preach about
this to everyone, all my student, anyone I get into dialog with about
programming development. This is something
I’ve gotten better about over the years and have also seen how big of a problem
it can be not doing so. ORGANIZE YOUR
FILES!!!!! Make a bulletproof file
structure. I can’t stress that any more
than I am right now. If you do not get
your files organized in a way you can find things quickly, you will hurt
yourself later.

Now, I don’t believe I have taken the time to give some big
tips and tricks that have worked before for me on a regular basis, so I’m going
to put them up here now. When I create a
new project I generally spend about 2-3 hours putting it together BEFORE
writing a single line of code. You may
say “WOW that’s a lot of time for preparation,” but I say 2-3 hours on a
project that you’re going to spend more than a week on… that 2-3 hours is
nothing. And if you didn’t do it I
wouldn’t be far from promising it would take 2 weeks instead of 1.

So, what I start a new project what do I do? First of all first and foremost even before
starting VS. I create a master directory
for the project. Typically on the root C
drive of my PC at home, if I had a D partition it would probably be there. For example RuneEngine V2’s master directory
is located at “C:\RUNE2.” Now what goes
in the master directory? The solution
right? NO!!! I stress that the solution
is not created here because with the rest I’m going to cover creating backups
would be nearly impossible or an extremely painful process otherwise.

The next folder I create is a child folder of the Master
directory “Bin”. This is where ALL my
projects output goes. In C:\RUNE2\Bin I have these sub directories:

REACH
HiDef
XBOX360
Mobile
DOCS (Yes I actually build documentation, it would not be
inappropriate for this go to outside of the bin in the master directory if you
prefer)
Editor
EditorAPI

As you may see above, these are all the platform targets,
not debug and release like VS typically creates. This is entirely intentional; my
Debug/Release folders are contained in these.
And this is where my projects target their output. This is why we do NOT put the solution in the
Master directory. When we create the
projects and configure their target paths we do not have to redo this for any
backups we generate. Also, Source
control is easier to… well control this way.

So, where are the projects created? They’re created in Subdirectories of the
Master Directory. The current working
solution is contained in C:\RUNE2\RuneEngine_2D_MAIN, but there are 4 other
backups and iterations of the engine there as well as the initiation of the
Native code etc etc blah blah. The
Master Directory contains anything and everything related to the project in
this setup, and it isn’t burrowed in C:\Users\Me\Documents\Visual Studio
2010\Projects….. Yep, not my favorite place to put things.

A note on source control, IF YOU ARE NOT CAREFUL YOUR
PROJECT CAN BE CORRUPTED, hence why I have multiple backups at all times. Usually it only gets corrupted if you’re using
it incorrectly, but better safe than sorry with large projects.

A note about creation of code files in the solution explorer
and handling folders. In C# you’ve
probably noticed that it adds namespace when you add to the folder. And sometimes you don’t want that. Of course you can just delete it and fix it
that way, but my tip is to just always add files in the namespace you desire
and if you want to move the file somewhere else to be more organized, it’s a
simple drag operation.

I hope this is a good read for other developers out there,
everyone has their own styles of handling files and I’ve tried quite a few
variations and this is the way I plan to stick to for a while. Below is a pseudo copy of my file structure
in RuneEngine v2’s project directories:

C:\
  RUNE2 – Master
    Bin
      REACH (Debug/Release)
      HiDef (Debug/Release)
      XBOX360 (Debug/Release)
      Mobile (Debug/Release)
      DOCS
      Editor (Debug/Release)
      EditorAPI (Debug/Release) – FYI I’m going to be
talking A LOT about this soon.
    Lib
    Includes (Lib and
includes are for the native build ignore them if you’re developing fully
managed)
    RuneEngine_2D_MAIN
(There are
actually multiple solutions here which load different combinations of the
projects)
      RuneEngine
      RuneEngine.Graphics
      RuneEngine.Content
      RuneEngine.Physics
      RuneEngine.ContentExtensions
      RuneEngine.Math
      RuneEngine.Scene
      RuneEngine.Threading
      RuneEngine.Components
    RuneEngineOLD2
    RuneEngineOLD1
    RuneEngineBACKUP
    RENativeDX




I wanted to make one last modification to this, though I suggest this methodology highly if it doesn't work for you don't do it. This ulimatley is a reminder of how important this is and a suggestion in what works for me. It's mostly about what you benefit from most. -Happy coding

Wednesday, April 4, 2012

DevConnections 2012 - Las Vegas

So, I was sent off to the DevConnections conference in Las Vegas recently. I was there as an exhibitor, but I also had a full attendee pass and was told to attend sessions as much as I could while there. There was a lot to learn there specifically on Metro and HTML 5. I'm writing now to summarize some of the things that were key points accross the sessions that I attended.


New C++ Features

I'm actually going to start with the new features of C++ in Visual Studio 11 as it is the shortest and probably in my opinion the most important.

One of the biggest surprises here was Microsofts statement regarding the state of C++ in software development today. IT'S BACK! That's right, as far as Microsoft claims to be seeing the interest and desire to work in C++ is growing again. It was thought for quite some time computers were surpassing the software we were putting on them so there was no need to go through the extra effort of C++/Native development.

The biggest things for me and I assume many developers with an interest and desire to work in C++ that are very good to hear are these two things:
  • Intellisense has greatly improved
  • Types are now color coded
I know these are not as big of a deal as they seem, but for many years C++ has been a painful experience while these two features greatly reduce just how painful that is. If you have used C++ in the VS 11 Beta already you have probably seen this.

There are a few things that are both really great and a little weird at the same time. For example there are a few new keywords added, one specifically I am not in full agreement on is the "auto" keyword. If you're familiar with var in C# or a few other various languages it basically does the same thing. Auto does not require a type definition, it requires a specific template based instantiation, but does not works very similar to var as it does not specify a type. It does delete itself, so it behaves a lot like a managed memory allocation. I refuse to use automatic type resolution myself so this was not appealing to me personally, and chances are if I'm developing in C++, it is to get away from managed and this sounds too much like managed behavior, without the CLR.

The last big implementation is that XAML can now be used with C++ when using WinRT. Yes, that's right Metro apps can be developed with C++ as well if you didn't already know this.
Something else really neat that threw me off a bit, mainly because they did not show much of what they meant was that supposedly the new Libs for C++ are more DirectX friendly and allow writing 2D/3D graphics in standard C++ libraries. It seemed to me all they really did was include DirectX in the standard Libs/Headers and that's just all it really seemed to be, still cool, but I don't know if it was a HUGE thing for me.


WinRT / Metro

This is where things start getting fun. WinRT and Metro are "practically" the same. So, let that sink in a moment...

Ok, unlike .NET WinRT communicates directly with the Operating System, but is also exclusive to Windows 8 and will not be ported for compatibility in Windows 7, which I think most everyone is aware of. What exactly is WinRT though? It is a new API for development which is NATIVE not managed for development of Metro applications in Windows 8.

WinRT is actually Native COM to be more specific. The DLLs/Assemblies are compiled with CLI metadata the same as .NET and actually... the code you write will very much resemble .NET. Another big kicker is that many of the .NET 4.5 objects ARE WinRT objects. Just in .NET they hit the CLR BEFORE going to WinRT.

INFORMATION OVERLOADED, take a breath...

Ok, now given the fact that WinRT is Native COM what does this give us? Unlike .NET the "common language runtime" WinRT is ACTUALLY more so a common language runtime than .NET by a thousand times. WinRT can be used in C#, VB, C++, Javascript/HTML, and pretty much anything else that can access COM. Another big factor is that ALL WinRT is XAML ready, sooooo... C++/XAML applications are possible where they were not really before.

There are a few downers to this though, WPF/Silverlight developers are not going to be as happy as they originally may have thought. WPF and Silverlight use XAML and so does Metro, but as one of the speakers at DevConnections stated XAML needs to be stated for what it really is and not associated directly with WPF/Silverlight.

XAML as he puts it is a language for object instantiation. Yes, this is true, but there is more to it than that. It defines data bindings as well and some extra syntax for handling event mapping as well. Basically think XML with a twist.

That being said, XAML in Metro communicates with WinRT, while WPF and Silverlight communicated with .NET or the Silverlight specific binaries. The objects and properties may be different... Actually you will find that only the MAJORLY used pieces of each were ported exactly as they are. So, just because you know WPF or Silverlight does not mean it's going to be easy, but it is NOT as bad as some are making out to be. General development should be rather simple, but most Metro apps will need a rewrite anyway to comply with the proper paradigm for Metro.


HTML 5

I really didn't take as much from these sessions. This is mainly because all they were really saying was it's an idea, you can use polyfills to add support to browsers that don't have it. There was some mention of more specifics, but there was nothing too glamorous or interesting to me aside from a little more realization to what the big fuss is. Oh and Opera is the most feature filled browser at this time. HTML 5 is very friendly will cell phones.

LOOK UP MONDERNIZR, this site has a ton of useful polyfills and scripts for making HTML5 work everywhere, even IE6.

Aside from that, I really don't have a whole lot here.


Conclusion

Ultimately, this article is not nearly as glamorous as I wanted it to be, but it's hard to get too deep into the specifics without losing majority of the people who may read this. Either way, I hope there was something here that sparked interest enough to do some of your own research.