After care: C++ Advent Calendar 2012 / day 4th : Native-client vs. HTML5 ; C++ in the web-client-world!
å æ¥ã®C++ Advent Calendar 2012 / day 4th : Native-client vs. HTML5 ; C++ in the web-client-world! - C++ ときどき ごはん、わりとてぃーぶれいく☆ã®ç¶ãããã®ï¼ã§ãã
ã¡ãã£ã¨ã ããªãã¡ã¯ã¿ãªã³ã°ããããC++ã¨JSã®ã¤ã³ã¿ã¼ãã§ã¼ã¹é¨åã®ãã£ã¤ãæãã©ãã«ããããªã©ãã¾ããã
ç¹ã«æå³ãã¦å±
ã¾ããã§ããããã©ãããSCOREãä¸æããæ§ã§ã^-^
ï¼ç²å群ãç»ç´ 群ã®æ´æ°ããªãã¡ã¯ã¿ãªã³ã°ã«ä¼´ãå°ã
ã³ã³ãã¯ãï¼ã¹ãã¼ãã«ãªã£ãå½±é¿ããªãï¼
主ãªå¤æ´ç¹
- ãã¼ãã£ã¯ã«ã·ã¹ãã ã®å®ç¾©ãnative-clientã®ã¤ã³ã¹ã¿ã³ã¹å®ç¾©ç¨ã®instance.hxxããparticle_system.hxxã¸åé¢
- JS-->C++ã®ã¤ã³ã¿ã¼ãã§ã¼ã¹ããã£ã¤ãæååã³ãã³ãããJSONã«å¤æ´
- C++å´ã®JSONãã¼ãµã¼ã¯kazuho/picojson · GitHubãJSå´ã§ã¯JSON.stringifyãã¦ããã
- particle_systemå ã®particleåã³pixelã®ç¶æ æ´æ°ãparticle/pixelããããã®å é¨ã§ã¯ãªããparticle_systemããè¡ãæ§ã«å¤æ´ãparticle/pixelã¯particle_systemã«å¯¾ãfriendã
- ã¹ã¯ãªã¼ã³ã¨æç»ç©ºéã®å解è½ã®ä»»æè¨å®ãå®è£
ãä¸é¨ãã¸ãã¯ãã³ãã¼ã¨ãªã£ã¦ããå解è½ã«é¢ãã決ãæã¡ã®å¤ãä»»æã«è¨å®å¯è½ã«ãªãã¾ããã
- JSå´ã«debug_command.change_resolutionãªãé¢æ°ãå®è£ ããã®ã§ããã©ã¦ã¶ã¼ã®éçºè ãã¼ã«ã®JSã³ã³ã½ã¼ã«ãã debug_command.change_resolution(640,480,64,48) ãè©ä¾¡ããã¨ãã¹ã¯ãªã¼ã³å解è½VGAãç»ç´ å解è½64x48(ç»ç´ ãµã¤ãº10x10)ã«åãæ¿ãããªã©å¯è½ã«ãªãã¾ããã
ãã®å¾ã¯
次ã¯ãã¼ãã£ã¯ã«ã·ã¹ãã ã®å¹çåããªã
ã¡ãªã¿ã«ãå®ã¯å½åHTML5(pure)çãæ¸ã段éã§é常ã«éããã³ããã¼ã¯ã«ãªãäºã¯æ³åã§ãã¾ãã®ã§ããå ¨ã¦ã®ç»ç´ ãå ¨ã¦ã®ç²åããã®å½±é¿ãè¨ç®ãããã®ã§ã¯ãªãããç²åããä¸å®è·é¢ã®ç»ç´ ã«ã®ã¿ç²åã®å½±é¿ãè¨ç®ããããªãå®è£ ã«ãã¦ãã¾ããã
ä¾ãã°ãåè ã®å ´åã¯ãããç²åã(x,y)ã«åå¨ããæãç»ç´ 空éã®å解è½ã160x90ã§ããã°14.4kåã®ç»ç´ ã«å¯¾ãã¦ç²åããã®è·é¢ã«åºã¥ããè²(å )ã®å½±é¿å ·åãè¨ç®ããäºã«ãªãã¾ãããå¾è ã®å ´åã«ã¯ç²åã®åå¾rã¾ãã¯rã«å½±é¿éãå¢æ¸ãã調æ´ç¨ã®å®æ°ãæããr'ãç¨æããä»®ã«ä¹ã40ç»ç´ åç¨åº¦ã®è·é¢ã§ããã°ãÏr'r'=3.14â¦Ã40Ã40â5,027åã®ç»ç´ ã ãã«ç²åã®å½±é¿ãè¨ç®ããã°è¯ãäºã«ãªããè² è·ã大ããä¸ãããã¾ãã
å®éã«ã¯ãç»ç´ 群ã¯ç¹å¥ãªãã¼ã¿æ§é ãæãããªãéããæç»ç³»APIã¨ã®æ´åæ§ããããé常ã¯é¢æ£çãª2次å ã®ã¦ã¼ã¯ãªãã空é(X軸ã¨Y軸ã«åè§ãåç®ç¶ã«èãã)ã§ç®¡çãã¦ãã¾ããããç²åã®åº§æ¨ã®å¨å²ãåå½¢ã«åæããäºã¯å°ãé£ãããå ãã¯ç²åã®å½±é¿ç¯å²ãå¤æ¥ããç©å½¢é åãåãåºããåæã³ã¹ãã¨ç»ç´ ã®å¦çã³ã¹ãã天秤ã«æãã¦ãç»ç´ ã¨ç²åã®è·é¢ãè¨ç®ããããæãã¯ç¶ºéºãªåå½¢ã§ã¯ãªãç©å½¢é åããã®ã¾ã¾ç²åã®å½±é¿ç¯å²ã®è¨ç®å¯¾è±¡ã¨ãã¦å¦çãè¡ãã¾ãã
ããããä»åå®è£ ãããã¼ãã£ã¯ã«ã·ã¹ãã ã§ã¯ãçµå±ã¯ç»ç´ ã®å ãå ·åã®æ±ºå®ã«å ¨ã¦ã®ç²åã¨ã®ãããã°ç·å½ãã®è¨ç®ãè¡ãªã£ã¦ãã¾ããå ãå ·åã®ã¢ãã«ãã{(I)ntensity}={c_(l)uminance}/({(d)istance}+1)ãä½ãI:å ãã®å¼·ããl:å ãå ·å調æ´ç¨ã®å®æ°ãd:ç»ç´ ã«å½±é¿ãåã¼ããã¨ããç²åã¾ã§ã®è·é¢ãã¨ãã¤ã¤ãlã大ããã«ããå ã溢ãã¤ã¤ãé£ã³åãç²åæãããç©ããã¦ç¶ºéºãªâ¦ã¨ããã£ã¦ãããã¡ã«ããã³ããã¼ã¯ã ãç·å½ãã§è¨ç®ããæ¹ã綺éºãªçµµãç°¡åã«åºããè¯ãããªãã¨ããããªããªã§ç·å½ãã®å®è£ ã«ãªã£ã¦ãã¾ã^^;
ã¨ãã¾ãããã¯ãã¦ãããç²åããç»ç´ 群ã®åæã§ããã°ä¸è¿°ã®éãã§ããã£ããæ´çãã¦èããã°ç©å½¢é åã®ç»ç´ 群ã®åãæãã¯ç°¡åã«æ³åã§ãã¾ãããã§ã¯éãªãã°ã©ãã§ãããï¼ã¤ã¾ããããç»ç´ ã主ä½ã¨ãªããå¨è¾ºã«ããç²åãåæãããããããã®å½±é¿ãè¨ç®ããã¨ãããªãã
ç²å群ã¯å¿è«åãã«ãã®ç²å群ã®åå¨ããä¸çã®ç©çæ³åã¯é©ç¨ã§ãã¾ããããå®éå®å ¨ã«äºæ¸¬ããããäºåã«è¨ç®ãã¦ããäºãå¯è½ã§ããä¹±æ´ã«çã£ç«¯ããäºåè¨ç®ãã¦ãã¾ã£ã¦ãã¼ã¿ãã¼ã¹åãã¦ããããæãã¯ãªã¤ã©ã¼æ³ãããé«åº¦ãªç²¾å¯ãªè¨ç®ãè¡ãé«ç²¾åº¦ã«äºæ¸¬ããå¿ è¦ããããã§ããããï¼
åæã¯å¯è½ã ãããããã®åº§æ¨ãäºæ¸¬ã§ããªãç²å群ã«ã¤ãã¦ãã座æ¨ã®è¿ãã«å± ãç²åãå¹ççã«æ½åºã§ããæ§ã«å·¥å¤«ãããã¼ã¿æ§é ãããã¾ãã代表ä¾ã¯ä»»æã®ç©å½¢é åã«ç²å群ãåå²ãã¦è¨æ¶ããäºããã¼ã¹ã¨ããç©å½¢é åããã®ããã¯ã¢ãããå¾æã¨ããRectangler-treeãã¾ããã®åãã¼ã¸ã§ã³ã®æ´¾çãã¼ã¿æ§é ãæãã¯å¯¾è±¡ç©ºéã2åå²ãç¹°ãè¿ãã¦ããããã«å«ã¾ããç²å群ãè¨æ¶ãããããã®åå²æ¯çãä»»æã«ã§ããæ§ã«ãããããkd-treeç³»ã®ãã¼ã¿æ§é ãªã©ãã¢ãã«ã«å¿ãã¦ç²å群ã®ãã¼ã¿æ§é ãæé©åãã¦ããæ¹æ³ãããã¾ãã
å®ã¯ãã®å¾ããã®ãã³ããã¼ã¯ç¨ã®ãã¼ãã£ã¯ã«ã·ã¹ãã ãã©ã®ããã«å¹çåãã¦ãã®ã·ãªã¼ãºãé²ãæ§ãã¯ã¾ã èãã¦ãã¾ãã^^; ãã¡ããããã«ãã¹ã¬ããã£ã³ã°ãSIMD(NaClã§åãããªãâ¦)å¨ããªã©ã®å®ç¨çãªåæãã·ã§ã¼ãã¼ã使ã£ã¦ãã¾ããã¼ããå«ããããã¡ãã£ã¨å¹´å ã«ãã®è¨äºã®ç¶ããæ¸ãããã¨æã£ã¦ãã¾ãã
ã§ã¯ã¿ãªãããè¯ããæ£æãã^^ï¼ã