]> git.jsancho.org Git - c-irrlicht.git/commitdiff
Use structs with casting, without classes replication master
authorJavier Sancho <jsf@jsancho.org>
Thu, 12 Dec 2019 08:26:09 +0000 (09:26 +0100)
committerJavier Sancho <jsf@jsancho.org>
Thu, 12 Dec 2019 08:26:09 +0000 (09:26 +0100)
examples/01.HelloWorld.c
examples/02.Quake3Map.c
examples/03.CustomSceneNode.c
include/SColor.h
src/IGUIEnvironment.cpp
src/ISceneManager.cpp
src/ISceneNode.cpp
src/IVideoDriver.cpp

index ed6746937595a61972dc4d135c46beed04b341d0..a6826927e78b92c023e58bde58a6867699be89a7 100644 (file)
@@ -74,7 +74,7 @@ int main()
   irr_scene_addCameraSceneNode(smgr, NULL, &position, &lookat, -1, true);
                                              
   // loop
-  irr_video_SColor bgcolor = {255, 100, 101, 140};
+  irr_video_SColor bgcolor = MAKE_COLOR(255, 100, 101, 140);
   while (irr_run(device))
     {
       irr_video_beginScene(driver, true, true, &bgcolor, NULL, NULL);
index 8d2f2791bb2b44c79f31f461a92d5beafd3ae05b..6dcaafeae3a06d45902a5d1b258fb4ff04570b97 100644 (file)
@@ -83,7 +83,7 @@ int main()
                                              
   // loop
   int lastFPS = -1;
-  irr_video_SColor bgcolor = {255, 200, 200, 200};
+  irr_video_SColor bgcolor = MAKE_COLOR(255, 200, 200, 200);
   while (irr_run(device))
     {
       if (irr_isWindowActive(device))
index 9d74614cd4bccf31a0ca79ad86660d9a60fe15d6..e2715f64b315648069bacc3907bd69ebf8cc0fa1 100644 (file)
@@ -73,10 +73,10 @@ int main()
   irr_video_S3DVertex vertices[] =
     {
      // pos, normal, color, tcoords
-     { {0, 0, 10}, {1, 1, 0}, {255, 0, 255, 255}, {0, 1} },
-     { {10, 0, -10}, {1, 0, 0}, {255, 255, 0, 255}, {1, 1} },
-     { {0, 20, 0}, {0, 1, 1}, {255, 255, 255, 0}, {1, 0} },
-     { {-10, 0, -10}, {0, 0, 1}, {255, 0, 255, 0}, {0, 0} }
+     { {0, 0, 10}, {1, 1, 0}, MAKE_COLOR(255, 0, 255, 255), {0, 1} },
+     { {10, 0, -10}, {1, 0, 0}, MAKE_COLOR(255, 255, 0, 255), {1, 1} },
+     { {0, 20, 0}, {0, 1, 1}, MAKE_COLOR(255, 255, 255, 0), {1, 0} },
+     { {-10, 0, -10}, {0, 0, 1}, MAKE_COLOR(255, 0, 255, 0), {0, 0} }
     };
   irr_video_SMaterial material = S_MATERIAL_DEFAULT;
   material.wireframe = false;
@@ -136,7 +136,7 @@ int main()
 
   // loop
   int frames = 0;
-  irr_video_SColor bgcolor = {0, 100, 100, 100};
+  irr_video_SColor bgcolor = MAKE_COLOR(0, 100, 100, 100);
   while (irr_run(device))
     {
       irr_video_beginScene(driver, true, true, &bgcolor, NULL, NULL);
index 6512315dd8533a7c12c419fb601a531d7228ca54..85f454f61417ea0f8bd13686880ce53cfc49c582 100644 (file)
 
 typedef struct
 {
-  uint8_t a;
-  uint8_t r;
-  uint8_t g;
   uint8_t b;
+  uint8_t g;
+  uint8_t r;
+  uint8_t a;
 } irr_video_SColor;
 
+#define MAKE_COLOR(a, r, g, b) {b, g, r, a}
+
 #endif
index f64f5a8abca65e859da4aafd768a9f587bbaa499..6fc3cfa05ae254ad8448fdf797fb5a4d8c12047c 100644 (file)
@@ -38,18 +38,11 @@ extern "C" {
     wchar_t *wtext = (wchar_t*)malloc((strlen(text) + 1) * sizeof(wchar_t));
     mbstowcs(wtext, text, strlen(text) + 1);
 
-    // Make rectangle
-    irr::core::rect<irr::s32> rect =
-      irr::core::rect<irr::s32>(rectangle->x,
-                                rectangle->y,
-                                rectangle->x2,
-                                rectangle->y2);
-
     // Add static text
     irr::gui::IGUIStaticText *staticText =
       ((irr::gui::IGUIEnvironment*)guienv)
       ->addStaticText(wtext,
-                      rect,
+                      *(irr::core::rect<irr::s32>*)rectangle,
                       border,
                       wordWrap,
                       (irr::gui::IGUIElement*)parent,
index 42bfac57fd3deea71cad27044a380c5c4169c832..d01e785b399fa2ca605f268be8edd02f9fff0f11 100644 (file)
@@ -89,29 +89,14 @@ extern "C" {
                                      irr_core_vector3df* scale,
                                      bool alsoAddIfMeshPointerZero)
   {
-    const irr::core::vector3df iPosition =
-      position ?
-      irr::core::vector3df(position->x, position->y, position->z) :
-      irr::core::vector3df(0, 0, 0);
-
-    const irr::core::vector3df iRotation =
-      rotation ?
-      irr::core::vector3df(rotation->x, rotation->y, rotation->z) :
-      irr::core::vector3df(0, 0, 0);
-
-    const irr::core::vector3df& iScale =
-      scale ?
-      irr::core::vector3df(scale->x, scale->y, scale->z) :
-      irr::core::vector3df(1, 1, 1);
-
     return (irr_scene_IAnimatedMeshSceneNode*)
       ((irr::scene::ISceneManager*)smgr)
       ->addAnimatedMeshSceneNode((irr::scene::IAnimatedMesh*)mesh,
                                  (irr::scene::ISceneNode*)parent,
                                  id,
-                                 iPosition,
-                                 iRotation,
-                                 iScale,
+                                 position ? *(irr::core::vector3df*)position : irr::core::vector3df(0, 0, 0),
+                                 rotation ? *(irr::core::vector3df*)rotation : irr::core::vector3df(0, 0, 0),
+                                 scale ? *(irr::core::vector3df*)scale : irr::core::vector3df(1, 1, 1),
                                  alsoAddIfMeshPointerZero);
   }
 
@@ -123,21 +108,11 @@ extern "C" {
                                int32_t id,
                                bool makeActive)
   {
-    const irr::core::vector3df& iPosition =
-      position ?
-      irr::core::vector3df(position->x, position->y, position->z) :
-      irr::core::vector3df(0, 0, 0);
-
-    const irr::core::vector3df& iLookat =
-      lookat ?
-      irr::core::vector3df(lookat->x, lookat->y, lookat->z) :
-      irr::core::vector3df(0, 0, 100);
-
     return (irr_scene_ICameraSceneNode*)
       ((irr::scene::ISceneManager*)smgr)
       ->addCameraSceneNode((irr::scene::ISceneNode*)parent,
-                           iPosition,
-                           iLookat,
+                           position ? *(irr::core::vector3df*)position : irr::core::vector3df(0, 0, 0),
+                           lookat ? *(irr::core::vector3df*)lookat : irr::core::vector3df(0, 0, 100),
                            id,
                            makeActive);
   }
@@ -185,28 +160,13 @@ extern "C" {
         parent = irr_scene_getRootSceneNode(smgr);
       }
 
-    const irr::core::vector3df iPosition =
-      position ?
-      irr::core::vector3df(position->x, position->y, position->z) :
-      irr::core::vector3df(0, 0, 0);
-
-    const irr::core::vector3df iRotation =
-      rotation ?
-      irr::core::vector3df(rotation->x, rotation->y, rotation->z) :
-      irr::core::vector3df(0, 0, 0);
-
-    const irr::core::vector3df& iScale =
-      scale ?
-      irr::core::vector3df(scale->x, scale->y, scale->z) :
-      irr::core::vector3df(1, 1, 1);
-
     CustomSceneNode *node =
       new CustomSceneNode((irr::scene::ISceneNode*)parent,
                           (irr::scene::ISceneManager*)smgr,
                           id,
-                          iPosition,
-                          iRotation,
-                          iScale,
+                          position ? *(irr::core::vector3df*)position : irr::core::vector3df(0, 0, 0),
+                          rotation ? *(irr::core::vector3df*)rotation : irr::core::vector3df(0, 0, 0),
+                          scale ? *(irr::core::vector3df*)scale : irr::core::vector3df(1, 1, 1),
                           render,
                           getBoundingBox,
                           getMaterialCount,
@@ -234,11 +194,8 @@ extern "C" {
   irr_scene_createRotationAnimator(irr_scene_ISceneManager* smgr,
                                    irr_core_vector3df* rotationSpeed)
   {
-    const irr::core::vector3df& irrRotationSpeed =
-      irr::core::vector3df(rotationSpeed->x, rotationSpeed->y, rotationSpeed->z);
-
     return ((irr::scene::ISceneManager*)smgr)
-      ->createRotationAnimator(irrRotationSpeed);
+      ->createRotationAnimator(*(irr::core::vector3df*)rotationSpeed);
   }
 
   void
index a2c90a7f9392633fede8d690663b923dad827d88..ce80c97803aee7b120330b0fc6f6d80b99005bd8 100644 (file)
@@ -62,11 +62,8 @@ extern "C" {
   irr_scene_setPosition(irr_scene_ISceneNode* node,
                         irr_core_vector3df* newpos)
   {
-    const irr::core::vector3df newPosition =
-      irr::core::vector3df(newpos->x, newpos->y, newpos->z);
-
     ((irr::scene::ISceneNode*)node)
-      ->setPosition(newPosition);
+      ->setPosition(*(irr::core::vector3df*)newpos);
   }
 
 }
index 6bc1020f8cfab87bf61778c141f85a379bfe2e07..61333989136cdecf3f75933c93084e7d41acd2fc 100644 (file)
@@ -32,31 +32,17 @@ extern "C" {
                        irr_video_SExposedVideoData* videoData,
                        const irr_core_rect_s32* sourceRect)
   {
-    // Color
-    irr::video::SColor col = irr::video::SColor(color->a, color->r,
-                                                color->g, color->b);
-
     // Video data
     // TODO
     irr::video::SExposedVideoData vdata = irr::video::SExposedVideoData();
 
-    // Source rect
-    irr::core::rect<irr::s32> rect;
-    if (sourceRect != NULL)
-      {
-        rect = irr::core::rect<irr::s32>(sourceRect->x,
-                                         sourceRect->y,
-                                         sourceRect->x2,
-                                         sourceRect->y2);
-      }
-
     // Begin scene
     return ((irr::video::IVideoDriver*)driver)
       ->beginScene(backBuffer,
                    zBuffer,
-                   col,
+                   *(irr::video::SColor*)color,
                    vdata,
-                   sourceRect != NULL ? &rect : 0);
+                   (irr::core::rect<irr::s32>*)sourceRect);
   }
 
   void
@@ -69,49 +55,12 @@ extern "C" {
                                     irr_scene_E_PRIMITIVE_TYPE pType,
                                     irr_video_E_INDEX_TYPE iType)
   {
-    // Convert vertices
-    irr::video::S3DVertex irrVertices[vertexCount];
-    for (int i=0; i<vertexCount; i++)
-      {
-        irr_video_S3DVertex *vertex = (irr_video_S3DVertex*)vertices + i;
-        irrVertices[i] =
-          irr::video::S3DVertex(vertex->pos.x, vertex->pos.y, vertex->pos.z,
-                                vertex->normal.x, vertex->normal.y, vertex->normal.z,
-                                irr::video::SColor(vertex->color.a,
-                                                   vertex->color.r,
-                                                   vertex->color.g,
-                                                   vertex->color.b),
-                                vertex->tCoords.x, vertex->tCoords.y);
-      }
-
-    // Convert indices
-    size_t indexListSize =
-      ((iType == irr_video_EIT_16BIT) ? sizeof(irr::u16) : sizeof(irr::u32)) *
-      primCount * 3;
-    void* irrIndexList = malloc(indexListSize);
-
-    for (int i=0; i<primCount*3; i++)
-      {
-        if (iType == irr_video_EIT_16BIT)
-          {
-            uint16_t *index = (uint16_t*)indexList + i;
-            ((irr::u16*)irrIndexList)[i] = *index;
-          }
-        else
-          {
-            uint32_t *index = (uint32_t*)indexList + i;
-            ((irr::u32*)irrIndexList)[i] = *index;
-          }
-      }
-
     ((irr::video::IVideoDriver*)driver)
-      ->drawVertexPrimitiveList(&irrVertices[0], vertexCount,
-                                irrIndexList, primCount,
+      ->drawVertexPrimitiveList(vertices, vertexCount,
+                                indexList, primCount,
                                 (irr::video::E_VERTEX_TYPE)vType,
                                 (irr::scene::E_PRIMITIVE_TYPE)pType,
                                 (irr::video::E_INDEX_TYPE)iType);
-
-    free(irrIndexList);
   }
 
   int