Author Topic: Need a little help with coding for menu  (Read 25602 times)

0 Members and 1 Guest are viewing this topic.

Offline Conle

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2203
Re: Need a little help with coding for menu
« Reply #30 on: August 05, 2010, 01:43:48 PM »
By the way,this loop needs unrolling :
Code: [Select]
        for (int i=0; i<320; i+=back[b]->width)
            for (int j=0; j<240; j+=back[b]->height)
            {
            rdp_load_texture(0, 0, MIRROR_DISABLED, back[b]);
                rdp_draw_sprite(0, i, j);
                b=b+1;
            }

to
Code: [Select]
        for (int j=0; j<240; j+=back[b]->height)
        for (int i=0; i<320; i+=back[b]->width)
       {
            rdp_load_texture(0, 0, MIRROR_DISABLED, back[b++]);
            rdp_draw_sprite(0, i, j);
        }
~sm-36.gif~

Offline ChillyWilly

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1751
  • Just a coding machine.
Re: Need a little help with coding for menu
« Reply #31 on: August 05, 2010, 02:22:01 PM »
Err - you didn't unroll it, you just flipped the order the tiles are drawn in.  ^-^

Offline Conle

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2203
Re: Need a little help with coding for menu
« Reply #32 on: August 05, 2010, 02:45:55 PM »
That!   ::sm-02::

Offline sanni

  • Moderator
  • Hero Member
  • *****
  • Posts: 502
Re: Need a little help with coding for menu
« Reply #33 on: August 05, 2010, 04:47:07 PM »


Seems like I messed up while cutting the image in 80 pieces, stupid black line  :-\


Offline Conle

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2203
Re: Need a little help with coding for menu
« Reply #34 on: August 05, 2010, 05:11:20 PM »
Don't edit manually each tile...Just store the background somewhere in rom or ram or psram and just do something like :

Code: [Select]
void upload_tiles(const unsigned char* buffer,int tileW,int tileH)
{
const char* end;
sprite_t* img = (sprite_t*)buffer;
const int blockSize = (tileW * tileH * img->bitdepth);

buffer += sizeof(sprite_t); //Skip lib dragon header

for(end = img->w * img->h * img->bitdepth - sizeof(sprite_t); buffer < end; buffer += blockSize)
{
img.data = buffer;
sync pipe
upload data
display data
}
}

Then you do :
Code: [Select]
upload_tiles(buffer,32,32); to fill the screen with 32x32 tiles.
 ::sm-10.gif::

ps - By the way , the image looks pretty good.Is it 32 or 16 bit?  ~sm-55.gif~.gif
ps2 - forgot to tell you that of course you must calculate the offset of each tile.
Its extremely simple.You'll need a variable for X and Y axis. Then , while looping , you increase X axis equally to tileW.
When X axis reaches screen width , you increase the Y axis by tileH pixels and you set the x pointer back to offset 0.
 8)

Edit again - Anyway here's the code if you feel puzzled :D
Code: [Select]
void upload_tiles(const unsigned char* buffer,int tileW,int tileH)
{
   const char* end;
   int x,y;
   sprite_t* img = (sprite_t*)buffer;
   const int blockSize = (tileW * tileH * img->bitdepth);

   buffer += sizeof(sprite_t); //Skip lib dragon header

   for(x = y = 0,end = img->w * img->h * img->bitdepth - sizeof(sprite_t); buffer < end; buffer += blockSize)
   {
  if(x >= img->w)
  {
         x = 0;
         y += tileH;
      }

      img.data = buffer;
      sync pipe
      upload data
      display img , x , y

  x += tileW;
   }
}
« Last Edit: August 05, 2010, 06:24:38 PM by Conle »

Offline sanni

  • Moderator
  • Hero Member
  • *****
  • Posts: 502
Re: Need a little help with coding for menu
« Reply #35 on: August 05, 2010, 07:14:35 PM »
Thats great, I will try that soon. That way changing the background would be a lot easier.  :)
The background is made with paint.net in 32bit, then sliced into 80 pieces, each saved as bmp and then batch converted to a 8Bit(256 Colors) png with Irfanview and finally with mksprite to a 16bit sprite. And TV is a 42" plasma. Picture made with Sony K750i mobile phone.

Anyway here the current state, it's not perfect but it's slowly progressing.  ::sm-29.gif::

« Last Edit: August 06, 2010, 03:09:01 PM by sanni »

Offline ChillyWilly

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1751
  • Just a coding machine.
Re: Need a little help with coding for menu
« Reply #36 on: August 05, 2010, 08:40:41 PM »
That's coming along rather well.  ::sm-09.gif::

Offline Conle

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2203
Re: Need a little help with coding for menu
« Reply #37 on: August 05, 2010, 09:10:21 PM »
Indeed it looks really good.   :) The only thing i don't like is the font color for the entry list.Maybe pick a bit darker colors.

Quote
Thats great, I will try that soon. That way changing the background would be a lot easier.

Just don't forget to fix this line in the code i posted:
Code: [Select]
for(x = y = 0,end = img->w * img->h * img->bitdepth - sizeof(sprite_t); buffer < end; buffer += blockSize)

To
Code: [Select]
for(x = y = 0,end = buffer + (( img->w * img->h * img->bitdepth) - sizeof(sprite_t)); buffer < end; buffer += blockSize)

Because the offset must be relative to the buffer address.
I haven't tested the code(written it just off the top of my head) but the algorithm looks fine.

Offline sanni

  • Moderator
  • Hero Member
  • *****
  • Posts: 502
Re: Need a little help with coding for menu
« Reply #38 on: August 06, 2010, 03:18:25 PM »
Is there anything better than Geany for programming on kubuntu?

Offline Conle

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2203
Re: Need a little help with coding for menu
« Reply #39 on: August 06, 2010, 03:27:37 PM »
Is there anything better than Geany for programming on kubuntu?

 O0O  O0O There's nothing better than Gedit with oblivion theme.  (Edit-->I think it must be called Kedit on Kubuntu  ~sm-79.gif~.gif )
 ^-^   8)
« Last Edit: August 06, 2010, 03:33:02 PM by Conle »

Offline ChillyWilly

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1751
  • Just a coding machine.
Re: Need a little help with coding for menu
« Reply #40 on: August 06, 2010, 04:01:39 PM »
Is there anything better than Geany for programming on kubuntu?

Are you looking for something lighter, or heavier? Lighter - gedit. Heavier - Code Blocks or Eclipse.

Offline sanni

  • Moderator
  • Hero Member
  • *****
  • Posts: 502
Re: Need a little help with coding for menu
« Reply #41 on: August 06, 2010, 04:10:45 PM »
Oh, I meant xubuntu of course, sorry ::sm-02::

Thank you I will try gedit, I already did try Eclipse on Windows but that was too much.

Offline Conle

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2203
Re: Need a little help with coding for menu
« Reply #42 on: August 06, 2010, 06:24:35 PM »
Oh, I meant xubuntu of course, sorry ::sm-02::

I believe that this is the purpose of those distros : to confuse us  ::sm-05::
You've   lost the battle  ::sm-16.gif::  , but not the war   O0O

Offline madmonkey

  • Neo MOD
  • Full Member
  • *
  • Posts: 178
Re: Need a little help with coding for menu
« Reply #43 on: August 06, 2010, 06:57:36 PM »
heavier: qt creator.
you don't need to use qt or qt project system to use it, and it's definitely convenient, but it's heavy :)

Offline sanni

  • Moderator
  • Hero Member
  • *****
  • Posts: 502
Re: Need a little help with coding for menu
« Reply #44 on: August 06, 2010, 07:23:02 PM »
- What I need is, when I write as example:
rdp_load_texture(
Then it should tell me if rdp_load_texture returns an int or what and also what I have to put into the parentheses. Right now if allways have to search through all header files and look by myself.

- Also I need more colors.
It should color all different kind of keywords
Like if I write:
sprite_t *images[2] = {NULL, NULL};
Then sprite_t and such things e.g. int or so should be colored, because that all are those definition things that define what type it is. So if I see that color, I know, here something gets defined.
And then *images[2] should be in an color for arrays and so on.

And when I write:
if
{
    if
  {
  }
   else
 {
 }
}
Then the matching brackets  should be in the same color as the if but in an other color then other brackets and other ifs so I know this bracket belongs to that bracket and that if.

Also if I write it like this:
   else
 {
 {
I would notice it because the brackets would be of different color.

- And also I don't wanna type make in the shell. Because it just says look in line 745 you messed up. But it would be better if I could just compile from within the editor and it would highlight the lines in the editor so I don't have to search. Because I do allot of line searching.

- Also very important i would like some sort of  book mark function, where I can label bookmarks in the code for quick jumping to different parts of the code.