Jump to content
  • Advertisement

kaveldun

Member
  • Content Count

    12
  • Joined

  • Last visited

Community Reputation

142 Neutral

About kaveldun

  • Rank
    Member
  1. kaveldun

    Unit testing in Angelscript

    Alright.   I will implement some form of unit testing framework since I need it for my game. When it shapes up, I'll show it and ask for feedback etc, and hopefully it would turn into something useful for others too. :)
  2. kaveldun

    Unit testing in Angelscript

    Hello!   I've been searching around but I haven't found any information on this. Are there any useful unit testing frameworks which enables me to run automatic tests on Angelscript code?    
  3. kaveldun

    Getting rid of Angelscript prints

    Ah, alright. Take your time. :)
  4. kaveldun

    Getting rid of Angelscript prints

    Hello!   I want to do my own error handling for when Angelscript functions fail. In most cases this is really easy by just checking the return value. However it seems like there is one case where I am getting an error print from Angelscript when I would rather want to take care of it myself. Here is the code in question:   asIObjectType* ScriptModule::getObjectTypeByDecl(const std::string& decl) {     std::cout << "Type declaration: " << decl << "\n";     auto id = mAsModule->GetTypeIdByDecl(decl.c_str());     std::cout << "Id: " << id << "\n";     if(id < 0)     {            std::cout << "Returning null!\n";         return nullptr;     }        auto thing = mEngine.getEngine()->GetObjectTypeById(id);     std::cout << "Thing is: " << thing << "\n";     return thing; } If I provide this function with a type that does not exist, "Elphant" instead of "Elephant" for instance, I get the following output:   Type declaration: Elphant  (1, 1) : error : Identifier 'Elphant' is not a data type Id: -12 Returning null! So it seems like everything works as expected, except that the function not only returns -12 as the error, but also gives this debug print which is unwanted. Is there a particular reason for this? Am I doing it the wrong way? If not, can I get rid of the print somehow?  
  5. kaveldun

    Registering glm::vec3, compilation error

    Aah, of course!   I totally overlooked that they are not functions indeed. Thanks a lot :)
  6. Hello!   I am trying to register a vector class from the glm maths library. I am using the following line when I register the method which returns the x component of the vector: r = engine->RegisterObjectMethod("Vec3", "float x()", asMETHOD(glm::vec3, x), asCALL_THISCALL); assert(r >= 0); This however gives me a compilation error saying: error: C-style cast from 'value_type glm::detail::tvec3<float>::*' to 'void (vec3::*)()' is not allowed r = engine->RegisterObjectMethod("Vec3", "float x()", asMETHOD(glm::vec3, x), asCALL_THISCALL); assert(r >= 0); ^~~~~~~~~~~~~~~~~~~~~~ expanded from macro 'asMETHOD' #define asMETHOD(c,m) asSMethodPtr<sizeof(void (c::*)())>::Convert((void (c::*)())(&c::m)) I am aware that this might be due to glm and not angelscript but I am just wondering if someone has any idea on how this could be solved.   Thanks!  
  7. kaveldun

    Registering script entities

    Alright, that got it covered, thank you!   I now have my entity system working the way I wanted to. :) Thanks for the library and for your kind help.
  8. kaveldun

    Registering script entities

    Well, I don't want the script to be forced to implement the setPosition function. I want the setPosition function correspond to a function on the application side, and it should be available on every entity type inheriting from Entity. So if I have:   Entity : Cow {} Entity : Whale {}   By Cow and Whale inheriting from Entity, I can now call .setPosition on them which will be handled in the application. But perhaps it is in't possible with an interface.   Because as you said, I can register my application side entity class as Entity, and have it have a setPosition function, but then since you can't inherit from an application side registered class, I need to solve it in some other way. Perhaps I do need to use the method of making an EntityCore class which is registered and then have it in Entity after all?   Thanks again.
  9. kaveldun

    Registering script entities

    Hmmmm, I have an additional question.   I have now registered the Entity interface and entities can inherit from it. I also added two global functions for removing and creating entities and this all works on both application side and the script side. What I also need however is calling member functions that are common for all Entity classes. Like, if i have:   class Cow : Entity {}   class Dino : Entity {}   Then I need to be able to do:   Entity@ dino = createEntity("Dino"); Entity@ cow = createEntity("Cow");   dino.setPosition(0.0f, 1.0f, 10.0f); cow.setPosition(0.0f, 2.0f, 12.0f);   Without explicitly define these. And I need to handle the position setting on the application side, would work if I on the application could receive an asIScriptObject* to the caller, into a global function. Is it possible to register a member function for an interface which triggers a general function in the application, giving an object handle to it? Or am I thinking about this in the wrong way?   Thanks again. :)
  10. kaveldun

    Registering script entities

    Thanks so much for the quick reply!   Your clarifications made it make sense at last. :) I have now gotten the basics for it up and running. Ended up using an interface Entity as you suggested!   Perhaps the thingy about the "f()" function in the documentation could be clarified? Unless it is there and I just missed it of course. For me it was quite confusing indeed.
  11. kaveldun

    Registering script entities

    Hello!   I am new to Angelscript and I would like some clarifications.   What I am trying to do. I am making a game where all the specific entity logic should be implemented script side using Angelscript. On the application side, there will only be a general entity type, but on the script side there will be different types of entities with each having specific behaviours. For instance, you could create these two files:   //cow.as class Cow : Entity {     onFrame()     {           //cow log     } }   //duck.as class Duck : Entity {     onFrame()     {          //duck logic     } }   All the application would do is to call onFrame on a general entity type, which would call corresponding onFrame function.  It should also be possible to create entities from the script, like so: Entity newCow = createEntity("Cow");   Me trying to solve this:   The application will be responsible for creating and entities since it has to do a lot with them application side too, like physics and such. So I figured I need to register a factory function which returns an Entity@ as explained in the manual and various demos. A lot of these resources seem to refer to a "f()" function which I don't understand. I thought it was just an example function, but looking around in the forum and at samples, it seems like the f() function is actually something which shows up now and then. This line is from the game sample: r = engine->RegisterObjectBehaviour("CGameObj", asBEHAVE_ADDREF, "void f()", asMETHOD(CGameObj, AddRef), asCALL_THISCALL); assert( r >= 0 ); and it has that "f()" function that I jut can't figure out and I haven't seen an explanation in the manual. Do you guys mind demystifying this function for me?   Furthermore, I'm not entirely sure on how the application <-> script communications work. If I have a factory function Entity@ createEntity("cow") which is registered as a factory function handled by the application side, then as far as I've understood, I need to have the Entity type known by both the script and the application, is that correct? And in that case, if I register an Entity type from the application, I cannot inherit that type in angelscript, since it doesn't support inheritance of registered classes afaik. In that sense my idea was to have on the application side, an EntityCore type which I register to the script, and then on the script end, I have a class Entity which internally is composed of an EntityCore and is then derived from. Is that a reasonable way to achieve what I want?   I also tried to implement this but there are many details I get stuck on, like since I am registering a reference type, I need to register reference counting functions. So I read about this in the manual, and look at other examples, and they show them as the example line I posted up there with the "f()" function. Does this mean that I don't need to implement any reference counting functions script side? Or what does it mean really?   I am sorry if my questions are rather lengthy and non straight forward to answer, but I feel like I'm entangled into confusion myself and even reading the manual doesn't straighten everything out so yeah. Any help or suggestions or examples to clear this up would be appreciated. :)   Thanks. (:
  12. kaveldun

    Class instanes breaking outside scope

    Hmmm weird with the post formatting. :S Anyway, it worked when I removed that cast, thanks! Not sure what I was thinking, I guess it might be a rest from a copy-paste or something. One of those mistakes that you end up overlooking all the time, checking everything else. Anyways, thanks again, nice to finally have it working.
  13. Hey. Angelscript seems like a great library so far, but despite the documentation, there are some details on how to use classes with angelscript that I haven't managed to figure out. I have managed to create instances, return them to the c++ side, and then call some member functions upon them. However, as soon as they go out of scope, I cannot use them, and I get a crash at any Execute() call involving them, or even if I do ->Release() on them. Some of my code to illustrate: [source lang="cpp"]asIScriptObject* WndScript::ScriptKeeper::instantiateEntityClass(std::string type, unsigned int id) { asIScriptModule* mod = engine->GetModule("EntityScripts"); asIObjectType* objectType = engine->GetObjectTypeById(mod->GetTypeIdByDecl(type.c_str())); std::stringstream factoryFunction; factoryFunction << type << " @" << type << "()"; asIScriptFunction* factory = objectType->GetFactoryByDecl(factoryFunction.str().c_str()); //instantiate entityContext->Prepare(factory); entityContext->Execute(); asIScriptObject* returnObj = *(asIScriptObject**) entityContext->GetAddressOfReturnValue(); returnObj->AddRef(); //set id asIScriptFunction* method = objectType->GetMethodByDecl("void setId(uint id)"); entityContext->Prepare(method); entityContext->SetObject(returnObj); entityContext->SetArgDWord(0, id); entityContext->Execute(); //set type method = objectType->GetMethodByDecl("void setType(string type)"); entityContext->Prepare(method); entityContext->SetObject(returnObj); entityContext->SetArgObject(0, &type); entityContext->Execute(); method = objectType->GetMethodByDecl("void onCollide()"); if( method == 0 ) { // The function couldn't be found. Instruct the script writer // to include the expected function in the script. printf("The script must have the function '%s'. Please add it and try again.\n", "void onCollide()"); return NULL; } entityContext->Prepare(method); entityContext->SetObject(returnObj); entityContext->Execute(); return returnObj; }[/source] Here is my function that instantiates a script class, and all functions I call upon them in this function works. But when I use that function like so...: [source lang="cpp"]asIScriptObject* scriptEntity = *(asIScriptObject**) WndScript::ScriptKeeper::getInstance()->instantiateEntityClass(entity->getType(), entity->getUniqueId());[/source] ...then I cannot use "scriptEntity" to call any methods or do anything with it without getting a crash with "access violation". As if it dies whenever going outside the scope of the function that created it. Am I missing something? Thanks.
  • 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!