From 0ba6435004f2a570c5a01eec5cd5bf6ef95d7fb9 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 30 Nov 2014 09:25:41 -0600 Subject: [PATCH 01/11] Beginning of a 1st person game --- graphics/traveller/Kconfig | 27 +++++ graphics/traveller/include/trv_debug.h | 139 +++++++++++++++++++++++++ graphics/traveller/include/trv_types.h | 73 +++++++++++++ 3 files changed, 239 insertions(+) create mode 100644 graphics/traveller/Kconfig create mode 100755 graphics/traveller/include/trv_debug.h create mode 100755 graphics/traveller/include/trv_types.h diff --git a/graphics/traveller/Kconfig b/graphics/traveller/Kconfig new file mode 100644 index 000000000..0906ebab9 --- /dev/null +++ b/graphics/traveller/Kconfig @@ -0,0 +1,27 @@ +# +# For a description of the syntax of this configuration file, +# see misc/tools/kconfig-language.txt. +# + +config GRAPHICS_TRAVELER + bool "Traveller game" + default n + select SYSTEM_INIFILE + ---help--- + Enable or disable the graphic Traveller game + +if GRAPHICS_TRAVELER + +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/traveller/include/trv_debug.h b/graphics/traveller/include/trv_debug.h new file mode 100755 index 000000000..33632df5f --- /dev/null +++ b/graphics/traveller/include/trv_debug.h @@ -0,0 +1,139 @@ +/**************************************************************************** + * apps/graphics/traveller/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_TRAVELLER_INCLUDE_TRV_DEBUG_H +#define __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_DEBUG_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "trv_types.h" + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Feature Selection Switches + * + * CONFIG_GRAPHICS_TRAVELLER_DEBUG_LEVEL == 3 turns off sound and video and + * enables verbose debug messages on stdout. + * CONFIG_GRAPHICS_TRAVELLER_DEBUG_LEVEL == 2 turns off sound and video and + * enables normal debug output + * CONFIG_GRAPHICS_TRAVELLER_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_TRAVELLER_DEBUG_LEVEL +# define CONFIG_GRAPHICS_TRAVELLER_DEBUG_LEVEL 0 +#ielf (CONFIG_GRAPHICS_TRAVELLER_DEBUG_LEVEL == 3) +# undef ENABLE_SOUND +# undef ENABLE_VIDEO +# define TRV_VERBOSE 1 +#elif (CONFIG_GRAPHICS_TRAVELLER_DEBUG_LEVEL == 2) +# undef ENABLE_SOUND +# undef ENABLE_VIDEO +#elif (CONFIG_GRAPHICS_TRAVELLER_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_TRAVELLER_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 vdbg(x...) +# endif + +# else + +# define dbg(x...) +# define vdbg(x...) + +# endif +#else + + /* Variadic macros NOT supported */ + +# if (CONFIG_GRAPHICS_TRAVELLER_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. + */ + +#ifndef CONFIG_CPP_HAVE_VARARGS && (CONFIG_GRAPHICS_TRAVELLER_DEBUG_LEVEL > 0) +int trv_debug(FAR const char *format, ...); +#endif + +#endif /* __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_DEBUG_H */ diff --git a/graphics/traveller/include/trv_types.h b/graphics/traveller/include/trv_types.h new file mode 100755 index 000000000..eb6c8549c --- /dev/null +++ b/graphics/traveller/include/trv_types.h @@ -0,0 +1,73 @@ +/**************************************************************************** + * apps/graphics/traveller/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_TRAVELLER_INCLUDE_TRV_TYPES_H +#define __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_TYPES_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#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; +typedef nxgl_mxpixel_t dev_pixel_t; + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#endif /* __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_TYPES_H */ From 8576a58cd181bf3ca6fb16994512fbf340f4cc46 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 30 Nov 2014 09:27:50 -0600 Subject: [PATCH 02/11] Remove carriage returns; correct file modes --- graphics/traveller/include/trv_debug.h | 0 graphics/traveller/include/trv_types.h | 146 ++++++++++++------------- 2 files changed, 73 insertions(+), 73 deletions(-) mode change 100755 => 100644 graphics/traveller/include/trv_debug.h mode change 100755 => 100644 graphics/traveller/include/trv_types.h diff --git a/graphics/traveller/include/trv_debug.h b/graphics/traveller/include/trv_debug.h old mode 100755 new mode 100644 diff --git a/graphics/traveller/include/trv_types.h b/graphics/traveller/include/trv_types.h old mode 100755 new mode 100644 index eb6c8549c..b7371b758 --- a/graphics/traveller/include/trv_types.h +++ b/graphics/traveller/include/trv_types.h @@ -1,73 +1,73 @@ -/**************************************************************************** - * apps/graphics/traveller/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_TRAVELLER_INCLUDE_TRV_TYPES_H -#define __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_TYPES_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#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; -typedef nxgl_mxpixel_t dev_pixel_t; - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#endif /* __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_TYPES_H */ +/**************************************************************************** + * apps/graphics/traveller/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_TRAVELLER_INCLUDE_TRV_TYPES_H +#define __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_TYPES_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#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; +typedef nxgl_mxpixel_t dev_pixel_t; + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#endif /* __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_TYPES_H */ From e1dd2a6221a811bb4d2ce2aff436f29791fdf191 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 30 Nov 2014 13:43:42 -0600 Subject: [PATCH 03/11] Add traveller main file and stubs for required headers --- graphics/Kconfig | 18 +- graphics/Make.defs | 4 + graphics/Makefile | 2 +- graphics/traveller/.gitignore | 11 + graphics/traveller/Kconfig | 13 +- graphics/traveller/Makefile | 142 ++++++++++ graphics/traveller/include/trv_bitmaps.h | 57 ++++ graphics/traveller/include/trv_color.h | 79 ++++++ graphics/traveller/include/trv_debug.h | 2 +- graphics/traveller/include/trv_doors.h | 52 ++++ graphics/traveller/include/trv_graphics.h | 82 ++++++ graphics/traveller/include/trv_input.h | 53 ++++ graphics/traveller/include/trv_main.h | 61 +++++ graphics/traveller/include/trv_pov.h | 61 +++++ graphics/traveller/include/trv_raycntl.h | 63 +++++ graphics/traveller/include/trv_rayrend.h | 60 +++++ graphics/traveller/include/trv_types.h | 7 +- graphics/traveller/include/trv_world.h | 69 +++++ graphics/traveller/src/trv_main.c | 312 ++++++++++++++++++++++ 19 files changed, 1134 insertions(+), 14 deletions(-) create mode 100644 graphics/traveller/.gitignore create mode 100644 graphics/traveller/Makefile create mode 100644 graphics/traveller/include/trv_bitmaps.h create mode 100644 graphics/traveller/include/trv_color.h create mode 100644 graphics/traveller/include/trv_doors.h create mode 100644 graphics/traveller/include/trv_graphics.h create mode 100644 graphics/traveller/include/trv_input.h create mode 100644 graphics/traveller/include/trv_main.h create mode 100644 graphics/traveller/include/trv_pov.h create mode 100644 graphics/traveller/include/trv_raycntl.h create mode 100644 graphics/traveller/include/trv_rayrend.h create mode 100644 graphics/traveller/include/trv_world.h create mode 100755 graphics/traveller/src/trv_main.c diff --git a/graphics/Kconfig b/graphics/Kconfig index a10650e27..55002bcc1 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 "Traveller game" + default n + select SYSTEM_INIFILE + ---help--- + Enable or disable the graphic Traveller game + +if GRAPHICS_TRAVELER + +menu "Traveller game" +source "$APPSDIR/graphics/traveller/Kconfig" +endmenu + +endif # GRAPHICS_TRAVELER + diff --git a/graphics/Make.defs b/graphics/Make.defs index 8f940cbad..3376e941a 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/traveller +endif diff --git a/graphics/Makefile b/graphics/Makefile index 7503c4343..551e21472 100644 --- a/graphics/Makefile +++ b/graphics/Makefile @@ -37,7 +37,7 @@ # Sub-directories -SUBDIRS = tiff screenshot +SUBDIRS = tiff screenshot traveller # Sub-directories that might need context setup diff --git a/graphics/traveller/.gitignore b/graphics/traveller/.gitignore new file mode 100644 index 000000000..83bd7b811 --- /dev/null +++ b/graphics/traveller/.gitignore @@ -0,0 +1,11 @@ +/Make.dep +/.depend +/.built +/*.asm +/*.rel +/*.lst +/*.sym +/*.adb +/*.lib +/*.src +/*.obj diff --git a/graphics/traveller/Kconfig b/graphics/traveller/Kconfig index 0906ebab9..3feee99bb 100644 --- a/graphics/traveller/Kconfig +++ b/graphics/traveller/Kconfig @@ -3,15 +3,14 @@ # see misc/tools/kconfig-language.txt. # -config GRAPHICS_TRAVELER - bool "Traveller game" - default n - select SYSTEM_INIFILE - ---help--- - Enable or disable the graphic Traveller game - if GRAPHICS_TRAVELER +config GRAPHICS_TRAVELER_PERFMON + bool "Performance monitor game" + default y + ---help--- + Enable or disable performance monitoring instrumentation and output. + config GRAPHICS_TRAVELER_DEBUG_LEVEL int "Debug output level" default 0 diff --git a/graphics/traveller/Makefile b/graphics/traveller/Makefile new file mode 100644 index 000000000..7a11a7b21 --- /dev/null +++ b/graphics/traveller/Makefile @@ -0,0 +1,142 @@ +############################################################################ +# apps/graphics/traveller/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 = traveller +PRIORITY = SCHED_PRIORITY_DEFAULT +STACKSIZE = 2048 + +# Hello, World! Example + +ASRCS = +CSRCS = +MAINSRC = trv_main.c + +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/traveller/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/traveller/include/trv_bitmaps.h b/graphics/traveller/include/trv_bitmaps.h new file mode 100644 index 000000000..43e6c84ea --- /dev/null +++ b/graphics/traveller/include/trv_bitmaps.h @@ -0,0 +1,57 @@ +/**************************************************************************** + * apps/graphics/traveller/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_TRAVELLER_INCLUDE_TRV_BITMAPS_H +#define __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_BITMAPS_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "trv_types.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#endif /* __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_BITMAPS_H */ diff --git a/graphics/traveller/include/trv_color.h b/graphics/traveller/include/trv_color.h new file mode 100644 index 000000000..3f11b4148 --- /dev/null +++ b/graphics/traveller/include/trv_color.h @@ -0,0 +1,79 @@ +/**************************************************************************** + * apps/graphics/traveller/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_TRAVELLER_INCLUDE_TRV_COLOR_H +#define __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_COLOR_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "trv_types.h" +#include "trv_graphics.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * 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 + ****************************************************************************/ + +bool trv_color_allocate(FAR struct trv_palette_s *pinfo); +void trv_color_endmapping(void); +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_TRAVELLER_INCLUDE_TRV_COLOR_H */ diff --git a/graphics/traveller/include/trv_debug.h b/graphics/traveller/include/trv_debug.h index 33632df5f..e0912f4fe 100644 --- a/graphics/traveller/include/trv_debug.h +++ b/graphics/traveller/include/trv_debug.h @@ -1,5 +1,5 @@ /**************************************************************************** - * apps/graphics/traveller/trv_debug.h + * apps/graphics/traveller/include/trv_debug.h * * Copyright (C) 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt diff --git a/graphics/traveller/include/trv_doors.h b/graphics/traveller/include/trv_doors.h new file mode 100644 index 000000000..44ab7e18c --- /dev/null +++ b/graphics/traveller/include/trv_doors.h @@ -0,0 +1,52 @@ +/**************************************************************************** + * apps/graphics/traveller/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_TRAVELLER_INCLUDE_TRV_DOORS_H +#define __APPS_GRAPHICS_TRAVELLER_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_TRAVELLER_INCLUDE_TRV_DOORS_H */ diff --git a/graphics/traveller/include/trv_graphics.h b/graphics/traveller/include/trv_graphics.h new file mode 100644 index 000000000..d63557b1b --- /dev/null +++ b/graphics/traveller/include/trv_graphics.h @@ -0,0 +1,82 @@ +/**************************************************************************** + * apps/graphics/traveller/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_TRAVELLER_INCLUDE_TRV_GRAPHICS_H +#define __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_GRAPHICS_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "trv_types.h" + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +struct trv_palette_s +{ + int ncolors; /* Number of colors in the look-up table */ + FAR nxgl_mxpixel_t *lut; /* Color lookup table */ +}; + +struct trv_graphics_info_s +{ + nxgl_coord_t width; /* Image width */ + nxgl_coord_t height; /* Image height */ + struct trv_palette_s palette; /* Color palette */ + FAR nxgl_mxpixel_t *buffer; /* Hardware framebuffer */ +}; + +struct trv_framebuffer_s +{ + nxgl_coord_t width; /* Image width */ + nxgl_coord_t height; /* Image height */ + FAR trv_pixel_t *buffer; /* Software render buffer */ +}; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +int trv_graphics_initialize(uint16_t width, uint16_t height, + uint8_t scale_factor, + FAR struct trv_graphics_info_s *ginfo); +void trv_graphics_terminate(void); +trv_pixel_t trv_graphics_index2pixel(int index); +void trv_display_update(struct trv_framebuffer_s *fb); +trv_pixel_t *trv_get_renderbuffer(uint16_t width, uint16_t height); + +#endif /* __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_GRAPHICS_H */ diff --git a/graphics/traveller/include/trv_input.h b/graphics/traveller/include/trv_input.h new file mode 100644 index 000000000..beeeb8179 --- /dev/null +++ b/graphics/traveller/include/trv_input.h @@ -0,0 +1,53 @@ +/**************************************************************************** + * apps/graphics/traveller/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_TRAVELLER_INCLUDE_TRV_INPUT_H +#define __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_INPUT_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "trv_types.h" + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +void trv_input_initialize(void); +void trv_input_read(void); +void trv_input_terminate(void); + +#endif /* __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_INPUT_H */ diff --git a/graphics/traveller/include/trv_main.h b/graphics/traveller/include/trv_main.h new file mode 100644 index 000000000..9d53c3ad5 --- /dev/null +++ b/graphics/traveller/include/trv_main.h @@ -0,0 +1,61 @@ +/**************************************************************************** + * apps/graphics/traveller/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_TRAVELLER_INCLUDE_TRV_MAIN_H +#define __APPS_GRAPHICS_TRAVELLER_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, ...); + +#endif /* __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_MAIN_H */ diff --git a/graphics/traveller/include/trv_pov.h b/graphics/traveller/include/trv_pov.h new file mode 100644 index 000000000..986480e11 --- /dev/null +++ b/graphics/traveller/include/trv_pov.h @@ -0,0 +1,61 @@ +/**************************************************************************** + * apps/graphics/traveller/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_TRAVELLER_INCLUDE_TRV_POV_H +#define __APPS_GRAPHICS_TRAVELLER_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_TRAVELLER_INCLUDE_TRV_POV_H */ diff --git a/graphics/traveller/include/trv_raycntl.h b/graphics/traveller/include/trv_raycntl.h new file mode 100644 index 000000000..a843cd2c8 --- /dev/null +++ b/graphics/traveller/include/trv_raycntl.h @@ -0,0 +1,63 @@ +/**************************************************************************** + * apps/graphics/traveller/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_TRAVELLER_INCLUDE_TRV_RAYCNTL_H +#define __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_RAYCNTL_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "trv_types.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +extern uint8_t *trv_raycaster_initialize(uint16_t screen_width, + uint16_t screen_height, + uint8_t scale_factor, + FAR uint8_t *screen_buffer); +extern void trv_raycaster(FAR struct trv_camera_s *player); + +#endif /* __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_RAYCNTL_H */ diff --git a/graphics/traveller/include/trv_rayrend.h b/graphics/traveller/include/trv_rayrend.h new file mode 100644 index 000000000..3773a977c --- /dev/null +++ b/graphics/traveller/include/trv_rayrend.h @@ -0,0 +1,60 @@ +/**************************************************************************** + * apps/graphics/traveller/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_TRAVELLER_INCLUDE_TRV_RAYEND_H +#define __APPS_GRAPHICS_TRAVELLER_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_TRAVELLER_INCLUDE_TRV_RAYEND_H */ diff --git a/graphics/traveller/include/trv_types.h b/graphics/traveller/include/trv_types.h index b7371b758..83ee29dd4 100644 --- a/graphics/traveller/include/trv_types.h +++ b/graphics/traveller/include/trv_types.h @@ -1,5 +1,5 @@ /**************************************************************************** - * apps/graphics/traveller/trv_types.h + * apps/graphics/traveller/include/trv_types.h * * Copyright (C) 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -63,11 +63,10 @@ * Public Types ****************************************************************************/ -typedef uint8_t trv_pixel_t; -typedef nxgl_mxpixel_t dev_pixel_t; +typedef uint8_t trv_pixel_t; /**************************************************************************** - * Pre-processor Definitions + * Public Function Prototypes ****************************************************************************/ #endif /* __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_TYPES_H */ diff --git a/graphics/traveller/include/trv_world.h b/graphics/traveller/include/trv_world.h new file mode 100644 index 000000000..5e06fc9a7 --- /dev/null +++ b/graphics/traveller/include/trv_world.h @@ -0,0 +1,69 @@ +/**************************************************************************** + * apps/graphics/traveller/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_TRAVELLER_INCLUDE_TRV_WORLD_H +#define __APPS_GRAPHICS_TRAVELLER_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 +{ + nxgl_coord_t x; /* Camera X position */ + nxgl_coord_t y; /* Camera Y position */ + nxgl_coord_t z; /* Camera Z position */ + int16_t yaw; /* Camera yaw orientation */ + int16_t pitch; /* Camera pitch orientation */ +}; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +int trv_world_create(FAR const char *mapfile); +void trv_world_destroy(void); + +#endif /* __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_WORLD_H */ diff --git a/graphics/traveller/src/trv_main.c b/graphics/traveller/src/trv_main.c new file mode 100755 index 000000000..6e4339f84 --- /dev/null +++ b/graphics/traveller/src/trv_main.c @@ -0,0 +1,312 @@ +/**************************************************************************** + * apps/graphics/traveller/trv_debug.h + * This file contains the main logic for the NuttX version of Traveller + * + * 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_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 Data + *************************************************************************/ + +static const char g_default_worldfile[] = "transfrm.wld"; + +/**************************************************************************** + * 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(); + + 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, " -b Selects 640x400 window (default is 320x200)\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: + ****************************************************************************/ + +int main(int argc, char *argv[]) +{ + FAR struct trv_graphics_info_s ginfo; + struct trv_framebuffer_s frame; + FAR const char *world_filename; + uint8_t scale_factor = 1; +#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 'b': + scale_factor = 2; + break; + + 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; + } + } + + printf("World data file = %s\n", world_filename); + + /* Initialize the graphics interface */ + + ret = trv_graphics_initialize(320, 200, scale_factor, &ginfo); + if (ret < 0) + { + fprintf(stderr, "ERROR: trv_graphics_initialize failed: %d\n", ret); + trv_exit(EXIT_FAILURE); + } + + /* Load the word data structures */ + + ret = trv_world_create(world_filename); + if (ret < 0) + { + fprintf(stderr, "ERROR: %d loading world file %s: %d\n", + world_filename, ret); + trv_exit(EXIT_FAILURE); + } + + /* We can now release any 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(); + + /* Initialize the ray cast engine */ + + frame.width = ginfo.width; + frame.height = ginfo.height; + frame.buffer = trv_get_renderbuffer(ginfo.width, ginfo.height); + + if (!trv_raycaster_initialize(frame.width, frame.height, + scale_factor, frame.buffer)) + { + fprintf(stderr, "Error: Initializing ray cast engine.\n"); + trv_exit(EXIT_FAILURE); + } + + /* 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); + + /* Display the world. */ + + trv_display_update(&frame); +#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); +} From 74e4ec91b6c4052eb381261befc4b0fd86674ca6 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 30 Nov 2014 14:06:05 -0600 Subject: [PATCH 04/11] Let's get consistent with spelling: Use the US spelling of traveler with one 'l' --- graphics/Kconfig | 8 ++--- graphics/Make.defs | 2 +- graphics/Makefile | 2 +- graphics/{traveller => traveler}/.gitignore | 0 graphics/{traveller => traveler}/Kconfig | 0 graphics/{traveller => traveler}/Makefile | 6 ++-- .../include/trv_bitmaps.h | 8 ++--- .../include/trv_color.h | 8 ++--- .../include/trv_debug.h | 30 +++++++++---------- .../include/trv_doors.h | 8 ++--- .../include/trv_graphics.h | 8 ++--- .../include/trv_input.h | 8 ++--- .../include/trv_main.h | 8 ++--- .../{traveller => traveler}/include/trv_pov.h | 8 ++--- .../include/trv_raycntl.h | 8 ++--- .../include/trv_rayrend.h | 8 ++--- .../include/trv_types.h | 8 ++--- .../include/trv_world.h | 8 ++--- .../{traveller => traveler}/src/trv_main.c | 4 +-- 19 files changed, 70 insertions(+), 70 deletions(-) rename graphics/{traveller => traveler}/.gitignore (100%) rename graphics/{traveller => traveler}/Kconfig (100%) rename graphics/{traveller => traveler}/Makefile (97%) rename graphics/{traveller => traveler}/include/trv_bitmaps.h (91%) rename graphics/{traveller => traveler}/include/trv_color.h (93%) rename graphics/{traveller => traveler}/include/trv_debug.h (81%) rename graphics/{traveller => traveler}/include/trv_doors.h (91%) rename graphics/{traveller => traveler}/include/trv_graphics.h (93%) rename graphics/{traveller => traveler}/include/trv_input.h (91%) rename graphics/{traveller => traveler}/include/trv_main.h (92%) rename graphics/{traveller => traveler}/include/trv_pov.h (92%) rename graphics/{traveller => traveler}/include/trv_raycntl.h (92%) rename graphics/{traveller => traveler}/include/trv_rayrend.h (92%) rename graphics/{traveller => traveler}/include/trv_types.h (92%) rename graphics/{traveller => traveler}/include/trv_world.h (92%) rename graphics/{traveller => traveler}/src/trv_main.c (99%) diff --git a/graphics/Kconfig b/graphics/Kconfig index 55002bcc1..74f084956 100644 --- a/graphics/Kconfig +++ b/graphics/Kconfig @@ -18,16 +18,16 @@ endmenu endif # TIFF config GRAPHICS_TRAVELER - bool "Traveller game" + bool "Traveler game" default n select SYSTEM_INIFILE ---help--- - Enable or disable the graphic Traveller game + Enable or disable the graphic Traveler game if GRAPHICS_TRAVELER -menu "Traveller game" -source "$APPSDIR/graphics/traveller/Kconfig" +menu "Traveler game" +source "$APPSDIR/graphics/traveler/Kconfig" endmenu endif # GRAPHICS_TRAVELER diff --git a/graphics/Make.defs b/graphics/Make.defs index 3376e941a..987c387b6 100644 --- a/graphics/Make.defs +++ b/graphics/Make.defs @@ -43,5 +43,5 @@ CONFIGURED_APPS += graphics/screenshot endif ifeq ($(CONFIG_GRAPHICS_TRAVELER),y) -CONFIGURED_APPS += graphics/traveller +CONFIGURED_APPS += graphics/traveler endif diff --git a/graphics/Makefile b/graphics/Makefile index 551e21472..7f33fe2a4 100644 --- a/graphics/Makefile +++ b/graphics/Makefile @@ -37,7 +37,7 @@ # Sub-directories -SUBDIRS = tiff screenshot traveller +SUBDIRS = tiff screenshot traveler # Sub-directories that might need context setup diff --git a/graphics/traveller/.gitignore b/graphics/traveler/.gitignore similarity index 100% rename from graphics/traveller/.gitignore rename to graphics/traveler/.gitignore diff --git a/graphics/traveller/Kconfig b/graphics/traveler/Kconfig similarity index 100% rename from graphics/traveller/Kconfig rename to graphics/traveler/Kconfig diff --git a/graphics/traveller/Makefile b/graphics/traveler/Makefile similarity index 97% rename from graphics/traveller/Makefile rename to graphics/traveler/Makefile index 7a11a7b21..75d48566f 100644 --- a/graphics/traveller/Makefile +++ b/graphics/traveler/Makefile @@ -1,5 +1,5 @@ ############################################################################ -# apps/graphics/traveller/Makefile +# apps/graphics/traveler/Makefile # # Copyright (C) 2014 Gregory Nutt. All rights reserved. # Author: Gregory Nutt @@ -39,7 +39,7 @@ include $(APPDIR)/Make.defs # Hello, World! built-in application info -APPNAME = traveller +APPNAME = traveler PRIORITY = SCHED_PRIORITY_DEFAULT STACKSIZE = 2048 @@ -83,7 +83,7 @@ ifeq ($(WINTOOL),y) INCDIROPT = -w endif -CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/graphics/traveller/include} +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/graphics/traveler/include} DEPPATH = --dep-path src VPATH = src diff --git a/graphics/traveller/include/trv_bitmaps.h b/graphics/traveler/include/trv_bitmaps.h similarity index 91% rename from graphics/traveller/include/trv_bitmaps.h rename to graphics/traveler/include/trv_bitmaps.h index 43e6c84ea..82df0c145 100644 --- a/graphics/traveller/include/trv_bitmaps.h +++ b/graphics/traveler/include/trv_bitmaps.h @@ -1,5 +1,5 @@ /**************************************************************************** - * apps/graphics/traveller/include/trv_bitmaps.h + * apps/graphics/traveler/include/trv_bitmaps.h * * Copyright (C) 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_BITMAPS_H -#define __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_BITMAPS_H +#ifndef __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_BITMAPS_H +#define __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_BITMAPS_H /**************************************************************************** * Included Files @@ -54,4 +54,4 @@ * Public Function Prototypes ****************************************************************************/ -#endif /* __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_BITMAPS_H */ +#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_BITMAPS_H */ diff --git a/graphics/traveller/include/trv_color.h b/graphics/traveler/include/trv_color.h similarity index 93% rename from graphics/traveller/include/trv_color.h rename to graphics/traveler/include/trv_color.h index 3f11b4148..04e9d1523 100644 --- a/graphics/traveller/include/trv_color.h +++ b/graphics/traveler/include/trv_color.h @@ -1,5 +1,5 @@ /**************************************************************************** - * apps/graphics/traveller/include/trv_color.h + * apps/graphics/traveler/include/trv_color.h * * Copyright (C) 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_COLOR_H -#define __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_COLOR_H +#ifndef __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_COLOR_H +#define __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_COLOR_H /**************************************************************************** * Included Files @@ -76,4 +76,4 @@ 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_TRAVELLER_INCLUDE_TRV_COLOR_H */ +#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_COLOR_H */ diff --git a/graphics/traveller/include/trv_debug.h b/graphics/traveler/include/trv_debug.h similarity index 81% rename from graphics/traveller/include/trv_debug.h rename to graphics/traveler/include/trv_debug.h index e0912f4fe..d54b1eb13 100644 --- a/graphics/traveller/include/trv_debug.h +++ b/graphics/traveler/include/trv_debug.h @@ -1,5 +1,5 @@ /**************************************************************************** - * apps/graphics/traveller/include/trv_debug.h + * apps/graphics/traveler/include/trv_debug.h * * Copyright (C) 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_DEBUG_H -#define __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_DEBUG_H +#ifndef __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_DEBUG_H +#define __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_DEBUG_H /**************************************************************************** * Included Files @@ -50,11 +50,11 @@ /* Feature Selection Switches * - * CONFIG_GRAPHICS_TRAVELLER_DEBUG_LEVEL == 3 turns off sound and video and + * CONFIG_GRAPHICS_TRAVELER_DEBUG_LEVEL == 3 turns off sound and video and * enables verbose debug messages on stdout. - * CONFIG_GRAPHICS_TRAVELLER_DEBUG_LEVEL == 2 turns off sound and video and + * CONFIG_GRAPHICS_TRAVELER_DEBUG_LEVEL == 2 turns off sound and video and * enables normal debug output - * CONFIG_GRAPHICS_TRAVELLER_DEBUG_LEVEL == 1 turns off sound and enables + * CONFIG_GRAPHICS_TRAVELER_DEBUG_LEVEL == 1 turns off sound and enables * normal debug output * OTHERWISE, all debugging features are disabled. */ @@ -63,16 +63,16 @@ #define ENABLE_VIDEO 1 #undef TRV_VERBOSE -#ifndef CONFIG_GRAPHICS_TRAVELLER_DEBUG_LEVEL -# define CONFIG_GRAPHICS_TRAVELLER_DEBUG_LEVEL 0 -#ielf (CONFIG_GRAPHICS_TRAVELLER_DEBUG_LEVEL == 3) +#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_TRAVELLER_DEBUG_LEVEL == 2) +#elif (CONFIG_GRAPHICS_TRAVELER_DEBUG_LEVEL == 2) # undef ENABLE_SOUND # undef ENABLE_VIDEO -#elif (CONFIG_GRAPHICS_TRAVELLER_DEBUG_LEVEL == 1) +#elif (CONFIG_GRAPHICS_TRAVELER_DEBUG_LEVEL == 1) # undef ENABLE_SOUND #endif @@ -83,7 +83,7 @@ /* Debug output macros */ #ifdef CONFIG_CPP_HAVE_VARARGS -# if (CONFIG_GRAPHICS_TRAVELLER_DEBUG_LEVEL > 0) +# if (CONFIG_GRAPHICS_TRAVELER_DEBUG_LEVEL > 0) # define trv_debug(format, ...) \ printf(EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) @@ -106,7 +106,7 @@ /* Variadic macros NOT supported */ -# if (CONFIG_GRAPHICS_TRAVELLER_DEBUG_LEVEL > 0) +# if (CONFIG_GRAPHICS_TRAVELER_DEBUG_LEVEL > 0) # ifdef TRV_VERBOSE # define trv_vdebug trv_debug # else @@ -132,8 +132,8 @@ * arguments, then this additional interface will be built. */ -#ifndef CONFIG_CPP_HAVE_VARARGS && (CONFIG_GRAPHICS_TRAVELLER_DEBUG_LEVEL > 0) +#ifndef CONFIG_CPP_HAVE_VARARGS && (CONFIG_GRAPHICS_TRAVELER_DEBUG_LEVEL > 0) int trv_debug(FAR const char *format, ...); #endif -#endif /* __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_DEBUG_H */ +#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_DEBUG_H */ diff --git a/graphics/traveller/include/trv_doors.h b/graphics/traveler/include/trv_doors.h similarity index 91% rename from graphics/traveller/include/trv_doors.h rename to graphics/traveler/include/trv_doors.h index 44ab7e18c..9179e2979 100644 --- a/graphics/traveller/include/trv_doors.h +++ b/graphics/traveler/include/trv_doors.h @@ -1,5 +1,5 @@ /**************************************************************************** - * apps/graphics/traveller/include/trv_doors.h + * apps/graphics/traveler/include/trv_doors.h * * Copyright (C) 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_DOORS_H -#define __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_DOORS_H +#ifndef __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_DOORS_H +#define __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_DOORS_H /**************************************************************************** * Included Files @@ -49,4 +49,4 @@ void trv_door_initialize(void); void trv_door_animate(void); -#endif /* __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_DOORS_H */ +#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_DOORS_H */ diff --git a/graphics/traveller/include/trv_graphics.h b/graphics/traveler/include/trv_graphics.h similarity index 93% rename from graphics/traveller/include/trv_graphics.h rename to graphics/traveler/include/trv_graphics.h index d63557b1b..5364c8bc7 100644 --- a/graphics/traveller/include/trv_graphics.h +++ b/graphics/traveler/include/trv_graphics.h @@ -1,5 +1,5 @@ /**************************************************************************** - * apps/graphics/traveller/include/trv_graphics.h + * apps/graphics/traveler/include/trv_graphics.h * * Copyright (C) 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_GRAPHICS_H -#define __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_GRAPHICS_H +#ifndef __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_GRAPHICS_H +#define __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_GRAPHICS_H /**************************************************************************** * Included Files @@ -79,4 +79,4 @@ trv_pixel_t trv_graphics_index2pixel(int index); void trv_display_update(struct trv_framebuffer_s *fb); trv_pixel_t *trv_get_renderbuffer(uint16_t width, uint16_t height); -#endif /* __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_GRAPHICS_H */ +#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_GRAPHICS_H */ diff --git a/graphics/traveller/include/trv_input.h b/graphics/traveler/include/trv_input.h similarity index 91% rename from graphics/traveller/include/trv_input.h rename to graphics/traveler/include/trv_input.h index beeeb8179..b4b4cf442 100644 --- a/graphics/traveller/include/trv_input.h +++ b/graphics/traveler/include/trv_input.h @@ -1,5 +1,5 @@ /**************************************************************************** - * apps/graphics/traveller/include/trv_input.h + * apps/graphics/traveler/include/trv_input.h * * Copyright (C) 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_INPUT_H -#define __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_INPUT_H +#ifndef __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_INPUT_H +#define __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_INPUT_H /**************************************************************************** * Included Files @@ -50,4 +50,4 @@ void trv_input_initialize(void); void trv_input_read(void); void trv_input_terminate(void); -#endif /* __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_INPUT_H */ +#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_INPUT_H */ diff --git a/graphics/traveller/include/trv_main.h b/graphics/traveler/include/trv_main.h similarity index 92% rename from graphics/traveller/include/trv_main.h rename to graphics/traveler/include/trv_main.h index 9d53c3ad5..08d16ef2b 100644 --- a/graphics/traveller/include/trv_main.h +++ b/graphics/traveler/include/trv_main.h @@ -1,5 +1,5 @@ /**************************************************************************** - * apps/graphics/traveller/include/trv_main.h + * apps/graphics/traveler/include/trv_main.h * * Copyright (C) 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_MAIN_H -#define __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_MAIN_H +#ifndef __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_MAIN_H +#define __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_MAIN_H /**************************************************************************** * Included Files @@ -58,4 +58,4 @@ extern bool g_trv_terminate; void trv_abort(FAR char *format, ...); -#endif /* __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_MAIN_H */ +#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_MAIN_H */ diff --git a/graphics/traveller/include/trv_pov.h b/graphics/traveler/include/trv_pov.h similarity index 92% rename from graphics/traveller/include/trv_pov.h rename to graphics/traveler/include/trv_pov.h index 986480e11..2edc5b7a2 100644 --- a/graphics/traveller/include/trv_pov.h +++ b/graphics/traveler/include/trv_pov.h @@ -1,5 +1,5 @@ /**************************************************************************** - * apps/graphics/traveller/include/trv_pov.h + * apps/graphics/traveler/include/trv_pov.h * * Copyright (C) 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_POV_H -#define __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_POV_H +#ifndef __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_POV_H +#define __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_POV_H /**************************************************************************** * Included Files @@ -58,4 +58,4 @@ extern struct trv_camera_s g_trv_player; void trv_pov_reset(void); void trv_pov_new(void); -#endif /* __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_POV_H */ +#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_POV_H */ diff --git a/graphics/traveller/include/trv_raycntl.h b/graphics/traveler/include/trv_raycntl.h similarity index 92% rename from graphics/traveller/include/trv_raycntl.h rename to graphics/traveler/include/trv_raycntl.h index a843cd2c8..01cbed191 100644 --- a/graphics/traveller/include/trv_raycntl.h +++ b/graphics/traveler/include/trv_raycntl.h @@ -1,5 +1,5 @@ /**************************************************************************** - * apps/graphics/traveller/include/trv_raycntl.h + * apps/graphics/traveler/include/trv_raycntl.h * * Copyright (C) 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_RAYCNTL_H -#define __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_RAYCNTL_H +#ifndef __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_RAYCNTL_H +#define __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_RAYCNTL_H /**************************************************************************** * Included Files @@ -60,4 +60,4 @@ extern uint8_t *trv_raycaster_initialize(uint16_t screen_width, FAR uint8_t *screen_buffer); extern void trv_raycaster(FAR struct trv_camera_s *player); -#endif /* __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_RAYCNTL_H */ +#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_RAYCNTL_H */ diff --git a/graphics/traveller/include/trv_rayrend.h b/graphics/traveler/include/trv_rayrend.h similarity index 92% rename from graphics/traveller/include/trv_rayrend.h rename to graphics/traveler/include/trv_rayrend.h index 3773a977c..189e17e46 100644 --- a/graphics/traveller/include/trv_rayrend.h +++ b/graphics/traveler/include/trv_rayrend.h @@ -1,5 +1,5 @@ /**************************************************************************** - * apps/graphics/traveller/include/trv_rayrend.h + * apps/graphics/traveler/include/trv_rayrend.h * * Copyright (C) 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_RAYEND_H -#define __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_RAYEND_H +#ifndef __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_RAYEND_H +#define __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_RAYEND_H /**************************************************************************** * Included Files @@ -57,4 +57,4 @@ void trv_rend_backdrop (struct trv_camera_s *camera); -#endif /* __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_RAYEND_H */ +#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_RAYEND_H */ diff --git a/graphics/traveller/include/trv_types.h b/graphics/traveler/include/trv_types.h similarity index 92% rename from graphics/traveller/include/trv_types.h rename to graphics/traveler/include/trv_types.h index 83ee29dd4..6fbf61071 100644 --- a/graphics/traveller/include/trv_types.h +++ b/graphics/traveler/include/trv_types.h @@ -1,5 +1,5 @@ /**************************************************************************** - * apps/graphics/traveller/include/trv_types.h + * apps/graphics/traveler/include/trv_types.h * * Copyright (C) 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_TYPES_H -#define __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_TYPES_H +#ifndef __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_TYPES_H +#define __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_TYPES_H /**************************************************************************** * Included Files @@ -69,4 +69,4 @@ typedef uint8_t trv_pixel_t; * Public Function Prototypes ****************************************************************************/ -#endif /* __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_TYPES_H */ +#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_TYPES_H */ diff --git a/graphics/traveller/include/trv_world.h b/graphics/traveler/include/trv_world.h similarity index 92% rename from graphics/traveller/include/trv_world.h rename to graphics/traveler/include/trv_world.h index 5e06fc9a7..b590e2f87 100644 --- a/graphics/traveller/include/trv_world.h +++ b/graphics/traveler/include/trv_world.h @@ -1,5 +1,5 @@ /**************************************************************************** - * apps/graphics/traveller/include/trv_world.h + * apps/graphics/traveler/include/trv_world.h * * Copyright (C) 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_WORLD_H -#define __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_WORLD_H +#ifndef __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_WORLD_H +#define __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_WORLD_H /**************************************************************************** * Included Files @@ -66,4 +66,4 @@ struct trv_camera_s int trv_world_create(FAR const char *mapfile); void trv_world_destroy(void); -#endif /* __APPS_GRAPHICS_TRAVELLER_INCLUDE_TRV_WORLD_H */ +#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_WORLD_H */ diff --git a/graphics/traveller/src/trv_main.c b/graphics/traveler/src/trv_main.c similarity index 99% rename from graphics/traveller/src/trv_main.c rename to graphics/traveler/src/trv_main.c index 6e4339f84..6f74055ba 100755 --- a/graphics/traveller/src/trv_main.c +++ b/graphics/traveler/src/trv_main.c @@ -1,6 +1,6 @@ /**************************************************************************** - * apps/graphics/traveller/trv_debug.h - * This file contains the main logic for the NuttX version of Traveller + * apps/graphics/traveler/trv_debug.h + * This file contains the main logic for the NuttX version of Traveler * * Copyright (C) 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt From 403c0951c576be7eb12f273bed6667c13cb57821 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 30 Nov 2014 15:44:11 -0600 Subject: [PATCH 05/11] A few more traveler fixes --- graphics/traveler/Kconfig | 1 + graphics/traveler/src/trv_main.c | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/graphics/traveler/Kconfig b/graphics/traveler/Kconfig index 3feee99bb..e938ec742 100644 --- a/graphics/traveler/Kconfig +++ b/graphics/traveler/Kconfig @@ -8,6 +8,7 @@ if GRAPHICS_TRAVELER config GRAPHICS_TRAVELER_PERFMON bool "Performance monitor game" default y + depends on NX && FS_READABLE && !NX_LCDDRIVER ---help--- Enable or disable performance monitoring instrumentation and output. diff --git a/graphics/traveler/src/trv_main.c b/graphics/traveler/src/trv_main.c index 6f74055ba..604ff2975 100755 --- a/graphics/traveler/src/trv_main.c +++ b/graphics/traveler/src/trv_main.c @@ -149,7 +149,11 @@ static double trv_current_time(void) * Description: ****************************************************************************/ -int main(int argc, char *argv[]) +#ifdef CONFIG_BUILD_KERNEL +int main(int argc, FAR char *argv[]) +#else +int traveler_main(int argc, char *argv[]) +#endif { FAR struct trv_graphics_info_s ginfo; struct trv_framebuffer_s frame; From 4c32019e4d218ab6140455657b648304519577a1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 1 Dec 2014 14:04:33 -0600 Subject: [PATCH 06/11] Add graphic device initialize logic (incomplete) --- examples/nxtext/nxtext_main.c | 2 +- examples/nxtext/nxtext_server.c | 2 +- graphics/traveler/Kconfig | 16 +- graphics/traveler/Makefile | 9 +- graphics/traveler/include/trv_color.h | 2 +- graphics/traveler/include/trv_debug.h | 8 +- graphics/traveler/include/trv_graphics.h | 77 ++- graphics/traveler/include/trv_main.h | 2 +- graphics/traveler/include/trv_mem.h | 52 +++ graphics/traveler/include/trv_raycntl.h | 8 +- graphics/traveler/include/trv_types.h | 7 +- graphics/traveler/include/trv_world.h | 10 +- graphics/traveler/src/trv_graphics.c | 572 +++++++++++++++++++++++ graphics/traveler/src/trv_main.c | 62 +-- graphics/traveler/src/trv_mem.c | 85 ++++ graphics/traveler/src/trv_nxbkgd.c | 175 +++++++ graphics/traveler/src/trv_nxserver.c | 114 +++++ 17 files changed, 1123 insertions(+), 80 deletions(-) create mode 100644 graphics/traveler/include/trv_mem.h create mode 100755 graphics/traveler/src/trv_graphics.c create mode 100755 graphics/traveler/src/trv_mem.c create mode 100644 graphics/traveler/src/trv_nxbkgd.c create mode 100644 graphics/traveler/src/trv_nxserver.c 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/traveler/Kconfig b/graphics/traveler/Kconfig index e938ec742..851ab4ca7 100644 --- a/graphics/traveler/Kconfig +++ b/graphics/traveler/Kconfig @@ -5,10 +5,22 @@ 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_PERFMON - bool "Performance monitor game" + bool "Performance monitor" default y - depends on NX && FS_READABLE && !NX_LCDDRIVER + depends on FS_READABLE ---help--- Enable or disable performance monitoring instrumentation and output. diff --git a/graphics/traveler/Makefile b/graphics/traveler/Makefile index 75d48566f..e04bf51c3 100644 --- a/graphics/traveler/Makefile +++ b/graphics/traveler/Makefile @@ -46,9 +46,16 @@ STACKSIZE = 2048 # Hello, World! Example ASRCS = -CSRCS = +CSRCS = trv_mem.c trv_graphics.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)) diff --git a/graphics/traveler/include/trv_color.h b/graphics/traveler/include/trv_color.h index 04e9d1523..0a2cf78bb 100644 --- a/graphics/traveler/include/trv_color.h +++ b/graphics/traveler/include/trv_color.h @@ -71,7 +71,7 @@ struct trv_color_lum_s ****************************************************************************/ bool 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); diff --git a/graphics/traveler/include/trv_debug.h b/graphics/traveler/include/trv_debug.h index d54b1eb13..08b4c2d3b 100644 --- a/graphics/traveler/include/trv_debug.h +++ b/graphics/traveler/include/trv_debug.h @@ -93,13 +93,13 @@ printf(EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) # else -# define vdbg(x...) +# define trv_vdebug(x...) # endif # else -# define dbg(x...) -# define vdbg(x...) +# define trv_debug(x...) +# define trv_vdebug(x...) # endif #else @@ -132,7 +132,7 @@ * arguments, then this additional interface will be built. */ -#ifndef CONFIG_CPP_HAVE_VARARGS && (CONFIG_GRAPHICS_TRAVELER_DEBUG_LEVEL > 0) +#if !defined(CONFIG_CPP_HAVE_VARARGS) && CONFIG_GRAPHICS_TRAVELER_DEBUG_LEVEL > 0 int trv_debug(FAR const char *format, ...); #endif diff --git a/graphics/traveler/include/trv_graphics.h b/graphics/traveler/include/trv_graphics.h index 5364c8bc7..69790e627 100644 --- a/graphics/traveler/include/trv_graphics.h +++ b/graphics/traveler/include/trv_graphics.h @@ -42,41 +42,88 @@ #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 nxgl_mxpixel_t *lut; /* Color lookup table */ + FAR dev_pixel_t *lut; /* Color lookup table */ }; struct trv_graphics_info_s { - nxgl_coord_t width; /* Image width */ - nxgl_coord_t height; /* Image height */ +#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 nxgl_mxpixel_t *buffer; /* Hardware framebuffer */ + FAR dev_pixel_t *hwbuffer; /* Hardware frame buffer */ + FAR trv_pixel_t *swbuffer; /* Software render buffer */ }; -struct trv_framebuffer_s -{ - nxgl_coord_t width; /* Image width */ - nxgl_coord_t height; /* Image height */ - FAR trv_pixel_t *buffer; /* 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(uint16_t width, uint16_t height, - uint8_t scale_factor, - FAR struct trv_graphics_info_s *ginfo); -void trv_graphics_terminate(void); +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_framebuffer_s *fb); +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_main.h b/graphics/traveler/include/trv_main.h index 08d16ef2b..62c5ad61f 100644 --- a/graphics/traveler/include/trv_main.h +++ b/graphics/traveler/include/trv_main.h @@ -56,6 +56,6 @@ extern bool g_trv_terminate; * Public Function Prototypes ****************************************************************************/ -void trv_abort(FAR char *format, ...); +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_raycntl.h b/graphics/traveler/include/trv_raycntl.h index 01cbed191..ffcf2b6d3 100644 --- a/graphics/traveler/include/trv_raycntl.h +++ b/graphics/traveler/include/trv_raycntl.h @@ -41,6 +41,7 @@ ****************************************************************************/ #include "trv_types.h" +#include "trv_graphics.h" /**************************************************************************** * Pre-processor Definitions @@ -54,10 +55,7 @@ * Public Function Prototypes ****************************************************************************/ -extern uint8_t *trv_raycaster_initialize(uint16_t screen_width, - uint16_t screen_height, - uint8_t scale_factor, - FAR uint8_t *screen_buffer); -extern void trv_raycaster(FAR struct trv_camera_s *player); +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_types.h b/graphics/traveler/include/trv_types.h index 6fbf61071..2eb9f2618 100644 --- a/graphics/traveler/include/trv_types.h +++ b/graphics/traveler/include/trv_types.h @@ -41,12 +41,12 @@ ****************************************************************************/ #include +#include +#include #include #include -#include - /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -63,7 +63,8 @@ * Public Types ****************************************************************************/ -typedef uint8_t trv_pixel_t; +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 diff --git a/graphics/traveler/include/trv_world.h b/graphics/traveler/include/trv_world.h index b590e2f87..939ec1820 100644 --- a/graphics/traveler/include/trv_world.h +++ b/graphics/traveler/include/trv_world.h @@ -52,11 +52,11 @@ struct trv_camera_s { - nxgl_coord_t x; /* Camera X position */ - nxgl_coord_t y; /* Camera Y position */ - nxgl_coord_t z; /* Camera Z position */ - int16_t yaw; /* Camera yaw orientation */ - int16_t pitch; /* Camera pitch orientation */ + 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 */ }; /**************************************************************************** diff --git a/graphics/traveler/src/trv_graphics.c b/graphics/traveler/src/trv_graphics.c new file mode 100755 index 000000000..6742147aa --- /dev/null +++ b/graphics/traveler/src/trv_graphics.c @@ -0,0 +1,572 @@ +/**************************************************************************** + * 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; + int ret; + + /* 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 */ + + ret = trv_color_allocate(&ginfo->palette); + if (ret < 0) + { + trv_abort("ERROR trv_color_allocate failed: %d"); + } + + 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_main.c b/graphics/traveler/src/trv_main.c index 604ff2975..fc9de19f6 100755 --- a/graphics/traveler/src/trv_main.c +++ b/graphics/traveler/src/trv_main.c @@ -52,7 +52,7 @@ #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 @@ -77,11 +77,22 @@ static double trv_current_time(void); 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 @@ -93,7 +104,7 @@ static const char g_default_worldfile[] = "transfrm.wld"; * Description: ****************************************************************************/ -static void trv_exit(int exitCode) +static void trv_exit(int exitcode) { /* Release memory held by the ray casting engine */ @@ -102,9 +113,9 @@ static void trv_exit(int exitCode) /* Close off input */ trv_input_terminate(); - trv_graphics_terminate(); + trv_graphics_terminate(&g_trv_ginfo); - exit(exitCode); + exit(exitcode); } /**************************************************************************** @@ -117,7 +128,6 @@ static void trv_usage(char *execname) { fprintf(stderr, "Usage: %s [-b] [-p] [world]\n", execname); fprintf(stderr, "Where:\n"); - fprintf(stderr, " -b Selects 640x400 window (default is 320x200)\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); @@ -155,10 +165,7 @@ int main(int argc, FAR char *argv[]) int traveler_main(int argc, char *argv[]) #endif { - FAR struct trv_graphics_info_s ginfo; - struct trv_framebuffer_s frame; FAR const char *world_filename; - uint8_t scale_factor = 1; #ifdef CONFIG_GRAPHICS_TRAVELER_PERFMON int32_t frame_count = 0; double elapsed_time = 0.0; @@ -178,10 +185,6 @@ int traveler_main(int argc, char *argv[]) ptr++; switch (*ptr) { - case 'b': - scale_factor = 2; - break; - case 'p' : ptr++; printf("World data path = %s\n", ptr); @@ -204,31 +207,21 @@ int traveler_main(int argc, char *argv[]) } } - printf("World data file = %s\n", world_filename); + trv_debug("World data file = %s\n", world_filename); /* Initialize the graphics interface */ - ret = trv_graphics_initialize(320, 200, scale_factor, &ginfo); - if (ret < 0) - { - fprintf(stderr, "ERROR: trv_graphics_initialize failed: %d\n", ret); - trv_exit(EXIT_FAILURE); - } + trv_graphics_initialize(&g_trv_ginfo); /* Load the word data structures */ ret = trv_world_create(world_filename); if (ret < 0) { - fprintf(stderr, "ERROR: %d loading world file %s: %d\n", - world_filename, ret); - trv_exit(EXIT_FAILURE); + trv_abort("ERROR: %d loading world file %s: %d\n", + world_filename, ret); } - /* We can now release any color mapping tables */ - - trv_color_endmapping(); - /* Set the player's POV in the new world */ trv_pov_reset(); @@ -237,19 +230,6 @@ int traveler_main(int argc, char *argv[]) trv_door_initialize(); - /* Initialize the ray cast engine */ - - frame.width = ginfo.width; - frame.height = ginfo.height; - frame.buffer = trv_get_renderbuffer(ginfo.width, ginfo.height); - - if (!trv_raycaster_initialize(frame.width, frame.height, - scale_factor, frame.buffer)) - { - fprintf(stderr, "Error: Initializing ray cast engine.\n"); - trv_exit(EXIT_FAILURE); - } - /* Set up to receive input */ trv_input_initialize(); @@ -276,11 +256,11 @@ int traveler_main(int argc, char *argv[]) /* Render the 3-D view */ - trv_raycaster(&g_trv_player); + trv_raycaster(&g_trv_player, &g_trv_ginfo); /* Display the world. */ - trv_display_update(&frame); + trv_display_update(&g_trv_ginfo); #ifdef CONFIG_GRAPHICS_TRAVELER_PERFMON frame_count++; elapsed_time += trv_current_time() - start_time; diff --git a/graphics/traveler/src/trv_mem.c b/graphics/traveler/src/trv_mem.c new file mode 100755 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..4bd8a6997 --- /dev/null +++ b/graphics/traveler/src/trv_nxbkgd.c @@ -0,0 +1,175 @@ +/**************************************************************************** + * 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" + +#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 */ + + gvdbg("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); + gvdbg("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) +{ + printf("trv_nxmousein: hwnd=%p pos=(%d,%d) button=%02x\n", + hwnd, pos->x, pos->y, buttons); +} +#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) +{ + gvdbg("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 */ From 00d4becbadc12d4410b6ec930e50e13cd24bcc22 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 1 Dec 2014 16:18:43 -0600 Subject: [PATCH 07/11] Making a place for color transformations --- graphics/traveler/include/trv_color.h | 3 ++- graphics/traveler/src/trv_graphics.c | 7 +------ graphics/traveler/src/trv_main.c | 4 ++++ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/graphics/traveler/include/trv_color.h b/graphics/traveler/include/trv_color.h index 0a2cf78bb..8252b6b9b 100644 --- a/graphics/traveler/include/trv_color.h +++ b/graphics/traveler/include/trv_color.h @@ -70,7 +70,8 @@ struct trv_color_lum_s * Public Function Prototypes ****************************************************************************/ -bool trv_color_allocate(FAR struct trv_palette_s *pinfo); +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); diff --git a/graphics/traveler/src/trv_graphics.c b/graphics/traveler/src/trv_graphics.c index 6742147aa..405c90422 100755 --- a/graphics/traveler/src/trv_graphics.c +++ b/graphics/traveler/src/trv_graphics.c @@ -459,12 +459,7 @@ int trv_graphics_initialize(FAR struct trv_graphics_info_s *ginfo) /* Allocate color mapping information */ - ret = trv_color_allocate(&ginfo->palette); - if (ret < 0) - { - trv_abort("ERROR trv_color_allocate failed: %d"); - } - + trv_color_allocate(&ginfo->palette); trv_vdebug("%d colors allocated\n", ginfo->palette.ncolors); return OK; } diff --git a/graphics/traveler/src/trv_main.c b/graphics/traveler/src/trv_main.c index fc9de19f6..7bd02458c 100755 --- a/graphics/traveler/src/trv_main.c +++ b/graphics/traveler/src/trv_main.c @@ -222,6 +222,10 @@ int traveler_main(int argc, char *argv[]) world_filename, ret); } + /* Release color mapping tables */ + + trv_color_endmapping(); + /* Set the player's POV in the new world */ trv_pov_reset(); From 158cfc8a52596e6310888990736250097ac92b69 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 1 Dec 2014 17:06:27 -0600 Subject: [PATCH 08/11] Add color initilization logi --- graphics/traveler/Makefile | 2 +- graphics/traveler/include/trv_color.h | 38 ++ graphics/traveler/src/trv_color.c | 673 ++++++++++++++++++++++++++ graphics/traveler/src/trv_graphics.c | 1 - graphics/traveler/src/trv_main.c | 1 + 5 files changed, 713 insertions(+), 2 deletions(-) create mode 100755 graphics/traveler/src/trv_color.c diff --git a/graphics/traveler/Makefile b/graphics/traveler/Makefile index e04bf51c3..c1e115986 100644 --- a/graphics/traveler/Makefile +++ b/graphics/traveler/Makefile @@ -46,7 +46,7 @@ STACKSIZE = 2048 # Hello, World! Example ASRCS = -CSRCS = trv_mem.c trv_graphics.c +CSRCS = trv_color.c trv_graphics.c trv_mem.c MAINSRC = trv_main.c ifeq ($(CONFIG_NX),y) diff --git a/graphics/traveler/include/trv_color.h b/graphics/traveler/include/trv_color.h index 8252b6b9b..9e8f8abb1 100644 --- a/graphics/traveler/include/trv_color.h +++ b/graphics/traveler/include/trv_color.h @@ -47,6 +47,44 @@ * 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 ****************************************************************************/ diff --git a/graphics/traveler/src/trv_color.c b/graphics/traveler/src/trv_color.c new file mode 100755 index 000000000..f7b9b68f1 --- /dev/null +++ b/graphics/traveler/src/trv_color.c @@ -0,0 +1,673 @@ +/******************************************************************************* + * 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_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 index 405c90422..02d9b61b9 100755 --- a/graphics/traveler/src/trv_graphics.c +++ b/graphics/traveler/src/trv_graphics.c @@ -386,7 +386,6 @@ int trv_graphics_initialize(FAR struct trv_graphics_info_s *ginfo) int swwidth; int swheight; int scale; - int ret; /* Initialize the graphics device and get information about the display */ diff --git a/graphics/traveler/src/trv_main.c b/graphics/traveler/src/trv_main.c index 7bd02458c..95c26eaf6 100755 --- a/graphics/traveler/src/trv_main.c +++ b/graphics/traveler/src/trv_main.c @@ -52,6 +52,7 @@ #include "trv_rayrend.h" #include "trv_input.h" #include "trv_graphics.h" +#include "trv_color.h" #include "trv_debug.h" #include "trv_main.h" From 976a0aff44cf118145f13473f7c6e310fc06bd19 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 1 Dec 2014 19:15:16 -0600 Subject: [PATCH 09/11] Add framework for joystick input --- graphics/traveler/Makefile | 2 +- graphics/traveler/include/trv_input.h | 43 ++++++++++ graphics/traveler/src/trv_color.c | 2 +- graphics/traveler/src/trv_graphics.c | 0 graphics/traveler/src/trv_input.c | 110 ++++++++++++++++++++++++++ graphics/traveler/src/trv_main.c | 2 +- graphics/traveler/src/trv_mem.c | 0 7 files changed, 156 insertions(+), 3 deletions(-) mode change 100755 => 100644 graphics/traveler/src/trv_color.c mode change 100755 => 100644 graphics/traveler/src/trv_graphics.c create mode 100644 graphics/traveler/src/trv_input.c mode change 100755 => 100644 graphics/traveler/src/trv_main.c mode change 100755 => 100644 graphics/traveler/src/trv_mem.c diff --git a/graphics/traveler/Makefile b/graphics/traveler/Makefile index c1e115986..71dbabeaf 100644 --- a/graphics/traveler/Makefile +++ b/graphics/traveler/Makefile @@ -46,7 +46,7 @@ STACKSIZE = 2048 # Hello, World! Example ASRCS = -CSRCS = trv_color.c trv_graphics.c trv_mem.c +CSRCS = trv_color.c trv_graphics.c trv_input.c trv_mem.c MAINSRC = trv_main.c ifeq ($(CONFIG_NX),y) diff --git a/graphics/traveler/include/trv_input.h b/graphics/traveler/include/trv_input.h index b4b4cf442..beb3b20a4 100644 --- a/graphics/traveler/include/trv_input.h +++ b/graphics/traveler/include/trv_input.h @@ -42,6 +42,49 @@ #include "trv_types.h" +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ +/* INPUT */ + +enum trv_move_event_e +{ + INPUT_MOVE_NONE = 0, + INPUT_MOVE_FORWARD, + INPUT_MOVE_BACKWARD, + INPUT_MOVE_LEFT, + INPUT_MOVE_RIGHT +}; + +enum trv_turn_event_e +{ + INPUT_TURN_NONE = 0, + INPUT_TURN_UP, + INPUT_TURN_DOWN, + INPUT_TURN_LEFT, + INPUT_TURN_RIGHT, +}; + +enum trv_door_event_e +{ + INPUT_DOOR_NONE = 0, + INPUT_DOOR_OPEN, +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +extern enum trv_move_event_e g_move_event; +extern enum trv_turn_event_e g_turn_event; +extern enum trv_door_event_e g_door_event; +extern trv_coord_t g_trv_move_rate; +extern trv_coord_t g_trv_turn_rate; + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ diff --git a/graphics/traveler/src/trv_color.c b/graphics/traveler/src/trv_color.c old mode 100755 new mode 100644 index f7b9b68f1..8760165a3 --- a/graphics/traveler/src/trv_color.c +++ b/graphics/traveler/src/trv_color.c @@ -1,5 +1,5 @@ /******************************************************************************* - * apps/graphics/traveler/src/trv_graphics.c + * apps/graphics/traveler/src/trv_color.c * * Copyright (C) 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt diff --git a/graphics/traveler/src/trv_graphics.c b/graphics/traveler/src/trv_graphics.c old mode 100755 new mode 100644 diff --git a/graphics/traveler/src/trv_input.c b/graphics/traveler/src/trv_input.c new file mode 100644 index 000000000..1bc9cbd38 --- /dev/null +++ b/graphics/traveler/src/trv_input.c @@ -0,0 +1,110 @@ +/**************************************************************************** + * 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_input.h" + +/**************************************************************************** + * Public Data + *************************************************************************/ + +extern enum trv_move_event_e g_move_event; +extern enum trv_turn_event_e g_turn_event; +extern enum trv_door_event_e g_door_event; +extern trv_coord_t g_trv_move_rate; +extern trv_coord_t g_trv_turn_rate; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + *************************************************************************/ + +static const char g_default_worldfile[] = "transfrm.wld"; +static FAR struct trv_graphics_info_s g_trv_ginfo; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: trv_input_initialize + * + * Description: + * Initialize the selected input device + * + ****************************************************************************/ + +void trv_input_initialize(void) +{ +#warning Missing Logic +} + +/**************************************************************************** + * Name: trv_input_read + * + * Description: + * Read the next input froom the input device + * + ****************************************************************************/ + +void trv_input_read(void) +{ +#warning Missing Logic +} + +/**************************************************************************** + * Name: trv_input_terminate + * + * Description: + * Terminate input and free resources + * + ****************************************************************************/ + +void trv_input_terminate(void) +{ +#warning Missing Logic +} diff --git a/graphics/traveler/src/trv_main.c b/graphics/traveler/src/trv_main.c old mode 100755 new mode 100644 index 95c26eaf6..594513a9a --- a/graphics/traveler/src/trv_main.c +++ b/graphics/traveler/src/trv_main.c @@ -1,5 +1,5 @@ /**************************************************************************** - * apps/graphics/traveler/trv_debug.h + * 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. diff --git a/graphics/traveler/src/trv_mem.c b/graphics/traveler/src/trv_mem.c old mode 100755 new mode 100644 From a5b0bee8428dbbb5badf7b80a8faac2444d7616e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 2 Dec 2014 07:34:51 -0600 Subject: [PATCH 10/11] Rethink positional input; Add input configuration logic --- graphics/traveler/Kconfig | 32 +++++ graphics/traveler/include/trv_input.h | 45 +++---- graphics/traveler/src/trv_input.c | 161 ++++++++++++++++++++++++-- graphics/traveler/src/trv_nxbkgd.c | 15 ++- 4 files changed, 208 insertions(+), 45 deletions(-) diff --git a/graphics/traveler/Kconfig b/graphics/traveler/Kconfig index 851ab4ca7..47dd09c1b 100644 --- a/graphics/traveler/Kconfig +++ b/graphics/traveler/Kconfig @@ -17,6 +17,38 @@ config GRAPHICS_TRAVELER_RGB32_888 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 diff --git a/graphics/traveler/include/trv_input.h b/graphics/traveler/include/trv_input.h index beb3b20a4..1c2e7e724 100644 --- a/graphics/traveler/include/trv_input.h +++ b/graphics/traveler/include/trv_input.h @@ -46,44 +46,26 @@ * Pre-processor Definitions ****************************************************************************/ +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 */ + bool dooropen; /* True: Open a door */ +}; + /**************************************************************************** * Public Types ****************************************************************************/ -/* INPUT */ - -enum trv_move_event_e -{ - INPUT_MOVE_NONE = 0, - INPUT_MOVE_FORWARD, - INPUT_MOVE_BACKWARD, - INPUT_MOVE_LEFT, - INPUT_MOVE_RIGHT -}; - -enum trv_turn_event_e -{ - INPUT_TURN_NONE = 0, - INPUT_TURN_UP, - INPUT_TURN_DOWN, - INPUT_TURN_LEFT, - INPUT_TURN_RIGHT, -}; - -enum trv_door_event_e -{ - INPUT_DOOR_NONE = 0, - INPUT_DOOR_OPEN, -}; /**************************************************************************** * Public Data ****************************************************************************/ -extern enum trv_move_event_e g_move_event; -extern enum trv_turn_event_e g_turn_event; -extern enum trv_door_event_e g_door_event; -extern trv_coord_t g_trv_move_rate; -extern trv_coord_t g_trv_turn_rate; +/* Report positional inputs */ + +extern struct trv_input_s g_trv_input; /**************************************************************************** * Public Function Prototypes @@ -92,5 +74,8 @@ extern trv_coord_t g_trv_turn_rate; 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/src/trv_input.c b/graphics/traveler/src/trv_input.c index 1bc9cbd38..ba8d987e7 100644 --- a/graphics/traveler/src/trv_input.c +++ b/graphics/traveler/src/trv_input.c @@ -41,31 +41,85 @@ #include "trv_types.h" #include "trv_input.h" +#if defined(CONFIG_GRAPHICS_TRAVELER_JOYSTICK) +# include +# include + +#if defined(CONFIG_GRAPHICS_TRAVELER_AJOYSTICK) +# 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 */ + int16_t maxleft; /* Maximum left X position */ + int16_t maxright; /* Maximum right x position */ + int16_t centery; /* Center Y position */ + int16_t maxforward; /* Maximum forward Y position */ + int16_t maxback; /* Maximum backward Y position */ +#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 *************************************************************************/ -extern enum trv_move_event_e g_move_event; -extern enum trv_turn_event_e g_turn_event; -extern enum trv_door_event_e g_door_event; -extern trv_coord_t g_trv_move_rate; -extern trv_coord_t g_trv_turn_rate; +/* 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 *************************************************************************/ -static const char g_default_worldfile[] = "transfrm.wld"; -static FAR struct trv_graphics_info_s g_trv_ginfo; - /**************************************************************************** * 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 ****************************************************************************/ @@ -80,20 +134,82 @@ static FAR struct trv_graphics_info_s g_trv_ginfo; void trv_input_initialize(void) { -#warning Missing Logic +#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 froom the input device + * Read the next input from the input device * ****************************************************************************/ void trv_input_read(void) { -#warning Missing Logic +#if defined(CONFIG_GRAPHICS_TRAVELER_JOYSTICK) +#if defined(CONFIG_GRAPHICS_TRAVELER_AJOYSTICK) + struct ajoy_sample_s sample; + 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_sample_s sample; + ssize_t nread; + + /* Read data from the discrete joystick */ + + nread = read(g_trv_input_info.fd, &sample, sizeof(struct djoy_sample_s)); + if (nread < 0) + { + trv_abort("ERROR: Joystick read error: %d\n", errno); + } + else if (nread != sizeof(struct djoy_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 + +#endif +#elif defined(CONFIG_GRAPHICS_TRAVELER_NX_XYINPUT) + /* Make position decision based on last sampled X/Y input data */ +#warning Missing logic +#endif } /**************************************************************************** @@ -106,5 +222,28 @@ void trv_input_read(void) 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_nxbkgd.c b/graphics/traveler/src/trv_nxbkgd.c index 4bd8a6997..08a54a834 100644 --- a/graphics/traveler/src/trv_nxbkgd.c +++ b/graphics/traveler/src/trv_nxbkgd.c @@ -38,6 +38,9 @@ ****************************************************************************/ #include "trv_types.h" +#ifdef CONFIG_GRAPHICS_TRAVELER_NX_XYINPUT +# include "trv_input.h" +#endif #include #include @@ -122,7 +125,7 @@ static void trv_nxposition(NXWINDOW hwnd, FAR const struct nxgl_size_s *size, /* Report the position */ - gvdbg("hwnd=%p size=(%d,%d) pos=(%d,%d) bounds={(%d,%d),(%d,%d)}\n", + 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); @@ -141,7 +144,7 @@ static void trv_nxposition(NXWINDOW hwnd, FAR const struct nxgl_size_s *size, g_trv_nxresolution = true; sem_post(&g_trv_nxevent); - gvdbg("Have width=%d height=%d\n", ginfo->width, ginfo->height); + trv_vdebug("Have width=%d height=%d\n", ginfo->width, ginfo->height); } } @@ -153,8 +156,12 @@ static void trv_nxposition(NXWINDOW hwnd, FAR const struct nxgl_size_s *size, static void trv_nxmousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos, uint8_t buttons, FAR void *arg) { - printf("trv_nxmousein: hwnd=%p pos=(%d,%d) button=%02x\n", + 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 @@ -166,7 +173,7 @@ static void trv_nxmousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos, static void trv_nxkbdin(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch, FAR void *arg) { - gvdbg("hwnd=%p nch=%d\n", hwnd, nch); + trv_vdebug("hwnd=%p nch=%d\n", hwnd, nch); } #endif From 35ee2e422538c4be2992f592b593de57e6689589 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 2 Dec 2014 10:13:08 -0600 Subject: [PATCH 11/11] A more more input positional logic --- graphics/traveler/include/trv_input.h | 13 ++- graphics/traveler/include/trv_trigtbl.h | 75 ++++++++++++++ graphics/traveler/include/trv_world.h | 21 ++++ graphics/traveler/src/trv_input.c | 129 ++++++++++++++++++++++-- 4 files changed, 225 insertions(+), 13 deletions(-) create mode 100644 graphics/traveler/include/trv_trigtbl.h diff --git a/graphics/traveler/include/trv_input.h b/graphics/traveler/include/trv_input.h index 1c2e7e724..9650089cf 100644 --- a/graphics/traveler/include/trv_input.h +++ b/graphics/traveler/include/trv_input.h @@ -46,19 +46,24 @@ * 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 Types - ****************************************************************************/ - /**************************************************************************** * Public Data ****************************************************************************/ 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_world.h b/graphics/traveler/include/trv_world.h index 939ec1820..3461fd792 100644 --- a/graphics/traveler/include/trv_world.h +++ b/graphics/traveler/include/trv_world.h @@ -59,6 +59,27 @@ struct trv_camera_s 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 ****************************************************************************/ diff --git a/graphics/traveler/src/trv_input.c b/graphics/traveler/src/trv_input.c index ba8d987e7..ea100de5c 100644 --- a/graphics/traveler/src/trv_input.c +++ b/graphics/traveler/src/trv_input.c @@ -39,6 +39,8 @@ ****************************************************************************/ #include "trv_types.h" +#include "trv_world.h" +#include "trv_trigtbl.h" #include "trv_input.h" #if defined(CONFIG_GRAPHICS_TRAVELER_JOYSTICK) @@ -46,6 +48,7 @@ # include #if defined(CONFIG_GRAPHICS_TRAVELER_AJOYSTICK) +# include # include #elif defined(CONFIG_GRAPHICS_TRAVELER_DJOYSTICK) # include @@ -68,11 +71,11 @@ struct trv_input_info_s int fd; /* Open driver descriptor */ #ifdef CONFIG_GRAPHICS_TRAVELER_AJOYSTICK int16_t centerx; /* Center X position */ - int16_t maxleft; /* Maximum left X position */ - int16_t maxright; /* Maximum right x position */ + b16_t leftslope; /* Slope for left of center */ + b16_t rightslope; /* Slope for left of center */ int16_t centery; /* Center Y position */ - int16_t maxforward; /* Maximum forward Y position */ - int16_t maxback; /* Maximum backward 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 */ @@ -169,6 +172,8 @@ 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 */ @@ -187,25 +192,131 @@ void trv_input_read(void) #warning Missing logic #elif defined(CONFIG_GRAPHICS_TRAVELER_DJOYSTICK) - struct djoy_sample_s sample; + struct djoy_buttonset_t buttonset; ssize_t nread; /* Read data from the discrete joystick */ - nread = read(g_trv_input_info.fd, &sample, sizeof(struct djoy_sample_s)); + 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_sample_s)) + 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 */ -#warning Missing logic -#endif + 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