Commits

p2 committed 3a73531

Implemented Clock

  • Participants
  • Parent commits c5294d6

Comments (0)

Files changed (3)

Classes/MatrixCodeAppDelegate.m

 		setBoolProperty("do_fog", (int)fog);
 	}
 	
-//	BOOL clock = [d boolForKey:settingKeyClock];
-//	if (clock != DEF_CLOCK) {
-//		setBoolProperty("do_clock", (int)clock);
-//	}
+	BOOL clock = [d boolForKey:settingKeyClock];
+	if (clock != DEF_CLOCK) {
+		setBoolProperty("do_clock", (int)clock);
+	}
 	
 	NSString *mode = [d objectForKey:settingKeyMode];
 	setCharProperty("mode", (char *)[mode UTF8String]);

Classes/glmatrix.h

 #define DEF_ROTATE      YES
 #define DEF_TEXTURE     YES
 #define DEF_MODE        "Matrix"
-#define DEF_TIMEFMT     " %l:%M %p "
+#define DEF_TIMEFMT     "%l:%M %p"
 
 
 void init_settings();

Classes/glmatrix.m

 	strip *strips;
 	const int *glyph_map;
 	int nglyphs;
-	GLfloat tex_char_width, tex_char_height;
 	
 	/* tracking direction of view */
 	Quaternion targetRotation;						/* where to rotate to compared to the null axis */
 static void reset_strip(strip *s)
 {
 	int i;
-	GLboolean time_displayed_p = NO;				/* never display time twice in one strip */
+	GLboolean time_displayed_p = YES;				// Set to NO to enable drawing time in strips - disabled here as we have separate time drawing
 	
 	memset(s, 0, sizeof(*s));
 	s->x = (GLfloat) (randf(GRID_SIZE) - (GRID_SIZE / 2));
 			strftime(text, sizeof(text)-1, timefmt, tm);
 			//printf("Time: %s\n", text);
 			/* render time into the strip */
-			for (j = 0; j < strlen(text) && i < GRID_SIZE; j++, i++)
-			{
+			for (j = 0; j < strlen(text) && i < GRID_SIZE; j++, i++) {
 				s->glyphs[i] = char_map[((unsigned char *) text)[j]];
-				//printf("Glyph -> %i (%i)\n", s->glyphs[i], ((unsigned char *) text)[j]);
+				//printf("TIME Glyph -> %i (%i)\n", s->glyphs[i], ((unsigned char *) text)[j]);
 				s->highlight[i] = YES;
 			}
 			
 
 // Draw a single character at the given position and brightness.
 static void	draw_glyph(int glyph, GLboolean highlight,
-					   GLfloat x, GLfloat y, GLfloat z, GLfloat w, GLfloat h,
-					   GLfloat brightness)
+					   GLfloat x, GLfloat y, GLfloat z,
+					   GLfloat brightness, GLfloat scale)
 {
-	GLfloat cx = 0, cy = 0;
-	GLfloat S = 1;
+	if (glyph == 0) {
+		return;
+	}
+	glyph -= 1;
+	
+	GLfloat cx = 0.f, cy = 0.f;
+	GLfloat S = 1.f * scale;
 	GLboolean is_spinner = (glyph < 0);
 	
-	if (glyph == 0) {
-		abort();
-	}
-	
 	if (is_spinner) {
 		glyph = -glyph;
 		brightness *= 1.5f;
 	}
 	
-	// assign x, y and width
+	// assign x and y on texture to get the right char
+	GLfloat w = (1.f / CHAR_COLS);
+	GLfloat h = (1.f / CHAR_ROWS);
 	if (!do_texture) {
-		S  = 0.8f;
-		x += 0.1f;
-		y += 0.1f;
+		S  = 0.8f * scale;
+		x += 0.1f * scale;
+		y += 0.1f * scale;
     }
 	else {
-		int ccx = ((glyph - 1) % CHAR_COLS);
-		int ccy = ((glyph - 1) / CHAR_COLS);
+		int ccx = (glyph % CHAR_COLS);
+		int ccy = (glyph / CHAR_COLS);
 		
 		cx = ccx * w;
 		cy = (CHAR_ROWS - ccy - 1) * h;
 		i = (i < 0) ? 0 : ((i >= WAVE_SIZE) ? WAVE_SIZE - 1 : i);
 		
 		a = m_config->brightness_ramp[i];
-#if 1
+#if 0
+		// The following issue does not occur on iOS, so we may hide it from the compiler:
+		
 		/* I don't understand this -- if I change the alpha on the color of
 		 the quad, I'd expect that to make the quad more transparent.
 		 But instead, it seems to be making the transparent parts of the
 	if (do_texture) {
 		GLfloat texcoord_data[] = {
 			cx,		cy,
-			cx+w,	cy,
-			cx,		cy+h,
-			cx+w,	cy+h
+			cx + w,	cy,
+			cx,		cy + h,
+			cx + w,	cy + h
 		};
 		glTexCoordPointer(2, GL_FLOAT, 0, texcoord_data);
 	}
 				brightness = m_config->brightness_ramp[j];
             }
 			
-			draw_glyph(g, s->highlight[i], s->x, s->y - i, s->z, m_config->tex_char_width, m_config->tex_char_height, brightness);
+			draw_glyph(g, s->highlight[i], s->x, s->y - i, s->z, brightness, 1.f);
         }
     }
 	
 	// draw the spinner
 	if (!s->erasing_p) {
-		draw_glyph(s->spinner_glyph, NO, s->x, s->y - s->spinner_y, s->z, m_config->tex_char_width, m_config->tex_char_height, 1.f);
+		draw_glyph(s->spinner_glyph, NO, s->x, (s->y - s->spinner_y), s->z, 1.f, 1.f);
 	}
 }
 
 	time_t now = time((time_t *) 0);
 	struct tm *tm = localtime(&now);
 	strftime(text, sizeof(text)-1, format, tm);
-	//printf("Time: %s\n", text);
 	
-	// Calculate width and height
-	GLfloat w = 0.8f * GRID_SIZE / strlen(text);
-	GLfloat h = m_config->tex_char_height / m_config->tex_char_width * w;
-	GLfloat x = GRID_SIZE - (GRID_SIZE / 2) * 0.8f;
-	GLfloat y = 0.25f;
+	// Calculate x and y
+	GLfloat scale = 2.25f;
+	GLfloat x = -scale * ((GLfloat)strlen(text) / 2);
+	GLfloat y = 0.5f;
+	//printf("Time: %s  (%lu chars)\n", text, strlen(text));
 	
 	// Render time string
 	int i;
 	for (i = 0; i < strlen(text); i++) {
-		int g = char_map[((unsigned char *) text)[i]];
-		//printf("Glyph -> %i (%i)\n", glyphs[i], ((unsigned char *) text)[i]);
-		if (g != 0) {
-			draw_glyph(g, YES, x + i * w, y, z, w, h, 1.f);
-		}
+		int g = char_map[((unsigned char *) text)[i]] + 1;
+		draw_glyph(g, YES, x + (i * scale), y, z, 1.f, scale);
 	}
 }
 
     }
 	
 	polygon_count = 0;
-	int drew_clock = !do_clock;
-	GLfloat clock_z = 0.f;
+	int did_draw_clock = !do_clock;
+	GLfloat clock_z = 2.f;				// TODO: Move closer or farther depending on timefmt?
 	
 	/* Render (and tick) each strip, starting at the back
      (draw the ones farthest from the camera first, to make
      the alpha transparency work out right.) */
-	if (1) {
-		strip **sorted = malloc(m_config->nstrips * sizeof(*sorted));
+#if 1
+	strip **sorted = malloc(m_config->nstrips * sizeof(*sorted));
+	
+	int i;
+	for (i = 0; i < m_config->nstrips; i++) {
+		sorted[i] = &m_config->strips[i];
+	}
+	qsort(sorted, i, sizeof(*sorted), cmp_strips);
+	
+	for (i = 0; i < m_config->nstrips; i++) {
+		strip *s = sorted[i];
+		tick_strip(s);
+		draw_strip(s);
 		
-		int i;
-		for (i = 0; i < m_config->nstrips; i++) {
-			sorted[i] = &m_config->strips[i];
+		// draw clock
+		if (!did_draw_clock && clock_z < s->z) {
+			draw_clock(timefmt, clock_z);
+			did_draw_clock = 1;
 		}
-		qsort(sorted, i, sizeof(*sorted), cmp_strips);
-		
-		for (i = 0; i < m_config->nstrips; i++) {
-			strip *s = sorted[i];
-			tick_strip(s);
-			draw_strip(s);
-			
-			// draw clock
-			if (!drew_clock && clock_z > s->z) {
-				draw_clock(timefmt, clock_z);
-				drew_clock = 1;
-			}
-		}
-		free(sorted);
 	}
+	free(sorted);
+#endif
 	
 	// rotation
 	auto_track();
 	// fps
 	double now = CACurrentMediaTime();
 	if (now - 2.0 > last_fps_take) {
-		last_fps = frame_count / 2;
+		last_fps = frame_count / (now - last_fps_take);
 		last_fps_take = now;
 		frame_count = 0;
 		//printf("fps: %i, polys: %i\n", last_fps, polygon_count);
 		m_config->track_duration = 0.08;				// seconds to animate between two quaternions
 		m_config->auto_track_duration = 8.0;			// 8 seconds to animate from one to another orientation
 		m_config->auto_track_timeout = 20;				// 20 seconds pause on current orientation
-		
-		// texture size per char
-		m_config->tex_char_width = 1.f / CHAR_COLS;
-		m_config->tex_char_height = 1.f / CHAR_ROWS;
 	}
 	
 	int i;