Lets take apart a .c file for knowledge

Compiling, libraries, modules, coding guidelines and porting

Moderators: jesterKing, stiv

theeth
Posts: 500
Joined: Wed Oct 16, 2002 5:47 am
Location: Montreal
Contact:

Post by theeth »

hannibar wrote:

Code: Select all

typedef struct EditEdge
{
	struct EditEdge *next, *prev;
	struct EditVert *v1, *v2, *vn;
	short f,h;
	short f1, dir;
} EditEdge;
I understand what this structure is used for, and when it is used, but I don't have a clue what the variables f, h, f1 and dir mean in this example.
f and f1 are flag variables. f has specific uses through the code while f1 is used for temporary flagging (editing functions for example can use it to indicate states of an edge for calculations).
I don't know about the other two.

The best place to ask that kind of thing is in #blendercoders. If you can get a hold of Ton or Zr they usually know that kind of stuff more than the rest of us.

Would be nice to put comments there though.

Martin
Life is what happens to you when you're busy making other plans.
- John Lennon

stiv
Posts: 0
Joined: Tue Aug 05, 2003 7:58 am
Location: 45N 86W

Post by stiv »

Bog forgive me for getting involved in this swamp of a thread, but one character variable names are a pet peeve of mine. Definitely worthy of a spanking, IMNSHO.

They tend to be unaccompanied by comments, they are nearly impossible to search for and given the fact that code is read much more often than it is written, they do *not* save any time at all.

I'm willing to cut some slack for common constructs like i,j,k loop variables and x,y,z,w coordinates, but that is about it.

EndOfRant

jesterKing
Site Admin
Posts: 207
Joined: Fri Oct 18, 2002 12:48 pm
Location: Finland

Post by jesterKing »

stiv wrote:EndOfRant
The rant is not valid, since it misses the opening "tag".

/jesterKing

stiv
Posts: 0
Joined: Tue Aug 05, 2003 7:58 am
Location: 45N 86W

Post by stiv »

jesterKing wrote:The rant is not valid, since it misses the opening "tag".
This is just one more example of how HTML has damaged the brains of young people today. EndOfRant is not an html tag. It is a separator that marks the end of a rant in the same way a newline marks the end of a line of text, or a '.' character marks the end of a sentence.

Since I am in ContinuousRant mode, a BeginRant marker is, by convention, unnecessary.

theeth
Posts: 500
Joined: Wed Oct 16, 2002 5:47 am
Location: Montreal
Contact:

Post by theeth »

while(!(stiv.EOR)) {
stiv.RantOn();
}
Last edited by theeth on Tue May 25, 2004 9:38 pm, edited 1 time in total.
Life is what happens to you when you're busy making other plans.
- John Lennon

SirDude
Posts: 233
Joined: Sun Oct 13, 2002 7:37 pm
Location: University of Minnesota (USA)
Contact:

Post by SirDude »

Getting back to the topic ;)

Money_Ya, (I think I spelled that right?)

if your having problems with the INSTALL docs for your
platform let us know where your having a hangup
and we'll try to improve that section, and or help you get
things working and you can improve the install docs. ;)

There are a couple of options depending on what platform and we have tried to document each platform so things get confusing quickly. Most of us here had to really work to get things to build in the beginning so now we look at it and think everything is straightforward. Its hard for us to see what exactly needs improvement.

stiv
Posts: 0
Joined: Tue Aug 05, 2003 7:58 am
Location: 45N 86W

Post by stiv »

Heh, theeth!

In a half-hearted attempt to stay on topic and not appear a complete cranky ol' bastard, let me say I admire the enthusiasm that started this thread but I fear it is misdirected and will lead to much frustration.

Simply put, Blender is a complicated program and is not suitable for an introduction to C programming. It is as if you wanted to learn about internal combustion engines and tried to start by disassembling a dual overhead cam multiport fuel-injected v-12 engine. Much better to start by taking apart a single cylinder lawn mower.

Here is what I would do if I were me:

If this is your first programming language, learn python. When I say first language, be aware that HTML, in spite of the L at the end, is *not* a programming language.

C is a hard language to start with because you are so close to the machine and the binary representation of data. Python is easy, there is a nice tutorial over on python.org and it will teach you the basic concepts of programming. The syntax is similar to C and it will give a leg up when we implement blender3 as python extensions.

I know you want to learn C but learning python will help teach the concepts of programming which are in some sense independent of programming languages.
Besides, everyone should know at least one scripting language because they are just so dang useful.

Second, you need to learn about data structures. These are things like those lists that keep keep showing up in Blender. Along with algorithms, they are the fundamental building blocks of programs. You need to understand data structures to understand the code. Python comes with some nice list and dictionary structures already built in.

As you are learning C/C++, look at and write some simple programs. This will help you understand things like #define and -I compiler directives.

I know this sounds like the long way around, but, trust me, you will arrive at your destination quicker and you will know what to do once you get there.

jesterKing
Site Admin
Posts: 207
Joined: Fri Oct 18, 2002 12:48 pm
Location: Finland

Post by jesterKing »

stiv wrote:
jesterKing wrote:The rant is not valid, since it misses the opening "tag".
This is just one more example of how HTML has damaged the brains of young people today. EndOfRant is not an html tag. It is a separator that marks the end of a rant in the same way a newline marks the end of a line of text, or a '.' character marks the end of a sentence.

Since I am in ContinuousRant mode, a BeginRant marker is, by convention, unnecessary.
True, I should've used the term 'state' or 'mode'. But if you're in ContinuousRant mode, an EndOfRant would also be unnecessary (by convention).

/jesterKing

Money_YaY!
Posts: 442
Joined: Wed Oct 23, 2002 2:47 pm

Post by Money_YaY! »

I am not ranting I am not yelling :D

I just want to learn what I can. I have no chance to ever learn C or C++ at the level of a programer. Blah blah blah...

stiv: I know that this is the smartest method, but I just don't get enough time to study it and poke at it. I just want to start hackking at it.. So it will still take some time, but as logic goes, once a method is found then a repeatable answer can be preformed. That is the golden ticket that eludes me, and maybe everyone still.... :P

SirDude: I am trying to make a blender version Without ANY features at all, a blank slate if you will. Then I can fit together the pieces to build a new blender and during that figure out how it all works, so yes it is like taking apart an engine a piece at a time. :twisted: ...

Kay, back to the fuel system... ^v^
Should I make a new post for questions ? This one seems to have become a fighting contest...

leon
Posts: 0
Joined: Mon Oct 20, 2003 7:14 am

Post by leon »

Hi Money_Yay,
I just want to start hackking at it..
I'm learning C by hacking around with Blender, so what you're attempting is not necessarily a bad way to go in my opinion. I hadn't done anything more than a little program which wrote "hello" before I got stuck into Blender.

The way I started was not to try and disect a random file first, but instead come up with a few things I wanted in Blender and try and program them - learning what the files did along the way.

So why not try something silly and useless first: for example add a command to a menu to create a pyramid.

Track through the code following how a cube is created, and copy n paste code modifying it where needed...

By the end of that, you should have enough knowledge to try something a bit more ambitious.

Cheers

Leon

Money_YaY!
Posts: 442
Joined: Wed Oct 23, 2002 2:47 pm

Post by Money_YaY! »

leon wrote:Hi Money_Yay,
I just want to start hackking at it..
I'm learning C by hacking around with Blender, so what you're attempting is not necessarily a bad way to go in my opinion. I hadn't done anything more than a little program which wrote "hello" before I got stuck into Blender.

The way I started was not to try and disect a random file first, but instead come up with a few things I wanted in Blender and try and program them - learning what the files did along the way.

So why not try something silly and useless first: for example add a command to a menu to create a pyramid.

Track through the code following how a cube is created, and copy n paste code modifying it where needed...

By the end of that, you should have enough knowledge to try something a bit more ambitious.

Cheers

Leon
Oooo Sounds like you found the method I am in search of. I will try out the example you teach. But can you give somemore bits of knowledge that you have found in your journey into code of Blender maddnesss ^v^

jesterKing
Site Admin
Posts: 207
Joined: Fri Oct 18, 2002 12:48 pm
Location: Finland

Post by jesterKing »

stiv wrote:the concepts of programming which are in some sense independent of programming languages.
I think this is the most important part to learn [first]. Of course, you'll be needing a language to express the concepts, but in the end the differences between languages is only syntactic and mechanical, as in how they provide ways to use programming concepts (ie. ANSI C is also a fully fledged OO language - provided you put in a bit more time).

I'd suggest that while you're getting familiar with C (and possibly Python), you should at all times try to think of the abstracts behind the code you see, the concepts of programming.

I've seen often trainees who have been learning to program through one language, while what they actually learned was the structure of the language, totally unable to recognise the problem they have to solve and see the use of previously learned techniques in new and helpfull ways.

So learn C, but please don't forget the more abstract part of programming (the theory-side, if you will). When you dive into Blender, and learn C as you go, make changes here, changes there, learn also *why* the changes work as they work, and when you get more into it, look if you can see the algorithms at use.

/jesterKing

ps. I hope the teacher-tone doesn't bother ;)
pss. This is of course my self-learned, non-qualified programmer opinion

SirDude
Posts: 233
Joined: Sun Oct 13, 2002 7:37 pm
Location: University of Minnesota (USA)
Contact:

Post by SirDude »

>> SirDude: I am trying to make a blender version Without ANY features at all, a blank slate if you will. Then I can fit together the pieces to build a new blender and during that figure out how it all works, so yes it is like taking apart an engine a piece at a time. ...

The problem with this is it doesn't work like that.
This probably gets back to your earlier questions about whats where, but blender is build on a bunch of packages that are needed and add complexity.

Its sort of like saying I want to learn Calculus but I want to remove addition,subtraction etc so I can understand it.

You can say start with addition but thats not really a
"blank" blender. The point being where do you draw the
line? Even ghost (the GUI library blender uses) is complicated and if you were just focusing on that you
wouldn't have anything at all releated to a working blender and it would still be confusing.

Your much better of getting blender compiling and then
working backwards with a feature as we mentioned
earlier. I'm not trying to sound like a dork not trying to help you, its just the way it is, and I'm trying to help.

So whats what in the blender world. Well there are these external packages as well as a number of others:
FTGL For international Font stuff.
PYTHON Used for scripting
SDL Used for Audio stuff in the sequencer
Freetype For fonts.
zlib Compression (asl required by libpng,libjpeg)
libpng Support for png images
libjpeg Support for jpeg images.
gettext For international Font stuff.
openal Used for audio in game engine.

Then there are a bunch of extra libraries in blender/intern
They are all similar and you can figure out most of them by the name, if your not sure of one ask.

There is also a blender/extern directory which is libs that aren't in intern and probably are not on your system so they are included as well all of these currently are for the game engine.

Next we move to blender/source/ dirs you may want explinations for:
gameengine gameengine specific code
blender Most of the code for blender is in
here its a huge directory broken down by various groupings
creator this is the location of the "main()" for
blender it should probably go into the source directory
but at one time there was a creator and a publisher version of blender and there were two directorys one for each version of blender.

the kernel dir has code that is shared by blender and the game engine and is sort of the code that lets the two talk to each other.

Smerity
Posts: 10
Joined: Wed Mar 19, 2003 10:48 am

Post by Smerity »

I do not pretend to be a highly competent coder, I have never been formally taught C/C++ and am only in Year 9, but in the way I am trying to learn at the moment, I think I am proceeding well...

I began using the usual stuff, learning how to program hello world, calculators, etc etc etc.

The way I started off with Blender tho was I added two simple buttons in the render area, one which simply was a slide bar for OSA and the other a way to choose background colour in there. These gave me the basic grounding in how to initiate buttons, how and where Blender's variablels are stored and how to access them.

I proceeded by adding a "cheat sheet" in Blender using the same functions as a splash screen. This worked completely fine, and gave me an intro to the datotoc program and also linking in an external file to Blender.

I always doodle in the code, you just do whatever you want. I looked into Eeshlo's AO code, and into the knife cut (I got that so it would select individual faces too) and other little silly projects.

My latest project was modifying Blender's raytracer so that it works in an additive mode (tho not very well, but that's not the point).

The main point is before you try and tackle a large project in Blender, you have to know the groundings first. I tried learning Blender's structure by starting programming a project, but in my experience (and at least to me) that doesn't work too well...

Anyway, that's all I have to say, you just gotta keep battling, there's no secrets to understanding it but time.
(also, invaluable, when you don't know what something does,

grep -r 'Whatever you want' files > searchresults.txt

ie, grep -r '#define horse' *.r > definehorse.txt)

gabio
Posts: 0
Joined: Thu Jan 15, 2004 6:41 am
Location: Canada - Québec - Sherbrooke
Contact:

Post by gabio »

May I ask a question?
well i trying to code something easy to begin, let say a floating panel in the 3dview. I followed the tutorial Here . What i wanted to do is coding this feature, the Object info floating box.
Now what i did so far:

BIF_space.h(56):

Code: Select all

#define VIEW3D_HANDLER_INFO			4
drawview.c(1647)

Code: Select all

static void view3d_panel_info(short cntrl) /*VIEW3d_HANDLER_INFO */
{
	uiBlock *block;
	View3D *vd;
	
	vd= G.vd;

	block= uiNewBlock(&curarea->uiblocks, "view3d_panel_info", UI_EMBOSS, UI_HELV, curarea->win);
	uiPanelControl(UI_PNL_SOLID | UI_PNL_CLOSE  | cntrl);
	uiSetPanelHandler(VIEW3D_HANDLER_INFO);  // for close and esc
	if(uiNewPanel(curarea, block, "Object Info", "View3d", 340, 10, 318, 204)==0) return;
	
	uiDefBut(block, LABEL, 1, "place you stuff here:",	0, 20, 76, 19, NULL, 0.0, 0.0, 0, 0, "En construction");
}
drawview.c(1682)

Code: Select all

case VIEW3D_HANDLER_INFO:
			view3d_panel_info(v3d->blockhandler[a+1]);
			break;
header_view3d.c(1502):

Code: Select all

uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "View Object Info",		0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 15, "");
What i'm trying to do is to call it from the Object menu header. But i dont have anyidea how menu is working. just tried to add the line in header_view3d.c, but when activated ether the tranform panel or the object info panle, it show up both: the transform panel and my panel. Also my panel can't be closed, if the tranform panel is closed, then the two close. N key also bring my panel up. For sure i dont understand event handler well.
How does blender think my panel is the same as the transform panel?

Post Reply