Skip to content

Commit

Permalink
Improve vector.
Browse files Browse the repository at this point in the history
  • Loading branch information
m1maker committed Dec 7, 2024
1 parent f511add commit c767730
Show file tree
Hide file tree
Showing 10 changed files with 469 additions and 80 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ set(NGT_SOURCES
"SRC/scripthelper/scripthelper.cpp"
"SRC/scriptmath/scriptmath.cpp"
"SRC/scriptmath/scriptmathcomplex.cpp"
"SRC/scriptmath/scriptmath3d.cpp"
"SRC/scriptstdstring/scriptstdstring.cpp"
"SRC/scriptstdstring/scriptstdstring_utils.cpp"
"SRC/scriptstdstring/scriptstdwstring.cpp"
Expand Down
2 changes: 1 addition & 1 deletion Release/Include/effect.as
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class effect
if (!is_safe(attached_handles[i]))
continue;

vector @pos = attached_handles[i].get_listener_position();
vector pos = attached_handles[i].get_listener_position();

// Check ranges without using in_range function
bool in_x_range = (pos.x >= -left_range && pos.x <= right_range);
Expand Down
4 changes: 2 additions & 2 deletions Release/Include/hip.as
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ namespace hip
return true;
return false;
}
bool in_range(double x, double y, double z, vector @min, vector @max)
bool in_range(double x, double y, double z, vector min, vector max)
{
try
{
Expand All @@ -477,7 +477,7 @@ namespace hip
return false;
}
}
bool in_range(vector @current, vector @min, vector @max)
bool in_range(vector current, vector min, vector max)
{
try
{
Expand Down
19 changes: 8 additions & 11 deletions Release/Include/sound_pool.as
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ class sound_pool_item

void update_listener_position(float listener_x, float listener_y, float listener_z, float rotation) {
if (position_locked)return;
vector @pos = sound_instance.get_source_position();
if (pos is null)
return;
vector pos = sound_instance.get_source_position();
// Calculate boundaries
float delta_left = pos.x - left_range;
float delta_right = pos.x + right_range;
Expand Down Expand Up @@ -80,14 +78,12 @@ class sound_pool_item

void update_position(float x, float y, float z){
if (position_locked)return;
vector @pos = sound_instance.get_listener_position();
if (pos is null)
return;
vector pos = sound_instance.get_listener_position();
sound_instance.set_position(pos.x, pos.y, pos.z, x, y, z, rotation);
}
float get_total_distance(float listener_x, float listener_y, float listener_z) {
if (position_locked)return 0.0f;
vector @source_pos = sound_instance.get_source_position();
vector source_pos = sound_instance.get_source_position();

float delta_left = source_pos.x - left_range;
float delta_right = source_pos.x + right_range;
Expand Down Expand Up @@ -302,8 +298,8 @@ class sound_pool
}

int play_3d(const string& in filename,
vector @listener,
vector @source,
vector listener,
vector source,
float rotation,
bool looping,
bool memory = false,
Expand All @@ -314,8 +310,8 @@ class sound_pool

int play_3d(
const string&in filename,
vector @listener,
vector @source,
vector listener,
vector source,

float rotation = 0,
float left_range = 0,
Expand Down Expand Up @@ -407,6 +403,7 @@ class sound_pool
@handle = pool[i].sound_instance;
return i; // Return index
}

void update_listener_position(float listener_x, float listener_y, float listener_z, float rotation = 0) {
for (int i = 0; i < max_sounds; ++i)
{
Expand Down
17 changes: 0 additions & 17 deletions SRC/ngt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2116,24 +2116,7 @@ uint64_t get_time_stamp_seconds() {
auto seconds = chrono::duration_cast<chrono::seconds>(duration).count();
return seconds;
}
float ngtvector::get_length()const {
return sqrt(x * x + y * y + z * z);
}
ngtvector& ngtvector::operator=(const ngtvector new_vector) {
this->x = new_vector.x;
this->y = new_vector.y;
this->z = new_vector.z;

return *this;
}
void ngtvector::reset() {
x = 0;
y = 0;
z = 0;
}
ngtvector::ngtvector() {
this->reset();
}
int sqlite3statement::step() { return sqlite3_step(stmt); }
int sqlite3statement::reset() { return sqlite3_reset(stmt); }
string sqlite3statement::get_expanded_sql_statement() const { return sqlite3_expanded_sql(stmt); }
Expand Down
8 changes: 0 additions & 8 deletions SRC/ngt.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,6 @@ using Poco::Net::StringPartSource;
#include "scriptdictionary/scriptdictionary.h"
using namespace std;
extern bool g_engineInitialized;
class ngtvector : public as_class {
public:
float x, y, z;
float get_length()const;
ngtvector& operator=(const ngtvector);
void reset();
ngtvector();
};

#ifdef _WIN32
wstring wstr(const string& utf8String);
Expand Down
13 changes: 2 additions & 11 deletions SRC/ngtreg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "print_func/print_func.h"
#include "scriptbuilder/scriptbuilder.h"
#include "Scripting.h"
#include "scriptmath/scriptmath3d.h"
#include "scriptstdstring/scriptstdstring.h"
#include <cstdlib>
#include <fstream>
Expand Down Expand Up @@ -246,7 +247,6 @@ void fscript_thread(asIScriptGeneric* gen) {

TTSVoice* ftts_voice() { return new TTSVoice(); }
network_event* fnetwork_event() { return new network_event; }
ngtvector* fngtvector() { return new ngtvector; }
sqlite3statement* fsqlite3statement() { return new sqlite3statement; }
ngtsqlite3* fngtsqlite3() { return new ngtsqlite3; }
network* fnetwork() { return new network; }
Expand Down Expand Up @@ -312,17 +312,8 @@ void RegisterFunctions(asIScriptEngine* engine)
engine->RegisterTypedef("ushort", "uint16");
engine->RegisterTypedef("size_t", "uint64");
engine->RegisterFuncdef("int exit_callback()");
engine->RegisterObjectType("vector", sizeof(ngtvector), asOBJ_REF);
engine->RegisterObjectBehaviour("vector", asBEHAVE_FACTORY, "vector@ v()", asFUNCTION(fngtvector), asCALL_CDECL);
engine->RegisterObjectBehaviour("vector", asBEHAVE_ADDREF, "void f()", asMETHOD(ngtvector, add_ref), asCALL_THISCALL);
engine->RegisterObjectBehaviour("vector", asBEHAVE_RELEASE, "void f()", asMETHOD(ngtvector, release), asCALL_THISCALL);
engine->RegisterObjectProperty(_O("vector"), "float x", asOFFSET(ngtvector, x));
engine->RegisterObjectProperty(_O("vector"), "float y", asOFFSET(ngtvector, y));
engine->RegisterObjectProperty(_O("vector"), "float z", asOFFSET(ngtvector, z));
engine->RegisterObjectMethod(_O("vector"), "float get_length()const property", asMETHOD(ngtvector, get_length), asCALL_THISCALL);
engine->RegisterObjectMethod(_O("vector"), "vector &opAssign(const vector&in)", asMETHOD(ngtvector, operator=), asCALL_THISCALL);
engine->RegisterObjectMethod(_O("vector"), "void reset()const", asMETHOD(ngtvector, reset), asCALL_THISCALL);
Print::asRegister(engine, true);
RegisterScriptMath3D(engine);
AS_BEGIN(engine, "os");
engine->RegisterGlobalFunction("int get_cpu_count()property", asFUNCTION(get_cpu_count), asCALL_CDECL);
engine->RegisterGlobalFunction("int get_system_ram()property", asFUNCTION(get_system_ram), asCALL_CDECL);
Expand Down
Loading

0 comments on commit c767730

Please sign in to comment.