Monday, January 28, 2013

Questions I had About the File System

I had a rough weekend and had to take care of few stuff, so I couldn't really get started on the file system. It is supposed to be easy and I believe it will. It's just that I'm confused about some stuff, and really didn't get the chance to ask about today.
The stuff that I read about the file system from the Game Engine Architecture book, and the Windows System Programming book made me not sure about how far I should go with the design of this file system for this particular assignment. I mean I don't know exactly what game programmers might need so that I can provide for them efficiently. Things like:
- Will they ever need to read text or characters for files? or all the need is just to read the files as binary.
- Shall I consider make the my file system I/O functions asynchronous so that a call to them doesn't block the game?
- Do I count on Windows to buffer the read/write I/O for me, or disable the buffering whenever I create a file handle, and do buffering on my own internally?

I started practicing a bit after I finished reading by coding some simple programs. Following prof. Ed's advice to make baby steps, prototyping to learn, and to use the tracer bullets concept to explore the unknown aspect of software design. In order to force myself that anything I write at this stage will be thrown away, I used a completely different IDE, namely Qt Creator. I used it several times before but I haven't used it for a while. I have to say after months of coding inside Visual Studio alone. Qt Creator is absolutely amazing, and fun to use.

I hope I could get it done soon, I'm waiting for the Unit Tests through, as they will clear out a lot of stuff.

The Math Engine seems to be a lot of work, but at the same time seems that it will be extremely fun. We'll see! :)

Tuesday, January 22, 2013

The Memory System: "Technically" Done!

I was really worried about this system. So I decided not to touch it until I'm fully prepared. I refused to look at any posts on the forums related to this system until I start working on it, so that I won't feel influenced or demotivated. I spent this whole Saturday studying for it. I read all the slides and took notes, and then read the sections related to Win32 Heap creations and allocations from the Windows System Programming book, and also took notes.

At that moment only, I felt a little ready to start coding. I dedicated the whole Sunday night for that. The first hour though wasn't the happiest. It was just a tour of all the stubs and the unit tests already written there. I was trying to get the big picture of how the individual components of the system interact. It was so demotivating at first, to the point I didn't want continue working on it and leave it till another time. But I knew if I had done so, I would have felt extremely guilty about it, so I kept working.

To raise my moral a bit, I followed the 'baby steps' rule. I just wanted one test out of the 40 unit tests to pass in order to feel like I have done something. So I tackled the easiest one at all, the one that test the initialize() method that initializes the Mem object. And there it was, 1 success - 39 failures. Shortly, the 1 success became 3, and then 7. And after that, in order to move from there, I had to work on the whole system at once. So I kept banging my head against it, sometimes dealing with failed assertions and sometimes illegal memory access, all of that for about 4 continuous hours. 4 hours of debugging and stepping through the code and experimenting here and there. And suddenly, to my surprise, 40 SUCCESSES!

I was extremely happy, but that didn't mean I'm done. I'm not really satisfied with the code at all. It was all about passing those 40 unit tests and get it "Technically" done, but it's not the most elegant code in the world.

So the refactoring process started today, and two change lists were submitted already so far. The examples that Prof. Keenan gave in class today helped a lot clearing some of the stuff up. The best part about today's lecture was the revision of how to do software design. This is so important and extremely helpful, specially that it is transferable to any software development area, whether it's game development, web development, mobile development ... etc. It is so relevant to this assignment since now I have to iterate over my code again and again trying to enhance it and refine it.

Monday, January 14, 2013

The PCS Tree

Data structures are always interesting to me. The ability to store data in certain ways so that they could have special inherent features, such as fast search, or fast access, ... etc, is very exciting and rewarding. As professor Keenan mentioned, computer science and software engineering are all about moving data around, period. Finding the most convenient data structure to represent the data and efficiently implement the task at hand is all that matters.

The PCS Tree is really great for representing any hierarchy of objects. It reminds me of the Composite Design Pattern which I used in SE456 to represent the the hierarchy of collision boxes in the Space Invaders game. However, the PCS Tree is very generic, you don't need to write your objects in certain class hierarchies to implement the composite pattern. Just have your data object inherit from the PCSNode class, and it's then possible to add it to the PCS Tree.

This assignment wasn't hard, but it was very important as it served as a very good warming up for what's next. After 6 months of being far away from C++, and working with only managed languages such as Java and C#, C++ gets rusty and forgotten. C++ is a real big ocean, now one can really surround all of its knowledge, But once I start coding in it, I start to remember things little by little and appreciate the closeness it gives me to the machine. At that moment I realize how much I love C++ and how much I wish I could learn more about it. This class is going to be very challenging but I'm sure it's going to be very rewarding at the end. And as the Cadillac ad. said: "Welcome to the world of gentlemen, gentlemen!"

What I liked about the PCS Tree assignment:

1- Unit tests were provided so we make sure we're on the right track.
2- A great opportunity to practice my understanding of recursion and recursive methods.

I also like the way I implemented the dumpTree() method. I wrote it so that it prints the tree in sideways. So this hierarchy:


is printed out sideways as this:



I'm worried about the memory system .. we'll see how that will go ...