[Scummvm-cvs-logs] CVS: scummvm util.cpp,NONE,1.1 util.h,NONE,1.1 Makefile.common,1.13,1.14 gfx.h,1.10,1.11 newgui.cpp,1.21,1.22 newgui.h,1.16,1.17 scumm.h,1.186,1.187 sdl.cpp,1.133,1.134 sys.cpp,1.17,1.18 system.h,1.24,1.25
Max Horn
fingolfin at users.sourceforge.net
Wed Jul 17 13:56:06 CEST 2002
Update of /cvsroot/scummvm/scummvm
In directory usw-pr-cvs1:/tmp/cvs-serv20700
Modified Files:
Makefile.common gfx.h newgui.cpp newgui.h scumm.h sdl.cpp
sys.cpp system.h
Added Files:
util.cpp util.h
Log Message:
moved gui/utils.* to main level; removed some unused stuff from our file accessor functions
--- NEW FILE: util.cpp ---
/* ScummVM - Scumm Interpreter
* Copyright (C) 2002 The ScummVM project
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header: /cvsroot/scummvm/scummvm/util.cpp,v 1.1 2002/07/17 20:55:36 fingolfin Exp $
*/
#include "stdafx.h"
#include "util.h"
// 8-bit alpha blending routines
int BlendCache[256][256];
int RGBMatch(byte *palette, int r, int g, int b)
{
int i, bestidx = 0, besterr = 0xFFFFFF;
int error = 0;
for (i = 0;i < 256;i++) {
byte *pal = palette + (i * 3);
int r_diff = r - (int)*pal++;
int g_diff = g - (int)*pal++;
int b_diff = b - (int)*pal++;
r_diff *= r_diff; g_diff *= g_diff; b_diff *= b_diff;
error = r_diff + g_diff + b_diff;
if (error < besterr) {
besterr = error;
bestidx = i;
}
}
return bestidx;
}
int Blend(int src, int dst, byte *palette)
{
int r, g, b;
int alpha = 128; // Level of transparency [0-256]
byte *srcpal = palette + (dst * 3);
byte *dstpal = palette + (src * 3);
if (BlendCache[dst][src] > -1)
return BlendCache[dst][src];
r = (*srcpal++ * alpha);
r += (*dstpal++ * (256-alpha));
r /= 256;
g = (*srcpal++ * alpha);
g += (*dstpal++ * (256-alpha));
g /= 256;
b = (*srcpal++ * alpha);
b += (*dstpal++ * (256-alpha));
b /= 256;
return (BlendCache[dst][src] = RGBMatch(palette, r , g , b ));
}
void ClearBlendCache(byte *palette, int weight)
{
for (int i = 0; i < 256; i++)
for (int j = 0 ; j < 256 ; j++)
// BlendCache[i][j] = i; // No alphablending
// BlendCache[i][j] = j; // 100% translucent
BlendCache[i][j] = -1; // Enable alphablending
}
#pragma mark -
String::String(const char *str)
{
_capacity = _len = strlen(str);
_str = (char *)calloc(1, _capacity+1);
memcpy(_str, str, _len+1);
}
String::String(const String &str)
{
_capacity = str._capacity;
_len = str._len;
_str = (char *)calloc(1, _capacity+1);
memcpy(_str, str._str, _len+1);
}
String::~String()
{
if (_str)
free(_str);
}
String& String::operator =(const char* str)
{
int len = strlen(str);
ensureCapacity(len, false);
_len = len;
if (_str)
memcpy(_str, str, _len + 1);
return *this;
}
String& String::operator =(const String& str)
{
int len = str._len;
ensureCapacity(len, false);
_len = len;
if (_str)
memcpy(_str, str._str, _len + 1);
return *this;
}
String& String::operator +=(const char* str)
{
int len = strlen(str);
ensureCapacity(_len + len, true);
if (_str)
memcpy(_str + _len, str, len + 1);
_len += len;
return *this;
}
String& String::operator +=(const String& str)
{
int len = str._len;
ensureCapacity(_len + len, true);
if (_str && str._str)
memcpy(_str + _len, str._str, len + 1);
_len += len;
return *this;
}
String& String::operator +=(char c)
{
int len = _len + 1;
ensureCapacity(len, true);
_str[_len++] = c;
_str[_len] = 0;
return *this;
}
void String::deleteLastChar() {
if (_len > 0) {
_len--;
_str[_len]=0;
}
}
void String::clear()
{
if (_str)
free(_str);
_capacity = 0;
_len = 0;
_str = 0;
}
void String::ensureCapacity(int new_len, bool keep_old)
{
if (new_len <= _capacity)
return;
char *old_str = _str;
_capacity = new_len + 32;
_str = (char *)calloc(1, _capacity+1);
if (old_str) {
if (keep_old)
memcpy(_str, old_str, _len+1);
free(old_str);
}
}
--- NEW FILE: util.h ---
/* ScummVM - Scumm Interpreter
* Copyright (C) 2002 The ScummVM project
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header: /cvsroot/scummvm/scummvm/util.h,v 1.1 2002/07/17 20:55:36 fingolfin Exp $
*/
#ifndef UTIL_H
#define UTIL_H
#include "scummsys.h"
int RGBMatch(byte *palette, int r, int g, int b);
int Blend(int src, int dst, byte *palette);
void ClearBlendCache(byte *palette, int weight);
template <class T>
class List {
protected:
int _capacity;
int _size;
T *_data;
public:
List<T>() : _capacity(0), _size(0), _data(0) {}
List<T>(const List<T>& list) : _capacity(0), _size(0), _data(0)
{
_size = list._size;
_capacity = _size + 32;
_data = new T[_capacity];
for (int i = 0; i < _size; i++)
_data[i] = list._data[i];
}
~List<T>()
{
if (_data)
delete [] _data;
}
void push_back(const T& str)
{
ensureCapacity(_size + 1);
_data[_size++] = str;
}
// TODO: insert, remove, ...
T& operator [](int idx)
{
assert(idx >= 0 && idx < _size);
return _data[idx];
}
const T& operator [](int idx) const
{
assert(idx >= 0 && idx < _size);
return _data[idx];
}
List<T>& operator =(const List<T>& list)
{
if (_data)
delete [] _data;
_size = list._size;
_capacity = _size + 32;
_data = new T[_capacity];
for (int i = 0; i < _size; i++)
_data[i] = list._data[i];
return *this;
}
int size() const { return _size; }
void clear()
{
if (_data) {
delete [] _data;
_data = 0;
}
_size = 0;
_capacity = 0;
}
protected:
void ensureCapacity(int new_len)
{
if (new_len <= _capacity)
return;
T *old_data = _data;
_capacity = new_len + 32;
_data = new T[_capacity];
if (old_data) {
// Copy old data
for (int i = 0; i < _size; i++)
_data[i] = old_data[i];
delete [] old_data;
}
}
};
class String {
protected:
int _capacity;
int _len;
char *_str;
public:
String() : _capacity(0), _len(0), _str(0) {}
String(const char *str);
String(const String &str);
~String();
String& operator =(const char* str);
String& operator =(const String& str);
String& operator +=(const char* str);
String& operator +=(const String& str);
String& operator +=(char c);
// operator char *() { return _str; }
operator const char *() const { return _str; }
const char *c_str() const { return _str; }
int size() const { return _len; }
void deleteLastChar();
void clear();
protected:
void ensureCapacity(int new_len, bool keep_old);
};
class StringList : public List<String> {
public:
void push_back(const char* str)
{
ensureCapacity(_size + 1);
_data[_size++] = str;
}
};
#endif
Index: Makefile.common
===================================================================
RCS file: /cvsroot/scummvm/scummvm/Makefile.common,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- Makefile.common 16 Jul 2002 11:17:31 -0000 1.13
+++ Makefile.common 17 Jul 2002 20:55:35 -0000 1.14
@@ -6,7 +6,7 @@
INCS = scumm.h scummsys.h stdafx.h
-OBJS += gui/widget.o gui/dialog.o gui/util.o newgui.o \
+OBJS += util.o newgui.o gui/widget.o gui/dialog.o \
gui/ListWidget.o gui/ScrollBarWidget.o \
actor.o boxes.o costume.o gfx.o object.o resource.o \
saveload.o script.o scummvm.o sound.o string.o \
Index: gfx.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gfx.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- gfx.h 27 Jun 2002 14:10:56 -0000 1.10
+++ gfx.h 17 Jul 2002 20:55:35 -0000 1.11
@@ -20,6 +20,10 @@
*
*/
+#ifndef GFX_H
+#define GFX_H
+
+
enum VideoMode { /* Video scalers */
VIDEO_SCALE = 0,
VIDEO_2XSAI = 1,
@@ -180,3 +184,7 @@
dbClear = 4
};
};
+
+void blit(byte *dst, byte *src, int w, int h);
+
+#endif
Index: newgui.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/newgui.cpp,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- newgui.cpp 16 Jul 2002 21:18:06 -0000 1.21
+++ newgui.cpp 17 Jul 2002 20:55:35 -0000 1.22
@@ -23,7 +23,7 @@
#include "newgui.h"
#include "guimaps.h"
#include "gui/dialog.h"
-#include "gui/util.h"
+#include "util.h"
/*
* TODO list
Index: newgui.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/newgui.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- newgui.h 16 Jul 2002 17:37:12 -0000 1.16
+++ newgui.h 17 Jul 2002 20:55:36 -0000 1.17
@@ -23,7 +23,7 @@
#include "scummsys.h"
#include "system.h" // For events
-#include "gui/util.h"
+#include "util.h"
class Dialog;
class Scumm;
Index: scumm.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm.h,v
retrieving revision 1.186
retrieving revision 1.187
diff -u -d -r1.186 -r1.187
--- scumm.h 16 Jul 2002 21:03:13 -0000 1.186
+++ scumm.h 17 Jul 2002 20:55:36 -0000 1.187
@@ -53,12 +53,6 @@
/* System Wide Constants */
enum {
-#ifdef _WIN32_WCE
- SAMPLES_PER_SEC = 11025,
-#else
- SAMPLES_PER_SEC = 22050,
-#endif
- BITS_PER_SAMPLE = 16,
NUM_MIXER = 4,
NUM_SCRIPT_SLOT = 40,
NUM_LOCALSCRIPT = 60,
@@ -1022,8 +1016,6 @@
/* Should be in System class */
- byte _fileMode;
- uint32 _whereInResToRead;
void fileClose(void *file);
void *fileOpen(const char *filename, int mode);
void fileSeek(void *file, long offs, int whence);
@@ -1499,6 +1491,5 @@
void CDECL warning(const char *s, ...);
void CDECL debug(int level, const char *s, ...);
void checkHeap();
-void blit(byte *dst, byte *src, int w, int h);
#endif
Index: sdl.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sdl.cpp,v
retrieving revision 1.133
retrieving revision 1.134
diff -u -d -r1.133 -r1.134
--- sdl.cpp 16 Jul 2002 21:18:02 -0000 1.133
+++ sdl.cpp 17 Jul 2002 20:55:36 -0000 1.134
@@ -23,15 +23,15 @@
#include "stdafx.h"
#include "scummsys.h"
#include "system.h"
-#include "scumm.h" // FIXME: remove this! Only needed for SAMPLES_PER_SEC, error() and warning()
#include "mididrv.h"
-#include "SDL_thread.h"
#include "gameDetector.h"
#include "scaler.h"
+#include "scumm.h" // Only #included for error() and warning()
#include "scummvm.xpm"
#include <SDL.h>
+#include <SDL_thread.h>
#define MAX(a,b) (((a)<(b)) ? (b) : (a))
#define MIN(a,b) (((a)>(b)) ? (b) : (a))
Index: sys.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sys.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- sys.cpp 16 Jul 2002 21:03:13 -0000 1.17
+++ sys.cpp 17 Jul 2002 20:55:36 -0000 1.18
@@ -25,23 +25,18 @@
void *Scumm::fileOpen(const char *filename, int mode)
{
- _fileMode = mode;
- _whereInResToRead = 0;
clearFileReadFailed(_fileHandle);
if (mode == 1)
return fopen(filename, "rb");
- if (mode == 2) {
- error("fileOpen: write not supported");
- }
-
+ error("This should not happen!");
return NULL;
}
void Scumm::fileClose(void *file)
{
- if (_fileMode == 1 || _fileMode == 2)
+ if (file)
fclose((FILE *)file);
}
@@ -67,49 +62,25 @@
void Scumm::fileSeek(void *file, long offs, int whence)
{
- switch (_fileMode) {
- case 1:
- case 2:
- if (fseek((FILE *)file, offs, whence) != 0)
- clearerr((FILE *)file);
- return;
- case 3:
- _whereInResToRead = offs;
- return;
- }
+ if (fseek((FILE *)file, offs, whence) != 0)
+ clearerr((FILE *)file);
}
void Scumm::fileRead(void *file, void *ptr, uint32 size)
{
byte *ptr2 = (byte *)ptr, *src;
- switch (_fileMode) {
- case 1:
- if (size == 0)
- return;
-
- if ((uint32)fread(ptr2, size, 1, (FILE *)file) != 1) {
- clearerr((FILE *)file);
- _fileReadFailed = true;
- }
-
- do {
- *ptr2++ ^= _encbyte;
- } while (--size);
-
+ if (size == 0)
return;
- case 3:
- if (size == 0)
- return;
-
- src = getResourceAddress(rtTemp, 3) + _whereInResToRead;
- _whereInResToRead += size;
- do {
- *ptr2++ = *src++ ^ _encbyte;
- } while (--size);
- return;
+ if ((uint32)fread(ptr2, size, 1, (FILE *)file) != 1) {
+ clearerr((FILE *)file);
+ _fileReadFailed = true;
}
+
+ do {
+ *ptr2++ ^= _encbyte;
+ } while (--size);
}
int Scumm::fileReadByte()
@@ -117,20 +88,11 @@
byte b;
byte *src;
- switch (_fileMode) {
- case 1:
- if (fread(&b, 1, 1, (FILE *)_fileHandle) != 1) {
- clearerr((FILE *)_fileHandle);
- _fileReadFailed = true;
- }
- return b ^ _encbyte;
-
- case 3:
- src = getResourceAddress(rtTemp, 3) + _whereInResToRead;
- _whereInResToRead++;
- return *src ^ _encbyte;
+ if (fread(&b, 1, 1, (FILE *)_fileHandle) != 1) {
+ clearerr((FILE *)_fileHandle);
+ _fileReadFailed = true;
}
- return 0;
+ return b ^ _encbyte;
}
uint Scumm::fileReadWordLE()
Index: system.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/system.h,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- system.h 16 Jul 2002 21:18:01 -0000 1.24
+++ system.h 17 Jul 2002 20:55:36 -0000 1.25
@@ -188,4 +188,12 @@
GD_DC
};
+enum {
+#ifdef _WIN32_WCE
+ SAMPLES_PER_SEC = 11025
+#else
+ SAMPLES_PER_SEC = 22050
+#endif
+};
+
#endif
More information about the Scummvm-git-logs
mailing list