Changed autofire algorithm to not require using a static array. Now just does an on/off frame calculation based on where it is in the overall duty cycle of the square wave.
This commit is contained in:
parent
092fc97078
commit
596c27ea5e
76
src/fceu.cpp
76
src/fceu.cpp
|
@ -644,42 +644,72 @@ void FCEUI_Kill(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int rapidAlternator = 0;
|
int rapidAlternator = 0;
|
||||||
int AutoFirePattern[8] = { 1, 0, 0, 0, 0, 0, 0, 0 };
|
//int AutoFirePattern[8] = { 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||||
int AutoFirePatternLength = 2;
|
int AutoFirePatternLength = 2;
|
||||||
|
|
||||||
void SetAutoFirePattern(int onframes, int offframes) {
|
void SetAutoFirePattern(int onframes, int offframes)
|
||||||
int i;
|
{
|
||||||
for (i = 0; i < onframes && i < 8; i++) {
|
//int i;
|
||||||
AutoFirePattern[i] = 1;
|
//for (i = 0; i < onframes && i < 8; i++) {
|
||||||
}
|
// AutoFirePattern[i] = 1;
|
||||||
for (; i < 8; i++) {
|
//}
|
||||||
AutoFirePattern[i] = 0;
|
//for (; i < 8; i++) {
|
||||||
}
|
// AutoFirePattern[i] = 0;
|
||||||
if (onframes + offframes < 2) {
|
//}
|
||||||
AutoFirePatternLength = 2;
|
//if (onframes + offframes < 2) {
|
||||||
} else if (onframes + offframes > 8) {
|
// AutoFirePatternLength = 2;
|
||||||
AutoFirePatternLength = 8;
|
//} else if (onframes + offframes > 8) {
|
||||||
} else {
|
// AutoFirePatternLength = 8;
|
||||||
AutoFirePatternLength = onframes + offframes;
|
//} else {
|
||||||
}
|
// AutoFirePatternLength = onframes + offframes;
|
||||||
|
//}
|
||||||
|
AutoFirePatternLength = onframes + offframes;
|
||||||
AFon = onframes; AFoff = offframes;
|
AFon = onframes; AFoff = offframes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetAutoFireOffset(int offset) {
|
void GetAutoFirePattern( int *onframes, int *offframes)
|
||||||
|
{
|
||||||
|
if ( onframes )
|
||||||
|
{
|
||||||
|
*onframes = AFon;
|
||||||
|
}
|
||||||
|
if ( offframes )
|
||||||
|
{
|
||||||
|
*offframes = AFoff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetAutoFireOffset(int offset)
|
||||||
|
{
|
||||||
if (offset < 0 || offset > 8) return;
|
if (offset < 0 || offset > 8) return;
|
||||||
AutoFireOffset = offset;
|
AutoFireOffset = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoFire(void) {
|
bool GetAutoFireState(int btnIdx)
|
||||||
|
{
|
||||||
|
return rapidAlternator;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AutoFire(void)
|
||||||
|
{
|
||||||
static int counter = 0;
|
static int counter = 0;
|
||||||
if (justLagged == false)
|
if (justLagged == false)
|
||||||
counter = (counter + 1) % (8 * 7 * 5 * 3);
|
{
|
||||||
|
//counter = (counter + 1) % (8 * 7 * 5 * 3);
|
||||||
|
counter = (counter + 1) % AutoFirePatternLength;
|
||||||
|
}
|
||||||
//If recording a movie, use the frame # for the autofire so the offset
|
//If recording a movie, use the frame # for the autofire so the offset
|
||||||
//doesn't get screwed up when loading.
|
//doesn't get screwed up when loading.
|
||||||
if (FCEUMOV_Mode(MOVIEMODE_RECORD | MOVIEMODE_PLAY)) {
|
if (FCEUMOV_Mode(MOVIEMODE_RECORD | MOVIEMODE_PLAY))
|
||||||
rapidAlternator = AutoFirePattern[(AutoFireOffset + FCEUMOV_GetFrame()) % AutoFirePatternLength]; //adelikat: TODO: Think through this, MOVIEMODE_FINISHED should not use movie data for auto-fire?
|
{
|
||||||
} else {
|
//rapidAlternator = AutoFirePattern[(AutoFireOffset + FCEUMOV_GetFrame()) % AutoFirePatternLength]; //adelikat: TODO: Think through this, MOVIEMODE_FINISHED should not use movie data for auto-fire?
|
||||||
rapidAlternator = AutoFirePattern[(AutoFireOffset + counter) % AutoFirePatternLength];
|
//adelikat: TODO: Think through this, MOVIEMODE_FINISHED should not use movie data for auto-fire?
|
||||||
|
rapidAlternator = ( (AutoFireOffset + FCEUMOV_GetFrame()) % AutoFirePatternLength ) < AFon;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//rapidAlternator = AutoFirePattern[(AutoFireOffset + counter) % AutoFirePatternLength];
|
||||||
|
rapidAlternator = ( (AutoFireOffset + counter) % AutoFirePatternLength ) < AFon;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,8 @@ void PowerNES(void);
|
||||||
|
|
||||||
void SetAutoFireOffset(int offset);
|
void SetAutoFireOffset(int offset);
|
||||||
void SetAutoFirePattern(int onframes, int offframes);
|
void SetAutoFirePattern(int onframes, int offframes);
|
||||||
|
void GetAutoFirePattern( int *onframes, int *offframes);
|
||||||
|
bool GetAutoFireState(int btnIdx);
|
||||||
void AutoFire(void);
|
void AutoFire(void);
|
||||||
void FCEUI_RewindToLastAutosave(void);
|
void FCEUI_RewindToLastAutosave(void);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue