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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,13 +1,15 @@
CC=ee-gcc CC=ee-gcc
CXX=ee-g++ CXX=ee-g++
AS=ee-g++ AS=ee-g++
LD=ee-g++ LD=ee-g++ -v
DVPAS=ee-dvp-as 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 LIBPATH=-L$(PS2SDK)/ee/lib
INCPATH=-I$(PS2SDK)/ee/include -I$(PS2SDK)/common/include -I$(HOME)/src/librw 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=$(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) CFLAGS = -c -Wall -nostdlib -fno-common -DPS2_EE $(INCPATH)
ASFLAGS = -c -xassembler-with-cpp 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 OBJ=$(C_SRC:.cpp=.o) $(S_SRC:.s=.o) vu.o defaultpipe.o skinpipe.o
$(OUT).elf: $(OBJ) $(HEADER) $(OUT).elf: $(OBJ) $(HEADER)
$(LD) $(LDFLAGS) $(PS2SDK)/ee/startup/crt0.o \ $(LD) $(LDFLAGS) $(LINK) $(OBJ) $(LIBS) -o $(OUT).elf
$(LINK) $(OBJ) $(LIBS) -o $(OUT).elf
.cpp.o: $(HEADER) .cpp.o: $(HEADER)
$(CXX) $(CFLAGS) $< -o $@ $(CXX) $(CFLAGS) $< -o $@

View File

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

View File

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