Page 1 of 1
Need help with cursors please
Posted: Sat Sep 22, 2012 7:06 am
by Roroy
Hello,
I have been following this tutorial:
http://www.codemii.com/2008/08/31/tutorial-4-cursors/
And I can't quite understand one section of the code:
Code: Select all
void DrawHLine (int x1, int x2, int y, int color) {
int i;
y = 320 * y;
x1 >>= 1;
x2 >>= 1;
for (i = x1; i <= x2; i++) {
u32 *tmpfb = xfb;
tmpfb[y+i] = color;
}
}
Specifically the
u32 *tmpfb = xfb;
tmpfb[y=i] = color;
Am I right in assuming that a new variable named tmpfb is created?
What is the purpose of the asterisk?
What does xfb mean?
What is the purpose of the [y+1]?
What does the >>= symbol mean? I've never seen it in C/C++ Programs before...
Thanks in advance.
I appreciate any help given!
Re: Need help with cursors please
Posted: Sat Sep 22, 2012 9:17 pm
by mtheall
Am I right in assuming that a new variable named tmpfb is created?
What is the purpose of the asterisk?
What does xfb mean?
What is the purpose of the [y+1]?
What does the >>= symbol mean? I've never seen it in C/C++ Programs before...
Yes, a new variable named tmpfb is created. The * indicates that it is a pointer. xfb is probably a global variable that was declared elsewhere. The [y+1] is an array dereferencer. Specifically, it is equivalent to "*(typeof(tmpfb))((int)tmpfb + (y+1)*sizeof(*tmpfb))". >>= is the bitwise shift + assignment combo operator.
If you don't know that a variable is being declared, you don't know what * is for, you don't know what [] means when applied to a pointer, you don't know what >>= is, then you need to be going through some C/C++ tutorials, not a Wii tutorial.
Re: Need help with cursors please
Posted: Tue Sep 25, 2012 8:53 am
by Roroy
Took your advice and step by step, have been taking C++ Tutorials.
So hopefully will understand this better.
Found out where xfb was declared:
static void *xfb = NULL;
(At the very top of the example source code in Wii folder)
But I don't get what this line does...
Re: Need help with cursors please
Posted: Tue Sep 25, 2012 11:25 pm
by mtheall
This line? It does the following things:
1. Declare a variable xfb
2. xfb is of type void* (a pointer to void, i.e. a pointer to generic/unknown type)
3. Assign the value NULL to xfb (NULL is ((void*)0) in GNU)
4. xfb is static (other translation units will never be able to see this variable, i.e. other c/cpp/h/hpp files)
Re: Need help with cursors please
Posted: Thu Sep 27, 2012 6:46 am
by relminator
Why are they still using software rendering on the Wii when we on the DS are doing HW accel?
Re: Need help with cursors please
Posted: Thu Sep 27, 2012 6:55 pm
by Izhido
Cause it's fun?
You should take a look at the beautiful things you can create when you have a crude, raw circle/arc drawing algorithm and a way to place pixels directly on-screen. Wonderful, wonderful GW-BASIC-over-DOS-programs memories...
(Oh. And slow pixel-filling algorithms too
)
Re: Need help with cursors please
Posted: Fri Sep 28, 2012 7:09 am
by relminator
Izhido wrote:Cause it's fun?
You should take a look at the beautiful things you can create when you have a crude, raw circle/arc drawing algorithm and a way to place pixels directly on-screen. Wonderful, wonderful GW-BASIC-over-DOS-programs memories...
(Oh. And slow pixel-filling algorithms too
)
Oh, trust me I do:
http://rel.phatcode.net/junk.php?id=119
Look at the bottom screens.