diff --git a/examples/nxtext/nxtext_main.c b/examples/nxtext/nxtext_main.c index bee9e90db..b1a795484 100644 --- a/examples/nxtext/nxtext_main.c +++ b/examples/nxtext/nxtext_main.c @@ -406,7 +406,7 @@ int nxtext_main(int argc, char **argv) ret = nx_requestbkgd(g_hnx, &g_nxtextcb, bgstate); if (ret < 0) { - printf("nxtext_main: nx_setbgcolor failed: %d\n", errno); + printf("nxtext_main: nx_requestbkgd failed: %d\n", errno); g_exitcode = NXEXIT_NXREQUESTBKGD; goto errout_with_nx; } diff --git a/examples/nxtext/nxtext_server.c b/examples/nxtext/nxtext_server.c index 6b5f7145d..ff3041a69 100644 --- a/examples/nxtext/nxtext_server.c +++ b/examples/nxtext/nxtext_server.c @@ -60,7 +60,7 @@ #ifdef CONFIG_NX_MULTIUSER /**************************************************************************** - * Definitions + * Pre-processor Definitions ****************************************************************************/ /**************************************************************************** diff --git a/graphics/Kconfig b/graphics/Kconfig index a10650e27..74f084956 100644 --- a/graphics/Kconfig +++ b/graphics/Kconfig @@ -15,4 +15,20 @@ menu "TIFF Screenshot Utility" source "$APPSDIR/graphics/screenshot/Kconfig" endmenu -endif +endif # TIFF + +config GRAPHICS_TRAVELER + bool "Traveler game" + default n + select SYSTEM_INIFILE + ---help--- + Enable or disable the graphic Traveler game + +if GRAPHICS_TRAVELER + +menu "Traveler game" +source "$APPSDIR/graphics/traveler/Kconfig" +endmenu + +endif # GRAPHICS_TRAVELER + diff --git a/graphics/Make.defs b/graphics/Make.defs index 8f940cbad..987c387b6 100644 --- a/graphics/Make.defs +++ b/graphics/Make.defs @@ -41,3 +41,7 @@ endif ifeq ($(CONFIG_GRAPHICS_SCREENSHOT),y) CONFIGURED_APPS += graphics/screenshot endif + +ifeq ($(CONFIG_GRAPHICS_TRAVELER),y) +CONFIGURED_APPS += graphics/traveler +endif diff --git a/graphics/Makefile b/graphics/Makefile index 7503c4343..7f33fe2a4 100644 --- a/graphics/Makefile +++ b/graphics/Makefile @@ -37,7 +37,7 @@ # Sub-directories -SUBDIRS = tiff screenshot +SUBDIRS = tiff screenshot traveler # Sub-directories that might need context setup diff --git a/graphics/traveler/.gitignore b/graphics/traveler/.gitignore new file mode 100644 index 000000000..83bd7b811 --- /dev/null +++ b/graphics/traveler/.gitignore @@ -0,0 +1,11 @@ +/Make.dep +/.depend +/.built +/*.asm +/*.rel +/*.lst +/*.sym +/*.adb +/*.lib +/*.src +/*.obj diff --git a/graphics/traveler/Kconfig b/graphics/traveler/Kconfig new file mode 100644 index 000000000..47dd09c1b --- /dev/null +++ b/graphics/traveler/Kconfig @@ -0,0 +1,71 @@ +# +# For a description of the syntax of this configuration file, +# see misc/tools/kconfig-language.txt. +# + +if GRAPHICS_TRAVELER + +choice + prompt "Color format" + default GRAPHICS_TRAVELER_RGB16_565 + +config GRAPHICS_TRAVELER_RGB16_565 + bool "RGB16 565" + +config GRAPHICS_TRAVELER_RGB32_888 + bool "RGB32 888 (no transparency)" + +endchoice # Color format + +config GRAPHICS_TRAVELER_JOYSTICK + bool + default n + +choice + prompt "Input device" + default GRAPHICS_TRAVELER_AJOYSTICK if CONFIG_AJOYSTICK + default GRAPHICS_TRAVELER_DJOYSTICK if CONFIG_DJOYSTICK && !CONFIG_AJOYSTICK + default GRAPHICS_TRAVELER_NX_XYINPUT if CONFIG_NX_XYINPUT && !CONFIG_AJOYSTICK && !CONFIG_DJOYSTICK + +config GRAPHICS_TRAVELER_AJOYSTICK + bool "Analog joystick" + depends on CONFIG_AJOYSTICK + select GRAPHICS_TRAVELER_JOYSTICK + +config GRAPHICS_TRAVELER_DJOYSTICK + bool "Discrete joystick" + depends on CONFIG_DJOYSTICK + select GRAPHICS_TRAVELER_JOYSTICK + +config GRAPHICS_TRAVELER_NX_XYINPUT + bool "NX X/Y input" + depends on CONFIG_NX_XYINPUT + +endchoice # Input device + +config GRAPHICS_TRAVELER_JOYDEV + string "Joystick device name" + default "/dev/ajoy0" if GRAPHICS_TRAVELER_AJOYSTICK + default "/dev/djoy0" if GRAPHICS_TRAVELER_DJOYSTICK + depends on GRAPHICS_TRAVELER_JOYSTICK + +config GRAPHICS_TRAVELER_PERFMON + bool "Performance monitor" + default y + depends on FS_READABLE + ---help--- + Enable or disable performance monitoring instrumentation and output. + +config GRAPHICS_TRAVELER_DEBUG_LEVEL + int "Debug output level" + default 0 + range 0 3 + ---help--- + DEBUG_LEVEL == 3 turns off sound and video and enables verbose debug + messages on stdout. + DEBUG_LEVEL == 2 turns off sound and video and enables normal debug + output + DEBUG_LEVEL == 1 turns off sound and enables normal debug output + OTHERWISE, all debugging features are disabled. + +endif # GRAPHICS_TRAVELER diff --git a/graphics/traveler/Makefile b/graphics/traveler/Makefile new file mode 100644 index 000000000..71dbabeaf --- /dev/null +++ b/graphics/traveler/Makefile @@ -0,0 +1,149 @@ +############################################################################ +# apps/graphics/traveler/Makefile +# +# Copyright (C) 2014 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +-include $(TOPDIR)/.config +-include $(TOPDIR)/Make.defs +include $(APPDIR)/Make.defs + +# Hello, World! built-in application info + +APPNAME = traveler +PRIORITY = SCHED_PRIORITY_DEFAULT +STACKSIZE = 2048 + +# Hello, World! Example + +ASRCS = +CSRCS = trv_color.c trv_graphics.c trv_input.c trv_mem.c +MAINSRC = trv_main.c + +ifeq ($(CONFIG_NX),y) +CSRCS += trv_nxbkgd.c +ifeq ($(CONFIG_NX),y) +CSRCS += trv_nxserver.c +endif +endif + +AOBJS = $(ASRCS:.S=$(OBJEXT)) +COBJS = $(CSRCS:.c=$(OBJEXT)) +MAINOBJ = $(MAINSRC:.c=$(OBJEXT)) + +SRCS = $(ASRCS) $(CSRCS) $(MAINSRC) +OBJS = $(AOBJS) $(COBJS) + +ifneq ($(CONFIG_BUILD_KERNEL),y) + OBJS += $(MAINOBJ) +endif + +ifeq ($(CONFIG_WINDOWS_NATIVE),y) + BIN = ..\..\libapps$(LIBEXT) +else +ifeq ($(WINTOOL),y) + BIN = ..\\..\\libapps$(LIBEXT) +else + BIN = ../../libapps$(LIBEXT) +endif +endif + +ifeq ($(WINTOOL),y) + INSTALL_DIR = "${shell cygpath -w $(BIN_DIR)}" +else + INSTALL_DIR = $(BIN_DIR) +endif + +CONFIG_EXAMPLES_HELLO_PROGNAME ?= hello$(EXEEXT) +PROGNAME = $(CONFIG_EXAMPLES_HELLO_PROGNAME) + +ifeq ($(WINTOOL),y) +INCDIROPT = -w +endif + +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/graphics/traveler/include} + +DEPPATH = --dep-path src +VPATH = src + +# Common build + +all: .built +.PHONY: clean depend distclean + +$(AOBJS): %$(OBJEXT): %.S + $(call ASSEMBLE, $<, $@) + +$(COBJS) $(MAINOBJ): %$(OBJEXT): %.c + $(call COMPILE, $<, $@) + +.built: $(OBJS) + $(call ARCHIVE, $(BIN), $(OBJS)) + @touch .built + +ifeq ($(CONFIG_BUILD_KERNEL),y) +$(BIN_DIR)$(DELIM)$(PROGNAME): $(OBJS) $(MAINOBJ) + @echo "LD: $(PROGNAME)" + $(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $(INSTALL_DIR)$(DELIM)$(PROGNAME) $(ARCHCRT0OBJ) $(MAINOBJ) $(LDLIBS) + $(Q) $(NM) -u $(INSTALL_DIR)$(DELIM)$(PROGNAME) + +install: $(BIN_DIR)$(DELIM)$(PROGNAME) + +else +install: + +endif + +ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) +$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile + $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main) + +context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat +else +context: +endif + +.depend: Makefile $(SRCS) + @$(MKDEP) $(DEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep + @touch $@ + +depend: .depend + +clean: + $(call DELFILE, .built) + $(call CLEAN) + +distclean: clean + $(call DELFILE, Make.dep) + $(call DELFILE, .depend) + +-include Make.dep diff --git a/graphics/traveler/include/trv_bitmaps.h b/graphics/traveler/include/trv_bitmaps.h new file mode 100644 index 000000000..82df0c145 --- /dev/null +++ b/graphics/traveler/include/trv_bitmaps.h @@ -0,0 +1,57 @@ +/**************************************************************************** + * apps/graphics/traveler/include/trv_bitmaps.h + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_BITMAPS_H +#define __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_BITMAPS_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "trv_types.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_BITMAPS_H */ diff --git a/graphics/traveler/include/trv_color.h b/graphics/traveler/include/trv_color.h new file mode 100644 index 000000000..9e8f8abb1 --- /dev/null +++ b/graphics/traveler/include/trv_color.h @@ -0,0 +1,118 @@ +/**************************************************************************** + * apps/graphics/traveler/include/trv_color.h + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_COLOR_H +#define __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_COLOR_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "trv_types.h" +#include "trv_graphics.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#if defined(CONFIG_GRAPHICS_TRAVELER_RGB16_565) +/* This macro creates RGB16 (5:6:5) + * + * R[7:3] -> RGB[15:11] + * G[7:2] -> RGB[10:5] + * B[7:3] -> RGB[4:0] + */ + +# define TRV_MKRGB(r,g,b) \ + ((((uint16_t)(r) << 8) & 0xf800) | (((uint16_t)(g) << 3) & 0x07e0) | (((uint16_t)(b) >> 3) & 0x001f)) + +/* And these macros perform the inverse transformation */ + +# define RGB2RED(rgb) (((rgb) >> 8) & 0xf8) +# define RGB2GREEN(rgb) (((rgb) >> 3) & 0xfc) +# define RGB2BLUE(rgb) (((rgb) << 3) & 0xf8) + +#elif defined(CONFIG_GRAPHICS_TRAVELER_RGB32_888) +/* This macro creates RGB24 (8:8:8) + * + * R[7:3] -> RGB[15:11] + * G[7:2] -> RGB[10:5] + * B[7:3] -> RGB[4:0] + */ + +# define TRV_MKRGB(r,g,b) \ + ((uint32_t)((r) & 0xff) << 16 | (uint32_t)((g) & 0xff) << 8 | (uint32_t)((b) & 0xff)) + +/* And these macros perform the inverse transformation */ + +# define RGB2RED(rgb) (((rgb) >> 16) & 0xff) +# define RGB2GREEN(rgb) (((rgb) >> 8) & 0xff) +# define RGB2BLUE(rgb) ( (rgb) & 0xff) + +#else +# error No color format defined +#endif + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +struct trv_color_rgb_s +{ + uint8_t red; + uint8_t green; + uint8_t blue; +}; + +struct trv_color_lum_s +{ + float red; + float green; + float blue; + float luminance; +}; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +void trv_color_allocate(FAR struct trv_palette_s *pinfo); +void trv_color_endmapping(void); +void trv_color_free(FAR struct trv_palette_s *pinfo); +trv_pixel_t trv_color_rgb2pixel(FAR struct trv_color_rgb_s *pixel); +void trv_color_pixel2lum(trv_pixel_t pixel, FAR struct trv_color_lum_s *lum); +trv_pixel_t trv_color_lum2pixel(FAR struct trv_color_lum_s *lum); + +#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_COLOR_H */ diff --git a/graphics/traveler/include/trv_debug.h b/graphics/traveler/include/trv_debug.h new file mode 100644 index 000000000..08b4c2d3b --- /dev/null +++ b/graphics/traveler/include/trv_debug.h @@ -0,0 +1,139 @@ +/**************************************************************************** + * apps/graphics/traveler/include/trv_debug.h + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_DEBUG_H +#define __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_DEBUG_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "trv_types.h" + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Feature Selection Switches + * + * CONFIG_GRAPHICS_TRAVELER_DEBUG_LEVEL == 3 turns off sound and video and + * enables verbose debug messages on stdout. + * CONFIG_GRAPHICS_TRAVELER_DEBUG_LEVEL == 2 turns off sound and video and + * enables normal debug output + * CONFIG_GRAPHICS_TRAVELER_DEBUG_LEVEL == 1 turns off sound and enables + * normal debug output + * OTHERWISE, all debugging features are disabled. + */ + +#define ENABLE_SOUND 1 +#define ENABLE_VIDEO 1 +#undef TRV_VERBOSE + +#ifndef CONFIG_GRAPHICS_TRAVELER_DEBUG_LEVEL +# define CONFIG_GRAPHICS_TRAVELER_DEBUG_LEVEL 0 +#ielf (CONFIG_GRAPHICS_TRAVELER_DEBUG_LEVEL == 3) +# undef ENABLE_SOUND +# undef ENABLE_VIDEO +# define TRV_VERBOSE 1 +#elif (CONFIG_GRAPHICS_TRAVELER_DEBUG_LEVEL == 2) +# undef ENABLE_SOUND +# undef ENABLE_VIDEO +#elif (CONFIG_GRAPHICS_TRAVELER_DEBUG_LEVEL == 1) +# undef ENABLE_SOUND +#endif + +/* Sound is not yet supported */ + +#undef ENABLE_SOUND + +/* Debug output macros */ + +#ifdef CONFIG_CPP_HAVE_VARARGS +# if (CONFIG_GRAPHICS_TRAVELER_DEBUG_LEVEL > 0) + +# define trv_debug(format, ...) \ + printf(EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) + +# ifdef TRV_VERBOSE +# define trv_vdebug(format, ...) \ + printf(EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) + +# else +# define trv_vdebug(x...) +# endif + +# else + +# define trv_debug(x...) +# define trv_vdebug(x...) + +# endif +#else + + /* Variadic macros NOT supported */ + +# if (CONFIG_GRAPHICS_TRAVELER_DEBUG_LEVEL > 0) +# ifdef TRV_VERBOSE +# define trv_vdebug trv_debug +# else +# define trv_vdebug (void) +# endif +# else +# define trv_debug (void) +# define trv_vdebug (void) +# endif + +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/* The debugging interfaces are normally accessed via the macros provided + * above. If the cross-compiler's C pre-processor supports a variable + * number of macro arguments, then those macros below will map all + * debug statements to printf. + * + * If the cross-compiler's pre-processor does not support variable length + * arguments, then this additional interface will be built. + */ + +#if !defined(CONFIG_CPP_HAVE_VARARGS) && CONFIG_GRAPHICS_TRAVELER_DEBUG_LEVEL > 0 +int trv_debug(FAR const char *format, ...); +#endif + +#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_DEBUG_H */ diff --git a/graphics/traveler/include/trv_doors.h b/graphics/traveler/include/trv_doors.h new file mode 100644 index 000000000..9179e2979 --- /dev/null +++ b/graphics/traveler/include/trv_doors.h @@ -0,0 +1,52 @@ +/**************************************************************************** + * apps/graphics/traveler/include/trv_doors.h + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_DOORS_H +#define __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_DOORS_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "trv_types.h" + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +void trv_door_initialize(void); +void trv_door_animate(void); + +#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_DOORS_H */ diff --git a/graphics/traveler/include/trv_graphics.h b/graphics/traveler/include/trv_graphics.h new file mode 100644 index 000000000..69790e627 --- /dev/null +++ b/graphics/traveler/include/trv_graphics.h @@ -0,0 +1,129 @@ +/**************************************************************************** + * apps/graphics/traveler/include/trv_graphics.h + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_GRAPHICS_H +#define __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_GRAPHICS_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "trv_types.h" + +#include +#ifdef CONFIG_NX +# include +#endif + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#if defined(CONFIG_GRAPHICS_TRAVELER_RGB16_565) +# define TRV_BPP 16 +# define TRV_COLOR_FMT FB_FMT_RGB16_565 +#elif defined(CONFIG_GRAPHICS_TRAVELER_RGB32_888) +# define TRV_BPP 32 +# define TRV_COLOR_FMT FB_FMT_RGB32 +#else +# error No color format defined +#endif + +#define MAX_REND_WIDTH 480 +#define MAX_REND_HEIGHT 240 + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +#if TRV_BPP == 16 +typedef uint16_t dev_pixel_t; /* Width of one hardware pixel */ +#elif TRV_BPP == 32 +typedef uint32_t dev_pixel_t; /* Width of one hardware pixel */ +#endif + +struct trv_palette_s +{ + int ncolors; /* Number of colors in the look-up table */ + FAR dev_pixel_t *lut; /* Color lookup table */ +}; + +struct trv_graphics_info_s +{ +#ifdef CONFIG_NX + NXHANDLE hnx; /* The connection handle */ + NXHANDLE bgwnd; /* Background window handle */ +#else + trv_coord_t stride; /* Length of a line in bytes */ +#endif + trv_coord_t hwwidth; /* Display width (pixels) */ + trv_coord_t hwheight; /* Display height (rows) */ + trv_coord_t swwidth; /* Software render width (pixels) */ + trv_coord_t swheight; /* Software render height height (rows) */ + uint8_t vscale; /* Log2 vertical image scale factor */ + uint8_t hscale; /* Log2 horizontal image scale factor */ + struct trv_palette_s palette; /* Color palette */ + FAR dev_pixel_t *hwbuffer; /* Hardware frame buffer */ + FAR trv_pixel_t *swbuffer; /* Software render buffer */ +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef CONFIG_NX +extern FAR const struct nx_callback_s *g_trv_nxcallback; +extern sem_t g_trv_nxevent; +extern volatile bool g_trv_nxresolution; +#ifdef CONFIG_NX_MULTIUSER +extern volatile bool g_trv_nxrconnected; +#endif +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +int trv_graphics_initialize(FAR struct trv_graphics_info_s *ginfo); +void trv_graphics_terminate(FAR struct trv_graphics_info_s *ginfo); +trv_pixel_t trv_graphics_index2pixel(int index); +void trv_display_update(struct trv_graphics_info_s *fb); +trv_pixel_t *trv_get_renderbuffer(uint16_t width, uint16_t height); + +#ifdef CONFIG_NX_MULTIUSER +FAR void *trv_nxlistener(FAR void *arg) +#endif + +#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_GRAPHICS_H */ diff --git a/graphics/traveler/include/trv_input.h b/graphics/traveler/include/trv_input.h new file mode 100644 index 000000000..9650089cf --- /dev/null +++ b/graphics/traveler/include/trv_input.h @@ -0,0 +1,86 @@ +/**************************************************************************** + * apps/graphics/traveler/include/trv_input.h + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_INPUT_H +#define __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_INPUT_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "trv_types.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Number of units player moves forward or backward. */ + +#define STEP_DISTANCE 15 + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +struct trv_input_s +{ + int16_t fwdrate; /* Forward motion rate. Negative is backward */ + int16_t leftrate; /* Left motion rate. Negative is right */ + int16_t yawrate; /* Yaw turn rate. Positive is to the left */ + int16_t pitchrate; /* Pitch turn rate. Positive is upward */ + int16_t stepheight; /* Size a a vertical step, if applicable */ + bool dooropen; /* True: Open a door */ +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* Report positional inputs */ + +extern struct trv_input_s g_trv_input; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +void trv_input_initialize(void); +void trv_input_read(void); +void trv_input_terminate(void); +#ifdef CONFIG_GRAPHICS_TRAVELER_NX_XYINPUT +void trv_input_xyinput(trv_coord_t xpos, trv_coord_t xpos, uint8_t buttons); +#endif + +#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_INPUT_H */ diff --git a/graphics/traveler/include/trv_main.h b/graphics/traveler/include/trv_main.h new file mode 100644 index 000000000..62c5ad61f --- /dev/null +++ b/graphics/traveler/include/trv_main.h @@ -0,0 +1,61 @@ +/**************************************************************************** + * apps/graphics/traveler/include/trv_main.h + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_MAIN_H +#define __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_MAIN_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "trv_types.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +extern bool g_trv_terminate; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +void trv_abort(FAR char *format, ...) noreturn_function; + +#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_MAIN_H */ diff --git a/graphics/traveler/include/trv_mem.h b/graphics/traveler/include/trv_mem.h new file mode 100644 index 000000000..5ae3866cf --- /dev/null +++ b/graphics/traveler/include/trv_mem.h @@ -0,0 +1,52 @@ +/**************************************************************************** + * apps/graphics/traveler/include/trv_mem.h + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_MEM_H +#define __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_MEM_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "trv_types.h" + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +FAR void *trv_malloc(size_t size); +void trv_free(FAR void *memory); + +#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_MEM_H */ diff --git a/graphics/traveler/include/trv_pov.h b/graphics/traveler/include/trv_pov.h new file mode 100644 index 000000000..2edc5b7a2 --- /dev/null +++ b/graphics/traveler/include/trv_pov.h @@ -0,0 +1,61 @@ +/**************************************************************************** + * apps/graphics/traveler/include/trv_pov.h + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_POV_H +#define __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_POV_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "trv_types.h" +#include "trv_world.h" + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* This structure defines the current camera position of the player's eyes */ + +extern struct trv_camera_s g_trv_player; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +void trv_pov_reset(void); +void trv_pov_new(void); + +#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_POV_H */ diff --git a/graphics/traveler/include/trv_raycntl.h b/graphics/traveler/include/trv_raycntl.h new file mode 100644 index 000000000..ffcf2b6d3 --- /dev/null +++ b/graphics/traveler/include/trv_raycntl.h @@ -0,0 +1,61 @@ +/**************************************************************************** + * apps/graphics/traveler/include/trv_raycntl.h + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_RAYCNTL_H +#define __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_RAYCNTL_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "trv_types.h" +#include "trv_graphics.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +void trv_raycaster(FAR struct trv_camera_s *player, + FAR struct trv_graphics_info_s *ginfo); + +#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_RAYCNTL_H */ diff --git a/graphics/traveler/include/trv_rayrend.h b/graphics/traveler/include/trv_rayrend.h new file mode 100644 index 000000000..189e17e46 --- /dev/null +++ b/graphics/traveler/include/trv_rayrend.h @@ -0,0 +1,60 @@ +/**************************************************************************** + * apps/graphics/traveler/include/trv_rayrend.h + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_RAYEND_H +#define __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_RAYEND_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "trv_types.h" +#include "trv_world.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +void trv_rend_backdrop (struct trv_camera_s *camera); + +#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_RAYEND_H */ diff --git a/graphics/traveler/include/trv_trigtbl.h b/graphics/traveler/include/trv_trigtbl.h new file mode 100644 index 000000000..2b73647c2 --- /dev/null +++ b/graphics/traveler/include/trv_trigtbl.h @@ -0,0 +1,75 @@ +/**************************************************************************** + * apps/graphics/traveler/include/trv_trigtbl.h + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_TRIGTBL_H +#define __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_TRIGTBL_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "trv_types.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* These are definitions of commonly used angles. */ + +#define TWOPI 1920 +#define PI 960 +#define HALFPI 480 +#define QTRPI 240 + +/* Here are definitions for those who prefer degrees */ +/* NOTE: ANGLE_60 and ANGLE_30 are special values. They were */ +/* chosen to match the horizontal screen resolution of 320 pixels. */ +/* These, in fact, drive the entire angular measurement system */ + +#define ANGLE_0 0 +#define ANGLE_6 32 +#define ANGLE_9 48 +#define ANGLE_30 160 +#define ANGLE_60 320 +#define ANGLE_90 480 +#define ANGLE_180 960 +#define ANGLE_270 1440 +#define ANGLE_360 1920 + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_TRIGTBL_H */ diff --git a/graphics/traveler/include/trv_types.h b/graphics/traveler/include/trv_types.h new file mode 100644 index 000000000..2eb9f2618 --- /dev/null +++ b/graphics/traveler/include/trv_types.h @@ -0,0 +1,73 @@ +/**************************************************************************** + * apps/graphics/traveler/include/trv_types.h + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_TYPES_H +#define __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_TYPES_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* The maximum size of a line (for example, in the .INI file) */ + +#define TRV_MAX_LINE 256 + +/* Size of one (internal) pixel */ + +#define TRV_PIXEL_MAX UINT8_MAX + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +typedef uint8_t trv_pixel_t; /* Width of one pixel in rendering phase */ +typedef int16_t trv_coord_t; /* Contains one display coordinate */ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_TYPES_H */ diff --git a/graphics/traveler/include/trv_world.h b/graphics/traveler/include/trv_world.h new file mode 100644 index 000000000..3461fd792 --- /dev/null +++ b/graphics/traveler/include/trv_world.h @@ -0,0 +1,90 @@ +/**************************************************************************** + * apps/graphics/traveler/include/trv_world.h + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_WORLD_H +#define __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_WORLD_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "trv_types.h" + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* The following structure contains all information necessary to define + * a point-of-view. + */ + +struct trv_camera_s +{ + trv_coord_t x; /* Camera X position */ + trv_coord_t y; /* Camera Y position */ + trv_coord_t z; /* Camera Z position */ + int16_t yaw; /* Camera yaw orientation */ + int16_t pitch; /* Camera pitch orientation */ +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ +/* This is the starting position and orientation of the camera in the world */ + +extern struct trv_camera_s g_initial_camera; + +/* This is the height of player (distance from the camera Z position to + * the position of the player's "feet" + */ + +extern trv_coord_t g_player_height; + +/* This is size of something that the player can step over when "walking" */ + +extern trv_coord_t g_walk_stepheight; + +/* This is size of something that the player can step over when "running" */ + +extern trv_coord_t g_run_stepheight; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +int trv_world_create(FAR const char *mapfile); +void trv_world_destroy(void); + +#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_WORLD_H */ diff --git a/graphics/traveler/src/trv_color.c b/graphics/traveler/src/trv_color.c new file mode 100644 index 000000000..8760165a3 --- /dev/null +++ b/graphics/traveler/src/trv_color.c @@ -0,0 +1,673 @@ +/******************************************************************************* + * apps/graphics/traveler/src/trv_color.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "trv_types.h" +#include "trv_mem.h" +#include "trv_bitmaps.h" +#include "trv_main.h" +#include "trv_graphics.h" +#include "trv_color.h" + +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#undef MIN +#undef MAX +#define MIN(a,b) ((a) < (b) ? (a) : (b)) +#define MAX(a,b) ((a) > (b) ? (a) : (b)) + +/* This defines the size of the RGB cube that can be supported by trv_pixel_t + * Use of the RGB cube gives us a fine control of the color space. However + * the lighting logic in this program requires fine control over luminance. + * If the RGB_CUBE_SIZE is small, then an alternative luminance model is + * used. + */ + +#define RGB_CUBE_SIZE 6 +#define MIN_LUM_LEVELS 8 + +/* These are definitions needed to support the luminance model */ + +#if RGB_CUBE_SIZE < MIN_LUM_LEVELS +#define NUNIT_VECTORS 16 +#define NLUMINANCES 16 /* ((TRV_PIXEL_MAX+1)/NUNIT_VECTORS) */ +#define MAX_LUM_INDEX 255 + +/* The following macros perform conversions between unit vector index and + * luminance code into pixels and vice versa. NOTE: These macros assume + * on the above values for NUNIT_VECTORS and NLUMINANCES + */ + +#define TRV_UVLUM2NDX(u,l) (((int)(u) << 4) + (l)) +#define TRV_NDX2UV(p) ((p) >> 4) +#define TRV_NDX2LUM(p) ((p) & 0x0f) + +/* Each color is one of NCOLOR_FORMS */ + +#define NCOLOR_FORMS 5 + +/**************************************************************************** + * Private Type Declarations + ************************************************************************/ + +/* The following enumeration defines indices into the g_unit_vector array */ + +enum unit_vector_index_e +{ + GREY_NDX = 0, + BLUE_NDX, + GREENERBLUE_NDX, + BLUEGREEN_NDX, + BLUEVIOLET_NDX, + VIOLET_NDX, + LIGHTBLUE_NDX, + GREEN_NDX, + BLUERGREN_NDX, + YELLOWGREEN_NDX, + YELLOW_NDX, + LIGHTGREEN_NDX, + RED_NDX, + REDVIOLET_NDX, + ORANGE_NDX, + PINK_NDX +}; + +#endif + +#if RGB_CUBE_SIZE < MIN_LUM_LEVELS +struct color_form_s +{ + float max; + float mid; + float min; +} ; +#endif + +/**************************************************************************** + * Private Variables + *************************************************************************/ + +#if RGB_CUBE_SIZE < MIN_LUM_LEVELS +static FAR struct trv_color_lum_s *g_pixel2um_lut; + +/* The following defines the "form" of each color in the g_unit_vector array */ + +static const struct color_form_s g_trv_colorform[NCOLOR_FORMS] = +{ + { 1.0, 0.0, 0.0 }, + { 0.875, 0.4841229, 0.0 }, + { 0.7071068, 0.7071068, 0.0 }, + { 0.6666667, 0.5270463, 0.5270463 }, + { 0.5773503, 0.5773503, 0.5773503 } +}; + +/* These arrays map color forms into g_unit_vector array indices */ + +static const enum unit_vector_index_e g_trv_bgrform_map[NCOLOR_FORMS] = + { + BLUE_NDX, GREENERBLUE_NDX, BLUEGREEN_NDX, LIGHTBLUE_NDX, GREY_NDX + }; + +static const enum unit_vector_index_e g_trv_brgform_map[NCOLOR_FORMS] = + { + BLUE_NDX, BLUEVIOLET_NDX, VIOLET_NDX, LIGHTBLUE_NDX, GREY_NDX + }; + +static const enum unit_vector_index_e g_trv_gbrform_map[NCOLOR_FORMS] = + { + GREEN_NDX, BLUERGREN_NDX, BLUEGREEN_NDX, LIGHTGREEN_NDX, GREY_NDX + }; + +static const enum unit_vector_index_e g_trv_grbform_map[NCOLOR_FORMS] = + { + GREEN_NDX, YELLOWGREEN_NDX, YELLOW_NDX, LIGHTGREEN_NDX, GREY_NDX + }; + +static const enum unit_vector_index_e g_trv_rbgform_map[NCOLOR_FORMS] = + { + RED_NDX, REDVIOLET_NDX, VIOLET_NDX, PINK_NDX, GREY_NDX + }; + +static const enum unit_vector_index_e g_trv_rgbform_map[NCOLOR_FORMS] = + { + RED_NDX, ORANGE_NDX, YELLOW_NDX, PINK_NDX, GREY_NDX + }; + +/* This array defines each color supported in the luminance model */ + +static const struct trv_color_lum_s g_unit_vector[NUNIT_VECTORS] = +{ + { 0.5773503, 0.5773503, 0.5773503, 441.672932,}, /* GREY_NDX */ + + { 0.0, 0.0, 1.0, 255.0 }, /* BLUE_NDX */ + { 0.0, 0.4841229, 0.875, 291.428571 }, /* GREENERBLUE_NDX */ + { 0.0, 0.7071068, 0.7071068, 360.624445 }, /* BLUEGREEN_NDX */ + { 0.4841229, 0.0, 0.875, 291.428571 }, /* BLUEVIOLET_NDX */ + { 0.7071068, 0.0, 0.7071068, 360.624445 }, /* VIOLET_NDX */ + { 0.5270463, 0.5270463, 0.6666667, 382.499981 }, /* LIGHTBLUE_NDX */ + + { 0.0, 1.0, 0.0, 255.0 }, /* GREEN_NDX */ + { 0.0, 0.875, 0.4841229, 291.428571 }, /* BLUERGREN_NDX */ + { 0.4841229, 0.875, 0.0, 291.428571 }, /* YELLOWGREEN_NDX */ + { 0.7071068, 0.7071068, 0.0, 360.624445 }, /* YELLOW_NDX */ + { 0.5270463, 0.6666667, 0.5270463, 382.499981 }, /* LIGHTGREEN_NDX */ + + { 1.0, 0.0, 0.0, 255.0 }, /* RED_NDX */ + { 0.875, 0.0, 0.4841229, 291.428571 }, /* REDVIOLET_NDX */ + { 0.875, 0.4841229, 0.0, 291.428571 }, /* ORANGE_NDX */ + { 0.6666667, 0.5270463, 0.5270463, 382.499981 }, /* PINK_NDX */ +}; +#else +static struct trv_color_rgb_s *g_pixl2rgb_lut = NULL; +static float g_trv_cube2pixel; +#endif + +/**************************************************************************** + * Private Functions + ************************************************************************/ + +/**************************************************************************** + * Name: trv_lum2formtype + * + * Description: + * Convert an ordered RGB-Luminance value a color form (index into + * XXXForm arrays). + * + ***************************************************************************/ + +#if RGB_CUBE_SIZE < MIN_LUM_LEVELS +static uint8_t trv_lum2formtype(struct color_form_s *lum) +{ + float factor1, factor2, factor3, error, lse; + uint8_t formNumber; + int i; + + /* Initialize for the search */ + factor1 = g_trv_colorform[0].max - lum->max; + factor2 = g_trv_colorform[0].mid - lum->mid; + factor3 = g_trv_colorform[0].min - lum->min; + lse = factor1*factor1 + factor2*factor2 + factor3*factor3; + formNumber = 0; + + /* Now, search the rest of the table, keeping the form with least + * squared error value + */ + + for (i = 1; i < NCOLOR_FORMS; i++) + { + factor1 = g_trv_colorform[i].max - lum->max; + factor2 = g_trv_colorform[i].mid - lum->mid; + factor3 = g_trv_colorform[i].min - lum->min; + error = factor1*factor1 + factor2*factor2 + factor3*factor3; + if (error < lse) + { + lse = error; + formNumber = i; + } + } + return formNumber; +} +#endif + +/**************************************************************************** + * Name: trv_lum2colorform + * + * Description: + * Convert an RGB-Luminance value into a color form code (index into + * g_unit_vector array). + * + ************************************************************************/ + +#if RGB_CUBE_SIZE < MIN_LUM_LEVELS +static enum unit_vector_index_e trv_lum2colorform(struct trv_color_lum_s *lum) +{ + struct color_form_s orderedLum; + enum unit_vector_index_e uvndx; + + /* Get an ordered representation of the luminance value */ + + if (lum->red >= lum->green) + { + if (lum->red >= lum->blue) + { + /* RED >= GREEN && RED >= BLUE */ + + if (lum->green >= lum->blue) + { + /* RED >= GREEN >= BLUE */ + + orderedLum.max = lum->red; + orderedLum.mid = lum->green; + orderedLum.min = lum->blue; + uvndx = g_trv_rgbform_map[trv_lum2formtype(&orderedLum)]; + } + else + { + /* RED >= BLUE > GREEN */ + + orderedLum.max = lum->red; + orderedLum.mid = lum->blue; + orderedLum.min = lum->green; + uvndx = g_trv_rbgform_map[trv_lum2formtype(&orderedLum)]; + } + } + else + { + /* BLUE > RED >= GREEN */ + + orderedLum.max = lum->blue; + orderedLum.mid = lum->red; + orderedLum.min = lum->green; + uvndx = g_trv_brgform_map[trv_lum2formtype(&orderedLum)]; + } + } + else + { + /* lum->red < lum->green) */ + + if (lum->green >= lum->blue) + { + /* GREEN > RED && GREEN >= BLUE */ + + if (lum->red >= lum->blue) + { + /* GREEN > RED >= BLUE */ + + orderedLum.max = lum->green; + orderedLum.mid = lum->red; + orderedLum.min = lum->blue; + uvndx = g_trv_grbform_map[trv_lum2formtype(&orderedLum)]; + } + else + { + /* GREEN >= BLUE > RED*/ + + orderedLum.max = lum->green; + orderedLum.mid = lum->blue; + orderedLum.min = lum->red; + uvndx = g_trv_gbrform_map[trv_lum2formtype(&orderedLum)]; + } + } + else + { + /* BLUE > GREEN > RED */ + + orderedLum.max = lum->blue; + orderedLum.mid = lum->green; + orderedLum.min = lum->red; + uvndx = g_trv_bgrform_map[trv_lum2formtype(&orderedLum)]; + } + } + + return uvndx; +} +#endif + +/**************************************************************************** + * Public Functions + ************************************************************************/ + +/**************************************************************************** + * Name: trv_color_allocate + * + * Description: + ************************************************************************/ + +void trv_color_allocate(FAR struct trv_palette_s *pinfo) +{ +#if RGB_CUBE_SIZE < MIN_LUM_LEVELS + dev_pixel_t *lut; + int uvndx; + int lumndx; + int index; + + /* Check if a color lookup table has been allocated */ + + pinfo->lut = (dev_pixel_t*) + trv_malloc(sizeof(dev_pixel_t) * (NUNIT_VECTORS*NLUMINANCES)); + + if (!pinfo->lut) + { + trv_abort("ERROR: Failed to allocate color lookup table\n"); + } + + lut = pinfo->lut; + + /* Save the color information and color lookup table for use in + * color mapping below. + */ + + g_pixel2um_lut = (struct trv_color_lum_s*) + trv_malloc(sizeof(struct trv_color_lum_s) * (NUNIT_VECTORS*NLUMINANCES)); + + if (!g_pixel2um_lut) + { + trv_abort("ERROR: Failed to allocate luminance table\n"); + } + + /* Allocate each color at each luminance value */ + + pinfo->ncolors = 0; + index = 0; + + for (uvndx = 0; uvndx < NUNIT_VECTORS; uvndx++) + { + for (lumndx = 0; lumndx < NLUMINANCES; lumndx++) + { + struct trv_color_rgb_s color; + FAR struct trv_color_lum_s *lum; + + /* Get a convenience pointer to the lookup table entry */ + + lum = &g_pixel2um_lut[index]; + *lum = g_unit_vector[uvndx]; + + /* Get the luminance associated with this lum for this + * unit vector. + */ + + lum->luminance = (lum->luminance * (float)(lumndx + 1)) / NLUMINANCES; + + /* Convert to RGB and allocate the color */ + + color.red = (short) (lum->red * lum->luminance); + color.green = (short) (lum->green * lum->luminance); + color.blue = (short) (lum->blue * lum->luminance); + + /* Save the RGB to pixel lookup data */ + + lut[index] = TRV_MKRGB(color.red, color.green, color.blue); + pinfo->ncolors = ++index; + } + } + +#else + dev_pixel_t *lut; + int index; + struct trv_color_rgb_s rgb; + + /* Check if a color lookup table has been allocated */ + + pinfo->lut = (dev_pixel_t*) + trv_malloc(sizeof(dev_pixel_t) * (TRV_PIXEL_MAX+1)); + + if (!pinfo->lut) + { + trv_abort("ERROR: Failed to allocate color lookup table\n"); + } + + /* Save the color information and color lookup table for use in + * subsequent color mapping. + */ + + lut = pinfo->lut; + + /* Check if a Pixel-to-RGB color mapping table has been allocated */ + + g_pixl2rgb_lut = (struct trv_color_rgb_s*) + trv_malloc(sizeof(struct trv_color_rgb_s) * (TRV_PIXEL_MAX+1)); + + if (!g_pixl2rgb_lut) + { + trv_abort("ERROR: Failed to allocate luminance table\n"); + } + + for (index = 0; index <= TRV_PIXEL_MAX; index++) + { + g_pixl2rgb_lut[index].red + = g_pixl2rgb_lut[index].green + = g_pixl2rgb_lut[index].blue = 0; + } + + /* Calculate the cube to trv_pixel_t scale factor. This factor will + * convert an RGB component in the range {0..RGB_CUBE_SIZE-1} to + * a value in the range {0..TRV_PIXEL_MAX}. + */ + + g_trv_cube2pixel = (float)TRV_PIXEL_MAX / (float)(RGB_CUBE_SIZE-1); + + /* Allocate each color in the RGB Cube */ + + pinfo->ncolors = index = 0; + for (rgb.red = 0; rgb.red < RGB_CUBE_SIZE; rgb.red++) + for (rgb.green = 0; rgb.green < RGB_CUBE_SIZE; rgb.green++) + for (rgb.blue = 0; rgb.blue < RGB_CUBE_SIZE; rgb.blue++) + { + struct trv_color_rgb_s color; + + color.red = (short) (rgb.red * 65535 / (RGB_CUBE_SIZE - 1)); + color.green = (short) (rgb.green * 65535 / (RGB_CUBE_SIZE - 1)); + color.blue = (short) (rgb.blue * 65535 / (RGB_CUBE_SIZE - 1)); + + /* Save the RGB to pixel lookup data */ + + lut[index] = TRV_MKRGB(color.red, color.green, color.blue); + pinfo->ncolors = ++index; + + /* Save the pixel to RGB lookup data */ + + if (color.pixel <= TRV_PIXEL_MAX) + { + g_pixl2rgb_lut[color.pixel] = rgb; + } + } +#endif +} + +/**************************************************************************** + * Name: trv_color_endmapping + * + * Description: + * When all color mapping has been performed, this function should be + * called to release all resources dedicated to color mapping. + * + ***************************************************************************/ + +void trv_color_endmapping(void) +{ +#if RGB_CUBE_SIZE < MIN_LUM_LEVELS + if (g_pixel2um_lut) + { + trv_free(g_pixel2um_lut); + g_pixel2um_lut = NULL; + } +#else + if (g_pixl2rgb_lut) + { + trv_free(g_pixl2rgb_lut); + g_pixl2rgb_lut = NULL; + } +#endif +} + +/**************************************************************************** + * Name: trv_color_free + * + * Description: + * Free the color lookup table + * + ***************************************************************************/ + +void trv_color_free(struct trv_palette_s *pinfo) +{ + if (pinfo->lut) + { + trv_free(pinfo->lut); + pinfo->lut = NULL; + } +} + +/**************************************************************************** + * Name: trv_color_rgb2pixel + * Description: Map a RGB triplet into the corresponding pixel. The + * value range of ech RGB value is assume to lie within 0 through + * TRV_PIXEL_MAX. + ************************************************************************/ + +trv_pixel_t trv_color_rgb2pixel(struct trv_color_rgb_s *pixel) +{ +#if RGB_CUBE_SIZE < MIN_LUM_LEVELS + struct trv_color_lum_s lum; + + /* Convert the RGB Value into a luminance value. + * Get the luminance associated with the RGB value. + */ + + lum.luminance = sqrt(pixel->red * pixel->red + + pixel->green * pixel->green + + pixel->blue * pixel->blue); + + /* Convert the RGB Component into unit vector + luminance */ + + if (lum.luminance > 0.0) + { + lum.red = (float)pixel->red / lum.luminance; + lum.green = (float)pixel->green / lum.luminance; + lum.blue = (float)pixel->blue / lum.luminance; + } + else + { + lum.red = lum.green = lum.blue = g_unit_vector[GREY_NDX].red; + } + + return trv_color_lum2pixel(&lum); +#else + trv_pixel_t returnValue; + int red, green, blue; + + red = MIN((pixel->red * RGB_CUBE_SIZE) / (TRV_PIXEL_MAX+1), + RGB_CUBE_SIZE - 1); + green = MIN((pixel->green * RGB_CUBE_SIZE) / (TRV_PIXEL_MAX+1), + RGB_CUBE_SIZE - 1); + blue = MIN((pixel->blue * RGB_CUBE_SIZE) / (TRV_PIXEL_MAX+1), + RGB_CUBE_SIZE - 1); + + returnValue = (red * RGB_CUBE_SIZE + green) * RGB_CUBE_SIZE + blue; + + return returnValue; +#endif +} + +/**************************************************************************** + * Name: trv_color_lum2pixel + * Description: Convert an RGB-Luminance value into a pixel + ************************************************************************/ + +trv_pixel_t trv_color_lum2pixel(struct trv_color_lum_s *lum) +{ +#if RGB_CUBE_SIZE < MIN_LUM_LEVELS + enum unit_vector_index_e uvndx; + uint8_t lumndx; + + /* Get the g_unit_vector array index associated with this lum */ + + uvndx = trv_lum2colorform(lum); + + /* Get the luminance number associated with this lum at this index + * Make sure that the requested luminance does not exceed the maximum + * allowed for this unit vector. + */ + + if (lum->luminance >= g_unit_vector[uvndx].luminance) + { + lumndx = (NLUMINANCES-1); + } + else + { + lumndx = (uint8_t)((float)NLUMINANCES + * lum->luminance / g_unit_vector[uvndx].luminance); + if (lumndx) lumndx--; + } + + /* Now get the pixel value from the unit vector index and the luminance + * number. We will probably have to expand this later from the 8-bit + * index to a wider representation. + */ + + return TRV_UVLUM2NDX(uvndx, lumndx); + +#else + struct trv_color_rgb_s rgb; + + /* Convert the luminance value to its RGB components */ + rgb.red = lum->red * lum->luminance; + rgb.green = lum->green * lum->luminance; + rgb.blue = lum->blue * lum->luminance; + + return trv_color_rgb2pixel(&rgb); +#endif +} + +/**************************************************************************** + * Name: trv_color_pixel2lum + * Description: Convert a pixel value into RGB-Luminance value. + ************************************************************************/ + +void trv_color_pixel2lum(trv_pixel_t pixval, + struct trv_color_lum_s *lum) +{ +#if RGB_CUBE_SIZE < MIN_LUM_LEVELS + *lum = g_pixel2um_lut[pixval]; +#else + /* Convert the pixel to its RGB components */ + + lum->red = g_trv_cube2pixel * (float)g_pixl2rgb_lut[pixval].red; + lum->green = g_trv_cube2pixel * (float)g_pixl2rgb_lut[pixval].green; + lum->blue = g_trv_cube2pixel * (float)g_pixl2rgb_lut[pixval].blue; + + /* Get the luminance associated with the RGB value */ + + lum->luminance = sqrt(lum->red * lum->red + + lum->green * lum->green + + lum->blue * lum->blue); + + /* Convert the RGB Component into unit vector + luminance */ + + if (lum->luminance > 0.0) + { + lum->red /= lum->luminance; + lum->blue /= lum->luminance; + lum->green /= lum->luminance; + } +#endif +} diff --git a/graphics/traveler/src/trv_graphics.c b/graphics/traveler/src/trv_graphics.c new file mode 100644 index 000000000..02d9b61b9 --- /dev/null +++ b/graphics/traveler/src/trv_graphics.c @@ -0,0 +1,566 @@ +/**************************************************************************** + * apps/graphics/traveler/src/trv_graphics.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "trv_types.h" +#include "trv_main.h" +#include "trv_mem.h" +#include "trv_color.h" +#include "trv_debug.h" +#include "trv_graphics.h" + +#include +#ifdef CONFIG_NX_MULTIUSER +# include +#endif + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef CONFIG_NX +FAR const struct nx_callback_s *g_trv_nxcallback; +sem_t g_trv_nxevent = SEM_INITIZIALIZER(0); +bool g_trv_nxresolution = false; +#ifdef CONFIG_NX_MULTIUSER +bool g_trv_nxrconnected = false; +#endif +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: trv_get_fbdev + * + * Description: + * Get the system framebuffer device + * + ****************************************************************************/ + +#ifndef CONFIG_NX_MULTIUSER +static FAR struct fb_vtable_s *trv_get_fbdev(void) +{ + FAR struct fb_vtable_s *fbdev; + int ret; + + /* Initialize the frame buffer device */ + + ret = up_fbinitialize(); + if (ret < 0) + { + trv_abort("up_fbinitialize failed: %d\n", -ret); + } + + /* Set up to use video plane 0. There is no support for anything but + * video plane 0. + */ + + fbdev = up_fbgetvplane(0); + if (!fbdev) + { + trv_abort("up_fbgetvplane(0) failed\n"); + } + + return fbdev; +} +#endif + +/**************************************************************************** + * Name: trv_fb_initialize + * + * Description: + * Get the system framebuffer device + * + ****************************************************************************/ + +#if !defined(CONFIG_NX_MULTIUSER) && !defined(CONFIG_NX) +static void trv_fb_initialize(FAR struct trv_graphics_info_s *ginfo) +{ + struct fb_videoinfo_s vinfo; + struct fb_planeinfo_s pinfo; + FAR struct fb_vtable_s *fbdev; + int ret; + + /* Get the framebuffer device */ + + fbdev = trv_get_fbdev(); + + /* Get information about video plane 0 */ + + ret = fbdev->getvideoinfo(fbdev, &vinfo); + if (ret < 0) + { + trv_abort("getvideoinfo() failed\n"); + } + + ginfo->hwwidth = vinfo.xres; + ginfo->hwheight = vinfo.yres; + + ret = fbdev->getplaneinfo(fbdev, 0, &pinfo); + if (ret < 0) + { + trv_abort("getplaneinfo() failed\n"); + } + + ginfo->stride = pinfo.stride; + ginfo->hwbuffer = pinfo.fbmem; + + if (vinfo.fmt != TRV_COLOR_FMT || pinfo.bpp != TRV_BPP) + { + trv_abort("Bad color format(%d)/bpp(%b)\n", vinfo.fmt, pinfo.bpp); + } +} +#endif + +/**************************************************************************** + * Name: trv_use_bgwindow + * + * Description: + * Get the NX background window + * + ****************************************************************************/ + +#ifdef CONFIG_NX +static void trv_use_bgwindow(FAR struct trv_graphics_info_s *ginfo) +{ + /* Get the background window */ + + ret = nx_requestbkgd(g_hnx, &g_trv_nxcallback, ginfo); + if (ret < 0) + { + trv_abort("nx_requestbkgd failed: %d\n", errno); + } + + /* Wait until we have the screen resolution. We'll have this immediately + * unless we are dealing with the NX server. + */ + + while (!g_trv_nxresolution) + { + (void)sem_wait(&g_trv_nxevent); + } +} +#endif + +/**************************************************************************** + * Name: trv_nxsu_initialize + ****************************************************************************/ + +#if defined(CONFIG_NX) && !defined(CONFIG_NX_MULTIUSER) +static inline int trv_nxsu_initialize(FAR struct trv_graphics_info_s *ginfo) +{ + FAR struct fb_vtable_s *fbdev; + int ret; + + /* Get the framebuffer device */ + + fbdev = trv_get_fbdev(); + + /* Open NX */ + + ginfo->hnx = nx_open(fbdev); + if (!ginfo->hnx) + { + trv_abort("trv_nxsu_initialize: nx_open failed: %d\n", errno); + } + + /* And use the background window */ + + trv_use_bgwindow(ginfo); +} +#endif + +/**************************************************************************** + * Name: trv_servertask + ****************************************************************************/ + +#ifdef CONFIG_NX_MULTIUSER +int trv_servertask(int argc, char *argv[]) +{ + FAR struct fb_vtable_s *fbdev; + int ret; + + /* Get the framebuffer device */ + + fbdev = trv_get_fbdev(); + + /* Then start the server */ + + ret = nx_run(dev); + trv_abort("nx_run returned: %d\n", errno); +} +#endif + +/**************************************************************************** + * Name: trv_nxmu_initialize + ****************************************************************************/ + +#ifdef CONFIG_NX_MULTIUSER +static inline int trv_nxmu_initialize(FAR struct trv_graphics_info_s *ginfo) +{ + struct sched_param param; + pthread_t thread; + pid_t servrid; + int ret; + + /* Set the client task priority */ + + param.sched_priority = CONFIG_EXAMPLES_NX_CLIENTPRIO; + ret = sched_setparam(0, ¶m); + if (ret < 0) + { + printf("nxeg_initialize: sched_setparam failed: %d\n" , ret); + g_exitcode = NXEXIT_SCHEDSETPARAM; + return ERROR; + } + + /* Start the server task */ + + printf("nxeg_initialize: Starting trv_servertask task\n"); + servrid = task_create("NX Server", CONFIG_EXAMPLES_NX_SERVERPRIO, + CONFIG_EXAMPLES_NX_STACKSIZE, trv_servertask, NULL); + if (servrid < 0) + { + printf("nxeg_initialize: Failed to create trv_servertask task: %d\n", errno); + g_exitcode = NXEXIT_TASKCREATE; + return ERROR; + } + + /* Wait a bit to let the server get started */ + + sleep(1); + + /* Connect to the server */ + + ginfo->hnx = nx_connect(); + if (ginfo->hnx) + { + pthread_attr_t attr; + + /* Start a separate thread to listen for server events. This is probably + * the least efficient way to do this, but it makes this example flow more + * smoothly. + */ + + (void)pthread_attr_init(&attr); + param.sched_priority = CONFIG_EXAMPLES_NX_LISTENERPRIO; + (void)pthread_attr_setschedparam(&attr, ¶m); + (void)pthread_attr_setstacksize(&attr, CONFIG_EXAMPLES_NX_STACKSIZE); + + ret = pthread_create(&thread, &attr, trv_nxlistener, NULL); + if (ret != 0) + { + printf("nxeg_initialize: pthread_create failed: %d\n", ret); + g_exitcode = NXEXIT_PTHREADCREATE; + return ERROR; + } + + /* Don't return until we are connected to the server */ + + while (!g_trv_nxrconnected) + { + /* Wait for the listener thread to wake us up when we really + * are connected. + */ + + (void)sem_wait(&g_trv_nxevent); + } + } + else + { + printf("nxeg_initialize: nx_connect failed: %d\n", errno); + g_exitcode = NXEXIT_NXCONNECT; + return ERROR; + } + + /* And use the background window */ + + trv_use_bgwindow(ginfo); +} +#endif + +/**************************************************************************** + * Name: trv_row_update + * + * Description: + * Expand one one either directly into the frame buffer or else into an + * intermediate line buffer. + * + ****************************************************************************/ + +void trv_row_update(struct trv_graphics_info_s *ginfo, + FAR const trv_pixel_t *src, + FAR dev_pixel_t *dest) +{ + trv_coord_t hexpand; + dev_pixel_t pixel; + trv_coord_t srccol; + int i; + + /* Loop for each column in the src render buffer */ + + hexpand = (1 << ginfo->hscale); + + for (srccol = 0; srccol < ginfo->swwidth; srccol++) + { + /* Map the source pixel */ + + pixel = ginfo->palette.lut[*src++]; + + /* Copy it to the destination, expanding as necessary */ + + for (i = 0; i < hexpand; i++) + { + *dest++ = pixel; + } + } +} + +/**************************************************************************** + * Name: trv_row_tranfer + * + * Description: + * Transfer one line from the line buffer to the NX window. + * + ****************************************************************************/ + +#ifdef CONFIG_NX +void trv_display_update(struct trv_graphics_info_s *ginfo, + FAR dev_pixel_t *dest, trv_coord_t destrow) +{ + /* Transfer the row buffer to the NX window */ +#warning Missing logic + +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: trv_graphics_initialize + * + * Description: + ****************************************************************************/ + +int trv_graphics_initialize(FAR struct trv_graphics_info_s *ginfo) +{ + int swwidth; + int swheight; + int scale; + + /* Initialize the graphics device and get information about the display */ + +#if !defined(CONFIG_NX) + trv_fb_initialize(ginfo); +#elif defined(CONFIG_NX_MULTIUSER) + trv_nxmu_initialize(ginfo); +#else + trv_nxsu_initialize(ginfo); +#endif + + /* Check if we need to scale the image */ + + swwidth = ginfo->hwwidth; + scale = 0; + + while (swwidth > MAX_REND_WIDTH) + { + swwidth >>= 1; + scale++; + } + + ginfo->swwidth = swwidth; + ginfo->hscale = scale; + + swheight = ginfo->hwheight; + scale = 0; + + while (swheight > MAX_REND_WIDTH) + { + swheight >>= 1; + scale++; + } + + ginfo->swheight = swheight; + ginfo->vscale = scale; + + /* Allocate buffers + * + * ginfo->swbuffer - Software renders into this buffer using an 8-bit + * encoding and perhaps at a different resolution that the final + * image. + */ + + ginfo->swbuffer = (trv_pixel_t*) + trv_malloc(swwidth * swheight * sizeof(trv_pixel_t)); + if (!ginfo->swbuffer) + { + trv_abort("ERROR: Failed to allocate render buffer\n"); + } + + /* Using the framebuffer driver: + * ginfo->hwbuffer - This address of the final, expanded frame image. + * This address is determined by hardware and is neither allocated + * nor freed. + * + * Using NX + * ginfo->hwbuffer - This address of one line of the final expanded + * image that must transferred to the window. + */ + +#ifdef CONFIG_NX + ginfo->hwbuffer = (trv_pixel_t*) + trv_malloc(ginfo->hwwidth * sizeof(dev_pixel_t)); + if (!ginfo->hwbuffer) + { + trv_abort("ERROR: Failed to allocate hardware line buffer\n"); + } +#endif + + /* Allocate color mapping information */ + + trv_color_allocate(&ginfo->palette); + trv_vdebug("%d colors allocated\n", ginfo->palette.ncolors); + return OK; +} + +/**************************************************************************** + * Name: trv_graphics_terminate + * + * Description: + ****************************************************************************/ + +void trv_graphics_terminate(FAR struct trv_graphics_info_s *ginfo) +{ + /* Free palette */ + + trv_color_free(&ginfo->palette); + + /* Free image buffers */ + + if (ginfo->swbuffer) + { + trv_free(ginfo->swbuffer); + ginfo->swbuffer = NULL; + } + +#ifdef CONFIG_NX + if (ginfo->hwbuffer) + { + trv_free(ginfo->hwbuffer); + ginfo->hwbuffer = NULL; + } + + /* Close/disconnect NX */ +#warning "Missing Logic" +#endif +} + +/**************************************************************************** + * Name: trv_display_update + * + * Description: + ****************************************************************************/ + +void trv_display_update(struct trv_graphics_info_s *ginfo) +{ + FAR const uint8_t *src = (FAR const uint8_t *)ginfo->swbuffer; + FAR uint8_t *dest = (FAR uint8_t *)ginfo->hwbuffer; + trv_coord_t srcrow; +#ifdef CONFIG_NX + trv_coord_t destrow; +#else + FAR uint8_t *first; + trv_coord_t lnwidth; +#endif + trv_coord_t vexpand; + int i; + + /* Loop for each row in the srce render buffer */ + + vexpand = (1 << ginfo->vscale); +#ifdef CONFIG_NX + destrow = 0; +#else + lnwidth = ginfo->hwwidth * sizeof(dev_pixel_t); +#endif + + for (srcrow = 0; srcrow < ginfo->swheight; srcrow++) + { + /* Transfer the row to the device row/buffer */ + + trv_row_update(ginfo, (FAR const trv_pixel_t *)src, + (FAR dev_pixel_t *)dest); + +#ifdef CONFIG_NX + /* Transfer the row buffer to the NX window */ + + trv_row_tranfer(ginfo, dest, destrow); + destrow++; +#else + first = dest; + dest += ginfo->stride; +#endif + + /* Then replicate as many times as is necessary */ + + for (i = 1; i < vexpand; i++) + { +#ifdef CONFIG_NX + /* Transfer the row buffer to the NX window */ + + trv_row_tranfer(ginfo, dest, destrow); + destrow++; +#else + /* Point to the next row in the frame buffer */ + + memcpy(dest, first, lnwidth); + dest += ginfo->stride; +#endif + } + + /* Point to the next src row */ + + src += ginfo->swwidth; + } +} + diff --git a/graphics/traveler/src/trv_input.c b/graphics/traveler/src/trv_input.c new file mode 100644 index 000000000..ea100de5c --- /dev/null +++ b/graphics/traveler/src/trv_input.c @@ -0,0 +1,360 @@ +/**************************************************************************** + * apps/graphics/traveler/trv_input.c + * This file contains the main logic for the NuttX version of Traveler + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "trv_types.h" +#include "trv_world.h" +#include "trv_trigtbl.h" +#include "trv_input.h" + +#if defined(CONFIG_GRAPHICS_TRAVELER_JOYSTICK) +# include +# include + +#if defined(CONFIG_GRAPHICS_TRAVELER_AJOYSTICK) +# include +# include +#elif defined(CONFIG_GRAPHICS_TRAVELER_DJOYSTICK) +# include +#endif + +#elif defined(CONFIG_GRAPHICS_TRAVELER_NX_XYINPUT) +#endif + +/**************************************************************************** + * Pre-processor Definitions + *************************************************************************/ + +/**************************************************************************** + * Private Types + *************************************************************************/ + +struct trv_input_info_s +{ +#if defined(CONFIG_GRAPHICS_TRAVELER_JOYSTICK) + int fd; /* Open driver descriptor */ +#ifdef CONFIG_GRAPHICS_TRAVELER_AJOYSTICK + int16_t centerx; /* Center X position */ + b16_t leftslope; /* Slope for left of center */ + b16_t rightslope; /* Slope for left of center */ + int16_t centery; /* Center Y position */ + b16_t fwdslope; /* Slope for forward from center */ + b16_t backslope; /* Slope for backward from center */ +#endif +#elif defined(CONFIG_GRAPHICS_TRAVELER_NX_XYINPUT) + trv_coord_t xpos; /* Reported X position */ + trv_coord_t ypos; /* Reported Y position */ + uint8_t buttons; /* Report button set */ +#endif +}; + +/**************************************************************************** + * Public Data + *************************************************************************/ + +/* Report positional inputs */ + +struct trv_input_s g_trv_input; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +#ifdef CONFIG_GRAPHICS_TRAVELER_NX_XYINPUT +static struct trv_input_info_s g_trv_input_info; +#endif + +/**************************************************************************** + * Private Data + *************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: trv_joystick_calibrate + * + * Description: + * Calibrate the joystick + * + ****************************************************************************/ + +#ifdef CONFIG_GRAPHICS_TRAVELER_AJOYSTICK +static void trv_joystick_calibrate(void) +{ +#warning Missing logic" +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: trv_input_initialize + * + * Description: + * Initialize the selected input device + * + ****************************************************************************/ + +void trv_input_initialize(void) +{ +#if defined(CONFIG_GRAPHICS_TRAVELER_JOYSTICK) + /* Open the joy stick device */ + + g_trv_input_info.fd = open(CONFIG_GRAPHICS_TRAVELER_JOYDEV, O_RDONLY); + if (g_trv_input_info.fd < 0) + { + trv_abort("ERROR: Failed to open %s: %d\n", + CONFIG_GRAPHICS_TRAVELER_JOYDEV, errno); + } + +#ifdef CONFIG_GRAPHICS_TRAVELER_AJOYSTICK + /* Calibrate the analog joystick device */ + + trv_joystick_calibrate(); +#endif + +#elif defined(CONFIG_GRAPHICS_TRAVELER_NX_XYINPUT) + /* Set the position to the center of the display at eye-level */ +#warning Missing logic +#endif +} + +/**************************************************************************** + * Name: trv_input_read + * + * Description: + * Read the next input from the input device + * + ****************************************************************************/ + +void trv_input_read(void) +{ +#if defined(CONFIG_GRAPHICS_TRAVELER_JOYSTICK) +#if defined(CONFIG_GRAPHICS_TRAVELER_AJOYSTICK) + struct ajoy_sample_s sample; + int16_t move_rate; + int16_t turn_rate; + ssize_t nread; + + /* Read data from the analog joystick */ + + nread = read(g_trv_input_info.fd, &sample, sizeof(struct ajoy_sample_s)); + if (nread < 0) + { + trv_abort("ERROR: Joystick read error: %d\n", errno); + } + else if (nread != sizeof(struct ajoy_sample_s)) + { + trv_abort("ERROR: Unexpected joystick read size: %ld\n", (long)nread); + } + + /* Determine the input data to return to the POV logic */ +#warning Missing logic + +#elif defined(CONFIG_GRAPHICS_TRAVELER_DJOYSTICK) + struct djoy_buttonset_t buttonset; + ssize_t nread; + + /* Read data from the discrete joystick */ + + nread = read(g_trv_input_info.fd, &buttonset, sizeof(djoy_buttonset_t)); + if (nread < 0) + { + trv_abort("ERROR: Joystick read error: %d\n", errno); + } + else if (nread != sizeof(struct djoy_buttonset_t)) + { + trv_abort("ERROR: Unexpected joystick read size: %ld\n", (long)nread); + } + + /* Determine the input data to return to the POV logic */ + + if ((buttonset & DJOY_BUTTON_RUN_BIT) != 0) + { + /* Run faster/step higher */ + + g_trv_input.stepheight = g_run_step_height; + move_rate = 2 * STEP_DISTANCE; + turn_rate = ANGLE_9; + } + else + { + /* Normal walking rate and stepping height */ + + g_trv_input.stepheight = g_walk_step_height; + move_rate = STEP_DISTANCE; + turn_rate = ANGLE_6; + } + + /* Move forward or backward OR look up or down */ + + g_trv_input.pitchrate = 0; + g_trv_input.fwdrate = 0; + + switch (buttonset & (DJOY_UP_BIT | DJOY_DOWN_BIT)) + { + case 0: + case (DJOY_UP_BIT | DJOY_DOWN_BIT): + /* Don't move, don't nod */ + + break; + + case DJOY_UP_BIT: + if ((buttonset & DJOY_BUTTON_FIRE_BIT) != 0) + { + /* Look upward */ + + g_trv_input.pitchrate = turn_rate; + } + else + { + /* Move forward */ + + g_trv_input.fwdrate = move_rate; + } + break; + + case DJOY_DOWN_BIT: + if ((buttonset & DJOY_BUTTON_FIRE_BIT) != 0) + { + /* Look downward */ + + g_trv_input.pitchrate = -turn_rate; + } + else + { + /* Move Backward */ + + g_trv_input.fwdrate = -move_rate; + } + break; + } + + /* Move forward or backward OR look up or down */ + + g_trv_input.yawrate = 0; + g_trv_input.leftrate = 0; + + switch (buttonset & (DJOY_LEFT_BIT | DJOY_RIGHT_BIT)) + { + case 0: + case (DJOY_LEFT_BIT | DJOY_RIGHT_BIT): + /* Don't move, don't nod */ + + break; + + case DJOY_LEFT_BIT: + if ((buttonset & DJOY_BUTTON_FIRE_BIT) != 0) + { + /* Turn left */ + + g_trv_input.yawrate = turn_rate; + } + else + { + /* Move left */ + + g_trv_input.leftrate = move_rate; + } + break; + + case DJOY_RIGHT_BIT: + if ((buttonset & DJOY_BUTTON_FIRE_BIT) != 0) + { + /* Turn right */ + + g_trv_input.yawrate = -turn_rate; + } + else + { + /* Move right */ + + g_trv_input.leftrate = -move_rate; + } + break; + } + + g_trv_input.leftrate = ((buttonset & DJOY_BUTTON_SELECT) != 0); + +#endif /* CONFIG_GRAPHICS_TRAVELER_DJOYSTICK */ +#elif defined(CONFIG_GRAPHICS_TRAVELER_NX_XYINPUT) + /* Make position decision based on last sampled X/Y input data */ +#warning Missing logic +#endif +} + +/**************************************************************************** + * Name: trv_input_terminate + * + * Description: + * Terminate input and free resources + * + ****************************************************************************/ + +void trv_input_terminate(void) +{ +#ifdef CONFIG_GRAPHICS_TRAVELER_JOYSTICK +#endif +#warning Missing Logic +} + +/**************************************************************************** + * Name: trv_input_xyinput + * + * Description: + * Receive X/Y input from NX + * + ****************************************************************************/ + +#ifdef CONFIG_GRAPHICS_TRAVELER_NX_XYINPUT +void trv_input_xyinput(trv_coord_t xpos, trv_coord_t xpos, uint8_t buttons) +{ + /* Just save the positional data and button presses for now. We will + * decide what to do with the data when we are polled for new input. + */ + + g_trv_input_info.xpos = xpos; + g_trv_input_info.ypos = ypos; + g_trv_input_info.buttons = buttons; +} +#endif diff --git a/graphics/traveler/src/trv_main.c b/graphics/traveler/src/trv_main.c new file mode 100644 index 000000000..594513a9a --- /dev/null +++ b/graphics/traveler/src/trv_main.c @@ -0,0 +1,301 @@ +/**************************************************************************** + * apps/graphics/traveler/trv_main.c + * This file contains the main logic for the NuttX version of Traveler + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include + +#include "trv_types.h" +#include "trv_bitmaps.h" +#include "trv_world.h" +#include "trv_doors.h" +#include "trv_pov.h" +#include "trv_raycntl.h" +#include "trv_rayrend.h" +#include "trv_input.h" +#include "trv_graphics.h" +#include "trv_color.h" +#include "trv_debug.h" +#include "trv_main.h" + +#if CONFIG_GRAPHICS_TRAVELER_PERFMON +# include +# include +# include +#endif + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static void trv_exit(int exitCode); +static void trv_usage(char *execname); +#if CONFIG_GRAPHICS_TRAVELER_PERFMON +static double trv_current_time(void); +#endif + +/**************************************************************************** + * Public Data + *************************************************************************/ + +bool g_trv_terminate; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static void trv_exit(int exitcode) noreturn_function; +static void trv_usage(char *execname); +#ifdef CONFIG_GRAPHICS_TRAVELER_PERFMON +static double trv_current_time(void); +#endif + +/**************************************************************************** + * Private Data + *************************************************************************/ + +static const char g_default_worldfile[] = "transfrm.wld"; +static FAR struct trv_graphics_info_s g_trv_ginfo; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: trv_exit + * + * Description: + ****************************************************************************/ + +static void trv_exit(int exitcode) +{ + /* Release memory held by the ray casting engine */ + + trv_world_destroy(); + + /* Close off input */ + + trv_input_terminate(); + trv_graphics_terminate(&g_trv_ginfo); + + exit(exitcode); +} + +/**************************************************************************** + * Name: trv_usage + * + * Description: + ****************************************************************************/ + +static void trv_usage(char *execname) +{ + fprintf(stderr, "Usage: %s [-b] [-p] [world]\n", execname); + fprintf(stderr, "Where:\n"); + fprintf(stderr, " -p Selects the path to the world data file\n"); + fprintf(stderr, " world Selects the world file name\n"); + exit(EXIT_FAILURE); +} + +/**************************************************************************** + * Name: trv_current_time + * + * Description: + ****************************************************************************/ + +#ifdef CONFIG_GRAPHICS_TRAVELER_PERFMON +static double trv_current_time(void) +{ + struct timeval tv; + + gettimeofday(&tv, NULL); + return (double) tv.tv_sec + (double) tv.tv_usec / 1000000.0; +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: main + * + * Description: + ****************************************************************************/ + +#ifdef CONFIG_BUILD_KERNEL +int main(int argc, FAR char *argv[]) +#else +int traveler_main(int argc, char *argv[]) +#endif +{ + FAR const char *world_filename; +#ifdef CONFIG_GRAPHICS_TRAVELER_PERFMON + int32_t frame_count = 0; + double elapsed_time = 0.0; + double start_time; +#endif + int ret; + int i; + + /* Check for command line arguments */ + + world_filename = g_default_worldfile; + for (i = 1; i < argc; i++) + { + FAR char *ptr = argv[i]; + if (*ptr == '-') + { + ptr++; + switch (*ptr) + { + case 'p' : + ptr++; + printf("World data path = %s\n", ptr); + if (chdir(ptr)) + { + fprintf(stderr, "Bad path name\n"); + trv_usage(argv[0]); + } + break; + + default: + fprintf(stderr, "Invalid Switch\n"); + trv_usage(argv[0]); + break; + } + } + else + { + world_filename = ptr; + } + } + + trv_debug("World data file = %s\n", world_filename); + + /* Initialize the graphics interface */ + + trv_graphics_initialize(&g_trv_ginfo); + + /* Load the word data structures */ + + ret = trv_world_create(world_filename); + if (ret < 0) + { + trv_abort("ERROR: %d loading world file %s: %d\n", + world_filename, ret); + } + + /* Release color mapping tables */ + + trv_color_endmapping(); + + /* Set the player's POV in the new world */ + + trv_pov_reset(); + + /* Initialize the world's door */ + + trv_door_initialize(); + + /* Set up to receive input */ + + trv_input_initialize(); + + g_trv_terminate = false; + while (!g_trv_terminate) + { +#ifdef CONFIG_GRAPHICS_TRAVELER_PERFMON + start_time = trv_current_time(); +#endif + trv_input_read(); + + /* Select the POV to use on this viewing cycle */ + + trv_pov_new(); + + /* Process door animations */ + + trv_door_animate(); + + /* Paint the back drop */ + + trv_rend_backdrop(&g_trv_player); + + /* Render the 3-D view */ + + trv_raycaster(&g_trv_player, &g_trv_ginfo); + + /* Display the world. */ + + trv_display_update(&g_trv_ginfo); +#ifdef CONFIG_GRAPHICS_TRAVELER_PERFMON + frame_count++; + elapsed_time += trv_current_time() - start_time; + if (frame_count == 100) + { + fprintf(stderr, "fps = %3.2f\n", (double) frame_count / elapsed_time); + frame_count = 0; + elapsed_time = 0.0; + } +#endif + } + + trv_exit(EXIT_SUCCESS); + return 0; +} + +/**************************************************************************** + * Name: trv_abort + * + * Description: + ****************************************************************************/ + +void trv_abort(FAR char *message, ...) +{ + va_list args; + + va_start(args, message); + vfprintf(stderr, message, args); + putc('\n', stderr); + va_end(args); + + trv_exit(EXIT_FAILURE); +} diff --git a/graphics/traveler/src/trv_mem.c b/graphics/traveler/src/trv_mem.c new file mode 100644 index 000000000..84e85c3d0 --- /dev/null +++ b/graphics/traveler/src/trv_mem.c @@ -0,0 +1,85 @@ +/**************************************************************************** + * apps/graphics/traveler/src/trv_mem.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "trv_types.h" +#include "trv_main.h" +#include "trv_mem.h" + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: trv_malloc + * + * Description: + ****************************************************************************/ + +FAR void *trv_malloc(size_t size) +{ + FAR void *memory; + + memory = malloc(size); + if (memory == NULL) + { + trv_abort("Out of memory (trv_malloc %x bytes)", size); + } + + return memory; +} + +/**************************************************************************** + * Name: trv_free + * + * Description: + ****************************************************************************/ + +void trv_free(void *memory) +{ + if (memory == NULL) + { + trv_abort("Freeing NULL"); + } + else + { + free(memory); + } +} diff --git a/graphics/traveler/src/trv_nxbkgd.c b/graphics/traveler/src/trv_nxbkgd.c new file mode 100644 index 000000000..08a54a834 --- /dev/null +++ b/graphics/traveler/src/trv_nxbkgd.c @@ -0,0 +1,182 @@ +/**************************************************************************** + * apps/graphics/traveler/trv_nxbkgd.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "trv_types.h" +#ifdef CONFIG_GRAPHICS_TRAVELER_NX_XYINPUT +# include "trv_input.h" +#endif + +#include +#include +#include + +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static void trv_nxredraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, + bool morem, FAR void *arg); +static void trv_nxposition(NXWINDOW hwnd, FAR const struct nxgl_size_s *size, + FAR const struct nxgl_point_s *pos, + FAR const struct nxgl_rect_s *bounds, + FAR void *arg); +#ifdef CONFIG_NX_XYINPUT +static void trv_nxmousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos, + uint8_t buttons, FAR void *arg); +#endif + +#ifdef CONFIG_NX_KBD +static void trv_nxkbdin(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch, + FAR void *arg); +#endif + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* Background window call table */ + +const struct nx_callback_s g_trv_nxcallback = +{ + trv_nxredraw, /* redraw */ + trv_nxposition /* position */ +#ifdef CONFIG_NX_XYINPUT + , trv_nxmousein /* mousein */ +#endif +#ifdef CONFIG_NX_KBD + , trv_nxkbdin /* my kbdin */ +#endif +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: trv_nxredraw + ****************************************************************************/ + +static void trv_nxredraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, + bool more, FAR void *arg) +{ +} + +/**************************************************************************** + * Name: trv_nxposition + ****************************************************************************/ + +static void trv_nxposition(NXWINDOW hwnd, FAR const struct nxgl_size_s *size, + FAR const struct nxgl_point_s *pos, + FAR const struct nxgl_rect_s *bounds, + FAR void *arg) +{ + FAR struct trv_graphics_info_s *ginfo = (FAR struct trv_graphics_info_s *)arg; + + /* Report the position */ + + trv_vdebug("hwnd=%p size=(%d,%d) pos=(%d,%d) bounds={(%d,%d),(%d,%d)}\n", + hwnd, size->w, size->h, pos->x, pos->y, + bounds->pt1.x, bounds->pt1.y, bounds->pt2.x, bounds->pt2.y); + + /* Have we picked off the window bounds yet? */ + + if (!g_trv_nxresolution) + { + /* Save the background window handle */ + + ginnfo->bgwnd = hwnd; + + /* Save the background window size */ + + ginfo->width = size->w; + ginfo->height = size->h; + + g_trv_nxresolution = true; + sem_post(&g_trv_nxevent); + trv_vdebug("Have width=%d height=%d\n", ginfo->width, ginfo->height); + } +} + +/**************************************************************************** + * Name: trv_nxmousein + ****************************************************************************/ + +#ifdef CONFIG_NX_XYINPUT +static void trv_nxmousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos, + uint8_t buttons, FAR void *arg) +{ + trv_vdebug("trv_nxmousein: hwnd=%p pos=(%d,%d) button=%02x\n", + hwnd, pos->x, pos->y, buttons); + +#ifdef CONFIG_GRAPHICS_TRAVELER_NX_XYINPUT + trv_input_xyinput((trv_coord_t)pos->x,(trv_coord_t) pos->y, buttons); +#endif +} +#endif + +/**************************************************************************** + * Name: trv_nxkbdin + ****************************************************************************/ + +#ifdef CONFIG_NX_KBD +static void trv_nxkbdin(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch, + FAR void *arg) +{ + trv_vdebug("hwnd=%p nch=%d\n", hwnd, nch); +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ diff --git a/graphics/traveler/src/trv_nxserver.c b/graphics/traveler/src/trv_nxserver.c new file mode 100644 index 000000000..e2cedaa28 --- /dev/null +++ b/graphics/traveler/src/trv_nxserver.c @@ -0,0 +1,114 @@ +/**************************************************************************** + * apps/graphics/traveler/trv_nxlistener.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "trv_types.h" + +#include +#include +#include +#include + +#include +#include +#include + +#ifdef CONFIG_NX_MULTIUSER + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: trv_nxlistener + ****************************************************************************/ + +FAR void *trv_nxlistener(FAR void *arg) +{ + int ret; + + /* Process events forever */ + + for (;;) + { + /* Handle the next event. If we were configured blocking, then + * we will stay right here until the next event is received. Since + * we have dedicated a while thread to servicing events, it would + * be most natural to also select CONFIG_NX_BLOCKING -- if not, the + * following would be a tight infinite loop (unless we added addition + * logic with nx_eventnotify and sigwait to pace it). + */ + + ret = nx_eventhandler(g_hnx); + if (ret < 0) + { + /* An error occurred... assume that we have lost connection with + * the server. + */ + + trv_abort("Lost server connection: %d\n", errno); + } + + /* If we received a message, we must be connected */ + + if (!g_trv_nxrconnected) + { + g_trv_nxrconnected = true; + sem_post(&g_trv_nxevent); + trv_debug("Connected to server\n"); + } + } +} + +#endif /* CONFIG_NX_MULTIUSER */