Introduction to Arc

by Clay Smith (clayasaurus)

Preamble

I am Clay Smith (clayasaurus) and I wrote ArcLib in my spare time so that I would have a nice library to write 2D games in. However, I have opened it up as a community project so that others won’t have to reinvent the wheel and D can have a solid system to write 2D games in. Being a community project first are foremost, contributions, suggestions, and posting on the forums is most welcome. While the library is geared towards hobbyists, it is fine to use ArcLib to write commercial games as well, as long as abides by the permissive zlib/png license.

The first two releases of ArcLib have it designed as one monolithic library. Lately, however, I have changed up the structure so that there is a small core library with various extension libraries. This allows a great flexibility so others may more easily contribute to the library by simply writing an ‘extension,’ without having to touch the core. Extensions also allows me to support conflicting features, such as per-pixel collision and 2d physics, and I let the user decide which suits the game the best. Having extensions means the small ArcLib core is more maintainable, and there will be more code available to the users of the library to pick and choose from, that others may contribute through extensions without any maintenance on my part, and that the system is broken down so a newcomer to the library may easily see where the code they want is. The extension system allows for greater flexibility overall.

ArcLib is designed to be…

1) Completely free to use for commercial games, this is done using the zlib/png license and avoidance of dependencies on commercial libraries.

2) Easy to use. ArcLib + DSSS/xfbuild should increase game development productivity dramatically. If any part of the library or extensions is troubling you, post on the forum.

3) Cross Platform, this is done by having only using cross platform libraries to build Arc upon. The libraries I use are…

  • OpenGL – Standard API for quality cross platform graphics
  • OpenAL – Free high quality audio system
  • SDL – Cross platform toolkit for Window/Input access
  • SDL_image – Image loading
  • FreeTypeTrueType font rendering

4) Full featured
  • Core API features an OpenAL based sound API, FreeType font rendering API, drawing primitives, input API, window API, math API, texturing API that can load up png/jpg/tga/bmp/gif/pcx/lbm/xpm/pnm graphics files, and timing utilities, basic resource management hidden from API that prevents loading the exact same file twice
  • GUI system extension that reads GUI from XML file
  • 2D Physics Engine support through a Blaze extension
  • Particle system extension
  • Camera extension that allows one to move around the game world
  • 2D Lighting extension that supports soft shadows
  • Sprite extension that supports sprites with multiple animations and sound effects
  • Per-pixel extension allows per-pixel collision detection

Now that you are familiar with the library, this tutorial will teach you how to set up your D compiler environment on Windows and compile a simple 'Hello World' test application.

  • Tip: If you need more help then these friendly tip's, come and ask in the forums.

Setting up the D compiler environment

1. Download and install the D compiler

2. Set up Eclipse with the descent IDE

  • Grab descent here
  • Follow the instruction on the site to install descent into eclipse
  • The Descent/Eclipse combo is simply the best IDE for D I’ve found

3. Testing your shiny new D compiler.

Using your favorite text editor or D IDE, create the following file and name it ‘main.d’

import tango.io.Console;

int main()
{
   Cout("Hello D World!\n");
   return 0;
}

In this tutorial I’m going to assume you are familiar with the command prompt. On windows, you get access to the command prompt through Start->Run and then type ‘cmd’ in the box and press ok. To switch drives, simply type the drive letter of your choice, like ‘d:’, ‘c:’, or ‘j:’. To move to a specific path, use the ‘cd’ command like ‘cd C:\program files\my path.’ Use the tab key for auto-completion of the text you write as well. Make sure you know how to move around directories in the command prompt before moving on with this tutorial.

Now, to test your code we are going to create a dsss configuration file that will build your program. Use the text editor of your choice to create this file and save it as dsss.conf, and put it in the same directory where you have saved the ‘main.d’ file.

[main.d]

Now, on the command prompt, type ‘dsss build.’ DSSS should build your program and then you can run it manually to test if it works. Learn how to use and work with DSSS, as DSSS simplifies managing D software and is the tool we will use throughout this tutorial to work with ArcLib.

Setting up Arc

1. Setting it up.

Once you have DSSS installed, it is easy to install ArcLib as long as you have a connection to the internet. Use the command from the command prompt

svn co http://svn.dsource.org/projects/arclib /trunk arclib
cd arclib/
dsss build & dsss install

Which builds the latest trunk arclib, for older version look in the branches/ svn folder.

[main.d]

From now on, DSSS will automatically link ArcLib and derelict when it finds imports of those libraries in your code.

  • Tip: DSSS net install is not supported anymore

ArcLib libraries will install in your dsss/bin folder. Windows users will need to grab their dll's from http://svn.dsource.org/projects/arclib/downloads/dll/ and place it in the folder the .exe file is in, but Linux users will have to use their favorite package manager and install SDL, SDL_image, OpenAL and Ogg/Vorbis, OpenGL drivers, and Freetype2 libraries.

2. Hello World.

Create a file called ‘main.d’ and set up an appropriate DSSS configuration file for it.

module hello;

import arc.all;

class MyGame : Game
{
    this(char[] argT, Size argS, bool argFS)
    {
        super(argT, argS, argFS);
        font = new Font("font.ttf", 16);
    }

    void process()
    {
        font.draw("Hello Arc World", arc.input.mousePos, Color.White);
    }

    // shutdown coder here
    void shutdown()
    {
    }

    // game vars, etc.
    Font font; 
}


// main entry
int main()
{
    // initialize game
    Game g = new MyGame("Hello Arc World", Size.d640x480, false);

    // loop game
    g.loop();

    // shutdown() is called by loop() after loop exits
    return 0;
}

Compile this code with the command ‘dsss build’ and run this code and you should get a window that pops up that says 'Hello Arc World.' Note that you will need the ‘font.ttf’ file, which can be found here.

Summary

Now that you have a good working knowledge of the philosophy behind Arc and how to install it and say ‘Hello World,’ you are ready to move onto the viewing the arclib examples ArcLib Examples. These examples show how to use every single feature of ArcLib.

Please visit me in my forums for comments and suggestions.


this tutorial is licensed under the Creative Commons license

/+ Multimedia development for the D Programming Language +/