Dude's Sonic Wii engine thread

Discussion in 'Engineering & Reverse Engineering' started by Dude, Nov 18, 2010.

Thread Status:
Not open for further replies.
  1. Dude

    Dude

    Tech Member
    3,138
    0
    16
    Southbridge, MA
    Random VR/AR trash
    Current issue: I'm having a hard time figuring out how to pick which tiles need to be shown onscreen. I'm getting 'tile pop', which is a result of the game dividing the screen coordinates by 256 to get the tile index of the upper left corner, and it is admittedly imprecise, which is causing the top and left rows to disappear when the division splits them off.

    [​IMG]

    somewhat recent implementation: <a href="http://pastebin.com/sjYYPq2s" target="_blank">http://pastebin.com/zRsu0mCY</a>
     
  2. GerbilSoft

    GerbilSoft

    RickRotate'd. Administrator
    2,895
    24
    18
    USA
    rom-properties
    Your conversion from row/col to index is slightly off. You should only multiply the row value by 256, not the column value.

    Code (Text):
    1. inline int rowcolToIdx(int row, int col)
    2. {
    3. &nbsp;&nbsp;&nbsp;&nbsp;return (col + (row * 256));
    4. }
    5.  
    6. inline int rowFromIdx(int idx)
    7. {
    8. &nbsp;&nbsp;&nbsp;&nbsp;return (idx >> 8);
    9. }
    10.  
    11. inline int colFromIdx(int idx)
    12. {
    13. &nbsp;&nbsp;&nbsp;&nbsp;return (idx & 0xFF);
    14. }
    Do note that these functions may end up returning an invalid index if the row value is too high. You'll have to add bounds checking yourself.

    Also, you might want to use unsigned values instead of signed values to prevent negative values. I used int for conciseness.
     
  3. Dude

    Dude

    Tech Member
    3,138
    0
    16
    Southbridge, MA
    Random VR/AR trash
    <a href="http://pastebin.com/Apt8UhGU" target="_blank">http://pastebin.com/Apt8UhGU</a>

    If anyone can figure out why the level isn't rendering, you win a cookie!
     
  4. DigitalDuck

    DigitalDuck

    Arriving four years late. Member
    4,915
    96
    28
    Lincs, UK
    TurBoa, S1RL
    <!--quoteo(post=531232:date=Nov 18 2010, 07:08 AM:name=Dude)--><div class='quotetop'>QUOTE (Dude @ Nov 18 2010, 07:08 AM) <a href="index.php?act=findpost&pid=531232">[​IMG]</a></div><div class='quotemain'><!--quotec-->If anyone can figure out why the level isn't rendering, you win a cookie!<!--QuoteEnd--></div><!--QuoteEEnd-->

    Lines 351-354:
    Code (Text):
    1. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(h = 0; h > 5; h++)
    2. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
    3. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(v = 0; v > 5; v++)
    4. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
    Try making those < signs so loops work correctly. :eng101:
     
  5. Sintendo

    Sintendo

    Member
    249
    0
    16
    Yeah, you do that in multiple places. Keep in mind that all types of loops in C (for, while) loop as long as the condition is true, you seem to have interpreted it the other way around (loops run until the condition is true).

    Also, any reason you're not using a 2D array to begin with?

    Code (Text):
    1. u8 tilearray[10][256];
     
  6. Dude

    Dude

    Tech Member
    3,138
    0
    16
    Southbridge, MA
    Random VR/AR trash
    <!--quoteo(post=531317:date=Nov 18 2010, 12:55 PM:name=Sintendo)--><div class='quotetop'>QUOTE (Sintendo @ Nov 18 2010, 12:55 PM) <a href="index.php?act=findpost&pid=531317">[​IMG]</a></div><div class='quotemain'><!--quotec-->Yeah, you do that in multiple places. Keep in mind that all types of loops in C (for, while) loop as long as the condition is true, you seem to have interpreted it the other way around (loops run until the condition is true).

    Also, any reason you're not using a 2D array to begin with?

    Code (Text):
    1. u8 tilearray[10][256];
    <!--QuoteEnd--></div><!--QuoteEEnd-->


    The reason I'm not using a 2d array is because for some reason if I try nesting one drawcall inside of 2 for loops (to keep track of array position), GRRLIB_DrawImg only draws one of the rows, so I opted for an approach where all of the tiles can be handled in one loop and the screen coords calculated as such.
     
  7. Dude

    Dude

    Tech Member
    3,138
    0
    16
    Southbridge, MA
    Random VR/AR trash
    <a href="http://pastebin.com/sjYYPq2s" target="_blank">http://pastebin.com/sjYYPq2s</a>

    It renders stuff now, but it's rendering the wrong tiles and I'm getting 'tile pop', where the leftmost and topmost rows sometimes don't draw. Any ideas?
     
  8. DigitalDuck

    DigitalDuck

    Arriving four years late. Member
    4,915
    96
    28
    Lincs, UK
    TurBoa, S1RL
    <!--quoteo(post=531778:date=Nov 20 2010, 01:32 AM:name=Dude)--><div class='quotetop'>QUOTE (Dude @ Nov 20 2010, 01:32 AM) <a href="index.php?act=findpost&pid=531778">[​IMG]</a></div><div class='quotemain'><!--quotec-->It renders stuff now, but it's rendering the wrong tiles and I'm getting 'tile pop', where the leftmost and topmost rows sometimes don't draw. Any ideas?<!--QuoteEnd--></div><!--QuoteEEnd-->

    They both sound like camera errors. The tile pop would suggest that you're not starting with the tile that's at the very top-left corner of the screen; I can't see why it's going wrong in the code, though. As for rendering wrong tiles... is that the entire screen, or just individual tiles?
     
  9. Dude

    Dude

    Tech Member
    3,138
    0
    16
    Southbridge, MA
    Random VR/AR trash
    <!--quoteo(post=531791:date=Nov 19 2010, 09:15 PM:name=DigitalDuck)--><div class='quotetop'>QUOTE (DigitalDuck @ Nov 19 2010, 09:15 PM) <a href="index.php?act=findpost&pid=531791">[​IMG]</a></div><div class='quotemain'><!--quotec--><!--quoteo(post=531778:date=Nov 20 2010, 01:32 AM:name=Dude)--><div class='quotetop'>QUOTE (Dude @ Nov 20 2010, 01:32 AM) <a href="index.php?act=findpost&pid=531778">[​IMG]</a></div><div class='quotemain'><!--quotec-->It renders stuff now, but it's rendering the wrong tiles and I'm getting 'tile pop', where the leftmost and topmost rows sometimes don't draw. Any ideas?<!--QuoteEnd--></div><!--QuoteEEnd-->

    As for rendering wrong tiles... is that the entire screen, or just individual tiles?
    <!--QuoteEnd--></div><!--QuoteEEnd-->

    I mean that the layout being shown doesn't match the one in the map editor. However, it does appear as though one tile on the screen usually shows the right tile, but I can't be sure. A different method for gathering the onscreen tiles might help, but I'm out of ideas for a fresh implementation.

    edit: screenshot because people like pictures of stuff =P

    [​IMG]
     
  10. Sintendo

    Sintendo

    Member
    249
    0
    16
    I'm not sure if this is related, but you're going out of your vis_tiles array bounds.

    Code (Text):
    1. unsigned int vis_tiles_1[3];
    2. unsigned int vis_tiles_2[3];
    3. unsigned int vis_tiles_3[3];
    4. unsigned int vis_tiles_4[3];
    Keep in mind that these arrays can only contain 3 items and the highest usable index for them is 2.

    Code (Text):
    1. for(h = 0; h < 4; h++) // first row
    2. {
    3. &nbsp;&nbsp;&nbsp;&nbsp;vis_tiles_1[h] = first_tile + h;
    4. }
    5.  
    6. for(h = 0; h < 4; h++) // second row
    7. {
    8. &nbsp;&nbsp;&nbsp;&nbsp;vis_tiles_2[h] = (first_tile + 256) + h;
    9. }
    10.  
    11. ...
    I'll let you know if I find more.
     
  11. Dude

    Dude

    Tech Member
    3,138
    0
    16
    Southbridge, MA
    Random VR/AR trash
    [​IMG]

    The level is loading properly, the only immediate issue is the tile pop (left/uppermost tiles disappearing unless camera coordinates are divisible by 256).

    <a href="http://pastebin.com/iApiBywT" target="_blank">http://pastebin.com/iApiBywT</a> <- latest source, for the curious/helpful =]
     
  12. Lapper

    Lapper

    Member
    1,605
    221
    43
    England
    Sonic Studio, Sonic Physics Guide, Kyle & Lucy: WW, Freedom Planet 2
    Not being able to help, I'll say this: This looks really interesting, it'd be nice to see a video =P.
     
  13. Dude

    Dude

    Tech Member
    3,138
    0
    16
    Southbridge, MA
    Random VR/AR trash
    [​IMG]

    Level rendering works now, onto collision detection.
     
  14. Aerosol

    Aerosol

    FML and FU2 Moderator
    10,619
    82
    28
    Not where I want to be.
    Sonic (?): Coming summer of 2055...?
    Just as a note, Dude, every engine I've ever seen has the layer switching at the apex of the curve, so in the case of a loop, the point at which you switch from one layer to the other should be at the top of the loop. The way you have it, you go from layer 1 to layer 0 to layer 2, with layer 1 being blue, layer 0 being the regular layer, and layer 2 being the red. It should go straight from layer 1 to layer 2 at the top of the loop.
     
  15. Dude

    Dude

    Tech Member
    3,138
    0
    16
    Southbridge, MA
    Random VR/AR trash
    <!--quoteo(post=532428:date=Nov 21 2010, 09:53 PM:name=AerosolSP)--><div class='quotetop'>QUOTE (AerosolSP @ Nov 21 2010, 09:53 PM) <a href="index.php?act=findpost&pid=532428">[​IMG]</a></div><div class='quotemain'><!--quotec-->Just as a note, Dude, every engine I've ever seen has the layer switching at the apex of the curve, so in the case of a loop, the point at which you switch from one layer to the other should be at the top of the loop. The way you have it, you go from layer 1 to layer 0 to layer 2, with layer 1 being blue, layer 0 being the regular layer, and layer 2 being the red. It should go straight from layer 1 to layer 2 at the top of the loop.<!--QuoteEnd--></div><!--QuoteEEnd-->

    I'm only rendering the collision ATM, the object for layer switching hasn't been implemented yet. I'll remember that though.
     
  16. Lapper

    Lapper

    Member
    1,605
    221
    43
    England
    Sonic Studio, Sonic Physics Guide, Kyle & Lucy: WW, Freedom Planet 2
    <!--quoteo(post=532426:date=Nov 22 2010, 02:46 AM:name=Dude)--><div class='quotetop'>QUOTE (Dude @ Nov 22 2010, 02:46 AM) <a href="index.php?act=findpost&pid=532426">[​IMG]</a></div><div class='quotemain'><!--quotec-->[​IMG]

    Level rendering works now, onto collision detection.<!--QuoteEnd--></div><!--QuoteEEnd-->
    Oh. Not got very far then. Bah, at least rendering is working for you.
     
  17. Dude

    Dude

    Tech Member
    3,138
    0
    16
    Southbridge, MA
    Random VR/AR trash
    [​IMG]

    Camera works now, and no longer causes a stack overflow because you can't push the camera out of bounds. I also have a debug menu system that lets you flip through pages of information about what's going on in the game's internals. Collision later today, prior engagements willing.
     
  18. nineko

    nineko

    I am the Holy Cat Tech Member
    <!--quoteo(post=532428:date=Nov 22 2010, 03:53 AM:name=AerosolSP)--><div class='quotetop'>QUOTE (AerosolSP @ Nov 22 2010, 03:53 AM) <a href="index.php?act=findpost&pid=532428">[​IMG]</a></div><div class='quotemain'><!--quotec-->every engine I've ever seen has the layer switching at the apex of the curve, so in the case of a loop, the point at which you switch from one layer to the other should be at the top of the loop.<!--QuoteEnd--></div><!--QuoteEEnd-->Most of the loops in Sonic 2 and Sonic 3 & Knuckles have the path changer at the top. Though there are some loops in Ice Cap (and possibly other zone) that have the path changer at the left. That is necessary for those sections with 2 or 3 stacked loops.
     
  19. Lapper

    Lapper

    Member
    1,605
    221
    43
    England
    Sonic Studio, Sonic Physics Guide, Kyle & Lucy: WW, Freedom Planet 2
    So... what's the progress on this?
     
  20. Dude

    Dude

    Tech Member
    3,138
    0
    16
    Southbridge, MA
    Random VR/AR trash
    <!--quoteo(post=534035:date=Nov 28 2010, 08:26 AM:name=Sonica)--><div class='quotetop'>QUOTE (Sonica @ Nov 28 2010, 08:26 AM) <a href="index.php?act=findpost&pid=534035">[​IMG]</a></div><div class='quotemain'><!--quotec-->So... what's the progress on this?<!--QuoteEnd--></div><!--QuoteEEnd-->

    I started implementing a rings system last night after MainMemory added them to the level editor he's making for me. I'm probably not going to use the png-based collision system after running into too many 'how do I go about doing this' problems.
     
Thread Status:
Not open for further replies.