Added new level loader

This commit is contained in:
Montagna Marco 2020-05-30 19:57:21 +02:00
parent d7016a9209
commit 1e786688ec
5 changed files with 441 additions and 194 deletions

View file

@ -1,14 +1,16 @@
#include "framework.h" #include "framework.h"
#include "newlevel.h" #include "levelloader.h"
#include "ChunkId.h" #include "ChunkId.h"
#include "ChunkReader.h" #include "ChunkReader.h"
#include "level.h"
#include <Specific\setup.h>
TrLevel::TrLevel(string filename) LevelLoader::LevelLoader(string filename)
{ {
m_filename = filename; m_filename = filename;
} }
TrLevel::~TrLevel() LevelLoader::~LevelLoader()
{ {
delete m_chunkTextureAtlas; delete m_chunkTextureAtlas;
delete m_chunkTextureColor; delete m_chunkTextureColor;
@ -57,9 +59,10 @@ TrLevel::~TrLevel()
delete m_chunkDummy; delete m_chunkDummy;
delete m_chunkAnimatedTextureSequence; delete m_chunkAnimatedTextureSequence;
delete m_chunkAnimatedTextureFrame; delete m_chunkAnimatedTextureFrame;
delete m_chunkFloorData;
} }
bool TrLevel::Load() bool LevelLoader::Load()
{ {
m_stream = new FileStream((char*)m_filename.c_str(), true, false); m_stream = new FileStream((char*)m_filename.c_str(), true, false);
m_reader = new ChunkReader(m_magicNumber, m_stream); m_reader = new ChunkReader(m_magicNumber, m_stream);
@ -72,6 +75,22 @@ bool TrLevel::Load()
return readAnimatedTextureSequence(); return readAnimatedTextureSequence();
else if (id->EqualsTo(m_chunkRoom)) else if (id->EqualsTo(m_chunkRoom))
return readRoom(); return readRoom();
else if (id->EqualsTo(m_chunkFloorData))
return readRoom();
else if (id->EqualsTo(m_chunkMesh))
return readMesh();
else if (id->EqualsTo(m_chunkBone))
return readBone();
else if (id->EqualsTo(m_chunkStateChange))
return readChange();
else if (id->EqualsTo(m_chunkAnimDispatch))
return readDispatch();
else if (id->EqualsTo(m_chunkKeyFrame))
return readKeyFrame();
else if (id->EqualsTo(m_chunkAnimCommand))
return readCommand();
else if (id->EqualsTo(m_chunkAnimation))
return readAnimation();
else if (id->EqualsTo(m_chunkMoveable)) else if (id->EqualsTo(m_chunkMoveable))
return readMoveable(); return readMoveable();
else if (id->EqualsTo(m_chunkStatic)) else if (id->EqualsTo(m_chunkStatic))
@ -94,8 +113,12 @@ bool TrLevel::Load()
return readSoundMap(); return readSoundMap();
else if (id->EqualsTo(m_chunkSoundDetail)) else if (id->EqualsTo(m_chunkSoundDetail))
return readSoundDetail(); return readSoundDetail();
else if (id->EqualsTo(m_chunkSample))
return readSample();
else if (id->EqualsTo(m_chunkBox)) else if (id->EqualsTo(m_chunkBox))
return readBox(); return readBox();
else if (id->EqualsTo(m_chunkOverlap))
return readOverlap();
else if (id->EqualsTo(m_chunkZone)) else if (id->EqualsTo(m_chunkZone))
return readZones(); return readZones();
else else
@ -111,7 +134,7 @@ bool TrLevel::Load()
ChunkReader* m_reader; ChunkReader* m_reader;
bool TrLevel::readTexture() bool LevelLoader::readTexture()
{ {
TrTexturePage texture; TrTexturePage texture;
@ -135,11 +158,12 @@ bool TrLevel::readTexture()
} }
}, 0); }, 0);
textures.push_back(texture); m_level.textures.push_back(texture);
return true; return true;
} }
bool TrLevel::readAnimatedTextureSequence() bool LevelLoader::readAnimatedTextureSequence()
{ {
TrAnimatedTexturesSequence sequence; TrAnimatedTexturesSequence sequence;
@ -170,11 +194,12 @@ bool TrLevel::readAnimatedTextureSequence()
} }
}, 0); }, 0);
animatedTextures.push_back(sequence); m_level.animatedTextures.push_back(sequence);
return true; return true;
} }
bool TrLevel::readRoom() bool LevelLoader::readRoom()
{ {
TrRoom room; TrRoom room;
@ -238,7 +263,10 @@ bool TrLevel::readRoom()
else if (id->EqualsTo(m_chunkRoomSector)) else if (id->EqualsTo(m_chunkRoomSector))
{ {
TrSector sector; TrSector sector;
m_stream->ReadInt32(&sector.boxIndex);
m_stream->ReadInt32(&sector.floorDataIndex);
m_stream->ReadInt32(&sector.floorDataCount);
m_stream->ReadInt32(&sector.box);
m_stream->ReadInt32(&sector.pathfindingFlags); m_stream->ReadInt32(&sector.pathfindingFlags);
m_stream->ReadInt32(&sector.stepSound); m_stream->ReadInt32(&sector.stepSound);
m_stream->ReadInt32(&sector.roomBelow); m_stream->ReadInt32(&sector.roomBelow);
@ -265,7 +293,7 @@ bool TrLevel::readRoom()
return true; return true;
} }
bool TrLevel::readBucket(TrBucket* bucket) bool LevelLoader::readBucket(TrBucket* bucket)
{ {
m_reader->ReadChunks([this, bucket](ChunkId * id, long size, int arg) { m_reader->ReadChunks([this, bucket](ChunkId * id, long size, int arg) {
if (id->EqualsTo(m_chunkMaterial)) if (id->EqualsTo(m_chunkMaterial))
@ -371,15 +399,30 @@ bool TrLevel::readBucket(TrBucket* bucket)
return true; return true;
} }
bool TrLevel::readMesh(TrMesh* mesh) bool LevelLoader::readFloorData()
{ {
m_stream->ReadBoundingSphere(&mesh->sphere); int count;
m_reader->ReadChunks([this, mesh](ChunkId * id, long size, int arg) { m_stream->ReadInt32(&count);
for (int i = 0; i < count; i++)
{
int data;
m_stream->ReadInt32(&data);
m_level.floorData.push_back(data);
}
return true;
}
bool LevelLoader::readMesh()
{
TrMesh mesh;
m_stream->ReadBoundingSphere(&mesh.sphere);
m_reader->ReadChunks([this, &mesh](ChunkId * id, long size, int arg) {
if (id->EqualsTo(m_chunkBucket)) if (id->EqualsTo(m_chunkBucket))
{ {
TrBucket bucket; TrBucket bucket;
readBucket(&bucket); readBucket(&bucket);
mesh->buckets.push_back(bucket); mesh.buckets.push_back(bucket);
return true; return true;
} }
else else
@ -387,23 +430,36 @@ bool TrLevel::readMesh(TrMesh* mesh)
return false; return false;
} }
}, 0); }, 0);
m_level.meshes.push_back(mesh);
return true; return true;
} }
bool TrLevel::readAnimation(TrAnimation* animation) bool LevelLoader::readAnimation()
{ {
m_stream->ReadInt32(&animation->framerate); TrAnimation animation;
m_stream->ReadInt32(&animation->state);
m_stream->ReadInt32(&animation->nextAnimation);
m_stream->ReadInt32(&animation->nextFrame);
m_stream->ReadInt32(&animation->frameStart);
m_stream->ReadInt32(&animation->frameEnd);
m_stream->ReadFloat(&animation->speed);
m_stream->ReadFloat(&animation->acceleration);
m_stream->ReadFloat(&animation->lateralSpeed);
m_stream->ReadFloat(&animation->lateralAcceleration);
m_reader->ReadChunks([this, animation](ChunkId * id, long size, int arg) { m_stream->ReadInt32(&animation.framerate);
m_stream->ReadInt32(&animation.state);
m_stream->ReadInt32(&animation.nextAnimation);
m_stream->ReadInt32(&animation.nextFrame);
m_stream->ReadInt32(&animation.frameBase);
m_stream->ReadInt32(&animation.frameEnd);
m_stream->ReadFloat(&animation.speed);
m_stream->ReadFloat(&animation.acceleration);
m_stream->ReadFloat(&animation.lateralSpeed);
m_stream->ReadFloat(&animation.lateralAcceleration);
m_stream->ReadInt32(&animation.framesIndex);
m_stream->ReadInt32(&animation.framesCount);
m_stream->ReadInt32(&animation.changesIndex);
m_stream->ReadInt32(&animation.changesCount);
m_stream->ReadInt32(&animation.commandsIndex);
m_stream->ReadInt32(&animation.commandsCount);
m_reader->ReadChunks([this, &animation](ChunkId * id, long size, int arg) {
return false;
/*
if (id->EqualsTo(m_chunkKeyFrame)) if (id->EqualsTo(m_chunkKeyFrame))
{ {
TrKeyFrame kf; TrKeyFrame kf;
@ -470,20 +526,112 @@ bool TrLevel::readAnimation(TrAnimation* animation)
else else
{ {
return false; return false;
} }*/
}, 0); }, 0);
m_level.animations.push_back(animation);
return true; return true;
} }
bool TrLevel::readMoveable() bool LevelLoader::readChange()
{
TrStateChange change;
m_stream->ReadInt32(&change.state);
m_stream->ReadInt32(&change.dispatchIndex);
m_stream->ReadInt32(&change.dispatchCount);
m_reader->ReadChunks([this, &change](ChunkId * id, long size, int arg) {
return false;
}, 0);
m_level.changes.push_back(change);
return true;
}
bool LevelLoader::readDispatch()
{
TrAnimDispatch dispatch;
m_stream->ReadInt32(&dispatch.inFrame);
m_stream->ReadInt32(&dispatch.outFrame);
m_stream->ReadInt32(&dispatch.nextAnimation);
m_stream->ReadInt32(&dispatch.nextFrame);
m_level.dispatches.push_back(dispatch);
return true;
}
bool LevelLoader::readBone()
{
TrBone bone;
m_stream->ReadInt32(&bone.opcode);
m_stream->ReadVector3(&bone.offset);
m_level.bones.push_back(bone);
return true;
}
bool LevelLoader::readCommand()
{
TrAnimCommand cmd;
m_stream->ReadInt32(&cmd.type);
m_stream->ReadInt32(&cmd.frame);
int count = 0;
m_stream->ReadInt32(&count);
for (int i = 0; i < count; i++)
{
int p;
m_stream->ReadInt32(&p);
cmd.params.push_back(p);
}
m_level.commands.push_back(cmd);
return true;
}
bool LevelLoader::readKeyFrame()
{
TrKeyFrame kf;
m_stream->ReadVector3(&kf.origin);
m_stream->ReadBoundingBox(&kf.boundingBox);
int count = 0;
m_stream->ReadInt32(&count);
for (int i = 0; i < count; i++)
{
Quaternion q;
m_stream->ReadQuaternion(&q);
kf.angles.push_back(q);
}
m_level.frames.push_back(kf);
return true;
}
bool LevelLoader::readMoveable()
{ {
TrMoveable moveable; TrMoveable moveable;
m_stream->ReadInt32(&moveable.id); m_stream->ReadInt32(&moveable.id);
m_stream->ReadInt32(&moveable.meshIndex);
m_stream->ReadInt32(&moveable.meshCount);
m_stream->ReadInt32(&moveable.bonesIndex);
m_stream->ReadInt32(&moveable.bonesCount);
m_stream->ReadInt32(&moveable.animationIndex);
m_stream->ReadInt32(&moveable.animationCount);
m_reader->ReadChunks([this, &moveable](ChunkId * id, long size, int arg) { m_reader->ReadChunks([this, &moveable](ChunkId * id, long size, int arg) {
if (id->EqualsTo(m_chunkMesh)) return false;
/*if (id->EqualsTo(m_chunkMesh))
{ {
TrMesh mesh; TrMesh mesh;
readMesh(&mesh); readMesh(&mesh);
@ -508,23 +656,26 @@ bool TrLevel::readMoveable()
else else
{ {
return false; return false;
} }*/
}, 0); }, 0);
moveables.push_back(moveable); m_level.moveables.push_back(moveable);
return true; return true;
} }
bool TrLevel::readStatic() bool LevelLoader::readStatic()
{ {
TrStatic st; TrStatic st;
m_stream->ReadInt32(&st.id); m_stream->ReadInt32(&st.id);
m_stream->ReadBoundingBox(&st.visibilityBox); m_stream->ReadBoundingBox(&st.visibilityBox);
m_stream->ReadBoundingBox(&st.collisionBox); m_stream->ReadBoundingBox(&st.collisionBox);
m_stream->ReadInt32(&st.meshNumber);
m_stream->ReadInt32(&st.meshCount);
m_reader->ReadChunks([this, &st](ChunkId * id, long size, int arg) { m_reader->ReadChunks([this, &st](ChunkId * id, long size, int arg) {
if (id->EqualsTo(m_chunkMesh)) /*if (id->EqualsTo(m_chunkMesh))
{ {
TrMesh mesh; TrMesh mesh;
readMesh(&mesh); readMesh(&mesh);
@ -534,22 +685,26 @@ bool TrLevel::readStatic()
else else
{ {
return false; return false;
} }*/
return false;
}, 0); }, 0);
statics.push_back(st); m_level.statics.push_back(st);
return true; return true;
} }
bool TrLevel::readSpriteSequence() bool LevelLoader::readSpriteSequence()
{ {
TrSpriteSequence sequence; TrSpriteSequence sequence;
m_stream->ReadInt32(&sequence.id); m_stream->ReadInt32(&sequence.id);
m_stream->ReadInt32(&sequence.spritesIndex);
m_stream->ReadInt32(&sequence.spritesCount);
m_reader->ReadChunks([this, &sequence](ChunkId * id, long size, int arg) { m_reader->ReadChunks([this, &sequence](ChunkId * id, long size, int arg) {
if (id->EqualsTo(m_chunkSprite)) /*if (id->EqualsTo(m_chunkSprite))
{ {
TrSprite sprite; TrSprite sprite;
@ -568,51 +723,55 @@ bool TrLevel::readSpriteSequence()
else else
{ {
return false; return false;
} }*/
return false;
}, 0); }, 0);
spriteSequences.push_back(sequence); m_level.spriteSequences.push_back(sequence);
return true; return true;
} }
bool TrLevel::readItem() bool LevelLoader::readItem()
{ {
TrItem item; TrItem item;
m_stream->ReadString(&item.name); m_stream->ReadString(&item.name);
m_stream->ReadVector3(&item.position); m_stream->ReadVector3(&item.position);
m_stream->ReadQuaternion(&item.rotation); m_stream->ReadQuaternion(&item.rotation);
m_stream->ReadFloat(&item.angle);
m_stream->ReadVector3(&item.scale); m_stream->ReadVector3(&item.scale);
m_stream->ReadVector3(&item.color); m_stream->ReadVector3(&item.color);
m_stream->ReadInt32(&item.roomNumber); m_stream->ReadInt32(&item.roomNumber);
m_stream->ReadInt32(&item.objectNumber); m_stream->ReadInt32(&item.objectNumber);
m_stream->ReadString(&item.script); m_stream->ReadString(&item.script);
items.push_back(item); m_level.items.push_back(item);
return true; return true;
} }
bool TrLevel::readAiItem() bool LevelLoader::readAiItem()
{ {
TrItem item; TrItem item;
m_stream->ReadString(&item.name); m_stream->ReadString(&item.name);
m_stream->ReadVector3(&item.position); m_stream->ReadVector3(&item.position);
m_stream->ReadQuaternion(&item.rotation); m_stream->ReadQuaternion(&item.rotation);
m_stream->ReadFloat(&item.angle);
m_stream->ReadVector3(&item.scale); m_stream->ReadVector3(&item.scale);
m_stream->ReadVector3(&item.color); m_stream->ReadVector3(&item.color);
m_stream->ReadInt32(&item.roomNumber); m_stream->ReadInt32(&item.roomNumber);
m_stream->ReadInt32(&item.objectNumber); m_stream->ReadInt32(&item.objectNumber);
m_stream->ReadString(&item.script); m_stream->ReadString(&item.script);
aiItems.push_back(item); m_level.aiItems.push_back(item);
return true; return true;
} }
bool TrLevel::readSink() bool LevelLoader::readSink()
{ {
TrSink sink; TrSink sink;
@ -624,12 +783,12 @@ bool TrLevel::readSink()
m_reader->ReadChunks([this, sink](ChunkId * id, long size, int arg) { return false; }, 0); m_reader->ReadChunks([this, sink](ChunkId * id, long size, int arg) { return false; }, 0);
sinks.push_back(sink); m_level.sinks.push_back(sink);
return true; return true;
} }
bool TrLevel::readCamera() bool LevelLoader::readCamera()
{ {
TrCamera camera; TrCamera camera;
@ -642,12 +801,12 @@ bool TrLevel::readCamera()
m_reader->ReadChunks([this, camera](ChunkId * id, long size, int arg) { return false; }, 0); m_reader->ReadChunks([this, camera](ChunkId * id, long size, int arg) { return false; }, 0);
cameras.push_back(camera); m_level.cameras.push_back(camera);
return true; return true;
} }
bool TrLevel::readFlybyCamera() bool LevelLoader::readFlybyCamera()
{ {
TrFlybyCamera camera; TrFlybyCamera camera;
@ -666,12 +825,12 @@ bool TrLevel::readFlybyCamera()
m_reader->ReadChunks([this, camera](ChunkId * id, long size, int arg) { return false; }, 0); m_reader->ReadChunks([this, camera](ChunkId * id, long size, int arg) { return false; }, 0);
flybyCameras.push_back(camera); m_level.flybyCameras.push_back(camera);
return true; return true;
} }
bool TrLevel::readSoundSource() bool LevelLoader::readSoundSource()
{ {
TrSoundSource soundSource; TrSoundSource soundSource;
@ -683,12 +842,12 @@ bool TrLevel::readSoundSource()
m_reader->ReadChunks([this, soundSource](ChunkId * id, long size, int arg) { return false; }, 0); m_reader->ReadChunks([this, soundSource](ChunkId * id, long size, int arg) { return false; }, 0);
soundSources.push_back(soundSource); m_level.soundSources.push_back(soundSource);
return true; return true;
} }
bool TrLevel::readBox() bool LevelLoader::readBox()
{ {
TrBox box; TrBox box;
@ -714,26 +873,26 @@ bool TrLevel::readBox()
} }
}, 0); }, 0);
boxes.push_back(box); m_level.boxes.push_back(box);
return true; return true;
} }
bool TrLevel::readZones() bool LevelLoader::readZones()
{ {
for (int z = 0; z < 5; z++) for (int a = 0; a < 2; a++)
for (int a = 0; a < 2; a++) for (int z = 0; z < 5; z++)
for (int b = 0; b < boxes.size(); b++) for (int b = 0; b < m_level.boxes.size(); b++)
{ {
int zone; int zone;
m_stream->ReadInt32(&zone); m_stream->ReadInt32(&zone);
zones.push_back(zone); m_level.zones[z][a].push_back(zone);
} }
return true; return true;
} }
bool TrLevel::readSoundMap() bool LevelLoader::readSoundMap()
{ {
int count; int count;
m_stream->ReadInt32(&count); m_stream->ReadInt32(&count);
@ -741,13 +900,13 @@ bool TrLevel::readSoundMap()
{ {
int sound; int sound;
m_stream->ReadInt32(&sound); m_stream->ReadInt32(&sound);
soundMap.push_back(sound); m_level.soundMap.push_back(sound);
} }
return true; return true;
} }
bool TrLevel::readSoundDetail() bool LevelLoader::readSoundDetail()
{ {
TrSoundDetails detail; TrSoundDetails detail;
@ -761,7 +920,7 @@ bool TrLevel::readSoundDetail()
m_stream->ReadByte(&detail.loop); m_stream->ReadByte(&detail.loop);
m_reader->ReadChunks([this, &detail](ChunkId * id, long size, int arg) { m_reader->ReadChunks([this, &detail](ChunkId * id, long size, int arg) {
if (id->EqualsTo(m_chunkSample)) /*if (id->EqualsTo(m_chunkSample))
{ {
TrSample sample; TrSample sample;
@ -777,10 +936,40 @@ bool TrLevel::readSoundDetail()
else else
{ {
return false; return false;
} }*/
return false;
}, 0); }, 0);
soundDetails.push_back(detail); m_level.soundDetails.push_back(detail);
return true;
}
bool LevelLoader::readSample()
{
TrSample sample;
m_stream->ReadInt32(&sample.uncompressedSize);
m_stream->ReadInt32(&sample.compressedSize);
sample.data = (byte*)malloc(sample.compressedSize);
m_stream->ReadBytes(sample.data, sample.compressedSize);
Sound_LoadSample((char*)sample.data, sample.compressedSize, sample.uncompressedSize, m_numSamples);
m_numSamples++;
return true;
}
bool LevelLoader::readOverlap()
{
TrOverlap overlap;
m_stream->ReadInt32(&overlap.box);
m_stream->ReadInt32(&overlap.flags);
m_reader->ReadChunks([this, &overlap](ChunkId * id, long size, int arg) { return false; }, 0);
m_level.overlaps.push_back(overlap);
return true; return true;
} }

View file

@ -0,0 +1,100 @@
#pragma once
#include "framework.h"
#include "sound.h"
#include "Streams.h"
#include "newtypes.h"
#include "ChunkId.h"
#include "ChunkReader.h"
class LevelLoader
{
private:
ChunkId* m_chunkTextureAtlas = ChunkId::FromString("T5MTex");
ChunkId* m_chunkTextureColor = ChunkId::FromString("T5MTexColMap");
ChunkId* m_chunkTextureNormalMap = ChunkId::FromString("T5MTexNrmMap");
ChunkId* m_chunkRoom = ChunkId::FromString("T5MRoom");
ChunkId* m_chunkRoomInfo = ChunkId::FromString("T5MRoomInfo");
ChunkId* m_chunkBucket = ChunkId::FromString("T5MBckt");
ChunkId* m_chunkRoomLight = ChunkId::FromString("T5MLight");
ChunkId* m_chunkRoomStatic = ChunkId::FromString("T5MRoomSt");
ChunkId* m_chunkRoomPortal = ChunkId::FromString("T5MPortal");
ChunkId* m_chunkRoomSector = ChunkId::FromString("T5MSector");
ChunkId* m_chunkRoomTriggerVolume = ChunkId::FromString("T5MTrigVol");
ChunkId* m_chunkRoomClimbVolume = ChunkId::FromString("T5MClimbVol");
ChunkId* m_chunkMaterial = ChunkId::FromString("T5MMat");
ChunkId* m_chunkVerticesPositions = ChunkId::FromString("T5MVrtPos");
ChunkId* m_chunkVerticesNormals = ChunkId::FromString("T5MVrtN");
ChunkId* m_chunkVerticesTextureCoords = ChunkId::FromString("T5MVrtUV");
ChunkId* m_chunkVerticesColors = ChunkId::FromString("T5MVrtCol");
ChunkId* m_chunkVerticesEffects = ChunkId::FromString("T5MVrtFX");
ChunkId* m_chunkVerticesBones = ChunkId::FromString("T5MVrtB");
ChunkId* m_chunkPolygon = ChunkId::FromString("T5MPoly");
ChunkId* m_chunkMesh = ChunkId::FromString("T5MMesh");
ChunkId* m_chunkBone = ChunkId::FromString("T5MBone");
ChunkId* m_chunkKeyFrame = ChunkId::FromString("T5MKf");
ChunkId* m_chunkAnimCommand = ChunkId::FromString("T5MAnCmd");
ChunkId* m_chunkStateChange = ChunkId::FromString("T5MStCh");
ChunkId* m_chunkAnimDispatch = ChunkId::FromString("T5MAnDisp");
ChunkId* m_chunkAnimation = ChunkId::FromString("T5MAnim");
ChunkId* m_chunkMoveable = ChunkId::FromString("T5MMoveable");
ChunkId* m_chunkStatic = ChunkId::FromString("T5MStatic");
ChunkId* m_chunkItem = ChunkId::FromString("T5MItem");
ChunkId* m_chunkAiItem = ChunkId::FromString("T5MAiItem");
ChunkId* m_chunkCamera = ChunkId::FromString("T5MCamera");
ChunkId* m_chunkSink = ChunkId::FromString("T5MSink");
ChunkId* m_chunkFlybyCamera = ChunkId::FromString("T5MFlyBy");
ChunkId* m_chunkSoundSource = ChunkId::FromString("T5MSndSrc");
ChunkId* m_chunkBox = ChunkId::FromString("T5MBox");
ChunkId* m_chunkOverlap = ChunkId::FromString("T5MOv");
ChunkId* m_chunkZone = ChunkId::FromString("T5MZone");
ChunkId* m_chunkSoundMap = ChunkId::FromString("T5MSoundMap");
ChunkId* m_chunkSoundDetail = ChunkId::FromString("T5MSndDet");
ChunkId* m_chunkSample = ChunkId::FromString("T5MSam");
ChunkId* m_chunkLeelScript = ChunkId::FromString("T5MScript");
ChunkId* m_chunkSprite = ChunkId::FromString("T5MSpr");
ChunkId* m_chunkSpriteSequence = ChunkId::FromString("T5MSprSeq");
ChunkId* m_chunkDummy = ChunkId::FromString("T5MDummy");
ChunkId* m_chunkAnimatedTextureSequence = ChunkId::FromString("T5MAnTxSeq");
ChunkId* m_chunkAnimatedTextureFrame = ChunkId::FromString("T5MAnTxFr");
ChunkId* m_chunkFloorData = ChunkId::FromString("T5MFloorData");
int m_magicNumber = 0x4D355254;
string m_filename;
ChunkReader* m_reader;
FileStream* m_stream;
int m_numSamples = 0;
TrLevel m_level;
bool readTexture();
bool readAnimatedTextureSequence();
bool readRoom();
bool readBucket(TrBucket* bucket);
bool readMesh();
bool readAnimation();
bool readChange();
bool readDispatch();
bool readBone();
bool readKeyFrame();
bool readCommand();
bool readOverlap();
bool readFloorData();
bool readMoveable();
bool readStatic();
bool readSpriteSequence();
bool readItem();
bool readAiItem();
bool readSink();
bool readCamera();
bool readFlybyCamera();
bool readSoundSource();
bool readBox();
bool readZones();
bool readSoundMap();
bool readSoundDetail();
bool readSample();
public:
LevelLoader(string filename);
~LevelLoader();
bool Load();
};

View file

@ -1,8 +1,5 @@
#pragma once #pragma once
#include "sound.h" #include "framework.h"
#include "ChunkId.h"
#include "ChunkReader.h"
#include "Streams.h"
struct TrTexturePage struct TrTexturePage
{ {
@ -62,7 +59,9 @@ struct TrTriggerVolume : TrVolume
struct TrSector struct TrSector
{ {
int boxIndex; int floorDataIndex;
int floorDataCount;
int box;
int pathfindingFlags; int pathfindingFlags;
int stepSound; int stepSound;
int roomBelow; int roomBelow;
@ -131,6 +130,8 @@ struct TrRoom
vector<TrPortal> portals; vector<TrPortal> portals;
vector<TrTriggerVolume> triggers; vector<TrTriggerVolume> triggers;
vector<TrClimbVolume> climbVolumes; vector<TrClimbVolume> climbVolumes;
int itemNumber;
int fxNumber;
}; };
struct TrMesh struct TrMesh
@ -170,6 +171,8 @@ struct TrAnimDispatch
struct TrStateChange struct TrStateChange
{ {
int state; int state;
int dispatchIndex;
int dispatchCount;
vector<TrAnimDispatch> dispatches; vector<TrAnimDispatch> dispatches;
}; };
@ -179,12 +182,18 @@ struct TrAnimation
int state; int state;
int nextAnimation; int nextAnimation;
int nextFrame; int nextFrame;
int frameStart; int frameBase;
int frameEnd; int frameEnd;
float speed; float speed;
float acceleration; float acceleration;
float lateralSpeed; float lateralSpeed;
float lateralAcceleration; float lateralAcceleration;
int framesIndex;
int framesCount;
int changesIndex;
int changesCount;
int commandsIndex;
int commandsCount;
vector<TrKeyFrame> keyframes; vector<TrKeyFrame> keyframes;
vector<TrStateChange> changes; vector<TrStateChange> changes;
vector<TrAnimCommand> commands; vector<TrAnimCommand> commands;
@ -193,6 +202,12 @@ struct TrAnimation
struct TrMoveable struct TrMoveable
{ {
int id; int id;
int animationIndex;
int animationCount;
int meshIndex;
int meshCount;
int bonesIndex;
int bonesCount;
vector<TrMesh> meshes; vector<TrMesh> meshes;
vector<TrBone> bones; vector<TrBone> bones;
vector<TrAnimation> animations; vector<TrAnimation> animations;
@ -203,6 +218,8 @@ struct TrStatic
int id; int id;
BoundingBox visibilityBox; BoundingBox visibilityBox;
BoundingBox collisionBox; BoundingBox collisionBox;
int meshNumber;
int meshCount;
vector<TrMesh> meshes; vector<TrMesh> meshes;
}; };
@ -225,6 +242,7 @@ struct TrItem
string name; string name;
Vector3 position; Vector3 position;
Quaternion rotation; Quaternion rotation;
float angle;
Vector3 scale; Vector3 scale;
Vector3 color; Vector3 color;
int roomNumber; int roomNumber;
@ -272,6 +290,9 @@ struct TrBox
Vector2 min; Vector2 min;
Vector2 max; Vector2 max;
int floor; int floor;
int flags;
int overlapsIndex;
int overlapsCount;
vector<TrOverlap> overlaps; vector<TrOverlap> overlaps;
}; };
@ -320,105 +341,38 @@ struct TrSprite
struct TrSpriteSequence struct TrSpriteSequence
{ {
int id; int id;
int spritesIndex;
int spritesCount;
vector<TrSprite> sprites; vector<TrSprite> sprites;
}; };
class TrLevel struct TrLevel
{ {
private:
ChunkId* m_chunkTextureAtlas = ChunkId::FromString("T5MTex");
ChunkId* m_chunkTextureColor = ChunkId::FromString("T5MTexColMap");
ChunkId* m_chunkTextureNormalMap = ChunkId::FromString("T5MTexNrmMap");
ChunkId* m_chunkRoom = ChunkId::FromString("T5MRoom");
ChunkId* m_chunkRoomInfo = ChunkId::FromString("T5MRoomInfo");
ChunkId* m_chunkBucket = ChunkId::FromString("T5MBckt");
ChunkId* m_chunkRoomLight = ChunkId::FromString("T5MLight");
ChunkId* m_chunkRoomStatic = ChunkId::FromString("T5MRoomSt");
ChunkId* m_chunkRoomPortal = ChunkId::FromString("T5MPortal");
ChunkId* m_chunkRoomSector = ChunkId::FromString("T5MSector");
ChunkId* m_chunkRoomTriggerVolume = ChunkId::FromString("T5MTrigVol");
ChunkId* m_chunkRoomClimbVolume = ChunkId::FromString("T5MClimbVol");
ChunkId* m_chunkMaterial = ChunkId::FromString("T5MMat");
ChunkId* m_chunkVerticesPositions = ChunkId::FromString("T5MVrtPos");
ChunkId* m_chunkVerticesNormals = ChunkId::FromString("T5MVrtN");
ChunkId* m_chunkVerticesTextureCoords = ChunkId::FromString("T5MVrtUV");
ChunkId* m_chunkVerticesColors = ChunkId::FromString("T5MVrtCol");
ChunkId* m_chunkVerticesEffects = ChunkId::FromString("T5MVrtFX");
ChunkId* m_chunkVerticesBones = ChunkId::FromString("T5MVrtB");
ChunkId* m_chunkPolygon = ChunkId::FromString("T5MPoly");
ChunkId* m_chunkMesh = ChunkId::FromString("T5MMesh");
ChunkId* m_chunkBone = ChunkId::FromString("T5MBone");
ChunkId* m_chunkKeyFrame = ChunkId::FromString("T5MKf");
ChunkId* m_chunkAnimCommand = ChunkId::FromString("T5MAnCmd");
ChunkId* m_chunkStateChange = ChunkId::FromString("T5MStCh");
ChunkId* m_chunkAnimDispatch = ChunkId::FromString("T5MAnDisp");
ChunkId* m_chunkAnimation = ChunkId::FromString("T5MAnim");
ChunkId* m_chunkMoveable = ChunkId::FromString("T5MMoveable");
ChunkId* m_chunkStatic = ChunkId::FromString("T5MStatic");
ChunkId* m_chunkItem = ChunkId::FromString("T5MItem");
ChunkId* m_chunkAiItem = ChunkId::FromString("T5MAiItem");
ChunkId* m_chunkCamera = ChunkId::FromString("T5MCamera");
ChunkId* m_chunkSink = ChunkId::FromString("T5MSink");
ChunkId* m_chunkFlybyCamera = ChunkId::FromString("T5MFlyBy");
ChunkId* m_chunkSoundSource = ChunkId::FromString("T5MSndSrc");
ChunkId* m_chunkBox = ChunkId::FromString("T5MBox");
ChunkId* m_chunkOverlap = ChunkId::FromString("T5MOv");
ChunkId* m_chunkZone = ChunkId::FromString("T5MZone");
ChunkId* m_chunkSoundMap = ChunkId::FromString("T5MSoundMap");
ChunkId* m_chunkSoundDetail = ChunkId::FromString("T5MSndDet");
ChunkId* m_chunkSample = ChunkId::FromString("T5MSam");
ChunkId* m_chunkLeelScript = ChunkId::FromString("T5MScript");
ChunkId* m_chunkSprite = ChunkId::FromString("T5MSpr");
ChunkId* m_chunkSpriteSequence = ChunkId::FromString("T5MSprSeq");
ChunkId* m_chunkDummy = ChunkId::FromString("T5MDummy");
ChunkId* m_chunkAnimatedTextureSequence = ChunkId::FromString("T5MAnTxSeq");
ChunkId* m_chunkAnimatedTextureFrame = ChunkId::FromString("T5MAnTxFr");
int m_magicNumber = 0x4D355254;
string m_filename;
ChunkReader* m_reader;
FileStream* m_stream;
bool readTexture();
bool readAnimatedTextureSequence();
bool readRoom();
bool readBucket(TrBucket* bucket);
bool readMesh(TrMesh* mesh);
bool readAnimation(TrAnimation* animation);
bool readMoveable();
bool readStatic();
bool readSpriteSequence();
bool readItem();
bool readAiItem();
bool readSink();
bool readCamera();
bool readFlybyCamera();
bool readSoundSource();
bool readBox();
bool readZones();
bool readSoundMap();
bool readSoundDetail();
public:
vector<TrTexturePage> textures; vector<TrTexturePage> textures;
vector<TrRoom> rooms; vector<TrRoom> rooms;
vector<TrMoveable> moveables; vector<int> floorData;
vector<TrStatic> statics; vector<TrMesh> meshes;
vector<TrItem> items; vector<TrAnimation> animations;
vector<TrItem> aiItems; vector<TrBone> bones;
vector<TrCamera> cameras; vector<TrStateChange> changes;
vector<TrSoundSource> soundSources; vector<TrAnimDispatch> dispatches;
vector<TrSink> sinks; vector<TrKeyFrame> frames;
vector<TrFlybyCamera> flybyCameras; vector<TrAnimCommand> commands;
vector<TrSpriteSequence> spriteSequences;
vector<TrAnimatedTexturesSequence> animatedTextures; vector<TrAnimatedTexturesSequence> animatedTextures;
vector<TrBox> boxes; vector<TrSprite> sprites;
vector<int> zones; vector<TrSpriteSequence> spriteSequences;
vector<int> soundMap; vector<int> soundMap;
vector<TrSoundDetails> soundDetails; vector<TrSoundDetails> soundDetails;
string script; vector<TrSample> samples;
vector<TrItem> items;
TrLevel(string filename); vector<TrItem> aiItems;
~TrLevel(); vector<TrMoveable> moveables;
bool Load(); vector<TrStatic> statics;
vector<TrBox> boxes;
vector<TrOverlap> overlaps;
vector<int> zones[5][2];
vector<TrSink> sinks;
vector<TrCamera> cameras;
vector<TrSoundSource> soundSources;
vector<TrFlybyCamera> flybyCameras;
}; };

View file

@ -247,7 +247,6 @@ xcopy /Y "$(ProjectDir)Scripting\Scripts\*.lua" "$(TargetDir)\Scripts"</Command>
<ClInclude Include="Objects\TR5\Entity\tr5_willowwisp.h" /> <ClInclude Include="Objects\TR5\Entity\tr5_willowwisp.h" />
<ClInclude Include="Objects\TR5\Shatter\tr5_smashobject.h" /> <ClInclude Include="Objects\TR5\Shatter\tr5_smashobject.h" />
<ClInclude Include="Renderer\RenderEnums.h" /> <ClInclude Include="Renderer\RenderEnums.h" />
<ClInclude Include="Specific\newlevel.h" />
<ClInclude Include="Libs\fixedpoint\fixed_point.hpp" /> <ClInclude Include="Libs\fixedpoint\fixed_point.hpp" />
<ClInclude Include="Objects\oldobjects.h" /> <ClInclude Include="Objects\oldobjects.h" />
<ClInclude Include="Objects\TR1\tr1_objects.h" /> <ClInclude Include="Objects\TR1\tr1_objects.h" />
@ -364,6 +363,8 @@ xcopy /Y "$(ProjectDir)Scripting\Scripts\*.lua" "$(TargetDir)\Scripts"</Command>
<ClInclude Include="Specific\input.h" /> <ClInclude Include="Specific\input.h" />
<ClInclude Include="Specific\IO\Streams.h" /> <ClInclude Include="Specific\IO\Streams.h" />
<ClInclude Include="Specific\level.h" /> <ClInclude Include="Specific\level.h" />
<ClInclude Include="Specific\levelloader.h" />
<ClInclude Include="Specific\newtypes.h" />
<ClInclude Include="Specific\setup.h" /> <ClInclude Include="Specific\setup.h" />
<ClInclude Include="Specific\winmain.h" /> <ClInclude Include="Specific\winmain.h" />
<ClInclude Include="targetver.h" /> <ClInclude Include="targetver.h" />
@ -572,7 +573,7 @@ xcopy /Y "$(ProjectDir)Scripting\Scripts\*.lua" "$(TargetDir)\Scripts"</Command>
<ClCompile Include="Specific\Init.cpp" /> <ClCompile Include="Specific\Init.cpp" />
<ClCompile Include="Specific\input.cpp" /> <ClCompile Include="Specific\input.cpp" />
<ClCompile Include="Specific\level.cpp" /> <ClCompile Include="Specific\level.cpp" />
<ClCompile Include="Specific\newlevel.cpp" /> <ClCompile Include="Specific\levelloader.cpp" />
<ClCompile Include="Specific\setup.cpp" /> <ClCompile Include="Specific\setup.cpp" />
<ClCompile Include="Specific\winmain.cpp" /> <ClCompile Include="Specific\winmain.cpp" />
</ItemGroup> </ItemGroup>

View file

@ -339,9 +339,6 @@
<ClInclude Include="Objects\TR4\tr4_objects.h"> <ClInclude Include="Objects\TR4\tr4_objects.h">
<Filter>File di intestazione</Filter> <Filter>File di intestazione</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Specific\newlevel.h">
<Filter>File di intestazione</Filter>
</ClInclude>
<ClInclude Include="Objects\TR5\tr5_objects.h"> <ClInclude Include="Objects\TR5\tr5_objects.h">
<Filter>File di intestazione</Filter> <Filter>File di intestazione</Filter>
</ClInclude> </ClInclude>
@ -741,6 +738,12 @@
<ClInclude Include="Game\lara_struct.h"> <ClInclude Include="Game\lara_struct.h">
<Filter>File di intestazione</Filter> <Filter>File di intestazione</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Specific\levelloader.h">
<Filter>File di intestazione</Filter>
</ClInclude>
<ClInclude Include="Specific\newtypes.h">
<Filter>File di intestazione</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="Game\box.cpp"> <ClCompile Include="Game\box.cpp">
@ -1010,9 +1013,6 @@
<ClCompile Include="Game\effect.cpp"> <ClCompile Include="Game\effect.cpp">
<Filter>File di origine</Filter> <Filter>File di origine</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Specific\newlevel.cpp">
<Filter>File di origine</Filter>
</ClCompile>
<ClCompile Include="Objects\TR5\Entity\tr5_autoguns.cpp"> <ClCompile Include="Objects\TR5\Entity\tr5_autoguns.cpp">
<Filter>File di origine</Filter> <Filter>File di origine</Filter>
</ClCompile> </ClCompile>
@ -1355,6 +1355,9 @@
<ClCompile Include="Game\trmath.cpp"> <ClCompile Include="Game\trmath.cpp">
<Filter>File di origine</Filter> <Filter>File di origine</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Specific\levelloader.cpp">
<Filter>File di origine</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />