Exemplo n.º 1
0
 int wmain(int argc, gs2d::str_type::char_t* argv[])
#endif
{
	Platform::FileManagerPtr fileManager(new Platform::StdFileManager());

	Platform::FileIOHubPtr fileIOHub = Platform::CreateFileIOHub(fileManager, GS_L("data/"));

	VideoPtr video;
	if ((video = CreateVideo(1024, 768, GS_L("temp"), true, true, fileIOHub, Texture::PF_UNKNOWN, false)))
	{
		InputPtr input = CreateInput(0, false);
		AudioPtr audio = CreateAudio(0);

		Video::APP_STATUS status;
		while ((status = video->HandleEvents()) != Video::APP_QUIT)
		{
			if (status == Video::APP_SKIP)
				continue;

			input->Update();
			video->BeginSpriteScene();
			video->EndSpriteScene();
		}
	}
	return 0;
}
Exemplo n.º 2
0
int main()
{
	VideoPtr video;
	BaseApplicationPtr application = CreateBaseApplication();

	if ((video = CreateVideo(480, 854, L"GS2D", true, true, L"assets/fonts/")))
	{
		InputPtr input = CreateInput(0, true);
		AudioPtr audio = CreateAudio(0);

		application->Start(video, input, audio);

		Video::APP_STATUS status;
		while ((status = video->HandleEvents()) != Video::APP_QUIT)
		{
			if (status == Video::APP_SKIP)
				continue;

			input->Update();
			application->Update(Min(static_cast<unsigned long>(1000), ComputeElapsedTime(video)));
			application->RenderFrame();
		}
	}
	application->Destroy();	

	#ifdef _DEBUG
	 #ifdef WIN32
	  _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
	  #endif
	#endif
	return 0;
}
Exemplo n.º 3
0
    void process() override
    {
        std::size_t num_inputs = VariadicInputs::getVariadicInputCount();

        sum = 0;

        for (std::size_t i_inputs = 0; i_inputs < num_inputs; ++i_inputs) {
            addInput(VariadicInputs::getVariadicInput(i_inputs));
        }

        InputPtr in = VariadicInputs::getVariadicInput(0);
        if (msg::isValue<int>(in.get())) {
            int out = (int)sum;
            msg::publish(out_, out);

        } else if (msg::isValue<double>(in.get())) {
            msg::publish(out_, sum);

        } else {
            // must be vector
            GenericVectorMessageConstPtr vec = msg::getMessage<GenericVectorMessage>(in.get());
            if (std::dynamic_pointer_cast<connection_types::GenericValueMessage<int> const>(vec->nestedType())) {
                int out = (int)sum;
                msg::publish(out_, out);
            } else {
                msg::publish(out_, sum);
            }
        }

        msg::publish(out_, sum);
    }
Exemplo n.º 4
0
bool EditorBase::DrawTab(VideoPtr video, InputPtr input, const Vector2 &v2Pos, const float width, const wstring &text, Color color)
{
	video->SetAlphaMode(Video::AM_PIXEL);
	video->SetVertexShader(ShaderPtr());
	video->SetPixelShader(ShaderPtr());
	video->SetZBuffer(false);
	video->SetZWrite(false);

	const Vector2 v2Cam = video->GetCameraPos();
	video->SetCameraPos(Vector2(0,0));
	bool mouseOver = false;
	if (mouseOver = ETHGlobal::PointInRect(input->GetCursorPositionF(video), v2Pos+Vector2(width/2, m_menuSize), Vector2(width, m_menuSize)))
	{
		if (color.a < 200)
			color.a = 200;
	}

	const Vector2 v2CurveSize = m_curve->GetBitmapSizeF();
	const float rectWidth = width-v2CurveSize.x*2;
	m_curve->FlipX();
	m_curve->Draw(v2Pos, color);

	const Vector2 v2RectPos = v2Pos+Vector2(v2CurveSize.x, 0);
	video->DrawRectangle(v2RectPos, Vector2(rectWidth, m_menuSize*2), color);

	m_curve->FlipX();
	m_curve->Draw(v2Pos+Vector2(v2CurveSize.x+rectWidth, 0), color);

	ShadowPrint(v2RectPos+Vector2(v2CurveSize.x, m_menuSize/2), text.c_str(), L"Verdana14_shadow.fnt", Color(color.a,255,255,255));
	video->SetCameraPos(v2Cam);
	return (mouseOver && input->GetKeyState(GSK_LMOUSE) == GSKS_HIT);
}
Exemplo n.º 5
0
TEST_F(ProcessingTest, DirectCallToProcess)
{
    NodeFacadeImplementationPtr times_4 = factory.makeNode("StaticMultiplier4", UUIDProvider::makeUUID_without_parent("StaticMultiplier4"), graph);
    Node& node = *times_4->getNode();
    NodeHandle& nh = *times_4->getNodeHandle();

    ASSERT_TRUE(node.canProcess());

    // set the input message
    TokenPtr token_in = msg::createToken(23);
    InputPtr input = nh.getInput(UUIDProvider::makeUUID_without_parent("StaticMultiplier4:|:in_0"));
    ASSERT_NE(nullptr, input);
    input->setToken(token_in);

    // no inputs are sent now -> node should multiply the input by 4
    ASSERT_TRUE(node.canProcess());
    node.process(nh, node);

    // commit the messages produced by the node
    OutputPtr output = nh.getOutput(UUIDProvider::makeUUID_without_parent("StaticMultiplier4:|:out_0"));
    ASSERT_NE(nullptr, output);
    output->commitMessages(false);

    // view outputs
    TokenPtr token_out = output->getToken();
    TokenDataConstPtr data_out = token_out->getTokenData();
    ASSERT_NE(nullptr, data_out);

    auto msg_out = std::dynamic_pointer_cast<connection_types::GenericValueMessage<int> const>(data_out);
    ASSERT_NE(nullptr, msg_out);

    ASSERT_EQ(23 * 4, msg_out->value);
}
Exemplo n.º 6
0
InputPtr SubgraphNode::createInternalInput(const TokenDataConstPtr& type, const UUID& internal_uuid, const std::string& label, bool optional)
{
    InputPtr input = node_handle_->addInternalInput(type, internal_uuid, label, optional);
    input->setGraphPort(true);
    input->setEssential(true);

    transition_relay_in_->addInput(input);

    return input;
}
Exemplo n.º 7
0
void SubgraphNode::removeVariadicInput(InputPtr input)
{
    OutputPtr relay = external_to_internal_outputs_[input->getUUID()];
    forwarding_connector_removed(relay);

    VariadicInputs::removeVariadicInput(input);

    relay_to_external_input_.erase(relay->getUUID());

    external_to_internal_outputs_.erase(input->getUUID());
    transition_relay_out_->removeOutput(relay);
}
Exemplo n.º 8
0
void SubgraphNode::removeVariadicOutput(OutputPtr output)
{
    InputPtr relay = external_to_internal_inputs_[output->getUUID()];
    forwarding_connector_removed(relay);

    relay->message_set.disconnectAll();

    VariadicOutputs::removeVariadicOutput(output);

    relay_to_external_output_.erase(relay->getUUID());

    external_to_internal_inputs_.erase(output->getUUID());
    transition_relay_in_->removeInput(relay);
}
Exemplo n.º 9
0
JNIEXPORT jstring JNICALL Java_net_asantee_gs2d_GS2DJNI_mainLoop(JNIEnv* env, jobject thiz, jstring inputStr)
{
	jboolean isCopy;
	g_inputStr = env->GetStringUTFChars(inputStr, &isCopy);

	video->HandleEvents();
	input->Update();

	// if the splash screen has already been shown, do the regular engine loop
	if (g_splashShown)
	{
		// if the engine hasn't been started yet (which means the previous frame was the splash screen frame),
		// start the engine machine before performing the regular loop
		if (!application)
		{
			StartApplication();
		}
		application->Update(Min(static_cast<unsigned long>(1000), ComputeElapsedTime(video)));
		application->RenderFrame();
	}
	else
	{
		// draw the splash screen and prepare the engine start
		DrawSplashScreen();
		g_splashShown = true;
	}

	return env->NewStringUTF(AssembleCommands().c_str());
}
Exemplo n.º 10
0
    void addInput(const InputPtr& in)
    {
        if (msg::isValue<int>(in.get())) {
            sum += msg::getValue<int>(in.get());

        } else if (msg::isValue<double>(in.get())) {
            sum += msg::getValue<double>(in.get());

        } else {
            // must be vector
            GenericVectorMessageConstPtr vec = msg::getMessage<GenericVectorMessage>(in.get());
            if (std::dynamic_pointer_cast<GenericValueMessage<double>>(vec->nestedType())) {
                acc<double>(vec);
            } else if (std::dynamic_pointer_cast<GenericValueMessage<int>>(vec->nestedType())) {
                acc<int>(vec);
            }
        }
    }
Exemplo n.º 11
0
UUID SubgraphNode::addForwardingOutput(const UUID& internal_uuid, const TokenDataConstPtr& type, const std::string& label)
{
    graph_->registerUUID(internal_uuid);

    Output* external_output = VariadicOutputs::createVariadicOutput(type, label);

    InputPtr relay = createInternalInput(type, internal_uuid, label, true);

    crossConnectLabelChange(external_output, relay.get());

    std::weak_ptr<Output> external_output_weak = std::dynamic_pointer_cast<Output>(external_output->shared_from_this());
    relay->message_set.connect([this, external_output_weak, relay](Connectable*) {
        if (auto external_output = external_output_weak.lock()) {
            TokenPtr token = relay->getToken();
            if (is_iterating_) {
                connection_types::GenericVectorMessage::Ptr vector;
                if (!external_output->hasMessage()) {
                    vector = connection_types::GenericVectorMessage::make(token->getTokenData());
                } else {
                    auto collected = external_output->getAddedToken()->getTokenData()->cloneAs<TokenData>();
                    vector = std::dynamic_pointer_cast<connection_types::GenericVectorMessage>(collected);
                }
                apex_assert(vector);
                vector->addNestedValue(token->getTokenData());
                msg::publish(external_output.get(), vector);

                external_output->setType(vector);

            } else {
                msg::publish(external_output.get(), token->getTokenData());
            }
        }
    });

    external_to_internal_inputs_[external_output->getUUID()] = relay;

    relay_to_external_output_[internal_uuid] = external_output->getUUID();

    forwarding_connector_added(relay);

    return external_output->getUUID();
}
Exemplo n.º 12
0
float CustomDataEditor::PlaceButtons(const Vector2 &v2Pos, const ETHEntity* pEntity, EditorBase *pEditor)
{
	VideoPtr video = pEditor->GetVideoHandler();
	InputPtr input = pEditor->GetInputHandler();
	if (pEntity->HasCustomData())
	{
		m_customDataButtonList.PlaceMenu(v2Pos);

		// if the cursor is over, show message
		if (m_customDataButtonList.IsMouseOver())
		{
			pEditor->ShadowPrint(input->GetCursorPositionF(video)-Vector2(0,pEditor->GetMenuSize()), GS_L("Click to edit"));
		}
	}
	else
	{
		m_customDataButtonList.Clear();
	}
	return static_cast<float>(m_customDataButtonList.GetNumButtons())*pEditor->GetMenuSize();
}
Exemplo n.º 13
0
void PlayerManager::Update(VideoPtr video, InputPtr input, ShootManagerPtr shootManager, SpritePtr playerSprite, SpritePtr shootSprite)
{
	static Vector2 hitPos, releasePos;
	static int turn = 0;
	if (input->GetTouchState(0) == GSKS_HIT)
	{	
		if (IsInArea(GetAbsolutePos(input, video), Rect2Df(GetPlayer(turn)->GetPos(), playerSprite->GetRect().size), Vector2(0.5f, 0.5f), video))
		{
			hitPos = input->GetTouchPos(0, video);
		}
		else
		{
			hitPos = GS_NO_TOUCH;
		}
	}
	if (input->GetTouchState(0) == GSKS_DOWN)
	{
		releasePos = hitPos - input->GetTouchPos(0, video);
	}
	if (input->GetTouchState(0) == GSKS_RELEASE && hitPos != GS_NO_TOUCH)
	{
		{
			Vector2 pos = m_simulator->GetPosition(GetPlayer(turn)->GetBodyId());
			shootManager->Shoot(pos, turn, releasePos);
			turn = !turn;
		}
	}
	if (hitPos == GS_NO_TOUCH)
	{
		video->MoveCamera(input->GetTouchMove(0) * -1);
	}
}
Exemplo n.º 14
0
void TouchButton::UpdateButton(VideoPtr video, InputPtr input, AudioPtr audio, SpriteResourceManager& spr, AudioResourceManager& aud)
{
	SpritePtr sprite = spr.GetSprite(video, m_buttonSprite);
	const Vector2 frameSize(GetButtonSize(sprite));
	const Vector2 currentTouch(input->GetTouchPos(0, video));
	if (input->GetTouchState(0) == GSKS_HIT && currentTouch != GS_NO_TOUCH)
		m_hitPos = currentTouch;

	if (m_status == SACTIVATED)
	{
		m_status = ACTIVATED;
	}

	if (currentTouch != GS_NO_TOUCH)
	{
		m_lastTouch = currentTouch;
		if (IsInArea(currentTouch, Rect2Df(m_pos, frameSize), m_origin) && IsInArea(m_hitPos, Rect2Df(m_pos, frameSize), m_origin))
		{
			m_status = PRESSED;
		}
		else
		{
			m_status = IDLE;
		}
	}

	if (input->GetTouchState(0) == GSKS_RELEASE)
	{
		if (IsInArea(m_lastTouch, Rect2Df(m_pos, frameSize), m_origin) && IsInArea(m_hitPos, Rect2Df(m_pos, frameSize), m_origin))
		{
			m_status = SACTIVATED;
			if (m_soundEffect != GS_L(""))
			{
				aud.GetSample(audio, m_soundEffect)->Play();
			}
		}
	}
}
double Optimizer::ComputeCost(InputPtr input_image,  Alpha& alpha) const
{
	double function_value = 0;

	for (int i = 0; i < LandmarkNum; ++i)
	{
		vec2 model_pos = alpha.ComputeLandmarkPosition(i);
		vec2 input_pos = input_image->LandmarkPosition(i);
		vec2 diff = (model_pos - input_pos);
		function_value += dot(diff, diff);
	}

	return function_value;

}
Exemplo n.º 16
0
void SubgraphNode::setIterationEnabled(const UUID& external_input_uuid, bool enabled)
{
    if (enabled) {
        // only one iteration is allowed for now
        apex_assert_eq(0, iterated_inputs_.size());

        iterated_inputs_.insert(external_input_uuid);

        InputPtr i = node_handle_->getInput(external_input_uuid);
        OutputPtr o = external_to_internal_outputs_.at(i->getUUID());

        // change the output type of the subgraph
        TokenDataConstPtr vector_type = i->getType();
        if (vector_type->isContainer()) {
            o->setType(vector_type->nestedType());
        }

        // change the input type of the subgraph
        for (const UUID& id : transition_relay_in_->getInputs()) {
            InputPtr i = transition_relay_in_->getInput(id);

            TokenDataConstPtr type = i->getType();

            original_types_[id] = type;

            if (auto vector = std::dynamic_pointer_cast<const connection_types::GenericVectorMessage>(type)) {
                i->setType(vector->nestedType());
            }
        }

    } else {
        iterated_inputs_.erase(external_input_uuid);

        // change back the input type of the subgraph
        for (const UUID& id : transition_relay_in_->getInputs()) {
            InputPtr i = transition_relay_in_->getInput(id);
            i->setType(original_types_[id]);
        }
    }
}
double Optimizer::ComputeCost(InputPtr input_image, ModelPtr model, Alpha& alpha) const
{
	double function_value = 0;
	
	int random_num = 1000;
	vector<int> triangle_ids;
	model->GenerateRandomNumbers(random_num, triangle_ids);	
	//int random_num = random_points_.size();

	for (int i = 0; i < random_num; ++i)
	{
		int id = triangle_ids[i];
    	//int id = random_points_[i];

		ivec2 pos = alpha.ComputePosition(id);
		vec3 model_color = alpha.ComputeColor(id);  // in RGB order 
		vec3 input_color = input_image->GetColor(Point(pos[0], pos[1])); // in RGB order
		vec3 diff = (model_color - input_color);
		function_value += dot(diff, diff);
	}
	return 40.0/1000*function_value;
}
Exemplo n.º 18
0
int wmain(int argc, wchar_t* argv[])
{
	bool compileAndRun, testing, wait;
	ProcParams(argc, argv, compileAndRun, testing, wait);
	ETHScriptWrapper::SetArgc(argc);
	ETHScriptWrapper::SetArgv(argv);

	Platform::FileManagerPtr fileManager(new Platform::StdFileManager());
	Platform::FileIOHubPtr fileIOHub(new Platform::WindowsFileIOHub(fileManager, ETHDirectories::GetBitmapFontDirectory()));
	const str_type::string resourceDirectory = fileIOHub->GetResourceDirectory(); 

	const ETHAppEnmlFile app(resourceDirectory + ETH_APP_PROPERTIES_FILE, Platform::FileManagerPtr(new Platform::StdFileManager), GS_L(""));
	const str_type::string bitmapFontPath = resourceDirectory + ETHDirectories::GetBitmapFontDirectory();

	bool aborted;
	{
		ETHEnginePtr application = ETHEnginePtr(new ETHEngine(testing, compileAndRun));
		application->SetHighEndDevice(true); // the PC will always be considered as a high-end device

		VideoPtr video;
		if ((video = CreateVideo(app.GetWidth(), app.GetHeight(), app.GetTitle(), app.IsWindowed(), app.IsVsyncEnabled(), fileIOHub, Texture::PF_UNKNOWN, false)))
		{
			InputPtr input = CreateInput(0, false);
			AudioPtr audio = CreateAudio(0);

			application->Start(video, input, audio);

			if (compileAndRun)
			{
				Video::APP_STATUS status;
				while ((status = video->HandleEvents()) != Video::APP_QUIT)
				{
					if (status == Video::APP_SKIP)
						continue;

					input->Update();
					if (application->Update(Min(static_cast<unsigned long>(1000), ComputeElapsedTime(video))) == Application::APP_QUIT)
					{
						break;
					}
					application->RenderFrame();
				}
			}
		}
		application->Destroy();	
		aborted = application->Aborted();
	}

	if (aborted)
	{
		ETH_STREAM_DECL(ss) << std::endl << GS_L("The program executed an ilegal operation and was aborted");
		//logger->Log(ss.str(), Platform::Logger::ERROR);
		std::wcerr << ss.str() << std::endl;
	}

	if (!compileAndRun && !aborted)
	{
		ETH_STREAM_DECL(ss) << std::endl << GS_L("Compilation successful: 0 errors");
		//logger->Log(ss.str(), Platform::Logger::INFO);
		std::wcerr << ss.str() << std::endl;
	}

	if (aborted && wait)
	{
		std::wcout << GS_L("Press any key to continue...") << std::endl;
		while(!_getch());
	}

	#ifdef _DEBUG
	 #ifdef WIN32
	  _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
	  #endif
	#endif
	return 0;
}
Exemplo n.º 19
0
inline Vector2 GetAbsolutePos(InputPtr input, VideoPtr video)
{
	return input->GetTouchPos(0, video) + video->GetCameraPos();
}
Exemplo n.º 20
0
void GSGUI_STRING_INPUT::PlaceInput(const Vector2& pos, const str_type::string& font, const unsigned int nMaxChars, 
				const float size, const Color& dwColor, VideoPtr video,
				InputPtr input)
{
	const unsigned int time = video->GetElapsedTime();
	if ((time-lastBlink) > blinkTime)
	{
		showingCarret = showingCarret==0 ? 1 : 0;
		lastBlink = video->GetElapsedTime();
	}

	// pick the text cursor position with a mouse click
	if (input->GetLeftClickState() == GSKS_HIT)
	{
		cursor = video->FindClosestCarretPosition(font, ss, pos, input->GetCursorPositionF(video));
	}
	
	// don't let the cursor exceed the text range
	cursor = Min(cursor, static_cast<unsigned int>(ss.length()));

	str_type::char_t lastInput = input->GetLastCharInput();
	if (lastInput != '\0' && ss.length() < nMaxChars)
	{
		if (numbersOnly)
		{
			if ((lastInput < 'a' || lastInput > 'z') &&
				(lastInput < 'A' || lastInput > 'Z'))
			{
				ss.insert(cursor, 1, lastInput);
			}
		}
		else
		{
			ss.insert(cursor, 1, lastInput);
		}
		cursor++;
	}

	if (input->GetKeyState(GSK_BACK) == GSKS_HIT)
	{
		if (cursor > 0)
		{
			ss.erase(cursor-1, 1);
			cursor--;
		}
	}
	
	if (input->GetKeyState(GSK_DELETE) == GSKS_HIT)
	{
		if (cursor < ss.length())
		{
			ss.erase(cursor, 1);
		}
	}
	
	if (input->GetKeyState(GSK_LEFT) == GSKS_HIT)
	{
		if (cursor > 0)
			cursor--;
	}
	if (input->GetKeyState(GSK_RIGHT) == GSKS_HIT)
	{
		cursor = Min(++cursor, static_cast<unsigned int>(ss.length()));
	}
	if (input->GetKeyState(GSK_END) == GSKS_HIT)
	{
		SendCursorToEnd();
	}

	const Vector2 cursorPosition = video->ComputeCarretPosition(font, ss, cursor);
	video->DrawBitmapText(pos, ss, font, dwColor);
	if (showingCarret==1)
		video->DrawRectangle(cursorPosition+pos-Vector2(2,0), Vector2(2,size), gs2d::constant::BLACK, gs2d::constant::BLACK, gs2d::constant::BLACK, gs2d::constant::BLACK, 0.0f);
}
Exemplo n.º 21
0
 int main(int argc, char** argv)
#endif
{
	// convert args to multibyte char
	#ifdef WIN32
		GS2D_UNUSED_ARGUMENT(hInstance);
		GS2D_UNUSED_ARGUMENT(nCmdShow);
		int argc = 0;
		LPWSTR* wargv = CommandLineToArgvW(lpCmdLine, &argc);

		LPSTR* argv = new LPSTR [argc];

		for (int t = 0; t < argc; t++)
		{
			std::size_t convertCount = 0;
			const std::size_t bufferSize = 4096;
			argv[t] = new CHAR [bufferSize];
			wcstombs_s(&convertCount, argv[t], bufferSize, wargv[t], wcslen(wargv[t]) + 1);
		}
	#endif

	// start engine runtime
	bool compileAndRun, testing, wait;
	ProcParams(argc, argv, compileAndRun, testing, wait);
	ETHScriptWrapper::SetArgc(argc);
	ETHScriptWrapper::SetArgv(argv);

	Platform::FileManagerPtr fileManager(new Platform::StdFileManager());

	Platform::FileIOHubPtr fileIOHub = Platform::CreateFileIOHub(fileManager, ETHDirectories::GetBitmapFontDirectory());
	{
		const str_type::string resourceDirectory = FindResourceDir(argc, argv);
		if (!resourceDirectory.empty())
			fileIOHub->SetResourceDirectory(resourceDirectory);
	}
	const str_type::string resourceDirectory = fileIOHub->GetResourceDirectory(); 

	const ETHAppEnmlFile app(resourceDirectory + ETH_APP_PROPERTIES_FILE, Platform::FileManagerPtr(new Platform::StdFileManager), Application::GetPlatformName());
	const str_type::string bitmapFontPath = resourceDirectory + ETHDirectories::GetBitmapFontDirectory();

	bool aborted;
	{
		ETHEnginePtr application = ETHEnginePtr(new ETHEngine(testing, compileAndRun));
		application->SetHighEndDevice(true);

		VideoPtr video;
		if ((video = CreateVideo(
			app.GetWidth(),
			app.GetHeight(),
			app.GetTitle(),
			app.IsWindowed(),
			app.IsVsyncEnabled(),
			fileIOHub,
			Texture::PF_UNKNOWN,
			false)))
		{
			InputPtr input = CreateInput(0, false);
			AudioPtr audio = CreateAudio(0);

			application->Start(video, input, audio);

			if (compileAndRun)
			{
				Video::APP_STATUS status;
				while ((status = video->HandleEvents()) != Video::APP_QUIT)
				{
					if (status == Video::APP_SKIP)
						continue;

					input->Update();
					if (application->Update(Min(1000.0f, ComputeElapsedTimeF(video))) == Application::APP_QUIT)
					{
						break;
					}
					application->RenderFrame();
				}
			}
		}
		application->Destroy();	
		aborted = application->Aborted();
	}

	if (aborted)
	{
		ETH_STREAM_DECL(ss) << std::endl << GS_L("The program executed an ilegal operation and was aborted");
		GS2D_CERR << ss.str() << std::endl;
	}

	if (!compileAndRun && !aborted)
	{
		ETH_STREAM_DECL(ss) << std::endl << GS_L("Compilation successful: 0 errors");
		GS2D_CERR << ss.str() << std::endl;
	}

	if (aborted && wait)
	{
		GS2D_COUT << GS_L("Press any key to continue...") << GS_L("\n");
		std::cin.get();
	}

	#if defined(_DEBUG) || defined(DEBUG)
	 #ifdef WIN32
	  _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
	  LocalFree(wargv);
	  for (int t = 0; t < argc; t++)
	  {
		  delete [] argv[t];
	  }
	  delete [] argv;
	  #endif
	#endif
	return 0;
}
Exemplo n.º 22
0
GS_PLAYER_INFO PlayCutscene(VideoPtr pVideo, const std::wstring& fileName,
							InputPtr pInput, const GS_KEY escapeKey)
{
	if (!pVideo)
	{
		ShowMessage(L"Invalid video handler - gs2d::PlayCutscene", GSMT_ERROR);
		return GSPI_FAILED;
	}

	GS_PLAYER_INFO info = GSPI_FINISHED;
	//pVideo->TurnLoopManagerOff();

	const bool rendering = pVideo->Rendering();
	if (rendering)
		pVideo->EndSpriteScene();

	PlayerPtr player = CreatePlayer(pVideo, fileName);
	if (!player)
	{
		ShowMessage(L"Failed while trying to load the video - gs2d::PlayCutscene", GSMT_ERROR);
		if (rendering)
			pVideo->BeginSpriteScene();
		return GSPI_FAILED;
	}

	pVideo->EnableMediaPlaying(true);
	player->SetFullscreen();
	player->Rewind();
	player->Play();

	while (!player->IsFinished())
	{
		player->UpdateVideo();
		const Video::APP_STATUS status = pVideo->HandleEvents();
		if (status == Video::APP_QUIT)
		{
			info = GSPI_CLOSE_WINDOW;
			break;
		}
		else
		{
			if (status == Video::APP_SKIP)
				continue;
		}

		if (pInput)
		{
			pInput->Update();
			if (pInput->GetKeyState(escapeKey) == GSKS_HIT)
			{
				info = GSPI_SKIPPED;
				break;
			}
		}
	}

	if (rendering)
		pVideo->BeginSpriteScene();

	pVideo->EnableMediaPlaying(false);
	return info;
}
Exemplo n.º 23
0
 int ETH_MACHINE_MAIN_FUNC(int argc, gs2d::str_type::char_t** argv)
#endif
{
	bool compileAndRun, testing, wait;
	ProcParams(argc, argv, compileAndRun, testing, wait);
	ETHScriptWrapper::SetArgc(argc);
	ETHScriptWrapper::SetArgv(argv);

	Platform::FileManagerPtr fileManager(new Platform::StdFileManager());

	Platform::FileIOHubPtr fileIOHub = Platform::CreateFileIOHub(fileManager, ETHDirectories::GetBitmapFontDirectory());
	{
		const str_type::string resourceDirectory = FindResourceDir(argc, argv);
		if (!resourceDirectory.empty())
			fileIOHub->SetResourceDirectory(resourceDirectory);
	}
	const str_type::string resourceDirectory = fileIOHub->GetResourceDirectory(); 

	const ETHAppEnmlFile app(resourceDirectory + ETH_APP_PROPERTIES_FILE, Platform::FileManagerPtr(new Platform::StdFileManager), Application::GetPlatformName());
	const str_type::string bitmapFontPath = resourceDirectory + ETHDirectories::GetBitmapFontDirectory();

	bool aborted;
	{
		ETHEnginePtr application = ETHEnginePtr(new ETHEngine(testing, compileAndRun));
		application->SetHighEndDevice(true);

		VideoPtr video;
		if ((video = CreateVideo(
			app.GetWidth(),
			app.GetHeight(),
			app.GetTitle(),
			app.IsWindowed(),
			app.IsVsyncEnabled(),
			fileIOHub,
			Texture::PF_UNKNOWN,
			false)))
		{
			InputPtr input = CreateInput(0, false);
			AudioPtr audio = CreateAudio(0);

			application->Start(video, input, audio);

			if (compileAndRun)
			{
				Video::APP_STATUS status;
				while ((status = video->HandleEvents()) != Video::APP_QUIT)
				{
					if (status == Video::APP_SKIP)
						continue;

					input->Update();
					if (application->Update(Min(static_cast<unsigned long>(1000), ComputeElapsedTime(video))) == Application::APP_QUIT)
					{
						break;
					}
					application->RenderFrame();
				}
			}
		}
		application->Destroy();	
		aborted = application->Aborted();
	}

	if (aborted)
	{
		ETH_STREAM_DECL(ss) << std::endl << GS_L("The program executed an ilegal operation and was aborted");
		GS2D_CERR << ss.str() << std::endl;
	}

	if (!compileAndRun && !aborted)
	{
		ETH_STREAM_DECL(ss) << std::endl << GS_L("Compilation successful: 0 errors");
		GS2D_CERR << ss.str() << std::endl;
	}

	if (aborted && wait)
	{
		GS2D_COUT << GS_L("Press any key to continue...") << GS_L("\n");
		std::cin.get();
	}

	#if defined(_DEBUG) || defined(DEBUG)
	 #ifdef WIN32
	  _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
	  #endif
	#endif
	return 0;
}