//Function to get the OpenGL information
void GameDebugger::GetGLInfo(ALLEGRO_DISPLAY* mydisplay)
{
    fprintf(OutputFile, "\n\n -- Display Information -- \n\n");
#ifdef _DEBUG
    printf("\n\n -- Display Information -- \n\n");
#endif

    char* glrinfo = NULL;
    HWND winHandle = al_get_win_window_handle(mydisplay);
    HDC myAdapter = GetDC(winHandle);

    //HGLRC hRC = wglCreateContext(myAdapter);
    HGLRC hRC = wglGetCurrentContext();
    if(!wglMakeCurrent(myAdapter, hRC))
    {
        Log("Could not retrieve OpenGL information!\nHWND: 0x%0x HDC: 0x%0x HGLRC: 0x%0x \n\n", info_type_error, winHandle, myAdapter, hRC);
        return;
    }

    glrinfo = (char*)glGetString(GL_RENDERER);
    fprintf(OutputFile, "GPU Vendor: %s\n", glrinfo);
    fprintf(OutputFile, "Renderer: OpenGL\n\n");

#ifdef _DEBUG
	printf("GPU Vendor: %s\n", glrinfo);
    printf("Renderer: OpenGL\n\n");
#endif

    //wglDeleteContext(hRC);
    return;
}
Exemple #2
0
int _al_show_native_message_box(ALLEGRO_DISPLAY *display,
   ALLEGRO_NATIVE_DIALOG *fd)
{
   UINT type = 0;
   int result;

   uint16_t *wide_text, *wide_title;
   size_t text_len, title_len;

   /* Note: the message box code cannot assume that Allegro is installed. */

   if (fd->flags & ALLEGRO_MESSAGEBOX_QUESTION)
      type |= MB_ICONQUESTION;
   else if (fd->flags & ALLEGRO_MESSAGEBOX_WARN)
      type |= MB_ICONWARNING;
   else if (fd->flags & ALLEGRO_MESSAGEBOX_ERROR) 
      type |= MB_ICONERROR;
   else 
      type |= MB_ICONINFORMATION;

   if (fd->flags & ALLEGRO_MESSAGEBOX_YES_NO)
      type |= MB_YESNO;
   else if (fd->flags & ALLEGRO_MESSAGEBOX_OK_CANCEL)
      type |= MB_OKCANCEL;

   /* heading + text are combined together */

   if (al_ustr_size(fd->mb_heading)) 
      al_ustr_append_cstr(fd->mb_heading, "\n\n");

   al_ustr_append(fd->mb_heading, fd->mb_text);

   text_len = al_ustr_size_utf16(fd->mb_heading);
   title_len = al_ustr_size_utf16(fd->title);

   wide_text = al_malloc(text_len + 1);
   if (!wide_text)
      return 0;

   wide_title = al_malloc(title_len + 1);
   if (!wide_title) {
      al_free(wide_text);
      return 0;
   }

   al_ustr_encode_utf16(fd->mb_heading, wide_text, text_len);
   al_ustr_encode_utf16(fd->title, wide_title, title_len);

   result = MessageBoxW(al_get_win_window_handle(display),
      (LPCWSTR) wide_text, (LPCWSTR) wide_title, type);

   al_free(wide_text);
   al_free(wide_title);

   if (result == IDYES || result == IDOK)
      return 1;
   else
      return 0;
}
bool ImGui_ImplA5_Init(ALLEGRO_DISPLAY* display)
{
    g_Display = display;
   
    // Create custom vertex declaration. 
    // Unfortunately Allegro doesn't support 32-bits packed colors so we have to convert them to 4 floats.
    // We still use a custom declaration to use 'ALLEGRO_PRIM_TEX_COORD' instead of 'ALLEGRO_PRIM_TEX_COORD_PIXEL' else we can't do a reliable conversion.
    ALLEGRO_VERTEX_ELEMENT elems[] = 
    {
        { ALLEGRO_PRIM_POSITION, ALLEGRO_PRIM_FLOAT_2, OFFSETOF(ImDrawVertAllegro, pos) },
        { ALLEGRO_PRIM_TEX_COORD, ALLEGRO_PRIM_FLOAT_2, OFFSETOF(ImDrawVertAllegro, uv) },
        { ALLEGRO_PRIM_COLOR_ATTR, 0, OFFSETOF(ImDrawVertAllegro, col) },
        { 0, 0, 0 }
    };
    g_VertexDecl = al_create_vertex_decl(elems, sizeof(ImDrawVertAllegro));

    ImGuiIO& io = ImGui::GetIO();
    io.KeyMap[ImGuiKey_Tab] = ALLEGRO_KEY_TAB;
    io.KeyMap[ImGuiKey_LeftArrow] = ALLEGRO_KEY_LEFT;
    io.KeyMap[ImGuiKey_RightArrow] = ALLEGRO_KEY_RIGHT;
    io.KeyMap[ImGuiKey_UpArrow] = ALLEGRO_KEY_UP;
    io.KeyMap[ImGuiKey_DownArrow] = ALLEGRO_KEY_DOWN;
    io.KeyMap[ImGuiKey_PageUp] = ALLEGRO_KEY_PGUP;
    io.KeyMap[ImGuiKey_PageDown] = ALLEGRO_KEY_PGDN;
    io.KeyMap[ImGuiKey_Home] = ALLEGRO_KEY_HOME;
    io.KeyMap[ImGuiKey_End] = ALLEGRO_KEY_END;
    io.KeyMap[ImGuiKey_Delete] = ALLEGRO_KEY_DELETE;
    io.KeyMap[ImGuiKey_Backspace] = ALLEGRO_KEY_BACKSPACE;
    io.KeyMap[ImGuiKey_Enter] = ALLEGRO_KEY_ENTER;
    io.KeyMap[ImGuiKey_Escape] = ALLEGRO_KEY_ESCAPE;
    io.KeyMap[ImGuiKey_A] = ALLEGRO_KEY_A;
    io.KeyMap[ImGuiKey_C] = ALLEGRO_KEY_C;
    io.KeyMap[ImGuiKey_V] = ALLEGRO_KEY_V;
    io.KeyMap[ImGuiKey_X] = ALLEGRO_KEY_X;
    io.KeyMap[ImGuiKey_Y] = ALLEGRO_KEY_Y;
    io.KeyMap[ImGuiKey_Z] = ALLEGRO_KEY_Z;

    io.RenderDrawListsFn = ImGui_ImplA5_RenderDrawLists;        // Alternatively you can set this to NULL and call ImGui::GetDrawData() after ImGui::Render() to get the same ImDrawData pointer.
#ifdef _WIN32
    io.ImeWindowHandle = al_get_win_window_handle(g_Display);
#endif

    return true;
}
Exemple #4
0
int main(int argc, char **argv) {

	Renderer* r = NULL;
	try {
		r = new Renderer(800, 600);
	
		EventQueue ev(r);
	
		CharacterManager cm;
		r->SetCharManager(&cm);

		Player player = Player(10, 10, "Dann Von Veigar");
		player.SetEventQueue(&ev);

		Item it = Item("Insígnia do MC Bin Laden", "insignia do mestre Bin Laden", 3000);
		player.AddItem(&it);

		Sprite s = Sprite("..\\characters\\dann.png", 1.5f, 0);
		player.SetSprite(&s);

		Asura asu = Asura{ 0,0 };
		Akhbran ahk = Akhbran{ 0,0 };

		CharFactory* cf = new CharFactory(&cm);

		Tree t = Tree(20, 20);
		Sprite stree = Sprite("..\\characters\\arvore1.png", 1, 60, 80);
		t.SetSprite(&stree);

		cf->RegisterCharacter(t.GetTypeID(), &t);


		cm.AddCharacter(&player);
		cm.SetPlayer(&player);

		
		/*
		cm.AddCharacter(cf->PutCharacter(t.GetTypeID(), 3, 8));
		cm.AddCharacter(cf->PutCharacter(t.GetTypeID(), 6, 11));
		cm.AddCharacter(cf->PutCharacter(t.GetTypeID(), 9, 20));
		cm.AddCharacter(cf->PutCharacter(t.GetTypeID(), 12, 25));
		cm.AddCharacter(cf->PutCharacter(t.GetTypeID(), 15, 20));
		cm.AddCharacter(cf->PutCharacter(t.GetTypeID(), 18, 11));
		cm.AddCharacter(cf->PutCharacter(t.GetTypeID(), 21, 8));
		cm.AddCharacter(cf->PutCharacter(t.GetTypeID(), 24, 11));
		cm.AddCharacter(cf->PutCharacter(t.GetTypeID(), 27, 20));
		*/

		cm.AddCharacter(&asu);
		cm.AddCharacter(&ahk);

		Map* m;
		Map::LoadTiles();

		MapOpener mpop;
		m = mpop.Open("..\\maps\\map2.map");		

		if (!m) {
			char strmaperr[32];
			sprintf_s(strmaperr, 32, "Erro ao abrir o mapa!");
			throw std::runtime_error(strmaperr);
		}


		int px, py;
		m->GetInitialPlayerPos(px, py);

		float fx = px, fy = py;
		player.SetPosition(fx, fy);


		std::vector<CharacterData>* chd = m->GetCharData();

		if (chd->size() > 0) {
			for (auto i = chd->begin(); i != chd->end(); i++) {
				cm.AddCharacter(cf->PutCharacter(i->Type, i->XPos, i->YPos));
			}

		}

		r->SetMap(m);
		cm.SetMap(m);

		HUD* hud = new HUD(&player);
		r->SetHUD(hud);

	

		bool render = true;

		double fps = (1/60), start_time, end_time;

		float start_animations = al_get_time();
		float start_events = al_get_time();

		float playerdx = 0, playerdy = 0;

		start_time = al_get_time();

		while (render) {
			
			//Run events in 15fps.
			float end_events = al_get_time();
			if ((end_events - start_events) >= 1/15.0f){
				cm.DoAllEvents();
				start_events - end_events;
			}

			//Processa eventos
			if (!ev.CheckEvents()) {
				render = false;
			}


			player.Control(m);
			Event e;

			if (ev.PopEvent(e)) {

				switch (e.keycode) {

				case ALLEGRO_KEY_I:

					if (e.keyletter != 'i') continue;

					//Enumera os itens no inventário do player.
					std::vector<Item*>* list;
					player.GetAllItems(&list);

					std::stringstream line;

					for (auto i = list->begin();
					i != list->end();
						i++) {
						std::string name;
						(*i)->GetName(name);
						line << (*i)->GetID() << " - " << name << " - " << (*i)->GetValue() << " money" << std::endl;
					
					}

					MessageBoxA(al_get_win_window_handle(r->GetDisplay()), line.str().c_str(), "Inventário", 0);

					break;


				}

				
			}

			float end_animations = al_get_time();
			/* Run animations in 5 fps by default. */
			if ((end_animations - start_animations) >= 1/5.0f) {
				player.Andar(playerdx, playerdy);
				asu.Andar(playerdx, playerdy);
				ahk.Andar(playerdx, playerdy);
				playerdx = 0;
				playerdy = 0;
				start_animations = end_animations;

			}

			cm.DoAllEvents();
			
			//Os renderiza
			r->Render();


			end_time = al_get_time();

			if ((end_time - start_time) < fps) {
				double delta = (end_time - start_time);
				Sleep((fps - delta) * 1000);
				
			}
			//printf("\r%.5f ms", end_time - start_time);
			
			start_time = al_get_time();

			frames++;
		}


	}
	catch (std::runtime_error& e) {
		if (r)
			MessageBoxA(r->GetDisplay() ? al_get_win_window_handle(r->GetDisplay()) : NULL,
				e.what(), "Dois Demônios - Erro", MB_ICONERROR);
		else
			MessageBoxA(NULL, e.what(), "Dois Demônios - Erro", MB_ICONERROR);
		return -1;
	}

	delete r;
	return 0;
}
/** Does the message box thingy to show the error.
 *
 * @returns True if program should continue going forward.
 */
bool ErrorSystem::execLastError() {
	if (errorCount == 0) return true;

	string concatError = lastError.title + " -- " + lastError.heading;
	if (lastError.message != "") {
		concatError += " -- " + lastError.message;
	}

	// If this error is not fatal and it is set to be suppressed, return true here already
	if (!lastError.fatal && this->isSuppressed(concatError)) {
		return true;
	}

#ifdef _WIN32
	// Windows wants it's console output in codepage 1252
	std::cerr << utf8toCP1252(concatError) << std::endl;
#else
	std::cerr << concatError << std::endl;
#endif

	if (lastError.fatal) {
		al_show_native_message_box(
					cb->gfxInterface->getWindow(),
					lastError.title.c_str(),
					lastError.heading.c_str(),
					lastError.message.c_str(),
					NULL,
					ALLEGRO_MESSAGEBOX_ERROR
		);
		cb->stop();
		return false;
	}
#ifndef _WIN32 // Allegro doesn't support custom messagebox buttons with Windows
	int ret = al_show_native_message_box(
				cb->gfxInterface->getWindow(),
				lastError.title.c_str(),
				lastError.heading.c_str(),
				lastError.message.c_str(),
				"Abort|Continue|Suppress this error",
				ALLEGRO_MESSAGEBOX_OK_CANCEL
	);
	switch (ret) {
		case 0: // No buttons clicked
		case 2: // User clicked continue
			return true;
		case 1: // User clicked abort
			cb->stop();
			return false;
		case 3: // Suppress errors
			this->suppressError(concatError);
			return true;
		default:
			FIXME("Undefined messagebox return value %i in ErrorSystem::execLastError()", ret);
			cb->stop();
			return false;
	}
#else
	string message;
	if (lastError.message.empty()) {
		message = lastError.heading;
	}
	else {
		message = lastError.heading + "\n\n" + lastError.message;
	}

	// Convert message and title to utf-16 with the amazing UTF8-CPP library
	wstring wideMsg = utf8ToUtf16(message);
	wstring wideTitle = utf8ToUtf16(lastError.title);

    int ret = CBTMessageBox(al_get_win_window_handle(cb->gfxInterface->getWindow()), &wideMsg[0], &wideTitle[0], MB_ABORTRETRYIGNORE | MB_ICONERROR);
	switch (ret) {
		case 0: // No buttons clicked
		case IDRETRY: // User clicked continue
			return true;
		case IDABORT: // User clicked abort
			cb->stop();
			return false;
		case IDIGNORE: // Suppress errors
			this->suppressError(concatError);
			return true;
		default:
			FIXME("Undefined messagebox return value %i in ErrorSystem::execLastError()", ret);
			cb->stop();
			return false;
	}
#endif // _WIN32
}