• Re: Looking moremore optimizations!

    From Niklas Lindholm@2:201/420 to Harry Potter on Fri Oct 26 16:39:30 2018
    Please ignore the commented-out code. It's left-overs from
    debugging. :(

    The human brain is not a compiler that easily skips commented out lines. It will still see everything and having that much noise in the code makes it extremely hard to read. If you want to improve code you need to be able to read
    what's already there. And in this case you can't really.
    --- NiKom v2.5.0dev
    * Origin: NiKom BBS, http://www.nikom.org/nikombbs.html (2:201/420.0)
  • From Harry Potter@3:770/3 to All on Sat Oct 27 05:21:07 2018
    Let me try again:
    -------------------------
    void vLook (void)//char Itm1)
    {
    static void (*func)();
    if (Itm1!=0xFF) {
    if (SearchInvPlayer () || SearchInvRoom ())
    {
    if ((s=hidereadw((void*)&Item[Itm1].Info))==0) {
    printscr ("No help available for that item.");
    return;
    }
    printh (s);
    //printh ((void*)&Item[Itm1].Info);
    //else
    // ;
    //return;
    //}
    }
    else {
    //puts (Message[msgItemNotAvail]);
    printmsg(msgItemNotAvail);
    }
    return;
    }
    CurRoomInv=Player.RoomInv[CRoom];
    CRm=(void*)&Room[CRoom];
    printh ((char*)hidereadw((void*)&CRm->Desc));
    func=hidereadw((void*)&CRm->RoomHandler);
    (*func) ();
    printcr();

    for (i=0; i<8 && (c=CurRoomInv[i])!=0xFF;++i) {
    prints ("There is a ");
    printh (hidereadw((void*)&Item[/*CurRoomInv[i]*/c].Name));
    printscr (" here.");
    }
    if (i)
    printcr();
    }

    void vLook2 (void)
    {
    Itm1=-1;
    vLook ();

    }

    void vGo ()//char Itm1)
    {
    if (Itm1>=160 && Itm1<164) {
    j = Itm1&0x0F; //goto godir;
    if ((i=CRm->NextRoom[j])==0xFF) {
    printmsg(msgCantGoThere); return;
    }
    CRoom = i; goto exitgood;
    }
    switch (Itm1)
    {
    case iTeleporter:
    if (!SearchInvRoom()) {
    printscr ("There's no teleporter here.");
    return;
    }
    Player.ExitRoom = CRoom;
    CRoom = rTeleporter;
    goto exitgood;
    }
    printmsg(msgCantGoThere); return;
    godir:
    exitgood:
    Player.ExitRoom =-1; vLook2();
    }
    ------------------------------------
    void main (void)
    {
    //static unsigned char c;
    //static char Input [38];
    //static unsigned char Vrb;//, Itm, ItmNum, CurPos;
    //static unsigned char CurPos;//IncPos;
    //static unsigned char i;
    static void (* vfunc) ();
    //printf ("%X\n", &Item[0].Name);
    //cgetc();
    //bordercolor(8); bgcolor (1);
    //textcolor (4);
    brdrcol=8;
    backcol=1;
    //textcol=4;
    /*123456789012345678901234567890123456789*/
    //clrscr ();
    printscr("\f\n\x9cWelcome to \"Adventures on Planet Smir\n"
    "III, Episode 1, v .10\" for the Commo-\n"
    "dore 64 and emulators, created with cc65"
    "by Joseph Rose.\n\n"

    "Type INTRO during the game for\n"
    "instructions.\n\n"
    "Do you want to load a saved game?");
    switch (getkey ())
    {
    case 'd': ++c;
    case 'y': ++c;
    }
    InitPlayer ();
    if (c==2) {
    printscr ("Debug mode: Enter room #"); GetInput (Input, 4);
    for (CurPos=0;Input[CurPos]; ++CurPos)
    {
    CRoom=(((CRoom<<2)+CRoom)<<1)+(Input[CurPos]&0xF);
    }
    }
    vLook2 ();
    while (1)
    {
    DispScoreBoard();
    if (!GetInput (Input,38)) continue;
    Vrb = FindVerb (/*Input*/);
    if (Vrb == 0xFF) {
    prints ("I don't know how to ");
    prints (Input);
    printperiod ();
    continue;
    }
    while (Input[CurPos]==32) ++CurPos;
    if (Input[CurPos]) //Itm1=-1; goto runverb;}
    {
    if ((Itm1 = FindItem (&Input[CurPos]))==0xFF ) {
    prints ("I don't know what a ");
    prints (&Input[CurPos]);
    printscr (" is.");
    continue;
    }
    } else Itm1=0xFF;
    vfunc=hidereadw((void*)&Verb[Vrb].vdo);
    (*vfunc) ();
    }
    }
    -----------------------
    Does this help? :)

    BTW, if necesssary, I can supply some of the variables' purposes.
    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Niklas Lindholm@2:201/420 to Harry Potter on Sat Oct 27 08:19:25 2018
    So what is it that you want to optimize for? Speed? Memory footprint? IO?

    You usually optimize something becuase there is an issue identified that you want to improve.

    There's a famous quote by Donald Knuth:
    "The real problem is that programmers have spent far too much time worrying
    about efficiency in the wrong places and at the wrong times; premature
    optimization is the root of all evil (or at least most of it) in
    programming."
    --- NiKom v2.5.0dev
    * Origin: NiKom BBS, http://www.nikom.org/nikombbs.html (2:201/420.0)
  • From Harry Potter@3:770/3 to Niklas Lindholm on Sat Oct 27 09:41:55 2018
    On Saturday, October 27, 2018 at 12:12:02 PM UTC-4, Niklas Lindholm wrote:
    So what is it that you want to optimize for? Speed? Memory footprint? IO?

    Size.

    You usually optimize something becuase there is an issue identified that you want to improve.

    It is not currently necessary here. I just like optimizing. :)

    There's a famous quote by Donald Knuth:
    "The real problem is that programmers have spent far too much time worrying
    about efficiency in the wrong places and at the wrong times; premature
    optimization is the root of all evil (or at least most of it) in
    programming."

    That's true. Again, I just like optimizing. :)
    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Harry Potter@3:770/3 to All on Sat Nov 3 13:22:36 2018
    Well...the text adventure *is* going to be pretty large, so I have an excuse to
    optimize early. What do you think? :)
    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Janne Johansson@2:221/6 to Harry Potter on Sun Nov 4 00:35:02 2018
    On 2018-11-03 12:22, Harry Potter : All wrote:
    What do you think?  :)

    Someone said "we have two ears and one mouth so that we may listen twice
    the mount that we speak".

    Did you take into account what people already replied to you?

    If you didn't, would it be worth for others to keep feeding advice?
    ---
    * Origin: - nntp://news.fidonet.fi - Lake Ylo - Finland - (2:221/6.0)
  • From Harry Potter@3:770/3 to Janne Johansson on Sun Nov 4 00:02:11 2018
    On Saturday, November 3, 2018 at 6:44:06 PM UTC-4, Janne Johansson wrote:
    Did you take into account what people already replied to you?

    Uhh...can somebody please re-post the advice. :( Years ago, I got some advice
    on optimizing and applied it, but IIRC, nothing on my text adventure.

    If you didn't, would it be worth for others to keep feeding advice?

    Admittedly, no. :(
    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Janne Johansson@2:221/6 to Harry Potter on Sun Nov 4 12:08:52 2018
    On 2018-11-03 23:02, Harry Potter : Janne Johansson wrote:
    On Saturday, November 3, 2018 at 6:44:06 PM UTC-4, Janne Johansson wrote:
    Did you take into account what people already replied to you?

    Uhh...can somebody please re-post the advice.  :(  Years ago, I got some advice on optimizing and applied it, but IIRC, nothing on my text
    adventure.

    If you didn't, would it be worth for others to keep feeding advice?

    Admittedly, no.  :(

    Both me and Niklas Lindholm replied to you this week on how showing code intermixed with 50+% commented-out lines makes it super hard for humans
    to see whats left, especially (at least in my case) if those lines
    contain a lot of " // else { " flow control since my brain is very much
    adapted to recognizing changes in control flow when trying to divinate
    what a program does.

    I'll jut leave you with: "rethink the algorithms, wait with instruction optimization until the very last". There is basically no use in looking
    for the best asm opcodes if you are bubblesorting 1000s of random
    entries using O(n^2) steps to do it, as opposed to using a better sort
    even if uses poor or expensive instructions to solve itself.

    Also, look up the term "Askhole" while pondering how come you get so few
    decent responses long-term. Like when it took some 10 weeks for you to
    find anything on LZ77 optimal parser after getting that exact hint on comp.compression. When I type "lz77 optim" google fills in the rest and
    there just pops out tons of pages on that very subject.

    I have absolutely no idea on how you are, what kind of person or
    anything but your actions clearly makes it appear as if you are throwing
    out a lot of "can you please make an effort for me?" and then just
    moving on not caring if people did small or large amounts of work for
    your sake.

    I don't think that pays off in the long run.
    ---
    * Origin: - nntp://news.fidonet.fi - Lake Ylo - Finland - (2:221/6.0)
  • From Pekka Takala@3:770/3 to Herr Doktor on Sat Nov 10 19:10:16 2018
    On 08.11.2018 20:04, Herr Doktor wrote:
    I realize I'm jumping into the middle of a conversation and it isn't
    my intention to derail it. What jumps out at me from your code is the
    lack of comments. It's been years since I did any programming but
    when I did I always commented extensively. I also use many small
    modules rather than one huge source file. Then the main program
    becomes just the flow of logic and decision with calls to the
    appropriate modules as required.

    I find that writing in this way makes things much easier all the way
    around, all aspects.

    Also, creating the game as modules helps you if you exceed the usable
    memory. You can then split things if they do not depend on each other
    and load them from disk/tape/cartridge when needed. If the code is in
    one big snippet, the splitting is WAY more difficult to do if needed.

    Commenting is important- what does what. The comments DO NOT take any
    space after compiling, the compiler just skips them completely. It helps
    you to read the code afterwards and makes guessing less needed. And
    also, if you make the code as modules, you can support various hardware
    easier since you can load various pieces to memory depending on hardware.

    And, when you have tasks those are common, in their own files, you
    lessen the trouble of getting hard-to-repair bugs. You can parametrise
    the functions so that you can use same code to little various tasks,
    still being similar. For example, you can read keyboard with its own
    function. If parametrised, you can restrict the keys needed to read, so
    you do not need to check them in later code since the keyboard code does
    that for you already. This method makes the code less prone to exploits, although on commodore platform the exploit avoiding is not so important
    than on platforms those are connectable to Internet. Still practicing
    this makes you better coder on other platforms also.

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Harry Potter@3:770/3 to Pekka Takala on Sat Nov 10 11:29:45 2018
    On Saturday, November 10, 2018 at 12:10:24 PM UTC-5, Pekka Takala wrote:
    Also, creating the game as modules helps you if you exceed the usable
    memory. You can then split things if they do not depend on each other
    and load them from disk/tape/cartridge when needed. If the code is in
    one big snippet, the splitting is WAY more difficult to do if needed.

    Well, the game currently *is* modularized. In fact, the executable is currently split into multiple parts, but, currently, all parts are loaded in at
    once. The main executable loads first, then two stubs loaded into the first k,
    then some strings and
    misc. data behind the I/O and kernal ROM to be accessed using my cc65 Hidden64 library.

    Commenting is important- what does what. The comments DO NOT take any
    space after compiling, the compiler just skips them completely. It helps
    you to read the code afterwards and makes guessing less needed. And
    also, if you make the code as modules, you can support various hardware easier since you can load various pieces to memory depending on hardware.

    I used to comment extravagantly but recently stopped. I don't know why. :(

    And, when you have tasks those are common, in their own files, you
    lessen the trouble of getting hard-to-repair bugs. You can parametrise
    the functions so that you can use same code to little various tasks,
    still being similar. For example, you can read keyboard with its own function. If parametrised, you can restrict the keys needed to read, so
    you do not need to check them in later code since the keyboard code does
    that for you already. This method makes the code less prone to exploits, although on commodore platform the exploit avoiding is not so important
    than on platforms those are connectable to Internet. Still practicing
    this makes you better coder on other platforms also.

    Well, I have my own input routine called AltInput for cc65. It is a front-end to my CBMSimpleIO library. Both are at https://sourceforge.net/projects/cc65extra/files/ui/.

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Herr Doktor@3:770/3 to rose.joseph12@yahoo.com on Thu Nov 8 13:04:56 2018
    I realize I'm jumping into the middle of a conversation and it isn't
    my intention to derail it. What jumps out at me from your code is the
    lack of comments. It's been years since I did any programming but
    when I did I always commented extensively. I also use many small
    modules rather than one huge source file. Then the main program
    becomes just the flow of logic and decision with calls to the
    appropriate modules as required.

    I find that writing in this way makes things much easier all the way
    around, all aspects.

    You say your program is going to be a big one. They can become
    unwieldy pretty fast when good organizing techniques are not used.
    On Sat, 27 Oct 2018 05:21:07 -0700 (PDT), Harry Potter <rose.joseph12@yahoo.com> wrote:

    Let me try again:
    -------------------------
    void vLook (void)//char Itm1)
    {
    static void (*func)();
    if (Itm1!=0xFF) {
    if (SearchInvPlayer () || SearchInvRoom ())
    {
    if ((s=hidereadw((void*)&Item[Itm1].Info))==0) {
    printscr ("No help available for that item.");
    return;
    }
    printh (s);
    //printh ((void*)&Item[Itm1].Info);
    //else
    // ;
    //return;
    //}
    }
    else {
    //puts (Message[msgItemNotAvail]);
    printmsg(msgItemNotAvail);
    }
    return;
    }
    CurRoomInv=Player.RoomInv[CRoom];
    CRm=(void*)&Room[CRoom];
    printh ((char*)hidereadw((void*)&CRm->Desc));
    func=hidereadw((void*)&CRm->RoomHandler);
    (*func) ();
    printcr();

    for (i=0; i<8 && (c=CurRoomInv[i])!=0xFF;++i) {
    prints ("There is a ");
    printh (hidereadw((void*)&Item[/*CurRoomInv[i]*/c].Name));
    printscr (" here.");
    }
    if (i)
    printcr();
    }

    void vLook2 (void)
    {
    Itm1=-1;
    vLook ();

    }

    void vGo ()//char Itm1)
    {
    if (Itm1>=160 && Itm1<164) {
    j = Itm1&0x0F; //goto godir;
    if ((i=CRm->NextRoom[j])==0xFF) {
    printmsg(msgCantGoThere); return;
    }
    CRoom = i; goto exitgood;
    }
    switch (Itm1)
    {
    case iTeleporter:
    if (!SearchInvRoom()) {
    printscr ("There's no teleporter here.");
    return;
    }
    Player.ExitRoom = CRoom;
    CRoom = rTeleporter;
    goto exitgood;
    }
    printmsg(msgCantGoThere); return;
    godir:
    exitgood:
    Player.ExitRoom =-1; vLook2();
    }
    ------------------------------------
    void main (void)
    {
    //static unsigned char c;
    //static char Input [38];
    //static unsigned char Vrb;//, Itm, ItmNum, CurPos;
    //static unsigned char CurPos;//IncPos;
    //static unsigned char i;
    static void (* vfunc) ();
    //printf ("%X\n", &Item[0].Name);
    //cgetc();
    //bordercolor(8); bgcolor (1);
    //textcolor (4);
    brdrcol=8;
    backcol=1;
    //textcol=4;
    /*123456789012345678901234567890123456789*/
    //clrscr ();
    printscr("\f\n\x9cWelcome to \"Adventures on Planet Smir\n"
    "III, Episode 1, v .10\" for the Commo-\n"
    "dore 64 and emulators, created with cc65"
    "by Joseph Rose.\n\n"

    "Type INTRO during the game for\n"
    "instructions.\n\n"
    "Do you want to load a saved game?");
    switch (getkey ())
    {
    case 'd': ++c;
    case 'y': ++c;
    }
    InitPlayer ();
    if (c==2) {
    printscr ("Debug mode: Enter room #"); GetInput (Input, 4);
    for (CurPos=0;Input[CurPos]; ++CurPos)
    {
    CRoom=(((CRoom<<2)+CRoom)<<1)+(Input[CurPos]&0xF);
    }
    }
    vLook2 ();
    while (1)
    {
    DispScoreBoard();
    if (!GetInput (Input,38)) continue;
    Vrb = FindVerb (/*Input*/);
    if (Vrb == 0xFF) {
    prints ("I don't know how to ");
    prints (Input);
    printperiod ();
    continue;
    }
    while (Input[CurPos]==32) ++CurPos;
    if (Input[CurPos]) //Itm1=-1; goto runverb;}
    {
    if ((Itm1 = FindItem (&Input[CurPos]))==0xFF ) {
    prints ("I don't know what a ");
    prints (&Input[CurPos]);
    printscr (" is.");
    continue;
    }
    } else Itm1=0xFF;
    vfunc=hidereadw((void*)&Verb[Vrb].vdo);
    (*vfunc) ();
    }
    }
    -----------------------
    Does this help? :)

    BTW, if necesssary, I can supply some of the variables' purposes.

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)