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