Permalink
Browse files

NaCl/build cleanup.

  • Loading branch information...
1 parent fdda899 commit 6a0c96756bcf2c26e6a49d1799e1af285187f9b4 @joelgwebber committed Dec 14, 2011
Showing with 20 additions and 103 deletions.
  1. +0 −5 c/Bench2d.cpp
  2. +4 −0 c/Bench2d.xcodeproj/project.pbxproj
  3. +1 −1 c/bench2d.js.mk
  4. +2 −1 c/bench2d.mk
  5. +7 −0 c/bench2d_main.cpp
  6. +0 −55 c/bench2d_nacl.cpp
  7. +5 −41 c/bench2d_nacl.html
  8. +1 −0 c/build.scons
View
@@ -86,8 +86,3 @@ void bench() {
printf("%f\n", (float32)total / FRAMES / CLOCKS_PER_SEC * 1000);
}
-int main(int argc, char** argv) {
- bench();
- return 0;
-}
-
@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
+ 913915231498FEAB0044A340 /* bench2d_main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 913915221498FEAB0044A340 /* bench2d_main.cpp */; };
9151393D1492651C00911A2F /* Bench2d.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9151393C1492651C00911A2F /* Bench2d.cpp */; };
91513A8C14926B2600911A2F /* b2BroadPhase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91513A2C14926B2500911A2F /* b2BroadPhase.cpp */; };
91513A8D14926B2600911A2F /* b2CollideCircle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91513A2E14926B2500911A2F /* b2CollideCircle.cpp */; };
@@ -69,6 +70,7 @@
/* Begin PBXFileReference section */
8DD76F6C0486A84900D96B5E /* Bench2d */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Bench2d; sourceTree = BUILT_PRODUCTS_DIR; };
+ 913915221498FEAB0044A340 /* bench2d_main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = bench2d_main.cpp; sourceTree = "<group>"; };
9151393C1492651C00911A2F /* Bench2d.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Bench2d.cpp; sourceTree = "<group>"; };
91513A2814926B2500911A2F /* Box2D.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Box2D.h; sourceTree = "<group>"; };
91513A2914926B2500911A2F /* Box2DConfig.cmake */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Box2DConfig.cmake; sourceTree = "<group>"; };
@@ -190,6 +192,7 @@
08FB7795FE84155DC02AAC07 /* Source */ = {
isa = PBXGroup;
children = (
+ 913915221498FEAB0044A340 /* bench2d_main.cpp */,
9151393C1492651C00911A2F /* Bench2d.cpp */,
);
name = Source;
@@ -463,6 +466,7 @@
91513AB614926B2600911A2F /* b2WeldJoint.cpp in Sources */,
91513AB714926B2600911A2F /* b2WheelJoint.cpp in Sources */,
91513AB814926B2600911A2F /* b2Rope.cpp in Sources */,
+ 913915231498FEAB0044A340 /* bench2d_main.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
@@ -27,7 +27,7 @@ EMSCRIPTEN_FLAGS = \
-s RUNTYPE_TYPE_INFO=0 \
-s CORRECT_ROUNDINGS=0
-OBJECTS = \
+OBJECTS = bench2d_main.bc \
Bench2d.bc \
Box2D_v2.2.1/Box2D/Collision/b2BroadPhase.bc \
Box2D_v2.2.1/Box2D/Collision/b2CollideCircle.bc \
View
@@ -2,7 +2,8 @@ CC = gcc
CFLAGS=-s -O3 -msse -mfpmath=sse -ffast-math -fomit-frame-pointer -IBox2D_v2.2.1 -DNDEBUG=1
LFLAGS = -lstdc++
-OBJECTS = Bench2d.o \
+OBJECTS = bench2d_main.o \
+Bench2d.o \
Box2D_v2.2.1/Box2D/Collision/b2BroadPhase.o \
Box2D_v2.2.1/Box2D/Collision/b2CollideCircle.o \
Box2D_v2.2.1/Box2D/Collision/b2CollideEdge.o \
View
@@ -0,0 +1,7 @@
+void bench();
+
+int main(int argc, char** argv) {
+ bench();
+ return 0;
+}
+
View
@@ -1,25 +1,3 @@
-/// @file <PROJECT_NAME>.cc
-/// This example demonstrates loading, running and scripting a very simple NaCl
-/// module. To load the NaCl module, the browser first looks for the
-/// CreateModule() factory method (at the end of this file). It calls
-/// CreateModule() once to load the module code from your .nexe. After the
-/// .nexe code is loaded, CreateModule() is not called again.
-///
-/// Once the .nexe code is loaded, the browser than calls the CreateInstance()
-/// method on the object returned by CreateModule(). It calls CreateInstance()
-/// each time it encounters an <embed> tag that references your NaCl module.
-///
-/// The browser can talk to your NaCl module via the postMessage() Javascript
-/// function. When you call postMessage() on your NaCl module from the browser,
-/// this becomes a call to the HandleMessage() method of your pp::Instance
-/// subclass. You can send messages back to the browser by calling the
-/// PostMessage() method on your pp::Instance. Note that these two methods
-/// (postMessage() in Javascript and PostMessage() in C++) are asynchronous.
-/// This means they return immediately - there is no waiting for the message
-/// to be handled. This has implications in your program design, particularly
-/// when mutating property values that are exposed to both the browser and the
-/// NaCl module.
-
#include <cstdio>
#include <string>
#include "ppapi/cpp/instance.h"
@@ -31,33 +9,11 @@ const char* const kReplyString = "Benchmarks complete.";
void bench();
-/// The Instance class. One of these exists for each instance of your NaCl
-/// module on the web page. The browser will ask the Module object to create
-/// a new Instance for each occurence of the <embed> tag that has these
-/// attributes:
-/// type="application/x-nacl"
-/// src="<PROJECT_NAME>.nmf"
-/// To communicate with the browser, you must override HandleMessage() for
-/// receiving messages from the borwser, and use PostMessage() to send messages
-/// back to the browser. Note that this interface is entirely asynchronous.
class Bench2dInstance : public pp::Instance {
public:
- /// The constructor creates the plugin-side instance.
- /// @param[in] instance the handle to the browser-side plugin instance.
explicit Bench2dInstance(PP_Instance instance) : pp::Instance(instance) {}
virtual ~Bench2dInstance() {}
- /// Handler for messages coming in from the browser via postMessage(). The
- /// @a var_message can contain anything: a JSON string; a string that encodes
- /// method names and arguments; etc. For example, you could use
- /// JSON.stringify in the browser to create a message that contains a method
- /// name and some parameters, something like this:
- /// var json_message = JSON.stringify({ "myMethod" : "3.14159" });
- /// nacl_module.postMessage(json_message);
- /// On receipt of this message in @a var_message, you could parse the JSON to
- /// retrieve the method name, match it to a function call, and then call it
- /// with the parameter.
- /// @param[in] var_message The message posted by the browser.
virtual void HandleMessage(const pp::Var& var_message) {
if (!var_message.is_string())
return;
@@ -72,29 +28,18 @@ class Bench2dInstance : public pp::Instance {
}
};
-/// The Module class. The browser calls the CreateInstance() method to create
-/// an instance of your NaCl module on the web page. The browser creates a new
-/// instance for each <embed> tag with type="application/x-nacl".
class Bench2dModule : public pp::Module {
public:
Bench2dModule() : pp::Module() {}
virtual ~Bench2dModule() {}
- /// Create and return a Bench2dInstance object.
- /// @param[in] instance The browser-side instance.
- /// @return the plugin-side instance.
virtual pp::Instance* CreateInstance(PP_Instance instance) {
return new Bench2dInstance(instance);
}
};
namespace pp {
-/// Factory function called by the browser when the module is first loaded.
-/// The browser keeps a singleton of this module. It calls the
-/// CreateInstance() method on the object you return to make instances. There
-/// is one instance per <embed> tag on the page. This is the main binding
-/// point for your NaCl module with the browser.
Module* CreateModule() {
return new Bench2dModule();
}
View
@@ -4,45 +4,27 @@
<title>Bench2d, NaCl Edition!</title>
<script type="text/javascript">
- Bench2dModule = null; // Global application object.
+ Bench2dModule = null;
statusText = 'NO-STATUS';
- // Indicate load success.
function moduleDidLoad() {
Bench2dModule = document.getElementById('Bench2d');
updateStatus('SUCCESS');
-
Bench2dModule.postMessage('bench');
}
- // The 'message' event handler. This handler is fired when the NaCl module
- // posts a message to the browser by calling PPB_Messaging.PostMessage()
- // (in C) or pp::Instance.PostMessage() (in C++). This implementation
- // simply displays the content of the message in an alert panel.
function handleMessage(message_event) {
alert(message_event.data);
}
- // If the page loads before the Native Client module loads, then set the
- // status message indicating that the module is still loading. Otherwise,
- // do not change the status message.
function pageDidLoad() {
if (Bench2dModule == null) {
- updateStatus('LOADING...');
+ updateStatus('Loading...');
} else {
- // It's possible that the Native Client module onload event fired
- // before the page's onload event. In this case, the status message
- // will reflect 'SUCCESS', but won't be displayed. This call will
- // display the current message.
updateStatus();
}
}
- // Set the global status message. If the element with id 'statusField'
- // exists, then set its HTML to the status message as well.
- // opt_message The message test. If this is null or undefined, then
- // attempt to set the element with id 'statusField' to the value of
- // |statusText|.
function updateStatus(opt_message) {
if (opt_message)
statusText = opt_message;
@@ -55,27 +37,9 @@
</head>
<body onload="pageDidLoad()">
- <h1>Native Client Module Bench2d</h1>
+ <p>Because I'm feeling too lazy to punt strings back out of the NaCl code, the benchmark output is all going to the old-school printf() console.
+ If you're on Linux, you probably know where to find this. If you're on a Mac, it'll be sitting in Console.app. If you're on Windows, you're on your own.</p>
<p>
- <!-- Load the published .nexe. This includes the 'nacl' attribute which
- shows how to load multi-architecture modules. Each entry in the "nexes"
- object in the .nmf manifest file is a key-value pair: the key is the
- instruction set architecture ('x86-32', 'x86-64', etc.); the value is a URL
- for the desired NaCl module.
- To load the debug versions of your .nexes, set the 'nacl' attribute to the
- _dbg.nmf version of the manifest file.
-
- Note: Since this NaCl module does not use any real-estate in the browser,
- its width and height are set to 0.
-
- Note: The <EMBED> element is wrapped inside a <DIV>, which has both a 'load'
- and a 'message' event listener attached. This wrapping method is used
- instead of attaching the event listeners directly to the <EMBED> element to
- ensure that the listeners are active before the NaCl module 'load' event
- fires. This also allows you to use PPB_Messaging.PostMessage() (in C) or
- pp::Instance.PostMessage() (in C++) from within the initialization code in
- your NaCl module.
- -->
<div id="listener">
<script type="text/javascript">
var listener = document.getElementById('listener');
@@ -88,7 +52,7 @@ <h1>Native Client Module Bench2d</h1>
</p>
<h2>Status</h2>
- <div id="status_field">NO-STATUS</div>
+ <div id="status_field"></div>
</body>
</html>
View
@@ -14,6 +14,7 @@ nacl_env = make_nacl_env.NaClEnvironment(
)
nacl_env.Append(CPPPATH='Box2D_v2.2.1')
+nacl_env.Append(CFLAGS='-s -O3 -msse -mfpmath=sse -ffast-math -fomit-frame-pointer -DNACL=1')
sources = [
'bench2d_nacl.cpp',

0 comments on commit 6a0c967

Please sign in to comment.