Wednesday, March 29, 2017

Progress is slow though inevitable, but is that enough?



I have a family with my wife and ~4 year old daughter. This makes me mentally tired quite often which is obviously not good for developing the game. Now I am an optimist regarding development and my attitude is that I will get there sooner or later. Well I am right, but also wrong.

I really didn't take into account all the facts, like the one, that I can not develop the game for too long of a period. I've already switched game library once and started to use javascript ES2015 version. If I spend a seriously longer period of developing it, then I could end up with a game that is out dated, already on the release day.

So I switched to working 4-days a week ~half a year ago. That was a good thing, but then even with 1 day of focusing on the development, it's isn't exactly fast. I took a big piece of the cake with this project and then there's also changing the workplace. I've practically resigned from my old place and will switch jobs soon with the plan to have 1-2 months of free time before another job position, to boost the development of the game.

The 4-days a week was a good deal and I have got my game progressing faster. But as an unfortunate timing, there were some inevitable events that got a big chunk of my time. I'm talking specifically about changing workplace (going to interviews etc.) and something personal that needed contemplation upon. Latter one came up during the last December and interrupted my game development pretty much totally for 2 months. I believe on the long run those are beneficial to me and thus to the game development, but on the short term, they did (and do) slow down the game development.



Luckily the summer is approaching and if you don't live up north (like Scandinavia), then you might not realize how much it affects the life here. People get a lot more energetic, when you get to actually see the sun sometimes :). There are places and time periods in Finland, when the sun doesn't actually rise at all. Summer will also boost my productivity during the next half a year. Even simply the need for sleep is less, when there is more light.

So my hopes and enthusiasm to get the game developed on overdrive, for the next half a year are quite high and I'm finally reaching a stage where I've got the main browser- and server-side logic working and can start working on the actual prototype / alpha version. So things start to look more promising and also more motivating for me (and all the millions of fans the game has... :))

Tuesday, January 10, 2017

Development challenges with javascript

(https://pixabay.com/en/technology-computer-black-code-1283624/)

Short intro

I've had so many interesting problems, challenges and moments of frustration with making the game with javascript, that I just have to share them. If you don't care about programming or javascript, feel free to skip this post and return for the next one, which should be more game development oriented.

This is probably the longest post I have made so far.

Standard coding style and linting

Description of linting from wikipedia:
Lint-like tools generally perform static analysis of source code.

Lint as a term can also refer more broadly to syntactic discrepancies in general, especially in interpreted languages like JavaScript and Python. For example, modern lint checkers are often used to find code that doesn't correspond to certain style guidelines. They can also be used as simple debuggers for common errors, or hard to find errors such as heisenbugs.
When you program, you always have a big variety of possibilities, which you can use to manage obstacles and construct the code. I am quite organized programmer when it comes to the style of the code and I love to have a standard approach to programming, whether it's my style or someone else's. So for me setting up a standard for code organizing, comes quite naturally. I don't have to specifically force myself to be excited about it.

In a company that has multiple developers, I would argue it's almost always a good approach to have a coding standards that everybody applies in their code. I happen to work in a company, where you might end up working in somebody else's codebase at anytime and it's very useful if people write the code with the same set of rules. I know I have suffered from this on multiple occasions.

Well with all this nice introduction talk to code organization, I'm not developing my game in a company am I? Nor are there even any other developers involved with the project really. So we have quite a different starting point here. Still there are some good points in having a standard coding rules.

Since I have been doing the game alone, I can admit it has not always been a smart choice to be very strict and enthusiastic regarding standard coding style. The pros and cons I would consider are something like this:

Personal projects

Pros:
  • When you look at old code, you understand it faster.
  • With some personalities, it can give you a piece of mind :)
  • If you setup linter only with syntax checking it will very likely just simply save time for you, as it spots errors, that would otherwise cause syntax errors or difficult to spot bugs.
Cons:
  • Sometime (e.g. when copy pasting) you might have to format the code manually.
  • It takes time to setup and maintain. Especially the more extensive the style rules are.

Company environment

Pros
  • Other people can look at your code, or you can look at other peoples code and understand the functionality much faster
  • Code reuse and sharing is easier
  • Teaching of solutions is more understandable
  • Easier to read source code of the company's code and thus save time
  • Fixing bugs on other peoples code is sometimes a lot more easier
Cons
  • Somebody has to push it internally and enforce it to be used inside the company
  • You might end up in disagreements regarding used coding styles
  • Somebody has to also look after other peoples codebase and make sure they follow the standard (linters can be used automatically, but if you really want code structure to be organized well, it is not always possible with automated tools).

Environment for multiple developers

I also made the whole project from the "open source and multiple developers"-perspective, so the base for the project would allow for simultaneous development. When I did this I was kind of hoping and dreaming. Realistically I did take into consideration it's very possible, there are not other people involved with it (and I even more assumed that). I still went to the path of setting the project for making it possible for multiple developers to develop the game engine.

This was a mistake. I have learned a lot through it too, so it wasn't a total waste of time, but later on when I realized how hard it is to make a game, I realized I should have cut the corner with this one.

I believe it was a good end goal, but I started it too early. For example CONTRIBUTING.md and gitter channels have been useless so far. Also I have fairly good documentation for the project and way less would have been sufficient for myself. Now if I would do 100% proper job, I would need to keep them up-to-date, which I don't cause it is not a wise option at this stage. And the end situation is that, I have out-dated and crappy documentation, since I'm fairly sure, no one else will start to develop it. Thus everybody will be less eager to do that, if there were somebody interested.

Though I do need to take into account the experience I've gained from doing all this. The project was always more emphasized as a hobby to learn and try out things, rather than something that brings me any real value. So fortunately, I've always been fairly realistic with this.

ES6 / ES 2015

ES6 is a synonym for ES 2015, both mean a specific version of javascript. Javascript took a big leap in new features and changes in that version, so I decided to hop on to that train. I regret that decision, even though I do want to take into account the massive amount of experience I have gained through the regrettable choice nonetheless.

I decided to choose the newer version of javascript, because I was always quite realistic with the project, in the sense that I knew it will take years to make it ready. During that time, the newer javascript of version would be usable by almost all the browsers. This was a wise theory and there was no issue with this. It seems that I was right on, with this theory, but there were other things I didn't take into account properly. The actual issue came with all the tools and other things that made the whole workflow more difficult to develop with and slowed the development down. One of the biggest strengths of browser environment is that you can code things basically live, if you wish to.

Description of transpiler from wikipedia:
source-to-source compilertranscompiler or transpiler is a type of compiler that takes the source code of a program written in one programming language as its input and produces the equivalent source code in another programming language
Choosing ES6 before it was actually supported by any browser fully, meant that I needed a transpiler (transpiler changes code written in ES6 to earlier ES5 and thus lets you use the code in browsers that don't support the new version yet). Having a transpiler, means having a whole set of workflow just to convert your code to something the browser can use. This was supposed to be a short and simple step, but it wasn't (more on the next chapter). What was the biggest issue with ES6 for me was the new features of exporting and importing modules, which ended up being the weakest standard in ES6.

There were also good new features in ES6 that I really liked, like arrow functions and default parameters. With default parameters I had some learning curve, as I was used to dealing with object literals and in general quite simple way of coding, I tried to use them originally with object parameters as such:
function custom(value, options = {property1: { property2: 2 }, property3: 3}) {}
Well I can tell you that doesn't work. It does not in the end make sense to even allow that, because then the function definitions might become really chaotic and long. So I had to use and try it out for a while, to actually realize it's just simply not how you should do things. You can always define another class / function that acts as an interface and use that, like so:
function custom(value, options = {}) {
    options = createOptionsProperty(options);
}
And the code will be much cleaner and clearer.

Javascript modules with webpack

So this was the thing that was really the clearest mistake I did. I really don't know did waste more of my time than other bad or questionable choices, but this one was just clearly a mistake, that I would have wanted to avoid (both by draining me mentally and using up my time).

Since I jumped on the ES6 train, I needed to have a workflow, where I write ES6 code and it gets changed to ES5 code. This would probably not have been an issue, if I would not have been using all of the new ES6 features, especially the import and export keywords. These keywords enable a standard way to split the whole structure to smaller files and modules. So in one file, you can import other files and modules to it by importing them at the start of the file, basically like in most other programming languages. Sounds nice? Sure, but there already were other non-standard approaches to importing and exporting. I could have used those, but I just wanted to be too stubborn and "on the frontier of javascript"-hippie.

There are tons of guides how to do transpiling, how hard could it be? First I went for jspm, since that was easy to setup. I did that for a long while in the beginning, until I reached a state where I wanted to have an option to bundle a javascript file without transpiling from ES6 to ES5. Since the game was expected to be ran natively with ES6 and not ES5. Well this proved to be an overwhelming task. On top of that, I discovered later, that the browsers were actually slower with native ES6 functions, than the transpiled version. They might still be, not sure of the present situation. Of course I decided during this to try out different libraries, to see how they work and which one would work best. Mostly I tried webpack, jspm and browserify. I setup the workflow with each one of them, but always encountered an issue, that was hard to get around.

I calculated the amount that I spent on trying to achieve the whole workflow and it was around 50 hours and that is a huge amount of time, when we are talking of one hobbyist free-time game developer. In the end I ended up switching my whole code base to use global module format. Months later when I again had the energy and time to get into the module workflow, I switched back to using the import and export keywords and succeeded with it. So I ended up using more than 50 hours for a task (probably around 80).

When I was using global module format, I had a complete workflow built with gulp and it worked nicely, but using a proper module format and workflow makes the whole package easier to handle and also the source maps work much better. Getting the modules working well would not have been in any way essential to the project, but because of my initial choices, I simply had to be able to do it. I needed to get piece of mind with it and to get the advantages it provided me (like properly working source maps).

Tuesday, November 15, 2016

Family life mixed with game development

I think I have mentioned this before, but starting to make an overly ambitious game, when you start to raise a family, is not the smartest of choices :). I would have had plenty of other moments and opportunities in my life to do so. You can't change the past, but you can choose your future. I think going after your dreams and having challenges and goals in your life is important to a successful life and that is definitely what I have been doing. Though often doubting it and being tired also, but always pushing forward.

Freetime, what is that?

Trying to mix together my family (one 3½y old daughter and a wife) and full-time work does not leave a lot of time to develop a game. We also have to take into consideration, that developing a game on free-time for extended period of time is very creative work and requires yourself to nourish that creativity and keep the passion and drive to do a good game, be innovative and think outside the box. Now what happens when you go on for 3½ years and don't even have an engine completely ready? You can run out of passion and drive fast and you will be more like a raisin regarding creativity than a juicy grape and you might even have hard time believing in the project anymore. That is why you definitely need some real free-time to meet family, friends and do other stuff.

Around a month ago, I decided that because this is very stressful and it goes forward very slowly, I will drop one day of from my work (so 4-days a week working). We don't have car, we live a modest life, so financially it's ok, until our daughter becomes a teenager and starts draining all my money :D.

My normal routine is to wake up at 5:00 around every other morning to develop the game 1-2 hours, before I have to take my daughter to daycare or leave for work. I do development sometimes on weekends too. After I decided to take every wednesday off from work to make my game I have been getting a bit more motivation and development done. I feel now like I can actually finish the project and I have set myself some timelines for that.

What freetime feels like now

Can you imagine how great it was to just be with my close gamer friends on our already traditional cottage trip a week ago? The funny part is that I have spent so much time at home making the game and spending time with my family, that I actually even forgot what it is to have fun with friends. It's such a dangerous thing to notice. But I'm really really grateful to have this group of friends in my life, who have been there for a long time already and who I count to be there for a long time still. And to keep me sane.

So I have decided to start having more time for myself to basically boost my creativity and motivation. I am already pretty close to getting the engine done, few months and I should have developer-oriented prototype ready and that is when I really need to be sharp and creative. So far it has been a fun, easy and enjoyable ride, just coding and designing mostly, doing what ever I want mostly. But after this phase is over, the actual huge game design challenges await me. I have read so much about game development and still never really got the opportunity to challenge the knowledge I have learned.

Edit:
I actually forgot that there were couple really good inspirations to a situation of mine (family + game development), one that I really liked and care to share a link to: http://www.bluethumbsgaming.com/single-post/2016/06/06/Parttime-game-development-and-life-balance

Monday, April 4, 2016

Game programming is different and challenging!

Game programming, compared to average software development, pfff...

It has really surprised me. I know that if you go to physics engine level, then you have to be very fond of mathematics and algorithms, but even this level of quite simple game programming requires more and diverse skills than my normal project. The game engine I am making (https://github.com/Hachitus/FlaTWorld) presents tasks and interesting challenges that I really don't encounter in normal javascript software programming. I like it!

And I hate it!

Rambling about math

My mind is not math-oriented, I actually did like mathematics in elementary school, but after that I started disliking it. My mind does not bend on abstract concepts that well and when you get to higher mathematics (and talking about college higher class mathematics, which is not even very high), my mind has troubles processing the data. Normally in programming that is not an issue, my mind is able to process programming as the concepts are still pretty concrete and solid.

So why I started talking about mathematics, is because game programming requires it. In my case even as simple situations as calculating clicks on the screen, related to hexagons. That has been one of my achilles heels, in my game project. Other one was using ES6 modules. Or not really using them, but trying to bundle them for production. I spent ~50h and couldn't get the project running with it, so I reverted to globals. Not a good solution, but that was unfortunately my only option at that point.

But I get over them eventually, that is at least something I have learned in programming so far. You always get past obstacles, if you try hard enough!

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.