Jump to content



0

Code optimization


3 replies to this topic

#1 jbs30000 OFFLINE  

jbs30000

    Moonsweeper

  • 459 posts

Posted Mon Oct 24, 2011 12:41 PM

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?

#2 theloon OFFLINE  

theloon

    Stargunner

  • 1,015 posts

Posted Tue Oct 25, 2011 8:11 AM

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..

#3 jbs30000 OFFLINE  

jbs30000

    Moonsweeper

  • 459 posts

Posted Tue Oct 25, 2011 11:31 AM

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.

#4 jbs30000 OFFLINE  

jbs30000

    Moonsweeper

  • 459 posts

Posted Tue Oct 25, 2011 11:06 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users