[Scummvm-cvs-logs] CVS: scummvm/saga script.cpp,1.14,1.15 script.h,1.7,1.8 sdata.cpp,1.10,1.11 sdebug.cpp,1.8,1.9 sthread.cpp,1.14,1.15

Joost Peters joostp at users.sourceforge.net
Sun Aug 1 16:48:10 CEST 2004


Update of /cvsroot/scummvm/scummvm/saga
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24376/saga

Modified Files:
	script.cpp script.h sdata.cpp sdebug.cpp sthread.cpp 
Log Message:
Clean up Script class a bit; add get/set functions


Index: script.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/script.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- script.cpp	1 Aug 2004 23:24:22 -0000	1.14
+++ script.cpp	1 Aug 2004 23:47:19 -0000	1.15
@@ -62,19 +62,16 @@
 	int i, j;
 
 	//initialize member variables
-	_initialized = 0;
-	_script_ctxt = 0;
-	_voice_lut_present = 0;
-	_script_lut = 0;
-	_script_lut_max = 0;
-	_script_lut_entrylen = 0;
-	_current_script = 0;
-	_thread_list = 0;
-	memset(_data_buf, 0, sizeof(_data_buf));
+	_scriptContext = 0;
+	_voiceLUTPresent = false;
+	_scriptLUTEntryLen = 0;
+	_currentScript = 0;
+	_threadList = 0;
+	memset(_dataBuf, 0, sizeof(_dataBuf));
 	
 	debug(0, "Initializing scripting subsystem");
 	// Load script resource file context
-	result = GAME_GetFileContext(&_script_ctxt, R_GAME_SCRIPTFILE, 0);
+	result = GAME_GetFileContext(&_scriptContext, R_GAME_SCRIPTFILE, 0);
 	if (result != R_SUCCESS) {
 		error("Couldn't get script file context");
 	}
@@ -92,48 +89,49 @@
 
 	// Create logical script LUT from resource
 	if (rsc_len % R_S_LUT_ENTRYLEN_ITECD == 0) {
-		_script_lut_entrylen = R_S_LUT_ENTRYLEN_ITECD;
+		_scriptLUTEntryLen = R_S_LUT_ENTRYLEN_ITECD;
 	} else if (rsc_len % R_S_LUT_ENTRYLEN_ITEDISK == 0) {
-		_script_lut_entrylen = R_S_LUT_ENTRYLEN_ITEDISK;
+		_scriptLUTEntryLen = R_S_LUT_ENTRYLEN_ITEDISK;
 	} else {
 		error("Error: Invalid script lookup table length");
 	}
 
 	// Calculate number of entries
-	_script_lut_max = rsc_len / _script_lut_entrylen;
+	_scriptLUTMax = rsc_len / _scriptLUTEntryLen;
 
 	// Allocate space for logical LUT
-	_script_lut = (R_SCRIPT_LUT_ENTRY *)malloc(_script_lut_max * sizeof(R_SCRIPT_LUT_ENTRY));
-	if (_script_lut == NULL) {
+	_scriptLUT = (R_SCRIPT_LUT_ENTRY *)malloc(_scriptLUTMax * sizeof(R_SCRIPT_LUT_ENTRY));
+	if (_scriptLUT == NULL) {
 		error("Error: Couldn't allocate memory for script resource look-up table");
 	}
 
 	// Convert LUT resource to logical LUT
 	MemoryReadStream readS(rsc_ptr, rsc_len);
-	for (i = 0; i < _script_lut_max; i++) {
+	for (i = 0; i < _scriptLUTMax; i++) {
 		prevTell = readS.pos();
-		_script_lut[i].script_rn = readS.readUint16LE();
-		_script_lut[i].diag_list_rn = readS.readUint16LE();
-		_script_lut[i].voice_lut_rn = readS.readUint16LE();
+		_scriptLUT[i].script_rn = readS.readUint16LE();
+		_scriptLUT[i].diag_list_rn = readS.readUint16LE();
+		_scriptLUT[i].voice_lut_rn = readS.readUint16LE();
+		
 		// Skip the unused portion of the structure
-		for (j = readS.pos(); j < prevTell + _script_lut_entrylen; j++)
+		for (j = readS.pos(); j < prevTell + _scriptLUTEntryLen; j++)
 			readS.readByte();
 	}
 
 	RSC_FreeResource(rsc_ptr);
 
 	// Any voice lookup table resources present?
-	for (i = 0; i < _script_lut_max; i++) {
-		if (_script_lut[i].voice_lut_rn) {
-			_voice_lut_present = 1;
+	for (i = 0; i < _scriptLUTMax; i++) {
+		if (_scriptLUT[i].voice_lut_rn) {
+			_voiceLUTPresent = true;
 			break;
 		}
 	}
 
 	// Initialize script submodules
-	_thread_list = ys_dll_create();
+	_threadList = ys_dll_create();
 
-	_initialized = 1;
+	_initialized = true;
 }
 
 // Shut down script module gracefully; free all allocated module resources
@@ -148,17 +146,17 @@
 	debug(0, "Shutting down scripting subsystem.");
 
 	// Free script lookup table
-	free(_script_lut);
+	free(_scriptLUT);
 
 	// Stop all threads and destroy them
 
-	for (thread_node = ys_dll_head(_thread_list); thread_node != NULL;
+	for (thread_node = ys_dll_head(_threadList); thread_node != NULL;
 				thread_node = ys_dll_next(thread_node)) {
 		thread = (R_SCRIPT_THREAD *)ys_dll_get_data(thread_node);
 		STHREAD_Destroy(thread);
 	}
 
-	_initialized = 0;
+	_initialized = false;
 }
 
 // Loads a script; including script bytecode and dialogue list 
@@ -180,7 +178,7 @@
 	}
 
 	// Validate script number
-	if ((script_num < 0) || (script_num > _script_lut_max)) {
+	if ((script_num < 0) || (script_num > _scriptLUTMax)) {
 		warning("Script::loadScript(): Invalid script number");
 		return R_FAILURE;
 	}
@@ -205,9 +203,9 @@
 	script_data->voice = NULL;
 
 	// Load script bytecode
-	scriptl_rn = _script_lut[script_num].script_rn;
+	scriptl_rn = _scriptLUT[script_num].script_rn;
 
-	result = RSC_LoadResource(_script_ctxt, scriptl_rn, &bytecode_p, &bytecode_len);
+	result = RSC_LoadResource(_scriptContext, scriptl_rn, &bytecode_p, &bytecode_len);
 	if (result != R_SUCCESS) {
 		warning("Error loading script bytecode resource");
 		free(script_data);
@@ -224,10 +222,10 @@
 	}
 
 	// Load script dialogue list
-	diagl_rn = _script_lut[script_num].diag_list_rn;
+	diagl_rn = _scriptLUT[script_num].diag_list_rn;
 
 	// Load dialogue list resource
-	result = RSC_LoadResource(_script_ctxt, diagl_rn, &diagl_p, &diagl_len);
+	result = RSC_LoadResource(_scriptContext, diagl_rn, &diagl_p, &diagl_len);
 	if (result != R_SUCCESS) {
 		warning("Error loading dialogue list resource");
 		free(script_data);
@@ -246,11 +244,11 @@
 	}
 
 	// Load voice resource lookup table
-	if (_voice_lut_present) {
-		voicelut_rn = _script_lut[script_num].voice_lut_rn;
+	if (_voiceLUTPresent) {
+		voicelut_rn = _scriptLUT[script_num].voice_lut_rn;
 
 		// Load voice LUT resource
-		result = RSC_LoadResource(_script_ctxt, voicelut_rn, &voicelut_p, &voicelut_len);
+		result = RSC_LoadResource(_scriptContext, voicelut_rn, &voicelut_p, &voicelut_len);
 		if (result != R_SUCCESS) {
 			warning("Error loading voice LUT resource");
 			free(script_data);
@@ -273,45 +271,45 @@
 
 	// Finish initialization
 	script_data->loaded = 1;
-	_current_script = script_data;
+	_currentScript = script_data;
 
 	return R_SUCCESS;
 }
 
 // Frees all resources associated with current script.
 int Script::freeScript() {
-	if (_current_script == NULL) {
+	if (_currentScript == NULL) {
 		return R_FAILURE;
 	}
 
-	if (!_current_script->loaded) {
+	if (!_currentScript->loaded) {
 		return R_FAILURE;
 	}
 
 	debug(0, "Releasing script data.");
 
 	// Finish initialization
-	if (_current_script->diag != NULL) {
-		free(_current_script->diag->str);
-		free(_current_script->diag->str_off);
+	if (_currentScript->diag != NULL) {
+		free(_currentScript->diag->str);
+		free(_currentScript->diag->str_off);
 	}
-	free(_current_script->diag);
+	free(_currentScript->diag);
 
-	if (_current_script->bytecode != NULL) {
-		free(_current_script->bytecode->entrypoints);
-		RSC_FreeResource(_current_script->bytecode->bytecode_p);
+	if (_currentScript->bytecode != NULL) {
+		free(_currentScript->bytecode->entrypoints);
+		RSC_FreeResource(_currentScript->bytecode->bytecode_p);
 	}
 
-	free(_current_script->bytecode);
+	free(_currentScript->bytecode);
 
-	if (_voice_lut_present) {
-		free(_current_script->voice->voices);
-		free(_current_script->voice);
+	if (_voiceLUTPresent) {
+		free(_currentScript->voice->voices);
+		free(_currentScript->voice);
 	}
 
-	free(_current_script);
+	free(_currentScript);
 
-	_current_script = NULL;
+	_currentScript = NULL;
 
 	return R_SUCCESS;
 }
@@ -494,21 +492,21 @@
 	uint32 i;
 	char *name_ptr;
 
-	if (((Script *)refCon)->_current_script == NULL) {
+	if (((Script *)refCon)->currentScript() == NULL) {
 		return;
 	}
 
-	if (!((Script *)refCon)->_current_script->loaded) {
+	if (!((Script *)refCon)->currentScript()->loaded) {
 		return;
 	}
 
-	n_entrypoints = ((Script *)refCon)->_current_script->bytecode->n_entrypoints;
+	n_entrypoints = ((Script *)refCon)->currentScript()->bytecode->n_entrypoints;
 
 	CON_Print("Current script contains %d entrypoints:", n_entrypoints);
 
 	for (i = 0; i < n_entrypoints; i++) {
-		name_ptr = (char *)((Script *)refCon)->_current_script->bytecode->bytecode_p +
-							((Script *)refCon)->_current_script->bytecode->entrypoints[i].name_offset;
+		name_ptr = (char *)((Script *)refCon)->currentScript()->bytecode->bytecode_p +
+							((Script *)refCon)->currentScript()->bytecode->entrypoints[i].name_offset;
 		CON_Print("%lu: %s", i, name_ptr);
 	}
 }
@@ -531,7 +529,7 @@
 		}
 	}
 
-	if (ep_num >= ((Script *)refCon)->_current_script->bytecode->n_entrypoints) {
+	if (ep_num >= ((Script *)refCon)->currentScript()->bytecode->n_entrypoints) {
 		CON_Print("Invalid entrypoint.");
 		return;
 	}

Index: script.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/script.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- script.h	1 Aug 2004 22:48:40 -0000	1.7
+++ script.h	1 Aug 2004 23:47:19 -0000	1.8
@@ -104,18 +104,25 @@
 	R_VOICE_LUT *loadVoiceLUT(const byte *voicelut_p, size_t voicelut_len, R_SCRIPTDATA *script);
 	int disassemble(R_SCRIPT_BYTECODE *script_list, R_DIALOGUE_LIST *diag_list);
 
-
-//protected:
-//these are temporarily public, eventually get/set methods should be created for them
-	int _initialized;
-	R_RSCFILE_CONTEXT *_script_ctxt;
-	int _voice_lut_present;
-	R_SCRIPT_LUT_ENTRY *_script_lut;
-	int _script_lut_max;
-	uint16 _script_lut_entrylen;
-	R_SCRIPTDATA *_current_script;
-	YS_DL_LIST *_thread_list;
-	R_SCRIPT_DATABUF *_data_buf[R_SCRIPT_DATABUF_NUM];
+	bool isInitialized() const { return _initialized;  }
+	bool isVoiceLUTPresent() const { return _voiceLUTPresent; }
+	R_SCRIPTDATA *currentScript() { return _currentScript; }
+	void setBuffer(int idx, R_SCRIPT_DATABUF *ptr) { _dataBuf[idx] = ptr; }
+	R_SCRIPT_DATABUF *dataBuffer(int idx) { return _dataBuf[idx]; }
+	YS_DL_LIST *threadList() { return _threadList; }
+	
+protected:
+	bool _initialized;
+	bool _voiceLUTPresent;
+	R_RSCFILE_CONTEXT *_scriptContext;
+	R_SCRIPT_LUT_ENTRY *_scriptLUT;
+	int _scriptLUTMax;
+	uint16 _scriptLUTEntryLen;
+	R_SCRIPTDATA *_currentScript;
+	R_SCRIPT_DATABUF *_dataBuf[R_SCRIPT_DATABUF_NUM];
+	YS_DL_LIST *_threadList;
+	
+public:
 	int _dbg_singlestep;
 	int _dbg_dostep;
 	R_SCRIPT_THREAD *_dbg_thread;

Index: sdata.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/sdata.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- sdata.cpp	1 Aug 2004 22:48:40 -0000	1.10
+++ sdata.cpp	1 Aug 2004 23:47:19 -0000	1.11
@@ -37,20 +37,20 @@
 
 	debug(0, "Initializing script data buffers");
 	for (i = 0; i < R_SCRIPT_DATABUF_NUM; i++) {
-		alloc_ptr = malloc(sizeof *_vm->_script->_data_buf[0]);
+		alloc_ptr = malloc(sizeof *_vm->_script->dataBuffer(0));
 		if (alloc_ptr == NULL) {
 			error("Couldn't allocate memory for script data buffer %d", i);
 		}
 
-		_vm->_script->_data_buf[i] = (R_SCRIPT_DATABUF *)alloc_ptr;
+		_vm->_script->setBuffer(i, (R_SCRIPT_DATABUF *)alloc_ptr);
 		alloc_ptr = calloc(R_SCRIPT_DATABUF_LEN, sizeof(SDataWord_T));
 
 		if (alloc_ptr == NULL) {
 			error("Couldn't allocate memory for script data buffer %d", i);
 		}
 
-		_vm->_script->_data_buf[i]->len = R_SCRIPT_DATABUF_LEN;
-		_vm->_script->_data_buf[i]->data = (SDataWord_T *)alloc_ptr;
+		_vm->_script->dataBuffer(i)->len = R_SCRIPT_DATABUF_LEN;
+		_vm->_script->dataBuffer(i)->data = (SDataWord_T *)alloc_ptr;
 	}
 }
 
@@ -62,7 +62,7 @@
 		return R_FAILURE;
 	}
 
-	if ((n_word < 0) || (n_word >= _vm->_script->_data_buf[n_buf]->len)) {
+	if ((n_word < 0) || (n_word >= _vm->_script->dataBuffer(n_buf)->len)) {
 		return R_FAILURE;
 	}
 
@@ -70,7 +70,7 @@
 		return R_FAILURE;
 	}
 
-	*data = _vm->_script->_data_buf[n_buf]->data[n_word];
+	*data = _vm->_script->dataBuffer(n_buf)->data[n_word];
 
 	return R_SUCCESS;
 }
@@ -80,11 +80,11 @@
 		return R_FAILURE;
 	}
 
-	if ((n_word < 0) || (n_word >= _vm->_script->_data_buf[n_buf]->len)) {
+	if ((n_word < 0) || (n_word >= _vm->_script->dataBuffer(n_buf)->len)) {
 		return R_FAILURE;
 	}
 
-	_vm->_script->_data_buf[n_buf]->data[n_word] = data;
+	_vm->_script->dataBuffer(n_buf)->data[n_word] = data;
 
 	return R_SUCCESS;
 }
@@ -99,7 +99,7 @@
 		return R_FAILURE;
 	}
 
-	if (n_bit >= (unsigned long)_vm->_script->_data_buf[n_buf]->len * (sizeof(SDataWord_T) * CHAR_BIT)) {
+	if (n_bit >= (unsigned long)_vm->_script->dataBuffer(n_buf)->len * (sizeof(SDataWord_T) * CHAR_BIT)) {
 		return R_FAILURE;
 	}
 
@@ -109,9 +109,9 @@
 	bit_pattern <<= ((sizeof(SDataWord_T) * CHAR_BIT) - (n_bitpos + 1));
 
 	if (bitstate) {
-		_vm->_script->_data_buf[n_buf]->data[n_word] |= bit_pattern;
+		_vm->_script->dataBuffer(n_buf)->data[n_word] |= bit_pattern;
 	} else {
-		_vm->_script->_data_buf[n_buf]->data[n_word] &= ~bit_pattern;
+		_vm->_script->dataBuffer(n_buf)->data[n_word] &= ~bit_pattern;
 	}
 
 	return R_SUCCESS;
@@ -127,7 +127,7 @@
 		return R_FAILURE;
 	}
 
-	if (n_bit >= (SDataWord_T) _vm->_script->_data_buf[n_buf]->len * (sizeof(SDataWord_T) * CHAR_BIT)) {
+	if (n_bit >= (SDataWord_T) _vm->_script->dataBuffer(n_buf)->len * (sizeof(SDataWord_T) * CHAR_BIT)) {
 		return R_FAILURE;
 	}
 
@@ -136,7 +136,7 @@
 
 	bit_pattern <<= ((sizeof(SDataWord_T) * CHAR_BIT) - (n_bitpos + 1));
 
-	*bitstate = (_vm->_script->_data_buf[n_buf]->data[n_word] & bit_pattern) ? 1 : 0;
+	*bitstate = (_vm->_script->dataBuffer(n_buf)->data[n_word] & bit_pattern) ? 1 : 0;
 
 	return R_SUCCESS;
 }

Index: sdebug.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/sdebug.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- sdebug.cpp	1 Aug 2004 23:24:22 -0000	1.8
+++ sdebug.cpp	1 Aug 2004 23:47:19 -0000	1.9
@@ -67,10 +67,9 @@
 	tl_e.string = disp_buf;
 	tl_e.display = 1;
 
-	// XXX
-	MemoryReadStream readS(_vm->_script->_current_script->bytecode->bytecode_p 
+	MemoryReadStream readS(_vm->_script->currentScript()->bytecode->bytecode_p 
 							 + thread->i_offset, 
-							 _vm->_script->_current_script->bytecode->bytecode_len 
+							 _vm->_script->currentScript()->bytecode->bytecode_len 
 							 - thread->i_offset);
 	in_char = readS.readByte();
 	sprintf(tmp_buf, "%04lX | %02X | ", thread->i_offset, in_char);

Index: sthread.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/sthread.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- sthread.cpp	1 Aug 2004 23:24:22 -0000	1.14
+++ sthread.cpp	1 Aug 2004 23:47:19 -0000	1.15
@@ -47,7 +47,7 @@
 
 	int result;
 
-	if (!_vm->_script->_initialized) {
+	if (!_vm->_script->isInitialized()) {
 		return NULL;
 	}
 
@@ -62,7 +62,7 @@
 		return NULL;
 	}
 
-	new_node = ys_dll_add_head(_vm->_script->_thread_list, new_thread, sizeof *new_thread);
+	new_node = ys_dll_add_head(_vm->_script->threadList(), new_thread, sizeof *new_thread);
 
 	free(new_thread);
 
@@ -83,11 +83,11 @@
 	YS_DL_NODE *walk_p;
 	R_SCRIPT_THREAD *thread;
 
-	if (!_vm->_script->_initialized) {
+	if (!_vm->_script->isInitialized()) {
 		return R_FAILURE;
 	}
 
-	for (walk_p = ys_dll_head(_vm->_script->_thread_list); walk_p != NULL; walk_p = ys_dll_next(walk_p)) {
+	for (walk_p = ys_dll_head(_vm->_script->threadList()); walk_p != NULL; walk_p = ys_dll_next(walk_p)) {
 		thread = (R_SCRIPT_THREAD *)ys_dll_get_data(walk_p);
 		if (thread->executing) {
 			STHREAD_Run(thread, STHREAD_DEF_INSTR_COUNT, msec);
@@ -101,9 +101,9 @@
 	R_SCRIPT_BYTECODE *bytecode;
 	int max_entrypoint;
 
-	assert(_vm->_script->_initialized);
+	assert(_vm->_script->isInitialized());
 
-	bytecode = _vm->_script->_current_script->bytecode;
+	bytecode = _vm->_script->currentScript()->bytecode;
 	max_entrypoint = bytecode->n_entrypoints;
 
 	if ((ep_num < 0) || (ep_num >= max_entrypoint)) {
@@ -117,9 +117,9 @@
 }
 
 int STHREAD_Execute(R_SCRIPT_THREAD *thread, int ep_num) {
-	assert(_vm->_script->_initialized);
+	assert(_vm->_script->isInitialized());
 
-	if ((_vm->_script->_current_script == NULL) || (!_vm->_script->_current_script->loaded)) {
+	if ((_vm->_script->currentScript() == NULL) || (!_vm->_script->currentScript()->loaded)) {
 		return R_FAILURE;
 	}
 
@@ -132,15 +132,15 @@
 }
 
 unsigned char *GetReadPtr(R_SCRIPT_THREAD *thread) {
-	return _vm->_script->_current_script->bytecode->bytecode_p + thread->i_offset;
+	return _vm->_script->currentScript()->bytecode->bytecode_p + thread->i_offset;
 }
 
 unsigned long GetReadOffset(const byte *read_p) {
-	return (unsigned long)(read_p - (unsigned char *)_vm->_script->_current_script->bytecode->bytecode_p);
+	return (unsigned long)(read_p - (unsigned char *)_vm->_script->currentScript()->bytecode->bytecode_p);
 }
 
 size_t GetReadLen(R_SCRIPT_THREAD *thread) {
-	return _vm->_script->_current_script->bytecode->bytecode_len - thread->i_offset;
+	return _vm->_script->currentScript()->bytecode->bytecode_len - thread->i_offset;
 }
 
 
@@ -730,12 +730,12 @@
 					SSTACK_Pop(thread->stack, &data);
 					if (a_index < 0)
 						continue;
-					if (!_vm->_script->_voice_lut_present) {
+					if (!_vm->_script->isVoiceLUTPresent()) {
 						voice_rn = -1;
 					} else {
-						voice_rn = _vm->_script->_current_script->voice->voices[data];
+						voice_rn = _vm->_script->currentScript()->voice->voices[data];
 					}
-					ACTOR_Speak(a_index, _vm->_script->_current_script->diag-> str[data], voice_rn, &thread->sem);
+					ACTOR_Speak(a_index, _vm->_script->currentScript()->diag-> str[data], voice_rn, &thread->sem);
 				}
 			}
 			break;





More information about the Scummvm-git-logs mailing list