From e9819e9f8a8b1bbf948d0f8fdf1610a280eae9bc Mon Sep 17 00:00:00 2001 From: Angelo Papenhoff Date: Sun, 28 Dec 2014 12:06:19 +0100 Subject: [PATCH] Some fixes for PS2. --- Makefile.ps2 | 3 ++- TODO | 3 +++ dffwrite.cpp | 7 ++++--- src/clump.cpp | 4 ---- src/plugins.cpp | 21 ++++++++++++++++++++- src/rwbase.cpp | 5 ++++- src/rwobjects.h | 1 + 7 files changed, 34 insertions(+), 10 deletions(-) diff --git a/Makefile.ps2 b/Makefile.ps2 index 328211b..f8586c7 100644 --- a/Makefile.ps2 +++ b/Makefile.ps2 @@ -12,13 +12,14 @@ SRC := $(patsubst %.cpp,$(SRCDIR)/%.cpp, rwbase.cpp clump.cpp\ OBJ := $(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.o,$(SRC)) DEP := $(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.d,$(SRC)) CFLAGS=-Wall -g $(BUILDDEF) #-Wno-parentheses #-Wconversion +INCPATH=-I$(PS2SDK)/ee/include -I$(PS2SDK)/common/include LIB=librw-$(BUILD).a $(LIB): $(OBJ) ar scr $@ $(OBJ) $(BUILDDIR)/%.o: $(SRCDIR)/%.cpp - $(CXX) $(CFLAGS) -c $< -o $@ + $(CXX) $(CFLAGS) $(INCPATH) -c $< -o $@ $(BUILDDIR)/%.d: $(SRCDIR)/%.cpp $(CXX) -MM -MT '$(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.o,$<)' $(CFLAGS) $< > $@ diff --git a/TODO b/TODO index de1628c..73a0cae 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,6 @@ +BUGS: + - fseek with negative offset on ps2 over ps2link messes up the current position + Clump & related: - make pointer arrays into lists - work on ref counts, destruction, copying etc. diff --git a/dffwrite.cpp b/dffwrite.cpp index 496daac..e8a2d03 100644 --- a/dffwrite.cpp +++ b/dffwrite.cpp @@ -21,6 +21,7 @@ main(int argc, char *argv[]) registerNodeNamePlugin(); registerBreakableModelPlugin(); registerNativeDataPlugin(); +// registerNativeDataPS2Plugin(); registerMeshPlugin(); Rw::Clump *c; @@ -32,9 +33,9 @@ main(int argc, char *argv[]) assert(c != NULL); in.close(); - Rw::Image *tga = Rw::readTGA("b.tga"); - assert(tga != NULL); - Rw::writeTGA(tga, "out.tga"); +// Rw::Image *tga = Rw::readTGA("b.tga"); +// assert(tga != NULL); +// Rw::writeTGA(tga, "out.tga"); // for(Rw::int32 i = 0; i < c->numAtomics; i++) // Rw::Gl::Instance(c->atomicList[i]); diff --git a/src/clump.cpp b/src/clump.cpp index 62d2375..b18267b 100644 --- a/src/clump.cpp +++ b/src/clump.cpp @@ -149,7 +149,6 @@ Clump::streamRead(Stream *stream) uint32 length, version; int32 buf[3]; Clump *clump; -printf("- before chunk: %X\n", stream->tell()); assert(FindChunk(stream, ID_STRUCT, &length, &version)); clump = new Clump; stream->read(buf, length); @@ -161,14 +160,12 @@ printf("- before chunk: %X\n", stream->tell()); clump->numCameras = buf[2]; } -printf("- frame list: %X\n", stream->tell()); // Frame list Frame **frameList; int32 numFrames; clump->frameListStreamRead(stream, &frameList, &numFrames); clump->parent = (void*)frameList[0]; -printf("- geometry list: %X\n", stream->tell()); // Geometry list int32 numGeometries = 0; assert(FindChunk(stream, ID_GEOMETRYLIST, NULL, NULL)); @@ -182,7 +179,6 @@ printf("- geometry list: %X\n", stream->tell()); geometryList[i] = Geometry::streamRead(stream); } -printf("- atomics: %X\n", stream->tell()); // Atomics if(clump->numAtomics) clump->atomicList = new Atomic*[clump->numAtomics]; diff --git a/src/plugins.cpp b/src/plugins.cpp index 5f47e55..9894232 100644 --- a/src/plugins.cpp +++ b/src/plugins.cpp @@ -270,6 +270,17 @@ registerNativeDataPlugin(void) (StreamGetSize)getSizeNativeData); } +void +registerNativeDataPS2Plugin(void) +{ + Geometry::registerPlugin(0, ID_NATIVEDATA, + NULL, DestroyNativeDataPS2, NULL); + Geometry::registerPluginStream(ID_NATIVEDATA, + (StreamRead)ReadNativeDataPS2, + (StreamWrite)WriteNativeDataPS2, + (StreamGetSize)GetSizeNativeDataPS2); +} + // Breakable Model // TODO: put this in a header @@ -290,6 +301,13 @@ struct Breakable float32 (*surfaceProps)[3]; }; +static void* +createBreakableModel(void *object, int32 offset, int32) +{ + *PLUGINOFFSET(uint8*, object, offset) = 0; + return object; +} + static void* destroyBreakableModel(void *object, int32 offset, int32) { @@ -371,7 +389,8 @@ getSizeBreakableModel(void *object, int32 offset, int32) void registerBreakableModelPlugin(void) { - Geometry::registerPlugin(sizeof(Breakable*), ID_BREAKABLE, NULL, + Geometry::registerPlugin(sizeof(Breakable*), ID_BREAKABLE, + createBreakableModel, destroyBreakableModel, NULL); Geometry::registerPluginStream(ID_BREAKABLE, (StreamRead)readBreakableModel, diff --git a/src/rwbase.cpp b/src/rwbase.cpp index 5c21f7a..1501c64 100644 --- a/src/rwbase.cpp +++ b/src/rwbase.cpp @@ -129,13 +129,14 @@ StreamFile::close(void) uint32 StreamFile::write(const void *data, uint32 length) { +//printf("write %d bytes @ %x\n", length, this->tell()); return fwrite(data, length, 1, this->file); } uint32 StreamFile::read(void *data, uint32 length) { - printf("read %d bytes @ %x\n", length, this->tell()); +//printf("read %d bytes @ %x\n", length, this->tell()); return fread(data, length, 1, this->file); } @@ -164,6 +165,7 @@ WriteChunkHeader(Stream *s, int32 type, int32 size) int32 type, size; uint32 id; } buf = { type, size, LibraryIDPack(Version, Build) }; +//printf("- write chunk %x @ %x\n", buf.type, s->tell()); s->write(&buf, 12); return true; } @@ -198,6 +200,7 @@ FindChunk(Stream *s, uint32 type, uint32 *length, uint32 *version) *length = header.length; if(version) *version = header.version; +//printf("- chunk %x @ %x\n", header.type, s->tell()-12); return true; } s->seek(header.length); diff --git a/src/rwobjects.h b/src/rwobjects.h index 016317e..d9c9f97 100644 --- a/src/rwobjects.h +++ b/src/rwobjects.h @@ -230,4 +230,5 @@ private: void registerNodeNamePlugin(void); void registerMeshPlugin(void); void registerNativeDataPlugin(void); +void registerNativeDataPS2Plugin(void); void registerBreakableModelPlugin(void);