C++ Advent Calendar 2012 / day 4th : Native-client vs. HTML5 ; C++ in the web-client-world!
C++ Advent Calendar 2012 / 4th day
- (!) ãã®è¨äºã¯C++ Advent Calendar 2012ã®åå è¨äºã§ã ã½(=´â½`=)ï¾
- è¨äºã®å ¬éã¨æ¬ç·¨å 容ã4th dayã®ãªãããããæ°æéé ãã¦ãã¾ãã¾ããäºããè©«ã³ç³ãä¸ãã¾ãã
Native-client vs. HTML5 ; C++ in web-client-world!
諸å
- Published: 2012.12.4
- By: Usagi Ito <[email protected]>
- Environments: (to see the last section of this entry)
Abstract
ä¸éã§ã¯HTML5ãä¸è¬ã«ã話é¡ã«ãªãå§ããå¾ã ã«æã¦åãããæ§ã«ãªãã次第ã«ä¸è¬ã«ã浸éãã¦æ¥ãæ§ãªæ°ããã2012å¹´ã®ã¯ãªã¹ãã¹ã·ã¼ãºã³ã
ï¼â¦ä¸ç¥â¦ï¼ã
ã¦ã§ãã¯ã³ã³ãã¤ã«ãããã¹ãã§ãã( ï½¥`Ï・´)
ã¨ãè¨ã訳ã§ã³ã³ãã¤ã«ãæããããã±ãããã·ãã¼ã©ããC++ã±ãã¼ã§ã²ããµãï½ï½ï½ï½ãï½ï½ï½ï½ãããã¤ãã£ãã«ã¢ããã¼ããæãã¤ã¤ãJavaScriptã®æµã«åãããHTML5ã«å¯¾ãNative-clientã®åªä½æ§ã示ãã¨å
±ã«C++erã«C++ã®ã¦ã§ãã¯ã©ã¤ã¢ã³ãã®ãä»äºãä¸ãããã©ãã·ã£ã¼ãªã«ããå¤æ
ãªã®HTML5ã«ãã©ã¹ãã¦Native-clientãå調çã«åä½ããæ§ã«çµã¿è¾¼ã¿ãããã¯ãã«ãªåºåã¨è¡¨ç¾åã®å¯è½æ§ã示ãããã
Introduction
Native-client
Native-clientã¯ã¦ã§ããã©ã¦ã¶ã¼ä¸ã§ãã¤ãã£ãã³ã¼ãã¢ããªã±ã¼ã·ã§ã³ãå®è¡ããçºã®æ çµã¿ã§ã Chromium(âChrome) 14 ãããã©ã¦ã¶ã¼ã¸ã®å®è£ ãé²ãããå·çæç¹ææ°ã® Chromium 24 ã§ãå¿è«ä½¿ç¨å¯è½ã§ãã
ä¸è¬ã«å¾æ¥ã¦ã§ããã©ã¦ã¶ã¼ä¸ã§ã¢ããªã±ã¼ã·ã§ã³ãåä½ãããæ¹æ³ã¯ãFLASHãJavaã¢ãã¬ãããJavaScriptããã®ä»ã®ãã¤ãã¼ã¹ã¯ãªããç°å¢ãªã©ãèãããã¾ãããä½ããã¯ã©ã¤ã¢ã³ãã®ãã·ã³æ§è½ãçããåãã«ã¯é«ç´éãããããã«ãã¹ã¬ããã£ã³ã°ããªã¢ã«ã¿ã¤ã æ§è½ã«æ¬ ãããå®è¡ç°å¢ãä¸è¬çã§ãªãããªã©ãã¦ãã¾ããå°¤ãæå¾ã®å®è¡ç°å¢ã®ä¸è¬æ§ã«ã¤ãã¦ã¯Native-clientã¯æ½å¨çã«ã¯Chromeã®ã·ã§ã¢ã以ã£ã¦æ®åãã¦ããã¨è¨ãã®ã¯ããä¹±æ´ãªç¶æ³ã§ã¯ããã¾ãããChromeã¦ã§ãã¹ãã¢ããæ¢ã«Secure ShellãLime Berta(NaClテスト版)ãBullet Physics NaCl TestãOgre Sample Browser NaClããªã©Native-clientãç¨ãããµã³ãã«ãå®ç¨ã¢ããªã®éçºãè¦ããã¨ãã§ãã¾ããã¨ããããNative Clientのクオリティー高すぎ!家庭用ゲーム機と同クオリティーを実現したブラウザゲームまとめ | Chrome Lifeã¨ãå®éã¨ã¦ãã²ã¼ã ã§ãã
HTML5
ã¿ããªå¤§å¥½ãHTML5ãWHATGã"Living Draft"ã¨ãã¦æ°¸é ã«å®æãããªãï¼ãã¡ããè¯ãæå³ã§è¡¨ç¾ãã¦ããï¼æ¹éãåããªããW3Cã¨ããããã¤ã¤æé·ä¸ã®æ°åHTMLé¢é£è¦æ ¼ã"é¢é£"ã¨ä»ããã®ã¯ãæ¢ã«ä¹ãç´ç²ãªHTMLã¨ãããã¼ã¿è¨è¿°è¨èªã®æ ãè¶ ãã¦ãCSSã¯å¿è«ã®äºãã¹ã¯ãªããè¨èªããJavaScriptããéä¿¡ã®ãªã¢ã«ã¿ã¤ã æ§ãæ¥ç¶æ§ãé«ããWebSocketãã¦ã§ãã¨ãã«ãã¡ãã£ã¢ããã¤ã¹ã¨ã®HTMLã«ããæ¥ç¶ãå®ç¾ãã¤ã¤ããWebRTCãªã©ãã»ãç´°ããä»æ§ãããããï¼æ£ç´å ¨é¨ææ¡ãã¦ãªãï¼ã
ããããHTML5ã®ããã°ã©ãããªãã£ã¯JavaScriptã ãã«æãã£ã¦ãããJavaScriptã¯2014å¹´ã«æ¬¡ã®è¦æ ¼ãçºè¡¨ããäºã«ãªã£ã¦ããæ°ã¯ãããããã®è¨èªã¯ãã10å¹´ãè¦æ ¼ã®æ´æ°äºã ã§ããç¶ãã¦ä»ã«è³ã£ã¦ãããä¸å®ã¯å¤§ããã
HTML5ã§è¿½å ãããä»åãæ±ãcanvasãããã«videoãaudioã®å¶å¾¡ã¯å¿è«ã®äºãWebGL(âOpenGL)ãWebCL(âOpenCL)ã«è³ã£ã¦ããã®APIã¯JavaScriptã®ã¿ã大åæã¨ãã¦ãããå®ã«é¦¬é¹¿ãã¦ããããã©ã¦ã¶ã¼ã¯ã¹ã¯ãªããè¨èªã®å¦çç³»ãåãé¢ããã¦ã¼ã¶ã¼ã«å¤æ§ãªã¹ã¯ãªãããµãã¼ããæä¾ããæ çµã¿ãæ´åãã¹ãã§ã¯ãªãããã(ä¾ãã°<script type="application-x/haskell">ã¨ããã£ã¨æ軽ã«ã§ãã¦æ¬²ããããNative-clientãããã¾ã§ãããªãã¨ãJavaScriptã§ã¯ãªãPythonãRubyãªã©ããã£ã¨æ軽ã«ä½¿ãã¦ãè¯ãã®ã§ã¯ãªãããããé度çã«ã¯JavaScriptã®æ¹ããã·ããããã©)ã
JavaScriptã¯å¤æ çãªæé©åãæ½ããã¦ããã§ãããå¦çç³»V8ã以ã£ã¦ãã¦ããæè©®ã¯JavaScriptãå°ãªãã¨ãç¾å¨ã®JavaScriptã®è¨èªä»æ§ã§ã¯é«éåããããã¤ãã£ããªä»çµã¿ã®å®è£ ã«å¯¾ãæµã大ãããããããã¤ãã³ãé§åã«æé©åãããã¾ã¨ããªã¹ã¬ããã£ã³ã°ããªã¢ã«ã¿ã¤ã è¦æ±ã«çãããããã¼ã¿æ§é ãã¡ã¢ãªã¼ã®åãæ±ããä¸èªç±ãªJavaScriptã§ãªãã§GLã ã®CLã ã®â¦ç¡çç¢çéããã
ããã§ãC++ãNative-clientã®åºçªã§ã( ï½¥`Ï・´)
Contents
åç½®ããé·ããªãã¾ããããä»åã®è¨äºã§åãæ±ãå 容ã«ã¤ãã¦æ´çãã¾ãã
- â HTML5/canvas ãç¨ãããã¼ãã£ã¯ã«ã·ã¹ãã ã¨ãã¯ã»ã«ãã¼ã¹ãã¬ã³ããªã³ã°ã«ãããã³ããã¼ã¯ãã¼ã¸
- ãã¢
- ã½ã¼ã¹
- 解説
- â¡ Native-client ã®æºåã¨éå½¢
- æºå
- éå½¢
- ⢠Native-client ã«ããâ ã¸ã®C++ã±ãã¼æ³¨å
¥
- ãã¢
- ã½ã¼ã¹
- 解説
ã¾ããä»åã¯æéãå°ã
足ããªãã£ãé½åï¼ã´ã¡ã³ããµã¤ã´ã¡ã³ããµã¤ï¼ãããããã®JavaScriptã¢ããªã®æé©åï¼ä½ãããã¯ã¡ã³ããã³ã¹æ§ã®èãããã¬ã¼ããªããä¼´ããªããã°çã®æé©åã¯ã§ããªãããè¨èªãªã®ã ãã©ï¼ï½ï¼ï¼ããHTML5/WebGLãNative-client/OpenGL ES 2.0çã«ã¤ãã¦ã¯å¹´å
ã«ä½åãåããã°è¿½å è¨äºã«ãããã¨æãã¾ãã
â HTML5/canvas ãç¨ãããã¼ãã£ã¯ã«ã·ã¹ãã ã¨ãã¯ã»ã«ãã¼ã¹ãã¬ã³ããªã³ã°ã«ãããã³ããã¼ã¯ãã¼ã¸
- ãã¢
ãããªæãã®ä½ãã¨ã£ã¦ãéããããããªãããã©ã¯ãªã¹ãã¹ã£ã½ããã¢ãï¼ãã¶ãï¼åãã¾ãã
ç»é¢å·¦ä¸ã« SCORE 㨠FPS ã表示ãããã³ããã¼ã¯ã¢ããªã«ãªã£ã¦ãã¾ããFPSã¯å¡ãç¾å¨ã®ãã¬ã¼ã ã¬ã¼ããSCOREã¯ä¸å®ééã§FPSãåºã«å ç®ãããã¢ã®çµäºæã«å¢å ãæ¢ã¾ãä»çµã¿ã§ãã
ãã«HD(1920x1080)å°ç¨ã§ãï¼ã
F11ãªã©æ¼ãã¦å
¨ç»é¢ã§ã楽ãã¿ä¸ããã¾ãã
ã¡ãªã¿ã«ãç§ã®éçºç°å¢(è¨äºæ«å°¾åç §)ã§ã® Chrome 23 ã®ã¹ã³ã¢ã¯ 464 ã§ããã
ï¼â»åããªãå ´åã¯ãã®ãã¢ã®å®è¡ã«å¯¾ãã¦ã¯ãã·ã³ã¹ããã¯ã足ãã¦ããªãããcanvasãaudioã®ä½¿ããªãã¬ã¬ã·ã¼ãªãã©ã¦ã¶ã¼ã使ã£ã¦ããã®ãåå ããããã¾ããããããããã¼ãã¼ã«ã§ã³ã³ã½ã¼ã«ãè¦ãã¨ã¨ã©ã¼ãåºã¦ããããããã¾ãããåºæ¬çã«ã¯ãµãã¼ãã¯ãã¾ãããæªããããã»ï½ã»ï¼
- ã½ã¼ã¹
- 解説
åºæ¬çã«ã¯ã³ã³ãã¥ã¼ã¿ã¼ã°ã©ãã£ãã¯ã¹ãã·ãã¥ã¬ã¼ã·ã§ã³åéã§ã®åºç¤æè¡ã®1ã¤ããã¼ãã£ã¯ã«ã·ã¹ãã ãJavaScriptã§æ§ç¯ãã表示ç»é¢å ããã¯ã»ã«ï¼â ãã£ã¹ãã¬ã¤ã®ãã¯ã»ã«ï¼ã«åå²ããã¼ãã£ã¯ã«ã«åºã¥ãã¦ãã¯ã»ã«ã®è²ä»ããè¡ãªã£ã¦ãã¾ãããªããåæç¶æ ã®è¨å®ã§ã¯ãã¼ãã£ã¯ã«ãç´æ¥æç»ãããäºã¯ããã¾ããã
ãã¼ãã£ã¯ã«ã¯åç´ãªãªã¤ã©ã¼æ³ã«ãããã¥ã¼ãã³ã®éåæ¹ç¨å¼ã«ãããéåã®å½±é¿ãåãã¤ã¤ãé度ãä½ç½®ãå¤åããã¾ããã¾ãããã¼ãã£ã¯ã«ã¯è²ã¨åå¾ãæã£ã¦ãã¾ãã
ãã¯ã»ã«ï¼ãã¤ããæ§ã§ãããã£ã¹ãã¬ã¤ã®ãã¯ã»ã«ã§ã¯ããã¾ããï¼ã¯ç»é¢ãæå®ã®å解è½ã§åå²ããé åã§ç»é¢ãã¿ã¤ã«ç¶ã«åãå°½ããã¦ãã¾ããããã¦ãã¯ã»ã«ã¯æ¯ãã¬ã¼ã ãéåãããã¼ãã£ã¯ã«ã¨ã®è·é¢ããè²ãæ´æ°ãã¦ãã¾ãã
ã½ã¼ã¹ã³ã¼ã: https://github.com/usagi/cpp_advent_calendar_2012_4th/blob/gh-pages/HTML5/main.html
HTMLãã¡ã¤ã«ã«å®ç¾©ãããHTMLã¿ã°ã¯DOCTYPE宣è¨ã®ä»ã¯ meta ã style ã script ã®ã¿ã§ãããã©ã¦ã¶ã¼ã«èªã¿è¾¼ã¾ããã¨ã
window.addEventListener('load', main);
ãå®ç¾©ããããã¼ã¸ãã¼ãå¾ã« main é¢æ°ãå¼ã°ãã¾ããããã°ã©ã å ¨ä½ã®ä»çµã¿ã¨ãã¦ã¯ã config ãå種è¨å®ãã¾ã¨ããå®è¡æã®ä¸æé å㯠tmp ã«æ´çãããæ§ã«ãªã£ã¦ãã¾ããä¸é¨ã® config ã¯ãããããã¼ãã¼ã«ã®ã³ã³ã½ã¼ã«ããå¤ãå¤ããäºã§å³åº§ã«é©ç¨ã§ãã¾ããä¾ãã°ã
conf.force_gravity = false;
ã¨ãè©ä¾¡ããã¨éåãç¡ããªãã¾ããã¾ãã
conf.present_particles = true;
ã¨ãè©ä¾¡ããã¨ãã¼ãã£ã¯ã«ã®ä½ç½®ã¨åå¾ã¨è²ãåããæ§ã«æç»ãããæ§ã«ãªãã¾ãã
ãã詳細ã«ã¤ãã¦ã¯ã½ã¼ã¹ã³ã¼ããã覧ä¸ããã
â¡ Native-client ã®æºåã¨éå½¢
- æºå
Native-clientã®éçºç°å¢å°å ¥ã«ã¤ãã¦ã¯ãopenSUSE-12.2にnative-client開発環境を入れる - C++ ときどき ごはん、わりとてぃーぶれいく☆ã«æ¸ããæ§ã«ã¨ã¦ãç°¡åãã¤Linuxãã£ã¹ããªãã¥ã¼ã¿ã¼ãOSä»å±ã®ããã±ã¼ã¸ç®¡çã·ã¹ãã ã«ä¾åãã¾ãããããã£ã¨å ¥ãã¡ããã¾ããããç°å¢å¤æ° NACL_SDK_ROOT ãéãã¦ç½®ãäºããå¿ããªãã
- éå½¢
Native-clientã®éçºç°å¢ãæ´ããã¨ãåå¥ã®ãã¼ã¸ã§ã³ã®Pepper SDKã¨åæã«ãã®ä¸ã«examplesãå°å ¥ããã¾ãããç´æã®ããã¦ã¯ã¢ã«ããå ¥ã£ã¦ãã¾ãã®ã§ãã¾ãã¯ãã®è¾ºããã¡ããã¡ãã試ããããå ã«ããã¨è¯ãããããã¾ããã
ããããSDKä»å±ã®exmapleã«å ¥ã£ã¦ããããã¸ã§ã¯ãã§ã¯Makefileãåé·ãªå²ã«ä½æ©è½ã ã£ãããglibcãã¼ã«ãã§ã¤ã³ã使ãéã® .nmf å®ç¾©ã¯æä½æ¥ã§æ¸ãå¿ è¦ããããªã©ä¸ä¾¿ã§ãã
ã¨ãè¨ã訳ã§éå½¢ãç¨æãã¦ã¿ã¾ããã
æ©è½é¢ã§ã¯éå½¢ã¨ãã¦ã¾ã£ãã足ãã¦ããªãé¨åã調æ´éä¸ã®é¨åãå¤ãã®ã§ããããã£ã¬ã¯ããªã¼æ§é ãMakefileã¯å½¹ç«ã¤ããããã¾ãããç¹ã«ããã®Makefileã§ã¯çæãã.nexeï¼Native-clientã®é å¸ç¨ã®å®è¡ãã¡ã¤ã«ã§ãï¼ãåºã«ä¾åããã©ã¤ãã©ãªã¼ã® .so ã®å®ç¾©ãªã©é¢å㪠.nmf ã®ä½æãå®å ¨ã«èªååãã¦ãã¾ãã
ã¾ããJavaScriptã¨ã®ã¡ãã»ã¼ã¸ã³ã°å¨ããªã©ãmain.jsã«å®è£ æ¸ã¿ã®ç¶æ ã¨ãªã£ã¦ãã¾ãã®ã§ããã辺ãNative-clientãå§ãã¦ã試ããããããªããããªæã®éå½¢ã¨ãã¦ã¯ä¾¿å©ããããã¾ããï¼main.jsã®wrp.nacl.prototype.on_message/post_messageï¼ããã®main.jsã238è¡ç®ã®addEventListener('load',main)ã«ããmainé¢æ°ãéå§ããå®è£ ã«ãªã£ã¦ãã¾ããã³ã³ã½ã¼ã«ã¸ã®ãã°åºåãããã©ã«ãæå¹ã§ãã®ã§ããã®éå½¢ã¯.nexeããæ¨æºåºåã¸ã®ãã°ãå¿è«ãJavaScriptã¬ãã«ã§ã以ä¸ã®ãããªãã°ããã©ã¦ã¶ã¼ã®JavaScriptã³ã³ã½ã¼ã«ã«åãåºããã¾ãããã¹ãããããã°ã®ãä¾ã«ã©ããã
ãã®JavaScriptå´ã®ãã°åºåã¯å½ç¶è² è·ãæããã¾ãã®ã§ãmain.jsã®åé 辺ãã§ã®
wrp.etc.log_off = true
ã¨ããããã«ç¶ãwrp.logãªãã¸ã§ã¯ãã®å®è£ ãåèã«é©å®ã«åãæ¿ãã¦ä½¿ç¨ãã¦ä¸ããã
ãã®ã»ããéå½¢ã«ã¯x86_64çã¨i686çã®ãã«ãããããã¼ã«ã«ãã¹ããµã¤ãä½æããã¼ã«ã«ãã¹ããµã¤ããdarkhttpdã§ç«ã¡ä¸ãããããã©ã¦ã¶ã¼ãç«ã¡ä¸ãããããæ©è½ãä¸å¿ç¨åº¦ã§ããä»ãã¦ãã¾ãã
% make % make _site
ããã§Native-clientå®è¡ãã¡ã¤ã«ã®ãã«ããããã¼ã«ã«ãã¹ãç¨ã®ãã£ã¬ã¯ããªã¼æ§é ãä½æã§ãã¾ãã
darkhttpdã使ããå ´åã¯ã
% make && make test-server
ã¨ãããã¨ãã¹ããµã¼ãã¼ãèµ·åãã¾ãããã°æµããåé¢ã®é½åããã©ã¢ã°ã©ã¦ã³ãã§é常åä½ããã¾ããã¯ã©ã¤ã¢ã³ãã§ã®ãã¹ããµã¼ãã¼ã¸ã®æ¥ç¶ã¯ã
% make test-client
ã¨ãå¥ç«¯æ«ãéãã¦ããå®è¡ããè¨è¨ã§ããããã¯ãChromiumãã©ã¦ã¶ã¼ãNative-clientã®æ¨æºåºååã³æ¨æºã¨ã©ã¼åºåã«Linuxã§ããã°å¯¾å¿ãã¦ãããï¼Windowsã§ã¯cmd.exeããChromiumãèµ·åãã¦ãä½ãåºã¾ããã¯ãã§ãï¼çºããã®ãã°åãã«ä¾¿å©ã¨ããäºã§å¥ç«¯æ«ãåæã¨ããä»æ§ã«ãã¦ããã¾ãã
å®éããã°åãã®ãµã³ãã«ã¨ãã¦ã include/wrp/log.hxx ãªãã¡ããã¡ããã¨ä»¥åæ¸ãã¦ãã£ããã°åãã¯ã©ã¹ããã®éå½¢ã®ããã¸ã§ã¯ãã§ã¯å©ç¨ããæ§ã«ãªã£ã¦ãã¾ãã®ã§ãããã«æ¨æºåºåçã®åä½ã確èªã§ããç¶æ ã«ãªã£ã¦ãã¾ãã
ã½ã¼ã¹ã³ã¼ã以å¤ã®çæç©ã.nexeã.nmfã_siteãªã©ãåé¤ãããå ´åã¯ã
% make clean
ã¨ãã¾ãã
ãã¦ãNative-clientã®åä½ããä»çµã¿ã«ã¤ãã¦ã¯ã
HTMLããã¼ããããâHTMLã®embedã«ãã対å¿ãã©ã¦ã¶ã¼ï¼Chromiumï¼ã§ããã°Native-clientãèµ·åã
â.nmfãèªã¿è¾¼ã¿Native-clientå®è¡ãã¡ã¤ã«.nexeããã¼ãããâ.nmfããå¿ è¦ãªã.soããã¼ããâpp::CreateModuleãå®è¡ããpp::Moduleï¼ããæ´¾çããèªåã®ã¢ããªã®ã¯ã©ã¹ï¼ãä½ããâpp::Module::CreateInstanceãå®è¡ããpp::Instanceï¼ããæ´¾çããèªåã®ã¢ããªã®ã¯ã©ã¹ï¼ãä½æããâã¤ã³ã¹ã¿ã³ã¹ãåä½ãã
ã¨ããæµãã§ããåä½ä¸ã®pp::Instanceã¯å¿ è¦ãªãã°HTMLãã¼ã¸ã®JavaScriptã¨ã®ç¸äºã®ã¡ãã»ã¼ã¸ã³ã°ãåãã¦ãã¾ãã®ã§ãããã ãã§ãå²ã¨ã¢ã¬ã³ã¬ã§ãã¾ããä»ã«AudioãOpenGL ES 2.0ãæ±ããã¨ãã§ãã¾ãããããã¯ã¾ãå¥ã®æ©ä¼ã«ã
åä½ã®æµãã¯å®éã®ãã¼ã«ã«ãã¹ããµã¤ãã¾ã§ãã«ããã¦ããããã®å 容ç©ã§è¿½ããããæ¹ãè¯ãã§ããããï¼.nmfã¯.nexeããçæããçºãéå½¢ã®ã½ã¼ã¹ã³ã¼ãä¸ã«ã¯å«ã¾ãã¦ããªããªã©ã®é½åãããã¾ãããï¼
ãªããéå½¢ã§ã¯ã¢ããªåã app_name ã§ä½æãã¦ããã¾ãã®ã§ãããã辺ã¯ä½¿ãéã«é©å®ã«æ¸ãæãã¦ä¸ãããã¾ãã bland_name ãã½ã¼ã¹ã³ã¼ãä¸ã§åå空éã®å®ç¾©ã«ä½¿ã£ã¦ãã¾ãã®ã§ããã¡ããåæ§ã«æ¸ãæãã¦ä½¿ç¨ãã¦ä¸ãããæ¸ãæãã¯find|sedã¨find|tr|mvã«æ £ãã¦å± ãã°ããã§ãè¯ãã®ã§ããããããªæã¯msrpã使ãã¨æ¥½ã§ããã
% msrp app_name cppac2012_4th . ( changed) ./main.js ( changed) ./Makefile ( changed) ./main.html ( changed) ./src.cxx/common.hxx (renaming f) ./src.cxx/app_name-client-nacl.cxx => ./src.cxx/cppac2012_4th-client-nacl.cxx trying: plain rename % msrp bland_name WonderRabbitProject . ( changed) ./src.cxx/common.hxx
ãããªå ·åã§ãã¡ã¤ã«ã®ä¸èº«ã®æååããã¡ã¤ã«åãä¸æ°ã«ç½®æã§ãã¾ããæ£è¦è¡¨ç¾ã«ã対å¿ãã¦ããã®ã§msrpã使ããã¨ä½ãã¨ä¾¿å©ã§ãã
⢠Native-client ã«ããâ ã¸ã®C++ã±ãã¼æ³¨å ¥
- ãã¢
ï¼â»Chromium 14以ä¸ã§Native-clientã®ãã¢ãåä½ããªãå ´åãã使ãã®Chromeã® chrome://flags/ ãããï¼éè¯ï¼Native-clientã®å®è¡ã許å¯ããå¿ è¦ãããããããã¾ãããï¼
- ã½ã¼ã¹
- 解説
ç§ã®ç°å¢ã§ã¯ã¹ã³ã¢ã874ã«ãªãã¾ãã^-^
å ã®HTML5(pure)çã«æ¯ã¹ãã¨å¡ã1.88åããªãããã«åãã®ã§ãè¦ã¦ãã¦ãããããã¦æ åç³»ã®ãã¢ã¨ãã¦è¦ããâ¦ããªãâ¦ãã¼ã^^;
ãã¡ãã¯ããã¼ãã£ã¯ã«ã·ã¹ãã ã¯Native-clientå´ã«å®è£ ãã
- JavaScript â Native-Client : 次㮠pixels ãè¨ç®ãã¦ããããªã¾ãï¼
- Native-Client : ãã¼ãã£ã¯ã«ã·ã¹ãã ã dt [sec] ã ãé²ã pixels ã決å®
- Native-Client â JavaScript : ã§ãããã ã£[ââââ¦(ãã¯ã»ã«ã®è²æ å ±ç¾¤)]
- JavaScript : pixels ã canvas ã«æç»ãããã¹ï¼
ãã® 1-2-3-4 ãJavaScriptå´ã®ã¡ã¤ã³ã«ã¼ãã§åãã¦ãã¾ãã
ã¡ãªã¿ã«ãJavaScriptã§ã¡ã¤ã³ã«ã¼ããåãéã¯ããã¸ã¼ã«ã¼ãã¯è«å¤ã¨ãã¦ãsetInterval/setTimeoutã使ãã¾ããã©ã¡ããè¯ããã¯è² è·æ¬¡ç¬¬ã§ãå®ã¯å ã«å®è£ ããHTML5(pure)çã§ã conf.main_loop_timeout ã true/false 㧠setInterval/setTimeout ãåãæ¿ãã¦å®è¡ããæ§ã«ä»è¾¼ãã§ããã¾ãã
é常㯠setInterval ãç¨ããæ¹ãã«ã¼ãå¦çã®çºã®è² è·ã軽ããªãããã§ãããããã setInterval ã§æå®ããå¼ã³åºãééã«å¯¾ãã¦éè² è·ãªå¦çã«ã¤ãã¦ã¯ã setTimeout(arguments.callee, 1) ãªã©ãã¦åããæ¹ãã©ããªã«éãããã¨ãä¸å¿ã¯ã³ã¼ã«ã¹ã¿ãã¯çã«ãå¥å ¨ãªç¶æ ãç¶æåºæ¥ãçºã setInterval ã§åããããã«ã¼ãå¦çã«ããè² è·ã¯è»½ãæ¸ãããã§ããï¼ãã®å¤æã¯Chromium 24ã§ã«ã¼ããåãã¦è¡ã£ãå®æ§çãªè©ä¾¡ã«ããã¾ããï¼
ä»å㯠Native-client ã®ã³ã¼ãå 㧠pixels ã®ç¢ºå®ã¾ã§è¡ãªã£ã¦ãã¾ããä¸è¨å·¥ç¨ã® 3 ã«ã¦çµæã JavaScript ã¸ã¡ãã»ã¼ã¸ã³ã°ãã¾ããããå®éã«å®ç¨çãªé¢ç½ãã¢ããªã¨ãªãã¨ãJavaScriptããåãåãå¤ã«å¿ãã¦Native-clientããã®å¿çï¼åºåï¼ãå¤åããããªã©ãããå ´åãããããããã¾ãããããããä»ã®ã¨ãã JavaScript â Native-client ã®ã¡ãã»ã¼ã¸ã³ã°ã«ã¯æªå®è£ æ©è½ãããã
[6:6:1204/185322:ERROR:message_channel.cc(129)] Not implemented reached in PP_Var webkit::ppapi::<unnamed>::CopyPPVar(const PP_Var&)
ãªãã¦ã¨ã©ã¼ãåãããããäºãããã¾ã^^; JavaScriptå´ããNative-clientã«å¯¾ãã¦postMessageããéã«ã¯ãã¹ã«ã©ã¼ã£ã½ãå¤ã¾ãã¯æååããä»æ§ã¨ãã¦ãå®è£ ããã¦ããããããã·ã¥ãªãã¸ã§ã¯ã { ... } ãå é¨çã¯å²ã¨ç価ãªé åãªãã¸ã§ã¯ã [ ... ] ãNative-clientå´ã¸ãã¹ãããã¨çºçãã¦ãã¾ãã¾ãããã®ããããããããã¼ã¿ã¯ JSON.stringify ã§JSONåãã¤ã¾ãæååã«ã·ãªã¢ã©ã¤ãºãã¦Native-clientã¸ãã¹ããããªã©ã®æéãå¿ è¦ã¨ãªãã¾ãã
éã«ãä»åã®æ§ã«ãNative-client â JavaScript ã®ã¡ãã»ã¼ã¸ã³ã°ã§ã¯ <ppapi/var_array_buffer>ã§å®ç¾©ããã¦ãã pp::VarArrayBuffer ãéãä»ãããã¾ããä»å㯠pixels = [pixel,pixel,pixel,...] ã®æ§ãªã¤ã¡ã¼ã¸ã®é
åãªãã¸ã§ã¯ããNative-clientããJavaScriptã¸éãä»ãã¦å±
ã¾ãã
ã¨ãããããNative-client â JavaScript ã®ã¡ãã»ã¼ã¸ã³ã°ã¯ JSON ã§ãã¯ã»ã«ç¾¤ã®ã«ã©ã¼ãã¼ã¿ãéãä»ããå®è£ ã«ãªã£ã¦ãã¾ãã
Conclusion
ãã®ãã¿ã¬ã¨ããããã¡ãã¡ãªå®è£ ç¶æ ã§ãNative-clientã®JavaScriptã«å¯¾ããåªä½æ§ãååã«ä¼ãã£ãï¼ãã¨ã«ãã¦ãã ããã»ï½ã»ï¼ãã¨æãã¾ããã¾ããä»åã¯Native-clientã¨JavaScriptã®ã¡ãã»ã¼ã¸ã³ã°ãï¼ç¡çç¢çï¼ä½¿ããå調çã«åä½ãããäºã«ãå¯è½æ§ãè¦ãã ããæ¹ãããã£ããã£ãããããã¾ããã
ã¾ããå°ã é¢åãªglibcãã¼ã«ãã§ã¤ã³æã®ã©ã¤ãã©ãªã¼ã®å梱ã.nmfã®æºåãªã©ãä»åé å¸ãããæ軽Makefileä»ãã®Native-clientããã¸ã§ã¯ãéå½¢ã使ã£ã¦é ããã°ã»ã¼è¦å´ããäºãç¡ãã¨æãã¾ããã¾ã ã»ãã®ãããç¨åº¦ããNative-clientã®ã±ãã¼ã使ãã¦å± ã¾ããããããããä»åã®ãã¢ã®åä½æ¹å¼ã§ã¯æ½å¨è½åãæ´»ãããç¶æ ã§ã¯ããã¾ããã§ãããããããªä¸ã§ãä½ããããä¼ãã§ããããã¯ãªã¹ãã¹ã¸ã®ã¢ããã³ã«ã¬ã³ãã¼ã¨ãã¦ãæãã¯ãã³ããã¼ã¯ã¢ããªã¨ãã¦å°ãã§ã楽ããã§é ãããªã幸ãã§ãã
å¼ãç¶ããããã°ã§ã¯Native-clientãæ±ãç¶ãããã¨æãã¾ãã
ã»ï½ã»ï¼
å®ã¯Native-clientã±ãã¼ã©ã®æ¹ã®ã½ã¼ã¹ã¯ã¨ã¦ããããªããã©è¦ããããªããï¼ï¼ ãªç¶æ ã§ããå¾¹å¤ç´æã§ãªãã¨ãåãç¶æ ã§ãããã¤ããã«éããªãã¨ãã§ããªãç¶æ ã§ããä½è£ãè¦ã¦ã©ãã«ããããããªã¼ã¨æãã¾ãã
ã¾ããä»åã¯ä¸éå端ã«HTML5/JavaScriptã¨ã¡ãã»ã¼ã¸ã³ã°é£æºãã¦ãã¾ãããããããNative-clientã«ãå¼·åãªæç»APIãããã¾ãããããã¡ãã®ã¬ããªNaClã³ã¼ããæéãåã次第è¼ããããªã¼ã¨æãã¾ãã
ï¼ï½ï¼ï¼
Native-client ã«ã¤ãã¦ä¸è¨ã ãã°ãµãªã¨è¨ãããã¨ããã°ããã¼ãããã« GCC-4.4 ãã¼ã¹ã¨ãåæ¥ãã¦ã¼ã¼ã¼ã¼ã¼ï¼ï¼ ã£ã¦äºãããããªï¼
ããããâ¦Eigen使ãããã¨æã£ããã ãã©ãã©ããã³ã³ãã¤ã«ãã.nexeãåä½ãã¹ããã¦ã¿ããä¾å¤è½ã¡ããã£ã½ãç¶æ ã§ãçµå±ä½¿ãã®ãæ¢ãã¦ç°¡åãªvector2ã ã¨ãcolorã ã¨ãããã£ã¨å®ç¾©ãã¦ä½¿ã£ã¦ããããã®ã¸ããå¾ã§ãã¡ãã¨èª¿æ»ããããªã¼ã
ã¡ãªã¿ã«ãä»åã®ä¼ç»ãå®ã¯ãã®ä¼ç»ã®åã«WebRTCã¨ã«ã¡ã©æ åå¦çãä¼ãã ã®ã ãã©ãã©ããLinuxã®Chromiumã¯WebRTCã®ã«ã¡ã©æ©è½ãæªå®è£ ãããã¦ã(´ã»Ïã»ï½) libusbåããªãããªã¼ã¨ãç»çããããã®ã®ãç´ ç´ã«è«¦ãããªã©ãã¦ããã®ã§ãããWebRTCãLinuxçã§ãå®è£ ããããéã¼ããã¨æã£ã¦ããã
Future
æéãåã次第ãå¹´æ«ã«ããã¦é次ããã¡ãã£ã¨ãã®ãã¿ãå¼ããããã¨æã£ã¦ãã¾ãã
References
- HTML5
- Native-client
- Meta-ball
- Color space conversion
- Tool
- Compiler
Special Thanks
Environments
å·çæã«ç¨ããç°å¢ã®è«¸å ãæ²è¼ãã¾ãã
Hardwares
Softwares
- OS
- Web Browser
- Chromium 24.0.1290.0 (160607)
- Pepper SDK (ânative-client SDK)
- Boost C++ Libraries
- libboost 1.49
- Eigen
eigen 3.1.2