diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-11-30 13:43:42 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-11-30 13:43:42 -0600 |
commit | 8846c4e02a25bfa686bb51eef94f03ae0b3a3b42 (patch) | |
tree | be0f5bb5fae97a8961f6c424314bf68edc09a8c0 /apps/graphics | |
parent | d4520b0475b3ba172a89279af2932d1fd15dc08e (diff) | |
download | nuttx-8846c4e02a25bfa686bb51eef94f03ae0b3a3b42.tar.gz nuttx-8846c4e02a25bfa686bb51eef94f03ae0b3a3b42.tar.bz2 nuttx-8846c4e02a25bfa686bb51eef94f03ae0b3a3b42.zip |
Add traveller main file and stubs for required headers
Diffstat (limited to 'apps/graphics')
-rw-r--r-- | apps/graphics/Kconfig | 18 | ||||
-rw-r--r-- | apps/graphics/Make.defs | 4 | ||||
-rw-r--r-- | apps/graphics/Makefile | 2 | ||||
-rw-r--r-- | apps/graphics/traveller/.gitignore | 11 | ||||
-rw-r--r-- | apps/graphics/traveller/Kconfig | 13 | ||||
-rw-r--r-- | apps/graphics/traveller/Makefile | 142 | ||||
-rw-r--r-- | apps/graphics/traveller/include/trv_bitmaps.h | 57 | ||||
-rw-r--r-- | apps/graphics/traveller/include/trv_color.h | 79 | ||||
-rw-r--r-- | apps/graphics/traveller/include/trv_debug.h | 2 | ||||
-rw-r--r-- | apps/graphics/traveller/include/trv_doors.h | 52 | ||||
-rw-r--r-- | apps/graphics/traveller/include/trv_graphics.h | 82 | ||||
-rw-r--r-- | apps/graphics/traveller/include/trv_input.h | 53 | ||||
-rw-r--r-- | apps/graphics/traveller/include/trv_main.h | 61 | ||||
-rw-r--r-- | apps/graphics/traveller/include/trv_pov.h | 61 | ||||
-rw-r--r-- | apps/graphics/traveller/include/trv_raycntl.h | 63 | ||||
-rw-r--r-- | apps/graphics/traveller/include/trv_rayrend.h | 60 | ||||
-rw-r--r-- | apps/graphics/traveller/include/trv_types.h | 7 | ||||
-rw-r--r-- | apps/graphics/traveller/include/trv_world.h | 69 | ||||
-rwxr-xr-x | apps/graphics/traveller/src/trv_main.c | 312 |
19 files changed, 1134 insertions, 14 deletions
diff --git a/apps/graphics/Kconfig b/apps/graphics/Kconfig index a10650e27..55002bcc1 100644 --- a/apps/graphics/Kconfig +++ b/apps/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/apps/graphics/Make.defs b/apps/graphics/Make.defs index 8f940cbad..3376e941a 100644 --- a/apps/graphics/Make.defs +++ b/apps/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/apps/graphics/Makefile b/apps/graphics/Makefile index 7503c4343..551e21472 100644 --- a/apps/graphics/Makefile +++ b/apps/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/apps/graphics/traveller/.gitignore b/apps/graphics/traveller/.gitignore new file mode 100644 index 000000000..83bd7b811 --- /dev/null +++ b/apps/graphics/traveller/.gitignore @@ -0,0 +1,11 @@ +/Make.dep +/.depend +/.built +/*.asm +/*.rel +/*.lst +/*.sym +/*.adb +/*.lib +/*.src +/*.obj diff --git a/apps/graphics/traveller/Kconfig b/apps/graphics/traveller/Kconfig index 0906ebab9..3feee99bb 100644 --- a/apps/graphics/traveller/Kconfig +++ b/apps/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/apps/graphics/traveller/Makefile b/apps/graphics/traveller/Makefile new file mode 100644 index 000000000..7a11a7b21 --- /dev/null +++ b/apps/graphics/traveller/Makefile @@ -0,0 +1,142 @@ +############################################################################ +# apps/graphics/traveller/Makefile +# +# Copyright (C) 2014 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt <gnutt@nuttx.org> +# +# 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/apps/graphics/traveller/include/trv_bitmaps.h b/apps/graphics/traveller/include/trv_bitmaps.h new file mode 100644 index 000000000..43e6c84ea --- /dev/null +++ b/apps/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 <gnutt@nuttx.org> + * + * 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/apps/graphics/traveller/include/trv_color.h b/apps/graphics/traveller/include/trv_color.h new file mode 100644 index 000000000..3f11b4148 --- /dev/null +++ b/apps/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 <gnutt@nuttx.org> + * + * 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/apps/graphics/traveller/include/trv_debug.h b/apps/graphics/traveller/include/trv_debug.h index 33632df5f..e0912f4fe 100644 --- a/apps/graphics/traveller/include/trv_debug.h +++ b/apps/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 <gnutt@nuttx.org> diff --git a/apps/graphics/traveller/include/trv_doors.h b/apps/graphics/traveller/include/trv_doors.h new file mode 100644 index 000000000..44ab7e18c --- /dev/null +++ b/apps/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 <gnutt@nuttx.org> + * + * 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/apps/graphics/traveller/include/trv_graphics.h b/apps/graphics/traveller/include/trv_graphics.h new file mode 100644 index 000000000..d63557b1b --- /dev/null +++ b/apps/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 <gnutt@nuttx.org> + * + * 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/apps/graphics/traveller/include/trv_input.h b/apps/graphics/traveller/include/trv_input.h new file mode 100644 index 000000000..beeeb8179 --- /dev/null +++ b/apps/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 <gnutt@nuttx.org> + * + * 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/apps/graphics/traveller/include/trv_main.h b/apps/graphics/traveller/include/trv_main.h new file mode 100644 index 000000000..9d53c3ad5 --- /dev/null +++ b/apps/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 <gnutt@nuttx.org> + * + * 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/apps/graphics/traveller/include/trv_pov.h b/apps/graphics/traveller/include/trv_pov.h new file mode 100644 index 000000000..986480e11 --- /dev/null +++ b/apps/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 <gnutt@nuttx.org> + * + * 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/apps/graphics/traveller/include/trv_raycntl.h b/apps/graphics/traveller/include/trv_raycntl.h new file mode 100644 index 000000000..a843cd2c8 --- /dev/null +++ b/apps/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 <gnutt@nuttx.org> + * + * 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/apps/graphics/traveller/include/trv_rayrend.h b/apps/graphics/traveller/include/trv_rayrend.h new file mode 100644 index 000000000..3773a977c --- /dev/null +++ b/apps/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 <gnutt@nuttx.org> + * + * 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/apps/graphics/traveller/include/trv_types.h b/apps/graphics/traveller/include/trv_types.h index b7371b758..83ee29dd4 100644 --- a/apps/graphics/traveller/include/trv_types.h +++ b/apps/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 <gnutt@nuttx.org> @@ -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/apps/graphics/traveller/include/trv_world.h b/apps/graphics/traveller/include/trv_world.h new file mode 100644 index 000000000..5e06fc9a7 --- /dev/null +++ b/apps/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 <gnutt@nuttx.org> + * + * 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/apps/graphics/traveller/src/trv_main.c b/apps/graphics/traveller/src/trv_main.c new file mode 100755 index 000000000..6e4339f84 --- /dev/null +++ b/apps/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 <gnutt@nuttx.org> + * + * 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 <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include <math.h> + +#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 <sys/types.h> +# include <sys/time.h> +# include <unistd.h> +#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<path>] [world]\n", execname); + fprintf(stderr, "Where:\n"); + fprintf(stderr, " -b Selects 640x400 window (default is 320x200)\n"); + fprintf(stderr, " -p<path> 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); +} |