如何解决Allegro 5,保持控制台焦点
我正在运行Allegro 5测试代码段(如下所示)。它可以编译并运行良好,但是我想查看控制台输出(在这种情况下只是一个愚蠢的递增数字),但是Allegro切换到其他Z-Order对象...
这是C ++代码。
#include <allegro5/allegro.h>
#include <allegro5/allegro_audio.h>
#include <allegro5/allegro_acodec.h>
#include <iostream> // std::std::cout
#include <thread> // std::thread
#include <unistd.h>
#include <mutex> // std::mutex
#include <cstdio>
std::mutex mtx; //mutex for critical section
int play_audio()
{
if (!al_init()) {
return 1;
}
if (!al_install_audio()) {
return 2;
}
if (!al_init_acodec_addon()) {
return 3;
}
if (!al_reserve_samples(1)) {
return 4;
}
set_display_switch_mode(SWITCH_PAUSE);
ALLEGRO_SAMPLE *idle_sound = al_load_sample("leaving.wav");
ALLEGRO_SAMPLE_INSTANCE *sample_instance = al_create_sample_instance(idle_sound);
if (!idle_sound || !sample_instance) {
printf("Setup error.\n");
return 5;
}
ALLEGRO_SAMPLE_ID sample_id;
mtx.lock();
if (!al_play_sample(idle_sound,1.0,0.0,ALLEGRO_PLAYMODE_ONCE,&sample_id)) {
printf("Failed to play sample.\n");
}
if (!al_play_sample_instance(sample_instance)) {
printf("Failed to play sample instance.\n");
}
al_rest(5.0);
al_destroy_sample_instance(sample_instance);
al_destroy_sample(idle_sound);
std::cout << "Thread I have finished" << std::endl;
mtx.unlock();
return 1;
}
int main (int argc,char **argv)
{
int n = 1;
printf("creating thread\n ");
std::thread t_audio(play_audio);
sleep(1);
while (!mtx.try_lock()) {
// Still can not lock this mutex
printf("N is %d\n",n);
n += 1;
sleep(1);
}
// Ha ha ... we locked it - the other code must be done
t_audio.join();
mtx.unlock();
printf("Main closing\n");
printf("All done... Closing\n");
return (0);
}
我是这样建造的
Makefile
obj = allegro audio2
CPPFLAGS += -I/usr/local/include
LDFLAGS += -L/usr/local/lib
LDLIBS += -lallegro
LDLIBS += -lallegro_main
LDLIBS += -lallegro_audio
LDLIBS += -lallegro_acodec
.PHONY: all
all : $(obj)
.PHONE: clean
clean:
rm -f $(obj)
allegro: allegro.cpp
audio2: audio2.cpp
运行时...控制台屏幕将输出我期望的结果...
creating thread
N is 1
N is 2
N is 3
N is 4
N is 5
Thread I have finished
Main closing
All done... Closing
但是我需要将Tab键重新回到终端机/控制台-有什么办法可以让我保持专注吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。