Made scripts access Animation fields via accessors and mutators, instead of using raw pointers.
svn-id: r33891
This commit is contained in:
parent
2679f6ce7a
commit
c70d09bc26
4 changed files with 83 additions and 19 deletions
|
@ -289,7 +289,7 @@ int16 ScriptVar::getValue() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_flags & kParaField) {
|
if (_flags & kParaField) {
|
||||||
return *_pvalue;
|
return _field->getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_flags & kParaRandom) {
|
if (_flags & kParaRandom) {
|
||||||
|
@ -311,7 +311,7 @@ void ScriptVar::setValue(int16 value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_flags & kParaField) {
|
if (_flags & kParaField) {
|
||||||
*_pvalue = value;
|
_field->setValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -321,11 +321,16 @@ void ScriptVar::setLocal(LocalVariable *local) {
|
||||||
_flags |= (kParaLocal | kParaLValue);
|
_flags |= (kParaLocal | kParaLValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptVar::setField(int16 *field) {
|
void ScriptVar::setField(Animation *anim, AnimationField::AccessorFunc accessor, AnimationField::MutatorFunc mutator) {
|
||||||
_pvalue = field;
|
_field = new AnimationField(anim, accessor, mutator);
|
||||||
_flags |= (kParaField | kParaLValue);
|
_flags |= (kParaField | kParaLValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScriptVar::setField(Animation *anim, AnimationField::AccessorFunc accessor) {
|
||||||
|
_field = new AnimationField(anim, accessor);
|
||||||
|
_flags |= kParaField;
|
||||||
|
}
|
||||||
|
|
||||||
void ScriptVar::setImmediate(int16 value) {
|
void ScriptVar::setImmediate(int16 value) {
|
||||||
_value = value;
|
_value = value;
|
||||||
_flags |= kParaImmediate;
|
_flags |= kParaImmediate;
|
||||||
|
@ -341,9 +346,14 @@ ScriptVar::ScriptVar() {
|
||||||
_flags = 0;
|
_flags = 0;
|
||||||
_local = 0;
|
_local = 0;
|
||||||
_value = 0;
|
_value = 0;
|
||||||
_pvalue = 0;
|
_field = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ScriptVar::~ScriptVar() {
|
||||||
|
delete _field;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Table::Table(uint32 size) : _size(size), _used(0), _disposeMemory(true) {
|
Table::Table(uint32 size) : _size(size), _used(0), _disposeMemory(true) {
|
||||||
_data = (char**)calloc(size, sizeof(char*));
|
_data = (char**)calloc(size, sizeof(char*));
|
||||||
}
|
}
|
||||||
|
|
|
@ -357,20 +357,61 @@ enum ParaFlags {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct AnimationField {
|
||||||
|
typedef Common::Functor0Mem<int16, Animation> Accessor;
|
||||||
|
typedef Common::Functor1Mem<int16, void, Animation> Mutator;
|
||||||
|
|
||||||
|
typedef Accessor::FuncType AccessorFunc;
|
||||||
|
typedef Mutator::FuncType MutatorFunc;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Accessor *_accessor;
|
||||||
|
Mutator *_mutator;
|
||||||
|
|
||||||
|
public:
|
||||||
|
AnimationField(Animation* instance, AccessorFunc accessor, MutatorFunc mutator) {
|
||||||
|
_accessor = new Accessor(instance, accessor);
|
||||||
|
_mutator = new Mutator(instance, mutator);
|
||||||
|
}
|
||||||
|
|
||||||
|
AnimationField(Animation* instance, AccessorFunc accessor) {
|
||||||
|
_accessor = new Accessor(instance, accessor);
|
||||||
|
_mutator = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
~AnimationField() {
|
||||||
|
delete _accessor;
|
||||||
|
delete _mutator;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16 getValue() const {
|
||||||
|
assert(_accessor);
|
||||||
|
return _accessor->operator()();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setValue(int16 value) {
|
||||||
|
assert(_mutator);
|
||||||
|
_mutator->operator()(value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
struct ScriptVar {
|
struct ScriptVar {
|
||||||
uint32 _flags;
|
uint32 _flags;
|
||||||
|
|
||||||
int16 _value;
|
int16 _value;
|
||||||
int16* _pvalue;
|
|
||||||
LocalVariable* _local;
|
LocalVariable* _local;
|
||||||
|
AnimationField* _field;
|
||||||
|
|
||||||
ScriptVar();
|
ScriptVar();
|
||||||
|
~ScriptVar();
|
||||||
|
|
||||||
int16 getValue();
|
int16 getValue();
|
||||||
void setValue(int16 value);
|
void setValue(int16 value);
|
||||||
|
|
||||||
void setLocal(LocalVariable *local);
|
void setLocal(LocalVariable *local);
|
||||||
void setField(int16 *field);
|
void setField(Animation *anim, AnimationField::AccessorFunc accessor, AnimationField::MutatorFunc mutator);
|
||||||
|
void setField(Animation *anim, AnimationField::AccessorFunc accessor);
|
||||||
void setImmediate(int16 value);
|
void setImmediate(int16 value);
|
||||||
void setRandom(int16 seed);
|
void setRandom(int16 seed);
|
||||||
};
|
};
|
||||||
|
@ -453,6 +494,19 @@ struct Animation : public Zone {
|
||||||
byte* getFrameData(uint32 index) const;
|
byte* getFrameData(uint32 index) const;
|
||||||
|
|
||||||
void validateScriptVars();
|
void validateScriptVars();
|
||||||
|
|
||||||
|
// getters/setters used by scripts
|
||||||
|
int16 getX() { return _left; }
|
||||||
|
void setX(int16 value) { _left = value; }
|
||||||
|
|
||||||
|
int16 getY() { return _top; }
|
||||||
|
void setY(int16 value) { _top = value; }
|
||||||
|
|
||||||
|
int16 getZ() { return _z; }
|
||||||
|
void setZ(int16 value) { _z = value; }
|
||||||
|
|
||||||
|
int16 getF() { return _frame; }
|
||||||
|
void setF(int16 value) { _frame = value; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class Table {
|
class Table {
|
||||||
|
|
|
@ -991,16 +991,16 @@ void ProgramParser_br::parseRValue(ScriptVar &v, const char *str) {
|
||||||
a = AnimationPtr(ctxt.a);
|
a = AnimationPtr(ctxt.a);
|
||||||
|
|
||||||
if (str[0] == 'X') {
|
if (str[0] == 'X') {
|
||||||
v.setField(&a->_left);
|
v.setField(a.get(), &Animation::getX);
|
||||||
} else
|
} else
|
||||||
if (str[0] == 'Y') {
|
if (str[0] == 'Y') {
|
||||||
v.setField(&a->_top);
|
v.setField(a.get(), &Animation::getY);
|
||||||
} else
|
} else
|
||||||
if (str[0] == 'Z') {
|
if (str[0] == 'Z') {
|
||||||
v.setField(&a->_z);
|
v.setField(a.get(), &Animation::getZ);
|
||||||
} else
|
} else
|
||||||
if (str[0] == 'F') {
|
if (str[0] == 'F') {
|
||||||
v.setField(&a->_frame);
|
v.setField(a.get(), &Animation::getF);
|
||||||
} else
|
} else
|
||||||
if (str[0] == 'N') {
|
if (str[0] == 'N') {
|
||||||
v.setImmediate(a->getFrameNum());
|
v.setImmediate(a->getFrameNum());
|
||||||
|
|
|
@ -551,16 +551,16 @@ void ProgramParser_ns::parseRValue(ScriptVar &v, const char *str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str[0] == 'X') {
|
if (str[0] == 'X') {
|
||||||
v.setField(&a->_left);
|
v.setField(a.get(), &Animation::getX);
|
||||||
} else
|
} else
|
||||||
if (str[0] == 'Y') {
|
if (str[0] == 'Y') {
|
||||||
v.setField(&a->_top);
|
v.setField(a.get(), &Animation::getY);
|
||||||
} else
|
} else
|
||||||
if (str[0] == 'Z') {
|
if (str[0] == 'Z') {
|
||||||
v.setField(&a->_z);
|
v.setField(a.get(), &Animation::getZ);
|
||||||
} else
|
} else
|
||||||
if (str[0] == 'F') {
|
if (str[0] == 'F') {
|
||||||
v.setField(&a->_frame);
|
v.setField(a.get(), &Animation::getF);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -581,16 +581,16 @@ void ProgramParser_ns::parseLValue(ScriptVar &v, const char *str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str[0] == 'X') {
|
if (str[0] == 'X') {
|
||||||
v.setField(&a->_left);
|
v.setField(a.get(), &Animation::getX, &Animation::setX);
|
||||||
} else
|
} else
|
||||||
if (str[0] == 'Y') {
|
if (str[0] == 'Y') {
|
||||||
v.setField(&a->_top);
|
v.setField(a.get(), &Animation::getY, &Animation::setY);
|
||||||
} else
|
} else
|
||||||
if (str[0] == 'Z') {
|
if (str[0] == 'Z') {
|
||||||
v.setField(&a->_z);
|
v.setField(a.get(), &Animation::getZ, &Animation::setZ);
|
||||||
} else
|
} else
|
||||||
if (str[0] == 'F') {
|
if (str[0] == 'F') {
|
||||||
v.setField(&a->_frame);
|
v.setField(a.get(), &Animation::getF, &Animation::setF);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue