Jump to content

  • Log In with Google      Sign In   
  • Create Account

hayden355

Member Since 12 Dec 2008
Offline Last Active Dec 12 2014 03:35 AM

Topics I've Started

Angelscript: Circular references between scripts and app-declared types/functions.

03 December 2014 - 06:29 AM

I have been playing around with Angelscript and I have come across a problem that I am not quite sure how to overcome.
 
I have a base class, ScriptComponent, declared in AS, from which I derive other AS classes (which represent a component for a game object system). These script component objects are created on the application side, and I want to be able to refer to them in other scripts via a function GetScriptComponent(), which returns a ScriptComponent@ (In the script I cast to the appropriate component type).
 
I have declared a global function which returns a asIScriptObject* in C++ (a pointer to an instance of a ScriptComponent derived type), and a ScriptComponent@ in AS. (I am not sure if this works yet).
 

// C++

RegisterGlobalFunction("ScriptComponent@ GetScriptComponent(uint, const string &in, int index = 0)", asMETHOD(EntityManager, GetEntityScriptComponent), asCALL_THISCALL_ASGLOBAL, this);

 
The problem is that at the point of declaring GetScriptComponent() on the application side, ScriptComponent needs to have been previously declared. I am loading all of the scripts via the CScriptBuilder add-on. If I load the scripts first, before the application-side declarations, I have undefined references to those types and functions. If I load the scripts after the declarations, specifically GetScriptComponent, I have an undefined reference to ScriptComponent (as it is declared in a script).
 
Can I do some sort of forward declaration of ScriptComponent, or is there some simpler way I am not seeing. I thought about declaring ScriptComponent on the application side, but I don't think I would be able to derive script classes from it, is that true? Is there some functionality in CScriptBuilder I can use? Or perhaps I need to look at using multiple modules? I'm not quite sure how to proceed, I'll keep looking, but if anyone can point me in the right direction, that would be handy. Thank you.
 
Here is an example of how I am using the scripts:

// Angelscript

class ScriptCompoent
{
}

class Health : ScriptComponent
{
    ...
}

class Wander : ScriptComponent
{
    bool OnLoad(uint uiEntity)
    {
        @kTransform = cast<Transform>(GetComponent(uiEntity, "Transform"));
        @kHealth = cast<Health>(GetScriptComponent(uiEntity, "Health"));
 
        return true;
    }
 
    void OnUpdate(float fDT)
    {
        // Move towards random location
        // If bleeding, loose a bit of health (probably a bad example, you would do this in Health itself).
    }
 
    Transform@ kTransform;
    Health@ kHealth;
}

Getting order of attributes, as specified in shader file.

21 November 2013 - 08:59 PM

Hi,

 

I am writing an OpenGL shader loader. Currently, once I have linked the shader program, I am looping through each active attribute using glGetObjectParameterivARB(m_uiShaderID, GL_OBJECT_ACTIVE_ATTRIBUTES_ARB, &iCount), and calling glGetActiveAttrib() using the loop index, and then glBindAttribLocation() with the index and the name returned from glGetObjectParameter.

 

This approach is not giving me the attributes in the order in which I have specified them in the shader program, for example I have:

 

in vec4 vPosition;

in vec3 vNormal;

 

and my loop output gives:

 

0 vNormal

1 vPosition;

 

Is there a way I can get the attributes in the correct order, using OpenGL functionality?


PARTNERS