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 = \
|
SRCS = \
|
||||||
src/main.cpp \
|
src/main.cpp \
|
||||||
src/renderer.cpp \
|
src/renderer.cpp \
|
||||||
src/splashpack.cpp
|
src/splashpack.cpp \
|
||||||
|
src/camera.cpp \
|
||||||
|
output.o
|
||||||
|
|
||||||
include third_party/nugget/psyqo/psyqo.mk
|
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,10 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "psyqo/matrix.hh"
|
#include <cstdint>
|
||||||
#include "psyqo/vector.hh"
|
#include <psyqo/matrix.hh>
|
||||||
|
#include <psyqo/vector.hh>
|
||||||
|
|
||||||
#include "mesh.hh"
|
#include "mesh.hh"
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
namespace psxsplash {
|
namespace psxsplash {
|
||||||
|
|
||||||
|
|||||||
110
src/main.cpp
110
src/main.cpp
@@ -1,31 +1,49 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "EASTL/array.h"
|
#include <cmath>
|
||||||
#include "gameobject.hh"
|
#include <cstdint>
|
||||||
#include "psyqo/application.hh"
|
#include <psyqo/advancedpad.hh>
|
||||||
#include "psyqo/font.hh"
|
#include <psyqo/application.hh>
|
||||||
#include "psyqo/gpu.hh"
|
#include <psyqo/fixed-point.hh>
|
||||||
#include "psyqo/scene.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 "renderer.hh"
|
||||||
#include "splashpack.hh"
|
#include "splashpack.hh"
|
||||||
|
|
||||||
|
extern uint8_t _binary_output_bin_start[];
|
||||||
|
|
||||||
namespace {
|
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 prepare() override;
|
||||||
void createScene() override;
|
void createScene() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
psyqo::Font<> m_font;
|
psyqo::Font<> m_font;
|
||||||
|
psyqo::AdvancedPad m_input;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MainScene final : public psyqo::Scene {
|
class MainScene final : public psyqo::Scene {
|
||||||
void frame() override;
|
void frame() override;
|
||||||
void start(StartReason reason) 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;
|
PSXSplash psxSplash;
|
||||||
@@ -45,13 +63,83 @@ void PSXSplash::prepare() {
|
|||||||
|
|
||||||
void PSXSplash::createScene() {
|
void PSXSplash::createScene() {
|
||||||
m_font.uploadSystemFont(gpu());
|
m_font.uploadSystemFont(gpu());
|
||||||
|
m_input.initialize();
|
||||||
pushScene(&mainScene);
|
pushScene(&mainScene);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainScene::start(StartReason reason) {
|
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(); }
|
int main() { return psxSplash.run(); }
|
||||||
|
|||||||
11
src/output.h
11
src/output.h
File diff suppressed because one or more lines are too long
107
src/renderer.cpp
107
src/renderer.cpp
@@ -1,13 +1,15 @@
|
|||||||
#include "renderer.hh"
|
#include "renderer.hh"
|
||||||
|
|
||||||
#include "EASTL/vector.h"
|
#include <EASTL/vector.h>
|
||||||
#include "psyqo/fixed-point.hh"
|
|
||||||
#include "psyqo/gte-kernels.hh"
|
#include <cstdint>
|
||||||
#include "psyqo/gte-registers.hh"
|
#include <psyqo/fixed-point.hh>
|
||||||
#include "psyqo/primitives/common.hh"
|
#include <psyqo/gte-kernels.hh>
|
||||||
#include "psyqo/primitives/triangles.hh"
|
#include <psyqo/gte-registers.hh>
|
||||||
#include "psyqo/soft-math.hh"
|
#include <psyqo/kernel.hh>
|
||||||
#include "psyqo/trigonometry.hh"
|
#include <psyqo/primitives/common.hh>
|
||||||
|
#include <psyqo/primitives/triangles.hh>
|
||||||
|
#include <psyqo/vector.hh>
|
||||||
|
|
||||||
using namespace psyqo::fixed_point_literals;
|
using namespace psyqo::fixed_point_literals;
|
||||||
using namespace psyqo::trig_literals;
|
using namespace psyqo::trig_literals;
|
||||||
@@ -15,31 +17,30 @@ using namespace psyqo::trig_literals;
|
|||||||
psxsplash::Renderer *psxsplash::Renderer::instance = nullptr;
|
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,
|
psyqo::Kernel::assert(instance == nullptr, "A second intialization of Renderer was tried");
|
||||||
"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>();
|
||||||
psyqo::GTE::clear<psyqo::GTE::Register::TRZ, psyqo::GTE::Unsafe>();
|
psyqo::GTE::clear<psyqo::GTE::Register::TRZ, psyqo::GTE::Unsafe>();
|
||||||
|
|
||||||
psyqo::GTE::write<psyqo::GTE::Register::OFX, psyqo::GTE::Unsafe>(
|
psyqo::GTE::write<psyqo::GTE::Register::OFX, psyqo::GTE::Unsafe>(psyqo::FixedPoint<16>(160.0).raw());
|
||||||
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::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::H, psyqo::GTE::Unsafe>(120);
|
||||||
|
|
||||||
psyqo::GTE::write<psyqo::GTE::Register::ZSF3, psyqo::GTE::Unsafe>(
|
psyqo::GTE::write<psyqo::GTE::Register::ZSF3, psyqo::GTE::Unsafe>(ORDERING_TABLE_SIZE / 3);
|
||||||
ORDERING_TABLE_SIZE / 3);
|
psyqo::GTE::write<psyqo::GTE::Register::ZSF4, psyqo::GTE::Unsafe>(ORDERING_TABLE_SIZE / 4);
|
||||||
psyqo::GTE::write<psyqo::GTE::Register::ZSF4, psyqo::GTE::Unsafe>(
|
|
||||||
ORDERING_TABLE_SIZE / 4);
|
|
||||||
|
|
||||||
if (!instance) {
|
if (!instance) {
|
||||||
instance = new Renderer(gpuInstance);
|
instance = new Renderer(gpuInstance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void psxsplash::Renderer::setCamera(psxsplash::Camera &camera) { m_currentCamera = &camera; }
|
||||||
|
|
||||||
void psxsplash::Renderer::render(eastl::vector<GameObject *> &objects) {
|
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();
|
uint8_t parity = m_gpu.getParity();
|
||||||
|
|
||||||
auto &ot = m_ots[parity];
|
auto &ot = m_ots[parity];
|
||||||
@@ -54,42 +55,66 @@ void psxsplash::Renderer::render(eastl::vector<GameObject *> &objects) {
|
|||||||
balloc.reset();
|
balloc.reset();
|
||||||
|
|
||||||
for (auto &obj : objects) {
|
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++) {
|
for (int i = 0; i < obj->polyCount; i++) {
|
||||||
|
|
||||||
Tri &tri = obj->polygons[i];
|
Tri &tri = obj->polygons[i];
|
||||||
|
psyqo::Vec3 result;
|
||||||
|
|
||||||
psyqo::GTE::writeUnsafe<psyqo::GTE::PseudoRegister::V0>(tri.v0);
|
psyqo::GTE::writeUnsafe<psyqo::GTE::PseudoRegister::Rotation>(obj->rotation);
|
||||||
psyqo::GTE::writeUnsafe<psyqo::GTE::PseudoRegister::V1>(tri.v1);
|
psyqo::GTE::write<psyqo::GTE::Register::TRX, psyqo::GTE::Unsafe>(obj->position.x.raw() +
|
||||||
psyqo::GTE::writeUnsafe<psyqo::GTE::PseudoRegister::V2>(tri.v2);
|
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::rtpt();
|
||||||
psyqo::GTE::Kernels::nclip();
|
psyqo::GTE::Kernels::nclip();
|
||||||
|
|
||||||
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) continue;
|
||||||
if (mac0 <= 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
psyqo::GTE::Kernels::avsz3();
|
|
||||||
int32_t zIndex = 0;
|
int32_t zIndex = 0;
|
||||||
psyqo::GTE::read<psyqo::GTE::Register::OTZ>(
|
uint32_t sz0, sz1, sz2;
|
||||||
reinterpret_cast<uint32_t *>(&zIndex));
|
psyqo::GTE::read<psyqo::GTE::Register::SZ0>(&sz0);
|
||||||
if (zIndex < 0 || zIndex >= ORDERING_TABLE_SIZE)
|
psyqo::GTE::read<psyqo::GTE::Register::SZ1>(&sz1);
|
||||||
continue;
|
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::SXY0>(&projected[0].packed);
|
||||||
psyqo::GTE::read<psyqo::GTE::Register::SXY1>(&projected[1].packed);
|
psyqo::GTE::read<psyqo::GTE::Register::SXY1>(&projected[1].packed);
|
||||||
psyqo::GTE::read<psyqo::GTE::Register::SXY2>(&projected[2].packed);
|
psyqo::GTE::read<psyqo::GTE::Register::SXY2>(&projected[2].packed);
|
||||||
|
|
||||||
auto &prim =
|
auto &prim = balloc.allocateFragment<psyqo::Prim::GouraudTexturedTriangle>();
|
||||||
balloc.allocateFragment<psyqo::Prim::GouraudTexturedTriangle>();
|
|
||||||
|
|
||||||
psyqo::PrimPieces::ClutIndex clut(obj->clutX, obj->clutY);
|
psyqo::PrimPieces::ClutIndex clut(obj->clutX, obj->clutY);
|
||||||
|
|
||||||
@@ -105,7 +130,6 @@ void psxsplash::Renderer::render(eastl::vector<GameObject *> &objects) {
|
|||||||
prim.primitive.setColorB(tri.colorB);
|
prim.primitive.setColorB(tri.colorB);
|
||||||
prim.primitive.setColorC(tri.colorC);
|
prim.primitive.setColorC(tri.colorC);
|
||||||
|
|
||||||
|
|
||||||
prim.primitive.setOpaque();
|
prim.primitive.setOpaque();
|
||||||
|
|
||||||
ot.insert(prim, zIndex);
|
ot.insert(prim, zIndex);
|
||||||
@@ -115,8 +139,7 @@ void psxsplash::Renderer::render(eastl::vector<GameObject *> &objects) {
|
|||||||
m_gpu.chain(ot);
|
m_gpu.chain(ot);
|
||||||
}
|
}
|
||||||
|
|
||||||
void psxsplash::Renderer::vramUpload(const uint16_t *imageData, int16_t posX,
|
void psxsplash::Renderer::vramUpload(const uint16_t *imageData, int16_t posX, int16_t posY, int16_t width,
|
||||||
int16_t posY, int16_t width,
|
|
||||||
int16_t height) {
|
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,31 +1,34 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "EASTL/vector.h"
|
#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 <cstdint>
|
#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 {
|
namespace psxsplash {
|
||||||
|
|
||||||
class Renderer final {
|
class Renderer final {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Renderer(const Renderer&) = delete;
|
Renderer(const Renderer&) = delete;
|
||||||
Renderer& operator=(const Renderer&) = delete;
|
Renderer& operator=(const Renderer&) = delete;
|
||||||
|
|
||||||
static constexpr size_t ORDERING_TABLE_SIZE = 4096 * 16;
|
static constexpr size_t ORDERING_TABLE_SIZE = 4096 * 16;
|
||||||
static constexpr size_t BUMP_ALLOCATOR_SIZE = 100000;
|
static constexpr size_t BUMP_ALLOCATOR_SIZE = 8192;
|
||||||
|
|
||||||
static void init(psyqo::GPU& gpuInstance);
|
static void init(psyqo::GPU& gpuInstance);
|
||||||
|
|
||||||
|
void setCamera(Camera& camera);
|
||||||
|
|
||||||
void render(eastl::vector<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);
|
||||||
|
|
||||||
@@ -37,10 +40,11 @@ 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() {}
|
||||||
|
|
||||||
|
Camera* m_currentCamera;
|
||||||
|
|
||||||
psyqo::GPU& m_gpu;
|
psyqo::GPU& m_gpu;
|
||||||
psyqo::Trig<> m_trig;
|
psyqo::Trig<> m_trig;
|
||||||
|
|
||||||
@@ -48,9 +52,6 @@ class Renderer final {
|
|||||||
psyqo::Fragments::SimpleFragment<psyqo::Prim::FastFill> m_clear[2];
|
psyqo::Fragments::SimpleFragment<psyqo::Prim::FastFill> m_clear[2];
|
||||||
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];
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace psxsplash
|
} // namespace psxsplash
|
||||||
@@ -1,21 +1,20 @@
|
|||||||
#include "splashpack.hh"
|
#include "splashpack.hh"
|
||||||
#include "gameobject.hh"
|
|
||||||
#include "mesh.hh"
|
|
||||||
#include "psyqo/primitives/common.hh"
|
|
||||||
#include "renderer.hh"
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <psyqo/primitives/common.hh>
|
||||||
|
|
||||||
|
#include "gameobject.hh"
|
||||||
|
#include "mesh.hh"
|
||||||
|
#include "renderer.hh"
|
||||||
|
|
||||||
namespace psxsplash {
|
namespace psxsplash {
|
||||||
|
|
||||||
eastl::vector<psxsplash::GameObject *> LoadSplashpack(uint8_t *data) {
|
eastl::vector<psxsplash::GameObject *> LoadSplashpack(uint8_t *data) {
|
||||||
psyqo::Kernel::assert(data != nullptr,
|
psyqo::Kernel::assert(data != nullptr, "Splashpack loading data pointer is null");
|
||||||
"Splashpack loading data pointer is null");
|
psxsplash::SPLASHPACKFileHeader *header = reinterpret_cast<psxsplash::SPLASHPACKFileHeader *>(data);
|
||||||
psxsplash::SPLASHPACKFileHeader *header =
|
psyqo::Kernel::assert(memcmp(header->magic, "SP", 2) == 0, "Splashpack has incorrect magic");
|
||||||
reinterpret_cast<psxsplash::SPLASHPACKFileHeader *>(data);
|
|
||||||
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);
|
||||||
@@ -23,12 +22,10 @@ eastl::vector<psxsplash::GameObject *> LoadSplashpack(uint8_t *data) {
|
|||||||
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 =
|
psxsplash::GameObject *go = reinterpret_cast<psxsplash::GameObject *>(curentPointer);
|
||||||
reinterpret_cast<psxsplash::GameObject *>(curentPointer);
|
|
||||||
|
|
||||||
int16_t width = 0;
|
int16_t width = 0;
|
||||||
switch ((psyqo::Prim::TPageAttr::ColorMode)(
|
switch ((psyqo::Prim::TPageAttr::ColorMode)((std::bit_cast<short>(go->texture) & 0x0180) >> 7)) {
|
||||||
(std::bit_cast<short>(go->texture) & 0x0180) >> 7)) {
|
|
||||||
case psyqo::Prim::TPageAttr::ColorMode::Tex4Bits:
|
case psyqo::Prim::TPageAttr::ColorMode::Tex4Bits:
|
||||||
width = 16;
|
width = 16;
|
||||||
break;
|
break;
|
||||||
@@ -40,28 +37,21 @@ eastl::vector<psxsplash::GameObject *> LoadSplashpack(uint8_t *data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (width > 0) {
|
if (width > 0) {
|
||||||
psxsplash::Renderer::getInstance().vramUpload(
|
psxsplash::Renderer::getInstance().vramUpload(go->clut, go->clutX * 16, go->clutY, width, 1);
|
||||||
go->clut, go->clutX*16, go->clutY, width, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
go->polygons =
|
go->polygons = reinterpret_cast<psxsplash::Tri *>(data + go->polygonsOffset);
|
||||||
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 =
|
psxsplash::SPLASHPACKTextureAtlas *atlas = reinterpret_cast<psxsplash::SPLASHPACKTextureAtlas *>(curentPointer);
|
||||||
reinterpret_cast<psxsplash::SPLASHPACKTextureAtlas *>(
|
|
||||||
curentPointer);
|
|
||||||
|
|
||||||
uint8_t *offsetData =
|
uint8_t *offsetData = data + atlas->polygonsOffset; // Ensure correct byte offset
|
||||||
data + atlas->polygonsOffset; // Ensure correct byte offset
|
uint16_t *castedData = reinterpret_cast<uint16_t *>(offsetData); // Safe cast
|
||||||
uint16_t *castedData =
|
psxsplash::Renderer::getInstance().vramUpload(castedData, atlas->x, atlas->y, atlas->width, atlas->height);
|
||||||
reinterpret_cast<uint16_t *>(offsetData); // Safe cast
|
|
||||||
psxsplash::Renderer::getInstance().vramUpload(
|
|
||||||
castedData, atlas->x, atlas->y, atlas->width, atlas->height);
|
|
||||||
curentPointer += sizeof(psxsplash::SPLASHPACKTextureAtlas);
|
curentPointer += sizeof(psxsplash::SPLASHPACKTextureAtlas);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "EASTL/vector.h"
|
#include <EASTL/vector.h>
|
||||||
#include "gameobject.hh"
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
#include "gameobject.hh"
|
||||||
|
|
||||||
namespace psxsplash {
|
namespace psxsplash {
|
||||||
|
|
||||||
struct SPLASHPACKFileHeader {
|
struct SPLASHPACKFileHeader {
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <psyqo/primitives/common.hh>
|
||||||
#include "psyqo/primitives/common.hh"
|
|
||||||
|
|
||||||
namespace psxsplash {
|
namespace psxsplash {
|
||||||
class Texture final {
|
class Texture final {
|
||||||
|
|||||||
Reference in New Issue
Block a user