Skip to content

Commit

Permalink
add support for SCR files
Browse files Browse the repository at this point in the history
  • Loading branch information
profezzorn committed Nov 13, 2023
1 parent 2d0f0a1 commit 93d2671
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions sound/effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class Effect {
BMP,
PBM,
Binary, // .BIN
SCR,
UNKNOWN,
};

Expand All @@ -98,6 +99,7 @@ class Effect {
enum class FileType : uint8_t {
SOUND,
IMAGE,
SCREEN,
UNKNOWN,
};

Expand All @@ -111,6 +113,8 @@ class Effect {
case PBM:
case Binary:
return FileType::IMAGE;
case SCR:
return FileType::SCREEN;
default:
return FileType::UNKNOWN;
}
Expand All @@ -123,6 +127,7 @@ class Effect {
if (endswith(".bmp", filename)) return BMP;
if (endswith(".pbm", filename)) return PBM;
if (endswith(".bin", filename)) return Binary;
if (endswith(".scr", filename)) return SCR;
return UNKNOWN;
}

Expand Down Expand Up @@ -772,7 +777,7 @@ class EffectFileReader : public FileReader {
public:
EffectFileReader() : FileReader(), do_open_(0) {}

bool Play(Effect* f) {
bool PlayInternal(Effect* f) {
do_open_.set(false);
Effect::FileID id = f->RandomFile();
if (!id) {
Expand All @@ -783,12 +788,33 @@ class EffectFileReader : public FileReader {
return true;
}

void Play(const char* filename) {
bool Play(Effect* f) {
if (PlayInternal(f)) {
do_open_.set(true);
return true;
} else {
return false;
}
}

void PlayInternal(const char* filename) {
do_open_.set(false);
strncpy(filename_, filename, sizeof(filename_));
}

void Play(const char* filename) {
PlayInternal(filename);
do_open_.set(true);
}

void do_open() {
do_open_.set(true);
}

bool get_do_open() const {
return do_open_.get();
}

// Returns true if we had been asked to open a file.
// Check if open succeded or not by calling IsOpen()
bool OpenFile() {
Expand All @@ -801,7 +827,11 @@ class EffectFileReader : public FileReader {
do_open_.set(false);
return true;
}
private:

const char* GetFilename() {
return filename_;
}
protected:
POAtomic<bool> do_open_;
char filename_[128];
};
Expand Down

0 comments on commit 93d2671

Please sign in to comment.