|
From: <sch...@us...> - 2008-11-22 01:17:19
|
Revision: 43
http://deraciel.svn.sourceforge.net/deraciel/?rev=43&view=rev
Author: schnippi001
Date: 2008-11-22 01:17:08 +0000 (Sat, 22 Nov 2008)
Log Message:
-----------
Rudimentary thread-based keyboard handler
Modified Paths:
--------------
trunk/INSTALL
trunk/main.c
trunk/random.c
trunk/random.h
trunk/text_window.c
Modified: trunk/INSTALL
===================================================================
--- trunk/INSTALL 2008-11-22 01:05:36 UTC (rev 42)
+++ trunk/INSTALL 2008-11-22 01:17:08 UTC (rev 43)
@@ -1,7 +1,7 @@
Compile
=======
-clear && gcc -std=c99 -o main *.c -lncurses -lform
+clear && gcc -std=c99 -o main *.c -lncurses -lform -lpthread
Run
Modified: trunk/main.c
===================================================================
--- trunk/main.c 2008-11-22 01:05:36 UTC (rev 42)
+++ trunk/main.c 2008-11-22 01:17:08 UTC (rev 43)
@@ -7,6 +7,7 @@
#include "text_window.h"
#include "random.h"
+#include "keyboard.h"
void finish(const int);
void repaint_windows(void);
@@ -38,57 +39,48 @@
text_window_create();
- // 1 Line output
- text_window_out("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmo");
+ /* Create keyboard handler */
+ keyreader_create();
- sleep(1);
-
- // 2 Line output
- text_window_out("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmoLorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmo");
-
- sleep(1);
-
- // 3 Line output
- text_window_out("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmoLorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmoLorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmo");
-
- sleep(1);
-
- // 1 Line output
- text_window_out("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmo");
-
-
int ch;
- while(ch != KEY_ESCAPE){
- ch = getch();
- if (ch == KEY_RESIZE) {
- endwin();
- curs_set(0); /* Hide the cursor */
-
- clear();
- refresh();
- text_window_resize();
- }
- }
+// while(ch != KEY_ESCAPE){
+// ch = getch();
+// if (ch == KEY_RESIZE) {
+// endwin();
+// curs_set(0); /* Hide the cursor */
+//
+// clear();
+// refresh();
+// text_window_resize();
+// }
+//
+// // 1 Line output
+// text_window_out("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmo");
+//
+// getch();
+//
+// // 2 Line output
+// text_window_out("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmoLorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmo");
+//
+// getch();
+//
+// // 3 Line output
+// text_window_out("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmoLorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmoLorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmo");
+//
+// getch();
+//
+// // 1 Line output
+// text_window_out("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmo");
+//
+// getch();
+// clear();
+// refresh();
+// }
- struct rng_struct *rng = rng_create(time(NULL));
+ /* Let thread work */
+ while(1);
- do {
- if (rng_roll(rng, 6) == 1)
- text_window_out("You hear screams right beneath you!");
- else
- text_window_out("You're doin' it quite right fellow adventurer!");
- getch();
- } while (!rng_get_bit(rng));
-
- rng_destroy(rng);
-
- text_window_out("All of a sudden you're dying painfully...");
- getch();
-
- text_window_out("Do you want your possessions identified? (y/n)");
- getch();
-
text_window_destroy();
finish(0);
return 0;
@@ -108,4 +100,3 @@
exit(0);
}
-
Modified: trunk/random.c
===================================================================
--- trunk/random.c 2008-11-22 01:05:36 UTC (rev 42)
+++ trunk/random.c 2008-11-22 01:17:08 UTC (rev 43)
@@ -55,4 +55,3 @@
return sum;
}
-
Modified: trunk/random.h
===================================================================
--- trunk/random.h 2008-11-22 01:05:36 UTC (rev 42)
+++ trunk/random.h 2008-11-22 01:17:08 UTC (rev 43)
@@ -49,4 +49,3 @@
#define rng_roll(rng, sides) rng_gen_from_range(rng, 1, sides)
#endif // !DERACIEL_RANDOM_H
-
Modified: trunk/text_window.c
===================================================================
--- trunk/text_window.c 2008-11-22 01:05:36 UTC (rev 42)
+++ trunk/text_window.c 2008-11-22 01:17:08 UTC (rev 43)
@@ -29,11 +29,7 @@
wattron(border_wnd, COLOR_PAIR(1));
wbkgd(text_wnd, COLOR_PAIR(2));
-
- draw_border();
-
- wrefresh(border_wnd);
- wrefresh(text_wnd);
+ repaint();
}
@@ -76,6 +72,9 @@
strncpy(linebuffer, string, TEXTWINDOW_LINEBUFFER_SIZE);
linebuffer[TEXTWINDOW_LINEBUFFER_SIZE-1] = '\0';
+ clear();
+ refresh();
+
// mod will be 0 if buffer fits *exactly* into line and 1 if we have to add a new line
int mod = strlen(linebuffer) % (BORDER_WND_MAXWIDTH-2);
@@ -102,9 +101,6 @@
wclear(border_wnd);
wclear(text_wnd);
- clear();
- refresh();
-
#ifdef TEXTWINDOW_BORDER
/* Redraw border with new dimensions */
draw_border();
@@ -113,6 +109,7 @@
wmove(text_wnd, 0, 0);
wprintw(text_wnd, linebuffer);
- wrefresh(border_wnd);
- wrefresh(text_wnd);
+ wnoutrefresh(border_wnd);
+ wnoutrefresh(text_wnd);
+ doupdate();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|