Permalink
Browse files

sistema funcional com threads, porem renderizando com erro

  • Loading branch information...
1 parent b89b276 commit 96a4923cf6059f01ddf065451b203f235fbf525f @prsolucoes committed Sep 17, 2012
Showing with 1 addition and 441 deletions.
  1. +0 −272 Makefile
  2. +1 −169 main.cpp
View
272 Makefile
@@ -1,272 +0,0 @@
-#############################################################################
-# Makefile for building: sfml-cmake.app/Contents/MacOS/sfml-cmake
-# Generated by qmake (2.01a) (Qt 4.8.1) on: Fri Sep 14 18:58:17 2012
-# Project: sfml-cmake.pro
-# Template: app
-# Command: /Users/paulo/QtSDK/Desktop/Qt/4.8.1/gcc/bin/qmake -spec ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/macx-g++42 CONFIG+=declarative_debug -o Makefile sfml-cmake.pro
-#############################################################################
-
-####### Compiler, tools and options
-
-CC = gcc-4.2
-CXX = g++-4.2
-DEFINES =
-CFLAGS = -pipe -g -gdwarf-2 -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -Wall -W $(DEFINES)
-CXXFLAGS = -pipe -g -gdwarf-2 -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -Wall -W $(DEFINES)
-INCPATH = -I../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/macx-g++42 -I. -Ilibrary/sfml/mac/include -Ilibrary/v8/mac/include -Ilibrary/sndfile/mac/include
-LINK = g++-4.2
-LFLAGS = -headerpad_max_install_names -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5
-LIBS = $(SUBLIBS)
-AR = ar cq
-RANLIB = ranlib -s
-QMAKE = /Users/paulo/QtSDK/Desktop/Qt/4.8.1/gcc/bin/qmake
-TAR = tar -cf
-COMPRESS = gzip -9f
-COPY = cp -f
-SED = sed
-COPY_FILE = cp -f
-COPY_DIR = cp -f -R
-STRIP =
-INSTALL_FILE = $(COPY_FILE)
-INSTALL_DIR = $(COPY_DIR)
-INSTALL_PROGRAM = $(COPY_FILE)
-DEL_FILE = rm -f
-SYMLINK = ln -f -s
-DEL_DIR = rmdir
-MOVE = mv -f
-CHK_DIR_EXISTS= test -d
-MKDIR = mkdir -p
-export MACOSX_DEPLOYMENT_TARGET = 10.4
-
-####### Output directory
-
-OBJECTS_DIR = ./
-
-####### Files
-
-SOURCES = main.cpp \
- sf_v8.cpp \
- v8wrap.cpp \
- JSCharacter.cpp \
- Character.cpp
-OBJECTS = main.o \
- sf_v8.o \
- v8wrap.o \
- JSCharacter.o \
- Character.o
-DIST = ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/common/unix.conf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/common/mac.conf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/common/gcc-base.conf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/common/gcc-base-macx.conf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/common/g++-base.conf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/common/g++-macx.conf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/qconfig.pri \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/modules/qt_webkit_version.pri \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/qt_functions.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/qt_config.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/exclusive_builds.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/default_pre.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/mac/default_pre.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/mac/dwarf2.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/debug.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/default_post.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/mac/default_post.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/mac/objective_c.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/declarative_debug.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/mac/x86_64.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/warn_on.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/mac/rez.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/mac/sdk.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/resources.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/uic.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/yacc.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/lex.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/include_source_dir.prf \
- sfml-cmake.pro
-QMAKE_TARGET = sfml-cmake
-DESTDIR =
-TARGET = sfml-cmake.app/Contents/MacOS/sfml-cmake
-
-####### Custom Compiler Variables
-QMAKE_COMP_QMAKE_OBJECTIVE_CFLAGS = -pipe \
- -g \
- -arch \
- x86_64 \
- -Xarch_x86_64 \
- -mmacosx-version-min=10.5 \
- -Wall \
- -W
-
-
-first: all
-####### Implicit rules
-
-.SUFFIXES: .o .c .cpp .cc .cxx .C
-
-.cpp.o:
- $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
-
-.cc.o:
- $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
-
-.cxx.o:
- $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
-
-.C.o:
- $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
-
-.c.o:
- $(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<"
-
-####### Build rules
-
-all: Makefile sfml-cmake.app/Contents/PkgInfo sfml-cmake.app/Contents/Resources/empty.lproj sfml-cmake.app/Contents/Info.plist $(TARGET)
-
-$(TARGET): $(OBJECTS)
- @$(CHK_DIR_EXISTS) sfml-cmake.app/Contents/MacOS/ || $(MKDIR) sfml-cmake.app/Contents/MacOS/
- $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)
-
-Makefile: sfml-cmake.pro ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/macx-g++42/qmake.conf ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/common/unix.conf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/common/mac.conf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/common/gcc-base.conf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/common/gcc-base-macx.conf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/common/g++-base.conf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/common/g++-macx.conf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/qconfig.pri \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/modules/qt_webkit_version.pri \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/qt_functions.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/qt_config.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/exclusive_builds.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/default_pre.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/mac/default_pre.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/mac/dwarf2.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/debug.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/default_post.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/mac/default_post.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/mac/objective_c.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/declarative_debug.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/mac/x86_64.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/warn_on.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/mac/rez.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/mac/sdk.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/resources.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/uic.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/yacc.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/lex.prf \
- ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/include_source_dir.prf
- $(QMAKE) -spec ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/macx-g++42 CONFIG+=declarative_debug -o Makefile sfml-cmake.pro
-../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/common/unix.conf:
-../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/common/mac.conf:
-../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/common/gcc-base.conf:
-../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/common/gcc-base-macx.conf:
-../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/common/g++-base.conf:
-../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/common/g++-macx.conf:
-../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/qconfig.pri:
-../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/modules/qt_webkit_version.pri:
-../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/qt_functions.prf:
-../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/qt_config.prf:
-../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/exclusive_builds.prf:
-../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/default_pre.prf:
-../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/mac/default_pre.prf:
-../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/mac/dwarf2.prf:
-../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/debug.prf:
-../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/default_post.prf:
-../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/mac/default_post.prf:
-../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/mac/objective_c.prf:
-../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/declarative_debug.prf:
-../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/mac/x86_64.prf:
-../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/warn_on.prf:
-../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/mac/rez.prf:
-../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/mac/sdk.prf:
-../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/resources.prf:
-../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/uic.prf:
-../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/yacc.prf:
-../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/lex.prf:
-../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/features/include_source_dir.prf:
-qmake: FORCE
- @$(QMAKE) -spec ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/macx-g++42 CONFIG+=declarative_debug -o Makefile sfml-cmake.pro
-
-sfml-cmake.app/Contents/PkgInfo:
- @$(CHK_DIR_EXISTS) sfml-cmake.app/Contents || $(MKDIR) sfml-cmake.app/Contents
- @$(DEL_FILE) sfml-cmake.app/Contents/PkgInfo
- @echo "APPL????" >sfml-cmake.app/Contents/PkgInfo
-sfml-cmake.app/Contents/Resources/empty.lproj:
- @$(CHK_DIR_EXISTS) sfml-cmake.app/Contents/Resources || $(MKDIR) sfml-cmake.app/Contents/Resources
- @touch sfml-cmake.app/Contents/Resources/empty.lproj
-
-sfml-cmake.app/Contents/Info.plist:
- @$(CHK_DIR_EXISTS) sfml-cmake.app/Contents || $(MKDIR) sfml-cmake.app/Contents
- @$(DEL_FILE) sfml-cmake.app/Contents/Info.plist
- @sed -e "s,@SHORT_VERSION@,1.0,g" -e "s,@TYPEINFO@,????,g" -e "s,@ICON@,,g" -e "s,@EXECUTABLE@,sfml-cmake,g" -e "s,@TYPEINFO@,????,g" ../../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/macx-g++42/Info.plist.app >sfml-cmake.app/Contents/Info.plist
-dist:
- @$(CHK_DIR_EXISTS) .tmp/sfml-cmake1.0.0 || $(MKDIR) .tmp/sfml-cmake1.0.0
- $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/sfml-cmake1.0.0/ && (cd `dirname .tmp/sfml-cmake1.0.0` && $(TAR) sfml-cmake1.0.0.tar sfml-cmake1.0.0 && $(COMPRESS) sfml-cmake1.0.0.tar) && $(MOVE) `dirname .tmp/sfml-cmake1.0.0`/sfml-cmake1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/sfml-cmake1.0.0
-
-
-clean:compiler_clean
- -$(DEL_FILE) $(OBJECTS)
- -$(DEL_FILE) *~ core *.core
-
-
-####### Sub-libraries
-
-distclean: clean
- -$(DEL_FILE) -r sfml-cmake.app
- -$(DEL_FILE) Makefile
-
-
-check: first
-
-compiler_objective_c_make_all:
-compiler_objective_c_clean:
-compiler_rez_source_make_all:
-compiler_rez_source_clean:
-compiler_rcc_make_all:
-compiler_rcc_clean:
-compiler_uic_make_all:
-compiler_uic_clean:
-compiler_image_collection_make_all: qmake_image_collection.cpp
-compiler_image_collection_clean:
- -$(DEL_FILE) qmake_image_collection.cpp
-compiler_yacc_decl_make_all:
-compiler_yacc_decl_clean:
-compiler_yacc_impl_make_all:
-compiler_yacc_impl_clean:
-compiler_lex_make_all:
-compiler_lex_clean:
-compiler_clean:
-
-####### Compile
-
-main.o: main.cpp sf_v8.h \
- v8wrap.h \
- ResourcePath.hpp \
- Character.h \
- JSCharacter.h
- $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp
-
-sf_v8.o: sf_v8.cpp sf_v8.h \
- v8wrap.h
- $(CXX) -c $(CXXFLAGS) $(INCPATH) -o sf_v8.o sf_v8.cpp
-
-v8wrap.o: v8wrap.cpp v8wrap.h
- $(CXX) -c $(CXXFLAGS) $(INCPATH) -o v8wrap.o v8wrap.cpp
-
-JSCharacter.o: JSCharacter.cpp JSCharacter.h \
- v8wrap.h \
- Character.h \
- ResourcePath.hpp
- $(CXX) -c $(CXXFLAGS) $(INCPATH) -o JSCharacter.o JSCharacter.cpp
-
-Character.o: Character.cpp Character.h \
- ResourcePath.hpp
- $(CXX) -c $(CXXFLAGS) $(INCPATH) -o Character.o Character.cpp
-
-####### Install
-
-install: FORCE
-
-uninstall: FORCE
-
-FORCE:
-
View
170 main.cpp
@@ -1,177 +1,9 @@
-#include <iostream>
-#include <SFML/Graphics.hpp>
-#include <v8.h>
-#include <v8-debug.h>
-#include "sf_v8.h"
-
#include "Engine.h"
-#if __APPLE__
- #include "ResourcePath.hpp"
-#else
- std::string resourcePath(void) { return ""; }
-#endif
-
-#include "Character.h"
-#include "JSCharacter.h"
-
-v8::Persistent<v8::Context> CreateShellContext() {
- v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
- return v8::Context::New(NULL, global);
-}
-
-// Reads a file into a v8 string.
-v8::Handle<v8::String> readFile(const std::string& name) {
- FILE* file = fopen(name.c_str(), "rb");
- if (file == NULL) return v8::Handle<v8::String>();
-
- fseek(file, 0, SEEK_END);
- int size = ftell(file);
- rewind(file);
-
- char* chars = new char[size + 1];
- chars[size] = '\0';
-
- for (int i = 0; i < size;)
- {
- int read = fread(&chars[i], 1, size - i, file);
- i += read;
- }
-
- fclose(file);
- v8::Handle<v8::String> result = v8::String::New(chars, size);
- delete[] chars;
- return result;
-}
-
-char *get(v8::Handle<v8::String> value, const char *fallback = "") {
- if (value->IsString()) {
- v8::String::AsciiValue string(value);
- char *str = (char *) malloc(string.length() + 1);
- strcpy(str, *string);
- return str;
- }
- char *str = (char *) malloc(strlen(fallback) + 1);
- strcpy(str, fallback);
- return str;
-}
-
-Character *robot1;
-sf::Mutex mutex;
-
-void start(v8::Persistent<v8::Context> &context)
-{
- v8::Locker locker;
-
- v8::Context::Scope scope(context);
-
- v8::Handle<v8::String> source = readFile(resourcePath() + "/js/robot1.js");
- v8::Handle<v8::Script> script = v8::Script::Compile(source);
- v8::Handle<v8::Value> result = script->Run();
-
- context.Dispose();
-
- std::cout << "::start" << std::endl;
-}
-
int main()
{
Engine *engine = new Engine();
engine->start();
- bool useThread = true;
-
- v8::HandleScope handleScope;
- v8::Persistent<v8::Context> context = v8::Context::New();
- v8::Context::Scope scope(context);
-
- //context->Global()->Set(v8::String::New("sf"), sf_v8::sf::Init());
-
- /*
- // EXEMPLO - IMPRIMIR STRING
- // Create a string containing the JavaScript code
- // to execute (notice the quotation).
- v8::Handle<v8::String> source = v8::String::New(" 'Hello World!'; ");
-
- // Compile the Javascript code.
- v8::Handle<v8::Script> script = v8::Script::Compile(source);
-
- // Run the script to get the result.
- v8::Handle<v8::Value> result = script->Run();
-
- v8::String::AsciiValue ascii(result);
- printf("%s\n", *ascii);
- */
-
- sf::RenderWindow window(sf::VideoMode(800, 600, 32), "SFML Sample Application");
-
- // teste com classe customizada
- robot1 = new Character();
- robot1->setType("robot1");
-
- JSCharacter::InitPOT(JSCharacter::POT);
- v8::Handle<v8::Object> Result = JSCharacter::POT->NewInstance();
- JSCharacter::MakeReference(Result, robot1);
- context->Global()->Set(v8::String::New("robot1"), Result);
- //context->Global()->Set(v8::String::New("sleep"), v8::FunctionTemplate::New(fn_sleep)->GetFunction() );
-
- /*
- // teste com sprite somente
- sf::Texture texture;
- if (!texture.loadFromFile(resourcePath() + "images/robot1.png"))
- return EXIT_FAILURE;
- sf::Sprite sprite(texture);
-
- sf::Sprite *robot1 = &sprite;
- v8::Handle<v8::Object> Result = sf_v8::sf_Sprite::POT->NewInstance();
- sf_v8::sf_Sprite::MakeReference(Result, robot1);
- context->Global()->Set(v8::String::New("robot1"), Result);
- */
-
- sf::Texture texture;
- if (!texture.loadFromFile(resourcePath() + "images/robot1.png"))
- {
- throw new std::exception();
- }
- sf::Sprite *sprite = new sf::Sprite(texture);
-
- while (window.isOpen())
- {
- sf::Event Event;
- while (window.pollEvent(Event))
- {
- switch (Event.type)
- {
- case sf::Event::Closed:
- window.close();
- break;
- default:
- break;
- }
- }
-
- if (useThread)
- {
- std::cout << "::thread::launch" << std::endl;
- sf::Thread thread(&start, context);
- thread.launch();
- }
- else
- {
- start(context);
- }
-
- window.clear(sf::Color(255, 255, 255));
- window.draw(*robot1->getSprite());
- window.draw(*sprite);
- window.display();
-
- sleep(1);
- }
-
- context.Dispose();
- delete robot1;
- delete sprite;
-
- return 0;
+ return EXIT_SUCCESS;
}

0 comments on commit 96a4923

Please sign in to comment.