Author Topic: Mappy  (Read 1274 times)

nodtveidt

  • Guest
Re: Mappy
« Reply #15 on: July 28, 2014, 03:26:39 AM »
Oh, and on the spr_make thing... that is a convenience function I wrote for obeybrew.com that I sometimes use in my own prototyping. When I know things work, I remove the function calls and replace them with proper code. It's just a simplistic way of getting sprites onto the screen, but it creates a ton of overhead and is pretty inefficient so it's not intended to be used regularly.

Bonknuts

  • Hero Member
  • *****
  • Posts: 3292
Re: Mappy
« Reply #16 on: July 28, 2014, 03:46:45 AM »
PD: Hah!

HyperFighting: ImagetoPCE (that recent app?) is a completely different function than Mappy. It's more for creating BG from a pic, where as Mappy is a tilemap editor (along with brushes and other stuffs).

 I convert my Mappy files directly to raw PCE files; tilemap, tiles, and palette. I've discovered a few tricks with using the editor, over the years. I wrote a conversion app (FMP2PCE... very original name :B ) to handle more complex stuff from the FMP format. I can clip any x1/x2, y1/y2 of a FMP tilemap. I can use embedded palette info for tiles (it knows what tiles belong to which subpalette number based on encoded color differences in the 36 increment/steps). I can offset the starting palette number. I can set the vram offset for the tiles. I can output the map in vertical or horizontal strips. 16x16 maps are converted to meta-tile and tiles divided down into 8x8. The map data can be prep'd for LUT use or no LUT use (map entry =tile_num*4, meta-tiles are offsets of 0,+1,+2,+3). You can choose other BG 'layers' in the FMP as collision maps(provided in byte or nibble output format), and optionally provided an offset subtract for that BG layer (to start with a cooked offset of '00' rather than the real tile number associated in the BG layer entry). Etc.

 I can create really large maps, that all use the same tile setup, and then chop them into 'screens' and save them individually, etc. Having a collision overlay, without having to tie it directly to tiles, is nice.

 But digging through the format, FMP format supports quite a few things that the editor does not. Each tile can have a whole range of attributes applied to it. Unfortunately, you need either the paid for Pro version, or you need to write LUA scripts to access that (from what I could tell).

As an editor, Mappy isn't exactly great. But it's decent for basic stuffs. And with a few tricks, you can supplement a few features manually. Since I have a crop function, I actually use large maps, with all the tiles I'm using in vram - at the start/top of the map. This allows me to format the order of the tiles (keeps them from being random), good for setting up animation or swapping them out, etc. And some blank area, to allow me to setup 'brushes' and save them, etc.





Off topic: The thing about vsync and updating the satb in vram; VDC satb auto dma happens right after the last visible line of the display (of the VDC, not the VCE). It doesn't happen again until the next frame. You won't have enough time to update the real SAT registers in the VDC (which the DMA does). So your sprite updates will be delayed by one frame. If you're syncing them to the background, you'll need to delay updating it as well. You'll see a good number of early PCE games that get this wrong (where sprites are supposed to be part of the BG layer); they get out of sync usually be one pixel (single pixel scrolling).

 I handle this by putting my vsync 'flag', in the hsync area (quite a number of scanlines before real vsync interrupt). This lead time allowed me to get gamepad input, do some responses, then update SATB in vram. When vsync does hit, it'll update it. Though you can't always fit collision and other code in this gap of time. Other method was delay the BG updates to sync with sprites, using a request system. That gives me the whole active display area to workout all game logic in time, without having to try and fit it vblank (regardless of sync issues or not). And the last method was more advanced; setting up the VDC to do two 'frames' per VDC frame. This allows you to have a SATB at the start of active display (or have it underneath a top border/stat window). For a while, I thought manually triggering SATB update via writing to the SATB destination reg immediate triggered SATBDMA on the VDC side, but my tests showed that wasn't the case and only issued a one time request at the end of the next frame. 

 How do you guys handle this? Have you gotten the same or different results, regarding SATBDMA syncing/frame reference?

Necromancer

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 21366
Re: Mappy
« Reply #17 on: July 28, 2014, 04:41:25 AM »
Heh, I totally went in here thinking Bonknuts was thinking of porting Mappy to the PCE...

Me too, then they started in with all this code gobbledygook and I fell asleep.  :mrgreen:
U.S. Collection: 97% complete    155/159 titles

HyperFighting

  • Newbie
  • *
  • Posts: 7
Re: Mappy
« Reply #18 on: July 28, 2014, 02:18:01 PM »
Hey guys I must say it is honor get some help from you guys. I really appreciate you guys taking the time to help me out. The Obey website rocks!!!! I feel like I have very evolved state machine for my main character at this point I want to eventually have something significant to show you guys.

I am looking for an alternative to Mappy and I think ImagetoPCE might just be the ticket. I should have removed the bonk stuff in the code I posted as it over complicates matters. I just wanted to give a beginner a quick snippet that they could work with when importing a map data created by ImagetoPCE. The ultimate goal is to be able to scroll to anywhere in the map I thought I was on the right track with the scroll command.

Bonknuts - I realize ImagetoPCE is intended to create a background from a picture but technically you could play by the rules work within the 16 pals and draw a bunch of repeating tiles and ten export it out of ImagetoPCE and it will do the optimizations (determine the repeating tiles etc).
It's like your favorite image editor is your Mappy and ImagetoPCE is your means to output your map.
The FMP stuff is crazy interesting I will definitely look into this as well (My head almost exploded it will take me a minute to comprehend all of this craziness)

I still have to run more tests to see if I can get scrolling happening on a larger map and figure out how to properly increment hex values when importing larger map data. :D

TheOldRover - I am definately using the spr_make command with my existing code and am using #incspr to load my .pcx files based on the examples on the Obey site. Now that I know this not the best approach I will have to investigate further.

Thanks again guys the more you think you know you don't.

synbiosfan

  • Hero Member
  • *****
  • Posts: 716
Re: Mappy
« Reply #19 on: July 28, 2014, 02:36:07 PM »
Heh, I totally went in here thinking Bonknuts was thinking of porting Mappy to the PCE...

Me too, then they started in with all this code gobbledygook and I fell asleep.  :mrgreen:

I also had my dreams crushed!

nodtveidt

  • Guest
Re: Mappy
« Reply #20 on: July 28, 2014, 02:56:15 PM »
You are on the right track with the scroll() function... TheOldMan was just curious as to why you were doing both a scroll() and a sprite move at the same time. Normally in games, you use one or the other but not both, unless you have a lazy camera setup.

EDIT: OK, I realize that that may have been confusing. :) For moving your player character around, you usually only scroll the screen or move the sprite in the same frame, but not both in the same frame.
« Last Edit: July 28, 2014, 02:58:11 PM by The Old Rover »

Bonknuts

  • Hero Member
  • *****
  • Posts: 3292
Re: Mappy
« Reply #21 on: July 28, 2014, 03:06:31 PM »
I am looking for an alternative to Mappy and I think ImagetoPCE might just be the ticket. I should have removed the bonk stuff in the code I posted as it over complicates matters. I just wanted to give a beginner a quick snippet that they could work with when importing a map data created by ImagetoPCE. The ultimate goal is to be able to scroll to anywhere in the map I thought I was on the right track with the scroll command.

Bonknuts - I realize ImagetoPCE is intended to create a background from a picture but technically you could play by the rules work within the 16 pals and draw a bunch of repeating tiles and ten export it out of ImagetoPCE and it will do the optimizations (determine the repeating tiles etc).
It's like your favorite image editor is your Mappy and ImagetoPCE is your means to output your map.
The FMP stuff is crazy interesting I will definitely look into this as well (My head almost exploded it will take me a minute to comprehend all of this craziness)


 ImagetoPCE isn't an editor though, therefore it's not an alternative. It's a conversion app. You could use it along side Mappy (Mappy can export into one large bitmap output file). Mappy isn't my favorite, it's just easy and convenient as an editor, and the format of FMP is clean and easy to use (with conversion tools, etc). But yeah, Mappy is a tilemap design tool. Image2PCE is an image conversion tool.

 Image2PCE is pretty decent, but I have other conversion tools that do the same. Image2PCE is an alternative to those, but it also has some downsides (sometimes I don't want lossy down sampling of colors, or I need other specifics like forcing a certain color to BG #0, etc). The more apps, the better.

TheOldMan

  • Hero Member
  • *****
  • Posts: 958
Re: Mappy
« Reply #22 on: July 28, 2014, 04:17:38 PM »
Quote
if I can get scrolling happening on a larger map....
A 2 screen x 2 screen setup isn't too hard to do; you just have to find the right constants for initializing the screen, and load the BAT correctly. The trade-off is, it uses 4K of VRAM (about 1/4, iirc).

The other choice is to check out the map_ functions; though I haven't played with them, they -should- let you scroll around on a very large map.

How large of a map are you talking about?

HyperFighting

  • Newbie
  • *
  • Posts: 7
Re: Mappy
« Reply #23 on: July 29, 2014, 04:22:46 PM »
My master plan is to have a map that is 3 screens high and as long width wise as I can make it.

The game would have a top area  (used for collecting secrets)
A middle area (used for the majority of the gameplay)
A bottom area (where the player falls to when he falls though a crack).

Each screen would tile seamlessly so that they could repeat and repeat forever.

 I managed to figure out how seamlessly repeat the same screen over and over again by messing with the move_map(whichway) function that is used in the Obey Brew Tutorial Part 7 - The State Of The State (Using the Mappy example provided)

I then wanted to see if there was a way I could export an entire map I created through photoshop to a PCE format and this is where the ImageToPCE came in.

Today I tried exporting a 512x512 image from ImageToPCE. I was unsuccessful when attempting to get it to scroll vertically...The image just kept repeating after the first screen.

I tried several attempts at implementing the map stuff similar to the format seen below... I realized that set_tile_data(leveltiles); is supposed to get three parameters if #incchr_ex is not used but I couldn't get it to compile correctly.The basic is idea is displayed below it is terrible freehand stuff but should describe gist of how I am trying to make it happen.   


Code: [Select]
#incbin(levelmap,"Star_DATA.bin");
#incbin(leveltiles,"Star_BAT.bin");
#incbin(levelpal0,"Star_PAL.bin"); 
main()
{
set_map_data(levelmap, 64, 64);
set_tile_data(leveltiles, 64, 1);
load_tile(0x1000);
load_map(0, 0, 0, 0, 34, 28);
load_palette(0, levelpal0, 1);

  for(;;)
  {
      if (input)
       mapx++;
       mapy++;
       load_map(mapx,mapy,mapx,mapy,1,SCR_H);
  }
     scroll(0,mapx, mapy, 0, 223, 0xc0);

I am beside myself after reviewing the spr_make function.

Code: [Select]
spr_make(spriteno,spritex,spritey,spritepattern,ctrl1,ctrl2,sprpal,sprpri)
int spriteno,spritex,spritey,spritepattern,ctrl1,ctrl2,sprpal,sprpri;
{
spr_set(spriteno);
spr_x(spritex);
spr_y(spritey);
spr_pattern(spritepattern);
spr_ctrl(ctrl1,ctrl2);
spr_pal(sprpal);
spr_pri(sprpri);
}

At a quick glance this function appears to use ints so I figured certain variables could be modified to be chars and that would optimize the function a little bit but I fear the real optimization comes from using different function calls. The entire function is based on function calls so this would mean using different more efficient function calls to create a sprite?

I would like to have a top score displayed at the top of the screen. I noticed when my background scrolls so does my text!? I can't seem to get it to sit still

The more you think you kno the more you don't know. Sorry for the ramblings and thanks for taking interest in this sad state of affairs.

TheOldMan

  • Hero Member
  • *****
  • Posts: 958
Re: Mappy
« Reply #24 on: July 29, 2014, 05:11:07 PM »
OKay, okay. One at a time :)

Quote
I was unsuccessful when attempting to get it to scroll vertically...The image just kept repeating after the first screen.
look at ...doc/Huc/clibref.txt. There is a function  set_screen_size(char size) that changes the size of the -virtual- screen (not the displayed screen). The scroll function uses the size of the virtual screen for scrolling, iirc. And of course, the default value is 32 tiles wide, to match what you see. Change it and you should be able to do a 512 pixel (64 tile) scroll quite easily.
When we did PP, I -think- I used a 64x64 tile screen.

Quote
I realized that set_tile_data(leveltiles); is supposed to get three parameters if #incchr_ex is not used but I couldn't get it to compile correctly.

...set_tile_data(leveltiles, 64, 1);....

The third parameter is a char *, which is an address. try set_tile_data( leveltiles, 64, levelpal0 ) and see if that works.

Quote
At a quick glance this function appears to use ints so I figured certain variables could be modified to be chars and that would optimize the function a little bit but I fear the real optimization comes from using different function calls. The entire function is based on function calls so this would mean using different more efficient function calls to create a sprite?

Using chars as parameters only sorta works. The get pushed as ints anyway.
The real optimization actually comes from not using parameters to spr_make(). If you are using a constant in the call, move it into spr_make() and get rid of the parameter. Most of the values passed in are not going to change, so making them constants speeds things up....

If you really want to know, here's how I believe it works:
When you call spr_make(), all of the parameters get pushed onto the 'C' stack. That's not the same as the hardware stack - in fact it's pretty in-efficient if you look at the assembler code.
Then, in order to pass them along to the functions inside of spr_make(), they have to
   1) Be read from the 'C' stack - that code is slow as well
   2) Be pushed back onto the 'C' stack, so the functions can find them.

If you move the actual constants or global variable inside spr_make(), you avoid the overhead of pushing the arguements for the call, and the reading from the stack just to push them again. :)

Quote
I would like to have a top score displayed at the top of the screen. I noticed when my background scrolls so does my text!?
Yep. You need more than 1 scroll area: one for the unmoving text, and one for the moving part of the map. Luckily you can have up to 4 scroll areas.
BUT there's a catch: Everything goes in the BAT for display. So when you load your map, you have to make sure you leave the text area alone.

Quote
The more you think you kno the more you don't know.
We were all beginners at this once. Tackle one problem at a time. Before you know it, all this stuff will be if not easy, at least more understood :)



HyperFighting

  • Newbie
  • *
  • Posts: 7
Re: Mappy
« Reply #25 on: July 29, 2014, 06:08:17 PM »
Thanks sooo much! I will vanish into the shadows and get to work. As soon as I have some good news to report I will post it.

P.S. Playing Bonks Revenge tonight I was shocked and amazed at how many characters and backgrounds and items it has! There must be a secret to cramming gfx into the little card! I must be ahead of myself. Just saying that game really has alot going on! Bonk is a man of many animations! Long live Hu-cards! I love holding ten games in my hand just like a small stack of credit cards crazy!

Bonknuts

  • Hero Member
  • *****
  • Posts: 3292
Re: Mappy
« Reply #26 on: July 31, 2014, 03:50:39 AM »
Well, back to Mappy topic. I'm creating a few more things/options for the fmp2pce, and was wondering if there's anything you guys would use if I release this tool publicly (with source code).

 Maybe it's best if I show off some features first. FMP format is fine, but HuC doesn't take any advantage of it. Raw output is a better option IMO.

DarkKobold

  • Hero Member
  • *****
  • Posts: 1200
Re: Mappy
« Reply #27 on: April 02, 2016, 10:22:00 AM »
Oh, and on the spr_make thing... that is a convenience function I wrote for obeybrew.com that I sometimes use in my own prototyping. When I know things work, I remove the function calls and replace them with proper code. It's just a simplistic way of getting sprites onto the screen, but it creates a ton of overhead and is pretty inefficient so it's not intended to be used regularly.

I was searching how to do some image2pce loading, and I found this comment. I've been WAY over abusing spr_make, and its bloating the crap out of my code.

Could you suggest how to do this less bloated code?
Hey, you.

Gredler

  • Guest
Re: Mappy
« Reply #28 on: April 02, 2016, 01:01:39 PM »
I do, I like it. Wish tiles could be mirriored, and the importing of multiple tilemap images was easier.

Bonknuts

  • Hero Member
  • *****
  • Posts: 3292
Re: Mappy
« Reply #29 on: April 02, 2016, 02:19:56 PM »
I do, I like it. Wish tiles could be mirriored, and the importing of multiple tilemap images was easier.
How would you handle tile mirroring when it's not supported by the hardware? You'd have to "stream" rows and/or columns of tiles at a time for that kind of support. It's doable, and realtime flipping is fast with a simple small LUT, but the scroll engine itself becomes more complex; you're scrolling a bitmap image that happens to wrap at tilemap arbitrary defined boundaries.

 You can handle merging/importing sections or layers via an external app. The Mappy FMP format is pretty easy to work with.