Jump to content
Sign in to follow this  
jbs30000

Code optimization

Recommended Posts

I have re-started my Mario game using the DPC+ kernel. This time I'm off to a great start and the code to dim my variables is a lot neater, cleaner, and easier to read than before.

 

Because of the limited amount of variables I used DEF a lot, but ran into the 50 DEF limit. So I've come up with a new way to set values, but I'm curious if there's an even better way.

 

First, a sample of how I was doing it:

 

def Make_Mario_Small=a{0}=0

def Make_Mario_Large=a{0}=1

def Mario_is_Small=!a{0}

rem ********************

def Make_Mario_Normal=a{1}=0

def Make_Mario_FirePowered=a{1}=1

def Mario_is_Normal=!a{1}

 

So, to make Mario large, all I'd have to type is Make_Mario_Large. To check Mario's size all I'd have to type is if Mario_is_Small then x else y.

 

How I'm redoing it is like this:

 

macro Poke

{1}={1}&{2}|{3}

end

def Setup=callmacro Poke

rem ********************

rem * Mario variables. *

rem ********************

dim Mario=a

rem ********************

const _Size=%11111110

const _Small=0

const _Large=1

rem ********************

const _Power=%11111101

const _None=0

const _Fire=2

 

So here, to make Mario large I go Setup Mario _Size _Large. To see if he's large I go if Mario&!_Size=_Large then x.

 

So, this works, but is there an even better way to do this?

Share this post


Link to post
Share on other sites

Forgive me if this seems like trolling, but, you may be over-engineering this.

 

You might consider allocating a variable for Mario that is used exclusively for boolean values:

DIM mariostats = a

 

Each bit could represent a logical value such as:

mariostats{0} could be 0 if Mario is small and 1 if mario is large

 

So, if you hit a Goomba the logic would be concise:

if mariostats{0} then [do what you need to do to make him small]

 

You would still need to manually keep track of which bit represents what state but I bet the assembly output would be simpler..

Share this post


Link to post
Share on other sites

The way it will work is that Mario starts out with a{0}=0. When he gets a mushroom then a{0}=1. I want to express that in English so that the program is easy to read.

 

So far I'm just going with the consts since I read on Random Terrain's board that you can have 500 of them.

Share this post


Link to post
Share on other sites

OK, I settled on using single defs for each attribute.

 

def True=1

def False=0

 

def Mario_is_Large=a{0}

def Mario_has_FirePower=a{1}

 

My main goal is to have other people (as well as I) be able to look at the code, and with little to no REM statements easily know what's going on because there's going to be a lot of code and it could get confusing easily if it's not immediately clear what the code does. Mario_is_Large=False isn't the best way to say that Mario is small, but it works.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...