using distance to ray argument for optimization

This commit is contained in:
devZoGok
2024-07-21 15:00:49 +03:00
parent 027dfc2071
commit fdaa2bf2bd
4 changed files with 27 additions and 8 deletions
+9 -3
View File
@@ -403,7 +403,7 @@ namespace battleship{
Vector3 endPos = screenToSpace(getCursorPos());
Vector3 rayDir = (endPos - camPos).norm();
vector<RayCaster::CollisionResult> results = RayCaster::cast(camPos, rayDir, Map::getSingleton()->getNodeParent());
vector<RayCaster::CollisionResult> results = RayCaster::cast(camPos, rayDir, Map::getSingleton()->getNodeParent(), 0, configData::DIST_FROM_RAY);
if(!results.empty()){
GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton();
@@ -414,7 +414,7 @@ namespace battleship{
Node *nodeParent = map->getNodeParent();
if(u->getType() == UnitType::UNDERWATER && nodeParent->getNumChildren() > 0){
vector<RayCaster::CollisionResult> res = RayCaster::cast(Vector3(pos.x, 100, pos.z), Vector3(0, -1, 0), nodeParent->getChild(0));
vector<RayCaster::CollisionResult> res = RayCaster::cast(Vector3(pos.x, 100, pos.z), Vector3(0, -1, 0), nodeParent->getChild(0), 0, configData::DIST_FROM_RAY);
Vector3 waterBodyPos = Vector3::VEC_ZERO;
Vector3 cellSize = map->getCellSize();
@@ -626,7 +626,13 @@ namespace battleship{
depth += 0.05;
Vector3 startPos = Root::getSingleton()->getCamera()->getPosition();
vector<RayCaster::CollisionResult> results = RayCaster::cast(startPos, (screenToSpace(getCursorPos()) - startPos).norm(), Map::getSingleton()->getNodeParent()->getChild(0));
vector<RayCaster::CollisionResult> results = RayCaster::cast(
startPos,
(screenToSpace(getCursorPos()) - startPos).norm(),
Map::getSingleton()->getNodeParent()->getChild(0),
0,
configData::DIST_FROM_RAY
);
if(!results.empty())
ufCtr->setPaintSelectRowStart(results[0].pos);
+2 -2
View File
@@ -20,8 +20,8 @@ namespace battleship{
using namespace gameBase;
const std::string DEFAULT_TEXTURE = "Textures/defaultTexture.jpg";
const double camPanSpeed = .5, CAMERA_DISTANCE = 100, CAMERA_ZOOM_INCREMENT = 1, NUM_MAX_ZOOMS = 75, cellLength = 14, cellWidth = 14, cellDepth = 7;
const int maxNumGroups = 10;
const double camPanSpeed = .5, CAMERA_DISTANCE = 100, CAMERA_ZOOM_INCREMENT = 1, cellLength = 14, cellWidth = 14, cellDepth = 7, DIST_FROM_RAY = 20;
const int maxNumGroups = 10, NUM_MAX_ZOOMS = 75;
const vb01::u32 IMPASS_NODE_VAL = 65535;
const static int numAppStates = 4;
+8 -1
View File
@@ -2,6 +2,7 @@
#include "gameObjectFrameController.h"
#include "resourceDeposit.h"
#include "defConfigs.h"
#include "player.h"
#include "game.h"
#include "unit.h"
@@ -118,7 +119,13 @@ namespace battleship{
frame.update();
Vector3 startPos = Root::getSingleton()->getCamera()->getPosition();
vector<RayCaster::CollisionResult> results = RayCaster::cast(startPos, (screenToSpace(getCursorPos()) - startPos).norm(), Map::getSingleton()->getNodeParent()->getChild(0));
vector<RayCaster::CollisionResult> results = RayCaster::cast(
startPos,
(screenToSpace(getCursorPos()) - startPos).norm(),
Map::getSingleton()->getNodeParent()->getChild(0),
0,
configData::DIST_FROM_RAY
);
if(results.empty()) return;
+8 -2
View File
@@ -317,7 +317,7 @@ namespace battleship{
for(int i = 0; i < numVertCells; i++)
for(int j = 0; j < numHorCells; j++){
Vector3 rayPos = startPos + Vector3(cellSize.x * j, 100, cellSize.z * i);
vector<RayCaster::CollisionResult> res = RayCaster::cast(rayPos, -Vector3::VEC_J, terrainNode->getChild(0), 0, 4);
vector<RayCaster::CollisionResult> res = RayCaster::cast(rayPos, -Vector3::VEC_J, terrainNode->getChild(0), 0, configData::DIST_FROM_RAY);
if(res.empty()){
RayCaster::CollisionResult r;
@@ -627,7 +627,13 @@ namespace battleship{
Vector2 cursorPos = getCursorPos();
Vector3 endPos = screenToSpace(cursorPos);
vector<RayCaster::CollisionResult> results = RayCaster::cast(startPos, (endPos - startPos).norm(), Root::getSingleton()->getRootNode());
vector<RayCaster::CollisionResult> results = RayCaster::cast(
startPos,
(endPos - startPos).norm(),
Root::getSingleton()->getRootNode(),
0,
configData::DIST_FROM_RAY
);
if(cursorPos.y < GameManager::getSingleton()->getHeight() - mapEditor->getGuiThreshold()){
bool push = !results.empty();