Simple code sample showing Cafu init

23 views
Skip to first unread message

Johannes Bauer

unread,
Aug 23, 2011, 2:12:46 PM8/23/11
to cafu...@googlegroups.com
Hi list,

I've written a small 2D tank shooting game in C++ a couple of years back
(inspired by "Return Fire") using SDL, Glut and Chipmunk.

Now I feel it's time for a complete rewrite (also using C++). For
preparation I'm looking into 3d engines and Cafu so far is the most
impressive: Clean website, active maintenance and well-documented API
really make it stand out. The level-editor is exceptional. It reminds me
very much of Qoole (which I used about 10 years ago for the last time),
incredibly easy to use!

Now I would like to jump into action and start coding a little bit. The
problem is, however: Where to start? Are there any good "Hello World"
tutorials? I know there's "Deathmatch", but it does so much and is a bit
overwhelming.

Is there some example code which utilizes Cafu using C++ which just does
*simple* things? By this I mean something like: Create a window,
intialize engine. Load a map. Rotate the camera. Not necessarily all the
keyboard interaction, no sound, no physics. I would like to learn step
by step :-)

Best regards,
Joe

Carsten Fuchs

unread,
Aug 24, 2011, 6:16:41 AM8/24/11
to cafu...@googlegroups.com
Dear Joe,

welcome to the Cafu Engine! :-)

Am 2011-08-23 20:12, schrieb Johannes Bauer:
> Now I feel it's time for a complete rewrite (also using C++). For
> preparation I'm looking into 3d engines and Cafu so far is the most
> impressive: Clean website, active maintenance and well-documented API
> really make it stand out. The level-editor is exceptional. It reminds me
> very much of Qoole (which I used about 10 years ago for the last time),
> incredibly easy to use!

Many thanks, it's nice to hear this!
:-)

> Now I would like to jump into action and start coding a little bit. The
> problem is, however: Where to start? Are there any good "Hello World"
> tutorials? I know there's "Deathmatch", but it does so much and is a bit
> overwhelming.
>
> Is there some example code which utilizes Cafu using C++ which just does
> *simple* things? By this I mean something like: Create a window,
> intialize engine. Load a map. Rotate the camera. Not necessarily all the
> keyboard interaction, no sound, no physics. I would like to learn step
> by step :-)

Your questions are good ones, though not easily answered:

We're doing our best to properly and well design the Cafu source code (newer code is better than
older portions, but we're getting better all the time ;-) ), and to keep things as modular and
as independent of each other as possible. The libraries (see
http://trac.cafu.de/browser/cafu/trunk/Libs) and the application executables are quite good in
this regard.

Also, you're of course very much welcome to use and re-use any parts, big or small (files,
classes, libraries, whatever) of Cafu in your own projects, and if you have specific questions
about anything, I'm happy to help.

Cafu however is very much focused on its task as game and graphics engine; for example, (at this
time) the network code is very much in the center of the design and consequently affects many
portions of the code. The situation is similar with other concepts, like the representation of
worlds in BSP trees that are populated with entities, etc.

These features make it a bit problematic to use Cafu in small doses, as one might be used to
from other graphics libraries that are designed and intended as general scene graphs that can be
used for each and every purpose (but usually don't cover non-graphics elements like network,
sound, collision detection, and so on).

For example, it's relatively difficult to use Cafu to just open a graphics window and display a
spinning cube. But it's relatively easy to use Cafu to have a spinning cube in the center of a
map that players can join over the network, that can tumble or make sounds when shot at, and
where the map can have many other rooms and cubes, etc.

Well, I'm aware that that leaves you standing in the rain (at least partially), but I'd still
like to encourage you to try: What exactly do you want to do? At what concrete step or piece of
code do you have problems or cannot proceed?
I'm aware that although our docs have vastly improved in the past, there is still a *lot* of
room for further and future improvements. Just ask, and I'm happy to answer your questions,
update and augment the documentation, etc. :-)

Btw., if you haven't seen it already, the very first step at least is well documented already:
http://www.cafu.de/wiki/cppdev:gettingstarted

Best regards,
Carsten


--
Cafu - the open-source Game and Graphics Engine
for multiplayer, cross-platform, real-time 3D Action
Learn more at http://www.cafu.de

Johannes Bauer

unread,
Aug 25, 2011, 1:50:40 PM8/25/11
to cafu...@googlegroups.com
Hi Carsten,

Am 24.08.2011 12:16, schrieb Carsten Fuchs:
> Dear Joe,
>
> welcome to the Cafu Engine! :-)

Thank you very much! :-)

> Also, you're of course very much welcome to use and re-use any parts,
> big or small (files, classes, libraries, whatever) of Cafu in your own
> projects, and if you have specific questions about anything, I'm happy
> to help.

This is very good to know. Does this also apply to textures and models?
The license.txt speaks about code a lot, but about textures it says they
"are copyrighted by their respective author". Who would this be?

> Cafu however is very much focused on its task as game and graphics
> engine; for example, (at this time) the network code is very much in the
> center of the design and consequently affects many portions of the code.
> The situation is similar with other concepts, like the representation of
> worlds in BSP trees that are populated with entities, etc.
>
> These features make it a bit problematic to use Cafu in small doses, as
> one might be used to from other graphics libraries that are designed and
> intended as general scene graphs that can be used for each and every
> purpose (but usually don't cover non-graphics elements like network,
> sound, collision detection, and so on).

Ah, I understand. Since these are all parts that I would need anyways,
this is probably not a problem for me, however. On the contrary: Getting
network right using SDL on the first write was quite the pain. It would
be nice if this would work more smoothly now.

> For example, it's relatively difficult to use Cafu to just open a
> graphics window and display a spinning cube. But it's relatively easy to
> use Cafu to have a spinning cube in the center of a map that players can
> join over the network, that can tumble or make sounds when shot at, and
> where the map can have many other rooms and cubes, etc.
>
> Well, I'm aware that that leaves you standing in the rain (at least
> partially), but I'd still like to encourage you to try: What exactly do
> you want to do? At what concrete step or piece of code do you have
> problems or cannot proceed?

Okay, to start off very simple: I'd like to place some model (this would
be a tank or a jeep or a helicopter) somewhere and view it from an
isometric perspective. Then I would like to implement the vehicle
physics (i.e. a tank will not slide around corners, but a jeep might).
For this I need some hooks on buttons and a understanding on how to
manipulate entity movement (or how to control what forces apply to rigid
bodies).

From what I understand, "Games" are basically shared objects which are
loaded by the main engine. The engine calls GetGame() upon
initialization, correct? Now there probably is some callback method or
function which is called periodically or some mechanism on how to
register listeners to events (i.e. collision, keypress, etc.). Could you
give me a pointer?

Also, the VSWM example seems a lot more easy than "DeathMatch" -
however, it refuses to work:

[...]
Libs/MaterialSystem/MaterialManagerImpl.cpp (364):
GetMaterial("Gui/Default") returns NULL.
Libs/MaterialSystem/MaterialManagerImpl.cpp (364):
GetMaterial("Gui/Cursors/Pointer") returns NULL.
Warning: Could not get the address of the GetGame() function.

I also tried copying VSWM to some other directory ("mygame") - then CaWE
complains upon startup that it could not find any materials (although it
does not complain about not having materials for VSWM). Seems a bit strange?

And one last thing: I created a small map and tried to walk around.
However, my character seems to get "stuck" every three seconds when
walking up a hill. This seems strange to me:
https://www.spornkuller.de/cafu.ogv

Am I doing anything wrong with the use of terrain there?

> I'm aware that although our docs have vastly improved in the past, there
> is still a *lot* of room for further and future improvements. Just ask,
> and I'm happy to answer your questions, update and augment the
> documentation, etc. :-)

If I have enough of an understanding to get some basic stuff running, I
would like to write a tutorial myself in order to contibute.

> Btw., if you haven't seen it already, the very first step at least is
> well documented already:
> http://www.cafu.de/wiki/cppdev:gettingstarted

Yup, I've done that and am working with the SVN version. Getting it all
to run was easy, although I needed also to use scons 2.1 alpha (2.0
would not work) even though I'm on Linux here.

Thanks for your help so far,
Best regards,
Joe

Carsten Fuchs

unread,
Aug 26, 2011, 9:52:21 AM8/26/11
to cafu...@googlegroups.com
Hi Johannes,

On 25.08.2011 19:50, Johannes Bauer wrote:
> This is very good to know. Does this also apply to textures and models?
> The license.txt speaks about code a lot, but about textures it says they
> "are copyrighted by their respective author". Who would this be?

The textures in Games/DeathMatch/Textures/...

generic/
meta/
photos/
TechDemo/ (the most important ones!)
Terrains/
SkyDomes.zip (the second-most important ones!)

are all owned by us, Carsten Fuchs Software, and you're free to use them in any free (that is,
GPL'ed) software project of yours.

Those in

Frank/
Industri/
Kai/
OldWAD/
Q1/
SkyDomes/Thrawn1*.*
SkyDomes/* (other)
WilliH/

were made by various people:
- I'm sure it's ok with Kai and Thrawn if you use their textures in GPL projects,
- those in Industri/ and Q1/ were made for the QRP, see
http://qrp.quakeone.com/faq/index.php?faq=2#2 for details, they are ok to use as well.
- For simplicity, I'd suggest to not use those in Frank/, OldWAD/ and WilliH/, as (only because)
I lost contact to these authors. For the non-Thrawn textures in SkyDomes/, see their txt files.

Those in

liquids/
misc/
sprites/

are from mixed and partially very old sources, I honestly do not remember (and have no records)
where they were from. As these textures are few and small, I don't think that anything bad will
happen if you use them, but if in doubt, they're easily replaced as well.


Regarding the models in Games/DeathMatch/Models/...

Static/
TechDemo/
Vegetation/
Weapons/

were all made by Kai, Thrawn and Slanny; as with the texture images, I'm sure they're ok/happy if
you re-use them.

For those in

Players/
Weapons/

we have for each an individual permission from the respective author, and partly they were
re-made/overhauled by Slanny. Same as above, it's ok to re-use them in GPL projects.

Those in

Items/
LifeForms/

are of mixed and very old origins, too. As above, it's probably ok to use them, but I unfortunately
have no records.


> Ah, I understand. Since these are all parts that I would need anyways,
> this is probably not a problem for me, however. On the contrary: Getting
> network right using SDL on the first write was quite the pain. It would
> be nice if this would work more smoothly now.

Well, yes, the implementation in Cafu is ready to use and stable (but I'm planning a complete
overhaul regarding its interface to the game system, so that programming entities becomes much
easier than it is right now).

> Okay, to start off very simple: I'd like to place some model (this would
> be a tank or a jeep or a helicopter) somewhere and view it from an
> isometric perspective.

Isometric? Or perspective?

> Then I would like to implement the vehicle
> physics (i.e. a tank will not slide around corners, but a jeep might).
> For this I need some hooks on buttons and a understanding on how to
> manipulate entity movement (or how to control what forces apply to rigid
> bodies).
>
> From what I understand, "Games" are basically shared objects which are
> loaded by the main engine. The engine calls GetGame() upon
> initialization, correct? Now there probably is some callback method or
> function which is called periodically or some mechanism on how to
> register listeners to events (i.e. collision, keypress, etc.). Could you
> give me a pointer?

I'll try to come up with a good overview description of the game system over the weekend, and then
send it as another reply to your message, or (if I can make it good enough), I'll add it to the
(wiki) documentation.
In any case, I'll let you know when done!

> Also, the VSWM example seems a lot more easy than "DeathMatch" -
> however, it refuses to work:

The VSWM is actually an old and inactive MOD that I only keep for testing CaWE with multiple game
configurations... It's code is only marginally maintained and it's no surprise that it doesn't work,
please disregard it.

> I also tried copying VSWM to some other directory ("mygame") - then CaWE
> complains upon startup that it could not find any materials (although it
> does not complain about not having materials for VSWM). Seems a bit strange?

Hmmm. This sounds like a bug.
Could you please file a ticket for it?
(http://www.cafu.de/wiki/cppdev:submittickets)

> And one last thing: I created a small map and tried to walk around.
> However, my character seems to get "stuck" every three seconds when
> walking up a hill. This seems strange to me:
> https://www.spornkuller.de/cafu.ogv
>
> Am I doing anything wrong with the use of terrain there?

From the video, it's difficult to tell, it could be anything from problems with the graphics driver
to disk swapping due to limited physical RAM. What are your system details? If in doubt, can you
please send the zipped map file? (if small enough, it's ok to send the file to this list, otherwise
just send to my private email adress)

> If I have enough of an understanding to get some basic stuff running, I
> would like to write a tutorial myself in order to contibute.

Thanks, that would be awesome!! :-)

> Yup, I've done that and am working with the SVN version. Getting it all
> to run was easy, although I needed also to use scons 2.1 alpha (2.0
> would not work) even though I'm on Linux here.

Oh, I'm surprised to hear this: Normally on Linux things work with the SCons version that comes with
the package manager. Which Linux distro do you use?

However, due to all those problems with SCons, I've started looking into and experimenting with
Premake4. It is able to create native Makefiles and Visual Studio solutions that allow everyone to
build all Cafu files in their known environment...

Johannes Bauer

unread,
Aug 26, 2011, 11:26:20 AM8/26/11
to cafu...@googlegroups.com
Aww, accidently replied to you directly instead of the list. Here it
goes again as a copy for the archive:

Am 26.08.2011 17:24, schrieb Johannes Bauer:
> Hi Carsten,


>
> Am 26.08.2011 15:52, schrieb Carsten Fuchs:
>
>> The textures in Games/DeathMatch/Textures/...
>>
>> generic/
>> meta/
>> photos/
>> TechDemo/ (the most important ones!)
>> Terrains/
>> SkyDomes.zip (the second-most important ones!)
>>
>> are all owned by us, Carsten Fuchs Software, and you're free to use them
>> in any free (that is, GPL'ed) software project of yours.
>

> Ah, wonderful, since the project will be GPLed. Do you care about the
> GPL version (i.e. 2 or 3)?

> Thank you for this very comprehensive list. I like to keep track of the
> sources so there's no confusion in the end.


>
>
>>> Okay, to start off very simple: I'd like to place some model (this would
>>> be a tank or a jeep or a helicopter) somewhere and view it from an
>>> isometric perspective.
>>
>> Isometric? Or perspective?
>

> Isometric projection is what I meant, sorry about the confusion.
> Although, thinking about it, basically any view from above with a angle
> that is choosable (i.e. rotatable camera position respective to the
> player) is fine.


>
>>> Then I would like to implement the vehicle
>>> physics (i.e. a tank will not slide around corners, but a jeep might).
>>> For this I need some hooks on buttons and a understanding on how to
>>> manipulate entity movement (or how to control what forces apply to rigid
>>> bodies).
>>>
>>> From what I understand, "Games" are basically shared objects which are
>>> loaded by the main engine. The engine calls GetGame() upon
>>> initialization, correct? Now there probably is some callback method or
>>> function which is called periodically or some mechanism on how to
>>> register listeners to events (i.e. collision, keypress, etc.). Could you
>>> give me a pointer?
>>
>> I'll try to come up with a good overview description of the game system
>> over the weekend, and then send it as another reply to your message, or
>> (if I can make it good enough), I'll add it to the (wiki) documentation.
>> In any case, I'll let you know when done!
>

> Wow, that would be fantastic. Thank you very much, this would be most
> helpful!


>
>>> Also, the VSWM example seems a lot more easy than "DeathMatch" -
>>> however, it refuses to work:
>>
>> The VSWM is actually an old and inactive MOD that I only keep for
>> testing CaWE with multiple game configurations... It's code is only
>> marginally maintained and it's no surprise that it doesn't work, please
>> disregard it.
>>
>>> I also tried copying VSWM to some other directory ("mygame") - then CaWE
>>> complains upon startup that it could not find any materials (although it
>>> does not complain about not having materials for VSWM). Seems a bit
>>> strange?
>>
>> Hmmm. This sounds like a bug.
>> Could you please file a ticket for it?
>> (http://www.cafu.de/wiki/cppdev:submittickets)
>

> Done: http://trac.cafu.de/ticket/82
> If there's any more info I can provide, I'd be happy to help.


>
>>> And one last thing: I created a small map and tried to walk around.
>>> However, my character seems to get "stuck" every three seconds when
>>> walking up a hill. This seems strange to me:
>>> https://www.spornkuller.de/cafu.ogv
>>>
>>> Am I doing anything wrong with the use of terrain there?
>>
>> From the video, it's difficult to tell, it could be anything from
>> problems with the graphics driver to disk swapping due to limited
>> physical RAM. What are your system details? If in doubt, can you please
>> send the zipped map file? (if small enough, it's ok to send the file to
>> this list, otherwise just send to my private email adress)
>

> Hmm, I doubt it is the system. I'm running a quad Q9550 @2.83GHz with
> 8GB of RAM on Gentoo Linux. Running in full-screen mode, both X and Cafu
> need about 60% CPU (i.e. two cores are about half-busy, total system
> load is about 30%). Virtual memory consumption during the demo is 350MB,
> although only 140 MB are actually needed. There's definitively no
> swapping going on. Graphics card is a Nvidia GeForce 9600GT running the
> proprietary Nvidia drivers (version 270.41.19).
>
> The reason why I don't think it's the system is that the player entity
> actually "hops" a little up and down when it comes to one of the jerking
> points. This reminded me of a collision detection artifact. It also only
> happens when going in about a 45ᅵ angle up a hill (but not with all
> terrains).
>
> Since the map is only 25k, I've attached them to this mail. Notice that
> the jerking is appearently directionally dependent. In the map if after
> the spawning you walk straight for about 8 seconds, then turn around
> 180ᅵ and walk towards the black texture blob, I can always reproduce it
> (although the effect varies).


>
>>> Yup, I've done that and am working with the SVN version. Getting it all
>>> to run was easy, although I needed also to use scons 2.1 alpha (2.0
>>> would not work) even though I'm on Linux here.
>>
>> Oh, I'm surprised to hear this: Normally on Linux things work with the
>> SCons version that comes with the package manager. Which Linux distro do
>> you use?
>

> I'm on Gentoo, which uses scons 2.0.1. 2.1 is not even in the tree yet,
> so I had to manually install 2.1alpha. With 2.0.1 I get the following
> error message when running scons:
>
> scons: Reading SConscript files ...
>
> Checking for C library png... yes
> Checking for C library z... yes
> KeyError: 'TARGET_ARCH':
> File
> "/home/joe/Eigene_Dokumente/Programmieren/GameEngine/cafu/SConstruct",
> line 231:
> if envCommon["TARGET_ARCH"]: my_build_dir +=
> "/"+envCommon["TARGET_ARCH"];
> File "/usr/lib/scons-1.2.0/SCons/Environment.py", line 404:
> return self._dict[key]


>
>> However, due to all those problems with SCons, I've started looking into
>> and experimenting with Premake4. It is able to create native Makefiles
>> and Visual Studio solutions that allow everyone to build all Cafu files
>> in their known environment...
>

> Ah, the description sounds very nice. I am actually also looking for a
> build manager replacement at the moment. Have been using Automake far
> too long and am really getting sick of it (it just has too many quirks
> and silly syntax issues for my taste).
>
> Best regards,
> Joe

joemap2.tar.gz

Carsten Fuchs

unread,
Aug 27, 2011, 6:36:08 AM8/27/11
to cafu...@googlegroups.com
Hi Joe,

Am 2011-08-26 17:24, schrieb Johannes Bauer:
> Ah, wonderful, since the project will be GPLed. Do you care about the
> GPL version (i.e. 2 or 3)?

Not really, but as all Cafu code is under GPL v3, best you use that as well.

> Done: http://trac.cafu.de/ticket/82
> If there's any more info I can provide, I'd be happy to help.

Thanks!
I'll look into this as soon as I can, i.e. near the start of the upcoming week.

> The reason why I don't think it's the system is that the player entity
> actually "hops" a little up and down when it comes to one of the jerking
> points. This reminded me of a collision detection artifact. It also only
> happens when going in about a 45ᅵ angle up a hill (but not with all
> terrains).
>
> Since the map is only 25k, I've attached them to this mail. Notice that
> the jerking is appearently directionally dependent. In the map if after
> the spawning you walk straight for about 8 seconds, then turn around
> 180ᅵ and walk towards the black texture blob, I can always reproduce it
> (although the effect varies).

Ok, I see this for the first time, but I can reproduce it here.
Would you mind opening another ticket for it?
Please copy your above description, and please attach your .cmap and .cw files as well.

> Ah, the description sounds very nice. I am actually also looking for a
> build manager replacement at the moment. Have been using Automake far
> too long and am really getting sick of it (it just has too many quirks
> and silly syntax issues for my taste).

Well, I've never used Automake, but used to maintain Makefiles manually for a long time, then
switched to SCons (which is, despite it's problems, a very good system), and have been looking
at alternatives such as CMake, Premake, gyp, waf, Bakefile, etc. since.
Each has its own pro's and con's, but Premake seems to work very well and my initial experiments
are promising, so unless something severe intervenes, we'll soon be able to build all
Cafu-related software with it (I'll however in parallel keep and maintain building with Scons,
too, at least for a while).

Johannes Bauer

unread,
Aug 27, 2011, 4:22:06 PM8/27/11
to cafu...@googlegroups.com
Hi Carsten,

Am 27.08.2011 12:36, schrieb Carsten Fuchs:

> Am 2011-08-26 17:24, schrieb Johannes Bauer:
>> Ah, wonderful, since the project will be GPLed. Do you care about the
>> GPL version (i.e. 2 or 3)?
>
> Not really, but as all Cafu code is under GPL v3, best you use that as
> well.

Alright, v3 is my preference anyways :-)

>> The reason why I don't think it's the system is that the player entity
>> actually "hops" a little up and down when it comes to one of the jerking
>> points. This reminded me of a collision detection artifact. It also only
>> happens when going in about a 45ᅵ angle up a hill (but not with all
>> terrains).
>>
>> Since the map is only 25k, I've attached them to this mail. Notice that
>> the jerking is appearently directionally dependent. In the map if after
>> the spawning you walk straight for about 8 seconds, then turn around
>> 180ᅵ and walk towards the black texture blob, I can always reproduce it
>> (although the effect varies).
>
> Ok, I see this for the first time, but I can reproduce it here.
> Would you mind opening another ticket for it?
> Please copy your above description, and please attach your .cmap and .cw
> files as well.

Done: http://trac.cafu.de/ticket/83 -- I'm really curious to why this is
happening.

Best regards,
Joe

Carsten Fuchs

unread,
Sep 13, 2011, 5:46:32 PM9/13/11
to cafu...@googlegroups.com
Hi Johannes,

Am 2011-08-26 15:52, schrieb Carsten Fuchs:
> On 25.08.2011 19:50, Johannes Bauer wrote:
>> Then I would like to implement the vehicle
>> physics (i.e. a tank will not slide around corners, but a jeep might).
>> For this I need some hooks on buttons and a understanding on how to
>> manipulate entity movement (or how to control what forces apply to rigid
>> bodies).
>>
>> From what I understand, "Games" are basically shared objects which are
>> loaded by the main engine. The engine calls GetGame() upon
>> initialization, correct? Now there probably is some callback method or
>> function which is called periodically or some mechanism on how to
>> register listeners to events (i.e. collision, keypress, etc.). Could you
>> give me a pointer?
>
> I'll try to come up with a good overview description of the game system over the weekend, and
> then send it as another reply to your message, or (if I can make it good enough), I'll add it to
> the (wiki) documentation.
> In any case, I'll let you know when done!

Sorry that it took me so long (I could not resist fixing the bugs and improving some related
code first ;-) ), but I finally made a start:

http://www.cafu.de/wiki/cppdev:gamecodeoverview

If you have more questions, please don't hesitate to ask: It's quite difficult for me to see
what needs more explanation and what doesn't, so questions are an excellent way to get the text
augmented and improved. ;-)

Btw., I also plan to thoroughly revise the game framework, in order to modernize the code and
its documentation, so that it's easier to understand and contains less historic burdens (of
which there are still plenty).

Reply all
Reply to author
Forward
0 new messages