chocomap.lua (v1.2) - better overworld, now with undocumented memory access

Share and discuss custom LunaLua code and content packs for SMBX2.
User avatar
deice
Dolphin
Dolphin
Posts: 85
Joined: Fri Jul 23, 2021 7:35 am

chocomap.lua (v1.2) - better overworld, now with undocumented memory access

Postby deice » Sat Oct 30, 2021 11:11 am

a short while ago, i was hit with the harrowing and tragic news (to me) that render priority doesn't apply to the world map.

since i need this feature for an episode i am creating, i made a library that redraws the vanilla overworld using lua. then i figured that this might be useful to other people as well, so i'm publishing it right now.

changelogs
1.2
Spoiler: show
- scenery which has been cleared out by paths is no longer drawn
- switch palaces can now be animated (see below)
- the "cheater" pause menu without save options now looks exactly like in vanilla
1.1
Spoiler: show
- now displays the vanilla pause menu and items still animate while the game is paused
- now supports costumes
- tiles with different sizes/animations now display correctly by default
- peach and toad now display correctly

features
animate and resize the everything
Spoiler: show
Image
  • you can use txt files for overworld elements (tiles, levels, paths, scenery) to customize the image width and height, as well as the number of frames, the framespeed and the render priority (more on that later), the parameter names are:

    Code: Select all

    width
    height
    frames
    framespeed
    priority
    pframes (SWITCH PALACE ONLY)
    
    (pframes indicates the amount of animation frames that a switch palace has while it's in pressed state, whereas for switch palaces "frames" indicates the frame count while not pressed. returns nil for levels that aren't switch palaces)
  • things like image height aren't inferred from frame count and image size, so please be concrete (also, the actual in-game size of the elements does not change, and using strange and unconventional image sizes might have unexpected or adverse effects for certain elements)
  • these files are to be placed in your episode folder
  • special thanks to whoever had the foresight to implement this functionality into the editor ahead of time, as it previews all of the animations correctly
draw whatever, wherever
Spoiler: show
Image
  • overworld elements now have strictly defined render priorities. this not only allows you to make specific overworld elements draw in front of or behind other ones where this would normally be impossible, but also allows use of Graphics.draw() on the overworld to make drawing things like large background textures possible.
  • levels, paths, scenery and tiles have configurable default priorities (you can change them at the start of the file, but not while the game is running)
  • according to the documentation, drawing with negative priorities on the world map is discouraged to maintain compatibility, so you are limited to the priority space between 0 and 10 (you can technically go below, but nothing will display)
dynamically reconfigure
Spoiler: show
Image
(this specific example requires some additional lua to work)
  • chocoMap comes with the following tables:

    Code: Select all

    tiles
    scenery
    paths
    levels
    
    these are indexed by id (except for level id 0, which is accessed via "levels.LEVEL0" instead) which contain the current images and configuration tables for each type of overworld element. all of it can be changed during play:

    Code: Select all

    chocoMap.levels[1].texture = Graphics.loadImage("mylevel.png") -- change the sprite of every level with the ID 1
    chocoMap.tiles[1].config.frames = 3 -- make every instance of tile 1 animated
    
  • you also have direct access to the frame data of (almost) every type of overworld element, using the sub-table "frameTable" that each of the tables above has. once again, it's indexed by id (save for level 0 which is "levels.frameTable.LEVEL0"):

    Code: Select all

    -- if this is run every tick, then instances of path 1 will not animate whenever "dontAnimateThis" is set to true
    if(dontAnimateThis) then
    	chocoMap.paths.frameTable[1] = 0
    end
    
  • the rendering priority of the player and HUD (chocoMap.PLAYER_PRIORITY and chocoMap.HUD_PRIORITY respectively) can be modified during play at any point, which makes it possible for the player to appear to move behind certain tiles as showcased in the preview
  • retains compatibility with activateOverworldHud and switchpalace.lua
limit camera movement
as seen in all the gifs above, the camera doesn't move. you can define regions which the camera will lock itself to if the player is within said region using:

Code: Select all

chocoMap.addCameraBoundary(x, y, width, height) -- width and height will be discarded if they are below the respective SMBX screen dimensions (800x600)
this function returns the index of said camera boundary within the array chocoMap.cameraBoundaries, and it's location and size can be modified during play (though this might look janky if you do it while the player is already inside it). this function is useful for creating SMW-styled submaps.

other
  • WHUD_NONE now stops the animated player from appearing in the corner. this is a side effect of drawVanillaOverworldHUD() and not an intentional feature of the library, but some might find it useful nonetheless.
  • most if not all of these features will probably make it into smbx2 eventually, and when that happens you can consider this library obsolete. however, intuitively, it should not cause issues with potential future episodes (as even if it would, future versions of smbx would most likely have the option to toggle the old version of the overworld renderer to maintain backwards compatibility)
  • while it hasn't been extensively stress-tested, since it only draws things when they're on the screen, slowdowns shouldn't really be able to happen for the most part. the only benchmark so far is:
    - 4.3k tiles
    - 3.6k scenery
    - 1k paths
    - 100 levels (each with both background types)
    with no noticeable slowdown or stuttering.
download
the hard hits, they never stop

reply with feedback and bug reports, please and thank you
Last edited by deice on Tue Nov 02, 2021 7:49 am, edited 6 times in total.

User avatar
KBM-Quine
Dolphin
Dolphin
Posts: 89
Joined: Wed Jan 15, 2014 11:10 am
Flair: Crazy with a K

Re: chocomap.lua - everybody's lua-drawn now

Postby KBM-Quine » Mon Nov 01, 2021 4:23 pm

as someone who's tinkered with 1.3 maps quite a bit, i like this! but chucking this in Ti2 without any other lua running yields this:
Image
as well as that, this renders over the vanilla pause menu. it also doesn't animate things when paused. that can be overcome by updating frames in onDraw.

as for your costume bugs, Graphics.sprites.player[player.character].img can be used in place of Graphics.loadImage(Misc.resolveGraphicsFile("player-"..tostring(player.character)..".png")). though you will need to update that to account for character/costume changes. you can do this in onDraw for that:

Code: Select all

-- make playerSprite just " local playerSprite" at the top then do this in onDraw
if not (playerSprite == Graphics.sprites.player[player.character].img) then
	playerSprite = Graphics.sprites.player[player.character].img
end
as for peach and toads' overworld rendering issues, you can find how that's handled in source here for an idea of how to handle that (if you can understand it anyhow)

on the switches, 0x00B2BFD8 is the animation array for 1.3 levels (gotten from map3d.lua in data/scripts). which makes sense, given that the level gets a "pressed" frame after you've beaten it.

all in all, i like where this is going. keep up the good work!
after some consideration, i've decided against allowing use of my assets to Novaverse/Stargate based levels and projects. anything accredited to me or my aliases is off-limits to those as such. - KBM-Quine
aliases: krazybluemonkey, Quine, KBM-Quine

Image
Image
Image
Image

User avatar
deice
Dolphin
Dolphin
Posts: 85
Joined: Fri Jul 23, 2021 7:35 am

Re: chocomap.lua (v1.1) - now with more QA

Postby deice » Mon Nov 01, 2021 7:01 pm

KBM-Quine wrote:
Mon Nov 01, 2021 4:23 pm
(bug reports)
all in all, i like where this is going. keep up the good work!
thank you very much for the feedback! i've addressed and (hopefully) completely fixed all of the issues you've pointed out in your post.
for anyone else reading, the script has been updated and a brief changelog is now visible in the top post, please redownload.

User avatar
deice
Dolphin
Dolphin
Posts: 85
Joined: Fri Jul 23, 2021 7:35 am

Re: chocomap.lua (v1.2) - better overworld, now with undocumented memory access

Postby deice » Tue Nov 02, 2021 7:50 am

apologies for the self bump, but i've updated the script once again with the features i couldn't get around to earlier. i suggest once again redownloading (but don't worry about constant updates anymore as this is the current definitive version unless new bugs are found)

User avatar
Hatsune Blake
Posts: 524
Joined: Sun Feb 23, 2014 1:55 pm
Pronouns: He / Him

Re: chocomap.lua (v1.2) - better overworld, now with undocumented memory access

Postby Hatsune Blake » Fri Nov 12, 2021 4:22 pm

This is really amazing. Fantastic work making the basegame overworld better!
Upcoming project...
Image

Check out my custom asset packs!
Hatsune Blake Asset Packs: show
Image
Image
Please check out my levels!
Hatsune Blakes Levels: show
Image
The logo above was made by FyreNova.

User avatar
FutureNyanCat2014
Volcano Lotus
Volcano Lotus
Posts: 527
Joined: Fri Dec 20, 2013 8:39 pm
Flair: The robotic kitty aka. Jaden1291 the Toad / Hex!
Pronouns: He/Him
Contact:

Re: chocomap.lua (v1.2) - better overworld, now with undocumented memory access

Postby FutureNyanCat2014 » Wed Nov 17, 2021 10:04 am

Honestly? I feel this deserves to be in SMBX2's full release. It gives players who prefer making vanilla overworld maps even more control over what they can do, especially for animated scenery, paths, and tiles. Nice work.
Image
Image Image Image Image Image Image
Image
Image
"F*ck you Einstein! Let's make a level with water + lava!" ~FutureNyanCat2014, 05/05/14
FutureNyanCat: Big Fan of Valtteri Since 2021

Other Stuff
Discord: Hexelectron#9736
Super Cat Wars Discord Server: https://discord.gg/esC6dH2

User avatar
deice
Dolphin
Dolphin
Posts: 85
Joined: Fri Jul 23, 2021 7:35 am

Re: chocomap.lua (v1.2) - better overworld, now with undocumented memory access

Postby deice » Wed Nov 17, 2021 12:16 pm

Hatsune Blake wrote:
Fri Nov 12, 2021 4:22 pm
This is really amazing. Fantastic work making the basegame overworld better!
FutureNyanCat2014 wrote: It gives players who prefer making vanilla overworld maps even more control over what they can do, especially for animated scenery, paths, and tiles. Nice work.
thanks for the compliments fellas, means a lot. i didn't think many people would care much for this with somewhat more robust map replacements like map3d or smwmap around ^^"
FutureNyanCat2014 wrote: Honestly? I feel this deserves to be in SMBX2's full release.
yea as i said i count on most of this being implemented into smbx2 when the staff starts to put more focus towards the overworld (as right now the documentation is a bit lacking for some overworld elements, and others aren't even named properly in the lunalua source) though i'm sure that whatever they come up with will be much faster performance-wise as it'll probably involve directly messing with the game's routines as opposed to chocomap which just draws a massive black rectangle over the player's viewport


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 1 guest