Jump to content
  • Advertisement

Sami Vuorela

Member
  • Content Count

    31
  • Joined

  • Last visited

Community Reputation

955 Good

About Sami Vuorela

  • Rank
    Member
  1. Sami Vuorela

    Template containers angelscript addon library release!

    The iterator problem is caused by AATC's iterators being quite nonstandard indeed. The manual page for iterators and the first page of this topic explain the iteration syntax. Maybe I should implement a more standard iteration syntax for easier c++ -> AS conversion and keep the current syntax available under a different operator or function name. The iterator syntax was originally created to reduce AS function calls and to improve performance.   The string problem is probably caused by AATC expecting strings to be AS value types and your AS reftype string causing terrible confusions. I did some testing with removing AATC's specialized string handling entirely, and treating strings as plain old objects or ref objects. Seemed to work pretty good with scriptstdstring, maybe it could help your reftype String as well.   If you want to try that route, make these changes to your AATC installation (and remove any other changes to strings):   In aatc_common.cpp, line 326 DATAHANDLINGTYPE Determine_Datahandlingtype(...){   ... return DATAHANDLINGTYPE::STRING ... } delete the part about "return DATAHANDLINGTYPE::STRING".   In aatc_container_shared.hpp, line 357 template<...> void autoregister::register_all_tempspec_basics_for_container(...){   ...   tempspec_container_template<config::t::string>::Register(rs, "string"); } delete the line regarding registering "string".   With these changes AATC will properly treat your reftype String as a reftype and you won't have to go changing "string" to "String" deep in the bowels of AATC after every update. AATC will also no longer be able to use it's native hash function for strings automatically, because AATC is treating String as an AS type. You will have to register a hash function manually for your String class, if you need to use it with the hashing containers.   If this thing works out for you, I'll make it an option in aatc_config.hpp.
  2. Sami Vuorela

    Template containers angelscript addon library release!

    AATC does allow using proper funcdefs where possible, for example when sorting a tempspec'd vector or list. See vector's script interface manual page.   Quote from aatc_funcpointer's manual page:  
  3. Sami Vuorela

    Template containers angelscript addon library release!

    Hey.   Apparently msvc2013 is very scared of templated template parameters declared with the syntax  template<template<int> typename functor_operate> , but fine with  template<template<int> class functor_operate>   I made a patch for you which seems to compile fine with msvc2013 and msvc2015, its in a separate branch for now at patch-2016-09-msvc2013. Will merge to master once I get my linux builder VM running and can confirm that GCC won't cry about it either.
  4. Good news everyone!   AATC has been rewritten using cleaner c++ and 1400% more namespaces in order to provide better linux compatibility, a better c++ <-> angelscript interface and to reduce insanity. The documentation has also been improved quite a bit. The github-pages documentation now has a changelog and contains old documentation for old versions.   Changelog 2.30.2 -> 2.31.0 Supports Angelscript 2.31.0 New container: deque Proper cpp <-> script interoperability Sort tempspec'd containers using native AS functions (including lambdas and delegates) Compiles on linux (only tested with GCC) Cleaner C++ code, more namespaces etc   The documentation pages for hashing and tempspecs have been improved. A new documentation page for c++ <-> script interoperability has been created and its pretty good.   bugfixes bugfixes   The new version has taken over the master branch, the previous version for AS 2.30.2 is in a branch called legacy-as-ver-2-30-2. The documentation for both versions is available using the new documentation version selectonator at the root of the docs.   Links: github the new fancy doc page for interoperability  
  5. Sami Vuorela

    Template containers angelscript addon library release!

    By the way friends, I have recently made a refactoring of the library that puts everything inside namespaces and adds a convenient interface to create and manipulate AATC containers in c++. Before this using the containers in c++ was outrageously inconvenient due to too many c++ templates getting in the way. Now you can conveniently pass containers between c++ and angelscript and make use of them in c++ without 400 templates getting in your way.   The refactor was born of this github issue. There's a bit of documentation available in the last post of the issue too.   The c++ side now makes use of metaprogramming techniques such as tag dispatch instead of std::conditional to achieve c++ side convenience. This makes it easier for AATC to support additional container types and somewhat reduces template smell.   The config file looks quite different because most options are now proper variables (not macros) and neatly organized inside namespaces. Some macros still remain.   I haven't merged the refactor to the master branch yet because it is quite the breaking change due to the new namespaces breaking literally all old names (in c++, not angelscript). I have tested the refactor with ye olde AATC tests and my game project. Seems to work good with only minor name changes.   The angelscript side interface has no major changes. Some default method names have been consolidated a bit (insert_position_before -> just insert, erase_position_range & erase_position -> just erase) etc. They can be changed right back in the config if you like the long names or have a grudge against function overloading.   The refactor is available in its own github branch for now. Before merging to main / creating full documentation I would like some reviews from users / Andreas. Does it work with your projects? Did I manage to remove some feature you were using? Is the c++ code more comprehensible?   pastebin link to initial list of name changes in cpp pastebin link to miniature documentation of the cpp interface  
  6. The scriptstdstring.cpp file in AS version 2.30.2 has this code after the first includes:   using namespace std; BEGIN_AS_NAMESPACE // This macro is used to avoid warnings about unused variables. // Usually where the variables are only used in debug mode. #define UNUSED_VAR(x) (void)(x) #if AS_USE_STRINGPOOL == 1 #ifdef AS_CAN_USE_CPP11 // The string pool doesn't need to keep a specific order in the // pool, so the unordered_map is faster than the ordinary map #include <unordered_map>  // std::unordered_map typedef unordered_map<const char *, string> map_t; #else #include <map>      // std::map typedef map<const char *, string> map_t; #endif . If the preprocessor definition AS_USE_NAMESPACE is defined and BEGIN_AS_NAMESPACE opens the Angelscript namespace, the includes for map or unordered_map after the namespace will explode horribly and give hundreds of errors about the gruesome internals of the standard library.   If I move the includes above the BEGIN_AS_NAMESPACE line, all is well.     No explosions:   using namespace std; #if AS_USE_STRINGPOOL == 1   #ifdef AS_CAN_USE_CPP11     // The string pool doesn't need to keep a specific order in the     // pool, so the unordered_map is faster than the ordinary map     #include <unordered_map>  // std::unordered_map   #else     #include <map>      // std::map   #endif #endif BEGIN_AS_NAMESPACE // This macro is used to avoid warnings about unused variables. // Usually where the variables are only used in debug mode. #define UNUSED_VAR(x) (void)(x) #if AS_USE_STRINGPOOL == 1 #ifdef AS_CAN_USE_CPP11   // The string pool doesn't need to keep a specific order in the   // pool, so the unordered_map is faster than the ordinary map   typedef unordered_map<const char *, string> map_t; #else   typedef map<const char *, string> map_t; #endif        
  7. Sami Vuorela

    Template containers angelscript addon library release!

    Implemented bool iterator::IsValid() and fixed some bugs.   Name is ofcourse configurable.
  8. Sami Vuorela

    Template containers angelscript addon library release!

    Implemented some form of iterator safety.   /* Every operation that changes a container increments a version number. If you try to access an iterator and it's version number differs from the container's, an exception will be thrown. Without this, illegal access will crash. This obviously reduces runtime performance. */ #define aatc_CONFIG_ENABLE_ERRORCHECK_ITERATOR_SAFETY_VERSION_NUMBERS 1   With this thing on, this code will cause exceptions instead of crashing:   vector<int> cont; cont.push_back(1); cont.push_back(2); cont.push_back(3); cont.push_back(4); cont.push_back(5); auto it = cont.find_iterator(3); cont.erase(it); cont.erase(it);//this line will cause an exception, because the previous erase modified the container for(auto it = cont.begin(); it++;){ Print("value = " + it.value); if(it.value == 4){ //modify the container //this line will work here, but any iterator access or incrementing after it will cause an exception cont.push_back(123); } }       You can custom tune your exception messages in the config: /* Happens when trying to access or set an iterator and the container has been modified after iterator construction. */ #define aatc_errormessage_iterator_container_modified "Invalid iterator. Container has been modified during iteration." /* Used by the container if it tries to use an invalid iterator. Example of erasing twice with the same iterator: vector<int> myvec; //add 1 2 3 4 5 to vector auto it = myvec.find_iterator(3); myvec.erase(it); myvec.erase(it);//this line will cause this exception, because the first erase changed the container state and invalidated all iterators */ #define aatc_errormessage_container_iterator_invalid "Invalid iterator."     Available in the experimental branch.
  9. Sami Vuorela

    Template containers angelscript addon library release!

    New iterator things!       iterator container::end() //returns an iterator that points at the end, useful for... bool iterator::operator==(const iterator &in) //checking if your iterator equals end bool iterator::IsEnd() //check it with 1 c++ function call and no need for creating another iterator object bool container::erase(const iterator &in) //erase at iterator, returns true if something was erased (if iterator was not end) size_t container::erase(const iterator_range_begin &in,const iterator_range_end &in) //erase a range, returns amount of things erased //non map containers iterator container::find_iterator(const value &in) //find that returns an iterator, returns end if not found //vector and list void container::insert(const iterator &in, const value &in) //insert before iterator, using end iterator will insert at the end //map / uo_map iterator container::find_iterator(const key &in) //find that returns an iterator, returns end if not found . As usual, you can change all the names in the config. If you don't like the nonstandard "value find(value,bool& success", you can name that to "nonstd_find" and name "find_iterator" to just "find".   No reverse iterators yet.   Also made some architecture changes to the c++ side of things, more templates, less nasty preprocessor names.       Theres a bit of a safety problem with iterators right now: If a container is modified, all of it's currently existing iterators become invalid and using them will crash. I got some plans for more iterator safety, but it didn't make it to this build.   New stuff available in the new branch "experimental". ZIP
  10. Sami Vuorela

    Template containers angelscript addon library release!

    opIndex now works as described in post 28.   The registration code abuses existing Find and Insert, Find returns a default value if the value is not found.   Registration code: engine->RegisterObjectMethod(n_container_T, "const T_value& get_opIndex(const T_key &in) const", asMETHODPR(T_container, Find, (void*), const void*), asCALL_THISCALL); engine->RegisterObjectMethod(n_container_T, "void set_opIndex(const T_key&in,const T_value&in)", asMETHOD(T_container, Insert), asCALL_THISCALL);       Find has an overload where it takes a reference to a bool and writes success yes/no there.     Code showing opIndex_set opIndex_get and find with success: map<int,int> mymap; mymap[1] = 11; mymap[3] = 33; mymap[2] = 22; Print("opindex[1] = "+mymap[1]); Print("opindex[2] = "+mymap[2]); Print("opindex[3] = "+mymap[3]); bool success = false; int findresult = mymap.find(2,success); if(success){   Print("findresult = "+findresult); } //Prints 11 22 33 and 22
  11. Sami Vuorela

    Template containers angelscript addon library release!

    Added opIndex for map and unordered map, does the same thing as map::Find. T_value& opIndex(const T_key &in) Its available in the experimental-serializer-support branch. ZIP.
  12. Sami Vuorela

    Template containers angelscript addon library release!

    There were some horrifying bugs related to the engine constructing aatc containers without an active script context. They are now fixed.   With those bugs fixed the serializer support can now handle structures of this complexity:     class sertest_Host{ vector<sertest_World@> worlds; }; class sertest_World{ sertest_Host@ host;//test circular reference vector<sertest_WorldObject@> objects; string name; }; class sertest_WorldObject{ sertest_World@ world;//test circular reference string name; unordered_set<int> values; map<string,string> textvalues; }; sertest_Host@ sertest_host; Container of objects containing containers of objects containing containers and circular references.   The serializer support still can't handle any handles directly to containers.  
  13. Sami Vuorela

    Template containers angelscript addon library release!

    There was a real problem: Apparently the serializer does two passes: recursive Restore on all the objects and recursive RestoreHandles on all the handles. Pointers passed to CSerializedValue::Restore must be valid until the RestoreHandles pass.   The scriptarray class allocates once and then restores things in place, so all its pointers to its stored objects will be legit.   Some AATC container's contents cannot be restored in place, for example with associative containers, where the state of the object decides its place in the container. Those container classes require that their contents are restored first, then added to the container once their state is ready for sorting or hashing.   In the previous code I was trying to restore them by passing pointers on the stack to CSerializedValue::Restore and adding them to the container during the restore callbacks, but using that approach the pointers to the restored objects were no longer valid during the RestoreHandles pass.   I solved this problem by restoring all the objects to an array during the restore callbacks, then adding the contents of that array to the actual container in a new pass, after the big call to Serializer::Restore. This approach might cause some problems if the state of the container is important for other objects during the Restore pass, but a bunch of semi-complex tests are working fine.   The arrays that store objects between the passes are currently stored in a global variable, because the CSerializer class has no userdata pointers available for storing things like these.       I did get all the things working mostly perfectly in the end. New experimental branch available here: https://github.com/Sami-Vuorela/aatc/archive/experimental-serializer-support.zip New readme: https://github.com/Sami-Vuorela/aatc/blob/experimental-serializer-support/EXPERIMENTAL_README.txt   Syntax: CSerializer* my_serializer = new CSerializer(); aatc_serializer_register(engine, my_serializer); my_serializer->Store(my_module); //Do_Things_Requiring_Script_Serialization() my_serializer->Restore(my_module); aatc_serializer_cleanup(engine, my_serializer); delete my_serializer; You can disable all serializer code in the config if its causing you trouble or if you want faster compilation.   The testing environment for this was quite simple so some problems miiiight have gotten through. Crazy things like this don't seem to work "vector<vector<SomeObject@>@>". Do post here and tell me if this thing actually works with whatever you're using it with.
  14. Sami Vuorela

    Template containers angelscript addon library release!

    yo Andreas, I could use some help with the serializings.   I got everything except for handles serializing properly.   Containers containing primitives are serialized by simply copying the whole container to CSerializedValue userdata, like in the example for std::string.   Containers containing script objects are serialized like this:   my_serializer_usertype::store(CSerializedValue* val_root, void* ptr){ actual_container_type* container = cast_dark_majicks(ptr); for(auto it = container->begin(); it != container->end(); it++){ val_root->m_children.push_back(new CSerializedValue(val_root, "", "", const_cast<void*>(*it), container->astypeid_content)); } } my_serializer_usertype::restore(CSerializedValue* val_root, void* ptr){ actual_container_type* container = cast_dark_majicks(ptr); container->clear();//this releases script objects properly for(int i = 0; i < val_root->m_children.size(); i++){ void* restored_object = container->engine->CreateScriptObject(container->objtype_content); val_root->m_children[i]->Restore(restored_object, container->astypeid_content); container->push_back(restored_object); } }   seems to work fine     Containers containing handles are serialized like this:   my_serializer_usertype::store(CSerializedValue* val_root, void* ptr){ actual_container_type* container = cast_dark_majicks(ptr); for(auto it = container->begin(); it != container->end(); it++){ const void* ptr_to_object = *it; const void** ptr_to_ptr_to_object = &ptr_to_object; val_root->m_children.push_back(new CSerializedValue(val_root, "", "", const_cast<void*>((void*)ptr_to_ptr_to_object), container->astypeid_content)); } } my_serializer_usertype::restore(CSerializedValue* val_root, void* ptr){ actual_container_type* container = cast_dark_majicks(ptr); container->clear();//this releases script objects properly for(int i = 0; i < val_root->m_children.size(); i++){ void* restored_object = nullptr; void** ptr_to_ptr_to_object = &restored_object; val_root->m_children[i]->Restore((void*)ptr_to_ptr_to_object, container->astypeid_content); container->push_back(restored_object); } }   this seems to die horribly during CSerializer::Restore with this callstack:     aatc_debug.exe![thunk]:AngelScript::asCScriptObject::`vcall'{8,{flat}}' }'() C++ > aatc_debug.exe!AngelScript::asCScriptEngine::CallObjectMethod(void * obj, AngelScript::asSSystemFunctionInterface * i, AngelScript::asCScriptFunction * s) Line 4211 C++   aatc_debug.exe!AngelScript::asCScriptEngine::CallObjectMethod(void * obj, int func) Line 4163 C++   aatc_debug.exe!AngelScript::asCScriptEngine::ReleaseScriptObject(void * obj, const AngelScript::asIObjectType * type) Line 5209 C++   aatc_debug.exe!AngelScript::CSerializedValue::RestoreHandles() Line 475 C++   aatc_debug.exe!AngelScript::CSerializedValue::RestoreHandles() Line 494 C++   aatc_debug.exe!AngelScript::CSerializedValue::RestoreHandles() Line 494 C++   aatc_debug.exe!AngelScript::CSerializer::Restore(AngelScript::asIScriptModule * mod) Line 125 C++   aatc_debug.exe!AngelScript::main_contents() Line 46 C++   aatc_debug.exe!main() Line 68 C++   [External Code]   how is this different from the array addon example?      
  15. Sami Vuorela

    Template containers angelscript addon library release!

    I've been trying to get the serialization working and guess what: as template problems. The serializer doesn't seem to care about template specializations at all.   vector<T> is a template vector<string> is a template specialization serializer->AddUserType(new aatc_serializer_usertype_container_vector_template(), "vector"); serializer->AddUserType(new aatc_serializer_usertype_container_vector_tempspec_string(), "vector<string>"); My test script has 1 'vector<string>' global thats supposed to get serialized. If I compile with both of the above lines, 'aatc_serializer_usertype_container_vector_template' usertype will be used, which is wrong. If I comment out the first line, I get this error 'Cannot restore type 'vector'' , the serializer refuses to use the 'aatc_serializer_usertype_container_vector_tempspec_string' usertype for 'vector<string>'.     Also, the serializer docs are a little old: new CSerializedValue(...) uses 4 parameters in the docs even though a new one has been added in the middle: 'const std::string& namespace' CSerializedValue->Restore(...) uses 1 parameter in the docs. A second parameter has been added: 'int refTypeId' , who knows how that is supposed to be used.
  • 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!