[Scummvm-cvs-logs] SF.net SVN: scummvm:[33889] scummvm/trunk/engines/parallaction

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Fri Aug 15 04:52:43 CEST 2008


Revision: 33889
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33889&view=rev
Author:   peres001
Date:     2008-08-15 02:52:42 +0000 (Fri, 15 Aug 2008)

Log Message:
-----------
Simplified handling of script variables (especially locals).

Modified Paths:
--------------
    scummvm/trunk/engines/parallaction/exec_br.cpp
    scummvm/trunk/engines/parallaction/exec_ns.cpp
    scummvm/trunk/engines/parallaction/objects.cpp
    scummvm/trunk/engines/parallaction/objects.h
    scummvm/trunk/engines/parallaction/parallaction.cpp
    scummvm/trunk/engines/parallaction/parallaction_ns.cpp
    scummvm/trunk/engines/parallaction/parser_br.cpp
    scummvm/trunk/engines/parallaction/parser_ns.cpp

Modified: scummvm/trunk/engines/parallaction/exec_br.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/exec_br.cpp	2008-08-15 01:22:09 UTC (rev 33888)
+++ scummvm/trunk/engines/parallaction/exec_br.cpp	2008-08-15 02:52:42 UTC (rev 33889)
@@ -321,12 +321,7 @@
 
 DECLARE_INSTRUCTION_OPCODE(set) {
 	InstructionPtr inst = *_ctxt.inst;
-
-	int16 rvalue = inst->_opB.getRValue();
-	int16* lvalue = inst->_opA.getLValue();
-
-	*lvalue = rvalue;
-
+	inst->_opA.setValue(inst->_opB.getValue());
 }
 
 
@@ -334,7 +329,7 @@
 DECLARE_INSTRUCTION_OPCODE(inc) {
 	InstructionPtr inst = *_ctxt.inst;
 
-	int16 rvalue = inst->_opB.getRValue();
+	int16 rvalue = inst->_opB.getValue();
 
 	if (inst->_flags & kInstMod) {	// mod
 		int16 _bx = (rvalue > 0 ? rvalue : -rvalue);
@@ -343,32 +338,30 @@
 		rvalue = (rvalue > 0 ?  1 : -1);
 	}
 
-	int16 *lvalue = inst->_opA.getLValue();
+	int16 lvalue = inst->_opA.getValue();
 
 	switch (inst->_index) {
 	case INST_INC:
-		*lvalue += rvalue;
+		lvalue += rvalue;
 		break;
 
 	case INST_DEC:
-		*lvalue -= rvalue;
+		lvalue -= rvalue;
 		break;
 
 	case INST_MUL:
-		*lvalue *= rvalue;
+		lvalue *= rvalue;
 		break;
 
 	case INST_DIV:
-		*lvalue /= rvalue;
+		lvalue /= rvalue;
 		break;
 
 	default:
 		error("This should never happen. Report immediately");
 	}
 
-	if (inst->_opA._flags & kParaLocal) {
-		inst->_opA._local->wrap();
-	}
+	inst->_opA.setValue(lvalue);
 
 }
 
@@ -401,11 +394,7 @@
 
 DECLARE_INSTRUCTION_OPCODE(color) {
 	InstructionPtr inst = *_ctxt.inst;
-
-	int16 entry = inst->_opB.getRValue();
-
-	_vm->_gfx->_palette.setEntry(entry, inst->_colors[0], inst->_colors[1], inst->_colors[2]);
-
+	_vm->_gfx->_palette.setEntry(inst->_opB.getValue(), inst->_colors[0], inst->_colors[1], inst->_colors[2]);
 }
 
 

Modified: scummvm/trunk/engines/parallaction/exec_ns.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/exec_ns.cpp	2008-08-15 01:22:09 UTC (rev 33888)
+++ scummvm/trunk/engines/parallaction/exec_ns.cpp	2008-08-15 02:52:42 UTC (rev 33889)
@@ -80,7 +80,7 @@
 DECLARE_INSTRUCTION_OPCODE(loop) {
 	InstructionPtr inst = *_ctxt.inst;
 
-	_ctxt.program->_loopCounter = inst->_opB.getRValue();
+	_ctxt.program->_loopCounter = inst->_opB.getValue();
 	_ctxt.program->_loopStart = _ctxt.ip;
 }
 
@@ -93,7 +93,7 @@
 
 DECLARE_INSTRUCTION_OPCODE(inc) {
 	InstructionPtr inst = *_ctxt.inst;
-	int16 _si = inst->_opB.getRValue();
+	int16 _si = inst->_opB.getValue();
 
 	if (inst->_flags & kInstMod) {	// mod
 		int16 _bx = (_si > 0 ? _si : -_si);
@@ -102,29 +102,22 @@
 		_si = (_si > 0 ?  1 : -1);
 	}
 
-	int16* lvalue = inst->_opA.getLValue();
+	int16 lvalue = inst->_opA.getValue();
 
 	if (inst->_index == INST_INC) {
-		*lvalue += _si;
+		lvalue += _si;
 	} else {
-		*lvalue -= _si;
+		lvalue -= _si;
 	}
 
-	if (inst->_opA._flags & kParaLocal) {
-		inst->_opA._local->wrap();
-	}
+	inst->_opA.setValue(lvalue);
 
 }
 
 
 DECLARE_INSTRUCTION_OPCODE(set) {
 	InstructionPtr inst = *_ctxt.inst;
-
-	int16 _si = inst->_opB.getRValue();
-	int16 *lvalue = inst->_opA.getLValue();
-
-	*lvalue = _si;
-
+	inst->_opA.setValue(inst->_opB.getValue());
 }
 
 
@@ -135,8 +128,8 @@
 	v18.h = inst->_a->height();
 	v18.pixels = inst->_a->getFrameData(inst->_a->_frame);
 
-	int16 x = inst->_opA.getRValue();
-	int16 y = inst->_opB.getRValue();
+	int16 x = inst->_opA.getValue();
+	int16 y = inst->_opB.getValue();
 	bool mask = (inst->_flags & kInstMaskedPut) == kInstMaskedPut;
 
 	_vm->_gfx->patchBackground(v18, x, y, mask);
@@ -176,8 +169,8 @@
 DECLARE_INSTRUCTION_OPCODE(move) {
 	InstructionPtr inst = (*_ctxt.inst);
 
-	int16 x = inst->_opA.getRValue();
-	int16 y = inst->_opB.getRValue();
+	int16 x = inst->_opA.getValue();
+	int16 y = inst->_opB.getValue();
 
 	_vm->_char.scheduleWalk(x, y);
 }
@@ -352,7 +345,6 @@
 
 		if (((anim->_flags & kFlagsActive) == 0) && (anim->_flags & kFlagsRemove))   {
 			anim->_flags &= ~kFlagsRemove;
-			anim->_oldPos.x = -1000;
 		}
 
 		if ((anim->_flags & kFlagsActive) && (anim->_flags & kFlagsRemove))	{

Modified: scummvm/trunk/engines/parallaction/objects.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/objects.cpp	2008-08-15 01:22:09 UTC (rev 33888)
+++ scummvm/trunk/engines/parallaction/objects.cpp	2008-08-15 02:52:42 UTC (rev 33889)
@@ -115,24 +115,29 @@
 	assert(_numLocals < NUM_LOCALS);
 
 	strcpy(_localNames[_numLocals], name);
-	_locals[_numLocals]._value = value;
+	_locals[_numLocals].setRange(min, max);
+	_locals[_numLocals].setValue(value);
 
-	_locals[_numLocals]._min = min;
-	_locals[_numLocals]._max = max;
-
 	return _numLocals++;
 }
 
-void LocalVariable::wrap() {
+void LocalVariable::setValue(int16 value) {
+	if (value >= _max)
+		value = _min;
+	if (value < _min)
+		value = _max - 1;
 
-	if (_value >= _max)
-		_value = _min;
-	if (_value < _min)
-		_value = _max - 1;
+	_value = value;
+}
 
-	return;
+void LocalVariable::setRange(int16 min, int16 max) {
+	_max = max;
+	_min = min;
 }
 
+int16 LocalVariable::getValue() const {
+	return _value;
+}
 
 
 Zone::Zone() {
@@ -273,14 +278,14 @@
 	free(_text2);
 }
 
-int16 ScriptVar::getRValue() {
+int16 ScriptVar::getValue() {
 
 	if (_flags & kParaImmediate) {
 		return _value;
 	}
 
 	if (_flags & kParaLocal) {
-		return _local->_value;
+		return _local->getValue();
 	}
 
 	if (_flags & kParaField) {
@@ -296,28 +301,29 @@
 	return 0;
 }
 
-int16* ScriptVar::getLValue() {
+void ScriptVar::setValue(int16 value) {
+	if ((_flags & kParaLValue) == 0) {
+		error("Only l-value can be set");
+	}
 
 	if (_flags & kParaLocal) {
-		return &_local->_value;
+		_local->setValue(value);
 	}
 
 	if (_flags & kParaField) {
-		return _pvalue;
+		*_pvalue = value;
 	}
 
-	error("Parameter is not an l-value");
-
 }
 
 void ScriptVar::setLocal(LocalVariable *local) {
 	_local = local;
-	_flags |= kParaLocal;
+	_flags |= (kParaLocal | kParaLValue);
 }
 
 void ScriptVar::setField(int16 *field) {
 	_pvalue = field;
-	_flags |= kParaField;
+	_flags |= (kParaField | kParaLValue);
 }
 
 void ScriptVar::setImmediate(int16 value) {

Modified: scummvm/trunk/engines/parallaction/objects.h
===================================================================
--- scummvm/trunk/engines/parallaction/objects.h	2008-08-15 01:22:09 UTC (rev 33888)
+++ scummvm/trunk/engines/parallaction/objects.h	2008-08-15 02:52:42 UTC (rev 33889)
@@ -306,8 +306,7 @@
 	uint32			_type;
 	uint32			_flags;
 	uint			_label;
-	uint16			field_2C;		// unused
-	uint16			field_2E;		// unused
+
 	TypeData		u;
 	CommandList		_commands;
 	Common::Point	_moveTo;
@@ -328,24 +327,33 @@
 
 
 struct LocalVariable {
+protected:
 	int16		_value;
 	int16		_min;
 	int16		_max;
 
+public:
+
 	LocalVariable() {
 		_value = 0;
 		_min = -10000;
 		_max = 10000;
 	}
 
-	void wrap();
+	void setRange(int16 min, int16 max);
+
+	int16 getValue() const;
+	void setValue(int16 value);
 };
 
+
 enum ParaFlags {
 	kParaImmediate	= 1,				// instruction is using an immediate parameter
 	kParaLocal		= 2,				// instruction is using a local variable
 	kParaField		= 0x10,				// instruction is using an animation's field
-	kParaRandom		= 0x100
+	kParaRandom		= 0x100,
+
+	kParaLValue		= 0x20
 };
 
 
@@ -358,8 +366,8 @@
 
 	ScriptVar();
 
-	int16	getRValue();
-	int16*	getLValue();
+	int16	getValue();
+	void	setValue(int16 value);
 
 	void	setLocal(LocalVariable *local);
 	void	setField(int16 *field);
@@ -431,19 +439,12 @@
 
 struct Animation : public Zone {
 
-	Common::Point	_oldPos;
 	GfxObj		*gfxobj;
 	char		*_scriptName;
 	int16		_frame;
-	uint16		field_50;		// unused
 	int16		_z;
-	uint16		field_54;		// unused
-	uint16		field_56;		// unused
-	uint16		field_58;		// unused
-	uint16		field_5A;		// unused
-	uint16		field_5C;		// unused
-	uint16		field_5E;		// unused
 
+
 	Animation();
 	virtual ~Animation();
 	virtual uint16 width() const;

Modified: scummvm/trunk/engines/parallaction/parallaction.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.cpp	2008-08-15 01:22:09 UTC (rev 33888)
+++ scummvm/trunk/engines/parallaction/parallaction.cpp	2008-08-15 02:52:42 UTC (rev 33889)
@@ -513,8 +513,6 @@
 	_ani->_left = 150;
 	_ani->_top = 100;
 	_ani->_z = 10;
-	_ani->_oldPos.x = -1000;
-	_ani->_oldPos.y = -1000;
 	_ani->_frame = 0;
 	_ani->_flags = kFlagsActive | kFlagsNoName;
 	_ani->_type = kZoneYou;

Modified: scummvm/trunk/engines/parallaction/parallaction_ns.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction_ns.cpp	2008-08-15 01:22:09 UTC (rev 33888)
+++ scummvm/trunk/engines/parallaction/parallaction_ns.cpp	2008-08-15 02:52:42 UTC (rev 33889)
@@ -318,10 +318,6 @@
 	strcpy(_saveData1, locname.location());
 	parseLocation(_saveData1);
 
-	_char._ani->_oldPos.x = -1000;
-	_char._ani->_oldPos.y = -1000;
-
-	_char._ani->field_50 = 0;
 	if (_location._startPosition.x != -1000) {
 		_char._ani->_left = _location._startPosition.x;
 		_char._ani->_top = _location._startPosition.y;

Modified: scummvm/trunk/engines/parallaction/parser_br.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parser_br.cpp	2008-08-15 01:22:09 UTC (rev 33888)
+++ scummvm/trunk/engines/parallaction/parser_br.cpp	2008-08-15 02:52:42 UTC (rev 33889)
@@ -849,9 +849,6 @@
 		ctxt.a->_bottom = ctxt.a->height();
 	}
 
-	ctxt.a->_oldPos.x = -1000;
-	ctxt.a->_oldPos.y = -1000;
-
 	ctxt.a->_flags |= 0x1000000;
 
 	_parser->popTables();

Modified: scummvm/trunk/engines/parallaction/parser_ns.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parser_ns.cpp	2008-08-15 01:22:09 UTC (rev 33888)
+++ scummvm/trunk/engines/parallaction/parser_ns.cpp	2008-08-15 02:52:42 UTC (rev 33889)
@@ -221,9 +221,6 @@
 		}
 	}
 
-	ctxt.a->_oldPos.x = -1000;
-	ctxt.a->_oldPos.y = -1000;
-
 	ctxt.a->_flags |= 0x1000000;
 
 	_parser->popTables();
@@ -284,10 +281,6 @@
 DECLARE_ANIM_PARSER(endanimation)  {
 	debugC(7, kDebugParser, "ANIM_PARSER(endanimation) ");
 
-
-	ctxt.a->_oldPos.x = -1000;
-	ctxt.a->_oldPos.y = -1000;
-
 	ctxt.a->_flags |= 0x1000000;
 
 	_parser->popTables();
@@ -523,7 +516,7 @@
 	}
 
 	ctxt.inst->_opA.setLocal(&ctxt.locals[index]);
-	ctxt.inst->_opB.setImmediate(ctxt.locals[index]._value);
+	ctxt.inst->_opB.setImmediate(ctxt.locals[index].getValue());
 
 	ctxt.inst->_index = INST_SET;
 }


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list