Commit af4fa69f authored by Mark Frohnmayer's avatar Mark Frohnmayer
Browse files

preparing tnl2 for build inside nacl

parent 97872219
Loading
Loading
Loading
Loading
+14 −14
Original line number Diff line number Diff line
@@ -95,7 +95,7 @@
		1D3822631153D0CD009D94C5 /* net_interface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = net_interface.h; path = ../tnl2/net_interface.h; sourceTree = SOURCE_ROOT; };
		1D3822641153D0CD009D94C5 /* net_object.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = net_object.h; path = ../tnl2/net_object.h; sourceTree = SOURCE_ROOT; };
		1D3822651153D0CD009D94C5 /* tnl2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = tnl2.h; path = ../tnl2/tnl2.h; sourceTree = SOURCE_ROOT; };
		1D3822711153D270009D94C5 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = ../../../../../../System/Library/Frameworks/OpenGL.framework; sourceTree = SOURCE_ROOT; };
		1D3822711153D270009D94C5 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = /System/Library/Frameworks/OpenGL.framework; sourceTree = "<absolute>"; };
		1D3822731153D280009D94C5 /* CoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreServices.framework; path = /System/Library/Frameworks/CoreServices.framework; sourceTree = "<absolute>"; };
		1D3822781153D2A1009D94C5 /* libtomcrypt.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libtomcrypt.a; path = ../../torque_sockets/lib/libtomcrypt/libtomcrypt.a; sourceTree = SOURCE_ROOT; };
		1D38227A1153D2B5009D94C5 /* libtommath.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libtommath.a; path = ../../torque_sockets/lib/libtommath/libtommath.a; sourceTree = SOURCE_ROOT; };
@@ -126,13 +126,15 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
		080E96DDFE201D6D7F000001 /* Classes */ = {
		080E96DDFE201D6D7F000001 /* Cocoa stub program */ = {
			isa = PBXGroup;
			children = (
				32CA4F630368D1EE00C91783 /* tnl2_test_cocoa_Prefix.pch */,
				29B97316FDCFA39411CA2CEA /* main.m */,
				1D38228C1153D404009D94C5 /* tnl2_test_view.h */,
				1D38228D1153D404009D94C5 /* tnl2_test_view.m */,
			);
			name = Classes;
			name = "Cocoa stub program";
			sourceTree = "<group>";
		};
		1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = {
@@ -253,13 +255,11 @@
			children = (
				1D38227A1153D2B5009D94C5 /* libtommath.a */,
				1D3822781153D2A1009D94C5 /* libtomcrypt.a */,
				1D3822731153D280009D94C5 /* CoreServices.framework */,
				1D3822711153D270009D94C5 /* OpenGL.framework */,
				1D3822231153D08A009D94C5 /* tnl2 */,
				1D3822221153D082009D94C5 /* torque_sockets */,
				1D3822211153D07C009D94C5 /* core */,
				080E96DDFE201D6D7F000001 /* Classes */,
				29B97315FDCFA39411CA2CEA /* Other Sources */,
				1D3822221153D082009D94C5 /* torque_sockets */,
				1D3822231153D08A009D94C5 /* tnl2 */,
				29B97315FDCFA39411CA2CEA /* tnl2_test */,
				080E96DDFE201D6D7F000001 /* Cocoa stub program */,
				29B97317FDCFA39411CA2CEA /* Resources */,
				29B97323FDCFA39411CA2CEA /* Frameworks */,
				19C28FACFE9D520D11CA2CBB /* Products */,
@@ -267,19 +267,17 @@
			name = tnl2_test_cocoa;
			sourceTree = "<group>";
		};
		29B97315FDCFA39411CA2CEA /* Other Sources */ = {
		29B97315FDCFA39411CA2CEA /* tnl2_test */ = {
			isa = PBXGroup;
			children = (
				1D38221A1153D076009D94C5 /* test_building.h */,
				1D38221B1153D076009D94C5 /* test_connection.h */,
				1D38221C1153D076009D94C5 /* test_game.cpp */,
				1D38221D1153D076009D94C5 /* test_game.h */,
				1D38221E1153D076009D94C5 /* test_net_interface.h */,
				1D38221F1153D076009D94C5 /* test_player.h */,
				32CA4F630368D1EE00C91783 /* tnl2_test_cocoa_Prefix.pch */,
				29B97316FDCFA39411CA2CEA /* main.m */,
				1D38221C1153D076009D94C5 /* test_game.cpp */,
			);
			name = "Other Sources";
			name = tnl2_test;
			sourceTree = "<group>";
		};
		29B97317FDCFA39411CA2CEA /* Resources */ = {
@@ -295,6 +293,8 @@
		29B97323FDCFA39411CA2CEA /* Frameworks */ = {
			isa = PBXGroup;
			children = (
				1D3822711153D270009D94C5 /* OpenGL.framework */,
				1D3822731153D280009D94C5 /* CoreServices.framework */,
				1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */,
				1058C7A2FEA54F0111CA2CBB /* Other Frameworks */,
			);
+2 −0
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 -Ilibtomcrypt/src/headers -Ilibtommath -lav -lsrpc -lpthread -lm -o nacl_test_tnl2_release.nexe 
+8 −0
Original line number Diff line number Diff line
A demo for tnl2 running in a Native Client + TorqueSocket enabled browser.

From this directory run:

make

Once the demo is built, point your browser (with the Native
Client and TorqueSocket plugins installed) to the nacl_test_tnl2.html file in this directory. This html file will run the demo embedded in a web page.
 No newline at end of file
+7 −2
Original line number Diff line number Diff line
@@ -2,10 +2,15 @@
#
# Tom St Denis
# Modified by Clay Culver
# Modified by Mark Frohnmayer to work with Native Client

# The version
VERSION=1.17

CC=/Users/markf/Work/gg/nativeclient/native_client/src/third_party/nacl_sdk/mac/sdk/nacl-sdk/bin/nacl-gcc
AR=/Users/markf/Work/gg/nativeclient/native_client/src/third_party/nacl_sdk/mac/sdk/nacl-sdk/bin/nacl-ar -r
RANLIB=/Users/markf/Work/gg/nativeclient/native_client/src/third_party/nacl_sdk/mac/sdk/nacl-sdk/bin/nacl-ranlib

PLATFORM := $(shell uname | sed -e 's/_.*//')

# Compiler and Linker Names
@@ -30,7 +35,7 @@ endif
endif

# Compilation flags. Note the += does not write over the user's CFLAGS!
CFLAGS += -arch i386 -c -I../libtommath -I./testprof/ -I./src/headers/ -Wall -Wsign-compare -W -Wshadow -Wno-unused-parameter -DLTC_SOURCE
CFLAGS += -c -I../libtommath -I./testprof/ -I./src/headers/ -Wall -Wsign-compare -W -Wshadow -Wno-unused-parameter -DLTC_SOURCE

# additional warnings (newer GCC 3.4 and higher)
ifdef GCC_34
@@ -265,7 +270,7 @@ testprof/$(LIBTEST):
	cd testprof ; CFLAGS="$(CFLAGS)" LIBTEST_S=$(LIBTEST_S) $(MAKE) 

$(LIBNAME): $(OBJECTS)
	$(AR) $(ARFLAGS) $@ $(OBJECTS) 
	$(AR) $@ $(OBJECTS) 
	$(RANLIB) $@

#This rule makes the hash program included with libtomcrypt
+200 −0
Original line number Diff line number Diff line
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <nacl/nacl_av.h>
#include <nacl/nacl_srpc.h>

#include <math.h>
#include <stdio.h>

#include <iostream>

// Copyright GarageGames.  See /license/info.txt in this distribution for licensing terms.

#include "tomcrypt.h"
#include "core/platform.h"
#include "torque_sockets/torque_sockets_c_api.h"

namespace core
{
#include "core/core.h"
	struct net {
#include "torque_sockets/torque_sockets.h"
	};
};

#include "torque_sockets/torque_sockets_c_implementation.h"

namespace core
{
	struct tnl {
#include "tnl2.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; }
};


// Drawing class holds information and functionality needed to render
class DrawingDemo {
 public:
  void Display();
  void Update();
  bool PollEvents();
  explicit DrawingDemo(Surface *s);
  ~DrawingDemo();

 private:
  Surface *surf_;
};


// This update loop is run once per frame.
// AGG renders straight into the DrawingDemo's surf_ pixel array.
void DrawingDemo::Update() {
}


// 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);
  }
}


// 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;
    }
  }
  return true;
}


// Sets up and initializes DrawingDemo.
DrawingDemo::DrawingDemo(Surface *surf) {
  surf_ = surf;
}


// Frees up resources.
DrawingDemo::~DrawingDemo() {
}


// 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;
  }
}


// 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);
  }
  Surface *surface = new Surface(g_window_width, g_window_height);
  return surface;
}


// Frees window buffer.
void Shutdown(Surface *surface) {
  delete surface;
  nacl_video_shutdown();
  nacl_multimedia_shutdown();
}


// 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);
      }
    }
  }
}


// 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;
}
Loading