Jump to content
  • Advertisement

howie_007

Member
  • Content Count

    325
  • Joined

  • Last visited

  1. howie_007

    Operator assignment question

    I changed the RegisterObjectType as you suggested and that worked! Awesome! Thank you for the help! The computer is an aging home built gaming rig repurposed as a development maching using an AMD Phenom chip running Arch Linux.
  2. howie_007

    Operator assignment question

    Unfortunately, adding "const" didn't solve the problem.
  3. howie_007

    Operator assignment question

    In doing some experimentation, I noticed doing the below didn't work. I'm sure I don't have the overloaded operators setup correctly for this. CPoint point1(5, 2, 7); CPoint point2(3, 4, 9); CPoint result; result = point1 * point2; Print( "point1: " + point1.x + ", " + point1.y + ", " + point1.z ); Print( "point2: " + point2.x + ", " + point2.y + ", " + point2.z ); Print( "Result: " + result.x + ", " + result.y + ", " + result.z ); ------------------------------------------------------- point1: 5, 2, 7 point2: 3, 4, 9 Result: 1.49854e-33, -1.03028e+37, 3.97328e-34
  4. howie_007

    Operator assignment question

    Here is the c++ angelscript wrapper function that receives the point. void IncPos1(CPoint<float> & pos, CSprite & sprite) { sprite.getObject()->incPos(pos); } Here's the CPoint class registration code /************************************************************************ * FILE NAME: scriptpoint.cpp * * DESCRIPTION: CPoint script object registration ************************************************************************/ // Physical component dependency #include <script/scriptpoint.h> // Game lib dependencies #include <common/point.h> #include <script/scriptmanager.h> #include <script/scriptglobals.h> // AngelScript lib dependencies #include <angelscript.h> namespace NScriptPoint { /************************************************************************ * DESC: Constructor ************************************************************************/ void Constructor(void * thisPointer) { new(thisPointer) CPoint<float>(); } /************************************************************************ * DESC: Copy Constructor ************************************************************************/ void CopyConstructor(const CPoint<float> & other, void * pThisPointer) { new(pThisPointer) CPoint<float>(other); } void ConstructorFromThreeFloats(float x, float y, float z, void * pThisPointer) { new(pThisPointer) CPoint<float>(x, y, z); } void ConstructorFromTwoFloats(float x, float y, void * pThisPointer) { new(pThisPointer) CPoint<float>(x, y); } /************************************************************************ * DESC: Destructor ************************************************************************/ void Destructor(void * pThisPointer) { ((CPoint<float>*)pThisPointer)->~CPoint(); } /************************************************************************ * DESC: Wrapper function due to type being a template ************************************************************************/ float GetLengthSquared2D1(CPoint<float> & point) { return point.getLengthSquared2D(); } float GetLengthSquared2D2(CPoint<float> & in, CPoint<float> & point) { return point.getLengthSquared2D( in ); } float GetLength2D1(CPoint<float> & point) { return point.getLength2D(); } float GetLength2D2(CPoint<float> & in, CPoint<float> & point) { return point.getLength2D( in ); } float GetLengthSquared1(CPoint<float> & point) { return point.getLengthSquared(); } float GetLengthSquared2(CPoint<float> & in, CPoint<float> & point) { return point.getLengthSquared( in ); } float GetLength1(CPoint<float> & point) { return point.getLength(); } float GetLength2(CPoint<float> & in, CPoint<float> & point) { return point.getLength( in ); } bool IsEquilEnough(CPoint<float> & in, float val, CPoint<float> & point) { return point.isEquilEnough( in, val ); } float GetDotProduct(CPoint<float> & in, CPoint<float> & point) { return point.getDotProduct( in ); } float GetDotProduct2D(CPoint<float> & in, CPoint<float> & point) { return point.getDotProduct2D( in ); } CPoint<float> GetCrossProduct(CPoint<float> & in, CPoint<float> & point) { return point.getCrossProduct( in ); } void Cap(float value, CPoint<float> & point) { point.cap(value); } /************************************************************************ * DESC: Register the class with AngelScript ************************************************************************/ void Register() { using namespace NScriptGlobals; // Used for Throw asIScriptEngine * pEngine = CScriptMgr::Instance().getEnginePtr(); // Register type Throw( pEngine->RegisterObjectType("CPoint", sizeof(CPoint<float>), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS | asOBJ_APP_CLASS_CONSTRUCTOR | asOBJ_APP_CLASS_COPY_CONSTRUCTOR | asOBJ_APP_CLASS_DESTRUCTOR ) ); // Register the object operator overloads Throw( pEngine->RegisterObjectBehaviour("CPoint", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(Constructor), asCALL_CDECL_OBJLAST) ); Throw( pEngine->RegisterObjectBehaviour("CPoint", asBEHAVE_CONSTRUCT, "void f(const CPoint & in)", asFUNCTION(CopyConstructor), asCALL_CDECL_OBJLAST) ); Throw( pEngine->RegisterObjectBehaviour("CPoint", asBEHAVE_CONSTRUCT, "void f(float, float, float)", asFUNCTION(ConstructorFromThreeFloats), asCALL_CDECL_OBJLAST) ); Throw( pEngine->RegisterObjectBehaviour("CPoint", asBEHAVE_CONSTRUCT, "void f(float, float)", asFUNCTION(ConstructorFromTwoFloats), asCALL_CDECL_OBJLAST) ); Throw( pEngine->RegisterObjectBehaviour("CPoint", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(Destructor), asCALL_CDECL_OBJLAST) ); // assignment operator Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint & opAssign(CPoint & in)", asMETHODPR(CPoint<float>, operator =, (const CPoint<float> &), CPoint<float> &), asCALL_THISCALL) ); // binary operators Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opAdd ( CPoint & in )", asMETHODPR(CPoint<float>, operator +, (const CPoint<float> &) const, CPoint<float>), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opSub ( CPoint & in )", asMETHODPR(CPoint<float>, operator -, (const CPoint<float> &) const, CPoint<float>), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opMul ( CPoint & in )", asMETHODPR(CPoint<float>, operator *, (const CPoint<float> &) const, CPoint<float>), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opDiv ( CPoint & in )", asMETHODPR(CPoint<float>, operator /, (const CPoint<float> &) const, CPoint<float>), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opAdd ( float )", asMETHODPR(CPoint<float>, operator +, (float) const, CPoint<float>), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opSub ( float )", asMETHODPR(CPoint<float>, operator -, (float) const, CPoint<float>), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opMul ( float )", asMETHODPR(CPoint<float>, operator *, (float) const, CPoint<float>), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opDiv ( float )", asMETHODPR(CPoint<float>, operator /, (float) const, CPoint<float>), asCALL_THISCALL) ); // compound assignment operators Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opAddAssign ( CPoint & in )", asMETHODPR(CPoint<float>, operator +=, (const CPoint<float> &), CPoint<float>), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opSubAssign ( CPoint & in )", asMETHODPR(CPoint<float>, operator -=, (const CPoint<float> &), CPoint<float>), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opMulAssign ( CPoint & in )", asMETHODPR(CPoint<float>, operator *=, (const CPoint<float> &), CPoint<float>), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opDivAssign ( CPoint & in )", asMETHODPR(CPoint<float>, operator /=, (const CPoint<float> &), CPoint<float>), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opAddAssign ( float )", asMETHODPR(CPoint<float>, operator +=, (float) , CPoint<float>), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opSubAssign ( float )", asMETHODPR(CPoint<float>, operator -=, (float) , CPoint<float>), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opMulAssign ( float )", asMETHODPR(CPoint<float>, operator *=, (float) , CPoint<float>), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opDivAssign ( float )", asMETHODPR(CPoint<float>, operator /=, (float) , CPoint<float>), asCALL_THISCALL) ); // Register property Throw( pEngine->RegisterObjectProperty("CPoint", "float x", asOFFSET(CPoint<float>, x)) ); Throw( pEngine->RegisterObjectProperty("CPoint", "float y", asOFFSET(CPoint<float>, y)) ); Throw( pEngine->RegisterObjectProperty("CPoint", "float z", asOFFSET(CPoint<float>, z)) ); // Class members Throw( pEngine->RegisterObjectMethod("CPoint", "void clearX()", asMETHOD(CPoint<float>, clearX), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "void clearY()", asMETHOD(CPoint<float>, clearY), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "void clearZ()", asMETHOD(CPoint<float>, clearZ), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "void clear()", asMETHOD(CPoint<float>, clear), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "bool isEmpty()", asMETHOD(CPoint<float>, isEmpty), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "bool isXEmpty()", asMETHOD(CPoint<float>, isXEmpty), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "bool isYEmpty()", asMETHOD(CPoint<float>, isYEmpty), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "bool isZEmpty()", asMETHOD(CPoint<float>, isZEmpty), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "void invert()", asMETHOD(CPoint<float>, invert), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "void invertX()", asMETHOD(CPoint<float>, invert), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "void invertY()", asMETHOD(CPoint<float>, invert), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "void invertZ()", asMETHOD(CPoint<float>, invert), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint getInvert() const", asMETHOD(CPoint<float>, getInvert), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "void normalize()", asMETHOD(CPoint<float>, normalize), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "void normalize2D()", asMETHOD(CPoint<float>, normalize2D), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "float getLengthSquared2D() const", asFUNCTION(GetLengthSquared2D1), asCALL_CDECL_OBJLAST) ); Throw( pEngine->RegisterObjectMethod("CPoint", "float getLengthSquared2D(CPoint & in) const", asFUNCTION(GetLengthSquared2D2), asCALL_CDECL_OBJLAST) ); Throw( pEngine->RegisterObjectMethod("CPoint", "float getLengthSquared() const", asFUNCTION(GetLengthSquared1), asCALL_CDECL_OBJLAST) ); Throw( pEngine->RegisterObjectMethod("CPoint", "float getLengthSquared(CPoint & in) const", asFUNCTION(GetLengthSquared2), asCALL_CDECL_OBJLAST) ); Throw( pEngine->RegisterObjectMethod("CPoint", "float getLength2D() const", asFUNCTION(GetLength2D1), asCALL_CDECL_OBJLAST) ); Throw( pEngine->RegisterObjectMethod("CPoint", "float getLength2D(CPoint & in) const", asFUNCTION(GetLength2D2), asCALL_CDECL_OBJLAST) ); Throw( pEngine->RegisterObjectMethod("CPoint", "float getLength() const", asFUNCTION(GetLength1), asCALL_CDECL_OBJLAST) ); Throw( pEngine->RegisterObjectMethod("CPoint", "float getLength(CPoint & in) const", asFUNCTION(GetLength2), asCALL_CDECL_OBJLAST) ); Throw( pEngine->RegisterObjectMethod("CPoint", "bool isEquilEnough(CPoint & in, float val)", asFUNCTION(IsEquilEnough), asCALL_CDECL_OBJLAST) ); Throw( pEngine->RegisterObjectMethod("CPoint", "float getDotProduct(CPoint & in) const", asFUNCTION(GetDotProduct), asCALL_CDECL_OBJLAST) ); Throw( pEngine->RegisterObjectMethod("CPoint", "float getDotProduct2D(CPoint & in) const", asFUNCTION(GetDotProduct2D), asCALL_CDECL_OBJLAST) ); Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint getCrossProduct(CPoint & in) const", asFUNCTION(GetCrossProduct), asCALL_CDECL_OBJLAST) ); Throw( pEngine->RegisterObjectMethod("CPoint", "void cap(float)", asFUNCTION(Cap), asCALL_CDECL_OBJLAST) ); } }
  5. howie_007

    Operator assignment question

    Should I be able to do this in the script code? The question is about the last line of the below code example. CPoint velocity; velocity.x = cos( rotation ) * PROJECTILE_SPEED; velocity.y = sin( rotation ) * PROJECTILE_SPEED; float time = HighResTimer.getElapsedTime(); sprite.incPos( velocity * time ); sprite.incPos receives a CPoint as a parameter. There's no compiler error and the code runs but the CPoint recieved by sprite.incPos is all zeros. Here's my assignment code. Perhaps I'm missing something. Thank you for all your hard work providing us this amazing scripting tool along with your other tools like the font creator. // binary operators Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opAdd ( CPoint & in )", asMETHODPR(CPoint<float>, operator +, (const CPoint<float> &) const, CPoint<float>), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opSub ( CPoint & in )", asMETHODPR(CPoint<float>, operator -, (const CPoint<float> &) const, CPoint<float>), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opMul ( CPoint & in )", asMETHODPR(CPoint<float>, operator *, (const CPoint<float> &) const, CPoint<float>), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opDiv ( CPoint & in )", asMETHODPR(CPoint<float>, operator /, (const CPoint<float> &) const, CPoint<float>), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opAdd ( float )", asMETHODPR(CPoint<float>, operator +, (float) const, CPoint<float>), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opSub ( float )", asMETHODPR(CPoint<float>, operator -, (float) const, CPoint<float>), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opMul ( float )", asMETHODPR(CPoint<float>, operator *, (float) const, CPoint<float>), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opDiv ( float )", asMETHODPR(CPoint<float>, operator /, (float) const, CPoint<float>), asCALL_THISCALL) ); // compound assignment operators Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opAddAssign ( CPoint & in )", asMETHODPR(CPoint<float>, operator +=, (const CPoint<float> &), CPoint<float>), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opSubAssign ( CPoint & in )", asMETHODPR(CPoint<float>, operator -=, (const CPoint<float> &), CPoint<float>), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opMulAssign ( CPoint & in )", asMETHODPR(CPoint<float>, operator *=, (const CPoint<float> &), CPoint<float>), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opDivAssign ( CPoint & in )", asMETHODPR(CPoint<float>, operator /=, (const CPoint<float> &), CPoint<float>), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opAddAssign ( float )", asMETHODPR(CPoint<float>, operator +=, (float) , CPoint<float>), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opSubAssign ( float )", asMETHODPR(CPoint<float>, operator -=, (float) , CPoint<float>), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opMulAssign ( float )", asMETHODPR(CPoint<float>, operator *=, (float) , CPoint<float>), asCALL_THISCALL) ); Throw( pEngine->RegisterObjectMethod("CPoint", "CPoint opDivAssign ( float )", asMETHODPR(CPoint<float>, operator /=, (float) , CPoint<float>), asCALL_THISCALL) );
  6. The search feature doesn't seem all that intuitive. I don't see a way to tell it I only want to search this one particular forum.
  7. howie_007

    AngelScript class destructor causes segfault

    Wow, that solved the problem, thanks!
  8. In my game engine which used Vulkan, I'm setting it up so that a game can be completely written in AngelScript. One of my functions that I bound in AngelScript is a call that tells Vulkan to wait for idle. Before you can free assets, you need to be sure they are not in the rendering pipeline so in the AngelScript destructor, I'm doing that before further cleanup. Calling these functions from the AngelScript class destructor causes a segment fault. I can call these same functions anywhere else in the AngelScript class but not from the destructor. Is the destructor doing something different? class CGame { ~CGame() { // Wait for all rendering to be finished Device.waitForIdle(); // Destroy the window and render device instance Device.destroy(); }
  9. Yeah, that's what I thought. I'll just comment out the assert since it's just a map holding an std::string and an int which is all self cleaning. Thanks for your help!
  10. That did not work. I have the script engine in a singleton so that as my script components come in and out of existence, they can draw from and return to the context pool in the singleton. My design assumes the context can be freed regardless of if the script engine has freed itself. When the game exits, the script components that are still around, they just free the contexts they are currently holding.
  11. angelscript/add_on/scriptstdstring/scriptstdstring.cpp:39: virtual CStdStringFactory::~CStdStringFactory(): Assertion `stringCache.size() == 0' failed. The above error happens when I quit out my application. I'm developing on Linux. I'm not sure why the stringCache still has strings in it. Shouldn't the destructor just clean-up the left over strings instead of asserting?
  12. howie_007

    Killing Room

    Looks cool!
  13. That helps because I didn't know what the tangent was for.   I've analyzed the code and simplified it. Below is the final modified version. Let's look at it line by line.   First useless line. const float pi = 4.0f*atanf(1.0f); All this does is give us the value of PI. math.h has a #define you can use so this is unnecessary. As you'll see in the finial code, many things were unnecessary.   Next line. const float aspect = (float)(m_renderbufferWidth) / (float)(m_renderbufferHeight); This give us the aspect ratio of the screen. Not sure why this is needed for the x coordinate and not the y. I think it's magic.   Next Two lines. const float fx = 2.0f * ((float)(x) / (float)(m_renderbufferWidth - 1)) - 1.0f; const float fy = 2.0f * ((float)(y) / (float)(m_renderbufferHeight - 1)) - 1.0f; This converts screen coordinates from a top/left orientation to a center screen coordinates but there's a little more to this then that. 1) Subtracting the width and height by one. The reason you do this is because resolution sizes are usually all even numbers. For example, a resolution of 1280x720 there is no center pixel or a pixel at 0. The other reason this could be is that you need a value of base 0, as if this was an array and w/h represents the total number of elements. 2) x/y divied by w/h. This gives you a normalize value of the point on your screen. In other words, a value from 0 to 1. 3) 2.0f *; not entirely sure what this is doing and why it is needed. 4) The last - 1.0f flips the sign.   Second useless line const float y_fov = pi/4; // pi/4 radians = 45 degrees This takes PI and divides it by 4 to give us 45 degrees in radians. This is unnecessary.   Modified line. const float tangent = tan(y_fov / 2.0f); This divides the 45 degrees by 2 to give use 22.5 degrees in radians. This can be simplified by plopping a number in tan.   I know what the rest is doing, I just don't understand why it works. /************************************************************************ * desc: Convert 2d screen coordinates to 3D perspective space ************************************************************************/ void Convert2Dto3D( float & destX, float & destY, float x, float y, float width, float height ) { const float aspect = width / height; // Convert upper left 0,0 to center screen 0,0 coordinates const float fx = (2.0f * (x / (width - 1))) - 1.0f; const float fy = (2.0f * (y / (height - 1))) - 1.0f; // (pi/4 radians = 45 degrees / 2) or ((pi/4) / 2)) const float tangent = tan( 0.392699082 ); // Project x,y to a z plane of 1 destX = aspect * tangent* fx; destY = -tangent * fy; } // Convert2Dto3D
  14. done! You have your up vote.   I wish I could look at this code and know what it's doing. If anyone can explain it, please do.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!