Rockbox Development > Starting Development and Compiling

noobish problems - C structure access and adding plugin images

(1/2) > >>

Loggerin:
i've been wanting to learn C for a while and i've been using Rockbox for a while so, 1+1=2; make a plugin for Rockbox!

i do have programing experience (php mostly) and over the course of 3 days ive run into two problems that i cant figure out.

1) assigning data to a custom data structure
ive created a data structure and can access data from it easily enough but im having problems actually assigning data to begin with

this works but is the unwanted (nearly useless) method

--- Code: ---typedef struct{
int width;
int height;
int num_subimg;
int num_subimg_per_row;
int cur_subimg;
} str_sprite;

str_sprite test_var = {1, 2, 3, 4, 5};
rb->splashf(HZ, "width = %d", test_var.width);

--- End code ---


and this is the wished for style that should work based on my learning c book and google searches

--- Code: ---typedef struct{
int width;
int height;
int num_subimg;
int num_subimg_per_row;
int cur_subimg;
} str_sprite;

str_sprite test_var;
test_var.width = 1;
test_var.height = 2;
test_var.num_subimg = 3;
test_var.num_subimg_per_row = 4;
test_var.cur_subimg = 5;
rb->splashf(HZ, "width = %d", test_var.width);

--- End code ---

the error i keep getting is "test_game.c:65: error: parse error before '.' token"
line 65 is: test_var.width = 1;

its probably a stupid 'duh' error but i cant figure it out


2)custom images in plugin
i've tried copying how other plugins use their own images but i cant figure it out.  i have edited all the required SOURCES files (i think) and added the images to the directory of apps\plugins\bitmaps\native. i also opened them in photoshop and saved them as 16bit bmp which seems to be the standard. i also followed the naming standard of *plugin name*_*filename*.*width*x*height*x*depth*.bmp
after i compile i get errors to my images missing .h file. due to the fact that i cant find the other images .h files i've concluded they must be created during the compiling process and that my image's .h file is not.

so my question is what do i have to edit to get the compiler to generate the .h file or if i completely got this wrong please explain the whole image thing in rockbox

ps. i already figured out how to manipulate images (used the rockbox logo) already in rockbox, just not my own

torne:
Are you doing the assignments inside a function? The initialiser style (= {1, 2, 3, 4, 5};) works fine for a global variable declaration, but assigning to the individual members is not allowed outside of a function.

Loggerin:
that was it exactly ;D
i had created the structure and assigned its values in the global scope but after moving the assigning to the main function everything worked perfectly.
Thanks, no i can start working on the sprite functions ;D

torne:
You should know, though, that initialising global structures that way is less efficient. If you use the initialiser syntax (= {1, 2, 3, 4, 5}) then the compiler will initialise the global structure for you at compile time, and place the initialised structure in the .data section where it just needs to be loaded along with the rest of the plugin. If you do it by initialising the individual variables in plugin_start, then the structure goes in .bss (zero initialised) and it will generate additional code which runs in plugin_start. The result will be that your plugin is a tiny bit bigger, and takes a tiny bit longer to start up: it's not likely to matter greatly, but this is why the initialiser style is preferable.

gevaerts:
There's also the initialiser-with-named-members style (which probably has a proper name), i.e.

--- Code: ---str_sprite test_var = {
    .width=1,
    .height=2
};

--- End code ---

Also note that the rockbox coding style guidelines don't like typedef for structs.

Navigation

[0] Message Index

[#] Next page

Go to full version