| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- #include <stdio.h>
- #include <string.h>
- #ifndef _MSC_VER
- # include <unistd.h>
- #endif
- #include <stdlib.h>
- #include "AllUrho.h"
- #include "glue.h"
- #include "interop.h"
- using namespace Urho3D;
- //
- // This is just an implemention of EventHandler that can be used with function
- // pointers, so we can register delegates from C#
- //
- extern "C" {
- DllExport
- void * urho_map_get_ptr (VariantMap &map, int hash)
- {
- StringHash h (hash);
- return map [h].GetVoidPtr ();
- }
- DllExport
- void * urho_map_get_object(VariantMap &map, int hash, int* objHash)
- {
- StringHash h(hash);
- void* ptr = map[h].GetVoidPtr();
- Object * object = static_cast<Object *>(ptr);
- *objHash = object->GetType().Value(); //GetType is virtual
- return ptr;
- }
- DllExport
- const char * urho_map_get_String (VariantMap& map, int hash)
- {
- StringHash h (hash);
- return stringdup(map [h].GetString ().CString());
- }
-
- DllExport
- int urho_map_get_StringHash (VariantMap& map, int hash)
- {
- StringHash h (hash);
- return map [h].GetStringHash ().Value ();
- }
-
- DllExport
- Variant urho_map_get_Variant (VariantMap& map, int hash)
- {
- StringHash h (hash);
- return map [h];
- }
-
- DllExport
- Vector3 urho_map_get_Vector3 (VariantMap& map, int hash)
- {
- StringHash h (hash);
- return map [h].GetVector3 ();
- }
- DllExport
- int urho_map_get_bool (VariantMap& map, int hash)
- {
- StringHash h (hash);
- return map [h].GetBool ();
- }
-
- DllExport
- float urho_map_get_float (VariantMap& map, int hash)
- {
- StringHash h (hash);
- return map [h].GetFloat ();
- }
-
- DllExport
- int urho_map_get_int (VariantMap& map, int hash)
- {
- StringHash h (hash);
- return map [h].GetInt ();
- }
-
- DllExport
- unsigned int urho_map_get_uint (VariantMap& map, int hash)
- {
- StringHash h (hash);
- return map [h].GetUInt ();
- }
- DllExport unsigned char *
- urho_map_get_buffer (VariantMap &map, int hash, unsigned *size)
- {
- StringHash h (hash);
- PODVector<unsigned char> p (map [h].GetBuffer ());
- *size = p.Size();
- unsigned char * result = new unsigned char[p.Size()];
- for (int i = 0; i < p.Size(); i++) {
- result[i] = p[i];
- }
- return result;
- }
- DllExport
- void urho_unsubscribe (NotificationProxy *proxy)
- {
- proxy->Unsub ();
- }
- DllExport void
- UI_LoadLayoutToElement(Urho3D::UI *_target, Urho3D::UIElement *to, Urho3D::ResourceCache *cache, const char * name)
- {
- SharedPtr<UIElement> layoutRoot = _target->LoadLayout(cache->GetResource<XMLFile>(name));
- to->AddChild(layoutRoot);
- }
- DllExport int
- Scene_LoadXMLFromCache(Urho3D::Scene *_target, Urho3D::ResourceCache *cache, const char * name)
- {
- SharedPtr<File> file = cache->GetFile(name);
- return _target->LoadXML(*file);
- }
-
- DllExport
- void *TouchState_GetTouchedElement (TouchState *state)
- {
- return (void *) state->GetTouchedElement ();
- }
- DllExport
- const char *Urho_GetPlatform ()
- {
- return stringdup (GetPlatform().CString ());
- }
- DllExport
- unsigned urho_stringhash_from_string (const char *p)
- {
- StringHash foo (p);
- return foo.Value ();
- }
-
- DllExport
- Skeleton *AnimatedModel_GetSkeleton (AnimatedModel *model)
- {
- return &model->GetSkeleton ();
- }
- DllExport
- unsigned Controls_GetButtons (Controls *controls)
- {
- return controls->buttons_;
- }
- DllExport
- void* Graphics_GetSdlWindow(Graphics* target)
- {
- return target->GetWindow();
- }
- DllExport
- void Controls_SetButtons (Controls *controls, unsigned value)
- {
- controls->buttons_ = value;
- }
-
- DllExport
- float Controls_GetYaw (Controls *controls)
- {
- return controls->yaw_;
- }
- DllExport
- void Controls_SetYaw (Controls *controls, float value)
- {
- controls->yaw_ = value;
- }
- DllExport
- float Controls_GetPitch (Controls *controls)
- {
- return controls->pitch_;
- }
- DllExport
- void Controls_SetPitch (Controls *controls, float value)
- {
- controls->pitch_ = value;
- }
- DllExport void
- Controls_Reset (Urho3D::Controls *_target)
- {
- _target->Reset ();
- }
-
- DllExport void
- Controls_Set (Urho3D::Controls *_target, unsigned int buttons, int down)
- {
- _target->Set (buttons, down);
- }
-
- DllExport int
- Controls_IsDown (Urho3D::Controls *_target, unsigned int button)
- {
- return _target->IsDown (button);
- }
-
- #if !defined(UWP)
- DllExport int
- Network_Connect(Network *net, const char *ptr, short port, Scene *scene)
- {
- String s(ptr);
- return net->Connect(s, port, scene) ? 1 : 0;
- }
- DllExport const Controls *
- Connection_GetControls (Connection *conn)
- {
- return &conn->GetControls ();
- }
- DllExport void
- Connection_SetControls(Connection *conn, Controls *ctl)
- {
- conn->SetControls(*ctl);
- }
- #endif
- DllExport Controls *
- Controls_Create ()
- {
- return new Controls ();
- }
- DllExport void
- Controls_Destroy (Controls *controls)
- {
- delete controls;
- }
- DllExport RayQueryResult *
- Octree_Raycast(Octree *octree, const Urho3D::Ray & ray, const Urho3D::RayQueryLevel & level, float maxDistance, unsigned int flags, unsigned int viewMask, bool single, int *count) {
- PODVector<RayQueryResult> results;
- auto size = sizeof(RayQueryResult);
- RayOctreeQuery query(results, ray, level, maxDistance, flags, viewMask);
- if (single)
- octree->RaycastSingle(query);
- else
- octree->Raycast(query);
- if (results.Size() == 0)
- return NULL;
- RayQueryResult * result = new RayQueryResult[results.Size()];
- *count = results.Size();
- for (int i = 0; i < results.Size(); i++) {
- result[i] = results[i];
- }
- return result;
- }
- DllExport void
- Console_OpenConsoleWindow()
- {
- OpenConsoleWindow();
- }
- DllExport const char *
- Console_GetConsoleInput()
- {
- return stringdup(GetConsoleInput().CString());
- }
- //
- // returns: null on no matches
- // otherwise, a pointer that should be released with free() that
- // contains a first element (pointer sized) with the number of elements
- // followed by the number of pointers
- //
- DllExport
- void *urho_node_get_components (Node *node, int code, int recursive, int *count)
- {
- PODVector<Node*> dest;
- node->GetChildrenWithComponent (dest, StringHash(code), recursive);
- if (dest.Size () == 0)
- return NULL;
- *count = dest.Size ();
- void **t = (void **) malloc (sizeof(Node*)*dest.Size());
- for (int i = 0; i < dest.Size (); i++){
- t [i] = dest [i];
- }
- return t;
- }
- DllExport Interop::Vector3 *
- urho_navigationmesh_findpath(NavigationMesh * navMesh, const class Urho3D::Vector3 & start, const class Urho3D::Vector3 & end, int *count)
- {
- PODVector<Vector3> dest;
- navMesh->FindPath(dest, start, end);
- if (dest.Size() == 0)
- return NULL;
- *count = dest.Size();
- Interop::Vector3 * results = new Interop::Vector3[dest.Size()];
- for (int i = 0; i < dest.Size(); i++) {
- auto vector = *((Interop::Vector3 *) &(dest[i]));
- results[i] = vector;
- }
- return results;
- }
-
- DllExport MemoryBuffer* MemoryBuffer_MemoryBuffer(void* data, int size)
- {
- auto buffer = new MemoryBuffer(data, size);
- return buffer;
- }
- DllExport unsigned char* MemoryBuffer_GetData(MemoryBuffer* target, int *count)
- {
- *count = target->GetSize();
- return target->GetData();
- }
- DllExport void MemoryBuffer_Dispose(MemoryBuffer* target)
- {
- delete target;
- }
- }
|