Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/graphics/MapGenerator.cpp
Show First 20 Lines • Show All 328 Lines • ▼ Show 20 Lines | JS::Value CMapGeneratorWorker::LoadHeightmap(ScriptInterface::CxPrivate* pCxPrivate, const VfsPath& filename) | ||||
JS::RootedValue returnValue(cx); | JS::RootedValue returnValue(cx); | ||||
ToJSVal_vector(cx, &returnValue, heightmap); | ToJSVal_vector(cx, &returnValue, heightmap); | ||||
return returnValue; | return returnValue; | ||||
} | } | ||||
// See CMapReader::UnpackTerrain, CMapReader::ParseTerrain for the reordering | // See CMapReader::UnpackTerrain, CMapReader::ParseTerrain for the reordering | ||||
JS::Value CMapGeneratorWorker::LoadMapTerrain(ScriptInterface::CxPrivate* pCxPrivate, const VfsPath& filename) | JS::Value CMapGeneratorWorker::LoadMapTerrain(ScriptInterface::CxPrivate* pCxPrivate, const VfsPath& filename) | ||||
{ | { | ||||
CMapGeneratorWorker* self = static_cast<CMapGeneratorWorker*>(pCxPrivate->pCBData); | |||||
JSContext* cx = self->m_ScriptInterface->GetContext(); | |||||
JSAutoRequest rq(cx); | |||||
if (!VfsFileExists(filename)) | if (!VfsFileExists(filename)) | ||||
throw PSERROR_File_OpenFailed(); | { | ||||
self->m_ScriptInterface->ReportError( | |||||
("Terrain file \"" + filename.string8() + "\" does not exist!").c_str()); | |||||
return JS::UndefinedValue(); | |||||
} | |||||
CFileUnpacker unpacker; | CFileUnpacker unpacker; | ||||
unpacker.Read(filename, "PSMP"); | unpacker.Read(filename, "PSMP"); | ||||
if (unpacker.GetVersion() < CMapIO::FILE_READ_VERSION) | if (unpacker.GetVersion() < CMapIO::FILE_READ_VERSION) | ||||
throw PSERROR_File_InvalidVersion(); | { | ||||
self->m_ScriptInterface->ReportError( | |||||
("Could not load terrain file \"" + filename.string8() + "\" too old version!").c_str()); | |||||
return JS::UndefinedValue(); | |||||
} | |||||
// unpack size | // unpack size | ||||
ssize_t patchesPerSide = (ssize_t)unpacker.UnpackSize(); | ssize_t patchesPerSide = (ssize_t)unpacker.UnpackSize(); | ||||
size_t verticesPerSide = patchesPerSide * PATCH_SIZE + 1; | size_t verticesPerSide = patchesPerSide * PATCH_SIZE + 1; | ||||
// unpack heightmap | // unpack heightmap | ||||
std::vector<u16> heightmap; | std::vector<u16> heightmap; | ||||
heightmap.resize(SQR(verticesPerSide)); | heightmap.resize(SQR(verticesPerSide)); | ||||
Show All 26 Lines | for (ssize_t x = 0; x < tilesPerSide; ++x) | ||||
{ | { | ||||
size_t patchY = y / PATCH_SIZE; | size_t patchY = y / PATCH_SIZE; | ||||
size_t offY = y % PATCH_SIZE; | size_t offY = y % PATCH_SIZE; | ||||
// m_Priority and m_Tex2Index unused | // m_Priority and m_Tex2Index unused | ||||
textureIDs.push_back(tiles[(patchY * patchesPerSide + patchX) * SQR(PATCH_SIZE) + (offY * PATCH_SIZE + offX)].m_Tex1Index); | textureIDs.push_back(tiles[(patchY * patchesPerSide + patchX) * SQR(PATCH_SIZE) + (offY * PATCH_SIZE + offX)].m_Tex1Index); | ||||
} | } | ||||
} | } | ||||
CMapGeneratorWorker* self = static_cast<CMapGeneratorWorker*>(pCxPrivate->pCBData); | |||||
JSContext* cx = self->m_ScriptInterface->GetContext(); | |||||
JSAutoRequest rq(cx); | |||||
JS::RootedValue returnValue(cx, JS::ObjectValue(*JS_NewPlainObject(cx))); | JS::RootedValue returnValue(cx, JS::ObjectValue(*JS_NewPlainObject(cx))); | ||||
self->m_ScriptInterface->SetProperty(returnValue, "height", heightmap); | self->m_ScriptInterface->SetProperty(returnValue, "height", heightmap); | ||||
self->m_ScriptInterface->SetProperty(returnValue, "textureNames", textureNames); | self->m_ScriptInterface->SetProperty(returnValue, "textureNames", textureNames); | ||||
self->m_ScriptInterface->SetProperty(returnValue, "textureIDs", textureIDs); | self->m_ScriptInterface->SetProperty(returnValue, "textureIDs", textureIDs); | ||||
return returnValue; | return returnValue; | ||||
} | } | ||||
Show All 26 Lines |
Wildfire Games · Phabricator