<wip> emscripten dev.
authorRejean Loyer <redj@ecere.com>
Sat, 3 Jan 2015 01:32:20 +0000 (20:32 -0500)
committerRejean Loyer <redj@ecere.com>
Mon, 16 Mar 2015 05:32:00 +0000 (01:32 -0400)
12 files changed:
ecere/ecere.epj
ecere/ecereCOM.epj
ecere/src/gfx/Bitmap.ec
ecere/src/gfx/bitmaps/PNGFormat.ec
ecere/src/gfx/drivers/OpenGLDisplayDriver.ec
ecere/src/gui/GuiApplication.ec
ecere/src/gui/drivers/EmscriptenInterface.ec
ecere/src/sys/EARArchive.ec
ecere/src/sys/File.ec
samples/eC/HelloWorld/HelloWorld.epj
samples/guiAndGfx/HelloForm/helloForm.ec
samples/guiAndGfx/HelloForm/helloForm.epj

index 6388b21..97d25c2 100644 (file)
@@ -447,28 +447,6 @@ from wherever you obtained them.
       {
          "Name" : "Emscripten",
          "Options" : {
-            "Warnings" : "None",
-            "NoLineNumbers" : true,
-            "Optimization" : "Size",
-            "PreprocessorDefinitions" : [
-               "BUILDING_ECERE_COM",
-               "ECERE_STATIC",
-               "ECERE_VANILLA",
-               "NOBLENDING"
-            ],
-            "TargetType" : "StaticLibrary",
-            "TargetFileName" : "ecereVanilla",
-            "PostbuildCommands" : [
-               "$(call cpq,$(TARGET),../obj/$(PLATFORM)$(COMPILER_SUFFIX)$(DEBUG_SUFFIX)/lib/)"
-            ],
-            "InstallCommands" : [
-               "$(if $(WINDOWS_HOST),$(call cpq,$(TARGET),\"$(DESTSLIBDIR)/\"),install $(INSTALL_FLAGS) $(TARGET) $(DESTSLIBDIR)/$(MODULE)$(A))"
-            ]
-         }
-      },
-      {
-         "Name" : "Emscripten",
-         "Options" : {
             "Debug" : true,
             "PreprocessorDefinitions" : [
                "ECERE_STATIC",
@@ -794,17 +772,7 @@ from wherever you obtained them.
                               }
                            ]
                         },
-                        {
-                           "FileName" : "PNGFormat.ec",
-                           "Configurations" : [
-                              {
-                                 "Name" : "Emscripten",
-                                 "Options" : {
-                                    "ExcludeFromBuild" : true
-                                 }
-                              }
-                           ]
-                        },
+                        "PNGFormat.ec",
                         {
                            "FileName" : "RGBFormat.ec",
                            "Configurations" : [
index 46aea46..d84e2d0 100644 (file)
             "TargetType" : "StaticLibrary",
             "TargetFileName" : "ecereCOMStatic"
          }
+      },
+      {
+         "Name" : "emjslib",
+         "Options" : {
+            "Debug" : true,
+            "Optimization" : "Size",
+            "PreprocessorDefinitions" : [
+               "ECERE_COM_ONLY"
+            ],
+            "TargetType" : "SharedLibrary"
+         }
       }
    ],
    "Files" : [
index 99fd856..b8ce93c 100644 (file)
@@ -30,23 +30,45 @@ static subclass(BitmapFormat) FindFormat(const char * type)
    if(type)
    {
       OldLink link;
+#if defined(__EMSCRIPTEN__)
+      printf("FindFormat: ");
+#endif
       for(link = class(BitmapFormat).derivatives.first; link; link = link.next)
       {
          const char ** extensions;
+#if defined(__EMSCRIPTEN__)
+         Class _class = link.data;
+#endif
          format = link.data;
          extensions = format.extensions;
+#if defined(__EMSCRIPTEN__)
+         printf(", c%s", _class.name);
+#endif
          if(extensions)
          {
             int c;
             for(c = 0; extensions[c] && extensions[c][0]; c++)
                if(!strcmp(extensions[c], type))
+               {
+#if defined(__EMSCRIPTEN__)
+                  printf(", e%s", extensions[c]);
+#endif
                   break;
+               }
             if(extensions[c] && extensions[c][0])
+            {
+#if defined(__EMSCRIPTEN__)
+               PrintLn("------------- type: ", type);
+#endif
                break;
+            }
          }
       }
       if(!link) format = null;
    }
+#if defined(__EMSCRIPTEN__)
+      printf("\n");
+#endif
    return format;
 }
 
@@ -524,22 +546,46 @@ public:
       if(!format)
          typeToTry = 0;
 
+#if defined(__EMSCRIPTEN__)
+      PrintLn("----------- type: ",  type, ", guessedType: ", guessedType, ", format: ", (uint)format);
+#endif
+
       for(; typeToTry < NUM_TYPES_TO_TRY; typeToTry++)
       {
          if(typeToTry >= 0)
+         {
             format = FindFormat(typesToTry[typeToTry]);
+#if defined(__EMSCRIPTEN__)
+            PrintLn("----------- typesToTry[typeToTry]: ",  typesToTry[typeToTry], "(", typeToTry, ")");
+#endif
+         }
 
          if(format)
          {
             File f = FileOpen(fileName, read);
+#if defined(__EMSCRIPTEN__)
+            PrintLn("--------------------------------------------------- fileNameLoading: ",  fileName, " (", f ==  null ? "error" : "ok", ")");
+#endif
             if(f)
             {
+#if defined(__EMSCRIPTEN__)
+               PrintLn("----------------------------- format: ", (uint)format, ", Load: ", (uint)format.Load, ", this: ", (uint)this);
+#endif
                if((result = format.Load(this, f)))
                {
+#if defined(__EMSCRIPTEN__)
+                  PrintLn("--------------------------------------------------- if((result = format.Load(this, f))): ok");
+#endif
                   if(displaySystem)
                   {
+#if defined(__EMSCRIPTEN__)
+                     PrintLn("--------------------------------------------------- if(displaySystem): ok");
+#endif
                      if(!MakeDD(displaySystem))
                      {
+#if defined(__EMSCRIPTEN__)
+                        PrintLn("--------------------------------------------------- if(!MakeDD(displaySystem)): ok");
+#endif
                         Free();
                         result = false;
                      }
index 17f2215..ea450fa 100644 (file)
@@ -2,8 +2,6 @@ namespace gfx::bitmaps;
 
 import "Display"
 
-#if !defined(__EMSCRIPTEN__) && !defined(__pnacl__)
-
 #define uint _uint
 #include "png.h"
 #undef uint
@@ -61,6 +59,9 @@ class PNGFormat : BitmapFormat
    bool Load(Bitmap bitmap, File f)
    {
       bool result = false;
+#if defined(__EMSCRIPTEN__)
+      PrintLn("  -------------------------------------  getting in here  -------------------------------------  ");
+#endif
 
       png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, null, null, null);
 
@@ -309,5 +310,3 @@ class PNGFormat : BitmapFormat
       return result;
    }
 }
-
-#endif // !defined(__EMSCRIPTEN__)
index 11a39d3..39df97e 100644 (file)
@@ -1645,6 +1645,11 @@ class OpenGLDisplayDriver : DisplayDriver
       bool result = false;
       OGLSystem oglSystem = displaySystem.driverData = OGLSystem { };
 
+#if defined(__EMSCRIPTEN__)
+      PrintLn("---------------> oglSystem.pow2textures = true;");
+      oglSystem.pow2textures = true;
+#endif
+
    #ifdef __WIN32__
       oglSystem.hwnd = CreateWindow("static", null, 0,0,0,0,0,null,null,null,null);
 
@@ -1776,7 +1781,7 @@ class OpenGLDisplayDriver : DisplayDriver
       #elif defined(__EMSCRIPTEN__)
          if(glfwInit() == GL_TRUE)
          {
-            const int width = 640, height = 480;
+            const int width = 1024, height = 480;
             if(glfwOpenWindow(width, height, 8, 8, 8, 8, 16, 0, GLFW_WINDOW) == GL_TRUE)
             {
                //glfwSwapBuffers();
index 38f13a8..e21e746 100644 (file)
@@ -704,6 +704,18 @@ public:
          }
 
 #if defined(__EMSCRIPTEN__)
+      EM_ASM
+      (
+         FS.mkdir('/persist');
+         FS.mount(IDBFS, {}, '/persist');
+
+         FS.syncfs(true, function (err)
+         {
+            assert(!err);
+            //ccall('em_idbfs_read_sync_callback', 'v');
+         });
+      );
+      PrintLn("============================================================== Main(); -- emscripten_set_main_loop(em_main_loop_callback, 1/-*60*-/, 1);");
       emscripten_set_main_loop(em_main_loop_callback, 0/*1*//*60*/, 1);
 #endif
 
@@ -1251,6 +1263,9 @@ public:
             {
                interfaceDriver.Terminate();
             }
+#if defined(__EMSCRIPTEN__)
+            PrintLn("============================================================== inter.Initialize();");
+#endif
             result = inter.Initialize();
          }
          else
@@ -1536,4 +1551,9 @@ private void em_main_loop_callback()
    guiApp.Cycle(false);
    guiApp.UpdateDisplay();
 }
+
+/*private *//*void em_idbfs_read_sync_callback()
+{
+   PrintLn("private void em_idbfs_read_sync_callback()");
+}*/
 #endif
index d5d425a..38c74e3 100644 (file)
@@ -536,10 +536,12 @@ private EM_BOOL em_mouse_callback(int eventType, const EmscriptenMouseEvent *e,
    canvasX = e->canvasX;
    canvasY = e->canvasY;
 
+#if 0
    printf("%s, screen: (%ld,%ld), client: (%ld,%ld),%s%s%s%s button: %hu, buttons: %hu, movement: (%ld,%ld), canvas: (%ld,%ld)\n",
          emscripten_event_type_to_string(eventType), e->screenX, e->screenY, e->clientX, e->clientY,
          e->ctrlKey ? " CTRL" : "", e->shiftKey ? " SHIFT" : "", e->altKey ? " ALT" : "", e->metaKey ? " META" : "",
          e->button, e->buttons, e->movementX, e->movementY, e->canvasX, e->canvasY);
+#endif
 
    if(e->shiftKey) mods.shift = true;
    if(e->ctrlKey) mods.ctrl = true;
@@ -578,10 +580,10 @@ private EM_BOOL em_mouse_callback(int eventType, const EmscriptenMouseEvent *e,
          }
          break;
       case EMSCRIPTEN_EVENT_MOUSEMOVE:  method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove;         break;
-      //case EMSCRIPTEN_EVENT_MOUSEENTER: method = 0; break;
-      //case EMSCRIPTEN_EVENT_MOUSELEAVE: method = 0; break;
+      case EMSCRIPTEN_EVENT_MOUSEENTER: method = 0; break;
+      case EMSCRIPTEN_EVENT_MOUSELEAVE: method = 0; break;
       case EMSCRIPTEN_EVENT_MOUSEOVER:  method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove;         break;
-      //case EMSCRIPTEN_EVENT_MOUSEOUT:   method = 0; break;
+      case EMSCRIPTEN_EVENT_MOUSEOUT:   method = 0; break;
       default:                          method = 0;
    }
 
@@ -1055,12 +1057,12 @@ class EmscriptenInterface : Interface
 
    void ::StartMoving(Window window, int x, int y, bool fromKeyBoard)
    {
-      sflnprintf("class(EmscriptenInterface) ::StartMoving [STUB!]\n");
+      // sflnprintf("class(EmscriptenInterface) ::StartMoving [STUB!]\n");
    }
 
    void ::StopMoving(Window window)
    {
-      sflnprintf("class(EmscriptenInterface) ::StopMoving [STUB!]\n");
+      // sflnprintf("class(EmscriptenInterface) ::StopMoving [STUB!]\n");
    }
 
 
@@ -1074,17 +1076,17 @@ class EmscriptenInterface : Interface
 
    void ::SetMousePosition(int x, int y)
    {
-      sflnprintf("class(EmscriptenInterface) ::SetMousePosition [STUB!]\n");
+      // sflnprintf("class(EmscriptenInterface) ::SetMousePosition [STUB!]\n");
    }
 
    void ::SetMouseRange(Window window, Box box)
    {
-      sflnprintf("class(EmscriptenInterface) ::SetMouseRange [STUB!]\n");
+      // sflnprintf("class(EmscriptenInterface) ::SetMouseRange [STUB!]\n");
    }
 
    void ::SetMouseCapture(Window window)
    {
-      sflnprintf("class(EmscriptenInterface) ::SetMouseCapture [STUB!]\n");
+      // sflnprintf("class(EmscriptenInterface) ::SetMouseCapture [STUB!]\n");
    }
 
 
@@ -1092,7 +1094,7 @@ class EmscriptenInterface : Interface
 
    void ::SetMouseCursor(Window window, SystemCursor cursor)
    {
-      sflnprintf("class(EmscriptenInterface) ::SetMouseCursor [STUB!]\n");
+      // sflnprintf("class(EmscriptenInterface) ::SetMouseCursor [STUB!]\n");
    }
 
 
@@ -1172,5 +1174,4 @@ class EmscriptenInterface : Interface
       sflnprintf("class(EmscriptenInterface) ::GetScreenArea [STUB!]\n");
    }
 }
-
 #endif
index 9e28be7..ad545ab 100644 (file)
@@ -42,18 +42,21 @@ static struct EAREntry
 static File EAROpenArchive(const char * archive, EARHeader header)
 {
    File f = null;
+   char moduleName[MAX_LOCATION];
+   moduleName[0] = '\0';
    if(archive[0] == ':')
    {
-      char moduleName[MAX_LOCATION];
       const char * name = archive + 1;
 #if defined(__ANDROID__) || defined(__EMSCRIPTEN__)
+      PrintLn("************************************************************", " archive: ", archive);
       if(!name[0])
          name = ((SubModule)__thisModule.application.modules.first).next.module.name;
 #endif
 #if defined(__EMSCRIPTEN__)
-      //sprintf(moduleName, "__%s.ear", name);
+      //sprintf(moduleName, "%s.data", name);
       sprintf(moduleName, "__%s.ear", "HelloForm");
       f = FileOpen(moduleName, read);
+      PrintLn("************************************************************", f == null ? " ERROR: " : " we have moduleName: ", moduleName, " | ", name);
 #else
       if(LocateModule(name, moduleName))
          f = FileOpen(moduleName, read);
@@ -68,7 +71,12 @@ static File EAROpenArchive(const char * archive, EARHeader header)
       // First attempt to treat this as an archive file
       if(f.Read(header, sizeof(EARHeader), 1) == 1 &&
          !memcmp(header.recognition, earRecognition, sizeof(earRecognition)))
+      {
+#if defined(__EMSCRIPTEN__)
+         PrintLn("************************************************************", " confirm archive moduleName: ", moduleName);
+#endif
          return f;
+      }
 
       // Then try to see if an archive is at the end of the file
       f.Seek(-(int)sizeof(uint), end);
@@ -78,6 +86,9 @@ static File EAROpenArchive(const char * archive, EARHeader header)
          !memcmp(header.recognition, earRecognition, sizeof(earRecognition)))
          return f;
 
+#if defined(__EMSCRIPTEN__)
+      PrintLn("************************************************************", " ERROR ARCHIVE moduleName: ", moduleName);
+#endif
       delete f;
    }
    return null;
index ad6e8f9..8544dcc 100644 (file)
@@ -1,6 +1,11 @@
 namespace sys;
 
 default:
+
+#if defined(__EMSCRIPTEN__)
+#include <emscripten.h>
+#endif
+
 #define set _set
 #define uint _uint
 #define File _File
@@ -245,6 +250,16 @@ public class File : IOChannel
          openCount--;
          fclose(input);
       }
+#if defined(__EMSCRIPTEN__)
+      EM_ASM
+      (
+         FS.syncfs(function (err)
+         {
+            assert(!err);
+            //ccall('em_idbfs_write_sync_callback', 'v');
+         });
+      );
+#endif
       input = null;
       output = null;
    }
@@ -1879,3 +1894,11 @@ public char * GetSlashPathBuffer(char * d, const char * p)
    MakeSlashPath(d);
    return d;
 }
+
+#if defined(__EMSCRIPTEN__)
+//default:
+/*private *//*void em_idbfs_write_sync_callback()
+{
+   PrintLn("private void em_idbfs_write_sync_callback()");
+}*/
+#endif
index ef09fd2..0459671 100644 (file)
@@ -25,6 +25,9 @@
             ],
             "FastMath" : false
          }
+      },
+      {
+         "Name" : "Emscripten"
       }
    ],
    "Files" : [
index 69793fc..3f17b1d 100644 (file)
@@ -2,16 +2,80 @@ import IMPORT_STATIC "ecere"
 
 class HelloForm : Window
 {
-   text = "My First eC Application";
+   caption = $"My First eC Application";
    borderStyle = sizable;
-   size = { 280, 100 };
    hasClose = true;
+   size = { 280, 100 };
 
-   Label label
+   /*Label label
    {
       this, position = { 10, 10 }, font = { "Arial", 30 },
       text = "Hello, World!!"
+   };*/
+
+   Button button1
+   {
+      this, caption = $"button1";
+      size = { 50, 50 };
+      anchor = { right = 0, bottom = 0 };
+
+      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
+      {
+#if 0
+         File f = FileOpen("/persist/test.txt", read);
+         PrintLn("NotifyClicked");
+         PrintLn(f == null ? "error: " : "ok: ", "File f = FileOpen(\"/persist/test.txt\", read);");
+         if(f)
+         {
+            PrintLn("PrintLn(f);");
+            PrintLn(f);
+            PrintLn("delete f;");
+            delete f;
+         }
+#endif
+         picture.image = null;
+         picture.image = { ":ecere.png" };
+         return true;
+      }
    };
+
+   Picture picture
+   {
+      this, size = { 80, 80 }, anchor = { top = 0 }//, image = { ":ecere.png" };
+   };
+
+   bool OnPostCreate()
+   {
+      //picture.image = { ":ecere.png" };
+
+#if 0
+      /*PrintLn("if(FileExists(\"/persist/test.txt\"))");
+      if(1)//if(FileExists("/persist/test.txt"))
+      {
+         PrintLn("File f = FileOpen(\"/persist/test.txt\", read);");
+         File f = FileOpen("/persist/test.txt", read);
+         if(f)
+         {
+            PrintLn("PrintLn(f);");
+            PrintLn(f);
+            delete f;
+         }
+      }
+      else*/
+      {
+         File f = FileOpen("/persist/test.txt", write);
+         PrintLn(f == null ? "error: " : "ok: ", "File f = FileOpen(\"/persist/test.txt\", write);");
+         if(f)
+         {
+            PrintLn("f.PrintLn(\"yo!\");");
+            f.PrintLn("yo!");
+            PrintLn("delete f;");
+            delete f;
+         }
+      }
+#endif
+      return true;
+   }
 };
 
 HelloForm hello { };
index 744b797..4aaf2c5 100644 (file)
             "Libraries" : [
                "ecereStatic",
                "freetype",
+               "png",
                "z"
-            ],
-            "LibraryDirs" : [
-               "../../../ecere/obj/emscripten.linux.emscripten.x32"
             ]
          }
       }
@@ -56,6 +54,6 @@
    ],
    "ResourcesPath" : "",
    "Resources" : [
-
+      "../../../share/pixmaps/ecere.png"
    ]
 }