changes and fixes for ps2
This commit is contained in:
parent
5501c4fdc7
commit
453ae4b9ee
26
src/base.cpp
26
src/base.cpp
@ -999,7 +999,7 @@ StreamFile*
|
|||||||
StreamFile::open(const char *path, const char *mode)
|
StreamFile::open(const char *path, const char *mode)
|
||||||
{
|
{
|
||||||
assert(this->file == nil);
|
assert(this->file == nil);
|
||||||
this->file = fopen(path, mode);
|
this->file = engine->filefuncs.rwfopen(path, mode);
|
||||||
if(this->file == nil){
|
if(this->file == nil){
|
||||||
RWERROR((ERR_FILE, path));
|
RWERROR((ERR_FILE, path));
|
||||||
return nil;
|
return nil;
|
||||||
@ -1011,38 +1011,38 @@ void
|
|||||||
StreamFile::close(void)
|
StreamFile::close(void)
|
||||||
{
|
{
|
||||||
assert(this->file);
|
assert(this->file);
|
||||||
fclose(this->file);
|
engine->filefuncs.rwfclose(this->file);
|
||||||
this->file = nil;
|
this->file = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32
|
uint32
|
||||||
StreamFile::write8(const void *data, uint32 length)
|
StreamFile::write8(const void *data, uint32 length)
|
||||||
{
|
{
|
||||||
return (uint32)fwrite(data, 1, length, this->file);
|
return (uint32)engine->filefuncs.rwfwrite(data, 1, length, this->file);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32
|
uint32
|
||||||
StreamFile::read8(void *data, uint32 length)
|
StreamFile::read8(void *data, uint32 length)
|
||||||
{
|
{
|
||||||
return (uint32)fread(data, 1, length, this->file);
|
return (uint32)engine->filefuncs.rwfread(data, 1, length, this->file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
StreamFile::seek(int32 offset, int32 whence)
|
StreamFile::seek(int32 offset, int32 whence)
|
||||||
{
|
{
|
||||||
fseek(this->file, offset, whence);
|
engine->filefuncs.rwfseek(this->file, offset, whence);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32
|
uint32
|
||||||
StreamFile::tell(void)
|
StreamFile::tell(void)
|
||||||
{
|
{
|
||||||
return ftell(this->file);
|
return engine->filefuncs.rwftell(this->file);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
StreamFile::eof(void)
|
StreamFile::eof(void)
|
||||||
{
|
{
|
||||||
return ( feof(this->file) != 0 );
|
return engine->filefuncs.rwfeof(this->file) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@ -1106,15 +1106,15 @@ findPointer(void *p, void **list, int32 num)
|
|||||||
uint8*
|
uint8*
|
||||||
getFileContents(const char *name, uint32 *len)
|
getFileContents(const char *name, uint32 *len)
|
||||||
{
|
{
|
||||||
FILE *cf = fopen(name, "rb");
|
void *cf = engine->filefuncs.rwfopen(name, "rb");
|
||||||
if(cf == nil)
|
if(cf == nil)
|
||||||
return nil;
|
return nil;
|
||||||
fseek(cf, 0, SEEK_END);
|
engine->filefuncs.rwfseek(cf, 0, SEEK_END);
|
||||||
*len = ftell(cf);
|
*len = engine->filefuncs.rwftell(cf);
|
||||||
fseek(cf, 0, SEEK_SET);
|
engine->filefuncs.rwfseek(cf, 0, SEEK_SET);
|
||||||
uint8 *data = rwNewT(uint8, *len, MEMDUR_EVENT);
|
uint8 *data = rwNewT(uint8, *len, MEMDUR_EVENT);
|
||||||
fread(data, 1, *len, cf);
|
engine->filefuncs.rwfread(data, 1, *len, cf);
|
||||||
fclose(cf);
|
engine->filefuncs.rwfclose(cf);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,6 +254,13 @@ Engine::open(EngineOpenParams *p)
|
|||||||
engine = (Engine*)rwNew(Engine::s_plglist.size, MEMDUR_GLOBAL);
|
engine = (Engine*)rwNew(Engine::s_plglist.size, MEMDUR_GLOBAL);
|
||||||
engine->currentCamera = nil;
|
engine->currentCamera = nil;
|
||||||
engine->currentWorld = nil;
|
engine->currentWorld = nil;
|
||||||
|
engine->filefuncs.rwfopen = (void *(*)(const char*, const char*))fopen;
|
||||||
|
engine->filefuncs.rwfclose = (int (*)(void*))fclose;
|
||||||
|
engine->filefuncs.rwfseek = (int (*)(void*, long, int))fseek;
|
||||||
|
engine->filefuncs.rwftell = (long (*)(void*))ftell;
|
||||||
|
engine->filefuncs.rwfread = (size_t (*)(void*, size_t, size_t, void*))fread;
|
||||||
|
engine->filefuncs.rwfwrite = (size_t (*)(const void*, size_t, size_t, void*))fwrite;
|
||||||
|
engine->filefuncs.rwfeof = (int (*)(void*))feof;
|
||||||
|
|
||||||
// Initialize device
|
// Initialize device
|
||||||
// Device and possibly OS specific!
|
// Device and possibly OS specific!
|
||||||
|
@ -931,15 +931,15 @@ char*
|
|||||||
Image::getFilename(const char *name)
|
Image::getFilename(const char *name)
|
||||||
{
|
{
|
||||||
ImageGlobals *g = PLUGINOFFSET(ImageGlobals, engine, imageModuleOffset);
|
ImageGlobals *g = PLUGINOFFSET(ImageGlobals, engine, imageModuleOffset);
|
||||||
FILE *f;
|
void *f;
|
||||||
char *s, *p = g->searchPaths;
|
char *s, *p = g->searchPaths;
|
||||||
size_t len = strlen(name)+1;
|
size_t len = strlen(name)+1;
|
||||||
if(g->numSearchPaths == 0){
|
if(g->numSearchPaths == 0){
|
||||||
s = rwStrdup(name, MEMDUR_EVENT);
|
s = rwStrdup(name, MEMDUR_EVENT);
|
||||||
makePath(s);
|
makePath(s);
|
||||||
f = fopen(s, "rb");
|
f = engine->filefuncs.rwfopen(s, "rb");
|
||||||
if(f){
|
if(f){
|
||||||
fclose(f);
|
engine->filefuncs.rwfclose(f);
|
||||||
printf("found %s\n", s);
|
printf("found %s\n", s);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
@ -955,9 +955,9 @@ Image::getFilename(const char *name)
|
|||||||
strcpy(s, p);
|
strcpy(s, p);
|
||||||
strcat(s, name);
|
strcat(s, name);
|
||||||
makePath(s);
|
makePath(s);
|
||||||
f = fopen(s, "r");
|
f = engine->filefuncs.rwfopen(s, "r");
|
||||||
if(f){
|
if(f){
|
||||||
fclose(f);
|
engine->filefuncs.rwfclose(f);
|
||||||
printf("found %s\n", name);
|
printf("found %s\n", name);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
@ -1219,7 +1219,7 @@ rasterCreateTexture(Raster *raster)
|
|||||||
// this obviously only works with 32 bit pointers, but it's only needed on the PS2 anyway
|
// this obviously only works with 32 bit pointers, but it's only needed on the PS2 anyway
|
||||||
*xferchain++ = (uint32)(uintptr)p - 0x50;
|
*xferchain++ = (uint32)(uintptr)p - 0x50;
|
||||||
*xferchain++ = 0; // VIF nop
|
*xferchain++ = 0; // VIF nop
|
||||||
*xferchain++ = 0x50000000 | sz+5; // VIF DIRECT 2 qwords
|
*xferchain++ = 0x50000000 | sz+5; // VIF DIRECT
|
||||||
}else{
|
}else{
|
||||||
// Add to existing transfer
|
// Add to existing transfer
|
||||||
xferchain[-4] = 0x30000000 | (xferchain[-4]&0xFFFF) + sz+5; // last DMAref
|
xferchain[-4] = 0x30000000 | (xferchain[-4]&0xFFFF) + sz+5; // last DMAref
|
||||||
@ -1243,7 +1243,7 @@ rasterCreateTexture(Raster *raster)
|
|||||||
*p++ = 0;
|
*p++ = 0;
|
||||||
|
|
||||||
// TRXPOS
|
// TRXPOS
|
||||||
*(uint64*)p = paltrxpos;
|
*(uint64*)p = (uint64)paltrxpos<<32;
|
||||||
p += 2;
|
p += 2;
|
||||||
*p++ = 0x51;
|
*p++ = 0x51;
|
||||||
*p++ = 0;
|
*p++ = 0;
|
||||||
@ -1291,10 +1291,10 @@ rasterCreateTexture(Raster *raster)
|
|||||||
xferchain[1] = xferchain[-15];
|
xferchain[1] = xferchain[-15];
|
||||||
xferchain[2] = xferchain[-14];
|
xferchain[2] = xferchain[-14];
|
||||||
xferchain[3] = xferchain[-13];
|
xferchain[3] = xferchain[-13];
|
||||||
|
xferchain += 4;
|
||||||
// Add to last transfer
|
// Add to last transfer
|
||||||
xferchain[-16] = 0x30000000 | (xferchain[-16]&0xFFFF) + sz+5; // last DMAref
|
xferchain[-16] = 0x30000000 | (xferchain[-16]&0xFFFF) + sz+5; // last DMAref
|
||||||
xferchain[-13] = 0x50000000 | (xferchain[-13]&0xFFFF) + sz+5; // last DIRECT
|
xferchain[-13] = 0x50000000 | (xferchain[-13]&0xFFFF) + sz+5; // last DIRECT
|
||||||
xferchain += 4;
|
|
||||||
pp->numTransfers--;
|
pp->numTransfers--;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1302,7 +1302,7 @@ rasterCreateTexture(Raster *raster)
|
|||||||
// this obviously only works with 32 bit pointers, but it's only needed on the PS2 anyway
|
// this obviously only works with 32 bit pointers, but it's only needed on the PS2 anyway
|
||||||
*xferchain++ = (uint32)(uintptr)p - 0x50;
|
*xferchain++ = (uint32)(uintptr)p - 0x50;
|
||||||
*xferchain++ = 0; // VIF nop
|
*xferchain++ = 0; // VIF nop
|
||||||
*xferchain++ = 0x50000000 | sz+5; // VIF DIRECT 2 qwords
|
*xferchain++ = 0x50000000 | sz+5; // VIF DIRECT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
raster->originalPixels = raster->pixels;
|
raster->originalPixels = raster->pixels;
|
||||||
|
@ -38,6 +38,28 @@ struct Im2DVertex
|
|||||||
float getV(void) { return this->v; }
|
float getV(void) { return this->v; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Im3DVertex
|
||||||
|
{
|
||||||
|
V3d position;
|
||||||
|
uint8 r, g, b, a;
|
||||||
|
float32 u, v;
|
||||||
|
|
||||||
|
void setX(float32 x) { this->position.x = x; }
|
||||||
|
void setY(float32 y) { this->position.y = y; }
|
||||||
|
void setZ(float32 z) { this->position.z = z; }
|
||||||
|
void setColor(uint8 r, uint8 g, uint8 b, uint8 a) {
|
||||||
|
this->r = r; this->g = g; this->b = b; this->a = a; }
|
||||||
|
void setU(float32 u) { this->u = u; }
|
||||||
|
void setV(float32 v) { this->v = v; }
|
||||||
|
|
||||||
|
float getX(void) { return this->position.x; }
|
||||||
|
float getY(void) { return this->position.y; }
|
||||||
|
float getZ(void) { return this->position.z; }
|
||||||
|
RGBA getColor(void) { return makeRGBA(this->r, this->g, this->b, this->a); }
|
||||||
|
float getU(void) { return this->u; }
|
||||||
|
float getV(void) { return this->v; }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
struct InstanceData
|
struct InstanceData
|
||||||
{
|
{
|
||||||
|
15
src/rwbase.h
15
src/rwbase.h
@ -151,7 +151,7 @@ struct RGBA
|
|||||||
uint8 blue;
|
uint8 blue;
|
||||||
uint8 alpha;
|
uint8 alpha;
|
||||||
};
|
};
|
||||||
inline RGBA makeRGBA(uint8 r, uint8 g, uint8 b, uint8 a) { RGBA c = { r, g, b, a }; return c; }
|
inline RGBA makeRGBA(uint8 r, uint8 g, uint8 b, uint8 a) { RGBA c; c.red = r; c.green = g; c.blue = b; c.alpha = a; return c; }
|
||||||
inline bool32 equal(const RGBA &c1, const RGBA &c2) { return c1.red == c2.red && c1.green == c2.green && c1.blue == c2.blue && c1.alpha == c2.alpha; }
|
inline bool32 equal(const RGBA &c1, const RGBA &c2) { return c1.red == c2.red && c1.green == c2.green && c1.blue == c2.blue && c1.alpha == c2.alpha; }
|
||||||
#define RWRGBAINT(r, g, b, a) ((uint32)((((a)&0xff)<<24)|(((b)&0xff)<<16)|(((g)&0xff)<<8)|((r)&0xff)))
|
#define RWRGBAINT(r, g, b, a) ((uint32)((((a)&0xff)<<24)|(((b)&0xff)<<16)|(((g)&0xff)<<8)|((r)&0xff)))
|
||||||
|
|
||||||
@ -162,7 +162,7 @@ struct RGBAf
|
|||||||
float32 blue;
|
float32 blue;
|
||||||
float32 alpha;
|
float32 alpha;
|
||||||
};
|
};
|
||||||
inline RGBAf makeRGBAf(float32 r, float32 g, float32 b, float32 a) { RGBAf c = { r, g, b, a }; return c; }
|
inline RGBAf makeRGBAf(float32 r, float32 g, float32 b, float32 a) { RGBAf c; c.red = r; c.green = g; c.blue = b; c.alpha = a; return c; }
|
||||||
inline bool32 equal(const RGBAf &c1, const RGBAf &c2) { return c1.red == c2.red && c1.green == c2.green && c1.blue == c2.blue && c1.alpha == c2.alpha; }
|
inline bool32 equal(const RGBAf &c1, const RGBAf &c2) { return c1.red == c2.red && c1.green == c2.green && c1.blue == c2.blue && c1.alpha == c2.alpha; }
|
||||||
inline RGBAf add(const RGBAf &a, const RGBAf &b) { return makeRGBAf(a.red+b.red, a.green+b.green, a.blue+b.blue, a.alpha+b.alpha); }
|
inline RGBAf add(const RGBAf &a, const RGBAf &b) { return makeRGBAf(a.red+b.red, a.green+b.green, a.blue+b.blue, a.alpha+b.alpha); }
|
||||||
inline RGBAf modulate(const RGBAf &a, const RGBAf &b) { return makeRGBAf(a.red*b.red, a.green*b.green, a.blue*b.blue, a.alpha*b.alpha); }
|
inline RGBAf modulate(const RGBAf &a, const RGBAf &b) { return makeRGBAf(a.red*b.red, a.green*b.green, a.blue*b.blue, a.alpha*b.alpha); }
|
||||||
@ -215,7 +215,7 @@ struct V2d
|
|||||||
this->x = x; this->y = y; }
|
this->x = x; this->y = y; }
|
||||||
};
|
};
|
||||||
|
|
||||||
inline V2d makeV2d(float32 x, float32 y) { V2d v = { x, y }; return v; }
|
inline V2d makeV2d(float32 x, float32 y) { V2d v; v.x = x; v.y = y; return v; }
|
||||||
inline bool32 equal(const V2d &v1, const V2d &v2) { return v1.x == v2.x && v1.y == v2.y; }
|
inline bool32 equal(const V2d &v1, const V2d &v2) { return v1.x == v2.x && v1.y == v2.y; }
|
||||||
inline V2d neg(const V2d &a) { return makeV2d(-a.x, -a.y); }
|
inline V2d neg(const V2d &a) { return makeV2d(-a.x, -a.y); }
|
||||||
inline V2d add(const V2d &a, const V2d &b) { return makeV2d(a.x+b.x, a.y+b.y); }
|
inline V2d add(const V2d &a, const V2d &b) { return makeV2d(a.x+b.x, a.y+b.y); }
|
||||||
@ -233,7 +233,7 @@ struct V3d
|
|||||||
static void transformVectors(V3d *out, const V3d *in, int32 n, const Matrix *m);
|
static void transformVectors(V3d *out, const V3d *in, int32 n, const Matrix *m);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline V3d makeV3d(float32 x, float32 y, float32 z) { V3d v = { x, y, z }; return v; }
|
inline V3d makeV3d(float32 x, float32 y, float32 z) { V3d v; v.x = x; v.y = y; v.z = z; return v; }
|
||||||
inline bool32 equal(const V3d &v1, const V3d &v2) { return v1.x == v2.x && v1.y == v2.y && v1.z == v2.z; }
|
inline bool32 equal(const V3d &v1, const V3d &v2) { return v1.x == v2.x && v1.y == v2.y && v1.z == v2.z; }
|
||||||
inline V3d neg(const V3d &a) { return makeV3d(-a.x, -a.y, -a.z); }
|
inline V3d neg(const V3d &a) { return makeV3d(-a.x, -a.y, -a.z); }
|
||||||
inline V3d add(const V3d &a, const V3d &b) { return makeV3d(a.x+b.x, a.y+b.y, a.z+b.z); }
|
inline V3d add(const V3d &a, const V3d &b) { return makeV3d(a.x+b.x, a.y+b.y, a.z+b.z); }
|
||||||
@ -281,8 +281,8 @@ struct Quat
|
|||||||
Quat *rotate(const V3d *axis, float32 angle, CombineOp op = rw::COMBINEPOSTCONCAT);
|
Quat *rotate(const V3d *axis, float32 angle, CombineOp op = rw::COMBINEPOSTCONCAT);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline Quat makeQuat(float32 w, float32 x, float32 y, float32 z) { Quat q = { x, y, z, w }; return q; }
|
inline Quat makeQuat(float32 w, float32 x, float32 y, float32 z) { Quat q; q.x = x; q.y = y; q.z = z; q.w = w; return q; }
|
||||||
inline Quat makeQuat(float32 w, const V3d &vec) { Quat q = { vec.x, vec.y, vec.z, w }; return q; }
|
inline Quat makeQuat(float32 w, const V3d &vec) { return makeQuat(w, vec.x, vec.y, vec.z); }
|
||||||
inline Quat add(const Quat &q, const Quat &p) { return makeQuat(q.w+p.w, q.x+p.x, q.y+p.y, q.z+p.z); }
|
inline Quat add(const Quat &q, const Quat &p) { return makeQuat(q.w+p.w, q.x+p.x, q.y+p.y, q.z+p.z); }
|
||||||
inline Quat sub(const Quat &q, const Quat &p) { return makeQuat(q.w-p.w, q.x-p.x, q.y-p.y, q.z-p.z); }
|
inline Quat sub(const Quat &q, const Quat &p) { return makeQuat(q.w-p.w, q.x-p.x, q.y-p.y, q.z-p.z); }
|
||||||
inline Quat negate(const Quat &q) { return makeQuat(-q.w, -q.x, -q.y, -q.z); }
|
inline Quat negate(const Quat &q) { return makeQuat(-q.w, -q.x, -q.y, -q.z); }
|
||||||
@ -509,9 +509,8 @@ public:
|
|||||||
|
|
||||||
class StreamFile : public Stream
|
class StreamFile : public Stream
|
||||||
{
|
{
|
||||||
|
void *file;
|
||||||
public:
|
public:
|
||||||
FILE *file;
|
|
||||||
|
|
||||||
StreamFile(void) { file = nil; }
|
StreamFile(void) { file = nil; }
|
||||||
void close(void);
|
void close(void);
|
||||||
uint32 write8(const void *data, uint32 length);
|
uint32 write8(const void *data, uint32 length);
|
||||||
|
@ -121,6 +121,17 @@ struct MemoryFunctions
|
|||||||
void *(*rwmustrealloc)(void *p, size_t sz, uint32 hint);
|
void *(*rwmustrealloc)(void *p, size_t sz, uint32 hint);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct FileFunctions
|
||||||
|
{
|
||||||
|
void *(*rwfopen)(const char *path, const char *mode);
|
||||||
|
int (*rwfclose)(void *fp);
|
||||||
|
int (*rwfseek)(void *fp, long offset, int whence);
|
||||||
|
long (*rwftell)(void *fp);
|
||||||
|
size_t (*rwfread)(void *ptr, size_t size, size_t nmemb, void *fp);
|
||||||
|
size_t (*rwfwrite)(const void *ptr, size_t size, size_t nmemb, void *fp);
|
||||||
|
int (*rwfeof)(void *fp);
|
||||||
|
};
|
||||||
|
|
||||||
struct SubSystemInfo
|
struct SubSystemInfo
|
||||||
{
|
{
|
||||||
char name[80];
|
char name[80];
|
||||||
@ -155,6 +166,7 @@ struct Engine
|
|||||||
Camera *currentCamera;
|
Camera *currentCamera;
|
||||||
World *currentWorld;
|
World *currentWorld;
|
||||||
LinkList frameDirtyList;
|
LinkList frameDirtyList;
|
||||||
|
FileFunctions filefuncs;
|
||||||
|
|
||||||
// Dynamically allocated because of plugins
|
// Dynamically allocated because of plugins
|
||||||
Driver *driver[NUM_PLATFORMS];
|
Driver *driver[NUM_PLATFORMS];
|
||||||
|
Loading…
Reference in New Issue
Block a user