It’s Insane I tell YA! – Aka The Git Based Buuugh Hunterrrrhh II!

Achtung-Achtung! You have been warned – A geeky article on Git and strange behaviour in the Java Swing API ahead!


First Step – Migration to new Git Repositories

Until recently I have used SVN for versioning of my game software, but the other day I talked to one of my colleagues about migrating my repository from SVN to Git. It seemed a natural choice, since Git its the versioning control system of this age and in my new job we work and code on a Linux platform using Git extensively on the command line.

I had some vague hints that I could use Git by calling git svn to clone my old SVN repository. Later that evening I had some time on my hands and started migrating. I don not use the cloud for backup I have several USB devices where I backup my stuff. My original repository is file based of the same reason and has this file based url:

file:///home/username/Android/AndroidRepository

So away to the terminal I went, created a GitOrigins folder for my new Git repositories. My Goal was to split my apps into individual Git repositories. I called git svn just to see what options I had before going ahead, but that didi not go well git: ‘svn’ is not a git command. See ‘git –help’ the terminal responded in its silent clinical way. No problem git-svn is part of the Git core system and can be installed on Ubuntu by calling:

sudo apt-get install git-core git-svn

Just to prepare I titled myself Sir GoogleALot for a period to find some recommendations on how to best procede after my web adventure I was ready to go. Starting with A Dungeon Horror Deed which was implemented with a trunk a folder called ADungeonHorrorDeedPilot/trunk in SVN I invoked my first magic Git conversion command in my GitOrigins folder:

git svn clone file:///home/usernam/Android/AndroidRepository/ADungeonHorrorDeedPilot/trunk

After a lot of conversion output in the terminal, I ended up getting a trunk folder. So now I needed to convince myself that it indeed was a valid Git repository so I installed some nifty Git tools for interactive meddling and started gitk which is a graphical viewer by calling these commands:

sudo apt-get install gitk
sudo apt-get install git-cola
sudo apt-get install git-gui
cd trunk
gitk

gitk is for browsing branches, commits and changes, git-gui as a helper for gitk and git-cola to work with commits and other git activities. Starting gitk showed med that I was in a valid Git repository.


But I wanted to extract the repository with the specific name ADHD, not trunk. I deleted the new trunk folder and invoked git-svn to extract to that specific name:

git svn clone file:///home/username/Android/AndroidRepository/ADungeonHorrorDeedPilot/trunk ADHD

And it went as expected, you can name the repository by adding the name you want at the end of the command as can be seen from the last calls. After this I went ahead and converted the rest of the repositories I had and checked all repositories with gitk for validity and they where ok. So far so good, at this stage I decided to make a zip of GitOrigins and saved it as a backup.

WTF! My origin must be bare!

After cloning all my projects to independent repositories, next i wanted to try out working with the code. As the first thing I made a Work folder and cloned the ADHD repository there by calling:

mkdir Work
cd Work
git clone file:///home/username/GitOrigins/ADHD
cd ADHD

Git has to know who the user is to do its operations this was done with these commands:

git config –global user.name โ€œusernameโ€
git config –global user.email โ€œusername@gmail.comโ€
git config –global color.ui ‘auto’

Now for the funny stuff, importing the ADHD project to Eclipse, building it and running it in a virtual Android device. It worked like a charm. However calling git status showed me that i had both a bin and a gen folder containing untracked files. These folders are generated but not needed to be put under version control, so in the best Git style i made a .gitignore file containing:

/bin/*
/gen/*

Now my git status command showed me that only the .gitignore was untracked so I tracked it and comitted it:

git add .gitignore
git commit -a -m “Initial version of ignore file”

No problem, so now to push this local change to the origin in the GitOrigins folder:

git push

But to my horror this failed to begin with. There are two types of Git repositories, bare and non-bare. Bare repositories are a working copies with out the actual files, but contains the Git version of the files in the form of structured changes and hashes, and these are the ones you per default can push your changes to.

To convert an existing working copy to a bare use these commands, for a working copy in a repository called myrepo:

cd myrepo
mv .git ../myrepo.git # renaming just for clarity
cd ..
rm -fr myrepo
cd myrepo.git
git config –bool core.bare true

I made a script containing these commands, that takes the name of the directory as the one argument to do this:

cd ${1}
mv .git ../${1}.git
cd ..
rm -fr ${1}
cd ${1}.git
git config –bool core.bare true

This was used to convert all the folders in my repository directory called
GitOrigins like this:

./make_bare.sh ACurrencyCalculator
./make_bare.sh ADHD

Then I could Push ๐Ÿ˜‰

The Sultan of Swing – Aka Weird Bug Solving

After this initial effort I also imported my ADHDEditor project. It all ran smoothly and I only had to ignore a bin directory since the editor is a Java Swing application. So i tried it out and to my horror discovered an undetected bug in my editor. As it turns out I have been a lazy bastard when I made the editor using JOptionPane to create most of my entity editing dialogs. Some of them uses JComboBox to select an entity icon and dynamically show it when a new selection is made in the JComboBox through a cunning listener implementation:


In the code that prepares the JOptionPane I did this to set the JComboBox:


But due to something weird in the Swing API for this listener implementation the icon is not updated when I try to edit a Quest where the first entry in the type ComboBox is selected. Strangely enough I also have a JOptionPane setup for editing monsters but that does not have the same problem. After messing around I ended replacing the setSelectedItem call with this fix:


I solves the problem but is not really a satisfactory fix since I can not can find the core reason for the bug imidiately, but it will have to do for now.

Final Elimination of the Franken Bug

As an aside it just occurred to me that the editor code for different entities can be put into separate classes, making the code even more maintainable. I have started this process with the QuestEditor class. I it will also give me a chance to dig deeper into the problem, because it is easier to test a single class like this.

And testing this way have also enabled me to find the problem. You can not invoke a change listener by selecting and item that already is selected. So I have made a method that updates the Icon that can be called in the listener and be called during the creation of the editing dialog and this solved the problem.

As a follow up here a small week after I wrote this post I can tell that the Editors has been moved to separate class removing some 500 lines from the main class file and at the same time giving a much better overview, making it much easier to maintain.

Leaving stuff better than when I entered always makes me happy ๐Ÿ˜‰

I am not Looking Back II!

Recently I read on OMG!UBUNTU! that a tech contributor from online magazine Forbes.com had ditched Windows and tried using Ubuntu for two weeks, the guy did try another Linux distribution first but dropped it since the installation ‘couldn’t find a drive to install the OS to.‘. He had the same issues as me with Windows even though he had used it for decades. After the experience he will continue using Ubuntu for his tech writing: ‘ this is absolutely my new daily driver for writing, working, communicating, browsing and media consumption‘. Read the article by Following this link.


As a conclusion on my part, I still do not see that Windows is improving as It is the company OS at the business where I work. In fact it has gotten worse with updates and all. Linux however stays the same and is fast and pleasant to work with, I have never once had a nagging doubt after ditching Windows. The advantages you get by dropping the stagnating OS are many, amongst a lot of other things not mentioned here, you will get a system that:

– Always boots in 30 seconds or less
– Always shuts down in 5 seconds or less
– Not forces you to update, but allows you to select when
– Not degrades in performance over time
– Has a free office suite (Libre Office)
– Not has a slowly corrupting registry
– Runs significantly faster than Windows
– Not has an ugly tile based user Interface, who ever made that brain fart I do not know…

Note that this is not a commercial, I am not getting money from a sponsor to say this, I am simply recommending a good product.

I know Microsoft is trying with a valiant effort to make the company look like an open source advocate, but I am not convinced. And I am not getting money to not recommend them either.. ๐Ÿ™‚

Holiday At last, refactoring as therapy…

After a period in and out of the job market I have finally landed a job at a company I hope is more credible/stable than the other jobs I have had in the last year. So now I am on official Vacation at last and gathering strength at home with the family.

So I just sat down to look at my Asteroids Clone and discovered some things that could be improved in the code. To many hard coded values and a slight little problem where the spaceship could be smashed up even before the game started.

Try the new improved Asteroid Clone!

It is satisfying to be able to clean up and make corrections to the code relatively fast event though I have not touched it for a while.

As I say, Good Code is defined by answering this question:

Would you give the guy who wrote this a beer after maintaining it?

Beware of The Mysterious Manor!

Since I am a dedicated board game player I really have to discipline myself. I have participated in the Kick Starter Campaign for Vast the Crystal Caverns, and now they are putting out a new and improved version called The Mysterious Manor.


It’s really tough!

This version is so much better and more grittier than the first version. This is one of those new games with an asymmetric game play, meaning that depending on your role in the game you play in different ways towards different goals to win the game. Beware of starting on the Kick Starter Path, I have participated in to many campaigns causing a storage problem at home and it is expensive too! ๐Ÿ™‚

PS! follow up!

I unfortunately fell in but, it is not as expensive as I first thought. Never the less I am starting to sell some of the games that I not am playing. They simply take up to much space…

Not Big Enough I Say!

I did it again, as I was driving home in my car I wondered why the hugest of the asteroids in my clone of the Atari Asteroids Game from 1979 not just pushed the smaller Asteriods out of the way on impact, I had a revelation!

The mass of an Asteriod is not based of a one dimensional diameter length like metric or a two dimensional area like metric for that matter. Mass is mass and it is volume based, so away I went an added a cubicSize member to my asteroid class which is size*size*size, where size is the diameter of the smallest circle surrounding the center of mass of the asteroid. And behold it looks more like the effect i was after, try it out:

https://schwartzengine.com/AsteroidClone/index.html

What a bummer! Using a one dimensional measure for volume, I must have been to eager to see the results of the collision algorithm when I implemented it. A typical trait when you make graphical software. It also goes to show that the human mind works in mysterious ways when it comes to trouble shooting and problem solving ๐Ÿ™‚

Software development is still a young craft and not easy ๐Ÿ˜‰

Is This Remnants from Half-Life 2

As I was cleaning up in the garage yesterday I encountered some ‘vintage’ boxes containing beverages in plastic bottles. They where so old that most of them contained colorless fluid, except the colas of course.


When placed on the worn concrete floor of the garage it looked like something out of the apocalyptic HฮปLF-LIFE series. Besides having fun with old memories of past gaming experiences I did clean up the garage and shaped up the garden with my lovely wife. All in all a great sunny day.

Recommended I say! A day like yesterday brings you new energy makes you wonder, get new takes on stuff you have been doing/ are doing currently ๐Ÿ™‚

As an aside I have discovered that Steam runs flawlesly on Ubuntu, so I am in the process of replaying good old HฮปLF-LIFE again, a great nostalgic trip! ๐Ÿ™‚

Reclaiming my Unit Testing!

This evening I had to make a new unit test for one of the classes in my A DUNGEON HORROR DEED editor, for a while Eclipse had spat some kind of IDE NULL pointer exception in my face every time I tried to run a test. I have not done anything about since the classes under test not have changed.

But now it was urgent, so away I went to the web and was lucky to find a couple of good suggestions on a Stack Overflow entry. I used this one that specified what to do in the Eclipse IDE:

– Go to help
– Select: Install New Software
– In the Work with text box type: Juno
– Expand Programming languages in the tree view
– Select: Install Eclipse Java Development Tools
– Install it
– Restart

And it worked in first try:


So now I can make my testing count again!

As an aside I can mention that the Dice class that have methods I have used since 1989 when I made a program for rolling new Characters for Warhammer Fantasy Roleplay have a method for rolling a specific range from (and including) a minimum integer value to a maximum. I have never tried what happens if you give the method a minimum that is larger than the maximum. So of course I made a test where I tried this. I expected the method to switch the two parameters and still deliver a range roll from (and including) the lowest to the highest of the two values.


And of course it crashed, away I went an refactored the method to switch the values if the minimum was largest and now the test succeeds. And then I added some explanatory java doc as well:

Enhancement of the ADHD Level editor

Last night it occurred to me that the editor I have made for A DUNGEON HORROR DEED not is quite up to speed regarding communicating that the map you are editing has changed…

So the gloves went of and I implemented the classic ‘hasChanged‘ flag used to indicate if your document/map has changed by adding an asterisk after the title of the editor window.

I also remembered that I had made a back door to mod the ADHD game. If you make a set of maps where one of them is named Gobbo Town and make a world map file from these called ADHDFakeMaps and copy that to where your save the progress of the game, then you will start in that map when starting a new game. I sat and used the Editor to create a little fake map level to use the back door and realized the the editor is well suited for this work, but the game will act a little strange if you try to load a save game from the original embedded map when you use the back door. So I have to remember that if I am modding. ๐Ÿ˜‰

As an aside I had to make a little extra features regarding saving. The Save… menu item worked as a Save As…, so I have implemented a true Save that saves with out questions. Also an opt to overwrite if an existing file is selected during Save As… was needed to make a proper editor, but I think it is OK now.. ๐Ÿ™‚

This is also added as part of the Game manual on schwartzengine.com, download the editor here.