Including the binary of the splaspack, added FPS camera
This commit is contained in:
7
Makefile
7
Makefile
@@ -4,6 +4,11 @@ TYPE = ps-exe
|
||||
SRCS = \
|
||||
src/main.cpp \
|
||||
src/renderer.cpp \
|
||||
src/splashpack.cpp
|
||||
src/splashpack.cpp \
|
||||
src/camera.cpp \
|
||||
output.o
|
||||
|
||||
include third_party/nugget/psyqo/psyqo.mk
|
||||
|
||||
%.o: %.bin
|
||||
$(PREFIX)-objcopy -I binary --set-section-alignment .data=4 --rename-section .data=.rodata,alloc,load,readonly,data,contents -O $(FORMAT) -B mips $< $@
|
||||
|
||||
BIN
output.bin
Normal file
BIN
output.bin
Normal file
Binary file not shown.
53
src/camera.cpp
Normal file
53
src/camera.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#include "camera.hh"
|
||||
|
||||
#include <psyqo/fixed-point.hh>
|
||||
#include <psyqo/matrix.hh>
|
||||
#include <psyqo/soft-math.hh>
|
||||
#include <psyqo/trigonometry.hh>
|
||||
|
||||
psxsplash::Camera::Camera() {
|
||||
m_rotationMatrix = psyqo::SoftMath::generateRotationMatrix33(0, psyqo::SoftMath::Axis::X, m_trig);
|
||||
}
|
||||
|
||||
void psxsplash::Camera::moveX(psyqo::FixedPoint<12> x) { m_rotation.x += -x; }
|
||||
|
||||
void psxsplash::Camera::moveY(psyqo::FixedPoint<12> y) { m_rotation.y += -y; }
|
||||
|
||||
void psxsplash::Camera::moveZ(psyqo::FixedPoint<12> z) { m_rotation.z += -z; }
|
||||
|
||||
void psxsplash::Camera::setPosition(psyqo::FixedPoint<12> x, psyqo::FixedPoint<12> y, psyqo::FixedPoint<12> z) {
|
||||
m_rotation.x = -x;
|
||||
m_rotation.y = -y;
|
||||
m_rotation.z = -z;
|
||||
}
|
||||
|
||||
void psxsplash::Camera::rotateX(psyqo::Angle x) {
|
||||
auto rot = psyqo::SoftMath::generateRotationMatrix33(-x, psyqo::SoftMath::Axis::X, m_trig);
|
||||
|
||||
psyqo::SoftMath::multiplyMatrix33(m_rotationMatrix, rot, &m_rotationMatrix);
|
||||
}
|
||||
|
||||
void psxsplash::Camera::rotateY(psyqo::Angle y) {
|
||||
auto rot = psyqo::SoftMath::generateRotationMatrix33(-y, psyqo::SoftMath::Axis::Y, m_trig);
|
||||
|
||||
psyqo::SoftMath::multiplyMatrix33(m_rotationMatrix, rot, &m_rotationMatrix);
|
||||
}
|
||||
|
||||
void psxsplash::Camera::rotateZ(psyqo::Angle z) {
|
||||
auto rot = psyqo::SoftMath::generateRotationMatrix33(-z, psyqo::SoftMath::Axis::Y, m_trig);
|
||||
|
||||
psyqo::SoftMath::multiplyMatrix33(m_rotationMatrix, rot, &m_rotationMatrix);
|
||||
}
|
||||
|
||||
void psxsplash::Camera::setRotation(psyqo::Angle x, psyqo::Angle y, psyqo::Angle z) {
|
||||
auto rotX = psyqo::SoftMath::generateRotationMatrix33(x, psyqo::SoftMath::Axis::X, m_trig);
|
||||
auto rotY = psyqo::SoftMath::generateRotationMatrix33(y, psyqo::SoftMath::Axis::Y, m_trig);
|
||||
auto rotZ = psyqo::SoftMath::generateRotationMatrix33(z, psyqo::SoftMath::Axis::Z, m_trig);
|
||||
|
||||
psyqo::SoftMath::multiplyMatrix33(rotY, rotX, &rotY);
|
||||
|
||||
psyqo::SoftMath::multiplyMatrix33(rotY, rotZ, &rotY);
|
||||
m_rotationMatrix = rotY;
|
||||
}
|
||||
|
||||
psyqo::Matrix33& psxsplash::Camera::getRotation() { return m_rotationMatrix; }
|
||||
35
src/camera.hh
Normal file
35
src/camera.hh
Normal file
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <psyqo/fixed-point.hh>
|
||||
#include <psyqo/matrix.hh>
|
||||
#include <psyqo/trigonometry.hh>
|
||||
|
||||
namespace psxsplash {
|
||||
|
||||
class Camera {
|
||||
public:
|
||||
Camera();
|
||||
|
||||
void moveX(psyqo::FixedPoint<12> x);
|
||||
void moveY(psyqo::FixedPoint<12> y);
|
||||
void moveZ(psyqo::FixedPoint<12> y);
|
||||
|
||||
void setPosition(psyqo::FixedPoint<12> x, psyqo::FixedPoint<12> y, psyqo::FixedPoint<12> z);
|
||||
|
||||
psyqo::Vec3& getPosition() { return m_rotation; }
|
||||
|
||||
void rotateX(psyqo::Angle x);
|
||||
void rotateY(psyqo::Angle y);
|
||||
void rotateZ(psyqo::Angle z);
|
||||
|
||||
void setRotation(psyqo::Angle x, psyqo::Angle y, psyqo::Angle z);
|
||||
psyqo::Matrix33& getRotation();
|
||||
|
||||
private:
|
||||
psyqo::Matrix33 m_rotationMatrix;
|
||||
psyqo::Trig<> m_trig;
|
||||
psyqo::Vec3 m_rotation;
|
||||
};
|
||||
} // namespace psxsplash
|
||||
@@ -1,24 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "psyqo/matrix.hh"
|
||||
#include "psyqo/vector.hh"
|
||||
#include <cstdint>
|
||||
#include <psyqo/matrix.hh>
|
||||
#include <psyqo/vector.hh>
|
||||
|
||||
#include "mesh.hh"
|
||||
#include <cstdint>
|
||||
|
||||
namespace psxsplash {
|
||||
|
||||
class GameObject final {
|
||||
public:
|
||||
psyqo::Vec3 position; // 12 bytes
|
||||
psyqo::Matrix33 rotation; // 36 bytes
|
||||
uint16_t polyCount; // 2 bytes
|
||||
psyqo::PrimPieces::TPageAttr texture; // 2 bytes
|
||||
psyqo::Vec3 position; // 12 bytes
|
||||
psyqo::Matrix33 rotation; // 36 bytes
|
||||
uint16_t polyCount; // 2 bytes
|
||||
psyqo::PrimPieces::TPageAttr texture; // 2 bytes
|
||||
uint16_t clutX, clutY;
|
||||
uint16_t clut[256];
|
||||
union { // 4 bytes
|
||||
union { // 4 bytes
|
||||
Tri *polygons;
|
||||
uint32_t polygonsOffset;
|
||||
};
|
||||
};
|
||||
} // namespace psxsplash
|
||||
} // namespace psxsplash
|
||||
112
src/main.cpp
112
src/main.cpp
@@ -1,37 +1,55 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "EASTL/array.h"
|
||||
#include "gameobject.hh"
|
||||
#include "psyqo/application.hh"
|
||||
#include "psyqo/font.hh"
|
||||
#include "psyqo/gpu.hh"
|
||||
#include "psyqo/scene.hh"
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <psyqo/advancedpad.hh>
|
||||
#include <psyqo/application.hh>
|
||||
#include <psyqo/fixed-point.hh>
|
||||
#include <psyqo/font.hh>
|
||||
#include <psyqo/gpu.hh>
|
||||
#include <psyqo/scene.hh>
|
||||
#include <psyqo/trigonometry.hh>
|
||||
|
||||
#include "output.h"
|
||||
#include "camera.hh"
|
||||
#include "gameobject.hh"
|
||||
#include "renderer.hh"
|
||||
#include "splashpack.hh"
|
||||
|
||||
extern uint8_t _binary_output_bin_start[];
|
||||
|
||||
namespace {
|
||||
|
||||
class PSXSplash final : public psyqo::Application {
|
||||
using namespace psyqo::fixed_point_literals;
|
||||
using namespace psyqo::trig_literals;
|
||||
|
||||
class PSXSplash final : public psyqo::Application {
|
||||
void prepare() override;
|
||||
void createScene() override;
|
||||
|
||||
public:
|
||||
psyqo::Font<> m_font;
|
||||
psyqo::AdvancedPad m_input;
|
||||
};
|
||||
|
||||
class MainScene final : public psyqo::Scene {
|
||||
void frame() override;
|
||||
void start(StartReason reason) override;
|
||||
eastl::vector<psxsplash::GameObject *> objects;
|
||||
|
||||
psxsplash::Camera m_mainCamera;
|
||||
psyqo::Angle camRotX, camRotY, camRotZ;
|
||||
|
||||
eastl::vector<psxsplash::GameObject*> m_objects;
|
||||
psyqo::Trig<> m_trig;
|
||||
uint32_t m_lastFrameCounter;
|
||||
|
||||
static constexpr psyqo::FixedPoint<12> moveSpeed = 0.01_fp;
|
||||
static constexpr psyqo::Angle rotSpeed = 0.01_pi;
|
||||
};
|
||||
|
||||
PSXSplash psxSplash;
|
||||
MainScene mainScene;
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
void PSXSplash::prepare() {
|
||||
psyqo::GPU::Configuration config;
|
||||
@@ -45,13 +63,83 @@ void PSXSplash::prepare() {
|
||||
|
||||
void PSXSplash::createScene() {
|
||||
m_font.uploadSystemFont(gpu());
|
||||
m_input.initialize();
|
||||
pushScene(&mainScene);
|
||||
}
|
||||
|
||||
void MainScene::start(StartReason reason) {
|
||||
objects = psxsplash::LoadSplashpack(bin2c_output_bin);
|
||||
m_objects = psxsplash::LoadSplashpack(_binary_output_bin_start);
|
||||
psxsplash::Renderer::getInstance().setCamera(m_mainCamera);
|
||||
}
|
||||
|
||||
void MainScene::frame() { psxsplash::Renderer::getInstance().render(objects); }
|
||||
void MainScene::frame() {
|
||||
uint32_t beginFrame = gpu().now();
|
||||
auto currentFrameCounter = gpu().getFrameCount();
|
||||
auto frameDiff = currentFrameCounter - mainScene.m_lastFrameCounter;
|
||||
if (frameDiff == 0) {
|
||||
return;
|
||||
}
|
||||
mainScene.m_lastFrameCounter = currentFrameCounter;
|
||||
|
||||
auto& input = psxSplash.m_input;
|
||||
|
||||
if (input.isButtonPressed(psyqo::AdvancedPad::Pad::Pad1a, psyqo::AdvancedPad::Right)) {
|
||||
m_mainCamera.moveX((m_trig.cos(camRotY) * moveSpeed));
|
||||
m_mainCamera.moveZ(-(m_trig.sin(camRotY) * moveSpeed));
|
||||
}
|
||||
|
||||
if (input.isButtonPressed(psyqo::AdvancedPad::Pad::Pad1a, psyqo::AdvancedPad::Left)) {
|
||||
m_mainCamera.moveX(-(m_trig.cos(camRotY) * moveSpeed));
|
||||
m_mainCamera.moveZ((m_trig.sin(camRotY) * moveSpeed));
|
||||
}
|
||||
|
||||
if (input.isButtonPressed(psyqo::AdvancedPad::Pad::Pad1a, psyqo::AdvancedPad::Up)) {
|
||||
m_mainCamera.moveX((m_trig.sin(camRotY) * m_trig.cos(camRotX)) * moveSpeed);
|
||||
m_mainCamera.moveY(-(m_trig.sin(camRotX) * moveSpeed));
|
||||
m_mainCamera.moveZ((m_trig.cos(camRotY) * m_trig.cos(camRotX)) * moveSpeed);
|
||||
}
|
||||
|
||||
if (input.isButtonPressed(psyqo::AdvancedPad::Pad::Pad1a, psyqo::AdvancedPad::Down)) {
|
||||
m_mainCamera.moveX(-((m_trig.sin(camRotY) * m_trig.cos(camRotX)) * moveSpeed));
|
||||
m_mainCamera.moveY((m_trig.sin(camRotX) * moveSpeed));
|
||||
m_mainCamera.moveZ(-((m_trig.cos(camRotY) * m_trig.cos(camRotX)) * moveSpeed));
|
||||
}
|
||||
|
||||
if (input.isButtonPressed(psyqo::AdvancedPad::Pad::Pad1a, psyqo::AdvancedPad::R1)) {
|
||||
m_mainCamera.moveY(-moveSpeed);
|
||||
}
|
||||
|
||||
if (input.isButtonPressed(psyqo::AdvancedPad::Pad::Pad1a, psyqo::AdvancedPad::L1)) {
|
||||
m_mainCamera.moveY(moveSpeed);
|
||||
}
|
||||
|
||||
if (input.isButtonPressed(psyqo::AdvancedPad::Pad::Pad1a, psyqo::AdvancedPad::Cross)) {
|
||||
camRotX -= rotSpeed;
|
||||
m_mainCamera.setRotation(camRotX, camRotY, camRotZ);
|
||||
}
|
||||
|
||||
if (input.isButtonPressed(psyqo::AdvancedPad::Pad::Pad1a, psyqo::AdvancedPad::Triangle)) {
|
||||
camRotX += rotSpeed;
|
||||
m_mainCamera.setRotation(camRotX, camRotY, camRotZ);
|
||||
}
|
||||
|
||||
if (input.isButtonPressed(psyqo::AdvancedPad::Pad::Pad1a, psyqo::AdvancedPad::Circle)) {
|
||||
camRotY += rotSpeed;
|
||||
m_mainCamera.setRotation(camRotX, camRotY, camRotZ);
|
||||
}
|
||||
|
||||
if (input.isButtonPressed(psyqo::AdvancedPad::Pad::Pad1a, psyqo::AdvancedPad::Square)) {
|
||||
camRotY -= rotSpeed;
|
||||
m_mainCamera.setRotation(camRotX, camRotY, camRotZ);
|
||||
}
|
||||
|
||||
psxsplash::Renderer::getInstance().render(m_objects);
|
||||
|
||||
psxSplash.m_font.chainprintf(gpu(), {{.x = 2, .y = 2}}, {{.r = 0xff, .g = 0xff, .b = 0xff}}, "FPS: %i",
|
||||
gpu().getRefreshRate() / frameDiff);
|
||||
gpu().pumpCallbacks();
|
||||
uint32_t endFrame = gpu().now();
|
||||
uint32_t spent = endFrame - beginFrame;
|
||||
}
|
||||
|
||||
int main() { return psxSplash.run(); }
|
||||
|
||||
11
src/output.h
11
src/output.h
File diff suppressed because one or more lines are too long
111
src/renderer.cpp
111
src/renderer.cpp
@@ -1,13 +1,15 @@
|
||||
#include "renderer.hh"
|
||||
|
||||
#include "EASTL/vector.h"
|
||||
#include "psyqo/fixed-point.hh"
|
||||
#include "psyqo/gte-kernels.hh"
|
||||
#include "psyqo/gte-registers.hh"
|
||||
#include "psyqo/primitives/common.hh"
|
||||
#include "psyqo/primitives/triangles.hh"
|
||||
#include "psyqo/soft-math.hh"
|
||||
#include "psyqo/trigonometry.hh"
|
||||
#include <EASTL/vector.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <psyqo/fixed-point.hh>
|
||||
#include <psyqo/gte-kernels.hh>
|
||||
#include <psyqo/gte-registers.hh>
|
||||
#include <psyqo/kernel.hh>
|
||||
#include <psyqo/primitives/common.hh>
|
||||
#include <psyqo/primitives/triangles.hh>
|
||||
#include <psyqo/vector.hh>
|
||||
|
||||
using namespace psyqo::fixed_point_literals;
|
||||
using namespace psyqo::trig_literals;
|
||||
@@ -15,31 +17,30 @@ using namespace psyqo::trig_literals;
|
||||
psxsplash::Renderer *psxsplash::Renderer::instance = nullptr;
|
||||
|
||||
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::TRY, psyqo::GTE::Unsafe>();
|
||||
psyqo::GTE::clear<psyqo::GTE::Register::TRZ, psyqo::GTE::Unsafe>();
|
||||
|
||||
psyqo::GTE::write<psyqo::GTE::Register::OFX, psyqo::GTE::Unsafe>(
|
||||
psyqo::FixedPoint<16>(160.0).raw());
|
||||
psyqo::GTE::write<psyqo::GTE::Register::OFY, psyqo::GTE::Unsafe>(
|
||||
psyqo::FixedPoint<16>(120.0).raw());
|
||||
psyqo::GTE::write<psyqo::GTE::Register::OFX, psyqo::GTE::Unsafe>(psyqo::FixedPoint<16>(160.0).raw());
|
||||
psyqo::GTE::write<psyqo::GTE::Register::OFY, psyqo::GTE::Unsafe>(psyqo::FixedPoint<16>(120.0).raw());
|
||||
|
||||
psyqo::GTE::write<psyqo::GTE::Register::H, psyqo::GTE::Unsafe>(120);
|
||||
|
||||
psyqo::GTE::write<psyqo::GTE::Register::ZSF3, psyqo::GTE::Unsafe>(
|
||||
ORDERING_TABLE_SIZE / 3);
|
||||
psyqo::GTE::write<psyqo::GTE::Register::ZSF4, psyqo::GTE::Unsafe>(
|
||||
ORDERING_TABLE_SIZE / 4);
|
||||
psyqo::GTE::write<psyqo::GTE::Register::ZSF3, psyqo::GTE::Unsafe>(ORDERING_TABLE_SIZE / 3);
|
||||
psyqo::GTE::write<psyqo::GTE::Register::ZSF4, psyqo::GTE::Unsafe>(ORDERING_TABLE_SIZE / 4);
|
||||
|
||||
if (!instance) {
|
||||
instance = new Renderer(gpuInstance);
|
||||
}
|
||||
}
|
||||
|
||||
void psxsplash::Renderer::setCamera(psxsplash::Camera &camera) { m_currentCamera = &camera; }
|
||||
|
||||
void psxsplash::Renderer::render(eastl::vector<GameObject *> &objects) {
|
||||
psyqo::Kernel::assert(m_currentCamera != nullptr, "PSXSPLASH: Tried to render without an active camera");
|
||||
|
||||
uint8_t parity = m_gpu.getParity();
|
||||
|
||||
auto &ot = m_ots[parity];
|
||||
@@ -54,45 +55,69 @@ void psxsplash::Renderer::render(eastl::vector<GameObject *> &objects) {
|
||||
balloc.reset();
|
||||
|
||||
for (auto &obj : objects) {
|
||||
|
||||
auto transform = psyqo::SoftMath::generateRotationMatrix33(
|
||||
0, psyqo::SoftMath::Axis::X, m_trig);
|
||||
psyqo::GTE::writeUnsafe<psyqo::GTE::PseudoRegister::Rotation>(
|
||||
transform);
|
||||
|
||||
for (int i = 0; i < obj->polyCount; i++) {
|
||||
|
||||
Tri &tri = obj->polygons[i];
|
||||
psyqo::Vec3 result;
|
||||
|
||||
psyqo::GTE::writeUnsafe<psyqo::GTE::PseudoRegister::V0>(tri.v0);
|
||||
psyqo::GTE::writeUnsafe<psyqo::GTE::PseudoRegister::V1>(tri.v1);
|
||||
psyqo::GTE::writeUnsafe<psyqo::GTE::PseudoRegister::V2>(tri.v2);
|
||||
psyqo::GTE::writeUnsafe<psyqo::GTE::PseudoRegister::Rotation>(obj->rotation);
|
||||
psyqo::GTE::write<psyqo::GTE::Register::TRX, psyqo::GTE::Unsafe>(obj->position.x.raw() +
|
||||
m_currentCamera->getPosition().x.raw());
|
||||
psyqo::GTE::write<psyqo::GTE::Register::TRY, psyqo::GTE::Unsafe>(obj->position.y.raw() +
|
||||
m_currentCamera->getPosition().y.raw());
|
||||
psyqo::GTE::write<psyqo::GTE::Register::TRZ, psyqo::GTE::Safe>(obj->position.z.raw() +
|
||||
m_currentCamera->getPosition().z.raw());
|
||||
|
||||
psyqo::GTE::writeSafe<psyqo::GTE::PseudoRegister::V0>(tri.v0);
|
||||
psyqo::GTE::writeSafe<psyqo::GTE::PseudoRegister::V1>(tri.v1);
|
||||
psyqo::GTE::writeSafe<psyqo::GTE::PseudoRegister::V2>(tri.v2);
|
||||
|
||||
psyqo::GTE::Kernels::mvmva<psyqo::GTE::Kernels::MX::RT, psyqo::GTE::Kernels::MV::V0,
|
||||
psyqo::GTE::Kernels::TV::TR>();
|
||||
result = psyqo::GTE::readSafe<psyqo::GTE::PseudoRegister::SV>();
|
||||
psyqo::GTE::writeSafe<psyqo::GTE::PseudoRegister::V0>(result);
|
||||
|
||||
psyqo::GTE::Kernels::mvmva<psyqo::GTE::Kernels::MX::RT, psyqo::GTE::Kernels::MV::V1,
|
||||
psyqo::GTE::Kernels::TV::TR>();
|
||||
result = psyqo::GTE::readSafe<psyqo::GTE::PseudoRegister::SV>();
|
||||
psyqo::GTE::writeSafe<psyqo::GTE::PseudoRegister::V1>(result);
|
||||
|
||||
psyqo::GTE::Kernels::mvmva<psyqo::GTE::Kernels::MX::RT, psyqo::GTE::Kernels::MV::V2,
|
||||
psyqo::GTE::Kernels::TV::TR>();
|
||||
result = psyqo::GTE::readSafe<psyqo::GTE::PseudoRegister::SV>();
|
||||
psyqo::GTE::writeSafe<psyqo::GTE::PseudoRegister::V2>(result);
|
||||
|
||||
psyqo::GTE::writeUnsafe<psyqo::GTE::PseudoRegister::Rotation>(m_currentCamera->getRotation());
|
||||
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::TRZ, psyqo::GTE::Unsafe>();
|
||||
|
||||
psyqo::GTE::Kernels::rtpt();
|
||||
psyqo::GTE::Kernels::nclip();
|
||||
|
||||
int32_t mac0 = 0;
|
||||
psyqo::GTE::read<psyqo::GTE::Register::MAC0>(
|
||||
reinterpret_cast<uint32_t *>(&mac0));
|
||||
if (mac0 <= 0)
|
||||
continue;
|
||||
psyqo::GTE::read<psyqo::GTE::Register::MAC0>(reinterpret_cast<uint32_t *>(&mac0));
|
||||
if (mac0 <= 0) continue;
|
||||
|
||||
psyqo::GTE::Kernels::avsz3();
|
||||
int32_t zIndex = 0;
|
||||
psyqo::GTE::read<psyqo::GTE::Register::OTZ>(
|
||||
reinterpret_cast<uint32_t *>(&zIndex));
|
||||
if (zIndex < 0 || zIndex >= ORDERING_TABLE_SIZE)
|
||||
continue;
|
||||
uint32_t sz0, sz1, sz2;
|
||||
psyqo::GTE::read<psyqo::GTE::Register::SZ0>(&sz0);
|
||||
psyqo::GTE::read<psyqo::GTE::Register::SZ1>(&sz1);
|
||||
psyqo::GTE::read<psyqo::GTE::Register::SZ2>(&sz2);
|
||||
|
||||
zIndex = eastl::max(eastl::max(sz0, sz1), sz2);
|
||||
|
||||
// psyqo::GTE::read<psyqo::GTE::Register::OTZ>(reinterpret_cast<uint32_t *>(&zIndex));
|
||||
|
||||
if (zIndex < 0 || zIndex >= ORDERING_TABLE_SIZE) continue;
|
||||
|
||||
psyqo::GTE::read<psyqo::GTE::Register::SXY0>(&projected[0].packed);
|
||||
psyqo::GTE::read<psyqo::GTE::Register::SXY1>(&projected[1].packed);
|
||||
psyqo::GTE::read<psyqo::GTE::Register::SXY2>(&projected[2].packed);
|
||||
|
||||
auto &prim =
|
||||
balloc.allocateFragment<psyqo::Prim::GouraudTexturedTriangle>();
|
||||
|
||||
auto &prim = balloc.allocateFragment<psyqo::Prim::GouraudTexturedTriangle>();
|
||||
|
||||
psyqo::PrimPieces::ClutIndex clut(obj->clutX, obj->clutY);
|
||||
|
||||
|
||||
prim.primitive.pointA = projected[0];
|
||||
prim.primitive.pointB = projected[1];
|
||||
prim.primitive.pointC = projected[2];
|
||||
@@ -104,7 +129,6 @@ void psxsplash::Renderer::render(eastl::vector<GameObject *> &objects) {
|
||||
prim.primitive.setColorA(tri.colorA);
|
||||
prim.primitive.setColorB(tri.colorB);
|
||||
prim.primitive.setColorC(tri.colorC);
|
||||
|
||||
|
||||
prim.primitive.setOpaque();
|
||||
|
||||
@@ -115,8 +139,7 @@ void psxsplash::Renderer::render(eastl::vector<GameObject *> &objects) {
|
||||
m_gpu.chain(ot);
|
||||
}
|
||||
|
||||
void psxsplash::Renderer::vramUpload(const uint16_t *imageData, int16_t posX,
|
||||
int16_t posY, int16_t width,
|
||||
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}};
|
||||
m_gpu.uploadToVRAM(imageData, uploadRect);
|
||||
|
||||
@@ -1,56 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include "EASTL/vector.h"
|
||||
#include "gameobject.hh"
|
||||
#include "psyqo/bump-allocator.hh"
|
||||
#include "psyqo/fragments.hh"
|
||||
#include "psyqo/gpu.hh"
|
||||
#include "psyqo/ordering-table.hh"
|
||||
#include "psyqo/primitives/common.hh"
|
||||
#include "psyqo/primitives/misc.hh"
|
||||
#include "psyqo/trigonometry.hh"
|
||||
#include "psyqo/kernel.hh"
|
||||
#include "psyqo//fixed-point.hh"
|
||||
#include <EASTL/vector.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <psyqo/bump-allocator.hh>
|
||||
#include <psyqo/fragments.hh>
|
||||
#include <psyqo/gpu.hh>
|
||||
#include <psyqo/kernel.hh>
|
||||
#include <psyqo/ordering-table.hh>
|
||||
#include <psyqo/primitives/common.hh>
|
||||
#include <psyqo/primitives/misc.hh>
|
||||
#include <psyqo/trigonometry.hh>
|
||||
|
||||
#include "camera.hh"
|
||||
#include "gameobject.hh"
|
||||
|
||||
namespace psxsplash {
|
||||
|
||||
class Renderer final {
|
||||
|
||||
public:
|
||||
public:
|
||||
Renderer(const Renderer&) = delete;
|
||||
Renderer& operator=(const Renderer&) = delete;
|
||||
|
||||
static constexpr size_t ORDERING_TABLE_SIZE = 4096*16;
|
||||
static constexpr size_t BUMP_ALLOCATOR_SIZE = 100000;
|
||||
static constexpr size_t ORDERING_TABLE_SIZE = 4096 * 16;
|
||||
static constexpr size_t BUMP_ALLOCATOR_SIZE = 8192;
|
||||
|
||||
static void init(psyqo::GPU &gpuInstance);
|
||||
static void init(psyqo::GPU& gpuInstance);
|
||||
|
||||
void render(eastl::vector<GameObject*> &objects);
|
||||
void setCamera(Camera& camera);
|
||||
|
||||
void render(eastl::vector<GameObject*>& objects);
|
||||
void vramUpload(const uint16_t* imageData, int16_t posX, int16_t posY, int16_t width, int16_t height);
|
||||
|
||||
static Renderer& getInstance() {
|
||||
psyqo::Kernel::assert(instance != nullptr, "Access to renderer was tried without prior initialization");
|
||||
return *instance;
|
||||
}
|
||||
psyqo::Kernel::assert(instance != nullptr, "Access to renderer was tried without prior initialization");
|
||||
return *instance;
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
static Renderer* instance;
|
||||
|
||||
Renderer(psyqo::GPU& gpuInstance) : m_gpu(gpuInstance) {}
|
||||
~Renderer() {}
|
||||
|
||||
Renderer(psyqo::GPU &gpuInstance) : m_gpu(gpuInstance) {}
|
||||
~Renderer() { }
|
||||
Camera* m_currentCamera;
|
||||
|
||||
psyqo::GPU &m_gpu;
|
||||
psyqo::GPU& m_gpu;
|
||||
psyqo::Trig<> m_trig;
|
||||
|
||||
psyqo::OrderingTable<ORDERING_TABLE_SIZE> m_ots[2];
|
||||
psyqo::Fragments::SimpleFragment<psyqo::Prim::FastFill> m_clear[2];
|
||||
psyqo::Color m_clearcolor = {.r = 63, .g = 63, .b = 63};
|
||||
psyqo::BumpAllocator<BUMP_ALLOCATOR_SIZE> m_ballocs[2];
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace psxsplash
|
||||
} // namespace psxsplash
|
||||
@@ -1,21 +1,20 @@
|
||||
#include "splashpack.hh"
|
||||
#include "gameobject.hh"
|
||||
#include "mesh.hh"
|
||||
#include "psyqo/primitives/common.hh"
|
||||
#include "renderer.hh"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <psyqo/primitives/common.hh>
|
||||
|
||||
#include "gameobject.hh"
|
||||
#include "mesh.hh"
|
||||
#include "renderer.hh"
|
||||
|
||||
namespace psxsplash {
|
||||
|
||||
eastl::vector<psxsplash::GameObject *> LoadSplashpack(uint8_t *data) {
|
||||
psyqo::Kernel::assert(data != nullptr,
|
||||
"Splashpack loading data pointer is null");
|
||||
psxsplash::SPLASHPACKFileHeader *header =
|
||||
reinterpret_cast<psxsplash::SPLASHPACKFileHeader *>(data);
|
||||
psyqo::Kernel::assert(memcmp(header->magic, "SP", 2) == 0,
|
||||
"Splashpack has incorrect magic");
|
||||
psyqo::Kernel::assert(data != nullptr, "Splashpack loading data pointer is null");
|
||||
psxsplash::SPLASHPACKFileHeader *header = reinterpret_cast<psxsplash::SPLASHPACKFileHeader *>(data);
|
||||
psyqo::Kernel::assert(memcmp(header->magic, "SP", 2) == 0, "Splashpack has incorrect magic");
|
||||
|
||||
eastl::vector<psxsplash::GameObject *> gameObjects;
|
||||
gameObjects.reserve(header->gameObjectCount);
|
||||
@@ -23,49 +22,40 @@ eastl::vector<psxsplash::GameObject *> LoadSplashpack(uint8_t *data) {
|
||||
uint8_t *curentPointer = data + sizeof(psxsplash::SPLASHPACKFileHeader);
|
||||
|
||||
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);
|
||||
|
||||
int16_t width = 0;
|
||||
switch ((psyqo::Prim::TPageAttr::ColorMode)(
|
||||
(std::bit_cast<short>(go->texture) & 0x0180) >> 7)) {
|
||||
case psyqo::Prim::TPageAttr::ColorMode::Tex4Bits:
|
||||
width = 16;
|
||||
break;
|
||||
case psyqo::Prim::TPageAttr::ColorMode::Tex8Bits:
|
||||
width = 256;
|
||||
break;
|
||||
default:
|
||||
width = -1;
|
||||
switch ((psyqo::Prim::TPageAttr::ColorMode)((std::bit_cast<short>(go->texture) & 0x0180) >> 7)) {
|
||||
case psyqo::Prim::TPageAttr::ColorMode::Tex4Bits:
|
||||
width = 16;
|
||||
break;
|
||||
case psyqo::Prim::TPageAttr::ColorMode::Tex8Bits:
|
||||
width = 256;
|
||||
break;
|
||||
default:
|
||||
width = -1;
|
||||
}
|
||||
|
||||
if(width > 0) {
|
||||
psxsplash::Renderer::getInstance().vramUpload(
|
||||
go->clut, go->clutX*16, go->clutY, width, 1);
|
||||
if (width > 0) {
|
||||
psxsplash::Renderer::getInstance().vramUpload(go->clut, go->clutX * 16, go->clutY, width, 1);
|
||||
}
|
||||
|
||||
go->polygons =
|
||||
reinterpret_cast<psxsplash::Tri *>(data + go->polygonsOffset);
|
||||
go->polygons = reinterpret_cast<psxsplash::Tri *>(data + go->polygonsOffset);
|
||||
|
||||
gameObjects.push_back(go);
|
||||
curentPointer += sizeof(psxsplash::GameObject);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
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);
|
||||
curentPointer += sizeof(psxsplash::SPLASHPACKTextureAtlas);
|
||||
}
|
||||
|
||||
return gameObjects;
|
||||
}
|
||||
|
||||
} // namespace psxsplash
|
||||
} // namespace psxsplash
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "EASTL/vector.h"
|
||||
#include "gameobject.hh"
|
||||
#include <EASTL/vector.h>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "gameobject.hh"
|
||||
|
||||
namespace psxsplash {
|
||||
|
||||
struct SPLASHPACKFileHeader {
|
||||
@@ -15,9 +18,9 @@ struct SPLASHPACKFileHeader {
|
||||
struct SPLASHPACKTextureAtlas {
|
||||
uint32_t polygonsOffset;
|
||||
uint16_t width, height;
|
||||
uint16_t x,y;
|
||||
uint16_t x, y;
|
||||
};
|
||||
|
||||
eastl::vector<GameObject*> LoadSplashpack(uint8_t *data);
|
||||
eastl::vector<GameObject *> LoadSplashpack(uint8_t *data);
|
||||
|
||||
}; // namespace psxsplash
|
||||
}; // namespace psxsplash
|
||||
@@ -1,8 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "psyqo/primitives/common.hh"
|
||||
#include <psyqo/primitives/common.hh>
|
||||
|
||||
namespace psxsplash {
|
||||
class Texture final {
|
||||
@@ -11,4 +10,4 @@ class Texture final {
|
||||
uint8_t m_width, m_height;
|
||||
};
|
||||
|
||||
} // namespace psxsplash
|
||||
} // namespace psxsplash
|
||||
Reference in New Issue
Block a user