Skip to content

Commit

Permalink
AURORA: Add properties loading for FEV files
Browse files Browse the repository at this point in the history
  • Loading branch information
Nostritius authored and DrMcCoy committed Nov 3, 2018
1 parent 204cccc commit 86a14fb
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 2 deletions.
36 changes: 34 additions & 2 deletions src/aurora/fevfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ void FEVFile::readCategory(Common::SeekableReadStream &fev) {
void FEVFile::readEventCategory(Common::SeekableReadStream &fev) {
Common::UString name = readLengthPrefixedString(fev);

fev.skip(4); // Unknown value
// Read user properties
readProperties(fev);

const uint32 numSubEventCategories = fev.readUint32LE();
const uint32 numEvents = fev.readUint32LE();
Expand Down Expand Up @@ -174,11 +175,42 @@ void FEVFile::readEvent(Common::SeekableReadStream &fev) {
event.spawnIntensity = fev.readIEEEFloatLE();
event.spawnIntensityRandomization = fev.readIEEEFloatLE();

fev.skip(36);
fev.skip(26);

event.userProperties = readProperties(fev);

fev.skip(4); // Always 1?

event.category = readLengthPrefixedString(fev);
}

std::map<Common::UString, FEVFile::Property> FEVFile::readProperties(Common::SeekableReadStream &fev) {
const uint32 numUserProperties = fev.readUint32LE();
std::map<Common::UString, FEVFile::Property> properties;
for (uint32 i = 0; i < numUserProperties; ++i) {
Common::UString propertyName = readLengthPrefixedString(fev);
Property property;
property.type = PropertyType(fev.readUint32LE());
switch (property.type) {
case kPropertyInt: // Integer value
property.value = fev.readSint32LE();
break;
case kPropertyFloat: // Floating point value
property.value = fev.readIEEEFloatLE();
break;
case kPropertyString: // String value
property.value = readLengthPrefixedString(fev);
break;
default:
throw Common::Exception("FEVFile::readEventCategory() Invalid property type %i", property.type);
}

properties.insert(std::make_pair(propertyName, property));
}

return properties;
}

Common::UString FEVFile::readLengthPrefixedString(Common::SeekableReadStream &fev) {
const uint32 length = fev.readUint32LE();
return Common::readStringFixed(fev, Common::kEncodingASCII, length);
Expand Down
53 changes: 53 additions & 0 deletions src/aurora/fevfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#ifndef AURORA_FEVFILE_H
#define AURORA_FEVFILE_H

#include <map>

#include <boost/variant.hpp>

#include "src/common/readstream.h"
#include "src/common/ustring.h"

Expand All @@ -45,6 +49,29 @@ class FEVFile {
kStreamFromDisk
};

/** Possible Play modes. */
enum PlayMode {
kSequential = 0,
kRandom,
kRandomNoRepeat,
kSequentialNoRepeat,
kShuffle,
kProgrammerSelected
};

/** Possible Property types. */
enum PropertyType {
kPropertyInt = 0,
kPropertyFloat,
kPropertyString
};

/** Some objects in FMOD can have generic properties. */
struct Property {
PropertyType type;
boost::variant<int32, float, Common::UString> value;
};

/** Reference to an external wave bank. */
struct WaveBank {
uint32 maxStreams;
Expand All @@ -59,6 +86,11 @@ class FEVFile {
uint32 pitch;
};

/** An event category for storing events. */
struct EventCategory {
Common::UString name;
};

/** An FMOD event.
*
* @note
Expand Down Expand Up @@ -97,9 +129,26 @@ class FEVFile {
float spawnIntensity;
float spawnIntensityRandomization;

std::map<Common::UString, Property> userProperties;
Common::UString category;
};

/** A sound definition. */
struct SoundDefinition {
PlayMode playMode;

Common::UString name;

uint32 spawnTimeMin;
uint32 spawnTimeMax;
uint32 maximumSpawnedSounds;
float volume;
float volumeRandomization;
float pitch;
float pitchRandomization;
float position3DRandomization;
};

FEVFile(const Common::UString &resRef);
FEVFile(Common::SeekableReadStream &fev);

Expand All @@ -118,13 +167,17 @@ class FEVFile {
/** Read an event. */
void readEvent(Common::SeekableReadStream &fev);

/** Read properties. */
std::map<Common::UString, Property> readProperties(Common::SeekableReadStream &fev);
/** Read an FEV length prefixed string. */
Common::UString readLengthPrefixedString(Common::SeekableReadStream &fev);

Common::UString _bankName;

std::vector<WaveBank> _waveBanks;
std::vector<Category> _categories;
std::vector<Event> _events;
std::vector<SoundDefinition> _definitions;
};

} // End of namespace Aurora
Expand Down

0 comments on commit 86a14fb

Please sign in to comment.