Adding splashpack
This commit is contained in:
3
Makefile
3
Makefile
@@ -3,6 +3,7 @@ TYPE = ps-exe
|
|||||||
|
|
||||||
SRCS = \
|
SRCS = \
|
||||||
src/main.cpp \
|
src/main.cpp \
|
||||||
src/renderer.cpp
|
src/renderer.cpp \
|
||||||
|
src/splashpack.cpp
|
||||||
|
|
||||||
include third_party/nugget/psyqo/psyqo.mk
|
include third_party/nugget/psyqo/psyqo.mk
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ namespace psxsplash {
|
|||||||
|
|
||||||
class GameObject final {
|
class GameObject final {
|
||||||
public:
|
public:
|
||||||
psyqo::Vec3 position;
|
psyqo::Vec3 position; // 12 bytes
|
||||||
psyqo::Matrix33 rotation;
|
psyqo::Matrix33 rotation; // 36 bytes
|
||||||
psyqo::PrimPieces::TPageAttr texture;
|
psyqo::PrimPieces::TPageAttr texture; // 2 bytes
|
||||||
uint16_t polyCount;
|
uint16_t polyCount; // 2 bytes
|
||||||
union {
|
union { // 4 bytes
|
||||||
Tri *polygons;
|
Tri *polygons;
|
||||||
uint32_t polygonsOffset;
|
uint32_t polygonsOffset;
|
||||||
};
|
};
|
||||||
|
|||||||
10
src/main.cpp
10
src/main.cpp
@@ -8,6 +8,8 @@
|
|||||||
#include "psyqo/scene.hh"
|
#include "psyqo/scene.hh"
|
||||||
|
|
||||||
#include "renderer.hh"
|
#include "renderer.hh"
|
||||||
|
#include "output.h"
|
||||||
|
#include "splashpack.hh"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@@ -22,7 +24,8 @@ class PSXSplash final : public psyqo::Application {
|
|||||||
|
|
||||||
class MainScene final : public psyqo::Scene {
|
class MainScene final : public psyqo::Scene {
|
||||||
void frame() override;
|
void frame() override;
|
||||||
eastl::array<psxsplash::GameObject> objects;
|
void start(StartReason reason) override;
|
||||||
|
eastl::vector<psxsplash::GameObject*> objects;
|
||||||
};
|
};
|
||||||
|
|
||||||
PSXSplash psxSplash;
|
PSXSplash psxSplash;
|
||||||
@@ -45,6 +48,11 @@ void PSXSplash::createScene() {
|
|||||||
pushScene(&mainScene);
|
pushScene(&mainScene);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MainScene::start(StartReason reason) {
|
||||||
|
objects = psxsplash::LoadSplashpack(bin2c_output_bin);
|
||||||
|
}
|
||||||
|
|
||||||
void MainScene::frame() { psxsplash::Renderer::getInstance().render(objects); }
|
void MainScene::frame() { psxsplash::Renderer::getInstance().render(objects); }
|
||||||
|
|
||||||
int main() { return psxSplash.run(); }
|
int main() { return psxSplash.run(); }
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "EASTL/array.h"
|
|
||||||
#include "psyqo/gte-registers.hh"
|
#include "psyqo/gte-registers.hh"
|
||||||
#include "psyqo/primitives/common.hh"
|
#include "psyqo/primitives/common.hh"
|
||||||
#include "texture.hh"
|
|
||||||
|
|
||||||
namespace psxsplash {
|
namespace psxsplash {
|
||||||
|
|
||||||
@@ -16,9 +14,4 @@ class Tri final {
|
|||||||
psyqo::Color colorA, colorB, colorC;
|
psyqo::Color colorA, colorB, colorC;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Mesh final {
|
|
||||||
public:
|
|
||||||
Texture m_texture;
|
|
||||||
eastl::array<Tri> m_polygons;
|
|
||||||
};
|
|
||||||
} // namespace psxsplash
|
} // namespace psxsplash
|
||||||
|
|||||||
11
src/output.h
Normal file
11
src/output.h
Normal file
File diff suppressed because one or more lines are too long
@@ -1,12 +1,21 @@
|
|||||||
#include "renderer.hh"
|
#include "renderer.hh"
|
||||||
|
|
||||||
|
#include "EASTL/vector.h"
|
||||||
|
#include "psyqo/fixed-point.hh"
|
||||||
#include "psyqo/gte-kernels.hh"
|
#include "psyqo/gte-kernels.hh"
|
||||||
|
#include "psyqo/gte-registers.hh"
|
||||||
#include "psyqo/primitives/triangles.hh"
|
#include "psyqo/primitives/triangles.hh"
|
||||||
|
#include "psyqo/soft-math.hh"
|
||||||
|
#include "psyqo/trigonometry.hh"
|
||||||
|
|
||||||
psxsplash::Renderer* psxsplash::Renderer::instance = nullptr;
|
using namespace psyqo::fixed_point_literals;
|
||||||
|
using namespace psyqo::trig_literals;
|
||||||
|
|
||||||
|
psxsplash::Renderer *psxsplash::Renderer::instance = nullptr;
|
||||||
|
|
||||||
void psxsplash::Renderer::init(psyqo::GPU &gpuInstance) {
|
void psxsplash::Renderer::init(psyqo::GPU &gpuInstance) {
|
||||||
psyqo::Kernel::assert(instance == nullptr, "A second intialization of Renderer was tried");
|
psyqo::Kernel::assert(instance == nullptr,
|
||||||
|
"A second intialization of Renderer was tried");
|
||||||
|
|
||||||
psyqo::GTE::clear<psyqo::GTE::Register::TRX, psyqo::GTE::Unsafe>();
|
psyqo::GTE::clear<psyqo::GTE::Register::TRX, psyqo::GTE::Unsafe>();
|
||||||
psyqo::GTE::clear<psyqo::GTE::Register::TRY, psyqo::GTE::Unsafe>();
|
psyqo::GTE::clear<psyqo::GTE::Register::TRY, psyqo::GTE::Unsafe>();
|
||||||
@@ -24,14 +33,12 @@ void psxsplash::Renderer::init(psyqo::GPU &gpuInstance) {
|
|||||||
psyqo::GTE::write<psyqo::GTE::Register::ZSF4, psyqo::GTE::Unsafe>(
|
psyqo::GTE::write<psyqo::GTE::Register::ZSF4, psyqo::GTE::Unsafe>(
|
||||||
ORDERING_TABLE_SIZE / 4);
|
ORDERING_TABLE_SIZE / 4);
|
||||||
|
|
||||||
if(!instance) {
|
if (!instance) {
|
||||||
instance = new Renderer(gpuInstance);
|
instance = new Renderer(gpuInstance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void psxsplash::Renderer::render(eastl::vector<GameObject *> &objects) {
|
||||||
|
|
||||||
void psxsplash::Renderer::render(eastl::array<GameObject> &objects) {
|
|
||||||
uint8_t parity = m_gpu.getParity();
|
uint8_t parity = m_gpu.getParity();
|
||||||
|
|
||||||
auto &ot = m_ots[parity];
|
auto &ot = m_ots[parity];
|
||||||
@@ -47,19 +54,21 @@ void psxsplash::Renderer::render(eastl::array<GameObject> &objects) {
|
|||||||
|
|
||||||
for (auto &obj : objects) {
|
for (auto &obj : objects) {
|
||||||
|
|
||||||
psyqo::GTE::write<psyqo::GTE::Register::TRX, psyqo::GTE::Unsafe>(
|
/*psyqo::GTE::write<psyqo::GTE::Register::TRX, psyqo::GTE::Unsafe>(
|
||||||
obj.position.x.raw());
|
obj->position.x.raw());
|
||||||
psyqo::GTE::write<psyqo::GTE::Register::TRY, psyqo::GTE::Unsafe>(
|
psyqo::GTE::write<psyqo::GTE::Register::TRY, psyqo::GTE::Unsafe>(
|
||||||
obj.position.y.raw());
|
obj->position.y.raw());
|
||||||
psyqo::GTE::write<psyqo::GTE::Register::TRZ, psyqo::GTE::Unsafe>(
|
|
||||||
obj.position.z.raw());
|
|
||||||
|
|
||||||
psyqo::GTE::writeUnsafe<psyqo::GTE::PseudoRegister::Rotation>(
|
psyqo::GTE::writeUnsafe<psyqo::GTE::PseudoRegister::Rotation>(
|
||||||
obj.rotation);
|
obj->rotation);*/
|
||||||
|
|
||||||
for (int i = 0; i < obj.polyCount; i++) {
|
psyqo::GTE::write<psyqo::GTE::Register::TRZ, psyqo::GTE::Unsafe>(1024);
|
||||||
|
psyqo::GTE::writeUnsafe<psyqo::GTE::PseudoRegister::Rotation>(
|
||||||
|
obj->rotation);
|
||||||
|
for (int i = 0; i < obj->polyCount; i++) {
|
||||||
|
|
||||||
Tri& tri = obj.polygons[i];
|
Tri &tri = obj->polygons[i];
|
||||||
|
|
||||||
psyqo::GTE::writeUnsafe<psyqo::GTE::PseudoRegister::V0>(tri.v0);
|
psyqo::GTE::writeUnsafe<psyqo::GTE::PseudoRegister::V0>(tri.v0);
|
||||||
psyqo::GTE::writeUnsafe<psyqo::GTE::PseudoRegister::V1>(tri.v1);
|
psyqo::GTE::writeUnsafe<psyqo::GTE::PseudoRegister::V1>(tri.v1);
|
||||||
@@ -71,22 +80,22 @@ void psxsplash::Renderer::render(eastl::array<GameObject> &objects) {
|
|||||||
int32_t mac0 = 0;
|
int32_t mac0 = 0;
|
||||||
psyqo::GTE::read<psyqo::GTE::Register::MAC0>(
|
psyqo::GTE::read<psyqo::GTE::Register::MAC0>(
|
||||||
reinterpret_cast<uint32_t *>(&mac0));
|
reinterpret_cast<uint32_t *>(&mac0));
|
||||||
if (mac0 <= 0)
|
// if (mac0 <= 0)
|
||||||
continue;
|
// continue;
|
||||||
|
|
||||||
psyqo::GTE::Kernels::avsz4();
|
psyqo::GTE::Kernels::avsz3();
|
||||||
int32_t zIndex = 0;
|
int32_t zIndex = 0;
|
||||||
psyqo::GTE::read<psyqo::GTE::Register::OTZ>(
|
psyqo::GTE::read<psyqo::GTE::Register::OTZ>(
|
||||||
reinterpret_cast<uint32_t *>(&zIndex));
|
reinterpret_cast<uint32_t *>(&zIndex));
|
||||||
if (zIndex < 0 || zIndex >= ORDERING_TABLE_SIZE)
|
// if (zIndex < 0 || zIndex >= ORDERING_TABLE_SIZE)
|
||||||
continue;
|
// continue;
|
||||||
|
|
||||||
psyqo::GTE::read<psyqo::GTE::Register::SXY0>(&projected[1].packed);
|
psyqo::GTE::read<psyqo::GTE::Register::SXY0>(&projected[0].packed);
|
||||||
psyqo::GTE::read<psyqo::GTE::Register::SXY1>(&projected[2].packed);
|
psyqo::GTE::read<psyqo::GTE::Register::SXY1>(&projected[1].packed);
|
||||||
psyqo::GTE::read<psyqo::GTE::Register::SXY2>(&projected[3].packed);
|
psyqo::GTE::read<psyqo::GTE::Register::SXY2>(&projected[2].packed);
|
||||||
|
|
||||||
auto &prim = balloc.allocate<psyqo::Fragments::SimpleFragment<
|
auto &prim =
|
||||||
psyqo::Prim::TexturedTriangle>>();
|
balloc.allocateFragment<psyqo::Prim::TexturedTriangle>();
|
||||||
|
|
||||||
prim.primitive.pointA = projected[0];
|
prim.primitive.pointA = projected[0];
|
||||||
prim.primitive.pointB = projected[1];
|
prim.primitive.pointB = projected[1];
|
||||||
@@ -94,7 +103,11 @@ void psxsplash::Renderer::render(eastl::array<GameObject> &objects) {
|
|||||||
prim.primitive.uvA = tri.uvA;
|
prim.primitive.uvA = tri.uvA;
|
||||||
prim.primitive.uvB = tri.uvB;
|
prim.primitive.uvB = tri.uvB;
|
||||||
prim.primitive.uvC = tri.uvC;
|
prim.primitive.uvC = tri.uvC;
|
||||||
prim.primitive.tpage = obj.texture;
|
prim.primitive.tpage = obj->texture;
|
||||||
|
prim.primitive.tpage.setPageX(5);
|
||||||
|
prim.primitive.tpage.setPageY(0);
|
||||||
|
|
||||||
|
prim.primitive.setOpaque();
|
||||||
|
|
||||||
ot.insert(prim, zIndex);
|
ot.insert(prim, zIndex);
|
||||||
}
|
}
|
||||||
@@ -103,7 +116,9 @@ void psxsplash::Renderer::render(eastl::array<GameObject> &objects) {
|
|||||||
m_gpu.chain(ot);
|
m_gpu.chain(ot);
|
||||||
}
|
}
|
||||||
|
|
||||||
void psxsplash::Renderer::vramUpload(const uint16_t * imageData, int16_t posX, int16_t posY, int16_t width, int16_t height) {
|
void psxsplash::Renderer::vramUpload(const uint16_t *imageData, int16_t posX,
|
||||||
|
int16_t posY, int16_t width,
|
||||||
|
int16_t height) {
|
||||||
psyqo::Rect uploadRect{.a = {.x = posX, .y = posY}, .b = {width, height}};
|
psyqo::Rect uploadRect{.a = {.x = posX, .y = posY}, .b = {width, height}};
|
||||||
m_gpu.uploadToVRAM(imageData, uploadRect);
|
m_gpu.uploadToVRAM(imageData, uploadRect);
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "EASTL/array.h"
|
#include "EASTL/vector.h"
|
||||||
#include "gameobject.hh"
|
#include "gameobject.hh"
|
||||||
#include "psyqo/bump-allocator.hh"
|
#include "psyqo/bump-allocator.hh"
|
||||||
#include "psyqo/fragments.hh"
|
#include "psyqo/fragments.hh"
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
#include "psyqo/primitives/misc.hh"
|
#include "psyqo/primitives/misc.hh"
|
||||||
#include "psyqo/trigonometry.hh"
|
#include "psyqo/trigonometry.hh"
|
||||||
#include "psyqo/kernel.hh"
|
#include "psyqo/kernel.hh"
|
||||||
|
#include "psyqo//fixed-point.hh"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace psxsplash {
|
namespace psxsplash {
|
||||||
@@ -25,7 +26,7 @@ class Renderer final {
|
|||||||
|
|
||||||
static void init(psyqo::GPU &gpuInstance);
|
static void init(psyqo::GPU &gpuInstance);
|
||||||
|
|
||||||
void render(eastl::array<GameObject> &objects);
|
void render(eastl::vector<GameObject*> &objects);
|
||||||
void vramUpload(const uint16_t* imageData, int16_t posX, int16_t posY, int16_t width, int16_t height);
|
void vramUpload(const uint16_t* imageData, int16_t posX, int16_t posY, int16_t width, int16_t height);
|
||||||
|
|
||||||
static Renderer& getInstance() {
|
static Renderer& getInstance() {
|
||||||
@@ -36,6 +37,7 @@ class Renderer final {
|
|||||||
private:
|
private:
|
||||||
static Renderer* instance;
|
static Renderer* instance;
|
||||||
|
|
||||||
|
|
||||||
Renderer(psyqo::GPU &gpuInstance) : m_gpu(gpuInstance) {}
|
Renderer(psyqo::GPU &gpuInstance) : m_gpu(gpuInstance) {}
|
||||||
~Renderer() { }
|
~Renderer() { }
|
||||||
|
|
||||||
@@ -47,6 +49,7 @@ class Renderer final {
|
|||||||
psyqo::Color m_clearcolor = {.r = 63, .g = 63, .b = 63};
|
psyqo::Color m_clearcolor = {.r = 63, .g = 63, .b = 63};
|
||||||
psyqo::BumpAllocator<BUMP_ALLOCATOR_SIZE> m_ballocs[2];
|
psyqo::BumpAllocator<BUMP_ALLOCATOR_SIZE> m_ballocs[2];
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,32 +2,38 @@
|
|||||||
#include "gameobject.hh"
|
#include "gameobject.hh"
|
||||||
#include "mesh.hh"
|
#include "mesh.hh"
|
||||||
#include "renderer.hh"
|
#include "renderer.hh"
|
||||||
#include <cassert>
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
namespace psxsplash {
|
||||||
|
|
||||||
eastl::vector<psxsplash::GameObject*> LoadSplashpack(uint8_t *data) {
|
eastl::vector<psxsplash::GameObject*> LoadSplashpack(uint8_t *data) {
|
||||||
assert(data != nullptr);
|
psyqo::Kernel::assert(data != nullptr, "Splashpack loading data pointer is null");
|
||||||
psxsplash::SPLASHPACKFileHeader *header =
|
psxsplash::SPLASHPACKFileHeader *header =
|
||||||
reinterpret_cast<psxsplash::SPLASHPACKFileHeader *>(data);
|
reinterpret_cast<psxsplash::SPLASHPACKFileHeader *>(data);
|
||||||
assert(memcmp(header->magic, "SP", 10) == 0);
|
psyqo::Kernel::assert(memcmp(header->magic, "SP", 2) == 0, "Splashpack has incorrect magic");
|
||||||
|
|
||||||
eastl::vector<psxsplash::GameObject*> gameObjects;
|
eastl::vector<psxsplash::GameObject*> gameObjects;
|
||||||
gameObjects.reserve(header->gameObjectCount);
|
gameObjects.reserve(header->gameObjectCount);
|
||||||
|
|
||||||
uint8_t* curentPointer = data += sizeof(psxsplash::SPLASHPACKFileHeader);
|
uint8_t* curentPointer = data + sizeof(psxsplash::SPLASHPACKFileHeader);
|
||||||
|
|
||||||
for(uint16_t i = 0; i < header->gameObjectCount; i++) {
|
for(uint16_t i = 0; i < header->gameObjectCount; i++) {
|
||||||
psxsplash::GameObject* go = reinterpret_cast<psxsplash::GameObject*>(curentPointer);
|
psxsplash::GameObject* go = reinterpret_cast<psxsplash::GameObject*>(curentPointer);
|
||||||
go->polygons = reinterpret_cast<psxsplash::Tri*>(data += go->polygonsOffset);
|
go->polygons = reinterpret_cast<psxsplash::Tri*>(data + go->polygonsOffset);
|
||||||
gameObjects.push_back(go);
|
gameObjects.push_back(go);
|
||||||
curentPointer += sizeof(psxsplash::GameObject);
|
curentPointer += sizeof(psxsplash::GameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(uint16_t i = 0; i < header->textureAtlasCount; i++) {
|
for(uint16_t i = 0; i < header->textureAtlasCount; i++) {
|
||||||
psxsplash::SPLASHPACKTextureAtlas* atlas = reinterpret_cast<psxsplash::SPLASHPACKTextureAtlas *>(curentPointer);
|
psxsplash::SPLASHPACKTextureAtlas* atlas = reinterpret_cast<psxsplash::SPLASHPACKTextureAtlas *>(curentPointer);
|
||||||
psxsplash::Renderer::getInstance().vramUpload((uint16_t*) (data += atlas->polygonsOffset), atlas->x, atlas->y, atlas->width, atlas->height);
|
|
||||||
|
uint8_t* offsetData = data + atlas->polygonsOffset; // Ensure correct byte offset
|
||||||
|
uint16_t* castedData = reinterpret_cast<uint16_t*>(offsetData); // Safe cast
|
||||||
|
psxsplash::Renderer::getInstance().vramUpload(castedData, atlas->x, atlas->y, atlas->width, atlas->height);
|
||||||
}
|
}
|
||||||
|
|
||||||
return gameObjects;
|
return gameObjects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,6 +18,6 @@ struct SPLASHPACKTextureAtlas {
|
|||||||
uint16_t x,y;
|
uint16_t x,y;
|
||||||
};
|
};
|
||||||
|
|
||||||
eastl::vector<GameObject> LoadSplashpack(const uint8_t *data);
|
eastl::vector<GameObject*> LoadSplashpack(uint8_t *data);
|
||||||
|
|
||||||
}; // namespace psxsplash
|
}; // namespace psxsplash
|
||||||
Reference in New Issue
Block a user