Created and implemented scenemanager, include cleanup, fixed winbuild?
This commit is contained in:
2
Makefile
2
Makefile
@@ -9,6 +9,8 @@ src/camera.cpp \
|
|||||||
src/gtemath.cpp \
|
src/gtemath.cpp \
|
||||||
src/navmesh.cpp \
|
src/navmesh.cpp \
|
||||||
src/lua.cpp \
|
src/lua.cpp \
|
||||||
|
src/scenemanager.cpp \
|
||||||
|
src/controls.cpp \
|
||||||
output.o
|
output.o
|
||||||
|
|
||||||
include third_party/nugget/psyqo-lua/psyqo-lua.mk
|
include third_party/nugget/psyqo-lua/psyqo-lua.mk
|
||||||
|
|||||||
BIN
output.bin
BIN
output.bin
Binary file not shown.
56
src/controls.cpp
Normal file
56
src/controls.cpp
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
#include "controls.hh"
|
||||||
|
|
||||||
|
#include <psyqo/vector.hh>
|
||||||
|
|
||||||
|
void psxsplash::Controls::Init() { m_input.initialize(); }
|
||||||
|
|
||||||
|
void psxsplash::Controls::HandleControls(psyqo::Vec3 &playerPosition, psyqo::Angle &playerRotationX,
|
||||||
|
psyqo::Angle &playerRotationY, psyqo::Angle &playerRotationZ, bool freecam,
|
||||||
|
int deltaTime) {
|
||||||
|
uint8_t rightX = m_input.getAdc(psyqo::AdvancedPad::Pad::Pad1a, 0);
|
||||||
|
uint8_t rightY = m_input.getAdc(psyqo::AdvancedPad::Pad::Pad1a, 1);
|
||||||
|
|
||||||
|
uint8_t leftX = m_input.getAdc(psyqo::AdvancedPad::Pad::Pad1a, 2);
|
||||||
|
uint8_t leftY = m_input.getAdc(psyqo::AdvancedPad::Pad::Pad1a, 3);
|
||||||
|
|
||||||
|
int16_t rightXOffset = (int16_t)rightX - 0x80;
|
||||||
|
int16_t rightYOffset = (int16_t)rightY - 0x80;
|
||||||
|
int16_t leftXOffset = (int16_t)leftX - 0x80;
|
||||||
|
int16_t leftYOffset = (int16_t)leftY - 0x80;
|
||||||
|
|
||||||
|
if (__builtin_abs(leftXOffset) < m_stickDeadzone && __builtin_abs(leftYOffset) < m_stickDeadzone) {
|
||||||
|
m_sprinting = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_input.isButtonPressed(psyqo::AdvancedPad::Pad::Pad1a, psyqo::AdvancedPad::Button::L3)) {
|
||||||
|
m_sprinting = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
psyqo::FixedPoint<12> speed = m_sprinting ? sprintSpeed : moveSpeed;
|
||||||
|
|
||||||
|
if (__builtin_abs(rightXOffset) > m_stickDeadzone) {
|
||||||
|
playerRotationY += (rightXOffset * rotSpeed * deltaTime) >> 7;
|
||||||
|
}
|
||||||
|
if (__builtin_abs(rightYOffset) > m_stickDeadzone) {
|
||||||
|
playerRotationX -= (rightYOffset * rotSpeed * deltaTime) >> 7;
|
||||||
|
playerRotationX = eastl::clamp(playerRotationX, -0.5_pi, 0.5_pi);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (__builtin_abs(leftYOffset) > m_stickDeadzone) {
|
||||||
|
psyqo::FixedPoint<12> forward = -(leftYOffset * speed * deltaTime) >> 7;
|
||||||
|
playerPosition.x += m_trig.sin(playerRotationY) * forward;
|
||||||
|
playerPosition.z += m_trig.cos(playerRotationY) * forward;
|
||||||
|
}
|
||||||
|
if (__builtin_abs(leftXOffset) > m_stickDeadzone) {
|
||||||
|
psyqo::FixedPoint<12> strafe = -(leftXOffset * speed * deltaTime) >> 7;
|
||||||
|
playerPosition.x -= m_trig.cos(playerRotationY) * strafe;
|
||||||
|
playerPosition.z += m_trig.sin(playerRotationY) * strafe;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_input.isButtonPressed(psyqo::AdvancedPad::Pad::Pad1a, psyqo::AdvancedPad::Button::L1)) {
|
||||||
|
playerPosition.y += speed * deltaTime;
|
||||||
|
}
|
||||||
|
if (m_input.isButtonPressed(psyqo::AdvancedPad::Pad::Pad1a, psyqo::AdvancedPad::Button::R1)) {
|
||||||
|
playerPosition.y -= speed * deltaTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
29
src/controls.hh
Normal file
29
src/controls.hh
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <psyqo/advancedpad.hh>
|
||||||
|
#include <psyqo/trigonometry.hh>
|
||||||
|
#include <psyqo/vector.hh>
|
||||||
|
|
||||||
|
namespace psxsplash {
|
||||||
|
|
||||||
|
using namespace psyqo::fixed_point_literals;
|
||||||
|
using namespace psyqo::trig_literals;
|
||||||
|
|
||||||
|
class Controls {
|
||||||
|
public:
|
||||||
|
void Init();
|
||||||
|
void HandleControls(psyqo::Vec3 &playerPosition, psyqo::Angle &playerRotationX, psyqo::Angle &playerRotationY,
|
||||||
|
psyqo::Angle &playerRotationZ, bool freecam, int deltaTime);
|
||||||
|
|
||||||
|
private:
|
||||||
|
psyqo::AdvancedPad m_input;
|
||||||
|
psyqo::Trig<> m_trig;
|
||||||
|
|
||||||
|
bool m_sprinting = false;
|
||||||
|
static constexpr uint8_t m_stickDeadzone = 0x30;
|
||||||
|
static constexpr psyqo::FixedPoint<12> moveSpeed = 0.002_fp;
|
||||||
|
static constexpr psyqo::Angle rotSpeed = 0.01_pi;
|
||||||
|
static constexpr psyqo::FixedPoint<12> sprintSpeed = 0.01_fp;
|
||||||
|
};
|
||||||
|
|
||||||
|
}; // namespace psxsplash
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <psyqo/matrix.hh>
|
#include <psyqo/matrix.hh>
|
||||||
#include <psyqo/vector.hh>
|
#include <psyqo/vector.hh>
|
||||||
|
|
||||||
@@ -17,7 +16,7 @@ class GameObject final {
|
|||||||
psyqo::Vec3 position;
|
psyqo::Vec3 position;
|
||||||
psyqo::Matrix33 rotation;
|
psyqo::Matrix33 rotation;
|
||||||
uint16_t polyCount;
|
uint16_t polyCount;
|
||||||
uint16_t reserved;
|
int16_t luaFileIndex;
|
||||||
};
|
};
|
||||||
static_assert(sizeof(GameObject) == 56, "GameObject is not 56 bytes");
|
static_assert(sizeof(GameObject) == 56, "GameObject is not 56 bytes");
|
||||||
} // namespace psxsplash
|
} // namespace psxsplash
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <psyqo/matrix.hh>
|
#include <psyqo/matrix.hh>
|
||||||
|
|
||||||
namespace psxsplash {
|
namespace psxsplash {
|
||||||
|
|||||||
176
src/lua.cpp
176
src/lua.cpp
@@ -1,44 +1,38 @@
|
|||||||
#include "lua.h"
|
#include "lua.h"
|
||||||
|
|
||||||
|
#include <psyqo-lua/lua.hh>
|
||||||
|
|
||||||
#include <psyqo/xprintf.h>
|
#include <psyqo/xprintf.h>
|
||||||
|
|
||||||
#include "gameobject.hh"
|
#include "gameobject.hh"
|
||||||
#include "psyqo-lua/lua.hh"
|
|
||||||
|
|
||||||
constexpr const char METATABLE_SCRIPT[] = R"(
|
constexpr const char METATABLE_SCRIPT[] = R"(
|
||||||
metatableForAllGameObjects = {
|
return function(metatable)
|
||||||
__index = function(self, key)
|
local get_position = metatable.get_position
|
||||||
if key == "position" then
|
local set_position = metatable.set_position
|
||||||
local pos = rawget(self, key)
|
|
||||||
if pos == nil then
|
|
||||||
pos = get_position(self.__cpp_ptr)
|
|
||||||
end
|
|
||||||
return pos
|
|
||||||
end
|
|
||||||
return nil
|
|
||||||
end,
|
|
||||||
|
|
||||||
__newindex = function(self, key, value)
|
metatable.get_position = nil
|
||||||
if key == "position" then
|
metatable.set_position = nil
|
||||||
set_position(self.__cpp_ptr, value)
|
|
||||||
return
|
function metatable.__index(self, key)
|
||||||
end
|
if key == "position" then
|
||||||
rawset(self, key, value)
|
return get_position(self.__cpp_ptr)
|
||||||
end
|
end
|
||||||
}
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
function metatable.__newindex(self, key, value)
|
||||||
|
if key == "position" then
|
||||||
|
set_position(self.__cpp_ptr, value)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
rawset(self, key, value)
|
||||||
|
end
|
||||||
|
end
|
||||||
)";
|
)";
|
||||||
|
|
||||||
// Lua helpers
|
// Lua helpers
|
||||||
|
|
||||||
int traceback(lua_State *L) {
|
|
||||||
const char *msg = lua_tostring(L, 1);
|
|
||||||
if (msg)
|
|
||||||
luaL_traceback(L, L, msg, 1);
|
|
||||||
else
|
|
||||||
lua_pushliteral(L, "(no error message)");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int gameobjectSetPosition(psyqo::Lua L) {
|
static int gameobjectSetPosition(psyqo::Lua L) {
|
||||||
auto go = L.toUserdata<psxsplash::GameObject>(1);
|
auto go = L.toUserdata<psxsplash::GameObject>(1);
|
||||||
L.getField(2, "x");
|
L.getField(2, "x");
|
||||||
@@ -69,46 +63,67 @@ static int gameobjectGetPosition(psyqo::Lua L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void psxsplash::Lua::Init() {
|
void psxsplash::Lua::Init() {
|
||||||
// L.push(luaPrint);
|
|
||||||
// L.setGlobal("print");
|
|
||||||
|
|
||||||
L.push(gameobjectGetPosition);
|
|
||||||
L.setGlobal("get_position");
|
|
||||||
|
|
||||||
L.push(gameobjectSetPosition);
|
|
||||||
L.setGlobal("set_position");
|
|
||||||
|
|
||||||
// Load and run the metatable script
|
// Load and run the metatable script
|
||||||
if (L.loadBuffer(METATABLE_SCRIPT, "metatableForAllGameObjects") == 0) {
|
if (L.loadBuffer(METATABLE_SCRIPT, "buffer:metatableForAllGameObjects") == 0) {
|
||||||
if (L.pcall(0, 0) == 0) {
|
if (L.pcall(0, 1) == 0) {
|
||||||
// Script executed successfully
|
// This will be our metatable
|
||||||
printf("Lua script 'metatableForAllGameObjects' loaded successfully\n");
|
L.newTable();
|
||||||
|
|
||||||
|
L.push(gameobjectGetPosition);
|
||||||
|
L.setField(-2, "get_position");
|
||||||
|
|
||||||
|
L.push(gameobjectSetPosition);
|
||||||
|
L.setField(-2, "set_position");
|
||||||
|
|
||||||
|
L.copy(-1);
|
||||||
|
m_metatableReference = L.ref();
|
||||||
|
|
||||||
|
if (L.pcall(1, 0) == 0) {
|
||||||
|
printf("Lua script 'metatableForAllGameObjects' executed successfully");
|
||||||
|
} else {
|
||||||
|
printf("Error registering Lua script: %s\n", L.optString(-1, "Unknown error"));
|
||||||
|
L.clearStack();
|
||||||
|
return;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Print Lua error if script execution fails
|
// Print Lua error if script execution fails
|
||||||
printf("Error executing Lua script: %s\n", L.isString(-1) ? L.toString(-1) : "Unknown error");
|
printf("Error executing Lua script: %s\n", L.optString(-1, "Unknown error"));
|
||||||
L.pop();
|
L.clearStack();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Print Lua error if script loading fails
|
// Print Lua error if script loading fails
|
||||||
printf("Error loading Lua script: %s\n", L.isString(-1) ? L.toString(-1) : "Unknown error");
|
printf("Error loading Lua script: %s\n", L.optString(-1, "Unknown error"));
|
||||||
L.pop();
|
L.clearStack();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the metatable was set as a global
|
L.newTable();
|
||||||
L.getGlobal("metatableForAllGameObjects");
|
m_luascriptsReference = L.ref();
|
||||||
if (L.isTable(-1)) {
|
|
||||||
printf("metatableForAllGameObjects successfully set as a global\n");
|
|
||||||
} else {
|
|
||||||
printf("Warning: metatableForAllGameObjects not found after init\n");
|
|
||||||
}
|
|
||||||
L.pop(); // Pop the global check
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void psxsplash::Lua::LoadLuaFile(const char* code, size_t len) {
|
void psxsplash::Lua::LoadLuaFile(const char* code, size_t len, int index) {
|
||||||
if (L.loadBuffer(code, len) != LUA_OK) {
|
char filename[32];
|
||||||
|
snprintf(filename, sizeof(filename), "lua_asset:%d", index);
|
||||||
|
if (L.loadBuffer(code, len, filename) != LUA_OK) {
|
||||||
printf("Lua error: %s\n", L.toString(-1));
|
printf("Lua error: %s\n", L.toString(-1));
|
||||||
L.pop();
|
L.pop();
|
||||||
}
|
}
|
||||||
|
// (1) script func
|
||||||
|
L.rawGetI(LUA_REGISTRYINDEX, m_luascriptsReference);
|
||||||
|
// (1) script func (2) scripts table
|
||||||
|
L.newTable();
|
||||||
|
// (1) script func (2) scripts table (3) {}
|
||||||
|
L.pushNumber(index);
|
||||||
|
// (1) script func (2) scripts table (3) {} (4) index
|
||||||
|
L.copy(-2);
|
||||||
|
// (1) script func (2) scripts table (3) {} (4) index (5) {}
|
||||||
|
L.setTable(-4);
|
||||||
|
// (1) script func (2) scripts table (3) {}
|
||||||
|
lua_setupvalue(L.getState(), -3, 1);
|
||||||
|
// (1) script func (2) scripts table
|
||||||
|
L.pop();
|
||||||
|
// (1) script func
|
||||||
if (L.pcall(0, 0)) {
|
if (L.pcall(0, 0)) {
|
||||||
printf("Lua error: %s\n", L.toString(-1));
|
printf("Lua error: %s\n", L.toString(-1));
|
||||||
L.pop();
|
L.pop();
|
||||||
@@ -116,42 +131,41 @@ void psxsplash::Lua::LoadLuaFile(const char* code, size_t len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void psxsplash::Lua::RegisterGameObject(GameObject* go) {
|
void psxsplash::Lua::RegisterGameObject(GameObject* go) {
|
||||||
L.push(go); // (1) = GameObject*
|
L.push(go);
|
||||||
// Create a new Lua table for the GameObject
|
// (1) go
|
||||||
L.newTable(); // (1) = GameObject*, (2) = {}
|
L.newTable();
|
||||||
|
// (1) go (2) {}
|
||||||
// Set the __cpp_ptr field to store the C++ pointer
|
L.push(go);
|
||||||
L.push(go); // (1) = GameObject*, (2) = {}, (3) = GameObject*
|
// (1) go (2) {} (3) go
|
||||||
L.setField(-2, "__cpp_ptr");
|
L.setField(-2, "__cpp_ptr");
|
||||||
// (1) = GameObject*, (2) = { __cpp_ptr = GameObject* }
|
// (1) go (2) { __cpp_ptr = go }
|
||||||
|
L.rawGetI(LUA_REGISTRYINDEX, m_metatableReference);
|
||||||
// Set the metatable for the table
|
// (1) go (2) { __cpp_ptr = go } (3) metatable
|
||||||
L.getGlobal("metatableForAllGameObjects");
|
|
||||||
// (1) = GameObject*, (2) = { __cpp_ptr = GameObject* }, (3) = metatableForAllGameObjects
|
|
||||||
if (L.isTable(-1)) {
|
if (L.isTable(-1)) {
|
||||||
L.setMetatable(-2); // Set the metatable for the table
|
L.setMetatable(-2);
|
||||||
} else {
|
} else {
|
||||||
printf("Warning: metatableForAllGameObjects not found\n");
|
printf("Warning: metatableForAllGameObjects not found\n");
|
||||||
L.pop(); // Pop the invalid metatable
|
L.pop();
|
||||||
}
|
}
|
||||||
// (1) = GameObject*, (2) = { __cpp_ptr = GameObject* + metatable }
|
// (1) go (2) { __cpp_ptr = go + metatable }
|
||||||
|
|
||||||
L.rawSet(LUA_REGISTRYINDEX);
|
L.rawSet(LUA_REGISTRYINDEX);
|
||||||
|
// empty stack
|
||||||
// stack empty
|
|
||||||
|
|
||||||
// Debugging: Confirm the GameObject was registered
|
|
||||||
printf("GameObject registered in Lua registry: %p\n", go);
|
printf("GameObject registered in Lua registry: %p\n", go);
|
||||||
}
|
}
|
||||||
|
|
||||||
void psxsplash::Lua::CallOnCollide(GameObject* self, GameObject* other) {
|
void psxsplash::Lua::CallOnCollide(GameObject* self, GameObject* other) {
|
||||||
L.push(traceback);
|
if (self->luaFileIndex == -1) {
|
||||||
int errfunc = L.getTop(); // Save the error function index
|
return;
|
||||||
|
}
|
||||||
L.getGlobal("onCollision");
|
L.rawGetI(LUA_REGISTRYINDEX, m_luascriptsReference);
|
||||||
|
// (1) scripts table
|
||||||
|
L.rawGetI(-1, self->luaFileIndex);
|
||||||
|
// (1) script table (2) script environment
|
||||||
|
L.getField(-1, "onCollision");
|
||||||
|
// (1) script table (2) script environment (3) onCollision
|
||||||
if (!L.isFunction(-1)) {
|
if (!L.isFunction(-1)) {
|
||||||
printf("Lua function 'onCollide' not found\n");
|
printf("Lua function 'onCollision' not found\n");
|
||||||
L.pop();
|
L.clearStack();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,8 +174,8 @@ void psxsplash::Lua::CallOnCollide(GameObject* self, GameObject* other) {
|
|||||||
|
|
||||||
if (L.pcall(2, 0) != LUA_OK) {
|
if (L.pcall(2, 0) != LUA_OK) {
|
||||||
printf("Lua error: %s\n", L.toString(-1));
|
printf("Lua error: %s\n", L.toString(-1));
|
||||||
L.pop();
|
|
||||||
}
|
}
|
||||||
|
L.clearStack();
|
||||||
}
|
}
|
||||||
|
|
||||||
void psxsplash::Lua::PushGameObject(GameObject* go) {
|
void psxsplash::Lua::PushGameObject(GameObject* go) {
|
||||||
|
|||||||
14
src/lua.h
14
src/lua.h
@@ -5,16 +5,28 @@
|
|||||||
#include "gameobject.hh"
|
#include "gameobject.hh"
|
||||||
|
|
||||||
namespace psxsplash {
|
namespace psxsplash {
|
||||||
|
|
||||||
|
struct LuaFile {
|
||||||
|
union {
|
||||||
|
uint32_t luaCodeOffset;
|
||||||
|
const char* luaCode;
|
||||||
|
};
|
||||||
|
uint32_t length;
|
||||||
|
};
|
||||||
|
|
||||||
class Lua {
|
class Lua {
|
||||||
public:
|
public:
|
||||||
void Init();
|
void Init();
|
||||||
|
|
||||||
void LoadLuaFile(const char* code, size_t len);
|
void LoadLuaFile(const char* code, size_t len, int index);
|
||||||
void RegisterGameObject(GameObject* go);
|
void RegisterGameObject(GameObject* go);
|
||||||
void CallOnCollide(GameObject* self, GameObject* other);
|
void CallOnCollide(GameObject* self, GameObject* other);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void PushGameObject(GameObject* go);
|
void PushGameObject(GameObject* go);
|
||||||
psyqo::Lua L;
|
psyqo::Lua L;
|
||||||
|
|
||||||
|
int m_metatableReference;
|
||||||
|
int m_luascriptsReference;
|
||||||
};
|
};
|
||||||
} // namespace psxsplash
|
} // namespace psxsplash
|
||||||
134
src/main.cpp
134
src/main.cpp
@@ -1,7 +1,3 @@
|
|||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <psyqo/advancedpad.hh>
|
#include <psyqo/advancedpad.hh>
|
||||||
#include <psyqo/application.hh>
|
#include <psyqo/application.hh>
|
||||||
#include <psyqo/fixed-point.hh>
|
#include <psyqo/fixed-point.hh>
|
||||||
@@ -10,56 +6,29 @@
|
|||||||
#include <psyqo/scene.hh>
|
#include <psyqo/scene.hh>
|
||||||
#include <psyqo/trigonometry.hh>
|
#include <psyqo/trigonometry.hh>
|
||||||
|
|
||||||
#include "EASTL/algorithm.h"
|
|
||||||
#include "camera.hh"
|
|
||||||
#include "lua.h"
|
|
||||||
#include "navmesh.hh"
|
|
||||||
#include "psyqo/vector.hh"
|
|
||||||
#include "renderer.hh"
|
#include "renderer.hh"
|
||||||
#include "splashpack.hh"
|
#include "scenemanager.hh"
|
||||||
|
|
||||||
// Data from the splashpack
|
// Data from the splashpack
|
||||||
extern uint8_t _binary_output_bin_start[];
|
extern uint8_t _binary_output_bin_start[];
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
using namespace psyqo::fixed_point_literals;
|
|
||||||
using namespace psyqo::trig_literals;
|
|
||||||
|
|
||||||
class PSXSplash final : public psyqo::Application {
|
class PSXSplash final : public psyqo::Application {
|
||||||
void prepare() override;
|
void prepare() override;
|
||||||
void createScene() override;
|
void createScene() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
psxsplash::Lua m_lua;
|
|
||||||
psxsplash::SplashPackLoader m_loader;
|
|
||||||
|
|
||||||
psyqo::Font<> m_font;
|
psyqo::Font<> m_font;
|
||||||
|
|
||||||
psyqo::AdvancedPad m_input;
|
|
||||||
static constexpr uint8_t m_stickDeadzone = 0x30;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
psxsplash::Camera m_mainCamera;
|
|
||||||
psyqo::Angle camRotX, camRotY, camRotZ;
|
|
||||||
|
|
||||||
psyqo::Trig<> m_trig;
|
|
||||||
uint32_t m_lastFrameCounter;
|
uint32_t m_lastFrameCounter;
|
||||||
|
|
||||||
static constexpr psyqo::FixedPoint<12> moveSpeed = 0.002_fp;
|
psxsplash::SceneManager m_sceneManager;
|
||||||
static constexpr psyqo::Angle rotSpeed = 0.01_pi;
|
|
||||||
|
|
||||||
bool m_sprinting = false;
|
|
||||||
static constexpr psyqo::FixedPoint<12> sprintSpeed = 0.01_fp;
|
|
||||||
|
|
||||||
bool m_freecam = false;
|
|
||||||
psyqo::FixedPoint<12> pheight = 0.0_fp;
|
|
||||||
|
|
||||||
bool m_renderSelect = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
PSXSplash app;
|
PSXSplash app;
|
||||||
@@ -77,49 +46,16 @@ void PSXSplash::prepare() {
|
|||||||
|
|
||||||
// Initialize the Renderer singleton
|
// Initialize the Renderer singleton
|
||||||
psxsplash::Renderer::Init(gpu());
|
psxsplash::Renderer::Init(gpu());
|
||||||
|
|
||||||
m_lua.Init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) { m_sceneManager.InitializeScene(_binary_output_bin_start); }
|
||||||
app.m_loader.LoadSplashpack(_binary_output_bin_start, app.m_lua);
|
|
||||||
psxsplash::Renderer::GetInstance().SetCamera(m_mainCamera);
|
|
||||||
|
|
||||||
m_mainCamera.SetPosition(static_cast<psyqo::FixedPoint<12>>(app.m_loader.playerStartPos.x),
|
|
||||||
static_cast<psyqo::FixedPoint<12>>(app.m_loader.playerStartPos.y),
|
|
||||||
static_cast<psyqo::FixedPoint<12>>(app.m_loader.playerStartPos.z));
|
|
||||||
|
|
||||||
pheight = psyqo::FixedPoint<12>(app.m_loader.playerHeight);
|
|
||||||
|
|
||||||
app.m_input.setOnEvent(
|
|
||||||
eastl::function<void(psyqo::AdvancedPad::Event)>{[this](const psyqo::AdvancedPad::Event& event) {
|
|
||||||
if (event.pad != psyqo::AdvancedPad::Pad::Pad1a) return;
|
|
||||||
if (app.m_loader.navmeshes.empty()) return;
|
|
||||||
if (event.type == psyqo::AdvancedPad::Event::ButtonPressed) {
|
|
||||||
if (event.button == psyqo::AdvancedPad::Button::Triangle) {
|
|
||||||
m_freecam = !m_freecam;
|
|
||||||
} else if (event.button == psyqo::AdvancedPad::Button::Square) {
|
|
||||||
m_renderSelect = !m_renderSelect;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}});
|
|
||||||
|
|
||||||
if (app.m_loader.navmeshes.empty()) {
|
|
||||||
m_freecam = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainScene::frame() {
|
void MainScene::frame() {
|
||||||
|
|
||||||
app.m_lua.CallOnCollide(app.m_loader.gameObjects[0], app.m_loader.gameObjects[1]);
|
|
||||||
|
|
||||||
|
|
||||||
uint32_t beginFrame = gpu().now();
|
uint32_t beginFrame = gpu().now();
|
||||||
auto currentFrameCounter = gpu().getFrameCount();
|
auto currentFrameCounter = gpu().getFrameCount();
|
||||||
auto deltaTime = currentFrameCounter - mainScene.m_lastFrameCounter;
|
auto deltaTime = currentFrameCounter - mainScene.m_lastFrameCounter;
|
||||||
@@ -131,70 +67,10 @@ void MainScene::frame() {
|
|||||||
|
|
||||||
mainScene.m_lastFrameCounter = currentFrameCounter;
|
mainScene.m_lastFrameCounter = currentFrameCounter;
|
||||||
|
|
||||||
uint8_t rightX = app.m_input.getAdc(psyqo::AdvancedPad::Pad::Pad1a, 0);
|
m_sceneManager.GameTick();
|
||||||
uint8_t rightY = app.m_input.getAdc(psyqo::AdvancedPad::Pad::Pad1a, 1);
|
|
||||||
|
|
||||||
uint8_t leftX = app.m_input.getAdc(psyqo::AdvancedPad::Pad::Pad1a, 2);
|
|
||||||
uint8_t leftY = app.m_input.getAdc(psyqo::AdvancedPad::Pad::Pad1a, 3);
|
|
||||||
|
|
||||||
int16_t rightXOffset = (int16_t)rightX - 0x80;
|
|
||||||
int16_t rightYOffset = (int16_t)rightY - 0x80;
|
|
||||||
int16_t leftXOffset = (int16_t)leftX - 0x80;
|
|
||||||
int16_t leftYOffset = (int16_t)leftY - 0x80;
|
|
||||||
|
|
||||||
if (__builtin_abs(leftXOffset) < app.m_stickDeadzone &&
|
|
||||||
__builtin_abs(leftYOffset) < app.m_stickDeadzone) {
|
|
||||||
m_sprinting = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (app.m_input.isButtonPressed(psyqo::AdvancedPad::Pad::Pad1a, psyqo::AdvancedPad::Button::L3)) {
|
|
||||||
m_sprinting = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
psyqo::FixedPoint<12> speed = m_sprinting ? sprintSpeed : moveSpeed;
|
|
||||||
|
|
||||||
if (__builtin_abs(rightXOffset) > app.m_stickDeadzone) {
|
|
||||||
camRotY += (rightXOffset * rotSpeed * deltaTime) >> 7;
|
|
||||||
}
|
|
||||||
if (__builtin_abs(rightYOffset) > app.m_stickDeadzone) {
|
|
||||||
camRotX -= (rightYOffset * rotSpeed * deltaTime) >> 7;
|
|
||||||
camRotX = eastl::clamp(camRotX, -0.5_pi, 0.5_pi);
|
|
||||||
}
|
|
||||||
m_mainCamera.SetRotation(camRotX, camRotY, camRotZ);
|
|
||||||
|
|
||||||
if (__builtin_abs(leftYOffset) > app.m_stickDeadzone) {
|
|
||||||
psyqo::FixedPoint<12> forward = -(leftYOffset * speed * deltaTime) >> 7;
|
|
||||||
m_mainCamera.MoveX((m_trig.sin(camRotY) * forward));
|
|
||||||
m_mainCamera.MoveZ((m_trig.cos(camRotY) * forward));
|
|
||||||
}
|
|
||||||
if (__builtin_abs(leftXOffset) > app.m_stickDeadzone) {
|
|
||||||
psyqo::FixedPoint<12> strafe = -(leftXOffset * speed * deltaTime) >> 7;
|
|
||||||
m_mainCamera.MoveX(-(m_trig.cos(camRotY) * strafe));
|
|
||||||
m_mainCamera.MoveZ((m_trig.sin(camRotY) * strafe));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (app.m_input.isButtonPressed(psyqo::AdvancedPad::Pad::Pad1a, psyqo::AdvancedPad::Button::L1)) {
|
|
||||||
m_mainCamera.MoveY(speed * deltaTime);
|
|
||||||
}
|
|
||||||
if (app.m_input.isButtonPressed(psyqo::AdvancedPad::Pad::Pad1a, psyqo::AdvancedPad::Button::R1)) {
|
|
||||||
m_mainCamera.MoveY(-speed * deltaTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_freecam) {
|
|
||||||
psyqo::Vec3 adjustedPosition =
|
|
||||||
psxsplash::ComputeNavmeshPosition(m_mainCamera.GetPosition(), *app.m_loader.navmeshes[0], -pheight);
|
|
||||||
m_mainCamera.SetPosition(adjustedPosition.x, adjustedPosition.y, adjustedPosition.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_renderSelect) {
|
|
||||||
psxsplash::Renderer::GetInstance().Render(app.m_loader.gameObjects);
|
|
||||||
} else {
|
|
||||||
psxsplash::Renderer::GetInstance().RenderNavmeshPreview(*app.m_loader.navmeshes[0], true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
app.m_font.chainprintf(gpu(), {{.x = 2, .y = 2}}, {{.r = 0xff, .g = 0xff, .b = 0xff}}, "FPS: %i",
|
app.m_font.chainprintf(gpu(), {{.x = 2, .y = 2}}, {{.r = 0xff, .g = 0xff, .b = 0xff}}, "FPS: %i",
|
||||||
gpu().getRefreshRate() / deltaTime);
|
gpu().getRefreshRate() / deltaTime);
|
||||||
|
|
||||||
gpu().pumpCallbacks();
|
gpu().pumpCallbacks();
|
||||||
uint32_t endFrame = gpu().now();
|
uint32_t endFrame = gpu().now();
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
#include "psyqo/fixed-point.hh"
|
#include <psyqo/fixed-point.hh>
|
||||||
#include "psyqo/vector.hh"
|
#include <psyqo/vector.hh>
|
||||||
|
|
||||||
using namespace psyqo::fixed_point_literals;
|
using namespace psyqo::fixed_point_literals;
|
||||||
|
|
||||||
@@ -80,10 +80,10 @@ psyqo::FixedPoint<12> CalculateY(const psyqo::Vec3& p, const NavMeshTri& tri) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
psyqo::Vec3 ComputeNavmeshPosition(psyqo::Vec3& position, Navmesh& navmesh, psyqo::FixedPoint<12> pheight) {
|
psyqo::Vec3 ComputeNavmeshPosition(psyqo::Vec3& position, Navmesh& navmesh, psyqo::FixedPoint<12> playerHeight) {
|
||||||
for (int i = 0; i < navmesh.triangleCount; i++) {
|
for (int i = 0; i < navmesh.triangleCount; i++) {
|
||||||
if (PointInTriangle(position, navmesh.polygons[i])) {
|
if (PointInTriangle(position, navmesh.polygons[i])) {
|
||||||
position.y = CalculateY(position, navmesh.polygons[i]) + pheight;
|
position.y = CalculateY(position, navmesh.polygons[i]) - playerHeight;
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,7 +108,7 @@ psyqo::Vec3 ComputeNavmeshPosition(psyqo::Vec3& position, Navmesh& navmesh, psyq
|
|||||||
if (distSq < minDist) {
|
if (distSq < minDist) {
|
||||||
minDist = distSq;
|
minDist = distSq;
|
||||||
closestPoint = proj;
|
closestPoint = proj;
|
||||||
position.y = CalculateY(position, navmesh.polygons[i]) + pheight;
|
position.y = CalculateY(position, navmesh.polygons[i]) - playerHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
#include <EASTL/array.h>
|
#include <EASTL/array.h>
|
||||||
#include <EASTL/vector.h>
|
#include <EASTL/vector.h>
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <psyqo/fixed-point.hh>
|
#include <psyqo/fixed-point.hh>
|
||||||
#include <psyqo/gte-kernels.hh>
|
#include <psyqo/gte-kernels.hh>
|
||||||
#include <psyqo/gte-registers.hh>
|
#include <psyqo/gte-registers.hh>
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
#include <EASTL/array.h>
|
#include <EASTL/array.h>
|
||||||
#include <EASTL/vector.h>
|
#include <EASTL/vector.h>
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <psyqo/bump-allocator.hh>
|
#include <psyqo/bump-allocator.hh>
|
||||||
#include <psyqo/fragments.hh>
|
#include <psyqo/fragments.hh>
|
||||||
#include <psyqo/gpu.hh>
|
#include <psyqo/gpu.hh>
|
||||||
@@ -25,7 +24,8 @@ class Renderer final {
|
|||||||
Renderer(const Renderer&) = delete;
|
Renderer(const Renderer&) = delete;
|
||||||
Renderer& operator=(const Renderer&) = delete;
|
Renderer& operator=(const Renderer&) = delete;
|
||||||
|
|
||||||
// FIXME: I have no idea how to precompute the required sizes of these. It would be best to allocate them based on the scene
|
// FIXME: I have no idea how to precompute the required sizes of these. It would be best to allocate them based on
|
||||||
|
// the scene
|
||||||
static constexpr size_t ORDERING_TABLE_SIZE = 2048 * 3;
|
static constexpr size_t ORDERING_TABLE_SIZE = 2048 * 3;
|
||||||
static constexpr size_t BUMP_ALLOCATOR_SIZE = 8096 * 24;
|
static constexpr size_t BUMP_ALLOCATOR_SIZE = 8096 * 24;
|
||||||
|
|
||||||
@@ -33,7 +33,6 @@ class Renderer final {
|
|||||||
|
|
||||||
void SetCamera(Camera& camera);
|
void SetCamera(Camera& camera);
|
||||||
|
|
||||||
|
|
||||||
void Render(eastl::vector<GameObject*>& objects);
|
void Render(eastl::vector<GameObject*>& objects);
|
||||||
void RenderNavmeshPreview(psxsplash::Navmesh navmesh, bool isOnMesh);
|
void RenderNavmeshPreview(psxsplash::Navmesh navmesh, bool isOnMesh);
|
||||||
|
|
||||||
@@ -61,8 +60,8 @@ class Renderer final {
|
|||||||
|
|
||||||
psyqo::Color m_clearcolor = {.r = 0, .g = 0, .b = 0};
|
psyqo::Color m_clearcolor = {.r = 0, .g = 0, .b = 0};
|
||||||
|
|
||||||
void recursiveSubdivideAndRender(Tri &tri, eastl::array<psyqo::Vertex, 3> &projected, int zIndex,
|
void recursiveSubdivideAndRender(Tri& tri, eastl::array<psyqo::Vertex, 3>& projected, int zIndex,
|
||||||
int maxIterations);
|
int maxIterations);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace psxsplash
|
} // namespace psxsplash
|
||||||
59
src/scenemanager.cpp
Normal file
59
src/scenemanager.cpp
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
#include "scenemanager.hh"
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#include "navmesh.hh"
|
||||||
|
#include "renderer.hh"
|
||||||
|
#include "splashpack.hh"
|
||||||
|
|
||||||
|
using namespace psyqo::trig_literals;
|
||||||
|
|
||||||
|
void psxsplash::SceneManager::InitializeScene(uint8_t* splashpackData) {
|
||||||
|
L.Init();
|
||||||
|
|
||||||
|
SplashpackSceneSetup sceneSetup;
|
||||||
|
m_loader.LoadSplashpack(splashpackData, sceneSetup);
|
||||||
|
|
||||||
|
m_luaFiles = std::move(sceneSetup.luaFiles);
|
||||||
|
m_gameObjects = std::move(sceneSetup.objects);
|
||||||
|
m_navmeshes = std::move(sceneSetup.navmeshes);
|
||||||
|
|
||||||
|
m_playerPosition = sceneSetup.playerStartPosition;
|
||||||
|
|
||||||
|
playerRotationX = 0.0_pi;
|
||||||
|
playerRotationY = 0.0_pi;
|
||||||
|
playerRotationZ = 0.0_pi;
|
||||||
|
|
||||||
|
m_playerHeight = sceneSetup.playerHeight;
|
||||||
|
|
||||||
|
// Load Lua files
|
||||||
|
for (int i = 0; i < m_luaFiles.size(); i++) {
|
||||||
|
auto luaFile = m_luaFiles[i];
|
||||||
|
L.LoadLuaFile(luaFile->luaCode, luaFile->length, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register game objects
|
||||||
|
for (auto object : m_gameObjects) {
|
||||||
|
L.RegisterGameObject(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_controls.Init();
|
||||||
|
Renderer::GetInstance().SetCamera(m_currentCamera);
|
||||||
|
}
|
||||||
|
|
||||||
|
void psxsplash::SceneManager::GameTick() {
|
||||||
|
auto& renderer = psxsplash::Renderer::GetInstance();
|
||||||
|
|
||||||
|
renderer.Render(m_gameObjects);
|
||||||
|
|
||||||
|
m_controls.HandleControls(m_playerPosition, playerRotationX, playerRotationY, playerRotationZ, false, 1);
|
||||||
|
if (!freecam) {
|
||||||
|
psxsplash::ComputeNavmeshPosition(m_playerPosition, *m_navmeshes[0],
|
||||||
|
static_cast<psyqo::FixedPoint<12>>(m_playerHeight));
|
||||||
|
}
|
||||||
|
|
||||||
|
m_currentCamera.SetPosition(static_cast<psyqo::FixedPoint<12>>(m_playerPosition.x),
|
||||||
|
static_cast<psyqo::FixedPoint<12>>(m_playerPosition.y),
|
||||||
|
static_cast<psyqo::FixedPoint<12>>(m_playerPosition.z));
|
||||||
|
m_currentCamera.SetRotation(playerRotationX, playerRotationY, playerRotationZ);
|
||||||
|
}
|
||||||
40
src/scenemanager.hh
Normal file
40
src/scenemanager.hh
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <EASTL/vector.h>
|
||||||
|
|
||||||
|
#include <psyqo/trigonometry.hh>
|
||||||
|
#include <psyqo/vector.hh>
|
||||||
|
|
||||||
|
#include "camera.hh"
|
||||||
|
#include "controls.hh"
|
||||||
|
#include "gameobject.hh"
|
||||||
|
#include "lua.h"
|
||||||
|
#include "splashpack.hh"
|
||||||
|
|
||||||
|
namespace psxsplash {
|
||||||
|
class SceneManager {
|
||||||
|
public:
|
||||||
|
void InitializeScene(uint8_t* splashpackData);
|
||||||
|
void GameTick();
|
||||||
|
|
||||||
|
private:
|
||||||
|
psxsplash::Lua L;
|
||||||
|
psxsplash::SplashPackLoader m_loader;
|
||||||
|
|
||||||
|
eastl::vector<LuaFile*> m_luaFiles;
|
||||||
|
eastl::vector<GameObject*> m_gameObjects;
|
||||||
|
eastl::vector<Navmesh*> m_navmeshes;
|
||||||
|
|
||||||
|
psxsplash::Controls m_controls;
|
||||||
|
|
||||||
|
psxsplash::Camera m_currentCamera;
|
||||||
|
|
||||||
|
psyqo::Vec3 m_playerPosition;
|
||||||
|
psyqo::Angle playerRotationX, playerRotationY, playerRotationZ;
|
||||||
|
|
||||||
|
psyqo::FixedPoint<12, uint16_t> m_playerHeight;
|
||||||
|
|
||||||
|
bool previewNavmesh = false;
|
||||||
|
bool freecam = false;
|
||||||
|
};
|
||||||
|
}; // namespace psxsplash
|
||||||
@@ -1,14 +1,15 @@
|
|||||||
#include "splashpack.hh"
|
#include "splashpack.hh"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <EASTL/vector.h>
|
||||||
#include <cstring>
|
|
||||||
|
#include <psyqo/fixed-point.hh>
|
||||||
|
#include <psyqo/gte-registers.hh>
|
||||||
#include <psyqo/primitives/common.hh>
|
#include <psyqo/primitives/common.hh>
|
||||||
|
|
||||||
#include "gameobject.hh"
|
#include "gameobject.hh"
|
||||||
#include "lua.h"
|
#include "lua.h"
|
||||||
#include "mesh.hh"
|
#include "mesh.hh"
|
||||||
#include "psyqo/fixed-point.hh"
|
#include "navmesh.hh"
|
||||||
#include "psyqo/gte-registers.hh"
|
|
||||||
#include "renderer.hh"
|
#include "renderer.hh"
|
||||||
|
|
||||||
namespace psxsplash {
|
namespace psxsplash {
|
||||||
@@ -27,14 +28,6 @@ struct SPLASHPACKFileHeader {
|
|||||||
uint16_t pad[2];
|
uint16_t pad[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SPLASHPACKLuaFile {
|
|
||||||
union {
|
|
||||||
uint32_t luaCodeOffset;
|
|
||||||
const char* luaCode;
|
|
||||||
};
|
|
||||||
uint32_t length;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SPLASHPACKTextureAtlas {
|
struct SPLASHPACKTextureAtlas {
|
||||||
uint32_t polygonsOffset;
|
uint32_t polygonsOffset;
|
||||||
uint16_t width, height;
|
uint16_t width, height;
|
||||||
@@ -49,39 +42,39 @@ struct SPLASHPACKClut {
|
|||||||
uint16_t pad;
|
uint16_t pad;
|
||||||
};
|
};
|
||||||
|
|
||||||
void SplashPackLoader::LoadSplashpack(uint8_t *data, psxsplash::Lua &lua) {
|
void SplashPackLoader::LoadSplashpack(uint8_t *data, SplashpackSceneSetup &setup) {
|
||||||
psyqo::Kernel::assert(data != nullptr, "Splashpack loading data pointer is null");
|
psyqo::Kernel::assert(data != nullptr, "Splashpack loading data pointer is null");
|
||||||
psxsplash::SPLASHPACKFileHeader *header = reinterpret_cast<psxsplash::SPLASHPACKFileHeader *>(data);
|
psxsplash::SPLASHPACKFileHeader *header = reinterpret_cast<psxsplash::SPLASHPACKFileHeader *>(data);
|
||||||
psyqo::Kernel::assert(memcmp(header->magic, "SP", 2) == 0, "Splashpack has incorrect magic");
|
psyqo::Kernel::assert(__builtin_memcmp(header->magic, "SP", 2) == 0, "Splashpack has incorrect magic");
|
||||||
|
|
||||||
playerStartPos = header->playerStartPos;
|
setup.playerStartPosition = header->playerStartPos;
|
||||||
playerStartRot = header->playerStartRot;
|
setup.playerStartRotation = header->playerStartRot;
|
||||||
playerHeight = header->playerHeight;
|
setup.playerHeight = header->playerHeight;
|
||||||
|
|
||||||
gameObjects.reserve(header->gameObjectCount);
|
setup.luaFiles.reserve(header->luaFileCount);
|
||||||
navmeshes.reserve(header->navmeshCount);
|
setup.objects.reserve(header->gameObjectCount);
|
||||||
|
setup.navmeshes.reserve(header->navmeshCount);
|
||||||
|
|
||||||
uint8_t *curentPointer = data + sizeof(psxsplash::SPLASHPACKFileHeader);
|
uint8_t *curentPointer = data + sizeof(psxsplash::SPLASHPACKFileHeader);
|
||||||
|
|
||||||
for (uint16_t i = 0; i < header->luaFileCount; i++) {
|
for (uint16_t i = 0; i < header->luaFileCount; i++) {
|
||||||
psxsplash::SPLASHPACKLuaFile *luaHeader = reinterpret_cast<psxsplash::SPLASHPACKLuaFile *>(curentPointer);
|
psxsplash::LuaFile *luaHeader = reinterpret_cast<psxsplash::LuaFile *>(curentPointer);
|
||||||
luaHeader->luaCode = reinterpret_cast<const char*>(data + luaHeader->luaCodeOffset);
|
luaHeader->luaCode = reinterpret_cast<const char *>(data + luaHeader->luaCodeOffset);
|
||||||
lua.LoadLuaFile(luaHeader->luaCode, luaHeader->length);
|
setup.luaFiles.push_back(luaHeader);
|
||||||
curentPointer += sizeof(psxsplash::SPLASHPACKLuaFile);
|
curentPointer += sizeof(psxsplash::LuaFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
lua.RegisterGameObject(go);
|
setup.objects.push_back(go);
|
||||||
gameObjects.push_back(go);
|
|
||||||
curentPointer += sizeof(psxsplash::GameObject);
|
curentPointer += sizeof(psxsplash::GameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint16_t i = 0; i < header->navmeshCount; i++) {
|
for (uint16_t i = 0; i < header->navmeshCount; i++) {
|
||||||
psxsplash::Navmesh *navmesh = reinterpret_cast<psxsplash::Navmesh *>(curentPointer);
|
psxsplash::Navmesh *navmesh = reinterpret_cast<psxsplash::Navmesh *>(curentPointer);
|
||||||
navmesh->polygons = reinterpret_cast<psxsplash::NavMeshTri *>(data + navmesh->polygonsOffset);
|
navmesh->polygons = reinterpret_cast<psxsplash::NavMeshTri *>(data + navmesh->polygonsOffset);
|
||||||
navmeshes.push_back(navmesh);
|
setup.navmeshes.push_back(navmesh);
|
||||||
curentPointer += sizeof(psxsplash::Navmesh);
|
curentPointer += sizeof(psxsplash::Navmesh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,25 +2,26 @@
|
|||||||
|
|
||||||
#include <EASTL/vector.h>
|
#include <EASTL/vector.h>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <psyqo/fixed-point.hh>
|
||||||
|
|
||||||
#include "gameobject.hh"
|
#include "gameobject.hh"
|
||||||
#include "lua.h"
|
#include "lua.h"
|
||||||
#include "navmesh.hh"
|
#include "navmesh.hh"
|
||||||
#include "psyqo/fixed-point.hh"
|
|
||||||
|
|
||||||
namespace psxsplash {
|
namespace psxsplash {
|
||||||
|
|
||||||
|
struct SplashpackSceneSetup {
|
||||||
|
eastl::vector<LuaFile *> luaFiles;
|
||||||
|
eastl::vector<GameObject *> objects;
|
||||||
|
eastl::vector<Navmesh *> navmeshes;
|
||||||
|
psyqo::GTE::PackedVec3 playerStartPosition;
|
||||||
|
psyqo::GTE::PackedVec3 playerStartRotation;
|
||||||
|
psyqo::FixedPoint<12, uint16_t> playerHeight;
|
||||||
|
};
|
||||||
|
|
||||||
class SplashPackLoader {
|
class SplashPackLoader {
|
||||||
public:
|
public:
|
||||||
eastl::vector<GameObject *> gameObjects;
|
void LoadSplashpack(uint8_t *data, SplashpackSceneSetup &setup);
|
||||||
eastl::vector<Navmesh *> navmeshes;
|
|
||||||
|
|
||||||
psyqo::GTE::PackedVec3 playerStartPos, playerStartRot;
|
|
||||||
psyqo::FixedPoint<12, uint16_t> playerHeight;
|
|
||||||
|
|
||||||
void LoadSplashpack(uint8_t *data, Lua &lua);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}; // namespace psxsplash
|
}; // namespace psxsplash
|
||||||
Reference in New Issue
Block a user