Saturday, October 31, 2015

I want the HTML 5 strategy game engine done!

A long while has gone by without any new posts. I originally also wanted to continue a stable blog of everything interesting I discover regarding the 3 topics important to me, but pauses were known to happen sooner or later :).

Probably one of the big reasons why the pause was so long, is that I finally changed to being a professional programmer. After thinking about it for ~10 years. I have programmed as a hobby for quite seldom during all my life and within the last 5 years, more and more frequently.

I am a javascript programmer, naturally. But most of my time nowadays goes to my family. Having a more stressful work and family life (as everybody who has a family, knows how much it causes stress), there is little energy left at the end of the day.

But I still have a big goal / dream to get my HTML5 game completed in the future. I had actually made the prototype quite far before, but then as I'm a perfectionist who wants to learn new things and as the project changed to something more simpler, I decided to start over with ES6.

I originally had a grand strategy game in development. Which can still be found here:

http://postapo.level7.fi/  (the game prototype should be working, but as it can be accidentally shut down on the development server, don't be surprised if the prototype doesn't show anything). This project, however, was way too ambitious. I have always read from experienced game developers, that you should start small and later on think something bigger. Even though I did know this, I still went too big.

The new project is partially seen in these tests:
http://warmapengine.level7.fi/tests/pixi_manualTest.html
and in github:
https://github.com/Hachitus/warmapengine ,
but after I get the engine to a stage I am fairly content with (as the basic functionality) I will move it to another repository, with another name. The idea for this project is to make an open source engine for making 2D strategy-games. The map should be flexible enough to be used in real-time and turn-based games with different tilesets, but the game I have in mind is hexagon and turn-based strategy game. So this also will reflect on the design choices when developing the game.

Also the plan is to make the engine first and then develop a simple game on top of it. As that is done I will think if I still want to make some more extensive game or not. But important goal is to finish the game engine and maybe someone else will also find it useful. My hope would be to make the HTML5 strategy games more prominent option, than they are presently. Unfortunately.

The timetable for the game will be very flexible as a family man my time is limited. But I have definitely decided to follow this path till the end.

Wednesday, April 1, 2015

Entrepreneurship

Short summary of my own time as an entrepreneur. This was a significant time for me and has changed me profoundly in multiple ways.

My company

The company I co-founded and stayed with till the end was named Level7. It was a gaming center, which had ~30 computers and a few game consoles for gamers. Also as a side-product we sold some snacks, candy and drinks to our customers.

We made a very good start with it. Basically our starting budget was supposed to be a lot higher than it was, so already at the start we encountered some problems. Those didn't really slow us down and we got it running stable financially in a few months. We got customers heavily from e-sports / hard-core gamer backgrounds at the start. We held e-sports tournaments and were generally very active in the gaming community. My roots personally were at the gaming community and that was my passion for this and the reason why I had a huge loads of motivation and vision.

During the years we made our mark to the Finnish e-sports scene. This was mostly through arranging very prestige tournaments at our premises. Some of the tournaments would not have been held at all in Finland and especially with such a well gathered prices, without us. And for that I am very proud!

In the end we parted with not-so-warm relationship with my business partner who was with me during the years we operated Level7.  Despite that, I am still grateful for having him with me operating the gaming center, because in many aspects we complimented each other. I was the technical and more visionary guy and he was the better organizer, stricter and better in relations towards external relations (like sponsors). The biggest problem between us, as it often is in business, was money. This appeared when the company was going through bad times in the end. But enough of that.

What I got from the experience

Running my own company has been the most profound experience I've had so far in my life. Well I can tell you that having a kid is really something, but even considering that the entrepreneurship was really awesome. Those are two very different experiences.

What I've learned:
  • You can achieve a lot of things, once you really decide to do them and put everything you have into it. That's what many of the successful entrepreneurs have also said and I totally agree with that.
  • When you are running your own company, the only person you can count on 100% is only you. But this comes down to people skills a lot. If you are good, you get more out of other people and you get then motivated better. But also note that never-ever get bitter about it or stop trusting other people and being cheerful and motivational. I think the worst thing you can do is do everything by yourself. This works at the beginning, but I've seen it turn upside down, when the company grows enough.
  • Also running your own company - and doing it well - will force you out of your own comfort zone a lot. If you want to do it well, you can't evade or postpone any things, just because you don't like it or you are not good at it. If there is nobody else to handle it, you have to take the responsibility and learn to do it.
  • Time management and prioritization are the most important single aspects. You should never waste your time on things that don't really make the most impact. If you waste time on doing things that will have very little effect on the operating of the company, but make you feel better, it's a bad choice. Get out of your comfort zone and do the things that need to be done, period.
  • Business world is selfish and sometimes cruel. Still, you do not have to be cruel or selfish yourself (and should not as that will cause bad relations), but you have to take into account the possibility of something bad happening when you operate the company. Despite of these warnings, my experience was surprisingly smooth. Though I had one lesson I will not forget.
  • Always write all deals you make with other parties in writing. No matter what it is. Email is also valid agreement and should work almost always.

Pros

  • You will learn a lot not just about entrepreneuring, but also about business life in general, when you deal with other companies. This will help in normal work-life too.
  • You have to push your limits and develop yourself, if you do the entrepreneurship properly. People are never ready or perfect and if everything goes ok, you will evolve as a person.
  • You will gain awesome memories and experiences. Really the likes that you will remember the rest of your life and be really proud of them!
  • You will learn to take the initiative (if you haven't yet) and do things that you don't want to.

Cons

  • Companies taking advantage of you, if you are not careful.
  • You have to do a lot of things, which you don't like, i.e. going out of your comfort zone.
  • You might not even make a normal living out of it, but rather have to make a lot of compromises financially. I know I did.
  • You will most probably work more than you earn (especially at the beginning). Most entrepreneurs are not in it for the money, but for the independence.

Microsofts autodiscover feature in linux

Just a short hint for anybody who wants to make Microsofts autodiscover-feature work in linux environment. Also this is a special case as I needed to make the autodiscover work with another domain. By this I mean if the domain in question is: mydomain.fi and you have a webhosting company: hosting.fi, then you will need to insert a DNS entry for the mydomain.fi which points to hosting.fis general autosdiscover DNS-entry. As:
mydomain.fi -> autodiscover.hosting.fi
autodiscover.mydomain.fi. IN CNAME autodiscover.hosting.fi.

This special need came when I worked at a hosting company and required just couple special alterations.

The only real script you need for that is here: http://0wned.it/wp-content/uploads/2011/09/autodiscover.php_.txt

Though the crappy part is that Microsoft wants to make everybody else's life hard, you might have to make more adjustments to the autodiscover, to make it work.

First I had htaccess redirect all the traffic to a php-file. So it doesn't matter which way the autodiscover is called it always works (e.g. some implementations call it with capitalizez (AUTODISCOVER) and some with lowercase (autodiscover).

.htaccess
RewriteEngine On
RewriteRule ^.*$ autodiscover.php [NC,L]

Then you want to redirect the http requests to SSL-site:

Top of autodiscover.php:
if (empty($_SERVER['HTTPS']) ||  $_SERVER['HTTPS'] == 'off') {
    header("Location: https://autodiscovered.company.com".$_SERVER['REDIRECT_URL']);
}

From here you might realize that you need at least 2 DNS-entries:
autodiscover.domain.fi. IN CNAME autodiscover.anotherdomain.fi.
And in the anotherdomain.fi zone:
autodiscovered.anotherdomain.fi. IN A [IP ADDRESS]

The way autodiscover works is it asks for certain file for the email address. If the email address is person@mydomain.fi, then autodiscover asks for autodiscover.mydomain.fi/autodiscover (actually I probably don't remember the correct path now, as it was some while back, but you get the idea). When it finds this it will use several methods to retrieve the data, in order. You can actually find the methods just by testing autodiscover on some domain here: https://testconnectivity.microsoft.com/ , but this method works on the HTTP redirect method.

The autodiscover.mydomain.fi should be redirected to SSL-site, otherwise autodiscover rejects the redirection.

2-way databinding in javascript

I ahve been using angularJS for a while now and I've learned NOT to like it. I liked it at the beginning, I mean who wouldn't, it's pure magic. But when you get deeper to it, you will realize some deficiencies. I will only mention the one that was the biggest for my latest project: Performance. I had an application that has excel-like table with hundreds or even thousands of cells, that could have naturally even 30 x 2-way databindings inside them.

I actually fixed this (to some extent) with making updates manually, so in the end I didn't have much use of angular, since fixing it's short comings takes a lot of time.

Later on I noticed a great article on 1-way databinding with vanilla javascript. I haven't actually tested this anywhere yet, but will definitely keep it in mind. With code-sections / libraries like these I like to work with, but working with big frameworks, always brings downsides too. At least for me almost always they bring a lot of work with fixing the issues the framework brings with it.

So I suggest to read this article about the javascript 2-way binding:
http://www.sellarafaeli.com/blog/native_javascript_data_binding?utm_source=javascriptweekly&utm_medium=email

P.S. To be honest, I'm not even excited about angular 2. Even though it breaks the compatibility with 1.3, you would assume it should be really a lot better than 1.3, but reading about it doesn't get me positive about it at all.

Sunday, January 25, 2015

Difficult to check or initialize javascript object-tree

In javascript I have many times tried to get rid of these scenarios and I think most people don't even end up in these situations. I've ended up in them many many times. The situation is that I have to check if the object-tree exists like so:

function dataManipulator(dataFromOutside) {
   var one = dataFromOutside;

   if(one.two && one.two.three && one.two.three.four && one.two.three.four) {
      one.two.three.four.value = 1;
   }
}

And the same goes especially well with initializations:
   one = one || {};
   one.two = one.two || {};
   one.two.three = one.two.three || {};
   one.two.three.four = one.two.three.four || {};
   one.two.three.four.value = 1;

I ended up in these situations especially when I was using firebase (external database service) and also when I was programming a game, which had objects with big and complex data-structures.

EDIT:
So I finally decided to fix this issue. I have a tendency of thinking things only from one angle for too long, so this was a hard issue for me originally. I finally decided to use eval as I always avoid it, but this really calls for it. So here are object checker and initializer:

http://jsfiddle.net/cuh8yghj/

function objectInitializer(obj, path) {
   var pathSoFar = "obj";

   path.forEach(function(realIndex) {
      pathSoFar += "['" + realIndex + "']";
      if(eval(pathSoFar) === undefined || eval(pathSoFar) === null) {
         eval(pathSoFar + " = {}");
      }
   });
}

function objectChecker(obj, path) {
   var pathSoFar = "obj";

   return path.every(function(realIndex) {
      pathSoFar += "['" + realIndex + "']";
      if(eval(pathSoFar) === undefined || eval(pathSoFar) === null) {
         return false;
      }
       return true;
   });
   
}