2015-01-26 19:23:45 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstring>
|
|
|
|
#define _USE_MATH_DEFINES
|
|
|
|
#include <cmath>
|
|
|
|
#include <cassert>
|
2015-01-18 18:35:23 +00:00
|
|
|
|
2015-01-25 21:27:03 +00:00
|
|
|
#include <rw.h>
|
|
|
|
#include <src/gtaplg.h>
|
|
|
|
|
2015-01-18 18:35:23 +00:00
|
|
|
#include "ps2.h"
|
|
|
|
#include "dma.h"
|
|
|
|
#include "gif.h"
|
|
|
|
#include "gs.h"
|
|
|
|
|
|
|
|
#include "math.h"
|
|
|
|
#include "mesh.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
extern uint32 MyDmaPacket[];
|
|
|
|
extern Matrix vuMat;
|
|
|
|
extern float vuOffset[];
|
|
|
|
extern uint64 vuGIFtag[];
|
|
|
|
extern float vuMatcolor[];
|
|
|
|
extern float vuSurfProps[];
|
|
|
|
extern uint32 vuGeometry[];
|
|
|
|
extern uint32 mpgCall[];
|
|
|
|
extern uint32 geometryCall[];
|
|
|
|
extern uint32 defaultPipe[];
|
|
|
|
extern uint32 skinPipe[];
|
|
|
|
|
2015-01-25 21:27:03 +00:00
|
|
|
rw::Clump *clump;
|
2015-01-18 18:35:23 +00:00
|
|
|
|
|
|
|
void
|
2015-01-25 21:27:03 +00:00
|
|
|
drawAtomic(rw::Atomic *atomic)
|
2015-01-18 18:35:23 +00:00
|
|
|
{
|
2015-01-25 21:27:03 +00:00
|
|
|
rw::Geometry *geo = atomic->geometry;
|
2015-01-18 18:35:23 +00:00
|
|
|
assert(geo->instData != NULL);
|
2015-01-25 21:27:03 +00:00
|
|
|
rw::ps2::InstanceDataHeader *instData =
|
|
|
|
(rw::ps2::InstanceDataHeader*)geo->instData;
|
2015-01-18 18:35:23 +00:00
|
|
|
|
|
|
|
atomic->frame->updateLTM();
|
|
|
|
matMult(vuMat, atomic->frame->ltm);
|
|
|
|
for(int i = 0; i < instData->numMeshes; i++){
|
|
|
|
if(instData->instanceMeshes[i].arePointersFixed == 0)
|
2015-01-25 21:27:03 +00:00
|
|
|
rw::ps2::fixDmaOffsets(&instData->instanceMeshes[i]);
|
2015-01-18 18:35:23 +00:00
|
|
|
geometryCall[1] = (uint32)instData->instanceMeshes[i].data;
|
|
|
|
|
|
|
|
vuGIFtag[0] = MAKE_GIF_TAG(0,1,1,0xC,0,2);
|
|
|
|
vuGIFtag[1] = 0x41;
|
|
|
|
vuMatcolor[0] = 1.0f;
|
|
|
|
vuMatcolor[1] = 1.0f;
|
|
|
|
vuMatcolor[2] = 1.0f;
|
|
|
|
vuMatcolor[3] = 0.5f;
|
2015-01-25 21:27:03 +00:00
|
|
|
rw::Skin *skin =
|
|
|
|
*PLUGINOFFSET(rw::Skin*, geo, rw::skinGlobals.offset);
|
|
|
|
if(rw::skinGlobals.offset && skin){
|
2015-01-18 18:35:23 +00:00
|
|
|
geometryCall[3] = 0x020000DC;
|
|
|
|
mpgCall[1] = (uint32)skinPipe;
|
|
|
|
}else{
|
|
|
|
geometryCall[3] = 0x02000114;
|
|
|
|
mpgCall[1] = (uint32)defaultPipe;
|
|
|
|
}
|
|
|
|
|
|
|
|
SET_REG32(D1_QWC, 0x00);
|
|
|
|
SET_REG32(D1_TADR, (uint)MyDmaPacket & 0x0FFFFFFF);
|
|
|
|
FlushCache(0);
|
|
|
|
SET_REG32(D1_CHCR, MAKE_DN_CHCR(1, 1, 0, 1, 0, 1));
|
|
|
|
DMA_WAIT(D1_CHCR);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
draw(void)
|
|
|
|
{
|
|
|
|
Matrix m;
|
|
|
|
static float rot = 0.0f;
|
|
|
|
|
|
|
|
gsClear();
|
|
|
|
|
|
|
|
matMakeIdentity(mathModelViewMat);
|
|
|
|
matTranslate(mathModelViewMat, 0.0f, 0.0f, -34.0f);
|
|
|
|
// matTranslate(mathModelViewMat, 0.0f, 0.0f, -10.0f);
|
|
|
|
// matTranslate(mathModelViewMat, 0.0f, 0.0f, -8.0f);
|
|
|
|
matRotateX(mathModelViewMat, rot);
|
|
|
|
matRotateY(mathModelViewMat, rot);
|
|
|
|
matRotateZ(mathModelViewMat, rot);
|
|
|
|
matInverse(mathNormalMat, mathModelViewMat);
|
|
|
|
|
|
|
|
matCopy(vuMat, mathProjectionMat);
|
|
|
|
matMult(vuMat, mathModelViewMat);
|
|
|
|
|
|
|
|
for(int i = 0; i < clump->numAtomics; i++){
|
|
|
|
char *name = PLUGINOFFSET(char, clump->atomicList[i]->frame,
|
2015-01-25 21:27:03 +00:00
|
|
|
gta::nodeNameOffset);
|
2015-01-18 18:35:23 +00:00
|
|
|
if(strstr(name, "_dam") || strstr(name, "_vlo"))
|
|
|
|
continue;
|
|
|
|
matCopy(m, vuMat);
|
|
|
|
drawAtomic(clump->atomicList[i]);
|
|
|
|
matCopy(vuMat, m);
|
|
|
|
}
|
|
|
|
|
|
|
|
rot += 0.01f;
|
|
|
|
if(rot > 2*M_PI)
|
|
|
|
rot -= 2*M_PI;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main()
|
|
|
|
{
|
|
|
|
GsState gss;
|
|
|
|
gsCurState = &gss;
|
|
|
|
|
|
|
|
dmaReset(1);
|
|
|
|
|
|
|
|
// gsInitState(NONINTERLACED, PAL, FRAME);
|
|
|
|
// gsInitState(INTERLACED, PAL, FRAME);
|
|
|
|
gsInitState(INTERLACED, PAL, FIELD);
|
|
|
|
gsCurState->clearcol = 0x80404040;
|
|
|
|
|
|
|
|
gsInit();
|
|
|
|
|
2015-01-26 19:23:45 +00:00
|
|
|
gta::registerEnvSpecPlugin();
|
2015-01-25 21:27:03 +00:00
|
|
|
rw::registerMatFXPlugin();
|
2015-01-26 19:23:45 +00:00
|
|
|
rw::registerMaterialRightsPlugin();
|
2015-01-25 21:27:03 +00:00
|
|
|
rw::registerAtomicRightsPlugin();
|
2015-01-26 19:23:45 +00:00
|
|
|
rw::registerHAnimPlugin();
|
2015-01-25 21:27:03 +00:00
|
|
|
gta::registerNodeNamePlugin();
|
|
|
|
gta::registerBreakableModelPlugin();
|
|
|
|
gta::registerExtraVertColorPlugin();
|
|
|
|
rw::ps2::registerADCPlugin();
|
|
|
|
rw::registerSkinPlugin();
|
|
|
|
rw::registerNativeDataPlugin();
|
2015-01-26 19:23:45 +00:00
|
|
|
// rw::ps2::registerNativeDataPlugin();
|
2015-01-25 21:27:03 +00:00
|
|
|
rw::registerMeshPlugin();
|
|
|
|
|
|
|
|
// rw::StreamFile in;
|
2015-01-18 18:35:23 +00:00
|
|
|
// in.open("host:player-vc-ps2.dff", "rb");
|
|
|
|
|
|
|
|
// FILE *cf = fopen("host:player-vc-ps2.dff", "rb");
|
|
|
|
FILE *cf = fopen("host:od_newscafe_dy-ps2.dff", "rb");
|
|
|
|
// FILE *cf = fopen("host:admiral-ps2.dff", "rb");
|
|
|
|
assert(cf != NULL);
|
|
|
|
fseek(cf, 0, SEEK_END);
|
2015-01-25 21:27:03 +00:00
|
|
|
rw::uint32 len = ftell(cf);
|
2015-01-18 18:35:23 +00:00
|
|
|
fseek(cf, 0, SEEK_SET);
|
2015-01-25 21:27:03 +00:00
|
|
|
rw::uint8 *data = new rw::uint8[len];
|
2015-01-18 18:35:23 +00:00
|
|
|
fread(data, len, 1, cf);
|
|
|
|
fclose(cf);
|
2015-01-25 21:27:03 +00:00
|
|
|
rw::StreamMemory in;
|
2015-01-18 18:35:23 +00:00
|
|
|
in.open(data, len);
|
|
|
|
|
|
|
|
printf("opened file\n");
|
2015-01-25 21:27:03 +00:00
|
|
|
rw::findChunk(&in, rw::ID_CLUMP, NULL, NULL);
|
2015-01-18 18:35:23 +00:00
|
|
|
printf("found chunk\n");
|
2015-01-25 21:27:03 +00:00
|
|
|
clump = rw::Clump::streamRead(&in);
|
2015-01-18 18:35:23 +00:00
|
|
|
printf("read file\n");
|
|
|
|
in.close();
|
|
|
|
printf("closed file\n");
|
|
|
|
delete[] data;
|
|
|
|
|
2015-01-25 21:27:03 +00:00
|
|
|
data = new rw::uint8[256*1024];
|
|
|
|
rw::StreamMemory out;
|
2015-01-18 18:35:23 +00:00
|
|
|
out.open(data, 0, 256*1024);
|
|
|
|
clump->streamWrite(&out);
|
|
|
|
// cf = fopen("host:out-ps2.dff", "wb");
|
|
|
|
// assert(cf != NULL);
|
|
|
|
// fwrite(data, out.getLength(), 1, cf);
|
|
|
|
// fclose(cf);
|
|
|
|
out.close();
|
|
|
|
delete[] data;
|
|
|
|
|
2015-01-25 21:27:03 +00:00
|
|
|
// rw::StreamFile out;
|
2015-01-18 18:35:23 +00:00
|
|
|
// out.open("host:out-ps2.dff", "wb");
|
|
|
|
// c->streamWrite(&out);
|
|
|
|
// out.close();
|
|
|
|
//
|
|
|
|
// printf("wrote file\n");
|
|
|
|
|
|
|
|
vuOffset[0] = 2048.0f;
|
|
|
|
vuOffset[1] = 2048.0f;
|
|
|
|
|
|
|
|
for(int i = 0; i < clump->numAtomics; i++){
|
2015-01-25 21:27:03 +00:00
|
|
|
rw::Atomic *a = clump->atomicList[i];
|
2015-01-18 18:35:23 +00:00
|
|
|
char *name =
|
2015-01-25 21:27:03 +00:00
|
|
|
PLUGINOFFSET(char, a->frame, gta::nodeNameOffset);
|
2015-01-18 18:35:23 +00:00
|
|
|
printf("%s\n", name);
|
|
|
|
}
|
|
|
|
|
|
|
|
// gsDumpState();
|
|
|
|
|
|
|
|
// matPerspective(mathProjectionMat, 60.0f, (float)gss.width/gss.height,
|
|
|
|
// matPerspective(mathProjectionMat, 60.0f, (float)gss.width/gss.dh,
|
|
|
|
// matPerspective(mathProjectionMat, 60.0f, 4.0/3.0, 1.0f, 100.0f);
|
|
|
|
// matPerspective(mathProjectionMat, 60.0f, 16.0/9.0, 1.0f, 100.0f);
|
|
|
|
matPerspective2(mathProjectionMat, 60.0f, 4.0/3.0, gss.width,gss.height,
|
|
|
|
1.0f, 100.0f, 16777216, 1);
|
|
|
|
|
|
|
|
for(;;){
|
|
|
|
draw();
|
|
|
|
gsFlip();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|