Pages: 1
  Print  
Author Topic: Inheritance  (Read 845 times)
Offline (Male) Goombert
Posted on: April 24, 2014, 03:46:45 AM

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 3110

View Profile
* This post is for Josh, stay the fag out of it.

I have a couple of questions I need you to answer, I wrote everything the way you told me to, but there are a couple of things you did not consider. Please answer these questions so that I may continue working tomorrow and have most of it done by the time you get home.

1) How do I rewrite events.res?
Code: (YAML) [Select]
alarm: 2
        Group
: Alarm
        Name
: Alarm %1
        Mode
: Stacked
        Sub Check
: {alarm[%1] = (int)alarm[%1]; if ((alarm[%1] == -1) or (alarm[%1]--)) return 0; }
I rewrote that subcheck to look like this.
Code: (YAML) [Select]
Sub Check: { alarm[%1] = (int)alarm[%1]; return !((alarm[%1] == -1) or (alarm[%1]--)); }Also how should the following be rewritten.
Code: (YAML) [Select]
keypress: 9
        Group
: Key Press
        Name
: Press <%1>
        Type
: Key
        Mode
: Stacked
        Super Check
: keyboard_check_pressed(%1)

2) I had to make the non-stackable event base sub check methods virtual for event_parent since that is what the iterator is cast to in ENIGMA_events.
Code: (C++) [Select]
   for (instance_event_iterator = event_nomorehealth->next; instance_event_iterator != NULL; instance_event_iterator = instance_event_iterator->next) {
    if (((enigma::event_parent*)(instance_event_iterator->inst))->myevent_nomorehealth_subcheck()) {
      ((enigma::event_parent*)(instance_event_iterator->inst))->myevent_nomorehealth();
    }
      if (enigma::room_switching_id != -1) goto after_events;
    }
   
    enigma::update_globals();
This is what the virtual subchecks look like in event_parent, and yes I know inline virtuals are redundant, see the next question.
Code: (C++) [Select]
inline virtual bool myevent_draw_subcheck() { return false; }Also, why do we bother duplicating the subcheck code for every instance when it has to go through this many steps? Why not just write all the subcheck code that's needed for every instance to event_parent?

3) I had to write the grouped event bases like event_perform for now, are you alright with this?
Code: (C++) [Select]
// Grouped event bases
      void myevent_alarm()
      {
          if (myevent_alarm_0_subcheck()) {
            myevent_alarm_0();
          }
          if (myevent_alarm_1_subcheck()) {
            myevent_alarm_1();
          }
      }
« Last Edit: May 19, 2014, 05:11:56 PM by Robert B Colton » Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Offline (Male) Josh @ Dreamland
Reply #1 Posted on: April 25, 2014, 07:59:38 PM

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2958

View Profile Email
To summarize our previous discussion for public record,
  • What you have is basically correct, but remember that checks which don't begin with {} are expressions and not code, and can just be inlined by the compiler. Super-checks are global and do not need rewritten.
  • Stacked events cannot call their parent's event dispatch method unless you guarantee that the child does not call any of the same events. You're better off just writing all the parent's event calls in with the child's, in those methods.
  • The big chain of ifs this case is fine. It's big if-else ladders we want to avoid, where the truth of any one implies the falsity of the others. These ifs are all independent and cannot be avoided. You should consider, though, that the code for myevent_alarm_0_subcheck and myevent_alarm_1_subcheck differs by very little, if not none at all, and can probably be consolidated into one method. This falls apart if the event does something screwy like construct variable names from the digit, which can frequently (but not always) be replaced with an array.
Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Pages: 1
  Print