Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++ API: Round 2 - Sprite naming with creator input #52

Merged
merged 2 commits into from
Oct 29, 2021

Conversation

Fordi
Copy link
Contributor

@Fordi Fordi commented Oct 26, 2021

Using info from here: #23 (comment)

@Fordi Fordi marked this pull request as draft October 26, 2021 17:10
@Fordi Fordi changed the title Round 2: Naming with creator input Round 2: Sprite naming with creator input Oct 26, 2021
@Fordi Fordi marked this pull request as ready for review October 26, 2021 17:16
{LASERGUN1, "Laser Gun"},
{MACE1, "Mace"},
{DAGGER, "Dagger"},
{TRIDENT, "Trident"},
Copy link
Contributor Author

@Fordi Fordi Oct 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figure it's probably fine to leave the old name strings, to let people know their interpretation of sprites is perfectly valid.

@Fordi
Copy link
Contributor Author

Fordi commented Oct 26, 2021

@Gadgetoid what pattern should be used to get these into MicroPython? Something like what's done in voice.cpp?

Alternately, (non-automated) conversion of the C++ enum to a native python enum is pretty easy:

from enum import Enum

class Sprite(Enum):
    CHERRY = 0x00
    TOMATO = 0x01
    BANANA = 0x02
    ORANGE = 0x03
    EGGPLANT = 0x04
    CARROT = 0x05
    POTATO = 0x06
    SPINACH = 0x07
    GINGER = 0x08
    MEAT = 0x09
    BEANS = 0x0A
    TURNIP = 0x0B
    STRAWBERRY = 0x0C
    PUMPKIN = 0x0D
    CUCUMBER = 0x0E
    RICE_BOWL = 0x0F
    CLAW = 0x10
    SWORD_WOOD = 0x11
    SWORD_FROST = 0x12
    AXE = 0x13
    SAIS = 0x14
    MORNING_STAR = 0x15
    BOW_HUNTERS = 0x16
    ARROW = 0x17
    ARROW_FIRE = 0x18
    ARROW_ICE = 0x19
    TRIDENT = 0x1A
    SPEAR = 0x1B
    TRIDENT_FIRE = 0x1C
    MACHINEGUN = 0x1D
    PISTOL = 0x1E
    SHOTGUN = 0x1F
    ORB_GREEN = 0x20
    ORB_RED = 0x21
    ORB_YELLOW = 0x22
    ORB_BLUE = 0x23
    CANDY = 0x24
    RUBY_BLUE = 0x25
    BUTTON = 0x26
    OFFICIAL_LETTER = 0x27
    COIN_A = 0x28
    SKULL = 0x29
    UI_CHECK = 0x2A
    UI_CANCEL = 0x2B
    ARMOR_WOOD = 0x2C
    ARMOR_IRON = 0x2D
    ARMOR_GOLD = 0x2E
    ARMOR_DIAMOND = 0x2F
    CORN = 0x30
    BROCCOLI = 0x31
    COOKIE = 0x32
    RADISHES = 0x33
    MALLET_FROST = 0x34
    CAMPFIRE = 0x35
    SHOTGUN_AUTO = 0x36
    PISTOL_AUTO = 0x37
    BODY_PROTECTOR = 0x38
    HAT_WIZARD = 0x39
    HELMET_IRON = 0x3A
    HELMET_VIKING = 0x3B
    BOOTS_LEATHER = 0x3C
    BOOTS_IRON = 0x3D
    BOOTS_GOLD = 0x3E
    BOOTS_DIAMOND = 0x3F
    UI_HEART = 0x40
    SLIME_GREEN = 0x41
    COIN_B = 0x42
    SWORD_IRON = 0x43
    DAGGER_IRON = 0x44
    VEST_LEATHER = 0x45
    DYNAMITE = 0x46
    HEALTH_KIT = 0x47
    PILOT_GOGGLES = 0x48
    HAT_DEMON_KING = 0x49
    BOMB = 0x4A
    WATERING_CAN = 0x4B
    MASK_DEMON = 0x4C
    MASK_ELVEN = 0x4D
    SPEECH_BUBBLE_A = 0x4E
    SPEECH_BUBBLE_B = 0x4F
    UI_HEART_HALF = 0x50
    UI_HEART_EMPTY = 0x51
    UI_HEART_FROZEN = 0x52
    BUTTERFLY = 0x53
    TORCH = 0x54
    STONE_PIECE = 0x55
    PLAYING_CARD = 0x56
    DIE = 0x57
    HAT_HIGH_KNIGHT_DECORATED = 0x58
    HAT_HIGH_KNIGHT = 0x59
    UI_ARROW_UP = 0x5A
    RING_GOLDEN = 0x5B
    RING_DEMONS = 0x5C
    RING_FROST = 0x5D
    RING_NATURE = 0x5E
    POUCH_LITTLE = 0x5F
    COIN_SILVER = 0x60
    POTION_HEALTH = 0x61
    POTION_MAGIC = 0x62
    RING_DIAMOND = 0x63
    RING_EMERALD = 0x64
    BLOCK_STACK_WOOD = 0x65
    BLOCK_STACK_STONE = 0x66
    BLOCK_STACK_SAND = 0x67
    BLOCK_STACK_BIOLOGIC = 0x68
    BLOCK_STACK_LAVA = 0x69
    BLOCK_STACK_IRON = 0x6A
    BLOCK_STACK_ICE = 0x6B
    BLOCK_STACK_DARK = 0x6C
    BLOCK_STACK_GOLD = 0x6D
    SHIELD_KNIGHT = 0x6E
    POUCH_LARGE = 0x6F
    COIN_GOLDEN = 0x70
    POTION_HEALTH_EMPTY = 0x71
    POTION_MAGIC_EMPTY = 0x72
    WINGS = 0x73
    BONE = 0x74
    BLOCK_WOOD = 0x75
    BLOCK_STONE = 0x76
    BLOCK_SAND = 0x77
    BLOCK_BIOLOGIC = 0x78
    BLOCK_LAVA = 0x79
    BLOCK_IRON = 0x7A
    BLOCK_ICE = 0x7B
    BLOCK_DARK = 0x7C
    BLOCK_GOLD = 0x7D
    SHIELD_MIRROR = 0x7E
    SHIELD = 0x7F
    FLOWER_DANDELION = 0x80
    FLOWER_TULIP_RED = 0x81
    GRASS = 0x82
    FLOWER_TULIP_BLUE = 0x83
    WAND_FIRE = 0x84
    SPEAR_FROST = 0x85
    MACHETE = 0x86
    LOG = 0x87
    MINE = 0x88
    MORNING_STAR_LARGE = 0x89
    AXE_DOUBLE = 0x8A
    STONE_SMALL = 0x8B
    SWORD_SILVER = 0x8C
    SWORD_SILVER_GREAT = 0x8D
    SWORD_DIAMOND = 0x8E
    CROWN = 0x8F
    GOLD = 0x90
    DIAMOND = 0x91
    RUBY = 0x92
    EMERALD = 0x93
    AXE_DOUBLE_GOLD = 0x94
    POISON_MUSHROOM = 0x95
    ROPE = 0x96
    LOG_WITH_LEAF = 0x97
    POTION_SPEED_EMPTY = 0x98
    POTION_SPEED = 0x99
    EMERALD_CRYSTAL = 0x9A
    HAT_SEAMONSTER = 0x9B
    DAGGER_SILVER = 0x9C
    DAGGER_SILVER_RARE = 0x9D
    DAGGER_DIAMOND = 0x9E
    CROWN_KINGS = 0x9F
    APPLE = 0xA0
    LEAF_SMALL = 0xA1
    LEAF_ACORN = 0xA2
    LEAF_LARGE = 0xA3
    LEAF_LONG = 0xA4
    MUSHROOM = 0xA5
    WOOD = 0xA6
    UI_STAR = 0xA7
    BIRD = 0xA8
    GREEN_BALL = 0xA9
    KEY_IRON = 0xAA
    KEY_GOLD = 0xAB
    KEY_GOLD_WORM = 0xAC
    AMULET_FROST = 0xAD
    AMULET_FIRE = 0xAE
    AMULET_FOREST = 0xAF
    WORM = 0xB0
    LEAF_SMALL_EATEN = 0xB1
    LEAF_ACORN_EATEN = 0xB2
    LEAF_LARGE_EATEN = 0xB3
    LEAF_LONG_EATEN = 0xB4
    FLOWER_SMALL = 0xB5
    FLOWER_MEDIUM = 0xB6
    FLOWER_LARGE = 0xB7
    TOTEM_IRON_SMALL = 0xB8
    EYEBALL = 0xB9
    FISH = 0xBA
    BURGER = 0xBB
    UI_SUN = 0xBC
    NOTE = 0xBD
    WATER = 0xBE
    LADLE = 0xBF
    AVOCADO = 0xC0
    POTION_WHITE = 0xC1
    POTION_YELLOW = 0xC2
    POTION_GREEN = 0xC3
    POTION_RED = 0xC4
    CANDYCANE = 0xC5
    EGG_FRIED = 0xC6
    SICKLE_IRON = 0xC7
    GRAPPLING_HOOK = 0xC8
    CLIMBING_HOOK = 0xC9
    CHEESE_A = 0xCA
    CHEESE_B = 0xCB
    UI_SELECT = 0xCC
    UI_SETTING_SELECT = 0xCD
    SPELL_FIRE = 0xCE
    SPELL_FIRE_MISSILE = 0xCF
    MEDICAL_KIT = 0xD0
    RING_DEATH = 0xD1
    BLUEBERRIES = 0xD2
    FLOWER_PINK = 0xD3
    PAN = 0xD4
    COMPUTER = 0xD5
    HEADPHONES = 0xD6
    STONE_TABLET_EMPTY = 0xD7
    STONE_TABLET_WRITTEN_HALF = 0xD8
    STONE_TABLET_WRITTEN = 0xD9
    DEMON_RED = 0xDA
    BURNING_SPEAR = 0xDB
    UI_CURSOR = 0xDC
    SPELL_MANA = 0xDD
    SPELL_MANA_RAIN = 0xDE
    SPELL_MANA_MISSILE = 0xDF
    BOOK_LARGE = 0xE0
    CABBAGE = 0xE1
    CONTAINER = 0xE2
    FLOWER_ROSE = 0xE3
    UI_SPACER_A = 0xE4
    UI_SPACER_B = 0xE5
    GLASS = 0xE6
    UI_DECREASE = 0xE7
    UI_INCREASE = 0xE8
    EAGLE = 0xE9
    DEMON_GREEN = 0xEA
    DEMON_BLUE = 0xEB
    CORPSE = 0xEC
    UI_CURRENT = 0xED
    SPELL_EMERALD_SPLASH = 0xEE
    SPELL_EMERALD_THUNDER = 0xEF
    UI_CLOCK = 0xF0
    UI_ATTENTION = 0xF1
    BATTERY_CELL = 0xF2
    UI_QUESTION_MARK = 0xF3
    UI_DISABLED_A = 0xF4
    UI_DISABLED_B = 0xF5
    BOW = 0xF6
    START_MARKER = 0xF7
    SMALL_START_MARKER = 0xF8
    FLAG_A = 0xF9
    FLAG_B = 0xFA
    FLAG_C = 0xFB
    FLAG_D = 0xFC
    UI_ERROR = 0xFD
    SPELL_EXPLOSION = 0xFE
    SPELL_EXPLOSIVE_MISSILE = 0xFF

Not really sure how to make either "part" of the MicroPython build, though. Also, that's a lot of string to stick in the Pico's memory.

@Fordi Fordi changed the title Round 2: Sprite naming with creator input C++ API: Round 2 - Sprite naming with creator input Oct 26, 2021
@Gadgetoid
Copy link
Member

Everything in MicroPython is implemented as a builtin at the moment, which requires some pretty ugly hacks but dramatically increases performance. That happens here: https://github.com/pimoroni/micropython/blob/experimental/picosystem/ports/rp2/boards/PIMORONI_PICOSYSTEM/board_builtin.h

The enum is a redundant repetition, since it's all repeated at the bottom like so:

    { MP_ROM_QSTR(MP_QSTR_SALT2), MP_ROM_INT(SALT2) }, \
    { MP_ROM_QSTR(MP_QSTR_STICK2), MP_ROM_INT(STICK2) }, \
    { MP_ROM_QSTR(MP_QSTR_VIAL5), MP_ROM_INT(VIAL5) }, \
    { MP_ROM_QSTR(MP_QSTR_VIAL6), MP_ROM_INT(VIAL6) }, \
    { MP_ROM_QSTR(MP_QSTR_DOT), MP_ROM_INT(DOT) }, \

So the MP_ROM_INT() could just take the number directly.

I tend to run the C++ table through VSCode to try and rustle up the above format.

@Fordi
Copy link
Contributor Author

Fordi commented Oct 29, 2021

Are there further changes you want in this PR before merging?

@Gadgetoid
Copy link
Member

Looks good to me, I'm just now testing against a MicroPython build.

I'm preparing the next SDK release and want this change to be part of it!

@Gadgetoid Gadgetoid merged commit b109693 into pimoroni:main Oct 29, 2021
@Gadgetoid
Copy link
Member

Thanks for your hard work here! Appreciated!

@Fordi Fordi deleted the sprites-round-2 branch February 20, 2024 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants