small cleanup
This commit is contained in:
@@ -37,6 +37,8 @@ because Mesh rendering uses only core.render()
|
|||||||
- [renderer] bbox parts optimization
|
- [renderer] bbox parts optimization
|
||||||
- [General] smart pointers and std::array instead of raw pointers
|
- [General] smart pointers and std::array instead of raw pointers
|
||||||
- [md2] refactor
|
- [md2] refactor
|
||||||
|
- [2D] Add zbuffer support (z-index)
|
||||||
|
- [3DUtility] Add zbuffer support (z-index)
|
||||||
- [2D] Fixed font support
|
- [2D] Fixed font support
|
||||||
- [File] Async file loading
|
- [File] Async file loading
|
||||||
- [obj] Add multicolor support to obj
|
- [obj] Add multicolor support to obj
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ class Enemy {
|
|||||||
bool isFighting = false;
|
bool isFighting = false;
|
||||||
Vec4 spawnPoint;
|
Vec4 spawnPoint;
|
||||||
|
|
||||||
Renderer3DUtility* utility;
|
|
||||||
Audio* audio;
|
Audio* audio;
|
||||||
EnemyInfo info;
|
EnemyInfo info;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ class Player {
|
|||||||
private:
|
private:
|
||||||
void handlePlayerPosition(const Heightmap& heightmap,
|
void handlePlayerPosition(const Heightmap& heightmap,
|
||||||
const float& terrainHeight);
|
const float& terrainHeight);
|
||||||
Renderer3DUtility* utility;
|
|
||||||
|
|
||||||
float speed;
|
float speed;
|
||||||
Pad* pad;
|
Pad* pad;
|
||||||
|
|||||||
@@ -11,13 +11,13 @@
|
|||||||
#include "states/game/enemy/enemy.hpp"
|
#include "states/game/enemy/enemy.hpp"
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
using Tyra::Color;
|
||||||
using Tyra::Math;
|
using Tyra::Math;
|
||||||
|
|
||||||
namespace Demo {
|
namespace Demo {
|
||||||
|
|
||||||
Enemy::Enemy(Engine* engine, const EnemyInfo& t_info) {
|
Enemy::Enemy(Engine* engine, const EnemyInfo& t_info) {
|
||||||
info = t_info;
|
info = t_info;
|
||||||
utility = &engine->renderer.renderer3D.utility;
|
|
||||||
|
|
||||||
mesh = new DynamicMesh(*info.motherMesh);
|
mesh = new DynamicMesh(*info.motherMesh);
|
||||||
|
|
||||||
@@ -87,20 +87,23 @@ void Enemy::update(const Heightmap& heightmap, const Vec4& playerPosition,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Enemy::handlePlayerShoot(const PlayerShootAction& shootAction) {
|
void Enemy::handlePlayerShoot(const PlayerShootAction& shootAction) {
|
||||||
if (!shootAction.isShooting) {
|
// if (!shootAction.isShooting) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
const auto& ray = shootAction.ray.value();
|
const auto& ray = shootAction.ray.value();
|
||||||
|
|
||||||
auto bbox =
|
auto bbox =
|
||||||
mesh->getCurrentBoundingBox().getTransformed(mesh->getModelMatrix());
|
mesh->getCurrentBoundingBox().getTransformed(mesh->getModelMatrix());
|
||||||
|
|
||||||
auto isOnEnemy = ray.intersectBox(bbox.min(), bbox.max());
|
float length = -1.0F;
|
||||||
|
auto isOnEnemy = ray.intersectBox(bbox.min(), bbox.max(), &length);
|
||||||
|
|
||||||
if (isOnEnemy) {
|
if (isOnEnemy) {
|
||||||
mesh->setPosition(spawnPoint);
|
mesh->setPosition(spawnPoint);
|
||||||
TYRA_LOG("Enemy hit!");
|
TYRA_LOG("Enemy hit!");
|
||||||
|
} else {
|
||||||
|
if (length != -1.0F) TYRA_LOG("Distance: ", length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ EnemyManager::EnemyManager(Engine* engine, const Heightmap& heightmap) {
|
|||||||
auto* sample = engine->audio.adpcm.load(
|
auto* sample = engine->audio.adpcm.load(
|
||||||
FileUtils::fromCwd("game/models/zombie/punch.adpcm"));
|
FileUtils::fromCwd("game/models/zombie/punch.adpcm"));
|
||||||
|
|
||||||
const int enemyCount = 10;
|
const int enemyCount = 1;
|
||||||
for (int i = 0; i < enemyCount; i++) {
|
for (int i = 0; i < enemyCount; i++) {
|
||||||
EnemyInfo info;
|
EnemyInfo info;
|
||||||
info.adpcmChannel = 9 + i;
|
info.adpcmChannel = 9 + i;
|
||||||
|
|||||||
@@ -85,6 +85,14 @@ void GameState::update() {
|
|||||||
renderer.add(terrain->pair);
|
renderer.add(terrain->pair);
|
||||||
renderer.render();
|
renderer.render();
|
||||||
|
|
||||||
|
// Debug
|
||||||
|
auto& utility = engine->renderer.renderer3D.utility;
|
||||||
|
utility.drawBox(*player->getCameraInfo().looksAt, 0.3F);
|
||||||
|
|
||||||
|
auto* firstEnemy = enemyManager->getPairs().front()->mesh;
|
||||||
|
utility.drawBBox(firstEnemy->getCurrentBoundingBox().getTransformed(
|
||||||
|
firstEnemy->getModelMatrix()));
|
||||||
|
|
||||||
// End frame
|
// End frame
|
||||||
engine->renderer.endFrame();
|
engine->renderer.endFrame();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,6 @@ Player::Player(Engine* engine)
|
|||||||
position = Vec4(3.0F, 50.0F, 0.0F);
|
position = Vec4(3.0F, 50.0F, 0.0F);
|
||||||
camera.lookAt = Vec4(0.0F, 0.0F, -30.0F);
|
camera.lookAt = Vec4(0.0F, 0.0F, -30.0F);
|
||||||
speed = 5.0F;
|
speed = 5.0F;
|
||||||
|
|
||||||
utility = &engine->renderer.renderer3D.utility;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Player::~Player() { delete pair; }
|
Player::~Player() { delete pair; }
|
||||||
@@ -37,14 +35,9 @@ PlayerShootAction Player::getShootAction() const {
|
|||||||
PlayerShootAction action;
|
PlayerShootAction action;
|
||||||
action.isShooting = weapon.isShooting;
|
action.isShooting = weapon.isShooting;
|
||||||
|
|
||||||
if (action.isShooting) {
|
// if (action.isShooting) {
|
||||||
action.ray = Ray(camera.position, camera.lookAt.getNormalized());
|
action.ray = Ray(camera.position, camera.lookAt.getNormalized());
|
||||||
}
|
// }
|
||||||
|
|
||||||
utility->drawBox(camera.lookAt, 1.0F);
|
|
||||||
|
|
||||||
// utility->drawLine(ray.origin, ray.direction);
|
|
||||||
utility->drawLine(camera.position + Vec4(0.0F, 1.0F, 0.0F), camera.lookAt);
|
|
||||||
|
|
||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,10 +19,10 @@
|
|||||||
namespace Tyra {
|
namespace Tyra {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Debug functions, with bad performance.
|
* Debug functions, without z buffer, with bad performance.
|
||||||
*
|
*
|
||||||
* Remember that you need to use them AFTER ALLPASS rendering.
|
* Remember to use these functions AFTER all 3D rendering,
|
||||||
* (for example after skybox), otherwise colors will not work.
|
* otherwise lines will be overwritten!
|
||||||
*/
|
*/
|
||||||
class Renderer3DUtility {
|
class Renderer3DUtility {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -65,7 +65,6 @@ void Renderer3DUtility::drawLine(const Vec4& from, const Vec4& to,
|
|||||||
const u8 vertCount = 2;
|
const u8 vertCount = 2;
|
||||||
const s8 thickness = 2;
|
const s8 thickness = 2;
|
||||||
s16 packetSize = 8 * thickness;
|
s16 packetSize = 8 * thickness;
|
||||||
prim.type = PRIM_LINE;
|
|
||||||
auto gsColor = getGSColor(color);
|
auto gsColor = getGSColor(color);
|
||||||
|
|
||||||
auto* packet =
|
auto* packet =
|
||||||
@@ -114,7 +113,6 @@ void Renderer3DUtility::drawBBox(const CoreBBox& v, const Color& color) {
|
|||||||
const u8 vertCount = 4;
|
const u8 vertCount = 4;
|
||||||
const s8 thickness = 2;
|
const s8 thickness = 2;
|
||||||
s16 packetSize = 150 * thickness;
|
s16 packetSize = 150 * thickness;
|
||||||
prim.type = PRIM_LINE;
|
|
||||||
auto gsColor = getGSColor(color);
|
auto gsColor = getGSColor(color);
|
||||||
|
|
||||||
auto* packet =
|
auto* packet =
|
||||||
@@ -284,13 +282,19 @@ bool Renderer3DUtility::calcLineVertices(xyz_t* outputArray, const Vec4& a,
|
|||||||
s32 centerY = ftoi4(2048 + displayOffset);
|
s32 centerY = ftoi4(2048 + displayOffset);
|
||||||
const u32 maxZ = ftoi4(((float)0xFFFFFF) / 32.0F);
|
const u32 maxZ = ftoi4(((float)0xFFFFFF) / 32.0F);
|
||||||
|
|
||||||
outputArray[0].x = (clippedVerts[0].position.x + 1.0F) * centerX;
|
outputArray[0].x =
|
||||||
outputArray[0].y = (clippedVerts[0].position.y + 1.0F) * centerY;
|
static_cast<u16>((clippedVerts[0].position.x + 1.0F) * centerX);
|
||||||
outputArray[0].z = (clippedVerts[0].position.z + 1.0F) * maxZ;
|
outputArray[0].y =
|
||||||
|
static_cast<u16>((clippedVerts[0].position.y + 1.0F) * centerY);
|
||||||
|
outputArray[0].z =
|
||||||
|
static_cast<u32>((clippedVerts[0].position.z + 1.0F) * maxZ);
|
||||||
|
|
||||||
outputArray[1].x = (clippedVerts[1].position.x + 1.0F) * centerX;
|
outputArray[1].x =
|
||||||
outputArray[1].y = (clippedVerts[1].position.y + 1.0F) * centerY;
|
static_cast<u16>((clippedVerts[1].position.x + 1.0F) * centerX);
|
||||||
outputArray[1].z = (clippedVerts[1].position.z + 1.0F) * maxZ;
|
outputArray[1].y =
|
||||||
|
static_cast<u16>((clippedVerts[1].position.y + 1.0F) * centerY);
|
||||||
|
outputArray[1].z =
|
||||||
|
static_cast<u32>((clippedVerts[1].position.z + 1.0F) * maxZ);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user