Changed naming convention and clean up somewhat. ps2 test no longer links :(

This commit is contained in:
Angelo Papenhoff 2015-01-25 22:27:03 +01:00
parent 535b9f0042
commit d55e9ea43b
21 changed files with 359 additions and 354 deletions

View File

@ -2,7 +2,6 @@
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <new>
#include "rw.h"
@ -13,66 +12,66 @@ using namespace std;
int
main(int argc, char *argv[])
{
// Rw::Version = 0x31000;
// Rw::Build = 0;
// rw::version = 0x31000;
// rw::build = 0;
// Rw::Version = 0x33002;
// rw::version = 0x33002;
Rw::RegisterEnvSpecPlugin();
Rw::RegisterMatFXPlugin();
Rw::RegisterMaterialRightsPlugin();
Rw::RegisterAtomicRightsPlugin();
Rw::RegisterHAnimPlugin();
Rw::RegisterNodeNamePlugin();
Rw::RegisterBreakableModelPlugin();
Rw::RegisterExtraVertColorPlugin();
Rw::Ps2::RegisterADCPlugin();
Rw::RegisterSkinPlugin();
Rw::RegisterNativeDataPlugin();
// Rw::Ps2::RegisterNativeDataPlugin();
Rw::RegisterMeshPlugin();
gta::registerEnvSpecPlugin();
rw::registerMatFXPlugin();
rw::registerMaterialRightsPlugin();
rw::registerAtomicRightsPlugin();
rw::registerHAnimPlugin();
gta::registerNodeNamePlugin();
gta::registerBreakableModelPlugin();
gta::registerExtraVertColorPlugin();
rw::ps2::registerADCPlugin();
rw::registerSkinPlugin();
rw::registerNativeDataPlugin();
// rw::ps2::registerNativeDataPlugin();
rw::registerMeshPlugin();
Rw::Clump *c;
rw::Clump *c;
// ifstream in(argv[1], ios::binary);
// Rw::StreamFile in;
// rw::StreamFile in;
// in.open(argv[1], "rb");
FILE *cf = fopen(argv[1], "rb");
assert(cf != NULL);
fseek(cf, 0, SEEK_END);
Rw::uint32 len = ftell(cf);
rw::uint32 len = ftell(cf);
fseek(cf, 0, SEEK_SET);
Rw::uint8 *data = new Rw::uint8[len];
rw::uint8 *data = new rw::uint8[len];
fread(data, len, 1, cf);
fclose(cf);
Rw::StreamMemory in;
rw::StreamMemory in;
in.open(data, len);
Rw::FindChunk(&in, Rw::ID_CLUMP, NULL, NULL);
Rw::DebugFile = argv[1];
c = Rw::Clump::streamRead(&in);
rw::findChunk(&in, rw::ID_CLUMP, NULL, NULL);
rw::debugFile = argv[1];
c = rw::Clump::streamRead(&in);
assert(c != NULL);
in.close();
delete[] data;
Rw::Image::setSearchPath("./;/home/aap/gamedata/ps2/gtavc/MODELS/gta3_archive/txd_extracted/");
rw::Image::setSearchPath("./;/home/aap/gamedata/ps2/gtavc/MODELS/gta3_archive/txd_extracted/");
// Rw::Image *tga = Rw::readTGA("b.tga");
Rw::Image *tga = Rw::readTGA("player.tga");
// rw::Image *tga = rw::readTGA("b.tga");
rw::Image *tga = rw::readTGA("player.tga");
assert(tga != NULL);
Rw::writeTGA(tga, "out.tga");
rw::writeTGA(tga, "out.tga");
// for(Rw::int32 i = 0; i < c->numAtomics; i++)
// Rw::Gl::Instance(c->atomicList[i]);
// for(rw::int32 i = 0; i < c->numAtomics; i++)
// rw::Gl::Instance(c->atomicList[i]);
// ofstream out(argv[2], ios::binary);
// Rw::StreamFile out;
// rw::StreamFile out;
// out.open(argv[2], "wb");
data = new Rw::uint8[256*1024];
Rw::StreamMemory out;
data = new rw::uint8[256*1024];
rw::StreamMemory out;
out.open(data, 0, 256*1024);
c->streamWrite(&out);

View File

@ -11,7 +11,7 @@
using namespace std;
namespace Rw {
namespace rw {
Frame::Frame(void)
{
@ -196,7 +196,7 @@ Clump::streamRead(Stream *stream)
uint32 length, version;
int32 buf[3];
Clump *clump;
assert(FindChunk(stream, ID_STRUCT, &length, &version));
assert(findChunk(stream, ID_STRUCT, &length, &version));
clump = new Clump;
stream->read(buf, length);
clump->numAtomics = buf[0];
@ -215,14 +215,14 @@ Clump::streamRead(Stream *stream)
// Geometry list
int32 numGeometries = 0;
assert(FindChunk(stream, ID_GEOMETRYLIST, NULL, NULL));
assert(FindChunk(stream, ID_STRUCT, NULL, NULL));
assert(findChunk(stream, ID_GEOMETRYLIST, NULL, NULL));
assert(findChunk(stream, ID_STRUCT, NULL, NULL));
numGeometries = stream->readI32();
Geometry **geometryList = 0;
if(numGeometries)
geometryList = new Geometry*[numGeometries];
for(int32 i = 0; i < numGeometries; i++){
assert(FindChunk(stream, ID_GEOMETRY, NULL, NULL));
assert(findChunk(stream, ID_GEOMETRY, NULL, NULL));
geometryList[i] = Geometry::streamRead(stream);
}
@ -230,7 +230,7 @@ Clump::streamRead(Stream *stream)
if(clump->numAtomics)
clump->atomicList = new Atomic*[clump->numAtomics];
for(int32 i = 0; i < clump->numAtomics; i++){
assert(FindChunk(stream, ID_ATOMIC, NULL, NULL));
assert(findChunk(stream, ID_ATOMIC, NULL, NULL));
clump->atomicList[i] = Atomic::streamReadClump(stream,
frameList, geometryList);
clump->atomicList[i]->clump = clump;
@ -241,9 +241,9 @@ Clump::streamRead(Stream *stream)
clump->lightList = new Light*[clump->numLights];
for(int32 i = 0; i < clump->numLights; i++){
int32 frm;
assert(FindChunk(stream, ID_STRUCT, NULL, NULL));
assert(findChunk(stream, ID_STRUCT, NULL, NULL));
frm = stream->readI32();
assert(FindChunk(stream, ID_LIGHT, NULL, NULL));
assert(findChunk(stream, ID_LIGHT, NULL, NULL));
clump->lightList[i] = Light::streamRead(stream);
clump->lightList[i]->frame = frameList[frm];
clump->lightList[i]->clump = clump;
@ -259,10 +259,10 @@ bool
Clump::streamWrite(Stream *stream)
{
int size = this->streamGetSize();
WriteChunkHeader(stream, ID_CLUMP, size);
writeChunkHeader(stream, ID_CLUMP, size);
int buf[3] = { this->numAtomics, this->numLights, this->numCameras };
size = Version >= 0x33000 ? 12 : 4;
WriteChunkHeader(stream, ID_STRUCT, size);
size = version >= 0x33000 ? 12 : 4;
writeChunkHeader(stream, ID_STRUCT, size);
stream->write(buf, size);
int32 numFrames = ((Frame*)this->parent)->count();
@ -274,8 +274,8 @@ Clump::streamWrite(Stream *stream)
size = 12+4;
for(int32 i = 0; i < this->numAtomics; i++)
size += 12 + this->atomicList[i]->geometry->streamGetSize();
WriteChunkHeader(stream, ID_GEOMETRYLIST, size);
WriteChunkHeader(stream, ID_STRUCT, 4);
writeChunkHeader(stream, ID_GEOMETRYLIST, size);
writeChunkHeader(stream, ID_STRUCT, 4);
stream->writeI32(this->numAtomics); // same as numGeometries
for(int32 i = 0; i < this->numAtomics; i++)
this->atomicList[i]->geometry->streamWrite(stream);
@ -288,7 +288,7 @@ Clump::streamWrite(Stream *stream)
int frm = findPointer((void*)l->frame, (void**)flist,numFrames);
if(frm < 0)
return false;
WriteChunkHeader(stream, ID_STRUCT, 4);
writeChunkHeader(stream, ID_STRUCT, 4);
stream->writeI32(frm);
l->streamWrite(stream);
}
@ -313,7 +313,7 @@ Clump::streamGetSize(void)
uint32 size = 0;
size += 12; // Struct
size += 4; // numAtomics
if(Version >= 0x33000)
if(version >= 0x33000)
size += 8; // numLights, numCameras
// frame list
@ -344,8 +344,8 @@ Clump::frameListStreamRead(Stream *stream, Frame ***flp, int32 *nf)
{
FrameStreamData buf;
int32 numFrames = 0;
assert(FindChunk(stream, ID_FRAMELIST, NULL, NULL));
assert(FindChunk(stream, ID_STRUCT, NULL, NULL));
assert(findChunk(stream, ID_FRAMELIST, NULL, NULL));
assert(findChunk(stream, ID_STRUCT, NULL, NULL));
numFrames = stream->readI32();
Frame **frameList = new Frame*[numFrames];
for(int32 i = 0; i < numFrames; i++){
@ -389,8 +389,8 @@ Clump::frameListStreamWrite(Stream *stream, Frame **frameList, int32 numFrames)
for(int32 i = 0; i < numFrames; i++)
size += 12 + frameList[i]->streamGetPluginSize();
WriteChunkHeader(stream, ID_FRAMELIST, size);
WriteChunkHeader(stream, ID_STRUCT, structsize);
writeChunkHeader(stream, ID_FRAMELIST, size);
writeChunkHeader(stream, ID_STRUCT, structsize);
stream->writeU32(numFrames);
for(int32 i = 0; i < numFrames; i++){
Frame *f = frameList[i];
@ -445,7 +445,7 @@ Atomic::streamReadClump(Stream *stream,
Frame **frameList, Geometry **geometryList)
{
int32 buf[4];
assert(FindChunk(stream, ID_STRUCT, NULL, NULL));
assert(findChunk(stream, ID_STRUCT, NULL, NULL));
stream->read(buf, 16);
Atomic *atomic = new Atomic;
atomic->frame = frameList[buf[0]];
@ -465,8 +465,8 @@ Atomic::streamWriteClump(Stream *stream, Frame **frameList, int32 numFrames)
Clump *c = this->clump;
if(c == NULL)
return false;
WriteChunkHeader(stream, ID_ATOMIC, this->streamGetSize());
WriteChunkHeader(stream, ID_STRUCT, 16);
writeChunkHeader(stream, ID_ATOMIC, this->streamGetSize());
writeChunkHeader(stream, ID_STRUCT, 16);
buf[0] = findPointer((void*)this->frame, (void**)frameList, numFrames);
// TODO
@ -515,7 +515,7 @@ getSizeAtomicRights(void *object, int32, int32)
}
void
RegisterAtomicRightsPlugin(void)
registerAtomicRightsPlugin(void)
{
Atomic::registerPlugin(0, ID_RIGHTTORENDER, NULL, NULL, NULL);
Atomic::registerPluginStream(ID_RIGHTTORENDER,
@ -559,7 +559,7 @@ Light*
Light::streamRead(Stream *stream)
{
LightChunkData buf;
assert(FindChunk(stream, ID_STRUCT, NULL, NULL));
assert(findChunk(stream, ID_STRUCT, NULL, NULL));
Light *light = new Light;
stream->read(&buf, sizeof(LightChunkData));
light->radius = buf.radius;
@ -579,8 +579,8 @@ bool
Light::streamWrite(Stream *stream)
{
LightChunkData buf;
WriteChunkHeader(stream, ID_LIGHT, this->streamGetSize());
WriteChunkHeader(stream, ID_STRUCT, sizeof(LightChunkData));
writeChunkHeader(stream, ID_LIGHT, this->streamGetSize());
writeChunkHeader(stream, ID_STRUCT, sizeof(LightChunkData));
buf.radius = this->radius;
buf.red = this->color[0];
buf.green = this->color[1];

View File

@ -11,7 +11,7 @@
using namespace std;
namespace Rw {
namespace rw {
Geometry::Geometry(int32 numVerts, int32 numTris, uint32 flags)
{
@ -103,7 +103,7 @@ Geometry::streamRead(Stream *stream)
{
uint32 version;
GeoStreamData buf;
assert(FindChunk(stream, ID_STRUCT, NULL, &version));
assert(findChunk(stream, ID_STRUCT, NULL, &version));
stream->read(&buf, sizeof(buf));
Geometry *geo = new Geometry(buf.numVertices,
buf.numTriangles, buf.flags);
@ -132,13 +132,13 @@ Geometry::streamRead(Stream *stream)
stream->read(m->normals, 3*geo->numVertices*4);
}
assert(FindChunk(stream, ID_MATLIST, NULL, NULL));
assert(FindChunk(stream, ID_STRUCT, NULL, NULL));
assert(findChunk(stream, ID_MATLIST, NULL, NULL));
assert(findChunk(stream, ID_STRUCT, NULL, NULL));
geo->numMaterials = stream->readI32();
geo->materialList = new Material*[geo->numMaterials];
stream->seek(geo->numMaterials*4); // unused (-1)
for(int32 i = 0; i < geo->numMaterials; i++){
assert(FindChunk(stream, ID_MATERIAL, NULL, NULL));
assert(findChunk(stream, ID_MATERIAL, NULL, NULL));
geo->materialList[i] = Material::streamRead(stream);
}
@ -152,7 +152,7 @@ geoStructSize(Geometry *geo)
{
uint32 size = 0;
size += sizeof(GeoStreamData);
if(Version < 0x34000)
if(version < 0x34000)
size += 12; // surface properties
if(!(geo->geoflags & Geometry::NATIVE)){
if(geo->geoflags&geo->PRELIT)
@ -181,15 +181,15 @@ Geometry::streamWrite(Stream *stream)
uint32 size;
static float32 fbuf[3] = { 1.0f, 1.0f, 1.0f };
WriteChunkHeader(stream, ID_GEOMETRY, this->streamGetSize());
WriteChunkHeader(stream, ID_STRUCT, geoStructSize(this));
writeChunkHeader(stream, ID_GEOMETRY, this->streamGetSize());
writeChunkHeader(stream, ID_STRUCT, geoStructSize(this));
buf.flags = this->geoflags | this->numTexCoordSets << 16;
buf.numTriangles = this->numTriangles;
buf.numVertices = this->numVertices;
buf.numMorphTargets = this->numMorphTargets;
stream->write(&buf, sizeof(buf));
if(Version < 0x34000)
if(version < 0x34000)
stream->write(fbuf, sizeof(fbuf));
if(!(this->geoflags & NATIVE)){
@ -222,8 +222,8 @@ Geometry::streamWrite(Stream *stream)
size = 12 + 4;
for(int32 i = 0; i < this->numMaterials; i++)
size += 4 + 12 + this->materialList[i]->streamGetSize();
WriteChunkHeader(stream, ID_MATLIST, size);
WriteChunkHeader(stream, ID_STRUCT, 4 + this->numMaterials*4);
writeChunkHeader(stream, ID_MATLIST, size);
writeChunkHeader(stream, ID_STRUCT, 4 + this->numMaterials*4);
stream->writeI32(this->numMaterials);
for(int32 i = 0; i < this->numMaterials; i++)
stream->writeI32(-1);
@ -330,7 +330,7 @@ Material::streamRead(Stream *stream)
{
uint32 length;
MatStreamData buf;
assert(FindChunk(stream, ID_STRUCT, NULL, NULL));
assert(findChunk(stream, ID_STRUCT, NULL, NULL));
stream->read(&buf, sizeof(buf));
Material *mat = new Material;
mat->color[0] = buf.color[0];
@ -342,7 +342,7 @@ Material::streamRead(Stream *stream)
mat->surfaceProps[2] = buf.surfaceProps[2];
if(buf.textured){
assert(FindChunk(stream, ID_TEXTURE, &length, NULL));
assert(findChunk(stream, ID_TEXTURE, &length, NULL));
mat->texture = Texture::streamRead(stream);
}
@ -358,8 +358,8 @@ Material::streamWrite(Stream *stream)
{
MatStreamData buf;
WriteChunkHeader(stream, ID_MATERIAL, this->streamGetSize());
WriteChunkHeader(stream, ID_STRUCT, sizeof(MatStreamData));
writeChunkHeader(stream, ID_MATERIAL, this->streamGetSize());
writeChunkHeader(stream, ID_STRUCT, sizeof(MatStreamData));
buf.color[0] = this->color[0];
buf.color[1] = this->color[1];
@ -420,7 +420,7 @@ getSizeMaterialRights(void *object, int32, int32)
}
void
RegisterMaterialRightsPlugin(void)
registerMaterialRightsPlugin(void)
{
Material::registerPlugin(0, ID_RIGHTTORENDER, NULL, NULL, NULL);
Material::registerPluginStream(ID_RIGHTTORENDER,

View File

@ -2,9 +2,6 @@
#include <cstdlib>
#include <cstring>
#include <cassert>
//#include <iostream>
//#include <fstream>
#include <new>
#include "rwbase.h"
@ -14,7 +11,7 @@
using namespace std;
namespace Rw {
namespace gta {
//
// Frame
@ -22,7 +19,7 @@ namespace Rw {
// Node Name
int32 NodeNameOffset;
int32 nodeNameOffset;
static void*
createNodeName(void *object, int32 offset, int32)
@ -72,9 +69,9 @@ getSizeNodeName(void *object, int32 offset, int32)
void
RegisterNodeNamePlugin(void)
registerNodeNamePlugin(void)
{
NodeNameOffset = Frame::registerPlugin(24, ID_NODENAME,
nodeNameOffset = Frame::registerPlugin(24, ID_NODENAME,
createNodeName,
destroyNodeName,
copyNodeName);
@ -90,7 +87,7 @@ RegisterNodeNamePlugin(void)
// Breakable Model
int32 BreakableOffset;
int32 breakableOffset;
static void*
createBreakableModel(void *object, int32 offset, int32)
@ -178,9 +175,9 @@ getSizeBreakableModel(void *object, int32 offset, int32)
}
void
RegisterBreakableModelPlugin(void)
registerBreakableModelPlugin(void)
{
BreakableOffset = Geometry::registerPlugin(sizeof(Breakable*),
breakableOffset = Geometry::registerPlugin(sizeof(Breakable*),
ID_BREAKABLE,
createBreakableModel,
destroyBreakableModel, NULL);
@ -192,7 +189,7 @@ RegisterBreakableModelPlugin(void)
// Extra colors
int32 ExtraVertColorOffset;
int32 extraVertColorOffset;
static void*
createExtraVertColors(void *object, int32 offset, int32)
@ -258,9 +255,9 @@ getSizeExtraVertColors(void *object, int32 offset, int32)
}
void
RegisterExtraVertColorPlugin(void)
registerExtraVertColorPlugin(void)
{
ExtraVertColorOffset = Geometry::registerPlugin(sizeof(ExtraVertColors),
extraVertColorOffset = Geometry::registerPlugin(sizeof(ExtraVertColors),
ID_EXTRAVERTCOLORS,
createExtraVertColors,
destroyExtraVertColors,
@ -273,7 +270,7 @@ RegisterExtraVertColorPlugin(void)
// Environment mat
int32 EnvMatOffset;
int32 envMatOffset;
static void*
createEnvMat(void *object, int32 offset, int32)
@ -353,7 +350,7 @@ getSizeEnvMat(void *object, int32 offset, int32)
// Specular mat
int32 SpecMatOffset;
int32 specMatOffset;
static void*
createSpecMat(void *object, int32 offset, int32)
@ -422,16 +419,16 @@ getSizeSpecMat(void *object, int32 offset, int32)
}
void
RegisterEnvSpecPlugin(void)
registerEnvSpecPlugin(void)
{
SpecMatOffset = Material::registerPlugin(sizeof(SpecMat*), ID_SPECMAT,
specMatOffset = Material::registerPlugin(sizeof(SpecMat*), ID_SPECMAT,
createSpecMat,
destroySpecMat,
copySpecMat);
Material::registerPluginStream(ID_SPECMAT, readSpecMat,
writeSpecMat,
getSizeSpecMat);
EnvMatOffset = Material::registerPlugin(sizeof(EnvMat*), ID_ENVMAT,
envMatOffset = Material::registerPlugin(sizeof(EnvMat*), ID_ENVMAT,
createEnvMat,
destroyEnvMat,
copyEnvMat);

View File

@ -1,4 +1,5 @@
namespace Rw {
namespace gta {
using namespace rw;
enum
{
@ -11,8 +12,8 @@ enum
// Node name
extern int32 NodeNameOffset;
void RegisterNodeNamePlugin(void);
extern int32 nodeNameOffset;
void registerNodeNamePlugin(void);
// Breakable model
@ -33,8 +34,8 @@ struct Breakable
float32 (*surfaceProps)[3];
};
extern int32 BreakableOffset;
void RegisterBreakableModelPlugin(void);
extern int32 breakableOffset;
void registerBreakableModelPlugin(void);
// Extra vert colors
@ -45,8 +46,8 @@ struct ExtraVertColors
float balance;
};
extern int32 ExtraVertColorOffset;
void RegisterExtraVertColorPlugin(void);
extern int32 extraVertColorOffset;
void registerExtraVertColorPlugin(void);
// Environment mat
@ -58,7 +59,7 @@ struct EnvMat
Texture *texture;
};
extern int32 EnvMatOffset;
extern int32 envMatOffset;
// Specular mat
@ -68,8 +69,8 @@ struct SpecMat
Texture *texture;
};
extern int32 SpecMatOffset;
extern int32 specMatOffset;
void RegisterEnvSpecPlugin(void);
void registerEnvSpecPlugin(void);
}

View File

@ -12,7 +12,7 @@
using namespace std;
namespace Rw {
namespace rw {
uint8
readUInt8(istream &rw)
@ -33,7 +33,7 @@ writeUInt8(uint8 tmp, ostream &rw)
// TexDictionary
//
TexDictionary *CurrentTexDictionary;
TexDictionary *currentTexDictionary;
TexDictionary::TexDictionary(void)
{
@ -92,7 +92,7 @@ Texture::read(const char *name, const char *mask)
Raster *raster = NULL;
Texture *tex;
if((tex = CurrentTexDictionary->find(name)))
if((tex = currentTexDictionary->find(name)))
return tex;
tex = new Texture;
strncpy(tex->name, name, 32);
@ -107,7 +107,7 @@ Texture::read(const char *name, const char *mask)
delete img;
}
tex->raster = raster;
CurrentTexDictionary->add(tex);
currentTexDictionary->add(tex);
return tex;
}
@ -116,15 +116,15 @@ Texture::streamRead(Stream *stream)
{
uint32 length;
char name[32], mask[32];
assert(FindChunk(stream, ID_STRUCT, NULL, NULL));
assert(findChunk(stream, ID_STRUCT, NULL, NULL));
uint32 filterAddressing = stream->readU16();
// TODO: what is this? (mipmap? i think)
stream->seek(2);
assert(FindChunk(stream, ID_STRING, &length, NULL));
assert(findChunk(stream, ID_STRING, &length, NULL));
stream->read(name, length);
assert(FindChunk(stream, ID_STRING, &length, NULL));
assert(findChunk(stream, ID_STRING, &length, NULL));
stream->read(mask, length);
Texture *tex = Texture::read(name, mask);
@ -140,17 +140,17 @@ bool
Texture::streamWrite(Stream *stream)
{
int size;
WriteChunkHeader(stream, ID_TEXTURE, this->streamGetSize());
WriteChunkHeader(stream, ID_STRUCT, 4);
writeChunkHeader(stream, ID_TEXTURE, this->streamGetSize());
writeChunkHeader(stream, ID_STRUCT, 4);
stream->writeU32(this->filterAddressing);
// TODO: length can't be > 32
size = strlen(this->name)+4 & ~3;
WriteChunkHeader(stream, ID_STRING, size);
writeChunkHeader(stream, ID_STRING, size);
stream->write(this->name, size);
size = strlen(this->mask)+4 & ~3;
WriteChunkHeader(stream, ID_STRING, size);
writeChunkHeader(stream, ID_STRING, size);
stream->write(this->mask, size);
this->streamWritePlugins(stream);

View File

@ -16,8 +16,8 @@
using namespace std;
namespace Rw {
namespace Gl {
namespace rw {
namespace gl {
// VC
// 8733 0 0 0 3
@ -54,7 +54,7 @@ printAttribInfo(AttribDesc *attribs, int n)
*/
void*
DestroyNativeData(void *object, int32, int32)
destroyNativeData(void *object, int32, int32)
{
Geometry *geometry = (Geometry*)object;
assert(geometry->instData->platform == PLATFORM_OGL);
@ -67,7 +67,7 @@ DestroyNativeData(void *object, int32, int32)
}
void
ReadNativeData(Stream *stream, int32, void *object, int32, int32)
readNativeData(Stream *stream, int32, void *object, int32, int32)
{
Geometry *geometry = (Geometry*)object;
InstanceDataHeader *header = new InstanceDataHeader;
@ -85,7 +85,7 @@ ReadNativeData(Stream *stream, int32, void *object, int32, int32)
}
void
WriteNativeData(Stream *stream, int32, void *object, int32, int32)
writeNativeData(Stream *stream, int32, void *object, int32, int32)
{
Geometry *geometry = (Geometry*)object;
assert(geometry->instData->platform == PLATFORM_OGL);
@ -97,7 +97,7 @@ WriteNativeData(Stream *stream, int32, void *object, int32, int32)
}
int32
GetSizeNativeData(void *object, int32, int32)
getSizeNativeData(void *object, int32, int32)
{
Geometry *geometry = (Geometry*)object;
assert(geometry->instData->platform == PLATFORM_OGL);
@ -166,7 +166,7 @@ packattrib(uint8 *dst, float32 *src, AttribDesc *a, float32 scale=1.0f)
// TODO: make pipeline dependent (skin data, night colors)
void
Instance(Atomic *atomic)
instance(Atomic *atomic)
{
Geometry *geo = atomic->geometry;
InstanceDataHeader *header = new InstanceDataHeader;
@ -283,7 +283,7 @@ Instance(Atomic *atomic)
#ifdef RW_OPENGL
void
UploadGeo(Geometry *geo)
uploadGeo(Geometry *geo)
{
InstanceDataHeader *inst = (InstanceDataHeader*)geo->instData;
MeshHeader *meshHeader = geo->meshHeader;
@ -308,7 +308,7 @@ UploadGeo(Geometry *geo)
}
void
SetAttribPointers(InstanceDataHeader *inst)
setAttribPointers(InstanceDataHeader *inst)
{
static GLenum attribType[] = {
GL_FLOAT,
@ -328,12 +328,12 @@ SetAttribPointers(InstanceDataHeader *inst)
// Skin
void
ReadNativeSkin(Stream *stream, int32, void *object, int32 offset)
readNativeSkin(Stream *stream, int32, void *object, int32 offset)
{
uint8 header[4];
uint32 vers;
Geometry *geometry = (Geometry*)object;
assert(FindChunk(stream, ID_STRUCT, NULL, &vers));
assert(findChunk(stream, ID_STRUCT, NULL, &vers));
assert(stream->readU32() == PLATFORM_OGL);
stream->read(header, 4);
Skin *skin = new Skin;
@ -364,11 +364,11 @@ ReadNativeSkin(Stream *stream, int32, void *object, int32 offset)
}
void
WriteNativeSkin(Stream *stream, int32 len, void *object, int32 offset)
writeNativeSkin(Stream *stream, int32 len, void *object, int32 offset)
{
uint8 header[4];
WriteChunkHeader(stream, ID_STRUCT, len-12);
writeChunkHeader(stream, ID_STRUCT, len-12);
stream->writeU32(PLATFORM_OGL);
Skin *skin = *PLUGINOFFSET(Skin*, object, offset);
header[0] = skin->numBones;
@ -380,7 +380,7 @@ WriteNativeSkin(Stream *stream, int32 len, void *object, int32 offset)
}
int32
GetSizeNativeSkin(void *object, int32 offset)
getSizeNativeSkin(void *object, int32 offset)
{
Skin *skin = *PLUGINOFFSET(Skin*, object, offset);
if(skin == NULL)
@ -391,7 +391,7 @@ GetSizeNativeSkin(void *object, int32 offset)
// Raster
int32 NativeRasterOffset;
int32 nativeRasterOffset;
#ifdef RW_OPENGL
struct GlRaster {
@ -422,9 +422,9 @@ copyNativeRaster(void *dst, void *, int32 offset, int32)
}
void
RegisterNativeRaster(void)
registerNativeRaster(void)
{
NativeRasterOffset = Raster::registerPlugin(sizeof(GlRaster),
nativeRasterOffset = Raster::registerPlugin(sizeof(GlRaster),
0x12340001,
createNativeRaster,
destroyNativeRaster,
@ -477,7 +477,7 @@ Texture::upload(void)
break;
}
glBindTexture(GL_TEXTURE_2D, 0);
GlRaster *glr = PLUGINOFFSET(GlRaster, r, NativeRasterOffset);
GlRaster *glr = PLUGINOFFSET(GlRaster, r, nativeRasterOffset);
glr->id = id;
}
@ -485,7 +485,7 @@ void
Texture::bind(int n)
{
Raster *r = this->raster;
GlRaster *glr = PLUGINOFFSET(GlRaster, r, NativeRasterOffset);
GlRaster *glr = PLUGINOFFSET(GlRaster, r, nativeRasterOffset);
glActiveTexture(GL_TEXTURE0+n);
if(r){
if(glr->id == 0)

View File

@ -12,13 +12,13 @@
using namespace std;
namespace Rw {
namespace rw {
//
// HAnim
//
int32 HAnimOffset;
int32 hAnimOffset;
static void*
createHAnim(void *object, int32 offset, int32)
@ -124,9 +124,9 @@ getSizeHAnim(void *object, int32 offset, int32)
}
void
RegisterHAnimPlugin(void)
registerHAnimPlugin(void)
{
HAnimOffset = Frame::registerPlugin(sizeof(HAnimData), ID_HANIMPLUGIN,
hAnimOffset = Frame::registerPlugin(sizeof(HAnimData), ID_HANIMPLUGIN,
createHAnim,
destroyHAnim, copyHAnim);
Frame::registerPluginStream(ID_HANIMPLUGIN,
@ -238,14 +238,11 @@ getSizeMesh(void *object, int32)
return size;
}
void
RegisterMeshPlugin(void)
registerMeshPlugin(void)
{
Geometry::registerPlugin(0, 0x50E, NULL, NULL, NULL);
Geometry::registerPluginStream(0x50E, (StreamRead)readMesh,
(StreamWrite)writeMesh,
(StreamGetSize)getSizeMesh);
Geometry::registerPluginStream(0x50E, readMesh, writeMesh, getSizeMesh);
}
// Native Data
@ -257,9 +254,9 @@ destroyNativeData(void *object, int32 offset, int32 size)
if(geometry->instData == NULL)
return object;
if(geometry->instData->platform == PLATFORM_PS2)
return Ps2::DestroyNativeData(object, offset, size);
return ps2::destroyNativeData(object, offset, size);
if(geometry->instData->platform == PLATFORM_OGL)
return Gl::DestroyNativeData(object, offset, size);
return gl::destroyNativeData(object, offset, size);
return object;
}
@ -272,19 +269,19 @@ readNativeData(Stream *stream, int32 len, void *object, int32 o, int32 s)
// ugly hack to find out platform
stream->seek(-4);
libid = stream->readU32();
ReadChunkHeaderInfo(stream, &header);
readChunkHeaderInfo(stream, &header);
if(header.type == ID_STRUCT &&
LibraryIDPack(header.version, header.build) == libid){
libraryIDPack(header.version, header.build) == libid){
// must be PS2 or Xbox
platform = stream->readU32();
stream->seek(-16);
if(platform == PLATFORM_PS2)
Ps2::ReadNativeData(stream, len, object, o, s);
ps2::readNativeData(stream, len, object, o, s);
else if(platform == PLATFORM_XBOX)
stream->seek(len);
}else{
stream->seek(-12);
Gl::ReadNativeData(stream, len, object, o, s);
gl::readNativeData(stream, len, object, o, s);
}
}
@ -295,9 +292,9 @@ writeNativeData(Stream *stream, int32 len, void *object, int32 o, int32 s)
if(geometry->instData == NULL)
return;
if(geometry->instData->platform == PLATFORM_PS2)
Ps2::WriteNativeData(stream, len, object, o, s);
ps2::writeNativeData(stream, len, object, o, s);
else if(geometry->instData->platform == PLATFORM_OGL)
Gl::WriteNativeData(stream, len, object, o, s);
gl::writeNativeData(stream, len, object, o, s);
}
static int32
@ -307,30 +304,30 @@ getSizeNativeData(void *object, int32 offset, int32 size)
if(geometry->instData == NULL)
return -1;
if(geometry->instData->platform == PLATFORM_PS2)
return Ps2::GetSizeNativeData(object, offset, size);
return ps2::getSizeNativeData(object, offset, size);
else if(geometry->instData->platform == PLATFORM_XBOX)
return -1;
else if(geometry->instData->platform == PLATFORM_OGL)
return Gl::GetSizeNativeData(object, offset, size);
return gl::getSizeNativeData(object, offset, size);
return -1;
}
void
RegisterNativeDataPlugin(void)
registerNativeDataPlugin(void)
{
Geometry::registerPlugin(0, ID_NATIVEDATA,
NULL, destroyNativeData, NULL);
Geometry::registerPluginStream(ID_NATIVEDATA,
(StreamRead)readNativeData,
(StreamWrite)writeNativeData,
(StreamGetSize)getSizeNativeData);
readNativeData,
writeNativeData,
getSizeNativeData);
}
//
// Skin
//
SkinGlobals_ SkinGlobals = { 0, NULL };
SkinGlobals skinGlobals = { 0, NULL };
static void*
createSkin(void *object, int32 offset, int32)
@ -406,9 +403,9 @@ readSkin(Stream *stream, int32 len, void *object, int32 offset, int32)
if(geometry->instData){
if(geometry->instData->platform == PLATFORM_PS2)
Ps2::ReadNativeSkin(stream, len, object, offset);
ps2::readNativeSkin(stream, len, object, offset);
else if(geometry->instData->platform == PLATFORM_OGL)
Gl::ReadNativeSkin(stream, len, object, offset);
gl::readNativeSkin(stream, len, object, offset);
else
assert(0 && "unsupported native skin platform");
return;
@ -480,16 +477,16 @@ writeSkin(Stream *stream, int32 len, void *object, int32 offset, int32)
if(geometry->instData){
if(geometry->instData->platform == PLATFORM_PS2)
Ps2::WriteNativeSkin(stream, len, object, offset);
ps2::writeNativeSkin(stream, len, object, offset);
else if(geometry->instData->platform == PLATFORM_OGL)
Gl::WriteNativeSkin(stream, len, object, offset);
gl::writeNativeSkin(stream, len, object, offset);
else
assert(0 && "unsupported native skin platform");
return;
}
Skin *skin = *PLUGINOFFSET(Skin*, object, offset);
bool oldFormat = Version < 0x34003;
bool oldFormat = version < 0x34003;
header[0] = skin->numBones;
header[1] = skin->numUsedBones;
header[2] = skin->maxIndex;
@ -521,9 +518,9 @@ getSizeSkin(void *object, int32 offset, int32)
if(geometry->instData){
if(geometry->instData->platform == PLATFORM_PS2)
return Ps2::GetSizeNativeSkin(object, offset);
return ps2::getSizeNativeSkin(object, offset);
if(geometry->instData->platform == PLATFORM_OGL)
return Gl::GetSizeNativeSkin(object, offset);
return gl::getSizeNativeSkin(object, offset);
assert(0 && "unsupported native skin platform");
}
@ -534,7 +531,7 @@ getSizeSkin(void *object, int32 offset, int32)
int32 size = 4 + geometry->numVertices*(16+4) +
skin->numBones*64;
// not sure which version introduced the new format
if(Version < 0x34003)
if(version < 0x34003)
size += skin->numBones*4;
else
size += skin->numUsedBones + 12;
@ -544,22 +541,23 @@ getSizeSkin(void *object, int32 offset, int32)
static void
skinRights(void *object, int32, int32, uint32 data)
{
((Atomic*)object)->pipeline = SkinGlobals.pipeline;
((Atomic*)object)->pipeline = skinGlobals.pipeline;
}
void
RegisterSkinPlugin(void)
registerSkinPlugin(void)
{
SkinGlobals.pipeline = new Pipeline;
SkinGlobals.pipeline->pluginID = ID_SKIN;
SkinGlobals.pipeline->pluginData = 1;
skinGlobals.pipeline = new Pipeline;
skinGlobals.pipeline->pluginID = ID_SKIN;
skinGlobals.pipeline->pluginData = 1;
SkinGlobals.offset = Geometry::registerPlugin(sizeof(Skin*), ID_SKIN,
createSkin, destroySkin, copySkin);
skinGlobals.offset = Geometry::registerPlugin(sizeof(Skin*), ID_SKIN,
createSkin,
destroySkin,
copySkin);
Geometry::registerPluginStream(ID_SKIN,
readSkin, writeSkin, getSizeSkin);
Atomic::registerPlugin(0, ID_SKIN,
NULL, NULL, NULL);
Atomic::registerPlugin(0, ID_SKIN, NULL, NULL, NULL);
Atomic::setStreamRightsCallback(ID_SKIN, skinRights);
}
@ -590,7 +588,7 @@ readAtomicMatFX(Stream *stream, int32, void *object, int32 offset, int32)
stream->read(&flag, 4);
*PLUGINOFFSET(int32, object, offset) = flag;
if(flag)
((Atomic*)object)->pipeline = MatFXGlobals.pipeline;
((Atomic*)object)->pipeline = matFXGlobals.pipeline;
}
static void
@ -611,7 +609,7 @@ getSizeAtomicMatFX(void *object, int32 offset, int32)
// Material
MatFXGlobals_ MatFXGlobals = { 0, 0, NULL };
MatFXGlobals matFXGlobals = { 0, 0, NULL };
// TODO: Frames and Matrices?
static void
@ -745,12 +743,12 @@ readMaterialMatFX(Stream *stream, int32, void *object, int32 offset, int32)
coefficient = stream->readF32();
bumpedTex = tex = NULL;
if(stream->readI32()){
assert(FindChunk(stream, ID_TEXTURE,
assert(findChunk(stream, ID_TEXTURE,
NULL, NULL));
bumpedTex = Texture::streamRead(stream);
}
if(stream->readI32()){
assert(FindChunk(stream, ID_TEXTURE,
assert(findChunk(stream, ID_TEXTURE,
NULL, NULL));
tex = Texture::streamRead(stream);
}
@ -766,7 +764,7 @@ readMaterialMatFX(Stream *stream, int32, void *object, int32 offset, int32)
fbAlpha = stream->readI32();
tex = NULL;
if(stream->readI32()){
assert(FindChunk(stream, ID_TEXTURE,
assert(findChunk(stream, ID_TEXTURE,
NULL, NULL));
tex = Texture::streamRead(stream);
}
@ -782,7 +780,7 @@ readMaterialMatFX(Stream *stream, int32, void *object, int32 offset, int32)
dstBlend = stream->readI32();
tex = NULL;
if(stream->readI32()){
assert(FindChunk(stream, ID_TEXTURE,
assert(findChunk(stream, ID_TEXTURE,
NULL, NULL));
tex = Texture::streamRead(stream);
}
@ -872,13 +870,13 @@ getSizeMaterialMatFX(void *object, int32 offset, int32)
}
void
RegisterMatFXPlugin(void)
registerMatFXPlugin(void)
{
MatFXGlobals.pipeline = new Pipeline;
MatFXGlobals.pipeline->pluginID = ID_MATFX;
MatFXGlobals.pipeline->pluginData = 0;
matFXGlobals.pipeline = new Pipeline;
matFXGlobals.pipeline->pluginID = ID_MATFX;
matFXGlobals.pipeline->pluginData = 0;
MatFXGlobals.atomicOffset =
matFXGlobals.atomicOffset =
Atomic::registerPlugin(sizeof(int32), ID_MATFX,
createAtomicMatFX, NULL, copyAtomicMatFX);
Atomic::registerPluginStream(ID_MATFX,
@ -886,7 +884,7 @@ RegisterMatFXPlugin(void)
writeAtomicMatFX,
getSizeAtomicMatFX);
MatFXGlobals.materialOffset =
matFXGlobals.materialOffset =
Material::registerPlugin(sizeof(MatFX*), ID_MATFX,
createMaterialMatFX, destroyMaterialMatFX,
copyMaterialMatFX);

View File

@ -12,11 +12,11 @@
using namespace std;
namespace Rw {
namespace Ps2 {
namespace rw {
namespace ps2 {
void*
DestroyNativeData(void *object, int32, int32)
destroyNativeData(void *object, int32, int32)
{
Geometry *geometry = (Geometry*)object;
assert(geometry->instData->platform == PLATFORM_PS2);
@ -29,10 +29,10 @@ DestroyNativeData(void *object, int32, int32)
}
void
ReadNativeData(Stream *stream, int32, void *object, int32, int32)
readNativeData(Stream *stream, int32, void *object, int32, int32)
{
Geometry *geometry = (Geometry*)object;
assert(FindChunk(stream, ID_STRUCT, NULL, NULL));
assert(findChunk(stream, ID_STRUCT, NULL, NULL));
assert(stream->readU32() == PLATFORM_PS2);
InstanceDataHeader *header = new InstanceDataHeader;
geometry->instData = header;
@ -58,10 +58,10 @@ ReadNativeData(Stream *stream, int32, void *object, int32, int32)
}
void
WriteNativeData(Stream *stream, int32 len, void *object, int32, int32)
writeNativeData(Stream *stream, int32 len, void *object, int32, int32)
{
Geometry *geometry = (Geometry*)object;
WriteChunkHeader(stream, ID_STRUCT, len-12);
writeChunkHeader(stream, ID_STRUCT, len-12);
assert(geometry->instData->platform == PLATFORM_PS2);
stream->writeU32(PLATFORM_PS2);
assert(geometry->instData != NULL);
@ -79,7 +79,7 @@ WriteNativeData(Stream *stream, int32 len, void *object, int32, int32)
}
int32
GetSizeNativeData(void *object, int32, int32)
getSizeNativeData(void *object, int32, int32)
{
Geometry *geometry = (Geometry*)object;
int32 size = 16;
@ -95,14 +95,14 @@ GetSizeNativeData(void *object, int32, int32)
}
void
RegisterNativeDataPlugin(void)
registerNativeDataPlugin(void)
{
Geometry::registerPlugin(0, ID_NATIVEDATA,
NULL, DestroyNativeData, NULL);
NULL, destroyNativeData, NULL);
Geometry::registerPluginStream(ID_NATIVEDATA,
(StreamRead)ReadNativeData,
(StreamWrite)WriteNativeData,
(StreamGetSize)GetSizeNativeData);
readNativeData,
writeNativeData,
getSizeNativeData);
}
#ifdef RW_PS2
@ -184,12 +184,12 @@ unfixDmaOffsets(InstanceData *inst)
// Skin
void
ReadNativeSkin(Stream *stream, int32, void *object, int32 offset)
readNativeSkin(Stream *stream, int32, void *object, int32 offset)
{
uint8 header[4];
uint32 vers;
Geometry *geometry = (Geometry*)object;
assert(FindChunk(stream, ID_STRUCT, NULL, &vers));
assert(findChunk(stream, ID_STRUCT, NULL, &vers));
assert(stream->readU32() == PLATFORM_PS2);
stream->read(header, 4);
Skin *skin = new Skin;
@ -230,14 +230,14 @@ ReadNativeSkin(Stream *stream, int32, void *object, int32 offset)
}
void
WriteNativeSkin(Stream *stream, int32 len, void *object, int32 offset)
writeNativeSkin(Stream *stream, int32 len, void *object, int32 offset)
{
uint8 header[4];
WriteChunkHeader(stream, ID_STRUCT, len-12);
writeChunkHeader(stream, ID_STRUCT, len-12);
stream->writeU32(PLATFORM_PS2);
Skin *skin = *PLUGINOFFSET(Skin*, object, offset);
bool oldFormat = Version < 0x34003;
bool oldFormat = version < 0x34003;
header[0] = skin->numBones;
header[1] = skin->numUsedBones;
header[2] = skin->maxIndex;
@ -258,14 +258,14 @@ WriteNativeSkin(Stream *stream, int32 len, void *object, int32 offset)
}
int32
GetSizeNativeSkin(void *object, int32 offset)
getSizeNativeSkin(void *object, int32 offset)
{
Skin *skin = *PLUGINOFFSET(Skin*, object, offset);
if(skin == NULL)
return -1;
int32 size = 12 + 4 + 4 + skin->numBones*64;
// not sure which version introduced the new format
if(Version >= 0x34003)
if(version >= 0x34003)
size += skin->numUsedBones + 16 + 12;
return size;
}
@ -304,7 +304,7 @@ readADC(Stream *stream, int32, void *object, int32 offset, int32)
static void
writeADC(Stream *stream, int32, void *, int32, int32)
{
WriteChunkHeader(stream, ID_ADC, 4);
writeChunkHeader(stream, ID_ADC, 4);
stream->writeI32(0);
}
@ -316,14 +316,14 @@ getSizeADC(void *object, int32 offset, int32)
}
void
RegisterADCPlugin(void)
registerADCPlugin(void)
{
Geometry::registerPlugin(sizeof(ADCData), ID_ADC,
createADC, NULL, copyADC);
Geometry::registerPluginStream(ID_ADC,
(StreamRead)readADC,
(StreamWrite)writeADC,
(StreamGetSize)getSizeADC);
readADC,
writeADC,
getSizeADC);
}

View File

@ -10,11 +10,11 @@
using namespace std;
namespace Rw {
namespace rw {
int Version = 0x36003;
int Build = 0xFFFF;
char *DebugFile = NULL;
int version = 0x36003;
int build = 0xFFFF;
char *debugFile = NULL;
int32
Stream::writeI8(int8 val)
@ -249,19 +249,19 @@ StreamFile::eof(void)
}
bool
WriteChunkHeader(Stream *s, int32 type, int32 size)
writeChunkHeader(Stream *s, int32 type, int32 size)
{
struct {
int32 type, size;
uint32 id;
} buf = { type, size, LibraryIDPack(Version, Build) };
} buf = { type, size, libraryIDPack(version, build) };
//printf("- write chunk %x @ %x\n", buf.type, s->tell());
s->write(&buf, 12);
return true;
}
bool
ReadChunkHeaderInfo(Stream *s, ChunkHeaderInfo *header)
readChunkHeaderInfo(Stream *s, ChunkHeaderInfo *header)
{
struct {
int32 type, size;
@ -273,16 +273,16 @@ ReadChunkHeaderInfo(Stream *s, ChunkHeaderInfo *header)
assert(header != NULL);
header->type = buf.type;
header->length = buf.size;
header->version = LibraryIDUnpackVersion(buf.id);
header->build = LibraryIDUnpackBuild(buf.id);
header->version = libraryIDUnpackVersion(buf.id);
header->build = libraryIDUnpackBuild(buf.id);
return true;
}
bool
FindChunk(Stream *s, uint32 type, uint32 *length, uint32 *version)
findChunk(Stream *s, uint32 type, uint32 *length, uint32 *version)
{
ChunkHeaderInfo header;
while(ReadChunkHeaderInfo(s, &header)){
while(readChunkHeaderInfo(s, &header)){
if(header.type == ID_NAOBJECT)
return false;
if(header.type == type){

View File

@ -1,4 +1,4 @@
namespace Rw {
namespace rw {
typedef char int8;
typedef short int16;
@ -118,12 +118,12 @@ enum PluginID
ID_NATIVEDATA = 0x510,
};
extern int Version;
extern int Build;
extern char *DebugFile;
extern int version;
extern int build;
extern char *debugFile;
inline uint32
LibraryIDPack(int version, int build)
libraryIDPack(int version, int build)
{
// TODO: check version in if statement
if(build){
@ -135,7 +135,7 @@ LibraryIDPack(int version, int build)
}
inline int
LibraryIDUnpackVersion(uint32 libid)
libraryIDUnpackVersion(uint32 libid)
{
if(libid & 0xFFFF0000)
return (libid>>14 & 0x3FF00) |
@ -146,7 +146,7 @@ LibraryIDUnpackVersion(uint32 libid)
}
inline int
LibraryIDUnpackBuild(uint32 libid)
libraryIDUnpackBuild(uint32 libid)
{
if(libid & 0xFFFF0000)
return libid & 0xFFFF;
@ -162,9 +162,9 @@ struct ChunkHeaderInfo
};
// TODO?: make these methods of ChunkHeaderInfo?
bool WriteChunkHeader(Stream *s, int32 type, int32 size);
bool ReadChunkHeaderInfo(Stream *s, ChunkHeaderInfo *header);
bool FindChunk(Stream *s, uint32 type, uint32 *length, uint32 *version);
bool writeChunkHeader(Stream *s, int32 type, int32 size);
bool readChunkHeaderInfo(Stream *s, ChunkHeaderInfo *header);
bool findChunk(Stream *s, uint32 type, uint32 *length, uint32 *version);
int32 findPointer(void *p, void **list, int32 num);
}

View File

@ -1,4 +1,4 @@
namespace Rw {
namespace rw {
// TODO: mostly a stub right now
struct Pipeline
@ -68,8 +68,8 @@ struct HAnimData
HAnimHierarchy *hierarchy;
};
extern int32 HAnimOffset;
void RegisterHAnimPlugin(void);
extern int32 hAnimOffset;
void registerHAnimPlugin(void);
struct Image
{
@ -180,7 +180,7 @@ struct Material : PluginBase<Material>
uint32 streamGetSize(void);
};
void RegisterMaterialRightsPlugin(void);
void registerMaterialRightsPlugin(void);
struct MatFX
{
@ -229,14 +229,14 @@ struct MatFX
int32 getEffectIndex(uint32 type);
};
struct MatFXGlobals_
struct MatFXGlobals
{
int32 atomicOffset;
int32 materialOffset;
Pipeline *pipeline;
};
extern MatFXGlobals_ MatFXGlobals;
void RegisterMatFXPlugin(void);
extern MatFXGlobals matFXGlobals;
void registerMatFXPlugin(void);
struct Mesh
{
@ -312,8 +312,8 @@ struct Geometry : PluginBase<Geometry>, Object
};
};
void RegisterMeshPlugin(void);
void RegisterNativeDataPlugin(void);
void registerMeshPlugin(void);
void registerNativeDataPlugin(void);
struct Skin
{
@ -327,13 +327,13 @@ struct Skin
uint8 *data; // only used by delete
};
struct SkinGlobals_
struct SkinGlobals
{
int32 offset;
Pipeline *pipeline;
};
extern SkinGlobals_ SkinGlobals;
void RegisterSkinPlugin(void);
extern SkinGlobals skinGlobals;
void registerSkinPlugin(void);
struct Clump;
@ -370,7 +370,7 @@ struct Atomic : PluginBase<Atomic>, Object
uint32 streamGetSize(void);
};
void RegisterAtomicRightsPlugin(void);
void registerAtomicRightsPlugin(void);
struct Clump : PluginBase<Clump>, Object
{
@ -402,6 +402,6 @@ struct TexDictionary
Texture *find(const char *name);
};
extern TexDictionary *CurrentTexDictionary;
extern TexDictionary *currentTexDictionary;
}

View File

@ -1,5 +1,5 @@
namespace Rw {
namespace Gl {
namespace rw {
namespace gl {
struct AttribDesc
{
@ -14,7 +14,7 @@ struct AttribDesc
uint32 offset;
};
struct InstanceDataHeader : Rw::InstanceDataHeader
struct InstanceDataHeader : rw::InstanceDataHeader
{
int32 numAttribs;
AttribDesc *attribs;
@ -26,33 +26,33 @@ struct InstanceDataHeader : Rw::InstanceDataHeader
uint32 ibo;
};
void *DestroyNativeData(void *object, int32, int32);
void ReadNativeData(Stream *stream, int32 len, void *object, int32, int32);
void WriteNativeData(Stream *stream, int32 len, void *object, int32, int32);
int32 GetSizeNativeData(void *object, int32, int32);
void *destroyNativeData(void *object, int32, int32);
void readNativeData(Stream *stream, int32 len, void *object, int32, int32);
void writeNativeData(Stream *stream, int32 len, void *object, int32, int32);
int32 getSizeNativeData(void *object, int32, int32);
void Instance(Atomic *atomic);
void instance(Atomic *atomic);
// only RW_OPENGL
void UploadGeo(Geometry *geo);
void SetAttribPointers(InstanceDataHeader *inst);
void uploadGeo(Geometry *geo);
void setAttribPointers(InstanceDataHeader *inst);
// Skin plugin
void ReadNativeSkin(Stream *stream, int32, void *object, int32 offset);
void WriteNativeSkin(Stream *stream, int32 len, void *object, int32 offset);
int32 GetSizeNativeSkin(void *object, int32 offset);
void readNativeSkin(Stream *stream, int32, void *object, int32 offset);
void writeNativeSkin(Stream *stream, int32 len, void *object, int32 offset);
int32 getSizeNativeSkin(void *object, int32 offset);
// Raster
struct Texture : Rw::Texture
struct Texture : rw::Texture
{
void upload(void);
void bind(int n);
};
extern int32 NativeRasterOffset;
void RegisterNativeRaster(void);
extern int32 nativeRasterOffset;
void registerNativeRaster(void);
}
}

View File

@ -1,4 +1,4 @@
namespace Rw {
namespace rw {
#define PLUGINOFFSET(type, base, offset) \
((type*)((char*)(base) + (offset)))
@ -85,11 +85,11 @@ template <typename T> void
PluginBase<T>::streamReadPlugins(Stream *stream)
{
int32 length;
Rw::ChunkHeaderInfo header;
if(!Rw::FindChunk(stream, Rw::ID_EXTENSION, (uint32*)&length, NULL))
ChunkHeaderInfo header;
if(!findChunk(stream, ID_EXTENSION, (uint32*)&length, NULL))
return;
while(length > 0){
Rw::ReadChunkHeaderInfo(stream, &header);
readChunkHeaderInfo(stream, &header);
length -= 12;
for(Plugin *p = this->s_plugins; p; p = p->next)
if(p->id == header.type){
@ -107,12 +107,12 @@ template <typename T> void
PluginBase<T>::streamWritePlugins(Stream *stream)
{
int size = this->streamGetPluginSize();
Rw::WriteChunkHeader(stream, Rw::ID_EXTENSION, size);
writeChunkHeader(stream, ID_EXTENSION, size);
for(Plugin *p = this->s_plugins; p; p = p->next){
if(p->getSize == NULL ||
(size = p->getSize(this, p->offset, p->size)) < 0)
continue;
Rw::WriteChunkHeader(stream, p->id, size);
writeChunkHeader(stream, p->id, size);
p->write(stream, size, this, p->offset, p->size);
}
}

View File

@ -1,5 +1,5 @@
namespace Rw {
namespace Ps2 {
namespace rw {
namespace ps2 {
struct InstanceData
{
@ -13,17 +13,17 @@ struct InstanceData
Material *material;
};
struct InstanceDataHeader : Rw::InstanceDataHeader
struct InstanceDataHeader : rw::InstanceDataHeader
{
uint32 numMeshes;
InstanceData *instanceMeshes;
};
void *DestroyNativeData(void *object, int32, int32);
void ReadNativeData(Stream *stream, int32 len, void *object, int32, int32);
void WriteNativeData(Stream *stream, int32 len, void *object, int32, int32);
int32 GetSizeNativeData(void *object, int32, int32);
void RegisterNativeDataPlugin(void);
void *destroyNativeData(void *object, int32, int32);
void readNativeData(Stream *stream, int32 len, void *object, int32, int32);
void writeNativeData(Stream *stream, int32 len, void *object, int32, int32);
int32 getSizeNativeData(void *object, int32, int32);
void registerNativeDataPlugin(void);
void walkDMA(InstanceData *inst, void (*f)(uint32 *data, int32 size));
void sizedebug(InstanceData *inst);
@ -34,9 +34,9 @@ void unfixDmaOffsets(InstanceData *inst);
// Skin plugin
void ReadNativeSkin(Stream *stream, int32, void *object, int32 offset);
void WriteNativeSkin(Stream *stream, int32 len, void *object, int32 offset);
int32 GetSizeNativeSkin(void *object, int32 offset);
void readNativeSkin(Stream *stream, int32, void *object, int32 offset);
void writeNativeSkin(Stream *stream, int32 len, void *object, int32 offset);
int32 getSizeNativeSkin(void *object, int32 offset);
// ADC plugin
@ -48,7 +48,7 @@ struct ADCData
uint32 adcFormatted;
};
void RegisterADCPlugin(void);
void registerADCPlugin(void);
}
}

View File

@ -1,6 +1,8 @@
namespace rw {
namespace gl {
GLint linkProgram(GLint vertshader, GLint fragshader);
GLint compileShader(const char **src, int count, int type);
}
}

View File

@ -1,5 +1,6 @@
#include "rwtest.h"
namespace rw {
namespace gl {
GLint
@ -59,3 +60,4 @@ compileShader(const char **src, int count, int type)
}
}
}

View File

@ -9,21 +9,21 @@ Camera *camera;
GLint program;
GLuint vbo;
Rw::Clump *clump;
rw::Clump *clump;
char *filename;
void
renderAtomic(Rw::Atomic *atomic)
renderAtomic(rw::Atomic *atomic)
{
using namespace Rw;
using namespace rw;
static GLenum prim[] = {
GL_TRIANGLES, GL_TRIANGLE_STRIP
};
Geometry *geo = atomic->geometry;
if(!(geo->geoflags & Geometry::NATIVE))
Gl::Instance(atomic);
Gl::InstanceDataHeader *inst = (Gl::InstanceDataHeader*)geo->instData;
gl::instance(atomic);
gl::InstanceDataHeader *inst = (gl::InstanceDataHeader*)geo->instData;
MeshHeader *meshHeader = geo->meshHeader;
Frame *frm = atomic->frame;
@ -34,10 +34,10 @@ renderAtomic(Rw::Atomic *atomic)
glVertexAttrib4f(3, 0.0f, 0.0f, 0.0f, 1.0f);
glVertexAttrib3f(2, 0.0f, 0.0f, 0.0f);
if(inst->vbo == 0 && inst->ibo == 0)
Gl::UploadGeo(geo);
gl::uploadGeo(geo);
glBindBuffer(GL_ARRAY_BUFFER, inst->vbo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, inst->ibo);
Gl::SetAttribPointers(inst);
gl::setAttribPointers(inst);
uint64 offset = 0;
for(uint32 i = 0; i < meshHeader->numMeshes; i++){
@ -50,7 +50,7 @@ renderAtomic(Rw::Atomic *atomic)
color[3] = col[3] / 255.0f;
glUniform4fv(glGetUniformLocation(program, "matColor"),
1, color);
Rw::Gl::Texture *tex =(Rw::Gl::Texture*)mesh->material->texture;
rw::gl::Texture *tex =(rw::gl::Texture*)mesh->material->texture;
if(tex)
tex->bind(0);
else
@ -92,9 +92,9 @@ render(void)
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(3);
for(Rw::uint32 i = 0; i < clump->numAtomics; i++){
for(rw::uint32 i = 0; i < clump->numAtomics; i++){
char *name = PLUGINOFFSET(char, clump->atomicList[i]->frame,
Rw::NodeNameOffset);
gta::nodeNameOffset);
if(strstr(name, "_dam") || strstr(name, "_vlo"))
continue;
renderAtomic(clump->atomicList[i]);
@ -145,12 +145,12 @@ init(void)
"}\n"
"#endif\n";
const char *srcarr[] = { "#define VERTEX", shadersrc };
GLint vertshader = gl::compileShader(srcarr, 2, GL_VERTEX_SHADER);
GLint vertshader = rw::gl::compileShader(srcarr, 2, GL_VERTEX_SHADER);
assert(vertshader != 0);
srcarr[0] = "#define FRAGMENT";
GLint fragshader = gl::compileShader(srcarr, 2, GL_FRAGMENT_SHADER);
GLint fragshader = rw::gl::compileShader(srcarr, 2, GL_FRAGMENT_SHADER);
assert(fragshader != 0);
program = gl::linkProgram(vertshader, fragshader);
program = rw::gl::linkProgram(vertshader, fragshader);
assert(program != 0);
GLfloat vertarray[] = {
@ -181,31 +181,31 @@ init(void)
camera->setTarget(Vec3(0.0f, 0.0f, 0.0f));
camera->setPosition(Vec3(0.0f, 5.0f, 0.0f));
Rw::CurrentTexDictionary = new Rw::TexDictionary;
// Rw::Image::setSearchPath("/home/aap/gamedata/ps2/gtasa/models/gta3_archive/txd_extracted/");
// Rw::Image::setSearchPath("/home/aap/gamedata/ps2/gtavc/MODELS/gta3_archive/txd_extracted/");
Rw::Image::setSearchPath(
rw::currentTexDictionary = new rw::TexDictionary;
// rw::Image::setSearchPath("/home/aap/gamedata/ps2/gtasa/models/gta3_archive/txd_extracted/");
// rw::Image::setSearchPath("/home/aap/gamedata/ps2/gtavc/MODELS/gta3_archive/txd_extracted/");
rw::Image::setSearchPath(
"/home/aap/gamedata/ps2/gta3/MODELS/gta3_archive/txd_extracted/;//home/aap/gamedata/ps2/gtavc/MODELS/gta3_archive/txd_extracted/;/home/aap/gamedata/ps2/gtasa/models/gta3_archive/txd_extracted/");
//"D:\\rockstargames\\ps2\\gtavc\\MODELS\\gta3_archive\\txd_extracted\\;D:\\rockstargames\\ps2\\gtasa\\models\\gta3_archive\\txd_extracted\\");
Rw::Gl::RegisterNativeRaster();
Rw::RegisterMaterialRightsPlugin();
Rw::RegisterMatFXPlugin();
Rw::RegisterAtomicRightsPlugin();
Rw::RegisterHAnimPlugin();
Rw::RegisterNodeNamePlugin();
Rw::RegisterBreakableModelPlugin();
Rw::RegisterExtraVertColorPlugin();
Rw::Ps2::RegisterADCPlugin();
Rw::RegisterSkinPlugin();
Rw::RegisterNativeDataPlugin();
// Rw::Ps2::RegisterNativeDataPlugin();
Rw::RegisterMeshPlugin();
rw::gl::registerNativeRaster();
rw::registerMaterialRightsPlugin();
rw::registerMatFXPlugin();
rw::registerAtomicRightsPlugin();
rw::registerHAnimPlugin();
gta::registerNodeNamePlugin();
gta::registerBreakableModelPlugin();
gta::registerExtraVertColorPlugin();
rw::ps2::registerADCPlugin();
rw::registerSkinPlugin();
rw::registerNativeDataPlugin();
// rw::ps2::registerNativeDataPlugin();
rw::registerMeshPlugin();
Rw::StreamFile in;
rw::StreamFile in;
if(in.open(filename, "rb") == NULL)
printf("couldn't open file\n");
Rw::FindChunk(&in, Rw::ID_CLUMP, NULL, NULL);
clump = Rw::Clump::streamRead(&in);
rw::findChunk(&in, rw::ID_CLUMP, NULL, NULL);
clump = rw::Clump::streamRead(&in);
assert(clump);
in.close();
}

View File

@ -1,13 +1,15 @@
CC=ee-gcc
CXX=ee-g++
AS=ee-g++
LD=ee-g++
LD=ee-g++ -v
DVPAS=ee-dvp-as
LINK=-T$(PS2SDK)/ee/startup/linkfile
LINK=-T$(PS2SDK)/ee/startup/linkfile $(PS2SDK)/ee/startup/crt0.o
#LINK=-T$(PS2SDK)/ee/startup/linkfile $(PS2DEV)/ee/lib/gcc-lib/ee/3.2.2/crti.o $(PS2DEV)/ee/lib/gcc-lib/ee/3.2.2/crtbegin.o $(PS2SDK)/ee/startup/crt0.o
LIBPATH=-L$(PS2SDK)/ee/lib
INCPATH=-I$(PS2SDK)/ee/include -I$(PS2SDK)/common/include -I$(HOME)/src/librw
LIBS=$(HOME)/src/librw/librw-ps2.a -lc -lc -lkernel -lmf # g++ throws one -lc away, why? (unless -nostdlib)
#LIBS=-nostdlib $(HOME)/src/librw/librw-ps2.a -lc -lkernel -lmf -lstdc++ -lm -lc -lgcc -lgcc $(PS2DEV)/ee/lib/gcc-lib/ee/3.2.2/crtend.o $(PS2DEV)/ee/lib/gcc-lib/ee/3.2.2/crtn.o
CFLAGS = -c -Wall -nostdlib -fno-common -DPS2_EE $(INCPATH)
ASFLAGS = -c -xassembler-with-cpp
@ -20,8 +22,7 @@ HEADER=dma.h ee_regs.h gif.h gs.h mips_regs.h ps2.h math.h mesh.h
OBJ=$(C_SRC:.cpp=.o) $(S_SRC:.s=.o) vu.o defaultpipe.o skinpipe.o
$(OUT).elf: $(OBJ) $(HEADER)
$(LD) $(LDFLAGS) $(PS2SDK)/ee/startup/crt0.o \
$(LINK) $(OBJ) $(LIBS) -o $(OUT).elf
$(LD) $(LDFLAGS) $(LINK) $(OBJ) $(LIBS) -o $(OUT).elf
.cpp.o: $(HEADER)
$(CXX) $(CFLAGS) $< -o $@

View File

@ -1,6 +1,13 @@
//#include <cstdio>
//#include <cstring>
//#define _USE_MATH_DEFINES
//#include <cmath>
//#include <cassert>
#include <fstream>
#include <stdio.h>
#include <rw.h>
#include <src/gtaplg.h>
#include "ps2.h"
#include "dma.h"
#include "gif.h"
@ -9,9 +16,6 @@
#include "math.h"
#include "mesh.h"
#include <rw.h>
#include <src/gtaplg.h>
using namespace std;
extern uint32 MyDmaPacket[];
@ -26,21 +30,21 @@ extern uint32 geometryCall[];
extern uint32 defaultPipe[];
extern uint32 skinPipe[];
Rw::Clump *clump;
rw::Clump *clump;
void
drawAtomic(Rw::Atomic *atomic)
drawAtomic(rw::Atomic *atomic)
{
Rw::Geometry *geo = atomic->geometry;
rw::Geometry *geo = atomic->geometry;
assert(geo->instData != NULL);
Rw::Ps2::InstanceDataHeader *instData =
(Rw::Ps2::InstanceDataHeader*)geo->instData;
rw::ps2::InstanceDataHeader *instData =
(rw::ps2::InstanceDataHeader*)geo->instData;
atomic->frame->updateLTM();
matMult(vuMat, atomic->frame->ltm);
for(int i = 0; i < instData->numMeshes; i++){
if(instData->instanceMeshes[i].arePointersFixed == 0)
Rw::Ps2::fixDmaOffsets(&instData->instanceMeshes[i]);
rw::ps2::fixDmaOffsets(&instData->instanceMeshes[i]);
geometryCall[1] = (uint32)instData->instanceMeshes[i].data;
vuGIFtag[0] = MAKE_GIF_TAG(0,1,1,0xC,0,2);
@ -49,9 +53,9 @@ drawAtomic(Rw::Atomic *atomic)
vuMatcolor[1] = 1.0f;
vuMatcolor[2] = 1.0f;
vuMatcolor[3] = 0.5f;
Rw::Skin *skin =
*PLUGINOFFSET(Rw::Skin*, geo, Rw::SkinGlobals.offset);
if(Rw::SkinGlobals.offset && skin){
rw::Skin *skin =
*PLUGINOFFSET(rw::Skin*, geo, rw::skinGlobals.offset);
if(rw::skinGlobals.offset && skin){
geometryCall[3] = 0x020000DC;
mpgCall[1] = (uint32)skinPipe;
}else{
@ -90,7 +94,7 @@ draw(void)
for(int i = 0; i < clump->numAtomics; i++){
char *name = PLUGINOFFSET(char, clump->atomicList[i]->frame,
Rw::NodeNameOffset);
gta::nodeNameOffset);
if(strstr(name, "_dam") || strstr(name, "_vlo"))
continue;
matCopy(m, vuMat);
@ -119,19 +123,19 @@ main()
gsInit();
printf("hallo\n");
Rw::RegisterMaterialRightsPlugin();
Rw::RegisterMatFXPlugin();
Rw::RegisterAtomicRightsPlugin();
Rw::RegisterNodeNamePlugin();
Rw::RegisterBreakableModelPlugin();
Rw::RegisterExtraVertColorPlugin();
Rw::Ps2::RegisterADCPlugin();
Rw::RegisterSkinPlugin();
Rw::RegisterNativeDataPlugin();
// Rw::Ps2::RegisterNativeDataPlugin();
Rw::RegisterMeshPlugin();
rw::registerMaterialRightsPlugin();
rw::registerMatFXPlugin();
rw::registerAtomicRightsPlugin();
gta::registerNodeNamePlugin();
gta::registerBreakableModelPlugin();
gta::registerExtraVertColorPlugin();
rw::ps2::registerADCPlugin();
rw::registerSkinPlugin();
rw::registerNativeDataPlugin();
// rw::ps2::registerNativeDataPlugin();
rw::registerMeshPlugin();
// Rw::StreamFile in;
// rw::StreamFile in;
// in.open("host:player-vc-ps2.dff", "rb");
// FILE *cf = fopen("host:player-vc-ps2.dff", "rb");
@ -139,25 +143,25 @@ main()
// FILE *cf = fopen("host:admiral-ps2.dff", "rb");
assert(cf != NULL);
fseek(cf, 0, SEEK_END);
Rw::uint32 len = ftell(cf);
rw::uint32 len = ftell(cf);
fseek(cf, 0, SEEK_SET);
Rw::uint8 *data = new Rw::uint8[len];
rw::uint8 *data = new rw::uint8[len];
fread(data, len, 1, cf);
fclose(cf);
Rw::StreamMemory in;
rw::StreamMemory in;
in.open(data, len);
printf("opened file\n");
Rw::FindChunk(&in, Rw::ID_CLUMP, NULL, NULL);
rw::findChunk(&in, rw::ID_CLUMP, NULL, NULL);
printf("found chunk\n");
clump = Rw::Clump::streamRead(&in);
clump = rw::Clump::streamRead(&in);
printf("read file\n");
in.close();
printf("closed file\n");
delete[] data;
data = new Rw::uint8[256*1024];
Rw::StreamMemory out;
data = new rw::uint8[256*1024];
rw::StreamMemory out;
out.open(data, 0, 256*1024);
clump->streamWrite(&out);
// cf = fopen("host:out-ps2.dff", "wb");
@ -167,7 +171,7 @@ main()
out.close();
delete[] data;
// Rw::StreamFile out;
// rw::StreamFile out;
// out.open("host:out-ps2.dff", "wb");
// c->streamWrite(&out);
// out.close();
@ -178,9 +182,9 @@ main()
vuOffset[1] = 2048.0f;
for(int i = 0; i < clump->numAtomics; i++){
Rw::Atomic *a = clump->atomicList[i];
rw::Atomic *a = clump->atomicList[i];
char *name =
PLUGINOFFSET(char, a->frame, Rw::NodeNameOffset);
PLUGINOFFSET(char, a->frame, gta::nodeNameOffset);
printf("%s\n", name);
}

View File

@ -1,4 +1,5 @@
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include "math.h"