15. December 2011

How to define C++ macro with string content and pass it to MSbuild

Imagine that we have C++ project e.g. for Visual Studio 2008. It is possible to build this project just by msbuild command:

msbuild MyProject.vcproj /p:Configuration="Release"

Let say that we want to use #define in the source code. It is necessary to define it in Configuration Properties > C++ > Command Line:

/DSIMPLE_DEFINE

This just pass SIMPLE_DEFINE as flag.

How to deal with string define which should behave like string? E.g.:

#define URL "http://georgik.sinusgear.com"

The trick is in escaping quotes. We can add following define to Command Line:

/DURL=\"http://georgik.sinusgear.com\"

It will transform into .vcproj file:

AdditionalOptions="/DURL=\"http://georgik.sinusgear.com\""

Let’s make one more step.

How to acquire such a define from environment variable? E.g. with following build.bat file:

set URL="http://georgik.sinusgear.com"
msbuild MyProject.vcproj /p:Configuration="Release"

It requires only small modification of .vcproj file:

AdditionalOptions="/DURL=\"$(URL)\""

­čśë

Small recap of flow: set env variable – pass it to XML – pass it compiler – pass it to code

18. March 2011

Collajader 0.3 – web preview of Collada format

Update: Collajader 0.2 was released. Check videos below.

Update 2: Collajader 0.3 was released. Added support for orbit camera.

There are several 3D libraries for Flash which are able to display 3D model in RIA application.

Tools like Blender and CAD/CAM software are able to generate Collada format (.dae). Alternativa3D support this format. You can load Collada file directly into application with Alternativa3D.

The only problem of exported model is that it contains a lot of other information that you do not need for rendering.

I created simple tool Collajader which is able to display content defined in Collada format in the web browser. You don’t need to start any 3D software and you can still finetune some details of the model.

Here is small screencast which shows how it works.

Update for version 0.2

You can access application here: Collajader 0.3.

Please, let me know if you find this application interesting.

10. January 2011

PyXML is dead project – warning: PyXML does not work with Python2.6

PyXML project has been dead for several years. Last version was released in 2004.

When you try to install PyXML with Python 2.6 you’ll get following error:

Failed to load application: invalid syntax (ParsedAbbreviatedRelativeLocationPath.py, line 31)

When you try to start PyXML with Python 2.5 you could see nice compiler warning:

python2.5 xml/xpath/ParsedAbbreviatedAbsoluteLocationPath.py

xml/xpath/ParsedAbbreviatedAbsoluteLocationPath.py:27:

Warning: ‘as’ will become a reserved keyword in Python 2.6

Problem is caused by following line:

´╗┐as = ParsedAxisSpecifier.ParsedAxisSpecifier('descendant-or-self')

PyXML is dead project. It does not accept patches. Some Linux distros already excluded it from repositories and Windows version for new Python does not exist as well.

Try to avoid using PyXML and replace it e.g. by xml.dom.minidom or elemettree.

7. October 2010

Prechádzka po XML s namespace v Pythone

V predch├ídzaj├║com pr├şspevku “Jednoduch├í prech├ídzka po XML v Pythone”, som uk├ízal, ako je mo┼żn├ę parsova┼ą XML pomocou Pythonu.

─îo ale v pr├şpade, ┼że potrebujeme pou┼żi┼ą namespace?

Namespace sa expanduje do tvaru {namespace}element. ─îo sa odraz├ş napr├şklad v pr├şkaze find. V├Żsledn├Ż k├│d bude vyzera┼ą nasledovne:

from xml.etree import ElementTree
xmlTest="""
 <s:xml xmlns:s="library://ns.adobe.com/flex">
  <s:person>
  <s:id>573280</s:id>
  <s:type>Supplier</s:type>
 </s:person>
 <s:person>
  <s:id>66172</s:id>
  <s:type>Customer</s:type>
 </s:person>
</s:xml>
"""

tree = ElementTree.fromstring(xmlTest)

namespace="library://ns.adobe.com/flex"
for person in tree:
  type = person.find('{%s}type' % namespace)
  id = person.find('{library://ns.adobe.com/flex}id')
  if type.text == 'Supplier':
    print "Supplier:",id.text

V┼íimnime si jednoduch├Ż trik s %s na riadku s type = person.find.

15. June 2010

Jednoduchá prechádzka po XML pomocou Pythonu

Tak├í u┼żito─Źn├í vec, mo┼żno sa niekomu hod├ş. ElementTree pre Python obsahuje parser XML. V nasleduj├║com pr├şklade vyrob├şm zo stringu Element a n├ísledne nad n├şm spust├şm iter├íciu cez for.

Je d├┤le┼żit├ę upozorni┼ą, ┼że find vracia prvky Element. Textov├Ż obsah z nich je mo┼żn├ę vytiahnu┼ą pomocou atrib├║tu text.

Pokia─ż sa s t├Żm chcete viac hra┼ą, odpor├║─Źam pou┼żi┼ą iPython shell, ktor├Ż podporuje dop─║┼łnanie pr├şkazov pomocou tabul├ítoru.

from xml.etree import ElementTree

xmlTest="""
<xml>
<person>
 <id>573280</id>
 <type>Supplier<type>
</person>
<person>
 <id>66172<id>
 <type>Customer</type>
</person>
</xml>
"""

tree = ElementTree.fromstring(xmlTest)

for person in tree:
    type = person.find('type')
    id = person.find('id')
    if type.text == 'Supplier':
        print "Supplier:",id.text

API k ElemenTree n├íjdete na python.org. Pre Debian je t├íto funkcionalita k dispoz├şcii v bal├ş─Źku python-elementtree.

23. January 2010

Tvorba m├íp do hier – TaT Tile Map Editor

Pod─ża m├┤jho n├ízoru, vytvorenie po─Ź├şta─Źovej hry prever├ş v┼íetky developersk├ę zru─Źnosti. Znalos┼ą v├Żvoj├írskych n├ístrojov, programovacieho jazyka a debuggeru je z├íklad. To v┼íak rozhodne nie je v┼íetko. Prever├ş aj to, ─Źi developer dok├í┼że vytvori┼ą aplik├íciu tak, aby be┼żala na po─Ź├şta─Źi aj niekomu in├ęmu. Prever├ş vynaliezavos┼ą a kreativitu pri tvorbe scen├íra. Naviac dnes je u┼ż pomaly v┼íetko zosie┼ąovan├ę a tak prever├ş aj jeho schopnos┼ą prepoji┼ą hru do sie┼ąov├ęho prostredia. Vytvorenie hry prever├ş aj silu v├┤le. Dotiahnu┼ą aplik├íciu do ├║spe┼ín├ęho konca, rozhodne nespo─Ź├şva len v p├şsan├ş k├│du.

A hlavne je to z├íbava. Ve─ża v├Żvoj├írov berie aplik├ície pr├şli┼í seri├│zne a potom to aj tak vyzer├í. M├í to v┼íetku funkcionalitu, ale nikto to nechce pou┼ż├şva┼ą. Toto je pekne pop├şsan├ę vo vzore Soviet Style.

Jednou z ─Źast├ş hry je aj tvorba levelov. Tu toti┼ż skon─Ź├ş v├Ą─Ź┼íina n├ídejn├Żch tvorcov. Pokia─ż nem├íte k dispoz├şcii n├ístroje, ktor├ę m├┤┼że pou┼ż├şva┼ą aj norm├ílny ─Źlovek a vytv├íra┼ą pomocou nich vlastn├ę levely, tak hra zakape.

Dobr├í spr├íva, nemus├şte plytva┼ą svoj├şm drahocenn├Żm ─Źasom, pou┼żite TaT Tile Map Editor. Jedn├í sa o vo─żne dostupn├Ż editor m├íp nap├şsan├Ż v Jave. Z├íkladom je mo┼żnos┼ą tvorby dla┼żdi─Źkov├Żch m├íp. Nadefinujete si grafiku do ┼ítvor─Źekov a potom pomocou nej sklad├íte mapu levelu. Za ve─żmi d├┤le┼żit├║ vlastnos┼ą pova┼żujem, ┼że dok├í┼że pracova┼ą s vrstvami. Takto si m├┤┼żete vytvori┼ą zlo┼żitej┼í├ş svet, postavi─Źky m├┤┼żu chodi┼ą┬á napr├şklad aj za st─║pom.

V├Żsledn├Ż projekt je ulo┼żen├Ż do ZIP arch├şvu, kde sa napr├şklad nach├ídza samotn├í mapa v s├║bore global.xml. Tento editor som vyu┼żil pri tvorbe PF2010. Jednotliv├ę ─Źasti mapy, ktor├ę sa postupne zobrazuj├║ po nazbieran├ş 10 vlo─Źiek, s├║ rie┼íen├ę ako vrstvy tej istej mapy.

Osobne tento editor odpor├║─Źam. Mysl├şm si, ┼że autorom hier m├┤┼że u┼íetri┼ą mno┼żstvo vz├ícneho ─Źasu.

  • Where’s the fish?

  • Translations

  • Further info

  • Twitter

    Follow @jurajmichalek on twitter.

  • Comments

  • Tags

  • Topics