예제 #1
0
파일: winmain.cpp 프로젝트: cpzhang/zen
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE , LPTSTR lpstrCmdLine, int nCmdShow)
{
	createGlobal();
	FrameWindow mw;
	mw.CreateEx();
	mw.ShowWindow(SW_MAXIMIZE);
	mw.UpdateWindow();
	MSG m;
	::ZeroMemory(&m, sizeof(m));
	for (;;)
	{
		::ZeroMemory(&m, sizeof(m));
		if (::PeekMessage(&m, NULL, 0, 0, PM_NOREMOVE))
		{
			::GetMessage(&m, NULL, 0, 0);
			if (m.message == WM_QUIT)
			{
				break;
			}
			::TranslateMessage(&m);
			::DispatchMessage(&m);
		}
		else
		{
			mw.onIdle();
		}
	}
	destroyGlobal();
	return 0;
}
예제 #2
0
파일: beascript.cpp 프로젝트: bagobor/bea
	//Initialize the javascript context and expose the methods in exposer
	bool _BeaScript::init()
	{
		
		lastError = "";
		HandleScope handle_scope;

		if (globalTemplate.IsEmpty()){
			globalTemplate = v8::Persistent<v8::ObjectTemplate>::New(createGlobal());
		}
		
		//Create the context
		m_context = v8::Context::New(NULL, globalTemplate);

		Context::Scope context_scope(m_context);

		globalSandbox = v8::Persistent<v8::Object>::New(v8::Object::New()); 

		Handle<Value> vCmdLine = bea::Convert<std::vector<std::string> >::ToJS(cmdLine);

		Handle<Object> objProcess = v8::Object::New();
		objProcess->Set(v8::String::New("argv"), vCmdLine);

		m_context->Global()->Set(v8::String::New("process"), objProcess);
		
		expose();

		executeScript("./loader.js");
		CloneObject(m_context->Global(), globalSandbox);


		return true; 
	}
예제 #3
0
bool JSAPITest::init()
{
    rt = createRuntime();
    if (!rt)
        return false;
    cx = createContext();
    if (!cx)
        return false;
    JS_BeginRequest(cx);
    JS::RootedObject global(cx, createGlobal());
    if (!global)
        return false;
    JS_EnterCompartment(cx, global);
    return true;
}
예제 #4
0
bool JSAPITest::init()
{
    rt = createRuntime();
    if (!rt)
        return false;
    cx = createContext();
    if (!cx)
        return false;
#ifdef JS_GC_ZEAL
    JS_SetGCZeal(cx, 0, 0);
#endif
    JS_BeginRequest(cx);
    js::RootedObject global(cx, createGlobal());
    if (!global)
        return false;
    oldCompartment = JS_EnterCompartment(cx, global);
    return oldCompartment != NULL;
}
예제 #5
0
파일: LuaAPI.cpp 프로젝트: cpzhang/zen
/* function: createGlobal */
static int tolua_LuaAPI_createGlobal00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
 tolua_Error tolua_err;
 if (
 !tolua_isnoobj(tolua_S,1,&tolua_err)
 )
 goto tolua_lerror;
 else
#endif
 {
 {
  createGlobal();
 }
 }
 return 0;
#ifndef TOLUA_RELEASE
 tolua_lerror:
 tolua_error(tolua_S,"#ferror in function 'createGlobal'.",&tolua_err);
 return 0;
#endif
}
예제 #6
0
파일: winmain.cpp 프로젝트: cpzhang/zen
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE , LPTSTR lpstrCmdLine, int nCmdShow)
{
	createGlobal();
	FrameWindow mw;
	mw.CreateEx();
	mw.ShowWindow(SW_SHOWMAXIMIZED);
	mw.UpdateWindow();
	MSG m;
	::ZeroMemory(&m, sizeof(m));
	float life = 0.0f;
	float frame = 0.0f;
	float fps = 0.0f;
	const size_t tDuration = 1000;
	const size_t tInterval = 1000/65;
	float inter = tInterval;
	for (;;)
	{
		::ZeroMemory(&m, sizeof(m));
		if (::PeekMessage(&m, NULL, 0, 0, PM_NOREMOVE))
		{
			::GetMessage(&m, NULL, 0, 0);
			if (m.message == WM_QUIT)
			{
				break;
			}
			::TranslateMessage(&m);
			::DispatchMessage(&m);
		}
		else
		{
			// GetTickCount only has a guaranteed resolution of 1/18th of a second, which is pretty horrible for game timing
			//Retrieves the number of milliseconds that have elapsed since the system was started, up to 49.7 days.
			float beforeRun = ::timeGetTime();
			mw.onIdle(inter);
			float afterRun = ::timeGetTime();
			float timeRun = afterRun - beforeRun;
			if (timeRun > tInterval)
			{
				inter = timeRun;
			}
			else
			{
				inter = tInterval;
			}
			++frame;
			float timeSleep = tInterval - timeRun;
			//¼ÆËãFPS
			life += inter;
			if (life >= tDuration)
			{
				fps = 1000.0f * frame / life;
				mw.setFPS(fps);
				life = 0.0f;
				frame = 0.0f;
			}
			//ÏÞÖ¡
			while(timeSleep >= 1.0f)
			{
				Sleep(1);
				--timeSleep;
			}
		}
	}
	destroyGlobal();

	return 0;
}