![]() |
Shadowrun: Awakened 29 September 2011 - Build 871
|
00001 /* 00002 Copyright 2005-2010 Intel Corporation. All Rights Reserved. 00003 00004 This file is part of Threading Building Blocks. 00005 00006 Threading Building Blocks is free software; you can redistribute it 00007 and/or modify it under the terms of the GNU General Public License 00008 version 2 as published by the Free Software Foundation. 00009 00010 Threading Building Blocks is distributed in the hope that it will be 00011 useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00012 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with Threading Building Blocks; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 00019 As a special exception, you may use this file as part of a free software 00020 library without restriction. Specifically, if other files instantiate 00021 templates or use macros or inline functions from this file, or you compile 00022 this file and link it with other files to produce an executable, this 00023 file does not by itself cause the resulting executable to be covered by 00024 the GNU General Public License. This exception does not however 00025 invalidate any other reasons why the executable file might be covered by 00026 the GNU General Public License. 00027 */ 00028 00029 #ifndef __VIDEO_H__ 00030 #define __VIDEO_H__ 00031 00032 #include <cassert> 00033 #if _WIN32 || _WIN64 00034 #include <windows.h> 00035 #else 00036 #include <unistd.h> 00037 #endif 00038 00039 typedef unsigned int color_t; 00040 typedef unsigned char colorcomp_t; 00041 00043 class video 00044 { 00046 char depth, red_shift, green_shift, blue_shift; 00047 color_t red_mask, green_mask, blue_mask; 00048 friend class drawing_area; 00049 00050 public: 00052 video(); 00054 ~video(); 00056 const char *title; 00058 bool calc_fps; 00060 bool threaded; 00062 bool running; 00064 bool updating; 00066 bool init_window(int sizex, int sizey); 00068 bool init_console(); 00070 void terminate(); 00072 void main_loop(); 00074 bool next_frame(); 00076 void show_title(); 00078 inline color_t get_color(colorcomp_t red, colorcomp_t green, colorcomp_t blue) const; 00079 00081 virtual void on_mouse(int x, int y, int key) { } 00083 virtual void on_key(int key) { } 00085 virtual void on_process() { while(next_frame()); } 00086 00087 #ifdef _WINDOWS 00088 00089 00090 static HINSTANCE win_hInstance; static int win_iCmdShow; 00092 void win_set_class(WNDCLASSEX &); 00094 void win_load_accelerators(int idc); 00095 #endif 00096 }; 00097 00099 class drawing_area 00100 { 00101 const size_t base_index, max_index, index_stride; 00102 const char pixel_depth; 00103 unsigned int * const ptr32; 00104 size_t index; 00105 public: 00106 const int start_x, start_y, size_x, size_y; 00108 drawing_area(int x, int y, int sizex, int sizey); 00110 ~drawing_area(); 00112 inline void set_pos(int local_x, int local_y); 00114 inline void put_pixel(color_t color); 00116 void set_pixel(int localx, int localy, color_t color) 00117 { set_pos(localx, localy); put_pixel(color); } 00118 }; 00119 00120 inline color_t video::get_color(colorcomp_t red, colorcomp_t green, colorcomp_t blue) const 00121 { 00122 if(red_shift == 16) // only for depth == 24 && red_shift > blue_shift 00123 return (red<<16) | (green<<8) | blue; 00124 else if(depth >= 24) 00125 return (red<<red_shift) | (green<<green_shift) | (blue<<blue_shift); 00126 else if(depth > 0) { 00127 register char bs = blue_shift, rs = red_shift; 00128 if(blue_shift < 0) blue >>= -bs, bs = 0; 00129 else /*red_shift < 0*/ red >>= -rs, rs = 0; 00130 return (red<<rs)&red_mask | (green<<green_shift)&green_mask | (blue<<bs)&blue_mask; 00131 } else { // UYVY colorspace 00132 register unsigned y, u, v; 00133 y = red * 77 + green * 150 + blue * 29; // sum(77+150+29=256) * max(=255): limit->2^16 00134 u = (2048 + (blue << 3) - (y >> 5)) >> 4; // (limit->2^12)>>4 00135 v = (2048 + (red << 3) - (y >> 5)) >> 4; 00136 y = y >> 8; 00137 return u | (y << 8) | (v << 16) | (y << 24); 00138 } 00139 } 00140 00141 inline void drawing_area::set_pos(int local_x, int local_y) 00142 { 00143 index = base_index + local_x + local_y*index_stride; 00144 } 00145 00146 inline void drawing_area::put_pixel(color_t color) 00147 { 00148 assert(index < max_index); 00149 if(pixel_depth > 16) ptr32[index++] = color; 00150 else if(pixel_depth > 0) 00151 ((unsigned short*)ptr32)[index++] = (unsigned short)color; 00152 else { // UYVY colorspace 00153 if(index&1) color >>= 16; 00154 ((unsigned short*)ptr32)[index++] = (unsigned short)color; 00155 } 00156 } 00157 00158 #if defined(_WINDOWS) && (defined(VIDEO_WINMAIN) || defined(VIDEO_WINMAIN_ARGS) ) 00159 #include <cstdlib> 00161 #ifdef VIDEO_WINMAIN_ARGS 00162 int main(int, char *[]); 00163 #else 00164 int main(); 00165 #endif 00166 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR szCmdLine, int iCmdShow) 00167 { 00168 video::win_hInstance = hInstance; video::win_iCmdShow = iCmdShow; 00169 #ifdef VIDEO_WINMAIN_ARGS 00170 return main(__argc, __argv); 00171 #else 00172 return main(); 00173 #endif 00174 } 00175 #endif 00176 00177 #endif// __VIDEO_H__
Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.