Game Engine Coding

I was reading the “Letter to Blender Nation” post and near the end there were some comments about how there are only a few people possibly more working on the game engine code and that there should be more. Erwin is working on Bullet, Charlie is working on Ogre integration and malCanDo has a thread on bug fixes. I may have missed some but I don’t know.

I feel the major reason why more individuals can’t or won’t help is that the source code is a major barrier to entry. There are a couple of files on a dusty section of the BlenderWiki that attempt to start an explanation of the GE code but not much else. Naturally one could say just download the source and read it yourself. There are a couple of problems with this approach though. Many coders assume that the code documents itself and second there is no big picture where one can see where everything fits together. Oh, let’s not forget that there is a conversion from Blender into the GE so you need to be familiar with the Blender code as well to figure out what is being dumped into the GE.

Almost over a year ago there was a push to start a GameEngineTeam and add this knowledge to the Wiki. I really don’t know what happened to this. I must admit I volunteered and quickly realized I needed to know more about using Blender and the GE in order for the code to make sense. In addition there was some wiki conversion going on and many of the files form the old GE Team are collecting dust. So I am partly to blame for failing the old GE Team.

Who among us is skilled and knowledgeable enough to provide a general overview of the Blender Game Engine Code? I am curious to know if Erwin, Charlie, or malCanDo is available to offer assistance? Of course their time is already strained. What can we do?

Well, I can offer a suggestion. We can do it ourselves. I haven’t counted the source files in the GE source nor the related includes form Blender but if we only pick one per week and start documenting the code it would be a start. Again, I don’t mean creating dry boring API documentation, but lively conversational documents that a layman can read and begin to understand the code. Think of it as walking a new coder through the Blender source. We can call it “Blender Source Code for Dummies”.

I don’t know. Your feedback is appreciated. I’ll post my hacked amature attempt at explaining the BlenderRoutines/BL_KetsjiEmbedStart.cpp as soon as I can. I understand this is where the GE code kicks off.

regards,

honeycomb

As anyone who ever wrote a decent tutorial knows, that is easier said than done.

Such documentation would take an awful lot of time to put together, especially if you take in account that there are only a few people who can actually write it in the first place.

honeycomb,

If you share this with us, it would be a very great thing!!

Thanks :slight_smile:

i agree with pOOf and the more the GE community could learn about the Blender source, the more plugins and such could be integrated into the real Blender source.

I’m fairly new to the GE code ( I used to code games many years ago in C/C++, so I had a bit of a head start ), but am familiar with using the GE ( I worked at NaN as a Blender game designer / artist ) and writing a tutorial ( I wrote the BSoD - Getting Started With The Game Engine documentation ).

When I started looking into the GE code ( about 2 months ago or so ), I spend the first week or so just downloading the free Visual C++ Express ( you really need a good debugger IDE like this for doing any coding ), the CVS code relevant libraries, and getting Blender to even compile. It was pretty frustrating getting this all to work - things are going to be a lot easier now that CMAKE is being used to create project files for Visual C++ - they tended to be out of date before, due to the frequency of change in Blender. Also, getting used to things like compiling the separate intern, extern and then blender libraries - this isn’t too obvious at the start :slight_smile:

After that, it took me a month or so tinkering around, just getting used to the layout ( of just the GE code - there’s too much code in Blender to get an overview of it all ).

To give myself a goal, I started looking at how to track down and fix some very small GE bugs ( eg the Message Sensor, Property Sensor stuff ).

That’s where I’m at at the moment. I hope to improve both the TrackTo and Camera Tracking code next, but I’m flat out with a few other work projects at the moment.

If anyone wants to get involved, just get the code downloaded and compiled. If you still have any enthusiasm left after that :slight_smile: then start with a small project - eg looking for small bugs to fix. If you ask on the forums, you’ll have no problem getting a list from the GE community :slight_smile:

Don’t underestimate the time it takes to get everything working firstly, so take it a step at a time - but make that first step as soon as you can!!!

Regards…
Mal

It’d really be nice if the GE had leaps and bounds as big as the rest of Blender.

Though the new physics and upcoming OGRE intergration is pretty big in itself.

Well everyone beat me to the post :slight_smile:

I really appreciate this interest! I would like to see more people willing to help bring the game engine up to date. Like you say Its just the three of us trying to improve the game engine. If we had more people willing to work on it the results would be better and faster.The complete Ogre integration source is on sourceforge, but to date any one that has been willing to help work on it I give them a link to the code, and then never hear back from them.

Voice your opinion on what you would like to see to help learn the source. I’m willing to help, and I’m sure Erwin & Mal are just as willing to help too.Maybe a new attempt at a team is in order, We could learn from the blender devs, and communicate through the wiki && IRC meetings & mailing lists.But there needs to be a unified plan for the GE. If Ogre integration is the census, then lets get it done!

Thanks,
Charlie

Perhaps if u can get a college professor interested in making blender GE a part of his students’ course requirments then you can get this thing going. Because there are many advanced programming students that could would love to learn game programming while also gaining something to place on their resume that would set them apart from the rest of the crowd.

They could actually show prospective professionals the physics or graphics or interface improvements they made. Which I think would be pretty good.

I know it seems kinda devious, but non profit causes tend to do this kind of thing because it’s mutually conveinant for all parties involved as is the case here. I want to see blender GE grow as well. So there is a suggestion.

I was wondering, why can’t Ton himself start an initiative to get more Game engine coders? Put something up on Blender.org to help out? Maybe some cash incentives to get to coding something? It’s not like he doesn’t care about the game engine.

That could help.

Well, “Cash incentives” is stretching it imo (even though it would probably work the best, it’s the most unlikelly thing to happen). However, getting some advertising on blenders main site is definitelly a more approachable proposal, and far overdue imho.

Someone closer to the “root” of the whole blender thing should recommend that to Ton.

Maybe Erwin could make the recommendation?

I’ll comment on other issues later as I just fried my brain and knocked this out in a couple of hours. This is kind of what I was talking about. It’s a start and we could hash out the organization and other administration at everyones leisure.

This link to v1.17BL_KetsjiEmbedStart.cpp. is where you can view the CVS log for this file and also view the source code. This is good if you don’t want to download the complete source and it is suitable for a start. Click on some of the links to get familiar with what they do, it’s all pretty simple.

Note, I only cover the load_game_data() function here there is so much more to do with this file though. There are 670 lines of code and I only covered 20.

 BL_KetsjiEmbedStart.cpp =

BL_KetsjiEmbedStart.cpp contains two functions, load_game_data() and
StartKetsjiShell().

== Blender Load Game Data ==

1) Reads a .blend file and loads data into BlendFileData structure

Line # 86

static BlendFileData *load_game_data(char *filename)
  "BlendFileData" is a type of data called a Structure.  All data is of a certain
type, it could be an number or a character among others types.  A type identifies
what you data you are working with.  A structure is a colletction of data types that
are related.  Think of a character in your game, each character has a name, age, 
weight, eye color and so on.  Now think of a structure like a drivers license or a
identification card and call it "ID" this is what "BlendFileData" is a, collection
of data that, drum roll, contains the stuff in your .blend file.

  "load_game_data" and "filename" are pointers.  A pointer is also a type of data
and what this type does is point to the location of the address of a variable or 
other data in memory.  This doesn't contain the data, just the address where the
data lives or resides.  We give it names so it is easier to read and understand.
One last thing, we use "*" in front of the pointer name to find the value stored in
the pointer. If you didn't use the "*" you would get the address of the pointer not
the address to the data that the pointer contains.  Make sense?

So what happens is we have the address to where the load_game_data() function is and
the address to where the "filename" is and a nice structure "BlendFileData" to store
it in a nice neat package for use.  Cool.

Line #87

BlendReadError error;

  So you know what a structure is.  What this does is create an instance of the
structure "BlendReadError".  We give it a name called error so that if there is an
error reading the file we can find it with "error".  So now "error" is a variable
which holds error information.

Line #90

FILE* file = fopen(filename,"rb");

We talked a little bit about pointer so here we have a nice exmple of how to create
one.  "FILE" is a data type and and the "*" immediately after the data type means we
are creating a pointer named "file".  Do not confuse this with accessing the address
of the data stored in "file" as noted above where the "*" asterisk is placed in
front of the pointer name.  So to keep things moving along we assign the address 
where the results of the fopen() function are stored to the "file" pointer.

Rember the "*filename" pointer above, well this is where we use the actual data to
open the file for reading "r", and that it is a binary file "b".  Remember your
.blend file is a binary file.

Line #91

BlendFileData *bfd  = 0;

 HELP:  I guess here we are clearing any old address stored in "bfd".

Line #92

if (file)

  Check to see if there is a pointer called "file".

Line #93

fseek(file, 0L, SEEK_END)

  The fseek() function allows you to read a file beginning at any point in the file.
We can see that it takes three parameters.  "file" is the pointer to the file being
searched.  "0L" is the offset or how far along move from the start.  The letrer "L"
after the number means that this number is of type long.  What this means is that a
normal number of type "int" can only store values betwee -32767 and 32767.  If you
need bigger numbers one thing to do is use "long" or other number types that have
more storage space.  You have to use "long" here.  An finally "SEEK_END" means 
measure the offset from the end of the file. So this just sets the position to the
end of the file.

Line #95

int len= ftell(file)

  ftell() tells how many bytes there are from the fseek() location to the beginning
of the file.  Above we set "SEEK_END" as the file position and the offset to 0 and
now "len" convieniently holds the length of bytes in the file as a "long".  Again
we know how fast the .blend file can grow so we need lots of space for the length.

Line #96

fseek(file, 0L, SEEK_SET)

  Simple enough, this sets the seek position to the start of the file.

Line #97

char* filebuffer= new char[len]

  Guess what this does.  It creates a pointer of type char named "filebuffer" and
assigns the memory location of the array "char" to it.  We havent touched on arrays
yet and many would say that they need discussion before pointers, but we need some
progress here.  An array is a series of emements of one data type.  The key here is
the word "series" because arrays have an index where you can find your data stored.

Our array "char" has as many spaces to hold data as there are bytes in our .blend
file.  The brackets identify "char" as and array and "len" is the number of
elements in the array.  Let's not forget that this array holds data of type "new".
HELP:  WHAT IS THE "NEW" DATA TYPE. THE COMMENT MIGHT TELL?  We access the elements in the array by the
index of the element.  Our array "char" starts with char[0] and goes all the way to
char[len] where "len" is the size of our .blend file in bytes.  If I want the 2473th
item in array we would use char[2473].  Easy enough.

Line #98

int sizeread = fread(filebuffer, len, 1, file);

  fread() is used to read binary data.  Binary dats is what we have ben using with
our .blend file all along.  Notice a pattern here, I do.  The parameters that fread()
take are "filebuffer" which is the pointer to the address where the binary data is
o be written in memory.  "len", AGAIN, is the size of the data in bytes, "1" 
represents the number of chunks to be written, and file is the file to be read.

  We now read one chenk of data with a length of "len" from the "file" into the
"filebuffer".  We also store the number of items sucessfully read in the variable
"sizeread".

Line #99

if (sizeread == 1)

  This checks to see that we acutally read 1 chunk of data ad like we wanted in line
# 98.

Line # 101

bfd = BLO_read_from_memory(filebuffer, len, &error);

  Were getting close to the end of the function here.  What we are doing here is
checking that the data was actually read from the file into memory.  I haven't found
the "BLO_read_from_memory() but I am guessing that it reads a chunk of binary data
from memory starting at the address in "filebuffer" and if there are any errors it
grabbs the address where it can store the location of the error data.

  Here is a bit more on pointers.  "error" is a pointer that holds the address of
data it points to.  To find the address of "error" we use "&" before the pointer
name.  Lets rephrase that.  *error is the address where the error data is stored.
&error is the address where we store the address to the error data.  

  Think of it this way.  I live in a huge appartment complex.  You need to know
where I live so I tell you to check mailbox #386.  Inside this mailbox you will find
the address to my appartment.  Mailbox #386 is like &error, it is only the address
to my mailbox.  My apartment #9876 is stored in this mailbox and this is just like
*error.  Hopefully that makes sense.

  In summary we read the data from memory and store it in the structure "bfd" for
use.

Line #103

fclose(file)

  If you open something, close it when you are done.  Not doing this is like leaving
the cap of the milk jug, things go sour.

Line #106

if (!bfd)

  Something happened and there is no "bfd" we didn't read the data from memory.
What do we do?

Line # 107

printf("Loading %s failed: %s
", filename, BLO_bre_as_string(error));

  Crash and burn, baby!  Loading "filename" failed: ERROR.  Just to be complete, the
printf() function prints data to the screen of console.  In this case ir prints some
text as well as data.  %s tells the function that the data is a string and we tell
it what string by the use of "filemane".  The second %s is string data and that is
the error message.  I can only geuss right how that the error is stored as binary
data and that the function BLO_bre_as_string() makes it human readable.

Line#110

return bfd;

  We have now read the .blend file by using this function.  This line tells the
function to make the data available for use outside the function.

I wont post any more text here but I do plan so see if I can find my Wiki username and password so I can add it there. Please proof this and give comments on layout and style. Of course everything can change when we get going but we just need to get going, and now.

Kind Regards,

honeycomb

Wow, thats a lot of info! Do you think it would be easier to summarize the the purpose of the function, then add points to important variables? I find it easier to know what the function does, then read the code and say ok, this is how they achieved that purpose…

Yes, that would be much better.

I’m fairly happy with the current game engine development, we don’t need many more developers, it would just become chaotic.
We slowly move towards using Ogre 3D. This should give a good foundation, together with Bullet for physics, COLLADA for data exchange (or .blend parser), and perhaps OpenAL for sound, Python for scripting.

Charlie, Malachy, RC Ruiz and me are working on it, in small steps. Remember it’s a side-project for us. If someone else has a fix/patch, just let us know.
Things are moving in the right direction for the game engine,
Erwin

I don’t think a couple of additional developers would pose too much of a problem as long as they were willing to respect the direction of the existing development team. There are enough minor bugs with each release to warrant at least one more person working with Mal (in my opinion). Also, certain aspects of the Game Engine that have not been getting addressed fully since 2.25. Mainly I’m thinking of the web plugin. To me, the plugin seems to be the aspect of the GE with the most unrealized potential. I was very glad to see an alpha release of the plugin for IE with 2.42 (thanks erwin!), and it would be nice to see multiple browser support and cross-platform compatibility again. I would at least like to have a Firefox version without the apparent security holes that the 2.25 plugin has. I personally don’t know what all is entailed in that process, but it seems like it would be enough work to merit its own developer.

Anyway, that’s my two cents…

Edit: BTW, I want to say thank you to the existing team. I really do appreciate all of the work you guys put into this, and I agree with you Erwin, the GE is moving in the right direction.

I think that you could take some college students hostage and make them your coding slaves/bitches. LOL - hey I was a college student too once! But okay, “Erwin knows best” I suppose;)

Does anyone know what Erwin does as his main job? Because for a side project Bullet/Blender/Game Engine is just sooo good!

Well, repeating myself again, and again…
There’s funds/money everywhere around the Blender project but not “touching” the Game engine side I guess
I would like to reward the game engine workers, or new ones if needed, with a donation
or something like that
I don’t have the time/manner to do that!
Maybe someone else?..

The Google Summer of Code might be a great way of getting students involved - I can remember reading titles of lots of Blender proposals, but none of them seemed to be related to the GE.

When the next SoC comes up, we could try promoting it to colleges who are teaching games programming.
Mal

snailrose, and Social I am not sure that this document is aimed at your level
of skill.

I feel that the purpose of this project is to help those who have an interest in coding get started. One might say that this is too complex for beginning coders but I disagree. The reason there is a lot of information is because, as Social would say, we assume a certain amount of programming knowledge as a prerequisite, but this level is somewhat low.

I attempted to meet this low level of prerequisite in this initial draft of the load_game_data() function. It was meant to explain intermediate concepts without starting from scratch. I do not care to spend a chapter on data types when this information can be introduced gradually as the subsequent chapters unfold. Again I would rather learn more about programming by examining a complex program that I have an interest in than writing console apps that fill structrues and classes with information about cats or horses.


erwin, I am not sure how to interpret you comment. I think that snailrose had a great solution in post #7. We could learn from the developers, and communicate through wiki, IRC, meetings & mailing lists. Communication is meant to avoid chaos - if the communication is effective. The biggest goal is to have a plan.

I am amused by many of the responses about college professors, cash prizes, an other methods of motivating programmers to code. Again, the goal is to educate people and inspire them to begin coding for themselves. This is our community after all, and Blender is an Open Source project.

So this means we don’t want outside students, professionals, contractors or others coding on Blender, we want the educated user to do it. We want the user to be the student, then the professional, then the contractor. We need to help people “scratch their own itch”, the problem is they don’t know how and reading source code alone is not the way to get there.


Here is my plan for now.

  1. Grab a file from the Blender Game Engine source and write a basic (beginners never coded before explanation) step by step explanation to what each line does.

  2. When finished write a quick summary of the functions and other important points in the file. This is somewhere between “for Dummies” and the actual source code. This is to get intermediate to advanced users going without pissing them off.

  3. Send me a PM by January 15th, 2007 that you have made some progress.

  4. I’ll post the progress report in this thread.

  5. Discuss the roadmap and the one file per week goal. This is the plan. Even the BSoD had a plan and each entrant had to write a proposal as well as an outline. This is no different.

Finally we are not coding Blender at this point. We are documenting the code and explaining its function in laymans terms so a person with little programming knowledge can understand. Simple.

Later on when we know what’s going on we can create a plan to code on an area of the Game Engine and submit the plan to the existing development team.

regards,

honeycomb

Magic:

Does anyone know what Erwin does as his main job?

he works for sony computer entertainment, with physics and stuff I think for the PS3