#!/usr/bin/env perl ############################################################################# ## ## Copyright (C) 2016 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## ## This file is part of the test suite of the Qt Toolkit. ## ## $QT_BEGIN_LICENSE:GPL-EXCEPT$ ## Commercial License Usage ## Licensees holding valid commercial Qt licenses may use this file in ## accordance with the commercial license agreement provided with the ## Software or, alternatively, in accordance with the terms contained in ## a written agreement between you and The Qt Company. For licensing terms ## and conditions see https://www.qt.io/terms-conditions. For further ## information use the contact form at https://www.qt.io/contact-us. ## ## GNU General Public License Usage ## Alternatively, this file may be used under the terms of the GNU ## General Public License version 3 as published by the Free Software ## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT ## included in the packaging of this file. Please review the following ## information to ensure the GNU General Public License requirements will ## be met: https://www.gnu.org/licenses/gpl-3.0.html. ## ## $QT_END_LICENSE$ ## #############################################################################
# Where do we run this script? What directory? $SEARCH_PATH=$ARGV[0]; if(!$SEARCH_PATH) { print"Please specify the search directory! \n"; exit(0); }
# We have four options: # 'U': Unix # 'W': Windows # 'M': Mac # 'E': Embedded $EXEC_MODE=$ARGV[1]; if($EXEC_MODE =~ /^U$/) { print"Using Unix execution mode\n"; $EXE_PREFIX="./"; $EXE_SUFFIX=""; } elsif($EXEC_MODE =~ /^W$/) { print"Using Windows execution mode\n"; $EXE_PREFIX=""; $EXE_SUFFIX=".exe"; } elsif($EXEC_MODE =~ /^M$/) { print"Using OSX execution mode\n"; $EXE_PREFIX="/Contents/MacOS/"; $EXE_SUFFIX=".app"; } elsif($EXEC_MODE =~ /^E$/) { print"Using embedded execution mode\n"; $EXE_PREFIX="./"; $EXE_SUFFIX=""; } else { print"Unknown execution mode: $EXEC_MODE \n"; print"Use: 'U' (Unix), 'W' (Windows), 'M' (MacOSX)\n"; exit(0); } # We get the current directory, we 'll need it afterwards $currentDirectory = getcwd();
$testRoot = Cwd::abs_path($SEARCH_PATH);
# We assume that by default goes to "reports" unless the user specifies it. $REPORTDIR = $ARGV[2]; if(!$REPORTDIR) { $REPORTDIR = $testRoot."/reports"; mkdir $REPORTDIR; } else { mkdir $REPORTDIR; $REPORTDIR = Cwd::abs_path($REPORTDIR); }
# If given we use it, otherwise we default to 300 seconds. $TIMEOUT = $ARGV[3]; if(!$TIMEOUT) { $TIMEOUT=300; } print"Timeout value: $TIMEOUT\n";
// c++ // 将容器a按升序排列 template<class T> voidselection_sort(T& a) { int n = a.size(); for (int i=0; i<n; ++i) { int min = i; for (int j=i+1; j<n; ++j) { if (a[j] < a[min]) min = j; }
SDL扩展 SDL_image 支持多种格式图片加载:BMP GIF PNG TGA PCX … SDL_net 跨平台网络库 SDL_mixer audio mixer library. 支持MP3 MIDI OGG SDL_ttf 支持TrueType字体 SDL_rtf support the rendering of the Rich Text Format (RTF).
SDL_Init() 初始化标识
1 2 3 4 5 6 7
SDL_INIT_HAPTIC Force feedback subsystem 力反馈 SDL_INIT_AUDIO Audio subsystem SDL_INIT_VIDEO Video subsystem SDL_INIT_TIMER Timer subsystem SDL_INIT_JOYSTICK Joystick subsystem SDL_INIT_EVERYTHING All subsystems SDL_INIT_noparachute Don't catch fatal signals
查看一个子系统是否已被初始化:
1 2
if (SDL_WasInit(SDL_INIT_VIDEO) != 0) cout << "video was initialized";
1 2 3 4 5
SDL_CreateRenderer() SDL_RENDERER_SOFTWARE Use software rendering SDL_RENDERER_ACCELERATED Use hardware acceleration SDL_RENDERER_PRESENTVSYNC Synchronize renderer update with screen's refresh rate SDL_RENDERER_TARGETTEXTURE Supports render to texture
游戏程序结构 初始化 游戏循环:获取输入 物理运算 渲染 退出
window flags
1 2 3 4 5 6 7 8 9 10 11 12
SDL_WINDOW_FULLSCREEN Make the window fullscreen SDL_WINDOW_OPENGL Window can be used with as an OpenGL context SDL_WINDOW_SHOWN The window is visible SDL_WINDOW_HIDDEN Hide the window SDL_WINDOW_BORDERLESS No border on the window SDL_WINDOW_RESIZABLE Enable resizing of the window SDL_WINDOW_MINIMIZED Minimize the window SDL_WINDOW_MAXIMIZED Maximize the window SDL_WINDOW_INPUT_GRABBED Window has grabbed input focus SDL_WINDOW_INPUT_FOCUS Window has input focus SDL_WINDOW_MOUSE_FOCUS Window has mouse focus SDL_WINDOW_FOREIGN The window was not created using SDL
Fixed frames per second (FPS) is not necessarily always a good option, especially when your game includes more advanced physics. It is worth bearing this in mind when you move on from this book and start developing your own games. Fixed FPS will, however, be fine for the small 2D games, which we will work towards in this book.
SDL joystick event SDL_JoyAxisEvent Axis motion information SDL_JoyButtonEvent Button press and release information SDL_JoyBallEvent Trackball event motion information SDL_JoyHatEvent Joystick hat position change
SDL joystick event Type value SDL_JoyAxisEvent SDL_JOYAXISMOTION SDL_JoyButtonEvent SDL_JOYBUTTONDOWN or SDL_JOYBUTTONUP SDL_JoyBallEvent SDL_JOYBALLMOTION SDL_JoyHatEvent SDL_JOYHATMOTION
不同的游戏控制器 按钮和轴可能有不同的值 比如Xbox360 controller, PS3 controller Xbox360 controller: Two analog sticks Analog sticks press as buttons Start and Select buttons Four face buttons: A, B, X, and Y Four triggers: two digital and two analog A digital directional pad
1 2 3 4 5 6 7 8 9 10 11 12 13 14
if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) SDL_InitSubSystem(SDL_INIT_JOYSTICK); if (SDL_NumJoysticks() > 0) { for (int i=0; i<SDL_NumJoysticks(); ++i) { SDL_Joystick* joy = SDL_JoystickOpen(i); if (SDL_JoystickOpened(i) == 1) m_joysticks.push_back(joy); } SDL_JoystickEventState(SDL_ENABLE); }
SDL_JoystickClose(joy);
分辨是哪个控制器的事件
1 2
if (event.type == SDL_JOYAXISMOTION) int whichOne = event.jaxis.which;
SDL Mouse Event Purpose SDL_MouseButtonEvent A button on the mouse has been pressed or released SDL_MouseMotionEvent The mouse has been moved SDL_MouseWheelEvent The mouse wheel has moved
SDL Mouse Event Type Value SDL_MouseButtonEvent SDL_MOUSEBUTTONDOWN or SDL_MOUSEBUTTONUP SDL_MouseMotionEvent SDL_MOUSEMOTION SDL_MouseWheelEvent SDL_MOUSEWHEEL
1 2 3 4 5
// 鼠标按钮 // SDL numbers these as 0 for left, 1 for middle, and 2 for right.
if (event.type == SDL_MOUSEBUTTONDOWN) if (event.button.button == SDL_BUTTON_LEFT)