Rockbox.org home
Downloads
Release release
Dev builds dev builds
Extras extras
themes themes
Documentation
Manual manual
Wiki wiki
Device Status device status
Support
Forums forums
Mailing lists mailing lists
IRC IRC
Development
Bugs bugs
Patches patches
Dev Guide dev guide
Search



Donate

Rockbox Technical Forums


Login with username, password and session length
Home Help Search Staff List Login Register
News:

Welcome to the Rockbox Technical Forums!

+  Rockbox Technical Forums
|-+  Rockbox Development
| |-+  Starting Development and Compiling
| | |-+  noobish problems - C structure access and adding plugin images
« previous next »
  • Print
Pages: [1]

Author Topic: noobish problems - C structure access and adding plugin images  (Read 1625 times)

Offline Loggerin

  • Member
  • *
  • Posts: 3
noobish problems - C structure access and adding plugin images
« on: February 02, 2010, 10:15:07 PM »
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: [Select]
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);


and this is the wished for style that should work based on my learning c book and google searches
Code: [Select]
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);

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
Logged

Offline torne

  • Developer
  • Member
  • *
  • Posts: 994
  • arf arf
Re: noobish problems - C structure access and adding plugin images
« Reply #1 on: February 03, 2010, 05:45:19 AM »
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.
Logged
some kind of ARM guy. ipodvideo/gigabeat-s/h120/clipv2. to save time let's assume i know everything.

Offline Loggerin

  • Member
  • *
  • Posts: 3
Re: noobish problems - C structure access and adding plugin images
« Reply #2 on: February 03, 2010, 09:39:43 AM »
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
Logged

Offline torne

  • Developer
  • Member
  • *
  • Posts: 994
  • arf arf
Re: noobish problems - C structure access and adding plugin images
« Reply #3 on: February 03, 2010, 10:37:28 AM »
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.
Logged
some kind of ARM guy. ipodvideo/gigabeat-s/h120/clipv2. to save time let's assume i know everything.

Offline gevaerts

  • Administrator
  • Member
  • *
  • Posts: 1053
Re: noobish problems - C structure access and adding plugin images
« Reply #4 on: February 03, 2010, 10:52:25 AM »
There's also the initialiser-with-named-members style (which probably has a proper name), i.e.
Code: [Select]
str_sprite test_var = {
    .width=1,
    .height=2
};

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

Offline Domonoky

  • Developer
  • Member
  • *
  • Posts: 205
Re: noobish problems - C structure access and adding plugin images
« Reply #5 on: February 03, 2010, 01:08:50 PM »

About 2) custom images in plugins:
Are you sure you added the image to apps\plugins\bitmaps\native\SOURCES ? If yes, are you sure you added it to a ifdef section which actually gets compiled for your target ? (maybe try to add it just at the top)
Logged

Offline Loggerin

  • Member
  • *
  • Posts: 3
Re: noobish problems - C structure access and adding plugin images
« Reply #6 on: February 03, 2010, 08:18:04 PM »
torne:  yes, i was going to use the initialize syntax for the base values but i asked about the test_var.width format so i could actually change the values without having to recreate and reassign all the values at the same time.  thanks for the tip about initializing in the global scope, always like faster code ;D

gevaerts:  thanks for the tip. i also took out the typedef (just wanted to save a little on the typing) and i started reading the For Developers section in the DocsIndex. hopefully the coding style guidelines are in there somewhere, but if they aren't could you please direct me to where they are?

Domonoky: i did put it in their but i might have put it under a ifdef so i'll be testing it now. thanks
edit: apparently i had it right i just had to do the ../tools/configure and a system restart
« Last Edit: February 03, 2010, 10:27:12 PM by Loggerin »
Logged

  • Print
Pages: [1]
« previous next »
+  Rockbox Technical Forums
|-+  Rockbox Development
| |-+  Starting Development and Compiling
| | |-+  noobish problems - C structure access and adding plugin images
 

  • SMF 2.0.17 | SMF © 2019, Simple Machines
  • Rockbox Privacy Policy
  • XHTML
  • RSS
  • WAP2

Page created in 0.082 seconds with 15 queries.