Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Man, I don't want this to turn into "MMG's help with coding corner" but I have an odd issue that just doesn't make sense to me from a coding standpoint.
I'm currently working on my vertical slice demo, where you interact with the priest, so everything is priest.c, priest2.c, etc, you get the idea.

In priest.c I play a bit of an intro animation and then some lip flaps:
priest.c:

int priestStart(void) {
...
install_int(priestIntro, 9999);     
install_int(priestTalk, 9999);
/*character intro sequence*/     
play_midi(priestData[PRIESTMID].dat, 0);     
while (priest_x > 250)     
{                 
        while (priest_y < 100)         
        {             
            clear_to_color(priestBuffer, makecol(0,0,0));             
            blit(priestData[CHURCH].dat, priestBuffer, 0, 0, 5, 5, 630, 280);                              
            priestIntro();             
            ...                         
            blit(priestBuffer, screen, 0, 0, 0, 0, priestBuffer->w, priestBuffer->h);              
            clear_bitmap(priestBuffer);         
        }     
}
remove_int(priestIntro);         
//do the talking     
while (priestAnim < 20)     
{         
    clear_to_color(priestBuffer, makecol(0,0,0));                 
    blit(priestData[CHURCH].dat, priestBuffer, 0, 0, 5, 5, 630, 280);             
    textprintf_ex(priestBuffer, font, 0, 80, makecol(255, 255, 0), -1, "PRIESTANIM %d", priestAnim);                  
    textout_ex(priestBuffer, npcFont, priestSays, 30, 290, makecol(83, 255, 93), -1);                 
    priestTalk();                  
    blit(priestBuffer, screen, 0, 0, 0, 0, priestBuffer->w, priestBuffer->h);                 
    clear_bitmap(priestBuffer);     
}         
remove_int(priestTalk);
...
}
void priestTalk() {          
rest(99);     
//play some animation here     
if (priestAnim % 2)     
    {         
        blit(priestData[PRIESTCHAR2].dat, priestBuffer, 0, 0, priest_x, priest_y, 100, 150);     
    } else     {         
        blit(priestData[PRIESTCHAR].dat, priestBuffer, 0, 0, priest_x, priest_y, 100, 150);         
    }     
    ++priestAnim; 
}

I have the rest(99) and timer(9999) in there so the animation doesn't fly by in a fraction of a second. What's weird though is that I tried to recreate the same behaviour once you proceed to priest2 but it hangs on the rest command (if it's not set to 0):

priest2.c:

int priestPhaseTwo(int selection) {
...
install_int(priest2Talk, 10);
priest2Anim = 0;
...
while (priest2Anim < 20)     
{         
    clear_to_color(priestBuffer, makecol(0,0,0));                 
    blit(priestData[CHURCH].dat, priestBuffer, 0, 0, 5, 5, 630, 280);             
    textout_ex(priestBuffer, npcFont, priestSays, 30, 290, makecol(83, 255, 93), -1);                 
    priest2Talk();                  
    blit(priestBuffer, screen, 0, 0, 0, 0, priestBuffer->w, priestBuffer->h);                 
    clear_bitmap(priestBuffer);     
}
remove_int(priest2Talk);
...
}
void priest2Talk() {     
//play some animation here
rest(99);
if (priest2Anim % 2)     
    {         
        blit(priestData[PRIESTCHAR2].dat, priestBuffer, 0, 0, priest_x, priest_y, 100, 150);     
    } else     {         
        blit(priestData[PRIESTCHAR].dat, priestBuffer, 0, 0, priest_x, priest_y, 100, 150);         
    }     
    ++priest2Anim;      
}

It's weird, as I'm not getting any SIGSEGV faults, it's just if it's set to rest(0) it works (and the animation plays before a human eye can see it) or if rest is set to anything other than 0 it hangs.

Is there some form of memory cleanup or processing I'm missing here? I admit this part of my coding skill is pretty threadbare, didn't have to worry about wait times and sleeps when coding websites in C#.

I found the solution by asking about it here - the install_int for file 1 was set to 9999 milliseconds while install_int in priest2 was set to 10. For whatever reason setting that to 9998 and the rest to 98 fixed it.

Ignore me!

(2 edits)

You're doing pretty heavy work (blit()) inside the interrupt handlers - not sure what specs you're targeting but I could see this causing issues on lower-end machines, or alongside other interrupt-heavy tasks such as audio. No need to change it if it's working for you, but if stuff starts to behave weirdly (graphics glitches, audio stutters etc) that will definitely be a possible culprit.

Thanks! I'll keep an eye on it as best I can :)

A common approach for this kind of thing is to install an interrupt that just increments a volatile timekeeping variable at a certain rate. Your main program can then just check that variable in a loop to see if enough time has passed, then do any updates or blitting you need. This way you also don't need to keep installing new interrupt handlers and can just keep all the animation logic as part of the normal program flow.

So that would prevent me hitting clashes like this? Cool, I'll give it a go.