Playing with HTML5

In the last weeks I have been playing with HTML5 in a very literal way, merging two of my interests: web development and video games. The result is a small arcade game which makes use of several features from the new web standard.

You can take a look at the code on GitHub at any time and even play it online here. Let me comment on some of the implementation details below:

The game loop

The game loop is implemented using the function setInterval() from the standard JS libraries. In particular, a callback is invoked 30 times per second: it checks the state of the game entities, updates them and then redraws the scene. This was the best option given that I’m not using any development framework.

Canvas

The game area is contained in a canvas. The canvas has been around long before HTML5 took shape, but it has received quite a lot of love recently in the form of acceleration. The game code is not specially designed for performance (after all, it was mostly developed in a week), and the scene is being completely redrawn 30 times per second. Nonetheless, I could try it in a first-generation Atom laptop with no noticeable lag.

Bitmaps

The canvas element has primitive operations to draw vector graphics (lines, bezier curves, text…) but 99% of the scene has been implemented using bitmaps, piled in several layers. This way of working is really similar to using a low-level graphic abstraction like SDL in the end.

What’s more, the bitmaps are sent to the browser packed in sheets that contain several sprites. It is a common technique in web development to save bandwidth and to overcome the limit in the number of simultaneous requests that browsers can send, but its use in video games dates from longer ago, when programmers had to deal with memory limitations.

Input

The game is controlled with the keyboard, and I use callbacks for standard key events (keyupkeydown) to check its state. These events act asynchronously and independently from the game loop, so the state of the keys is stored in an object which is checked in the update entities phase of the loop.

It also has to be taken into account that the key event callbacks are set on the canvas object, as a consequence events are lost if the focus moves out of the canvas. I have found some weird interactions when the focus changes while keys are pressed, so this part of the code definitely needs some work yet to become more robust.

Sound

I’ve used the web audio API to be able to manipulate sound with a high level of detail. Though I haven’t used most of its capabilities by far, it was worth connecting all the wires to make it work.

This API is designed as an audio flow going through several nodes, similarly to other popular multimedia frameworks. Each node has the ability to process the input in some way before sending it to the next node. I used only one intermediate node, the GainNode, to be able to mute the audio output at will, but it could have been used to implement an internal volume control.

Wishlist

A project is never complete with a list of things one would like to add, complete or polish. I’ve already mentioned some details worth revisiting, but there are also some features that I would have liked to use; examples are local storage to implement high score boards or network code to implement some sort of interaction between players. But in the end of the day, this has been a worthwhile exercise; I’m satisfied with the result and  I might still improve it in the future!

KiCad nas XII Xornadas Libres

De novo visito a  Facultade de Informática da Coruña para participar na seguinte edición das Xornadas Libres que organiza o GPUL. Para esta ocasión preparo un pequeno taller sobre KiCad coa axuda do meu compañeiro Samuel. Trataremos de mostrar un ciclo completo do deseño dun proxecto hardware usando esta ferramenta.

Así que este xoves 25 ás 18:00 haberá KiCad na Facultade, pero non olvidedes botarlle un ollo ao resto de actividades, que abranguen diversos aspectos da cultura libre; sen ir máis lonxe, o meu compañeiro Chema tamén estará alí para convencer aos desenvolvedores noveis da importancia de licenciar o seu software.

Vémonos alí!

New release: PhpReport 2.1!

Although I’ve recently changed of scene, there’s still some love for one of the eldest tools we have in Igalia, PhpReport. I’ve been gathering some hours here and there in the last months to be able to develop and ship a new batch of improvements. I would like to highlight some of them:

  • Now we have a way to block the edition of tasks after some time. You can configure a number of days after which users will not be able to insert new tasks or modify existing ones. This will prevent that huge changes in the past affect to your numbers without notice.
  • There is also a new report for users to check their list of tasks and search among them. It gives a higher-level view of your work than the day-to-day tasks interface, while providing more detail than the user or projects details screens. There is also a complementary web service that can be accessed by external scripts. The first commit of this feature dates back from 2010, so it has indeed been stopped for too much!
  • The annoying bug in the tasks screen that prevented you from saving correct tasks under certain conditions is finally gone. And since we were at it, we have modified the notification banners to show up only once.
  • Finally there’s some documentation for system administrators beyond the installation instructions.
  • We added a new boolean field to the tasks to mark specific tasks as done “on site”.
  • Implemented some keyboard shortcuts to increase the productivity in the tasks screen. In particular, you can quick jump to a task with CTRL + 1, 2, etc., save with CTRL + S or add a new task with CTRL + N. Alternatives with ALT exists for browsers not allowing to override these specific combinations, see the corresponding section in the user documentation for details.

The list could be wider, but you can already read it in the changelog. Meanwhile, you can download the new version, or try it online [EDIT: online demo not available any more]. Enjoy!

KiCad bug squashing, round 2

Here we are again with a new batch of fixes for KiCad, again with a focus on usability and UX. Those are the kind of things that make a piece of software outstand among its competitors 🙂

Cyrillic text plotted as ??? when I plot dxf from eeschema (#1107767): sometimes we developers don’t realize about all the variety of use cases out there… and this is specially true when managing user text input. In this particular case, non-ASCII text was not correctly plotted to .dxf files. Our fix outputs non-ASCII text as lines because that’s the most compatible option. It’s waiting to be merged.

Launcher: create empty directory for new projects (#1108773): a good practice for KiCad projects is saving them in their own directory, because they are comprised by several different files (schematic, board, netlist, libraries…) and they must be kept together to backup or distribute the project. From now on, KiCad will check if you are creating a project in a new directory and will suggest to do it if that’s not the case.

Eeschema: title bar provides outdated information (#1110651): I was myself very confused the first times I used the application and realized that the title bar was not updated after saving the project for the first time or with a new name. That lack of feedback makes the user doubt about the reliability of the software, even when the save operations were working correctly. Fortunately the support was already there and the problem was fixed with a very simple patch.

Inconsistency between confirmation dialogs (#1116059): the different KiCad sub-apps showed different exit confirmation dialogs. It’s not actually a terrible problem because the user was still being warned about losing unsaved changes, but those different messages with different options (Yes/No, Save/Don’t save/Cancel) gave a somehow unprofessional look. Now the three-option exit confirmation dialog is used in all cases.

Eeschema: schematic files might be saved having a wrong file extension (#1122212): this was again a UI consistency problem. Some save dialogs forced the addition of the file extension even when not explicitly set, while others didn’t. At the same time, most open file dialogs expected the files to have the proper extensions and that could lead to strange situations like saving a file without extension and not being able to open it until manually renamed. Antía’s patch is ready and waiting to be integrated upstream.

PcbNew: Insert a footprint in the board, from the Library Browser, by double clicking on it (#1125047): we had already done the same improvement to the library browser in Eeschema. It was a simple change but it greatly improved the usability of that window. We’ve just realized that the same was happening in Pcbnew; although it was less noticeable because you usually import all the components from the netlist and don’t add them manually, Antía fixed it too and we expect to have it upstream soon.

Finally, I sent an amendment to my patches for bugs #1101718 and #1102381 because I wasn’t really satisfied with the solution and, as I suspected, there was a simpler way to do things.

I would like to thank the KiCad community members for being so welcoming in the last months. We are very proud here at Igalia for taking part in this process and help improving the state of the art of EDA open source software. And remember that we are ready and available if you need some consultancy work on KiCad.

KiCad bug squashing, round 1

We have taken over the project bug tracker to get some issues fixed. Bugfixing is sometimes an annoying task , but provides one of the most tangible sensations of contribution as you see how real problems that affect to your users disappear 🙂

 

Here is a list of our recent contributions:

Eeschema: actions disabled during move operation can be accessed via hotkeys (#1092837): some actions that were disabled from the menus while doing special operations (drag, move) were accessible using their corresponding hotkeys. The fix of this bug resulted on a review of the hotkeys code: some new ones were added, and we made sure that their actions were undoable.

Set focus on the exit confirmation dialog button (#1092873): there are some UI behaviours we all are used to; one of them is using tab + enter or space to manipulate options in modal dialogs. You couldn’t do that in some dialogs because focus was not being correctly set, but it seemed to happen only in version 2.8 of wxWidgets for GTK+. After some discussion and patches back and forth, Dick Hollenbeck commited a fix.

Empty plot filename (#1101718): after you first save a project, some internal structures were not refreshed correctly, which caused that output operations that use the file name didn’t work as expected. In particular, when plotting a schematic the output file got an empty name.

Eeschema: -cache.lib file not created the first time you save (#1102381): as another consequence of the previous bug, the library cache files were saved with an empty name too. Our patches for both are already merged.

Pcbnew: crash when deleting a track (#1108717): a blocking stdout operation was freezing the UI when the program was launched under certain conditions. It seems to be a problem happening only in debug builds and there’s no agreement about how to fix it, so we will live with it; after all, real users are not affected.

Eeschema: error message when opening a file with a long path from the command line (#1108838): this bug was a consequence of file paths not being correctly normalized (make absolute, remove .. and . directories) when creating the lock files. A patch is waiting to be pushed.

We detected and reported other bugs, some were already fixed by other community members and others are patiently waiting for the next bug squashing round, live from Igalia!