Commits

Anonymous committed 3598f0d

Implemented Dingoo (Native) support. Dingux should build too. Fixed problem with audio on Linux desktop that I introduced when added 320x240 mode (my laptop has no audio hence missing it).

Dingoo controls:

Select : quit
Y : Fire

Currently getting ~90fps (with music playing).

Comments (0)

Files changed (5)

 	printf("Budu nahravat obrazek %s\n", path);
 #endif /* DEBUG */
 	sprintf(local_path, "%s%s", GFXPATH, path);
+#ifdef DINGOO_NATIVE
+	char_replace(local_path, '/', DIRSEP_CHAR);
+#endif /* DINGOO_NATIVE */
 	image_bmp = SDL_LoadBMP(local_path);
 	if (image_bmp == NULL) {
 		CSystem::problemSDL(__FILE__, __LINE__, __FUNCTION__);
 #include <stdlib.h>
 #include <time.h>
 
+#ifdef DINGOO_NATIVE
+void debug_printf(char *fmt, ...);
+#define printf debug_printf
+
+char *char_replace(char *s, char c, char r)
+{
+    char *t;
+
+    for (t=s; *t; t++)
+    {
+        if (*t == c)
+        {
+            *t = r;
+        }
+    }
+
+    return s;
+}
+
+#endif /* DINGOO_NATIVE */
+
 // staticky prvek, spusti se konstructor CSRand()
 CSRand CSystem::initRandom = CSRand();
 
 void
 CSystem::problemSDL(const char* filename, int linenum, const char* functionname) 
 {
+#ifdef DINGOO_NATIVE
+	debug_printf("Problem: %s\n", SDL_GetError());
+	debug_printf("%s:%d function %s()\n", filename, linenum, functionname);
+#else /* DINGOO_NATIVE */
 	fprintf(stderr, "Problem: %s\n", SDL_GetError());
-    /*
-	fprintf(stderr, "%s:%d function %s()\n", __FILE__, __LINE__, __FUNCTION__);
-    */
 	fprintf(stderr, "%s:%d function %s()\n", filename, linenum, functionname);
+#endif /* DINGOO_NATIVE */
 
 	exit(1);
 }
 void
 CSystem::echo(const char *text) 
 {
+#ifdef DINGOO_NATIVE
+	debug_printf("%s\n", text);
+#else /* DINGOO_NATIVE */
 	fprintf(stderr, "%s\n", text);
+#endif /* DINGOO_NATIVE */
 }
 	
 
 	printf("Budu nahravat obrazek %s\n", path);
 #endif /* DEBUG */
 	sprintf(local_path, "%s%s", GFXPATH, path);
+#ifdef DINGOO_NATIVE
+	char_replace(local_path, '/', DIRSEP_CHAR);
+#endif /* DINGOO_NATIVE */
+#ifdef DEBUG
+	printf("\tBudu nahravat obrazek %s\n", local_path);
+#endif /* DEBUG */
 
 	image_bmp = SDL_LoadBMP(local_path);
 	if (image_bmp == NULL) {
 	return surface;	
 }
 
+
 /* 
 * nacteni zvuku
  */
 CSystem::loadWav(const char *path) 
 {
 	Mix_Chunk *wav;
+	char local_path[MYMAXPATH];
 
 #ifdef DEBUG
 	printf("Budu nahravat wav %s\n", path);
 #endif /* DEBUG */
-	wav = Mix_LoadWAV(path);
+	sprintf(local_path, "%s%s", GFXPATH, path);
+#ifdef DINGOO_NATIVE
+	char_replace(local_path, '/', DIRSEP_CHAR);
+#endif /* DINGOO_NATIVE */
+#ifdef DEBUG
+	printf("\tBudu nahravat wav %s\n", local_path);
+#endif /* DEBUG */
+
+	wav = Mix_LoadWAV(local_path);
 #ifndef SHIPS_IGNORE_SOUND_FAILURE
 	if (wav == NULL) {
 		CSystem::problemSDL(__FILE__, __LINE__, __FUNCTION__);
 #include "SDL/SDL.h"
 #include "SDL/SDL_mixer.h"
 
+#ifdef DINGOO_NATIVE
+    #define DIRSEP "\\"
+    char *char_replace(char *s, char c, char r);
+#else /* DINGOO_NATIVE */
+    #define DIRSEP "/"
+#endif /* DINGOO_NATIVE */
+#define DIRSEP_CHAR DIRSEP[0]
+
 /*
-#define DIRSEP "\\"
 #define GFXDIR "gfx640x480"
 #define GFXDIR "gfx320x240"
 */
-#define DIRSEP "/"
 /*
 #define GFXDIR "gfx" #SCREEN_WIDTH "x" #SCREEN_HEIGHT
 */

Makefile.dingoo_native

 
 STD_OPTS  = -G0 -O3 $(INCLUDE) -Wall -Wextra -finline-functions -fomit-frame-pointer -msoft-float -fno-builtin -fno-exceptions -mips32 -mno-abicalls -fno-pic -DMPU_JZ4740 -DNDEBUG -D_DINGOO
 CPP_OPTS  = -c $(STD_OPTS) -fno-rtti -fno-threadsafe-statics
+#CPP_OPTS += -DDEBUG=1
+CPP_OPTS += -DDINGOO_NATIVE=1
 CPP_OPTS += -DMYMAXPATH=255
 CPP_OPTS += -DSCREEN_WIDTH=320 -DSCREEN_HEIGHT=240 # -DGFXDIR=gfx320x240
 
  */
 // sturctura: mDown, mUp, mLeft, mRight;
 COvladani_move sipky_player1 = {SDLK_DOWN, SDLK_UP, SDLK_LEFT, SDLK_RIGHT};
-COvladani_fire strelba_player1 = {SDLK_RSHIFT};
+COvladani_fire strelba_player1 = {
+#ifdef DINGOO_NATIVE
+    SDLK_LSHIFT 
+#else /* DINGOO_NATIVE */
+    SDLK_RSHIFT
+#endif /* DINGOO_NATIVE */
+    };
 // druhy hrac
 COvladani_move sipky_player2 = {SDLK_s, SDLK_w, SDLK_a, SDLK_d};
-COvladani_fire strelba_player2 = {SDLK_LSHIFT};
+COvladani_fire strelba_player2 = {
+#ifdef DINGOO_NATIVE
+    SDLK_SPACE
+#else /* DINGOO_NATIVE */
+    SDLK_LSHIFT
+#endif /* DINGOO_NATIVE */
+    };
 // zda se muze pripojit druhy hrac
 bool play2Volno = true;
 
 
+/****************************************************************/
+#ifdef DINGOO_NATIVE
+void debug_printf_init()
+{
+	char tmp_buf[1024];
+	int mesg_len=0;
+	FILE *fptr=NULL;
+
+	fptr = fopen("stdout.txt", "w");
+	if (fptr != NULL)
+	{
+		mesg_len = sprintf(tmp_buf, "stdout for ships\n");
+		fwrite(tmp_buf, mesg_len, 1, fptr);
+		fclose(fptr);
+	}
+	/* else nothing we can do except maybe print to screen */
+}
+
+void debug_printf(char *fmt, ...)
+{
+	va_list ap;
+	char tmp_buf[1024];
+	int mesg_len=0;
+	FILE *fptr=NULL;
+
+	va_start(ap, fmt);
+	fptr = fopen("stdout.txt", "a");
+	if (fptr != NULL)
+	{
+		mesg_len = vsnprintf(tmp_buf, sizeof(tmp_buf)-1, fmt, ap);
+		fwrite(tmp_buf, mesg_len, 1, fptr);
+		fclose(fptr);
+	}
+	/* else nothing we can do except maybe print to screen */
+	va_end(ap);
+}
+#define printf debug_printf
+#endif /* DINGOO_NATIVE */
+/****************************************************************/
 
 
 /*
 		default:
 			assert("blba musika" == NULL);
 	}
+#ifdef DEBUG
+	if (music == NULL)
+		printf("music == NULL\n");
+#endif /* DEBUG */
 	// 0 ... znaci bez opakovani
 	Mix_PlayMusic(music, 0);
+#ifdef DEBUG
+	printf("Mix_PlayMusic()\n");
+#endif /* DEBUG */
 	Mix_HookMusicFinished(musicDone);
+#ifdef DEBUG
+	printf("Mix_HookMusicFinished()\n");
+#endif /* DEBUG */
 }
 
 
 	int 
 main() 
 {
+#ifdef DINGOO_NATIVE
+    debug_printf_init();
+#endif /* DINGOO_NATIVE */
+
 	// inicializace SDL a video modu
 	videoInit();
 	// inicializace Audia a spusteni skladby