Loading cocao_test_tnl2/tnl2_test_cocoa.xcodeproj/project.pbxproj +42 −0 Original line number Diff line number Diff line Loading @@ -101,7 +101,23 @@ 1DA782FB116058F800FB41C2 /* test_game_render_frame_open_gl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = test_game_render_frame_open_gl.h; path = ../test_tnl2/test_game_render_frame_open_gl.h; sourceTree = SOURCE_ROOT; }; 1DA782FC116058F800FB41C2 /* test_net_interface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = test_net_interface.h; path = ../test_tnl2/test_net_interface.h; sourceTree = SOURCE_ROOT; }; 1DA782FD116058F800FB41C2 /* test_player.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = test_player.h; path = ../test_tnl2/test_player.h; sourceTree = SOURCE_ROOT; }; 1DA8A0A9118FBE5900B11667 /* function_call_record.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = function_call_record.h; path = ../../torque_sockets/core/function_call_record.h; sourceTree = SOURCE_ROOT; }; 1DA8A0AA118FBEBF00B11667 /* system_includes_nacl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = system_includes_nacl.h; path = ../../torque_sockets/core/system_includes_nacl.h; sourceTree = SOURCE_ROOT; }; 1DAD5F7F118E647C008301BF /* jni.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jni.h; path = ../../torque_sockets/plugin_framework/jni.h; sourceTree = SOURCE_ROOT; }; 1DAD5F80118E647C008301BF /* jni_md.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jni_md.h; path = ../../torque_sockets/plugin_framework/jni_md.h; sourceTree = SOURCE_ROOT; }; 1DAD5F81118E647C008301BF /* jri.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jri.h; path = ../../torque_sockets/plugin_framework/jri.h; sourceTree = SOURCE_ROOT; }; 1DAD5F82118E647C008301BF /* jri_md.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jri_md.h; path = ../../torque_sockets/plugin_framework/jri_md.h; sourceTree = SOURCE_ROOT; }; 1DAD5F83118E647C008301BF /* jritypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jritypes.h; path = ../../torque_sockets/plugin_framework/jritypes.h; sourceTree = SOURCE_ROOT; }; 1DAD5F84118E647C008301BF /* npapi.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = npapi.h; path = ../../torque_sockets/plugin_framework/npapi.h; sourceTree = SOURCE_ROOT; }; 1DAD5F85118E647C008301BF /* npruntime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = npruntime.h; path = ../../torque_sockets/plugin_framework/npruntime.h; sourceTree = SOURCE_ROOT; }; 1DAD5F86118E647C008301BF /* nptypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = nptypes.h; path = ../../torque_sockets/plugin_framework/nptypes.h; sourceTree = SOURCE_ROOT; }; 1DAD5F87118E647C008301BF /* npupp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = npupp.h; path = ../../torque_sockets/plugin_framework/npupp.h; sourceTree = SOURCE_ROOT; }; 1DAD5F88118E647C008301BF /* plugin_framework.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = plugin_framework.h; path = ../../torque_sockets/plugin_framework/plugin_framework.h; sourceTree = SOURCE_ROOT; }; 1DAD5F89118E647C008301BF /* prcpucfg_unix.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = prcpucfg_unix.h; path = ../../torque_sockets/plugin_framework/prcpucfg_unix.h; sourceTree = SOURCE_ROOT; }; 1DAD5F8A118E647C008301BF /* prcpucfg_win32.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = prcpucfg_win32.h; path = ../../torque_sockets/plugin_framework/prcpucfg_win32.h; sourceTree = SOURCE_ROOT; }; 1DAD5F8B118E647C008301BF /* prtypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = prtypes.h; path = ../../torque_sockets/plugin_framework/prtypes.h; sourceTree = SOURCE_ROOT; }; 1DDD58150DA1D0A300B32029 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainMenu.xib; sourceTree = "<group>"; }; 1DF3DCCB117A822E008F7A78 /* chat_example.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = chat_example.html; path = ../../torque_sockets/products/TorqueSocketsPlugin/chat_example.html; sourceTree = SOURCE_ROOT; }; 29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; }; 29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; }; 29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; }; Loading Loading @@ -166,6 +182,7 @@ 1D3822211153D07C009D94C5 /* core */ = { isa = PBXGroup; children = ( 1DA8A0A9118FBE5900B11667 /* function_call_record.h */, 1D3822241153D0A7009D94C5 /* algorithm_templates.h */, 1D3822251153D0A7009D94C5 /* array.h */, 1D3822261153D0A7009D94C5 /* assert.h */, Loading Loading @@ -199,6 +216,7 @@ 1D3822421153D0A7009D94C5 /* string.h */, 1D3822431153D0A7009D94C5 /* system_includes_linux.h */, 1D3822441153D0A7009D94C5 /* system_includes_mac_osx.h */, 1DA8A0AA118FBEBF00B11667 /* system_includes_nacl.h */, 1D3822451153D0A7009D94C5 /* system_includes_win32.h */, 1D3822461153D0A7009D94C5 /* thread.h */, 1D3822471153D0A7009D94C5 /* thread_queue.h */, Loading Loading @@ -249,11 +267,33 @@ name = tnl2; sourceTree = "<group>"; }; 1DAD5F7E118E645E008301BF /* plugin_framework */ = { isa = PBXGroup; children = ( 1DAD5F7F118E647C008301BF /* jni.h */, 1DAD5F80118E647C008301BF /* jni_md.h */, 1DAD5F81118E647C008301BF /* jri.h */, 1DAD5F82118E647C008301BF /* jri_md.h */, 1DAD5F83118E647C008301BF /* jritypes.h */, 1DAD5F84118E647C008301BF /* npapi.h */, 1DAD5F85118E647C008301BF /* npruntime.h */, 1DAD5F86118E647C008301BF /* nptypes.h */, 1DAD5F87118E647C008301BF /* npupp.h */, 1DAD5F88118E647C008301BF /* plugin_framework.h */, 1DAD5F89118E647C008301BF /* prcpucfg_unix.h */, 1DAD5F8A118E647C008301BF /* prcpucfg_win32.h */, 1DAD5F8B118E647C008301BF /* prtypes.h */, ); name = plugin_framework; sourceTree = "<group>"; }; 29B97314FDCFA39411CA2CEA /* tnl2_test_cocoa */ = { isa = PBXGroup; children = ( 1DAD5F7E118E645E008301BF /* plugin_framework */, 1D38227A1153D2B5009D94C5 /* libtommath.a */, 1D3822781153D2A1009D94C5 /* libtomcrypt.a */, 1DF3DCCB117A822E008F7A78 /* chat_example.html */, 1D3822211153D07C009D94C5 /* core */, 1D3822221153D082009D94C5 /* torque_sockets */, 1D3822231153D08A009D94C5 /* tnl2 */, Loading Loading @@ -449,6 +489,7 @@ ARCHS = "$(ARCHS_STANDARD_32_BIT)"; GCC_C_LANGUAGE_STANDARD = c99; GCC_OPTIMIZATION_LEVEL = 0; GCC_VERSION = 4.2; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; ONLY_ACTIVE_ARCH = YES; Loading @@ -462,6 +503,7 @@ buildSettings = { ARCHS = "$(ARCHS_STANDARD_32_BIT)"; GCC_C_LANGUAGE_STANDARD = c99; GCC_VERSION = 4.2; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; PREBINDING = NO; Loading nacl_test_tnl2/Makefile +3 −1 Original line number Diff line number Diff line nacl_test_tnl2_release.nexe: nacl_test_tnl2.cc /Users/markf/Work/gg/nativeclient/native_client/src/third_party/nacl_sdk/mac/sdk/nacl-sdk/bin/nacl-g++ nacl_test_tnl2.cc -O2 -I../tnl2 -I../../torque_sockets -I../test_tnl2 -Ilibtomcrypt/src/headers -Ilibtommath -Llibtommath -Llibtomcrypt -ltomcrypt -ltommath -lav -lsrpc -lpthread -lm -o nacl_test_tnl2_release.nexe /Users/markf/Work/gg/nativeclient/native_client/toolchain/mac_x86/sdk/nacl-sdk/bin/nacl-g++ nacl_test_tnl2.cc -O2 -DXP_UNIX -I../../nativeclient -I../tnl2 -I../../torque_sockets -I../test_tnl2 -Ilibtomcrypt/src/headers -Ilibtommath -Llibtommath -Llibtomcrypt -ltomcrypt -ltommath -lm -lgoogle_nacl_imc -lgoogle_nacl_npruntime -lgoogle_nacl_pgl -lgoogle_nacl_gpu -lpthread -lsrpc -o nacl_test_tnl2_release.nexe nacl_test_tnl2/httpd.py 0 → 100755 +97 −0 Original line number Diff line number Diff line #!/usr/bin/python # Copyright 2008, Google Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following disclaimer # in the documentation and/or other materials provided with the # distribution. # * Neither the name of Google Inc. nor the names of its # contributors may be used to endorse or promote products derived from # this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """A tiny web server. This is intended to be used for testing, and only run from within the googleclient/native_client """ import BaseHTTPServer import logging import os import SimpleHTTPServer import SocketServer import sys logging.getLogger().setLevel(logging.INFO) # Using 'localhost' means that we only accept connections # via the loop back interface. SERVER_PORT = 5103 SERVER_HOST = '' # We only run from the native_client directory, so that not too much # is exposed via this HTTP server. Everything in the directory is # served, so there should never be anything potentially sensitive in # the serving directory, especially if the machine might be a # multi-user machine and not all users are trusted. We only serve via # the loopback interface. SAFE_DIR_COMPONENTS = ['native_client'] SAFE_DIR_SUFFIX = apply(os.path.join, SAFE_DIR_COMPONENTS) def SanityCheckDirectory(): if os.getcwd().endswith(SAFE_DIR_SUFFIX): return # endif #logging.error('httpd.py should only be run from the %s', SAFE_DIR_SUFFIX) #logging.error('directory for testing purposes.') #logging.error('We are currently in %s', os.getcwd()) #sys.exit(1) # enddef # the sole purpose of this class is to make the BaseHTTPServer threaded class ThreadedServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer): pass def Run(server_address, server_class=ThreadedServer, handler_class=SimpleHTTPServer.SimpleHTTPRequestHandler): httpd = server_class(server_address, handler_class) logging.info('started server on port %d', httpd.server_address[1]) httpd.serve_forever() # enddef if __name__ == '__main__': SanityCheckDirectory() if len(sys.argv) > 1: Run((SERVER_HOST, int(sys.argv[1]))) else: Run((SERVER_HOST, SERVER_PORT)) # endif # endif nacl_test_tnl2/nacl_test_tnl2.cc +154 −164 Original line number Diff line number Diff line #include <errno.h> #include <stdio.h> //#include <nacl/nacl_av.h> //#include <nacl/nacl_srpc.h> #include <stdlib.h> #include <nacl/nacl_av.h> #include <nacl/nacl_srpc.h> #include <stdio.h> #include <nacl/nacl_npapi.h> #include <nacl/npruntime.h> #include <nacl/npapi_extensions.h> #include <nacl/npupp.h> #include <pgl/pgl.h> #include <GLES2/gl2.h> #include "test_tnl2.h" #include "plugin_framework/plugin_framework.h" #include "third_party/npapi/bindings/npapi_extensions_private.h" // global properties used to setup demo static const int kMaxWindow = 4096; static const int kMaxFrames = 10000000; static int g_window_width = 512; static int g_window_height = 512; static int g_num_frames = 9999; // Simple Surface structure to hold a raster rectangle struct Surface { int width, height, pitch; uint32_t *pixels; Surface(int w, int h) { width = w; height = h; pitch = w; pixels = new uint32_t[width * height]; } ~Surface() { delete[] pixels; } }; const int32_t kCommandBufferSize = 1024 * 1024; NPExtensions* extensions = NULL; // Drawing class holds information and functionality needed to render class DrawingDemo { class tnl_test_instance : public scriptable_object { public: void Display(); void Update(); bool PollEvents(); explicit DrawingDemo(Surface *s); ~DrawingDemo(); private: Surface *surf_; }; core::string bind_address; float _color; int _width, _height; NPDeviceContext3D _context3d; NPDevice* _device3d; PGLContext _pgl_context; tnl_test::test_game *_game; tnl_test_instance() { _color = 0; SOCKADDR addr; // This update loop is run once per frame. // AGG renders straight into the DrawingDemo's surf_ pixel array. void DrawingDemo::Update() { _game = new tnl_test::test_game(true, addr, addr); } // Displays software rendered image on the screen void DrawingDemo::Display() { int r; r = nacl_video_update(surf_->pixels); if (-1 == r) { printf("nacl_video_update() returned %d\n", errno); ~tnl_test_instance() { delete _game; destroy_context(); } } // Polls events and services them. bool DrawingDemo::PollEvents() { NaClMultimediaEvent event; while (0 == nacl_video_poll_event(&event)) { if (event.type == NACL_EVENT_QUIT) { return false; void init(NPMIMEType pluginType, core::int16 argc, char* argn[], char* argv[]) { if (!extensions) { browser->getvalue(get_plugin_instance(), NPNVPepperExtensions, reinterpret_cast<void*>(&extensions)); // CHECK(extensions); } _device3d = extensions->acquireDevice(get_plugin_instance(), NPPepper3DDevice); if (_device3d == NULL) { printf("Failed to acquire 3DDevice\n"); exit(1); } return true; } void set_window(NPWindow *window) { _width = window->width; _height = window->height; // Sets up and initializes DrawingDemo. DrawingDemo::DrawingDemo(Surface *surf) { surf_ = surf; if(!_pgl_context) init_context(); browser->pluginthreadasynccall(get_plugin_instance(), tick_callback, this); } // Frees up resources. DrawingDemo::~DrawingDemo() { void init_context() { // Initialize a 3D context. NPDeviceContext3DConfig config; config.commandBufferSize = kCommandBufferSize; NPError err = _device3d->initializeContext(get_plugin_instance(), &config, &_context3d); if (err != NPERR_NO_ERROR) { printf("Failed to initialize 3D context\n"); exit(1); } // Create a PGL context. _pgl_context = pglCreateContext(get_plugin_instance(), _device3d, &_context3d); // Runs the demo and animate the image for kNumFrames void RunDemo(Surface *surface) { DrawingDemo demo(surface); for (int i = 0; i < g_num_frames; ++i) { demo.Update(); demo.Display(); printf("Frame: %04d\b\b\b\b\b\b\b\b\b\b\b", i); fflush(stdout); if (!demo.PollEvents()) break; } // Initialize the demo GL state. pglMakeCurrent(_pgl_context); pglMakeCurrent(NULL); } void destroy_context() { // Destroy the PGL context. pglDestroyContext(_pgl_context); _pgl_context = NULL; // Initializes a window buffer. Surface* Initialize() { int r; int width; int height; r = nacl_multimedia_init(NACL_SUBSYSTEM_VIDEO | NACL_SUBSYSTEM_EMBED); if (-1 == r) { printf("Multimedia system failed to initialize! errno: %d\n", errno); exit(-1); } // if this call succeeds, use width & height from embedded html r = nacl_multimedia_get_embed_size(&width, &height); if (0 == r) { g_window_width = width; g_window_height = height; } r = nacl_video_init(g_window_width, g_window_height); if (-1 == r) { printf("Video subsystem failed to initialize! errno; %d\n", errno); exit(-1); // Destroy the Device3D context. _device3d->destroyContext(get_plugin_instance(), &_context3d); } Surface *surface = new Surface(g_window_width, g_window_height); return surface; static void tick_callback(void *data) { static_cast<tnl_test_instance *>(data)->tick(); } void tick() { _game->tick(); // Frees window buffer. void Shutdown(Surface *surface) { delete surface; nacl_video_shutdown(); nacl_multimedia_shutdown(); logprintf("hit draw (%d, %d)", _width, _height); if(!pglMakeCurrent(_pgl_context) && pglGetError() == PGL_CONTEXT_LOST) { destroy_context(); init_context(); pglMakeCurrent(_pgl_context); } glViewport(0, 0, _width, _height); _color += 0.05; if(_color > 1) _color = 0; glClearColor(_color, _color, 0, 1); glClear(GL_COLOR_BUFFER_BIT); // If user specified options on cmd line, parse them // here and update global settings as needed. void ParseCmdLineArgs(int argc, char **argv) { // look for cmd line args if (argc > 1) { for (int i = 1; i < argc; i++) { if (argv[i][0] == '-' && argv[i][1] == 'w') { int w = atoi(&argv[i][2]); if ((w > 0) && (w < kMaxWindow)) { g_window_width = w; } } else if (argv[i][0] == '-' && argv[i][1] == 'h') { int h = atoi(&argv[i][2]); if ((h > 0) && (h < kMaxWindow)) { g_window_height = h; } } else if (argv[i][0] == '-' && argv[i][1] == 'f') { int f = atoi(&argv[i][2]); if ((f > 0) && (f < kMaxFrames)) { g_num_frames = f; } } else { printf("nacl_test_tnl2\n"); printf("usage: -w<n> width of window.\n"); printf(" -h<n> height of window.\n"); printf(" -f<n> number of frames.\n"); printf(" --help show this screen.\n"); exit(0); tnl_test::test_game_render_frame_open_gl(0); glFlush(); pglSwapBuffers(); pglMakeCurrent(NULL); browser->pluginthreadasynccall(get_plugin_instance(), tick_callback, this); } core::int16 handle_event(void *event) { return 0; } bool module_ready() { return true; } static void register_class(type_database &db) { tnl_begin_class(db, tnl_test_instance, scriptable_object, true); tnl_method(db, tnl_test_instance, module_ready); tnl_end_class(db); } }; void plugin_initialize() { pglInitialize(); ltc_mp = ltm_desc; tnl_test_instance::register_class(global_type_database()); global_plugin.add_class(get_global_type_record<tnl_test_instance>()); global_plugin.set_plugin_class(get_global_type_record<tnl_test_instance>()); } // Parses cmd line options, initializes surface, runs the demo & shuts down. int main(int argc, char **argv) { ParseCmdLineArgs(argc, argv); Surface *surface = Initialize(); RunDemo(surface); Shutdown(surface); return 0; void plugin_shutdown() { pglTerminate(); } No newline at end of file nacl_test_tnl2/nacl_test_tnl2.html +23 −20 Original line number Diff line number Diff line <HTML> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <HEAD> <TITLE>Torque Network Library 2.0 Test in Native Client</TITLE> <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> <META HTTP-EQUIV="Expires" CONTENT="-1"> <script type="text/javascript"> <!-- var nacl_elt; // Before scripting the loaded module, ensure the Native Client module is loaded. var startupTimeout; var PostLoadInit = function() { if (nacl_elt.__moduleReady == 1) { var PostLoadInit = function() { try { var embed = document.getElementById("embed1"); var ready = embed.module_ready(); clearTimeout(startupTimeout); nacl_elt.focus(); } else { if (nacl_elt.__moduleReady == undefined) { alert('The Native Client plugin was unable to load'); alert('The Native Client plugin is ready'); return; } startupTimeout = setTimeout(PostLoadInit, 100); catch(e) { // do nothing } startupTimeout = setTimeout(PostLoadInit, 100); } // Init is called when the document has completed loading. It downloads the Loading @@ -31,7 +39,7 @@ var Init = function() { PostLoadInit(); } --> </script> </HEAD> Loading @@ -49,13 +57,8 @@ var Init = function() { <a href="http://www.libtnl.com/">http://www.libtnl.com/</a> for more information about the Torque Network Library. </p> <embed id="embed1" src="nacl_test_tnl2.nexe" type="application/x-nacl-srpc" width=512 height=512> <embed id="embed1" src="nacl_test_tnl2_release.nexe" type="application/x-nacl-srpc" width=512 height=512> <br> <script> var embed1 = document.getElementById('embed1'); </script> </BODY> </HTML> Loading
cocao_test_tnl2/tnl2_test_cocoa.xcodeproj/project.pbxproj +42 −0 Original line number Diff line number Diff line Loading @@ -101,7 +101,23 @@ 1DA782FB116058F800FB41C2 /* test_game_render_frame_open_gl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = test_game_render_frame_open_gl.h; path = ../test_tnl2/test_game_render_frame_open_gl.h; sourceTree = SOURCE_ROOT; }; 1DA782FC116058F800FB41C2 /* test_net_interface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = test_net_interface.h; path = ../test_tnl2/test_net_interface.h; sourceTree = SOURCE_ROOT; }; 1DA782FD116058F800FB41C2 /* test_player.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = test_player.h; path = ../test_tnl2/test_player.h; sourceTree = SOURCE_ROOT; }; 1DA8A0A9118FBE5900B11667 /* function_call_record.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = function_call_record.h; path = ../../torque_sockets/core/function_call_record.h; sourceTree = SOURCE_ROOT; }; 1DA8A0AA118FBEBF00B11667 /* system_includes_nacl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = system_includes_nacl.h; path = ../../torque_sockets/core/system_includes_nacl.h; sourceTree = SOURCE_ROOT; }; 1DAD5F7F118E647C008301BF /* jni.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jni.h; path = ../../torque_sockets/plugin_framework/jni.h; sourceTree = SOURCE_ROOT; }; 1DAD5F80118E647C008301BF /* jni_md.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jni_md.h; path = ../../torque_sockets/plugin_framework/jni_md.h; sourceTree = SOURCE_ROOT; }; 1DAD5F81118E647C008301BF /* jri.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jri.h; path = ../../torque_sockets/plugin_framework/jri.h; sourceTree = SOURCE_ROOT; }; 1DAD5F82118E647C008301BF /* jri_md.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jri_md.h; path = ../../torque_sockets/plugin_framework/jri_md.h; sourceTree = SOURCE_ROOT; }; 1DAD5F83118E647C008301BF /* jritypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jritypes.h; path = ../../torque_sockets/plugin_framework/jritypes.h; sourceTree = SOURCE_ROOT; }; 1DAD5F84118E647C008301BF /* npapi.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = npapi.h; path = ../../torque_sockets/plugin_framework/npapi.h; sourceTree = SOURCE_ROOT; }; 1DAD5F85118E647C008301BF /* npruntime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = npruntime.h; path = ../../torque_sockets/plugin_framework/npruntime.h; sourceTree = SOURCE_ROOT; }; 1DAD5F86118E647C008301BF /* nptypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = nptypes.h; path = ../../torque_sockets/plugin_framework/nptypes.h; sourceTree = SOURCE_ROOT; }; 1DAD5F87118E647C008301BF /* npupp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = npupp.h; path = ../../torque_sockets/plugin_framework/npupp.h; sourceTree = SOURCE_ROOT; }; 1DAD5F88118E647C008301BF /* plugin_framework.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = plugin_framework.h; path = ../../torque_sockets/plugin_framework/plugin_framework.h; sourceTree = SOURCE_ROOT; }; 1DAD5F89118E647C008301BF /* prcpucfg_unix.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = prcpucfg_unix.h; path = ../../torque_sockets/plugin_framework/prcpucfg_unix.h; sourceTree = SOURCE_ROOT; }; 1DAD5F8A118E647C008301BF /* prcpucfg_win32.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = prcpucfg_win32.h; path = ../../torque_sockets/plugin_framework/prcpucfg_win32.h; sourceTree = SOURCE_ROOT; }; 1DAD5F8B118E647C008301BF /* prtypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = prtypes.h; path = ../../torque_sockets/plugin_framework/prtypes.h; sourceTree = SOURCE_ROOT; }; 1DDD58150DA1D0A300B32029 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainMenu.xib; sourceTree = "<group>"; }; 1DF3DCCB117A822E008F7A78 /* chat_example.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = chat_example.html; path = ../../torque_sockets/products/TorqueSocketsPlugin/chat_example.html; sourceTree = SOURCE_ROOT; }; 29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; }; 29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; }; 29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; }; Loading Loading @@ -166,6 +182,7 @@ 1D3822211153D07C009D94C5 /* core */ = { isa = PBXGroup; children = ( 1DA8A0A9118FBE5900B11667 /* function_call_record.h */, 1D3822241153D0A7009D94C5 /* algorithm_templates.h */, 1D3822251153D0A7009D94C5 /* array.h */, 1D3822261153D0A7009D94C5 /* assert.h */, Loading Loading @@ -199,6 +216,7 @@ 1D3822421153D0A7009D94C5 /* string.h */, 1D3822431153D0A7009D94C5 /* system_includes_linux.h */, 1D3822441153D0A7009D94C5 /* system_includes_mac_osx.h */, 1DA8A0AA118FBEBF00B11667 /* system_includes_nacl.h */, 1D3822451153D0A7009D94C5 /* system_includes_win32.h */, 1D3822461153D0A7009D94C5 /* thread.h */, 1D3822471153D0A7009D94C5 /* thread_queue.h */, Loading Loading @@ -249,11 +267,33 @@ name = tnl2; sourceTree = "<group>"; }; 1DAD5F7E118E645E008301BF /* plugin_framework */ = { isa = PBXGroup; children = ( 1DAD5F7F118E647C008301BF /* jni.h */, 1DAD5F80118E647C008301BF /* jni_md.h */, 1DAD5F81118E647C008301BF /* jri.h */, 1DAD5F82118E647C008301BF /* jri_md.h */, 1DAD5F83118E647C008301BF /* jritypes.h */, 1DAD5F84118E647C008301BF /* npapi.h */, 1DAD5F85118E647C008301BF /* npruntime.h */, 1DAD5F86118E647C008301BF /* nptypes.h */, 1DAD5F87118E647C008301BF /* npupp.h */, 1DAD5F88118E647C008301BF /* plugin_framework.h */, 1DAD5F89118E647C008301BF /* prcpucfg_unix.h */, 1DAD5F8A118E647C008301BF /* prcpucfg_win32.h */, 1DAD5F8B118E647C008301BF /* prtypes.h */, ); name = plugin_framework; sourceTree = "<group>"; }; 29B97314FDCFA39411CA2CEA /* tnl2_test_cocoa */ = { isa = PBXGroup; children = ( 1DAD5F7E118E645E008301BF /* plugin_framework */, 1D38227A1153D2B5009D94C5 /* libtommath.a */, 1D3822781153D2A1009D94C5 /* libtomcrypt.a */, 1DF3DCCB117A822E008F7A78 /* chat_example.html */, 1D3822211153D07C009D94C5 /* core */, 1D3822221153D082009D94C5 /* torque_sockets */, 1D3822231153D08A009D94C5 /* tnl2 */, Loading Loading @@ -449,6 +489,7 @@ ARCHS = "$(ARCHS_STANDARD_32_BIT)"; GCC_C_LANGUAGE_STANDARD = c99; GCC_OPTIMIZATION_LEVEL = 0; GCC_VERSION = 4.2; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; ONLY_ACTIVE_ARCH = YES; Loading @@ -462,6 +503,7 @@ buildSettings = { ARCHS = "$(ARCHS_STANDARD_32_BIT)"; GCC_C_LANGUAGE_STANDARD = c99; GCC_VERSION = 4.2; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; PREBINDING = NO; Loading
nacl_test_tnl2/Makefile +3 −1 Original line number Diff line number Diff line nacl_test_tnl2_release.nexe: nacl_test_tnl2.cc /Users/markf/Work/gg/nativeclient/native_client/src/third_party/nacl_sdk/mac/sdk/nacl-sdk/bin/nacl-g++ nacl_test_tnl2.cc -O2 -I../tnl2 -I../../torque_sockets -I../test_tnl2 -Ilibtomcrypt/src/headers -Ilibtommath -Llibtommath -Llibtomcrypt -ltomcrypt -ltommath -lav -lsrpc -lpthread -lm -o nacl_test_tnl2_release.nexe /Users/markf/Work/gg/nativeclient/native_client/toolchain/mac_x86/sdk/nacl-sdk/bin/nacl-g++ nacl_test_tnl2.cc -O2 -DXP_UNIX -I../../nativeclient -I../tnl2 -I../../torque_sockets -I../test_tnl2 -Ilibtomcrypt/src/headers -Ilibtommath -Llibtommath -Llibtomcrypt -ltomcrypt -ltommath -lm -lgoogle_nacl_imc -lgoogle_nacl_npruntime -lgoogle_nacl_pgl -lgoogle_nacl_gpu -lpthread -lsrpc -o nacl_test_tnl2_release.nexe
nacl_test_tnl2/httpd.py 0 → 100755 +97 −0 Original line number Diff line number Diff line #!/usr/bin/python # Copyright 2008, Google Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following disclaimer # in the documentation and/or other materials provided with the # distribution. # * Neither the name of Google Inc. nor the names of its # contributors may be used to endorse or promote products derived from # this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """A tiny web server. This is intended to be used for testing, and only run from within the googleclient/native_client """ import BaseHTTPServer import logging import os import SimpleHTTPServer import SocketServer import sys logging.getLogger().setLevel(logging.INFO) # Using 'localhost' means that we only accept connections # via the loop back interface. SERVER_PORT = 5103 SERVER_HOST = '' # We only run from the native_client directory, so that not too much # is exposed via this HTTP server. Everything in the directory is # served, so there should never be anything potentially sensitive in # the serving directory, especially if the machine might be a # multi-user machine and not all users are trusted. We only serve via # the loopback interface. SAFE_DIR_COMPONENTS = ['native_client'] SAFE_DIR_SUFFIX = apply(os.path.join, SAFE_DIR_COMPONENTS) def SanityCheckDirectory(): if os.getcwd().endswith(SAFE_DIR_SUFFIX): return # endif #logging.error('httpd.py should only be run from the %s', SAFE_DIR_SUFFIX) #logging.error('directory for testing purposes.') #logging.error('We are currently in %s', os.getcwd()) #sys.exit(1) # enddef # the sole purpose of this class is to make the BaseHTTPServer threaded class ThreadedServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer): pass def Run(server_address, server_class=ThreadedServer, handler_class=SimpleHTTPServer.SimpleHTTPRequestHandler): httpd = server_class(server_address, handler_class) logging.info('started server on port %d', httpd.server_address[1]) httpd.serve_forever() # enddef if __name__ == '__main__': SanityCheckDirectory() if len(sys.argv) > 1: Run((SERVER_HOST, int(sys.argv[1]))) else: Run((SERVER_HOST, SERVER_PORT)) # endif # endif
nacl_test_tnl2/nacl_test_tnl2.cc +154 −164 Original line number Diff line number Diff line #include <errno.h> #include <stdio.h> //#include <nacl/nacl_av.h> //#include <nacl/nacl_srpc.h> #include <stdlib.h> #include <nacl/nacl_av.h> #include <nacl/nacl_srpc.h> #include <stdio.h> #include <nacl/nacl_npapi.h> #include <nacl/npruntime.h> #include <nacl/npapi_extensions.h> #include <nacl/npupp.h> #include <pgl/pgl.h> #include <GLES2/gl2.h> #include "test_tnl2.h" #include "plugin_framework/plugin_framework.h" #include "third_party/npapi/bindings/npapi_extensions_private.h" // global properties used to setup demo static const int kMaxWindow = 4096; static const int kMaxFrames = 10000000; static int g_window_width = 512; static int g_window_height = 512; static int g_num_frames = 9999; // Simple Surface structure to hold a raster rectangle struct Surface { int width, height, pitch; uint32_t *pixels; Surface(int w, int h) { width = w; height = h; pitch = w; pixels = new uint32_t[width * height]; } ~Surface() { delete[] pixels; } }; const int32_t kCommandBufferSize = 1024 * 1024; NPExtensions* extensions = NULL; // Drawing class holds information and functionality needed to render class DrawingDemo { class tnl_test_instance : public scriptable_object { public: void Display(); void Update(); bool PollEvents(); explicit DrawingDemo(Surface *s); ~DrawingDemo(); private: Surface *surf_; }; core::string bind_address; float _color; int _width, _height; NPDeviceContext3D _context3d; NPDevice* _device3d; PGLContext _pgl_context; tnl_test::test_game *_game; tnl_test_instance() { _color = 0; SOCKADDR addr; // This update loop is run once per frame. // AGG renders straight into the DrawingDemo's surf_ pixel array. void DrawingDemo::Update() { _game = new tnl_test::test_game(true, addr, addr); } // Displays software rendered image on the screen void DrawingDemo::Display() { int r; r = nacl_video_update(surf_->pixels); if (-1 == r) { printf("nacl_video_update() returned %d\n", errno); ~tnl_test_instance() { delete _game; destroy_context(); } } // Polls events and services them. bool DrawingDemo::PollEvents() { NaClMultimediaEvent event; while (0 == nacl_video_poll_event(&event)) { if (event.type == NACL_EVENT_QUIT) { return false; void init(NPMIMEType pluginType, core::int16 argc, char* argn[], char* argv[]) { if (!extensions) { browser->getvalue(get_plugin_instance(), NPNVPepperExtensions, reinterpret_cast<void*>(&extensions)); // CHECK(extensions); } _device3d = extensions->acquireDevice(get_plugin_instance(), NPPepper3DDevice); if (_device3d == NULL) { printf("Failed to acquire 3DDevice\n"); exit(1); } return true; } void set_window(NPWindow *window) { _width = window->width; _height = window->height; // Sets up and initializes DrawingDemo. DrawingDemo::DrawingDemo(Surface *surf) { surf_ = surf; if(!_pgl_context) init_context(); browser->pluginthreadasynccall(get_plugin_instance(), tick_callback, this); } // Frees up resources. DrawingDemo::~DrawingDemo() { void init_context() { // Initialize a 3D context. NPDeviceContext3DConfig config; config.commandBufferSize = kCommandBufferSize; NPError err = _device3d->initializeContext(get_plugin_instance(), &config, &_context3d); if (err != NPERR_NO_ERROR) { printf("Failed to initialize 3D context\n"); exit(1); } // Create a PGL context. _pgl_context = pglCreateContext(get_plugin_instance(), _device3d, &_context3d); // Runs the demo and animate the image for kNumFrames void RunDemo(Surface *surface) { DrawingDemo demo(surface); for (int i = 0; i < g_num_frames; ++i) { demo.Update(); demo.Display(); printf("Frame: %04d\b\b\b\b\b\b\b\b\b\b\b", i); fflush(stdout); if (!demo.PollEvents()) break; } // Initialize the demo GL state. pglMakeCurrent(_pgl_context); pglMakeCurrent(NULL); } void destroy_context() { // Destroy the PGL context. pglDestroyContext(_pgl_context); _pgl_context = NULL; // Initializes a window buffer. Surface* Initialize() { int r; int width; int height; r = nacl_multimedia_init(NACL_SUBSYSTEM_VIDEO | NACL_SUBSYSTEM_EMBED); if (-1 == r) { printf("Multimedia system failed to initialize! errno: %d\n", errno); exit(-1); } // if this call succeeds, use width & height from embedded html r = nacl_multimedia_get_embed_size(&width, &height); if (0 == r) { g_window_width = width; g_window_height = height; } r = nacl_video_init(g_window_width, g_window_height); if (-1 == r) { printf("Video subsystem failed to initialize! errno; %d\n", errno); exit(-1); // Destroy the Device3D context. _device3d->destroyContext(get_plugin_instance(), &_context3d); } Surface *surface = new Surface(g_window_width, g_window_height); return surface; static void tick_callback(void *data) { static_cast<tnl_test_instance *>(data)->tick(); } void tick() { _game->tick(); // Frees window buffer. void Shutdown(Surface *surface) { delete surface; nacl_video_shutdown(); nacl_multimedia_shutdown(); logprintf("hit draw (%d, %d)", _width, _height); if(!pglMakeCurrent(_pgl_context) && pglGetError() == PGL_CONTEXT_LOST) { destroy_context(); init_context(); pglMakeCurrent(_pgl_context); } glViewport(0, 0, _width, _height); _color += 0.05; if(_color > 1) _color = 0; glClearColor(_color, _color, 0, 1); glClear(GL_COLOR_BUFFER_BIT); // If user specified options on cmd line, parse them // here and update global settings as needed. void ParseCmdLineArgs(int argc, char **argv) { // look for cmd line args if (argc > 1) { for (int i = 1; i < argc; i++) { if (argv[i][0] == '-' && argv[i][1] == 'w') { int w = atoi(&argv[i][2]); if ((w > 0) && (w < kMaxWindow)) { g_window_width = w; } } else if (argv[i][0] == '-' && argv[i][1] == 'h') { int h = atoi(&argv[i][2]); if ((h > 0) && (h < kMaxWindow)) { g_window_height = h; } } else if (argv[i][0] == '-' && argv[i][1] == 'f') { int f = atoi(&argv[i][2]); if ((f > 0) && (f < kMaxFrames)) { g_num_frames = f; } } else { printf("nacl_test_tnl2\n"); printf("usage: -w<n> width of window.\n"); printf(" -h<n> height of window.\n"); printf(" -f<n> number of frames.\n"); printf(" --help show this screen.\n"); exit(0); tnl_test::test_game_render_frame_open_gl(0); glFlush(); pglSwapBuffers(); pglMakeCurrent(NULL); browser->pluginthreadasynccall(get_plugin_instance(), tick_callback, this); } core::int16 handle_event(void *event) { return 0; } bool module_ready() { return true; } static void register_class(type_database &db) { tnl_begin_class(db, tnl_test_instance, scriptable_object, true); tnl_method(db, tnl_test_instance, module_ready); tnl_end_class(db); } }; void plugin_initialize() { pglInitialize(); ltc_mp = ltm_desc; tnl_test_instance::register_class(global_type_database()); global_plugin.add_class(get_global_type_record<tnl_test_instance>()); global_plugin.set_plugin_class(get_global_type_record<tnl_test_instance>()); } // Parses cmd line options, initializes surface, runs the demo & shuts down. int main(int argc, char **argv) { ParseCmdLineArgs(argc, argv); Surface *surface = Initialize(); RunDemo(surface); Shutdown(surface); return 0; void plugin_shutdown() { pglTerminate(); } No newline at end of file
nacl_test_tnl2/nacl_test_tnl2.html +23 −20 Original line number Diff line number Diff line <HTML> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <HEAD> <TITLE>Torque Network Library 2.0 Test in Native Client</TITLE> <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> <META HTTP-EQUIV="Expires" CONTENT="-1"> <script type="text/javascript"> <!-- var nacl_elt; // Before scripting the loaded module, ensure the Native Client module is loaded. var startupTimeout; var PostLoadInit = function() { if (nacl_elt.__moduleReady == 1) { var PostLoadInit = function() { try { var embed = document.getElementById("embed1"); var ready = embed.module_ready(); clearTimeout(startupTimeout); nacl_elt.focus(); } else { if (nacl_elt.__moduleReady == undefined) { alert('The Native Client plugin was unable to load'); alert('The Native Client plugin is ready'); return; } startupTimeout = setTimeout(PostLoadInit, 100); catch(e) { // do nothing } startupTimeout = setTimeout(PostLoadInit, 100); } // Init is called when the document has completed loading. It downloads the Loading @@ -31,7 +39,7 @@ var Init = function() { PostLoadInit(); } --> </script> </HEAD> Loading @@ -49,13 +57,8 @@ var Init = function() { <a href="http://www.libtnl.com/">http://www.libtnl.com/</a> for more information about the Torque Network Library. </p> <embed id="embed1" src="nacl_test_tnl2.nexe" type="application/x-nacl-srpc" width=512 height=512> <embed id="embed1" src="nacl_test_tnl2_release.nexe" type="application/x-nacl-srpc" width=512 height=512> <br> <script> var embed1 = document.getElementById('embed1'); </script> </BODY> </HTML>