Irrlicht Newton GD tutorial: application architecture
Basic terms
Let’s talk a bit about our application before we create it. In order to make the development process sequential and least painful, we need to design the application well. The design of an application or the application architecture is the hardest thing to change on later stages of development. Thus it must be well-thought at the very beginning to prevent suffering in the future.
Well, there are number of application architecture’ levels:
![](/images/irrlicht-newton-tutorials/japan_feudal_system.webp)
The highest level defines which modules will the whole application consist of and what functionality will each of those modules have.
<p>
The next level is how the modules communicate to each other, how they work together.
</p>
<p>
The lower level is the structure of each module - what classes, entities, data structures and similar things will
the module consist of.
</p>
<p>
One of the lowest, yet still very important architecture levels is how files are organized.
</p>
</div>
From the highest architecture layer point of view, I can advice a very simple architecture:
- a stable, rarely changed core
- a set of assets (models, textures, sounds - any content, made by artists and used to be presented to the player)
- a bunch of scripts, defining all the logic of a game (how character looks like, how the menus are shown and how they react to player’s actions)
The main benefits of such an approach are:
- scripts and assets may be changed at any time
- scripts and assets define what we show to the user and how the application behaves, so we can changes them without the need to re-compile the core
- we can modify the core (for example - optimize some features) without changing the application behaviour
We can make the core so flexible that we may re-use it in the future projects.
The tools
We will use Irrlicht engine because of its simplicity. And it satisfies all our needs - it does not need much content preparation; it provides GUI; extending it with IrrKlang will give us very simple interface to sound and music playback.
Newton Game Dynamics engine we will use to simulate physics. It is easy to use and is really powerful - you would be impressed!
The last, not the least, we will use Lua scripting language to write scripts. Lua is a lightweight programming language and perfectly suits that goal.
One of the most beautiful parts of this tutorial, will be the part on making of assets. We will use Blender 3D to create a couple of 3D models.
I also found CMake kind of user-friendly. It is not that handy as any of dependency managers for all
those languages, supporting them (npm
for JavaScript, go get
for Go, RubyGems
for Ruby, leiningen
for Clojure and many others). Yet it makes your project a little more portable, helps to handle your
dependencies, totally eliminates the need of all those How to configure VisualStudio for OGRE tutorials.
Just try it!
Conclusion
Remember all the three rules for our architecture. And keeping them in mind, let’s get to some coding already!
Irrlicht Newton GD tutorial: introduction
What will you learn?
This tutorial covers the development of a game from a very beginning. This includes:
- planning the architecture for a game
- developing the game engine
- defining game logic with scripts
- creating 3d models
- and distributing the application
And of course, the whole tutorial is built around Irrlicht and Newton Game Dynamics libraries.
As for {{ site.time | date: ‘%d %b %Y’ }}, the tutorial covers:
- an introduction to NewtonGD
- creating Irrlicht-powered application
- controlling the application logic with Lua scripts
- building application with CMake
Why writing everything from scratch? Why not use Unity / Unreal Engine / you-name-it?
There are some well-known and used game engines like Unreal Engine 4, Unity 3D and others. They all come with enormous amount of learning materials. So why this tutorial might be interesting for you? You might want to know how things work and thus get most flexibility out of your tools. Or even start working on building your own tools.
What should I know to proceed?
I expect you to have at least some experience with these three things:
- C++
- computer graphics
- game development
The latter - to make sure, you will not call 3d models “textures” or miss the “script” word’ meaning.
Why these libraries?
Irrlicht is easy to use and contains all the features you will need to build a game - resource management, support for majority of asset formats out-of-the-box, user input (keyboard, mouse and joystick events handling), GUI (Graphical User Interface - buttons, text inputs, etc.).
Irrlicht is easy to use and contains all the features you will need to build a game - resource management, support for majority of asset formats out-of-the-box, user input (keyboard, mouse and joystick events handling), GUI (Graphical User Interface - buttons, text inputs, etc.).
Newton Game Dynamics is also very easy to use; it is constantly developed; and it is darn powerful!
If you are still interested - please proceed to the first chapter.
ReactJS introduction
Foreword
Last time I wrote an article on how one can encapsulate both HTML and CSS in one entity, called WebComponent. This time I want to tell a bit about how to encapsulate JavaScript and HTML.
When I see an article on Habrahabr titled React something, I think Omg, React again?... But React, just as Ember was always a mystery for me.
Until today.
About Bower, WebComponents and the all the good
![](/images/Pg-02-shakespeare-getty.webp)
BEM
These days, many web developers use different methodologies to make their web page source look structured and clean. But all those methodologies only work well until you use third-party libraries or involve a new person in your project.
Memory allocation in ASM
Currently I am working on a long arithmetic problem at the university. This problem is much more complicated than I described or than a task I shall be describing now, but here’s the thing: I needed some part of memory to be allocated from within my function. And I needed this to be done in assembly.
Assembly in C++ programs
Foreword
Writing code in assembly language in 2015 seems stupid and meaningless. Yet, it has a few huge benefits:
- understanding how computers / compilers / programs work
- hardcore optimizations for performance-critical applications
- just for fun!
Well, in real life, I’ve never met conditions of such performance requirements when I should be writing some parts of application in ASM. Except, maybe, a handful of ACM ICPC problems.
Those are two merely big benefits to write in assembly. Thus, if you are not getting fun out of coding, you may not be interested in this blog.
This blog is mostly for academical purposes. People who study something like low-level programming at the university may be interested.
ShootThem!
A few days ago I’ve found my old game, ShootThem! sources.
Half of hour being trying to run it, and viola!
I have hosted sources with all the dependencies on GitHub.
One has no story (in-game, but has one written before the game presentation on a programming competition for students in Dnepropetrovsk). It has (almost) no colors. No code structure or architecture. No animations.
It is really plain.
Yet, it was and still it is a starting point for me 😁
Here are some of game screenshots:
![](/images/tumblr/shootthem/tumblr_inline_nmea8sxPPW1qh5oee_640.png)
![](/images/tumblr/shootthem/tumblr_inline_nmea966kmi1qh5oee_640.png)
![](/images/tumblr/shootthem/tumblr_inline_nmea9pD5Nj1qh5oee_640.png)
![](/images/tumblr/shootthem/tumblr_inline_nmeaa4oVAD1qh5oee_640.png)
![](/images/tumblr/shootthem/tumblr_inline_nmeaaiOKq51qh5oee_640.png)
Running Qt + MySQL application
Yesterday I tried to run my university project made with Qt and MySQL. But all I got was strange error message, saying QMYSQL driver is not loaded
whilst loaded driver list actually included that one.
Searching all over the internet up ‘til 2 AM and recompiling the whole Qt gave no result except time being wasted. Yeah, and 90% of search results were tutorials on how to recompile Qt MySQL plugin under Windows.
Yet in the morning I found solution and it was beautifully simple! I just performed one step from Deploying Qt applications, actually just copied the plugins/
directory to the dir where the application executable lives (build-debug/
or build-release/
for my project; I hate the default build-#{ProjectName}-Desktop_5_4_1-Debug/
paths); included the sqldrivers/
directory there (just copied) and created (a bit tuned although) the qt.conf
file. That file just pointed the plugins path to the custom one:
[Paths]
Prefix=.
Plugins=./plugins
To sum everything up:
- create a
plugins/
directory in your build directory - copy
Qt/5.4/Src/qtbase/plugins/platforms/
there - copy
Qt/5.4/gcc_64/plugins/sqldrivers/
there too - create
qt.conf
file in build directory and fill it as mentioned above
And one more hint before the end: to debug why your Qt plugins fail use this application startup switch: QT_DEBUG_PLUGINS=1 ./app_name
- this will display plugins debug information.
Tiny java code...
This one was super easy so I did a quick comparison of a couple of ways you can do it; the goal is to count all the alphanumeric (a-zA-Z0-9) characters in the text of a Sherlock Holmes book. There’s probably other ways do do it because there’s lots of ways to do literally anything, but the fastest one here is stripping out all non-alphanumeric characters (\W).
//*********************************************//
// //
// EASY DAILY PROGRAMMING TASK #19 //
// ALPHANUMERIC CHARACTER COUNTING //
// //
//*********************************************//
public void count1(String text) {
long start = System.currentTimeMillis();
int count = 0;
for (char c : text.toCharArray()) {
if ((c + "").matches("[a-zA-Z0-9]")) {
count++;
}
}
long end = System.currentTimeMillis();
System.out.println("Count 1: " + count + " Time taken: " + (end - start));
}
public void count2(String text) {
long start = System.currentTimeMillis();
int count1 = text.length();
text = text.replaceAll("\\w", "");
long end = System.currentTimeMillis();
System.out.println("Count 2: " + (count1 - text.length()) + " Time taken: " + (end - start));
}
public void count3(String text) {
long start = System.currentTimeMillis();
text = text.replaceAll("\\W", "");
long end = System.currentTimeMillis();
System.out.println("Count 3: " + text.length() + " Time taken: " + (end - start));
}
Countiung all alphanumeric characters in Sherlock.txt:
Count 1: 432188 Time taken: 269
Count 2: 432188 Time taken: 53
Count 3: 432188 Time taken: 22
The new hardcore
![](/tumblr_files/tumblr_nls50x91hr1qio88bo1_1280.png)
Trying some new hardcore - Assembly in Emacs 😁