diff --git a/src/reactphysics.cpp b/src/reactphysics.cpp index 4fea79a7..95e24f51 100644 --- a/src/reactphysics.cpp +++ b/src/reactphysics.cpp @@ -26,7 +26,7 @@ template void rp_construct(void* mem, A... args) { new template void rp_copy_construct(void* mem, const T& obj) { new(mem) T(obj); } template void rp_destruct(T* obj) { obj->~T(); } -// Some functions require manual wrapping, especially anything dealing with arrays. +// Some functions require manual wrapping, especially anything dealing with arrays or force inline. CScriptArray* transform_get_opengl_matrix(const Transform& t) { CScriptArray* array = CScriptArray::Create(get_array_type("array"), 16); t.getOpenGLMatrix(reinterpret_cast(array->GetBuffer())); @@ -51,6 +51,8 @@ template void RegisterCollisionShape() { } void RegisterReactphysics(asIScriptEngine* engine) { + engine->RegisterGlobalFunction("int clamp(int value, int min, int max)", asFUNCTIONPR(clamp, (int, int, int), int), asCALL_CDECL); + engine->RegisterGlobalFunction("float clamp(float value, float min, float max)", asFUNCTIONPR(clamp, (decimal, decimal, decimal), decimal), asCALL_CDECL); engine->RegisterEnum("physics_shape_type"); engine->RegisterEnumValue("physics_shape_type", "SHAPE_TYPE_SPHERE", int(CollisionShapeType::SPHERE)); engine->RegisterEnumValue("physics_shape_type", "SHAPE_TYPE_CAPSULE", int(CollisionShapeType::CAPSULE)); diff --git a/src/sound.cpp b/src/sound.cpp index 3d0fbb9a..0f33bc99 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -1516,7 +1516,6 @@ BOOL mixer::add_mixer(mixer* m) { if (ret) { m->parent_mixer = this; mixers.insert(m); - AddRef(); } return ret; } @@ -1526,7 +1525,6 @@ BOOL mixer::remove_mixer(mixer* m, BOOL internal) { return FALSE; mixers.erase(i); BASS_Mixer_ChannelRemove(m->channel); - Release(); if (internal) return TRUE; m->parent_mixer = NULL; diff --git a/src/timestuff.cpp b/src/timestuff.cpp index 683bf122..d7db6fc0 100644 --- a/src/timestuff.cpp +++ b/src/timestuff.cpp @@ -270,22 +270,27 @@ asINT64 system_running_milliseconds() { uint64_t timer_default_accuracy = Timespan::MILLISECONDS; timer::timer() : value(microticks()), accuracy(timer_default_accuracy), paused(false), secure(speedhack_protection) {} timer::timer(bool secure) : value(microticks(secure)), accuracy(timer_default_accuracy), paused(false), secure(secure) {} -timer::timer(int64_t initial_value, bool secure) : value(microticks(secure) + initial_value * timer_default_accuracy), accuracy(timer_default_accuracy), paused(false), secure(secure) {} -timer::timer(int64_t initial_value, uint64_t initial_accuracy, bool secure) : value(microticks(secure) + initial_value * initial_accuracy), accuracy(initial_accuracy), paused(false), secure(secure) {} -int64_t timer::get_elapsed() const { return (paused ? value : microticks(secure) - value) / accuracy; } +timer::timer(int64_t initial_value, bool secure) : value(int64_t(microticks(secure)) - initial_value * timer_default_accuracy), accuracy(timer_default_accuracy), paused(false), secure(secure) {} +timer::timer(int64_t initial_value, uint64_t initial_accuracy, bool secure) : value(int64_t(microticks(secure)) - initial_value * initial_accuracy), accuracy(initial_accuracy), paused(false), secure(secure) {} +int64_t timer::get_elapsed() const { return int64_t(paused ? value : microticks(secure) - value) / int64_t(accuracy); } bool timer::has_elapsed(int64_t value) const { return get_elapsed() >= value; } void timer::force(int64_t new_value) { paused ? value = new_value * accuracy : value = microticks(secure) - new_value * accuracy; } void timer::adjust(int64_t new_value) { paused ? value += new_value * accuracy : value -= new_value * accuracy; } -void timer::restart() { value = microticks(secure); paused = false; } +void timer::restart() { value = int64_t(microticks(secure)); paused = false; } bool timer::get_secure() const { return secure; } bool timer::get_paused() const { return paused; } bool timer::get_running() const { return !paused; } bool timer::pause() { return paused ? false : set_paused(true); } bool timer::resume() { return !paused ? false : set_paused(false); } void timer::toggle_pause() { value = microticks(secure) - value; paused = !paused; } +bool timer::tick(int64_t value) { + if (!has_elapsed(value)) return false; + restart(); + return true; +} bool timer::set_paused(bool new_paused) { if (paused == new_paused) return false; - value = microticks(secure) - value; + value = int64_t(microticks(secure)) - value; paused = new_paused; return true; } @@ -370,6 +375,7 @@ void RegisterScriptTimestuff(asIScriptEngine* engine) { engine->RegisterObjectMethod(_O("timer"), _O("int64 get_elapsed() const property"), asMETHOD(timer, get_elapsed), asCALL_THISCALL); engine->RegisterObjectMethod(_O("timer"), _O("void set_elapsed(int64 time_units) property"), asMETHOD(timer, force), asCALL_THISCALL); engine->RegisterObjectMethod(_O("timer"), _O("bool has_elapsed(int64 time_units) const"), asMETHOD(timer, has_elapsed), asCALL_THISCALL); + engine->RegisterObjectMethod(_O("timer"), _O("bool tick(int64 time_units)"), asMETHOD(timer, tick), asCALL_THISCALL); engine->RegisterObjectMethod(_O("timer"), _O("void force(int64 elapsed)"), asMETHOD(timer, force), asCALL_THISCALL); engine->RegisterObjectMethod(_O("timer"), _O("void adjust(int64 mod_elapsed)"), asMETHOD(timer, adjust), asCALL_THISCALL); engine->RegisterObjectMethod(_O("timer"), _O("void restart()"), asMETHOD(timer, restart), asCALL_THISCALL); diff --git a/src/timestuff.h b/src/timestuff.h index cc4fe62c..1769aff1 100644 --- a/src/timestuff.h +++ b/src/timestuff.h @@ -84,6 +84,7 @@ class timer : public Poco::RefCountedObject { timer(int64_t initial_value, uint64_t initial_accuracy, bool secure); int64_t get_elapsed() const; bool has_elapsed(int64_t value) const; + bool tick(int64_t value); void force(int64_t value); void adjust(int64_t value); void restart(); diff --git a/test/quick/timer.nvgt b/test/quick/timer.nvgt index dea47531..05711121 100644 --- a/test/quick/timer.nvgt +++ b/test/quick/timer.nvgt @@ -4,7 +4,7 @@ void main() { timer t_millis, t_dec; - timer t_secs(0, SECONDS); + timer t_secs(-5, SECONDS); timer t_micros(0, 1); show_window("test"); t_dec.accuracy = SECONDS / 10;