Thursday, September 3, 2015

Perkun as a library.

Imagine you would like to use Perkun (http://sourceforge.net/projects/perkun/) as a library in your own project. It is possible! Take a look at my game: Perkun Wars (http://sourceforge.net/projects/perkunwars/).

In your configure.ac you have to add the line:

PKG_CHECK_MODULES([PERKUN], [libperkun >= 0.0.7])

In src/Makefile.am you will add the flags defined by this macro - PERKUN_CFLAGS to AM_CXXFLAGS and PERKUN_LIBS to your LDADD. For example:

AM_CXXFLAGS = @CXXFLAGS@ \
    -I.. -I../inc \
    @XML_CFLAGS@ @GTK_CFLAGS@ @PERKUN_CFLAGS@ \
    -DDATADIR=\"$(datadir)\"


perkun_wars_LDADD = \
    @LIBS@ @GTK_LIBS@ @PERKUN_LIBS@ @XML_LIBS@


In your header file you need to include <perkun.h>. See the file inc/perkun_wars.h.

Define a new class inheriting perkun::optimizer_with_all_data, In Perkun Wars it is the class npc.

Instantiate the class and run the perkun interpreter (see the file src/perkun_wars.cc, function main_perkun). You run the interpreter calling the function "parse".

This function main_perkun runs in a separate process, because in Perkun specification we use the loop. But there are pipes in place and the redefined virtual functions of the class npc communicate with the main process through the pipes. In fact there are three extra processes in Perkun Wars. They are named after the heros:
  • Dorban
  • Pregor
  • Thragos

No comments:

Post a Comment