Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #262 from storm-devs/feature/save-tweaks
Browse files Browse the repository at this point in the history
Save tweaks for compatibility with older saves
  • Loading branch information
espkk authored Nov 21, 2021
2 parents b498fcf + 1ae6589 commit 0c494c9
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 34 deletions.
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ if(STORM_WATERMARK_FILE)
endif()

if (MSVC)
# Ignore warnings about missing pdb
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ignore:4099")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /ignore:4099")
set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /ignore:4099")

# Always generate PDBs
add_compile_options(/Zi)
add_link_options(/DEBUG)
Expand Down
26 changes: 23 additions & 3 deletions src/apps/ENGINE/src/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6120,6 +6120,10 @@ char *COMPILER::ReadString()

char *pBuffer = new char[n];
ReadData(pBuffer, n);
if (!utf8::IsValidUtf8(pBuffer))
{
spdlog::warn("Deserializing invalid utf8 string: {}", pBuffer);
}
return pBuffer;
}

Expand Down Expand Up @@ -6205,6 +6209,25 @@ bool COMPILER::ReadVariable(char *name, /* DWORD code,*/ bool bDim, uint32_t a_i
// load array elements
for (uint32_t n = 0; n < nElementsNum; n++)
{
if (bSkipVariable)
{
if (eType == S_TOKEN_TYPE::VAR_INTEGER)
ReadData(nullptr, sizeof(long));
else if (eType == S_TOKEN_TYPE::VAR_FLOAT)
ReadData(nullptr, sizeof(float));
else if (eType == S_TOKEN_TYPE::VAR_STRING)
ReadString();
else if (eType == S_TOKEN_TYPE::VAR_OBJECT)
{
ReadData(nullptr, sizeof(uint64_t));
ATTRIBUTES TA(&SCodec);
ReadAttributesData(&TA, nullptr);
}
else
Assert(false);
continue;
}

if (!ReadVariable(name, /*code,*/ true, n))
return false;
}
Expand Down Expand Up @@ -6593,7 +6616,6 @@ bool COMPILER::LoadState(std::fstream &fileS)
pString = ReadString();
if (pString)
{
Assert(utf8::IsValidUtf8(pString));
SCodec.Convert(pString);
delete[] pString;
}
Expand All @@ -6610,7 +6632,6 @@ bool COMPILER::LoadState(std::fstream &fileS)
for (n = 0; n < nSegments2Load; n++)
{
char *pSegmentName = ReadString();
Assert(utf8::IsValidUtf8(pSegmentName));
if (!BC_LoadSegment(pSegmentName))
return false;
delete[] pSegmentName;
Expand All @@ -6626,7 +6647,6 @@ bool COMPILER::LoadState(std::fstream &fileS)
SetError("missing variable name");
return false;
}
Assert(utf8::IsValidUtf8(pString));
ReadVariable(pString /*,n*/);

delete[] pString;
Expand Down
2 changes: 1 addition & 1 deletion src/apps/ENGINE/src/token.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ enum S_TOKEN_TYPE
COMMENT,
INCLIDE_FILE,
VAR_INTEGER,
VAR_PTR,
VAR_FLOAT,
VAR_STRING,
VAR_OBJECT,
VAR_REFERENCE,
VAR_AREFERENCE,
VAR_PTR,
BLOCK_IN,
BLOCK_OUT,
NUMBER,
Expand Down
92 changes: 64 additions & 28 deletions src/libs/sea_ai/src/AIBalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ AIBalls::~AIBalls()
{
STORM_DELETE(pBall->pParticle);
}
pBall->sBallEvent[0] = '\0';
pBall->sBallEvent.clear();
}
aBallTypes[i].Balls.clear();
}
Expand Down Expand Up @@ -134,31 +134,25 @@ void AIBalls::AddBall(ATTRIBUTES *pABall)

pBall->iBallOwner = pABall->GetAttributeAsDword("CharacterIndex");

#define GetAFloat(x) pABall->GetAttributeAsFloat(x)
#define GetADword(x) pABall->GetAttributeAsDword(x)

pBall->fTime = 0.0f;
pBall->vPos = pBall->vFirstPos = CVECTOR(GetAFloat("x"), GetAFloat("y"), GetAFloat("z"));
pBall->fSpeedV0 = GetAFloat("SpdV0");
pBall->fHeightMultiply = GetAFloat("HeightMultiply");
pBall->fSizeMultiply = GetAFloat("SizeMultiply");
pBall->fTimeSpeedMultiply = GetAFloat("TimeSpeedMultiply");
pBall->dwCannonType = GetADword("CannonType");
pBall->fMaxFireDistance = GetAFloat("MaxFireDistance");
const auto fAngle = GetAFloat("Ang");
pBall->vPos = pBall->vFirstPos =
CVECTOR(pABall->GetAttributeAsFloat("x"), pABall->GetAttributeAsFloat("y"), pABall->GetAttributeAsFloat("z"));
pBall->fSpeedV0 = pABall->GetAttributeAsFloat("SpdV0");
pBall->fHeightMultiply = pABall->GetAttributeAsFloat("HeightMultiply");
pBall->fSizeMultiply = pABall->GetAttributeAsFloat("SizeMultiply");
pBall->fTimeSpeedMultiply = pABall->GetAttributeAsFloat("TimeSpeedMultiply");
pBall->dwCannonType = pABall->GetAttributeAsDword("CannonType");
pBall->fMaxFireDistance = pABall->GetAttributeAsFloat("MaxFireDistance");
const auto fAngle = pABall->GetAttributeAsFloat("Ang");
pBall->fCosAngle = cosf(fAngle);
pBall->fSinAngle = sinf(fAngle);
const auto fDir = GetAFloat("Dir");
const auto fDir = pABall->GetAttributeAsFloat("Dir");
pBall->fDirX = cosf(fDir);
pBall->fDirZ = sinf(fDir);
pBall->pParticle = nullptr;

// pBall->sBallEvent = pABall->GetAttribute("Event");
const auto *event_str = pABall->GetAttribute("Event");
const auto len = std::min(strlen(event_str), static_cast<size_t>(TSE_MAX_EVENT_LENGTH));
std::copy_n(event_str, len, pBall->sBallEvent);
pBall->sBallEvent[len] = '\0';

pBall->sBallEvent = pABall->GetAttribute("Event");

if (aBallTypes[i].sParticleName.size())
{
entid_t eidParticle;
Expand Down Expand Up @@ -220,8 +214,8 @@ void AIBalls::Execute(uint32_t Delta_Time)

vDst = pBall->vPos;

if (pBall->sBallEvent[0] != '\0')
core.Event(pBall->sBallEvent, "lllffffffs", pBall->iBallOwner, static_cast<uint32_t>(1),
if (!pBall->sBallEvent.empty())
core.Event(pBall->sBallEvent.c_str(), "lllffffffs", pBall->iBallOwner, static_cast<uint32_t>(1),
pBallsType->dwGoodIndex, pBall->vPos.x, pBall->vPos.y, pBall->vPos.z, vSrc.x, vSrc.y,
vSrc.z);

Expand Down Expand Up @@ -281,12 +275,12 @@ void AIBalls::Execute(uint32_t Delta_Time)
// delete ball
if (fRes <= 1.0f)
{
if (pBall->sBallEvent[0] != '\0')
if (!pBall->sBallEvent.empty())
{
core.Event(pBall->sBallEvent, "lllffffff", pBall->iBallOwner, static_cast<uint32_t>(0),
core.Event(pBall->sBallEvent.c_str(), "lllffffff", pBall->iBallOwner, static_cast<uint32_t>(0),
pBallsType->dwGoodIndex, pBall->vPos.x, pBall->vPos.y, pBall->vPos.z, vSrc.x, vSrc.y,
vSrc.z);
pBall->sBallEvent[0] = '\0';
pBall->sBallEvent.clear();
}

if (pBall->pParticle)
Expand All @@ -302,7 +296,7 @@ void AIBalls::Execute(uint32_t Delta_Time)
continue;
}

if (pBall->sBallEvent[0] == '\0')
if (pBall->sBallEvent.empty())
{
aBallRects.push_back(RS_RECT{});
// RS_RECT * pRSR = &aBallRects[aBallRects.Add()];
Expand Down Expand Up @@ -351,7 +345,7 @@ uint32_t AIBalls::AttributeChanged(ATTRIBUTES *pAttributeChanged)
{
BALL_PARAMS *pBall = &pBallsType->Balls[j];

pBall->sBallEvent[0] = '\0';
pBall->sBallEvent.clear();

if (pBall->pParticle)
{
Expand Down Expand Up @@ -434,6 +428,27 @@ uint64_t AIBalls::ProcessMessage(MESSAGE &message)
return 0;
}

void BALL_PARAMS::Save(CSaveLoad *pSL)
{
pSL->SaveVector(vFirstPos);
pSL->SaveVector(vPos);
// pSL->SaveDword(reinterpret_cast<uint32_t>(pParticle));
pSL->SaveQword(reinterpret_cast<uint64_t>(pParticle));
pSL->SaveString(sBallEvent);
pSL->SaveLong(iBallOwner);
pSL->SaveFloat(fTime);
pSL->SaveFloat(fSpeedV0);
pSL->SaveFloat(fDirX);
pSL->SaveFloat(fDirZ);
pSL->SaveFloat(fSinAngle);
pSL->SaveFloat(fCosAngle);
pSL->SaveFloat(fHeightMultiply);
pSL->SaveFloat(fSizeMultiply);
pSL->SaveFloat(fTimeSpeedMultiply);
pSL->SaveFloat(fMaxFireDistance);
pSL->SaveDword(dwCannonType);
}

void AIBalls::Save(CSaveLoad *pSL)
{
for (uint32_t i = 0; i < aBallTypes.size(); i++)
Expand All @@ -442,11 +457,32 @@ void AIBalls::Save(CSaveLoad *pSL)

for (uint32_t j = 0; j < aBallTypes[i].Balls.size(); j++)
{
pSL->SaveBuffer((const char *)&aBallTypes[i].Balls[j], sizeof(BALL_PARAMS));
aBallTypes[i].Balls[j].Save(pSL);
}
}
}

void BALL_PARAMS::Load(CSaveLoad *pSL)
{
vFirstPos = pSL->LoadVector();
vPos = pSL->LoadVector();
//pParticle = reinterpret_cast<VPARTICLE_SYSTEM *>(pSL->LoadDword());
pParticle = reinterpret_cast<VPARTICLE_SYSTEM *>(pSL->LoadQword());
sBallEvent = pSL->LoadString();
iBallOwner = pSL->LoadLong();
fTime = pSL->LoadFloat();
fSpeedV0 = pSL->LoadFloat();
fDirX = pSL->LoadFloat();
fDirZ = pSL->LoadFloat();
fSinAngle = pSL->LoadFloat();
fCosAngle = pSL->LoadFloat();
fHeightMultiply = pSL->LoadFloat();
fSizeMultiply = pSL->LoadFloat();
fTimeSpeedMultiply = pSL->LoadFloat();
fMaxFireDistance = pSL->LoadFloat();
dwCannonType = pSL->LoadDword();
}

void AIBalls::Load(CSaveLoad *pSL)
{
for (uint32_t i = 0; i < aBallTypes.size(); i++)
Expand All @@ -459,7 +495,7 @@ void AIBalls::Load(CSaveLoad *pSL)
{
// BALL_PARAMS * pB = &aBallTypes[i].Balls[aBallTypes[i].Balls.Add()];
BALL_PARAMS &pB = aBallTypes[i].Balls[balls_size + j];
pSL->Load2Buffer(&pB);
pB.Load(pSL);
if (pB.pParticle)
{
pB.pParticle = nullptr;
Expand Down
5 changes: 4 additions & 1 deletion src/libs/sea_ai/src/AIBalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@

struct BALL_PARAMS
{
void Save(CSaveLoad *pSL);
void Load(CSaveLoad *pSL);

CVECTOR vFirstPos, vPos; // first and current ball position
VPARTICLE_SYSTEM *pParticle;
char sBallEvent[TSE_MAX_EVENT_LENGTH + 1];
std::string sBallEvent;
long iBallOwner; // ball owner(character index)
float fTime; // ball time: in seconds
float fSpeedV0; // initial speed: in m/s
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ship/src/ship.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1955,7 +1955,7 @@ void SHIP::Load(CSaveLoad *pSL)
ExecuteLayer = pSL->LoadDword();
const std::string sTmp = pSL->LoadString();
strcpy_s(cShipIniName, sTmp.c_str());
pSL->LoadLong();
iShipPriorityExecute = pSL->LoadLong();
fGravity = pSL->LoadFloat();
fSailState = pSL->LoadFloat();

Expand Down

0 comments on commit 0c494c9

Please sign in to comment.